@feardread/feature-factory 5.0.3 → 5.0.4
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.
- package/dist/bundle.min.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/factory/index.js +3 -3
package/dist/index.js
CHANGED
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
*
|
|
17
17
|
* This source code is licensed under the MIT license found in the
|
|
18
18
|
* LICENSE file in the root directory of this source tree.
|
|
19
|
-
*/var os=(rs||(rs=1,"production"===process.env.NODE_ENV?Za.exports=function(){if(Ya)return es;Ya=1;var e=Ja(),t="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},r=e.useSyncExternalStore,n=e.useRef,o=e.useEffect,i=e.useMemo,a=e.useDebugValue;return es.useSyncExternalStoreWithSelector=function(e,s,c,u,l){var f=n(null);if(null===f.current){var d={hasValue:!1,value:null};f.current=d}else d=f.current;f=i(function(){function e(e){if(!o){if(o=!0,r=e,e=u(e),void 0!==l&&d.hasValue){var i=d.value;if(l(i,e))return n=i}return n=e}if(i=n,t(r,e))return i;var a=u(e);return void 0!==l&&l(i,a)?(r=e,i):(r=e,n=a)}var r,n,o=!1,i=void 0===c?null:c;return[function(){return e(s())},null===i?void 0:function(){return e(i())}]},[s,c,u,l]);var p=r(e,f[0],f[1]);return o(function(){d.hasValue=!0,d.value=p},[p]),a(p),p},es}():Za.exports=(ts||(ts=1,"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var e=Ja(),t="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},r=e.useSyncExternalStore,n=e.useRef,o=e.useEffect,i=e.useMemo,a=e.useDebugValue;ns.useSyncExternalStoreWithSelector=function(e,s,c,u,l){var f=n(null);if(null===f.current){var d={hasValue:!1,value:null};f.current=d}else d=f.current;f=i(function(){function e(e){if(!o){if(o=!0,r=e,e=u(e),void 0!==l&&d.hasValue){var i=d.value;if(l(i,e))return n=i}return n=e}if(i=n,t(r,e))return i;var a=u(e);return void 0!==l&&l(i,a)?(r=e,i):(r=e,n=a)}var r,n,o=!1,i=void 0===c?null:c;return[function(){return e(s())},null===i?void 0:function(){return e(i())}]},[s,c,u,l]);var p=r(e,f[0],f[1]);return o(function(){d.hasValue=!0,d.value=p},[p]),a(p),p},"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),ns)),Za.exports);function is(e,t){return e===t?0!==e||0!==t||1/e==1/t:e!=e&&t!=t}function as(e,t){if(is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(let n=0;n<r.length;n++)if(!Object.prototype.hasOwnProperty.call(t,r[n])||!is(e[r[n]],t[r[n]]))return!1;return!0}var ss=Symbol.for("react-redux-context"),cs="undefined"!=typeof globalThis?globalThis:{};function us(){if(!Xa.createContext)return{};const e=cs[ss]??=new Map;let t=e.get(Xa.createContext);return t||(t=Xa.createContext(null),"production"!==process.env.NODE_ENV&&(t.displayName="ReactRedux"),e.set(Xa.createContext,t)),t}var ls=us();function fs(e=ls){return function(){const t=Xa.useContext(e);if("production"!==process.env.NODE_ENV&&!t)throw new Error("could not find react-redux context value; please ensure the component is wrapped in a <Provider>");return t}}var ds=fs();function ps(e=ls){const t=e===ls?ds:fs(e),r=()=>{const{store:e}=t();return e};return Object.assign(r,{withTypes:()=>r}),r}var ys=ps();function hs(e=ls){const t=e===ls?ys:ps(e),r=()=>t().dispatch;return Object.assign(r,{withTypes:()=>r}),r}var ms=hs(),gs=(e,t)=>e===t;function bs(e=ls){const t=e===ls?ds:fs(e),r=(e,r={})=>{const{equalityFn:n=gs}="function"==typeof r?{equalityFn:r}:r;if("production"!==process.env.NODE_ENV){if(!e)throw new Error("You must pass a selector to useSelector");if("function"!=typeof e)throw new Error("You must pass a function as a selector to useSelector");if("function"!=typeof n)throw new Error("You must pass a function as an equality function to useSelector")}const o=t(),{store:i,subscription:a,getServerState:s}=o,c=Xa.useRef(!0),u=Xa.useCallback({[e.name](t){const i=e(t);if("production"!==process.env.NODE_ENV){const{devModeChecks:a={}}="function"==typeof r?{}:r,{identityFunctionCheck:s,stabilityCheck:u}=o,{identityFunctionCheck:l,stabilityCheck:f}={stabilityCheck:u,identityFunctionCheck:s,...a};if("always"===f||"once"===f&&c.current){const r=e(t);if(!n(i,r)){let n;try{throw new Error}catch(e){({stack:n}=e)}console.warn("Selector "+(e.name||"unknown")+" returned a different result when called with the same parameters. This can lead to unnecessary rerenders.\nSelectors that return a new reference (such as an object or an array) should be memoized: https://redux.js.org/usage/deriving-data-selectors#optimizing-selectors-with-memoization",{state:t,selected:i,selected2:r,stack:n})}}if(("always"===l||"once"===l&&c.current)&&i===t){let t;try{throw new Error}catch(e){({stack:t}=e)}console.warn("Selector "+(e.name||"unknown")+" returned the root state when called. This can lead to unnecessary rerenders.\nSelectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever *anything* in state changes.",{stack:t})}c.current&&(c.current=!1)}return i}}[e.name],[e]),l=os.useSyncExternalStoreWithSelector(a.addNestedSub,i.getState,s||i.getState,u,n);return Xa.useDebugValue(l),l};return Object.assign(r,{withTypes:()=>r}),r}var vs=bs(),ws=function(e){e()};function Es(e){return e.replace(e[0],e[0].toUpperCase())}function Ss(e){let t=0;for(const r in e)t++;return t}function Os(e){return"infinitequery"===e.type}function _s(e,...t){return Object.assign(e,...t)}var As=Symbol();function Ts(e,t,r,n){const o=Xa.useMemo(()=>({queryArgs:e,serialized:"object"==typeof e?t({queryArgs:e,endpointDefinition:r,endpointName:n}):e}),[e,t,r,n]),i=Xa.useRef(o);return Xa.useEffect(()=>{i.current.serialized!==o.serialized&&(i.current=o)},[o]),i.current.serialized===o.serialized?i.current.queryArgs:e}function Rs(e){const t=Xa.useRef(e);return Xa.useEffect(()=>{as(t.current,e)||(t.current=e)},[e]),as(t.current,e)?t.current:e}var Ps=(()=>!("undefined"==typeof window||void 0===window.document||void 0===window.document.createElement))(),js=(()=>"undefined"!=typeof navigator&&"ReactNative"===navigator.product)(),ks=(()=>Ps||js?Xa.useLayoutEffect:Xa.useEffect)(),Cs=e=>e.isUninitialized?{...e,isUninitialized:!1,isFetching:!0,isLoading:void 0===e.data,status:Li.pending}:e;function Ns(e,...t){const r={};return t.forEach(t=>{r[t]=e[t]}),r}var Is=["data","status","isLoading","isSuccess","isError","error"];var xs=Symbol(),Ds=ja($a(),(({batch:e=ws,hooks:t={useDispatch:ms,useSelector:vs,useStore:ys},createSelector:r=ye,unstable__sideEffectsInRender:n=!1,...o}={})=>{if("production"!==process.env.NODE_ENV){const e=["useDispatch","useSelector","useStore"];let r=!1;for(const n of e)if(Ss(o)>0&&(o[n]&&(r||(console.warn("As of RTK 2.0, the hooks now need to be specified as one object, provided under a `hooks` key:\n`reactHooksModule({ hooks: { useDispatch, useSelector, useStore } })`"),r=!0)),t[n]=o[n]),"function"!=typeof t[n])throw new Error("production"===process.env.NODE_ENV?ot(36):`When using custom hooks for context, all ${e.length} hooks need to be provided: ${e.join(", ")}.\nHook ${n} was either not provided or not a function.`)}return{name:xs,init(o,{serializeQueryArgs:i},a){const s=o,{buildQueryHooks:c,buildInfiniteQueryHooks:u,buildMutationHook:l,usePrefetch:f}=function({api:e,moduleOptions:{batch:t,hooks:{useDispatch:r,useSelector:n,useStore:o},unstable__sideEffectsInRender:i,createSelector:a},serializeQueryArgs:s,context:c}){const u=i?e=>e():Xa.useEffect;return{buildQueryHooks:function(n){const o=(e,t={})=>{const[r]=d(n,e,t);return y(r),Xa.useMemo(()=>({refetch:()=>h(r)}),[r])},i=({refetchOnReconnect:o,refetchOnFocus:i,pollingInterval:a=0,skipPollingIfUnfocused:s=!1}={})=>{const{initiate:c}=e.endpoints[n],l=r(),[f,d]=Xa.useState(As),p=Xa.useRef(void 0),y=Rs({refetchOnReconnect:o,refetchOnFocus:i,pollingInterval:a,skipPollingIfUnfocused:s});u(()=>{const e=p.current?.subscriptionOptions;y!==e&&p.current?.updateSubscriptionOptions(y)},[y]);const h=Xa.useRef(y);u(()=>{h.current=y},[y]);const m=Xa.useCallback(function(e,r=!1){let n;return t(()=>{p.current?.unsubscribe(),p.current=n=l(c(e,{subscriptionOptions:h.current,forceRefetch:!r})),d(e)}),n},[l,c]),g=Xa.useCallback(()=>{p.current?.queryCacheKey&&l(e.internalActions.removeQueryResult({queryCacheKey:p.current?.queryCacheKey}))},[l]);return Xa.useEffect(()=>()=>{p?.current?.unsubscribe()},[]),Xa.useEffect(()=>{f===As||p.current||m(f,!0)},[f,m]),Xa.useMemo(()=>[m,f,{reset:g}],[m,f,g])},a=p(n,l);return{useQueryState:a,useQuerySubscription:o,useLazyQuerySubscription:i,useLazyQuery(e){const[t,r,{reset:n}]=i(e),o=a(r,{...e,skip:r===As}),s=Xa.useMemo(()=>({lastArg:r}),[r]);return Xa.useMemo(()=>[t,{...o,reset:n},s],[t,o,n,s])},useQuery(e,t){const r=o(e,t),n=a(e,{selectFromResult:e===Oa||t?.skip?void 0:Cs,...t}),i=Ns(n,...Is);return Xa.useDebugValue(i),Xa.useMemo(()=>({...n,...r}),[n,r])}}},buildInfiniteQueryHooks:function(e){const r=(r,n={})=>{const[o,i,a,s]=d(e,r,n),l=Xa.useRef(s);u(()=>{l.current=s},[s]);const f=Xa.useCallback(function(e,r){let n;return t(()=>{o.current?.unsubscribe(),o.current=n=i(a(e,{subscriptionOptions:l.current,direction:r}))}),n},[o,i,a]);y(o);const p=Ts(n.skip?Oa:r,Pa,c.endpointDefinitions[e],e),m=Xa.useCallback(()=>h(o),[o]);return Xa.useMemo(()=>({trigger:f,refetch:m,fetchNextPage:()=>f(p,"forward"),fetchPreviousPage:()=>f(p,"backward")}),[m,f,p])},n=p(e,f);return{useInfiniteQueryState:n,useInfiniteQuerySubscription:r,useInfiniteQuery(e,t){const{refetch:o,fetchNextPage:i,fetchPreviousPage:a}=r(e,t),s=n(e,{selectFromResult:e===Oa||t?.skip?void 0:Cs,...t}),c=Ns(s,...Is,"hasNextPage","hasPreviousPage");return Xa.useDebugValue(c),Xa.useMemo(()=>({...s,fetchNextPage:i,fetchPreviousPage:a,refetch:o}),[s,i,a,o])}}},buildMutationHook:function(o){return({selectFromResult:i,fixedCacheKey:s}={})=>{const{select:c,initiate:u}=e.endpoints[o],l=r(),[f,d]=Xa.useState();Xa.useEffect(()=>()=>{f?.arg.fixedCacheKey||f?.reset()},[f]);const p=Xa.useCallback(function(e){const t=l(u(e,{fixedCacheKey:s}));return d(t),t},[l,u,s]),{requestId:y}=f||{},h=Xa.useMemo(()=>c({fixedCacheKey:s,requestId:f?.requestId}),[s,f,c]),m=Xa.useMemo(()=>i?a([h],i):h,[i,h]),g=n(m,as),b=null==s?f?.arg.originalArgs:void 0,v=Xa.useCallback(()=>{t(()=>{f&&d(void 0),s&&l(e.internalActions.removeMutationResult({requestId:y,fixedCacheKey:s}))})},[l,s,f,y]),w=Ns(g,...Is,"endpointName");Xa.useDebugValue(w);const E=Xa.useMemo(()=>({...g,originalArgs:b,reset:v}),[g,b,v]);return Xa.useMemo(()=>[p,E],[p,E])}},usePrefetch:function(t,n){const o=r(),i=Rs(n);return Xa.useCallback((r,n)=>o(e.util.prefetch(t,r,{...i,...n})),[t,o,i])}};function l(e,t,r){if(t?.endpointName&&e.isUninitialized){const{endpointName:e}=t,n=c.endpointDefinitions[e];r!==Oa&&s({queryArgs:t.originalArgs,endpointDefinition:n,endpointName:e})===s({queryArgs:r,endpointDefinition:n,endpointName:e})&&(t=void 0)}let n=e.isSuccess?e.data:t?.data;void 0===n&&(n=e.data);const o=void 0!==n,i=e.isLoading,a=(!t||t.isLoading||t.isUninitialized)&&!o&&i,u=e.isSuccess||o&&(i&&!t?.isError||e.isUninitialized);return{...e,data:n,currentData:e.data,isFetching:i,isLoading:a,isSuccess:u}}function f(e,t,r){if(t?.endpointName&&e.isUninitialized){const{endpointName:e}=t,n=c.endpointDefinitions[e];r!==Oa&&s({queryArgs:t.originalArgs,endpointDefinition:n,endpointName:e})===s({queryArgs:r,endpointDefinition:n,endpointName:e})&&(t=void 0)}let n=e.isSuccess?e.data:t?.data;void 0===n&&(n=e.data);const o=void 0!==n,i=e.isLoading,a=(!t||t.isLoading||t.isUninitialized)&&!o&&i,u=e.isSuccess||i&&o;return{...e,data:n,currentData:e.data,isFetching:i,isLoading:a,isSuccess:u}}function d(t,n,{refetchOnReconnect:o,refetchOnFocus:i,refetchOnMountOrArgChange:a,skip:s=!1,pollingInterval:l=0,skipPollingIfUnfocused:f=!1,...d}={}){const{initiate:p}=e.endpoints[t],y=r(),h=Xa.useRef(void 0);if(!h.current){const t=y(e.internalActions.internal_getRTKQSubscriptions());if("production"!==process.env.NODE_ENV&&("object"!=typeof t||"string"==typeof t?.type))throw new Error("production"===process.env.NODE_ENV?ot(37):`Warning: Middleware for RTK-Query API at reducerPath "${e.reducerPath}" has not been added to the store.\n You must add the middleware for RTK-Query to function correctly!`);h.current=t}const m=Ts(s?Oa:n,Pa,c.endpointDefinitions[t],t),g=Rs({refetchOnReconnect:o,refetchOnFocus:i,pollingInterval:l,skipPollingIfUnfocused:f}),b=Rs(d.initialPageParam),v=Xa.useRef(void 0);let{queryCacheKey:w,requestId:E}=v.current||{},S=!1;w&&E&&(S=h.current.isRequestSubscribed(w,E));const O=!S&&void 0!==v.current;return u(()=>{O&&(v.current=void 0)},[O]),u(()=>{const e=v.current;if("undefined"!=typeof process&&"removeMeOnCompilation"===process.env.NODE_ENV&&console.log(O),m===Oa)return e?.unsubscribe(),void(v.current=void 0);const r=v.current?.subscriptionOptions;if(e&&e.arg===m)g!==r&&e.updateSubscriptionOptions(g);else{e?.unsubscribe();const r=y(p(m,{subscriptionOptions:g,forceRefetch:a,...Os(c.endpointDefinitions[t])?{initialPageParam:b}:{}}));v.current=r}},[y,p,a,m,g,O,b,t]),[v,y,p,g]}function p(t,r){return(i,{skip:u=!1,selectFromResult:l}={})=>{const{select:f}=e.endpoints[t],d=Ts(u?Oa:i,s,c.endpointDefinitions[t],t),p=Xa.useRef(void 0),y=Xa.useMemo(()=>a([f(d),(e,t)=>t,e=>d],r,{memoizeOptions:{resultEqualityCheck:as}}),[f,d]),h=Xa.useMemo(()=>l?a([y],l,{devModeChecks:{identityFunctionCheck:"never"}}):y,[y,l]),m=n(e=>h(e,p.current),as),g=o(),b=y(g.getState(),p.current);return ks(()=>{p.current=b},[b]),m}}function y(e){Xa.useEffect(()=>()=>{e.current?.unsubscribe?.(),e.current=void 0},[e])}function h(e){if(!e.current)throw new Error("production"===process.env.NODE_ENV?ot(38):"Cannot refetch a query that has not been started yet.");return e.current.refetch()}}({api:o,moduleOptions:{batch:e,hooks:t,unstable__sideEffectsInRender:n,createSelector:r},serializeQueryArgs:i,context:a});return _s(s,{usePrefetch:f}),_s(a,{batch:e}),{injectEndpoint(e,t){if("query"===t.type){const{useQuery:t,useLazyQuery:r,useLazyQuerySubscription:n,useQueryState:i,useQuerySubscription:a}=c(e);_s(s.endpoints[e],{useQuery:t,useLazyQuery:r,useLazyQuerySubscription:n,useQueryState:i,useQuerySubscription:a}),o[`use${Es(e)}Query`]=t,o[`useLazy${Es(e)}Query`]=r}if(function(e){return"mutation"===e.type}(t)){const t=l(e);_s(s.endpoints[e],{useMutation:t}),o[`use${Es(e)}Mutation`]=t}else if(Os(t)){const{useInfiniteQuery:t,useInfiniteQuerySubscription:r,useInfiniteQueryState:n}=u(e);_s(s.endpoints[e],{useInfiniteQuery:t,useInfiniteQuerySubscription:r,useInfiniteQueryState:n}),o[`use${Es(e)}InfiniteQuery`]=t}}}}}})());const qs={baseUrl:process.env.REACT_APP_API_BASE_URL||"http://localhost:4000/fear/api/",timeout:3e4,credentials:"include",prepareHeaders:(e,{getState:t})=>{e.set("Content-Type","application/json");const r=t()?.auth?.token;return r&&e.set("Authorization",`Bearer ${r}`),e}},Fs={GET:"GET",POST:"POST",PUT:"PUT",PATCH:"PATCH",DELETE:"DELETE"},Ms={getAll:{method:Fs.GET,url:e=>`${e}/all`,providesTags:e=>[{type:e,id:"LIST"}]},getById:{method:Fs.GET,url:(e,t)=>`${e}/${t}`,providesTags:(e,t)=>[{type:e,id:t}]},create:{method:Fs.POST,url:e=>`${e}`,invalidatesTags:e=>[{type:e,id:"LIST"}]},update:{method:Fs.PUT,url:(e,t)=>`${e}/${t}`,invalidatesTags:(e,t)=>[{type:e,id:t},{type:e,id:"LIST"}]},patch:{method:Fs.PATCH,url:(e,t)=>`${e}/${t}`,invalidatesTags:(e,t)=>[{type:e,id:t},{type:e,id:"LIST"}]},delete:{method:Fs.DELETE,url:(e,t)=>`${e}/${t}`,invalidatesTags:(e,t)=>[{type:e,id:t},{type:e,id:"LIST"}]},search:{method:Fs.GET,url:e=>`${e}/search`,providesTags:e=>[{type:e,id:"SEARCH"}]}},Us=e=>e.status?{status:e.status,message:e.data?.message||`HTTP Error ${e.status}`,data:e.data}:{status:"FETCH_ERROR",message:e.message||"Network error occurred",error:e.error},Ls=(e,t,r={})=>{const{method:n,url:o}=e;let i={method:n,url:"function"==typeof o?o(t,r.id,r):o};return n!==Fs.GET&&n!==Fs.DELETE&&(i.body=r.data||r),n===Fs.GET&&r.params&&(i.params=r.params),i},$s=(e,t={})=>{(e=>{if(!e||"string"!=typeof e)throw new Error("SliceName must be a non-empty string")})(e);const r={tagTypes:["Product","Order","User","Category"],baseQuery:{},includeStandardEndpoints:!0,...t},n=(o=e).charAt(0).toUpperCase()+o.slice(1);var o;r.tagTypes.includes(n)||r.tagTypes.push(n);const i={...qs,...r.baseQuery},a=Ds({reducerPath:`${e}Api`,tagTypes:r.tagTypes,baseQuery:Xi(i),endpoints:()=>({})}),s=(t,r)=>{const{method:n=Fs.GET,url:o,type:i=(n===Fs.GET?"query":"mutation"),providesTags:s,invalidatesTags:c,transformResponse:u,transformErrorResponse:l=Us}=r;return a.injectEndpoints({endpoints:r=>({[t]:r[i]({query:(t={})=>Ls({method:n,url:o},e,t),providesTags:s?(t,r,n)=>s(e,n?.id,t,r,n):void 0,invalidatesTags:c?(t,r,n)=>c(e,n?.id,t,r,n):void 0,transformResponse:u,transformErrorResponse:l})})})},c=t=>a.injectEndpoints({endpoints:r=>{const n={};return Object.entries(t).forEach(([t,o])=>{const{method:i=Fs.GET,url:a,type:s=(i===Fs.GET?"query":"mutation"),providesTags:c,invalidatesTags:u,transformResponse:l,transformErrorResponse:f=Us}=o;n[t]=r[s]({query:(t={})=>Ls({method:i,url:a},e,t),providesTags:c?(t,r,n)=>c(e,n?.id,t,r,n):void 0,invalidatesTags:u?(t,r,n)=>u(e,n?.id,t,r,n):void 0,transformResponse:l,transformErrorResponse:f})}),n}}),u=()=>{const e={};return Object.entries(Ms).forEach(([t,r])=>{e[t]={method:r.method,url:r.url,providesTags:r.providesTags,invalidatesTags:r.invalidatesTags}}),c(e)};return{sliceName:e,entityTagType:n,baseApi:a,inject:s,injectMany:c,create:()=>{let e=a;return r.includeStandardEndpoints&&(e=u()),e},createStandard:u,createBulk:()=>{const t={bulkCreate:{method:Fs.POST,url:`${e}/bulk`,invalidatesTags:()=>[{type:n,id:"LIST"}]},bulkUpdate:{method:Fs.PUT,url:`${e}/bulk`,invalidatesTags:()=>[{type:n,id:"LIST"}]},bulkDelete:{method:Fs.DELETE,url:`${e}/bulk`,invalidatesTags:()=>[{type:n,id:"LIST"}]}};return c(t)},createCustom:(e,t)=>s(e,t),getTagTypes:()=>[...r.tagTypes],getBaseUrl:()=>i.baseUrl,getReducerPath:()=>a.reducerPath,withAuth:t=>$s(e,{...r,baseQuery:{...i,prepareHeaders:(e,r)=>(e.set("Authorization",`Bearer ${t}`),qs.prepareHeaders(e,r))}}),withBaseUrl:t=>$s(e,{...r,baseQuery:{...i,baseUrl:t}})}};$s.createComplete=(e,t={})=>$s(e,t).create(),$s.createCustom=(e,t,r={})=>$s(e,{...r,includeStandardEndpoints:!1}).injectMany(t),$s.getStandardEndpoints=()=>({...Ms}),$s.getHttpMethods=()=>({...Fs}),exports.API=Pi,exports.ApiFactory=$s,exports.CacheFactory=hi,exports.FeatureFactory=function(e,t={},r=null){if(!e||"string"!=typeof e)throw new Error("Entity name must be provided as a string");const n=nt(),o=(e,t)=>{if(!e||!t)throw new Error("Both source and destination objects must be provided");return Object.keys(e).reduce((t,r)=>(Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]),t),{...t})},i=(e,t,r)=>{Object.entries(t).forEach(([t,n])=>{e.addCase(n.pending,e=>{e.loading=!0,e.error=null}).addCase(n.fulfilled,(e,n)=>{e.loading=!1,e.success=!0,e.data=n.payload.result,("fetchOne"===t&&Array.isArray(n.payload)||Array.isArray(n.payload)&&n.payload.length>0)&&(e[r]=n.payload[0].result)}).addCase(n.rejected,(e,t)=>{e.loading=!1,e.success=!1,e.error=t.error||t.payload})})};return{entity:e,reducers:t,adapter:n,manager:(e={})=>{const t={...e};let r=s(t);return{reduce:(e,t)=>r(e,t),add:(e,n)=>{e&&"string"==typeof e?t[e]?console.warn(`Reducer with key '${e}' already exists`):(t[e]=n,r=s(t)):console.warn("Invalid reducer key provided")},remove:e=>{e&&t[e]?(delete t[e],r=s(t)):console.warn(`Reducer with key '${e}' does not exist`)},getReducerMap:()=>({...t})}},inject:o,create:(r={})=>{const{service:n=null,initialState:a=null}=r,s=e,c=(e=>({fetch:Ii.create(e,"all"),fetchOne:Ii.create(e,"one"),search:Ii.post(e,"search")}))(s);return{slice:Ke({name:s,initialState:a||Mi(s),reducers:t,extraReducers:e=>{if(i(e,c,s),n&&"object"==typeof n){const t=Object.entries(n).reduce((e,[t,r])=>(c[t]||(e[t]=r),e),{});i(e,t,s)}}}),asyncActions:n?o(c,n):c}},getEntityName:()=>e,getAdapter:()=>n}},exports.StateFactory=Mi,exports.ThunkFactory=Ii;
|
|
19
|
+
*/var os=(rs||(rs=1,"production"===process.env.NODE_ENV?Za.exports=function(){if(Ya)return es;Ya=1;var e=Ja(),t="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},r=e.useSyncExternalStore,n=e.useRef,o=e.useEffect,i=e.useMemo,a=e.useDebugValue;return es.useSyncExternalStoreWithSelector=function(e,s,c,u,l){var f=n(null);if(null===f.current){var d={hasValue:!1,value:null};f.current=d}else d=f.current;f=i(function(){function e(e){if(!o){if(o=!0,r=e,e=u(e),void 0!==l&&d.hasValue){var i=d.value;if(l(i,e))return n=i}return n=e}if(i=n,t(r,e))return i;var a=u(e);return void 0!==l&&l(i,a)?(r=e,i):(r=e,n=a)}var r,n,o=!1,i=void 0===c?null:c;return[function(){return e(s())},null===i?void 0:function(){return e(i())}]},[s,c,u,l]);var p=r(e,f[0],f[1]);return o(function(){d.hasValue=!0,d.value=p},[p]),a(p),p},es}():Za.exports=(ts||(ts=1,"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var e=Ja(),t="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},r=e.useSyncExternalStore,n=e.useRef,o=e.useEffect,i=e.useMemo,a=e.useDebugValue;ns.useSyncExternalStoreWithSelector=function(e,s,c,u,l){var f=n(null);if(null===f.current){var d={hasValue:!1,value:null};f.current=d}else d=f.current;f=i(function(){function e(e){if(!o){if(o=!0,r=e,e=u(e),void 0!==l&&d.hasValue){var i=d.value;if(l(i,e))return n=i}return n=e}if(i=n,t(r,e))return i;var a=u(e);return void 0!==l&&l(i,a)?(r=e,i):(r=e,n=a)}var r,n,o=!1,i=void 0===c?null:c;return[function(){return e(s())},null===i?void 0:function(){return e(i())}]},[s,c,u,l]);var p=r(e,f[0],f[1]);return o(function(){d.hasValue=!0,d.value=p},[p]),a(p),p},"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),ns)),Za.exports);function is(e,t){return e===t?0!==e||0!==t||1/e==1/t:e!=e&&t!=t}function as(e,t){if(is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(let n=0;n<r.length;n++)if(!Object.prototype.hasOwnProperty.call(t,r[n])||!is(e[r[n]],t[r[n]]))return!1;return!0}var ss=Symbol.for("react-redux-context"),cs="undefined"!=typeof globalThis?globalThis:{};function us(){if(!Xa.createContext)return{};const e=cs[ss]??=new Map;let t=e.get(Xa.createContext);return t||(t=Xa.createContext(null),"production"!==process.env.NODE_ENV&&(t.displayName="ReactRedux"),e.set(Xa.createContext,t)),t}var ls=us();function fs(e=ls){return function(){const t=Xa.useContext(e);if("production"!==process.env.NODE_ENV&&!t)throw new Error("could not find react-redux context value; please ensure the component is wrapped in a <Provider>");return t}}var ds=fs();function ps(e=ls){const t=e===ls?ds:fs(e),r=()=>{const{store:e}=t();return e};return Object.assign(r,{withTypes:()=>r}),r}var ys=ps();function hs(e=ls){const t=e===ls?ys:ps(e),r=()=>t().dispatch;return Object.assign(r,{withTypes:()=>r}),r}var ms=hs(),gs=(e,t)=>e===t;function bs(e=ls){const t=e===ls?ds:fs(e),r=(e,r={})=>{const{equalityFn:n=gs}="function"==typeof r?{equalityFn:r}:r;if("production"!==process.env.NODE_ENV){if(!e)throw new Error("You must pass a selector to useSelector");if("function"!=typeof e)throw new Error("You must pass a function as a selector to useSelector");if("function"!=typeof n)throw new Error("You must pass a function as an equality function to useSelector")}const o=t(),{store:i,subscription:a,getServerState:s}=o,c=Xa.useRef(!0),u=Xa.useCallback({[e.name](t){const i=e(t);if("production"!==process.env.NODE_ENV){const{devModeChecks:a={}}="function"==typeof r?{}:r,{identityFunctionCheck:s,stabilityCheck:u}=o,{identityFunctionCheck:l,stabilityCheck:f}={stabilityCheck:u,identityFunctionCheck:s,...a};if("always"===f||"once"===f&&c.current){const r=e(t);if(!n(i,r)){let n;try{throw new Error}catch(e){({stack:n}=e)}console.warn("Selector "+(e.name||"unknown")+" returned a different result when called with the same parameters. This can lead to unnecessary rerenders.\nSelectors that return a new reference (such as an object or an array) should be memoized: https://redux.js.org/usage/deriving-data-selectors#optimizing-selectors-with-memoization",{state:t,selected:i,selected2:r,stack:n})}}if(("always"===l||"once"===l&&c.current)&&i===t){let t;try{throw new Error}catch(e){({stack:t}=e)}console.warn("Selector "+(e.name||"unknown")+" returned the root state when called. This can lead to unnecessary rerenders.\nSelectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever *anything* in state changes.",{stack:t})}c.current&&(c.current=!1)}return i}}[e.name],[e]),l=os.useSyncExternalStoreWithSelector(a.addNestedSub,i.getState,s||i.getState,u,n);return Xa.useDebugValue(l),l};return Object.assign(r,{withTypes:()=>r}),r}var vs=bs(),ws=function(e){e()};function Es(e){return e.replace(e[0],e[0].toUpperCase())}function Ss(e){let t=0;for(const r in e)t++;return t}function Os(e){return"infinitequery"===e.type}function _s(e,...t){return Object.assign(e,...t)}var As=Symbol();function Ts(e,t,r,n){const o=Xa.useMemo(()=>({queryArgs:e,serialized:"object"==typeof e?t({queryArgs:e,endpointDefinition:r,endpointName:n}):e}),[e,t,r,n]),i=Xa.useRef(o);return Xa.useEffect(()=>{i.current.serialized!==o.serialized&&(i.current=o)},[o]),i.current.serialized===o.serialized?i.current.queryArgs:e}function Rs(e){const t=Xa.useRef(e);return Xa.useEffect(()=>{as(t.current,e)||(t.current=e)},[e]),as(t.current,e)?t.current:e}var Ps=(()=>!("undefined"==typeof window||void 0===window.document||void 0===window.document.createElement))(),js=(()=>"undefined"!=typeof navigator&&"ReactNative"===navigator.product)(),ks=(()=>Ps||js?Xa.useLayoutEffect:Xa.useEffect)(),Cs=e=>e.isUninitialized?{...e,isUninitialized:!1,isFetching:!0,isLoading:void 0===e.data,status:Li.pending}:e;function Ns(e,...t){const r={};return t.forEach(t=>{r[t]=e[t]}),r}var Is=["data","status","isLoading","isSuccess","isError","error"];var xs=Symbol(),Ds=ja($a(),(({batch:e=ws,hooks:t={useDispatch:ms,useSelector:vs,useStore:ys},createSelector:r=ye,unstable__sideEffectsInRender:n=!1,...o}={})=>{if("production"!==process.env.NODE_ENV){const e=["useDispatch","useSelector","useStore"];let r=!1;for(const n of e)if(Ss(o)>0&&(o[n]&&(r||(console.warn("As of RTK 2.0, the hooks now need to be specified as one object, provided under a `hooks` key:\n`reactHooksModule({ hooks: { useDispatch, useSelector, useStore } })`"),r=!0)),t[n]=o[n]),"function"!=typeof t[n])throw new Error("production"===process.env.NODE_ENV?ot(36):`When using custom hooks for context, all ${e.length} hooks need to be provided: ${e.join(", ")}.\nHook ${n} was either not provided or not a function.`)}return{name:xs,init(o,{serializeQueryArgs:i},a){const s=o,{buildQueryHooks:c,buildInfiniteQueryHooks:u,buildMutationHook:l,usePrefetch:f}=function({api:e,moduleOptions:{batch:t,hooks:{useDispatch:r,useSelector:n,useStore:o},unstable__sideEffectsInRender:i,createSelector:a},serializeQueryArgs:s,context:c}){const u=i?e=>e():Xa.useEffect;return{buildQueryHooks:function(n){const o=(e,t={})=>{const[r]=d(n,e,t);return y(r),Xa.useMemo(()=>({refetch:()=>h(r)}),[r])},i=({refetchOnReconnect:o,refetchOnFocus:i,pollingInterval:a=0,skipPollingIfUnfocused:s=!1}={})=>{const{initiate:c}=e.endpoints[n],l=r(),[f,d]=Xa.useState(As),p=Xa.useRef(void 0),y=Rs({refetchOnReconnect:o,refetchOnFocus:i,pollingInterval:a,skipPollingIfUnfocused:s});u(()=>{const e=p.current?.subscriptionOptions;y!==e&&p.current?.updateSubscriptionOptions(y)},[y]);const h=Xa.useRef(y);u(()=>{h.current=y},[y]);const m=Xa.useCallback(function(e,r=!1){let n;return t(()=>{p.current?.unsubscribe(),p.current=n=l(c(e,{subscriptionOptions:h.current,forceRefetch:!r})),d(e)}),n},[l,c]),g=Xa.useCallback(()=>{p.current?.queryCacheKey&&l(e.internalActions.removeQueryResult({queryCacheKey:p.current?.queryCacheKey}))},[l]);return Xa.useEffect(()=>()=>{p?.current?.unsubscribe()},[]),Xa.useEffect(()=>{f===As||p.current||m(f,!0)},[f,m]),Xa.useMemo(()=>[m,f,{reset:g}],[m,f,g])},a=p(n,l);return{useQueryState:a,useQuerySubscription:o,useLazyQuerySubscription:i,useLazyQuery(e){const[t,r,{reset:n}]=i(e),o=a(r,{...e,skip:r===As}),s=Xa.useMemo(()=>({lastArg:r}),[r]);return Xa.useMemo(()=>[t,{...o,reset:n},s],[t,o,n,s])},useQuery(e,t){const r=o(e,t),n=a(e,{selectFromResult:e===Oa||t?.skip?void 0:Cs,...t}),i=Ns(n,...Is);return Xa.useDebugValue(i),Xa.useMemo(()=>({...n,...r}),[n,r])}}},buildInfiniteQueryHooks:function(e){const r=(r,n={})=>{const[o,i,a,s]=d(e,r,n),l=Xa.useRef(s);u(()=>{l.current=s},[s]);const f=Xa.useCallback(function(e,r){let n;return t(()=>{o.current?.unsubscribe(),o.current=n=i(a(e,{subscriptionOptions:l.current,direction:r}))}),n},[o,i,a]);y(o);const p=Ts(n.skip?Oa:r,Pa,c.endpointDefinitions[e],e),m=Xa.useCallback(()=>h(o),[o]);return Xa.useMemo(()=>({trigger:f,refetch:m,fetchNextPage:()=>f(p,"forward"),fetchPreviousPage:()=>f(p,"backward")}),[m,f,p])},n=p(e,f);return{useInfiniteQueryState:n,useInfiniteQuerySubscription:r,useInfiniteQuery(e,t){const{refetch:o,fetchNextPage:i,fetchPreviousPage:a}=r(e,t),s=n(e,{selectFromResult:e===Oa||t?.skip?void 0:Cs,...t}),c=Ns(s,...Is,"hasNextPage","hasPreviousPage");return Xa.useDebugValue(c),Xa.useMemo(()=>({...s,fetchNextPage:i,fetchPreviousPage:a,refetch:o}),[s,i,a,o])}}},buildMutationHook:function(o){return({selectFromResult:i,fixedCacheKey:s}={})=>{const{select:c,initiate:u}=e.endpoints[o],l=r(),[f,d]=Xa.useState();Xa.useEffect(()=>()=>{f?.arg.fixedCacheKey||f?.reset()},[f]);const p=Xa.useCallback(function(e){const t=l(u(e,{fixedCacheKey:s}));return d(t),t},[l,u,s]),{requestId:y}=f||{},h=Xa.useMemo(()=>c({fixedCacheKey:s,requestId:f?.requestId}),[s,f,c]),m=Xa.useMemo(()=>i?a([h],i):h,[i,h]),g=n(m,as),b=null==s?f?.arg.originalArgs:void 0,v=Xa.useCallback(()=>{t(()=>{f&&d(void 0),s&&l(e.internalActions.removeMutationResult({requestId:y,fixedCacheKey:s}))})},[l,s,f,y]),w=Ns(g,...Is,"endpointName");Xa.useDebugValue(w);const E=Xa.useMemo(()=>({...g,originalArgs:b,reset:v}),[g,b,v]);return Xa.useMemo(()=>[p,E],[p,E])}},usePrefetch:function(t,n){const o=r(),i=Rs(n);return Xa.useCallback((r,n)=>o(e.util.prefetch(t,r,{...i,...n})),[t,o,i])}};function l(e,t,r){if(t?.endpointName&&e.isUninitialized){const{endpointName:e}=t,n=c.endpointDefinitions[e];r!==Oa&&s({queryArgs:t.originalArgs,endpointDefinition:n,endpointName:e})===s({queryArgs:r,endpointDefinition:n,endpointName:e})&&(t=void 0)}let n=e.isSuccess?e.data:t?.data;void 0===n&&(n=e.data);const o=void 0!==n,i=e.isLoading,a=(!t||t.isLoading||t.isUninitialized)&&!o&&i,u=e.isSuccess||o&&(i&&!t?.isError||e.isUninitialized);return{...e,data:n,currentData:e.data,isFetching:i,isLoading:a,isSuccess:u}}function f(e,t,r){if(t?.endpointName&&e.isUninitialized){const{endpointName:e}=t,n=c.endpointDefinitions[e];r!==Oa&&s({queryArgs:t.originalArgs,endpointDefinition:n,endpointName:e})===s({queryArgs:r,endpointDefinition:n,endpointName:e})&&(t=void 0)}let n=e.isSuccess?e.data:t?.data;void 0===n&&(n=e.data);const o=void 0!==n,i=e.isLoading,a=(!t||t.isLoading||t.isUninitialized)&&!o&&i,u=e.isSuccess||i&&o;return{...e,data:n,currentData:e.data,isFetching:i,isLoading:a,isSuccess:u}}function d(t,n,{refetchOnReconnect:o,refetchOnFocus:i,refetchOnMountOrArgChange:a,skip:s=!1,pollingInterval:l=0,skipPollingIfUnfocused:f=!1,...d}={}){const{initiate:p}=e.endpoints[t],y=r(),h=Xa.useRef(void 0);if(!h.current){const t=y(e.internalActions.internal_getRTKQSubscriptions());if("production"!==process.env.NODE_ENV&&("object"!=typeof t||"string"==typeof t?.type))throw new Error("production"===process.env.NODE_ENV?ot(37):`Warning: Middleware for RTK-Query API at reducerPath "${e.reducerPath}" has not been added to the store.\n You must add the middleware for RTK-Query to function correctly!`);h.current=t}const m=Ts(s?Oa:n,Pa,c.endpointDefinitions[t],t),g=Rs({refetchOnReconnect:o,refetchOnFocus:i,pollingInterval:l,skipPollingIfUnfocused:f}),b=Rs(d.initialPageParam),v=Xa.useRef(void 0);let{queryCacheKey:w,requestId:E}=v.current||{},S=!1;w&&E&&(S=h.current.isRequestSubscribed(w,E));const O=!S&&void 0!==v.current;return u(()=>{O&&(v.current=void 0)},[O]),u(()=>{const e=v.current;if("undefined"!=typeof process&&"removeMeOnCompilation"===process.env.NODE_ENV&&console.log(O),m===Oa)return e?.unsubscribe(),void(v.current=void 0);const r=v.current?.subscriptionOptions;if(e&&e.arg===m)g!==r&&e.updateSubscriptionOptions(g);else{e?.unsubscribe();const r=y(p(m,{subscriptionOptions:g,forceRefetch:a,...Os(c.endpointDefinitions[t])?{initialPageParam:b}:{}}));v.current=r}},[y,p,a,m,g,O,b,t]),[v,y,p,g]}function p(t,r){return(i,{skip:u=!1,selectFromResult:l}={})=>{const{select:f}=e.endpoints[t],d=Ts(u?Oa:i,s,c.endpointDefinitions[t],t),p=Xa.useRef(void 0),y=Xa.useMemo(()=>a([f(d),(e,t)=>t,e=>d],r,{memoizeOptions:{resultEqualityCheck:as}}),[f,d]),h=Xa.useMemo(()=>l?a([y],l,{devModeChecks:{identityFunctionCheck:"never"}}):y,[y,l]),m=n(e=>h(e,p.current),as),g=o(),b=y(g.getState(),p.current);return ks(()=>{p.current=b},[b]),m}}function y(e){Xa.useEffect(()=>()=>{e.current?.unsubscribe?.(),e.current=void 0},[e])}function h(e){if(!e.current)throw new Error("production"===process.env.NODE_ENV?ot(38):"Cannot refetch a query that has not been started yet.");return e.current.refetch()}}({api:o,moduleOptions:{batch:e,hooks:t,unstable__sideEffectsInRender:n,createSelector:r},serializeQueryArgs:i,context:a});return _s(s,{usePrefetch:f}),_s(a,{batch:e}),{injectEndpoint(e,t){if("query"===t.type){const{useQuery:t,useLazyQuery:r,useLazyQuerySubscription:n,useQueryState:i,useQuerySubscription:a}=c(e);_s(s.endpoints[e],{useQuery:t,useLazyQuery:r,useLazyQuerySubscription:n,useQueryState:i,useQuerySubscription:a}),o[`use${Es(e)}Query`]=t,o[`useLazy${Es(e)}Query`]=r}if(function(e){return"mutation"===e.type}(t)){const t=l(e);_s(s.endpoints[e],{useMutation:t}),o[`use${Es(e)}Mutation`]=t}else if(Os(t)){const{useInfiniteQuery:t,useInfiniteQuerySubscription:r,useInfiniteQueryState:n}=u(e);_s(s.endpoints[e],{useInfiniteQuery:t,useInfiniteQuerySubscription:r,useInfiniteQueryState:n}),o[`use${Es(e)}InfiniteQuery`]=t}}}}}})());const qs={baseUrl:process.env.REACT_APP_API_BASE_URL||"http://localhost:4000/fear/api/",timeout:3e4,credentials:"include",prepareHeaders:(e,{getState:t})=>{e.set("Content-Type","application/json");const r=t()?.auth?.token;return r&&e.set("Authorization",`Bearer ${r}`),e}},Fs={GET:"GET",POST:"POST",PUT:"PUT",PATCH:"PATCH",DELETE:"DELETE"},Ms={getAll:{method:Fs.GET,url:e=>`${e}/all`,providesTags:e=>[{type:e,id:"LIST"}]},getById:{method:Fs.GET,url:(e,t)=>`${e}/${t}`,providesTags:(e,t)=>[{type:e,id:t}]},create:{method:Fs.POST,url:e=>`${e}`,invalidatesTags:e=>[{type:e,id:"LIST"}]},update:{method:Fs.PUT,url:(e,t)=>`${e}/${t}`,invalidatesTags:(e,t)=>[{type:e,id:t},{type:e,id:"LIST"}]},patch:{method:Fs.PATCH,url:(e,t)=>`${e}/${t}`,invalidatesTags:(e,t)=>[{type:e,id:t},{type:e,id:"LIST"}]},delete:{method:Fs.DELETE,url:(e,t)=>`${e}/${t}`,invalidatesTags:(e,t)=>[{type:e,id:t},{type:e,id:"LIST"}]},search:{method:Fs.GET,url:e=>`${e}/search`,providesTags:e=>[{type:e,id:"SEARCH"}]}},Us=e=>e.status?{status:e.status,message:e.data?.message||`HTTP Error ${e.status}`,data:e.data}:{status:"FETCH_ERROR",message:e.message||"Network error occurred",error:e.error},Ls=(e,t,r={})=>{const{method:n,url:o}=e;let i={method:n,url:"function"==typeof o?o(t,r.id,r):o};return n!==Fs.GET&&n!==Fs.DELETE&&(i.body=r.data||r),n===Fs.GET&&r.params&&(i.params=r.params),i},$s=(e,t={})=>{(e=>{if(!e||"string"!=typeof e)throw new Error("SliceName must be a non-empty string")})(e);const r={tagTypes:["Product","Order","User","Category"],baseQuery:{},includeStandardEndpoints:!0,...t},n=(o=e).charAt(0).toUpperCase()+o.slice(1);var o;r.tagTypes.includes(n)||r.tagTypes.push(n);const i={...qs,...r.baseQuery},a=Ds({reducerPath:`${e}Api`,tagTypes:r.tagTypes,baseQuery:Xi(i),endpoints:()=>({})}),s=(t,r)=>{const{method:n=Fs.GET,url:o,type:i=(n===Fs.GET?"query":"mutation"),providesTags:s,invalidatesTags:c,transformResponse:u,transformErrorResponse:l=Us}=r;return a.injectEndpoints({endpoints:r=>({[t]:r[i]({query:(t={})=>Ls({method:n,url:o},e,t),providesTags:s?(t,r,n)=>s(e,n?.id,t,r,n):void 0,invalidatesTags:c?(t,r,n)=>c(e,n?.id,t,r,n):void 0,transformResponse:u,transformErrorResponse:l})})})},c=t=>a.injectEndpoints({endpoints:r=>{const n={};return Object.entries(t).forEach(([t,o])=>{const{method:i=Fs.GET,url:a,type:s=(i===Fs.GET?"query":"mutation"),providesTags:c,invalidatesTags:u,transformResponse:l,transformErrorResponse:f=Us}=o;n[t]=r[s]({query:(t={})=>Ls({method:i,url:a},e,t),providesTags:c?(t,r,n)=>c(e,n?.id,t,r,n):void 0,invalidatesTags:u?(t,r,n)=>u(e,n?.id,t,r,n):void 0,transformResponse:l,transformErrorResponse:f})}),n}}),u=()=>{const e={};return Object.entries(Ms).forEach(([t,r])=>{e[t]={method:r.method,url:r.url,providesTags:r.providesTags,invalidatesTags:r.invalidatesTags}}),c(e)};return{sliceName:e,entityTagType:n,baseApi:a,inject:s,injectMany:c,create:()=>{let e=a;return r.includeStandardEndpoints&&(e=u()),e},createStandard:u,createBulk:()=>{const t={bulkCreate:{method:Fs.POST,url:`${e}/bulk`,invalidatesTags:()=>[{type:n,id:"LIST"}]},bulkUpdate:{method:Fs.PUT,url:`${e}/bulk`,invalidatesTags:()=>[{type:n,id:"LIST"}]},bulkDelete:{method:Fs.DELETE,url:`${e}/bulk`,invalidatesTags:()=>[{type:n,id:"LIST"}]}};return c(t)},createCustom:(e,t)=>s(e,t),getTagTypes:()=>[...r.tagTypes],getBaseUrl:()=>i.baseUrl,getReducerPath:()=>a.reducerPath,withAuth:t=>$s(e,{...r,baseQuery:{...i,prepareHeaders:(e,r)=>(e.set("Authorization",`Bearer ${t}`),qs.prepareHeaders(e,r))}}),withBaseUrl:t=>$s(e,{...r,baseQuery:{...i,baseUrl:t}})}};$s.createComplete=(e,t={})=>$s(e,t).create(),$s.createCustom=(e,t,r={})=>$s(e,{...r,includeStandardEndpoints:!1}).injectMany(t),$s.getStandardEndpoints=()=>({...Ms}),$s.getHttpMethods=()=>({...Fs}),exports.API=Pi,exports.ApiFactory=$s,exports.CacheFactory=hi,exports.FeatureFactory=function(e,t={},r=null){if(!e||"string"!=typeof e)throw new Error("Entity name must be provided as a string");const n=nt(),o=(e,t)=>{if(!e||!t)throw new Error("Both source and destination objects must be provided");return Object.keys(e).reduce((t,r)=>(Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]),t),{...t})},i=(e,t,r)=>{Object.entries(t).forEach(([t,n])=>{e.addCase(n.pending,e=>{e.loading=!0,e.error=null}).addCase(n.fulfilled,(e,n)=>{e.loading=!1,e.success=!0,e.data=n.payload,("fetchOne"===t&&Array.isArray(n.payload)||Array.isArray(n.payload)&&n.payload.length>0)&&(e[r]=n.payload[0])}).addCase(n.rejected,(e,t)=>{e.loading=!1,e.success=!1,e.error=t.error||t.payload})})};return{entity:e,reducers:t,adapter:n,manager:(e={})=>{const t={...e};let r=s(t);return{reduce:(e,t)=>r(e,t),add:(e,n)=>{e&&"string"==typeof e?t[e]?console.warn(`Reducer with key '${e}' already exists`):(t[e]=n,r=s(t)):console.warn("Invalid reducer key provided")},remove:e=>{e&&t[e]?(delete t[e],r=s(t)):console.warn(`Reducer with key '${e}' does not exist`)},getReducerMap:()=>({...t})}},inject:o,create:(r={})=>{const{service:n=null,initialState:a=null}=r,s=e,c=(e=>({fetch:Ii.create(e,"all"),fetchOne:Ii.create(e,"one"),search:Ii.post(e,"search")}))(s);return{slice:Ke({name:s,initialState:a||Mi(s),reducers:t,extraReducers:e=>{if(i(e,c,s),n&&"object"==typeof n){const t=Object.entries(n).reduce((e,[t,r])=>(c[t]||(e[t]=r),e),{});i(e,t,s)}}}),asyncActions:n?o(c,n):c}},getEntityName:()=>e,getAdapter:()=>n}},exports.StateFactory=Mi,exports.ThunkFactory=Ii;
|
|
20
20
|
//# sourceMappingURL=index.js.map
|