Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@axios-use/vue

Package Overview
Dependencies
Maintainers
0
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@axios-use/vue - npm Package Compare versions

Comparing version 0.3.0-alpha.1 to 0.3.0-alpha.2

2

dist/axios-use-vue.umd.js

@@ -1,2 +0,2 @@

(function(r,c){typeof exports=="object"&&typeof module!="undefined"?c(exports,require("vue"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","axios"],c):(r=typeof globalThis!="undefined"?globalThis:r||self,c(r.AxiosUseVue={},r.Vue,r.Axios))})(this,function(r,c,s){"use strict";var X=Object.defineProperty,Y=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var L=(r,c,s)=>c in r?X(r,c,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[c]=s,D=(r,c)=>{for(var s in c||(c={}))F.call(c,s)&&L(r,s,c[s]);if(O)for(var s of O(c))H.call(c,s)&&L(r,s,c[s]);return r},M=(r,c)=>Y(r,z(c));var V=(r,c,s)=>new Promise((v,S)=>{var w=g=>{try{I(s.next(g))}catch(A){S(A)}},U=g=>{try{I(s.throw(g))}catch(A){S(A)}},I=g=>g.done?v(g.value):Promise.resolve(g.value).then(w,U);I((s=s.apply(r,c)).next())});const v="[@axios-use/vue warn]: getUseRequestConfig() can only be used inside setup() or functional components.",S=Symbol("axios_use_vue_config"),w=(n,e)=>{Number(n.version.split(".")[0])===2?n.mixin({beforeCreate(){if(!this._provided){const a={};Object.defineProperty(this,"_provided",{get:()=>a,set:u=>Object.assign(a,u)})}this._provided[S]=e}}):n.provide(S,e||{})},U=n=>n==null?void 0:n.data,I=()=>{const n=!!c.getCurrentInstance();n||console.warn(v);const{instance:e=s,getResponseItem:t=U}=n?c.inject(S,{}):{};return{instance:e,getResponseItem:t}},g={install(n,e){w(n,e)}};function A(n){return n}const G=n=>n;function j(n){var f,h,R,C,q,l,o;const e=n,t=n,a=(h=(f=e==null?void 0:e.response)==null?void 0:f.data)!=null?h:t==null?void 0:t.data,u=(l=(q=(R=a==null?void 0:a.code)!=null?R:e==null?void 0:e.code)!=null?q:(C=e==null?void 0:e.response)==null?void 0:C.status)!=null?l:t==null?void 0:t.status,T=(e==null?void 0:e.message)||((o=e==null?void 0:e.response)==null?void 0:o.statusText)||(t==null?void 0:t.statusText);return{code:u,data:a,message:T,isCancel:s.isCancel(n),original:n}}function E(n,e){const t=I(),a=(e==null?void 0:e.instance)||t.instance,u=c.shallowRef([]),T=c.computed(()=>c.unref(u).length>0),{onCompleted:f,onError:h}=e||{},R=l=>{const o=c.unref(u);l&&o.length>0&&(u.value=o.filter(y=>y.token!==l))},C=l=>{const o=c.unref(u);o.length>0&&(o.map(y=>y.cancel(l)),u.value=[])};return c.onUnmounted(()=>{C()}),[(...l)=>{const o=n(...l),y=s.CancelToken.source();return{ready:()=>(u.value=[...c.unref(u),y],a(M(D({},o),{cancelToken:y.token})).then(_=>{R(y.token);const i=e!=null&&e.getResponseItem?e.getResponseItem(_):t.getResponseItem(_);return f==null||f(i,_,l),[i,_]}).catch(_=>{R(y.token);const i=j(_);throw h==null||h(i,l),i})),cancel:y.cancel}},{clear:C,hasPending:T}]}function B(n,e){const t=c.ref(e),a=u=>{t.value=n(t.value,u)};return[c.readonly(t),a]}function k(n){return n&&Array.isArray(n)?n.map(e=>c.unref(e)):[]}function J(n){return n&&Array.isArray(n)?n.some(c.isReactive):!1}const N="A new request has been made before completing the last one";function K(n,e){if(n)return e&&typeof e=="function"?e(...n):!0}function Q(n,e){const t=e.type==="success"?e.response:n.response;return{data:e.type==="success"?e.data:n.data,response:t,error:e.type==="error"?e.error:void 0,isLoading:e.type==="start"}}function W(n,e,t){const[a,{clear:u}]=E(n,{onCompleted:t==null?void 0:t.onCompleted,onError:t==null?void 0:t.onError,instance:t==null?void 0:t.instance,getResponseItem:t==null?void 0:t.getResponseItem}),[T,f]=B(Q,D({isLoading:K(e&&k(e),t==null?void 0:t.filter)},t==null?void 0:t.defaultState)),h=(...d)=>{u(N);const{ready:_,cancel:i}=a(...d);return f({type:"start"}),_().then(([m,b])=>{f({type:"success",data:m,response:b})}).catch(m=>{const b=m;b.isCancel||f({type:"error",error:b})}),i},R=(...d)=>V(this,null,function*(){u(N);const{ready:_}=a(...d);try{f({type:"start"});const[i,m]=yield _();return f({type:"success",data:i,response:m}),[i,m]}catch(i){const m=i;throw m.isCancel||f({type:"error",error:m}),i}}),C=(...d)=>t!=null&&t.asyncReq?R(...d):h(...d),q=()=>{const d=k(e||[]);if(typeof(t==null?void 0:t.filter)=="function"?t.filter(...d):!0)return h(...d)},l=d=>{f({type:"reset"}),u(d)},o=c.computed(()=>e&&k(e));return c.watch(o,d=>{d&&q()},{immediate:!0,deep:J(e)}),[c.computed(()=>c.unref(T)),C,q,l]}r._request=A,r.createRequestError=j,r.default=g,r.request=G,r.useRequest=E,r.useResource=W,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
(function(r,c){typeof exports=="object"&&typeof module!="undefined"?c(exports,require("vue"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","axios"],c):(r=typeof globalThis!="undefined"?globalThis:r||self,c(r.AxiosUseVue={},r.Vue,r.Axios))})(this,function(r,c,u){"use strict";var X=Object.defineProperty,Y=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var L=(r,c,u)=>c in r?X(r,c,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[c]=u,k=(r,c)=>{for(var u in c||(c={}))F.call(c,u)&&L(r,u,c[u]);if(N)for(var u of N(c))H.call(c,u)&&L(r,u,c[u]);return r},M=(r,c)=>Y(r,z(c));var V=(r,c,u)=>new Promise((v,S)=>{var w=R=>{try{A(u.next(R))}catch(T){S(T)}},U=R=>{try{A(u.throw(R))}catch(T){S(T)}},A=R=>R.done?v(R.value):Promise.resolve(R.value).then(w,U);A((u=u.apply(r,c)).next())});const v="[@axios-use/vue warn]: getUseRequestConfig() can only be used inside setup() or functional components.",S=Symbol("axios_use_vue_config"),w=(n,e)=>{Number(n.version.split(".")[0])===2?n.mixin({beforeCreate(){if(!this._provided){const a={};Object.defineProperty(this,"_provided",{get:()=>a,set:s=>Object.assign(a,s)})}this._provided[S]=e}}):n.provide(S,e||{})},U=n=>n==null?void 0:n.data,A=()=>{const n=!!c.getCurrentInstance();n||console.warn(v);const{instance:e=u,getResponseItem:t=U}=n?c.inject(S,{}):{};return{instance:e,getResponseItem:t}},R={install(n,e){w(n,e)}};function T(n){return n}const G=n=>n;function D(n){var f,m,q,C,I,l,y;const e=n,t=n,a=(m=(f=e==null?void 0:e.response)==null?void 0:f.data)!=null?m:t==null?void 0:t.data,s=(l=(I=(q=a==null?void 0:a.code)!=null?q:e==null?void 0:e.code)!=null?I:(C=e==null?void 0:e.response)==null?void 0:C.status)!=null?l:t==null?void 0:t.status,b=(e==null?void 0:e.message)||((y=e==null?void 0:e.response)==null?void 0:y.statusText)||(t==null?void 0:t.statusText);return{code:s,data:a,message:b,isCancel:u.isCancel(n),original:n}}function j(n,e){const t=A(),a=(e==null?void 0:e.instance)||t.instance,s=c.shallowRef([]),b=c.computed(()=>c.unref(s).length>0),{onCompleted:f,onError:m}=e||{},q=l=>{const y=c.unref(s);l&&y.length>0&&(s.value=y.filter(g=>g.token!==l))},C=l=>{const y=c.unref(s);y.length>0&&(y.map(g=>g.cancel(l)),s.value=[])};return c.onUnmounted(()=>{C()}),[(...l)=>{const y=n(...l),g=u.CancelToken.source();return{ready:()=>(s.value=[...c.unref(s),g],a(M(k({},y),{cancelToken:g.token})).then(h=>{q(g.token);const _=e!=null&&e.getResponseItem?e.getResponseItem(h):t.getResponseItem(h);return f==null||f(_,h,l),[_,h]}).catch(h=>{q(g.token);const _=D(h);throw m==null||m(_,l),_})),cancel:g.cancel}},{clear:C,hasPending:b}]}function B(n,e){const t=c.ref(e),a=s=>{t.value=n(t.value,s,e)};return[c.readonly(t),a]}function O(n){return n&&Array.isArray(n)?n.map(e=>c.unref(e)):[]}function J(n){return n&&Array.isArray(n)?n.some(c.isReactive):!1}const E="A new request has been made before completing the last one";function K(n,e){if(n)return e&&typeof e=="function"?e(...n):!0}function Q(n,e,t){let a=n.data,s=n.response;return e.type==="success"&&(a=e.data,s=e.response),(e.type==="start"||e.type==="reset")&&e.reset&&(a=t==null?void 0:t.data,s=t==null?void 0:t.response),{data:a,response:s,error:e.type==="error"?e.error:void 0,isLoading:e.type==="start"}}function W(n,e,t){const[a,{clear:s}]=j(n,{onCompleted:t==null?void 0:t.onCompleted,onError:t==null?void 0:t.onError,instance:t==null?void 0:t.instance,getResponseItem:t==null?void 0:t.getResponseItem}),[b,f]=B(Q,k({isLoading:K(e&&O(e),t==null?void 0:t.filter)},t==null?void 0:t.defaultState)),m=(...d)=>{s(E);const{ready:h,cancel:_}=a(...d);return f({type:"start",reset:t==null?void 0:t.resetOnReq}),h().then(([o,i])=>{f({type:"success",data:o,response:i})}).catch(o=>{const i=o;i.isCancel||f({type:"error",error:i})}),_},q=(...d)=>V(this,null,function*(){s(E);const{ready:h}=a(...d);try{f({type:"start",reset:t==null?void 0:t.resetOnReq});const[_,o]=yield h();return f({type:"success",data:_,response:o}),[_,o]}catch(_){const o=_;throw o.isCancel||f({type:"error",error:o}),_}}),C=(...d)=>t!=null&&t.asyncReq?q(...d):m(...d),I=()=>{const d=O(e||[]);if(typeof(t==null?void 0:t.filter)=="function"?t.filter(...d):!0)return m(...d)},l=d=>{f({type:"reset"}),s(d)},y=c.computed(()=>e&&O(e));return c.watch(y,d=>{d&&I()},{immediate:!0,deep:J(e)}),[c.computed(()=>c.unref(b)),C,I,l]}r._request=T,r.createRequestError=D,r.default=R,r.request=G,r.useRequest=j,r.useResource=W,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
//# sourceMappingURL=axios-use-vue.umd.js.map

@@ -29,4 +29,6 @@ import type { ComputedRef } from "vue";

asyncReq?: A;
/** Sets the state to initialState before executing the promise. */
resetOnReq?: boolean;
};
export type RequestDepsParameters<T extends Request> = Parameters<T> | FullRefArrayItem<Parameters<T>> | ComputedRef<Parameters<T>>;
export declare function useResource<T extends Request, A extends boolean = false>(fn: T, requestParams?: RequestDepsParameters<T> | false, options?: UseResourceOptions<T, A>): UseResourceResult<T, A>;
var b = Object.defineProperty;
var _ = Object.getOwnPropertySymbols;
var n = Object.getOwnPropertySymbols;
var x = Object.prototype.hasOwnProperty, I = Object.prototype.propertyIsEnumerable;

@@ -7,36 +7,36 @@ var E = (t, r, e) => r in t ? b(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e, C = (t, r) => {

x.call(r, e) && E(t, e, r[e]);
if (_)
for (var e of _(r))
if (n)
for (var e of n(r))
I.call(r, e) && E(t, e, r[e]);
return t;
};
var v = (t, r, e) => new Promise((l, d) => {
var v = (t, r, e) => new Promise((y, a) => {
var g = (u) => {
try {
y(e.next(u));
} catch (s) {
d(s);
s(e.next(u));
} catch (R) {
a(R);
}
}, a = (u) => {
}, f = (u) => {
try {
y(e.throw(u));
} catch (s) {
d(s);
s(e.throw(u));
} catch (R) {
a(R);
}
}, y = (u) => u.done ? l(u.value) : Promise.resolve(u.value).then(g, a);
y((e = e.apply(t, r)).next());
}, s = (u) => u.done ? y(u.value) : Promise.resolve(u.value).then(g, f);
s((e = e.apply(t, r)).next());
});
import { computed as w, watch as G, unref as M } from "vue";
import { useRequest as N } from "./useRequest.js";
import { useReducer as Q, unrefs as m, hasReactive as T } from "./utils.js";
import { computed as w, watch as O, unref as q } from "vue";
import { useRequest as G } from "./useRequest.js";
import { useReducer as M, unrefs as m, hasReactive as N } from "./utils.js";
const A = "A new request has been made before completing the last one";
function U(t, r) {
function Q(t, r) {
if (t)
return r && typeof r == "function" ? r(...t) : !0;
}
function j(t, r) {
const e = r.type === "success" ? r.response : t.response;
return {
data: r.type === "success" ? r.data : t.data,
response: e,
function T(t, r, e) {
let y = t.data, a = t.response;
return r.type === "success" && (y = r.data, a = r.response), (r.type === "start" || r.type === "reset") && r.reset && (y = e == null ? void 0 : e.data, a = e == null ? void 0 : e.response), {
data: y,
response: a,
error: r.type === "error" ? r.error : void 0,

@@ -46,4 +46,4 @@ isLoading: r.type === "start"

}
function J(t, r, e) {
const [l, { clear: d }] = N(t, {
function F(t, r, e) {
const [y, { clear: a }] = G(t, {
onCompleted: e == null ? void 0 : e.onCompleted,

@@ -53,37 +53,37 @@ onError: e == null ? void 0 : e.onError,

getResponseItem: e == null ? void 0 : e.getResponseItem
}), [g, a] = Q(j, C({
isLoading: U(
}), [g, f] = M(T, C({
isLoading: Q(
r && m(r),
e == null ? void 0 : e.filter
)
}, e == null ? void 0 : e.defaultState)), y = (...c) => {
d(A);
const { ready: h, cancel: n } = l(...c);
return a({ type: "start" }), h().then(([f, R]) => {
a({ type: "success", data: f, response: R });
}).catch((f) => {
const R = f;
R.isCancel || a({ type: "error", error: R });
}), n;
}, e == null ? void 0 : e.defaultState)), s = (...c) => {
a(A);
const { ready: h, cancel: l } = y(...c);
return f({ type: "start", reset: e == null ? void 0 : e.resetOnReq }), h().then(([d, _]) => {
f({ type: "success", data: d, response: _ });
}).catch((d) => {
const _ = d;
_.isCancel || f({ type: "error", error: _ });
}), l;
}, u = (...c) => v(this, null, function* () {
d(A);
const { ready: h } = l(...c);
a(A);
const { ready: h } = y(...c);
try {
a({ type: "start" });
const [n, f] = yield h();
return a({ type: "success", data: n, response: f }), [n, f];
} catch (n) {
const f = n;
throw f.isCancel || a({ type: "error", error: f }), n;
f({ type: "start", reset: e == null ? void 0 : e.resetOnReq });
const [l, d] = yield h();
return f({ type: "success", data: l, response: d }), [l, d];
} catch (l) {
const d = l;
throw d.isCancel || f({ type: "error", error: d }), l;
}
}), s = (...c) => e != null && e.asyncReq ? u(...c) : y(...c), S = () => {
}), R = (...c) => e != null && e.asyncReq ? u(...c) : s(...c), S = () => {
const c = m(r || []);
if (typeof (e == null ? void 0 : e.filter) == "function" ? e.filter(...c) : !0)
return y(...c);
return s(...c);
}, L = (c) => {
a({ type: "reset" }), d(c);
f({ type: "reset" }), a(c);
}, D = w(
() => r && m(r)
);
return G(
return O(
D,

@@ -95,8 +95,8 @@ (c) => {

immediate: !0,
deep: T(r)
deep: N(r)
}
), [w(() => M(g)), s, S, L];
), [w(() => q(g)), R, S, L];
}
export {
J as useResource
F as useResource
};
import type { ComputedRef, Ref } from "vue";
type Reducer<S, A> = (prevState: S, action: A) => S;
type Reducer<S, A> = (prevState: S, action: A, initSate?: Partial<S>) => S;
type ReducerState<R extends Reducer<any, any>> = R extends Reducer<infer S, any> ? S : never;

@@ -4,0 +4,0 @@ type ReducerAction<R extends Reducer<any, any>> = R extends Reducer<any, infer A> ? A : never;

@@ -1,18 +0,18 @@

import { ref as i, readonly as a, unref as f, isReactive as o } from "vue";
function c(e, r) {
const t = i(r), n = (u) => {
t.value = e(t.value, u);
import { ref as f, readonly as o, unref as s, isReactive as a } from "vue";
function i(e, r) {
const t = f(r), n = (u) => {
t.value = e(t.value, u, r);
};
return [a(t), n];
return [o(t), n];
}
function y(e) {
return e && Array.isArray(e) ? e.map((r) => f(r)) : [];
return e && Array.isArray(e) ? e.map((r) => s(r)) : [];
}
function l(e) {
return e && Array.isArray(e) ? e.some(o) : !1;
function m(e) {
return e && Array.isArray(e) ? e.some(a) : !1;
}
export {
l as hasReactive,
m as hasReactive,
y as unrefs,
c as useReducer
i as useReducer
};
{
"name": "@axios-use/vue",
"version": "0.3.0-alpha.1",
"version": "0.3.0-alpha.2",
"description": "A Vue composition utilities for Axios.",

@@ -5,0 +5,0 @@ "type": "module",

@@ -156,2 +156,3 @@ <br>

| options.getResponseItem | function | custom returns the value of `data`(index 0). |
| options.asyncReq | boolean | Control the return value of the request |

@@ -188,2 +189,4 @@ ```ts

type Fetch = (...args: Parameters<T>) => Canceler;
// if `options.asyncReq` is `true`
type Fetch = (...args: Parameters<T>) => Promise<[Payload<T>, AxiosResponse]>;

@@ -190,0 +193,0 @@ // 1. Same as `fetch`. But no parameters required. Inherit `useResource` parameters

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc