You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP →

@better-typed/react-hyper-fetch

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

to
0.0.25

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

import { FetchCommandInstance, ExtractResponse, ExtractFetchReturn, ExtractError, CacheValueType, FetchLoadingEventType, FetchProgressType } from "@better-typed/hyper-fetch";
import { FetchCommandInstance, ExtractFetchReturn, ExtractResponse, ExtractError, CacheValueType, FetchLoadingEventType, FetchProgressType } from "@better-typed/hyper-fetch";
type UseDependentStateType<DataType = any, ErrorType = any> = {

@@ -27,3 +27,3 @@ data: null | DataType;

};
type UseFetchOptionsType<T extends FetchCommandInstance, MapperResponse> = {
type UseFetchOptionsType<T extends FetchCommandInstance> = {
dependencies?: any[];

@@ -44,6 +44,5 @@ disabled?: boolean;

shouldThrow?: boolean;
responseDataModifierFn?: ((data: ExtractResponse<T>) => MapperResponse) | null;
};
type UseFetchReturnType<T extends FetchCommandInstance, MapperResponse = unknown> = Omit<UseDependentStateType<ExtractResponse<T>, ExtractError<T>>, "data"> & {
data: null | (MapperResponse extends never ? ExtractResponse<T> : MapperResponse);
type UseFetchReturnType<T extends FetchCommandInstance> = Omit<UseDependentStateType<ExtractResponse<T>, ExtractError<T>>, "data"> & {
data: null | ExtractResponse<T>;
actions: UseDependentStateActions<ExtractResponse<T>, ExtractError<T>>;

@@ -71,6 +70,8 @@ onRequest: (callback: OnRequestCallbackType) => void;

// TBD - suspense
declare const useFetch: <T extends FetchCommandInstance, MapperResponse>(command: T, { dependencies, disabled, dependencyTracking, revalidateOnMount, initialData, refresh, refreshTime, refreshBlurred, refreshOnTabBlur, refreshOnTabFocus, refreshOnReconnect, debounce, debounceTime, responseDataModifierFn, shouldThrow }?: UseFetchOptionsType<T, MapperResponse>) => UseFetchReturnType<T, MapperResponse extends never ? ExtractResponse<T> : MapperResponse>;
type UseSubmitOptionsType<T extends FetchCommandInstance, MapperResponse> = {
declare const useFetch: <T extends FetchCommandInstance>(command: T, { dependencies, disabled, dependencyTracking, revalidateOnMount, initialData, refresh, refreshTime, refreshBlurred, refreshOnTabBlur, refreshOnTabFocus, refreshOnReconnect, debounce, debounceTime,
// suspense = useFetchDefaultOptions.suspense
shouldThrow }?: UseFetchOptionsType<T>) => UseFetchReturnType<T>;
type UseSubmitOptionsType<T extends FetchCommandInstance> = {
disabled?: boolean;
invalidate: (string | FetchCommandInstance)[];
invalidate?: (string | FetchCommandInstance)[];
cacheOnMount?: boolean;

@@ -82,7 +83,6 @@ initialData?: CacheValueType<ExtractResponse<T>, ExtractError<T>>["response"] | null;

shouldThrow?: boolean;
responseDataModifierFn?: ((data: ExtractResponse<T>) => MapperResponse) | null;
dependencyTracking?: boolean;
};
type UseSubmitReturnType<T extends FetchCommandInstance, MapperResponse = unknown> = Omit<UseDependentStateType<ExtractResponse<T>, ExtractError<T>>, "data" | "refreshError" | "loading"> & {
data: null | (MapperResponse extends never ? ExtractResponse<T> : MapperResponse);
type UseSubmitReturnType<T extends FetchCommandInstance> = Omit<UseDependentStateType<ExtractResponse<T>, ExtractError<T>>, "data" | "refreshError" | "loading"> & {
data: null | ExtractResponse<T>;
actions: UseDependentStateActions<ExtractResponse<T>, ExtractError<T>>;

@@ -102,8 +102,6 @@ onSubmitRequest: (callback: OnRequestCallbackType) => void;

};
declare const useSubmit: <T extends FetchCommandInstance, MapperResponse>(command: T, { disabled, dependencyTracking, initialData,
// debounce = useSubmitDefaultOptions.debounce,
// debounceTime = useSubmitDefaultOptions.debounceTime,
declare const useSubmit: <T extends FetchCommandInstance>(command: T, { disabled, dependencyTracking, initialData, debounce, debounceTime,
// suspense = useSubmitDefaultOptions.suspense,
// invalidate = useSubmitDefaultOptions.invalidate,
shouldThrow, responseDataModifierFn }?: UseSubmitOptionsType<T, MapperResponse>) => UseSubmitReturnType<T, MapperResponse extends never ? ExtractResponse<T> : MapperResponse>;
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=k(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(F([])));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 D(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 k(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,k(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 j(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 F(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(D.prototype),D.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(j),!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),j(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;j(t)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,t){return this.delegate={iterator:F(e),resultName:r,nextLoc:t},"next"===this.method&&(this.arg=undefined),v}};var L={wrap:h,isGeneratorFunction:E,AsyncIterator:D,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 D(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:F};function M(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var q=(e,r,t)=>{if(r&&e&&t&&+e.timestamp+t>+new Date)return e},_=(e,r)=>!r||!!e&&+new Date>+r+e,K={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){M(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 C=(e,r)=>{var t,n,a,i;return A(A({},K),{},{data:(null==r||null===(t=r.response)||void 0===t?void 0:t[0])||K.data,error:(null==r||null===(n=r.response)||void 0===n?void 0:n[1])||K.error,status:(null==r||null===(a=r.response)||void 0===a?void 0:a[2])||K.status,retries:(null==r?void 0:r.retries)||K.retries,timestamp:(i=(null==r?void 0:r.timestamp)||K.timestamp,i?new Date(i):null),isOnline:e.builder.appManager.isOnline,isFocused:e.builder.appManager.isFocused,loading:!!e.builder.fetchQueue.get(e.queueKey)||K.loading})};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 B(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){M(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 N=(t,n)=>{var i=t.builder,s=t.cache,u=t.cacheKey,c=t.cacheTime,l=o(e.useState(!1),2),d=l[0],f=l[1],h=o(e.useState(+new Date),2)[1],p=e.useRef(C(t,(e=>e?{response:e,retries:0,timestamp:+new Date,isRefreshed:!1}:null)(n))),v=e.useRef([]),m=e=>{v.current.find((r=>e.includes(r)))&&h(+new Date)};r.useDidMount((()=>{(function(){var e=a(L.mark((function e(){var r,a,o,l;return L.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i.cache.get(u);case 2:r=e.sent,a=q(r,s,c),o=_(c,null==a?void 0:a.timestamp),l=o?(d=n)?{response:d,retries:0,timestamp:+new Date,isRefreshed:!1}:null:a,p.current=C(t,l),f(!0),h(+new Date);case 9:case"end":return e.stop()}var d}),e)})));return function(){return e.apply(this,arguments)}})()()})),r.useDidMount((()=>{var e=i.appManager.events.onFocus((()=>{p.current.isFocused=!0,m(["isFocused"])})),r=i.appManager.events.onBlur((()=>{p.current.isFocused=!1,m(["isFocused"])})),t=i.appManager.events.onOnline((()=>{p.current.isOnline=!0,m(["isOnline"])})),n=i.appManager.events.onOffline((()=>{p.current.isOnline=!1,m(["isOnline"])}));return()=>{e(),r(),t(),n()}}));var g,y,b,w,O,x,R,E,D,k,S={setCacheData:(k=a(L.mark((function e(r){var t,n=arguments;return L.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,i.cache.set(B({cache:s,cacheKey:u},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},p.current=B(B({},p.current),t),m(Object.keys(t));case 9:case"end":return e.stop()}}),e)}))),function(e){return k.apply(this,arguments)}),setData:(D=a(L.mark((function e(r){var t,n=arguments;return L.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=p.current,e.next=5,i.cache.set({cache:s,cacheKey:u,response:[r,t.error,t.status],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:p.current.data=r,m(["data"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return D.apply(this,arguments)}),setError:(E=a(L.mark((function e(r){var t,n=arguments;return L.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=p.current,e.next=5,i.cache.set({cache:s,cacheKey:u,response:[t.data,r,t.status],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:p.current.error=r,m(["error"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return E.apply(this,arguments)}),setLoading:(R=a(L.mark((function e(r){var t=arguments;return L.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t.length>1&&void 0!==t[1]&&!t[1]?(p.current.loading=r,m(["loading"])):i.fetchQueue.events.setLoading(u,{isLoading:r,isRetry:!1});case 2:case"end":return e.stop()}}),e)}))),function(e){return R.apply(this,arguments)}),setStatus:(x=a(L.mark((function e(r){var t,n=arguments;return L.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=p.current,e.next=5,i.cache.set({cache:s,cacheKey:u,response:[t.data,t.error,r],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:p.current.status=r,m(["status"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return x.apply(this,arguments)}),setRefreshed:(O=a(L.mark((function e(r){var t,n=arguments;return L.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=p.current,e.next=5,i.cache.set({cache:s,cacheKey:u,response:[t.data,t.error,t.status],retries:t.retries,isRefreshed:r});case 5:e.next=9;break;case 7:p.current.isRefreshed=r,m(["isRefreshed"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return O.apply(this,arguments)}),setRefreshError:(w=a(L.mark((function e(r){var t,n=arguments;return L.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=p.current,e.next=5,i.cache.set({cache:s,cacheKey:u,response:[t.data,r,t.status],retries:t.retries,isRefreshed:!0});case 5:e.next=9;break;case 7:p.current.refreshError=r,m(["refreshError"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return w.apply(this,arguments)}),setRetryError:(b=a(L.mark((function e(r){var t,n=arguments;return L.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=p.current,e.next=5,i.cache.set({cache:s,cacheKey:u,response:[t.data,r,t.status],retries:t.retries,isRefreshed:!0});case 5:e.next=9;break;case 7:p.current.retryError=r,m(["retryError"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return b.apply(this,arguments)}),setRetries:(y=a(L.mark((function e(r){var t,n=arguments;return L.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=p.current,e.next=5,i.cache.set({cache:s,cacheKey:u,response:[t.data,t.error,t.status],retries:r,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:p.current.retries=r,m(["retries"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return y.apply(this,arguments)}),setTimestamp:(g=a(L.mark((function e(r){var t,n=arguments;return L.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=p.current,e.next=5,i.cache.set({cache:s,cacheKey:u,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:p.current.timestamp=r,m(["timestamp"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return g.apply(this,arguments)})};return[p.current,S,e=>{v.current.push(e)},d]},G=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}},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&&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}},W={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},Y={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]:W,s=i.dependencies,u=void 0===s?W.dependencies:s,c=i.disabled,l=void 0===c?W.disabled:c,d=i.dependencyTracking,f=void 0===d?W.dependencyTracking:d,h=i.revalidateOnMount,p=void 0===h?W.revalidateOnMount:h,v=i.initialData,m=void 0===v?W.initialData:v,g=i.refresh,y=void 0===g?W.refresh:g,b=i.refreshTime,w=void 0===b?W.refreshTime:b,O=i.refreshBlurred,x=void 0===O?W.refreshBlurred:O,R=i.refreshOnTabBlur,E=void 0===R?W.refreshOnTabBlur:R,D=i.refreshOnTabFocus,k=void 0===D?W.refreshOnTabFocus:D,S=i.refreshOnReconnect,j=void 0===S?W.refreshOnReconnect:S,T=i.debounce,F=void 0===T?W.debounce:T,P=i.debounceTime,M=void 0===P?W.debounceTime:P,q=i.responseDataModifierFn,K=void 0===q?W.responseDataModifierFn:q,I=i.shouldThrow,A=void 0===I?W.shouldThrow:I,C=n.cacheTime,U=n.cacheKey,B=n.queueKey,Y=n.builder,$=G(M),z=Q(w),H=Y.cache,J=Y.fetchQueue,V=Y.appManager,X=Y.commandManager,Z=Y.loggerManager,ee=e.useRef(Z.init("useFetch")).current,re=N(n,m),te=o(re,4),ne=te[0],ae=te[1],ie=te[2],oe=te[3],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=e.useRef(null),pe=e.useRef(null),ve=()=>{l?ee.debug("Cannot add to fetch queue",{disabled:l}):(ee.debug("Adding request to fetch queue"),J.add(n))},me=()=>{z.resetInterval();var e=ne.timestamp,r=e?Math.max(+e+w-+new Date,w):w;y&&(ee.debug("Starting refresh counter, request will be send in ".concat(r,"ms")),z.interval(a(L.mark((function e(){var r,t,a;return L.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,J.get(B);case 2:r=e.sent,t=!n.builder.appManager.isFocused,a=t&&x||n.builder.appManager.isFocused,!!!r.requests.length&&a&&(ee.info("Performing refresh request"),ve(),z.resetInterval());case 8:case"end":return e.stop()}}),e)}))),r))},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]),A)throw{message:"Fetching Error.",error:e[1]};null==le||null===(r=le.current)||void 0===r||r.call(le,e)}},ye=e=>{ge(e.response),ae.setCacheData(e,!1)},be=(e,r)=>{ge([ne.data,ne.error,ne.status]),ae.setRefreshed(e,!1),ae.setTimestamp(new Date(r),!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=e=>{e&&"string"==typeof e?n.builder.cache.events.revalidate(e):e&&e instanceof t.FetchCommand?n.builder.cache.events.revalidate(t.getCommandKey(e)):Oe()},Re=e=>{var r;null==he||null===(r=he.current)||void 0===r||r.call(he,e)},Ee=e=>{var r;null==pe||null===(r=pe.current)||void 0===r||r.call(pe,e)},De=e=>{var r;null==de||null===(r=de.current)||void 0===r||r.call(de,e)},ke=e=>{var r;null==de||null===(r=de.current)||void 0===r||r.call(de,e)},Se=()=>{var e=V.events.onFocus((()=>k&&ve())),r=V.events.onBlur((()=>E&&ve())),t=V.events.onOnline((()=>j&&ve())),n=X.events.onDownloadProgress(B,Re),a=X.events.onUploadProgress(B,Ee),i=X.events.onRequestStart(B,De),o=X.events.onResponseStart(B,ke),s=J.events.getLoading(B,we),u=H.events.get(U,ye),c=H.events.getEqualData(U,be),l=H.events.onRevalidate(U,Oe);return()=>{e(),r(),t(),n(),a(),i(),o(),s(),u(),c(),l()}},je=()=>K&&ne.data?K(ne.data):ne.data,Te=()=>{f||Object.keys(ne).forEach((e=>ie(e)))};return r.useDidMount((()=>((p||_(C,ne.timestamp))&&ve(),Te(),Se()))),r.useDidUpdate((()=>{oe&&ge([ne.data,ne.error,ne.status])}),[oe],!0),r.useDidUpdate((()=>{!J.requestCount&&F?$.debounce((()=>ve())):ve()}),[...u,l]),r.useDidUpdate((()=>{me()}),[y,w,ne.timestamp],!0),{get data(){return ie("data"),je()},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,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:$.active,refresh:xe}},exports.useSubmit=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Y,a=n.disabled,i=void 0===a?Y.disabled:a,s=n.dependencyTracking,u=void 0===s?Y.dependencyTracking:s,c=n.initialData,l=void 0===c?Y.initialData:c,d=n.shouldThrow,f=void 0===d?Y.shouldThrow:d,h=n.responseDataModifierFn,p=void 0===h?Y.responseDataModifierFn:h,v=t.cacheTime,m=t.cacheKey,g=t.queueKey,y=t.builder,b=y.cache,w=y.submitQueue,O=y.commandManager,x=y.loggerManager,R=e.useRef(x.init("useSubmit")).current,E=N(t,l),D=o(E,3),k=D[0],S=D[1],j=D[2],T=e.useRef(null),F=e.useRef(null),P=e.useRef(null),L=e.useRef(null),M=e.useRef(null),q=e.useRef(null),K=e.useRef(null),I=e.useRef(null),A=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)),i?R.debug("Cannot add to submit queue",{disabled:i,options:r}):(R.debug("Adding request to submit queue",{disabled:i,options:r}),w.add(e))},C=e=>{if(e){var r,t,n;if(e[0])null==F||null===(t=F.current)||void 0===t||t.call(F,e[0]);if(e[1])if(null==P||null===(n=P.current)||void 0===n||n.call(P,e[1]),f)throw{message:"Fetching Error.",error:e[1]};null==L||null===(r=L.current)||void 0===r||r.call(L,e)}},U=e=>{C(e.response),S.setCacheData(e,!1)},B=(e,r)=>{C([k.data,k.error,k.status]),S.setRefreshed(e,!1),S.setTimestamp(new Date(r),!1)},G=e=>{var r,t=e.isLoading,n=e.isRetry;S.setLoading(t,!1),null===(r=T.current)||void 0===r||r.call(T,{isRetry:n})},Q=e=>{var r;null==K||null===(r=K.current)||void 0===r||r.call(K,e)},W=e=>{var r;null==I||null===(r=I.current)||void 0===r||r.call(I,e)},$=e=>{var r;null==M||null===(r=M.current)||void 0===r||r.call(M,e)},z=e=>{var r;null==M||null===(r=M.current)||void 0===r||r.call(M,e)},H=()=>{var e=O.events.onDownloadProgress(g,Q),r=O.events.onUploadProgress(g,W),t=O.events.onRequestStart(g,$),n=O.events.onResponseStart(g,z),a=w.events.getLoading(g,G),i=b.events.get(g,U),o=b.events.getEqualData(m,B);return()=>{e(),r(),t(),n(),a(),i(),o()}},J=()=>p&&k.data?p(k.data):k.data,V=()=>{u||Object.keys(k).forEach((e=>j(e)))};return r.useDidMount((()=>(V(),H()))),{submit:A,get data(){return j("data"),J()},get error(){return j("error"),k.error},get submitting(){return j("loading"),k.loading},get status(){return j("status"),k.status},get retryError(){return j("retryError"),k.retryError},get retries(){return j("retries"),k.retries},get timestamp(){return j("timestamp"),k.timestamp},get isOnline(){return j("isOnline"),k.isOnline},get isFocused(){return j("isFocused"),k.isFocused},get isStale(){return _(v,k.timestamp)},actions:S,isDebouncing:!1,isRefreshed:!1,onSubmitRequest:e=>{T.current=e},onSubmitSuccess:e=>{F.current=e},onSubmitError:e=>{P.current=e},onSubmitFinished:e=>{L.current=e},onSubmitRequestStart:e=>{M.current=e},onSubmitResponseStart:e=>{q.current=e},onSubmitDownloadProgress:e=>{K.current=e},onSubmitUploadProgress:e=>{I.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 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}}};
//# sourceMappingURL=index.cjs.js.map

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

declare type UseFetchOptionsType<T extends FetchCommandInstance, MapperResponse> = {
declare type UseFetchOptionsType<T extends FetchCommandInstance> = {
dependencies?: any[];

@@ -46,6 +46,5 @@ disabled?: boolean;

shouldThrow?: boolean;
responseDataModifierFn?: ((data: ExtractResponse<T>) => MapperResponse) | null;
};
declare type UseFetchReturnType<T extends FetchCommandInstance, MapperResponse = unknown> = Omit<UseDependentStateType<ExtractResponse<T>, ExtractError<T>>, "data"> & {
data: null | (MapperResponse extends never ? ExtractResponse<T> : MapperResponse);
declare type UseFetchReturnType<T extends FetchCommandInstance> = Omit<UseDependentStateType<ExtractResponse<T>, ExtractError<T>>, "data"> & {
data: null | ExtractResponse<T>;
actions: UseDependentStateActions<ExtractResponse<T>, ExtractError<T>>;

@@ -73,7 +72,7 @@ onRequest: (callback: OnRequestCallbackType$1) => void;

declare const useFetch: <T extends FetchCommandInstance, MapperResponse>(command: T, { dependencies, disabled, dependencyTracking, revalidateOnMount, initialData, refresh, refreshTime, refreshBlurred, refreshOnTabBlur, refreshOnTabFocus, refreshOnReconnect, debounce, debounceTime, responseDataModifierFn, shouldThrow, }?: UseFetchOptionsType<T, MapperResponse>) => UseFetchReturnType<T, MapperResponse extends never ? ExtractResponse<T> : MapperResponse>;
declare const useFetch: <T extends FetchCommandInstance>(command: T, { dependencies, disabled, dependencyTracking, revalidateOnMount, initialData, refresh, refreshTime, refreshBlurred, refreshOnTabBlur, refreshOnTabFocus, refreshOnReconnect, debounce, debounceTime, shouldThrow, }?: UseFetchOptionsType<T>) => UseFetchReturnType<T>;
declare type UseSubmitOptionsType<T extends FetchCommandInstance, MapperResponse> = {
declare type UseSubmitOptionsType<T extends FetchCommandInstance> = {
disabled?: boolean;
invalidate: (string | FetchCommandInstance)[];
invalidate?: (string | FetchCommandInstance)[];
cacheOnMount?: boolean;

@@ -85,7 +84,6 @@ initialData?: CacheValueType<ExtractResponse<T>, ExtractError<T>>["response"] | null;

shouldThrow?: boolean;
responseDataModifierFn?: ((data: ExtractResponse<T>) => MapperResponse) | null;
dependencyTracking?: boolean;
};
declare type UseSubmitReturnType<T extends FetchCommandInstance, MapperResponse = unknown> = Omit<UseDependentStateType<ExtractResponse<T>, ExtractError<T>>, "data" | "refreshError" | "loading"> & {
data: null | (MapperResponse extends never ? ExtractResponse<T> : MapperResponse);
declare type UseSubmitReturnType<T extends FetchCommandInstance> = Omit<UseDependentStateType<ExtractResponse<T>, ExtractError<T>>, "data" | "refreshError" | "loading"> & {
data: null | ExtractResponse<T>;
actions: UseDependentStateActions<ExtractResponse<T>, ExtractError<T>>;

@@ -112,4 +110,4 @@ onSubmitRequest: (callback: OnRequestCallbackType) => void;

declare const useSubmit: <T extends FetchCommandInstance, MapperResponse>(command: T, { disabled, dependencyTracking, initialData, shouldThrow, responseDataModifierFn, }?: UseSubmitOptionsType<T, MapperResponse>) => UseSubmitReturnType<T, MapperResponse extends never ? ExtractResponse<T> : MapperResponse>;
declare const useSubmit: <T extends FetchCommandInstance>(command: T, { disabled, dependencyTracking, initialData, debounce, debounceTime, shouldThrow, }?: UseSubmitOptionsType<T>) => UseSubmitReturnType<T>;
export { OnErrorCallbackType$1 as OnErrorCallbackType, OnFinishedCallbackType$1 as OnFinishedCallbackType, OnProgressCallbackType$1 as OnProgressCallbackType, OnRequestCallbackType$1 as OnRequestCallbackType, OnStartCallbackType$1 as OnStartCallbackType, OnSuccessCallbackType$1 as OnSuccessCallbackType, UseFetchOptionsType, UseFetchReturnType, useFetch, useSubmit };

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

import { FetchCommandInstance, ExtractResponse, ExtractFetchReturn, ExtractError, CacheValueType, FetchLoadingEventType, FetchProgressType } from "@better-typed/hyper-fetch";
import { FetchCommandInstance, ExtractFetchReturn, ExtractResponse, ExtractError, CacheValueType, FetchLoadingEventType, FetchProgressType } from "@better-typed/hyper-fetch";
type UseDependentStateType<DataType = any, ErrorType = any> = {

@@ -27,3 +27,3 @@ data: null | DataType;

};
type UseFetchOptionsType<T extends FetchCommandInstance, MapperResponse> = {
type UseFetchOptionsType<T extends FetchCommandInstance> = {
dependencies?: any[];

@@ -44,6 +44,5 @@ disabled?: boolean;

shouldThrow?: boolean;
responseDataModifierFn?: ((data: ExtractResponse<T>) => MapperResponse) | null;
};
type UseFetchReturnType<T extends FetchCommandInstance, MapperResponse = unknown> = Omit<UseDependentStateType<ExtractResponse<T>, ExtractError<T>>, "data"> & {
data: null | (MapperResponse extends never ? ExtractResponse<T> : MapperResponse);
type UseFetchReturnType<T extends FetchCommandInstance> = Omit<UseDependentStateType<ExtractResponse<T>, ExtractError<T>>, "data"> & {
data: null | ExtractResponse<T>;
actions: UseDependentStateActions<ExtractResponse<T>, ExtractError<T>>;

@@ -71,6 +70,8 @@ onRequest: (callback: OnRequestCallbackType) => void;

// TBD - suspense
declare const useFetch: <T extends FetchCommandInstance, MapperResponse>(command: T, { dependencies, disabled, dependencyTracking, revalidateOnMount, initialData, refresh, refreshTime, refreshBlurred, refreshOnTabBlur, refreshOnTabFocus, refreshOnReconnect, debounce, debounceTime, responseDataModifierFn, shouldThrow }?: UseFetchOptionsType<T, MapperResponse>) => UseFetchReturnType<T, MapperResponse extends never ? ExtractResponse<T> : MapperResponse>;
type UseSubmitOptionsType<T extends FetchCommandInstance, MapperResponse> = {
declare const useFetch: <T extends FetchCommandInstance>(command: T, { dependencies, disabled, dependencyTracking, revalidateOnMount, initialData, refresh, refreshTime, refreshBlurred, refreshOnTabBlur, refreshOnTabFocus, refreshOnReconnect, debounce, debounceTime,
// suspense = useFetchDefaultOptions.suspense
shouldThrow }?: UseFetchOptionsType<T>) => UseFetchReturnType<T>;
type UseSubmitOptionsType<T extends FetchCommandInstance> = {
disabled?: boolean;
invalidate: (string | FetchCommandInstance)[];
invalidate?: (string | FetchCommandInstance)[];
cacheOnMount?: boolean;

@@ -82,7 +83,6 @@ initialData?: CacheValueType<ExtractResponse<T>, ExtractError<T>>["response"] | null;

shouldThrow?: boolean;
responseDataModifierFn?: ((data: ExtractResponse<T>) => MapperResponse) | null;
dependencyTracking?: boolean;
};
type UseSubmitReturnType<T extends FetchCommandInstance, MapperResponse = unknown> = Omit<UseDependentStateType<ExtractResponse<T>, ExtractError<T>>, "data" | "refreshError" | "loading"> & {
data: null | (MapperResponse extends never ? ExtractResponse<T> : MapperResponse);
type UseSubmitReturnType<T extends FetchCommandInstance> = Omit<UseDependentStateType<ExtractResponse<T>, ExtractError<T>>, "data" | "refreshError" | "loading"> & {
data: null | ExtractResponse<T>;
actions: UseDependentStateActions<ExtractResponse<T>, ExtractError<T>>;

@@ -102,8 +102,6 @@ onSubmitRequest: (callback: OnRequestCallbackType) => void;

};
declare const useSubmit: <T extends FetchCommandInstance, MapperResponse>(command: T, { disabled, dependencyTracking, initialData,
// debounce = useSubmitDefaultOptions.debounce,
// debounceTime = useSubmitDefaultOptions.debounceTime,
declare const useSubmit: <T extends FetchCommandInstance>(command: T, { disabled, dependencyTracking, initialData, debounce, debounceTime,
// suspense = useSubmitDefaultOptions.suspense,
// invalidate = useSubmitDefaultOptions.invalidate,
shouldThrow, responseDataModifierFn }?: UseSubmitOptionsType<T, MapperResponse>) => UseSubmitReturnType<T, MapperResponse extends never ? ExtractResponse<T> : MapperResponse>;
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 q(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 R={};R[v]=function(){return this};var k=Object.getPrototypeOf,D=k&&k(k(K([])));D&&D!==f&&h.call(D,v)&&(R=D);var j=E.prototype=O.prototype=Object.create(R);function S(e){["next","throw","return"].forEach((function(r){e[r]=function(e){return this._invoke(r,e)}}))}function T(e){var r="function"==typeof e&&e.constructor;return!!r&&(r===x||"GeneratorFunction"===(r.displayName||r.name))}function L(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 M(e){var r=e.completion||{};r.type="normal",delete r.arg,e.completion=r}function q(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=j.constructor=E,E.constructor=x,E[g]=x.displayName="GeneratorFunction",S(L.prototype),L.prototype[m]=function(){return this},S(j),j[g]="Generator",j[v]=function(){return this},j.toString=function(){return"[object Generator]"},q.prototype={constructor:q,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(M),!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),M(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;M(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:T,AsyncIterator:L,mark:function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,E):(e.__proto__=E,g in e||(e[g]="GeneratorFunction")),e.prototype=Object.create(j),e},awrap:function(e){return{__await:e}},async:function(e,r,t,n,a){void 0===a&&(a=Promise);var i=new L(y(e,r,t,n),a);return T(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,r)=>!r||!!e&&+new Date>+r+e,N={data:null,error:null,loading:!1,status:null,refreshError:null,retryError:null,isRefreshed:!1,retries:0,timestamp:null,isOnline:!0,isFocused:!0};function G(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?G(Object(t),!0).forEach((function(r){A(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):G(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var U=(e,r)=>{var t,n,a,i;return Q(Q({},N),{},{data:(null==r||null===(t=r.response)||void 0===t?void 0:t[0])||N.data,error:(null==r||null===(n=r.response)||void 0===n?void 0:n[1])||N.error,status:(null==r||null===(a=r.response)||void 0===a?void 0:a[2])||N.status,retries:(null==r?void 0:r.retries)||N.retries,timestamp:(i=(null==r?void 0:r.timestamp)||N.timestamp,i?new Date(i):null),isOnline:e.builder.appManager.isOnline,isFocused:e.builder.appManager.isFocused,loading:!!e.builder.fetchQueue.get(e.queueKey)||N.loading})};function Y(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 $(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?Y(Object(t),!0).forEach((function(r){A(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):Y(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var z=(n,a)=>{var i=n.builder,o=n.cache,s=n.cacheKey,u=n.cacheTime,l=d(e(!1),2),f=l[0],h=l[1],p=d(e(+new Date),2)[1],v=r(U(n,(e=>e?{response:e,retries:0,timestamp:+new Date,isRefreshed:!1}:null)(a))),m=r([]),g=e=>{m.current.find((r=>e.includes(r)))&&p(+new Date)};t((()=>{(function(){var e=c(I.mark((function e(){var r,t,c,l;return I.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i.cache.get(s);case 2:r=e.sent,t=B(r,o,u),c=C(u,null==t?void 0:t.timestamp),l=c?(d=a)?{response:d,retries:0,timestamp:+new Date,isRefreshed:!1}:null:t,v.current=U(n,l),h(!0),p(+new Date);case 9:case"end":return e.stop()}var d}),e)})));return function(){return e.apply(this,arguments)}})()()})),t((()=>{var e=i.appManager.events.onFocus((()=>{v.current.isFocused=!0,g(["isFocused"])})),r=i.appManager.events.onBlur((()=>{v.current.isFocused=!1,g(["isFocused"])})),t=i.appManager.events.onOnline((()=>{v.current.isOnline=!0,g(["isOnline"])})),n=i.appManager.events.onOffline((()=>{v.current.isOnline=!1,g(["isOnline"])}));return()=>{e(),r(),t(),n()}}));var y,b,w,O,x,E,R,k,D,j,S={setCacheData:(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=6;break}return e.next=4,i.cache.set($({cache:o,cacheKey:s},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},v.current=$($({},v.current),t),g(Object.keys(t));case 9:case"end":return e.stop()}}),e)}))),function(e){return j.apply(this,arguments)}),setData:(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=v.current,e.next=5,i.cache.set({cache:o,cacheKey:s,response:[r,t.error,t.status],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:v.current.data=r,g(["data"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return D.apply(this,arguments)}),setError:(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=v.current,e.next=5,i.cache.set({cache:o,cacheKey:s,response:[t.data,r,t.status],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:v.current.error=r,g(["error"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return k.apply(this,arguments)}),setLoading:(R=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]?(v.current.loading=r,g(["loading"])):i.fetchQueue.events.setLoading(s,{isLoading:r,isRetry:!1});case 2:case"end":return e.stop()}}),e)}))),function(e){return R.apply(this,arguments)}),setStatus:(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=v.current,e.next=5,i.cache.set({cache:o,cacheKey:s,response:[t.data,t.error,r],retries:t.retries,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:v.current.status=r,g(["status"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return E.apply(this,arguments)}),setRefreshed:(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=v.current,e.next=5,i.cache.set({cache:o,cacheKey:s,response:[t.data,t.error,t.status],retries:t.retries,isRefreshed:r});case 5:e.next=9;break;case 7:v.current.isRefreshed=r,g(["isRefreshed"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return x.apply(this,arguments)}),setRefreshError:(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=v.current,e.next=5,i.cache.set({cache:o,cacheKey:s,response:[t.data,r,t.status],retries:t.retries,isRefreshed:!0});case 5:e.next=9;break;case 7:v.current.refreshError=r,g(["refreshError"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return O.apply(this,arguments)}),setRetryError:(w=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=v.current,e.next=5,i.cache.set({cache:o,cacheKey:s,response:[t.data,r,t.status],retries:t.retries,isRefreshed:!0});case 5:e.next=9;break;case 7:v.current.retryError=r,g(["retryError"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return w.apply(this,arguments)}),setRetries:(b=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=v.current,e.next=5,i.cache.set({cache:o,cacheKey:s,response:[t.data,t.error,t.status],retries:r,isRefreshed:t.isRefreshed});case 5:e.next=9;break;case 7:v.current.retries=r,g(["retries"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return b.apply(this,arguments)}),setTimestamp:(y=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=v.current,e.next=5,i.cache.set({cache:o,cacheKey:s,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:v.current.timestamp=r,g(["timestamp"]);case 9:case"end":return e.stop()}}),e)}))),function(e){return y.apply(this,arguments)})};return[v.current,S,e=>{m.current.push(e)},f]},H=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}},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&&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}},V={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},W=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:V,i=n.dependencies,u=void 0===i?V.dependencies:i,l=n.disabled,f=void 0===l?V.disabled:l,h=n.dependencyTracking,p=void 0===h?V.dependencyTracking:h,v=n.revalidateOnMount,m=void 0===v?V.revalidateOnMount:v,g=n.initialData,y=void 0===g?V.initialData:g,b=n.refresh,w=void 0===b?V.refresh:b,O=n.refreshTime,x=void 0===O?V.refreshTime:O,E=n.refreshBlurred,R=void 0===E?V.refreshBlurred:E,k=n.refreshOnTabBlur,D=void 0===k?V.refreshOnTabBlur:k,j=n.refreshOnTabFocus,S=void 0===j?V.refreshOnTabFocus:j,T=n.refreshOnReconnect,L=void 0===T?V.refreshOnReconnect:T,P=n.debounce,F=void 0===P?V.debounce:P,M=n.debounceTime,q=void 0===M?V.debounceTime:M,K=n.responseDataModifierFn,_=void 0===K?V.responseDataModifierFn:K,A=n.shouldThrow,B=void 0===A?V.shouldThrow:A,N=e.cacheTime,G=e.cacheKey,Q=e.queueKey,U=e.builder,Y=H(q),$=J(x),W=U.cache,X=U.fetchQueue,Z=U.appManager,ee=U.commandManager,re=U.loggerManager,te=r(re.init("useFetch")).current,ne=z(e,y),ae=d(ne,4),ie=ae[0],oe=ae[1],se=ae[2],ue=ae[3],ce=r(null),le=r(null),de=r(null),fe=r(null),he=r(null),pe=r(null),ve=r(null),me=r(null),ge=()=>{f?te.debug("Cannot add to fetch queue",{disabled:f}):(te.debug("Adding request to fetch queue"),X.add(e))},ye=()=>{$.resetInterval();var r=ie.timestamp,t=r?Math.max(+r+x-+new Date,x):x;w&&(te.debug("Starting refresh counter, request will be send in ".concat(t,"ms")),$.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,X.get(Q);case 2:t=r.sent,n=!e.builder.appManager.isFocused,a=n&&R||e.builder.appManager.isFocused,!!!t.requests.length&&a&&(te.info("Performing refresh request"),ge(),$.resetInterval());case 8:case"end":return r.stop()}}),r)}))),t))},be=e=>{if(e){var r,t,n;if(e[0])null==le||null===(t=le.current)||void 0===t||t.call(le,e[0]);if(e[1])if(null==de||null===(n=de.current)||void 0===n||n.call(de,e[1]),B)throw{message:"Fetching Error.",error:e[1]};null==fe||null===(r=fe.current)||void 0===r||r.call(fe,e)}},we=e=>{be(e.response),oe.setCacheData(e,!1)},Oe=(e,r)=>{be([ie.data,ie.error,ie.status]),oe.setRefreshed(e,!1),oe.setTimestamp(new Date(r),!1)},xe=e=>{var r,t=e.isLoading,n=e.isRetry;oe.setLoading(t,!1),null===(r=ce.current)||void 0===r||r.call(ce,{isRetry:n})},Ee=()=>{ge()},Re=r=>{r&&"string"==typeof r?e.builder.cache.events.revalidate(r):r&&r instanceof o?e.builder.cache.events.revalidate(s(r)):Ee()},ke=e=>{var r;null==ve||null===(r=ve.current)||void 0===r||r.call(ve,e)},De=e=>{var r;null==me||null===(r=me.current)||void 0===r||r.call(me,e)},je=e=>{var r;null==he||null===(r=he.current)||void 0===r||r.call(he,e)},Se=e=>{var r;null==he||null===(r=he.current)||void 0===r||r.call(he,e)},Te=()=>{var e=Z.events.onFocus((()=>S&&ge())),r=Z.events.onBlur((()=>D&&ge())),t=Z.events.onOnline((()=>L&&ge())),n=ee.events.onDownloadProgress(Q,ke),a=ee.events.onUploadProgress(Q,De),i=ee.events.onRequestStart(Q,je),o=ee.events.onResponseStart(Q,Se),s=X.events.getLoading(Q,xe),u=W.events.get(G,we),c=W.events.getEqualData(G,Oe),l=W.events.onRevalidate(G,Ee);return()=>{e(),r(),t(),n(),a(),i(),o(),s(),u(),c(),l()}},Le=()=>_&&ie.data?_(ie.data):ie.data,Pe=()=>{p||Object.keys(ie).forEach((e=>se(e)))};return t((()=>((m||C(N,ie.timestamp))&&ge(),Pe(),Te()))),a((()=>{ue&&be([ie.data,ie.error,ie.status])}),[ue],!0),a((()=>{!X.requestCount&&F?Y.debounce((()=>ge())):ge()}),[...u,f]),a((()=>{ye()}),[w,x,ie.timestamp],!0),{get data(){return se("data"),Le()},get error(){return se("error"),ie.error},get loading(){return se("loading"),ie.loading},get status(){return se("status"),ie.status},get retryError(){return se("retryError"),ie.retryError},get refreshError(){return se("refreshError"),ie.refreshError},get isRefreshed(){return se("isRefreshed"),ie.isRefreshed},get retries(){return se("retries"),ie.retries},get timestamp(){return se("timestamp"),ie.timestamp},get isOnline(){return se("isOnline"),ie.isOnline},get isFocused(){return se("isFocused"),ie.isFocused},get isStale(){return C(N,ie.timestamp)},actions:oe,onRequest:e=>{ce.current=e},onSuccess:e=>{le.current=e},onError:e=>{de.current=e},onFinished:e=>{fe.current=e},onRequestStart:e=>{he.current=e},onResponseStart:e=>{pe.current=e},onDownloadProgress:e=>{ve.current=e},onUploadProgress:e=>{me.current=e},isRefreshingError:!!ie.error&&ie.isRefreshed,isDebouncing:Y.active,refresh:Re}},X={disabled:!1,dependencyTracking:!0,cacheOnMount:!0,initialData:null,debounce:!1,debounceTime:400,suspense:!1,shouldThrow:!1,responseDataModifierFn:null,invalidate:[]},Z=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:X,a=n.disabled,i=void 0===a?X.disabled:a,o=n.dependencyTracking,s=void 0===o?X.dependencyTracking:o,u=n.initialData,c=void 0===u?X.initialData:u,l=n.shouldThrow,f=void 0===l?X.shouldThrow:l,h=n.responseDataModifierFn,p=void 0===h?X.responseDataModifierFn:h,v=e.cacheTime,m=e.cacheKey,g=e.queueKey,y=e.builder,b=y.cache,w=y.submitQueue,O=y.commandManager,x=y.loggerManager,E=r(x.init("useSubmit")).current,R=z(e,c),k=d(R,3),D=k[0],j=k[1],S=k[2],T=r(null),L=r(null),P=r(null),F=r(null),M=r(null),q=r(null),K=r(null),_=r(null),I=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?E.debug("Cannot add to submit queue",{disabled:i,options:t}):(E.debug("Adding request to submit queue",{disabled:i,options:t}),w.add(r))},A=e=>{if(e){var r,t,n;if(e[0])null==L||null===(t=L.current)||void 0===t||t.call(L,e[0]);if(e[1])if(null==P||null===(n=P.current)||void 0===n||n.call(P,e[1]),f)throw{message:"Fetching Error.",error:e[1]};null==F||null===(r=F.current)||void 0===r||r.call(F,e)}},B=e=>{A(e.response),j.setCacheData(e,!1)},N=(e,r)=>{A([D.data,D.error,D.status]),j.setRefreshed(e,!1),j.setTimestamp(new Date(r),!1)},G=e=>{var r,t=e.isLoading,n=e.isRetry;j.setLoading(t,!1),null===(r=T.current)||void 0===r||r.call(T,{isRetry:n})},Q=e=>{var r;null==K||null===(r=K.current)||void 0===r||r.call(K,e)},U=e=>{var r;null==_||null===(r=_.current)||void 0===r||r.call(_,e)},Y=e=>{var r;null==M||null===(r=M.current)||void 0===r||r.call(M,e)},$=e=>{var r;null==M||null===(r=M.current)||void 0===r||r.call(M,e)},H=()=>{var e=O.events.onDownloadProgress(g,Q),r=O.events.onUploadProgress(g,U),t=O.events.onRequestStart(g,Y),n=O.events.onResponseStart(g,$),a=w.events.getLoading(g,G),i=b.events.get(g,B),o=b.events.getEqualData(m,N);return()=>{e(),r(),t(),n(),a(),i(),o()}},J=()=>p&&D.data?p(D.data):D.data,V=()=>{s||Object.keys(D).forEach((e=>S(e)))};return t((()=>(V(),H()))),{submit:I,get data(){return S("data"),J()},get error(){return S("error"),D.error},get submitting(){return S("loading"),D.loading},get status(){return S("status"),D.status},get retryError(){return S("retryError"),D.retryError},get retries(){return S("retries"),D.retries},get timestamp(){return S("timestamp"),D.timestamp},get isOnline(){return S("isOnline"),D.isOnline},get isFocused(){return S("isFocused"),D.isFocused},get isStale(){return C(v,D.timestamp)},actions:j,isDebouncing:!1,isRefreshed:!1,onSubmitRequest:e=>{T.current=e},onSubmitSuccess:e=>{L.current=e},onSubmitError:e=>{P.current=e},onSubmitFinished:e=>{F.current=e},onSubmitRequestStart:e=>{M.current=e},onSubmitResponseStart:e=>{q.current=e},onSubmitDownloadProgress:e=>{K.current=e},onSubmitUploadProgress:e=>{_.current=e}}};export{W as useFetch,Z 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,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};
//# sourceMappingURL=index.esm.js.map
import { useRef, useState } from "react";
import { useDidMount } from "@better-typed/react-lifecycle-hooks";
import { ClientResponseType, FetchCommandInstance, ExtractResponse, ExtractError } from "@better-typed/hyper-fetch";
import {
ClientResponseType,
FetchCommandInstance,
ExtractResponse,
ExtractError,
FetchBuilderInstance,
} from "@better-typed/hyper-fetch";

@@ -12,2 +18,3 @@ import { getCacheState, getUseFetchInitialData, isStaleCacheData } from "use-fetch/use-fetch.utils";

initialData: ClientResponseType<ExtractResponse<T>, ExtractError<T>> | null,
queue: FetchBuilderInstance["fetchQueue"] | FetchBuilderInstance["submitQueue"],
): [

@@ -19,3 +26,3 @@ UseDependentStateType<ExtractResponse<T>, ExtractError<T>>,

] => {
const { builder, cache, cacheKey, cacheTime } = command;
const { builder, cache, cacheKey, cacheTime, queueKey } = command;

@@ -44,4 +51,9 @@ const [initialized, setInitialized] = useState(false);

const cacheValue = isStale ? getUseFetchInitialData<T>(initialData) : initCacheState;
const queueElement = await queue.get(queueKey);
state.current = getInitialDependentStateData(command, cacheValue);
state.current = getInitialDependentStateData(
command,
cacheValue,
state.current.loading || !!queueElement.requests.length,
);
setInitialized(true);

@@ -48,0 +60,0 @@ rerender(+new Date());

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

initialData: NullableType<CacheValueType>,
initialLoading?: boolean,
) => ({

@@ -29,11 +30,11 @@ ...initialState,

isFocused: command.builder.appManager.isFocused,
loading: !!command.builder.fetchQueue.get(command.queueKey) || initialState.loading,
loading: initialLoading ?? initialState.loading,
});
export const transformDataToCacheValue = <T>(
initialData: ClientResponseType<ExtractResponse<T>, ExtractError<T>> | null,
response: ClientResponseType<ExtractResponse<T>, ExtractError<T>> | null,
): NullableType<CacheValueType> => {
if (!initialData) return null;
if (!response) return null;
return {
response: initialData,
response,
retries: 0,

@@ -40,0 +41,0 @@ timestamp: +new Date(),

@@ -33,3 +33,3 @@ import { useRef } from "react";

// TBD - suspense
export const useFetch = <T extends FetchCommandInstance, MapperResponse>(
export const useFetch = <T extends FetchCommandInstance>(
command: T,

@@ -50,6 +50,6 @@ {

debounceTime = useFetchDefaultOptions.debounceTime,
responseDataModifierFn = useFetchDefaultOptions.responseDataModifierFn,
// suspense = useFetchDefaultOptions.suspense
shouldThrow = useFetchDefaultOptions.shouldThrow,
}: UseFetchOptionsType<T, MapperResponse> = useFetchDefaultOptions,
): UseFetchReturnType<T, MapperResponse extends never ? ExtractResponse<T> : MapperResponse> => {
}: UseFetchOptionsType<T> = useFetchDefaultOptions,
): UseFetchReturnType<T> => {
const { cacheTime, cacheKey, queueKey, builder } = command;

@@ -62,3 +62,3 @@

const logger = useRef(loggerManager.init("useFetch")).current;
const [state, actions, setRenderKey, initialized] = useDependentState<T>(command, initialData);
const [state, actions, setRenderKey, initialized] = useDependentState<T>(command, initialData, fetchQueue);

@@ -133,5 +133,6 @@ const onRequestCallback = useRef<null | OnRequestCallbackType>(null);

const handleGetCacheData = (cacheData: CacheValueType<ExtractResponse<T>, ExtractError<T>>) => {
const handleGetCacheData = async (cacheData: CacheValueType<ExtractResponse<T>, ExtractError<T>>) => {
handleCallbacks(cacheData.response); // Must be first
actions.setCacheData(cacheData, false);
actions.setLoading(false, false);
};

@@ -143,2 +144,3 @@

actions.setTimestamp(new Date(timestamp), false);
actions.setLoading(false, false);
};

@@ -214,6 +216,2 @@

const handleData = () => {
return responseDataModifierFn && state.data ? responseDataModifierFn(state.data) : state.data;
};
const handleDependencyTracking = () => {

@@ -278,7 +276,3 @@ if (!dependencyTracking) {

setRenderKey("data");
return handleData() as (MapperResponse extends never ? ExtractResponse<T> : MapperResponse) extends never
? ExtractResponse<T>
: MapperResponse extends never
? ExtractResponse<T>
: MapperResponse;
return state.data;
},

@@ -285,0 +279,0 @@ get error() {

@@ -13,3 +13,3 @@ import {

export type UseFetchOptionsType<T extends FetchCommandInstance, MapperResponse> = {
export type UseFetchOptionsType<T extends FetchCommandInstance> = {
dependencies?: any[];

@@ -30,10 +30,9 @@ disabled?: boolean;

shouldThrow?: boolean;
responseDataModifierFn?: ((data: ExtractResponse<T>) => MapperResponse) | null;
};
export type UseFetchReturnType<T extends FetchCommandInstance, MapperResponse = unknown> = Omit<
export type UseFetchReturnType<T extends FetchCommandInstance> = Omit<
UseDependentStateType<ExtractResponse<T>, ExtractError<T>>,
"data"
> & {
data: null | (MapperResponse extends never ? ExtractResponse<T> : MapperResponse);
data: null | ExtractResponse<T>;
actions: UseDependentStateActions<ExtractResponse<T>, ExtractError<T>>;

@@ -40,0 +39,0 @@ onRequest: (callback: OnRequestCallbackType) => void;

@@ -13,2 +13,3 @@ import { useRef } from "react";

import { useDebounce } from "use-debounce/use-debounce.hooks";
import {

@@ -28,3 +29,3 @@ UseSubmitOptionsType,

export const useSubmit = <T extends FetchCommandInstance, MapperResponse>(
export const useSubmit = <T extends FetchCommandInstance>(
command: T,

@@ -35,15 +36,14 @@ {

initialData = useSubmitDefaultOptions.initialData,
// debounce = useSubmitDefaultOptions.debounce,
// debounceTime = useSubmitDefaultOptions.debounceTime,
debounce = useSubmitDefaultOptions.debounce,
debounceTime = useSubmitDefaultOptions.debounceTime,
// suspense = useSubmitDefaultOptions.suspense,
// invalidate = useSubmitDefaultOptions.invalidate,
shouldThrow = useSubmitDefaultOptions.shouldThrow,
responseDataModifierFn = useSubmitDefaultOptions.responseDataModifierFn,
}: UseSubmitOptionsType<T, MapperResponse> = useSubmitDefaultOptions,
): UseSubmitReturnType<T, MapperResponse extends never ? ExtractResponse<T> : MapperResponse> => {
}: UseSubmitOptionsType<T> = useSubmitDefaultOptions,
): UseSubmitReturnType<T> => {
const { cacheTime, cacheKey, queueKey, builder } = command;
// const requestDebounce = useDebounce(debounceTime);
const requestDebounce = useDebounce(debounceTime);
const { cache, submitQueue, commandManager, loggerManager } = builder;
const logger = useRef(loggerManager.init("useSubmit")).current;
const [state, actions, setRenderKey] = useDependentState<T>(command, initialData);
const [state, actions, setRenderKey] = useDependentState<T>(command, initialData, submitQueue);

@@ -76,3 +76,8 @@ const onRequestCallback = useRef<null | OnRequestCallbackType>(null);

logger.debug(`Adding request to submit queue`, { disabled, options });
submitQueue.add(request);
if (debounce) {
requestDebounce.debounce(() => submitQueue.add(request));
} else {
submitQueue.add(request);
}
} else {

@@ -101,5 +106,6 @@ logger.debug(`Cannot add to submit queue`, { disabled, options });

const handleGetCacheData = (cacheData: CacheValueType<ExtractResponse<T>, ExtractError<T>>) => {
const handleGetCacheData = async (cacheData: CacheValueType<ExtractResponse<T>, ExtractError<T>>) => {
handleCallbacks(cacheData.response); // Must be first
actions.setCacheData(cacheData, false);
actions.setLoading(false, false);
};

@@ -111,2 +117,3 @@

actions.setTimestamp(new Date(timestamp), false);
actions.setLoading(false, false);
};

@@ -158,6 +165,2 @@

const handleData = () => {
return responseDataModifierFn && state.data ? responseDataModifierFn(state.data) : state.data;
};
const handleDependencyTracking = () => {

@@ -182,7 +185,3 @@ if (!dependencyTracking) {

setRenderKey("data");
return handleData() as (MapperResponse extends never ? ExtractResponse<T> : MapperResponse) extends never
? ExtractResponse<T>
: MapperResponse extends never
? ExtractResponse<T>
: MapperResponse;
return state.data;
},

@@ -189,0 +188,0 @@ get error() {

@@ -13,5 +13,5 @@ import {

export type UseSubmitOptionsType<T extends FetchCommandInstance, MapperResponse> = {
export type UseSubmitOptionsType<T extends FetchCommandInstance> = {
disabled?: boolean;
invalidate: (string | FetchCommandInstance)[];
invalidate?: (string | FetchCommandInstance)[];
cacheOnMount?: boolean;

@@ -23,11 +23,10 @@ initialData?: CacheValueType<ExtractResponse<T>, ExtractError<T>>["response"] | null;

shouldThrow?: boolean;
responseDataModifierFn?: ((data: ExtractResponse<T>) => MapperResponse) | null;
dependencyTracking?: boolean;
};
export type UseSubmitReturnType<T extends FetchCommandInstance, MapperResponse = unknown> = Omit<
export type UseSubmitReturnType<T extends FetchCommandInstance> = Omit<
UseDependentStateType<ExtractResponse<T>, ExtractError<T>>,
"data" | "refreshError" | "loading"
> & {
data: null | (MapperResponse extends never ? ExtractResponse<T> : MapperResponse);
data: null | ExtractResponse<T>;
actions: UseDependentStateActions<ExtractResponse<T>, ExtractError<T>>;

@@ -34,0 +33,0 @@ onSubmitRequest: (callback: OnRequestCallbackType) => void;

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

@@ -5,0 +5,0 @@ "description": "React hooks and utils for the hyper-fetch",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet