@note3/utils 0.0.21 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-K5PSO7Y4.min.js → chunk-WMNPGCQZ.min.js} +2 -2
- package/dist/{chunk-K5PSO7Y4.min.js.map → chunk-WMNPGCQZ.min.js.map} +1 -1
- package/dist/index.min.js +1 -1
- package/dist/tree-builder.d.ts +5 -2
- package/dist/tree-builder.d.ts.map +1 -1
- package/dist/tree-builder.min.js +1 -1
- package/package.json +2 -2
|
@@ -58,7 +58,7 @@ ${l}`),G.pop(),`{${R}}`}case"number":return isFinite(j)?String(j):V?V(j):"null";
|
|
|
58
58
|
`+" ".repeat(--t)+s:s===","&&r===0?n+=s+`
|
|
59
59
|
`+" ".repeat(t):s==="{"&&r===0?(r++,n+=s+`
|
|
60
60
|
`+" ".repeat(t+1)):s==="}"&&r===1?(r--,n+=`
|
|
61
|
-
`+" ".repeat(t)+s):s==="{"&&r>0?(r++,n+=s):(s==="}"&&r>1&&r--,n+=s)}return n}function U_(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]instanceof li){if(t[n]!==e[n])return!1}else if(!ut.structural(e[n],t[n]))return!1;return!0}var{WARN:lu,LOG:zw,DEBUG:j_,VERBOSE:qw,ERROR:fn}=xe.setup(xe.INFO,{prefix:"[thread]"});function fi(e){return e.init!==void 0}var li=class{constructor(e,t,n,r=[],i={}){this.name=e,this._applogs=r,this.parents=t===null?null:Oa(t),this.filters=n,Ve(()=>this.parents?.length===0)&&lu("[Thread] empty parents array",e),i.skipObservable||oo(this,{applogsCids:lt,applogsByCid:lt,insert:gt,size:lt,isEmpty:lt,firstLog:lt,latestLog:lt},{name:`Thread{${e}}`})}filters;parents;_subscribers=[];get readOnly(){return this.parents.length!==1?!0:this.parents[0].readOnly}insert(e){if(this.readOnly)throw fn("[Thread] insert() called on read-only thread:",this.nameAndSizeUntracked);if(!this.parents)throw fn("[Thread] insert() called on non-writable thread without parents:",this.nameAndSizeUntracked);if(this.parents?.length!==1)throw fn("[Thread] insert() called on thread with multiple parents:",this.nameAndSizeUntracked);return this.parents[0].insert(e)}insertRaw(e){if(this.readOnly)throw fn("[Thread] insertRaw() called on read-only thread:",this.nameAndSizeUntracked);if(!this.parents)throw fn("[Thread] insertRaw() called on non-writable thread without parents:",this.nameAndSizeUntracked);if(this.parents?.length!==1)throw fn("[Thread] insertRaw() called on thread with multiple parents:",this.nameAndSizeUntracked);return this.parents[0].insertRaw(e)}subscribe(e){return this._subscribers.push(e),this.unsubscribe.bind(this,e)}unsubscribe(e){let t=this._subscribers.indexOf(e);t!==-1?this._subscribers.splice(t,1):lu("unsubscribe called for non-existent",e)}notifySubscribers(e){j_(`[thread: ${this.name}] notifying`,this._subscribers.length,"subscribers of",{...e,subs:this._subscribers});for(let t of this._subscribers)t(e)}get applogs(){return this._applogs}get applogsCids(){return this._applogs.map(e=>e.cid)}map(e){return this.applogs.map(e)}get findLast(){return this.applogs.findLast.bind(this.applogs)}get findFirst(){return this.applogs.find.bind(this.applogs)}get firstLog(){return this.applogs[0]}get latestLog(){return this.applogs[this.applogs.length-1]}hasApplog(e,t){if(t)return this.applogs.includes(e);if(!e.cid)throw fn("[hasApplogs] applog without CID:",e);return this.hasApplogCid(e.cid)}hasApplogCid(e){return this.applogsCids.includes(e.toString())}get applogsByCid(){return new Map(this.applogs.map(e=>[e.cid,e]))}getApplog(e){return this.applogsByCid.get(e.toString())}hasApplogWithDiffTs(e){return this.applogs.find(t=>t.en===e.en&&t.at===e.at&&t.vl===e.vl&&t.ag===e.ag)}get isEmpty(){return this.size===0}get size(){return this.applogs.length}get length(){return this.applogs.length}get untrackedSize(){return Ve(()=>this.size)}get nameAndSizeUntracked(){return Ve(()=>`${this.name} (${this.size})`)}get prettyName(){return x_(this.name)}get hasParents(){return!!this.parents?.length}};var D_={};po(D_,{code:()=>J0,decode:()=>kc,encode:()=>Fc,format:()=>wu,name:()=>H0,parse:()=>Y0,stringify:()=>wu});var M_=["string","number","bigint","symbol"],L_=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function B_(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(M_.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(F_(e))return"Buffer";let n=k_(e);return n||"Object"}function F_(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function k_(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(L_.includes(t))return t}var U=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};U.uint=new U(0,"uint",!0);U.negint=new U(1,"negint",!0);U.bytes=new U(2,"bytes",!0);U.string=new U(3,"string",!0);U.array=new U(4,"array",!1);U.map=new U(5,"map",!1);U.tag=new U(6,"tag",!1);U.float=new U(7,"float",!0);U.false=new U(7,"false",!0);U.true=new U(7,"true",!0);U.null=new U(7,"null",!0);U.undefined=new U(7,"undefined",!0);U.break=new U(7,"break",!0);var re=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}},Gn=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",K_=new TextDecoder,G_=new TextEncoder;function di(e){return Gn&&globalThis.Buffer.isBuffer(e)}function Yo(e){return e instanceof Uint8Array?di(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var V_=Gn?((e,t,n)=>n-t>64?globalThis.Buffer.from(e.subarray(t,n)).toString("utf8"):pu(e,t,n)):((e,t,n)=>n-t>64?K_.decode(e.subarray(t,n)):pu(e,t,n)),Tc=Gn?(e=>e.length>64?globalThis.Buffer.from(e):du(e)):(e=>e.length>64?G_.encode(e):du(e)),Qo=Gn?((e,t,n)=>di(e)?new Uint8Array(e.subarray(t,n)):e.slice(t,n)):((e,t,n)=>e.slice(t,n)),z_=Gn?((e,t)=>(e=e.map(n=>n instanceof Uint8Array?n:globalThis.Buffer.from(n)),Yo(globalThis.Buffer.concat(e,t)))):((e,t)=>{let n=new Uint8Array(t),r=0;for(let i of e)r+i.length>n.length&&(i=i.subarray(0,n.length-r)),n.set(i,r),r+=i.length;return n}),q_=Gn?(e=>globalThis.Buffer.allocUnsafe(e)):(e=>new Uint8Array(e));function W_(e,t){if(di(e)&&di(t))return e.compare(t);for(let n=0;n<e.length;n++)if(e[n]!==t[n])return e[n]<t[n]?-1:1;return 0}function du(e){let t=[],n=0;for(let r=0;r<e.length;r++){let i=e.charCodeAt(r);i<128?t[n++]=i:i<2048?(t[n++]=i>>6|192,t[n++]=i&63|128):(i&64512)===55296&&r+1<e.length&&(e.charCodeAt(r+1)&64512)===56320?(i=65536+((i&1023)<<10)+(e.charCodeAt(++r)&1023),t[n++]=i>>18|240,t[n++]=i>>12&63|128,t[n++]=i>>6&63|128,t[n++]=i&63|128):(t[n++]=i>>12|224,t[n++]=i>>6&63|128,t[n++]=i&63|128)}return t}function pu(e,t,n){let r=[];for(;t<n;){let i=e[t],s=null,o=i>239?4:i>223?3:i>191?2:1;if(t+o<=n){let u,f,c,g;switch(o){case 1:i<128&&(s=i);break;case 2:u=e[t+1],(u&192)===128&&(g=(i&31)<<6|u&63,g>127&&(s=g));break;case 3:u=e[t+1],f=e[t+2],(u&192)===128&&(f&192)===128&&(g=(i&15)<<12|(u&63)<<6|f&63,g>2047&&(g<55296||g>57343)&&(s=g));break;case 4:u=e[t+1],f=e[t+2],c=e[t+3],(u&192)===128&&(f&192)===128&&(c&192)===128&&(g=(i&15)<<18|(u&63)<<12|(f&63)<<6|c&63,g>65535&&g<1114112&&(s=g))}}s===null?(s=65533,o=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),t+=o}return wc(r)}var yu=4096;function wc(e){let t=e.length;if(t<=yu)return String.fromCharCode.apply(String,e);let n="",r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=yu));return n}var H_=256,Oc=class{constructor(e=H_){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let r=t.length-(this.maxCursor-this.cursor)-1;t.set(e,r)}else{if(t){let r=t.length-(this.maxCursor-this.cursor)-1;r<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,r),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=q_(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=Qo(n,0,this.cursor)}else t=z_(this.chunks,this.cursor);return e&&this.reset(),t}},de="CBOR decode error:",pn="CBOR encode error:",_r=[];_r[23]=1;_r[24]=2;_r[25]=3;_r[26]=5;_r[27]=9;function Vn(e,t,n){if(e.length-t<n)throw new Error(`${de} not enough data for type`)}var Me=[24,256,65536,4294967296,BigInt("18446744073709551616")];function gn(e,t,n){Vn(e,t,1);let r=e[t];if(n.strict===!0&&r<Me[0])throw new Error(`${de} integer encoded in more bytes than necessary (strict decode)`);return r}function mn(e,t,n){Vn(e,t,2);let r=e[t]<<8|e[t+1];if(n.strict===!0&&r<Me[1])throw new Error(`${de} integer encoded in more bytes than necessary (strict decode)`);return r}function bn(e,t,n){Vn(e,t,4);let r=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(n.strict===!0&&r<Me[2])throw new Error(`${de} integer encoded in more bytes than necessary (strict decode)`);return r}function vn(e,t,n){Vn(e,t,8);let r=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],i=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],s=(BigInt(r)<<BigInt(32))+BigInt(i);if(n.strict===!0&&s<Me[3])throw new Error(`${de} integer encoded in more bytes than necessary (strict decode)`);if(s<=Number.MAX_SAFE_INTEGER)return Number(s);if(n.allowBigInt===!0)return s;throw new Error(`${de} integers outside of the safe integer range are not supported`)}function J_(e,t,n,r){return new re(U.uint,gn(e,t+1,r),2)}function X_(e,t,n,r){return new re(U.uint,mn(e,t+1,r),3)}function Y_(e,t,n,r){return new re(U.uint,bn(e,t+1,r),5)}function Q_(e,t,n,r){return new re(U.uint,vn(e,t+1,r),9)}function _n(e,t){return pt(e,0,t.value)}function pt(e,t,n){if(n<Me[0]){let r=Number(n);e.push([t|r])}else if(n<Me[1]){let r=Number(n);e.push([t|24,r])}else if(n<Me[2]){let r=Number(n);e.push([t|25,r>>>8,r&255])}else if(n<Me[3]){let r=Number(n);e.push([t|26,r>>>24&255,r>>>16&255,r>>>8&255,r&255])}else{let r=BigInt(n);if(r<Me[4]){let i=[t|27,0,0,0,0,0,0,0],s=Number(r&BigInt(4294967295)),o=Number(r>>BigInt(32)&BigInt(4294967295));i[8]=s&255,s=s>>8,i[7]=s&255,s=s>>8,i[6]=s&255,s=s>>8,i[5]=s&255,i[4]=o&255,o=o>>8,i[3]=o&255,o=o>>8,i[2]=o&255,o=o>>8,i[1]=o&255,e.push(i)}else throw new Error(`${de} encountered BigInt larger than allowable range`)}}_n.encodedSize=function(t){return pt.encodedSize(t.value)};pt.encodedSize=function(t){return t<Me[0]?1:t<Me[1]?2:t<Me[2]?3:t<Me[3]?5:9};_n.compareTokens=function(t,n){return t.value<n.value?-1:t.value>n.value?1:0};function Z_(e,t,n,r){return new re(U.negint,-1-gn(e,t+1,r),2)}function eT(e,t,n,r){return new re(U.negint,-1-mn(e,t+1,r),3)}function tT(e,t,n,r){return new re(U.negint,-1-bn(e,t+1,r),5)}var Zo=BigInt(-1),Ac=BigInt(1);function nT(e,t,n,r){let i=vn(e,t+1,r);if(typeof i!="bigint"){let s=-1-i;if(s>=Number.MIN_SAFE_INTEGER)return new re(U.negint,s,9)}if(r.allowBigInt!==!0)throw new Error(`${de} integers outside of the safe integer range are not supported`);return new re(U.negint,Zo-BigInt(i),9)}function es(e,t){let n=t.value,r=typeof n=="bigint"?n*Zo-Ac:n*-1-1;pt(e,t.type.majorEncoded,r)}es.encodedSize=function(t){let n=t.value,r=typeof n=="bigint"?n*Zo-Ac:n*-1-1;return r<Me[0]?1:r<Me[1]?2:r<Me[2]?3:r<Me[3]?5:9};es.compareTokens=function(t,n){return t.value<n.value?1:t.value>n.value?-1:0};function Tr(e,t,n,r){Vn(e,t,n+r);let i=Qo(e,t+n,t+n+r);return new re(U.bytes,i,n+r)}function rT(e,t,n,r){return Tr(e,t,1,n)}function iT(e,t,n,r){return Tr(e,t,2,gn(e,t+1,r))}function oT(e,t,n,r){return Tr(e,t,3,mn(e,t+1,r))}function sT(e,t,n,r){return Tr(e,t,5,bn(e,t+1,r))}function aT(e,t,n,r){let i=vn(e,t+1,r);if(typeof i=="bigint")throw new Error(`${de} 64-bit integer bytes lengths not supported`);return Tr(e,t,9,i)}function pi(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===U.string?Tc(e.value):e.value),e.encodedBytes}function Si(e,t){let n=pi(t);pt(e,t.type.majorEncoded,n.length),e.push(n)}Si.encodedSize=function(t){let n=pi(t);return pt.encodedSize(n.length)+n.length};Si.compareTokens=function(t,n){return uT(pi(t),pi(n))};function uT(e,t){return e.length<t.length?-1:e.length>t.length?1:W_(e,t)}function wr(e,t,n,r,i){let s=n+r;Vn(e,t,s);let o=new re(U.string,V_(e,t+n,t+s),s);return i.retainStringBytes===!0&&(o.byteValue=Qo(e,t+n,t+s)),o}function cT(e,t,n,r){return wr(e,t,1,n,r)}function fT(e,t,n,r){return wr(e,t,2,gn(e,t+1,r),r)}function lT(e,t,n,r){return wr(e,t,3,mn(e,t+1,r),r)}function dT(e,t,n,r){return wr(e,t,5,bn(e,t+1,r),r)}function pT(e,t,n,r){let i=vn(e,t+1,r);if(typeof i=="bigint")throw new Error(`${de} 64-bit integer string lengths not supported`);return wr(e,t,9,i,r)}var yT=Si;function zn(e,t,n,r){return new re(U.array,r,n)}function hT(e,t,n,r){return zn(e,t,1,n)}function gT(e,t,n,r){return zn(e,t,2,gn(e,t+1,r))}function mT(e,t,n,r){return zn(e,t,3,mn(e,t+1,r))}function bT(e,t,n,r){return zn(e,t,5,bn(e,t+1,r))}function vT(e,t,n,r){let i=vn(e,t+1,r);if(typeof i=="bigint")throw new Error(`${de} 64-bit integer array lengths not supported`);return zn(e,t,9,i)}function _T(e,t,n,r){if(r.allowIndefinite===!1)throw new Error(`${de} indefinite length items not allowed`);return zn(e,t,1,1/0)}function ts(e,t){pt(e,U.array.majorEncoded,t.value)}ts.compareTokens=_n.compareTokens;ts.encodedSize=function(t){return pt.encodedSize(t.value)};function qn(e,t,n,r){return new re(U.map,r,n)}function TT(e,t,n,r){return qn(e,t,1,n)}function wT(e,t,n,r){return qn(e,t,2,gn(e,t+1,r))}function OT(e,t,n,r){return qn(e,t,3,mn(e,t+1,r))}function AT(e,t,n,r){return qn(e,t,5,bn(e,t+1,r))}function IT(e,t,n,r){let i=vn(e,t+1,r);if(typeof i=="bigint")throw new Error(`${de} 64-bit integer map lengths not supported`);return qn(e,t,9,i)}function ET(e,t,n,r){if(r.allowIndefinite===!1)throw new Error(`${de} indefinite length items not allowed`);return qn(e,t,1,1/0)}function ns(e,t){pt(e,U.map.majorEncoded,t.value)}ns.compareTokens=_n.compareTokens;ns.encodedSize=function(t){return pt.encodedSize(t.value)};function ST(e,t,n,r){return new re(U.tag,n,1)}function PT(e,t,n,r){return new re(U.tag,gn(e,t+1,r),2)}function $T(e,t,n,r){return new re(U.tag,mn(e,t+1,r),3)}function RT(e,t,n,r){return new re(U.tag,bn(e,t+1,r),5)}function NT(e,t,n,r){return new re(U.tag,vn(e,t+1,r),9)}function rs(e,t){pt(e,U.tag.majorEncoded,t.value)}rs.compareTokens=_n.compareTokens;rs.encodedSize=function(t){return pt.encodedSize(t.value)};var CT=20,xT=21,UT=22,jT=23;function DT(e,t,n,r){if(r.allowUndefined===!1)throw new Error(`${de} undefined values are not supported`);return r.coerceUndefinedToNull===!0?new re(U.null,null,1):new re(U.undefined,void 0,1)}function MT(e,t,n,r){if(r.allowIndefinite===!1)throw new Error(`${de} indefinite length items not allowed`);return new re(U.break,void 0,1)}function is(e,t,n){if(n){if(n.allowNaN===!1&&Number.isNaN(e))throw new Error(`${de} NaN values are not supported`);if(n.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${de} Infinity values are not supported`)}return new re(U.float,e,t)}function LT(e,t,n,r){return is(ss(e,t+1),3,r)}function BT(e,t,n,r){return is(as(e,t+1),5,r)}function FT(e,t,n,r){return is(Pc(e,t+1),9,r)}function os(e,t,n){let r=t.value;if(r===!1)e.push([U.float.majorEncoded|CT]);else if(r===!0)e.push([U.float.majorEncoded|xT]);else if(r===null)e.push([U.float.majorEncoded|UT]);else if(r===void 0)e.push([U.float.majorEncoded|jT]);else{let i,s=!1;(!n||n.float64!==!0)&&(Ec(r),i=ss(Ot,1),r===i||Number.isNaN(r)?(Ot[0]=249,e.push(Ot.slice(0,3)),s=!0):(Sc(r),i=as(Ot,1),r===i&&(Ot[0]=250,e.push(Ot.slice(0,5)),s=!0))),s||(kT(r),i=Pc(Ot,1),Ot[0]=251,e.push(Ot.slice(0,9)))}}os.encodedSize=function(t,n){let r=t.value;if(r===!1||r===!0||r===null||r===void 0)return 1;if(!n||n.float64!==!0){Ec(r);let i=ss(Ot,1);if(r===i||Number.isNaN(r))return 3;if(Sc(r),i=as(Ot,1),r===i)return 5}return 9};var Ic=new ArrayBuffer(9),dt=new DataView(Ic,1),Ot=new Uint8Array(Ic,0);function Ec(e){if(e===1/0)dt.setUint16(0,31744,!1);else if(e===-1/0)dt.setUint16(0,64512,!1);else if(Number.isNaN(e))dt.setUint16(0,32256,!1);else{dt.setFloat32(0,e);let t=dt.getUint32(0),n=(t&2139095040)>>23,r=t&8388607;if(n===255)dt.setUint16(0,31744,!1);else if(n===0)dt.setUint16(0,(e&2147483648)>>16|r>>13,!1);else{let i=n-127;i<-24?dt.setUint16(0,0):i<-14?dt.setUint16(0,(t&2147483648)>>16|1<<24+i,!1):dt.setUint16(0,(t&2147483648)>>16|i+15<<10|r>>13,!1)}}}function ss(e,t){if(e.length-t<2)throw new Error(`${de} not enough data for float16`);let n=(e[t]<<8)+e[t+1];if(n===31744)return 1/0;if(n===64512)return-1/0;if(n===32256)return NaN;let r=n>>10&31,i=n&1023,s;return r===0?s=i*2**-24:r!==31?s=(i+1024)*2**(r-25):s=i===0?1/0:NaN,n&32768?-s:s}function Sc(e){dt.setFloat32(0,e,!1)}function as(e,t){if(e.length-t<4)throw new Error(`${de} not enough data for float32`);let n=(e.byteOffset||0)+t;return new DataView(e.buffer,n,4).getFloat32(0,!1)}function kT(e){dt.setFloat64(0,e,!1)}function Pc(e,t){if(e.length-t<8)throw new Error(`${de} not enough data for float64`);let n=(e.byteOffset||0)+t;return new DataView(e.buffer,n,8).getFloat64(0,!1)}os.compareTokens=_n.compareTokens;function _e(e,t,n){throw new Error(`${de} encountered invalid minor (${n}) for major ${e[t]>>>5}`)}function Pi(e){return()=>{throw new Error(`${de} ${e}`)}}var oe=[];for(let e=0;e<=23;e++)oe[e]=_e;oe[24]=J_;oe[25]=X_;oe[26]=Y_;oe[27]=Q_;oe[28]=_e;oe[29]=_e;oe[30]=_e;oe[31]=_e;for(let e=32;e<=55;e++)oe[e]=_e;oe[56]=Z_;oe[57]=eT;oe[58]=tT;oe[59]=nT;oe[60]=_e;oe[61]=_e;oe[62]=_e;oe[63]=_e;for(let e=64;e<=87;e++)oe[e]=rT;oe[88]=iT;oe[89]=oT;oe[90]=sT;oe[91]=aT;oe[92]=_e;oe[93]=_e;oe[94]=_e;oe[95]=Pi("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)oe[e]=cT;oe[120]=fT;oe[121]=lT;oe[122]=dT;oe[123]=pT;oe[124]=_e;oe[125]=_e;oe[126]=_e;oe[127]=Pi("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)oe[e]=hT;oe[152]=gT;oe[153]=mT;oe[154]=bT;oe[155]=vT;oe[156]=_e;oe[157]=_e;oe[158]=_e;oe[159]=_T;for(let e=160;e<=183;e++)oe[e]=TT;oe[184]=wT;oe[185]=OT;oe[186]=AT;oe[187]=IT;oe[188]=_e;oe[189]=_e;oe[190]=_e;oe[191]=ET;for(let e=192;e<=215;e++)oe[e]=ST;oe[216]=PT;oe[217]=$T;oe[218]=RT;oe[219]=NT;oe[220]=_e;oe[221]=_e;oe[222]=_e;oe[223]=_e;for(let e=224;e<=243;e++)oe[e]=Pi("simple values are not supported");oe[244]=_e;oe[245]=_e;oe[246]=_e;oe[247]=DT;oe[248]=Pi("simple values are not supported");oe[249]=LT;oe[250]=BT;oe[251]=FT;oe[252]=_e;oe[253]=_e;oe[254]=_e;oe[255]=MT;var Nt=[];for(let e=0;e<24;e++)Nt[e]=new re(U.uint,e,1);for(let e=-1;e>=-24;e--)Nt[31-e]=new re(U.negint,e,1);Nt[64]=new re(U.bytes,new Uint8Array(0),1);Nt[96]=new re(U.string,"",1);Nt[128]=new re(U.array,0,1);Nt[160]=new re(U.map,0,1);Nt[244]=new re(U.false,!1,1);Nt[245]=new re(U.true,!0,1);Nt[246]=new re(U.null,null,1);function KT(){let e=[];return e[U.uint.major]=_n,e[U.negint.major]=es,e[U.bytes.major]=Si,e[U.string.major]=yT,e[U.array.major]=ts,e[U.map.major]=ns,e[U.tag.major]=rs,e[U.float.major]=os,e}var Ww=KT(),wo=new Oc,hu=class $c{constructor(t,n){this.obj=t,this.parent=n}includes(t){let n=this;do if(n.obj===t)return!0;while(n=n.parent);return!1}static createCheck(t,n){if(t&&t.includes(n))throw new Error(`${pn} object contains circular references`);return new $c(n,t)}},Wt={null:new re(U.null,null),undefined:new re(U.undefined,void 0),true:new re(U.true,!0),false:new re(U.false,!1),emptyArray:new re(U.array,0),emptyMap:new re(U.map,0)},Xt={number(e,t,n,r){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new re(U.float,e):e>=0?new re(U.uint,e):new re(U.negint,e)},bigint(e,t,n,r){return e>=BigInt(0)?new re(U.uint,e):new re(U.negint,e)},Uint8Array(e,t,n,r){return new re(U.bytes,e)},string(e,t,n,r){return new re(U.string,e)},boolean(e,t,n,r){return e?Wt.true:Wt.false},null(e,t,n,r){return Wt.null},undefined(e,t,n,r){return Wt.undefined},ArrayBuffer(e,t,n,r){return new re(U.bytes,new Uint8Array(e))},DataView(e,t,n,r){return new re(U.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,n,r){if(!e.length)return n.addBreakTokens===!0?[Wt.emptyArray,new re(U.break)]:Wt.emptyArray;r=hu.createCheck(r,e);let i=[],s=0;for(let o of e)i[s++]=ei(o,n,r);return n.addBreakTokens?[new re(U.array,e.length),i,new re(U.break)]:[new re(U.array,e.length),i]},Object(e,t,n,r){let i=t!=="Object",s=i?e.keys():Object.keys(e),o=i?e.size:s.length;if(!o)return n.addBreakTokens===!0?[Wt.emptyMap,new re(U.break)]:Wt.emptyMap;r=hu.createCheck(r,e);let u=[],f=0;for(let c of s)u[f++]=[ei(c,n,r),ei(i?e.get(c):e[c],n,r)];return GT(u,n),n.addBreakTokens?[new re(U.map,o),u,new re(U.break)]:[new re(U.map,o),u]}};Xt.Map=Xt.Object;Xt.Buffer=Xt.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Xt[`${e}Array`]=Xt.DataView;function ei(e,t={},n){let r=B_(e),i=t&&t.typeEncoders&&t.typeEncoders[r]||Xt[r];if(typeof i=="function"){let o=i(e,r,t,n);if(o!=null)return o}let s=Xt[r];if(!s)throw new Error(`${pn} unsupported type: ${r}`);return s(e,r,t,n)}function GT(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Rc(e,t,n,r){if(Array.isArray(t))for(let i of t)Rc(e,i,n,r);else n[t.type.major](e,t,r)}function VT(e,t,n){let r=ei(e,n);if(!Array.isArray(r)&&n.quickEncodeToken){let i=n.quickEncodeToken(r);if(i)return i;let s=t[r.type.major];if(s.encodedSize){let o=s.encodedSize(r,n),u=new Oc(o);if(s(u,r,n),u.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${r} was wrong`);return Yo(u.chunks[0])}}return wo.reset(),Rc(wo,r,t,n),wo.toBytes(!0)}var zT={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},qT=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=Nt[e];if(t===void 0){let n=oe[e];if(!n)throw new Error(`${de} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let r=e&31;t=n(this.data,this._pos,r,this.options)}return this._pos+=t.encodedLength,t}},mr=Symbol.for("DONE"),$i=Symbol.for("BREAK");function WT(e,t,n){let r=[];for(let i=0;i<e.value;i++){let s=br(t,n);if(s===$i){if(e.value===1/0)break;throw new Error(`${de} got unexpected break to lengthed array`)}if(s===mr)throw new Error(`${de} found array but not enough entries (got ${i}, expected ${e.value})`);r[i]=s}return r}function HT(e,t,n){let r=n.useMaps===!0,i=r?void 0:{},s=r?new Map:void 0;for(let o=0;o<e.value;o++){let u=br(t,n);if(u===$i){if(e.value===1/0)break;throw new Error(`${de} got unexpected break to lengthed map`)}if(u===mr)throw new Error(`${de} found map but not enough entries (got ${o} [no key], expected ${e.value})`);if(r!==!0&&typeof u!="string")throw new Error(`${de} non-string keys not supported (got ${typeof u})`);if(n.rejectDuplicateMapKeys===!0&&(r&&s.has(u)||!r&&u in i))throw new Error(`${de} found repeat map key "${u}"`);let f=br(t,n);if(f===mr)throw new Error(`${de} found map but not enough entries (got ${o} [no value], expected ${e.value})`);r?s.set(u,f):i[u]=f}return r?s:i}function br(e,t){if(e.done())return mr;let n=e.next();if(n.type===U.break)return $i;if(n.type.terminal)return n.value;if(n.type===U.array)return WT(n,e,t);if(n.type===U.map)return HT(n,e,t);if(n.type===U.tag){if(t.tags&&typeof t.tags[n.value]=="function"){let r=br(e,t);return t.tags[n.value](r)}throw new Error(`${de} tag not supported (${n.value})`)}throw new Error("unsupported")}function JT(e,t){if(!(e instanceof Uint8Array))throw new Error(`${de} data to decode must be a Uint8Array`);t=Object.assign({},zT,t);let n=t.tokenizer||new qT(e,t),r=br(n,t);if(r===mr)throw new Error(`${de} did not find any content to decode`);if(r===$i)throw new Error(`${de} got unexpected break`);return[r,e.subarray(n.pos())]}function XT(e,t){let[n,r]=JT(e,t);if(r.length>0)throw new Error(`${de} too many terminals, data makes no sense`);return n}var YT=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===U.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===U.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[U.uint.major](e,t){this.prefix(e);let n=String(t.value),r=[];for(let i=0;i<n.length;i++)r[i]=n.charCodeAt(i);e.push(r)}[U.negint.major](e,t){this[U.uint.major](e,t)}[U.bytes.major](e,t){throw new Error(`${pn} unsupported type: Uint8Array`)}[U.string.major](e,t){this.prefix(e);let n=Tc(JSON.stringify(t.value));e.push(n.length>32?Yo(n):n)}[U.array.major](e,t){this.prefix(e),this.inRecursive.push({type:U.array,elements:0}),e.push([91])}[U.map.major](e,t){this.prefix(e),this.inRecursive.push({type:U.map,elements:0}),e.push([123])}[U.tag.major](e,t){}[U.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===U.array)e.push([93]);else if(s.type===U.map)e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(t.value===void 0)throw new Error(`${pn} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.value),r=[],i=!1;for(let s=0;s<n.length;s++)r[s]=n.charCodeAt(s),!i&&(r[s]===46||r[s]===101||r[s]===69)&&(i=!0);i||(r.push(46),r.push(48)),e.push(r)}};function QT(e,t){if(Array.isArray(e[0])||Array.isArray(t[0]))throw new Error(`${pn} complex map keys are not supported`);let n=e[0],r=t[0];if(n.type!==U.string||r.type!==U.string)throw new Error(`${pn} non-string map keys are not supported`);if(n<r)return-1;if(n>r)return 1;throw new Error(`${pn} unexpected duplicate map keys, this is not supported`)}var ZT={addBreakTokens:!0,mapSorter:QT};function e0(e,t){return t=Object.assign({},ZT,t),VT(e,new YT,t)}var Nc=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${de} unexpected end of input at position ${this._pos}`);for(let t=0;t<e.length;t++)if(this.data[this._pos++]!==e[t])throw new Error(`${de} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,r=o=>{for(;!this.done();){let u=this.ch();if(o.includes(u))this._pos++;else break}};if(this.ch()===45&&(t=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new re(U.uint,0,this._pos-e);if(r([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${de} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${de} unexpected token at position ${this._pos}`);n=!0,this._pos++,r([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,r([48,49,50,51,52,53,54,55,56,57]));let i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);return n?new re(U.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new re(s>=0?U.uint:U.negint,s,this._pos-e):new re(s>=0?U.uint:U.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${de} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let o=this.data[i];if(o===92||o<32||o>=128)break;if(o===34){let u=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new re(U.string,u,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${de} unexpected end of unicode escape sequence at position ${this._pos}`);let i=0;for(let s=0;s<4;s++){let o=this.ch();if(o>=48&&o<=57)o-=48;else if(o>=97&&o<=102)o=o-97+10;else if(o>=65&&o<=70)o=o-65+10;else throw new Error(`${de} unexpected unicode escape character at position ${this._pos}`);i=i*16+o,this._pos++}return i},r=()=>{let i=this.ch(),s=null,o=i>239?4:i>223?3:i>191?2:1;if(this._pos+o>this.data.length)throw new Error(`${de} unexpected unicode sequence at position ${this._pos}`);let u,f,c,g;switch(o){case 1:i<128&&(s=i);break;case 2:u=this.data[this._pos+1],(u&192)===128&&(g=(i&31)<<6|u&63,g>127&&(s=g));break;case 3:u=this.data[this._pos+1],f=this.data[this._pos+2],(u&192)===128&&(f&192)===128&&(g=(i&15)<<12|(u&63)<<6|f&63,g>2047&&(g<55296||g>57343)&&(s=g));break;case 4:u=this.data[this._pos+1],f=this.data[this._pos+2],c=this.data[this._pos+3],(u&192)===128&&(f&192)===128&&(c&192)===128&&(g=(i&15)<<18|(u&63)<<12|(f&63)<<6|c&63,g>65535&&g<1114112&&(s=g))}s===null?(s=65533,o=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=o};for(;!this.done();){let i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${de} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:t.push(s);break;case 98:t.push(8);break;case 116:t.push(9);break;case 110:t.push(10);break;case 102:t.push(12);break;case 114:t.push(13);break;case 117:t.push(n());break;default:throw new Error(`${de} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new re(U.string,wc(t),this._pos-e);default:if(i<32)throw new Error(`${de} invalid control character at position ${this._pos}`);i<128?(t.push(i),this._pos++):r()}}throw new Error(`${de} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new re(U.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new re(U.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new re(U.null,null,4);case 102:return this.expect([102,97,108,115,101]),new re(U.false,!1,5);case 116:return this.expect([116,114,117,101]),new re(U.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${de} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new re(U.break,void 0,1);if(this.ch()!==44)throw new Error(`${de} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new re(U.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new re(U.break,void 0,1);if(this.ch()!==44)throw new Error(`${de} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new re(U.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${de} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${de} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function t0(e,t){return t=Object.assign({tokenizer:new Nc(e,t)},t),XT(e,t)}var Hw=new Uint8Array(0);function n0(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.byteLength;n++)if(e[n]!==t[n])return!1;return!0}function us(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function r0(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<e.length;i++){var s=e.charAt(i),o=s.charCodeAt(0);if(n[o]!==255)throw new TypeError(s+" is ambiguous");n[o]=i}var u=e.length,f=e.charAt(0),c=Math.log(u)/Math.log(256),g=Math.log(256)/Math.log(u);function b(L){if(L instanceof Uint8Array||(ArrayBuffer.isView(L)?L=new Uint8Array(L.buffer,L.byteOffset,L.byteLength):Array.isArray(L)&&(L=Uint8Array.from(L))),!(L instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(L.length===0)return"";for(var H=0,Z=0,K=0,B=L.length;K!==B&&L[K]===0;)K++,H++;for(var V=(B-K)*g+1>>>0,q=new Uint8Array(V);K!==B;){for(var F=L[K],ee=0,z=V-1;(F!==0||ee<Z)&&z!==-1;z--,ee++)F+=256*q[z]>>>0,q[z]=F%u>>>0,F=F/u>>>0;if(F!==0)throw new Error("Non-zero carry");Z=ee,K++}for(var fe=V-Z;fe!==V&&q[fe]===0;)fe++;for(var N=f.repeat(H);fe<V;++fe)N+=e.charAt(q[fe]);return N}function M(L){if(typeof L!="string")throw new TypeError("Expected String");if(L.length===0)return new Uint8Array;var H=0;if(L[H]!==" "){for(var Z=0,K=0;L[H]===f;)Z++,H++;for(var B=(L.length-H)*c+1>>>0,V=new Uint8Array(B);L[H];){var q=n[L.charCodeAt(H)];if(q===255)return;for(var F=0,ee=B-1;(q!==0||F<K)&&ee!==-1;ee--,F++)q+=u*V[ee]>>>0,V[ee]=q%256>>>0,q=q/256>>>0;if(q!==0)throw new Error("Non-zero carry");K=F,H++}if(L[H]!==" "){for(var z=B-K;z!==B&&V[z]===0;)z++;for(var fe=new Uint8Array(Z+(B-z)),N=Z;z!==B;)fe[N++]=V[z++];return fe}}}function $(L){var H=M(L);if(H)return H;throw new Error(`Non-${t} character`)}return{encode:b,decodeUnsafe:M,decode:$}}var i0=r0,o0=i0,s0=o0,a0=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},u0=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let r=t.codePointAt(0);if(r===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r,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 Cc(this,e)}},c0=class{decoders;constructor(e){this.decoders=e}or(e){return Cc(this,e)}decode(e){let t=e[0],n=this.decoders[t];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 Cc(e,t){return new c0({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var f0=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,r){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=r,this.encoder=new a0(e,t,n),this.decoder=new u0(e,t,r)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function xc({name:e,prefix:t,encode:n,decode:r}){return new f0(e,t,n,r)}function Ri({name:e,prefix:t,alphabet:n}){let{encode:r,decode:i}=s0(n,e);return xc({prefix:t,name:e,encode:r,decode:s=>us(i(s))})}function l0(e,t,n,r){let i=e.length;for(;e[i-1]==="=";)--i;let s=new Uint8Array(i*n/8|0),o=0,u=0,f=0;for(let c=0;c<i;++c){let g=t[e[c]];if(g===void 0)throw new SyntaxError(`Non-${r} character`);u=u<<n|g,o+=n,o>=8&&(o-=8,s[f++]=255&u>>o)}if(o>=n||(255&u<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return s}function d0(e,t,n){let r=t[t.length-1]==="=",i=(1<<n)-1,s="",o=0,u=0;for(let f=0;f<e.length;++f)for(u=u<<8|e[f],o+=8;o>n;)o-=n,s+=t[i&u>>o];if(o!==0&&(s+=t[i&u<<n-o]),r)for(;(s.length*n&7)!==0;)s+="=";return s}function p0(e){let t={};for(let n=0;n<e.length;++n)t[e[n]]=n;return t}function et({name:e,prefix:t,bitsPerChar:n,alphabet:r}){let i=p0(r);return xc({prefix:t,name:e,encode(s){return d0(s,r,n)},decode(s){return l0(s,i,n,e)}})}var ti=et({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Jw=et({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xw=et({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Yw=et({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Qw=et({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Zw=et({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),eO=et({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tO=et({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),nO=et({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5}),Oo=Ri({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),rO=Ri({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"}),Ht=Ri({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),iO=Ri({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"}),y0={};po(y0,{Digest:()=>Ni,create:()=>cs,decode:()=>jc,equals:()=>Dc,hasCode:()=>x0});var h0=Uc,gu=128,g0=127,m0=~g0,b0=Math.pow(2,31);function Uc(e,t,n){t=t||[],n=n||0;for(var r=n;e>=b0;)t[n++]=e&255|gu,e/=128;for(;e&m0;)t[n++]=e&255|gu,e>>>=7;return t[n]=e|0,Uc.bytes=n-r+1,t}var v0=$o,_0=128,mu=127;function $o(e,r){var n=0,r=r||0,i=0,s=r,o,u=e.length;do{if(s>=u)throw $o.bytes=0,new RangeError("Could not decode varint");o=e[s++],n+=i<28?(o&mu)<<i:(o&mu)*Math.pow(2,i),i+=7}while(o>=_0);return $o.bytes=s-r,n}var T0=Math.pow(2,7),w0=Math.pow(2,14),O0=Math.pow(2,21),A0=Math.pow(2,28),I0=Math.pow(2,35),E0=Math.pow(2,42),S0=Math.pow(2,49),P0=Math.pow(2,56),$0=Math.pow(2,63),R0=function(e){return e<T0?1:e<w0?2:e<O0?3:e<A0?4:e<I0?5:e<E0?6:e<S0?7:e<P0?8:e<$0?9:10},N0={encode:h0,decode:v0,encodingLength:R0},C0=N0,yi=C0;function Ro(e,t=0){return[yi.decode(e,t),yi.decode.bytes]}function hi(e,t,n=0){return yi.encode(e,t,n),t}function gi(e){return yi.encodingLength(e)}function cs(e,t){let n=t.byteLength,r=gi(e),i=r+gi(n),s=new Uint8Array(i+n);return hi(e,s,0),hi(n,s,r),s.set(t,i),new Ni(e,n,t,s)}function jc(e){let t=us(e),[n,r]=Ro(t),[i,s]=Ro(t.subarray(r)),o=t.subarray(r+s);if(o.byteLength!==i)throw new Error("Incorrect length");return new Ni(n,i,o,t)}function Dc(e,t){if(e===t)return!0;{let n=t;return e.code===n.code&&e.size===n.size&&n.bytes instanceof Uint8Array&&n0(e.bytes,n.bytes)}}var Ni=class{code;size;digest;bytes;constructor(e,t,n,r){this.code=e,this.size=t,this.digest=n,this.bytes=r}};function x0(e,t){return e.code===t}function bu(e,t){let{bytes:n,version:r}=e;switch(r){case 0:return j0(n,No(e),t??Ht.encoder);default:return D0(n,No(e),t??ti.encoder)}}var vu=new WeakMap;function No(e){let t=vu.get(e);if(t==null){let n=new Map;return vu.set(e,n),n}return t}var Mc=class Be{code;version;multihash;bytes;"/";constructor(t,n,r,i){this.code=n,this.version=t,this.multihash=r,this.bytes=i,this["/"]=i}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:t,multihash:n}=this;if(t!==cr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(n.code!==M0)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return Be.createV0(n)}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:t,digest:n}=this.multihash,r=cs(t,n);return Be.createV1(this.code,r)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return Be.equals(this,t)}static equals(t,n){let r=n;return r!=null&&t.code===r.code&&t.version===r.version&&Dc(t.multihash,r.multihash)}toString(t){return bu(this,t)}toJSON(){return{"/":bu(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let n=t;if(n instanceof Be)return n;if(n["/"]!=null&&n["/"]===n.bytes||n.asCID===n){let{version:r,code:i,multihash:s,bytes:o}=n;return new Be(r,i,s,o??_u(r,i,s.bytes))}else if(n[L0]===!0){let{version:r,multihash:i,code:s}=n,o=jc(i);return Be.create(r,s,o)}else return null}static create(t,n,r){if(typeof n!="number")throw new Error("String codecs are no longer supported");if(!(r.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(n!==cr)throw new Error(`Version 0 CID must use dag-pb (code: ${cr}) block encoding`);return new Be(t,n,r,r.bytes)}case 1:{let i=_u(t,n,r.bytes);return new Be(t,n,r,i)}default:throw new Error("Invalid version")}}static createV0(t){return Be.create(0,cr,t)}static createV1(t,n){return Be.create(1,t,n)}static decode(t){let[n,r]=Be.decodeFirst(t);if(r.length!==0)throw new Error("Incorrect length");return n}static decodeFirst(t){let n=Be.inspectBytes(t),r=n.size-n.multihashSize,i=us(t.subarray(r,r+n.multihashSize));if(i.byteLength!==n.multihashSize)throw new Error("Incorrect length");let s=i.subarray(n.multihashSize-n.digestSize),o=new Ni(n.multihashCode,n.digestSize,s,i);return[n.version===0?Be.createV0(o):Be.createV1(n.codec,o),t.subarray(n.size)]}static inspectBytes(t){let n=0,r=()=>{let[b,M]=Ro(t.subarray(n));return n+=M,b},i=r(),s=cr;if(i===18?(i=0,n=0):s=r(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let o=n,u=r(),f=r(),c=n+f,g=c-o;return{version:i,codec:s,multihashCode:u,digestSize:f,multihashSize:g,size:c}}static parse(t,n){let[r,i]=U0(t,n),s=Be.decode(i);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return No(s).set(r,t),s}};function U0(e,t){switch(e[0]){case"Q":{let n=t??Ht;return[Ht.prefix,n.decode(`${Ht.prefix}${e}`)]}case Ht.prefix:{let n=t??Ht;return[Ht.prefix,n.decode(e)]}case ti.prefix:{let n=t??ti;return[ti.prefix,n.decode(e)]}case Oo.prefix:{let n=t??Oo;return[Oo.prefix,n.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function j0(e,t,n){let{prefix:r}=n;if(r!==Ht.prefix)throw Error(`Cannot string encode V0 in ${n.name} encoding`);let i=t.get(r);if(i==null){let s=n.encode(e).slice(1);return t.set(r,s),s}else return i}function D0(e,t,n){let{prefix:r}=n,i=t.get(r);if(i==null){let s=n.encode(e);return t.set(r,s),s}else return i}var cr=112,M0=18;function _u(e,t,n){let r=gi(e),i=r+gi(t),s=new Uint8Array(i+n.byteLength);return hi(e,s,0),hi(t,s,r),s.set(n,i),s}var L0=Symbol.for("@ipld/js-cid/CID"),B0=20;function Lc({name:e,code:t,encode:n,minDigestLength:r,maxDigestLength:i}){return new F0(e,t,n,r,i)}var F0=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,r,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=r??B0,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Tu(n,this.code,t?.truncate):n.then(r=>Tu(r,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Tu(e,t,n){if(n!=null&&n!==e.byteLength){if(n>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,n)}return cs(t,e)}var Bc=et({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),oO=et({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),sO=et({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),aO=et({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function k0(e){return e instanceof ArrayBuffer?new Uint8Array(e,0,e.byteLength):e}function K0(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=Mc.asCID(e);if(!t)return null;let n=t.toString();return[new re(U.map,1/0,1),new re(U.string,"/",1),new re(U.string,n,n.length),new re(U.break,void 0,1)]}function mi(e){let t=Bc.encode(e).slice(1);return[new re(U.map,1/0,1),new re(U.string,"/",1),new re(U.map,1/0,1),new re(U.string,"bytes",5),new re(U.string,t,t.length),new re(U.break,void 0,1),new re(U.break,void 0,1)]}function wt(e){return mi(new Uint8Array(e.buffer,e.byteOffset,e.byteLength))}function G0(e){return mi(new Uint8Array(e))}function V0(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function z0(e){if(Number.isNaN(e))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(e===1/0||e===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var q0={typeEncoders:{Object:K0,Buffer:mi,Uint8Array:mi,Int8Array:wt,Uint16Array:wt,Int16Array:wt,Uint32Array:wt,Int32Array:wt,Float32Array:wt,Float64Array:wt,Uint8ClampedArray:wt,BigInt64Array:wt,BigUint64Array:wt,DataView:wt,ArrayBuffer:G0,undefined:V0,number:z0}},W0=class extends Nc{constructor(e,t){super(e,t),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(e.type===U.map){let t=this._next();if(t.type===U.string&&t.value==="/"){let n=this._next();if(n.type===U.string){if(this._next().type!==U.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new re(U.tag,42,0)}if(n.type===U.map){let r=this._next();if(r.type===U.string&&r.value==="bytes"){let i=this._next();if(i.type===U.string){for(let o=0;o<2;o++)if(this._next().type!==U.break)throw new Error("Invalid encoded Bytes form");let s=Bc.decode(`m${i.value}`);return new re(U.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(r)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},Co={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Co.tags[42]=Mc.parse;var H0="dag-json",J0=297,Fc=e=>e0(e,q0),kc=e=>{let t=k0(e),n=Object.assign(Co,{tokenizer:new W0(t,Co)});return t0(t,n)},wu=e=>X0.decode(Fc(e)),X0=new TextDecoder,Y0=e=>kc(Q0.encode(e)),Q0=new TextEncoder;var Ue=qt(Lt(),1),Kc=qt(Sd(),1),xo=e=>Ue.Type.Union([e,Ue.Type.Null()]);var Gc=/^(k51qz|baguq)[0-9a-z]{56,57}$/,Z0=/^[0-9A-Fa-f]{7,8}$/g;Ue.FormatRegistry.Set("EntityID",e=>!!e.match(Z0)||!!e.match(Gc));var Vc=Ue.Type.String();Ue.FormatRegistry.Set("CID",e=>!!e.match(Gc));var fs=Ue.Type.String({format:"CID"}),ew=/^http([s]?):\/\/.*\..*/;Ue.FormatRegistry.Set("URL",e=>!!e.match(ew));var tw=Ue.Type.String({format:"URL"}),ls=Ue.Type.Object({en:Vc,at:Ue.Type.String(),vl:xo(Ue.Type.Union([Ue.Type.String(),Ue.Type.Boolean(),Ue.Type.Number()])),ts:Ue.Type.String(),ag:Ue.Type.String(),pv:xo(fs)}),Uo=Kc.TypeCompiler.Compile(ls);var nw=Uo.Check.bind(Uo),zc=Ue.Type.Composite([Ue.Type.Object({cid:fs}),ls]),jo=Kc.TypeCompiler.Compile(zc);var rw=jo.Check.bind(jo);function qc(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var uO=Lc({name:"sha2-256",code:18,encode:qc("SHA-256")}),cO=Lc({name:"sha2-512",code:19,encode:qc("SHA-512")}),{WARN:fO,LOG:lO,DEBUG:dO,VERBOSE:pO,ERROR:yO}=xe.setup(xe.INFO);var{WARN:hO,LOG:gO,DEBUG:mO,VERBOSE:bO,ERROR:vO}=xe.setup(xe.INFO);var Wc=(e,t,n)=>ut.structural(cu(t,e),cu(n,e));var iw=v_(Wc,["en","at"]);var Ci=(e,t=8)=>Xc(ci(e),31,t);function Hc(e,t,n){let r;if(t){let i=typeof t;i==="string"?r=t===n:i==="function"?r=t(n):typeof t.has=="function"?r=t.has(n):Array.isArray(t)&&!Array.isArray(n)?r=t.includes(n):r=t===n}else r=t===n;return e.charAt(0)==="!"?!r:r}var Jc=function(t){for(var n=0,r=0,i=t.length;r<i;r++)n+=t[r];return n},Ou=function(t){return Jc(t)/t.length},Qe={max:function(e){return Math.max.apply(null,e)},min:function(e){return Math.min.apply(null,e)},range:function(e){return Qe.max(e)-Qe.min(e)},midrange:function(e){return Qe.range(e)/2},sum:Jc,mean:Ou,average:Ou,median:function(e){e.sort(function(n,r){return n-r});var t=e.length/2;return t%1?e[t-.5]:(e[t-1]+e[t])/2},modes:function(e){if(!e.length)return[];var t={},n=0,r=[];return e.forEach(function(i){t[i]?t[i]++:t[i]=1,t[i]>n?(r=[i],n=t[i]):t[i]===n&&(r.push(i),n=t[i])}),r},variance:function(e){var t=Qe.mean(e);return Qe.mean(e.map(function(n){return Math.pow(n-t,2)}))},standardDeviation:function(e){return Math.sqrt(Qe.variance(e))},meanAbsoluteDeviation:function(e){var t=Qe.mean(e);return Qe.mean(e.map(function(n){return Math.abs(n-t)}))},zScores:function(e){var t=Qe.mean(e),n=Qe.standardDeviation(e);return e.map(function(r){return(r-t)/n})}};Qe.average=Qe.mean;var Xc=function(e,t=13,n){if(!e?.length)throw new Error(`Empty string: ${e}`);let r=3735928559^t,i=1103547991^t;for(let o=0,u;o<e.length;o++)u=e.charCodeAt(o),r=Math.imul(r^u,2654435761),i=Math.imul(i^u,1597334677);return r=Math.imul(r^r>>>16,2246822507)^Math.imul(i^i>>>13,3266489909),i=Math.imul(i^i>>>16,2246822507)^Math.imul(r^r>>>13,3266489909),(4294967296*(2097151&i)+(r>>>0)).toString(16).slice(-n).padStart(n,"0")};function xi(){return new Date().toISOString()}var{WARN:_O,LOG:TO,DEBUG:wO,VERBOSE:OO,ERROR:AO}=xe.setup(xe.INFO);var{WARN:Au,LOG:IO,DEBUG:Iu,VERBOSE:ln,ERROR:Eu}=xe.setup(xe.INFO),Yc=class Qc extends li{constructor(t,n,r,i,s,o=null){super(t,n,r,s?Pe.array([...i],{deep:!1,name:`${t}.array`}):i),this.name=t,this._initialLogs=i,this._eventMapper=s,this._writeMapper=o,oo(this,{onParentUpdate:gt}),s&&this.subscribeToParents()}static mapWrites(t,n,r){return new Qc(`${n}<${t.nameAndSizeUntracked}>`,t,t.filters,t._applogs,null,r)}_parentSubscriptions=null;insert(t){let n=this._writeMapper?this._writeMapper(t):t;if(!(this._writeMapper&&!n))return this.parents.forEach(r=>r.insert(n))}insertRaw(t){let n=this._writeMapper?this._writeMapper(t):t;if(!(this._writeMapper&&!n))return this.parents.forEach(r=>r.insertRaw(n))}subscribeToParents(){this._parentSubscriptions=new Map;let t=ro(()=>{this.parents.length||Au("MappedThread has no parents",this),ln(`[MappedThread: ${this.name}] subscribing to parents:`,this.parents.map(r=>r.name));let n=new Set([...this._parentSubscriptions.keys()]);for(let r of this.parents){n.delete(r)&&ln(`[MappedThread: ${this.name}] Skipping re-sub to parent`,r.nameAndSizeUntracked),ln(`[MappedThread: ${this.name}] sub to new parent`,r.nameAndSizeUntracked);let s=this.onParentUpdate.bind(this,r),o=r.subscribe(s);this._parentSubscriptions.set(r,o)}for(let r of n)ln(`[MappedThread: ${this.name}] un-subscribing from old parent`,r.nameAndSizeUntracked),this._parentSubscriptions.get(r)(),this._parentSubscriptions.delete(r)})}subscribe(t){return this._parentSubscriptions||this.subscribeToParents(),super.subscribe(t)}triggerRemap(){if(!this._eventMapper)throw Eu("triggerRemap on a thread that is not actually mapping?!",this.nameAndSizeUntracked);Iu(`MappedThread{${this.nameAndSizeUntracked}} triggerRemap`),this.parents.length!==1&&Au(`MappedThread{${this.nameAndSizeUntracked}} triggerRemap with parentCount=${this.parents.length} - not meant for this`),this.parents.forEach(t=>{this.onParentUpdate(t,{init:Ve(()=>Nn(t.applogs))})})}onParentUpdate(t,n){ln(`MappedThread{${this.nameAndSizeUntracked}} parentUpdate`,n);let r=this._eventMapper?this._eventMapper(n,t):n;if(this._eventMapper)if(ln(`MappedThread{${this.nameAndSizeUntracked}} parentUpdate => mapped`,r),fi(r))this._applogs.replace([...r.init]);else{for(let i of r.added)this._applogs.splice(R_(this._applogs,i,"ts"),0,i);if(r.removed){for(let i of r.removed)if(!this._applogs.remove(i))if(!fi(n)&&n.removed?.includes(i))Iu("Ignoring remove event for non-existent because it was part of parent event's removed",i,n);else throw Eu(`MappedThread{${this.name}} toRemove contained log that doesn't exist`,i,{thread:this,event:n,mapResult:r})}}ln(`MappedThread{${this.nameAndSizeUntracked}} parentUpdate => deps?`,Yr(this._applogs)),this.notifySubscribers(r)}get readOnly(){return!1}},{WARN:EO,LOG:SO,DEBUG:PO,VERBOSE:Ao,ERROR:ow}=xe.setup(xe.INFO),$O=Xo("rollingFilter",function(t,n,r={}){let i=sw(n),s=Su(i),o=Pe.array(Ve(function(){return s(t.applogs)}),{deep:!1,name:`${t.name} | ${r.name||`rollingFilter.array{${ci(i)}}`}`}),u=b=>{let M;return fi(b)?M={init:s(b.init)}:M={added:s(b.added),removed:b.removed},Ao(`rollingFilter{${t.nameAndSizeUntracked} | ${r.name?` '${r.name}'}`:""} parentUpdate`,i,b,"=>",M),M},f=new Yc(`${t.name} | ${r.name||`rollingFilter{${ci(i)}}`}`,t,[...t.filters,...r.extraFilterName?[r.extraFilterName]:[]],o,u),c=ca(()=>Nn(n),b=>{Ao(`rollingFilter<${t.nameAndSizeUntracked}>${r.name?` '${r.name}'`:""} patternUpdate`,i,"=>",b),i=b,s=Su(i),f.triggerRemap()}),g=ir(o,()=>{Ao(`rollingFilter<${Ve(()=>t.name)}>${r.name?` '${r.name}'`:""} unobserve`,i),c(),g()});return f},{equals:_c,argsDebugName:(e,t,n)=>vc({caller:"rollingFilter",thread:e,pattern:t,args:n})}),RO=Xo("rollingMapper",function(t,n,r={}){let i=Ve(()=>n.call(null,{init:t.applogs},t));if(!fi(i))throw ow("Initial run must return init event");let s=i.init;return new Yc(`${t.name} | ${r.name||"rollingMapper"}`,t,[...t.filters,...r.extraFilterName?[r.extraFilterName]:[]],s,n)},{equals:_c,argsDebugName:(e,t,n)=>vc({caller:"rollingMapper",thread:e,args:n})}),NO=Xo("rollingAcc",function(t,n,r,i={}){let s=gt(r);return s({init:t.applogs},n),t.subscribe(o=>{s(o,n)}),n},{argsDebugName:(e,t,n,r)=>`rollingAcc{${e.nameAndSizeUntracked}${r?.name?` | ${r?.name}`:""}}`}),sw=function(t){let n=Ve(function(){return Object.fromEntries(Object.entries(Nn(t)).map(([i,s])=>[Nn(i),Nn(s)]))});if(!Object.entries(n).length)throw new Error("Pattern is empty");return n};function Su(e){return function(n){return n.filter(function(i){for(let s of Object.keys(e)){let o=e[s];if(o===void 0)continue;let u=i[s.startsWith("!")?s.slice(1):s];if(!Hc(s,o,u))return!1}return!0})}}var{WARN:CO,LOG:xO,DEBUG:UO,VERBOSE:jO,ERROR:DO}=xe.setup(xe.INFO);var{WARN:MO,LOG:LO,DEBUG:BO,VERBOSE:FO,ERROR:kO}=xe.setup(xe.INFO);function aw(e){return typeof e=="string"?e:JSON.stringify(e)}function uw(e,t){let n=aw(e),r=t??Ci({content:n,ts:xi()},7);return{en:r,applogs:[{en:r,at:"block/content",vl:n}]}}function cw(e,t,n,r){let i=r??Ci({blockID:e,childOf:t,after:n,ts:xi()},7);return{en:i,applogs:[{en:i,at:"relation/block",vl:e},{en:i,at:"relation/childOf",vl:t},{en:i,at:"relation/after",vl:n}]}}function ds(e,t,n){let r=[],{en:i,applogs:s}=uw(e.content);if(r.push(...s),t){let{applogs:u}=cw(i,t,n??null);r.push(...u)}let o=null;if(e.children)for(let u of e.children){let f=ds(u,i,o);r.push(...f.applogs),o=f.blockID}return{blockID:i,applogs:r}}function tI(e,t){let n=[],r=[],i=null;for(let s of e){let o=ds(s,t,i);n.push(...o.applogs),r.push(o.blockID),i=o.blockID}return{rootIDs:r,applogs:n}}function nI(e){return ds(e)}export{uw as a,cw as b,ds as c,tI as d,nI as e};
|
|
61
|
+
`+" ".repeat(t)+s):s==="{"&&r>0?(r++,n+=s):(s==="}"&&r>1&&r--,n+=s)}return n}function U_(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]instanceof li){if(t[n]!==e[n])return!1}else if(!ut.structural(e[n],t[n]))return!1;return!0}var{WARN:lu,LOG:zw,DEBUG:j_,VERBOSE:qw,ERROR:fn}=xe.setup(xe.INFO,{prefix:"[thread]"});function fi(e){return e.init!==void 0}var li=class{constructor(e,t,n,r=[],i={}){this.name=e,this._applogs=r,this.parents=t===null?null:Oa(t),this.filters=n,Ve(()=>this.parents?.length===0)&&lu("[Thread] empty parents array",e),i.skipObservable||oo(this,{applogsCids:lt,applogsByCid:lt,insert:gt,size:lt,isEmpty:lt,firstLog:lt,latestLog:lt},{name:`Thread{${e}}`})}filters;parents;_subscribers=[];get readOnly(){return this.parents.length!==1?!0:this.parents[0].readOnly}insert(e){if(this.readOnly)throw fn("[Thread] insert() called on read-only thread:",this.nameAndSizeUntracked);if(!this.parents)throw fn("[Thread] insert() called on non-writable thread without parents:",this.nameAndSizeUntracked);if(this.parents?.length!==1)throw fn("[Thread] insert() called on thread with multiple parents:",this.nameAndSizeUntracked);return this.parents[0].insert(e)}insertRaw(e){if(this.readOnly)throw fn("[Thread] insertRaw() called on read-only thread:",this.nameAndSizeUntracked);if(!this.parents)throw fn("[Thread] insertRaw() called on non-writable thread without parents:",this.nameAndSizeUntracked);if(this.parents?.length!==1)throw fn("[Thread] insertRaw() called on thread with multiple parents:",this.nameAndSizeUntracked);return this.parents[0].insertRaw(e)}subscribe(e){return this._subscribers.push(e),this.unsubscribe.bind(this,e)}unsubscribe(e){let t=this._subscribers.indexOf(e);t!==-1?this._subscribers.splice(t,1):lu("unsubscribe called for non-existent",e)}notifySubscribers(e){j_(`[thread: ${this.name}] notifying`,this._subscribers.length,"subscribers of",{...e,subs:this._subscribers});for(let t of this._subscribers)t(e)}get applogs(){return this._applogs}get applogsCids(){return this._applogs.map(e=>e.cid)}map(e){return this.applogs.map(e)}get findLast(){return this.applogs.findLast.bind(this.applogs)}get findFirst(){return this.applogs.find.bind(this.applogs)}get firstLog(){return this.applogs[0]}get latestLog(){return this.applogs[this.applogs.length-1]}hasApplog(e,t){if(t)return this.applogs.includes(e);if(!e.cid)throw fn("[hasApplogs] applog without CID:",e);return this.hasApplogCid(e.cid)}hasApplogCid(e){return this.applogsCids.includes(e.toString())}get applogsByCid(){return new Map(this.applogs.map(e=>[e.cid,e]))}getApplog(e){return this.applogsByCid.get(e.toString())}hasApplogWithDiffTs(e){return this.applogs.find(t=>t.en===e.en&&t.at===e.at&&t.vl===e.vl&&t.ag===e.ag)}get isEmpty(){return this.size===0}get size(){return this.applogs.length}get length(){return this.applogs.length}get untrackedSize(){return Ve(()=>this.size)}get nameAndSizeUntracked(){return Ve(()=>`${this.name} (${this.size})`)}get prettyName(){return x_(this.name)}get hasParents(){return!!this.parents?.length}};var D_={};po(D_,{code:()=>J0,decode:()=>kc,encode:()=>Fc,format:()=>wu,name:()=>H0,parse:()=>Y0,stringify:()=>wu});var M_=["string","number","bigint","symbol"],L_=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function B_(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(M_.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(F_(e))return"Buffer";let n=k_(e);return n||"Object"}function F_(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function k_(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(L_.includes(t))return t}var U=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};U.uint=new U(0,"uint",!0);U.negint=new U(1,"negint",!0);U.bytes=new U(2,"bytes",!0);U.string=new U(3,"string",!0);U.array=new U(4,"array",!1);U.map=new U(5,"map",!1);U.tag=new U(6,"tag",!1);U.float=new U(7,"float",!0);U.false=new U(7,"false",!0);U.true=new U(7,"true",!0);U.null=new U(7,"null",!0);U.undefined=new U(7,"undefined",!0);U.break=new U(7,"break",!0);var re=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}},Gn=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",K_=new TextDecoder,G_=new TextEncoder;function di(e){return Gn&&globalThis.Buffer.isBuffer(e)}function Yo(e){return e instanceof Uint8Array?di(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var V_=Gn?((e,t,n)=>n-t>64?globalThis.Buffer.from(e.subarray(t,n)).toString("utf8"):pu(e,t,n)):((e,t,n)=>n-t>64?K_.decode(e.subarray(t,n)):pu(e,t,n)),Tc=Gn?(e=>e.length>64?globalThis.Buffer.from(e):du(e)):(e=>e.length>64?G_.encode(e):du(e)),Qo=Gn?((e,t,n)=>di(e)?new Uint8Array(e.subarray(t,n)):e.slice(t,n)):((e,t,n)=>e.slice(t,n)),z_=Gn?((e,t)=>(e=e.map(n=>n instanceof Uint8Array?n:globalThis.Buffer.from(n)),Yo(globalThis.Buffer.concat(e,t)))):((e,t)=>{let n=new Uint8Array(t),r=0;for(let i of e)r+i.length>n.length&&(i=i.subarray(0,n.length-r)),n.set(i,r),r+=i.length;return n}),q_=Gn?(e=>globalThis.Buffer.allocUnsafe(e)):(e=>new Uint8Array(e));function W_(e,t){if(di(e)&&di(t))return e.compare(t);for(let n=0;n<e.length;n++)if(e[n]!==t[n])return e[n]<t[n]?-1:1;return 0}function du(e){let t=[],n=0;for(let r=0;r<e.length;r++){let i=e.charCodeAt(r);i<128?t[n++]=i:i<2048?(t[n++]=i>>6|192,t[n++]=i&63|128):(i&64512)===55296&&r+1<e.length&&(e.charCodeAt(r+1)&64512)===56320?(i=65536+((i&1023)<<10)+(e.charCodeAt(++r)&1023),t[n++]=i>>18|240,t[n++]=i>>12&63|128,t[n++]=i>>6&63|128,t[n++]=i&63|128):(t[n++]=i>>12|224,t[n++]=i>>6&63|128,t[n++]=i&63|128)}return t}function pu(e,t,n){let r=[];for(;t<n;){let i=e[t],s=null,o=i>239?4:i>223?3:i>191?2:1;if(t+o<=n){let u,f,c,g;switch(o){case 1:i<128&&(s=i);break;case 2:u=e[t+1],(u&192)===128&&(g=(i&31)<<6|u&63,g>127&&(s=g));break;case 3:u=e[t+1],f=e[t+2],(u&192)===128&&(f&192)===128&&(g=(i&15)<<12|(u&63)<<6|f&63,g>2047&&(g<55296||g>57343)&&(s=g));break;case 4:u=e[t+1],f=e[t+2],c=e[t+3],(u&192)===128&&(f&192)===128&&(c&192)===128&&(g=(i&15)<<18|(u&63)<<12|(f&63)<<6|c&63,g>65535&&g<1114112&&(s=g))}}s===null?(s=65533,o=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),t+=o}return wc(r)}var yu=4096;function wc(e){let t=e.length;if(t<=yu)return String.fromCharCode.apply(String,e);let n="",r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=yu));return n}var H_=256,Oc=class{constructor(e=H_){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let r=t.length-(this.maxCursor-this.cursor)-1;t.set(e,r)}else{if(t){let r=t.length-(this.maxCursor-this.cursor)-1;r<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,r),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=q_(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=Qo(n,0,this.cursor)}else t=z_(this.chunks,this.cursor);return e&&this.reset(),t}},de="CBOR decode error:",pn="CBOR encode error:",_r=[];_r[23]=1;_r[24]=2;_r[25]=3;_r[26]=5;_r[27]=9;function Vn(e,t,n){if(e.length-t<n)throw new Error(`${de} not enough data for type`)}var Me=[24,256,65536,4294967296,BigInt("18446744073709551616")];function gn(e,t,n){Vn(e,t,1);let r=e[t];if(n.strict===!0&&r<Me[0])throw new Error(`${de} integer encoded in more bytes than necessary (strict decode)`);return r}function mn(e,t,n){Vn(e,t,2);let r=e[t]<<8|e[t+1];if(n.strict===!0&&r<Me[1])throw new Error(`${de} integer encoded in more bytes than necessary (strict decode)`);return r}function bn(e,t,n){Vn(e,t,4);let r=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(n.strict===!0&&r<Me[2])throw new Error(`${de} integer encoded in more bytes than necessary (strict decode)`);return r}function vn(e,t,n){Vn(e,t,8);let r=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],i=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],s=(BigInt(r)<<BigInt(32))+BigInt(i);if(n.strict===!0&&s<Me[3])throw new Error(`${de} integer encoded in more bytes than necessary (strict decode)`);if(s<=Number.MAX_SAFE_INTEGER)return Number(s);if(n.allowBigInt===!0)return s;throw new Error(`${de} integers outside of the safe integer range are not supported`)}function J_(e,t,n,r){return new re(U.uint,gn(e,t+1,r),2)}function X_(e,t,n,r){return new re(U.uint,mn(e,t+1,r),3)}function Y_(e,t,n,r){return new re(U.uint,bn(e,t+1,r),5)}function Q_(e,t,n,r){return new re(U.uint,vn(e,t+1,r),9)}function _n(e,t){return pt(e,0,t.value)}function pt(e,t,n){if(n<Me[0]){let r=Number(n);e.push([t|r])}else if(n<Me[1]){let r=Number(n);e.push([t|24,r])}else if(n<Me[2]){let r=Number(n);e.push([t|25,r>>>8,r&255])}else if(n<Me[3]){let r=Number(n);e.push([t|26,r>>>24&255,r>>>16&255,r>>>8&255,r&255])}else{let r=BigInt(n);if(r<Me[4]){let i=[t|27,0,0,0,0,0,0,0],s=Number(r&BigInt(4294967295)),o=Number(r>>BigInt(32)&BigInt(4294967295));i[8]=s&255,s=s>>8,i[7]=s&255,s=s>>8,i[6]=s&255,s=s>>8,i[5]=s&255,i[4]=o&255,o=o>>8,i[3]=o&255,o=o>>8,i[2]=o&255,o=o>>8,i[1]=o&255,e.push(i)}else throw new Error(`${de} encountered BigInt larger than allowable range`)}}_n.encodedSize=function(t){return pt.encodedSize(t.value)};pt.encodedSize=function(t){return t<Me[0]?1:t<Me[1]?2:t<Me[2]?3:t<Me[3]?5:9};_n.compareTokens=function(t,n){return t.value<n.value?-1:t.value>n.value?1:0};function Z_(e,t,n,r){return new re(U.negint,-1-gn(e,t+1,r),2)}function eT(e,t,n,r){return new re(U.negint,-1-mn(e,t+1,r),3)}function tT(e,t,n,r){return new re(U.negint,-1-bn(e,t+1,r),5)}var Zo=BigInt(-1),Ac=BigInt(1);function nT(e,t,n,r){let i=vn(e,t+1,r);if(typeof i!="bigint"){let s=-1-i;if(s>=Number.MIN_SAFE_INTEGER)return new re(U.negint,s,9)}if(r.allowBigInt!==!0)throw new Error(`${de} integers outside of the safe integer range are not supported`);return new re(U.negint,Zo-BigInt(i),9)}function es(e,t){let n=t.value,r=typeof n=="bigint"?n*Zo-Ac:n*-1-1;pt(e,t.type.majorEncoded,r)}es.encodedSize=function(t){let n=t.value,r=typeof n=="bigint"?n*Zo-Ac:n*-1-1;return r<Me[0]?1:r<Me[1]?2:r<Me[2]?3:r<Me[3]?5:9};es.compareTokens=function(t,n){return t.value<n.value?1:t.value>n.value?-1:0};function Tr(e,t,n,r){Vn(e,t,n+r);let i=Qo(e,t+n,t+n+r);return new re(U.bytes,i,n+r)}function rT(e,t,n,r){return Tr(e,t,1,n)}function iT(e,t,n,r){return Tr(e,t,2,gn(e,t+1,r))}function oT(e,t,n,r){return Tr(e,t,3,mn(e,t+1,r))}function sT(e,t,n,r){return Tr(e,t,5,bn(e,t+1,r))}function aT(e,t,n,r){let i=vn(e,t+1,r);if(typeof i=="bigint")throw new Error(`${de} 64-bit integer bytes lengths not supported`);return Tr(e,t,9,i)}function pi(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===U.string?Tc(e.value):e.value),e.encodedBytes}function Si(e,t){let n=pi(t);pt(e,t.type.majorEncoded,n.length),e.push(n)}Si.encodedSize=function(t){let n=pi(t);return pt.encodedSize(n.length)+n.length};Si.compareTokens=function(t,n){return uT(pi(t),pi(n))};function uT(e,t){return e.length<t.length?-1:e.length>t.length?1:W_(e,t)}function wr(e,t,n,r,i){let s=n+r;Vn(e,t,s);let o=new re(U.string,V_(e,t+n,t+s),s);return i.retainStringBytes===!0&&(o.byteValue=Qo(e,t+n,t+s)),o}function cT(e,t,n,r){return wr(e,t,1,n,r)}function fT(e,t,n,r){return wr(e,t,2,gn(e,t+1,r),r)}function lT(e,t,n,r){return wr(e,t,3,mn(e,t+1,r),r)}function dT(e,t,n,r){return wr(e,t,5,bn(e,t+1,r),r)}function pT(e,t,n,r){let i=vn(e,t+1,r);if(typeof i=="bigint")throw new Error(`${de} 64-bit integer string lengths not supported`);return wr(e,t,9,i,r)}var yT=Si;function zn(e,t,n,r){return new re(U.array,r,n)}function hT(e,t,n,r){return zn(e,t,1,n)}function gT(e,t,n,r){return zn(e,t,2,gn(e,t+1,r))}function mT(e,t,n,r){return zn(e,t,3,mn(e,t+1,r))}function bT(e,t,n,r){return zn(e,t,5,bn(e,t+1,r))}function vT(e,t,n,r){let i=vn(e,t+1,r);if(typeof i=="bigint")throw new Error(`${de} 64-bit integer array lengths not supported`);return zn(e,t,9,i)}function _T(e,t,n,r){if(r.allowIndefinite===!1)throw new Error(`${de} indefinite length items not allowed`);return zn(e,t,1,1/0)}function ts(e,t){pt(e,U.array.majorEncoded,t.value)}ts.compareTokens=_n.compareTokens;ts.encodedSize=function(t){return pt.encodedSize(t.value)};function qn(e,t,n,r){return new re(U.map,r,n)}function TT(e,t,n,r){return qn(e,t,1,n)}function wT(e,t,n,r){return qn(e,t,2,gn(e,t+1,r))}function OT(e,t,n,r){return qn(e,t,3,mn(e,t+1,r))}function AT(e,t,n,r){return qn(e,t,5,bn(e,t+1,r))}function IT(e,t,n,r){let i=vn(e,t+1,r);if(typeof i=="bigint")throw new Error(`${de} 64-bit integer map lengths not supported`);return qn(e,t,9,i)}function ET(e,t,n,r){if(r.allowIndefinite===!1)throw new Error(`${de} indefinite length items not allowed`);return qn(e,t,1,1/0)}function ns(e,t){pt(e,U.map.majorEncoded,t.value)}ns.compareTokens=_n.compareTokens;ns.encodedSize=function(t){return pt.encodedSize(t.value)};function ST(e,t,n,r){return new re(U.tag,n,1)}function PT(e,t,n,r){return new re(U.tag,gn(e,t+1,r),2)}function $T(e,t,n,r){return new re(U.tag,mn(e,t+1,r),3)}function RT(e,t,n,r){return new re(U.tag,bn(e,t+1,r),5)}function NT(e,t,n,r){return new re(U.tag,vn(e,t+1,r),9)}function rs(e,t){pt(e,U.tag.majorEncoded,t.value)}rs.compareTokens=_n.compareTokens;rs.encodedSize=function(t){return pt.encodedSize(t.value)};var CT=20,xT=21,UT=22,jT=23;function DT(e,t,n,r){if(r.allowUndefined===!1)throw new Error(`${de} undefined values are not supported`);return r.coerceUndefinedToNull===!0?new re(U.null,null,1):new re(U.undefined,void 0,1)}function MT(e,t,n,r){if(r.allowIndefinite===!1)throw new Error(`${de} indefinite length items not allowed`);return new re(U.break,void 0,1)}function is(e,t,n){if(n){if(n.allowNaN===!1&&Number.isNaN(e))throw new Error(`${de} NaN values are not supported`);if(n.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${de} Infinity values are not supported`)}return new re(U.float,e,t)}function LT(e,t,n,r){return is(ss(e,t+1),3,r)}function BT(e,t,n,r){return is(as(e,t+1),5,r)}function FT(e,t,n,r){return is(Pc(e,t+1),9,r)}function os(e,t,n){let r=t.value;if(r===!1)e.push([U.float.majorEncoded|CT]);else if(r===!0)e.push([U.float.majorEncoded|xT]);else if(r===null)e.push([U.float.majorEncoded|UT]);else if(r===void 0)e.push([U.float.majorEncoded|jT]);else{let i,s=!1;(!n||n.float64!==!0)&&(Ec(r),i=ss(Ot,1),r===i||Number.isNaN(r)?(Ot[0]=249,e.push(Ot.slice(0,3)),s=!0):(Sc(r),i=as(Ot,1),r===i&&(Ot[0]=250,e.push(Ot.slice(0,5)),s=!0))),s||(kT(r),i=Pc(Ot,1),Ot[0]=251,e.push(Ot.slice(0,9)))}}os.encodedSize=function(t,n){let r=t.value;if(r===!1||r===!0||r===null||r===void 0)return 1;if(!n||n.float64!==!0){Ec(r);let i=ss(Ot,1);if(r===i||Number.isNaN(r))return 3;if(Sc(r),i=as(Ot,1),r===i)return 5}return 9};var Ic=new ArrayBuffer(9),dt=new DataView(Ic,1),Ot=new Uint8Array(Ic,0);function Ec(e){if(e===1/0)dt.setUint16(0,31744,!1);else if(e===-1/0)dt.setUint16(0,64512,!1);else if(Number.isNaN(e))dt.setUint16(0,32256,!1);else{dt.setFloat32(0,e);let t=dt.getUint32(0),n=(t&2139095040)>>23,r=t&8388607;if(n===255)dt.setUint16(0,31744,!1);else if(n===0)dt.setUint16(0,(e&2147483648)>>16|r>>13,!1);else{let i=n-127;i<-24?dt.setUint16(0,0):i<-14?dt.setUint16(0,(t&2147483648)>>16|1<<24+i,!1):dt.setUint16(0,(t&2147483648)>>16|i+15<<10|r>>13,!1)}}}function ss(e,t){if(e.length-t<2)throw new Error(`${de} not enough data for float16`);let n=(e[t]<<8)+e[t+1];if(n===31744)return 1/0;if(n===64512)return-1/0;if(n===32256)return NaN;let r=n>>10&31,i=n&1023,s;return r===0?s=i*2**-24:r!==31?s=(i+1024)*2**(r-25):s=i===0?1/0:NaN,n&32768?-s:s}function Sc(e){dt.setFloat32(0,e,!1)}function as(e,t){if(e.length-t<4)throw new Error(`${de} not enough data for float32`);let n=(e.byteOffset||0)+t;return new DataView(e.buffer,n,4).getFloat32(0,!1)}function kT(e){dt.setFloat64(0,e,!1)}function Pc(e,t){if(e.length-t<8)throw new Error(`${de} not enough data for float64`);let n=(e.byteOffset||0)+t;return new DataView(e.buffer,n,8).getFloat64(0,!1)}os.compareTokens=_n.compareTokens;function _e(e,t,n){throw new Error(`${de} encountered invalid minor (${n}) for major ${e[t]>>>5}`)}function Pi(e){return()=>{throw new Error(`${de} ${e}`)}}var oe=[];for(let e=0;e<=23;e++)oe[e]=_e;oe[24]=J_;oe[25]=X_;oe[26]=Y_;oe[27]=Q_;oe[28]=_e;oe[29]=_e;oe[30]=_e;oe[31]=_e;for(let e=32;e<=55;e++)oe[e]=_e;oe[56]=Z_;oe[57]=eT;oe[58]=tT;oe[59]=nT;oe[60]=_e;oe[61]=_e;oe[62]=_e;oe[63]=_e;for(let e=64;e<=87;e++)oe[e]=rT;oe[88]=iT;oe[89]=oT;oe[90]=sT;oe[91]=aT;oe[92]=_e;oe[93]=_e;oe[94]=_e;oe[95]=Pi("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)oe[e]=cT;oe[120]=fT;oe[121]=lT;oe[122]=dT;oe[123]=pT;oe[124]=_e;oe[125]=_e;oe[126]=_e;oe[127]=Pi("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)oe[e]=hT;oe[152]=gT;oe[153]=mT;oe[154]=bT;oe[155]=vT;oe[156]=_e;oe[157]=_e;oe[158]=_e;oe[159]=_T;for(let e=160;e<=183;e++)oe[e]=TT;oe[184]=wT;oe[185]=OT;oe[186]=AT;oe[187]=IT;oe[188]=_e;oe[189]=_e;oe[190]=_e;oe[191]=ET;for(let e=192;e<=215;e++)oe[e]=ST;oe[216]=PT;oe[217]=$T;oe[218]=RT;oe[219]=NT;oe[220]=_e;oe[221]=_e;oe[222]=_e;oe[223]=_e;for(let e=224;e<=243;e++)oe[e]=Pi("simple values are not supported");oe[244]=_e;oe[245]=_e;oe[246]=_e;oe[247]=DT;oe[248]=Pi("simple values are not supported");oe[249]=LT;oe[250]=BT;oe[251]=FT;oe[252]=_e;oe[253]=_e;oe[254]=_e;oe[255]=MT;var Nt=[];for(let e=0;e<24;e++)Nt[e]=new re(U.uint,e,1);for(let e=-1;e>=-24;e--)Nt[31-e]=new re(U.negint,e,1);Nt[64]=new re(U.bytes,new Uint8Array(0),1);Nt[96]=new re(U.string,"",1);Nt[128]=new re(U.array,0,1);Nt[160]=new re(U.map,0,1);Nt[244]=new re(U.false,!1,1);Nt[245]=new re(U.true,!0,1);Nt[246]=new re(U.null,null,1);function KT(){let e=[];return e[U.uint.major]=_n,e[U.negint.major]=es,e[U.bytes.major]=Si,e[U.string.major]=yT,e[U.array.major]=ts,e[U.map.major]=ns,e[U.tag.major]=rs,e[U.float.major]=os,e}var Ww=KT(),wo=new Oc,hu=class $c{constructor(t,n){this.obj=t,this.parent=n}includes(t){let n=this;do if(n.obj===t)return!0;while(n=n.parent);return!1}static createCheck(t,n){if(t&&t.includes(n))throw new Error(`${pn} object contains circular references`);return new $c(n,t)}},Wt={null:new re(U.null,null),undefined:new re(U.undefined,void 0),true:new re(U.true,!0),false:new re(U.false,!1),emptyArray:new re(U.array,0),emptyMap:new re(U.map,0)},Xt={number(e,t,n,r){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new re(U.float,e):e>=0?new re(U.uint,e):new re(U.negint,e)},bigint(e,t,n,r){return e>=BigInt(0)?new re(U.uint,e):new re(U.negint,e)},Uint8Array(e,t,n,r){return new re(U.bytes,e)},string(e,t,n,r){return new re(U.string,e)},boolean(e,t,n,r){return e?Wt.true:Wt.false},null(e,t,n,r){return Wt.null},undefined(e,t,n,r){return Wt.undefined},ArrayBuffer(e,t,n,r){return new re(U.bytes,new Uint8Array(e))},DataView(e,t,n,r){return new re(U.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,n,r){if(!e.length)return n.addBreakTokens===!0?[Wt.emptyArray,new re(U.break)]:Wt.emptyArray;r=hu.createCheck(r,e);let i=[],s=0;for(let o of e)i[s++]=ei(o,n,r);return n.addBreakTokens?[new re(U.array,e.length),i,new re(U.break)]:[new re(U.array,e.length),i]},Object(e,t,n,r){let i=t!=="Object",s=i?e.keys():Object.keys(e),o=i?e.size:s.length;if(!o)return n.addBreakTokens===!0?[Wt.emptyMap,new re(U.break)]:Wt.emptyMap;r=hu.createCheck(r,e);let u=[],f=0;for(let c of s)u[f++]=[ei(c,n,r),ei(i?e.get(c):e[c],n,r)];return GT(u,n),n.addBreakTokens?[new re(U.map,o),u,new re(U.break)]:[new re(U.map,o),u]}};Xt.Map=Xt.Object;Xt.Buffer=Xt.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Xt[`${e}Array`]=Xt.DataView;function ei(e,t={},n){let r=B_(e),i=t&&t.typeEncoders&&t.typeEncoders[r]||Xt[r];if(typeof i=="function"){let o=i(e,r,t,n);if(o!=null)return o}let s=Xt[r];if(!s)throw new Error(`${pn} unsupported type: ${r}`);return s(e,r,t,n)}function GT(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Rc(e,t,n,r){if(Array.isArray(t))for(let i of t)Rc(e,i,n,r);else n[t.type.major](e,t,r)}function VT(e,t,n){let r=ei(e,n);if(!Array.isArray(r)&&n.quickEncodeToken){let i=n.quickEncodeToken(r);if(i)return i;let s=t[r.type.major];if(s.encodedSize){let o=s.encodedSize(r,n),u=new Oc(o);if(s(u,r,n),u.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${r} was wrong`);return Yo(u.chunks[0])}}return wo.reset(),Rc(wo,r,t,n),wo.toBytes(!0)}var zT={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},qT=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=Nt[e];if(t===void 0){let n=oe[e];if(!n)throw new Error(`${de} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let r=e&31;t=n(this.data,this._pos,r,this.options)}return this._pos+=t.encodedLength,t}},mr=Symbol.for("DONE"),$i=Symbol.for("BREAK");function WT(e,t,n){let r=[];for(let i=0;i<e.value;i++){let s=br(t,n);if(s===$i){if(e.value===1/0)break;throw new Error(`${de} got unexpected break to lengthed array`)}if(s===mr)throw new Error(`${de} found array but not enough entries (got ${i}, expected ${e.value})`);r[i]=s}return r}function HT(e,t,n){let r=n.useMaps===!0,i=r?void 0:{},s=r?new Map:void 0;for(let o=0;o<e.value;o++){let u=br(t,n);if(u===$i){if(e.value===1/0)break;throw new Error(`${de} got unexpected break to lengthed map`)}if(u===mr)throw new Error(`${de} found map but not enough entries (got ${o} [no key], expected ${e.value})`);if(r!==!0&&typeof u!="string")throw new Error(`${de} non-string keys not supported (got ${typeof u})`);if(n.rejectDuplicateMapKeys===!0&&(r&&s.has(u)||!r&&u in i))throw new Error(`${de} found repeat map key "${u}"`);let f=br(t,n);if(f===mr)throw new Error(`${de} found map but not enough entries (got ${o} [no value], expected ${e.value})`);r?s.set(u,f):i[u]=f}return r?s:i}function br(e,t){if(e.done())return mr;let n=e.next();if(n.type===U.break)return $i;if(n.type.terminal)return n.value;if(n.type===U.array)return WT(n,e,t);if(n.type===U.map)return HT(n,e,t);if(n.type===U.tag){if(t.tags&&typeof t.tags[n.value]=="function"){let r=br(e,t);return t.tags[n.value](r)}throw new Error(`${de} tag not supported (${n.value})`)}throw new Error("unsupported")}function JT(e,t){if(!(e instanceof Uint8Array))throw new Error(`${de} data to decode must be a Uint8Array`);t=Object.assign({},zT,t);let n=t.tokenizer||new qT(e,t),r=br(n,t);if(r===mr)throw new Error(`${de} did not find any content to decode`);if(r===$i)throw new Error(`${de} got unexpected break`);return[r,e.subarray(n.pos())]}function XT(e,t){let[n,r]=JT(e,t);if(r.length>0)throw new Error(`${de} too many terminals, data makes no sense`);return n}var YT=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let t=this.inRecursive[this.inRecursive.length-1];t&&(t.type===U.array&&(t.elements++,t.elements!==1&&e.push([44])),t.type===U.map&&(t.elements++,t.elements!==1&&(t.elements%2===1?e.push([44]):e.push([58]))))}[U.uint.major](e,t){this.prefix(e);let n=String(t.value),r=[];for(let i=0;i<n.length;i++)r[i]=n.charCodeAt(i);e.push(r)}[U.negint.major](e,t){this[U.uint.major](e,t)}[U.bytes.major](e,t){throw new Error(`${pn} unsupported type: Uint8Array`)}[U.string.major](e,t){this.prefix(e);let n=Tc(JSON.stringify(t.value));e.push(n.length>32?Yo(n):n)}[U.array.major](e,t){this.prefix(e),this.inRecursive.push({type:U.array,elements:0}),e.push([91])}[U.map.major](e,t){this.prefix(e),this.inRecursive.push({type:U.map,elements:0}),e.push([123])}[U.tag.major](e,t){}[U.float.major](e,t){if(t.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===U.array)e.push([93]);else if(s.type===U.map)e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(t.value===void 0)throw new Error(`${pn} unsupported type: undefined`);if(this.prefix(e),t.type.name==="true"){e.push([116,114,117,101]);return}else if(t.type.name==="false"){e.push([102,97,108,115,101]);return}else if(t.type.name==="null"){e.push([110,117,108,108]);return}let n=String(t.value),r=[],i=!1;for(let s=0;s<n.length;s++)r[s]=n.charCodeAt(s),!i&&(r[s]===46||r[s]===101||r[s]===69)&&(i=!0);i||(r.push(46),r.push(48)),e.push(r)}};function QT(e,t){if(Array.isArray(e[0])||Array.isArray(t[0]))throw new Error(`${pn} complex map keys are not supported`);let n=e[0],r=t[0];if(n.type!==U.string||r.type!==U.string)throw new Error(`${pn} non-string map keys are not supported`);if(n<r)return-1;if(n>r)return 1;throw new Error(`${pn} unexpected duplicate map keys, this is not supported`)}var ZT={addBreakTokens:!0,mapSorter:QT};function e0(e,t){return t=Object.assign({},ZT,t),VT(e,new YT,t)}var Nc=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${de} unexpected end of input at position ${this._pos}`);for(let t=0;t<e.length;t++)if(this.data[this._pos++]!==e[t])throw new Error(`${de} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,t=!1,n=!1,r=o=>{for(;!this.done();){let u=this.ch();if(o.includes(u))this._pos++;else break}};if(this.ch()===45&&(t=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new re(U.uint,0,this._pos-e);if(r([48,49,50,51,52,53,54,55,56,57]),t&&this._pos===e+1)throw new Error(`${de} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${de} unexpected token at position ${this._pos}`);n=!0,this._pos++,r([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,r([48,49,50,51,52,53,54,55,56,57]));let i=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(i);return n?new re(U.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new re(s>=0?U.uint:U.negint,s,this._pos-e):new re(s>=0?U.uint:U.negint,BigInt(i),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${de} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let i=this._pos,s=0;i<this.data.length&&s<65536;i++,s++){let o=this.data[i];if(o===92||o<32||o>=128)break;if(o===34){let u=String.fromCharCode.apply(null,this.data.subarray(this._pos,i));return this._pos=i+1,new re(U.string,u,s)}}let e=this._pos,t=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${de} unexpected end of unicode escape sequence at position ${this._pos}`);let i=0;for(let s=0;s<4;s++){let o=this.ch();if(o>=48&&o<=57)o-=48;else if(o>=97&&o<=102)o=o-97+10;else if(o>=65&&o<=70)o=o-65+10;else throw new Error(`${de} unexpected unicode escape character at position ${this._pos}`);i=i*16+o,this._pos++}return i},r=()=>{let i=this.ch(),s=null,o=i>239?4:i>223?3:i>191?2:1;if(this._pos+o>this.data.length)throw new Error(`${de} unexpected unicode sequence at position ${this._pos}`);let u,f,c,g;switch(o){case 1:i<128&&(s=i);break;case 2:u=this.data[this._pos+1],(u&192)===128&&(g=(i&31)<<6|u&63,g>127&&(s=g));break;case 3:u=this.data[this._pos+1],f=this.data[this._pos+2],(u&192)===128&&(f&192)===128&&(g=(i&15)<<12|(u&63)<<6|f&63,g>2047&&(g<55296||g>57343)&&(s=g));break;case 4:u=this.data[this._pos+1],f=this.data[this._pos+2],c=this.data[this._pos+3],(u&192)===128&&(f&192)===128&&(c&192)===128&&(g=(i&15)<<18|(u&63)<<12|(f&63)<<6|c&63,g>65535&&g<1114112&&(s=g))}s===null?(s=65533,o=1):s>65535&&(s-=65536,t.push(s>>>10&1023|55296),s=56320|s&1023),t.push(s),this._pos+=o};for(;!this.done();){let i=this.ch(),s;switch(i){case 92:if(this._pos++,this.done())throw new Error(`${de} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:t.push(s);break;case 98:t.push(8);break;case 116:t.push(9);break;case 110:t.push(10);break;case 102:t.push(12);break;case 114:t.push(13);break;case 117:t.push(n());break;default:throw new Error(`${de} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new re(U.string,wc(t),this._pos-e);default:if(i<32)throw new Error(`${de} invalid control character at position ${this._pos}`);i<128?(t.push(i),this._pos++):r()}}throw new Error(`${de} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new re(U.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new re(U.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new re(U.null,null,4);case 102:return this.expect([102,97,108,115,101]),new re(U.false,!1,5);case 116:return this.expect([116,114,117,101]),new re(U.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${de} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new re(U.break,void 0,1);if(this.ch()!==44)throw new Error(`${de} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new re(U.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new re(U.break,void 0,1);if(this.ch()!==44)throw new Error(`${de} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new re(U.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${de} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${de} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function t0(e,t){return t=Object.assign({tokenizer:new Nc(e,t)},t),XT(e,t)}var Hw=new Uint8Array(0);function n0(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.byteLength;n++)if(e[n]!==t[n])return!1;return!0}function us(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function r0(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<e.length;i++){var s=e.charAt(i),o=s.charCodeAt(0);if(n[o]!==255)throw new TypeError(s+" is ambiguous");n[o]=i}var u=e.length,f=e.charAt(0),c=Math.log(u)/Math.log(256),g=Math.log(256)/Math.log(u);function b(L){if(L instanceof Uint8Array||(ArrayBuffer.isView(L)?L=new Uint8Array(L.buffer,L.byteOffset,L.byteLength):Array.isArray(L)&&(L=Uint8Array.from(L))),!(L instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(L.length===0)return"";for(var H=0,Z=0,K=0,B=L.length;K!==B&&L[K]===0;)K++,H++;for(var V=(B-K)*g+1>>>0,q=new Uint8Array(V);K!==B;){for(var F=L[K],ee=0,z=V-1;(F!==0||ee<Z)&&z!==-1;z--,ee++)F+=256*q[z]>>>0,q[z]=F%u>>>0,F=F/u>>>0;if(F!==0)throw new Error("Non-zero carry");Z=ee,K++}for(var fe=V-Z;fe!==V&&q[fe]===0;)fe++;for(var N=f.repeat(H);fe<V;++fe)N+=e.charAt(q[fe]);return N}function M(L){if(typeof L!="string")throw new TypeError("Expected String");if(L.length===0)return new Uint8Array;var H=0;if(L[H]!==" "){for(var Z=0,K=0;L[H]===f;)Z++,H++;for(var B=(L.length-H)*c+1>>>0,V=new Uint8Array(B);L[H];){var q=n[L.charCodeAt(H)];if(q===255)return;for(var F=0,ee=B-1;(q!==0||F<K)&&ee!==-1;ee--,F++)q+=u*V[ee]>>>0,V[ee]=q%256>>>0,q=q/256>>>0;if(q!==0)throw new Error("Non-zero carry");K=F,H++}if(L[H]!==" "){for(var z=B-K;z!==B&&V[z]===0;)z++;for(var fe=new Uint8Array(Z+(B-z)),N=Z;z!==B;)fe[N++]=V[z++];return fe}}}function $(L){var H=M(L);if(H)return H;throw new Error(`Non-${t} character`)}return{encode:b,decodeUnsafe:M,decode:$}}var i0=r0,o0=i0,s0=o0,a0=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},u0=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let r=t.codePointAt(0);if(r===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r,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 Cc(this,e)}},c0=class{decoders;constructor(e){this.decoders=e}or(e){return Cc(this,e)}decode(e){let t=e[0],n=this.decoders[t];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 Cc(e,t){return new c0({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var f0=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,r){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=r,this.encoder=new a0(e,t,n),this.decoder=new u0(e,t,r)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function xc({name:e,prefix:t,encode:n,decode:r}){return new f0(e,t,n,r)}function Ri({name:e,prefix:t,alphabet:n}){let{encode:r,decode:i}=s0(n,e);return xc({prefix:t,name:e,encode:r,decode:s=>us(i(s))})}function l0(e,t,n,r){let i=e.length;for(;e[i-1]==="=";)--i;let s=new Uint8Array(i*n/8|0),o=0,u=0,f=0;for(let c=0;c<i;++c){let g=t[e[c]];if(g===void 0)throw new SyntaxError(`Non-${r} character`);u=u<<n|g,o+=n,o>=8&&(o-=8,s[f++]=255&u>>o)}if(o>=n||(255&u<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return s}function d0(e,t,n){let r=t[t.length-1]==="=",i=(1<<n)-1,s="",o=0,u=0;for(let f=0;f<e.length;++f)for(u=u<<8|e[f],o+=8;o>n;)o-=n,s+=t[i&u>>o];if(o!==0&&(s+=t[i&u<<n-o]),r)for(;(s.length*n&7)!==0;)s+="=";return s}function p0(e){let t={};for(let n=0;n<e.length;++n)t[e[n]]=n;return t}function et({name:e,prefix:t,bitsPerChar:n,alphabet:r}){let i=p0(r);return xc({prefix:t,name:e,encode(s){return d0(s,r,n)},decode(s){return l0(s,i,n,e)}})}var ti=et({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Jw=et({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xw=et({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Yw=et({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Qw=et({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Zw=et({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),eO=et({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tO=et({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),nO=et({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5}),Oo=Ri({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),rO=Ri({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"}),Ht=Ri({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),iO=Ri({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"}),y0={};po(y0,{Digest:()=>Ni,create:()=>cs,decode:()=>jc,equals:()=>Dc,hasCode:()=>x0});var h0=Uc,gu=128,g0=127,m0=~g0,b0=Math.pow(2,31);function Uc(e,t,n){t=t||[],n=n||0;for(var r=n;e>=b0;)t[n++]=e&255|gu,e/=128;for(;e&m0;)t[n++]=e&255|gu,e>>>=7;return t[n]=e|0,Uc.bytes=n-r+1,t}var v0=$o,_0=128,mu=127;function $o(e,r){var n=0,r=r||0,i=0,s=r,o,u=e.length;do{if(s>=u)throw $o.bytes=0,new RangeError("Could not decode varint");o=e[s++],n+=i<28?(o&mu)<<i:(o&mu)*Math.pow(2,i),i+=7}while(o>=_0);return $o.bytes=s-r,n}var T0=Math.pow(2,7),w0=Math.pow(2,14),O0=Math.pow(2,21),A0=Math.pow(2,28),I0=Math.pow(2,35),E0=Math.pow(2,42),S0=Math.pow(2,49),P0=Math.pow(2,56),$0=Math.pow(2,63),R0=function(e){return e<T0?1:e<w0?2:e<O0?3:e<A0?4:e<I0?5:e<E0?6:e<S0?7:e<P0?8:e<$0?9:10},N0={encode:h0,decode:v0,encodingLength:R0},C0=N0,yi=C0;function Ro(e,t=0){return[yi.decode(e,t),yi.decode.bytes]}function hi(e,t,n=0){return yi.encode(e,t,n),t}function gi(e){return yi.encodingLength(e)}function cs(e,t){let n=t.byteLength,r=gi(e),i=r+gi(n),s=new Uint8Array(i+n);return hi(e,s,0),hi(n,s,r),s.set(t,i),new Ni(e,n,t,s)}function jc(e){let t=us(e),[n,r]=Ro(t),[i,s]=Ro(t.subarray(r)),o=t.subarray(r+s);if(o.byteLength!==i)throw new Error("Incorrect length");return new Ni(n,i,o,t)}function Dc(e,t){if(e===t)return!0;{let n=t;return e.code===n.code&&e.size===n.size&&n.bytes instanceof Uint8Array&&n0(e.bytes,n.bytes)}}var Ni=class{code;size;digest;bytes;constructor(e,t,n,r){this.code=e,this.size=t,this.digest=n,this.bytes=r}};function x0(e,t){return e.code===t}function bu(e,t){let{bytes:n,version:r}=e;switch(r){case 0:return j0(n,No(e),t??Ht.encoder);default:return D0(n,No(e),t??ti.encoder)}}var vu=new WeakMap;function No(e){let t=vu.get(e);if(t==null){let n=new Map;return vu.set(e,n),n}return t}var Mc=class Be{code;version;multihash;bytes;"/";constructor(t,n,r,i){this.code=n,this.version=t,this.multihash=r,this.bytes=i,this["/"]=i}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:t,multihash:n}=this;if(t!==cr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(n.code!==M0)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return Be.createV0(n)}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:t,digest:n}=this.multihash,r=cs(t,n);return Be.createV1(this.code,r)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return Be.equals(this,t)}static equals(t,n){let r=n;return r!=null&&t.code===r.code&&t.version===r.version&&Dc(t.multihash,r.multihash)}toString(t){return bu(this,t)}toJSON(){return{"/":bu(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let n=t;if(n instanceof Be)return n;if(n["/"]!=null&&n["/"]===n.bytes||n.asCID===n){let{version:r,code:i,multihash:s,bytes:o}=n;return new Be(r,i,s,o??_u(r,i,s.bytes))}else if(n[L0]===!0){let{version:r,multihash:i,code:s}=n,o=jc(i);return Be.create(r,s,o)}else return null}static create(t,n,r){if(typeof n!="number")throw new Error("String codecs are no longer supported");if(!(r.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(n!==cr)throw new Error(`Version 0 CID must use dag-pb (code: ${cr}) block encoding`);return new Be(t,n,r,r.bytes)}case 1:{let i=_u(t,n,r.bytes);return new Be(t,n,r,i)}default:throw new Error("Invalid version")}}static createV0(t){return Be.create(0,cr,t)}static createV1(t,n){return Be.create(1,t,n)}static decode(t){let[n,r]=Be.decodeFirst(t);if(r.length!==0)throw new Error("Incorrect length");return n}static decodeFirst(t){let n=Be.inspectBytes(t),r=n.size-n.multihashSize,i=us(t.subarray(r,r+n.multihashSize));if(i.byteLength!==n.multihashSize)throw new Error("Incorrect length");let s=i.subarray(n.multihashSize-n.digestSize),o=new Ni(n.multihashCode,n.digestSize,s,i);return[n.version===0?Be.createV0(o):Be.createV1(n.codec,o),t.subarray(n.size)]}static inspectBytes(t){let n=0,r=()=>{let[b,M]=Ro(t.subarray(n));return n+=M,b},i=r(),s=cr;if(i===18?(i=0,n=0):s=r(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let o=n,u=r(),f=r(),c=n+f,g=c-o;return{version:i,codec:s,multihashCode:u,digestSize:f,multihashSize:g,size:c}}static parse(t,n){let[r,i]=U0(t,n),s=Be.decode(i);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return No(s).set(r,t),s}};function U0(e,t){switch(e[0]){case"Q":{let n=t??Ht;return[Ht.prefix,n.decode(`${Ht.prefix}${e}`)]}case Ht.prefix:{let n=t??Ht;return[Ht.prefix,n.decode(e)]}case ti.prefix:{let n=t??ti;return[ti.prefix,n.decode(e)]}case Oo.prefix:{let n=t??Oo;return[Oo.prefix,n.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function j0(e,t,n){let{prefix:r}=n;if(r!==Ht.prefix)throw Error(`Cannot string encode V0 in ${n.name} encoding`);let i=t.get(r);if(i==null){let s=n.encode(e).slice(1);return t.set(r,s),s}else return i}function D0(e,t,n){let{prefix:r}=n,i=t.get(r);if(i==null){let s=n.encode(e);return t.set(r,s),s}else return i}var cr=112,M0=18;function _u(e,t,n){let r=gi(e),i=r+gi(t),s=new Uint8Array(i+n.byteLength);return hi(e,s,0),hi(t,s,r),s.set(n,i),s}var L0=Symbol.for("@ipld/js-cid/CID"),B0=20;function Lc({name:e,code:t,encode:n,minDigestLength:r,maxDigestLength:i}){return new F0(e,t,n,r,i)}var F0=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,r,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=r??B0,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Tu(n,this.code,t?.truncate):n.then(r=>Tu(r,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Tu(e,t,n){if(n!=null&&n!==e.byteLength){if(n>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,n)}return cs(t,e)}var Bc=et({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),oO=et({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),sO=et({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),aO=et({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function k0(e){return e instanceof ArrayBuffer?new Uint8Array(e,0,e.byteLength):e}function K0(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=Mc.asCID(e);if(!t)return null;let n=t.toString();return[new re(U.map,1/0,1),new re(U.string,"/",1),new re(U.string,n,n.length),new re(U.break,void 0,1)]}function mi(e){let t=Bc.encode(e).slice(1);return[new re(U.map,1/0,1),new re(U.string,"/",1),new re(U.map,1/0,1),new re(U.string,"bytes",5),new re(U.string,t,t.length),new re(U.break,void 0,1),new re(U.break,void 0,1)]}function wt(e){return mi(new Uint8Array(e.buffer,e.byteOffset,e.byteLength))}function G0(e){return mi(new Uint8Array(e))}function V0(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function z0(e){if(Number.isNaN(e))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(e===1/0||e===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var q0={typeEncoders:{Object:K0,Buffer:mi,Uint8Array:mi,Int8Array:wt,Uint16Array:wt,Int16Array:wt,Uint32Array:wt,Int32Array:wt,Float32Array:wt,Float64Array:wt,Uint8ClampedArray:wt,BigInt64Array:wt,BigUint64Array:wt,DataView:wt,ArrayBuffer:G0,undefined:V0,number:z0}},W0=class extends Nc{constructor(e,t){super(e,t),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(e.type===U.map){let t=this._next();if(t.type===U.string&&t.value==="/"){let n=this._next();if(n.type===U.string){if(this._next().type!==U.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new re(U.tag,42,0)}if(n.type===U.map){let r=this._next();if(r.type===U.string&&r.value==="bytes"){let i=this._next();if(i.type===U.string){for(let o=0;o<2;o++)if(this._next().type!==U.break)throw new Error("Invalid encoded Bytes form");let s=Bc.decode(`m${i.value}`);return new re(U.bytes,s,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(r)}this.tokenBuffer.push(n)}this.tokenBuffer.push(t)}return e}},Co={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Co.tags[42]=Mc.parse;var H0="dag-json",J0=297,Fc=e=>e0(e,q0),kc=e=>{let t=k0(e),n=Object.assign(Co,{tokenizer:new W0(t,Co)});return t0(t,n)},wu=e=>X0.decode(Fc(e)),X0=new TextDecoder,Y0=e=>kc(Q0.encode(e)),Q0=new TextEncoder;var Ue=qt(Lt(),1),Kc=qt(Sd(),1),xo=e=>Ue.Type.Union([e,Ue.Type.Null()]);var Gc=/^(k51qz|baguq)[0-9a-z]{56,57}$/,Z0=/^[0-9A-Fa-f]{7,8}$/g;Ue.FormatRegistry.Set("EntityID",e=>!!e.match(Z0)||!!e.match(Gc));var Vc=Ue.Type.String();Ue.FormatRegistry.Set("CID",e=>!!e.match(Gc));var fs=Ue.Type.String({format:"CID"}),ew=/^http([s]?):\/\/.*\..*/;Ue.FormatRegistry.Set("URL",e=>!!e.match(ew));var tw=Ue.Type.String({format:"URL"}),ls=Ue.Type.Object({en:Vc,at:Ue.Type.String(),vl:xo(Ue.Type.Union([Ue.Type.String(),Ue.Type.Boolean(),Ue.Type.Number()])),ts:Ue.Type.String(),ag:Ue.Type.String(),pv:xo(fs)}),Uo=Kc.TypeCompiler.Compile(ls);var nw=Uo.Check.bind(Uo),zc=Ue.Type.Composite([Ue.Type.Object({cid:fs}),ls]),jo=Kc.TypeCompiler.Compile(zc);var rw=jo.Check.bind(jo);function qc(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var uO=Lc({name:"sha2-256",code:18,encode:qc("SHA-256")}),cO=Lc({name:"sha2-512",code:19,encode:qc("SHA-512")}),{WARN:fO,LOG:lO,DEBUG:dO,VERBOSE:pO,ERROR:yO}=xe.setup(xe.INFO);var{WARN:hO,LOG:gO,DEBUG:mO,VERBOSE:bO,ERROR:vO}=xe.setup(xe.INFO);var Wc=(e,t,n)=>ut.structural(cu(t,e),cu(n,e));var iw=v_(Wc,["en","at"]);var Ci=(e,t=8)=>Xc(ci(e),31,t);function Hc(e,t,n){let r;if(t){let i=typeof t;i==="string"?r=t===n:i==="function"?r=t(n):typeof t.has=="function"?r=t.has(n):Array.isArray(t)&&!Array.isArray(n)?r=t.includes(n):r=t===n}else r=t===n;return e.charAt(0)==="!"?!r:r}var Jc=function(t){for(var n=0,r=0,i=t.length;r<i;r++)n+=t[r];return n},Ou=function(t){return Jc(t)/t.length},Qe={max:function(e){return Math.max.apply(null,e)},min:function(e){return Math.min.apply(null,e)},range:function(e){return Qe.max(e)-Qe.min(e)},midrange:function(e){return Qe.range(e)/2},sum:Jc,mean:Ou,average:Ou,median:function(e){e.sort(function(n,r){return n-r});var t=e.length/2;return t%1?e[t-.5]:(e[t-1]+e[t])/2},modes:function(e){if(!e.length)return[];var t={},n=0,r=[];return e.forEach(function(i){t[i]?t[i]++:t[i]=1,t[i]>n?(r=[i],n=t[i]):t[i]===n&&(r.push(i),n=t[i])}),r},variance:function(e){var t=Qe.mean(e);return Qe.mean(e.map(function(n){return Math.pow(n-t,2)}))},standardDeviation:function(e){return Math.sqrt(Qe.variance(e))},meanAbsoluteDeviation:function(e){var t=Qe.mean(e);return Qe.mean(e.map(function(n){return Math.abs(n-t)}))},zScores:function(e){var t=Qe.mean(e),n=Qe.standardDeviation(e);return e.map(function(r){return(r-t)/n})}};Qe.average=Qe.mean;var Xc=function(e,t=13,n){if(!e?.length)throw new Error(`Empty string: ${e}`);let r=3735928559^t,i=1103547991^t;for(let o=0,u;o<e.length;o++)u=e.charCodeAt(o),r=Math.imul(r^u,2654435761),i=Math.imul(i^u,1597334677);return r=Math.imul(r^r>>>16,2246822507)^Math.imul(i^i>>>13,3266489909),i=Math.imul(i^i>>>16,2246822507)^Math.imul(r^r>>>13,3266489909),(4294967296*(2097151&i)+(r>>>0)).toString(16).slice(-n).padStart(n,"0")};function xi(){return new Date().toISOString()}var{WARN:_O,LOG:TO,DEBUG:wO,VERBOSE:OO,ERROR:AO}=xe.setup(xe.INFO);var{WARN:Au,LOG:IO,DEBUG:Iu,VERBOSE:ln,ERROR:Eu}=xe.setup(xe.INFO),Yc=class Qc extends li{constructor(t,n,r,i,s,o=null){super(t,n,r,s?Pe.array([...i],{deep:!1,name:`${t}.array`}):i),this.name=t,this._initialLogs=i,this._eventMapper=s,this._writeMapper=o,oo(this,{onParentUpdate:gt}),s&&this.subscribeToParents()}static mapWrites(t,n,r){return new Qc(`${n}<${t.nameAndSizeUntracked}>`,t,t.filters,t._applogs,null,r)}_parentSubscriptions=null;insert(t){let n=this._writeMapper?this._writeMapper(t):t;if(!(this._writeMapper&&!n))return this.parents.forEach(r=>r.insert(n))}insertRaw(t){let n=this._writeMapper?this._writeMapper(t):t;if(!(this._writeMapper&&!n))return this.parents.forEach(r=>r.insertRaw(n))}subscribeToParents(){this._parentSubscriptions=new Map;let t=ro(()=>{this.parents.length||Au("MappedThread has no parents",this),ln(`[MappedThread: ${this.name}] subscribing to parents:`,this.parents.map(r=>r.name));let n=new Set([...this._parentSubscriptions.keys()]);for(let r of this.parents){n.delete(r)&&ln(`[MappedThread: ${this.name}] Skipping re-sub to parent`,r.nameAndSizeUntracked),ln(`[MappedThread: ${this.name}] sub to new parent`,r.nameAndSizeUntracked);let s=this.onParentUpdate.bind(this,r),o=r.subscribe(s);this._parentSubscriptions.set(r,o)}for(let r of n)ln(`[MappedThread: ${this.name}] un-subscribing from old parent`,r.nameAndSizeUntracked),this._parentSubscriptions.get(r)(),this._parentSubscriptions.delete(r)})}subscribe(t){return this._parentSubscriptions||this.subscribeToParents(),super.subscribe(t)}triggerRemap(){if(!this._eventMapper)throw Eu("triggerRemap on a thread that is not actually mapping?!",this.nameAndSizeUntracked);Iu(`MappedThread{${this.nameAndSizeUntracked}} triggerRemap`),this.parents.length!==1&&Au(`MappedThread{${this.nameAndSizeUntracked}} triggerRemap with parentCount=${this.parents.length} - not meant for this`),this.parents.forEach(t=>{this.onParentUpdate(t,{init:Ve(()=>Nn(t.applogs))})})}onParentUpdate(t,n){ln(`MappedThread{${this.nameAndSizeUntracked}} parentUpdate`,n);let r=this._eventMapper?this._eventMapper(n,t):n;if(this._eventMapper)if(ln(`MappedThread{${this.nameAndSizeUntracked}} parentUpdate => mapped`,r),fi(r))this._applogs.replace([...r.init]);else{for(let i of r.added)this._applogs.splice(R_(this._applogs,i,"ts"),0,i);if(r.removed){for(let i of r.removed)if(!this._applogs.remove(i))if(!fi(n)&&n.removed?.includes(i))Iu("Ignoring remove event for non-existent because it was part of parent event's removed",i,n);else throw Eu(`MappedThread{${this.name}} toRemove contained log that doesn't exist`,i,{thread:this,event:n,mapResult:r})}}ln(`MappedThread{${this.nameAndSizeUntracked}} parentUpdate => deps?`,Yr(this._applogs)),this.notifySubscribers(r)}get readOnly(){return!1}},{WARN:EO,LOG:SO,DEBUG:PO,VERBOSE:Ao,ERROR:ow}=xe.setup(xe.INFO),$O=Xo("rollingFilter",function(t,n,r={}){let i=sw(n),s=Su(i),o=Pe.array(Ve(function(){return s(t.applogs)}),{deep:!1,name:`${t.name} | ${r.name||`rollingFilter.array{${ci(i)}}`}`}),u=b=>{let M;return fi(b)?M={init:s(b.init)}:M={added:s(b.added),removed:b.removed},Ao(`rollingFilter{${t.nameAndSizeUntracked} | ${r.name?` '${r.name}'}`:""} parentUpdate`,i,b,"=>",M),M},f=new Yc(`${t.name} | ${r.name||`rollingFilter{${ci(i)}}`}`,t,[...t.filters,...r.extraFilterName?[r.extraFilterName]:[]],o,u),c=ca(()=>Nn(n),b=>{Ao(`rollingFilter<${t.nameAndSizeUntracked}>${r.name?` '${r.name}'`:""} patternUpdate`,i,"=>",b),i=b,s=Su(i),f.triggerRemap()}),g=ir(o,()=>{Ao(`rollingFilter<${Ve(()=>t.name)}>${r.name?` '${r.name}'`:""} unobserve`,i),c(),g()});return f},{equals:_c,argsDebugName:(e,t,n)=>vc({caller:"rollingFilter",thread:e,pattern:t,args:n})}),RO=Xo("rollingMapper",function(t,n,r={}){let i=Ve(()=>n.call(null,{init:t.applogs},t));if(!fi(i))throw ow("Initial run must return init event");let s=i.init;return new Yc(`${t.name} | ${r.name||"rollingMapper"}`,t,[...t.filters,...r.extraFilterName?[r.extraFilterName]:[]],s,n)},{equals:_c,argsDebugName:(e,t,n)=>vc({caller:"rollingMapper",thread:e,args:n})}),NO=Xo("rollingAcc",function(t,n,r,i={}){let s=gt(r);return s({init:t.applogs},n),t.subscribe(o=>{s(o,n)}),n},{argsDebugName:(e,t,n,r)=>`rollingAcc{${e.nameAndSizeUntracked}${r?.name?` | ${r?.name}`:""}}`}),sw=function(t){let n=Ve(function(){return Object.fromEntries(Object.entries(Nn(t)).map(([i,s])=>[Nn(i),Nn(s)]))});if(!Object.entries(n).length)throw new Error("Pattern is empty");return n};function Su(e){return function(n){return n.filter(function(i){for(let s of Object.keys(e)){let o=e[s];if(o===void 0)continue;let u=i[s.startsWith("!")?s.slice(1):s];if(!Hc(s,o,u))return!1}return!0})}}var{WARN:CO,LOG:xO,DEBUG:UO,VERBOSE:jO,ERROR:DO}=xe.setup(xe.INFO);var{WARN:MO,LOG:LO,DEBUG:BO,VERBOSE:FO,ERROR:kO}=xe.setup(xe.INFO);function aw(e){return typeof e=="string"?e:JSON.stringify(e)}function uw(e,t,n,r){let i=aw(e),s=r??Ci({content:i,parentID:t,after:n,ts:xi()},7);return{en:s,applogs:[{en:s,at:"block/content",vl:i}]}}function cw(e,t,n,r){let i=r??Ci({blockID:e,childOf:t,after:n,ts:xi()},7);return{en:i,applogs:[{en:i,at:"relation/block",vl:e},{en:i,at:"relation/childOf",vl:t},{en:i,at:"relation/after",vl:n}]}}function ds(e,t,n){let r=[],{en:i,applogs:s}=uw(e.content,t,n);if(r.push(...s),t){let{applogs:u}=cw(i,t,n??null);r.push(...u)}let o=null;if(e.children)for(let u of e.children){let f=ds(u,i,o);r.push(...f.applogs),o=f.blockID}return{blockID:i,applogs:r}}function tI(e,t){let n=[],r=[],i=null;for(let s of e){let o=ds(s,t,i);n.push(...o.applogs),r.push(o.blockID),i=o.blockID}return{rootIDs:r,applogs:n}}function nI(e){return ds(e)}export{uw as a,cw as b,ds as c,tI as d,nI as e};
|
|
62
62
|
/*! Bundled license information:
|
|
63
63
|
|
|
64
64
|
lodash-es/lodash.js:
|
|
@@ -75,4 +75,4 @@ lodash-es/lodash.js:
|
|
|
75
75
|
@noble/hashes/utils.js:
|
|
76
76
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
77
77
|
*/
|
|
78
|
-
//# sourceMappingURL=chunk-
|
|
78
|
+
//# sourceMappingURL=chunk-WMNPGCQZ.min.js.map
|