blockstore-idb
Advanced tools
Comparing version 1.0.1 to 1.0.2
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.BlockstoreIdb = factory()}(typeof self !== 'undefined' ? self : this, function () { | ||
"use strict";var BlockstoreIdb=(()=>{var Ve=Object.create;var q=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var je=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty;var qe=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ce=(t,e)=>{for(var r in e)q(t,r,{get:e[r],enumerable:!0})},de=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of _e(e))!$e.call(t,o)&&o!==r&&q(t,o,{get:()=>e[o],enumerable:!(n=Ne(e,o))||n.enumerable});return t};var We=(t,e,r)=>(r=t!=null?Ve(je(t)):{},de(e||!t||!t.__esModule?q(r,"default",{value:t,enumerable:!0}):r,t)),Ge=t=>de(q({},"__esModule",{value:!0}),t);var xe=qe((qt,ge)=>{"use strict";function me(t,e){for(let r in e)Object.defineProperty(t,r,{value:e[r],enumerable:!0,configurable:!0});return t}function rt(t,e,r){if(!t||typeof t=="string")throw new TypeError("Please pass an Error to err-code");r||(r={}),typeof e=="object"&&(r=e,e=""),e&&(r.code=e);try{return me(t,r)}catch{r.message=t.message,r.stack=t.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(t)),me(new o,r)}}ge.exports=rt});var Rt={};ce(Rt,{IDBBlockstore:()=>ae});var Je=(t,e)=>e.some(r=>t instanceof r),he,fe;function Ke(){return he||(he=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Qe(){return fe||(fe=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var le=new WeakMap,K=new WeakMap,ue=new WeakMap,J=new WeakMap,X=new WeakMap;function Xe(t){let e=new Promise((r,n)=>{let o=()=>{t.removeEventListener("success",s),t.removeEventListener("error",i)},s=()=>{r(y(t.result)),o()},i=()=>{n(t.error),o()};t.addEventListener("success",s),t.addEventListener("error",i)});return e.then(r=>{r instanceof IDBCursor&&le.set(r,t)}).catch(()=>{}),X.set(e,t),e}function He(t){if(K.has(t))return;let e=new Promise((r,n)=>{let o=()=>{t.removeEventListener("complete",s),t.removeEventListener("error",i),t.removeEventListener("abort",i)},s=()=>{r(),o()},i=()=>{n(t.error||new DOMException("AbortError","AbortError")),o()};t.addEventListener("complete",s),t.addEventListener("error",i),t.addEventListener("abort",i)});K.set(t,e)}var Q={get(t,e,r){if(t instanceof IDBTransaction){if(e==="done")return K.get(t);if(e==="objectStoreNames")return t.objectStoreNames||ue.get(t);if(e==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return y(t[e])},set(t,e,r){return t[e]=r,!0},has(t,e){return t instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in t}};function pe(t){Q=t(Q)}function Ze(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...r){let n=t.call(W(this),e,...r);return ue.set(n,e.sort?e.sort():[e]),y(n)}:Qe().includes(t)?function(...e){return t.apply(W(this),e),y(le.get(this))}:function(...e){return y(t.apply(W(this),e))}}function Ye(t){return typeof t=="function"?Ze(t):(t instanceof IDBTransaction&&He(t),Je(t,Ke())?new Proxy(t,Q):t)}function y(t){if(t instanceof IDBRequest)return Xe(t);if(J.has(t))return J.get(t);let e=Ye(t);return e!==t&&(J.set(t,e),X.set(e,t)),e}var W=t=>X.get(t);function be(t,e,{blocked:r,upgrade:n,blocking:o,terminated:s}={}){let i=indexedDB.open(t,e),a=y(i);return n&&i.addEventListener("upgradeneeded",c=>{n(y(i.result),c.oldVersion,c.newVersion,y(i.transaction),c)}),r&&i.addEventListener("blocked",c=>r(c.oldVersion,c.newVersion,c)),a.then(c=>{s&&c.addEventListener("close",()=>s()),o&&c.addEventListener("versionchange",f=>o(f.oldVersion,f.newVersion,f))}).catch(()=>{}),a}function ye(t,{blocked:e}={}){let r=indexedDB.deleteDatabase(t);return e&&r.addEventListener("blocked",n=>e(n.oldVersion,n)),y(r).then(()=>{})}var et=["get","getKey","getAll","getAllKeys","count"],tt=["put","add","delete","clear"],H=new Map;function we(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(H.get(e))return H.get(e);let r=e.replace(/FromIndex$/,""),n=e!==r,o=tt.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(o||et.includes(r)))return;let s=async function(i,...a){let c=this.transaction(i,o?"readwrite":"readonly"),f=c.store;return n&&(f=f.index(a.shift())),(await Promise.all([f[r](...a),o&&c.done]))[0]};return H.set(e,s),s}pe(t=>({...t,get:(e,r,n)=>we(e,r)||t.get(e,r,n),has:(e,r)=>!!we(e,r)||t.has(e,r)}));var G={};ce(G,{abortedError:()=>dt,closeFailedError:()=>ot,deleteFailedError:()=>at,getFailedError:()=>it,hasFailedError:()=>ct,notFoundError:()=>Ee,openFailedError:()=>nt,putFailedError:()=>st});var D=We(xe(),1);function nt(t){return t=t??new Error("Open failed"),(0,D.default)(t,"ERR_OPEN_FAILED")}function ot(t){return t=t??new Error("Close failed"),(0,D.default)(t,"ERR_CLOSE_FAILED")}function st(t){return t=t??new Error("Put failed"),(0,D.default)(t,"ERR_PUT_FAILED")}function it(t){return t=t??new Error("Get failed"),(0,D.default)(t,"ERR_GET_FAILED")}function at(t){return t=t??new Error("Delete failed"),(0,D.default)(t,"ERR_DELETE_FAILED")}function ct(t){return t=t??new Error("Has failed"),(0,D.default)(t,"ERR_HAS_FAILED")}function Ee(t){return t=t??new Error("Not Found"),(0,D.default)(t,"ERR_NOT_FOUND")}function dt(t){return t=t??new Error("Aborted"),(0,D.default)(t,"ERR_ABORTED")}var F=class{async has(e,r){return await Promise.reject(new Error(".has is not implemented"))}async put(e,r,n){await Promise.reject(new Error(".put is not implemented"))}async*putMany(e,r){for await(let{cid:n,block:o}of e)await this.put(n,o,r),yield{cid:n,block:o}}async get(e,r){return await Promise.reject(new Error(".get is not implemented"))}async*getMany(e,r){for await(let n of e)yield this.get(n,r)}async delete(e,r){await Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,r){for await(let n of e)await this.delete(n,r),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};function ht(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function C(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var l=0,S=0,w=0,m=d.length;w!==m&&d[w]===0;)w++,l++;for(var g=(m-w)*u+1>>>0,p=new Uint8Array(g);w!==m;){for(var x=d[w],B=0,b=g-1;(x!==0||B<S)&&b!==-1;b--,B++)x+=256*p[b]>>>0,p[b]=x%a>>>0,x=x/a>>>0;if(x!==0)throw new Error("Non-zero carry");S=B,w++}for(var v=g-S;v!==g&&p[v]===0;)v++;for(var $=c.repeat(l);v<g;++v)$+=t.charAt(p[v]);return $}function j(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var l=0;if(d[l]!==" "){for(var S=0,w=0;d[l]===c;)S++,l++;for(var m=(d.length-l)*f+1>>>0,g=new Uint8Array(m);d[l];){var p=r[d.charCodeAt(l)];if(p===255)return;for(var x=0,B=m-1;(p!==0||x<w)&&B!==-1;B--,x++)p+=a*g[B]>>>0,g[B]=p%256>>>0,p=p/256>>>0;if(p!==0)throw new Error("Non-zero carry");w=x,l++}if(d[l]!==" "){for(var b=m-w;b!==m&&g[b]===0;)b++;for(var v=new Uint8Array(S+(m-b)),$=S;b!==m;)v[$++]=g[b++];return v}}}function Re(d){var l=j(d);if(l)return l;throw new Error(`Non-${e} character`)}return{encode:C,decodeUnsafe:j,decode:Re}}var ft=ht,lt=ft,ve=lt;var Jt=new Uint8Array(0);var De=(t,e)=>{if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0},I=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")};var Z=class{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Y=class{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.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 Ae(this,e)}},ee=class{constructor(e){this.decoders=e}or(e){return Ae(this,e)}decode(e){let r=e[0],n=this.decoders[r];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`)}},Ae=(t,e)=>new ee({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),te=class{constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Z(e,r,n),this.decoder=new Y(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},Be=({name:t,prefix:e,encode:r,decode:n})=>new te(t,e,r,n),re=({prefix:t,name:e,alphabet:r})=>{let{encode:n,decode:o}=ve(r,e);return Be({prefix:t,name:e,encode:n,decode:s=>I(o(s))})},ut=(t,e,r,n)=>{let o={};for(let u=0;u<e.length;++u)o[e[u]]=u;let s=t.length;for(;t[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),a=0,c=0,f=0;for(let u=0;u<s;++u){let C=o[t[u]];if(C===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|C,a+=r,a>=8&&(a-=8,i[f++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i},pt=(t,e,r)=>{let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i&&(s+=e[o&a<<r-i]),n)for(;s.length*r&7;)s+="=";return s},E=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>Be({prefix:e,name:t,encode(o){return pt(o,n,r)},decode(o){return ut(o,n,r,t)}});var k=E({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Se=E({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Yt=E({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),er=E({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),tr=E({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),rr=E({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),nr=E({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),or=E({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),sr=E({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ne=85;var wt=Ce,Me=128,bt=127,yt=~bt,mt=Math.pow(2,31);function Ce(t,e,r){e=e||[],r=r||0;for(var n=r;t>=mt;)e[r++]=t&255|Me,t/=128;for(;t&yt;)e[r++]=t&255|Me,t>>>=7;return e[r]=t|0,Ce.bytes=r-n+1,e}var gt=oe,xt=128,Le=127;function oe(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw oe.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Le)<<o:(i&Le)*Math.pow(2,o),o+=7}while(i>=xt);return oe.bytes=s-n,r}var Et=Math.pow(2,7),vt=Math.pow(2,14),Dt=Math.pow(2,21),At=Math.pow(2,28),Bt=Math.pow(2,35),St=Math.pow(2,42),It=Math.pow(2,49),Mt=Math.pow(2,56),Lt=Math.pow(2,63),Ct=function(t){return t<Et?1:t<vt?2:t<Dt?3:t<At?4:t<Bt?5:t<St?6:t<It?7:t<Mt?8:t<Lt?9:10},Ft={encode:wt,decode:gt,encodingLength:Ct},kt=Ft,z=kt;var P=(t,e=0)=>[z.decode(t,e),z.decode.bytes],O=(t,e,r=0)=>(z.encode(t,e,r),e),T=t=>z.encodingLength(t);var ke=(t,e)=>{let r=e.byteLength,n=T(t),o=n+T(r),s=new Uint8Array(o+r);return O(t,s,0),O(r,s,n),s.set(e,o),new U(t,r,e,s)},R=t=>{let e=I(t),[r,n]=P(e),[o,s]=P(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new U(r,o,i,e)},Oe=(t,e)=>{if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&De(t.bytes,r.bytes)}},U=class{constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var A=re({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),lr=re({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Te=(t,e)=>{let{bytes:r,version:n}=t;switch(n){case 0:return Tt(r,ie(t),e||A.encoder);default:return Ut(r,ie(t),e||k.encoder)}};var Ue=new WeakMap,ie=t=>{let e=Ue.get(t);if(e==null){let r=new Map;return Ue.set(t,r),r}return e},h=class{constructor(e,r,n,o){this.code=r,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:r}=this;if(e!==V)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==zt)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return h.createV0(r)}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:r}=this.multihash,n=ke(e,r);return h.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 h.equals(this,e)}static equals(e,r){let n=r;return n&&e.code===n.code&&e.version===n.version&&Oe(e.multihash,n.multihash)}toString(e){return Te(this,e)}toJSON(){return{"/":Te(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 r=e;if(r instanceof h)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new h(n,o,s,i||ze(n,o,s.bytes))}else if(r[Pt]===!0){let{version:n,multihash:o,code:s}=r,i=R(o);return h.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="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(r!==V)throw new Error(`Version 0 CID must use dag-pb (code: ${V}) block encoding`);return new h(e,r,n,n.bytes)}case 1:{let o=ze(e,r,n.bytes);return new h(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return h.create(0,V,e)}static createV1(e,r){return h.create(1,e,r)}static decode(e){let[r,n]=h.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=h.inspectBytes(e),n=r.size-r.multihashSize,o=I(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new U(r.multihashCode,r.digestSize,s,o);return[r.version===0?h.createV0(i):h.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[C,j]=P(e.subarray(r));return r+=j,C},o=n(),s=V;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),f=r+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,r){let[n,o]=Ot(e,r),s=h.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ie(s).set(n,e),s}},Ot=(t,e)=>{switch(t[0]){case"Q":{let r=e||A;return[A.prefix,r.decode(`${A.prefix}${t}`)]}case A.prefix:{let r=e||A;return[A.prefix,r.decode(t)]}case k.prefix:{let r=e||k;return[k.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}},Tt=(t,e,r)=>{let{prefix:n}=r;if(n!==A.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o},Ut=(t,e,r)=>{let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o},V=112,zt=18,ze=(t,e,r)=>{let n=T(t),o=n+T(e),s=new Uint8Array(o+r.byteLength);return O(t,s,0),O(e,s,n),s.set(r,o),s},Pt=Symbol.for("@ipld/js-cid/CID");var M={...G};var N=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},L,_,Pe,ae=class extends F{constructor(e,r={}){super(),L.add(this),this.location=`${r.prefix??""}${e}`,this.version=r.version??1,this.base=r.base??Se}async open(){try{let e=this.location;this.db=await be(e,this.version,{upgrade(r){r.createObjectStore(e)}})}catch(e){throw M.openFailedError(e)}}async close(){this.db?.close()}async put(e,r){if(this.db==null)throw new Error("Blockstore needs to be opened.");try{await this.db.put(this.location,r,N(this,L,"m",_).call(this,e))}catch(n){throw M.putFailedError(n)}}async get(e){if(this.db==null)throw new Error("Blockstore needs to be opened.");let r;try{r=await this.db.get(this.location,N(this,L,"m",_).call(this,e))}catch(n){throw M.putFailedError(n)}if(r===void 0)throw M.notFoundError();return r}async delete(e){if(this.db==null)throw new Error("Blockstore needs to be opened.");try{await this.db.delete(this.location,N(this,L,"m",_).call(this,e))}catch(r){throw M.putFailedError(r)}}async has(e){if(this.db==null)throw new Error("Blockstore needs to be opened.");try{return!!await this.db.getKey(this.location,N(this,L,"m",_).call(this,e))}catch(r){throw M.putFailedError(r)}}async*getAll(e){if(this.db==null)throw new Error("Blockstore needs to be opened.");for(let r of await this.db.getAllKeys(this.location)){let n=N(this,L,"m",Pe).call(this,r.toString()),o=await this.get(n);yield{cid:n,block:o}}}async destroy(){await ye(this.location)}};L=new WeakSet,_=function(e){return`/${this.base.encoder.encode(e.multihash.bytes)}`},Pe=function(e){return h.createV1(ne,R(this.base.decoder.decode(e.substring(1))))};return Ge(Rt);})(); | ||
"use strict";var BlockstoreIdb=(()=>{var Ve=Object.create;var q=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var je=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty;var qe=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ce=(t,e)=>{for(var r in e)q(t,r,{get:e[r],enumerable:!0})},de=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of _e(e))!$e.call(t,o)&&o!==r&&q(t,o,{get:()=>e[o],enumerable:!(n=Ne(e,o))||n.enumerable});return t};var We=(t,e,r)=>(r=t!=null?Ve(je(t)):{},de(e||!t||!t.__esModule?q(r,"default",{value:t,enumerable:!0}):r,t)),Ge=t=>de(q({},"__esModule",{value:!0}),t);var xe=qe((qt,ge)=>{"use strict";function ye(t,e){for(let r in e)Object.defineProperty(t,r,{value:e[r],enumerable:!0,configurable:!0});return t}function rt(t,e,r){if(!t||typeof t=="string")throw new TypeError("Please pass an Error to err-code");r||(r={}),typeof e=="object"&&(r=e,e=""),e&&(r.code=e);try{return ye(t,r)}catch{r.message=t.message,r.stack=t.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(t)),ye(new o,r)}}ge.exports=rt});var Rt={};ce(Rt,{IDBBlockstore:()=>ae});var Je=(t,e)=>e.some(r=>t instanceof r),he,fe;function Ke(){return he||(he=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Qe(){return fe||(fe=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var le=new WeakMap,K=new WeakMap,ue=new WeakMap,J=new WeakMap,X=new WeakMap;function Xe(t){let e=new Promise((r,n)=>{let o=()=>{t.removeEventListener("success",s),t.removeEventListener("error",i)},s=()=>{r(m(t.result)),o()},i=()=>{n(t.error),o()};t.addEventListener("success",s),t.addEventListener("error",i)});return e.then(r=>{r instanceof IDBCursor&&le.set(r,t)}).catch(()=>{}),X.set(e,t),e}function He(t){if(K.has(t))return;let e=new Promise((r,n)=>{let o=()=>{t.removeEventListener("complete",s),t.removeEventListener("error",i),t.removeEventListener("abort",i)},s=()=>{r(),o()},i=()=>{n(t.error||new DOMException("AbortError","AbortError")),o()};t.addEventListener("complete",s),t.addEventListener("error",i),t.addEventListener("abort",i)});K.set(t,e)}var Q={get(t,e,r){if(t instanceof IDBTransaction){if(e==="done")return K.get(t);if(e==="objectStoreNames")return t.objectStoreNames||ue.get(t);if(e==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return m(t[e])},set(t,e,r){return t[e]=r,!0},has(t,e){return t instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in t}};function pe(t){Q=t(Q)}function Ze(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...r){let n=t.call(W(this),e,...r);return ue.set(n,e.sort?e.sort():[e]),m(n)}:Qe().includes(t)?function(...e){return t.apply(W(this),e),m(le.get(this))}:function(...e){return m(t.apply(W(this),e))}}function Ye(t){return typeof t=="function"?Ze(t):(t instanceof IDBTransaction&&He(t),Je(t,Ke())?new Proxy(t,Q):t)}function m(t){if(t instanceof IDBRequest)return Xe(t);if(J.has(t))return J.get(t);let e=Ye(t);return e!==t&&(J.set(t,e),X.set(e,t)),e}var W=t=>X.get(t);function be(t,e,{blocked:r,upgrade:n,blocking:o,terminated:s}={}){let i=indexedDB.open(t,e),a=m(i);return n&&i.addEventListener("upgradeneeded",c=>{n(m(i.result),c.oldVersion,c.newVersion,m(i.transaction),c)}),r&&i.addEventListener("blocked",c=>r(c.oldVersion,c.newVersion,c)),a.then(c=>{s&&c.addEventListener("close",()=>s()),o&&c.addEventListener("versionchange",f=>o(f.oldVersion,f.newVersion,f))}).catch(()=>{}),a}function me(t,{blocked:e}={}){let r=indexedDB.deleteDatabase(t);return e&&r.addEventListener("blocked",n=>e(n.oldVersion,n)),m(r).then(()=>{})}var et=["get","getKey","getAll","getAllKeys","count"],tt=["put","add","delete","clear"],H=new Map;function we(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(H.get(e))return H.get(e);let r=e.replace(/FromIndex$/,""),n=e!==r,o=tt.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(o||et.includes(r)))return;let s=async function(i,...a){let c=this.transaction(i,o?"readwrite":"readonly"),f=c.store;return n&&(f=f.index(a.shift())),(await Promise.all([f[r](...a),o&&c.done]))[0]};return H.set(e,s),s}pe(t=>({...t,get:(e,r,n)=>we(e,r)||t.get(e,r,n),has:(e,r)=>!!we(e,r)||t.has(e,r)}));var G={};ce(G,{abortedError:()=>dt,closeFailedError:()=>ot,deleteFailedError:()=>at,getFailedError:()=>it,hasFailedError:()=>ct,notFoundError:()=>Ee,openFailedError:()=>nt,putFailedError:()=>st});var D=We(xe(),1);function nt(t){return t=t??new Error("Open failed"),(0,D.default)(t,"ERR_OPEN_FAILED")}function ot(t){return t=t??new Error("Close failed"),(0,D.default)(t,"ERR_CLOSE_FAILED")}function st(t){return t=t??new Error("Put failed"),(0,D.default)(t,"ERR_PUT_FAILED")}function it(t){return t=t??new Error("Get failed"),(0,D.default)(t,"ERR_GET_FAILED")}function at(t){return t=t??new Error("Delete failed"),(0,D.default)(t,"ERR_DELETE_FAILED")}function ct(t){return t=t??new Error("Has failed"),(0,D.default)(t,"ERR_HAS_FAILED")}function Ee(t){return t=t??new Error("Not Found"),(0,D.default)(t,"ERR_NOT_FOUND")}function dt(t){return t=t??new Error("Aborted"),(0,D.default)(t,"ERR_ABORTED")}var F=class{has(e,r){return Promise.reject(new Error(".has is not implemented"))}put(e,r,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,r){for await(let{cid:n,block:o}of e)await this.put(n,o,r),yield n}get(e,r){return Promise.reject(new Error(".get is not implemented"))}async*getMany(e,r){for await(let n of e)yield{cid:n,block:await this.get(n,r)}}async delete(e,r){await Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,r){for await(let n of e)await this.delete(n,r),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};function ht(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function C(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var l=0,S=0,w=0,y=d.length;w!==y&&d[w]===0;)w++,l++;for(var g=(y-w)*u+1>>>0,p=new Uint8Array(g);w!==y;){for(var x=d[w],B=0,b=g-1;(x!==0||B<S)&&b!==-1;b--,B++)x+=256*p[b]>>>0,p[b]=x%a>>>0,x=x/a>>>0;if(x!==0)throw new Error("Non-zero carry");S=B,w++}for(var v=g-S;v!==g&&p[v]===0;)v++;for(var $=c.repeat(l);v<g;++v)$+=t.charAt(p[v]);return $}function j(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var l=0;if(d[l]!==" "){for(var S=0,w=0;d[l]===c;)S++,l++;for(var y=(d.length-l)*f+1>>>0,g=new Uint8Array(y);d[l];){var p=r[d.charCodeAt(l)];if(p===255)return;for(var x=0,B=y-1;(p!==0||x<w)&&B!==-1;B--,x++)p+=a*g[B]>>>0,g[B]=p%256>>>0,p=p/256>>>0;if(p!==0)throw new Error("Non-zero carry");w=x,l++}if(d[l]!==" "){for(var b=y-w;b!==y&&g[b]===0;)b++;for(var v=new Uint8Array(S+(y-b)),$=S;b!==y;)v[$++]=g[b++];return v}}}function Re(d){var l=j(d);if(l)return l;throw new Error(`Non-${e} character`)}return{encode:C,decodeUnsafe:j,decode:Re}}var ft=ht,lt=ft,ve=lt;var Jt=new Uint8Array(0);var De=(t,e)=>{if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0},I=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")};var Z=class{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Y=class{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.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 Ae(this,e)}},ee=class{constructor(e){this.decoders=e}or(e){return Ae(this,e)}decode(e){let r=e[0],n=this.decoders[r];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`)}},Ae=(t,e)=>new ee({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),te=class{constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Z(e,r,n),this.decoder=new Y(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},Be=({name:t,prefix:e,encode:r,decode:n})=>new te(t,e,r,n),re=({prefix:t,name:e,alphabet:r})=>{let{encode:n,decode:o}=ve(r,e);return Be({prefix:t,name:e,encode:n,decode:s=>I(o(s))})},ut=(t,e,r,n)=>{let o={};for(let u=0;u<e.length;++u)o[e[u]]=u;let s=t.length;for(;t[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),a=0,c=0,f=0;for(let u=0;u<s;++u){let C=o[t[u]];if(C===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|C,a+=r,a>=8&&(a-=8,i[f++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i},pt=(t,e,r)=>{let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i&&(s+=e[o&a<<r-i]),n)for(;s.length*r&7;)s+="=";return s},E=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>Be({prefix:e,name:t,encode(o){return pt(o,n,r)},decode(o){return ut(o,n,r,t)}});var k=E({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Se=E({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Yt=E({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),er=E({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),tr=E({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),rr=E({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),nr=E({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),or=E({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),sr=E({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ne=85;var wt=Ce,Me=128,bt=127,mt=~bt,yt=Math.pow(2,31);function Ce(t,e,r){e=e||[],r=r||0;for(var n=r;t>=yt;)e[r++]=t&255|Me,t/=128;for(;t&mt;)e[r++]=t&255|Me,t>>>=7;return e[r]=t|0,Ce.bytes=r-n+1,e}var gt=oe,xt=128,Le=127;function oe(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw oe.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Le)<<o:(i&Le)*Math.pow(2,o),o+=7}while(i>=xt);return oe.bytes=s-n,r}var Et=Math.pow(2,7),vt=Math.pow(2,14),Dt=Math.pow(2,21),At=Math.pow(2,28),Bt=Math.pow(2,35),St=Math.pow(2,42),It=Math.pow(2,49),Mt=Math.pow(2,56),Lt=Math.pow(2,63),Ct=function(t){return t<Et?1:t<vt?2:t<Dt?3:t<At?4:t<Bt?5:t<St?6:t<It?7:t<Mt?8:t<Lt?9:10},Ft={encode:wt,decode:gt,encodingLength:Ct},kt=Ft,z=kt;var P=(t,e=0)=>[z.decode(t,e),z.decode.bytes],O=(t,e,r=0)=>(z.encode(t,e,r),e),T=t=>z.encodingLength(t);var ke=(t,e)=>{let r=e.byteLength,n=T(t),o=n+T(r),s=new Uint8Array(o+r);return O(t,s,0),O(r,s,n),s.set(e,o),new U(t,r,e,s)},R=t=>{let e=I(t),[r,n]=P(e),[o,s]=P(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new U(r,o,i,e)},Oe=(t,e)=>{if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&De(t.bytes,r.bytes)}},U=class{constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var A=re({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),lr=re({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Te=(t,e)=>{let{bytes:r,version:n}=t;switch(n){case 0:return Tt(r,ie(t),e||A.encoder);default:return Ut(r,ie(t),e||k.encoder)}};var Ue=new WeakMap,ie=t=>{let e=Ue.get(t);if(e==null){let r=new Map;return Ue.set(t,r),r}return e},h=class{constructor(e,r,n,o){this.code=r,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:r}=this;if(e!==V)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==zt)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return h.createV0(r)}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:r}=this.multihash,n=ke(e,r);return h.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 h.equals(this,e)}static equals(e,r){let n=r;return n&&e.code===n.code&&e.version===n.version&&Oe(e.multihash,n.multihash)}toString(e){return Te(this,e)}toJSON(){return{"/":Te(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 r=e;if(r instanceof h)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new h(n,o,s,i||ze(n,o,s.bytes))}else if(r[Pt]===!0){let{version:n,multihash:o,code:s}=r,i=R(o);return h.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="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(r!==V)throw new Error(`Version 0 CID must use dag-pb (code: ${V}) block encoding`);return new h(e,r,n,n.bytes)}case 1:{let o=ze(e,r,n.bytes);return new h(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return h.create(0,V,e)}static createV1(e,r){return h.create(1,e,r)}static decode(e){let[r,n]=h.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=h.inspectBytes(e),n=r.size-r.multihashSize,o=I(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new U(r.multihashCode,r.digestSize,s,o);return[r.version===0?h.createV0(i):h.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[C,j]=P(e.subarray(r));return r+=j,C},o=n(),s=V;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),f=r+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,r){let[n,o]=Ot(e,r),s=h.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ie(s).set(n,e),s}},Ot=(t,e)=>{switch(t[0]){case"Q":{let r=e||A;return[A.prefix,r.decode(`${A.prefix}${t}`)]}case A.prefix:{let r=e||A;return[A.prefix,r.decode(t)]}case k.prefix:{let r=e||k;return[k.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}},Tt=(t,e,r)=>{let{prefix:n}=r;if(n!==A.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o},Ut=(t,e,r)=>{let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o},V=112,zt=18,ze=(t,e,r)=>{let n=T(t),o=n+T(e),s=new Uint8Array(o+r.byteLength);return O(t,s,0),O(e,s,n),s.set(r,o),s},Pt=Symbol.for("@ipld/js-cid/CID");var M={...G};var N=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},L,_,Pe,ae=class extends F{constructor(e,r={}){super(),L.add(this),this.location=`${r.prefix??""}${e}`,this.version=r.version??1,this.base=r.base??Se}async open(){try{let e=this.location;this.db=await be(e,this.version,{upgrade(r){r.createObjectStore(e)}})}catch(e){throw M.openFailedError(e)}}async close(){this.db?.close()}async put(e,r){if(this.db==null)throw new Error("Blockstore needs to be opened.");try{return await this.db.put(this.location,r,N(this,L,"m",_).call(this,e)),e}catch(n){throw M.putFailedError(n)}}async get(e){if(this.db==null)throw new Error("Blockstore needs to be opened.");let r;try{r=await this.db.get(this.location,N(this,L,"m",_).call(this,e))}catch(n){throw M.putFailedError(n)}if(r===void 0)throw M.notFoundError();return r}async delete(e){if(this.db==null)throw new Error("Blockstore needs to be opened.");try{await this.db.delete(this.location,N(this,L,"m",_).call(this,e))}catch(r){throw M.putFailedError(r)}}async has(e){if(this.db==null)throw new Error("Blockstore needs to be opened.");try{return!!await this.db.getKey(this.location,N(this,L,"m",_).call(this,e))}catch(r){throw M.putFailedError(r)}}async*getAll(e){if(this.db==null)throw new Error("Blockstore needs to be opened.");for(let r of await this.db.getAllKeys(this.location)){let n=N(this,L,"m",Pe).call(this,r.toString()),o=await this.get(n);yield{cid:n,block:o}}}async destroy(){await me(this.location)}};L=new WeakSet,_=function(e){return`/${this.base.encoder.encode(e.multihash.bytes)}`},Pe=function(e){return h.createV1(ne,R(this.base.decoder.decode(e.substring(1))))};return Ge(Rt);})(); | ||
return BlockstoreIdb})); |
import { BaseBlockstore } from 'blockstore-core'; | ||
import { CID } from 'multiformats/cid'; | ||
import type { MultibaseCodec } from 'multiformats/bases/interface'; | ||
import type { Options, Pair } from 'interface-blockstore'; | ||
import type { AwaitIterable } from 'interface-store'; | ||
import type { Pair } from 'interface-blockstore'; | ||
import type { AbortOptions, AwaitIterable } from 'interface-store'; | ||
export interface IDBDatastoreInit { | ||
@@ -30,9 +30,9 @@ /** | ||
close(): Promise<void>; | ||
put(key: CID, val: Uint8Array): Promise<void>; | ||
put(key: CID, val: Uint8Array): Promise<CID>; | ||
get(key: CID): Promise<Uint8Array>; | ||
delete(key: CID): Promise<void>; | ||
has(key: CID): Promise<boolean>; | ||
getAll(options?: Options): AwaitIterable<Pair>; | ||
getAll(options?: AbortOptions): AwaitIterable<Pair>; | ||
destroy(): Promise<void>; | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
@@ -44,2 +44,3 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
await this.db.put(this.location, val, __classPrivateFieldGet(this, _IDBBlockstore_instances, "m", _IDBBlockstore_encode).call(this, key)); | ||
return key; | ||
} | ||
@@ -46,0 +47,0 @@ catch (err) { |
{ | ||
"name": "blockstore-idb", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Blockstore implementation with IndexedDB backend", | ||
@@ -145,6 +145,6 @@ "license": "Apache-2.0 OR MIT", | ||
"dependencies": { | ||
"blockstore-core": "^4.0.0", | ||
"blockstore-core": "^4.0.2", | ||
"idb": "^7.1.1", | ||
"interface-blockstore": "^5.0.0", | ||
"interface-store": "^4.0.0", | ||
"interface-blockstore": "^5.1.1", | ||
"interface-store": "^5.0.1", | ||
"multiformats": "^11.0.2" | ||
@@ -154,4 +154,4 @@ }, | ||
"aegir": "^38.1.7", | ||
"interface-blockstore-tests": "^5.0.0" | ||
"interface-blockstore-tests": "^6.0.0" | ||
} | ||
} |
@@ -11,4 +11,4 @@ import { openDB, IDBPDatabase, deleteDB } from 'idb' | ||
import * as Digest from 'multiformats/hashes/digest' | ||
import type { Options, Pair } from 'interface-blockstore' | ||
import type { AwaitIterable } from 'interface-store' | ||
import type { Pair } from 'interface-blockstore' | ||
import type { AbortOptions, AwaitIterable } from 'interface-store' | ||
@@ -75,3 +75,3 @@ export interface IDBDatastoreInit { | ||
async put (key: CID, val: Uint8Array): Promise<void> { | ||
async put (key: CID, val: Uint8Array): Promise<CID> { | ||
if (this.db == null) { | ||
@@ -83,2 +83,4 @@ throw new Error('Blockstore needs to be opened.') | ||
await this.db.put(this.location, val, this.#encode(key)) | ||
return key | ||
} catch (err: any) { | ||
@@ -133,3 +135,3 @@ throw Errors.putFailedError(err) | ||
async * getAll (options?: Options): AwaitIterable<Pair> { | ||
async * getAll (options?: AbortOptions): AwaitIterable<Pair> { | ||
if (this.db == null) { | ||
@@ -136,0 +138,0 @@ throw new Error('Blockstore needs to be opened.') |
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
38474
336
- Removedinterface-store@4.1.0(transitive)
Updatedblockstore-core@^4.0.2
Updatedinterface-blockstore@^5.1.1
Updatedinterface-store@^5.0.1