You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

vue-use-async

Package Overview
Dependencies
Maintainers
0
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-use-async - npm Package Compare versions

Comparing version

to
1.9.0-beta.4

4

dist/index.d.ts

@@ -47,2 +47,6 @@ import type { ComputedRef, Ref } from 'vue';

export type TypeAllowed = undefined | null | string | number | boolean | Obj;
type Params<Z, A extends unknown[]> = (() => (Z | [...A])) | ComputedRef<Z | [...A]> | Ref<Z | [...A]> | Z | [
...A
];
export type RequiredParams<Z extends TypeAllowed, A extends TypeAllowed[]> = Params<Required<Z>, Required<A>>;
export type GetReturn<T> = {

@@ -49,0 +53,0 @@ isPending: ComputedRef<undefined | boolean>;

2

dist/index.js

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

import*as e from"vue";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},r={};t.d(r,{cY:()=>h,TF:()=>D,PP:()=>i,LH:()=>a,Ej:()=>u,IL:()=>s,Yb:()=>R,n_:()=>k,bz:()=>S,p6:()=>M,cU:()=>z});const n={log:function(e){},warn:function(e){},info:function(e){},error:function(e){},debug:function(e){}};var o=new Map;function i(e){var t,r,i=e||{},u=i.id,a=i.xhr,s="string"!=typeof e.duration&&e.duration||200;if("max"===e.duration&&(s=36e5),!o.get(u)&&a?(t=a(),o.set(u,t),t.then((function(e){return n.log("[Log] add cache: ".concat(u)),clearTimeout(r),r=window.setTimeout((function(){o.delete(u),n.log("[Log] delete cache: ".concat(u)),clearTimeout(r)}),s),e}),(function(){return o.delete(u),n.log("[Log] delete cache: ".concat(u))}))):u&&(t=o.get(u)),t)return t;throw Error("Call to undefined cache")}function u(){return o.size}function a(){return Array.from(o.keys())}function s(e){e?o.delete(e):o.forEach((function(e,t,r){r.delete(t)})),n.log("[Log] cache cleared")}function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function l(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,d(n.key),n)}}function f(e,t,r){return t&&l(e.prototype,t),r&&l(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function v(e,t,r){return(t=d(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(e){var t=function(e,t){if("object"!=c(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=c(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==c(t)?t:t+""}var h=f((function e(){var t=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),v(this,"resolve",void 0),v(this,"reject",void 0),v(this,"promise",void 0),v(this,"done",!1),this.resolve=function(){throw Error("Can t resolve")},this.reject=function(){throw Error("Can t reject")},this.promise=new Promise((function(e,r){t.resolve=e,t.reject=r})),this.promise.finally((function(){t.done=!0}))}));const p=(y={computed:()=>e.computed,isRef:()=>e.isRef,onBeforeUnmount:()=>e.onBeforeUnmount,ref:()=>e.ref,unref:()=>e.unref,watch:()=>e.watch},m={},t.d(m,y),m);var y,m;const b="10000000-1000-4000-8000-100000000000".replace(/[018]/g,(function(e){return(+e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+e/4).toString(16)}));function g(e){return g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},g(e)}function w(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,j(n.key),n)}}function E(e,t,r){return t&&w(e.prototype,t),r&&w(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _(e,t,r){return(t=j(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function j(e){var t=function(e,t){if("object"!=g(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=g(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==g(t)?t:t+""}var O=E((function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),_(this,"value",void 0),_(this,"uuid",void 0),this.uuid=b,this.value=t}));function S(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(e){return e},n=void 0===e.value?t:e.value;return e.value=void 0===n?n:new O(null==r?void 0:r(n)),(0,p.watch)((function(){return e.value}),(function(t){void 0===t||t instanceof O||(e.value=new O(null==r?void 0:r(t)))})),(0,p.computed)({get:function(){var r;return void 0===(r=e.value instanceof O?e.value.value:e.value)?t:r},set:function(t){e.value=new O(t)}})}function P(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}const R=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:(0,p.ref)(!0),n=(0,p.ref)(),o=(0,p.ref)(),i=(0,p.ref)(null),u=[],a=[],s=[],c=(0,p.ref)(null),l=(0,p.computed)((function(){return"function"==typeof t?t():(0,p.unref)(t)})),f=(0,p.ref)(),v=(0,p.computed)((function(){return"function"==typeof r?r():(0,p.unref)(r)})),d=function(t){if(!v.value)return null;a.forEach((function(e){return e(l.value)})),n.value=!0,i.value=null;var r,f=e,d=e;return c.value=Array.isArray(t)?d.apply(void 0,function(e){if(Array.isArray(e))return P(e)}(r=t)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(r)||function(e,t){if(e){if("string"==typeof e)return P(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?P(e,t):void 0}}(r)||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.")}()):f(t),c.value.catch((function(e){i.value=e||null,u.forEach((function(e){return e(i.value,l.value)})),i.value=e})),c.value.then((function(e){o.value=e,s.forEach((function(t){return t(e,l.value)}))})),c.value.finally((function(){n.value=!1})),c.value},h=(0,p.computed)((function(){return c.value}));return(0,p.watch)((function(){return v.value}),(function(e){!n.value&&e&&d(l.value)}),{immediate:!1}),(0,p.watch)((function(){return i.value}),(function(e){if(e)throw e})),(0,p.watch)((function(){return l.value}),(function(e){var t=JSON.stringify(e);!n.value&&(void 0===e&&void 0===f.value||v.value&&t!==JSON.stringify(f.value))&&d(e),f.value=void 0===t?void 0:JSON.parse(t)}),{immediate:v.value,deep:!0}),{isPending:n,data:(0,p.computed)({get:function(){return o.value},set:function(e){e instanceof O&&e.uuid===b||(console.log(o.value),console.warn('"useAsync" update a readonly field is not allowed')),o.value=e}}),error:i,reload:function(){return d(l.value)},onError:function(e){u.push(e)},onStart:function(e){a.push(e)},onEnd:function(e){s.push(e)},promise:h}};function k(e){var t=(0,p.ref)(),r=(0,p.ref)(),n=(0,p.ref)(),o=[],i=[],u=(0,p.ref)(null);return{mutate:function(a){for(var s=arguments.length,c=new Array(s>1?s-1:0),l=1;l<s;l++)c[l-1]=arguments[l];t.value=!0,n.value=null;var f=e;return u.value=f.apply(void 0,[a].concat(c)),u.value.catch((function(e){n.value=e||null,o.forEach((function(e){return e(n.value,c.length?[a].concat(c):a)})),n.value=e})),u.value.then((function(e){r.value=e,i.forEach((function(e){return e(r.value,c.length?[a].concat(c):a)}))})),u.value.finally((function(){t.value=!1})),u.value},onError:function(e){return o.push(e)},onEnd:function(e){return i.push(e)},isPending:t,error:n,data:r,promise:(0,p.computed)((function(){return u.value}))}}function A(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function X(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,u,a=[],s=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);s=!0);}catch(e){c=!0,o=e}finally{try{if(!s&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(c)throw o}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return T(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?T(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function T(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function H(e){return H="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},H(e)}function L(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,N(n.key),n)}}function U(e,t,r){return(t=N(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function N(e){var t=function(e,t){if("object"!=H(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=H(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==H(t)?t:t+""}var D=function(){function e(t,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),U(this,"onError",(function(){})),U(this,"onStart",(function(){})),U(this,"onAbort",(function(){})),U(this,"onProgress",(function(){})),U(this,"onEnd",(function(){})),U(this,"token",null),U(this,"url",""),U(this,"params",{}),U(this,"sendAs","json"),U(this,"timeout",1e4),U(this,"port",80),U(this,"responseType","text"),U(this,"isPending",!1),U(this,"_eventsReady",void 0),U(this,"_oXHR",void 0),U(this,"_onEnd",(function(){})),U(this,"_onError",(function(){})),U(this,"_deferred",void 0),U(this,"_isXhrResolved",void 0),U(this,"_isXhrRejected",void 0),U(this,"_eventReady",void 0),this._eventsReady=!1,this._constructor(t||{},r)}return t=e,r=[{key:"_getUrl",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.onBeforeSendList.reduce((function(e,t){return t(e||{})}),t);return e.stringifyUrl(this.url,r)}},{key:"removeEvents",value:function(){var e=this,t=function(){e._oXHR.removeEventListener("load",e._onEnd,!1),e._oXHR.removeEventListener("error",e._onError,!1),e._oXHR.removeEventListener("timeout",e._onError,!1),e._oXHR.removeEventListener("loadstart",e.onStart,!1),e._oXHR.removeEventListener("abort",e.onAbort,!1),e._oXHR.upload.removeEventListener("progress",e.onProgress,!1),e._oXHR.removeEventListener("progress",e.onProgress,!1)};this._deferred.promise.then(t,t)}},{key:"post",value:function(e){return this._constructor(e),this._oXHR.open("POST",this._getUrl(),!0),this._send(),this._deferred.promise}},{key:"put",value:function(e){return this._constructor(e),this._oXHR.open("PUT",this._getUrl(),!0),this._send(),this._deferred.promise}},{key:"get",value:function(e){this._constructor(e||{}),this._oXHR.open("GET",this._getUrl("multipart"===this.sendAs?{}:this.params),!0),this._send();var t=this._deferred.promise;return t.abortXhr=this.abort.bind(this),t}},{key:"delete",value:function(e){return this._constructor(e),this._oXHR.open("DELETE",this._getUrl(this.params),!0),this._send(),this._deferred.promise}},{key:"abort",value:function(){return this._isXhrResolved&&!this._isXhrRejected||(this._oXHR.abort(null,this),this._isXhrRejected=!0,this._deferred.reject({message:"Xhr aborted: ".concat(this.url),name:"HTTP-ABORTED"})),this._deferred.promise}},{key:"resolve",value:function(e){return this._deferred.resolve(e),this._deferred.promise}},{key:"reject",value:function(e){return this._deferred.reject(e),this._deferred.promise}},{key:"_setEvents",value:function(e){this._eventsReady||(this._eventReady=!0,e.addEventListener("load",this._onEnd,!1),e.addEventListener("error",this._onError,!1),e.addEventListener("timeout",this._onError,!1),e.addEventListener("loadstart",this.onStart,!1),e.addEventListener("abort",this.onAbort,!1),e.upload.addEventListener("progress",this.onProgress,!1),e.addEventListener("progress",this.onProgress,!1))}},{key:"_send",value:function(){var t;this.isPending=!0,"multipart"===this.sendAs?t=e.getFormData(this.params):"json"===this.sendAs&&(this._oXHR.setRequestHeader("content-type","application/json; charset=utf-8"),t=JSON.stringify(this.params)),this.token&&this._oXHR.setRequestHeader("Authorization","Bearer ".concat(this.token)),this._oXHR.send(t,this)}},{key:"_constructor",value:function(t,r){var n=this;t&&"object"===H(t)?(this.sendAs=t.sendAs||this.sendAs,this.url=t.url||this.url,this.port=t.port||this.port,this.params=t.params||this.params,this.timeout=t.timeout||this.timeout,this.responseType=t.responseType||this.responseType,this.onProgress=(t.onProgress||this.onProgress).bind(this),this.onStart=(t.onStart||this.onStart).bind(this),this.onAbort=(t.onAbort||this.onAbort).bind(this),this.onEnd=(t.onEnd||this.onEnd).bind(this),this.onError=(t.onError||this.onError).bind(this),this.token=t.token||this.token):t&&"string"==typeof t&&(this.url=t,this.params=r||this.params),80!==this.port&&(this.url="".concat(window.location.protocol,"//").concat(window.location.hostname,":").concat(this.port).concat(this.url)),this._deferred=new h,this._deferred.promise.finally((function(){n.isPending=!1})),this._oXHR=new XMLHttpRequest,this._oXHR.timeout=this.timeout,this._oXHR.responseType=this.responseType,this._isXhrResolved=!1,this._isXhrRejected=!1;var o=e.injectParamsInUrl(this.url,this.params),i=o.url,u=o.params;this.url=i,this.params=u,this._onError=function(e){n.onError(e),n.removeEvents(),n._deferred.reject(e)},this._onEnd=function(t){var r=e.parseResult(n._oXHR);return n._oXHR.status>=400?(n._isXhrRejected=!0,n._onError(r),n._deferred.reject(r)):(n.onEnd(r,t),n._isXhrResolved=!0,n.removeEvents(),n.resolve(r))},this._setEvents(this._oXHR)}}],n=[{key:"parseResult",value:function(e){var t=e.response;try{var r=e.getResponseHeader("Content-Type");r&&r.toLowerCase().indexOf("json")>-1&&(t=JSON.parse(e.response))}catch(r){t=e.response}return t}},{key:"extractQueryParams",value:function(e){var t={},r=e.search(/#/);r>-1&&(e=e.substring(0,r));var n=e.indexOf("?"),o=(!0).toString(),i=(!1).toString();return n>-1&&e.split("?")[1].split("&").reduce((function(e,t){var r=X(t.split("="),2),n=r[0],u=r[1],a=X((void 0===u?"":u).match(/^(?:"?([^"]+)"?)$/)||[],2)[1];if(a===o||a===i)e[n]=a===o;else{var s=Number(a);e[n]=""===a||Number.isNaN(s)?a:s}return e}),t),t}},{key:"onBeforeSend",value:function(t){e.onBeforeSendList.push(t)}},{key:"new",value:function(t){return new e(t)}},{key:"stringifyUrl",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.injectParamsInUrl(t,r);t=n.url,r=n.params;var o=t.indexOf("?")>-1?"&":"?",i="";return r&&!Array.isArray(r)&&"object"===H(r)?Object.getOwnPropertyNames(r).filter((function(e){return void 0!==r[e]})).forEach((function(e){i+="".concat(o).concat(e,"=").concat(encodeURIComponent(JSON.stringify(r[e]))),o="&"})):r&&(i=o+encodeURIComponent(JSON.stringify(r))),(t=t.replace(/\/:[^/]*/gi,""))+i}},{key:"getFormData",value:function(e){var t,r=new FormData;return Object.keys(e).forEach((function(n){if(e[n]instanceof FileList)for(var o=0;o<e[n].length;o+=1)r.append(n,e[n][o]);else e[n]instanceof File?r.append(n,e[n]):("object"!==H(t=e[n])&&!Array.isArray(t)||null===t||(t=JSON.stringify(t)),r.append(n,t))})),r}},{key:"_stringifyForPathParam",value:function(e,t,r){var n=r[t];switch(H(r[t])){case"boolean":case"string":case"bigint":case"number":n=String(n);break;default:n=null===n?"null":encodeURIComponent(JSON.stringify(n))}return e.replace(":".concat(t),n)}},{key:"injectParamsInUrl",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Array.isArray(r)||0===Object.keys(r).length)return{url:t,params:r};var n=decodeURIComponent(t),o=e.extractQueryParams(n),i=n.search(/\?|#/);i>-1&&(n=n.substring(0,i));var u=Object.getOwnPropertyNames(r).reduce((function(e,t){return e[t]=r[t],e}),function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?A(Object(r),!0).forEach((function(t){U(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):A(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},o));(n.match(/:[a-z0-9]+/gi)||[]).forEach((function(t){t=t.substring(1),void 0!==u[t]&&(n=e._stringifyForPathParam(n,t,u),delete u[t])})),Object.keys(u).forEach((function(e){void 0!==o[e]&&(o[e]=u[e],delete u[e])}));var a=Object.keys(o);if(a.length){var s="?";a.forEach((function(e){if(!0===o[e]||!1===o[e])n+="".concat(s).concat(e,"=").concat(o[e]);else if(null===o[e])n+="".concat(s).concat(e,"=").concat(o[e]);else{var t=Number(o[e]),r=Number.isNaN(t)?encodeURIComponent('"'.concat(o[e],'"')):t;n+="".concat(s).concat(e,"=").concat(r)}s="&"}))}return{url:n,params:u}}}],r&&L(t.prototype,r),n&&L(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,n}();function I(e){return I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},I(e)}function C(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function x(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?C(Object(r),!0).forEach((function(t){B(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):C(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function B(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=I(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=I(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==I(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}U(D,"onBeforeSendList",[]);var F=function(){},J=function(e){return(0,p.unref)(e)};function z(e){var t=e||{onError:function(){},onStart:function(){},onEnd:function(){},context:null,legacy:!1,token:null},r=t.onError,n=t.onStart,o=t.onEnd,u=t.context,a=t.legacy,s=t.token,c=void 0===s?null:s,l=(0,p.ref)([]),f=[],v=function(e,t,r){var n,o=(0,p.computed)((function(){var e={},n=(0,p.unref)(t||{});r||(r=n.params||{}),e.params=(0,p.unref)(r),c&&(e.token=J(c));var o=(0,p.unref)(e.params||r||{});return"function"==typeof o&&(o=o()),e.url=(0,p.unref)(n.url),e})),i=new D,u=(0,p.unref)(o.value.params)||{};switch(e){case"post":default:n=i.post.bind(i);break;case"put":n=i.put.bind(i);break;case"delete":n=i.delete.bind(i)}return x(x({},R((function(){return n(x(x({},o.value),{},{params:u}))}))),{},{xhr:i})};return a||(0,p.onBeforeUnmount)((function(){l.value.forEach((function(e){e.isPending&&e.abort()})),f.forEach((function(e){return e()}))})),{get:function(e,t,a){var s=new D,v=(r||F).bind(u),d=(n||F).bind(u),h=(o||F).bind(u),y=[v],m=[d],g=[h],w=(0,p.ref)(null);l.value.push(s);var E=(0,p.ref)(),_=(0,p.ref)(),j="",S=0,P=(0,p.computed)((function(){var r,n={},o=(0,p.unref)(e);"string"==typeof o?r=o:(r=(0,p.unref)(o.url),t||(t=o.params||{}),S=o.cacheDuration,void 0!==o.enabled&&(n.enabled=o.enabled),void 0===n.enabled&&(n.enabled=a),n.params=(0,p.unref)(t),n.cacheDuration=S),c&&(n.token=J(c));var i=(0,p.unref)(n.params||t||{});return"function"==typeof i&&(i=i()),n.params=x(x({},i),(0,p.isRef)(t)?t.value||{}:t),j="function"==typeof r?r(n.params):(0,p.unref)(r),n.url=j,n})),R=function(){var e=void 0!==P.value.enabled?P.value.enabled:a;return void 0===e||((0,p.isRef)(e)?(0,p.unref)(e):"function"==typeof e?e():!0===e)},k=(0,p.ref)(),A=function(){if(R()){E.value&&s.abort();var e="object"===I(P.value.params)?P.value.params:{};m.forEach((function(t){return t(e,s)})),E.value=!0,w.value=null;var t=decodeURIComponent(D.stringifyUrl(String(j),e));k.value=i({id:t,xhr:s.get.bind(s,P.value),duration:S}),k.value.catch((function(e){y.forEach((function(t){return t(e,s)})),w.value=e})),k.value.then((function(e){_.value=e})),k.value.finally((function(){var t;(t=l.value.indexOf(s))>-1&&l.value.splice(t,1),E.value=!1,g.forEach((function(t){return t(_.value,e,s)}))}))}};return f.push((0,p.watch)((function(){return P.value}),A,{immediate:R(),deep:!0})),f.push((0,p.watch)((function(){return w.value}),(function(e){if(e)throw e}))),{isPending:(0,p.computed)((function(){return E.value})),data:(0,p.computed)({get:function(){return _.value},set:function(e){e instanceof O&&e.uuid===b||console.warn('"useXhr" update a readonly field is not allowed'),_.value=e}}),onError:function(e){return y.push(e)},onStart:function(e){return m.push(e)},onEnd:function(e){return g.push(e)},error:w,abort:function(){var e;return null===(e=k.value)||void 0===e?void 0:e.abortXhr()},promise:(0,p.computed)((function(){return k.value||new Promise((function(){}))})),reload:A,xhr:s}},post:function(e,t){return v("post",e,t)},put:function(e,t){return v("put",e,t)},delete:function(e,t){return v("delete",e,t)}}}function M(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:400,n=(0,p.ref)(!1),o=0;return(0,p.watch)((function(){return e.value}),(function(e){if(e&&(o=Date.now(),n.value=e),!1===e&&o>0){var i=Date.now()-o;clearTimeout(t),i>r?n.value=e:t=setTimeout((function(){n.value=e}),r-i)}}),{immediate:!0}),(0,p.onBeforeUnmount)((function(){clearTimeout(t)})),(0,p.computed)((function(){return n.value}))}var Y=r.cY,q=r.TF,$=r.PP,Q=r.LH,G=r.Ej,V=r.IL,K=r.Yb,W=r.n_,Z=r.bz,ee=r.p6,te=r.cU;export{Y as Deferred,q as Xhr,$ as cache,Q as cacheIds,G as cacheSize,V as clearCache,K as useAsync,W as useMutation,Z as useResult,ee as useSpinner,te as useXhr};
import*as e from"vue";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},r={};t.d(r,{cY:()=>h,TF:()=>D,PP:()=>i,LH:()=>a,Ej:()=>u,IL:()=>s,Yb:()=>R,n_:()=>k,bz:()=>S,p6:()=>M,cU:()=>z});const n={log:function(e){},warn:function(e){},info:function(e){},error:function(e){},debug:function(e){}};var o=new Map;function i(e){var t,r,i=e||{},u=i.id,a=i.xhr,s="string"!=typeof e.duration&&e.duration||200;if("max"===e.duration&&(s=36e5),!o.get(u)&&a?(t=a(),o.set(u,t),t.then((function(e){return n.log("[Log] add cache: ".concat(u)),clearTimeout(r),r=window.setTimeout((function(){o.delete(u),n.log("[Log] delete cache: ".concat(u)),clearTimeout(r)}),s),e}),(function(){return o.delete(u),n.log("[Log] delete cache: ".concat(u))}))):u&&(t=o.get(u)),t)return t;throw Error("Call to undefined cache")}function u(){return o.size}function a(){return Array.from(o.keys())}function s(e){e?o.delete(e):o.forEach((function(e,t,r){r.delete(t)})),n.log("[Log] cache cleared")}function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function l(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,d(n.key),n)}}function f(e,t,r){return t&&l(e.prototype,t),r&&l(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function v(e,t,r){return(t=d(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(e){var t=function(e,t){if("object"!=c(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=c(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==c(t)?t:t+""}var h=f((function e(){var t=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),v(this,"resolve",void 0),v(this,"reject",void 0),v(this,"promise",void 0),v(this,"done",!1),this.resolve=function(){throw Error("Can t resolve")},this.reject=function(){throw Error("Can t reject")},this.promise=new Promise((function(e,r){t.resolve=e,t.reject=r})),this.promise.finally((function(){t.done=!0}))}));const p=(y={computed:()=>e.computed,isRef:()=>e.isRef,onBeforeUnmount:()=>e.onBeforeUnmount,ref:()=>e.ref,unref:()=>e.unref,watch:()=>e.watch},m={},t.d(m,y),m);var y,m;const b="10000000-1000-4000-8000-100000000000".replace(/[018]/g,(function(e){return(+e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+e/4).toString(16)}));function g(e){return g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},g(e)}function w(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,j(n.key),n)}}function E(e,t,r){return t&&w(e.prototype,t),r&&w(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _(e,t,r){return(t=j(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function j(e){var t=function(e,t){if("object"!=g(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=g(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==g(t)?t:t+""}var O=E((function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),_(this,"value",void 0),_(this,"uuid",void 0),this.uuid=b,this.value=t}));function S(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(e){return e},n=void 0===e.value?t:e.value;return e.value=void 0===n?n:new O(null==r?void 0:r(n)),(0,p.watch)((function(){return e.value}),(function(t){void 0===t||t instanceof O||(e.value=new O(null==r?void 0:r(t)))})),(0,p.computed)({get:function(){var r;return void 0===(r=e.value instanceof O?e.value.value:e.value)?t:r},set:function(t){e.value=new O(t)}})}function P(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}const R=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:(0,p.ref)(!0),n=(0,p.ref)(),o=(0,p.ref)(),i=(0,p.ref)(null),u=[],a=[],s=[],c=(0,p.ref)(null),l=(0,p.computed)((function(){return"function"==typeof t?t():(0,p.unref)(t)})),f=(0,p.ref)(),v=(0,p.computed)((function(){return"function"==typeof r?r():(0,p.unref)(r)})),d=function(t){if(!v.value)return null;a.forEach((function(e){return e(l.value)})),n.value=!0,i.value=null;var r,f=e,d=e;return c.value=Array.isArray(t)?d.apply(void 0,function(e){if(Array.isArray(e))return P(e)}(r=t)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(r)||function(e,t){if(e){if("string"==typeof e)return P(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?P(e,t):void 0}}(r)||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.")}()):f(t),c.value.catch((function(e){i.value=e||null,u.forEach((function(e){return e(i.value,l.value)})),i.value=e})),c.value.then((function(e){o.value=e,s.forEach((function(t){return t(e,l.value)}))})),c.value.finally((function(){n.value=!1})),c.value},h=(0,p.computed)((function(){return c.value}));return(0,p.watch)((function(){return v.value}),(function(e){!n.value&&e&&d(l.value)}),{immediate:!1}),(0,p.watch)((function(){return i.value}),(function(e){if(e)throw e})),(0,p.watch)((function(){return l.value}),(function(e){var t=JSON.stringify(e);!n.value&&(void 0===e&&void 0===f.value||v.value&&t!==JSON.stringify(f.value))&&d(e),f.value=void 0===t?void 0:JSON.parse(t)}),{immediate:v.value,deep:!0}),{isPending:n,data:(0,p.computed)({get:function(){return o.value},set:function(e){e instanceof O&&e.uuid===b||console.warn('"useAsync" update a readonly field is not allowed'),o.value=e}}),error:i,reload:function(){return d(l.value)},onError:function(e){u.push(e)},onStart:function(e){a.push(e)},onEnd:function(e){s.push(e)},promise:h}};function k(e){var t=(0,p.ref)(),r=(0,p.ref)(),n=(0,p.ref)(),o=[],i=[],u=(0,p.ref)(null);return{mutate:function(a){for(var s=arguments.length,c=new Array(s>1?s-1:0),l=1;l<s;l++)c[l-1]=arguments[l];t.value=!0,n.value=null;var f=e;return u.value=f.apply(void 0,[a].concat(c)),u.value.catch((function(e){n.value=e||null,o.forEach((function(e){return e(n.value,c.length?[a].concat(c):a)})),n.value=e})),u.value.then((function(e){r.value=e,i.forEach((function(e){return e(r.value,c.length?[a].concat(c):a)}))})),u.value.finally((function(){t.value=!1})),u.value},onError:function(e){return o.push(e)},onEnd:function(e){return i.push(e)},isPending:t,error:n,data:r,promise:(0,p.computed)((function(){return u.value}))}}function A(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function X(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,u,a=[],s=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);s=!0);}catch(e){c=!0,o=e}finally{try{if(!s&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(c)throw o}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return T(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?T(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function T(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function H(e){return H="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},H(e)}function L(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,N(n.key),n)}}function U(e,t,r){return(t=N(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function N(e){var t=function(e,t){if("object"!=H(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=H(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==H(t)?t:t+""}var D=function(){function e(t,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),U(this,"onError",(function(){})),U(this,"onStart",(function(){})),U(this,"onAbort",(function(){})),U(this,"onProgress",(function(){})),U(this,"onEnd",(function(){})),U(this,"token",null),U(this,"url",""),U(this,"params",{}),U(this,"sendAs","json"),U(this,"timeout",1e4),U(this,"port",80),U(this,"responseType","text"),U(this,"isPending",!1),U(this,"_eventsReady",void 0),U(this,"_oXHR",void 0),U(this,"_onEnd",(function(){})),U(this,"_onError",(function(){})),U(this,"_deferred",void 0),U(this,"_isXhrResolved",void 0),U(this,"_isXhrRejected",void 0),U(this,"_eventReady",void 0),this._eventsReady=!1,this._constructor(t||{},r)}return t=e,r=[{key:"_getUrl",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.onBeforeSendList.reduce((function(e,t){return t(e||{})}),t);return e.stringifyUrl(this.url,r)}},{key:"removeEvents",value:function(){var e=this,t=function(){e._oXHR.removeEventListener("load",e._onEnd,!1),e._oXHR.removeEventListener("error",e._onError,!1),e._oXHR.removeEventListener("timeout",e._onError,!1),e._oXHR.removeEventListener("loadstart",e.onStart,!1),e._oXHR.removeEventListener("abort",e.onAbort,!1),e._oXHR.upload.removeEventListener("progress",e.onProgress,!1),e._oXHR.removeEventListener("progress",e.onProgress,!1)};this._deferred.promise.then(t,t)}},{key:"post",value:function(e){return this._constructor(e),this._oXHR.open("POST",this._getUrl(),!0),this._send(),this._deferred.promise}},{key:"put",value:function(e){return this._constructor(e),this._oXHR.open("PUT",this._getUrl(),!0),this._send(),this._deferred.promise}},{key:"get",value:function(e){this._constructor(e||{}),this._oXHR.open("GET",this._getUrl("multipart"===this.sendAs?{}:this.params),!0),this._send();var t=this._deferred.promise;return t.abortXhr=this.abort.bind(this),t}},{key:"delete",value:function(e){return this._constructor(e),this._oXHR.open("DELETE",this._getUrl(this.params),!0),this._send(),this._deferred.promise}},{key:"abort",value:function(){return this._isXhrResolved&&!this._isXhrRejected||(this._oXHR.abort(null,this),this._isXhrRejected=!0,this._deferred.reject({message:"Xhr aborted: ".concat(this.url),name:"HTTP-ABORTED"})),this._deferred.promise}},{key:"resolve",value:function(e){return this._deferred.resolve(e),this._deferred.promise}},{key:"reject",value:function(e){return this._deferred.reject(e),this._deferred.promise}},{key:"_setEvents",value:function(e){this._eventsReady||(this._eventReady=!0,e.addEventListener("load",this._onEnd,!1),e.addEventListener("error",this._onError,!1),e.addEventListener("timeout",this._onError,!1),e.addEventListener("loadstart",this.onStart,!1),e.addEventListener("abort",this.onAbort,!1),e.upload.addEventListener("progress",this.onProgress,!1),e.addEventListener("progress",this.onProgress,!1))}},{key:"_send",value:function(){var t;this.isPending=!0,"multipart"===this.sendAs?t=e.getFormData(this.params):"json"===this.sendAs&&(this._oXHR.setRequestHeader("content-type","application/json; charset=utf-8"),t=JSON.stringify(this.params)),this.token&&this._oXHR.setRequestHeader("Authorization","Bearer ".concat(this.token)),this._oXHR.send(t,this)}},{key:"_constructor",value:function(t,r){var n=this;t&&"object"===H(t)?(this.sendAs=t.sendAs||this.sendAs,this.url=t.url||this.url,this.port=t.port||this.port,this.params=t.params||this.params,this.timeout=t.timeout||this.timeout,this.responseType=t.responseType||this.responseType,this.onProgress=(t.onProgress||this.onProgress).bind(this),this.onStart=(t.onStart||this.onStart).bind(this),this.onAbort=(t.onAbort||this.onAbort).bind(this),this.onEnd=(t.onEnd||this.onEnd).bind(this),this.onError=(t.onError||this.onError).bind(this),this.token=t.token||this.token):t&&"string"==typeof t&&(this.url=t,this.params=r||this.params),80!==this.port&&(this.url="".concat(window.location.protocol,"//").concat(window.location.hostname,":").concat(this.port).concat(this.url)),this._deferred=new h,this._deferred.promise.finally((function(){n.isPending=!1})),this._oXHR=new XMLHttpRequest,this._oXHR.timeout=this.timeout,this._oXHR.responseType=this.responseType,this._isXhrResolved=!1,this._isXhrRejected=!1;var o=e.injectParamsInUrl(this.url,this.params),i=o.url,u=o.params;this.url=i,this.params=u,this._onError=function(e){n.onError(e),n.removeEvents(),n._deferred.reject(e)},this._onEnd=function(t){var r=e.parseResult(n._oXHR);return n._oXHR.status>=400?(n._isXhrRejected=!0,n._onError(r),n._deferred.reject(r)):(n.onEnd(r,t),n._isXhrResolved=!0,n.removeEvents(),n.resolve(r))},this._setEvents(this._oXHR)}}],n=[{key:"parseResult",value:function(e){var t=e.response;try{var r=e.getResponseHeader("Content-Type");r&&r.toLowerCase().indexOf("json")>-1&&(t=JSON.parse(e.response))}catch(r){t=e.response}return t}},{key:"extractQueryParams",value:function(e){var t={},r=e.search(/#/);r>-1&&(e=e.substring(0,r));var n=e.indexOf("?"),o=(!0).toString(),i=(!1).toString();return n>-1&&e.split("?")[1].split("&").reduce((function(e,t){var r=X(t.split("="),2),n=r[0],u=r[1],a=X((void 0===u?"":u).match(/^(?:"?([^"]+)"?)$/)||[],2)[1];if(a===o||a===i)e[n]=a===o;else{var s=Number(a);e[n]=""===a||Number.isNaN(s)?a:s}return e}),t),t}},{key:"onBeforeSend",value:function(t){e.onBeforeSendList.push(t)}},{key:"new",value:function(t){return new e(t)}},{key:"stringifyUrl",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.injectParamsInUrl(t,r);t=n.url,r=n.params;var o=t.indexOf("?")>-1?"&":"?",i="";return r&&!Array.isArray(r)&&"object"===H(r)?Object.getOwnPropertyNames(r).filter((function(e){return void 0!==r[e]})).forEach((function(e){i+="".concat(o).concat(e,"=").concat(encodeURIComponent(JSON.stringify(r[e]))),o="&"})):r&&(i=o+encodeURIComponent(JSON.stringify(r))),(t=t.replace(/\/:[^/]*/gi,""))+i}},{key:"getFormData",value:function(e){var t,r=new FormData;return Object.keys(e).forEach((function(n){if(e[n]instanceof FileList)for(var o=0;o<e[n].length;o+=1)r.append(n,e[n][o]);else e[n]instanceof File?r.append(n,e[n]):("object"!==H(t=e[n])&&!Array.isArray(t)||null===t||(t=JSON.stringify(t)),r.append(n,t))})),r}},{key:"_stringifyForPathParam",value:function(e,t,r){var n=r[t];switch(H(r[t])){case"boolean":case"string":case"bigint":case"number":n=String(n);break;default:n=null===n?"null":encodeURIComponent(JSON.stringify(n))}return e.replace(":".concat(t),n)}},{key:"injectParamsInUrl",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Array.isArray(r)||0===Object.keys(r).length)return{url:t,params:r};var n=decodeURIComponent(t),o=e.extractQueryParams(n),i=n.search(/\?|#/);i>-1&&(n=n.substring(0,i));var u=Object.getOwnPropertyNames(r).reduce((function(e,t){return e[t]=r[t],e}),function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?A(Object(r),!0).forEach((function(t){U(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):A(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},o));(n.match(/:[a-z0-9]+/gi)||[]).forEach((function(t){t=t.substring(1),void 0!==u[t]&&(n=e._stringifyForPathParam(n,t,u),delete u[t])})),Object.keys(u).forEach((function(e){void 0!==o[e]&&(o[e]=u[e],delete u[e])}));var a=Object.keys(o);if(a.length){var s="?";a.forEach((function(e){if(!0===o[e]||!1===o[e])n+="".concat(s).concat(e,"=").concat(o[e]);else if(null===o[e])n+="".concat(s).concat(e,"=").concat(o[e]);else{var t=Number(o[e]),r=Number.isNaN(t)?encodeURIComponent('"'.concat(o[e],'"')):t;n+="".concat(s).concat(e,"=").concat(r)}s="&"}))}return{url:n,params:u}}}],r&&L(t.prototype,r),n&&L(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,n}();function I(e){return I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},I(e)}function C(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function x(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?C(Object(r),!0).forEach((function(t){B(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):C(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function B(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=I(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=I(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==I(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}U(D,"onBeforeSendList",[]);var F=function(){},J=function(e){return(0,p.unref)(e)};function z(e){var t=e||{onError:function(){},onStart:function(){},onEnd:function(){},context:null,legacy:!1,token:null},r=t.onError,n=t.onStart,o=t.onEnd,u=t.context,a=t.legacy,s=t.token,c=void 0===s?null:s,l=(0,p.ref)([]),f=[],v=function(e,t,r){var n,o=(0,p.computed)((function(){var e={},n=(0,p.unref)(t||{});return r||(r=n.params||{}),e.params=(0,p.unref)(r),c&&(e.token=J(c)),e.url=(0,p.unref)(n.url),e})),i=new D,u=(0,p.unref)(o.value.params)||{};switch(e){case"post":default:n=i.post.bind(i);break;case"put":n=i.put.bind(i);break;case"delete":n=i.delete.bind(i)}return x(x({},R((function(){return n(x(x({},o.value),{},{params:u}))}))),{},{xhr:i})};return a||(0,p.onBeforeUnmount)((function(){l.value.forEach((function(e){e.isPending&&e.abort()})),f.forEach((function(e){return e()}))})),{get:function(e,t,a){var s=new D,v=(r||F).bind(u),d=(n||F).bind(u),h=(o||F).bind(u),y=[v],m=[d],g=[h],w=(0,p.ref)(null);l.value.push(s);var E=(0,p.ref)(),_=(0,p.ref)(),j="",S=0,P=(0,p.computed)((function(){var r,n={},o=(0,p.unref)(e);"string"==typeof o?r=o:(r=(0,p.unref)(o.url),t||(t=o.params||{}),S=o.cacheDuration,void 0!==o.enabled&&(n.enabled=o.enabled),void 0===n.enabled&&(n.enabled=a),n.params=(0,p.unref)(t),n.cacheDuration=S),c&&(n.token=J(c));var i=(0,p.unref)(n.params||t||{});return"function"==typeof i&&(i=i()),n.params=x(x({},i),(0,p.isRef)(t)?t.value||{}:t),j="function"==typeof r?r(n.params):(0,p.unref)(r),n.url=j,n})),R=function(){var e=void 0!==P.value.enabled?P.value.enabled:a;return void 0===e||((0,p.isRef)(e)?(0,p.unref)(e):"function"==typeof e?e():!0===e)},k=(0,p.ref)(),A=function(){if(R()){E.value&&s.abort();var e="object"===I(P.value.params)?P.value.params:{};m.forEach((function(t){return t(e,s)})),E.value=!0,w.value=null;var t=decodeURIComponent(D.stringifyUrl(String(j),e));k.value=i({id:t,xhr:s.get.bind(s,P.value),duration:S}),k.value.catch((function(e){y.forEach((function(t){return t(e,s)})),w.value=e})),k.value.then((function(e){_.value=e})),k.value.finally((function(){var t;(t=l.value.indexOf(s))>-1&&l.value.splice(t,1),E.value=!1,g.forEach((function(t){return t(_.value,e,s)}))}))}};return f.push((0,p.watch)((function(){return P.value}),A,{immediate:R(),deep:!0})),f.push((0,p.watch)((function(){return w.value}),(function(e){if(e)throw e}))),{isPending:(0,p.computed)((function(){return E.value})),data:(0,p.computed)({get:function(){return _.value},set:function(e){e instanceof O&&e.uuid===b||console.warn('"useXhr" update a readonly field is not allowed'),_.value=e}}),onError:function(e){return y.push(e)},onStart:function(e){return m.push(e)},onEnd:function(e){return g.push(e)},error:w,abort:function(){var e;return null===(e=k.value)||void 0===e?void 0:e.abortXhr()},promise:(0,p.computed)((function(){return k.value||new Promise((function(){}))})),reload:A,xhr:s}},post:function(e,t){return v("post",e,t)},put:function(e,t){return v("put",e,t)},delete:function(e,t){return v("delete",e,t)}}}function M(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:400,n=(0,p.ref)(!1),o=0;return(0,p.watch)((function(){return e.value}),(function(e){if(e&&(o=Date.now(),n.value=e),!1===e&&o>0){var i=Date.now()-o;clearTimeout(t),i>r?n.value=e:t=setTimeout((function(){n.value=e}),r-i)}}),{immediate:!0}),(0,p.onBeforeUnmount)((function(){clearTimeout(t)})),(0,p.computed)((function(){return n.value}))}var Y=r.cY,q=r.TF,$=r.PP,Q=r.LH,G=r.Ej,V=r.IL,K=r.Yb,W=r.n_,Z=r.bz,ee=r.p6,te=r.cU;export{Y as Deferred,q as Xhr,$ as cache,Q as cacheIds,G as cacheSize,V as clearCache,K as useAsync,W as useMutation,Z as useResult,ee as useSpinner,te as useXhr};
import type { ComputedRef, Ref } from 'vue';
import type { TypeAllowed, UnwrappedPromiseType } from './index';
import type { TypeAllowed, UnwrappedPromiseType, RequiredParams } from './index';
type OnErrorCb<T> = (e: null | Error, params: T) => unknown;
type OnStartCb<T> = (params: T) => unknown;
type OnEndCb<T, Z> = (res: T, params: Z) => unknown;
type Params<Z, A extends unknown[]> = (() => (Z | [...A])) | ComputedRef<Z | [...A]> | Ref<Z | [...A]> | Z | [
...A
];
declare const useAsync: <T, Z extends TypeAllowed, A extends TypeAllowed[]>(func: ((...args: A) => Promise<T>) | ((args: Z) => Promise<T>), params?: Params<Z, A>, enabled?: Ref<boolean> | (() => boolean)) => {
declare const useAsync: <T, Z extends TypeAllowed, A extends TypeAllowed[]>(func: ((...args: A) => Promise<T>) | ((args: Z) => Promise<T>), params?: RequiredParams<Z, A>, enabled?: Ref<boolean> | (() => boolean)) => {
isPending: Ref<undefined | boolean>;

@@ -14,7 +11,7 @@ data: ComputedRef<undefined | null | UnwrappedPromiseType<typeof func>>;

reload: () => unknown;
onError: (cb: OnErrorCb<Params<Z, A>>) => unknown;
onStart: (cb: OnStartCb<Params<Z, A>>) => unknown;
onEnd: (cb: OnEndCb<UnwrappedPromiseType<typeof func>, Params<Z, A>>) => unknown;
onError: (cb: OnErrorCb<RequiredParams<Z, A>>) => unknown;
onStart: (cb: OnStartCb<RequiredParams<Z, A>>) => unknown;
onEnd: (cb: OnEndCb<UnwrappedPromiseType<typeof func>, RequiredParams<Z, A>>) => unknown;
promise: ComputedRef<null | ReturnType<typeof func>>;
};
export default useAsync;
import type { ComputedRef, Ref } from 'vue';
import type { $UpdateConfigArgs, GetConfig, GetReturn, TypeAllowed } from './index';
import type { $UpdateConfigArgs, GetConfig, GetReturn, RequiredParams, TypeAllowed } from './index';
import Xhr from './Xhr';

@@ -9,7 +9,6 @@ type Enabled = undefined | null | (() => boolean) | Ref<boolean> | ComputedRef<boolean> | boolean;

type OnEndCb<T, Z> = (res: T, params: Z, xhr: Xhr<T>) => unknown;
type Params<Z> = (() => Z) | ComputedRef<Z> | Ref<Z> | Z;
declare type UseXhr<T, Z extends TypeAllowed> = Partial<{
declare type UseXhr<T, Z extends TypeAllowed, A extends TypeAllowed[]> = Partial<{
onError: OnErrorCb<T>;
onStart: OnStartCb<T, Params<Z>>;
onEnd: OnEndCb<T, Params<Z>>;
onStart: OnStartCb<T, RequiredParams<Z, A>>;
onEnd: OnEndCb<T, RequiredParams<Z, A>>;
onProgress: (e: ProgressEvent) => any;

@@ -21,5 +20,5 @@ onAbort: (e: ProgressEvent) => any;

}>;
export default function <T, Z extends TypeAllowed>(args?: UseXhr<T, Z>): {
get: <TT = T, ZZ = Z>(parametersObj: GetConfig<ZZ>, params?: Params<ZZ>, enabled?: Enabled) => GetReturn<TT>;
post: <TT = T, ZZ = Z>(xhrConfig?: $UpdateConfigArgs, params?: Params<ZZ>) => {
export default function <T, Z extends TypeAllowed, A extends TypeAllowed[]>(args?: UseXhr<T, Z, A>): {
get: <TT = T, ZZ extends TypeAllowed = Z, AA extends TypeAllowed[] = A>(parametersObj: GetConfig<ZZ>, params?: RequiredParams<ZZ, AA>, enabled?: Enabled) => GetReturn<TT>;
post: <TT = T, ZZ extends TypeAllowed = Z, AA extends TypeAllowed[] = A>(xhrConfig?: $UpdateConfigArgs, params?: RequiredParams<ZZ, AA>) => {
xhr: Xhr<TT>;

@@ -30,8 +29,8 @@ isPending: Ref<undefined | boolean>;

reload: () => unknown;
onError: (cb: (e: null | Error, params: [] | TypeAllowed | ComputedRef<[] | TypeAllowed> | Ref<[] | TypeAllowed> | (() => [] | TypeAllowed)) => unknown) => unknown;
onStart: (cb: (params: [] | TypeAllowed | ComputedRef<[] | TypeAllowed> | Ref<[] | TypeAllowed> | (() => [] | TypeAllowed)) => unknown) => unknown;
onEnd: (cb: (res: TT, params: [] | TypeAllowed | ComputedRef<[] | TypeAllowed> | Ref<[] | TypeAllowed> | (() => [] | TypeAllowed)) => unknown) => unknown;
onError: (cb: (e: null | Error, params: RequiredParams<TypeAllowed, []>) => unknown) => unknown;
onStart: (cb: (params: RequiredParams<TypeAllowed, []>) => unknown) => unknown;
onEnd: (cb: (res: TT, params: RequiredParams<TypeAllowed, []>) => unknown) => unknown;
promise: ComputedRef<Promise<TT> | null>;
};
put: <TT = T, ZZ = Z>(xhrConfig?: $UpdateConfigArgs, params?: Params<ZZ>) => {
put: <TT = T, ZZ extends TypeAllowed = Z, AA extends TypeAllowed[] = A>(xhrConfig?: $UpdateConfigArgs, params?: RequiredParams<ZZ, AA>) => {
xhr: Xhr<TT>;

@@ -42,8 +41,8 @@ isPending: Ref<undefined | boolean>;

reload: () => unknown;
onError: (cb: (e: null | Error, params: [] | TypeAllowed | ComputedRef<[] | TypeAllowed> | Ref<[] | TypeAllowed> | (() => [] | TypeAllowed)) => unknown) => unknown;
onStart: (cb: (params: [] | TypeAllowed | ComputedRef<[] | TypeAllowed> | Ref<[] | TypeAllowed> | (() => [] | TypeAllowed)) => unknown) => unknown;
onEnd: (cb: (res: TT, params: [] | TypeAllowed | ComputedRef<[] | TypeAllowed> | Ref<[] | TypeAllowed> | (() => [] | TypeAllowed)) => unknown) => unknown;
onError: (cb: (e: null | Error, params: RequiredParams<TypeAllowed, []>) => unknown) => unknown;
onStart: (cb: (params: RequiredParams<TypeAllowed, []>) => unknown) => unknown;
onEnd: (cb: (res: TT, params: RequiredParams<TypeAllowed, []>) => unknown) => unknown;
promise: ComputedRef<Promise<TT> | null>;
};
delete: <TT = T, ZZ = Z>(xhrConfig?: $UpdateConfigArgs, params?: Params<ZZ>) => {
delete: <TT = T, ZZ extends TypeAllowed = Z, AA extends TypeAllowed[] = A>(xhrConfig?: $UpdateConfigArgs, params?: RequiredParams<ZZ, AA>) => {
xhr: Xhr<TT>;

@@ -54,5 +53,5 @@ isPending: Ref<undefined | boolean>;

reload: () => unknown;
onError: (cb: (e: null | Error, params: [] | TypeAllowed | ComputedRef<[] | TypeAllowed> | Ref<[] | TypeAllowed> | (() => [] | TypeAllowed)) => unknown) => unknown;
onStart: (cb: (params: [] | TypeAllowed | ComputedRef<[] | TypeAllowed> | Ref<[] | TypeAllowed> | (() => [] | TypeAllowed)) => unknown) => unknown;
onEnd: (cb: (res: TT, params: [] | TypeAllowed | ComputedRef<[] | TypeAllowed> | Ref<[] | TypeAllowed> | (() => [] | TypeAllowed)) => unknown) => unknown;
onError: (cb: (e: null | Error, params: RequiredParams<TypeAllowed, []>) => unknown) => unknown;
onStart: (cb: (params: RequiredParams<TypeAllowed, []>) => unknown) => unknown;
onEnd: (cb: (res: TT, params: RequiredParams<TypeAllowed, []>) => unknown) => unknown;
promise: ComputedRef<Promise<TT> | null>;

@@ -59,0 +58,0 @@ };

{
"name": "vue-use-async",
"version": "1.9.0-beta.3",
"version": "1.9.0-beta.4",
"description": "Xhr and async helpers",

@@ -5,0 +5,0 @@ "repository": {