blockstore-idb
Advanced tools
Comparing version 1.1.0 to 1.1.1
(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 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);})(); | ||
"use strict";var BlockstoreIdb=(()=>{var Ue=Object.create;var j=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var Ve=Object.getPrototypeOf,Ne=Object.prototype.hasOwnProperty;var Pe=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),se=(t,e)=>{for(var r in e)j(t,r,{get:e[r],enumerable:!0})},ie=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Re(e))!Ne.call(t,o)&&o!==r&&j(t,o,{get:()=>e[o],enumerable:!(n=ze(e,o))||n.enumerable});return t};var je=(t,e,r)=>(r=t!=null?Ue(Ve(t)):{},ie(e||!t||!t.__esModule?j(r,"default",{value:t,enumerable:!0}):r,t)),$e=t=>ie(j({},"__esModule",{value:!0}),t);var de=Pe((zt,ce)=>{"use strict";function ae(t,e){for(let r in e)Object.defineProperty(t,r,{value:e[r],enumerable:!0,configurable:!0});return t}function _e(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 ae(t,r)}catch{r.message=t.message,r.stack=t.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(t)),ae(new o,r)}}ce.exports=_e});var Tt={};se(Tt,{IDBBlockstore:()=>oe});var $={};se($,{abortedError:()=>Xe,closeFailedError:()=>Je,deleteFailedError:()=>Ge,getFailedError:()=>We,hasFailedError:()=>Qe,notFoundError:()=>he,openFailedError:()=>qe,putFailedError:()=>Ke});var A=je(de(),1);function qe(t){return t=t??new Error("Open failed"),(0,A.default)(t,"ERR_OPEN_FAILED")}function Je(t){return t=t??new Error("Close failed"),(0,A.default)(t,"ERR_CLOSE_FAILED")}function Ke(t){return t=t??new Error("Put failed"),(0,A.default)(t,"ERR_PUT_FAILED")}function We(t){return t=t??new Error("Get failed"),(0,A.default)(t,"ERR_GET_FAILED")}function Ge(t){return t=t??new Error("Delete failed"),(0,A.default)(t,"ERR_DELETE_FAILED")}function Qe(t){return t=t??new Error("Has failed"),(0,A.default)(t,"ERR_HAS_FAILED")}function he(t){return t=t??new Error("Not Found"),(0,A.default)(t,"ERR_NOT_FOUND")}function Xe(t){return t=t??new Error("Aborted"),(0,A.default)(t,"ERR_ABORTED")}var C=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 He(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),l=Math.log(256)/Math.log(a);function L(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 u=0,B=0,w=0,y=d.length;w!==y&&d[w]===0;)w++,u++;for(var g=(y-w)*l+1>>>0,p=new Uint8Array(g);w!==y;){for(var x=d[w],S=0,b=g-1;(x!==0||S<B)&&b!==-1;b--,S++)x+=256*p[b]>>>0,p[b]=x%a>>>0,x=x/a>>>0;if(x!==0)throw new Error("Non-zero carry");B=S,w++}for(var v=g-B;v!==g&&p[v]===0;)v++;for(var P=c.repeat(u);v<g;++v)P+=t.charAt(p[v]);return P}function N(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var u=0;if(d[u]!==" "){for(var B=0,w=0;d[u]===c;)B++,u++;for(var y=(d.length-u)*f+1>>>0,g=new Uint8Array(y);d[u];){var p=r[d.charCodeAt(u)];if(p===255)return;for(var x=0,S=y-1;(p!==0||x<w)&&S!==-1;S--,x++)p+=a*g[S]>>>0,g[S]=p%256>>>0,p=p/256>>>0;if(p!==0)throw new Error("Non-zero carry");w=x,u++}if(d[u]!==" "){for(var b=y-w;b!==y&&g[b]===0;)b++;for(var v=new Uint8Array(B+(y-b)),P=B;b!==y;)v[P++]=g[b++];return v}}}function Te(d){var u=N(d);if(u)return u;throw new Error(`Non-${e} character`)}return{encode:L,decodeUnsafe:N,decode:Te}}var Ze=He,Ye=Ze,fe=Ye;var Nt=new Uint8Array(0);var ue=(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 q=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")}},J=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 le(this,e)}},K=class{constructor(e){this.decoders=e}or(e){return le(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`)}},le=(t,e)=>new K({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),W=class{constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new q(e,r,n),this.decoder=new J(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},pe=({name:t,prefix:e,encode:r,decode:n})=>new W(t,e,r,n),G=({prefix:t,name:e,alphabet:r})=>{let{encode:n,decode:o}=fe(r,e);return pe({prefix:t,name:e,encode:n,decode:s=>I(o(s))})},et=(t,e,r,n)=>{let o={};for(let l=0;l<e.length;++l)o[e[l]]=l;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 l=0;l<s;++l){let L=o[t[l]];if(L===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|L,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},tt=(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})=>pe({prefix:e,name:t,encode(o){return tt(o,n,r)},decode(o){return et(o,n,r,t)}});var F=E({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),we=E({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Jt=E({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Kt=E({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wt=E({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Gt=E({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Qt=E({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Xt=E({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ht=E({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var rt=ye,be=128,nt=127,ot=~nt,st=Math.pow(2,31);function ye(t,e,r){e=e||[],r=r||0;for(var n=r;t>=st;)e[r++]=t&255|be,t/=128;for(;t&ot;)e[r++]=t&255|be,t>>>=7;return e[r]=t|0,ye.bytes=r-n+1,e}var it=Q,at=128,me=127;function Q(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Q.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&me)<<o:(i&me)*Math.pow(2,o),o+=7}while(i>=at);return Q.bytes=s-n,r}var ct=Math.pow(2,7),dt=Math.pow(2,14),ht=Math.pow(2,21),ft=Math.pow(2,28),ut=Math.pow(2,35),lt=Math.pow(2,42),pt=Math.pow(2,49),wt=Math.pow(2,56),bt=Math.pow(2,63),mt=function(t){return t<ct?1:t<dt?2:t<ht?3:t<ft?4:t<ut?5:t<lt?6:t<pt?7:t<wt?8:t<bt?9:10},yt={encode:rt,decode:it,encodingLength:mt},gt=yt,U=gt;var z=(t,e=0)=>[U.decode(t,e),U.decode.bytes],O=(t,e,r=0)=>(U.encode(t,e,r),e),k=t=>U.encodingLength(t);var xe=(t,e)=>{let r=e.byteLength,n=k(t),o=n+k(r),s=new Uint8Array(o+r);return O(t,s,0),O(r,s,n),s.set(e,o),new T(t,r,e,s)},R=t=>{let e=I(t),[r,n]=z(e),[o,s]=z(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new T(r,o,i,e)},Ee=(t,e)=>{if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ue(t.bytes,r.bytes)}},T=class{constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var D=G({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),nr=G({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ve=(t,e)=>{let{bytes:r,version:n}=t;switch(n){case 0:return Et(r,H(t),e||D.encoder);default:return vt(r,H(t),e||F.encoder)}};var Ae=new WeakMap,H=t=>{let e=Ae.get(t);if(e==null){let r=new Map;return Ae.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!==At)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=xe(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&&Ee(e.multihash,n.multihash)}toString(e){return ve(this,e)}toJSON(){return{"/":ve(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||De(n,o,s.bytes))}else if(r[Dt]===!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=De(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 T(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[L,N]=z(e.subarray(r));return r+=N,L},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,l=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:f}}static parse(e,r){let[n,o]=xt(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 H(s).set(n,e),s}},xt=(t,e)=>{switch(t[0]){case"Q":{let r=e||D;return[D.prefix,r.decode(`${D.prefix}${t}`)]}case D.prefix:{let r=e||D;return[D.prefix,r.decode(t)]}case F.prefix:{let r=e||F;return[F.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)]}}},Et=(t,e,r)=>{let{prefix:n}=r;if(n!==D.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},vt=(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,At=18,De=(t,e,r)=>{let n=k(t),o=n+k(e),s=new Uint8Array(o+r.byteLength);return O(t,s,0),O(e,s,n),s.set(r,o),s},Dt=Symbol.for("@ipld/js-cid/CID");var Z=85;var M={...$};var St=(t,e)=>e.some(r=>t instanceof r),Be,Ie;function Bt(){return Be||(Be=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function It(){return Ie||(Ie=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var Me=new WeakMap,ee=new WeakMap,Le=new WeakMap,Y=new WeakMap,re=new WeakMap;function Mt(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&&Me.set(r,t)}).catch(()=>{}),re.set(e,t),e}function Lt(t){if(ee.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)});ee.set(t,e)}var te={get(t,e,r){if(t instanceof IDBTransaction){if(e==="done")return ee.get(t);if(e==="objectStoreNames")return t.objectStoreNames||Le.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 Ce(t){te=t(te)}function Ct(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...r){let n=t.call(_(this),e,...r);return Le.set(n,e.sort?e.sort():[e]),m(n)}:It().includes(t)?function(...e){return t.apply(_(this),e),m(Me.get(this))}:function(...e){return m(t.apply(_(this),e))}}function Ft(t){return typeof t=="function"?Ct(t):(t instanceof IDBTransaction&&Lt(t),St(t,Bt())?new Proxy(t,te):t)}function m(t){if(t instanceof IDBRequest)return Mt(t);if(Y.has(t))return Y.get(t);let e=Ft(t);return e!==t&&(Y.set(t,e),re.set(e,t)),e}var _=t=>re.get(t);function Oe(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 ke(t,{blocked:e}={}){let r=indexedDB.deleteDatabase(t);return e&&r.addEventListener("blocked",n=>e(n.oldVersion,n)),m(r).then(()=>{})}var Ot=["get","getKey","getAll","getAllKeys","count"],kt=["put","add","delete","clear"],ne=new Map;function Fe(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(ne.get(e))return ne.get(e);let r=e.replace(/FromIndex$/,""),n=e!==r,o=kt.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(o||Ot.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 ne.set(e,s),s}Ce(t=>({...t,get:(e,r,n)=>Fe(e,r)||t.get(e,r,n),has:(e,r)=>!!Fe(e,r)||t.has(e,r)}));var oe=class extends C{location;version;db;base;constructor(e,r={}){super(),this.location=`${r.prefix??""}${e}`,this.version=r.version??1,this.base=r.base??we}#e(e){return`/${this.base.encoder.encode(e.multihash.bytes)}`}#t(e){return h.createV1(Z,R(this.base.decoder.decode(e.substring(1))))}async open(){try{let e=this.location;this.db=await Oe(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,this.#e(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,this.#e(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,this.#e(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,this.#e(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=this.#t(r.toString()),o=await this.get(n);yield{cid:n,block:o}}}async destroy(){await ke(this.location)}};return $e(Tt);})(); | ||
return BlockstoreIdb})); |
import { BaseBlockstore } from 'blockstore-core'; | ||
import { CID } from 'multiformats/cid'; | ||
import type { MultibaseCodec } from 'multiformats/bases/interface'; | ||
import type { Pair } from 'interface-blockstore'; | ||
import type { AbortOptions, AwaitIterable } from 'interface-store'; | ||
import type { MultibaseCodec } from 'multiformats/bases/interface'; | ||
export interface IDBDatastoreInit { | ||
@@ -7,0 +7,0 @@ /** |
@@ -1,17 +0,14 @@ | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var _IDBBlockstore_instances, _IDBBlockstore_encode, _IDBBlockstore_decode; | ||
import { BaseBlockstore, Errors } from 'blockstore-core'; | ||
import { openDB, deleteDB } from 'idb'; | ||
import { BaseBlockstore, Errors } from 'blockstore-core'; | ||
import { base32upper } from 'multiformats/bases/base32'; | ||
import { CID } from 'multiformats/cid'; | ||
import { base32upper } from 'multiformats/bases/base32'; | ||
import * as raw from 'multiformats/codecs/raw'; | ||
import * as Digest from 'multiformats/hashes/digest'; | ||
export class IDBBlockstore extends BaseBlockstore { | ||
location; | ||
version; | ||
db; | ||
base; | ||
constructor(location, init = {}) { | ||
super(); | ||
_IDBBlockstore_instances.add(this); | ||
this.location = `${init.prefix ?? ''}${location}`; | ||
@@ -22,2 +19,8 @@ this.version = init.version ?? 1; | ||
} | ||
#encode(cid) { | ||
return `/${this.base.encoder.encode(cid.multihash.bytes)}`; | ||
} | ||
#decode(key) { | ||
return CID.createV1(raw.code, Digest.decode(this.base.decoder.decode(key.substring(1)))); | ||
} | ||
async open() { | ||
@@ -44,3 +47,3 @@ try { | ||
try { | ||
await this.db.put(this.location, val, __classPrivateFieldGet(this, _IDBBlockstore_instances, "m", _IDBBlockstore_encode).call(this, key)); | ||
await this.db.put(this.location, val, this.#encode(key)); | ||
return key; | ||
@@ -58,3 +61,3 @@ } | ||
try { | ||
val = await this.db.get(this.location, __classPrivateFieldGet(this, _IDBBlockstore_instances, "m", _IDBBlockstore_encode).call(this, key)); | ||
val = await this.db.get(this.location, this.#encode(key)); | ||
} | ||
@@ -74,3 +77,3 @@ catch (err) { | ||
try { | ||
await this.db.delete(this.location, __classPrivateFieldGet(this, _IDBBlockstore_instances, "m", _IDBBlockstore_encode).call(this, key)); | ||
await this.db.delete(this.location, this.#encode(key)); | ||
} | ||
@@ -86,3 +89,3 @@ catch (err) { | ||
try { | ||
return Boolean(await this.db.getKey(this.location, __classPrivateFieldGet(this, _IDBBlockstore_instances, "m", _IDBBlockstore_encode).call(this, key))); | ||
return Boolean(await this.db.getKey(this.location, this.#encode(key))); | ||
} | ||
@@ -98,3 +101,3 @@ catch (err) { | ||
for (const key of await this.db.getAllKeys(this.location)) { | ||
const cid = __classPrivateFieldGet(this, _IDBBlockstore_instances, "m", _IDBBlockstore_decode).call(this, key.toString()); // eslint-disable-line @typescript-eslint/no-base-to-string | ||
const cid = this.#decode(key.toString()); // eslint-disable-line @typescript-eslint/no-base-to-string | ||
const block = await this.get(cid); | ||
@@ -108,7 +111,2 @@ yield { cid, block }; | ||
} | ||
_IDBBlockstore_instances = new WeakSet(), _IDBBlockstore_encode = function _IDBBlockstore_encode(cid) { | ||
return `/${this.base.encoder.encode(cid.multihash.bytes)}`; | ||
}, _IDBBlockstore_decode = function _IDBBlockstore_decode(key) { | ||
return CID.createV1(raw.code, Digest.decode(this.base.decoder.decode(key.substring(1)))); | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "blockstore-idb", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Blockstore implementation with IndexedDB backend", | ||
@@ -48,3 +48,3 @@ "license": "Apache-2.0 OR MIT", | ||
"branches": [ | ||
"master" | ||
"main" | ||
], | ||
@@ -153,3 +153,3 @@ "plugins": [ | ||
"devDependencies": { | ||
"aegir": "^38.1.7", | ||
"aegir": "^39.0.9", | ||
"interface-blockstore-tests": "^6.0.0" | ||
@@ -156,0 +156,0 @@ }, |
@@ -6,3 +6,3 @@ # blockstore-idb <!-- omit in toc --> | ||
[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-stores.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-stores) | ||
[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-stores/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/ipfs/js-stores/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) | ||
[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-stores/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/ipfs/js-stores/actions/workflows/js-test-and-release.yml?query=branch%3Amain) | ||
@@ -9,0 +9,0 @@ > Blockstore implementation with IndexedDB backend |
@@ -1,2 +0,1 @@ | ||
import { openDB, IDBPDatabase, deleteDB } from 'idb' | ||
import { | ||
@@ -6,5 +5,5 @@ BaseBlockstore, | ||
} from 'blockstore-core' | ||
import { openDB, type IDBPDatabase, deleteDB } from 'idb' | ||
import { base32upper } from 'multiformats/bases/base32' | ||
import { CID } from 'multiformats/cid' | ||
import type { MultibaseCodec } from 'multiformats/bases/interface' | ||
import { base32upper } from 'multiformats/bases/base32' | ||
import * as raw from 'multiformats/codecs/raw' | ||
@@ -14,2 +13,3 @@ import * as Digest from 'multiformats/hashes/digest' | ||
import type { AbortOptions, AwaitIterable } from 'interface-store' | ||
import type { MultibaseCodec } from 'multiformats/bases/interface' | ||
@@ -16,0 +16,0 @@ export interface IDBDatastoreInit { |
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
37020
333