@helia/utils 2.3.1 → 2.3.2-574ac5e4
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 +4 -4
- package/dist/index.min.js.map +4 -4
- package/dist/src/errors.d.ts +4 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +4 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/utils/networked-storage.d.ts.map +1 -1
- package/dist/src/utils/networked-storage.js +15 -3
- package/dist/src/utils/networked-storage.js.map +1 -1
- package/package.json +3 -3
- package/src/errors.ts +5 -0
- package/src/utils/networked-storage.ts +20 -3
- package/dist/typedoc-urls.json +0 -19
package/dist/index.min.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaUtils = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var HeliaUtils=(()=>{var ha=Object.create;var pt=Object.defineProperty;var da=Object.getOwnPropertyDescriptor;var pa=Object.getOwnPropertyNames;var ma=Object.getPrototypeOf,ga=Object.prototype.hasOwnProperty;var Ti=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),I=(r,e)=>{for(var t in e)pt(r,t,{get:e[t],enumerable:!0})},Li=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of pa(e))!ga.call(r,i)&&i!==t&&pt(r,i,{get:()=>e[i],enumerable:!(n=da(e,i))||n.enumerable});return r};var Pi=(r,e,t)=>(t=r!=null?ha(ma(r)):{},Li(e||!r||!r.__esModule?pt(t,"default",{value:r,enumerable:!0}):t,r)),ya=r=>Li(pt({},"__esModule",{value:!0}),r);var Wi=Ti((Af,on)=>{"use strict";var Ya=Object.prototype.hasOwnProperty,B="~";function We(){}Object.create&&(We.prototype=Object.create(null),new We().__proto__||(B=!1));function Xa(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Hi(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var o=new Xa(t,n||r,i),s=B?B+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],o]:r._events[s].push(o):(r._events[s]=o,r._eventsCount++),r}function bt(r,e){--r._eventsCount===0?r._events=new We:delete r._events[e]}function N(){this._events=new We,this._eventsCount=0}N.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Ya.call(t,n)&&e.push(B?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};N.prototype.listeners=function(e){var t=B?B+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};N.prototype.listenerCount=function(e){var t=B?B+e:e,n=this._events[t];return n?n.fn?1:n.length:0};N.prototype.emit=function(e,t,n,i,o,s){var a=B?B+e:e;if(!this._events[a])return!1;var c=this._events[a],h=arguments.length,l,f;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),h){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,o),!0;case 6:return c.fn.call(c.context,t,n,i,o,s),!0}for(f=1,l=new Array(h-1);f<h;f++)l[f-1]=arguments[f];c.fn.apply(c.context,l)}else{var m=c.length,y;for(f=0;f<m;f++)switch(c[f].once&&this.removeListener(e,c[f].fn,void 0,!0),h){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,n,i);break;default:if(!l)for(y=1,l=new Array(h-1);y<h;y++)l[y-1]=arguments[y];c[f].fn.apply(c[f].context,l)}}return!0};N.prototype.on=function(e,t,n){return Hi(this,e,t,n,!1)};N.prototype.once=function(e,t,n){return Hi(this,e,t,n,!0)};N.prototype.removeListener=function(e,t,n,i){var o=B?B+e:e;if(!this._events[o])return this;if(!t)return bt(this,o),this;var s=this._events[o];if(s.fn)s.fn===t&&(!i||s.once)&&(!n||s.context===n)&&bt(this,o);else{for(var a=0,c=[],h=s.length;a<h;a++)(s[a].fn!==t||i&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:bt(this,o)}return this};N.prototype.removeAllListeners=function(e){var t;return e?(t=B?B+e:e,this._events[t]&&bt(this,t)):(this._events=new We,this._eventsCount=0),this};N.prototype.off=N.prototype.removeListener;N.prototype.addListener=N.prototype.on;N.prefixed=B;N.EventEmitter=N;typeof on<"u"&&(on.exports=N)});var mo=Ti((Ph,po)=>{po.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function i(o,s){t[o]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(o){return t[o]!==void 0||n[o]!==void 0},remove:function(o){t[o]!==void 0&&(t[o]=void 0),n[o]!==void 0&&(n[o]=void 0)},get:function(o){var s=t[o];if(s!==void 0)return s;if((s=n[o])!==void 0)return i(o,s),s},set:function(o,s){t[o]!==void 0?t[o]=s:i(o,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var Gl={};I(Gl,{AbstractSession:()=>Gr,Helia:()=>Ii,breadthFirstWalker:()=>ua,depthFirstWalker:()=>ca,naturalOrderWalker:()=>la});var Ni=Symbol.for("@libp2p/content-routing");var J=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var Le=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var mt=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var gt=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Di=Symbol.for("@libp2p/peer-routing");function Ri(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function he(...r){let e=[];for(let t of r)Ri(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function de(...r){let e=[];for(let t of r)Ri(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var K=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let i=this.#e.get(e);i!=null&&(i=i.filter(({callback:o})=>o!==t),this.#e.set(e,i))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:i})=>!i),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var en={};I(en,{base32:()=>me,base32hex:()=>Ca,base32hexpad:()=>Ta,base32hexpadupper:()=>La,base32hexupper:()=>Ia,base32pad:()=>Aa,base32padupper:()=>Sa,base32upper:()=>ka,base32z:()=>Pa});var tf=new Uint8Array(0);function Bi(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Y(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Ui(r){return new TextEncoder().encode(r)}function $i(r){return new TextDecoder().decode(r)}function wa(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(t[s]!==255)throw new TypeError(o+" is ambiguous");t[s]=i}var a=r.length,c=r.charAt(0),h=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var _=0,w=0,b=0,A=x.length;b!==A&&x[b]===0;)b++,_++;for(var S=(A-b)*l+1>>>0,D=new Uint8Array(S);b!==A;){for(var L=x[b],se=0,R=S-1;(L!==0||se<w)&&R!==-1;R--,se++)L+=256*D[R]>>>0,D[R]=L%a>>>0,L=L/a>>>0;if(L!==0)throw new Error("Non-zero carry");w=se,b++}for(var Q=S-w;Q!==S&&D[Q]===0;)Q++;for(var be=c.repeat(_);Q<S;++Q)be+=r.charAt(D[Q]);return be}function m(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var _=0;if(x[_]!==" "){for(var w=0,b=0;x[_]===c;)w++,_++;for(var A=(x.length-_)*h+1>>>0,S=new Uint8Array(A);x[_];){var D=t[x.charCodeAt(_)];if(D===255)return;for(var L=0,se=A-1;(D!==0||L<b)&&se!==-1;se--,L++)D+=a*S[se]>>>0,S[se]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");b=L,_++}if(x[_]!==" "){for(var R=A-b;R!==A&&S[R]===0;)R++;for(var Q=new Uint8Array(w+(A-R)),be=w;R!==A;)Q[be++]=S[R++];return Q}}}function y(x){var _=m(x);if(_)return _;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:y}}var xa=wa,ba=xa,Fi=ba;var Jr=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Yr=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let i=t.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}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 Oi(this,e)}},Xr=class{decoders;constructor(e){this.decoders=e}or(e){return Oi(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Oi(r,e){return new Xr({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Zr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new Jr(e,t,n),this.decoder=new Yr(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Pe({name:r,prefix:e,encode:t,decode:n}){return new Zr(r,e,t,n)}function pe({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=Fi(t,r);return Pe({prefix:e,name:r,encode:n,decode:o=>Y(i(o))})}function Ea(r,e,t,n){let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*t/8|0),s=0,a=0,c=0;for(let h=0;h<i;++h){let l=e[r[h]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|l,s+=t,s>=8&&(s-=8,o[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return o}function va(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,o="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<t-s]),n)for(;(o.length*t&7)!==0;)o+="=";return o}function _a(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function C({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let i=_a(n);return Pe({prefix:e,name:r,encode(o){return va(o,n,t)},decode(o){return Ea(o,i,t,r)}})}var me=C({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ka=C({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Aa=C({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Sa=C({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ca=C({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ia=C({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ta=C({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),La=C({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Pa=C({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var tn={};I(tn,{base58btc:()=>H,base58flickr:()=>Na});var H=pe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Na=pe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var rn={};I(rn,{base64:()=>ge,base64pad:()=>Da,base64url:()=>Ra,base64urlpad:()=>Ba});var ge=C({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Da=C({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ra=C({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ba=C({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Ua(r,e){if(typeof r=="string")return $a(r);if(typeof r=="number")return za(r,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(r)}`)}var yt=Ua;function $a(r){if(typeof r!="string"||r.length===0||r.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(r)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(r);if(!e?.groups)return NaN;let{value:t,unit:n="ms"}=e.groups,i=parseFloat(t),o=n.toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return i*315576e5;case"months":case"month":case"mo":return i*26298e5;case"weeks":case"week":case"w":return i*6048e5;case"days":case"day":case"d":return i*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return i*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return i*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return i*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return i;default:throw Error(`Unknown unit "${o}" provided to ms.parse(). value=${JSON.stringify(r)}`)}}function Fa(r){let e=Math.abs(r);return e>=315576e5?`${Math.round(r/315576e5)}y`:e>=26298e5?`${Math.round(r/26298e5)}mo`:e>=6048e5?`${Math.round(r/6048e5)}w`:e>=864e5?`${Math.round(r/864e5)}d`:e>=36e5?`${Math.round(r/36e5)}h`:e>=6e4?`${Math.round(r/6e4)}m`:e>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function Oa(r){let e=Math.abs(r);return e>=315576e5?Ee(r,e,315576e5,"year"):e>=26298e5?Ee(r,e,26298e5,"month"):e>=6048e5?Ee(r,e,6048e5,"week"):e>=864e5?Ee(r,e,864e5,"day"):e>=36e5?Ee(r,e,36e5,"hour"):e>=6e4?Ee(r,e,6e4,"minute"):e>=1e3?Ee(r,e,1e3,"second"):`${r} ms`}function za(r,e){if(typeof r!="number"||!Number.isFinite(r))throw Error("Value provided to ms.format() must be of type number.");return e?.long?Oa(r):Fa(r)}function Ee(r,e,t,n){let i=e>=t*1.5;return`${Math.round(r/t)} ${n}${i?"s":""}`}function nn(r){t.debug=t,t.default=t,t.coerce=c,t.disable=o,t.enable=i,t.enabled=s,t.humanize=yt,t.destroy=h,Object.keys(r).forEach(l=>{t[l]=r[l]}),t.names=[],t.skips=[],t.formatters={};function e(l){let f=0;for(let m=0;m<l.length;m++)f=(f<<5)-f+l.charCodeAt(m),f|=0;return t.colors[Math.abs(f)%t.colors.length]}t.selectColor=e;function t(l,f){let m,y=null,x,_;function w(...b){if(!w.enabled)return;let A=w,S=Number(new Date),D=S-(m||S);A.diff=D,A.prev=m,A.curr=S,m=S,b[0]=t.coerce(b[0]),typeof b[0]!="string"&&b.unshift("%O");let L=0;b[0]=b[0].replace(/%([a-zA-Z%])/g,(R,Q)=>{if(R==="%%")return"%";L++;let be=t.formatters[Q];if(typeof be=="function"){let fa=b[L];R=be.call(A,fa),b.splice(L,1),L--}return R}),t.formatArgs.call(A,b),f?.onLog!=null&&f.onLog(...b),(A.log||t.log).apply(A,b)}return w.namespace=l,w.useColors=t.useColors(),w.color=t.selectColor(l),w.extend=n,w.destroy=t.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>y!==null?y:(x!==t.namespaces&&(x=t.namespaces,_=t.enabled(l)),_),set:b=>{y=b}}),typeof t.init=="function"&&t.init(w),w}function n(l,f){let m=t(this.namespace+(typeof f>"u"?":":f)+l);return m.log=this.log,m}function i(l){t.save(l),t.namespaces=l,t.names=[],t.skips=[];let f,m=(typeof l=="string"?l:"").split(/[\s,]+/),y=m.length;for(f=0;f<y;f++)m[f]&&(l=m[f].replace(/\*/g,".*?"),l[0]==="-"?t.skips.push(new RegExp("^"+l.substr(1)+"$")):t.names.push(new RegExp("^"+l+"$")))}function o(){let l=[...t.names.map(a),...t.skips.map(a).map(f=>"-"+f)].join(",");return t.enable(""),l}function s(l){if(l[l.length-1]==="*")return!0;let f,m;for(f=0,m=t.skips.length;f<m;f++)if(t.skips[f].test(l))return!1;for(f=0,m=t.names.length;f<m;f++)if(t.names[f].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function c(l){return l instanceof Error?l.stack??l.message:l}function h(){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.setupFormatters(t.formatters),t.enable(t.load()),t}var wt=Wa(),Ma=["#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 qa(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function ja(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+yt(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(t++,i==="%c"&&(n=t))}),r.splice(n,0,e)}var Va=console.debug??console.log??(()=>{});function Ka(r){try{r?wt?.setItem("debug",r):wt?.removeItem("debug")}catch{}}function Ha(){let r;try{r=wt?.getItem("debug")}catch{}return!r&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(r=globalThis.process.env.DEBUG),r}function Wa(){try{return localStorage}catch{}}function Ga(r){r.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}var zi=nn({formatArgs:ja,save:Ka,load:Ha,useColors:qa,setupFormatters:Ga,colors:Ma,storage:wt,log:Va});var U=zi;U.formatters.b=r=>r==null?"undefined":H.baseEncode(r);U.formatters.t=r=>r==null?"undefined":me.baseEncode(r);U.formatters.m=r=>r==null?"undefined":ge.baseEncode(r);U.formatters.p=r=>r==null?"undefined":r.toString();U.formatters.c=r=>r==null?"undefined":r.toString();U.formatters.k=r=>r==null?"undefined":r.toString();U.formatters.a=r=>r==null?"undefined":r.toString();function Mi(r,e=""){let t=qi(r.message),n=qi(r.stack);return t!=null&&n!=null?n.includes(t)?`${n.split(`
|
|
2
|
+
"use strict";var HeliaUtils=(()=>{var ua=Object.create;var mt=Object.defineProperty;var la=Object.getOwnPropertyDescriptor;var fa=Object.getOwnPropertyNames;var ha=Object.getPrototypeOf,da=Object.prototype.hasOwnProperty;var Ii=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),I=(r,e)=>{for(var t in e)mt(r,t,{get:e[t],enumerable:!0})},Ti=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of fa(e))!da.call(r,i)&&i!==t&&mt(r,i,{get:()=>e[i],enumerable:!(n=la(e,i))||n.enumerable});return r};var Li=(r,e,t)=>(t=r!=null?ua(ha(r)):{},Ti(e||!r||!r.__esModule?mt(t,"default",{value:r,enumerable:!0}):t,r)),pa=r=>Ti(mt({},"__esModule",{value:!0}),r);var Hi=Ii((vf,nn)=>{"use strict";var Ga=Object.prototype.hasOwnProperty,B="~";function Ge(){}Object.create&&(Ge.prototype=Object.create(null),new Ge().__proto__||(B=!1));function Qa(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Ki(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var o=new Qa(t,n||r,i),s=B?B+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],o]:r._events[s].push(o):(r._events[s]=o,r._eventsCount++),r}function Et(r,e){--r._eventsCount===0?r._events=new Ge:delete r._events[e]}function N(){this._events=new Ge,this._eventsCount=0}N.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Ga.call(t,n)&&e.push(B?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};N.prototype.listeners=function(e){var t=B?B+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};N.prototype.listenerCount=function(e){var t=B?B+e:e,n=this._events[t];return n?n.fn?1:n.length:0};N.prototype.emit=function(e,t,n,i,o,s){var a=B?B+e:e;if(!this._events[a])return!1;var c=this._events[a],h=arguments.length,l,f;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),h){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,o),!0;case 6:return c.fn.call(c.context,t,n,i,o,s),!0}for(f=1,l=new Array(h-1);f<h;f++)l[f-1]=arguments[f];c.fn.apply(c.context,l)}else{var m=c.length,y;for(f=0;f<m;f++)switch(c[f].once&&this.removeListener(e,c[f].fn,void 0,!0),h){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,n,i);break;default:if(!l)for(y=1,l=new Array(h-1);y<h;y++)l[y-1]=arguments[y];c[f].fn.apply(c[f].context,l)}}return!0};N.prototype.on=function(e,t,n){return Ki(this,e,t,n,!1)};N.prototype.once=function(e,t,n){return Ki(this,e,t,n,!0)};N.prototype.removeListener=function(e,t,n,i){var o=B?B+e:e;if(!this._events[o])return this;if(!t)return Et(this,o),this;var s=this._events[o];if(s.fn)s.fn===t&&(!i||s.once)&&(!n||s.context===n)&&Et(this,o);else{for(var a=0,c=[],h=s.length;a<h;a++)(s[a].fn!==t||i&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:Et(this,o)}return this};N.prototype.removeAllListeners=function(e){var t;return e?(t=B?B+e:e,this._events[t]&&Et(this,t)):(this._events=new Ge,this._eventsCount=0),this};N.prototype.off=N.prototype.removeListener;N.prototype.addListener=N.prototype.on;N.prefixed=B;N.EventEmitter=N;typeof nn<"u"&&(nn.exports=N)});var po=Ii((Ih,ho)=>{ho.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function i(o,s){t[o]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(o){return t[o]!==void 0||n[o]!==void 0},remove:function(o){t[o]!==void 0&&(t[o]=void 0),n[o]!==void 0&&(n[o]=void 0)},get:function(o){var s=t[o];if(s!==void 0)return s;if((s=n[o])!==void 0)return i(o,s),s},set:function(o,s){t[o]!==void 0?t[o]=s:i(o,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var Kl={};I(Kl,{AbstractSession:()=>Wr,Helia:()=>Ci,breadthFirstWalker:()=>sa,depthFirstWalker:()=>oa,naturalOrderWalker:()=>aa});var Pi=Symbol.for("@libp2p/content-routing");var J=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var Pe=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var gt=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var yt=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Ni=Symbol.for("@libp2p/peer-routing");function Di(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function de(...r){let e=[];for(let t of r)Di(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function pe(...r){let e=[];for(let t of r)Di(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var K=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let i=this.#e.get(e);i!=null&&(i=i.filter(({callback:o})=>o!==t),this.#e.set(e,i))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:i})=>!i),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Zr={};I(Zr,{base32:()=>ge,base32hex:()=>ka,base32hexpad:()=>Sa,base32hexpadupper:()=>Ca,base32hexupper:()=>Aa,base32pad:()=>va,base32padupper:()=>_a,base32upper:()=>Ea,base32z:()=>Ia});var Xl=new Uint8Array(0);function Ri(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Y(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Bi(r){return new TextEncoder().encode(r)}function Ui(r){return new TextDecoder().decode(r)}function ma(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(t[s]!==255)throw new TypeError(o+" is ambiguous");t[s]=i}var a=r.length,c=r.charAt(0),h=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var _=0,w=0,b=0,A=x.length;b!==A&&x[b]===0;)b++,_++;for(var S=(A-b)*l+1>>>0,D=new Uint8Array(S);b!==A;){for(var L=x[b],se=0,R=S-1;(L!==0||se<w)&&R!==-1;R--,se++)L+=256*D[R]>>>0,D[R]=L%a>>>0,L=L/a>>>0;if(L!==0)throw new Error("Non-zero carry");w=se,b++}for(var Q=S-w;Q!==S&&D[Q]===0;)Q++;for(var Ee=c.repeat(_);Q<S;++Q)Ee+=r.charAt(D[Q]);return Ee}function m(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var _=0;if(x[_]!==" "){for(var w=0,b=0;x[_]===c;)w++,_++;for(var A=(x.length-_)*h+1>>>0,S=new Uint8Array(A);x[_];){var D=t[x.charCodeAt(_)];if(D===255)return;for(var L=0,se=A-1;(D!==0||L<b)&&se!==-1;se--,L++)D+=a*S[se]>>>0,S[se]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");b=L,_++}if(x[_]!==" "){for(var R=A-b;R!==A&&S[R]===0;)R++;for(var Q=new Uint8Array(w+(A-R)),Ee=w;R!==A;)Q[Ee++]=S[R++];return Q}}}function y(x){var _=m(x);if(_)return _;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:y}}var ga=ma,ya=ga,$i=ya;var Qr=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Jr=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let i=t.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}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 Fi(this,e)}},Yr=class{decoders;constructor(e){this.decoders=e}or(e){return Fi(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Fi(r,e){return new Yr({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Xr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new Qr(e,t,n),this.decoder=new Jr(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ne({name:r,prefix:e,encode:t,decode:n}){return new Xr(r,e,t,n)}function me({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=$i(t,r);return Ne({prefix:e,name:r,encode:n,decode:o=>Y(i(o))})}function wa(r,e,t,n){let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*t/8|0),s=0,a=0,c=0;for(let h=0;h<i;++h){let l=e[r[h]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|l,s+=t,s>=8&&(s-=8,o[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return o}function xa(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,o="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<t-s]),n)for(;(o.length*t&7)!==0;)o+="=";return o}function ba(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function C({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let i=ba(n);return Ne({prefix:e,name:r,encode(o){return xa(o,n,t)},decode(o){return wa(o,i,t,r)}})}var ge=C({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ea=C({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),va=C({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),_a=C({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ka=C({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Aa=C({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Sa=C({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ca=C({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ia=C({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var en={};I(en,{base58btc:()=>H,base58flickr:()=>Ta});var H=me({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ta=me({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var tn={};I(tn,{base64:()=>ye,base64pad:()=>La,base64url:()=>Pa,base64urlpad:()=>Na});var ye=C({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),La=C({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Pa=C({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Na=C({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Da(r,e){if(typeof r=="string")return Ra(r);if(typeof r=="number")return $a(r,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(r)}`)}var wt=Da;function Ra(r){if(typeof r!="string"||r.length===0||r.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(r)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(r);if(!e?.groups)return NaN;let{value:t,unit:n="ms"}=e.groups,i=parseFloat(t),o=n.toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return i*315576e5;case"months":case"month":case"mo":return i*26298e5;case"weeks":case"week":case"w":return i*6048e5;case"days":case"day":case"d":return i*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return i*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return i*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return i*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return i;default:throw Error(`Unknown unit "${o}" provided to ms.parse(). value=${JSON.stringify(r)}`)}}function Ba(r){let e=Math.abs(r);return e>=315576e5?`${Math.round(r/315576e5)}y`:e>=26298e5?`${Math.round(r/26298e5)}mo`:e>=6048e5?`${Math.round(r/6048e5)}w`:e>=864e5?`${Math.round(r/864e5)}d`:e>=36e5?`${Math.round(r/36e5)}h`:e>=6e4?`${Math.round(r/6e4)}m`:e>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function Ua(r){let e=Math.abs(r);return e>=315576e5?ve(r,e,315576e5,"year"):e>=26298e5?ve(r,e,26298e5,"month"):e>=6048e5?ve(r,e,6048e5,"week"):e>=864e5?ve(r,e,864e5,"day"):e>=36e5?ve(r,e,36e5,"hour"):e>=6e4?ve(r,e,6e4,"minute"):e>=1e3?ve(r,e,1e3,"second"):`${r} ms`}function $a(r,e){if(typeof r!="number"||!Number.isFinite(r))throw Error("Value provided to ms.format() must be of type number.");return e?.long?Ua(r):Ba(r)}function ve(r,e,t,n){let i=e>=t*1.5;return`${Math.round(r/t)} ${n}${i?"s":""}`}function rn(r){t.debug=t,t.default=t,t.coerce=c,t.disable=o,t.enable=i,t.enabled=s,t.humanize=wt,t.destroy=h,Object.keys(r).forEach(l=>{t[l]=r[l]}),t.names=[],t.skips=[],t.formatters={};function e(l){let f=0;for(let m=0;m<l.length;m++)f=(f<<5)-f+l.charCodeAt(m),f|=0;return t.colors[Math.abs(f)%t.colors.length]}t.selectColor=e;function t(l,f){let m,y=null,x,_;function w(...b){if(!w.enabled)return;let A=w,S=Number(new Date),D=S-(m||S);A.diff=D,A.prev=m,A.curr=S,m=S,b[0]=t.coerce(b[0]),typeof b[0]!="string"&&b.unshift("%O");let L=0;b[0]=b[0].replace(/%([a-zA-Z%])/g,(R,Q)=>{if(R==="%%")return"%";L++;let Ee=t.formatters[Q];if(typeof Ee=="function"){let ca=b[L];R=Ee.call(A,ca),b.splice(L,1),L--}return R}),t.formatArgs.call(A,b),f?.onLog!=null&&f.onLog(...b),(A.log||t.log).apply(A,b)}return w.namespace=l,w.useColors=t.useColors(),w.color=t.selectColor(l),w.extend=n,w.destroy=t.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>y!==null?y:(x!==t.namespaces&&(x=t.namespaces,_=t.enabled(l)),_),set:b=>{y=b}}),typeof t.init=="function"&&t.init(w),w}function n(l,f){let m=t(this.namespace+(typeof f>"u"?":":f)+l);return m.log=this.log,m}function i(l){t.save(l),t.namespaces=l,t.names=[],t.skips=[];let f,m=(typeof l=="string"?l:"").split(/[\s,]+/),y=m.length;for(f=0;f<y;f++)m[f]&&(l=m[f].replace(/\*/g,".*?"),l[0]==="-"?t.skips.push(new RegExp("^"+l.substr(1)+"$")):t.names.push(new RegExp("^"+l+"$")))}function o(){let l=[...t.names.map(a),...t.skips.map(a).map(f=>"-"+f)].join(",");return t.enable(""),l}function s(l){if(l[l.length-1]==="*")return!0;let f,m;for(f=0,m=t.skips.length;f<m;f++)if(t.skips[f].test(l))return!1;for(f=0,m=t.names.length;f<m;f++)if(t.names[f].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function c(l){return l instanceof Error?l.stack??l.message:l}function h(){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.setupFormatters(t.formatters),t.enable(t.load()),t}var xt=Va(),Fa=["#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 Oa(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function za(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+wt(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(t++,i==="%c"&&(n=t))}),r.splice(n,0,e)}var Ma=console.debug??console.log??(()=>{});function qa(r){try{r?xt?.setItem("debug",r):xt?.removeItem("debug")}catch{}}function ja(){let r;try{r=xt?.getItem("debug")}catch{}return!r&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(r=globalThis.process.env.DEBUG),r}function Va(){try{return localStorage}catch{}}function Ka(r){r.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}var Oi=rn({formatArgs:za,save:qa,load:ja,useColors:Oa,setupFormatters:Ka,colors:Fa,storage:xt,log:Ma});var U=Oi;U.formatters.b=r=>r==null?"undefined":H.baseEncode(r);U.formatters.t=r=>r==null?"undefined":ge.baseEncode(r);U.formatters.m=r=>r==null?"undefined":ye.baseEncode(r);U.formatters.p=r=>r==null?"undefined":r.toString();U.formatters.c=r=>r==null?"undefined":r.toString();U.formatters.k=r=>r==null?"undefined":r.toString();U.formatters.a=r=>r==null?"undefined":r.toString();function zi(r,e=""){let t=Mi(r.message),n=Mi(r.stack);return t!=null&&n!=null?n.includes(t)?`${n.split(`
|
|
3
3
|
`).join(`
|
|
4
4
|
${e}`)}`:`${t}
|
|
5
5
|
${e}${n.split(`
|
|
6
6
|
`).join(`
|
|
7
7
|
${e}`)}`:n!=null?`${n.split(`
|
|
8
8
|
`).join(`
|
|
9
|
-
${e}`)}`:t!=null?`${t}`:`${r.toString()}`}function
|
|
10
|
-
${e}${r.errors.map(n=>`${
|
|
9
|
+
${e}`)}`:t!=null?`${t}`:`${r.toString()}`}function Ha(r){return r instanceof AggregateError||r?.name==="AggregateError"&&Array.isArray(r.errors)}function qi(r,e=""){if(Ha(r)){let t=zi(r,e);return r.errors.length>0?(e=`${e} `,t+=`
|
|
10
|
+
${e}${r.errors.map(n=>`${qi(n,`${e}`)}`).join(`
|
|
11
11
|
${e}`)}`):t+=`
|
|
12
|
-
${e}[Error list was empty]`,t.trim()}return Mi(r,e)}U.formatters.e=r=>r==null?"undefined":ji(r);function Ja(r){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=r,e.destroy=()=>!0,e.extend=()=>e,e}function Vi(r){return{forComponent(e){return Ki(e,r)}}}function Ki(r,e){let t=Ja(`${r}:trace`);return U.enabled(`${r}:trace`)&&U.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(t=U(`${r}:trace`,e)),Object.assign(U(r,e),{error:U(`${r}:error`,e),trace:t,newScope:n=>Ki(`${r}:${n}`,e)})}function qi(r){if(r!=null&&(r=r.trim(),r.length!==0))return r}var v=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var xt=class extends AggregateError{static name="DNSQueryFailedError";name="DNSQueryFailedError"};var sn=Pi(Wi(),1);var an=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},Gi=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function cn(r,e){let{milliseconds:t,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout},signal:s}=e,a,c,l=new Promise((f,m)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(s?.aborted){m(Gi(s));return}if(s&&(c=()=>{m(Gi(s))},s.addEventListener("abort",c,{once:!0})),r.then(f,m),t===Number.POSITIVE_INFINITY)return;let y=new an;a=o.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(x){m(x)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?f():i instanceof Error?m(i):(y.message=i??`Promise timed out after ${t} milliseconds`,m(y))},t)}).finally(()=>{l.clear(),c&&s&&s.removeEventListener("abort",c)});return l.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},l}function un(r,e,t){let n=0,i=r.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;t(r[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Ge=class{#e=[];enqueue(e,t){let{priority:n=0,id:i}=t??{},o={priority:n,id:i,run:e};if(this.size===0||this.#e[this.size-1].priority>=n){this.#e.push(o);return}let s=un(this.#e,o,(a,c)=>c.priority-a.priority);this.#e.splice(s,0,o)}setPriority(e,t){let n=this.#e.findIndex(o=>o.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[i]=this.#e.splice(n,1);this.enqueue(i.run,{priority:t,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var Qe=class extends sn.default{#e;#n;#i=0;#d;#p=!1;#m=!1;#u;#x=0;#g=0;#o;#s;#t;#b;#r=0;#l;#a;#S=1n;#f=new Map;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Ge,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#n=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#u=e.interval,this.#t=new e.queueClass,this.#b=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#a=e.autoStart===!1,this.#D()}get#C(){return this.#n||this.#i<this.#d}get#I(){return this.#r<this.#l}#T(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#y(),this.emit("next")}#L(){this.#k(),this.#_(),this.#s=void 0}get#P(){let e=Date.now();if(this.#o===void 0){let t=this.#x-e;if(t<0){if(this.#g>0){let n=e-this.#g;if(n<this.#u)return this.#E(this.#u-n),!0}this.#i=this.#e?this.#r:0}else return this.#E(t),!0}return!1}#E(e){this.#s===void 0&&(this.#s=setTimeout(()=>{this.#L()},e))}#v(){this.#o&&(clearInterval(this.#o),this.#o=void 0)}#N(){this.#s&&(clearTimeout(this.#s),this.#s=void 0)}#y(){if(this.#t.size===0)return this.#v(),this.emit("empty"),this.#r===0&&(this.#N(),this.emit("idle")),!1;let e=!1;if(!this.#a){let t=!this.#P;if(this.#C&&this.#I){let n=this.#t.dequeue();this.#n||(this.#i++,this.#h()),this.emit("active"),this.#g=Date.now(),n(),t&&this.#_(),e=!0}}return e}#_(){this.#n||this.#o!==void 0||(this.#o=setInterval(()=>{this.#k()},this.#u),this.#x=Date.now()+this.#u)}#k(){this.#i===0&&this.#r===0&&this.#o&&this.#v(),this.#i=this.#e?this.#r:0,this.#w(),this.#h()}#w(){for(;this.#y(););}get concurrency(){return this.#l}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#l=e,this.#w()}setPriority(e,t){if(typeof t!="number"||!Number.isFinite(t))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${t}\` (${typeof t})`);this.#t.setPriority(e,t)}async add(e,t={}){return t.id??=(this.#S++).toString(),t={timeout:this.timeout,...t},new Promise((n,i)=>{let o=Symbol(`task-${t.id}`);this.#t.enqueue(async()=>{this.#r++,this.#f.set(o,{id:t.id,priority:t.priority??0,startTime:Date.now(),timeout:t.timeout});let s;try{try{t.signal?.throwIfAborted()}catch(h){throw this.#n||this.#i--,this.#f.delete(o),h}let a=e({signal:t.signal});if(t.timeout&&(a=cn(Promise.resolve(a),{milliseconds:t.timeout,message:`Task timed out after ${t.timeout}ms (queue has ${this.#r} running, ${this.#t.size} waiting)`})),t.signal){let{signal:h}=t;a=Promise.race([a,new Promise((l,f)=>{s=()=>{f(h.reason)},h.addEventListener("abort",s,{once:!0})})])}let c=await a;n(c),this.emit("completed",c)}catch(a){i(a),this.emit("error",a)}finally{s&&t.signal?.removeEventListener("abort",s),this.#f.delete(o),queueMicrotask(()=>{this.#T()})}},t),this.emit("add"),this.#y()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#a?(this.#a=!1,this.#w(),this):this}pause(){this.#a=!0}clear(){this.#t=new this.#b,this.#A()}async onEmpty(){this.#t.size!==0&&await this.#c("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#c("next",()=>this.#t.size<e)}async onIdle(){this.#r===0&&this.#t.size===0||await this.#c("idle")}async onPendingZero(){this.#r!==0&&await this.#c("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#c("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#c("rateLimitCleared")}async onError(){return new Promise((e,t)=>{let n=i=>{this.off("error",n),t(i)};this.on("error",n)})}async#c(e,t){return new Promise(n=>{let i=()=>{t&&!t()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#r}get isPaused(){return this.#a}#D(){this.#n||(this.on("add",()=>{this.#t.size>0&&this.#h()}),this.on("next",()=>{this.#h()}))}#h(){this.#n||this.#m||(this.#m=!0,queueMicrotask(()=>{this.#m=!1,this.#A()}))}#A(){let e=this.#p,t=!this.#n&&this.#i>=this.#d&&this.#t.size>0;t!==e&&(this.#p=t,this.emit(t?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#p}get isSaturated(){return this.#r===this.#l&&this.#t.size>0||this.isRateLimited&&this.#t.size>0}get runningTasks(){return[...this.#f.values()].map(e=>({...e}))}};function Et(r){let e=[X.A];return r==null?e:Array.isArray(r)?r.length===0?e:r:[r]}var ln={};I(ln,{base10:()=>Za});var Za=pe({prefix:"9",name:"base10",alphabet:"0123456789"});var fn={};I(fn,{base16:()=>ec,base16upper:()=>tc});var ec=C({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),tc=C({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var hn={};I(hn,{base2:()=>rc});var rc=C({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var dn={};I(dn,{base256emoji:()=>ac});var Qi=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}"),nc=Qi.reduce((r,e,t)=>(r[t]=e,r),[]),ic=Qi.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function oc(r){return r.reduce((e,t)=>(e+=nc[t],e),"")}function sc(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let i=ic[n];if(i==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(i)}return new Uint8Array(e)}var ac=Pe({prefix:"\u{1F680}",name:"base256emoji",encode:oc,decode:sc});var pn={};I(pn,{base36:()=>ae,base36upper:()=>cc});var ae=pe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),cc=pe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var mn={};I(mn,{base8:()=>uc});var uc=C({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var gn={};I(gn,{identity:()=>lc});var lc=Pe({prefix:"\0",name:"identity",encode:r=>$i(r),decode:r=>Ui(r)});var vt={};I(vt,{code:()=>yn,decode:()=>mc,encode:()=>pc,name:()=>dc});var fc=new TextEncoder,hc=new TextDecoder,dc="json",yn=512;function pc(r){return fc.encode(JSON.stringify(r))}function mc(r){return JSON.parse(hc.decode(r))}var _t={};I(_t,{code:()=>wn,decode:()=>wc,encode:()=>yc,name:()=>gc});var gc="raw",wn=85;function yc(r){return Y(r)}function wc(r){return Y(r)}var bn={};I(bn,{identity:()=>At});var xc=Xi,Ji=128,bc=127,Ec=~bc,vc=Math.pow(2,31);function Xi(r,e,t){e=e||[],t=t||0;for(var n=t;r>=vc;)e[t++]=r&255|Ji,r/=128;for(;r&Ec;)e[t++]=r&255|Ji,r>>>=7;return e[t]=r|0,Xi.bytes=t-n+1,e}var _c=xn,kc=128,Yi=127;function xn(r,n){var t=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a)throw xn.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&Yi)<<i:(s&Yi)*Math.pow(2,i),i+=7}while(s>=kc);return xn.bytes=o-n,t}var Ac=Math.pow(2,7),Sc=Math.pow(2,14),Cc=Math.pow(2,21),Ic=Math.pow(2,28),Tc=Math.pow(2,35),Lc=Math.pow(2,42),Pc=Math.pow(2,49),Nc=Math.pow(2,56),Dc=Math.pow(2,63),Rc=function(r){return r<Ac?1:r<Sc?2:r<Cc?3:r<Ic?4:r<Tc?5:r<Lc?6:r<Pc?7:r<Nc?8:r<Dc?9:10},Bc={encode:xc,decode:_c,encodingLength:Rc},Uc=Bc,Je=Uc;function Ye(r,e=0){return[Je.decode(r,e),Je.decode.bytes]}function Ne(r,e,t=0){return Je.encode(r,e,t),e}function De(r){return Je.encodingLength(r)}function Be(r,e){let t=e.byteLength,n=De(r),i=n+De(t),o=new Uint8Array(i+t);return Ne(r,o,0),Ne(t,o,n),o.set(e,i),new Re(r,t,e,o)}function Zi(r){let e=Y(r),[t,n]=Ye(e),[i,o]=Ye(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Re(t,i,s,e)}function eo(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Bi(r.bytes,t.bytes)}}var Re=class{code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};var to=0,$c="identity",ro=Y;function Fc(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return Be(to,ro(r))}var At={code:to,name:$c,encode:ro,digest:Fc};var _n={};I(_n,{sha256:()=>St,sha512:()=>Ct});var Oc=20;function vn({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:i}){return new En(r,e,t,n,i)}var En=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,i,o){this.name=e,this.code=t,this.encode=n,this.minDigestLength=i??Oc,this.maxDigestLength=o}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?no(n,this.code,t?.truncate):n.then(i=>no(i,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function no(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return Be(e,r)}function oo(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var St=vn({name:"sha2-256",code:18,encode:oo("SHA-256")}),Ct=vn({name:"sha2-512",code:19,encode:oo("SHA-512")});function so(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Mc(t,kn(r),e??H.encoder);default:return qc(t,kn(r),e??me.encoder)}}var ao=new WeakMap;function kn(r){let e=ao.get(r);if(e==null){let t=new Map;return ao.set(r,t),t}return e}var k=class r{code;version;multihash;bytes;"/";constructor(e,t,n,i){this.code=t,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}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!==Ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==jc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.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,n=Be(e,t);return r.createV1(this.code,n)}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 r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&eo(e.multihash,n.multihash)}toString(e){return so(this,e)}toJSON(){return{"/":so(this)}}link(){return this}[Symbol.toStringTag]="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 r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:i,multihash:o,bytes:s}=t;return new r(n,i,o,s??co(n,i,o.bytes))}else if(t[Vc]===!0){let{version:n,multihash:i,code:o}=t,s=Zi(i);return r.create(n,o,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Ze)throw new Error(`Version 0 CID must use dag-pb (code: ${Ze}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=co(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ze,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,i=Y(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=i.subarray(t.multihashSize-t.digestSize),s=new Re(t.multihashCode,t.digestSize,o,i);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,m]=Ye(e.subarray(t));return t+=m,f},i=n(),o=Ze;if(i===18?(i=0,t=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=t,a=n(),c=n(),h=t+c,l=h-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:h}}static parse(e,t){let[n,i]=zc(e,t),o=r.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return kn(o).set(n,e),o}};function zc(r,e){switch(r[0]){case"Q":{let t=e??H;return[H.prefix,t.decode(`${H.prefix}${r}`)]}case H.prefix:{let t=e??H;return[H.prefix,t.decode(r)]}case me.prefix:{let t=e??me;return[me.prefix,t.decode(r)]}case ae.prefix:{let t=e??ae;return[ae.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Mc(r,e,t){let{prefix:n}=t;if(n!==H.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return i}function qc(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let o=t.encode(r);return e.set(n,o),o}else return i}var Ze=112,jc=18;function co(r,e,t){let n=De(r),i=n+De(e),o=new Uint8Array(i+t.byteLength);return Ne(r,o,0),Ne(e,o,n),o.set(t,i),o}var Vc=Symbol.for("@ipld/js-cid/CID");var An={...gn,...hn,...mn,...ln,...fn,...en,...pn,...tn,...rn,...dn},hh={..._n,...bn};function uo(r=0){return new Uint8Array(r)}function It(r=0){return new Uint8Array(r)}function fo(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var lo=fo("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Sn=fo("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=It(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Kc={utf8:lo,"utf-8":lo,hex:An.base16,latin1:Sn,ascii:Sn,binary:Sn,...An},Tt=Kc;function ye(r,e="utf8"){let t=Tt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Cn=60;function Lt(r){return{Status:r.Status??0,TC:r.TC??r.flag_tc??!1,RD:r.RD??r.flag_rd??!1,RA:r.RA??r.flag_ra??!1,AD:r.AD??r.flag_ad??!1,CD:r.CD??r.flag_cd??!1,Question:(r.Question??r.questions??[]).map(e=>({name:e.name,type:X[e.type]})),Answer:(r.Answer??r.answers??[]).map(e=>({name:e.name,type:X[e.type],TTL:e.TTL??e.ttl??Cn,data:e.data instanceof Uint8Array?ye(e.data):e.data}))}}var Hc=4;function In(r,e={}){let t=new Qe({concurrency:e.queryConcurrency??Hc});return async(n,i={})=>{let o=new URLSearchParams;o.set("name",n),Et(i.types).forEach(a=>{o.append("type",X[a])}),i.onProgress?.(new v("dns:query",n));let s=await t.add(async()=>{let a=await fetch(`${r}?${o}`,{headers:{accept:"application/dns-json"},signal:i?.signal});if(a.status!==200)throw new Error(`Unexpected HTTP status: ${a.status} - ${a.statusText}`);let c=Lt(await a.json());return i.onProgress?.(new v("dns:response",c)),c},{signal:i.signal});if(s==null)throw new Error("No DNS response received");return s}}function ho(){return[In("https://cloudflare-dns.com/dns-query"),In("https://dns.google/resolve")]}var go=Pi(mo(),1);var Tn=class{lru;constructor(e){this.lru=(0,go.default)(e)}get(e,t){let n=!0,i=[];for(let o of t){let s=this.getAnswers(e,o);if(s.length===0){n=!1;break}i.push(...s)}if(n)return Lt({answers:i})}getAnswers(e,t){let n=`${e.toLowerCase()}-${t}`,i=this.lru.get(n);if(i!=null){let o=i.filter(s=>s.expires>Date.now()).map(({expires:s,value:a})=>({...a,TTL:Math.round((s-Date.now())/1e3),type:X[a.type]}));return o.length===0&&this.lru.remove(n),o}return[]}add(e,t){let n=`${e.toLowerCase()}-${t.type}`,i=this.lru.get(n)??[];i.push({expires:Date.now()+(t.TTL??Cn)*1e3,value:t}),this.lru.set(n,i)}remove(e,t){let n=`${e.toLowerCase()}-${t}`;this.lru.remove(n)}clear(){this.lru.clear()}};function yo(r){return new Tn(r)}var Wc=1e3,Pt=class{resolvers;cache;constructor(e){this.resolvers={},this.cache=yo(e.cacheSize??Wc),Object.entries(e.resolvers??{}).forEach(([t,n])=>{Array.isArray(n)||(n=[n]),t.endsWith(".")||(t=`${t}.`),this.resolvers[t]=n}),this.resolvers["."]==null&&(this.resolvers["."]=ho())}async query(e,t={}){let n=Et(t.types),i=t.cached!==!1?this.cache.get(e,n):void 0;if(i!=null)return t.onProgress?.(new v("dns:cache",i)),i;let o=`${e.split(".").pop()}.`,s=(this.resolvers[o]??this.resolvers["."]).sort(()=>Math.random()>.5?-1:1),a=[];for(let c of s){if(t.signal?.aborted===!0)break;try{let h=await c(e,{...t,types:n});for(let l of h.Answer)this.cache.add(e,l);return h}catch(h){a.push(h),t.onProgress?.(new v("dns:error",h))}}throw new xt(a,`DNS lookup of ${e} ${n} failed`)}};var X;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(X||(X={}));function wo(r={}){return new Pt(r)}function Gc(r){return r[Symbol.asyncIterator]!=null}function Qc(r){if(Gc(r))return(async()=>{for await(let e of r);})();for(let e of r);}var xo=Qc;function ve(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Ln(r,e){e==null&&(e=r.reduce((i,o)=>i+o.length,0));let t=It(e),n=0;for(let i of r)t.set(i,n),n+=i.length;return t}function $(r,e="utf8"){let t=Tt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var Pn={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},bo={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Eo=new globalThis.TextEncoder;function Jc(r,e){let t=Pn[e],n=bo[e];for(let i=0;i<r.length;i++)n^=BigInt(r[i]),n=BigInt.asUintN(e,n*t);return n}function Yc(r,e,t){if(t.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Pn[e],i=bo[e],o=r;for(;o.length>0;){let s=Eo.encodeInto(o,t);o=o.slice(s.read);for(let a=0;a<s.written;a++)i^=BigInt(t[a]),i=BigInt.asUintN(e,i*n)}return i}function Nn(r,{size:e=32,utf8Buffer:t}={}){if(!Pn[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(t)return Yc(r,e,t);r=Eo.encode(r)}return Jc(r,e)}var et={hash:r=>Number(Nn(r,{size:32})),hashV:(r,e)=>Xc(et.hash(r,e))};function Xc(r){let e=r.toString(16);return e.length%2===1&&(e=`0${e}`),$(e,"base16")}var Dn=64,Z=class{fp;h;seed;constructor(e,t,n,i=2){if(i>Dn)throw new TypeError("Invalid Fingerprint Size");let o=t.hashV(e,n),s=uo(i);for(let a=0;a<s.length;a++)s[a]=o[a];s.length===0&&(s[0]=7),this.fp=s,this.h=t,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?ve(this.fp,e.fp):!1}};function _e(r,e){return Math.floor(Math.random()*(e-r))+r}var ke=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof Z))throw new TypeError("Invalid Fingerprint");return this.contents.some(t=>e.equals(t))}add(e){if(!(e instanceof Z))throw new TypeError("Invalid Fingerprint");for(let t=0;t<this.contents.length;t++)if(this.contents[t]==null)return this.contents[t]=e,!0;return!0}swap(e){if(!(e instanceof Z))throw new TypeError("Invalid Fingerprint");let t=_e(0,this.contents.length-1),n=this.contents[t];return this.contents[t]=e,n}remove(e){if(!(e instanceof Z))throw new TypeError("Invalid Fingerprint");let t=this.contents.findIndex(n=>e.equals(n));return t>-1?(this.contents[t]=null,!0):!1}};var Zc=500,tt=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??et,this.seed=e.seed??_e(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=$(e));let t=new Z(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,i=(n^t.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new ke(this.bucketSize)),this.buckets[i]==null&&(this.buckets[i]=new ke(this.bucketSize)),this.buckets[n].add(t)||this.buckets[i].add(t))return this.count++,!0;let o=[n,i],s=o[_e(0,o.length-1)];this.buckets[s]==null&&(this.buckets[s]=new ke(this.bucketSize));for(let a=0;a<Zc;a++){let c=this.buckets[s].swap(t);if(c!=null&&(s=(s^c.hash())%this.filterSize,this.buckets[s]==null&&(this.buckets[s]=new ke(this.bucketSize)),this.buckets[s].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=$(e));let t=new Z(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,i=this.buckets[n]?.has(t)??!1;if(i)return i;let o=(n^t.hash())%this.filterSize;return this.buckets[o]?.has(t)??!1}remove(e){typeof e=="string"&&(e=$(e));let t=new Z(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,i=this.buckets[n]?.remove(t)??!1;if(i)return this.count--,i;let o=(n^t.hash())%this.filterSize,s=this.buckets[o]?.remove(t)??!1;return s&&this.count--,s}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},eu={1:.5,2:.84,4:.95,8:.98};function tu(r=.001){return r>.002?2:r>1e-5?4:8}function vo(r,e=.001){let t=tu(e),n=eu[t],i=Math.round(r/n),o=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*t)),Dn);return{filterSize:i,bucketSize:t,fingerprintSize:o}}var Nt=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??et,this.seed=e.seed??_e(0,Math.pow(2,10)),this.filterSeries=[new tt({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=$(e)),this.has(e))return!0;let t=this.filterSeries.find(n=>n.reliable);if(t==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);t=new tt({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(t)}return t.add(e)}has(e){typeof e=="string"&&(e=$(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=$(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,t)=>e+t.count,0)}};function Rn(r,e=.001,t){return new Nt({...vo(r,e),...t??{}})}function F(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Dt=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)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}},Ue=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Dt(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 Dt(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Bn=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Rt(r={}){return ru(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function ru(r,e){e=e??{};let t=e.onEnd,n=new Ue,i,o,s,a=F(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((w,b)=>{o=A=>{o=null,n.push(A);try{w(r(n))}catch(S){b(S)}return i}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=F()})}},h=w=>o!=null?o(w):(n.push(w),i),l=w=>(n=new Ue,o!=null?o({error:w}):(n.push({error:w}),i)),f=w=>{if(s)return i;if(e?.objectMode!==!0&&w?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return h({done:!1,value:w})},m=w=>s?i:(s=!0,w!=null?l(w):h({done:!0})),y=()=>(n=new Ue,m(),{done:!0}),x=w=>(m(w),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:y,throw:x,push:f,end:m,get readableLength(){return n.size},onEmpty:async w=>{let b=w?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let A,S;b!=null&&(A=new Promise((D,L)=>{S=()=>{L(new Bn)},b.addEventListener("abort",S)}));try{await Promise.race([a.promise,A])}finally{S!=null&&b!=null&&b?.removeEventListener("abort",S)}}},t==null)return i;let _=i;return i={[Symbol.asyncIterator](){return this},next(){return _.next()},throw(w){return _.throw(w),t!=null&&(t(w),t=void 0),{done:!0}},return(){return _.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(w){return _.end(w),t!=null&&(t(w),t=void 0),i},get readableLength(){return _.readableLength},onEmpty:w=>_.onEmpty(w)},i}var Un=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},$n=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},_o=r=>globalThis.DOMException===void 0?new $n(r):new DOMException(r),ko=r=>{let e=r.reason===void 0?_o("This operation was aborted."):r.reason;return e instanceof Error?e:_o(e)};function Fn(r,e){let{milliseconds:t,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout}}=e,s,a,h=new Promise((l,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:y}=e;y.aborted&&f(ko(y)),a=()=>{f(ko(y))},y.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(l,f);return}let m=new Un;s=o.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(y){f(y)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?l():i instanceof Error?f(i):(m.message=i??`Promise timed out after ${t} milliseconds`,f(m))},t),(async()=>{try{l(await r)}catch(y){f(y)}})()}).finally(()=>{h.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return h.clear=()=>{o.clearTimeout.call(void 0,s),s=void 0},h}var nu=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function iu(r,e,t){let n,i=new Promise((o,s)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:h,removeListener:l}=nu(r),f=async(...y)=>{let x=t.multiArgs?y:y[0];if(t.filter)try{if(!await t.filter(x))return}catch(_){n(),s(_);return}c.push(x),t.count===c.length&&(n(),o(c))},m=(...y)=>{n(),s(t.rejectionMultiArgs?y:y[0])};n=()=>{for(let y of a)l(y,f);for(let y of t.rejectionEvents)a.includes(y)||l(y,m)};for(let y of a)h(y,f);for(let y of t.rejectionEvents)a.includes(y)||h(y,m);t.signal&&t.signal.addEventListener("abort",()=>{m(t.signal.reason)},{once:!0}),t.resolveImmediately&&o(c)});if(i.cancel=n,typeof t.timeout=="number"){let o=Fn(i,{milliseconds:t.timeout});return o.cancel=()=>{n(),o.clear()},o}return i}function Bt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=iu(r,e,t),i=n.then(o=>o[0]);return i.cancel=n.cancel,i}function On(r,e){let t,n=function(){let i=function(){t=void 0,r()};clearTimeout(t),t=setTimeout(i,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(t)},n}var Ut=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function ou(r){return r.reason}async function rt(r,e,t){if(e==null)return r;let n=t?.translateError??ou;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let i;try{return await Promise.race([r,new Promise((o,s)=>{i=()=>{s(n(e))},e.addEventListener("abort",i)})])}finally{i!=null&&e.removeEventListener("abort",i)}}var $t=class{deferred;signal;constructor(e){this.signal=e,this.deferred=F(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new J)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function su(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Ft=class{id;fn;options;recipients;status;timeline;controller;constructor(e,t){this.id=su(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new J),this.cleanup())}async join(e={}){let t=new $t(e.signal);return this.recipients.push(t),e.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await rt(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var O=class extends K{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=On(this.emitEmpty.bind(this),1),this.emitIdle=On(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,t){if(t?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Ut;let n=new Ft(e,t);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(t).then(i=>(this.safeDispatchEvent("completed",{detail:i}),this.safeDispatchEvent("success",{detail:{job:n,result:i}}),i)).catch(i=>{if(n.status==="queued"){for(let o=0;o<this.queue.length;o++)if(this.queue[o]===n){this.queue.splice(o,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:i}}),i})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new J)}),this.clear()}async onEmpty(e){this.size!==0&&await Bt(this,"empty",e)}async onSizeLessThan(e,t){this.size<e||await Bt(this,"next",{...t,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Bt(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=Rt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},i=c=>{c.detail!=null&&t.push(c.detail)},o=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new J("Queue aborted"))};this.addEventListener("completed",i),this.addEventListener("failure",o),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",i),this.removeEventListener("failure",o),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function ie(r){let e=new globalThis.AbortController;function t(){e.abort();for(let o of r)o?.removeEventListener!=null&&o.removeEventListener("abort",t)}for(let o of r){if(o?.aborted===!0){t();break}o?.addEventListener!=null&&o.addEventListener("abort",t)}function n(){for(let o of r)o?.removeEventListener!=null&&o.removeEventListener("abort",t)}let i=e.signal;return i.clear=n,i}var Ot=class extends Error{type;code;constructor(e,t,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=t??"ABORT_ERR"}};async function Ao(r,e,t){if(e==null)return r;if(e.aborted)return r.catch(()=>{}),Promise.reject(new Ot(t?.errorMessage,t?.errorCode,t?.errorName));let n,i=new Ot(t?.errorMessage,t?.errorCode,t?.errorName);try{return await Promise.race([r,new Promise((o,s)=>{n=()=>{s(i)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var zn=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=F(),this.haveNext=F()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=F(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=F(),await Ao(this.readNext.promise,t?.signal,t)}};function So(){return new zn}function au(r){return r[Symbol.asyncIterator]!=null}async function cu(r,e,t){try{await Promise.all(r.map(async n=>{for await(let i of n)await e.push(i,{signal:t}),t.throwIfAborted()})),await e.end(void 0,{signal:t})}catch(n){await e.end(n,{signal:t}).catch(()=>{})}}async function*uu(r){let e=new AbortController,t=So();cu(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*lu(r){for(let e of r)yield*e}function fu(...r){let e=[];for(let t of r)au(t)||e.push(t);return e.length===r.length?lu(e):uu(r)}var zt=fu;var hu=["string","number","bigint","symbol"],du=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Co(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(hu.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(pu(r))return"Buffer";let t=mu(r);return t||"Object"}function pu(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function mu(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(du.includes(e))return e}var u=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};u.uint=new u(0,"uint",!0);u.negint=new u(1,"negint",!0);u.bytes=new u(2,"bytes",!0);u.string=new u(3,"string",!0);u.array=new u(4,"array",!1);u.map=new u(5,"map",!1);u.tag=new u(6,"tag",!1);u.float=new u(7,"float",!0);u.false=new u(7,"false",!0);u.true=new u(7,"true",!0);u.null=new u(7,"null",!0);u.undefined=new u(7,"undefined",!0);u.break=new u(7,"break",!0);var d=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var $e=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",gu=new TextDecoder,yu=new TextEncoder;function Mt(r){return $e&&globalThis.Buffer.isBuffer(r)}function nt(r){return r instanceof Uint8Array?Mt(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var Po=$e?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):To(r,e,t):(r,e,t)=>t-e>64?gu.decode(r.subarray(e,t)):To(r,e,t),qt=$e?r=>r.length>64?globalThis.Buffer.from(r):Io(r):r=>r.length>64?yu.encode(r):Io(r),oe=r=>Uint8Array.from(r),Fe=$e?(r,e,t)=>Mt(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),No=$e?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),nt(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let i of r)n+i.length>t.length&&(i=i.subarray(0,t.length-n)),t.set(i,n),n+=i.length;return t},Do=$e?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function jt(r,e){if(Mt(r)&&Mt(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function Io(r){let e=[],t=0;for(let n=0;n<r.length;n++){let i=r.charCodeAt(n);i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128)}return e}function To(r,e,t){let n=[];for(;e<t;){let i=r[e],o=null,s=i>239?4:i>223?3:i>191?2:1;if(e+s<=t){let a,c,h,l;switch(s){case 1:i<128&&(o=i);break;case 2:a=r[e+1],(a&192)===128&&(l=(i&31)<<6|a&63,l>127&&(o=l));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(l=(i&15)<<12|(a&63)<<6|c&63,l>2047&&(l<55296||l>57343)&&(o=l));break;case 4:a=r[e+1],c=r[e+2],h=r[e+3],(a&192)===128&&(c&192)===128&&(h&192)===128&&(l=(i&15)<<18|(a&63)<<12|(c&63)<<6|h&63,l>65535&&l<1114112&&(o=l))}}o===null?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|o&1023),n.push(o),e+=s}return Mn(n)}var Lo=4096;function Mn(r){let e=r.length;if(e<=Lo)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Lo));return t}var wu=256,it=class{constructor(e=wu){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=t.length-(this.maxCursor-this.cursor)-1;t.set(e,i)}else{if(t){let i=t.length-(this.maxCursor-this.cursor)-1;i<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Do(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=Fe(n,0,this.cursor)}else t=No(this.chunks,this.cursor);return e&&this.reset(),t}};var g="CBOR decode error:",ce="CBOR encode error:",ot=[];ot[23]=1;ot[24]=2;ot[25]=3;ot[26]=5;ot[27]=9;function ue(r,e,t){if(r.length-e<t)throw new Error(`${g} not enough data for type`)}var T=[24,256,65536,4294967296,BigInt("18446744073709551616")];function z(r,e,t){ue(r,e,1);let n=r[e];if(t.strict===!0&&n<T[0])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function M(r,e,t){ue(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<T[1])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function q(r,e,t){ue(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<T[2])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function j(r,e,t){ue(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],i=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(t.strict===!0&&o<T[3])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(t.allowBigInt===!0)return o;throw new Error(`${g} integers outside of the safe integer range are not supported`)}function Ro(r,e,t,n){return new d(u.uint,z(r,e+1,n),2)}function Bo(r,e,t,n){return new d(u.uint,M(r,e+1,n),3)}function Uo(r,e,t,n){return new d(u.uint,q(r,e+1,n),5)}function $o(r,e,t,n){return new d(u.uint,j(r,e+1,n),9)}function W(r,e){return P(r,0,e.value)}function P(r,e,t){if(t<T[0]){let n=Number(t);r.push([e|n])}else if(t<T[1]){let n=Number(t);r.push([e|24,n])}else if(t<T[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<T[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<T[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,r.push(i)}else throw new Error(`${g} encountered BigInt larger than allowable range`)}}W.encodedSize=function(e){return P.encodedSize(e.value)};P.encodedSize=function(e){return e<T[0]?1:e<T[1]?2:e<T[2]?3:e<T[3]?5:9};W.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function Fo(r,e,t,n){return new d(u.negint,-1-z(r,e+1,n),2)}function Oo(r,e,t,n){return new d(u.negint,-1-M(r,e+1,n),3)}function zo(r,e,t,n){return new d(u.negint,-1-q(r,e+1,n),5)}var qn=BigInt(-1),Mo=BigInt(1);function qo(r,e,t,n){let i=j(r,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new d(u.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${g} integers outside of the safe integer range are not supported`);return new d(u.negint,qn-BigInt(i),9)}function Vt(r,e){let t=e.value,n=typeof t=="bigint"?t*qn-Mo:t*-1-1;P(r,e.type.majorEncoded,n)}Vt.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*qn-Mo:t*-1-1;return n<T[0]?1:n<T[1]?2:n<T[2]?3:n<T[3]?5:9};Vt.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function st(r,e,t,n){ue(r,e,t+n);let i=Fe(r,e+t,e+t+n);return new d(u.bytes,i,t+n)}function jo(r,e,t,n){return st(r,e,1,t)}function Vo(r,e,t,n){return st(r,e,2,z(r,e+1,n))}function Ko(r,e,t,n){return st(r,e,3,M(r,e+1,n))}function Ho(r,e,t,n){return st(r,e,5,q(r,e+1,n))}function Wo(r,e,t,n){let i=j(r,e+1,n);if(typeof i=="bigint")throw new Error(`${g} 64-bit integer bytes lengths not supported`);return st(r,e,9,i)}function Kt(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===u.string?qt(r.value):r.value),r.encodedBytes}function Oe(r,e){let t=Kt(e);P(r,e.type.majorEncoded,t.length),r.push(t)}Oe.encodedSize=function(e){let t=Kt(e);return P.encodedSize(t.length)+t.length};Oe.compareTokens=function(e,t){return bu(Kt(e),Kt(t))};function bu(r,e){return r.length<e.length?-1:r.length>e.length?1:jt(r,e)}function at(r,e,t,n,i){let o=t+n;ue(r,e,o);let s=new d(u.string,Po(r,e+t,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=Fe(r,e+t,e+o)),s}function Go(r,e,t,n){return at(r,e,1,t,n)}function Qo(r,e,t,n){return at(r,e,2,z(r,e+1,n),n)}function Jo(r,e,t,n){return at(r,e,3,M(r,e+1,n),n)}function Yo(r,e,t,n){return at(r,e,5,q(r,e+1,n),n)}function Xo(r,e,t,n){let i=j(r,e+1,n);if(typeof i=="bigint")throw new Error(`${g} 64-bit integer string lengths not supported`);return at(r,e,9,i,n)}var Zo=Oe;function ze(r,e,t,n){return new d(u.array,n,t)}function es(r,e,t,n){return ze(r,e,1,t)}function ts(r,e,t,n){return ze(r,e,2,z(r,e+1,n))}function rs(r,e,t,n){return ze(r,e,3,M(r,e+1,n))}function ns(r,e,t,n){return ze(r,e,5,q(r,e+1,n))}function is(r,e,t,n){let i=j(r,e+1,n);if(typeof i=="bigint")throw new Error(`${g} 64-bit integer array lengths not supported`);return ze(r,e,9,i)}function os(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return ze(r,e,1,1/0)}function Ht(r,e){P(r,u.array.majorEncoded,e.value)}Ht.compareTokens=W.compareTokens;Ht.encodedSize=function(e){return P.encodedSize(e.value)};function Me(r,e,t,n){return new d(u.map,n,t)}function ss(r,e,t,n){return Me(r,e,1,t)}function as(r,e,t,n){return Me(r,e,2,z(r,e+1,n))}function cs(r,e,t,n){return Me(r,e,3,M(r,e+1,n))}function us(r,e,t,n){return Me(r,e,5,q(r,e+1,n))}function ls(r,e,t,n){let i=j(r,e+1,n);if(typeof i=="bigint")throw new Error(`${g} 64-bit integer map lengths not supported`);return Me(r,e,9,i)}function fs(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return Me(r,e,1,1/0)}function Wt(r,e){P(r,u.map.majorEncoded,e.value)}Wt.compareTokens=W.compareTokens;Wt.encodedSize=function(e){return P.encodedSize(e.value)};function hs(r,e,t,n){return new d(u.tag,t,1)}function ds(r,e,t,n){return new d(u.tag,z(r,e+1,n),2)}function ps(r,e,t,n){return new d(u.tag,M(r,e+1,n),3)}function ms(r,e,t,n){return new d(u.tag,q(r,e+1,n),5)}function gs(r,e,t,n){return new d(u.tag,j(r,e+1,n),9)}function Gt(r,e){P(r,u.tag.majorEncoded,e.value)}Gt.compareTokens=W.compareTokens;Gt.encodedSize=function(e){return P.encodedSize(e.value)};var Su=20,Cu=21,Iu=22,Tu=23;function ys(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${g} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new d(u.null,null,1):new d(u.undefined,void 0,1)}function ws(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return new d(u.break,void 0,1)}function jn(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${g} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${g} Infinity values are not supported`)}return new d(u.float,r,e)}function xs(r,e,t,n){return jn(Vn(r,e+1),3,n)}function bs(r,e,t,n){return jn(Kn(r,e+1),5,n)}function Es(r,e,t,n){return jn(As(r,e+1),9,n)}function Qt(r,e,t){let n=e.value;if(n===!1)r.push([u.float.majorEncoded|Su]);else if(n===!0)r.push([u.float.majorEncoded|Cu]);else if(n===null)r.push([u.float.majorEncoded|Iu]);else if(n===void 0)r.push([u.float.majorEncoded|Tu]);else{let i,o=!1;(!t||t.float64!==!0)&&(_s(n),i=Vn(ee,1),n===i||Number.isNaN(n)?(ee[0]=249,r.push(ee.slice(0,3)),o=!0):(ks(n),i=Kn(ee,1),n===i&&(ee[0]=250,r.push(ee.slice(0,5)),o=!0))),o||(Lu(n),i=As(ee,1),ee[0]=251,r.push(ee.slice(0,9)))}}Qt.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){_s(n);let i=Vn(ee,1);if(n===i||Number.isNaN(n))return 3;if(ks(n),i=Kn(ee,1),n===i)return 5}return 9};var vs=new ArrayBuffer(9),G=new DataView(vs,1),ee=new Uint8Array(vs,0);function _s(r){if(r===1/0)G.setUint16(0,31744,!1);else if(r===-1/0)G.setUint16(0,64512,!1);else if(Number.isNaN(r))G.setUint16(0,32256,!1);else{G.setFloat32(0,r);let e=G.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)G.setUint16(0,31744,!1);else if(t===0)G.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let i=t-127;i<-24?G.setUint16(0,0):i<-14?G.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):G.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function Vn(r,e){if(r.length-e<2)throw new Error(`${g} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,i=t&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,t&32768?-o:o}function ks(r){G.setFloat32(0,r,!1)}function Kn(r,e){if(r.length-e<4)throw new Error(`${g} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function Lu(r){G.setFloat64(0,r,!1)}function As(r,e){if(r.length-e<8)throw new Error(`${g} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}Qt.compareTokens=W.compareTokens;function E(r,e,t){throw new Error(`${g} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function Jt(r){return()=>{throw new Error(`${g} ${r}`)}}var p=[];for(let r=0;r<=23;r++)p[r]=E;p[24]=Ro;p[25]=Bo;p[26]=Uo;p[27]=$o;p[28]=E;p[29]=E;p[30]=E;p[31]=E;for(let r=32;r<=55;r++)p[r]=E;p[56]=Fo;p[57]=Oo;p[58]=zo;p[59]=qo;p[60]=E;p[61]=E;p[62]=E;p[63]=E;for(let r=64;r<=87;r++)p[r]=jo;p[88]=Vo;p[89]=Ko;p[90]=Ho;p[91]=Wo;p[92]=E;p[93]=E;p[94]=E;p[95]=Jt("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)p[r]=Go;p[120]=Qo;p[121]=Jo;p[122]=Yo;p[123]=Xo;p[124]=E;p[125]=E;p[126]=E;p[127]=Jt("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)p[r]=es;p[152]=ts;p[153]=rs;p[154]=ns;p[155]=is;p[156]=E;p[157]=E;p[158]=E;p[159]=os;for(let r=160;r<=183;r++)p[r]=ss;p[184]=as;p[185]=cs;p[186]=us;p[187]=ls;p[188]=E;p[189]=E;p[190]=E;p[191]=fs;for(let r=192;r<=215;r++)p[r]=hs;p[216]=ds;p[217]=ps;p[218]=ms;p[219]=gs;p[220]=E;p[221]=E;p[222]=E;p[223]=E;for(let r=224;r<=243;r++)p[r]=Jt("simple values are not supported");p[244]=E;p[245]=E;p[246]=E;p[247]=ys;p[248]=Jt("simple values are not supported");p[249]=xs;p[250]=bs;p[251]=Es;p[252]=E;p[253]=E;p[254]=E;p[255]=ws;var te=[];for(let r=0;r<24;r++)te[r]=new d(u.uint,r,1);for(let r=-1;r>=-24;r--)te[31-r]=new d(u.negint,r,1);te[64]=new d(u.bytes,new Uint8Array(0),1);te[96]=new d(u.string,"",1);te[128]=new d(u.array,0,1);te[160]=new d(u.map,0,1);te[244]=new d(u.false,!1,1);te[245]=new d(u.true,!0,1);te[246]=new d(u.null,null,1);function Hn(r){switch(r.type){case u.false:return oe([244]);case u.true:return oe([245]);case u.null:return oe([246]);case u.bytes:return r.value.length?void 0:oe([64]);case u.string:return r.value===""?oe([96]):void 0;case u.array:return r.value===0?oe([128]):void 0;case u.map:return r.value===0?oe([160]):void 0;case u.uint:return r.value<24?oe([Number(r.value)]):void 0;case u.negint:if(r.value>=-24)return oe([31-Number(r.value)])}}var Nu={float64:!1,mapSorter:Bu,quickEncodeToken:Hn},Cs=Object.freeze({float64:!0,mapSorter:Uu,quickEncodeToken:Hn});function Du(){let r=[];return r[u.uint.major]=W,r[u.negint.major]=Vt,r[u.bytes.major]=Oe,r[u.string.major]=Zo,r[u.array.major]=Ht,r[u.map.major]=Wt,r[u.tag.major]=Gt,r[u.float.major]=Qt,r}var Gn=Du(),Wn=new it,Xt=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${ce} object contains circular references`);return new r(t,e)}},we={null:new d(u.null,null),undefined:new d(u.undefined,void 0),true:new d(u.true,!0),false:new d(u.false,!1),emptyArray:new d(u.array,0),emptyMap:new d(u.map,0)},xe={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new d(u.float,r):r>=0?new d(u.uint,r):new d(u.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new d(u.uint,r):new d(u.negint,r)},Uint8Array(r,e,t,n){return new d(u.bytes,r)},string(r,e,t,n){return new d(u.string,r)},boolean(r,e,t,n){return r?we.true:we.false},null(r,e,t,n){return we.null},undefined(r,e,t,n){return we.undefined},ArrayBuffer(r,e,t,n){return new d(u.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new d(u.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[we.emptyArray,new d(u.break)]:we.emptyArray;n=Xt.createCheck(n,r);let i=[],o=0;for(let s of r)i[o++]=Yt(s,t,n);return t.addBreakTokens?[new d(u.array,r.length),i,new d(u.break)]:[new d(u.array,r.length),i]},Object(r,e,t,n){let i=e!=="Object",o=i?r.keys():Object.keys(r),s=i?r.size:o.length;if(!s)return t.addBreakTokens===!0?[we.emptyMap,new d(u.break)]:we.emptyMap;n=Xt.createCheck(n,r);let a=[],c=0;for(let h of o)a[c++]=[Yt(h,t,n),Yt(i?r.get(h):r[h],t,n)];return Ru(a,t),t.addBreakTokens?[new d(u.map,s),a,new d(u.break)]:[new d(u.map,s),a]}};xe.Map=xe.Object;xe.Buffer=xe.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))xe[`${r}Array`]=xe.DataView;function Yt(r,e={},t){let n=Co(r),i=e&&e.typeEncoders&&e.typeEncoders[n]||xe[n];if(typeof i=="function"){let s=i(r,n,e,t);if(s!=null)return s}let o=xe[n];if(!o)throw new Error(`${ce} unsupported type: ${n}`);return o(r,n,e,t)}function Ru(r,e){e.mapSorter&&r.sort(e.mapSorter)}function Bu(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let i=t.type.major,o=Gn[i].compareTokens(t,n);return o===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),o}function Uu(r,e){if(r[0]instanceof d&&e[0]instanceof d){let t=r[0],n=e[0];return t._keyBytes||(t._keyBytes=Ss(t.value)),n._keyBytes||(n._keyBytes=Ss(n.value)),jt(t._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Ss(r){return Zt(r,Gn,Cs)}function Is(r,e,t,n){if(Array.isArray(e))for(let i of e)Is(r,i,t,n);else t[e.type.major](r,e,n)}function Zt(r,e,t){let n=Yt(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let i=t.quickEncodeToken(n);if(i)return i;let o=e[n.type.major];if(o.encodedSize){let s=o.encodedSize(n,t),a=new it(s);if(o(a,n,t),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return nt(a.chunks[0])}}return Wn.reset(),Is(Wn,n,e,t),Wn.toBytes(!0)}function Se(r,e){return e=Object.assign({},Nu,e),Zt(r,Gn,e)}var $u={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},er=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=te[e];if(t===void 0){let n=p[e];if(!n)throw new Error(`${g} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;t=n(this.data,this._pos,i,this.options)}return this._pos+=t.encodedLength,t}},ct=Symbol.for("DONE"),tr=Symbol.for("BREAK");function Fu(r,e,t){let n=[];for(let i=0;i<r.value;i++){let o=qe(e,t);if(o===tr){if(r.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed array`)}if(o===ct)throw new Error(`${g} found array but not enough entries (got ${i}, expected ${r.value})`);n[i]=o}return n}function Ou(r,e,t){let n=t.useMaps===!0,i=n?void 0:{},o=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=qe(e,t);if(a===tr){if(r.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(a===ct)throw new Error(`${g} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${g} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&o.has(a)||!n&&a in i))throw new Error(`${g} found repeat map key "${a}"`);let c=qe(e,t);if(c===ct)throw new Error(`${g} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?o.set(a,c):i[a]=c}return n?o:i}function qe(r,e){if(r.done())return ct;let t=r.next();if(t.type===u.break)return tr;if(t.type.terminal)return t.value;if(t.type===u.array)return Fu(t,r,e);if(t.type===u.map)return Ou(t,r,e);if(t.type===u.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=qe(r,e);return e.tags[t.value](n)}throw new Error(`${g} tag not supported (${t.value})`)}throw new Error("unsupported")}function Qn(r,e){if(!(r instanceof Uint8Array))throw new Error(`${g} data to decode must be a Uint8Array`);e=Object.assign({},$u,e);let t=e.tokenizer||new er(r,e),n=qe(t,e);if(n===ct)throw new Error(`${g} did not find any content to decode`);if(n===tr)throw new Error(`${g} got unexpected break`);return[n,r.subarray(t.pos())]}function re(r,e){let[t,n]=Qn(r,e);if(n.length>0)throw new Error(`${g} too many terminals, data makes no sense`);return t}var rr=class extends O{has(e){return this.find(e)!=null}find(e){return this.queue.find(t=>e.equals(t.options.peerId))}};var le="/",Ls=new TextEncoder().encode(le),nr=Ls[0],fe=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=$(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==nr)throw new Error("Invalid key")}toString(e="utf8"){return ye(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(le))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Ls),this._buf[0]!==nr){let e=new Uint8Array(this._buf.byteLength+1);e.fill(nr,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===nr;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let i=0;i<t.length;i++){if(n.length<i+1)return!1;let o=t[i],s=n[i];if(o<s)return!0;if(o>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(le).slice(1)}type(){return zu(this.baseNamespace())}name(){return Mu(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(le)||(e+=le),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(le):new r(e.slice(0,-1).join(le))}child(e){return this.toString()===le?e:e.toString()===le?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...qu(e.map(t=>t.namespaces()))])}};function zu(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Mu(r){let e=r.split(":");return e[e.length-1]}function qu(r){return[].concat(...r)}function ju(r){return r[Symbol.asyncIterator]!=null}function Vu(r){if(ju(r))return(async()=>{let n=new Uint8Array(0);for await(let i of r)n=Ln([n,i],n.length+i.length);return n})();let e=[],t=0;for(let n of r)e.push(n),t+=n.byteLength;return Ln(e,t)}var ir=Vu;function or({enumerable:r=!0,configurable:e=!1}={}){return{enumerable:r,configurable:e,writable:!1}}function*Ku(r,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[t,n]of e.entries()){let i=[...r,t],o=k.asCID(n);o!=null?yield[i.join("/"),o]:typeof n=="object"&&(yield*Jn(n,i))}else{let t=k.asCID(e);t!=null?yield[r.join("/"),t]:yield*Jn(e,r)}}function*Jn(r,e){if(r==null||r instanceof Uint8Array)return;let t=k.asCID(r);t!=null&&(yield[e.join("/"),t]);for(let[n,i]of Object.entries(r)){let o=[...e,n];yield*Ku(o,i)}}function*Hu(r,e){if(Array.isArray(e))for(let[t,n]of e.entries()){let i=[...r,t];yield i.join("/"),typeof n=="object"&&k.asCID(n)==null&&(yield*Yn(n,i))}else yield*Yn(e,r)}function*Yn(r,e){if(!(r==null||typeof r!="object"))for(let[t,n]of Object.entries(r)){let i=[...e,t];yield i.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&k.asCID(n)==null&&(yield*Hu(i,n))}}function Wu(r,e){let t=r;for(let[n,i]of e.entries()){if(t=t[i],t==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(s=>`[${JSON.stringify(s)}]`).join("")}`);let o=k.asCID(t);if(o!=null)return{value:o,remaining:e.slice(n+1).join("/")}}return{value:t}}var Xn=class{cid;bytes;value;asBlock;constructor({cid:e,bytes:t,value:n}){if(e==null||t==null||typeof n>"u")throw new Error("Missing required argument");this.cid=e,this.bytes=t,this.value=n,this.asBlock=this,Object.defineProperties(this,{cid:or(),bytes:or(),value:or(),asBlock:or()})}links(){return Jn(this.value,[])}tree(){return Yn(this.value,[])}get(e="/"){return Wu(this.value,e.split("/").filter(Boolean))}};function sr({bytes:r,cid:e,value:t,codec:n}){let i=t!==void 0?t:n?.decode(r);if(i===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new Xn({cid:e,bytes:r,value:i})}var ar=class extends Error{static name="AlreadyPinnedError";name="AlreadyPinnedError"},ut=class extends Error{static name="BlockPinnedError";name="BlockPinnedError"},cr=class extends Error{static name="InvalidDatastoreVersionError";name="InvalidDatastoreVersionError"},ur=class extends Error{static name="InvalidConfigurationError";name="InvalidConfigurationError"},lr=class extends AggregateError{static name="GetFailedError";name="GetFailedError"},fr=class extends AggregateError{static name="LoadBlockFailedError";name="LoadBlockFailedError"};var Ds="/pin/",Ps="/pinned-block/",Zn=ae,Ns=1;function hr(r){return r.version===0&&(r=r.toV1()),new fe(`${Ds}${r.toString(Zn)}`)}var dr=class{datastore;blockstore;getCodec;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.getCodec=n}async*add(e,t={}){let n=hr(e);if(await this.datastore.has(n))throw new ar("Already pinned");let i=Math.round(t.depth??1/0);if(i<0)throw new Le("Depth must be greater than or equal to 0");let o=new O({concurrency:Ns});for await(let a of this.#e(e,o,{...t,depth:i}))await this.#n(a,c=>c.pinnedBy.find(h=>ve(h,e.bytes))!=null?!1:(c.pinCount++,c.pinnedBy.push(e.bytes),!0),t),yield a;let s={depth:i,metadata:t.metadata??{}};await this.datastore.put(n,Se(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let i=await this.getCodec(e.code),o=await ir(this.blockstore.get(e,n)),s=sr({bytes:o,cid:e,codec:i});yield e;for(let[,a]of s.links())yield*await t.add(async()=>this.#e(a,t,{...n,depth:n.depth-1}))}async#n(e,t,n){let i=new fe(`${Ps}${Zn.encode(e.multihash.bytes)}`),o={pinCount:0,pinnedBy:[]};try{o=re(await this.datastore.get(i,n))}catch(a){if(a.name!=="NotFoundError")throw a}if(t(o)){if(o.pinCount===0&&await this.datastore.has(i)){await this.datastore.delete(i);return}await this.datastore.put(i,Se(o),n),n.onProgress?.(new v("helia:pin:add",e))}}async*rm(e,t={}){let n=hr(e),i=await this.datastore.get(n,t),o=re(i);await this.datastore.delete(n,t);let s=new O({concurrency:Ns});for await(let a of this.#e(e,s,{...t,depth:o.depth}))await this.#n(a,c=>(c.pinCount--,c.pinnedBy=c.pinnedBy.filter(h=>ve(h,e.bytes)),!0),{...t,depth:o.depth}),yield a}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:Ds+(e.cid!=null?`${e.cid.toString(ae)}`:"")},e)){let i=k.parse(t.toString().substring(5),ae),o=re(n);yield{cid:i,...o}}}async isPinned(e,t={}){let n=new fe(`${Ps}${Zn.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}async get(e,t){let n=hr(e),i=await this.datastore.get(n,t);return re(i)}async setMetadata(e,t,n){let i=hr(e),o=await this.datastore.get(i,n),s=re(o);s.metadata=t??{},await this.datastore.put(i,Se(s),n)}};var pr=class extends Error{static name="InsufficientProvidersError";constructor(e="Insufficient providers found"){super(e),this.name="InsufficientProvidersError"}},Ce=class extends Error{static name="NoRoutersAvailableError";constructor(e="No routers available"){super(e),this.name="NoRoutersAvailableError"}},mr=class extends Error{static name="UnknownHashAlgorithmError";constructor(e="Unknown hash algorithm"){super(e),this.name="UnknownHashAlgorithmError"}},gr=class extends Error{static name="UnknownCodecError";constructor(e="Unknown codec"){super(e),this.name="UnknownCodecError"}};var Gu=5,yr=class{log;routers;providerLookupConcurrency;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[],this.providerLookupConcurrency=t.providerLookupConcurrency??Gu,this.findProviders=e.metrics?.traceFunction("helia.routing.findProviders",this.findProviders.bind(this),{optionsIndex:1})??this.findProviders,this.provide=e.metrics?.traceFunction("helia.routing.provide",this.provide.bind(this),{optionsIndex:1})??this.provide,this.cancelReprovide=e.metrics?.traceFunction("helia.routing.cancelReprovide",this.cancelReprovide.bind(this),{optionsIndex:1})??this.cancelReprovide,this.put=e.metrics?.traceFunction("helia.routing.put",this.put.bind(this),{optionsIndex:2})??this.put,this.get=e.metrics?.traceFunction("helia.routing.get",this.get.bind(this),{optionsIndex:1})??this.get,this.findPeer=e.metrics?.traceFunction("helia.routing.findPeer",this.findPeer.bind(this),{optionsIndex:1})??this.findPeer,this.getClosestPeers=e.metrics?.traceFunction("helia.routing.getClosestPeers",this.getClosestPeers.bind(this),{optionsIndex:1})??this.getClosestPeers}async start(){await he(...this.routers)}async stop(){await de(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new Ce("No content routers available");let n=new rr({concurrency:this.providerLookupConcurrency}),i=0,o=[],s=this,a=0;this.log("findProviders for %c start using routers %s",e,this.routers.map(h=>h.toString()).join(", "));let c=Ie(this.routers,"findProviders").map(async function*(h){let l=0;try{for await(let f of h.findProviders(e,t))l++,yield f}catch(f){o.push(f)}finally{s.log("router %s found %d providers for %c",h,l,e),a++,a===c.length&&n.size===0&&n.emitIdle()}});for await(let h of zt(n.toGenerator(),...c))if(h!=null){if(h.multiaddrs.length===0){if(n.find(h.id)!=null)continue;n.add(async()=>{try{let l=await this.findPeer(h.id,t);return l.multiaddrs.length===0?null:{...l,protocols:h.protocols,routing:h.routing}}catch(l){return this.log.error("could not load multiaddrs for peer %p - %e",h.id,l),null}},{peerId:h.id,signal:t.signal}).catch(l=>{this.log.error("could not load multiaddrs for peer %p - %e",h.id,l)});continue}i++,yield h}this.log("findProviders finished, found %d providers for %c",i,e)}async provide(e,t={}){if(this.routers.length===0)throw new Ce("No content routers available");await Promise.all(Ie(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async cancelReprovide(e,t={}){await Promise.all(Ie(this.routers,"cancelReprovide").map(async n=>{await n.cancelReprovide(e,t)}))}async put(e,t,n){await Promise.all(Ie(this.routers,"put").map(async i=>{await i.put(e,t,n)}))}async get(e,t){let n=[],i;try{i=await Promise.any(Ie(this.routers,"get").map(async o=>{try{return await o.get(e,t)}catch(s){this.log("router %s failed with %e",o,s),n.push(s)}}))}catch{}if(i==null)throw new lr(n,`Failed to get value key ${ye(e,"base58btc")}`);return i}async findPeer(e,t){if(this.routers.length===0)throw new Ce("No peer routers available");let n=this,i=zt(...Ie(this.routers,"findPeer").map(o=>(async function*(){try{yield await o.findPeer(e,t)}catch(s){n.log.error(s)}})()));for await(let o of i)if(o!=null)return o;throw new mt("Could not find peer in routing")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new Ce("No peer routers available");for await(let n of zt(...Ie(this.routers,"getClosestPeers").map(i=>i.getClosestPeers(e,t))))n!=null&&(yield n)}};function Ie(r,e){return r.filter(t=>t[e]!=null)}var V=class extends Error{static name="AbortError";name="AbortError";constructor(e="The operation was aborted",...t){super(e,...t)}};async function wr(r,e,t,n){let i=new V(n?.errorMessage);n?.errorCode!=null&&(i.code=n.errorCode);let o=n?.errorEvent??"error";return t?.aborted===!0?Promise.reject(i):new Promise((s,a)=>{function c(){ti(t,"abort",f),ti(r,e,h),ti(r,o,l)}let h=m=>{try{if(n?.filter?.(m)===!1)return}catch(y){c(),a(y);return}c(),s(m)},l=m=>{if(c(),m instanceof Error){a(m);return}a(m.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},f=()=>{c(),a(i)};ei(t,"abort",f),ei(r,e,h),ei(r,o,l)})}function ei(r,e,t){r!=null&&(Rs(r)?r.addEventListener(e,t):r.addListener(e,t))}function ti(r,e,t){r!=null&&(Rs(r)?r.removeEventListener(e,t):r.removeListener(e,t))}function Rs(r){return typeof r.addEventListener=="function"&&typeof r.removeEventListener=="function"}var xr=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var br=class extends Error{type;code;constructor(e,t,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=t??"ABORT_ERR"}};async function Bs(r,e,t){if(e==null)return r;if(e.aborted)return r.catch(()=>{}),Promise.reject(new br(t?.errorMessage,t?.errorCode,t?.errorName));let n,i=new br(t?.errorMessage,t?.errorCode,t?.errorName);try{return await Promise.race([r,new Promise((o,s)=>{n=()=>{s(i)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var Er=class{deferred;signal;constructor(e){this.signal=e,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new V)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Qu(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var vr=class{id;fn;options;recipients;status;timeline;controller;constructor(e,t){this.id=Qu(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new V),this.cleanup())}async join(e={}){let t=new Er(e.signal);return this.recipients.push(t),e.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Bs(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};function ri(r,e){let t,n=function(){let i=function(){t=void 0,r()};clearTimeout(t),t=setTimeout(i,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(t)},n}var lt=class extends K{concurrency;maxSize;queue;pending;sort;autoStart;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=e.autoStart??!0,this.sort=e.sort,this.queue=[],this.emitEmpty=ri(this.emitEmpty.bind(this),1),this.emitIdle=ri(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(e,t){if(t?.signal?.throwIfAborted(),this.size===this.maxSize)throw new xr;let n=new vr(e,t);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(t).then(i=>(this.safeDispatchEvent("success",{detail:{job:n,result:i}}),i)).catch(i=>{if(n.status==="queued"){for(let o=0;o<this.queue.length;o++)if(this.queue[o]===n){this.queue.splice(o,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:i}}),i})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new V)}),this.clear()}async onEmpty(e){this.size!==0&&await wr(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await wr(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await wr(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=Rt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},i=c=>{c.detail!=null&&t.push(c.detail.result)},o=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new V("Queue aborted"))};this.addEventListener("success",i),this.addEventListener("failure",o),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("success",i),this.removeEventListener("failure",o),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var _r="lock:worker:request-read",kr="lock:worker:abort-read-request",Ar="lock:worker:release-read",Sr="lock:master:grant-read",Cr="lock:master:error-read",Ir="lock:worker:request-write",Tr="lock:worker:abort-write-request",Lr="lock:worker:release-write",Pr="lock:master:grant-write",Nr="lock:master:error-write",Dr="lock:worker:finalize",Rr="mortice",Us={singleProcess:!1};var ni=(r,e,t,n,i,o,s,a,c)=>h=>{if(h.data==null)return;let l={type:h.data.type,name:h.data.name,identifier:h.data.identifier};l.type===i&&r.safeDispatchEvent(t,{detail:{name:l.name,identifier:l.identifier,handler:async()=>{e.postMessage({type:c,name:l.name,identifier:l.identifier}),await new Promise(f=>{let m=y=>{if(y?.data==null)return;let x={type:y.data.type,name:y.data.name,identifier:y.data.identifier};x.type===a&&x.identifier===l.identifier&&(e.removeEventListener("message",m),f())};e.addEventListener("message",m)})},onError:f=>{e.postMessage({type:s,name:l.name,identifier:l.identifier,error:{message:f.message,name:f.name,stack:f.stack}})}}}),l.type===o&&r.safeDispatchEvent(n,{detail:{name:l.name,identifier:l.identifier}}),l.type===Dr&&r.safeDispatchEvent("finalizeRequest",{detail:{name:l.name}})};var $s=(r=10)=>Math.random().toString().substring(2,r+2);var Br=class{name;channel;constructor(e){this.name=e,this.channel=new BroadcastChannel(Rr)}readLock(e){return this.sendRequest(_r,kr,Sr,Cr,Ar,e)}writeLock(e){return this.sendRequest(Ir,Tr,Pr,Nr,Lr,e)}finalize(){this.channel.postMessage({type:Dr,name:this.name}),this.channel.close()}async sendRequest(e,t,n,i,o,s){s?.signal?.throwIfAborted();let a=$s();return this.channel.postMessage({type:e,identifier:a,name:this.name}),new Promise((c,h)=>{let l=()=>{this.channel.postMessage({type:t,identifier:a,name:this.name})};s?.signal?.addEventListener("abort",l,{once:!0});let f=m=>{if(m.data?.identifier===a&&(m.data?.type===n&&(this.channel.removeEventListener("message",f),s?.signal?.removeEventListener("abort",l),c(()=>{this.channel.postMessage({type:o,identifier:a,name:this.name})})),m.data.type===i)){this.channel.removeEventListener("message",f),s?.signal?.removeEventListener("abort",l);let y=new Error;m.data.error!=null&&(y.message=m.data.error.message,y.name=m.data.error.name,y.stack=m.data.error.stack),h(y)}};this.channel.addEventListener("message",f)})}};var Fs=r=>{if(r=Object.assign({},Us,r),!!globalThis.document||r.singleProcess){let t=new BroadcastChannel(Rr),n=new K;return t.addEventListener("message",ni(n,t,"requestReadLock","abortReadLockRequest",_r,kr,Cr,Ar,Sr)),t.addEventListener("message",ni(n,t,"requestWriteLock","abortWriteLockRequest",Ir,Tr,Nr,Lr,Pr)),n}return new Br(r.name)};var Te=new Map,ft;function Os(r){return typeof r?.readLock=="function"&&typeof r?.writeLock=="function"}function Ju(r){if(ft==null&&(ft=Fs(r),!Os(ft))){let e=ft;e.addEventListener("requestReadLock",t=>{let n=t.detail.name,i=t.detail.identifier,o=Te.get(n);if(o==null)return;let s=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==i||s.abort()};e.addEventListener("abortReadLockRequest",a),o.readLock({signal:s.signal}).then(async c=>{await t.detail.handler().finally(()=>{c()})}).catch(c=>{t.detail.onError(c)}).finally(()=>{e.removeEventListener("abortReadLockRequest",a)})}),e.addEventListener("requestWriteLock",t=>{let n=t.detail.name,i=t.detail.identifier,o=Te.get(n);if(o==null)return;let s=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==i||s.abort()};e.addEventListener("abortWriteLockRequest",a),o.writeLock({signal:s.signal}).then(async c=>{await t.detail.handler().finally(()=>{c()})}).catch(c=>{t.detail.onError(c)}).finally(()=>{e.removeEventListener("abortWriteLockRequest",a)})}),e.addEventListener("finalizeRequest",t=>{let n=t.detail.name,i=Te.get(n);i?.finalize()})}return ft}async function ii(r,e){let t,n,i=new Promise((s,a)=>{t=s,n=a}),o=()=>{n(new V)};return e?.signal?.addEventListener("abort",o,{once:!0}),r.add(async()=>{await new Promise(s=>{t(()=>{e?.signal?.removeEventListener("abort",o),s()})})},{signal:e?.signal}).catch(s=>{n(s)}),i}var zs=(r,e)=>{let t=Te.get(r);if(t!=null)return t;let n=Ju(e);if(Os(n))return t=n,Te.set(r,t),t;let i=new lt({concurrency:1}),o;return t={async readLock(s){if(o!=null)return ii(o,s);o=new lt({concurrency:e.concurrency,autoStart:!1});let a=o,c=ii(o,s);return i.add(async()=>{a.start(),await a.onIdle().then(()=>{o===a&&(o=null)})}),c},async writeLock(s){return o=null,ii(i,s)},finalize:()=>{Te.delete(r)},queue:i},Te.set(r,t),e.autoFinalize===!0&&i.addEventListener("idle",()=>{t.finalize()},{once:!0}),t};var Yu={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function oi(r){let e=Object.assign({},Yu,r);return zs(e.name,e)}var Ur=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=oi({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await he(this.child),this.started=!0}async stop(){await de(this.child),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){n?.signal?.throwIfAborted();let i=await this.lock.readLock();try{return await this.child.put(e,t,n)}finally{i()}}async*putMany(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.putMany(e,t)}finally{n()}}async*get(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.get(e,t)}finally{n()}}async*getMany(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.getMany(e,t)}finally{n()}}async delete(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.writeLock();try{if(await this.pins.isPinned(e))throw new ut("Block was pinned - please unpin and try again");await this.child.delete(e,t)}finally{n()}}async*deleteMany(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.writeLock();try{let i=this;yield*this.child.deleteMany((async function*(){for await(let o of e){if(await i.pins.isPinned(o))throw new ut("Block was pinned - please unpin and try again");yield o}})(),t)}finally{n()}}async has(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{return await this.child.has(e,t)}finally{n()}}async*getAll(e={}){e?.signal?.throwIfAborted();let t=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{t()}}createSession(e,t){return t?.signal?.throwIfAborted(),this.child.createSession(e,t)}};var si=new fe("/version"),Ms=1;async function qs(r){if(!await r.has(si)){await r.put(si,$(`${Ms}`));return}let e=await r.get(si),t=ye(e);if(parseInt(t,10)!==Ms)throw new cr("Invalid datastore version, a datastore migration may be required")}var ui={};I(ui,{code:()=>ci,decode:()=>al,decodeOptions:()=>il,encode:()=>sl,encodeOptions:()=>rl,name:()=>ol,toByteView:()=>Vs});var js=42;function Vs(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function Xu(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=k.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new d(u.tag,js),new d(u.bytes,t)]}function Zu(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function el(r){if(Number.isNaN(r))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(r===1/0||r===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function tl(r){for(let e of r.keys())if(typeof e!="string"||e.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var ai={float64:!0,typeEncoders:{Map:tl,Object:Xu,undefined:Zu,number:el}},rl={...ai,typeEncoders:{...ai.typeEncoders}};function nl(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return k.decode(r.subarray(1))}var $r={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};$r.tags[js]=nl;var il={...$r,tags:$r.tags.slice()},ol="dag-cbor",ci=113,sl=r=>Se(r,ai),al=r=>re(Vs(r),$r);var gi={};I(gi,{code:()=>mi,decode:()=>Hs,encode:()=>Ks,format:()=>wl,name:()=>yl,parse:()=>bl,stringify:()=>wl});var li=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===u.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===u.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[u.uint.major](e,t){this.prefix(e);let n=String(t.value),i=[];for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);e.push(i)}[u.negint.major](e,t){this[u.uint.major](e,t)}[u.bytes.major](e,t){throw new Error(`${ce} unsupported type: Uint8Array`)}[u.string.major](e,t){this.prefix(e);let n=qt(JSON.stringify(t.value));e.push(n.length>32?nt(n):n)}[u.array.major](e,t){this.prefix(e),this.inRecursive.push({type:u.array,elements:0}),e.push([91])}[u.map.major](e,t){this.prefix(e),this.inRecursive.push({type:u.map,elements:0}),e.push([123])}[u.tag.major](e,t){}[u.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===u.array)e.push([93]);else if(s.type===u.map)e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(t.value===void 0)throw new Error(`${ce} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.value),i=[],o=!1;for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s),!o&&(i[s]===46||i[s]===101||i[s]===69)&&(o=!0);o||(i.push(46),i.push(48)),e.push(i)}};function cl(r,e){if(Array.isArray(r[0])||Array.isArray(e[0]))throw new Error(`${ce} complex map keys are not supported`);let t=r[0],n=e[0];if(t.type!==u.string||n.type!==u.string)throw new Error(`${ce} non-string map keys are not supported`);if(t<n)return-1;if(t>n)return 1;throw new Error(`${ce} unexpected duplicate map keys, this is not supported`)}var ul={addBreakTokens:!0,mapSorter:cl};function fi(r,e){return e=Object.assign({},ul,e),Zt(r,new li,e)}var je=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${g} unexpected end of input at position ${this._pos}`);for(let t=0;t<e.length;t++)if(this.data[this._pos++]!==e[t])throw new Error(`${g} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,i=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(t=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new d(u.uint,0,this._pos-e);if(i([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${g} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${g} unexpected token at position ${this._pos}`);n=!0,this._pos++,i([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,i([48,49,50,51,52,53,54,55,56,57]));let o=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(o);return n?new d(u.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new d(s>=0?u.uint:u.negint,s,this._pos-e):new d(s>=0?u.uint:u.negint,BigInt(o),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${g} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let o=this._pos,s=0;o<this.data.length&&s<65536;o++,s++){let a=this.data[o];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,o));return this._pos=o+1,new d(u.string,c,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${g} unexpected end of unicode escape sequence at position ${this._pos}`);let o=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${g} unexpected unicode escape character at position ${this._pos}`);o=o*16+a,this._pos++}return o},i=()=>{let o=this.ch(),s=null,a=o>239?4:o>223?3:o>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${g} unexpected unicode sequence at position ${this._pos}`);let c,h,l,f;switch(a){case 1:o<128&&(s=o);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(f=(o&31)<<6|c&63,f>127&&(s=f));break;case 3:c=this.data[this._pos+1],h=this.data[this._pos+2],(c&192)===128&&(h&192)===128&&(f=(o&15)<<12|(c&63)<<6|h&63,f>2047&&(f<55296||f>57343)&&(s=f));break;case 4:c=this.data[this._pos+1],h=this.data[this._pos+2],l=this.data[this._pos+3],(c&192)===128&&(h&192)===128&&(l&192)===128&&(f=(o&15)<<18|(c&63)<<12|(h&63)<<6|l&63,f>65535&&f<1114112&&(s=f))}s===null?(s=65533,a=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=a};for(;!this.done();){let o=this.ch(),s;switch(o){case 92:if(this._pos++,this.done())throw new Error(`${g} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:t.push(s);break;case 98:t.push(8);break;case 116:t.push(9);break;case 110:t.push(10);break;case 102:t.push(12);break;case 114:t.push(13);break;case 117:t.push(n());break;default:throw new Error(`${g} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new d(u.string,Mn(t),this._pos-e);default:if(o<32)throw new Error(`${g} invalid control character at position ${this._pos}`);o<128?(t.push(o),this._pos++):i()}}throw new Error(`${g} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new d(u.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new d(u.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new d(u.null,null,4);case 102:return this.expect([102,97,108,115,101]),new d(u.false,!1,5);case 116:return this.expect([116,114,117,101]),new d(u.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${g} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new d(u.break,void 0,1);if(this.ch()!==44)throw new Error(`${g} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new d(u.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new d(u.break,void 0,1);if(this.ch()!==44)throw new Error(`${g} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new d(u.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${g} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${g} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function hi(r,e){return e=Object.assign({tokenizer:new je(r,e)},e),re(r,e)}function fl(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function hl(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=k.asCID(r);if(!e)return null;let t=e.toString();return[new d(u.map,1/0,1),new d(u.string,"/",1),new d(u.string,t,t.length),new d(u.break,void 0,1)]}function Fr(r){let e=ge.encode(r).slice(1);return[new d(u.map,1/0,1),new d(u.string,"/",1),new d(u.map,1/0,1),new d(u.string,"bytes",5),new d(u.string,e,e.length),new d(u.break,void 0,1),new d(u.break,void 0,1)]}function ne(r){return Fr(new Uint8Array(r.buffer,r.byteOffset,r.byteLength))}function dl(r){return Fr(new Uint8Array(r))}function pl(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function ml(r){if(Number.isNaN(r))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(r===1/0||r===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var gl={typeEncoders:{Object:hl,Buffer:Fr,Uint8Array:Fr,Int8Array:ne,Uint16Array:ne,Int16Array:ne,Uint32Array:ne,Int32Array:ne,Float32Array:ne,Float64Array:ne,Uint8ClampedArray:ne,BigInt64Array:ne,BigUint64Array:ne,DataView:ne,ArrayBuffer:dl,undefined:pl,number:ml}},di=class extends je{constructor(e,t){super(e,t),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(e.type===u.map){let t=this._next();if(t.type===u.string&&t.value==="/"){let n=this._next();if(n.type===u.string){if(this._next().type!==u.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new d(u.tag,42,0)}if(n.type===u.map){let i=this._next();if(i.type===u.string&&i.value==="bytes"){let o=this._next();if(o.type===u.string){for(let a=0;a<2;a++)if(this._next().type!==u.break)throw new Error("Invalid encoded Bytes form");let s=ge.decode(`m${o.value}`);return new d(u.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},pi={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};pi.tags[42]=k.parse;var yl="dag-json",mi=297,Ks=r=>fi(r,gl),Hs=r=>{let e=fl(r),t=Object.assign(pi,{tokenizer:new di(e,pi)});return hi(e,t)},wl=r=>xl.decode(Ks(r));var xl=new TextDecoder,bl=r=>Hs(El.encode(r)),El=new TextEncoder;var vi={};I(vi,{code:()=>Ei,createLink:()=>ra,createNode:()=>ta,decode:()=>Rl,encode:()=>Dl,name:()=>Nl,prepare:()=>xi,validate:()=>bi});var vl=new TextDecoder;function yi(r,e){let t=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=r.length)throw new Error("protobuf: unexpected end of data");let i=r[e++];if(t+=n<28?(i&127)<<n:(i&127)*2**n,i<128)break}return[t,e]}function Or(r,e){let t;[t,e]=yi(r,e);let n=e+t;if(t<0||n<0)throw new Error("protobuf: invalid length");if(n>r.length)throw new Error("protobuf: unexpected end of data");return[r.subarray(e,n),n]}function Ws(r,e){let t;return[t,e]=yi(r,e),[t&7,t>>3,e]}function _l(r){let e={},t=r.length,n=0;for(;n<t;){let i,o;if([i,o,n]=Ws(r,n),o===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=Or(r,n)}else if(o===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=Or(r,n),e.Name=vl.decode(s)}else if(o===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(i!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Tsize`);[e.Tsize,n]=yi(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${o}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Gs(r){let e=r.length,t=0,n,i=!1,o;for(;t<e;){let a,c;if([a,c,t]=Ws(r,t),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(o)throw new Error("protobuf: (PBNode) duplicate Data section");[o,t]=Or(r,t),n&&(i=!0)}else if(c===2){if(i)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let h;[h,t]=Or(r,t),n.push(_l(h))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(t>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return o&&(s.Data=o),s.Links=n||[],s}var Js=new TextEncoder,Qs=2**32,kl=2**31;function Al(r,e){let t=e.length;if(typeof r.Tsize=="number"){if(r.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(r.Tsize))throw new Error("Tsize too large for encoding");t=ht(e,t,r.Tsize)-1,e[t]=24}if(typeof r.Name=="string"){let n=Js.encode(r.Name);t-=n.length,e.set(n,t),t=ht(e,t,n.length)-1,e[t]=18}return r.Hash&&(t-=r.Hash.length,e.set(r.Hash,t),t=ht(e,t,r.Hash.length)-1,e[t]=10),e.length-t}function Ys(r){let e=Cl(r),t=new Uint8Array(e),n=e;if(r.Data&&(n-=r.Data.length,t.set(r.Data,n),n=ht(t,n,r.Data.length)-1,t[n]=10),r.Links)for(let i=r.Links.length-1;i>=0;i--){let o=Al(r.Links[i],t.subarray(0,n));n-=o,n=ht(t,n,o)-1,t[n]=18}return t}function Sl(r){let e=0;if(r.Hash){let t=r.Hash.length;e+=1+t+Ve(t)}if(typeof r.Name=="string"){let t=Js.encode(r.Name).length;e+=1+t+Ve(t)}return typeof r.Tsize=="number"&&(e+=1+Ve(r.Tsize)),e}function Cl(r){let e=0;if(r.Data){let t=r.Data.length;e+=1+t+Ve(t)}if(r.Links)for(let t of r.Links){let n=Sl(t);e+=1+n+Ve(n)}return e}function ht(r,e,t){e-=Ve(t);let n=e;for(;t>=kl;)r[e++]=t&127|128,t/=128;for(;t>=128;)r[e++]=t&127|128,t>>>=7;return r[e]=t,n}function Ve(r){return r%2===0&&r++,Math.floor((Il(r)+6)/7)}function Il(r){let e=0;return r>=Qs&&(r=Math.floor(r/Qs),e=32),r>=65536&&(r>>>=16,e+=16),r>=256&&(r>>>=8,e+=8),e+Tl[r]}var Tl=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];var Ll=["Data","Links"],Pl=["Hash","Name","Tsize"],wi=new TextEncoder;function Zs(r,e){if(r===e)return 0;let t=r.Name?wi.encode(r.Name):[],n=e.Name?wi.encode(e.Name):[],i=t.length,o=n.length;for(let s=0,a=Math.min(i,o);s<a;++s)if(t[s]!==n[s]){i=t[s],o=n[s];break}return i<o?-1:o<i?1:0}function Xs(r,e){return!Object.keys(r).some(t=>!e.includes(t))}function ea(r){if(typeof r.asCID=="object"){let t=k.asCID(r);if(!t)throw new TypeError("Invalid DAG-PB form");return{Hash:t}}if(typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let e={};if(r.Hash){let t=k.asCID(r.Hash);try{t||(typeof r.Hash=="string"?t=k.parse(r.Hash):r.Hash instanceof Uint8Array&&(t=k.decode(r.Hash)))}catch(n){throw new TypeError(`Invalid DAG-PB form: ${n.message}`)}t&&(e.Hash=t)}if(!e.Hash)throw new TypeError("Invalid DAG-PB form");return typeof r.Name=="string"&&(e.Name=r.Name),typeof r.Tsize=="number"&&(e.Tsize=r.Tsize),e}function xi(r){if((r instanceof Uint8Array||typeof r=="string")&&(r={Data:r}),typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let e={};if(r.Data!==void 0)if(typeof r.Data=="string")e.Data=wi.encode(r.Data);else if(r.Data instanceof Uint8Array)e.Data=r.Data;else throw new TypeError("Invalid DAG-PB form");if(r.Links!==void 0)if(Array.isArray(r.Links))e.Links=r.Links.map(ea),e.Links.sort(Zs);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function bi(r){if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form");if(!Xs(r,Ll))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(r.Data!==void 0&&!(r.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(r.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e<r.Links.length;e++){let t=r.Links[e];if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!Xs(t,Pl))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(t.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(t.Hash==null||!t.Hash["/"]||t.Hash["/"]!==t.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(t.Name!==void 0&&typeof t.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(t.Tsize!==void 0){if(typeof t.Tsize!="number"||t.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(t.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(e>0&&Zs(t,r.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function ta(r,e=[]){return xi({Data:r,Links:e})}function ra(r,e,t){return ea({Hash:t,Name:r,Tsize:e})}function na(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var Nl="dag-pb",Ei=112;function Dl(r){bi(r);let e={};return r.Links&&(e.Links=r.Links.map(t=>{let n={};return t.Hash&&(n.Hash=t.Hash.bytes),t.Name!==void 0&&(n.Name=t.Name),t.Tsize!==void 0&&(n.Tsize=t.Tsize),n})),r.Data&&(e.Data=r.Data),Ys(e)}function Rl(r){let e=na(r),t=Gs(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(i=>{let o={};try{o.Hash=k.decode(i.Hash)}catch{}if(!o.Hash)throw new Error("Invalid Hash field found in link, expected CID");return i.Name!==void 0&&(o.Name=i.Name),i.Tsize!==void 0&&(o.Tsize=i.Tsize),o})),n}function Ke(r){return r?.then!=null}function ia(r=[],e){let t={[Ei]:vi,[wn]:_t,[ci]:ui,[mi]:gi,[yn]:vt};return r.forEach(n=>{t[n.code]=n}),async n=>{let i=t[n];if(i==null&&e!=null){let o=e(n);Ke(o)?i=await o:i=o,t[i.code]=i}if(i!=null)return i;throw new gr(`Could not load codec for ${n}`)}}function oa(r=[],e){let t={[St.code]:St,[Ct.code]:Ct,[At.code]:At};return r.forEach(n=>{t[n.code]=n}),async n=>{let i=t[n];if(i==null&&e!=null){let o=e(n);Ke(o)?i=await o:i=o,t[i.code]=i}if(i!=null)return i;throw new mr(`No hasher configured for multihash code 0x${n.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`)}}var zr=class r extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=r.name;code=r.code;constructor(e="Not Found"){super(e)}};var Mr=class{has(e,t){return Promise.reject(new Error(".has is not implemented"))}put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,t){for await(let{cid:n,bytes:i}of e)await this.put(n,i,t),yield n}get(e,t){throw new Error(".get is not implemented")}async*getMany(e,t){for await(let n of e)yield{cid:n,bytes:this.get(n,t)}}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,t){for await(let n of e)await this.delete(n,t),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var qr=0,He=class extends Error{static name="IdentityHashDigestTooLongError";name="IdentityHashDigestTooLongError"},jr=class extends Mr{child;maxDigestLength;constructor(e,t){super(),this.child=e,this.maxDigestLength=t?.maxDigestLength}put(e,t,n){if(e.multihash.code===qr){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new He(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);return n?.signal?.throwIfAborted(),e}return this.child==null?(n?.signal?.throwIfAborted(),e):this.child.put(e,t,n)}*get(e,t){if(e.multihash.code===qr){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new He(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);t?.signal?.throwIfAborted(),yield e.multihash.digest;return}if(this.child==null)throw t?.signal?.throwIfAborted(),new zr;yield*this.child.get(e,t)}has(e,t){if(e.multihash.code===qr){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new He(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);return t?.signal?.throwIfAborted(),!0}return this.child==null?(t?.signal?.throwIfAborted(),!1):this.child.has(e,t)}delete(e,t){if(e.code===qr){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new He(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);t?.signal?.throwIfAborted();return}if(this.child!=null)return this.child.delete(e,t)}*getAll(e){this.child!=null&&(yield*this.child.getAll(e)),e?.signal?.throwIfAborted()}};function Bl(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var Vr=Bl;function Ul(r){return r[Symbol.asyncIterator]!=null}function $l(r,e){let t=0;if(Ul(r))return(async function*(){for await(let c of r)await e(c,t++)&&(yield c)})();let n=Vr(r),{value:i,done:o}=n.next();if(o===!0)return(function*(){})();let s=e(i,t++);if(typeof s.then=="function")return(async function*(){await s&&(yield i);for(let c of n)await e(c,t++)&&(yield c)})();let a=e;return(function*(){s===!0&&(yield i);for(let c of n)a(c,t++)&&(yield c)})()}var Kr=$l;function Fl(r){return r[Symbol.asyncIterator]!=null}function sa(r){return r?.then!=null}function Ol(r,e){let t=0;if(Fl(r))return(async function*(){for await(let c of r){let h=e(c,t++);sa(h)&&await h,yield c}})();let n=Vr(r),{value:i,done:o}=n.next();if(o===!0)return(function*(){})();if(typeof e(i,t++)?.then=="function")return(async function*(){yield i;for(let c of n){let h=e(c,t++);sa(h)&&await h,yield c}})();let a=e;return(function*(){yield i;for(let c of n)a(c,t++),yield c})()}var _i=Ol;var Ml=128,Hr=class{child;getHasher;log;logger;components;constructor(e,t={}){this.log=e.logger.forComponent("helia:networked-storage"),this.logger=e.logger,this.components=e,this.child=new jr(e.blockstore,{maxDigestLength:t.maxIdentityHashDigestLength??Ml}),this.getHasher=e.getHasher}async put(e,t,n={}){return await this.child.has(e,n)?(n.onProgress?.(new v("blocks:put:duplicate",e)),e):(n.onProgress?.(new v("blocks:put:providers:notify",e)),await Promise.all(this.components.blockBrokers.map(async i=>i.announce?.(e,n))),n.onProgress?.(new v("blocks:put:blockstore:put",e)),this.child.put(e,t,n))}async*putMany(e,t={}){let n=Kr(e,async({cid:o})=>{let s=await this.child.has(o,t);return s&&t.onProgress?.(new v("blocks:put-many:duplicate",o)),!s}),i=_i(n,async({cid:o})=>{t.onProgress?.(new v("blocks:put-many:providers:notify",o)),await Promise.all(this.components.blockBrokers.map(async s=>s.announce?.(o,t)))});t.onProgress?.(new v("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(i,t)}async*get(e,t={}){if(t.offline!==!0&&!await this.child.has(e,t)){let n=await this.getHasher(e.multihash.code);t.onProgress?.(new v("blocks:get:providers:get",e));let i=await aa(e,this.components.blockBrokers,n,{...t,log:this.log});t.onProgress?.(new v("blocks:get:blockstore:put",e)),await this.child.put(e,i,t),t.onProgress?.(new v("blocks:get:providers:notify",e)),await Promise.all(this.components.blockBrokers.map(async o=>o.announce?.(e,t))),yield i;return}t.onProgress?.(new v("blocks:get:blockstore:get",e)),yield*this.child.get(e,t)}async*getMany(e,t={}){t.onProgress?.(new v("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(_i(e,async n=>{if(t.offline!==!0&&!await this.child.has(n,t)){let i=await this.getHasher(n.multihash.code);t.onProgress?.(new v("blocks:get-many:providers:get",n));let o=await aa(n,this.components.blockBrokers,i,{...t,log:this.log});t.onProgress?.(new v("blocks:get-many:blockstore:put",n)),await this.child.put(n,o,t),t.onProgress?.(new v("blocks:get-many:providers:notify",n)),await Promise.all(this.components.blockBrokers.map(async s=>s.announce?.(n,t)))}}))}async delete(e,t={}){t.onProgress?.(new v("blocks:delete:blockstore:delete",e)),await this.child.delete(e,t)}async*deleteMany(e,t={}){t.onProgress?.(new v("blocks:delete-many:blockstore:delete-many")),yield*this.child.deleteMany((async function*(){for await(let n of e)yield n})(),t)}async has(e,t={}){return this.child.has(e,t)}async*getAll(e={}){e.onProgress?.(new v("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}},Wr=class extends Hr{started;constructor(e,t={}){super(e,t),this.started=!1}isStarted(){return this.started}async start(){await he(this.child,...this.components.blockBrokers),this.started=!0}async stop(){await de(this.child,...this.components.blockBrokers),this.started=!1}unwrap(){return this.child}createSession(e,t){let n=this.components.blockBrokers.map(i=>i.createSession==null?i:i.createSession(t));return new ki({blockstore:this.child,blockBrokers:n,getHasher:this.getHasher,logger:this.logger},{root:e})}},ki=class extends Hr{closeController;constructor(e,t){super(e),this.closeController=new AbortController,this.closeController.signal,this.log=e.logger.forComponent(`helia:session-storage:${t.root}`)}close(){this.closeController.abort()}async put(e,t,n={}){let i=ie([this.closeController.signal,n.signal]);try{return await super.put(e,t,{...n,signal:i})}finally{i.clear()}}async*putMany(e,t={}){let n=ie([this.closeController.signal,t.signal]);try{yield*super.putMany(e,{...t,signal:n})}finally{n.clear()}}async*get(e,t={}){let n=ie([this.closeController.signal,t.signal]);try{yield*super.get(e,{...t,signal:n})}finally{n.clear()}}async*getMany(e,t={}){let n=ie([this.closeController.signal,t.signal]);try{yield*super.getMany(e,{...t,signal:n})}finally{n.clear()}}async delete(e,t={}){let n=ie([this.closeController.signal,t.signal]);try{await super.delete(e,{...t,signal:n})}finally{n.clear()}}async*deleteMany(e,t={}){let n=ie([this.closeController.signal,t.signal]);try{yield*super.deleteMany(e,{...t,signal:n})}finally{n.clear()}}async has(e,t={}){let n=ie([this.closeController.signal,t.signal]);try{return await super.has(e,{...t,signal:n})}finally{n.clear()}}async*getAll(e={}){let t=ie([this.closeController.signal,e.signal]);try{yield*super.getAll({...e,signal:t})}finally{t.clear()}}};function ql(r){return typeof r.retrieve=="function"}var jl=(r,e)=>{if(e==null)throw new Le(`No hasher configured for multihash code 0x${r.multihash.code.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`);return async t=>{let n,i=e.digest(t,{truncate:r.multihash.digest.byteLength});if(Ke(i)?n=await i:n=i,!ve(n.digest,r.multihash.digest))throw new gt("Hash of downloaded block did not match multihash from passed CID")}};async function aa(r,e,t,n){let i=jl(r,t),o=new AbortController,s=ie([o.signal,n.signal]);o.signal;let a=[];for(let c of e)ql(c)&&a.push(c);if(a.length===0)throw new ur(`No block brokers capable of retrieving blocks are configured, the CID ${r} cannot be fetched from the network`);try{return await Promise.any(a.map(async c=>{try{let h=!1,l=await c.retrieve(r,{...n,signal:s,validateFn:async f=>{await i(f),n.signal?.throwIfAborted(),h=!0}});return h||(await i(l),n.signal?.throwIfAborted()),l}catch(h){throw n.log.error("could not retrieve verified block for %c - %e",r,h),h}}))}catch(c){throw new fr(c.errors,`Failed to load block for ${r}`)}finally{o.abort(),s.clear()}}var Gr=class extends K{initialPeerSearchComplete;requests;name;log;logger;minProviders;maxProviders;providers;evictionFilter;initialProviders;constructor(e,t){super(),this.name=t.name,this.logger=e.logger,this.log=e.logger.forComponent(this.name),this.requests=new Map,this.minProviders=t.minProviders??1,this.maxProviders=t.maxProviders??5,this.providers=[],this.evictionFilter=Rn(this.maxProviders),this.initialProviders=t.providers??[]}async retrieve(e,t={}){let n=ge.encode(e.multihash.bytes),i=this.requests.get(n);if(i!=null)return this.log("join existing request for %c",e),i;let o=F();if(this.requests.set(n,o.promise),this.providers.length===0){let l=!1;this.initialPeerSearchComplete==null&&(l=!0,this.log=this.logger.forComponent(`${this.name}:${e}`),this.initialPeerSearchComplete=this.findProviders(e,this.minProviders,t));try{await rt(this.initialPeerSearchComplete,t.signal),l&&this.log("found initial session peers for %c",e)}catch(f){throw l&&this.log("failed to find initial session peers for %c - %e",e,f),this.requests.delete(n),o.reject(f),f}}let s=!1,a=new O({concurrency:this.maxProviders});a.addEventListener("failure",l=>{this.log.error("error querying provider %s, evicting from session - %e",l.detail.job.options.provider,l.detail.error),this.evict(l.detail.job.options.provider)}),a.addEventListener("success",l=>{s=!0,o.resolve(l.detail.result)}),a.addEventListener("idle",()=>{if(s){this.log.trace("session idle, found block");return}if(t.signal?.aborted===!0){this.log.trace("session idle, signal aborted");return}Promise.resolve().then(async()=>{this.log("no session peers had block for for %c, finding new providers",e);for(let l=0;l<this.minProviders&&this.providers.length!==0;l++){let f=this.providers[Math.floor(Math.random()*this.providers.length)];this.evict(f)}await this.findProviders(e,this.minProviders,t),this.log("found new providers re-retrieving %c",e),this.requests.delete(n),o.resolve(await this.retrieve(e,t))}).catch(l=>{this.log.error("could not find new providers for %c - %e",e,l),o.reject(l)})});let c=l=>{a.add(async()=>this.queryProvider(e,l.detail,t),{provider:l.detail}).catch(f=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,f)})};this.addEventListener("provider",c),Promise.all([...this.providers].map(async l=>a.add(async()=>this.queryProvider(e,l,t),{provider:l}))).catch(l=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,l)});let h=()=>{o.reject(new J(t.signal?.reason??"Session aborted")),a.abort()};t.signal?.addEventListener("abort",h);try{return await rt(o.promise,t.signal)}finally{this.removeEventListener("provider",c),t.signal?.removeEventListener("abort",h),a.clear(),this.requests.delete(n)}}evict(e){this.evictionFilter.add(this.toEvictionKey(e));let t=this.providers.findIndex(n=>this.equals(n,e));t!==-1&&this.providers.splice(t,1)}isEvicted(e){return this.evictionFilter.has(this.toEvictionKey(e))}hasProvider(e){return!!(this.providers.find(t=>this.equals(t,e))!=null||this.isEvicted(e))}async findProviders(e,t,n){let i=F(),o=0;return Promise.resolve().then(async()=>{if(this.log("finding %d-%d new provider(s) for %c",t,this.maxProviders,e),this.initialProviders.length>0)for(;o<t&&this.initialProviders.length>0;){let s=this.initialProviders.pop();if(s==null)break;let a=await this.convertToProvider(s,n);if(n.signal?.aborted===!0)break;if(a!=null&&!this.hasProvider(a)&&(this.log("found %d/%d new providers",o,this.maxProviders),this.providers.push(a),this.safeDispatchEvent("provider",{detail:a}),o++,o===t&&(this.log("session is ready"),i.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers",o);break}}if(o<this.maxProviders)for await(let s of this.findNewProviders(e,n)){if(o===this.maxProviders||n.signal?.aborted===!0)break;if(!this.hasProvider(s)&&(this.log("found %d/%d new providers",o,this.maxProviders),this.providers.push(s),this.safeDispatchEvent("provider",{detail:s}),o++,o===t&&(this.log("session is ready"),i.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers",o);break}}if(this.log("found %d/%d new session peers",o,this.maxProviders),o<t)throw new pr(`Found ${o} of ${t} ${this.name} providers for ${e}`)}).catch(s=>{this.log.error("error searching routing for potential session peers for %c - %e",e,s),i.reject(s)}),i.promise}};function ca(r){return e=>new Ai(e,r)}function ua(r){return e=>new Si(e,r)}function la(r){return e=>new Ci(e,r)}var dt=class{components;constructor(e,t={}){this.components=e}async*walk(e,t){let n=this.getQueue(),i=Kr(n.toGenerator(t),a=>a!=null),o=!1,s=async a=>{let c=a.cid,h=await ir(this.components.blockstore.get(c,a)),l=sr({cid:c,bytes:h,codec:await this.components.getCodec(c.code)});for(let[,f]of l.links())t?.includeChild?.(f,l)!==!1&&n.add(s,{...a,cid:f,depth:a.depth+1,path:[...a.path,f]}).catch(m=>{o||i.throw(m)});return{block:l,depth:a.depth,path:a.path}};n.add(s,{...t,cid:e,depth:0,path:[e]}).catch(a=>{o||i.throw(a)});try{yield*i}finally{o=!0,n.abort()}}},Ai=class extends dt{getQueue(){return new O({concurrency:1,sort:(e,t)=>e.options.depth===t.options.depth?0:e.options.depth<t.options.depth?1:-1})}},Si=class extends dt{getQueue(){return new O({concurrency:1,sort:(e,t)=>e.options.depth===t.options.depth?0:e.options.depth<t.options.depth?-1:1})}},Ci=class extends dt{getQueue(){return new O({concurrency:1})}};var Ii=class{libp2p;blockstore;datastore;events;pins;logger;routing;getCodec;getHasher;dns;metrics;log;constructor(e){this.logger=e.logger??Vi(),this.log=this.logger.forComponent("helia"),this.getHasher=oa(e.hashers,e.loadHasher),this.getCodec=ia(e.codecs,e.loadCodec),this.dns=e.dns??wo(),this.metrics=e.metrics,this.libp2p=e.libp2p,this.events=new K;let t={blockstore:e.blockstore,datastore:e.datastore,logger:this.logger,libp2p:this.libp2p,blockBrokers:[],getHasher:this.getHasher,getCodec:this.getCodec,dns:this.dns,metrics:this.metrics,...e.components??{}};this.routing=t.routing=new yr(t,{routers:(e.routers??[]).flatMap(i=>{typeof i=="function"&&(i=i(t));let o=[i],s=Hl(i);s!=null&&o.push(s);let a=Wl(i);return a!=null&&o.push(a),o}),providerLookupConcurrency:e.providerLookupConcurrency});let n=new Wr(t,e);this.pins=new dr(e.datastore,n,this.getCodec),this.blockstore=new Ur(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,t.blockBrokers=e.blockBrokers.map(i=>i(t))}async start(){await qs(this.datastore),await he(this.blockstore,this.datastore,this.routing,this.libp2p),this.events.dispatchEvent(new CustomEvent("start",{detail:this}))}async stop(){await de(this.blockstore,this.datastore,this.routing,this.libp2p),this.events.dispatchEvent(new CustomEvent("stop",{detail:this}))}async gc(e={}){let t=await this.blockstore.lock.writeLock();try{let n=this,i=this.blockstore.unwrap();this.log("gc start"),await xo(i.deleteMany((async function*(){for await(let{cid:o}of i.getAll())try{if(await n.pins.isPinned(o,e))continue;yield o,e.onProgress?.(new v("helia:gc:deleted",o))}catch(s){n.log.error("error during gc - %e",s),e.onProgress?.(new v("helia:gc:error",s))}})()))}finally{t()}this.log("gc finished")}};function Hl(r){return r?.[Ni]}function Wl(r){return r?.[Di]}return ya(Gl);})();
|
|
12
|
+
${e}[Error list was empty]`,t.trim()}return zi(r,e)}U.formatters.e=r=>r==null?"undefined":qi(r);function Wa(r){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=r,e.destroy=()=>!0,e.extend=()=>e,e}function ji(r){return{forComponent(e){return Vi(e,r)}}}function Vi(r,e){let t=Wa(`${r}:trace`);return U.enabled(`${r}:trace`)&&U.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(t=U(`${r}:trace`,e)),Object.assign(U(r,e),{error:U(`${r}:error`,e),trace:t,newScope:n=>Vi(`${r}:${n}`,e)})}function Mi(r){if(r!=null&&(r=r.trim(),r.length!==0))return r}var v=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var bt=class extends AggregateError{static name="DNSQueryFailedError";name="DNSQueryFailedError"};var on=Li(Hi(),1);var sn=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},Wi=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function an(r,e){let{milliseconds:t,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout},signal:s}=e,a,c,l=new Promise((f,m)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(s?.aborted){m(Wi(s));return}if(s&&(c=()=>{m(Wi(s))},s.addEventListener("abort",c,{once:!0})),r.then(f,m),t===Number.POSITIVE_INFINITY)return;let y=new sn;a=o.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(x){m(x)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?f():i instanceof Error?m(i):(y.message=i??`Promise timed out after ${t} milliseconds`,m(y))},t)}).finally(()=>{l.clear(),c&&s&&s.removeEventListener("abort",c)});return l.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},l}function cn(r,e,t){let n=0,i=r.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;t(r[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Qe=class{#e=[];enqueue(e,t){let{priority:n=0,id:i}=t??{},o={priority:n,id:i,run:e};if(this.size===0||this.#e[this.size-1].priority>=n){this.#e.push(o);return}let s=cn(this.#e,o,(a,c)=>c.priority-a.priority);this.#e.splice(s,0,o)}setPriority(e,t){let n=this.#e.findIndex(o=>o.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[i]=this.#e.splice(n,1);this.enqueue(i.run,{priority:t,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var Je=class extends on.default{#e;#n;#i=0;#d;#p=!1;#m=!1;#u;#x=0;#g=0;#o;#s;#t;#b;#r=0;#l;#a;#S=1n;#f=new Map;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Qe,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#n=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#u=e.interval,this.#t=new e.queueClass,this.#b=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#a=e.autoStart===!1,this.#D()}get#C(){return this.#n||this.#i<this.#d}get#I(){return this.#r<this.#l}#T(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#y(),this.emit("next")}#L(){this.#k(),this.#_(),this.#s=void 0}get#P(){let e=Date.now();if(this.#o===void 0){let t=this.#x-e;if(t<0){if(this.#g>0){let n=e-this.#g;if(n<this.#u)return this.#E(this.#u-n),!0}this.#i=this.#e?this.#r:0}else return this.#E(t),!0}return!1}#E(e){this.#s===void 0&&(this.#s=setTimeout(()=>{this.#L()},e))}#v(){this.#o&&(clearInterval(this.#o),this.#o=void 0)}#N(){this.#s&&(clearTimeout(this.#s),this.#s=void 0)}#y(){if(this.#t.size===0)return this.#v(),this.emit("empty"),this.#r===0&&(this.#N(),this.emit("idle")),!1;let e=!1;if(!this.#a){let t=!this.#P;if(this.#C&&this.#I){let n=this.#t.dequeue();this.#n||(this.#i++,this.#h()),this.emit("active"),this.#g=Date.now(),n(),t&&this.#_(),e=!0}}return e}#_(){this.#n||this.#o!==void 0||(this.#o=setInterval(()=>{this.#k()},this.#u),this.#x=Date.now()+this.#u)}#k(){this.#i===0&&this.#r===0&&this.#o&&this.#v(),this.#i=this.#e?this.#r:0,this.#w(),this.#h()}#w(){for(;this.#y(););}get concurrency(){return this.#l}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#l=e,this.#w()}setPriority(e,t){if(typeof t!="number"||!Number.isFinite(t))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${t}\` (${typeof t})`);this.#t.setPriority(e,t)}async add(e,t={}){return t.id??=(this.#S++).toString(),t={timeout:this.timeout,...t},new Promise((n,i)=>{let o=Symbol(`task-${t.id}`);this.#t.enqueue(async()=>{this.#r++,this.#f.set(o,{id:t.id,priority:t.priority??0,startTime:Date.now(),timeout:t.timeout});let s;try{try{t.signal?.throwIfAborted()}catch(h){throw this.#n||this.#i--,this.#f.delete(o),h}let a=e({signal:t.signal});if(t.timeout&&(a=an(Promise.resolve(a),{milliseconds:t.timeout,message:`Task timed out after ${t.timeout}ms (queue has ${this.#r} running, ${this.#t.size} waiting)`})),t.signal){let{signal:h}=t;a=Promise.race([a,new Promise((l,f)=>{s=()=>{f(h.reason)},h.addEventListener("abort",s,{once:!0})})])}let c=await a;n(c),this.emit("completed",c)}catch(a){i(a),this.emit("error",a)}finally{s&&t.signal?.removeEventListener("abort",s),this.#f.delete(o),queueMicrotask(()=>{this.#T()})}},t),this.emit("add"),this.#y()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#a?(this.#a=!1,this.#w(),this):this}pause(){this.#a=!0}clear(){this.#t=new this.#b,this.#A()}async onEmpty(){this.#t.size!==0&&await this.#c("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#c("next",()=>this.#t.size<e)}async onIdle(){this.#r===0&&this.#t.size===0||await this.#c("idle")}async onPendingZero(){this.#r!==0&&await this.#c("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#c("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#c("rateLimitCleared")}async onError(){return new Promise((e,t)=>{let n=i=>{this.off("error",n),t(i)};this.on("error",n)})}async#c(e,t){return new Promise(n=>{let i=()=>{t&&!t()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#r}get isPaused(){return this.#a}#D(){this.#n||(this.on("add",()=>{this.#t.size>0&&this.#h()}),this.on("next",()=>{this.#h()}))}#h(){this.#n||this.#m||(this.#m=!0,queueMicrotask(()=>{this.#m=!1,this.#A()}))}#A(){let e=this.#p,t=!this.#n&&this.#i>=this.#d&&this.#t.size>0;t!==e&&(this.#p=t,this.emit(t?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#p}get isSaturated(){return this.#r===this.#l&&this.#t.size>0||this.isRateLimited&&this.#t.size>0}get runningTasks(){return[...this.#f.values()].map(e=>({...e}))}};function vt(r){let e=[X.A];return r==null?e:Array.isArray(r)?r.length===0?e:r:[r]}var un={};I(un,{base10:()=>Ja});var Ja=me({prefix:"9",name:"base10",alphabet:"0123456789"});var ln={};I(ln,{base16:()=>Ya,base16upper:()=>Xa});var Ya=C({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Xa=C({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var fn={};I(fn,{base2:()=>Za});var Za=C({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var hn={};I(hn,{base256emoji:()=>ic});var Gi=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}"),ec=Gi.reduce((r,e,t)=>(r[t]=e,r),[]),tc=Gi.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function rc(r){return r.reduce((e,t)=>(e+=ec[t],e),"")}function nc(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let i=tc[n];if(i==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(i)}return new Uint8Array(e)}var ic=Ne({prefix:"\u{1F680}",name:"base256emoji",encode:rc,decode:nc});var dn={};I(dn,{base36:()=>ae,base36upper:()=>oc});var ae=me({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),oc=me({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var pn={};I(pn,{base8:()=>sc});var sc=C({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var mn={};I(mn,{identity:()=>ac});var ac=Ne({prefix:"\0",name:"identity",encode:r=>Ui(r),decode:r=>Bi(r)});var _t={};I(_t,{code:()=>gn,decode:()=>hc,encode:()=>fc,name:()=>lc});var cc=new TextEncoder,uc=new TextDecoder,lc="json",gn=512;function fc(r){return cc.encode(JSON.stringify(r))}function hc(r){return JSON.parse(uc.decode(r))}var kt={};I(kt,{code:()=>yn,decode:()=>mc,encode:()=>pc,name:()=>dc});var dc="raw",yn=85;function pc(r){return Y(r)}function mc(r){return Y(r)}var xn={};I(xn,{identity:()=>St});var gc=Yi,Qi=128,yc=127,wc=~yc,xc=Math.pow(2,31);function Yi(r,e,t){e=e||[],t=t||0;for(var n=t;r>=xc;)e[t++]=r&255|Qi,r/=128;for(;r&wc;)e[t++]=r&255|Qi,r>>>=7;return e[t]=r|0,Yi.bytes=t-n+1,e}var bc=wn,Ec=128,Ji=127;function wn(r,n){var t=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a)throw wn.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&Ji)<<i:(s&Ji)*Math.pow(2,i),i+=7}while(s>=Ec);return wn.bytes=o-n,t}var vc=Math.pow(2,7),_c=Math.pow(2,14),kc=Math.pow(2,21),Ac=Math.pow(2,28),Sc=Math.pow(2,35),Cc=Math.pow(2,42),Ic=Math.pow(2,49),Tc=Math.pow(2,56),Lc=Math.pow(2,63),Pc=function(r){return r<vc?1:r<_c?2:r<kc?3:r<Ac?4:r<Sc?5:r<Cc?6:r<Ic?7:r<Tc?8:r<Lc?9:10},Nc={encode:gc,decode:bc,encodingLength:Pc},Dc=Nc,Ye=Dc;function Xe(r,e=0){return[Ye.decode(r,e),Ye.decode.bytes]}function De(r,e,t=0){return Ye.encode(r,e,t),e}function Re(r){return Ye.encodingLength(r)}function Ue(r,e){let t=e.byteLength,n=Re(r),i=n+Re(t),o=new Uint8Array(i+t);return De(r,o,0),De(t,o,n),o.set(e,i),new Be(r,t,e,o)}function Xi(r){let e=Y(r),[t,n]=Xe(e),[i,o]=Xe(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Be(t,i,s,e)}function Zi(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Ri(r.bytes,t.bytes)}}var Be=class{code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};var eo=0,Rc="identity",to=Y;function Bc(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return Ue(eo,to(r))}var St={code:eo,name:Rc,encode:to,digest:Bc};var vn={};I(vn,{sha256:()=>Ct,sha512:()=>It});var Uc=20;function En({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:i}){return new bn(r,e,t,n,i)}var bn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,i,o){this.name=e,this.code=t,this.encode=n,this.minDigestLength=i??Uc,this.maxDigestLength=o}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ro(n,this.code,t?.truncate):n.then(i=>ro(i,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function ro(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return Ue(e,r)}function io(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Ct=En({name:"sha2-256",code:18,encode:io("SHA-256")}),It=En({name:"sha2-512",code:19,encode:io("SHA-512")});function oo(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Fc(t,_n(r),e??H.encoder);default:return Oc(t,_n(r),e??ge.encoder)}}var so=new WeakMap;function _n(r){let e=so.get(r);if(e==null){let t=new Map;return so.set(r,t),t}return e}var k=class r{code;version;multihash;bytes;"/";constructor(e,t,n,i){this.code=t,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}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!==et)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==zc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.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,n=Ue(e,t);return r.createV1(this.code,n)}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 r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Zi(e.multihash,n.multihash)}toString(e){return oo(this,e)}toJSON(){return{"/":oo(this)}}link(){return this}[Symbol.toStringTag]="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 r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:i,multihash:o,bytes:s}=t;return new r(n,i,o,s??ao(n,i,o.bytes))}else if(t[Mc]===!0){let{version:n,multihash:i,code:o}=t,s=Xi(i);return r.create(n,o,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==et)throw new Error(`Version 0 CID must use dag-pb (code: ${et}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=ao(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,et,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,i=Y(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=i.subarray(t.multihashSize-t.digestSize),s=new Be(t.multihashCode,t.digestSize,o,i);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,m]=Xe(e.subarray(t));return t+=m,f},i=n(),o=et;if(i===18?(i=0,t=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=t,a=n(),c=n(),h=t+c,l=h-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:h}}static parse(e,t){let[n,i]=$c(e,t),o=r.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return _n(o).set(n,e),o}};function $c(r,e){switch(r[0]){case"Q":{let t=e??H;return[H.prefix,t.decode(`${H.prefix}${r}`)]}case H.prefix:{let t=e??H;return[H.prefix,t.decode(r)]}case ge.prefix:{let t=e??ge;return[ge.prefix,t.decode(r)]}case ae.prefix:{let t=e??ae;return[ae.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Fc(r,e,t){let{prefix:n}=t;if(n!==H.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return i}function Oc(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let o=t.encode(r);return e.set(n,o),o}else return i}var et=112,zc=18;function ao(r,e,t){let n=Re(r),i=n+Re(e),o=new Uint8Array(i+t.byteLength);return De(r,o,0),De(e,o,n),o.set(t,i),o}var Mc=Symbol.for("@ipld/js-cid/CID");var kn={...mn,...fn,...pn,...un,...ln,...Zr,...dn,...en,...tn,...hn},uh={...vn,...xn};function co(r=0){return new Uint8Array(r)}function Tt(r=0){return new Uint8Array(r)}function lo(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var uo=lo("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),An=lo("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Tt(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),qc={utf8:uo,"utf-8":uo,hex:kn.base16,latin1:An,ascii:An,binary:An,...kn},Lt=qc;function we(r,e="utf8"){let t=Lt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Sn=60;function Pt(r){return{Status:r.Status??0,TC:r.TC??r.flag_tc??!1,RD:r.RD??r.flag_rd??!1,RA:r.RA??r.flag_ra??!1,AD:r.AD??r.flag_ad??!1,CD:r.CD??r.flag_cd??!1,Question:(r.Question??r.questions??[]).map(e=>({name:e.name,type:X[e.type]})),Answer:(r.Answer??r.answers??[]).map(e=>({name:e.name,type:X[e.type],TTL:e.TTL??e.ttl??Sn,data:e.data instanceof Uint8Array?we(e.data):e.data}))}}var jc=4;function Cn(r,e={}){let t=new Je({concurrency:e.queryConcurrency??jc});return async(n,i={})=>{let o=new URLSearchParams;o.set("name",n),vt(i.types).forEach(a=>{o.append("type",X[a])}),i.onProgress?.(new v("dns:query",n));let s=await t.add(async()=>{let a=await fetch(`${r}?${o}`,{headers:{accept:"application/dns-json"},signal:i?.signal});if(a.status!==200)throw new Error(`Unexpected HTTP status: ${a.status} - ${a.statusText}`);let c=Pt(await a.json());return i.onProgress?.(new v("dns:response",c)),c},{signal:i.signal});if(s==null)throw new Error("No DNS response received");return s}}function fo(){return[Cn("https://cloudflare-dns.com/dns-query"),Cn("https://dns.google/resolve")]}var mo=Li(po(),1);var In=class{lru;constructor(e){this.lru=(0,mo.default)(e)}get(e,t){let n=!0,i=[];for(let o of t){let s=this.getAnswers(e,o);if(s.length===0){n=!1;break}i.push(...s)}if(n)return Pt({answers:i})}getAnswers(e,t){let n=`${e.toLowerCase()}-${t}`,i=this.lru.get(n);if(i!=null){let o=i.filter(s=>s.expires>Date.now()).map(({expires:s,value:a})=>({...a,TTL:Math.round((s-Date.now())/1e3),type:X[a.type]}));return o.length===0&&this.lru.remove(n),o}return[]}add(e,t){let n=`${e.toLowerCase()}-${t.type}`,i=this.lru.get(n)??[];i.push({expires:Date.now()+(t.TTL??Sn)*1e3,value:t}),this.lru.set(n,i)}remove(e,t){let n=`${e.toLowerCase()}-${t}`;this.lru.remove(n)}clear(){this.lru.clear()}};function go(r){return new In(r)}var Vc=1e3,Nt=class{resolvers;cache;constructor(e){this.resolvers={},this.cache=go(e.cacheSize??Vc),Object.entries(e.resolvers??{}).forEach(([t,n])=>{Array.isArray(n)||(n=[n]),t.endsWith(".")||(t=`${t}.`),this.resolvers[t]=n}),this.resolvers["."]==null&&(this.resolvers["."]=fo())}async query(e,t={}){let n=vt(t.types),i=t.cached!==!1?this.cache.get(e,n):void 0;if(i!=null)return t.onProgress?.(new v("dns:cache",i)),i;let o=`${e.split(".").pop()}.`,s=(this.resolvers[o]??this.resolvers["."]).sort(()=>Math.random()>.5?-1:1),a=[];for(let c of s){if(t.signal?.aborted===!0)break;try{let h=await c(e,{...t,types:n});for(let l of h.Answer)this.cache.add(e,l);return h}catch(h){a.push(h),t.onProgress?.(new v("dns:error",h))}}throw new bt(a,`DNS lookup of ${e} ${n} failed`)}};var X;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(X||(X={}));function yo(r={}){return new Nt(r)}function Kc(r){return r[Symbol.asyncIterator]!=null}function Hc(r){if(Kc(r))return(async()=>{for await(let e of r);})();for(let e of r);}var wo=Hc;function _e(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Tn(r,e){e==null&&(e=r.reduce((i,o)=>i+o.length,0));let t=Tt(e),n=0;for(let i of r)t.set(i,n),n+=i.length;return t}function $(r,e="utf8"){let t=Lt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var Ln={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},xo={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},bo=new globalThis.TextEncoder;function Wc(r,e){let t=Ln[e],n=xo[e];for(let i=0;i<r.length;i++)n^=BigInt(r[i]),n=BigInt.asUintN(e,n*t);return n}function Gc(r,e,t){if(t.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Ln[e],i=xo[e],o=r;for(;o.length>0;){let s=bo.encodeInto(o,t);o=o.slice(s.read);for(let a=0;a<s.written;a++)i^=BigInt(t[a]),i=BigInt.asUintN(e,i*n)}return i}function Pn(r,{size:e=32,utf8Buffer:t}={}){if(!Ln[e])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(t)return Gc(r,e,t);r=bo.encode(r)}return Wc(r,e)}var tt={hash:r=>Number(Pn(r,{size:32})),hashV:(r,e)=>Qc(tt.hash(r,e))};function Qc(r){let e=r.toString(16);return e.length%2===1&&(e=`0${e}`),$(e,"base16")}var Nn=64,Z=class{fp;h;seed;constructor(e,t,n,i=2){if(i>Nn)throw new TypeError("Invalid Fingerprint Size");let o=t.hashV(e,n),s=co(i);for(let a=0;a<s.length;a++)s[a]=o[a];s.length===0&&(s[0]=7),this.fp=s,this.h=t,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?_e(this.fp,e.fp):!1}};function ke(r,e){return Math.floor(Math.random()*(e-r))+r}var Ae=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof Z))throw new TypeError("Invalid Fingerprint");return this.contents.some(t=>e.equals(t))}add(e){if(!(e instanceof Z))throw new TypeError("Invalid Fingerprint");for(let t=0;t<this.contents.length;t++)if(this.contents[t]==null)return this.contents[t]=e,!0;return!0}swap(e){if(!(e instanceof Z))throw new TypeError("Invalid Fingerprint");let t=ke(0,this.contents.length-1),n=this.contents[t];return this.contents[t]=e,n}remove(e){if(!(e instanceof Z))throw new TypeError("Invalid Fingerprint");let t=this.contents.findIndex(n=>e.equals(n));return t>-1?(this.contents[t]=null,!0):!1}};var Jc=500,rt=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(e){this.filterSize=e.filterSize,this.bucketSize=e.bucketSize??4,this.fingerprintSize=e.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=e.hash??tt,this.seed=e.seed??ke(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=$(e));let t=new Z(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,i=(n^t.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new Ae(this.bucketSize)),this.buckets[i]==null&&(this.buckets[i]=new Ae(this.bucketSize)),this.buckets[n].add(t)||this.buckets[i].add(t))return this.count++,!0;let o=[n,i],s=o[ke(0,o.length-1)];this.buckets[s]==null&&(this.buckets[s]=new Ae(this.bucketSize));for(let a=0;a<Jc;a++){let c=this.buckets[s].swap(t);if(c!=null&&(s=(s^c.hash())%this.filterSize,this.buckets[s]==null&&(this.buckets[s]=new Ae(this.bucketSize)),this.buckets[s].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=$(e));let t=new Z(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,i=this.buckets[n]?.has(t)??!1;if(i)return i;let o=(n^t.hash())%this.filterSize;return this.buckets[o]?.has(t)??!1}remove(e){typeof e=="string"&&(e=$(e));let t=new Z(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,i=this.buckets[n]?.remove(t)??!1;if(i)return this.count--,i;let o=(n^t.hash())%this.filterSize,s=this.buckets[o]?.remove(t)??!1;return s&&this.count--,s}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Yc={1:.5,2:.84,4:.95,8:.98};function Xc(r=.001){return r>.002?2:r>1e-5?4:8}function Eo(r,e=.001){let t=Xc(e),n=Yc[t],i=Math.round(r/n),o=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*t)),Nn);return{filterSize:i,bucketSize:t,fingerprintSize:o}}var Dt=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(e){this.bucketSize=e.bucketSize??4,this.filterSize=e.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=e.fingerprintSize??2,this.scale=e.scale??2,this.hash=e.hash??tt,this.seed=e.seed??ke(0,Math.pow(2,10)),this.filterSeries=[new rt({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=$(e)),this.has(e))return!0;let t=this.filterSeries.find(n=>n.reliable);if(t==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);t=new rt({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(t)}return t.add(e)}has(e){typeof e=="string"&&(e=$(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].has(e))return!0;return!1}remove(e){typeof e=="string"&&(e=$(e));for(let t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].remove(e))return!0;return!1}get count(){return this.filterSeries.reduce((e,t)=>e+t.count,0)}};function Dn(r,e=.001,t){return new Dt({...Eo(r,e),...t??{}})}function F(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Rt=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)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}},$e=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Rt(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 Rt(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Rn=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Bt(r={}){return Zc(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Zc(r,e){e=e??{};let t=e.onEnd,n=new $e,i,o,s,a=F(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((w,b)=>{o=A=>{o=null,n.push(A);try{w(r(n))}catch(S){b(S)}return i}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=F()})}},h=w=>o!=null?o(w):(n.push(w),i),l=w=>(n=new $e,o!=null?o({error:w}):(n.push({error:w}),i)),f=w=>{if(s)return i;if(e?.objectMode!==!0&&w?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return h({done:!1,value:w})},m=w=>s?i:(s=!0,w!=null?l(w):h({done:!0})),y=()=>(n=new $e,m(),{done:!0}),x=w=>(m(w),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:y,throw:x,push:f,end:m,get readableLength(){return n.size},onEmpty:async w=>{let b=w?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let A,S;b!=null&&(A=new Promise((D,L)=>{S=()=>{L(new Rn)},b.addEventListener("abort",S)}));try{await Promise.race([a.promise,A])}finally{S!=null&&b!=null&&b?.removeEventListener("abort",S)}}},t==null)return i;let _=i;return i={[Symbol.asyncIterator](){return this},next(){return _.next()},throw(w){return _.throw(w),t!=null&&(t(w),t=void 0),{done:!0}},return(){return _.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(w){return _.end(w),t!=null&&(t(w),t=void 0),i},get readableLength(){return _.readableLength},onEmpty:w=>_.onEmpty(w)},i}var Bn=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Un=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},vo=r=>globalThis.DOMException===void 0?new Un(r):new DOMException(r),_o=r=>{let e=r.reason===void 0?vo("This operation was aborted."):r.reason;return e instanceof Error?e:vo(e)};function $n(r,e){let{milliseconds:t,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout}}=e,s,a,h=new Promise((l,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:y}=e;y.aborted&&f(_o(y)),a=()=>{f(_o(y))},y.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(l,f);return}let m=new Bn;s=o.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(y){f(y)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?l():i instanceof Error?f(i):(m.message=i??`Promise timed out after ${t} milliseconds`,f(m))},t),(async()=>{try{l(await r)}catch(y){f(y)}})()}).finally(()=>{h.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return h.clear=()=>{o.clearTimeout.call(void 0,s),s=void 0},h}var eu=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function tu(r,e,t){let n,i=new Promise((o,s)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:h,removeListener:l}=eu(r),f=async(...y)=>{let x=t.multiArgs?y:y[0];if(t.filter)try{if(!await t.filter(x))return}catch(_){n(),s(_);return}c.push(x),t.count===c.length&&(n(),o(c))},m=(...y)=>{n(),s(t.rejectionMultiArgs?y:y[0])};n=()=>{for(let y of a)l(y,f);for(let y of t.rejectionEvents)a.includes(y)||l(y,m)};for(let y of a)h(y,f);for(let y of t.rejectionEvents)a.includes(y)||h(y,m);t.signal&&t.signal.addEventListener("abort",()=>{m(t.signal.reason)},{once:!0}),t.resolveImmediately&&o(c)});if(i.cancel=n,typeof t.timeout=="number"){let o=$n(i,{milliseconds:t.timeout});return o.cancel=()=>{n(),o.clear()},o}return i}function Ut(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=tu(r,e,t),i=n.then(o=>o[0]);return i.cancel=n.cancel,i}function Fn(r,e){let t,n=function(){let i=function(){t=void 0,r()};clearTimeout(t),t=setTimeout(i,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(t)},n}var $t=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function ru(r){return r.reason}async function ce(r,e,t){if(e==null)return r;let n=t?.translateError??ru;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let i;try{return await Promise.race([r,new Promise((o,s)=>{i=()=>{s(n(e))},e.addEventListener("abort",i)})])}finally{i!=null&&e.removeEventListener("abort",i)}}var Ft=class{deferred;signal;constructor(e){this.signal=e,this.deferred=F(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new J)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function nu(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Ot=class{id;fn;options;recipients;status;timeline;controller;constructor(e,t){this.id=nu(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new J),this.cleanup())}async join(e={}){let t=new Ft(e.signal);return this.recipients.push(t),e.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await ce(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var O=class extends K{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=Fn(this.emitEmpty.bind(this),1),this.emitIdle=Fn(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,t){if(t?.signal?.throwIfAborted(),this.size===this.maxSize)throw new $t;let n=new Ot(e,t);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(t).then(i=>(this.safeDispatchEvent("completed",{detail:i}),this.safeDispatchEvent("success",{detail:{job:n,result:i}}),i)).catch(i=>{if(n.status==="queued"){for(let o=0;o<this.queue.length;o++)if(this.queue[o]===n){this.queue.splice(o,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:i}}),i})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new J)}),this.clear()}async onEmpty(e){this.size!==0&&await Ut(this,"empty",e)}async onSizeLessThan(e,t){this.size<e||await Ut(this,"next",{...t,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Ut(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=Bt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},i=c=>{c.detail!=null&&t.push(c.detail)},o=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new J("Queue aborted"))};this.addEventListener("completed",i),this.addEventListener("failure",o),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",i),this.removeEventListener("failure",o),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function ie(r){let e=new globalThis.AbortController;function t(){e.abort();for(let o of r)o?.removeEventListener!=null&&o.removeEventListener("abort",t)}for(let o of r){if(o?.aborted===!0){t();break}o?.addEventListener!=null&&o.addEventListener("abort",t)}function n(){for(let o of r)o?.removeEventListener!=null&&o.removeEventListener("abort",t)}let i=e.signal;return i.clear=n,i}var On=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=F(),this.haveNext=F()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=F(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=F(),await ce(this.readNext.promise,t?.signal,t)}};function ko(){return new On}function iu(r){return r[Symbol.asyncIterator]!=null}async function ou(r,e,t){try{await Promise.all(r.map(async n=>{for await(let i of n)await e.push(i,{signal:t}),t.throwIfAborted()})),await e.end(void 0,{signal:t})}catch(n){await e.end(n,{signal:t}).catch(()=>{})}}async function*su(r){let e=new AbortController,t=ko();ou(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*au(r){for(let e of r)yield*e}function cu(...r){let e=[];for(let t of r)iu(t)||e.push(t);return e.length===r.length?au(e):su(r)}var zt=cu;var uu=["string","number","bigint","symbol"],lu=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Ao(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(uu.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(fu(r))return"Buffer";let t=hu(r);return t||"Object"}function fu(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function hu(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(lu.includes(e))return e}var u=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};u.uint=new u(0,"uint",!0);u.negint=new u(1,"negint",!0);u.bytes=new u(2,"bytes",!0);u.string=new u(3,"string",!0);u.array=new u(4,"array",!1);u.map=new u(5,"map",!1);u.tag=new u(6,"tag",!1);u.float=new u(7,"float",!0);u.false=new u(7,"false",!0);u.true=new u(7,"true",!0);u.null=new u(7,"null",!0);u.undefined=new u(7,"undefined",!0);u.break=new u(7,"break",!0);var d=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Fe=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",du=new TextDecoder,pu=new TextEncoder;function Mt(r){return Fe&&globalThis.Buffer.isBuffer(r)}function nt(r){return r instanceof Uint8Array?Mt(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var To=Fe?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):Co(r,e,t):(r,e,t)=>t-e>64?du.decode(r.subarray(e,t)):Co(r,e,t),qt=Fe?r=>r.length>64?globalThis.Buffer.from(r):So(r):r=>r.length>64?pu.encode(r):So(r),oe=r=>Uint8Array.from(r),Oe=Fe?(r,e,t)=>Mt(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),Lo=Fe?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),nt(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let i of r)n+i.length>t.length&&(i=i.subarray(0,t.length-n)),t.set(i,n),n+=i.length;return t},Po=Fe?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function jt(r,e){if(Mt(r)&&Mt(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function So(r){let e=[],t=0;for(let n=0;n<r.length;n++){let i=r.charCodeAt(n);i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128)}return e}function Co(r,e,t){let n=[];for(;e<t;){let i=r[e],o=null,s=i>239?4:i>223?3:i>191?2:1;if(e+s<=t){let a,c,h,l;switch(s){case 1:i<128&&(o=i);break;case 2:a=r[e+1],(a&192)===128&&(l=(i&31)<<6|a&63,l>127&&(o=l));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(l=(i&15)<<12|(a&63)<<6|c&63,l>2047&&(l<55296||l>57343)&&(o=l));break;case 4:a=r[e+1],c=r[e+2],h=r[e+3],(a&192)===128&&(c&192)===128&&(h&192)===128&&(l=(i&15)<<18|(a&63)<<12|(c&63)<<6|h&63,l>65535&&l<1114112&&(o=l))}}o===null?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|o&1023),n.push(o),e+=s}return zn(n)}var Io=4096;function zn(r){let e=r.length;if(e<=Io)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Io));return t}var mu=256,it=class{constructor(e=mu){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=t.length-(this.maxCursor-this.cursor)-1;t.set(e,i)}else{if(t){let i=t.length-(this.maxCursor-this.cursor)-1;i<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Po(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=Oe(n,0,this.cursor)}else t=Lo(this.chunks,this.cursor);return e&&this.reset(),t}};var g="CBOR decode error:",ue="CBOR encode error:",ot=[];ot[23]=1;ot[24]=2;ot[25]=3;ot[26]=5;ot[27]=9;function le(r,e,t){if(r.length-e<t)throw new Error(`${g} not enough data for type`)}var T=[24,256,65536,4294967296,BigInt("18446744073709551616")];function z(r,e,t){le(r,e,1);let n=r[e];if(t.strict===!0&&n<T[0])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function M(r,e,t){le(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<T[1])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function q(r,e,t){le(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<T[2])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function j(r,e,t){le(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],i=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(t.strict===!0&&o<T[3])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(t.allowBigInt===!0)return o;throw new Error(`${g} integers outside of the safe integer range are not supported`)}function No(r,e,t,n){return new d(u.uint,z(r,e+1,n),2)}function Do(r,e,t,n){return new d(u.uint,M(r,e+1,n),3)}function Ro(r,e,t,n){return new d(u.uint,q(r,e+1,n),5)}function Bo(r,e,t,n){return new d(u.uint,j(r,e+1,n),9)}function W(r,e){return P(r,0,e.value)}function P(r,e,t){if(t<T[0]){let n=Number(t);r.push([e|n])}else if(t<T[1]){let n=Number(t);r.push([e|24,n])}else if(t<T[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<T[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<T[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,r.push(i)}else throw new Error(`${g} encountered BigInt larger than allowable range`)}}W.encodedSize=function(e){return P.encodedSize(e.value)};P.encodedSize=function(e){return e<T[0]?1:e<T[1]?2:e<T[2]?3:e<T[3]?5:9};W.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function Uo(r,e,t,n){return new d(u.negint,-1-z(r,e+1,n),2)}function $o(r,e,t,n){return new d(u.negint,-1-M(r,e+1,n),3)}function Fo(r,e,t,n){return new d(u.negint,-1-q(r,e+1,n),5)}var Mn=BigInt(-1),Oo=BigInt(1);function zo(r,e,t,n){let i=j(r,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new d(u.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${g} integers outside of the safe integer range are not supported`);return new d(u.negint,Mn-BigInt(i),9)}function Vt(r,e){let t=e.value,n=typeof t=="bigint"?t*Mn-Oo:t*-1-1;P(r,e.type.majorEncoded,n)}Vt.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*Mn-Oo:t*-1-1;return n<T[0]?1:n<T[1]?2:n<T[2]?3:n<T[3]?5:9};Vt.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function st(r,e,t,n){le(r,e,t+n);let i=Oe(r,e+t,e+t+n);return new d(u.bytes,i,t+n)}function Mo(r,e,t,n){return st(r,e,1,t)}function qo(r,e,t,n){return st(r,e,2,z(r,e+1,n))}function jo(r,e,t,n){return st(r,e,3,M(r,e+1,n))}function Vo(r,e,t,n){return st(r,e,5,q(r,e+1,n))}function Ko(r,e,t,n){let i=j(r,e+1,n);if(typeof i=="bigint")throw new Error(`${g} 64-bit integer bytes lengths not supported`);return st(r,e,9,i)}function Kt(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===u.string?qt(r.value):r.value),r.encodedBytes}function ze(r,e){let t=Kt(e);P(r,e.type.majorEncoded,t.length),r.push(t)}ze.encodedSize=function(e){let t=Kt(e);return P.encodedSize(t.length)+t.length};ze.compareTokens=function(e,t){return yu(Kt(e),Kt(t))};function yu(r,e){return r.length<e.length?-1:r.length>e.length?1:jt(r,e)}function at(r,e,t,n,i){let o=t+n;le(r,e,o);let s=new d(u.string,To(r,e+t,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=Oe(r,e+t,e+o)),s}function Ho(r,e,t,n){return at(r,e,1,t,n)}function Wo(r,e,t,n){return at(r,e,2,z(r,e+1,n),n)}function Go(r,e,t,n){return at(r,e,3,M(r,e+1,n),n)}function Qo(r,e,t,n){return at(r,e,5,q(r,e+1,n),n)}function Jo(r,e,t,n){let i=j(r,e+1,n);if(typeof i=="bigint")throw new Error(`${g} 64-bit integer string lengths not supported`);return at(r,e,9,i,n)}var Yo=ze;function Me(r,e,t,n){return new d(u.array,n,t)}function Xo(r,e,t,n){return Me(r,e,1,t)}function Zo(r,e,t,n){return Me(r,e,2,z(r,e+1,n))}function es(r,e,t,n){return Me(r,e,3,M(r,e+1,n))}function ts(r,e,t,n){return Me(r,e,5,q(r,e+1,n))}function rs(r,e,t,n){let i=j(r,e+1,n);if(typeof i=="bigint")throw new Error(`${g} 64-bit integer array lengths not supported`);return Me(r,e,9,i)}function ns(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return Me(r,e,1,1/0)}function Ht(r,e){P(r,u.array.majorEncoded,e.value)}Ht.compareTokens=W.compareTokens;Ht.encodedSize=function(e){return P.encodedSize(e.value)};function qe(r,e,t,n){return new d(u.map,n,t)}function is(r,e,t,n){return qe(r,e,1,t)}function os(r,e,t,n){return qe(r,e,2,z(r,e+1,n))}function ss(r,e,t,n){return qe(r,e,3,M(r,e+1,n))}function as(r,e,t,n){return qe(r,e,5,q(r,e+1,n))}function cs(r,e,t,n){let i=j(r,e+1,n);if(typeof i=="bigint")throw new Error(`${g} 64-bit integer map lengths not supported`);return qe(r,e,9,i)}function us(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return qe(r,e,1,1/0)}function Wt(r,e){P(r,u.map.majorEncoded,e.value)}Wt.compareTokens=W.compareTokens;Wt.encodedSize=function(e){return P.encodedSize(e.value)};function ls(r,e,t,n){return new d(u.tag,t,1)}function fs(r,e,t,n){return new d(u.tag,z(r,e+1,n),2)}function hs(r,e,t,n){return new d(u.tag,M(r,e+1,n),3)}function ds(r,e,t,n){return new d(u.tag,q(r,e+1,n),5)}function ps(r,e,t,n){return new d(u.tag,j(r,e+1,n),9)}function Gt(r,e){P(r,u.tag.majorEncoded,e.value)}Gt.compareTokens=W.compareTokens;Gt.encodedSize=function(e){return P.encodedSize(e.value)};var _u=20,ku=21,Au=22,Su=23;function ms(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${g} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new d(u.null,null,1):new d(u.undefined,void 0,1)}function gs(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return new d(u.break,void 0,1)}function qn(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${g} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${g} Infinity values are not supported`)}return new d(u.float,r,e)}function ys(r,e,t,n){return qn(jn(r,e+1),3,n)}function ws(r,e,t,n){return qn(Vn(r,e+1),5,n)}function xs(r,e,t,n){return qn(_s(r,e+1),9,n)}function Qt(r,e,t){let n=e.value;if(n===!1)r.push([u.float.majorEncoded|_u]);else if(n===!0)r.push([u.float.majorEncoded|ku]);else if(n===null)r.push([u.float.majorEncoded|Au]);else if(n===void 0)r.push([u.float.majorEncoded|Su]);else{let i,o=!1;(!t||t.float64!==!0)&&(Es(n),i=jn(ee,1),n===i||Number.isNaN(n)?(ee[0]=249,r.push(ee.slice(0,3)),o=!0):(vs(n),i=Vn(ee,1),n===i&&(ee[0]=250,r.push(ee.slice(0,5)),o=!0))),o||(Cu(n),i=_s(ee,1),ee[0]=251,r.push(ee.slice(0,9)))}}Qt.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){Es(n);let i=jn(ee,1);if(n===i||Number.isNaN(n))return 3;if(vs(n),i=Vn(ee,1),n===i)return 5}return 9};var bs=new ArrayBuffer(9),G=new DataView(bs,1),ee=new Uint8Array(bs,0);function Es(r){if(r===1/0)G.setUint16(0,31744,!1);else if(r===-1/0)G.setUint16(0,64512,!1);else if(Number.isNaN(r))G.setUint16(0,32256,!1);else{G.setFloat32(0,r);let e=G.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)G.setUint16(0,31744,!1);else if(t===0)G.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let i=t-127;i<-24?G.setUint16(0,0):i<-14?G.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):G.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function jn(r,e){if(r.length-e<2)throw new Error(`${g} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,i=t&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,t&32768?-o:o}function vs(r){G.setFloat32(0,r,!1)}function Vn(r,e){if(r.length-e<4)throw new Error(`${g} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function Cu(r){G.setFloat64(0,r,!1)}function _s(r,e){if(r.length-e<8)throw new Error(`${g} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}Qt.compareTokens=W.compareTokens;function E(r,e,t){throw new Error(`${g} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function Jt(r){return()=>{throw new Error(`${g} ${r}`)}}var p=[];for(let r=0;r<=23;r++)p[r]=E;p[24]=No;p[25]=Do;p[26]=Ro;p[27]=Bo;p[28]=E;p[29]=E;p[30]=E;p[31]=E;for(let r=32;r<=55;r++)p[r]=E;p[56]=Uo;p[57]=$o;p[58]=Fo;p[59]=zo;p[60]=E;p[61]=E;p[62]=E;p[63]=E;for(let r=64;r<=87;r++)p[r]=Mo;p[88]=qo;p[89]=jo;p[90]=Vo;p[91]=Ko;p[92]=E;p[93]=E;p[94]=E;p[95]=Jt("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)p[r]=Ho;p[120]=Wo;p[121]=Go;p[122]=Qo;p[123]=Jo;p[124]=E;p[125]=E;p[126]=E;p[127]=Jt("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)p[r]=Xo;p[152]=Zo;p[153]=es;p[154]=ts;p[155]=rs;p[156]=E;p[157]=E;p[158]=E;p[159]=ns;for(let r=160;r<=183;r++)p[r]=is;p[184]=os;p[185]=ss;p[186]=as;p[187]=cs;p[188]=E;p[189]=E;p[190]=E;p[191]=us;for(let r=192;r<=215;r++)p[r]=ls;p[216]=fs;p[217]=hs;p[218]=ds;p[219]=ps;p[220]=E;p[221]=E;p[222]=E;p[223]=E;for(let r=224;r<=243;r++)p[r]=Jt("simple values are not supported");p[244]=E;p[245]=E;p[246]=E;p[247]=ms;p[248]=Jt("simple values are not supported");p[249]=ys;p[250]=ws;p[251]=xs;p[252]=E;p[253]=E;p[254]=E;p[255]=gs;var te=[];for(let r=0;r<24;r++)te[r]=new d(u.uint,r,1);for(let r=-1;r>=-24;r--)te[31-r]=new d(u.negint,r,1);te[64]=new d(u.bytes,new Uint8Array(0),1);te[96]=new d(u.string,"",1);te[128]=new d(u.array,0,1);te[160]=new d(u.map,0,1);te[244]=new d(u.false,!1,1);te[245]=new d(u.true,!0,1);te[246]=new d(u.null,null,1);function Kn(r){switch(r.type){case u.false:return oe([244]);case u.true:return oe([245]);case u.null:return oe([246]);case u.bytes:return r.value.length?void 0:oe([64]);case u.string:return r.value===""?oe([96]):void 0;case u.array:return r.value===0?oe([128]):void 0;case u.map:return r.value===0?oe([160]):void 0;case u.uint:return r.value<24?oe([Number(r.value)]):void 0;case u.negint:if(r.value>=-24)return oe([31-Number(r.value)])}}var Tu={float64:!1,mapSorter:Nu,quickEncodeToken:Kn},As=Object.freeze({float64:!0,mapSorter:Du,quickEncodeToken:Kn});function Lu(){let r=[];return r[u.uint.major]=W,r[u.negint.major]=Vt,r[u.bytes.major]=ze,r[u.string.major]=Yo,r[u.array.major]=Ht,r[u.map.major]=Wt,r[u.tag.major]=Gt,r[u.float.major]=Qt,r}var Wn=Lu(),Hn=new it,Xt=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${ue} object contains circular references`);return new r(t,e)}},xe={null:new d(u.null,null),undefined:new d(u.undefined,void 0),true:new d(u.true,!0),false:new d(u.false,!1),emptyArray:new d(u.array,0),emptyMap:new d(u.map,0)},be={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new d(u.float,r):r>=0?new d(u.uint,r):new d(u.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new d(u.uint,r):new d(u.negint,r)},Uint8Array(r,e,t,n){return new d(u.bytes,r)},string(r,e,t,n){return new d(u.string,r)},boolean(r,e,t,n){return r?xe.true:xe.false},null(r,e,t,n){return xe.null},undefined(r,e,t,n){return xe.undefined},ArrayBuffer(r,e,t,n){return new d(u.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new d(u.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[xe.emptyArray,new d(u.break)]:xe.emptyArray;n=Xt.createCheck(n,r);let i=[],o=0;for(let s of r)i[o++]=Yt(s,t,n);return t.addBreakTokens?[new d(u.array,r.length),i,new d(u.break)]:[new d(u.array,r.length),i]},Object(r,e,t,n){let i=e!=="Object",o=i?r.keys():Object.keys(r),s=i?r.size:o.length;if(!s)return t.addBreakTokens===!0?[xe.emptyMap,new d(u.break)]:xe.emptyMap;n=Xt.createCheck(n,r);let a=[],c=0;for(let h of o)a[c++]=[Yt(h,t,n),Yt(i?r.get(h):r[h],t,n)];return Pu(a,t),t.addBreakTokens?[new d(u.map,s),a,new d(u.break)]:[new d(u.map,s),a]}};be.Map=be.Object;be.Buffer=be.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))be[`${r}Array`]=be.DataView;function Yt(r,e={},t){let n=Ao(r),i=e&&e.typeEncoders&&e.typeEncoders[n]||be[n];if(typeof i=="function"){let s=i(r,n,e,t);if(s!=null)return s}let o=be[n];if(!o)throw new Error(`${ue} unsupported type: ${n}`);return o(r,n,e,t)}function Pu(r,e){e.mapSorter&&r.sort(e.mapSorter)}function Nu(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let i=t.type.major,o=Wn[i].compareTokens(t,n);return o===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),o}function Du(r,e){if(r[0]instanceof d&&e[0]instanceof d){let t=r[0],n=e[0];return t._keyBytes||(t._keyBytes=ks(t.value)),n._keyBytes||(n._keyBytes=ks(n.value)),jt(t._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function ks(r){return Zt(r,Wn,As)}function Ss(r,e,t,n){if(Array.isArray(e))for(let i of e)Ss(r,i,t,n);else t[e.type.major](r,e,n)}function Zt(r,e,t){let n=Yt(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let i=t.quickEncodeToken(n);if(i)return i;let o=e[n.type.major];if(o.encodedSize){let s=o.encodedSize(n,t),a=new it(s);if(o(a,n,t),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return nt(a.chunks[0])}}return Hn.reset(),Ss(Hn,n,e,t),Hn.toBytes(!0)}function Ce(r,e){return e=Object.assign({},Tu,e),Zt(r,Wn,e)}var Ru={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},er=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=te[e];if(t===void 0){let n=p[e];if(!n)throw new Error(`${g} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;t=n(this.data,this._pos,i,this.options)}return this._pos+=t.encodedLength,t}},ct=Symbol.for("DONE"),tr=Symbol.for("BREAK");function Bu(r,e,t){let n=[];for(let i=0;i<r.value;i++){let o=je(e,t);if(o===tr){if(r.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed array`)}if(o===ct)throw new Error(`${g} found array but not enough entries (got ${i}, expected ${r.value})`);n[i]=o}return n}function Uu(r,e,t){let n=t.useMaps===!0,i=n?void 0:{},o=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=je(e,t);if(a===tr){if(r.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(a===ct)throw new Error(`${g} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${g} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&o.has(a)||!n&&a in i))throw new Error(`${g} found repeat map key "${a}"`);let c=je(e,t);if(c===ct)throw new Error(`${g} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?o.set(a,c):i[a]=c}return n?o:i}function je(r,e){if(r.done())return ct;let t=r.next();if(t.type===u.break)return tr;if(t.type.terminal)return t.value;if(t.type===u.array)return Bu(t,r,e);if(t.type===u.map)return Uu(t,r,e);if(t.type===u.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=je(r,e);return e.tags[t.value](n)}throw new Error(`${g} tag not supported (${t.value})`)}throw new Error("unsupported")}function Gn(r,e){if(!(r instanceof Uint8Array))throw new Error(`${g} data to decode must be a Uint8Array`);e=Object.assign({},Ru,e);let t=e.tokenizer||new er(r,e),n=je(t,e);if(n===ct)throw new Error(`${g} did not find any content to decode`);if(n===tr)throw new Error(`${g} got unexpected break`);return[n,r.subarray(t.pos())]}function re(r,e){let[t,n]=Gn(r,e);if(n.length>0)throw new Error(`${g} too many terminals, data makes no sense`);return t}var rr=class extends O{has(e){return this.find(e)!=null}find(e){return this.queue.find(t=>e.equals(t.options.peerId))}};var fe="/",Is=new TextEncoder().encode(fe),nr=Is[0],he=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=$(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==nr)throw new Error("Invalid key")}toString(e="utf8"){return we(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(fe))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Is),this._buf[0]!==nr){let e=new Uint8Array(this._buf.byteLength+1);e.fill(nr,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===nr;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let i=0;i<t.length;i++){if(n.length<i+1)return!1;let o=t[i],s=n[i];if(o<s)return!0;if(o>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(fe).slice(1)}type(){return $u(this.baseNamespace())}name(){return Fu(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(fe)||(e+=fe),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(fe):new r(e.slice(0,-1).join(fe))}child(e){return this.toString()===fe?e:e.toString()===fe?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...Ou(e.map(t=>t.namespaces()))])}};function $u(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Fu(r){let e=r.split(":");return e[e.length-1]}function Ou(r){return[].concat(...r)}function zu(r){return r[Symbol.asyncIterator]!=null}function Mu(r){if(zu(r))return(async()=>{let n=new Uint8Array(0);for await(let i of r)n=Tn([n,i],n.length+i.length);return n})();let e=[],t=0;for(let n of r)e.push(n),t+=n.byteLength;return Tn(e,t)}var ir=Mu;function or({enumerable:r=!0,configurable:e=!1}={}){return{enumerable:r,configurable:e,writable:!1}}function*qu(r,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[t,n]of e.entries()){let i=[...r,t],o=k.asCID(n);o!=null?yield[i.join("/"),o]:typeof n=="object"&&(yield*Qn(n,i))}else{let t=k.asCID(e);t!=null?yield[r.join("/"),t]:yield*Qn(e,r)}}function*Qn(r,e){if(r==null||r instanceof Uint8Array)return;let t=k.asCID(r);t!=null&&(yield[e.join("/"),t]);for(let[n,i]of Object.entries(r)){let o=[...e,n];yield*qu(o,i)}}function*ju(r,e){if(Array.isArray(e))for(let[t,n]of e.entries()){let i=[...r,t];yield i.join("/"),typeof n=="object"&&k.asCID(n)==null&&(yield*Jn(n,i))}else yield*Jn(e,r)}function*Jn(r,e){if(!(r==null||typeof r!="object"))for(let[t,n]of Object.entries(r)){let i=[...e,t];yield i.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&k.asCID(n)==null&&(yield*ju(i,n))}}function Vu(r,e){let t=r;for(let[n,i]of e.entries()){if(t=t[i],t==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(s=>`[${JSON.stringify(s)}]`).join("")}`);let o=k.asCID(t);if(o!=null)return{value:o,remaining:e.slice(n+1).join("/")}}return{value:t}}var Yn=class{cid;bytes;value;asBlock;constructor({cid:e,bytes:t,value:n}){if(e==null||t==null||typeof n>"u")throw new Error("Missing required argument");this.cid=e,this.bytes=t,this.value=n,this.asBlock=this,Object.defineProperties(this,{cid:or(),bytes:or(),value:or(),asBlock:or()})}links(){return Qn(this.value,[])}tree(){return Jn(this.value,[])}get(e="/"){return Vu(this.value,e.split("/").filter(Boolean))}};function sr({bytes:r,cid:e,value:t,codec:n}){let i=t!==void 0?t:n?.decode(r);if(i===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new Yn({cid:e,bytes:r,value:i})}var ar=class extends Error{static name="AlreadyPinnedError";name="AlreadyPinnedError"},ut=class extends Error{static name="BlockPinnedError";name="BlockPinnedError"},cr=class extends Error{static name="InvalidDatastoreVersionError";name="InvalidDatastoreVersionError"},ur=class extends Error{static name="InvalidConfigurationError";name="InvalidConfigurationError"},lr=class extends AggregateError{static name="GetFailedError";name="GetFailedError"},fr=class extends AggregateError{static name="LoadBlockFailedError";name="LoadBlockFailedError"},lt=class extends Error{static name="BlockNotFoundWhileOfflineError";name="BlockNotFoundWhileOfflineError"};var Ps="/pin/",Ts="/pinned-block/",Xn=ae,Ls=1;function hr(r){return r.version===0&&(r=r.toV1()),new he(`${Ps}${r.toString(Xn)}`)}var dr=class{datastore;blockstore;getCodec;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.getCodec=n}async*add(e,t={}){let n=hr(e);if(await this.datastore.has(n))throw new ar("Already pinned");let i=Math.round(t.depth??1/0);if(i<0)throw new Pe("Depth must be greater than or equal to 0");let o=new O({concurrency:Ls});for await(let a of this.#e(e,o,{...t,depth:i}))await this.#n(a,c=>c.pinnedBy.find(h=>_e(h,e.bytes))!=null?!1:(c.pinCount++,c.pinnedBy.push(e.bytes),!0),t),yield a;let s={depth:i,metadata:t.metadata??{}};await this.datastore.put(n,Ce(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let i=await this.getCodec(e.code),o=await ir(this.blockstore.get(e,n)),s=sr({bytes:o,cid:e,codec:i});yield e;for(let[,a]of s.links())yield*await t.add(async()=>this.#e(a,t,{...n,depth:n.depth-1}))}async#n(e,t,n){let i=new he(`${Ts}${Xn.encode(e.multihash.bytes)}`),o={pinCount:0,pinnedBy:[]};try{o=re(await this.datastore.get(i,n))}catch(a){if(a.name!=="NotFoundError")throw a}if(t(o)){if(o.pinCount===0&&await this.datastore.has(i)){await this.datastore.delete(i);return}await this.datastore.put(i,Ce(o),n),n.onProgress?.(new v("helia:pin:add",e))}}async*rm(e,t={}){let n=hr(e),i=await this.datastore.get(n,t),o=re(i);await this.datastore.delete(n,t);let s=new O({concurrency:Ls});for await(let a of this.#e(e,s,{...t,depth:o.depth}))await this.#n(a,c=>(c.pinCount--,c.pinnedBy=c.pinnedBy.filter(h=>_e(h,e.bytes)),!0),{...t,depth:o.depth}),yield a}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:Ps+(e.cid!=null?`${e.cid.toString(ae)}`:"")},e)){let i=k.parse(t.toString().substring(5),ae),o=re(n);yield{cid:i,...o}}}async isPinned(e,t={}){let n=new he(`${Ts}${Xn.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}async get(e,t){let n=hr(e),i=await this.datastore.get(n,t);return re(i)}async setMetadata(e,t,n){let i=hr(e),o=await this.datastore.get(i,n),s=re(o);s.metadata=t??{},await this.datastore.put(i,Ce(s),n)}};var pr=class extends Error{static name="InsufficientProvidersError";constructor(e="Insufficient providers found"){super(e),this.name="InsufficientProvidersError"}},Ie=class extends Error{static name="NoRoutersAvailableError";constructor(e="No routers available"){super(e),this.name="NoRoutersAvailableError"}},mr=class extends Error{static name="UnknownHashAlgorithmError";constructor(e="Unknown hash algorithm"){super(e),this.name="UnknownHashAlgorithmError"}},gr=class extends Error{static name="UnknownCodecError";constructor(e="Unknown codec"){super(e),this.name="UnknownCodecError"}};var Ku=5,yr=class{log;routers;providerLookupConcurrency;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[],this.providerLookupConcurrency=t.providerLookupConcurrency??Ku,this.findProviders=e.metrics?.traceFunction("helia.routing.findProviders",this.findProviders.bind(this),{optionsIndex:1})??this.findProviders,this.provide=e.metrics?.traceFunction("helia.routing.provide",this.provide.bind(this),{optionsIndex:1})??this.provide,this.cancelReprovide=e.metrics?.traceFunction("helia.routing.cancelReprovide",this.cancelReprovide.bind(this),{optionsIndex:1})??this.cancelReprovide,this.put=e.metrics?.traceFunction("helia.routing.put",this.put.bind(this),{optionsIndex:2})??this.put,this.get=e.metrics?.traceFunction("helia.routing.get",this.get.bind(this),{optionsIndex:1})??this.get,this.findPeer=e.metrics?.traceFunction("helia.routing.findPeer",this.findPeer.bind(this),{optionsIndex:1})??this.findPeer,this.getClosestPeers=e.metrics?.traceFunction("helia.routing.getClosestPeers",this.getClosestPeers.bind(this),{optionsIndex:1})??this.getClosestPeers}async start(){await de(...this.routers)}async stop(){await pe(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new Ie("No content routers available");let n=new rr({concurrency:this.providerLookupConcurrency}),i=0,o=[],s=this,a=0;this.log("findProviders for %c start using routers %s",e,this.routers.map(h=>h.toString()).join(", "));let c=Te(this.routers,"findProviders").map(async function*(h){let l=0;try{for await(let f of h.findProviders(e,t))l++,yield f}catch(f){o.push(f)}finally{s.log("router %s found %d providers for %c",h,l,e),a++,a===c.length&&n.size===0&&n.emitIdle()}});for await(let h of zt(n.toGenerator(),...c))if(h!=null){if(h.multiaddrs.length===0){if(n.find(h.id)!=null)continue;n.add(async()=>{try{let l=await this.findPeer(h.id,t);return l.multiaddrs.length===0?null:{...l,protocols:h.protocols,routing:h.routing}}catch(l){return this.log.error("could not load multiaddrs for peer %p - %e",h.id,l),null}},{peerId:h.id,signal:t.signal}).catch(l=>{this.log.error("could not load multiaddrs for peer %p - %e",h.id,l)});continue}i++,yield h}this.log("findProviders finished, found %d providers for %c",i,e)}async provide(e,t={}){if(this.routers.length===0)throw new Ie("No content routers available");await Promise.all(Te(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async cancelReprovide(e,t={}){await Promise.all(Te(this.routers,"cancelReprovide").map(async n=>{await n.cancelReprovide(e,t)}))}async put(e,t,n){await Promise.all(Te(this.routers,"put").map(async i=>{await i.put(e,t,n)}))}async get(e,t){let n=[],i;try{i=await Promise.any(Te(this.routers,"get").map(async o=>{try{return await o.get(e,t)}catch(s){this.log("router %s failed with %e",o,s),n.push(s)}}))}catch{}if(i==null)throw new lr(n,`Failed to get value key ${we(e,"base58btc")}`);return i}async findPeer(e,t){if(this.routers.length===0)throw new Ie("No peer routers available");let n=this,i=zt(...Te(this.routers,"findPeer").map(o=>(async function*(){try{yield await o.findPeer(e,t)}catch(s){n.log.error(s)}})()));for await(let o of i)if(o!=null)return o;throw new gt("Could not find peer in routing")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new Ie("No peer routers available");for await(let n of zt(...Te(this.routers,"getClosestPeers").map(i=>i.getClosestPeers(e,t))))n!=null&&(yield n)}};function Te(r,e){return r.filter(t=>t[e]!=null)}var V=class extends Error{static name="AbortError";name="AbortError";constructor(e="The operation was aborted",...t){super(e,...t)}};async function wr(r,e,t,n){let i=new V(n?.errorMessage);n?.errorCode!=null&&(i.code=n.errorCode);let o=n?.errorEvent??"error";return t?.aborted===!0?Promise.reject(i):new Promise((s,a)=>{function c(){ei(t,"abort",f),ei(r,e,h),ei(r,o,l)}let h=m=>{try{if(n?.filter?.(m)===!1)return}catch(y){c(),a(y);return}c(),s(m)},l=m=>{if(c(),m instanceof Error){a(m);return}a(m.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},f=()=>{c(),a(i)};Zn(t,"abort",f),Zn(r,e,h),Zn(r,o,l)})}function Zn(r,e,t){r!=null&&(Ns(r)?r.addEventListener(e,t):r.addListener(e,t))}function ei(r,e,t){r!=null&&(Ns(r)?r.removeEventListener(e,t):r.removeListener(e,t))}function Ns(r){return typeof r.addEventListener=="function"&&typeof r.removeEventListener=="function"}var xr=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var br=class{deferred;signal;constructor(e){this.signal=e,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new V)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Hu(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Er=class{id;fn;options;recipients;status;timeline;controller;constructor(e,t){this.id=Hu(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new V),this.cleanup())}async join(e={}){let t=new br(e.signal);return this.recipients.push(t),e.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await ce(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};function ti(r,e){let t,n=function(){let i=function(){t=void 0,r()};clearTimeout(t),t=setTimeout(i,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(t)},n}var ft=class extends K{concurrency;maxSize;queue;pending;sort;autoStart;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=e.autoStart??!0,this.sort=e.sort,this.queue=[],this.emitEmpty=ti(this.emitEmpty.bind(this),1),this.emitIdle=ti(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(e,t){if(t?.signal?.throwIfAborted(),this.size===this.maxSize)throw new xr;let n=new Er(e,t);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(t).then(i=>(this.safeDispatchEvent("success",{detail:{job:n,result:i}}),i)).catch(i=>{if(n.status==="queued"){for(let o=0;o<this.queue.length;o++)if(this.queue[o]===n){this.queue.splice(o,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:i}}),i})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new V)}),this.clear()}async onEmpty(e){this.size!==0&&await wr(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await wr(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await wr(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=Bt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},i=c=>{c.detail!=null&&t.push(c.detail.result)},o=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new V("Queue aborted"))};this.addEventListener("success",i),this.addEventListener("failure",o),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("success",i),this.removeEventListener("failure",o),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var vr="lock:worker:request-read",_r="lock:worker:abort-read-request",kr="lock:worker:release-read",Ar="lock:master:grant-read",Sr="lock:master:error-read",Cr="lock:worker:request-write",Ir="lock:worker:abort-write-request",Tr="lock:worker:release-write",Lr="lock:master:grant-write",Pr="lock:master:error-write",Nr="lock:worker:finalize",Dr="mortice",Ds={singleProcess:!1};var ri=(r,e,t,n,i,o,s,a,c)=>h=>{if(h.data==null)return;let l={type:h.data.type,name:h.data.name,identifier:h.data.identifier};l.type===i&&r.safeDispatchEvent(t,{detail:{name:l.name,identifier:l.identifier,handler:async()=>{e.postMessage({type:c,name:l.name,identifier:l.identifier}),await new Promise(f=>{let m=y=>{if(y?.data==null)return;let x={type:y.data.type,name:y.data.name,identifier:y.data.identifier};x.type===a&&x.identifier===l.identifier&&(e.removeEventListener("message",m),f())};e.addEventListener("message",m)})},onError:f=>{e.postMessage({type:s,name:l.name,identifier:l.identifier,error:{message:f.message,name:f.name,stack:f.stack}})}}}),l.type===o&&r.safeDispatchEvent(n,{detail:{name:l.name,identifier:l.identifier}}),l.type===Nr&&r.safeDispatchEvent("finalizeRequest",{detail:{name:l.name}})};var Rs=(r=10)=>Math.random().toString().substring(2,r+2);var Rr=class{name;channel;constructor(e){this.name=e,this.channel=new BroadcastChannel(Dr)}readLock(e){return this.sendRequest(vr,_r,Ar,Sr,kr,e)}writeLock(e){return this.sendRequest(Cr,Ir,Lr,Pr,Tr,e)}finalize(){this.channel.postMessage({type:Nr,name:this.name}),this.channel.close()}async sendRequest(e,t,n,i,o,s){s?.signal?.throwIfAborted();let a=Rs();return this.channel.postMessage({type:e,identifier:a,name:this.name}),new Promise((c,h)=>{let l=()=>{this.channel.postMessage({type:t,identifier:a,name:this.name})};s?.signal?.addEventListener("abort",l,{once:!0});let f=m=>{if(m.data?.identifier===a&&(m.data?.type===n&&(this.channel.removeEventListener("message",f),s?.signal?.removeEventListener("abort",l),c(()=>{this.channel.postMessage({type:o,identifier:a,name:this.name})})),m.data.type===i)){this.channel.removeEventListener("message",f),s?.signal?.removeEventListener("abort",l);let y=new Error;m.data.error!=null&&(y.message=m.data.error.message,y.name=m.data.error.name,y.stack=m.data.error.stack),h(y)}};this.channel.addEventListener("message",f)})}};var Bs=r=>{if(r=Object.assign({},Ds,r),!!globalThis.document||r.singleProcess){let t=new BroadcastChannel(Dr),n=new K;return t.addEventListener("message",ri(n,t,"requestReadLock","abortReadLockRequest",vr,_r,Sr,kr,Ar)),t.addEventListener("message",ri(n,t,"requestWriteLock","abortWriteLockRequest",Cr,Ir,Pr,Tr,Lr)),n}return new Rr(r.name)};var Le=new Map,ht;function Us(r){return typeof r?.readLock=="function"&&typeof r?.writeLock=="function"}function Wu(r){if(ht==null&&(ht=Bs(r),!Us(ht))){let e=ht;e.addEventListener("requestReadLock",t=>{let n=t.detail.name,i=t.detail.identifier,o=Le.get(n);if(o==null)return;let s=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==i||s.abort()};e.addEventListener("abortReadLockRequest",a),o.readLock({signal:s.signal}).then(async c=>{await t.detail.handler().finally(()=>{c()})}).catch(c=>{t.detail.onError(c)}).finally(()=>{e.removeEventListener("abortReadLockRequest",a)})}),e.addEventListener("requestWriteLock",t=>{let n=t.detail.name,i=t.detail.identifier,o=Le.get(n);if(o==null)return;let s=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==i||s.abort()};e.addEventListener("abortWriteLockRequest",a),o.writeLock({signal:s.signal}).then(async c=>{await t.detail.handler().finally(()=>{c()})}).catch(c=>{t.detail.onError(c)}).finally(()=>{e.removeEventListener("abortWriteLockRequest",a)})}),e.addEventListener("finalizeRequest",t=>{let n=t.detail.name,i=Le.get(n);i?.finalize()})}return ht}async function ni(r,e){let t,n,i=new Promise((s,a)=>{t=s,n=a}),o=()=>{n(new V)};return e?.signal?.addEventListener("abort",o,{once:!0}),r.add(async()=>{await new Promise(s=>{t(()=>{e?.signal?.removeEventListener("abort",o),s()})})},{signal:e?.signal}).catch(s=>{n(s)}),i}var $s=(r,e)=>{let t=Le.get(r);if(t!=null)return t;let n=Wu(e);if(Us(n))return t=n,Le.set(r,t),t;let i=new ft({concurrency:1}),o;return t={async readLock(s){if(o!=null)return ni(o,s);o=new ft({concurrency:e.concurrency,autoStart:!1});let a=o,c=ni(o,s);return i.add(async()=>{a.start(),await a.onIdle().then(()=>{o===a&&(o=null)})}),c},async writeLock(s){return o=null,ni(i,s)},finalize:()=>{Le.delete(r)},queue:i},Le.set(r,t),e.autoFinalize===!0&&i.addEventListener("idle",()=>{t.finalize()},{once:!0}),t};var Gu={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function ii(r){let e=Object.assign({},Gu,r);return $s(e.name,e)}var Br=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=ii({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await de(this.child),this.started=!0}async stop(){await pe(this.child),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){n?.signal?.throwIfAborted();let i=await this.lock.readLock();try{return await this.child.put(e,t,n)}finally{i()}}async*putMany(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.putMany(e,t)}finally{n()}}async*get(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.get(e,t)}finally{n()}}async*getMany(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{yield*this.child.getMany(e,t)}finally{n()}}async delete(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.writeLock();try{if(await this.pins.isPinned(e))throw new ut("Block was pinned - please unpin and try again");await this.child.delete(e,t)}finally{n()}}async*deleteMany(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.writeLock();try{let i=this;yield*this.child.deleteMany((async function*(){for await(let o of e){if(await i.pins.isPinned(o))throw new ut("Block was pinned - please unpin and try again");yield o}})(),t)}finally{n()}}async has(e,t={}){t?.signal?.throwIfAborted();let n=await this.lock.readLock();try{return await this.child.has(e,t)}finally{n()}}async*getAll(e={}){e?.signal?.throwIfAborted();let t=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{t()}}createSession(e,t){return t?.signal?.throwIfAborted(),this.child.createSession(e,t)}};var oi=new he("/version"),Fs=1;async function Os(r){if(!await r.has(oi)){await r.put(oi,$(`${Fs}`));return}let e=await r.get(oi),t=we(e);if(parseInt(t,10)!==Fs)throw new cr("Invalid datastore version, a datastore migration may be required")}var ci={};I(ci,{code:()=>ai,decode:()=>il,decodeOptions:()=>tl,encode:()=>nl,encodeOptions:()=>Zu,name:()=>rl,toByteView:()=>Ms});var zs=42;function Ms(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function Qu(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=k.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new d(u.tag,zs),new d(u.bytes,t)]}function Ju(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Yu(r){if(Number.isNaN(r))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(r===1/0||r===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function Xu(r){for(let e of r.keys())if(typeof e!="string"||e.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var si={float64:!0,typeEncoders:{Map:Xu,Object:Qu,undefined:Ju,number:Yu}},Zu={...si,typeEncoders:{...si.typeEncoders}};function el(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return k.decode(r.subarray(1))}var Ur={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Ur.tags[zs]=el;var tl={...Ur,tags:Ur.tags.slice()},rl="dag-cbor",ai=113,nl=r=>Ce(r,si),il=r=>re(Ms(r),Ur);var mi={};I(mi,{code:()=>pi,decode:()=>js,encode:()=>qs,format:()=>ml,name:()=>pl,parse:()=>yl,stringify:()=>ml});var ui=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===u.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===u.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[u.uint.major](e,t){this.prefix(e);let n=String(t.value),i=[];for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);e.push(i)}[u.negint.major](e,t){this[u.uint.major](e,t)}[u.bytes.major](e,t){throw new Error(`${ue} unsupported type: Uint8Array`)}[u.string.major](e,t){this.prefix(e);let n=qt(JSON.stringify(t.value));e.push(n.length>32?nt(n):n)}[u.array.major](e,t){this.prefix(e),this.inRecursive.push({type:u.array,elements:0}),e.push([91])}[u.map.major](e,t){this.prefix(e),this.inRecursive.push({type:u.map,elements:0}),e.push([123])}[u.tag.major](e,t){}[u.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===u.array)e.push([93]);else if(s.type===u.map)e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(t.value===void 0)throw new Error(`${ue} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.value),i=[],o=!1;for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s),!o&&(i[s]===46||i[s]===101||i[s]===69)&&(o=!0);o||(i.push(46),i.push(48)),e.push(i)}};function ol(r,e){if(Array.isArray(r[0])||Array.isArray(e[0]))throw new Error(`${ue} complex map keys are not supported`);let t=r[0],n=e[0];if(t.type!==u.string||n.type!==u.string)throw new Error(`${ue} non-string map keys are not supported`);if(t<n)return-1;if(t>n)return 1;throw new Error(`${ue} unexpected duplicate map keys, this is not supported`)}var sl={addBreakTokens:!0,mapSorter:ol};function li(r,e){return e=Object.assign({},sl,e),Zt(r,new ui,e)}var Ve=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${g} unexpected end of input at position ${this._pos}`);for(let t=0;t<e.length;t++)if(this.data[this._pos++]!==e[t])throw new Error(`${g} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,i=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(t=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new d(u.uint,0,this._pos-e);if(i([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${g} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${g} unexpected token at position ${this._pos}`);n=!0,this._pos++,i([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,i([48,49,50,51,52,53,54,55,56,57]));let o=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(o);return n?new d(u.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new d(s>=0?u.uint:u.negint,s,this._pos-e):new d(s>=0?u.uint:u.negint,BigInt(o),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${g} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let o=this._pos,s=0;o<this.data.length&&s<65536;o++,s++){let a=this.data[o];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,o));return this._pos=o+1,new d(u.string,c,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${g} unexpected end of unicode escape sequence at position ${this._pos}`);let o=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${g} unexpected unicode escape character at position ${this._pos}`);o=o*16+a,this._pos++}return o},i=()=>{let o=this.ch(),s=null,a=o>239?4:o>223?3:o>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${g} unexpected unicode sequence at position ${this._pos}`);let c,h,l,f;switch(a){case 1:o<128&&(s=o);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(f=(o&31)<<6|c&63,f>127&&(s=f));break;case 3:c=this.data[this._pos+1],h=this.data[this._pos+2],(c&192)===128&&(h&192)===128&&(f=(o&15)<<12|(c&63)<<6|h&63,f>2047&&(f<55296||f>57343)&&(s=f));break;case 4:c=this.data[this._pos+1],h=this.data[this._pos+2],l=this.data[this._pos+3],(c&192)===128&&(h&192)===128&&(l&192)===128&&(f=(o&15)<<18|(c&63)<<12|(h&63)<<6|l&63,f>65535&&f<1114112&&(s=f))}s===null?(s=65533,a=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=a};for(;!this.done();){let o=this.ch(),s;switch(o){case 92:if(this._pos++,this.done())throw new Error(`${g} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:t.push(s);break;case 98:t.push(8);break;case 116:t.push(9);break;case 110:t.push(10);break;case 102:t.push(12);break;case 114:t.push(13);break;case 117:t.push(n());break;default:throw new Error(`${g} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new d(u.string,zn(t),this._pos-e);default:if(o<32)throw new Error(`${g} invalid control character at position ${this._pos}`);o<128?(t.push(o),this._pos++):i()}}throw new Error(`${g} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new d(u.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new d(u.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new d(u.null,null,4);case 102:return this.expect([102,97,108,115,101]),new d(u.false,!1,5);case 116:return this.expect([116,114,117,101]),new d(u.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${g} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new d(u.break,void 0,1);if(this.ch()!==44)throw new Error(`${g} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new d(u.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new d(u.break,void 0,1);if(this.ch()!==44)throw new Error(`${g} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new d(u.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${g} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${g} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function fi(r,e){return e=Object.assign({tokenizer:new Ve(r,e)},e),re(r,e)}function cl(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}function ul(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=k.asCID(r);if(!e)return null;let t=e.toString();return[new d(u.map,1/0,1),new d(u.string,"/",1),new d(u.string,t,t.length),new d(u.break,void 0,1)]}function $r(r){let e=ye.encode(r).slice(1);return[new d(u.map,1/0,1),new d(u.string,"/",1),new d(u.map,1/0,1),new d(u.string,"bytes",5),new d(u.string,e,e.length),new d(u.break,void 0,1),new d(u.break,void 0,1)]}function ne(r){return $r(new Uint8Array(r.buffer,r.byteOffset,r.byteLength))}function ll(r){return $r(new Uint8Array(r))}function fl(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function hl(r){if(Number.isNaN(r))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(r===1/0||r===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var dl={typeEncoders:{Object:ul,Buffer:$r,Uint8Array:$r,Int8Array:ne,Uint16Array:ne,Int16Array:ne,Uint32Array:ne,Int32Array:ne,Float32Array:ne,Float64Array:ne,Uint8ClampedArray:ne,BigInt64Array:ne,BigUint64Array:ne,DataView:ne,ArrayBuffer:ll,undefined:fl,number:hl}},hi=class extends Ve{constructor(e,t){super(e,t),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(e.type===u.map){let t=this._next();if(t.type===u.string&&t.value==="/"){let n=this._next();if(n.type===u.string){if(this._next().type!==u.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new d(u.tag,42,0)}if(n.type===u.map){let i=this._next();if(i.type===u.string&&i.value==="bytes"){let o=this._next();if(o.type===u.string){for(let a=0;a<2;a++)if(this._next().type!==u.break)throw new Error("Invalid encoded Bytes form");let s=ye.decode(`m${o.value}`);return new d(u.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},di={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};di.tags[42]=k.parse;var pl="dag-json",pi=297,qs=r=>li(r,dl),js=r=>{let e=cl(r),t=Object.assign(di,{tokenizer:new hi(e,di)});return fi(e,t)},ml=r=>gl.decode(qs(r));var gl=new TextDecoder,yl=r=>js(wl.encode(r)),wl=new TextEncoder;var Ei={};I(Ei,{code:()=>bi,createLink:()=>Zs,createNode:()=>Xs,decode:()=>Pl,encode:()=>Ll,name:()=>Tl,prepare:()=>wi,validate:()=>xi});var xl=new TextDecoder;function gi(r,e){let t=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=r.length)throw new Error("protobuf: unexpected end of data");let i=r[e++];if(t+=n<28?(i&127)<<n:(i&127)*2**n,i<128)break}return[t,e]}function Fr(r,e){let t;[t,e]=gi(r,e);let n=e+t;if(t<0||n<0)throw new Error("protobuf: invalid length");if(n>r.length)throw new Error("protobuf: unexpected end of data");return[r.subarray(e,n),n]}function Vs(r,e){let t;return[t,e]=gi(r,e),[t&7,t>>3,e]}function bl(r){let e={},t=r.length,n=0;for(;n<t;){let i,o;if([i,o,n]=Vs(r,n),o===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=Fr(r,n)}else if(o===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=Fr(r,n),e.Name=xl.decode(s)}else if(o===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(i!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Tsize`);[e.Tsize,n]=gi(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${o}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Ks(r){let e=r.length,t=0,n,i=!1,o;for(;t<e;){let a,c;if([a,c,t]=Vs(r,t),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(o)throw new Error("protobuf: (PBNode) duplicate Data section");[o,t]=Fr(r,t),n&&(i=!0)}else if(c===2){if(i)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let h;[h,t]=Fr(r,t),n.push(bl(h))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(t>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return o&&(s.Data=o),s.Links=n||[],s}var Ws=new TextEncoder,Hs=2**32,El=2**31;function vl(r,e){let t=e.length;if(typeof r.Tsize=="number"){if(r.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(r.Tsize))throw new Error("Tsize too large for encoding");t=dt(e,t,r.Tsize)-1,e[t]=24}if(typeof r.Name=="string"){let n=Ws.encode(r.Name);t-=n.length,e.set(n,t),t=dt(e,t,n.length)-1,e[t]=18}return r.Hash&&(t-=r.Hash.length,e.set(r.Hash,t),t=dt(e,t,r.Hash.length)-1,e[t]=10),e.length-t}function Gs(r){let e=kl(r),t=new Uint8Array(e),n=e;if(r.Data&&(n-=r.Data.length,t.set(r.Data,n),n=dt(t,n,r.Data.length)-1,t[n]=10),r.Links)for(let i=r.Links.length-1;i>=0;i--){let o=vl(r.Links[i],t.subarray(0,n));n-=o,n=dt(t,n,o)-1,t[n]=18}return t}function _l(r){let e=0;if(r.Hash){let t=r.Hash.length;e+=1+t+Ke(t)}if(typeof r.Name=="string"){let t=Ws.encode(r.Name).length;e+=1+t+Ke(t)}return typeof r.Tsize=="number"&&(e+=1+Ke(r.Tsize)),e}function kl(r){let e=0;if(r.Data){let t=r.Data.length;e+=1+t+Ke(t)}if(r.Links)for(let t of r.Links){let n=_l(t);e+=1+n+Ke(n)}return e}function dt(r,e,t){e-=Ke(t);let n=e;for(;t>=El;)r[e++]=t&127|128,t/=128;for(;t>=128;)r[e++]=t&127|128,t>>>=7;return r[e]=t,n}function Ke(r){return r%2===0&&r++,Math.floor((Al(r)+6)/7)}function Al(r){let e=0;return r>=Hs&&(r=Math.floor(r/Hs),e=32),r>=65536&&(r>>>=16,e+=16),r>=256&&(r>>>=8,e+=8),e+Sl[r]}var Sl=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];var Cl=["Data","Links"],Il=["Hash","Name","Tsize"],yi=new TextEncoder;function Js(r,e){if(r===e)return 0;let t=r.Name?yi.encode(r.Name):[],n=e.Name?yi.encode(e.Name):[],i=t.length,o=n.length;for(let s=0,a=Math.min(i,o);s<a;++s)if(t[s]!==n[s]){i=t[s],o=n[s];break}return i<o?-1:o<i?1:0}function Qs(r,e){return!Object.keys(r).some(t=>!e.includes(t))}function Ys(r){if(typeof r.asCID=="object"){let t=k.asCID(r);if(!t)throw new TypeError("Invalid DAG-PB form");return{Hash:t}}if(typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let e={};if(r.Hash){let t=k.asCID(r.Hash);try{t||(typeof r.Hash=="string"?t=k.parse(r.Hash):r.Hash instanceof Uint8Array&&(t=k.decode(r.Hash)))}catch(n){throw new TypeError(`Invalid DAG-PB form: ${n.message}`)}t&&(e.Hash=t)}if(!e.Hash)throw new TypeError("Invalid DAG-PB form");return typeof r.Name=="string"&&(e.Name=r.Name),typeof r.Tsize=="number"&&(e.Tsize=r.Tsize),e}function wi(r){if((r instanceof Uint8Array||typeof r=="string")&&(r={Data:r}),typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let e={};if(r.Data!==void 0)if(typeof r.Data=="string")e.Data=yi.encode(r.Data);else if(r.Data instanceof Uint8Array)e.Data=r.Data;else throw new TypeError("Invalid DAG-PB form");if(r.Links!==void 0)if(Array.isArray(r.Links))e.Links=r.Links.map(Ys),e.Links.sort(Js);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function xi(r){if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form");if(!Qs(r,Cl))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(r.Data!==void 0&&!(r.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(r.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e<r.Links.length;e++){let t=r.Links[e];if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!Qs(t,Il))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(t.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(t.Hash==null||!t.Hash["/"]||t.Hash["/"]!==t.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(t.Name!==void 0&&typeof t.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(t.Tsize!==void 0){if(typeof t.Tsize!="number"||t.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(t.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(e>0&&Js(t,r.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function Xs(r,e=[]){return wi({Data:r,Links:e})}function Zs(r,e,t){return Ys({Hash:t,Name:r,Tsize:e})}function ea(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var Tl="dag-pb",bi=112;function Ll(r){xi(r);let e={};return r.Links&&(e.Links=r.Links.map(t=>{let n={};return t.Hash&&(n.Hash=t.Hash.bytes),t.Name!==void 0&&(n.Name=t.Name),t.Tsize!==void 0&&(n.Tsize=t.Tsize),n})),r.Data&&(e.Data=r.Data),Gs(e)}function Pl(r){let e=ea(r),t=Ks(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(i=>{let o={};try{o.Hash=k.decode(i.Hash)}catch{}if(!o.Hash)throw new Error("Invalid Hash field found in link, expected CID");return i.Name!==void 0&&(o.Name=i.Name),i.Tsize!==void 0&&(o.Tsize=i.Tsize),o})),n}function He(r){return r?.then!=null}function ta(r=[],e){let t={[bi]:Ei,[yn]:kt,[ai]:ci,[pi]:mi,[gn]:_t};return r.forEach(n=>{t[n.code]=n}),async n=>{let i=t[n];if(i==null&&e!=null){let o=e(n);He(o)?i=await o:i=o,t[i.code]=i}if(i!=null)return i;throw new gr(`Could not load codec for ${n}`)}}function ra(r=[],e){let t={[Ct.code]:Ct,[It.code]:It,[St.code]:St};return r.forEach(n=>{t[n.code]=n}),async n=>{let i=t[n];if(i==null&&e!=null){let o=e(n);He(o)?i=await o:i=o,t[i.code]=i}if(i!=null)return i;throw new mr(`No hasher configured for multihash code 0x${n.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`)}}var Or=class r extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=r.name;code=r.code;constructor(e="Not Found"){super(e)}};var zr=class{has(e,t){return Promise.reject(new Error(".has is not implemented"))}put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,t){for await(let{cid:n,bytes:i}of e)await this.put(n,i,t),yield n}get(e,t){throw new Error(".get is not implemented")}async*getMany(e,t){for await(let n of e)yield{cid:n,bytes:this.get(n,t)}}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,t){for await(let n of e)await this.delete(n,t),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var Mr=0,We=class extends Error{static name="IdentityHashDigestTooLongError";name="IdentityHashDigestTooLongError"},qr=class extends zr{child;maxDigestLength;constructor(e,t){super(),this.child=e,this.maxDigestLength=t?.maxDigestLength}put(e,t,n){if(e.multihash.code===Mr){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new We(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);return n?.signal?.throwIfAborted(),e}return this.child==null?(n?.signal?.throwIfAborted(),e):this.child.put(e,t,n)}*get(e,t){if(e.multihash.code===Mr){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new We(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);t?.signal?.throwIfAborted(),yield e.multihash.digest;return}if(this.child==null)throw t?.signal?.throwIfAborted(),new Or;yield*this.child.get(e,t)}has(e,t){if(e.multihash.code===Mr){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new We(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);return t?.signal?.throwIfAborted(),!0}return this.child==null?(t?.signal?.throwIfAborted(),!1):this.child.has(e,t)}delete(e,t){if(e.code===Mr){if(this.maxDigestLength!=null&&e.multihash.digest.byteLength>this.maxDigestLength)throw new We(`Identity digest too long - ${e.multihash.digest.byteLength} > this.maxDigestLength`);t?.signal?.throwIfAborted();return}if(this.child!=null)return this.child.delete(e,t)}*getAll(e){this.child!=null&&(yield*this.child.getAll(e)),e?.signal?.throwIfAborted()}};function Nl(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var jr=Nl;function Dl(r){return r[Symbol.asyncIterator]!=null}function Rl(r,e){let t=0;if(Dl(r))return(async function*(){for await(let c of r)await e(c,t++)&&(yield c)})();let n=jr(r),{value:i,done:o}=n.next();if(o===!0)return(function*(){})();let s=e(i,t++);if(typeof s.then=="function")return(async function*(){await s&&(yield i);for(let c of n)await e(c,t++)&&(yield c)})();let a=e;return(function*(){s===!0&&(yield i);for(let c of n)a(c,t++)&&(yield c)})()}var Vr=Rl;function Bl(r){return r[Symbol.asyncIterator]!=null}function na(r){return r?.then!=null}function Ul(r,e){let t=0;if(Bl(r))return(async function*(){for await(let c of r){let h=e(c,t++);na(h)&&await h,yield c}})();let n=jr(r),{value:i,done:o}=n.next();if(o===!0)return(function*(){})();let s=e(i,t++);if(typeof s?.then=="function")return(async function*(){await s,yield i;for(let c of n){let h=e(c,t++);na(h)&&await h,yield c}})();let a=e;return(function*(){yield i;for(let c of n)a(c,t++),yield c})()}var vi=Ul;var Fl=128,Kr=class{child;getHasher;log;logger;components;constructor(e,t={}){this.log=e.logger.forComponent("helia:networked-storage"),this.logger=e.logger,this.components=e,this.child=new qr(e.blockstore,{maxDigestLength:t.maxIdentityHashDigestLength??Fl}),this.getHasher=e.getHasher}async put(e,t,n={}){return await this.child.has(e,n)?(n.onProgress?.(new v("blocks:put:duplicate",e)),e):(n.onProgress?.(new v("blocks:put:providers:notify",e)),await Promise.all(this.components.blockBrokers.map(async i=>i.announce?.(e,n))),n.onProgress?.(new v("blocks:put:blockstore:put",e)),this.child.put(e,t,n))}async*putMany(e,t={}){let n=Vr(e,async({cid:o})=>{let s=await this.child.has(o,t);return s&&t.onProgress?.(new v("blocks:put-many:duplicate",o)),!s}),i=vi(n,async({cid:o})=>{t.onProgress?.(new v("blocks:put-many:providers:notify",o)),await Promise.all(this.components.blockBrokers.map(async s=>s.announce?.(o,t)))});t.onProgress?.(new v("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(i,t)}async*get(e,t={}){let n=await this.child.has(e,t),i=t.offline===!0;if(!n){if(i)throw new lt("The block was present in the blockstore and the node is running offline so cannot fetch it");let o=await this.getHasher(e.multihash.code);t?.signal?.throwIfAborted(),t.onProgress?.(new v("blocks:get:providers:get",e));let s=await ia(e,this.components.blockBrokers,o,{...t,log:this.log});t.onProgress?.(new v("blocks:get:blockstore:put",e)),await this.child.put(e,s,t),t.onProgress?.(new v("blocks:get:providers:notify",e)),await Promise.all(this.components.blockBrokers.map(async a=>a.announce?.(e,t))),yield s;return}t.onProgress?.(new v("blocks:get:blockstore:get",e)),yield*this.child.get(e,t)}async*getMany(e,t={}){t.onProgress?.(new v("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(vi(e,async n=>{let i=await this.child.has(n,t),o=t.offline===!0;if(!i){if(o)throw new lt("The block was present in the blockstore and the node is running offline so cannot fetch it");let s=await this.getHasher(n.multihash.code);t?.signal?.throwIfAborted(),t.onProgress?.(new v("blocks:get-many:providers:get",n));let a=await ia(n,this.components.blockBrokers,s,{...t,log:this.log});t.onProgress?.(new v("blocks:get-many:blockstore:put",n)),await this.child.put(n,a,t),t.onProgress?.(new v("blocks:get-many:providers:notify",n)),await Promise.all(this.components.blockBrokers.map(async c=>c.announce?.(n,t)))}}))}async delete(e,t={}){t.onProgress?.(new v("blocks:delete:blockstore:delete",e)),await this.child.delete(e,t)}async*deleteMany(e,t={}){t.onProgress?.(new v("blocks:delete-many:blockstore:delete-many")),yield*this.child.deleteMany((async function*(){for await(let n of e)yield n})(),t)}async has(e,t={}){return this.child.has(e,t)}async*getAll(e={}){e.onProgress?.(new v("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}},Hr=class extends Kr{started;constructor(e,t={}){super(e,t),this.started=!1}isStarted(){return this.started}async start(){await de(this.child,...this.components.blockBrokers),this.started=!0}async stop(){await pe(this.child,...this.components.blockBrokers),this.started=!1}unwrap(){return this.child}createSession(e,t){let n=this.components.blockBrokers.map(i=>i.createSession==null?i:i.createSession(t));return new _i({blockstore:this.child,blockBrokers:n,getHasher:this.getHasher,logger:this.logger},{root:e})}},_i=class extends Kr{closeController;constructor(e,t){super(e),this.closeController=new AbortController,this.closeController.signal,this.log=e.logger.forComponent(`helia:session-storage:${t.root}`)}close(){this.closeController.abort()}async put(e,t,n={}){let i=ie([this.closeController.signal,n.signal]);try{return await super.put(e,t,{...n,signal:i})}finally{i.clear()}}async*putMany(e,t={}){let n=ie([this.closeController.signal,t.signal]);try{yield*super.putMany(e,{...t,signal:n})}finally{n.clear()}}async*get(e,t={}){let n=ie([this.closeController.signal,t.signal]);try{yield*super.get(e,{...t,signal:n})}finally{n.clear()}}async*getMany(e,t={}){let n=ie([this.closeController.signal,t.signal]);try{yield*super.getMany(e,{...t,signal:n})}finally{n.clear()}}async delete(e,t={}){let n=ie([this.closeController.signal,t.signal]);try{await super.delete(e,{...t,signal:n})}finally{n.clear()}}async*deleteMany(e,t={}){let n=ie([this.closeController.signal,t.signal]);try{yield*super.deleteMany(e,{...t,signal:n})}finally{n.clear()}}async has(e,t={}){let n=ie([this.closeController.signal,t.signal]);try{return await super.has(e,{...t,signal:n})}finally{n.clear()}}async*getAll(e={}){let t=ie([this.closeController.signal,e.signal]);try{yield*super.getAll({...e,signal:t})}finally{t.clear()}}};function Ol(r){return typeof r.retrieve=="function"}var zl=(r,e)=>{if(e==null)throw new Pe(`No hasher configured for multihash code 0x${r.multihash.code.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`);return async t=>{let n,i=e.digest(t,{truncate:r.multihash.digest.byteLength});if(He(i)?n=await i:n=i,!_e(n.digest,r.multihash.digest))throw new yt("Hash of downloaded block did not match multihash from passed CID")}};async function ia(r,e,t,n){let i=zl(r,t),o=new AbortController,s=ie([o.signal,n.signal]);o.signal;let a=[];for(let c of e)Ol(c)&&a.push(c);if(a.length===0)throw new ur(`No block brokers capable of retrieving blocks are configured, the CID ${r} cannot be fetched from the network`);try{return await Promise.any(a.map(async c=>{try{let h=!1,l=await c.retrieve(r,{...n,signal:s,validateFn:async f=>{await i(f),n.signal?.throwIfAborted(),h=!0}});return h||(await i(l),n.signal?.throwIfAborted()),l}catch(h){throw n.log.error("could not retrieve verified block for %c - %e",r,h),h}}))}catch(c){throw new fr(c.errors,`Failed to load block for ${r}`)}finally{o.abort(),s.clear()}}var Wr=class extends K{initialPeerSearchComplete;requests;name;log;logger;minProviders;maxProviders;providers;evictionFilter;initialProviders;constructor(e,t){super(),this.name=t.name,this.logger=e.logger,this.log=e.logger.forComponent(this.name),this.requests=new Map,this.minProviders=t.minProviders??1,this.maxProviders=t.maxProviders??5,this.providers=[],this.evictionFilter=Dn(this.maxProviders),this.initialProviders=t.providers??[]}async retrieve(e,t={}){let n=ye.encode(e.multihash.bytes),i=this.requests.get(n);if(i!=null)return this.log("join existing request for %c",e),i;let o=F();if(this.requests.set(n,o.promise),this.providers.length===0){let l=!1;this.initialPeerSearchComplete==null&&(l=!0,this.log=this.logger.forComponent(`${this.name}:${e}`),this.initialPeerSearchComplete=this.findProviders(e,this.minProviders,t));try{await ce(this.initialPeerSearchComplete,t.signal),l&&this.log("found initial session peers for %c",e)}catch(f){throw l&&this.log("failed to find initial session peers for %c - %e",e,f),this.requests.delete(n),o.reject(f),f}}let s=!1,a=new O({concurrency:this.maxProviders});a.addEventListener("failure",l=>{this.log.error("error querying provider %s, evicting from session - %e",l.detail.job.options.provider,l.detail.error),this.evict(l.detail.job.options.provider)}),a.addEventListener("success",l=>{s=!0,o.resolve(l.detail.result)}),a.addEventListener("idle",()=>{if(s){this.log.trace("session idle, found block");return}if(t.signal?.aborted===!0){this.log.trace("session idle, signal aborted");return}Promise.resolve().then(async()=>{this.log("no session peers had block for for %c, finding new providers",e);for(let l=0;l<this.minProviders&&this.providers.length!==0;l++){let f=this.providers[Math.floor(Math.random()*this.providers.length)];this.evict(f)}await this.findProviders(e,this.minProviders,t),this.log("found new providers re-retrieving %c",e),this.requests.delete(n),o.resolve(await this.retrieve(e,t))}).catch(l=>{this.log.error("could not find new providers for %c - %e",e,l),o.reject(l)})});let c=l=>{a.add(async()=>this.queryProvider(e,l.detail,t),{provider:l.detail}).catch(f=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,f)})};this.addEventListener("provider",c),Promise.all([...this.providers].map(async l=>a.add(async()=>this.queryProvider(e,l,t),{provider:l}))).catch(l=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,l)});let h=()=>{o.reject(new J(t.signal?.reason??"Session aborted")),a.abort()};t.signal?.addEventListener("abort",h);try{return await ce(o.promise,t.signal)}finally{this.removeEventListener("provider",c),t.signal?.removeEventListener("abort",h),a.clear(),this.requests.delete(n)}}evict(e){this.evictionFilter.add(this.toEvictionKey(e));let t=this.providers.findIndex(n=>this.equals(n,e));t!==-1&&this.providers.splice(t,1)}isEvicted(e){return this.evictionFilter.has(this.toEvictionKey(e))}hasProvider(e){return!!(this.providers.find(t=>this.equals(t,e))!=null||this.isEvicted(e))}async findProviders(e,t,n){let i=F(),o=0;return Promise.resolve().then(async()=>{if(this.log("finding %d-%d new provider(s) for %c",t,this.maxProviders,e),this.initialProviders.length>0)for(;o<t&&this.initialProviders.length>0;){let s=this.initialProviders.pop();if(s==null)break;let a=await this.convertToProvider(s,n);if(n.signal?.aborted===!0)break;if(a!=null&&!this.hasProvider(a)&&(this.log("found %d/%d new providers",o,this.maxProviders),this.providers.push(a),this.safeDispatchEvent("provider",{detail:a}),o++,o===t&&(this.log("session is ready"),i.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers",o);break}}if(o<this.maxProviders)for await(let s of this.findNewProviders(e,n)){if(o===this.maxProviders||n.signal?.aborted===!0)break;if(!this.hasProvider(s)&&(this.log("found %d/%d new providers",o,this.maxProviders),this.providers.push(s),this.safeDispatchEvent("provider",{detail:s}),o++,o===t&&(this.log("session is ready"),i.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers",o);break}}if(this.log("found %d/%d new session peers",o,this.maxProviders),o<t)throw new pr(`Found ${o} of ${t} ${this.name} providers for ${e}`)}).catch(s=>{this.log.error("error searching routing for potential session peers for %c - %e",e,s),i.reject(s)}),i.promise}};function oa(r){return e=>new ki(e,r)}function sa(r){return e=>new Ai(e,r)}function aa(r){return e=>new Si(e,r)}var pt=class{components;constructor(e,t={}){this.components=e}async*walk(e,t){let n=this.getQueue(),i=Vr(n.toGenerator(t),a=>a!=null),o=!1,s=async a=>{let c=a.cid,h=await ir(this.components.blockstore.get(c,a)),l=sr({cid:c,bytes:h,codec:await this.components.getCodec(c.code)});for(let[,f]of l.links())t?.includeChild?.(f,l)!==!1&&n.add(s,{...a,cid:f,depth:a.depth+1,path:[...a.path,f]}).catch(m=>{o||i.throw(m)});return{block:l,depth:a.depth,path:a.path}};n.add(s,{...t,cid:e,depth:0,path:[e]}).catch(a=>{o||i.throw(a)});try{yield*i}finally{o=!0,n.abort()}}},ki=class extends pt{getQueue(){return new O({concurrency:1,sort:(e,t)=>e.options.depth===t.options.depth?0:e.options.depth<t.options.depth?1:-1})}},Ai=class extends pt{getQueue(){return new O({concurrency:1,sort:(e,t)=>e.options.depth===t.options.depth?0:e.options.depth<t.options.depth?-1:1})}},Si=class extends pt{getQueue(){return new O({concurrency:1})}};var Ci=class{libp2p;blockstore;datastore;events;pins;logger;routing;getCodec;getHasher;dns;metrics;log;constructor(e){this.logger=e.logger??ji(),this.log=this.logger.forComponent("helia"),this.getHasher=ra(e.hashers,e.loadHasher),this.getCodec=ta(e.codecs,e.loadCodec),this.dns=e.dns??yo(),this.metrics=e.metrics,this.libp2p=e.libp2p,this.events=new K;let t={blockstore:e.blockstore,datastore:e.datastore,logger:this.logger,libp2p:this.libp2p,blockBrokers:[],getHasher:this.getHasher,getCodec:this.getCodec,dns:this.dns,metrics:this.metrics,...e.components??{}};this.routing=t.routing=new yr(t,{routers:(e.routers??[]).flatMap(i=>{typeof i=="function"&&(i=i(t));let o=[i],s=jl(i);s!=null&&o.push(s);let a=Vl(i);return a!=null&&o.push(a),o}),providerLookupConcurrency:e.providerLookupConcurrency});let n=new Hr(t,e);this.pins=new dr(e.datastore,n,this.getCodec),this.blockstore=new Br(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,t.blockBrokers=e.blockBrokers.map(i=>i(t))}async start(){await Os(this.datastore),await de(this.blockstore,this.datastore,this.routing,this.libp2p),this.events.dispatchEvent(new CustomEvent("start",{detail:this}))}async stop(){await pe(this.blockstore,this.datastore,this.routing,this.libp2p),this.events.dispatchEvent(new CustomEvent("stop",{detail:this}))}async gc(e={}){let t=await this.blockstore.lock.writeLock();try{let n=this,i=this.blockstore.unwrap();this.log("gc start"),await wo(i.deleteMany((async function*(){for await(let{cid:o}of i.getAll())try{if(await n.pins.isPinned(o,e))continue;yield o,e.onProgress?.(new v("helia:gc:deleted",o))}catch(s){n.log.error("error during gc - %e",s),e.onProgress?.(new v("helia:gc:error",s))}})()))}finally{t()}this.log("gc finished")}};function jl(r){return r?.[Pi]}function Vl(r){return r?.[Ni]}return pa(Kl);})();
|
|
13
13
|
return HeliaUtils}));
|
|
14
14
|
//# sourceMappingURL=index.min.js.map
|