vue-use-async 1.13.0 → 1.13.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/Xhr.d.ts +2 -2
- package/dist/cache.d.ts +4 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mockXhr.d.ts +1 -1
- package/dist/useAsync.d.ts +1 -1
- package/package.json +21 -16
package/dist/Xhr.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export default class Xhr<T> {
|
|
|
9
9
|
onAbort: (e: ProgressEvent) => void;
|
|
10
10
|
onProgress: (e: ProgressEvent) => void;
|
|
11
11
|
onEnd: (result: T | null, e: ProgressEvent) => void;
|
|
12
|
-
static onBeforeSendList:
|
|
12
|
+
static onBeforeSendList: ((params: Obj) => Obj)[];
|
|
13
13
|
static onBeforeSend(cb: (params: Obj) => Obj): void;
|
|
14
14
|
token: string | null;
|
|
15
15
|
url: string;
|
|
@@ -64,7 +64,7 @@ export default class Xhr<T> {
|
|
|
64
64
|
/**
|
|
65
65
|
* url with path params will be replaced by params values
|
|
66
66
|
*/
|
|
67
|
-
static injectParamsInUrl(url: string, params: Obj |
|
|
67
|
+
static injectParamsInUrl(url: string, params: Obj | unknown[], method?: Method): {
|
|
68
68
|
url: string;
|
|
69
69
|
params: Obj;
|
|
70
70
|
};
|
package/dist/cache.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import type { XhrGet } from '.';
|
|
2
|
-
|
|
3
|
-
* @params {String} params.id
|
|
4
|
-
* @params {Promise} params.xhr
|
|
5
|
-
* @params {Number} params.duration, in ms
|
|
6
|
-
*/
|
|
7
|
-
export default function <T>(params: {
|
|
2
|
+
interface Params<T> {
|
|
8
3
|
id: string;
|
|
9
4
|
xhr?: () => XhrGet<T>;
|
|
10
5
|
duration?: number | 'max' | null;
|
|
11
|
-
}
|
|
6
|
+
}
|
|
7
|
+
export default function <T>(params: Params<T>): XhrGet<T>;
|
|
12
8
|
export declare function cacheSize(): number;
|
|
13
9
|
export declare function cacheIds(): string[];
|
|
14
10
|
export declare function clearCache(id?: string): void;
|
|
11
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export type $GetConfigArgs<T = object> = (Omit<GetConfigArgsWithoutParams, 'url'
|
|
|
44
44
|
export type $GetConfig<T> = string | $GetConfigArgs<T>;
|
|
45
45
|
export type GetConfig<T> = $GetConfig<T> | Ref<$GetConfig<T>>;
|
|
46
46
|
export type TypeAllowed = undefined | null | string | number | boolean | Obj;
|
|
47
|
-
type Params<Z, A extends unknown[]> = (() => (Z | [...A])) | ComputedRef<Z | [...A]> | Ref<Z | [...A]> | Z | [...A];
|
|
47
|
+
type Params<Z, A extends unknown[]> = A extends [unknown, unknown, ...unknown[]] ? (() => [...A]) | ComputedRef<[...A]> | Ref<[...A]> | [...A] : (() => (Z | [...A])) | ComputedRef<Z | [...A]> | Ref<Z | [...A]> | Z | [...A];
|
|
48
48
|
export type RequiredParams<Z extends TypeAllowed, A extends TypeAllowed[]> = Params<Z, A>;
|
|
49
49
|
export interface GetReturn<T> {
|
|
50
50
|
isPending: ComputedRef<undefined | boolean>;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
import{computed as t,isRef as e,onBeforeUnmount as r,ref as n,unref as o,watch as i}from"vue";var u=new Map;function a(t){var e,r,n=t||{},o=n.id,i=n.xhr,a="string"!=typeof t.duration&&t.duration||200;if("max"===t.duration&&(a=36e5),!u.get(o)&&i?(e=i(),u.set(o,e),e.then(function(t){return"[Log] add cache: ".concat(o),clearTimeout(r),r=window.setTimeout(function(){u.delete(o),"[Log] delete cache: ".concat(o),clearTimeout(r)},a),t},function(){u.delete(o),"[Log] delete cache: ".concat(o)})):o&&(e=u.get(o)),e)return e;throw Error("Call to undefined cache")}function s(){return u.size}function c(){return Array.from(u.keys())}function l(t){t?u.delete(t):u.forEach(function(t,e,r){r.delete(e)})}function f(t){return f="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},f(t)}function v(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,d(n.key),n)}}function h(t,e,r){return e&&v(t.prototype,e),r&&v(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function p(t,e,r){return(e=d(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function d(t){var e=function(t){if("object"!=f(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=f(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==f(e)?e:e+""}var y=h(function t(){var e=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),p(this,"resolve",void 0),p(this,"reject",void 0),p(this,"promise",void 0),p(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 m="10000000-1000-4000-8000-100000000000".replace(/[018]/g,function(t){return(+t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+t/4).toString(16)});function b(t){return b="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},b(t)}function g(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&&g(t.prototype,e),r&&g(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"!=b(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=b(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==b(e)?e:e+""}var w=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=m,this.value=e});function O(e,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(t){return t},o=void 0===e.value?r:e.value;return e.value=void 0===o?o:new w(null==n?void 0:n(o)),i(function(){return e.value},function(t){void 0===t||t instanceof w||(e.value=new w(null==n?void 0:n(t)))}),t({get:function(){var t;return void 0===(t=e.value instanceof w?e.value.value:e.value)?r:t},set:function(t){e.value=new w(t)}})}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 P=function(e,r){var u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:n(!0),a=n(),s=n(),c=n(null),l=[],f=[],v=[],h=n(null),p=t(function(){return"function"==typeof r?r():o(r)}),d=n(),y=t(function(){return"function"==typeof u?u():o(u)}),b=function(t){if(!y.value)return null;var r,n;a.value&&(null===(r=h.value)||void 0===r||null===(n=r.abortXhr)||void 0===n||n.call(r)),f.forEach(function(t){return t(p.value)}),a.value=!0,c.value=null;var o,i=e,u=e;return h.value=Array.isArray(t)?u.apply(void 0,function(t){if(Array.isArray(t))return S(t)}(o=t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(o)||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}}(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(t),h.value.catch(function(t){c.value=t||null,l.forEach(function(t){return t(c.value,p.value)})}),h.value.then(function(t){s.value=t,v.forEach(function(e){return e(t,p.value)})}),h.value.finally(function(){a.value=!1}),h.value},g=t(function(){return h.value});return i(function(){return y.value},function(t){!a.value&&t&&b(p.value)},{immediate:!1}),i(function(){return c.value},function(t){if(t)throw t}),i(function(){return p.value},function(t){var e=JSON.stringify(t);!a.value&&(void 0===t&&void 0===d.value||y.value&&e!==JSON.stringify(d.value))&&b(t),d.value=void 0===e?void 0:JSON.parse(e)},{immediate:y.value,deep:!0}),{isPending:a,data:t({get:function(){return s.value},set:function(t){t instanceof w&&t.uuid===m||console.warn('"useAsync" update a readonly field is not allowed'),s.value=t}}),error:c,reload:function(){return b(p.value)},onError:function(t){l.push(t)},onStart:function(t){f.push(t)},onEnd:function(t){v.push(t)},promise:g}};function R(e){var r=n(),o=n(),i=n(),u=[],a=[],s=n(null);return{mutate:function(t){for(var n=arguments.length,c=new Array(n>1?n-1:0),l=1;l<n;l++)c[l-1]=arguments[l];r.value=!0,i.value=null;var f=e;return s.value=f.apply(void 0,[t].concat(c)),s.value.catch(function(e){i.value=e||null,u.forEach(function(e){return e(i.value,c.length?[t].concat(c):t)}),i.value=e}),s.value.then(function(e){o.value=e,a.forEach(function(e){return e(o.value,c.length?[t].concat(c):t)})}),s.value.finally(function(){r.value=!1}),s.value},onError:function(t){return u.push(t)},onEnd:function(t){return a.push(t)},isPending:r,error:i,data:o,promise:t(function(){return s.value})}}function k(){return function(t){return R(t)}}function A(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){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?A(Object(r),!0).forEach(function(e){D(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):A(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function T(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,u,a=[],s=!0,c=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=i.call(r)).done)&&(a.push(n.value),a.length!==e);s=!0);}catch(t){c=!0,o=t}finally{try{if(!s&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(c)throw o}}return a}}(t,e)||function(t,e){if(t){if("string"==typeof t)return H(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)?H(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 H(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 U(){var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var s=n&&n.prototype instanceof a?n:a,c=Object.create(s.prototype);return L(c,"_invoke",function(r,n,o){var i,a,s,c=0,l=o||[],f=!1,v={p:0,n:0,v:t,a:h,f:h.bind(t,4),d:function(e,r){return i=e,a=0,s=t,v.n=r,u}};function h(r,n){for(a=r,s=n,e=0;!f&&c&&!o&&e<l.length;e++){var o,i=l[e],h=v.p,p=i[2];r>3?(o=p===n)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=h&&((o=r<2&&h<i[1])?(a=0,v.v=n,v.n=i[1]):h<p&&(o=r<3||i[0]>n||n>p)&&(i[4]=r,i[5]=n,v.n=p,a=0))}if(o||r>1)return u;throw f=!0,n}return function(o,l,p){if(c>1)throw TypeError("Generator is already running");for(f&&1===l&&h(l,p),a=l,s=p;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(v.n=-1),h(a,s)):v.n=s:v.v=s);try{if(c=2,i){if(a||(o="next"),e=i[o]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+o+"' method"),a=1);i=t}else if((e=(f=v.n<0)?s:r.call(n,v))!==u)break}catch(e){i=t,a=1,s=e}finally{c=1}}return{value:e,done:f}}}(r,o,i),!0),c}var u={};function a(){}function s(){}function c(){}e=Object.getPrototypeOf;var l=[][n]?e(e([][n]())):(L(e={},n,function(){return this}),e),f=c.prototype=a.prototype=Object.create(l);function v(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,c):(t.__proto__=c,L(t,o,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=c,L(f,"constructor",c),L(c,"constructor",s),s.displayName="GeneratorFunction",L(c,o,"GeneratorFunction"),L(f),L(f,o,"Generator"),L(f,n,function(){return this}),L(f,"toString",function(){return"[object Generator]"}),(U=function(){return{w:i,m:v}})()}function L(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}L=function(t,e,r,n){function i(e,r){L(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},L(t,e,r,n)}function N(t,e,r,n,o,i,u){try{var a=t[i](u),s=a.value}catch(t){return void r(t)}a.done?e(s):Promise.resolve(s).then(n,o)}function x(t){return x="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},x(t)}function I(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,C(n.key),n)}}function D(t,e,r){return(e=C(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function C(t){var e=function(t){if("object"!=x(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=x(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==x(e)?e:e+""}var F=function(){function t(e,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),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(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(e){this._constructor(e);var r=t.injectParamsInUrl(this.url,this.params),n=r.url,o=r.params;return this.url=n,this.params=o,this._oXHR.open("POST",this._getUrl(),!0),this._send(),this._deferred.promise}},{key:"put",value:function(e){this._constructor(e);var r=t.injectParamsInUrl(this.url,this.params),n=r.url,o=r.params;return this.url=n,this.params=o,this._oXHR.open("PUT",this._getUrl(),!0),this._send(),this._deferred.promise}},{key:"get",value:function(e){this._constructor(e||{});var r=t.injectParamsInUrl(this.url,this.params),n=r.url,o=r.params;this.url=n,this.params=o,this._oXHR.open("GET",this._getUrl("multipart"===this.sendAs?{}:this.params),!0),this._send();var i=this._deferred.promise;return i.abortXhr=this.abort.bind(this),i}},{key:"delete",value:function(e){this._constructor(e);var r=t.injectParamsInUrl(this.url,this.params),n=r.url,o=r.params;return this.url=n,this.params=o,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"===x(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 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,this._onError=function(t){n.onError(t),n.removeEvents(),n._deferred.reject(t)},this._onEnd=function(){var e,r=(e=U().m(function e(r){var o,i,u,a,s;return U().w(function(e){for(;;)switch(e.n){case 0:if(o=t.parseResult(n._oXHR),!(n._oXHR.status>=400)){e.n=3;break}return e.n=1,null===(i=(u=n._oXHR.response).text)||void 0===i?void 0:i.call(u);case 1:if(s=e.v){e.n=2;break}s=n._oXHR.response;case 2:a=s;try{a=JSON.parse(a)}catch(t){}return n._isXhrRejected=!0,n._onError(a),e.a(2,n._deferred.reject(a));case 3:return n.onEnd(o,r),n._isXhrResolved=!0,n.removeEvents(),e.a(2,n.resolve(o))}},e)}),function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function u(t){N(i,n,o,u,a,"next",t)}function a(t){N(i,n,o,u,a,"throw",t)}u(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");null!=r&&r.toLowerCase().includes("json")&&(e=JSON.parse(t.response))}catch(r){e=t.response}return e}},{key:"extractQueryParams",value:function(t){var e=t,r={},n=e.search(/#/);n>-1&&(e=e.substring(0,n));var o=e.indexOf("?"),i=(!0).toString(),u=(!1).toString();return o>-1&&e.split("?")[1].split("&").reduce(function(t,e){var r=t,n=T(e.split("="),2),o=n[0],a=n[1],s=T(/^(?:"?([^"]+)"?)$/.exec(void 0===a?"":a)||[],2)[1];if(s===i||s===u)return r[o]=s===i,r;var c=Number(s);return r[o]=""===s||Number.isNaN(c)?s:c,r},r),r}},{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=e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=t.injectParamsInUrl(r,n);r=o.url,n=o.params;var i=r.includes("?")?"&":"?",u="";return n&&!Array.isArray(n)&&"object"===x(n)?Object.getOwnPropertyNames(n).filter(function(t){return void 0!==n[t]}).forEach(function(t){u+="".concat(i).concat(t,"=").concat(encodeURIComponent(JSON.stringify(n[t]))),i="&"}):n&&(u=i+encodeURIComponent(JSON.stringify(n))),(r=r.replace(/\/:[^/]*/gi,""))+u}},{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"!==x(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(x(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]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"GET";if(Array.isArray(r)||0===Object.keys(r).length)return{url:e,params:r};var o=r,i=e;if("GET"===n){i=decodeURIComponent(e);var u=t.extractQueryParams(i),a=i.search(/\?|#/);a>-1&&(i=i.substring(0,a)),o=Object.getOwnPropertyNames(r).reduce(function(t,e){return X(X({},t),{},D({},e,r[e]))},X({},u)),Object.keys(o).forEach(function(t){void 0!==u[t]&&(u[t]=o[t],delete o[t])});var s=Object.keys(u);if(s.length){var c="?";s.forEach(function(t){if(!0===u[t]||!1===u[t])i+="".concat(c).concat(t,"=").concat(u[t]);else if(null===u[t])i+="".concat(c).concat(t,"=").concat(u[t]);else{var e=Number(u[t]),r=Number.isNaN(e)?encodeURIComponent('"'.concat(u[t],'"')):e;i+="".concat(c).concat(t,"=").concat(r)}c="&"})}}return(i.match(/:[a-z0-9]+/gi)||[]).forEach(function(e){var r=e;r=r.substring(1),void 0!==o[r]&&(i=t._stringifyForPathParam(i,r,o),delete o[r])}),{url:i,params:o}}}],r&&I(e.prototype,r),n&&I(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}();function J(t){return J="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},J(t)}function G(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?G(Object(r),!0).forEach(function(e){M(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):G(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function M(t,e,r){return(e=function(t){var e=function(t){if("object"!=J(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=J(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==J(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}D(F,"onBeforeSendList",[]);var q=function(){},z=function(t){return o(t)};function $(u){var s=u||{onError:function(){},onStart:function(){},onEnd:function(){},context:null,legacy:!1,token:null},c=s.onError,l=s.onStart,f=s.onEnd,v=s.context,h=s.legacy,p=s.token,d=void 0===p?null:p,y=n([]),b=[],g=function(e,r,n){var i,u=n,a=t(function(){var t={},e=o(r||{});return u||(u=e.params||{}),t.params=o(u),d&&(t.token=z(d)),t.url=o(e.url),t}),s=new F,c=o(a.value.params)||{};switch(e){case"post":default:i=s.post.bind(s);break;case"put":i=s.put.bind(s);break;case"delete":i=s.delete.bind(s)}return B(B({},P(function(){return i(B(B({},a.value),{},{params:c}))})),{},{xhr:s})};return h||r(function(){y.value.forEach(function(t){t.isPending&&t.abort()}),b.forEach(function(t){return t()})}),{get:function(r,u,s){var h=u,p=new F,g=(c||q).bind(v),E=(l||q).bind(v),_=(f||q).bind(v),j=[g],O=[E],S=[_],P=n(null);y.value.push(p);var R=n(),k=n(),A="",X=0,T=t(function(){var t,n={},i=o(r);"string"==typeof i?t=i:(t=o(i.url),h||(h=i.params||{}),X=i.cacheDuration,void 0!==i.enabled&&(n.enabled=i.enabled),void 0===n.enabled&&(n.enabled=s),n.params=o(h),n.cacheDuration=X),d&&(n.token=z(d));var u=o(n.params||h||{});return"function"==typeof u&&(u=u()),n.params=B(B({},u),e(h)?h.value||{}:h),A="function"==typeof t?t(n.params):o(t),n.url=A,n}),H=function(){var t=void 0!==T.value.enabled?T.value.enabled:s;return void 0===t||(e(t)?o(t):"function"==typeof t?t():!0===t)},U=n(),L=function(){if(H()){R.value&&p.abort();var t="object"===J(T.value.params)?T.value.params:{};O.forEach(function(e){return e(t,p)}),R.value=!0,P.value=null;var e=decodeURIComponent(F.stringifyUrl(String(A),t));U.value=a({id:e,xhr:p.get.bind(p,T.value),duration:X}),U.value.catch(function(t){j.forEach(function(e){return e(t,p)}),P.value=t}),U.value.then(function(t){k.value=t}),U.value.finally(function(){var e;(e=y.value.indexOf(p))>-1&&y.value.splice(e,1),R.value=!1,S.forEach(function(e){return e(k.value,t,p)})})}};return b.push(i(function(){return T.value},L,{immediate:H(),deep:!0})),b.push(i(function(){return P.value},function(t){if(t)throw t})),{isPending:t(function(){return R.value}),data:t({get:function(){return k.value},set:function(t){t instanceof w&&t.uuid===m||console.warn('"useXhr" update a readonly field is not allowed'),k.value=t}}),onError:function(t){return j.push(t)},onStart:function(t){return O.push(t)},onEnd:function(t){return S.push(t)},error:P,abort:function(){var t;return null===(t=U.value)||void 0===t?void 0:t.abortXhr()},promise:t(function(){return U.value||new Promise(function(){})}),reload:L,xhr:p}},post:function(t,e){return g("post",t,e)},put:function(t,e){return g("put",t,e)},delete:function(t,e){return g("delete",t,e)}}}function Q(e){var o,u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:400,a=n(!1),s=0;return i(function(){return e.value},function(t){if(t&&(s=Date.now(),a.value=t),!1===t&&s>0){var e=Date.now()-s;clearTimeout(o),e>u?a.value=t:o=setTimeout(function(){a.value=t},u-e)}},{immediate:!0}),r(function(){clearTimeout(o)}),t(function(){return a.value})}export{y as Deferred,F as Xhr,a as cache,c as cacheIds,s as cacheSize,l as clearCache,P as useAsync,R as useMutation,k as useMutationWithError,O as useResult,Q as useSpinner,$ as useXhr};
|
|
2
|
+
import{computed as t,isRef as e,onBeforeUnmount as r,ref as n,unref as o,watch as i}from"vue";function u(){var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof s?n:s,f=Object.create(u.prototype);return a(f,"_invoke",function(r,n,o){var i,u,a,s=0,f=o||[],l=!1,v={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,r){return i=e,u=0,a=t,v.n=r,c}};function p(r,n){for(u=r,a=n,e=0;!l&&s&&!o&&e<f.length;e++){var o,i=f[e],p=v.p,h=i[2];r>3?(o=h===n)&&(a=i[(u=i[4])?5:(u=3,3)],i[4]=i[5]=t):i[0]<=p&&((o=r<2&&p<i[1])?(u=0,v.v=n,v.n=i[1]):p<h&&(o=r<3||i[0]>n||n>h)&&(i[4]=r,i[5]=n,v.n=h,u=0))}if(o||r>1)return c;throw l=!0,n}return function(o,f,h){if(s>1)throw TypeError("Generator is already running");for(l&&1===f&&p(f,h),u=f,a=h;(e=u<2?t:a)||!l;){i||(u?u<3?(u>1&&(v.n=-1),p(u,a)):v.n=a:v.v=a);try{if(s=2,i){if(u||(o="next"),e=i[o]){if(!(e=e.call(i,a)))throw TypeError("iterator result is not an object");if(!e.done)return e;a=e.value,u<2&&(u=0)}else 1===u&&(e=i.return)&&e.call(i),u<2&&(a=TypeError("The iterator does not provide a '"+o+"' method"),u=1);i=t}else if((e=(l=v.n<0)?a:r.call(n,v))!==c)break}catch(e){i=t,u=1,a=e}finally{s=1}}return{value:e,done:l}}}(r,o,i),!0),f}var c={};function s(){}function f(){}function l(){}e=Object.getPrototypeOf;var v=[][n]?e(e([][n]())):(a(e={},n,function(){return this}),e),p=l.prototype=s.prototype=Object.create(v);function h(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,a(t,o,"GeneratorFunction")),t.prototype=Object.create(p),t}return f.prototype=l,a(p,"constructor",l),a(l,"constructor",f),f.displayName="GeneratorFunction",a(l,o,"GeneratorFunction"),a(p),a(p,o,"Generator"),a(p,n,function(){return this}),a(p,"toString",function(){return"[object Generator]"}),(u=function(){return{w:i,m:h}})()}function a(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}a=function(t,e,r,n){function i(e,r){a(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},a(t,e,r,n)}function c(t,e,r,n,o,i,u){try{var a=t[i](u),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,o)}var s=new Map;function f(t){return l.apply(this,arguments)}function l(){var t;return t=u().m(function t(e){var r,n,o,i,a,c;return u().w(function(t){for(;;)switch(t.n){case 0:if(n=(r=e||{}).id,o=r.xhr,i="string"!=typeof e.duration&&e.duration||200,"max"===e.duration&&(i=36e5),!s.get(n)&&o?(a=o(),s.set(n,a),a.then(function(t){return"[Log] add cache: ".concat(n),clearTimeout(c),c=window.setTimeout(function(){s.delete(n),"[Log] delete cache: ".concat(n),clearTimeout(c)},i),t},function(){s.delete(n),"[Log] delete cache: ".concat(n)})):n&&(a=s.get(n)),!a){t.n=1;break}return t.a(2,a);case 1:throw Error("Call to undefined cache");case 2:return t.a(2)}},t)}),l=function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function u(t){c(i,n,o,u,a,"next",t)}function a(t){c(i,n,o,u,a,"throw",t)}u(void 0)})},l.apply(this,arguments)}function v(){return s.size}function p(){return Array.from(s.keys())}function h(t){t?s.delete(t):s.forEach(function(t,e,r){r.delete(e)})}function d(t){return d="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},d(t)}function y(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,g(n.key),n)}}function m(t,e,r){return e&&y(t.prototype,e),r&&y(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function b(t,e,r){return(e=g(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function g(t){var e=function(t){if("object"!=d(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=d(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==d(e)?e:e+""}var w=m(function t(){var e=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),b(this,"resolve",void 0),b(this,"reject",void 0),b(this,"promise",void 0),b(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 j="10000000-1000-4000-8000-100000000000".replace(/[018]/g,function(t){return(+t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+t/4).toString(16)});function _(t){return _="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},_(t)}function O(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,P(n.key),n)}}function E(t,e,r){return e&&O(t.prototype,e),r&&O(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function S(t,e,r){return(e=P(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function P(t){var e=function(t){if("object"!=_(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=_(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==_(e)?e:e+""}var k=E(function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),S(this,"value",void 0),S(this,"uuid",void 0),this.uuid=j,this.value=e});function R(e,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(t){return t},o=void 0===e.value?r:e.value;return e.value=void 0===o?o:new k(null==n?void 0:n(o)),i(function(){return e.value},function(t){void 0===t||t instanceof k||(e.value=new k(null==n?void 0:n(t)))}),t({get:function(){var t;return void 0===(t=e.value instanceof k?e.value.value:e.value)?r:t},set:function(t){e.value=new k(t)}})}function T(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 A=function(e){for(var r=arguments.length,u=new Array(r>1?r-1:0),a=1;a<r;a++)u[a-1]=arguments[a];var c=u[0],s=u[1],f=null!=s?s:n(!0),l=n(),v=n(),p=n(null),h=[],d=[],y=[],m=n(null),b=t(function(){return"function"==typeof c?c():o(c)}),g=n(),w=t(function(){return"function"==typeof f?f():o(f)}),_=function(t){if(!w.value)return null;var r,n;l.value&&(null===(r=m.value)||void 0===r||null===(n=r.abortXhr)||void 0===n||n.call(r)),d.forEach(function(t){return t(b.value)}),l.value=!0,p.value=null;var o,i=e,u=e;return m.value=Array.isArray(t)?u.apply(void 0,function(t){if(Array.isArray(t))return T(t)}(o=t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(o)||function(t,e){if(t){if("string"==typeof t)return T(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)?T(t,e):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(t),m.value.catch(function(t){p.value=t||null,h.forEach(function(t){return t(p.value,b.value)})}),m.value.then(function(t){v.value=t,y.forEach(function(e){return e(t,b.value)})}),m.value.finally(function(){l.value=!1}),m.value},O=t(function(){return m.value});return i(function(){return w.value},function(t){!l.value&&t&&_(b.value)},{immediate:!1}),i(function(){return p.value},function(t){if(t)throw t}),i(function(){return b.value},function(t){var e=JSON.stringify(t);!l.value&&(void 0===t&&void 0===g.value||w.value&&e!==JSON.stringify(g.value))&&_(t),g.value=void 0===e?void 0:JSON.parse(e)},{immediate:w.value,deep:!0}),{isPending:l,data:t({get:function(){return v.value},set:function(t){t instanceof k&&t.uuid===j||console.warn('"useAsync" update a readonly field is not allowed'),v.value=t}}),error:p,reload:function(){return _(b.value)},onError:function(t){h.push(t)},onStart:function(t){d.push(t)},onEnd:function(t){y.push(t)},promise:O}};function X(e){var r=n(),o=n(),i=n(),u=[],a=[],c=n(null);return{mutate:function(t){for(var n=arguments.length,s=new Array(n>1?n-1:0),f=1;f<n;f++)s[f-1]=arguments[f];r.value=!0,i.value=null;var l=e;return c.value=l.apply(void 0,[t].concat(s)),c.value.catch(function(e){i.value=e||null,u.forEach(function(e){return e(i.value,s.length?[t].concat(s):t)}),i.value=e}),c.value.then(function(e){o.value=e,a.forEach(function(e){return e(o.value,s.length?[t].concat(s):t)})}),c.value.finally(function(){r.value=!1}),c.value},onError:function(t){return u.push(t)},onEnd:function(t){return a.push(t)},isPending:r,error:i,data:o,promise:t(function(){return c.value})}}function H(){return function(t){return X(t)}}function x(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 U(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?x(Object(r),!0).forEach(function(e){B(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):x(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function L(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,u,a=[],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)&&(a.push(n.value),a.length!==e);c=!0);}catch(t){s=!0,o=t}finally{try{if(!c&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(s)throw o}}return a}}(t,e)||function(t,e){if(t){if("string"==typeof t)return N(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)?N(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 N(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 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 I(){var t,e,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 D(s,"_invoke",function(r,n,o){var i,a,c,s=0,f=o||[],l=!1,v={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,r){return i=e,a=0,c=t,v.n=r,u}};function p(r,n){for(a=r,c=n,e=0;!l&&s&&!o&&e<f.length;e++){var o,i=f[e],p=v.p,h=i[2];r>3?(o=h===n)&&(c=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((o=r<2&&p<i[1])?(a=0,v.v=n,v.n=i[1]):p<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 l=!0,n}return function(o,f,h){if(s>1)throw TypeError("Generator is already running");for(l&&1===f&&p(f,h),a=f,c=h;(e=a<2?t:c)||!l;){i||(a?a<3?(a>1&&(v.n=-1),p(a,c)):v.n=c:v.v=c);try{if(s=2,i){if(a||(o="next"),e=i[o]){if(!(e=e.call(i,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),a=1);i=t}else if((e=(l=v.n<0)?c:r.call(n,v))!==u)break}catch(e){i=t,a=1,c=e}finally{s=1}}return{value:e,done:l}}}(r,o,i),!0),s}var u={};function a(){}function c(){}function s(){}e=Object.getPrototypeOf;var f=[][n]?e(e([][n]())):(D(e={},n,function(){return this}),e),l=s.prototype=a.prototype=Object.create(f);function v(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,s):(t.__proto__=s,D(t,o,"GeneratorFunction")),t.prototype=Object.create(l),t}return c.prototype=s,D(l,"constructor",s),D(s,"constructor",c),c.displayName="GeneratorFunction",D(s,o,"GeneratorFunction"),D(l),D(l,o,"Generator"),D(l,n,function(){return this}),D(l,"toString",function(){return"[object Generator]"}),(I=function(){return{w:i,m:v}})()}function D(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}D=function(t,e,r,n){function i(e,r){D(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},D(t,e,r,n)}function C(t,e,r,n,o,i,u){try{var a=t[i](u),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,o)}function F(t){return function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function u(t){C(i,n,o,u,a,"next",t)}function a(t){C(i,n,o,u,a,"throw",t)}u(void 0)})}}function J(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,M(n.key),n)}}function B(t,e,r){return(e=M(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function M(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 q=function(){function t(e,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),B(this,"onError",function(){}),B(this,"onStart",function(){}),B(this,"onAbort",function(){}),B(this,"onProgress",function(){}),B(this,"onEnd",function(){}),B(this,"token",null),B(this,"url",""),B(this,"params",{}),B(this,"sendAs","json"),B(this,"timeout",1e4),B(this,"port",80),B(this,"responseType","text"),B(this,"isPending",!1),B(this,"_eventsReady",void 0),B(this,"_oXHR",void 0),B(this,"_onEnd",function(){}),B(this,"_onError",function(){}),B(this,"_deferred",void 0),B(this,"_isXhrResolved",void 0),B(this,"_isXhrRejected",void 0),B(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:(f=F(I().m(function e(r){var n,o,i;return I().w(function(e){for(;;)if(0===e.n)return this._constructor(r),n=t.injectParamsInUrl(this.url,this.params),o=n.url,i=n.params,this.url=o,this.params=i,this._oXHR.open("POST",this._getUrl(),!0),this._send(),e.a(2,this._deferred.promise)},e,this)})),function(t){return f.apply(this,arguments)})},{key:"put",value:(s=F(I().m(function e(r){var n,o,i;return I().w(function(e){for(;;)if(0===e.n)return this._constructor(r),n=t.injectParamsInUrl(this.url,this.params),o=n.url,i=n.params,this.url=o,this.params=i,this._oXHR.open("PUT",this._getUrl(),!0),this._send(),e.a(2,this._deferred.promise)},e,this)})),function(t){return s.apply(this,arguments)})},{key:"get",value:(c=F(I().m(function e(r){var n,o,i,u;return I().w(function(e){for(;;)if(0===e.n)return this._constructor(r||{}),n=t.injectParamsInUrl(this.url,this.params),o=n.url,i=n.params,this.url=o,this.params=i,this._oXHR.open("GET",this._getUrl("multipart"===this.sendAs?{}:this.params),!0),this._send(),(u=this._deferred.promise).abortXhr=this.abort.bind(this),e.a(2,u)},e,this)})),function(t){return c.apply(this,arguments)})},{key:"delete",value:(a=F(I().m(function e(r){var n,o,i;return I().w(function(e){for(;;)if(0===e.n)return this._constructor(r),n=t.injectParamsInUrl(this.url,this.params),o=n.url,i=n.params,this.url=o,this.params=i,this._oXHR.open("DELETE",this._getUrl(this.params),!0),this._send(),e.a(2,this._deferred.promise)},e,this)})),function(t){return a.apply(this,arguments)})},{key:"abort",value:(u=F(I().m(function t(){return I().w(function(t){for(;;)if(0===t.n)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"})),t.a(2,this._deferred.promise)},t,this)})),function(){return u.apply(this,arguments)})},{key:"resolve",value:(i=F(I().m(function t(e){return I().w(function(t){for(;;)if(0===t.n)return this._deferred.resolve(e),t.a(2,this._deferred.promise)},t,this)})),function(t){return i.apply(this,arguments)})},{key:"reject",value:(o=F(I().m(function t(e){return I().w(function(t){for(;;)if(0===t.n)return this._deferred.reject(e),t.a(2,this._deferred.promise)},t,this)})),function(t){return o.apply(this,arguments)})},{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"===G(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 w,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,this._onError=function(t){n.onError(t),n.removeEvents(),n._deferred.reject(t)},this._onEnd=function(){var e=F(I().m(function e(r){var o,i,u,a,c;return I().w(function(e){for(;;)switch(e.n){case 0:if(o=t.parseResult(n._oXHR),!(n._oXHR.status>=400)){e.n=3;break}return e.n=1,null===(i=(u=n._oXHR.response).text)||void 0===i?void 0:i.call(u);case 1:if(c=e.v){e.n=2;break}c=n._oXHR.response;case 2:a=c;try{a=JSON.parse(a)}catch(t){}return n._isXhrRejected=!0,n._onError(a),e.a(2,n._deferred.reject(a));case 3:return n.onEnd(o,r),n._isXhrResolved=!0,n.removeEvents(),e.a(2,n.resolve(o))}},e)}));return function(t){return e.apply(this,arguments)}}(),this._setEvents(this._oXHR)}}],n=[{key:"parseResult",value:function(t){var e=t.response;try{var r=t.getResponseHeader("Content-Type");null!=r&&r.toLowerCase().includes("json")&&(e=JSON.parse(t.response))}catch(r){e=t.response}return e}},{key:"extractQueryParams",value:function(t){var e=t,r={},n=e.search(/#/);n>-1&&(e=e.substring(0,n));var o=e.indexOf("?"),i=(!0).toString(),u=(!1).toString();return o>-1&&e.split("?")[1].split("&").reduce(function(t,e){var r=t,n=L(e.split("="),2),o=n[0],a=n[1],c=L(/^(?:"?([^"]+)"?)$/.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(e){t.onBeforeSendList.push(e)}},{key:"new",value:function(e){return new t(e)}},{key:"stringifyUrl",value:function(e){var r=e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=t.injectParamsInUrl(r,n);r=o.url,n=o.params;var i=r.includes("?")?"&":"?",u="";return n&&!Array.isArray(n)&&"object"===G(n)?Object.getOwnPropertyNames(n).filter(function(t){return void 0!==n[t]}).forEach(function(t){u+="".concat(i).concat(t,"=").concat(encodeURIComponent(JSON.stringify(n[t]))),i="&"}):n&&(u=i+encodeURIComponent(JSON.stringify(n))),(r=r.replace(/\/:[^/]*/gi,""))+u}},{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"!==G(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(G(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]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"GET";if(Array.isArray(r)||0===Object.keys(r).length)return{url:e,params:r};var o=r,i=e;if("GET"===n){i=decodeURIComponent(e);var u=t.extractQueryParams(i),a=i.search(/\?|#/);a>-1&&(i=i.substring(0,a)),o=Object.getOwnPropertyNames(r).reduce(function(t,e){return U(U({},t),{},B({},e,r[e]))},U({},u)),Object.keys(o).forEach(function(t){void 0!==u[t]&&(u[t]=o[t],delete o[t])});var c=Object.keys(u);if(c.length){var s="?";c.forEach(function(t){if(!0===u[t]||!1===u[t])i+="".concat(s).concat(t,"=").concat(u[t]);else if(null===u[t])i+="".concat(s).concat(t,"=").concat(u[t]);else{var e=Number(u[t]),r=Number.isNaN(e)?encodeURIComponent('"'.concat(u[t],'"')):e;i+="".concat(s).concat(t,"=").concat(r)}s="&"})}}return(i.match(/:[a-z0-9]+/gi)||[]).forEach(function(e){var r=e;r=r.substring(1),void 0!==o[r]&&(i=t._stringifyForPathParam(i,r,o),delete o[r])}),{url:i,params:o}}}],r&&J(e.prototype,r),n&&J(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n,o,i,u,a,c,s,f}();function z(){var t,e,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 $(s,"_invoke",function(r,n,o){var i,a,c,s=0,f=o||[],l=!1,v={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,r){return i=e,a=0,c=t,v.n=r,u}};function p(r,n){for(a=r,c=n,e=0;!l&&s&&!o&&e<f.length;e++){var o,i=f[e],p=v.p,h=i[2];r>3?(o=h===n)&&(c=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((o=r<2&&p<i[1])?(a=0,v.v=n,v.n=i[1]):p<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 l=!0,n}return function(o,f,h){if(s>1)throw TypeError("Generator is already running");for(l&&1===f&&p(f,h),a=f,c=h;(e=a<2?t:c)||!l;){i||(a?a<3?(a>1&&(v.n=-1),p(a,c)):v.n=c:v.v=c);try{if(s=2,i){if(a||(o="next"),e=i[o]){if(!(e=e.call(i,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),a=1);i=t}else if((e=(l=v.n<0)?c:r.call(n,v))!==u)break}catch(e){i=t,a=1,c=e}finally{s=1}}return{value:e,done:l}}}(r,o,i),!0),s}var u={};function a(){}function c(){}function s(){}e=Object.getPrototypeOf;var f=[][n]?e(e([][n]())):($(e={},n,function(){return this}),e),l=s.prototype=a.prototype=Object.create(f);function v(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,s):(t.__proto__=s,$(t,o,"GeneratorFunction")),t.prototype=Object.create(l),t}return c.prototype=s,$(l,"constructor",s),$(s,"constructor",c),c.displayName="GeneratorFunction",$(s,o,"GeneratorFunction"),$(l),$(l,o,"Generator"),$(l,n,function(){return this}),$(l,"toString",function(){return"[object Generator]"}),(z=function(){return{w:i,m:v}})()}function $(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}$=function(t,e,r,n){function i(e,r){$(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},$(t,e,r,n)}function Q(t,e,r,n,o,i,u){try{var a=t[i](u),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,o)}function V(t){return function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function u(t){Q(i,n,o,u,a,"next",t)}function a(t){Q(i,n,o,u,a,"throw",t)}u(void 0)})}}function K(t){return K="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},K(t)}function W(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 Y(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?W(Object(r),!0).forEach(function(e){Z(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):W(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function Z(t,e,r){return(e=function(t){var e=function(t){if("object"!=K(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=K(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==K(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}B(q,"onBeforeSendList",[]);var tt=function(){},et=function(t){return o(t)};function rt(u){var a=u||{onError:function(){},onStart:function(){},onEnd:function(){},context:null,legacy:!1,token:null},c=a.onError,s=a.onStart,l=a.onEnd,v=a.context,p=a.legacy,h=a.token,d=void 0===h?null:h,y=n([]),m=[],b=function(e,r,n){var i,u=n,a=t(function(){var t={},e=o(r||{});return u||(u=e.params||{}),t.params=o(u),d&&(t.token=et(d)),t.url=o(e.url),t}),c=new q,s=o(a.value.params)||{};switch(e){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 Y(Y({},A(V(z().m(function t(){return z().w(function(t){for(;;)if(0===t.n)return t.a(2,i(Y(Y({},a.value),{},{params:s})))},t)})))),{},{xhr:c})};return p||r(function(){y.value.forEach(function(t){t.isPending&&t.abort()}),m.forEach(function(t){return t()})}),{get:function(r,u,a){var p=u,h=new q,b=(c||tt).bind(v),g=(s||tt).bind(v),w=(l||tt).bind(v),_=[b],O=[g],E=[w],S=n(null);y.value.push(h);var P=n(),R=n(),T="",A=0,X=t(function(){var t,n={},i=o(r);"string"==typeof i?t=i:(t=o(i.url),p||(p=i.params||{}),A=i.cacheDuration,void 0!==i.enabled&&(n.enabled=i.enabled),void 0===n.enabled&&(n.enabled=a),n.params=o(p),n.cacheDuration=A),d&&(n.token=et(d));var u=o(n.params||p||{});return"function"==typeof u&&(u=u()),n.params=Y(Y({},u),e(p)?p.value||{}:p),T="function"==typeof t?t(n.params):o(t),n.url=T,n}),H=function(){var t=void 0!==X.value.enabled?X.value.enabled:a;return void 0===t||(e(t)?o(t):"function"==typeof t?t():!0===t)},x=n(),U=function(){if(H()){P.value&&h.abort();var t="object"===K(X.value.params)?X.value.params:{};O.forEach(function(e){return e(t,h)}),P.value=!0,S.value=null;var e=decodeURIComponent(q.stringifyUrl(String(T),t));x.value=f({id:e,xhr:h.get.bind(h,X.value),duration:A}),x.value.catch(function(t){_.forEach(function(e){return e(t,h)}),S.value=t}),x.value.then(function(t){R.value=t}),x.value.finally(function(){var e;(e=y.value.indexOf(h))>-1&&y.value.splice(e,1),P.value=!1,E.forEach(function(e){return e(R.value,t,h)})})}};return m.push(i(function(){return X.value},U,{immediate:H(),deep:!0})),m.push(i(function(){return S.value},function(t){if(t)throw t})),{isPending:t(function(){return P.value}),data:t({get:function(){return R.value},set:function(t){t instanceof k&&t.uuid===j||console.warn('"useXhr" update a readonly field is not allowed'),R.value=t}}),onError:function(t){return _.push(t)},onStart:function(t){return O.push(t)},onEnd:function(t){return E.push(t)},error:S,abort:function(){var t;return null===(t=x.value)||void 0===t?void 0:t.abortXhr()},promise:t(V(z().m(function t(){return z().w(function(t){for(;;)if(0===t.n)return t.a(2,x.value||new Promise(function(){}))},t)}))),reload:U,xhr:h}},post:function(t,e){return b("post",t,e)},put:function(t,e){return b("put",t,e)},delete:function(t,e){return b("delete",t,e)}}}function nt(e){var o,u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:400,a=n(!1),c=0;return i(function(){return e.value},function(t){if(t&&(c=Date.now(),a.value=t),!1===t&&c>0){var e=Date.now()-c;clearTimeout(o),e>u?a.value=t:o=setTimeout(function(){a.value=t},u-e)}},{immediate:!0}),r(function(){clearTimeout(o)}),t(function(){return a.value})}export{w as Deferred,q as Xhr,f as cache,p as cacheIds,v as cacheSize,h as clearCache,A as useAsync,X as useMutation,H as useMutationWithError,R as useResult,nt as useSpinner,rt as useXhr};
|
package/dist/mockXhr.d.ts
CHANGED
package/dist/useAsync.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { RequiredParams, TypeAllowed, UnwrappedPromiseType } from '.';
|
|
|
3
3
|
type OnErrorCb<T> = (e: null | Error, params: T) => unknown;
|
|
4
4
|
type OnStartCb<T> = (params: T) => unknown;
|
|
5
5
|
type OnEndCb<T, Z> = (res: T, params: Z) => unknown;
|
|
6
|
-
declare const useAsync: <T, Z extends TypeAllowed, A extends TypeAllowed[], F extends ((...args: A) => Promise<T>) | ((args: Z) => Promise<T>), P extends RequiredParams<Parameters<F>[0], A>>(func: ((...args: A) => Promise<T>) | ((args: Z) => Promise<T>), params?: P, enabled?: Ref<boolean> | (() => boolean)) => {
|
|
6
|
+
declare const useAsync: <T, Z extends TypeAllowed, A extends TypeAllowed[], F extends ((...args: A) => Promise<T>) | ((args: Z) => Promise<T>), P extends RequiredParams<Parameters<F>[0], A>>(func: ((...args: A) => Promise<T>) | ((args: Z) => Promise<T>), ...[params, enabledArg]: undefined extends P ? [params?: P, enabled?: Ref<boolean> | (() => boolean)] : [params: P, enabled?: Ref<boolean> | (() => boolean)]) => {
|
|
7
7
|
isPending: Ref<undefined | boolean>;
|
|
8
8
|
data: ComputedRef<undefined | null | UnwrappedPromiseType<F>>;
|
|
9
9
|
error: Ref<null | Error>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-use-async",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.4",
|
|
4
4
|
"description": "Xhr and async helpers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"main": "dist/index.js",
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
14
|
"scripts": {
|
|
15
|
-
"afterbuild": "node
|
|
16
|
-
"beforebuild": "node
|
|
15
|
+
"afterbuild": "node scripts/afterbuild.js",
|
|
16
|
+
"beforebuild": "node scripts/beforeBuild.js && npm run tsgo:export-types",
|
|
17
17
|
"build": "npm run beforebuild && npm run build:webpack && npm run afterbuild",
|
|
18
18
|
"build:webpack": "webpack --mode=production",
|
|
19
19
|
"lint": "npm run tsgo:check-types && eslint scripts src tests",
|
|
@@ -26,20 +26,25 @@
|
|
|
26
26
|
"tsgo:check-types": "tsgo --noemit",
|
|
27
27
|
"tsgo:export-types": "tsgo --outDir types"
|
|
28
28
|
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@eslint/config-helpers": "^0.6.0",
|
|
31
|
+
"@jest/globals": "^30.4.1"
|
|
32
|
+
},
|
|
29
33
|
"devDependencies": {
|
|
30
34
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
31
|
-
"@babel/plugin-proposal-decorators": "^7.29.
|
|
32
|
-
"@babel/preset-env": "^7.29.
|
|
33
|
-
"@babel/preset-typescript": "^7.
|
|
35
|
+
"@babel/plugin-proposal-decorators": "^7.29.7",
|
|
36
|
+
"@babel/preset-env": "^7.29.7",
|
|
37
|
+
"@babel/preset-typescript": "^7.29.7",
|
|
34
38
|
"@eslint/compat": "^2.1.0",
|
|
35
39
|
"@eslint/eslintrc": "^3.3.5",
|
|
36
40
|
"@eslint/js": "^9.39.2",
|
|
37
41
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
42
|
+
"@tcy/eslint-rules": "^1.6.2",
|
|
38
43
|
"@types/jest": "^30.0.0",
|
|
39
44
|
"@types/node": "^25.9.1",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
41
|
-
"@typescript-eslint/parser": "^8.
|
|
42
|
-
"@typescript/native-preview": "^7.0.0-dev.
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "^8.60.0",
|
|
46
|
+
"@typescript-eslint/parser": "^8.60.0",
|
|
47
|
+
"@typescript/native-preview": "^7.0.0-dev.20260527.2",
|
|
43
48
|
"babel-loader": "^10.1.1",
|
|
44
49
|
"babel-plugin-module-resolver": "^5.0.3",
|
|
45
50
|
"eslint": "^9.39.2",
|
|
@@ -55,9 +60,9 @@
|
|
|
55
60
|
"rimraf": "^6.1.3",
|
|
56
61
|
"ts-node": "^10.9.2",
|
|
57
62
|
"typescript": "^6.0.3",
|
|
58
|
-
"typescript-eslint": "^8.
|
|
59
|
-
"webpack": "^5.107.
|
|
60
|
-
"webpack-cli": "^7.0.
|
|
63
|
+
"typescript-eslint": "^8.60.0",
|
|
64
|
+
"webpack": "^5.107.2",
|
|
65
|
+
"webpack-cli": "^7.0.3"
|
|
61
66
|
},
|
|
62
67
|
"peerDependencies": {
|
|
63
68
|
"vue": "*"
|
|
@@ -66,8 +71,8 @@
|
|
|
66
71
|
"darwin",
|
|
67
72
|
"linux"
|
|
68
73
|
],
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
|
|
74
|
+
"cpu": [
|
|
75
|
+
"x64",
|
|
76
|
+
"arm64"
|
|
77
|
+
]
|
|
73
78
|
}
|