@libp2p/mplex 9.0.0-fdd80820 → 9.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,25 +1,25 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PMplex = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PMplex=(()=>{var Ui=Object.create;var be=Object.defineProperty;var qi=Object.getOwnPropertyDescriptor;var zi=Object.getOwnPropertyNames;var $i=Object.getPrototypeOf,Vi=Object.prototype.hasOwnProperty;var E=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),M=(i,e)=>{for(var t in e)be(i,t,{get:e[t],enumerable:!0})},Pt=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of zi(e))!Vi.call(i,n)&&n!==t&&be(i,n,{get:()=>e[n],enumerable:!(r=qi(e,n))||r.enumerable});return i};var ke=(i,e,t)=>(t=i!=null?Ui($i(i)):{},Pt(e||!i||!i.__esModule?be(t,"default",{value:i,enumerable:!0}):t,i)),Wi=i=>Pt(be({},"__esModule",{value:!0}),i);var Bt=E((ko,Dt)=>{var j=1e3,H=j*60,Q=H*60,K=Q*24,Ki=K*7,Gi=K*365.25;Dt.exports=function(i,e){e=e||{};var t=typeof i;if(t==="string"&&i.length>0)return ji(i);if(t==="number"&&isFinite(i))return e.long?Qi(i):Hi(i);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(i))};function ji(i){if(i=String(i),!(i.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(i);if(e){var t=parseFloat(e[1]),r=(e[2]||"ms").toLowerCase();switch(r){case"years":case"year":case"yrs":case"yr":case"y":return t*Gi;case"weeks":case"week":case"w":return t*Ki;case"days":case"day":case"d":return t*K;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Q;case"minutes":case"minute":case"mins":case"min":case"m":return t*H;case"seconds":case"second":case"secs":case"sec":case"s":return t*j;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function Hi(i){var e=Math.abs(i);return e>=K?Math.round(i/K)+"d":e>=Q?Math.round(i/Q)+"h":e>=H?Math.round(i/H)+"m":e>=j?Math.round(i/j)+"s":i+"ms"}function Qi(i){var e=Math.abs(i);return e>=K?ye(i,e,K,"day"):e>=Q?ye(i,e,Q,"hour"):e>=H?ye(i,e,H,"minute"):e>=j?ye(i,e,j,"second"):i+" ms"}function ye(i,e,t,r){var n=e>=t*1.5;return Math.round(i/t)+" "+r+(n?"s":"")}});var Ft=E((vo,Ot)=>{function Xi(i){t.debug=t,t.default=t,t.coerce=c,t.disable=s,t.enable=n,t.enabled=o,t.humanize=Bt(),t.destroy=u,Object.keys(i).forEach(l=>{t[l]=i[l]}),t.names=[],t.skips=[],t.formatters={};function e(l){let h=0;for(let p=0;p<l.length;p++)h=(h<<5)-h+l.charCodeAt(p),h|=0;return t.colors[Math.abs(h)%t.colors.length]}t.selectColor=e;function t(l){let h,p=null,_,f;function d(...m){if(!d.enabled)return;let b=d,w=Number(new Date),x=w-(h||w);b.diff=x,b.prev=h,b.curr=w,h=w,m[0]=t.coerce(m[0]),typeof m[0]!="string"&&m.unshift("%O");let g=0;m[0]=m[0].replace(/%([a-zA-Z%])/g,(I,S)=>{if(I==="%%")return"%";g++;let A=t.formatters[S];if(typeof A=="function"){let B=m[g];I=A.call(b,B),m.splice(g,1),g--}return I}),t.formatArgs.call(b,m),(b.log||t.log).apply(b,m)}return d.namespace=l,d.useColors=t.useColors(),d.color=t.selectColor(l),d.extend=r,d.destroy=t.destroy,Object.defineProperty(d,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(_!==t.namespaces&&(_=t.namespaces,f=t.enabled(l)),f),set:m=>{p=m}}),typeof t.init=="function"&&t.init(d),d}function r(l,h){let p=t(this.namespace+(typeof h>"u"?":":h)+l);return p.log=this.log,p}function n(l){t.save(l),t.namespaces=l,t.names=[],t.skips=[];let h,p=(typeof l=="string"?l:"").split(/[\s,]+/),_=p.length;for(h=0;h<_;h++)p[h]&&(l=p[h].replace(/\*/g,".*?"),l[0]==="-"?t.skips.push(new RegExp("^"+l.slice(1)+"$")):t.names.push(new RegExp("^"+l+"$")))}function s(){let l=[...t.names.map(a),...t.skips.map(a).map(h=>"-"+h)].join(",");return t.enable(""),l}function o(l){if(l[l.length-1]==="*")return!0;let h,p;for(h=0,p=t.skips.length;h<p;h++)if(t.skips[h].test(l))return!1;for(h=0,p=t.names.length;h<p;h++)if(t.names[h].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function c(l){return l instanceof Error?l.stack||l.message:l}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}Ot.exports=Xi});var Ut=E((N,we)=>{N.formatArgs=Ji;N.save=Zi;N.load=en;N.useColors=Yi;N.storage=tn();N.destroy=(()=>{let i=!1;return()=>{i||(i=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();N.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Yi(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Ji(i){if(i[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+i[0]+(this.useColors?"%c ":" ")+"+"+we.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;i.splice(1,0,e,"color: inherit");let t=0,r=0;i[0].replace(/%[a-zA-Z%]/g,n=>{n!=="%%"&&(t++,n==="%c"&&(r=t))}),i.splice(r,0,e)}N.log=console.debug||console.log||(()=>{});function Zi(i){try{i?N.storage.setItem("debug",i):N.storage.removeItem("debug")}catch{}}function en(){let i;try{i=N.storage.getItem("debug")}catch{}return!i&&typeof process<"u"&&"env"in process&&(i=process.env.DEBUG),i}function tn(){try{return localStorage}catch{}}we.exports=Ft()(N);var{formatters:rn}=we.exports;rn.j=function(i){try{return JSON.stringify(i)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var le=E((Ca,er)=>{er.exports=class{constructor(e={}){this.points=e.points,this.duration=e.duration,this.blockDuration=e.blockDuration,this.execEvenly=e.execEvenly,this.execEvenlyMinDelayMs=e.execEvenlyMinDelayMs,this.keyPrefix=e.keyPrefix}get points(){return this._points}set points(e){this._points=e>=0?e:4}get duration(){return this._duration}set duration(e){this._duration=typeof e>"u"?1:e}get msDuration(){return this.duration*1e3}get blockDuration(){return this._blockDuration}set blockDuration(e){this._blockDuration=typeof e>"u"?0:e}get msBlockDuration(){return this.blockDuration*1e3}get execEvenly(){return this._execEvenly}set execEvenly(e){this._execEvenly=typeof e>"u"?!1:!!e}get execEvenlyMinDelayMs(){return this._execEvenlyMinDelayMs}set execEvenlyMinDelayMs(e){this._execEvenlyMinDelayMs=typeof e>"u"?Math.ceil(this.msDuration/this.points):e}get keyPrefix(){return this._keyPrefix}set keyPrefix(e){if(typeof e>"u"&&(e="rlflx"),typeof e!="string")throw new Error("keyPrefix must be string");this._keyPrefix=e}_getKeySecDuration(e={}){return e&&e.customDuration>=0?e.customDuration:this.duration}getKey(e){return this.keyPrefix.length>0?`${this.keyPrefix}:${e}`:e}parseKey(e){return e.substring(this.keyPrefix.length)}consume(){throw new Error("You have to implement the method 'consume'!")}penalty(){throw new Error("You have to implement the method 'penalty'!")}reward(){throw new Error("You have to implement the method 'reward'!")}get(){throw new Error("You have to implement the method 'get'!")}set(){throw new Error("You have to implement the method 'set'!")}block(){throw new Error("You have to implement the method 'block'!")}delete(){throw new Error("You have to implement the method 'delete'!")}}});var rr=E((Ra,tr)=>{tr.exports=class{constructor(){this._keys={},this._addedKeysAmount=0}collectExpired(){let e=Date.now();Object.keys(this._keys).forEach(t=>{this._keys[t]<=e&&delete this._keys[t]}),this._addedKeysAmount=Object.keys(this._keys).length}add(e,t){this.addMs(e,t*1e3)}addMs(e,t){this._keys[e]=Date.now()+t,this._addedKeysAmount++,this._addedKeysAmount>999&&this.collectExpired()}msBeforeExpire(e){let t=this._keys[e];if(t&&t>=Date.now()){this.collectExpired();let r=Date.now();return t>=r?t-r:0}return 0}delete(e){e?delete this._keys[e]:Object.keys(this._keys).forEach(t=>{delete this._keys[t]})}}});var nr=E((Ia,ir)=>{var mn=rr();ir.exports=mn});var v=E((La,sr)=>{sr.exports=class{constructor(e,t,r,n){this.remainingPoints=typeof e>"u"?0:e,this.msBeforeNext=typeof t>"u"?0:t,this.consumedPoints=typeof r>"u"?0:r,this.isFirstInDuration=typeof n>"u"?!1:n}get msBeforeNext(){return this._msBeforeNext}set msBeforeNext(e){return this._msBeforeNext=e,this}get remainingPoints(){return this._remainingPoints}set remainingPoints(e){return this._remainingPoints=e,this}get consumedPoints(){return this._consumedPoints}set consumedPoints(e){return this._consumedPoints=e,this}get isFirstInDuration(){return this._isFirstInDuration}set isFirstInDuration(e){this._isFirstInDuration=!!e}_getDecoratedProperties(){return{remainingPoints:this.remainingPoints,msBeforeNext:this.msBeforeNext,consumedPoints:this.consumedPoints,isFirstInDuration:this.isFirstInDuration}}[Symbol.for("nodejs.util.inspect.custom")](){return this._getDecoratedProperties()}toString(){return JSON.stringify(this._getDecoratedProperties())}toJSON(){return this._getDecoratedProperties()}}});var J=E((Na,ar)=>{var qe=le(),pn=nr(),or=v();ar.exports=class extends qe{constructor(e={}){super(e),this.inMemoryBlockOnConsumed=e.inMemoryBlockOnConsumed||e.inmemoryBlockOnConsumed,this.inMemoryBlockDuration=e.inMemoryBlockDuration||e.inmemoryBlockDuration,this.insuranceLimiter=e.insuranceLimiter,this._inMemoryBlockedKeys=new pn}get client(){return this._client}set client(e){if(typeof e>"u")throw new Error("storeClient is not set");this._client=e}_afterConsume(e,t,r,n,s,o={}){let a=this._getRateLimiterRes(r,n,s);if(this.inMemoryBlockOnConsumed>0&&!(this.inMemoryBlockDuration>0)&&a.consumedPoints>=this.inMemoryBlockOnConsumed)return this._inMemoryBlockedKeys.addMs(r,a.msBeforeNext),a.consumedPoints>this.points?t(a):e(a);if(a.consumedPoints>this.points){let c=Promise.resolve();this.blockDuration>0&&a.consumedPoints<=this.points+n&&(a.msBeforeNext=this.msBlockDuration,c=this._block(r,a.consumedPoints,this.msBlockDuration,o)),this.inMemoryBlockOnConsumed>0&&a.consumedPoints>=this.inMemoryBlockOnConsumed&&(this._inMemoryBlockedKeys.add(r,this.inMemoryBlockDuration),a.msBeforeNext=this.msInMemoryBlockDuration),c.then(()=>{t(a)}).catch(u=>{t(u)})}else if(this.execEvenly&&a.msBeforeNext>0&&!a.isFirstInDuration){let c=Math.ceil(a.msBeforeNext/(a.remainingPoints+2));c<this.execEvenlyMinDelayMs&&(c=a.consumedPoints*this.execEvenlyMinDelayMs),setTimeout(e,c,a)}else e(a)}_handleError(e,t,r,n,s,o=!1,a={}){this.insuranceLimiter instanceof qe?this.insuranceLimiter[t](s,o,a).then(c=>{r(c)}).catch(c=>{n(c)}):n(e)}get _inmemoryBlockedKeys(){return this._inMemoryBlockedKeys}getInmemoryBlockMsBeforeExpire(e){return this.getInMemoryBlockMsBeforeExpire(e)}get inmemoryBlockOnConsumed(){return this.inMemoryBlockOnConsumed}set inmemoryBlockOnConsumed(e){this.inMemoryBlockOnConsumed=e}get inmemoryBlockDuration(){return this.inMemoryBlockDuration}set inmemoryBlockDuration(e){this.inMemoryBlockDuration=e}get msInmemoryBlockDuration(){return this.inMemoryBlockDuration*1e3}getInMemoryBlockMsBeforeExpire(e){return this.inMemoryBlockOnConsumed>0?this._inMemoryBlockedKeys.msBeforeExpire(e):0}get inMemoryBlockOnConsumed(){return this._inMemoryBlockOnConsumed}set inMemoryBlockOnConsumed(e){if(this._inMemoryBlockOnConsumed=e?parseInt(e):0,this.inMemoryBlockOnConsumed>0&&this.points>this.inMemoryBlockOnConsumed)throw new Error('inMemoryBlockOnConsumed option must be greater or equal "points" option')}get inMemoryBlockDuration(){return this._inMemoryBlockDuration}set inMemoryBlockDuration(e){if(this._inMemoryBlockDuration=e?parseInt(e):0,this.inMemoryBlockDuration>0&&this.inMemoryBlockOnConsumed===0)throw new Error("inMemoryBlockOnConsumed option must be set up")}get msInMemoryBlockDuration(){return this._inMemoryBlockDuration*1e3}get insuranceLimiter(){return this._insuranceLimiter}set insuranceLimiter(e){if(typeof e<"u"&&!(e instanceof qe))throw new Error("insuranceLimiter must be instance of RateLimiterAbstract");this._insuranceLimiter=e,this._insuranceLimiter&&(this._insuranceLimiter.blockDuration=this.blockDuration,this._insuranceLimiter.execEvenly=this.execEvenly)}block(e,t,r={}){let n=t*1e3;return this._block(this.getKey(e),this.points+1,n,r)}set(e,t,r,n={}){let s=(r>=0?r:this.duration)*1e3;return this._block(this.getKey(e),t,s,n)}consume(e,t=1,r={}){return new Promise((n,s)=>{let o=this.getKey(e),a=this.getInMemoryBlockMsBeforeExpire(o);if(a>0)return s(new or(0,a));this._upsert(o,t,this._getKeySecDuration(r)*1e3,!1,r).then(c=>{this._afterConsume(n,s,o,t,c)}).catch(c=>{this._handleError(c,"consume",n,s,e,t,r)})})}penalty(e,t=1,r={}){let n=this.getKey(e);return new Promise((s,o)=>{this._upsert(n,t,this._getKeySecDuration(r)*1e3,!1,r).then(a=>{s(this._getRateLimiterRes(n,t,a))}).catch(a=>{this._handleError(a,"penalty",s,o,e,t,r)})})}reward(e,t=1,r={}){let n=this.getKey(e);return new Promise((s,o)=>{this._upsert(n,-t,this._getKeySecDuration(r)*1e3,!1,r).then(a=>{s(this._getRateLimiterRes(n,-t,a))}).catch(a=>{this._handleError(a,"reward",s,o,e,t,r)})})}get(e,t={}){let r=this.getKey(e);return new Promise((n,s)=>{this._get(r,t).then(o=>{n(o===null||typeof o>"u"?null:this._getRateLimiterRes(r,0,o))}).catch(o=>{this._handleError(o,"get",n,s,e,t)})})}delete(e,t={}){let r=this.getKey(e);return new Promise((n,s)=>{this._delete(r,t).then(o=>{this._inMemoryBlockedKeys.delete(r),n(o)}).catch(o=>{this._handleError(o,"delete",n,s,e,t)})})}deleteInMemoryBlockedAll(){this._inMemoryBlockedKeys.delete()}_getRateLimiterRes(e,t,r){throw new Error("You have to implement the method '_getRateLimiterRes'!")}_block(e,t,r,n={}){return new Promise((s,o)=>{this._upsert(e,t,r,!0,n).then(()=>{s(new or(0,r>0?r:-1,t))}).catch(a=>{this._handleError(a,"block",s,o,this.parseKey(e),r/1e3,n)})})}_get(e,t={}){throw new Error("You have to implement the method '_get'!")}_delete(e,t={}){throw new Error("You have to implement the method '_delete'!")}_upsert(e,t,r,n=!1,s={}){throw new Error("You have to implement the method '_upsert'!")}}});var ur=E((ka,lr)=>{var bn=J(),yn=v(),cr="redis.call('set', KEYS[1], 0, 'EX', ARGV[2], 'NX') local consumed = redis.call('incrby', KEYS[1], ARGV[1]) local ttl = redis.call('pttl', KEYS[1]) if ttl == -1 then redis.call('expire', KEYS[1], ARGV[2]) ttl = 1000 * ARGV[2] end return {consumed, ttl} ",ze=class extends bn{constructor(e){super(e),e.redis?this.client=e.redis:this.client=e.storeClient,this._rejectIfRedisNotReady=!!e.rejectIfRedisNotReady,typeof this.client.defineCommand=="function"&&this.client.defineCommand("rlflxIncr",{numberOfKeys:1,lua:cr})}_isRedisReady(){return this._rejectIfRedisNotReady?!(this.client.status&&this.client.status!=="ready"||typeof this.client.isReady=="function"&&!this.client.isReady()):!0}_getRateLimiterRes(e,t,r){let[n,s]=r;Array.isArray(n)&&([,n]=n,[,s]=s);let o=new yn;return o.consumedPoints=parseInt(n),o.isFirstInDuration=o.consumedPoints===t,o.remainingPoints=Math.max(this.points-o.consumedPoints,0),o.msBeforeNext=s,o}_upsert(e,t,r,n=!1){return new Promise((s,o)=>{if(!this._isRedisReady())return o(new Error("Redis connection is not ready"));let a=Math.floor(r/1e3),c=this.client.multi();if(n)a>0?c.set(e,t,"EX",a):c.set(e,t),c.pttl(e).exec((u,l)=>u?o(u):s(l));else if(a>0){let u=function(l,h){return l?o(l):s(h)};typeof this.client.rlflxIncr=="function"?this.client.rlflxIncr(e,t,a,u):this.client.eval(cr,1,e,t,a,u)}else c.incrby(e,t).pttl(e).exec((u,l)=>u?o(u):s(l))})}_get(e){return new Promise((t,r)=>{if(!this._isRedisReady())return r(new Error("Redis connection is not ready"));this.client.multi().get(e).pttl(e).exec((n,s)=>{if(n)r(n);else{let[o]=s;if(o===null)return t(null);t(s)}})})}_delete(e){return new Promise((t,r)=>{this.client.del(e,(n,s)=>{n?r(n):t(s>0)})})}};lr.exports=ze});var dr=E((va,fr)=>{var wn=J(),gn=v();function hr(i){try{let e=i.client?i.client:i,{version:t}=e.topology.s.options.metadata.driver,r=t.split(".").map(n=>parseInt(n));return{major:r[0],feature:r[1],patch:r[2]}}catch{return{major:0,feature:0,patch:0}}}var $e=class i extends wn{constructor(e){super(e),this.dbName=e.dbName,this.tableName=e.tableName,this.indexKeyPrefix=e.indexKeyPrefix,e.mongo?this.client=e.mongo:this.client=e.storeClient,typeof this.client.then=="function"?this.client.then(t=>{this.client=t,this._initCollection(),this._driverVersion=hr(this.client)}):(this._initCollection(),this._driverVersion=hr(this.client))}get dbName(){return this._dbName}set dbName(e){this._dbName=typeof e>"u"?i.getDbName():e}static getDbName(){return"node-rate-limiter-flexible"}get tableName(){return this._tableName}set tableName(e){this._tableName=typeof e>"u"?this.keyPrefix:e}get client(){return this._client}set client(e){if(typeof e>"u")throw new Error("mongo is not set");this._client=e}get indexKeyPrefix(){return this._indexKeyPrefix}set indexKeyPrefix(e){this._indexKeyPrefix=e||{}}_initCollection(){let t=(typeof this.client.db=="function"?this.client.db(this.dbName):this.client).collection(this.tableName);t.createIndex({expire:-1},{expireAfterSeconds:0}),t.createIndex(Object.assign({},this.indexKeyPrefix,{key:1}),{unique:!0}),this._collection=t}_getRateLimiterRes(e,t,r){let n=new gn,s;return typeof r.value>"u"?s=r:s=r.value,n.isFirstInDuration=s.points===t,n.consumedPoints=s.points,n.remainingPoints=Math.max(this.points-n.consumedPoints,0),n.msBeforeNext=s.expire!==null?Math.max(new Date(s.expire).getTime()-Date.now(),0):-1,n}_upsert(e,t,r,n=!1,s={}){if(!this._collection)return Promise.reject(Error("Mongo connection is not established"));let o=s.attrs||{},a,c;n?(a={key:e},a=Object.assign(a,o),c={$set:{key:e,points:t,expire:r>0?new Date(Date.now()+r):null}},c.$set=Object.assign(c.$set,o)):(a={$or:[{expire:{$gt:new Date}},{expire:{$eq:null}}],key:e},a=Object.assign(a,o),c={$setOnInsert:{key:e,expire:r>0?new Date(Date.now()+r):null},$inc:{points:t}},c.$setOnInsert=Object.assign(c.$setOnInsert,o));let u={upsert:!0};return this._driverVersion.major>=4||this._driverVersion.major===3&&this._driverVersion.feature>=7||this._driverVersion.feature>=6&&this._driverVersion.patch>=7?u.returnDocument="after":u.returnOriginal=!1,new Promise((l,h)=>{this._collection.findOneAndUpdate(a,c,u).then(p=>{l(p)}).catch(p=>{if(p&&p.code===11e3){let _=Object.assign({$or:[{expire:{$lte:new Date}},{expire:{$eq:null}}],key:e},o),f={$set:Object.assign({key:e,points:t,expire:r>0?new Date(Date.now()+r):null},o)};this._collection.findOneAndUpdate(_,f,u).then(d=>{l(d)}).catch(d=>{d&&d.code===11e3?this._upsert(e,t,r,n).then(m=>l(m)).catch(m=>h(m)):h(d)})}else h(p)})})}_get(e,t={}){if(!this._collection)return Promise.reject(Error("Mongo connection is not established"));let r=t.attrs||{},n=Object.assign({key:e,$or:[{expire:{$gt:new Date}},{expire:{$eq:null}}]},r);return this._collection.findOne(n)}_delete(e,t={}){if(!this._collection)return Promise.reject(Error("Mongo connection is not established"));let r=t.attrs||{},n=Object.assign({key:e},r);return this._collection.deleteOne(n).then(s=>s.deletedCount>0)}};fr.exports=$e});var pr=E((Pa,mr)=>{var xn=J(),En=v(),Ve=class extends xn{constructor(e,t=null){super(e),this.client=e.storeClient,this.clientType=e.storeType,this.dbName=e.dbName,this.tableName=e.tableName,this.clearExpiredByTimeout=e.clearExpiredByTimeout,this.tableCreated=e.tableCreated,this.tableCreated?(this.clearExpiredByTimeout&&this._clearExpiredHourAgo(),typeof t=="function"&&t()):this._createDbAndTable().then(()=>{this.tableCreated=!0,this.clearExpiredByTimeout&&this._clearExpiredHourAgo(),typeof t=="function"&&t()}).catch(r=>{if(typeof t=="function")t(r);else throw r})}clearExpired(e){return new Promise(t=>{this._getConnection().then(r=>{r.query("DELETE FROM ??.?? WHERE expire < ?",[this.dbName,this.tableName,e],()=>{this._releaseConnection(r),t()})}).catch(()=>{t()})})}_clearExpiredHourAgo(){this._clearExpiredTimeoutId&&clearTimeout(this._clearExpiredTimeoutId),this._clearExpiredTimeoutId=setTimeout(()=>{this.clearExpired(Date.now()-36e5).then(()=>{this._clearExpiredHourAgo()})},3e5),this._clearExpiredTimeoutId.unref()}_getConnection(){switch(this.clientType){case"pool":return new Promise((e,t)=>{this.client.getConnection((r,n)=>{if(r)return t(r);e(n)})});case"sequelize":return this.client.connectionManager.getConnection();case"knex":return this.client.client.acquireConnection();default:return Promise.resolve(this.client)}}_releaseConnection(e){switch(this.clientType){case"pool":return e.release();case"sequelize":return this.client.connectionManager.releaseConnection(e);case"knex":return this.client.client.releaseConnection(e);default:return!0}}_createDbAndTable(){return new Promise((e,t)=>{this._getConnection().then(r=>{r.query(`CREATE DATABASE IF NOT EXISTS \`${this.dbName}\`;`,n=>{if(n)return this._releaseConnection(r),t(n);r.query(this._getCreateTableStmt(),s=>{if(s)return this._releaseConnection(r),t(s);this._releaseConnection(r),e()})})}).catch(r=>{t(r)})})}_getCreateTableStmt(){return`CREATE TABLE IF NOT EXISTS \`${this.dbName}\`.\`${this.tableName}\` (\`key\` VARCHAR(255) CHARACTER SET utf8 NOT NULL,\`points\` INT(9) NOT NULL default 0,\`expire\` BIGINT UNSIGNED,PRIMARY KEY (\`key\`)) ENGINE = INNODB;`}get clientType(){return this._clientType}set clientType(e){if(typeof e>"u")if(this.client.constructor.name==="Connection")e="connection";else if(this.client.constructor.name==="Pool")e="pool";else if(this.client.constructor.name==="Sequelize")e="sequelize";else throw new Error("storeType is not defined");this._clientType=e.toLowerCase()}get dbName(){return this._dbName}set dbName(e){this._dbName=typeof e>"u"?"rtlmtrflx":e}get tableName(){return this._tableName}set tableName(e){this._tableName=typeof e>"u"?this.keyPrefix:e}get tableCreated(){return this._tableCreated}set tableCreated(e){this._tableCreated=typeof e>"u"?!1:!!e}get clearExpiredByTimeout(){return this._clearExpiredByTimeout}set clearExpiredByTimeout(e){this._clearExpiredByTimeout=typeof e>"u"?!0:!!e}_getRateLimiterRes(e,t,r){let n=new En,[s]=r;return n.isFirstInDuration=t===s.points,n.consumedPoints=n.isFirstInDuration?t:s.points,n.remainingPoints=Math.max(this.points-n.consumedPoints,0),n.msBeforeNext=s.expire?Math.max(s.expire-Date.now(),0):-1,n}_upsertTransaction(e,t,r,n,s){return new Promise((o,a)=>{e.query("BEGIN",c=>{if(c)return e.rollback(),a(c);let u=Date.now(),l=n>0?u+n:null,h,p;s?(h=`INSERT INTO ??.?? VALUES (?, ?, ?)
2
+ "use strict";var Libp2PMplex=(()=>{var Ii=Object.create;var pe=Object.defineProperty;var Li=Object.getOwnPropertyDescriptor;var Ti=Object.getOwnPropertyNames;var Mi=Object.getPrototypeOf,Ni=Object.prototype.hasOwnProperty;var y=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),I=(i,e)=>{for(var t in e)pe(i,t,{get:e[t],enumerable:!0})},Tt=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ti(e))!Ni.call(i,s)&&s!==t&&pe(i,s,{get:()=>e[s],enumerable:!(r=Li(e,s))||r.enumerable});return i};var Ne=(i,e,t)=>(t=i!=null?Ii(Mi(i)):{},Tt(e||!i||!i.__esModule?pe(t,"default",{value:i,enumerable:!0}):t,i)),ki=i=>Tt(pe({},"__esModule",{value:!0}),i);var Nt=y((mo,Mt)=>{var j=1e3,H=j*60,Y=H*60,W=Y*24,Pi=W*7,vi=W*365.25;Mt.exports=function(i,e){e=e||{};var t=typeof i;if(t==="string"&&i.length>0)return Di(i);if(t==="number"&&isFinite(i))return e.long?Oi(i):Bi(i);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(i))};function Di(i){if(i=String(i),!(i.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(i);if(e){var t=parseFloat(e[1]),r=(e[2]||"ms").toLowerCase();switch(r){case"years":case"year":case"yrs":case"yr":case"y":return t*vi;case"weeks":case"week":case"w":return t*Pi;case"days":case"day":case"d":return t*W;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Y;case"minutes":case"minute":case"mins":case"min":case"m":return t*H;case"seconds":case"second":case"secs":case"sec":case"s":return t*j;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function Bi(i){var e=Math.abs(i);return e>=W?Math.round(i/W)+"d":e>=Y?Math.round(i/Y)+"h":e>=H?Math.round(i/H)+"m":e>=j?Math.round(i/j)+"s":i+"ms"}function Oi(i){var e=Math.abs(i);return e>=W?be(i,e,W,"day"):e>=Y?be(i,e,Y,"hour"):e>=H?be(i,e,H,"minute"):e>=j?be(i,e,j,"second"):i+" ms"}function be(i,e,t,r){var s=e>=t*1.5;return Math.round(i/t)+" "+r+(s?"s":"")}});var Pt=y((po,kt)=>{function Fi(i){t.debug=t,t.default=t,t.coerce=c,t.disable=n,t.enable=s,t.enabled=o,t.humanize=Nt(),t.destroy=u,Object.keys(i).forEach(l=>{t[l]=i[l]}),t.names=[],t.skips=[],t.formatters={};function e(l){let h=0;for(let f=0;f<l.length;f++)h=(h<<5)-h+l.charCodeAt(f),h|=0;return t.colors[Math.abs(h)%t.colors.length]}t.selectColor=e;function t(l){let h,f=null,g,m;function p(...d){if(!p.enabled)return;let w=p,x=Number(new Date),_=x-(h||x);w.diff=_,w.prev=h,w.curr=x,h=x,d[0]=t.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let S=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(k,R)=>{if(k==="%%")return"%";S++;let P=t.formatters[R];if(typeof P=="function"){let G=d[S];k=P.call(w,G),d.splice(S,1),S--}return k}),t.formatArgs.call(w,d),(w.log||t.log).apply(w,d)}return p.namespace=l,p.useColors=t.useColors(),p.color=t.selectColor(l),p.extend=r,p.destroy=t.destroy,Object.defineProperty(p,"enabled",{enumerable:!0,configurable:!1,get:()=>f!==null?f:(g!==t.namespaces&&(g=t.namespaces,m=t.enabled(l)),m),set:d=>{f=d}}),typeof t.init=="function"&&t.init(p),p}function r(l,h){let f=t(this.namespace+(typeof h>"u"?":":h)+l);return f.log=this.log,f}function s(l){t.save(l),t.namespaces=l,t.names=[],t.skips=[];let h,f=(typeof l=="string"?l:"").split(/[\s,]+/),g=f.length;for(h=0;h<g;h++)f[h]&&(l=f[h].replace(/\*/g,".*?"),l[0]==="-"?t.skips.push(new RegExp("^"+l.slice(1)+"$")):t.names.push(new RegExp("^"+l+"$")))}function n(){let l=[...t.names.map(a),...t.skips.map(a).map(h=>"-"+h)].join(",");return t.enable(""),l}function o(l){if(l[l.length-1]==="*")return!0;let h,f;for(h=0,f=t.skips.length;h<f;h++)if(t.skips[h].test(l))return!1;for(h=0,f=t.names.length;h<f;h++)if(t.names[h].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function c(l){return l instanceof Error?l.stack||l.message:l}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}kt.exports=Fi});var vt=y((L,ye)=>{L.formatArgs=qi;L.save=zi;L.load=$i;L.useColors=Ui;L.storage=Vi();L.destroy=(()=>{let i=!1;return()=>{i||(i=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();L.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Ui(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function qi(i){if(i[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+i[0]+(this.useColors?"%c ":" ")+"+"+ye.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;i.splice(1,0,e,"color: inherit");let t=0,r=0;i[0].replace(/%[a-zA-Z%]/g,s=>{s!=="%%"&&(t++,s==="%c"&&(r=t))}),i.splice(r,0,e)}L.log=console.debug||console.log||(()=>{});function zi(i){try{i?L.storage.setItem("debug",i):L.storage.removeItem("debug")}catch{}}function $i(){let i;try{i=L.storage.getItem("debug")}catch{}return!i&&typeof process<"u"&&"env"in process&&(i=process.env.DEBUG),i}function Vi(){try{return localStorage}catch{}}ye.exports=Pt()(L);var{formatters:Wi}=ye.exports;Wi.j=function(i){try{return JSON.stringify(i)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var ce=y((Wo,Ht)=>{Ht.exports=class{constructor(e={}){this.points=e.points,this.duration=e.duration,this.blockDuration=e.blockDuration,this.execEvenly=e.execEvenly,this.execEvenlyMinDelayMs=e.execEvenlyMinDelayMs,this.keyPrefix=e.keyPrefix}get points(){return this._points}set points(e){this._points=e>=0?e:4}get duration(){return this._duration}set duration(e){this._duration=typeof e>"u"?1:e}get msDuration(){return this.duration*1e3}get blockDuration(){return this._blockDuration}set blockDuration(e){this._blockDuration=typeof e>"u"?0:e}get msBlockDuration(){return this.blockDuration*1e3}get execEvenly(){return this._execEvenly}set execEvenly(e){this._execEvenly=typeof e>"u"?!1:!!e}get execEvenlyMinDelayMs(){return this._execEvenlyMinDelayMs}set execEvenlyMinDelayMs(e){this._execEvenlyMinDelayMs=typeof e>"u"?Math.ceil(this.msDuration/this.points):e}get keyPrefix(){return this._keyPrefix}set keyPrefix(e){if(typeof e>"u"&&(e="rlflx"),typeof e!="string")throw new Error("keyPrefix must be string");this._keyPrefix=e}_getKeySecDuration(e={}){return e&&e.customDuration>=0?e.customDuration:this.duration}getKey(e){return this.keyPrefix.length>0?`${this.keyPrefix}:${e}`:e}parseKey(e){return e.substring(this.keyPrefix.length)}consume(){throw new Error("You have to implement the method 'consume'!")}penalty(){throw new Error("You have to implement the method 'penalty'!")}reward(){throw new Error("You have to implement the method 'reward'!")}get(){throw new Error("You have to implement the method 'get'!")}set(){throw new Error("You have to implement the method 'set'!")}block(){throw new Error("You have to implement the method 'block'!")}delete(){throw new Error("You have to implement the method 'delete'!")}}});var Qt=y((Go,Yt)=>{Yt.exports=class{constructor(){this._keys={},this._addedKeysAmount=0}collectExpired(){let e=Date.now();Object.keys(this._keys).forEach(t=>{this._keys[t]<=e&&delete this._keys[t]}),this._addedKeysAmount=Object.keys(this._keys).length}add(e,t){this.addMs(e,t*1e3)}addMs(e,t){this._keys[e]=Date.now()+t,this._addedKeysAmount++,this._addedKeysAmount>999&&this.collectExpired()}msBeforeExpire(e){let t=this._keys[e];if(t&&t>=Date.now()){this.collectExpired();let r=Date.now();return t>=r?t-r:0}return 0}delete(e){e?delete this._keys[e]:Object.keys(this._keys).forEach(t=>{delete this._keys[t]})}}});var Jt=y((jo,Xt)=>{var ds=Qt();Xt.exports=ds});var M=y((Yo,Zt)=>{Zt.exports=class{constructor(e,t,r,s){this.remainingPoints=typeof e>"u"?0:e,this.msBeforeNext=typeof t>"u"?0:t,this.consumedPoints=typeof r>"u"?0:r,this.isFirstInDuration=typeof s>"u"?!1:s}get msBeforeNext(){return this._msBeforeNext}set msBeforeNext(e){return this._msBeforeNext=e,this}get remainingPoints(){return this._remainingPoints}set remainingPoints(e){return this._remainingPoints=e,this}get consumedPoints(){return this._consumedPoints}set consumedPoints(e){return this._consumedPoints=e,this}get isFirstInDuration(){return this._isFirstInDuration}set isFirstInDuration(e){this._isFirstInDuration=!!e}_getDecoratedProperties(){return{remainingPoints:this.remainingPoints,msBeforeNext:this.msBeforeNext,consumedPoints:this.consumedPoints,isFirstInDuration:this.isFirstInDuration}}[Symbol.for("nodejs.util.inspect.custom")](){return this._getDecoratedProperties()}toString(){return JSON.stringify(this._getDecoratedProperties())}toJSON(){return this._getDecoratedProperties()}}});var Z=y((Xo,tr)=>{var $e=ce(),ms=Jt(),er=M();tr.exports=class extends $e{constructor(e={}){super(e),this.inMemoryBlockOnConsumed=e.inMemoryBlockOnConsumed||e.inmemoryBlockOnConsumed,this.inMemoryBlockDuration=e.inMemoryBlockDuration||e.inmemoryBlockDuration,this.insuranceLimiter=e.insuranceLimiter,this._inMemoryBlockedKeys=new ms}get client(){return this._client}set client(e){if(typeof e>"u")throw new Error("storeClient is not set");this._client=e}_afterConsume(e,t,r,s,n,o={}){let a=this._getRateLimiterRes(r,s,n);if(this.inMemoryBlockOnConsumed>0&&!(this.inMemoryBlockDuration>0)&&a.consumedPoints>=this.inMemoryBlockOnConsumed)return this._inMemoryBlockedKeys.addMs(r,a.msBeforeNext),a.consumedPoints>this.points?t(a):e(a);if(a.consumedPoints>this.points){let c=Promise.resolve();this.blockDuration>0&&a.consumedPoints<=this.points+s&&(a.msBeforeNext=this.msBlockDuration,c=this._block(r,a.consumedPoints,this.msBlockDuration,o)),this.inMemoryBlockOnConsumed>0&&a.consumedPoints>=this.inMemoryBlockOnConsumed&&(this._inMemoryBlockedKeys.add(r,this.inMemoryBlockDuration),a.msBeforeNext=this.msInMemoryBlockDuration),c.then(()=>{t(a)}).catch(u=>{t(u)})}else if(this.execEvenly&&a.msBeforeNext>0&&!a.isFirstInDuration){let c=Math.ceil(a.msBeforeNext/(a.remainingPoints+2));c<this.execEvenlyMinDelayMs&&(c=a.consumedPoints*this.execEvenlyMinDelayMs),setTimeout(e,c,a)}else e(a)}_handleError(e,t,r,s,n,o=!1,a={}){this.insuranceLimiter instanceof $e?this.insuranceLimiter[t](n,o,a).then(c=>{r(c)}).catch(c=>{s(c)}):s(e)}get _inmemoryBlockedKeys(){return this._inMemoryBlockedKeys}getInmemoryBlockMsBeforeExpire(e){return this.getInMemoryBlockMsBeforeExpire(e)}get inmemoryBlockOnConsumed(){return this.inMemoryBlockOnConsumed}set inmemoryBlockOnConsumed(e){this.inMemoryBlockOnConsumed=e}get inmemoryBlockDuration(){return this.inMemoryBlockDuration}set inmemoryBlockDuration(e){this.inMemoryBlockDuration=e}get msInmemoryBlockDuration(){return this.inMemoryBlockDuration*1e3}getInMemoryBlockMsBeforeExpire(e){return this.inMemoryBlockOnConsumed>0?this._inMemoryBlockedKeys.msBeforeExpire(e):0}get inMemoryBlockOnConsumed(){return this._inMemoryBlockOnConsumed}set inMemoryBlockOnConsumed(e){if(this._inMemoryBlockOnConsumed=e?parseInt(e):0,this.inMemoryBlockOnConsumed>0&&this.points>this.inMemoryBlockOnConsumed)throw new Error('inMemoryBlockOnConsumed option must be greater or equal "points" option')}get inMemoryBlockDuration(){return this._inMemoryBlockDuration}set inMemoryBlockDuration(e){if(this._inMemoryBlockDuration=e?parseInt(e):0,this.inMemoryBlockDuration>0&&this.inMemoryBlockOnConsumed===0)throw new Error("inMemoryBlockOnConsumed option must be set up")}get msInMemoryBlockDuration(){return this._inMemoryBlockDuration*1e3}get insuranceLimiter(){return this._insuranceLimiter}set insuranceLimiter(e){if(typeof e<"u"&&!(e instanceof $e))throw new Error("insuranceLimiter must be instance of RateLimiterAbstract");this._insuranceLimiter=e,this._insuranceLimiter&&(this._insuranceLimiter.blockDuration=this.blockDuration,this._insuranceLimiter.execEvenly=this.execEvenly)}block(e,t,r={}){let s=t*1e3;return this._block(this.getKey(e),this.points+1,s,r)}set(e,t,r,s={}){let n=(r>=0?r:this.duration)*1e3;return this._block(this.getKey(e),t,n,s)}consume(e,t=1,r={}){return new Promise((s,n)=>{let o=this.getKey(e),a=this.getInMemoryBlockMsBeforeExpire(o);if(a>0)return n(new er(0,a));this._upsert(o,t,this._getKeySecDuration(r)*1e3,!1,r).then(c=>{this._afterConsume(s,n,o,t,c)}).catch(c=>{this._handleError(c,"consume",s,n,e,t,r)})})}penalty(e,t=1,r={}){let s=this.getKey(e);return new Promise((n,o)=>{this._upsert(s,t,this._getKeySecDuration(r)*1e3,!1,r).then(a=>{n(this._getRateLimiterRes(s,t,a))}).catch(a=>{this._handleError(a,"penalty",n,o,e,t,r)})})}reward(e,t=1,r={}){let s=this.getKey(e);return new Promise((n,o)=>{this._upsert(s,-t,this._getKeySecDuration(r)*1e3,!1,r).then(a=>{n(this._getRateLimiterRes(s,-t,a))}).catch(a=>{this._handleError(a,"reward",n,o,e,t,r)})})}get(e,t={}){let r=this.getKey(e);return new Promise((s,n)=>{this._get(r,t).then(o=>{s(o===null||typeof o>"u"?null:this._getRateLimiterRes(r,0,o))}).catch(o=>{this._handleError(o,"get",s,n,e,t)})})}delete(e,t={}){let r=this.getKey(e);return new Promise((s,n)=>{this._delete(r,t).then(o=>{this._inMemoryBlockedKeys.delete(r),s(o)}).catch(o=>{this._handleError(o,"delete",s,n,e,t)})})}deleteInMemoryBlockedAll(){this._inMemoryBlockedKeys.delete()}_getRateLimiterRes(e,t,r){throw new Error("You have to implement the method '_getRateLimiterRes'!")}_block(e,t,r,s={}){return new Promise((n,o)=>{this._upsert(e,t,r,!0,s).then(()=>{n(new er(0,r>0?r:-1,t))}).catch(a=>{this._handleError(a,"block",n,o,this.parseKey(e),r/1e3,s)})})}_get(e,t={}){throw new Error("You have to implement the method '_get'!")}_delete(e,t={}){throw new Error("You have to implement the method '_delete'!")}_upsert(e,t,r,s=!1,n={}){throw new Error("You have to implement the method '_upsert'!")}}});var sr=y((Jo,ir)=>{var ps=Z(),bs=M(),rr="redis.call('set', KEYS[1], 0, 'EX', ARGV[2], 'NX') local consumed = redis.call('incrby', KEYS[1], ARGV[1]) local ttl = redis.call('pttl', KEYS[1]) if ttl == -1 then redis.call('expire', KEYS[1], ARGV[2]) ttl = 1000 * ARGV[2] end return {consumed, ttl} ",Ve=class extends ps{constructor(e){super(e),e.redis?this.client=e.redis:this.client=e.storeClient,this._rejectIfRedisNotReady=!!e.rejectIfRedisNotReady,typeof this.client.defineCommand=="function"&&this.client.defineCommand("rlflxIncr",{numberOfKeys:1,lua:rr})}_isRedisReady(){return this._rejectIfRedisNotReady?!(this.client.status&&this.client.status!=="ready"||typeof this.client.isReady=="function"&&!this.client.isReady()):!0}_getRateLimiterRes(e,t,r){let[s,n]=r;Array.isArray(s)&&([,s]=s,[,n]=n);let o=new bs;return o.consumedPoints=parseInt(s),o.isFirstInDuration=o.consumedPoints===t,o.remainingPoints=Math.max(this.points-o.consumedPoints,0),o.msBeforeNext=n,o}_upsert(e,t,r,s=!1){return new Promise((n,o)=>{if(!this._isRedisReady())return o(new Error("Redis connection is not ready"));let a=Math.floor(r/1e3),c=this.client.multi();if(s)a>0?c.set(e,t,"EX",a):c.set(e,t),c.pttl(e).exec((u,l)=>u?o(u):n(l));else if(a>0){let u=function(l,h){return l?o(l):n(h)};typeof this.client.rlflxIncr=="function"?this.client.rlflxIncr(e,t,a,u):this.client.eval(rr,1,e,t,a,u)}else c.incrby(e,t).pttl(e).exec((u,l)=>u?o(u):n(l))})}_get(e){return new Promise((t,r)=>{if(!this._isRedisReady())return r(new Error("Redis connection is not ready"));this.client.multi().get(e).pttl(e).exec((s,n)=>{if(s)r(s);else{let[o]=n;if(o===null)return t(null);t(n)}})})}_delete(e){return new Promise((t,r)=>{this.client.del(e,(s,n)=>{s?r(s):t(n>0)})})}};ir.exports=Ve});var ar=y((Zo,or)=>{var ys=Z(),ws=M();function nr(i){try{let e=i.client?i.client:i,{version:t}=e.topology.s.options.metadata.driver,r=t.split(".").map(s=>parseInt(s));return{major:r[0],feature:r[1],patch:r[2]}}catch{return{major:0,feature:0,patch:0}}}var We=class i extends ys{constructor(e){super(e),this.dbName=e.dbName,this.tableName=e.tableName,this.indexKeyPrefix=e.indexKeyPrefix,e.mongo?this.client=e.mongo:this.client=e.storeClient,typeof this.client.then=="function"?this.client.then(t=>{this.client=t,this._initCollection(),this._driverVersion=nr(this.client)}):(this._initCollection(),this._driverVersion=nr(this.client))}get dbName(){return this._dbName}set dbName(e){this._dbName=typeof e>"u"?i.getDbName():e}static getDbName(){return"node-rate-limiter-flexible"}get tableName(){return this._tableName}set tableName(e){this._tableName=typeof e>"u"?this.keyPrefix:e}get client(){return this._client}set client(e){if(typeof e>"u")throw new Error("mongo is not set");this._client=e}get indexKeyPrefix(){return this._indexKeyPrefix}set indexKeyPrefix(e){this._indexKeyPrefix=e||{}}_initCollection(){let t=(typeof this.client.db=="function"?this.client.db(this.dbName):this.client).collection(this.tableName);t.createIndex({expire:-1},{expireAfterSeconds:0}),t.createIndex(Object.assign({},this.indexKeyPrefix,{key:1}),{unique:!0}),this._collection=t}_getRateLimiterRes(e,t,r){let s=new ws,n;return typeof r.value>"u"?n=r:n=r.value,s.isFirstInDuration=n.points===t,s.consumedPoints=n.points,s.remainingPoints=Math.max(this.points-s.consumedPoints,0),s.msBeforeNext=n.expire!==null?Math.max(new Date(n.expire).getTime()-Date.now(),0):-1,s}_upsert(e,t,r,s=!1,n={}){if(!this._collection)return Promise.reject(Error("Mongo connection is not established"));let o=n.attrs||{},a,c;s?(a={key:e},a=Object.assign(a,o),c={$set:{key:e,points:t,expire:r>0?new Date(Date.now()+r):null}},c.$set=Object.assign(c.$set,o)):(a={$or:[{expire:{$gt:new Date}},{expire:{$eq:null}}],key:e},a=Object.assign(a,o),c={$setOnInsert:{key:e,expire:r>0?new Date(Date.now()+r):null},$inc:{points:t}},c.$setOnInsert=Object.assign(c.$setOnInsert,o));let u={upsert:!0};return this._driverVersion.major>=4||this._driverVersion.major===3&&this._driverVersion.feature>=7||this._driverVersion.feature>=6&&this._driverVersion.patch>=7?u.returnDocument="after":u.returnOriginal=!1,new Promise((l,h)=>{this._collection.findOneAndUpdate(a,c,u).then(f=>{l(f)}).catch(f=>{if(f&&f.code===11e3){let g=Object.assign({$or:[{expire:{$lte:new Date}},{expire:{$eq:null}}],key:e},o),m={$set:Object.assign({key:e,points:t,expire:r>0?new Date(Date.now()+r):null},o)};this._collection.findOneAndUpdate(g,m,u).then(p=>{l(p)}).catch(p=>{p&&p.code===11e3?this._upsert(e,t,r,s).then(d=>l(d)).catch(d=>h(d)):h(p)})}else h(f)})})}_get(e,t={}){if(!this._collection)return Promise.reject(Error("Mongo connection is not established"));let r=t.attrs||{},s=Object.assign({key:e,$or:[{expire:{$gt:new Date}},{expire:{$eq:null}}]},r);return this._collection.findOne(s)}_delete(e,t={}){if(!this._collection)return Promise.reject(Error("Mongo connection is not established"));let r=t.attrs||{},s=Object.assign({key:e},r);return this._collection.deleteOne(s).then(n=>n.deletedCount>0)}};or.exports=We});var lr=y((ea,cr)=>{var gs=Z(),Es=M(),Ke=class extends gs{constructor(e,t=null){super(e),this.client=e.storeClient,this.clientType=e.storeType,this.dbName=e.dbName,this.tableName=e.tableName,this.clearExpiredByTimeout=e.clearExpiredByTimeout,this.tableCreated=e.tableCreated,this.tableCreated?(this.clearExpiredByTimeout&&this._clearExpiredHourAgo(),typeof t=="function"&&t()):this._createDbAndTable().then(()=>{this.tableCreated=!0,this.clearExpiredByTimeout&&this._clearExpiredHourAgo(),typeof t=="function"&&t()}).catch(r=>{if(typeof t=="function")t(r);else throw r})}clearExpired(e){return new Promise(t=>{this._getConnection().then(r=>{r.query("DELETE FROM ??.?? WHERE expire < ?",[this.dbName,this.tableName,e],()=>{this._releaseConnection(r),t()})}).catch(()=>{t()})})}_clearExpiredHourAgo(){this._clearExpiredTimeoutId&&clearTimeout(this._clearExpiredTimeoutId),this._clearExpiredTimeoutId=setTimeout(()=>{this.clearExpired(Date.now()-36e5).then(()=>{this._clearExpiredHourAgo()})},3e5),this._clearExpiredTimeoutId.unref()}_getConnection(){switch(this.clientType){case"pool":return new Promise((e,t)=>{this.client.getConnection((r,s)=>{if(r)return t(r);e(s)})});case"sequelize":return this.client.connectionManager.getConnection();case"knex":return this.client.client.acquireConnection();default:return Promise.resolve(this.client)}}_releaseConnection(e){switch(this.clientType){case"pool":return e.release();case"sequelize":return this.client.connectionManager.releaseConnection(e);case"knex":return this.client.client.releaseConnection(e);default:return!0}}_createDbAndTable(){return new Promise((e,t)=>{this._getConnection().then(r=>{r.query(`CREATE DATABASE IF NOT EXISTS \`${this.dbName}\`;`,s=>{if(s)return this._releaseConnection(r),t(s);r.query(this._getCreateTableStmt(),n=>{if(n)return this._releaseConnection(r),t(n);this._releaseConnection(r),e()})})}).catch(r=>{t(r)})})}_getCreateTableStmt(){return`CREATE TABLE IF NOT EXISTS \`${this.dbName}\`.\`${this.tableName}\` (\`key\` VARCHAR(255) CHARACTER SET utf8 NOT NULL,\`points\` INT(9) NOT NULL default 0,\`expire\` BIGINT UNSIGNED,PRIMARY KEY (\`key\`)) ENGINE = INNODB;`}get clientType(){return this._clientType}set clientType(e){if(typeof e>"u")if(this.client.constructor.name==="Connection")e="connection";else if(this.client.constructor.name==="Pool")e="pool";else if(this.client.constructor.name==="Sequelize")e="sequelize";else throw new Error("storeType is not defined");this._clientType=e.toLowerCase()}get dbName(){return this._dbName}set dbName(e){this._dbName=typeof e>"u"?"rtlmtrflx":e}get tableName(){return this._tableName}set tableName(e){this._tableName=typeof e>"u"?this.keyPrefix:e}get tableCreated(){return this._tableCreated}set tableCreated(e){this._tableCreated=typeof e>"u"?!1:!!e}get clearExpiredByTimeout(){return this._clearExpiredByTimeout}set clearExpiredByTimeout(e){this._clearExpiredByTimeout=typeof e>"u"?!0:!!e}_getRateLimiterRes(e,t,r){let s=new Es,[n]=r;return s.isFirstInDuration=t===n.points,s.consumedPoints=s.isFirstInDuration?t:n.points,s.remainingPoints=Math.max(this.points-s.consumedPoints,0),s.msBeforeNext=n.expire?Math.max(n.expire-Date.now(),0):-1,s}_upsertTransaction(e,t,r,s,n){return new Promise((o,a)=>{e.query("BEGIN",c=>{if(c)return e.rollback(),a(c);let u=Date.now(),l=s>0?u+s:null,h,f;n?(h=`INSERT INTO ??.?? VALUES (?, ?, ?)
3
3
  ON DUPLICATE KEY UPDATE
4
4
  points = ?,
5
- expire = ?;`,p=[this.dbName,this.tableName,t,r,l,r,l]):(h=`INSERT INTO ??.?? VALUES (?, ?, ?)
5
+ expire = ?;`,f=[this.dbName,this.tableName,t,r,l,r,l]):(h=`INSERT INTO ??.?? VALUES (?, ?, ?)
6
6
  ON DUPLICATE KEY UPDATE
7
7
  points = IF(expire <= ?, ?, points + (?)),
8
- expire = IF(expire <= ?, ?, expire);`,p=[this.dbName,this.tableName,t,r,l,u,r,r,u,l]),e.query(h,p,_=>{if(_)return e.rollback(),a(_);e.query("SELECT points, expire FROM ??.?? WHERE `key` = ?;",[this.dbName,this.tableName,t],(f,d)=>{if(f)return e.rollback(),a(f);e.query("COMMIT",m=>{if(m)return e.rollback(),a(m);o(d)})})})})})}_upsert(e,t,r,n=!1){return this.tableCreated?new Promise((s,o)=>{this._getConnection().then(a=>{this._upsertTransaction(a,e,t,r,n).then(c=>{s(c),this._releaseConnection(a)}).catch(c=>{o(c),this._releaseConnection(a)})}).catch(a=>{o(a)})}):Promise.reject(Error("Table is not created yet"))}_get(e){return this.tableCreated?new Promise((t,r)=>{this._getConnection().then(n=>{n.query("SELECT points, expire FROM ??.?? WHERE `key` = ? AND (`expire` > ? OR `expire` IS NULL)",[this.dbName,this.tableName,e,Date.now()],(s,o)=>{s?r(s):o.length===0?t(null):t(o),this._releaseConnection(n)})}).catch(n=>{r(n)})}):Promise.reject(Error("Table is not created yet"))}_delete(e){return this.tableCreated?new Promise((t,r)=>{this._getConnection().then(n=>{n.query("DELETE FROM ??.?? WHERE `key` = ?",[this.dbName,this.tableName,e],(s,o)=>{s?r(s):t(o.affectedRows>0),this._releaseConnection(n)})}).catch(n=>{r(n)})}):Promise.reject(Error("Table is not created yet"))}};mr.exports=Ve});var yr=E((Da,br)=>{var _n=J(),Sn=v(),We=class extends _n{constructor(e,t=null){super(e),this.client=e.storeClient,this.clientType=e.storeType,this.tableName=e.tableName,this.clearExpiredByTimeout=e.clearExpiredByTimeout,this.tableCreated=e.tableCreated,this.tableCreated?typeof t=="function"&&t():this._createTable().then(()=>{this.tableCreated=!0,this.clearExpiredByTimeout&&this._clearExpiredHourAgo(),typeof t=="function"&&t()}).catch(r=>{if(typeof t=="function")t(r);else throw r})}clearExpired(e){return new Promise(t=>{let r={name:"rlflx-clear-expired",text:`DELETE FROM ${this.tableName} WHERE expire < $1`,values:[e]};this._query(r).then(()=>{t()}).catch(()=>{t()})})}_clearExpiredHourAgo(){this._clearExpiredTimeoutId&&clearTimeout(this._clearExpiredTimeoutId),this._clearExpiredTimeoutId=setTimeout(()=>{this.clearExpired(Date.now()-36e5).then(()=>{this._clearExpiredHourAgo()})},3e5),this._clearExpiredTimeoutId.unref()}_getConnection(){switch(this.clientType){case"pool":return Promise.resolve(this.client);case"sequelize":return this.client.connectionManager.getConnection();case"knex":return this.client.client.acquireConnection();case"typeorm":return Promise.resolve(this.client.driver.master);default:return Promise.resolve(this.client)}}_releaseConnection(e){switch(this.clientType){case"pool":return!0;case"sequelize":return this.client.connectionManager.releaseConnection(e);case"knex":return this.client.client.releaseConnection(e);case"typeorm":return!0;default:return!0}}_createTable(){return new Promise((e,t)=>{this._query({text:this._getCreateTableStmt()}).then(()=>{e()}).catch(r=>{r.code==="23505"?e():t(r)})})}_getCreateTableStmt(){return`CREATE TABLE IF NOT EXISTS ${this.tableName} (
8
+ expire = IF(expire <= ?, ?, expire);`,f=[this.dbName,this.tableName,t,r,l,u,r,r,u,l]),e.query(h,f,g=>{if(g)return e.rollback(),a(g);e.query("SELECT points, expire FROM ??.?? WHERE `key` = ?;",[this.dbName,this.tableName,t],(m,p)=>{if(m)return e.rollback(),a(m);e.query("COMMIT",d=>{if(d)return e.rollback(),a(d);o(p)})})})})})}_upsert(e,t,r,s=!1){return this.tableCreated?new Promise((n,o)=>{this._getConnection().then(a=>{this._upsertTransaction(a,e,t,r,s).then(c=>{n(c),this._releaseConnection(a)}).catch(c=>{o(c),this._releaseConnection(a)})}).catch(a=>{o(a)})}):Promise.reject(Error("Table is not created yet"))}_get(e){return this.tableCreated?new Promise((t,r)=>{this._getConnection().then(s=>{s.query("SELECT points, expire FROM ??.?? WHERE `key` = ? AND (`expire` > ? OR `expire` IS NULL)",[this.dbName,this.tableName,e,Date.now()],(n,o)=>{n?r(n):o.length===0?t(null):t(o),this._releaseConnection(s)})}).catch(s=>{r(s)})}):Promise.reject(Error("Table is not created yet"))}_delete(e){return this.tableCreated?new Promise((t,r)=>{this._getConnection().then(s=>{s.query("DELETE FROM ??.?? WHERE `key` = ?",[this.dbName,this.tableName,e],(n,o)=>{n?r(n):t(o.affectedRows>0),this._releaseConnection(s)})}).catch(s=>{r(s)})}):Promise.reject(Error("Table is not created yet"))}};cr.exports=Ke});var hr=y((ta,ur)=>{var xs=Z(),_s=M(),Ge=class extends xs{constructor(e,t=null){super(e),this.client=e.storeClient,this.clientType=e.storeType,this.tableName=e.tableName,this.clearExpiredByTimeout=e.clearExpiredByTimeout,this.tableCreated=e.tableCreated,this.tableCreated?typeof t=="function"&&t():this._createTable().then(()=>{this.tableCreated=!0,this.clearExpiredByTimeout&&this._clearExpiredHourAgo(),typeof t=="function"&&t()}).catch(r=>{if(typeof t=="function")t(r);else throw r})}clearExpired(e){return new Promise(t=>{let r={name:"rlflx-clear-expired",text:`DELETE FROM ${this.tableName} WHERE expire < $1`,values:[e]};this._query(r).then(()=>{t()}).catch(()=>{t()})})}_clearExpiredHourAgo(){this._clearExpiredTimeoutId&&clearTimeout(this._clearExpiredTimeoutId),this._clearExpiredTimeoutId=setTimeout(()=>{this.clearExpired(Date.now()-36e5).then(()=>{this._clearExpiredHourAgo()})},3e5),this._clearExpiredTimeoutId.unref()}_getConnection(){switch(this.clientType){case"pool":return Promise.resolve(this.client);case"sequelize":return this.client.connectionManager.getConnection();case"knex":return this.client.client.acquireConnection();case"typeorm":return Promise.resolve(this.client.driver.master);default:return Promise.resolve(this.client)}}_releaseConnection(e){switch(this.clientType){case"pool":return!0;case"sequelize":return this.client.connectionManager.releaseConnection(e);case"knex":return this.client.client.releaseConnection(e);case"typeorm":return!0;default:return!0}}_createTable(){return new Promise((e,t)=>{this._query({text:this._getCreateTableStmt()}).then(()=>{e()}).catch(r=>{r.code==="23505"?e():t(r)})})}_getCreateTableStmt(){return`CREATE TABLE IF NOT EXISTS ${this.tableName} (
9
9
  key varchar(255) PRIMARY KEY,
10
10
  points integer NOT NULL DEFAULT 0,
11
11
  expire bigint
12
- );`}get clientType(){return this._clientType}set clientType(e){let t=this.client.constructor.name;if(typeof e>"u")if(t==="Client")e="client";else if(t==="Pool"||t==="BoundPool")e="pool";else if(t==="Sequelize")e="sequelize";else throw new Error("storeType is not defined");this._clientType=e.toLowerCase()}get tableName(){return this._tableName}set tableName(e){this._tableName=typeof e>"u"?this.keyPrefix:e}get tableCreated(){return this._tableCreated}set tableCreated(e){this._tableCreated=typeof e>"u"?!1:!!e}get clearExpiredByTimeout(){return this._clearExpiredByTimeout}set clearExpiredByTimeout(e){this._clearExpiredByTimeout=typeof e>"u"?!0:!!e}_getRateLimiterRes(e,t,r){let n=new Sn,s=r.rows[0];return n.isFirstInDuration=t===s.points,n.consumedPoints=n.isFirstInDuration?t:s.points,n.remainingPoints=Math.max(this.points-n.consumedPoints,0),n.msBeforeNext=s.expire?Math.max(s.expire-Date.now(),0):-1,n}_query(e){let r={name:`${this.tableName.toLowerCase()}:${e.name}`,text:e.text,values:e.values};return new Promise((n,s)=>{this._getConnection().then(o=>{o.query(r).then(a=>{n(a),this._releaseConnection(o)}).catch(a=>{s(a),this._releaseConnection(o)})}).catch(o=>{s(o)})})}_upsert(e,t,r,n=!1){if(!this.tableCreated)return Promise.reject(Error("Table is not created yet"));let s=r>0?Date.now()+r:null,o=n?" $3 ":` CASE
12
+ );`}get clientType(){return this._clientType}set clientType(e){let t=this.client.constructor.name;if(typeof e>"u")if(t==="Client")e="client";else if(t==="Pool"||t==="BoundPool")e="pool";else if(t==="Sequelize")e="sequelize";else throw new Error("storeType is not defined");this._clientType=e.toLowerCase()}get tableName(){return this._tableName}set tableName(e){this._tableName=typeof e>"u"?this.keyPrefix:e}get tableCreated(){return this._tableCreated}set tableCreated(e){this._tableCreated=typeof e>"u"?!1:!!e}get clearExpiredByTimeout(){return this._clearExpiredByTimeout}set clearExpiredByTimeout(e){this._clearExpiredByTimeout=typeof e>"u"?!0:!!e}_getRateLimiterRes(e,t,r){let s=new _s,n=r.rows[0];return s.isFirstInDuration=t===n.points,s.consumedPoints=s.isFirstInDuration?t:n.points,s.remainingPoints=Math.max(this.points-s.consumedPoints,0),s.msBeforeNext=n.expire?Math.max(n.expire-Date.now(),0):-1,s}_query(e){let r={name:`${this.tableName.toLowerCase()}:${e.name}`,text:e.text,values:e.values};return new Promise((s,n)=>{this._getConnection().then(o=>{o.query(r).then(a=>{s(a),this._releaseConnection(o)}).catch(a=>{n(a),this._releaseConnection(o)})}).catch(o=>{n(o)})})}_upsert(e,t,r,s=!1){if(!this.tableCreated)return Promise.reject(Error("Table is not created yet"));let n=r>0?Date.now()+r:null,o=s?" $3 ":` CASE
13
13
  WHEN ${this.tableName}.expire <= $4 THEN $3
14
14
  ELSE ${this.tableName}.expire
15
- END `;return this._query({name:n?"rlflx-upsert-force":"rlflx-upsert",text:`
15
+ END `;return this._query({name:s?"rlflx-upsert-force":"rlflx-upsert",text:`
16
16
  INSERT INTO ${this.tableName} VALUES ($1, $2, $3)
17
17
  ON CONFLICT(key) DO UPDATE SET
18
18
  points = CASE
19
- WHEN (${this.tableName}.expire <= $4 OR 1=${n?1:0}) THEN $2
19
+ WHEN (${this.tableName}.expire <= $4 OR 1=${s?1:0}) THEN $2
20
20
  ELSE ${this.tableName}.points + ($2)
21
21
  END,
22
22
  expire = ${o}
23
- RETURNING points, expire;`,values:[e,t,s,Date.now()]})}_get(e){return this.tableCreated?new Promise((t,r)=>{this._query({name:"rlflx-get",text:`
24
- SELECT points, expire FROM ${this.tableName} WHERE key = $1 AND (expire > $2 OR expire IS NULL);`,values:[e,Date.now()]}).then(n=>{n.rowCount===0&&(n=null),t(n)}).catch(n=>{r(n)})}):Promise.reject(Error("Table is not created yet"))}_delete(e){return this.tableCreated?this._query({name:"rlflx-delete",text:`DELETE FROM ${this.tableName} WHERE key = $1`,values:[e]}).then(t=>t.rowCount>0):Promise.reject(Error("Table is not created yet"))}};br.exports=We});var wr=E(()=>{});var gr=E(()=>{});var Er=E((za,xr)=>{xr.exports=class{constructor(e,t,r=null){this.value=e,this.expiresAt=t,this.timeoutId=r}get value(){return this._value}set value(e){this._value=parseInt(e)}get expiresAt(){return this._expiresAt}set expiresAt(e){!(e instanceof Date)&&Number.isInteger(e)&&(e=new Date(e)),this._expiresAt=e}get timeoutId(){return this._timeoutId}set timeoutId(e){this._timeoutId=e}}});var Sr=E((Va,_r)=>{var Cn=Er(),Ke=v();_r.exports=class{constructor(){this._storage={}}incrby(e,t,r){if(this._storage[e]){let n=this._storage[e].expiresAt?this._storage[e].expiresAt.getTime()-new Date().getTime():-1;return n!==0?(this._storage[e].value=this._storage[e].value+t,new Ke(0,n,this._storage[e].value,!1)):this.set(e,t,r)}return this.set(e,t,r)}set(e,t,r){let n=r*1e3;return this._storage[e]&&this._storage[e].timeoutId&&clearTimeout(this._storage[e].timeoutId),this._storage[e]=new Cn(t,n>0?new Date(Date.now()+n):null),n>0&&(this._storage[e].timeoutId=setTimeout(()=>{delete this._storage[e]},n),this._storage[e].timeoutId.unref&&this._storage[e].timeoutId.unref()),new Ke(0,n===0?-1:n,this._storage[e].value,!0)}get(e){if(this._storage[e]){let t=this._storage[e].expiresAt?this._storage[e].expiresAt.getTime()-new Date().getTime():-1;return new Ke(0,t,this._storage[e].value,!1)}return null}delete(e){return this._storage[e]?(this._storage[e].timeoutId&&clearTimeout(this._storage[e].timeoutId),delete this._storage[e],!0):!1}}});var je=E((Wa,Ar)=>{var An=le(),Rn=Sr(),Cr=v(),Ge=class extends An{constructor(e={}){super(e),this._memoryStorage=new Rn}consume(e,t=1,r={}){return new Promise((n,s)=>{let o=this.getKey(e),a=this._getKeySecDuration(r),c=this._memoryStorage.incrby(o,t,a);if(c.remainingPoints=Math.max(this.points-c.consumedPoints,0),c.consumedPoints>this.points)this.blockDuration>0&&c.consumedPoints<=this.points+t&&(c=this._memoryStorage.set(o,c.consumedPoints,this.blockDuration)),s(c);else if(this.execEvenly&&c.msBeforeNext>0&&!c.isFirstInDuration){let u=Math.ceil(c.msBeforeNext/(c.remainingPoints+2));u<this.execEvenlyMinDelayMs&&(u=c.consumedPoints*this.execEvenlyMinDelayMs),setTimeout(n,u,c)}else n(c)})}penalty(e,t=1,r={}){let n=this.getKey(e);return new Promise(s=>{let o=this._getKeySecDuration(r),a=this._memoryStorage.incrby(n,t,o);a.remainingPoints=Math.max(this.points-a.consumedPoints,0),s(a)})}reward(e,t=1,r={}){let n=this.getKey(e);return new Promise(s=>{let o=this._getKeySecDuration(r),a=this._memoryStorage.incrby(n,-t,o);a.remainingPoints=Math.max(this.points-a.consumedPoints,0),s(a)})}block(e,t){let r=t*1e3,n=this.points+1;return this._memoryStorage.set(this.getKey(e),n,t),Promise.resolve(new Cr(0,r===0?-1:r,n))}set(e,t,r){let n=(r>=0?r:this.duration)*1e3;return this._memoryStorage.set(this.getKey(e),t,r),Promise.resolve(new Cr(0,n===0?-1:n,t))}get(e){let t=this._memoryStorage.get(this.getKey(e));return t!==null&&(t.remainingPoints=Math.max(this.points-t.consumedPoints,0)),Promise.resolve(t)}delete(e){return Promise.resolve(this._memoryStorage.delete(this.getKey(e)))}};Ar.exports=Ge});var kr=E((Ka,Nr)=>{var Rr=wr(),In=gr(),Tn=le(),Tr=je(),Ln=v(),D="rate_limiter_flexible",te=null,Ir=function(i,e,t,r){let n;r===null||r===!0||r===!1?n=r:n={remainingPoints:r.remainingPoints,msBeforeNext:r.msBeforeNext,consumedPoints:r.consumedPoints,isFirstInDuration:r.isFirstInDuration},i.send({channel:D,keyPrefix:e.keyPrefix,promiseId:e.promiseId,type:t,data:n})},Lr=function(i){setTimeout(()=>{this._initiated?process.send(i):typeof this._promises[i.promiseId]<"u"&&Lr.call(this,i)},30)},Z=function(i,e,t,r,n){let s={channel:D,keyPrefix:this.keyPrefix,func:i,promiseId:e,data:{key:t,arg:r,opts:n}};this._initiated?process.send(s):Lr.call(this,s)},Mr=function(i,e){if(!e||e.channel!==D||typeof this._rateLimiters[e.keyPrefix]>"u")return!1;let t;switch(e.func){case"consume":t=this._rateLimiters[e.keyPrefix].consume(e.data.key,e.data.arg,e.data.opts);break;case"penalty":t=this._rateLimiters[e.keyPrefix].penalty(e.data.key,e.data.arg,e.data.opts);break;case"reward":t=this._rateLimiters[e.keyPrefix].reward(e.data.key,e.data.arg,e.data.opts);break;case"block":t=this._rateLimiters[e.keyPrefix].block(e.data.key,e.data.arg,e.data.opts);break;case"get":t=this._rateLimiters[e.keyPrefix].get(e.data.key,e.data.opts);break;case"delete":t=this._rateLimiters[e.keyPrefix].delete(e.data.key,e.data.opts);break;default:return!1}t&&t.then(r=>{Ir(i,e,"resolve",r)}).catch(r=>{Ir(i,e,"reject",r)})},Mn=function(i){if(!i||i.channel!==D||i.keyPrefix!==this.keyPrefix)return!1;if(this._promises[i.promiseId]){clearTimeout(this._promises[i.promiseId].timeoutId);let e;switch(i.data===null||i.data===!0||i.data===!1?e=i.data:e=new Ln(i.data.remainingPoints,i.data.msBeforeNext,i.data.consumedPoints,i.data.isFirstInDuration),i.type){case"resolve":this._promises[i.promiseId].resolve(e);break;case"reject":this._promises[i.promiseId].reject(e);break;default:throw new Error(`RateLimiterCluster: no such message type '${i.type}'`)}delete this._promises[i.promiseId]}},Nn=function(){return{points:this.points,duration:this.duration,blockDuration:this.blockDuration,execEvenly:this.execEvenly,execEvenlyMinDelayMs:this.execEvenlyMinDelayMs,keyPrefix:this.keyPrefix}},ee=function(i,e){let t=process.hrtime(),r=t[0].toString()+t[1].toString();return typeof this._promises[r]<"u"&&(r+=In.randomBytes(12).toString("base64")),this._promises[r]={resolve:i,reject:e,timeoutId:setTimeout(()=>{delete this._promises[r],e(new Error("RateLimiterCluster timeout: no answer from master in time"))},this.timeoutMs)},r},He=class{constructor(){if(te)return te;this._rateLimiters={},Rr.setMaxListeners(0),Rr.on("message",(e,t)=>{t&&t.channel===D&&t.type==="init"?(typeof this._rateLimiters[t.opts.keyPrefix]>"u"&&(this._rateLimiters[t.opts.keyPrefix]=new Tr(t.opts)),e.send({channel:D,type:"init",keyPrefix:t.opts.keyPrefix})):Mr.call(this,e,t)}),te=this}},Qe=class{constructor(e){if(te)return te;this._rateLimiters={},e.launchBus((t,r)=>{r.on("process:msg",n=>{let s=n.raw;if(s&&s.channel===D&&s.type==="init")typeof this._rateLimiters[s.opts.keyPrefix]>"u"&&(this._rateLimiters[s.opts.keyPrefix]=new Tr(s.opts)),e.sendDataToProcessId(n.process.pm_id,{data:{},topic:D,channel:D,type:"init",keyPrefix:s.opts.keyPrefix},(o,a)=>{o&&console.log(o,a)});else{let o={send:a=>{let c=a;c.topic=D,typeof c.data>"u"&&(c.data={}),e.sendDataToProcessId(n.process.pm_id,c,(u,l)=>{u&&console.log(u,l)})}};Mr.call(this,o,s)}})}),te=this}},Xe=class extends Tn{get timeoutMs(){return this._timeoutMs}set timeoutMs(e){this._timeoutMs=typeof e>"u"?5e3:Math.abs(parseInt(e))}constructor(e={}){super(e),process.setMaxListeners(0),this.timeoutMs=e.timeoutMs,this._initiated=!1,process.on("message",t=>{t&&t.channel===D&&t.type==="init"&&t.keyPrefix===this.keyPrefix?this._initiated=!0:Mn.call(this,t)}),process.send({channel:D,type:"init",opts:Nn.call(this)}),this._promises={}}consume(e,t=1,r={}){return new Promise((n,s)=>{let o=ee.call(this,n,s);Z.call(this,"consume",o,e,t,r)})}penalty(e,t=1,r={}){return new Promise((n,s)=>{let o=ee.call(this,n,s);Z.call(this,"penalty",o,e,t,r)})}reward(e,t=1,r={}){return new Promise((n,s)=>{let o=ee.call(this,n,s);Z.call(this,"reward",o,e,t,r)})}block(e,t,r={}){return new Promise((n,s)=>{let o=ee.call(this,n,s);Z.call(this,"block",o,e,t,r)})}get(e,t={}){return new Promise((r,n)=>{let s=ee.call(this,r,n);Z.call(this,"get",s,e,t)})}delete(e,t={}){return new Promise((r,n)=>{let s=ee.call(this,r,n);Z.call(this,"delete",s,e,t)})}};Nr.exports={RateLimiterClusterMaster:He,RateLimiterClusterMasterPM2:Qe,RateLimiterCluster:Xe}});var Pr=E((Ga,vr)=>{var kn=J(),vn=v(),Ye=class extends kn{constructor(e){super(e),this.client=e.storeClient}_getRateLimiterRes(e,t,r){let n=new vn;return n.consumedPoints=parseInt(r.consumedPoints),n.isFirstInDuration=r.consumedPoints===t,n.remainingPoints=Math.max(this.points-n.consumedPoints,0),n.msBeforeNext=r.msBeforeNext,n}_upsert(e,t,r,n=!1,s={}){return new Promise((o,a)=>{let c=Date.now(),u=Math.floor(r/1e3);n?this.client.set(e,t,u,l=>{l?a(l):this.client.set(`${e}_expire`,u>0?c+u*1e3:-1,u,()=>{let h={consumedPoints:t,msBeforeNext:u>0?u*1e3:-1};o(h)})}):this.client.incr(e,t,(l,h)=>{l||h===!1?this.client.add(e,t,u,(p,_)=>{if(p||!_)if(typeof s.attemptNumber>"u"||s.attemptNumber<3){let f=Object.assign({},s);f.attemptNumber=f.attemptNumber?f.attemptNumber+1:1,this._upsert(e,t,r,n,f).then(d=>o(d)).catch(d=>a(d))}else a(new Error("Can not add key"));else this.client.add(`${e}_expire`,u>0?c+u*1e3:-1,u,()=>{let f={consumedPoints:t,msBeforeNext:u>0?u*1e3:-1};o(f)})}):this.client.get(`${e}_expire`,(p,_)=>{if(p)a(p);else{let f=_===!1?0:_,d={consumedPoints:h,msBeforeNext:f>=0?Math.max(f-c,0):-1};o(d)}})})})}_get(e){return new Promise((t,r)=>{let n=Date.now();this.client.get(e,(s,o)=>{o?this.client.get(`${e}_expire`,(a,c)=>{if(a)r(a);else{let u=c===!1?0:c,l={consumedPoints:o,msBeforeNext:u>=0?Math.max(u-n,0):-1};t(l)}}):t(null)})})}_delete(e){return new Promise((t,r)=>{this.client.del(e,(n,s)=>{n?r(n):s===!1?t(s):this.client.del(`${e}_expire`,o=>{o?r(o):t(s)})})})}};vr.exports=Ye});var Or=E((Ha,Br)=>{var Dr=v();Br.exports=class{constructor(e={}){this.limiter=e.limiter,this.blackList=e.blackList,this.whiteList=e.whiteList,this.isBlackListed=e.isBlackListed,this.isWhiteListed=e.isWhiteListed,this.runActionAnyway=e.runActionAnyway}get limiter(){return this._limiter}set limiter(e){if(typeof e>"u")throw new Error("limiter is not set");this._limiter=e}get runActionAnyway(){return this._runActionAnyway}set runActionAnyway(e){this._runActionAnyway=typeof e>"u"?!1:e}get blackList(){return this._blackList}set blackList(e){this._blackList=Array.isArray(e)?e:[]}get isBlackListed(){return this._isBlackListed}set isBlackListed(e){if(typeof e>"u"&&(e=()=>!1),typeof e!="function")throw new Error("isBlackListed must be function");this._isBlackListed=e}get whiteList(){return this._whiteList}set whiteList(e){this._whiteList=Array.isArray(e)?e:[]}get isWhiteListed(){return this._isWhiteListed}set isWhiteListed(e){if(typeof e>"u"&&(e=()=>!1),typeof e!="function")throw new Error("isWhiteListed must be function");this._isWhiteListed=e}isBlackListedSomewhere(e){return this.blackList.indexOf(e)>=0||this.isBlackListed(e)}isWhiteListedSomewhere(e){return this.whiteList.indexOf(e)>=0||this.isWhiteListed(e)}getBlackRes(){return new Dr(0,Number.MAX_SAFE_INTEGER,0,!1)}getWhiteRes(){return new Dr(Number.MAX_SAFE_INTEGER,0,0,!1)}rejectBlack(){return Promise.reject(this.getBlackRes())}resolveBlack(){return Promise.resolve(this.getBlackRes())}resolveWhite(){return Promise.resolve(this.getWhiteRes())}consume(e,t=1){let r;return this.isWhiteListedSomewhere(e)?r=this.resolveWhite():this.isBlackListedSomewhere(e)&&(r=this.rejectBlack()),typeof r>"u"?this.limiter.consume(e,t):(this.runActionAnyway&&this.limiter.consume(e,t).catch(()=>{}),r)}block(e,t){let r;return this.isWhiteListedSomewhere(e)?r=this.resolveWhite():this.isBlackListedSomewhere(e)&&(r=this.resolveBlack()),typeof r>"u"?this.limiter.block(e,t):(this.runActionAnyway&&this.limiter.block(e,t).catch(()=>{}),r)}penalty(e,t){let r;return this.isWhiteListedSomewhere(e)?r=this.resolveWhite():this.isBlackListedSomewhere(e)&&(r=this.resolveBlack()),typeof r>"u"?this.limiter.penalty(e,t):(this.runActionAnyway&&this.limiter.penalty(e,t).catch(()=>{}),r)}reward(e,t){let r;return this.isWhiteListedSomewhere(e)?r=this.resolveWhite():this.isBlackListedSomewhere(e)&&(r=this.resolveBlack()),typeof r>"u"?this.limiter.reward(e,t):(this.runActionAnyway&&this.limiter.reward(e,t).catch(()=>{}),r)}get(e){let t;return this.isWhiteListedSomewhere(e)?t=this.resolveWhite():this.isBlackListedSomewhere(e)&&(t=this.resolveBlack()),typeof t>"u"||this.runActionAnyway?this.limiter.get(e):t}delete(e){return this.limiter.delete(e)}}});var Ur=E((Xa,Fr)=>{var Pn=le();Fr.exports=class{constructor(...e){if(e.length<1)throw new Error("RateLimiterUnion: at least one limiter have to be passed");e.forEach(t=>{if(!(t instanceof Pn))throw new Error("RateLimiterUnion: all limiters have to be instance of RateLimiterAbstract")}),this._limiters=e}consume(e,t=1){return new Promise((r,n)=>{let s=[];this._limiters.forEach(o=>{s.push(o.consume(e,t).catch(a=>({rejected:!0,rej:a})))}),Promise.all(s).then(o=>{let a={},c=!1;o.forEach(u=>{u.rejected===!0&&(c=!0)});for(let u=0;u<o.length;u++)c&&o[u].rejected===!0?a[this._limiters[u].keyPrefix]=o[u].rej:c||(a[this._limiters[u].keyPrefix]=o[u]);c?n(a):r(a)})})}}});var zr=E((Ja,qr)=>{qr.exports=class extends Error{constructor(e,t){super(),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.name="CustomError",this.message=e,t&&(this.extra=t)}}});var Kr=E((ec,Wr)=>{var $r=zr(),Vr=4294967295,Je="limiter";Wr.exports=class{constructor(e,t={maxQueueSize:Vr}){this._queueLimiters={KEY_DEFAULT:new _e(e,t)},this._limiterFlexible=e,this._maxQueueSize=t.maxQueueSize}getTokensRemaining(e=Je){return this._queueLimiters[e]?this._queueLimiters[e].getTokensRemaining():Promise.resolve(this._limiterFlexible.points)}removeTokens(e,t=Je){return this._queueLimiters[t]||(this._queueLimiters[t]=new _e(this._limiterFlexible,{key:t,maxQueueSize:this._maxQueueSize})),this._queueLimiters[t].removeTokens(e)}};var _e=class{constructor(e,t={maxQueueSize:Vr,key:Je}){this._key=t.key,this._waitTimeout=null,this._queue=[],this._limiterFlexible=e,this._maxQueueSize=t.maxQueueSize}getTokensRemaining(){return this._limiterFlexible.get(this._key).then(e=>e!==null?e.remainingPoints:this._limiterFlexible.points)}removeTokens(e){let t=this;return new Promise((r,n)=>{if(e>t._limiterFlexible.points){n(new $r(`Requested tokens ${e} exceeds maximum ${t._limiterFlexible.points} tokens per interval`));return}t._queue.length>0?t._queueRequest.call(t,r,n,e):t._limiterFlexible.consume(t._key,e).then(s=>{r(s.remainingPoints)}).catch(s=>{s instanceof Error?n(s):(t._queueRequest.call(t,r,n,e),t._waitTimeout===null&&(t._waitTimeout=setTimeout(t._processFIFO.bind(t),s.msBeforeNext)))})})}_queueRequest(e,t,r){let n=this;n._queue.length<n._maxQueueSize?n._queue.push({resolve:e,reject:t,tokens:r}):t(new $r(`Number of requests reached it's maximum ${n._maxQueueSize}`))}_processFIFO(){let e=this;if(e._waitTimeout!==null&&(clearTimeout(e._waitTimeout),e._waitTimeout=null),e._queue.length===0)return;let t=e._queue.shift();e._limiterFlexible.consume(e._key,t.tokens).then(r=>{t.resolve(r.remainingPoints),e._processFIFO.call(e)}).catch(r=>{r instanceof Error?(t.reject(r),e._processFIFO.call(e)):(e._queue.unshift(t),e._waitTimeout===null&&(e._waitTimeout=setTimeout(e._processFIFO.bind(e),r.msBeforeNext)))})}}});var jr=E((rc,Gr)=>{var Ze=v();Gr.exports=class{constructor(e,t){this._rateLimiter=e,this._burstLimiter=t}_combineRes(e,t){return e?new Ze(e.remainingPoints,Math.min(e.msBeforeNext,t?t.msBeforeNext:0),e.consumedPoints,e.isFirstInDuration):null}consume(e,t=1,r={}){return this._rateLimiter.consume(e,t,r).catch(n=>n instanceof Ze?this._burstLimiter.consume(e,t,r).then(s=>Promise.resolve(this._combineRes(n,s))).catch(s=>s instanceof Ze?Promise.reject(this._combineRes(n,s)):Promise.reject(s)):Promise.reject(n))}get(e){return Promise.all([this._rateLimiter.get(e),this._burstLimiter.get(e)]).then(([t,r])=>this._combineRes(t,r))}get points(){return this._rateLimiter.points}}});var Qr=E((ic,Hr)=>{var Dn=ur(),Bn=dr(),On=pr(),Fn=yr(),{RateLimiterClusterMaster:Un,RateLimiterClusterMasterPM2:qn,RateLimiterCluster:zn}=kr(),$n=je(),Vn=Pr(),Wn=Or(),Kn=Ur(),Gn=Kr(),jn=jr(),Hn=v();Hr.exports={RateLimiterRedis:Dn,RateLimiterMongo:Bn,RateLimiterMySQL:On,RateLimiterPostgres:Fn,RateLimiterMemory:$n,RateLimiterMemcache:Vn,RateLimiterClusterMaster:Un,RateLimiterClusterMasterPM2:qn,RateLimiterCluster:zn,RLWrapperBlackAndWhite:Wn,RateLimiterUnion:Kn,RateLimiterQueue:Gn,BurstyRateLimiter:jn,RateLimiterRes:Hn}});var Ri=E((Cl,Ai)=>{Ai.exports=Rt;var Ci=128,ao=127,co=~ao,lo=Math.pow(2,31);function Rt(i,e,t){if(Number.MAX_SAFE_INTEGER&&i>Number.MAX_SAFE_INTEGER)throw Rt.bytes=0,new RangeError("Could not encode varint");e=e||[],t=t||0;for(var r=t;i>=lo;)e[t++]=i&255|Ci,i/=128;for(;i&co;)e[t++]=i&255|Ci,i>>>=7;return e[t]=i|0,Rt.bytes=t-r+1,e}});var Li=E((Al,Ti)=>{Ti.exports=It;var uo=128,Ii=127;function It(i,r){var t=0,r=r||0,n=0,s=r,o,a=i.length;do{if(s>=a||n>49)throw It.bytes=0,new RangeError("Could not decode varint");o=i[s++],t+=n<28?(o&Ii)<<n:(o&Ii)*Math.pow(2,n),n+=7}while(o>=uo);return It.bytes=s-r,t}});var Ni=E((Rl,Mi)=>{var ho=Math.pow(2,7),fo=Math.pow(2,14),mo=Math.pow(2,21),po=Math.pow(2,28),bo=Math.pow(2,35),yo=Math.pow(2,42),wo=Math.pow(2,49),go=Math.pow(2,56),xo=Math.pow(2,63);Mi.exports=function(i){return i<ho?1:i<fo?2:i<mo?3:i<po?4:i<bo?5:i<yo?6:i<wo?7:i<go?8:i<xo?9:10}});var vi=E((Il,ki)=>{ki.exports={encode:Ri(),decode:Li(),encodingLength:Ni()}});var Lo={};M(Lo,{mplex:()=>To});var z=class extends Error{code;props;constructor(e,t,r){super(e),this.code=t,this.name=r?.name??"CodeError",this.props=r??{}}};var k=ke(Ut(),1);function nn(i,e){if(i.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<i.length;n++){var s=i.charAt(n),o=s.charCodeAt(0);if(t[o]!==255)throw new TypeError(s+" is ambiguous");t[o]=n}var a=i.length,c=i.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function h(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var d=0,m=0,b=0,w=f.length;b!==w&&f[b]===0;)b++,d++;for(var x=(w-b)*l+1>>>0,g=new Uint8Array(x);b!==w;){for(var C=f[b],I=0,S=x-1;(C!==0||I<m)&&S!==-1;S--,I++)C+=256*g[S]>>>0,g[S]=C%a>>>0,C=C/a>>>0;if(C!==0)throw new Error("Non-zero carry");m=I,b++}for(var A=x-m;A!==x&&g[A]===0;)A++;for(var B=c.repeat(d);A<x;++A)B+=i.charAt(g[A]);return B}function p(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var d=0;if(f[d]!==" "){for(var m=0,b=0;f[d]===c;)m++,d++;for(var w=(f.length-d)*u+1>>>0,x=new Uint8Array(w);f[d];){var g=t[f.charCodeAt(d)];if(g===255)return;for(var C=0,I=w-1;(g!==0||C<b)&&I!==-1;I--,C++)g+=a*x[I]>>>0,x[I]=g%256>>>0,g=g/256>>>0;if(g!==0)throw new Error("Non-zero carry");b=C,d++}if(f[d]!==" "){for(var S=w-b;S!==w&&x[S]===0;)S++;for(var A=new Uint8Array(m+(w-S)),B=m;S!==w;)A[B++]=x[S++];return A}}}function _(f){var d=p(f);if(d)return d;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:p,decode:_}}var sn=nn,on=sn,qt=on;var Do=new Uint8Array(0);var zt=i=>{if(i instanceof Uint8Array&&i.constructor.name==="Uint8Array")return i;if(i instanceof ArrayBuffer)return new Uint8Array(i);if(ArrayBuffer.isView(i))return new Uint8Array(i.buffer,i.byteOffset,i.byteLength);throw new Error("Unknown type, must be binary type")};var ve=class{constructor(e,t,r){this.name=e,this.prefix=t,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Pe=class{constructor(e,t,r){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=r}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return $t(this,e)}},De=class{constructor(e){this.decoders=e}or(e){return $t(this,e)}decode(e){let t=e[0],r=this.decoders[t];if(r)return r.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},$t=(i,e)=>new De({...i.decoders||{[i.prefix]:i},...e.decoders||{[e.prefix]:e}}),Be=class{constructor(e,t,r,n){this.name=e,this.prefix=t,this.baseEncode=r,this.baseDecode=n,this.encoder=new ve(e,t,r),this.decoder=new Pe(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},Vt=({name:i,prefix:e,encode:t,decode:r})=>new Be(i,e,t,r),Oe=({prefix:i,name:e,alphabet:t})=>{let{encode:r,decode:n}=qt(t,e);return Vt({prefix:i,name:e,encode:r,decode:s=>zt(n(s))})},an=(i,e,t,r)=>{let n={};for(let l=0;l<e.length;++l)n[e[l]]=l;let s=i.length;for(;i[s-1]==="=";)--s;let o=new Uint8Array(s*t/8|0),a=0,c=0,u=0;for(let l=0;l<s;++l){let h=n[i[l]];if(h===void 0)throw new SyntaxError(`Non-${r} character`);c=c<<t|h,a+=t,a>=8&&(a-=8,o[u++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},cn=(i,e,t)=>{let r=e[e.length-1]==="=",n=(1<<t)-1,s="",o=0,a=0;for(let c=0;c<i.length;++c)for(a=a<<8|i[c],o+=8;o>t;)o-=t,s+=e[n&a>>o];if(o&&(s+=e[n&a<<t-o]),r)for(;s.length*t&7;)s+="=";return s},T=({name:i,prefix:e,bitsPerChar:t,alphabet:r})=>Vt({prefix:e,name:i,encode(n){return cn(n,r,t)},decode(n){return an(n,r,t,i)}});var Wt=T({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),zo=T({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$o=T({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Vo=T({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wo=T({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ko=T({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Go=T({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),jo=T({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ho=T({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Kt=Oe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Yo=Oe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Gt=T({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ea=T({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ta=T({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ra=T({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});k.default.formatters.b=i=>i==null?"undefined":Kt.baseEncode(i);k.default.formatters.t=i=>i==null?"undefined":Wt.baseEncode(i);k.default.formatters.m=i=>i==null?"undefined":Gt.baseEncode(i);k.default.formatters.p=i=>i==null?"undefined":i.toString();k.default.formatters.c=i=>i==null?"undefined":i.toString();k.default.formatters.k=i=>i==null?"undefined":i.toString();k.default.formatters.a=i=>i==null?"undefined":i.toString();function ln(i){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=i,e.destroy=()=>!0,e.extend=()=>e,e}function ge(i){let e=ln(`${i}:trace`);return k.default.enabled(`${i}:trace`)&&k.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,k.default)(`${i}:trace`)),Object.assign((0,k.default)(i),{error:(0,k.default)(`${i}:error`),trace:e})}var ce=class extends Error{constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function jt(i){if(i!=null){if(typeof i[Symbol.iterator]=="function")return i[Symbol.iterator]();if(typeof i[Symbol.asyncIterator]=="function")return i[Symbol.asyncIterator]();if(typeof i.next=="function")return i}throw new Error("argument is not an iterator or iterable")}function xe(i,e,t){let r=t??{},n=jt(i);async function*s(){let o,a=()=>{o?.()};for(e.addEventListener("abort",a);;){let c;try{if(e.aborted){let{abortMessage:l,abortCode:h}=r;throw new ce(l,h)}let u=new Promise((l,h)=>{o=()=>{let{abortMessage:p,abortCode:_}=r;h(new ce(p,_))}});c=await Promise.race([u,n.next()]),o=null}catch(u){e.removeEventListener("abort",a);let l=u.type==="aborted"&&e.aborted;if(l&&r.onAbort!=null&&r.onAbort(i),typeof n.return=="function")try{let h=n.return();h instanceof Promise&&h.catch(p=>{r.onReturnError!=null&&r.onReturnError(p)})}catch(h){r.onReturnError!=null&&r.onReturnError(h)}if(l&&r.returnOnAbort===!0)return;throw u}if(c.done===!0)break;yield c.value}e.removeEventListener("abort",a)}return s()}function F(){let i={};return i.promise=new Promise((e,t)=>{i.resolve=e,i.reject=t}),i}var Ee=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},X=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Ee(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new Ee(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Fe=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Y(i={}){return Qt(t=>{let r=t.shift();if(r==null)return{done:!0};if(r.error!=null)throw r.error;return{done:r.done===!0,value:r.value}},i)}function Ht(i={}){return Qt(t=>{let r,n=[];for(;!t.isEmpty()&&(r=t.shift(),r!=null);){if(r.error!=null)throw r.error;r.done===!1&&n.push(r.value)}return r==null?{done:!0}:{done:r.done===!0,value:n}},i)}function Qt(i,e){e=e??{};let t=e.onEnd,r=new X,n,s,o,a=F(),c=async()=>{try{return r.isEmpty()?o?{done:!0}:await new Promise((m,b)=>{s=w=>{s=null,r.push(w);try{m(i(r))}catch(x){b(x)}return n}}):i(r)}finally{r.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=F()})}},u=m=>s!=null?s(m):(r.push(m),n),l=m=>(r=new X,s!=null?s({error:m}):(r.push({error:m}),n)),h=m=>{if(o)return n;if(e?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:m})},p=m=>o?n:(o=!0,m!=null?l(m):u({done:!0})),_=()=>(r=new X,p(),{done:!0}),f=m=>(p(m),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:c,return:_,throw:f,push:h,end:p,get readableLength(){return r.size},onEmpty:async m=>{let b=m?.signal;if(b?.throwIfAborted(),r.isEmpty())return;let w,x;b!=null&&(w=new Promise((g,C)=>{x=()=>{C(new Fe)},b.addEventListener("abort",x)}));try{await Promise.race([a.promise,w])}finally{x!=null&&b!=null&&b?.removeEventListener("abort",x)}}},t==null)return n;let d=n;return n={[Symbol.asyncIterator](){return this},next(){return d.next()},throw(m){return d.throw(m),t!=null&&(t(m),t=void 0),{done:!0}},return(){return d.return(),t!=null&&(t(),t=void 0),{done:!0}},push:h,end(m){return d.end(m),t!=null&&(t(m),t=void 0),n},get readableLength(){return d.readableLength}},n}function un(i){return i[Symbol.asyncIterator]!=null}function hn(...i){let e=[];for(let t of i)un(t)||e.push(t);return e.length===i.length?function*(){for(let t of e)yield*t}():async function*(){let t=Y({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(i.map(async r=>{for await(let n of r)t.push(n)})),t.end()}catch(r){t.end(r)}}),yield*t}()}var Xt=hn;function Yt(i,...e){if(i==null)throw new Error("Empty pipeline");if(Ue(i)){let r=i;i=()=>r.source}else if(Zt(i)||Jt(i)){let r=i;i=()=>r}let t=[i,...e];if(t.length>1&&Ue(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let r=1;r<t.length-1;r++)Ue(t[r])&&(t[r]=dn(t[r]));return fn(...t)}var fn=(...i)=>{let e;for(;i.length>0;)e=i.shift()(e);return e},Jt=i=>i?.[Symbol.asyncIterator]!=null,Zt=i=>i?.[Symbol.iterator]!=null,Ue=i=>i==null?!1:i.sink!=null&&i.source!=null,dn=i=>e=>{let t=i.sink(e);if(t?.then!=null){let r=Y({objectMode:!0});t.then(()=>{r.end()},o=>{r.end(o)});let n,s=i.source;if(Jt(s))n=async function*(){yield*s,r.end()};else if(Zt(s))n=function*(){yield*s,r.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Xt(r,n())}return i.source};var Fi=ke(Qr(),1);function $(i){return globalThis.Buffer!=null?new Uint8Array(i.buffer,i.byteOffset,i.byteLength):i}function U(i=0){return globalThis.Buffer?.alloc!=null?$(globalThis.Buffer.alloc(i)):new Uint8Array(i)}function V(i=0){return globalThis.Buffer?.allocUnsafe!=null?$(globalThis.Buffer.allocUnsafe(i)):new Uint8Array(i)}function Se(i,e){e==null&&(e=i.reduce((n,s)=>n+s.length,0));let t=V(e),r=0;for(let n of i)t.set(n,r),r+=n.length;return $(t)}function et(i,e){if(i===e)return!0;if(i.byteLength!==e.byteLength)return!1;for(let t=0;t<i.byteLength;t++)if(i[t]!==e[t])return!1;return!0}var st={};M(st,{identity:()=>es});function Qn(i,e){if(i.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<i.length;n++){var s=i.charAt(n),o=s.charCodeAt(0);if(t[o]!==255)throw new TypeError(s+" is ambiguous");t[o]=n}var a=i.length,c=i.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function h(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var d=0,m=0,b=0,w=f.length;b!==w&&f[b]===0;)b++,d++;for(var x=(w-b)*l+1>>>0,g=new Uint8Array(x);b!==w;){for(var C=f[b],I=0,S=x-1;(C!==0||I<m)&&S!==-1;S--,I++)C+=256*g[S]>>>0,g[S]=C%a>>>0,C=C/a>>>0;if(C!==0)throw new Error("Non-zero carry");m=I,b++}for(var A=x-m;A!==x&&g[A]===0;)A++;for(var B=c.repeat(d);A<x;++A)B+=i.charAt(g[A]);return B}function p(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var d=0;if(f[d]!==" "){for(var m=0,b=0;f[d]===c;)m++,d++;for(var w=(f.length-d)*u+1>>>0,x=new Uint8Array(w);f[d];){var g=t[f.charCodeAt(d)];if(g===255)return;for(var C=0,I=w-1;(g!==0||C<b)&&I!==-1;I--,C++)g+=a*x[I]>>>0,x[I]=g%256>>>0,g=g/256>>>0;if(g!==0)throw new Error("Non-zero carry");b=C,d++}if(f[d]!==" "){for(var S=w-b;S!==w&&x[S]===0;)S++;for(var A=new Uint8Array(m+(w-S)),B=m;S!==w;)A[B++]=x[S++];return A}}}function _(f){var d=p(f);if(d)return d;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:p,decode:_}}var Xn=Qn,Yn=Xn,Xr=Yn;var dc=new Uint8Array(0);var Yr=(i,e)=>{if(i===e)return!0;if(i.byteLength!==e.byteLength)return!1;for(let t=0;t<i.byteLength;t++)if(i[t]!==e[t])return!1;return!0},q=i=>{if(i instanceof Uint8Array&&i.constructor.name==="Uint8Array")return i;if(i instanceof ArrayBuffer)return new Uint8Array(i);if(ArrayBuffer.isView(i))return new Uint8Array(i.buffer,i.byteOffset,i.byteLength);throw new Error("Unknown type, must be binary type")};var Jr=i=>new TextEncoder().encode(i),Zr=i=>new TextDecoder().decode(i);var tt=class{constructor(e,t,r){this.name=e,this.prefix=t,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},rt=class{constructor(e,t,r){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=r}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return ti(this,e)}},it=class{constructor(e){this.decoders=e}or(e){return ti(this,e)}decode(e){let t=e[0],r=this.decoders[t];if(r)return r.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},ti=(i,e)=>new it({...i.decoders||{[i.prefix]:i},...e.decoders||{[e.prefix]:e}}),nt=class{constructor(e,t,r,n){this.name=e,this.prefix=t,this.baseEncode=r,this.baseDecode=n,this.encoder=new tt(e,t,r),this.decoder=new rt(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},re=({name:i,prefix:e,encode:t,decode:r})=>new nt(i,e,t,r),W=({prefix:i,name:e,alphabet:t})=>{let{encode:r,decode:n}=Xr(t,e);return re({prefix:i,name:e,encode:r,decode:s=>q(n(s))})},Jn=(i,e,t,r)=>{let n={};for(let l=0;l<e.length;++l)n[e[l]]=l;let s=i.length;for(;i[s-1]==="=";)--s;let o=new Uint8Array(s*t/8|0),a=0,c=0,u=0;for(let l=0;l<s;++l){let h=n[i[l]];if(h===void 0)throw new SyntaxError(`Non-${r} character`);c=c<<t|h,a+=t,a>=8&&(a-=8,o[u++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},Zn=(i,e,t)=>{let r=e[e.length-1]==="=",n=(1<<t)-1,s="",o=0,a=0;for(let c=0;c<i.length;++c)for(a=a<<8|i[c],o+=8;o>t;)o-=t,s+=e[n&a>>o];if(o&&(s+=e[n&a<<t-o]),r)for(;s.length*t&7;)s+="=";return s},R=({name:i,prefix:e,bitsPerChar:t,alphabet:r})=>re({prefix:e,name:i,encode(n){return Zn(n,r,t)},decode(n){return Jn(n,r,t,i)}});var es=re({prefix:"\0",name:"identity",encode:i=>Zr(i),decode:i=>Jr(i)});var ot={};M(ot,{base2:()=>ts});var ts=R({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var at={};M(at,{base8:()=>rs});var rs=R({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ct={};M(ct,{base10:()=>is});var is=W({prefix:"9",name:"base10",alphabet:"0123456789"});var lt={};M(lt,{base16:()=>ns,base16upper:()=>ss});var ns=R({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ss=R({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ut={};M(ut,{base32:()=>ie,base32hex:()=>ls,base32hexpad:()=>hs,base32hexpadupper:()=>fs,base32hexupper:()=>us,base32pad:()=>as,base32padupper:()=>cs,base32upper:()=>os,base32z:()=>ds});var ie=R({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),os=R({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),as=R({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),cs=R({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ls=R({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),us=R({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),hs=R({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),fs=R({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ds=R({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ht={};M(ht,{base36:()=>ms,base36upper:()=>ps});var ms=W({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ps=W({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ft={};M(ft,{base58btc:()=>O,base58flickr:()=>bs});var O=W({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),bs=W({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var dt={};M(dt,{base64:()=>ys,base64pad:()=>ws,base64url:()=>gs,base64urlpad:()=>xs});var ys=R({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ws=R({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),gs=R({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),xs=R({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var mt={};M(mt,{base256emoji:()=>As});var ri=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Es=ri.reduce((i,e,t)=>(i[t]=e,i),[]),_s=ri.reduce((i,e,t)=>(i[e.codePointAt(0)]=t,i),[]);function Ss(i){return i.reduce((e,t)=>(e+=Es[t],e),"")}function Cs(i){let e=[];for(let t of i){let r=_s[t.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(r)}return new Uint8Array(e)}var As=re({prefix:"\u{1F680}",name:"base256emoji",encode:Ss,decode:Cs});var wt={};M(wt,{sha256:()=>Ws,sha512:()=>Ks});var Rs=si,ii=128,Is=127,Ts=~Is,Ls=Math.pow(2,31);function si(i,e,t){e=e||[],t=t||0;for(var r=t;i>=Ls;)e[t++]=i&255|ii,i/=128;for(;i&Ts;)e[t++]=i&255|ii,i>>>=7;return e[t]=i|0,si.bytes=t-r+1,e}var Ms=pt,Ns=128,ni=127;function pt(i,r){var t=0,r=r||0,n=0,s=r,o,a=i.length;do{if(s>=a)throw pt.bytes=0,new RangeError("Could not decode varint");o=i[s++],t+=n<28?(o&ni)<<n:(o&ni)*Math.pow(2,n),n+=7}while(o>=Ns);return pt.bytes=s-r,t}var ks=Math.pow(2,7),vs=Math.pow(2,14),Ps=Math.pow(2,21),Ds=Math.pow(2,28),Bs=Math.pow(2,35),Os=Math.pow(2,42),Fs=Math.pow(2,49),Us=Math.pow(2,56),qs=Math.pow(2,63),zs=function(i){return i<ks?1:i<vs?2:i<Ps?3:i<Ds?4:i<Bs?5:i<Os?6:i<Fs?7:i<Us?8:i<qs?9:10},$s={encode:Rs,decode:Ms,encodingLength:zs},Vs=$s,ue=Vs;var he=(i,e=0)=>[ue.decode(i,e),ue.decode.bytes],ne=(i,e,t=0)=>(ue.encode(i,e,t),e),se=i=>ue.encodingLength(i);var G=(i,e)=>{let t=e.byteLength,r=se(i),n=r+se(t),s=new Uint8Array(n+t);return ne(i,s,0),ne(t,s,r),s.set(e,n),new oe(i,t,e,s)},oi=i=>{let e=q(i),[t,r]=he(e),[n,s]=he(e.subarray(r)),o=e.subarray(r+s);if(o.byteLength!==n)throw new Error("Incorrect length");return new oe(t,n,o,e)},ai=(i,e)=>{if(i===e)return!0;{let t=e;return i.code===t.code&&i.size===t.size&&t.bytes instanceof Uint8Array&&Yr(i.bytes,t.bytes)}},oe=class{constructor(e,t,r,n){this.code=e,this.size=t,this.digest=r,this.bytes=n}};var yt=({name:i,code:e,encode:t})=>new bt(i,e,t),bt=class{constructor(e,t,r){this.name=e,this.code=t,this.encode=r}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?G(this.code,t):t.then(r=>G(this.code,r))}else throw Error("Unknown type, must be binary type")}};var li=i=>async e=>new Uint8Array(await crypto.subtle.digest(i,e)),Ws=yt({name:"sha2-256",code:18,encode:li("SHA-256")}),Ks=yt({name:"sha2-512",code:19,encode:li("SHA-512")});var gt={};M(gt,{identity:()=>Hs});var ui=0,Gs="identity",hi=q,js=i=>G(ui,hi(i)),Hs={code:ui,name:Gs,encode:hi,digest:js};var Pc=new TextEncoder,Dc=new TextDecoder;var fi=(i,e)=>{let{bytes:t,version:r}=i;switch(r){case 0:return Js(t,xt(i),e||O.encoder);default:return Zs(t,xt(i),e||ie.encoder)}};var di=new WeakMap,xt=i=>{let e=di.get(i);if(e==null){let t=new Map;return di.set(i,t),t}return e},Ae=class i{constructor(e,t,r,n){this.code=t,this.version=e,this.multihash=r,this.bytes=n,this["/"]=n}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==de)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==eo)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return i.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,r=G(e,t);return i.createV1(this.code,r)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return i.equals(this,e)}static equals(e,t){let r=t;return r&&e.code===r.code&&e.version===r.version&&ai(e.multihash,r.multihash)}toString(e){return fi(this,e)}toJSON(){return{"/":fi(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof i)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:r,code:n,multihash:s,bytes:o}=t;return new i(r,n,s,o||mi(r,n,s.bytes))}else if(t[to]===!0){let{version:r,multihash:n,code:s}=t,o=oi(n);return i.create(r,s,o)}else return null}static create(e,t,r){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(r.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==de)throw new Error(`Version 0 CID must use dag-pb (code: ${de}) block encoding`);return new i(e,t,r,r.bytes)}case 1:{let n=mi(e,t,r.bytes);return new i(e,t,r,n)}default:throw new Error("Invalid version")}}static createV0(e){return i.create(0,de,e)}static createV1(e,t){return i.create(1,e,t)}static decode(e){let[t,r]=i.decodeFirst(e);if(r.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=i.inspectBytes(e),r=t.size-t.multihashSize,n=q(e.subarray(r,r+t.multihashSize));if(n.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=n.subarray(t.multihashSize-t.digestSize),o=new oe(t.multihashCode,t.digestSize,s,n);return[t.version===0?i.createV0(o):i.createV1(t.codec,o),e.subarray(t.size)]}static inspectBytes(e){let t=0,r=()=>{let[h,p]=he(e.subarray(t));return t+=p,h},n=r(),s=de;if(n===18?(n=0,t=0):s=r(),n!==0&&n!==1)throw new RangeError(`Invalid CID version ${n}`);let o=t,a=r(),c=r(),u=t+c,l=u-o;return{version:n,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[r,n]=Ys(e,t),s=i.decode(n);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return xt(s).set(r,e),s}},Ys=(i,e)=>{switch(i[0]){case"Q":{let t=e||O;return[O.prefix,t.decode(`${O.prefix}${i}`)]}case O.prefix:{let t=e||O;return[O.prefix,t.decode(i)]}case ie.prefix:{let t=e||ie;return[ie.prefix,t.decode(i)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[i[0],e.decode(i)]}}},Js=(i,e,t)=>{let{prefix:r}=t;if(r!==O.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let n=e.get(r);if(n==null){let s=t.encode(i).slice(1);return e.set(r,s),s}else return n},Zs=(i,e,t)=>{let{prefix:r}=t,n=e.get(r);if(n==null){let s=t.encode(i);return e.set(r,s),s}else return n},de=112,eo=18,mi=(i,e,t)=>{let r=se(i),n=r+se(e),s=new Uint8Array(n+t.byteLength);return ne(i,s,0),ne(e,s,r),s.set(t,n),s},to=Symbol.for("@ipld/js-cid/CID");var Et={...st,...ot,...at,...ct,...lt,...ut,...ht,...ft,...dt,...mt},Kc={...wt,...gt};function bi(i,e,t,r){return{name:i,prefix:e,encoder:{name:i,prefix:e,encode:t},decoder:{decode:r}}}var pi=bi("utf8","u",i=>"u"+new TextDecoder("utf8").decode(i),i=>new TextEncoder().encode(i.substring(1))),_t=bi("ascii","a",i=>{let e="a";for(let t=0;t<i.length;t++)e+=String.fromCharCode(i[t]);return e},i=>{i=i.substring(1);let e=V(i.length);for(let t=0;t<i.length;t++)e[t]=i.charCodeAt(t);return e}),ro={utf8:pi,"utf-8":pi,hex:Et.base16,latin1:_t,ascii:_t,binary:_t,...Et},Re=ro;function St(i,e="utf8"){let t=Re[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?$(globalThis.Buffer.from(i,"utf-8")):t.decoder.decode(`${t.prefix}${i}`)}function me(i,e="utf8"){let t=Re[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(i.buffer,i.byteOffset,i.byteLength).toString("utf8"):t.encoder.encode(i).substring(1)}var wi=Symbol.for("@achingbrain/uint8arraylist");function yi(i,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let r of i){let n=t+r.byteLength;if(e<n)return{buf:r,index:e-t};t=n}throw new RangeError("index is out of bounds")}function Ie(i){return!!i?.[wi]}var L=class i{constructor(...e){Object.defineProperty(this,wi,{value:!0}),this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let r of e)if(r instanceof Uint8Array)t+=r.byteLength,this.bufs.push(r);else if(Ie(r))t+=r.byteLength,this.bufs.push(...r.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let r of e.reverse())if(r instanceof Uint8Array)t+=r.byteLength,this.bufs.unshift(r);else if(Ie(r))t+=r.byteLength,this.bufs.unshift(...r.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=yi(this.bufs,e);return t.buf[t.index]}set(e,t){let r=yi(this.bufs,e);r.buf[r.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let r=0;r<e.length;r++)this.set(t+r,e[r]);else if(Ie(e))for(let r=0;r<e.length;r++)this.set(t+r,e.get(r));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:r,length:n}=this._subList(e,t);return Se(r,n)}subarray(e,t){let{bufs:r,length:n}=this._subList(e,t);return r.length===1?r[0]:Se(r,n)}sublist(e,t){let{bufs:r,length:n}=this._subList(e,t),s=new i;return s.length=n,s.bufs=r,s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:[...this.bufs],length:this.length};let r=[],n=0;for(let s=0;s<this.bufs.length;s++){let o=this.bufs[s],a=n,c=a+o.byteLength;if(n=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){r.push(o);break}let h=e-a;r.push(o.subarray(h,h+(t-e)));break}if(u){if(e===0){r.push(o);continue}r.push(o.subarray(e-a));continue}if(l){if(t===c){r.push(o);break}r.push(o.subarray(0,t-a));break}r.push(o)}return{bufs:r,length:t-e}}indexOf(e,t=0){if(!Ie(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let r=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let n=r.byteLength;if(n===0)throw new TypeError("search must be at least 1 byte long");let s=256,o=new Int32Array(s);for(let h=0;h<s;h++)o[h]=-1;for(let h=0;h<n;h++)o[r[h]]=h;let a=o,c=this.byteLength-r.byteLength,u=r.byteLength-1,l;for(let h=t;h<=c;h+=l){l=0;for(let p=u;p>=0;p--){let _=this.get(h+p);if(r[p]!==_){l=Math.max(1,p-a[_]);break}}if(l===0)return h}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let r=V(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt8(0,t),this.write(r,e)}getInt16(e,t){let r=this.subarray(e,e+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt16(0,t)}setInt16(e,t,r){let n=U(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt16(0,t,r),this.write(n,e)}getInt32(e,t){let r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt32(0,t)}setInt32(e,t,r){let n=U(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt32(0,t,r),this.write(n,e)}getBigInt64(e,t){let r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigInt64(0,t)}setBigInt64(e,t,r){let n=U(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigInt64(0,t,r),this.write(n,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let r=V(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint8(0,t),this.write(r,e)}getUint16(e,t){let r=this.subarray(e,e+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint16(0,t)}setUint16(e,t,r){let n=U(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint16(0,t,r),this.write(n,e)}getUint32(e,t){let r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(0,t)}setUint32(e,t,r){let n=U(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(0,t,r),this.write(n,e)}getBigUint64(e,t){let r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigUint64(0,t)}setBigUint64(e,t,r){let n=U(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigUint64(0,t,r),this.write(n,e)}getFloat32(e,t){let r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat32(0,t)}setFloat32(e,t,r){let n=U(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat32(0,t,r),this.write(n,e)}getFloat64(e,t){let r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat64(0,t)}setFloat64(e,t,r){let n=U(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat64(0,t,r),this.write(n,e)}equals(e){if(e==null||!(e instanceof i)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!et(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let r=new i;return r.bufs=e,t==null&&(t=e.reduce((n,s)=>n+s.byteLength,0)),r.length=t,r}};var y;(function(i){i[i.NEW_STREAM=0]="NEW_STREAM",i[i.MESSAGE_RECEIVER=1]="MESSAGE_RECEIVER",i[i.MESSAGE_INITIATOR=2]="MESSAGE_INITIATOR",i[i.CLOSE_RECEIVER=3]="CLOSE_RECEIVER",i[i.CLOSE_INITIATOR=4]="CLOSE_INITIATOR",i[i.RESET_RECEIVER=5]="RESET_RECEIVER",i[i.RESET_INITIATOR=6]="RESET_INITIATOR"})(y||(y={}));var pe=Object.freeze({0:"NEW_STREAM",1:"MESSAGE_RECEIVER",2:"MESSAGE_INITIATOR",3:"CLOSE_RECEIVER",4:"CLOSE_INITIATOR",5:"RESET_RECEIVER",6:"RESET_INITIATOR"}),Ct=Object.freeze({NEW_STREAM:y.NEW_STREAM,MESSAGE:y.MESSAGE_INITIATOR,CLOSE:y.CLOSE_INITIATOR,RESET:y.RESET_INITIATOR}),gi=Object.freeze({MESSAGE:y.MESSAGE_RECEIVER,CLOSE:y.CLOSE_RECEIVER,RESET:y.RESET_RECEIVER});var At=1<<20,io=4<<20,Te=class{_buffer;_headerInfo;_maxMessageSize;_maxUnprocessedMessageQueueSize;constructor(e=At,t=io){this._buffer=new L,this._headerInfo=null,this._maxMessageSize=e,this._maxUnprocessedMessageQueueSize=t}write(e){if(e==null||e.length===0)return[];if(this._buffer.append(e),this._buffer.byteLength>this._maxUnprocessedMessageQueueSize)throw Object.assign(new Error("unprocessed message queue size too large!"),{code:"ERR_MSG_QUEUE_TOO_BIG"});let t=[];for(;this._buffer.length!==0;){if(this._headerInfo==null)try{this._headerInfo=this._decodeHeader(this._buffer)}catch(u){if(u.code==="ERR_MSG_TOO_BIG")throw u;break}let{id:r,type:n,length:s,offset:o}=this._headerInfo;if(this._buffer.length-o<s)break;let c={id:r,type:n};(n===y.NEW_STREAM||n===y.MESSAGE_INITIATOR||n===y.MESSAGE_RECEIVER)&&(c.data=this._buffer.sublist(o,o+s)),t.push(c),this._buffer.consume(o+s),this._headerInfo=null}return t}_decodeHeader(e){let{value:t,offset:r}=Ei(e),{value:n,offset:s}=Ei(e,r),o=t&7;if(pe[o]==null)throw new Error(`Invalid type received: ${o}`);if(n>this._maxMessageSize)throw Object.assign(new Error("message size too large!"),{code:"ERR_MSG_TOO_BIG"});return{id:t>>3,type:o,offset:r+s,length:n}}},no=128,xi=127;function Ei(i,e=0){let t=0,r=0,n=e,s,o=i.length;do{if(n>=o||r>49)throw e=0,new RangeError("Could not decode varint");s=i.get(n++),t+=r<28?(s&xi)<<r:(s&xi)*Math.pow(2,r),r+=7}while(s>=no);return e=n-e,{value:t,offset:e}}function so(i){return i[Symbol.asyncIterator]!=null}var Le=1024*1024,_i=(i,e)=>{e.append(i)};function oo(i,e){return so(i)?async function*(){let t=new L,r=!1,n=F(),s=Number(e?.size??Le);if((isNaN(s)||s===0||s<0)&&(s=Le),s!==Math.round(s))throw new Error("Batch size must be an integer");let o=e?.yieldAfter??0,a=e?.serialize??_i;for(Promise.resolve().then(async()=>{try{let c;for await(let u of i){if(a(u,t),t.byteLength>=s){clearTimeout(c),n.resolve();continue}c=setTimeout(()=>{n.resolve()},o)}clearTimeout(c),n.resolve()}catch(c){n.reject(c)}finally{r=!0}});!r;)if(await n.promise,n=F(),t.byteLength>0){let c=t;t=new L,yield c.subarray()}}():function*(){let t=new L,r=Number(e?.size??Le);if((isNaN(r)||r===0||r<0)&&(r=Le),r!==Math.round(r))throw new Error("Batch size must be an integer");let n=e?.serialize??_i;for(let s of i)n(s,t),t.byteLength>=r&&(yield t.subarray(0,r),t.consume(r));t.byteLength>0&&(yield t.subarray())}()}var Si=oo;var ae=ke(vi(),1);function Tt(i){return new Uint8Array(i)}var Lt=10*1024,Mt=class{_pool;_poolOffset;constructor(){this._pool=Tt(Lt),this._poolOffset=0}write(e,t){let r=this._pool,n=this._poolOffset;ae.default.encode(e.id<<3|e.type,r,n),n+=ae.default.encode.bytes??0,(e.type===y.NEW_STREAM||e.type===y.MESSAGE_INITIATOR||e.type===y.MESSAGE_RECEIVER)&&e.data!=null?ae.default.encode(e.data.length,r,n):ae.default.encode(0,r,n),n+=ae.default.encode.bytes??0;let s=r.subarray(this._poolOffset,n);Lt-n<100?(this._pool=Tt(Lt),this._poolOffset=0):this._poolOffset=n,t.append(s),(e.type===y.NEW_STREAM||e.type===y.MESSAGE_INITIATOR||e.type===y.MESSAGE_RECEIVER)&&e.data!=null&&t.append(e.data)}},Pi=new Mt;async function*Di(i,e=0){if(e==null||e===0){for await(let t of i){let r=new L;for(let n of t)Pi.write(n,r);yield r.subarray()}return}yield*Si(i,{size:e,serialize:(t,r)=>{for(let n of t)Pi.write(n,r)}})}var Eo="ERR_STREAM_RESET",_o="ERR_SINK_INVALID_STATE";function Nt(i){return i!=null&&typeof i.then=="function"}var Me=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;sinkController;sinkEnd;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;log;constructor(e){this.sinkController=new AbortController,this.sinkEnd=F(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.onEnd=e.onEnd,this.onCloseRead=e?.onCloseRead,this.onCloseWrite=e?.onCloseWrite,this.onReset=e?.onReset,this.onAbort=e?.onAbort,this.source=this.streamSource=Y({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.readStatus="closed",this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new z(`writable end state is "${this.writeStatus}" not "ready"`,_o);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let r=this.sendNewStream(t);Nt(r)&&await r}e=xe(e,this.sinkController.signal,{returnOnAbort:!0}),this.log.trace("sink reading from source");for await(let r of e){r=r instanceof Uint8Array?new L(r):r;let n=this.sendData(r,t);Nt(n)&&await n}this.log.trace("sink finished reading from source"),this.writeStatus="done",this.log.trace("sink calling closeWrite"),await this.closeWrite(t),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.onEnd!=null&&this.onEnd(this.endErr)):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.onEnd!=null&&this.onEnd(this.endErr)):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.log.trace("closing gracefully"),this.status="closing",await Promise.all([this.closeRead(e),this.closeWrite(e)]),this.status="closed",this.log.trace("closed gracefully")}async closeRead(e={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let t=this.readStatus;this.readStatus="closing",t==="ready"&&(this.log.trace("ending internal source queue"),this.streamSource.end()),this.status!=="reset"&&this.status!=="aborted"&&(this.log.trace("send close read to remote"),await this.sendCloseRead(e)),this.log.trace("closed readable end of stream")}async closeWrite(e={}){if(this.writeStatus==="closing"||this.writeStatus==="closed")return;this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus);let t=this.writeStatus;this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await this.sink([])),this.writeStatus="closing",t==="writing"&&await new Promise((r,n)=>{queueMicrotask(()=>{this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),this.sinkEnd.promise.then(r,n)})}),this.status!=="reset"&&this.status!=="aborted"&&(this.log.trace("send close write to remote"),await this.sendCloseWrite(e)),this.writeStatus="closed",this.log.trace("closed writable end of stream")}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();Nt(t)&&t.catch(r=>{this.log.error("error sending reset message",r)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new z("stream reset",Eo);this.status="reset",this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("muxer destroyed"),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};var kt=class extends Me{name;streamId;send;types;maxDataSize;constructor(e){super(e),this.types=e.direction==="outbound"?Ct:gi,this.send=e.send,this.name=e.name,this.streamId=e.streamId,this.maxDataSize=e.maxDataSize}async sendNewStream(){await this.send({id:this.streamId,type:Ct.NEW_STREAM,data:new L(St(this.name))})}async sendData(e){for(e=e.sublist();e.byteLength>0;){let t=Math.min(e.byteLength,this.maxDataSize);await this.send({id:this.streamId,type:this.types.MESSAGE,data:e.sublist(0,t)}),e.consume(t)}}async sendReset(){await this.send({id:this.streamId,type:this.types.RESET})}async sendCloseWrite(){await this.send({id:this.streamId,type:this.types.CLOSE})}async sendCloseRead(){}};function Bi(i){let{id:e,name:t,send:r,onEnd:n,type:s="initiator",maxMsgSize:o=At}=i;return new kt({id:s==="initiator"?`i${e}`:`r${e}`,streamId:e,name:`${t??e}`,direction:s==="initiator"?"outbound":"inbound",maxDataSize:o,onEnd:n,send:r,log:ge(`libp2p:mplex:stream:${s}:${e}`)})}var P=ge("libp2p:mplex"),So=1024,Co=1024,Ao=1024*1024*4,Ro=5,Io=500;function Oi(i){let e={...i,type:`${pe[i.type]} (${i.type})`};return i.type===y.NEW_STREAM&&(e.data=me(i.data instanceof Uint8Array?i.data:i.data.subarray())),(i.type===y.MESSAGE_INITIATOR||i.type===y.MESSAGE_RECEIVER)&&(e.data=me(i.data instanceof Uint8Array?i.data:i.data.subarray(),"base16")),e}var Ne=class{protocol="/mplex/6.7.0";sink;source;_streamId;_streams;_init;_source;closeController;rateLimiter;closeTimeout;constructor(e){e=e??{},this._streamId=0,this._streams={initiators:new Map,receivers:new Map},this._init=e,this.closeTimeout=e.closeTimeout??Io,this.sink=this._createSink(),this._source=Ht({objectMode:!0,onEnd:()=>{for(let t of this._streams.initiators.values())t.destroy();for(let t of this._streams.receivers.values())t.destroy()}}),this.source=Yt(this._source,t=>Di(t,this._init.minSendBytes)),this.closeController=new AbortController,this.rateLimiter=new Fi.RateLimiterMemory({points:e.disconnectThreshold??Ro,duration:1})}get streams(){let e=[];for(let t of this._streams.initiators.values())e.push(t);for(let t of this._streams.receivers.values())e.push(t);return e}newStream(e){if(this.closeController.signal.aborted)throw new Error("Muxer already closed");let t=this._streamId++;e=e==null?t.toString():e.toString();let r=this._streams.initiators;return this._newStream({id:t,name:e,type:"initiator",registry:r})}async close(e){if(this.closeController.signal.aborted)return;let t=e?.signal??AbortSignal.timeout(this.closeTimeout);try{await Promise.all(this.streams.map(async r=>r.close({signal:t}))),this._source.end(),await this._source.onEmpty({signal:t}),this.closeController.abort()}catch(r){this.abort(r)}}abort(e){this.closeController.signal.aborted||(this.streams.forEach(t=>{t.abort(e)}),this.closeController.abort(e))}_newReceiverStream(e){let{id:t,name:r}=e,n=this._streams.receivers;return this._newStream({id:t,name:r,type:"receiver",registry:n})}_newStream(e){let{id:t,name:r,type:n,registry:s}=e;if(P("new %s stream %s",n,t),n==="initiator"&&this._streams.initiators.size===(this._init.maxOutboundStreams??Co))throw new z("Too many outbound streams open","ERR_TOO_MANY_OUTBOUND_STREAMS");if(s.has(t))throw new Error(`${n} stream ${t} already exists!`);let c=Bi({id:t,name:r,send:async u=>{P.enabled&&P.trace("%s stream %s send",n,t,Oi(u)),this._source.push(u)},type:n,onEnd:()=>{P("%s stream with id %s and protocol %s ended",n,t,c.protocol),s.delete(t),this._init.onStreamEnd!=null&&this._init.onStreamEnd(c)},maxMsgSize:this._init.maxMsgSize});return s.set(t,c),c}_createSink(){return async t=>{try{t=xe(t,this.closeController.signal,{returnOnAbort:!0});let r=new Te(this._init.maxMsgSize,this._init.maxUnprocessedMessageQueueSize);for await(let n of t)for(let s of r.write(n))await this._handleIncoming(s);this._source.end()}catch(r){P("error in sink",r),this._source.end(r)}}}async _handleIncoming(e){let{id:t,type:r}=e;if(P.enabled&&P.trace("incoming message",Oi(e)),e.type===y.NEW_STREAM){if(this._streams.receivers.size===(this._init.maxInboundStreams??So)){P("too many inbound streams open"),this._source.push({id:t,type:y.RESET_RECEIVER});try{await this.rateLimiter.consume("new-stream",1)}catch{P("rate limit hit when opening too many new streams over the inbound stream limit - closing remote connection"),this.abort(new Error("Too many open streams"));return}return}let a=this._newReceiverStream({id:t,name:me(e.data instanceof Uint8Array?e.data:e.data.subarray())});this._init.onIncomingStream!=null&&this._init.onIncomingStream(a);return}let s=((r&1)===1?this._streams.initiators:this._streams.receivers).get(t);if(s==null){P("missing stream %s for message type %s",t,pe[r]);try{await this.rateLimiter.consume("missing-stream",1)}catch{P("rate limit hit when receiving messages for streams that do not exist - closing remote connection"),this.abort(new Error("Too many messages for missing streams"));return}return}let o=this._init.maxStreamBufferSize??Ao;try{switch(r){case y.MESSAGE_INITIATOR:case y.MESSAGE_RECEIVER:if(s.sourceReadableLength()>o)throw this._source.push({id:e.id,type:r===y.MESSAGE_INITIATOR?y.RESET_RECEIVER:y.RESET_INITIATOR}),new z("Input buffer full - increase Mplex maxBufferSize to accommodate slow consumers","ERR_STREAM_INPUT_BUFFER_FULL");s.sourcePush(e.data);break;case y.CLOSE_INITIATOR:case y.CLOSE_RECEIVER:s.remoteCloseWrite();break;case y.RESET_INITIATOR:case y.RESET_RECEIVER:s.reset();break;default:P("unknown message type %s",r)}}catch(a){P.error("error while processing message",a),s.abort(a)}}};var vt=class{protocol="/mplex/6.7.0";_init;constructor(e={}){this._init=e}createStreamMuxer(e={}){return new Ne({...e,...this._init})}};function To(i={}){return()=>new vt(i)}return Wi(Lo);})();
23
+ RETURNING points, expire;`,values:[e,t,n,Date.now()]})}_get(e){return this.tableCreated?new Promise((t,r)=>{this._query({name:"rlflx-get",text:`
24
+ SELECT points, expire FROM ${this.tableName} WHERE key = $1 AND (expire > $2 OR expire IS NULL);`,values:[e,Date.now()]}).then(s=>{s.rowCount===0&&(s=null),t(s)}).catch(s=>{r(s)})}):Promise.reject(Error("Table is not created yet"))}_delete(e){return this.tableCreated?this._query({name:"rlflx-delete",text:`DELETE FROM ${this.tableName} WHERE key = $1`,values:[e]}).then(t=>t.rowCount>0):Promise.reject(Error("Table is not created yet"))}};ur.exports=Ge});var fr=y(()=>{});var dr=y(()=>{});var pr=y((aa,mr)=>{mr.exports=class{constructor(e,t,r=null){this.value=e,this.expiresAt=t,this.timeoutId=r}get value(){return this._value}set value(e){this._value=parseInt(e)}get expiresAt(){return this._expiresAt}set expiresAt(e){!(e instanceof Date)&&Number.isInteger(e)&&(e=new Date(e)),this._expiresAt=e}get timeoutId(){return this._timeoutId}set timeoutId(e){this._timeoutId=e}}});var yr=y((la,br)=>{var Ss=pr(),je=M();br.exports=class{constructor(){this._storage={}}incrby(e,t,r){if(this._storage[e]){let s=this._storage[e].expiresAt?this._storage[e].expiresAt.getTime()-new Date().getTime():-1;return s!==0?(this._storage[e].value=this._storage[e].value+t,new je(0,s,this._storage[e].value,!1)):this.set(e,t,r)}return this.set(e,t,r)}set(e,t,r){let s=r*1e3;return this._storage[e]&&this._storage[e].timeoutId&&clearTimeout(this._storage[e].timeoutId),this._storage[e]=new Ss(t,s>0?new Date(Date.now()+s):null),s>0&&(this._storage[e].timeoutId=setTimeout(()=>{delete this._storage[e]},s),this._storage[e].timeoutId.unref&&this._storage[e].timeoutId.unref()),new je(0,s===0?-1:s,this._storage[e].value,!0)}get(e){if(this._storage[e]){let t=this._storage[e].expiresAt?this._storage[e].expiresAt.getTime()-new Date().getTime():-1;return new je(0,t,this._storage[e].value,!1)}return null}delete(e){return this._storage[e]?(this._storage[e].timeoutId&&clearTimeout(this._storage[e].timeoutId),delete this._storage[e],!0):!1}}});var Ye=y((ua,gr)=>{var Cs=ce(),As=yr(),wr=M(),He=class extends Cs{constructor(e={}){super(e),this._memoryStorage=new As}consume(e,t=1,r={}){return new Promise((s,n)=>{let o=this.getKey(e),a=this._getKeySecDuration(r),c=this._memoryStorage.incrby(o,t,a);if(c.remainingPoints=Math.max(this.points-c.consumedPoints,0),c.consumedPoints>this.points)this.blockDuration>0&&c.consumedPoints<=this.points+t&&(c=this._memoryStorage.set(o,c.consumedPoints,this.blockDuration)),n(c);else if(this.execEvenly&&c.msBeforeNext>0&&!c.isFirstInDuration){let u=Math.ceil(c.msBeforeNext/(c.remainingPoints+2));u<this.execEvenlyMinDelayMs&&(u=c.consumedPoints*this.execEvenlyMinDelayMs),setTimeout(s,u,c)}else s(c)})}penalty(e,t=1,r={}){let s=this.getKey(e);return new Promise(n=>{let o=this._getKeySecDuration(r),a=this._memoryStorage.incrby(s,t,o);a.remainingPoints=Math.max(this.points-a.consumedPoints,0),n(a)})}reward(e,t=1,r={}){let s=this.getKey(e);return new Promise(n=>{let o=this._getKeySecDuration(r),a=this._memoryStorage.incrby(s,-t,o);a.remainingPoints=Math.max(this.points-a.consumedPoints,0),n(a)})}block(e,t){let r=t*1e3,s=this.points+1;return this._memoryStorage.set(this.getKey(e),s,t),Promise.resolve(new wr(0,r===0?-1:r,s))}set(e,t,r){let s=(r>=0?r:this.duration)*1e3;return this._memoryStorage.set(this.getKey(e),t,r),Promise.resolve(new wr(0,s===0?-1:s,t))}get(e){let t=this._memoryStorage.get(this.getKey(e));return t!==null&&(t.remainingPoints=Math.max(this.points-t.consumedPoints,0)),Promise.resolve(t)}delete(e){return Promise.resolve(this._memoryStorage.delete(this.getKey(e)))}};gr.exports=He});var Rr=y((ha,Ar)=>{var Er=fr(),Rs=dr(),Is=ce(),_r=Ye(),Ls=M(),D="rate_limiter_flexible",re=null,xr=function(i,e,t,r){let s;r===null||r===!0||r===!1?s=r:s={remainingPoints:r.remainingPoints,msBeforeNext:r.msBeforeNext,consumedPoints:r.consumedPoints,isFirstInDuration:r.isFirstInDuration},i.send({channel:D,keyPrefix:e.keyPrefix,promiseId:e.promiseId,type:t,data:s})},Sr=function(i){setTimeout(()=>{this._initiated?process.send(i):typeof this._promises[i.promiseId]<"u"&&Sr.call(this,i)},30)},ee=function(i,e,t,r,s){let n={channel:D,keyPrefix:this.keyPrefix,func:i,promiseId:e,data:{key:t,arg:r,opts:s}};this._initiated?process.send(n):Sr.call(this,n)},Cr=function(i,e){if(!e||e.channel!==D||typeof this._rateLimiters[e.keyPrefix]>"u")return!1;let t;switch(e.func){case"consume":t=this._rateLimiters[e.keyPrefix].consume(e.data.key,e.data.arg,e.data.opts);break;case"penalty":t=this._rateLimiters[e.keyPrefix].penalty(e.data.key,e.data.arg,e.data.opts);break;case"reward":t=this._rateLimiters[e.keyPrefix].reward(e.data.key,e.data.arg,e.data.opts);break;case"block":t=this._rateLimiters[e.keyPrefix].block(e.data.key,e.data.arg,e.data.opts);break;case"get":t=this._rateLimiters[e.keyPrefix].get(e.data.key,e.data.opts);break;case"delete":t=this._rateLimiters[e.keyPrefix].delete(e.data.key,e.data.opts);break;default:return!1}t&&t.then(r=>{xr(i,e,"resolve",r)}).catch(r=>{xr(i,e,"reject",r)})},Ts=function(i){if(!i||i.channel!==D||i.keyPrefix!==this.keyPrefix)return!1;if(this._promises[i.promiseId]){clearTimeout(this._promises[i.promiseId].timeoutId);let e;switch(i.data===null||i.data===!0||i.data===!1?e=i.data:e=new Ls(i.data.remainingPoints,i.data.msBeforeNext,i.data.consumedPoints,i.data.isFirstInDuration),i.type){case"resolve":this._promises[i.promiseId].resolve(e);break;case"reject":this._promises[i.promiseId].reject(e);break;default:throw new Error(`RateLimiterCluster: no such message type '${i.type}'`)}delete this._promises[i.promiseId]}},Ms=function(){return{points:this.points,duration:this.duration,blockDuration:this.blockDuration,execEvenly:this.execEvenly,execEvenlyMinDelayMs:this.execEvenlyMinDelayMs,keyPrefix:this.keyPrefix}},te=function(i,e){let t=process.hrtime(),r=t[0].toString()+t[1].toString();return typeof this._promises[r]<"u"&&(r+=Rs.randomBytes(12).toString("base64")),this._promises[r]={resolve:i,reject:e,timeoutId:setTimeout(()=>{delete this._promises[r],e(new Error("RateLimiterCluster timeout: no answer from master in time"))},this.timeoutMs)},r},Qe=class{constructor(){if(re)return re;this._rateLimiters={},Er.setMaxListeners(0),Er.on("message",(e,t)=>{t&&t.channel===D&&t.type==="init"?(typeof this._rateLimiters[t.opts.keyPrefix]>"u"&&(this._rateLimiters[t.opts.keyPrefix]=new _r(t.opts)),e.send({channel:D,type:"init",keyPrefix:t.opts.keyPrefix})):Cr.call(this,e,t)}),re=this}},Xe=class{constructor(e){if(re)return re;this._rateLimiters={},e.launchBus((t,r)=>{r.on("process:msg",s=>{let n=s.raw;if(n&&n.channel===D&&n.type==="init")typeof this._rateLimiters[n.opts.keyPrefix]>"u"&&(this._rateLimiters[n.opts.keyPrefix]=new _r(n.opts)),e.sendDataToProcessId(s.process.pm_id,{data:{},topic:D,channel:D,type:"init",keyPrefix:n.opts.keyPrefix},(o,a)=>{o&&console.log(o,a)});else{let o={send:a=>{let c=a;c.topic=D,typeof c.data>"u"&&(c.data={}),e.sendDataToProcessId(s.process.pm_id,c,(u,l)=>{u&&console.log(u,l)})}};Cr.call(this,o,n)}})}),re=this}},Je=class extends Is{get timeoutMs(){return this._timeoutMs}set timeoutMs(e){this._timeoutMs=typeof e>"u"?5e3:Math.abs(parseInt(e))}constructor(e={}){super(e),process.setMaxListeners(0),this.timeoutMs=e.timeoutMs,this._initiated=!1,process.on("message",t=>{t&&t.channel===D&&t.type==="init"&&t.keyPrefix===this.keyPrefix?this._initiated=!0:Ts.call(this,t)}),process.send({channel:D,type:"init",opts:Ms.call(this)}),this._promises={}}consume(e,t=1,r={}){return new Promise((s,n)=>{let o=te.call(this,s,n);ee.call(this,"consume",o,e,t,r)})}penalty(e,t=1,r={}){return new Promise((s,n)=>{let o=te.call(this,s,n);ee.call(this,"penalty",o,e,t,r)})}reward(e,t=1,r={}){return new Promise((s,n)=>{let o=te.call(this,s,n);ee.call(this,"reward",o,e,t,r)})}block(e,t,r={}){return new Promise((s,n)=>{let o=te.call(this,s,n);ee.call(this,"block",o,e,t,r)})}get(e,t={}){return new Promise((r,s)=>{let n=te.call(this,r,s);ee.call(this,"get",n,e,t)})}delete(e,t={}){return new Promise((r,s)=>{let n=te.call(this,r,s);ee.call(this,"delete",n,e,t)})}};Ar.exports={RateLimiterClusterMaster:Qe,RateLimiterClusterMasterPM2:Xe,RateLimiterCluster:Je}});var Lr=y((fa,Ir)=>{var Ns=Z(),ks=M(),Ze=class extends Ns{constructor(e){super(e),this.client=e.storeClient}_getRateLimiterRes(e,t,r){let s=new ks;return s.consumedPoints=parseInt(r.consumedPoints),s.isFirstInDuration=r.consumedPoints===t,s.remainingPoints=Math.max(this.points-s.consumedPoints,0),s.msBeforeNext=r.msBeforeNext,s}_upsert(e,t,r,s=!1,n={}){return new Promise((o,a)=>{let c=Date.now(),u=Math.floor(r/1e3);s?this.client.set(e,t,u,l=>{l?a(l):this.client.set(`${e}_expire`,u>0?c+u*1e3:-1,u,()=>{let h={consumedPoints:t,msBeforeNext:u>0?u*1e3:-1};o(h)})}):this.client.incr(e,t,(l,h)=>{l||h===!1?this.client.add(e,t,u,(f,g)=>{if(f||!g)if(typeof n.attemptNumber>"u"||n.attemptNumber<3){let m=Object.assign({},n);m.attemptNumber=m.attemptNumber?m.attemptNumber+1:1,this._upsert(e,t,r,s,m).then(p=>o(p)).catch(p=>a(p))}else a(new Error("Can not add key"));else this.client.add(`${e}_expire`,u>0?c+u*1e3:-1,u,()=>{let m={consumedPoints:t,msBeforeNext:u>0?u*1e3:-1};o(m)})}):this.client.get(`${e}_expire`,(f,g)=>{if(f)a(f);else{let m=g===!1?0:g,p={consumedPoints:h,msBeforeNext:m>=0?Math.max(m-c,0):-1};o(p)}})})})}_get(e){return new Promise((t,r)=>{let s=Date.now();this.client.get(e,(n,o)=>{o?this.client.get(`${e}_expire`,(a,c)=>{if(a)r(a);else{let u=c===!1?0:c,l={consumedPoints:o,msBeforeNext:u>=0?Math.max(u-s,0):-1};t(l)}}):t(null)})})}_delete(e){return new Promise((t,r)=>{this.client.del(e,(s,n)=>{s?r(s):n===!1?t(n):this.client.del(`${e}_expire`,o=>{o?r(o):t(n)})})})}};Ir.exports=Ze});var Nr=y((ma,Mr)=>{var Tr=M();Mr.exports=class{constructor(e={}){this.limiter=e.limiter,this.blackList=e.blackList,this.whiteList=e.whiteList,this.isBlackListed=e.isBlackListed,this.isWhiteListed=e.isWhiteListed,this.runActionAnyway=e.runActionAnyway}get limiter(){return this._limiter}set limiter(e){if(typeof e>"u")throw new Error("limiter is not set");this._limiter=e}get runActionAnyway(){return this._runActionAnyway}set runActionAnyway(e){this._runActionAnyway=typeof e>"u"?!1:e}get blackList(){return this._blackList}set blackList(e){this._blackList=Array.isArray(e)?e:[]}get isBlackListed(){return this._isBlackListed}set isBlackListed(e){if(typeof e>"u"&&(e=()=>!1),typeof e!="function")throw new Error("isBlackListed must be function");this._isBlackListed=e}get whiteList(){return this._whiteList}set whiteList(e){this._whiteList=Array.isArray(e)?e:[]}get isWhiteListed(){return this._isWhiteListed}set isWhiteListed(e){if(typeof e>"u"&&(e=()=>!1),typeof e!="function")throw new Error("isWhiteListed must be function");this._isWhiteListed=e}isBlackListedSomewhere(e){return this.blackList.indexOf(e)>=0||this.isBlackListed(e)}isWhiteListedSomewhere(e){return this.whiteList.indexOf(e)>=0||this.isWhiteListed(e)}getBlackRes(){return new Tr(0,Number.MAX_SAFE_INTEGER,0,!1)}getWhiteRes(){return new Tr(Number.MAX_SAFE_INTEGER,0,0,!1)}rejectBlack(){return Promise.reject(this.getBlackRes())}resolveBlack(){return Promise.resolve(this.getBlackRes())}resolveWhite(){return Promise.resolve(this.getWhiteRes())}consume(e,t=1){let r;return this.isWhiteListedSomewhere(e)?r=this.resolveWhite():this.isBlackListedSomewhere(e)&&(r=this.rejectBlack()),typeof r>"u"?this.limiter.consume(e,t):(this.runActionAnyway&&this.limiter.consume(e,t).catch(()=>{}),r)}block(e,t){let r;return this.isWhiteListedSomewhere(e)?r=this.resolveWhite():this.isBlackListedSomewhere(e)&&(r=this.resolveBlack()),typeof r>"u"?this.limiter.block(e,t):(this.runActionAnyway&&this.limiter.block(e,t).catch(()=>{}),r)}penalty(e,t){let r;return this.isWhiteListedSomewhere(e)?r=this.resolveWhite():this.isBlackListedSomewhere(e)&&(r=this.resolveBlack()),typeof r>"u"?this.limiter.penalty(e,t):(this.runActionAnyway&&this.limiter.penalty(e,t).catch(()=>{}),r)}reward(e,t){let r;return this.isWhiteListedSomewhere(e)?r=this.resolveWhite():this.isBlackListedSomewhere(e)&&(r=this.resolveBlack()),typeof r>"u"?this.limiter.reward(e,t):(this.runActionAnyway&&this.limiter.reward(e,t).catch(()=>{}),r)}get(e){let t;return this.isWhiteListedSomewhere(e)?t=this.resolveWhite():this.isBlackListedSomewhere(e)&&(t=this.resolveBlack()),typeof t>"u"||this.runActionAnyway?this.limiter.get(e):t}delete(e){return this.limiter.delete(e)}}});var Pr=y((ba,kr)=>{var Ps=ce();kr.exports=class{constructor(...e){if(e.length<1)throw new Error("RateLimiterUnion: at least one limiter have to be passed");e.forEach(t=>{if(!(t instanceof Ps))throw new Error("RateLimiterUnion: all limiters have to be instance of RateLimiterAbstract")}),this._limiters=e}consume(e,t=1){return new Promise((r,s)=>{let n=[];this._limiters.forEach(o=>{n.push(o.consume(e,t).catch(a=>({rejected:!0,rej:a})))}),Promise.all(n).then(o=>{let a={},c=!1;o.forEach(u=>{u.rejected===!0&&(c=!0)});for(let u=0;u<o.length;u++)c&&o[u].rejected===!0?a[this._limiters[u].keyPrefix]=o[u].rej:c||(a[this._limiters[u].keyPrefix]=o[u]);c?s(a):r(a)})})}}});var Dr=y((wa,vr)=>{vr.exports=class extends Error{constructor(e,t){super(),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.name="CustomError",this.message=e,t&&(this.extra=t)}}});var Ur=y((Ea,Fr)=>{var Br=Dr(),Or=4294967295,et="limiter";Fr.exports=class{constructor(e,t={maxQueueSize:Or}){this._queueLimiters={KEY_DEFAULT:new xe(e,t)},this._limiterFlexible=e,this._maxQueueSize=t.maxQueueSize}getTokensRemaining(e=et){return this._queueLimiters[e]?this._queueLimiters[e].getTokensRemaining():Promise.resolve(this._limiterFlexible.points)}removeTokens(e,t=et){return this._queueLimiters[t]||(this._queueLimiters[t]=new xe(this._limiterFlexible,{key:t,maxQueueSize:this._maxQueueSize})),this._queueLimiters[t].removeTokens(e)}};var xe=class{constructor(e,t={maxQueueSize:Or,key:et}){this._key=t.key,this._waitTimeout=null,this._queue=[],this._limiterFlexible=e,this._maxQueueSize=t.maxQueueSize}getTokensRemaining(){return this._limiterFlexible.get(this._key).then(e=>e!==null?e.remainingPoints:this._limiterFlexible.points)}removeTokens(e){let t=this;return new Promise((r,s)=>{if(e>t._limiterFlexible.points){s(new Br(`Requested tokens ${e} exceeds maximum ${t._limiterFlexible.points} tokens per interval`));return}t._queue.length>0?t._queueRequest.call(t,r,s,e):t._limiterFlexible.consume(t._key,e).then(n=>{r(n.remainingPoints)}).catch(n=>{n instanceof Error?s(n):(t._queueRequest.call(t,r,s,e),t._waitTimeout===null&&(t._waitTimeout=setTimeout(t._processFIFO.bind(t),n.msBeforeNext)))})})}_queueRequest(e,t,r){let s=this;s._queue.length<s._maxQueueSize?s._queue.push({resolve:e,reject:t,tokens:r}):t(new Br(`Number of requests reached it's maximum ${s._maxQueueSize}`))}_processFIFO(){let e=this;if(e._waitTimeout!==null&&(clearTimeout(e._waitTimeout),e._waitTimeout=null),e._queue.length===0)return;let t=e._queue.shift();e._limiterFlexible.consume(e._key,t.tokens).then(r=>{t.resolve(r.remainingPoints),e._processFIFO.call(e)}).catch(r=>{r instanceof Error?(t.reject(r),e._processFIFO.call(e)):(e._queue.unshift(t),e._waitTimeout===null&&(e._waitTimeout=setTimeout(e._processFIFO.bind(e),r.msBeforeNext)))})}}});var zr=y((_a,qr)=>{var tt=M();qr.exports=class{constructor(e,t){this._rateLimiter=e,this._burstLimiter=t}_combineRes(e,t){return e?new tt(e.remainingPoints,Math.min(e.msBeforeNext,t?t.msBeforeNext:0),e.consumedPoints,e.isFirstInDuration):null}consume(e,t=1,r={}){return this._rateLimiter.consume(e,t,r).catch(s=>s instanceof tt?this._burstLimiter.consume(e,t,r).then(n=>Promise.resolve(this._combineRes(s,n))).catch(n=>n instanceof tt?Promise.reject(this._combineRes(s,n)):Promise.reject(n)):Promise.reject(s))}get(e){return Promise.all([this._rateLimiter.get(e),this._burstLimiter.get(e)]).then(([t,r])=>this._combineRes(t,r))}get points(){return this._rateLimiter.points}}});var Vr=y((Sa,$r)=>{var vs=sr(),Ds=ar(),Bs=lr(),Os=hr(),{RateLimiterClusterMaster:Fs,RateLimiterClusterMasterPM2:Us,RateLimiterCluster:qs}=Rr(),zs=Ye(),$s=Lr(),Vs=Nr(),Ws=Pr(),Ks=Ur(),Gs=zr(),js=M();$r.exports={RateLimiterRedis:vs,RateLimiterMongo:Ds,RateLimiterMySQL:Bs,RateLimiterPostgres:Os,RateLimiterMemory:zs,RateLimiterMemcache:$s,RateLimiterClusterMaster:Fs,RateLimiterClusterMasterPM2:Us,RateLimiterCluster:qs,RLWrapperBlackAndWhite:Vs,RateLimiterUnion:Ws,RateLimiterQueue:Ks,BurstyRateLimiter:Gs,RateLimiterRes:js}});var mi=y((Bc,di)=>{di.exports=xt;var fi=128,Vn=127,Wn=~Vn,Kn=Math.pow(2,31);function xt(i,e,t){if(Number.MAX_SAFE_INTEGER&&i>Number.MAX_SAFE_INTEGER)throw xt.bytes=0,new RangeError("Could not encode varint");e=e||[],t=t||0;for(var r=t;i>=Kn;)e[t++]=i&255|fi,i/=128;for(;i&Wn;)e[t++]=i&255|fi,i>>>=7;return e[t]=i|0,xt.bytes=t-r+1,e}});var yi=y((Oc,bi)=>{bi.exports=_t;var Gn=128,pi=127;function _t(i,r){var t=0,r=r||0,s=0,n=r,o,a=i.length;do{if(n>=a||s>49)throw _t.bytes=0,new RangeError("Could not decode varint");o=i[n++],t+=s<28?(o&pi)<<s:(o&pi)*Math.pow(2,s),s+=7}while(o>=Gn);return _t.bytes=n-r,t}});var gi=y((Fc,wi)=>{var jn=Math.pow(2,7),Hn=Math.pow(2,14),Yn=Math.pow(2,21),Qn=Math.pow(2,28),Xn=Math.pow(2,35),Jn=Math.pow(2,42),Zn=Math.pow(2,49),eo=Math.pow(2,56),to=Math.pow(2,63);wi.exports=function(i){return i<jn?1:i<Hn?2:i<Yn?3:i<Qn?4:i<Xn?5:i<Jn?6:i<Zn?7:i<eo?8:i<to?9:10}});var xi=y((Uc,Ei)=>{Ei.exports={encode:mi(),decode:yi(),encodingLength:gi()}});var uo={};I(uo,{mplex:()=>lo});var U=class extends Error{code;props;constructor(e,t,r){super(e),this.code=t,this.name=r?.name??"CodeError",this.props=r??{}}};var T=Ne(vt(),1);var Be={};I(Be,{base32:()=>z,base32hex:()=>Zi,base32hexpad:()=>ts,base32hexpadupper:()=>rs,base32hexupper:()=>es,base32pad:()=>Xi,base32padupper:()=>Ji,base32upper:()=>Qi,base32z:()=>is});function Ki(i,e){if(i.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var s=0;s<i.length;s++){var n=i.charAt(s),o=n.charCodeAt(0);if(t[o]!==255)throw new TypeError(n+" is ambiguous");t[o]=s}var a=i.length,c=i.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function h(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var p=0,d=0,w=0,x=m.length;w!==x&&m[w]===0;)w++,p++;for(var _=(x-w)*l+1>>>0,S=new Uint8Array(_);w!==x;){for(var A=m[w],k=0,R=_-1;(A!==0||k<d)&&R!==-1;R--,k++)A+=256*S[R]>>>0,S[R]=A%a>>>0,A=A/a>>>0;if(A!==0)throw new Error("Non-zero carry");d=k,w++}for(var P=_-d;P!==_&&S[P]===0;)P++;for(var G=c.repeat(p);P<_;++P)G+=i.charAt(S[P]);return G}function f(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var p=0;if(m[p]!==" "){for(var d=0,w=0;m[p]===c;)d++,p++;for(var x=(m.length-p)*u+1>>>0,_=new Uint8Array(x);m[p];){var S=t[m.charCodeAt(p)];if(S===255)return;for(var A=0,k=x-1;(S!==0||A<w)&&k!==-1;k--,A++)S+=a*_[k]>>>0,_[k]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");w=A,p++}if(m[p]!==" "){for(var R=x-w;R!==x&&_[R]===0;)R++;for(var P=new Uint8Array(d+(x-R)),G=d;R!==x;)P[G++]=_[R++];return P}}}function g(m){var p=f(m);if(p)return p;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:f,decode:g}}var Gi=Ki,ji=Gi,Dt=ji;var yo=new Uint8Array(0);var Bt=(i,e)=>{if(i===e)return!0;if(i.byteLength!==e.byteLength)return!1;for(let t=0;t<i.byteLength;t++)if(i[t]!==e[t])return!1;return!0},B=i=>{if(i instanceof Uint8Array&&i.constructor.name==="Uint8Array")return i;if(i instanceof ArrayBuffer)return new Uint8Array(i);if(ArrayBuffer.isView(i))return new Uint8Array(i.buffer,i.byteOffset,i.byteLength);throw new Error("Unknown type, must be binary type")};var Ot=i=>new TextEncoder().encode(i),Ft=i=>new TextDecoder().decode(i);var ke=class{constructor(e,t,r){this.name=e,this.prefix=t,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Pe=class{constructor(e,t,r){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=r}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return qt(this,e)}},ve=class{constructor(e){this.decoders=e}or(e){return qt(this,e)}decode(e){let t=e[0],r=this.decoders[t];if(r)return r.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},qt=(i,e)=>new ve({...i.decoders||{[i.prefix]:i},...e.decoders||{[e.prefix]:e}}),De=class{constructor(e,t,r,s){this.name=e,this.prefix=t,this.baseEncode=r,this.baseDecode=s,this.encoder=new ke(e,t,r),this.decoder=new Pe(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},Q=({name:i,prefix:e,encode:t,decode:r})=>new De(i,e,t,r),q=({prefix:i,name:e,alphabet:t})=>{let{encode:r,decode:s}=Dt(t,e);return Q({prefix:i,name:e,encode:r,decode:n=>B(s(n))})},Hi=(i,e,t,r)=>{let s={};for(let l=0;l<e.length;++l)s[e[l]]=l;let n=i.length;for(;i[n-1]==="=";)--n;let o=new Uint8Array(n*t/8|0),a=0,c=0,u=0;for(let l=0;l<n;++l){let h=s[i[l]];if(h===void 0)throw new SyntaxError(`Non-${r} character`);c=c<<t|h,a+=t,a>=8&&(a-=8,o[u++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},Yi=(i,e,t)=>{let r=e[e.length-1]==="=",s=(1<<t)-1,n="",o=0,a=0;for(let c=0;c<i.length;++c)for(a=a<<8|i[c],o+=8;o>t;)o-=t,n+=e[s&a>>o];if(o&&(n+=e[s&a<<t-o]),r)for(;n.length*t&7;)n+="=";return n},E=({name:i,prefix:e,bitsPerChar:t,alphabet:r})=>Q({prefix:e,name:i,encode(s){return Yi(s,r,t)},decode(s){return Hi(s,r,t,i)}});var z=E({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Qi=E({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xi=E({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ji=E({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Zi=E({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),es=E({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ts=E({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),rs=E({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),is=E({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Oe={};I(Oe,{base58btc:()=>v,base58flickr:()=>ss});var v=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ss=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ue={};I(Ue,{base64:()=>Fe,base64pad:()=>ns,base64url:()=>os,base64urlpad:()=>as});var Fe=E({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ns=E({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),os=E({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),as=E({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});T.default.formatters.b=i=>i==null?"undefined":v.baseEncode(i);T.default.formatters.t=i=>i==null?"undefined":z.baseEncode(i);T.default.formatters.m=i=>i==null?"undefined":Fe.baseEncode(i);T.default.formatters.p=i=>i==null?"undefined":i.toString();T.default.formatters.c=i=>i==null?"undefined":i.toString();T.default.formatters.k=i=>i==null?"undefined":i.toString();T.default.formatters.a=i=>i==null?"undefined":i.toString();function cs(i){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=i,e.destroy=()=>!0,e.extend=()=>e,e}function we(i){let e=cs(`${i}:trace`);return T.default.enabled(`${i}:trace`)&&T.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,T.default)(`${i}:trace`)),Object.assign((0,T.default)(i),{error:(0,T.default)(`${i}:error`),trace:e})}var ae=class extends Error{constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function zt(i){if(i!=null){if(typeof i[Symbol.iterator]=="function")return i[Symbol.iterator]();if(typeof i[Symbol.asyncIterator]=="function")return i[Symbol.asyncIterator]();if(typeof i.next=="function")return i}throw new Error("argument is not an iterator or iterable")}function ge(i,e,t){let r=t??{},s=zt(i);async function*n(){let o,a=()=>{o?.()};for(e.addEventListener("abort",a);;){let c;try{if(e.aborted){let{abortMessage:l,abortCode:h}=r;throw new ae(l,h)}let u=new Promise((l,h)=>{o=()=>{let{abortMessage:f,abortCode:g}=r;h(new ae(f,g))}});c=await Promise.race([u,s.next()]),o=null}catch(u){e.removeEventListener("abort",a);let l=u.type==="aborted"&&e.aborted;if(l&&r.onAbort!=null&&r.onAbort(i),typeof s.return=="function")try{let h=s.return();h instanceof Promise&&h.catch(f=>{r.onReturnError!=null&&r.onReturnError(f)})}catch(h){r.onReturnError!=null&&r.onReturnError(h)}if(l&&r.returnOnAbort===!0)return;throw u}if(c.done===!0)break;yield c.value}e.removeEventListener("abort",a)}return n()}function O(){let i={};return i.promise=new Promise((e,t)=>{i.resolve=e,i.reject=t}),i}var Ee=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},X=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Ee(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new Ee(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var qe=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function J(i={}){return Vt(t=>{let r=t.shift();if(r==null)return{done:!0};if(r.error!=null)throw r.error;return{done:r.done===!0,value:r.value}},i)}function $t(i={}){return Vt(t=>{let r,s=[];for(;!t.isEmpty()&&(r=t.shift(),r!=null);){if(r.error!=null)throw r.error;r.done===!1&&s.push(r.value)}return r==null?{done:!0}:{done:r.done===!0,value:s}},i)}function Vt(i,e){e=e??{};let t=e.onEnd,r=new X,s,n,o,a=O(),c=async()=>{try{return r.isEmpty()?o?{done:!0}:await new Promise((d,w)=>{n=x=>{n=null,r.push(x);try{d(i(r))}catch(_){w(_)}return s}}):i(r)}finally{r.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=O()})}},u=d=>n!=null?n(d):(r.push(d),s),l=d=>(r=new X,n!=null?n({error:d}):(r.push({error:d}),s)),h=d=>{if(o)return s;if(e?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:d})},f=d=>o?s:(o=!0,d!=null?l(d):u({done:!0})),g=()=>(r=new X,f(),{done:!0}),m=d=>(f(d),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:g,throw:m,push:h,end:f,get readableLength(){return r.size},onEmpty:async d=>{let w=d?.signal;if(w?.throwIfAborted(),r.isEmpty())return;let x,_;w!=null&&(x=new Promise((S,A)=>{_=()=>{A(new qe)},w.addEventListener("abort",_)}));try{await Promise.race([a.promise,x])}finally{_!=null&&w!=null&&w?.removeEventListener("abort",_)}}},t==null)return s;let p=s;return s={[Symbol.asyncIterator](){return this},next(){return p.next()},throw(d){return p.throw(d),t!=null&&(t(d),t=void 0),{done:!0}},return(){return p.return(),t!=null&&(t(),t=void 0),{done:!0}},push:h,end(d){return p.end(d),t!=null&&(t(d),t=void 0),s},get readableLength(){return p.readableLength}},s}function ls(i){return i[Symbol.asyncIterator]!=null}function us(...i){let e=[];for(let t of i)ls(t)||e.push(t);return e.length===i.length?function*(){for(let t of e)yield*t}():async function*(){let t=J({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(i.map(async r=>{for await(let s of r)t.push(s)})),t.end()}catch(r){t.end(r)}}),yield*t}()}var Wt=us;function Kt(i,...e){if(i==null)throw new Error("Empty pipeline");if(ze(i)){let r=i;i=()=>r.source}else if(jt(i)||Gt(i)){let r=i;i=()=>r}let t=[i,...e];if(t.length>1&&ze(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let r=1;r<t.length-1;r++)ze(t[r])&&(t[r]=fs(t[r]));return hs(...t)}var hs=(...i)=>{let e;for(;i.length>0;)e=i.shift()(e);return e},Gt=i=>i?.[Symbol.asyncIterator]!=null,jt=i=>i?.[Symbol.iterator]!=null,ze=i=>i==null?!1:i.sink!=null&&i.source!=null,fs=i=>e=>{let t=i.sink(e);if(t?.then!=null){let r=J({objectMode:!0});t.then(()=>{r.end()},o=>{r.end(o)});let s,n=i.source;if(Gt(n))s=async function*(){yield*n,r.end()};else if(jt(n))s=function*(){yield*n,r.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Wt(r,s())}return i.source};var Ri=Ne(Vr(),1);function $(i){return globalThis.Buffer!=null?new Uint8Array(i.buffer,i.byteOffset,i.byteLength):i}function F(i=0){return globalThis.Buffer?.alloc!=null?$(globalThis.Buffer.alloc(i)):new Uint8Array(i)}function V(i=0){return globalThis.Buffer?.allocUnsafe!=null?$(globalThis.Buffer.allocUnsafe(i)):new Uint8Array(i)}function _e(i,e){e==null&&(e=i.reduce((s,n)=>s+n.length,0));let t=V(e),r=0;for(let s of i)t.set(s,r),r+=s.length;return $(t)}function rt(i,e){if(i===e)return!0;if(i.byteLength!==e.byteLength)return!1;for(let t=0;t<i.byteLength;t++)if(i[t]!==e[t])return!1;return!0}var it={};I(it,{identity:()=>Hs});var Hs=Q({prefix:"\0",name:"identity",encode:i=>Ft(i),decode:i=>Ot(i)});var st={};I(st,{base2:()=>Ys});var Ys=E({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var nt={};I(nt,{base8:()=>Qs});var Qs=E({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ot={};I(ot,{base10:()=>Xs});var Xs=q({prefix:"9",name:"base10",alphabet:"0123456789"});var at={};I(at,{base16:()=>Js,base16upper:()=>Zs});var Js=E({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Zs=E({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ct={};I(ct,{base36:()=>en,base36upper:()=>tn});var en=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),tn=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var lt={};I(lt,{base256emoji:()=>an});var Wr=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),rn=Wr.reduce((i,e,t)=>(i[t]=e,i),[]),sn=Wr.reduce((i,e,t)=>(i[e.codePointAt(0)]=t,i),[]);function nn(i){return i.reduce((e,t)=>(e+=rn[t],e),"")}function on(i){let e=[];for(let t of i){let r=sn[t.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(r)}return new Uint8Array(e)}var an=Q({prefix:"\u{1F680}",name:"base256emoji",encode:nn,decode:on});var dt={};I(dt,{sha256:()=>Rn,sha512:()=>In});var cn=jr,Kr=128,ln=127,un=~ln,hn=Math.pow(2,31);function jr(i,e,t){e=e||[],t=t||0;for(var r=t;i>=hn;)e[t++]=i&255|Kr,i/=128;for(;i&un;)e[t++]=i&255|Kr,i>>>=7;return e[t]=i|0,jr.bytes=t-r+1,e}var fn=ut,dn=128,Gr=127;function ut(i,r){var t=0,r=r||0,s=0,n=r,o,a=i.length;do{if(n>=a)throw ut.bytes=0,new RangeError("Could not decode varint");o=i[n++],t+=s<28?(o&Gr)<<s:(o&Gr)*Math.pow(2,s),s+=7}while(o>=dn);return ut.bytes=n-r,t}var mn=Math.pow(2,7),pn=Math.pow(2,14),bn=Math.pow(2,21),yn=Math.pow(2,28),wn=Math.pow(2,35),gn=Math.pow(2,42),En=Math.pow(2,49),xn=Math.pow(2,56),_n=Math.pow(2,63),Sn=function(i){return i<mn?1:i<pn?2:i<bn?3:i<yn?4:i<wn?5:i<gn?6:i<En?7:i<xn?8:i<_n?9:10},Cn={encode:cn,decode:fn,encodingLength:Sn},An=Cn,le=An;var ue=(i,e=0)=>[le.decode(i,e),le.decode.bytes],ie=(i,e,t=0)=>(le.encode(i,e,t),e),se=i=>le.encodingLength(i);var K=(i,e)=>{let t=e.byteLength,r=se(i),s=r+se(t),n=new Uint8Array(s+t);return ie(i,n,0),ie(t,n,r),n.set(e,s),new ne(i,t,e,n)},Hr=i=>{let e=B(i),[t,r]=ue(e),[s,n]=ue(e.subarray(r)),o=e.subarray(r+n);if(o.byteLength!==s)throw new Error("Incorrect length");return new ne(t,s,o,e)},Yr=(i,e)=>{if(i===e)return!0;{let t=e;return i.code===t.code&&i.size===t.size&&t.bytes instanceof Uint8Array&&Bt(i.bytes,t.bytes)}},ne=class{constructor(e,t,r,s){this.code=e,this.size=t,this.digest=r,this.bytes=s}};var ft=({name:i,code:e,encode:t})=>new ht(i,e,t),ht=class{constructor(e,t,r){this.name=e,this.code=t,this.encode=r}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?K(this.code,t):t.then(r=>K(this.code,r))}else throw Error("Unknown type, must be binary type")}};var Xr=i=>async e=>new Uint8Array(await crypto.subtle.digest(i,e)),Rn=ft({name:"sha2-256",code:18,encode:Xr("SHA-256")}),In=ft({name:"sha2-512",code:19,encode:Xr("SHA-512")});var mt={};I(mt,{identity:()=>Mn});var Jr=0,Ln="identity",Zr=B,Tn=i=>K(Jr,Zr(i)),Mn={code:Jr,name:Ln,encode:Zr,digest:Tn};var Ga=new TextEncoder,ja=new TextDecoder;var ei=(i,e)=>{let{bytes:t,version:r}=i;switch(r){case 0:return vn(t,pt(i),e||v.encoder);default:return Dn(t,pt(i),e||z.encoder)}};var ti=new WeakMap,pt=i=>{let e=ti.get(i);if(e==null){let t=new Map;return ti.set(i,t),t}return e},Ce=class i{constructor(e,t,r,s){this.code=t,this.version=e,this.multihash=r,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==fe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Bn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return i.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,r=K(e,t);return i.createV1(this.code,r)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return i.equals(this,e)}static equals(e,t){let r=t;return r&&e.code===r.code&&e.version===r.version&&Yr(e.multihash,r.multihash)}toString(e){return ei(this,e)}toJSON(){return{"/":ei(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof i)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:r,code:s,multihash:n,bytes:o}=t;return new i(r,s,n,o||ri(r,s,n.bytes))}else if(t[On]===!0){let{version:r,multihash:s,code:n}=t,o=Hr(s);return i.create(r,n,o)}else return null}static create(e,t,r){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(r.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==fe)throw new Error(`Version 0 CID must use dag-pb (code: ${fe}) block encoding`);return new i(e,t,r,r.bytes)}case 1:{let s=ri(e,t,r.bytes);return new i(e,t,r,s)}default:throw new Error("Invalid version")}}static createV0(e){return i.create(0,fe,e)}static createV1(e,t){return i.create(1,e,t)}static decode(e){let[t,r]=i.decodeFirst(e);if(r.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=i.inspectBytes(e),r=t.size-t.multihashSize,s=B(e.subarray(r,r+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let n=s.subarray(t.multihashSize-t.digestSize),o=new ne(t.multihashCode,t.digestSize,n,s);return[t.version===0?i.createV0(o):i.createV1(t.codec,o),e.subarray(t.size)]}static inspectBytes(e){let t=0,r=()=>{let[h,f]=ue(e.subarray(t));return t+=f,h},s=r(),n=fe;if(s===18?(s=0,t=0):n=r(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=t,a=r(),c=r(),u=t+c,l=u-o;return{version:s,codec:n,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[r,s]=Pn(e,t),n=i.decode(s);if(n.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return pt(n).set(r,e),n}},Pn=(i,e)=>{switch(i[0]){case"Q":{let t=e||v;return[v.prefix,t.decode(`${v.prefix}${i}`)]}case v.prefix:{let t=e||v;return[v.prefix,t.decode(i)]}case z.prefix:{let t=e||z;return[z.prefix,t.decode(i)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[i[0],e.decode(i)]}}},vn=(i,e,t)=>{let{prefix:r}=t;if(r!==v.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(r);if(s==null){let n=t.encode(i).slice(1);return e.set(r,n),n}else return s},Dn=(i,e,t)=>{let{prefix:r}=t,s=e.get(r);if(s==null){let n=t.encode(i);return e.set(r,n),n}else return s},fe=112,Bn=18,ri=(i,e,t)=>{let r=se(i),s=r+se(e),n=new Uint8Array(s+t.byteLength);return ie(i,n,0),ie(e,n,r),n.set(t,s),n},On=Symbol.for("@ipld/js-cid/CID");var bt={...it,...st,...nt,...ot,...at,...Be,...ct,...Oe,...Ue,...lt},ic={...dt,...mt};function si(i,e,t,r){return{name:i,prefix:e,encoder:{name:i,prefix:e,encode:t},decoder:{decode:r}}}var ii=si("utf8","u",i=>"u"+new TextDecoder("utf8").decode(i),i=>new TextEncoder().encode(i.substring(1))),yt=si("ascii","a",i=>{let e="a";for(let t=0;t<i.length;t++)e+=String.fromCharCode(i[t]);return e},i=>{i=i.substring(1);let e=V(i.length);for(let t=0;t<i.length;t++)e[t]=i.charCodeAt(t);return e}),Fn={utf8:ii,"utf-8":ii,hex:bt.base16,latin1:yt,ascii:yt,binary:yt,...bt},Ae=Fn;function wt(i,e="utf8"){let t=Ae[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?$(globalThis.Buffer.from(i,"utf-8")):t.decoder.decode(`${t.prefix}${i}`)}function de(i,e="utf8"){let t=Ae[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(i.buffer,i.byteOffset,i.byteLength).toString("utf8"):t.encoder.encode(i).substring(1)}var oi=Symbol.for("@achingbrain/uint8arraylist");function ni(i,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let r of i){let s=t+r.byteLength;if(e<s)return{buf:r,index:e-t};t=s}throw new RangeError("index is out of bounds")}function Re(i){return!!i?.[oi]}var C=class i{constructor(...e){Object.defineProperty(this,oi,{value:!0}),this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let r of e)if(r instanceof Uint8Array)t+=r.byteLength,this.bufs.push(r);else if(Re(r))t+=r.byteLength,this.bufs.push(...r.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let r of e.reverse())if(r instanceof Uint8Array)t+=r.byteLength,this.bufs.unshift(r);else if(Re(r))t+=r.byteLength,this.bufs.unshift(...r.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=ni(this.bufs,e);return t.buf[t.index]}set(e,t){let r=ni(this.bufs,e);r.buf[r.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let r=0;r<e.length;r++)this.set(t+r,e[r]);else if(Re(e))for(let r=0;r<e.length;r++)this.set(t+r,e.get(r));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:r,length:s}=this._subList(e,t);return _e(r,s)}subarray(e,t){let{bufs:r,length:s}=this._subList(e,t);return r.length===1?r[0]:_e(r,s)}sublist(e,t){let{bufs:r,length:s}=this._subList(e,t),n=new i;return n.length=s,n.bufs=r,n}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:[...this.bufs],length:this.length};let r=[],s=0;for(let n=0;n<this.bufs.length;n++){let o=this.bufs[n],a=s,c=a+o.byteLength;if(s=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){r.push(o);break}let h=e-a;r.push(o.subarray(h,h+(t-e)));break}if(u){if(e===0){r.push(o);continue}r.push(o.subarray(e-a));continue}if(l){if(t===c){r.push(o);break}r.push(o.subarray(0,t-a));break}r.push(o)}return{bufs:r,length:t-e}}indexOf(e,t=0){if(!Re(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let r=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let s=r.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let n=256,o=new Int32Array(n);for(let h=0;h<n;h++)o[h]=-1;for(let h=0;h<s;h++)o[r[h]]=h;let a=o,c=this.byteLength-r.byteLength,u=r.byteLength-1,l;for(let h=t;h<=c;h+=l){l=0;for(let f=u;f>=0;f--){let g=this.get(h+f);if(r[f]!==g){l=Math.max(1,f-a[g]);break}}if(l===0)return h}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let r=V(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt8(0,t),this.write(r,e)}getInt16(e,t){let r=this.subarray(e,e+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt16(0,t)}setInt16(e,t,r){let s=F(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,t,r),this.write(s,e)}getInt32(e,t){let r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt32(0,t)}setInt32(e,t,r){let s=F(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,t,r),this.write(s,e)}getBigInt64(e,t){let r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigInt64(0,t)}setBigInt64(e,t,r){let s=F(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,t,r),this.write(s,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let r=V(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint8(0,t),this.write(r,e)}getUint16(e,t){let r=this.subarray(e,e+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint16(0,t)}setUint16(e,t,r){let s=F(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,t,r),this.write(s,e)}getUint32(e,t){let r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(0,t)}setUint32(e,t,r){let s=F(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,t,r),this.write(s,e)}getBigUint64(e,t){let r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigUint64(0,t)}setBigUint64(e,t,r){let s=F(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,t,r),this.write(s,e)}getFloat32(e,t){let r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat32(0,t)}setFloat32(e,t,r){let s=F(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,t,r),this.write(s,e)}getFloat64(e,t){let r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat64(0,t)}setFloat64(e,t,r){let s=F(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,t,r),this.write(s,e)}equals(e){if(e==null||!(e instanceof i)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!rt(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let r=new i;return r.bufs=e,t==null&&(t=e.reduce((s,n)=>s+n.byteLength,0)),r.length=t,r}};var b;(function(i){i[i.NEW_STREAM=0]="NEW_STREAM",i[i.MESSAGE_RECEIVER=1]="MESSAGE_RECEIVER",i[i.MESSAGE_INITIATOR=2]="MESSAGE_INITIATOR",i[i.CLOSE_RECEIVER=3]="CLOSE_RECEIVER",i[i.CLOSE_INITIATOR=4]="CLOSE_INITIATOR",i[i.RESET_RECEIVER=5]="RESET_RECEIVER",i[i.RESET_INITIATOR=6]="RESET_INITIATOR"})(b||(b={}));var me=Object.freeze({0:"NEW_STREAM",1:"MESSAGE_RECEIVER",2:"MESSAGE_INITIATOR",3:"CLOSE_RECEIVER",4:"CLOSE_INITIATOR",5:"RESET_RECEIVER",6:"RESET_INITIATOR"}),gt=Object.freeze({NEW_STREAM:b.NEW_STREAM,MESSAGE:b.MESSAGE_INITIATOR,CLOSE:b.CLOSE_INITIATOR,RESET:b.RESET_INITIATOR}),ai=Object.freeze({MESSAGE:b.MESSAGE_RECEIVER,CLOSE:b.CLOSE_RECEIVER,RESET:b.RESET_RECEIVER});var Et=1<<20,Un=4<<20,Ie=class{_buffer;_headerInfo;_maxMessageSize;_maxUnprocessedMessageQueueSize;constructor(e=Et,t=Un){this._buffer=new C,this._headerInfo=null,this._maxMessageSize=e,this._maxUnprocessedMessageQueueSize=t}write(e){if(e==null||e.length===0)return[];if(this._buffer.append(e),this._buffer.byteLength>this._maxUnprocessedMessageQueueSize)throw Object.assign(new Error("unprocessed message queue size too large!"),{code:"ERR_MSG_QUEUE_TOO_BIG"});let t=[];for(;this._buffer.length!==0;){if(this._headerInfo==null)try{this._headerInfo=this._decodeHeader(this._buffer)}catch(u){if(u.code==="ERR_MSG_TOO_BIG")throw u;break}let{id:r,type:s,length:n,offset:o}=this._headerInfo;if(this._buffer.length-o<n)break;let c={id:r,type:s};(s===b.NEW_STREAM||s===b.MESSAGE_INITIATOR||s===b.MESSAGE_RECEIVER)&&(c.data=this._buffer.sublist(o,o+n)),t.push(c),this._buffer.consume(o+n),this._headerInfo=null}return t}_decodeHeader(e){let{value:t,offset:r}=li(e),{value:s,offset:n}=li(e,r),o=t&7;if(me[o]==null)throw new Error(`Invalid type received: ${o}`);if(s>this._maxMessageSize)throw Object.assign(new Error("message size too large!"),{code:"ERR_MSG_TOO_BIG"});return{id:t>>3,type:o,offset:r+n,length:s}}},qn=128,ci=127;function li(i,e=0){let t=0,r=0,s=e,n,o=i.length;do{if(s>=o||r>49)throw e=0,new RangeError("Could not decode varint");n=i.get(s++),t+=r<28?(n&ci)<<r:(n&ci)*Math.pow(2,r),r+=7}while(n>=qn);return e=s-e,{value:t,offset:e}}function zn(i){return i[Symbol.asyncIterator]!=null}var Le=1024*1024,ui=(i,e)=>{e.append(i)};function $n(i,e){return zn(i)?async function*(){let t=new C,r=!1,s=O(),n=Number(e?.size??Le);if((isNaN(n)||n===0||n<0)&&(n=Le),n!==Math.round(n))throw new Error("Batch size must be an integer");let o=e?.yieldAfter??0,a=e?.serialize??ui;for(Promise.resolve().then(async()=>{try{let c;for await(let u of i){if(a(u,t),t.byteLength>=n){clearTimeout(c),s.resolve();continue}c=setTimeout(()=>{s.resolve()},o)}clearTimeout(c),s.resolve()}catch(c){s.reject(c)}finally{r=!0}});!r;)if(await s.promise,s=O(),t.byteLength>0){let c=t;t=new C,yield c.subarray()}}():function*(){let t=new C,r=Number(e?.size??Le);if((isNaN(r)||r===0||r<0)&&(r=Le),r!==Math.round(r))throw new Error("Batch size must be an integer");let s=e?.serialize??ui;for(let n of i)s(n,t),t.byteLength>=r&&(yield t.subarray(0,r),t.consume(r));t.byteLength>0&&(yield t.subarray())}()}var hi=$n;var oe=Ne(xi(),1);function St(i){return new Uint8Array(i)}var Ct=10*1024,At=class{_pool;_poolOffset;constructor(){this._pool=St(Ct),this._poolOffset=0}write(e,t){let r=this._pool,s=this._poolOffset;oe.default.encode(e.id<<3|e.type,r,s),s+=oe.default.encode.bytes??0,(e.type===b.NEW_STREAM||e.type===b.MESSAGE_INITIATOR||e.type===b.MESSAGE_RECEIVER)&&e.data!=null?oe.default.encode(e.data.length,r,s):oe.default.encode(0,r,s),s+=oe.default.encode.bytes??0;let n=r.subarray(this._poolOffset,s);Ct-s<100?(this._pool=St(Ct),this._poolOffset=0):this._poolOffset=s,t.append(n),(e.type===b.NEW_STREAM||e.type===b.MESSAGE_INITIATOR||e.type===b.MESSAGE_RECEIVER)&&e.data!=null&&t.append(e.data)}},_i=new At;async function*Si(i,e=0){if(e==null||e===0){for await(let t of i){let r=new C;for(let s of t)_i.write(s,r);yield r.subarray()}return}yield*hi(i,{size:e,serialize:(t,r)=>{for(let s of t)_i.write(s,r)}})}var ro="ERR_STREAM_RESET",io="ERR_SINK_INVALID_STATE";function Rt(i){return i!=null&&typeof i.then=="function"}var Te=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;sinkController;sinkEnd;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;log;constructor(e){this.sinkController=new AbortController,this.sinkEnd=O(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.onEnd=e.onEnd,this.onCloseRead=e?.onCloseRead,this.onCloseWrite=e?.onCloseWrite,this.onReset=e?.onReset,this.onAbort=e?.onAbort,this.source=this.streamSource=J({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.readStatus="closed",this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new U(`writable end state is "${this.writeStatus}" not "ready"`,io);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let r=this.sendNewStream(t);Rt(r)&&await r}e=ge(e,this.sinkController.signal,{returnOnAbort:!0}),this.log.trace("sink reading from source");for await(let r of e){r=r instanceof Uint8Array?new C(r):r;let s=this.sendData(r,t);Rt(s)&&await s}this.log.trace("sink finished reading from source"),this.writeStatus="done",this.log.trace("sink calling closeWrite"),await this.closeWrite(t),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.onEnd!=null&&this.onEnd(this.endErr)):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.onEnd!=null&&this.onEnd(this.endErr)):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.log.trace("closing gracefully"),this.status="closing",await Promise.all([this.closeRead(e),this.closeWrite(e)]),this.status="closed",this.log.trace("closed gracefully")}async closeRead(e={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let t=this.readStatus;this.readStatus="closing",t==="ready"&&(this.log.trace("ending internal source queue"),this.streamSource.end()),this.status!=="reset"&&this.status!=="aborted"&&(this.log.trace("send close read to remote"),await this.sendCloseRead(e)),this.log.trace("closed readable end of stream")}async closeWrite(e={}){if(this.writeStatus==="closing"||this.writeStatus==="closed")return;this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus);let t=this.writeStatus;this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await this.sink([])),this.writeStatus="closing",t==="writing"&&await new Promise((r,s)=>{queueMicrotask(()=>{this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),this.sinkEnd.promise.then(r,s)})}),this.status!=="reset"&&this.status!=="aborted"&&(this.log.trace("send close write to remote"),await this.sendCloseWrite(e)),this.writeStatus="closed",this.log.trace("closed writable end of stream")}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();Rt(t)&&t.catch(r=>{this.log.error("error sending reset message",r)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new U("stream reset",ro);this.status="reset",this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("muxer destroyed"),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};var It=class extends Te{name;streamId;send;types;maxDataSize;constructor(e){super(e),this.types=e.direction==="outbound"?gt:ai,this.send=e.send,this.name=e.name,this.streamId=e.streamId,this.maxDataSize=e.maxDataSize}async sendNewStream(){await this.send({id:this.streamId,type:gt.NEW_STREAM,data:new C(wt(this.name))})}async sendData(e){for(e=e.sublist();e.byteLength>0;){let t=Math.min(e.byteLength,this.maxDataSize);await this.send({id:this.streamId,type:this.types.MESSAGE,data:e.sublist(0,t)}),e.consume(t)}}async sendReset(){await this.send({id:this.streamId,type:this.types.RESET})}async sendCloseWrite(){await this.send({id:this.streamId,type:this.types.CLOSE})}async sendCloseRead(){}};function Ci(i){let{id:e,name:t,send:r,onEnd:s,type:n="initiator",maxMsgSize:o=Et}=i;return new It({id:n==="initiator"?`i${e}`:`r${e}`,streamId:e,name:`${t??e}`,direction:n==="initiator"?"outbound":"inbound",maxDataSize:o,onEnd:s,send:r,log:we(`libp2p:mplex:stream:${n}:${e}`)})}var N=we("libp2p:mplex"),so=1024,no=1024,oo=1024*1024*4,ao=5,co=500;function Ai(i){let e={...i,type:`${me[i.type]} (${i.type})`};return i.type===b.NEW_STREAM&&(e.data=de(i.data instanceof Uint8Array?i.data:i.data.subarray())),(i.type===b.MESSAGE_INITIATOR||i.type===b.MESSAGE_RECEIVER)&&(e.data=de(i.data instanceof Uint8Array?i.data:i.data.subarray(),"base16")),e}var Me=class{protocol="/mplex/6.7.0";sink;source;_streamId;_streams;_init;_source;closeController;rateLimiter;closeTimeout;constructor(e){e=e??{},this._streamId=0,this._streams={initiators:new Map,receivers:new Map},this._init=e,this.closeTimeout=e.closeTimeout??co,this.sink=this._createSink(),this._source=$t({objectMode:!0,onEnd:()=>{for(let t of this._streams.initiators.values())t.destroy();for(let t of this._streams.receivers.values())t.destroy()}}),this.source=Kt(this._source,t=>Si(t,this._init.minSendBytes)),this.closeController=new AbortController,this.rateLimiter=new Ri.RateLimiterMemory({points:e.disconnectThreshold??ao,duration:1})}get streams(){let e=[];for(let t of this._streams.initiators.values())e.push(t);for(let t of this._streams.receivers.values())e.push(t);return e}newStream(e){if(this.closeController.signal.aborted)throw new Error("Muxer already closed");let t=this._streamId++;e=e==null?t.toString():e.toString();let r=this._streams.initiators;return this._newStream({id:t,name:e,type:"initiator",registry:r})}async close(e){if(this.closeController.signal.aborted)return;let t=e?.signal??AbortSignal.timeout(this.closeTimeout);try{await Promise.all(this.streams.map(async r=>r.close({signal:t}))),this._source.end(),await this._source.onEmpty({signal:t}),this.closeController.abort()}catch(r){this.abort(r)}}abort(e){this.closeController.signal.aborted||(this.streams.forEach(t=>{t.abort(e)}),this.closeController.abort(e))}_newReceiverStream(e){let{id:t,name:r}=e,s=this._streams.receivers;return this._newStream({id:t,name:r,type:"receiver",registry:s})}_newStream(e){let{id:t,name:r,type:s,registry:n}=e;if(N("new %s stream %s",s,t),s==="initiator"&&this._streams.initiators.size===(this._init.maxOutboundStreams??no))throw new U("Too many outbound streams open","ERR_TOO_MANY_OUTBOUND_STREAMS");if(n.has(t))throw new Error(`${s} stream ${t} already exists!`);let c=Ci({id:t,name:r,send:async u=>{N.enabled&&N.trace("%s stream %s send",s,t,Ai(u)),this._source.push(u)},type:s,onEnd:()=>{N("%s stream with id %s and protocol %s ended",s,t,c.protocol),n.delete(t),this._init.onStreamEnd!=null&&this._init.onStreamEnd(c)},maxMsgSize:this._init.maxMsgSize});return n.set(t,c),c}_createSink(){return async t=>{try{t=ge(t,this.closeController.signal,{returnOnAbort:!0});let r=new Ie(this._init.maxMsgSize,this._init.maxUnprocessedMessageQueueSize);for await(let s of t)for(let n of r.write(s))await this._handleIncoming(n);this._source.end()}catch(r){N("error in sink",r),this._source.end(r)}}}async _handleIncoming(e){let{id:t,type:r}=e;if(N.enabled&&N.trace("incoming message",Ai(e)),e.type===b.NEW_STREAM){if(this._streams.receivers.size===(this._init.maxInboundStreams??so)){N("too many inbound streams open"),this._source.push({id:t,type:b.RESET_RECEIVER});try{await this.rateLimiter.consume("new-stream",1)}catch{N("rate limit hit when opening too many new streams over the inbound stream limit - closing remote connection"),this.abort(new Error("Too many open streams"));return}return}let a=this._newReceiverStream({id:t,name:de(e.data instanceof Uint8Array?e.data:e.data.subarray())});this._init.onIncomingStream!=null&&this._init.onIncomingStream(a);return}let n=((r&1)===1?this._streams.initiators:this._streams.receivers).get(t);if(n==null){N("missing stream %s for message type %s",t,me[r]);try{await this.rateLimiter.consume("missing-stream",1)}catch{N("rate limit hit when receiving messages for streams that do not exist - closing remote connection"),this.abort(new Error("Too many messages for missing streams"));return}return}let o=this._init.maxStreamBufferSize??oo;try{switch(r){case b.MESSAGE_INITIATOR:case b.MESSAGE_RECEIVER:if(n.sourceReadableLength()>o)throw this._source.push({id:e.id,type:r===b.MESSAGE_INITIATOR?b.RESET_RECEIVER:b.RESET_INITIATOR}),new U("Input buffer full - increase Mplex maxBufferSize to accommodate slow consumers","ERR_STREAM_INPUT_BUFFER_FULL");n.sourcePush(e.data);break;case b.CLOSE_INITIATOR:case b.CLOSE_RECEIVER:n.remoteCloseWrite();break;case b.RESET_INITIATOR:case b.RESET_RECEIVER:n.reset();break;default:N("unknown message type %s",r)}}catch(a){N.error("error while processing message",a),n.abort(a)}}};var Lt=class{protocol="/mplex/6.7.0";_init;constructor(e={}){this._init=e}createStreamMuxer(e={}){return new Me({...e,...this._init})}};function lo(i={}){return()=>new Lt(i)}return ki(uo);})();
25
25
  return Libp2PMplex}));
@@ -0,0 +1,4 @@
1
+ {
2
+ "MplexInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_mplex.MplexInit.html",
3
+ "mplex": "https://libp2p.github.io/js-libp2p/functions/_libp2p_mplex.mplex.html"
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/mplex",
3
- "version": "9.0.0-fdd80820",
3
+ "version": "9.0.1",
4
4
  "description": "JavaScript implementation of https://github.com/libp2p/mplex",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/stream-multiplexer-mplex#readme",
@@ -56,8 +56,8 @@
56
56
  "test:electron-main": "aegir test -t electron-main"
57
57
  },
58
58
  "dependencies": {
59
- "@libp2p/interface": "0.1.0-fdd80820",
60
- "@libp2p/logger": "3.0.0-fdd80820",
59
+ "@libp2p/interface": "^0.1.0",
60
+ "@libp2p/logger": "^3.0.0",
61
61
  "abortable-iterator": "^5.0.1",
62
62
  "benchmark": "^2.1.4",
63
63
  "it-batched-bytes": "^2.0.2",
@@ -69,7 +69,7 @@
69
69
  "varint": "^6.0.0"
70
70
  },
71
71
  "devDependencies": {
72
- "@libp2p/interface-compliance-tests": "4.0.0-fdd80820",
72
+ "@libp2p/interface-compliance-tests": "^4.0.1",
73
73
  "@types/varint": "^6.0.0",
74
74
  "aegir": "^40.0.1",
75
75
  "cborg": "^2.0.1",