blockstore-core
Advanced tools
Comparing version 4.1.0 to 4.1.1
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.BlockstoreCore = factory()}(typeof self !== 'undefined' ? self : this, function () { | ||
"use strict";var BlockstoreCore=(()=>{var me=Object.create;var V=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var xe=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty;var Ee=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),K=(r,e)=>{for(var t in e)V(r,t,{get:e[t],enumerable:!0})},W=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ge(e))!ve.call(r,o)&&o!==t&&V(r,o,{get:()=>e[o],enumerable:!(n=ye(e,o))||n.enumerable});return r};var Ae=(r,e,t)=>(t=r!=null?me(xe(r)):{},W(e||!r||!r.__esModule?V(t,"default",{value:r,enumerable:!0}):t,r)),Se=r=>W(V({},"__esModule",{value:!0}),r);var ee=Ee((ft,Y)=>{"use strict";function Z(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function Ue(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 Z(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),Z(new o,t)}}Y.exports=Ue});var dt={};K(dt,{BaseBlockstore:()=>F,Errors:()=>ct,MemoryBlockstore:()=>$});var B={};K(B,{abortedError:()=>Re,closeFailedError:()=>Oe,deleteFailedError:()=>De,getFailedError:()=>Fe,hasFailedError:()=>Me,notFoundError:()=>j,openFailedError:()=>ze,putFailedError:()=>Ce});var E=Ae(ee(),1);function ze(r){return r=r??new Error("Open failed"),(0,E.default)(r,"ERR_OPEN_FAILED")}function Oe(r){return r=r??new Error("Close failed"),(0,E.default)(r,"ERR_CLOSE_FAILED")}function Ce(r){return r=r??new Error("Put failed"),(0,E.default)(r,"ERR_PUT_FAILED")}function Fe(r){return r=r??new Error("Get failed"),(0,E.default)(r,"ERR_GET_FAILED")}function De(r){return r=r??new Error("Delete failed"),(0,E.default)(r,"ERR_DELETE_FAILED")}function Me(r){return r=r??new Error("Has failed"),(0,E.default)(r,"ERR_HAS_FAILED")}function j(r){return r=r??new Error("Not Found"),(0,E.default)(r,"ERR_NOT_FOUND")}function Re(r){return r=r??new Error("Aborted"),(0,E.default)(r,"ERR_ABORTED")}var F=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)}}async delete(e,t){await 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")}};function Le(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 s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var c=r.length,h=r.charAt(0),O=Math.log(c)/Math.log(256),p=Math.log(256)/Math.log(c);function C(a){if(a instanceof Uint8Array||(ArrayBuffer.isView(a)?a=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):Array.isArray(a)&&(a=Uint8Array.from(a))),!(a instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(a.length===0)return"";for(var f=0,U=0,u=0,m=a.length;u!==m&&a[u]===0;)u++,f++;for(var y=(m-u)*p+1>>>0,l=new Uint8Array(y);u!==m;){for(var g=a[u],S=0,w=y-1;(g!==0||S<U)&&w!==-1;w--,S++)g+=256*l[w]>>>0,l[w]=g%c>>>0,g=g/c>>>0;if(g!==0)throw new Error("Non-zero carry");U=S,u++}for(var v=y-U;v!==y&&l[v]===0;)v++;for(var I=h.repeat(f);v<y;++v)I+=r.charAt(l[v]);return I}function T(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var f=0;if(a[f]!==" "){for(var U=0,u=0;a[f]===h;)U++,f++;for(var m=(a.length-f)*O+1>>>0,y=new Uint8Array(m);a[f];){var l=t[a.charCodeAt(f)];if(l===255)return;for(var g=0,S=m-1;(l!==0||g<u)&&S!==-1;S--,g++)l+=c*y[S]>>>0,y[S]=l%256>>>0,l=l/256>>>0;if(l!==0)throw new Error("Non-zero carry");u=g,f++}if(a[f]!==" "){for(var w=m-u;w!==m&&y[w]===0;)w++;for(var v=new Uint8Array(U+(m-w)),I=U;w!==m;)v[I++]=y[w++];return v}}}function be(a){var f=T(a);if(f)return f;throw new Error(`Non-${e} character`)}return{encode:C,decodeUnsafe:T,decode:be}}var Ne=Le,ke=Ne,te=ke;var ut=new Uint8Array(0);var re=(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},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")};var q=class{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")}},_=class{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 ne(this,e)}},J=class{constructor(e){this.decoders=e}or(e){return ne(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},ne=(r,e)=>new J({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),G=class{constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new q(e,t,n),this.decoder=new _(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},oe=({name:r,prefix:e,encode:t,decode:n})=>new G(r,e,t,n),Q=({prefix:r,name:e,alphabet:t})=>{let{encode:n,decode:o}=te(t,e);return oe({prefix:r,name:e,encode:n,decode:s=>z(o(s))})},Te=(r,e,t,n)=>{let o={};for(let p=0;p<e.length;++p)o[e[p]]=p;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),c=0,h=0,O=0;for(let p=0;p<s;++p){let C=o[r[p]];if(C===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<t|C,c+=t,c>=8&&(c-=8,i[O++]=255&h>>c)}if(c>=t||255&h<<8-c)throw new SyntaxError("Unexpected end of data");return i},Ie=(r,e,t)=>{let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,c=0;for(let h=0;h<r.length;++h)for(c=c<<8|r[h],i+=8;i>t;)i-=t,s+=e[o&c>>i];if(i&&(s+=e[o&c<<t-i]),n)for(;s.length*t&7;)s+="=";return s},x=({name:r,prefix:e,bitsPerChar:t,alphabet:n})=>oe({prefix:e,name:r,encode(o){return Ie(o,n,t)},decode(o){return Te(o,n,t,r)}});var b=x({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),xt=x({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vt=x({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Et=x({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),At=x({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),St=x({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ut=x({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),zt=x({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ot=x({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var se=85;var Be=ce,ie=128,Pe=127,$e=~Pe,je=Math.pow(2,31);function ce(r,e,t){e=e||[],t=t||0;for(var n=t;r>=je;)e[t++]=r&255|ie,r/=128;for(;r&$e;)e[t++]=r&255|ie,r>>>=7;return e[t]=r|0,ce.bytes=t-n+1,e}var qe=X,_e=128,ae=127;function X(r,n){var t=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw X.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&ae)<<o:(i&ae)*Math.pow(2,o),o+=7}while(i>=_e);return X.bytes=s-n,t}var Je=Math.pow(2,7),Ge=Math.pow(2,14),Qe=Math.pow(2,21),Xe=Math.pow(2,28),He=Math.pow(2,35),Ke=Math.pow(2,42),We=Math.pow(2,49),Ze=Math.pow(2,56),Ye=Math.pow(2,63),et=function(r){return r<Je?1:r<Ge?2:r<Qe?3:r<Xe?4:r<He?5:r<Ke?6:r<We?7:r<Ze?8:r<Ye?9:10},tt={encode:Be,decode:qe,encodingLength:et},rt=tt,L=rt;var N=(r,e=0)=>[L.decode(r,e),L.decode.bytes],D=(r,e,t=0)=>(L.encode(r,e,t),e),M=r=>L.encodingLength(r);var he=(r,e)=>{let t=e.byteLength,n=M(r),o=n+M(t),s=new Uint8Array(o+t);return D(r,s,0),D(t,s,n),s.set(e,o),new R(r,t,e,s)},P=r=>{let e=z(r),[t,n]=N(e),[o,s]=N(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new R(t,o,i,e)},fe=(r,e)=>{if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&re(r.bytes,t.bytes)}},R=class{constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var A=Q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Nt=Q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var le=(r,e)=>{let{bytes:t,version:n}=r;switch(n){case 0:return ot(t,H(r),e||A.encoder);default:return st(t,H(r),e||b.encoder)}};var ue=new WeakMap,H=r=>{let e=ue.get(r);if(e==null){let t=new Map;return ue.set(r,t),t}return e},d=class{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!==k)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==it)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return d.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=he(e,t);return d.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 d.equals(this,e)}static equals(e,t){let n=t;return n&&e.code===n.code&&e.version===n.version&&fe(e.multihash,n.multihash)}toString(e){return le(this,e)}toJSON(){return{"/":le(this)}}link(){return this}get[Symbol.toStringTag](){return"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 d)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new d(n,o,s,i||we(n,o,s.bytes))}else if(t[at]===!0){let{version:n,multihash:o,code:s}=t,i=P(o);return d.create(n,s,i)}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!==k)throw new Error(`Version 0 CID must use dag-pb (code: ${k}) block encoding`);return new d(e,t,n,n.bytes)}case 1:{let o=we(e,t,n.bytes);return new d(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return d.create(0,k,e)}static createV1(e,t){return d.create(1,e,t)}static decode(e){let[t,n]=d.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=d.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 s=o.subarray(t.multihashSize-t.digestSize),i=new R(t.multihashCode,t.digestSize,s,o);return[t.version===0?d.createV0(i):d.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[C,T]=N(e.subarray(t));return t+=T,C},o=n(),s=k;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,c=n(),h=n(),O=t+h,p=O-i;return{version:o,codec:s,multihashCode:c,digestSize:h,multihashSize:p,size:O}}static parse(e,t){let[n,o]=nt(e,t),s=d.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return H(s).set(n,e),s}},nt=(r,e)=>{switch(r[0]){case"Q":{let t=e||A;return[A.prefix,t.decode(`${A.prefix}${r}`)]}case A.prefix:{let t=e||A;return[A.prefix,t.decode(r)]}case b.prefix:{let t=e||b;return[b.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)]}}},ot=(r,e,t)=>{let{prefix:n}=t;if(n!==A.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o},st=(r,e,t)=>{let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o},k=112,it=18,we=(r,e,t)=>{let n=M(r),o=n+M(e),s=new Uint8Array(o+t.byteLength);return D(r,s,0),D(e,s,n),s.set(t,o),s},at=Symbol.for("@ipld/js-cid/CID");var $=class extends F{constructor(){super(),this.data=new Map}put(e,t){return this.data.set(b.encode(e.multihash.bytes),t),e}get(e){let t=this.data.get(b.encode(e.multihash.bytes));if(t==null)throw j();return t}has(e){return this.data.has(b.encode(e.multihash.bytes))}async delete(e){this.data.delete(b.encode(e.multihash.bytes))}async*getAll(){for(let[e,t]of this.data.entries())yield{cid:d.createV1(se,P(b.decode(e))),block:t}}};var ct={...B};return Se(dt);})(); | ||
"use strict";var BlockstoreCore=(()=>{var me=Object.create;var V=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var xe=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty;var Ee=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),K=(r,e)=>{for(var t in e)V(r,t,{get:e[t],enumerable:!0})},W=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ge(e))!ve.call(r,o)&&o!==t&&V(r,o,{get:()=>e[o],enumerable:!(n=ye(e,o))||n.enumerable});return r};var Ae=(r,e,t)=>(t=r!=null?me(xe(r)):{},W(e||!r||!r.__esModule?V(t,"default",{value:r,enumerable:!0}):t,r)),Se=r=>W(V({},"__esModule",{value:!0}),r);var ee=Ee((ft,Y)=>{"use strict";function Z(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function Ue(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 Z(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),Z(new o,t)}}Y.exports=Ue});var dt={};K(dt,{BaseBlockstore:()=>F,Errors:()=>ct,MemoryBlockstore:()=>$});var B={};K(B,{abortedError:()=>Re,closeFailedError:()=>Oe,deleteFailedError:()=>De,getFailedError:()=>Fe,hasFailedError:()=>Me,notFoundError:()=>j,openFailedError:()=>ze,putFailedError:()=>Ce});var E=Ae(ee(),1);function ze(r){return r=r??new Error("Open failed"),(0,E.default)(r,"ERR_OPEN_FAILED")}function Oe(r){return r=r??new Error("Close failed"),(0,E.default)(r,"ERR_CLOSE_FAILED")}function Ce(r){return r=r??new Error("Put failed"),(0,E.default)(r,"ERR_PUT_FAILED")}function Fe(r){return r=r??new Error("Get failed"),(0,E.default)(r,"ERR_GET_FAILED")}function De(r){return r=r??new Error("Delete failed"),(0,E.default)(r,"ERR_DELETE_FAILED")}function Me(r){return r=r??new Error("Has failed"),(0,E.default)(r,"ERR_HAS_FAILED")}function j(r){return r=r??new Error("Not Found"),(0,E.default)(r,"ERR_NOT_FOUND")}function Re(r){return r=r??new Error("Aborted"),(0,E.default)(r,"ERR_ABORTED")}var F=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)}}async delete(e,t){await 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")}};function Le(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 s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var c=r.length,h=r.charAt(0),O=Math.log(c)/Math.log(256),p=Math.log(256)/Math.log(c);function C(a){if(a instanceof Uint8Array||(ArrayBuffer.isView(a)?a=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):Array.isArray(a)&&(a=Uint8Array.from(a))),!(a instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(a.length===0)return"";for(var f=0,U=0,u=0,m=a.length;u!==m&&a[u]===0;)u++,f++;for(var y=(m-u)*p+1>>>0,l=new Uint8Array(y);u!==m;){for(var g=a[u],S=0,w=y-1;(g!==0||S<U)&&w!==-1;w--,S++)g+=256*l[w]>>>0,l[w]=g%c>>>0,g=g/c>>>0;if(g!==0)throw new Error("Non-zero carry");U=S,u++}for(var v=y-U;v!==y&&l[v]===0;)v++;for(var I=h.repeat(f);v<y;++v)I+=r.charAt(l[v]);return I}function T(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var f=0;if(a[f]!==" "){for(var U=0,u=0;a[f]===h;)U++,f++;for(var m=(a.length-f)*O+1>>>0,y=new Uint8Array(m);a[f];){var l=t[a.charCodeAt(f)];if(l===255)return;for(var g=0,S=m-1;(l!==0||g<u)&&S!==-1;S--,g++)l+=c*y[S]>>>0,y[S]=l%256>>>0,l=l/256>>>0;if(l!==0)throw new Error("Non-zero carry");u=g,f++}if(a[f]!==" "){for(var w=m-u;w!==m&&y[w]===0;)w++;for(var v=new Uint8Array(U+(m-w)),I=U;w!==m;)v[I++]=y[w++];return v}}}function be(a){var f=T(a);if(f)return f;throw new Error(`Non-${e} character`)}return{encode:C,decodeUnsafe:T,decode:be}}var Ne=Le,ke=Ne,te=ke;var ut=new Uint8Array(0);var re=(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},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")};var q=class{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")}},_=class{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 ne(this,e)}},J=class{constructor(e){this.decoders=e}or(e){return ne(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},ne=(r,e)=>new J({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),G=class{constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new q(e,t,n),this.decoder=new _(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},oe=({name:r,prefix:e,encode:t,decode:n})=>new G(r,e,t,n),Q=({prefix:r,name:e,alphabet:t})=>{let{encode:n,decode:o}=te(t,e);return oe({prefix:r,name:e,encode:n,decode:s=>z(o(s))})},Te=(r,e,t,n)=>{let o={};for(let p=0;p<e.length;++p)o[e[p]]=p;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),c=0,h=0,O=0;for(let p=0;p<s;++p){let C=o[r[p]];if(C===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<t|C,c+=t,c>=8&&(c-=8,i[O++]=255&h>>c)}if(c>=t||255&h<<8-c)throw new SyntaxError("Unexpected end of data");return i},Ie=(r,e,t)=>{let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,c=0;for(let h=0;h<r.length;++h)for(c=c<<8|r[h],i+=8;i>t;)i-=t,s+=e[o&c>>i];if(i&&(s+=e[o&c<<t-i]),n)for(;s.length*t&7;)s+="=";return s},x=({name:r,prefix:e,bitsPerChar:t,alphabet:n})=>oe({prefix:e,name:r,encode(o){return Ie(o,n,t)},decode(o){return Te(o,n,t,r)}});var b=x({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),xt=x({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vt=x({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Et=x({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),At=x({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),St=x({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ut=x({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),zt=x({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ot=x({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ve=ae,se=128,Be=127,Pe=~Be,$e=Math.pow(2,31);function ae(r,e,t){e=e||[],t=t||0;for(var n=t;r>=$e;)e[t++]=r&255|se,r/=128;for(;r&Pe;)e[t++]=r&255|se,r>>>=7;return e[t]=r|0,ae.bytes=t-n+1,e}var je=X,qe=128,ie=127;function X(r,n){var t=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw X.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&ie)<<o:(i&ie)*Math.pow(2,o),o+=7}while(i>=qe);return X.bytes=s-n,t}var _e=Math.pow(2,7),Je=Math.pow(2,14),Ge=Math.pow(2,21),Qe=Math.pow(2,28),Xe=Math.pow(2,35),He=Math.pow(2,42),Ke=Math.pow(2,49),We=Math.pow(2,56),Ze=Math.pow(2,63),Ye=function(r){return r<_e?1:r<Je?2:r<Ge?3:r<Qe?4:r<Xe?5:r<He?6:r<Ke?7:r<We?8:r<Ze?9:10},et={encode:Ve,decode:je,encodingLength:Ye},tt=et,L=tt;var N=(r,e=0)=>[L.decode(r,e),L.decode.bytes],D=(r,e,t=0)=>(L.encode(r,e,t),e),M=r=>L.encodingLength(r);var de=(r,e)=>{let t=e.byteLength,n=M(r),o=n+M(t),s=new Uint8Array(o+t);return D(r,s,0),D(t,s,n),s.set(e,o),new R(r,t,e,s)},P=r=>{let e=z(r),[t,n]=N(e),[o,s]=N(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new R(t,o,i,e)},he=(r,e)=>{if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&re(r.bytes,t.bytes)}},R=class{constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var A=Q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Lt=Q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var pe=(r,e)=>{let{bytes:t,version:n}=r;switch(n){case 0:return nt(t,H(r),e||A.encoder);default:return ot(t,H(r),e||b.encoder)}};var le=new WeakMap,H=r=>{let e=le.get(r);if(e==null){let t=new Map;return le.set(r,t),t}return e},d=class{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!==k)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==st)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return d.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=de(e,t);return d.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 d.equals(this,e)}static equals(e,t){let n=t;return n&&e.code===n.code&&e.version===n.version&&he(e.multihash,n.multihash)}toString(e){return pe(this,e)}toJSON(){return{"/":pe(this)}}link(){return this}get[Symbol.toStringTag](){return"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 d)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new d(n,o,s,i||ue(n,o,s.bytes))}else if(t[it]===!0){let{version:n,multihash:o,code:s}=t,i=P(o);return d.create(n,s,i)}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!==k)throw new Error(`Version 0 CID must use dag-pb (code: ${k}) block encoding`);return new d(e,t,n,n.bytes)}case 1:{let o=ue(e,t,n.bytes);return new d(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return d.create(0,k,e)}static createV1(e,t){return d.create(1,e,t)}static decode(e){let[t,n]=d.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=d.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 s=o.subarray(t.multihashSize-t.digestSize),i=new R(t.multihashCode,t.digestSize,s,o);return[t.version===0?d.createV0(i):d.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[C,T]=N(e.subarray(t));return t+=T,C},o=n(),s=k;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,c=n(),h=n(),O=t+h,p=O-i;return{version:o,codec:s,multihashCode:c,digestSize:h,multihashSize:p,size:O}}static parse(e,t){let[n,o]=rt(e,t),s=d.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return H(s).set(n,e),s}},rt=(r,e)=>{switch(r[0]){case"Q":{let t=e||A;return[A.prefix,t.decode(`${A.prefix}${r}`)]}case A.prefix:{let t=e||A;return[A.prefix,t.decode(r)]}case b.prefix:{let t=e||b;return[b.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)]}}},nt=(r,e,t)=>{let{prefix:n}=t;if(n!==A.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o},ot=(r,e,t)=>{let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o},k=112,st=18,ue=(r,e,t)=>{let n=M(r),o=n+M(e),s=new Uint8Array(o+t.byteLength);return D(r,s,0),D(e,s,n),s.set(t,o),s},it=Symbol.for("@ipld/js-cid/CID");var we=85;var $=class extends F{data;constructor(){super(),this.data=new Map}put(e,t){return this.data.set(b.encode(e.multihash.bytes),t),e}get(e){let t=this.data.get(b.encode(e.multihash.bytes));if(t==null)throw j();return t}has(e){return this.data.has(b.encode(e.multihash.bytes))}async delete(e){this.data.delete(b.encode(e.multihash.bytes))}async*getAll(){for(let[e,t]of this.data.entries())yield{cid:d.createV1(we,P(b.decode(e))),block:t}}};var ct={...B};return Se(dt);})(); | ||
return BlockstoreCore})); |
@@ -0,5 +1,5 @@ | ||
import { CID } from 'multiformats/cid'; | ||
import { BaseBlockstore } from './base.js'; | ||
import { CID } from 'multiformats/cid'; | ||
import type { Pair } from 'interface-blockstore'; | ||
import type { Await, AwaitIterable } from 'interface-store'; | ||
import type { Pair } from 'interface-blockstore'; | ||
export declare class MemoryBlockstore extends BaseBlockstore { | ||
@@ -6,0 +6,0 @@ private readonly data; |
@@ -1,8 +0,9 @@ | ||
import { BaseBlockstore } from './base.js'; | ||
import { base32 } from 'multiformats/bases/base32'; | ||
import { CID } from 'multiformats/cid'; | ||
import * as raw from 'multiformats/codecs/raw'; | ||
import { CID } from 'multiformats/cid'; | ||
import * as Digest from 'multiformats/hashes/digest'; | ||
import { BaseBlockstore } from './base.js'; | ||
import * as Errors from './errors.js'; | ||
export class MemoryBlockstore extends BaseBlockstore { | ||
data; | ||
constructor() { | ||
@@ -9,0 +10,0 @@ super(); |
{ | ||
"name": "blockstore-core", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"description": "Contains various implementations of the API contract described in interface-blockstore", | ||
@@ -75,3 +75,3 @@ "author": "Alex Potsides <alex.potsides@protocol.ai>", | ||
"branches": [ | ||
"master" | ||
"main" | ||
], | ||
@@ -181,3 +181,3 @@ "plugins": [ | ||
"devDependencies": { | ||
"aegir": "^38.1.7", | ||
"aegir": "^39.0.9", | ||
"interface-blockstore-tests": "^6.0.0" | ||
@@ -184,0 +184,0 @@ }, |
@@ -6,3 +6,3 @@ # blockstore-core <!-- omit in toc --> | ||
[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-stores.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-stores) | ||
[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-stores/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/ipfs/js-stores/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) | ||
[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-stores/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/ipfs/js-stores/actions/workflows/js-test-and-release.yml?query=branch%3Amain) | ||
@@ -9,0 +9,0 @@ > Contains various implementations of the API contract described in interface-blockstore |
@@ -1,9 +0,9 @@ | ||
import { BaseBlockstore } from './base.js' | ||
import { base32 } from 'multiformats/bases/base32' | ||
import { CID } from 'multiformats/cid' | ||
import * as raw from 'multiformats/codecs/raw' | ||
import { CID } from 'multiformats/cid' | ||
import * as Digest from 'multiformats/hashes/digest' | ||
import { BaseBlockstore } from './base.js' | ||
import * as Errors from './errors.js' | ||
import type { Pair } from 'interface-blockstore' | ||
import type { Await, AwaitIterable } from 'interface-store' | ||
import type { Pair } from 'interface-blockstore' | ||
@@ -10,0 +10,0 @@ export class MemoryBlockstore extends BaseBlockstore { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39954
354