blockstore-core
Version:
Contains various implementations of the API contract described in interface-blockstore
5 lines (4 loc) • 24.8 kB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.BlockstoreCore = factory()}(typeof self !== 'undefined' ? self : this, function () {
;var BlockstoreCore=(()=>{var W=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var Me=Object.prototype.hasOwnProperty;var ze=(r,t)=>{for(var e in t)W(r,e,{get:t[e],enumerable:!0})},Le=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Re(t))!Me.call(r,o)&&o!==e&&W(r,o,{get:()=>t[o],enumerable:!(n=ke(t,o))||n.enumerable});return r};var Oe=r=>Le(W({},"__esModule",{value:!0}),r);var Ot={};ze(Ot,{BaseBlockstore:()=>N,BlackHoleBlockstore:()=>G,MemoryBlockstore:()=>J,TieredBlockstore:()=>Z});var N=class{has(t,e){return Promise.reject(new Error(".has is not implemented"))}put(t,e,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(t,e){for await(let{cid:n,block:o}of t)await this.put(n,o,e),yield n}get(t,e){return Promise.reject(new Error(".get is not implemented"))}async*getMany(t,e){for await(let n of t)yield{cid:n,block:await this.get(n,e)}}delete(t,e){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(t,e){for await(let n of t)await this.delete(n,e),yield n}async*getAll(t){throw new Error(".getAll is not implemented")}};var D=class r extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=r.name;code=r.code;constructor(t="Not Found"){super(t)}};var Vt=new Uint8Array(0);function ie(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function k(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 Ue(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),a=s.charCodeAt(0);if(e[a]!==255)throw new TypeError(s+" is ambiguous");e[a]=o}var u=r.length,h=r.charAt(0),I=Math.log(u)/Math.log(256),i=Math.log(256)/Math.log(u);function c(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var l=0,p=0,m=0,w=d.length;m!==w&&d[m]===0;)m++,l++;for(var v=(w-m)*i+1>>>0,b=new Uint8Array(v);m!==w;){for(var A=d[m],E=0,x=v-1;(A!==0||E<p)&&x!==-1;x--,E++)A+=256*b[x]>>>0,b[x]=A%u>>>0,A=A/u>>>0;if(A!==0)throw new Error("Non-zero carry");p=E,m++}for(var F=v-p;F!==v&&b[F]===0;)F++;for(var M=h.repeat(l);F<v;++F)M+=r.charAt(b[F]);return M}function f(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var l=0;if(d[l]!==" "){for(var p=0,m=0;d[l]===h;)p++,l++;for(var w=(d.length-l)*I+1>>>0,v=new Uint8Array(w);d[l];){var b=e[d.charCodeAt(l)];if(b===255)return;for(var A=0,E=w-1;(b!==0||A<m)&&E!==-1;E--,A++)b+=u*v[E]>>>0,v[E]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");m=A,l++}if(d[l]!==" "){for(var x=w-m;x!==w&&v[x]===0;)x++;for(var F=new Uint8Array(p+(w-x)),M=p;x!==w;)F[M++]=v[x++];return F}}}function R(d){var l=f(d);if(l)return l;throw new Error(`Non-${t} character`)}return{encode:c,decodeUnsafe:f,decode:R}}var $e=Ue,Te=$e,ae=Te;var Y=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},_=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ce(this,t)}},ee=class{decoders;constructor(t){this.decoders=t}or(t){return ce(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ce(r,t){return new ee({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var te=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Y(t,e,n),this.decoder=new _(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function de({name:r,prefix:t,encode:e,decode:n}){return new te(r,t,e,n)}function z({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ae(e,r);return de({prefix:t,name:r,encode:n,decode:s=>k(o(s))})}function Pe(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),a=0,u=0,h=0;for(let I=0;I<o;++I){let i=t[r[I]];if(i===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<e|i,a+=e,a>=8&&(a-=8,s[h++]=255&u>>a)}if(a>=e||(255&u<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return s}function Be(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",a=0,u=0;for(let h=0;h<r.length;++h)for(u=u<<8|r[h],a+=8;a>e;)a-=e,s+=t[o&u>>a];if(a!==0&&(s+=t[o&u<<e-a]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Ve(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Ve(n);return de({prefix:t,name:r,encode(s){return Be(s,n,e)},decode(s){return Pe(s,o,e,r)}})}var C=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Kt=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Qt=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Zt=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wt=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Yt=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),_t=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),er=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),tr=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var V=z({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),or=z({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var S=z({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ar=z({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var je=fe,ue=128,qe=127,Je=~qe,Ge=Math.pow(2,31);function fe(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ge;)t[e++]=r&255|ue,r/=128;for(;r&Je;)t[e++]=r&255|ue,r>>>=7;return t[e]=r|0,fe.bytes=e-n+1,t}var Xe=re,He=128,le=127;function re(r,n){var e=0,n=n||0,o=0,s=n,a,u=r.length;do{if(s>=u)throw re.bytes=0,new RangeError("Could not decode varint");a=r[s++],e+=o<28?(a&le)<<o:(a&le)*Math.pow(2,o),o+=7}while(a>=He);return re.bytes=s-n,e}var Ke=Math.pow(2,7),Qe=Math.pow(2,14),Ze=Math.pow(2,21),We=Math.pow(2,28),Ye=Math.pow(2,35),_e=Math.pow(2,42),et=Math.pow(2,49),tt=Math.pow(2,56),rt=Math.pow(2,63),nt=function(r){return r<Ke?1:r<Qe?2:r<Ze?3:r<We?4:r<Ye?5:r<_e?6:r<et?7:r<tt?8:r<rt?9:10},ot={encode:je,decode:Xe,encodingLength:nt},st=ot,T=st;function P(r,t=0){return[T.decode(r,t),T.decode.bytes]}function L(r,t,e=0){return T.encode(r,t,e),t}function O(r){return T.encodingLength(r)}function pe(r,t){let e=t.byteLength,n=O(r),o=n+O(e),s=new Uint8Array(o+e);return L(r,s,0),L(e,s,n),s.set(t,o),new U(r,e,t,s)}function j(r){let t=k(r),[e,n]=P(t),[o,s]=P(t.subarray(n)),a=t.subarray(n+s);if(a.byteLength!==o)throw new Error("Incorrect length");return new U(e,o,a,t)}function me(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ie(r.bytes,e.bytes)}}var U=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function we(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return at(e,ne(r),t??S.encoder);default:return ct(e,ne(r),t??C.encoder)}}var ye=new WeakMap;function ne(r){let t=ye.get(r);if(t==null){let e=new Map;return ye.set(r,e),e}return t}var q=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,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:t,multihash:e}=this;if(t!==B)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==dt)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:t,digest:e}=this.multihash,n=pe(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&me(t.multihash,n.multihash)}toString(t){return we(this,t)}toJSON(){return{"/":we(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:a}=e;return new r(n,o,s,a??ge(n,o,s.bytes))}else if(e[ut]===!0){let{version:n,multihash:o,code:s}=e,a=j(o);return r.create(n,s,a)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==B)throw new Error(`Version 0 CID must use dag-pb (code: ${B}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ge(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,B,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=k(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),a=new U(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(a):r.createV1(e.codec,a),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[c,f]=P(t.subarray(e));return e+=f,c},o=n(),s=B;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let a=e,u=n(),h=n(),I=e+h,i=I-a;return{version:o,codec:s,multihashCode:u,digestSize:h,multihashSize:i,size:I}}static parse(t,e){let[n,o]=it(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ne(s).set(n,t),s}};function it(r,t){switch(r[0]){case"Q":{let e=t??S;return[S.prefix,e.decode(`${S.prefix}${r}`)]}case S.prefix:{let e=t??S;return[S.prefix,e.decode(r)]}case C.prefix:{let e=t??C;return[C.prefix,e.decode(r)]}case V.prefix:{let e=t??V;return[V.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function at(r,t,e){let{prefix:n}=e;if(n!==S.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function ct(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var B=112,dt=18;function ge(r,t,e){let n=O(r),o=n+O(t),s=new Uint8Array(o+e.byteLength);return L(r,s,0),L(t,s,n),s.set(e,o),s}var ut=Symbol.for("@ipld/js-cid/CID");var xe=85;var J=class extends N{data;constructor(){super(),this.data=new Map}put(t,e,n){return n?.signal?.throwIfAborted(),this.data.set(C.encode(t.multihash.bytes),e),t}get(t,e){e?.signal?.throwIfAborted();let n=this.data.get(C.encode(t.multihash.bytes));if(n==null)throw new D;return n}has(t,e){return e?.signal?.throwIfAborted(),this.data.has(C.encode(t.multihash.bytes))}async delete(t,e){e?.signal?.throwIfAborted(),this.data.delete(C.encode(t.multihash.bytes))}async*getAll(t){t?.signal?.throwIfAborted();for(let[e,n]of this.data.entries())yield{cid:q.createV1(xe,j(C.decode(e))),block:n},t?.signal?.throwIfAborted()}};var G=class extends N{put(t,e,n){return n?.signal?.throwIfAborted(),t}get(t,e){throw e?.signal?.throwIfAborted(),new D}has(t,e){return e?.signal?.throwIfAborted(),!1}async delete(t,e){e?.signal?.throwIfAborted()}async*getAll(t){t?.signal?.throwIfAborted()}};var Ce=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Nr=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Dr=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),kr=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function ft(r,t){try{if(typeof r=="string"&&r.length>0)return ht(r);if(typeof r=="number"&&isFinite(r))return t?.long?mt(r):pt(r);throw new Error("Value is not a string or number.")}catch(e){let n=bt(e)?`${e.message}. value=${JSON.stringify(r)}`:"An unknown error has occured.";throw new Error(n)}}function ht(r){if(r=String(r),r.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let t=/^(-?(?:\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(!t)return NaN;let e=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return e*315576e5;case"weeks":case"week":case"w":return e*6048e5;case"days":case"day":case"d":return e*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return e*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return e*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return e*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return e;default:throw new Error(`The unit ${n} was matched, but no matching case exists.`)}}var H=ft;function pt(r){let t=Math.abs(r);return t>=864e5?`${Math.round(r/864e5)}d`:t>=36e5?`${Math.round(r/36e5)}h`:t>=6e4?`${Math.round(r/6e4)}m`:t>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function mt(r){let t=Math.abs(r);return t>=864e5?X(r,t,864e5,"day"):t>=36e5?X(r,t,36e5,"hour"):t>=6e4?X(r,t,6e4,"minute"):t>=1e3?X(r,t,1e3,"second"):`${r} ms`}function X(r,t,e,n){let o=t>=e*1.5;return`${Math.round(r/e)} ${n}${o?"s":""}`}function bt(r){return typeof r=="object"&&r!==null&&"message"in r}function oe(r){e.debug=e,e.default=e,e.coerce=h,e.disable=s,e.enable=o,e.enabled=a,e.humanize=H,e.destroy=I,Object.keys(r).forEach(i=>{e[i]=r[i]}),e.names=[],e.skips=[],e.formatters={};function t(i){let c=0;for(let f=0;f<i.length;f++)c=(c<<5)-c+i.charCodeAt(f),c|=0;return e.colors[Math.abs(c)%e.colors.length]}e.selectColor=t;function e(i){let c,f=null,R,d;function l(...p){if(!l.enabled)return;let m=l,w=Number(new Date),v=w-(c||w);m.diff=v,m.prev=c,m.curr=w,c=w,p[0]=e.coerce(p[0]),typeof p[0]!="string"&&p.unshift("%O");let b=0;p[0]=p[0].replace(/%([a-zA-Z%])/g,(E,x)=>{if(E==="%%")return"%";b++;let F=e.formatters[x];if(typeof F=="function"){let M=p[b];E=F.call(m,M),p.splice(b,1),b--}return E}),e.formatArgs.call(m,p),(m.log||e.log).apply(m,p)}return l.namespace=i,l.useColors=e.useColors(),l.color=e.selectColor(i),l.extend=n,l.destroy=e.destroy,Object.defineProperty(l,"enabled",{enumerable:!0,configurable:!1,get:()=>f!==null?f:(R!==e.namespaces&&(R=e.namespaces,d=e.enabled(i)),d),set:p=>{f=p}}),typeof e.init=="function"&&e.init(l),l}function n(i,c){let f=e(this.namespace+(typeof c>"u"?":":c)+i);return f.log=this.log,f}function o(i){e.save(i),e.namespaces=i,e.names=[],e.skips=[];let c,f=(typeof i=="string"?i:"").split(/[\s,]+/),R=f.length;for(c=0;c<R;c++)f[c]&&(i=f[c].replace(/\*/g,".*?"),i[0]==="-"?e.skips.push(new RegExp("^"+i.substr(1)+"$")):e.names.push(new RegExp("^"+i+"$")))}function s(){let i=[...e.names.map(u),...e.skips.map(u).map(c=>"-"+c)].join(",");return e.enable(""),i}function a(i){if(i[i.length-1]==="*")return!0;let c,f;for(c=0,f=e.skips.length;c<f;c++)if(e.skips[c].test(i))return!1;for(c=0,f=e.names.length;c<f;c++)if(e.names[c].test(i))return!0;return!1}function u(i){return i.toString().substring(2,i.toString().length-2).replace(/\.\*\?$/,"*")}function h(i){return i instanceof Error?i.stack??i.message:i}function I(){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 e.setupFormatters(e.formatters),e.enable(e.load()),e}var K=Et(),wt=["#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 yt(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function gt(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+H(this.diff),!this.useColors)return;let t="color: "+this.color;r.splice(1,0,t,"color: inherit");let e=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(e++,o==="%c"&&(n=e))}),r.splice(n,0,t)}var xt=console.debug??console.log??(()=>{});function Ct(r){try{r?K?.setItem("debug",r):K?.removeItem("debug")}catch{}}function vt(){let r;try{r=K?.getItem("debug")}catch{}return!r&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(r=globalThis.process.env.DEBUG),r}function Et(){try{return localStorage}catch{}}function Ft(r){r.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}var ve=oe({formatArgs:gt,save:Ct,load:vt,useColors:yt,setupFormatters:Ft,colors:wt,storage:K,log:xt});var g=ve;g.formatters.b=r=>r==null?"undefined":S.baseEncode(r);g.formatters.t=r=>r==null?"undefined":C.baseEncode(r);g.formatters.m=r=>r==null?"undefined":Ce.baseEncode(r);g.formatters.p=r=>r==null?"undefined":r.toString();g.formatters.c=r=>r==null?"undefined":r.toString();g.formatters.k=r=>r==null?"undefined":r.toString();g.formatters.a=r=>r==null?"undefined":r.toString();g.formatters.e=r=>r==null?"undefined":Ee(r.stack)??Ee(r.message)??r.toString();function At(r){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=r,t.destroy=()=>!0,t.extend=()=>t,t}function Fe(r){let t=At(`${r}:trace`);return g.enabled(`${r}:trace`)&&g.names.map(e=>e.toString()).find(e=>e.includes(":trace"))!=null&&(t=g(`${r}:trace`)),Object.assign(g(r),{error:g(`${r}:error`),trace:t})}function Ee(r){if(r!=null&&(r=r.trim(),r.length!==0))return r}function St(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var Ae=St;function It(r){return r[Symbol.asyncIterator]!=null}function Nt(r,t){let e=0;if(It(r))return async function*(){for await(let h of r)await t(h,e++)&&(yield h)}();let n=Ae(r),{value:o,done:s}=n.next();if(s===!0)return function*(){}();let a=t(o,e++);if(typeof a.then=="function")return async function*(){await a&&(yield o);for await(let h of n)await t(h,e++)&&(yield h)}();let u=t;return function*(){a===!0&&(yield o);for(let h of n)u(h,e++)&&(yield h)}()}var Se=Nt;function $(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Q=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Ie(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Q(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Q(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,a)=>{n=()=>{a(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var se=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=$(),this.haveNext=$()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=$(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=$(),await Ie(this.readNext.promise,e?.signal,e)}};function Ne(){return new se}function Dt(r){return r[Symbol.asyncIterator]!=null}async function kt(r,t,e){try{await Promise.all(r.map(async n=>{for await(let o of n)await t.push(o,{signal:e}),e.throwIfAborted()})),await t.end(void 0,{signal:e})}catch(n){await t.end(n,{signal:e}).catch(()=>{})}}async function*Rt(r){let t=new AbortController,e=Ne();kt(r,e,t.signal).catch(()=>{});try{yield*e}finally{t.abort()}}function*Mt(r){for(let t of r)yield*t}function zt(...r){let t=[];for(let e of r)Dt(e)||t.push(e);return t.length===r.length?Mt(t):Rt(r)}var De=zt;var Lt=Fe("blockstore:core:tiered"),Z=class extends N{stores;constructor(t){super(),this.stores=t.slice()}async put(t,e,n){return await Promise.all(this.stores.map(async o=>{await o.put(t,e,n)})),t}async get(t,e){let n;for(let o of this.stores)try{let s=await o.get(t,e);if(s!=null)return s}catch(s){n=s,Lt.error(s)}throw n??new D}async has(t,e){for(let n of this.stores)if(await n.has(t,e))return!0;return!1}async delete(t,e){await Promise.all(this.stores.map(async n=>{await n.delete(t,e)}))}async*putMany(t,e={}){for await(let n of t)await this.put(n.cid,n.block,e),yield n.cid}async*deleteMany(t,e={}){for await(let n of t)await this.delete(n,e),yield n}async*getAll(t){let e=new Set;yield*Se(De(...this.stores.map(n=>n.getAll(t))),n=>{let o=n.cid.toString();return e.has(o)?!1:(e.add(o),!0)})}};return Oe(Ot);})();
return BlockstoreCore}));
//# sourceMappingURL=index.min.js.map