reactjrx 1.68.0 → 1.69.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/README.md +6 -2
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.d.ts +5 -5
  4. package/dist/index.js +2052 -1488
  5. package/dist/lib/binding/types.d.ts +2 -0
  6. package/dist/lib/binding/useObservableEvent.d.ts +5 -0
  7. package/dist/lib/binding/useObservableState.d.ts +16 -0
  8. package/dist/lib/binding/useSubscribe.d.ts +2 -3
  9. package/dist/lib/binding/useSubscribeEffect.d.ts +11 -0
  10. package/dist/lib/queries/client/QueryClient.d.ts +48 -0
  11. package/dist/lib/queries/client/focusManager.d.ts +19 -0
  12. package/dist/lib/queries/client/keys/hashKey.d.ts +3 -0
  13. package/dist/lib/queries/client/keys/{compareKeys.d.ts → matchKey.d.ts} +1 -1
  14. package/dist/lib/queries/client/keys/partialMatchKey.d.ts +5 -0
  15. package/dist/lib/queries/client/mutations/cache/MutationCache.d.ts +5 -16
  16. package/dist/lib/queries/client/mutations/mutation/Mutation.d.ts +4 -10
  17. package/dist/lib/queries/client/mutations/mutation/delayWhenNetworkOnline.d.ts +4 -0
  18. package/dist/lib/queries/client/mutations/mutation/observeUntilFinished.d.ts +3 -0
  19. package/dist/lib/queries/client/mutations/mutation/types.d.ts +4 -3
  20. package/dist/lib/queries/client/mutations/mutation/waitForNetworkOnError.d.ts +6 -0
  21. package/dist/lib/queries/client/mutations/observers/MutationObserver.d.ts +1 -7
  22. package/dist/lib/queries/client/mutations/runner/MutationRunner.d.ts +9 -7
  23. package/dist/lib/queries/client/onlineManager.d.ts +10 -0
  24. package/dist/lib/queries/client/queries/cache/QueryCache.d.ts +33 -0
  25. package/dist/lib/queries/client/queries/cache/types.d.ts +45 -0
  26. package/dist/lib/queries/client/queries/observer/QueryObserver.d.ts +65 -0
  27. package/dist/lib/queries/client/queries/observer/queryStateHelpers.d.ts +9 -0
  28. package/dist/lib/queries/client/queries/observer/types.d.ts +241 -0
  29. package/dist/lib/queries/client/queries/query/Query.d.ts +71 -0
  30. package/dist/lib/queries/client/queries/query/delayOnNetworkMode.d.ts +6 -0
  31. package/dist/lib/queries/client/queries/query/delayUntilFocus.d.ts +2 -0
  32. package/dist/lib/queries/client/queries/query/executeQuery.d.ts +17 -0
  33. package/dist/lib/queries/client/queries/query/getDefaultState.d.ts +4 -0
  34. package/dist/lib/queries/client/queries/query/operators.d.ts +13 -0
  35. package/dist/lib/queries/client/queries/query/types.d.ts +93 -0
  36. package/dist/lib/queries/client/queries/retryer/CancelledError.d.ts +6 -0
  37. package/dist/lib/queries/client/queries/retryer/types.d.ts +4 -0
  38. package/dist/lib/queries/client/queries/retryer/utils.d.ts +2 -0
  39. package/dist/lib/queries/client/queries/types.d.ts +112 -0
  40. package/dist/lib/queries/client/queries/utils.d.ts +8 -0
  41. package/dist/lib/queries/client/store.d.ts +25 -0
  42. package/dist/lib/queries/client/tests/utils.d.ts +7 -1
  43. package/dist/lib/queries/client/types.d.ts +20 -11
  44. package/dist/lib/queries/client/utils/keepPreviousData.d.ts +1 -0
  45. package/dist/lib/queries/client/utils/makeObservable.d.ts +6 -0
  46. package/dist/lib/queries/react/QueryClientProvider.d.ts +7 -0
  47. package/dist/lib/queries/react/QueryClientProvider.rq.test.d.ts +1 -0
  48. package/dist/lib/queries/react/mutations/useIsMutating.d.ts +1 -1
  49. package/dist/lib/queries/react/mutations/useMutation.d.ts +1 -1
  50. package/dist/lib/queries/react/mutations/useMutationState.d.ts +2 -2
  51. package/dist/lib/queries/react/queries/QueryErrorResetBoundary.d.ts +11 -0
  52. package/dist/lib/queries/react/queries/QueryOptions.rq.types.test.d.ts +1 -0
  53. package/dist/lib/queries/react/queries/errorBoundaryUtils.d.ts +12 -0
  54. package/dist/lib/queries/react/queries/isRestoring.d.ts +3 -0
  55. package/dist/lib/queries/react/queries/queryOptions.d.ts +18 -0
  56. package/dist/lib/queries/react/queries/types.d.ts +9 -11
  57. package/dist/lib/queries/react/queries/useBaseQuery.d.ts +6 -0
  58. package/dist/lib/queries/react/queries/useIsFetching.d.ts +3 -0
  59. package/dist/lib/queries/react/queries/useIsFetching.rq.test.d.ts +1 -0
  60. package/dist/lib/queries/react/queries/useQuery.d.ts +8 -6
  61. package/dist/lib/queries/react/queries/useQuery.rq.test.d.ts +1 -0
  62. package/dist/lib/queries/react/queries/useQuery.rq.types.test.d.ts +1 -0
  63. package/dist/lib/queries/react/useQueryClient.d.ts +2 -0
  64. package/dist/lib/utils/filterObjectByKey.d.ts +1 -0
  65. package/dist/lib/utils/hasObjectPrototype.d.ts +1 -0
  66. package/dist/lib/utils/index.d.ts +1 -0
  67. package/dist/lib/utils/isPlainArray.d.ts +1 -0
  68. package/dist/lib/utils/isPlainObject.d.ts +1 -0
  69. package/dist/lib/utils/isPromiseLike.d.ts +1 -0
  70. package/dist/lib/utils/isServer.d.ts +1 -0
  71. package/dist/lib/utils/operators/retryBackoff.d.ts +7 -5
  72. package/dist/lib/utils/replaceEqualDeep.d.ts +6 -0
  73. package/dist/lib/utils/types.d.ts +7 -0
  74. package/dist/tests/testUtils.d.ts +1 -1
  75. package/dist/tests/utils.d.ts +12 -6
  76. package/package.json +10 -11
  77. package/dist/lib/binding/trigger.d.ts +0 -4
  78. package/dist/lib/binding/useObserveCallback.d.ts +0 -5
  79. package/dist/lib/queries/client/cache/cacheClient.d.ts +0 -12
  80. package/dist/lib/queries/client/cache/invalidateCache.d.ts +0 -5
  81. package/dist/lib/queries/client/cache/logger.d.ts +0 -24
  82. package/dist/lib/queries/client/cache/registerResultInCache.d.ts +0 -8
  83. package/dist/lib/queries/client/createClient.d.ts +0 -90
  84. package/dist/lib/queries/client/deduplication/deduplicate.d.ts +0 -3
  85. package/dist/lib/queries/client/fetch/notifyQueryResult.d.ts +0 -3
  86. package/dist/lib/queries/client/fetch/queryFetch.d.ts +0 -12
  87. package/dist/lib/queries/client/invalidation/invalidationClient.d.ts +0 -11
  88. package/dist/lib/queries/client/invalidation/logger.d.ts +0 -24
  89. package/dist/lib/queries/client/invalidation/markAsStale.d.ts +0 -8
  90. package/dist/lib/queries/client/keys/serializeKey.d.ts +0 -4
  91. package/dist/lib/queries/client/keys/withKeyComparison.d.ts +0 -16
  92. package/dist/lib/queries/client/operators.d.ts +0 -8
  93. package/dist/lib/queries/client/refetch/client.d.ts +0 -17
  94. package/dist/lib/queries/client/refetch/dispatchExternalRefetchToAllQueries.d.ts +0 -3
  95. package/dist/lib/queries/client/refetch/logger.d.ts +0 -24
  96. package/dist/lib/queries/client/refetch/markQueryAsStaleIfRefetch.d.ts +0 -3
  97. package/dist/lib/queries/client/store/createQueryStore.d.ts +0 -55
  98. package/dist/lib/queries/client/store/debugger.d.ts +0 -3
  99. package/dist/lib/queries/client/store/garbageCache.d.ts +0 -5
  100. package/dist/lib/queries/client/store/initializeQueryInStore.d.ts +0 -8
  101. package/dist/lib/queries/client/store/mapStoreQueryToRunnerOptions.d.ts +0 -4
  102. package/dist/lib/queries/client/store/queryListener.d.ts +0 -3
  103. package/dist/lib/queries/client/store/updateStoreWithNewQuery.d.ts +0 -10
  104. package/dist/lib/queries/client/triggers.d.ts +0 -8
  105. package/dist/lib/queries/client/utils/functionAsObservable.d.ts +0 -2
  106. package/dist/lib/queries/client/utils/wrapInPromise.d.ts +0 -3
  107. package/dist/lib/queries/react/Provider.d.ts +0 -12
  108. package/dist/lib/queries/react/queries/helpers.d.ts +0 -28
  109. package/dist/lib/queries/react/triggers/activityTrigger.d.ts +0 -11
  110. package/dist/lib/queries/react/triggers/networkTrigger.d.ts +0 -8
  111. package/dist/lib/queries/react/useSubscribeEffect.d.ts +0 -10
  112. /package/dist/lib/queries/client/{cache/cache.garbage.test.d.ts → QueryClient.types.rq.test.d.ts} +0 -0
  113. /package/dist/lib/queries/client/{cache/cacheClient.test.d.ts → focusManager.rq.test.d.ts} +0 -0
  114. /package/dist/lib/queries/client/{deduplication/deduplicate.test.d.ts → keys/hashKey.test.d.ts} +0 -0
  115. /package/dist/lib/queries/client/{invalidation/invalidation.test.d.ts → keys/matchKey.test.d.ts} +0 -0
  116. /package/dist/lib/queries/client/keys/{compareKeys.test.d.ts → partialMatchKey.rq.test.d.ts} +0 -0
  117. /package/dist/lib/queries/client/{keys/keys.test.d.ts → mutations/cache/mutationCache.rq.test.d.ts} +0 -0
  118. /package/dist/lib/queries/client/{keys/serializeKey.test.d.ts → queries/observer/QueryObserver.rq.test.d.ts} +0 -0
  119. /package/dist/lib/queries/client/{mutations/cache/mutationCache.test.d.ts → queries/observer/QueryObserver.types.rq.test.d.ts} +0 -0
  120. /package/dist/lib/queries/client/{refetch/refetch.test.d.ts → queries/query/query.rq.test.d.ts} +0 -0
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
- #reactjrx
1
+ # reactjrx
2
2
 
3
- `reactjrx` is a javascript library which provides a simple and efficient API for handling global state, flow control, and queries in React applications using RxJS. With a small footprint and scalability to suit any project size, it is a great alternative to other popular libraries such as Recoil, Redux, React Query, Zustand, etc.
3
+ `reactjrx` is an innovative library designed to bridge RxJS and React, offering developers a powerful set of tools to integrate observables into their React applications seamlessly.
4
+
5
+ It simplifies the reactive programming approach by providing easy-to-use bindings for observing and reacting to data changes, coupled with advanced state management and queries helpers akin to `react-query` for handling effects, mutations, and asynchronous data fetching.
6
+
7
+ Tailored for projects where RxJS is a core dependency, `reactjrx` enhances the development experience by enabling more dynamic, efficient, and responsive UIs, making it an essential addition for developers looking to leverage the full potential of RxJS within their React applications.
4
8
 
5
9
  Please visit the [documentation](https://bret-maxime.gitbook.io/reactjrx/) for more information on how to use.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var fe=Object.defineProperty;var de=(r,t,n)=>t in r?fe(r,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[t]=n;var S=(r,t,n)=>(de(r,typeof t!="symbol"?t+"":t,n),n),he=(r,t,n)=>{if(!t.has(r))throw TypeError("Cannot "+n)};var T=(r,t,n)=>(he(r,t,"read from private field"),n?n.call(r):t.get(r)),z=(r,t,n)=>{if(t.has(r))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(r):t.set(r,n)};Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react"),e=require("rxjs"),P=require("rxjs/operators"),B=require("react/jsx-runtime"),R=r=>{const t=b.useRef(r);return b.useMemo(()=>{t.current=r},[r]),t};function ge(r,t){return typeof r=="string"&&r===t||typeof r=="number"&&r===t||typeof r=="boolean"&&r===t||typeof r=="symbol"&&r===t||typeof r=="bigint"&&r===t||typeof r>"u"&&r===t||r===null&&r===t}function A(r,t,n){const s=t!=null&&!Array.isArray(t)?t:{defaultValue:void 0,key:"",unsubscribeOnUnmount:!0},i=n==null&&Array.isArray(t)?t:typeof r=="function"?n??[]:[r],u=b.useRef("getValue"in r&&typeof r.getValue=="function"?r.getValue():s.defaultValue),a=R(r),l=R(s),f=b.useCallback(h=>{const p=a.current,o=(typeof p=="function"?p:()=>p)().pipe(e.distinctUntilChanged(ge),e.tap(m=>{u.current=m}),e.finalize(h),e.catchError(m=>(console.error(m),u.current=void 0,e.EMPTY))).subscribe(h);return()=>{l.current.unsubscribeOnUnmount!==!1&&o.unsubscribe()}},[...i]),g=b.useCallback(()=>u.current,[]);return b.useSyncExternalStore(f,g,g)}function Y(r,t=[]){const n=R(r),s=typeof r=="function"?void 0:r;b.useEffect(()=>{const i=n.current,a=(typeof i=="function"?i:()=>i)().pipe(e.catchError(l=>(console.error("Uncaught error at useSubscribe. Please consider adding a catchError or other handling."),console.error(l),e.EMPTY))).subscribe();return()=>{a.unsubscribe()}},[...t,s,n])}const J=r=>{const t=b.useRef();return t.current||(t.current=r()),b.useEffect(()=>{process.env.NODE_ENV},[]),t},K=({onBeforeComplete:r,completeOnUnmount:t=!0}={})=>{const n=J(()=>new e.Subject),s=b.useRef(!1),i=R(r),u=R(t);return b.useEffect(()=>(s.current&&(n.current=new e.Subject,s.current=!1),()=>{if(!u.current){s.current=!0;return}s.current||(i.current!=null&&i.current(),n.current.complete(),s.current=!0)}),[u,i,n]),n},me=(r,t)=>{const n=K();return Y(()=>r(n.current),[n,...t]),[b.useCallback(i=>{n.current.next(i)},[n]),n]};function be(r=e.identity){const t=new e.Subject;return[t.asObservable(),(...n)=>{t.next(r(...n))}]}const X=r=>{const t=J(()=>new e.BehaviorSubject(r)),n=b.useRef(!1),s=b.useRef(r);return b.useEffect(()=>(n.current&&(t.current=new e.BehaviorSubject(s.current),n.current=!1),()=>{n.current||(t.current.complete(),n.current=!0)}),[t]),t},Z=Symbol("SIGNAL_RESET");function ye(r){const{default:t}=r??{},n=new e.BehaviorSubject(t);return{setValue:u=>{if(typeof u=="function"){const a=u(n.getValue());if(a===n.getValue())return;n.next(a);return}if(u===Z){n.next(t??void 0);return}n.next(u)},getValue:()=>n.getValue(),config:r,subject:n}}function Se(r,t){const n=t??(s=>s);return A(()=>r.subject.pipe(e.map(s=>n(s)),e.distinctUntilChanged()),{defaultValue:n(r.getValue())},[])}const H=r=>{if(!(!r||typeof r!="object"))return r},ve=({adapter:r,key:t})=>({getItem:async n=>{const s=await r.getItem(t),i=H(s)??{};if(n in i)return i[n]},setItem:async(n,s)=>{const i=await r.getItem(t),u=H(i)??{};await r.setItem(t,{...u,[n]:s})}}),$e=r=>({getItem:async t=>{const n=await r.getItem(t);if(n)return JSON.parse(n)},setItem:async(t,n)=>{await r.setItem(t,JSON.stringify(n))}}),we=r=>({getItem:async t=>{const n=r.getItem(t);if(n)return JSON.parse(n)},setItem:async(t,n)=>{r.setItem(t,JSON.stringify(n))}}),j="__reactjrx",Ee=r=>{if(typeof r=="object"&&r!==null&&j in r&&r[j]===j)return r},Ce=async({adapter:r,signal:t,version:n})=>{const i={value:t.getValue(),[j]:j,migrationVersion:n};await r.setItem(t.config.key,i)},Me=({adapter:r,version:t,signal:n})=>e.from(r.getItem(n.config.key)).pipe(e.switchMap(s=>{const i=Ee(s);return!i||i.migrationVersion!==void 0&&t>i.migrationVersion||n.setValue(s.value),e.of(s)})),Re=({entries:r=[],onReady:t,adapter:n=we(localStorage)})=>{const s=R(r),i=R(t),u=R(n),a=A(()=>{const l=s.current;return(l.length===0?e.of(!0):e.zip(...l.map(({signal:g,version:d})=>Me({adapter:u.current,signal:g,version:d}))).pipe(e.map(()=>!0))).pipe(e.tap(()=>{i.current!=null&&i.current()}),e.catchError(g=>(console.error("Unable to hydrate",g),e.EMPTY)))},{defaultValue:!1},[]);return Y(()=>a?e.merge(...s.current.map(({signal:l,version:f})=>l.subject.pipe(e.throttleTime(500,e.asyncScheduler,{trailing:!0}),e.switchMap(()=>e.from(Ce({adapter:u.current,signal:l,version:f})))))):e.EMPTY,[a,u]),{isHydrated:a}},Oe=()=>{const r=K({onBeforeComplete:()=>{r.current.next()}});return r};function q(r,t){return Math.min(r,t)}function ee(r,t){return Math.pow(2,r)*t}function te(r){const{initialInterval:t,maxRetries:n=1/0,maxInterval:s=1/0,shouldRetry:i=()=>!0,resetOnSuccess:u=!1,backoffDelay:a=ee}=r;return l=>e.defer(()=>{let f=0;const g=(d,h)=>d<n&&i(d,h);return l.pipe(P.catchError(d=>{var p;if(f++,!g(f-1,d))throw d;const h=(p=r.caughtError)==null?void 0:p.call(r,f,d);if(!h)throw d;return e.merge(h,e.throwError(()=>d))}),P.retryWhen(d=>d.pipe(P.concatMap(h=>{const p=f-1;return e.iif(()=>g(p,h),e.timer(q(a(p,t),s)),e.throwError(()=>h))}))),P.catchError(d=>{if(r.catchError)return r.catchError(f,d);throw d}),P.tap(()=>{u&&(f=0)}))})}const re=b.createContext({client:null}),Te=({client:r})=>(b.useEffect(()=>{const t=r.mount();return()=>{t()}},[r]),null),xe=b.memo(({children:r,client:t})=>{const n=b.useMemo(()=>({client:t}),[t]);return B.jsxs(re.Provider,{value:n,children:[B.jsx(Te,{client:n.client}),r]})}),G=({unsafe:r=!1}={})=>{const t=b.useContext(re);if(!r&&t.client===null)throw new Error("You forgot to register the provider");return t.client},L=r=>Array.isArray(r)?r.reduce((t,n,s)=>s===r.length-1?`${t}${L(n)}]`:`${t}${L(n)},`,"["):r===void 0?"":JSON.stringify(r,Object.keys(r).sort()),O=r=>r.length===0?"[]":L(r),ne=(r=21)=>crypto.getRandomValues(new Uint8Array(r)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),""),U=()=>({context:void 0,data:void 0,error:null,status:"idle",submittedAt:0,variables:void 0,failureCount:0,failureReason:null,isPaused:!1});function C(r,t){if(r==null||t===void 0||typeof r!="object"||typeof t!="object")return r===t;if(r.constructor!==(t==null?void 0:t.constructor))return!1;const n=Object.keys(r),s=Object.keys(t);if(n.length!==s.length)return!1;for(const i of n)if(!t.hasOwnProperty(i)||r[i]!==t[i])return!1;return!0}function se(r){let t=0;return function(s){return new e.Observable(i=>{t++,r(t);const u=s.subscribe(i);return()=>{t--,r(t),u.unsubscribe()}})}}class Ve{constructor({__queryFinalizeHook:t}={}){S(this,"trigger$",new e.Subject);S(this,"state$");const n=new e.BehaviorSubject(0),s=n.pipe(e.filter(i=>i===0));this.state$=this.trigger$.pipe(e.concatMap(({args:i,mutation:u,options:a})=>{const l=a.mapOperator??"merge",f=this.trigger$.pipe(e.filter(()=>l==="merge")),g=this.trigger$.pipe(e.filter(()=>l==="switch"),e.tap(()=>{u.reset()})),d=e.defer(()=>(u.execute(i),e.EMPTY)),h=u.observeTillFinished().pipe(e.last(),e.mergeMap(()=>u.state$),e.takeUntil(this.trigger$)),p=u.observeTillFinished().pipe(e.skip(1));return e.merge(p,h,d).pipe(t??e.identity,e.takeUntil(e.merge(s,f,g)))}),e.scan((i,u)=>({...i,...u,...u.status==="pending"&&{data:u.data??i.data},...u.status==="pending"&&{error:u.error??i.error}}),U()),e.distinctUntilChanged(({data:i,...u},{data:a,...l})=>C(u,l)&&C(i,a)),e.shareReplay({refCount:!0,bufferSize:1}),se(i=>{n.next(i)}))}trigger({args:t,options:n,mutation:s}){this.trigger$.next({args:t,options:n,mutation:s})}}function Q(r){return r!=null}const _=(r,t,{exact:n=!1}={})=>n?O(r)===O(t):r.reduce((s,i,u)=>s?i===void 0&&!r.slice(u,r.length-1).some(l=>l!==void 0)?!0:L(i)===L(t[u]):!1,!0);var x;class ke{constructor(t,n={},s){S(this,"numberOfObservers",0);S(this,"mutationRunner");z(this,x,new e.BehaviorSubject(void 0));S(this,"observed$");S(this,"result$");S(this,"getObserverResultFromState",t=>({...U(),...t,isSuccess:t.status==="success",isPending:t.status==="pending",isIdle:t.status==="idle",isError:t.status==="error",mutate:this.mutate,reset:this.reset}));var i;this.client=t,this.options=n,this.options.mutationKey=((i=this.options)==null?void 0:i.mutationKey)??[ne()],this.mutationRunner=s??new Ve(this.options),this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this),this.result$=this.mutationRunner.state$.pipe(e.map(u=>({state:this.getObserverResultFromState(u),options:{}}))),T(this,x).pipe(e.filter(Q),e.mergeMap(u=>this.mutationRunner.state$.pipe(e.takeUntil(u.mutation.observeTillFinished().pipe(e.last()))))).subscribe(),this.observed$=T(this,x).pipe(e.switchMap(u=>(u==null?void 0:u.mutation.observeTillFinished().pipe(e.last(),e.map(a=>({state:a,options:u.options}))))??e.EMPTY),e.mergeMap(({state:u,options:a})=>(u.status==="error"&&(a!=null&&a.onError&&(a==null||a.onError(u.error,u.variables,u.context)),a!=null&&a.onSettled&&(a==null||a.onSettled(u.data,u.error,u.variables,u.context))),u.status==="success"&&(a!=null&&a.onSuccess&&(a==null||a.onSuccess(u.data,u.variables,u.context)),a!=null&&a.onSettled&&(a==null||a.onSettled(u.data,u.error,u.variables,u.context))),e.EMPTY)))}setOptions(t){var s;const n=this.options;this.options=this.client.defaultMutationOptions({mutationKey:this.options.mutationKey,...t}),(s=T(this,x).getValue())==null||s.mutation.setOptions(this.options),this.options.mutationKey&&n.mutationKey&&!_(this.options.mutationKey,n.mutationKey,{exact:!0})&&this.reset()}observe(){var s;const t=this.getObserverResultFromState(((s=T(this,x).getValue())==null?void 0:s.mutation.state)??U());return{result$:e.merge(this.observed$,this.result$.pipe(e.map(({state:i})=>i))),lastValue:t}}subscribe(t){const n=this.observe().result$.subscribe(s=>{t(s)});return()=>{n.unsubscribe()}}async mutate(t,n={}){const s=this.client.getMutationCache().build(this.client,this.options);return T(this,x).next({mutation:s,options:n}),this.mutationRunner.trigger({args:t,options:this.options,mutation:s}),await new Promise((i,u)=>{s.observeTillFinished().pipe(e.last()).subscribe({error:a=>{u(a)},next:a=>{a.error?u(a.error):i(a.data)}})})}getCurrentResult(){var n;const t=this.client.getMutationCache().find({exact:!0,mutationKey:(n=this.options)==null?void 0:n.mutationKey});return this.getObserverResultFromState((t==null?void 0:t.state)??U())}reset(){var t;(t=T(this,x).getValue())==null||t.mutation.reset()}}x=new WeakMap;function Ue(){}function Ie(r,t){const n=G({unsafe:!!t}),s=t??n,i=R(r),u=J(()=>[ne()]),a=O(r.mutationKey??u.current),[l]=b.useState(()=>new ke(s,r));b.useEffect(()=>{l.setOptions(r)},[l,r]);const f=b.useMemo(()=>l.observe(),[a,l]),g=A(f.result$)??f.lastValue,d=b.useCallback((h,p)=>{l.mutate(h,p).catch(Ue)},[l]);return b.useEffect(()=>()=>{i.current.cancelOnUnMount&&l.reset()},[l,i]),{...g,mutate:d,mutateAsync:g.mutate}}const ie=(r,t)=>r.length===t.length&&r.every((n,s)=>n===t[s]),Qe=r=>r.pipe(e.switchMap(({options:{refetchOnWindowFocus:t=!0}})=>{const n=typeof t=="function"?t({}):t;return n!==!1?e.merge(e.fromEvent(document,"visibilitychange").pipe(e.filter(()=>!document.hidden),e.map(()=>({type:"refetch",ignoreStale:n==="always"}))),e.fromEvent(window,"focus").pipe(e.map(()=>({type:"refetch",ignoreStale:n==="always"})))):e.EMPTY})),Pe=r=>r.pipe(e.switchMap(({options:{refetchOnReconnect:t=!0}})=>{const n=typeof t=="function"?t({}):t;return n!==!1?e.fromEvent(window,"online").pipe(e.map(()=>({type:"refetch",ignoreStale:n==="always"}))):e.EMPTY})),je=({queryKey:r,queryFn:t,...n})=>{const s=X({queryKey:r,options:n,queryFn:t});return b.useEffect(()=>{s.current.next({queryKey:r,options:n,queryFn:t})},[r,n,t,s]),s},Fe={data:void 0,isLoading:!0,error:void 0,status:"loading",fetchStatus:"idle"};function Le({queryKey:r,queryFn:t,...n}){const s=K(),i=G(),u=je({queryFn:t,queryKey:r,...n}),a=A(()=>{const f=u.current.pipe(e.map(({queryKey:v})=>v??[])),g=e.of(null),d=f.pipe(e.distinctUntilChanged(ie),e.skip(1)),h=v=>!!v&&typeof v!="function",p=u.current.pipe(e.map(({queryFn:v})=>v),e.filter(h),e.distinctUntilChanged(C),h(u.current.getValue().queryFn)?e.skip(1):e.identity),c=u.current.pipe(e.map(({queryFn:v})=>v),e.filter(Q)),o=u.current.pipe(e.map(({options:v})=>v)),m=Qe(u.current),w=Pe(u.current),y=e.merge(g,d,p),V=e.merge(s.current,e.merge(m,w).pipe(e.throttleTime(500)));return y.pipe(e.withLatestFrom(f),e.switchMap(([,v])=>{const{result$:$}=i.client.query({key:v,fn$:c,options$:o,trigger$:V});return $.pipe(e.scan((M,{data:k,...D})=>({data:void 0,...M,...D,isLoading:D.status==="loading",...k&&{data:k.result}}),{}))}))},{defaultValue:{...Fe,isLoading:u.current.getValue().options.enabled!==!1}},[i]),l=b.useCallback(()=>{s.current.next({type:"refetch",ignoreStale:!0})},[s]);return{...a,refetch:l}}function _e(r,t,n=[]){const i=(t!=null&&!Array.isArray(t)?t:{}).retry??!0,u=typeof r=="function",a=b.useCallback(u?r:()=>r,u?n:[r]),l=b.useCallback(()=>a().pipe(e.catchError(f=>{throw console.error(f),f}),i?e.retry():e.identity),[a,i]);Y(l,n)}const ue=({retryDelay:r,retry:t,...n})=>te({initialInterval:typeof r=="number"?r:100,...typeof t=="function"?{shouldRetry:t}:{maxRetries:t===!1?0:t??0},...n}),Ne=r=>r.pipe(e.scan((t,n)=>({...t,...n}),{data:void 0,error:void 0,fetchStatus:"idle",status:"loading"}),e.distinctUntilChanged(({data:t,...n},{data:s,...i})=>C(n,i)&&C(t,s))),Ae={backgroundColor:"transparent",color:"inherit"};function ae(r){const t={namespaces:[{name:"@reactjrx",style:{backgroundColor:"#d02f4e",color:"white"}}],namespace(n,s){const i=ae(r);return i.namespaces.push({name:n,style:s??Ae}),i},printNamespaces(){return{namespaces:t.namespaces.map(({name:n})=>`%c ${n} %c`).join(" "),styles:t.namespaces.reduce((n,{style:s})=>(n.push(`background-color: ${s.backgroundColor}; color: ${s.color};`),n.push("background-color: transparent; color: inherit;"),n),[])}},print(n,...s){if(r==="development"){const{namespaces:i,styles:u}=t.printNamespaces();console[n](i,...u,...s)}return t},printWithoutNamespace(n,...s){return r==="development"&&console[n](...s),t},log(...n){return t.print("log",...n)},warn(...n){return t.print("warn",...n)},error(...n){return t.print("error",...n)},group(...n){return t.print("group",...n)},groupEnd(){return r==="development"&&console.groupEnd(),t}};return t}const I=ae("production"),Ye=I.namespace("store"),Ke=r=>r.pipe(e.map(t=>[...t.keys()].reduce((n,s)=>{var i;return n[s]=(i=t.get(s))==null?void 0:i.getValue(),n},{})),e.distinctUntilChanged(C)).subscribe(t=>{Ye.log("store","update",t)}),ze=()=>{const r=new Map,t=new e.BehaviorSubject(r),n=new e.Subject,s=new e.Subject,i=()=>{t.next(r)},u=(c,o)=>{r.set(c,new e.BehaviorSubject(o)),i()},a=c=>{var o;return(o=r.get(c))==null?void 0:o.getValue()},l=c=>t.pipe(e.map(()=>r.get(c)),e.filter(Q),e.map(o=>o.getValue()),e.distinctUntilChanged(C)),f=(c,o)=>{const m=r.get(c);m&&(typeof o=="function"?m.next({...m.getValue(),...o(m.getValue())}):m.next({...m.getValue(),...o}),t.next(r))},g=(c,o=()=>!0)=>{r.forEach(m=>{const w=m.getValue();o(w)&&m.next({...w,...c})}),t.next(r)},d=c=>{r.delete(c),t.next(r)},h=(c,o)=>(f(c,m=>({...m,runners:[...m.runners,o]})),()=>{var w;const m=((w=r.get(c))==null?void 0:w.getValue().runners.filter(y=>y!==o))??[];f(c,y=>({...y,runners:m}))}),p=()=>{const c=Ke(t);return()=>{c.unsubscribe()}};return{set:u,get:a,get$:l,delete:d,update:f,keys:()=>r.keys(),updateMany:g,addRunner:h,store$:t,queryEvent$:n.asObservable(),dispatchQueryEvent:c=>{n.next(c)},queryTrigger$:s.asObservable(),dispatchQueryTrigger:c=>{s.next(c)},size:()=>r.size,start:p}},We=({options$:r,queryStore:t,key:n})=>{const i=r.pipe(e.map(({enabled:u=!0})=>u),e.distinctUntilChanged()).pipe(e.skip(1),e.filter(u=>u));return e.merge(t.queryTrigger$.pipe(e.filter(u=>n===u.key),e.map(({trigger:u})=>u)),i.pipe(e.map(()=>({type:"enabled",ignoreStale:!1}))))},Je=(r,t)=>n=>r===O([])?n:e.defer(()=>{var a;const s=(a=t.get(r))==null?void 0:a.deduplication_fn;if(s)return s;let i;const u=()=>{var l;((l=t.get(r))==null?void 0:l.deduplication_fn)===i&&t.update(r,{deduplication_fn:void 0})};return i=n.pipe(e.tap({error:u,complete:u}),e.finalize(u),e.shareReplay({refCount:!0,bufferSize:1})),t.update(r,{deduplication_fn:i}),i}),Ge=r=>t=>t.pipe(e.withLatestFrom(r),e.map(([n,s])=>{var i,u;return n.error?(i=s.onError)==null||i.call(s,n.error):(u=s.onSuccess)==null||u.call(s,n),n})),De=({queryStore:r,serializedKey:t,options:n})=>s=>s.pipe(e.tap(({data:i})=>{if(i!=null&&i.result){const u=i==null?void 0:i.result;r.update(t,{...n.cacheTime!==0&&{cache_fnResult:{result:u}}})}})),Be=({options$:r,options:t,fn:n,queryStore:s,serializedKey:i,trigger:u,trigger$:a})=>{const f=r.pipe(e.map(({enabled:y=!0})=>y),e.distinctUntilChanged()).pipe(e.distinctUntilChanged(),e.filter(y=>!y)),d=e.defer(()=>{const y=typeof n=="function"?n():n;return e.from(y)}).pipe(ue(t),Je(i,s),e.tap(()=>{s.dispatchQueryEvent({key:i,type:"fetchSuccess"}),s.update(i,{lastFetchedAt:new Date().getTime()})}),e.map(y=>({status:"success",data:{result:y},error:void 0})),e.endWith({fetchStatus:"idle"}),e.catchError(y=>(s.dispatchQueryEvent({key:i,type:"fetchError"}),e.of({fetchStatus:"idle",status:"error",data:void 0,error:y}))),Ge(r),De({serializedKey:i,options:t,queryStore:s})),h=s.queryEvent$.pipe(e.filter(y=>y.key===i&&y.type==="queryDataSet"),e.map(()=>{var y,V;return(V=(y=s.get(i))==null?void 0:y.cache_fnResult)==null?void 0:V.result}),e.filter(Q),e.map(y=>({status:"success",data:{result:y}})),e.delay(1)),p=e.merge(f.pipe(e.take(1),e.map(()=>({fetchStatus:"idle"}))),e.merge(e.of({fetchStatus:"fetching",error:void 0}),d).pipe(e.takeUntil(f)),h).pipe(e.takeUntil(a)),c=s.get(i),o=c==null?void 0:c.cache_fnResult,m=!!o,w=u.type==="refetch"&&u.ignoreStale;return m?!(c!=null&&c.isStale)&&!w?e.of({fetchStatus:"idle",status:"success",data:{result:o.result},error:void 0}):e.merge(e.of({fetchStatus:"fetching",status:"success",data:{result:o.result},error:void 0}),p):p},F=I.namespace("invalidation"),He=({queryStore:r})=>({invalidateQueries:({queryKey:n,exact:s=!1,predicate:i}={})=>{let u=[];n?(F.log("invalidation requested for",n),r.updateMany({isStale:!0},a=>{const l=_(n,a.queryKey,{exact:s});return l&&u.push(O(a.queryKey)),l})):i?r.updateMany({isStale:!0},a=>{const l=i(a);return l&&u.push(O(a.queryKey)),l}):(F.log("Invalidation requested for all queries"),r.updateMany({isStale:!0}),u=Array.from(r.keys())),u.forEach(a=>{r.update(a,{deduplication_fn:void 0}),r.dispatchQueryTrigger({key:a,trigger:{ignoreStale:!0,type:"refetch"}})})}}),Xe=r=>({pipeQueryResult:({options$:s})=>i=>{const u=i.pipe(e.share());return e.merge(u,u.pipe(e.filter(a=>!!a.data&&a.fetchStatus!=="fetching"),e.distinctUntilChanged((a,l)=>a.data===l.data),e.withLatestFrom(s),e.map(([,{refetchInterval:a}])=>a),e.filter(Q),e.switchMap(a=>typeof a=="number"?e.timer(a).pipe(e.map(()=>({type:"refetch",ignoreStale:!0})),e.switchMap(()=>e.EMPTY)):e.EMPTY)))},refetchQueries:s=>{}}),Ze=(r,t)=>r.filter(n=>!t.includes(n)),qe=(r,t)=>r.store$.pipe(e.map(n=>[...n.keys()]),e.startWith([]),e.pairwise(),e.mergeMap(([n,s])=>{const i=Ze(s,n);return e.merge(...i.map(u=>{const a=r.store$.pipe(e.map(()=>r.get(u)),e.filter(l=>l===void 0));return e.merge(e.NEVER,e.of(u)).pipe(e.tap(()=>{}),t,e.finalize(()=>{}),e.takeUntil(a))}))})),ce=r=>r.pipe(e.switchMap(t=>e.combineLatest(t.runners)),e.map(t=>t.map(({options:n})=>n))),et=r=>r.pipe(e.map(t=>t.reduce((n,s)=>({...n,lowestStaleTime:s.staleTime===void 0?n.lowestStaleTime:Math.min(s.staleTime??1/0,n.lowestStaleTime??1/0)}),{lowestStaleTime:void 0})),e.distinctUntilChanged(C)),tt=r=>t=>t.pipe(e.filter(n=>n.key===r&&(n.type==="fetchError"||n.type==="fetchSuccess"))),rt=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>{const s=r.get$(n);return r.queryEvent$.pipe(tt(n),e.switchMap(()=>s.pipe(ce,et,e.tap(({lowestStaleTime:i=0})=>{var u;i===0?(F.log(n,"marked as stale!",{staleTime:i}),r.update(n,{isStale:!0})):(u=r.get(n))!=null&&u.isStale&&(F.log(n,"marked non stale",{staleTime:i}),r.update(n,{isStale:!1}))}),e.filter(({lowestStaleTime:i})=>i!==1/0&&i!==0),e.switchMap(({lowestStaleTime:i=0})=>e.timer(i)),e.tap(()=>{var i;(i=r.get(n))!=null&&i.isStale||(F.log(n,"marked as stale!"),r.update(n,{isStale:!0}))}))),e.map(()=>n))})),nt=r=>r.pipe(e.map(t=>t.reduce((n,s)=>({...n,lowestCacheTime:s.cacheTime===void 0?n.lowestCacheTime:Math.min(s.cacheTime??1/0,n.lowestCacheTime??1/0)}),{lowestCacheTime:void 0})),e.distinctUntilChanged(C)),st=r=>r.pipe(e.map(t=>t.cache_fnResult),e.distinctUntilChanged(C)),it=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>{const s=r.get$(n);return s.pipe(st,e.switchMap(()=>s.pipe(ce,nt,e.switchMap(({lowestCacheTime:u=5*60*1e3})=>e.timer(u).pipe(e.tap(()=>{r.update(n,{cache_fnResult:void 0})})))))).pipe(e.map(()=>n))})),ut=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>r.get$(n).pipe(e.filter(i=>!i.cache_fnResult),e.map(i=>i.runners.length>0),e.pairwise(),e.filter(([i,u])=>i&&!u),e.tap(()=>{r.delete(n)}),e.map(()=>n)))),oe=({key:r})=>({isStale:!0,queryKey:r,runners:[]}),at=({queryStore:r,serializedKey:t,runner$:n,options$:s,key:i})=>u=>u.pipe(e.withLatestFrom(s),e.map(([a,l])=>i.length===0?[a,void 0]:a.type!=="initial"?[a,void 0]:(r.get(t)?r.update(t,{queryKey:i,...l.markStale&&{isStale:!0}}):r.set(t,oe({key:i})),[a,r.addRunner(t,n)]))),ct=I.namespace("cache"),ot=({queryStore:r})=>({setQueryData:({queryKey:n,updater:s})=>{const i=O(n);n.length!==0&&(ct.log("set cache for query",O),r.get(i)||r.set(i,oe({key:n})),r.update(i,u=>{var a;return typeof s=="function"?{...u,cache_fnResult:{result:s((a=u.cache_fnResult)==null?void 0:a.result)}}:{...u,cache_fnResult:{result:s}}}),r.dispatchQueryEvent({key:i,type:"queryDataSet"}))}}),lt=I.namespace("refetch"),pt=({key:r,serializedKey:t,queryStore:n})=>s=>s.pipe(e.tap(i=>{if(i.type!=="refetch")return;const u=n.get(t);u&&i.ignoreStale&&!u.isStale&&(lt.log(r,"marked stale by trigger!"),n.update(t,{isStale:!0}))})),ft=({queryStore:r,serializedKey:t})=>n=>n.pipe(e.tap(s=>{s.type==="refetch"&&(r.update(t,{deduplication_fn:void 0}),r.dispatchQueryTrigger({key:t,trigger:s}))}),e.filter(s=>s.type!=="refetch")),E=r=>e.defer(()=>{const t=r();return t instanceof Promise?e.from(t):t instanceof e.Observable?t:e.of(t)}),dt=({variables:r,state:t,options:n})=>{const s=t.isPaused,i=async()=>await Promise.reject(new Error("No mutationFn found")),u=n.mutationFn??i,l=e.iif(()=>s,e.of(t.context),E(()=>{var p;return((p=n.onMutate)==null?void 0:p.call(n,r))??void 0})).pipe(e.share()),f=(p,c,o)=>(console.error(p),E(()=>{var w;return(w=n.onError)==null?void 0:w.call(n,p,r,c)}).pipe(e.catchError(()=>e.of(p)),e.map(()=>({failureCount:o,error:p,failureReason:p,context:c,status:"error"})))),g=l.pipe(e.switchMap(p=>(typeof u=="function"?E(()=>u(r)):u).pipe(e.map(o=>({result:{data:o},error:null,context:p})),ue({...n,caughtError:(o,m)=>e.of({failureCount:o,failureReason:m}),catchError:(o,m)=>f(m,p,o).pipe(e.map(w=>({...w,result:void 0})))}),e.takeWhile(({result:o,error:m})=>(o==null?void 0:o.data)===void 0&&m===void 0,!0)))),d=e.of({...t,variables:r,status:"pending",isPaused:!1,failureCount:0,failureReason:null,submittedAt:t.submittedAt??new Date().getTime()});return e.merge(d,l.pipe(e.map(p=>({context:p}))),g.pipe(e.switchMap(({result:p,error:c,...o})=>{if(!p&&!c)return e.of({...o});const m=c?e.of(null):E(()=>{var v;return(v=n.onSuccess)==null?void 0:v.call(n,p==null?void 0:p.data,r,o.context)}),y=E(()=>{var v;return(v=n.onSettled)==null?void 0:v.call(n,p==null?void 0:p.data,c,r,o.context)}).pipe(e.catchError(v=>p?e.of(p):e.of(v)));return e.concat(m,y).pipe(e.toArray(),e.map(()=>c?{error:c,data:void 0,variables:r,...o}:{status:"success",error:c,data:p==null?void 0:p.data,variables:r,...o}),e.catchError(v=>f(v,o.context,0).pipe(e.map($=>({...$,data:void 0})))))}))).pipe(e.scan((p,c)=>({...p,...c,data:c.data??p.data,error:c.error??p.error}),U()),e.distinctUntilChanged(({data:p,...c},{data:o,...m})=>C(c,m)&&C(p,o)))};class ht{constructor({options:t,mutationCache:n,state:s}){S(this,"mutationCache");S(this,"observerCount",new e.BehaviorSubject(0));S(this,"destroySubject",new e.Subject);S(this,"resetSubject",new e.Subject);S(this,"executeSubject",new e.Subject);S(this,"state",U());S(this,"state$");S(this,"options");S(this,"observerCount$",this.observerCount.asObservable());S(this,"destroyed$",this.destroySubject.asObservable());this.options=t,this.mutationCache=n,this.state=s??this.state;const i=e.of(this.state),u=this.resetSubject.pipe(e.map(()=>U())),a=this.executeSubject.pipe(e.switchMap(l=>dt({options:{...this.options,onMutate:f=>{const g=E(()=>{var h,p;return(p=(h=n.config).onMutate)==null?void 0:p.call(h,f,this)}),d=E(()=>{var h,p;return((p=(h=this.options).onMutate)==null?void 0:p.call(h,f))??void 0});return g.pipe(e.mergeMap(()=>d))},onError:(f,g,d)=>{const h=E(()=>{var c,o;return(o=(c=n.config).onError)==null?void 0:o.call(c,f,g,d,this)}),p=E(()=>{var c,o;return(o=(c=this.options).onError)==null?void 0:o.call(c,f,g,d)});return e.concat(h,p).pipe(e.toArray())},onSettled:(f,g,d,h)=>{const p=E(()=>{var o,m;return(m=(o=n.config).onSettled)==null?void 0:m.call(o,f,g,d,h,this)}),c=E(()=>{var o,m;return(m=(o=this.options).onSettled)==null?void 0:m.call(o,f,g,d,h)});return e.concat(p,c).pipe(e.toArray())},onSuccess:(f,g,d)=>{const h=E(()=>{var c,o;return(o=(c=n.config).onSuccess)==null?void 0:o.call(c,f,g,d,this)}),p=E(()=>{var c,o;return(o=(c=this.options).onSuccess)==null?void 0:o.call(c,f,g,d)});return e.concat(h,p).pipe(e.toArray())}},state:this.state,variables:l})),e.tap(l=>{this.state={...this.state,...l}}),e.takeUntil(this.destroySubject));this.state$=e.merge(i,a,u).pipe(e.shareReplay({bufferSize:1,refCount:!1}),e.takeUntil(this.destroySubject),se(l=>{this.observerCount.next(l)}))}get meta(){return this.options.meta}setOptions(t){this.options={...this.options,...t}}observeTillFinished(){return this.state$.pipe(e.takeWhile(t=>t.status!=="error"&&t.status!=="success",!0))}execute(t){return this.executeSubject.next(t),this.executeSubject.complete(),this.observeTillFinished()}continue(){return this.execute(this.state.variables)}destroy(){this.destroySubject.next(),this.destroySubject.complete(),this.executeSubject.complete()}reset(){this.resetSubject.next(),this.resetSubject.complete(),this.destroy()}}const W=({mutationKey:r,status:t,predicate:n,exact:s=!0}={})=>u=>s&&r!==void 0&&u.options.mutationKey!==void 0&&!_(u.options.mutationKey,r,{exact:s})||!s&&r!==void 0&&u.options.mutationKey!==void 0&&!_(r,u.options.mutationKey,{exact:s})||t&&u.state.status!==t?!1:n?n(u):!0;class le{constructor(t={}){S(this,"mutationsSubject",new e.BehaviorSubject([]));S(this,"mutations$",this.mutationsSubject.pipe(e.map(t=>t.map(n=>n)),e.distinctUntilChanged(ie),e.share()));S(this,"added$",this.mutations$.pipe(e.pairwise(),e.map(([t,n])=>n.filter(s=>!t.includes(s))[0]),e.filter(Q),e.share()));S(this,"removed$",this.mutations$.pipe(e.pairwise(),e.map(([t,n])=>t.filter(s=>!n.includes(s))),e.mergeMap(t=>e.from(t)),e.share()));S(this,"stateChange$",this.added$.pipe(e.mergeMap(t=>t.state$.pipe(e.map(()=>t),e.takeUntil(this.removed$.pipe(e.filter(n=>n===t))))),e.share()));this.config=t}build(t,n,s){const i=new ht({mutationCache:this,options:t.defaultMutationOptions(n),state:s});return i.state$.pipe(e.filter(({status:u})=>u==="success"||u==="error"),e.switchMap(()=>i.observerCount$.pipe(e.filter(u=>u<=1),e.take(1))),e.switchMap(()=>e.timer(i.options.gcTime??5*60*1e3)),e.take(1)).subscribe({complete:()=>{this.mutationsSubject.next(this.mutationsSubject.getValue().filter(u=>i!==u))}}),this.mutationsSubject.next([...this.mutationsSubject.getValue(),i]),i}getAll(){return this.findAll()}remove(t){const n=this.mutationsSubject.getValue().find(s=>s===t);n==null||n.destroy()}find(t){const n={exact:!0,...t},s=W(n);return this.mutationsSubject.getValue().find(i=>s(i))}findAll(t={}){const n={exact:!0,...t},s=W(n);return this.mutationsSubject.getValue().filter(i=>s(i)).map(i=>i)}observe({filters:t,select:n}={}){const s=W(t),i=n??(l=>l.state),u=this.getAll().reduce((l,f)=>[...l,f],[]).filter(s).map(l=>i(l));return{value$:this.stateChange$.pipe(e.startWith(),e.map(()=>this.getAll().filter(s).map(i)),e.distinctUntilChanged(C)),lastValue:u}}subscribe(t){const n=e.merge(this.added$.pipe(e.tap(s=>{t({type:"added",mutation:s})})),this.removed$.pipe(e.tap(s=>{t({type:"removed",mutation:s})})),this.stateChange$.pipe(e.tap(s=>{t({type:"updated",action:{...s.state,type:"success"},mutation:s})}))).subscribe();return()=>{n.unsubscribe()}}resumePausedMutations(){const t=this.findAll({predicate:s=>s.state.isPaused});if(!t.length)return e.EMPTY;const n=t.map(s=>s.continue());return e.combineLatest(n)}clear(){this.getAll().forEach(t=>{this.remove(t)})}}const pe=()=>{const r=ze(),t=He({queryStore:r}),n=ot({queryStore:r}),s=Xe();let i=!1;const u=({key:g,fn$:d,fn:h,trigger$:p=new e.Subject,options$:c=new e.BehaviorSubject({})})=>{if(!i)throw new Error("You forgot to start client");const o=O(g),m=d??(h?e.of(h):e.NEVER);I.log("query$)",o);const w=c.pipe(e.map($=>({options:$})));let y=()=>{};const V=e.merge(p.pipe(ft({queryStore:r,serializedKey:o})),We({options$:c,key:o,queryStore:r})).pipe(e.share());return{result$:e.merge(e.of({type:"initial"}),V).pipe(at({key:g,queryStore:r,runner$:w,serializedKey:o,options$:c}),e.map(([$,M])=>(M&&(y=M),$)),pt({key:g,options$:c,queryStore:r,serializedKey:o}),e.withLatestFrom(m,c),e.map(([$,M,k])=>({trigger:$,fn:M,options:k})),e.map($=>(I.log(o,"query trigger",{trigger:$.trigger,options:$.options}),$)),e.filter(({options:$})=>$.enabled!==!1),e.mergeMap(({fn:$,options:M,trigger:k})=>Be({options$:c,options:M,fn:$,queryStore:r,serializedKey:o,trigger:k,trigger$:V})),Ne,e.withLatestFrom(c),e.takeWhile(([$,M])=>!($.data!==void 0&&M.terminateOnFirstResult),!0),e.map(([$])=>$),e.finalize(()=>{y()}))}},a=qe(r,g=>g.pipe(e.switchMap(d=>{const h=e.of(d);return e.merge(it({queryStore:r})(h),rt({queryStore:r})(h),ut({queryStore:r})(h))})));return{start:()=>{i=!0;const g=a.subscribe(),d=[r.start()];return()=>{d.forEach(h=>{h()}),g.unsubscribe()}},query:u,queryStore:r,...t,...n,...s,destroy:()=>{}}};var N;class gt{constructor({mutationCache:t}={mutationCache:new le}){S(this,"client");S(this,"mutationCache");z(this,N,new Map);this.mutationCache=t,this.client=pe()}mount(){const t=this.client.start();return()=>{t()}}getMutationCache(){return this.mutationCache}defaultMutationOptions(t){return{...(t==null?void 0:t.mutationKey)&&this.getMutationDefaults(t.mutationKey),...t}}getMutationDefaults(t){const n=[...T(this,N).values()];let s={};return n.forEach(i=>{_(t,i.mutationKey)&&(s={...s,...i.defaultOptions})}),s}setMutationDefaults(t,n){T(this,N).set(O(t),{mutationKey:t,defaultOptions:n})}async resumePausedMutations(){return await e.lastValueFrom(this.mutationCache.resumePausedMutations())}clear(){}}N=new WeakMap;exports.MutationCache=le;exports.QueryClient=gt;exports.QueryClientProvider=xe;exports.SIGNAL_RESET=Z;exports.createClient=pe;exports.createLocalforageAdapter=$e;exports.createSharedStoreAdapter=ve;exports.exponentialBackoffDelay=ee;exports.getDelay=q;exports.retryBackoff=te;exports.signal=ye;exports.trigger=be;exports.useBehaviorSubject=X;exports.useLiveRef=R;exports.useMutation=Ie;exports.useObserve=A;exports.useObserveCallback=me;exports.usePersistSignals=Re;exports.useQuery=Le;exports.useQueryClient=G;exports.useSignalValue=Se;exports.useSubject=K;exports.useSubscribe=Y;exports.useSubscribeEffect=_e;exports.useUnmountObservable=Oe;
1
+ "use strict";var at=Object.defineProperty;var ut=(s,e,t)=>e in s?at(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var g=(s,e,t)=>(ut(s,typeof e!="symbol"?e+"":e,t),t),Qe=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var c=(s,e,t)=>(Qe(s,e,"read from private field"),t?t.call(s):e.get(s)),w=(s,e,t)=>{if(e.has(s))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(s):e.set(s,t)},M=(s,e,t,n)=>(Qe(s,e,"write to private field"),n?n.call(s,t):e.set(s,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react"),r=require("rxjs"),T=require("rxjs/operators"),Pe=require("react/jsx-runtime");function ct(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const ve=ct(S),A=s=>{const e=S.useRef(s);return S.useMemo(()=>{e.current=s},[s]),e};function ot(s,e){return typeof s=="string"&&s===e||typeof s=="number"&&s===e||typeof s=="boolean"&&s===e||typeof s=="symbol"&&s===e||typeof s=="bigint"&&s===e||typeof s>"u"&&s===e||s===null&&s===e}function he(s,e,t){const n=e!=null&&!Array.isArray(e)?e:{defaultValue:void 0,key:"",unsubscribeOnUnmount:!0},i=t==null&&Array.isArray(e)?e:typeof s=="function"?t??[]:[s],u=S.useRef("getValue"in s&&typeof s.getValue=="function"?s.getValue():n.defaultValue),a=A(s),l=A(n),p=S.useCallback(d=>{const o=a.current,$=(typeof o=="function"?o:()=>o)().pipe(r.distinctUntilChanged(ot),r.tap(b=>{u.current=b}),r.finalize(d),r.catchError(b=>(console.error(b),u.current=void 0,r.EMPTY))).subscribe(d);return()=>{l.current.unsubscribeOnUnmount!==!1&&$.unsubscribe()}},[...i]),f=S.useCallback(()=>u.current,[]);return S.useSyncExternalStore(p,f,f)}function ke(s){return s instanceof Promise||s&&typeof s.then=="function"&&typeof s.catch=="function"}function R(s){if(r.isObservable(s))return s;if(ke(s))return r.from(s);if(typeof s!="function")return r.of(s);const e=s;return r.defer(()=>{const t=e();return ke(t)?r.from(t):r.isObservable(t)?t:r.of(t)})}function Ce(s,e=[]){const t=A(s);S.useEffect(()=>{const n=R(t.current).subscribe();return()=>{n.unsubscribe()}},[...e,t])}const Oe=s=>{const e=S.useRef();return e.current||(e.current=s()),S.useEffect(()=>{process.env.NODE_ENV},[]),e},Ee=({onBeforeComplete:s,completeOnUnmount:e=!0}={})=>{const t=Oe(()=>new r.Subject),n=S.useRef(!1),i=A(s),u=A(e);return S.useEffect(()=>(n.current&&(t.current=new r.Subject,n.current=!1),()=>{if(!u.current){n.current=!0;return}n.current||(i.current!=null&&i.current(),t.current.complete(),n.current=!0)}),[u,i,t]),t},lt=()=>{const s=Ee(),e=A(s.current.asObservable()),t=S.useCallback(n=>{s.current.next(n)},[]);return[e,t]},Le=s=>{const e=Oe(()=>new r.BehaviorSubject(s)),t=S.useRef(!1),n=S.useRef(s);return S.useEffect(()=>(t.current&&(e.current=new r.BehaviorSubject(n.current),t.current=!1),()=>{t.current||(e.current.complete(),t.current=!0)}),[e]),e},ht=s=>{const e=Le(s),t=A(e.current.asObservable()),n=S.useCallback(i=>{e.current.next(i)},[e.current]);return[t.current,n,e.current.getValue()]},_e=Symbol("SIGNAL_RESET");function ft(s){const{default:e}=s??{},t=new r.BehaviorSubject(e);return{setValue:u=>{if(typeof u=="function"){const a=u(t.getValue());if(a===t.getValue())return;t.next(a);return}if(u===_e){t.next(e??void 0);return}t.next(u)},getValue:()=>t.getValue(),config:s,subject:t}}function dt(s,e){const t=e??(n=>n);return he(()=>s.subject.pipe(r.map(n=>t(n)),r.distinctUntilChanged()),{defaultValue:t(s.getValue())},[])}const Ve=s=>{if(!(!s||typeof s!="object"))return s},pt=({adapter:s,key:e})=>({getItem:async t=>{const n=await s.getItem(e),i=Ve(n)??{};if(t in i)return i[t]},setItem:async(t,n)=>{const i=await s.getItem(e),u=Ve(i)??{};await s.setItem(e,{...u,[t]:n})}}),bt=s=>({getItem:async e=>{const t=await s.getItem(e);if(t)return JSON.parse(t)},setItem:async(e,t)=>{await s.setItem(e,JSON.stringify(t))}}),gt=s=>({getItem:async e=>{const t=s.getItem(e);if(t)return JSON.parse(t)},setItem:async(e,t)=>{s.setItem(e,JSON.stringify(t))}}),te="__reactjrx",yt=s=>{if(typeof s=="object"&&s!==null&&te in s&&s[te]===te)return s},mt=async({adapter:s,signal:e,version:t})=>{const i={value:e.getValue(),[te]:te,migrationVersion:t};await s.setItem(e.config.key,i)},St=({adapter:s,version:e,signal:t})=>r.from(s.getItem(t.config.key)).pipe(r.switchMap(n=>{const i=yt(n);return!i||i.migrationVersion!==void 0&&e>i.migrationVersion||t.setValue(n.value),r.of(n)})),vt=({entries:s=[],onReady:e,adapter:t=gt(localStorage)})=>{const n=A(s),i=A(e),u=A(t),a=he(()=>{const l=n.current;return(l.length===0?r.of(!0):r.zip(...l.map(({signal:f,version:h})=>St({adapter:u.current,signal:f,version:h}))).pipe(r.map(()=>!0))).pipe(r.tap(()=>{i.current!=null&&i.current()}),r.catchError(f=>(console.error("Unable to hydrate",f),r.EMPTY)))},{defaultValue:!1},[]);return Ce(()=>a?r.merge(...n.current.map(({signal:l,version:p})=>l.subject.pipe(r.throttleTime(500,r.asyncScheduler,{trailing:!0}),r.switchMap(()=>r.from(mt({adapter:u.current,signal:l,version:p})))))):r.EMPTY,[a,u]),{isHydrated:a}},Ot=()=>{const s=Ee({onBeforeComplete:()=>{s.current.next()}});return s};function ze(s,e){return Math.min(s,e)}function Be(s,e){return Math.pow(2,s)*e}function Me(s){const{retry:e,retryDelay:t,retryAfterDelay:n,retryAfter:i=()=>r.of(!0)}=s,u=typeof e!="function"?e===!1?0:e===!0?1/0:e??1/0:1/0,a=typeof e=="function"?e:()=>!0,l=typeof t=="number"?t:100,p={shouldRetry:a,...s},{maxInterval:f=1/0,resetOnSuccess:h=!1,backoffDelay:d=Be}=p;return o=>r.defer(()=>{let y=0;const $=(b,v)=>b<u?a(b,v):!1;return o.pipe(T.catchError(b=>{var O;if(y++,!$(y-1,b))throw b;const v=(O=s.caughtError)==null?void 0:O.call(s,y,b);if(!v)throw b;return v.pipe(T.mergeMap(V=>r.merge(r.of(V),r.throwError(()=>b))))}),T.retryWhen(b=>b.pipe(T.concatMap(v=>{const O=y-1;return i().pipe(T.first(),T.mergeMap(()=>$(O,v)?r.timer(ze(d(O,l),f)).pipe(T.mergeMap(V=>n&&!n(O,v)?r.throwError(()=>v):r.of(V))):r.throwError(()=>v)))}))),T.catchError(b=>{if(s.catchError)return s.catchError(y,b);throw b}),T.tap(()=>{h&&(y=0)}))})}function Ie(s){return Object.prototype.toString.call(s)==="[object Object]"}function $e(s){if(!Ie(s))return!1;const e=s.constructor;if(typeof e>"u")return!0;const t=e.prototype;return!(!Ie(t)||!t.hasOwnProperty("isPrototypeOf"))}const ee=s=>JSON.stringify(s,(e,t)=>$e(t)?Object.keys(t).sort().reduce((n,i)=>(n[i]=t[i],n),{}):t),je=(s=21)=>crypto.getRandomValues(new Uint8Array(s)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+="-":e+="_",e),""),z=()=>({context:void 0,data:void 0,error:null,status:"idle",submittedAt:0,variables:void 0,failureCount:0,failureReason:null,isPaused:!1});function x(s,e){if(s==null||e===void 0||typeof s!="object"||typeof e!="object")return s===e;if(s.constructor!==(e==null?void 0:e.constructor))return!1;const t=Object.keys(s),n=Object.keys(e);if(t.length!==n.length)return!1;for(const i of t)if(!e.hasOwnProperty(i)||s[i]!==e[i])return!1;return!0}function Re(s){let e=0;return function(n){return new r.Observable(i=>{e++;const u=n.subscribe(i);return s(e),()=>{e--,u.unsubscribe(),s(e)}})}}const re=s=>s.pipe(r.takeWhile(e=>e.status!=="error"&&e.status!=="success",!0));var H;class wt{constructor({__queryFinalizeHook:e}={}){w(this,H,new r.Subject);g(this,"state$");const t=new r.BehaviorSubject(0),n=t.pipe(r.filter(i=>i===0));this.state$=c(this,H).pipe(r.concatMap(({args:i,mutation:u,options:a})=>{const l=a.mapOperator??"merge",p=c(this,H).pipe(r.filter(()=>l==="merge")),f=c(this,H).pipe(r.filter(()=>l==="switch"),r.tap(()=>{u.cancel()})),h=r.defer(()=>(u.execute(i),r.EMPTY)),d=u.state$.pipe(re,r.last(),r.mergeMap(()=>u.state$),r.takeUntil(c(this,H))),o=u.state$.pipe(re,r.skip(1)),y=r.merge(n,p,f,u.cancelled$);return r.merge(o,d,h).pipe(e??r.identity,r.takeUntil(y))}),r.scan((i,u)=>({...i,...u,...u.status==="pending"&&{data:u.data??i.data},...u.status==="pending"&&{error:u.error??i.error}}),z()),r.distinctUntilChanged(({data:i,...u},{data:a,...l})=>x(u,l)&&x(i,a)),r.shareReplay({refCount:!0,bufferSize:1}),Re(i=>{t.next(i)}))}trigger({args:e,options:t,mutation:n}){c(this,H).next({args:e,options:t,mutation:n})}}H=new WeakMap;function De(s){return s!=null}function we(s,e){return s===e?!0:typeof s!=typeof e?!1:s&&e&&typeof s=="object"&&typeof e=="object"?!Object.keys(e).some(t=>!we(s[t],e[t])):!1}const ge=(s,e,{exact:t=!1}={})=>t?ee(s)===ee(e):we(s,e);var B,D;class $t{constructor(e,t={},n){w(this,B,void 0);w(this,D,new r.BehaviorSubject(void 0));g(this,"observed$");g(this,"getObserverResultFromState",e=>({...z(),...e,isSuccess:e.status==="success",isPending:e.status==="pending",isIdle:e.status==="idle",isError:e.status==="error",mutate:this.mutate,reset:this.reset}));var i;this.client=e,this.options=t,this.options.mutationKey=((i=this.options)==null?void 0:i.mutationKey)??[je()],M(this,B,n??new wt(this.options)),this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this),c(this,D).pipe(r.filter(De),r.mergeMap(u=>c(this,B).state$.pipe(r.takeUntil(u.mutation.state$.pipe(re,r.last()))))).subscribe(),this.observed$=c(this,D).pipe(r.switchMap(u=>(u==null?void 0:u.mutation.state$.pipe(r.map(a=>({state:a,options:u.options}))))??r.EMPTY),r.tap(({state:u,options:a})=>{u.status==="error"&&(a!=null&&a.onError&&(a==null||a.onError(u.error,u.variables,u.context)),a!=null&&a.onSettled&&(a==null||a.onSettled(u.data,u.error,u.variables,u.context))),u.status==="success"&&(a!=null&&a.onSuccess&&(a==null||a.onSuccess(u.data,u.variables,u.context)),a!=null&&a.onSettled&&(a==null||a.onSettled(u.data,u.error,u.variables,u.context)))}),r.ignoreElements())}setOptions(e){var i;const t=this.options;this.options=this.client.defaultMutationOptions({mutationKey:this.options.mutationKey,...e});const n=(i=c(this,D).getValue())==null?void 0:i.mutation;this.options.mutationKey&&t.mutationKey&&!ge(this.options.mutationKey,t.mutationKey,{exact:!0})?this.reset():n==null||n.setOptions(this.options)}observe(){var u;const e=this.getObserverResultFromState(((u=c(this,D).getValue())==null?void 0:u.mutation.state)??z()),t=c(this,B).state$.pipe(r.map(a=>this.getObserverResultFromState(a))),n=c(this,D).pipe(r.filter(De),r.switchMap(a=>a.mutation.cancelled$),r.map(()=>this.getObserverResultFromState(z())));return{result$:r.merge(this.observed$,t,n),lastValue:e}}subscribe(e){const t=this.observe().result$.subscribe(n=>{e(n)});return()=>{t.unsubscribe()}}async mutate(e,t={}){const n=this.client.getMutationCache().build(this.client,this.options);return c(this,D).next({mutation:n,options:t}),c(this,B).trigger({args:e,options:this.options,mutation:n}),await new Promise((i,u)=>{n.state$.pipe(re,r.last()).subscribe({error:a=>{u(a)},next:a=>{a.error?u(a.error):i(a.data)}})})}getCurrentResult(){var t;const e=this.client.getMutationCache().find({exact:!0,mutationKey:(t=this.options)==null?void 0:t.mutationKey});return this.getObserverResultFromState((e==null?void 0:e.state)??z())}reset(){const{mutation:e}=c(this,D).getValue()??{};c(this,D).next(void 0),e==null||e.cancel()}}B=new WeakMap,D=new WeakMap;const Ye=S.createContext(void 0),Ct=({client:s})=>(S.useEffect(()=>(s.mount(),()=>{s.unmount()}),[s]),null),Et=S.memo(({children:s,client:e})=>{const t=S.useMemo(()=>e,[e]);return Pe.jsxs(Ye.Provider,{value:t,children:[Pe.jsx(Ct,{client:e}),s]})}),Ge=s=>{const e=S.useContext(Ye);if(s)return s;if(!e)throw new Error("No QueryClient set, use QueryClientProvider to set one");return e};function Mt(){}function jt(s,e){const t=Ge(e),n=A(s),i=Oe(()=>[je()]),u=ee(s.mutationKey??i.current),[a]=S.useState(()=>new $t(t,s));S.useEffect(()=>{a.setOptions(s)},[a,s]);const l=S.useMemo(()=>a.observe(),[u,a]),p=he(l.result$)??l.lastValue,f=S.useCallback((h,d)=>{a.mutate(h,d).catch(Mt)},[a]);return S.useEffect(()=>()=>{n.current.cancelOnUnMount&&a.reset()},[a,n]),{...p,mutate:f,mutateAsync:p.mutate}}function Rt(s){return e=>e.pipe(T.tap(t=>{s.next(t)}))}class Ft{constructor(){g(this,"isOnlineSubject",new r.BehaviorSubject(!0));g(this,"online$",this.isOnlineSubject.pipe(r.distinctUntilChanged()));g(this,"backToOnline$",this.online$.pipe(r.filter(e=>e),r.first()));r.merge(r.fromEvent(window,"offline").pipe(r.map(()=>!1)),r.fromEvent(window,"online").pipe(r.map(()=>!0))).pipe(Rt(this.isOnlineSubject)).subscribe()}isOnline(){return this.isOnlineSubject.getValue()}setOnline(e){this.isOnlineSubject.getValue()!==e&&this.isOnlineSubject.next(e)}}const _=new Ft;function Fe(s,e){return s.isStaleByTime(e.staleTime)}function Ut(s,e){return e.enabled!==!1&&!s.state.dataUpdatedAt&&!(s.state.status==="error"&&e.retryOnMount===!1)}function Te(s,e){return Ut(s,e)||s.state.dataUpdatedAt>0&&Je(s,e,e.refetchOnMount)}function Ke(s,e,t,n){return s.state.fetchStatus!=="fetching"&&t.enabled!==!1&&(s!==e||n.enabled===!1)&&(!t.suspense||s.state.status!=="error")&&Fe(s,t)}function xt(s,e){return Je(s,e,e.refetchOnWindowFocus)}function Je(s,e,t){if(e.enabled!==!1){const n=typeof t=="function"?t(s):t;return n==="always"||n!==!1&&Fe(s,e)}return!1}function At(s){return(s??"online")==="online"?_.isOnline():!0}function Ne(s,e){return e.reduce((t,n)=>n in s?{...t,[n]:s[n]}:t,{})}function qe(s){return Array.isArray(s)&&s.length===Object.keys(s).length}function Xe(s,e){if(s===e)return s;const t=qe(s)&&qe(e);if(t||$e(s)&&$e(e)){const n=t?s:Object.keys(s),i=n.length,u=t?e:Object.keys(e),a=u.length,l=t?[]:{};let p=0;for(let f=0;f<a;f++){const h=t?f:u[f];!t&&s[h]===void 0&&e[h]===void 0&&n.includes(h)?(l[h]=void 0,p++):(l[h]=Xe(s[h],e[h]),l[h]===s[h]&&s[h]!==void 0&&p++)}return i===a&&p===i?s:l}return e}function Ue(s,e){return((e==null?void 0:e.queryKeyHashFn)??ee)(s)}function He(s,e){const{type:t="all",exact:n,fetchStatus:i,predicate:u,queryKey:a,stale:l}=s;if(a){if(n){if(e.queryHash!==Ue(a,e.options))return!1}else if(!we(e.queryKey,a))return!1}if(t!=="all"){const p=e.isActive();if(t==="active"&&!p||t==="inactive"&&p)return!1}return!(typeof l=="boolean"&&e.isStale()!==l||typeof i<"u"&&i!==e.state.fetchStatus||u&&!u(e))}function Qt(s,e){return Math.max(s+(e??0)-Date.now(),0)}function Pt(s,e){return typeof s=="function"?s(e):s}function ye(s,e,t){return typeof t.structuralSharing=="function"?t.structuralSharing(s,e):t.structuralSharing!==!1?Xe(s,e):e}const kt=({getOptions:s,getState:e,initialState:t})=>n=>n.pipe(r.scan((i,{command:u,state:a})=>{if(u==="reset")return{...i,...a};if(u==="cancel"){const E=i.status==="pending"?"pending":a.status??i.status;return{...i,...a,status:E}}const l=a.data,p=l!==void 0&&l!==i.data,f="data"in a,h=a.status==="success",d=i.data!==void 0,o=i.error!==void 0||i.error!==null,y=a.status??i.status,$=p?ye(e().data,l,s()):f?a.data:i.data,b=i.status==="error"||i.status==="success",v=a.status==="error"&&(i.status==="error"&&i.fetchStatus==="fetching"||i.status!=="error")?i.errorUpdateCount+1:i.errorUpdateCount,O=p?i.dataUpdateCount+1:a.dataUpdateCount??i.dataUpdateCount,V=a.status==="pending"&&b&&(d||o),F=y==="pending"?null:a.error??i.error;return{...i,...a,status:y,error:F,errorUpdateCount:v,...h&&{isInvalidated:!1},data:$,dataUpdateCount:O,...V&&{status:i.status}}},t)),Vt=s=>s.pipe(r.map(({status:e,fetchStatus:t})=>t==="idle"&&(e==="success"||e==="error"))),Ze=s=>s.pipe(r.takeWhile(e=>e.fetchStatus!=="idle",!0));var Se,W;class It{constructor(){w(this,Se,r.merge(r.fromEvent(document,"visibilitychange"),r.fromEvent(window,"visibilitychange")).pipe(r.map(()=>document.visibilityState)));w(this,W,new r.BehaviorSubject(document.visibilityState==="visible"));g(this,"focused$",c(this,W));g(this,"focusRegained$",this.focused$.pipe(r.skip(1),r.filter(e=>e)));c(this,Se).pipe(r.tap(e=>{c(this,W).next(e==="visible")})).subscribe()}isFocused(){return c(this,W).getValue()}setFocused(e){c(this,W).getValue()!==(e??!0)&&c(this,W).next(e??!0)}subscribe(e){const t=this.focused$.subscribe(e);return()=>{t.unsubscribe()}}refresh(){document.dispatchEvent(new Event("visibilitychange"))}}Se=new WeakMap,W=new WeakMap;const me=new It;var N,C,se,Y,U,X,ne;class Dt{constructor(e,t){w(this,N,void 0);w(this,C,void 0);w(this,se,new r.Subject);g(this,"queryUpdateSubject",new r.Subject);w(this,Y,void 0);w(this,U,void 0);w(this,X,void 0);w(this,ne,0);g(this,"getObserverResultFromQuery",({options:e,query:t,optimisticResult:n,prevResult:{result:i,options:u,state:a,select:l,selectError:p,selectResult:f}})=>{var be;const h=t.state,d=t.state.status==="pending",o=c(this,C),y=this.options,b=t!==o?t.state:c(this,Y);let{errorUpdatedAt:v,fetchStatus:O,error:V}=h;if(n){const P=!!c(this,ne),Ae=!P&&Te(t,e),it=P&&Ke(t,o,e,y);(Ae||it)&&(O=At(t.options.networkMode)?"fetching":"paused")}const F=d&&O==="fetching";let E,m=p,q=l??null,Q=f;if(e.select&&typeof h.data<"u")if(i&&h.data===(a==null?void 0:a.data)&&e.select===l)E=f;else try{q=e.select,E=e.select(h.data),E=ye(i==null?void 0:i.data,E,e),Q=E,m=null}catch(P){E=f,m=P}else E=h.data,m=null;let I=O!=="idle"&&!h.dataUpdatedAt?"pending":h.status;m&&(V=m,E=f,v=(i==null?void 0:i.errorUpdatedAt)??v,I="error");const fe=I==="error";let de=!1;if(typeof e.placeholderData<"u"&&typeof E>"u"&&I==="pending"){let P;if(i!=null&&i.isPlaceholderData&&e.placeholderData===(u==null?void 0:u.placeholderData))P=i.data;else if(P=typeof e.placeholderData=="function"?e.placeholderData((be=c(this,X))==null?void 0:be.state.data,c(this,X)):e.placeholderData,e.select&&typeof P<"u")try{P=e.select(P)}catch{}typeof P<"u"&&(I="success",E=ye(i==null?void 0:i.data,P,e),de=!0)}const pe=O==="fetching";return{result:{status:I,fetchStatus:O,isPending:d,isSuccess:I==="success",isError:fe,isInitialLoading:F,isLoading:F,data:E,dataUpdatedAt:h.dataUpdatedAt,error:V,errorUpdatedAt:v,failureCount:h.fetchFailureCount,failureReason:h.fetchFailureReason,errorUpdateCount:h.errorUpdateCount,isFetched:h.dataUpdateCount>0||h.errorUpdateCount>0,isFetchedAfterMount:h.dataUpdateCount>b.dataUpdateCount||h.errorUpdateCount>b.errorUpdateCount,isFetching:pe,isRefetching:pe&&!d,isLoadingError:fe&&h.dataUpdatedAt===0,isPaused:O==="paused",isPlaceholderData:de,isRefetchError:fe&&h.dataUpdatedAt!==0,isStale:Fe(t,e),refetch:this.refetch},selectError:m,select:q,selectResult:Q}});this.options=t,M(this,N,e),this.bindMethods(),M(this,C,this.setOptions(t));const n=c(this,C);M(this,Y,n.state);const{result:i,select:u}=this.getObserverResultFromQuery({query:n,options:this.options,prevResult:{options:this.options,state:n.state}});M(this,U,{state:n.state,options:t,result:i,select:u})}bindMethods(){this.refetch=this.refetch.bind(this)}setOptions(e){const t=this.options;if(this.options=c(this,N).defaultQueryOptions(e),x(this.options,t)||c(this,N).getQueryCache().notify({type:"observerOptionsUpdated",query:c(this,C),observer:this}),typeof this.options.enabled<"u"&&typeof this.options.enabled!="boolean")throw new Error("Expected enabled to be a boolean");const n=this.buildQuery(this.options);return n!==c(this,C)&&(M(this,Y,n.state),M(this,C,n)),this.queryUpdateSubject.next({options:this.options,query:n}),n}buildQuery(e){const t=c(this,N).getQueryCache().build(c(this,N),e);return!t.options.queryFn&&this.options.queryFn&&t.setOptions(e),t}getCurrentResult(){return this.getObserverResultFromQuery({options:this.options,prevResult:c(this,U),query:c(this,C)}).result}getCurrentQuery(){return c(this,C)}getOptimisticResult(e){const t=this.buildQuery(e),n=this.getObserverResultFromQuery({query:t,options:e,optimisticResult:!0,prevResult:c(this,U)});return Tt(this,n.result)&&this.updateResult({query:t,...n}),n.result}updateResult({query:e,result:t,selectError:n,select:i,selectResult:u}){c(this,U).state=e.state,c(this,U).result=t,c(this,U).selectResult=u,n!==void 0&&(c(this,U).selectError=n),i!==void 0&&(c(this,U).select=i),c(this,U).options=this.options,e.state.data!==void 0&&M(this,X,e),c(this,N).getQueryCache().notify({query:c(this,C),type:"observerResultsUpdated"})}async refetch({...e}={}){return await this.fetch({...e})}async fetch(e){const t=this.buildQuery(this.options);t!==c(this,C)&&(M(this,C,t),M(this,Y,t.state),this.queryUpdateSubject.next({options:this.options,query:t}));const n={...e,cancelRefetch:(e==null?void 0:e.cancelRefetch)??!0};c(this,C).fetch(this.options,n).catch(r.noop),c(this,se).next({query:t,fetchOptions:n}),await t.getFetchResultAsPromise();const{result:i}=this.getObserverResultFromQuery({query:t,options:this.options,prevResult:c(this,U)});return i}subscribe(e){const t=this.observe().subscribe(e);return()=>{t.unsubscribe()}}observe(){const e=c(this,C),t=this.queryUpdateSubject.pipe(r.map(({query:a})=>a),r.startWith(c(this,C)),r.distinctUntilChanged()),n=this.queryUpdateSubject.pipe(r.startWith({query:c(this,C),options:this.options}),r.pairwise(),r.tap(([{options:a,query:l},{options:p,query:f}])=>{Ke(f,l,p,a)&&this.fetch().catch(r.noop)}),r.ignoreElements()),i=t.pipe(r.switchMap(a=>a.observe(this)),r.ignoreElements());return r.merge(i,n,t.pipe(r.switchMap(a=>{const l=this.options,p=this.queryUpdateSubject.pipe(r.startWith({query:a,options:l}),r.filter(m=>m.query===a),r.map(m=>m.options),r.distinctUntilChanged(),r.shareReplay(1)),f=c(this,se).pipe(r.filter(m=>m.query===a)),h=a.state$.pipe(r.filter(m=>m.status==="success"),r.switchMap(m=>this.options.staleTime===1/0?r.NEVER:r.timer(this.options.staleTime??1).pipe(r.map(()=>m))),r.takeWhile(()=>this.options.enabled??!0)),d=(m,q)=>{const Q=l.notifyOnChangeProps,I=typeof Q=="function"?Q():Q;return(Array.isArray(I)?I.length===0?()=>!0:(de,pe)=>{const xe=Ne(de,I),be=Ne(pe,I);return x(xe,be)}:x)(m,q)},o=f.pipe(r.switchMap(()=>a.state$),Ze),y=p.pipe(r.switchMap(()=>{const{refetchInterval:m,refetchIntervalInBackground:q}=this.options,Q=(typeof m=="function"?m(c(this,C)):m)??!1;return Q?r.interval(Q).pipe(r.tap(()=>{(q||me.isFocused())&&this.fetch({cancelRefetch:!1}).catch(r.noop)})):r.NEVER}),r.ignoreElements()),$=p.pipe(r.map(({enabled:m})=>m??!0),r.distinctUntilChanged()),b=$.pipe(r.filter(m=>!m),r.map(()=>a.state)),v=$.pipe(r.filter(m=>m),r.switchMap(()=>me.focusRegained$),r.withLatestFrom(p),r.tap(([,m])=>{xt(a,m)&&this.fetch({cancelRefetch:!1}).catch(r.noop)}),r.ignoreElements()),O=b.pipe(r.map(()=>a.state)),V=m=>m.pipe(r.withLatestFrom(p),r.map(([,q])=>{const Q=this.getObserverResultFromQuery({query:a,options:q,prevResult:c(this,U)});return this.updateResult({query:a,...Q}),Q.result})),E=r.merge(O,o,a.state$,h).pipe(V,r.distinctUntilChanged(x),r.distinctUntilChanged(d));return r.merge(y,v,E)})).pipe(Re(a=>M(this,ne,a)),r.tap({subscribe:()=>{Te(e,this.options)&&this.fetch().catch(r.noop)}})))}destroy(){}}N=new WeakMap,C=new WeakMap,se=new WeakMap,Y=new WeakMap,U=new WeakMap,X=new WeakMap,ne=new WeakMap;function Tt(s,e){return!x(s.getCurrentResult(),e)}const et=ve.createContext(!1),Kt=()=>ve.useContext(et);et.Provider;function Nt(){let s=!1;return{clearReset:()=>{s=!1},reset:()=>{s=!0},isReset:()=>s}}const qt=ve.createContext(Nt()),Ht=()=>ve.useContext(qt);function Wt(s,e){return typeof s=="function"?s(...e):!!s}const Lt=({result:s,errorResetBoundary:e,throwOnError:t,query:n})=>s.isError&&!e.isReset()&&!s.isFetching&&n&&Wt(t,[s.error,n]);function _t(s,e,t){if(process.env.NODE_ENV!=="production"&&(typeof s!="object"||Array.isArray(s)))throw new Error('Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object');const n=Ge(t),i=Kt(),u=Ht(),a=n.defaultQueryOptions(s);a._optimisticResults=i?"isRestoring":"optimistic";const[l]=S.useState(()=>new e(n,a)),p=Oe(()=>l.observe()),f=A(l.getOptimisticResult(a)),h=f.current;he(()=>p.current.pipe(r.filter(o=>!x(o,f.current))),[]),S.useEffect(()=>{l.setOptions(a)},[a,l]);const d=h.error;if(d&&Lt({result:h,errorResetBoundary:u,throwOnError:a.throwOnError,query:n.getQueryCache().get(a.queryHash)}))throw d;return f.current}function zt(s,e){return _t(s,Dt,e)}function Bt(s,e,t=[]){const n=e!=null&&!Array.isArray(e)?e:{},i=n.retry??!0,u=A(n.onError??(p=>{console.error(p)})),a=S.useCallback(()=>R(s),t),l=S.useCallback(()=>a().pipe(r.catchError(p=>{throw u.current(p),p}),i?r.retry():r.identity),[a,i,u]);Ce(l,t)}const tt=()=>s=>r.merge(r.of({isPaused:!0}),_.backToOnline$.pipe(r.mergeMap(()=>r.merge(r.of({isPaused:!1}),s)))),Yt=s=>{let e=0;return s.pipe(r.catchError(t=>(e++,e<=1&&!_.isOnline()?r.merge(r.of({failureCount:e,failureReason:t}),r.timer(1).pipe(r.mergeMap(()=>r.throwError(()=>t).pipe(tt())))):r.throwError(()=>t))))},Gt=({variables:s,state:e,options:t})=>{const n=e.isPaused,i=async()=>await Promise.reject(new Error("No mutationFn found")),u=t.mutationFn??i,l=r.iif(()=>n,r.of(e.context),R(()=>{var o;return((o=t.onMutate)==null?void 0:o.call(t,s))??void 0})).pipe(r.shareReplay(1)),p=(o,y,$)=>(console.error(o),R(()=>{var v;return(v=t.onError)==null?void 0:v.call(t,o,s,y)}).pipe(r.catchError(()=>r.of(o)),r.map(()=>({failureCount:$,error:o,failureReason:o,context:y,status:"error"})))),f=l.pipe(r.switchMap(o=>{const $=(typeof u=="function"?R(()=>u(s)):u).pipe(r.map(b=>({result:{data:b},error:null,context:o})),Yt,Me({...t,retry:(b,v)=>{const O=t.retry??0;return typeof O=="function"?O(b,v):typeof O=="boolean"?O:b<O},caughtError:(b,v)=>r.of({failureCount:b,failureReason:v}),catchError:(b,v)=>p(v,o,b).pipe(r.map(O=>({...O,result:void 0})))}),r.takeWhile(({result:b,error:v})=>(b==null?void 0:b.data)===void 0&&v===void 0,!0));return _.isOnline()||t.networkMode==="offlineFirst"?$:$.pipe(tt())})),h=r.of({...e,variables:s,status:"pending",isPaused:!1,failureCount:0,failureReason:null,submittedAt:e.submittedAt??new Date().getTime()});return r.merge(h,l.pipe(r.map(o=>({context:o}))),f.pipe(r.switchMap(({result:o,error:y,...$})=>{if(!o&&!y)return r.of({...$});const b=y?r.of(null):R(()=>{var F;return(F=t.onSuccess)==null?void 0:F.call(t,o==null?void 0:o.data,s,$.context)}),O=R(()=>{var F;return(F=t.onSettled)==null?void 0:F.call(t,o==null?void 0:o.data,y,s,$.context)}).pipe(r.catchError(F=>o?r.of(o):r.of(F)));return r.concat(b,O).pipe(r.toArray(),r.map(()=>y?{error:y,data:void 0,variables:s,...$}:{status:"success",error:y,data:o==null?void 0:o.data,variables:s,failureCount:0,failureReason:null,...$}),r.catchError(F=>p(F,$.context,0).pipe(r.map(E=>({...E,data:void 0})))))}))).pipe(r.scan((o,y)=>({...o,...y,data:y.data??o.data,error:y.error??o.error}),z()),r.distinctUntilChanged(({data:o,...y},{data:$,...b})=>x(y,b)&&x(o,$)))};var ie,L,Z;class Jt{constructor({options:e,mutationCache:t,state:n}){w(this,ie,new r.BehaviorSubject(0));w(this,L,new r.Subject);w(this,Z,new r.Subject);g(this,"state",z());g(this,"state$");g(this,"options");g(this,"observerCount$",c(this,ie).asObservable());g(this,"cancelled$",c(this,L).asObservable());this.options=e,this.state=n??this.state;const i=c(this,Z).pipe(r.switchMap(u=>Gt({options:{...this.options,onMutate:a=>{const l=R(()=>{var d,o;return(o=(d=t.config).onMutate)==null?void 0:o.call(d,a,this)}),f=R(()=>{var d,o;return(o=(d=this.options).onMutate)==null?void 0:o.call(d,a)});return l.pipe(r.mergeMap(()=>f))},onError:(a,l,p)=>{const f=R(()=>{var d,o;return(o=(d=t.config).onError)==null?void 0:o.call(d,a,l,p,this)}),h=R(()=>{var d,o;return(o=(d=this.options).onError)==null?void 0:o.call(d,a,l,p)});return r.concat(f,h).pipe(r.toArray())},onSettled:(a,l,p,f)=>{const h=R(()=>{var o,y;return(y=(o=t.config).onSettled)==null?void 0:y.call(o,a,l,p,f,this)}),d=R(()=>{var o,y;return(y=(o=this.options).onSettled)==null?void 0:y.call(o,a,l,p,f)});return r.concat(h,d).pipe(r.toArray())},onSuccess:(a,l,p)=>{const f=R(()=>{var d,o;return(o=(d=t.config).onSuccess)==null?void 0:o.call(d,a,l,p,this)}),h=R(()=>{var d,o;return(o=(d=this.options).onSuccess)==null?void 0:o.call(d,a,l,p)});return r.concat(f,h).pipe(r.toArray())}},state:this.state,variables:u}).pipe(r.takeUntil(c(this,L)))));this.state$=r.merge(i,r.NEVER).pipe(r.startWith(this.state),r.tap(u=>{this.state={...this.state,...u}}),r.takeUntil(c(this,L)),r.shareReplay({bufferSize:1,refCount:!1}),Re(u=>{c(this,ie).next(u)}))}get meta(){return this.options.meta}setOptions(e){this.options={...this.options,...e}}execute(e){return c(this,Z).next(e),c(this,Z).complete(),this.state$.pipe(re)}continue(){return this.execute(this.state.variables)}cancel(){c(this,L).next(),c(this,L).complete()}}ie=new WeakMap,L=new WeakMap,Z=new WeakMap;const We=({mutationKey:s,status:e,predicate:t,exact:n=!0}={})=>u=>n&&s!==void 0&&u.options.mutationKey!==void 0&&!ge(u.options.mutationKey,s,{exact:n})||!n&&s!==void 0&&u.options.mutationKey!==void 0&&!ge(u.options.mutationKey,s,{exact:n})||e&&u.state.status!==e?!1:t?t(u):!0;class rt{constructor(){g(this,"entriesSubject",new r.BehaviorSubject([]));g(this,"changeSubject",new r.Subject);g(this,"entries$",this.entriesSubject.pipe(r.share()));g(this,"added$",this.changeSubject.pipe(r.filter(({type:e})=>e==="added"),r.map(({entity:e})=>e),r.share()));g(this,"removed$",this.changeSubject.pipe(r.filter(({type:e})=>e==="removed"),r.map(({entity:e})=>e),r.share()));g(this,"stateChange$",r.merge(this.entriesSubject.pipe(r.first(),r.mergeMap(e=>r.from(e))),this.added$).pipe(r.mergeMap(e=>e.state$.pipe(r.map(()=>e),r.takeUntil(this.removed$.pipe(r.filter(t=>t===e))))),r.share()))}getValues(){return this.entriesSubject.getValue()}remove(e){this.entriesSubject.next(this.entriesSubject.getValue().filter(t=>e!==t)),this.changeSubject.next({type:"removed",entity:e})}add(e){this.entriesSubject.next([...this.entriesSubject.getValue(),e]),this.changeSubject.next({type:"added",entity:e})}find(e){return this.entriesSubject.getValue().find(e)}}var k;class st{constructor(e={}){w(this,k,new rt);this.config=e}build(e,t,n){const i=new Jt({mutationCache:this,options:e.defaultMutationOptions(t),state:n});return i.state$.pipe(r.filter(({status:u})=>u==="success"||u==="error"),r.switchMap(()=>i.observerCount$.pipe(r.filter(u=>u<=1),r.take(1))),r.switchMap(()=>r.timer(i.options.gcTime??5*60*1e3)),r.take(1)).subscribe({complete:()=>{this.remove(i)}}),c(this,k).add(i),i}getAll(){return this.findAll()}remove(e){const t=c(this,k).getValues().find(n=>n===e);t==null||t.cancel(),c(this,k).remove(e)}find(e){const t={exact:!0,...e},n=We(t);return c(this,k).getValues().find(i=>n(i))}findAll(e={}){const t={exact:!0,...e},n=We(t);return c(this,k).getValues().filter(i=>n(i)).map(i=>i)}observe(){return c(this,k).stateChange$.pipe(r.startWith())}subscribe(e){const t=r.merge(c(this,k).added$.pipe(r.tap(n=>{e({type:"added",mutation:n})})),c(this,k).removed$.pipe(r.tap(n=>{e({type:"removed",mutation:n})})),c(this,k).stateChange$.pipe(r.tap(n=>{e({type:"updated",action:{...n.state,type:"success"},mutation:n})}))).subscribe();return()=>{t.unsubscribe()}}resumePausedMutations(){const e=this.findAll({predicate:n=>n.state.isPaused});if(!e.length)return r.EMPTY;const t=e.map(n=>n.continue());return r.combineLatest(t)}clear(){this.getAll().forEach(e=>{this.remove(e)})}}k=new WeakMap;const Xt=typeof window>"u"||"Deno"in window;function Zt(s){const e=typeof s.initialData=="function"?s.initialData():s.initialData,t=typeof e<"u",n=t?typeof s.initialDataUpdatedAt=="function"?s.initialDataUpdatedAt():s.initialDataUpdatedAt:0;return{data:e,dataUpdateCount:0,dataUpdatedAt:t?n??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:t?"success":"pending",fetchStatus:"idle"}}const er=s=>r.defer(()=>me.isFocused()?s:me.focusRegained$.pipe(r.mergeMap(()=>s))),tr=s=>{let e=0;return t=>{const n=_.backToOnline$.pipe(r.mergeMap(()=>r.merge(r.of({fetchStatus:"fetching"}),t)));return r.defer(()=>(e++,!_.isOnline()&&s.networkMode==="offlineFirst"&&e>1?r.merge(r.of({fetchStatus:"paused"}),n):!_.isOnline()&&s.networkMode!=="always"&&s.networkMode!=="offlineFirst"?r.merge(r.of({fetchStatus:"paused"}),n):t))}},rr=s=>{const e=async()=>await Promise.reject(new Error("No query found"));let t=!1;const n=s.queryFn??e,i=new AbortController,u={meta:s.meta,queryKey:s.queryKey};(d=>{Object.defineProperty(d,"signal",{enumerable:!0,get:()=>(s.onSignalConsumed(),i.signal)})})(u);const p=(typeof n=="function"?R(()=>n(u)):n).pipe(r.tap({complete:()=>{t=!0}}),r.map(d=>({data:d})),tr(s),Me({...s,retryAfter:()=>r.of(!0).pipe(er),catchError:(d,o)=>r.of({status:"error",fetchStatus:"idle",fetchFailureCount:d,fetchFailureReason:o,error:o}),caughtError:(d,o)=>r.of({fetchFailureCount:d,fetchFailureReason:o})}),r.mergeMap(d=>"data"in d?r.of({...d,status:"success",fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null,dataUpdatedAt:new Date().getTime()}).pipe(r.delay(1),r.map(o=>t?o:{...o,fetchStatus:"fetching"})):r.of(d)),r.share()),f=p.pipe(r.ignoreElements(),r.endWith({fetchStatus:"idle"})),h=r.of({status:"pending",fetchStatus:_.isOnline()?"fetching":"paused"});return{state$:r.merge(h,p,f),abortController:i}};class sr{constructor(e){g(this,"revert");g(this,"silent");this.revert=e==null?void 0:e.revert,this.silent=e==null?void 0:e.silent}}const nr={backgroundColor:"transparent",color:"inherit"};function nt(s){const e={namespaces:[{name:"@reactjrx",style:{backgroundColor:"#d02f4e",color:"white"}}],namespace(t,n){const i=nt(s);return i.namespaces.push({name:t,style:n??nr}),i},printNamespaces(){return{namespaces:e.namespaces.map(({name:t})=>`%c ${t} %c`).join(" "),styles:e.namespaces.reduce((t,{style:n})=>(t.push(`background-color: ${n.backgroundColor}; color: ${n.color};`),t.push("background-color: transparent; color: inherit;"),t),[])}},print(t,...n){if(s==="development"){const{namespaces:i,styles:u}=e.printNamespaces();console[t](i,...u,...n)}return e},printWithoutNamespace(t,...n){return s==="development"&&console[t](...n),e},log(...t){return e.print("log",...t)},warn(...t){return e.print("warn",...t)},error(...t){return e.print("error",...t)},group(...t){return e.print("group",...t)},groupEnd(){return s==="development"&&console.groupEnd(),e}};return e}const ir=nt("production");var ae,G;class ar{constructor(e){g(this,"queryKey");g(this,"queryHash");g(this,"gcTime");g(this,"options");w(this,ae,void 0);w(this,G,void 0);g(this,"state");g(this,"executeSubject",new r.Subject);g(this,"cancelSubject",new r.Subject);g(this,"setDataSubject",new r.Subject);g(this,"invalidatedSubject",new r.Subject);g(this,"resetSubject",new r.Subject);g(this,"destroySubject",new r.Subject);g(this,"observersSubject",new r.BehaviorSubject([]));g(this,"abortSignalConsumed",!1);g(this,"observerCount$",this.observersSubject.asObservable().pipe(r.map(e=>e.length)));g(this,"observers$",this.observersSubject.asObservable());g(this,"state$");M(this,ae,e.defaultOptions),this.options=this.setOptions(e.options),this.queryKey=e.queryKey,this.queryHash=e.queryHash,M(this,G,e.state??Zt(this.options)),this.state=c(this,G),this.gcTime=this.updateGcTime(this.options.gcTime),this.state$=r.merge(this.resetSubject.pipe(r.map(()=>({command:"reset",state:c(this,G)}))),this.invalidatedSubject.pipe(r.filter(()=>!this.state.isInvalidated),r.map(()=>({command:"invalidate",state:{isInvalidated:!0}}))),this.cancelSubject.pipe(r.filter(()=>!(this.state.error&&this.state.status==="error")),r.map(t=>({command:"cancel",state:{status:t!=null&&t.revert?this.state.status:"error",fetchStatus:"idle",error:new sr(t)}}))),this.executeSubject.pipe(r.mergeMap(()=>{let t=!1;const n=this.executeSubject.pipe(r.filter(f=>(f==null?void 0:f.cancelRefetch)!==!1)),i=this.observers$.pipe(r.pairwise(),r.tap(([f,h])=>{h.length===0&&f.length>0?t=!0:t=!1}),r.ignoreElements()),{state$:u,abortController:a}=rr({...this.options,queryKey:this.queryKey,retry:(f,h)=>{const d=this.options.retry??!0;return typeof d=="function"?d(f,h):typeof d=="boolean"?d:f<d},retryAfterDelay:()=>!t,onSignalConsumed:()=>{this.abortSignalConsumed=!0}}),l=this.observerCount$.pipe(r.filter(f=>f===0&&this.abortSignalConsumed),r.tap(()=>{this.cancelSubject.next({revert:!0})})),p=r.merge(this.cancelSubject,n,this.resetSubject,l).pipe(r.tap(()=>{this.abortSignalConsumed&&a.abort()}));return r.merge(u,i).pipe(r.map(f=>({command:"execute",state:f})),r.takeUntil(p))})),this.setDataSubject.pipe(r.map(({data:t,options:n})=>({command:"setData",state:{status:"success",data:t,dataUpdatedAt:(n==null?void 0:n.updatedAt)!==void 0?n.updatedAt:new Date().getTime()}})))).pipe(kt({initialState:this.state,getOptions:()=>this.options,getState:()=>this.state}),r.startWith(c(this,G)),r.distinctUntilChanged(x),r.tap(t=>{this.state=t}),r.takeUntil(this.destroySubject),r.shareReplay({bufferSize:1,refCount:!1}),r.catchError(t=>{throw ir.error(t),t}))}setOptions(e){return this.options={...c(this,ae),...e},this.updateGcTime(this.options.gcTime),this.options}get meta(){return this.options.meta}get success$(){return this.state$.pipe(r.map(({data:e,status:t})=>({data:e,status:t})),r.distinctUntilChanged(x),r.filter(({status:e})=>e==="success"))}get error$(){return this.state$.pipe(r.map(({error:e,status:t})=>({error:e,status:t})),r.distinctUntilChanged(x),r.filter(({status:e})=>e==="error"))}get settled$(){return this.state$.pipe(r.map(({status:e})=>({status:e})),r.distinctUntilChanged(x),r.filter(({status:e})=>e==="success"||e==="error"))}observe(e){return this.state$.pipe(r.tap({subscribe:()=>{this.observersSubject.next([e,...this.observersSubject.getValue()])},unsubscribe:()=>{this.observersSubject.next(this.observersSubject.getValue().filter(n=>n!==e))}}))}getObserversCount(){return this.observersSubject.getValue().length}updateGcTime(e){return this.gcTime=Math.max(this.gcTime||0,e??(Xt?1/0:5*60*1e3)),this.gcTime}isActive(){return this.observersSubject.getValue().some(e=>e.options.enabled!==!1)}isDisabled(){return this.getObserversCount()>0&&!this.isActive()}isStale(){return this.state.isInvalidated||!this.state.dataUpdatedAt||this.observersSubject.getValue().some(e=>e.getCurrentResult().isStale)}isStaleByTime(e=0){return this.state.isInvalidated||!this.state.dataUpdatedAt||!Qt(this.state.dataUpdatedAt,e)}async getFetchResultAsPromise(){return await new Promise((e,t)=>{this.state$.pipe(Ze,r.last()).subscribe({error:t,next:n=>{n.error?t(n.error):e(n.data)}})})}async fetch(e,t){const{cancelRefetch:n}=t??{};return this.state.fetchStatus!=="idle"&&!(!!this.state.dataUpdatedAt&&n)?await this.getFetchResultAsPromise():(e&&this.setOptions(e),this.executeSubject.next(t),await this.getFetchResultAsPromise())}setData(e,t){const n=ye(this.state.data,e,this.options);return this.setDataSubject.next({data:n,options:t}),n}invalidate(){this.invalidatedSubject.next()}async cancel(e){this.cancelSubject.next(e)}destroy(){this.destroySubject.next(),this.destroySubject.complete(),this.executeSubject.complete()}reset(){this.resetSubject.next()}}ae=new WeakMap,G=new WeakMap;var ue,K;class ur{constructor(e={}){w(this,ue,new r.Subject);w(this,K,new rt);this.config=e}mount(){}unmount(){}notify(e){c(this,ue).next(e)}observeIsFetching(e){return c(this,K).stateChange$.pipe(r.startWith(),r.map(()=>this.findAll({...e,fetchStatus:"fetching"}).length),r.distinctUntilChanged())}getAll(){return[...c(this,K).getValues()]}findAll(e={}){const t=this.getAll();return Object.keys(e).length>0?t.filter(n=>He(e,n)):t}build(e,t,n){const i=t.queryKey??[je()],u=t.queryHash??Ue(i,t);let a=this.get(u);return a||(a=new ar({cache:this,queryKey:i,queryHash:u,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(i)}),this.add(a)),a}add(e){if(!c(this,K).find(t=>t.queryHash===e.queryHash)){c(this,K).add(e);const t=e.observerCount$.pipe(r.filter(n=>n<1),r.take(1));e.success$.subscribe(()=>{var n,i;(i=(n=this.config).onSuccess)==null||i.call(n,e.state.data,e)}),e.error$.subscribe(()=>{var n,i;(i=(n=this.config).onError)==null||i.call(n,e.state.error,e)}),e.settled$.subscribe(()=>{var n,i;(i=(n=this.config).onSettled)==null||i.call(n,e.state.data,e.state.error,e)}),e.state$.pipe(Vt,r.switchMap(n=>n?t.pipe(r.switchMap(()=>e.gcTime===1/0?r.NEVER:(setTimeout(r.noop,e.gcTime),r.timer(e.gcTime)))):r.NEVER),r.take(1)).subscribe({complete:()=>{this.remove(e)}})}}get(e){return c(this,K).find(t=>t.queryHash===e)}find(e){const t={exact:!0,...e};return this.getAll().find(n=>He(t,n))}subscribe(e){const t=r.merge(c(this,ue).pipe(r.tap(e))).subscribe();return()=>{t.unsubscribe()}}remove(e){const t=c(this,K).find(n=>n===e);t&&(e.destroy(),t===e&&c(this,K).remove(e))}clear(){}}ue=new WeakMap,K=new WeakMap;var J,j,ce,oe,le;class cr{constructor({mutationCache:e,queryCache:t,defaultOptions:n}={}){w(this,J,void 0);w(this,j,void 0);w(this,ce,new Map);w(this,oe,new Map);w(this,le,void 0);M(this,J,e??new st),M(this,j,t??new ur),M(this,le,n??{})}mount(){}unmount(){}getMutationCache(){return c(this,J)}getQueryCache(){return c(this,j)}defaultMutationOptions(e){return{...(e==null?void 0:e.mutationKey)&&this.getMutationDefaults(e.mutationKey),...e}}defaultQueryOptions(e){if(e!=null&&e._defaulted)return e;const t={...c(this,le).queries,...(e==null?void 0:e.queryKey)&&this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=Ue(t.queryKey,t)),typeof t.refetchOnReconnect>"u"&&(t.refetchOnReconnect=t.networkMode!=="always"),typeof t.throwOnError>"u"&&(t.throwOnError=!!t.suspense),typeof t.networkMode>"u"&&t.persister&&(t.networkMode="offlineFirst"),t}async fetchQuery(e){const t=this.defaultQueryOptions(e);typeof t.retry>"u"&&(t.retry=!1);const n=c(this,j).build(this,t);return n.isStaleByTime(t.staleTime)?await n.fetch(t):await Promise.resolve(n.state.data)}async prefetchQuery(e){await this.fetchQuery(e).then(r.noop).catch(r.noop)}async resetQueries(e,t){const n=c(this,j),i={type:"active",...e};n.findAll(e).forEach(u=>{u.reset()}),await this.refetchQueries(i,t)}async refetchQueries(e={},t){const n={...t,cancelRefetch:(t==null?void 0:t.cancelRefetch)??!0},i=c(this,j).findAll(e).filter(u=>!u.isDisabled()).map(async u=>{let a=u.fetch(void 0,n);return n.throwOnError||(a=a.catch(r.noop)),u.state.fetchStatus==="paused"?void 0:await a});await Promise.all(i).then(r.noop)}getQueryData(e){var n;const t=this.defaultQueryOptions({queryKey:e});return(n=c(this,j).get(t.queryHash))==null?void 0:n.state.data}setQueryData(e,t,n){const i=c(this,j).find({queryKey:e}),u=i==null?void 0:i.state.data,a=Pt(t,u);if(typeof a>"u")return;const l=this.defaultQueryOptions({queryKey:e});return c(this,j).build(this,l).setData(a,{...n,manual:!0})}getMutationDefaults(e){const t=[...c(this,ce).values()];let n={};return t.forEach(i=>{ge(e,i.mutationKey)&&(n={...n,...i.defaultOptions})}),n}getQueryState(e){var t;return(t=c(this,j).find({queryKey:e}))==null?void 0:t.state}setMutationDefaults(e,t){c(this,ce).set(ee(e),{mutationKey:e,defaultOptions:t})}setQueryDefaults(e,t){c(this,oe).set(ee(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...c(this,oe).values()];let n={};return t.forEach(i=>{we(e,i.queryKey)&&(n={...n,...i.defaultOptions})}),n}removeQueries(e){const t=c(this,j);t.findAll(e).forEach(n=>{t.remove(n)})}async cancelQueries(e={},t={}){const n={revert:!0,...t},i=c(this,j).findAll(e).map(async u=>{await u.cancel(n)});await Promise.all(i).then(r.noop).catch(r.noop)}async invalidateQueries(e={},t={}){if(c(this,j).findAll(e).forEach(i=>{i.invalidate()}),e.refetchType==="none"){await Promise.resolve();return}const n={...e,type:e.refetchType??e.type??"active"};await this.refetchQueries(n,t)}async resumePausedMutations(){return await r.lastValueFrom(c(this,J).resumePausedMutations())}isFetching(e){return c(this,j).findAll({...e,fetchStatus:"fetching"}).length}clear(){c(this,j).clear(),c(this,J).clear()}}J=new WeakMap,j=new WeakMap,ce=new WeakMap,oe=new WeakMap,le=new WeakMap;exports.MutationCache=st;exports.QueryClient=cr;exports.QueryClientProvider=Et;exports.SIGNAL_RESET=_e;exports.createLocalforageAdapter=bt;exports.createSharedStoreAdapter=pt;exports.exponentialBackoffDelay=Be;exports.getDelay=ze;exports.retryBackoff=Me;exports.signal=ft;exports.useBehaviorSubject=Le;exports.useLiveRef=A;exports.useMutation=jt;exports.useObservableState=ht;exports.useObserve=he;exports.useObserveCallback=lt;exports.usePersistSignals=vt;exports.useQuery=zt;exports.useSignalValue=dt;exports.useSubject=Ee;exports.useSubscribe=Ce;exports.useSubscribeEffect=Bt;exports.useUnmountObservable=Ot;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export * from "./lib/binding/useObserve";
2
2
  export * from "./lib/binding/useSubscribe";
3
- export * from "./lib/binding/useObserveCallback";
4
- export * from "./lib/binding/trigger";
3
+ export * from "./lib/binding/useObservableEvent";
4
+ export * from "./lib/binding/useObservableState";
5
5
  export * from "./lib/binding/useSubject";
6
6
  export * from "./lib/binding/useBehaviorSubject";
7
7
  export * from "./lib/state/signal";
@@ -15,7 +15,7 @@ export * from "./lib/utils/operators/retryBackoff";
15
15
  export * from "./lib/utils/useLiveRef";
16
16
  export * from "./lib/queries/react/mutations/useMutation";
17
17
  export * from "./lib/queries/react/queries/useQuery";
18
- export * from "./lib/queries/react/useSubscribeEffect";
19
- export * from "./lib/queries/client/createClient";
20
- export { QueryClientProvider, useQueryClient } from "./lib/queries/react/Provider";
18
+ export * from "./lib/binding/useSubscribeEffect";
19
+ export * from "./lib/queries/client/QueryClient";
20
+ export { QueryClientProvider } from "./lib/queries/react/QueryClientProvider";
21
21
  export { MutationCache } from "./lib/queries/client/mutations/cache/MutationCache";