react-query-manager
Version:
This is a library to simplify the work with @tanstack/react-query. It offers unified style for keys in the cache, ability to cancel a request. automatic cache refresh after mutation.
2 lines • 21.8 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var I=class e extends Error{constructor(r,a,s){super(r);this.message=r;this.status=a;this.data=s;Object.setPrototypeOf(this,e.prototype),this.name=this.constructor.name,typeof Error.captureStackTrace=="function"?Error.captureStackTrace(this,this.constructor):this.stack=new Error(r).stack,this.stack=new Error().stack,console.error(this.message,this)}};var ue=e=>{if(e!==null&&typeof e=="object"){let t={};return Object.entries(e).forEach(([a,s])=>{(s||typeof s=="boolean"||typeof s=="number")&&(t[a]=s)}),t}return{}},v=e=>encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]"),w= exports.fetcher =({onSuccess:e,onError:t,context:r,...a})=>{let s=a.data instanceof FormData,i=(()=>{let o=a.url;if(a.params){let c=ue(a.params);if(a.queryParamsSerializer)o+=`?${a.queryParamsSerializer(a.params)}`;else if(Object.keys(c).length>0){let y=[];for(let x in c)c.hasOwnProperty(x)&&(Array.isArray(c[x])?c[x].forEach(g=>{y.push(`${v(x)}${a.queryArrayParamStyle==="indexedArray"?"[]":""}=${v(g)}`)}):y.push(`${v(x)}=${v(c[x])}`));o+=`?${y.join("&")}`}}let[p,T]=o.split("?");return`${p}${T?`?${T}`:""}`})(),n=s?a.data:a.data?JSON.stringify(a.data):"",u={method:a.method,headers:{...!s&&{"Content-Type":"application/json"},...a.authorization&&{Authorization:a.authorization},...a.headers},...n&&{body:n},...a.options};return fetch(i,u).then(async o=>{let p=await(async()=>{try{let c=o.headers.get("Content-Length"),y=_optionalChain([o, 'access', _2 => _2.headers, 'access', _3 => _3.get, 'call', _4 => _4("Content-Type"), 'optionalAccess', _5 => _5.toLowerCase, 'call', _6 => _6()]);return o.status===204||o.status===304||c==="0"||!y?null:y.includes("application/json")?await o.json():y.includes("text/plain")||y.includes("text/csv")||y.includes("application/xml")||y.includes("text/xml")||y.includes("application/javascript")||y.includes("text/html")?await o.text():y.includes("multipart/form-data")?await o.formData():await o.blob()}catch (e2){return null}})(),T={};return o.headers.forEach((c,y)=>{T[y]=c}),{status:o.status,statusText:o.statusText,headers:T,data:p}}).then(o=>{if(o.status<200||o.status>=300){let p=new I(`Request failed with status code: ${o.status}`,o.status,o.data);return t&&t(p,a,r),Promise.reject(p)}return e&&e(o,a,r),Promise.resolve(o)}).catch(o=>Promise.reject(new I(o.message)))};var _reactquery = require('@tanstack/react-query'); _createStarExport(_reactquery);function V(e){return typeof e=="string"?e.replace(/^\/+/,"").replace(/\/+$/,""):""}var R=(e,t)=>{let r=V(e.path.replace(/{(\w+)}/g,(a,s)=>e.params[s].toString()));return t?`${r}/`:r};var _reactquerydevtools = require('@tanstack/react-query-devtools');var _react = require('react');var _headless = require('react-hot-toast/headless'); var _headless2 = _interopRequireDefault(_headless);var _jsxruntime = require('react/jsx-runtime');var pe=(()=>{let e;return()=>{if(e===void 0&&typeof window<"u"&&window.matchMedia){let t=matchMedia("(prefers-reduced-motion: reduce)");e=!t||t.matches}return e}})();function me({id:e,className:t,style:r,onHeightUpdate:a,children:s}){let i=_react.useCallback.call(void 0, n=>{if(n){let u=()=>{let{height:o}=n.getBoundingClientRect();a(e,o)};u(),new MutationObserver(u).observe(n,{subtree:!0,childList:!0,characterData:!0})}},[e,a]);return _jsxruntime.jsx.call(void 0, "div",{"data-toast-id":e,ref:i,className:t,style:r,children:s})}var le=(e,t)=>{let r=e.includes("top"),a=r?{top:0}:{bottom:0},s=e.includes("center")?{justifyContent:"center"}:e.includes("right")?{justifyContent:"flex-end"}:{};return{left:0,right:0,display:"flex",position:"absolute",transition:pe()?void 0:"all 230ms cubic-bezier(.21,1.02,.73,1)",transform:`translateY(${t*(r?1:-1)}px)`,...a,...s}},$=16;function z({reverseOrder:e,position:t="top-center",toastOptions:r,gutter:a,children:s,containerStyle:i,containerClassName:n}){let{toasts:u,handlers:o}=_headless.useToaster.call(void 0, r);return _jsxruntime.jsx.call(void 0, "div",{style:{position:"fixed",zIndex:9999,top:$,left:$,right:$,bottom:$,pointerEvents:"none",...i},className:n,onMouseEnter:o.startPause,onMouseLeave:o.endPause,children:u.map(p=>{let T=p.position||t,c={...p,position:T},y=o.calculateOffset(c,{reverseOrder:e,gutter:a,defaultPosition:t}),x=le(T,y),g=s;return _jsxruntime.jsx.call(void 0, me,{id:c.id,onHeightUpdate:o.updateHeight,style:{...x,pointerEvents:"auto"},children:c.type==="custom"?_headless.resolveValue.call(void 0, p.message,c):g?_jsxruntime.jsx.call(void 0, g,{...c}):_jsxruntime.jsx.call(void 0, "div",{style:{display:p.visible?"flex":"none"},children:_headless.resolveValue.call(void 0, c.message,c)})},c.id)})})}var _reacthottoast = require('react-hot-toast');var{remove:Xe,...de}=_headless2.default,B= exports.toast =Object.assign((...e)=>_headless2.default.call(void 0, ...e),de),Ze= exports.ToastBar =_reacthottoast.ToastBar,et= exports.resolveToastValue =_reacthottoast.resolveValue;var _eventemitter3 = require('eventemitter3'); var _eventemitter32 = _interopRequireDefault(_eventemitter3);var H=new _eventemitter32.default,S={once:(e,t)=>{H.once(e,t)},emit:(e,t)=>{H.emit(e,t)}};var q=process.env.NODE_ENV==="test";var W={queryClient:{}},E=()=>W.queryClient;var Z=_react.createContext.call(void 0, {apiUrl:"",apiEnsureTrailingSlash:!1,apiClient:w,toastUndo:()=>{}}),C= exports.useRQWrapperContext =()=>_react.useContext.call(void 0, Z);function Dt({children:e,config:t={},apiUrl:r,apiClient:a=w,apiEnsureTrailingSlash:s=!1,apiAuthorization:i,apiHeaders:n,apiOnSuccess:u,apiOnError:o,isDevTools:p,devToolsOptions:T,toast:c}){let y=_react.useMemo.call(void 0, ()=>{let Q=new (0, _reactquery.QueryClient)({...t});return W.queryClient=Q,Q},[]),x=_react.useCallback.call(void 0, Q=>{let m=i?i():"",l=n?n():{},d=(...f)=>{u&&u(...f),Q.onSuccess&&Q.onSuccess(...f)},h=(...f)=>{o&&o(...f),Q.onError&&Q.onError(...f)};return a({...Q,headers:Q.headers?{...l,...Q.headers}:l,authorization:Q.authorization||m,onSuccess:d,onError:h})},[]),g=_react.useCallback.call(void 0, Q=>{let m=!1;B.dismiss();let l=()=>{m=!0,S.emit("end",!0),B.dismiss()};q||B.success(d=>{let h=_optionalChain([c, 'optionalAccess', _7 => _7.CustomUndoContent]);return!d.visible&&!m&&(m=!0,S.emit("end",!1)),h?_jsxruntime.jsx.call(void 0, h,{message:Q.message,onUndo:l,type:Q.type,toast:d}):_jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment,{children:[Q.message,_jsxruntime.jsx.call(void 0, "span",{style:{marginLeft:"10px",cursor:"pointer"},onClick:l,role:"button",tabIndex:0,"aria-label":"Undo",title:"Undo",children:"UNDO"})]})},{duration:_optionalChain([c, 'optionalAccess', _8 => _8.globalProps, 'optionalAccess', _9 => _9.toastOptions, 'optionalAccess', _10 => _10.duration])||5e3})},[]),K=_react.useMemo.call(void 0, ()=>({apiUrl:V(r),apiClient:x,apiEnsureTrailingSlash:s,toastUndo:g}),[r,x,g,s]);return _jsxruntime.jsxs.call(void 0, _reactquery.QueryClientProvider,{client:y,children:[!q&&_jsxruntime.jsx.call(void 0, z,{..._optionalChain([c, 'optionalAccess', _11 => _11.globalProps]),children:_optionalChain([c, 'optionalAccess', _12 => _12.CustomContent])}),_jsxruntime.jsx.call(void 0, Z.Provider,{value:K,children:e}),p&&_jsxruntime.jsx.call(void 0, _reactquerydevtools.ReactQueryDevtools,{buttonPosition:"bottom-right",initialIsOpen:!1,...T})]})}var Ct=({queryOptions:e,resource:t,params:r={},apiClientParams:a})=>{let{apiUrl:s,apiClient:i,apiEnsureTrailingSlash:n}=C();return _reactquery.useQuery.call(void 0, {...e,queryKey:["get-list",t.path,t.params,r,..._optionalChain([e, 'optionalAccess', _13 => _13.queryKey])?e.queryKey:[]],queryFn:async({queryKey:o})=>{let p={resource:t,params:r,queryKey:o},T=`${s}/${R(p.resource,n)}`;return _optionalChain([e, 'optionalAccess', _14 => _14.queryFn])?await _optionalChain([e, 'optionalAccess', _15 => _15.queryFn, 'call', _16 => _16({apiClient:i,apiUrl:s,variables:p,url:T})]):await i({url:T,method:"GET",params:r,...a})}})};var St=({queryOptions:e,resource:t,params:r={},apiClientParams:a,pagination:s})=>{let{apiUrl:i,apiClient:n,apiEnsureTrailingSlash:u}=C();return _reactquery.useInfiniteQuery.call(void 0, {initialPageParam:1,getNextPageParam:(...p)=>{let T=p[0],c=Number(p[2]);if(_optionalChain([T, 'optionalAccess', _17 => _17.data, 'optionalAccess', _18 => _18.length]))return c+1},getPreviousPageParam:(...p)=>{let T=Number(p[2]);if(!(T<=1))return T-1},...e,queryKey:["get-infinite-list",t.path,t.params,s,r,..._optionalChain([e, 'optionalAccess', _19 => _19.queryKey])?e.queryKey:[]],queryFn:async({queryKey:p,pageParam:T})=>{let c={resource:t,params:{...r,[s.page[0]]:T,[s.per_page[0]]:s.per_page[1]},queryKey:p},y=`${i}/${R(c.resource,u)}`;return _optionalChain([e, 'optionalAccess', _20 => _20.queryFn])?await _optionalChain([e, 'optionalAccess', _21 => _21.queryFn, 'call', _22 => _22({apiClient:n,apiUrl:i,variables:c,url:y})]):await n({url:y,method:"GET",params:c.params,...a})}})};var Ut=({resource:e,id:t,queryOptions:r,params:a={},apiClientParams:s})=>{let{apiUrl:i,apiClient:n,apiEnsureTrailingSlash:u}=C();return _reactquery.useQuery.call(void 0, {...r,queryKey:["get-one",e.path,e.params,String(t),a,..._optionalChain([r, 'optionalAccess', _23 => _23.queryKey])?r.queryKey:[]],queryFn:async({queryKey:p})=>{let T={id:t,resource:e,params:a,queryKey:p},c=`${i}/${R(T.resource,!0)}`;return _optionalChain([r, 'optionalAccess', _24 => _24.queryFn])?await _optionalChain([r, 'optionalAccess', _25 => _25.queryFn, 'call', _26 => _26({apiClient:n,apiUrl:i,variables:T,url:c})]):await n({url:`${c}${T.id}${u?"/":""}`,method:"GET",params:a,...s})}})};var ee=({data:e,queryKeysOne:t})=>{let r=E();t&&t.forEach(a=>{r.setQueryData(a,e)})};var te=({data:e,queryKeysList:t,queryKeysInfiniteList:r,cacheAddItemTo:a="start"})=>{let s=E(),i=n=>!n||!(n.data instanceof Array)?n:{...n,data:a==="start"?[...e,...n.data]:[...n.data,...e]};t&&t.forEach(n=>{s.setQueriesData({queryKey:n},i)}),r&&r.forEach(n=>{s.setQueriesData({queryKey:n},u=>u&&{...u,pages:u.pages.map(i)})})};var re=({queryKeys:e})=>{let t=E();e.forEach(r=>{t.removeQueries({queryKey:r})})};var ae=({ids:e,queryKeysOne:t,queryKeysList:r,queryKeysInfiniteList:a})=>{let s=E(),i=n=>!n||!(n.data instanceof Array)?n:{...n,data:n.data.filter(u=>!e.some(o=>String(o)===String(u.id)))};t&&re({queryKeys:t}),r&&r.forEach(n=>{s.setQueriesData({queryKey:n},i)}),a&&a.forEach(n=>{s.setQueriesData({queryKey:n},u=>u&&{...u,pages:u.pages.map(i)})})};var P={getOne:(e,t)=>["get-one",e.path,e.params,String(t)],getOneArray:(e,t)=>t.map(r=>["get-one",e.path,e.params,String(r)]),getList:e=>["get-list",e.path,e.params],getInfiniteList:e=>["get-infinite-list",e.path,e.params],getDataQuery:e=>["query-data",e.path,e.params]};function O(e,t){if(typeof e!=typeof t||Object.prototype.toString.call(e)!==Object.prototype.toString.call(t))return!1;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r]&&!O(e[r],t[r]))return!1;return!0}if(e instanceof Object&&t instanceof Object){let r=Object.keys(e),a=Object.keys(t);if(r.length!==a.length)return!1;for(let s of r){let i=e[s],n=t[s];if(i!==n&&!O(i,n))return!1}return!0}return e===t}var Yt=({queryKeys:e})=>{E().invalidateQueries({predicate:r=>{let a=r.queryKey;return e.some(s=>s.every(i=>a.some(n=>O(n,i))))}})};var tr=({queryKeys:e})=>{E().removeQueries({predicate:r=>{let a=r.queryKey;return e.some(s=>s.every(i=>a.some(n=>O(n,i))))}})};var A=({queryKeys:e})=>{let t=E();e.forEach(r=>{t.invalidateQueries({queryKey:r})})};function se(e){return["number","string"].includes(typeof e)}function Ke(e,t){return se(e)&&se(t)}function k(e,t){let r={...e};if(e instanceof Object&&t instanceof Object){for(let a in t)if(a in e){let s=e[a],i=t[a],n=typeof s==typeof i&&(Array.isArray(s)&&Array.isArray(i)||s!==null&&!Array.isArray(s)&&typeof s=="object"&&!Array.isArray(i)&&typeof i=="object"||typeof s!="object"&&typeof i!="object"),u=Ke(s,i);(n||u)&&(typeof s=="object"&&s!==null&&!Array.isArray(s)?r[a]=k(s,i):r[a]=i)}}return r}var oe=({data:e,ids:t,queryKeysOne:r,queryKeysList:a,queryKeysInfiniteList:s})=>{let i=E(),n=u=>!u||!(u.data instanceof Array)?u:{...u,data:u.data.map(o=>t.some(p=>String(p)===String(o.id))?k(o,e):o)};r&&r.forEach(u=>{i.setQueriesData({queryKey:u},o=>!o||!(o.data instanceof Object)||!(e instanceof Object)?o:{...o,data:k(o.data,e)})}),a&&a.forEach(u=>{i.setQueriesData({queryKey:u},n)}),s&&s.forEach(u=>{i.setQueriesData({queryKey:u},o=>o&&{...o,pages:o.pages.map(n)})})};var N=async e=>{let t=E(),r=e.reduce((a,s)=>a.concat(t.getQueriesData({queryKey:s})),[]);return await Promise.all(r.map(([a])=>t.cancelQueries({queryKey:a}))),r};var ne=({resourcePath:e,mutationOptions:t,mode:r={optimistic:!0,undoable:!0},extraResources:a=[],shouldUpdateCurrentResource:s=!0,shouldInvalidateCache:i=!0,type:n="many"})=>{let{apiUrl:u,apiClient:o,apiEnsureTrailingSlash:p,toastUndo:T}=C(),c=_reactquery.useQueryClient.call(void 0, ),y=_react.useRef.call(void 0, []),x=()=>{y.current.forEach(([m,l])=>{c.setQueryData(m,l)})},{mutate:g,...K}=_reactquery.useMutation.call(void 0, {...t,mutationKey:[n==="many"?"delete-many":"delete-one",e,..._optionalChain([t, 'optionalAccess', _27 => _27.mutationKey])?t.mutationKey:[]],mutationFn:async m=>{let l=`${u}/${R(m.resource,!0)}`;if(_optionalChain([t, 'optionalAccess', _28 => _28.mutationFn]))return await _optionalChain([t, 'optionalAccess', _29 => _29.mutationFn, 'call', _30 => _30({apiClient:o,apiUrl:u,variables:m,url:l})]);let d=n==="many"?m.ids:[m.id],h=await Promise.allSettled(d.map(D=>o({url:`${l}${D}${p?"/":""}`,method:"DELETE",...m.apiClientParams}))),f=[];return h.forEach(D=>{if(D.status==="fulfilled")f.push(D.value);else throw D.reason}),n==="many"?f:f[0]},onSuccess:(...m)=>{if(i){let l=m[1],d=l.extraResources?[...a,...l.extraResources]:a,h=[P.getList(l.resource),P.getInfiniteList(l.resource)];d.forEach(f=>{h.push(P.getList(f)),h.push(P.getInfiniteList(f))}),A({queryKeys:h})}_optionalChain([t, 'optionalAccess', _31 => _31.onSuccess])&&t.onSuccess(...m)},onError:(...m)=>{_optionalChain([t, 'optionalAccess', _32 => _32.onError])&&t.onError(...m),x()}});return{mutation:K,delete:async({resourceParams:m,undoMessage:l,...d})=>{let h={path:e,params:m},f=n==="many"?d.ids:[d.id];if(r.optimistic){let D=d.extraResources?[...a,...d.extraResources]:a,b=s?P.getOneArray(h,f):[],F=s?[P.getList(h)]:[],L=s?[P.getInfiniteList(h)]:[];D.forEach(M=>{b.push(...P.getOneArray(M,f)),F.push(P.getList(M)),L.push(P.getInfiniteList(M))}),y.current=await N([...b,...F,...L]),ae({ids:f,queryKeysOne:b,queryKeysList:F,queryKeysInfiniteList:L})}if(r.undoable&&!q){let D=f.length>1;S.once("end",b=>{b?x():g({...d,resource:h})}),T({message:l||`Element${D?"s":""} deleted`,type:D?"delete-many":"delete-one"})}else g({...d,resource:h})}}},Lr= exports.useDeleteOne =e=>ne({...e,type:"one"}),Mr= exports.useDeleteMany =e=>ne({...e,type:"many"});var ie=({resourcePath:e,mutationOptions:t,mode:r={optimistic:!0,undoable:!0},extraResources:a=[],shouldUpdateCurrentResource:s=!0,shouldInvalidateCache:i=!0,type:n="many"})=>{let{apiUrl:u,apiClient:o,apiEnsureTrailingSlash:p,toastUndo:T}=C(),c=_reactquery.useQueryClient.call(void 0, ),y=_react.useRef.call(void 0, []),x=()=>{y.current.forEach(([m,l])=>{c.setQueryData(m,l)})},{mutate:g,...K}=_reactquery.useMutation.call(void 0, {...t,mutationKey:[n==="many"?"update-many":"update-one",e,..._optionalChain([t, 'optionalAccess', _33 => _33.mutationKey])?t.mutationKey:[]],mutationFn:async m=>{let l=`${u}/${R(m.resource,!0)}`;if(_optionalChain([t, 'optionalAccess', _34 => _34.mutationFn]))return await _optionalChain([t, 'optionalAccess', _35 => _35.mutationFn, 'call', _36 => _36({apiClient:o,apiUrl:u,variables:m,url:l})]);let d=n==="many"?m.ids:[m.id],h=await Promise.allSettled(d.map(D=>o({url:`${l}${D}${p?"/":""}`,method:"PATCH",data:m.data,...m.apiClientParams}))),f=[];return h.forEach(D=>{if(D.status==="fulfilled")f.push(D.value);else throw D.reason}),n==="many"?f:f[0]},onSuccess:(...m)=>{if(i){let l=m[1],d=l.extraResources?[...a,...l.extraResources]:a,h=n==="many"?l.ids:[l.id],f=[...P.getOneArray(l.resource,h),P.getList(l.resource),P.getInfiniteList(l.resource)];d.forEach(D=>{f.push(...P.getOneArray(D,h)),f.push(P.getList(D)),f.push(P.getInfiniteList(D))}),A({queryKeys:f})}_optionalChain([t, 'optionalAccess', _37 => _37.onSuccess])&&t.onSuccess(...m)},onError:(...m)=>{_optionalChain([t, 'optionalAccess', _38 => _38.onError])&&t.onError(...m),x()}});return{mutation:K,update:async({resourceParams:m,undoMessage:l,...d})=>{let h={path:e,params:m},f=n==="many"?d.ids:[d.id];if(r.optimistic){let D=d.extraResources?[...a,...d.extraResources]:a,b=s?P.getOneArray(h,f):[],F=s?[P.getList(h)]:[],L=s?[P.getInfiniteList(h)]:[];D.forEach(M=>{b.push(...P.getOneArray(M,f)),F.push(P.getList(M)),L.push(P.getInfiniteList(M))}),y.current=await N([...b,...F,...L]),oe({data:d.data,ids:f,queryKeysOne:b,queryKeysList:F,queryKeysInfiniteList:L})}if(r.undoable&&!q){let D=f.length>1;S.once("end",b=>{b?x():g({...d,resource:h})}),T({message:l||`Element${D?"s":""} updated`,type:D?"update-many":"update-one"})}else g({...d,resource:h})}}},Vr= exports.useUpdateOne =e=>ie({...e,type:"one"}),$r= exports.useUpdateMany =e=>ie({...e,type:"many"});var zr=({resourcePath:e,mutationOptions:t,extraResources:r=[],shouldUpdateCurrentResource:a=!0,cacheAddItemTo:s="start",shouldInvalidateCache:i=!0})=>{let{apiUrl:n,apiClient:u,apiEnsureTrailingSlash:o}=C(),{mutate:p,...T}=_reactquery.useMutation.call(void 0, {...t,mutationKey:["create",e,..._optionalChain([t, 'optionalAccess', _39 => _39.mutationKey])?t.mutationKey:[]],mutationFn:async y=>{let x=`${n}/${R(y.resource,o)}`;return _optionalChain([t, 'optionalAccess', _40 => _40.mutationFn])?await _optionalChain([t, 'optionalAccess', _41 => _41.mutationFn, 'call', _42 => _42({apiClient:u,apiUrl:n,variables:y,url:x})]):await u({url:x,method:"POST",data:y.data,...y.apiClientParams})},onSuccess:(...y)=>{let x=y[0],g=y[1],K=g.extraResources?[...r,...g.extraResources]:r;if(x){let Q=y[1],m=[P.getList(Q.resource)],l=[P.getInfiniteList(Q.resource)];if(K.forEach(d=>{m.push(P.getList(d)),l.push(P.getInfiniteList(d))}),a){let d=Array.isArray(x)?x:[x];d.forEach(h=>{if(h){let{id:f}=h.data,D=[P.getOne(Q.resource,f)];K.forEach(b=>{D.push(P.getOne(b,f))}),ee({data:h,queryKeysOne:D.map(b=>[...b,{}])})}}),te({data:d.map(h=>_optionalChain([h, 'optionalAccess', _43 => _43.data])||{}),cacheAddItemTo:s,queryKeysInfiniteList:[...a&&[P.getInfiniteList(Q.resource)],...l],queryKeysList:[...a&&[P.getList(Q.resource)],...m]})}i&&A({queryKeys:[...m,...l]})}_optionalChain([t, 'optionalAccess', _44 => _44.onSuccess])&&t.onSuccess(...y)}});return{mutation:T,create:({resourceParams:y,...x})=>{p({...x,resource:{path:e,params:y}})}}};var Xr=({queryOptions:e,resource:t,params:r={},apiClientParams:a})=>{let{apiUrl:s,apiClient:i,apiEnsureTrailingSlash:n}=C();return _reactquery.useQuery.call(void 0, {...e,queryKey:["query-data",t.path,t.params,r,..._optionalChain([e, 'optionalAccess', _45 => _45.queryKey])?e.queryKey:[]],queryFn:async({queryKey:o})=>{let p={resource:t,params:r,queryKey:o},T=`${s}/${R(p.resource,n)}`;return _optionalChain([e, 'optionalAccess', _46 => _46.queryFn])?await _optionalChain([e, 'optionalAccess', _47 => _47.queryFn, 'call', _48 => _48({apiClient:i,apiUrl:s,variables:p,url:T})]):await i({url:T,method:"GET",params:r,...a})}})};var aa=({resourcePath:e,mutationOptions:t})=>{let{apiUrl:r,apiClient:a,apiEnsureTrailingSlash:s}=C(),{mutate:i,...n}=_reactquery.useMutation.call(void 0, {...t,mutationKey:["mutate-data",e,..._optionalChain([t, 'optionalAccess', _49 => _49.mutationKey])?t.mutationKey:[]],mutationFn:async o=>{let p=`${r}/${R(o.resource,s)}`;return _optionalChain([t, 'optionalAccess', _50 => _50.mutationFn])?await _optionalChain([t, 'optionalAccess', _51 => _51.mutationFn, 'call', _52 => _52({apiClient:a,apiUrl:r,variables:o,url:p})]):await a({url:p,data:o.data,...o.apiClientParams})}});return{mutation:n,mutate:async({resourceParams:o,...p})=>{i({...p,resource:{path:e,params:o}})}}};exports.CustomError = I; exports.RQWrapper = Dt; exports.ToastBar = Ze; exports.addItemToQueryCache = ee; exports.addItemsToListQueryCache = te; exports.deleteItemsFromQueryCache = ae; exports.fetcher = w; exports.getUrlFromResource = R; exports.helpersQueryKeys = P; exports.invalidateMatchingQueries = Yt; exports.invalidateQueries = A; exports.removeMatchingQueries = tr; exports.removeQueries = re; exports.resolveToastValue = et; exports.toast = B; exports.updateItemsFromQueryCache = oe; exports.useCreate = zr; exports.useDataMutate = aa; exports.useDataQuery = Xr; exports.useDeleteMany = Mr; exports.useDeleteOne = Lr; exports.useGetInfiniteList = St; exports.useGetList = Ct; exports.useGetOne = Ut; exports.useRQWrapperContext = C; exports.useUpdateMany = $r; exports.useUpdateOne = Vr;
//# sourceMappingURL=index.js.map