@awsless/cli 0.0.36 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/prebuild/icon/bundle.zip +0 -0
- package/dist/prebuild/image/bundle.zip +0 -0
- package/dist/prebuild/on-error-log/bundle.zip +0 -0
- package/dist/prebuild/on-failure/bundle.zip +0 -0
- package/dist/prebuild/pubsub-publisher/bundle.zip +0 -0
- package/dist/prebuild/pubsub-server/HASH +1 -1
- package/dist/prebuild/pubsub-server/index.mjs +1 -1
- package/dist/prebuild/rpc/bundle.zip +0 -0
- package/package.json +4 -4
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
0d98303bb30788c86d9940c34b77ac681a574b34
|
|
@@ -233,4 +233,4 @@ $`+Buffer.byteLength(this.name)+`\r
|
|
|
233
233
|
`+n+`\r
|
|
234
234
|
`}}return t}stringifyArguments(){for(let e=0;e<this.args.length;++e){let t=this.args[e];typeof t==`string`||(t instanceof Buffer?this.bufferMode=!0:this.args[e]=(0,i.toArg)(t))}}transformReply(t){this.replyEncoding&&(t=(0,i.convertBufferToString)(t,this.replyEncoding));let n=e._transformer.reply[this.name];return n&&(t=n(t)),t}setTimeout(e){this._commandTimeoutTimer||=setTimeout(()=>{this.isResolved||this.reject(Error(`Command timed out`))},e)}setBlockingTimeout(e){if(e<=0)return;this._blockingTimeoutTimer&&=(clearTimeout(this._blockingTimeoutTimer),void 0);let t=Date.now();this._blockingDeadline===void 0&&(this._blockingDeadline=t+e);let n=this._blockingDeadline-t;if(n<=0){this.resolve(null);return}this._blockingTimeoutTimer=setTimeout(()=>{if(this.isResolved){this._blockingTimeoutTimer=void 0;return}this._blockingTimeoutTimer=void 0,this.resolve(null)},n)}extractBlockingTimeout(){let t=this.args;if(!t||t.length===0)return;let n=this.name.toLowerCase();if(e.checkFlag(`LAST_ARG_TIMEOUT_COMMANDS`,n))return(0,a.parseSecondsArgument)(t[t.length-1]);if(e.checkFlag(`FIRST_ARG_TIMEOUT_COMMANDS`,n))return(0,a.parseSecondsArgument)(t[0]);if(e.checkFlag(`BLOCK_OPTION_COMMANDS`,n))return(0,a.parseBlockOption)(t)}_clearTimers(){let e=this._commandTimeoutTimer;e&&(clearTimeout(e),delete this._commandTimeoutTimer);let t=this._blockingTimeoutTimer;t&&(clearTimeout(t),delete this._blockingTimeoutTimer)}initPromise(){let t=new Promise((t,n)=>{if(!this.transformed){this.transformed=!0;let t=e._transformer.argument[this.name];t&&(this.args=t(this.args)),this.stringifyArguments()}this.resolve=this._convertValue(t),this.reject=e=>{this._clearTimers(),this.errorStack?n((0,i.optimizeErrorStack)(e,this.errorStack.stack,__dirname)):n(e)}});this.promise=(0,r.default)(t,this.callback)}_iterateKeys(e=e=>e){if(this.keys===void 0&&(this.keys=[],(0,t.exists)(this.name,{caseInsensitive:!0}))){let n=(0,t.getKeyIndexes)(this.name,this.args,{nameCaseInsensitive:!0});for(let t of n)this.args[t]=e(this.args[t]),this.keys.push(this.args[t])}return this.keys}_convertValue(e){return t=>{try{this._clearTimers(),e(this.transformReply(t)),this.isResolved=!0}catch(e){this.reject(e)}return this.promise}}};e.default=o,o.FLAGS={VALID_IN_SUBSCRIBER_MODE:[`subscribe`,`psubscribe`,`unsubscribe`,`punsubscribe`,`ssubscribe`,`sunsubscribe`,`ping`,`quit`],VALID_IN_MONITOR_MODE:[`monitor`,`auth`],ENTER_SUBSCRIBER_MODE:[`subscribe`,`psubscribe`,`ssubscribe`],EXIT_SUBSCRIBER_MODE:[`unsubscribe`,`punsubscribe`,`sunsubscribe`],WILL_DISCONNECT:[`quit`],HANDSHAKE_COMMANDS:[`auth`,`select`,`client`,`readonly`,`info`],IGNORE_RECONNECT_ON_ERROR:[`client`],BLOCKING_COMMANDS:[`blpop`,`brpop`,`brpoplpush`,`blmove`,`bzpopmin`,`bzpopmax`,`bzmpop`,`blmpop`,`xread`,`xreadgroup`],LAST_ARG_TIMEOUT_COMMANDS:[`blpop`,`brpop`,`brpoplpush`,`blmove`,`bzpopmin`,`bzpopmax`],FIRST_ARG_TIMEOUT_COMMANDS:[`bzmpop`,`blmpop`],BLOCK_OPTION_COMMANDS:[`xread`,`xreadgroup`]},o._transformer={argument:{},reply:{}};let s=function(e){if(e.length===1){if(e[0]instanceof Map)return(0,i.convertMapToArray)(e[0]);if(typeof e[0]==`object`&&e[0]!==null)return(0,i.convertObjectToArray)(e[0])}return e},c=function(e){if(e.length===2){if(e[1]instanceof Map)return[e[0]].concat((0,i.convertMapToArray)(e[1]));if(typeof e[1]==`object`&&e[1]!==null)return[e[0]].concat((0,i.convertObjectToArray)(e[1]))}return e};o.setArgumentTransformer(`mset`,s),o.setArgumentTransformer(`msetnx`,s),o.setArgumentTransformer(`hset`,c),o.setArgumentTransformer(`hmset`,c),o.setReplyTransformer(`hgetall`,function(e){if(Array.isArray(e)){let t={};for(let n=0;n<e.length;n+=2){let r=e[n],i=e[n+1];r in t?Object.defineProperty(t,r,{value:i,configurable:!0,enumerable:!0,writable:!0}):t[r]=i}return t}return e});var l=class{constructor(){this.length=0,this.items=[]}push(e){this.length+=Buffer.byteLength(e),this.items.push(e)}toBuffer(){let e=Buffer.allocUnsafe(this.length),t=0;for(let n of this.items){let r=Buffer.byteLength(n);Buffer.isBuffer(n)?n.copy(e,t):e.write(n,t,r),t+=r}return e}}})),yF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=iF();var n=class extends t.RedisError{constructor(e,t){super(e),this.lastNodeError=t,Error.captureStackTrace(this,this.constructor)}get name(){return this.constructor.name}};e.default=n,n.defaultMessage=`Failed to refresh slots cache.`})),bF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=h(`stream`);e.default=class extends t.Readable{constructor(e){super(e),this.opt=e,this._redisCursor=`0`,this._redisDrained=!1}_read(){if(this._redisDrained){this.push(null);return}let e=[this._redisCursor];this.opt.key&&e.unshift(this.opt.key),this.opt.match&&e.push(`MATCH`,this.opt.match),this.opt.type&&e.push(`TYPE`,this.opt.type),this.opt.count&&e.push(`COUNT`,String(this.opt.count)),this.opt.noValues&&e.push(`NOVALUES`),this.opt.redis[this.opt.command](e,(e,t)=>{if(e){this.emit(`error`,e);return}this._redisCursor=t[0]instanceof Buffer?t[0].toString():t[0],this._redisCursor===`0`&&(this._redisDrained=!0),this.push(t[1])})}close(){this._redisDrained=!0}}})),xF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.executeWithAutoPipelining=e.getFirstValueInFlattenedArray=e.shouldUseAutoPipelining=e.notAllowedAutoPipelineCommands=e.kCallbacks=e.kExec=void 0;let t=cF(),n=aF(),r=tF(),i=$P();e.kExec=Symbol(`exec`),e.kCallbacks=Symbol(`callbacks`),e.notAllowedAutoPipelineCommands=[`auth`,`info`,`script`,`quit`,`cluster`,`pipeline`,`multi`,`subscribe`,`psubscribe`,`unsubscribe`,`unpsubscribe`,`select`,`client`];function a(t,n){if(t._runningAutoPipelines.has(n)||!t._autoPipelines.has(n))return;t._runningAutoPipelines.add(n);let r=t._autoPipelines.get(n);t._autoPipelines.delete(n);let i=r[e.kCallbacks];r[e.kCallbacks]=null,r.exec(function(e,r){if(t._runningAutoPipelines.delete(n),e)for(let t=0;t<i.length;t++)process.nextTick(i[t],e);else for(let e=0;e<i.length;e++)process.nextTick(i[e],...r[e]);t._autoPipelines.has(n)&&a(t,n)})}function o(t,n,r){return n&&t.options.enableAutoPipelining&&!t.isPipeline&&!e.notAllowedAutoPipelineCommands.includes(r)&&!t.options.autoPipeliningIgnoredCommands.includes(r)}e.shouldUseAutoPipelining=o;function s(e){for(let n=0;n<e.length;n++){let r=e[n];if(typeof r==`string`)return r;if(Array.isArray(r)||(0,t.isArguments)(r)){if(r.length===0)continue;return r[0]}let i=[r].flat();if(i.length>0)return i[0]}}e.getFirstValueInFlattenedArray=s;function c(o,l,u,d,f){if(o.isCluster&&!o.slots.length)return o.status===`wait`&&o.connect().catch(t.noop),(0,r.default)(new Promise(function(e,t){o.delayUntilReady(n=>{if(n){t(n);return}c(o,l,u,d,null).then(e,t)})}),f);let p=o.options.keyPrefix||``,m=o.isCluster?o.slots[n(`${p}${s(d)}`)].join(`,`):`main`;if(o.isCluster&&o.options.scaleReads!==`master`){let e=(0,i.exists)(u)&&(0,i.hasFlag)(u,`readonly`);m+=e?`:read`:`:write`}if(!o._autoPipelines.has(m)){let t=o.pipeline();t[e.kExec]=!1,t[e.kCallbacks]=[],o._autoPipelines.set(m,t)}let h=o._autoPipelines.get(m);h[e.kExec]||(h[e.kExec]=!0,setImmediate(a,o,m));let g=new Promise(function(t,n){h[e.kCallbacks].push(function(e,r){if(e){n(e);return}t(r)}),l===`call`&&d.unshift(u),h[l](...d)});return(0,r.default)(g,f)}e.executeWithAutoPipelining=c})),SF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=h(`crypto`),n=vF(),r=tF();e.default=class{constructor(e,r=null,i=``,a=!1){this.lua=e,this.numberOfKeys=r,this.keyPrefix=i,this.readOnly=a,this.sha=(0,t.createHash)(`sha1`).update(e).digest(`hex`);let o=this.sha,s=new WeakSet;this.Command=class extends n.default{toWritable(t){let n=this.reject;return this.reject=e=>{e.message.indexOf(`NOSCRIPT`)!==-1&&s.delete(t),n.call(this,e)},s.has(t)?this.name===`eval`&&(this.name=`evalsha`,this.args[0]=o):(s.add(t),this.name=`eval`,this.args[0]=e),super.toWritable(t)}}}execute(e,t,n,i){typeof this.numberOfKeys==`number`&&t.unshift(this.numberOfKeys),this.keyPrefix&&(n.keyPrefix=this.keyPrefix),this.readOnly&&(n.readOnly=!0);let a=new this.Command(`evalsha`,[this.sha,...t],n);return a.promise=a.promise.catch(r=>{if(r.message.indexOf(`NOSCRIPT`)===-1)throw r;let i=new this.Command(`evalsha`,[this.sha,...t],n);return(e.isPipeline?e.redis:e).sendCommand(i)}),(0,r.default)(a.promise,i),e.sendCommand(a)}}})),CF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=$P(),n=xF(),r=vF(),i=SF();var a=class{constructor(){this.options={},this.scriptsSet={},this.addedBuiltinSet=new Set}getBuiltinCommands(){return o.slice(0)}createBuiltinCommand(e){return{string:s(null,e,`utf8`),buffer:s(null,e,null)}}addBuiltinCommand(e){this.addedBuiltinSet.add(e),this[e]=s(e,e,`utf8`),this[e+`Buffer`]=s(e+`Buffer`,e,null)}defineCommand(e,t){let n=new i.default(t.lua,t.numberOfKeys,this.options.keyPrefix,t.readOnly);this.scriptsSet[e]=n,this[e]=c(e,e,n,`utf8`),this[e+`Buffer`]=c(e+`Buffer`,e,n,null)}sendCommand(e,t,n){throw Error(`"sendCommand" is not implemented`)}};let o=t.list.filter(e=>e!==`monitor`);o.push(`sentinel`),o.forEach(function(e){a.prototype[e]=s(e,e,`utf8`),a.prototype[e+`Buffer`]=s(e+`Buffer`,e,null)}),a.prototype.call=s(`call`,`utf8`),a.prototype.callBuffer=s(`callBuffer`,null),a.prototype.send_command=a.prototype.call;function s(e,t,i){return i===void 0&&(i=t,t=null),function(...a){let o=t||a.shift(),s=a[a.length-1];typeof s==`function`?a.pop():s=void 0;let c={errorStack:this.options.showFriendlyErrorStack?Error():void 0,keyPrefix:this.options.keyPrefix,replyEncoding:i};return(0,n.shouldUseAutoPipelining)(this,e,o)?(0,n.executeWithAutoPipelining)(this,e,o,a,s):this.sendCommand(new r.default(o,a,c,s))}}function c(e,t,r,i){return function(...a){let o=typeof a[a.length-1]==`function`?a.pop():void 0,s={replyEncoding:i};return this.options.showFriendlyErrorStack&&(s.errorStack=Error()),(0,n.shouldUseAutoPipelining)(this,e,t)?(0,n.executeWithAutoPipelining)(this,e,t,a,o):r.execute(this,a,s,o)}}e.default=a})),wF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=aF(),n=$P(),r=tF(),i=h(`util`),a=vF(),o=gF(),s=CF();function c(e,n){let r=t(n[0]),i=e._groupsBySlot[r];for(let r=1;r<n.length;r++)if(e._groupsBySlot[t(n[r])]!==i)return-1;return r}var l=class extends s.default{constructor(e){super(),this.redis=e,this.isPipeline=!0,this.replyPending=0,this._queue=[],this._result=[],this._transactions=0,this._shaToScript={},this.isCluster=this.redis.constructor.name===`Cluster`||this.redis.isCluster,this.options=e.options,Object.keys(e.scriptsSet).forEach(t=>{let n=e.scriptsSet[t];this._shaToScript[n.sha]=n,this[t]=e[t],this[t+`Buffer`]=e[t+`Buffer`]}),e.addedBuiltinSet.forEach(t=>{this[t]=e[t],this[t+`Buffer`]=e[t+`Buffer`]}),this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t});let t=this;Object.defineProperty(this,`length`,{get:function(){return t._queue.length}})}fillResult(e,t){if(this._queue[t].name===`exec`&&Array.isArray(e[1])){let n=e[1].length;for(let r=0;r<n;r++){if(e[1][r]instanceof Error)continue;let i=this._queue[t-(n-r)];try{e[1][r]=i.transformReply(e[1][r])}catch(t){e[1][r]=t}}}if(this._result[t]=e,--this.replyPending)return;if(this.isCluster){let e=!0,t;for(let r=0;r<this._result.length;++r){let i=this._result[r][0],a=this._queue[r];if(i){if(a.name===`exec`&&i.message===`EXECABORT Transaction discarded because of previous errors.`)continue;if(!t)t={name:i.name,message:i.message};else if(t.name!==i.name||t.message!==i.message){e=!1;break}}else if(!a.inTransaction&&!((0,n.exists)(a.name,{caseInsensitive:!0})&&(0,n.hasFlag)(a.name,`readonly`,{nameCaseInsensitive:!0}))){e=!1;break}}if(t&&e){let e=this,n=t.message.split(` `),r=this._queue,i=!1;this._queue=[];for(let e=0;e<r.length;++e){if(n[0]===`ASK`&&!i&&r[e].name!==`asking`&&(!r[e-1]||r[e-1].name!==`asking`)){let e=new a.default(`asking`);e.ignore=!0,this.sendCommand(e)}r[e].initPromise(),this.sendCommand(r[e]),i=r[e].inTransaction}let o=!0;this.leftRedirections===void 0&&(this.leftRedirections={});let s=function(){e.exec()},c=this.redis;if(c.handleError(t,this.leftRedirections,{moved:function(t,r){e.preferKey=r,c.slots[n[1]]?c.slots[n[1]][0]!==r&&(c.slots[n[1]]=[r]):c.slots[n[1]]=[r],c._groupsBySlot[n[1]]=c._groupsIds[c.slots[n[1]].join(`;`)],c.refreshSlotsCache(),e.exec()},ask:function(t,n){e.preferKey=n,e.exec()},tryagain:s,clusterDown:s,connectionClosed:s,maxRedirections:()=>{o=!1},defaults:()=>{o=!1}}),o)return}}let r=0;for(let e=0;e<this._queue.length-r;++e)this._queue[e+r].ignore&&(r+=1),this._result[e]=this._result[e+r];this.resolve(this._result.slice(0,this._result.length-r))}sendCommand(e){this._transactions>0&&(e.inTransaction=!0);let t=this._queue.length;return e.pipelineIndex=t,e.promise.then(e=>{this.fillResult([null,e],t)}).catch(e=>{this.fillResult([e],t)}),this._queue.push(e),this}addBatch(e){let t,n,r;for(let i=0;i<e.length;++i)t=e[i],n=t[0],r=t.slice(1),this[n].apply(this,r);return this}};e.default=l;let u=l.prototype.multi;l.prototype.multi=function(){return this._transactions+=1,u.apply(this,arguments)};let d=l.prototype.execBuffer;l.prototype.execBuffer=(0,i.deprecate)(function(){return this._transactions>0&&--this._transactions,d.apply(this,arguments)},`Pipeline#execBuffer: Use Pipeline#exec instead`),l.prototype.exec=function(e){if(this.isCluster&&!this.redis.slots.length)return this.redis.status===`wait`&&this.redis.connect().catch(o.noop),e&&!this.nodeifiedPromise&&(this.nodeifiedPromise=!0,(0,r.default)(this.promise,e)),this.redis.delayUntilReady(t=>{if(t){this.reject(t);return}this.exec(e)}),this.promise;if(this._transactions>0)return--this._transactions,d.apply(this,arguments);this.nodeifiedPromise||(this.nodeifiedPromise=!0,(0,r.default)(this.promise,e)),this._queue.length||this.resolve([]);let n;if(this.isCluster){let e=[];for(let n=0;n<this._queue.length;n++){let r=this._queue[n].getKeys();if(r.length&&e.push(r[0]),r.length&&t.generateMulti(r)<0)return this.reject(Error(`All the keys in a pipeline command should belong to the same slot`)),this.promise}if(e.length){if(n=c(this.redis,e),n<0)return this.reject(Error(`All keys in the pipeline should belong to the same slots allocation group`)),this.promise}else n=Math.random()*16384|0}let i=this;return a(),this.promise;function a(){let e=i.replyPending=i._queue.length,t;i.isCluster&&(t={slot:n,redis:i.redis.connectionPool.nodes.all[i.preferKey]});let r=``,a,o={isPipeline:!0,destination:i.isCluster?t:{redis:i.redis},write(t){typeof t==`string`?r+=t:(a||=[],r&&=(a.push(Buffer.from(r,`utf8`)),``),a.push(t)),--e||(a?(r&&a.push(Buffer.from(r,`utf8`)),o.destination.redis.stream.write(Buffer.concat(a))):o.destination.redis.stream.write(r),e=i._queue.length,r=``,a=void 0)}};for(let e=0;e<i._queue.length;++e)i.redis.sendCommand(i._queue[e],o,t);return i.promise}}})),TF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.addTransactionSupport=void 0;let t=gF(),n=tF(),r=wF();function i(e){e.pipeline=function(e){let t=new r.default(this);return Array.isArray(e)&&t.addBatch(e),t};let{multi:i}=e;e.multi=function(e,a){if(a===void 0&&!Array.isArray(e)&&(a=e,e=null),a&&a.pipeline===!1)return i.call(this);let o=new r.default(this);o.multi(),Array.isArray(e)&&o.addBatch(e);let s=o.exec;o.exec=function(e){if(this.isCluster&&!this.redis.slots.length)return this.redis.status===`wait`&&this.redis.connect().catch(t.noop),(0,n.default)(new Promise((e,t)=>{this.redis.delayUntilReady(n=>{if(n){t(n);return}this.exec(o).then(e,t)})}),e);if(this._transactions>0&&s.call(o),this.nodeifiedPromise)return s.call(o);let r=s.call(o);return(0,n.default)(r.then(function(e){let n=e[e.length-1];if(n===void 0)throw Error("Pipeline cannot be used to send any commands when the `exec()` has been called on it.");if(n[0]){n[0].previousErrors=[];for(let t=0;t<e.length-1;++t)e[t][0]&&n[0].previousErrors.push(e[t][0]);throw n[0]}return(0,t.wrapMultiResult)(n[1])}),e)};let{execBuffer:c}=o;return o.execBuffer=function(e){return this._transactions>0&&c.call(o),o.exec(e)},o};let{exec:a}=e;e.exec=function(e){return(0,n.default)(a.call(this).then(function(e){return Array.isArray(e)&&(e=(0,t.wrapMultiResult)(e)),e}),e)}}e.addTransactionSupport=i})),EF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});function t(e,t){Object.getOwnPropertyNames(t.prototype).forEach(n=>{Object.defineProperty(e.prototype,n,Object.getOwnPropertyDescriptor(t.prototype,n))})}e.default=t})),DF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.DEFAULT_CLUSTER_OPTIONS=void 0;let t=h(`dns`);e.DEFAULT_CLUSTER_OPTIONS={clusterRetryStrategy:e=>Math.min(100+e*2,2e3),enableOfflineQueue:!0,enableReadyCheck:!0,scaleReads:`master`,maxRedirections:16,retryDelayOnMoved:0,retryDelayOnFailover:100,retryDelayOnClusterDown:100,retryDelayOnTryAgain:100,slotsRefreshTimeout:1e3,useSRVRecords:!1,resolveSrv:t.resolveSrv,dnsLookup:t.lookup,enableAutoPipelining:!1,autoPipeliningIgnoredCommands:[],shardedSubscribers:!1}})),OF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.getConnectionName=e.weightSrvRecords=e.groupSrvRecords=e.getUniqueHostnamesFromOptions=e.normalizeNodeOptions=e.nodeKeyToRedisOptions=e.getNodeKey=void 0;let t=gF(),n=h(`net`);function r(e){return e.port=e.port||6379,e.host=e.host||`127.0.0.1`,e.host+`:`+e.port}e.getNodeKey=r;function i(e){let t=e.lastIndexOf(`:`);if(t===-1)throw Error(`Invalid node key ${e}`);return{host:e.slice(0,t),port:Number(e.slice(t+1))}}e.nodeKeyToRedisOptions=i;function a(e){return e.map(e=>{let n={};if(typeof e==`object`)Object.assign(n,e);else if(typeof e==`string`)Object.assign(n,(0,t.parseURL)(e));else if(typeof e==`number`)n.port=e;else throw Error(`Invalid argument `+e);return typeof n.port==`string`&&(n.port=parseInt(n.port,10)),delete n.db,n.port||=6379,n.host||=`127.0.0.1`,(0,t.resolveTLSProfile)(n)})}e.normalizeNodeOptions=a;function o(e){let t={};return e.forEach(e=>{t[e.host]=!0}),Object.keys(t).filter(e=>!(0,n.isIP)(e))}e.getUniqueHostnamesFromOptions=o;function s(e){let t={};for(let n of e)t.hasOwnProperty(n.priority)?(t[n.priority].totalWeight+=n.weight,t[n.priority].records.push(n)):t[n.priority]={totalWeight:n.weight,records:[n]};return t}e.groupSrvRecords=s;function c(e){if(e.records.length===1)return e.totalWeight=0,e.records.shift();let t=Math.floor(Math.random()*(e.totalWeight+e.records.length)),n=0;for(let[r,i]of e.records.entries())if(n+=1+i.weight,n>t)return e.totalWeight-=i.weight,e.records.splice(r,1),i}e.weightSrvRecords=c;function l(e,t){let n=`ioredis-cluster(${e})`;return t?`${n}:${t}`:n}e.getConnectionName=l})),kF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=OF(),n=gF(),r=XF(),i=(0,n.Debug)(`cluster:subscriber`);e.default=class{constructor(e,n,r=!1){this.connectionPool=e,this.emitter=n,this.isSharded=r,this.started=!1,this.subscriber=null,this.slotRange=[],this.onSubscriberEnd=()=>{if(!this.started){i(`subscriber has disconnected, but ClusterSubscriber is not started, so not reconnecting.`);return}i(`subscriber has disconnected, selecting a new one...`),this.selectSubscriber()},this.connectionPool.on(`-node`,(e,n)=>{!this.started||!this.subscriber||(0,t.getNodeKey)(this.subscriber.options)===n&&(i(`subscriber has left, selecting a new one...`),this.selectSubscriber())}),this.connectionPool.on(`+node`,()=>{!this.started||this.subscriber||(i(`a new node is discovered and there is no subscriber, selecting a new one...`),this.selectSubscriber())})}getInstance(){return this.subscriber}associateSlotRange(e){return this.isSharded&&(this.slotRange=e),this.slotRange}start(){this.started=!0,this.selectSubscriber(),i(`started`)}stop(){this.started=!1,this.subscriber&&=(this.subscriber.disconnect(),null)}isStarted(){return this.started}selectSubscriber(){let e=this.lastActiveSubscriber;e&&(e.off(`end`,this.onSubscriberEnd),e.disconnect()),this.subscriber&&(this.subscriber.off(`end`,this.onSubscriberEnd),this.subscriber.disconnect());let a=(0,n.sample)(this.connectionPool.getNodes());if(!a){i(`selecting subscriber failed since there is no node discovered in the cluster yet`),this.subscriber=null;return}let{options:o}=a;i(`selected a subscriber %s:%s`,o.host,o.port);let s=`subscriber`;this.isSharded&&(s=`ssubscriber`),this.subscriber=new r.default({port:o.port,host:o.host,username:o.username,password:o.password,enableReadyCheck:!0,connectionName:(0,t.getConnectionName)(s,o.connectionName),lazyConnect:!0,tls:o.tls,retryStrategy:null}),this.subscriber.on(`error`,n.noop),this.subscriber.on(`moved`,()=>{this.emitter.emit(`forceRefresh`)}),this.subscriber.once(`end`,this.onSubscriberEnd);let c={subscribe:[],psubscribe:[],ssubscribe:[]};if(e){let t=e.condition||e.prevCondition;t&&t.subscriber&&(c.subscribe=t.subscriber.channels(`subscribe`),c.psubscribe=t.subscriber.channels(`psubscribe`),c.ssubscribe=t.subscriber.channels(`ssubscribe`))}if(c.subscribe.length||c.psubscribe.length||c.ssubscribe.length){let e=0;for(let t of[`subscribe`,`psubscribe`,`ssubscribe`]){let n=c[t];if(n.length!=0)if(i(`%s %d channels`,t,n.length),t===`ssubscribe`)for(let r of n)e+=1,this.subscriber[t](r).then(()=>{--e||(this.lastActiveSubscriber=this.subscriber)}).catch(()=>{i(`failed to ssubscribe to channel: %s`,r)});else e+=1,this.subscriber[t](n).then(()=>{--e||(this.lastActiveSubscriber=this.subscriber)}).catch(()=>{i(`failed to %s %d channels`,t,n.length)})}}else this.lastActiveSubscriber=this.subscriber;for(let e of[`message`,`messageBuffer`])this.subscriber.on(e,(t,n)=>{this.emitter.emit(e,t,n)});for(let e of[`pmessage`,`pmessageBuffer`])this.subscriber.on(e,(t,n,r)=>{this.emitter.emit(e,t,n,r)});if(this.isSharded==1)for(let e of[`smessage`,`smessageBuffer`])this.subscriber.on(e,(t,n)=>{this.emitter.emit(e,t,n)})}}})),AF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=h(`events`),n=gF(),r=OF(),i=XF(),a=(0,n.Debug)(`cluster:connectionPool`);e.default=class extends t.EventEmitter{constructor(e){super(),this.redisOptions=e,this.nodes={all:{},master:{},slave:{}},this.specifiedOptions={}}getNodes(e=`all`){let t=this.nodes[e];return Object.keys(t).map(e=>t[e])}getInstanceByKey(e){return this.nodes.all[e]}getSampleInstance(e){let t=Object.keys(this.nodes[e]),r=(0,n.sample)(t);return this.nodes[e][r]}addMasterNode(e){let t=(0,r.getNodeKey)(e.options),n=this.createRedisFromOptions(e,e.options.readOnly);return e.options.readOnly?!1:(this.nodes.all[t]=n,this.nodes.master[t]=n,!0)}createRedisFromOptions(e,t){return new i.default((0,n.defaults)({retryStrategy:null,enableOfflineQueue:!0,readOnly:t},e,this.redisOptions,{lazyConnect:!0}))}findOrCreate(e,t=!1){let i=(0,r.getNodeKey)(e);t=!!t,this.specifiedOptions[i]?Object.assign(e,this.specifiedOptions[i]):this.specifiedOptions[i]=e;let o;return this.nodes.all[i]?(o=this.nodes.all[i],o.options.readOnly!==t&&(o.options.readOnly=t,a(`Change role of %s to %s`,i,t?`slave`:`master`),o[t?`readonly`:`readwrite`]().catch(n.noop),t?(delete this.nodes.master[i],this.nodes.slave[i]=o):(delete this.nodes.slave[i],this.nodes.master[i]=o))):(a(`Connecting to %s as %s`,i,t?`slave`:`master`),o=this.createRedisFromOptions(e,t),this.nodes.all[i]=o,this.nodes[t?`slave`:`master`][i]=o,o.once(`end`,()=>{this.removeNode(i),this.emit(`-node`,o,i),Object.keys(this.nodes.all).length||this.emit(`drain`)}),this.emit(`+node`,o,i),o.on(`error`,function(e){this.emit(`nodeError`,e,i)})),o}reset(e){a(`Reset with %O`,e);let t={};e.forEach(e=>{let n=(0,r.getNodeKey)(e);e.readOnly&&t[n]||(t[n]=e)}),Object.keys(this.nodes.all).forEach(e=>{t[e]||(a(`Disconnect %s because the node does not hold any slot`,e),this.nodes.all[e].disconnect(),this.removeNode(e))}),Object.keys(t).forEach(e=>{let n=t[e];this.findOrCreate(n,n.readOnly)})}removeNode(e){let{nodes:t}=this;t.all[e]&&(a(`Remove %s from the pool`,e),delete t.all[e]),delete t.master[e],delete t.slave[e]}}})),jF=u(((e,t)=>{function n(e,t){var t=t||{};this._capacity=t.capacity,this._head=0,this._tail=0,Array.isArray(e)?this._fromArray(e):(this._capacityMask=3,this._list=[,,,,])}n.prototype.peekAt=function(e){var t=e;if(t===(t|0)){var n=this.size();if(!(t>=n||t<-n))return t<0&&(t+=n),t=this._head+t&this._capacityMask,this._list[t]}},n.prototype.get=function(e){return this.peekAt(e)},n.prototype.peek=function(){if(this._head!==this._tail)return this._list[this._head]},n.prototype.peekFront=function(){return this.peek()},n.prototype.peekBack=function(){return this.peekAt(-1)},Object.defineProperty(n.prototype,`length`,{get:function(){return this.size()}}),n.prototype.size=function(){return this._head===this._tail?0:this._head<this._tail?this._tail-this._head:this._capacityMask+1-(this._head-this._tail)},n.prototype.unshift=function(e){if(arguments.length===0)return this.size();var t=this._list.length;return this._head=this._head-1+t&this._capacityMask,this._list[this._head]=e,this._tail===this._head&&this._growArray(),this._capacity&&this.size()>this._capacity&&this.pop(),this._head<this._tail?this._tail-this._head:this._capacityMask+1-(this._head-this._tail)},n.prototype.shift=function(){var e=this._head;if(e!==this._tail){var t=this._list[e];return this._list[e]=void 0,this._head=e+1&this._capacityMask,e<2&&this._tail>1e4&&this._tail<=this._list.length>>>2&&this._shrinkArray(),t}},n.prototype.push=function(e){if(arguments.length===0)return this.size();var t=this._tail;return this._list[t]=e,this._tail=t+1&this._capacityMask,this._tail===this._head&&this._growArray(),this._capacity&&this.size()>this._capacity&&this.shift(),this._head<this._tail?this._tail-this._head:this._capacityMask+1-(this._head-this._tail)},n.prototype.pop=function(){var e=this._tail;if(e!==this._head){var t=this._list.length;this._tail=e-1+t&this._capacityMask;var n=this._list[this._tail];return this._list[this._tail]=void 0,this._head<2&&e>1e4&&e<=t>>>2&&this._shrinkArray(),n}},n.prototype.removeOne=function(e){var t=e;if(t===(t|0)&&this._head!==this._tail){var n=this.size(),r=this._list.length;if(!(t>=n||t<-n)){t<0&&(t+=n),t=this._head+t&this._capacityMask;var i=this._list[t],a;if(e<n/2){for(a=e;a>0;a--)this._list[t]=this._list[t=t-1+r&this._capacityMask];this._list[t]=void 0,this._head=this._head+1+r&this._capacityMask}else{for(a=n-1-e;a>0;a--)this._list[t]=this._list[t=t+1+r&this._capacityMask];this._list[t]=void 0,this._tail=this._tail-1+r&this._capacityMask}return i}}},n.prototype.remove=function(e,t){var n=e,r,i=t;if(n===(n|0)&&this._head!==this._tail){var a=this.size(),o=this._list.length;if(!(n>=a||n<-a||t<1)){if(n<0&&(n+=a),t===1||!t)return r=[,],r[0]=this.removeOne(n),r;if(n===0&&n+t>=a)return r=this.toArray(),this.clear(),r;n+t>a&&(t=a-n);var s;for(r=Array(t),s=0;s<t;s++)r[s]=this._list[this._head+n+s&this._capacityMask];if(n=this._head+n&this._capacityMask,e+t===a){for(this._tail=this._tail-t+o&this._capacityMask,s=t;s>0;s--)this._list[n=n+1+o&this._capacityMask]=void 0;return r}if(e===0){for(this._head=this._head+t+o&this._capacityMask,s=t-1;s>0;s--)this._list[n=n+1+o&this._capacityMask]=void 0;return r}if(n<a/2){for(this._head=this._head+e+t+o&this._capacityMask,s=e;s>0;s--)this.unshift(this._list[n=n-1+o&this._capacityMask]);for(n=this._head-1+o&this._capacityMask;i>0;)this._list[n=n-1+o&this._capacityMask]=void 0,i--;e<0&&(this._tail=n)}else{for(this._tail=n,n=n+t+o&this._capacityMask,s=a-(t+e);s>0;s--)this.push(this._list[n++]);for(n=this._tail;i>0;)this._list[n=n+1+o&this._capacityMask]=void 0,i--}return this._head<2&&this._tail>1e4&&this._tail<=o>>>2&&this._shrinkArray(),r}}},n.prototype.splice=function(e,t){var n=e;if(n===(n|0)){var r=this.size();if(n<0&&(n+=r),!(n>r))if(arguments.length>2){var i,a,o,s=arguments.length,c=this._list.length,l=2;if(!r||n<r/2){for(a=Array(n),i=0;i<n;i++)a[i]=this._list[this._head+i&this._capacityMask];for(t===0?(o=[],n>0&&(this._head=this._head+n+c&this._capacityMask)):(o=this.remove(n,t),this._head=this._head+n+c&this._capacityMask);s>l;)this.unshift(arguments[--s]);for(i=n;i>0;i--)this.unshift(a[i-1])}else{a=Array(r-(n+t));var u=a.length;for(i=0;i<u;i++)a[i]=this._list[this._head+n+t+i&this._capacityMask];for(t===0?(o=[],n!=r&&(this._tail=this._head+n+c&this._capacityMask)):(o=this.remove(n,t),this._tail=this._tail-u+c&this._capacityMask);l<s;)this.push(arguments[l++]);for(i=0;i<u;i++)this.push(a[i])}return o}else return this.remove(n,t)}},n.prototype.clear=function(){this._list=Array(this._list.length),this._head=0,this._tail=0},n.prototype.isEmpty=function(){return this._head===this._tail},n.prototype.toArray=function(){return this._copyArray(!1)},n.prototype._fromArray=function(e){var t=e.length,n=this._nextPowerOf2(t);this._list=Array(n),this._capacityMask=n-1,this._tail=t;for(var r=0;r<t;r++)this._list[r]=e[r]},n.prototype._copyArray=function(e,t){var n=this._list,r=n.length,i=this.length;if(t|=i,t==i&&this._head<this._tail)return this._list.slice(this._head,this._tail);var a=Array(t),o=0,s;if(e||this._head>this._tail){for(s=this._head;s<r;s++)a[o++]=n[s];for(s=0;s<this._tail;s++)a[o++]=n[s]}else for(s=this._head;s<this._tail;s++)a[o++]=n[s];return a},n.prototype._growArray=function(){if(this._head!=0){var e=this._copyArray(!0,this._list.length<<1);this._tail=this._list.length,this._head=0,this._list=e}else this._tail=this._list.length,this._list.length<<=1;this._capacityMask=this._capacityMask<<1|1},n.prototype._shrinkArray=function(){this._list.length>>>=1,this._capacityMask>>>=1},n.prototype._nextPowerOf2=function(e){var t=1<<Math.log(e)/Math.log(2)+1;return Math.max(t,4)},t.exports=n})),MF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=gF(),n=jF(),r=(0,t.Debug)(`delayqueue`);e.default=class{constructor(){this.queues={},this.timeouts={}}push(e,t,r){let i=r.callback||process.nextTick;this.queues[e]||(this.queues[e]=new n),this.queues[e].push(t),this.timeouts[e]||(this.timeouts[e]=setTimeout(()=>{i(()=>{this.timeouts[e]=null,this.execute(e)})},r.timeout))}execute(e){let t=this.queues[e];if(!t)return;let{length:n}=t;if(n)for(r(`send %d commands in %s queue`,n,e),this.queues[e]=null;t.length>0;)t.shift()()}}})),NF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=OF(),n=gF(),r=XF(),i=(0,n.Debug)(`cluster:subscriberGroup:shardedSubscriber`),a={IDLE:`idle`,STARTING:`starting`,CONNECTED:`connected`,STOPPING:`stopping`,ENDED:`ended`},o={[a.IDLE]:[a.STARTING,a.STOPPING,a.ENDED],[a.STARTING]:[a.CONNECTED,a.STOPPING,a.ENDED],[a.CONNECTED]:[a.STOPPING,a.ENDED],[a.STOPPING]:[a.ENDED],[a.ENDED]:[]};e.default=class{constructor(e,i,o){this.emitter=e,this.status=a.IDLE,this.instance=null,this.connectPromise=null,this.messageListeners=new Map,this.onEnd=()=>{this.updateStatus(a.ENDED),this.emitter.emit(`-node`,this.instance,this.nodeKey)},this.onError=e=>{this.emitter.emit(`nodeError`,e,this.nodeKey)},this.onMoved=()=>{this.emitter.emit(`moved`)},this.instance=new r.default((0,n.defaults)({enableReadyCheck:!1,enableOfflineQueue:!0,connectionName:(0,t.getConnectionName)(`ssubscriber`,i.connectionName),retryStrategy:null,lazyConnect:!0},i,o)),this.lazyConnect=o?.lazyConnect??!0,this.nodeKey=(0,t.getNodeKey)(i),this.instance.on(`end`,this.onEnd),this.instance.on(`error`,this.onError),this.instance.on(`moved`,this.onMoved);for(let e of[`smessage`,`smessageBuffer`]){let t=(...t)=>{this.emitter.emit(e,...t)};this.messageListeners.set(e,t),this.instance.on(e,t)}}async start(){if(this.connectPromise)return this.connectPromise;if(!(this.status===a.STARTING||this.status===a.CONNECTED)){if(this.status===a.ENDED||!this.instance)throw Error(`Sharded subscriber ${this.nodeKey} cannot be restarted once ended.`);this.updateStatus(a.STARTING),this.connectPromise=this.instance.connect();try{await this.connectPromise,this.updateStatus(a.CONNECTED)}catch(e){throw this.updateStatus(a.ENDED),e}finally{this.connectPromise=null}}}stop(){this.updateStatus(a.STOPPING),this.instance&&=(this.instance.disconnect(),this.instance.removeAllListeners(),this.messageListeners.clear(),null),this.updateStatus(a.ENDED),i(`stopped %s`,this.nodeKey)}isStarted(){return[a.CONNECTED,a.STARTING].includes(this.status)}get subscriberStatus(){return this.status}isHealthy(){return(this.status===a.IDLE||this.status===a.CONNECTED||this.status===a.STARTING)&&this.instance!==null}getInstance(){return this.instance}getNodeKey(){return this.nodeKey}isLazyConnect(){return this.lazyConnect}updateStatus(e){if(this.status!==e){if(!o[this.status].includes(e)){i(`Invalid status transition for %s: %s -> %s`,this.nodeKey,this.status,e);return}this.status=e}}}})),PF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=gF(),n=OF(),r=aF(),i=NF(),a=(0,t.Debug)(`cluster:subscriberGroup`);var o=class e{constructor(t,n){this.subscriberGroupEmitter=t,this.options=n,this.shardedSubscribers=new Map,this.clusterSlots=[],this.subscriberToSlotsIndex=new Map,this.channels=new Map,this.failedAttemptsByNode=new Map,this.isResetting=!1,this.pendingReset=null,this.handleSubscriberConnectFailed=(t,n)=>{let r=(this.failedAttemptsByNode.get(n)||0)+1;this.failedAttemptsByNode.set(n,r);let i=Math.min(r,e.MAX_RETRY_ATTEMPTS),o=Math.min(e.BASE_BACKOFF_MS*2**i,e.MAX_BACKOFF_MS),s=Math.floor((Math.random()-.5)*(o*.5)),c=Math.max(0,o+s);a(`Failed to connect subscriber for %s. Refreshing slots in %dms`,n,c),this.subscriberGroupEmitter.emit(`subscriberConnectFailed`,{delay:c,error:t})},this.handleSubscriberConnectSucceeded=e=>{this.failedAttemptsByNode.delete(e)}}getResponsibleSubscriber(e){let t=this.clusterSlots[e][0],n=this.shardedSubscribers.get(t);return n&&n.subscriberStatus===`idle`&&n.start().then(()=>{this.handleSubscriberConnectSucceeded(n.getNodeKey())}).catch(e=>{this.handleSubscriberConnectFailed(e,n.getNodeKey())}),n}addChannels(e){let t=r(e[0]);for(let n of e)if(r(n)!==t)return-1;let n=this.channels.get(t);return n?this.channels.set(t,n.concat(e)):this.channels.set(t,e),Array.from(this.channels.values()).reduce((e,t)=>e+t.length,0)}removeChannels(e){let t=r(e[0]);for(let n of e)if(r(n)!==t)return-1;let n=this.channels.get(t);if(n){let r=n.filter(t=>!e.includes(t));this.channels.set(t,r)}return Array.from(this.channels.values()).reduce((e,t)=>e+t.length,0)}stop(){for(let e of this.shardedSubscribers.values())e.stop();this.pendingReset=null,this.shardedSubscribers.clear(),this.subscriberToSlotsIndex.clear()}start(){let e=[];for(let t of this.shardedSubscribers.values())this.shouldStartSubscriber(t)&&(e.push(t.start().then(()=>{this.handleSubscriberConnectSucceeded(t.getNodeKey())}).catch(e=>{this.handleSubscriberConnectFailed(e,t.getNodeKey())})),this.subscriberGroupEmitter.emit(`+subscriber`));return Promise.all(e)}async reset(e,t){if(this.isResetting){this.pendingReset={slots:e,nodes:t};return}this.isResetting=!0;try{let r=this._refreshSlots(e),o=this.hasUnhealthySubscribers();if(!r&&!o){a(`No topology change detected or failed subscribers. Skipping reset.`);return}for(let[e,t]of this.shardedSubscribers){if(this.subscriberToSlotsIndex.has(e)&&t.isHealthy()){a(`Skipping deleting subscriber for %s`,e);continue}a(`Removing subscriber for %s`,e),t.stop(),this.shardedSubscribers.delete(e),this.subscriberGroupEmitter.emit(`-subscriber`)}let s=[];for(let[e,r]of this.subscriberToSlotsIndex){let r=this.shardedSubscribers.get(e);if(r&&r.isHealthy()){a(`Skipping creating new subscriber for %s`,e),!r.isStarted()&&this.shouldStartSubscriber(r)&&s.push(r.start().then(()=>{this.handleSubscriberConnectSucceeded(e)}).catch(t=>{this.handleSubscriberConnectFailed(t,e)}));continue}r&&!r.isHealthy()&&(a(`Replacing subscriber for %s`,e),r.stop(),this.shardedSubscribers.delete(e),this.subscriberGroupEmitter.emit(`-subscriber`)),a(`Creating new subscriber for %s`,e);let o=t.find(t=>(0,n.getNodeKey)(t.options)===e);if(!o){a(`Failed to find node for key %s`,e);continue}let c=new i.default(this.subscriberGroupEmitter,o.options,this.options.redisOptions);this.shardedSubscribers.set(e,c),this.shouldStartSubscriber(c)&&s.push(c.start().then(()=>{this.handleSubscriberConnectSucceeded(e)}).catch(t=>{this.handleSubscriberConnectFailed(t,e)})),this.subscriberGroupEmitter.emit(`+subscriber`)}await Promise.all(s),this._resubscribe(),this.subscriberGroupEmitter.emit(`subscribersReady`)}finally{if(this.isResetting=!1,this.pendingReset){let{slots:e,nodes:t}=this.pendingReset;this.pendingReset=null,await this.reset(e,t)}}}_refreshSlots(e){if(this._slotsAreEqual(e)&&this.subscriberToSlotsIndex.size>0)return a(`Nothing to refresh because the new cluster map is equal to the previous one.`),!1;a(`Refreshing the slots of the subscriber group.`),this.subscriberToSlotsIndex=new Map;for(let t=0;t<e.length;t++){let n=e[t][0];this.subscriberToSlotsIndex.has(n)||this.subscriberToSlotsIndex.set(n,[]),this.subscriberToSlotsIndex.get(n).push(Number(t))}return this.clusterSlots=JSON.parse(JSON.stringify(e)),!0}_resubscribe(){this.shardedSubscribers&&this.shardedSubscribers.forEach((e,t)=>{let n=this.subscriberToSlotsIndex.get(t);n&&n.forEach(n=>{let r=e.getInstance(),i=this.channels.get(n);if(i&&i.length>0){if(!r||r.status===`end`)return;r.status===`ready`?r.ssubscribe(...i).catch(e=>{a(`Failed to ssubscribe on node %s: %s`,t,e)}):r.once(`ready`,()=>{r.ssubscribe(...i).catch(e=>{a(`Failed to ssubscribe on node %s: %s`,t,e)})})}})})}_slotsAreEqual(e){return this.clusterSlots===void 0?!1:JSON.stringify(this.clusterSlots)===JSON.stringify(e)}hasUnhealthySubscribers(){let e=Array.from(this.shardedSubscribers.values()).some(e=>!e.isHealthy()),t=Array.from(this.subscriberToSlotsIndex.keys()).some(e=>!this.shardedSubscribers.has(e));return e||t}shouldStartSubscriber(e){if(e.isStarted())return!1;if(!e.isLazyConnect())return!0;let t=this.subscriberToSlotsIndex.get(e.getNodeKey());return t?t.some(e=>{let t=this.channels.get(e);return!!(t&&t.length>0)}):!1}};e.default=o,o.MAX_RETRY_ATTEMPTS=10,o.MAX_BACKOFF_MS=2e3,o.BASE_BACKOFF_MS=100})),FF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=$P(),n=h(`events`),r=iF(),i=tF(),a=vF(),o=yF(),s=XF(),c=bF(),l=TF(),u=gF(),d=EF(),f=CF(),p=DF(),m=kF(),g=AF(),_=MF(),v=OF(),y=jF(),b=PF(),x=(0,u.Debug)(`cluster`),S=new WeakSet;var C=class e extends f.default{constructor(e,t={}){if(super(),this.slots=[],this._groupsIds={},this._groupsBySlot=Array(16384),this.isCluster=!0,this.retryAttempts=0,this.delayQueue=new _.default,this.offlineQueue=new y,this.isRefreshing=!1,this._refreshSlotsCacheCallbacks=[],this._autoPipelines=new Map,this._runningAutoPipelines=new Set,this._readyDelayedCallbacks=[],this.connectionEpoch=0,n.EventEmitter.call(this),this.startupNodes=e,this.options=(0,u.defaults)({},t,p.DEFAULT_CLUSTER_OPTIONS,this.options),this.options.shardedSubscribers&&this.createShardedSubscriberGroup(),this.options.redisOptions&&this.options.redisOptions.keyPrefix&&!this.options.keyPrefix&&(this.options.keyPrefix=this.options.redisOptions.keyPrefix),typeof this.options.scaleReads!=`function`&&[`all`,`master`,`slave`].indexOf(this.options.scaleReads)===-1)throw Error(`Invalid option scaleReads "`+this.options.scaleReads+`". Expected "all", "master", "slave" or a custom function`);this.connectionPool=new g.default(this.options.redisOptions),this.connectionPool.on(`-node`,(e,t)=>{this.emit(`-node`,e)}),this.connectionPool.on(`+node`,e=>{this.emit(`+node`,e)}),this.connectionPool.on(`drain`,()=>{this.setStatus(`close`)}),this.connectionPool.on(`nodeError`,(e,t)=>{this.emit(`node error`,e,t)}),this.subscriber=new m.default(this.connectionPool,this),this.options.scripts&&Object.entries(this.options.scripts).forEach(([e,t])=>{this.defineCommand(e,t)}),this.options.lazyConnect?this.setStatus(`wait`):this.connect().catch(e=>{x(`connecting failed: %s`,e)})}connect(){return new Promise((e,t)=>{if(this.status===`connecting`||this.status===`connect`||this.status===`ready`){t(Error(`Redis is already connecting/connected`));return}let n=++this.connectionEpoch;this.setStatus(`connecting`),this.resolveStartupNodeHostnames().then(i=>{if(this.connectionEpoch!==n){x(`discard connecting after resolving startup nodes because epoch not match: %d != %d`,n,this.connectionEpoch),t(new r.RedisError(`Connection is discarded because a new connection is made`));return}if(this.status!==`connecting`){x(`discard connecting after resolving startup nodes because the status changed to %s`,this.status),t(new r.RedisError(`Connection is aborted`));return}this.connectionPool.reset(i),this.options.shardedSubscribers&&this.shardedSubscribers.reset(this.slots,this.connectionPool.getNodes(`all`)).catch(e=>{x(`Error while starting subscribers: %s`,e)});let a=()=>{this.setStatus(`ready`),this.retryAttempts=0,this.executeOfflineCommands(),this.resetNodesRefreshInterval(),e()},c,l=()=>{this.invokeReadyDelayedCallbacks(void 0),this.removeListener(`close`,c),this.manuallyClosing=!1,this.setStatus(`connect`),this.options.enableReadyCheck?this.readyCheck((e,t)=>{e||t?(x(`Ready check failed (%s). Reconnecting...`,e||t),this.status===`connect`&&this.disconnect(!0)):a()}):a()};c=()=>{let e=Error(`None of startup nodes is available`);this.removeListener(`refresh`,l),this.invokeReadyDelayedCallbacks(e),t(e)},this.once(`refresh`,l),this.once(`close`,c),this.once(`close`,this.handleCloseEvent.bind(this)),this.refreshSlotsCache(e=>{e&&e.message===o.default.defaultMessage&&(s.default.prototype.silentEmit.call(this,`error`,e),this.connectionPool.reset([]))}),this.subscriber.start(),this.options.shardedSubscribers&&this.shardedSubscribers.start().catch(e=>{x(`Error while starting subscribers: %s`,e)})}).catch(e=>{this.setStatus(`close`),this.handleCloseEvent(e),this.invokeReadyDelayedCallbacks(e),t(e)})})}disconnect(e=!1){let t=this.status;this.setStatus(`disconnecting`),e||(this.manuallyClosing=!0),this.reconnectTimeout&&!e&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null,x(`Canceled reconnecting attempts`)),this.clearNodesRefreshInterval(),this.subscriber.stop(),this.options.shardedSubscribers&&this.shardedSubscribers.stop(),t===`wait`?(this.setStatus(`close`),this.handleCloseEvent()):this.connectionPool.reset([])}quit(e){let t=this.status;if(this.setStatus(`disconnecting`),this.manuallyClosing=!0,this.reconnectTimeout&&=(clearTimeout(this.reconnectTimeout),null),this.clearNodesRefreshInterval(),this.subscriber.stop(),this.options.shardedSubscribers&&this.shardedSubscribers.stop(),t===`wait`){let t=(0,i.default)(Promise.resolve(`OK`),e);return setImmediate(function(){this.setStatus(`close`),this.handleCloseEvent()}.bind(this)),t}return(0,i.default)(Promise.all(this.nodes().map(e=>e.quit().catch(e=>{if(e.message===u.CONNECTION_CLOSED_ERROR_MSG)return`OK`;throw e}))).then(()=>`OK`),e)}duplicate(t=[],n={}){return new e(t.length>0?t:this.startupNodes.slice(0),Object.assign({},this.options,n))}nodes(e=`all`){if(e!==`all`&&e!==`master`&&e!==`slave`)throw Error(`Invalid role "`+e+`". Expected "all", "master" or "slave"`);return this.connectionPool.getNodes(e)}delayUntilReady(e){this._readyDelayedCallbacks.push(e)}get autoPipelineQueueSize(){let e=0;for(let t of this._autoPipelines.values())e+=t.length;return e}refreshSlotsCache(e){if(e&&this._refreshSlotsCacheCallbacks.push(e),this.isRefreshing)return;this.isRefreshing=!0;let t=this,n=e=>{this.isRefreshing=!1;for(let t of this._refreshSlotsCacheCallbacks)t(e);this._refreshSlotsCacheCallbacks=[]},r=(0,u.shuffle)(this.connectionPool.getNodes()),i=null;function a(e){if(e===r.length)return n(new o.default(o.default.defaultMessage,i));let s=r[e],c=`${s.options.host}:${s.options.port}`;x(`getting slot cache from %s`,c),t.getInfoFromNode(s,function(r){switch(t.status){case`close`:case`end`:return n(Error(`Cluster is disconnected.`));case`disconnecting`:return n(Error(`Cluster is disconnecting.`))}r?(t.emit(`node error`,r,c),i=r,a(e+1)):(t.emit(`refresh`),n())})}a(0)}sendCommand(e,n,i){if(this.status===`wait`&&this.connect().catch(u.noop),this.status===`end`)return e.reject(Error(u.CONNECTION_CLOSED_ERROR_MSG)),e.promise;let o=this.options.scaleReads;o!==`master`&&(e.isReadOnly||(0,t.exists)(e.name)&&(0,t.hasFlag)(e.name,`readonly`)||(o=`master`));let s=i?i.slot:e.getSlot(),c={},l=this;if(!i&&!S.has(e)){S.add(e);let t=e.reject;e.reject=function(n){let r=d.bind(null,!0);l.handleError(n,c,{moved:function(t,n){x(`command %s is moved to %s`,e.name,n),s=Number(t),l.slots[t]?l.slots[t][0]=n:l.slots[t]=[n],l._groupsBySlot[t]=l._groupsIds[l.slots[t].join(`;`)],l.connectionPool.findOrCreate(l.natMapper(n)),d(),x(`refreshing slot caches... (triggered by MOVED error)`),l.refreshSlotsCache()},ask:function(t,n){x(`command %s is required to ask %s:%s`,e.name,n);let r=l.natMapper(n);l.connectionPool.findOrCreate(r),d(!1,`${r.host}:${r.port}`)},tryagain:r,clusterDown:r,connectionClosed:r,maxRedirections:function(n){t.call(e,n)},defaults:function(){t.call(e,n)}})}}d();function d(t,c){if(l.status===`end`){e.reject(new r.AbortError(`Cluster is ended.`));return}let d;if(l.status===`ready`||e.name===`cluster`){if(i&&i.redis)d=i.redis;else if(a.default.checkFlag(`ENTER_SUBSCRIBER_MODE`,e.name)||a.default.checkFlag(`EXIT_SUBSCRIBER_MODE`,e.name)){if(l.options.shardedSubscribers&&(e.name==`ssubscribe`||e.name==`sunsubscribe`)){let t=l.shardedSubscribers.getResponsibleSubscriber(s);if(!t){e.reject(new r.AbortError(`No sharded subscriber for slot: ${s}`));return}let n=-1;e.name==`ssubscribe`&&(n=l.shardedSubscribers.addChannels(e.getKeys())),e.name==`sunsubscribe`&&(n=l.shardedSubscribers.removeChannels(e.getKeys())),n===-1?e.reject(new r.AbortError(`Possible CROSSSLOT error: All channels must hash to the same slot`)):d=t.getInstance()}else d=l.subscriber.getInstance();if(!d){e.reject(new r.AbortError(`No subscriber for the cluster`));return}}else{if(!t){if(typeof s==`number`&&l.slots[s]){let t=l.slots[s];if(typeof o==`function`){let n=t.map(function(e){return l.connectionPool.getInstanceByKey(e)});d=o(n,e),Array.isArray(d)&&(d=(0,u.sample)(d)),d||=n[0]}else{let e;e=o===`all`?(0,u.sample)(t):o===`slave`&&t.length>1?(0,u.sample)(t,1):t[0],d=l.connectionPool.getInstanceByKey(e)}}c&&(d=l.connectionPool.getInstanceByKey(c),d.asking())}d||=(typeof o==`function`?null:l.connectionPool.getSampleInstance(o))||l.connectionPool.getSampleInstance(`all`)}i&&!i.redis&&(i.redis=d)}d?d.sendCommand(e,n):l.options.enableOfflineQueue?l.offlineQueue.push({command:e,stream:n,node:i}):e.reject(Error(`Cluster isn't ready and enableOfflineQueue options is false`))}return e.promise}sscanStream(e,t){return this.createScanStream(`sscan`,{key:e,options:t})}sscanBufferStream(e,t){return this.createScanStream(`sscanBuffer`,{key:e,options:t})}hscanStream(e,t){return this.createScanStream(`hscan`,{key:e,options:t})}hscanBufferStream(e,t){return this.createScanStream(`hscanBuffer`,{key:e,options:t})}zscanStream(e,t){return this.createScanStream(`zscan`,{key:e,options:t})}zscanBufferStream(e,t){return this.createScanStream(`zscanBuffer`,{key:e,options:t})}handleError(e,t,n){if(t.value===void 0?t.value=this.options.maxRedirections:--t.value,t.value<=0){n.maxRedirections(Error(`Too many Cluster redirections. Last error: `+e));return}let r=e.message.split(` `);if(r[0]===`MOVED`){let e=this.options.retryDelayOnMoved;e&&typeof e==`number`?this.delayQueue.push(`moved`,n.moved.bind(null,r[1],r[2]),{timeout:e}):n.moved(r[1],r[2])}else r[0]===`ASK`?n.ask(r[1],r[2]):r[0]===`TRYAGAIN`?this.delayQueue.push(`tryagain`,n.tryagain,{timeout:this.options.retryDelayOnTryAgain}):r[0]===`CLUSTERDOWN`&&this.options.retryDelayOnClusterDown>0?this.delayQueue.push(`clusterdown`,n.connectionClosed,{timeout:this.options.retryDelayOnClusterDown,callback:this.refreshSlotsCache.bind(this)}):e.message===u.CONNECTION_CLOSED_ERROR_MSG&&this.options.retryDelayOnFailover>0&&this.status===`ready`?this.delayQueue.push(`failover`,n.connectionClosed,{timeout:this.options.retryDelayOnFailover,callback:this.refreshSlotsCache.bind(this)}):n.defaults()}resetOfflineQueue(){this.offlineQueue=new y}clearNodesRefreshInterval(){this.slotsTimer&&=(clearTimeout(this.slotsTimer),null)}resetNodesRefreshInterval(){if(this.slotsTimer||!this.options.slotsRefreshInterval)return;let e=()=>{this.slotsTimer=setTimeout(()=>{x(`refreshing slot caches... (triggered by "slotsRefreshInterval" option)`),this.refreshSlotsCache(()=>{e()})},this.options.slotsRefreshInterval)};e()}setStatus(e){x(`status: %s -> %s`,this.status||`[empty]`,e),this.status=e,process.nextTick(()=>{this.emit(e)})}handleCloseEvent(e){var t;e&&x(`closed because %s`,e);let n;!this.manuallyClosing&&typeof this.options.clusterRetryStrategy==`function`&&(n=this.options.clusterRetryStrategy.call(this,++this.retryAttempts,e)),typeof n==`number`?(this.setStatus(`reconnecting`),this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=null,x(`Cluster is disconnected. Retrying after %dms`,n),this.connect().catch(function(e){x(`Got error %s when reconnecting. Ignoring...`,e)})},n)):(this.options.shardedSubscribers&&((t=this.subscriberGroupEmitter)==null||t.removeAllListeners()),this.setStatus(`end`),this.flushQueue(Error(`None of startup nodes is available`)))}flushQueue(e){let t;for(;t=this.offlineQueue.shift();)t.command.reject(e)}executeOfflineCommands(){if(this.offlineQueue.length){x(`send %d commands in offline queue`,this.offlineQueue.length);let e=this.offlineQueue;this.resetOfflineQueue();let t;for(;t=e.shift();)this.sendCommand(t.command,t.stream,t.node)}}natMapper(e){let t=typeof e==`string`?e:`${e.host}:${e.port}`,n=null;return this.options.natMap&&typeof this.options.natMap==`function`?n=this.options.natMap(t):this.options.natMap&&typeof this.options.natMap==`object`&&(n=this.options.natMap[t]),n?(x(`NAT mapping %s -> %O`,t,n),Object.assign({},n)):typeof e==`string`?(0,v.nodeKeyToRedisOptions)(e):e}getInfoFromNode(e,t){if(!e)return t(Error(`Node is disconnected`));let n=e.duplicate({enableOfflineQueue:!0,enableReadyCheck:!1,retryStrategy:null,connectionName:(0,v.getConnectionName)(`refresher`,this.options.redisOptions&&this.options.redisOptions.connectionName)});n.on(`error`,u.noop),n.cluster(`SLOTS`,(0,u.timeout)((e,r)=>{if(n.disconnect(),e)return x(`error encountered running CLUSTER.SLOTS: %s`,e),t(e);if(this.status===`disconnecting`||this.status===`close`||this.status===`end`){x(`ignore CLUSTER.SLOTS results (count: %d) since cluster status is %s`,r.length,this.status),t();return}let i=[];x(`cluster slots result count: %d`,r.length);for(let e=0;e<r.length;++e){let t=r[e],n=t[0],a=t[1],o=[];for(let e=2;e<t.length;e++){if(!t[e][0])continue;let n=this.natMapper({host:t[e][0],port:t[e][1]});n.readOnly=e!==2,i.push(n),o.push(n.host+`:`+n.port)}x(`cluster slots result [%d]: slots %d~%d served by %s`,e,n,a,o);for(let e=n;e<=a;e++)this.slots[e]=o}this._groupsIds=Object.create(null);let a=0;for(let e=0;e<16384;e++){let t=(this.slots[e]||[]).join(`;`);if(!t.length){this._groupsBySlot[e]=void 0;continue}this._groupsIds[t]||(this._groupsIds[t]=++a),this._groupsBySlot[e]=this._groupsIds[t]}this.connectionPool.reset(i),this.options.shardedSubscribers&&this.shardedSubscribers.reset(this.slots,this.connectionPool.getNodes(`all`)).catch(e=>{x(`Error while starting subscribers: %s`,e)}),t()},this.options.slotsRefreshTimeout))}invokeReadyDelayedCallbacks(e){for(let t of this._readyDelayedCallbacks)process.nextTick(t,e);this._readyDelayedCallbacks=[]}readyCheck(e){this.cluster(`INFO`,(t,n)=>{if(t)return e(t);if(typeof n!=`string`)return e();let r,i=n.split(`\r
|
|
235
235
|
`);for(let e=0;e<i.length;++e){let t=i[e].split(`:`);if(t[0]===`cluster_state`){r=t[1];break}}r===`fail`?(x(`cluster state not ok (%s)`,r),e(null,r)):e()})}resolveSrv(e){return new Promise((t,n)=>{this.options.resolveSrv(e,(e,r)=>{if(e)return n(e);let i=this,a=(0,v.groupSrvRecords)(r),o=Object.keys(a).sort((e,t)=>parseInt(e)-parseInt(t));function s(e){if(!o.length)return n(e);let r=a[o[0]],c=(0,v.weightSrvRecords)(r);r.records.length||o.shift(),i.dnsLookup(c.name).then(e=>t({host:e,port:c.port}),s)}s()})})}dnsLookup(e){return new Promise((t,n)=>{this.options.dnsLookup(e,(r,i)=>{r?(x(`failed to resolve hostname %s to IP: %s`,e,r.message),n(r)):(x(`resolved hostname %s to IP %s`,e,i),t(i))})})}async resolveStartupNodeHostnames(){if(!Array.isArray(this.startupNodes)||this.startupNodes.length===0)throw Error("`startupNodes` should contain at least one node.");let e=(0,v.normalizeNodeOptions)(this.startupNodes),t=(0,v.getUniqueHostnamesFromOptions)(e);if(t.length===0)return e;let n=await Promise.all(t.map((this.options.useSRVRecords?this.resolveSrv:this.dnsLookup).bind(this))),r=(0,u.zipMap)(t,n);return e.map(e=>{let t=r.get(e.host);return t?this.options.useSRVRecords?Object.assign({},e,t):Object.assign({},e,{host:t}):e})}createScanStream(e,{key:t,options:n={}}){return new c.default({objectMode:!0,key:t,redis:this,command:e,...n})}createShardedSubscriberGroup(){this.subscriberGroupEmitter=new n.EventEmitter,this.shardedSubscribers=new b.default(this.subscriberGroupEmitter,this.options);let e=e=>{e instanceof o.default&&this.disconnect(!0)};this.subscriberGroupEmitter.on(`-node`,(t,n)=>{this.emit(`-node`,t,n),this.refreshSlotsCache(e)}),this.subscriberGroupEmitter.on(`subscriberConnectFailed`,({delay:t,error:n})=>{this.emit(`error`,n),setTimeout(()=>{this.refreshSlotsCache(e)},t)}),this.subscriberGroupEmitter.on(`moved`,()=>{this.refreshSlotsCache(e)}),this.subscriberGroupEmitter.on(`-subscriber`,()=>{this.emit(`-subscriber`)}),this.subscriberGroupEmitter.on(`+subscriber`,()=>{this.emit(`+subscriber`)}),this.subscriberGroupEmitter.on(`nodeError`,(e,t)=>{this.emit(`nodeError`,e,t)}),this.subscriberGroupEmitter.on(`subscribersReady`,()=>{this.emit(`subscribersReady`)});for(let e of[`smessage`,`smessageBuffer`])this.subscriberGroupEmitter.on(e,(t,n,r)=>{this.emit(e,t,n,r)})}};(0,d.default)(C,n.EventEmitter),(0,l.addTransactionSupport)(C.prototype),e.default=C})),IF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=(0,gF().Debug)(`AbstractConnector`);e.default=class{constructor(e){this.connecting=!1,this.disconnectTimeout=e}check(e){return!0}disconnect(){if(this.connecting=!1,this.stream){let e=this.stream,n=setTimeout(()=>{t(`stream %s:%s still open, destroying it`,e.remoteAddress,e.remotePort),e.destroy()},this.disconnectTimeout);e.on(`close`,()=>clearTimeout(n)),e.end()}}}})),LF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=h(`net`),n=h(`tls`),r=gF(),i=IF();e.default=class extends i.default{constructor(e){super(e.disconnectTimeout),this.options=e}connect(e){let{options:i}=this;this.connecting=!0;let a;return`path`in i&&i.path?a={path:i.path}:(a={},`port`in i&&i.port!=null&&(a.port=i.port),`host`in i&&i.host!=null&&(a.host=i.host),`family`in i&&i.family!=null&&(a.family=i.family)),i.tls&&Object.assign(a,i.tls),new Promise((e,o)=>{process.nextTick(()=>{if(!this.connecting){o(Error(r.CONNECTION_CLOSED_ERROR_MSG));return}try{i.tls?this.stream=(0,n.connect)(a):this.stream=(0,t.createConnection)(a)}catch(e){o(e);return}this.stream.once(`error`,e=>{this.firstError=e}),e(this.stream)})})}}})),RF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});function t(e,t){return(e.host||`127.0.0.1`)===(t.host||`127.0.0.1`)&&(e.port||26379)===(t.port||26379)}e.default=class{constructor(e){this.cursor=0,this.sentinels=e.slice(0)}next(){let e=this.cursor>=this.sentinels.length;return{done:e,value:e?void 0:this.sentinels[this.cursor++]}}reset(e){e&&this.sentinels.length>1&&this.cursor!==1&&this.sentinels.unshift(...this.sentinels.splice(this.cursor-1)),this.cursor=0}add(e){for(let n=0;n<this.sentinels.length;n++)if(t(e,this.sentinels[n]))return!1;return this.sentinels.push(e),!0}toString(){return`${JSON.stringify(this.sentinels)} @${this.cursor}`}}})),zF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.FailoverDetector=void 0;let t=(0,gF().Debug)(`FailoverDetector`),n=`+switch-master`;e.FailoverDetector=class{constructor(e,t){this.isDisconnected=!1,this.connector=e,this.sentinels=t}cleanup(){this.isDisconnected=!0;for(let e of this.sentinels)e.client.disconnect()}async subscribe(){t(`Starting FailoverDetector`);let e=[];for(let r of this.sentinels){let i=r.client.subscribe(n).catch(e=>{t(`Failed to subscribe to failover messages on sentinel %s:%s (%s)`,r.address.host||`127.0.0.1`,r.address.port||26739,e.message)});e.push(i),r.client.on(`message`,e=>{!this.isDisconnected&&e===n&&this.disconnect()})}await Promise.all(e)}disconnect(){this.isDisconnected=!0,t(`Failover detected, disconnecting`),this.connector.disconnect()}}})),BF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.SentinelIterator=void 0;let t=h(`net`),n=gF(),r=h(`tls`),i=RF();e.SentinelIterator=i.default;let a=IF(),o=XF(),s=zF(),c=(0,n.Debug)(`SentinelConnector`);e.default=class extends a.default{constructor(e){if(super(e.disconnectTimeout),this.options=e,this.emitter=null,this.failoverDetector=null,!this.options.sentinels.length)throw Error(`Requires at least one sentinel to connect to.`);if(!this.options.name)throw Error(`Requires the name of master.`);this.sentinelIterator=new i.default(this.options.sentinels)}check(e){let t=!e.role||this.options.role===e.role;return t||(c(`role invalid, expected %s, but got %s`,this.options.role,e.role),this.sentinelIterator.next(),this.sentinelIterator.next(),this.sentinelIterator.reset(!0)),t}disconnect(){super.disconnect(),this.failoverDetector&&this.failoverDetector.cleanup()}connect(e){this.connecting=!0,this.retryAttempts=0;let i,a=async()=>{let o=this.sentinelIterator.next();if(o.done){this.sentinelIterator.reset(!1);let t=typeof this.options.sentinelRetryStrategy==`function`?this.options.sentinelRetryStrategy(++this.retryAttempts):null,n=typeof t==`number`?`All sentinels are unreachable. Retrying from scratch after ${t}ms.`:`All sentinels are unreachable and retry is disabled.`;i&&(n+=` Last error: ${i.message}`),c(n);let r=Error(n);if(typeof t==`number`)return e(`error`,r),await new Promise(e=>setTimeout(e,t)),a();throw r}let s=null,l=null;try{s=await this.resolve(o.value)}catch(e){l=e}if(!this.connecting)throw Error(n.CONNECTION_CLOSED_ERROR_MSG);let u=o.value.host+`:`+o.value.port;if(s)return c(`resolved: %s:%s from sentinel %s`,s.host,s.port,u),this.options.enableTLSForSentinelMode&&this.options.tls?(Object.assign(s,this.options.tls),this.stream=(0,r.connect)(s),this.stream.once(`secureConnect`,this.initFailoverDetector.bind(this))):(this.stream=(0,t.createConnection)(s),this.stream.once(`connect`,this.initFailoverDetector.bind(this))),this.stream.once(`error`,e=>{this.firstError=e}),this.stream;{let t=l?`failed to connect to sentinel `+u+` because `+l.message:`connected to sentinel `+u+` successfully, but got an invalid reply: `+s;return c(t),e(`sentinelError`,Error(t)),l&&(i=l),a()}};return a()}async updateSentinels(e){if(!this.options.updateSentinels)return;let t=await e.sentinel(`sentinels`,this.options.name);Array.isArray(t)&&(t.map(n.packObject).forEach(e=>{if((e.flags?e.flags.split(`,`):[]).indexOf(`disconnected`)===-1&&e.ip&&e.port){let t=this.sentinelNatResolve(u(e));this.sentinelIterator.add(t)&&c(`adding sentinel %s:%s`,t.host,t.port)}}),c(`Updated internal sentinels: %s`,this.sentinelIterator))}async resolveMaster(e){let t=await e.sentinel(`get-master-addr-by-name`,this.options.name);return await this.updateSentinels(e),this.sentinelNatResolve(Array.isArray(t)?{host:t[0],port:Number(t[1])}:null)}async resolveSlave(e){let t=await e.sentinel(`slaves`,this.options.name);if(!Array.isArray(t))return null;let r=t.map(n.packObject).filter(e=>e.flags&&!e.flags.match(/(disconnected|s_down|o_down)/));return this.sentinelNatResolve(l(r,this.options.preferredSlaves))}sentinelNatResolve(e){if(!e||!this.options.natMap)return e;let t=`${e.host}:${e.port}`,n=e;return typeof this.options.natMap==`function`?n=this.options.natMap(t)||e:typeof this.options.natMap==`object`&&(n=this.options.natMap[t]||e),n}connectToSentinel(e,t){return new o.default({port:e.port||26379,host:e.host,username:this.options.sentinelUsername||null,password:this.options.sentinelPassword||null,family:e.family||(`path`in this.options&&this.options.path?void 0:this.options.family),tls:this.options.sentinelTLS,retryStrategy:null,enableReadyCheck:!1,connectTimeout:this.options.connectTimeout,commandTimeout:this.options.sentinelCommandTimeout,...t})}async resolve(e){let t=this.connectToSentinel(e);t.on(`error`,d);try{return this.options.role===`slave`?await this.resolveSlave(t):await this.resolveMaster(t)}finally{t.disconnect()}}async initFailoverDetector(){var e;if(!this.options.failoverDetector)return;this.sentinelIterator.reset(!0);let t=[];for(;t.length<this.options.sentinelMaxConnections;){let{done:e,value:n}=this.sentinelIterator.next();if(e)break;let r=this.connectToSentinel(n,{lazyConnect:!0,retryStrategy:this.options.sentinelReconnectStrategy});r.on(`reconnecting`,()=>{var e;(e=this.emitter)==null||e.emit(`sentinelReconnecting`)}),t.push({address:n,client:r})}this.sentinelIterator.reset(!1),this.failoverDetector&&this.failoverDetector.cleanup(),this.failoverDetector=new s.FailoverDetector(this,t),await this.failoverDetector.subscribe(),(e=this.emitter)==null||e.emit(`failoverSubscribed`)}};function l(e,t){if(e.length===0)return null;let r;if(typeof t==`function`)r=t(e);else if(typeof t==`object`&&t){let n=Array.isArray(t)?t:[t];n.sort((e,t)=>(e.prio||=1,t.prio||=1,e.prio<t.prio?-1:e.prio>t.prio?1:0));for(let t=0;t<n.length;t++){for(let i=0;i<e.length;i++){let a=e[i];if(a.ip===n[t].ip&&a.port===n[t].port){r=a;break}}if(r)break}}return r||=(0,n.sample)(e),u(r)}function u(e){return{host:e.ip,port:Number(e.port)}}function d(){}})),VF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.SentinelConnector=e.StandaloneConnector=void 0,e.StandaloneConnector=LF().default,e.SentinelConnector=BF().default})),HF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=iF();e.default=class extends t.AbortError{constructor(e){let t=`Reached the max retries per request limit (which is ${e}). Refer to "maxRetriesPerRequest" option for details.`;super(t),Error.captureStackTrace(this,this.constructor)}get name(){return this.constructor.name}}})),UF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.MaxRetriesPerRequestError=void 0,e.MaxRetriesPerRequestError=HF().default})),WF=u(((e,t)=>{let n=h(`buffer`).Buffer,r=h(`string_decoder`).StringDecoder,i=new r,a=iF(),o=a.ReplyError,s=a.ParserError;var c=n.allocUnsafe(32*1024),l=0,u=null,d=0,f=0;function p(e){let t=e.buffer.length-1;var n=e.offset,r=0,i=1;for(e.buffer[n]===45&&(i=-1,n++);n<t;){let t=e.buffer[n++];if(t===13)return e.offset=n+1,i*r;r=r*10+(t-48)}}function m(e){let t=e.buffer.length-1;var n=e.offset,r=0,i=``;for(e.buffer[n]===45&&(i+=`-`,n++);n<t;){var a=e.buffer[n++];if(a===13)return e.offset=n+1,r!==0&&(i+=r),i;r>429496728?(i+=r*10+(a-48),r=0):a===48&&r===0?i+=0:r=r*10+(a-48)}}function g(e){let t=e.offset,n=e.buffer,r=n.length-1;for(var i=t;i<r;)if(n[i++]===13)return e.offset=i+1,e.optionReturnBuffers===!0?e.buffer.slice(t,i-1):e.buffer.toString(`utf8`,t,i-1)}function _(e){let t=e.buffer.length-1;for(var n=e.offset,r=0;n<t;){let t=e.buffer[n++];if(t===13)return e.offset=n+1,r;r=r*10+(t-48)}}function v(e){return e.optionStringNumbers===!0?m(e):p(e)}function y(e){let t=_(e);if(t===void 0)return;if(t<0)return null;let n=e.offset+t;if(n+2>e.buffer.length){e.bigStrSize=n+2,e.totalChunkSize=e.buffer.length,e.bufferCache.push(e.buffer);return}let r=e.offset;return e.offset=n+2,e.optionReturnBuffers===!0?e.buffer.slice(r,n):e.buffer.toString(`utf8`,r,n)}function b(e){var t=g(e);if(t!==void 0)return e.optionReturnBuffers===!0&&(t=t.toString()),new o(t)}function x(e,t){let n=new s(`Protocol error, got `+JSON.stringify(String.fromCharCode(t))+` as reply type byte`,JSON.stringify(e.buffer),e.offset);e.buffer=null,e.returnFatalError(n)}function S(e){let t=_(e);if(t!==void 0)return t<0?null:ee(e,Array(t),0)}function C(e,t,n){e.arrayCache.push(t),e.arrayPos.push(n)}function w(e){let t=e.arrayCache.pop();var n=e.arrayPos.pop();if(e.arrayCache.length){let r=w(e);if(r===void 0){C(e,t,n);return}t[n++]=r}return ee(e,t,n)}function ee(e,t,n){let r=e.buffer.length;for(;n<t.length;){let i=e.offset;if(e.offset>=r){C(e,t,n);return}let a=te(e,e.buffer[e.offset++]);if(a===void 0){e.arrayCache.length||e.bufferCache.length||(e.offset=i),C(e,t,n);return}t[n]=a,n++}return t}function te(e,t){switch(t){case 36:return y(e);case 43:return g(e);case 42:return S(e);case 58:return v(e);case 45:return b(e);default:return x(e,t)}}function T(){if(c.length>50*1024)if(d===1||f>d*2){let e=Math.floor(c.length/10),t=e<l?l:e;l=0,c=c.slice(t,c.length)}else f++,d--;else clearInterval(u),d=0,f=0,u=null}function E(e){if(c.length<e+l){let t=e>1024*1024*75?2:3;l>1024*1024*111&&(l=1024*1024*50),c=n.allocUnsafe(e*t+l),l=0,d++,u===null&&(u=setInterval(T,50))}}function ne(e){let t=e.bufferCache,n=e.offset;var r=t.length,a=e.bigStrSize-e.totalChunkSize;if(e.offset=a,a<=2){if(r===2)return t[0].toString(`utf8`,n,t[0].length+a-2);r--,a=t[t.length-2].length+a}for(var o=i.write(t[0].slice(n)),s=1;s<r-1;s++)o+=i.write(t[s]);return o+=i.end(t[s].slice(0,a-2)),o}function re(e){let t=e.bufferCache,n=e.offset,r=e.bigStrSize-n-2;var i=t.length,a=e.bigStrSize-e.totalChunkSize;if(e.offset=a,a<=2){if(i===2)return t[0].slice(n,t[0].length+a-2);i--,a=t[t.length-2].length+a}E(r);let o=l;t[0].copy(c,o,n,t[0].length),l+=t[0].length-n;for(var s=1;s<i-1;s++)t[s].copy(c,l),l+=t[s].length;return t[s].copy(c,l,0,a-2),l+=a-2,c.slice(o,l)}t.exports=class{constructor(e){if(!e)throw TypeError(`Options are mandatory.`);if(typeof e.returnError!=`function`||typeof e.returnReply!=`function`)throw TypeError(`The returnReply and returnError options have to be functions.`);this.setReturnBuffers(!!e.returnBuffers),this.setStringNumbers(!!e.stringNumbers),this.returnError=e.returnError,this.returnFatalError=e.returnFatalError||e.returnError,this.returnReply=e.returnReply,this.reset()}reset(){this.offset=0,this.buffer=null,this.bigStrSize=0,this.totalChunkSize=0,this.bufferCache=[],this.arrayCache=[],this.arrayPos=[]}setReturnBuffers(e){if(typeof e!=`boolean`)throw TypeError(`The returnBuffers argument has to be a boolean`);this.optionReturnBuffers=e}setStringNumbers(e){if(typeof e!=`boolean`)throw TypeError(`The stringNumbers argument has to be a boolean`);this.optionStringNumbers=e}execute(e){if(this.buffer===null)this.buffer=e,this.offset=0;else if(this.bigStrSize===0){let t=this.buffer.length,r=t-this.offset,i=n.allocUnsafe(r+e.length);if(this.buffer.copy(i,0,this.offset,t),e.copy(i,r,0,e.length),this.buffer=i,this.offset=0,this.arrayCache.length){let e=w(this);if(e===void 0)return;this.returnReply(e)}}else if(this.totalChunkSize+e.length>=this.bigStrSize){this.bufferCache.push(e);var t=this.optionReturnBuffers?re(this):ne(this);if(this.bigStrSize=0,this.bufferCache=[],this.buffer=e,this.arrayCache.length&&(this.arrayCache[0][this.arrayPos[0]++]=t,t=w(this),t===void 0))return;this.returnReply(t)}else{this.bufferCache.push(e),this.totalChunkSize+=e.length;return}for(;this.offset<this.buffer.length;){let e=this.offset,t=this.buffer[this.offset++],n=te(this,t);if(n===void 0){this.arrayCache.length||this.bufferCache.length||(this.offset=e);return}t===45?this.returnError(n):this.returnReply(n)}this.buffer=null}}})),GF=u(((e,t)=>{t.exports=WF()})),KF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.default=class{constructor(){this.set={subscribe:{},psubscribe:{},ssubscribe:{}}}add(e,n){this.set[t(e)][n]=!0}del(e,n){delete this.set[t(e)][n]}channels(e){return Object.keys(this.set[t(e)])}isEmpty(){return this.channels(`subscribe`).length===0&&this.channels(`psubscribe`).length===0&&this.channels(`ssubscribe`).length===0}};function t(e){return e===`unsubscribe`?`subscribe`:e===`punsubscribe`?`psubscribe`:e===`sunsubscribe`?`ssubscribe`:e}})),qF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=vF(),n=gF(),r=GF(),i=KF(),a=(0,n.Debug)(`dataHandler`);e.default=class{constructor(e,t){this.redis=e;let n=new r({stringNumbers:t.stringNumbers,returnBuffers:!0,returnError:e=>{this.returnError(e)},returnFatalError:e=>{this.returnFatalError(e)},returnReply:e=>{this.returnReply(e)}});e.stream.prependListener(`data`,e=>{n.execute(e)}),e.stream.resume()}returnFatalError(e){e.message+=`. Please report this.`,this.redis.recoverFromFatalError(e,e,{offlineQueue:!1})}returnError(e){let t=this.shiftCommand(e);if(t){if(e.command={name:t.command.name,args:t.command.args},t.command.name==`ssubscribe`&&e.message.includes(`MOVED`)){this.redis.emit(`moved`);return}this.redis.handleReconnection(e,t)}}returnReply(e){if(this.handleMonitorReply(e)||this.handleSubscriberReply(e))return;let n=this.shiftCommand(e);n&&(t.default.checkFlag(`ENTER_SUBSCRIBER_MODE`,n.command.name)?(this.redis.condition.subscriber=new i.default,this.redis.condition.subscriber.add(n.command.name,e[1].toString()),s(n.command,e[2])||this.redis.commandQueue.unshift(n)):t.default.checkFlag(`EXIT_SUBSCRIBER_MODE`,n.command.name)?c(n.command,e[2])||this.redis.commandQueue.unshift(n):n.command.resolve(e))}handleSubscriberReply(e){if(!this.redis.condition.subscriber)return!1;let t=Array.isArray(e)?e[0].toString():null;switch(a(`receive reply "%s" in subscriber mode`,t),t){case`message`:this.redis.listeners(`message`).length>0&&this.redis.emit(`message`,e[1].toString(),e[2]?e[2].toString():``),this.redis.emit(`messageBuffer`,e[1],e[2]);break;case`pmessage`:{let t=e[1].toString();this.redis.listeners(`pmessage`).length>0&&this.redis.emit(`pmessage`,t,e[2].toString(),e[3].toString()),this.redis.emit(`pmessageBuffer`,t,e[2],e[3]);break}case`smessage`:this.redis.listeners(`smessage`).length>0&&this.redis.emit(`smessage`,e[1].toString(),e[2]?e[2].toString():``),this.redis.emit(`smessageBuffer`,e[1],e[2]);break;case`ssubscribe`:case`subscribe`:case`psubscribe`:{let n=e[1].toString();this.redis.condition.subscriber.add(t,n);let r=this.shiftCommand(e);if(!r)return;s(r.command,e[2])||this.redis.commandQueue.unshift(r);break}case`sunsubscribe`:case`unsubscribe`:case`punsubscribe`:{let n=e[1]?e[1].toString():null;n&&this.redis.condition.subscriber.del(t,n);let r=e[2];Number(r)===0&&(this.redis.condition.subscriber=!1);let i=this.shiftCommand(e);if(!i)return;c(i.command,r)||this.redis.commandQueue.unshift(i);break}default:{let t=this.shiftCommand(e);if(!t)return;t.command.resolve(e)}}return!0}handleMonitorReply(e){if(this.redis.status!==`monitoring`)return!1;let t=e.toString();if(t===`OK`)return!1;let n=t.indexOf(` `),r=t.slice(0,n),i=t.indexOf(`"`),a=t.slice(i+1,-1).split(`" "`).map(e=>e.replace(/\\"/g,`"`)),o=t.slice(n+2,i-2).split(` `);return this.redis.emit(`monitor`,r,a,o[1],o[0]),!0}shiftCommand(e){let t=this.redis.commandQueue.shift();if(!t){let t=Error(`Command queue state error. If you can reproduce this, please report it.`+(e instanceof Error?` Last error: ${e.message}`:` Last reply: ${e.toString()}`));return this.redis.emit(`error`,t),null}return t}};let o=new WeakMap;function s(e,t){let n=o.has(e)?o.get(e):e.args.length;return--n,n<=0?(e.resolve(t),o.delete(e),!0):(o.set(e,n),!1)}function c(e,t){let n=o.has(e)?o.get(e):e.args.length;return n===0?Number(t)===0?(o.delete(e),e.resolve(t),!0):!1:(--n,n<=0?(e.resolve(t),!0):(o.set(e,n),!1))}})),JF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.readyHandler=e.errorHandler=e.closeHandler=e.connectHandler=void 0;let t=iF(),n=vF(),r=UF(),i=gF(),a=qF(),o=(0,i.Debug)(`connection`);function s(t){return function(){t.setStatus(`connect`),t.resetCommandQueue();let n=!1,{connectionEpoch:r}=t;t.condition.auth&&t.auth(t.condition.auth,function(e){r===t.connectionEpoch&&e&&(e.message.indexOf(`no password is set`)===-1?e.message.indexOf(`without any password configured for the default user`)===-1?e.message.indexOf(`wrong number of arguments for 'auth' command`)===-1?(n=!0,t.recoverFromFatalError(e,e)):console.warn(`[ERROR] The server returned "wrong number of arguments for 'auth' command". You are probably passing both username and password to Redis version 5 or below. You should only pass the 'password' option for Redis version 5 and under.`):console.warn("[WARN] This Redis server's `default` user does not require a password, but a password was supplied"):console.warn(`[WARN] Redis server does not require a password, but a password was supplied.`))}),t.condition.select&&t.select(t.condition.select).catch(e=>{t.silentEmit(`error`,e)}),new a.default(t,{stringNumbers:t.options.stringNumbers});let s=[];t.options.connectionName&&(o(`set the connection name [%s]`,t.options.connectionName),s.push(t.client(`setname`,t.options.connectionName).catch(i.noop))),t.options.disableClientInfo||(o(`set the client info`),s.push((0,i.getPackageMeta)().then(e=>t.client(`SETINFO`,`LIB-VER`,e.version).catch(i.noop)).catch(i.noop)),s.push(t.client(`SETINFO`,`LIB-NAME`,t.options?.clientInfoTag?`ioredis(${t.options.clientInfoTag})`:`ioredis`).catch(i.noop))),Promise.all(s).catch(i.noop).finally(()=>{t.options.enableReadyCheck||e.readyHandler(t)(),t.options.enableReadyCheck&&t._readyCheck(function(i,a){r===t.connectionEpoch&&(i?n||t.recoverFromFatalError(Error(`Ready check failed: `+i.message),i):t.connector.check(a)?e.readyHandler(t)():t.disconnect(!0))})})}}e.connectHandler=s;function c(e){let n=new t.AbortError(`Command aborted due to connection close`);return n.command={name:e.name,args:e.args},n}function l(e){let t=0;for(let n=0;n<e.length;){let r=e.peekAt(n)?.command,i=r.pipelineIndex;if((i===void 0||i===0)&&(t=0),i!==void 0&&i!==t++){e.remove(n,1),r.reject(c(r));continue}n++}}function u(e){for(let t=0;t<e.length;){let n=e.peekAt(t)?.command;if(n.name===`multi`)break;if(n.name===`exec`){e.remove(t,1),n.reject(c(n));break}n.inTransaction?(e.remove(t,1),n.reject(c(n))):t++}}function d(e){return function(){let n=e.status;if(e.setStatus(`close`),e.commandQueue.length&&l(e.commandQueue),e.offlineQueue.length&&u(e.offlineQueue),n===`ready`&&(e.prevCondition||=e.condition,e.commandQueue.length&&(e.prevCommandQueue=e.commandQueue)),e.manuallyClosing)return e.manuallyClosing=!1,o(`skip reconnecting since the connection is manually closed.`),t();if(typeof e.options.retryStrategy!=`function`)return o("skip reconnecting because `retryStrategy` is not a function"),t();let a=e.options.retryStrategy(++e.retryAttempts);if(typeof a!=`number`)return o("skip reconnecting because `retryStrategy` doesn't return a number"),t();o(`reconnect in %sms`,a),e.setStatus(`reconnecting`,a),e.reconnectTimeout=setTimeout(function(){e.reconnectTimeout=null,e.connect().catch(i.noop)},a);let{maxRetriesPerRequest:s}=e.options;typeof s==`number`&&(s<0?o(`maxRetriesPerRequest is negative, ignoring...`):e.retryAttempts%(s+1)===0&&(o(`reach maxRetriesPerRequest limitation, flushing command queue...`),e.flushQueue(new r.MaxRetriesPerRequestError(s))))};function t(){e.setStatus(`end`),e.flushQueue(Error(i.CONNECTION_CLOSED_ERROR_MSG))}}e.closeHandler=d;function f(e){return function(t){o(`error: %s`,t),e.silentEmit(`error`,t)}}e.errorHandler=f;function p(e){return function(){if(e.setStatus(`ready`),e.retryAttempts=0,e.options.monitor){e.call(`monitor`).then(()=>e.setStatus(`monitoring`),t=>e.emit(`error`,t));let{sendCommand:t}=e;e.sendCommand=function(r){return n.default.checkFlag(`VALID_IN_MONITOR_MODE`,r.name)?t.call(e,r):(r.reject(Error(`Connection is in monitoring mode, can't process commands.`)),r.promise)},e.once(`close`,function(){delete e.sendCommand});return}let t=e.prevCondition?e.prevCondition.select:e.condition.select;if(e.options.readOnly&&(o(`set the connection to readonly mode`),e.readonly().catch(i.noop)),e.prevCondition){let n=e.prevCondition;if(e.prevCondition=null,n.subscriber&&e.options.autoResubscribe){e.condition.select!==t&&(o(`connect to db [%d]`,t),e.select(t));let r=n.subscriber.channels(`subscribe`);r.length&&(o(`subscribe %d channels`,r.length),e.subscribe(r));let i=n.subscriber.channels(`psubscribe`);i.length&&(o(`psubscribe %d channels`,i.length),e.psubscribe(i));let a=n.subscriber.channels(`ssubscribe`);if(a.length){o(`ssubscribe %s`,a.length);for(let t of a)e.ssubscribe(t)}}}if(e.prevCommandQueue)if(e.options.autoResendUnfulfilledCommands)for(o(`resend %d unfulfilled commands`,e.prevCommandQueue.length);e.prevCommandQueue.length>0;){let t=e.prevCommandQueue.shift();t.select!==e.condition.select&&t.command.name!==`select`&&e.select(t.select),e.sendCommand(t.command,t.stream)}else e.prevCommandQueue=null;if(e.offlineQueue.length){o(`send %d commands in offline queue`,e.offlineQueue.length);let t=e.offlineQueue;for(e.resetOfflineQueue();t.length>0;){let n=t.shift();n.select!==e.condition.select&&n.command.name!==`select`&&e.select(n.select),e.sendCommand(n.command,n.stream)}}e.condition.select!==t&&(o(`connect to db [%d]`,t),e.select(t))}}e.readyHandler=p})),YF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.DEFAULT_REDIS_OPTIONS=void 0,e.DEFAULT_REDIS_OPTIONS={port:6379,host:`localhost`,family:0,connectTimeout:1e4,disconnectTimeout:2e3,retryStrategy:function(e){return Math.min(e*50,2e3)},keepAlive:0,noDelay:!0,connectionName:null,disableClientInfo:!1,clientInfoTag:void 0,sentinels:null,name:null,role:`master`,sentinelRetryStrategy:function(e){return Math.min(e*10,1e3)},sentinelReconnectStrategy:function(){return 6e4},natMap:null,enableTLSForSentinelMode:!1,updateSentinels:!0,failoverDetector:!1,username:null,password:null,db:0,enableOfflineQueue:!0,enableReadyCheck:!0,autoResubscribe:!0,autoResendUnfulfilledCommands:!0,lazyConnect:!1,keyPrefix:``,reconnectOnError:null,readOnly:!1,stringNumbers:!1,maxRetriesPerRequest:20,maxLoadingRetryTime:1e4,enableAutoPipelining:!1,autoPipeliningIgnoredCommands:[],sentinelMaxConnections:10,blockingTimeoutGrace:100}})),XF=u((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=$P(),n=h(`events`),r=tF(),i=FF(),a=vF(),o=VF(),s=BF(),c=JF(),l=YF(),u=bF(),d=TF(),f=gF(),p=EF(),m=CF(),g=cF(),_=jF(),v=(0,f.Debug)(`redis`);var y=class e extends m.default{constructor(e,t,r){if(super(),this.status=`wait`,this.isCluster=!1,this.reconnectTimeout=null,this.connectionEpoch=0,this.retryAttempts=0,this.manuallyClosing=!1,this._autoPipelines=new Map,this._runningAutoPipelines=new Set,this.parseOptions(e,t,r),n.EventEmitter.call(this),this.resetCommandQueue(),this.resetOfflineQueue(),this.options.Connector)this.connector=new this.options.Connector(this.options);else if(this.options.sentinels){let e=new s.default(this.options);e.emitter=this,this.connector=e}else this.connector=new o.StandaloneConnector(this.options);this.options.scripts&&Object.entries(this.options.scripts).forEach(([e,t])=>{this.defineCommand(e,t)}),this.options.lazyConnect?this.setStatus(`wait`):this.connect().catch(g.noop)}static createClient(...t){return new e(...t)}get autoPipelineQueueSize(){let e=0;for(let t of this._autoPipelines.values())e+=t.length;return e}connect(e){let t=new Promise((e,t)=>{if(this.status===`connecting`||this.status===`connect`||this.status===`ready`){t(Error(`Redis is already connecting/connected`));return}this.connectionEpoch+=1,this.setStatus(`connecting`);let{options:n}=this;this.condition={select:n.db,auth:n.username?[n.username,n.password]:n.password,subscriber:!1};let i=this;(0,r.default)(this.connector.connect(function(e,t){i.silentEmit(e,t)}),function(r,a){if(r){i.flushQueue(r),i.silentEmit(`error`,r),t(r),i.setStatus(`end`);return}let o=n.tls?`secureConnect`:`connect`;if(`sentinels`in n&&n.sentinels&&!n.enableTLSForSentinelMode&&(o=`connect`),i.stream=a,n.noDelay&&a.setNoDelay(!0),typeof n.keepAlive==`number`&&(a.connecting?a.once(o,()=>{a.setKeepAlive(!0,n.keepAlive)}):a.setKeepAlive(!0,n.keepAlive)),a.connecting){if(a.once(o,c.connectHandler(i)),n.connectTimeout){let e=!1;a.setTimeout(n.connectTimeout,function(){if(e)return;a.setTimeout(0),a.destroy();let t=Error(`connect ETIMEDOUT`);t.errorno=`ETIMEDOUT`,t.code=`ETIMEDOUT`,t.syscall=`connect`,c.errorHandler(i)(t)}),a.once(o,function(){e=!0,a.setTimeout(0)})}}else if(a.destroyed){let e=i.connector.firstError;e&&process.nextTick(()=>{c.errorHandler(i)(e)}),process.nextTick(c.closeHandler(i))}else process.nextTick(c.connectHandler(i));a.destroyed||(a.once(`error`,c.errorHandler(i)),a.once(`close`,c.closeHandler(i)));let s=function(){i.removeListener(`close`,l),e()};var l=function(){i.removeListener(`ready`,s),t(Error(f.CONNECTION_CLOSED_ERROR_MSG))};i.once(`ready`,s),i.once(`close`,l)})});return(0,r.default)(t,e)}disconnect(e=!1){e||(this.manuallyClosing=!0),this.reconnectTimeout&&!e&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.status===`wait`?c.closeHandler(this)():this.connector.disconnect()}end(){this.disconnect()}duplicate(t){return new e({...this.options,...t})}get mode(){return this.options.monitor?`monitor`:this.condition?.subscriber?`subscriber`:`normal`}monitor(e){let t=this.duplicate({monitor:!0,lazyConnect:!1});return(0,r.default)(new Promise(function(e,n){t.once(`error`,n),t.once(`monitoring`,function(){e(t)})}),e)}sendCommand(e,n){if(this.status===`wait`&&this.connect().catch(g.noop),this.status===`end`)return e.reject(Error(f.CONNECTION_CLOSED_ERROR_MSG)),e.promise;if(this.condition?.subscriber&&!a.default.checkFlag(`VALID_IN_SUBSCRIBER_MODE`,e.name))return e.reject(Error(`Connection in subscriber mode, only subscriber commands may be used`)),e.promise;typeof this.options.commandTimeout==`number`&&e.setTimeout(this.options.commandTimeout);let r=this.getBlockingTimeoutInMs(e),i=this.status===`ready`||!n&&this.status===`connect`&&(0,t.exists)(e.name,{caseInsensitive:!0})&&((0,t.hasFlag)(e.name,`loading`,{nameCaseInsensitive:!0})||a.default.checkFlag(`HANDSHAKE_COMMANDS`,e.name));if(this.stream&&this.stream.writable?this.stream._writableState&&this.stream._writableState.ended&&(i=!1):i=!1,i)v.enabled&&v(`write command[%s]: %d -> %s(%o)`,this._getDescription(),this.condition?.select,e.name,e.args),n?`isPipeline`in n&&n.isPipeline?n.write(e.toWritable(n.destination.redis.stream)):n.write(e.toWritable(n)):this.stream.write(e.toWritable(this.stream)),this.commandQueue.push({command:e,stream:n,select:this.condition.select}),r!==void 0&&e.setBlockingTimeout(r),a.default.checkFlag(`WILL_DISCONNECT`,e.name)&&(this.manuallyClosing=!0),this.options.socketTimeout!==void 0&&this.socketTimeoutTimer===void 0&&this.setSocketTimeout();else{if(!this.options.enableOfflineQueue)return e.reject(Error(`Stream isn't writeable and enableOfflineQueue options is false`)),e.promise;if(e.name===`quit`&&this.offlineQueue.length===0)return this.disconnect(),e.resolve(Buffer.from(`OK`)),e.promise;if(v.enabled&&v(`queue command[%s]: %d -> %s(%o)`,this._getDescription(),this.condition.select,e.name,e.args),this.offlineQueue.push({command:e,stream:n,select:this.condition.select}),a.default.checkFlag(`BLOCKING_COMMANDS`,e.name)){let t=this.getConfiguredBlockingTimeout();t!==void 0&&e.setBlockingTimeout(t)}}if(e.name===`select`&&(0,f.isInt)(e.args[0])){let t=parseInt(e.args[0],10);this.condition.select!==t&&(this.condition.select=t,this.emit(`select`,t),v(`switch to db [%d]`,this.condition.select))}return e.promise}getBlockingTimeoutInMs(e){if(!a.default.checkFlag(`BLOCKING_COMMANDS`,e.name))return;let t=this.getConfiguredBlockingTimeout();if(t===void 0)return;let n=e.extractBlockingTimeout();if(typeof n==`number`)return n>0?n+(this.options.blockingTimeoutGrace??l.DEFAULT_REDIS_OPTIONS.blockingTimeoutGrace):t;if(n===null)return t}getConfiguredBlockingTimeout(){if(typeof this.options.blockingTimeout==`number`&&this.options.blockingTimeout>0)return this.options.blockingTimeout}setSocketTimeout(){this.socketTimeoutTimer=setTimeout(()=>{this.stream.destroy(Error(`Socket timeout. Expecting data, but didn't receive any in ${this.options.socketTimeout}ms.`)),this.socketTimeoutTimer=void 0},this.options.socketTimeout),this.stream.once(`data`,()=>{clearTimeout(this.socketTimeoutTimer),this.socketTimeoutTimer=void 0,this.commandQueue.length!==0&&this.setSocketTimeout()})}scanStream(e){return this.createScanStream(`scan`,{options:e})}scanBufferStream(e){return this.createScanStream(`scanBuffer`,{options:e})}sscanStream(e,t){return this.createScanStream(`sscan`,{key:e,options:t})}sscanBufferStream(e,t){return this.createScanStream(`sscanBuffer`,{key:e,options:t})}hscanStream(e,t){return this.createScanStream(`hscan`,{key:e,options:t})}hscanBufferStream(e,t){return this.createScanStream(`hscanBuffer`,{key:e,options:t})}zscanStream(e,t){return this.createScanStream(`zscan`,{key:e,options:t})}zscanBufferStream(e,t){return this.createScanStream(`zscanBuffer`,{key:e,options:t})}silentEmit(e,t){let n;if(!(e===`error`&&(n=t,this.status===`end`||this.manuallyClosing&&n instanceof Error&&(n.message===f.CONNECTION_CLOSED_ERROR_MSG||n.syscall===`connect`||n.syscall===`read`))))return this.listeners(e).length>0?this.emit.apply(this,arguments):(n&&n instanceof Error&&console.error(`[ioredis] Unhandled error event:`,n.stack),!1)}recoverFromFatalError(e,t,n){this.flushQueue(t,n),this.silentEmit(`error`,t),this.disconnect(!0)}handleReconnection(e,t){let n=!1;switch(this.options.reconnectOnError&&!a.default.checkFlag(`IGNORE_RECONNECT_ON_ERROR`,t.command.name)&&(n=this.options.reconnectOnError(e)),n){case 1:case!0:this.status!==`reconnecting`&&this.disconnect(!0),t.command.reject(e);break;case 2:this.status!==`reconnecting`&&this.disconnect(!0),this.condition?.select!==t.select&&t.command.name!==`select`&&this.select(t.select),this.sendCommand(t.command);break;default:t.command.reject(e)}}_getDescription(){let e;return e=`path`in this.options&&this.options.path?this.options.path:this.stream&&this.stream.remoteAddress&&this.stream.remotePort?this.stream.remoteAddress+`:`+this.stream.remotePort:`host`in this.options&&this.options.host?this.options.host+`:`+this.options.port:``,this.options.connectionName&&(e+=` (${this.options.connectionName})`),e}resetCommandQueue(){this.commandQueue=new _}resetOfflineQueue(){this.offlineQueue=new _}parseOptions(...t){let n={},r=!1;for(let e=0;e<t.length;++e){let i=t[e];if(i!=null)if(typeof i==`object`)(0,g.defaults)(n,i);else if(typeof i==`string`)(0,g.defaults)(n,(0,f.parseURL)(i)),i.startsWith(`rediss://`)&&(r=!0);else if(typeof i==`number`)n.port=i;else throw Error(`Invalid argument `+i)}r&&(0,g.defaults)(n,{tls:!0}),(0,g.defaults)(n,e.defaultOptions),typeof n.port==`string`&&(n.port=parseInt(n.port,10)),typeof n.db==`string`&&(n.db=parseInt(n.db,10)),this.options=(0,f.resolveTLSProfile)(n)}setStatus(e,t){v.enabled&&v(`status[%s]: %s -> %s`,this._getDescription(),this.status||`[empty]`,e),this.status=e,process.nextTick(this.emit.bind(this,e,t))}createScanStream(e,{key:t,options:n={}}){return new u.default({objectMode:!0,key:t,redis:this,command:e,...n})}flushQueue(e,t){t=(0,g.defaults)({},t,{offlineQueue:!0,commandQueue:!0});let n;if(t.offlineQueue)for(;n=this.offlineQueue.shift();)n.command.reject(e);if(t.commandQueue&&this.commandQueue.length>0)for(this.stream&&this.stream.removeAllListeners(`data`);n=this.commandQueue.shift();)n.command.reject(e)}_readyCheck(e){let t=this;this.info(function(n,r){if(n)return n.message&&n.message.includes(`NOPERM`)?(console.warn(`Skipping the ready check because INFO command fails: "${n.message}". You can disable ready check with "enableReadyCheck". More: https://github.com/luin/ioredis/wiki/Disable-ready-check.`),e(null,{})):e(n);if(typeof r!=`string`)return e(null,r);let i={},a=r.split(`\r
|
|
236
|
-
`);for(let e=0;e<a.length;++e){let[t,...n]=a[e].split(`:`),r=n.join(`:`);r&&(i[t]=r)}if(!i.loading||i.loading===`0`)e(null,i);else{let n=(i.loading_eta_seconds||1)*1e3,r=t.options.maxLoadingRetryTime&&t.options.maxLoadingRetryTime<n?t.options.maxLoadingRetryTime:n;v(`Redis server still loading, trying again in `+r+`ms`),setTimeout(function(){t._readyCheck(e)},r)}}).catch(g.noop)}};y.Cluster=i.default,y.Command=a.default,y.defaultOptions=l.DEFAULT_REDIS_OPTIONS,(0,p.default)(y,n.EventEmitter),(0,d.addTransactionSupport)(y.prototype),e.default=y})),ZF=u(((e,t)=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.print=e.ReplyError=e.SentinelIterator=e.SentinelConnector=e.AbstractConnector=e.Pipeline=e.ScanStream=e.Command=e.Cluster=e.Redis=e.default=void 0,e=t.exports=XF().default;var n=XF();Object.defineProperty(e,`default`,{enumerable:!0,get:function(){return n.default}});var r=XF();Object.defineProperty(e,`Redis`,{enumerable:!0,get:function(){return r.default}});var i=FF();Object.defineProperty(e,`Cluster`,{enumerable:!0,get:function(){return i.default}});var a=vF();Object.defineProperty(e,`Command`,{enumerable:!0,get:function(){return a.default}});var o=bF();Object.defineProperty(e,`ScanStream`,{enumerable:!0,get:function(){return o.default}});var s=wF();Object.defineProperty(e,`Pipeline`,{enumerable:!0,get:function(){return s.default}});var c=IF();Object.defineProperty(e,`AbstractConnector`,{enumerable:!0,get:function(){return c.default}});var l=BF();Object.defineProperty(e,`SentinelConnector`,{enumerable:!0,get:function(){return l.default}}),Object.defineProperty(e,`SentinelIterator`,{enumerable:!0,get:function(){return l.SentinelIterator}}),e.ReplyError=iF().ReplyError,Object.defineProperty(e,`Promise`,{get(){return console.warn(`ioredis v5 does not support plugging third-party Promise library anymore. Native Promise will be used.`),Promise},set(e){console.warn(`ioredis v5 does not support plugging third-party Promise library anymore. Native Promise will be used.`)}});function u(e,t){e?console.log(`Error: `+e):console.log(`Reply: `+t)}e.print=u}))();const QF=e=>{let t=process.env.REDIS_HOST,n=Number(process.env.REDIS_PORT??6379),r=process.env.CHANNEL;if(!t||!r)return console.warn(`Relay disabled: missing REDIS_HOST or CHANNEL`),{async stop(){}};let i=new ZF.Redis({host:t,port:n,tls:{},keepAlive:0,noDelay:!0,enableReadyCheck:!1,connectTimeout:5e3,retryStrategy(e){return e>20?null:Math.min(e*500,5e3)}});return i.on(`error`,e=>{console.error(`Relay redis error`,e)}),i.on(`end`,()=>{console.error(`Relay redis connection ended`),process.exit(1)}),i.subscribe(r).catch(e=>{console.error(`Relay subscribe failed`,e),process.exit(1)}),i.on(`message`,(t,n)=>{let r;try{r=Le(n)}catch{return}if(typeof r!=`object`||!r||!(`topic`in r)||typeof r.topic!=`string`||!(`event`in r)||typeof r.event!=`string`)return;let i=`payload`in r&&typeof r.payload==`string`?r.payload:``;e.publish(r.topic,`${r.event} ${i}`)}),{async stop(){await i.quit().catch(()=>{})}}},$F=Number(process.env.PORT??3e3),eI=process.env.ORIGIN_SECRET,tI=(e,t)=>{let n=e.headers.get(`x-forwarded-for`);if(n){let e=n.split(`,`).map(e=>e.trim()).filter(Boolean);return e.length>=2?e[e.length-2]:e[0]}return t.requestIP(e)?.address},nI=Bun.serve({port:$F,routes:{"/health":()=>new Response(`ok`),"/ws":(e,n)=>{if(eI&&e.headers.get(`x-origin-secret`)!==eI)return new Response(`Forbidden`,{status:403});let r=tI(e,n);if(!r)return new Response(`Unable to determine the client address`,{status:400});if(!n.upgrade(e,{data:{id:t(),ip:r,authenticated:!1,allowed:[]}}))return new Response(`Upgrade failed`,{status:500})}},websocket:{data:{},sendPings:!0,idleTimeout:15,perMessageDeflate:!
|
|
236
|
+
`);for(let e=0;e<a.length;++e){let[t,...n]=a[e].split(`:`),r=n.join(`:`);r&&(i[t]=r)}if(!i.loading||i.loading===`0`)e(null,i);else{let n=(i.loading_eta_seconds||1)*1e3,r=t.options.maxLoadingRetryTime&&t.options.maxLoadingRetryTime<n?t.options.maxLoadingRetryTime:n;v(`Redis server still loading, trying again in `+r+`ms`),setTimeout(function(){t._readyCheck(e)},r)}}).catch(g.noop)}};y.Cluster=i.default,y.Command=a.default,y.defaultOptions=l.DEFAULT_REDIS_OPTIONS,(0,p.default)(y,n.EventEmitter),(0,d.addTransactionSupport)(y.prototype),e.default=y})),ZF=u(((e,t)=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.print=e.ReplyError=e.SentinelIterator=e.SentinelConnector=e.AbstractConnector=e.Pipeline=e.ScanStream=e.Command=e.Cluster=e.Redis=e.default=void 0,e=t.exports=XF().default;var n=XF();Object.defineProperty(e,`default`,{enumerable:!0,get:function(){return n.default}});var r=XF();Object.defineProperty(e,`Redis`,{enumerable:!0,get:function(){return r.default}});var i=FF();Object.defineProperty(e,`Cluster`,{enumerable:!0,get:function(){return i.default}});var a=vF();Object.defineProperty(e,`Command`,{enumerable:!0,get:function(){return a.default}});var o=bF();Object.defineProperty(e,`ScanStream`,{enumerable:!0,get:function(){return o.default}});var s=wF();Object.defineProperty(e,`Pipeline`,{enumerable:!0,get:function(){return s.default}});var c=IF();Object.defineProperty(e,`AbstractConnector`,{enumerable:!0,get:function(){return c.default}});var l=BF();Object.defineProperty(e,`SentinelConnector`,{enumerable:!0,get:function(){return l.default}}),Object.defineProperty(e,`SentinelIterator`,{enumerable:!0,get:function(){return l.SentinelIterator}}),e.ReplyError=iF().ReplyError,Object.defineProperty(e,`Promise`,{get(){return console.warn(`ioredis v5 does not support plugging third-party Promise library anymore. Native Promise will be used.`),Promise},set(e){console.warn(`ioredis v5 does not support plugging third-party Promise library anymore. Native Promise will be used.`)}});function u(e,t){e?console.log(`Error: `+e):console.log(`Reply: `+t)}e.print=u}))();const QF=e=>{let t=process.env.REDIS_HOST,n=Number(process.env.REDIS_PORT??6379),r=process.env.CHANNEL;if(!t||!r)return console.warn(`Relay disabled: missing REDIS_HOST or CHANNEL`),{async stop(){}};let i=new ZF.Redis({host:t,port:n,tls:{},keepAlive:0,noDelay:!0,enableReadyCheck:!1,connectTimeout:5e3,retryStrategy(e){return e>20?null:Math.min(e*500,5e3)}});return i.on(`error`,e=>{console.error(`Relay redis error`,e)}),i.on(`end`,()=>{console.error(`Relay redis connection ended`),process.exit(1)}),i.subscribe(r).catch(e=>{console.error(`Relay subscribe failed`,e),process.exit(1)}),i.on(`message`,(t,n)=>{let r;try{r=Le(n)}catch{return}if(typeof r!=`object`||!r||!(`topic`in r)||typeof r.topic!=`string`||!(`event`in r)||typeof r.event!=`string`)return;let i=`payload`in r&&typeof r.payload==`string`?r.payload:``;e.publish(r.topic,`${r.event} ${i}`)}),{async stop(){await i.quit().catch(()=>{})}}},$F=Number(process.env.PORT??3e3),eI=process.env.ORIGIN_SECRET,tI=(e,t)=>{let n=e.headers.get(`x-forwarded-for`);if(n){let e=n.split(`,`).map(e=>e.trim()).filter(Boolean);return e.length>=2?e[e.length-2]:e[0]}return t.requestIP(e)?.address},nI=Bun.serve({port:$F,routes:{"/health":()=>new Response(`ok`),"/ws":(e,n)=>{if(eI&&e.headers.get(`x-origin-secret`)!==eI)return new Response(`Forbidden`,{status:403});let r=tI(e,n);if(!r)return new Response(`Unable to determine the client address`,{status:400});if(!n.upgrade(e,{data:{id:t(),ip:r,authenticated:!1,allowed:[]}}))return new Response(`Upgrade failed`,{status:500})}},websocket:{data:{},sendPings:!0,idleTimeout:15,perMessageDeflate:!1,open(e){e.data.authTimeout=setTimeout(()=>{e.close(4001,`Authentication timeout`)},1e4)},async message(e,t){if(typeof t!=`string`){e.close(4e3,`Invalid message payload`);return}if(t===`PING`){e.send(`PONG`);return}let[n,...r]=t.split(` `);if(!e.data.authenticated){if(n!==`AUTH`||e.data.authenticating){e.close(4001,`Not authenticated`);return}e.data.authenticating=!0;let t=r.join(` `),i=await ZP(t===``?void 0:t);if(e.readyState!==WebSocket.OPEN)return;if(!i.authorized){e.close(4001,i.reason);return}clearTimeout(e.data.authTimeout),e.data.authenticated=!0,e.data.authenticating=!1,e.data.context=i.context,e.data.allowed=i.allowed,e.sendText(`ACK`),fd(e);return}let i=r.join(` `).split(`,`);if(n===`SUB`){md(e,i);return}if(n===`UNSUB`){hd(e,i);return}e.close(4e3,`Invalid message payload`)},close(e){clearTimeout(e.data.authTimeout),pd(e)}}}),rI=QF(nI);process.on(`SIGTERM`,async()=>{nI.stop(),await rI.stop(),process.exit(0)}),console.log(`Socket server running on port ${$F}`);export{};
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -89,20 +89,20 @@
|
|
|
89
89
|
"zod-to-json-schema": "^3.24.3",
|
|
90
90
|
"@awsless/big-float": "^0.1.7",
|
|
91
91
|
"@awsless/cloudwatch": "^0.0.1",
|
|
92
|
+
"@awsless/dynamodb": "^0.3.21",
|
|
92
93
|
"@awsless/duration": "^0.0.4",
|
|
93
94
|
"@awsless/json": "^0.0.11",
|
|
94
95
|
"@awsless/iot": "^0.0.5",
|
|
95
96
|
"@awsless/lambda": "^0.0.44",
|
|
96
|
-
"@awsless/dynamodb": "^0.3.21",
|
|
97
|
-
"@awsless/size": "^0.0.2",
|
|
98
97
|
"@awsless/redis": "^0.1.13",
|
|
99
98
|
"@awsless/s3": "^0.0.21",
|
|
100
|
-
"@awsless/sns": "^0.0.10",
|
|
101
99
|
"@awsless/scheduler": "^0.0.4",
|
|
100
|
+
"@awsless/sns": "^0.0.10",
|
|
102
101
|
"@awsless/sqs": "^0.0.24",
|
|
103
102
|
"@awsless/validate": "^0.1.7",
|
|
104
103
|
"@awsless/weak-cache": "^0.0.1",
|
|
105
104
|
"awsless": "^0.0.13",
|
|
105
|
+
"@awsless/size": "^0.0.2",
|
|
106
106
|
"@awsless/clui": "^0.0.8",
|
|
107
107
|
"@awsless/ts-file-cache": "^0.0.16"
|
|
108
108
|
},
|