vue-use-async 1.9.8 → 1.10.1
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/Deferred.d.ts +2 -2
- package/dist/Xhr.d.ts +3 -3
- package/dist/cache.d.ts +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +1 -1
- package/dist/mockXhr.d.ts +1 -3
- package/dist/tests.d.ts +2 -0
- package/dist/useAsync.d.ts +1 -1
- package/dist/useMutation.d.ts +2 -2
- package/dist/useResult.d.ts +1 -1
- package/dist/useSpinner.d.ts +1 -1
- package/dist/useXhr.d.ts +4 -4
- package/package.json +30 -28
package/dist/Deferred.d.ts
CHANGED
package/dist/Xhr.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Obj, XhrConfig, XhrGet } from '
|
|
1
|
+
import type { Obj, XhrConfig, XhrGet } from '.';
|
|
2
2
|
import Deferred from './Deferred';
|
|
3
3
|
export default class Xhr<T> {
|
|
4
4
|
static parseResult(xhr: XMLHttpRequest): Response;
|
|
@@ -7,7 +7,7 @@ export default class Xhr<T> {
|
|
|
7
7
|
onStart: (e: ProgressEvent) => void;
|
|
8
8
|
onAbort: (e: ProgressEvent) => void;
|
|
9
9
|
onProgress: (e: ProgressEvent) => void;
|
|
10
|
-
onEnd: (result:
|
|
10
|
+
onEnd: (result: T | null, e: ProgressEvent) => void;
|
|
11
11
|
static onBeforeSendList: Array<(params: Obj) => Obj>;
|
|
12
12
|
static onBeforeSend(cb: (params: Obj) => Obj): void;
|
|
13
13
|
token: string | null;
|
|
@@ -39,7 +39,7 @@ export default class Xhr<T> {
|
|
|
39
39
|
* @returns {Promise}, consolidate the promise with the `abortXhr` function
|
|
40
40
|
*/
|
|
41
41
|
get(paramsObj?: XhrConfig): XhrGet<T>;
|
|
42
|
-
delete(paramsObj: XhrConfig): Promise<
|
|
42
|
+
delete(paramsObj: XhrConfig): Promise<T>;
|
|
43
43
|
/**
|
|
44
44
|
* Abort xhr query and reject promise
|
|
45
45
|
*/
|
package/dist/cache.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -7,9 +7,7 @@ import useResult from './useResult';
|
|
|
7
7
|
import useXhr from './useXhr';
|
|
8
8
|
import Xhr from './Xhr';
|
|
9
9
|
import useSpinner from './useSpinner';
|
|
10
|
-
export type Obj =
|
|
11
|
-
[id: string]: any;
|
|
12
|
-
};
|
|
10
|
+
export type Obj = Record<string, any>;
|
|
13
11
|
export type Func = (...args: any[]) => any;
|
|
14
12
|
export type UnwrappedPromiseType<T extends (...args: any) => any> = T extends (...args: any) => Promise<infer U> ? U : T extends (...args: any) => infer U ? U : any;
|
|
15
13
|
interface CancellablePromise<T> extends Promise<T> {
|
|
@@ -50,7 +48,7 @@ type Params<Z, A extends unknown[]> = (() => (Z | [...A])) | ComputedRef<Z | [..
|
|
|
50
48
|
...A
|
|
51
49
|
];
|
|
52
50
|
export type RequiredParams<Z extends TypeAllowed, A extends TypeAllowed[]> = Params<Z, A>;
|
|
53
|
-
export
|
|
51
|
+
export interface GetReturn<T> {
|
|
54
52
|
isPending: ComputedRef<undefined | boolean>;
|
|
55
53
|
data: ComputedRef<T>;
|
|
56
54
|
error: Ref<null | Error | Obj>;
|
|
@@ -61,5 +59,5 @@ export type GetReturn<T> = {
|
|
|
61
59
|
onStart: (cb: (params: any, xhr: Xhr<T>) => any) => any;
|
|
62
60
|
onEnd: (cb: (res: T, params: any, xhr: Xhr<T>) => any) => any;
|
|
63
61
|
xhr: Xhr<T>;
|
|
64
|
-
}
|
|
62
|
+
}
|
|
65
63
|
export { cache, clearCache, cacheSize, cacheIds, Deferred, useAsync, useMutation, useResult, useXhr, Xhr, useSpinner, };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
import*as t from"vue";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},r={};e.d(r,{cY:()=>p,TF:()=>D,PP:()=>i,LH:()=>u,Ej:()=>a,IL:()=>c,Yb:()=>L,n_:()=>R,bz:()=>P,p6:()=>M,cU:()=>Y});const n={log:function(t){},warn:function(t){},info:function(t){},error:function(t){},debug:function(t){}};var o=new Map;function i(t){var e,r,i=t||{},a=i.id,u=i.xhr,c="string"!=typeof t.duration&&t.duration||200;if("max"===t.duration&&(c=36e5),!o.get(a)&&u?(e=u(),o.set(a,e),e.then((function(t){return n.log("[Log] add cache: ".concat(a)),clearTimeout(r),r=window.setTimeout((function(){o.delete(a),n.log("[Log] delete cache: ".concat(a)),clearTimeout(r)}),c),t}),(function(){return o.delete(a),n.log("[Log] delete cache: ".concat(a))}))):a&&(e=o.get(a)),e)return e;throw Error("Call to undefined cache")}function a(){return o.size}function u(){return Array.from(o.keys())}function c(t){t?o.delete(t):o.forEach((function(t,e,r){r.delete(e)})),n.log("[Log] cache cleared")}function s(t){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s(t)}function l(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,v(n.key),n)}}function f(t,e,r){return e&&l(t.prototype,e),r&&l(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function h(t,e,r){return(e=v(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function v(t){var e=function(t){if("object"!=s(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=s(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==s(e)?e:e+""}var p=f((function t(){var e=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),h(this,"resolve",void 0),h(this,"reject",void 0),h(this,"promise",void 0),h(this,"done",!1),this.resolve=function(){throw Error("Can t resolve")},this.reject=function(){throw Error("Can t reject")},this.promise=new Promise((function(t,r){e.resolve=t,e.reject=r})),this.promise.finally((function(){e.done=!0}))}));const d=(y={computed:()=>t.computed,isRef:()=>t.isRef,onBeforeUnmount:()=>t.onBeforeUnmount,ref:()=>t.ref,unref:()=>t.unref,watch:()=>t.watch},m={},e.d(m,y),m);var y,m;const b="10000000-1000-4000-8000-100000000000".replace(/[018]/g,(function(t){return(+t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+t/4).toString(16)}));function g(t){return g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},g(t)}function w(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,j(n.key),n)}}function E(t,e,r){return e&&w(t.prototype,e),r&&w(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function _(t,e,r){return(e=j(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function j(t){var e=function(t){if("object"!=g(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=g(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==g(e)?e:e+""}var O=E((function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),_(this,"value",void 0),_(this,"uuid",void 0),this.uuid=b,this.value=e}));function P(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(t){return t},n=void 0===t.value?e:t.value;return t.value=void 0===n?n:new O(null==r?void 0:r(n)),(0,d.watch)((function(){return t.value}),(function(e){void 0===e||e instanceof O||(t.value=new O(null==r?void 0:r(e)))})),(0,d.computed)({get:function(){var r;return void 0===(r=t.value instanceof O?t.value.value:t.value)?e:r},set:function(e){t.value=new O(e)}})}function S(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}const L=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:(0,d.ref)(!0),n=(0,d.ref)(),o=(0,d.ref)(),i=(0,d.ref)(null),a=[],u=[],c=[],s=(0,d.ref)(null),l=(0,d.computed)((function(){return"function"==typeof e?e():(0,d.unref)(e)})),f=(0,d.ref)(),h=(0,d.computed)((function(){return"function"==typeof r?r():(0,d.unref)(r)})),v=function(e){if(!h.value)return null;var r,f;n.value&&(null===(r=s.value)||void 0===r||null===(f=r.abortXhr)||void 0===f||f.call(r)),u.forEach((function(t){return t(l.value)})),n.value=!0,i.value=null;var v,p=t,d=t;return s.value=Array.isArray(e)?d.apply(void 0,function(t){if(Array.isArray(t))return S(t)}(v=e)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(v)||function(t,e){if(t){if("string"==typeof t)return S(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?S(t,e):void 0}}(v)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()):p(e),s.value.catch((function(t){i.value=t||null,a.forEach((function(t){return t(i.value,l.value)}))})),s.value.then((function(t){o.value=t,c.forEach((function(e){return e(t,l.value)}))})),s.value.finally((function(){n.value=!1})),s.value},p=(0,d.computed)((function(){return s.value}));return(0,d.watch)((function(){return h.value}),(function(t){!n.value&&t&&v(l.value)}),{immediate:!1}),(0,d.watch)((function(){return i.value}),(function(t){if(t)throw t})),(0,d.watch)((function(){return l.value}),(function(t){var e=JSON.stringify(t);!n.value&&(void 0===t&&void 0===f.value||h.value&&e!==JSON.stringify(f.value))&&v(t),f.value=void 0===e?void 0:JSON.parse(e)}),{immediate:h.value,deep:!0}),{isPending:n,data:(0,d.computed)({get:function(){return o.value},set:function(t){t instanceof O&&t.uuid===b||console.warn('"useAsync" update a readonly field is not allowed'),o.value=t}}),error:i,reload:function(){return v(l.value)},onError:function(t){a.push(t)},onStart:function(t){u.push(t)},onEnd:function(t){c.push(t)},promise:p}};function R(t){var e=(0,d.ref)(),r=(0,d.ref)(),n=(0,d.ref)(),o=[],i=[],a=(0,d.ref)(null);return{mutate:function(u){for(var c=arguments.length,s=new Array(c>1?c-1:0),l=1;l<c;l++)s[l-1]=arguments[l];e.value=!0,n.value=null;var f=t;return a.value=f.apply(void 0,[u].concat(s)),a.value.catch((function(t){n.value=t||null,o.forEach((function(t){return t(n.value,s.length?[u].concat(s):u)})),n.value=t})),a.value.then((function(t){r.value=t,i.forEach((function(t){return t(r.value,s.length?[u].concat(s):u)}))})),a.value.finally((function(){e.value=!1})),a.value},onError:function(t){return o.push(t)},onEnd:function(t){return i.push(t)},isPending:e,error:n,data:r,promise:(0,d.computed)((function(){return a.value}))}}function k(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function x(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,s=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);c=!0);}catch(t){s=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return u}}(t,e)||function(t,e){if(t){if("string"==typeof t)return A(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?A(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function A(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function X(){X=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var i=e&&e.prototype instanceof m?e:m,a=Object.create(i.prototype),u=new x(n||[]);return o(a,"_invoke",{value:S(t,r,u)}),a}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=l;var h="suspendedStart",v="suspendedYield",p="executing",d="completed",y={};function m(){}function b(){}function g(){}var w={};s(w,a,(function(){return this}));var E=Object.getPrototypeOf,_=E&&E(E(A([])));_&&_!==r&&n.call(_,a)&&(w=_);var j=g.prototype=m.prototype=Object.create(w);function O(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function P(t,e){function r(o,i,a,u){var c=f(t[o],t,i);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==H(l)&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function S(e,r,n){var o=h;return function(i,a){if(o===p)throw Error("Generator is already running");if(o===d){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=L(u,n);if(c){if(c===y)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=p;var s=f(e,r,n);if("normal"===s.type){if(o=n.done?d:v,s.arg===y)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=d,n.method="throw",n.arg=s.arg)}}}function L(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,L(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=f(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,y;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,y):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function R(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function k(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function x(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(R,this),this.reset(!0)}function A(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(H(e)+" is not iterable")}return b.prototype=g,o(j,"constructor",{value:g,configurable:!0}),o(g,"constructor",{value:b,configurable:!0}),b.displayName=s(g,c,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,s(t,c,"GeneratorFunction")),t.prototype=Object.create(j),t},e.awrap=function(t){return{__await:t}},O(P.prototype),s(P.prototype,u,(function(){return this})),e.AsyncIterator=P,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new P(l(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},O(j),s(j,c,"Generator"),s(j,a,(function(){return this})),s(j,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=A,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(k),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return u.type="throw",u.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),k(r),y}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;k(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:A(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),y}},e}function T(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function H(t){return H="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},H(t)}function N(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,I(n.key),n)}}function U(t,e,r){return(e=I(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function I(t){var e=function(t){if("object"!=H(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=H(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==H(e)?e:e+""}var D=function(){function t(e,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),U(this,"onError",(function(){})),U(this,"onStart",(function(){})),U(this,"onAbort",(function(){})),U(this,"onProgress",(function(){})),U(this,"onEnd",(function(){})),U(this,"token",null),U(this,"url",""),U(this,"params",{}),U(this,"sendAs","json"),U(this,"timeout",1e4),U(this,"port",80),U(this,"responseType","text"),U(this,"isPending",!1),U(this,"_eventsReady",void 0),U(this,"_oXHR",void 0),U(this,"_onEnd",(function(){})),U(this,"_onError",(function(){})),U(this,"_deferred",void 0),U(this,"_isXhrResolved",void 0),U(this,"_isXhrRejected",void 0),U(this,"_eventReady",void 0),this._eventsReady=!1,this._constructor(e||{},r)}return e=t,r=[{key:"_getUrl",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.onBeforeSendList.reduce((function(t,e){return e(t||{})}),e);return t.stringifyUrl(this.url,r)}},{key:"removeEvents",value:function(){var t=this,e=function(){t._oXHR.removeEventListener("load",t._onEnd,!1),t._oXHR.removeEventListener("error",t._onError,!1),t._oXHR.removeEventListener("timeout",t._onError,!1),t._oXHR.removeEventListener("loadstart",t.onStart,!1),t._oXHR.removeEventListener("abort",t.onAbort,!1),t._oXHR.upload.removeEventListener("progress",t.onProgress,!1),t._oXHR.removeEventListener("progress",t.onProgress,!1)};this._deferred.promise.then(e,e)}},{key:"post",value:function(t){return this._constructor(t),this._oXHR.open("POST",this._getUrl(),!0),this._send(),this._deferred.promise}},{key:"put",value:function(t){return this._constructor(t),this._oXHR.open("PUT",this._getUrl(),!0),this._send(),this._deferred.promise}},{key:"get",value:function(t){this._constructor(t||{}),this._oXHR.open("GET",this._getUrl("multipart"===this.sendAs?{}:this.params),!0),this._send();var e=this._deferred.promise;return e.abortXhr=this.abort.bind(this),e}},{key:"delete",value:function(t){return this._constructor(t),this._oXHR.open("DELETE",this._getUrl(this.params),!0),this._send(),this._deferred.promise}},{key:"abort",value:function(){return this._isXhrResolved&&!this._isXhrRejected||(this._oXHR.abort(null,this),this._isXhrRejected=!0,this._deferred.reject({message:"Xhr aborted: ".concat(this.url),name:"HTTP-ABORTED"})),this._deferred.promise}},{key:"resolve",value:function(t){return this._deferred.resolve(t),this._deferred.promise}},{key:"reject",value:function(t){return this._deferred.reject(t),this._deferred.promise}},{key:"_setEvents",value:function(t){this._eventsReady||(this._eventReady=!0,t.addEventListener("load",this._onEnd,!1),t.addEventListener("error",this._onError,!1),t.addEventListener("timeout",this._onError,!1),t.addEventListener("loadstart",this.onStart,!1),t.addEventListener("abort",this.onAbort,!1),t.upload.addEventListener("progress",this.onProgress,!1),t.addEventListener("progress",this.onProgress,!1))}},{key:"_send",value:function(){var e;this.isPending=!0,"multipart"===this.sendAs?e=t.getFormData(this.params):"json"===this.sendAs&&(this._oXHR.setRequestHeader("content-type","application/json; charset=utf-8"),e=JSON.stringify(this.params)),this.token&&this._oXHR.setRequestHeader("Authorization","Bearer ".concat(this.token)),this._oXHR.send(e,this)}},{key:"_constructor",value:function(e,r){var n=this;e&&"object"===H(e)?(this.sendAs=e.sendAs||this.sendAs,this.url=e.url||this.url,this.port=e.port||this.port,this.params=e.params||this.params,this.timeout=e.timeout||this.timeout,this.responseType=e.responseType||this.responseType,this.onProgress=(e.onProgress||this.onProgress).bind(this),this.onStart=(e.onStart||this.onStart).bind(this),this.onAbort=(e.onAbort||this.onAbort).bind(this),this.onEnd=(e.onEnd||this.onEnd).bind(this),this.onError=(e.onError||this.onError).bind(this),this.token=e.token||this.token):e&&"string"==typeof e&&(this.url=e,this.params=r||this.params),80!==this.port&&(this.url="".concat(window.location.protocol,"//").concat(window.location.hostname,":").concat(this.port).concat(this.url)),this._deferred=new p,this._deferred.promise.finally((function(){n.isPending=!1})),this._oXHR=new XMLHttpRequest,this._oXHR.timeout=this.timeout,this._oXHR.responseType=this.responseType,this._isXhrResolved=!1,this._isXhrRejected=!1;var o=t.injectParamsInUrl(this.url,this.params),i=o.url,a=o.params;this.url=i,this.params=a,this._onError=function(t){n.onError(t),n.removeEvents(),n._deferred.reject(t)},this._onEnd=function(){var e,r=(e=X().mark((function e(r){var o,i,a,u;return X().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=t.parseResult(n._oXHR),!(n._oXHR.status>=400)){e.next=12;break}return e.next=4,null===(i=(a=n._oXHR.response).text)||void 0===i?void 0:i.call(a);case 4:if(e.t0=e.sent,e.t0){e.next=7;break}e.t0=n._oXHR.response;case 7:u=e.t0;try{u=JSON.parse(u)}catch(t){}return n._isXhrRejected=!0,n._onError(u),e.abrupt("return",n._deferred.reject(u));case 12:return n.onEnd(o,r),n._isXhrResolved=!0,n.removeEvents(),e.abrupt("return",n.resolve(o));case 16:case"end":return e.stop()}}),e)})),function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(t){T(i,n,o,a,u,"next",t)}function u(t){T(i,n,o,a,u,"throw",t)}a(void 0)}))});return function(t){return r.apply(this,arguments)}}(),this._setEvents(this._oXHR)}}],n=[{key:"parseResult",value:function(t){var e=t.response;try{var r=t.getResponseHeader("Content-Type");r&&r.toLowerCase().indexOf("json")>-1&&(e=JSON.parse(t.response))}catch(r){e=t.response}return e}},{key:"extractQueryParams",value:function(t){var e={},r=t.search(/#/);r>-1&&(t=t.substring(0,r));var n=t.indexOf("?"),o=(!0).toString(),i=(!1).toString();return n>-1&&t.split("?")[1].split("&").reduce((function(t,e){var r=x(e.split("="),2),n=r[0],a=r[1],u=x((void 0===a?"":a).match(/^(?:"?([^"]+)"?)$/)||[],2)[1];if(u===o||u===i)t[n]=u===o;else{var c=Number(u);t[n]=""===u||Number.isNaN(c)?u:c}return t}),e),e}},{key:"onBeforeSend",value:function(e){t.onBeforeSendList.push(e)}},{key:"new",value:function(e){return new t(e)}},{key:"stringifyUrl",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.injectParamsInUrl(e,r);e=n.url,r=n.params;var o=e.indexOf("?")>-1?"&":"?",i="";return r&&!Array.isArray(r)&&"object"===H(r)?Object.getOwnPropertyNames(r).filter((function(t){return void 0!==r[t]})).forEach((function(t){i+="".concat(o).concat(t,"=").concat(encodeURIComponent(JSON.stringify(r[t]))),o="&"})):r&&(i=o+encodeURIComponent(JSON.stringify(r))),(e=e.replace(/\/:[^/]*/gi,""))+i}},{key:"getFormData",value:function(t){var e,r=new FormData;return Object.keys(t).forEach((function(n){if(t[n]instanceof FileList)for(var o=0;o<t[n].length;o+=1)r.append(n,t[n][o]);else t[n]instanceof File?r.append(n,t[n]):("object"!==H(e=t[n])&&!Array.isArray(e)||null===e||(e=JSON.stringify(e)),r.append(n,e))})),r}},{key:"_stringifyForPathParam",value:function(t,e,r){var n=r[e];switch(H(r[e])){case"boolean":case"string":case"bigint":case"number":n=String(n);break;default:n=null===n?"null":encodeURIComponent(JSON.stringify(n))}return t.replace(":".concat(e),n)}},{key:"injectParamsInUrl",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Array.isArray(r)||0===Object.keys(r).length)return{url:e,params:r};var n=decodeURIComponent(e),o=t.extractQueryParams(n),i=n.search(/\?|#/);i>-1&&(n=n.substring(0,i));var a=Object.getOwnPropertyNames(r).reduce((function(t,e){return t[e]=r[e],t}),function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?k(Object(r),!0).forEach((function(e){U(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):k(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}({},o));(n.match(/:[a-z0-9]+/gi)||[]).forEach((function(e){e=e.substring(1),void 0!==a[e]&&(n=t._stringifyForPathParam(n,e,a),delete a[e])})),Object.keys(a).forEach((function(t){void 0!==o[t]&&(o[t]=a[t],delete a[t])}));var u=Object.keys(o);if(u.length){var c="?";u.forEach((function(t){if(!0===o[t]||!1===o[t])n+="".concat(c).concat(t,"=").concat(o[t]);else if(null===o[t])n+="".concat(c).concat(t,"=").concat(o[t]);else{var e=Number(o[t]),r=Number.isNaN(e)?encodeURIComponent('"'.concat(o[t],'"')):e;n+="".concat(c).concat(t,"=").concat(r)}c="&"}))}return{url:n,params:a}}}],r&&N(e.prototype,r),n&&N(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}();function C(t){return C="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},C(t)}function F(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function B(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?F(Object(r),!0).forEach((function(e){J(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):F(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function J(t,e,r){return(e=function(t){var e=function(t){if("object"!=C(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=C(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==C(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}U(D,"onBeforeSendList",[]);var G=function(){},z=function(t){return(0,d.unref)(t)};function Y(t){var e=t||{onError:function(){},onStart:function(){},onEnd:function(){},context:null,legacy:!1,token:null},r=e.onError,n=e.onStart,o=e.onEnd,a=e.context,u=e.legacy,c=e.token,s=void 0===c?null:c,l=(0,d.ref)([]),f=[],h=function(t,e,r){var n,o=(0,d.computed)((function(){var t={},n=(0,d.unref)(e||{});return r||(r=n.params||{}),t.params=(0,d.unref)(r),s&&(t.token=z(s)),t.url=(0,d.unref)(n.url),t})),i=new D,a=(0,d.unref)(o.value.params)||{};switch(t){case"post":default:n=i.post.bind(i);break;case"put":n=i.put.bind(i);break;case"delete":n=i.delete.bind(i)}return B(B({},L((function(){return n(B(B({},o.value),{},{params:a}))}))),{},{xhr:i})};return u||(0,d.onBeforeUnmount)((function(){l.value.forEach((function(t){t.isPending&&t.abort()})),f.forEach((function(t){return t()}))})),{get:function(t,e,u){var c=new D,h=(r||G).bind(a),v=(n||G).bind(a),p=(o||G).bind(a),y=[h],m=[v],g=[p],w=(0,d.ref)(null);l.value.push(c);var E=(0,d.ref)(),_=(0,d.ref)(),j="",P=0,S=(0,d.computed)((function(){var r,n={},o=(0,d.unref)(t);"string"==typeof o?r=o:(r=(0,d.unref)(o.url),e||(e=o.params||{}),P=o.cacheDuration,void 0!==o.enabled&&(n.enabled=o.enabled),void 0===n.enabled&&(n.enabled=u),n.params=(0,d.unref)(e),n.cacheDuration=P),s&&(n.token=z(s));var i=(0,d.unref)(n.params||e||{});return"function"==typeof i&&(i=i()),n.params=B(B({},i),(0,d.isRef)(e)?e.value||{}:e),j="function"==typeof r?r(n.params):(0,d.unref)(r),n.url=j,n})),L=function(){var t=void 0!==S.value.enabled?S.value.enabled:u;return void 0===t||((0,d.isRef)(t)?(0,d.unref)(t):"function"==typeof t?t():!0===t)},R=(0,d.ref)(),k=function(){if(L()){E.value&&c.abort();var t="object"===C(S.value.params)?S.value.params:{};m.forEach((function(e){return e(t,c)})),E.value=!0,w.value=null;var e=decodeURIComponent(D.stringifyUrl(String(j),t));R.value=i({id:e,xhr:c.get.bind(c,S.value),duration:P}),R.value.catch((function(t){y.forEach((function(e){return e(t,c)})),w.value=t})),R.value.then((function(t){_.value=t})),R.value.finally((function(){var e;(e=l.value.indexOf(c))>-1&&l.value.splice(e,1),E.value=!1,g.forEach((function(e){return e(_.value,t,c)}))}))}};return f.push((0,d.watch)((function(){return S.value}),k,{immediate:L(),deep:!0})),f.push((0,d.watch)((function(){return w.value}),(function(t){if(t)throw t}))),{isPending:(0,d.computed)((function(){return E.value})),data:(0,d.computed)({get:function(){return _.value},set:function(t){t instanceof O&&t.uuid===b||console.warn('"useXhr" update a readonly field is not allowed'),_.value=t}}),onError:function(t){return y.push(t)},onStart:function(t){return m.push(t)},onEnd:function(t){return g.push(t)},error:w,abort:function(){var t;return null===(t=R.value)||void 0===t?void 0:t.abortXhr()},promise:(0,d.computed)((function(){return R.value||new Promise((function(){}))})),reload:k,xhr:c}},post:function(t,e){return h("post",t,e)},put:function(t,e){return h("put",t,e)},delete:function(t,e){return h("delete",t,e)}}}function M(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:400,n=(0,d.ref)(!1),o=0;return(0,d.watch)((function(){return t.value}),(function(t){if(t&&(o=Date.now(),n.value=t),!1===t&&o>0){var i=Date.now()-o;clearTimeout(e),i>r?n.value=t:e=setTimeout((function(){n.value=t}),r-i)}}),{immediate:!0}),(0,d.onBeforeUnmount)((function(){clearTimeout(e)})),(0,d.computed)((function(){return n.value}))}var q=r.cY,$=r.TF,Q=r.PP,V=r.LH,K=r.Ej,W=r.IL,Z=r.Yb,tt=r.n_,et=r.bz,rt=r.p6,nt=r.cU;export{q as Deferred,$ as Xhr,Q as cache,V as cacheIds,K as cacheSize,W as clearCache,Z as useAsync,tt as useMutation,et as useResult,rt as useSpinner,nt as useXhr};
|
|
2
|
+
import{computed as e,isRef as t,onBeforeUnmount as r,ref as n,unref as o,watch as i}from"vue";var u=new Map;function a(e){var t,r,n=e||{},o=n.id,i=n.xhr,a="string"!=typeof e.duration&&e.duration||200;if("max"===e.duration&&(a=36e5),!u.get(o)&&i?(t=i(),u.set(o,t),t.then(function(e){return"[Log] add cache: ".concat(o),clearTimeout(r),r=window.setTimeout(function(){u.delete(o),"[Log] delete cache: ".concat(o),clearTimeout(r)},a),e},function(){u.delete(o),"[Log] delete cache: ".concat(o)})):o&&(t=u.get(o)),t)return t;throw Error("Call to undefined cache")}function c(){return u.size}function s(){return Array.from(u.keys())}function l(e){e?u.delete(e):u.forEach(function(e,t,r){r.delete(t)})}function f(e){return f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},f(e)}function v(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,p(n.key),n)}}function d(e,t,r){return t&&v(e.prototype,t),r&&v(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function h(e,t,r){return(t=p(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function p(e){var t=function(e){if("object"!=f(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=f(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==f(t)?t:t+""}var y=d(function e(){var t=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),h(this,"resolve",void 0),h(this,"reject",void 0),h(this,"promise",void 0),h(this,"done",!1),this.resolve=function(){throw Error("Can t resolve")},this.reject=function(){throw Error("Can t reject")},this.promise=new Promise(function(e,r){t.resolve=e,t.reject=r}),this.promise.finally(function(){t.done=!0})});const m="10000000-1000-4000-8000-100000000000".replace(/[018]/g,function(e){return(+e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+e/4).toString(16)});function b(e){return b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},b(e)}function g(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,w(n.key),n)}}function _(e,t,r){return t&&g(e.prototype,t),r&&g(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function E(e,t,r){return(t=w(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function w(e){var t=function(e){if("object"!=b(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=b(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==b(t)?t:t+""}var j=_(function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),E(this,"value",void 0),E(this,"uuid",void 0),this.uuid=m,this.value=t});function O(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(e){return e},o=void 0===t.value?r:t.value;return t.value=void 0===o?o:new j(null==n?void 0:n(o)),i(function(){return t.value},function(e){void 0===e||e instanceof j||(t.value=new j(null==n?void 0:n(e)))}),e({get:function(){var e;return void 0===(e=t.value instanceof j?t.value.value:t.value)?r:e},set:function(e){t.value=new j(e)}})}function S(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}const P=function(t,r){var u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:n(!0),a=n(),c=n(),s=n(null),l=[],f=[],v=[],d=n(null),h=e(function(){return"function"==typeof r?r():o(r)}),p=n(),y=e(function(){return"function"==typeof u?u():o(u)}),b=function(e){if(!y.value)return null;var r,n;a.value&&(null===(r=d.value)||void 0===r||null===(n=r.abortXhr)||void 0===n||n.call(r)),f.forEach(function(e){return e(h.value)}),a.value=!0,s.value=null;var o,i=t,u=t;return d.value=Array.isArray(e)?u.apply(void 0,function(e){if(Array.isArray(e))return S(e)}(o=e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(o)||function(e,t){if(e){if("string"==typeof e)return S(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?S(e,t):void 0}}(o)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()):i(e),d.value.catch(function(e){s.value=e||null,l.forEach(function(e){return e(s.value,h.value)})}),d.value.then(function(e){c.value=e,v.forEach(function(t){return t(e,h.value)})}),d.value.finally(function(){a.value=!1}),d.value},g=e(function(){return d.value});return i(function(){return y.value},function(e){!a.value&&e&&b(h.value)},{immediate:!1}),i(function(){return s.value},function(e){if(e)throw e}),i(function(){return h.value},function(e){var t=JSON.stringify(e);!a.value&&(void 0===e&&void 0===p.value||y.value&&t!==JSON.stringify(p.value))&&b(e),p.value=void 0===t?void 0:JSON.parse(t)},{immediate:y.value,deep:!0}),{isPending:a,data:e({get:function(){return c.value},set:function(e){e instanceof j&&e.uuid===m||console.warn('"useAsync" update a readonly field is not allowed'),c.value=e}}),error:s,reload:function(){return b(h.value)},onError:function(e){l.push(e)},onStart:function(e){f.push(e)},onEnd:function(e){v.push(e)},promise:g}};function R(t){var r=n(),o=n(),i=n(),u=[],a=[],c=n(null);return{mutate:function(e){for(var n=arguments.length,s=new Array(n>1?n-1:0),l=1;l<n;l++)s[l-1]=arguments[l];r.value=!0,i.value=null;var f=t;return c.value=f.apply(void 0,[e].concat(s)),c.value.catch(function(t){i.value=t||null,u.forEach(function(t){return t(i.value,s.length?[e].concat(s):e)}),i.value=t}),c.value.then(function(t){o.value=t,a.forEach(function(t){return t(o.value,s.length?[e].concat(s):e)})}),c.value.finally(function(){r.value=!1}),c.value},onError:function(e){return u.push(e)},onEnd:function(e){return a.push(e)},isPending:r,error:i,data:o,promise:e(function(){return c.value})}}function k(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function A(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?k(Object(r),!0).forEach(function(t){D(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):k(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function X(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,u,a=[],c=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);c=!0);}catch(e){s=!0,o=e}finally{try{if(!c&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(s)throw o}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return T(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?T(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function T(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function H(){var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof a?n:a,s=Object.create(c.prototype);return L(s,"_invoke",function(r,n,o){var i,a,c,s=0,l=o||[],f=!1,v={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function(t,r){return i=t,a=0,c=e,v.n=r,u}};function d(r,n){for(a=r,c=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],d=v.p,h=i[2];r>3?(o=h===n)&&(c=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=r<2&&d<i[1])?(a=0,v.v=n,v.n=i[1]):d<h&&(o=r<3||i[0]>n||n>h)&&(i[4]=r,i[5]=n,v.n=h,a=0))}if(o||r>1)return u;throw f=!0,n}return function(o,l,h){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,h),a=l,c=h;(t=a<2?e:c)||!f;){i||(a?a<3?(a>1&&(v.n=-1),d(a,c)):v.n=c:v.v=c);try{if(s=2,i){if(a||(o="next"),t=i[o]){if(!(t=t.call(i,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),a=1);i=e}else if((t=(f=v.n<0)?c:r.call(n,v))!==u)break}catch(t){i=e,a=1,c=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var u={};function a(){}function c(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(L(t={},n,function(){return this}),t),f=s.prototype=a.prototype=Object.create(l);function v(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,L(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return c.prototype=s,L(f,"constructor",s),L(s,"constructor",c),c.displayName="GeneratorFunction",L(s,o,"GeneratorFunction"),L(f),L(f,o,"Generator"),L(f,n,function(){return this}),L(f,"toString",function(){return"[object Generator]"}),(H=function(){return{w:i,m:v}})()}function L(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}L=function(e,t,r,n){function i(t,r){L(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},L(e,t,r,n)}function N(e,t,r,n,o,i,u){try{var a=e[i](u),c=a.value}catch(e){return void r(e)}a.done?t(c):Promise.resolve(c).then(n,o)}function U(e){return U="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},U(e)}function x(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,C(n.key),n)}}function D(e,t,r){return(t=C(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function C(e){var t=function(e){if("object"!=U(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=U(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==U(t)?t:t+""}var I=function(){function e(t,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),D(this,"onError",function(){}),D(this,"onStart",function(){}),D(this,"onAbort",function(){}),D(this,"onProgress",function(){}),D(this,"onEnd",function(){}),D(this,"token",null),D(this,"url",""),D(this,"params",{}),D(this,"sendAs","json"),D(this,"timeout",1e4),D(this,"port",80),D(this,"responseType","text"),D(this,"isPending",!1),D(this,"_eventsReady",void 0),D(this,"_oXHR",void 0),D(this,"_onEnd",function(){}),D(this,"_onError",function(){}),D(this,"_deferred",void 0),D(this,"_isXhrResolved",void 0),D(this,"_isXhrRejected",void 0),D(this,"_eventReady",void 0),this._eventsReady=!1,this._constructor(t||{},r)}return t=e,r=[{key:"_getUrl",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.onBeforeSendList.reduce(function(e,t){return t(e||{})},t);return e.stringifyUrl(this.url,r)}},{key:"removeEvents",value:function(){var e=this,t=function(){e._oXHR.removeEventListener("load",e._onEnd,!1),e._oXHR.removeEventListener("error",e._onError,!1),e._oXHR.removeEventListener("timeout",e._onError,!1),e._oXHR.removeEventListener("loadstart",e.onStart,!1),e._oXHR.removeEventListener("abort",e.onAbort,!1),e._oXHR.upload.removeEventListener("progress",e.onProgress,!1),e._oXHR.removeEventListener("progress",e.onProgress,!1)};this._deferred.promise.then(t,t)}},{key:"post",value:function(e){return this._constructor(e),this._oXHR.open("POST",this._getUrl(),!0),this._send(),this._deferred.promise}},{key:"put",value:function(e){return this._constructor(e),this._oXHR.open("PUT",this._getUrl(),!0),this._send(),this._deferred.promise}},{key:"get",value:function(e){this._constructor(e||{}),this._oXHR.open("GET",this._getUrl("multipart"===this.sendAs?{}:this.params),!0),this._send();var t=this._deferred.promise;return t.abortXhr=this.abort.bind(this),t}},{key:"delete",value:function(e){return this._constructor(e),this._oXHR.open("DELETE",this._getUrl(this.params),!0),this._send(),this._deferred.promise}},{key:"abort",value:function(){return this._isXhrResolved&&!this._isXhrRejected||(this._oXHR.abort(null,this),this._isXhrRejected=!0,this._deferred.reject({message:"Xhr aborted: ".concat(this.url),name:"HTTP-ABORTED"})),this._deferred.promise}},{key:"resolve",value:function(e){return this._deferred.resolve(e),this._deferred.promise}},{key:"reject",value:function(e){return this._deferred.reject(e),this._deferred.promise}},{key:"_setEvents",value:function(e){this._eventsReady||(this._eventReady=!0,e.addEventListener("load",this._onEnd,!1),e.addEventListener("error",this._onError,!1),e.addEventListener("timeout",this._onError,!1),e.addEventListener("loadstart",this.onStart,!1),e.addEventListener("abort",this.onAbort,!1),e.upload.addEventListener("progress",this.onProgress,!1),e.addEventListener("progress",this.onProgress,!1))}},{key:"_send",value:function(){var t;this.isPending=!0,"multipart"===this.sendAs?t=e.getFormData(this.params):"json"===this.sendAs&&(this._oXHR.setRequestHeader("content-type","application/json; charset=utf-8"),t=JSON.stringify(this.params)),this.token&&this._oXHR.setRequestHeader("Authorization","Bearer ".concat(this.token)),this._oXHR.send(t,this)}},{key:"_constructor",value:function(t,r){var n=this;t&&"object"===U(t)?(this.sendAs=t.sendAs||this.sendAs,this.url=t.url||this.url,this.port=t.port||this.port,this.params=t.params||this.params,this.timeout=t.timeout||this.timeout,this.responseType=t.responseType||this.responseType,this.onProgress=(t.onProgress||this.onProgress).bind(this),this.onStart=(t.onStart||this.onStart).bind(this),this.onAbort=(t.onAbort||this.onAbort).bind(this),this.onEnd=(t.onEnd||this.onEnd).bind(this),this.onError=(t.onError||this.onError).bind(this),this.token=t.token||this.token):t&&"string"==typeof t&&(this.url=t,this.params=r||this.params),80!==this.port&&(this.url="".concat(window.location.protocol,"//").concat(window.location.hostname,":").concat(this.port).concat(this.url)),this._deferred=new y,this._deferred.promise.finally(function(){n.isPending=!1}),this._oXHR=new XMLHttpRequest,this._oXHR.timeout=this.timeout,this._oXHR.responseType=this.responseType,this._isXhrResolved=!1,this._isXhrRejected=!1;var o=e.injectParamsInUrl(this.url,this.params),i=o.url,u=o.params;this.url=i,this.params=u,this._onError=function(e){n.onError(e),n.removeEvents(),n._deferred.reject(e)},this._onEnd=function(){var t,r=(t=H().m(function t(r){var o,i,u,a,c;return H().w(function(t){for(;;)switch(t.n){case 0:if(o=e.parseResult(n._oXHR),!(n._oXHR.status>=400)){t.n=3;break}return t.n=1,null===(i=(u=n._oXHR.response).text)||void 0===i?void 0:i.call(u);case 1:if(c=t.v){t.n=2;break}c=n._oXHR.response;case 2:a=c;try{a=JSON.parse(a)}catch(e){}return n._isXhrRejected=!0,n._onError(a),t.a(2,n._deferred.reject(a));case 3:return n.onEnd(o,r),n._isXhrResolved=!0,n.removeEvents(),t.a(2,n.resolve(o))}},t)}),function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function u(e){N(i,n,o,u,a,"next",e)}function a(e){N(i,n,o,u,a,"throw",e)}u(void 0)})});return function(e){return r.apply(this,arguments)}}(),this._setEvents(this._oXHR)}}],n=[{key:"parseResult",value:function(e){var t=e.response;try{var r=e.getResponseHeader("Content-Type");null!=r&&r.toLowerCase().includes("json")&&(t=JSON.parse(e.response))}catch(r){t=e.response}return t}},{key:"extractQueryParams",value:function(e){var t=e,r={},n=t.search(/#/);n>-1&&(t=t.substring(0,n));var o=t.indexOf("?"),i=(!0).toString(),u=(!1).toString();return o>-1&&t.split("?")[1].split("&").reduce(function(e,t){var r=e,n=X(t.split("="),2),o=n[0],a=n[1],c=X(/^(?:"?([^"]+)"?)$/.exec(void 0===a?"":a)||[],2)[1];if(c===i||c===u)return r[o]=c===i,r;var s=Number(c);return r[o]=""===c||Number.isNaN(s)?c:s,r},r),r}},{key:"onBeforeSend",value:function(t){e.onBeforeSendList.push(t)}},{key:"new",value:function(t){return new e(t)}},{key:"stringifyUrl",value:function(t){var r=t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=e.injectParamsInUrl(r,n);r=o.url,n=o.params;var i=r.includes("?")?"&":"?",u="";return n&&!Array.isArray(n)&&"object"===U(n)?Object.getOwnPropertyNames(n).filter(function(e){return void 0!==n[e]}).forEach(function(e){u+="".concat(i).concat(e,"=").concat(encodeURIComponent(JSON.stringify(n[e]))),i="&"}):n&&(u=i+encodeURIComponent(JSON.stringify(n))),(r=r.replace(/\/:[^/]*/gi,""))+u}},{key:"getFormData",value:function(e){var t,r=new FormData;return Object.keys(e).forEach(function(n){if(e[n]instanceof FileList)for(var o=0;o<e[n].length;o+=1)r.append(n,e[n][o]);else e[n]instanceof File?r.append(n,e[n]):("object"!==U(t=e[n])&&!Array.isArray(t)||null===t||(t=JSON.stringify(t)),r.append(n,t))}),r}},{key:"_stringifyForPathParam",value:function(e,t,r){var n=r[t];switch(U(r[t])){case"boolean":case"string":case"bigint":case"number":n=String(n);break;default:n=null===n?"null":encodeURIComponent(JSON.stringify(n))}return e.replace(":".concat(t),n)}},{key:"injectParamsInUrl",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Array.isArray(r)||0===Object.keys(r).length)return{url:t,params:r};var n=decodeURIComponent(t),o=e.extractQueryParams(n),i=n.search(/\?|#/);i>-1&&(n=n.substring(0,i));var u=Object.getOwnPropertyNames(r).reduce(function(e,t){return A(A({},e),{},D({},t,r[t]))},A({},o));(n.match(/:[a-z0-9]+/gi)||[]).forEach(function(t){var r=t;r=r.substring(1),void 0!==u[r]&&(n=e._stringifyForPathParam(n,r,u),delete u[r])}),Object.keys(u).forEach(function(e){void 0!==o[e]&&(o[e]=u[e],delete u[e])});var a=Object.keys(o);if(a.length){var c="?";a.forEach(function(e){if(!0===o[e]||!1===o[e])n+="".concat(c).concat(e,"=").concat(o[e]);else if(null===o[e])n+="".concat(c).concat(e,"=").concat(o[e]);else{var t=Number(o[e]),r=Number.isNaN(t)?encodeURIComponent('"'.concat(o[e],'"')):t;n+="".concat(c).concat(e,"=").concat(r)}c="&"})}return{url:n,params:u}}}],r&&x(t.prototype,r),n&&x(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,n}();function F(e){return F="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},F(e)}function J(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function G(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?J(Object(r),!0).forEach(function(t){B(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):J(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function B(e,t,r){return(t=function(e){var t=function(e){if("object"!=F(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=F(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==F(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}D(I,"onBeforeSendList",[]);var M=function(){},q=function(e){return o(e)};function z(u){var c=u||{onError:function(){},onStart:function(){},onEnd:function(){},context:null,legacy:!1,token:null},s=c.onError,l=c.onStart,f=c.onEnd,v=c.context,d=c.legacy,h=c.token,p=void 0===h?null:h,y=n([]),b=[],g=function(t,r,n){var i,u=n,a=e(function(){var e={},t=o(r||{});return u||(u=t.params||{}),e.params=o(u),p&&(e.token=q(p)),e.url=o(t.url),e}),c=new I,s=o(a.value.params)||{};switch(t){case"post":default:i=c.post.bind(c);break;case"put":i=c.put.bind(c);break;case"delete":i=c.delete.bind(c)}return G(G({},P(function(){return i(G(G({},a.value),{},{params:s}))})),{},{xhr:c})};return d||r(function(){y.value.forEach(function(e){e.isPending&&e.abort()}),b.forEach(function(e){return e()})}),{get:function(r,u,c){var d=u,h=new I,g=(s||M).bind(v),_=(l||M).bind(v),E=(f||M).bind(v),w=[g],O=[_],S=[E],P=n(null);y.value.push(h);var R=n(),k=n(),A="",X=0,T=e(function(){var e,n={},i=o(r);"string"==typeof i?e=i:(e=o(i.url),d||(d=i.params||{}),X=i.cacheDuration,void 0!==i.enabled&&(n.enabled=i.enabled),void 0===n.enabled&&(n.enabled=c),n.params=o(d),n.cacheDuration=X),p&&(n.token=q(p));var u=o(n.params||d||{});return"function"==typeof u&&(u=u()),n.params=G(G({},u),t(d)?d.value||{}:d),A="function"==typeof e?e(n.params):o(e),n.url=A,n}),H=function(){var e=void 0!==T.value.enabled?T.value.enabled:c;return void 0===e||(t(e)?o(e):"function"==typeof e?e():!0===e)},L=n(),N=function(){if(H()){R.value&&h.abort();var e="object"===F(T.value.params)?T.value.params:{};O.forEach(function(t){return t(e,h)}),R.value=!0,P.value=null;var t=decodeURIComponent(I.stringifyUrl(String(A),e));L.value=a({id:t,xhr:h.get.bind(h,T.value),duration:X}),L.value.catch(function(e){w.forEach(function(t){return t(e,h)}),P.value=e}),L.value.then(function(e){k.value=e}),L.value.finally(function(){var t;(t=y.value.indexOf(h))>-1&&y.value.splice(t,1),R.value=!1,S.forEach(function(t){return t(k.value,e,h)})})}};return b.push(i(function(){return T.value},N,{immediate:H(),deep:!0})),b.push(i(function(){return P.value},function(e){if(e)throw e})),{isPending:e(function(){return R.value}),data:e({get:function(){return k.value},set:function(e){e instanceof j&&e.uuid===m||console.warn('"useXhr" update a readonly field is not allowed'),k.value=e}}),onError:function(e){return w.push(e)},onStart:function(e){return O.push(e)},onEnd:function(e){return S.push(e)},error:P,abort:function(){var e;return null===(e=L.value)||void 0===e?void 0:e.abortXhr()},promise:e(function(){return L.value||new Promise(function(){})}),reload:N,xhr:h}},post:function(e,t){return g("post",e,t)},put:function(e,t){return g("put",e,t)},delete:function(e,t){return g("delete",e,t)}}}function $(t){var o,u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:400,a=n(!1),c=0;return i(function(){return t.value},function(e){if(e&&(c=Date.now(),a.value=e),!1===e&&c>0){var t=Date.now()-c;clearTimeout(o),t>u?a.value=e:o=setTimeout(function(){a.value=e},u-t)}},{immediate:!0}),r(function(){clearTimeout(o)}),e(function(){return a.value})}export{y as Deferred,I as Xhr,a as cache,s as cacheIds,c as cacheSize,l as clearCache,P as useAsync,R as useMutation,O as useResult,$ as useSpinner,z as useXhr};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/
|
|
1
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
package/dist/mockXhr.d.ts
CHANGED
package/dist/tests.d.ts
CHANGED
package/dist/useAsync.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComputedRef, Ref, UnwrapRef } from 'vue';
|
|
2
|
-
import type { RequiredParams, TypeAllowed, UnwrappedPromiseType } from '
|
|
2
|
+
import type { RequiredParams, TypeAllowed, UnwrappedPromiseType } from '.';
|
|
3
3
|
type OnErrorCb<T> = (e: null | Error, params: T) => void;
|
|
4
4
|
type OnStartCb<T> = (params: T) => void;
|
|
5
5
|
type OnEndCb<T, Z> = (res: T, params: Z) => void;
|
package/dist/useMutation.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ComputedRef, Ref } from 'vue';
|
|
2
|
-
import type { Obj, UnwrappedPromiseType } from '
|
|
1
|
+
import type { ComputedRef, Ref } from 'vue';
|
|
2
|
+
import type { Obj, UnwrappedPromiseType } from '.';
|
|
3
3
|
type TypeAllowed = undefined | boolean | null | string | number | Obj;
|
|
4
4
|
type OnErrorCb<Z, A extends TypeAllowed[]> = (e: null | Error, params: A extends [] ? Z : [Z, ...A]) => unknown;
|
|
5
5
|
type OnEndCb<T, Z, A extends TypeAllowed[]> = (res: T, params: A extends [] ? Z : [Z, ...A]) => unknown;
|
package/dist/useResult.d.ts
CHANGED
package/dist/useSpinner.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Ref } from 'vue';
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
2
|
export default function (isPending: Ref<undefined | boolean>, minDuration?: number): import("vue").ComputedRef<boolean>;
|
package/dist/useXhr.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComputedRef, Ref } from 'vue';
|
|
2
|
-
import type { $UpdateConfigArgs, GetConfig, GetReturn, RequiredParams, TypeAllowed } from '
|
|
2
|
+
import type { $UpdateConfigArgs, GetConfig, GetReturn, RequiredParams, TypeAllowed } from '.';
|
|
3
3
|
import Xhr from './Xhr';
|
|
4
4
|
type Enabled = undefined | null | (() => boolean) | Ref<boolean> | ComputedRef<boolean> | boolean;
|
|
5
5
|
type Token = Ref<string | null> | ComputedRef<string | null> | string | null;
|
|
@@ -10,9 +10,9 @@ declare type UseXhr<T, Z extends TypeAllowed, A extends TypeAllowed[], F extends
|
|
|
10
10
|
onError: (cb: OnErrorCb<P>) => unknown;
|
|
11
11
|
onStart: OnStartCb<T, P>;
|
|
12
12
|
onEnd: OnEndCb<T, P>;
|
|
13
|
-
onProgress: (e: ProgressEvent) =>
|
|
14
|
-
onAbort: (e: ProgressEvent) =>
|
|
15
|
-
context:
|
|
13
|
+
onProgress: (e: ProgressEvent) => unknown;
|
|
14
|
+
onAbort: (e: ProgressEvent) => unknown;
|
|
15
|
+
context: unknown;
|
|
16
16
|
legacy: boolean;
|
|
17
17
|
token: Token;
|
|
18
18
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-use-async",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"description": "Xhr and async helpers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"beforebuild": "node ./scripts/beforeBuild.cjs && npm run tsc:export-types",
|
|
17
17
|
"build": "npm run beforebuild && npm run build:webpack && npm run afterbuild",
|
|
18
18
|
"build:webpack": "webpack --mode=production",
|
|
19
|
-
"lint": "npm run tsc:check-types && eslint src tests",
|
|
20
|
-
"lint:fix": "npm run tsc:check-types && eslint --fix src tests",
|
|
19
|
+
"lint": "npm run tsc:check-types && eslint scripts src tests",
|
|
20
|
+
"lint:fix": "npm run tsc:check-types && eslint --fix scripts src tests",
|
|
21
21
|
"lint:quiet": "eslint --quiet \"{tests,src}/**/*.{js,ts,tsx,vue}\" && npm run tsc:check-types",
|
|
22
22
|
"precommit": "lint-staged",
|
|
23
|
-
"prepare": "husky
|
|
23
|
+
"prepare": "husky",
|
|
24
24
|
"prepublishOnly": "npm run lint && npm run test && npm run build",
|
|
25
25
|
"test": "NODE_OPTIONS=--unhandled-rejections=warn jest tests/** --no-cache",
|
|
26
26
|
"tsc:check-types": "tsc --noemit",
|
|
@@ -28,37 +28,39 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
31
|
-
"@babel/
|
|
32
|
-
"@babel/preset-
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
31
|
+
"@babel/plugin-proposal-decorators": "^7.28.0",
|
|
32
|
+
"@babel/preset-env": "^7.28.0",
|
|
33
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
34
|
+
"@eslint/compat": "^1.3.1",
|
|
35
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
36
|
+
"@eslint/js": "^9.32.0",
|
|
37
|
+
"@stylistic/eslint-plugin": "^3.1.0",
|
|
38
|
+
"@types/jest": "^30.0.0",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^8.39.0",
|
|
40
|
+
"@typescript-eslint/parser": "^8.39.0",
|
|
41
|
+
"babel-loader": "^10.0.0",
|
|
40
42
|
"babel-plugin-module-resolver": "^5.0.2",
|
|
41
|
-
"eslint": "^9.
|
|
42
|
-
"eslint-config-airbnb-
|
|
43
|
-
"eslint-import-resolver-typescript": "^
|
|
44
|
-
"eslint-plugin-import": "^
|
|
45
|
-
"eslint-plugin-jest": "^
|
|
46
|
-
"
|
|
43
|
+
"eslint": "^9.32.0",
|
|
44
|
+
"eslint-config-airbnb-extended": "^2.1.2",
|
|
45
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
46
|
+
"eslint-plugin-import-x": "^4.16.1",
|
|
47
|
+
"eslint-plugin-jest": "^29.0.1",
|
|
48
|
+
"eslint-plugin-n": "^17.21.3",
|
|
49
|
+
"globals": "^16.3.0",
|
|
47
50
|
"husky": "^9.1.7",
|
|
48
|
-
"jest": "^
|
|
49
|
-
"jest-environment-jsdom": "^
|
|
50
|
-
"lint-staged": "^
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
51
|
+
"jest": "^30.0.5",
|
|
52
|
+
"jest-environment-jsdom": "^30.0.5",
|
|
53
|
+
"lint-staged": "^16.1.4",
|
|
54
|
+
"rimraf": "^6.0.1",
|
|
55
|
+
"ts-node": "^10.9.2",
|
|
56
|
+
"typescript": "^5.9.2",
|
|
57
|
+
"typescript-eslint": "^8.39.0",
|
|
58
|
+
"webpack": "^5.101.0",
|
|
54
59
|
"webpack-cli": "^6.0.1"
|
|
55
60
|
},
|
|
56
61
|
"peerDependencies": {
|
|
57
62
|
"vue": "*"
|
|
58
63
|
},
|
|
59
|
-
"engines": {
|
|
60
|
-
"node": ">=14"
|
|
61
|
-
},
|
|
62
64
|
"os": [
|
|
63
65
|
"darwin",
|
|
64
66
|
"linux"
|