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

opossum

Package Overview
Dependencies
Maintainers
9
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opossum - npm Package Compare versions

Comparing version 8.1.4 to 8.2.0

2

dist/opossum.min.js

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.circuitBreaker=t():e.circuitBreaker=t()}(self,(()=>{return e={187:e=>{"use strict";var t,n="object"==typeof Reflect?Reflect:null,r=n&&"function"==typeof n.apply?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};t=n&&"function"==typeof n.ownKeys?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var o=Number.isNaN||function(e){return e!=e};function i(){i.init.call(this)}e.exports=i,e.exports.once=function(e,t){return new Promise((function(n,r){function o(n){e.removeListener(t,i),r(n)}function i(){"function"==typeof e.removeListener&&e.removeListener("error",o),n([].slice.call(arguments))}m(e,t,i,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&m(e,"error",t,{once:!0})}(e,o)}))},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var s=10;function u(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function c(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function a(e,t,n,r){var o,i,s,a;if(u(n),void 0===(i=e._events)?(i=e._events=Object.create(null),e._eventsCount=0):(void 0!==i.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),i=e._events),s=i[t]),void 0===s)s=i[t]=n,++e._eventsCount;else if("function"==typeof s?s=i[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),(o=c(e))>0&&s.length>o&&!s.warned){s.warned=!0;var l=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=e,l.type=t,l.count=s.length,a=l,console&&console.warn&&console.warn(a)}return e}function l(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function f(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},o=l.bind(r);return o.listener=n,r.wrapFn=o,o}function p(e,t,n){var r=e._events;if(void 0===r)return[];var o=r[t];return void 0===o?[]:"function"==typeof o?n?[o.listener||o]:[o]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(o):y(o,o.length)}function h(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function y(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function m(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function o(i){r.once&&e.removeEventListener(t,o),n(i)}))}}Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return s},set:function(e){if("number"!=typeof e||e<0||o(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");s=e}}),i.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},i.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||o(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},i.prototype.getMaxListeners=function(){return c(this)},i.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var o="error"===e,i=this._events;if(void 0!==i)o=o&&void 0===i.error;else if(!o)return!1;if(o){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var u=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw u.context=s,u}var c=i[e];if(void 0===c)return!1;if("function"==typeof c)r(c,this,t);else{var a=c.length,l=y(c,a);for(n=0;n<a;++n)r(l[n],this,t)}return!0},i.prototype.addListener=function(e,t){return a(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return a(this,e,t,!0)},i.prototype.once=function(e,t){return u(t),this.on(e,f(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){return u(t),this.prependListener(e,f(this,e,t)),this},i.prototype.removeListener=function(e,t){var n,r,o,i,s;if(u(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(o=-1,i=n.length-1;i>=0;i--)if(n[i]===t||n[i].listener===t){s=n[i].listener,o=i;break}if(o<0)return this;0===o?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,o),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,s||t)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var o,i=Object.keys(n);for(r=0;r<i.length;++r)"removeListener"!==(o=i[r])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},i.prototype.listeners=function(e){return p(this,e,!0)},i.prototype.rawListeners=function(e){return p(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):h.call(e,t)},i.prototype.listenerCount=h,i.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},524:(e,t,n)=>{"use strict";e.exports=n(269)},235:(e,t)=>{function n(e){return n="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},n(e)}function r(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,(void 0,i=function(e,t){if("object"!==n(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,"string");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(o.key),"symbol"===n(i)?i:String(i)),o)}var i}var o=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.cache=new Map}var t,n;return t=e,(n=[{key:"get",value:function(e){var t=this.cache.get(e);if(t){if(t.expiresAt>Date.now()||0===t.expiresAt)return t.value;this.cache.delete(e)}}},{key:"set",value:function(e,t,n){this.cache.set(e,{expiresAt:n,value:t})}},{key:"flush",value:function(){this.cache.clear()}}])&&r(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();e.exports=o},269:(e,t,n)=>{"use strict";function r(e){return function(e){if(Array.isArray(e))return o(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return o(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}(e)||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.")}()}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}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 s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(void 0,o=function(e,t){if("object"!==i(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,"string");if("object"!==i(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(r.key),"symbol"===i(o)?o:String(o)),r)}var o}function u(e,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},u(e,t)}function c(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}var l=n(187),f=n(741),p=n(384),h=n(235),y=Symbol("state"),m=Symbol("open"),v=Symbol("closed"),b=Symbol("half-open"),d=Symbol("pending-close"),w=Symbol("shutdown"),g=Symbol("fallback"),O=Symbol("status"),T=Symbol("name"),k=Symbol("group"),S=Symbol("Enabled"),j=Symbol("warming-up"),x=Symbol("volume-threshold"),E=Symbol("our-error"),P=Symbol("reset-timeout"),L=Symbol("warmup-timeout"),C=Symbol("last-timer-at"),_=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&u(e,t)}(D,e);var t,n,r,o,l,_=(o=D,l=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=a(o);if(l){var n=a(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"===i(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return c(e)}(this,e)});function D(e){var t,n,r,o,s,u,a,l,E=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,D),(l=_.call(this)).options=E,l.options.timeout=null!==(t=E.timeout)&&void 0!==t?t:1e4,l.options.resetTimeout=null!==(n=E.resetTimeout)&&void 0!==n?n:3e4,l.options.errorThresholdPercentage=null!==(r=E.errorThresholdPercentage)&&void 0!==r?r:50,l.options.rollingCountTimeout=null!==(o=E.rollingCountTimeout)&&void 0!==o?o:1e4,l.options.rollingCountBuckets=null!==(s=E.rollingCountBuckets)&&void 0!==s?s:10,l.options.rollingPercentilesEnabled=!1!==E.rollingPercentilesEnabled,l.options.capacity=Number.isInteger(E.capacity)?E.capacity:Number.MAX_SAFE_INTEGER,l.options.errorFilter=E.errorFilter||function(e){return!1},l.options.cacheTTL=null!==(u=E.cacheTTL)&&void 0!==u?u:0,l.options.cacheGetKey=null!==(a=E.cacheGetKey)&&void 0!==a?a:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return JSON.stringify(t)},l.options.enableSnapshots=!1!==E.enableSnapshots,l.options.rotateBucketController=E.rotateBucketController,l.options.cache)if(void 0===l.options.cacheTransport)l.options.cacheTransport=new h;else if("object"!==i(l.options.cacheTransport)||!l.options.cacheTransport.get||!l.options.cacheTransport.set||!l.options.cacheTransport.flush)throw new TypeError("options.cacheTransport should be an object with `get`, `set` and `flush` methods");if(l.semaphore=new p(l.options.capacity),!e)throw new TypeError("No action provided. Cannot construct a CircuitBreaker without an invocable action.");if(E.abortController&&"function"!=typeof E.abortController.abort)throw new TypeError("AbortController does not contain `abort()` method");if(l[x]=Number.isInteger(E.volumeThreshold)?E.volumeThreshold:0,l[j]=!0===E.allowWarmUp,l.options.status?l.options.status instanceof f?l[O]=l.options.status:l[O]=new f({stats:l.options.status}):l[O]=new f(l.options),l[y]=v,E.state?(l[S]=!1!==E.state.enabled,l[j]=E.state.warmUp||l[j],l[v]=!1!==E.state.closed,l[b]=l[d]=E.state.halfOpen||!1,l[m]=!l[v]&&!l[b],l[w]=E.state.shutdown||!1):(l[d]=!1,l[S]=!1!==E.enabled),l[g]=null,l[T]=E.name||e.name||M(),l[k]=E.group||l[T],l[j]){var B=l[L]=setTimeout((function(e){return l[j]=!1}),l.options.rollingCountTimeout);"function"==typeof B.unref&&B.unref()}l.action="function"!=typeof e?function(t){return Promise.resolve(e)}:e,E.maxFailures&&console.error("options.maxFailures is deprecated. Please use options.errorThresholdPercentage");var R,A=function(e){return function(t,n){return l[O].increment(e,n)}};function N(e){e[y]=b,e[d]=!0,e.emit("halfOpen",e.options.resetTimeout)}return l.on("success",A("successes")),l.on("failure",A("failures")),l.on("fallback",A("fallbacks")),l.on("timeout",A("timeouts")),l.on("fire",A("fires")),l.on("reject",A("rejects")),l.on("cacheHit",A("cacheHits")),l.on("cacheMiss",A("cacheMisses")),l.on("open",(function(e){return l[O].open()})),l.on("close",(function(e){return l[O].close()})),l.on("semaphoreLocked",A("semaphoreRejections")),l.on("open",((R=c(l))[C]=Date.now(),function(e){var t=R[P]=setTimeout((function(){N(R)}),R.options.resetTimeout);"function"==typeof t.unref&&t.unref()})),l.on("success",(function(e){l.halfOpen&&l.close()})),l[w]?(l[y]=w,l.shutdown()):l[v]?l.close():l[m]?void 0!==l.options.state.lastTimerAt&&Date.now()-l.options.state.lastTimerAt>l.options.resetTimeout?N(c(l)):l.open():l[b]&&(l[y]=b),l}return t=D,n=[{key:"close",value:function(){this[y]!==v&&(this[P]&&clearTimeout(this[P]),this[y]=v,this[d]=!1,this.emit("close"))}},{key:"open",value:function(){this[y]!==m&&(this[y]=m,this[d]=!1,this.emit("open"))}},{key:"shutdown",value:function(){this.emit("shutdown"),this.disable(),this.removeAllListeners(),this[P]&&clearTimeout(this[P]),this[L]&&clearTimeout(this[L]),this.status.shutdown(),this[y]=w,this.clearCache()}},{key:"isShutdown",get:function(){return this[y]===w}},{key:"name",get:function(){return this[T]}},{key:"group",get:function(){return this[k]}},{key:"pendingClose",get:function(){return this[d]}},{key:"closed",get:function(){return this[y]===v}},{key:"opened",get:function(){return this[y]===m}},{key:"halfOpen",get:function(){return this[y]===b}},{key:"status",get:function(){return this[O]}},{key:"stats",get:function(){return this[O].stats}},{key:"toJSON",value:function(){return{state:{name:this.name,enabled:this.enabled,closed:this.closed,open:this.opened,halfOpen:this.halfOpen,warmUp:this.warmUp,shutdown:this.isShutdown,lastTimerAt:this[C]},status:this.status.stats}}},{key:"enabled",get:function(){return this[S]}},{key:"warmUp",get:function(){return this[j]}},{key:"volumeThreshold",get:function(){return this[x]}},{key:"fallback",value:function(e){var t=e;return e instanceof D&&(t=function(){return e.fire.apply(e,arguments)}),this[g]=t,this}},{key:"fire",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return this.call.apply(this,[this.action].concat(t))}},{key:"call",value:function(e){var t=this;if(this.isShutdown){var n=A("The circuit has been shutdown.","ESHUTDOWN");return Promise.reject(n)}for(var r=arguments.length,o=new Array(r>1?r-1:0),i=1;i<r;i++)o[i-1]=arguments[i];var s,u=o.slice(),c="";if(this.emit("fire",u),this.options.cache){c=this.options.cacheGetKey.apply(this,o);var a=this.options.cacheTransport.get(c);if(a)return this.emit("cacheHit"),a;this.emit("cacheMiss")}if(!this[S]){var l=this.action.apply(e,u);return"function"==typeof l.then?l:Promise.resolve(l)}if(!this.closed&&!this.pendingClose){var f=A("Breaker is open","EOPENBREAKER");return this.emit("reject",f),R(this,f,u)||Promise.reject(f)}this[d]=!1;var p=!1;return new Promise((function(n,r){var o=Date.now();if(t.semaphore.test()){t.options.timeout&&(s=setTimeout((function(){p=!0;var e=A("Timed out after ".concat(t.options.timeout,"ms"),"ETIMEDOUT"),i=Date.now()-o;t.semaphore.release(),t.emit("timeout",e,i,u),B(e,t,s,u,i,n,r),t.options.abortController&&t.options.abortController.abort()}),t.options.timeout));try{var i=t.action.apply(e,u),a="function"==typeof i.then?i:Promise.resolve(i);a.then((function(e){p||(clearTimeout(s),t.emit("success",e,Date.now()-o),t.semaphore.release(),n(e),t.options.cache&&t.options.cacheTransport.set(c,a,t.options.cacheTTL>0?Date.now()+t.options.cacheTTL:0))})).catch((function(e){if(!p){t.semaphore.release();var i=Date.now()-o;B(e,t,s,u,i,n,r)}}))}catch(e){t.semaphore.release();var l=Date.now()-o;B(e,t,s,u,l,n,r)}}else{var f=Date.now()-o,h=A("Semaphore locked","ESEMLOCKED");t.emit("semaphoreLocked",h,f),B(h,t,s,u,f,n,r)}}))}},{key:"clearCache",value:function(){this.options.cache&&this.options.cacheTransport.flush()}},{key:"healthCheck",value:function(e,t){var n=this;if(t=t||5e3,"function"!=typeof e)throw new TypeError("Health check function must be a function");if(isNaN(t))throw new TypeError("Health check interval must be a number");var r=function(t){e.apply(n).catch((function(e){n.emit("healthCheckFailed",e),n.open()}))},o=setInterval(r,t);"function"==typeof o.unref&&o.unref(),r()}},{key:"enable",value:function(){this[S]=!0,this.status.startListeneningForRotateEvent()}},{key:"disable",value:function(){this[S]=!1,this.status.removeRotateBucketControllerListener()}}],r=[{key:"isOurError",value:function(e){return!!e[E]}},{key:"newStatus",value:function(e){return new f(e)}}],n&&s(t.prototype,n),r&&s(t,r),Object.defineProperty(t,"prototype",{writable:!1}),D}(l);function B(e,t,n,o,i,s,u){var c;if(clearTimeout(n),(c=t.options).errorFilter.apply(c,[e].concat(r(o))))t.emit("success",e,i);else{!function(e,t,n,r){if(e.emit("failure",t,r,n),!e.warmUp){var o=e.stats;o.fires<e.volumeThreshold&&!e.halfOpen||(o.failures/o.fires*100>e.options.errorThresholdPercentage||e.halfOpen)&&e.open()}}(t,e,o,i);var a=R(t,e,o);if(a)return s(a)}u(e)}function R(e,t,n){if(e[g])try{var o=e[g].apply(e[g],[].concat(r(n),[t]));return e.emit("fallback",o,t),o instanceof Promise?o:Promise.resolve(o)}catch(e){return Promise.reject(e)}}function A(e,t){var n=new Error(e);return n.code=t,n[E]=!0,n}var M=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))};e.exports=_},384:(e,t)=>{"use strict";e.exports=function(e){var t=[],n=e,r={take:o,release:i,test:function(){return!(n<1)&&o()&&!0}};return Object.defineProperty(r,"count",{get:function(e){return n},enumerable:!0}),r;function o(e){return n>0?(--n,Promise.resolve(i)):new Promise((function(r,o){t.push((function(e){--n,r(i)})),e&&setTimeout((function(n){t.shift();var r=new Error("Timed out after ".concat(e,"ms"));r.code="ETIMEDOUT",o(r)}),e)}))}function i(){n++,t.length>0&&t.shift()()}}},741:(e,t,n)=>{"use strict";function r(e){return r="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},r(e)}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){s(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function s(e,t,n){return(t=c(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,c(r.key),r)}}function c(e){var t=function(e,t){if("object"!==r(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,"string");if("object"!==r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"===r(t)?t:String(t)}function a(e,t){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},a(e,t)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}var f=Symbol("window"),p=Symbol("buckets"),h=Symbol("timeout"),y=Symbol("percentiles"),m=Symbol("bucket-interval"),v=Symbol("snapshot-interval"),b=Symbol("rotate-event-name"),d=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&a(e,t)}(d,e);var t,n,o,s,c=(o=d,s=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=l(o);if(s){var n=l(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function d(e){var t;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,d),(t=c.call(this))[p]=e.rollingCountBuckets||10,t[h]=e.rollingCountTimeout||1e4,t[f]=new Array(t[p]),t[y]=[0,.25,.5,.75,.9,.95,.99,.995,1],t[b]="rotate",t.rollingPercentilesEnabled=!1!==e.rollingPercentilesEnabled,t.enableSnapshots=!1!==e.enableSnapshots,t.rotateBucketController=e.rotateBucketController,t.rotateBucket=w(t[f]);for(var n=0;n<t[p];n++)t[f][n]=g();var r=Math.floor(t[h]/t[p]);return t.rotateBucketController?t.startListeneningForRotateEvent():(t[m]=setInterval(t.rotateBucket,r),"function"==typeof t[m].unref&&t[m].unref()),t.enableSnapshots&&(t[v]=setInterval((function(e){return t.emit("snapshot",t.stats)}),r),"function"==typeof t[v].unref&&t[v].unref()),e.stats&&(t[f][0]=i(i({},g()),e.stats)),t}return t=d,(n=[{key:"stats",get:function(){var e=this,t=this[f].reduce((function(t,n){return n?(Object.keys(t).forEach((function(e){"latencyTimes"!==e&&"percentiles"!==e&&(t[e]+=n[e]||0)})),e.rollingPercentilesEnabled&&n.latencyTimes&&(t.latencyTimes=t.latencyTimes.concat(n.latencyTimes)),t):t}),g());return this.rollingPercentilesEnabled?(t.latencyTimes.sort((function(e,t){return e-t})),t.latencyTimes.length?t.latencyMean=t.latencyTimes.reduce((function(e,t){return e+t}),0)/t.latencyTimes.length:t.latencyMean=0,this[y].forEach((function(e){t.percentiles[e]=function(e,t){return 0===e?t[0]||0:t[Math.ceil(e*t.length)-1]||0}(e,t.latencyTimes)}))):(t.latencyMean=-1,this[y].forEach((function(e){t.percentiles[e]=-1}))),t}},{key:"window",get:function(){return this[f].slice()}},{key:"increment",value:function(e,t){this[f][0][e]++,"successes"!==e&&"failures"!==e&&"timeouts"!==e||this[f][0].latencyTimes.push(t||0)}},{key:"open",value:function(){this[f][0].isCircuitBreakerOpen=!0}},{key:"close",value:function(){this[f][0].isCircuitBreakerOpen=!1}},{key:"shutdown",value:function(){this.removeAllListeners(),void 0===this.rotateBucketController?clearInterval(this[m]):this.removeRotateBucketControllerListener(),this.enableSnapshots&&clearInterval(this[v])}},{key:"removeRotateBucketControllerListener",value:function(){this.rotateBucketController&&this.rotateBucketController.removeListener(this[b],this.rotateBucket)}},{key:"startListeneningForRotateEvent",value:function(){this.rotateBucketController&&0===this.rotateBucketController.listenerCount(this[b],this.rotateBucket)&&this.rotateBucketController.on(this[b],this.rotateBucket)}}])&&u(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),d}(n(187).EventEmitter),w=function(e){return function(t){e.pop(),e.unshift(g())}},g=function(e){return{failures:0,fallbacks:0,successes:0,rejects:0,fires:0,timeouts:0,cacheHits:0,cacheMisses:0,semaphoreRejections:0,percentiles:{},latencyTimes:[]}};e.exports=d}},t={},function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}(524);var e,t}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.circuitBreaker=t():e.circuitBreaker=t()}(self,(()=>{return e={187:e=>{"use strict";var t,n="object"==typeof Reflect?Reflect:null,r=n&&"function"==typeof n.apply?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};t=n&&"function"==typeof n.ownKeys?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var o=Number.isNaN||function(e){return e!=e};function i(){i.init.call(this)}e.exports=i,e.exports.once=function(e,t){return new Promise((function(n,r){function o(n){e.removeListener(t,i),r(n)}function i(){"function"==typeof e.removeListener&&e.removeListener("error",o),n([].slice.call(arguments))}m(e,t,i,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&m(e,"error",t,{once:!0})}(e,o)}))},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var s=10;function c(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function a(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function u(e,t,n,r){var o,i,s,u;if(c(n),void 0===(i=e._events)?(i=e._events=Object.create(null),e._eventsCount=0):(void 0!==i.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),i=e._events),s=i[t]),void 0===s)s=i[t]=n,++e._eventsCount;else if("function"==typeof s?s=i[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),(o=a(e))>0&&s.length>o&&!s.warned){s.warned=!0;var l=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=e,l.type=t,l.count=s.length,u=l,console&&console.warn&&console.warn(u)}return e}function l(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function f(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},o=l.bind(r);return o.listener=n,r.wrapFn=o,o}function p(e,t,n){var r=e._events;if(void 0===r)return[];var o=r[t];return void 0===o?[]:"function"==typeof o?n?[o.listener||o]:[o]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(o):y(o,o.length)}function h(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function y(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function m(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function o(i){r.once&&e.removeEventListener(t,o),n(i)}))}}Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return s},set:function(e){if("number"!=typeof e||e<0||o(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");s=e}}),i.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},i.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||o(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},i.prototype.getMaxListeners=function(){return a(this)},i.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var o="error"===e,i=this._events;if(void 0!==i)o=o&&void 0===i.error;else if(!o)return!1;if(o){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var a=i[e];if(void 0===a)return!1;if("function"==typeof a)r(a,this,t);else{var u=a.length,l=y(a,u);for(n=0;n<u;++n)r(l[n],this,t)}return!0},i.prototype.addListener=function(e,t){return u(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return u(this,e,t,!0)},i.prototype.once=function(e,t){return c(t),this.on(e,f(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){return c(t),this.prependListener(e,f(this,e,t)),this},i.prototype.removeListener=function(e,t){var n,r,o,i,s;if(c(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(o=-1,i=n.length-1;i>=0;i--)if(n[i]===t||n[i].listener===t){s=n[i].listener,o=i;break}if(o<0)return this;0===o?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,o),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,s||t)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var o,i=Object.keys(n);for(r=0;r<i.length;++r)"removeListener"!==(o=i[r])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},i.prototype.listeners=function(e){return p(this,e,!0)},i.prototype.rawListeners=function(e){return p(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):h.call(e,t)},i.prototype.listenerCount=h,i.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},524:(e,t,n)=>{"use strict";e.exports=n(269)},235:(e,t)=>{function n(e){return n="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},n(e)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,o(r.key),r)}}function o(e){var t=function(e,t){if("object"!=n(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,"string");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==n(t)?t:t+""}var i=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.cache=new Map,this.maxEntries=null!=t?t:21}var t,n;return t=e,(n=[{key:"get",value:function(e){var t=this.cache.get(e);if(t){if(t.expiresAt>Date.now()||0===t.expiresAt)return t.value;this.cache.delete(e)}}},{key:"set",value:function(e,t,n){this.cache.size===this.maxEntries&&this.cache.delete(this.cache.keys().next().value),this.cache.set(e,{expiresAt:n,value:t})}},{key:"flush",value:function(){this.cache.clear()}}])&&r(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();e.exports=i},269:(e,t,n)=>{"use strict";function r(e){return function(e){if(Array.isArray(e))return o(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return o(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}(e)||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.")}()}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}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 s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,c(r.key),r)}}function c(e){var t=function(e,t){if("object"!=i(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,"string");if("object"!=i(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==i(t)?t:t+""}function a(e,t){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},a(e,t)}function u(e){var t=f();return function(){var n,r=p(e);if(t){var o=p(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return function(e,t){if(t&&("object"==i(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return l(e)}(this,n)}}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function f(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(f=function(){return!!e})()}function p(e){return p=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},p(e)}var h=n(187),y=n(741),m=n(384),v=n(235),b=Symbol("state"),d=Symbol("open"),w=Symbol("closed"),g=Symbol("half-open"),T=Symbol("pending-close"),O=Symbol("shutdown"),k=Symbol("fallback"),S=Symbol("status"),j=Symbol("name"),x=Symbol("group"),E=Symbol("Enabled"),C=Symbol("warming-up"),P=Symbol("volume-threshold"),L=Symbol("our-error"),_=Symbol("reset-timeout"),B=Symbol("warmup-timeout"),A=Symbol("last-timer-at"),M=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&a(e,t)}(c,e);var t,n,r,o=u(c);function c(e){var t,n,r,s,a,u,f,p,h,L=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,c),(h=o.call(this)).options=L,h.options.timeout=null!==(t=L.timeout)&&void 0!==t?t:1e4,h.options.resetTimeout=null!==(n=L.resetTimeout)&&void 0!==n?n:3e4,h.options.errorThresholdPercentage=null!==(r=L.errorThresholdPercentage)&&void 0!==r?r:50,h.options.rollingCountTimeout=null!==(s=L.rollingCountTimeout)&&void 0!==s?s:1e4,h.options.rollingCountBuckets=null!==(a=L.rollingCountBuckets)&&void 0!==a?a:10,h.options.rollingPercentilesEnabled=!1!==L.rollingPercentilesEnabled,h.options.capacity=Number.isInteger(L.capacity)?L.capacity:Number.MAX_SAFE_INTEGER,h.options.errorFilter=L.errorFilter||function(e){return!1},h.options.cacheTTL=null!==(u=L.cacheTTL)&&void 0!==u?u:0,h.options.cacheGetKey=null!==(f=L.cacheGetKey)&&void 0!==f?f:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return JSON.stringify(t)},h.options.enableSnapshots=!1!==L.enableSnapshots,h.options.rotateBucketController=L.rotateBucketController,h.options.coalesce=!!L.coalesce,h.options.coalesceTTL=null!==(p=L.coalesceTTL)&&void 0!==p?p:h.options.timeout,h.options.cache)if(void 0===h.options.cacheTransport)h.options.cacheTransport=new v(L.cacheSize);else if("object"!==i(h.options.cacheTransport)||!h.options.cacheTransport.get||!h.options.cacheTransport.set||!h.options.cacheTransport.flush)throw new TypeError("options.cacheTransport should be an object with `get`, `set` and `flush` methods");if(h.options.coalesce&&(h.options.coalesceCache=new v(L.coalesceSize)),h.semaphore=new m(h.options.capacity),!e)throw new TypeError("No action provided. Cannot construct a CircuitBreaker without an invocable action.");if(L.abortController&&"function"!=typeof L.abortController.abort)throw new TypeError("AbortController does not contain `abort()` method");if(h[P]=Number.isInteger(L.volumeThreshold)?L.volumeThreshold:0,h[C]=!0===L.allowWarmUp,h.options.status?h.options.status instanceof y?h[S]=h.options.status:h[S]=new y({stats:h.options.status}):h[S]=new y(h.options),h[b]=w,L.state?(h[E]=!1!==L.state.enabled,h[C]=L.state.warmUp||h[C],h[w]=!1!==L.state.closed,h[g]=h[T]=L.state.halfOpen||!1,h[d]=!h[w]&&!h[g],h[O]=L.state.shutdown||!1):(h[T]=!1,h[E]=!1!==L.enabled),h[k]=null,h[j]=L.name||e.name||F(),h[x]=L.group||h[j],h[C]){var M=h[B]=setTimeout((function(e){return h[C]=!1}),h.options.rollingCountTimeout);"function"==typeof M.unref&&M.unref()}h.action="function"!=typeof e?function(t){return Promise.resolve(e)}:e,L.maxFailures&&console.error("options.maxFailures is deprecated. Please use options.errorThresholdPercentage");var R,D=function(e){return function(t,n){return h[S].increment(e,n)}};function N(e){e[b]=g,e[T]=!0,e.emit("halfOpen",e.options.resetTimeout)}return h.on("success",D("successes")),h.on("failure",D("failures")),h.on("fallback",D("fallbacks")),h.on("timeout",D("timeouts")),h.on("fire",D("fires")),h.on("reject",D("rejects")),h.on("cacheHit",D("cacheHits")),h.on("cacheMiss",D("cacheMisses")),h.on("coalesceCacheHit",D("coalesceCacheHits")),h.on("coalesceCacheMiss",D("coalesceCacheMisses")),h.on("open",(function(e){return h[S].open()})),h.on("close",(function(e){return h[S].close()})),h.on("semaphoreLocked",D("semaphoreRejections")),h.on("open",((R=l(h))[A]=Date.now(),function(e){var t=R[_]=setTimeout((function(){N(R)}),R.options.resetTimeout);"function"==typeof t.unref&&t.unref()})),h.on("success",(function(e){h.halfOpen&&h.close()})),h[O]?(h[b]=O,h.shutdown()):h[w]?h.close():h[d]?void 0!==h.options.state.lastTimerAt&&Date.now()-h.options.state.lastTimerAt>h.options.resetTimeout?N(l(h)):h.open():h[g]&&(h[b]=g),h}return t=c,n=[{key:"close",value:function(){this[b]!==w&&(this[_]&&clearTimeout(this[_]),this[b]=w,this[T]=!1,this.emit("close"))}},{key:"open",value:function(){this[b]!==d&&(this[b]=d,this[T]=!1,this.emit("open"))}},{key:"shutdown",value:function(){this.emit("shutdown"),this.disable(),this.removeAllListeners(),this[_]&&clearTimeout(this[_]),this[B]&&clearTimeout(this[B]),this.status.shutdown(),this[b]=O,this.clearCache()}},{key:"isShutdown",get:function(){return this[b]===O}},{key:"name",get:function(){return this[j]}},{key:"group",get:function(){return this[x]}},{key:"pendingClose",get:function(){return this[T]}},{key:"closed",get:function(){return this[b]===w}},{key:"opened",get:function(){return this[b]===d}},{key:"halfOpen",get:function(){return this[b]===g}},{key:"status",get:function(){return this[S]}},{key:"stats",get:function(){return this[S].stats}},{key:"toJSON",value:function(){return{state:{name:this.name,enabled:this.enabled,closed:this.closed,open:this.opened,halfOpen:this.halfOpen,warmUp:this.warmUp,shutdown:this.isShutdown,lastTimerAt:this[A]},status:this.status.stats}}},{key:"enabled",get:function(){return this[E]}},{key:"warmUp",get:function(){return this[C]}},{key:"volumeThreshold",get:function(){return this[P]}},{key:"fallback",value:function(e){var t=e;return e instanceof c&&(t=function(){return e.fire.apply(e,arguments)}),this[k]=t,this}},{key:"fire",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return this.call.apply(this,[this.action].concat(t))}},{key:"call",value:function(e){var t=this;if(this.isShutdown){var n=N("The circuit has been shutdown.","ESHUTDOWN");return Promise.reject(n)}for(var r=arguments.length,o=new Array(r>1?r-1:0),i=1;i<r;i++)o[i-1]=arguments[i];var s=o.slice();if(!this[E]){var c=this.action.apply(e,s);return"function"==typeof c.then?c:Promise.resolve(c)}var a,u="";if(this.emit("fire",s),this.options.cache){u=this.options.cacheGetKey.apply(this,o);var l=this.options.cacheTransport.get(u);if(l)return this.emit("cacheHit"),l;this.emit("cacheMiss")}if(this.options.coalesce){var f=this.options.coalesceCache.get(u);if(f)return this.emit("coalesceCacheHit"),f;this.emit("coalesceCacheMiss")}if(!this.closed&&!this.pendingClose){var p=N("Breaker is open","EOPENBREAKER");return this.emit("reject",p),D(this,p,s)||Promise.reject(p)}this[T]=!1;var h=!1,y=new Promise((function(n,r){var o=Date.now();if(t.semaphore.test()){t.options.timeout&&(a=setTimeout((function(){h=!0;var e=N("Timed out after ".concat(t.options.timeout,"ms"),"ETIMEDOUT"),i=Date.now()-o;t.semaphore.release(),t.emit("timeout",e,i,s),R(e,t,a,s,i,n,r),t.options.abortController&&t.options.abortController.abort()}),t.options.timeout));try{var i=t.action.apply(e,s),c="function"==typeof i.then?i:Promise.resolve(i);c.then((function(e){h||(clearTimeout(a),t.emit("success",e,Date.now()-o),t.semaphore.release(),n(e),t.options.cache&&t.options.cacheTransport.set(u,c,t.options.cacheTTL>0?Date.now()+t.options.cacheTTL:0))})).catch((function(e){if(!h){t.semaphore.release();var i=Date.now()-o;R(e,t,a,s,i,n,r)}}))}catch(e){t.semaphore.release();var l=Date.now()-o;R(e,t,a,s,l,n,r)}}else{var f=Date.now()-o,p=N("Semaphore locked","ESEMLOCKED");t.emit("semaphoreLocked",p,f),R(p,t,a,s,f,n,r)}}));return this.options.coalesce&&this.options.coalesceCache.set(u,y,this.options.coalesceTTL>0?Date.now()+this.options.coalesceTTL:0),y}},{key:"clearCache",value:function(){this.options.cache&&this.options.cacheTransport.flush()}},{key:"healthCheck",value:function(e,t){var n=this;if(t=t||5e3,"function"!=typeof e)throw new TypeError("Health check function must be a function");if(isNaN(t))throw new TypeError("Health check interval must be a number");var r=function(t){e.apply(n).catch((function(e){n.emit("healthCheckFailed",e),n.open()}))},o=setInterval(r,t);"function"==typeof o.unref&&o.unref(),r()}},{key:"enable",value:function(){this[E]=!0,this.status.startListeneningForRotateEvent()}},{key:"disable",value:function(){this[E]=!1,this.status.removeRotateBucketControllerListener()}}],r=[{key:"isOurError",value:function(e){return!!e[L]}},{key:"newStatus",value:function(e){return new y(e)}}],n&&s(t.prototype,n),r&&s(t,r),Object.defineProperty(t,"prototype",{writable:!1}),c}(h);function R(e,t,n,o,i,s,c){var a;if(clearTimeout(n),(a=t.options).errorFilter.apply(a,[e].concat(r(o))))t.emit("success",e,i);else{!function(e,t,n,r){if(e.emit("failure",t,r,n),!e.warmUp){var o=e.stats;o.fires<e.volumeThreshold&&!e.halfOpen||(o.failures/o.fires*100>e.options.errorThresholdPercentage||e.halfOpen)&&e.open()}}(t,e,o,i);var u=D(t,e,o);if(u)return s(u)}c(e)}function D(e,t,n){if(e[k])try{var o=e[k].apply(e[k],[].concat(r(n),[t]));return e.emit("fallback",o,t),o instanceof Promise?o:Promise.resolve(o)}catch(e){return Promise.reject(e)}}function N(e,t){var n=new Error(e);return n.code=t,n[L]=!0,n}var F=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))};e.exports=M},384:(e,t)=>{"use strict";e.exports=function(e){var t=[],n=e,r={take:o,release:i,test:function(){return!(n<1)&&o()&&!0}};return Object.defineProperty(r,"count",{get:function(e){return n},enumerable:!0}),r;function o(e){return n>0?(--n,Promise.resolve(i)):new Promise((function(r,o){t.push((function(e){--n,r(i)})),e&&setTimeout((function(n){t.shift();var r=new Error("Timed out after ".concat(e,"ms"));r.code="ETIMEDOUT",o(r)}),e)}))}function i(){n++,t.length>0&&t.shift()()}}},741:(e,t,n)=>{"use strict";function r(e){return r="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},r(e)}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){s(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function s(e,t,n){return(t=a(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,a(r.key),r)}}function a(e){var t=function(e,t){if("object"!=r(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,"string");if("object"!=r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==r(t)?t:t+""}function u(e,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},u(e,t)}function l(e){var t=f();return function(){var n,o=p(e);if(t){var i=p(this).constructor;n=Reflect.construct(o,arguments,i)}else n=o.apply(this,arguments);return function(e,t){if(t&&("object"==r(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,n)}}function f(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(f=function(){return!!e})()}function p(e){return p=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},p(e)}var h=Symbol("window"),y=Symbol("buckets"),m=Symbol("timeout"),v=Symbol("percentiles"),b=Symbol("bucket-interval"),d=Symbol("snapshot-interval"),w=Symbol("rotate-event-name"),g=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&u(e,t)}(o,e);var t,n,r=l(o);function o(e){var t;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(t=r.call(this))[y]=e.rollingCountBuckets||10,t[m]=e.rollingCountTimeout||1e4,t[h]=new Array(t[y]),t[v]=[0,.25,.5,.75,.9,.95,.99,.995,1],t[w]="rotate",t.rollingPercentilesEnabled=!1!==e.rollingPercentilesEnabled,t.enableSnapshots=!1!==e.enableSnapshots,t.rotateBucketController=e.rotateBucketController,t.rotateBucket=T(t[h]);for(var n=0;n<t[y];n++)t[h][n]=O();var s=Math.floor(t[m]/t[y]);return t.rotateBucketController?t.startListeneningForRotateEvent():(t[b]=setInterval(t.rotateBucket,s),"function"==typeof t[b].unref&&t[b].unref()),t.enableSnapshots&&(t[d]=setInterval((function(e){return t.emit("snapshot",t.stats)}),s),"function"==typeof t[d].unref&&t[d].unref()),e.stats&&(t[h][0]=i(i({},O()),e.stats)),t}return t=o,(n=[{key:"stats",get:function(){var e=this,t=this[h].reduce((function(t,n){return n?(Object.keys(t).forEach((function(e){"latencyTimes"!==e&&"percentiles"!==e&&(t[e]+=n[e]||0)})),e.rollingPercentilesEnabled&&n.latencyTimes&&(t.latencyTimes=t.latencyTimes.concat(n.latencyTimes)),t):t}),O());return this.rollingPercentilesEnabled?(t.latencyTimes.sort((function(e,t){return e-t})),t.latencyTimes.length?t.latencyMean=t.latencyTimes.reduce((function(e,t){return e+t}),0)/t.latencyTimes.length:t.latencyMean=0,this[v].forEach((function(e){t.percentiles[e]=function(e,t){return 0===e?t[0]||0:t[Math.ceil(e*t.length)-1]||0}(e,t.latencyTimes)}))):(t.latencyMean=-1,this[v].forEach((function(e){t.percentiles[e]=-1}))),t}},{key:"window",get:function(){return this[h].slice()}},{key:"increment",value:function(e,t){this[h][0][e]++,"successes"!==e&&"failures"!==e&&"timeouts"!==e||this[h][0].latencyTimes.push(t||0)}},{key:"open",value:function(){this[h][0].isCircuitBreakerOpen=!0}},{key:"close",value:function(){this[h][0].isCircuitBreakerOpen=!1}},{key:"shutdown",value:function(){this.removeAllListeners(),void 0===this.rotateBucketController?clearInterval(this[b]):this.removeRotateBucketControllerListener(),this.enableSnapshots&&clearInterval(this[d])}},{key:"removeRotateBucketControllerListener",value:function(){this.rotateBucketController&&this.rotateBucketController.removeListener(this[w],this.rotateBucket)}},{key:"startListeneningForRotateEvent",value:function(){this.rotateBucketController&&0===this.rotateBucketController.listenerCount(this[w],this.rotateBucket)&&this.rotateBucketController.on(this[w],this.rotateBucket)}}])&&c(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),o}(n(187).EventEmitter),T=function(e){return function(t){e.pop(),e.unshift(O())}},O=function(e){return{failures:0,fallbacks:0,successes:0,rejects:0,fires:0,timeouts:0,cacheHits:0,cacheMisses:0,coalesceCacheHits:0,coalesceCacheMisses:0,semaphoreRejections:0,percentiles:{},latencyTimes:[]}};e.exports=g}},t={},function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}(524);var e,t}));
//# sourceMappingURL=opossum.min.map

@@ -7,4 +7,5 @@ /**

class MemoryCache {
constructor () {
constructor (maxEntries) {
this.cache = new Map();
this.maxEntries = maxEntries ?? 2 ^ 24 - 1; // Max size for Map is 2 ^ 24.
}

@@ -36,2 +37,7 @@

set (key, value, ttl) {
// Evict oldest entry when at capacity.
if (this.cache.size === this.maxEntries) {
this.cache.delete(this.cache.keys().next().value);
}
this.cache.set(key, {

@@ -38,0 +44,0 @@ expiresAt: ttl,

@@ -91,2 +91,5 @@ 'use strict';

* in milliseconds. Set 0 for infinity cache. Default: 0 (no TTL)
* @param {Number} options.cacheSize the max amount of entries in the internal
* cache. Only used when cacheTransport is not defined.
* Default: max size of JS map (2^24).
* @param {Function} options.cacheGetKey function that returns the key to use

@@ -99,2 +102,15 @@ * when caching the result of the circuit's fire.

* should implement `get`, `set` and `flush` methods.
* @param {boolean} options.coalesce If true, this provides coalescing of
* requests to this breaker, in other words: the promise will be cached.
* Only one action (with same cache key) is executed at a time, and the other
* pending actions wait for the result. Performance will improve when rapidly
* firing the circuitbreaker with the same request, especially on a slower
* action (e.g. multiple end-users fetching same data from remote).
* Will use internal cache only. Can be used in combination with options.cache.
* The metrics `coalesceCacheHit` and `coalesceCacheMiss` are available.
* Default: false
* @param {Number} options.coalesceTTL the time to live for the coalescing
* in milliseconds. Set 0 for infinity cache. Default: same as options.timeout
* @param {Number} options.coalesceSize the max amount of entries in the
* coalescing cache. Default: max size of JS map (2^24).
* @param {AbortController} options.abortController this allows Opossum to

@@ -120,2 +136,4 @@ * signal upon timeout and properly abort your on going requests instead of

* @fires CircuitBreaker#cacheMiss
* @fires CircuitBreaker#coalesceCacheHit
* @fires CircuitBreaker#coalesceCacheMiss
* @fires CircuitBreaker#reject

@@ -174,2 +192,4 @@ * @fires CircuitBreaker#timeout

this.options.rotateBucketController = options.rotateBucketController;
this.options.coalesce = !!options.coalesce;
this.options.coalesceTTL = options.coalesceTTL ?? this.options.timeout;

@@ -179,3 +199,3 @@ // Set default cache transport if not provided

if (this.options.cacheTransport === undefined) {
this.options.cacheTransport = new MemoryCache();
this.options.cacheTransport = new MemoryCache(options.cacheSize);
} else if (typeof this.options.cacheTransport !== 'object' ||

@@ -192,2 +212,6 @@ !this.options.cacheTransport.get ||

if (this.options.coalesce) {
this.options.coalesceCache = new MemoryCache(options.coalesceSize);
}
this.semaphore = new Semaphore(this.options.capacity);

@@ -274,2 +298,4 @@

this.on('cacheMiss', increment('cacheMisses'));
this.on('coalesceCacheHit', increment('coalesceCacheHits'));
this.on('coalesceCacheMiss', increment('coalesceCacheMisses'));
this.on('open', _ => this[STATUS].open());

@@ -603,2 +629,10 @@ this.on('close', _ => this[STATUS].close());

// Protection, caches and coalesce disabled.
if (!this[ENABLED]) {
const result = this.action.apply(context, args);
return (typeof result.then === 'function')
? result
: Promise.resolve(result);
}
// Need to create variable here to prevent extra calls if cache is disabled

@@ -635,7 +669,22 @@ let cacheKey = '';

if (!this[ENABLED]) {
const result = this.action.apply(context, args);
return (typeof result.then === 'function')
? result
: Promise.resolve(result);
/* When coalesce is enabled, check coalesce cache and return
promise, if any. */
if (this.options.coalesce) {
const cachedCall = this.options.coalesceCache.get(cacheKey);
if (cachedCall) {
/**
* Emitted when the circuit breaker is using coalesce cache
* and finds a cached promise.
* @event CircuitBreaker#coalesceCacheHit
*/
this.emit('coalesceCacheHit');
return cachedCall;
}
/**
* Emitted when the circuit breaker does not find a value in
* coalesce cache, but the coalesce option is enabled.
* @event CircuitBreaker#coalesceCacheMiss
*/
this.emit('coalesceCacheMiss');
}

@@ -660,3 +709,4 @@

let timeoutError = false;
return new Promise((resolve, reject) => {
const call = new Promise((resolve, reject) => {
const latencyStartTime = Date.now();

@@ -741,2 +791,15 @@ if (this.semaphore.test()) {

});
/* When coalesce is enabled, store promise in coalesceCache */
if (this.options.coalesce) {
this.options.coalesceCache.set(
cacheKey,
call,
this.options.coalesceTTL > 0
? Date.now() + this.options.coalesceTTL
: 0
);
}
return call;
}

@@ -743,0 +806,0 @@

@@ -232,2 +232,4 @@ 'use strict';

cacheMisses: 0,
coalesceCacheHits: 0,
coalesceCacheMisses: 0,
semaphoreRejections: 0,

@@ -234,0 +236,0 @@ percentiles: {},

{
"name": "opossum",
"version": "8.1.4",
"version": "8.2.0",
"author": "Red Hat, Inc.",

@@ -41,5 +41,5 @@ "license": "Apache-2.0",

"@babel/preset-env": "^7.22.9",
"babel-loader": "^9.1.3",
"babel-loader": "^9.2.1",
"buffer": "^6.0.3",
"documentation": "^14.0.1",
"documentation": "^14.0.3",
"eslint": "^8.51.0",

@@ -55,7 +55,7 @@ "eslint-config-semistandard": "^17.0.0",

"husky": "^8.0.3",
"nyc": "~15.1.0",
"nyc": "~17.0.0",
"opener": "1.5.2",
"serve": "^14.2.0",
"stream-browserify": "^3.0.0",
"tape": "~5.7.2",
"tape": "~5.9.0",
"util": "^0.12.5",

@@ -62,0 +62,0 @@ "webpack": "~5.88.2",

@@ -185,2 +185,4 @@ # opossum

cacheMisses: 0,
coalesceCacheHits: 0,
coalesceCacheMisses: 0,
semaphoreRejections: 0,

@@ -421,3 +423,6 @@ percentiles: {

### Coalesce calls
Circuitbreaker offers coalescing your calls. If options.coalesce is set, multiple calls to the circuitbreaker will be handled as one, within the given timeframe (options.coalesceTTL). Performance will improve when rapidly firing the circuitbreaker with the same request, especially on a slower action. This is especially useful if multiple events can trigger the same functions at the same time. Of course, caching has the same function, but will only be effective when the call has been executed once to store the return value. Coalescing and cache can be used at the same time, coalescing calls will always use the internal cache.
### Typings

@@ -424,0 +429,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc