Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

datastore-core

Package Overview
Dependencies
Maintainers
3
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datastore-core - npm Package Compare versions

Comparing version 7.0.0 to 7.0.1

4

cjs/src/index.js

@@ -15,4 +15,4 @@ 'use strict';

const Errors = { ...errors };
const shard = { ...shard$1 };
const Errors = errors;
const shard = shard$1;

@@ -19,0 +19,0 @@ exports.BaseDatastore = base.BaseDatastore;

@@ -8,23 +8,8 @@ export { BaseDatastore } from "./base.js";

export { NamespaceDatastore } from "./namespace.js";
export const Errors: {
dbOpenFailedError(err?: Error | undefined): Error & import("err-code").Extensions;
dbDeleteFailedError(err?: Error | undefined): Error & import("err-code").Extensions;
dbWriteFailedError(err?: Error | undefined): Error & import("err-code").Extensions;
notFoundError(err?: Error | undefined): Error & import("err-code").Extensions;
abortedError(err?: Error | undefined): Error & import("err-code").Extensions;
};
export const shard: {
parseShardFun(str: string): import("./types").Shard;
PREFIX: "/repo/flatfs/shard/";
SHARDING_FN: "SHARDING";
README_FN: "_README";
ShardBase: typeof ShardImport.ShardBase;
Prefix: typeof ShardImport.Prefix;
Suffix: typeof ShardImport.Suffix;
NextToLast: typeof ShardImport.NextToLast;
readShardFun: (path: string | Uint8Array, store: import("interface-datastore").Datastore) => Promise<import("./types").Shard>;
readme: "This is a repository of IPLD objects. Each IPLD object is in a single file,\nnamed <base32 encoding of cid>.data. Where <base32 encoding of cid> is the\n\"base32\" encoding of the CID (as specified in\nhttps://github.com/multiformats/multibase) without the 'B' prefix.\nAll the object files are placed in a tree of directories, based on a\nfunction of the CID. This is a form of sharding similar to\nthe objects directory in git repositories. Previously, we used\nprefixes, we now use the next-to-last two charters.\n func NextToLast(base32cid string) {\n nextToLastLen := 2\n offset := len(base32cid) - nextToLastLen - 1\n return str[offset : offset+nextToLastLen]\n }\nFor example, an object with a base58 CIDv1 of\n zb2rhYSxw4ZjuzgCnWSt19Q94ERaeFhu9uSqRgjSdx9bsgM6f\nhas a base32 CIDv1 of\n BAFKREIA22FLID5AJ2KU7URG47MDLROZIH6YF2KALU2PWEFPVI37YLKRSCA\nand will be placed at\n SC/AFKREIA22FLID5AJ2KU7URG47MDLROZIH6YF2KALU2PWEFPVI37YLKRSCA.data\nwith 'SC' being the last-to-next two characters and the 'B' at the\nbeginning of the CIDv1 string is the multibase prefix that is not\nstored in the filename.\n";
};
export const Errors: typeof ErrorsImport;
export const shard: typeof ShardImport;
export type Shard = import("./types").Shard;
export type KeyTransform = import("./types").KeyTransform;
import * as ErrorsImport from "./errors.js";
import * as ShardImport from "./shard.js";
//# sourceMappingURL=index.d.ts.map

@@ -24,3 +24,3 @@ import * as ErrorsImport from './errors.js';

} from './namespace.js';
export const Errors = { ...ErrorsImport };
export const shard = { ...ShardImport };
export const Errors = ErrorsImport;
export const shard = ShardImport;
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.DatastoreCore = factory()}(typeof self !== 'undefined' ? self : this, function () {
var DatastoreCore=(()=>{var dr=Object.create;var he=Object.defineProperty;var lr=Object.getOwnPropertyDescriptor;var pr=Object.getOwnPropertyNames;var mr=Object.getPrototypeOf,yr=Object.prototype.hasOwnProperty;var ct=r=>he(r,"__esModule",{value:!0});var C=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),v=(r,e)=>{ct(r);for(var t in e)he(r,t,{get:e[t],enumerable:!0})},br=(r,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of pr(e))!yr.call(r,s)&&s!=="default"&&he(r,s,{get:()=>e[s],enumerable:!(t=lr(e,s))||t.enumerable});return r},S=r=>br(ct(he(r!=null?dr(mr(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var ht=C((Zs,ft)=>{"use strict";function ut(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function wr(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 ut(r,t)}catch(s){t.message=r.message,t.stack=r.stack;let n=function(){};return n.prototype=Object.create(Object.getPrototypeOf(r)),ut(new n,t)}}ft.exports=wr});var Kt=C((to,Bt)=>{"use strict";var As=async r=>{let e=[];for await(let t of r)e.push(t);return e};Bt.exports=As});var Je=C((so,Vt)=>{"use strict";var js=async r=>{for await(let e of r);};Vt.exports=js});var Ge=C((no,Wt)=>{"use strict";var Ds=async function*(r,e){for await(let t of r)await e(t)&&(yield t)};Wt.exports=Ds});var He=C((oo,Jt)=>{"use strict";var Is=async function*(r,e){let t=0;if(!(e<1)){for await(let s of r)if(yield s,t++,t===e)return}};Jt.exports=Is});var Ht=C((lo,Gt)=>{"use strict";var ks=async function*(r,e){for await(let t of r)yield e(t)};Gt.exports=ks});var Zt=C((po,X)=>{var Xt=(...r)=>{let e;for(;r.length;)e=r.shift()(e);return e},Qe=r=>r&&(typeof r[Symbol.asyncIterator]=="function"||typeof r[Symbol.iterator]=="function"||typeof r.next=="function"),ve=r=>r&&typeof r.sink=="function"&&Qe(r.source),Ms=r=>e=>(r.sink(e),r.source),Yt=(...r)=>{if(ve(r[0])){let e=r[0];r[0]=()=>e.source}else if(Qe(r[0])){let e=r[0];r[0]=()=>e}if(r.length>1&&ve(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let e=1;e<r.length-1;e++)ve(r[e])&&(r[e]=Ms(r[e]));return Xt(...r)};X.exports=Yt;X.exports.pipe=Yt;X.exports.rawPipe=Xt;X.exports.isIterable=Qe;X.exports.isDuplex=ve});var qt=C((Ao,Qt)=>{Qt.exports=class{constructor(e){if(!(e>0)||(e-1&e)!=0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}}});var rr=C((Do,tr)=>{var er=qt();tr.exports=class{constructor(e){this.hwm=e||16,this.head=new er(this.hwm),this.tail=this.head}push(e){if(!this.head.push(e)){let t=this.head;this.head=t.next=new er(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next){let t=this.tail.next;return this.tail.next=null,this.tail=t,this.tail.shift()}return e}isEmpty(){return this.head.isEmpty()}}});var et=C((Io,sr)=>{var qe=rr();sr.exports=r=>{r=r||{};let e;typeof r=="function"?(e=r,r={}):e=r.onEnd;let t=new qe,s,n,o,i=()=>{if(!t.isEmpty()){if(r.writev){let h,d=[];for(;!t.isEmpty();){if(h=t.shift(),h.error)throw h.error;d.push(h.value)}return{done:h.done,value:d}}let a=t.shift();if(a.error)throw a.error;return a}return o?{done:!0}:new Promise((a,h)=>{n=d=>(n=null,d.error?h(d.error):r.writev&&!d.done?a({done:d.done,value:[d.value]}):a(d),s)})},u=a=>n?n(a):(t.push(a),s),b=a=>(t=new qe,n?n({error:a}):(t.push({error:a}),s)),k=a=>o?s:u({done:!1,value:a}),c=a=>o?s:(o=!0,a?b(a):u({done:!0})),f=()=>(t=new qe,c(),{done:!0}),p=a=>(c(a),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:i,return:f,throw:p,push:k,end:c},!e)return s;let M=s;return s={[Symbol.asyncIterator](){return this},next(){return M.next()},throw(a){return M.throw(a),e&&(e(a),e=null),{done:!0}},return(){return M.return(),e&&(e(),e=null),{done:!0}},push:k,end(a){return M.end(a),e&&(e(a),e=null),s}},s}});var or=C((ko,nr)=>{"use strict";var Ns=et(),Os=async function*(...r){let e=Ns();setTimeout(async()=>{try{await Promise.all(r.map(async t=>{for await(let s of t)e.push(s)})),e.end()}catch(t){e.end(t)}},0),yield*e};nr.exports=Os});var ar=C((_o,ir)=>{var Z=1e3,Q=Z*60,q=Q*60,K=q*24,Rs=K*7,_s=K*365.25;ir.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return Us(r);if(t==="number"&&isFinite(r))return e.long?Ps(r):Ls(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Us(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(!!e){var t=parseFloat(e[1]),s=(e[2]||"ms").toLowerCase();switch(s){case"years":case"year":case"yrs":case"yr":case"y":return t*_s;case"weeks":case"week":case"w":return t*Rs;case"days":case"day":case"d":return t*K;case"hours":case"hour":case"hrs":case"hr":case"h":return t*q;case"minutes":case"minute":case"mins":case"min":case"m":return t*Q;case"seconds":case"second":case"secs":case"sec":case"s":return t*Z;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function Ls(r){var e=Math.abs(r);return e>=K?Math.round(r/K)+"d":e>=q?Math.round(r/q)+"h":e>=Q?Math.round(r/Q)+"m":e>=Z?Math.round(r/Z)+"s":r+"ms"}function Ps(r){var e=Math.abs(r);return e>=K?Se(r,e,K,"day"):e>=q?Se(r,e,q,"hour"):e>=Q?Se(r,e,Q,"minute"):e>=Z?Se(r,e,Z,"second"):r+" ms"}function Se(r,e,t,s){var n=e>=t*1.5;return Math.round(r/t)+" "+s+(n?"s":"")}});var ur=C((Uo,cr)=>{function Ts(r){t.debug=t,t.default=t,t.coerce=b,t.disable=o,t.enable=n,t.enabled=i,t.humanize=ar(),t.destroy=k,Object.keys(r).forEach(c=>{t[c]=r[c]}),t.names=[],t.skips=[],t.formatters={};function e(c){let f=0;for(let p=0;p<c.length;p++)f=(f<<5)-f+c.charCodeAt(p),f|=0;return t.colors[Math.abs(f)%t.colors.length]}t.selectColor=e;function t(c){let f,p=null,M,a;function h(...d){if(!h.enabled)return;let y=h,x=Number(new Date),j=x-(f||x);y.diff=j,y.prev=f,y.curr=x,f=x,d[0]=t.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let g=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(D,E)=>{if(D==="%%")return"%";g++;let I=t.formatters[E];if(typeof I=="function"){let $=d[g];D=I.call(y,$),d.splice(g,1),g--}return D}),t.formatArgs.call(y,d),(y.log||t.log).apply(y,d)}return h.namespace=c,h.useColors=t.useColors(),h.color=t.selectColor(c),h.extend=s,h.destroy=t.destroy,Object.defineProperty(h,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(M!==t.namespaces&&(M=t.namespaces,a=t.enabled(c)),a),set:d=>{p=d}}),typeof t.init=="function"&&t.init(h),h}function s(c,f){let p=t(this.namespace+(typeof f=="undefined"?":":f)+c);return p.log=this.log,p}function n(c){t.save(c),t.namespaces=c,t.names=[],t.skips=[];let f,p=(typeof c=="string"?c:"").split(/[\s,]+/),M=p.length;for(f=0;f<M;f++)!p[f]||(c=p[f].replace(/\*/g,".*?"),c[0]==="-"?t.skips.push(new RegExp("^"+c.substr(1)+"$")):t.names.push(new RegExp("^"+c+"$")))}function o(){let c=[...t.names.map(u),...t.skips.map(u).map(f=>"-"+f)].join(",");return t.enable(""),c}function i(c){if(c[c.length-1]==="*")return!0;let f,p;for(f=0,p=t.skips.length;f<p;f++)if(t.skips[f].test(c))return!1;for(f=0,p=t.names.length;f<p;f++)if(t.names[f].test(c))return!0;return!1}function u(c){return c.toString().substring(2,c.toString().length-2).replace(/\.\*\?$/,"*")}function b(c){return c instanceof Error?c.stack||c.message:c}function k(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}cr.exports=Ts});var fr=C((A,Fe)=>{A.formatArgs=Bs;A.save=Ks;A.load=$s;A.useColors=zs;A.storage=Vs();A.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();A.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function zs(){return typeof window!="undefined"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator!="undefined"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document!="undefined"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window!="undefined"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator!="undefined"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator!="undefined"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Bs(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Fe.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,s=0;r[0].replace(/%[a-zA-Z%]/g,n=>{n!=="%%"&&(t++,n==="%c"&&(s=t))}),r.splice(s,0,e)}A.log=console.debug||console.log||(()=>{});function Ks(r){try{r?A.storage.setItem("debug",r):A.storage.removeItem("debug")}catch(e){}}function $s(){let r;try{r=A.storage.getItem("debug")}catch(e){}return!r&&typeof process!="undefined"&&"env"in process&&(r=process.env.DEBUG),r}function Vs(){try{return localStorage}catch(r){}}Fe.exports=ur()(A);var{formatters:Ws}=Fe.exports;Ws.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var Xs={};v(Xs,{BaseDatastore:()=>F,Errors:()=>Gs,KeyTransformDatastore:()=>B,MemoryDatastore:()=>Ze,MountDatastore:()=>st,NamespaceDatastore:()=>at,ShardingDatastore:()=>P,TieredDatastore:()=>it,shard:()=>Hs});var Ae={};v(Ae,{abortedError:()=>gr,dbDeleteFailedError:()=>te,dbOpenFailedError:()=>ee,dbWriteFailedError:()=>re,notFoundError:()=>T});var V=S(ht());function ee(r){return r=r||new Error("Cannot open database"),(0,V.default)(r,"ERR_DB_OPEN_FAILED")}function te(r){return r=r||new Error("Delete failed"),(0,V.default)(r,"ERR_DB_DELETE_FAILED")}function re(r){return r=r||new Error("Write failed"),(0,V.default)(r,"ERR_DB_WRITE_FAILED")}function T(r){return r=r||new Error("Not Found"),(0,V.default)(r,"ERR_NOT_FOUND")}function gr(r){return r=r||new Error("Aborted"),(0,V.default)(r,"ERR_ABORTED")}var We={};v(We,{NextToLast:()=>Ve,PREFIX:()=>ge,Prefix:()=>Ke,README_FN:()=>Be,SHARDING_FN:()=>xe,ShardBase:()=>ce,Suffix:()=>$e,parseShardFun:()=>zt,readShardFun:()=>Ce,readme:()=>we});var dt=(r=21)=>{let e="",t=crypto.getRandomValues(new Uint8Array(r));for(;r--;){let s=t[r]&63;s<36?e+=s.toString(36):s<62?e+=(s-26).toString(36).toUpperCase():s<63?e+="_":e+="-"}return e};var je={};v(je,{identity:()=>Fr});function xr(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),s=0;s<t.length;s++)t[s]=255;for(var n=0;n<r.length;n++){var o=r.charAt(n),i=o.charCodeAt(0);if(t[i]!==255)throw new TypeError(o+" is ambiguous");t[i]=n}var u=r.length,b=r.charAt(0),k=Math.log(u)/Math.log(256),c=Math.log(256)/Math.log(u);function f(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,d=0,y=0,x=a.length;y!==x&&a[y]===0;)y++,h++;for(var j=(x-y)*c+1>>>0,g=new Uint8Array(j);y!==x;){for(var N=a[y],D=0,E=j-1;(N!==0||D<d)&&E!==-1;E--,D++)N+=256*g[E]>>>0,g[E]=N%u>>>0,N=N/u>>>0;if(N!==0)throw new Error("Non-zero carry");d=D,y++}for(var I=j-d;I!==j&&g[I]===0;)I++;for(var $=b.repeat(h);I<j;++I)$+=r.charAt(g[I]);return $}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 d=0,y=0;a[h]===b;)d++,h++;for(var x=(a.length-h)*k+1>>>0,j=new Uint8Array(x);a[h];){var g=t[a.charCodeAt(h)];if(g===255)return;for(var N=0,D=x-1;(g!==0||N<y)&&D!==-1;D--,N++)g+=u*j[D]>>>0,j[D]=g%256>>>0,g=g/256>>>0;if(g!==0)throw new Error("Non-zero carry");y=N,h++}if(a[h]!==" "){for(var E=x-y;E!==x&&j[E]===0;)E++;for(var I=new Uint8Array(d+(x-E)),$=d;E!==x;)I[$++]=j[E++];return I}}}function M(a){var h=p(a);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:p,decode:M}}var Cr=xr,vr=Cr,lt=vr;var sn=new Uint8Array(0);var pt=(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},R=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 mt=r=>new TextEncoder().encode(r),yt=r=>new TextDecoder().decode(r);var wt=class{constructor(e,t,s){this.name=e,this.prefix=t,this.baseEncode=s}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},gt=class{constructor(e,t,s){this.name=e,this.prefix=t,this.baseDecode=s}decode(e){if(typeof e=="string")switch(e[0]){case this.prefix:return this.baseDecode(e.slice(1));default:throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`)}else throw Error("Can only multibase decode strings")}or(e){return Ct(this,e)}},xt=class{constructor(e){this.decoders=e}or(e){return Ct(this,e)}decode(e){let t=e[0],s=this.decoders[t];if(s)return s.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Ct=(r,e)=>new xt({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),vt=class{constructor(e,t,s,n){this.name=e,this.prefix=t,this.baseEncode=s,this.baseDecode=n,this.encoder=new wt(e,t,s),this.decoder=new gt(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},de=({name:r,prefix:e,encode:t,decode:s})=>new vt(r,e,t,s),U=({prefix:r,name:e,alphabet:t})=>{let{encode:s,decode:n}=lt(t,e);return de({prefix:r,name:e,encode:s,decode:o=>R(n(o))})},Er=(r,e,t,s)=>{let n={};for(let c=0;c<e.length;++c)n[e[c]]=c;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),u=0,b=0,k=0;for(let c=0;c<o;++c){let f=n[r[c]];if(f===void 0)throw new SyntaxError(`Non-${s} character`);b=b<<t|f,u+=t,u>=8&&(u-=8,i[k++]=255&b>>u)}if(u>=t||255&b<<8-u)throw new SyntaxError("Unexpected end of data");return i},Sr=(r,e,t)=>{let s=e[e.length-1]==="=",n=(1<<t)-1,o="",i=0,u=0;for(let b=0;b<r.length;++b)for(u=u<<8|r[b],i+=8;i>t;)i-=t,o+=e[n&u>>i];if(i&&(o+=e[n&u<<t-i]),s)for(;o.length*t&7;)o+="=";return o},m=({name:r,prefix:e,bitsPerChar:t,alphabet:s})=>de({prefix:e,name:r,encode(n){return Sr(n,s,t)},decode(n){return Er(n,s,t,r)}});var Fr=de({prefix:"\0",name:"identity",encode:r=>yt(r),decode:r=>mt(r)});var De={};v(De,{base2:()=>Ar});var Ar=m({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ie={};v(Ie,{base8:()=>jr});var jr=m({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ke={};v(ke,{base10:()=>Dr});var Dr=U({prefix:"9",name:"base10",alphabet:"0123456789"});var Me={};v(Me,{base16:()=>Ir,base16upper:()=>kr});var Ir=m({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),kr=m({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ne={};v(Ne,{base32:()=>W,base32hex:()=>Rr,base32hexpad:()=>Ur,base32hexpadupper:()=>Lr,base32hexupper:()=>_r,base32pad:()=>Nr,base32padupper:()=>Or,base32upper:()=>Mr,base32z:()=>Pr});var W=m({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Mr=m({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Nr=m({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Or=m({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Rr=m({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),_r=m({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ur=m({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Lr=m({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Pr=m({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Oe={};v(Oe,{base36:()=>Tr,base36upper:()=>zr});var Tr=U({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zr=U({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Re={};v(Re,{base58btc:()=>O,base58flickr:()=>Br});var O=U({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Br=U({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _e={};v(_e,{base64:()=>Kr,base64pad:()=>$r,base64url:()=>Vr,base64urlpad:()=>Wr});var Kr=m({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),$r=m({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Vr=m({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Wr=m({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Le={};v(Le,{sha256:()=>fs,sha512:()=>hs});var Jr=St,Et=128,Gr=127,Hr=~Gr,Xr=Math.pow(2,31);function St(r,e,t){e=e||[],t=t||0;for(var s=t;r>=Xr;)e[t++]=r&255|Et,r/=128;for(;r&Hr;)e[t++]=r&255|Et,r>>>=7;return e[t]=r|0,St.bytes=t-s+1,e}var Yr=Ue,Zr=128,Ft=127;function Ue(r,e){var t=0,e=e||0,s=0,n=e,o,i=r.length;do{if(n>=i)throw Ue.bytes=0,new RangeError("Could not decode varint");o=r[n++],t+=s<28?(o&Ft)<<s:(o&Ft)*Math.pow(2,s),s+=7}while(o>=Zr);return Ue.bytes=n-e,t}var Qr=Math.pow(2,7),qr=Math.pow(2,14),es=Math.pow(2,21),ts=Math.pow(2,28),rs=Math.pow(2,35),ss=Math.pow(2,42),ns=Math.pow(2,49),os=Math.pow(2,56),is=Math.pow(2,63),as=function(r){return r<Qr?1:r<qr?2:r<es?3:r<ts?4:r<rs?5:r<ss?6:r<ns?7:r<os?8:r<is?9:10},cs={encode:Jr,decode:Yr,encodingLength:as},us=cs,se=us;var ne=r=>[se.decode(r),se.decode.bytes],J=(r,e,t=0)=>(se.encode(r,e,t),e),G=r=>se.encodingLength(r);var le=(r,e)=>{let t=e.byteLength,s=G(r),n=s+G(t),o=new Uint8Array(n+t);return J(r,o,0),J(t,o,s),o.set(e,n),new oe(r,t,e,o)},jt=r=>{let e=R(r),[t,s]=ne(e),[n,o]=ne(e.subarray(s)),i=e.subarray(s+o);if(i.byteLength!==n)throw new Error("Incorrect length");return new oe(t,n,i,e)},Dt=(r,e)=>r===e?!0:r.code===e.code&&r.size===e.size&&pt(r.bytes,e.bytes),oe=class{constructor(e,t,s,n){this.code=e,this.size=t,this.digest=s,this.bytes=n}};var ie=({name:r,code:e,encode:t})=>new kt(r,e,t),kt=class{constructor(e,t,s){this.name=e,this.code=t,this.encode=s}async digest(e){if(e instanceof Uint8Array){let t=await this.encode(e);return le(this.code,t)}else throw Error("Unknown type, must be binary type")}};var Nt=r=>async e=>new Uint8Array(await crypto.subtle.digest(r,e)),fs=ie({name:"sha2-256",code:18,encode:Nt("SHA-256")}),hs=ie({name:"sha2-512",code:19,encode:Nt("SHA-512")});var Pe={};v(Pe,{identity:()=>ds});var ds=ie({name:"identity",code:0,encode:r=>R(r)});var jn=new TextEncoder,Dn=new TextDecoder;var w=class{constructor(e,t,s,n){this.code=t,this.version=e,this.multihash=s,this.bytes=n,this.byteOffset=n.byteOffset,this.byteLength=n.byteLength,this.asCID=this,this._baseCache=new Map,Object.defineProperties(this,{byteOffset:me,byteLength:me,code:pe,version:pe,multihash:pe,bytes:pe,_baseCache:me,asCID:me})}toV0(){switch(this.version){case 0:return this;default:{let{code:e,multihash:t}=this;if(e!==ae)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==ws)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return w.createV0(t)}}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,s=le(e,t);return w.createV1(this.code,s)}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&&Dt(this.multihash,e.multihash)}toString(e){let{bytes:t,version:s,_baseCache:n}=this;switch(s){case 0:return ys(t,n,e||O.encoder);default:return bs(t,n,e||W.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 xs(/^0\.0/,Cs),!!(e&&(e[Rt]||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 w)return e;if(e!=null&&e.asCID===e){let{version:t,code:s,multihash:n,bytes:o}=e;return new w(t,s,n,o||Ot(t,s,n.bytes))}else if(e!=null&&e[Rt]===!0){let{version:t,multihash:s,code:n}=e,o=jt(s);return w.create(t,n,o)}else return null}static create(e,t,s){if(typeof t!="number")throw new Error("String codecs are no longer supported");switch(e){case 0:{if(t!==ae)throw new Error(`Version 0 CID must use dag-pb (code: ${ae}) block encoding`);return new w(e,t,s,s.bytes)}case 1:{let n=Ot(e,t,s.bytes);return new w(e,t,s,n)}default:throw new Error("Invalid version")}}static createV0(e){return w.create(0,ae,e)}static createV1(e,t){return w.create(1,e,t)}static decode(e){let[t,s]=w.decodeFirst(e);if(s.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=w.inspectBytes(e),s=t.size-t.multihashSize,n=R(e.subarray(s,s+t.multihashSize));if(n.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=n.subarray(t.multihashSize-t.digestSize),i=new oe(t.multihashCode,t.digestSize,o,n);return[t.version===0?w.createV0(i):w.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,s=()=>{let[f,p]=ne(e.subarray(t));return t+=p,f},n=s(),o=ae;if(n===18?(n=0,t=0):n===1&&(o=s()),n!==0&&n!==1)throw new RangeError(`Invalid CID version ${n}`);let i=t,u=s(),b=s(),k=t+b,c=k-i;return{version:n,codec:o,multihashCode:u,digestSize:b,multihashSize:c,size:k}}static parse(e,t){let[s,n]=ms(e,t),o=w.decode(n);return o._baseCache.set(s,e),o}},ms=(r,e)=>{switch(r[0]){case"Q":{let t=e||O;return[O.prefix,t.decode(`${O.prefix}${r}`)]}case O.prefix:{let t=e||O;return[O.prefix,t.decode(r)]}case W.prefix:{let t=e||W;return[W.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)]}}},ys=(r,e,t)=>{let{prefix:s}=t;if(s!==O.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let n=e.get(s);if(n==null){let o=t.encode(r).slice(1);return e.set(s,o),o}else return n},bs=(r,e,t)=>{let{prefix:s}=t,n=e.get(s);if(n==null){let o=t.encode(r);return e.set(s,o),o}else return n},ae=112,ws=18,Ot=(r,e,t)=>{let s=G(r),n=s+G(e),o=new Uint8Array(n+t.byteLength);return J(r,o,0),J(e,o,s),o.set(t,n),o},Rt=Symbol.for("@ipld/js-cid/CID"),pe={writable:!1,configurable:!1,enumerable:!0},me={writable:!1,enumerable:!1,configurable:!1},gs="0.0.0-dev",xs=(r,e)=>{if(r.test(gs))console.warn(e);else throw new Error(e)},Cs=`CID.isCID(v) is deprecated and will be removed in the next major release.
var DatastoreCore=(()=>{var pr=Object.create;var he=Object.defineProperty;var mr=Object.getOwnPropertyDescriptor;var yr=Object.getOwnPropertyNames;var br=Object.getPrototypeOf,gr=Object.prototype.hasOwnProperty;var ct=r=>he(r,"__esModule",{value:!0});var C=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),v=(r,e)=>{ct(r);for(var t in e)he(r,t,{get:e[t],enumerable:!0})},wr=(r,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of yr(e))!gr.call(r,s)&&s!=="default"&&he(r,s,{get:()=>e[s],enumerable:!(t=mr(e,s))||t.enumerable});return r},S=r=>wr(ct(he(r!=null?pr(br(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var ht=C((tn,ft)=>{"use strict";function ut(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function xr(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 ut(r,t)}catch(s){t.message=r.message,t.stack=r.stack;let n=function(){};return n.prototype=Object.create(Object.getPrototypeOf(r)),ut(new n,t)}}ft.exports=xr});var Vt=C((oo,$t)=>{"use strict";var ks=async r=>{let e=[];for await(let t of r)e.push(t);return e};$t.exports=ks});var Je=C((ao,Jt)=>{"use strict";var Ms=async r=>{for await(let e of r);};Jt.exports=Ms});var Ge=C((co,Gt)=>{"use strict";var Ns=async function*(r,e){for await(let t of r)await e(t)&&(yield t)};Gt.exports=Ns});var He=C((uo,Ht)=>{"use strict";var Os=async function*(r,e){let t=0;if(!(e<1)){for await(let s of r)if(yield s,t++,t===e)return}};Ht.exports=Os});var Yt=C((bo,Xt)=>{"use strict";var Rs=async function*(r,e){for await(let t of r)yield e(t)};Xt.exports=Rs});var qt=C((go,Y)=>{var Zt=(...r)=>{let e;for(;r.length;)e=r.shift()(e);return e},Qe=r=>r&&(typeof r[Symbol.asyncIterator]=="function"||typeof r[Symbol.iterator]=="function"||typeof r.next=="function"),Ce=r=>r&&typeof r.sink=="function"&&Qe(r.source),Us=r=>e=>(r.sink(e),r.source),Qt=(...r)=>{if(Ce(r[0])){let e=r[0];r[0]=()=>e.source}else if(Qe(r[0])){let e=r[0];r[0]=()=>e}if(r.length>1&&Ce(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let e=1;e<r.length-1;e++)Ce(r[e])&&(r[e]=Us(r[e]));return Zt(...r)};Y.exports=Qt;Y.exports.pipe=Qt;Y.exports.rawPipe=Zt;Y.exports.isIterable=Qe;Y.exports.isDuplex=Ce});var tr=C((ko,er)=>{er.exports=class{constructor(e){if(!(e>0)||(e-1&e)!=0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}peek(){return this.buffer[this.btm]}isEmpty(){return this.buffer[this.btm]===void 0}}});var nr=C((No,sr)=>{var rr=tr();sr.exports=class{constructor(e){this.hwm=e||16,this.head=new rr(this.hwm),this.tail=this.head}push(e){if(!this.head.push(e)){let t=this.head;this.head=t.next=new rr(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next){let t=this.tail.next;return this.tail.next=null,this.tail=t,this.tail.shift()}return e}peek(){return this.tail.peek()}isEmpty(){return this.head.isEmpty()}}});var et=C((Oo,or)=>{var qe=nr();or.exports=r=>{r=r||{};let e;typeof r=="function"?(e=r,r={}):e=r.onEnd;let t=new qe,s,n,o,i=()=>{if(!t.isEmpty()){if(r.writev){let h,d=[];for(;!t.isEmpty();){if(h=t.shift(),h.error)throw h.error;d.push(h.value)}return{done:h.done,value:d}}let a=t.shift();if(a.error)throw a.error;return a}return o?{done:!0}:new Promise((a,h)=>{n=d=>(n=null,d.error?h(d.error):r.writev&&!d.done?a({done:d.done,value:[d.value]}):a(d),s)})},u=a=>n?n(a):(t.push(a),s),b=a=>(t=new qe,n?n({error:a}):(t.push({error:a}),s)),k=a=>o?s:u({done:!1,value:a}),c=a=>o?s:(o=!0,a?b(a):u({done:!0})),f=()=>(t=new qe,c(),{done:!0}),p=a=>(c(a),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:i,return:f,throw:p,push:k,end:c},!e)return s;let M=s;return s={[Symbol.asyncIterator](){return this},next(){return M.next()},throw(a){return M.throw(a),e&&(e(a),e=null),{done:!0}},return(){return M.return(),e&&(e(),e=null),{done:!0}},push:k,end(a){return M.end(a),e&&(e(a),e=null),s}},s}});var ar=C((Ro,ir)=>{"use strict";var _s=et(),Ls=async function*(...r){let e=_s();setTimeout(async()=>{try{await Promise.all(r.map(async t=>{for await(let s of t)e.push(s)})),e.end()}catch(t){e.end(t)}},0),yield*e};ir.exports=Ls});var ur=C((To,cr)=>{var Q=1e3,q=Q*60,ee=q*60,$=ee*24,Ps=$*7,Ts=$*365.25;cr.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return zs(r);if(t==="number"&&isFinite(r))return e.long?Ks(r):Bs(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function zs(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(!!e){var t=parseFloat(e[1]),s=(e[2]||"ms").toLowerCase();switch(s){case"years":case"year":case"yrs":case"yr":case"y":return t*Ts;case"weeks":case"week":case"w":return t*Ps;case"days":case"day":case"d":return t*$;case"hours":case"hour":case"hrs":case"hr":case"h":return t*ee;case"minutes":case"minute":case"mins":case"min":case"m":return t*q;case"seconds":case"second":case"secs":case"sec":case"s":return t*Q;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function Bs(r){var e=Math.abs(r);return e>=$?Math.round(r/$)+"d":e>=ee?Math.round(r/ee)+"h":e>=q?Math.round(r/q)+"m":e>=Q?Math.round(r/Q)+"s":r+"ms"}function Ks(r){var e=Math.abs(r);return e>=$?Ee(r,e,$,"day"):e>=ee?Ee(r,e,ee,"hour"):e>=q?Ee(r,e,q,"minute"):e>=Q?Ee(r,e,Q,"second"):r+" ms"}function Ee(r,e,t,s){var n=e>=t*1.5;return Math.round(r/t)+" "+s+(n?"s":"")}});var hr=C((zo,fr)=>{function $s(r){t.debug=t,t.default=t,t.coerce=b,t.disable=o,t.enable=n,t.enabled=i,t.humanize=ur(),t.destroy=k,Object.keys(r).forEach(c=>{t[c]=r[c]}),t.names=[],t.skips=[],t.formatters={};function e(c){let f=0;for(let p=0;p<c.length;p++)f=(f<<5)-f+c.charCodeAt(p),f|=0;return t.colors[Math.abs(f)%t.colors.length]}t.selectColor=e;function t(c){let f,p=null,M,a;function h(...d){if(!h.enabled)return;let y=h,x=Number(new Date),j=x-(f||x);y.diff=j,y.prev=f,y.curr=x,f=x,d[0]=t.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let w=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(D,E)=>{if(D==="%%")return"%";w++;let I=t.formatters[E];if(typeof I=="function"){let V=d[w];D=I.call(y,V),d.splice(w,1),w--}return D}),t.formatArgs.call(y,d),(y.log||t.log).apply(y,d)}return h.namespace=c,h.useColors=t.useColors(),h.color=t.selectColor(c),h.extend=s,h.destroy=t.destroy,Object.defineProperty(h,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(M!==t.namespaces&&(M=t.namespaces,a=t.enabled(c)),a),set:d=>{p=d}}),typeof t.init=="function"&&t.init(h),h}function s(c,f){let p=t(this.namespace+(typeof f=="undefined"?":":f)+c);return p.log=this.log,p}function n(c){t.save(c),t.namespaces=c,t.names=[],t.skips=[];let f,p=(typeof c=="string"?c:"").split(/[\s,]+/),M=p.length;for(f=0;f<M;f++)!p[f]||(c=p[f].replace(/\*/g,".*?"),c[0]==="-"?t.skips.push(new RegExp("^"+c.substr(1)+"$")):t.names.push(new RegExp("^"+c+"$")))}function o(){let c=[...t.names.map(u),...t.skips.map(u).map(f=>"-"+f)].join(",");return t.enable(""),c}function i(c){if(c[c.length-1]==="*")return!0;let f,p;for(f=0,p=t.skips.length;f<p;f++)if(t.skips[f].test(c))return!1;for(f=0,p=t.names.length;f<p;f++)if(t.names[f].test(c))return!0;return!1}function u(c){return c.toString().substring(2,c.toString().length-2).replace(/\.\*\?$/,"*")}function b(c){return c instanceof Error?c.stack||c.message:c}function k(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}fr.exports=$s});var dr=C((A,Se)=>{A.formatArgs=Ws;A.save=Js;A.load=Gs;A.useColors=Vs;A.storage=Hs();A.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();A.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Vs(){return typeof window!="undefined"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator!="undefined"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document!="undefined"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window!="undefined"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator!="undefined"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator!="undefined"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Ws(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Se.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,s=0;r[0].replace(/%[a-zA-Z%]/g,n=>{n!=="%%"&&(t++,n==="%c"&&(s=t))}),r.splice(s,0,e)}A.log=console.debug||console.log||(()=>{});function Js(r){try{r?A.storage.setItem("debug",r):A.storage.removeItem("debug")}catch(e){}}function Gs(){let r;try{r=A.storage.getItem("debug")}catch(e){}return!r&&typeof process!="undefined"&&"env"in process&&(r=process.env.DEBUG),r}function Hs(){try{return localStorage}catch(r){}}Se.exports=hr()(A);var{formatters:Xs}=Se.exports;Xs.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var qs={};v(qs,{BaseDatastore:()=>F,Errors:()=>Zs,KeyTransformDatastore:()=>K,MemoryDatastore:()=>Ze,MountDatastore:()=>st,NamespaceDatastore:()=>at,ShardingDatastore:()=>P,TieredDatastore:()=>it,shard:()=>Qs});var Fe={};v(Fe,{abortedError:()=>Cr,dbDeleteFailedError:()=>re,dbOpenFailedError:()=>te,dbWriteFailedError:()=>se,notFoundError:()=>T});var W=S(ht());function te(r){return r=r||new Error("Cannot open database"),(0,W.default)(r,"ERR_DB_OPEN_FAILED")}function re(r){return r=r||new Error("Delete failed"),(0,W.default)(r,"ERR_DB_DELETE_FAILED")}function se(r){return r=r||new Error("Write failed"),(0,W.default)(r,"ERR_DB_WRITE_FAILED")}function T(r){return r=r||new Error("Not Found"),(0,W.default)(r,"ERR_NOT_FOUND")}function Cr(r){return r=r||new Error("Aborted"),(0,W.default)(r,"ERR_ABORTED")}var We={};v(We,{NextToLast:()=>Ve,PREFIX:()=>ge,Prefix:()=>Ke,README_FN:()=>Be,SHARDING_FN:()=>we,ShardBase:()=>ce,Suffix:()=>$e,parseShardFun:()=>Kt,readShardFun:()=>xe,readme:()=>be});var dt=(r=21)=>{let e="",t=crypto.getRandomValues(new Uint8Array(r));for(;r--;){let s=t[r]&63;s<36?e+=s.toString(36):s<62?e+=(s-26).toString(36).toUpperCase():s<63?e+="_":e+="-"}return e};var Ae={};v(Ae,{identity:()=>jr});function vr(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),s=0;s<t.length;s++)t[s]=255;for(var n=0;n<r.length;n++){var o=r.charAt(n),i=o.charCodeAt(0);if(t[i]!==255)throw new TypeError(o+" is ambiguous");t[i]=n}var u=r.length,b=r.charAt(0),k=Math.log(u)/Math.log(256),c=Math.log(256)/Math.log(u);function f(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,d=0,y=0,x=a.length;y!==x&&a[y]===0;)y++,h++;for(var j=(x-y)*c+1>>>0,w=new Uint8Array(j);y!==x;){for(var N=a[y],D=0,E=j-1;(N!==0||D<d)&&E!==-1;E--,D++)N+=256*w[E]>>>0,w[E]=N%u>>>0,N=N/u>>>0;if(N!==0)throw new Error("Non-zero carry");d=D,y++}for(var I=j-d;I!==j&&w[I]===0;)I++;for(var V=b.repeat(h);I<j;++I)V+=r.charAt(w[I]);return V}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 d=0,y=0;a[h]===b;)d++,h++;for(var x=(a.length-h)*k+1>>>0,j=new Uint8Array(x);a[h];){var w=t[a.charCodeAt(h)];if(w===255)return;for(var N=0,D=x-1;(w!==0||N<y)&&D!==-1;D--,N++)w+=u*j[D]>>>0,j[D]=w%256>>>0,w=w/256>>>0;if(w!==0)throw new Error("Non-zero carry");y=N,h++}if(a[h]!==" "){for(var E=x-y;E!==x&&j[E]===0;)E++;for(var I=new Uint8Array(d+(x-E)),V=d;E!==x;)I[V++]=j[E++];return I}}}function M(a){var h=p(a);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:p,decode:M}}var Er=vr,Sr=Er,lt=Sr;var cn=new Uint8Array(0);var pt=(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},R=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 mt=r=>new TextEncoder().encode(r),yt=r=>new TextDecoder().decode(r);var gt=class{constructor(e,t,s){this.name=e,this.prefix=t,this.baseEncode=s}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},wt=class{constructor(e,t,s){this.name=e,this.prefix=t,this.baseDecode=s}decode(e){if(typeof e=="string")switch(e[0]){case this.prefix:return this.baseDecode(e.slice(1));default:throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`)}else throw Error("Can only multibase decode strings")}or(e){return Ct(this,e)}},xt=class{constructor(e){this.decoders=e}or(e){return Ct(this,e)}decode(e){let t=e[0],s=this.decoders[t];if(s)return s.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Ct=(r,e)=>new xt({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),vt=class{constructor(e,t,s,n){this.name=e,this.prefix=t,this.baseEncode=s,this.baseDecode=n,this.encoder=new gt(e,t,s),this.decoder=new wt(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},de=({name:r,prefix:e,encode:t,decode:s})=>new vt(r,e,t,s),_=({prefix:r,name:e,alphabet:t})=>{let{encode:s,decode:n}=lt(t,e);return de({prefix:r,name:e,encode:s,decode:o=>R(n(o))})},Fr=(r,e,t,s)=>{let n={};for(let c=0;c<e.length;++c)n[e[c]]=c;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),u=0,b=0,k=0;for(let c=0;c<o;++c){let f=n[r[c]];if(f===void 0)throw new SyntaxError(`Non-${s} character`);b=b<<t|f,u+=t,u>=8&&(u-=8,i[k++]=255&b>>u)}if(u>=t||255&b<<8-u)throw new SyntaxError("Unexpected end of data");return i},Ar=(r,e,t)=>{let s=e[e.length-1]==="=",n=(1<<t)-1,o="",i=0,u=0;for(let b=0;b<r.length;++b)for(u=u<<8|r[b],i+=8;i>t;)i-=t,o+=e[n&u>>i];if(i&&(o+=e[n&u<<t-i]),s)for(;o.length*t&7;)o+="=";return o},m=({name:r,prefix:e,bitsPerChar:t,alphabet:s})=>de({prefix:e,name:r,encode(n){return Ar(n,s,t)},decode(n){return Fr(n,s,t,r)}});var jr=de({prefix:"\0",name:"identity",encode:r=>yt(r),decode:r=>mt(r)});var je={};v(je,{base2:()=>Dr});var Dr=m({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var De={};v(De,{base8:()=>Ir});var Ir=m({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ie={};v(Ie,{base10:()=>kr});var kr=_({prefix:"9",name:"base10",alphabet:"0123456789"});var ke={};v(ke,{base16:()=>Mr,base16upper:()=>Nr});var Mr=m({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Nr=m({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Me={};v(Me,{base32:()=>J,base32hex:()=>_r,base32hexpad:()=>Pr,base32hexpadupper:()=>Tr,base32hexupper:()=>Lr,base32pad:()=>Rr,base32padupper:()=>Ur,base32upper:()=>Or,base32z:()=>zr});var J=m({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Or=m({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Rr=m({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ur=m({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),_r=m({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Lr=m({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Pr=m({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Tr=m({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),zr=m({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ne={};v(Ne,{base36:()=>Br,base36upper:()=>Kr});var Br=_({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Kr=_({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Oe={};v(Oe,{base58btc:()=>O,base58flickr:()=>$r});var O=_({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),$r=_({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Re={};v(Re,{base64:()=>Vr,base64pad:()=>Wr,base64url:()=>Jr,base64urlpad:()=>Gr});var Vr=m({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Wr=m({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Jr=m({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Gr=m({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Le={};v(Le,{sha256:()=>ds,sha512:()=>ls});var Hr=St,Et=128,Xr=127,Yr=~Xr,Zr=Math.pow(2,31);function St(r,e,t){e=e||[],t=t||0;for(var s=t;r>=Zr;)e[t++]=r&255|Et,r/=128;for(;r&Yr;)e[t++]=r&255|Et,r>>>=7;return e[t]=r|0,St.bytes=t-s+1,e}var Qr=Ue,qr=128,Ft=127;function Ue(r,e){var t=0,e=e||0,s=0,n=e,o,i=r.length;do{if(n>=i)throw Ue.bytes=0,new RangeError("Could not decode varint");o=r[n++],t+=s<28?(o&Ft)<<s:(o&Ft)*Math.pow(2,s),s+=7}while(o>=qr);return Ue.bytes=n-e,t}var es=Math.pow(2,7),ts=Math.pow(2,14),rs=Math.pow(2,21),ss=Math.pow(2,28),ns=Math.pow(2,35),os=Math.pow(2,42),is=Math.pow(2,49),as=Math.pow(2,56),cs=Math.pow(2,63),us=function(r){return r<es?1:r<ts?2:r<rs?3:r<ss?4:r<ns?5:r<os?6:r<is?7:r<as?8:r<cs?9:10},fs={encode:Hr,decode:Qr,encodingLength:us},hs=fs,ne=hs;var oe=r=>[ne.decode(r),ne.decode.bytes],G=(r,e,t=0)=>(ne.encode(r,e,t),e),H=r=>ne.encodingLength(r);var z=(r,e)=>{let t=e.byteLength,s=H(r),n=s+H(t),o=new Uint8Array(n+t);return G(r,o,0),G(t,o,s),o.set(e,n),new ie(r,t,e,o)},jt=r=>{let e=R(r),[t,s]=oe(e),[n,o]=oe(e.subarray(s)),i=e.subarray(s+o);if(i.byteLength!==n)throw new Error("Incorrect length");return new ie(t,n,i,e)},Dt=(r,e)=>r===e?!0:r.code===e.code&&r.size===e.size&&pt(r.bytes,e.bytes),ie=class{constructor(e,t,s,n){this.code=e,this.size=t,this.digest=s,this.bytes=n}};var _e=({name:r,code:e,encode:t})=>new kt(r,e,t),kt=class{constructor(e,t,s){this.name=e,this.code=t,this.encode=s}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?z(this.code,t):t.then(s=>z(this.code,s))}else throw Error("Unknown type, must be binary type")}};var Nt=r=>async e=>new Uint8Array(await crypto.subtle.digest(r,e)),ds=_e({name:"sha2-256",code:18,encode:Nt("SHA-256")}),ls=_e({name:"sha2-512",code:19,encode:Nt("SHA-512")});var Pe={};v(Pe,{identity:()=>ys});var Ot=0,ps="identity",Rt=R,ms=r=>z(Ot,Rt(r)),ys={code:Ot,name:ps,encode:Rt,digest:ms};var Mn=new TextEncoder,Nn=new TextDecoder;var g=class{constructor(e,t,s,n){this.code=t,this.version=e,this.multihash=s,this.bytes=n,this.byteOffset=n.byteOffset,this.byteLength=n.byteLength,this.asCID=this,this._baseCache=new Map,Object.defineProperties(this,{byteOffset:pe,byteLength:pe,code:le,version:le,multihash:le,bytes:le,_baseCache:pe,asCID:pe})}toV0(){switch(this.version){case 0:return this;default:{let{code:e,multihash:t}=this;if(e!==ae)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==vs)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return g.createV0(t)}}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,s=z(e,t);return g.createV1(this.code,s)}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&&Dt(this.multihash,e.multihash)}toString(e){let{bytes:t,version:s,_baseCache:n}=this;switch(s){case 0:return xs(t,n,e||O.encoder);default:return Cs(t,n,e||J.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 Ss(/^0\.0/,Fs),!!(e&&(e[_t]||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 g)return e;if(e!=null&&e.asCID===e){let{version:t,code:s,multihash:n,bytes:o}=e;return new g(t,s,n,o||Ut(t,s,n.bytes))}else if(e!=null&&e[_t]===!0){let{version:t,multihash:s,code:n}=e,o=jt(s);return g.create(t,n,o)}else return null}static create(e,t,s){if(typeof t!="number")throw new Error("String codecs are no longer supported");switch(e){case 0:{if(t!==ae)throw new Error(`Version 0 CID must use dag-pb (code: ${ae}) block encoding`);return new g(e,t,s,s.bytes)}case 1:{let n=Ut(e,t,s.bytes);return new g(e,t,s,n)}default:throw new Error("Invalid version")}}static createV0(e){return g.create(0,ae,e)}static createV1(e,t){return g.create(1,e,t)}static decode(e){let[t,s]=g.decodeFirst(e);if(s.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=g.inspectBytes(e),s=t.size-t.multihashSize,n=R(e.subarray(s,s+t.multihashSize));if(n.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=n.subarray(t.multihashSize-t.digestSize),i=new ie(t.multihashCode,t.digestSize,o,n);return[t.version===0?g.createV0(i):g.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,s=()=>{let[f,p]=oe(e.subarray(t));return t+=p,f},n=s(),o=ae;if(n===18?(n=0,t=0):n===1&&(o=s()),n!==0&&n!==1)throw new RangeError(`Invalid CID version ${n}`);let i=t,u=s(),b=s(),k=t+b,c=k-i;return{version:n,codec:o,multihashCode:u,digestSize:b,multihashSize:c,size:k}}static parse(e,t){let[s,n]=ws(e,t),o=g.decode(n);return o._baseCache.set(s,e),o}},ws=(r,e)=>{switch(r[0]){case"Q":{let t=e||O;return[O.prefix,t.decode(`${O.prefix}${r}`)]}case O.prefix:{let t=e||O;return[O.prefix,t.decode(r)]}case J.prefix:{let t=e||J;return[J.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)]}}},xs=(r,e,t)=>{let{prefix:s}=t;if(s!==O.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let n=e.get(s);if(n==null){let o=t.encode(r).slice(1);return e.set(s,o),o}else return n},Cs=(r,e,t)=>{let{prefix:s}=t,n=e.get(s);if(n==null){let o=t.encode(r);return e.set(s,o),o}else return n},ae=112,vs=18,Ut=(r,e,t)=>{let s=H(r),n=s+H(e),o=new Uint8Array(n+t.byteLength);return G(r,o,0),G(e,o,s),o.set(t,n),o},_t=Symbol.for("@ipld/js-cid/CID"),le={writable:!1,configurable:!1,enumerable:!0},pe={writable:!1,enumerable:!1,configurable:!1},Es="0.0.0-dev",Ss=(r,e)=>{if(r.test(Es))console.warn(e);else throw new Error(e)},Fs=`CID.isCID(v) is deprecated and will be removed in the next major release.
Following code pattern:

@@ -16,3 +16,3 @@

}
`;var Te={...je,...De,...Ie,...ke,...Me,...Ne,...Oe,...Re,..._e},Pn={...Le,...Pe};function _t(r,e,t,s){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:s}}}var Ut=_t("utf8","u",r=>{let e=new TextDecoder("utf8");return"u"+e.decode(r)},r=>new TextEncoder().encode(r.substring(1))),ze=_t("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),vs={utf8:Ut,"utf-8":Ut,hex:Te.base16,latin1:ze,ascii:ze,binary:ze,...Te},ye=vs;function Lt(r,e="utf8"){let t=ye[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}function Pt(r,e="utf8"){let t=ye[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var _="/",Tt=new TextEncoder().encode(_),be=Tt[0],l=class{constructor(e,t){if(typeof e=="string")this._buf=Pt(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==be)throw new Error("Invalid key")}toString(e="utf8"){return Lt(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new l(e.join(_))}static random(){return new l(dt().replace(/-/g,""))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new l(e):e.uint8Array?new l(e.uint8Array()):null}clean(){if((!this._buf||this._buf.byteLength===0)&&(this._buf=Tt),this._buf[0]!==be){let e=new Uint8Array(this._buf.byteLength+1);e.fill(be,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===be;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),s=e.list();for(let n=0;n<t.length;n++){if(s.length<n+1)return!1;let o=t[n],i=s[n];if(o<i)return!0;if(o>i)return!1}return t.length<s.length}reverse(){return l.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(_).slice(1)}type(){return Es(this.baseNamespace())}name(){return Ss(this.baseNamespace())}instance(e){return new l(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(_)||(e+=_),e+=this.type(),new l(e)}parent(){let e=this.list();return e.length===1?new l(_):new l(e.slice(0,-1).join(_))}child(e){return this.toString()===_?e:e.toString()===_?this:new l(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return l.withNamespaces([...this.namespaces(),...Fs(e.map(t=>t.namespaces()))])}};function Es(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Ss(r){let e=r.split(":");return e[e.length-1]}function Fs(r){return[].concat(...r)}var we=`This is a repository of IPLD objects. Each IPLD object is in a single file,
`;var Te={...Ae,...je,...De,...Ie,...ke,...Me,...Ne,...Oe,...Re},Kn={...Le,...Pe};function Lt(r,e,t,s){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:s}}}var Pt=Lt("utf8","u",r=>{let e=new TextDecoder("utf8");return"u"+e.decode(r)},r=>new TextEncoder().encode(r.substring(1))),ze=Lt("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),As={utf8:Pt,"utf-8":Pt,hex:Te.base16,latin1:ze,ascii:ze,binary:ze,...Te},me=As;function Tt(r,e="utf8"){let t=me[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}function zt(r,e="utf8"){let t=me[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var U="/",Bt=new TextEncoder().encode(U),ye=Bt[0],l=class{constructor(e,t){if(typeof e=="string")this._buf=zt(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==ye)throw new Error("Invalid key")}toString(e="utf8"){return Tt(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new l(e.join(U))}static random(){return new l(dt().replace(/-/g,""))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new l(e):e.uint8Array?new l(e.uint8Array()):null}clean(){if((!this._buf||this._buf.byteLength===0)&&(this._buf=Bt),this._buf[0]!==ye){let e=new Uint8Array(this._buf.byteLength+1);e.fill(ye,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===ye;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),s=e.list();for(let n=0;n<t.length;n++){if(s.length<n+1)return!1;let o=t[n],i=s[n];if(o<i)return!0;if(o>i)return!1}return t.length<s.length}reverse(){return l.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(U).slice(1)}type(){return js(this.baseNamespace())}name(){return Ds(this.baseNamespace())}instance(e){return new l(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(U)||(e+=U),e+=this.type(),new l(e)}parent(){let e=this.list();return e.length===1?new l(U):new l(e.slice(0,-1).join(U))}child(e){return this.toString()===U?e:e.toString()===U?this:new l(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return l.withNamespaces([...this.namespaces(),...Is(e.map(t=>t.namespaces()))])}};function js(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Ds(r){let e=r.split(":");return e[e.length-1]}function Is(r){return[].concat(...r)}var be=`This is a repository of IPLD objects. Each IPLD object is in a single file,
named <base32 encoding of cid>.data. Where <base32 encoding of cid> is the

@@ -39,4 +39,4 @@ "base32" encoding of the CID (as specified in

stored in the filename.
`;var ge="/repo/flatfs/shard/",xe="SHARDING",Be="_README",ce=class{constructor(e){this.param=e,this.name="base",this._padding=""}fun(e){return"implement me"}toString(){return`${ge}v1/${this.name}/${this.param}`}},Ke=class extends ce{constructor(e){super(e);this._padding="".padStart(e,"_"),this.name="prefix"}fun(e){return(e+this._padding).slice(0,this.param)}},$e=class extends ce{constructor(e){super(e);this._padding="".padStart(e,"_"),this.name="suffix"}fun(e){let t=this._padding+e;return t.slice(t.length-this.param)}},Ve=class extends ce{constructor(e){super(e);this._padding="".padStart(e+1,"_"),this.name="next-to-last"}fun(e){let t=this._padding+e,s=t.length-this.param-1;return t.slice(s,s+this.param)}};function zt(r){if(r=r.trim(),r.length===0)throw new Error("empty shard string");if(!r.startsWith(ge))throw new Error(`invalid or no path prefix: ${r}`);let e=r.slice(ge.length).split("/"),t=e[0];if(t!=="v1")throw new Error(`expect 'v1' version, got '${t}'`);let s=e[1];if(!e[2])throw new Error("missing param");let n=parseInt(e[2],10);switch(s){case"prefix":return new Ke(n);case"suffix":return new $e(n);case"next-to-last":return new Ve(n);default:throw new Error(`unkown sharding function: ${s}`)}}var Ce=async(r,e)=>{let t=new l(r).child(new l(xe)),n=await(typeof e.getRaw=="function"?e.getRaw.bind(e):e.get.bind(e))(t);return zt(new TextDecoder().decode(n||"").trim())};var $t=S(Kt()),H=(r,e)=>async function*(){yield*(await(0,$t.default)(r)).sort(e)}();var Xe=S(Je()),z=S(Ge()),Ye=S(He()),F=class{open(){return Promise.reject(new Error(".open is not implemented"))}close(){return Promise.reject(new Error(".close is not implemented"))}put(e,t,s){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:s,value:n}of e)await this.put(s,n,t),yield{key:s,value:n}}async*getMany(e,t={}){for await(let s of e)yield this.get(s,t)}async*deleteMany(e,t={}){for await(let s of e)await this.delete(s,t),yield s}batch(){let e=[],t=[];return{put(s,n){e.push({key:s,value:n})},delete(s){t.push(s)},commit:async s=>{await(0,Xe.default)(this.putMany(e,s)),e=[],await(0,Xe.default)(this.deleteMany(t,s)),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 s=this._all(e,t);if(e.prefix!=null&&(s=(0,z.default)(s,n=>n.key.toString().startsWith(e.prefix))),Array.isArray(e.filters)&&(s=e.filters.reduce((n,o)=>(0,z.default)(n,o),s)),Array.isArray(e.orders)&&(s=e.orders.reduce((n,o)=>H(n,o),s)),e.offset!=null){let n=0;s=(0,z.default)(s,()=>n++>=e.offset)}return e.limit!=null&&(s=(0,Ye.default)(s,e.limit)),s}queryKeys(e,t){let s=this._allKeys(e,t);if(e.prefix!=null&&(s=(0,z.default)(s,n=>n.toString().startsWith(e.prefix))),Array.isArray(e.filters)&&(s=e.filters.reduce((n,o)=>(0,z.default)(n,o),s)),Array.isArray(e.orders)&&(s=e.orders.reduce((n,o)=>H(n,o),s)),e.offset!=null){let n=0;s=(0,z.default)(s,()=>n++>=e.offset)}return e.limit!=null&&(s=(0,Ye.default)(s,e.limit)),s}};var Ze=class extends F{constructor(){super();this.data={}}open(){return Promise.resolve()}close(){return Promise.resolve()}async put(e,t){this.data[e.toString()]=t}async get(e){if(!await this.has(e))throw T();return this.data[e.toString()]}async has(e){return this.data[e.toString()]!==void 0}async delete(e){delete this.data[e.toString()]}async*_all(){yield*Object.entries(this.data).map(([e,t])=>({key:new l(e),value:t}))}async*_allKeys(){yield*Object.entries(this.data).map(([e])=>new l(e))}};var L=S(Ht()),Ee=S(Zt()),B=class extends F{constructor(e,t){super();this.child=e,this.transform=t}open(){return this.child.open()}put(e,t,s){return this.child.put(this.transform.convert(e),t,s)}get(e,t){return this.child.get(this.transform.convert(e),t)}has(e,t){return this.child.has(this.transform.convert(e),t)}delete(e,t){return this.child.delete(this.transform.convert(e),t)}async*putMany(e,t={}){let s=this.transform,n=this.child;yield*(0,Ee.pipe)(e,async function*(o){yield*(0,L.default)(o,({key:i,value:u})=>({key:s.convert(i),value:u}))},async function*(o){yield*n.putMany(o,t)},async function*(o){yield*(0,L.default)(o,({key:i,value:u})=>({key:s.invert(i),value:u}))})}async*getMany(e,t={}){let s=this.transform,n=this.child;yield*(0,Ee.pipe)(e,async function*(o){yield*(0,L.default)(o,i=>s.convert(i))},async function*(o){yield*n.getMany(o,t)})}async*deleteMany(e,t={}){let s=this.transform,n=this.child;yield*(0,Ee.pipe)(e,async function*(o){yield*(0,L.default)(o,i=>s.convert(i))},async function*(o){yield*n.deleteMany(o,t)},async function*(o){yield*(0,L.default)(o,i=>s.invert(i))})}batch(){let e=this.child.batch();return{put:(t,s)=>{e.put(this.transform.convert(t),s)},delete:t=>{e.delete(this.transform.convert(t))},commit:t=>e.commit(t)}}query(e,t){let s={...e};s.filters=(s.filters||[]).map(o=>({key:i,value:u})=>o({key:this.transform.convert(i),value:u}));let{prefix:n}=e;return n!=null&&n!=="/"&&(delete s.prefix,s.filters.push(({key:o})=>this.transform.invert(o).toString().startsWith(n))),s.orders&&(s.orders=s.orders.map(o=>(i,u)=>o({key:this.transform.invert(i.key),value:i.value},{key:this.transform.invert(u.key),value:u.value}))),(0,L.default)(this.child.query(s,t),({key:o,value:i})=>({key:this.transform.invert(o),value:i}))}queryKeys(e,t){let s={...e};s.filters=(s.filters||[]).map(o=>i=>o(this.transform.convert(i)));let{prefix:n}=e;return n!=null&&n!=="/"&&(delete s.prefix,s.filters.push(o=>this.transform.invert(o).toString().startsWith(n))),s.orders&&(s.orders=s.orders.map(o=>(i,u)=>o(this.transform.invert(i),this.transform.invert(u)))),(0,L.default)(this.child.queryKeys(s,t),o=>this.transform.invert(o))}close(){return this.child.close()}};var Y=new l(xe),ue=new l(Be),P=class extends F{constructor(e,t){super();this.child=new B(e,{convert:this._convertKey.bind(this),invert:this._invertKey.bind(this)}),this.shard=t}async open(){await this.child.open(),this.shard=await P.create(this.child,this.shard)}_convertKey(e){let t=e.toString();return t===Y.toString()||t===ue.toString()?e:new l(this.shard.fun(t)).child(e)}_invertKey(e){let t=e.toString();return t===Y.toString()||t===ue.toString()?e:l.withNamespaces(e.list().slice(1))}static async createOrOpen(e,t){try{await P.create(e,t)}catch(s){if(s&&s.message!=="datastore exists")throw s}return P.open(e)}static async open(e){let t=await Ce("/",e);return new P(e,t)}static async create(e,t){let s=await e.has(Y);if(!s&&!t)throw ee(Error("Shard is required when datastore doesn't have a shard key already."));if(!s){let u=typeof e.putRaw=="function"?e.putRaw.bind(e):e.put.bind(e);return await Promise.all([u(Y,new TextEncoder().encode(t.toString()+`
`)),u(ue,new TextEncoder().encode(we))]),t}let n=await Ce("/",e),o=(n||"").toString(),i=t.toString();if(o!==i)throw new Error(`specified fun ${i} does not match repo shard fun ${o}`);return n}put(e,t,s){return this.child.put(e,t,s)}get(e,t){return this.child.get(e,t)}has(e,t){return this.child.has(e,t)}delete(e,t){return this.child.delete(e,t)}async*putMany(e,t={}){yield*this.child.putMany(e,t)}async*getMany(e,t={}){yield*this.child.getMany(e,t)}async*deleteMany(e,t={}){yield*this.child.deleteMany(e,t)}batch(){return this.child.batch()}query(e,t){let s={...e,filters:[({key:n})=>n.toString()!==Y.toString(),({key:n})=>n.toString()!==ue.toString()].concat(e.filters||[])};return this.child.query(s,t)}queryKeys(e,t){let s={...e,filters:[n=>n.toString()!==Y.toString(),n=>n.toString()!==ue.toString()].concat(e.filters||[])};return this.child.queryKeys(s,t)}close(){return this.child.close()}};var fe=S(Ge()),tt=S(He()),rt=S(or());var st=class extends F{constructor(e){super();this.mounts=e.slice()}async open(){await Promise.all(this.mounts.map(e=>e.datastore.open()))}_lookup(e){for(let t of this.mounts)if(t.prefix.toString()===e.toString()||t.prefix.isAncestorOf(e))return{datastore:t.datastore,mountpoint:t.prefix}}put(e,t,s){let n=this._lookup(e);if(n==null)throw re(new Error("No datastore mounted for this key"));return n.datastore.put(e,t,s)}get(e,t){let s=this._lookup(e);if(s==null)throw T(new Error("No datastore mounted for this key"));return s.datastore.get(e,t)}has(e,t){let s=this._lookup(e);return s==null?Promise.resolve(!1):s.datastore.has(e,t)}delete(e,t){let s=this._lookup(e);if(s==null)throw te(new Error("No datastore mounted for this key"));return s.datastore.delete(e,t)}async close(){await Promise.all(this.mounts.map(e=>e.datastore.close()))}batch(){let e={},t=s=>{let n=this._lookup(s);if(n==null)throw new Error("No datastore mounted for this key");let o=n.mountpoint.toString();return e[o]==null&&(e[o]=n.datastore.batch()),{batch:e[o]}};return{put:(s,n)=>{t(s).batch.put(s,n)},delete:s=>{t(s).batch.delete(s)},commit:async s=>{await Promise.all(Object.keys(e).map(n=>e[n].commit(s)))}}}query(e,t){let s=this.mounts.map(o=>o.datastore.query({prefix:e.prefix,filters:e.filters},t)),n=(0,rt.default)(...s);if(e.filters&&e.filters.forEach(o=>{n=(0,fe.default)(n,o)}),e.orders&&e.orders.forEach(o=>{n=H(n,o)}),e.offset!=null){let o=0;n=(0,fe.default)(n,()=>o++>=e.offset)}return e.limit!=null&&(n=(0,tt.default)(n,e.limit)),n}queryKeys(e,t){let s=this.mounts.map(o=>o.datastore.queryKeys({prefix:e.prefix,filters:e.filters},t)),n=(0,rt.default)(...s);if(e.filters&&e.filters.forEach(o=>{n=(0,fe.default)(n,o)}),e.orders&&e.orders.forEach(o=>{n=H(n,o)}),e.offset!=null){let o=0;n=(0,fe.default)(n,()=>o++>=e.offset)}return e.limit!=null&&(n=(0,tt.default)(n,e.limit)),n}};var hr=S(fr()),nt=S(et()),ot=S(Je()),Js=(0,hr.default)("datastore:core:tiered"),it=class extends F{constructor(e){super();this.stores=e.slice()}async open(){try{await Promise.all(this.stores.map(e=>e.open()))}catch(e){throw ee()}}async put(e,t){try{await Promise.all(this.stores.map(s=>s.put(e,t)))}catch(s){throw re()}}async get(e,t){for(let s of this.stores)try{let n=await s.get(e,t);if(n)return n}catch(n){Js(n)}throw T()}async has(e,t){for(let s of this.stores)if(await s.has(e,t))return!0;return!1}async delete(e,t){try{await Promise.all(this.stores.map(s=>s.delete(e,t)))}catch(s){throw te()}}async*putMany(e,t={}){let s,n=this.stores.map(o=>{let i=(0,nt.default)();return(0,ot.default)(o.putMany(i,t)).catch(u=>{s=u}),i});try{for await(let o of e){if(s)throw s;n.forEach(i=>i.push(o)),yield o}}finally{n.forEach(o=>o.end())}}async*deleteMany(e,t={}){let s,n=this.stores.map(o=>{let i=(0,nt.default)();return(0,ot.default)(o.deleteMany(i,t)).catch(u=>{s=u}),i});try{for await(let o of e){if(s)throw s;n.forEach(i=>i.push(o)),yield o}}finally{n.forEach(o=>o.end())}}async close(){await Promise.all(this.stores.map(e=>e.close()))}batch(){let e=this.stores.map(t=>t.batch());return{put:(t,s)=>{e.forEach(n=>n.put(t,s))},delete:t=>{e.forEach(s=>s.delete(t))},commit:async t=>{for(let s of e)await s.commit(t)}}}query(e,t){return this.stores[this.stores.length-1].query(e,t)}queryKeys(e,t){return this.stores[this.stores.length-1].queryKeys(e,t)}};var at=class extends B{constructor(e,t){super(e,{convert(s){return t.child(s)},invert(s){if(t.toString()==="/")return s;if(!t.isAncestorOf(s))throw new Error(`Expected prefix: (${t.toString()}) in key: ${s.toString()}`);return new l(s.toString().slice(t.toString().length),!1)}})}};var Gs={...Ae},Hs={...We};return Xs;})();
`;var ge="/repo/flatfs/shard/",we="SHARDING",Be="_README",ce=class{constructor(e){this.param=e,this.name="base",this._padding=""}fun(e){return"implement me"}toString(){return`${ge}v1/${this.name}/${this.param}`}},Ke=class extends ce{constructor(e){super(e);this._padding="".padStart(e,"_"),this.name="prefix"}fun(e){return(e+this._padding).slice(0,this.param)}},$e=class extends ce{constructor(e){super(e);this._padding="".padStart(e,"_"),this.name="suffix"}fun(e){let t=this._padding+e;return t.slice(t.length-this.param)}},Ve=class extends ce{constructor(e){super(e);this._padding="".padStart(e+1,"_"),this.name="next-to-last"}fun(e){let t=this._padding+e,s=t.length-this.param-1;return t.slice(s,s+this.param)}};function Kt(r){if(r=r.trim(),r.length===0)throw new Error("empty shard string");if(!r.startsWith(ge))throw new Error(`invalid or no path prefix: ${r}`);let e=r.slice(ge.length).split("/"),t=e[0];if(t!=="v1")throw new Error(`expect 'v1' version, got '${t}'`);let s=e[1];if(!e[2])throw new Error("missing param");let n=parseInt(e[2],10);switch(s){case"prefix":return new Ke(n);case"suffix":return new $e(n);case"next-to-last":return new Ve(n);default:throw new Error(`unkown sharding function: ${s}`)}}var xe=async(r,e)=>{let t=new l(r).child(new l(we)),n=await(typeof e.getRaw=="function"?e.getRaw.bind(e):e.get.bind(e))(t);return Kt(new TextDecoder().decode(n||"").trim())};var Wt=S(Vt()),X=(r,e)=>async function*(){yield*(await(0,Wt.default)(r)).sort(e)}();var Xe=S(Je()),B=S(Ge()),Ye=S(He()),F=class{open(){return Promise.reject(new Error(".open is not implemented"))}close(){return Promise.reject(new Error(".close is not implemented"))}put(e,t,s){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:s,value:n}of e)await this.put(s,n,t),yield{key:s,value:n}}async*getMany(e,t={}){for await(let s of e)yield this.get(s,t)}async*deleteMany(e,t={}){for await(let s of e)await this.delete(s,t),yield s}batch(){let e=[],t=[];return{put(s,n){e.push({key:s,value:n})},delete(s){t.push(s)},commit:async s=>{await(0,Xe.default)(this.putMany(e,s)),e=[],await(0,Xe.default)(this.deleteMany(t,s)),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 s=this._all(e,t);if(e.prefix!=null&&(s=(0,B.default)(s,n=>n.key.toString().startsWith(e.prefix))),Array.isArray(e.filters)&&(s=e.filters.reduce((n,o)=>(0,B.default)(n,o),s)),Array.isArray(e.orders)&&(s=e.orders.reduce((n,o)=>X(n,o),s)),e.offset!=null){let n=0;s=(0,B.default)(s,()=>n++>=e.offset)}return e.limit!=null&&(s=(0,Ye.default)(s,e.limit)),s}queryKeys(e,t){let s=this._allKeys(e,t);if(e.prefix!=null&&(s=(0,B.default)(s,n=>n.toString().startsWith(e.prefix))),Array.isArray(e.filters)&&(s=e.filters.reduce((n,o)=>(0,B.default)(n,o),s)),Array.isArray(e.orders)&&(s=e.orders.reduce((n,o)=>X(n,o),s)),e.offset!=null){let n=0;s=(0,B.default)(s,()=>n++>=e.offset)}return e.limit!=null&&(s=(0,Ye.default)(s,e.limit)),s}};var Ze=class extends F{constructor(){super();this.data={}}open(){return Promise.resolve()}close(){return Promise.resolve()}async put(e,t){this.data[e.toString()]=t}async get(e){if(!await this.has(e))throw T();return this.data[e.toString()]}async has(e){return this.data[e.toString()]!==void 0}async delete(e){delete this.data[e.toString()]}async*_all(){yield*Object.entries(this.data).map(([e,t])=>({key:new l(e),value:t}))}async*_allKeys(){yield*Object.entries(this.data).map(([e])=>new l(e))}};var L=S(Yt()),ve=S(qt()),K=class extends F{constructor(e,t){super();this.child=e,this.transform=t}open(){return this.child.open()}put(e,t,s){return this.child.put(this.transform.convert(e),t,s)}get(e,t){return this.child.get(this.transform.convert(e),t)}has(e,t){return this.child.has(this.transform.convert(e),t)}delete(e,t){return this.child.delete(this.transform.convert(e),t)}async*putMany(e,t={}){let s=this.transform,n=this.child;yield*(0,ve.pipe)(e,async function*(o){yield*(0,L.default)(o,({key:i,value:u})=>({key:s.convert(i),value:u}))},async function*(o){yield*n.putMany(o,t)},async function*(o){yield*(0,L.default)(o,({key:i,value:u})=>({key:s.invert(i),value:u}))})}async*getMany(e,t={}){let s=this.transform,n=this.child;yield*(0,ve.pipe)(e,async function*(o){yield*(0,L.default)(o,i=>s.convert(i))},async function*(o){yield*n.getMany(o,t)})}async*deleteMany(e,t={}){let s=this.transform,n=this.child;yield*(0,ve.pipe)(e,async function*(o){yield*(0,L.default)(o,i=>s.convert(i))},async function*(o){yield*n.deleteMany(o,t)},async function*(o){yield*(0,L.default)(o,i=>s.invert(i))})}batch(){let e=this.child.batch();return{put:(t,s)=>{e.put(this.transform.convert(t),s)},delete:t=>{e.delete(this.transform.convert(t))},commit:t=>e.commit(t)}}query(e,t){let s={...e};s.filters=(s.filters||[]).map(o=>({key:i,value:u})=>o({key:this.transform.convert(i),value:u}));let{prefix:n}=e;return n!=null&&n!=="/"&&(delete s.prefix,s.filters.push(({key:o})=>this.transform.invert(o).toString().startsWith(n))),s.orders&&(s.orders=s.orders.map(o=>(i,u)=>o({key:this.transform.invert(i.key),value:i.value},{key:this.transform.invert(u.key),value:u.value}))),(0,L.default)(this.child.query(s,t),({key:o,value:i})=>({key:this.transform.invert(o),value:i}))}queryKeys(e,t){let s={...e};s.filters=(s.filters||[]).map(o=>i=>o(this.transform.convert(i)));let{prefix:n}=e;return n!=null&&n!=="/"&&(delete s.prefix,s.filters.push(o=>this.transform.invert(o).toString().startsWith(n))),s.orders&&(s.orders=s.orders.map(o=>(i,u)=>o(this.transform.invert(i),this.transform.invert(u)))),(0,L.default)(this.child.queryKeys(s,t),o=>this.transform.invert(o))}close(){return this.child.close()}};var Z=new l(we),ue=new l(Be),P=class extends F{constructor(e,t){super();this.child=new K(e,{convert:this._convertKey.bind(this),invert:this._invertKey.bind(this)}),this.shard=t}async open(){await this.child.open(),this.shard=await P.create(this.child,this.shard)}_convertKey(e){let t=e.toString();return t===Z.toString()||t===ue.toString()?e:new l(this.shard.fun(t)).child(e)}_invertKey(e){let t=e.toString();return t===Z.toString()||t===ue.toString()?e:l.withNamespaces(e.list().slice(1))}static async createOrOpen(e,t){try{await P.create(e,t)}catch(s){if(s&&s.message!=="datastore exists")throw s}return P.open(e)}static async open(e){let t=await xe("/",e);return new P(e,t)}static async create(e,t){let s=await e.has(Z);if(!s&&!t)throw te(Error("Shard is required when datastore doesn't have a shard key already."));if(!s){let u=typeof e.putRaw=="function"?e.putRaw.bind(e):e.put.bind(e);return await Promise.all([u(Z,new TextEncoder().encode(t.toString()+`
`)),u(ue,new TextEncoder().encode(be))]),t}let n=await xe("/",e),o=(n||"").toString(),i=t.toString();if(o!==i)throw new Error(`specified fun ${i} does not match repo shard fun ${o}`);return n}put(e,t,s){return this.child.put(e,t,s)}get(e,t){return this.child.get(e,t)}has(e,t){return this.child.has(e,t)}delete(e,t){return this.child.delete(e,t)}async*putMany(e,t={}){yield*this.child.putMany(e,t)}async*getMany(e,t={}){yield*this.child.getMany(e,t)}async*deleteMany(e,t={}){yield*this.child.deleteMany(e,t)}batch(){return this.child.batch()}query(e,t){let s={...e,filters:[({key:n})=>n.toString()!==Z.toString(),({key:n})=>n.toString()!==ue.toString()].concat(e.filters||[])};return this.child.query(s,t)}queryKeys(e,t){let s={...e,filters:[n=>n.toString()!==Z.toString(),n=>n.toString()!==ue.toString()].concat(e.filters||[])};return this.child.queryKeys(s,t)}close(){return this.child.close()}};var fe=S(Ge()),tt=S(He()),rt=S(ar());var st=class extends F{constructor(e){super();this.mounts=e.slice()}async open(){await Promise.all(this.mounts.map(e=>e.datastore.open()))}_lookup(e){for(let t of this.mounts)if(t.prefix.toString()===e.toString()||t.prefix.isAncestorOf(e))return{datastore:t.datastore,mountpoint:t.prefix}}put(e,t,s){let n=this._lookup(e);if(n==null)throw se(new Error("No datastore mounted for this key"));return n.datastore.put(e,t,s)}get(e,t){let s=this._lookup(e);if(s==null)throw T(new Error("No datastore mounted for this key"));return s.datastore.get(e,t)}has(e,t){let s=this._lookup(e);return s==null?Promise.resolve(!1):s.datastore.has(e,t)}delete(e,t){let s=this._lookup(e);if(s==null)throw re(new Error("No datastore mounted for this key"));return s.datastore.delete(e,t)}async close(){await Promise.all(this.mounts.map(e=>e.datastore.close()))}batch(){let e={},t=s=>{let n=this._lookup(s);if(n==null)throw new Error("No datastore mounted for this key");let o=n.mountpoint.toString();return e[o]==null&&(e[o]=n.datastore.batch()),{batch:e[o]}};return{put:(s,n)=>{t(s).batch.put(s,n)},delete:s=>{t(s).batch.delete(s)},commit:async s=>{await Promise.all(Object.keys(e).map(n=>e[n].commit(s)))}}}query(e,t){let s=this.mounts.map(o=>o.datastore.query({prefix:e.prefix,filters:e.filters},t)),n=(0,rt.default)(...s);if(e.filters&&e.filters.forEach(o=>{n=(0,fe.default)(n,o)}),e.orders&&e.orders.forEach(o=>{n=X(n,o)}),e.offset!=null){let o=0;n=(0,fe.default)(n,()=>o++>=e.offset)}return e.limit!=null&&(n=(0,tt.default)(n,e.limit)),n}queryKeys(e,t){let s=this.mounts.map(o=>o.datastore.queryKeys({prefix:e.prefix,filters:e.filters},t)),n=(0,rt.default)(...s);if(e.filters&&e.filters.forEach(o=>{n=(0,fe.default)(n,o)}),e.orders&&e.orders.forEach(o=>{n=X(n,o)}),e.offset!=null){let o=0;n=(0,fe.default)(n,()=>o++>=e.offset)}return e.limit!=null&&(n=(0,tt.default)(n,e.limit)),n}};var lr=S(dr()),nt=S(et()),ot=S(Je()),Ys=(0,lr.default)("datastore:core:tiered"),it=class extends F{constructor(e){super();this.stores=e.slice()}async open(){try{await Promise.all(this.stores.map(e=>e.open()))}catch(e){throw te()}}async put(e,t){try{await Promise.all(this.stores.map(s=>s.put(e,t)))}catch(s){throw se()}}async get(e,t){for(let s of this.stores)try{let n=await s.get(e,t);if(n)return n}catch(n){Ys(n)}throw T()}async has(e,t){for(let s of this.stores)if(await s.has(e,t))return!0;return!1}async delete(e,t){try{await Promise.all(this.stores.map(s=>s.delete(e,t)))}catch(s){throw re()}}async*putMany(e,t={}){let s,n=this.stores.map(o=>{let i=(0,nt.default)();return(0,ot.default)(o.putMany(i,t)).catch(u=>{s=u}),i});try{for await(let o of e){if(s)throw s;n.forEach(i=>i.push(o)),yield o}}finally{n.forEach(o=>o.end())}}async*deleteMany(e,t={}){let s,n=this.stores.map(o=>{let i=(0,nt.default)();return(0,ot.default)(o.deleteMany(i,t)).catch(u=>{s=u}),i});try{for await(let o of e){if(s)throw s;n.forEach(i=>i.push(o)),yield o}}finally{n.forEach(o=>o.end())}}async close(){await Promise.all(this.stores.map(e=>e.close()))}batch(){let e=this.stores.map(t=>t.batch());return{put:(t,s)=>{e.forEach(n=>n.put(t,s))},delete:t=>{e.forEach(s=>s.delete(t))},commit:async t=>{for(let s of e)await s.commit(t)}}}query(e,t){return this.stores[this.stores.length-1].query(e,t)}queryKeys(e,t){return this.stores[this.stores.length-1].queryKeys(e,t)}};var at=class extends K{constructor(e,t){super(e,{convert(s){return t.child(s)},invert(s){if(t.toString()==="/")return s;if(!t.isAncestorOf(s))throw new Error(`Expected prefix: (${t.toString()}) in key: ${s.toString()}`);return new l(s.toString().slice(t.toString().length),!1)}})}};var Zs=Fe,Qs=We;return qs;})();
return DatastoreCore}));
{
"name": "datastore-core",
"version": "7.0.0",
"version": "7.0.1",
"description": "Wrapper implementation for interface-datastore",

@@ -5,0 +5,0 @@ "author": "Friedel Ziegelmayer <dignifiedquire@gmail.com>",

@@ -8,23 +8,8 @@ export { BaseDatastore } from "./base.js";

export { NamespaceDatastore } from "./namespace.js";
export const Errors: {
dbOpenFailedError(err?: Error | undefined): Error & import("err-code").Extensions;
dbDeleteFailedError(err?: Error | undefined): Error & import("err-code").Extensions;
dbWriteFailedError(err?: Error | undefined): Error & import("err-code").Extensions;
notFoundError(err?: Error | undefined): Error & import("err-code").Extensions;
abortedError(err?: Error | undefined): Error & import("err-code").Extensions;
};
export const shard: {
parseShardFun(str: string): import("./types").Shard;
PREFIX: "/repo/flatfs/shard/";
SHARDING_FN: "SHARDING";
README_FN: "_README";
ShardBase: typeof ShardImport.ShardBase;
Prefix: typeof ShardImport.Prefix;
Suffix: typeof ShardImport.Suffix;
NextToLast: typeof ShardImport.NextToLast;
readShardFun: (path: string | Uint8Array, store: import("interface-datastore").Datastore) => Promise<import("./types").Shard>;
readme: "This is a repository of IPLD objects. Each IPLD object is in a single file,\nnamed <base32 encoding of cid>.data. Where <base32 encoding of cid> is the\n\"base32\" encoding of the CID (as specified in\nhttps://github.com/multiformats/multibase) without the 'B' prefix.\nAll the object files are placed in a tree of directories, based on a\nfunction of the CID. This is a form of sharding similar to\nthe objects directory in git repositories. Previously, we used\nprefixes, we now use the next-to-last two charters.\n func NextToLast(base32cid string) {\n nextToLastLen := 2\n offset := len(base32cid) - nextToLastLen - 1\n return str[offset : offset+nextToLastLen]\n }\nFor example, an object with a base58 CIDv1 of\n zb2rhYSxw4ZjuzgCnWSt19Q94ERaeFhu9uSqRgjSdx9bsgM6f\nhas a base32 CIDv1 of\n BAFKREIA22FLID5AJ2KU7URG47MDLROZIH6YF2KALU2PWEFPVI37YLKRSCA\nand will be placed at\n SC/AFKREIA22FLID5AJ2KU7URG47MDLROZIH6YF2KALU2PWEFPVI37YLKRSCA.data\nwith 'SC' being the last-to-next two characters and the 'B' at the\nbeginning of the CIDv1 string is the multibase prefix that is not\nstored in the filename.\n";
};
export const Errors: typeof ErrorsImport;
export const shard: typeof ShardImport;
export type Shard = import("./types").Shard;
export type KeyTransform = import("./types").KeyTransform;
import * as ErrorsImport from "./errors.js";
import * as ShardImport from "./shard.js";
//# sourceMappingURL=index.d.ts.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc