@leancodepl/react-query-cqrs-client 9.7.4 → 10.0.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.
@@ -1,4 +1,4 @@
1
- (function(M,K){typeof exports=="object"&&typeof module<"u"?K(exports,require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime"],K):(M=typeof globalThis<"u"?globalThis:M||self,K(M["@leancodepl/react-query-cqrs-client"]={},M.React))})(this,(function(M,K){"use strict";function St(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const R=St(K);var Y=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},Ot={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},Pt=class{#t=Ot;#e=!1;setTimeoutProvider(e){process.env.NODE_ENV!=="production"&&this.#e&&e!==this.#t&&console.error("[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.",{previous:this.#t,provider:e}),this.#t=e,process.env.NODE_ENV!=="production"&&(this.#e=!1)}setTimeout(e,t){return process.env.NODE_ENV!=="production"&&(this.#e=!0),this.#t.setTimeout(e,t)}clearTimeout(e){this.#t.clearTimeout(e)}setInterval(e,t){return process.env.NODE_ENV!=="production"&&(this.#e=!0),this.#t.setInterval(e,t)}clearInterval(e){this.#t.clearInterval(e)}},Z=new Pt;function Rt(e){setTimeout(e,0)}var V=typeof window>"u"||"Deno"in globalThis;function ee(){}function Ie(e){return typeof e=="number"&&e>=0&&e!==1/0}function Tt(e,t){return Math.max(e+(t||0)-Date.now(),0)}function $(e,t){return typeof e=="function"?e(t):e}function F(e,t){return typeof e=="function"?e(t):e}function Ae(e){return JSON.stringify(e,(t,r)=>ue(r)?Object.keys(r).sort().reduce((n,i)=>(n[i]=r[i],n),{}):r)}var xt=Object.prototype.hasOwnProperty;function ae(e,t){if(e===t)return e;const r=Fe(e)&&Fe(t);if(!r&&!(ue(e)&&ue(t)))return t;const i=(r?e:Object.keys(e)).length,s=r?t:Object.keys(t),a=s.length,l=r?new Array(a):{};let o=0;for(let c=0;c<a;c++){const u=r?c:s[c],f=e[u],h=t[u];if(f===h){l[u]=f,(r?c<i:xt.call(e,u))&&o++;continue}if(f===null||h===null||typeof f!="object"||typeof h!="object"){l[u]=h;continue}const d=ae(f,h);l[u]=d,d===f&&o++}return i===a&&o===i?e:l}function te(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(const r in e)if(e[r]!==t[r])return!1;return!0}function Fe(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function ue(e){if(!je(e))return!1;const t=e.constructor;if(t===void 0)return!0;const r=t.prototype;return!(!je(r)||!r.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(e)!==Object.prototype)}function je(e){return Object.prototype.toString.call(e)==="[object Object]"}function ke(e,t,r){if(typeof r.structuralSharing=="function")return r.structuralSharing(e,t);if(r.structuralSharing!==!1){if(process.env.NODE_ENV!=="production")try{return ae(e,t)}catch(n){throw console.error(`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${r.queryHash}]: ${n}`),n}return ae(e,t)}return t}function It(e,t,r=0){const n=[...e,t];return r&&n.length>r?n.slice(1):n}function At(e,t,r=0){const n=[t,...e];return r&&n.length>r?n.slice(0,-1):n}var Ce=Symbol();function Ft(e,t){return process.env.NODE_ENV!=="production"&&e.queryFn===Ce&&console.error(`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${e.queryHash}'`),!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===Ce?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function Me(e,t){return typeof e=="function"?e(...t):!!e}var jt=class extends Y{#t;#e;#r;constructor(){super(),this.#r=e=>{if(!V&&window.addEventListener){const t=()=>e();return window.addEventListener("visibilitychange",t,!1),()=>{window.removeEventListener("visibilitychange",t)}}}}onSubscribe(){this.#e||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#e?.(),this.#e=void 0)}setEventListener(e){this.#r=e,this.#e?.(),this.#e=e(t=>{typeof t=="boolean"?this.setFocused(t):this.onFocus()})}setFocused(e){this.#t!==e&&(this.#t=e,this.onFocus())}onFocus(){const e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#t=="boolean"?this.#t:globalThis.document?.visibilityState!=="hidden"}},kt=new jt;function Le(){let e,t;const r=new Promise((i,s)=>{e=i,t=s});r.status="pending",r.catch(()=>{});function n(i){Object.assign(r,i),delete r.resolve,delete r.reject}return r.resolve=i=>{n({status:"fulfilled",value:i}),e(i)},r.reject=i=>{n({status:"rejected",reason:i}),t(i)},r}var Ct=Rt;function Mt(){let e=[],t=0,r=l=>{l()},n=l=>{l()},i=Ct;const s=l=>{t?e.push(l):i(()=>{r(l)})},a=()=>{const l=e;e=[],l.length&&i(()=>{n(()=>{l.forEach(o=>{r(o)})})})};return{batch:l=>{let o;t++;try{o=l()}finally{t--,t||a()}return o},batchCalls:l=>(...o)=>{s(()=>{l(...o)})},schedule:s,setNotifyFunction:l=>{r=l},setBatchNotifyFunction:l=>{n=l},setScheduler:l=>{i=l}}}var re=Mt(),Lt=class extends Y{#t=!0;#e;#r;constructor(){super(),this.#r=e=>{if(!V&&window.addEventListener){const t=()=>e(!0),r=()=>e(!1);return window.addEventListener("online",t,!1),window.addEventListener("offline",r,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",r)}}}}onSubscribe(){this.#e||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#e?.(),this.#e=void 0)}setEventListener(e){this.#r=e,this.#e?.(),this.#e=e(this.setOnline.bind(this))}setOnline(e){this.#t!==e&&(this.#t=e,this.listeners.forEach(r=>{r(e)}))}isOnline(){return this.#t}},Dt=new Lt;function Qt(e){return(e??"online")==="online"?Dt.isOnline():!0}function Nt(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:Qt(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}var De=class extends Y{constructor(e,t){super(),this.options=t,this.#t=e,this.#a=null,this.#o=Le(),this.bindMethods(),this.setOptions(t)}#t;#e=void 0;#r=void 0;#n=void 0;#i;#s;#o;#a;#y;#h;#d;#c;#l;#u;#p=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#e.addObserver(this),Qe(this.#e,this.options)?this.#f():this.updateResult(),this.#g())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return ce(this.#e,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return ce(this.#e,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#w(),this.#E(),this.#e.removeObserver(this)}setOptions(e){const t=this.options,r=this.#e;if(this.options=this.#t.defaultQueryOptions(e),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof F(this.options.enabled,this.#e)!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");this.#S(),this.#e.setOptions(this.options),t._defaulted&&!te(this.options,t)&&this.#t.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#e,observer:this});const n=this.hasListeners();n&&Ne(this.#e,r,this.options,t)&&this.#f(),this.updateResult(),n&&(this.#e!==r||F(this.options.enabled,this.#e)!==F(t.enabled,this.#e)||$(this.options.staleTime,this.#e)!==$(t.staleTime,this.#e))&&this.#v();const i=this.#m();n&&(this.#e!==r||F(this.options.enabled,this.#e)!==F(t.enabled,this.#e)||i!==this.#u)&&this.#b(i)}getOptimisticResult(e){const t=this.#t.getQueryCache().build(this.#t,e),r=this.createResult(t,e);return _t(this,r)&&(this.#n=r,this.#s=this.options,this.#i=this.#e.state),r}getCurrentResult(){return this.#n}trackResult(e,t){return new Proxy(e,{get:(r,n)=>(this.trackProp(n),t?.(n),n==="promise"&&!this.options.experimental_prefetchInRender&&this.#o.status==="pending"&&this.#o.reject(new Error("experimental_prefetchInRender feature flag is not enabled")),Reflect.get(r,n))})}trackProp(e){this.#p.add(e)}getCurrentQuery(){return this.#e}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){const t=this.#t.defaultQueryOptions(e),r=this.#t.getQueryCache().build(this.#t,t);return r.fetch().then(()=>this.createResult(r,t))}fetch(e){return this.#f({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#n))}#f(e){this.#S();let t=this.#e.fetch(this.options,e);return e?.throwOnError||(t=t.catch(ee)),t}#v(){this.#w();const e=$(this.options.staleTime,this.#e);if(V||this.#n.isStale||!Ie(e))return;const r=Tt(this.#n.dataUpdatedAt,e)+1;this.#c=Z.setTimeout(()=>{this.#n.isStale||this.updateResult()},r)}#m(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(this.#e):this.options.refetchInterval)??!1}#b(e){this.#E(),this.#u=e,!(V||F(this.options.enabled,this.#e)===!1||!Ie(this.#u)||this.#u===0)&&(this.#l=Z.setInterval(()=>{(this.options.refetchIntervalInBackground||kt.isFocused())&&this.#f()},this.#u))}#g(){this.#v(),this.#b(this.#m())}#w(){this.#c&&(Z.clearTimeout(this.#c),this.#c=void 0)}#E(){this.#l&&(Z.clearInterval(this.#l),this.#l=void 0)}createResult(e,t){const r=this.#e,n=this.options,i=this.#n,s=this.#i,a=this.#s,o=e!==r?e.state:this.#r,{state:c}=e;let u={...c},f=!1,h;if(t._optimisticResults){const T=this.hasListeners(),B=!T&&Qe(e,t),k=T&&Ne(e,r,t,n);(B||k)&&(u={...u,...Nt(c.data,e.options)}),t._optimisticResults==="isRestoring"&&(u.fetchStatus="idle")}let{error:d,errorUpdatedAt:y,status:p}=u;h=u.data;let S=!1;if(t.placeholderData!==void 0&&h===void 0&&p==="pending"){let T;i?.isPlaceholderData&&t.placeholderData===a?.placeholderData?(T=i.data,S=!0):T=typeof t.placeholderData=="function"?t.placeholderData(this.#d?.state.data,this.#d):t.placeholderData,T!==void 0&&(p="success",h=ke(i?.data,T,t),f=!0)}if(t.select&&h!==void 0&&!S)if(i&&h===s?.data&&t.select===this.#y)h=this.#h;else try{this.#y=t.select,h=t.select(h),h=ke(i?.data,h,t),this.#h=h,this.#a=null}catch(T){this.#a=T}this.#a&&(d=this.#a,h=this.#h,y=Date.now(),p="error");const g=u.fetchStatus==="fetching",P=p==="pending",w=p==="error",v=P&&g,m=h!==void 0,A={status:p,fetchStatus:u.fetchStatus,isPending:P,isSuccess:p==="success",isError:w,isInitialLoading:v,isLoading:v,data:h,dataUpdatedAt:u.dataUpdatedAt,error:d,errorUpdatedAt:y,failureCount:u.fetchFailureCount,failureReason:u.fetchFailureReason,errorUpdateCount:u.errorUpdateCount,isFetched:u.dataUpdateCount>0||u.errorUpdateCount>0,isFetchedAfterMount:u.dataUpdateCount>o.dataUpdateCount||u.errorUpdateCount>o.errorUpdateCount,isFetching:g,isRefetching:g&&!P,isLoadingError:w&&!m,isPaused:u.fetchStatus==="paused",isPlaceholderData:f,isRefetchError:w&&m,isStale:le(e,t),refetch:this.refetch,promise:this.#o,isEnabled:F(t.enabled,e)!==!1};if(this.options.experimental_prefetchInRender){const T=U=>{A.status==="error"?U.reject(A.error):A.data!==void 0&&U.resolve(A.data)},B=()=>{const U=this.#o=A.promise=Le();T(U)},k=this.#o;switch(k.status){case"pending":e.queryHash===r.queryHash&&T(k);break;case"fulfilled":(A.status==="error"||A.data!==k.value)&&B();break;case"rejected":(A.status!=="error"||A.error!==k.reason)&&B();break}}return A}updateResult(){const e=this.#n,t=this.createResult(this.#e,this.options);if(this.#i=this.#e.state,this.#s=this.options,this.#i.data!==void 0&&(this.#d=this.#e),te(t,e))return;this.#n=t;const r=()=>{if(!e)return!0;const{notifyOnChangeProps:n}=this.options,i=typeof n=="function"?n():n;if(i==="all"||!i&&!this.#p.size)return!0;const s=new Set(i??this.#p);return this.options.throwOnError&&s.add("error"),Object.keys(this.#n).some(a=>{const l=a;return this.#n[l]!==e[l]&&s.has(l)})};this.#O({listeners:r()})}#S(){const e=this.#t.getQueryCache().build(this.#t,this.options);if(e===this.#e)return;const t=this.#e;this.#e=e,this.#r=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#g()}#O(e){re.batch(()=>{e.listeners&&this.listeners.forEach(t=>{t(this.#n)}),this.#t.getQueryCache().notify({query:this.#e,type:"observerResultsUpdated"})})}};function Ut(e,t){return F(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status==="error"&&t.retryOnMount===!1)}function Qe(e,t){return Ut(e,t)||e.state.data!==void 0&&ce(e,t,t.refetchOnMount)}function ce(e,t,r){if(F(t.enabled,e)!==!1&&$(t.staleTime,e)!=="static"){const n=typeof r=="function"?r(e):r;return n==="always"||n!==!1&&le(e,t)}return!1}function Ne(e,t,r,n){return(e!==t||F(n.enabled,e)===!1)&&(!r.suspense||e.state.status!=="error")&&le(e,r)}function le(e,t){return F(t.enabled,e)!==!1&&e.isStaleByTime($(t.staleTime,e))}function _t(e,t){return!te(e.getCurrentResult(),t)}function Ue(e){return{onFetch:(t,r)=>{const n=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,s=t.state.data?.pages||[],a=t.state.data?.pageParams||[];let l={pages:[],pageParams:[]},o=0;const c=async()=>{let u=!1;const f=y=>{Object.defineProperty(y,"signal",{enumerable:!0,get:()=>(t.signal.aborted?u=!0:t.signal.addEventListener("abort",()=>{u=!0}),t.signal)})},h=Ft(t.options,t.fetchOptions),d=async(y,p,S)=>{if(u)return Promise.reject();if(p==null&&y.pages.length)return Promise.resolve(y);const P=(()=>{const C={client:t.client,queryKey:t.queryKey,pageParam:p,direction:S?"backward":"forward",meta:t.options.meta};return f(C),C})(),w=await h(P),{maxPages:v}=t.options,m=S?At:It;return{pages:m(y.pages,w,v),pageParams:m(y.pageParams,p,v)}};if(i&&s.length){const y=i==="backward",p=y?_e:fe,S={pages:s,pageParams:a},g=p(n,S);l=await d(S,g,y)}else{const y=s.length;do{const p=o===0?a[0]??n.initialPageParam:fe(n,l);if(o>0&&p==null)break;l=await d(l,p),o++}while(o<y)}return l};t.options.persister?t.fetchFn=()=>t.options.persister?.(c,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},r):t.fetchFn=c}}}function fe(e,{pages:t,pageParams:r}){const n=t.length-1;return t.length>0?e.getNextPageParam(t[n],t,r[n],r):void 0}function _e(e,{pages:t,pageParams:r}){return t.length>0?e.getPreviousPageParam?.(t[0],t,r[0],r):void 0}function qt(e,t){return t?fe(e,t)!=null:!1}function Ht(e,t){return!t||!e.getPreviousPageParam?!1:_e(e,t)!=null}var Bt=class extends De{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){super.setOptions({...e,behavior:Ue()})}getOptimisticResult(e){return e.behavior=Ue(),super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"backward"}}})}createResult(e,t){const{state:r}=e,n=super.createResult(e,t),{isFetching:i,isRefetching:s,isError:a,isRefetchError:l}=n,o=r.fetchMeta?.fetchMore?.direction,c=a&&o==="forward",u=i&&o==="forward",f=a&&o==="backward",h=i&&o==="backward";return{...n,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:qt(t,r.data),hasPreviousPage:Ht(t,r.data),isFetchNextPageError:c,isFetchingNextPage:u,isFetchPreviousPageError:f,isFetchingPreviousPage:h,isRefetchError:l&&!c&&!f,isRefetching:s&&!u&&!h}}};function Kt(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var Vt=class extends Y{#t;#e=void 0;#r;#n;constructor(e,t){super(),this.#t=e,this.setOptions(t),this.bindMethods(),this.#i()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(e){const t=this.options;this.options=this.#t.defaultMutationOptions(e),te(this.options,t)||this.#t.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.#r,observer:this}),t?.mutationKey&&this.options.mutationKey&&Ae(t.mutationKey)!==Ae(this.options.mutationKey)?this.reset():this.#r?.state.status==="pending"&&this.#r.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#r?.removeObserver(this)}onMutationUpdate(e){this.#i(),this.#s(e)}getCurrentResult(){return this.#e}reset(){this.#r?.removeObserver(this),this.#r=void 0,this.#i(),this.#s()}mutate(e,t){return this.#n=t,this.#r?.removeObserver(this),this.#r=this.#t.getMutationCache().build(this.#t,this.options),this.#r.addObserver(this),this.#r.execute(e)}#i(){const e=this.#r?.state??Kt();this.#e={...e,isPending:e.status==="pending",isSuccess:e.status==="success",isError:e.status==="error",isIdle:e.status==="idle",mutate:this.mutate,reset:this.reset}}#s(e){re.batch(()=>{if(this.#n&&this.hasListeners()){const t=this.#e.variables,r=this.#e.context,n={client:this.#t,meta:this.options.meta,mutationKey:this.options.mutationKey};e?.type==="success"?(this.#n.onSuccess?.(e.data,t,r,n),this.#n.onSettled?.(e.data,null,t,r,n)):e?.type==="error"&&(this.#n.onError?.(e.error,t,r,n),this.#n.onSettled?.(void 0,e.error,t,r,n))}this.listeners.forEach(t=>{t(this.#e)})})}},$t=R.createContext(void 0),qe=e=>{const t=R.useContext($t);if(e)return e;if(!t)throw new Error("No QueryClient set, use QueryClientProvider to set one");return t},He=R.createContext(!1),zt=()=>R.useContext(He);He.Provider;function Gt(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var Jt=R.createContext(Gt()),Xt=()=>R.useContext(Jt),Wt=(e,t)=>{(e.suspense||e.throwOnError||e.experimental_prefetchInRender)&&(t.isReset()||(e.retryOnMount=!1))},Yt=e=>{R.useEffect(()=>{e.clearReset()},[e])},Zt=({result:e,errorResetBoundary:t,throwOnError:r,query:n,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&n&&(i&&e.data===void 0||Me(r,[e.error,n])),er=e=>{if(e.suspense){const r=i=>i==="static"?i:Math.max(i??1e3,1e3),n=e.staleTime;e.staleTime=typeof n=="function"?(...i)=>r(n(...i)):r(n),typeof e.gcTime=="number"&&(e.gcTime=Math.max(e.gcTime,1e3))}},tr=(e,t)=>e.isLoading&&e.isFetching&&!t,rr=(e,t)=>e?.suspense&&t.isPending,Be=(e,t,r)=>t.fetchOptimistic(e).catch(()=>{r.clearReset()});function Ke(e,t,r){if(process.env.NODE_ENV!=="production"&&(typeof e!="object"||Array.isArray(e)))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=zt(),i=Xt(),s=qe(r),a=s.defaultQueryOptions(e);s.getDefaultOptions().queries?._experimental_beforeQuery?.(a),process.env.NODE_ENV!=="production"&&(a.queryFn||console.error(`[${a.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`)),a._optimisticResults=n?"isRestoring":"optimistic",er(a),Wt(a,i),Yt(i);const l=!s.getQueryCache().get(a.queryHash),[o]=R.useState(()=>new t(s,a)),c=o.getOptimisticResult(a),u=!n&&e.subscribed!==!1;if(R.useSyncExternalStore(R.useCallback(f=>{const h=u?o.subscribe(re.batchCalls(f)):ee;return o.updateResult(),h},[o,u]),()=>o.getCurrentResult(),()=>o.getCurrentResult()),R.useEffect(()=>{o.setOptions(a)},[a,o]),rr(a,c))throw Be(a,o,i);if(Zt({result:c,errorResetBoundary:i,throwOnError:a.throwOnError,query:s.getQueryCache().get(a.queryHash),suspense:a.suspense}))throw c.error;return s.getDefaultOptions().queries?._experimental_afterQuery?.(a,c),a.experimental_prefetchInRender&&!V&&tr(c,n)&&(l?Be(a,o,i):s.getQueryCache().get(a.queryHash)?.promise)?.catch(ee).finally(()=>{o.updateResult()}),a.notifyOnChangeProps?c:o.trackResult(c)}function nr(e,t){return Ke(e,De,t)}function he(e,t){const r=qe(t),[n]=R.useState(()=>new Vt(r,e));R.useEffect(()=>{n.setOptions(e)},[n,e]);const i=R.useSyncExternalStore(R.useCallback(a=>n.subscribe(re.batchCalls(a)),[n]),()=>n.getCurrentResult(),()=>n.getCurrentResult()),s=R.useCallback((a,l)=>{n.mutate(a,l).catch(ee)},[n]);if(i.error&&Me(n.options.throwOnError,[i.error]))throw i.error;return{...i,mutate:s,mutateAsync:i.mutate}}function ir(e,t){return Ke(e,Bt,t)}var de=function(e,t){return de=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(r[i]=n[i])},de(e,t)};function pe(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");de(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}var z=function(){return z=Object.assign||function(t){for(var r,n=1,i=arguments.length;n<i;n++){r=arguments[n];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t},z.apply(this,arguments)};function sr(e,t,r,n){function i(s){return s instanceof r?s:new r(function(a){a(s)})}return new(r||(r=Promise))(function(s,a){function l(u){try{c(n.next(u))}catch(f){a(f)}}function o(u){try{c(n.throw(u))}catch(f){a(f)}}function c(u){u.done?s(u.value):i(u.value).then(l,o)}c((n=n.apply(e,t||[])).next())})}function Ve(e,t){var r={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,i,s,a=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return a.next=l(0),a.throw=l(1),a.return=l(2),typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function l(c){return function(u){return o([c,u])}}function o(c){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(r=0)),r;)try{if(n=1,i&&(s=c[0]&2?i.return:c[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,c[1])).done)return s;switch(i=0,s&&(c=[c[0]&2,s.value]),c[0]){case 0:case 1:s=c;break;case 4:return r.label++,{value:c[1],done:!1};case 5:r.label++,i=c[1],c=[0];continue;case 7:c=r.ops.pop(),r.trys.pop();continue;default:if(s=r.trys,!(s=s.length>0&&s[s.length-1])&&(c[0]===6||c[0]===2)){r=0;continue}if(c[0]===3&&(!s||c[1]>s[0]&&c[1]<s[3])){r.label=c[1];break}if(c[0]===6&&r.label<s[1]){r.label=s[1],s=c;break}if(s&&r.label<s[2]){r.label=s[2],r.ops.push(c);break}s[2]&&r.ops.pop(),r.trys.pop();continue}c=t.call(e,r)}catch(u){c=[6,u],i=0}finally{n=s=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}function G(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function J(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var n=r.call(e),i,s=[],a;try{for(;(t===void 0||t-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(l){a={error:l}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(a)throw a.error}}return s}function ne(e,t,r){if(r||arguments.length===2)for(var n=0,i=t.length,s;n<i;n++)(s||!(n in t))&&(s||(s=Array.prototype.slice.call(t,0,n)),s[n]=t[n]);return e.concat(s||Array.prototype.slice.call(t))}function q(e){return this instanceof q?(this.v=e,this):new q(e)}function or(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),i,s=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),l("next"),l("throw"),l("return",a),i[Symbol.asyncIterator]=function(){return this},i;function a(d){return function(y){return Promise.resolve(y).then(d,f)}}function l(d,y){n[d]&&(i[d]=function(p){return new Promise(function(S,g){s.push([d,p,S,g])>1||o(d,p)})},y&&(i[d]=y(i[d])))}function o(d,y){try{c(n[d](y))}catch(p){h(s[0][3],p)}}function c(d){d.value instanceof q?Promise.resolve(d.value.v).then(u,f):h(s[0][2],d)}function u(d){o("next",d)}function f(d){o("throw",d)}function h(d,y){d(y),s.shift(),s.length&&o(s[0][0],s[0][1])}}function ar(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof G=="function"?G(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(s){r[s]=e[s]&&function(a){return new Promise(function(l,o){a=e[s](a),i(l,o,a.done,a.value)})}}function i(s,a,l,o){Promise.resolve(o).then(function(c){s({value:c,done:l})},a)}}typeof SuppressedError=="function"&&SuppressedError;function b(e){return typeof e=="function"}function ye(e){var t=function(n){Error.call(n),n.stack=new Error().stack},r=e(t);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var ve=ye(function(e){return function(r){e(this),this.message=r?r.length+` errors occurred during unsubscription:
1
+ (function(P,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("@tanstack/react-query"),require("rxjs"),require("@leancodepl/validation"),require("@leancodepl/utils")):typeof define=="function"&&define.amd?define(["exports","@tanstack/react-query","rxjs","@leancodepl/validation","@leancodepl/utils"],k):(P=typeof globalThis<"u"?globalThis:P||self,k(P["@leancodepl/react-query-cqrs-client"]={},P.reactQuery,P.rxjs,P.validation,P.utils))})(this,(function(P,k,A,Ae,ge){"use strict";var _=function(e,t){return _=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(r[i]=n[i])},_(e,t)};function M(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");_(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}var D=function(){return D=Object.assign||function(t){for(var r,n=1,i=arguments.length;n<i;n++){r=arguments[n];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o])}return t},D.apply(this,arguments)};function Oe(e,t,r,n){function i(o){return o instanceof r?o:new r(function(u){u(o)})}return new(r||(r=Promise))(function(o,u){function l(c){try{s(n.next(c))}catch(f){u(f)}}function a(c){try{s(n.throw(c))}catch(f){u(f)}}function s(c){c.done?o(c.value):i(c.value).then(l,a)}s((n=n.apply(e,t||[])).next())})}function ee(e,t){var r={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},n,i,o,u=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return u.next=l(0),u.throw=l(1),u.return=l(2),typeof Symbol=="function"&&(u[Symbol.iterator]=function(){return this}),u;function l(s){return function(c){return a([s,c])}}function a(s){if(n)throw new TypeError("Generator is already executing.");for(;u&&(u=0,s[0]&&(r=0)),r;)try{if(n=1,i&&(o=s[0]&2?i.return:s[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,s[1])).done)return o;switch(i=0,o&&(s=[s[0]&2,o.value]),s[0]){case 0:case 1:o=s;break;case 4:return r.label++,{value:s[1],done:!1};case 5:r.label++,i=s[1],s=[0];continue;case 7:s=r.ops.pop(),r.trys.pop();continue;default:if(o=r.trys,!(o=o.length>0&&o[o.length-1])&&(s[0]===6||s[0]===2)){r=0;continue}if(s[0]===3&&(!o||s[1]>o[0]&&s[1]<o[3])){r.label=s[1];break}if(s[0]===6&&r.label<o[1]){r.label=o[1],o=s;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(s);break}o[2]&&r.ops.pop(),r.trys.pop();continue}s=t.call(e,r)}catch(c){s=[6,c],i=0}finally{n=o=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}function U(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function V(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var n=r.call(e),i,o=[],u;try{for(;(t===void 0||t-- >0)&&!(i=n.next()).done;)o.push(i.value)}catch(l){u={error:l}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(u)throw u.error}}return o}function B(e,t,r){if(r||arguments.length===2)for(var n=0,i=t.length,o;n<i;n++)(o||!(n in t))&&(o||(o=Array.prototype.slice.call(t,0,n)),o[n]=t[n]);return e.concat(o||Array.prototype.slice.call(t))}function L(e){return this instanceof L?(this.v=e,this):new L(e)}function xe(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),i,o=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),l("next"),l("throw"),l("return",u),i[Symbol.asyncIterator]=function(){return this},i;function u(p){return function(m){return Promise.resolve(m).then(p,f)}}function l(p,m){n[p]&&(i[p]=function(y){return new Promise(function(x,S){o.push([p,y,x,S])>1||a(p,y)})},m&&(i[p]=m(i[p])))}function a(p,m){try{s(n[p](m))}catch(y){d(o[0][3],y)}}function s(p){p.value instanceof L?Promise.resolve(p.value.v).then(c,f):d(o[0][2],p)}function c(p){a("next",p)}function f(p){a("throw",p)}function d(p,m){p(m),o.shift(),o.length&&a(o[0][0],o[0][1])}}function Pe(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof U=="function"?U(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=e[o]&&function(u){return new Promise(function(l,a){u=e[o](u),i(l,a,u.done,u.value)})}}function i(o,u,l,a){Promise.resolve(a).then(function(s){o({value:s,done:l})},u)}}typeof SuppressedError=="function"&&SuppressedError;function T(e){return typeof e=="function"}function ke(e){return T(e?.lift)}function te(e){return function(t){if(ke(t))return t.lift(function(r){try{return e(r,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function re(e){var t=function(n){Error.call(n),n.stack=new Error().stack},r=e(t);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var G=re(function(e){return function(r){e(this),this.message=r?r.length+` errors occurred during unsubscription:
2
2
  `+r.map(function(n,i){return i+1+") "+n.toString()}).join(`
3
- `):"",this.name="UnsubscriptionError",this.errors=r}});function $e(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var me=(function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,r,n,i,s;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var l=G(a),o=l.next();!o.done;o=l.next()){var c=o.value;c.remove(this)}}catch(p){t={error:p}}finally{try{o&&!o.done&&(r=l.return)&&r.call(l)}finally{if(t)throw t.error}}else a.remove(this);var u=this.initialTeardown;if(b(u))try{u()}catch(p){s=p instanceof ve?p.errors:[p]}var f=this._finalizers;if(f){this._finalizers=null;try{for(var h=G(f),d=h.next();!d.done;d=h.next()){var y=d.value;try{Ge(y)}catch(p){s=s??[],p instanceof ve?s=ne(ne([],J(s)),J(p.errors)):s.push(p)}}}catch(p){n={error:p}}finally{try{d&&!d.done&&(i=h.return)&&i.call(h)}finally{if(n)throw n.error}}}if(s)throw new ve(s)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)Ge(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(t)}},e.prototype._hasParent=function(t){var r=this._parentage;return r===t||Array.isArray(r)&&r.includes(t)},e.prototype._addParent=function(t){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(t),r):r?[r,t]:t},e.prototype._removeParent=function(t){var r=this._parentage;r===t?this._parentage=null:Array.isArray(r)&&$e(r,t)},e.prototype.remove=function(t){var r=this._finalizers;r&&$e(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=(function(){var t=new e;return t.closed=!0,t})(),e})();me.EMPTY;function ze(e){return e instanceof me||e&&"closed"in e&&b(e.remove)&&b(e.add)&&b(e.unsubscribe)}function Ge(e){b(e)?e():e.unsubscribe()}var ur={Promise:void 0},cr={setTimeout:function(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];return setTimeout.apply(void 0,ne([e,t],J(r)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function Je(e){cr.setTimeout(function(){throw e})}function Xe(){}function lr(e){e()}var be=(function(e){pe(t,e);function t(r){var n=e.call(this)||this;return n.isStopped=!1,r?(n.destination=r,ze(r)&&r.add(n)):n.destination=dr,n}return t.create=function(r,n,i){return new ie(r,n,i)},t.prototype.next=function(r){this.isStopped||this._next(r)},t.prototype.error=function(r){this.isStopped||(this.isStopped=!0,this._error(r))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(r){this.destination.next(r)},t.prototype._error=function(r){try{this.destination.error(r)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(me),fr=(function(){function e(t){this.partialObserver=t}return e.prototype.next=function(t){var r=this.partialObserver;if(r.next)try{r.next(t)}catch(n){se(n)}},e.prototype.error=function(t){var r=this.partialObserver;if(r.error)try{r.error(t)}catch(n){se(n)}else se(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(r){se(r)}},e})(),ie=(function(e){pe(t,e);function t(r,n,i){var s=e.call(this)||this,a;return b(r)||!r?a={next:r??void 0,error:n??void 0,complete:i??void 0}:a=r,s.destination=new fr(a),s}return t})(be);function se(e){Je(e)}function hr(e){throw e}var dr={closed:!0,next:Xe,error:hr,complete:Xe},ge=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function pr(e){return e}function yr(e){return e.length===0?pr:e.length===1?e[0]:function(r){return e.reduce(function(n,i){return i(n)},r)}}var x=(function(){function e(t){t&&(this._subscribe=t)}return e.prototype.lift=function(t){var r=new e;return r.source=this,r.operator=t,r},e.prototype.subscribe=function(t,r,n){var i=this,s=mr(t)?t:new ie(t,r,n);return lr(function(){var a=i,l=a.operator,o=a.source;s.add(l?l.call(s,o):o?i._subscribe(s):i._trySubscribe(s))}),s},e.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(r){t.error(r)}},e.prototype.forEach=function(t,r){var n=this;return r=We(r),new r(function(i,s){var a=new ie({next:function(l){try{t(l)}catch(o){s(o),a.unsubscribe()}},error:s,complete:i});n.subscribe(a)})},e.prototype._subscribe=function(t){var r;return(r=this.source)===null||r===void 0?void 0:r.subscribe(t)},e.prototype[ge]=function(){return this},e.prototype.pipe=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return yr(t)(this)},e.prototype.toPromise=function(t){var r=this;return t=We(t),new t(function(n,i){var s;r.subscribe(function(a){return s=a},function(a){return i(a)},function(){return n(s)})})},e.create=function(t){return new e(t)},e})();function We(e){var t;return(t=e??ur.Promise)!==null&&t!==void 0?t:Promise}function vr(e){return e&&b(e.next)&&b(e.error)&&b(e.complete)}function mr(e){return e&&e instanceof be||vr(e)&&ze(e)}function br(e){return b(e?.lift)}function X(e){return function(t){if(br(t))return t.lift(function(r){try{return e(r,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function H(e,t,r,n,i){return new gr(e,t,r,n,i)}var gr=(function(e){pe(t,e);function t(r,n,i,s,a,l){var o=e.call(this,r)||this;return o.onFinalize=a,o.shouldUnsubscribe=l,o._next=n?function(c){try{n(c)}catch(u){r.error(u)}}:e.prototype._next,o._error=s?function(c){try{s(c)}catch(u){r.error(u)}finally{this.unsubscribe()}}:e.prototype._error,o._complete=i?function(){try{i()}catch(c){r.error(c)}finally{this.unsubscribe()}}:e.prototype._complete,o}return t.prototype.unsubscribe=function(){var r;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;e.prototype.unsubscribe.call(this),!n&&((r=this.onFinalize)===null||r===void 0||r.call(this))}},t})(be);function wr(e){return e&&b(e.schedule)}function Er(e){return e[e.length-1]}function Sr(e){return wr(Er(e))?e.pop():void 0}var we=(function(e){return e&&typeof e.length=="number"&&typeof e!="function"});function Ye(e){return b(e?.then)}function Ze(e){return b(e[ge])}function et(e){return Symbol.asyncIterator&&b(e?.[Symbol.asyncIterator])}function tt(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Or(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var rt=Or();function nt(e){return b(e?.[rt])}function it(e){return or(this,arguments,function(){var r,n,i,s;return Ve(this,function(a){switch(a.label){case 0:r=e.getReader(),a.label=1;case 1:a.trys.push([1,,9,10]),a.label=2;case 2:return[4,q(r.read())];case 3:return n=a.sent(),i=n.value,s=n.done,s?[4,q(void 0)]:[3,5];case 4:return[2,a.sent()];case 5:return[4,q(i)];case 6:return[4,a.sent()];case 7:return a.sent(),[3,2];case 8:return[3,10];case 9:return r.releaseLock(),[7];case 10:return[2]}})})}function st(e){return b(e?.getReader)}function j(e){if(e instanceof x)return e;if(e!=null){if(Ze(e))return Pr(e);if(we(e))return Rr(e);if(Ye(e))return Tr(e);if(et(e))return ot(e);if(nt(e))return xr(e);if(st(e))return Ir(e)}throw tt(e)}function Pr(e){return new x(function(t){var r=e[ge]();if(b(r.subscribe))return r.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Rr(e){return new x(function(t){for(var r=0;r<e.length&&!t.closed;r++)t.next(e[r]);t.complete()})}function Tr(e){return new x(function(t){e.then(function(r){t.closed||(t.next(r),t.complete())},function(r){return t.error(r)}).then(null,Je)})}function xr(e){return new x(function(t){var r,n;try{for(var i=G(e),s=i.next();!s.done;s=i.next()){var a=s.value;if(t.next(a),t.closed)return}}catch(l){r={error:l}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}t.complete()})}function ot(e){return new x(function(t){Ar(e,t).catch(function(r){return t.error(r)})})}function Ir(e){return ot(it(e))}function Ar(e,t){var r,n,i,s;return sr(this,void 0,void 0,function(){var a,l;return Ve(this,function(o){switch(o.label){case 0:o.trys.push([0,5,6,11]),r=ar(e),o.label=1;case 1:return[4,r.next()];case 2:if(n=o.sent(),!!n.done)return[3,4];if(a=n.value,t.next(a),t.closed)return[2];o.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return l=o.sent(),i={error:l},[3,11];case 6:return o.trys.push([6,,9,10]),n&&!n.done&&(s=r.return)?[4,s.call(r)]:[3,8];case 7:o.sent(),o.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function L(e,t,r,n,i){n===void 0&&(n=0),i===void 0&&(i=!1);var s=t.schedule(function(){r(),i?e.add(this.schedule(null,n)):this.unsubscribe()},n);if(e.add(s),!i)return s}function at(e,t){return t===void 0&&(t=0),X(function(r,n){r.subscribe(H(n,function(i){return L(n,e,function(){return n.next(i)},t)},function(){return L(n,e,function(){return n.complete()},t)},function(i){return L(n,e,function(){return n.error(i)},t)}))})}function ut(e,t){return t===void 0&&(t=0),X(function(r,n){n.add(e.schedule(function(){return r.subscribe(n)},t))})}function Fr(e,t){return j(e).pipe(ut(t),at(t))}function jr(e,t){return j(e).pipe(ut(t),at(t))}function kr(e,t){return new x(function(r){var n=0;return t.schedule(function(){n===e.length?r.complete():(r.next(e[n++]),r.closed||this.schedule())})})}function Cr(e,t){return new x(function(r){var n;return L(r,t,function(){n=e[rt](),L(r,t,function(){var i,s,a;try{i=n.next(),s=i.value,a=i.done}catch(l){r.error(l);return}a?r.complete():r.next(s)},0,!0)}),function(){return b(n?.return)&&n.return()}})}function ct(e,t){if(!e)throw new Error("Iterable cannot be null");return new x(function(r){L(r,t,function(){var n=e[Symbol.asyncIterator]();L(r,t,function(){n.next().then(function(i){i.done?r.complete():r.next(i.value)})},0,!0)})})}function Mr(e,t){return ct(it(e),t)}function Lr(e,t){if(e!=null){if(Ze(e))return Fr(e,t);if(we(e))return kr(e,t);if(Ye(e))return jr(e,t);if(et(e))return ct(e,t);if(nt(e))return Cr(e,t);if(st(e))return Mr(e,t)}throw tt(e)}function lt(e,t){return t?Lr(e,t):j(e)}function Dr(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=Sr(e);return lt(e,r)}function ft(e,t){var r=b(e)?e:function(){return e},n=function(i){return i.error(r())};return new x(n)}var Qr=ye(function(e){return function(){e(this),this.name="EmptyError",this.message="no elements in sequence"}});function D(e,t){return new Promise(function(r,n){var i=new ie({next:function(s){r(s),i.unsubscribe()},error:n,complete:function(){n(new Qr)}});e.subscribe(i)})}function Q(e,t){return X(function(r,n){var i=0;r.subscribe(H(n,function(s){n.next(e.call(t,s,i++))}))})}var Nr=Array.isArray;function Ur(e,t){return Nr(t)?e.apply(void 0,ne([],J(t))):e(t)}function _r(e){return Q(function(t){return Ur(e,t)})}function qr(e,t,r,n,i,s,a,l){var o=[],c=0,u=0,f=!1,h=function(){f&&!o.length&&!c&&t.complete()},d=function(p){return c<n?y(p):o.push(p)},y=function(p){c++;var S=!1;j(r(p,u++)).subscribe(H(t,function(g){t.next(g)},function(){S=!0},void 0,function(){if(S)try{c--;for(var g=function(){var P=o.shift();a||y(P)};o.length&&c<n;)g();h()}catch(P){t.error(P)}}))};return e.subscribe(H(t,d,function(){f=!0,h()})),function(){}}function oe(e,t,r){return r===void 0&&(r=1/0),b(t)?oe(function(n,i){return Q(function(s,a){return t(n,s,i,a)})(j(e(n,i)))},r):(typeof t=="number"&&(r=t),X(function(n,i){return qr(n,i,e,r)}))}var Hr=["addListener","removeListener"],Br=["addEventListener","removeEventListener"],Kr=["on","off"];function Ee(e,t,r,n){if(b(r)&&(n=r,r=void 0),n)return Ee(e,t,r).pipe(_r(n));var i=J(zr(e)?Br.map(function(l){return function(o){return e[l](t,o,r)}}):Vr(e)?Hr.map(ht(e,t)):$r(e)?Kr.map(ht(e,t)):[],2),s=i[0],a=i[1];if(!s&&we(e))return oe(function(l){return Ee(l,t,r)})(j(e));if(!s)throw new TypeError("Invalid event target");return new x(function(l){var o=function(){for(var c=[],u=0;u<arguments.length;u++)c[u]=arguments[u];return l.next(1<c.length?c:c[0])};return s(o),function(){return a(o)}})}function ht(e,t){return function(r){return function(n){return e[r](t,n)}}}function Vr(e){return b(e.addListener)&&b(e.removeListener)}function $r(e){return b(e.on)&&b(e.off)}function zr(e){return b(e.addEventListener)&&b(e.removeEventListener)}var Gr=Array.isArray;function Jr(e){return e.length===1&&Gr(e[0])?e[0]:e}function Xr(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e=Jr(e),e.length===1?j(e[0]):new x(Wr(e))}function Wr(e){return function(t){for(var r=[],n=function(s){r.push(j(e[s]).subscribe(H(t,function(a){if(r){for(var l=0;l<r.length;l++)l!==s&&r[l].unsubscribe();r=null}t.next(a)})))},i=0;r&&!t.closed&&i<e.length;i++)n(i)}}function Se(e){return X(function(t,r){var n=null,i=!1,s;n=t.subscribe(H(r,void 0,void 0,function(a){s=j(e(a,Se(e)(t))),n?(n.unsubscribe(),n=null,s.subscribe(r)):i=!0})),i&&(n.unsubscribe(),n=null,s.subscribe(r))})}function dt(e){switch(e.responseType){case"json":{if("response"in e)return e.response;var t=e;return JSON.parse(t.responseText)}case"document":return e.responseXML;default:{if("response"in e)return e.response;var t=e;return t.responseText}}}var Yr=(function(){function e(t,r,n,i){i===void 0&&(i="download_load"),this.originalEvent=t,this.xhr=r,this.request=n,this.type=i;var s=r.status,a=r.responseType;this.status=s??0,this.responseType=a??"";var l=r.getAllResponseHeaders();this.responseHeaders=l?l.split(`
4
- `).reduce(function(u,f){var h=f.indexOf(": ");return u[f.slice(0,h)]=f.slice(h+2),u},{}):{},this.response=dt(r);var o=t.loaded,c=t.total;this.loaded=o,this.total=c}return e})(),W=ye(function(e){return function(r,n,i){this.message=r,this.name="AjaxError",this.xhr=n,this.request=i,this.status=n.status,this.responseType=n.responseType;var s;try{s=dt(n)}catch{s=n.responseText}this.response=s}}),Zr=(function(){function e(t,r){return W.call(this,"ajax timeout",t,r),this.name="AjaxTimeoutError",this}return e.prototype=Object.create(W.prototype),e})();function en(e,t){return N({method:"GET",url:e,headers:t})}function tn(e,t,r){return N({method:"POST",url:e,body:t,headers:r})}function rn(e,t){return N({method:"DELETE",url:e,headers:t})}function nn(e,t,r){return N({method:"PUT",url:e,body:t,headers:r})}function sn(e,t,r){return N({method:"PATCH",url:e,body:t,headers:r})}var on=Q(function(e){return e.response});function an(e,t){return on(N({method:"GET",url:e,headers:t}))}var N=(function(){var e=function(t){var r=typeof t=="string"?{url:t}:t;return cn(r)};return e.get=en,e.post=tn,e.delete=rn,e.put=nn,e.patch=sn,e.getJSON=an,e})(),un="upload",pt="download",Oe="loadstart",Pe="progress",yt="load";function cn(e){return new x(function(t){var r,n,i=z({async:!0,crossDomain:!1,withCredentials:!1,method:"GET",timeout:0,responseType:"json"},e),s=i.queryParams,a=i.body,l=i.headers,o=i.url;if(!o)throw new TypeError("url is required");if(s){var c;if(o.includes("?")){var u=o.split("?");if(2<u.length)throw new TypeError("invalid url");c=new URLSearchParams(u[1]),new URLSearchParams(s).forEach(function(E,O){return c.set(O,E)}),o=u[0]+"?"+c}else c=new URLSearchParams(s),o=o+"?"+c}var f={};if(l)for(var h in l)l.hasOwnProperty(h)&&(f[h.toLowerCase()]=l[h]);var d=i.crossDomain;!d&&!("x-requested-with"in f)&&(f["x-requested-with"]="XMLHttpRequest");var y=i.withCredentials,p=i.xsrfCookieName,S=i.xsrfHeaderName;if((y||!d)&&p&&S){var g=(n=(r=document?.cookie.match(new RegExp("(^|;\\s*)("+p+")=([^;]*)")))===null||r===void 0?void 0:r.pop())!==null&&n!==void 0?n:"";g&&(f[S]=g)}var P=ln(a,f),w=z(z({},i),{url:o,headers:f,body:P}),v;v=e.createXHR?e.createXHR():new XMLHttpRequest;{var m=e.progressSubscriber,C=e.includeDownloadProgress,A=C===void 0?!1:C,T=e.includeUploadProgress,B=T===void 0?!1:T,k=function(E,O){v.addEventListener(E,function(){var I,_=O();(I=m?.error)===null||I===void 0||I.call(m,_),t.error(_)})};k("timeout",function(){return new Zr(v,w)}),k("abort",function(){return new W("aborted",v,w)});var U=function(E,O){return new Yr(O,v,w,E+"_"+O.type)},mt=function(E,O,I){E.addEventListener(O,function(_){t.next(U(I,_))})};B&&[Oe,Pe,yt].forEach(function(E){return mt(v.upload,E,un)}),m&&[Oe,Pe].forEach(function(E){return v.upload.addEventListener(E,function(O){var I;return(I=m?.next)===null||I===void 0?void 0:I.call(m,O)})}),A&&[Oe,Pe].forEach(function(E){return mt(v,E,pt)});var bt=function(E){var O="ajax error"+(E?" "+E:"");t.error(new W(O,v,w))};v.addEventListener("error",function(E){var O;(O=m?.error)===null||O===void 0||O.call(m,E),bt()}),v.addEventListener(yt,function(E){var O,I,_=v.status;if(_<400){(O=m?.complete)===null||O===void 0||O.call(m);var Et=void 0;try{Et=U(pt,E)}catch(Rn){t.error(Rn);return}t.next(Et),t.complete()}else(I=m?.error)===null||I===void 0||I.call(m,E),bt(_)})}var gt=w.user,wt=w.method,xe=w.async;gt?v.open(wt,o,xe,gt,w.password):v.open(wt,o,xe),xe&&(v.timeout=w.timeout,v.responseType=w.responseType),"withCredentials"in v&&(v.withCredentials=w.withCredentials);for(var h in f)f.hasOwnProperty(h)&&v.setRequestHeader(h,f[h]);return P?v.send(P):v.send(),function(){v&&v.readyState!==4&&v.abort()}})}function ln(e,t){var r;if(!e||typeof e=="string"||vn(e)||mn(e)||hn(e)||dn(e)||pn(e)||bn(e))return e;if(yn(e))return e.buffer;if(typeof e=="object")return t["content-type"]=(r=t["content-type"])!==null&&r!==void 0?r:"application/json;charset=utf-8",JSON.stringify(e);throw new TypeError("Unknown body type")}var fn=Object.prototype.toString;function Re(e,t){return fn.call(e)==="[object "+t+"]"}function hn(e){return Re(e,"ArrayBuffer")}function dn(e){return Re(e,"File")}function pn(e){return Re(e,"Blob")}function yn(e){return typeof ArrayBuffer<"u"&&ArrayBuffer.isView(e)}function vn(e){return typeof FormData<"u"&&e instanceof FormData}function mn(e){return typeof URLSearchParams<"u"&&e instanceof URLSearchParams}function bn(e){return typeof ReadableStream<"u"&&e instanceof ReadableStream}function Te(e,t,r=[]){return{handle:(n,i)=>{let s;for(const l of Array.isArray(n)?n:[n]){const o=e.find(c=>c.ErrorCode===t[l]);if(o){s=i(l,o);break}}let a=r;return s!==void 0&&(a=[...a,s]),Te(e,t,a)},handleAll:(n,i)=>{let s;const a=(Array.isArray(n)?n:[n]).reduce((o,c)=>{const u=e.filter(f=>f.ErrorCode===t[c]);return u.length===0?o:[...o,{errorName:c,errors:u}]},[]);a.length>0&&(s=i(a));let l=r;return s!==void 0&&(l=[...l,s]),Te(e,t,l)},check:(n=>{if(n)return r.reduce(n.reducer,n.initialValue)})}}function gn(e,t){const r={...t,success:-1,failure:-2},n=e.isSuccess?e.result.WasSuccessful?[{ErrorMessage:"",PropertyName:"",ErrorCode:-1}]:e.result.ValidationErrors:[{ErrorMessage:"",PropertyName:"",ErrorCode:-2}];return Te(n,r)}function wn(e){return e?.invalidateToken?t=>t.pipe(Se(r=>(r.status===401&&e.invalidateToken?.(),ft(()=>r)))):t=>t}process.env.NODE_ENV;function En(e,t){return e.length===0?"":t(e[0])+e.slice(1)}function Sn(e){return En(e,t=>t.toLowerCase())}function On(e){return JSON.parse(e,(t,r)=>{if(!(r===null&&t!==""))return!r||Array.isArray(r)||typeof r!="object"?r:Object.fromEntries(Object.entries(r).map(([n,i])=>[Sn(n),i]))})}function vt(){return e=>e.pipe(Q(On))}function Pn({cqrsEndpoint:e,queryClient:t,tokenProvider:r,ajaxOptions:n,tokenHeader:i="Authorization"}){function s(a,l={}){const o=(f,h)=>N({...n,...l,headers:{[i]:h,"Content-Type":"application/json"},url:`${e}/${a}`,method:"POST",body:f,withCredentials:n?.withCredentials??!0}),c=r?.getToken,u=(f,h)=>o(f,h).pipe(wn(r),Q(d=>d.response));return c?f=>lt(c()).pipe(oe(h=>u(f,h))):f=>u(f)}return{createQuery(a){const l=s(`query/${a}`,{responseType:"text"});function o(u,f){return nr({queryKey:o.key(u),queryFn:h=>D(o.fetcher(u,h)),...f},t)}o.type=a,o.fetcher=(u,f)=>Xr([l(u).pipe(vt()),...f?.signal?[Ee(f.signal,"abort").pipe(oe(()=>ft(()=>new Error("Query aborted"))))]:[]]),o.fetch=(u,f)=>t.fetchQuery({queryKey:o.key(u),queryFn:h=>D(o.fetcher(u,h)),...f}),o.lazy=function(u={}){return he({mutationKey:[a],mutationFn:f=>D(o.fetcher(f)),...u},t)},o.infinite=function(u,f){return ir({queryKey:[a],queryFn:h=>D(o.fetcher(h.pageParam,h)),initialPageParam:u,...f},t)},o.key=u=>[a,u];function c(u,f){const h=Array.isArray(u)?u:o.key(u);return t.setQueryData(h,f)}return o.setQueryData=c,o.setQueriesData=(u,f)=>t.setQueriesData({queryKey:o.key(u)},f),o.getQueryData=u=>t.getQueryData(o.key(u)),o.getQueriesData=u=>t.getQueriesData({queryKey:o.key(u)}),o.prefetch=(u,f)=>t.prefetchQuery({queryKey:o.key(u),queryFn:h=>D(o.fetcher(u,h)),...f}),o.invalidate=u=>t.invalidateQueries({queryKey:o.key(u)}),o.cancel=u=>t.cancelQueries({queryKey:o.key(u)}),o.optimisticUpdate=async(u,f={})=>{await o.cancel(f);const h=o.getQueriesData(f);return o.setQueriesData(f,u),()=>h.forEach(([d,y])=>t.setQueryData(d,y))},o},createOperation(a){const l=s(`operation/${a}`,{responseType:"text"});function o({onSuccess:c,invalidateQueries:u,...f}={}){return he({mutationKey:o.key,mutationFn:h=>D(o.fetcher(h)),...f,async onSuccess(h,d,y,p){const S=await c?.(h,d,y,p);return u&&await Promise.allSettled(u.map(g=>t.invalidateQueries({queryKey:g}))),S}},t)}return o.type=a,o.key=[o.type],o.fetcher=c=>l(c).pipe(vt()),o},createCommand(a,l){const o=s(`command/${a}`);function c({invalidateQueries:u,handler:f,optimisticUpdate:h,onMutate:d,onError:y,onSettled:p,...S}={}){return he({...S,mutationKey:c.key,mutationFn:g=>D(c.call(g,f)),async onMutate(g,P){const w=await d?.(g,P),v=await Promise.all(h?.(g)??[]);return{...w,revertOptimisticUpdate:()=>v.forEach(m=>m())}},async onError(g,P,w,v){await y?.(g,P,w,v),w?.revertOptimisticUpdate()},async onSettled(g,P,w,v,m){return u&&await Promise.allSettled(u.map(C=>t.invalidateQueries({queryKey:C}))),await p?.(g,P,w,v,m)}},t)}return c.type=a,c.key=[c.type],c.fetcher=o,c.call=(u,f)=>c.fetcher(u).pipe(Q(d=>({isSuccess:!0,result:d})),Se(d=>Dr(c.mapError(d))),Q(d=>{const y=f?c.handleResponse(f,u)(d):d;if(!d.isSuccess||!d.result.WasSuccessful)throw y;return y})),c.mapError=u=>u instanceof W&&u.status===422?{isSuccess:!0,result:u.response}:{isSuccess:!1,error:u},c.handleResponse=(u,f)=>h=>u(gn(h,l),f),c}}}M.mkCqrsClient=Pn,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})}));
3
+ `):"",this.name="UnsubscriptionError",this.errors=r}});function ne(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var K=(function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,r,n,i,o;if(!this.closed){this.closed=!0;var u=this._parentage;if(u)if(this._parentage=null,Array.isArray(u))try{for(var l=U(u),a=l.next();!a.done;a=l.next()){var s=a.value;s.remove(this)}}catch(y){t={error:y}}finally{try{a&&!a.done&&(r=l.return)&&r.call(l)}finally{if(t)throw t.error}}else u.remove(this);var c=this.initialTeardown;if(T(c))try{c()}catch(y){o=y instanceof G?y.errors:[y]}var f=this._finalizers;if(f){this._finalizers=null;try{for(var d=U(f),p=d.next();!p.done;p=d.next()){var m=p.value;try{ie(m)}catch(y){o=o??[],y instanceof G?o=B(B([],V(o)),V(y.errors)):o.push(y)}}}catch(y){n={error:y}}finally{try{p&&!p.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}}if(o)throw new G(o)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)ie(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(t)}},e.prototype._hasParent=function(t){var r=this._parentage;return r===t||Array.isArray(r)&&r.includes(t)},e.prototype._addParent=function(t){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(t),r):r?[r,t]:t},e.prototype._removeParent=function(t){var r=this._parentage;r===t?this._parentage=null:Array.isArray(r)&&ne(r,t)},e.prototype.remove=function(t){var r=this._finalizers;r&&ne(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=(function(){var t=new e;return t.closed=!0,t})(),e})();K.EMPTY;function oe(e){return e instanceof K||e&&"closed"in e&&T(e.remove)&&T(e.add)&&T(e.unsubscribe)}function ie(e){T(e)?e():e.unsubscribe()}var Re={Promise:void 0},Ie={setTimeout:function(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];return setTimeout.apply(void 0,B([e,t],V(r)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function ae(e){Ie.setTimeout(function(){throw e})}function ue(){}function je(e){e()}var $=(function(e){M(t,e);function t(r){var n=e.call(this)||this;return n.isStopped=!1,r?(n.destination=r,oe(r)&&r.add(n)):n.destination=De,n}return t.create=function(r,n,i){return new C(r,n,i)},t.prototype.next=function(r){this.isStopped||this._next(r)},t.prototype.error=function(r){this.isStopped||(this.isStopped=!0,this._error(r))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(r){this.destination.next(r)},t.prototype._error=function(r){try{this.destination.error(r)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(K),Le=(function(){function e(t){this.partialObserver=t}return e.prototype.next=function(t){var r=this.partialObserver;if(r.next)try{r.next(t)}catch(n){Q(n)}},e.prototype.error=function(t){var r=this.partialObserver;if(r.error)try{r.error(t)}catch(n){Q(n)}else Q(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(r){Q(r)}},e})(),C=(function(e){M(t,e);function t(r,n,i){var o=e.call(this)||this,u;return T(r)||!r?u={next:r??void 0,error:n??void 0,complete:i??void 0}:u=r,o.destination=new Le(u),o}return t})($);function Q(e){ae(e)}function Fe(e){throw e}var De={closed:!0,next:ue,error:Fe,complete:ue};function X(e,t,r,n,i){return new Ue(e,t,r,n,i)}var Ue=(function(e){M(t,e);function t(r,n,i,o,u,l){var a=e.call(this,r)||this;return a.onFinalize=u,a.shouldUnsubscribe=l,a._next=n?function(s){try{n(s)}catch(c){r.error(c)}}:e.prototype._next,a._error=o?function(s){try{o(s)}catch(c){r.error(c)}finally{this.unsubscribe()}}:e.prototype._error,a._complete=i?function(){try{i()}catch(s){r.error(s)}finally{this.unsubscribe()}}:e.prototype._complete,a}return t.prototype.unsubscribe=function(){var r;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;e.prototype.unsubscribe.call(this),!n&&((r=this.onFinalize)===null||r===void 0||r.call(this))}},t})($);function F(e,t){return te(function(r,n){var i=0;r.subscribe(X(n,function(o){n.next(e.call(t,o,i++))}))})}var J=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function qe(e){return e}function Qe(e){return e.length===0?qe:e.length===1?e[0]:function(r){return e.reduce(function(n,i){return i(n)},r)}}var R=(function(){function e(t){t&&(this._subscribe=t)}return e.prototype.lift=function(t){var r=new e;return r.source=this,r.operator=t,r},e.prototype.subscribe=function(t,r,n){var i=this,o=_e(t)?t:new C(t,r,n);return je(function(){var u=i,l=u.operator,a=u.source;o.add(l?l.call(o,a):a?i._subscribe(o):i._trySubscribe(o))}),o},e.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(r){t.error(r)}},e.prototype.forEach=function(t,r){var n=this;return r=se(r),new r(function(i,o){var u=new C({next:function(l){try{t(l)}catch(a){o(a),u.unsubscribe()}},error:o,complete:i});n.subscribe(u)})},e.prototype._subscribe=function(t){var r;return(r=this.source)===null||r===void 0?void 0:r.subscribe(t)},e.prototype[J]=function(){return this},e.prototype.pipe=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return Qe(t)(this)},e.prototype.toPromise=function(t){var r=this;return t=se(t),new t(function(n,i){var o;r.subscribe(function(u){return o=u},function(u){return i(u)},function(){return n(o)})})},e.create=function(t){return new e(t)},e})();function se(e){var t;return(t=e??Re.Promise)!==null&&t!==void 0?t:Promise}function He(e){return e&&T(e.next)&&T(e.error)&&T(e.complete)}function _e(e){return e&&e instanceof $||He(e)&&oe(e)}function ce(e){switch(e.responseType){case"json":{if("response"in e)return e.response;var t=e;return JSON.parse(t.responseText)}case"document":return e.responseXML;default:{if("response"in e)return e.response;var t=e;return t.responseText}}}var Me=(function(){function e(t,r,n,i){i===void 0&&(i="download_load"),this.originalEvent=t,this.xhr=r,this.request=n,this.type=i;var o=r.status,u=r.responseType;this.status=o??0,this.responseType=u??"";var l=r.getAllResponseHeaders();this.responseHeaders=l?l.split(`
4
+ `).reduce(function(c,f){var d=f.indexOf(": ");return c[f.slice(0,d)]=f.slice(d+2),c},{}):{},this.response=ce(r);var a=t.loaded,s=t.total;this.loaded=a,this.total=s}return e})(),q=re(function(e){return function(r,n,i){this.message=r,this.name="AjaxError",this.xhr=n,this.request=i,this.status=n.status,this.responseType=n.responseType;var o;try{o=ce(n)}catch{o=n.responseText}this.response=o}}),Ve=(function(){function e(t,r){return q.call(this,"ajax timeout",t,r),this.name="AjaxTimeoutError",this}return e.prototype=Object.create(q.prototype),e})();function Be(e,t){return I({method:"GET",url:e,headers:t})}function Ge(e,t,r){return I({method:"POST",url:e,body:t,headers:r})}function Ke(e,t){return I({method:"DELETE",url:e,headers:t})}function $e(e,t,r){return I({method:"PUT",url:e,body:t,headers:r})}function Ce(e,t,r){return I({method:"PATCH",url:e,body:t,headers:r})}var Xe=F(function(e){return e.response});function Je(e,t){return Xe(I({method:"GET",url:e,headers:t}))}var I=(function(){var e=function(t){var r=typeof t=="string"?{url:t}:t;return Ne(r)};return e.get=Be,e.post=Ge,e.delete=Ke,e.put=$e,e.patch=Ce,e.getJSON=Je,e})(),ze="upload",fe="download",z="loadstart",N="progress",le="load";function Ne(e){return new R(function(t){var r,n,i=D({async:!0,crossDomain:!1,withCredentials:!1,method:"GET",timeout:0,responseType:"json"},e),o=i.queryParams,u=i.body,l=i.headers,a=i.url;if(!a)throw new TypeError("url is required");if(o){var s;if(a.includes("?")){var c=a.split("?");if(2<c.length)throw new TypeError("invalid url");s=new URLSearchParams(c[1]),new URLSearchParams(o).forEach(function(w,b){return s.set(b,w)}),a=c[0]+"?"+s}else s=new URLSearchParams(o),a=a+"?"+s}var f={};if(l)for(var d in l)l.hasOwnProperty(d)&&(f[d.toLowerCase()]=l[d]);var p=i.crossDomain;!p&&!("x-requested-with"in f)&&(f["x-requested-with"]="XMLHttpRequest");var m=i.withCredentials,y=i.xsrfCookieName,x=i.xsrfHeaderName;if((m||!p)&&y&&x){var S=(n=(r=document?.cookie.match(new RegExp("(^|;\\s*)("+y+")=([^;]*)")))===null||r===void 0?void 0:r.pop())!==null&&n!==void 0?n:"";S&&(f[x]=S)}var g=Ye(u,f),E=D(D({},i),{url:a,headers:f,body:g}),h;h=e.createXHR?e.createXHR():new XMLHttpRequest;{var v=e.progressSubscriber,H=e.includeDownloadProgress,xt=H===void 0?!1:H,ye=e.includeUploadProgress,Pt=ye===void 0?!1:ye,ve=function(w,b){h.addEventListener(w,function(){var O,j=b();(O=v?.error)===null||O===void 0||O.call(v,j),t.error(j)})};ve("timeout",function(){return new Ve(h,E)}),ve("abort",function(){return new q("aborted",h,E)});var me=function(w,b){return new Me(b,h,E,w+"_"+b.type)},we=function(w,b,O){w.addEventListener(b,function(j){t.next(me(O,j))})};Pt&&[z,N,le].forEach(function(w){return we(h.upload,w,ze)}),v&&[z,N].forEach(function(w){return h.upload.addEventListener(w,function(b){var O;return(O=v?.next)===null||O===void 0?void 0:O.call(v,b)})}),xt&&[z,N].forEach(function(w){return we(h,w,fe)});var be=function(w){var b="ajax error"+(w?" "+w:"");t.error(new q(b,h,E))};h.addEventListener("error",function(w){var b;(b=v?.error)===null||b===void 0||b.call(v,w),be()}),h.addEventListener(le,function(w){var b,O,j=h.status;if(j<400){(b=v?.complete)===null||b===void 0||b.call(v);var Te=void 0;try{Te=me(fe,w)}catch(kt){t.error(kt);return}t.next(Te),t.complete()}else(O=v?.error)===null||O===void 0||O.call(v,w),be(j)})}var Se=E.user,Ee=E.method,Z=E.async;Se?h.open(Ee,a,Z,Se,E.password):h.open(Ee,a,Z),Z&&(h.timeout=E.timeout,h.responseType=E.responseType),"withCredentials"in h&&(h.withCredentials=E.withCredentials);for(var d in f)f.hasOwnProperty(d)&&h.setRequestHeader(d,f[d]);return g?h.send(g):h.send(),function(){h&&h.readyState!==4&&h.abort()}})}function Ye(e,t){var r;if(!e||typeof e=="string"||nt(e)||ot(e)||Ze(e)||et(e)||tt(e)||it(e))return e;if(rt(e))return e.buffer;if(typeof e=="object")return t["content-type"]=(r=t["content-type"])!==null&&r!==void 0?r:"application/json;charset=utf-8",JSON.stringify(e);throw new TypeError("Unknown body type")}var We=Object.prototype.toString;function Y(e,t){return We.call(e)==="[object "+t+"]"}function Ze(e){return Y(e,"ArrayBuffer")}function et(e){return Y(e,"File")}function tt(e){return Y(e,"Blob")}function rt(e){return typeof ArrayBuffer<"u"&&ArrayBuffer.isView(e)}function nt(e){return typeof FormData<"u"&&e instanceof FormData}function ot(e){return typeof URLSearchParams<"u"&&e instanceof URLSearchParams}function it(e){return typeof ReadableStream<"u"&&e instanceof ReadableStream}var at=(function(e){return e&&typeof e.length=="number"&&typeof e!="function"});function ut(e){return T(e?.then)}function st(e){return T(e[J])}function ct(e){return Symbol.asyncIterator&&T(e?.[Symbol.asyncIterator])}function ft(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function lt(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var dt=lt();function pt(e){return T(e?.[dt])}function ht(e){return xe(this,arguments,function(){var r,n,i,o;return ee(this,function(u){switch(u.label){case 0:r=e.getReader(),u.label=1;case 1:u.trys.push([1,,9,10]),u.label=2;case 2:return[4,L(r.read())];case 3:return n=u.sent(),i=n.value,o=n.done,o?[4,L(void 0)]:[3,5];case 4:return[2,u.sent()];case 5:return[4,L(i)];case 6:return[4,u.sent()];case 7:return u.sent(),[3,2];case 8:return[3,10];case 9:return r.releaseLock(),[7];case 10:return[2]}})})}function yt(e){return T(e?.getReader)}function de(e){if(e instanceof R)return e;if(e!=null){if(st(e))return vt(e);if(at(e))return mt(e);if(ut(e))return wt(e);if(ct(e))return pe(e);if(pt(e))return bt(e);if(yt(e))return St(e)}throw ft(e)}function vt(e){return new R(function(t){var r=e[J]();if(T(r.subscribe))return r.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function mt(e){return new R(function(t){for(var r=0;r<e.length&&!t.closed;r++)t.next(e[r]);t.complete()})}function wt(e){return new R(function(t){e.then(function(r){t.closed||(t.next(r),t.complete())},function(r){return t.error(r)}).then(null,ae)})}function bt(e){return new R(function(t){var r,n;try{for(var i=U(e),o=i.next();!o.done;o=i.next()){var u=o.value;if(t.next(u),t.closed)return}}catch(l){r={error:l}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}t.complete()})}function pe(e){return new R(function(t){Et(e,t).catch(function(r){return t.error(r)})})}function St(e){return pe(ht(e))}function Et(e,t){var r,n,i,o;return Oe(this,void 0,void 0,function(){var u,l;return ee(this,function(a){switch(a.label){case 0:a.trys.push([0,5,6,11]),r=Pe(e),a.label=1;case 1:return[4,r.next()];case 2:if(n=a.sent(),!!n.done)return[3,4];if(u=n.value,t.next(u),t.closed)return[2];a.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return l=a.sent(),i={error:l},[3,11];case 6:return a.trys.push([6,,9,10]),n&&!n.done&&(o=r.return)?[4,o.call(r)]:[3,8];case 7:a.sent(),a.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function Rt(e,t,r,n,i){n===void 0&&(n=0),i===void 0&&(i=!1);var o=t.schedule(function(){r(),i?e.add(this.schedule(null,n)):this.unsubscribe()},n);if(e.add(o),!i)return o}function Tt(e,t,r,n,i,o,u,l){var a=[],s=0,c=0,f=!1,d=function(){f&&!a.length&&!s&&t.complete()},p=function(y){return s<n?m(y):a.push(y)},m=function(y){s++;var x=!1;de(r(y,c++)).subscribe(X(t,function(S){t.next(S)},function(){x=!0},void 0,function(){if(x)try{s--;for(var S=function(){var g=a.shift();u||m(g)};a.length&&s<n;)S();d()}catch(g){t.error(g)}}))};return e.subscribe(X(t,p,function(){f=!0,d()})),function(){}}function W(e,t,r){return r===void 0&&(r=1/0),T(t)?W(function(n,i){return F(function(o,u){return t(n,o,i,u)})(de(e(n,i)))},r):(typeof t=="number"&&(r=t),te(function(n,i){return Tt(n,i,e,r)}))}function At(e){return e?.invalidateToken?t=>t.pipe(A.catchError(r=>(r.status===401&&e.invalidateToken?.(),A.throwError(()=>r)))):t=>t}function gt(e){return JSON.parse(e,(t,r)=>{if(!(r===null&&t!==""))return!r||Array.isArray(r)||typeof r!="object"?r:Object.fromEntries(Object.entries(r).map(([n,i])=>[ge.toLowerFirst(n),i]))})}function he(){return e=>e.pipe(F(gt))}function Ot({cqrsEndpoint:e,queryClient:t,tokenProvider:r,ajaxOptions:n,tokenHeader:i="Authorization"}){function o(u,l={}){const a=(f,d)=>I({...n,...l,headers:{[i]:d,"Content-Type":"application/json"},url:`${e}/${u}`,method:"POST",body:f,withCredentials:n?.withCredentials??!0}),s=r?.getToken,c=(f,d)=>a(f,d).pipe(At(r),F(p=>p.response));return s?f=>A.from(s()).pipe(W(d=>c(f,d))):f=>c(f)}return{createQuery(u){const l=o(`query/${u}`,{responseType:"text"});function a(c,f){return k.useQuery({queryKey:a.key(c),queryFn:d=>A.firstValueFrom(a.fetcher(c,d)),...f},t)}a.type=u,a.fetcher=(c,f)=>A.race([l(c).pipe(he()),...f?.signal?[A.fromEvent(f.signal,"abort").pipe(W(()=>A.throwError(()=>new Error("Query aborted"))))]:[]]),a.fetch=(c,f)=>t.fetchQuery({queryKey:a.key(c),queryFn:d=>A.firstValueFrom(a.fetcher(c,d)),...f}),a.lazy=function(c={}){return k.useMutation({mutationKey:[u],mutationFn:f=>A.firstValueFrom(a.fetcher(f)),...c},t)},a.infinite=function(c,f){return k.useInfiniteQuery({queryKey:[u],queryFn:d=>A.firstValueFrom(a.fetcher(d.pageParam,d)),initialPageParam:c,...f},t)},a.key=c=>[u,c];function s(c,f){const d=Array.isArray(c)?c:a.key(c);return t.setQueryData(d,f)}return a.setQueryData=s,a.setQueriesData=(c,f)=>t.setQueriesData({queryKey:a.key(c)},f),a.getQueryData=c=>t.getQueryData(a.key(c)),a.getQueriesData=c=>t.getQueriesData({queryKey:a.key(c)}),a.prefetch=(c,f)=>t.prefetchQuery({queryKey:a.key(c),queryFn:d=>A.firstValueFrom(a.fetcher(c,d)),...f}),a.invalidate=c=>t.invalidateQueries({queryKey:a.key(c)}),a.cancel=c=>t.cancelQueries({queryKey:a.key(c)}),a.optimisticUpdate=async(c,f={})=>{await a.cancel(f);const d=a.getQueriesData(f);return a.setQueriesData(f,c),()=>d.forEach(([p,m])=>t.setQueryData(p,m))},a},createOperation(u){const l=o(`operation/${u}`,{responseType:"text"});function a({onSuccess:s,invalidateQueries:c,...f}={}){return k.useMutation({mutationKey:a.key,mutationFn:d=>A.firstValueFrom(a.fetcher(d)),...f,async onSuccess(d,p,m,y){const x=await s?.(d,p,m,y);return c&&await Promise.allSettled(c.map(S=>t.invalidateQueries({queryKey:S}))),x}},t)}return a.type=u,a.key=[a.type],a.fetcher=s=>l(s).pipe(he()),a},createCommand(u,l){const a=o(`command/${u}`);function s({invalidateQueries:c,handler:f,optimisticUpdate:d,onMutate:p,onError:m,onSettled:y,...x}={}){return k.useMutation({...x,mutationKey:s.key,mutationFn:S=>A.firstValueFrom(s.call(S,f)),async onMutate(S,g){const E=await p?.(S,g),h=await Promise.all(d?.(S)??[]);return{...E,revertOptimisticUpdate:()=>h.forEach(v=>v())}},async onError(S,g,E,h){await m?.(S,g,E,h),E?.revertOptimisticUpdate()},async onSettled(S,g,E,h,v){return c&&await Promise.allSettled(c.map(H=>t.invalidateQueries({queryKey:H}))),await y?.(S,g,E,h,v)}},t)}return s.type=u,s.key=[s.type],s.fetcher=a,s.call=(c,f)=>s.fetcher(c).pipe(F(p=>({isSuccess:!0,result:p})),A.catchError(p=>A.of(s.mapError(p))),F(p=>{const m=f?s.handleResponse(f,c)(p):p;if(!p.isSuccess||!p.result.WasSuccessful)throw m;return m})),s.mapError=c=>c instanceof q&&c.status===422?{isSuccess:!0,result:c.response}:{isSuccess:!1,error:c},s.handleResponse=(c,f)=>d=>c(Ae.handleResponse(d,l),f),s}}}P.mkCqrsClient=Ot,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leancodepl/react-query-cqrs-client",
3
- "version": "9.7.4",
3
+ "version": "10.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,9 +15,9 @@
15
15
  }
16
16
  },
17
17
  "dependencies": {
18
- "@leancodepl/cqrs-client-base": "9.7.4",
19
- "@leancodepl/utils": "9.7.4",
20
- "@leancodepl/validation": "9.7.4",
18
+ "@leancodepl/cqrs-client-base": "10.0.0",
19
+ "@leancodepl/utils": "10.0.0",
20
+ "@leancodepl/validation": "10.0.0",
21
21
  "@tanstack/react-query": ">=5.0.0",
22
22
  "rxjs": ">=7.0.0"
23
23
  },