@helia/utils 3.0.0-3a1dd561 → 3.0.0-883ff053

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,4 +1,4 @@
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 xe=Object.defineProperty;var Qt=Object.getOwnPropertyDescriptor;var Jt=Object.getOwnPropertyNames;var Kt=Object.prototype.hasOwnProperty;var v=(r,e)=>{for(var t in e)xe(r,t,{get:e[t],enumerable:!0})},Ht=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Jt(e))!Kt.call(r,s)&&s!==t&&xe(r,s,{get:()=>e[s],enumerable:!(n=Qt(e,s))||n.enumerable});return r};var Xt=r=>Ht(xe({},"__esModule",{value:!0}),r);var qn={};v(qn,{AbstractSession:()=>Ye,AlreadyPinnedError:()=>We,BlockNotFoundWhileOfflineError:()=>st,BlockPinnedError:()=>Ze,DecryptionFailedError:()=>it,GetFailedError:()=>rt,InvalidConfigurationError:()=>tt,InvalidDatastoreVersionError:()=>et,LoadBlockFailedError:()=>nt,NaturalOrderGraphWalker:()=>ge,breadthFirstWalker:()=>Tn,depthFirstWalker:()=>kn,isCID:()=>Nn,isPromise:()=>Fn,naturalOrderWalker:()=>Dn});var Un=new Uint8Array(0);function ht(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 N(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return j(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return j(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function ft(r){return new TextEncoder().encode(r)}function dt(r){return new TextDecoder().decode(r)}function Gt(r){return r?.buffer instanceof ArrayBuffer}function j(r){return Gt(r)?r:r.slice()}var Se={};v(Se,{base32:()=>$,base32hex:()=>or,base32hexpad:()=>cr,base32hexpadupper:()=>ur,base32hexupper:()=>ar,base32pad:()=>sr,base32padupper:()=>ir,base32upper:()=>nr,base32z:()=>lr});function Yt(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),a=o.charCodeAt(0);if(n[a]!==255)throw new TypeError(o+" is ambiguous");if(n[a]=i,t){var c=o.toLowerCase().charCodeAt(0),l=o.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),l!==a&&(n[l]=i)}}var d=r.length,b=r.charAt(0),u=Math.log(d)/Math.log(256),f=Math.log(256)/Math.log(d);function y(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var g=0,x=0,w=0,E=h.length;w!==E&&h[w]===0;)w++,g++;for(var L=(E-w)*f+1>>>0,S=new Uint8Array(L);w!==E;){for(var z=h[w],q=0,A=L-1;(z!==0||q<x)&&A!==-1;A--,q++)z+=256*S[A]>>>0,S[A]=z%d>>>0,z=z/d>>>0;if(z!==0)throw new Error("Non-zero carry");x=q,w++}for(var D=L-x;D!==L&&S[D]===0;)D++;for(var se=b.repeat(g);D<L;++D)se+=r.charAt(S[D]);return se}function I(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var g=0;if(h[g]!==" "){for(var x=0,w=0;h[g]===b;)x++,g++;for(var E=(h.length-g)*u+1>>>0,L=new Uint8Array(E);h[g];){var S=n[h.charCodeAt(g)];if(S===255)return;for(var z=0,q=E-1;(S!==0||z<w)&&q!==-1;q--,z++)S+=d*L[q]>>>0,L[q]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");w=z,g++}if(h[g]!==" "){for(var A=E-w;A!==E&&L[A]===0;)A++;for(var D=new Uint8Array(x+(E-A)),se=x;A!==E;)D[se++]=L[A++];return D}}}function p(h){var g=I(h);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:y,decodeUnsafe:I,decode:p}}var Wt=Yt,Zt=Wt,pt=Zt;var ve=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")}},_e=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let s=t.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 mt(this,e)}},we=class{decoders;constructor(e){this.decoders=e}or(e){return mt(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 mt(r,e){return new we({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ee=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new ve(e,t,n),this.decoder=new _e(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function V({name:r,prefix:e,encode:t,decode:n}){return new Ee(r,e,t,n)}function M({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:s,decode:i}=pt(t,r,n);return V({prefix:e,name:r,encode:s,decode:o=>N(i(o))})}function er(r,e,t,n){let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),o=0,a=0,c=0;for(let l=0;l<s;++l){let d=e[r[l]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|d,o+=t,o>=8&&(o-=8,i[c++]=255&a>>o)}if(o>=t||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return i}function tr(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>t;)o-=t,i+=e[s&a>>o];if(o!==0&&(i+=e[s&a<<t-o]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function rr(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let s=r[n].toLowerCase(),i=r[n].toUpperCase();s!==r[n]&&(t[s]=n),i!==r[n]&&(t[i]=n)}return t}function m({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:s=!1}){let i=rr(n,s);return V({prefix:e,name:r,encode(o){return tr(o,n,t)},decode(o){return er(o,i,t,r)}})}var $=m({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),nr=m({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),sr=m({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),ir=m({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),or=m({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),ar=m({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),cr=m({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),ur=m({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),lr=m({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ie={};v(Ie,{base36:()=>G,base36upper:()=>hr});var G=M({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),hr=M({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Ae={};v(Ae,{base58btc:()=>k,base58flickr:()=>fr});var k=M({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),fr=M({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var dr=xt,bt=128,pr=127,mr=~pr,br=Math.pow(2,31);function xt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=br;)e[t++]=r&255|bt,r/=128;for(;r&mr;)e[t++]=r&255|bt,r>>>=7;return e[t]=r|0,xt.bytes=t-n+1,e}var gr=Pe,xr=128,gt=127;function Pe(r,n){var t=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw Pe.bytes=0,new RangeError("Could not decode varint");o=r[i++],t+=s<28?(o&gt)<<s:(o&gt)*Math.pow(2,s),s+=7}while(o>=xr);return Pe.bytes=i-n,t}var yr=Math.pow(2,7),vr=Math.pow(2,14),_r=Math.pow(2,21),wr=Math.pow(2,28),Er=Math.pow(2,35),Sr=Math.pow(2,42),Ir=Math.pow(2,49),Ar=Math.pow(2,56),Pr=Math.pow(2,63),Cr=function(r){return r<yr?1:r<vr?2:r<_r?3:r<wr?4:r<Er?5:r<Sr?6:r<Ir?7:r<Ar?8:r<Pr?9:10},Lr={encode:dr,decode:gr,encodingLength:Cr},zr=Lr,Y=zr;function W(r,e=0){return[Y.decode(r,e),Y.decode.bytes]}function R(r,e,t=0){return Y.encode(r,e,t),e}function Q(r){return Y.encodingLength(r)}function K(r,e){let t=e.byteLength,n=Q(r),s=n+Q(t),i=new Uint8Array(s+t);return R(r,i,0),R(t,i,n),i.set(e,s),new J(r,t,e,i)}function yt(r){let e=N(r),[t,n]=W(e),[s,i]=W(e.subarray(n)),o=e.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new J(t,s,o,e)}function vt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ht(r.bytes,t.bytes)}}var J=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=j(n),this.bytes=j(s)}};function _t(r,e){let{bytes:t,version:n}=r;return n===0?Tr(t,Ce(r),e??k.encoder):Dr(t,Ce(r),e??$.encoder)}var wt=new WeakMap;function Ce(r){let e=wt.get(r);if(e==null){let t=new Map;return wt.set(r,t),t}return e}var _=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=j(s),this["/"]=this.bytes}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!==ee)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Nr)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=K(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&&vt(e.multihash,n.multihash)}toString(e){return _t(this,e)}toJSON(){return{"/":_t(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:s,multihash:i,bytes:o}=t;return new r(n,s,i,o??Et(n,s,i.bytes))}else if(t[Fr]===!0){let{version:n,multihash:s,code:i}=t,o=yt(s);return r.create(n,i,o)}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!==ee)throw new Error(`Version 0 CID must use dag-pb (code: ${ee}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=Et(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ee,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,s=N(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=s.subarray(t.multihashSize-t.digestSize),o=new J(t.multihashCode,t.digestSize,i,s);return[t.version===0?r.createV0(o):r.createV1(t.codec,o),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[b,u]=W(e.subarray(t));return t+=u,b},s=n(),i=ee;if(s===18?(s=0,t=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=t,a=n(),c=n(),l=t+c,d=l-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:d,size:l}}static parse(e,t){let[n,s]=kr(e,t),i=r.decode(s);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ce(i).set(n,e),i}};function kr(r,e){switch(r[0]){case"Q":{let t=e??k;return[k.prefix,t.decode(`${k.prefix}${r}`)]}case k.prefix:{let t=e??k;return[k.prefix,t.decode(r)]}case $.prefix:{let t=e??$;return[$.prefix,t.decode(r)]}case G.prefix:{let t=e??G;return[G.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 Tr(r,e,t){let{prefix:n}=t;if(n!==k.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return s}function Dr(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let i=t.encode(r);return e.set(n,i),i}else return s}var ee=112,Nr=18;function Et(r,e,t){let n=Q(r),s=n+Q(e),i=new Uint8Array(s+t.byteLength);return R(r,i,0),R(e,i,n),i.set(t,s),i}var Fr=Symbol.for("@ipld/js-cid/CID");var qr=20;function ze({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:s}){return new Le(r,e,t,n,s)}var Le=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,s,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=s??qr,this.maxDigestLength=i}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?St(n,this.code,t?.truncate):n.then(s=>St(s,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function St(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 K(e,r)}var Te={};v(Te,{base64:()=>ke,base64pad:()=>Mr,base64url:()=>Ur,base64urlpad:()=>jr});var ke=m({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Mr=m({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ur=m({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),jr=m({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var De={};v(De,{identity:()=>Vr});var At=0,Br="identity",Pt=N;function Or(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 K(At,Pt(r))}var Vr={code:At,name:Br,encode:Pt,digest:Or};function Ct(r=0){return new Uint8Array(r)}function oe(r=0){return new Uint8Array(r)}function $r(r){return r?.buffer instanceof ArrayBuffer}function Lt(r){if($r(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ne(r,e){e==null&&(e=r.reduce((s,i)=>s+i.length,0));let t=oe(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return Lt(t)}function zt(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}var Fe={};v(Fe,{base10:()=>Rr});var Rr=M({prefix:"9",name:"base10",alphabet:"0123456789"});var qe={};v(qe,{base16:()=>Qr,base16upper:()=>Jr});var Qr=m({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Jr=m({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Me={};v(Me,{base2:()=>Kr});var Kr=m({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ue={};v(Ue,{base256emoji:()=>Wr});var kt=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}"),Hr=kt.reduce((r,e,t)=>(r[t]=e,r),[]),Xr=kt.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Gr(r){return r.reduce((e,t)=>(e+=Hr[t],e),"")}function Yr(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let s=Xr[n];if(s==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(s)}return new Uint8Array(e)}var Wr=V({prefix:"\u{1F680}",name:"base256emoji",encode:Gr,decode:Yr});var je={};v(je,{base8:()=>Zr});var Zr=m({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Be={};v(Be,{identity:()=>en});var en=V({prefix:"\0",name:"identity",encode:r=>dt(r),decode:r=>ft(r)});var Ss=new TextEncoder,Is=new TextDecoder;var Oe={};v(Oe,{sha256:()=>nn,sha512:()=>sn});function Tt(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var nn=ze({name:"sha2-256",code:18,encode:Tt("SHA-256")}),sn=ze({name:"sha2-512",code:19,encode:Tt("SHA-512")});var Ve={...Be,...Me,...je,...Fe,...qe,...Se,...Ie,...Ae,...Te,...Ue},Ls={...Oe,...De};function Nt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Dt=Nt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),$e=Nt("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=oe(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),on={utf8:Dt,"utf-8":Dt,hex:Ve.base16,latin1:$e,ascii:$e,binary:$e,...Ve},Ft=on;function T(r,e="utf8"){let t=Ft[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var ae=class extends Error{static name="InsufficientProvidersError";constructor(e="Insufficient providers found"){super(e),this.name="InsufficientProvidersError"}};var P=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};function an(r){return typeof r?.handleEvent=="function"}function cn(r){return(r!==!0&&r!==!1&&r?.once)??!1}var H=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){let s=cn(n);super.addEventListener(e,o=>{if(s){let a=this.#e.get(o.type);a!=null&&(a=a.filter(({callback:c})=>c!==t),this.#e.set(o.type,a))}an(t)?t.handleEvent(o):t(o)},n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:t,once:s})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let s=this.#e.get(e);s!=null&&(s=s.filter(({callback:i})=>i!==t),this.#e.set(e,s))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Re={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},qt={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Mt=new globalThis.TextEncoder;function un(r,e){let t=Re[e],n=qt[e];for(let s=0;s<r.length;s++)n^=BigInt(r[s]),n=BigInt.asUintN(e,n*t);return n}function ln(r,e,t){if(t.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Re[e],s=qt[e],i=r;for(;i.length>0;){let o=Mt.encodeInto(i,t);i=i.slice(o.read);for(let a=0;a<o.written;a++)s^=BigInt(t[a]),s=BigInt.asUintN(e,s*n)}return s}function Qe(r,{size:e=32,utf8Buffer:t}={}){if(!Re[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 ln(r,e,t);r=Mt.encode(r)}return un(r,e)}var te={hash:r=>Number(Qe(r,{size:32})),hashV:(r,e)=>hn(te.hash(r,e))};function hn(r){let e=r.toString(16);return e.length%2===1&&(e=`0${e}`),T(e,"base16")}var Je=64,C=class{fp;h;seed;constructor(e,t,n,s=2){if(s>Je)throw new TypeError("Invalid Fingerprint Size");let i=t.hashV(e,n),o=Ct(s);for(let a=0;a<o.length;a++)o[a]=i[a];o.length===0&&(o[0]=7),this.fp=o,this.h=t,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?zt(this.fp,e.fp):!1}};function B(r,e){return Math.floor(Math.random()*(e-r))+r}var O=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof C))throw new TypeError("Invalid Fingerprint");return this.contents.some(t=>e.equals(t))}add(e){if(!(e instanceof C))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 C))throw new TypeError("Invalid Fingerprint");let t=B(0,this.contents.length-1),n=this.contents[t];return this.contents[t]=e,n}remove(e){if(!(e instanceof C))throw new TypeError("Invalid Fingerprint");let t=this.contents.findIndex(n=>e.equals(n));return t>-1?(this.contents[t]=null,!0):!1}};var fn=500,re=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??te,this.seed=e.seed??B(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=T(e));let t=new C(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,s=(n^t.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new O(this.bucketSize)),this.buckets[s]==null&&(this.buckets[s]=new O(this.bucketSize)),this.buckets[n].add(t)||this.buckets[s].add(t))return this.count++,!0;let i=[n,s],o=i[B(0,i.length-1)];this.buckets[o]==null&&(this.buckets[o]=new O(this.bucketSize));for(let a=0;a<fn;a++){let c=this.buckets[o].swap(t);if(c!=null&&(o=(o^c.hash())%this.filterSize,this.buckets[o]==null&&(this.buckets[o]=new O(this.bucketSize)),this.buckets[o].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=T(e));let t=new C(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,s=this.buckets[n]?.has(t)??!1;if(s)return s;let i=(n^t.hash())%this.filterSize;return this.buckets[i]?.has(t)??!1}remove(e){typeof e=="string"&&(e=T(e));let t=new C(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,s=this.buckets[n]?.remove(t)??!1;if(s)return this.count--,s;let i=(n^t.hash())%this.filterSize,o=this.buckets[i]?.remove(t)??!1;return o&&this.count--,o}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},dn={1:.5,2:.84,4:.95,8:.98};function pn(r=.001){return r>.002?2:r>1e-5?4:8}function Ut(r,e=.001){let t=pn(e),n=dn[t],s=Math.round(r/n),i=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*t)),Je);return{filterSize:s,bucketSize:t,fingerprintSize:i}}var ce=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??te,this.seed=e.seed??B(0,Math.pow(2,10)),this.filterSeries=[new re({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=T(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 re({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=T(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=T(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 ue(r,e=.001,t){return new ce({...Ut(r,e),...t??{}})}function F(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var le=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}},X=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new le(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 le(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 Ke=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function jt(r={}){return mn(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 mn(r,e){e=e??{};let t=e.onEnd,n=new X,s,i,o,a=F(),c=async()=>{try{return n.isEmpty()?o?{done:!0}:await new Promise((p,h)=>{i=g=>{i=null,n.push(g);try{p(r(n))}catch(x){h(x)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=F()})}},l=p=>i!=null?i(p):(n.push(p),s),d=p=>(n=new X,i!=null?i({error:p}):(n.push({error:p}),s)),b=p=>{if(o)return s;if(e?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},u=p=>o?s:(o=!0,p!=null?d(p):l({done:!0})),f=()=>(n=new X,u(),{done:!0}),y=p=>(u(p),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:f,throw:y,push:b,end:u,get readableLength(){return n.size},onEmpty:async p=>{let h=p?.signal;if(h?.throwIfAborted(),n.isEmpty())return;let g,x;h!=null&&(g=new Promise((w,E)=>{x=()=>{E(new Ke)},h.addEventListener("abort",x)}));try{await Promise.race([a.promise,g])}finally{x!=null&&h!=null&&h?.removeEventListener("abort",x)}}},t==null)return s;let I=s;return s={[Symbol.asyncIterator](){return this},next(){return I.next()},throw(p){return I.throw(p),t!=null&&(t(p),t=void 0),{done:!0}},return(){return I.return(),t!=null&&(t(),t=void 0),{done:!0}},push:b,end(p){return I.end(p),t!=null&&(t(p),t=void 0),s},get readableLength(){return I.readableLength},onEmpty:p=>I.onEmpty(p)},s}var He=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},Bt=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Xe(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout},signal:o}=e,a,c,d=new Promise((b,u)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(o?.aborted){u(Bt(o));return}if(o&&(c=()=>{u(Bt(o))},o.addEventListener("abort",c,{once:!0})),r.then(b,u),t===Number.POSITIVE_INFINITY)return;let f=new He;a=i.setTimeout.call(void 0,()=>{if(n){try{b(n())}catch(y){u(y)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?b():s instanceof Error?u(s):(f.message=s??`Promise timed out after ${t} milliseconds`,u(f))},t)}).finally(()=>{d.clear(),c&&o&&o.removeEventListener("abort",c)});return d.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},d}var bn=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 gn(r,e,t){let n,s=new Promise((i,o)=>{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:l,removeListener:d}=bn(r),b=async(...f)=>{let y=t.multiArgs?f:f[0];if(t.filter)try{if(!await t.filter(y))return}catch(I){n(),o(I);return}c.push(y),t.count===c.length&&(n(),i(c))},u=(...f)=>{n(),o(t.rejectionMultiArgs?f:f[0])};n=()=>{for(let f of a)d(f,b);for(let f of t.rejectionEvents)a.includes(f)||d(f,u)};for(let f of a)l(f,b);for(let f of t.rejectionEvents)a.includes(f)||l(f,u);t.signal&&t.signal.addEventListener("abort",()=>{u(t.signal.reason)},{once:!0}),t.resolveImmediately&&i(c)});if(s.cancel=n,typeof t.timeout=="number"){let i=Xe(s,{milliseconds:t.timeout});return i.cancel=()=>{n(),i.clear()},i}return s}function he(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=gn(r,e,t),s=n.then(i=>i[0]);return s.cancel=n.cancel,s}function Ge(r,e){let t,n=function(){let s=function(){t=void 0,r()};clearTimeout(t),t=setTimeout(s,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(t)},n}var fe=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function xn(r){return r.reason}async function de(r,e,t){if(e==null)return r;let n=t?.translateError??xn;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let s;try{return await Promise.race([r,new Promise((i,o)=>{s=()=>{o(n(e))},e.addEventListener("abort",s)})])}finally{s!=null&&e.removeEventListener("abort",s)}}var pe=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=F(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new P)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function yn(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var me=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,t){this.id=yn(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,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 P),this.cleanup())}async join(e){let t=new pe(e);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 de(this.fn({...this.options??{},signal:this.controller.signal,onProgress:t=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(t)})}finally{this.dispatchingProgress=!1}}}}),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 U=class extends H{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=Ge(this.emitEmpty.bind(this),1),this.emitIdle=Ge(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 fe;let n=new me(e,t);this.enqueue(n),this.safeDispatchEvent("add");let s=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});return this.tryToStartAnother(),s}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new P)}),this.clear()}async onEmpty(e){this.size!==0&&await he(this,"empty",e)}async onSizeLessThan(e,t){this.size<e||await he(this,"next",{...t,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await he(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=jt({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),t.end(c)},s=c=>{c.detail!=null&&t.push(c.detail)},i=c=>{n(c.detail.error)},o=()=>{n()},a=()=>{n(new P("Queue aborted"))};this.addEventListener("completed",s),this.addEventListener("failure",i),this.addEventListener("idle",o),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",s),this.removeEventListener("failure",i),this.removeEventListener("idle",o),e?.signal?.removeEventListener("abort",a),n()}}};var Ye=class extends H{initialPeerSearchComplete;requests;logName;log;logger;minProviders;maxProviders;providers;evictionFilter;initialProviders;cidPeerFilterSize;constructor(e,t){super(),this.logName=t.name,this.logger=e.logger,this.log=e.logger.forComponent(this.logName),this.requests=new Map,this.minProviders=t.minProviders??1,this.maxProviders=t.maxProviders??5,this.cidPeerFilterSize=t.cidPeerFilterSize??100,this.providers=[],this.evictionFilter=ue(this.maxProviders),this.initialProviders=[...t.providers??[]]}async retrieve(e,t={}){let n=ke.encode(e.multihash.bytes),s=this.requests.get(n);if(s!=null)return this.log("join existing request for %c",e),s.observers++,s.promise;let i=F(),o={promise:i.promise,observers:1,queryFilter:ue(this.cidPeerFilterSize)};this.requests.set(n,o);let a=!1;this.initialPeerSearchComplete==null&&(a=!0,this.log=this.logger.forComponent(`${this.logName}:${e}`),this.initialPeerSearchComplete=this.findProviders(e,this.minProviders,t));let c=!1,l=new U({concurrency:this.maxProviders});l.addEventListener("failure",u=>{this.log.error("error querying provider %s, evicting from session - %e",u.detail.job.options.provider,u.detail.error),this.evict(u.detail.job.options.provider)}),l.addEventListener("success",u=>{c=!0,i.resolve(u.detail.result)}),l.addEventListener("idle",()=>{if(c){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 u=0;u<this.minProviders&&this.providers.length!==0;u++){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),i.resolve(await this.retrieve(e,t))}).catch(u=>{this.log.error("could not find new providers for %c - %e",e,u),i.reject(u)})});let d=u=>{let f=this.toFilterKey(u.detail);o.queryFilter.has(f)||(o.queryFilter.add(f),this.emitFoundProviderProgressEvent(e,u.detail,t),l.add(async()=>this.queryProvider(e,u.detail,t),{provider:u.detail}).catch(y=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,y)}))};if(this.addEventListener("provider",d),a)try{await de(this.initialPeerSearchComplete,t.signal),a&&this.log("found initial session peers for %c",e)}catch(u){throw a&&this.log("failed to find initial session peers for %c - %e",e,u),this.requests.delete(n),o.observers>1&&i.reject(u),u}Promise.all([...this.providers].filter(u=>{let f=this.toFilterKey(u),y=o.queryFilter.has(f);return y||o.queryFilter.add(this.toFilterKey(u)),!y}).map(async u=>l.add(async()=>this.queryProvider(e,u,t),{provider:u}))).catch(u=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,u)});let b=()=>{i.reject(new P(t.signal?.reason??"Session aborted")),l.abort()};t.signal?.addEventListener("abort",b);try{return await i.promise}finally{this.removeEventListener("provider",d),t.signal?.removeEventListener("abort",b),l.clear(),this.requests.delete(n)}}evict(e){this.evictionFilter.add(this.toFilterKey(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.toFilterKey(e))}hasProvider(e){return!!(this.providers.find(t=>this.equals(t,e))!=null||this.isEvicted(e))}async addPeer(e,t){let n=await this.convertToProvider(e,"manually-added",t);n==null||this.hasProvider(n)||(this.providers.push(n),this.safeDispatchEvent("provider",{detail:n}))}async findProviders(e,t,n){let s=F(),i=0;return Promise.resolve().then(async()=>{this.log("finding %d-%d new provider(s) for %c - %d initial providers",t,this.maxProviders,e,this.initialProviders.length);let o=this,a=async function*(){for(;o.initialProviders.length>0;){let l=o.initialProviders.pop();if(l==null)continue;let d=await o.convertToProvider(l,"manual",n);d!=null&&(yield d)}},c=async function*(){yield*a(),yield*o.findNewProviders(e,n)};for await(let l of c()){if(this.providers.length===this.maxProviders||n.signal?.aborted===!0)break;if(!this.hasProvider(l)&&(this.log("found %d providers, %d in session",i,this.providers.length),this.providers.push(l),this.safeDispatchEvent("provider",{detail:l}),i++,this.providers.length===t&&(this.log("session is ready with %d peer(s), new peers present",this.providers.length),s.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers %d",this.providers.length);break}}if(this.log("found %d new session peers while trying to find %d, %d in session",i,t,this.providers.length),this.providers.length<t)throw new ae(`Found ${i} of ${t} ${this.name} providers for ${e}, ${this.providers.length} in session after evictions`)}).catch(o=>{this.log.error("error searching routing for potential session peers for %c - %e",e,o),s.reject(o)}),s.promise}};var We=class extends Error{static name="AlreadyPinnedError";name="AlreadyPinnedError"},Ze=class extends Error{static name="BlockPinnedError";name="BlockPinnedError"},et=class extends Error{static name="InvalidDatastoreVersionError";name="InvalidDatastoreVersionError"},tt=class extends Error{static name="InvalidConfigurationError";name="InvalidConfigurationError"},rt=class extends AggregateError{static name="GetFailedError";name="GetFailedError"},nt=class extends AggregateError{static name="LoadBlockFailedError";name="LoadBlockFailedError"},st=class extends Error{static name="BlockNotFoundWhileOfflineError";name="BlockNotFoundWhileOfflineError"},it=class extends Error{static name="DecryptionFailedError";name="DecryptionFailedError"};function En(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:s=>{n.push(s)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var Ot=En;function Sn(r){return r[Symbol.asyncIterator]!=null}function In(r,e){let t=0;if(Sn(r))return(async function*(){for await(let c of r)await e(c,t++)&&(yield c)})();let n=Ot(r),{value:s,done:i}=n.next();if(i===!0)return(function*(){})();let o=e(s,t++);if(typeof o.then=="function")return(async function*(){await o&&(yield s);for(let c of n)await e(c,t++)&&(yield c)})();let a=e;return(function*(){o===!0&&(yield s);for(let c of n)a(c,t++)&&(yield c)})()}var Vt=In;function An(r){return r[Symbol.asyncIterator]!=null}function Pn(r){if(An(r))return(async()=>{let n=new Uint8Array(0);for await(let s of r)n=Ne([n,s],n.length+s.length);return n})();let e=[],t=0;for(let n of r)e.push(n),t+=n.byteLength;return Ne(e,t)}var $t=Pn;function be({enumerable:r=!0,configurable:e=!1}={}){return{enumerable:r,configurable:e,writable:!1}}function*Cn(r,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[t,n]of e.entries()){let s=[...r,t],i=_.asCID(n);i!=null?yield[s.join("/"),i]:typeof n=="object"&&(yield*ot(n,s))}else{let t=_.asCID(e);t!=null?yield[r.join("/"),t]:yield*ot(e,r)}}function*ot(r,e){if(r==null||r instanceof Uint8Array)return;let t=_.asCID(r);t!=null&&(yield[e.join("/"),t]);for(let[n,s]of Object.entries(r)){let i=[...e,n];yield*Cn(i,s)}}function*Ln(r,e){if(Array.isArray(e))for(let[t,n]of e.entries()){let s=[...r,t];yield s.join("/"),typeof n=="object"&&_.asCID(n)==null&&(yield*at(n,s))}else yield*at(e,r)}function*at(r,e){if(!(r==null||typeof r!="object"))for(let[t,n]of Object.entries(r)){let s=[...e,t];yield s.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&_.asCID(n)==null&&(yield*Ln(s,n))}}function zn(r,e){let t=r;for(let[n,s]of e.entries()){if(t=t[s],t==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(o=>`[${JSON.stringify(o)}]`).join("")}`);let i=_.asCID(t);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:t}}var ct=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:be(),bytes:be(),value:be(),asBlock:be()})}links(){return ot(this.value,[])}tree(){return at(this.value,[])}get(e="/"){return zn(this.value,e.split("/").filter(Boolean))}};function Rt({bytes:r,cid:e,value:t,codec:n}){let s=t!==void 0?t:n?.decode(r);if(s===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new ct({cid:e,bytes:r,value:s})}function kn(r){return e=>new ut(e,r)}function Tn(r){return e=>new lt(e,r)}function Dn(r){return e=>new ge(e,r)}var ne=class{components;constructor(e,t={}){this.components=e}async*walk(e,t){let n=this.getQueue(),s=Vt(n.toGenerator(t),c=>c!=null),i=!1,o=t?.depth??1/0,a=async c=>{let l=c.cid,d=await $t(this.components.blockstore.get(l,c)),b=Rt({cid:l,bytes:d,codec:await this.components.getCodec(l.code)});if(c.depth<o)for(let[,u]of b.links())t?.includeChild?.(u,b)!==!1&&n.add(a,{...c,cid:u,depth:c.depth+1,path:[...c.path,u]}).catch(f=>{i||s.throw(f)});return{block:b,depth:c.depth,path:c.path}};n.add(a,{...t,cid:e,depth:0,path:[e]}).catch(c=>{i||s.throw(c)});try{yield*s}finally{i=!0,n.abort()}}},ut=class extends ne{getQueue(){return new U({concurrency:1,sort:(e,t)=>e.options.depth===t.options.depth?0:e.options.depth<t.options.depth?1:-1})}},lt=class extends ne{getQueue(){return new U({concurrency:1,sort:(e,t)=>e.options.depth===t.options.depth?0:e.options.depth<t.options.depth?-1:1})}},ge=class extends ne{getQueue(){return new U({concurrency:1})}};function Nn(r){return r==null?!1:_.asCID(r)!=null}function Fn(r){return r?.then!=null}return Xt(qn);})();
2
+ "use strict";var HeliaUtils=(()=>{var xe=Object.defineProperty;var Jt=Object.getOwnPropertyDescriptor;var Kt=Object.getOwnPropertyNames;var Ht=Object.prototype.hasOwnProperty;var v=(r,e)=>{for(var t in e)xe(r,t,{get:e[t],enumerable:!0})},Xt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Kt(e))!Ht.call(r,s)&&s!==t&&xe(r,s,{get:()=>e[s],enumerable:!(n=Jt(e,s))||n.enumerable});return r};var Gt=r=>Xt(xe({},"__esModule",{value:!0}),r);var qn={};v(qn,{AbstractSession:()=>Ye,AlreadyPinnedError:()=>We,BlockNotFoundWhileOfflineError:()=>st,BlockPinnedError:()=>Ze,DecryptionFailedError:()=>it,GetFailedError:()=>rt,InvalidConfigurationError:()=>tt,InvalidDatastoreVersionError:()=>et,LoadBlockFailedError:()=>nt,NaturalOrderGraphWalker:()=>be,breadthFirstWalker:()=>Dn,depthFirstWalker:()=>Tn,isCID:()=>Fn,isPromise:()=>Mn,naturalOrderWalker:()=>Nn});var jn=new Uint8Array(0);function ft(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 I(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return j(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return j(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function dt(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var ht=4096;function pt(r){let e=r.length;if(e<=ht)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=ht));return t}function Yt(r){return r?.buffer instanceof ArrayBuffer}function j(r){return Yt(r)?r:r.slice()}var Se={};v(Se,{base32:()=>$,base32hex:()=>ar,base32hexpad:()=>ur,base32hexpadupper:()=>lr,base32hexupper:()=>cr,base32pad:()=>ir,base32padupper:()=>or,base32upper:()=>sr,base32z:()=>hr});function Wt(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),a=o.charCodeAt(0);if(n[a]!==255)throw new TypeError(o+" is ambiguous");if(n[a]=i,t){var c=o.toLowerCase().charCodeAt(0),l=o.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),l!==a&&(n[l]=i)}}var d=r.length,g=r.charAt(0),u=Math.log(d)/Math.log(256),f=Math.log(256)/Math.log(d);function y(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var b=0,x=0,w=0,E=h.length;w!==E&&h[w]===0;)w++,b++;for(var z=(E-w)*f+1>>>0,S=new Uint8Array(z);w!==E;){for(var k=h[w],M=0,P=z-1;(k!==0||M<x)&&P!==-1;P--,M++)k+=256*S[P]>>>0,S[P]=k%d>>>0,k=k/d>>>0;if(k!==0)throw new Error("Non-zero carry");x=M,w++}for(var N=z-x;N!==z&&S[N]===0;)N++;for(var se=g.repeat(b);N<z;++N)se+=r.charAt(S[N]);return se}function A(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var b=0;if(h[b]!==" "){for(var x=0,w=0;h[b]===g;)x++,b++;for(var E=(h.length-b)*u+1>>>0,z=new Uint8Array(E);h[b];){var S=n[h.charCodeAt(b)];if(S===255)return;for(var k=0,M=E-1;(S!==0||k<w)&&M!==-1;M--,k++)S+=d*z[M]>>>0,z[M]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");w=k,b++}if(h[b]!==" "){for(var P=E-w;P!==E&&z[P]===0;)P++;for(var N=new Uint8Array(x+(E-P)),se=x;P!==E;)N[se++]=z[P++];return N}}}function p(h){var b=A(h);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:y,decodeUnsafe:A,decode:p}}var Zt=Wt,er=Zt,mt=er;var ve=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")}},_e=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let s=t.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 gt(this,e)}},we=class{decoders;constructor(e){this.decoders=e}or(e){return gt(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 gt(r,e){return new we({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ee=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new ve(e,t,n),this.decoder=new _e(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function V({name:r,prefix:e,encode:t,decode:n}){return new Ee(r,e,t,n)}function q({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:s,decode:i}=mt(t,r,n);return V({prefix:e,name:r,encode:s,decode:o=>I(i(o))})}function tr(r,e,t,n){let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),o=0,a=0,c=0;for(let l=0;l<s;++l){let d=e[r[l]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|d,o+=t,o>=8&&(o-=8,i[c++]=255&a>>o)}if(o>=t||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return i}function rr(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>t;)o-=t,i+=e[s&a>>o];if(o!==0&&(i+=e[s&a<<t-o]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function nr(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let s=r[n].toLowerCase(),i=r[n].toUpperCase();s!==r[n]&&(t[s]=n),i!==r[n]&&(t[i]=n)}return t}function m({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:s=!1}){let i=nr(n,s);return V({prefix:e,name:r,encode(o){return rr(o,n,t)},decode(o){return tr(o,i,t,r)}})}var $=m({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),sr=m({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),ir=m({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),or=m({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),ar=m({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),cr=m({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),ur=m({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),lr=m({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),hr=m({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ie={};v(Ie,{base36:()=>G,base36upper:()=>fr});var G=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),fr=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Ae={};v(Ae,{base58btc:()=>T,base58flickr:()=>dr});var T=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),dr=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var pr=yt,bt=128,mr=127,gr=~mr,br=Math.pow(2,31);function yt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=br;)e[t++]=r&255|bt,r/=128;for(;r&gr;)e[t++]=r&255|bt,r>>>=7;return e[t]=r|0,yt.bytes=t-n+1,e}var xr=Pe,yr=128,xt=127;function Pe(r,n){var t=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw Pe.bytes=0,new RangeError("Could not decode varint");o=r[i++],t+=s<28?(o&xt)<<s:(o&xt)*Math.pow(2,s),s+=7}while(o>=yr);return Pe.bytes=i-n,t}var vr=Math.pow(2,7),_r=Math.pow(2,14),wr=Math.pow(2,21),Er=Math.pow(2,28),Sr=Math.pow(2,35),Ir=Math.pow(2,42),Ar=Math.pow(2,49),Pr=Math.pow(2,56),Cr=Math.pow(2,63),Lr=function(r){return r<vr?1:r<_r?2:r<wr?3:r<Er?4:r<Sr?5:r<Ir?6:r<Ar?7:r<Pr?8:r<Cr?9:10},zr={encode:pr,decode:xr,encodingLength:Lr},kr=zr,Y=kr;function W(r,e=0){return[Y.decode(r,e),Y.decode.bytes]}function R(r,e,t=0){return Y.encode(r,e,t),e}function Q(r){return Y.encodingLength(r)}function K(r,e){let t=e.byteLength,n=Q(r),s=n+Q(t),i=new Uint8Array(s+t);return R(r,i,0),R(t,i,n),i.set(e,s),new J(r,t,e,i)}function vt(r){let e=I(r),[t,n]=W(e),[s,i]=W(e.subarray(n)),o=e.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new J(t,s,o,e)}function _t(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ft(r.bytes,t.bytes)}}var J=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=j(n),this.bytes=j(s)}};function wt(r,e){let{bytes:t,version:n}=r;return n===0?Dr(t,Ce(r),e??T.encoder):Nr(t,Ce(r),e??$.encoder)}var Et=new WeakMap;function Ce(r){let e=Et.get(r);if(e==null){let t=new Map;return Et.set(r,t),t}return e}var _=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=j(s),this["/"]=this.bytes}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!==ee)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Fr)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=K(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&&_t(e.multihash,n.multihash)}toString(e){return wt(this,e)}toJSON(){return{"/":wt(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:s,multihash:i,bytes:o}=t;return new r(n,s,i,o??St(n,s,i.bytes))}else if(t[Mr]===!0){let{version:n,multihash:s,code:i}=t,o=vt(s);return r.create(n,i,o)}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!==ee)throw new Error(`Version 0 CID must use dag-pb (code: ${ee}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=St(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ee,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,s=I(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=s.subarray(t.multihashSize-t.digestSize),o=new J(t.multihashCode,t.digestSize,i,s);return[t.version===0?r.createV0(o):r.createV1(t.codec,o),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[g,u]=W(e.subarray(t));return t+=u,g},s=n(),i=ee;if(s===18?(s=0,t=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=t,a=n(),c=n(),l=t+c,d=l-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:d,size:l}}static parse(e,t){let[n,s]=Tr(e,t),i=r.decode(s);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ce(i).set(n,e),i}};function Tr(r,e){switch(r[0]){case"Q":{let t=e??T;return[T.prefix,t.decode(`${T.prefix}${r}`)]}case T.prefix:{let t=e??T;return[T.prefix,t.decode(r)]}case $.prefix:{let t=e??$;return[$.prefix,t.decode(r)]}case G.prefix:{let t=e??G;return[G.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 Dr(r,e,t){let{prefix:n}=t;if(n!==T.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return s}function Nr(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let i=t.encode(r);return e.set(n,i),i}else return s}var ee=112,Fr=18;function St(r,e,t){let n=Q(r),s=n+Q(e),i=new Uint8Array(s+t.byteLength);return R(r,i,0),R(e,i,n),i.set(t,s),i}var Mr=Symbol.for("@ipld/js-cid/CID");var qr=20;function ze({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:s}){return new Le(r,e,t,n,s)}var Le=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,s,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=s??qr,this.maxDigestLength=i}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?It(n,this.code,t?.truncate):n.then(s=>It(s,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function It(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 K(e,r)}var Te={};v(Te,{base64:()=>ke,base64pad:()=>Ur,base64url:()=>jr,base64urlpad:()=>Br});var ke=m({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ur=m({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),jr=m({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Br=m({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var De={};v(De,{identity:()=>$r});var Pt=0,Or="identity",Ct=I;function Vr(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 K(Pt,Ct(r))}var $r={code:Pt,name:Or,encode:Ct,digest:Vr};function Lt(r=0){return new Uint8Array(r)}function oe(r=0){return new Uint8Array(r)}function Rr(r){return r?.buffer instanceof ArrayBuffer}function zt(r){if(Rr(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ne(r,e){e==null&&(e=r.reduce((s,i)=>s+i.length,0));let t=oe(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return zt(t)}function kt(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}var Fe={};v(Fe,{base10:()=>Qr});var Qr=q({prefix:"9",name:"base10",alphabet:"0123456789"});var Me={};v(Me,{base16:()=>Jr,base16upper:()=>Kr});var Jr=m({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Kr=m({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var qe={};v(qe,{base2:()=>Hr});var Hr=m({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ue={};v(Ue,{base256emoji:()=>Zr});var Tt=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}"),Xr=Tt.reduce((r,e,t)=>(r[t]=e,r),[]),Gr=Tt.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Yr(r){return r.reduce((e,t)=>(e+=Xr[t],e),"")}function Wr(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let s=Gr[n];if(s==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(s)}return new Uint8Array(e)}var Zr=V({prefix:"\u{1F680}",name:"base256emoji",encode:Yr,decode:Wr});var je={};v(je,{base8:()=>en});var en=m({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Be={};v(Be,{identity:()=>tn});var tn=V({prefix:"\0",name:"identity",encode:r=>pt(I(r)),decode:r=>I(dt(r))});var Is=new TextEncoder,As=new TextDecoder;var Oe={};v(Oe,{sha256:()=>sn,sha512:()=>on});function Dt(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var sn=ze({name:"sha2-256",code:18,encode:Dt("SHA-256")}),on=ze({name:"sha2-512",code:19,encode:Dt("SHA-512")});var Ve={...Be,...qe,...je,...Fe,...Me,...Se,...Ie,...Ae,...Te,...Ue},zs={...Oe,...De};function Ft(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Nt=Ft("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),$e=Ft("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=oe(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),an={utf8:Nt,"utf-8":Nt,hex:Ve.base16,latin1:$e,ascii:$e,binary:$e,...Ve},Mt=an;function D(r,e="utf8"){let t=Mt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var ae=class extends Error{static name="InsufficientProvidersError";constructor(e="Insufficient providers found"){super(e),this.name="InsufficientProvidersError"}};var C=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};function cn(r){return typeof r?.handleEvent=="function"}function un(r){return(r!==!0&&r!==!1&&r?.once)??!1}var H=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){let s=un(n);super.addEventListener(e,o=>{if(s){let a=this.#e.get(o.type);a!=null&&(a=a.filter(({callback:c})=>c!==t),this.#e.set(o.type,a))}cn(t)?t.handleEvent(o):t(o)},n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:t,once:s})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let s=this.#e.get(e);s!=null&&(s=s.filter(({callback:i})=>i!==t),this.#e.set(e,s))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Re={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},qt={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Ut=new globalThis.TextEncoder;function ln(r,e){let t=Re[e],n=qt[e];for(let s=0;s<r.length;s++)n^=BigInt(r[s]),n=BigInt.asUintN(e,n*t);return n}function hn(r,e,t){if(t.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Re[e],s=qt[e],i=r;for(;i.length>0;){let o=Ut.encodeInto(i,t);i=i.slice(o.read);for(let a=0;a<o.written;a++)s^=BigInt(t[a]),s=BigInt.asUintN(e,s*n)}return s}function Qe(r,{size:e=32,utf8Buffer:t}={}){if(!Re[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 hn(r,e,t);r=Ut.encode(r)}return ln(r,e)}var te={hash:r=>Number(Qe(r,{size:32})),hashV:(r,e)=>fn(te.hash(r,e))};function fn(r){let e=r.toString(16);return e.length%2===1&&(e=`0${e}`),D(e,"base16")}var Je=64,L=class{fp;h;seed;constructor(e,t,n,s=2){if(s>Je)throw new TypeError("Invalid Fingerprint Size");let i=t.hashV(e,n),o=Lt(s);for(let a=0;a<o.length;a++)o[a]=i[a];o.length===0&&(o[0]=7),this.fp=o,this.h=t,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(e){return e?.fp instanceof Uint8Array?kt(this.fp,e.fp):!1}};function B(r,e){return Math.floor(Math.random()*(e-r))+r}var O=class{contents;constructor(e){this.contents=new Array(e).fill(null)}has(e){if(!(e instanceof L))throw new TypeError("Invalid Fingerprint");return this.contents.some(t=>e.equals(t))}add(e){if(!(e instanceof L))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 L))throw new TypeError("Invalid Fingerprint");let t=B(0,this.contents.length-1),n=this.contents[t];return this.contents[t]=e,n}remove(e){if(!(e instanceof L))throw new TypeError("Invalid Fingerprint");let t=this.contents.findIndex(n=>e.equals(n));return t>-1?(this.contents[t]=null,!0):!1}};var dn=500,re=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??te,this.seed=e.seed??B(0,Math.pow(2,10))}add(e){typeof e=="string"&&(e=D(e));let t=new L(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,s=(n^t.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new O(this.bucketSize)),this.buckets[s]==null&&(this.buckets[s]=new O(this.bucketSize)),this.buckets[n].add(t)||this.buckets[s].add(t))return this.count++,!0;let i=[n,s],o=i[B(0,i.length-1)];this.buckets[o]==null&&(this.buckets[o]=new O(this.bucketSize));for(let a=0;a<dn;a++){let c=this.buckets[o].swap(t);if(c!=null&&(o=(o^c.hash())%this.filterSize,this.buckets[o]==null&&(this.buckets[o]=new O(this.bucketSize)),this.buckets[o].add(c)))return this.count++,!0}return!1}has(e){typeof e=="string"&&(e=D(e));let t=new L(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,s=this.buckets[n]?.has(t)??!1;if(s)return s;let i=(n^t.hash())%this.filterSize;return this.buckets[i]?.has(t)??!1}remove(e){typeof e=="string"&&(e=D(e));let t=new L(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,s=this.buckets[n]?.remove(t)??!1;if(s)return this.count--,s;let i=(n^t.hash())%this.filterSize,o=this.buckets[i]?.remove(t)??!1;return o&&this.count--,o}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},pn={1:.5,2:.84,4:.95,8:.98};function mn(r=.001){return r>.002?2:r>1e-5?4:8}function jt(r,e=.001){let t=mn(e),n=pn[t],s=Math.round(r/n),i=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*t)),Je);return{filterSize:s,bucketSize:t,fingerprintSize:i}}var ce=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??te,this.seed=e.seed??B(0,Math.pow(2,10)),this.filterSeries=[new re({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(e){if(typeof e=="string"&&(e=D(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 re({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=D(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=D(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 ue(r,e=.001,t){return new ce({...jt(r,e),...t??{}})}function F(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var le=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}},X=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new le(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 le(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 Ke=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 gn(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 gn(r,e){e=e??{};let t=e.onEnd,n=new X,s,i,o,a=F(),c=async()=>{try{return n.isEmpty()?o?{done:!0}:await new Promise((p,h)=>{i=b=>{i=null,n.push(b);try{p(r(n))}catch(x){h(x)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=F()})}},l=p=>i!=null?i(p):(n.push(p),s),d=p=>(n=new X,i!=null?i({error:p}):(n.push({error:p}),s)),g=p=>{if(o)return s;if(e?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},u=p=>o?s:(o=!0,p!=null?d(p):l({done:!0})),f=()=>(n=new X,u(),{done:!0}),y=p=>(u(p),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:f,throw:y,push:g,end:u,get readableLength(){return n.size},onEmpty:async p=>{let h=p?.signal;if(h?.throwIfAborted(),n.isEmpty())return;let b,x;h!=null&&(b=new Promise((w,E)=>{x=()=>{E(new Ke)},h.addEventListener("abort",x)}));try{await Promise.race([a.promise,b])}finally{x!=null&&h!=null&&h?.removeEventListener("abort",x)}}},t==null)return s;let A=s;return s={[Symbol.asyncIterator](){return this},next(){return A.next()},throw(p){return A.throw(p),t!=null&&(t(p),t=void 0),{done:!0}},return(){return A.return(),t!=null&&(t(),t=void 0),{done:!0}},push:g,end(p){return A.end(p),t!=null&&(t(p),t=void 0),s},get readableLength(){return A.readableLength},onEmpty:p=>A.onEmpty(p)},s}var He=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},Ot=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Xe(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout},signal:o}=e,a,c,d=new Promise((g,u)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(o?.aborted){u(Ot(o));return}if(o&&(c=()=>{u(Ot(o))},o.addEventListener("abort",c,{once:!0})),r.then(g,u),t===Number.POSITIVE_INFINITY)return;let f=new He;a=i.setTimeout.call(void 0,()=>{if(n){try{g(n())}catch(y){u(y)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?g():s instanceof Error?u(s):(f.message=s??`Promise timed out after ${t} milliseconds`,u(f))},t)}).finally(()=>{d.clear(),c&&o&&o.removeEventListener("abort",c)});return d.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},d}var bn=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 xn(r,e,t){let n,s=new Promise((i,o)=>{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:l,removeListener:d}=bn(r),g=async(...f)=>{let y=t.multiArgs?f:f[0];if(t.filter)try{if(!await t.filter(y))return}catch(A){n(),o(A);return}c.push(y),t.count===c.length&&(n(),i(c))},u=(...f)=>{n(),o(t.rejectionMultiArgs?f:f[0])};n=()=>{for(let f of a)d(f,g);for(let f of t.rejectionEvents)a.includes(f)||d(f,u)};for(let f of a)l(f,g);for(let f of t.rejectionEvents)a.includes(f)||l(f,u);t.signal&&t.signal.addEventListener("abort",()=>{u(t.signal.reason)},{once:!0}),t.resolveImmediately&&i(c)});if(s.cancel=n,typeof t.timeout=="number"){let i=Xe(s,{milliseconds:t.timeout});return i.cancel=()=>{n(),i.clear()},i}return s}function he(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=xn(r,e,t),s=n.then(i=>i[0]);return s.cancel=n.cancel,s}function Ge(r,e){let t,n=function(){let s=function(){t=void 0,r()};clearTimeout(t),t=setTimeout(s,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(t)},n}var fe=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function yn(r){return r.reason}async function de(r,e,t){if(e==null)return r;let n=t?.translateError??yn;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let s;try{return await Promise.race([r,new Promise((i,o)=>{s=()=>{o(n(e))},e.addEventListener("abort",s)})])}finally{s!=null&&e.removeEventListener("abort",s)}}var pe=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=F(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new C)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function vn(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var me=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,t){this.id=vn(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,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 C),this.cleanup())}async join(e){let t=new pe(e);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 de(this.fn({...this.options??{},signal:this.controller.signal,onProgress:t=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(t)})}finally{this.dispatchingProgress=!1}}}}),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 U=class extends H{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=Ge(this.emitEmpty.bind(this),1),this.emitIdle=Ge(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 fe;let n=new me(e,t);this.enqueue(n),this.safeDispatchEvent("add");let s=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});return this.tryToStartAnother(),s}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new C)}),this.clear()}async onEmpty(e){this.size!==0&&await he(this,"empty",e)}async onSizeLessThan(e,t){this.size<e||await he(this,"next",{...t,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await he(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)},s=c=>{c.detail!=null&&t.push(c.detail)},i=c=>{n(c.detail.error)},o=()=>{n()},a=()=>{n(new C("Queue aborted"))};this.addEventListener("completed",s),this.addEventListener("failure",i),this.addEventListener("idle",o),e?.signal?.addEventListener("abort",a);try{yield*t}finally{this.removeEventListener("completed",s),this.removeEventListener("failure",i),this.removeEventListener("idle",o),e?.signal?.removeEventListener("abort",a),n()}}};var Ye=class extends H{initialPeerSearchComplete;requests;logName;log;logger;minProviders;maxProviders;providers;evictionFilter;initialProviders;cidPeerFilterSize;constructor(e,t){super(),this.logName=t.name,this.logger=e.logger,this.log=e.logger.forComponent(this.logName),this.requests=new Map,this.minProviders=t.minProviders??1,this.maxProviders=t.maxProviders??5,this.cidPeerFilterSize=t.cidPeerFilterSize??100,this.providers=[],this.evictionFilter=ue(this.maxProviders),this.initialProviders=[...t.providers??[]]}async retrieve(e,t={}){let n=ke.encode(e.multihash.bytes),s=this.requests.get(n);if(s!=null)return this.log("join existing request for %c",e),s.observers++,s.promise;let i=F(),o={promise:i.promise,observers:1,queryFilter:ue(this.cidPeerFilterSize)};this.requests.set(n,o);let a=!1;this.initialPeerSearchComplete==null&&(a=!0,this.log=this.logger.forComponent(`${this.logName}:${e}`),this.initialPeerSearchComplete=this.findProviders(e,this.minProviders,t));let c=!1,l=new U({concurrency:this.maxProviders});l.addEventListener("failure",u=>{this.log.error("error querying provider %s, evicting from session - %e",u.detail.job.options.provider,u.detail.error),this.evict(u.detail.job.options.provider)}),l.addEventListener("success",u=>{c=!0,i.resolve(u.detail.result)}),l.addEventListener("idle",()=>{if(c){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 u=0;u<this.minProviders&&this.providers.length!==0;u++){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),i.resolve(await this.retrieve(e,t))}).catch(u=>{this.log.error("could not find new providers for %c - %e",e,u),i.reject(u)})});let d=u=>{let f=this.toFilterKey(u.detail);o.queryFilter.has(f)||(o.queryFilter.add(f),this.emitFoundProviderProgressEvent(e,u.detail,t),l.add(async()=>this.queryProvider(e,u.detail,t),{provider:u.detail}).catch(y=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,y)}))};if(this.addEventListener("provider",d),a)try{await de(this.initialPeerSearchComplete,t.signal),a&&this.log("found initial session peers for %c",e)}catch(u){throw a&&this.log("failed to find initial session peers for %c - %e",e,u),this.requests.delete(n),o.observers>1&&i.reject(u),u}Promise.all([...this.providers].filter(u=>{let f=this.toFilterKey(u),y=o.queryFilter.has(f);return y||o.queryFilter.add(this.toFilterKey(u)),!y}).map(async u=>l.add(async()=>this.queryProvider(e,u,t),{provider:u}))).catch(u=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,u)});let g=()=>{i.reject(new C(t.signal?.reason??"Session aborted")),l.abort()};t.signal?.addEventListener("abort",g);try{return await i.promise}finally{this.removeEventListener("provider",d),t.signal?.removeEventListener("abort",g),l.clear(),this.requests.delete(n)}}evict(e){this.evictionFilter.add(this.toFilterKey(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.toFilterKey(e))}hasProvider(e){return!!(this.providers.find(t=>this.equals(t,e))!=null||this.isEvicted(e))}async addPeer(e,t){let n=await this.convertToProvider(e,"manually-added",t);n==null||this.hasProvider(n)||(this.providers.push(n),this.safeDispatchEvent("provider",{detail:n}))}async findProviders(e,t,n){let s=F(),i=0;return Promise.resolve().then(async()=>{this.log("finding %d-%d new provider(s) for %c - %d initial providers",t,this.maxProviders,e,this.initialProviders.length);let o=this,a=async function*(){for(;o.initialProviders.length>0;){let l=o.initialProviders.pop();if(l==null)continue;let d=await o.convertToProvider(l,"manual",n);d!=null&&(yield d)}},c=async function*(){yield*a(),yield*o.findNewProviders(e,n)};for await(let l of c()){if(this.providers.length===this.maxProviders||n.signal?.aborted===!0)break;if(!this.hasProvider(l)&&(this.log("found %d providers, %d in session",i,this.providers.length),this.providers.push(l),this.safeDispatchEvent("provider",{detail:l}),i++,this.providers.length===t&&(this.log("session is ready with %d peer(s), new peers present",this.providers.length),s.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers %d",this.providers.length);break}}if(this.log("found %d new session peers while trying to find %d, %d in session",i,t,this.providers.length),this.providers.length<t)throw new ae(`Found ${i} of ${t} ${this.name} providers for ${e}, ${this.providers.length} in session after evictions`)}).catch(o=>{this.log.error("error searching routing for potential session peers for %c - %e",e,o),s.reject(o)}),s.promise}};var We=class extends Error{static name="AlreadyPinnedError";name="AlreadyPinnedError"},Ze=class extends Error{static name="BlockPinnedError";name="BlockPinnedError"},et=class extends Error{static name="InvalidDatastoreVersionError";name="InvalidDatastoreVersionError"},tt=class extends Error{static name="InvalidConfigurationError";name="InvalidConfigurationError"},rt=class extends AggregateError{static name="GetFailedError";name="GetFailedError"},nt=class extends AggregateError{static name="LoadBlockFailedError";name="LoadBlockFailedError"},st=class extends Error{static name="BlockNotFoundWhileOfflineError";name="BlockNotFoundWhileOfflineError"},it=class extends Error{static name="DecryptionFailedError";name="DecryptionFailedError"};function Sn(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:s=>{n.push(s)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var Vt=Sn;function In(r){return r[Symbol.asyncIterator]!=null}function An(r,e){let t=0;if(In(r))return(async function*(){for await(let c of r)await e(c,t++)&&(yield c)})();let n=Vt(r),{value:s,done:i}=n.next();if(i===!0)return(function*(){})();let o=e(s,t++);if(typeof o.then=="function")return(async function*(){await o&&(yield s);for(let c of n)await e(c,t++)&&(yield c)})();let a=e;return(function*(){o===!0&&(yield s);for(let c of n)a(c,t++)&&(yield c)})()}var $t=An;function Pn(r){return r[Symbol.asyncIterator]!=null}function Cn(r){if(Pn(r))return(async()=>{let n=new Uint8Array(0);for await(let s of r)n=Ne([n,s],n.length+s.length);return n})();let e=[],t=0;for(let n of r)e.push(n),t+=n.byteLength;return Ne(e,t)}var Rt=Cn;function ge({enumerable:r=!0,configurable:e=!1}={}){return{enumerable:r,configurable:e,writable:!1}}function*Ln(r,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[t,n]of e.entries()){let s=[...r,t],i=_.asCID(n);i!=null?yield[s.join("/"),i]:typeof n=="object"&&(yield*ot(n,s))}else{let t=_.asCID(e);t!=null?yield[r.join("/"),t]:yield*ot(e,r)}}function*ot(r,e){if(r==null||r instanceof Uint8Array)return;let t=_.asCID(r);t!=null&&(yield[e.join("/"),t]);for(let[n,s]of Object.entries(r)){let i=[...e,n];yield*Ln(i,s)}}function*zn(r,e){if(Array.isArray(e))for(let[t,n]of e.entries()){let s=[...r,t];yield s.join("/"),typeof n=="object"&&_.asCID(n)==null&&(yield*at(n,s))}else yield*at(e,r)}function*at(r,e){if(!(r==null||typeof r!="object"))for(let[t,n]of Object.entries(r)){let s=[...e,t];yield s.join("/"),n!=null&&!(n instanceof Uint8Array)&&typeof n=="object"&&_.asCID(n)==null&&(yield*zn(s,n))}}function kn(r,e){let t=r;for(let[n,s]of e.entries()){if(t=t[s],t==null)throw new Error(`Object has no property at ${e.slice(0,n+1).map(o=>`[${JSON.stringify(o)}]`).join("")}`);let i=_.asCID(t);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:t}}var ct=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:ge(),bytes:ge(),value:ge(),asBlock:ge()})}links(){return ot(this.value,[])}tree(){return at(this.value,[])}get(e="/"){return kn(this.value,e.split("/").filter(Boolean))}};function Qt({bytes:r,cid:e,value:t,codec:n}){let s=t!==void 0?t:n?.decode(r);if(s===void 0)throw new Error('Missing required argument, must either provide "value" or "codec"');return new ct({cid:e,bytes:r,value:s})}function Tn(r){return e=>new ut(e,r)}function Dn(r){return e=>new lt(e,r)}function Nn(r){return e=>new be(e,r)}var ne=class{components;constructor(e,t={}){this.components=e}async*walk(e,t){let n=this.getQueue(),s=$t(n.toGenerator(t),c=>c!=null),i=!1,o=t?.depth??1/0,a=async c=>{let l=c.cid,d=await Rt(this.components.blockstore.get(l,c)),g=Qt({cid:l,bytes:d,codec:await this.components.getCodec(l.code)});if(c.depth<o)for(let[,u]of g.links())t?.includeChild?.(u,g)!==!1&&n.add(a,{...c,cid:u,depth:c.depth+1,path:[...c.path,u]}).catch(f=>{i||s.throw(f)});return{block:g,depth:c.depth,path:c.path}};n.add(a,{...t,cid:e,depth:0,path:[e]}).catch(c=>{i||s.throw(c)});try{yield*s}finally{i=!0,n.abort()}}},ut=class extends ne{getQueue(){return new U({concurrency:1,sort:(e,t)=>e.options.depth===t.options.depth?0:e.options.depth<t.options.depth?1:-1})}},lt=class extends ne{getQueue(){return new U({concurrency:1,sort:(e,t)=>e.options.depth===t.options.depth?0:e.options.depth<t.options.depth?-1:1})}},be=class extends ne{getQueue(){return new U({concurrency:1})}};function Fn(r){return r==null?!1:_.asCID(r)!=null}function Mn(r){return r?.then!=null}return Gt(qn);})();
3
3
  return HeliaUtils}));
4
4
  //# sourceMappingURL=index.min.js.map