interface-datastore
Version:
5 lines (4 loc) • 20.2 kB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.InterfaceDatastore = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var InterfaceDatastore=(()=>{var Q=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var Je=Object.prototype.hasOwnProperty;var h=(t,e)=>{for(var r in e)Q(t,r,{get:e[r],enumerable:!0})},Ke=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Re(e))!Je.call(t,o)&&o!==r&&Q(t,o,{get:()=>e[o],enumerable:!(n=qe(e,o))||n.enumerable});return t};var Xe=t=>Ke(Q({},"__esModule",{value:!0}),t);var or={};h(or,{Key:()=>K});var Y={};h(Y,{base10:()=>_e});var sr=new Uint8Array(0);function me(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}function v(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")}function xe(t){return new TextEncoder().encode(t)}function ge(t){return new TextDecoder().decode(t)}function Qe(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 i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var f=t.length,u=t.charAt(0),A=Math.log(f)/Math.log(256),I=Math.log(256)/Math.log(f);function X(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 p=0,U=0,l=0,m=a.length;l!==m&&a[l]===0;)l++,p++;for(var x=(m-l)*I+1>>>0,d=new Uint8Array(x);l!==m;){for(var g=a[l],C=0,b=x-1;(g!==0||C<U)&&b!==-1;b--,C++)g+=256*d[b]>>>0,d[b]=g%f>>>0,g=g/f>>>0;if(g!==0)throw new Error("Non-zero carry");U=C,l++}for(var y=x-U;y!==x&&d[y]===0;)y++;for(var j=u.repeat(p);y<x;++y)j+=t.charAt(d[y]);return j}function F(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var p=0;if(a[p]!==" "){for(var U=0,l=0;a[p]===u;)U++,p++;for(var m=(a.length-p)*A+1>>>0,x=new Uint8Array(m);a[p];){var d=r[a.charCodeAt(p)];if(d===255)return;for(var g=0,C=m-1;(d!==0||g<l)&&C!==-1;C--,g++)d+=f*x[C]>>>0,x[C]=d%256>>>0,d=d/256>>>0;if(d!==0)throw new Error("Non-zero carry");l=g,p++}if(a[p]!==" "){for(var b=m-l;b!==m&&x[b]===0;)b++;for(var y=new Uint8Array(U+(m-b)),j=U;b!==m;)y[j++]=x[b++];return y}}}function ke(a){var p=F(a);if(p)return p;throw new Error(`Non-${e} character`)}return{encode:X,decodeUnsafe:F,decode:ke}}var We=Qe,Ge=We,ye=Ge;var W=class{name;prefix;baseEncode;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")}},G=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,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 ve(this,e)}},H=class{decoders;constructor(e){this.decoders=e}or(e){return ve(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ve(t,e){return new H({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Z=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new W(e,r,n),this.decoder=new G(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function z({name:t,prefix:e,encode:r,decode:n}){return new Z(t,e,r,n)}function E({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=ye(r,t);return z({prefix:e,name:t,encode:n,decode:i=>v(o(i))})}function He(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,f=0,u=0;for(let A=0;A<o;++A){let I=e[t[A]];if(I===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<r|I,s+=r,s>=8&&(s-=8,i[u++]=255&f>>s)}if(s>=r||(255&f<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Ze(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,f=0;for(let u=0;u<t.length;++u)for(f=f<<8|t[u],s+=8;s>r;)s-=r,i+=e[o&f>>s];if(s!==0&&(i+=e[o&f<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Ye(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function c({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Ye(n);return z({prefix:e,name:t,encode(i){return Ze(i,n,r)},decode(i){return He(i,o,r,t)}})}var _e=E({prefix:"9",name:"base10",alphabet:"0123456789"});var _={};h(_,{base16:()=>et,base16upper:()=>tt});var et=c({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),tt=c({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ee={};h(ee,{base2:()=>rt});var rt=c({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var te={};h(te,{base256emoji:()=>at});var Se=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),nt=Se.reduce((t,e,r)=>(t[r]=e,t),[]),ot=Se.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function it(t){return t.reduce((e,r)=>(e+=nt[r],e),"")}function st(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=ot[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var at=z({prefix:"\u{1F680}",name:"base256emoji",encode:it,decode:st});var re={};h(re,{base32:()=>N,base32hex:()=>ht,base32hexpad:()=>ut,base32hexpadupper:()=>lt,base32hexupper:()=>dt,base32pad:()=>ft,base32padupper:()=>pt,base32upper:()=>ct,base32z:()=>bt});var N=c({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ct=c({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ft=c({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),pt=c({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ht=c({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),dt=c({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ut=c({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),lt=c({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),bt=c({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ne={};h(ne,{base36:()=>L,base36upper:()=>mt});var L=E({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),mt=E({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var oe={};h(oe,{base58btc:()=>w,base58flickr:()=>xt});var w=E({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xt=E({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ie={};h(ie,{base64:()=>gt,base64pad:()=>wt,base64url:()=>yt,base64urlpad:()=>vt});var gt=c({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),wt=c({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),yt=c({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),vt=c({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var se={};h(se,{base8:()=>St});var St=c({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ae={};h(ae,{identity:()=>At});var At=z({prefix:"\0",name:"identity",encode:t=>ge(t),decode:t=>xe(t)});var Sr=new TextEncoder,Ar=new TextDecoder;var fe={};h(fe,{identity:()=>Xt});var Ut=Ee,Ae=128,Dt=127,It=~Dt,zt=Math.pow(2,31);function Ee(t,e,r){e=e||[],r=r||0;for(var n=r;t>=zt;)e[r++]=t&255|Ae,t/=128;for(;t&It;)e[r++]=t&255|Ae,t>>>=7;return e[r]=t|0,Ee.bytes=r-n+1,e}var Nt=ce,Tt=128,Ce=127;function ce(t,n){var r=0,n=n||0,o=0,i=n,s,f=t.length;do{if(i>=f)throw ce.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Ce)<<o:(s&Ce)*Math.pow(2,o),o+=7}while(s>=Tt);return ce.bytes=i-n,r}var Mt=Math.pow(2,7),Ot=Math.pow(2,14),Lt=Math.pow(2,21),Bt=Math.pow(2,28),Vt=Math.pow(2,35),Pt=Math.pow(2,42),$t=Math.pow(2,49),Ft=Math.pow(2,56),jt=Math.pow(2,63),kt=function(t){return t<Mt?1:t<Ot?2:t<Lt?3:t<Bt?4:t<Vt?5:t<Pt?6:t<$t?7:t<Ft?8:t<jt?9:10},qt={encode:Ut,decode:Nt,encodingLength:kt},Rt=qt,B=Rt;function V(t,e=0){return[B.decode(t,e),B.decode.bytes]}function T(t,e,r=0){return B.encode(t,e,r),e}function M(t){return B.encodingLength(t)}function D(t,e){let r=e.byteLength,n=M(t),o=n+M(r),i=new Uint8Array(o+r);return T(t,i,0),T(r,i,n),i.set(e,o),new O(t,r,e,i)}function Ue(t){let e=v(t),[r,n]=V(e),[o,i]=V(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new O(r,o,s,e)}function De(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&me(t.bytes,r.bytes)}}var O=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var Ie=0,Jt="identity",ze=v;function Kt(t){return D(Ie,ze(t))}var Xt={code:Ie,name:Jt,encode:ze,digest:Kt};var de={};h(de,{sha256:()=>Qt,sha512:()=>Wt});function he({name:t,code:e,encode:r}){return new pe(t,e,r)}var pe=class{name;code;encode;constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?D(this.code,r):r.then(n=>D(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Te(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Qt=he({name:"sha2-256",code:18,encode:Te("SHA-256")}),Wt=he({name:"sha2-512",code:19,encode:Te("SHA-512")});function Me(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Ht(r,ue(t),e??w.encoder);default:return Zt(r,ue(t),e??N.encoder)}}var Oe=new WeakMap;function ue(t){let e=Oe.get(t);if(e==null){let r=new Map;return Oe.set(t,r),r}return e}var q=class t{code;version;multihash;bytes;"/";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!==$)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Yt)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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=D(e,r);return t.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 t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&De(e.multihash,n.multihash)}toString(e){return Me(this,e)}toJSON(){return{"/":Me(this)}}link(){return this}[Symbol.toStringTag]="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 t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??Le(n,o,i.bytes))}else if(r[_t]===!0){let{version:n,multihash:o,code:i}=r,s=Ue(o);return t.create(n,i,s)}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!==$)throw new Error(`Version 0 CID must use dag-pb (code: ${$}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Le(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,$,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=v(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new O(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[X,F]=V(e.subarray(r));return r+=F,X},o=n(),i=$;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,f=n(),u=n(),A=r+u,I=A-s;return{version:o,codec:i,multihashCode:f,digestSize:u,multihashSize:I,size:A}}static parse(e,r){let[n,o]=Gt(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ue(i).set(n,e),i}};function Gt(t,e){switch(t[0]){case"Q":{let r=e??w;return[w.prefix,r.decode(`${w.prefix}${t}`)]}case w.prefix:{let r=e??w;return[w.prefix,r.decode(t)]}case N.prefix:{let r=e??N;return[N.prefix,r.decode(t)]}case L.prefix:{let r=e??L;return[L.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Ht(t,e,r){let{prefix:n}=r;if(n!==w.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function Zt(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var $=112,Yt=18;function Le(t,e,r){let n=M(t),o=n+M(e),i=new Uint8Array(o+r.byteLength);return T(t,i,0),T(e,i,n),i.set(r,o),i}var _t=Symbol.for("@ipld/js-cid/CID");var le={...ae,...ee,...se,...Y,..._,...re,...ne,...oe,...ie,...te},Kr={...de,...fe};function Be(t=0){return new Uint8Array(t)}function Pe(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ve=Pe("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),be=Pe("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Be(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),er={utf8:Ve,"utf-8":Ve,hex:le.base16,latin1:be,ascii:be,binary:be,...le},R=er;function $e(t,e="utf8"){let r=R[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Fe(t,e="utf8"){let r=R[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var S="/",je=new TextEncoder().encode(S),J=je[0],K=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=$e(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==J)throw new Error("Invalid key")}toString(e="utf8"){return Fe(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(S))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=je),this._buf[0]!==J){let e=new Uint8Array(this._buf.byteLength+1);e.fill(J,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===J;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let i=r[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(S).slice(1)}type(){return tr(this.baseNamespace())}name(){return rr(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(S)||(e+=S),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(S):new t(e.slice(0,-1).join(S))}child(e){return this.toString()===S?e:e.toString()===S?this:new t(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 t.withNamespaces([...this.namespaces(),...nr(e.map(r=>r.namespaces()))])}};function tr(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function rr(t){let e=t.split(":");return e[e.length-1]}function nr(t){return[].concat(...t)}return Xe(or);})();
return InterfaceDatastore}));
//# sourceMappingURL=index.min.js.map