vue-use-async 1.13.3 → 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/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";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,r){var u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:n(!0),a=n(),c=n(),s=n(null),f=[],l=[],v=[],p=n(null),h=t(function(){return"function"==typeof r?r():o(r)}),d=n(),y=t(function(){return"function"==typeof u?u():o(u)}),m=function(t){if(!y.value)return null;var r,n;a.value&&(null===(r=p.value)||void 0===r||null===(n=r.abortXhr)||void 0===n||n.call(r)),l.forEach(function(t){return t(h.value)}),a.value=!0,s.value=null;var o,i=e,u=e;return p.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),p.value.catch(function(t){s.value=t||null,f.forEach(function(t){return t(s.value,h.value)})}),p.value.then(function(t){c.value=t,v.forEach(function(e){return e(t,h.value)})}),p.value.finally(function(){a.value=!1}),p.value},b=t(function(){return p.value});return i(function(){return y.value},function(t){!a.value&&t&&m(h.value)},{immediate:!1}),i(function(){return s.value},function(t){if(t)throw t}),i(function(){return h.value},function(t){var e=JSON.stringify(t);!a.value&&(void 0===t&&void 0===d.value||y.value&&e!==JSON.stringify(d.value))&&m(t),d.value=void 0===e?void 0:JSON.parse(e)},{immediate:y.value,deep:!0}),{isPending:a,data:t({get:function(){return c.value},set:function(t){t instanceof k&&t.uuid===j||console.warn('"useAsync" update a readonly field is not allowed'),c.value=t}}),error:s,reload:function(){return m(h.value)},onError:function(t){f.push(t)},onStart:function(t){l.push(t)},onEnd:function(t){v.push(t)},promise:b}};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};
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};
@@ -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",
3
+ "version": "1.13.4",
4
4
  "description": "Xhr and async helpers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -44,7 +44,7 @@
44
44
  "@types/node": "^25.9.1",
45
45
  "@typescript-eslint/eslint-plugin": "^8.60.0",
46
46
  "@typescript-eslint/parser": "^8.60.0",
47
- "@typescript/native-preview": "^7.0.0-dev.20260526.1",
47
+ "@typescript/native-preview": "^7.0.0-dev.20260527.2",
48
48
  "babel-loader": "^10.1.1",
49
49
  "babel-plugin-module-resolver": "^5.0.3",
50
50
  "eslint": "^9.39.2",
@@ -62,7 +62,7 @@
62
62
  "typescript": "^6.0.3",
63
63
  "typescript-eslint": "^8.60.0",
64
64
  "webpack": "^5.107.2",
65
- "webpack-cli": "^7.0.2"
65
+ "webpack-cli": "^7.0.3"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "vue": "*"