@zodios/react
Advanced tools
Comparing version 10.4.2 to 10.4.3
@@ -7,5 +7,5 @@ 'use strict'; | ||
function l(r,s){let e={...r};for(let t of s)delete e[t];return e}function p(r,s){let e={};if(r)for(let t of s)t in r&&r[t]!==void 0&&(e[t]=r[t]);return e}function P(r){return r.charAt(0).toUpperCase()+r.slice(1)}function D(r){return Boolean(r)}function A(...r){let s=r.filter(D);if(s.length<2)return s[0];let e=new AbortController;function t(){e.abort(),s.forEach(o=>{o.removeEventListener("abort",t);});}return s.forEach(o=>{o.aborted?t():o.addEventListener("abort",t);}),e.signal}var T=class{constructor(s,e,t={}){this.apiName=s;this.zodios=e;this.options=t;this.injectAliasEndpoints();}injectAliasEndpoints(){this.zodios.api.forEach(s=>{s.alias&&(["post","put","patch","delete"].includes(s.method)?s.method==="post"&&s.immutable?this[`use${P(s.alias)}`]=(e,t,o)=>this.useImmutableQuery(s.path,e,t,o):this[`use${P(s.alias)}`]=(e,t)=>this.useMutation(s.method,s.path,e,t):this[`use${P(s.alias)}`]=(e,t)=>this.useQuery(s.path,e,t));});}getEndpointByPath(s,e){return this.zodios.api.find(t=>t.method===s&&t.path===e)}getEndpointByAlias(s){return this.zodios.api.find(e=>e.alias===s)}getKeyByPath(s,e,t){let o=this.getEndpointByPath(s,e);if(!o)throw new Error(`No endpoint found for path '${s} ${e}'`);if(t){let a=p(t,["params","queries"]);return [{api:this.apiName,path:o.path},a]}return [{api:this.apiName,path:o.path}]}getKeyByAlias(s,e){let t=this.getEndpointByAlias(s);if(!t)throw new Error(`No endpoint found for alias '${s}'`);if(e){let o=p(e,["params","queries"]);return [{api:this.apiName,path:t.path},o]}return [{api:this.apiName,path:t.path}]}useQuery(s,...[e,t]){let o=p(e,["params","queries"]),a=[{api:this.apiName,path:s},o],d=this.options.shouldAbortOnUnmount?({signal:y})=>this.zodios.get(s,{...e,signal:A(y,e==null?void 0:e.signal)}):()=>this.zodios.get(s,e),u=reactQuery.useQueryClient(),h=()=>u.invalidateQueries(a),i=reactQuery.useQuery(a,d,t);return i.invalidate=h,i.key=a,i}useImmutableQuery(s,e,...[t,o]){let a=p(t,["params","queries"]),d=[{api:this.apiName,path:s},a,e],u=this.options.shouldAbortOnUnmount?({signal:n})=>this.zodios.post(s,e,{...t,signal:A(n,t==null?void 0:t.signal)}):()=>this.zodios.post(s,e,t),h=reactQuery.useQueryClient(),i=()=>h.invalidateQueries(d),y=reactQuery.useQuery(d,u,o);return y.invalidate=i,y.key=d,y}useInfiniteQuery(s,...[e,t]){let o=p(e,["params","queries"]);o.params&&t&&(o.params=l(o.params,t.getPageParamList())),o.queries&&t&&(o.queries=l(o.queries,t.getPageParamList()));let a=[{api:this.apiName,path:s},o],d=this.options.shouldAbortOnUnmount?({pageParam:i=void 0,signal:y})=>this.zodios.get(s,{...e,queries:{...e==null?void 0:e.queries,...i==null?void 0:i.queries},params:{...e==null?void 0:e.params,...i==null?void 0:i.params},signal:A(y,e==null?void 0:e.signal)}):({pageParam:i=void 0})=>this.zodios.get(s,{...e,queries:{...e==null?void 0:e.queries,...i==null?void 0:i.queries},params:{...e==null?void 0:e.params,...i==null?void 0:i.params}}),u=reactQuery.useQueryClient();return {invalidate:()=>u.invalidateQueries(a),key:a,...reactQuery.useInfiniteQuery(a,d,t)}}useImmutableInfiniteQuery(s,e,...[t,o]){let a=p(t,["params","queries"]);a.params&&o&&(a.params=l(a.params,o.getPageParamList())),a.queries&&o&&(a.queries=l(a.queries,o.getPageParamList()));let d;e&&o&&(d=l(e,o.getPageParamList()));let u=[{api:this.apiName,path:s},a,d],h=this.options.shouldAbortOnUnmount?({pageParam:n=void 0,signal:O})=>this.zodios.post(s,{...e,...n==null?void 0:n.body},{...t,queries:{...t==null?void 0:t.queries,...n==null?void 0:n.queries},params:{...t==null?void 0:t.params,...n==null?void 0:n.params},signal:A(O,t==null?void 0:t.signal)}):({pageParam:n=void 0})=>this.zodios.post(s,{...e,...n==null?void 0:n.body},{...t,queries:{...t==null?void 0:t.queries,...n==null?void 0:n.queries},params:{...t==null?void 0:t.params,...n==null?void 0:n.params}}),i=reactQuery.useQueryClient();return {invalidate:()=>i.invalidateQueries(u),key:u,...reactQuery.useInfiniteQuery(u,h,o)}}useMutation(s,e,...[t,o]){return reactQuery.useMutation(d=>this.zodios.request({...t,method:s,url:e,data:d}),o)}useGet(s,...e){return this.useQuery(s,...e)}usePost(s,...e){return this.useMutation("post",s,...e)}usePut(s,...e){return this.useMutation("put",s,...e)}usePatch(s,...e){return this.useMutation("patch",s,...e)}useDelete(s,...e){return this.useMutation("delete",s,...e)}},R=T; | ||
function l(r,s){let e={...r};for(let t of s)delete e[t];return e}function p(r,s){let e={};if(r)for(let t of s)t in r&&r[t]!==void 0&&(e[t]=r[t]);return e}function P(r){return r.charAt(0).toUpperCase()+r.slice(1)}function D(r){return Boolean(r)}function A(...r){let s=r.filter(D);if(s.length<2)return s[0];let e=new AbortController;function t(){e.abort(),s.forEach(o=>{o.removeEventListener("abort",t);});}return s.forEach(o=>{o.aborted?t():o.addEventListener("abort",t);}),e.signal}var T=class{constructor(s,e,t={}){this.apiName=s;this.zodios=e;this.options=t;this.injectAliasEndpoints();}injectAliasEndpoints(){this.zodios.api.forEach(s=>{s.alias&&(["post","put","patch","delete"].includes(s.method)?s.method==="post"&&s.immutable?this[`use${P(s.alias)}`]=(e,t,o)=>this.useImmutableQuery(s.path,e,t,o):this[`use${P(s.alias)}`]=(e,t)=>this.useMutation(s.method,s.path,e,t):this[`use${P(s.alias)}`]=(e,t)=>this.useQuery(s.path,e,t));});}getEndpointByPath(s,e){return this.zodios.api.find(t=>t.method===s&&t.path===e)}getEndpointByAlias(s){return this.zodios.api.find(e=>e.alias===s)}getKeyByPath(s,e,t){let o=this.getEndpointByPath(s,e);if(!o)throw new Error(`No endpoint found for path '${s} ${e}'`);if(t){let a=p(t,["params","queries"]);return [{api:this.apiName,path:o.path},a]}return [{api:this.apiName,path:o.path}]}getKeyByAlias(s,e){let t=this.getEndpointByAlias(s);if(!t)throw new Error(`No endpoint found for alias '${s}'`);if(e){let o=p(e,["params","queries"]);return [{api:this.apiName,path:t.path},o]}return [{api:this.apiName,path:t.path}]}useQuery(s,...[e,t]){let o=p(e,["params","queries"]),a=[{api:this.apiName,path:s},o],d=this.options.shouldAbortOnUnmount?({signal:u})=>this.zodios.get(s,{...e,signal:A(u,e==null?void 0:e.signal)}):()=>this.zodios.get(s,e),y=reactQuery.useQueryClient(),h=()=>y.invalidateQueries(a),i=reactQuery.useQuery(a,d,t);return i.invalidate=h,i.key=a,i}useImmutableQuery(s,e,...[t,o]){let a=p(t,["params","queries"]),d=[{api:this.apiName,path:s},a,e],y=this.options.shouldAbortOnUnmount?({signal:n})=>this.zodios.post(s,e,{...t,signal:A(n,t==null?void 0:t.signal)}):()=>this.zodios.post(s,e,t),h=reactQuery.useQueryClient(),i=()=>h.invalidateQueries(d),u=reactQuery.useQuery(d,y,o);return u.invalidate=i,u.key=d,u}useInfiniteQuery(s,...[e,t]){let o=p(e,["params","queries"]);o.params&&t&&(o.params=l(o.params,t.getPageParamList())),o.queries&&t&&(o.queries=l(o.queries,t.getPageParamList()));let a=[{api:this.apiName,path:s},o],d=this.options.shouldAbortOnUnmount?({pageParam:i=void 0,signal:u})=>this.zodios.get(s,{...e,queries:{...e==null?void 0:e.queries,...i==null?void 0:i.queries},params:{...e==null?void 0:e.params,...i==null?void 0:i.params},signal:A(u,e==null?void 0:e.signal)}):({pageParam:i=void 0})=>this.zodios.get(s,{...e,queries:{...e==null?void 0:e.queries,...i==null?void 0:i.queries},params:{...e==null?void 0:e.params,...i==null?void 0:i.params}}),y=reactQuery.useQueryClient();return {invalidate:()=>y.invalidateQueries(a),key:a,...reactQuery.useInfiniteQuery(a,d,t)}}useImmutableInfiniteQuery(s,e,...[t,o]){let a=p(t,["params","queries"]);a.params&&o&&(a.params=l(a.params,o.getPageParamList())),a.queries&&o&&(a.queries=l(a.queries,o.getPageParamList()));let d;e&&o&&(d=l(e,o.getPageParamList()));let y=[{api:this.apiName,path:s},a,d],h=this.options.shouldAbortOnUnmount?({pageParam:n=void 0,signal:O})=>this.zodios.post(s,{...e,...n==null?void 0:n.body},{...t,queries:{...t==null?void 0:t.queries,...n==null?void 0:n.queries},params:{...t==null?void 0:t.params,...n==null?void 0:n.params},signal:A(O,t==null?void 0:t.signal)}):({pageParam:n=void 0})=>this.zodios.post(s,{...e,...n==null?void 0:n.body},{...t,queries:{...t==null?void 0:t.queries,...n==null?void 0:n.queries},params:{...t==null?void 0:t.params,...n==null?void 0:n.params}}),i=reactQuery.useQueryClient();return {invalidate:()=>i.invalidateQueries(y),key:y,...reactQuery.useInfiniteQuery(y,h,o)}}useMutation(s,e,...[t,o]){return reactQuery.useMutation(d=>this.zodios.request({...t,method:s,url:e,data:d}),o)}useGet(s,...e){return this.useQuery(s,...e)}usePost(s,...e){return this.useMutation("post",s,...e)}usePut(s,...e){return this.useMutation("put",s,...e)}usePatch(s,...e){return this.useMutation("patch",s,...e)}useDelete(s,...e){return this.useMutation("delete",s,...e)}},R=T; | ||
exports.ZodiosHooks = R; | ||
exports.ZodiosHooksClass = T; |
{ | ||
"name": "@zodios/react", | ||
"description": "React hooks for zodios", | ||
"version": "10.4.2", | ||
"version": "10.4.3", | ||
"main": "lib/index.js", | ||
@@ -51,4 +51,4 @@ "module": "lib/index.mjs", | ||
"devDependencies": { | ||
"@tanstack/react-query": "4.20.9", | ||
"@testing-library/dom": "8.19.1", | ||
"@tanstack/react-query": "4.23.0", | ||
"@testing-library/dom": "8.20.0", | ||
"@testing-library/jest-dom": "5.16.5", | ||
@@ -60,17 +60,17 @@ "@testing-library/react": "13.4.0", | ||
"@types/cors": "2.8.13", | ||
"@types/express": "4.17.15", | ||
"@types/jest": "29.2.5", | ||
"@types/express": "4.17.16", | ||
"@types/jest": "29.4.0", | ||
"@types/node": "18.11.18", | ||
"@types/react": "18.0.26", | ||
"@zodios/core": "10.7.1", | ||
"axios": "1.2.2", | ||
"@types/react": "18.0.27", | ||
"@zodios/core": "10.7.3", | ||
"axios": "1.2.5", | ||
"cors": "2.8.5", | ||
"express": "4.18.2", | ||
"jest": "29.3.1", | ||
"jest-environment-jsdom": "29.3.1", | ||
"jest": "29.4.1", | ||
"jest-environment-jsdom": "29.4.1", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"react-test-renderer": "18.2.0", | ||
"rimraf": "3.0.2", | ||
"ts-jest": "29.0.3", | ||
"rimraf": "4.1.2", | ||
"ts-jest": "29.0.5", | ||
"ts-node": "10.9.1", | ||
@@ -82,5 +82,5 @@ "tsup": "6.3.0", | ||
"resolutions": { | ||
"@types/react": "18.0.26" | ||
"@types/react": "18.0.27" | ||
}, | ||
"dependencies": {} | ||
} |
Sorry, the diff of this file is not supported yet