@libp2p/mplex 8.0.4-d853d124 → 8.0.4-f427cfc9

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,11 +1,11 @@
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 Ci=Object.create;var ye=Object.defineProperty;var Ri=Object.getOwnPropertyDescriptor;var Ai=Object.getOwnPropertyNames;var Li=Object.getPrototypeOf,Ti=Object.prototype.hasOwnProperty;var y=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),A=(i,e)=>{for(var t in e)ye(i,t,{get:e[t],enumerable:!0})},It=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ai(e))!Ti.call(i,n)&&n!==t&&ye(i,n,{get:()=>e[n],enumerable:!(r=Ri(e,n))||r.enumerable});return i};var Pe=(i,e,t)=>(t=i!=null?Ci(Li(i)):{},It(e||!i||!i.__esModule?ye(t,"default",{value:i,enumerable:!0}):t,i)),Ii=i=>It(ye({},"__esModule",{value:!0}),i);var Nt=y((co,Mt)=>{var Q=1e3,Y=Q*60,X=Y*60,W=X*24,Mi=W*7,Ni=W*365.25;Mt.exports=function(i,e){e=e||{};var t=typeof i;if(t==="string"&&i.length>0)return ki(i);if(t==="number"&&isFinite(i))return e.long?Pi(i):vi(i);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(i))};function ki(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*Ni;case"weeks":case"week":case"w":return t*Mi;case"days":case"day":case"d":return t*W;case"hours":case"hour":case"hrs":case"hr":case"h":return t*X;case"minutes":case"minute":case"mins":case"min":case"m":return t*Y;case"seconds":case"second":case"secs":case"sec":case"s":return t*Q;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function vi(i){var e=Math.abs(i);return e>=W?Math.round(i/W)+"d":e>=X?Math.round(i/X)+"h":e>=Y?Math.round(i/Y)+"m":e>=Q?Math.round(i/Q)+"s":i+"ms"}function Pi(i){var e=Math.abs(i);return e>=W?we(i,e,W,"day"):e>=X?we(i,e,X,"hour"):e>=Y?we(i,e,Y,"minute"):e>=Q?we(i,e,Q,"second"):i+" ms"}function we(i,e,t,r){var n=e>=t*1.5;return Math.round(i/t)+" "+r+(n?"s":"")}});var vt=y((uo,kt)=>{function Bi(i){t.debug=t,t.default=t,t.coerce=c,t.disable=s,t.enable=n,t.enabled=o,t.humanize=Nt(),t.destroy=l,Object.keys(i).forEach(u=>{t[u]=i[u]}),t.names=[],t.skips=[],t.formatters={};function e(u){let h=0;for(let d=0;d<u.length;d++)h=(h<<5)-h+u.charCodeAt(d),h|=0;return t.colors[Math.abs(h)%t.colors.length]}t.selectColor=e;function t(u){let h,d=null,w,m;function f(...b){if(!f.enabled)return;let E=f,S=Number(new Date),N=S-(h||S);E.diff=N,E.prev=h,E.curr=S,h=S,b[0]=t.coerce(b[0]),typeof b[0]!="string"&&b.unshift("%O");let C=0;b[0]=b[0].replace(/%([a-zA-Z%])/g,(k,R)=>{if(k==="%%")return"%";C++;let v=t.formatters[R];if(typeof v=="function"){let H=b[C];k=v.call(E,H),b.splice(C,1),C--}return k}),t.formatArgs.call(E,b),(E.log||t.log).apply(E,b)}return f.namespace=u,f.useColors=t.useColors(),f.color=t.selectColor(u),f.extend=r,f.destroy=t.destroy,Object.defineProperty(f,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(w!==t.namespaces&&(w=t.namespaces,m=t.enabled(u)),m),set:b=>{d=b}}),typeof t.init=="function"&&t.init(f),f}function r(u,h){let d=t(this.namespace+(typeof h>"u"?":":h)+u);return d.log=this.log,d}function n(u){t.save(u),t.namespaces=u,t.names=[],t.skips=[];let h,d=(typeof u=="string"?u:"").split(/[\s,]+/),w=d.length;for(h=0;h<w;h++)d[h]&&(u=d[h].replace(/\*/g,".*?"),u[0]==="-"?t.skips.push(new RegExp("^"+u.slice(1)+"$")):t.names.push(new RegExp("^"+u+"$")))}function s(){let u=[...t.names.map(a),...t.skips.map(a).map(h=>"-"+h)].join(",");return t.enable(""),u}function o(u){if(u[u.length-1]==="*")return!0;let h,d;for(h=0,d=t.skips.length;h<d;h++)if(t.skips[h].test(u))return!1;for(h=0,d=t.names.length;h<d;h++)if(t.names[h].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack||u.message:u}function l(){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=Bi});var Pt=y((L,ge)=>{L.formatArgs=Oi;L.save=Fi;L.load=Ui;L.useColors=Di;L.storage=qi();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 Di(){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 Oi(i){if(i[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+i[0]+(this.useColors?"%c ":" ")+"+"+ge.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)}L.log=console.debug||console.log||(()=>{});function Fi(i){try{i?L.storage.setItem("debug",i):L.storage.removeItem("debug")}catch{}}function Ui(){let i;try{i=L.storage.getItem("debug")}catch{}return!i&&typeof process<"u"&&"env"in process&&(i=process.env.DEBUG),i}function qi(){try{return localStorage}catch{}}ge.exports=vt()(L);var{formatters:zi}=ge.exports;zi.j=function(i){try{return JSON.stringify(i)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var ue=y((vo,Wt)=>{Wt.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 jt=y((Bo,Gt)=>{Gt.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 Qt=y((Do,Ht)=>{var an=jt();Ht.exports=an});var I=y((Fo,Yt)=>{Yt.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 ee=y((qo,Jt)=>{var Ve=ue(),cn=Qt(),Xt=I();Jt.exports=class extends Ve{constructor(e={}){super(e),this.inMemoryBlockOnConsumed=e.inMemoryBlockOnConsumed||e.inmemoryBlockOnConsumed,this.inMemoryBlockDuration=e.inMemoryBlockDuration||e.inmemoryBlockDuration,this.insuranceLimiter=e.insuranceLimiter,this._inMemoryBlockedKeys=new cn}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(l=>{t(l)})}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 Ve?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 Ve))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 Xt(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 Xt(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 tr=y((zo,er)=>{var un=ee(),ln=I(),Zt="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} ",Ke=class extends un{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:Zt})}_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 ln;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((l,u)=>l?o(l):s(u));else if(a>0){let l=function(u,h){return u?o(u):s(h)};typeof this.client.rlflxIncr=="function"?this.client.rlflxIncr(e,t,a,l):this.client.eval(Zt,1,e,t,a,l)}else c.incrby(e,t).pttl(e).exec((l,u)=>l?o(l):s(u))})}_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)})})}};er.exports=Ke});var nr=y(($o,ir)=>{var hn=ee(),fn=I();function rr(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 le=class extends hn{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=rr(this.client)}):(this._initCollection(),this._driverVersion=rr(this.client))}get dbName(){return this._dbName}set dbName(e){this._dbName=typeof e>"u"?le.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 fn,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 l={upsert:!0};return this._driverVersion.major>=4||this._driverVersion.major===3&&this._driverVersion.feature>=7||this._driverVersion.feature>=6&&this._driverVersion.patch>=7?l.returnDocument="after":l.returnOriginal=!1,new Promise((u,h)=>{this._collection.findOneAndUpdate(a,c,l).then(d=>{u(d)}).catch(d=>{if(d&&d.code===11e3){let w=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(w,m,l).then(f=>{u(f)}).catch(f=>{f&&f.code===11e3?this._upsert(e,t,r,n).then(b=>u(b)).catch(b=>h(b)):h(f)})}else h(d)})})}_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)}};ir.exports=le});var or=y((Vo,sr)=>{var dn=ee(),mn=I(),We=class extends dn{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 mn,[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 l=Date.now(),u=n>0?l+n:null,h,d;s?(h=`INSERT INTO ??.?? VALUES (?, ?, ?)
2
+ "use strict";var Libp2PMplex=(()=>{var Di=Object.create;var we=Object.defineProperty;var Oi=Object.getOwnPropertyDescriptor;var Fi=Object.getOwnPropertyNames;var Ui=Object.getPrototypeOf,qi=Object.prototype.hasOwnProperty;var g=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),v=(i,e)=>{for(var t in e)we(i,t,{get:e[t],enumerable:!0})},kt=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Fi(e))!qi.call(i,n)&&n!==t&&we(i,n,{get:()=>e[n],enumerable:!(r=Oi(e,n))||r.enumerable});return i};var Pe=(i,e,t)=>(t=i!=null?Di(Ui(i)):{},kt(e||!i||!i.__esModule?we(t,"default",{value:i,enumerable:!0}):t,i)),zi=i=>kt(we({},"__esModule",{value:!0}),i);var Bt=g((Lo,Pt)=>{var Q=1e3,X=Q*60,Y=X*60,G=Y*24,$i=G*7,Vi=G*365.25;Pt.exports=function(i,e){e=e||{};var t=typeof i;if(t==="string"&&i.length>0)return Ki(i);if(t==="number"&&isFinite(i))return e.long?Gi(i):Wi(i);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(i))};function Ki(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*$i;case"days":case"day":case"d":return t*G;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*X;case"seconds":case"second":case"secs":case"sec":case"s":return t*Q;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function Wi(i){var e=Math.abs(i);return e>=G?Math.round(i/G)+"d":e>=Y?Math.round(i/Y)+"h":e>=X?Math.round(i/X)+"m":e>=Q?Math.round(i/Q)+"s":i+"ms"}function Gi(i){var e=Math.abs(i);return e>=G?ge(i,e,G,"day"):e>=Y?ge(i,e,Y,"hour"):e>=X?ge(i,e,X,"minute"):e>=Q?ge(i,e,Q,"second"):i+" ms"}function ge(i,e,t,r){var n=e>=t*1.5;return Math.round(i/t)+" "+r+(n?"s":"")}});var Ot=g((To,Dt)=>{function ji(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(h=>{t[h]=i[h]}),t.names=[],t.skips=[],t.formatters={};function e(h){let l=0;for(let m=0;m<h.length;m++)l=(l<<5)-l+h.charCodeAt(m),l|=0;return t.colors[Math.abs(l)%t.colors.length]}t.selectColor=e;function t(h){let l,m=null,E,d;function f(...p){if(!f.enabled)return;let y=f,x=Number(new Date),S=x-(l||x);y.diff=S,y.prev=l,y.curr=x,l=x,p[0]=t.coerce(p[0]),typeof p[0]!="string"&&p.unshift("%O");let w=0;p[0]=p[0].replace(/%([a-zA-Z%])/g,(L,_)=>{if(L==="%%")return"%";w++;let A=t.formatters[_];if(typeof A=="function"){let O=p[w];L=A.call(y,O),p.splice(w,1),w--}return L}),t.formatArgs.call(y,p),(y.log||t.log).apply(y,p)}return f.namespace=h,f.useColors=t.useColors(),f.color=t.selectColor(h),f.extend=r,f.destroy=t.destroy,Object.defineProperty(f,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(E!==t.namespaces&&(E=t.namespaces,d=t.enabled(h)),d),set:p=>{m=p}}),typeof t.init=="function"&&t.init(f),f}function r(h,l){let m=t(this.namespace+(typeof l>"u"?":":l)+h);return m.log=this.log,m}function n(h){t.save(h),t.namespaces=h,t.names=[],t.skips=[];let l,m=(typeof h=="string"?h:"").split(/[\s,]+/),E=m.length;for(l=0;l<E;l++)m[l]&&(h=m[l].replace(/\*/g,".*?"),h[0]==="-"?t.skips.push(new RegExp("^"+h.slice(1)+"$")):t.names.push(new RegExp("^"+h+"$")))}function s(){let h=[...t.names.map(a),...t.skips.map(a).map(l=>"-"+l)].join(",");return t.enable(""),h}function o(h){if(h[h.length-1]==="*")return!0;let l,m;for(l=0,m=t.skips.length;l<m;l++)if(t.skips[l].test(h))return!1;for(l=0,m=t.names.length;l<m;l++)if(t.names[l].test(h))return!0;return!1}function a(h){return h.toString().substring(2,h.toString().length-2).replace(/\.\*\?$/,"*")}function c(h){return h instanceof Error?h.stack||h.message:h}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}Dt.exports=ji});var Ft=g((k,xe)=>{k.formatArgs=Qi;k.save=Xi;k.load=Yi;k.useColors=Hi;k.storage=Ji();k.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`."))}})();k.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 Hi(){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 ":" ")+"+"+xe.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)}k.log=console.debug||console.log||(()=>{});function Xi(i){try{i?k.storage.setItem("debug",i):k.storage.removeItem("debug")}catch{}}function Yi(){let i;try{i=k.storage.getItem("debug")}catch{}return!i&&typeof process<"u"&&"env"in process&&(i=process.env.DEBUG),i}function Ji(){try{return localStorage}catch{}}xe.exports=Ot()(k);var{formatters:Zi}=xe.exports;Zi.j=function(i){try{return JSON.stringify(i)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var le=g((da,Yt)=>{Yt.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 Zt=g((pa,Jt)=>{Jt.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 tr=g((ba,er)=>{var an=Zt();er.exports=an});var B=g((wa,rr)=>{rr.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 Z=g((xa,nr)=>{var qe=le(),cn=tr(),ir=B();nr.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 cn}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 ir(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 ir(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 ar=g((Ea,or)=>{var hn=Z(),ln=B(),sr="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 hn{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:sr})}_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 ln;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,h)=>u?o(u):s(h));else if(a>0){let u=function(h,l){return h?o(h):s(l)};typeof this.client.rlflxIncr=="function"?this.client.rlflxIncr(e,t,a,u):this.client.eval(sr,1,e,t,a,u)}else c.incrby(e,t).pttl(e).exec((u,h)=>u?o(u):s(h))})}_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)})})}};or.exports=ze});var lr=g((_a,hr)=>{var un=Z(),fn=B();function cr(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 ue=class extends un{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=cr(this.client)}):(this._initCollection(),this._driverVersion=cr(this.client))}get dbName(){return this._dbName}set dbName(e){this._dbName=typeof e>"u"?ue.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 fn,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((h,l)=>{this._collection.findOneAndUpdate(a,c,u).then(m=>{h(m)}).catch(m=>{if(m&&m.code===11e3){let E=Object.assign({$or:[{expire:{$lte:new Date}},{expire:{$eq:null}}],key:e},o),d={$set:Object.assign({key:e,points:t,expire:r>0?new Date(Date.now()+r):null},o)};this._collection.findOneAndUpdate(E,d,u).then(f=>{h(f)}).catch(f=>{f&&f.code===11e3?this._upsert(e,t,r,n).then(p=>h(p)).catch(p=>l(p)):l(f)})}else l(m)})})}_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)}};hr.exports=ue});var fr=g((Sa,ur)=>{var dn=Z(),mn=B(),$e=class extends dn{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 mn,[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(),h=n>0?u+n:null,l,m;s?(l=`INSERT INTO ??.?? VALUES (?, ?, ?)
3
3
  ON DUPLICATE KEY UPDATE
4
4
  points = ?,
5
- expire = ?;`,d=[this.dbName,this.tableName,t,r,u,r,u]):(h=`INSERT INTO ??.?? VALUES (?, ?, ?)
5
+ expire = ?;`,m=[this.dbName,this.tableName,t,r,h,r,h]):(l=`INSERT INTO ??.?? VALUES (?, ?, ?)
6
6
  ON DUPLICATE KEY UPDATE
7
7
  points = IF(expire <= ?, ?, points + (?)),
8
- expire = IF(expire <= ?, ?, expire);`,d=[this.dbName,this.tableName,t,r,u,l,r,r,l,u]),e.query(h,d,w=>{if(w)return e.rollback(),a(w);e.query("SELECT points, expire FROM ??.?? WHERE `key` = ?;",[this.dbName,this.tableName,t],(m,f)=>{if(m)return e.rollback(),a(m);e.query("COMMIT",b=>{if(b)return e.rollback(),a(b);o(f)})})})})})}_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"))}};sr.exports=We});var cr=y((Ko,ar)=>{var pn=ee(),bn=I(),Ge=class extends pn{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);`,m=[this.dbName,this.tableName,t,r,h,u,r,r,u,h]),e.query(l,m,E=>{if(E)return e.rollback(),a(E);e.query("SELECT points, expire FROM ??.?? WHERE `key` = ?;",[this.dbName,this.tableName,t],(d,f)=>{if(d)return e.rollback(),a(d);e.query("COMMIT",p=>{if(p)return e.rollback(),a(p);o(f)})})})})})}_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"))}};ur.exports=$e});var mr=g((Ca,dr)=>{var pn=Z(),bn=B(),Ve=class extends pn{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
@@ -21,5 +21,5 @@
21
21
  END,
22
22
  expire = ${o}
23
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"))}};ar.exports=Ge});var ur=y(()=>{});var lr=y(()=>{});var fr=y((Yo,hr)=>{hr.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 mr=y((Jo,dr)=>{var yn=fr(),je=I();dr.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 je(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 yn(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 je(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 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 Qe=y((Zo,br)=>{var wn=ue(),gn=mr(),pr=I(),He=class extends wn{constructor(e={}){super(e),this._memoryStorage=new gn}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 l=Math.ceil(c.msBeforeNext/(c.remainingPoints+2));l<this.execEvenlyMinDelayMs&&(l=c.consumedPoints*this.execEvenlyMinDelayMs),setTimeout(n,l,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 pr(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 pr(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)))}};br.exports=He});var Sr=y((ea,xr)=>{var yr=ur(),En=lr(),_n=ue(),gr=Qe(),xn=I(),B="rate_limiter_flexible",ie=null,wr=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:B,keyPrefix:e.keyPrefix,promiseId:e.promiseId,type:t,data:n})},Er=function(i){setTimeout(()=>{this._initiated?process.send(i):typeof this._promises[i.promiseId]<"u"&&Er.call(this,i)},30)},te=function(i,e,t,r,n){let s={channel:B,keyPrefix:this.keyPrefix,func:i,promiseId:e,data:{key:t,arg:r,opts:n}};this._initiated?process.send(s):Er.call(this,s)},_r=function(i,e){if(!e||e.channel!==B||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=>{wr(i,e,"resolve",r)}).catch(r=>{wr(i,e,"reject",r)})},Sn=function(i){if(!i||i.channel!==B||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 xn(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]}},Cn=function(){return{points:this.points,duration:this.duration,blockDuration:this.blockDuration,execEvenly:this.execEvenly,execEvenlyMinDelayMs:this.execEvenlyMinDelayMs,keyPrefix:this.keyPrefix}},re=function(i,e){let t=process.hrtime(),r=t[0].toString()+t[1].toString();return typeof this._promises[r]<"u"&&(r+=En.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},Ye=class{constructor(){if(ie)return ie;this._rateLimiters={},yr.setMaxListeners(0),yr.on("message",(e,t)=>{t&&t.channel===B&&t.type==="init"?(typeof this._rateLimiters[t.opts.keyPrefix]>"u"&&(this._rateLimiters[t.opts.keyPrefix]=new gr(t.opts)),e.send({channel:B,type:"init",keyPrefix:t.opts.keyPrefix})):_r.call(this,e,t)}),ie=this}},Xe=class{constructor(e){if(ie)return ie;this._rateLimiters={},e.launchBus((t,r)=>{r.on("process:msg",n=>{let s=n.raw;if(s&&s.channel===B&&s.type==="init")typeof this._rateLimiters[s.opts.keyPrefix]>"u"&&(this._rateLimiters[s.opts.keyPrefix]=new gr(s.opts)),e.sendDataToProcessId(n.process.pm_id,{data:{},topic:B,channel:B,type:"init",keyPrefix:s.opts.keyPrefix},(o,a)=>{o&&console.log(o,a)});else{let o={send:a=>{let c=a;c.topic=B,typeof c.data>"u"&&(c.data={}),e.sendDataToProcessId(n.process.pm_id,c,(l,u)=>{l&&console.log(l,u)})}};_r.call(this,o,s)}})}),ie=this}},Je=class extends _n{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===B&&t.type==="init"&&t.keyPrefix===this.keyPrefix?this._initiated=!0:Sn.call(this,t)}),process.send({channel:B,type:"init",opts:Cn.call(this)}),this._promises={}}consume(e,t=1,r={}){return new Promise((n,s)=>{let o=re.call(this,n,s);te.call(this,"consume",o,e,t,r)})}penalty(e,t=1,r={}){return new Promise((n,s)=>{let o=re.call(this,n,s);te.call(this,"penalty",o,e,t,r)})}reward(e,t=1,r={}){return new Promise((n,s)=>{let o=re.call(this,n,s);te.call(this,"reward",o,e,t,r)})}block(e,t,r={}){return new Promise((n,s)=>{let o=re.call(this,n,s);te.call(this,"block",o,e,t,r)})}get(e,t={}){return new Promise((r,n)=>{let s=re.call(this,r,n);te.call(this,"get",s,e,t)})}delete(e,t={}){return new Promise((r,n)=>{let s=re.call(this,r,n);te.call(this,"delete",s,e,t)})}};xr.exports={RateLimiterClusterMaster:Ye,RateLimiterClusterMasterPM2:Xe,RateLimiterCluster:Je}});var Rr=y((ta,Cr)=>{var Rn=ee(),An=I(),Ze=class extends Rn{constructor(e){super(e),this.client=e.storeClient}_getRateLimiterRes(e,t,r){let n=new An;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(),l=Math.floor(r/1e3);n?this.client.set(e,t,l,u=>{u?a(u):this.client.set(`${e}_expire`,l>0?c+l*1e3:-1,l,()=>{let h={consumedPoints:t,msBeforeNext:l>0?l*1e3:-1};o(h)})}):this.client.incr(e,t,(u,h)=>{u||h===!1?this.client.add(e,t,l,(d,w)=>{if(d||!w)if(typeof s.attemptNumber>"u"||s.attemptNumber<3){let m=Object.assign({},s);m.attemptNumber=m.attemptNumber?m.attemptNumber+1:1,this._upsert(e,t,r,n,m).then(f=>o(f)).catch(f=>a(f))}else a(new Error("Can not add key"));else this.client.add(`${e}_expire`,l>0?c+l*1e3:-1,l,()=>{let m={consumedPoints:t,msBeforeNext:l>0?l*1e3:-1};o(m)})}):this.client.get(`${e}_expire`,(d,w)=>{if(d)a(d);else{let m=w===!1?0:w,f={consumedPoints:h,msBeforeNext:m>=0?Math.max(m-c,0):-1};o(f)}})})})}_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 l=c===!1?0:c,u={consumedPoints:o,msBeforeNext:l>=0?Math.max(l-n,0):-1};t(u)}}):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)})})})}};Cr.exports=Ze});var Tr=y((ia,Lr)=>{var Ar=I();Lr.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 Ar(0,Number.MAX_SAFE_INTEGER,0,!1)}getWhiteRes(){return new Ar(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 Mr=y((sa,Ir)=>{var Ln=ue();Ir.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 Ln))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(l=>{l.rejected===!0&&(c=!0)});for(let l=0;l<o.length;l++)c&&o[l].rejected===!0?a[this._limiters[l].keyPrefix]=o[l].rej:c||(a[this._limiters[l].keyPrefix]=o[l]);c?n(a):r(a)})})}}});var kr=y((aa,Nr)=>{Nr.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 Dr=y((ua,Br)=>{var vr=kr(),Pr=4294967295,et="limiter";Br.exports=class{constructor(e,t={maxQueueSize:Pr}){this._queueLimiters={KEY_DEFAULT:new Ce(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 Ce(this._limiterFlexible,{key:t,maxQueueSize:this._maxQueueSize})),this._queueLimiters[t].removeTokens(e)}};var Ce=class{constructor(e,t={maxQueueSize:Pr,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,n)=>{if(e>t._limiterFlexible.points){n(new vr(`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 vr(`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 Fr=y((ha,Or)=>{var tt=I();Or.exports=class{constructor(e,t){this._rateLimiter=e,this._burstLimiter=t}_combineRes(e,t){return new tt(e.remainingPoints,Math.min(e.msBeforeNext,t.msBeforeNext),e.consumedPoints,e.isFirstInDuration)}consume(e,t=1,r={}){return this._rateLimiter.consume(e,t,r).catch(n=>n instanceof tt?this._burstLimiter.consume(e,t,r).then(s=>Promise.resolve(this._combineRes(n,s))).catch(s=>s instanceof tt?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=y((fa,Ur)=>{var Tn=tr(),In=nr(),Mn=or(),Nn=cr(),{RateLimiterClusterMaster:kn,RateLimiterClusterMasterPM2:vn,RateLimiterCluster:Pn}=Sr(),Bn=Qe(),Dn=Rr(),On=Tr(),Fn=Mr(),Un=Dr(),qn=Fr(),zn=I();Ur.exports={RateLimiterRedis:Tn,RateLimiterMongo:In,RateLimiterMySQL:Mn,RateLimiterPostgres:Nn,RateLimiterMemory:Bn,RateLimiterMemcache:Dn,RateLimiterClusterMaster:kn,RateLimiterClusterMasterPM2:vn,RateLimiterCluster:Pn,RLWrapperBlackAndWhite:On,RateLimiterUnion:Fn,RateLimiterQueue:Un,BurstyRateLimiter:qn,RateLimiterRes:zn}});var hi=y((Ac,li)=>{li.exports=_t;var ui=128,Ds=127,Os=~Ds,Fs=Math.pow(2,31);function _t(i,e,t){if(Number.MAX_SAFE_INTEGER&&i>Number.MAX_SAFE_INTEGER)throw _t.bytes=0,new RangeError("Could not encode varint");e=e||[],t=t||0;for(var r=t;i>=Fs;)e[t++]=i&255|ui,i/=128;for(;i&Os;)e[t++]=i&255|ui,i>>>=7;return e[t]=i|0,_t.bytes=t-r+1,e}});var mi=y((Lc,di)=>{di.exports=xt;var Us=128,fi=127;function xt(i,r){var t=0,r=r||0,n=0,s=r,o,a=i.length;do{if(s>=a||n>49)throw xt.bytes=0,new RangeError("Could not decode varint");o=i[s++],t+=n<28?(o&fi)<<n:(o&fi)*Math.pow(2,n),n+=7}while(o>=Us);return xt.bytes=s-r,t}});var bi=y((Tc,pi)=>{var qs=Math.pow(2,7),zs=Math.pow(2,14),$s=Math.pow(2,21),Vs=Math.pow(2,28),Ks=Math.pow(2,35),Ws=Math.pow(2,42),Gs=Math.pow(2,49),js=Math.pow(2,56),Hs=Math.pow(2,63);pi.exports=function(i){return i<qs?1:i<zs?2:i<$s?3:i<Vs?4:i<Ks?5:i<Ws?6:i<Gs?7:i<js?8:i<Hs?9:10}});var wi=y((Ic,yi)=>{yi.exports={encode:hi(),decode:mi(),encodingLength:bi()}});var io={};A(io,{mplex:()=>ro});var F=class extends Error{code;props;constructor(e,t,r){super(e),this.code=t,this.name=r?.name??"CodeError",this.props=r??{}}};var T=Pe(Pt(),1);var Ue={};A(Ue,{base32:()=>$,base32hex:()=>Yi,base32hexpad:()=>Ji,base32hexpadupper:()=>Zi,base32hexupper:()=>Xi,base32pad:()=>Hi,base32padupper:()=>Qi,base32upper:()=>ji,base32z:()=>en});function $i(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),l=Math.log(a)/Math.log(256),u=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 f=0,b=0,E=0,S=m.length;E!==S&&m[E]===0;)E++,f++;for(var N=(S-E)*u+1>>>0,C=new Uint8Array(N);E!==S;){for(var D=m[E],k=0,R=N-1;(D!==0||k<b)&&R!==-1;R--,k++)D+=256*C[R]>>>0,C[R]=D%a>>>0,D=D/a>>>0;if(D!==0)throw new Error("Non-zero carry");b=k,E++}for(var v=N-b;v!==N&&C[v]===0;)v++;for(var H=c.repeat(f);v<N;++v)H+=i.charAt(C[v]);return H}function d(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var f=0;if(m[f]!==" "){for(var b=0,E=0;m[f]===c;)b++,f++;for(var S=(m.length-f)*l+1>>>0,N=new Uint8Array(S);m[f];){var C=t[m.charCodeAt(f)];if(C===255)return;for(var D=0,k=S-1;(C!==0||D<E)&&k!==-1;k--,D++)C+=a*N[k]>>>0,N[k]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");E=D,f++}if(m[f]!==" "){for(var R=S-E;R!==S&&N[R]===0;)R++;for(var v=new Uint8Array(b+(S-R)),H=b;R!==S;)v[H++]=N[R++];return v}}}function w(m){var f=d(m);if(f)return f;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:d,decode:w}}var Vi=$i,Ki=Vi,Bt=Ki;var ho=new Uint8Array(0);var Dt=(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},U=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 Be=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")}},De=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)}},Oe=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 Oe({...i.decoders||{[i.prefix]:i},...e.decoders||{[e.prefix]:e}}),Fe=class{constructor(e,t,r,n){this.name=e,this.prefix=t,this.baseEncode=r,this.baseDecode=n,this.encoder=new Be(e,t,r),this.decoder=new De(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},J=({name:i,prefix:e,encode:t,decode:r})=>new Fe(i,e,t,r),z=({prefix:i,name:e,alphabet:t})=>{let{encode:r,decode:n}=Bt(t,e);return J({prefix:i,name:e,encode:r,decode:s=>U(n(s))})},Wi=(i,e,t,r)=>{let n={};for(let u=0;u<e.length;++u)n[e[u]]=u;let s=i.length;for(;i[s-1]==="=";)--s;let o=new Uint8Array(s*t/8|0),a=0,c=0,l=0;for(let u=0;u<s;++u){let h=n[i[u]];if(h===void 0)throw new SyntaxError(`Non-${r} character`);c=c<<t|h,a+=t,a>=8&&(a-=8,o[l++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},Gi=(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},g=({name:i,prefix:e,bitsPerChar:t,alphabet:r})=>J({prefix:e,name:i,encode(n){return Gi(n,r,t)},decode(n){return Wi(n,r,t,i)}});var $=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ji=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Hi=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Qi=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Yi=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Xi=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ji=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Zi=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),en=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var qe={};A(qe,{base58btc:()=>P,base58flickr:()=>tn});var P=z({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),tn=z({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var $e={};A($e,{base64:()=>ze,base64pad:()=>rn,base64url:()=>nn,base64urlpad:()=>sn});var ze=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),rn=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),nn=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sn=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});T.default.formatters.b=i=>i==null?"undefined":P.baseEncode(i);T.default.formatters.t=i=>i==null?"undefined":$.baseEncode(i);T.default.formatters.m=i=>i==null?"undefined":ze.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 on(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 Ee(i){let e=on(`${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 ce=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 _e(i,e,t){let r=t??{},n=zt(i);async function*s(){let o,a=()=>{o?.()};for(e.addEventListener("abort",a);;){let c;try{if(e.aborted){let{abortMessage:u,abortCode:h}=r;throw new ce(u,h)}let l=new Promise((u,h)=>{o=()=>{let{abortMessage:d,abortCode:w}=r;h(new ce(d,w))}});c=await Promise.race([l,n.next()]),o=null}catch(l){e.removeEventListener("abort",a);let u=l.type==="aborted"&&e.aborted;if(u&&r.onAbort!=null&&r.onAbort(i),typeof n.return=="function")try{let h=n.return();h instanceof Promise&&h.catch(d=>{r.onReturnError!=null&&r.onReturnError(d)})}catch(h){r.onReturnError!=null&&r.onReturnError(h)}if(u&&r.returnOnAbort===!0)return;throw l}if(c.done===!0)break;yield c.value}e.removeEventListener("abort",a)}return s()}function xe(i){let e=new globalThis.AbortController;function t(){e.abort();for(let s of i)s?.removeEventListener!=null&&s.removeEventListener("abort",t)}for(let s of i){if(s?.aborted===!0){t();break}s?.addEventListener!=null&&s.addEventListener("abort",t)}function r(){for(let s of i)s?.removeEventListener!=null&&s.removeEventListener("abort",t)}let n=e.signal;return n.clear=r,n}var Se=class{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}},Z=class{constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Se(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 Se(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()}};function $t(i={}){return Kt(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 Vt(i={}){return Kt(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 Kt(i,e){e=e??{};let t=e.onEnd,r=new Z,n,s,o,a=async()=>r.isEmpty()?o?{done:!0}:await new Promise((f,b)=>{s=E=>{s=null,r.push(E);try{f(i(r))}catch(S){b(S)}return n}}):i(r),c=f=>s!=null?s(f):(r.push(f),n),l=f=>(r=new Z,s!=null?s({error:f}):(r.push({error:f}),n)),u=f=>{if(o)return n;if(e?.objectMode!==!0&&f?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return c({done:!1,value:f})},h=f=>o?n:(o=!0,f!=null?l(f):c({done:!0})),d=()=>(r=new Z,h(),{done:!0}),w=f=>(h(f),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:a,return:d,throw:w,push:u,end:h,get readableLength(){return r.size}},t==null)return n;let m=n;return n={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(f){return m.throw(f),t!=null&&(t(f),t=void 0),{done:!0}},return(){return m.return(),t!=null&&(t(),t=void 0),{done:!0}},push:u,end(f){return m.end(f),t!=null&&(t(f),t=void 0),n},get readableLength(){return m.readableLength}},n}var Si=Pe(qr(),1);function V(i){return globalThis.Buffer!=null?new Uint8Array(i.buffer,i.byteOffset,i.byteLength):i}function q(i=0){return globalThis.Buffer?.alloc!=null?V(globalThis.Buffer.alloc(i)):new Uint8Array(i)}function K(i=0){return globalThis.Buffer?.allocUnsafe!=null?V(globalThis.Buffer.allocUnsafe(i)):new Uint8Array(i)}function Re(i,e){e==null&&(e=i.reduce((n,s)=>n+s.length,0));let t=K(e),r=0;for(let n of i)t.set(n,r),r+=n.length;return V(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={};A(it,{identity:()=>$n});var $n=J({prefix:"\0",name:"identity",encode:i=>Ft(i),decode:i=>Ot(i)});var nt={};A(nt,{base2:()=>Vn});var Vn=g({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var st={};A(st,{base8:()=>Kn});var Kn=g({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ot={};A(ot,{base10:()=>Wn});var Wn=z({prefix:"9",name:"base10",alphabet:"0123456789"});var at={};A(at,{base16:()=>Gn,base16upper:()=>jn});var Gn=g({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),jn=g({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ct={};A(ct,{base36:()=>Hn,base36upper:()=>Qn});var Hn=z({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Qn=z({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ut={};A(ut,{base256emoji:()=>es});var zr=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}"),Yn=zr.reduce((i,e,t)=>(i[t]=e,i),[]),Xn=zr.reduce((i,e,t)=>(i[e.codePointAt(0)]=t,i),[]);function Jn(i){return i.reduce((e,t)=>(e+=Yn[t],e),"")}function Zn(i){let e=[];for(let t of i){let r=Xn[t.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(r)}return new Uint8Array(e)}var es=J({prefix:"\u{1F680}",name:"base256emoji",encode:Jn,decode:Zn});var dt={};A(dt,{sha256:()=>gs,sha512:()=>Es});var ts=Kr,$r=128,rs=127,is=~rs,ns=Math.pow(2,31);function Kr(i,e,t){e=e||[],t=t||0;for(var r=t;i>=ns;)e[t++]=i&255|$r,i/=128;for(;i&is;)e[t++]=i&255|$r,i>>>=7;return e[t]=i|0,Kr.bytes=t-r+1,e}var ss=lt,os=128,Vr=127;function lt(i,r){var t=0,r=r||0,n=0,s=r,o,a=i.length;do{if(s>=a)throw lt.bytes=0,new RangeError("Could not decode varint");o=i[s++],t+=n<28?(o&Vr)<<n:(o&Vr)*Math.pow(2,n),n+=7}while(o>=os);return lt.bytes=s-r,t}var as=Math.pow(2,7),cs=Math.pow(2,14),us=Math.pow(2,21),ls=Math.pow(2,28),hs=Math.pow(2,35),fs=Math.pow(2,42),ds=Math.pow(2,49),ms=Math.pow(2,56),ps=Math.pow(2,63),bs=function(i){return i<as?1:i<cs?2:i<us?3:i<ls?4:i<hs?5:i<fs?6:i<ds?7:i<ms?8:i<ps?9:10},ys={encode:ts,decode:ss,encodingLength:bs},ws=ys,he=ws;var fe=(i,e=0)=>[he.decode(i,e),he.decode.bytes],ne=(i,e,t=0)=>(he.encode(i,e,t),e),se=i=>he.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)},Wr=i=>{let e=U(i),[t,r]=fe(e),[n,s]=fe(e.subarray(r)),o=e.subarray(r+s);if(o.byteLength!==n)throw new Error("Incorrect length");return new oe(t,n,o,e)},Gr=(i,e)=>{if(i===e)return!0;{let t=e;return i.code===t.code&&i.size===t.size&&t.bytes instanceof Uint8Array&&Dt(i.bytes,t.bytes)}},oe=class{constructor(e,t,r,n){this.code=e,this.size=t,this.digest=r,this.bytes=n}};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?G(this.code,t):t.then(r=>G(this.code,r))}else throw Error("Unknown type, must be binary type")}};var Hr=i=>async e=>new Uint8Array(await crypto.subtle.digest(i,e)),gs=ft({name:"sha2-256",code:18,encode:Hr("SHA-256")}),Es=ft({name:"sha2-512",code:19,encode:Hr("SHA-512")});var mt={};A(mt,{identity:()=>Ss});var Qr=0,_s="identity",Yr=U,xs=i=>G(Qr,Yr(i)),Ss={code:Qr,name:_s,encode:Yr,digest:xs};var Ba=new TextEncoder,Da=new TextDecoder;var Xr=(i,e)=>{let{bytes:t,version:r}=i;switch(r){case 0:return Ls(t,pt(i),e||P.encoder);default:return Ts(t,pt(i),e||$.encoder)}};var Jr=new WeakMap,pt=i=>{let e=Jr.get(i);if(e==null){let t=new Map;return Jr.set(i,t),t}return e},_=class{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!==me)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Is)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return _.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 _.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 _.equals(this,e)}static equals(e,t){let r=t;return r&&e.code===r.code&&e.version===r.version&&Gr(e.multihash,r.multihash)}toString(e){return Xr(this,e)}toJSON(){return{"/":Xr(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 _)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:r,code:n,multihash:s,bytes:o}=t;return new _(r,n,s,o||Zr(r,n,s.bytes))}else if(t[Ms]===!0){let{version:r,multihash:n,code:s}=t,o=Wr(n);return _.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!==me)throw new Error(`Version 0 CID must use dag-pb (code: ${me}) block encoding`);return new _(e,t,r,r.bytes)}case 1:{let n=Zr(e,t,r.bytes);return new _(e,t,r,n)}default:throw new Error("Invalid version")}}static createV0(e){return _.create(0,me,e)}static createV1(e,t){return _.create(1,e,t)}static decode(e){let[t,r]=_.decodeFirst(e);if(r.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=_.inspectBytes(e),r=t.size-t.multihashSize,n=U(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?_.createV0(o):_.createV1(t.codec,o),e.subarray(t.size)]}static inspectBytes(e){let t=0,r=()=>{let[h,d]=fe(e.subarray(t));return t+=d,h},n=r(),s=me;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(),l=t+c,u=l-o;return{version:n,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(e,t){let[r,n]=As(e,t),s=_.decode(n);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return pt(s).set(r,e),s}},As=(i,e)=>{switch(i[0]){case"Q":{let t=e||P;return[P.prefix,t.decode(`${P.prefix}${i}`)]}case P.prefix:{let t=e||P;return[P.prefix,t.decode(i)]}case $.prefix:{let t=e||$;return[$.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)]}}},Ls=(i,e,t)=>{let{prefix:r}=t;if(r!==P.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},Ts=(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},me=112,Is=18,Zr=(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},Ms=Symbol.for("@ipld/js-cid/CID");var bt={...it,...nt,...st,...ot,...at,...Ue,...ct,...qe,...$e,...ut},Ga={...dt,...mt};function ti(i,e,t,r){return{name:i,prefix:e,encoder:{name:i,prefix:e,encode:t},decoder:{decode:r}}}var ei=ti("utf8","u",i=>"u"+new TextDecoder("utf8").decode(i),i=>new TextEncoder().encode(i.substring(1))),yt=ti("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=K(i.length);for(let t=0;t<i.length;t++)e[t]=i.charCodeAt(t);return e}),Ns={utf8:ei,"utf-8":ei,hex:bt.base16,latin1:yt,ascii:yt,binary:yt,...bt},Le=Ns;function wt(i,e="utf8"){let t=Le[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?V(globalThis.Buffer.from(i,"utf-8")):t.decoder.decode(`${t.prefix}${i}`)}function pe(i,e="utf8"){let t=Le[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 ii=Symbol.for("@achingbrain/uint8arraylist");function ri(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 Te(i){return!!i?.[ii]}var x=class{constructor(...e){Object.defineProperty(this,ii,{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(Te(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(Te(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=ri(this.bufs,e);return t.buf[t.index]}set(e,t){let r=ri(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(Te(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 Re(r,n)}subarray(e,t){let{bufs:r,length:n}=this._subList(e,t);return r.length===1?r[0]:Re(r,n)}sublist(e,t){let{bufs:r,length:n}=this._subList(e,t),s=new x;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 l=e>=a&&e<c,u=t>a&&t<=c;if(l&&u){if(e===a&&t===c){r.push(o);break}let h=e-a;r.push(o.subarray(h,h+(t-e)));break}if(l){if(e===0){r.push(o);continue}r.push(o.subarray(e-a));continue}if(u){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(!Te(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,l=r.byteLength-1,u;for(let h=t;h<=c;h+=u){u=0;for(let d=l;d>=0;d--){let w=this.get(h+d);if(r[d]!==w){u=Math.max(1,d-a[w]);break}}if(u===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=K(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=q(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=q(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=q(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=K(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=q(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=q(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=q(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=q(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=q(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat64(0,t,r),this.write(n,e)}equals(e){if(e==null||!(e instanceof x)||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 x;return r.bufs=e,t==null&&(t=e.reduce((n,s)=>n+s.byteLength,0)),r.length=t,r}};var p;(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"})(p||(p={}));var be=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:p.NEW_STREAM,MESSAGE:p.MESSAGE_INITIATOR,CLOSE:p.CLOSE_INITIATOR,RESET:p.RESET_INITIATOR}),ni=Object.freeze({MESSAGE:p.MESSAGE_RECEIVER,CLOSE:p.CLOSE_RECEIVER,RESET:p.RESET_RECEIVER});var Et=1<<20,ks=4<<20,Ie=class{_buffer;_headerInfo;_maxMessageSize;_maxUnprocessedMessageQueueSize;constructor(e=Et,t=ks){this._buffer=new x,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(l){if(l.code==="ERR_MSG_TOO_BIG")throw l;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===p.NEW_STREAM||n===p.MESSAGE_INITIATOR||n===p.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}=oi(e),{value:n,offset:s}=oi(e,r),o=t&7;if(be[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}}},vs=128,si=127;function oi(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&si)<<r:(s&si)*Math.pow(2,r),r+=7}while(s>=vs);return e=n-e,{value:t,offset:e}}function Me(){let i={};return i.promise=new Promise((e,t)=>{i.resolve=e,i.reject=t}),i}function Ps(i){return i[Symbol.asyncIterator]!=null}var Ne=1024*1024,ai=(i,e)=>{e.append(i)};function Bs(i,e){return Ps(i)?async function*(){let t=new x,r=!1,n=Me(),s=Number(e?.size??Ne);if((isNaN(s)||s===0||s<0)&&(s=Ne),s!==Math.round(s))throw new Error("Batch size must be an integer");let o=e?.yieldAfter??0,a=e?.serialize??ai;for(Promise.resolve().then(async()=>{try{let c;for await(let l of i){if(a(l,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=Me(),t.byteLength>0){let c=t;t=new x,yield c.subarray()}}():function*(){let t=new x,r=Number(e?.size??Ne);if((isNaN(r)||r===0||r<0)&&(r=Ne),r!==Math.round(r))throw new Error("Batch size must be an integer");let n=e?.serialize??ai;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 ci=Bs;var ae=Pe(wi(),1);function St(i){return new Uint8Array(i)}var Ct=10*1024,Rt=class{_pool;_poolOffset;constructor(){this._pool=St(Ct),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===p.NEW_STREAM||e.type===p.MESSAGE_INITIATOR||e.type===p.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);Ct-n<100?(this._pool=St(Ct),this._poolOffset=0):this._poolOffset=n,t.append(s),(e.type===p.NEW_STREAM||e.type===p.MESSAGE_INITIATOR||e.type===p.MESSAGE_RECEIVER)&&e.data!=null&&t.append(e.data)}},gi=new Rt;async function*Ei(i,e=0){if(e==null||e===0){for await(let t of i){let r=new x;for(let n of t)gi.write(n,r);yield r.subarray()}return}yield*ci(i,{size:e,serialize:(t,r)=>{for(let n of t)gi.write(n,r)}})}var M=Ee("libp2p:stream"),At="ERR_STREAM_RESET",Qs="ERR_STREAM_ABORT",Ys="ERR_SINK_ENDED",Xs="ERR_DOUBLE_SINK";function j(i){return i!=null&&typeof i.then=="function"}var ke=class{id;stat;metadata;source;abortController;resetController;closeController;sourceEnded;sinkEnded;sinkSunk;endErr;streamSource;onEnd;maxDataSize;constructor(e){this.abortController=new AbortController,this.resetController=new AbortController,this.closeController=new AbortController,this.sourceEnded=!1,this.sinkEnded=!1,this.sinkSunk=!1,this.id=e.id,this.metadata=e.metadata??{},this.stat={direction:e.direction,timeline:{open:Date.now()}},this.maxDataSize=e.maxDataSize,this.onEnd=e.onEnd,this.source=this.streamSource=$t({onEnd:()=>{if(this.stat.timeline.reset!==null){let t=this.sendCloseRead();j(t)&&t.catch(r=>{M.error("error while sending close read",r)})}this.onSourceEnd()}}),this.sink=this.sink.bind(this)}onSourceEnd(e){this.sourceEnded||(this.stat.timeline.closeRead=Date.now(),this.sourceEnded=!0,M.trace("%s stream %s source end - err: %o",this.stat.direction,this.id,e),e!=null&&this.endErr==null&&(this.endErr=e),this.sinkEnded&&(this.stat.timeline.close=Date.now(),this.onEnd!=null&&this.onEnd(this.endErr)))}onSinkEnd(e){this.sinkEnded||(this.stat.timeline.closeWrite=Date.now(),this.sinkEnded=!0,M.trace("%s stream %s sink end - err: %o",this.stat.direction,this.id,e),e!=null&&this.endErr==null&&(this.endErr=e),this.sourceEnded&&(this.stat.timeline.close=Date.now(),this.onEnd!=null&&this.onEnd(this.endErr)))}close(){M.trace("%s stream %s close",this.stat.direction,this.id),this.closeRead(),this.closeWrite()}closeRead(){M.trace("%s stream %s closeRead",this.stat.direction,this.id),!this.sourceEnded&&this.streamSource.end()}closeWrite(){if(M.trace("%s stream %s closeWrite",this.stat.direction,this.id),!this.sinkEnded){this.closeController.abort();try{let e=this.sendCloseWrite();j(e)&&e.catch(t=>{M.error("error while sending close write",t)})}catch(e){M.trace("%s stream %s error sending close",this.stat.direction,this.id,e)}this.onSinkEnd()}}abort(e){M.trace("%s stream %s abort",this.stat.direction,this.id,e),this.streamSource.end(e),this.abortController.abort(),this.onSinkEnd(e)}reset(){let e=new F("stream reset",At);this.resetController.abort(),this.streamSource.end(e),this.onSinkEnd(e)}async sink(e){if(this.sinkSunk)throw new F("sink already called on stream",Xs);if(this.sinkSunk=!0,this.sinkEnded)throw new F("stream closed for writing",Ys);let t=xe([this.abortController.signal,this.resetController.signal,this.closeController.signal]);try{if(e=_e(e,t),this.stat.direction==="outbound"){let r=this.sendNewStream();j(r)&&await r}for await(let r of e)for(;r.length>0;){if(r.length<=this.maxDataSize){let s=this.sendData(r instanceof Uint8Array?new x(r):r);j(s)&&await s;break}r=r instanceof Uint8Array?new x(r):r;let n=this.sendData(r.sublist(0,this.maxDataSize));j(n)&&await n,r.consume(this.maxDataSize)}}catch(r){if(r.type==="aborted"&&r.message==="The operation was aborted"){if(this.closeController.signal.aborted)return;this.resetController.signal.aborted&&(r.message="stream reset",r.code=At),this.abortController.signal.aborted&&(r.message="stream aborted",r.code=Qs)}if(r.code===At)M.trace("%s stream %s reset",this.stat.direction,this.id);else{M.trace("%s stream %s error",this.stat.direction,this.id,r);try{let n=this.sendReset();j(n)&&await n,this.stat.timeline.reset=Date.now()}catch(n){M.trace("%s stream %s error sending reset",this.stat.direction,this.id,n)}}throw this.streamSource.end(r),this.onSinkEnd(r),r}finally{t.clear()}try{let r=this.sendCloseWrite();j(r)&&await r}catch(r){M.trace("%s stream %s error sending close",this.stat.direction,this.id,r)}this.onSinkEnd()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};var Lt=class extends ke{name;streamId;send;types;constructor(e){super(e),this.types=e.direction==="outbound"?gt:ni,this.send=e.send,this.name=e.name,this.streamId=e.streamId}sendNewStream(){this.send({id:this.streamId,type:gt.NEW_STREAM,data:new x(wt(this.name))})}sendData(e){this.send({id:this.streamId,type:this.types.MESSAGE,data:e})}sendReset(){this.send({id:this.streamId,type:this.types.RESET})}sendCloseWrite(){this.send({id:this.streamId,type:this.types.CLOSE})}sendCloseRead(){}};function _i(i){let{id:e,name:t,send:r,onEnd:n,type:s="initiator",maxMsgSize:o=Et}=i;return new Lt({id:s==="initiator"?`i${e}`:`r${e}`,streamId:e,name:`${t??e}`,direction:s==="initiator"?"outbound":"inbound",maxDataSize:o,onEnd:n,send:r})}var O=Ee("libp2p:mplex"),Js=1024,Zs=1024,eo=1024*1024*4,to=5;function xi(i){let e={...i,type:`${be[i.type]} (${i.type})`};return i.type===p.NEW_STREAM&&(e.data=pe(i.data instanceof Uint8Array?i.data:i.data.subarray())),(i.type===p.MESSAGE_INITIATOR||i.type===p.MESSAGE_RECEIVER)&&(e.data=pe(i.data instanceof Uint8Array?i.data:i.data.subarray(),"base16")),e}var ve=class{protocol="/mplex/6.7.0";sink;source;_streamId;_streams;_init;_source;closeController;rateLimiter;constructor(e){e=e??{},this._streamId=0,this._streams={initiators:new Map,receivers:new Map},this._init=e,this.sink=this._createSink();let t=this._createSource();this._source=t,this.source=t,this.closeController=new AbortController,this.rateLimiter=new Si.RateLimiterMemory({points:e.disconnectThreshold??to,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})}close(e){this.closeController.signal.aborted||(e!=null?this.streams.forEach(t=>{t.abort(e)}):this.streams.forEach(t=>{t.close()}),this.closeController.abort())}_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(O("new %s stream %s",n,t),n==="initiator"&&this._streams.initiators.size===(this._init.maxOutboundStreams??Zs))throw new F("Too many outbound streams open","ERR_TOO_MANY_OUTBOUND_STREAMS");if(s.has(t))throw new Error(`${n} stream ${t} already exists!`);let c=_i({id:t,name:r,send:l=>{O.enabled&&O.trace("%s stream %s send",n,t,xi(l)),this._source.push(l)},type:n,onEnd:()=>{O("%s stream with id %s and protocol %s ended",n,t,c.stat.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=>{let r=xe([this.closeController.signal,this._init.signal]);try{t=_e(t,r);let n=new Ie(this._init.maxMsgSize,this._init.maxUnprocessedMessageQueueSize);for await(let s of t)for(let o of n.write(s))await this._handleIncoming(o);this._source.end()}catch(n){O("error in sink",n),this._source.end(n)}finally{r.clear()}}}_createSource(){let t=Vt({objectMode:!0,onEnd:r=>{this.close(r)}});return Object.assign(Ei(t,this._init.minSendBytes),{push:t.push,end:t.end,return:t.return})}async _handleIncoming(e){let{id:t,type:r}=e;if(O.enabled&&O.trace("incoming message",xi(e)),e.type===p.NEW_STREAM){if(this._streams.receivers.size===(this._init.maxInboundStreams??Js)){O("too many inbound streams open"),this._source.push({id:t,type:p.RESET_RECEIVER});try{await this.rateLimiter.consume("new-stream",1)}catch{O("rate limit hit when opening too many new streams over the inbound stream limit - closing remote connection"),this._source.end(new Error("Too many open streams"));return}return}let a=this._newReceiverStream({id:t,name:pe(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){O("missing stream %s for message type %s",t,be[r]);return}let o=this._init.maxStreamBufferSize??eo;switch(r){case p.MESSAGE_INITIATOR:case p.MESSAGE_RECEIVER:if(s.sourceReadableLength()>o){this._source.push({id:e.id,type:r===p.MESSAGE_INITIATOR?p.RESET_RECEIVER:p.RESET_INITIATOR});let a=new F("Input buffer full - increase Mplex maxBufferSize to accommodate slow consumers","ERR_STREAM_INPUT_BUFFER_FULL");s.abort(a);return}s.sourcePush(e.data);break;case p.CLOSE_INITIATOR:case p.CLOSE_RECEIVER:s.closeRead();break;case p.RESET_INITIATOR:case p.RESET_RECEIVER:s.reset();break;default:O("unknown message type %s",r)}}};var Tt=class{protocol="/mplex/6.7.0";_init;constructor(e={}){this._init=e}createStreamMuxer(e={}){return new ve({...e,...this._init})}};function ro(i={}){return()=>new Tt(i)}return Ii(io);})();
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"))}};dr.exports=Ve});var pr=g(()=>{});var br=g(()=>{});var wr=g((Na,yr)=>{yr.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 xr=g((va,gr)=>{var yn=wr(),Ke=B();gr.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 yn(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 Ge=g((ka,_r)=>{var wn=le(),gn=xr(),Er=B(),We=class extends wn{constructor(e={}){super(e),this._memoryStorage=new gn}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 Er(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 Er(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)))}};_r.exports=We});var Ir=g((Pa,Tr)=>{var Sr=pr(),xn=br(),En=le(),Ar=Ge(),_n=B(),D="rate_limiter_flexible",re=null,Cr=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})},Rr=function(i){setTimeout(()=>{this._initiated?process.send(i):typeof this._promises[i.promiseId]<"u"&&Rr.call(this,i)},30)},ee=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):Rr.call(this,s)},Lr=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=>{Cr(i,e,"resolve",r)}).catch(r=>{Cr(i,e,"reject",r)})},Sn=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 _n(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]}},Cn=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+=xn.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},je=class{constructor(){if(re)return re;this._rateLimiters={},Sr.setMaxListeners(0),Sr.on("message",(e,t)=>{t&&t.channel===D&&t.type==="init"?(typeof this._rateLimiters[t.opts.keyPrefix]>"u"&&(this._rateLimiters[t.opts.keyPrefix]=new Ar(t.opts)),e.send({channel:D,type:"init",keyPrefix:t.opts.keyPrefix})):Lr.call(this,e,t)}),re=this}},He=class{constructor(e){if(re)return re;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 Ar(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,h)=>{u&&console.log(u,h)})}};Lr.call(this,o,s)}})}),re=this}},Qe=class extends En{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:Sn.call(this,t)}),process.send({channel:D,type:"init",opts:Cn.call(this)}),this._promises={}}consume(e,t=1,r={}){return new Promise((n,s)=>{let o=te.call(this,n,s);ee.call(this,"consume",o,e,t,r)})}penalty(e,t=1,r={}){return new Promise((n,s)=>{let o=te.call(this,n,s);ee.call(this,"penalty",o,e,t,r)})}reward(e,t=1,r={}){return new Promise((n,s)=>{let o=te.call(this,n,s);ee.call(this,"reward",o,e,t,r)})}block(e,t,r={}){return new Promise((n,s)=>{let o=te.call(this,n,s);ee.call(this,"block",o,e,t,r)})}get(e,t={}){return new Promise((r,n)=>{let s=te.call(this,r,n);ee.call(this,"get",s,e,t)})}delete(e,t={}){return new Promise((r,n)=>{let s=te.call(this,r,n);ee.call(this,"delete",s,e,t)})}};Tr.exports={RateLimiterClusterMaster:je,RateLimiterClusterMasterPM2:He,RateLimiterCluster:Qe}});var Mr=g((Ba,Nr)=>{var An=Z(),Rn=B(),Xe=class extends An{constructor(e){super(e),this.client=e.storeClient}_getRateLimiterRes(e,t,r){let n=new Rn;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,h=>{h?a(h):this.client.set(`${e}_expire`,u>0?c+u*1e3:-1,u,()=>{let l={consumedPoints:t,msBeforeNext:u>0?u*1e3:-1};o(l)})}):this.client.incr(e,t,(h,l)=>{h||l===!1?this.client.add(e,t,u,(m,E)=>{if(m||!E)if(typeof s.attemptNumber>"u"||s.attemptNumber<3){let d=Object.assign({},s);d.attemptNumber=d.attemptNumber?d.attemptNumber+1:1,this._upsert(e,t,r,n,d).then(f=>o(f)).catch(f=>a(f))}else a(new Error("Can not add key"));else this.client.add(`${e}_expire`,u>0?c+u*1e3:-1,u,()=>{let d={consumedPoints:t,msBeforeNext:u>0?u*1e3:-1};o(d)})}):this.client.get(`${e}_expire`,(m,E)=>{if(m)a(m);else{let d=E===!1?0:E,f={consumedPoints:l,msBeforeNext:d>=0?Math.max(d-c,0):-1};o(f)}})})})}_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,h={consumedPoints:o,msBeforeNext:u>=0?Math.max(u-n,0):-1};t(h)}}):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)})})})}};Nr.exports=Xe});var Pr=g((Oa,kr)=>{var vr=B();kr.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 vr(0,Number.MAX_SAFE_INTEGER,0,!1)}getWhiteRes(){return new vr(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 Dr=g((Ua,Br)=>{var Ln=le();Br.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 Ln))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 Fr=g((za,Or)=>{Or.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 $r=g((Va,zr)=>{var Ur=Fr(),qr=4294967295,Ye="limiter";zr.exports=class{constructor(e,t={maxQueueSize:qr}){this._queueLimiters={KEY_DEFAULT:new Ce(e,t)},this._limiterFlexible=e,this._maxQueueSize=t.maxQueueSize}getTokensRemaining(e=Ye){return this._queueLimiters[e]?this._queueLimiters[e].getTokensRemaining():Promise.resolve(this._limiterFlexible.points)}removeTokens(e,t=Ye){return this._queueLimiters[t]||(this._queueLimiters[t]=new Ce(this._limiterFlexible,{key:t,maxQueueSize:this._maxQueueSize})),this._queueLimiters[t].removeTokens(e)}};var Ce=class{constructor(e,t={maxQueueSize:qr,key:Ye}){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 Ur(`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 Ur(`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 Kr=g((Wa,Vr)=>{var Je=B();Vr.exports=class{constructor(e,t){this._rateLimiter=e,this._burstLimiter=t}_combineRes(e,t){return new Je(e.remainingPoints,Math.min(e.msBeforeNext,t.msBeforeNext),e.consumedPoints,e.isFirstInDuration)}consume(e,t=1,r={}){return this._rateLimiter.consume(e,t,r).catch(n=>n instanceof Je?this._burstLimiter.consume(e,t,r).then(s=>Promise.resolve(this._combineRes(n,s))).catch(s=>s instanceof Je?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 Gr=g((Ga,Wr)=>{var Tn=ar(),In=lr(),Nn=fr(),Mn=mr(),{RateLimiterClusterMaster:vn,RateLimiterClusterMasterPM2:kn,RateLimiterCluster:Pn}=Ir(),Bn=Ge(),Dn=Mr(),On=Pr(),Fn=Dr(),Un=$r(),qn=Kr(),zn=B();Wr.exports={RateLimiterRedis:Tn,RateLimiterMongo:In,RateLimiterMySQL:Nn,RateLimiterPostgres:Mn,RateLimiterMemory:Bn,RateLimiterMemcache:Dn,RateLimiterClusterMaster:vn,RateLimiterClusterMasterPM2:kn,RateLimiterCluster:Pn,RLWrapperBlackAndWhite:On,RateLimiterUnion:Fn,RateLimiterQueue:Un,BurstyRateLimiter:qn,RateLimiterRes:zn}});var Si=g((mh,_i)=>{_i.exports=At;var Ei=128,eo=127,to=~eo,ro=Math.pow(2,31);function At(i,e,t){if(Number.MAX_SAFE_INTEGER&&i>Number.MAX_SAFE_INTEGER)throw At.bytes=0,new RangeError("Could not encode varint");e=e||[],t=t||0;for(var r=t;i>=ro;)e[t++]=i&255|Ei,i/=128;for(;i&to;)e[t++]=i&255|Ei,i>>>=7;return e[t]=i|0,At.bytes=t-r+1,e}});var Ri=g((ph,Ai)=>{Ai.exports=Rt;var io=128,Ci=127;function Rt(i,r){var t=0,r=r||0,n=0,s=r,o,a=i.length;do{if(s>=a||n>49)throw Rt.bytes=0,new RangeError("Could not decode varint");o=i[s++],t+=n<28?(o&Ci)<<n:(o&Ci)*Math.pow(2,n),n+=7}while(o>=io);return Rt.bytes=s-r,t}});var Ti=g((bh,Li)=>{var no=Math.pow(2,7),so=Math.pow(2,14),oo=Math.pow(2,21),ao=Math.pow(2,28),co=Math.pow(2,35),ho=Math.pow(2,42),lo=Math.pow(2,49),uo=Math.pow(2,56),fo=Math.pow(2,63);Li.exports=function(i){return i<no?1:i<so?2:i<oo?3:i<ao?4:i<co?5:i<ho?6:i<lo?7:i<uo?8:i<fo?9:10}});var Ni=g((yh,Ii)=>{Ii.exports={encode:Si(),decode:Ri(),encodingLength:Ti()}});var _o={};v(_o,{mplex:()=>Eo});var q=class extends Error{code;props;constructor(e,t,r){super(e),this.code=t,this.name=r?.name??"CodeError",this.props=r??{}}};var P=Pe(Ft(),1);function en(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),h=Math.log(256)/Math.log(a);function l(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var f=0,p=0,y=0,x=d.length;y!==x&&d[y]===0;)y++,f++;for(var S=(x-y)*h+1>>>0,w=new Uint8Array(S);y!==x;){for(var C=d[y],L=0,_=S-1;(C!==0||L<p)&&_!==-1;_--,L++)C+=256*w[_]>>>0,w[_]=C%a>>>0,C=C/a>>>0;if(C!==0)throw new Error("Non-zero carry");p=L,y++}for(var A=S-p;A!==S&&w[A]===0;)A++;for(var O=c.repeat(f);A<S;++A)O+=i.charAt(w[A]);return O}function m(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var f=0;if(d[f]!==" "){for(var p=0,y=0;d[f]===c;)p++,f++;for(var x=(d.length-f)*u+1>>>0,S=new Uint8Array(x);d[f];){var w=t[d.charCodeAt(f)];if(w===255)return;for(var C=0,L=x-1;(w!==0||C<y)&&L!==-1;L--,C++)w+=a*S[L]>>>0,S[L]=w%256>>>0,w=w/256>>>0;if(w!==0)throw new Error("Non-zero carry");y=C,f++}if(d[f]!==" "){for(var _=x-y;_!==x&&S[_]===0;)_++;for(var A=new Uint8Array(p+(x-_)),O=p;_!==x;)A[O++]=S[_++];return A}}}function E(d){var f=m(d);if(f)return f;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:m,decode:E}}var tn=en,rn=tn,Ut=rn;var No=new Uint8Array(0);var qt=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 Be=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")}},De=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 zt(this,e)}},Oe=class{constructor(e){this.decoders=e}or(e){return zt(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`)}},zt=(i,e)=>new Oe({...i.decoders||{[i.prefix]:i},...e.decoders||{[e.prefix]:e}}),Fe=class{constructor(e,t,r,n){this.name=e,this.prefix=t,this.baseEncode=r,this.baseDecode=n,this.encoder=new Be(e,t,r),this.decoder=new De(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},$t=({name:i,prefix:e,encode:t,decode:r})=>new Fe(i,e,t,r),Ue=({prefix:i,name:e,alphabet:t})=>{let{encode:r,decode:n}=Ut(t,e);return $t({prefix:i,name:e,encode:r,decode:s=>qt(n(s))})},nn=(i,e,t,r)=>{let n={};for(let h=0;h<e.length;++h)n[e[h]]=h;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 h=0;h<s;++h){let l=n[i[h]];if(l===void 0)throw new SyntaxError(`Non-${r} character`);c=c<<t|l,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},sn=(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},N=({name:i,prefix:e,bitsPerChar:t,alphabet:r})=>$t({prefix:e,name:i,encode(n){return sn(n,r,t)},decode(n){return nn(n,r,t,i)}});var Vt=N({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Do=N({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Oo=N({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Fo=N({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Uo=N({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),qo=N({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),zo=N({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),$o=N({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Vo=N({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Kt=Ue({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Go=Ue({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Wt=N({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Qo=N({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xo=N({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yo=N({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});P.default.formatters.b=i=>i==null?"undefined":Kt.baseEncode(i);P.default.formatters.t=i=>i==null?"undefined":Vt.baseEncode(i);P.default.formatters.m=i=>i==null?"undefined":Wt.baseEncode(i);P.default.formatters.p=i=>i==null?"undefined":i.toString();P.default.formatters.c=i=>i==null?"undefined":i.toString();P.default.formatters.k=i=>i==null?"undefined":i.toString();P.default.formatters.a=i=>i==null?"undefined":i.toString();function on(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 Gt(i){let e=on(`${i}:trace`);return P.default.enabled(`${i}:trace`)&&P.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,P.default)(`${i}:trace`)),Object.assign((0,P.default)(i),{error:(0,P.default)(`${i}:error`),trace:e})}var he=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 Ee(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:h,abortCode:l}=r;throw new he(h,l)}let u=new Promise((h,l)=>{o=()=>{let{abortMessage:m,abortCode:E}=r;l(new he(m,E))}});c=await Promise.race([u,n.next()]),o=null}catch(u){e.removeEventListener("abort",a);let h=u.type==="aborted"&&e.aborted;if(h&&r.onAbort!=null&&r.onAbort(i),typeof n.return=="function")try{let l=n.return();l instanceof Promise&&l.catch(m=>{r.onReturnError!=null&&r.onReturnError(m)})}catch(l){r.onReturnError!=null&&r.onReturnError(l)}if(h&&r.returnOnAbort===!0)return;throw u}if(c.done===!0)break;yield c.value}e.removeEventListener("abort",a)}return s()}function _e(i){let e=new globalThis.AbortController;function t(){e.abort();for(let s of i)s?.removeEventListener!=null&&s.removeEventListener("abort",t)}for(let s of i){if(s?.aborted===!0){t();break}s?.addEventListener!=null&&s.addEventListener("abort",t)}function r(){for(let s of i)s?.removeEventListener!=null&&s.removeEventListener("abort",t)}let n=e.signal;return n.clear=r,n}var Se=class{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}},J=class{constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Se(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 Se(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()}};function Ht(i={}){return Xt(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 Qt(i={}){return Xt(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 Xt(i,e){e=e??{};let t=e.onEnd,r=new J,n,s,o,a=async()=>r.isEmpty()?o?{done:!0}:await new Promise((f,p)=>{s=y=>{s=null,r.push(y);try{f(i(r))}catch(x){p(x)}return n}}):i(r),c=f=>s!=null?s(f):(r.push(f),n),u=f=>(r=new J,s!=null?s({error:f}):(r.push({error:f}),n)),h=f=>{if(o)return n;if(e?.objectMode!==!0&&f?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return c({done:!1,value:f})},l=f=>o?n:(o=!0,f!=null?u(f):c({done:!0})),m=()=>(r=new J,l(),{done:!0}),E=f=>(l(f),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:a,return:m,throw:E,push:h,end:l,get readableLength(){return r.size}},t==null)return n;let d=n;return n={[Symbol.asyncIterator](){return this},next(){return d.next()},throw(f){return d.throw(f),t!=null&&(t(f),t=void 0),{done:!0}},return(){return d.return(),t!=null&&(t(),t=void 0),{done:!0}},push:h,end(f){return d.end(f),t!=null&&(t(f),t=void 0),n},get readableLength(){return d.readableLength}},n}var Bi=Pe(Gr(),1);function V(i){return globalThis.Buffer!=null?new Uint8Array(i.buffer,i.byteOffset,i.byteLength):i}function z(i=0){return globalThis.Buffer?.alloc!=null?V(globalThis.Buffer.alloc(i)):new Uint8Array(i)}function K(i=0){return globalThis.Buffer?.allocUnsafe!=null?V(globalThis.Buffer.allocUnsafe(i)):new Uint8Array(i)}function Ae(i,e){e==null&&(e=i.reduce((n,s)=>n+s.length,0));let t=K(e),r=0;for(let n of i)t.set(n,r),r+=n.length;return V(t)}function Ze(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 nt={};v(nt,{identity:()=>jn});function $n(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),h=Math.log(256)/Math.log(a);function l(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var f=0,p=0,y=0,x=d.length;y!==x&&d[y]===0;)y++,f++;for(var S=(x-y)*h+1>>>0,w=new Uint8Array(S);y!==x;){for(var C=d[y],L=0,_=S-1;(C!==0||L<p)&&_!==-1;_--,L++)C+=256*w[_]>>>0,w[_]=C%a>>>0,C=C/a>>>0;if(C!==0)throw new Error("Non-zero carry");p=L,y++}for(var A=S-p;A!==S&&w[A]===0;)A++;for(var O=c.repeat(f);A<S;++A)O+=i.charAt(w[A]);return O}function m(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var f=0;if(d[f]!==" "){for(var p=0,y=0;d[f]===c;)p++,f++;for(var x=(d.length-f)*u+1>>>0,S=new Uint8Array(x);d[f];){var w=t[d.charCodeAt(f)];if(w===255)return;for(var C=0,L=x-1;(w!==0||C<y)&&L!==-1;L--,C++)w+=a*S[L]>>>0,S[L]=w%256>>>0,w=w/256>>>0;if(w!==0)throw new Error("Non-zero carry");y=C,f++}if(d[f]!==" "){for(var _=x-y;_!==x&&S[_]===0;)_++;for(var A=new Uint8Array(p+(x-_)),O=p;_!==x;)A[O++]=S[_++];return A}}}function E(d){var f=m(d);if(f)return f;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:m,decode:E}}var Vn=$n,Kn=Vn,jr=Kn;var rc=new Uint8Array(0);var Hr=(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},$=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 Qr=i=>new TextEncoder().encode(i),Xr=i=>new TextDecoder().decode(i);var et=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")}},tt=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 Jr(this,e)}},rt=class{constructor(e){this.decoders=e}or(e){return Jr(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`)}},Jr=(i,e)=>new rt({...i.decoders||{[i.prefix]:i},...e.decoders||{[e.prefix]:e}}),it=class{constructor(e,t,r,n){this.name=e,this.prefix=t,this.baseEncode=r,this.baseDecode=n,this.encoder=new et(e,t,r),this.decoder=new tt(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},ie=({name:i,prefix:e,encode:t,decode:r})=>new it(i,e,t,r),W=({prefix:i,name:e,alphabet:t})=>{let{encode:r,decode:n}=jr(t,e);return ie({prefix:i,name:e,encode:r,decode:s=>$(n(s))})},Wn=(i,e,t,r)=>{let n={};for(let h=0;h<e.length;++h)n[e[h]]=h;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 h=0;h<s;++h){let l=n[i[h]];if(l===void 0)throw new SyntaxError(`Non-${r} character`);c=c<<t|l,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},Gn=(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})=>ie({prefix:e,name:i,encode(n){return Gn(n,r,t)},decode(n){return Wn(n,r,t,i)}});var jn=ie({prefix:"\0",name:"identity",encode:i=>Xr(i),decode:i=>Qr(i)});var st={};v(st,{base2:()=>Hn});var Hn=R({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ot={};v(ot,{base8:()=>Qn});var Qn=R({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var at={};v(at,{base10:()=>Xn});var Xn=W({prefix:"9",name:"base10",alphabet:"0123456789"});var ct={};v(ct,{base16:()=>Yn,base16upper:()=>Jn});var Yn=R({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Jn=R({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ht={};v(ht,{base32:()=>ne,base32hex:()=>rs,base32hexpad:()=>ns,base32hexpadupper:()=>ss,base32hexupper:()=>is,base32pad:()=>es,base32padupper:()=>ts,base32upper:()=>Zn,base32z:()=>os});var ne=R({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Zn=R({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),es=R({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ts=R({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),rs=R({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),is=R({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ns=R({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ss=R({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),os=R({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var lt={};v(lt,{base36:()=>as,base36upper:()=>cs});var as=W({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),cs=W({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ut={};v(ut,{base58btc:()=>U,base58flickr:()=>hs});var U=W({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),hs=W({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ft={};v(ft,{base64:()=>ls,base64pad:()=>us,base64url:()=>fs,base64urlpad:()=>ds});var ls=R({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),us=R({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),fs=R({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ds=R({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var dt={};v(dt,{base256emoji:()=>ws});var Zr=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}"),ms=Zr.reduce((i,e,t)=>(i[t]=e,i),[]),ps=Zr.reduce((i,e,t)=>(i[e.codePointAt(0)]=t,i),[]);function bs(i){return i.reduce((e,t)=>(e+=ms[t],e),"")}function ys(i){let e=[];for(let t of i){let r=ps[t.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(r)}return new Uint8Array(e)}var ws=ie({prefix:"\u{1F680}",name:"base256emoji",encode:bs,decode:ys});var yt={};v(yt,{sha256:()=>Os,sha512:()=>Fs});var gs=ri,ei=128,xs=127,Es=~xs,_s=Math.pow(2,31);function ri(i,e,t){e=e||[],t=t||0;for(var r=t;i>=_s;)e[t++]=i&255|ei,i/=128;for(;i&Es;)e[t++]=i&255|ei,i>>>=7;return e[t]=i|0,ri.bytes=t-r+1,e}var Ss=mt,Cs=128,ti=127;function mt(i,r){var t=0,r=r||0,n=0,s=r,o,a=i.length;do{if(s>=a)throw mt.bytes=0,new RangeError("Could not decode varint");o=i[s++],t+=n<28?(o&ti)<<n:(o&ti)*Math.pow(2,n),n+=7}while(o>=Cs);return mt.bytes=s-r,t}var As=Math.pow(2,7),Rs=Math.pow(2,14),Ls=Math.pow(2,21),Ts=Math.pow(2,28),Is=Math.pow(2,35),Ns=Math.pow(2,42),Ms=Math.pow(2,49),vs=Math.pow(2,56),ks=Math.pow(2,63),Ps=function(i){return i<As?1:i<Rs?2:i<Ls?3:i<Ts?4:i<Is?5:i<Ns?6:i<Ms?7:i<vs?8:i<ks?9:10},Bs={encode:gs,decode:Ss,encodingLength:Ps},Ds=Bs,fe=Ds;var de=(i,e=0)=>[fe.decode(i,e),fe.decode.bytes],se=(i,e,t=0)=>(fe.encode(i,e,t),e),oe=i=>fe.encodingLength(i);var j=(i,e)=>{let t=e.byteLength,r=oe(i),n=r+oe(t),s=new Uint8Array(n+t);return se(i,s,0),se(t,s,r),s.set(e,n),new ae(i,t,e,s)},ii=i=>{let e=$(i),[t,r]=de(e),[n,s]=de(e.subarray(r)),o=e.subarray(r+s);if(o.byteLength!==n)throw new Error("Incorrect length");return new ae(t,n,o,e)},ni=(i,e)=>{if(i===e)return!0;{let t=e;return i.code===t.code&&i.size===t.size&&t.bytes instanceof Uint8Array&&Hr(i.bytes,t.bytes)}},ae=class{constructor(e,t,r,n){this.code=e,this.size=t,this.digest=r,this.bytes=n}};var bt=({name:i,code:e,encode:t})=>new pt(i,e,t),pt=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?j(this.code,t):t.then(r=>j(this.code,r))}else throw Error("Unknown type, must be binary type")}};var oi=i=>async e=>new Uint8Array(await crypto.subtle.digest(i,e)),Os=bt({name:"sha2-256",code:18,encode:oi("SHA-256")}),Fs=bt({name:"sha2-512",code:19,encode:oi("SHA-512")});var wt={};v(wt,{identity:()=>zs});var ai=0,Us="identity",ci=$,qs=i=>j(ai,ci(i)),zs={code:ai,name:Us,encode:ci,digest:qs};var Sc=new TextEncoder,Cc=new TextDecoder;var hi=(i,e)=>{let{bytes:t,version:r}=i;switch(r){case 0:return Ws(t,gt(i),e||U.encoder);default:return Gs(t,gt(i),e||ne.encoder)}};var li=new WeakMap,gt=i=>{let e=li.get(i);if(e==null){let t=new Map;return li.set(i,t),t}return e},T=class{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!==pe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==js)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return T.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=j(e,t);return T.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 T.equals(this,e)}static equals(e,t){let r=t;return r&&e.code===r.code&&e.version===r.version&&ni(e.multihash,r.multihash)}toString(e){return hi(this,e)}toJSON(){return{"/":hi(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 T)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:r,code:n,multihash:s,bytes:o}=t;return new T(r,n,s,o||ui(r,n,s.bytes))}else if(t[Hs]===!0){let{version:r,multihash:n,code:s}=t,o=ii(n);return T.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!==pe)throw new Error(`Version 0 CID must use dag-pb (code: ${pe}) block encoding`);return new T(e,t,r,r.bytes)}case 1:{let n=ui(e,t,r.bytes);return new T(e,t,r,n)}default:throw new Error("Invalid version")}}static createV0(e){return T.create(0,pe,e)}static createV1(e,t){return T.create(1,e,t)}static decode(e){let[t,r]=T.decodeFirst(e);if(r.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=T.inspectBytes(e),r=t.size-t.multihashSize,n=$(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 ae(t.multihashCode,t.digestSize,s,n);return[t.version===0?T.createV0(o):T.createV1(t.codec,o),e.subarray(t.size)]}static inspectBytes(e){let t=0,r=()=>{let[l,m]=de(e.subarray(t));return t+=m,l},n=r(),s=pe;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,h=u-o;return{version:n,codec:s,multihashCode:a,digestSize:c,multihashSize:h,size:u}}static parse(e,t){let[r,n]=Ks(e,t),s=T.decode(n);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return gt(s).set(r,e),s}},Ks=(i,e)=>{switch(i[0]){case"Q":{let t=e||U;return[U.prefix,t.decode(`${U.prefix}${i}`)]}case U.prefix:{let t=e||U;return[U.prefix,t.decode(i)]}case ne.prefix:{let t=e||ne;return[ne.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)]}}},Ws=(i,e,t)=>{let{prefix:r}=t;if(r!==U.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},Gs=(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},pe=112,js=18,ui=(i,e,t)=>{let r=oe(i),n=r+oe(e),s=new Uint8Array(n+t.byteLength);return se(i,s,0),se(e,s,r),s.set(t,n),s},Hs=Symbol.for("@ipld/js-cid/CID");var xt={...nt,...st,...ot,...at,...ct,...ht,...lt,...ut,...ft,...dt},Pc={...yt,...wt};function di(i,e,t,r){return{name:i,prefix:e,encoder:{name:i,prefix:e,encode:t},decoder:{decode:r}}}var fi=di("utf8","u",i=>"u"+new TextDecoder("utf8").decode(i),i=>new TextEncoder().encode(i.substring(1))),Et=di("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=K(i.length);for(let t=0;t<i.length;t++)e[t]=i.charCodeAt(t);return e}),Qs={utf8:fi,"utf-8":fi,hex:xt.base16,latin1:Et,ascii:Et,binary:Et,...xt},Le=Qs;function _t(i,e="utf8"){let t=Le[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?V(globalThis.Buffer.from(i,"utf-8")):t.decoder.decode(`${t.prefix}${i}`)}function be(i,e="utf8"){let t=Le[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 pi=Symbol.for("@achingbrain/uint8arraylist");function mi(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 Te(i){return!!i?.[pi]}var I=class{constructor(...e){Object.defineProperty(this,pi,{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(Te(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(Te(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=mi(this.bufs,e);return t.buf[t.index]}set(e,t){let r=mi(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(Te(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 Ae(r,n)}subarray(e,t){let{bufs:r,length:n}=this._subList(e,t);return r.length===1?r[0]:Ae(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,h=t>a&&t<=c;if(u&&h){if(e===a&&t===c){r.push(o);break}let l=e-a;r.push(o.subarray(l,l+(t-e)));break}if(u){if(e===0){r.push(o);continue}r.push(o.subarray(e-a));continue}if(h){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(!Te(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 l=0;l<s;l++)o[l]=-1;for(let l=0;l<n;l++)o[r[l]]=l;let a=o,c=this.byteLength-r.byteLength,u=r.byteLength-1,h;for(let l=t;l<=c;l+=h){h=0;for(let m=u;m>=0;m--){let E=this.get(l+m);if(r[m]!==E){h=Math.max(1,m-a[E]);break}}if(h===0)return l}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=K(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=z(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=z(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=z(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=K(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=z(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=z(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=z(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=z(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=z(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(!Ze(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 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 ye=Object.freeze({0:"NEW_STREAM",1:"MESSAGE_RECEIVER",2:"MESSAGE_INITIATOR",3:"CLOSE_RECEIVER",4:"CLOSE_INITIATOR",5:"RESET_RECEIVER",6:"RESET_INITIATOR"}),St=Object.freeze({NEW_STREAM:b.NEW_STREAM,MESSAGE:b.MESSAGE_INITIATOR,CLOSE:b.CLOSE_INITIATOR,RESET:b.RESET_INITIATOR}),bi=Object.freeze({MESSAGE:b.MESSAGE_RECEIVER,CLOSE:b.CLOSE_RECEIVER,RESET:b.RESET_RECEIVER});var Ct=1<<20,Xs=4<<20,Ie=class{_buffer;_headerInfo;_maxMessageSize;_maxUnprocessedMessageQueueSize;constructor(e=Ct,t=Xs){this._buffer=new I,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===b.NEW_STREAM||n===b.MESSAGE_INITIATOR||n===b.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}=wi(e),{value:n,offset:s}=wi(e,r),o=t&7;if(ye[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}}},Ys=128,yi=127;function wi(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&yi)<<r:(s&yi)*Math.pow(2,r),r+=7}while(s>=Ys);return e=n-e,{value:t,offset:e}}function Ne(){let i={};return i.promise=new Promise((e,t)=>{i.resolve=e,i.reject=t}),i}function Js(i){return i[Symbol.asyncIterator]!=null}var Me=1024*1024,gi=(i,e)=>{e.append(i)};function Zs(i,e){return Js(i)?async function*(){let t=new I,r=!1,n=Ne(),s=Number(e?.size??Me);if((isNaN(s)||s===0||s<0)&&(s=Me),s!==Math.round(s))throw new Error("Batch size must be an integer");let o=e?.yieldAfter??0,a=e?.serialize??gi;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=Ne(),t.byteLength>0){let c=t;t=new I,yield c.subarray()}}():function*(){let t=new I,r=Number(e?.size??Me);if((isNaN(r)||r===0||r<0)&&(r=Me),r!==Math.round(r))throw new Error("Batch size must be an integer");let n=e?.serialize??gi;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 xi=Zs;var ce=Pe(Ni(),1);function Lt(i){return new Uint8Array(i)}var Tt=10*1024,It=class{_pool;_poolOffset;constructor(){this._pool=Lt(Tt),this._poolOffset=0}write(e,t){let r=this._pool,n=this._poolOffset;ce.default.encode(e.id<<3|e.type,r,n),n+=ce.default.encode.bytes??0,(e.type===b.NEW_STREAM||e.type===b.MESSAGE_INITIATOR||e.type===b.MESSAGE_RECEIVER)&&e.data!=null?ce.default.encode(e.data.length,r,n):ce.default.encode(0,r,n),n+=ce.default.encode.bytes??0;let s=r.subarray(this._poolOffset,n);Tt-n<100?(this._pool=Lt(Tt),this._poolOffset=0):this._poolOffset=n,t.append(s),(e.type===b.NEW_STREAM||e.type===b.MESSAGE_INITIATOR||e.type===b.MESSAGE_RECEIVER)&&e.data!=null&&t.append(e.data)}},Mi=new It;async function*vi(i,e=0){if(e==null||e===0){for await(let t of i){let r=new I;for(let n of t)Mi.write(n,r);yield r.subarray()}return}yield*xi(i,{size:e,serialize:(t,r)=>{for(let n of t)Mi.write(n,r)}})}var M=()=>{};M.trace=()=>{};M.error=()=>{};var Nt="ERR_STREAM_RESET",mo="ERR_STREAM_ABORT",po="ERR_SINK_ENDED",bo="ERR_DOUBLE_SINK";function H(i){return i!=null&&typeof i.then=="function"}var ve=class{id;stat;metadata;source;abortController;resetController;closeController;sourceEnded;sinkEnded;sinkSunk;endErr;streamSource;onEnd;maxDataSize;constructor(e){this.abortController=new AbortController,this.resetController=new AbortController,this.closeController=new AbortController,this.sourceEnded=!1,this.sinkEnded=!1,this.sinkSunk=!1,this.id=e.id,this.metadata=e.metadata??{},this.stat={direction:e.direction,timeline:{open:Date.now()}},this.maxDataSize=e.maxDataSize,this.onEnd=e.onEnd,this.source=this.streamSource=Ht({onEnd:()=>{if(this.stat.timeline.reset!==null){let t=this.sendCloseRead();H(t)&&t.catch(r=>{M.error("error while sending close read",r)})}this.onSourceEnd()}}),this.sink=this.sink.bind(this)}onSourceEnd(e){this.sourceEnded||(this.stat.timeline.closeRead=Date.now(),this.sourceEnded=!0,M.trace("%s stream %s source end - err: %o",this.stat.direction,this.id,e),e!=null&&this.endErr==null&&(this.endErr=e),this.sinkEnded&&(this.stat.timeline.close=Date.now(),this.onEnd!=null&&this.onEnd(this.endErr)))}onSinkEnd(e){this.sinkEnded||(this.stat.timeline.closeWrite=Date.now(),this.sinkEnded=!0,M.trace("%s stream %s sink end - err: %o",this.stat.direction,this.id,e),e!=null&&this.endErr==null&&(this.endErr=e),this.sourceEnded&&(this.stat.timeline.close=Date.now(),this.onEnd!=null&&this.onEnd(this.endErr)))}close(){M.trace("%s stream %s close",this.stat.direction,this.id),this.closeRead(),this.closeWrite()}closeRead(){M.trace("%s stream %s closeRead",this.stat.direction,this.id),!this.sourceEnded&&this.streamSource.end()}closeWrite(){if(M.trace("%s stream %s closeWrite",this.stat.direction,this.id),!this.sinkEnded){this.closeController.abort();try{let e=this.sendCloseWrite();H(e)&&e.catch(t=>{M.error("error while sending close write",t)})}catch(e){M.trace("%s stream %s error sending close",this.stat.direction,this.id,e)}this.onSinkEnd()}}abort(e){M.trace("%s stream %s abort",this.stat.direction,this.id,e),this.streamSource.end(e),this.abortController.abort(),this.onSinkEnd(e)}reset(){let e=new q("stream reset",Nt);this.resetController.abort(),this.streamSource.end(e),this.onSinkEnd(e)}async sink(e){if(this.sinkSunk)throw new q("sink already called on stream",bo);if(this.sinkSunk=!0,this.sinkEnded)throw new q("stream closed for writing",po);let t=_e([this.abortController.signal,this.resetController.signal,this.closeController.signal]);try{if(e=Ee(e,t),this.stat.direction==="outbound"){let r=this.sendNewStream();H(r)&&await r}for await(let r of e)for(;r.length>0;){if(r.length<=this.maxDataSize){let s=this.sendData(r instanceof Uint8Array?new I(r):r);H(s)&&await s;break}r=r instanceof Uint8Array?new I(r):r;let n=this.sendData(r.sublist(0,this.maxDataSize));H(n)&&await n,r.consume(this.maxDataSize)}}catch(r){if(r.type==="aborted"&&r.message==="The operation was aborted"){if(this.closeController.signal.aborted)return;this.resetController.signal.aborted&&(r.message="stream reset",r.code=Nt),this.abortController.signal.aborted&&(r.message="stream aborted",r.code=mo)}if(r.code===Nt)M.trace("%s stream %s reset",this.stat.direction,this.id);else{M.trace("%s stream %s error",this.stat.direction,this.id,r);try{let n=this.sendReset();H(n)&&await n,this.stat.timeline.reset=Date.now()}catch(n){M.trace("%s stream %s error sending reset",this.stat.direction,this.id,n)}}throw this.streamSource.end(r),this.onSinkEnd(r),r}finally{t.clear()}try{let r=this.sendCloseWrite();H(r)&&await r}catch(r){M.trace("%s stream %s error sending close",this.stat.direction,this.id,r)}this.onSinkEnd()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};var Mt=class extends ve{name;streamId;send;types;constructor(e){super(e),this.types=e.direction==="outbound"?St:bi,this.send=e.send,this.name=e.name,this.streamId=e.streamId}sendNewStream(){this.send({id:this.streamId,type:St.NEW_STREAM,data:new I(_t(this.name))})}sendData(e){this.send({id:this.streamId,type:this.types.MESSAGE,data:e})}sendReset(){this.send({id:this.streamId,type:this.types.RESET})}sendCloseWrite(){this.send({id:this.streamId,type:this.types.CLOSE})}sendCloseRead(){}};function ki(i){let{id:e,name:t,send:r,onEnd:n,type:s="initiator",maxMsgSize:o=Ct}=i;return new Mt({id:s==="initiator"?`i${e}`:`r${e}`,streamId:e,name:`${t??e}`,direction:s==="initiator"?"outbound":"inbound",maxDataSize:o,onEnd:n,send:r})}var F=Gt("libp2p:mplex"),yo=1024,wo=1024,go=1024*1024*4,xo=5;function Pi(i){let e={...i,type:`${ye[i.type]} (${i.type})`};return i.type===b.NEW_STREAM&&(e.data=be(i.data instanceof Uint8Array?i.data:i.data.subarray())),(i.type===b.MESSAGE_INITIATOR||i.type===b.MESSAGE_RECEIVER)&&(e.data=be(i.data instanceof Uint8Array?i.data:i.data.subarray(),"base16")),e}var ke=class{protocol="/mplex/6.7.0";sink;source;_streamId;_streams;_init;_source;closeController;rateLimiter;constructor(e){e=e??{},this._streamId=0,this._streams={initiators:new Map,receivers:new Map},this._init=e,this.sink=this._createSink();let t=this._createSource();this._source=t,this.source=t,this.closeController=new AbortController,this.rateLimiter=new Bi.RateLimiterMemory({points:e.disconnectThreshold??xo,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})}close(e){this.closeController.signal.aborted||(e!=null?this.streams.forEach(t=>{t.abort(e)}):this.streams.forEach(t=>{t.close()}),this.closeController.abort())}_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(F("new %s stream %s",n,t),n==="initiator"&&this._streams.initiators.size===(this._init.maxOutboundStreams??wo))throw new q("Too many outbound streams open","ERR_TOO_MANY_OUTBOUND_STREAMS");if(s.has(t))throw new Error(`${n} stream ${t} already exists!`);let c=ki({id:t,name:r,send:u=>{F.enabled&&F.trace("%s stream %s send",n,t,Pi(u)),this._source.push(u)},type:n,onEnd:()=>{F("%s stream with id %s and protocol %s ended",n,t,c.stat.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=>{let r=_e([this.closeController.signal,this._init.signal]);try{t=Ee(t,r);let n=new Ie(this._init.maxMsgSize,this._init.maxUnprocessedMessageQueueSize);for await(let s of t)for(let o of n.write(s))await this._handleIncoming(o);this._source.end()}catch(n){F("error in sink",n),this._source.end(n)}finally{r.clear()}}}_createSource(){let t=Qt({objectMode:!0,onEnd:r=>{this.close(r)}});return Object.assign(vi(t,this._init.minSendBytes),{push:t.push,end:t.end,return:t.return})}async _handleIncoming(e){let{id:t,type:r}=e;if(F.enabled&&F.trace("incoming message",Pi(e)),e.type===b.NEW_STREAM){if(this._streams.receivers.size===(this._init.maxInboundStreams??yo)){F("too many inbound streams open"),this._source.push({id:t,type:b.RESET_RECEIVER});try{await this.rateLimiter.consume("new-stream",1)}catch{F("rate limit hit when opening too many new streams over the inbound stream limit - closing remote connection"),this._source.end(new Error("Too many open streams"));return}return}let a=this._newReceiverStream({id:t,name:be(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){F("missing stream %s for message type %s",t,ye[r]);return}let o=this._init.maxStreamBufferSize??go;switch(r){case b.MESSAGE_INITIATOR:case b.MESSAGE_RECEIVER:if(s.sourceReadableLength()>o){this._source.push({id:e.id,type:r===b.MESSAGE_INITIATOR?b.RESET_RECEIVER:b.RESET_INITIATOR});let a=new q("Input buffer full - increase Mplex maxBufferSize to accommodate slow consumers","ERR_STREAM_INPUT_BUFFER_FULL");s.abort(a);return}s.sourcePush(e.data);break;case b.CLOSE_INITIATOR:case b.CLOSE_RECEIVER:s.closeRead();break;case b.RESET_INITIATOR:case b.RESET_RECEIVER:s.reset();break;default:F("unknown message type %s",r)}}};var vt=class{protocol="/mplex/6.7.0";_init;constructor(e={}){this._init=e}createStreamMuxer(e={}){return new ke({...e,...this._init})}};function Eo(i={}){return()=>new vt(i)}return zi(_o);})();
25
25
  return Libp2PMplex}));
@@ -1,4 +1,4 @@
1
- import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer';
1
+ import type { StreamMuxerFactory } from '@libp2p/interface/stream-muxer';
2
2
  export interface MplexInit {
3
3
  /**
4
4
  * The maximum size of message that can be sent in one go in bytes.
@@ -1,7 +1,7 @@
1
1
  import { type Message } from './message-types.js';
2
2
  import type { MplexInit } from './index.js';
3
- import type { Stream } from '@libp2p/interface-connection';
4
- import type { StreamMuxer, StreamMuxerInit } from '@libp2p/interface-stream-muxer';
3
+ import type { Stream } from '@libp2p/interface/connection';
4
+ import type { StreamMuxer, StreamMuxerInit } from '@libp2p/interface/stream-muxer';
5
5
  import type { Sink, Source } from 'it-stream-types';
6
6
  import type { Uint8ArrayList } from 'uint8arraylist';
7
7
  export interface MplexStream extends Stream {
package/dist/src/mplex.js CHANGED
@@ -1,4 +1,4 @@
1
- import { CodeError } from '@libp2p/interfaces/errors';
1
+ import { CodeError } from '@libp2p/interface/errors';
2
2
  import { logger } from '@libp2p/logger';
3
3
  import { abortableSource } from 'abortable-iterator';
4
4
  import { anySignal } from 'any-signal';
@@ -1 +1 @@
1
- {"version":3,"file":"mplex.js","sourceRoot":"","sources":["../../src/mplex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAgB,MAAM,oBAAoB,CAAA;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAO1C,MAAM,GAAG,G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8BAA8B,CAAC,CAAA;oBAC7I,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;oBAEnB,OAAM;iBACP;gBAED,6DAA6D;gBAC7D,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;gBAC/B,MAAK;YACP,KAAK,YAAY,CAAC,eAAe,CAAC;YAClC,KAAK,YAAY,CAAC,cAAc;gBAC9B,8DAA8D;gBAC9D,MAAM,CAAC,SAAS,EAAE,CAAA;gBAClB,MAAK;YACP,KAAK,YAAY,CAAC,eAAe,CAAC;YAClC,KAAK,YAAY,CAAC,cAAc;gBAC9B,qDAAqD;gBACrD,MAAM,CAAC,KAAK,EAAE,CAAA;gBACd,MAAK;YACP;gBACE,GAAG,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAA;SACvC;IACH,CAAC;CACF"}
@@ -1,4 +1,4 @@
1
- import { AbstractStream, type AbstractStreamInit } from '@libp2p/interface-stream-muxer/stream';
1
+ import { AbstractStream, type AbstractStreamInit } from '@libp2p/interface/stream-muxer/stream';
2
2
  import { Uint8ArrayList } from 'uint8arraylist';
3
3
  import type { Message } from './message-types.js';
4
4
  export interface Options {
@@ -1,4 +1,4 @@
1
- import { AbstractStream } from '@libp2p/interface-stream-muxer/stream';
1
+ import { AbstractStream } from '@libp2p/interface/stream-muxer/stream';
2
2
  import { Uint8ArrayList } from 'uint8arraylist';
3
3
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
4
4
  import { MAX_MSG_SIZE } from './decode.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/mplex",
3
- "version": "8.0.4-d853d124",
3
+ "version": "8.0.4-f427cfc9",
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,10 +56,8 @@
56
56
  "test:electron-main": "aegir test -t electron-main"
57
57
  },
58
58
  "dependencies": {
59
- "@libp2p/interface-connection": "5.1.1-d853d124",
60
- "@libp2p/interface-stream-muxer": "4.1.2-d853d124",
61
- "@libp2p/interfaces": "3.3.2-d853d124",
62
- "@libp2p/logger": "2.1.1-d853d124",
59
+ "@libp2p/interface": "0.0.1-f427cfc9",
60
+ "@libp2p/logger": "2.1.1-f427cfc9",
63
61
  "abortable-iterator": "^5.0.1",
64
62
  "any-signal": "^4.1.1",
65
63
  "benchmark": "^2.1.4",
@@ -68,11 +66,11 @@
68
66
  "it-stream-types": "^2.0.1",
69
67
  "rate-limiter-flexible": "^2.3.11",
70
68
  "uint8arraylist": "^2.4.3",
71
- "uint8arrays": "^4.0.3",
69
+ "uint8arrays": "^4.0.4",
72
70
  "varint": "^6.0.0"
73
71
  },
74
72
  "devDependencies": {
75
- "@libp2p/interface-stream-muxer-compliance-tests": "7.0.3-d853d124",
73
+ "@libp2p/interface-compliance-tests": "3.0.7-f427cfc9",
76
74
  "@types/varint": "^6.0.0",
77
75
  "aegir": "^39.0.10",
78
76
  "cborg": "^2.0.1",
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MplexStreamMuxer } from './mplex.js'
2
- import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface-stream-muxer'
2
+ import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface/stream-muxer'
3
3
 
4
4
  export interface MplexInit {
5
5
  /**
package/src/mplex.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CodeError } from '@libp2p/interfaces/errors'
1
+ import { CodeError } from '@libp2p/interface/errors'
2
2
  import { logger } from '@libp2p/logger'
3
3
  import { abortableSource } from 'abortable-iterator'
4
4
  import { anySignal } from 'any-signal'
@@ -10,8 +10,8 @@ import { encode } from './encode.js'
10
10
  import { MessageTypes, MessageTypeNames, type Message } from './message-types.js'
11
11
  import { createStream } from './stream.js'
12
12
  import type { MplexInit } from './index.js'
13
- import type { Stream } from '@libp2p/interface-connection'
14
- import type { StreamMuxer, StreamMuxerInit } from '@libp2p/interface-stream-muxer'
13
+ import type { Stream } from '@libp2p/interface/connection'
14
+ import type { StreamMuxer, StreamMuxerInit } from '@libp2p/interface/stream-muxer'
15
15
  import type { Sink, Source } from 'it-stream-types'
16
16
  import type { Uint8ArrayList } from 'uint8arraylist'
17
17
 
package/src/stream.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AbstractStream, type AbstractStreamInit } from '@libp2p/interface-stream-muxer/stream'
1
+ import { AbstractStream, type AbstractStreamInit } from '@libp2p/interface/stream-muxer/stream'
2
2
  import { Uint8ArrayList } from 'uint8arraylist'
3
3
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
4
4
  import { MAX_MSG_SIZE } from './decode.js'