blockstore-core
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -1,17 +0,3 @@ | ||
"use strict";(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.BlockstoreCore = factory()}(typeof self !== 'undefined' ? self : this, function () { | ||
var BlockstoreCore=(()=>{var ke=Object.create;var _=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var Te=Object.getOwnPropertyNames;var Be=Object.getPrototypeOf,Ve=Object.prototype.hasOwnProperty;var N=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ne=(r,e)=>{for(var t in e)_(r,t,{get:e[t],enumerable:!0})},oe=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Te(e))!Ve.call(r,o)&&o!==t&&_(r,o,{get:()=>e[o],enumerable:!(n=Ne(e,o))||n.enumerable});return r};var T=(r,e,t)=>(t=r!=null?ke(Be(r)):{},oe(e||!r||!r.__esModule?_(t,"default",{value:r,enumerable:!0}):t,r)),Le=r=>oe(_({},"__esModule",{value:!0}),r);var ae=N((St,ie)=>{"use strict";function se(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function je(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 se(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),se(new o,t)}}ie.exports=je});var de=N((Ct,ce)=>{"use strict";var Re=async r=>{for await(let e of r);};ce.exports=Re});var he=N((Dt,fe)=>{"use strict";var _e=async function*(r,e){for await(let t of r)await e(t)&&(yield t)};fe.exports=_e});var pe=N((zt,le)=>{"use strict";var $e=async function*(r,e){let t=0;if(!(e<1)){for await(let n of r)if(yield n,t++,t===e)return}};le.exports=$e});var ye=N((Ot,ue)=>{"use strict";var Fe=async r=>{let e=[];for await(let t of r)e.push(t);return e};ue.exports=Fe});var Et={};ne(Et,{BaseBlockstore:()=>U,Errors:()=>vt,MemoryBlockstore:()=>J});var $={};ne($,{abortedError:()=>Pe,notFoundError:()=>G});var W=T(ae(),1);function G(r){return r=r||new Error("Not Found"),(0,W.default)(r,"ERR_NOT_FOUND")}function Pe(r){return r=r||new Error("Aborted"),(0,W.default)(r,"ERR_ABORTED")}var Q=T(de(),1),C=T(he(),1),X=T(pe(),1),me=T(ye(),1),we=(r,e)=>async function*(){yield*(await(0,me.default)(r)).sort(e)}(),U=class{open(){return Promise.reject(new Error(".open is not implemented"))}close(){return Promise.reject(new Error(".close is not implemented"))}put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}get(e,t){return Promise.reject(new Error(".get is not implemented"))}has(e,t){return Promise.reject(new Error(".has is not implemented"))}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*putMany(e,t={}){for await(let{key:n,value:o}of e)await this.put(n,o,t),yield{key:n,value:o}}async*getMany(e,t={}){for await(let n of e)yield this.get(n,t)}async*deleteMany(e,t={}){for await(let n of e)await this.delete(n,t),yield n}batch(){let e=[],t=[];return{put(n,o){e.push({key:n,value:o})},delete(n){t.push(n)},commit:async n=>{await(0,Q.default)(this.putMany(e,n)),e=[],await(0,Q.default)(this.deleteMany(t,n)),t=[]}}}async*_all(e,t){throw new Error("._all is not implemented")}async*_allKeys(e,t){throw new Error("._allKeys is not implemented")}query(e,t){let n=this._all(e,t);if(e.prefix!=null&&(n=(0,C.default)(n,o=>o.key.toString().startsWith(e.prefix||""))),Array.isArray(e.filters)&&(n=e.filters.reduce((o,s)=>(0,C.default)(o,s),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((o,s)=>we(o,s),n)),e.offset!=null){let o=0;n=(0,C.default)(n,()=>o++>=(e.offset||0))}return e.limit!=null&&(n=(0,X.default)(n,e.limit)),n}queryKeys(e,t){let n=this._allKeys(e,t);if(e.prefix!=null&&(n=(0,C.default)(n,o=>o.toString().startsWith(e.prefix||""))),Array.isArray(e.filters)&&(n=e.filters.reduce((o,s)=>(0,C.default)(o,s),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((o,s)=>we(o,s),n)),e.offset!=null){let o=0;n=(0,C.default)(n,()=>o++>=e.offset)}return e.limit!=null&&(n=(0,X.default)(n,e.limit)),n}};function Ke(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,f=r.charAt(0),z=Math.log(c)/Math.log(256),l=Math.log(256)/Math.log(c);function O(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 h=0,S=0,y=0,m=a.length;y!==m&&a[y]===0;)y++,h++;for(var b=(m-y)*l+1>>>0,p=new Uint8Array(b);y!==m;){for(var g=a[y],A=0,w=b-1;(g!==0||A<S)&&w!==-1;w--,A++)g+=256*p[w]>>>0,p[w]=g%c>>>0,g=g/c>>>0;if(g!==0)throw new Error("Non-zero carry");S=A,y++}for(var v=b-S;v!==b&&p[v]===0;)v++;for(var R=f.repeat(h);v<b;++v)R+=r.charAt(p[v]);return R}function P(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var h=0;if(a[h]!==" "){for(var S=0,y=0;a[h]===f;)S++,h++;for(var m=(a.length-h)*z+1>>>0,b=new Uint8Array(m);a[h];){var p=t[a.charCodeAt(h)];if(p===255)return;for(var g=0,A=m-1;(p!==0||g<y)&&A!==-1;A--,g++)p+=c*b[A]>>>0,b[A]=p%256>>>0,p=p/256>>>0;if(p!==0)throw new Error("Non-zero carry");y=g,h++}if(a[h]!==" "){for(var w=m-y;w!==m&&b[w]===0;)w++;for(var v=new Uint8Array(S+(m-w)),R=S;w!==m;)v[R++]=b[w++];return v}}}function Ie(a){var h=P(a);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:O,decodeUnsafe:P,decode:Ie}}var Je=Ke,We=Je,be=We;var It=new Uint8Array(0);var ge=(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},D=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 Z=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")}},H=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 xe(this,e)}},Y=class{constructor(e){this.decoders=e}or(e){return xe(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`)}},xe=(r,e)=>new Y({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),q=class{constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Z(e,t,n),this.decoder=new H(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},ve=({name:r,prefix:e,encode:t,decode:n})=>new q(r,e,t,n),ee=({prefix:r,name:e,alphabet:t})=>{let{encode:n,decode:o}=be(t,e);return ve({prefix:r,name:e,encode:n,decode:s=>D(o(s))})},Ge=(r,e,t,n)=>{let o={};for(let l=0;l<e.length;++l)o[e[l]]=l;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),c=0,f=0,z=0;for(let l=0;l<s;++l){let O=o[r[l]];if(O===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<t|O,c+=t,c>=8&&(c-=8,i[z++]=255&f>>c)}if(c>=t||255&f<<8-c)throw new SyntaxError("Unexpected end of data");return i},Qe=(r,e,t)=>{let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,c=0;for(let f=0;f<r.length;++f)for(c=c<<8|r[f],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})=>ve({prefix:e,name:r,encode(o){return Qe(o,n,t)},decode(o){return Ge(o,n,t,r)}});var u=x({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Lt=x({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jt=x({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Pt=x({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Rt=x({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),_t=x({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),$t=x({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ft=x({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Kt=x({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var te=85;var Ze=Se,Ee=128,He=127,Ye=~He,qe=Math.pow(2,31);function Se(r,e,t){e=e||[],t=t||0;for(var n=t;r>=qe;)e[t++]=r&255|Ee,r/=128;for(;r&Ye;)e[t++]=r&255|Ee,r>>>=7;return e[t]=r|0,Se.bytes=t-n+1,e}var et=re,tt=128,Ae=127;function re(r,n){var t=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw re.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>=tt);return re.bytes=s-n,t}var rt=Math.pow(2,7),nt=Math.pow(2,14),ot=Math.pow(2,21),st=Math.pow(2,28),it=Math.pow(2,35),at=Math.pow(2,42),ct=Math.pow(2,49),dt=Math.pow(2,56),ft=Math.pow(2,63),ht=function(r){return r<rt?1:r<nt?2:r<ot?3:r<st?4:r<it?5:r<at?6:r<ct?7:r<dt?8:r<ft?9:10},lt={encode:Ze,decode:et,encodingLength:ht},pt=lt,B=pt;var V=r=>[B.decode(r),B.decode.bytes],M=(r,e,t=0)=>(B.encode(r,e,t),e),I=r=>B.encodingLength(r);var De=(r,e)=>{let t=e.byteLength,n=I(r),o=n+I(t),s=new Uint8Array(o+t);return M(r,s,0),M(t,s,n),s.set(e,o),new k(r,t,e,s)},L=r=>{let e=D(r),[t,n]=V(e),[o,s]=V(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new k(t,o,i,e)},ze=(r,e)=>r===e?!0:r.code===e.code&&r.size===e.size&&ge(r.bytes,e.bytes),k=class{constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var E=ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ht=ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var d=class{constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this.byteOffset=o.byteOffset,this.byteLength=o.byteLength,this.asCID=this,this._baseCache=new Map,Object.defineProperties(this,{byteOffset:K,byteLength:K,code:F,version:F,multihash:F,bytes:F,_baseCache:K,asCID:K})}toV0(){switch(this.version){case 0:return this;default:{let{code:e,multihash:t}=this;if(e!==j)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==mt)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return d.createV0(t)}}}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 0. This is a bug please report`)}}equals(e){return e&&this.code===e.code&&this.version===e.version&&ze(this.multihash,e.multihash)}toString(e){let{bytes:t,version:n,_baseCache:o}=this;switch(n){case 0:return yt(t,o,e||E.encoder);default:return wt(t,o,e||u.encoder)}}toJSON(){return{code:this.code,version:this.version,hash:this.multihash.bytes}}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return"CID("+this.toString()+")"}static isCID(e){return gt(/^0\.0/,xt),!!(e&&(e[Me]||e.asCID===e))}get toBaseEncodedString(){throw new Error("Deprecated, use .toString()")}get codec(){throw new Error('"codec" property is deprecated, use integer "code" property instead')}get buffer(){throw new Error("Deprecated .buffer property, use .bytes to get Uint8Array instead")}get multibaseName(){throw new Error('"multibaseName" property is deprecated')}get prefix(){throw new Error('"prefix" property is deprecated')}static asCID(e){if(e instanceof d)return e;if(e!=null&&e.asCID===e){let{version:t,code:n,multihash:o,bytes:s}=e;return new d(t,n,o,s||Ue(t,n,o.bytes))}else if(e!=null&&e[Me]===!0){let{version:t,multihash:n,code:o}=e,s=L(n);return d.create(t,o,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");switch(e){case 0:{if(t!==j)throw new Error(`Version 0 CID must use dag-pb (code: ${j}) 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,j,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=D(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 k(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[O,P]=V(e.subarray(t));return t+=P,O},o=n(),s=j;if(o===18?(o=0,t=0):o===1&&(s=n()),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,c=n(),f=n(),z=t+f,l=z-i;return{version:o,codec:s,multihashCode:c,digestSize:f,multihashSize:l,size:z}}static parse(e,t){let[n,o]=ut(e,t),s=d.decode(o);return s._baseCache.set(n,e),s}},ut=(r,e)=>{switch(r[0]){case"Q":{let t=e||E;return[E.prefix,t.decode(`${E.prefix}${r}`)]}case E.prefix:{let t=e||E;return[E.prefix,t.decode(r)]}case u.prefix:{let t=e||u;return[u.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)]}}},yt=(r,e,t)=>{let{prefix:n}=t;if(n!==E.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},wt=(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},j=112,mt=18,Ue=(r,e,t)=>{let n=I(r),o=n+I(e),s=new Uint8Array(o+t.byteLength);return M(r,s,0),M(e,s,n),s.set(t,o),s},Me=Symbol.for("@ipld/js-cid/CID"),F={writable:!1,configurable:!1,enumerable:!0},K={writable:!1,enumerable:!1,configurable:!1},bt="0.0.0-dev",gt=(r,e)=>{if(r.test(bt))console.warn(e);else throw new Error(e)},xt=`CID.isCID(v) is deprecated and will be removed in the next major release. | ||
Following code pattern: | ||
if (CID.isCID(value)) { | ||
doSomethingWithCID(value) | ||
} | ||
Is replaced with: | ||
const cid = CID.asCID(value) | ||
if (cid) { | ||
// Make sure to use cid instead of value | ||
doSomethingWithCID(cid) | ||
} | ||
`;var J=class extends U{constructor(){super(),this.data={}}open(){return Promise.resolve()}close(){return Promise.resolve()}async put(e,t){this.data[u.encode(e.multihash.bytes)]=t}async get(e){if(!await this.has(e))throw G();return this.data[u.encode(e.multihash.bytes)]}async has(e){return this.data[u.encode(e.multihash.bytes)]!==void 0}async delete(e){delete this.data[u.encode(e.multihash.bytes)]}async*_all(){yield*Object.entries(this.data).map(([e,t])=>({key:d.createV1(te,L(u.decode(e))),value:t}))}async*_allKeys(){yield*Object.entries(this.data).map(([e])=>d.createV1(te,L(u.decode(e))))}};var vt={...$};return Le(Et);})(); | ||
(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 Ne=Object.create;var $=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var Be=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty;var V=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),re=(r,e)=>{for(var t in e)$(r,t,{get:e[t],enumerable:!0})},ne=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ve(e))!De.call(r,o)&&o!==t&&$(r,o,{get:()=>e[o],enumerable:!(n=Te(e,o))||n.enumerable});return r};var B=(r,e,t)=>(t=r!=null?Ne(Be(r)):{},ne(e||!r||!r.__esModule?$(t,"default",{value:r,enumerable:!0}):t,r)),Le=r=>ne($({},"__esModule",{value:!0}),r);var ie=V((Et,se)=>{"use strict";function oe(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function Pe(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 oe(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),oe(new o,t)}}se.exports=Pe});var ce=V((At,ae)=>{"use strict";var Fe=async r=>{for await(let e of r);};ae.exports=Fe});var fe=V((St,de)=>{"use strict";var Re=async function*(r,e){for await(let t of r)await e(t)&&(yield t)};de.exports=Re});var le=V((zt,he)=>{"use strict";var $e=async function*(r,e){let t=0;if(!(e<1)){for await(let n of r)if(yield n,t++,t===e)return}};he.exports=$e});var ue=V((Ut,pe)=>{"use strict";var Ie=async r=>{let e=[];for await(let t of r)e.push(t);return e};pe.exports=Ie});var xt={};re(xt,{BaseBlockstore:()=>C,Errors:()=>gt,MemoryBlockstore:()=>K});var I={};re(I,{abortedError:()=>je,notFoundError:()=>J});var _=B(ie(),1);function J(r){return r=r||new Error("Not Found"),(0,_.default)(r,"ERR_NOT_FOUND")}function je(r){return r=r||new Error("Aborted"),(0,_.default)(r,"ERR_ABORTED")}var G=B(ce(),1),z=B(fe(),1),Q=B(le(),1),me=B(ue(),1),ye=(r,e)=>async function*(){yield*(await(0,me.default)(r)).sort(e)}(),C=class{open(){return Promise.reject(new Error(".open is not implemented"))}close(){return Promise.reject(new Error(".close is not implemented"))}put(e,t,n){return Promise.reject(new Error(".put is not implemented"))}get(e,t){return Promise.reject(new Error(".get is not implemented"))}has(e,t){return Promise.reject(new Error(".has is not implemented"))}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*putMany(e,t={}){for await(let{key:n,value:o}of e)await this.put(n,o,t),yield{key:n,value:o}}async*getMany(e,t={}){for await(let n of e)yield this.get(n,t)}async*deleteMany(e,t={}){for await(let n of e)await this.delete(n,t),yield n}batch(){let e=[],t=[];return{put(n,o){e.push({key:n,value:o})},delete(n){t.push(n)},commit:async n=>{await(0,G.default)(this.putMany(e,n)),e=[],await(0,G.default)(this.deleteMany(t,n)),t=[]}}}async*_all(e,t){throw new Error("._all is not implemented")}async*_allKeys(e,t){throw new Error("._allKeys is not implemented")}query(e,t){let n=this._all(e,t);if(e.prefix!=null&&(n=(0,z.default)(n,o=>o.key.toString().startsWith(e.prefix||""))),Array.isArray(e.filters)&&(n=e.filters.reduce((o,s)=>(0,z.default)(o,s),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((o,s)=>ye(o,s),n)),e.offset!=null){let o=0;n=(0,z.default)(n,()=>o++>=(e.offset||0))}return e.limit!=null&&(n=(0,Q.default)(n,e.limit)),n}queryKeys(e,t){let n=this._allKeys(e,t);if(e.prefix!=null&&(n=(0,z.default)(n,o=>o.toString().startsWith(e.prefix||""))),Array.isArray(e.filters)&&(n=e.filters.reduce((o,s)=>(0,z.default)(o,s),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((o,s)=>ye(o,s),n)),e.offset!=null){let o=0;n=(0,z.default)(n,()=>o++>=e.offset)}return e.limit!=null&&(n=(0,Q.default)(n,e.limit)),n}};function Ke(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,f=r.charAt(0),M=Math.log(c)/Math.log(256),l=Math.log(256)/Math.log(c);function O(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 h=0,S=0,y=0,w=a.length;y!==w&&a[y]===0;)y++,h++;for(var b=(w-y)*l+1>>>0,p=new Uint8Array(b);y!==w;){for(var g=a[y],A=0,m=b-1;(g!==0||A<S)&&m!==-1;m--,A++)g+=256*p[m]>>>0,p[m]=g%c>>>0,g=g/c>>>0;if(g!==0)throw new Error("Non-zero carry");S=A,y++}for(var v=b-S;v!==b&&p[v]===0;)v++;for(var R=f.repeat(h);v<b;++v)R+=r.charAt(p[v]);return R}function F(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var h=0;if(a[h]!==" "){for(var S=0,y=0;a[h]===f;)S++,h++;for(var w=(a.length-h)*M+1>>>0,b=new Uint8Array(w);a[h];){var p=t[a.charCodeAt(h)];if(p===255)return;for(var g=0,A=w-1;(p!==0||g<y)&&A!==-1;A--,g++)p+=c*b[A]>>>0,b[A]=p%256>>>0,p=p/256>>>0;if(p!==0)throw new Error("Non-zero carry");y=g,h++}if(a[h]!==" "){for(var m=w-y;m!==w&&b[m]===0;)m++;for(var v=new Uint8Array(S+(w-m)),R=S;m!==w;)v[R++]=b[m++];return v}}}function ke(a){var h=F(a);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:O,decodeUnsafe:F,decode:ke}}var _e=Ke,Je=_e,we=Je;var Ct=new Uint8Array(0);var be=(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},U=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 W=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")}},X=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 ge(this,e)}},Z=class{constructor(e){this.decoders=e}or(e){return ge(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`)}},ge=(r,e)=>new Z({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),H=class{constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new W(e,t,n),this.decoder=new X(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},xe=({name:r,prefix:e,encode:t,decode:n})=>new H(r,e,t,n),Y=({prefix:r,name:e,alphabet:t})=>{let{encode:n,decode:o}=we(t,e);return xe({prefix:r,name:e,encode:n,decode:s=>U(o(s))})},Ge=(r,e,t,n)=>{let o={};for(let l=0;l<e.length;++l)o[e[l]]=l;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),c=0,f=0,M=0;for(let l=0;l<s;++l){let O=o[r[l]];if(O===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<t|O,c+=t,c>=8&&(c-=8,i[M++]=255&f>>c)}if(c>=t||255&f<<8-c)throw new SyntaxError("Unexpected end of data");return i},Qe=(r,e,t)=>{let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,c=0;for(let f=0;f<r.length;++f)for(c=c<<8|r[f],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})=>xe({prefix:e,name:r,encode(o){return Qe(o,n,t)},decode(o){return Ge(o,n,t,r)}});var u=x({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Dt=x({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Lt=x({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Pt=x({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),jt=x({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ft=x({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Rt=x({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),$t=x({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),It=x({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var q=85;var Xe=Ae,ve=128,Ze=127,He=~Ze,Ye=Math.pow(2,31);function Ae(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Ye;)e[t++]=r&255|ve,r/=128;for(;r&He;)e[t++]=r&255|ve,r>>>=7;return e[t]=r|0,Ae.bytes=t-n+1,e}var qe=ee,et=128,Ee=127;function ee(r,n){var t=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw ee.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Ee)<<o:(i&Ee)*Math.pow(2,o),o+=7}while(i>=et);return ee.bytes=s-n,t}var tt=Math.pow(2,7),rt=Math.pow(2,14),nt=Math.pow(2,21),ot=Math.pow(2,28),st=Math.pow(2,35),it=Math.pow(2,42),at=Math.pow(2,49),ct=Math.pow(2,56),dt=Math.pow(2,63),ft=function(r){return r<tt?1:r<rt?2:r<nt?3:r<ot?4:r<st?5:r<it?6:r<at?7:r<ct?8:r<dt?9:10},ht={encode:Xe,decode:qe,encodingLength:ft},lt=ht,D=lt;var L=(r,e=0)=>[D.decode(r,e),D.decode.bytes],k=(r,e,t=0)=>(D.encode(r,e,t),e),N=r=>D.encodingLength(r);var ze=(r,e)=>{let t=e.byteLength,n=N(r),o=n+N(t),s=new Uint8Array(o+t);return k(r,s,0),k(t,s,n),s.set(e,o),new T(r,t,e,s)},P=r=>{let e=U(r),[t,n]=L(e),[o,s]=L(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new T(t,o,i,e)},Ue=(r,e)=>{if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&be(r.bytes,t.bytes)}},T=class{constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var E=Y({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xt=Y({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var pt=(r,e)=>{let{bytes:t,version:n}=r;switch(n){case 0:return yt(t,te(r),e||E.encoder);default:return mt(t,te(r),e||u.encoder)}},Oe=new WeakMap,te=r=>{let e=Oe.get(r);if(e==null){let t=new Map;return Oe.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.byteOffset=o.byteOffset,this.byteLength=o.byteLength,this.asCID=this}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==j)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==wt)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=ze(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&&Ue(e.multihash,n.multihash)}toString(e){return pt(this,e)}toJSON(){return{code:this.code,version:this.version,hash:this.multihash.bytes}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){let t=e;if(t instanceof d)return t;if(t!=null&&t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new d(n,o,s,i||Ce(n,o,s.bytes))}else if(t!=null&&t[bt]===!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");switch(e){case 0:{if(t!==j)throw new Error(`Version 0 CID must use dag-pb (code: ${j}) block encoding`);return new d(e,t,n,n.bytes)}case 1:{let o=Ce(e,t,n.bytes);return new d(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return d.create(0,j,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=U(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 T(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[O,F]=L(e.subarray(t));return t+=F,O},o=n(),s=j;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(),f=n(),M=t+f,l=M-i;return{version:o,codec:s,multihashCode:c,digestSize:f,multihashSize:l,size:M}}static parse(e,t){let[n,o]=ut(e,t),s=d.decode(o);return te(s).set(n,e),s}},ut=(r,e)=>{switch(r[0]){case"Q":{let t=e||E;return[E.prefix,t.decode(`${E.prefix}${r}`)]}case E.prefix:{let t=e||E;return[E.prefix,t.decode(r)]}case u.prefix:{let t=e||u;return[u.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)]}}},yt=(r,e,t)=>{let{prefix:n}=t;if(n!==E.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},mt=(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},j=112,wt=18,Ce=(r,e,t)=>{let n=N(r),o=n+N(e),s=new Uint8Array(o+t.byteLength);return k(r,s,0),k(e,s,n),s.set(t,o),s},bt=Symbol.for("@ipld/js-cid/CID");var K=class extends C{constructor(){super(),this.data={}}open(){return Promise.resolve()}close(){return Promise.resolve()}async put(e,t){this.data[u.encode(e.multihash.bytes)]=t}async get(e){if(!await this.has(e))throw J();return this.data[u.encode(e.multihash.bytes)]}async has(e){return this.data[u.encode(e.multihash.bytes)]!==void 0}async delete(e){delete this.data[u.encode(e.multihash.bytes)]}async*_all(){yield*Object.entries(this.data).map(([e,t])=>({key:d.createV1(q,P(u.decode(e))),value:t}))}async*_allKeys(){yield*Object.entries(this.data).map(([e])=>d.createV1(q,P(u.decode(e))))}};var gt={...I};return Le(xt);})(); | ||
return BlockstoreCore})); |
@@ -99,3 +99,3 @@ /** | ||
*/ | ||
queryKeys(q: KeyQuery, options?: import("interface-blockstore").Options | undefined): AsyncIterable<import("multiformats").CID>; | ||
queryKeys(q: KeyQuery, options?: import("interface-blockstore").Options | undefined): AsyncIterable<import("multiformats").CID<any, number, number, import("multiformats").Version>>; | ||
} | ||
@@ -102,0 +102,0 @@ export type Options = import('interface-blockstore').Options; |
@@ -31,6 +31,6 @@ /** | ||
_all(): AsyncGenerator<{ | ||
key: CID; | ||
key: CID<unknown, 85, number, 1>; | ||
value: Uint8Array; | ||
}, void, undefined>; | ||
_allKeys(): AsyncGenerator<CID, void, undefined>; | ||
_allKeys(): AsyncGenerator<CID<unknown, 85, number, 1>, void, undefined>; | ||
} | ||
@@ -37,0 +37,0 @@ export type Pair = import('interface-blockstore').Pair; |
{ | ||
"name": "blockstore-core", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Contains various implementations of the API contract described in interface-blockstore", | ||
@@ -180,3 +180,3 @@ "author": "Alex Potsides <alex.potsides@protocol.ai>", | ||
"it-take": "^1.0.1", | ||
"multiformats": "^9.4.7" | ||
"multiformats": "^10.0.0" | ||
}, | ||
@@ -183,0 +183,0 @@ "devDependencies": { |
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
37816
515
- Removedmultiformats@9.9.0(transitive)
Updatedmultiformats@^10.0.0