!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((t=t||self).ReactQuery={},t.React)}(this,(function(t,e){"use strict";var n="default"in e?e.default:e;function r(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}var i=function(){function t(){this.listeners=[]}var e=t.prototype;return e.subscribe=function(t){var e=this,n=t||function(){};return this.listeners.push(n),this.onSubscribe(),function(){e.listeners=e.listeners.filter((function(t){return t!==n})),e.onUnsubscribe()}},e.hasListeners=function(){return this.listeners.length>0},e.onSubscribe=function(){},e.onUnsubscribe=function(){},t}();function u(){return(u=Object.assign||function(t){for(var e=1;e=0&&t!==1/0}function c(t){return Array.isArray(t)?t:[t]}function l(t,e){return t.filter((function(t){return-1===e.indexOf(t)}))}function h(t,e){return Math.max(t+(e||0)-Date.now(),0)}function f(t,e,n){return R(t)?"function"==typeof e?u({},n,{queryKey:t,queryFn:e}):u({},e,{queryKey:t}):t}function d(t,e,n){return R(t)?[u({},e,{queryKey:t}),n]:[t||{},e]}function v(t,e){var n=t.active,r=t.exact,i=t.fetching,u=t.inactive,s=t.predicate,o=t.queryKey,a=t.stale;if(R(o))if(r){if(e.queryHash!==y(o,e.options))return!1}else if(!b(e.queryKey,o))return!1;var c=function(t,e){return!0===t&&!0===e||null==t&&null==e?"all":!1===t&&!1===e?"none":(null!=t?t:!e)?"active":"inactive"}(n,u);if("none"===c)return!1;if("all"!==c){var l=e.isActive();if("active"===c&&!l)return!1;if("inactive"===c&&l)return!1}return("boolean"!=typeof a||e.isStale()===a)&&(("boolean"!=typeof i||e.isFetching()===i)&&!(s&&!s(e)))}function p(t,e){var n=t.exact,r=t.fetching,i=t.predicate,u=t.mutationKey;if(R(u)){if(!e.options.mutationKey)return!1;if(n){if(m(e.options.mutationKey)!==m(u))return!1}else if(!b(e.options.mutationKey,u))return!1}return("boolean"!=typeof r||"loading"===e.state.status===r)&&!(i&&!i(e))}function y(t,e){return((null==e?void 0:e.queryKeyHashFn)||m)(t)}function m(t){var e,n=c(t);return e=n,JSON.stringify(e,(function(t,e){return O(e)?Object.keys(e).sort().reduce((function(t,n){return t[n]=e[n],t}),{}):e}))}function b(t,e){return function t(e,n){if(e===n)return!0;if(typeof e!=typeof n)return!1;if(e&&n&&"object"==typeof e&&"object"==typeof n)return!Object.keys(n).some((function(r){return!t(e[r],n[r])}));return!1}(c(t),c(e))}function g(t,e){if(t===e)return t;var n=Array.isArray(t)&&Array.isArray(e);if(n||O(t)&&O(e)){for(var r=n?t.length:Object.keys(t).length,i=n?e:Object.keys(e),u=i.length,s=n?[]:{},o=0,a=0;a0?this.queries.filter((function(t){return v(n,t)})):this.queries},n.notify=function(t){var e=this;A.batch((function(){e.listeners.forEach((function(e){e(t)}))}))},n.onFocus=function(){var t=this;A.batch((function(){t.queries.forEach((function(t){t.onFocus()}))}))},n.onOnline=function(){var t=this;A.batch((function(){t.queries.forEach((function(t){t.onOnline()}))}))},e}(i),K=function(){function t(t){this.options=u({},t.defaultOptions,t.options),this.mutationId=t.mutationId,this.mutationCache=t.mutationCache,this.observers=[],this.state=t.state||L(),this.meta=t.meta}var e=t.prototype;return e.setState=function(t){this.dispatch({type:"setState",state:t})},e.addObserver=function(t){-1===this.observers.indexOf(t)&&this.observers.push(t)},e.removeObserver=function(t){this.observers=this.observers.filter((function(e){return e!==t}))},e.cancel=function(){return this.retryer?(this.retryer.cancel(),this.retryer.promise.then(o).catch(o)):Promise.resolve()},e.continue=function(){return this.retryer?(this.retryer.continue(),this.retryer.promise):this.execute()},e.execute=function(){var t,e=this,n="loading"===this.state.status,r=Promise.resolve();return n||(this.dispatch({type:"loading",variables:this.options.variables}),r=r.then((function(){null==e.mutationCache.config.onMutate||e.mutationCache.config.onMutate(e.state.variables,e)})).then((function(){return null==e.options.onMutate?void 0:e.options.onMutate(e.state.variables)})).then((function(t){t!==e.state.context&&e.dispatch({type:"loading",context:t,variables:e.state.variables})}))),r.then((function(){return e.executeMutation()})).then((function(n){t=n,null==e.mutationCache.config.onSuccess||e.mutationCache.config.onSuccess(t,e.state.variables,e.state.context,e)})).then((function(){return null==e.options.onSuccess?void 0:e.options.onSuccess(t,e.state.variables,e.state.context)})).then((function(){return null==e.options.onSettled?void 0:e.options.onSettled(t,null,e.state.variables,e.state.context)})).then((function(){return e.dispatch({type:"success",data:t}),t})).catch((function(t){return null==e.mutationCache.config.onError||e.mutationCache.config.onError(t,e.state.variables,e.state.context,e),U().error(t),Promise.resolve().then((function(){return null==e.options.onError?void 0:e.options.onError(t,e.state.variables,e.state.context)})).then((function(){return null==e.options.onSettled?void 0:e.options.onSettled(void 0,t,e.state.variables,e.state.context)})).then((function(){throw e.dispatch({type:"error",error:t}),t}))}))},e.executeMutation=function(){var t,e=this;return this.retryer=new x({fn:function(){return e.options.mutationFn?e.options.mutationFn(e.state.variables):Promise.reject("No mutationFn found")},onFail:function(){e.dispatch({type:"failed"})},onPause:function(){e.dispatch({type:"pause"})},onContinue:function(){e.dispatch({type:"continue"})},retry:null!=(t=this.options.retry)?t:0,retryDelay:this.options.retryDelay}),this.retryer.promise},e.dispatch=function(t){var e=this;this.state=function(t,e){switch(e.type){case"failed":return u({},t,{failureCount:t.failureCount+1});case"pause":return u({},t,{isPaused:!0});case"continue":return u({},t,{isPaused:!1});case"loading":return u({},t,{context:e.context,data:void 0,error:null,isPaused:!1,status:"loading",variables:e.variables});case"success":return u({},t,{data:e.data,error:null,status:"success",isPaused:!1});case"error":return u({},t,{data:void 0,error:e.error,failureCount:t.failureCount+1,isPaused:!1,status:"error"});case"setState":return u({},t,e.state);default:return t}}(this.state,t),A.batch((function(){e.observers.forEach((function(e){e.onMutationUpdate(t)})),e.mutationCache.notify(e)}))},t}();function L(){return{context:void 0,data:void 0,error:null,failureCount:0,isPaused:!1,status:"idle",variables:void 0}}var j=function(t){function e(e){var n;return(n=t.call(this)||this).config=e||{},n.mutations=[],n.mutationId=0,n}r(e,t);var n=e.prototype;return n.build=function(t,e,n){var r=new K({mutationCache:this,mutationId:++this.mutationId,options:t.defaultMutationOptions(e),state:n,defaultOptions:e.mutationKey?t.getMutationDefaults(e.mutationKey):void 0,meta:e.meta});return this.add(r),r},n.add=function(t){this.mutations.push(t),this.notify(t)},n.remove=function(t){this.mutations=this.mutations.filter((function(e){return e!==t})),t.cancel(),this.notify(t)},n.clear=function(){var t=this;A.batch((function(){t.mutations.forEach((function(e){t.remove(e)}))}))},n.getAll=function(){return this.mutations},n.find=function(t){return void 0===t.exact&&(t.exact=!0),this.mutations.find((function(e){return p(t,e)}))},n.findAll=function(t){return this.mutations.filter((function(e){return p(t,e)}))},n.notify=function(t){var e=this;A.batch((function(){e.listeners.forEach((function(e){e(t)}))}))},n.onFocus=function(){this.resumePausedMutations()},n.onOnline=function(){this.resumePausedMutations()},n.resumePausedMutations=function(){var t=this.mutations.filter((function(t){return t.state.isPaused}));return A.batch((function(){return t.reduce((function(t,e){return t.then((function(){return e.continue().catch(o)}))}),Promise.resolve())}))},e}(i);function H(){return{onFetch:function(t){t.fetchFn=function(){var e,n,r,i,u,s,o,a=null==(e=t.fetchOptions)||null==(n=e.meta)?void 0:n.refetchPage,c=null==(r=t.fetchOptions)||null==(i=r.meta)?void 0:i.fetchMore,l=null==c?void 0:c.pageParam,h="forward"===(null==c?void 0:c.direction),f="backward"===(null==c?void 0:c.direction),d=(null==(u=t.state.data)?void 0:u.pages)||[],v=(null==(s=t.state.data)?void 0:s.pageParams)||[],p=q(),y=null==p?void 0:p.signal,m=v,b=!1,g=t.options.queryFn||function(){return Promise.reject("Missing queryFn")},O=function(t,e,n,r){return m=r?[e].concat(m):[].concat(m,[e]),r?[n].concat(t):[].concat(t,[n])},C=function(e,n,r,i){if(b)return Promise.reject("Cancelled");if(void 0===r&&!n&&e.length)return Promise.resolve(e);var u={queryKey:t.queryKey,signal:y,pageParam:r,meta:t.meta},s=g(u),o=Promise.resolve(s).then((function(t){return O(e,r,t,i)}));F(s)&&(o.cancel=s.cancel);return o};if(d.length)if(h){var R=void 0!==l,P=R?l:k(t.options,d);o=C(d,R,P)}else if(f){var Q=void 0!==l,E=Q?l:N(t.options,d);o=C(d,Q,E,!0)}else!function(){m=[];var e=void 0===t.options.getNextPageParam,n=!a||!d[0]||a(d[0],0,d);o=n?C([],e,v[0]):Promise.resolve(O([],v[0],d[0]));for(var r=function(n){o=o.then((function(r){if(!a||!d[n]||a(d[n],n,d)){var i=e?v[n]:k(t.options,r);return C(r,e,i)}return Promise.resolve(O(r,v[n],d[n]))}))},i=1;i0||h.errorUpdateCount>0,isFetchedAfterMount:h.dataUpdateCount>c.dataUpdateCount||h.errorUpdateCount>c.errorUpdateCount,isFetching:p,isRefetching:p&&"loading"!==y,isLoadingError:"error"===y&&0===h.dataUpdatedAt,isPlaceholderData:b,isPreviousData:m,isRefetchError:"error"===y&&0!==h.dataUpdatedAt,isStale:X(t,e),refetch:this.refetch,remove:this.remove}},n.shouldNotifyListeners=function(t,e){if(!e)return!0;var n=this.options,r=n.notifyOnChangeProps,i=n.notifyOnChangePropsExclusions;if(!r&&!i)return!0;if("tracked"===r&&!this.trackedProps.length)return!0;var u="tracked"===r?this.trackedProps:r;return Object.keys(t).some((function(n){var r=n,s=t[r]!==e[r],o=null==u?void 0:u.some((function(t){return t===n})),a=null==i?void 0:i.some((function(t){return t===n}));return s&&!a&&(!u||o)}))},n.updateResult=function(t){var e=this.currentResult;if(this.currentResult=this.createResult(this.currentQuery,this.options),this.currentResultState=this.currentQuery.state,this.currentResultOptions=this.options,!function(t,e){if(t&&!e||e&&!t)return!1;for(var n in t)if(t[n]!==e[n])return!1;return!0}(this.currentResult,e)){var n={cache:!0};!1!==(null==t?void 0:t.listeners)&&this.shouldNotifyListeners(this.currentResult,e)&&(n.listeners=!0),this.notify(u({},n,t))}},n.updateQuery=function(){var t=this.client.getQueryCache().build(this.client,this.options);if(t!==this.currentQuery){var e=this.currentQuery;this.currentQuery=t,this.currentQueryInitialState=t.state,this.previousQueryResult=this.currentResult,this.hasListeners()&&(null==e||e.removeObserver(this),t.addObserver(this))}},n.onQueryUpdate=function(t){var e={};"success"===t.type?e.onSuccess=!0:"error"!==t.type||w(t.error)||(e.onError=!0),this.updateResult(e),this.hasListeners()&&this.updateTimers()},n.notify=function(t){var e=this;A.batch((function(){t.onSuccess?(null==e.options.onSuccess||e.options.onSuccess(e.currentResult.data),null==e.options.onSettled||e.options.onSettled(e.currentResult.data,null)):t.onError&&(null==e.options.onError||e.options.onError(e.currentResult.error),null==e.options.onSettled||e.options.onSettled(void 0,e.currentResult.error)),t.listeners&&e.listeners.forEach((function(t){t(e.currentResult)})),t.cache&&e.client.getQueryCache().notify({query:e.currentQuery,type:"observerResultsUpdated"})}))},e}(i);function J(t,e){return function(t,e){return!(!1===e.enabled||t.state.dataUpdatedAt||"error"===t.state.status&&!1===e.retryOnMount)}(t,e)||t.state.dataUpdatedAt>0&&z(t,e,e.refetchOnMount)}function z(t,e,n){if(!1!==e.enabled){var r="function"==typeof n?n(t):n;return"always"===r||!1!==r&&X(t,e)}return!1}function V(t,e,n,r){return!1!==n.enabled&&(t!==e||!1===r.enabled)&&(!n.suspense||"error"!==t.state.status)&&X(t,n)}function X(t,e){return t.isStaleByTime(e.staleTime)}var Y=function(t){function e(e,n){var r;return(r=t.call(this)||this).client=e,r.queries=[],r.result=[],r.observers=[],r.observersMap={},n&&r.setQueries(n),r}r(e,t);var n=e.prototype;return n.onSubscribe=function(){var t=this;1===this.listeners.length&&this.observers.forEach((function(e){e.subscribe((function(n){t.onUpdate(e,n)}))}))},n.onUnsubscribe=function(){this.listeners.length||this.destroy()},n.destroy=function(){this.listeners=[],this.observers.forEach((function(t){t.destroy()}))},n.setQueries=function(t,e){this.queries=t,this.updateObservers(e)},n.getCurrentResult=function(){return this.result},n.getOptimisticResult=function(t){return this.findMatchingObservers(t).map((function(t){return t.observer.getOptimisticResult(t.defaultedQueryOptions)}))},n.findMatchingObservers=function(t){var e=this,n=this.observers,r=t.map((function(t){return e.client.defaultQueryObserverOptions(t)})),i=r.flatMap((function(t){var e=n.find((function(e){return e.options.queryHash===t.queryHash}));return null!=e?[{defaultedQueryOptions:t,observer:e}]:[]})),u=i.map((function(t){return t.defaultedQueryOptions.queryHash})),s=r.filter((function(t){return!u.includes(t.queryHash)})),o=n.filter((function(t){return!i.some((function(e){return e.observer===t}))})),a=s.map((function(t,n){if(t.keepPreviousData){var r=o[n];if(void 0!==r)return{defaultedQueryOptions:t,observer:r}}return{defaultedQueryOptions:t,observer:e.getObserver(t)}}));return i.concat(a).sort((function(t,e){return r.indexOf(t.defaultedQueryOptions)-r.indexOf(e.defaultedQueryOptions)}))},n.getObserver=function(t){var e=this.client.defaultQueryObserverOptions(t),n=this.observersMap[e.queryHash];return null!=n?n:new W(this.client,e)},n.updateObservers=function(t){var e=this;A.batch((function(){var n=e.observers,r=e.findMatchingObservers(e.queries);r.forEach((function(e){return e.observer.setOptions(e.defaultedQueryOptions,t)}));var i=r.map((function(t){return t.observer})),u=Object.fromEntries(i.map((function(t){return[t.options.queryHash,t]}))),s=i.map((function(t){return t.getCurrentResult()})),o=i.some((function(t,e){return t!==n[e]}));(n.length!==i.length||o)&&(e.observers=i,e.observersMap=u,e.result=s,e.hasListeners()&&(l(n,i).forEach((function(t){t.destroy()})),l(i,n).forEach((function(t){t.subscribe((function(n){e.onUpdate(t,n)}))})),e.notify()))}))},n.onUpdate=function(t,e){var n=this.observers.indexOf(t);-1!==n&&(this.result=function(t,e,n){var r=t.slice(0);return r[e]=n,r}(this.result,n,e),this.notify())},n.notify=function(){var t=this;A.batch((function(){t.listeners.forEach((function(e){e(t.result)}))}))},e}(i),Z=function(t){function e(e,n){return t.call(this,e,n)||this}r(e,t);var n=e.prototype;return n.bindMethods=function(){t.prototype.bindMethods.call(this),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)},n.setOptions=function(e,n){t.prototype.setOptions.call(this,u({},e,{behavior:H()}),n)},n.getOptimisticResult=function(e){return e.behavior=H(),t.prototype.getOptimisticResult.call(this,e)},n.fetchNextPage=function(t){var e;return this.fetch({cancelRefetch:null==(e=null==t?void 0:t.cancelRefetch)||e,throwOnError:null==t?void 0:t.throwOnError,meta:{fetchMore:{direction:"forward",pageParam:null==t?void 0:t.pageParam}}})},n.fetchPreviousPage=function(t){var e;return this.fetch({cancelRefetch:null==(e=null==t?void 0:t.cancelRefetch)||e,throwOnError:null==t?void 0:t.throwOnError,meta:{fetchMore:{direction:"backward",pageParam:null==t?void 0:t.pageParam}}})},n.createResult=function(e,n){var r,i,s,o,a,c,l=e.state;return u({},t.prototype.createResult.call(this,e,n),{fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:B(n,null==(r=l.data)?void 0:r.pages),hasPreviousPage:_(n,null==(i=l.data)?void 0:i.pages),isFetchingNextPage:l.isFetching&&"forward"===(null==(s=l.fetchMeta)||null==(o=s.fetchMore)?void 0:o.direction),isFetchingPreviousPage:l.isFetching&&"backward"===(null==(a=l.fetchMeta)||null==(c=a.fetchMore)?void 0:c.direction)})},e}(W),$=function(t){function e(e,n){var r;return(r=t.call(this)||this).client=e,r.setOptions(n),r.bindMethods(),r.updateResult(),r}r(e,t);var n=e.prototype;return n.bindMethods=function(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)},n.setOptions=function(t){this.options=this.client.defaultMutationOptions(t)},n.onUnsubscribe=function(){var t;this.listeners.length||(null==(t=this.currentMutation)||t.removeObserver(this))},n.onMutationUpdate=function(t){this.updateResult();var e={listeners:!0};"success"===t.type?e.onSuccess=!0:"error"===t.type&&(e.onError=!0),this.notify(e)},n.getCurrentResult=function(){return this.currentResult},n.reset=function(){this.currentMutation=void 0,this.updateResult(),this.notify({listeners:!0})},n.mutate=function(t,e){return this.mutateOptions=e,this.currentMutation&&this.currentMutation.removeObserver(this),this.currentMutation=this.client.getMutationCache().build(this.client,u({},this.options,{variables:void 0!==t?t:this.options.variables})),this.currentMutation.addObserver(this),this.currentMutation.execute()},n.updateResult=function(){var t=this.currentMutation?this.currentMutation.state:{context:void 0,data:void 0,error:null,failureCount:0,isPaused:!1,status:"idle",variables:void 0},e=u({},t,{isLoading:"loading"===t.status,isSuccess:"success"===t.status,isError:"error"===t.status,isIdle:"idle"===t.status,mutate:this.mutate,reset:this.reset});this.currentResult=e},n.notify=function(t){var e=this;A.batch((function(){e.mutateOptions&&(t.onSuccess?(null==e.mutateOptions.onSuccess||e.mutateOptions.onSuccess(e.currentResult.data,e.currentResult.variables,e.currentResult.context),null==e.mutateOptions.onSettled||e.mutateOptions.onSettled(e.currentResult.data,null,e.currentResult.variables,e.currentResult.context)):t.onError&&(null==e.mutateOptions.onError||e.mutateOptions.onError(e.currentResult.error,e.currentResult.variables,e.currentResult.context),null==e.mutateOptions.onSettled||e.mutateOptions.onSettled(void 0,e.currentResult.error,e.currentResult.variables,e.currentResult.context))),t.listeners&&e.listeners.forEach((function(t){t(e.currentResult)}))}))},e}(i);function tt(t){return t.state.isPaused}function et(t){return"success"===t.state.status}function nt(t,e,n){if("object"==typeof e&&null!==e){var r=t.getMutationCache(),i=t.getQueryCache(),s=e.mutations||[],o=e.queries||[];s.forEach((function(e){var i;r.build(t,u({},null==n||null==(i=n.defaultOptions)?void 0:i.mutations,{mutationKey:e.mutationKey}),e.state)})),o.forEach((function(e){var r,s=i.get(e.queryHash);s?s.state.dataUpdatedAt