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 7.1.0 to 8.0.0

lib/cache.js

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,(()=>(()=>{"use strict";var e={497:(e,t,n)=>{e.exports=n(638)},638:(e,t,n)=>{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){return function(e){if(Array.isArray(e))return i(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 i(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)?i(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 i(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 s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}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,r.key,r)}}function c(e,t){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},c(e,t)}function a(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 l(e)}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=n(187),h=n(361),y=n(125),m=Symbol("state"),v=Symbol("open"),b=Symbol("closed"),d=Symbol("half-open"),w=Symbol("pending-close"),g=Symbol("shutdown"),O=Symbol("fallback"),x=Symbol("status"),T=Symbol("name"),j=Symbol("group"),k=new WeakMap,E=Symbol("Enabled"),P=Symbol("warming-up"),S=Symbol("volume-threshold"),_=Symbol("our-error"),L=Symbol("reset-timeout"),C=Symbol("warmup-timeout"),A=Symbol("last-timer-at"),R="options.maxFailures is deprecated. Please use options.errorThresholdPercentage",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&&c(e,t)}(M,e);var t,n,r,o,i,p=(o=M,i=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=f(o);if(i){var n=f(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return a(this,e)});function M(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(s(this,M),(t=p.call(this)).options=n,t.options.timeout=!1!==n.timeout&&(n.timeout||1e4),t.options.resetTimeout=n.resetTimeout||3e4,t.options.errorThresholdPercentage=n.errorThresholdPercentage||50,t.options.rollingCountTimeout=n.rollingCountTimeout||1e4,t.options.rollingCountBuckets=n.rollingCountBuckets||10,t.options.rollingPercentilesEnabled=!1!==n.rollingPercentilesEnabled,t.options.capacity=Number.isInteger(n.capacity)?n.capacity:Number.MAX_SAFE_INTEGER,t.options.errorFilter=n.errorFilter||function(e){return!1},t.semaphore=new y(t.options.capacity),!e)throw new TypeError("No action provided. Cannot construct a CircuitBreaker without an invocable action.");if(n.abortController&&"function"!=typeof n.abortController.abort)throw new TypeError("AbortController does not contain `abort()` method");if(t[S]=Number.isInteger(n.volumeThreshold)?n.volumeThreshold:0,t[P]=!0===n.allowWarmUp,t.options.status?t.options.status instanceof h?t[x]=t.options.status:t[x]=new h({stats:t.options.status}):t[x]=new h(t.options),t[m]=b,n.state?(t[E]=!1!==n.state.enabled,t[P]=n.state.warmUp||t[P],t[b]=!1!==n.state.closed,t[d]=t[w]=n.state.halfOpen||!1,t[v]=!t[b]&&!t[d],t[g]=n.state.shutdown||!1):(t[w]=!1,t[E]=!1!==n.enabled),t[O]=null,t[T]=n.name||e.name||B(),t[j]=n.group||t[T],t[P]){var r=t[C]=setTimeout((function(e){return t[P]=!1}),t.options.rollingCountTimeout);"function"==typeof r.unref&&r.unref()}t.action="function"!=typeof e?function(t){return Promise.resolve(e)}:e,n.maxFailures&&console.error(R);var o=function(e){return function(n,r){return t[x].increment(e,r)}};function i(e){return e[A]=Date.now(),function(t){var n=e[L]=setTimeout((function(){u(e)}),e.options.resetTimeout);"function"==typeof n.unref&&n.unref()}}function u(e){e[m]=d,e[w]=!0,e.emit("halfOpen",e.options.resetTimeout)}return t.on("success",o("successes")),t.on("failure",o("failures")),t.on("fallback",o("fallbacks")),t.on("timeout",o("timeouts")),t.on("fire",o("fires")),t.on("reject",o("rejects")),t.on("cacheHit",o("cacheHits")),t.on("cacheMiss",o("cacheMisses")),t.on("open",(function(e){return t[x].open()})),t.on("close",(function(e){return t[x].close()})),t.on("semaphoreLocked",o("semaphoreRejections")),t.on("open",i(l(t))),t.on("success",(function(e){t.halfOpen&&t.close()})),t.options.cache&&k.set(l(t),void 0),t[g]?(t[m]=g,t.shutdown()):t[b]?t.close():t[v]?void 0!==t.options.state.lastTimerAt&&Date.now()-t.options.state.lastTimerAt>t.options.resetTimeout?u(l(t)):t.open():t[d]&&(t[m]=d),t}return t=M,n=[{key:"close",value:function(){this[m]!==b&&(this[L]&&clearTimeout(this[L]),this[m]=b,this[w]=!1,this.emit("close"))}},{key:"open",value:function(){this[m]!==v&&(this[m]=v,this[w]=!1,this.emit("open"))}},{key:"shutdown",value:function(){this.emit("shutdown"),this.disable(),this.removeAllListeners(),this[L]&&clearTimeout(this[L]),this[C]&&clearTimeout(this[C]),this.status.shutdown(),this[m]=g}},{key:"isShutdown",get:function(){return this[m]===g}},{key:"name",get:function(){return this[T]}},{key:"group",get:function(){return this[j]}},{key:"pendingClose",get:function(){return this[w]}},{key:"closed",get:function(){return this[m]===b}},{key:"opened",get:function(){return this[m]===v}},{key:"halfOpen",get:function(){return this[m]===d}},{key:"status",get:function(){return this[x]}},{key:"stats",get:function(){return this[x].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[P]}},{key:"volumeThreshold",get:function(){return this[S]}},{key:"fallback",value:function(e){var t=e;return e instanceof M&&(t=function(){return e.fire.apply(e,arguments)}),this[O]=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=I("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=Array.prototype.slice.call(o);if(this.emit("fire",u),void 0!==k.get(this))return this.emit("cacheHit"),k.get(this);if(this.options.cache&&this.emit("cacheMiss"),!this[E]){var c=this.action.apply(e,u);return"function"==typeof c.then?c:Promise.resolve(c)}if(!this.closed&&!this.pendingClose){var a=I("Breaker is open","EOPENBREAKER");return this.emit("reject",a),N(this,a,u)||Promise.reject(a)}this[w]=!1;var l=!1;return new Promise((function(n,r){var o=Date.now();if(t.semaphore.test()){t.options.timeout&&(s=setTimeout((function(){l=!0;var e=I("Timed out after ".concat(t.options.timeout,"ms"),"ETIMEDOUT"),i=Date.now()-o;t.semaphore.release(),t.emit("timeout",e,i,u),D(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),c="function"==typeof i.then?i:Promise.resolve(i);c.then((function(e){l||(clearTimeout(s),t.emit("success",e,Date.now()-o),t.semaphore.release(),n(e),t.options.cache&&k.set(t,c))})).catch((function(e){if(!l){t.semaphore.release();var i=Date.now()-o;D(e,t,s,u,i,n,r)}}))}catch(e){t.semaphore.release();var a=Date.now()-o;D(e,t,s,u,a,n,r)}}else{var f=Date.now()-o,p=I("Semaphore locked","ESEMLOCKED");t.emit("semaphoreLocked",p,f),D(p,t,s,u,f,n,r)}}))}},{key:"clearCache",value:function(){k.set(this,void 0)}},{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}},{key:"disable",value:function(){this[E]=!1}}],r=[{key:"isOurError",value:function(e){return!!e[_]}},{key:"newStatus",value:function(e){return new h(e)}}],n&&u(t.prototype,n),r&&u(t,r),Object.defineProperty(t,"prototype",{writable:!1}),M}(p);function D(e,t,n,r,i,s,u){var c;if(clearTimeout(n),(c=t.options).errorFilter.apply(c,[e].concat(o(r))))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,r,i);var a=N(t,e,r);if(a)return s(a)}u(e)}function N(e,t,n){if(e[O])try{var r=e[O].apply(e[O],[].concat(o(n),[t]));return e.emit("fallback",r,t),r instanceof Promise?r:Promise.resolve(r)}catch(e){return Promise.reject(e)}}function I(e,t){var n=new Error(e);return n.code=t,n[_]=!0,n}var B=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},125:(e,t)=>{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()()}}},361:(e,t,n)=>{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 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,r.key,r)}}function c(e,t){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},c(e,t)}function a(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)}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=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&&c(e,t)}(b,e);var t,n,r,o,s=(r=b,o=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(r);if(o){var n=l(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return a(this,e)});function b(e){var t;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,b),(t=s.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.rollingPercentilesEnabled=!1!==e.rollingPercentilesEnabled;for(var n=0;n<t[p];n++)t[f][n]=w();var r=Math.floor(t[h]/t[p]);return t[m]=setInterval(d(t[f]),r),"function"==typeof t[m].unref&&t[m].unref(),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({},w()),e.stats)),t}return t=b,(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&&t.latencyTimes.push.apply(t.latencyTimes,n.latencyTimes||[]),t):t}),w());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(),clearInterval(this[m]),clearInterval(this[v])}}])&&u(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),b}(n(187).EventEmitter),d=function(e){return function(t){e.pop(),e.unshift(w())}},w=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=b},187:e=>{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):[]}}},t={};return 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}(497)})()));
!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,t);if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(o.key,"string"),"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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}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,(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,t);if("object"!==i(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(r.key,"string"),"symbol"===i(o)?o:String(o)),r)}var o}function c(e,t){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},c(e,t)}function a(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)}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=n(187),h=n(741),y=n(384),m=n(235),v=Symbol("state"),b=Symbol("open"),d=Symbol("closed"),w=Symbol("half-open"),g=Symbol("pending-close"),O=Symbol("shutdown"),T=Symbol("fallback"),j=Symbol("status"),x=Symbol("name"),S=Symbol("group"),k=Symbol("Enabled"),E=Symbol("warming-up"),P=Symbol("volume-threshold"),L=Symbol("our-error"),_=Symbol("reset-timeout"),C=Symbol("warmup-timeout"),A=Symbol("last-timer-at"),R="options.maxFailures is deprecated. Please use options.errorThresholdPercentage",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&&c(e,t)}(F,e);var t,n,r,o,p,M=(o=F,p=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=f(o);if(p){var n=f(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return a(this,e)});function F(e){var t,n,r,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(s(this,F),(r=M.call(this)).options=o,r.options.timeout=!1!==o.timeout&&(o.timeout||1e4),r.options.resetTimeout=o.resetTimeout||3e4,r.options.errorThresholdPercentage=o.errorThresholdPercentage||50,r.options.rollingCountTimeout=o.rollingCountTimeout||1e4,r.options.rollingCountBuckets=o.rollingCountBuckets||10,r.options.rollingPercentilesEnabled=!1!==o.rollingPercentilesEnabled,r.options.capacity=Number.isInteger(o.capacity)?o.capacity:Number.MAX_SAFE_INTEGER,r.options.errorFilter=o.errorFilter||function(e){return!1},r.options.cacheTTL=null!==(t=o.cacheTTL)&&void 0!==t?t:0,r.options.cacheGetKey=null!==(n=o.cacheGetKey)&&void 0!==n?n:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return JSON.stringify(t)},r.options.cache)if(void 0===r.options.cacheTransport)r.options.cacheTransport=new m;else if("object"!==i(r.options.cacheTransport)||!r.options.cacheTransport.get||!r.options.cacheTransport.set||!r.options.cacheTransport.flush)throw new TypeError("options.cacheTransport should be an object with `get`, `set` and `flush` methods");if(r.semaphore=new y(r.options.capacity),!e)throw new TypeError("No action provided. Cannot construct a CircuitBreaker without an invocable action.");if(o.abortController&&"function"!=typeof o.abortController.abort)throw new TypeError("AbortController does not contain `abort()` method");if(r[P]=Number.isInteger(o.volumeThreshold)?o.volumeThreshold:0,r[E]=!0===o.allowWarmUp,r.options.status?r.options.status instanceof h?r[j]=r.options.status:r[j]=new h({stats:r.options.status}):r[j]=new h(r.options),r[v]=d,o.state?(r[k]=!1!==o.state.enabled,r[E]=o.state.warmUp||r[E],r[d]=!1!==o.state.closed,r[w]=r[g]=o.state.halfOpen||!1,r[b]=!r[d]&&!r[w],r[O]=o.state.shutdown||!1):(r[g]=!1,r[k]=!1!==o.enabled),r[T]=null,r[x]=o.name||e.name||B(),r[S]=o.group||r[x],r[E]){var u=r[C]=setTimeout((function(e){return r[E]=!1}),r.options.rollingCountTimeout);"function"==typeof u.unref&&u.unref()}r.action="function"!=typeof e?function(t){return Promise.resolve(e)}:e,o.maxFailures&&console.error(R);var c=function(e){return function(t,n){return r[j].increment(e,n)}};function a(e){return e[A]=Date.now(),function(t){var n=e[_]=setTimeout((function(){f(e)}),e.options.resetTimeout);"function"==typeof n.unref&&n.unref()}}function f(e){e[v]=w,e[g]=!0,e.emit("halfOpen",e.options.resetTimeout)}return r.on("success",c("successes")),r.on("failure",c("failures")),r.on("fallback",c("fallbacks")),r.on("timeout",c("timeouts")),r.on("fire",c("fires")),r.on("reject",c("rejects")),r.on("cacheHit",c("cacheHits")),r.on("cacheMiss",c("cacheMisses")),r.on("open",(function(e){return r[j].open()})),r.on("close",(function(e){return r[j].close()})),r.on("semaphoreLocked",c("semaphoreRejections")),r.on("open",a(l(r))),r.on("success",(function(e){r.halfOpen&&r.close()})),r[O]?(r[v]=O,r.shutdown()):r[d]?r.close():r[b]?void 0!==r.options.state.lastTimerAt&&Date.now()-r.options.state.lastTimerAt>r.options.resetTimeout?f(l(r)):r.open():r[w]&&(r[v]=w),r}return t=F,n=[{key:"close",value:function(){this[v]!==d&&(this[_]&&clearTimeout(this[_]),this[v]=d,this[g]=!1,this.emit("close"))}},{key:"open",value:function(){this[v]!==b&&(this[v]=b,this[g]=!1,this.emit("open"))}},{key:"shutdown",value:function(){this.emit("shutdown"),this.disable(),this.removeAllListeners(),this[_]&&clearTimeout(this[_]),this[C]&&clearTimeout(this[C]),this.status.shutdown(),this[v]=O,this.clearCache()}},{key:"isShutdown",get:function(){return this[v]===O}},{key:"name",get:function(){return this[x]}},{key:"group",get:function(){return this[S]}},{key:"pendingClose",get:function(){return this[g]}},{key:"closed",get:function(){return this[v]===d}},{key:"opened",get:function(){return this[v]===b}},{key:"halfOpen",get:function(){return this[v]===w}},{key:"status",get:function(){return this[j]}},{key:"stats",get:function(){return this[j].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[k]}},{key:"warmUp",get:function(){return this[E]}},{key:"volumeThreshold",get:function(){return this[P]}},{key:"fallback",value:function(e){var t=e;return e instanceof F&&(t=function(){return e.fire.apply(e,arguments)}),this[T]=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=I("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=Array.prototype.slice.call(o),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[k]){var l=this.action.apply(e,u);return"function"==typeof l.then?l:Promise.resolve(l)}if(!this.closed&&!this.pendingClose){var f=I("Breaker is open","EOPENBREAKER");return this.emit("reject",f),N(this,f,u)||Promise.reject(f)}this[g]=!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=I("Timed out after ".concat(t.options.timeout,"ms"),"ETIMEDOUT"),i=Date.now()-o;t.semaphore.release(),t.emit("timeout",e,i,u),D(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;D(e,t,s,u,i,n,r)}}))}catch(e){t.semaphore.release();var l=Date.now()-o;D(e,t,s,u,l,n,r)}}else{var f=Date.now()-o,h=I("Semaphore locked","ESEMLOCKED");t.emit("semaphoreLocked",h,f),D(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[k]=!0}},{key:"disable",value:function(){this[k]=!1}}],r=[{key:"isOurError",value:function(e){return!!e[L]}},{key:"newStatus",value:function(e){return new h(e)}}],n&&u(t.prototype,n),r&&u(t,r),Object.defineProperty(t,"prototype",{writable:!1}),F}(p);function D(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=N(t,e,o);if(a)return s(a)}u(e)}function N(e,t,n){if(e[T])try{var o=e[T].apply(e[T],[].concat(r(n),[t]));return e.emit("fallback",o,t),o instanceof Promise?o:Promise.resolve(o)}catch(e){return Promise.reject(e)}}function I(e,t){var n=new Error(e);return n.code=t,n[L]=!0,n}var B=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=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,t);if("object"!==r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");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,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)}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=Symbol("window"),h=Symbol("buckets"),y=Symbol("timeout"),m=Symbol("percentiles"),v=Symbol("bucket-interval"),b=Symbol("snapshot-interval"),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)}(c,e);var t,n,r,o,s=(r=c,o=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=f(r);if(o){var n=f(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return l(this,e)});function c(e){var t;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,c),(t=s.call(this))[h]=e.rollingCountBuckets||10,t[y]=e.rollingCountTimeout||1e4,t[p]=new Array(t[h]),t[m]=[0,.25,.5,.75,.9,.95,.99,.995,1],t.rollingPercentilesEnabled=!1!==e.rollingPercentilesEnabled;for(var n=0;n<t[h];n++)t[p][n]=g();var r=Math.floor(t[y]/t[h]);return t[v]=setInterval(w(t[p]),r),"function"==typeof t[v].unref&&t[v].unref(),t[b]=setInterval((function(e){return t.emit("snapshot",t.stats)}),r),"function"==typeof t[b].unref&&t[b].unref(),e.stats&&(t[p][0]=i(i({},g()),e.stats)),t}return t=c,(n=[{key:"stats",get:function(){var e=this,t=this[p].reduce((function(t,n){return n?(Object.keys(t).forEach((function(e){"latencyTimes"!==e&&"percentiles"!==e&&(t[e]+=n[e]||0)})),e.rollingPercentilesEnabled&&t.latencyTimes.push.apply(t.latencyTimes,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[m].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[m].forEach((function(e){t.percentiles[e]=-1}))),t}},{key:"window",get:function(){return this[p].slice()}},{key:"increment",value:function(e,t){this[p][0][e]++,"successes"!==e&&"failures"!==e&&"timeouts"!==e||this[p][0].latencyTimes.push(t||0)}},{key:"open",value:function(){this[p][0].isCircuitBreakerOpen=!0}},{key:"close",value:function(){this[p][0].isCircuitBreakerOpen=!1}},{key:"shutdown",value:function(){this.removeAllListeners(),clearInterval(this[v]),clearInterval(this[b])}}])&&u(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),c}(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}));
//# sourceMappingURL=opossum.min.map

@@ -6,2 +6,3 @@ 'use strict';

const Semaphore = require('./semaphore');
const MemoryCache = require('./cache');

@@ -18,3 +19,2 @@ const STATE = Symbol('state');

const GROUP = Symbol('group');
const CACHE = new WeakMap();
const ENABLED = Symbol('Enabled');

@@ -91,2 +91,11 @@ const WARMING_UP = Symbol('warming-up');

* `cacheMiss` reflect cache activity.) Default: false
* @param {Number} options.cacheTTL the time to live for the cache
* in milliseconds. Set 0 for infinity cache. Default: 0 (no TTL)
* @param {Function} options.cacheGetKey function that returns the key to use
* when caching the result of the circuit's fire.
* Better to use custom one, because `JSON.stringify` is not good
* from performance perspective.
* Default: `(...args) => JSON.stringify(args)`
* @param {CacheTransport} options.cacheTransport custom cache transport
* should implement `get`, `set` and `flush` methods.
* @param {AbortController} options.abortController this allows Opossum to

@@ -152,3 +161,21 @@ * signal upon timeout and properly abort your on going requests instead of

this.options.errorFilter = options.errorFilter || (_ => false);
this.options.cacheTTL = options.cacheTTL ?? 0;
this.options.cacheGetKey = options.cacheGetKey ??
((...args) => JSON.stringify(args));
// Set default cache transport if not provided
if (this.options.cache) {
if (this.options.cacheTransport === undefined) {
this.options.cacheTransport = new MemoryCache();
} else if (typeof this.options.cacheTransport !== 'object' ||
!this.options.cacheTransport.get ||
!this.options.cacheTransport.set ||
!this.options.cacheTransport.flush
) {
throw new TypeError(
'options.cacheTransport should be an object with `get`, `set` and `flush` methods'
);
}
}
this.semaphore = new Semaphore(this.options.capacity);

@@ -282,5 +309,2 @@

});
if (this.options.cache) {
CACHE.set(this, undefined);
}

@@ -373,2 +397,5 @@ // Prepopulate the State of the Breaker

this[STATE] = SHUTDOWN;
// clear cache on shutdown
this.clearCache();
}

@@ -566,2 +593,5 @@

// Need to create variable here to prevent extra calls if cache is disabled
let cacheKey = '';
/**

@@ -574,12 +604,16 @@ * Emitted when the circuit breaker action is executed

if (CACHE.get(this) !== undefined) {
// If cache is enabled, check if we have a cached value
if (this.options.cache) {
cacheKey = this.options.cacheGetKey.apply(this, rest);
const cached = this.options.cacheTransport.get(cacheKey);
if (cached) {
/**
* Emitted when the circuit breaker is using the cache
* and finds a value.
* @event CircuitBreaker#cacheHit
*/
this.emit('cacheHit');
return cached;
}
/**
* Emitted when the circuit breaker is using the cache
* and finds a value.
* @event CircuitBreaker#cacheHit
*/
this.emit('cacheHit');
return CACHE.get(this);
} else if (this.options.cache) {
/**
* Emitted when the circuit breaker does not find a value in

@@ -660,3 +694,9 @@ * the cache, but the cache option is enabled.

if (this.options.cache) {
CACHE.set(this, promise);
this.options.cacheTransport.set(
cacheKey,
promise,
this.options.cacheTTL > 0
? Date.now() + this.options.cacheTTL
: 0
);
}

@@ -698,3 +738,5 @@ }

clearCache () {
CACHE.set(this, undefined);
if (this.options.cache) {
this.options.cacheTransport.flush();
}
}

@@ -701,0 +743,0 @@

{
"name": "opossum",
"version": "7.1.0",
"version": "8.0.0",
"author": "Red Hat, Inc.",
"license": "Apache-2.0",
"type": "commonjs",
"scripts": {

@@ -38,12 +39,12 @@ "prepare": "husky install",

"devDependencies": {
"@babel/core": "^7.20.7",
"@babel/preset-env": "^7.19.4",
"babel-loader": "^9.1.0",
"@babel/core": "^7.21.8",
"@babel/preset-env": "^7.21.5",
"babel-loader": "^9.1.2",
"buffer": "^6.0.3",
"documentation": "^14.0.1",
"eslint": "^8.30.0",
"eslint": "^8.39.0",
"eslint-config-semistandard": "^17.0.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.6.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-node": "^11.1.0",

@@ -53,11 +54,11 @@ "eslint-plugin-promise": "^6.1.0",

"faucet": "^0.0.3",
"husky": "^8.0.1",
"husky": "^8.0.3",
"nyc": "~15.1.0",
"opener": "1.5.2",
"serve": "^14.1.2",
"serve": "^14.2.0",
"stream-browserify": "^3.0.0",
"tape": "~5.6.1",
"tape": "~5.6.3",
"util": "^0.12.5",
"webpack": "~5.75.0",
"webpack-cli": "~5.0.1"
"webpack": "~5.82.0",
"webpack-cli": "~5.0.2"
},

@@ -75,5 +76,5 @@ "description": "A fail-fast circuit breaker for promises and callbacks",

"engines": {
"node": "^19 || ^18 || ^16 || ^14"
"node": "^20 || ^18 || ^16"
},
"support": true
}

@@ -23,3 +23,3 @@ # opossum

| Issue tracker: | https://github.com/nodeshift/opossum/issues |
| Engines: | Node.js >= 14 |
| Engines: | Node.js >= 16 |

@@ -26,0 +26,0 @@ ## Usage

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