New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@better-typed/react-hyper-fetch

Package Overview
Dependencies
Maintainers
2
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@better-typed/react-hyper-fetch - npm Package Compare versions

Comparing version 0.0.25 to 0.0.26

2

dist/index.cjs.d.ts

@@ -85,2 +85,3 @@ import { FetchCommandInstance, ExtractFetchReturn, ExtractResponse, ExtractError, CacheValueType, FetchLoadingEventType, FetchProgressType } from "@better-typed/hyper-fetch";

actions: UseDependentStateActions<ExtractResponse<T>, ExtractError<T>>;
invalidate: (invalidateKey: string | FetchCommandInstance | RegExp) => void;
onSubmitRequest: (callback: OnRequestCallbackType) => void;

@@ -101,4 +102,3 @@ onSubmitSuccess: (callback: OnSuccessCallbackType<ExtractResponse<T>>) => void;

// suspense = useSubmitDefaultOptions.suspense,
// invalidate = useSubmitDefaultOptions.invalidate,
shouldThrow }?: UseSubmitOptionsType<T>) => UseSubmitReturnType<T>;
export { useFetch, UseFetchOptionsType, UseFetchReturnType, OnRequestCallbackType, OnSuccessCallbackType, OnErrorCallbackType, OnFinishedCallbackType, OnStartCallbackType, OnProgressCallbackType, useSubmit };

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("@better-typed/react-lifecycle-hooks"),t=require("@better-typed/hyper-fetch");function n(e,r,t,n,a,i,o){try{var s=e[i](o),u=s.value}catch(e){return void t(e)}s.done?r(u):Promise.resolve(u).then(n,a)}function a(e){return function(){var r=this,t=arguments;return new Promise((function(a,i){var o=e.apply(r,t);function s(e){n(o,a,i,s,u,"next",e)}function u(e){n(o,a,i,s,u,"throw",e)}s(void 0)}))}}function i(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function o(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,a,i=[],o=!0,s=!1;try{for(t=t.call(e);!(o=(n=t.next()).done)&&(i.push(n.value),!r||i.length!==r);o=!0);}catch(e){s=!0,a=e}finally{try{o||null==t.return||t.return()}finally{if(s)throw a}}return i}}(e,r)||function(e,r){if(e){if("string"==typeof e)return i(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,r):void 0}}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var s=Object.prototype,u=s.hasOwnProperty,c="function"==typeof Symbol?Symbol:{},l=c.iterator||"@@iterator",d=c.asyncIterator||"@@asyncIterator",f=c.toStringTag||"@@toStringTag";function h(e,r,t,n){var a=r&&r.prototype instanceof m?r:m,i=Object.create(a.prototype),o=new T(n||[]);return i._invoke=function(e,r,t){var n="suspendedStart";return function(a,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===a)throw i;return P()}for(t.method=a,t.arg=i;;){var o=t.delegate;if(o){var s=D(o,t);if(s){if(s===v)continue;return s}}if("next"===t.method)t.sent=t._sent=t.arg;else if("throw"===t.method){if("suspendedStart"===n)throw n="completed",t.arg;t.dispatchException(t.arg)}else"return"===t.method&&t.abrupt("return",t.arg);n="executing";var u=p(e,r,t);if("normal"===u.type){if(n=t.done?"completed":"suspendedYield",u.arg===v)continue;return{value:u.arg,done:t.done}}"throw"===u.type&&(n="completed",t.method="throw",t.arg=u.arg)}}}(e,t,o),i}function p(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}var v={};function m(){}function g(){}function y(){}var b={};b[l]=function(){return this};var w=Object.getPrototypeOf,O=w&&w(w(j([])));O&&O!==s&&u.call(O,l)&&(b=O);var x=y.prototype=m.prototype=Object.create(b);function R(e){["next","throw","return"].forEach((function(r){e[r]=function(e){return this._invoke(r,e)}}))}function E(e){var r="function"==typeof e&&e.constructor;return!!r&&(r===g||"GeneratorFunction"===(r.displayName||r.name))}function k(e,r){function t(n,a,i,o){var s=p(e[n],e,a);if("throw"!==s.type){var c=s.arg,l=c.value;return l&&"object"==typeof l&&u.call(l,"__await")?r.resolve(l.__await).then((function(e){t("next",e,i,o)}),(function(e){t("throw",e,i,o)})):r.resolve(l).then((function(e){c.value=e,i(c)}),(function(e){return t("throw",e,i,o)}))}o(s.arg)}var n;this._invoke=function(e,a){function i(){return new r((function(r,n){t(e,a,r,n)}))}return n=n?n.then(i,i):i()}}function D(e,r){var t=e.iterator[r.method];if(undefined===t){if(r.delegate=null,"throw"===r.method){if(e.iterator.return&&(r.method="return",r.arg=undefined,D(e,r),"throw"===r.method))return v;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var n=p(t,e.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,v;var a=n.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=undefined),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function S(e){var r={tryLoc:e[0]};1 in e&&(r.catchLoc=e[1]),2 in e&&(r.finallyLoc=e[2],r.afterLoc=e[3]),this.tryEntries.push(r)}function L(e){var r=e.completion||{};r.type="normal",delete r.arg,e.completion=r}function T(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(S,this),this.reset(!0)}function j(e){if(e){var r=e[l];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var t=-1,n=function r(){for(;++t<e.length;)if(u.call(e,t))return r.value=e[t],r.done=!1,r;return r.value=undefined,r.done=!0,r};return n.next=n}}return{next:P}}function P(){return{value:undefined,done:!0}}g.prototype=x.constructor=y,y.constructor=g,y[f]=g.displayName="GeneratorFunction",R(k.prototype),k.prototype[d]=function(){return this},R(x),x[f]="Generator",x[l]=function(){return this},x.toString=function(){return"[object Generator]"},T.prototype={constructor:T,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=undefined,this.done=!1,this.delegate=null,this.method="next",this.arg=undefined,this.tryEntries.forEach(L),!e)for(var r in this)"t"===r.charAt(0)&&u.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=undefined)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function t(t,n){return i.type="throw",i.arg=e,r.next=t,n&&(r.method="next",r.arg=undefined),!!n}for(var n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n],i=a.completion;if("root"===a.tryLoc)return t("end");if(a.tryLoc<=this.prev){var o=u.call(a,"catchLoc"),s=u.call(a,"finallyLoc");if(o&&s){if(this.prev<a.catchLoc)return t(a.catchLoc,!0);if(this.prev<a.finallyLoc)return t(a.finallyLoc)}else if(o){if(this.prev<a.catchLoc)return t(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return t(a.finallyLoc)}}}},abrupt:function(e,r){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc<=this.prev&&u.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var a=n;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=r&&r<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=r,a?(this.method="next",this.next=a.finallyLoc,v):this.complete(i)},complete:function(e,r){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&r&&(this.next=r),v},finish:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e)return this.complete(t.completion,t.afterLoc),L(t),v}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if("throw"===n.type){var a=n.arg;L(t)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,t){return this.delegate={iterator:j(e),resultName:r,nextLoc:t},"next"===this.method&&(this.arg=undefined),v}};var F={wrap:h,isGeneratorFunction:E,AsyncIterator:k,mark:function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,f in e||(e[f]="GeneratorFunction")),e.prototype=Object.create(x),e},awrap:function(e){return{__await:e}},async:function(e,r,t,n,a){void 0===a&&(a=Promise);var i=new k(h(e,r,t,n),a);return E(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},keys:function(e){var r=[];for(var t in e)r.push(t);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},values:j};function q(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var M=(e,r,t)=>{if(r&&e&&t&&+e.timestamp+t>+new Date)return e},_=e=>e?{response:e,retries:0,timestamp:+new Date,isRefreshed:!1}:null,K=(e,r)=>!r||!!e&&+new Date>+r+e,I={data:null,error:null,loading:!1,status:null,refreshError:null,retryError:null,isRefreshed:!1,retries:0,timestamp:null,isOnline:!0,isFocused:!0};function A(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function C(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?A(Object(t),!0).forEach((function(r){q(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):A(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var U=(e,r,t)=>{var n,a,i,o;return C(C({},I),{},{data:(null==r||null===(n=r.response)||void 0===n?void 0:n[0])||I.data,error:(null==r||null===(a=r.response)||void 0===a?void 0:a[1])||I.error,status:(null==r||null===(i=r.response)||void 0===i?void 0:i[2])||I.status,retries:(null==r?void 0:r.retries)||I.retries,timestamp:(o=(null==r?void 0:r.timestamp)||I.timestamp,o?new Date(o):null),isOnline:e.builder.appManager.isOnline,isFocused:e.builder.appManager.isFocused,loading:null!=t?t:I.loading})};function B(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function N(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?B(Object(t),!0).forEach((function(r){q(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):B(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var G=(t,n,i)=>{var s,u=t.builder,c=t.cache,l=t.cacheKey,d=t.cacheTime,f=t.queueKey,h=o(e.useState(!1),2),p=h[0],v=h[1],m=o(e.useState(+new Date),2)[1],g=e.useRef(U(t,(s=n)?{response:s,retries:0,timestamp:+new Date,isRefreshed:!1}:null)),y=e.useRef([]),b=e=>{y.current.find((r=>e.includes(r)))&&m(+new Date)};r.useDidMount((()=>{(function(){var e=a(F.mark((function e(){var r,a,o,s,h;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,u.cache.get(l);case 2:return r=e.sent,a=M(r,c,d),o=K(d,null==a?void 0:a.timestamp),s=o?_(n):a,e.next=8,i.get(f);case 8:h=e.sent,g.current=U(t,s,g.current.loading||!!h.requests.length),v(!0),m(+new Date);case 12:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}})()()})),r.useDidMount((()=>{var e=u.appManager.events.onFocus((()=>{g.current.isFocused=!0,b(["isFocused"])})),r=u.appManager.events.onBlur((()=>{g.current.isFocused=!1,b(["isFocused"])})),t=u.appManager.events.onOnline((()=>{g.current.isOnline=!0,b(["isOnline"])})),n=u.appManager.events.onOffline((()=>{g.current.isOnline=!1,b(["isOnline"])}));return()=>{e(),r(),t(),n()}}));var w,O,x,R,E,k,D,S,L,T,j={setCacheData:(T=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=6;break}return e.next=4,u.cache.set(N({cache:c,cacheKey:l},r));case 4:e.next=9;break;case 6:t={data:r.response[0],error:r.response[1],status:r.response[2],retries:r.retries,timestamp:new Date(r.timestamp),retryError:r.retryError,refreshError:r.refreshError,isRefreshed:r.isRefreshed,loading:!1},g.current=N(N({},g.current),t),b(Object.keys(t));case 9:case"end":return e.stop()}}),e)}))),function(e){return T.apply(this,arguments)}),setData:(L=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[r,t.error,t.status],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:g.current.data=r,b(["data"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return L.apply(this,arguments)}),setError:(S=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[t.data,r,t.status],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:g.current.error=r,b(["error"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return S.apply(this,arguments)}),setLoading:(D=a(F.mark((function e(r){var t=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t.length>1&&void 0!==t[1]&&!t[1]?(g.current.loading=r,b(["loading"])):u.fetchQueue.events.setLoading(l,{isLoading:r,isRetry:!1});case 2:case"end":return e.stop()}}),e)}))),function(e){return D.apply(this,arguments)}),setStatus:(k=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[t.data,t.error,r],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:g.current.status=r,b(["status"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return k.apply(this,arguments)}),setRefreshed:(E=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[t.data,t.error,t.status],retries:t.retries,isRefreshed:r});case 5:e.next=9;break;case 7:g.current.isRefreshed=r,b(["isRefreshed"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return E.apply(this,arguments)}),setRefreshError:(R=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[t.data,r,t.status],retries:t.retries,isRefreshed:!0});case 5:e.next=9;break;case 7:g.current.refreshError=r,b(["refreshError"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return R.apply(this,arguments)}),setRetryError:(x=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[t.data,r,t.status],retries:t.retries,isRefreshed:!0});case 5:e.next=9;break;case 7:g.current.retryError=r,b(["retryError"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return x.apply(this,arguments)}),setRetries:(O=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[t.data,t.error,t.status],retries:r,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:g.current.retries=r,b(["retries"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return O.apply(this,arguments)}),setTimestamp:(w=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[t.data,t.error,t.status],retries:t.retries,isRefreshed:t.isRefreshed,timestamp:r?+r:void 0});case 5:e.next=9;break;case 7:g.current.timestamp=r,b(["timestamp"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return w.apply(this,arguments)})};return[g.current,j,e=>{y.current.push(e)},p]},Q=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:600,n=e.useRef({time:t,timer:null});n.current.time=t;var a=()=>{n.current.timer&&clearTimeout(n.current.timer),n.current.timer=null},i=e=>{a(),n.current.timer=setTimeout((()=>{n.current.timer=null,e()}),n.current.time)};return r.useWillUnmount(a),{debounce:i,resetDebounce:a,active:!!n.current.timer}},W=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:600,n=e.useRef({time:t,timer:null});n.current.time=t;var a=()=>{n.current.timer&&clearInterval(n.current.timer),n.current.timer=null},i=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;a(),n.current.timer=setInterval((()=>{e()}),r<=0?n.current.time:r)};return r.useWillUnmount(a),{interval:i,resetInterval:a,active:!!n.current.timer}},Y={dependencies:[],disabled:!1,dependencyTracking:!0,cacheOnMount:!0,revalidateOnMount:!0,initialData:null,refresh:!1,refreshTime:t.DateInterval.hour,refreshBlurred:!1,refreshOnTabBlur:!1,refreshOnTabFocus:!1,refreshOnReconnect:!1,cancelable:!1,debounce:!1,debounceTime:400,deepCompareFn:void 0,responseDataModifierFn:null,shouldThrow:!1},$={disabled:!1,dependencyTracking:!0,cacheOnMount:!0,initialData:null,debounce:!1,debounceTime:400,suspense:!1,shouldThrow:!1,responseDataModifierFn:null,invalidate:[]};exports.useFetch=function(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Y,s=i.dependencies,u=void 0===s?Y.dependencies:s,c=i.disabled,l=void 0===c?Y.disabled:c,d=i.dependencyTracking,f=void 0===d?Y.dependencyTracking:d,h=i.revalidateOnMount,p=void 0===h?Y.revalidateOnMount:h,v=i.initialData,m=void 0===v?Y.initialData:v,g=i.refresh,y=void 0===g?Y.refresh:g,b=i.refreshTime,w=void 0===b?Y.refreshTime:b,O=i.refreshBlurred,x=void 0===O?Y.refreshBlurred:O,R=i.refreshOnTabBlur,E=void 0===R?Y.refreshOnTabBlur:R,k=i.refreshOnTabFocus,D=void 0===k?Y.refreshOnTabFocus:k,S=i.refreshOnReconnect,L=void 0===S?Y.refreshOnReconnect:S,T=i.debounce,j=void 0===T?Y.debounce:T,P=i.debounceTime,q=void 0===P?Y.debounceTime:P,M=i.shouldThrow,_=void 0===M?Y.shouldThrow:M,I=n.cacheTime,A=n.cacheKey,C=n.queueKey,U=n.builder,B=Q(q),N=W(w),$=U.cache,z=U.fetchQueue,H=U.appManager,J=U.commandManager,V=U.loggerManager,X=e.useRef(V.init("useFetch")).current,Z=G(n,m,z),ee=o(Z,4),re=ee[0],te=ee[1],ne=ee[2],ae=ee[3],ie=e.useRef(null),oe=e.useRef(null),se=e.useRef(null),ue=e.useRef(null),ce=e.useRef(null),le=e.useRef(null),de=e.useRef(null),fe=e.useRef(null),he=()=>{l?X.debug("Cannot add to fetch queue",{disabled:l}):(X.debug("Adding request to fetch queue"),z.add(n))},pe=()=>{N.resetInterval();var e=re.timestamp,r=e?Math.max(+e+w-+new Date,w):w;y&&(X.debug("Starting refresh counter, request will be send in ".concat(r,"ms")),N.interval(a(F.mark((function e(){var r,t,a;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,z.get(C);case 2:r=e.sent,t=!n.builder.appManager.isFocused,a=t&&x||n.builder.appManager.isFocused,!!!r.requests.length&&a&&(X.info("Performing refresh request"),he(),N.resetInterval());case 8:case"end":return e.stop()}}),e)}))),r))},ve=e=>{if(e){var r,t,n;if(e[0])null==oe||null===(t=oe.current)||void 0===t||t.call(oe,e[0]);if(e[1])if(null==se||null===(n=se.current)||void 0===n||n.call(se,e[1]),_)throw{message:"Fetching Error.",error:e[1]};null==ue||null===(r=ue.current)||void 0===r||r.call(ue,e)}},me=function(){var e=a(F.mark((function e(r){return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:ve(r.response),te.setCacheData(r,!1),te.setLoading(!1,!1);case 3:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}(),ge=(e,r)=>{ve([re.data,re.error,re.status]),te.setRefreshed(e,!1),te.setTimestamp(new Date(r),!1),te.setLoading(!1,!1)},ye=e=>{var r,t=e.isLoading,n=e.isRetry;te.setLoading(t,!1),null===(r=ie.current)||void 0===r||r.call(ie,{isRetry:n})},be=()=>{he()},we=e=>{e&&"string"==typeof e?n.builder.cache.events.revalidate(e):e&&e instanceof t.FetchCommand?n.builder.cache.events.revalidate(t.getCommandKey(e)):be()},Oe=e=>{var r;null==de||null===(r=de.current)||void 0===r||r.call(de,e)},xe=e=>{var r;null==fe||null===(r=fe.current)||void 0===r||r.call(fe,e)},Re=e=>{var r;null==ce||null===(r=ce.current)||void 0===r||r.call(ce,e)},Ee=e=>{var r;null==ce||null===(r=ce.current)||void 0===r||r.call(ce,e)},ke=()=>{var e=H.events.onFocus((()=>D&&he())),r=H.events.onBlur((()=>E&&he())),t=H.events.onOnline((()=>L&&he())),n=J.events.onDownloadProgress(C,Oe),a=J.events.onUploadProgress(C,xe),i=J.events.onRequestStart(C,Re),o=J.events.onResponseStart(C,Ee),s=z.events.getLoading(C,ye),u=$.events.get(A,me),c=$.events.getEqualData(A,ge),l=$.events.onRevalidate(A,be);return()=>{e(),r(),t(),n(),a(),i(),o(),s(),u(),c(),l()}},De=()=>{f||Object.keys(re).forEach((e=>ne(e)))};return r.useDidMount((()=>((p||K(I,re.timestamp))&&he(),De(),ke()))),r.useDidUpdate((()=>{ae&&ve([re.data,re.error,re.status])}),[ae],!0),r.useDidUpdate((()=>{!z.requestCount&&j?B.debounce((()=>he())):he()}),[...u,l]),r.useDidUpdate((()=>{pe()}),[y,w,re.timestamp],!0),{get data(){return ne("data"),re.data},get error(){return ne("error"),re.error},get loading(){return ne("loading"),re.loading},get status(){return ne("status"),re.status},get retryError(){return ne("retryError"),re.retryError},get refreshError(){return ne("refreshError"),re.refreshError},get isRefreshed(){return ne("isRefreshed"),re.isRefreshed},get retries(){return ne("retries"),re.retries},get timestamp(){return ne("timestamp"),re.timestamp},get isOnline(){return ne("isOnline"),re.isOnline},get isFocused(){return ne("isFocused"),re.isFocused},get isStale(){return K(I,re.timestamp)},actions:te,onRequest:e=>{ie.current=e},onSuccess:e=>{oe.current=e},onError:e=>{se.current=e},onFinished:e=>{ue.current=e},onRequestStart:e=>{ce.current=e},onResponseStart:e=>{le.current=e},onDownloadProgress:e=>{de.current=e},onUploadProgress:e=>{fe.current=e},isRefreshingError:!!re.error&&re.isRefreshed,isDebouncing:B.active,refresh:we}},exports.useSubmit=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$,i=n.disabled,s=void 0===i?$.disabled:i,u=n.dependencyTracking,c=void 0===u?$.dependencyTracking:u,l=n.initialData,d=void 0===l?$.initialData:l,f=n.debounce,h=void 0===f?$.debounce:f,p=n.debounceTime,v=void 0===p?$.debounceTime:p,m=n.shouldThrow,g=void 0===m?$.shouldThrow:m,y=t.cacheTime,b=t.cacheKey,w=t.queueKey,O=t.builder,x=Q(v),R=O.cache,E=O.submitQueue,k=O.commandManager,D=O.loggerManager,S=e.useRef(D.init("useSubmit")).current,L=G(t,d,E),T=o(L,3),j=T[0],P=T[1],q=T[2],M=e.useRef(null),_=e.useRef(null),I=e.useRef(null),A=e.useRef(null),C=e.useRef(null),U=e.useRef(null),B=e.useRef(null),N=e.useRef(null),W=function(){var e=t,r=arguments.length<=0?void 0:arguments[0];null!=r&&r.data&&(e=e.setData(r.data)),null!=r&&r.params&&(e=e.setParams(r.params)),null!=r&&r.queryParams&&(e=e.setQueryParams(r.queryParams)),s?S.debug("Cannot add to submit queue",{disabled:s,options:r}):(S.debug("Adding request to submit queue",{disabled:s,options:r}),h?x.debounce((()=>E.add(e))):E.add(e))},Y=e=>{if(e){var r,t,n;if(e[0])null==_||null===(t=_.current)||void 0===t||t.call(_,e[0]);if(e[1])if(null==I||null===(n=I.current)||void 0===n||n.call(I,e[1]),g)throw{message:"Fetching Error.",error:e[1]};null==A||null===(r=A.current)||void 0===r||r.call(A,e)}},z=function(){var e=a(F.mark((function e(r){return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:Y(r.response),P.setCacheData(r,!1),P.setLoading(!1,!1);case 3:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}(),H=(e,r)=>{Y([j.data,j.error,j.status]),P.setRefreshed(e,!1),P.setTimestamp(new Date(r),!1),P.setLoading(!1,!1)},J=e=>{var r,t=e.isLoading,n=e.isRetry;P.setLoading(t,!1),null===(r=M.current)||void 0===r||r.call(M,{isRetry:n})},V=e=>{var r;null==B||null===(r=B.current)||void 0===r||r.call(B,e)},X=e=>{var r;null==N||null===(r=N.current)||void 0===r||r.call(N,e)},Z=e=>{var r;null==C||null===(r=C.current)||void 0===r||r.call(C,e)},ee=e=>{var r;null==C||null===(r=C.current)||void 0===r||r.call(C,e)},re=()=>{var e=k.events.onDownloadProgress(w,V),r=k.events.onUploadProgress(w,X),t=k.events.onRequestStart(w,Z),n=k.events.onResponseStart(w,ee),a=E.events.getLoading(w,J),i=R.events.get(w,z),o=R.events.getEqualData(b,H);return()=>{e(),r(),t(),n(),a(),i(),o()}},te=()=>{c||Object.keys(j).forEach((e=>q(e)))};return r.useDidMount((()=>(te(),re()))),{submit:W,get data(){return q("data"),j.data},get error(){return q("error"),j.error},get submitting(){return q("loading"),j.loading},get status(){return q("status"),j.status},get retryError(){return q("retryError"),j.retryError},get retries(){return q("retries"),j.retries},get timestamp(){return q("timestamp"),j.timestamp},get isOnline(){return q("isOnline"),j.isOnline},get isFocused(){return q("isFocused"),j.isFocused},get isStale(){return K(y,j.timestamp)},actions:P,isDebouncing:!1,isRefreshed:!1,onSubmitRequest:e=>{M.current=e},onSubmitSuccess:e=>{_.current=e},onSubmitError:e=>{I.current=e},onSubmitFinished:e=>{A.current=e},onSubmitRequestStart:e=>{C.current=e},onSubmitResponseStart:e=>{U.current=e},onSubmitDownloadProgress:e=>{B.current=e},onSubmitUploadProgress:e=>{N.current=e}}};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("@better-typed/react-lifecycle-hooks"),t=require("@better-typed/hyper-fetch");function n(e,r,t,n,a,i,o){try{var s=e[i](o),u=s.value}catch(e){return void t(e)}s.done?r(u):Promise.resolve(u).then(n,a)}function a(e){return function(){var r=this,t=arguments;return new Promise((function(a,i){var o=e.apply(r,t);function s(e){n(o,a,i,s,u,"next",e)}function u(e){n(o,a,i,s,u,"throw",e)}s(void 0)}))}}function i(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function o(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,a,i=[],o=!0,s=!1;try{for(t=t.call(e);!(o=(n=t.next()).done)&&(i.push(n.value),!r||i.length!==r);o=!0);}catch(e){s=!0,a=e}finally{try{o||null==t.return||t.return()}finally{if(s)throw a}}return i}}(e,r)||function(e,r){if(e){if("string"==typeof e)return i(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,r):void 0}}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var s=Object.prototype,u=s.hasOwnProperty,c="function"==typeof Symbol?Symbol:{},l=c.iterator||"@@iterator",d=c.asyncIterator||"@@asyncIterator",f=c.toStringTag||"@@toStringTag";function h(e,r,t,n){var a=r&&r.prototype instanceof m?r:m,i=Object.create(a.prototype),o=new L(n||[]);return i._invoke=function(e,r,t){var n="suspendedStart";return function(a,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===a)throw i;return P()}for(t.method=a,t.arg=i;;){var o=t.delegate;if(o){var s=D(o,t);if(s){if(s===v)continue;return s}}if("next"===t.method)t.sent=t._sent=t.arg;else if("throw"===t.method){if("suspendedStart"===n)throw n="completed",t.arg;t.dispatchException(t.arg)}else"return"===t.method&&t.abrupt("return",t.arg);n="executing";var u=p(e,r,t);if("normal"===u.type){if(n=t.done?"completed":"suspendedYield",u.arg===v)continue;return{value:u.arg,done:t.done}}"throw"===u.type&&(n="completed",t.method="throw",t.arg=u.arg)}}}(e,t,o),i}function p(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}var v={};function m(){}function g(){}function y(){}var b={};b[l]=function(){return this};var w=Object.getPrototypeOf,O=w&&w(w(j([])));O&&O!==s&&u.call(O,l)&&(b=O);var x=y.prototype=m.prototype=Object.create(b);function R(e){["next","throw","return"].forEach((function(r){e[r]=function(e){return this._invoke(r,e)}}))}function E(e){var r="function"==typeof e&&e.constructor;return!!r&&(r===g||"GeneratorFunction"===(r.displayName||r.name))}function k(e,r){function t(n,a,i,o){var s=p(e[n],e,a);if("throw"!==s.type){var c=s.arg,l=c.value;return l&&"object"==typeof l&&u.call(l,"__await")?r.resolve(l.__await).then((function(e){t("next",e,i,o)}),(function(e){t("throw",e,i,o)})):r.resolve(l).then((function(e){c.value=e,i(c)}),(function(e){return t("throw",e,i,o)}))}o(s.arg)}var n;this._invoke=function(e,a){function i(){return new r((function(r,n){t(e,a,r,n)}))}return n=n?n.then(i,i):i()}}function D(e,r){var t=e.iterator[r.method];if(undefined===t){if(r.delegate=null,"throw"===r.method){if(e.iterator.return&&(r.method="return",r.arg=undefined,D(e,r),"throw"===r.method))return v;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var n=p(t,e.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,v;var a=n.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=undefined),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function T(e){var r={tryLoc:e[0]};1 in e&&(r.catchLoc=e[1]),2 in e&&(r.finallyLoc=e[2],r.afterLoc=e[3]),this.tryEntries.push(r)}function S(e){var r=e.completion||{};r.type="normal",delete r.arg,e.completion=r}function L(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function j(e){if(e){var r=e[l];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var t=-1,n=function r(){for(;++t<e.length;)if(u.call(e,t))return r.value=e[t],r.done=!1,r;return r.value=undefined,r.done=!0,r};return n.next=n}}return{next:P}}function P(){return{value:undefined,done:!0}}g.prototype=x.constructor=y,y.constructor=g,y[f]=g.displayName="GeneratorFunction",R(k.prototype),k.prototype[d]=function(){return this},R(x),x[f]="Generator",x[l]=function(){return this},x.toString=function(){return"[object Generator]"},L.prototype={constructor:L,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=undefined,this.done=!1,this.delegate=null,this.method="next",this.arg=undefined,this.tryEntries.forEach(S),!e)for(var r in this)"t"===r.charAt(0)&&u.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=undefined)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function t(t,n){return i.type="throw",i.arg=e,r.next=t,n&&(r.method="next",r.arg=undefined),!!n}for(var n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n],i=a.completion;if("root"===a.tryLoc)return t("end");if(a.tryLoc<=this.prev){var o=u.call(a,"catchLoc"),s=u.call(a,"finallyLoc");if(o&&s){if(this.prev<a.catchLoc)return t(a.catchLoc,!0);if(this.prev<a.finallyLoc)return t(a.finallyLoc)}else if(o){if(this.prev<a.catchLoc)return t(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return t(a.finallyLoc)}}}},abrupt:function(e,r){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc<=this.prev&&u.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var a=n;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=r&&r<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=r,a?(this.method="next",this.next=a.finallyLoc,v):this.complete(i)},complete:function(e,r){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&r&&(this.next=r),v},finish:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e)return this.complete(t.completion,t.afterLoc),S(t),v}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if("throw"===n.type){var a=n.arg;S(t)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,t){return this.delegate={iterator:j(e),resultName:r,nextLoc:t},"next"===this.method&&(this.arg=undefined),v}};var F={wrap:h,isGeneratorFunction:E,AsyncIterator:k,mark:function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,f in e||(e[f]="GeneratorFunction")),e.prototype=Object.create(x),e},awrap:function(e){return{__await:e}},async:function(e,r,t,n,a){void 0===a&&(a=Promise);var i=new k(h(e,r,t,n),a);return E(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},keys:function(e){var r=[];for(var t in e)r.push(t);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},values:j};function q(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var M=(e,r,t)=>{if(r&&e&&t&&+e.timestamp+t>+new Date)return e},K=e=>e?{response:e,retries:0,timestamp:+new Date,isRefreshed:!1}:null,_=(e,r)=>!r||!!e&&+new Date>+r+e,C={data:null,error:null,loading:!1,status:null,refreshError:null,retryError:null,isRefreshed:!1,retries:0,timestamp:null,isOnline:!0,isFocused:!0};function I(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function A(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?I(Object(t),!0).forEach((function(r){q(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):I(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var U=(e,r,t)=>{var n,a,i,o;return A(A({},C),{},{data:(null==r||null===(n=r.response)||void 0===n?void 0:n[0])||C.data,error:(null==r||null===(a=r.response)||void 0===a?void 0:a[1])||C.error,status:(null==r||null===(i=r.response)||void 0===i?void 0:i[2])||C.status,retries:(null==r?void 0:r.retries)||C.retries,timestamp:(o=(null==r?void 0:r.timestamp)||C.timestamp,o?new Date(o):null),isOnline:e.builder.appManager.isOnline,isFocused:e.builder.appManager.isFocused,loading:null!=t?t:C.loading})};function N(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function B(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?N(Object(t),!0).forEach((function(r){q(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):N(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var G=(t,n,i)=>{var s,u=t.builder,c=t.cache,l=t.cacheKey,d=t.cacheTime,f=t.queueKey,h=o(e.useState(!1),2),p=h[0],v=h[1],m=o(e.useState(+new Date),2)[1],g=e.useRef(U(t,(s=n)?{response:s,retries:0,timestamp:+new Date,isRefreshed:!1}:null)),y=e.useRef([]),b=e=>{y.current.find((r=>e.includes(r)))&&m(+new Date)};r.useDidMount((()=>{(function(){var e=a(F.mark((function e(){var r,a,o,s,h;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,u.cache.get(l);case 2:return r=e.sent,a=M(r,c,d),o=_(d,null==a?void 0:a.timestamp),s=o?K(n):a,e.next=8,i.get(f);case 8:h=e.sent,g.current=U(t,s,g.current.loading||!!h.requests.length),v(!0),m(+new Date);case 12:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}})()()})),r.useDidMount((()=>{var e=u.appManager.events.onFocus((()=>{g.current.isFocused=!0,b(["isFocused"])})),r=u.appManager.events.onBlur((()=>{g.current.isFocused=!1,b(["isFocused"])})),t=u.appManager.events.onOnline((()=>{g.current.isOnline=!0,b(["isOnline"])})),n=u.appManager.events.onOffline((()=>{g.current.isOnline=!1,b(["isOnline"])}));return()=>{e(),r(),t(),n()}}));var w,O,x,R,E,k,D,T,S,L,j={setCacheData:(L=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=6;break}return e.next=4,u.cache.set(B({cache:c,cacheKey:l},r));case 4:e.next=9;break;case 6:t={data:r.response[0],error:r.response[1],status:r.response[2],retries:r.retries,timestamp:new Date(r.timestamp),retryError:r.retryError,refreshError:r.refreshError,isRefreshed:r.isRefreshed,loading:!1},g.current=B(B({},g.current),t),b(Object.keys(t));case 9:case"end":return e.stop()}}),e)}))),function(e){return L.apply(this,arguments)}),setData:(S=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[r,t.error,t.status],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:g.current.data=r,b(["data"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return S.apply(this,arguments)}),setError:(T=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[t.data,r,t.status],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:g.current.error=r,b(["error"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return T.apply(this,arguments)}),setLoading:(D=a(F.mark((function e(r){var t=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t.length>1&&void 0!==t[1]&&!t[1]?(g.current.loading=r,b(["loading"])):u.fetchQueue.events.setLoading(l,{isLoading:r,isRetry:!1});case 2:case"end":return e.stop()}}),e)}))),function(e){return D.apply(this,arguments)}),setStatus:(k=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[t.data,t.error,r],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:g.current.status=r,b(["status"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return k.apply(this,arguments)}),setRefreshed:(E=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[t.data,t.error,t.status],retries:t.retries,isRefreshed:r});case 5:e.next=9;break;case 7:g.current.isRefreshed=r,b(["isRefreshed"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return E.apply(this,arguments)}),setRefreshError:(R=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[t.data,r,t.status],retries:t.retries,isRefreshed:!0});case 5:e.next=9;break;case 7:g.current.refreshError=r,b(["refreshError"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return R.apply(this,arguments)}),setRetryError:(x=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[t.data,r,t.status],retries:t.retries,isRefreshed:!0});case 5:e.next=9;break;case 7:g.current.retryError=r,b(["retryError"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return x.apply(this,arguments)}),setRetries:(O=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[t.data,t.error,t.status],retries:r,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:g.current.retries=r,b(["retries"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return O.apply(this,arguments)}),setTimestamp:(w=a(F.mark((function e(r){var t,n=arguments;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=g.current,e.next=5,u.cache.set({cache:c,cacheKey:l,response:[t.data,t.error,t.status],retries:t.retries,isRefreshed:t.isRefreshed,timestamp:r?+r:void 0});case 5:e.next=9;break;case 7:g.current.timestamp=r,b(["timestamp"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return w.apply(this,arguments)})};return[g.current,j,e=>{y.current.push(e)},p]},Q=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:600,n=e.useRef({time:t,timer:null});n.current.time=t;var a=()=>{n.current.timer&&clearTimeout(n.current.timer),n.current.timer=null},i=e=>{a(),n.current.timer=setTimeout((()=>{n.current.timer=null,e()}),n.current.time)};return r.useWillUnmount(a),{debounce:i,resetDebounce:a,active:!!n.current.timer}},W=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:600,n=e.useRef({time:t,timer:null});n.current.time=t;var a=()=>{n.current.timer&&clearInterval(n.current.timer),n.current.timer=null},i=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;a(),n.current.timer=setInterval((()=>{e()}),r<=0?n.current.time:r)};return r.useWillUnmount(a),{interval:i,resetInterval:a,active:!!n.current.timer}},Y={dependencies:[],disabled:!1,dependencyTracking:!0,cacheOnMount:!0,revalidateOnMount:!0,initialData:null,refresh:!1,refreshTime:t.DateInterval.hour,refreshBlurred:!1,refreshOnTabBlur:!1,refreshOnTabFocus:!1,refreshOnReconnect:!1,cancelable:!1,debounce:!1,debounceTime:400,deepCompareFn:void 0,responseDataModifierFn:null,shouldThrow:!1},$={disabled:!1,dependencyTracking:!0,cacheOnMount:!0,initialData:null,debounce:!1,debounceTime:400,suspense:!1,shouldThrow:!1,responseDataModifierFn:null,invalidate:[]};exports.useFetch=function(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Y,s=i.dependencies,u=void 0===s?Y.dependencies:s,c=i.disabled,l=void 0===c?Y.disabled:c,d=i.dependencyTracking,f=void 0===d?Y.dependencyTracking:d,h=i.revalidateOnMount,p=void 0===h?Y.revalidateOnMount:h,v=i.initialData,m=void 0===v?Y.initialData:v,g=i.refresh,y=void 0===g?Y.refresh:g,b=i.refreshTime,w=void 0===b?Y.refreshTime:b,O=i.refreshBlurred,x=void 0===O?Y.refreshBlurred:O,R=i.refreshOnTabBlur,E=void 0===R?Y.refreshOnTabBlur:R,k=i.refreshOnTabFocus,D=void 0===k?Y.refreshOnTabFocus:k,T=i.refreshOnReconnect,S=void 0===T?Y.refreshOnReconnect:T,L=i.debounce,j=void 0===L?Y.debounce:L,P=i.debounceTime,q=void 0===P?Y.debounceTime:P,M=i.shouldThrow,K=void 0===M?Y.shouldThrow:M,C=n.cacheTime,I=n.cacheKey,A=n.queueKey,U=n.builder,N=Q(q),B=W(w),$=U.cache,z=U.fetchQueue,H=U.appManager,J=U.commandManager,V=U.loggerManager,X=e.useRef(V.init("useFetch")).current,Z=G(n,m,z),ee=o(Z,4),re=ee[0],te=ee[1],ne=ee[2],ae=ee[3],ie=e.useRef(null),oe=e.useRef(null),se=e.useRef(null),ue=e.useRef(null),ce=e.useRef(null),le=e.useRef(null),de=e.useRef(null),fe=e.useRef(null),he=()=>{l?X.debug("Cannot add to fetch queue",{disabled:l}):(X.debug("Adding request to fetch queue"),z.add(n))},pe=()=>{B.resetInterval();var e=re.timestamp,r=e?Math.max(+e+w-+new Date,w):w;y&&(X.debug("Starting refresh counter, request will be send in ".concat(r,"ms")),B.interval(a(F.mark((function e(){var r,t,a;return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,z.get(A);case 2:r=e.sent,t=!n.builder.appManager.isFocused,a=t&&x||n.builder.appManager.isFocused,!!!r.requests.length&&a&&(X.info("Performing refresh request"),he(),B.resetInterval());case 8:case"end":return e.stop()}}),e)}))),r))},ve=e=>{if(e){var r,t,n;if(e[0])null==oe||null===(t=oe.current)||void 0===t||t.call(oe,e[0]);if(e[1])if(null==se||null===(n=se.current)||void 0===n||n.call(se,e[1]),K)throw{message:"Fetching Error.",error:e[1]};null==ue||null===(r=ue.current)||void 0===r||r.call(ue,e)}},me=function(){var e=a(F.mark((function e(r){return F.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:ve(r.response),te.setCacheData(r,!1),te.setLoading(!1,!1);case 3:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}(),ge=(e,r,t)=>{ve(e.response),te.setRefreshed(r,!1),te.setTimestamp(new Date(t),!1),te.setLoading(!1,!1)},ye=e=>{var r,t=e.isLoading,n=e.isRetry;te.setLoading(t,!1),null===(r=ie.current)||void 0===r||r.call(ie,{isRetry:n})},be=()=>{he()},we=e=>{e&&e instanceof t.FetchCommand?n.builder.cache.events.revalidate("/".concat(t.getCommandKey(e,!0),"/")):e?n.builder.cache.events.revalidate(e):be()},Oe=e=>{var r;null==de||null===(r=de.current)||void 0===r||r.call(de,e)},xe=e=>{var r;null==fe||null===(r=fe.current)||void 0===r||r.call(fe,e)},Re=e=>{var r;null==ce||null===(r=ce.current)||void 0===r||r.call(ce,e)},Ee=e=>{var r;null==ce||null===(r=ce.current)||void 0===r||r.call(ce,e)},ke=()=>{var e=H.events.onFocus((()=>D&&he())),r=H.events.onBlur((()=>E&&he())),t=H.events.onOnline((()=>S&&he())),n=J.events.onDownloadProgress(A,Oe),a=J.events.onUploadProgress(A,xe),i=J.events.onRequestStart(A,Re),o=J.events.onResponseStart(A,Ee),s=z.events.getLoading(A,ye),u=$.events.get(I,me),c=$.events.getEqualData(I,ge),l=$.events.onRevalidate(I,be);return()=>{e(),r(),t(),n(),a(),i(),o(),s(),u(),c(),l()}},De=()=>{f||Object.keys(re).forEach((e=>ne(e)))};return r.useDidMount((()=>((p||_(C,re.timestamp))&&he(),De(),ke()))),r.useDidUpdate((()=>{ae&&ve([re.data,re.error,re.status])}),[ae],!0),r.useDidUpdate((()=>{!z.requestCount&&j?N.debounce((()=>he())):he()}),[...u,l]),r.useDidUpdate((()=>{pe()}),[y,w,re.timestamp],!0),{get data(){return ne("data"),re.data},get error(){return ne("error"),re.error},get loading(){return ne("loading"),re.loading},get status(){return ne("status"),re.status},get retryError(){return ne("retryError"),re.retryError},get refreshError(){return ne("refreshError"),re.refreshError},get isRefreshed(){return ne("isRefreshed"),re.isRefreshed},get retries(){return ne("retries"),re.retries},get timestamp(){return ne("timestamp"),re.timestamp},get isOnline(){return ne("isOnline"),re.isOnline},get isFocused(){return ne("isFocused"),re.isFocused},get isStale(){return _(C,re.timestamp)},actions:te,onRequest:e=>{ie.current=e},onSuccess:e=>{oe.current=e},onError:e=>{se.current=e},onFinished:e=>{ue.current=e},onRequestStart:e=>{ce.current=e},onResponseStart:e=>{le.current=e},onDownloadProgress:e=>{de.current=e},onUploadProgress:e=>{fe.current=e},isRefreshingError:!!re.error&&re.isRefreshed,isDebouncing:N.active,refresh:we}},exports.useSubmit=function(n){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$,i=a.disabled,s=void 0===i?$.disabled:i,u=a.dependencyTracking,c=void 0===u?$.dependencyTracking:u,l=a.initialData,d=void 0===l?$.initialData:l,f=a.debounce,h=void 0===f?$.debounce:f,p=a.debounceTime,v=void 0===p?$.debounceTime:p,m=a.shouldThrow,g=void 0===m?$.shouldThrow:m,y=n.cacheTime,b=n.cacheKey,w=n.queueKey,O=n.builder,x=Q(v),R=O.cache,E=O.submitQueue,k=O.commandManager,D=O.loggerManager,T=e.useRef(D.init("useSubmit")).current,S=G(n,d,E),L=o(S,3),j=L[0],P=L[1],F=L[2],q=e.useRef(null),M=e.useRef(null),K=e.useRef(null),C=e.useRef(null),I=e.useRef(null),A=e.useRef(null),U=e.useRef(null),N=e.useRef(null),B=function(){var e=n,r=arguments.length<=0?void 0:arguments[0];if(null!=r&&r.data&&(e=e.setData(r.data)),null!=r&&r.params&&(e=e.setParams(r.params)),null!=r&&r.queryParams&&(e=e.setQueryParams(r.queryParams)),s)T.debug("Cannot add to submit queue",{disabled:s,options:r});else{if(T.debug("Adding request to submit queue",{disabled:s,options:r}),!h)return e.send({queueType:"submit"});x.debounce((()=>{e.send({queueType:"submit"})}))}},W=e=>{if(e){var r,t,n;if(e[0])null==M||null===(t=M.current)||void 0===t||t.call(M,e[0]);if(e[1])if(null==K||null===(n=K.current)||void 0===n||n.call(K,e[1]),g)throw{message:"Fetching Error.",error:e[1]};null==C||null===(r=C.current)||void 0===r||r.call(C,e)}else T.debug("No response to perform callbacks")},Y=e=>{W(e.response),P.setLoading(!1,!1),P.setCacheData(e,!1)},z=(e,r,t)=>{W(e.response),P.setRefreshed(r,!1),P.setTimestamp(new Date(t),!1),P.setLoading(!1,!1)},H=e=>{var r,t=e.isLoading,n=e.isRetry;P.setLoading(t,!1),null===(r=q.current)||void 0===r||r.call(q,{isRetry:n})},J=e=>{var r;null==U||null===(r=U.current)||void 0===r||r.call(U,e)},V=e=>{var r;null==N||null===(r=N.current)||void 0===r||r.call(N,e)},X=e=>{var r;null==I||null===(r=I.current)||void 0===r||r.call(I,e)},Z=e=>{var r;null==I||null===(r=I.current)||void 0===r||r.call(I,e)},ee=()=>{var e=k.events.onDownloadProgress(w,J),r=k.events.onUploadProgress(w,V),t=k.events.onRequestStart(w,X),n=k.events.onResponseStart(w,Z),a=E.events.getLoading(w,H),i=R.events.get(w,Y),o=R.events.getEqualData(b,z);return()=>{e(),r(),t(),n(),a(),i(),o()}},re=()=>{c||Object.keys(j).forEach((e=>F(e)))},te=e=>{e&&e instanceof t.FetchCommand?n.builder.cache.events.revalidate("/".concat(t.getCommandKey(e,!0),"/")):n.builder.cache.events.revalidate(e)};return r.useDidMount((()=>(re(),ee()))),{submit:B,get data(){return F("data"),j.data},get error(){return F("error"),j.error},get submitting(){return F("loading"),j.loading},get status(){return F("status"),j.status},get retryError(){return F("retryError"),j.retryError},get retries(){return F("retries"),j.retries},get timestamp(){return F("timestamp"),j.timestamp},get isOnline(){return F("isOnline"),j.isOnline},get isFocused(){return F("isFocused"),j.isFocused},get isStale(){return _(y,j.timestamp)},actions:P,isDebouncing:!1,isRefreshed:!1,invalidate:te,onSubmitRequest:e=>{q.current=e},onSubmitSuccess:e=>{M.current=e},onSubmitError:e=>{K.current=e},onSubmitFinished:e=>{C.current=e},onSubmitRequestStart:e=>{I.current=e},onSubmitResponseStart:e=>{A.current=e},onSubmitDownloadProgress:e=>{U.current=e},onSubmitUploadProgress:e=>{N.current=e}}};
//# sourceMappingURL=index.cjs.js.map

@@ -86,2 +86,3 @@ import { CacheValueType, FetchCommandInstance, ExtractResponse, ExtractError, ExtractFetchReturn, FetchLoadingEventType, FetchProgressType, SubmitLoadingEventType } from '@better-typed/hyper-fetch';

actions: UseDependentStateActions<ExtractResponse<T>, ExtractError<T>>;
invalidate: (invalidateKey: string | FetchCommandInstance | RegExp) => void;
onSubmitRequest: (callback: OnRequestCallbackType) => void;

@@ -88,0 +89,0 @@ onSubmitSuccess: (callback: OnSuccessCallbackType<ExtractResponse<T>>) => void;

@@ -85,2 +85,3 @@ import { FetchCommandInstance, ExtractFetchReturn, ExtractResponse, ExtractError, CacheValueType, FetchLoadingEventType, FetchProgressType } from "@better-typed/hyper-fetch";

actions: UseDependentStateActions<ExtractResponse<T>, ExtractError<T>>;
invalidate: (invalidateKey: string | FetchCommandInstance | RegExp) => void;
onSubmitRequest: (callback: OnRequestCallbackType) => void;

@@ -101,4 +102,3 @@ onSubmitSuccess: (callback: OnSuccessCallbackType<ExtractResponse<T>>) => void;

// suspense = useSubmitDefaultOptions.suspense,
// invalidate = useSubmitDefaultOptions.invalidate,
shouldThrow }?: UseSubmitOptionsType<T>) => UseSubmitReturnType<T>;
export { useFetch, UseFetchOptionsType, UseFetchReturnType, OnRequestCallbackType, OnSuccessCallbackType, OnErrorCallbackType, OnFinishedCallbackType, OnStartCallbackType, OnProgressCallbackType, useSubmit };

@@ -1,2 +0,2 @@

import{useState as e,useRef as r}from"react";import{useDidMount as t,useWillUnmount as n,useDidUpdate as a}from"@better-typed/react-lifecycle-hooks";import{DateInterval as i,FetchCommand as o,getCommandKey as s}from"@better-typed/hyper-fetch";function u(e,r,t,n,a,i,o){try{var s=e[i](o),u=s.value}catch(e){return void t(e)}s.done?r(u):Promise.resolve(u).then(n,a)}function c(e){return function(){var r=this,t=arguments;return new Promise((function(n,a){var i=e.apply(r,t);function o(e){u(i,n,a,o,s,"next",e)}function s(e){u(i,n,a,o,s,"throw",e)}o(void 0)}))}}function l(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function d(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,a,i=[],o=!0,s=!1;try{for(t=t.call(e);!(o=(n=t.next()).done)&&(i.push(n.value),!r||i.length!==r);o=!0);}catch(e){s=!0,a=e}finally{try{o||null==t.return||t.return()}finally{if(s)throw a}}return i}}(e,r)||function(e,r){if(e){if("string"==typeof e)return l(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?l(e,r):void 0}}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var f=Object.prototype,h=f.hasOwnProperty,p="function"==typeof Symbol?Symbol:{},v=p.iterator||"@@iterator",m=p.asyncIterator||"@@asyncIterator",g=p.toStringTag||"@@toStringTag";function y(e,r,t,n){var a=r&&r.prototype instanceof O?r:O,i=Object.create(a.prototype),o=new M(n||[]);return i._invoke=function(e,r,t){var n="suspendedStart";return function(a,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===a)throw i;return _()}for(t.method=a,t.arg=i;;){var o=t.delegate;if(o){var s=P(o,t);if(s){if(s===w)continue;return s}}if("next"===t.method)t.sent=t._sent=t.arg;else if("throw"===t.method){if("suspendedStart"===n)throw n="completed",t.arg;t.dispatchException(t.arg)}else"return"===t.method&&t.abrupt("return",t.arg);n="executing";var u=b(e,r,t);if("normal"===u.type){if(n=t.done?"completed":"suspendedYield",u.arg===w)continue;return{value:u.arg,done:t.done}}"throw"===u.type&&(n="completed",t.method="throw",t.arg=u.arg)}}}(e,t,o),i}function b(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}var w={};function O(){}function x(){}function E(){}var k={};k[v]=function(){return this};var R=Object.getPrototypeOf,D=R&&R(R(K([])));D&&D!==f&&h.call(D,v)&&(k=D);var L=E.prototype=O.prototype=Object.create(k);function T(e){["next","throw","return"].forEach((function(r){e[r]=function(e){return this._invoke(r,e)}}))}function j(e){var r="function"==typeof e&&e.constructor;return!!r&&(r===x||"GeneratorFunction"===(r.displayName||r.name))}function S(e,r){function t(n,a,i,o){var s=b(e[n],e,a);if("throw"!==s.type){var u=s.arg,c=u.value;return c&&"object"==typeof c&&h.call(c,"__await")?r.resolve(c.__await).then((function(e){t("next",e,i,o)}),(function(e){t("throw",e,i,o)})):r.resolve(c).then((function(e){u.value=e,i(u)}),(function(e){return t("throw",e,i,o)}))}o(s.arg)}var n;this._invoke=function(e,a){function i(){return new r((function(r,n){t(e,a,r,n)}))}return n=n?n.then(i,i):i()}}function P(e,r){var t=e.iterator[r.method];if(undefined===t){if(r.delegate=null,"throw"===r.method){if(e.iterator.return&&(r.method="return",r.arg=undefined,P(e,r),"throw"===r.method))return w;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return w}var n=b(t,e.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,w;var a=n.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=undefined),r.delegate=null,w):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,w)}function F(e){var r={tryLoc:e[0]};1 in e&&(r.catchLoc=e[1]),2 in e&&(r.finallyLoc=e[2],r.afterLoc=e[3]),this.tryEntries.push(r)}function q(e){var r=e.completion||{};r.type="normal",delete r.arg,e.completion=r}function M(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(F,this),this.reset(!0)}function K(e){if(e){var r=e[v];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var t=-1,n=function r(){for(;++t<e.length;)if(h.call(e,t))return r.value=e[t],r.done=!1,r;return r.value=undefined,r.done=!0,r};return n.next=n}}return{next:_}}function _(){return{value:undefined,done:!0}}x.prototype=L.constructor=E,E.constructor=x,E[g]=x.displayName="GeneratorFunction",T(S.prototype),S.prototype[m]=function(){return this},T(L),L[g]="Generator",L[v]=function(){return this},L.toString=function(){return"[object Generator]"},M.prototype={constructor:M,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=undefined,this.done=!1,this.delegate=null,this.method="next",this.arg=undefined,this.tryEntries.forEach(q),!e)for(var r in this)"t"===r.charAt(0)&&h.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=undefined)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function t(t,n){return i.type="throw",i.arg=e,r.next=t,n&&(r.method="next",r.arg=undefined),!!n}for(var n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n],i=a.completion;if("root"===a.tryLoc)return t("end");if(a.tryLoc<=this.prev){var o=h.call(a,"catchLoc"),s=h.call(a,"finallyLoc");if(o&&s){if(this.prev<a.catchLoc)return t(a.catchLoc,!0);if(this.prev<a.finallyLoc)return t(a.finallyLoc)}else if(o){if(this.prev<a.catchLoc)return t(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return t(a.finallyLoc)}}}},abrupt:function(e,r){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc<=this.prev&&h.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var a=n;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=r&&r<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=r,a?(this.method="next",this.next=a.finallyLoc,w):this.complete(i)},complete:function(e,r){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&r&&(this.next=r),w},finish:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e)return this.complete(t.completion,t.afterLoc),q(t),w}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if("throw"===n.type){var a=n.arg;q(t)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,t){return this.delegate={iterator:K(e),resultName:r,nextLoc:t},"next"===this.method&&(this.arg=undefined),w}};var I={wrap:y,isGeneratorFunction:j,AsyncIterator:S,mark:function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,E):(e.__proto__=E,g in e||(e[g]="GeneratorFunction")),e.prototype=Object.create(L),e},awrap:function(e){return{__await:e}},async:function(e,r,t,n,a){void 0===a&&(a=Promise);var i=new S(y(e,r,t,n),a);return j(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},keys:function(e){var r=[];for(var t in e)r.push(t);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},values:K};function A(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var B=(e,r,t)=>{if(r&&e&&t&&+e.timestamp+t>+new Date)return e},C=e=>e?{response:e,retries:0,timestamp:+new Date,isRefreshed:!1}:null,N=(e,r)=>!r||!!e&&+new Date>+r+e,G={data:null,error:null,loading:!1,status:null,refreshError:null,retryError:null,isRefreshed:!1,retries:0,timestamp:null,isOnline:!0,isFocused:!0};function U(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function Q(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?U(Object(t),!0).forEach((function(r){A(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):U(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var Y=(e,r,t)=>{var n,a,i,o;return Q(Q({},G),{},{data:(null==r||null===(n=r.response)||void 0===n?void 0:n[0])||G.data,error:(null==r||null===(a=r.response)||void 0===a?void 0:a[1])||G.error,status:(null==r||null===(i=r.response)||void 0===i?void 0:i[2])||G.status,retries:(null==r?void 0:r.retries)||G.retries,timestamp:(o=(null==r?void 0:r.timestamp)||G.timestamp,o?new Date(o):null),isOnline:e.builder.appManager.isOnline,isFocused:e.builder.appManager.isFocused,loading:null!=t?t:G.loading})};function $(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function z(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?$(Object(t),!0).forEach((function(r){A(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):$(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var H=(n,a,i)=>{var o,s=n.builder,u=n.cache,l=n.cacheKey,f=n.cacheTime,h=n.queueKey,p=d(e(!1),2),v=p[0],m=p[1],g=d(e(+new Date),2)[1],y=r(Y(n,(o=a)?{response:o,retries:0,timestamp:+new Date,isRefreshed:!1}:null)),b=r([]),w=e=>{b.current.find((r=>e.includes(r)))&&g(+new Date)};t((()=>{(function(){var e=c(I.mark((function e(){var r,t,o,c,d;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,s.cache.get(l);case 2:return r=e.sent,t=B(r,u,f),o=N(f,null==t?void 0:t.timestamp),c=o?C(a):t,e.next=8,i.get(h);case 8:d=e.sent,y.current=Y(n,c,y.current.loading||!!d.requests.length),m(!0),g(+new Date);case 12:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}})()()})),t((()=>{var e=s.appManager.events.onFocus((()=>{y.current.isFocused=!0,w(["isFocused"])})),r=s.appManager.events.onBlur((()=>{y.current.isFocused=!1,w(["isFocused"])})),t=s.appManager.events.onOnline((()=>{y.current.isOnline=!0,w(["isOnline"])})),n=s.appManager.events.onOffline((()=>{y.current.isOnline=!1,w(["isOnline"])}));return()=>{e(),r(),t(),n()}}));var O,x,E,k,R,D,L,T,j,S,P={setCacheData:(S=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=6;break}return e.next=4,s.cache.set(z({cache:u,cacheKey:l},r));case 4:e.next=9;break;case 6:t={data:r.response[0],error:r.response[1],status:r.response[2],retries:r.retries,timestamp:new Date(r.timestamp),retryError:r.retryError,refreshError:r.refreshError,isRefreshed:r.isRefreshed,loading:!1},y.current=z(z({},y.current),t),w(Object.keys(t));case 9:case"end":return e.stop()}}),e)}))),function(e){return S.apply(this,arguments)}),setData:(j=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[r,t.error,t.status],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:y.current.data=r,w(["data"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return j.apply(this,arguments)}),setError:(T=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[t.data,r,t.status],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:y.current.error=r,w(["error"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return T.apply(this,arguments)}),setLoading:(L=c(I.mark((function e(r){var t=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t.length>1&&void 0!==t[1]&&!t[1]?(y.current.loading=r,w(["loading"])):s.fetchQueue.events.setLoading(l,{isLoading:r,isRetry:!1});case 2:case"end":return e.stop()}}),e)}))),function(e){return L.apply(this,arguments)}),setStatus:(D=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[t.data,t.error,r],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:y.current.status=r,w(["status"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return D.apply(this,arguments)}),setRefreshed:(R=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[t.data,t.error,t.status],retries:t.retries,isRefreshed:r});case 5:e.next=9;break;case 7:y.current.isRefreshed=r,w(["isRefreshed"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return R.apply(this,arguments)}),setRefreshError:(k=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[t.data,r,t.status],retries:t.retries,isRefreshed:!0});case 5:e.next=9;break;case 7:y.current.refreshError=r,w(["refreshError"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return k.apply(this,arguments)}),setRetryError:(E=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[t.data,r,t.status],retries:t.retries,isRefreshed:!0});case 5:e.next=9;break;case 7:y.current.retryError=r,w(["retryError"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return E.apply(this,arguments)}),setRetries:(x=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[t.data,t.error,t.status],retries:r,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:y.current.retries=r,w(["retries"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return x.apply(this,arguments)}),setTimestamp:(O=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[t.data,t.error,t.status],retries:t.retries,isRefreshed:t.isRefreshed,timestamp:r?+r:void 0});case 5:e.next=9;break;case 7:y.current.timestamp=r,w(["timestamp"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return O.apply(this,arguments)})};return[y.current,P,e=>{b.current.push(e)},v]},J=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:600,t=r({time:e,timer:null});t.current.time=e;var a=()=>{t.current.timer&&clearTimeout(t.current.timer),t.current.timer=null},i=e=>{a(),t.current.timer=setTimeout((()=>{t.current.timer=null,e()}),t.current.time)};return n(a),{debounce:i,resetDebounce:a,active:!!t.current.timer}},V=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:600,t=r({time:e,timer:null});t.current.time=e;var a=()=>{t.current.timer&&clearInterval(t.current.timer),t.current.timer=null},i=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;a(),t.current.timer=setInterval((()=>{e()}),r<=0?t.current.time:r)};return n(a),{interval:i,resetInterval:a,active:!!t.current.timer}},W={dependencies:[],disabled:!1,dependencyTracking:!0,cacheOnMount:!0,revalidateOnMount:!0,initialData:null,refresh:!1,refreshTime:i.hour,refreshBlurred:!1,refreshOnTabBlur:!1,refreshOnTabFocus:!1,refreshOnReconnect:!1,cancelable:!1,debounce:!1,debounceTime:400,deepCompareFn:void 0,responseDataModifierFn:null,shouldThrow:!1},X=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:W,i=n.dependencies,u=void 0===i?W.dependencies:i,l=n.disabled,f=void 0===l?W.disabled:l,h=n.dependencyTracking,p=void 0===h?W.dependencyTracking:h,v=n.revalidateOnMount,m=void 0===v?W.revalidateOnMount:v,g=n.initialData,y=void 0===g?W.initialData:g,b=n.refresh,w=void 0===b?W.refresh:b,O=n.refreshTime,x=void 0===O?W.refreshTime:O,E=n.refreshBlurred,k=void 0===E?W.refreshBlurred:E,R=n.refreshOnTabBlur,D=void 0===R?W.refreshOnTabBlur:R,L=n.refreshOnTabFocus,T=void 0===L?W.refreshOnTabFocus:L,j=n.refreshOnReconnect,S=void 0===j?W.refreshOnReconnect:j,P=n.debounce,F=void 0===P?W.debounce:P,q=n.debounceTime,M=void 0===q?W.debounceTime:q,K=n.shouldThrow,_=void 0===K?W.shouldThrow:K,A=e.cacheTime,B=e.cacheKey,C=e.queueKey,G=e.builder,U=J(M),Q=V(x),Y=G.cache,$=G.fetchQueue,z=G.appManager,X=G.commandManager,Z=G.loggerManager,ee=r(Z.init("useFetch")).current,re=H(e,y,$),te=d(re,4),ne=te[0],ae=te[1],ie=te[2],oe=te[3],se=r(null),ue=r(null),ce=r(null),le=r(null),de=r(null),fe=r(null),he=r(null),pe=r(null),ve=()=>{f?ee.debug("Cannot add to fetch queue",{disabled:f}):(ee.debug("Adding request to fetch queue"),$.add(e))},me=()=>{Q.resetInterval();var r=ne.timestamp,t=r?Math.max(+r+x-+new Date,x):x;w&&(ee.debug("Starting refresh counter, request will be send in ".concat(t,"ms")),Q.interval(c(I.mark((function r(){var t,n,a;return I.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,$.get(C);case 2:t=r.sent,n=!e.builder.appManager.isFocused,a=n&&k||e.builder.appManager.isFocused,!!!t.requests.length&&a&&(ee.info("Performing refresh request"),ve(),Q.resetInterval());case 8:case"end":return r.stop()}}),r)}))),t))},ge=e=>{if(e){var r,t,n;if(e[0])null==ue||null===(t=ue.current)||void 0===t||t.call(ue,e[0]);if(e[1])if(null==ce||null===(n=ce.current)||void 0===n||n.call(ce,e[1]),_)throw{message:"Fetching Error.",error:e[1]};null==le||null===(r=le.current)||void 0===r||r.call(le,e)}},ye=function(){var e=c(I.mark((function e(r){return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:ge(r.response),ae.setCacheData(r,!1),ae.setLoading(!1,!1);case 3:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}(),be=(e,r)=>{ge([ne.data,ne.error,ne.status]),ae.setRefreshed(e,!1),ae.setTimestamp(new Date(r),!1),ae.setLoading(!1,!1)},we=e=>{var r,t=e.isLoading,n=e.isRetry;ae.setLoading(t,!1),null===(r=se.current)||void 0===r||r.call(se,{isRetry:n})},Oe=()=>{ve()},xe=r=>{r&&"string"==typeof r?e.builder.cache.events.revalidate(r):r&&r instanceof o?e.builder.cache.events.revalidate(s(r)):Oe()},Ee=e=>{var r;null==he||null===(r=he.current)||void 0===r||r.call(he,e)},ke=e=>{var r;null==pe||null===(r=pe.current)||void 0===r||r.call(pe,e)},Re=e=>{var r;null==de||null===(r=de.current)||void 0===r||r.call(de,e)},De=e=>{var r;null==de||null===(r=de.current)||void 0===r||r.call(de,e)},Le=()=>{var e=z.events.onFocus((()=>T&&ve())),r=z.events.onBlur((()=>D&&ve())),t=z.events.onOnline((()=>S&&ve())),n=X.events.onDownloadProgress(C,Ee),a=X.events.onUploadProgress(C,ke),i=X.events.onRequestStart(C,Re),o=X.events.onResponseStart(C,De),s=$.events.getLoading(C,we),u=Y.events.get(B,ye),c=Y.events.getEqualData(B,be),l=Y.events.onRevalidate(B,Oe);return()=>{e(),r(),t(),n(),a(),i(),o(),s(),u(),c(),l()}},Te=()=>{p||Object.keys(ne).forEach((e=>ie(e)))};return t((()=>((m||N(A,ne.timestamp))&&ve(),Te(),Le()))),a((()=>{oe&&ge([ne.data,ne.error,ne.status])}),[oe],!0),a((()=>{!$.requestCount&&F?U.debounce((()=>ve())):ve()}),[...u,f]),a((()=>{me()}),[w,x,ne.timestamp],!0),{get data(){return ie("data"),ne.data},get error(){return ie("error"),ne.error},get loading(){return ie("loading"),ne.loading},get status(){return ie("status"),ne.status},get retryError(){return ie("retryError"),ne.retryError},get refreshError(){return ie("refreshError"),ne.refreshError},get isRefreshed(){return ie("isRefreshed"),ne.isRefreshed},get retries(){return ie("retries"),ne.retries},get timestamp(){return ie("timestamp"),ne.timestamp},get isOnline(){return ie("isOnline"),ne.isOnline},get isFocused(){return ie("isFocused"),ne.isFocused},get isStale(){return N(A,ne.timestamp)},actions:ae,onRequest:e=>{se.current=e},onSuccess:e=>{ue.current=e},onError:e=>{ce.current=e},onFinished:e=>{le.current=e},onRequestStart:e=>{de.current=e},onResponseStart:e=>{fe.current=e},onDownloadProgress:e=>{he.current=e},onUploadProgress:e=>{pe.current=e},isRefreshingError:!!ne.error&&ne.isRefreshed,isDebouncing:U.active,refresh:xe}},Z={disabled:!1,dependencyTracking:!0,cacheOnMount:!0,initialData:null,debounce:!1,debounceTime:400,suspense:!1,shouldThrow:!1,responseDataModifierFn:null,invalidate:[]},ee=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z,a=n.disabled,i=void 0===a?Z.disabled:a,o=n.dependencyTracking,s=void 0===o?Z.dependencyTracking:o,u=n.initialData,l=void 0===u?Z.initialData:u,f=n.debounce,h=void 0===f?Z.debounce:f,p=n.debounceTime,v=void 0===p?Z.debounceTime:p,m=n.shouldThrow,g=void 0===m?Z.shouldThrow:m,y=e.cacheTime,b=e.cacheKey,w=e.queueKey,O=e.builder,x=J(v),E=O.cache,k=O.submitQueue,R=O.commandManager,D=O.loggerManager,L=r(D.init("useSubmit")).current,T=H(e,l,k),j=d(T,3),S=j[0],P=j[1],F=j[2],q=r(null),M=r(null),K=r(null),_=r(null),A=r(null),B=r(null),C=r(null),G=r(null),U=function(){var r=e,t=arguments.length<=0?void 0:arguments[0];null!=t&&t.data&&(r=r.setData(t.data)),null!=t&&t.params&&(r=r.setParams(t.params)),null!=t&&t.queryParams&&(r=r.setQueryParams(t.queryParams)),i?L.debug("Cannot add to submit queue",{disabled:i,options:t}):(L.debug("Adding request to submit queue",{disabled:i,options:t}),h?x.debounce((()=>k.add(r))):k.add(r))},Q=e=>{if(e){var r,t,n;if(e[0])null==M||null===(t=M.current)||void 0===t||t.call(M,e[0]);if(e[1])if(null==K||null===(n=K.current)||void 0===n||n.call(K,e[1]),g)throw{message:"Fetching Error.",error:e[1]};null==_||null===(r=_.current)||void 0===r||r.call(_,e)}},Y=function(){var e=c(I.mark((function e(r){return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:Q(r.response),P.setCacheData(r,!1),P.setLoading(!1,!1);case 3:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}(),$=(e,r)=>{Q([S.data,S.error,S.status]),P.setRefreshed(e,!1),P.setTimestamp(new Date(r),!1),P.setLoading(!1,!1)},z=e=>{var r,t=e.isLoading,n=e.isRetry;P.setLoading(t,!1),null===(r=q.current)||void 0===r||r.call(q,{isRetry:n})},V=e=>{var r;null==C||null===(r=C.current)||void 0===r||r.call(C,e)},W=e=>{var r;null==G||null===(r=G.current)||void 0===r||r.call(G,e)},X=e=>{var r;null==A||null===(r=A.current)||void 0===r||r.call(A,e)},ee=e=>{var r;null==A||null===(r=A.current)||void 0===r||r.call(A,e)},re=()=>{var e=R.events.onDownloadProgress(w,V),r=R.events.onUploadProgress(w,W),t=R.events.onRequestStart(w,X),n=R.events.onResponseStart(w,ee),a=k.events.getLoading(w,z),i=E.events.get(w,Y),o=E.events.getEqualData(b,$);return()=>{e(),r(),t(),n(),a(),i(),o()}},te=()=>{s||Object.keys(S).forEach((e=>F(e)))};return t((()=>(te(),re()))),{submit:U,get data(){return F("data"),S.data},get error(){return F("error"),S.error},get submitting(){return F("loading"),S.loading},get status(){return F("status"),S.status},get retryError(){return F("retryError"),S.retryError},get retries(){return F("retries"),S.retries},get timestamp(){return F("timestamp"),S.timestamp},get isOnline(){return F("isOnline"),S.isOnline},get isFocused(){return F("isFocused"),S.isFocused},get isStale(){return N(y,S.timestamp)},actions:P,isDebouncing:!1,isRefreshed:!1,onSubmitRequest:e=>{q.current=e},onSubmitSuccess:e=>{M.current=e},onSubmitError:e=>{K.current=e},onSubmitFinished:e=>{_.current=e},onSubmitRequestStart:e=>{A.current=e},onSubmitResponseStart:e=>{B.current=e},onSubmitDownloadProgress:e=>{C.current=e},onSubmitUploadProgress:e=>{G.current=e}}};export{X as useFetch,ee as useSubmit};
import{useState as e,useRef as r}from"react";import{useDidMount as t,useWillUnmount as n,useDidUpdate as a}from"@better-typed/react-lifecycle-hooks";import{DateInterval as i,FetchCommand as o,getCommandKey as s}from"@better-typed/hyper-fetch";function u(e,r,t,n,a,i,o){try{var s=e[i](o),u=s.value}catch(e){return void t(e)}s.done?r(u):Promise.resolve(u).then(n,a)}function c(e){return function(){var r=this,t=arguments;return new Promise((function(n,a){var i=e.apply(r,t);function o(e){u(i,n,a,o,s,"next",e)}function s(e){u(i,n,a,o,s,"throw",e)}o(void 0)}))}}function l(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function d(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,a,i=[],o=!0,s=!1;try{for(t=t.call(e);!(o=(n=t.next()).done)&&(i.push(n.value),!r||i.length!==r);o=!0);}catch(e){s=!0,a=e}finally{try{o||null==t.return||t.return()}finally{if(s)throw a}}return i}}(e,r)||function(e,r){if(e){if("string"==typeof e)return l(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?l(e,r):void 0}}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var f=Object.prototype,h=f.hasOwnProperty,p="function"==typeof Symbol?Symbol:{},v=p.iterator||"@@iterator",m=p.asyncIterator||"@@asyncIterator",g=p.toStringTag||"@@toStringTag";function y(e,r,t,n){var a=r&&r.prototype instanceof O?r:O,i=Object.create(a.prototype),o=new M(n||[]);return i._invoke=function(e,r,t){var n="suspendedStart";return function(a,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===a)throw i;return _()}for(t.method=a,t.arg=i;;){var o=t.delegate;if(o){var s=P(o,t);if(s){if(s===w)continue;return s}}if("next"===t.method)t.sent=t._sent=t.arg;else if("throw"===t.method){if("suspendedStart"===n)throw n="completed",t.arg;t.dispatchException(t.arg)}else"return"===t.method&&t.abrupt("return",t.arg);n="executing";var u=b(e,r,t);if("normal"===u.type){if(n=t.done?"completed":"suspendedYield",u.arg===w)continue;return{value:u.arg,done:t.done}}"throw"===u.type&&(n="completed",t.method="throw",t.arg=u.arg)}}}(e,t,o),i}function b(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}var w={};function O(){}function x(){}function E(){}var k={};k[v]=function(){return this};var R=Object.getPrototypeOf,T=R&&R(R(K([])));T&&T!==f&&h.call(T,v)&&(k=T);var D=E.prototype=O.prototype=Object.create(k);function L(e){["next","throw","return"].forEach((function(r){e[r]=function(e){return this._invoke(r,e)}}))}function j(e){var r="function"==typeof e&&e.constructor;return!!r&&(r===x||"GeneratorFunction"===(r.displayName||r.name))}function S(e,r){function t(n,a,i,o){var s=b(e[n],e,a);if("throw"!==s.type){var u=s.arg,c=u.value;return c&&"object"==typeof c&&h.call(c,"__await")?r.resolve(c.__await).then((function(e){t("next",e,i,o)}),(function(e){t("throw",e,i,o)})):r.resolve(c).then((function(e){u.value=e,i(u)}),(function(e){return t("throw",e,i,o)}))}o(s.arg)}var n;this._invoke=function(e,a){function i(){return new r((function(r,n){t(e,a,r,n)}))}return n=n?n.then(i,i):i()}}function P(e,r){var t=e.iterator[r.method];if(undefined===t){if(r.delegate=null,"throw"===r.method){if(e.iterator.return&&(r.method="return",r.arg=undefined,P(e,r),"throw"===r.method))return w;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return w}var n=b(t,e.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,w;var a=n.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=undefined),r.delegate=null,w):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,w)}function F(e){var r={tryLoc:e[0]};1 in e&&(r.catchLoc=e[1]),2 in e&&(r.finallyLoc=e[2],r.afterLoc=e[3]),this.tryEntries.push(r)}function q(e){var r=e.completion||{};r.type="normal",delete r.arg,e.completion=r}function M(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(F,this),this.reset(!0)}function K(e){if(e){var r=e[v];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var t=-1,n=function r(){for(;++t<e.length;)if(h.call(e,t))return r.value=e[t],r.done=!1,r;return r.value=undefined,r.done=!0,r};return n.next=n}}return{next:_}}function _(){return{value:undefined,done:!0}}x.prototype=D.constructor=E,E.constructor=x,E[g]=x.displayName="GeneratorFunction",L(S.prototype),S.prototype[m]=function(){return this},L(D),D[g]="Generator",D[v]=function(){return this},D.toString=function(){return"[object Generator]"},M.prototype={constructor:M,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=undefined,this.done=!1,this.delegate=null,this.method="next",this.arg=undefined,this.tryEntries.forEach(q),!e)for(var r in this)"t"===r.charAt(0)&&h.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=undefined)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function t(t,n){return i.type="throw",i.arg=e,r.next=t,n&&(r.method="next",r.arg=undefined),!!n}for(var n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n],i=a.completion;if("root"===a.tryLoc)return t("end");if(a.tryLoc<=this.prev){var o=h.call(a,"catchLoc"),s=h.call(a,"finallyLoc");if(o&&s){if(this.prev<a.catchLoc)return t(a.catchLoc,!0);if(this.prev<a.finallyLoc)return t(a.finallyLoc)}else if(o){if(this.prev<a.catchLoc)return t(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return t(a.finallyLoc)}}}},abrupt:function(e,r){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc<=this.prev&&h.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var a=n;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=r&&r<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=r,a?(this.method="next",this.next=a.finallyLoc,w):this.complete(i)},complete:function(e,r){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&r&&(this.next=r),w},finish:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e)return this.complete(t.completion,t.afterLoc),q(t),w}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if("throw"===n.type){var a=n.arg;q(t)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,t){return this.delegate={iterator:K(e),resultName:r,nextLoc:t},"next"===this.method&&(this.arg=undefined),w}};var I={wrap:y,isGeneratorFunction:j,AsyncIterator:S,mark:function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,E):(e.__proto__=E,g in e||(e[g]="GeneratorFunction")),e.prototype=Object.create(D),e},awrap:function(e){return{__await:e}},async:function(e,r,t,n,a){void 0===a&&(a=Promise);var i=new S(y(e,r,t,n),a);return j(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},keys:function(e){var r=[];for(var t in e)r.push(t);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},values:K};function A(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var N=(e,r,t)=>{if(r&&e&&t&&+e.timestamp+t>+new Date)return e},B=e=>e?{response:e,retries:0,timestamp:+new Date,isRefreshed:!1}:null,C=(e,r)=>!r||!!e&&+new Date>+r+e,G={data:null,error:null,loading:!1,status:null,refreshError:null,retryError:null,isRefreshed:!1,retries:0,timestamp:null,isOnline:!0,isFocused:!0};function U(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function Q(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?U(Object(t),!0).forEach((function(r){A(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):U(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var Y=(e,r,t)=>{var n,a,i,o;return Q(Q({},G),{},{data:(null==r||null===(n=r.response)||void 0===n?void 0:n[0])||G.data,error:(null==r||null===(a=r.response)||void 0===a?void 0:a[1])||G.error,status:(null==r||null===(i=r.response)||void 0===i?void 0:i[2])||G.status,retries:(null==r?void 0:r.retries)||G.retries,timestamp:(o=(null==r?void 0:r.timestamp)||G.timestamp,o?new Date(o):null),isOnline:e.builder.appManager.isOnline,isFocused:e.builder.appManager.isFocused,loading:null!=t?t:G.loading})};function $(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function z(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?$(Object(t),!0).forEach((function(r){A(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):$(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var H=(n,a,i)=>{var o,s=n.builder,u=n.cache,l=n.cacheKey,f=n.cacheTime,h=n.queueKey,p=d(e(!1),2),v=p[0],m=p[1],g=d(e(+new Date),2)[1],y=r(Y(n,(o=a)?{response:o,retries:0,timestamp:+new Date,isRefreshed:!1}:null)),b=r([]),w=e=>{b.current.find((r=>e.includes(r)))&&g(+new Date)};t((()=>{(function(){var e=c(I.mark((function e(){var r,t,o,c,d;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,s.cache.get(l);case 2:return r=e.sent,t=N(r,u,f),o=C(f,null==t?void 0:t.timestamp),c=o?B(a):t,e.next=8,i.get(h);case 8:d=e.sent,y.current=Y(n,c,y.current.loading||!!d.requests.length),m(!0),g(+new Date);case 12:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}})()()})),t((()=>{var e=s.appManager.events.onFocus((()=>{y.current.isFocused=!0,w(["isFocused"])})),r=s.appManager.events.onBlur((()=>{y.current.isFocused=!1,w(["isFocused"])})),t=s.appManager.events.onOnline((()=>{y.current.isOnline=!0,w(["isOnline"])})),n=s.appManager.events.onOffline((()=>{y.current.isOnline=!1,w(["isOnline"])}));return()=>{e(),r(),t(),n()}}));var O,x,E,k,R,T,D,L,j,S,P={setCacheData:(S=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=6;break}return e.next=4,s.cache.set(z({cache:u,cacheKey:l},r));case 4:e.next=9;break;case 6:t={data:r.response[0],error:r.response[1],status:r.response[2],retries:r.retries,timestamp:new Date(r.timestamp),retryError:r.retryError,refreshError:r.refreshError,isRefreshed:r.isRefreshed,loading:!1},y.current=z(z({},y.current),t),w(Object.keys(t));case 9:case"end":return e.stop()}}),e)}))),function(e){return S.apply(this,arguments)}),setData:(j=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[r,t.error,t.status],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:y.current.data=r,w(["data"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return j.apply(this,arguments)}),setError:(L=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[t.data,r,t.status],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:y.current.error=r,w(["error"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return L.apply(this,arguments)}),setLoading:(D=c(I.mark((function e(r){var t=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t.length>1&&void 0!==t[1]&&!t[1]?(y.current.loading=r,w(["loading"])):s.fetchQueue.events.setLoading(l,{isLoading:r,isRetry:!1});case 2:case"end":return e.stop()}}),e)}))),function(e){return D.apply(this,arguments)}),setStatus:(T=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[t.data,t.error,r],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:y.current.status=r,w(["status"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return T.apply(this,arguments)}),setRefreshed:(R=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[t.data,t.error,t.status],retries:t.retries,isRefreshed:r});case 5:e.next=9;break;case 7:y.current.isRefreshed=r,w(["isRefreshed"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return R.apply(this,arguments)}),setRefreshError:(k=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[t.data,r,t.status],retries:t.retries,isRefreshed:!0});case 5:e.next=9;break;case 7:y.current.refreshError=r,w(["refreshError"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return k.apply(this,arguments)}),setRetryError:(E=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[t.data,r,t.status],retries:t.retries,isRefreshed:!0});case 5:e.next=9;break;case 7:y.current.retryError=r,w(["retryError"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return E.apply(this,arguments)}),setRetries:(x=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[t.data,t.error,t.status],retries:r,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:y.current.retries=r,w(["retries"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return x.apply(this,arguments)}),setTimestamp:(O=c(I.mark((function e(r){var t,n=arguments;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length>1&&void 0!==n[1]&&!n[1]){e.next=7;break}return t=y.current,e.next=5,s.cache.set({cache:u,cacheKey:l,response:[t.data,t.error,t.status],retries:t.retries,isRefreshed:t.isRefreshed,timestamp:r?+r:void 0});case 5:e.next=9;break;case 7:y.current.timestamp=r,w(["timestamp"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return O.apply(this,arguments)})};return[y.current,P,e=>{b.current.push(e)},v]},J=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:600,t=r({time:e,timer:null});t.current.time=e;var a=()=>{t.current.timer&&clearTimeout(t.current.timer),t.current.timer=null},i=e=>{a(),t.current.timer=setTimeout((()=>{t.current.timer=null,e()}),t.current.time)};return n(a),{debounce:i,resetDebounce:a,active:!!t.current.timer}},V=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:600,t=r({time:e,timer:null});t.current.time=e;var a=()=>{t.current.timer&&clearInterval(t.current.timer),t.current.timer=null},i=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;a(),t.current.timer=setInterval((()=>{e()}),r<=0?t.current.time:r)};return n(a),{interval:i,resetInterval:a,active:!!t.current.timer}},W={dependencies:[],disabled:!1,dependencyTracking:!0,cacheOnMount:!0,revalidateOnMount:!0,initialData:null,refresh:!1,refreshTime:i.hour,refreshBlurred:!1,refreshOnTabBlur:!1,refreshOnTabFocus:!1,refreshOnReconnect:!1,cancelable:!1,debounce:!1,debounceTime:400,deepCompareFn:void 0,responseDataModifierFn:null,shouldThrow:!1},X=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:W,i=n.dependencies,u=void 0===i?W.dependencies:i,l=n.disabled,f=void 0===l?W.disabled:l,h=n.dependencyTracking,p=void 0===h?W.dependencyTracking:h,v=n.revalidateOnMount,m=void 0===v?W.revalidateOnMount:v,g=n.initialData,y=void 0===g?W.initialData:g,b=n.refresh,w=void 0===b?W.refresh:b,O=n.refreshTime,x=void 0===O?W.refreshTime:O,E=n.refreshBlurred,k=void 0===E?W.refreshBlurred:E,R=n.refreshOnTabBlur,T=void 0===R?W.refreshOnTabBlur:R,D=n.refreshOnTabFocus,L=void 0===D?W.refreshOnTabFocus:D,j=n.refreshOnReconnect,S=void 0===j?W.refreshOnReconnect:j,P=n.debounce,F=void 0===P?W.debounce:P,q=n.debounceTime,M=void 0===q?W.debounceTime:q,K=n.shouldThrow,_=void 0===K?W.shouldThrow:K,A=e.cacheTime,N=e.cacheKey,B=e.queueKey,G=e.builder,U=J(M),Q=V(x),Y=G.cache,$=G.fetchQueue,z=G.appManager,X=G.commandManager,Z=G.loggerManager,ee=r(Z.init("useFetch")).current,re=H(e,y,$),te=d(re,4),ne=te[0],ae=te[1],ie=te[2],oe=te[3],se=r(null),ue=r(null),ce=r(null),le=r(null),de=r(null),fe=r(null),he=r(null),pe=r(null),ve=()=>{f?ee.debug("Cannot add to fetch queue",{disabled:f}):(ee.debug("Adding request to fetch queue"),$.add(e))},me=()=>{Q.resetInterval();var r=ne.timestamp,t=r?Math.max(+r+x-+new Date,x):x;w&&(ee.debug("Starting refresh counter, request will be send in ".concat(t,"ms")),Q.interval(c(I.mark((function r(){var t,n,a;return I.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,$.get(B);case 2:t=r.sent,n=!e.builder.appManager.isFocused,a=n&&k||e.builder.appManager.isFocused,!!!t.requests.length&&a&&(ee.info("Performing refresh request"),ve(),Q.resetInterval());case 8:case"end":return r.stop()}}),r)}))),t))},ge=e=>{if(e){var r,t,n;if(e[0])null==ue||null===(t=ue.current)||void 0===t||t.call(ue,e[0]);if(e[1])if(null==ce||null===(n=ce.current)||void 0===n||n.call(ce,e[1]),_)throw{message:"Fetching Error.",error:e[1]};null==le||null===(r=le.current)||void 0===r||r.call(le,e)}},ye=function(){var e=c(I.mark((function e(r){return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:ge(r.response),ae.setCacheData(r,!1),ae.setLoading(!1,!1);case 3:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}(),be=(e,r,t)=>{ge(e.response),ae.setRefreshed(r,!1),ae.setTimestamp(new Date(t),!1),ae.setLoading(!1,!1)},we=e=>{var r,t=e.isLoading,n=e.isRetry;ae.setLoading(t,!1),null===(r=se.current)||void 0===r||r.call(se,{isRetry:n})},Oe=()=>{ve()},xe=r=>{r&&r instanceof o?e.builder.cache.events.revalidate("/".concat(s(r,!0),"/")):r?e.builder.cache.events.revalidate(r):Oe()},Ee=e=>{var r;null==he||null===(r=he.current)||void 0===r||r.call(he,e)},ke=e=>{var r;null==pe||null===(r=pe.current)||void 0===r||r.call(pe,e)},Re=e=>{var r;null==de||null===(r=de.current)||void 0===r||r.call(de,e)},Te=e=>{var r;null==de||null===(r=de.current)||void 0===r||r.call(de,e)},De=()=>{var e=z.events.onFocus((()=>L&&ve())),r=z.events.onBlur((()=>T&&ve())),t=z.events.onOnline((()=>S&&ve())),n=X.events.onDownloadProgress(B,Ee),a=X.events.onUploadProgress(B,ke),i=X.events.onRequestStart(B,Re),o=X.events.onResponseStart(B,Te),s=$.events.getLoading(B,we),u=Y.events.get(N,ye),c=Y.events.getEqualData(N,be),l=Y.events.onRevalidate(N,Oe);return()=>{e(),r(),t(),n(),a(),i(),o(),s(),u(),c(),l()}},Le=()=>{p||Object.keys(ne).forEach((e=>ie(e)))};return t((()=>((m||C(A,ne.timestamp))&&ve(),Le(),De()))),a((()=>{oe&&ge([ne.data,ne.error,ne.status])}),[oe],!0),a((()=>{!$.requestCount&&F?U.debounce((()=>ve())):ve()}),[...u,f]),a((()=>{me()}),[w,x,ne.timestamp],!0),{get data(){return ie("data"),ne.data},get error(){return ie("error"),ne.error},get loading(){return ie("loading"),ne.loading},get status(){return ie("status"),ne.status},get retryError(){return ie("retryError"),ne.retryError},get refreshError(){return ie("refreshError"),ne.refreshError},get isRefreshed(){return ie("isRefreshed"),ne.isRefreshed},get retries(){return ie("retries"),ne.retries},get timestamp(){return ie("timestamp"),ne.timestamp},get isOnline(){return ie("isOnline"),ne.isOnline},get isFocused(){return ie("isFocused"),ne.isFocused},get isStale(){return C(A,ne.timestamp)},actions:ae,onRequest:e=>{se.current=e},onSuccess:e=>{ue.current=e},onError:e=>{ce.current=e},onFinished:e=>{le.current=e},onRequestStart:e=>{de.current=e},onResponseStart:e=>{fe.current=e},onDownloadProgress:e=>{he.current=e},onUploadProgress:e=>{pe.current=e},isRefreshingError:!!ne.error&&ne.isRefreshed,isDebouncing:U.active,refresh:xe}},Z={disabled:!1,dependencyTracking:!0,cacheOnMount:!0,initialData:null,debounce:!1,debounceTime:400,suspense:!1,shouldThrow:!1,responseDataModifierFn:null,invalidate:[]},ee=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z,a=n.disabled,i=void 0===a?Z.disabled:a,u=n.dependencyTracking,c=void 0===u?Z.dependencyTracking:u,l=n.initialData,f=void 0===l?Z.initialData:l,h=n.debounce,p=void 0===h?Z.debounce:h,v=n.debounceTime,m=void 0===v?Z.debounceTime:v,g=n.shouldThrow,y=void 0===g?Z.shouldThrow:g,b=e.cacheTime,w=e.cacheKey,O=e.queueKey,x=e.builder,E=J(m),k=x.cache,R=x.submitQueue,T=x.commandManager,D=x.loggerManager,L=r(D.init("useSubmit")).current,j=H(e,f,R),S=d(j,3),P=S[0],F=S[1],q=S[2],M=r(null),K=r(null),_=r(null),I=r(null),A=r(null),N=r(null),B=r(null),G=r(null),U=function(){var r=e,t=arguments.length<=0?void 0:arguments[0];if(null!=t&&t.data&&(r=r.setData(t.data)),null!=t&&t.params&&(r=r.setParams(t.params)),null!=t&&t.queryParams&&(r=r.setQueryParams(t.queryParams)),i)L.debug("Cannot add to submit queue",{disabled:i,options:t});else{if(L.debug("Adding request to submit queue",{disabled:i,options:t}),!p)return r.send({queueType:"submit"});E.debounce((()=>{r.send({queueType:"submit"})}))}},Q=e=>{if(e){var r,t,n;if(e[0])null==K||null===(t=K.current)||void 0===t||t.call(K,e[0]);if(e[1])if(null==_||null===(n=_.current)||void 0===n||n.call(_,e[1]),y)throw{message:"Fetching Error.",error:e[1]};null==I||null===(r=I.current)||void 0===r||r.call(I,e)}else L.debug("No response to perform callbacks")},Y=e=>{Q(e.response),F.setLoading(!1,!1),F.setCacheData(e,!1)},$=(e,r,t)=>{Q(e.response),F.setRefreshed(r,!1),F.setTimestamp(new Date(t),!1),F.setLoading(!1,!1)},z=e=>{var r,t=e.isLoading,n=e.isRetry;F.setLoading(t,!1),null===(r=M.current)||void 0===r||r.call(M,{isRetry:n})},V=e=>{var r;null==B||null===(r=B.current)||void 0===r||r.call(B,e)},W=e=>{var r;null==G||null===(r=G.current)||void 0===r||r.call(G,e)},X=e=>{var r;null==A||null===(r=A.current)||void 0===r||r.call(A,e)},ee=e=>{var r;null==A||null===(r=A.current)||void 0===r||r.call(A,e)},re=()=>{var e=T.events.onDownloadProgress(O,V),r=T.events.onUploadProgress(O,W),t=T.events.onRequestStart(O,X),n=T.events.onResponseStart(O,ee),a=R.events.getLoading(O,z),i=k.events.get(O,Y),o=k.events.getEqualData(w,$);return()=>{e(),r(),t(),n(),a(),i(),o()}},te=()=>{c||Object.keys(P).forEach((e=>q(e)))},ne=r=>{r&&r instanceof o?e.builder.cache.events.revalidate("/".concat(s(r,!0),"/")):e.builder.cache.events.revalidate(r)};return t((()=>(te(),re()))),{submit:U,get data(){return q("data"),P.data},get error(){return q("error"),P.error},get submitting(){return q("loading"),P.loading},get status(){return q("status"),P.status},get retryError(){return q("retryError"),P.retryError},get retries(){return q("retries"),P.retries},get timestamp(){return q("timestamp"),P.timestamp},get isOnline(){return q("isOnline"),P.isOnline},get isFocused(){return q("isFocused"),P.isFocused},get isStale(){return C(b,P.timestamp)},actions:F,isDebouncing:!1,isRefreshed:!1,invalidate:ne,onSubmitRequest:e=>{M.current=e},onSubmitSuccess:e=>{K.current=e},onSubmitError:e=>{_.current=e},onSubmitFinished:e=>{I.current=e},onSubmitRequestStart:e=>{A.current=e},onSubmitResponseStart:e=>{N.current=e},onSubmitDownloadProgress:e=>{B.current=e},onSubmitUploadProgress:e=>{G.current=e}}};export{X as useFetch,ee as useSubmit};
//# sourceMappingURL=index.esm.js.map

@@ -136,4 +136,8 @@ import { useRef } from "react";

const handleGetEqualCacheUpdate = (isRefreshed: boolean, timestamp: number) => {
handleCallbacks([state.data, state.error, state.status]); // Must be first
const handleGetEqualCacheUpdate = (
cacheData: CacheValueType<ExtractResponse<T>>,
isRefreshed: boolean,
timestamp: number,
) => {
handleCallbacks(cacheData.response); // Must be first
actions.setRefreshed(isRefreshed, false);

@@ -153,7 +157,7 @@ actions.setTimestamp(new Date(timestamp), false);

const refreshFn = (invalidateKey?: string | FetchCommandInstance) => {
if (invalidateKey && typeof invalidateKey === "string") {
const refreshFn = (invalidateKey?: string | FetchCommandInstance | RegExp) => {
if (invalidateKey && invalidateKey instanceof FetchCommand) {
command.builder.cache.events.revalidate(`/${getCommandKey(invalidateKey, true)}/`);
} else if (invalidateKey) {
command.builder.cache.events.revalidate(invalidateKey);
} else if (invalidateKey && invalidateKey instanceof FetchCommand) {
command.builder.cache.events.revalidate(getCommandKey(invalidateKey));
} else {

@@ -193,3 +197,3 @@ handleRevalidate();

const getUnmount = cache.events.get<T>(cacheKey, handleGetCacheData);
const getEqualDataUnmount = cache.events.getEqualData(cacheKey, handleGetEqualCacheUpdate);
const getEqualDataUnmount = cache.events.getEqualData<T>(cacheKey, handleGetEqualCacheUpdate);
const revalidateUnmount = cache.events.onRevalidate(cacheKey, handleRevalidate);

@@ -196,0 +200,0 @@

@@ -10,2 +10,4 @@ import { useRef } from "react";

CacheValueType,
getCommandKey,
FetchCommand,
} from "@better-typed/hyper-fetch";

@@ -38,3 +40,2 @@ import { useDidMount } from "@better-typed/react-lifecycle-hooks";

// suspense = useSubmitDefaultOptions.suspense,
// invalidate = useSubmitDefaultOptions.invalidate,
shouldThrow = useSubmitDefaultOptions.shouldThrow,

@@ -77,5 +78,7 @@ }: UseSubmitOptionsType<T> = useSubmitDefaultOptions,

if (debounce) {
requestDebounce.debounce(() => submitQueue.add(request));
requestDebounce.debounce(() => {
request.send({ queueType: "submit" });
});
} else {
submitQueue.add(request);
return request.send({ queueType: "submit" });
}

@@ -102,13 +105,19 @@ } else {

onFinishedCallback?.current?.(response);
} else {
logger.debug("No response to perform callbacks");
}
};
const handleGetCacheData = async (cacheData: CacheValueType<ExtractResponse<T>, ExtractError<T>>) => {
const handleGetCacheData = (cacheData: CacheValueType<ExtractResponse<T>, ExtractError<T>>) => {
handleCallbacks(cacheData.response); // Must be first
actions.setLoading(false, false);
actions.setCacheData(cacheData, false);
actions.setLoading(false, false);
};
const handleGetEqualCacheUpdate = (isRefreshed: boolean, timestamp: number) => {
handleCallbacks([state.data, state.error, state.status]); // Must be first
const handleGetEqualCacheUpdate = (
cacheData: CacheValueType<ExtractResponse<T>>,
isRefreshed: boolean,
timestamp: number,
) => {
handleCallbacks(cacheData.response); // Must be first
actions.setRefreshed(isRefreshed, false);

@@ -149,3 +158,3 @@ actions.setTimestamp(new Date(timestamp), false);

const getDataUnmount = cache.events.get<T>(queueKey, handleGetCacheData);
const getEqualDataUnmount = cache.events.getEqualData(cacheKey, handleGetEqualCacheUpdate);
const getEqualDataUnmount = cache.events.getEqualData<T>(cacheKey, handleGetEqualCacheUpdate);

@@ -170,2 +179,10 @@ return () => {

const invalidateFn = (invalidateKey: string | FetchCommandInstance | RegExp) => {
if (invalidateKey && invalidateKey instanceof FetchCommand) {
command.builder.cache.events.revalidate(`/${getCommandKey(invalidateKey, true)}/`);
} else {
command.builder.cache.events.revalidate(invalidateKey);
}
};
/**

@@ -224,2 +241,3 @@ * Initialization of the events related to data exchange with cache and queue

isRefreshed: false,
invalidate: invalidateFn,
onSubmitRequest: (callback: OnRequestCallbackType) => {

@@ -226,0 +244,0 @@ onRequestCallback.current = callback;

@@ -31,2 +31,3 @@ import {

actions: UseDependentStateActions<ExtractResponse<T>, ExtractError<T>>;
invalidate: (invalidateKey: string | FetchCommandInstance | RegExp) => void;
onSubmitRequest: (callback: OnRequestCallbackType) => void;

@@ -33,0 +34,0 @@ onSubmitSuccess: (callback: OnSuccessCallbackType<ExtractResponse<T>>) => void;

{
"name": "@better-typed/react-hyper-fetch",
"version": "0.0.25",
"version": "0.0.26",
"private": false,

@@ -36,4 +36,4 @@ "description": "React hooks and utils for the hyper-fetch",

"build": "rollup -c",
"test": "jest --watchAll",
"test-pipeline": "jest --watchAll=false",
"test": "jest --watchAll --maxWorkers=2",
"test-pipeline": "jest --watchAll=false --maxWorkers=2",
"coverage": "jest --coverage --watchAll=false",

@@ -40,0 +40,0 @@ "lint": "eslint . --ext .js,.jsx,.tsx,.ts --fix",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc