@helia/utils 3.0.5-c9f35dab → 3.0.5-ca4dee6f
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 +1 -1
- package/dist/index.min.js.map +2 -2
- package/package.json +2 -2
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 Ht=Object.getOwnPropertyDescriptor;var Xt=Object.getOwnPropertyNames;var Gt=Object.prototype.hasOwnProperty;var y=(r,e)=>{for(var t in e)xe(r,t,{get:e[t],enumerable:!0})},Yt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Xt(e))!Gt.call(r,s)&&s!==t&&xe(r,s,{get:()=>e[s],enumerable:!(n=Ht(e,s))||n.enumerable});return r};var Wt=r=>Yt(xe({},"__esModule",{value:!0}),r);var Bn={};y(Bn,{AbstractSession:()=>We,AlreadyPinnedError:()=>Ze,BlockNotFoundWhileOfflineError:()=>it,BlockPinnedError:()=>et,DecryptionFailedError:()=>ot,GetFailedError:()=>nt,InvalidConfigurationError:()=>rt,InvalidDatastoreVersionError:()=>tt,LoadBlockFailedError:()=>st,NaturalOrderGraphWalker:()=>be,breadthFirstWalker:()=>Mn,depthFirstWalker:()=>qn,isCID:()=>Un,isPromise:()=>jn,naturalOrderWalker:()=>Fn});var Vn=new Uint8Array(0);function dt(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 pt(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var ft=4096;function mt(r){let e=r.length;if(e<=ft)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=ft));return t}function Zt(r){return r?.buffer instanceof ArrayBuffer}function j(r){return Zt(r)?r:r.slice()}var Se={};y(Se,{base32:()=>R,base32hex:()=>ur,base32hexpad:()=>hr,base32hexpadupper:()=>fr,base32hexupper:()=>lr,base32pad:()=>ar,base32padupper:()=>cr,base32upper:()=>or,base32z:()=>dr});function er(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),c=o.charCodeAt(0);if(n[c]!==255)throw new TypeError(o+" is ambiguous");if(n[c]=i,t){var a=o.toLowerCase().charCodeAt(0),l=o.toUpperCase().charCodeAt(0);a!==c&&(n[a]=i),l!==c&&(n[l]=i)}}var d=r.length,g=r.charAt(0),u=Math.log(d)/Math.log(256),h=Math.log(256)/Math.log(d);function v(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var b=0,x=0,w=0,_=f.length;w!==_&&f[w]===0;)w++,b++;for(var k=(_-w)*h+1>>>0,S=new Uint8Array(k);w!==_;){for(var z=f[w],M=0,P=k-1;(z!==0||M<x)&&P!==-1;P--,M++)z+=256*S[P]>>>0,S[P]=z%d>>>0,z=z/d>>>0;if(z!==0)throw new Error("Non-zero carry");x=M,w++}for(var N=k-x;N!==k&&S[N]===0;)N++;for(var se=g.repeat(b);N<k;++N)se+=r.charAt(S[N]);return se}function A(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var b=0;if(f[b]!==" "){for(var x=0,w=0;f[b]===g;)x++,b++;for(var _=(f.length-b)*u+1>>>0,k=new Uint8Array(_);f[b];){var S=n[f.charCodeAt(b)];if(S===255)return;for(var z=0,M=_-1;(S!==0||z<w)&&M!==-1;M--,z++)S+=d*k[M]>>>0,k[M]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");w=z,b++}if(f[b]!==" "){for(var P=_-w;P!==_&&k[P]===0;)P++;for(var N=new Uint8Array(x+(_-P)),se=x;P!==_;)N[se++]=k[P++];return N}}}function p(f){var b=A(f);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:v,decodeUnsafe:A,decode:p}}var tr=er,rr=tr,gt=rr;var ye=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")}},Ee=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 bt(this,e)}},we=class{decoders;constructor(e){this.decoders=e}or(e){return bt(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 bt(r,e){return new we({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var _e=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 ye(e,t,n),this.decoder=new Ee(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 _e(r,e,t,n)}function F({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:s,decode:i}=gt(t,r,n);return V({prefix:e,name:r,encode:s,decode:o=>I(i(o))})}function nr(r,e,t,n){let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),o=0,c=0,a=0;for(let l=0;l<s;++l){let d=e[r[l]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|d,o+=t,o>=8&&(o-=8,i[a++]=255&c>>o)}if(o>=t||(255&c<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return i}function sr(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,i="",o=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],o+=8;o>t;)o-=t,i+=e[s&c>>o];if(o!==0&&(i+=e[s&c<<t-o]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function ir(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=ir(n,s);return V({prefix:e,name:r,encode(o){return sr(o,n,t)},decode(o){return nr(o,i,t,r)}})}var R=m({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),or=m({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),ar=m({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),cr=m({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),ur=m({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),lr=m({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),hr=m({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),fr=m({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),dr=m({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ie={};y(Ie,{base36:()=>G,base36upper:()=>pr});var G=F({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),pr=F({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Ae={};y(Ae,{base58btc:()=>T,base58flickr:()=>mr});var T=F({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),mr=F({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var gr=yt,xt=128,br=127,xr=~br,vr=Math.pow(2,31);function yt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=vr;)e[t++]=r&255|xt,r/=128;for(;r&xr;)e[t++]=r&255|xt,r>>>=7;return e[t]=r|0,yt.bytes=t-n+1,e}var yr=Pe,Er=128,vt=127;function Pe(r,n){var t=0,n=n||0,s=0,i=n,o,c=r.length;do{if(i>=c)throw Pe.bytes=0,new RangeError("Could not decode varint");o=r[i++],t+=s<28?(o&vt)<<s:(o&vt)*Math.pow(2,s),s+=7}while(o>=Er);return Pe.bytes=i-n,t}var wr=Math.pow(2,7),_r=Math.pow(2,14),Sr=Math.pow(2,21),Ir=Math.pow(2,28),Ar=Math.pow(2,35),Pr=Math.pow(2,42),Cr=Math.pow(2,49),Lr=Math.pow(2,56),kr=Math.pow(2,63),zr=function(r){return r<wr?1:r<_r?2:r<Sr?3:r<Ir?4:r<Ar?5:r<Pr?6:r<Cr?7:r<Lr?8:r<kr?9:10},Tr={encode:gr,decode:yr,encodingLength:zr},Dr=Tr,Y=Dr;function W(r,e=0){let t=Y.decode(r,e),n=Y.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[t,n]}function $(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,i,0),$(t,i,n),i.set(e,s),new J(r,t,e,i)}function Et(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 wt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&dt(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?qr(t,Ce(r),e??T.encoder):Mr(t,Ce(r),e??R.encoder)}var St=new WeakMap;function Ce(r){let e=St.get(r);if(e==null){let t=new Map;return St.set(r,t),t}return e}var E=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&&wt(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??It(n,s,i.bytes))}else if(t[Ur]===!0){let{version:n,multihash:s,code:i}=t,o=Et(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=It(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,c=n(),a=n(),l=t+a,d=l-o;return{version:s,codec:i,multihashCode:c,digestSize:a,multihashSize:d,size:l}}static parse(e,t){let[n,s]=Nr(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 Nr(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 R.prefix:{let t=e??R;return[R.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 qr(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 Mr(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 It(r,e,t){let n=Q(r),s=n+Q(e),i=new Uint8Array(s+t.byteLength);return $(r,i,0),$(e,i,n),i.set(t,s),i}var Ur=Symbol.for("@ipld/js-cid/CID");var jr=20;function ke({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??jr,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?At(n,this.code,t?.truncate):n.then(s=>At(s,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function At(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={};y(Te,{base64:()=>ze,base64pad:()=>Br,base64url:()=>Or,base64urlpad:()=>Vr});var ze=m({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Br=m({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Or=m({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Vr=m({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var De={};y(De,{identity:()=>Qr});var Ct=0,Rr="identity",Lt=I;function $r(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(Ct,Lt(r))}var Qr={code:Ct,name:Rr,encode:Lt,digest:$r};function kt(r=0){return new Uint8Array(r)}function oe(r=0){return new Uint8Array(r)}function Jr(r){return r?.buffer instanceof ArrayBuffer}function zt(r){if(Jr(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 Tt(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 qe={};y(qe,{base10:()=>Kr});var Kr=F({prefix:"9",name:"base10",alphabet:"0123456789"});var Me={};y(Me,{base16:()=>Hr,base16upper:()=>Xr});var Hr=m({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Xr=m({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Fe={};y(Fe,{base2:()=>Gr});var Gr=m({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ue={};y(Ue,{base256emoji:()=>tn});var Dt=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}"),Yr=Dt.reduce((r,e,t)=>(r[t]=e,r),[]),Wr=Dt.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Zr(r){return r.reduce((e,t)=>(e+=Yr[t],e),"")}function en(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let s=Wr[n];if(s==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(s)}return new Uint8Array(e)}var tn=V({prefix:"\u{1F680}",name:"base256emoji",encode:Zr,decode:en});var je={};y(je,{base8:()=>rn});var rn=m({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Be={};y(Be,{identity:()=>nn});var nn=V({prefix:"\0",name:"identity",encode:r=>mt(I(r)),decode:r=>I(pt(r))});var Cs=new TextEncoder,Ls=new TextDecoder;var Oe={};y(Oe,{sha256:()=>an,sha512:()=>cn});function Nt(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var an=ke({name:"sha2-256",code:18,encode:Nt("SHA-256")}),cn=ke({name:"sha2-512",code:19,encode:Nt("SHA-512")});var Ve={...Be,...Fe,...je,...qe,...Me,...Se,...Ie,...Ae,...Te,...Ue},Ds={...Oe,...De};function Mt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var qt=Mt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Re=Mt("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}),un={utf8:qt,"utf-8":qt,hex:Ve.base16,latin1:Re,ascii:Re,binary:Re,...Ve},Ft=un;function D(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 C=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};function ln(r){return typeof r?.handleEvent=="function"}function hn(r){return r===!0||r===!1}function fn(r){return hn(r)?r:r?.capture??!1}function $e(r){let e={capture:fn(r),once:!!r?.once};return r?.passive!=null&&(e.passive=r?.passive),r?.signal!=null&&(e.signal=r?.signal),e}function Ut(r,e){return $e(r).capture===$e(e).capture}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=$e(n);if(s?.signal?.aborted===!0)return;let i=l=>{s.once&&this.removeEventListener(e,t,s),ln(t)?t.handleEvent(l):t(l)},o=this.#e.get(e);if(o==null&&(o=[],this.#e.set(e,o)),o.some(l=>l.callback!==t?!1:Ut(l.options,s)))return;super.addEventListener(e,i,s);let a=()=>{this.removeEventListener(e,t,s)};s.signal?.addEventListener("abort",a),o.push({callback:t,wrapper:i,options:s,onAbort:a})}removeEventListener(e,t,n){let s=this.#e.get(e);if(s==null){super.removeEventListener(e,t??null,n);return}this.#e.set(e,s.filter(i=>i.callback===t&&Ut(i.options,n)?(super.removeEventListener(e,i.wrapper,n),i.options?.signal?.removeEventListener("abort",i.onAbort),!1):!0))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Qe={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},jt={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Bt=new globalThis.TextEncoder;function dn(r,e){let t=Qe[e],n=jt[e];for(let s=0;s<r.length;s++)n^=BigInt(r[s]),n=BigInt.asUintN(e,n*t);return n}function pn(r,e,t){if(t.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Qe[e],s=jt[e],i=r;for(;i.length>0;){let o=Bt.encodeInto(i,t);i=i.slice(o.read);for(let c=0;c<o.written;c++)s^=BigInt(t[c]),s=BigInt.asUintN(e,s*n)}return s}function Je(r,{size:e=32,utf8Buffer:t}={}){if(!Qe[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 pn(r,e,t);r=Bt.encode(r)}return dn(r,e)}var te={hash:r=>Number(Je(r,{size:32})),hashV:(r,e)=>mn(te.hash(r,e))};function mn(r){let e=r.toString(16);return e.length%2===1&&(e=`0${e}`),D(e,"base16")}var Ke=64,L=class{fp;h;seed;constructor(e,t,n,s=2){if(s>Ke)throw new TypeError("Invalid Fingerprint Size");let i=t.hashV(e,n),o=kt(s);for(let c=0;c<o.length;c++)o[c]=i[c];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?Tt(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 gn=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 c=0;c<gn;c++){let a=this.buckets[o].swap(t);if(a!=null&&(o=(o^a.hash())%this.filterSize,this.buckets[o]==null&&(this.buckets[o]=new O(this.bucketSize)),this.buckets[o].add(a)))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}},bn={1:.5,2:.84,4:.95,8:.98};function xn(r=.001){return r>.002?2:r>1e-5?4:8}function Ot(r,e=.001){let t=xn(e),n=bn[t],s=Math.round(r/n),i=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*t)),Ke);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({...Ot(r,e),...t??{}})}function q(){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 He=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Vt(r={}){return vn(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 vn(r,e){e=e??{};let t=e.onEnd,n=new X,s,i,o,c=q(),a=async()=>{try{return n.isEmpty()?o?{done:!0}:await new Promise((p,f)=>{i=b=>{i=null,n.push(b);try{p(r(n))}catch(x){f(x)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=q()})}},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})),h=()=>(n=new X,u(),{done:!0}),v=p=>(u(p),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:a,return:h,throw:v,push:g,end:u,get readableLength(){return n.size},onEmpty:async p=>{let f=p?.signal;if(f?.throwIfAborted(),n.isEmpty())return;let b,x;f!=null&&(b=new Promise((w,_)=>{x=()=>{_(new He)},f.addEventListener("abort",x)}));try{await Promise.race([c.promise,b])}finally{x!=null&&f!=null&&f?.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 Xe=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},Rt=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Ge(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout},signal:o}=e,c,a,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(Rt(o));return}if(o&&(a=()=>{u(Rt(o))},o.addEventListener("abort",a,{once:!0})),r.then(g,u),t===Number.POSITIVE_INFINITY)return;let h=new Xe;c=i.setTimeout.call(void 0,()=>{if(n){try{g(n())}catch(v){u(v)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?g():s instanceof Error?u(s):(h.message=s??`Promise timed out after ${t} milliseconds`,u(h))},t)}).finally(()=>{d.clear(),a&&o&&o.removeEventListener("abort",a)});return d.clear=()=>{i.clearTimeout.call(void 0,c),c=void 0},d}var yn=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 En(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 c=[e].flat(),a=[],{addListener:l,removeListener:d}=yn(r),g=async(...h)=>{let v=t.multiArgs?h:h[0];if(t.filter)try{if(!await t.filter(v))return}catch(A){n(),o(A);return}a.push(v),t.count===a.length&&(n(),i(a))},u=(...h)=>{n(),o(t.rejectionMultiArgs?h:h[0])};n=()=>{for(let h of c)d(h,g);for(let h of t.rejectionEvents)c.includes(h)||d(h,u)};for(let h of c)l(h,g);for(let h of t.rejectionEvents)c.includes(h)||l(h,u);t.signal&&t.signal.addEventListener("abort",()=>{u(t.signal.reason)},{once:!0}),t.resolveImmediately&&i(a)});if(s.cancel=n,typeof t.timeout=="number"){let i=Ge(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=En(r,e,t),s=n.then(i=>i[0]);return s.cancel=n.cancel,s}function Ye(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 wn(r){return r.reason}function de(r,e,t){if(e==null||r==null)return r;let n=t?.translateError??wn;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let s;return 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=q(),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 _n(){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=_n(),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=Ye(this.emitEmpty.bind(this),1),this.emitIdle=Ye(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=Vt({objectMode:!0}),n=a=>{a!=null?this.abort():this.clear(),t.end(a)},s=a=>{a.detail!=null&&t.push(a.detail)},i=a=>{n(a.detail.error)},o=()=>{n()},c=()=>{n(new C("Queue aborted"))};this.addEventListener("completed",s),this.addEventListener("failure",i),this.addEventListener("idle",o),e?.signal?.addEventListener("abort",c);try{yield*t}finally{this.removeEventListener("completed",s),this.removeEventListener("failure",i),this.removeEventListener("idle",o),e?.signal?.removeEventListener("abort",c),n()}}};var We=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=ze.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=q(),o={promise:i.promise,observers:1,queryFilter:ue(this.cidPeerFilterSize)};this.requests.set(n,o);let c=!1;this.initialPeerSearchComplete==null&&(c=!0,this.log=this.logger.forComponent(`${this.logName}:${e}`),this.initialPeerSearchComplete=this.findProviders(e,this.minProviders,t));let a=!1,l=new U({concurrency:this.maxProviders});l.addEventListener("failure",u=>{if(u.detail.job.options.provider.fallback){this.log.error("error querying fallback provider %s - %e",u.detail.job.options.provider,u.detail.error);return}if(u.detail.error.name==="NoEvictionError"){this.log.error("no-eviction error querying provider %s - %e",u.detail.job.options.provider,u.detail.error);return}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=>{a=!0,i.resolve(u.detail.result)}),l.addEventListener("idle",()=>{if(a){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 h=this.providers[Math.floor(Math.random()*this.providers.length)];h.fallback||(this.log("evicting %s to make room for more providers",h),this.evict(h))}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 h=this.toFilterKey(u.detail);o.queryFilter.has(h)||(o.queryFilter.add(h),this.emitFoundProviderProgressEvent(e,u.detail,t),l.add(async()=>this.queryProvider(e,u.detail,t),{provider:u.detail}).catch(v=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,v)}))};if(this.addEventListener("provider",d),c)try{await de(this.initialPeerSearchComplete,t.signal),c&&this.log("found initial session peers for %c",e)}catch(u){throw c&&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 h=this.toFilterKey(u),v=o.queryFilter.has(h);return v||o.queryFilter.add(this.toFilterKey(u)),!v}).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=q(),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,c=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)}},a=async function*(){yield*c(),yield*o.findNewProviders(e,n)};for await(let l of a()){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 Ze=class extends Error{static name="AlreadyPinnedError";name="AlreadyPinnedError"},et=class extends Error{static name="BlockPinnedError";name="BlockPinnedError"},tt=class extends Error{static name="InvalidDatastoreVersionError";name="InvalidDatastoreVersionError"},rt=class extends Error{static name="InvalidConfigurationError";name="InvalidConfigurationError"},nt=class extends AggregateError{static name="GetFailedError";name="GetFailedError"},st=class extends AggregateError{static name="LoadBlockFailedError";name="LoadBlockFailedError"},it=class extends Error{static name="BlockNotFoundWhileOfflineError";name="BlockNotFoundWhileOfflineError"},ot=class extends Error{static name="DecryptionFailedError";name="DecryptionFailedError"};function Pn(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 $t=Pn;function Cn(r){return r[Symbol.asyncIterator]!=null}function Ln(r,e){let t=0;if(Cn(r))return(async function*(){for await(let a of r)await e(a,t++)&&(yield a)})();let n=$t(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 a of n)await e(a,t++)&&(yield a)})();let c=e;return(function*(){o===!0&&(yield s);for(let a of n)c(a,t++)&&(yield a)})()}var Qt=Ln;function kn(r){return r[Symbol.asyncIterator]!=null}function zn(r){if(kn(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 Jt=zn;function ge({enumerable:r=!0,configurable:e=!1}={}){return{enumerable:r,configurable:e,writable:!1}}function*Tn(r,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[t,n]of e.entries()){let s=[...r,t],i=E.asCID(n);i!=null?yield[s.join("/"),i]:typeof n=="object"&&(yield*at(n,s))}else{let t=E.asCID(e);t!=null?yield[r.join("/"),t]:yield*at(e,r)}}function*at(r,e){if(r==null||r instanceof Uint8Array)return;let t=E.asCID(r);t!=null&&(yield[e.join("/"),t]);for(let[n,s]of Object.entries(r)){let i=[...e,n];yield*Tn(i,s)}}function*Dn(r,e){if(Array.isArray(e))for(let[t,n]of e.entries()){let s=[...r,t];yield s.join("/"),typeof n=="object"&&E.asCID(n)==null&&(yield*ct(n,s))}else yield*ct(e,r)}function*ct(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"&&E.asCID(n)==null&&(yield*Dn(s,n))}}function Nn(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=E.asCID(t);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:t}}var ut=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 at(this.value,[])}tree(){return ct(this.value,[])}get(e="/"){return Nn(this.value,e.split("/").filter(Boolean))}};function Kt({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 ut({cid:e,bytes:r,value:s})}function qn(r){return e=>new lt(e,r)}function Mn(r){return e=>new ht(e,r)}function Fn(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=Qt(n.toGenerator(t),a=>a!=null),i=!1,o=t?.depth??1/0,c=async a=>{let l=a.cid,d=await Jt(this.components.blockstore.get(l,a)),g=Kt({cid:l,bytes:d,codec:await this.components.getCodec(l.code)});if(a.depth<o)for(let[,u]of g.links())t?.includeChild?.(u,g)!==!1&&n.add(c,{...a,cid:u,depth:a.depth+1,path:[...a.path,u]}).catch(h=>{i||s.throw(h)});return{block:g,depth:a.depth,path:a.path}};n.add(c,{...t,cid:e,depth:0,path:[e]}).catch(a=>{i||s.throw(a)});try{yield*s}finally{i=!0,n.abort()}}},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})}},ht=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 Un(r){return r==null?!1:E.asCID(r)!=null}function jn(r){return r?.then!=null}return Wt(Bn);})();
|
|
2
|
+
"use strict";var HeliaUtils=(()=>{var xe=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var Xt=Object.getOwnPropertyNames;var Gt=Object.prototype.hasOwnProperty;var y=(r,e)=>{for(var t in e)xe(r,t,{get:e[t],enumerable:!0})},Yt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Xt(e))!Gt.call(r,s)&&s!==t&&xe(r,s,{get:()=>e[s],enumerable:!(n=Ht(e,s))||n.enumerable});return r};var Wt=r=>Yt(xe({},"__esModule",{value:!0}),r);var Bn={};y(Bn,{AbstractSession:()=>We,AlreadyPinnedError:()=>Ze,BlockNotFoundWhileOfflineError:()=>it,BlockPinnedError:()=>et,DecryptionFailedError:()=>ot,GetFailedError:()=>nt,InvalidConfigurationError:()=>rt,InvalidDatastoreVersionError:()=>tt,LoadBlockFailedError:()=>st,NaturalOrderGraphWalker:()=>be,breadthFirstWalker:()=>Mn,depthFirstWalker:()=>qn,isCID:()=>Un,isPromise:()=>jn,naturalOrderWalker:()=>Fn});var Vn=new Uint8Array(0);function dt(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 pt(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var ft=4096;function mt(r){let e=r.length;if(e<=ft)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=ft));return t}function Zt(r){return r?.buffer instanceof ArrayBuffer}function j(r){return Zt(r)?r:r.slice()}var Se={};y(Se,{base32:()=>R,base32hex:()=>ur,base32hexpad:()=>hr,base32hexpadupper:()=>fr,base32hexupper:()=>lr,base32pad:()=>ar,base32padupper:()=>cr,base32upper:()=>or,base32z:()=>dr});function er(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),c=o.charCodeAt(0);if(n[c]!==255)throw new TypeError(o+" is ambiguous");if(n[c]=i,t){var a=o.toLowerCase().charCodeAt(0),l=o.toUpperCase().charCodeAt(0);a!==c&&(n[a]=i),l!==c&&(n[l]=i)}}var d=r.length,g=r.charAt(0),u=Math.log(d)/Math.log(256),h=Math.log(256)/Math.log(d);function v(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var b=0,x=0,w=0,_=f.length;w!==_&&f[w]===0;)w++,b++;for(var k=(_-w)*h+1>>>0,S=new Uint8Array(k);w!==_;){for(var z=f[w],M=0,P=k-1;(z!==0||M<x)&&P!==-1;P--,M++)z+=256*S[P]>>>0,S[P]=z%d>>>0,z=z/d>>>0;if(z!==0)throw new Error("Non-zero carry");x=M,w++}for(var N=k-x;N!==k&&S[N]===0;)N++;for(var se=g.repeat(b);N<k;++N)se+=r.charAt(S[N]);return se}function A(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var b=0;if(f[b]!==" "){for(var x=0,w=0;f[b]===g;)x++,b++;for(var _=(f.length-b)*u+1>>>0,k=new Uint8Array(_);f[b];){var S=n[f.charCodeAt(b)];if(S===255)return;for(var z=0,M=_-1;(S!==0||z<w)&&M!==-1;M--,z++)S+=d*k[M]>>>0,k[M]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");w=z,b++}if(f[b]!==" "){for(var P=_-w;P!==_&&k[P]===0;)P++;for(var N=new Uint8Array(x+(_-P)),se=x;P!==_;)N[se++]=k[P++];return N}}}function p(f){var b=A(f);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:v,decodeUnsafe:A,decode:p}}var tr=er,rr=tr,gt=rr;var ye=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")}},Ee=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 bt(this,e)}},we=class{decoders;constructor(e){this.decoders=e}or(e){return bt(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 bt(r,e){return new we({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var _e=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 ye(e,t,n),this.decoder=new Ee(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 _e(r,e,t,n)}function F({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:s,decode:i}=gt(t,r,n);return V({prefix:e,name:r,encode:s,decode:o=>I(i(o))})}function nr(r,e,t,n){let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),o=0,c=0,a=0;for(let l=0;l<s;++l){let d=e[r[l]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|d,o+=t,o>=8&&(o-=8,i[a++]=255&c>>o)}if(o>=t||(255&c<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return i}function sr(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,i="",o=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],o+=8;o>t;)o-=t,i+=e[s&c>>o];if(o!==0&&(i+=e[s&c<<t-o]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function ir(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=ir(n,s);return V({prefix:e,name:r,encode(o){return sr(o,n,t)},decode(o){return nr(o,i,t,r)}})}var R=m({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),or=m({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),ar=m({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),cr=m({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),ur=m({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),lr=m({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),hr=m({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),fr=m({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),dr=m({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ie={};y(Ie,{base36:()=>G,base36upper:()=>pr});var G=F({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),pr=F({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Ae={};y(Ae,{base58btc:()=>T,base58flickr:()=>mr});var T=F({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),mr=F({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var gr=yt,xt=128,br=127,xr=~br,vr=Math.pow(2,31);function yt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=vr;)e[t++]=r&255|xt,r/=128;for(;r&xr;)e[t++]=r&255|xt,r>>>=7;return e[t]=r|0,yt.bytes=t-n+1,e}var yr=Pe,Er=128,vt=127;function Pe(r,n){var t=0,n=n||0,s=0,i=n,o,c=r.length;do{if(i>=c)throw Pe.bytes=0,new RangeError("Could not decode varint");o=r[i++],t+=s<28?(o&vt)<<s:(o&vt)*Math.pow(2,s),s+=7}while(o>=Er);return Pe.bytes=i-n,t}var wr=Math.pow(2,7),_r=Math.pow(2,14),Sr=Math.pow(2,21),Ir=Math.pow(2,28),Ar=Math.pow(2,35),Pr=Math.pow(2,42),Cr=Math.pow(2,49),Lr=Math.pow(2,56),kr=Math.pow(2,63),zr=function(r){return r<wr?1:r<_r?2:r<Sr?3:r<Ir?4:r<Ar?5:r<Pr?6:r<Cr?7:r<Lr?8:r<kr?9:10},Tr={encode:gr,decode:yr,encodingLength:zr},Dr=Tr,Y=Dr;function W(r,e=0){let t=Y.decode(r,e),n=Y.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[t,n]}function $(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,i,0),$(t,i,n),i.set(e,s),new J(r,t,e,i)}function Et(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 wt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&dt(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?qr(t,Ce(r),e??T.encoder):Mr(t,Ce(r),e??R.encoder)}var St=new WeakMap;function Ce(r){let e=St.get(r);if(e==null){let t=new Map;return St.set(r,t),t}return e}var E=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&&wt(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??It(n,s,i.bytes))}else if(t[Ur]===!0){let{version:n,multihash:s,code:i}=t,o=Et(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=It(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,c=n(),a=n(),l=t+a,d=l-o;return{version:s,codec:i,multihashCode:c,digestSize:a,multihashSize:d,size:l}}static parse(e,t){let[n,s]=Nr(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 Nr(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 R.prefix:{let t=e??R;return[R.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 qr(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 Mr(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 It(r,e,t){let n=Q(r),s=n+Q(e),i=new Uint8Array(s+t.byteLength);return $(r,i,0),$(e,i,n),i.set(t,s),i}var Ur=Symbol.for("@ipld/js-cid/CID");var jr=20;function ke({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??jr,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?At(n,this.code,t?.truncate):n.then(s=>At(s,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function At(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={};y(Te,{base64:()=>ze,base64pad:()=>Br,base64url:()=>Or,base64urlpad:()=>Vr});var ze=m({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Br=m({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Or=m({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Vr=m({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var De={};y(De,{identity:()=>Qr});var Ct=0,Rr="identity",Lt=I;function $r(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(Ct,Lt(r))}var Qr={code:Ct,name:Rr,encode:Lt,digest:$r};function kt(r=0){return new Uint8Array(r)}function oe(r=0){return new Uint8Array(r)}function Jr(r){return r?.buffer instanceof ArrayBuffer}function zt(r){if(Jr(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 Tt(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 qe={};y(qe,{base10:()=>Kr});var Kr=F({prefix:"9",name:"base10",alphabet:"0123456789"});var Me={};y(Me,{base16:()=>Hr,base16upper:()=>Xr});var Hr=m({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Xr=m({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Fe={};y(Fe,{base2:()=>Gr});var Gr=m({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ue={};y(Ue,{base256emoji:()=>tn});var Dt=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}"),Yr=Dt.reduce((r,e,t)=>(r[t]=e,r),[]),Wr=Dt.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Zr(r){return r.reduce((e,t)=>(e+=Yr[t],e),"")}function en(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let s=Wr[n];if(s==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(s)}return new Uint8Array(e)}var tn=V({prefix:"\u{1F680}",name:"base256emoji",encode:Zr,decode:en});var je={};y(je,{base8:()=>rn});var rn=m({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Be={};y(Be,{identity:()=>nn});var nn=V({prefix:"\0",name:"identity",encode:r=>mt(I(r)),decode:r=>I(pt(r))});var Cs=new TextEncoder,Ls=new TextDecoder;var Oe={};y(Oe,{sha256:()=>an,sha512:()=>cn});function Nt(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var an=ke({name:"sha2-256",code:18,encode:Nt("SHA-256")}),cn=ke({name:"sha2-512",code:19,encode:Nt("SHA-512")});var Ve={...Be,...Fe,...je,...qe,...Me,...Se,...Ie,...Ae,...Te,...Ue},Ds={...Oe,...De};function Mt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var qt=Mt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Re=Mt("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}),un={utf8:qt,"utf-8":qt,hex:Ve.base16,latin1:Re,ascii:Re,binary:Re,...Ve},Ft=un;function D(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 C=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};function ln(r){return typeof r?.handleEvent=="function"}function hn(r){return r===!0||r===!1}function fn(r){return hn(r)?r:r?.capture??!1}function $e(r){let e={capture:fn(r),once:!!r?.once};return r?.passive!=null&&(e.passive=r?.passive),r?.signal!=null&&(e.signal=r?.signal),e}function Ut(r,e){return $e(r).capture===$e(e).capture}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=$e(n);if(s?.signal?.aborted===!0)return;let i=l=>{s.once&&this.removeEventListener(e,t,s),ln(t)?t.handleEvent(l):t(l)},o=this.#e.get(e);if(o==null&&(o=[],this.#e.set(e,o)),o.some(l=>l.callback!==t?!1:Ut(l.options,s)))return;super.addEventListener(e,i,s);let a=()=>{this.removeEventListener(e,t,s)};s.signal?.addEventListener("abort",a),o.push({callback:t,wrapper:i,options:s,onAbort:a})}removeEventListener(e,t,n){let s=this.#e.get(e);if(s==null){super.removeEventListener(e,t??null,n);return}this.#e.set(e,s.filter(i=>i.callback===t&&Ut(i.options,n)?(super.removeEventListener(e,i.wrapper,n),i.options?.signal?.removeEventListener("abort",i.onAbort),!1):!0))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Qe={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},jt={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Bt=new globalThis.TextEncoder;function dn(r,e){let t=Qe[e],n=jt[e];for(let s=0;s<r.length;s++)n^=BigInt(r[s]),n=BigInt.asUintN(e,n*t);return n}function pn(r,e,t){if(t.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Qe[e],s=jt[e],i=r;for(;i.length>0;){let o=Bt.encodeInto(i,t);i=i.slice(o.read);for(let c=0;c<o.written;c++)s^=BigInt(t[c]),s=BigInt.asUintN(e,s*n)}return s}function Je(r,{size:e=32,utf8Buffer:t}={}){if(!Qe[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 pn(r,e,t);r=Bt.encode(r)}return dn(r,e)}var te={hash:r=>Number(Je(r,{size:32})),hashV:(r,e)=>mn(te.hash(r,e))};function mn(r){let e=r.toString(16);return e.length%2===1&&(e=`0${e}`),D(e,"base16")}var Ke=64,L=class{fp;h;seed;constructor(e,t,n,s=2){if(s>Ke)throw new TypeError("Invalid Fingerprint Size");let i=t.hashV(e,n),o=kt(s);for(let c=0;c<o.length;c++)o[c]=i[c];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?Tt(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 gn=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 c=0;c<gn;c++){let a=this.buckets[o].swap(t);if(a!=null&&(o=(o^a.hash())%this.filterSize,this.buckets[o]==null&&(this.buckets[o]=new O(this.bucketSize)),this.buckets[o].add(a)))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}},bn={1:.5,2:.84,4:.95,8:.98};function xn(r=.001){return r>.002?2:r>1e-5?4:8}function Ot(r,e=.001){let t=xn(e),n=bn[t],s=Math.round(r/n),i=Math.min(Math.ceil(Math.log2(1/e)+Math.log2(2*t)),Ke);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({...Ot(r,e),...t??{}})}function q(){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 He=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Vt(r={}){return vn(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 vn(r,e){e=e??{};let t=e.onEnd,n=new X,s,i,o,c=q(),a=async()=>{try{return n.isEmpty()?o?{done:!0}:await new Promise((p,f)=>{i=b=>{i=null,n.push(b);try{p(r(n))}catch(x){f(x)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=q()})}},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})),h=()=>(n=new X,u(),{done:!0}),v=p=>(u(p),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:a,return:h,throw:v,push:g,end:u,get readableLength(){return n.size},onEmpty:async p=>{let f=p?.signal;if(f?.throwIfAborted(),n.isEmpty())return;let b,x;f!=null&&(b=new Promise((w,_)=>{x=()=>{_(new He)},f.addEventListener("abort",x)}));try{await Promise.race([c.promise,b])}finally{x!=null&&f!=null&&f?.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 Xe=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},Rt=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Ge(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout},signal:o}=e,c,a,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(Rt(o));return}if(o&&(a=()=>{u(Rt(o))},o.addEventListener("abort",a,{once:!0})),r.then(g,u),t===Number.POSITIVE_INFINITY)return;let h=new Xe;c=i.setTimeout.call(void 0,()=>{if(n){try{g(n())}catch(v){u(v)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?g():s instanceof Error?u(s):(h.message=s??`Promise timed out after ${t} milliseconds`,u(h))},t)}).finally(()=>{d.clear(),a&&o&&o.removeEventListener("abort",a)});return d.clear=()=>{i.clearTimeout.call(void 0,c),c=void 0},d}var yn=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 En(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 c=[e].flat(),a=[],{addListener:l,removeListener:d}=yn(r),g=async(...h)=>{let v=t.multiArgs?h:h[0];if(t.filter)try{if(!await t.filter(v))return}catch(A){n(),o(A);return}a.push(v),t.count===a.length&&(n(),i(a))},u=(...h)=>{n(),o(t.rejectionMultiArgs?h:h[0])};n=()=>{for(let h of c)d(h,g);for(let h of t.rejectionEvents)c.includes(h)||d(h,u)};for(let h of c)l(h,g);for(let h of t.rejectionEvents)c.includes(h)||l(h,u);t.signal&&t.signal.addEventListener("abort",()=>{u(t.signal.reason)},{once:!0}),t.resolveImmediately&&i(a)});if(s.cancel=n,typeof t.timeout=="number"){let i=Ge(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=En(r,e,t),s=n.then(i=>i[0]);return s.cancel=n.cancel,s}function Ye(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 wn(r){return r.reason}async function de(r,e,t){if(e==null)return r;let n=t?.translateError??wn;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=q(),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 _n(){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=_n(),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=Ye(this.emitEmpty.bind(this),1),this.emitIdle=Ye(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=Vt({objectMode:!0}),n=a=>{a!=null?this.abort():this.clear(),t.end(a)},s=a=>{a.detail!=null&&t.push(a.detail)},i=a=>{n(a.detail.error)},o=()=>{n()},c=()=>{n(new C("Queue aborted"))};this.addEventListener("completed",s),this.addEventListener("failure",i),this.addEventListener("idle",o),e?.signal?.addEventListener("abort",c);try{yield*t}finally{this.removeEventListener("completed",s),this.removeEventListener("failure",i),this.removeEventListener("idle",o),e?.signal?.removeEventListener("abort",c),n()}}};var We=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=ze.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=q(),o={promise:i.promise,observers:1,queryFilter:ue(this.cidPeerFilterSize)};this.requests.set(n,o);let c=!1;this.initialPeerSearchComplete==null&&(c=!0,this.log=this.logger.forComponent(`${this.logName}:${e}`),this.initialPeerSearchComplete=this.findProviders(e,this.minProviders,t));let a=!1,l=new U({concurrency:this.maxProviders});l.addEventListener("failure",u=>{if(u.detail.job.options.provider.fallback){this.log.error("error querying fallback provider %s - %e",u.detail.job.options.provider,u.detail.error);return}if(u.detail.error.name==="NoEvictionError"){this.log.error("no-eviction error querying provider %s - %e",u.detail.job.options.provider,u.detail.error);return}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=>{a=!0,i.resolve(u.detail.result)}),l.addEventListener("idle",()=>{if(a){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 h=this.providers[Math.floor(Math.random()*this.providers.length)];h.fallback||(this.log("evicting %s to make room for more providers",h),this.evict(h))}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 h=this.toFilterKey(u.detail);o.queryFilter.has(h)||(o.queryFilter.add(h),this.emitFoundProviderProgressEvent(e,u.detail,t),l.add(async()=>this.queryProvider(e,u.detail,t),{provider:u.detail}).catch(v=>{t.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",e,v)}))};if(this.addEventListener("provider",d),c)try{await de(this.initialPeerSearchComplete,t.signal),c&&this.log("found initial session peers for %c",e)}catch(u){throw c&&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 h=this.toFilterKey(u),v=o.queryFilter.has(h);return v||o.queryFilter.add(this.toFilterKey(u)),!v}).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=q(),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,c=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)}},a=async function*(){yield*c(),yield*o.findNewProviders(e,n)};for await(let l of a()){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 Ze=class extends Error{static name="AlreadyPinnedError";name="AlreadyPinnedError"},et=class extends Error{static name="BlockPinnedError";name="BlockPinnedError"},tt=class extends Error{static name="InvalidDatastoreVersionError";name="InvalidDatastoreVersionError"},rt=class extends Error{static name="InvalidConfigurationError";name="InvalidConfigurationError"},nt=class extends AggregateError{static name="GetFailedError";name="GetFailedError"},st=class extends AggregateError{static name="LoadBlockFailedError";name="LoadBlockFailedError"},it=class extends Error{static name="BlockNotFoundWhileOfflineError";name="BlockNotFoundWhileOfflineError"},ot=class extends Error{static name="DecryptionFailedError";name="DecryptionFailedError"};function Pn(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 $t=Pn;function Cn(r){return r[Symbol.asyncIterator]!=null}function Ln(r,e){let t=0;if(Cn(r))return(async function*(){for await(let a of r)await e(a,t++)&&(yield a)})();let n=$t(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 a of n)await e(a,t++)&&(yield a)})();let c=e;return(function*(){o===!0&&(yield s);for(let a of n)c(a,t++)&&(yield a)})()}var Qt=Ln;function kn(r){return r[Symbol.asyncIterator]!=null}function zn(r){if(kn(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 Jt=zn;function ge({enumerable:r=!0,configurable:e=!1}={}){return{enumerable:r,configurable:e,writable:!1}}function*Tn(r,e){if(e!=null&&typeof e=="object")if(Array.isArray(e))for(let[t,n]of e.entries()){let s=[...r,t],i=E.asCID(n);i!=null?yield[s.join("/"),i]:typeof n=="object"&&(yield*at(n,s))}else{let t=E.asCID(e);t!=null?yield[r.join("/"),t]:yield*at(e,r)}}function*at(r,e){if(r==null||r instanceof Uint8Array)return;let t=E.asCID(r);t!=null&&(yield[e.join("/"),t]);for(let[n,s]of Object.entries(r)){let i=[...e,n];yield*Tn(i,s)}}function*Dn(r,e){if(Array.isArray(e))for(let[t,n]of e.entries()){let s=[...r,t];yield s.join("/"),typeof n=="object"&&E.asCID(n)==null&&(yield*ct(n,s))}else yield*ct(e,r)}function*ct(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"&&E.asCID(n)==null&&(yield*Dn(s,n))}}function Nn(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=E.asCID(t);if(i!=null)return{value:i,remaining:e.slice(n+1).join("/")}}return{value:t}}var ut=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 at(this.value,[])}tree(){return ct(this.value,[])}get(e="/"){return Nn(this.value,e.split("/").filter(Boolean))}};function Kt({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 ut({cid:e,bytes:r,value:s})}function qn(r){return e=>new lt(e,r)}function Mn(r){return e=>new ht(e,r)}function Fn(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=Qt(n.toGenerator(t),a=>a!=null),i=!1,o=t?.depth??1/0,c=async a=>{let l=a.cid,d=await Jt(this.components.blockstore.get(l,a)),g=Kt({cid:l,bytes:d,codec:await this.components.getCodec(l.code)});if(a.depth<o)for(let[,u]of g.links())t?.includeChild?.(u,g)!==!1&&n.add(c,{...a,cid:u,depth:a.depth+1,path:[...a.path,u]}).catch(h=>{i||s.throw(h)});return{block:g,depth:a.depth,path:a.path}};n.add(c,{...t,cid:e,depth:0,path:[e]}).catch(a=>{i||s.throw(a)});try{yield*s}finally{i=!0,n.abort()}}},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})}},ht=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 Un(r){return r==null?!1:E.asCID(r)!=null}function jn(r){return r?.then!=null}return Wt(Bn);})();
|
|
3
3
|
return HeliaUtils}));
|
|
4
4
|
//# sourceMappingURL=index.min.js.map
|