@helia/utils 0.1.0-9ac5909 → 0.1.0-9c8a2c0
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/src/index.d.ts.map +1 -1
- package/dist/src/index.js +11 -10
- package/dist/src/index.js.map +1 -1
- package/dist/src/routing.d.ts.map +1 -1
- package/dist/src/routing.js +0 -13
- package/dist/src/routing.js.map +1 -1
- package/dist/src/storage.d.ts +2 -1
- package/dist/src/storage.d.ts.map +1 -1
- package/dist/src/storage.js +14 -1
- package/dist/src/storage.js.map +1 -1
- package/dist/src/utils/networked-storage.d.ts +9 -5
- package/dist/src/utils/networked-storage.d.ts.map +1 -1
- package/dist/src/utils/networked-storage.js +50 -38
- package/dist/src/utils/networked-storage.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +14 -13
- package/src/routing.ts +0 -19
- package/src/storage.ts +19 -3
- package/src/utils/networked-storage.ts +88 -61
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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 Qi=Object.create;var wt=Object.defineProperty;var Yi=Object.getOwnPropertyDescriptor;var Xi=Object.getOwnPropertyNames;var Zi=Object.getPrototypeOf,es=Object.prototype.hasOwnProperty;var Ee=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),U=(r,e)=>{for(var t in e)wt(r,t,{get:e[t],enumerable:!0})},mn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Xi(e))!es.call(r,o)&&o!==t&&wt(r,o,{get:()=>e[o],enumerable:!(n=Yi(e,o))||n.enumerable});return r};var xt=(r,e,t)=>(t=r!=null?Qi(Zi(r)):{},mn(e||!r||!r.__esModule?wt(t,"default",{value:r,enumerable:!0}):t,r)),ts=r=>mn(wt({},"__esModule",{value:!0}),r);var xn=Ee((Hc,wn)=>{var ve=1e3,ke=ve*60,Ae=ke*60,me=Ae*24,ns=me*7,os=me*365.25;wn.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return is(r);if(t==="number"&&isFinite(r))return e.long?as(r):ss(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function is(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*os;case"weeks":case"week":case"w":return t*ns;case"days":case"day":case"d":return t*me;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Ae;case"minutes":case"minute":case"mins":case"min":case"m":return t*ke;case"seconds":case"second":case"secs":case"sec":case"s":return t*ve;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function ss(r){var e=Math.abs(r);return e>=me?Math.round(r/me)+"d":e>=Ae?Math.round(r/Ae)+"h":e>=ke?Math.round(r/ke)+"m":e>=ve?Math.round(r/ve)+"s":r+"ms"}function as(r){var e=Math.abs(r);return e>=me?vt(r,e,me,"day"):e>=Ae?vt(r,e,Ae,"hour"):e>=ke?vt(r,e,ke,"minute"):e>=ve?vt(r,e,ve,"second"):r+" ms"}function vt(r,e,t,n){var o=e>=t*1.5;return Math.round(r/t)+" "+n+(o?"s":"")}});var En=Ee((Kc,bn)=>{function cs(r){t.debug=t,t.default=t,t.coerce=u,t.disable=i,t.enable=o,t.enabled=s,t.humanize=xn(),t.destroy=m,Object.keys(r).forEach(f=>{t[f]=r[f]}),t.names=[],t.skips=[],t.formatters={};function e(f){let d=0;for(let g=0;g<f.length;g++)d=(d<<5)-d+f.charCodeAt(g),d|=0;return t.colors[Math.abs(d)%t.colors.length]}t.selectColor=e;function t(f){let d,g=null,B,E;function w(...y){if(!w.enabled)return;let v=w,A=Number(new Date),_=A-(d||A);v.diff=_,v.prev=d,v.curr=A,d=A,y[0]=t.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let T=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(V,R)=>{if(V==="%%")return"%";T++;let W=t.formatters[R];if(typeof W=="function"){let be=y[T];V=W.call(v,be),y.splice(T,1),T--}return V}),t.formatArgs.call(v,y),(v.log||t.log).apply(v,y)}return w.namespace=f,w.useColors=t.useColors(),w.color=t.selectColor(f),w.extend=n,w.destroy=t.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>g!==null?g:(B!==t.namespaces&&(B=t.namespaces,E=t.enabled(f)),E),set:y=>{g=y}}),typeof t.init=="function"&&t.init(w),w}function n(f,d){let g=t(this.namespace+(typeof d>"u"?":":d)+f);return g.log=this.log,g}function o(f){t.save(f),t.namespaces=f,t.names=[],t.skips=[];let d,g=(typeof f=="string"?f:"").split(/[\s,]+/),B=g.length;for(d=0;d<B;d++)g[d]&&(f=g[d].replace(/\*/g,".*?"),f[0]==="-"?t.skips.push(new RegExp("^"+f.slice(1)+"$")):t.names.push(new RegExp("^"+f+"$")))}function i(){let f=[...t.names.map(c),...t.skips.map(c).map(d=>"-"+d)].join(",");return t.enable(""),f}function s(f){if(f[f.length-1]==="*")return!0;let d,g;for(d=0,g=t.skips.length;d<g;d++)if(t.skips[d].test(f))return!1;for(d=0,g=t.names.length;d<g;d++)if(t.names[d].test(f))return!0;return!1}function c(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function u(f){return f instanceof Error?f.stack||f.message:f}function m(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}bn.exports=cs});var vn=Ee((F,kt)=>{F.formatArgs=fs;F.save=ls;F.load=ds;F.useColors=us;F.storage=hs();F.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();F.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function us(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function fs(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+kt.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}F.log=console.debug||console.log||(()=>{});function ls(r){try{r?F.storage.setItem("debug",r):F.storage.removeItem("debug")}catch{}}function ds(){let r;try{r=F.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function hs(){try{return localStorage}catch{}}kt.exports=En()(F);var{formatters:ps}=kt.exports;ps.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var Dn=Ee((au,xr)=>{"use strict";var Bs=Object.prototype.hasOwnProperty,N="~";function Je(){}Object.create&&(Je.prototype=Object.create(null),new Je().__proto__||(N=!1));function Ps(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Ln(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new Ps(t,n||r,o),s=N?N+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],i]:r._events[s].push(i):(r._events[s]=i,r._eventsCount++),r}function At(r,e){--r._eventsCount===0?r._events=new Je:delete r._events[e]}function L(){this._events=new Je,this._eventsCount=0}L.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Bs.call(t,n)&&e.push(N?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};L.prototype.listeners=function(e){var t=N?N+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};L.prototype.listenerCount=function(e){var t=N?N+e:e,n=this._events[t];return n?n.fn?1:n.length:0};L.prototype.emit=function(e,t,n,o,i,s){var c=N?N+e:e;if(!this._events[c])return!1;var u=this._events[c],m=arguments.length,f,d;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),m){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,n),!0;case 4:return u.fn.call(u.context,t,n,o),!0;case 5:return u.fn.call(u.context,t,n,o,i),!0;case 6:return u.fn.call(u.context,t,n,o,i,s),!0}for(d=1,f=new Array(m-1);d<m;d++)f[d-1]=arguments[d];u.fn.apply(u.context,f)}else{var g=u.length,B;for(d=0;d<g;d++)switch(u[d].once&&this.removeListener(e,u[d].fn,void 0,!0),m){case 1:u[d].fn.call(u[d].context);break;case 2:u[d].fn.call(u[d].context,t);break;case 3:u[d].fn.call(u[d].context,t,n);break;case 4:u[d].fn.call(u[d].context,t,n,o);break;default:if(!f)for(B=1,f=new Array(m-1);B<m;B++)f[B-1]=arguments[B];u[d].fn.apply(u[d].context,f)}}return!0};L.prototype.on=function(e,t,n){return Ln(this,e,t,n,!1)};L.prototype.once=function(e,t,n){return Ln(this,e,t,n,!0)};L.prototype.removeListener=function(e,t,n,o){var i=N?N+e:e;if(!this._events[i])return this;if(!t)return At(this,i),this;var s=this._events[i];if(s.fn)s.fn===t&&(!o||s.once)&&(!n||s.context===n)&&At(this,i);else{for(var c=0,u=[],m=s.length;c<m;c++)(s[c].fn!==t||o&&!s[c].once||n&&s[c].context!==n)&&u.push(s[c]);u.length?this._events[i]=u.length===1?u[0]:u:At(this,i)}return this};L.prototype.removeAllListeners=function(e){var t;return e?(t=N?N+e:e,this._events[t]&&At(this,t)):(this._events=new Je,this._eventsCount=0),this};L.prototype.off=L.prototype.removeListener;L.prototype.addListener=L.prototype.on;L.prefixed=N;L.EventEmitter=L;typeof xr<"u"&&(xr.exports=L)});var to=Ee((pf,eo)=>{eo.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function o(i,s){t[i]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(i){return t[i]!==void 0||n[i]!==void 0},remove:function(i){t[i]!==void 0&&(t[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=t[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){t[i]!==void 0?t[i]=s:o(i,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var ji=Ee((Rh,qi)=>{"use strict";function zi(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function _c(r,e,t){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");t||(t={}),typeof e=="object"&&(t=e,e=""),e&&(t.code=e);try{return zi(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),zi(new o,t)}}qi.exports=_c});var Uc={};U(Uc,{Helia:()=>pn});var cr=Symbol.for("@libp2p/content-routing");var yn=Symbol.for("@libp2p/peer-id");var ur=Symbol.for("@libp2p/peer-routing");var ne=class r extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},O=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var bt=(r,...e)=>{try{[...e]}catch{}};var Et=class extends EventTarget{#e=new Map;constructor(){super(),bt(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new rs(e,t))}},fr=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},rs=globalThis.CustomEvent??fr;function gn(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function oe(...r){let e=[];for(let t of r)gn(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function ie(...r){let e=[];for(let t of r)gn(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var $=xt(vn(),1);var mr={};U(mr,{base32:()=>ae,base32hex:()=>ks,base32hexpad:()=>Cs,base32hexpadupper:()=>_s,base32hexupper:()=>As,base32pad:()=>Es,base32padupper:()=>vs,base32upper:()=>bs,base32z:()=>Ts});var Gc=new Uint8Array(0);function kn(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 X(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function An(r){return new TextEncoder().encode(r)}function Cn(r){return new TextDecoder().decode(r)}function ms(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var c=r.length,u=r.charAt(0),m=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function d(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var w=0,y=0,v=0,A=E.length;v!==A&&E[v]===0;)v++,w++;for(var _=(A-v)*f+1>>>0,T=new Uint8Array(_);v!==A;){for(var P=E[v],V=0,R=_-1;(P!==0||V<y)&&R!==-1;R--,V++)P+=256*T[R]>>>0,T[R]=P%c>>>0,P=P/c>>>0;if(P!==0)throw new Error("Non-zero carry");y=V,v++}for(var W=_-y;W!==_&&T[W]===0;)W++;for(var be=u.repeat(w);W<_;++W)be+=r.charAt(T[W]);return be}function g(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var w=0;if(E[w]!==" "){for(var y=0,v=0;E[w]===u;)y++,w++;for(var A=(E.length-w)*m+1>>>0,_=new Uint8Array(A);E[w];){var T=t[E.charCodeAt(w)];if(T===255)return;for(var P=0,V=A-1;(T!==0||P<v)&&V!==-1;V--,P++)T+=c*_[V]>>>0,_[V]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");v=P,w++}if(E[w]!==" "){for(var R=A-v;R!==A&&_[R]===0;)R++;for(var W=new Uint8Array(y+(A-R)),be=y;R!==A;)W[be++]=_[R++];return W}}}function B(E){var w=g(E);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:g,decode:B}}var ys=ms,gs=ys,Tn=gs;var lr=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")}},dr=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=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 Sn(this,e)}},hr=class{decoders;constructor(e){this.decoders=e}or(e){return Sn(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 Sn(r,e){return new hr({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var pr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new lr(e,t,n),this.decoder=new dr(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ce({name:r,prefix:e,encode:t,decode:n}){return new pr(r,e,t,n)}function se({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Tn(t,r);return Ce({prefix:e,name:r,encode:n,decode:i=>X(o(i))})}function ws(r,e,t,n){let o={};for(let f=0;f<e.length;++f)o[e[f]]=f;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),c=0,u=0,m=0;for(let f=0;f<i;++f){let d=o[r[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<t|d,c+=t,c>=8&&(c-=8,s[m++]=255&u>>c)}if(c>=t||255&u<<8-c)throw new SyntaxError("Unexpected end of data");return s}function xs(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,c=0;for(let u=0;u<r.length;++u)for(c=c<<8|r[u],s+=8;s>t;)s-=t,i+=e[o&c>>s];if(s!==0&&(i+=e[o&c<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function k({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Ce({prefix:e,name:r,encode(o){return xs(o,n,t)},decode(o){return ws(o,n,t,r)}})}var ae=k({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),bs=k({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Es=k({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),vs=k({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ks=k({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),As=k({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Cs=k({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),_s=k({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ts=k({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var yr={};U(yr,{base58btc:()=>D,base58flickr:()=>Ss});var D=se({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ss=se({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var gr={};U(gr,{base64:()=>_e,base64pad:()=>Is,base64url:()=>Ls,base64urlpad:()=>Ds});var _e=k({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Is=k({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ls=k({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ds=k({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});$.default.formatters.b=r=>r==null?"undefined":D.baseEncode(r);$.default.formatters.t=r=>r==null?"undefined":ae.baseEncode(r);$.default.formatters.m=r=>r==null?"undefined":_e.baseEncode(r);$.default.formatters.p=r=>r==null?"undefined":r.toString();$.default.formatters.c=r=>r==null?"undefined":r.toString();$.default.formatters.k=r=>r==null?"undefined":r.toString();$.default.formatters.a=r=>r==null?"undefined":r.toString();function Ns(r){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=r,e.destroy=()=>!0,e.extend=()=>e,e}function In(){return{forComponent(r){return wr(r)}}}function wr(r){let e=Ns(`${r}:trace`);return $.default.enabled(`${r}:trace`)&&$.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,$.default)(`${r}:trace`)),Object.assign((0,$.default)(r),{error:(0,$.default)(`${r}:error`),trace:e})}var b=class extends Event{constructor(e,t){super(e),this.detail=t}};var br=xt(Dn(),1);var Qe=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Er=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Nn=r=>globalThis.DOMException===void 0?new Er(r):new DOMException(r),Bn=r=>{let e=r.reason===void 0?Nn("This operation was aborted."):r.reason;return e instanceof Error?e:Nn(e)};function Ye(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,u=new Promise((m,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:g}=e;g.aborted&&f(Bn(g)),g.addEventListener("abort",()=>{f(Bn(g))})}if(t===Number.POSITIVE_INFINITY){r.then(m,f);return}let d=new Qe;s=i.setTimeout.call(void 0,()=>{if(n){try{m(n())}catch(g){f(g)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?m():o instanceof Error?f(o):(d.message=o??`Promise timed out after ${t} milliseconds`,f(d))},t),(async()=>{try{m(await r)}catch(g){f(g)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function vr(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var Xe=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let o=vr(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var ce=class extends br.default{#e;#o;#s=0;#h;#a;#p=0;#r;#c;#t;#m;#n=0;#u;#i;#y;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Xe,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#o=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#h=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#y=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#x(){return this.#o||this.#s<this.#h}get#b(){return this.#n<this.#u}#E(){this.#n--,this.#f(),this.emit("next")}#v(){this.#w(),this.#g(),this.#c=void 0}get#k(){let e=Date.now();if(this.#r===void 0){let t=this.#p-e;if(t<0)this.#s=this.#e?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},t)),!0}return!1}#f(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){let e=!this.#k;if(this.#x&&this.#b){let t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#g(),!0):!1}}return!1}#g(){this.#o||this.#r!==void 0||(this.#r=setInterval(()=>{this.#w()},this.#a),this.#p=Date.now()+this.#a)}#w(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#e?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#u=e,this.#l()}async#A(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#y,...t},new Promise((n,o)=>{this.#t.enqueue(async()=>{this.#n++,this.#s++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=Ye(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#A(t.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof Qe&&!t.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#E()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#i?(this.#i=!1,this.#l(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#m}async onEmpty(){this.#t.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#d("next",()=>this.#t.size<e)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#d("idle")}async#d(e,t){return new Promise(n=>{let o=()=>{t&&!t()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#i}};function Ct(r){let e=[Z.A];return r==null?e:Array.isArray(r)?r.length===0?e:r:[r]}var kr={};U(kr,{base10:()=>Rs});var Rs=se({prefix:"9",name:"base10",alphabet:"0123456789"});var Ar={};U(Ar,{base16:()=>Us,base16upper:()=>Os});var Us=k({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Os=k({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Cr={};U(Cr,{base2:()=>Fs});var Fs=k({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var _r={};U(_r,{base256emoji:()=>js});var Pn=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}"),$s=Pn.reduce((r,e,t)=>(r[t]=e,r),[]),Ms=Pn.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function zs(r){return r.reduce((e,t)=>(e+=$s[t],e),"")}function qs(r){let e=[];for(let t of r){let n=Ms[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var js=Ce({prefix:"\u{1F680}",name:"base256emoji",encode:zs,decode:qs});var Tr={};U(Tr,{base36:()=>Ze,base36upper:()=>Vs});var Ze=se({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Vs=se({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Sr={};U(Sr,{base8:()=>Ws});var Ws=k({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ir={};U(Ir,{identity:()=>Hs});var Hs=Ce({prefix:"\0",name:"identity",encode:r=>Cn(r),decode:r=>An(r)});var Tu=new TextEncoder,Su=new TextDecoder;var Rn=512;var On=85;var Dr={};U(Dr,{identity:()=>De});var Ks=zn,$n=128,Gs=127,Js=~Gs,Qs=Math.pow(2,31);function zn(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Qs;)e[t++]=r&255|$n,r/=128;for(;r&Js;)e[t++]=r&255|$n,r>>>=7;return e[t]=r|0,zn.bytes=t-n+1,e}var Ys=Lr,Xs=128,Mn=127;function Lr(r,n){var t=0,n=n||0,o=0,i=n,s,c=r.length;do{if(i>=c)throw Lr.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Mn)<<o:(s&Mn)*Math.pow(2,o),o+=7}while(s>=Xs);return Lr.bytes=i-n,t}var Zs=Math.pow(2,7),ea=Math.pow(2,14),ta=Math.pow(2,21),ra=Math.pow(2,28),na=Math.pow(2,35),oa=Math.pow(2,42),ia=Math.pow(2,49),sa=Math.pow(2,56),aa=Math.pow(2,63),ca=function(r){return r<Zs?1:r<ea?2:r<ta?3:r<ra?4:r<na?5:r<oa?6:r<ia?7:r<sa?8:r<aa?9:10},ua={encode:Ks,decode:Ys,encodingLength:ca},fa=ua,et=fa;function tt(r,e=0){return[et.decode(r,e),et.decode.bytes]}function Te(r,e,t=0){return et.encode(r,e,t),e}function Se(r){return et.encodingLength(r)}function ue(r,e){let t=e.byteLength,n=Se(r),o=n+Se(t),i=new Uint8Array(o+t);return Te(r,i,0),Te(t,i,n),i.set(e,o),new Ie(r,t,e,i)}function rt(r){let e=X(r),[t,n]=tt(e),[o,i]=tt(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ie(t,o,s,e)}function qn(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&kn(r.bytes,t.bytes)}}var Ie=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var jn=0,la="identity",Vn=X;function da(r){return ue(jn,Vn(r))}var De={code:jn,name:la,encode:Vn,digest:da};var Rr={};U(Rr,{sha256:()=>Ne,sha512:()=>Pr});function Br({name:r,code:e,encode:t}){return new Nr(r,e,t)}var Nr=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?ue(this.code,t):t.then(n=>ue(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Hn(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Ne=Br({name:"sha2-256",code:18,encode:Hn("SHA-256")}),Pr=Br({name:"sha2-512",code:19,encode:Hn("SHA-512")});function Kn(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return pa(t,Ur(r),e??D.encoder);default:return ma(t,Ur(r),e??ae.encoder)}}var Gn=new WeakMap;function Ur(r){let e=Gn.get(r);if(e==null){let t=new Map;return Gn.set(r,t),t}return e}var C=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}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!==nt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==ya)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=ue(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&qn(e.multihash,n.multihash)}toString(e){return Kn(this,e)}toJSON(){return{"/":Kn(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:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??Jn(n,o,i.bytes))}else if(t[ga]===!0){let{version:n,multihash:o,code:i}=t,s=rt(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==nt)throw new Error(`Version 0 CID must use dag-pb (code: ${nt}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Jn(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,nt,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,o=X(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Ie(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[d,g]=tt(e.subarray(t));return t+=g,d},o=n(),i=nt;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,c=n(),u=n(),m=t+u,f=m-s;return{version:o,codec:i,multihashCode:c,digestSize:u,multihashSize:f,size:m}}static parse(e,t){let[n,o]=ha(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ur(i).set(n,e),i}};function ha(r,e){switch(r[0]){case"Q":{let t=e??D;return[D.prefix,t.decode(`${D.prefix}${r}`)]}case D.prefix:{let t=e??D;return[D.prefix,t.decode(r)]}case ae.prefix:{let t=e??ae;return[ae.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function pa(r,e,t){let{prefix:n}=t;if(n!==D.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function ma(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var nt=112,ya=18;function Jn(r,e,t){let n=Se(r),o=n+Se(e),i=new Uint8Array(o+t.byteLength);return Te(r,i,0),Te(e,i,n),i.set(t,o),i}var ga=Symbol.for("@ipld/js-cid/CID");var Be={...Ir,...Cr,...Sr,...kr,...Ar,...mr,...Tr,...yr,...gr,..._r},Ju={...Rr,...Dr};function Qn(r=0){return new Uint8Array(r)}function Xn(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Yn=Xn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Or=Xn("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=Qn(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),wa={utf8:Yn,"utf-8":Yn,hex:Be.base16,latin1:Or,ascii:Or,binary:Or,...Be},Tt=wa;function Pe(r,e="utf8"){let t=Tt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Fr=60;function St(r){return{Status:r.Status??0,TC:r.TC??r.flag_tc??!1,RD:r.RD??r.flag_rd??!1,RA:r.RA??r.flag_ra??!1,AD:r.AD??r.flag_ad??!1,CD:r.CD??r.flag_cd??!1,Question:(r.Question??r.questions??[]).map(e=>({name:e.name,type:Z[e.type]})),Answer:(r.Answer??r.answers??[]).map(e=>({name:e.name,type:Z[e.type],TTL:e.TTL??e.ttl??Fr,data:e.data instanceof Uint8Array?Pe(e.data):e.data}))}}var xa=4;function $r(r,e={}){let t=new ce({concurrency:e.queryConcurrency??xa});return async(n,o={})=>{let i=new URLSearchParams;i.set("name",n),Ct(o.types).forEach(c=>{i.append("type",c.toString())}),o.onProgress?.(new b("dns:query",{detail:n}));let s=await t.add(async()=>{let c=await fetch(`${r}?${i}`,{headers:{accept:"application/dns-json"},signal:o?.signal});if(c.status!==200)throw new Error(`Unexpected HTTP status: ${c.status} - ${c.statusText}`);let u=St(await c.json());return o.onProgress?.(new b("dns:response",{detail:u})),u},{signal:o.signal});if(s==null)throw new Error("No DNS response received");return s}}function Zn(){return[$r("https://cloudflare-dns.com/dns-query"),$r("https://dns.google/resolve")]}var ro=xt(to(),1);var Mr=class{lru;constructor(e){this.lru=(0,ro.default)(e)}get(e,t){let n=!0,o=[];for(let i of t){let s=this.getAnswers(e,i);if(s.length===0){n=!1;break}o.push(...s)}if(n)return St({answers:o})}getAnswers(e,t){let n=`${e.toLowerCase()}-${t}`,o=this.lru.get(n);if(o!=null){let i=o.filter(s=>s.expires>Date.now()).map(({expires:s,value:c})=>({...c,TTL:Math.round((s-Date.now())/1e3),type:Z[c.type]}));return i.length===0&&this.lru.remove(n),i}return[]}add(e,t){let n=`${e.toLowerCase()}-${t.type}`,o=this.lru.get(n)??[];o.push({expires:Date.now()+(t.TTL??Fr)*1e3,value:t}),this.lru.set(n,o)}remove(e,t){let n=`${e.toLowerCase()}-${t}`;this.lru.remove(n)}clear(){this.lru.clear()}};function no(r){return new Mr(r)}var ba=1e3,It=class{resolvers;cache;constructor(e){this.resolvers={},this.cache=no(e.cacheSize??ba),Object.entries(e.resolvers??{}).forEach(([t,n])=>{Array.isArray(n)||(n=[n]),t.endsWith(".")||(t=`${t}.`),this.resolvers[t]=n}),this.resolvers["."]==null&&(this.resolvers["."]=Zn())}async query(e,t={}){let n=Ct(t.types),o=t.cached!==!1?this.cache.get(e,n):void 0;if(o!=null)return t.onProgress?.(new b("dns:cache",{detail:o})),o;let i=`${e.split(".").pop()}.`,s=(this.resolvers[i]??this.resolvers["."]).sort(()=>Math.random()>.5?-1:1),c=[];for(let u of s){if(t.signal?.aborted===!0)break;try{let m=await u(e,{...t,types:n});for(let f of m.Answer)this.cache.add(e,f);return m}catch(m){c.push(m),t.onProgress?.(new b("dns:error",{detail:m}))}}throw c.length===1?c[0]:new AggregateError(c,`DNS lookup of ${e} ${n} failed`)}};var Z;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(Z||(Z={}));function oo(r={}){return new It(r)}function Ea(r){return r[Symbol.asyncIterator]!=null}function va(r){if(Ea(r))return(async()=>{for await(let e of r);})();for(let e of r);}var ot=va;function Re(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Lt=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Ue=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Lt(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 Lt(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 zr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function ye(r={}){return ka(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 ka(r,e){e=e??{};let t=e.onEnd,n=new Ue,o,i,s,c=Re(),u=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,v)=>{i=A=>{i=null,n.push(A);try{y(r(n))}catch(_){v(_)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Re()})}},m=y=>i!=null?i(y):(n.push(y),o),f=y=>(n=new Ue,i!=null?i({error:y}):(n.push({error:y}),o)),d=y=>{if(s)return o;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return m({done:!1,value:y})},g=y=>s?o:(s=!0,y!=null?f(y):m({done:!0})),B=()=>(n=new Ue,g(),{done:!0}),E=y=>(g(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:B,throw:E,push:d,end:g,get readableLength(){return n.size},onEmpty:async y=>{let v=y?.signal;if(v?.throwIfAborted(),n.isEmpty())return;let A,_;v!=null&&(A=new Promise((T,P)=>{_=()=>{P(new zr)},v.addEventListener("abort",_)}));try{await Promise.race([c.promise,A])}finally{_!=null&&v!=null&&v?.removeEventListener("abort",_)}}},t==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(y){return w.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:d,end(y){return w.end(y),t!=null&&(t(y),t=void 0),o},get readableLength(){return w.readableLength},onEmpty:y=>w.onEmpty(y)},o}var qr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Dt(r,e,t,n){let o=new qr(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{let c=m=>{try{if(n?.filter?.(m)===!1)return}catch(f){r.removeEventListener(e,c),t?.removeEventListener("abort",u),s(f);return}r.removeEventListener(e,c),t?.removeEventListener("abort",u),i(m)},u=()=>{r.removeEventListener(e,c),t?.removeEventListener("abort",u),s(o)};r.addEventListener(e,c),t?.addEventListener("abort",u)})}var Nt=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function io(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new Nt(t?.errorMessage,t?.errorCode));let n,o=new Nt(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var Bt=class{deferred;signal;where;constructor(e,t){this.signal=t,this.deferred=Re(),this.where=e,this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(new ne)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Aa(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Pt=class{id;fn;options;priority;recipients;status;timeline;controller;constructor(e,t,n=0){this.id=Aa(),this.status="queued",this.fn=e,this.priority=n,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,bt(1/0,this.controller.signal),this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&this.controller.abort(new ne)}async join(e={}){let t=new Bt(new Error("where").stack,e.signal);return this.recipients.push(t),e.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await io(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.signal?.removeEventListener("abort",this.onAbort)})}};function Ca(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var it=class extends Et{concurrency;queue;pending;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.pending=0,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.queue=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!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){if(this.queue[this.size-1]?.priority>=e.priority){this.queue.push(e);return}let t=Ca(this.queue,e,(n,o)=>o.priority-n.priority);this.queue.splice(t,0,e)}async add(e,t){t?.signal?.throwIfAborted();let n=new Pt(e,t,t?.priority),o=n.join(t).then(i=>(this.safeDispatchEvent("completed",{detail:i}),i)).catch(i=>{throw this.safeDispatchEvent("error",{detail:i}),i});return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new ne)}),this.clear()}async onEmpty(e){this.size!==0&&await Dt(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await Dt(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Dt(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=ye({objectMode:!0}),n=u=>{u!=null?this.abort():this.clear(),t.end(u)},o=u=>{u.detail!=null&&t.push(u.detail)},i=u=>{n(u.detail)},s=()=>{n()},c=()=>{n(new O("Queue aborted","ERR_QUEUE_ABORTED"))};this.addEventListener("completed",o),this.addEventListener("error",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",c);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("error",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",c),n()}}};var _a=["string","number","bigint","symbol"],Ta=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function so(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(_a.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(Sa(r))return"Buffer";let t=Ia(r);return t||"Object"}function Sa(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function Ia(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(Ta.includes(e))return e}var a=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};a.uint=new a(0,"uint",!0);a.negint=new a(1,"negint",!0);a.bytes=new a(2,"bytes",!0);a.string=new a(3,"string",!0);a.array=new a(4,"array",!1);a.map=new a(5,"map",!1);a.tag=new a(6,"tag",!1);a.float=new a(7,"float",!0);a.false=new a(7,"false",!0);a.true=new a(7,"true",!0);a.null=new a(7,"null",!0);a.undefined=new a(7,"undefined",!0);a.break=new a(7,"break",!0);var l=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Oe=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",La=new TextDecoder,Da=new TextEncoder;function Rt(r){return Oe&&globalThis.Buffer.isBuffer(r)}function st(r){return r instanceof Uint8Array?Rt(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var fo=Oe?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):co(r,e,t):(r,e,t)=>t-e>64?La.decode(r.subarray(e,t)):co(r,e,t),Ut=Oe?r=>r.length>64?globalThis.Buffer.from(r):ao(r):r=>r.length>64?Da.encode(r):ao(r),Q=r=>Uint8Array.from(r),Fe=Oe?(r,e,t)=>Rt(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),lo=Oe?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),st(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},ho=Oe?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function po(r,e){if(Rt(r)&&Rt(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function ao(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128)}return e}function co(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let c,u,m,f;switch(s){case 1:o<128&&(i=o);break;case 2:c=r[e+1],(c&192)===128&&(f=(o&31)<<6|c&63,f>127&&(i=f));break;case 3:c=r[e+1],u=r[e+2],(c&192)===128&&(u&192)===128&&(f=(o&15)<<12|(c&63)<<6|u&63,f>2047&&(f<55296||f>57343)&&(i=f));break;case 4:c=r[e+1],u=r[e+2],m=r[e+3],(c&192)===128&&(u&192)===128&&(m&192)===128&&(f=(o&15)<<18|(c&63)<<12|(u&63)<<6|m&63,f>65535&&f<1114112&&(i=f))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return jr(n)}var uo=4096;function jr(r){let e=r.length;if(e<=uo)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=uo));return t}var Na=256,at=class{constructor(e=Na){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=ho(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=Fe(n,0,this.cursor)}else t=lo(this.chunks,this.cursor);return e&&this.reset(),t}};var p="CBOR decode error:",$e="CBOR encode error:",ct=[];ct[23]=1;ct[24]=2;ct[25]=3;ct[26]=5;ct[27]=9;function ee(r,e,t){if(r.length-e<t)throw new Error(`${p} not enough data for type`)}var S=[24,256,65536,4294967296,BigInt("18446744073709551616")];function M(r,e,t){ee(r,e,1);let n=r[e];if(t.strict===!0&&n<S[0])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);return n}function z(r,e,t){ee(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<S[1])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);return n}function q(r,e,t){ee(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<S[2])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);return n}function j(r,e,t){ee(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<S[3])throw new Error(`${p} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${p} integers outside of the safe integer range are not supported`)}function mo(r,e,t,n){return new l(a.uint,M(r,e+1,n),2)}function yo(r,e,t,n){return new l(a.uint,z(r,e+1,n),3)}function go(r,e,t,n){return new l(a.uint,q(r,e+1,n),5)}function wo(r,e,t,n){return new l(a.uint,j(r,e+1,n),9)}function H(r,e){return I(r,0,e.value)}function I(r,e,t){if(t<S[0]){let n=Number(t);r.push([e|n])}else if(t<S[1]){let n=Number(t);r.push([e|24,n])}else if(t<S[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<S[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<S[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${p} encountered BigInt larger than allowable range`)}}H.encodedSize=function(e){return I.encodedSize(e.value)};I.encodedSize=function(e){return e<S[0]?1:e<S[1]?2:e<S[2]?3:e<S[3]?5:9};H.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function xo(r,e,t,n){return new l(a.negint,-1-M(r,e+1,n),2)}function bo(r,e,t,n){return new l(a.negint,-1-z(r,e+1,n),3)}function Eo(r,e,t,n){return new l(a.negint,-1-q(r,e+1,n),5)}var Vr=BigInt(-1),vo=BigInt(1);function ko(r,e,t,n){let o=j(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new l(a.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${p} integers outside of the safe integer range are not supported`);return new l(a.negint,Vr-BigInt(o),9)}function Ot(r,e){let t=e.value,n=typeof t=="bigint"?t*Vr-vo:t*-1-1;I(r,e.type.majorEncoded,n)}Ot.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*Vr-vo:t*-1-1;return n<S[0]?1:n<S[1]?2:n<S[2]?3:n<S[3]?5:9};Ot.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function ut(r,e,t,n){ee(r,e,t+n);let o=Fe(r,e+t,e+t+n);return new l(a.bytes,o,t+n)}function Ao(r,e,t,n){return ut(r,e,1,t)}function Co(r,e,t,n){return ut(r,e,2,M(r,e+1,n))}function _o(r,e,t,n){return ut(r,e,3,z(r,e+1,n))}function To(r,e,t,n){return ut(r,e,5,q(r,e+1,n))}function So(r,e,t,n){let o=j(r,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer bytes lengths not supported`);return ut(r,e,9,o)}function Ft(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===a.string?Ut(r.value):r.value),r.encodedBytes}function Me(r,e){let t=Ft(e);I(r,e.type.majorEncoded,t.length),r.push(t)}Me.encodedSize=function(e){let t=Ft(e);return I.encodedSize(t.length)+t.length};Me.compareTokens=function(e,t){return Pa(Ft(e),Ft(t))};function Pa(r,e){return r.length<e.length?-1:r.length>e.length?1:po(r,e)}function ft(r,e,t,n,o){let i=t+n;ee(r,e,i);let s=new l(a.string,fo(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Fe(r,e+t,e+i)),s}function Io(r,e,t,n){return ft(r,e,1,t,n)}function Lo(r,e,t,n){return ft(r,e,2,M(r,e+1,n),n)}function Do(r,e,t,n){return ft(r,e,3,z(r,e+1,n),n)}function No(r,e,t,n){return ft(r,e,5,q(r,e+1,n),n)}function Bo(r,e,t,n){let o=j(r,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer string lengths not supported`);return ft(r,e,9,o,n)}var Po=Me;function ze(r,e,t,n){return new l(a.array,n,t)}function Ro(r,e,t,n){return ze(r,e,1,t)}function Uo(r,e,t,n){return ze(r,e,2,M(r,e+1,n))}function Oo(r,e,t,n){return ze(r,e,3,z(r,e+1,n))}function Fo(r,e,t,n){return ze(r,e,5,q(r,e+1,n))}function $o(r,e,t,n){let o=j(r,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer array lengths not supported`);return ze(r,e,9,o)}function Mo(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${p} indefinite length items not allowed`);return ze(r,e,1,1/0)}function $t(r,e){I(r,a.array.majorEncoded,e.value)}$t.compareTokens=H.compareTokens;$t.encodedSize=function(e){return I.encodedSize(e.value)};function qe(r,e,t,n){return new l(a.map,n,t)}function zo(r,e,t,n){return qe(r,e,1,t)}function qo(r,e,t,n){return qe(r,e,2,M(r,e+1,n))}function jo(r,e,t,n){return qe(r,e,3,z(r,e+1,n))}function Vo(r,e,t,n){return qe(r,e,5,q(r,e+1,n))}function Wo(r,e,t,n){let o=j(r,e+1,n);if(typeof o=="bigint")throw new Error(`${p} 64-bit integer map lengths not supported`);return qe(r,e,9,o)}function Ho(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${p} indefinite length items not allowed`);return qe(r,e,1,1/0)}function Mt(r,e){I(r,a.map.majorEncoded,e.value)}Mt.compareTokens=H.compareTokens;Mt.encodedSize=function(e){return I.encodedSize(e.value)};function Ko(r,e,t,n){return new l(a.tag,t,1)}function Go(r,e,t,n){return new l(a.tag,M(r,e+1,n),2)}function Jo(r,e,t,n){return new l(a.tag,z(r,e+1,n),3)}function Qo(r,e,t,n){return new l(a.tag,q(r,e+1,n),5)}function Yo(r,e,t,n){return new l(a.tag,j(r,e+1,n),9)}function zt(r,e){I(r,a.tag.majorEncoded,e.value)}zt.compareTokens=H.compareTokens;zt.encodedSize=function(e){return I.encodedSize(e.value)};var Ma=20,za=21,qa=22,ja=23;function Xo(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${p} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new l(a.null,null,1):new l(a.undefined,void 0,1)}function Zo(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${p} indefinite length items not allowed`);return new l(a.break,void 0,1)}function Wr(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${p} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${p} Infinity values are not supported`)}return new l(a.float,r,e)}function ei(r,e,t,n){return Wr(Hr(r,e+1),3,n)}function ti(r,e,t,n){return Wr(Kr(r,e+1),5,n)}function ri(r,e,t,n){return Wr(si(r,e+1),9,n)}function qt(r,e,t){let n=e.value;if(n===!1)r.push([a.float.majorEncoded|Ma]);else if(n===!0)r.push([a.float.majorEncoded|za]);else if(n===null)r.push([a.float.majorEncoded|qa]);else if(n===void 0)r.push([a.float.majorEncoded|ja]);else{let o,i=!1;(!t||t.float64!==!0)&&(oi(n),o=Hr(G,1),n===o||Number.isNaN(n)?(G[0]=249,r.push(G.slice(0,3)),i=!0):(ii(n),o=Kr(G,1),n===o&&(G[0]=250,r.push(G.slice(0,5)),i=!0))),i||(Va(n),o=si(G,1),G[0]=251,r.push(G.slice(0,9)))}}qt.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){oi(n);let o=Hr(G,1);if(n===o||Number.isNaN(n))return 3;if(ii(n),o=Kr(G,1),n===o)return 5}return 9};var ni=new ArrayBuffer(9),K=new DataView(ni,1),G=new Uint8Array(ni,0);function oi(r){if(r===1/0)K.setUint16(0,31744,!1);else if(r===-1/0)K.setUint16(0,64512,!1);else if(Number.isNaN(r))K.setUint16(0,32256,!1);else{K.setFloat32(0,r);let e=K.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)K.setUint16(0,31744,!1);else if(t===0)K.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?K.setUint16(0,0):o<-14?K.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):K.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Hr(r,e){if(r.length-e<2)throw new Error(`${p} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function ii(r){K.setFloat32(0,r,!1)}function Kr(r,e){if(r.length-e<4)throw new Error(`${p} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function Va(r){K.setFloat64(0,r,!1)}function si(r,e){if(r.length-e<8)throw new Error(`${p} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}qt.compareTokens=H.compareTokens;function x(r,e,t){throw new Error(`${p} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function jt(r){return()=>{throw new Error(`${p} ${r}`)}}var h=[];for(let r=0;r<=23;r++)h[r]=x;h[24]=mo;h[25]=yo;h[26]=go;h[27]=wo;h[28]=x;h[29]=x;h[30]=x;h[31]=x;for(let r=32;r<=55;r++)h[r]=x;h[56]=xo;h[57]=bo;h[58]=Eo;h[59]=ko;h[60]=x;h[61]=x;h[62]=x;h[63]=x;for(let r=64;r<=87;r++)h[r]=Ao;h[88]=Co;h[89]=_o;h[90]=To;h[91]=So;h[92]=x;h[93]=x;h[94]=x;h[95]=jt("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)h[r]=Io;h[120]=Lo;h[121]=Do;h[122]=No;h[123]=Bo;h[124]=x;h[125]=x;h[126]=x;h[127]=jt("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)h[r]=Ro;h[152]=Uo;h[153]=Oo;h[154]=Fo;h[155]=$o;h[156]=x;h[157]=x;h[158]=x;h[159]=Mo;for(let r=160;r<=183;r++)h[r]=zo;h[184]=qo;h[185]=jo;h[186]=Vo;h[187]=Wo;h[188]=x;h[189]=x;h[190]=x;h[191]=Ho;for(let r=192;r<=215;r++)h[r]=Ko;h[216]=Go;h[217]=Jo;h[218]=Qo;h[219]=Yo;h[220]=x;h[221]=x;h[222]=x;h[223]=x;for(let r=224;r<=243;r++)h[r]=jt("simple values are not supported");h[244]=x;h[245]=x;h[246]=x;h[247]=Xo;h[248]=jt("simple values are not supported");h[249]=ei;h[250]=ti;h[251]=ri;h[252]=x;h[253]=x;h[254]=x;h[255]=Zo;var J=[];for(let r=0;r<24;r++)J[r]=new l(a.uint,r,1);for(let r=-1;r>=-24;r--)J[31-r]=new l(a.negint,r,1);J[64]=new l(a.bytes,new Uint8Array(0),1);J[96]=new l(a.string,"",1);J[128]=new l(a.array,0,1);J[160]=new l(a.map,0,1);J[244]=new l(a.false,!1,1);J[245]=new l(a.true,!0,1);J[246]=new l(a.null,null,1);function ai(r){switch(r.type){case a.false:return Q([244]);case a.true:return Q([245]);case a.null:return Q([246]);case a.bytes:return r.value.length?void 0:Q([64]);case a.string:return r.value===""?Q([96]):void 0;case a.array:return r.value===0?Q([128]):void 0;case a.map:return r.value===0?Q([160]):void 0;case a.uint:return r.value<24?Q([Number(r.value)]):void 0;case a.negint:if(r.value>=-24)return Q([31-Number(r.value)])}}var Ha={float64:!1,mapSorter:Ja,quickEncodeToken:ai};function Ka(){let r=[];return r[a.uint.major]=H,r[a.negint.major]=Ot,r[a.bytes.major]=Me,r[a.string.major]=Po,r[a.array.major]=$t,r[a.map.major]=Mt,r[a.tag.major]=zt,r[a.float.major]=qt,r}var ci=Ka(),Gr=new at,Wt=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${$e} object contains circular references`);return new r(t,e)}},fe={null:new l(a.null,null),undefined:new l(a.undefined,void 0),true:new l(a.true,!0),false:new l(a.false,!1),emptyArray:new l(a.array,0),emptyMap:new l(a.map,0)},le={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new l(a.float,r):r>=0?new l(a.uint,r):new l(a.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new l(a.uint,r):new l(a.negint,r)},Uint8Array(r,e,t,n){return new l(a.bytes,r)},string(r,e,t,n){return new l(a.string,r)},boolean(r,e,t,n){return r?fe.true:fe.false},null(r,e,t,n){return fe.null},undefined(r,e,t,n){return fe.undefined},ArrayBuffer(r,e,t,n){return new l(a.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new l(a.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[fe.emptyArray,new l(a.break)]:fe.emptyArray;n=Wt.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=Vt(s,t,n);return t.addBreakTokens?[new l(a.array,r.length),o,new l(a.break)]:[new l(a.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[fe.emptyMap,new l(a.break)]:fe.emptyMap;n=Wt.createCheck(n,r);let c=[],u=0;for(let m of i)c[u++]=[Vt(m,t,n),Vt(o?r.get(m):r[m],t,n)];return Ga(c,t),t.addBreakTokens?[new l(a.map,s),c,new l(a.break)]:[new l(a.map,s),c]}};le.Map=le.Object;le.Buffer=le.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))le[`${r}Array`]=le.DataView;function Vt(r,e={},t){let n=so(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||le[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=le[n];if(!i)throw new Error(`${$e} unsupported type: ${n}`);return i(r,n,e,t)}function Ga(r,e){e.mapSorter&&r.sort(e.mapSorter)}function Ja(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let o=t.type.major,i=ci[o].compareTokens(t,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function ui(r,e,t,n){if(Array.isArray(e))for(let o of e)ui(r,o,t,n);else t[e.type.major](r,e,n)}function fi(r,e,t){let n=Vt(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let o=t.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,t),c=new at(s);if(i(c,n,t),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return st(c.chunks[0])}}return Gr.reset(),ui(Gr,n,e,t),Gr.toBytes(!0)}function lt(r,e){return e=Object.assign({},Ha,e),fi(r,ci,e)}var Qa={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Ht=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=J[e];if(t===void 0){let n=h[e];if(!n)throw new Error(`${p} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},dt=Symbol.for("DONE"),Kt=Symbol.for("BREAK");function Ya(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=je(e,t);if(i===Kt){if(r.value===1/0)break;throw new Error(`${p} got unexpected break to lengthed array`)}if(i===dt)throw new Error(`${p} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function Xa(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let c=je(e,t);if(c===Kt){if(r.value===1/0)break;throw new Error(`${p} got unexpected break to lengthed map`)}if(c===dt)throw new Error(`${p} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${p} non-string keys not supported (got ${typeof c})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${p} found repeat map key "${c}"`);let u=je(e,t);if(u===dt)throw new Error(`${p} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(c,u):o[c]=u}return n?i:o}function je(r,e){if(r.done())return dt;let t=r.next();if(t.type===a.break)return Kt;if(t.type.terminal)return t.value;if(t.type===a.array)return Ya(t,r,e);if(t.type===a.map)return Xa(t,r,e);if(t.type===a.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=je(r,e);return e.tags[t.value](n)}throw new Error(`${p} tag not supported (${t.value})`)}throw new Error("unsupported")}function Jr(r,e){if(!(r instanceof Uint8Array))throw new Error(`${p} data to decode must be a Uint8Array`);e=Object.assign({},Qa,e);let t=e.tokenizer||new Ht(r,e),n=je(t,e);if(n===dt)throw new Error(`${p} did not find any content to decode`);if(n===Kt)throw new Error(`${p} got unexpected break`);return[n,r.subarray(t.pos())]}function Y(r,e){let[t,n]=Jr(r,e);if(n.length>0)throw new Error(`${p} too many terminals, data makes no sense`);return t}function Gt(r,e="utf8"){let t=Tt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var te="/",li=new TextEncoder().encode(te),Jt=li[0],re=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=Gt(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Jt)throw new Error("Invalid key")}toString(e="utf8"){return Pe(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(te))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=li),this._buf[0]!==Jt){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Jt,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Jt;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let o=0;o<t.length;o++){if(n.length<o+1)return!1;let i=t[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(te).slice(1)}type(){return Za(this.baseNamespace())}name(){return ec(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(te)||(e+=te),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(te):new r(e.slice(0,-1).join(te))}child(e){return this.toString()===te?e:e.toString()===te?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...tc(e.map(t=>t.namespaces()))])}};function Za(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function ec(r){let e=r.split(":");return e[e.length-1]}function tc(r){return[].concat(...r)}function de(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 mi="/pin/",di="/pinned-block/",Yr=Ze,hi=1;function pi(r){return r.version===0&&(r=r.toV1()),new re(`${mi}${r.toString(Yr)}`)}var Qt=class{datastore;blockstore;dagWalkers;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.dagWalkers=n}async*add(e,t={}){let n=pi(e);if(await this.datastore.has(n))throw new Error("Already pinned");let o=Math.round(t.depth??1/0);if(o<0)throw new Error("Depth must be greater than or equal to 0");let i=new it({concurrency:hi});for await(let c of this.#e(e,i,{...t,depth:o}))await this.#o(c,u=>u.pinnedBy.find(m=>de(m,e.bytes))!=null?!1:(u.pinCount++,u.pinnedBy.push(e.bytes),!0),t),yield c;let s={depth:o,metadata:t.metadata??{}};await this.datastore.put(n,lt(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let o=this.dagWalkers[e.code];if(o==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let i=await this.blockstore.get(e,n);yield e;for await(let s of o.walk(i))yield*await t.add(async()=>this.#e(s,t,{...n,depth:n.depth-1}))}async#o(e,t,n){let o=new re(`${di}${Yr.encode(e.multihash.bytes)}`),i={pinCount:0,pinnedBy:[]};try{i=Y(await this.datastore.get(o,n))}catch(c){if(c.code!=="ERR_NOT_FOUND")throw c}if(t(i)){if(i.pinCount===0&&await this.datastore.has(o)){await this.datastore.delete(o);return}await this.datastore.put(o,lt(i),n),n.onProgress?.(new b("helia:pin:add",e))}}async*rm(e,t={}){let n=pi(e),o=await this.datastore.get(n,t),i=Y(o);await this.datastore.delete(n,t);let s=new it({concurrency:hi});for await(let c of this.#e(e,s,{...t,depth:i.depth}))await this.#o(c,u=>(u.pinCount--,u.pinnedBy=u.pinnedBy.filter(m=>de(m,e.bytes)),!0),{...t,depth:i.depth}),yield c}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:mi+(e.cid!=null?`${e.cid.toString(Ze)}`:"")},e)){let o=C.parse(t.toString().substring(5),Ze),i=Y(n);yield{cid:o,...i}}}async isPinned(e,t={}){let n=new re(`${di}${Yr.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}};var rc=Symbol.for("nodejs.util.inspect.custom"),yi=Object.values(Be).map(r=>r.decoder).reduce((r,e)=>r.or(e),Be.identity.decoder),gi=114,wi=36,xi=37,ht=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[yn]=!0;toString(){return this.string==null&&(this.string=D.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return C.createV1(gi,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return de(this.multihash.bytes,e);if(typeof e=="string")return gt(e).equals(this);if(e?.multihash?.bytes!=null)return de(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[rc](){return`PeerId(${this.toString()})`}},pt=class extends ht{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},mt=class extends ht{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},yt=class extends ht{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function gt(r,e){if(e=e??yi,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=rt(D.decode(`z${r}`));return r.startsWith("12D")?new mt({multihash:t}):r.startsWith("16U")?new yt({multihash:t}):new pt({multihash:t})}return nc(yi.decode(r))}function nc(r){try{let e=rt(r);if(e.code===De.code){if(e.digest.length===wi)return new mt({multihash:e});if(e.digest.length===xi)return new yt({multihash:e})}if(e.code===Ne.code)return new pt({multihash:e})}catch{return oc(C.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function oc(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==gi)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===Ne.code)return new pt({multihash:r.multihash});if(e.code===De.code){if(e.digest.length===wi)return new mt({multihash:r.multihash});if(e.digest.length===xi)return new yt({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}function Xr(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:e(o)}}};return t}var Ve=class r{set;constructor(e){if(this.set=new Set,e!=null)for(let t of e)this.set.add(t.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(e){this.set.add(e.toString())}clear(){this.set.clear()}delete(e){this.set.delete(e.toString())}entries(){return Xr(this.set.entries(),e=>{let t=gt(e[0]);return[t,t]})}forEach(e){this.set.forEach(t=>{let n=gt(t);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return Xr(this.set.values(),e=>gt(e))}intersection(e){let t=new r;for(let n of e)this.has(n)&&t.add(n);return t}difference(e){let t=new r;for(let n of this)e.has(n)||t.add(n);return t}union(e){let t=new r;for(let n of e)t.add(n);for(let n of this)t.add(n);return t}};function ic(r){return r[Symbol.asyncIterator]!=null}function sc(...r){let e=[];for(let t of r)ic(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=ye({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)t.push(o)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var We=sc;var Yt=class{log;routers;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[]}async start(){await oe(...this.routers)}async stop(){await ie(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new O("No content routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new Ve;for await(let o of We(...He(this.routers,"findProviders").map(i=>i.findProviders(e,t))))o!=null&&(n.has(o.id)||(n.add(o.id),yield o))}async provide(e,t={}){if(this.routers.length===0)throw new O("No content routers available","ERR_NO_ROUTERS_AVAILABLE");await Promise.all(He(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async put(e,t,n){await Promise.all(He(this.routers,"put").map(async o=>{await o.put(e,t,n)}))}async get(e,t){return Promise.any(He(this.routers,"get").map(async n=>n.get(e,t)))}async findPeer(e,t){if(this.routers.length===0)throw new O("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=this,o=We(...He(this.routers,"findPeer").map(i=>async function*(){try{yield await i.findPeer(e,t)}catch(s){n.log.error(s)}}()));for await(let i of o)if(i!=null)return i;throw new O("Could not find peer in routing","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new O("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=new Ve;for await(let o of We(...He(this.routers,"getClosestPeers").map(i=>i.getClosestPeers(e,t))))o!=null&&(n.has(o.id)||(n.add(o.id),yield o))}};function He(r,e){return r.filter(t=>t[e]!=null)}var he={},Ke=r=>{r.addEventListener("message",e=>{Ke.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{Ke.dispatchEvent("message",r,e)})};Ke.addEventListener=(r,e)=>{he[r]==null&&(he[r]=[]),he[r].push(e)};Ke.removeEventListener=(r,e)=>{he[r]!=null&&(he[r]=he[r].filter(t=>t===e))};Ke.dispatchEvent=function(r,e,t){he[r]!=null&&he[r].forEach(n=>n(e,t))};var Zr=Ke;var en="lock:worker:request-read",tn="lock:worker:release-read",rn="lock:master:grant-read",nn="lock:worker:request-write",on="lock:worker:release-write",sn="lock:master:grant-write";var bi=(r=21)=>Math.random().toString().substring(2);var Ei=(r,e,t,n,o)=>(i,s)=>{if(s.data.type!==t)return;let c={type:s.data.type,name:s.data.name,identifier:s.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:c.name,handler:async()=>{i.postMessage({type:o,name:c.name,identifier:c.identifier}),await new Promise(u=>{let m=f=>{if(f==null||f.data==null)return;let d={type:f.data.type,name:f.data.name,identifier:f.data.identifier};d.type===n&&d.identifier===c.identifier&&(i.removeEventListener("message",m),u())};i.addEventListener("message",m)})}}}))},vi=(r,e,t,n)=>async()=>{let o=bi();return globalThis.postMessage({type:e,identifier:o,name:r}),new Promise(i=>{let s=c=>{if(c==null||c.data==null)return;let u={type:c.data.type,identifier:c.data.identifier};u.type===t&&u.identifier===o&&(globalThis.removeEventListener("message",s),i(()=>{globalThis.postMessage({type:n,identifier:o,name:r})}))};globalThis.addEventListener("message",s)})},ac={singleProcess:!1},ki=r=>{if(r=Object.assign({},ac,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return Zr.addEventListener("message",Ei(t,"requestReadLock",en,tn,rn)),Zr.addEventListener("message",Ei(t,"requestWriteLock",nn,on,sn)),t}return{isWorker:!0,readLock:t=>vi(t,en,rn,tn),writeLock:t=>vi(t,nn,sn,on)}};var we={},pe;async function an(r,e){let t,n=new Promise(o=>{t=o});return r.add(async()=>Ye((async()=>{await new Promise(o=>{t(()=>{o()})})})(),{milliseconds:e.timeout})),n}var cc=(r,e)=>{if(pe.isWorker===!0)return{readLock:pe.readLock(r,e),writeLock:pe.writeLock(r,e)};let t=new ce({concurrency:1}),n;return{async readLock(){if(n!=null)return an(n,e);n=new ce({concurrency:e.concurrency,autoStart:!1});let o=n,i=an(n,e);return t.add(async()=>{o.start(),await o.onIdle().then(()=>{n===o&&(n=null)})}),i},async writeLock(){return n=null,an(t,e)}}},uc={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function cn(r){let e=Object.assign({},uc,r);return pe==null&&(pe=ki(e),pe.isWorker!==!0&&(pe.addEventListener("requestReadLock",t=>{we[t.data.name]!=null&&we[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),pe.addEventListener("requestWriteLock",async t=>{we[t.data.name]!=null&&we[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),we[e.name]==null&&(we[e.name]=cc(e.name,e)),we[e.name]}var Xt=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=cn({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await oe(this.child),this.started=!0}async stop(){await ie(this.child),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){let o=await this.lock.readLock();try{return await this.child.put(e,t,n)}finally{o()}}async*putMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.putMany(e,t)}finally{n()}}async get(e,t={}){let n=await this.lock.readLock();try{return await this.child.get(e,t)}finally{n()}}async*getMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.getMany(e,t)}finally{n()}}async delete(e,t={}){let n=await this.lock.writeLock();try{if(await this.pins.isPinned(e))throw new Error("CID was pinned");await this.child.delete(e,t)}finally{n()}}async*deleteMany(e,t={}){let n=await this.lock.writeLock();try{let o=this;yield*this.child.deleteMany(async function*(){for await(let i of e){if(await o.pins.isPinned(i))throw new Error("CID was pinned");yield i}}(),t)}finally{n()}}async has(e,t={}){let n=await this.lock.readLock();try{return await this.child.has(e,t)}finally{n()}}async*getAll(e={}){let t=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{t()}}};var Ci=42;function fc(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=C.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new l(a.tag,Ci),new l(a.bytes,t)]}function lc(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function dc(r){if(Number.isNaN(r))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(r===1/0||r===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var Ai={float64:!0,typeEncoders:{Object:fc,undefined:lc,number:dc}},$d={...Ai,typeEncoders:{...Ai.typeEncoders}};function hc(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return C.decode(r.subarray(1))}var un={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};un.tags[Ci]=hc;var Md={...un,tags:un.tags.slice()};var _i=113;var Ti=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===a.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===a.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[a.uint.major](e,t){this.prefix(e);let n=String(t.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[a.negint.major](e,t){this[a.uint.major](e,t)}[a.bytes.major](e,t){throw new Error(`${$e} unsupported type: Uint8Array`)}[a.string.major](e,t){this.prefix(e);let n=Ut(JSON.stringify(t.value));e.push(n.length>32?st(n):n)}[a.array.major](e,t){this.prefix(e),this.inRecursive.push({type:a.array,elements:0}),e.push([91])}[a.map.major](e,t){this.prefix(e),this.inRecursive.push({type:a.map,elements:0}),e.push([123])}[a.tag.major](e,t){}[a.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===a.array)e.push([93]);else if(s.type===a.map)e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(t.value===void 0)throw new Error(`${$e} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.value),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};var xe=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${p} unexpected end of input at position ${this._pos}`);for(let t=0;t<e.length;t++)if(this.data[this._pos++]!==e[t])throw new Error(`${p} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,o=c=>{for(;!this.done();){let u=this.ch();if(c.includes(u))this._pos++;else break}};if(this.ch()===45&&(t=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new l(a.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${p} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${p} unexpected token at position ${this._pos}`);n=!0,this._pos++,o([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,o([48,49,50,51,52,53,54,55,56,57]));let i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);return n?new l(a.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new l(s>=0?a.uint:a.negint,s,this._pos-e):new l(s>=0?a.uint:a.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${p} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let c=this.data[i];if(c===92||c<32||c>=128)break;if(c===34){let u=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new l(a.string,u,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${p} unexpected end of unicode escape sequence at position ${this._pos}`);let i=0;for(let s=0;s<4;s++){let c=this.ch();if(c>=48&&c<=57)c-=48;else if(c>=97&&c<=102)c=c-97+10;else if(c>=65&&c<=70)c=c-65+10;else throw new Error(`${p} unexpected unicode escape character at position ${this._pos}`);i=i*16+c,this._pos++}return i},o=()=>{let i=this.ch(),s=null,c=i>239?4:i>223?3:i>191?2:1;if(this._pos+c>this.data.length)throw new Error(`${p} unexpected unicode sequence at position ${this._pos}`);let u,m,f,d;switch(c){case 1:i<128&&(s=i);break;case 2:u=this.data[this._pos+1],(u&192)===128&&(d=(i&31)<<6|u&63,d>127&&(s=d));break;case 3:u=this.data[this._pos+1],m=this.data[this._pos+2],(u&192)===128&&(m&192)===128&&(d=(i&15)<<12|(u&63)<<6|m&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:u=this.data[this._pos+1],m=this.data[this._pos+2],f=this.data[this._pos+3],(u&192)===128&&(m&192)===128&&(f&192)===128&&(d=(i&15)<<18|(u&63)<<12|(m&63)<<6|f&63,d>65535&&d<1114112&&(s=d))}s===null?(s=65533,c=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=c};for(;!this.done();){let i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${p} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:t.push(s);break;case 98:t.push(8);break;case 116:t.push(9);break;case 110:t.push(10);break;case 102:t.push(12);break;case 114:t.push(13);break;case 117:t.push(n());break;default:throw new Error(`${p} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new l(a.string,jr(t),this._pos-e);default:if(i<32)throw new Error(`${p} invalid control character at position ${this._pos}`);i<128?(t.push(i),this._pos++):o()}}throw new Error(`${p} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new l(a.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new l(a.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new l(a.null,null,4);case 102:return this.expect([102,97,108,115,101]),new l(a.false,!1,5);case 116:return this.expect([116,114,117,101]),new l(a.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${p} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new l(a.break,void 0,1);if(this.ch()!==44)throw new Error(`${p} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new l(a.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new l(a.break,void 0,1);if(this.ch()!==44)throw new Error(`${p} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new l(a.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${p} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${p} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Zt(r,e){return e=Object.assign({tokenizer:new xe(r,e)},e),Y(r,e)}var yc={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};yc.tags[42]=C.parse;var Ii=297;var nh=new TextDecoder;var oh=new TextEncoder;var wc=new TextDecoder;function fn(r,e){let t=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=r.length)throw new Error("protobuf: unexpected end of data");let o=r[e++];if(t+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[t,e]}function er(r,e){let t;[t,e]=fn(r,e);let n=e+t;if(t<0||n<0)throw new Error("protobuf: invalid length");if(n>r.length)throw new Error("protobuf: unexpected end of data");return[r.subarray(e,n),n]}function Li(r,e){let t;return[t,e]=fn(r,e),[t&7,t>>3,e]}function xc(r){let e={},t=r.length,n=0;for(;n<t;){let o,i;if([o,i,n]=Li(r,n),i===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=er(r,n)}else if(i===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=er(r,n),e.Name=wc.decode(s)}else if(i===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(o!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Tsize`);[e.Tsize,n]=fn(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Di(r){let e=r.length,t=0,n,o=!1,i;for(;t<e;){let c,u;if([c,u,t]=Li(r,t),c!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${c}`);if(u===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,t]=er(r,t),n&&(o=!0)}else if(u===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let m;[m,t]=er(r,t),n.push(xc(m))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${u}`)}if(t>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var sh=new TextEncoder,ah=2**32,ch=2**31;var lh=new TextEncoder;function Ni(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var Bi=112;function Pi(r){let e=Ni(r),t=Di(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(o=>{let i={};try{i.Hash=C.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}var Ec={codec:Bi,*walk(r){yield*Pi(r).Links.map(t=>t.Hash)}},vc={codec:On,*walk(){}},Ri=42,kc={codec:_i,*walk(r){let e=[],t=[];t[Ri]=n=>{if(n[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");let o=C.decode(n.subarray(1));return e.push(o),o},Y(r,{tags:t}),yield*e}},ln=class extends xe{tokenBuffer;constructor(e,t){super(e,t),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(e.type===a.map){let t=this._next();if(t.type===a.string&&t.value==="/"){let n=this._next();if(n.type===a.string){if(this._next().type!==a.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new l(a.tag,42,0)}if(n.type===a.map){let o=this._next();if(o.type===a.string&&o.value==="bytes"){let i=this._next();if(i.type===a.string){for(let c=0;c<2;c++)if(this._next().type!==a.break)throw new Error("Invalid encoded Bytes form");let s=_e.decode(`m${i.value}`);return new l(a.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},Ac={codec:Ii,*walk(r){let e=[],t=[];t[Ri]=n=>{let o=C.parse(n);return e.push(o),o},Zt(r,{tags:t,tokenizer:new ln(r,{tags:t,allowIndefinite:!0,allowUndefined:!0,allowNaN:!0,allowInfinity:!0,allowBigInt:!0,strict:!1,rejectDuplicateMapKeys:!1})}),yield*e}},Cc={codec:Rn,*walk(){}};function Ui(r=[]){let e={};return[Ec,vc,kc,Ac,Cc,...r].forEach(t=>{e[t.codec]=t}),e}var dn=new re("/version"),Oi=1;async function Fi(r){if(!await r.has(dn)){await r.put(dn,Gt(`${Oi}`));return}let e=await r.get(dn),t=Pe(e);if(parseInt(t,10)!==Oi)throw new Error("Unknown datastore version, a datastore migration may be required")}function $i(r=[]){let e={};return[Ne,Pr,De,...r].forEach(t=>{e[t.code]=t}),e}function Mi(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var Ge=class{has(e,t){return Promise.reject(new Error(".has is not implemented"))}put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,t){for await(let{cid:n,block:o}of e)await this.put(n,o,t),yield n}get(e,t){return Promise.reject(new Error(".get is not implemented"))}async*getMany(e,t){for await(let n of e)yield{cid:n,block:await this.get(n,t)}}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,t){for await(let n of e)await this.delete(n,t),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var tr=xt(ji(),1);function Vi(r){return r=r??new Error("Put failed"),(0,tr.default)(r,"ERR_PUT_FAILED")}function Wi(r){return r=r??new Error("Delete failed"),(0,tr.default)(r,"ERR_DELETE_FAILED")}function rr(r){return r=r??new Error("Not Found"),(0,tr.default)(r,"ERR_NOT_FOUND")}var Ki=0,nr=class extends Ge{put(e){return e}get(e){if(e.code===Ki)return e.multihash.digest;throw rr()}has(e){return e.code===Ki}delete(){}*getAll(){}};function Tc(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var or=Tc;function Sc(r){return r[Symbol.asyncIterator]!=null}function Ic(r,e){if(Sc(r))return async function*(){for await(let c of r)await e(c)&&(yield c)}();let t=or(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();let i=e(n);if(typeof i.then=="function")return async function*(){await i&&(yield n);for await(let c of t)await e(c)&&(yield c)}();let s=e;return function*(){i===!0&&(yield n);for(let c of t)s(c)&&(yield c)}()}var ir=Ic;var Lc=wr("blockstore:core:tiered"),sr=class extends Ge{stores;constructor(e){super(),this.stores=e.slice()}async put(e,t,n){try{return await Promise.all(this.stores.map(async o=>{await o.put(e,t,n)})),e}catch(o){throw Vi(o)}}async get(e,t){for(let n of this.stores)try{let o=await n.get(e,t);if(o!=null)return o}catch(o){Lc.error(o)}throw rr()}async has(e,t){for(let n of this.stores)if(await n.has(e,t))return!0;return!1}async delete(e,t){try{await Promise.all(this.stores.map(async n=>{await n.delete(e,t)}))}catch(n){throw Wi(n)}}async*putMany(e,t={}){let n,o=this.stores.map(i=>{let s=ye({objectMode:!0});return ot(i.putMany(s,t)).catch(c=>{n=c}),s});try{for await(let i of e){if(n!=null)throw n;o.forEach(s=>s.push(i)),yield i.cid}}finally{o.forEach(i=>i.end())}}async*deleteMany(e,t={}){let n,o=this.stores.map(i=>{let s=ye({objectMode:!0});return ot(i.deleteMany(s,t)).catch(c=>{n=c}),s});try{for await(let i of e){if(n!=null)throw n;o.forEach(s=>s.push(i)),yield i}}finally{o.forEach(i=>i.end())}}async*getAll(e){let t=new Set;yield*ir(We(...this.stores.map(n=>n.getAll(e))),n=>{let o=n.cid.toString();return t.has(o)?!1:(t.add(o),!0)})}};function Dc(r){return r[Symbol.asyncIterator]!=null}function Gi(r){return r?.then!=null}function Nc(r,e){if(Dc(r))return async function*(){for await(let c of r){let u=e(c);Gi(u)&&await u,yield c}}();let t=or(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();if(typeof e(n)?.then=="function")return async function*(){yield n;for await(let c of t){let u=e(c);Gi(u)&&await u,yield c}}();let s=e;return function*(){yield n;for(let c of t)s(c),yield c}()}var hn=Nc;function Bc(r){return typeof r.retrieve=="function"}function Pc(r){return typeof r.announce=="function"}var ar=class{child;blockRetrievers;blockAnnouncers;hashers;started;log;constructor(e){this.log=e.logger.forComponent("helia:networked-storage"),this.child=new sr([new nr,e.blockstore]),this.blockRetrievers=(e.blockBrokers??[]).filter(Bc),this.blockAnnouncers=(e.blockBrokers??[]).filter(Pc),this.hashers=e.hashers??{},this.started=!1}isStarted(){return this.started}async start(){await oe(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!0}async stop(){await ie(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){return await this.child.has(e)?(n.onProgress?.(new b("blocks:put:duplicate",e)),e):(n.onProgress?.(new b("blocks:put:providers:notify",e)),this.blockAnnouncers.forEach(o=>{o.announce(e,t,n)}),n.onProgress?.(new b("blocks:put:blockstore:put",e)),this.child.put(e,t,n))}async*putMany(e,t={}){let n=ir(e,async({cid:i})=>{let s=await this.child.has(i);return s&&t.onProgress?.(new b("blocks:put-many:duplicate",i)),!s}),o=hn(n,({cid:i,block:s})=>{t.onProgress?.(new b("blocks:put-many:providers:notify",i)),this.blockAnnouncers.forEach(c=>{c.announce(i,s,t)})});t.onProgress?.(new b("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(o,t)}async get(e,t={}){if(t.offline!==!0&&!await this.child.has(e)){t.onProgress?.(new b("blocks:get:providers:get",e));let n=await Ji(e,this.blockRetrievers,this.hashers[e.multihash.code],{...t,log:this.log});return t.onProgress?.(new b("blocks:get:blockstore:put",e)),await this.child.put(e,n,t),t.onProgress?.(new b("blocks:get:providers:notify",e)),this.blockAnnouncers.forEach(o=>{o.announce(e,n,t)}),n}return t.onProgress?.(new b("blocks:get:blockstore:get",e)),this.child.get(e,t)}async*getMany(e,t={}){t.onProgress?.(new b("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(hn(e,async n=>{if(t.offline!==!0&&!await this.child.has(n)){t.onProgress?.(new b("blocks:get-many:providers:get",n));let o=await Ji(n,this.blockRetrievers,this.hashers[n.multihash.code],{...t,log:this.log});t.onProgress?.(new b("blocks:get-many:blockstore:put",n)),await this.child.put(n,o,t),t.onProgress?.(new b("blocks:get-many:providers:notify",n)),this.blockAnnouncers.forEach(i=>{i.announce(n,o,t)})}}))}async delete(e,t={}){t.onProgress?.(new b("blocks:delete:blockstore:delete",e)),await this.child.delete(e,t)}async*deleteMany(e,t={}){t.onProgress?.(new b("blocks:delete-many:blockstore:delete-many")),yield*this.child.deleteMany(async function*(){for await(let n of e)yield n}(),t)}async has(e,t={}){return this.child.has(e,t)}async*getAll(e={}){e.onProgress?.(new b("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}},Rc=(r,e)=>{if(e==null)throw new O(`No hasher configured for multihash code 0x${r.multihash.code.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`,"ERR_UNKNOWN_HASH_ALG");return async t=>{let n=await e.digest(t);if(!de(n.digest,r.multihash.digest))throw new O("Hash of downloaded block did not match multihash from passed CID","ERR_HASH_MISMATCH")}};async function Ji(r,e,t,n){let o=Rc(r,t),i=new AbortController,s=Mi([i.signal,n.signal]);try{return await Promise.any(e.map(async c=>{try{let u=!1,m=await c.retrieve(r,{...n,signal:s,validateFn:async f=>{await o(f),u=!0}});return u||await o(m),m}catch(u){throw n.log.error("could not retrieve verified block for %c",r,u),u}}))}finally{s.clear()}}var pn=class{blockstore;datastore;pins;logger;routing;dagWalkers;hashers;dns;log;constructor(e){this.logger=e.logger??In(),this.log=this.logger.forComponent("helia"),this.hashers=$i(e.hashers),this.dagWalkers=Ui(e.dagWalkers),this.dns=e.dns??oo();let t={blockstore:e.blockstore,datastore:e.datastore,hashers:this.hashers,dagWalkers:this.dagWalkers,logger:this.logger,blockBrokers:[],dns:this.dns,...e.components??{}};t.blockBrokers=e.blockBrokers.map(o=>o(t));let n=new ar(t);this.pins=new Qt(e.datastore,n,this.dagWalkers),this.blockstore=new Xt(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,this.routing=new Yt(t,{routers:(e.routers??[]).flatMap(o=>{let i=[o];return o[cr]!=null&&i.push(o[cr]),o[ur]!=null&&i.push(o[ur]),i})})}async start(){await Fi(this.datastore),await oe(this.blockstore,this.datastore,this.routing)}async stop(){await ie(this.blockstore,this.datastore,this.routing)}async gc(e={}){let t=await this.blockstore.lock.writeLock();try{let n=this,o=this.blockstore.unwrap();this.log("gc start"),await ot(o.deleteMany(async function*(){for await(let{cid:i}of o.getAll())try{if(await n.pins.isPinned(i,e))continue;yield i,e.onProgress?.(new b("helia:gc:deleted",i))}catch(s){n.log.error("Error during gc",s),e.onProgress?.(new b("helia:gc:error",s))}}()))}finally{t()}this.log("gc finished")}};return ts(Uc);})();
|
|
2
|
+
"use strict";var HeliaUtils=(()=>{var Fi=Object.create;var ft=Object.defineProperty;var $i=Object.getOwnPropertyDescriptor;var Mi=Object.getOwnPropertyNames;var zi=Object.getPrototypeOf,qi=Object.prototype.hasOwnProperty;var Ee=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),P=(r,e)=>{for(var t in e)ft(r,t,{get:e[t],enumerable:!0})},ln=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Mi(e))!qi.call(r,o)&&o!==t&&ft(r,o,{get:()=>e[o],enumerable:!(n=$i(e,o))||n.enumerable});return r};var lt=(r,e,t)=>(t=r!=null?Fi(zi(r)):{},ln(e||!r||!r.__esModule?ft(t,"default",{value:r,enumerable:!0}):t,r)),Vi=r=>ln(ft({},"__esModule",{value:!0}),r);var pn=Ee((Bc,hn)=>{var ve=1e3,Ae=ve*60,Ce=Ae*60,me=Ce*24,Wi=me*7,Hi=me*365.25;hn.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return Gi(r);if(t==="number"&&isFinite(r))return e.long?Ji(r):Ki(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Gi(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*Hi;case"weeks":case"week":case"w":return t*Wi;case"days":case"day":case"d":return t*me;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Ce;case"minutes":case"minute":case"mins":case"min":case"m":return t*Ae;case"seconds":case"second":case"secs":case"sec":case"s":return t*ve;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function Ki(r){var e=Math.abs(r);return e>=me?Math.round(r/me)+"d":e>=Ce?Math.round(r/Ce)+"h":e>=Ae?Math.round(r/Ae)+"m":e>=ve?Math.round(r/ve)+"s":r+"ms"}function Ji(r){var e=Math.abs(r);return e>=me?ht(r,e,me,"day"):e>=Ce?ht(r,e,Ce,"hour"):e>=Ae?ht(r,e,Ae,"minute"):e>=ve?ht(r,e,ve,"second"):r+" ms"}function ht(r,e,t,n){var o=e>=t*1.5;return Math.round(r/t)+" "+n+(o?"s":"")}});var yn=Ee((Pc,mn)=>{function Qi(r){t.debug=t,t.default=t,t.coerce=u,t.disable=i,t.enable=o,t.enabled=s,t.humanize=pn(),t.destroy=p,Object.keys(r).forEach(f=>{t[f]=r[f]}),t.names=[],t.skips=[],t.formatters={};function e(f){let d=0;for(let g=0;g<f.length;g++)d=(d<<5)-d+f.charCodeAt(g),d|=0;return t.colors[Math.abs(d)%t.colors.length]}t.selectColor=e;function t(f){let d,g=null,B,E;function w(...y){if(!w.enabled)return;let k=w,A=Number(new Date),C=A-(d||A);k.diff=C,k.prev=d,k.curr=A,d=A,y[0]=t.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let T=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(V,R)=>{if(V==="%%")return"%";T++;let j=t.formatters[R];if(typeof j=="function"){let be=y[T];V=j.call(k,be),y.splice(T,1),T--}return V}),t.formatArgs.call(k,y),(k.log||t.log).apply(k,y)}return w.namespace=f,w.useColors=t.useColors(),w.color=t.selectColor(f),w.extend=n,w.destroy=t.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>g!==null?g:(B!==t.namespaces&&(B=t.namespaces,E=t.enabled(f)),E),set:y=>{g=y}}),typeof t.init=="function"&&t.init(w),w}function n(f,d){let g=t(this.namespace+(typeof d>"u"?":":d)+f);return g.log=this.log,g}function o(f){t.save(f),t.namespaces=f,t.names=[],t.skips=[];let d,g=(typeof f=="string"?f:"").split(/[\s,]+/),B=g.length;for(d=0;d<B;d++)g[d]&&(f=g[d].replace(/\*/g,".*?"),f[0]==="-"?t.skips.push(new RegExp("^"+f.slice(1)+"$")):t.names.push(new RegExp("^"+f+"$")))}function i(){let f=[...t.names.map(c),...t.skips.map(c).map(d=>"-"+d)].join(",");return t.enable(""),f}function s(f){if(f[f.length-1]==="*")return!0;let d,g;for(d=0,g=t.skips.length;d<g;d++)if(t.skips[d].test(f))return!1;for(d=0,g=t.names.length;d<g;d++)if(t.names[d].test(f))return!0;return!1}function c(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function u(f){return f instanceof Error?f.stack||f.message:f}function p(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}mn.exports=Qi});var gn=Ee((O,pt)=>{O.formatArgs=Yi;O.save=Zi;O.load=es;O.useColors=Xi;O.storage=ts();O.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();O.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Xi(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Yi(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+pt.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}O.log=console.debug||console.log||(()=>{});function Zi(r){try{r?O.storage.setItem("debug",r):O.storage.removeItem("debug")}catch{}}function es(){let r;try{r=O.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function ts(){try{return localStorage}catch{}}pt.exports=yn()(O);var{formatters:rs}=pt.exports;rs.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var Tn=Ee((Kc,cr)=>{"use strict";var Es=Object.prototype.hasOwnProperty,D="~";function We(){}Object.create&&(We.prototype=Object.create(null),new We().__proto__||(D=!1));function ks(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Cn(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new ks(t,n||r,o),s=D?D+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],i]:r._events[s].push(i):(r._events[s]=i,r._eventsCount++),r}function mt(r,e){--r._eventsCount===0?r._events=new We:delete r._events[e]}function L(){this._events=new We,this._eventsCount=0}L.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Es.call(t,n)&&e.push(D?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};L.prototype.listeners=function(e){var t=D?D+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};L.prototype.listenerCount=function(e){var t=D?D+e:e,n=this._events[t];return n?n.fn?1:n.length:0};L.prototype.emit=function(e,t,n,o,i,s){var c=D?D+e:e;if(!this._events[c])return!1;var u=this._events[c],p=arguments.length,f,d;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),p){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,n),!0;case 4:return u.fn.call(u.context,t,n,o),!0;case 5:return u.fn.call(u.context,t,n,o,i),!0;case 6:return u.fn.call(u.context,t,n,o,i,s),!0}for(d=1,f=new Array(p-1);d<p;d++)f[d-1]=arguments[d];u.fn.apply(u.context,f)}else{var g=u.length,B;for(d=0;d<g;d++)switch(u[d].once&&this.removeListener(e,u[d].fn,void 0,!0),p){case 1:u[d].fn.call(u[d].context);break;case 2:u[d].fn.call(u[d].context,t);break;case 3:u[d].fn.call(u[d].context,t,n);break;case 4:u[d].fn.call(u[d].context,t,n,o);break;default:if(!f)for(B=1,f=new Array(p-1);B<p;B++)f[B-1]=arguments[B];u[d].fn.apply(u[d].context,f)}}return!0};L.prototype.on=function(e,t,n){return Cn(this,e,t,n,!1)};L.prototype.once=function(e,t,n){return Cn(this,e,t,n,!0)};L.prototype.removeListener=function(e,t,n,o){var i=D?D+e:e;if(!this._events[i])return this;if(!t)return mt(this,i),this;var s=this._events[i];if(s.fn)s.fn===t&&(!o||s.once)&&(!n||s.context===n)&&mt(this,i);else{for(var c=0,u=[],p=s.length;c<p;c++)(s[c].fn!==t||o&&!s[c].once||n&&s[c].context!==n)&&u.push(s[c]);u.length?this._events[i]=u.length===1?u[0]:u:mt(this,i)}return this};L.prototype.removeAllListeners=function(e){var t;return e?(t=D?D+e:e,this._events[t]&&mt(this,t)):(this._events=new We,this._eventsCount=0),this};L.prototype.off=L.prototype.removeListener;L.prototype.addListener=L.prototype.on;L.prefixed=D;L.EventEmitter=L;typeof cr<"u"&&(cr.exports=L)});var Kn=Ee((tf,Gn)=>{Gn.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function o(i,s){t[i]=s,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(i){return t[i]!==void 0||n[i]!==void 0},remove:function(i){t[i]!==void 0&&(t[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=t[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){t[i]!==void 0?t[i]=s:o(i,s)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var Di=Ee((ah,Ni)=>{"use strict";function Li(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function lc(r,e,t){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");t||(t={}),typeof e=="object"&&(t=e,e=""),e&&(t.code=e);try{return Li(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),Li(new o,t)}}Ni.exports=lc});var Ac={};P(Ac,{Helia:()=>fn});var Xt=Symbol.for("@libp2p/content-routing");var Yt=Symbol.for("@libp2p/peer-routing");var ie=class r extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.name="AbortError",this.code=r.code,this.type=r.type}static code="ABORT_ERR";static type="aborted"},N=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var ke=(r,...e)=>{try{[...e]}catch{}};var dt=class extends EventTarget{#e=new Map;constructor(){super(),ke(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new ji(e,t))}},Zt=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},ji=globalThis.CustomEvent??Zt;function dn(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function se(...r){let e=[];for(let t of r)dn(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function ae(...r){let e=[];for(let t of r)dn(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var F=lt(gn(),1);var or={};P(or,{base32:()=>ee,base32hex:()=>ls,base32hexpad:()=>hs,base32hexpadupper:()=>ps,base32hexupper:()=>ds,base32pad:()=>us,base32padupper:()=>fs,base32upper:()=>cs,base32z:()=>ms});var Uc=new Uint8Array(0);function wn(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 Z(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function xn(r){return new TextEncoder().encode(r)}function bn(r){return new TextDecoder().decode(r)}function ns(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var c=r.length,u=r.charAt(0),p=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function d(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var w=0,y=0,k=0,A=E.length;k!==A&&E[k]===0;)k++,w++;for(var C=(A-k)*f+1>>>0,T=new Uint8Array(C);k!==A;){for(var U=E[k],V=0,R=C-1;(U!==0||V<y)&&R!==-1;R--,V++)U+=256*T[R]>>>0,T[R]=U%c>>>0,U=U/c>>>0;if(U!==0)throw new Error("Non-zero carry");y=V,k++}for(var j=C-y;j!==C&&T[j]===0;)j++;for(var be=u.repeat(w);j<C;++j)be+=r.charAt(T[j]);return be}function g(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var w=0;if(E[w]!==" "){for(var y=0,k=0;E[w]===u;)y++,w++;for(var A=(E.length-w)*p+1>>>0,C=new Uint8Array(A);E[w];){var T=t[E.charCodeAt(w)];if(T===255)return;for(var U=0,V=A-1;(T!==0||U<k)&&V!==-1;V--,U++)T+=c*C[V]>>>0,C[V]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");k=U,w++}if(E[w]!==" "){for(var R=A-k;R!==A&&C[R]===0;)R++;for(var j=new Uint8Array(y+(A-R)),be=y;R!==A;)j[be++]=C[R++];return j}}}function B(E){var w=g(E);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:g,decode:B}}var os=ns,is=os,kn=is;var er=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")}},tr=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=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 vn(this,e)}},rr=class{decoders;constructor(e){this.decoders=e}or(e){return vn(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 vn(r,e){return new rr({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var nr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new er(e,t,n),this.decoder=new tr(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Te({name:r,prefix:e,encode:t,decode:n}){return new nr(r,e,t,n)}function ce({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=kn(t,r);return Te({prefix:e,name:r,encode:n,decode:i=>Z(o(i))})}function ss(r,e,t,n){let o={};for(let f=0;f<e.length;++f)o[e[f]]=f;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),c=0,u=0,p=0;for(let f=0;f<i;++f){let d=o[r[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<t|d,c+=t,c>=8&&(c-=8,s[p++]=255&u>>c)}if(c>=t||255&u<<8-c)throw new SyntaxError("Unexpected end of data");return s}function as(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,c=0;for(let u=0;u<r.length;++u)for(c=c<<8|r[u],s+=8;s>t;)s-=t,i+=e[o&c>>s];if(s!==0&&(i+=e[o&c<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function v({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Te({prefix:e,name:r,encode(o){return as(o,n,t)},decode(o){return ss(o,n,t,r)}})}var ee=v({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),cs=v({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),us=v({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),fs=v({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ls=v({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ds=v({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),hs=v({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ps=v({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ms=v({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ir={};P(ir,{base58btc:()=>W,base58flickr:()=>ys});var W=ce({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ys=ce({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var sr={};P(sr,{base64:()=>_e,base64pad:()=>gs,base64url:()=>ws,base64urlpad:()=>xs});var _e=v({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),gs=v({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ws=v({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),xs=v({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});F.default.formatters.b=r=>r==null?"undefined":W.baseEncode(r);F.default.formatters.t=r=>r==null?"undefined":ee.baseEncode(r);F.default.formatters.m=r=>r==null?"undefined":_e.baseEncode(r);F.default.formatters.p=r=>r==null?"undefined":r.toString();F.default.formatters.c=r=>r==null?"undefined":r.toString();F.default.formatters.k=r=>r==null?"undefined":r.toString();F.default.formatters.a=r=>r==null?"undefined":r.toString();function bs(r){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=r,e.destroy=()=>!0,e.extend=()=>e,e}function An(){return{forComponent(r){return ar(r)}}}function ar(r){let e=bs(`${r}:trace`);return F.default.enabled(`${r}:trace`)&&F.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,F.default)(`${r}:trace`)),Object.assign((0,F.default)(r),{error:(0,F.default)(`${r}:error`),trace:e})}var b=class extends Event{constructor(e,t){super(e),this.detail=t}};var ur=lt(Tn(),1);var He=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},fr=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},_n=r=>globalThis.DOMException===void 0?new fr(r):new DOMException(r),Sn=r=>{let e=r.reason===void 0?_n("This operation was aborted."):r.reason;return e instanceof Error?e:_n(e)};function Ge(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,u=new Promise((p,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:g}=e;g.aborted&&f(Sn(g)),g.addEventListener("abort",()=>{f(Sn(g))})}if(t===Number.POSITIVE_INFINITY){r.then(p,f);return}let d=new He;s=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(g){f(g)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?f(o):(d.message=o??`Promise timed out after ${t} milliseconds`,f(d))},t),(async()=>{try{p(await r)}catch(g){f(g)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function lr(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var Ke=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let o=lr(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var ue=class extends ur.default{#e;#o;#s=0;#h;#a;#p=0;#r;#c;#t;#m;#n=0;#u;#i;#y;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Ke,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#o=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#h=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#y=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#x(){return this.#o||this.#s<this.#h}get#b(){return this.#n<this.#u}#E(){this.#n--,this.#f(),this.emit("next")}#k(){this.#w(),this.#g(),this.#c=void 0}get#v(){let e=Date.now();if(this.#r===void 0){let t=this.#p-e;if(t<0)this.#s=this.#e?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#k()},t)),!0}return!1}#f(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){let e=!this.#v;if(this.#x&&this.#b){let t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#g(),!0):!1}}return!1}#g(){this.#o||this.#r!==void 0||(this.#r=setInterval(()=>{this.#w()},this.#a),this.#p=Date.now()+this.#a)}#w(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#e?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#u=e,this.#l()}async#A(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#y,...t},new Promise((n,o)=>{this.#t.enqueue(async()=>{this.#n++,this.#s++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=Ge(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#A(t.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof He&&!t.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#E()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#i?(this.#i=!1,this.#l(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#m}async onEmpty(){this.#t.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#d("next",()=>this.#t.size<e)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#d("idle")}async#d(e,t){return new Promise(n=>{let o=()=>{t&&!t()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#i}};function yt(r){let e=[K.A];return r==null?e:Array.isArray(r)?r.length===0?e:r:[r]}var dr={};P(dr,{base10:()=>vs});var vs=ce({prefix:"9",name:"base10",alphabet:"0123456789"});var hr={};P(hr,{base16:()=>As,base16upper:()=>Cs});var As=v({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Cs=v({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var pr={};P(pr,{base2:()=>Ts});var Ts=v({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var mr={};P(mr,{base256emoji:()=>Ns});var In=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}"),_s=In.reduce((r,e,t)=>(r[t]=e,r),[]),Ss=In.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Is(r){return r.reduce((e,t)=>(e+=_s[t],e),"")}function Ls(r){let e=[];for(let t of r){let n=Ss[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Ns=Te({prefix:"\u{1F680}",name:"base256emoji",encode:Is,decode:Ls});var yr={};P(yr,{base36:()=>Je,base36upper:()=>Ds});var Je=ce({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ds=ce({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var gr={};P(gr,{base8:()=>Bs});var Bs=v({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var wr={};P(wr,{identity:()=>Ps});var Ps=Te({prefix:"\0",name:"identity",encode:r=>bn(r),decode:r=>xn(r)});var pu=new TextEncoder,mu=new TextDecoder;var Ln=512;var xr=85;var Ar={};P(Ar,{identity:()=>vr});var Us=Pn,Dn=128,Rs=127,Os=~Rs,Fs=Math.pow(2,31);function Pn(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Fs;)e[t++]=r&255|Dn,r/=128;for(;r&Os;)e[t++]=r&255|Dn,r>>>=7;return e[t]=r|0,Pn.bytes=t-n+1,e}var $s=Er,Ms=128,Bn=127;function Er(r,n){var t=0,n=n||0,o=0,i=n,s,c=r.length;do{if(i>=c)throw Er.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Bn)<<o:(s&Bn)*Math.pow(2,o),o+=7}while(s>=Ms);return Er.bytes=i-n,t}var zs=Math.pow(2,7),qs=Math.pow(2,14),Vs=Math.pow(2,21),js=Math.pow(2,28),Ws=Math.pow(2,35),Hs=Math.pow(2,42),Gs=Math.pow(2,49),Ks=Math.pow(2,56),Js=Math.pow(2,63),Qs=function(r){return r<zs?1:r<qs?2:r<Vs?3:r<js?4:r<Ws?5:r<Hs?6:r<Gs?7:r<Ks?8:r<Js?9:10},Xs={encode:Us,decode:$s,encodingLength:Qs},Ys=Xs,Qe=Ys;function Xe(r,e=0){return[Qe.decode(r,e),Qe.decode.bytes]}function Se(r,e,t=0){return Qe.encode(r,e,t),e}function Ie(r){return Qe.encodingLength(r)}function ye(r,e){let t=e.byteLength,n=Ie(r),o=n+Ie(t),i=new Uint8Array(o+t);return Se(r,i,0),Se(t,i,n),i.set(e,o),new Le(r,t,e,i)}function kr(r){let e=Z(r),[t,n]=Xe(e),[o,i]=Xe(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Le(t,o,s,e)}function Un(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&wn(r.bytes,t.bytes)}}var Le=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Rn=0,Zs="identity",On=Z;function ea(r){return ye(Rn,On(r))}var vr={code:Rn,name:Zs,encode:On,digest:ea};var Ir={};P(Ir,{sha256:()=>_r,sha512:()=>Sr});function Tr({name:r,code:e,encode:t}){return new Cr(r,e,t)}var Cr=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?ye(this.code,t):t.then(n=>ye(this.code,n))}else throw Error("Unknown type, must be binary type")}};function $n(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var _r=Tr({name:"sha2-256",code:18,encode:$n("SHA-256")}),Sr=Tr({name:"sha2-512",code:19,encode:$n("SHA-512")});function Mn(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return ra(t,Lr(r),e??W.encoder);default:return na(t,Lr(r),e??ee.encoder)}}var zn=new WeakMap;function Lr(r){let e=zn.get(r);if(e==null){let t=new Map;return zn.set(r,t),t}return e}var _=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}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!==Ye)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==oa)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=ye(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&&Un(e.multihash,n.multihash)}toString(e){return Mn(this,e)}toJSON(){return{"/":Mn(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:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??qn(n,o,i.bytes))}else if(t[ia]===!0){let{version:n,multihash:o,code:i}=t,s=kr(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Ye)throw new Error(`Version 0 CID must use dag-pb (code: ${Ye}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=qn(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ye,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,o=Z(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Le(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[d,g]=Xe(e.subarray(t));return t+=g,d},o=n(),i=Ye;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,c=n(),u=n(),p=t+u,f=p-s;return{version:o,codec:i,multihashCode:c,digestSize:u,multihashSize:f,size:p}}static parse(e,t){let[n,o]=ta(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Lr(i).set(n,e),i}};function ta(r,e){switch(r[0]){case"Q":{let t=e??W;return[W.prefix,t.decode(`${W.prefix}${r}`)]}case W.prefix:{let t=e??W;return[W.prefix,t.decode(r)]}case ee.prefix:{let t=e??ee;return[ee.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function ra(r,e,t){let{prefix:n}=t;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function na(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var Ye=112,oa=18;function qn(r,e,t){let n=Ie(r),o=n+Ie(e),i=new Uint8Array(o+t.byteLength);return Se(r,i,0),Se(e,i,n),i.set(t,o),i}var ia=Symbol.for("@ipld/js-cid/CID");var Nr={...wr,...pr,...gr,...dr,...hr,...or,...yr,...ir,...sr,...mr},Ru={...Ir,...Ar};function Vn(r=0){return new Uint8Array(r)}function Wn(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var jn=Wn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Dr=Wn("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=Vn(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),sa={utf8:jn,"utf-8":jn,hex:Nr.base16,latin1:Dr,ascii:Dr,binary:Dr,...Nr},wt=sa;function De(r,e="utf8"){let t=wt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Br=60;function xt(r){return{Status:r.Status??0,TC:r.TC??r.flag_tc??!1,RD:r.RD??r.flag_rd??!1,RA:r.RA??r.flag_ra??!1,AD:r.AD??r.flag_ad??!1,CD:r.CD??r.flag_cd??!1,Question:(r.Question??r.questions??[]).map(e=>({name:e.name,type:K[e.type]})),Answer:(r.Answer??r.answers??[]).map(e=>({name:e.name,type:K[e.type],TTL:e.TTL??e.ttl??Br,data:e.data instanceof Uint8Array?De(e.data):e.data}))}}var aa=4;function Pr(r,e={}){let t=new ue({concurrency:e.queryConcurrency??aa});return async(n,o={})=>{let i=new URLSearchParams;i.set("name",n),yt(o.types).forEach(c=>{i.append("type",K[c])}),o.onProgress?.(new b("dns:query",{detail:n}));let s=await t.add(async()=>{let c=await fetch(`${r}?${i}`,{headers:{accept:"application/dns-json"},signal:o?.signal});if(c.status!==200)throw new Error(`Unexpected HTTP status: ${c.status} - ${c.statusText}`);let u=xt(await c.json());return o.onProgress?.(new b("dns:response",{detail:u})),u},{signal:o.signal});if(s==null)throw new Error("No DNS response received");return s}}function Hn(){return[Pr("https://cloudflare-dns.com/dns-query"),Pr("https://dns.google/resolve")]}var Jn=lt(Kn(),1);var Ur=class{lru;constructor(e){this.lru=(0,Jn.default)(e)}get(e,t){let n=!0,o=[];for(let i of t){let s=this.getAnswers(e,i);if(s.length===0){n=!1;break}o.push(...s)}if(n)return xt({answers:o})}getAnswers(e,t){let n=`${e.toLowerCase()}-${t}`,o=this.lru.get(n);if(o!=null){let i=o.filter(s=>s.expires>Date.now()).map(({expires:s,value:c})=>({...c,TTL:Math.round((s-Date.now())/1e3),type:K[c.type]}));return i.length===0&&this.lru.remove(n),i}return[]}add(e,t){let n=`${e.toLowerCase()}-${t.type}`,o=this.lru.get(n)??[];o.push({expires:Date.now()+(t.TTL??Br)*1e3,value:t}),this.lru.set(n,o)}remove(e,t){let n=`${e.toLowerCase()}-${t}`;this.lru.remove(n)}clear(){this.lru.clear()}};function Qn(r){return new Ur(r)}var ca=1e3,bt=class{resolvers;cache;constructor(e){this.resolvers={},this.cache=Qn(e.cacheSize??ca),Object.entries(e.resolvers??{}).forEach(([t,n])=>{Array.isArray(n)||(n=[n]),t.endsWith(".")||(t=`${t}.`),this.resolvers[t]=n}),this.resolvers["."]==null&&(this.resolvers["."]=Hn())}async query(e,t={}){let n=yt(t.types),o=t.cached!==!1?this.cache.get(e,n):void 0;if(o!=null)return t.onProgress?.(new b("dns:cache",{detail:o})),o;let i=`${e.split(".").pop()}.`,s=(this.resolvers[i]??this.resolvers["."]).sort(()=>Math.random()>.5?-1:1),c=[];for(let u of s){if(t.signal?.aborted===!0)break;try{let p=await u(e,{...t,types:n});for(let f of p.Answer)this.cache.add(e,f);return p}catch(p){c.push(p),t.onProgress?.(new b("dns:error",{detail:p}))}}throw c.length===1?c[0]:new AggregateError(c,`DNS lookup of ${e} ${n} failed`)}};var K;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(K||(K={}));function Xn(r={}){return new bt(r)}function ua(r){return r[Symbol.asyncIterator]!=null}function fa(r){if(ua(r))return(async()=>{for await(let e of r);})();for(let e of r);}var Rr=fa;function Be(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Et=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Pe=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Et(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 Et(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 Or=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Ze(r={}){return la(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 la(r,e){e=e??{};let t=e.onEnd,n=new Pe,o,i,s,c=Be(),u=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,k)=>{i=A=>{i=null,n.push(A);try{y(r(n))}catch(C){k(C)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Be()})}},p=y=>i!=null?i(y):(n.push(y),o),f=y=>(n=new Pe,i!=null?i({error:y}):(n.push({error:y}),o)),d=y=>{if(s)return o;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return p({done:!1,value:y})},g=y=>s?o:(s=!0,y!=null?f(y):p({done:!0})),B=()=>(n=new Pe,g(),{done:!0}),E=y=>(g(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:B,throw:E,push:d,end:g,get readableLength(){return n.size},onEmpty:async y=>{let k=y?.signal;if(k?.throwIfAborted(),n.isEmpty())return;let A,C;k!=null&&(A=new Promise((T,U)=>{C=()=>{U(new Or)},k.addEventListener("abort",C)}));try{await Promise.race([c.promise,A])}finally{C!=null&&k!=null&&k?.removeEventListener("abort",C)}}},t==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(y){return w.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:d,end(y){return w.end(y),t!=null&&(t(y),t=void 0),o},get readableLength(){return w.readableLength},onEmpty:y=>w.onEmpty(y)},o}var Fr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function kt(r,e,t,n){let o=new Fr(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{let c=p=>{try{if(n?.filter?.(p)===!1)return}catch(f){r.removeEventListener(e,c),t?.removeEventListener("abort",u),s(f);return}r.removeEventListener(e,c),t?.removeEventListener("abort",u),i(p)},u=()=>{r.removeEventListener(e,c),t?.removeEventListener("abort",u),s(o)};r.addEventListener(e,c),t?.addEventListener("abort",u)})}var vt=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Yn(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new vt(t?.errorMessage,t?.errorCode));let n,o=new vt(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var At=class{deferred;signal;where;constructor(e,t){this.signal=t,this.deferred=Be(),this.where=e,this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(new ie)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function da(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Ct=class{id;fn;options;priority;recipients;status;timeline;controller;constructor(e,t,n=0){this.id=da(),this.status="queued",this.fn=e,this.priority=n,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,ke(1/0,this.controller.signal),this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&this.controller.abort(new ie)}async join(e={}){let t=new At(new Error("where").stack,e.signal);return this.recipients.push(t),e.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Yn(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.signal?.removeEventListener("abort",this.onAbort)})}};function ha(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var et=class extends dt{concurrency;queue;pending;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.pending=0,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.queue=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!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){if(this.queue[this.size-1]?.priority>=e.priority){this.queue.push(e);return}let t=ha(this.queue,e,(n,o)=>o.priority-n.priority);this.queue.splice(t,0,e)}async add(e,t){t?.signal?.throwIfAborted();let n=new Ct(e,t,t?.priority),o=n.join(t).then(i=>(this.safeDispatchEvent("completed",{detail:i}),this.safeDispatchEvent("success",{detail:{job:n,result:i}}),i)).catch(i=>{throw this.safeDispatchEvent("error",{detail:i}),this.safeDispatchEvent("failure",{detail:{job:n,error:i}}),i});return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new ie)}),this.clear()}async onEmpty(e){this.size!==0&&await kt(this,"empty",e?.signal)}async onSizeLessThan(e,t){this.size<e||await kt(this,"next",t?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await kt(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=Ze({objectMode:!0}),n=u=>{u!=null?this.abort():this.clear(),t.end(u)},o=u=>{u.detail!=null&&t.push(u.detail)},i=u=>{n(u.detail)},s=()=>{n()},c=()=>{n(new N("Queue aborted","ERR_QUEUE_ABORTED"))};this.addEventListener("completed",o),this.addEventListener("error",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",c);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("error",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",c),n()}}};var pa=["string","number","bigint","symbol"],ma=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Zn(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(pa.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(ya(r))return"Buffer";let t=ga(r);return t||"Object"}function ya(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function ga(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(ma.includes(e))return e}var a=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};a.uint=new a(0,"uint",!0);a.negint=new a(1,"negint",!0);a.bytes=new a(2,"bytes",!0);a.string=new a(3,"string",!0);a.array=new a(4,"array",!1);a.map=new a(5,"map",!1);a.tag=new a(6,"tag",!1);a.float=new a(7,"float",!0);a.false=new a(7,"false",!0);a.true=new a(7,"true",!0);a.null=new a(7,"null",!0);a.undefined=new a(7,"undefined",!0);a.break=new a(7,"break",!0);var l=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Ue=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",wa=new TextDecoder,xa=new TextEncoder;function Tt(r){return Ue&&globalThis.Buffer.isBuffer(r)}function tt(r){return r instanceof Uint8Array?Tt(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var no=Ue?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):to(r,e,t):(r,e,t)=>t-e>64?wa.decode(r.subarray(e,t)):to(r,e,t),_t=Ue?r=>r.length>64?globalThis.Buffer.from(r):eo(r):r=>r.length>64?xa.encode(r):eo(r),X=r=>Uint8Array.from(r),Re=Ue?(r,e,t)=>Tt(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),oo=Ue?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),tt(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},io=Ue?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function so(r,e){if(Tt(r)&&Tt(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function eo(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128)}return e}function to(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let c,u,p,f;switch(s){case 1:o<128&&(i=o);break;case 2:c=r[e+1],(c&192)===128&&(f=(o&31)<<6|c&63,f>127&&(i=f));break;case 3:c=r[e+1],u=r[e+2],(c&192)===128&&(u&192)===128&&(f=(o&15)<<12|(c&63)<<6|u&63,f>2047&&(f<55296||f>57343)&&(i=f));break;case 4:c=r[e+1],u=r[e+2],p=r[e+3],(c&192)===128&&(u&192)===128&&(p&192)===128&&(f=(o&15)<<18|(c&63)<<12|(u&63)<<6|p&63,f>65535&&f<1114112&&(i=f))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return $r(n)}var ro=4096;function $r(r){let e=r.length;if(e<=ro)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=ro));return t}var ba=256,rt=class{constructor(e=ba){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=io(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=Re(n,0,this.cursor)}else t=oo(this.chunks,this.cursor);return e&&this.reset(),t}};var m="CBOR decode error:",Oe="CBOR encode error:",nt=[];nt[23]=1;nt[24]=2;nt[25]=3;nt[26]=5;nt[27]=9;function te(r,e,t){if(r.length-e<t)throw new Error(`${m} not enough data for type`)}var S=[24,256,65536,4294967296,BigInt("18446744073709551616")];function $(r,e,t){te(r,e,1);let n=r[e];if(t.strict===!0&&n<S[0])throw new Error(`${m} integer encoded in more bytes than necessary (strict decode)`);return n}function M(r,e,t){te(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<S[1])throw new Error(`${m} integer encoded in more bytes than necessary (strict decode)`);return n}function z(r,e,t){te(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<S[2])throw new Error(`${m} integer encoded in more bytes than necessary (strict decode)`);return n}function q(r,e,t){te(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<S[3])throw new Error(`${m} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${m} integers outside of the safe integer range are not supported`)}function ao(r,e,t,n){return new l(a.uint,$(r,e+1,n),2)}function co(r,e,t,n){return new l(a.uint,M(r,e+1,n),3)}function uo(r,e,t,n){return new l(a.uint,z(r,e+1,n),5)}function fo(r,e,t,n){return new l(a.uint,q(r,e+1,n),9)}function H(r,e){return I(r,0,e.value)}function I(r,e,t){if(t<S[0]){let n=Number(t);r.push([e|n])}else if(t<S[1]){let n=Number(t);r.push([e|24,n])}else if(t<S[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<S[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<S[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${m} encountered BigInt larger than allowable range`)}}H.encodedSize=function(e){return I.encodedSize(e.value)};I.encodedSize=function(e){return e<S[0]?1:e<S[1]?2:e<S[2]?3:e<S[3]?5:9};H.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function lo(r,e,t,n){return new l(a.negint,-1-$(r,e+1,n),2)}function ho(r,e,t,n){return new l(a.negint,-1-M(r,e+1,n),3)}function po(r,e,t,n){return new l(a.negint,-1-z(r,e+1,n),5)}var Mr=BigInt(-1),mo=BigInt(1);function yo(r,e,t,n){let o=q(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new l(a.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${m} integers outside of the safe integer range are not supported`);return new l(a.negint,Mr-BigInt(o),9)}function St(r,e){let t=e.value,n=typeof t=="bigint"?t*Mr-mo:t*-1-1;I(r,e.type.majorEncoded,n)}St.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*Mr-mo:t*-1-1;return n<S[0]?1:n<S[1]?2:n<S[2]?3:n<S[3]?5:9};St.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function ot(r,e,t,n){te(r,e,t+n);let o=Re(r,e+t,e+t+n);return new l(a.bytes,o,t+n)}function go(r,e,t,n){return ot(r,e,1,t)}function wo(r,e,t,n){return ot(r,e,2,$(r,e+1,n))}function xo(r,e,t,n){return ot(r,e,3,M(r,e+1,n))}function bo(r,e,t,n){return ot(r,e,5,z(r,e+1,n))}function Eo(r,e,t,n){let o=q(r,e+1,n);if(typeof o=="bigint")throw new Error(`${m} 64-bit integer bytes lengths not supported`);return ot(r,e,9,o)}function It(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===a.string?_t(r.value):r.value),r.encodedBytes}function Fe(r,e){let t=It(e);I(r,e.type.majorEncoded,t.length),r.push(t)}Fe.encodedSize=function(e){let t=It(e);return I.encodedSize(t.length)+t.length};Fe.compareTokens=function(e,t){return ka(It(e),It(t))};function ka(r,e){return r.length<e.length?-1:r.length>e.length?1:so(r,e)}function it(r,e,t,n,o){let i=t+n;te(r,e,i);let s=new l(a.string,no(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Re(r,e+t,e+i)),s}function ko(r,e,t,n){return it(r,e,1,t,n)}function vo(r,e,t,n){return it(r,e,2,$(r,e+1,n),n)}function Ao(r,e,t,n){return it(r,e,3,M(r,e+1,n),n)}function Co(r,e,t,n){return it(r,e,5,z(r,e+1,n),n)}function To(r,e,t,n){let o=q(r,e+1,n);if(typeof o=="bigint")throw new Error(`${m} 64-bit integer string lengths not supported`);return it(r,e,9,o,n)}var _o=Fe;function $e(r,e,t,n){return new l(a.array,n,t)}function So(r,e,t,n){return $e(r,e,1,t)}function Io(r,e,t,n){return $e(r,e,2,$(r,e+1,n))}function Lo(r,e,t,n){return $e(r,e,3,M(r,e+1,n))}function No(r,e,t,n){return $e(r,e,5,z(r,e+1,n))}function Do(r,e,t,n){let o=q(r,e+1,n);if(typeof o=="bigint")throw new Error(`${m} 64-bit integer array lengths not supported`);return $e(r,e,9,o)}function Bo(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${m} indefinite length items not allowed`);return $e(r,e,1,1/0)}function Lt(r,e){I(r,a.array.majorEncoded,e.value)}Lt.compareTokens=H.compareTokens;Lt.encodedSize=function(e){return I.encodedSize(e.value)};function Me(r,e,t,n){return new l(a.map,n,t)}function Po(r,e,t,n){return Me(r,e,1,t)}function Uo(r,e,t,n){return Me(r,e,2,$(r,e+1,n))}function Ro(r,e,t,n){return Me(r,e,3,M(r,e+1,n))}function Oo(r,e,t,n){return Me(r,e,5,z(r,e+1,n))}function Fo(r,e,t,n){let o=q(r,e+1,n);if(typeof o=="bigint")throw new Error(`${m} 64-bit integer map lengths not supported`);return Me(r,e,9,o)}function $o(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${m} indefinite length items not allowed`);return Me(r,e,1,1/0)}function Nt(r,e){I(r,a.map.majorEncoded,e.value)}Nt.compareTokens=H.compareTokens;Nt.encodedSize=function(e){return I.encodedSize(e.value)};function Mo(r,e,t,n){return new l(a.tag,t,1)}function zo(r,e,t,n){return new l(a.tag,$(r,e+1,n),2)}function qo(r,e,t,n){return new l(a.tag,M(r,e+1,n),3)}function Vo(r,e,t,n){return new l(a.tag,z(r,e+1,n),5)}function jo(r,e,t,n){return new l(a.tag,q(r,e+1,n),9)}function Dt(r,e){I(r,a.tag.majorEncoded,e.value)}Dt.compareTokens=H.compareTokens;Dt.encodedSize=function(e){return I.encodedSize(e.value)};var Sa=20,Ia=21,La=22,Na=23;function Wo(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${m} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new l(a.null,null,1):new l(a.undefined,void 0,1)}function Ho(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${m} indefinite length items not allowed`);return new l(a.break,void 0,1)}function zr(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${m} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${m} Infinity values are not supported`)}return new l(a.float,r,e)}function Go(r,e,t,n){return zr(qr(r,e+1),3,n)}function Ko(r,e,t,n){return zr(Vr(r,e+1),5,n)}function Jo(r,e,t,n){return zr(Zo(r,e+1),9,n)}function Bt(r,e,t){let n=e.value;if(n===!1)r.push([a.float.majorEncoded|Sa]);else if(n===!0)r.push([a.float.majorEncoded|Ia]);else if(n===null)r.push([a.float.majorEncoded|La]);else if(n===void 0)r.push([a.float.majorEncoded|Na]);else{let o,i=!1;(!t||t.float64!==!0)&&(Xo(n),o=qr(J,1),n===o||Number.isNaN(n)?(J[0]=249,r.push(J.slice(0,3)),i=!0):(Yo(n),o=Vr(J,1),n===o&&(J[0]=250,r.push(J.slice(0,5)),i=!0))),i||(Da(n),o=Zo(J,1),J[0]=251,r.push(J.slice(0,9)))}}Bt.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){Xo(n);let o=qr(J,1);if(n===o||Number.isNaN(n))return 3;if(Yo(n),o=Vr(J,1),n===o)return 5}return 9};var Qo=new ArrayBuffer(9),G=new DataView(Qo,1),J=new Uint8Array(Qo,0);function Xo(r){if(r===1/0)G.setUint16(0,31744,!1);else if(r===-1/0)G.setUint16(0,64512,!1);else if(Number.isNaN(r))G.setUint16(0,32256,!1);else{G.setFloat32(0,r);let e=G.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)G.setUint16(0,31744,!1);else if(t===0)G.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?G.setUint16(0,0):o<-14?G.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):G.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function qr(r,e){if(r.length-e<2)throw new Error(`${m} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function Yo(r){G.setFloat32(0,r,!1)}function Vr(r,e){if(r.length-e<4)throw new Error(`${m} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function Da(r){G.setFloat64(0,r,!1)}function Zo(r,e){if(r.length-e<8)throw new Error(`${m} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}Bt.compareTokens=H.compareTokens;function x(r,e,t){throw new Error(`${m} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function Pt(r){return()=>{throw new Error(`${m} ${r}`)}}var h=[];for(let r=0;r<=23;r++)h[r]=x;h[24]=ao;h[25]=co;h[26]=uo;h[27]=fo;h[28]=x;h[29]=x;h[30]=x;h[31]=x;for(let r=32;r<=55;r++)h[r]=x;h[56]=lo;h[57]=ho;h[58]=po;h[59]=yo;h[60]=x;h[61]=x;h[62]=x;h[63]=x;for(let r=64;r<=87;r++)h[r]=go;h[88]=wo;h[89]=xo;h[90]=bo;h[91]=Eo;h[92]=x;h[93]=x;h[94]=x;h[95]=Pt("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)h[r]=ko;h[120]=vo;h[121]=Ao;h[122]=Co;h[123]=To;h[124]=x;h[125]=x;h[126]=x;h[127]=Pt("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)h[r]=So;h[152]=Io;h[153]=Lo;h[154]=No;h[155]=Do;h[156]=x;h[157]=x;h[158]=x;h[159]=Bo;for(let r=160;r<=183;r++)h[r]=Po;h[184]=Uo;h[185]=Ro;h[186]=Oo;h[187]=Fo;h[188]=x;h[189]=x;h[190]=x;h[191]=$o;for(let r=192;r<=215;r++)h[r]=Mo;h[216]=zo;h[217]=qo;h[218]=Vo;h[219]=jo;h[220]=x;h[221]=x;h[222]=x;h[223]=x;for(let r=224;r<=243;r++)h[r]=Pt("simple values are not supported");h[244]=x;h[245]=x;h[246]=x;h[247]=Wo;h[248]=Pt("simple values are not supported");h[249]=Go;h[250]=Ko;h[251]=Jo;h[252]=x;h[253]=x;h[254]=x;h[255]=Ho;var Q=[];for(let r=0;r<24;r++)Q[r]=new l(a.uint,r,1);for(let r=-1;r>=-24;r--)Q[31-r]=new l(a.negint,r,1);Q[64]=new l(a.bytes,new Uint8Array(0),1);Q[96]=new l(a.string,"",1);Q[128]=new l(a.array,0,1);Q[160]=new l(a.map,0,1);Q[244]=new l(a.false,!1,1);Q[245]=new l(a.true,!0,1);Q[246]=new l(a.null,null,1);function ei(r){switch(r.type){case a.false:return X([244]);case a.true:return X([245]);case a.null:return X([246]);case a.bytes:return r.value.length?void 0:X([64]);case a.string:return r.value===""?X([96]):void 0;case a.array:return r.value===0?X([128]):void 0;case a.map:return r.value===0?X([160]):void 0;case a.uint:return r.value<24?X([Number(r.value)]):void 0;case a.negint:if(r.value>=-24)return X([31-Number(r.value)])}}var Pa={float64:!1,mapSorter:Oa,quickEncodeToken:ei};function Ua(){let r=[];return r[a.uint.major]=H,r[a.negint.major]=St,r[a.bytes.major]=Fe,r[a.string.major]=_o,r[a.array.major]=Lt,r[a.map.major]=Nt,r[a.tag.major]=Dt,r[a.float.major]=Bt,r}var ti=Ua(),jr=new rt,Rt=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${Oe} object contains circular references`);return new r(t,e)}},fe={null:new l(a.null,null),undefined:new l(a.undefined,void 0),true:new l(a.true,!0),false:new l(a.false,!1),emptyArray:new l(a.array,0),emptyMap:new l(a.map,0)},le={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new l(a.float,r):r>=0?new l(a.uint,r):new l(a.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new l(a.uint,r):new l(a.negint,r)},Uint8Array(r,e,t,n){return new l(a.bytes,r)},string(r,e,t,n){return new l(a.string,r)},boolean(r,e,t,n){return r?fe.true:fe.false},null(r,e,t,n){return fe.null},undefined(r,e,t,n){return fe.undefined},ArrayBuffer(r,e,t,n){return new l(a.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new l(a.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[fe.emptyArray,new l(a.break)]:fe.emptyArray;n=Rt.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=Ut(s,t,n);return t.addBreakTokens?[new l(a.array,r.length),o,new l(a.break)]:[new l(a.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[fe.emptyMap,new l(a.break)]:fe.emptyMap;n=Rt.createCheck(n,r);let c=[],u=0;for(let p of i)c[u++]=[Ut(p,t,n),Ut(o?r.get(p):r[p],t,n)];return Ra(c,t),t.addBreakTokens?[new l(a.map,s),c,new l(a.break)]:[new l(a.map,s),c]}};le.Map=le.Object;le.Buffer=le.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))le[`${r}Array`]=le.DataView;function Ut(r,e={},t){let n=Zn(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||le[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=le[n];if(!i)throw new Error(`${Oe} unsupported type: ${n}`);return i(r,n,e,t)}function Ra(r,e){e.mapSorter&&r.sort(e.mapSorter)}function Oa(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let o=t.type.major,i=ti[o].compareTokens(t,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function ri(r,e,t,n){if(Array.isArray(e))for(let o of e)ri(r,o,t,n);else t[e.type.major](r,e,n)}function ni(r,e,t){let n=Ut(r,t);if(!Array.isArray(n)&&t.quickEncodeToken){let o=t.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,t),c=new rt(s);if(i(c,n,t),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return tt(c.chunks[0])}}return jr.reset(),ri(jr,n,e,t),jr.toBytes(!0)}function st(r,e){return e=Object.assign({},Pa,e),ni(r,ti,e)}var Fa={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Ot=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=Q[e];if(t===void 0){let n=h[e];if(!n)throw new Error(`${m} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},at=Symbol.for("DONE"),Ft=Symbol.for("BREAK");function $a(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=ze(e,t);if(i===Ft){if(r.value===1/0)break;throw new Error(`${m} got unexpected break to lengthed array`)}if(i===at)throw new Error(`${m} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function Ma(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let c=ze(e,t);if(c===Ft){if(r.value===1/0)break;throw new Error(`${m} got unexpected break to lengthed map`)}if(c===at)throw new Error(`${m} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${m} non-string keys not supported (got ${typeof c})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${m} found repeat map key "${c}"`);let u=ze(e,t);if(u===at)throw new Error(`${m} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(c,u):o[c]=u}return n?i:o}function ze(r,e){if(r.done())return at;let t=r.next();if(t.type===a.break)return Ft;if(t.type.terminal)return t.value;if(t.type===a.array)return $a(t,r,e);if(t.type===a.map)return Ma(t,r,e);if(t.type===a.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=ze(r,e);return e.tags[t.value](n)}throw new Error(`${m} tag not supported (${t.value})`)}throw new Error("unsupported")}function Wr(r,e){if(!(r instanceof Uint8Array))throw new Error(`${m} data to decode must be a Uint8Array`);e=Object.assign({},Fa,e);let t=e.tokenizer||new Ot(r,e),n=ze(t,e);if(n===at)throw new Error(`${m} did not find any content to decode`);if(n===Ft)throw new Error(`${m} got unexpected break`);return[n,r.subarray(t.pos())]}function Y(r,e){let[t,n]=Wr(r,e);if(n.length>0)throw new Error(`${m} too many terminals, data makes no sense`);return t}function $t(r,e="utf8"){let t=wt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var re="/",oi=new TextEncoder().encode(re),Mt=oi[0],ne=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=$t(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Mt)throw new Error("Invalid key")}toString(e="utf8"){return De(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(re))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=oi),this._buf[0]!==Mt){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Mt,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Mt;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let o=0;o<t.length;o++){if(n.length<o+1)return!1;let i=t[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(re).slice(1)}type(){return za(this.baseNamespace())}name(){return qa(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(re)||(e+=re),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(re):new r(e.slice(0,-1).join(re))}child(e){return this.toString()===re?e:e.toString()===re?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...Va(e.map(t=>t.namespaces()))])}};function za(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function qa(r){let e=r.split(":");return e[e.length-1]}function Va(r){return[].concat(...r)}function ct(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 ci="/pin/",ii="/pinned-block/",Gr=Je,si=1;function ai(r){return r.version===0&&(r=r.toV1()),new ne(`${ci}${r.toString(Gr)}`)}var zt=class{datastore;blockstore;dagWalkers;constructor(e,t,n){this.datastore=e,this.blockstore=t,this.dagWalkers=n}async*add(e,t={}){let n=ai(e);if(await this.datastore.has(n))throw new Error("Already pinned");let o=Math.round(t.depth??1/0);if(o<0)throw new Error("Depth must be greater than or equal to 0");let i=new et({concurrency:si});for await(let c of this.#e(e,i,{...t,depth:o}))await this.#o(c,u=>u.pinnedBy.find(p=>ct(p,e.bytes))!=null?!1:(u.pinCount++,u.pinnedBy.push(e.bytes),!0),t),yield c;let s={depth:o,metadata:t.metadata??{}};await this.datastore.put(n,st(s),t)}async*#e(e,t,n){if(n.depth===-1)return;let o=this.dagWalkers[e.code];if(o==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let i=await this.blockstore.get(e,n);yield e;for await(let s of o.walk(i))yield*await t.add(async()=>this.#e(s,t,{...n,depth:n.depth-1}))}async#o(e,t,n){let o=new ne(`${ii}${Gr.encode(e.multihash.bytes)}`),i={pinCount:0,pinnedBy:[]};try{i=Y(await this.datastore.get(o,n))}catch(c){if(c.code!=="ERR_NOT_FOUND")throw c}if(t(i)){if(i.pinCount===0&&await this.datastore.has(o)){await this.datastore.delete(o);return}await this.datastore.put(o,st(i),n),n.onProgress?.(new b("helia:pin:add",e))}}async*rm(e,t={}){let n=ai(e),o=await this.datastore.get(n,t),i=Y(o);await this.datastore.delete(n,t);let s=new et({concurrency:si});for await(let c of this.#e(e,s,{...t,depth:i.depth}))await this.#o(c,u=>(u.pinCount--,u.pinnedBy=u.pinnedBy.filter(p=>ct(p,e.bytes)),!0),{...t,depth:i.depth}),yield c}async*ls(e={}){for await(let{key:t,value:n}of this.datastore.query({prefix:ci+(e.cid!=null?`${e.cid.toString(Je)}`:"")},e)){let o=_.parse(t.toString().substring(5),Je),i=Y(n);yield{cid:o,...i}}}async isPinned(e,t={}){let n=new ne(`${ii}${Gr.encode(e.multihash.bytes)}`);return this.datastore.has(n,t)}};function ja(r){return r[Symbol.asyncIterator]!=null}function Wa(...r){let e=[];for(let t of r)ja(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Ze({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)t.push(o)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var ut=Wa;var qt=class{log;routers;constructor(e,t){this.log=e.logger.forComponent("helia:routing"),this.routers=t.routers??[]}async start(){await se(...this.routers)}async stop(){await ae(...this.routers)}async*findProviders(e,t={}){if(this.routers.length===0)throw new N("No content routers available","ERR_NO_ROUTERS_AVAILABLE");for await(let n of ut(...qe(this.routers,"findProviders").map(o=>o.findProviders(e,t))))n!=null&&(yield n)}async provide(e,t={}){if(this.routers.length===0)throw new N("No content routers available","ERR_NO_ROUTERS_AVAILABLE");await Promise.all(qe(this.routers,"provide").map(async n=>{await n.provide(e,t)}))}async put(e,t,n){await Promise.all(qe(this.routers,"put").map(async o=>{await o.put(e,t,n)}))}async get(e,t){return Promise.any(qe(this.routers,"get").map(async n=>n.get(e,t)))}async findPeer(e,t){if(this.routers.length===0)throw new N("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");let n=this,o=ut(...qe(this.routers,"findPeer").map(i=>async function*(){try{yield await i.findPeer(e,t)}catch(s){n.log.error(s)}}()));for await(let i of o)if(i!=null)return i;throw new N("Could not find peer in routing","ERR_NOT_FOUND")}async*getClosestPeers(e,t={}){if(this.routers.length===0)throw new N("No peer routers available","ERR_NO_ROUTERS_AVAILABLE");for await(let n of ut(...qe(this.routers,"getClosestPeers").map(o=>o.getClosestPeers(e,t))))n!=null&&(yield n)}};function qe(r,e){return r.filter(t=>t[e]!=null)}var de={},Ve=r=>{r.addEventListener("message",e=>{Ve.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{Ve.dispatchEvent("message",r,e)})};Ve.addEventListener=(r,e)=>{de[r]==null&&(de[r]=[]),de[r].push(e)};Ve.removeEventListener=(r,e)=>{de[r]!=null&&(de[r]=de[r].filter(t=>t===e))};Ve.dispatchEvent=function(r,e,t){de[r]!=null&&de[r].forEach(n=>n(e,t))};var Kr=Ve;var Jr="lock:worker:request-read",Qr="lock:worker:release-read",Xr="lock:master:grant-read",Yr="lock:worker:request-write",Zr="lock:worker:release-write",en="lock:master:grant-write";var ui=(r=21)=>Math.random().toString().substring(2);var fi=(r,e,t,n,o)=>(i,s)=>{if(s.data.type!==t)return;let c={type:s.data.type,name:s.data.name,identifier:s.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:c.name,handler:async()=>{i.postMessage({type:o,name:c.name,identifier:c.identifier}),await new Promise(u=>{let p=f=>{if(f==null||f.data==null)return;let d={type:f.data.type,name:f.data.name,identifier:f.data.identifier};d.type===n&&d.identifier===c.identifier&&(i.removeEventListener("message",p),u())};i.addEventListener("message",p)})}}}))},li=(r,e,t,n)=>async()=>{let o=ui();return globalThis.postMessage({type:e,identifier:o,name:r}),new Promise(i=>{let s=c=>{if(c==null||c.data==null)return;let u={type:c.data.type,identifier:c.data.identifier};u.type===t&&u.identifier===o&&(globalThis.removeEventListener("message",s),i(()=>{globalThis.postMessage({type:n,identifier:o,name:r})}))};globalThis.addEventListener("message",s)})},Ha={singleProcess:!1},di=r=>{if(r=Object.assign({},Ha,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return Kr.addEventListener("message",fi(t,"requestReadLock",Jr,Qr,Xr)),Kr.addEventListener("message",fi(t,"requestWriteLock",Yr,Zr,en)),t}return{isWorker:!0,readLock:t=>li(t,Jr,Xr,Qr),writeLock:t=>li(t,Yr,en,Zr)}};var we={},he;async function tn(r,e){let t,n=new Promise(o=>{t=o});return r.add(async()=>Ge((async()=>{await new Promise(o=>{t(()=>{o()})})})(),{milliseconds:e.timeout})),n}var Ga=(r,e)=>{if(he.isWorker===!0)return{readLock:he.readLock(r,e),writeLock:he.writeLock(r,e)};let t=new ue({concurrency:1}),n;return{async readLock(){if(n!=null)return tn(n,e);n=new ue({concurrency:e.concurrency,autoStart:!1});let o=n,i=tn(n,e);return t.add(async()=>{o.start(),await o.onIdle().then(()=>{n===o&&(n=null)})}),i},async writeLock(){return n=null,tn(t,e)}}},Ka={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function rn(r){let e=Object.assign({},Ka,r);return he==null&&(he=di(e),he.isWorker!==!0&&(he.addEventListener("requestReadLock",t=>{we[t.data.name]!=null&&we[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),he.addEventListener("requestWriteLock",async t=>{we[t.data.name]!=null&&we[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),we[e.name]==null&&(we[e.name]=Ga(e.name,e)),we[e.name]}var Vt=class{lock;child;pins;started;constructor(e,t,n={}){this.child=e,this.pins=t,this.lock=rn({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await se(this.child),this.started=!0}async stop(){await ae(this.child),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){let o=await this.lock.readLock();try{return await this.child.put(e,t,n)}finally{o()}}async*putMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.putMany(e,t)}finally{n()}}async get(e,t={}){let n=await this.lock.readLock();try{return await this.child.get(e,t)}finally{n()}}async*getMany(e,t={}){let n=await this.lock.readLock();try{yield*this.child.getMany(e,t)}finally{n()}}async delete(e,t={}){let n=await this.lock.writeLock();try{if(await this.pins.isPinned(e))throw new Error("CID was pinned");await this.child.delete(e,t)}finally{n()}}async*deleteMany(e,t={}){let n=await this.lock.writeLock();try{let o=this;yield*this.child.deleteMany(async function*(){for await(let i of e){if(await o.pins.isPinned(i))throw new Error("CID was pinned");yield i}}(),t)}finally{n()}}async has(e,t={}){let n=await this.lock.readLock();try{return await this.child.has(e,t)}finally{n()}}async*getAll(e={}){let t=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{t()}}async createSession(e,t){let n=await this.lock.readLock();try{let o=await this.child.createSession(e,t);if(o==null)throw new N("Sessions not supported","ERR_UNSUPPORTED");return o}finally{n()}}};var pi=42;function Ja(r){if(r.asCID!==r&&r["/"]!==r.bytes)return null;let e=_.asCID(r);if(!e)return null;let t=new Uint8Array(e.bytes.byteLength+1);return t.set(e.bytes,1),[new l(a.tag,pi),new l(a.bytes,t)]}function Qa(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Xa(r){if(Number.isNaN(r))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(r===1/0||r===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var hi={float64:!0,typeEncoders:{Object:Ja,undefined:Qa,number:Xa}},ld={...hi,typeEncoders:{...hi.typeEncoders}};function Ya(r){if(r[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return _.decode(r.subarray(1))}var nn={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};nn.tags[pi]=Ya;var dd={...nn,tags:nn.tags.slice()};var mi=113;var yi=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===a.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===a.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[a.uint.major](e,t){this.prefix(e);let n=String(t.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[a.negint.major](e,t){this[a.uint.major](e,t)}[a.bytes.major](e,t){throw new Error(`${Oe} unsupported type: Uint8Array`)}[a.string.major](e,t){this.prefix(e);let n=_t(JSON.stringify(t.value));e.push(n.length>32?tt(n):n)}[a.array.major](e,t){this.prefix(e),this.inRecursive.push({type:a.array,elements:0}),e.push([91])}[a.map.major](e,t){this.prefix(e),this.inRecursive.push({type:a.map,elements:0}),e.push([123])}[a.tag.major](e,t){}[a.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===a.array)e.push([93]);else if(s.type===a.map)e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(t.value===void 0)throw new Error(`${Oe} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.value),o=[],i=!1;for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s),!i&&(o[s]===46||o[s]===101||o[s]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};var xe=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${m} unexpected end of input at position ${this._pos}`);for(let t=0;t<e.length;t++)if(this.data[this._pos++]!==e[t])throw new Error(`${m} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,o=c=>{for(;!this.done();){let u=this.ch();if(c.includes(u))this._pos++;else break}};if(this.ch()===45&&(t=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new l(a.uint,0,this._pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${m} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${m} unexpected token at position ${this._pos}`);n=!0,this._pos++,o([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,o([48,49,50,51,52,53,54,55,56,57]));let i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);return n?new l(a.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new l(s>=0?a.uint:a.negint,s,this._pos-e):new l(s>=0?a.uint:a.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${m} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let c=this.data[i];if(c===92||c<32||c>=128)break;if(c===34){let u=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new l(a.string,u,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${m} unexpected end of unicode escape sequence at position ${this._pos}`);let i=0;for(let s=0;s<4;s++){let c=this.ch();if(c>=48&&c<=57)c-=48;else if(c>=97&&c<=102)c=c-97+10;else if(c>=65&&c<=70)c=c-65+10;else throw new Error(`${m} unexpected unicode escape character at position ${this._pos}`);i=i*16+c,this._pos++}return i},o=()=>{let i=this.ch(),s=null,c=i>239?4:i>223?3:i>191?2:1;if(this._pos+c>this.data.length)throw new Error(`${m} unexpected unicode sequence at position ${this._pos}`);let u,p,f,d;switch(c){case 1:i<128&&(s=i);break;case 2:u=this.data[this._pos+1],(u&192)===128&&(d=(i&31)<<6|u&63,d>127&&(s=d));break;case 3:u=this.data[this._pos+1],p=this.data[this._pos+2],(u&192)===128&&(p&192)===128&&(d=(i&15)<<12|(u&63)<<6|p&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:u=this.data[this._pos+1],p=this.data[this._pos+2],f=this.data[this._pos+3],(u&192)===128&&(p&192)===128&&(f&192)===128&&(d=(i&15)<<18|(u&63)<<12|(p&63)<<6|f&63,d>65535&&d<1114112&&(s=d))}s===null?(s=65533,c=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=c};for(;!this.done();){let i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${m} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:t.push(s);break;case 98:t.push(8);break;case 116:t.push(9);break;case 110:t.push(10);break;case 102:t.push(12);break;case 114:t.push(13);break;case 117:t.push(n());break;default:throw new Error(`${m} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new l(a.string,$r(t),this._pos-e);default:if(i<32)throw new Error(`${m} invalid control character at position ${this._pos}`);i<128?(t.push(i),this._pos++):o()}}throw new Error(`${m} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new l(a.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new l(a.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new l(a.null,null,4);case 102:return this.expect([102,97,108,115,101]),new l(a.false,!1,5);case 116:return this.expect([116,114,117,101]),new l(a.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${m} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new l(a.break,void 0,1);if(this.ch()!==44)throw new Error(`${m} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new l(a.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new l(a.break,void 0,1);if(this.ch()!==44)throw new Error(`${m} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new l(a.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${m} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${m} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function jt(r,e){return e=Object.assign({tokenizer:new xe(r,e)},e),Y(r,e)}var tc={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};tc.tags[42]=_.parse;var wi=297;var Id=new TextDecoder;var Ld=new TextEncoder;var nc=new TextDecoder;function on(r,e){let t=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=r.length)throw new Error("protobuf: unexpected end of data");let o=r[e++];if(t+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[t,e]}function Wt(r,e){let t;[t,e]=on(r,e);let n=e+t;if(t<0||n<0)throw new Error("protobuf: invalid length");if(n>r.length)throw new Error("protobuf: unexpected end of data");return[r.subarray(e,n),n]}function xi(r,e){let t;return[t,e]=on(r,e),[t&7,t>>3,e]}function oc(r){let e={},t=r.length,n=0;for(;n<t;){let o,i;if([o,i,n]=xi(r,n),i===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=Wt(r,n)}else if(i===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=Wt(r,n),e.Name=nc.decode(s)}else if(i===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(o!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Tsize`);[e.Tsize,n]=on(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>t)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function bi(r){let e=r.length,t=0,n,o=!1,i;for(;t<e;){let c,u;if([c,u,t]=xi(r,t),c!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${c}`);if(u===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,t]=Wt(r,t),n&&(o=!0)}else if(u===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let p;[p,t]=Wt(r,t),n.push(oc(p))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${u}`)}if(t>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var Dd=new TextEncoder,Bd=2**32,Pd=2**31;var Od=new TextEncoder;function Ei(r){return r instanceof ArrayBuffer?new Uint8Array(r,0,r.byteLength):r}var ki=112;function vi(r){let e=Ei(r),t=bi(e),n={};return t.Data&&(n.Data=t.Data),t.Links&&(n.Links=t.Links.map(o=>{let i={};try{i.Hash=_.decode(o.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return o.Name!==void 0&&(i.Name=o.Name),o.Tsize!==void 0&&(i.Tsize=o.Tsize),i})),n}var sc={codec:ki,*walk(r){yield*vi(r).Links.map(t=>t.Hash)}},ac={codec:xr,*walk(){}},Ai=42,cc={codec:mi,*walk(r){let e=[],t=[];t[Ai]=n=>{if(n[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");let o=_.decode(n.subarray(1));return e.push(o),o},Y(r,{tags:t}),yield*e}},sn=class extends xe{tokenBuffer;constructor(e,t){super(e,t),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(e.type===a.map){let t=this._next();if(t.type===a.string&&t.value==="/"){let n=this._next();if(n.type===a.string){if(this._next().type!==a.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new l(a.tag,42,0)}if(n.type===a.map){let o=this._next();if(o.type===a.string&&o.value==="bytes"){let i=this._next();if(i.type===a.string){for(let c=0;c<2;c++)if(this._next().type!==a.break)throw new Error("Invalid encoded Bytes form");let s=_e.decode(`m${i.value}`);return new l(a.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},uc={codec:wi,*walk(r){let e=[],t=[];t[Ai]=n=>{let o=_.parse(n);return e.push(o),o},jt(r,{tags:t,tokenizer:new sn(r,{tags:t,allowIndefinite:!0,allowUndefined:!0,allowNaN:!0,allowInfinity:!0,allowBigInt:!0,strict:!1,rejectDuplicateMapKeys:!1})}),yield*e}},fc={codec:Ln,*walk(){}};function Ci(r=[]){let e={};return[sc,ac,cc,uc,fc,...r].forEach(t=>{e[t.codec]=t}),e}var an=new ne("/version"),Ti=1;async function _i(r){if(!await r.has(an)){await r.put(an,$t(`${Ti}`));return}let e=await r.get(an),t=De(e);if(parseInt(t,10)!==Ti)throw new Error("Unknown datastore version, a datastore migration may be required")}function Si(r=[]){let e={};return[_r,Sr,vr,...r].forEach(t=>{e[t.code]=t}),e}function Ii(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var pe=class{has(e,t){return Promise.reject(new Error(".has is not implemented"))}put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,t){for await(let{cid:n,block:o}of e)await this.put(n,o,t),yield n}get(e,t){return Promise.reject(new Error(".get is not implemented"))}async*getMany(e,t){for await(let n of e)yield{cid:n,block:await this.get(n,t)}}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,t){for await(let n of e)await this.delete(n,t),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var je={};P(je,{abortedError:()=>yc,closeFailedError:()=>hc,deleteFailedError:()=>Pi,getFailedError:()=>pc,hasFailedError:()=>mc,notFoundError:()=>Ht,openFailedError:()=>dc,putFailedError:()=>Bi});var oe=lt(Di(),1);function dc(r){return r=r??new Error("Open failed"),(0,oe.default)(r,"ERR_OPEN_FAILED")}function hc(r){return r=r??new Error("Close failed"),(0,oe.default)(r,"ERR_CLOSE_FAILED")}function Bi(r){return r=r??new Error("Put failed"),(0,oe.default)(r,"ERR_PUT_FAILED")}function pc(r){return r=r??new Error("Get failed"),(0,oe.default)(r,"ERR_GET_FAILED")}function Pi(r){return r=r??new Error("Delete failed"),(0,oe.default)(r,"ERR_DELETE_FAILED")}function mc(r){return r=r??new Error("Has failed"),(0,oe.default)(r,"ERR_HAS_FAILED")}function Ht(r){return r=r??new Error("Not Found"),(0,oe.default)(r,"ERR_NOT_FOUND")}function yc(r){return r=r??new Error("Aborted"),(0,oe.default)(r,"ERR_ABORTED")}function gc(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var Gt=gc;function wc(r){return r[Symbol.asyncIterator]!=null}function xc(r,e){if(wc(r))return async function*(){for await(let c of r)await e(c)&&(yield c)}();let t=Gt(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();let i=e(n);if(typeof i.then=="function")return async function*(){await i&&(yield n);for await(let c of t)await e(c)&&(yield c)}();let s=e;return function*(){i===!0&&(yield n);for(let c of t)s(c)&&(yield c)}()}var cn=xc;var vh=ar("blockstore:core:tiered");var Ui={...je};var Kt=0,Jt=class extends pe{child;constructor(e){super(),this.child=e}put(e,t){return e.multihash.code===Kt||this.child==null?e:this.child.put(e,t)}get(e){if(e.multihash.code===Kt)return e.multihash.digest;if(this.child==null)throw Ui.notFoundError();return this.child.get(e)}has(e){return e.multihash.code===Kt?!0:this.child==null?!1:this.child.has(e)}delete(e){if(e.code!==Kt&&this.child!=null)return this.child.delete(e)}getAll(e){return this.child!=null?this.child.getAll(e):[]}};function bc(r){return r[Symbol.asyncIterator]!=null}function Ri(r){return r?.then!=null}function Ec(r,e){if(bc(r))return async function*(){for await(let c of r){let u=e(c);Ri(u)&&await u,yield c}}();let t=Gt(r),{value:n,done:o}=t.next();if(o===!0)return function*(){}();if(typeof e(n)?.then=="function")return async function*(){yield n;for await(let c of t){let u=e(c);Ri(u)&&await u,yield c}}();let s=e;return function*(){yield n;for(let c of t)s(c),yield c}()}var un=Ec;var Qt=class r{child;hashers;started;log;logger;components;constructor(e,t={}){this.log=e.logger.forComponent(`helia:networked-storage${t.root==null?"":`:${t.root}`}`),this.logger=e.logger,this.components=e,this.child=new Jt(e.blockstore),this.hashers=e.hashers??{},this.started=!1}isStarted(){return this.started}async start(){await se(this.child,...this.components.blockBrokers),this.started=!0}async stop(){await ae(this.child,...this.components.blockBrokers),this.started=!1}unwrap(){return this.child}async put(e,t,n={}){return await this.child.has(e)?(n.onProgress?.(new b("blocks:put:duplicate",e)),e):(n.onProgress?.(new b("blocks:put:providers:notify",e)),await Promise.all(this.components.blockBrokers.map(async o=>o.announce?.(e,t,n))),n.onProgress?.(new b("blocks:put:blockstore:put",e)),this.child.put(e,t,n))}async*putMany(e,t={}){let n=cn(e,async({cid:i})=>{let s=await this.child.has(i);return s&&t.onProgress?.(new b("blocks:put-many:duplicate",i)),!s}),o=un(n,async({cid:i,block:s})=>{t.onProgress?.(new b("blocks:put-many:providers:notify",i)),await Promise.all(this.components.blockBrokers.map(async c=>c.announce?.(i,s,t)))});t.onProgress?.(new b("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(o,t)}async get(e,t={}){if(t.offline!==!0&&!await this.child.has(e)){t.onProgress?.(new b("blocks:get:providers:get",e));let n=await Oi(e,this.components.blockBrokers,this.hashers[e.multihash.code],{...t,log:this.log});return t.onProgress?.(new b("blocks:get:blockstore:put",e)),await this.child.put(e,n,t),t.onProgress?.(new b("blocks:get:providers:notify",e)),await Promise.all(this.components.blockBrokers.map(async o=>o.announce?.(e,n,t))),n}return t.onProgress?.(new b("blocks:get:blockstore:get",e)),this.child.get(e,t)}async*getMany(e,t={}){t.onProgress?.(new b("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(un(e,async n=>{if(t.offline!==!0&&!await this.child.has(n)){t.onProgress?.(new b("blocks:get-many:providers:get",n));let o=await Oi(n,this.components.blockBrokers,this.hashers[n.multihash.code],{...t,log:this.log});t.onProgress?.(new b("blocks:get-many:blockstore:put",n)),await this.child.put(n,o,t),t.onProgress?.(new b("blocks:get-many:providers:notify",n)),await Promise.all(this.components.blockBrokers.map(async i=>i.announce?.(n,o,t)))}}))}async delete(e,t={}){t.onProgress?.(new b("blocks:delete:blockstore:delete",e)),await this.child.delete(e,t)}async*deleteMany(e,t={}){t.onProgress?.(new b("blocks:delete-many:blockstore:delete-many")),yield*this.child.deleteMany(async function*(){for await(let n of e)yield n}(),t)}async has(e,t={}){return this.child.has(e,t)}async*getAll(e={}){e.onProgress?.(new b("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}async createSession(e,t){let n=await Promise.all(this.components.blockBrokers.map(async o=>o.createSession==null?o:o.createSession(e,t)));return new r({blockstore:this.child,blockBrokers:n,hashers:this.hashers,logger:this.logger},{root:e})}};function kc(r){return typeof r.retrieve=="function"}var vc=(r,e)=>{if(e==null)throw new N(`No hasher configured for multihash code 0x${r.multihash.code.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`,"ERR_UNKNOWN_HASH_ALG");return async t=>{let n=await e.digest(t);if(!ct(n.digest,r.multihash.digest))throw new N("Hash of downloaded block did not match multihash from passed CID","ERR_HASH_MISMATCH")}};async function Oi(r,e,t,n){let o=vc(r,t),i=new AbortController,s=Ii([i.signal,n.signal]);ke(1/0,i.signal,s);let c=[];for(let u of e)kc(u)&&c.push(u);try{return await Promise.any(c.map(async u=>{try{let p=!1,f=await u.retrieve(r,{...n,signal:s,validateFn:async d=>{await o(d),p=!0}});return p||await o(f),f}catch(p){throw n.log.error("could not retrieve verified block for %c",r,p),p}}))}finally{i.abort(),s.clear()}}var fn=class{blockstore;datastore;pins;logger;routing;dagWalkers;hashers;dns;log;constructor(e){this.logger=e.logger??An(),this.log=this.logger.forComponent("helia"),this.hashers=Si(e.hashers),this.dagWalkers=Ci(e.dagWalkers),this.dns=e.dns??Xn();let t={blockstore:e.blockstore,datastore:e.datastore,hashers:this.hashers,dagWalkers:this.dagWalkers,logger:this.logger,blockBrokers:[],dns:this.dns,...e.components??{}};this.routing=t.routing=new qt(t,{routers:(e.routers??[]).flatMap(o=>{let i=[o];return o[Xt]!=null&&i.push(o[Xt]),o[Yt]!=null&&i.push(o[Yt]),i})});let n=new Qt(t);this.pins=new zt(e.datastore,n,this.dagWalkers),this.blockstore=new Vt(n,this.pins,{holdGcLock:e.holdGcLock??!0}),this.datastore=e.datastore,t.blockBrokers=e.blockBrokers.map(o=>o(t))}async start(){await _i(this.datastore),await se(this.blockstore,this.datastore,this.routing)}async stop(){await ae(this.blockstore,this.datastore,this.routing)}async gc(e={}){let t=await this.blockstore.lock.writeLock();try{let n=this,o=this.blockstore.unwrap();this.log("gc start"),await Rr(o.deleteMany(async function*(){for await(let{cid:i}of o.getAll())try{if(await n.pins.isPinned(i,e))continue;yield i,e.onProgress?.(new b("helia:gc:deleted",i))}catch(s){n.log.error("Error during gc",s),e.onProgress?.(new b("helia:gc:error",s))}}()))}finally{t()}this.log("gc finished")}};return Vi(Ac);})();
|
|
3
3
|
return HeliaUtils}));
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AASH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAK3C,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,IAAI,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC9F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,mBAAmB,CAAA;AAChE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAEpE;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,UAAU,EAAE,UAAU,CAAA;IAEtB;;OAEG;IACH,SAAS,EAAE,SAAS,CAAA;IAEpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,eAAe,EAAE,CAAA;IAE3B;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,EAAE,CAAA;IAExB;;;OAGG;IACH,YAAY,EAAE,KAAK,CAAC,CAAC,UAAU,EAAE,GAAG,KAAK,WAAW,CAAC,CAAA;IAErD;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB;;;OAGG;IACH,MAAM,CAAC,EAAE,eAAe,CAAA;IAExB;;;OAGG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;IAEjC;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAEhC;;OAEG;IACH,GAAG,CAAC,EAAE,GAAG,CAAA;CACV;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AASH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAK3C,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,IAAI,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC9F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,mBAAmB,CAAA;AAChE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAEpE;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,UAAU,EAAE,UAAU,CAAA;IAEtB;;OAEG;IACH,SAAS,EAAE,SAAS,CAAA;IAEpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,eAAe,EAAE,CAAA;IAE3B;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,EAAE,CAAA;IAExB;;;OAGG;IACH,YAAY,EAAE,KAAK,CAAC,CAAC,UAAU,EAAE,GAAG,KAAK,WAAW,CAAC,CAAA;IAErD;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB;;;OAGG;IACH,MAAM,CAAC,EAAE,eAAe,CAAA;IAExB;;;OAGG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;IAEjC;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAEhC;;OAEG;IACH,GAAG,CAAC,EAAE,GAAG,CAAA;CACV;AAaD,qBAAa,KAAM,YAAW,cAAc;IACnC,UAAU,EAAE,YAAY,CAAA;IACxB,SAAS,EAAE,SAAS,CAAA;IACpB,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IACrC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IACxC,GAAG,EAAE,GAAG,CAAA;IACf,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;gBAEf,IAAI,EAAE,SAAS;IAoDtB,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IASvB,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAQtB,EAAE,CAAE,OAAO,GAAE,SAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CA+BlD"}
|
package/dist/src/index.js
CHANGED
|
@@ -44,6 +44,7 @@ export class Helia {
|
|
|
44
44
|
this.hashers = defaultHashers(init.hashers);
|
|
45
45
|
this.dagWalkers = defaultDagWalkers(init.dagWalkers);
|
|
46
46
|
this.dns = init.dns ?? dns();
|
|
47
|
+
// @ts-expect-error routing is not set
|
|
47
48
|
const components = {
|
|
48
49
|
blockstore: init.blockstore,
|
|
49
50
|
datastore: init.datastore,
|
|
@@ -54,16 +55,7 @@ export class Helia {
|
|
|
54
55
|
dns: this.dns,
|
|
55
56
|
...(init.components ?? {})
|
|
56
57
|
};
|
|
57
|
-
components.
|
|
58
|
-
return fn(components);
|
|
59
|
-
});
|
|
60
|
-
const networkedStorage = new NetworkedStorage(components);
|
|
61
|
-
this.pins = new PinsImpl(init.datastore, networkedStorage, this.dagWalkers);
|
|
62
|
-
this.blockstore = new BlockStorage(networkedStorage, this.pins, {
|
|
63
|
-
holdGcLock: init.holdGcLock ?? true
|
|
64
|
-
});
|
|
65
|
-
this.datastore = init.datastore;
|
|
66
|
-
this.routing = new RoutingClass(components, {
|
|
58
|
+
this.routing = components.routing = new RoutingClass(components, {
|
|
67
59
|
routers: (init.routers ?? []).flatMap((router) => {
|
|
68
60
|
// if the router itself is a router
|
|
69
61
|
const routers = [
|
|
@@ -80,6 +72,15 @@ export class Helia {
|
|
|
80
72
|
return routers;
|
|
81
73
|
})
|
|
82
74
|
});
|
|
75
|
+
const networkedStorage = new NetworkedStorage(components);
|
|
76
|
+
this.pins = new PinsImpl(init.datastore, networkedStorage, this.dagWalkers);
|
|
77
|
+
this.blockstore = new BlockStorage(networkedStorage, this.pins, {
|
|
78
|
+
holdGcLock: init.holdGcLock ?? true
|
|
79
|
+
});
|
|
80
|
+
this.datastore = init.datastore;
|
|
81
|
+
components.blockBrokers = init.blockBrokers.map((fn) => {
|
|
82
|
+
return fn(components);
|
|
83
|
+
});
|
|
83
84
|
}
|
|
84
85
|
async start() {
|
|
85
86
|
await assertDatastoreVersionIsCurrent(this.datastore);
|