blockstore-core
Advanced tools
Comparing version 4.0.1 to 4.0.2
(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 be=Object.create;var V=Object.defineProperty;var me=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=me(e,o))||n.enumerable});return r};var Ae=(r,e,t)=>(t=r!=null?be(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{async has(e,t){return await Promise.reject(new Error(".has is not implemented"))}async put(e,t,n){await 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{cid:n,block:o}}async get(e,t){return await Promise.reject(new Error(".get is not implemented"))}async*getMany(e,t){for await(let n of e)yield 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,b=a.length;u!==b&&a[u]===0;)u++,f++;for(var m=(b-u)*p+1>>>0,l=new Uint8Array(m);u!==b;){for(var g=a[u],S=0,w=m-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=m-U;v!==m&&l[v]===0;)v++;for(var I=h.repeat(f);v<m;++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 b=(a.length-f)*O+1>>>0,m=new Uint8Array(b);a[f];){var l=t[a.charCodeAt(f)];if(l===255)return;for(var g=0,S=b-1;(l!==0||g<u)&&S!==-1;S--,g++)l+=c*m[S]>>>0,m[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=b-u;w!==b&&m[w]===0;)w++;for(var v=new Uint8Array(U+(b-w)),I=U;w!==b;)v[I++]=m[w++];return v}}}function ye(a){var f=T(a);if(f)return f;throw new Error(`Non-${e} character`)}return{encode:C,decodeUnsafe:T,decode:ye}}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 y=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||y.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 y.prefix:{let t=e||y;return[y.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}async put(e,t){this.data.set(y.encode(e.multihash.bytes),t)}async get(e){let t=this.data.get(y.encode(e.multihash.bytes));if(t==null)throw j();return t}async has(e){return this.data.has(y.encode(e.multihash.bytes))}async delete(e){this.data.delete(y.encode(e.multihash.bytes))}async*getAll(){for(let[e,t]of this.data.entries())yield{cid:d.createV1(se,P(y.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 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);})(); | ||
return BlockstoreCore})); |
@@ -1,17 +0,17 @@ | ||
import type { Blockstore, Options, Pair } from 'interface-blockstore'; | ||
import type { Blockstore, Pair } from 'interface-blockstore'; | ||
import type { AbortOptions, Await, AwaitIterable } from 'interface-store'; | ||
import type { CID } from 'multiformats/cid'; | ||
import type { AwaitIterable } from 'interface-store'; | ||
export declare class BaseBlockstore implements Blockstore { | ||
has(key: CID, options?: Options): Promise<boolean>; | ||
put(key: CID, val: Uint8Array, options?: Options): Promise<void>; | ||
putMany(source: AwaitIterable<Pair>, options?: Options): AsyncIterable<Pair>; | ||
get(key: CID, options?: Options): Promise<Uint8Array>; | ||
getMany(source: AwaitIterable<CID>, options?: Options): AsyncIterable<Uint8Array>; | ||
delete(key: CID, options?: Options): Promise<void>; | ||
deleteMany(source: AwaitIterable<CID>, options?: Options): AsyncIterable<CID>; | ||
has(key: CID, options?: AbortOptions): Await<boolean>; | ||
put(key: CID, val: Uint8Array, options?: AbortOptions): Await<CID>; | ||
putMany(source: AwaitIterable<Pair>, options?: AbortOptions): AwaitIterable<CID>; | ||
get(key: CID, options?: AbortOptions): Await<Uint8Array>; | ||
getMany(source: AwaitIterable<CID>, options?: AbortOptions): AwaitIterable<Pair>; | ||
delete(key: CID, options?: AbortOptions): Promise<void>; | ||
deleteMany(source: AwaitIterable<CID>, options?: AbortOptions): AwaitIterable<CID>; | ||
/** | ||
* Extending classes should override `query` or implement this method | ||
*/ | ||
getAll(options?: Options): AwaitIterable<Pair>; | ||
getAll(options?: AbortOptions): AwaitIterable<Pair>; | ||
} | ||
//# sourceMappingURL=base.d.ts.map |
export class BaseBlockstore { | ||
async has(key, options) { | ||
return await Promise.reject(new Error('.has is not implemented')); | ||
has(key, options) { | ||
return Promise.reject(new Error('.has is not implemented')); | ||
} | ||
async put(key, val, options) { | ||
await Promise.reject(new Error('.put is not implemented')); | ||
put(key, val, options) { | ||
return Promise.reject(new Error('.put is not implemented')); | ||
} | ||
@@ -11,11 +11,14 @@ async *putMany(source, options) { | ||
await this.put(cid, block, options); | ||
yield { cid, block }; | ||
yield cid; | ||
} | ||
} | ||
async get(key, options) { | ||
return await Promise.reject(new Error('.get is not implemented')); | ||
get(key, options) { | ||
return Promise.reject(new Error('.get is not implemented')); | ||
} | ||
async *getMany(source, options) { | ||
for await (const key of source) { | ||
yield this.get(key, options); | ||
yield { | ||
cid: key, | ||
block: await this.get(key, options) | ||
}; | ||
} | ||
@@ -22,0 +25,0 @@ } |
import { BaseBlockstore } from './base.js'; | ||
import { CID } from 'multiformats/cid'; | ||
import type { AwaitIterable } from 'interface-store'; | ||
import type { Await, AwaitIterable } from 'interface-store'; | ||
import type { Pair } from 'interface-blockstore'; | ||
@@ -8,5 +8,5 @@ export declare class MemoryBlockstore extends BaseBlockstore { | ||
constructor(); | ||
put(key: CID, val: Uint8Array): Promise<void>; | ||
get(key: CID): Promise<Uint8Array>; | ||
has(key: CID): Promise<boolean>; | ||
put(key: CID, val: Uint8Array): Await<CID>; | ||
get(key: CID): Await<Uint8Array>; | ||
has(key: CID): Await<boolean>; | ||
delete(key: CID): Promise<void>; | ||
@@ -13,0 +13,0 @@ getAll(): AwaitIterable<Pair>; |
@@ -12,6 +12,7 @@ import { BaseBlockstore } from './base.js'; | ||
} | ||
async put(key, val) { | ||
put(key, val) { | ||
this.data.set(base32.encode(key.multihash.bytes), val); | ||
return key; | ||
} | ||
async get(key) { | ||
get(key) { | ||
const buf = this.data.get(base32.encode(key.multihash.bytes)); | ||
@@ -23,3 +24,3 @@ if (buf == null) { | ||
} | ||
async has(key) { | ||
has(key) { | ||
return this.data.has(base32.encode(key.multihash.bytes)); | ||
@@ -26,0 +27,0 @@ } |
{ | ||
"name": "blockstore-core", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Contains various implementations of the API contract described in interface-blockstore", | ||
@@ -175,4 +175,4 @@ "author": "Alex Potsides <alex.potsides@protocol.ai>", | ||
"err-code": "^3.0.1", | ||
"interface-blockstore": "^5.0.0", | ||
"interface-store": "^4.0.0", | ||
"interface-blockstore": "^5.1.1", | ||
"interface-store": "^5.0.1", | ||
"multiformats": "^11.0.0" | ||
@@ -182,4 +182,4 @@ }, | ||
"aegir": "^38.1.7", | ||
"interface-blockstore-tests": "^5.0.0" | ||
"interface-blockstore-tests": "^6.0.0" | ||
} | ||
} |
@@ -1,36 +0,39 @@ | ||
import type { Blockstore, Options, Pair } from 'interface-blockstore' | ||
import type { Blockstore, Pair } from 'interface-blockstore' | ||
import type { AbortOptions, Await, AwaitIterable } from 'interface-store' | ||
import type { CID } from 'multiformats/cid' | ||
import type { AwaitIterable } from 'interface-store' | ||
export class BaseBlockstore implements Blockstore { | ||
async has (key: CID, options?: Options): Promise<boolean> { | ||
return await Promise.reject(new Error('.has is not implemented')) | ||
has (key: CID, options?: AbortOptions): Await<boolean> { | ||
return Promise.reject(new Error('.has is not implemented')) | ||
} | ||
async put (key: CID, val: Uint8Array, options?: Options): Promise<void> { | ||
await Promise.reject(new Error('.put is not implemented')) | ||
put (key: CID, val: Uint8Array, options?: AbortOptions): Await<CID> { | ||
return Promise.reject(new Error('.put is not implemented')) | ||
} | ||
async * putMany (source: AwaitIterable<Pair>, options?: Options): AsyncIterable<Pair> { | ||
async * putMany (source: AwaitIterable<Pair>, options?: AbortOptions): AwaitIterable<CID> { | ||
for await (const { cid, block } of source) { | ||
await this.put(cid, block, options) | ||
yield { cid, block } | ||
yield cid | ||
} | ||
} | ||
async get (key: CID, options?: Options): Promise<Uint8Array> { | ||
return await Promise.reject(new Error('.get is not implemented')) | ||
get (key: CID, options?: AbortOptions): Await<Uint8Array> { | ||
return Promise.reject(new Error('.get is not implemented')) | ||
} | ||
async * getMany (source: AwaitIterable<CID>, options?: Options): AsyncIterable<Uint8Array> { | ||
async * getMany (source: AwaitIterable<CID>, options?: AbortOptions): AwaitIterable<Pair> { | ||
for await (const key of source) { | ||
yield this.get(key, options) | ||
yield { | ||
cid: key, | ||
block: await this.get(key, options) | ||
} | ||
} | ||
} | ||
async delete (key: CID, options?: Options): Promise<void> { | ||
async delete (key: CID, options?: AbortOptions): Promise<void> { | ||
await Promise.reject(new Error('.delete is not implemented')) | ||
} | ||
async * deleteMany (source: AwaitIterable<CID>, options?: Options): AsyncIterable<CID> { | ||
async * deleteMany (source: AwaitIterable<CID>, options?: AbortOptions): AwaitIterable<CID> { | ||
for await (const key of source) { | ||
@@ -45,5 +48,5 @@ await this.delete(key, options) | ||
*/ | ||
async * getAll (options?: Options): AwaitIterable<Pair> { // eslint-disable-line require-yield | ||
async * getAll (options?: AbortOptions): AwaitIterable<Pair> { // eslint-disable-line require-yield | ||
throw new Error('.getAll is not implemented') | ||
} | ||
} |
@@ -7,3 +7,3 @@ import { BaseBlockstore } from './base.js' | ||
import * as Errors from './errors.js' | ||
import type { AwaitIterable } from 'interface-store' | ||
import type { Await, AwaitIterable } from 'interface-store' | ||
import type { Pair } from 'interface-blockstore' | ||
@@ -20,7 +20,9 @@ | ||
async put (key: CID, val: Uint8Array): Promise<void> { // eslint-disable-line require-await | ||
put (key: CID, val: Uint8Array): Await<CID> { // eslint-disable-line require-await | ||
this.data.set(base32.encode(key.multihash.bytes), val) | ||
return key | ||
} | ||
async get (key: CID): Promise<Uint8Array> { | ||
get (key: CID): Await<Uint8Array> { | ||
const buf = this.data.get(base32.encode(key.multihash.bytes)) | ||
@@ -35,3 +37,3 @@ | ||
async has (key: CID): Promise<boolean> { | ||
has (key: CID): Await<boolean> { | ||
return this.data.has(base32.encode(key.multihash.bytes)) | ||
@@ -38,0 +40,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
39987
353
+ Addedinterface-store@5.1.8(transitive)
- Removedinterface-store@4.1.0(transitive)
Updatedinterface-blockstore@^5.1.1
Updatedinterface-store@^5.0.1