An ATProto Lexicon validator for Gleam.

fix: handle JavaScript Array/Object types in dynamic_to_json

When running in JavaScript, dynamic.classify returns 'Array' and
'Object' for native JS types, not 'List' and 'Dict'. This makes
the JSON conversion work correctly when called from JavaScript.

Changed files
+6 -6
dist
src
honk
+4 -4
dist/honk.min.js
··· 1 - var honk=(()=>{var sr=Object.defineProperty;var Zs=Object.getOwnPropertyDescriptor;var Ws=Object.getOwnPropertyNames;var Hs=Object.prototype.hasOwnProperty;var Ys=(e,t)=>{for(var n in t)sr(e,n,{get:t[n],enumerable:!0})},Ks=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ws(t))!Hs.call(e,i)&&i!==n&&sr(e,i,{get:()=>t[i],enumerable:!(r=Zs(t,i))||r.enumerable});return e};var Xs=e=>Ks(sr({},"__esModule",{value:!0}),e);var ru={};Ys(ru,{build_validation_context:()=>Rs,dynamic_to_json:()=>Js,is_valid_nsid:()=>eu,parse_json_string:()=>Gs,parse_json_strings:()=>nu,toList:()=>h,validate:()=>Xa,validate_record:()=>Qa,validate_record_with_context:()=>Ps,validate_string_format:()=>tu});var v=class{withFields(t){let n=Object.keys(this).map(r=>r in t?t[r]:this[r]);return new this.constructor(...n)}},Q=class{static fromArray(t,n){let r=n||new y;for(let i=t.length-1;i>=0;--i)r=new Te(t[i],r);return r}[Symbol.iterator](){return new or(this)}toArray(){return[...this]}atLeastLength(t){let n=this;for(;t-- >0&&n;)n=n.tail;return n!==void 0}hasLength(t){let n=this;for(;t-- >0&&n;)n=n.tail;return t===-1&&n instanceof y}countLength(){let t=this,n=0;for(;t;)t=t.tail,n++;return n-1}};function F(e,t){return new Te(e,t)}function h(e,t){return Q.fromArray(e,t)}var or=class{#e;constructor(t){this.#e=t}next(){if(this.#e instanceof y)return{done:!0};{let{head:t,tail:n}=this.#e;return this.#e=n,{value:t,done:!1}}}},y=class extends Q{};var Te=class extends Q{constructor(t,n){super(),this.head=t,this.tail=n}};var fi=e=>e instanceof Te,ci=e=>e.head,di=e=>e.tail,X=class{bitSize;byteSize;bitOffset;rawBuffer;constructor(t,n,r){if(!(t instanceof Uint8Array))throw globalThis.Error("BitArray can only be constructed from a Uint8Array");if(this.bitSize=n??t.length*8,this.byteSize=Math.trunc((this.bitSize+7)/8),this.bitOffset=r??0,this.bitSize<0)throw globalThis.Error(`BitArray bit size is invalid: ${this.bitSize}`);if(this.bitOffset<0||this.bitOffset>7)throw globalThis.Error(`BitArray bit offset is invalid: ${this.bitOffset}`);if(t.length!==Math.trunc((this.bitOffset+this.bitSize+7)/8))throw globalThis.Error("BitArray buffer length is invalid");this.rawBuffer=t}byteAt(t){if(!(t<0||t>=this.byteSize))return tt(this.rawBuffer,this.bitOffset,t)}equals(t){if(this.bitSize!==t.bitSize)return!1;let n=Math.trunc(this.bitSize/8);if(this.bitOffset===0&&t.bitOffset===0){for(let i=0;i<n;i++)if(this.rawBuffer[i]!==t.rawBuffer[i])return!1;let r=this.bitSize%8;if(r){let i=8-r;if(this.rawBuffer[n]>>i!==t.rawBuffer[n]>>i)return!1}}else{for(let i=0;i<n;i++){let s=tt(this.rawBuffer,this.bitOffset,i),l=tt(t.rawBuffer,t.bitOffset,i);if(s!==l)return!1}let r=this.bitSize%8;if(r){let i=tt(this.rawBuffer,this.bitOffset,n),s=tt(t.rawBuffer,t.bitOffset,n),l=8-r;if(i>>l!==s>>l)return!1}}return!0}get buffer(){if(li("buffer","Use BitArray.byteAt() or BitArray.rawBuffer instead"),this.bitOffset!==0||this.bitSize%8!==0)throw new globalThis.Error("BitArray.buffer does not support unaligned bit arrays");return this.rawBuffer}get length(){if(li("length","Use BitArray.bitSize or BitArray.byteSize instead"),this.bitOffset!==0||this.bitSize%8!==0)throw new globalThis.Error("BitArray.length does not support unaligned bit arrays");return this.rawBuffer.length}};function tt(e,t,n){if(t===0)return e[n]??0;{let r=e[n]<<t&255,i=e[n+1]>>8-t;return r|i}}var mn=class{constructor(t){this.value=t}},oi={};function li(e,t){oi[e]||(console.warn(`Deprecated BitArray.${e} property used in JavaScript FFI code. ${t}.`),oi[e]=!0)}function oe(e,t,n){if(n??=e.bitSize,Qs(e,t,n),t===n)return new X(new Uint8Array);if(t===0&&n===e.bitSize)return e;t+=e.bitOffset,n+=e.bitOffset;let r=Math.trunc(t/8),s=Math.trunc((n+7)/8)-r,l;return r===0&&s===e.rawBuffer.byteLength?l=e.rawBuffer:l=new Uint8Array(e.rawBuffer.buffer,e.rawBuffer.byteOffset+r,s),new X(l,n-t,t%8)}function hn(e){if(e.length===0)return new X(new Uint8Array);if(e.length===1){let l=e[0];return l instanceof X?l:l instanceof Uint8Array?new X(l):new X(new Uint8Array(e))}let t=0,n=!0;for(let l of e)l instanceof X?(t+=l.bitSize,n=!1):l instanceof Uint8Array?(t+=l.byteLength*8,n=!1):t+=8;if(n)return new X(new Uint8Array(e));let r=new Uint8Array(Math.trunc((t+7)/8)),i=0;for(let l of e){let a=i%8===0;if(l instanceof X)if(a&&l.bitOffset===0){r.set(l.rawBuffer,i/8),i+=l.bitSize;let f=l.bitSize%8;if(f!==0){let c=Math.trunc(i/8);r[c]>>=8-f,r[c]<<=8-f}}else s(l.rawBuffer,l.bitSize,l.bitOffset);else l instanceof Uint8Array?a?(r.set(l,i/8),i+=l.byteLength*8):s(l,l.byteLength*8,0):a?(r[i/8]=l,i+=8):s(new Uint8Array([l]),8,0)}function s(l,a,f){if(a===0)return;let c=Math.trunc(a+7/8),$=i%8,_=8-$,x=Math.trunc(i/8);for(let g=0;g<c;g++){let S=tt(l,f,g);a<8&&(S>>=8-a,S<<=8-a),r[x]|=S>>$;let E=a-Math.max(0,a-_);if(a-=E,i+=E,a===0)break;r[++x]=S<<_,E=a-Math.max(0,a-$),a-=E,i+=E}}return new X(r,t)}function Qs(e,t,n){if(t<0||t>e.bitSize||n<t||n>e.bitSize){let r=`Invalid bit array slice: start = ${t}, end = ${n}, bit size = ${e.bitSize}`;throw new globalThis.Error(r)}}var ai;function pi(e){return ai??=new TextEncoder,ai.encode(e)}var nt=class e extends v{static isResult(t){return t instanceof e}},o=class extends nt{constructor(t){super(),this[0]=t}isOk(){return!0}},$i=e=>new o(e);var u=class extends nt{constructor(t){super(),this[0]=t}isOk(){return!1}},_i=e=>new u(e);function D(e,t){let n=[e,t];for(;n.length;){let r=n.pop(),i=n.pop();if(r===i)continue;if(!ui(r)||!ui(i)||!lo(r,i)||to(r,i)||no(r,i)||ro(r,i)||io(r,i)||so(r,i)||oo(r,i))return!1;let l=Object.getPrototypeOf(r);if(l!==null&&typeof l.equals=="function")try{if(r.equals(i))continue;return!1}catch{}let[a,f]=eo(r),c=a(r),$=a(i);if(c.length!==$.length)return!1;for(let _ of c)n.push(f(r,_),f(i,_))}return!0}function eo(e){if(e instanceof Map)return[t=>t.keys(),(t,n)=>t.get(n)];{let t=e instanceof globalThis.Error?["message"]:[];return[n=>[...t,...Object.keys(n)],(n,r)=>n[r]]}}function to(e,t){return e instanceof Date&&(e>t||e<t)}function no(e,t){return!(e instanceof X)&&e.buffer instanceof ArrayBuffer&&e.BYTES_PER_ELEMENT&&!(e.byteLength===t.byteLength&&e.every((n,r)=>n===t[r]))}function ro(e,t){return Array.isArray(e)&&e.length!==t.length}function io(e,t){return e instanceof Map&&e.size!==t.size}function so(e,t){return e instanceof Set&&(e.size!=t.size||[...e].some(n=>!t.has(n)))}function oo(e,t){return e instanceof RegExp&&(e.source!==t.source||e.flags!==t.flags)}function ui(e){return typeof e=="object"&&e!==null}function lo(e,t){return typeof e!="object"&&typeof t!="object"&&(!e||!t)||[Promise,WeakSet,WeakMap,Function].some(r=>e instanceof r)?!1:e.constructor===t.constructor}function It(e,t){return t===0?0:e%t}function Nt(e,t){return Math.trunc(wn(e,t))}function wn(e,t){return t===0?0:e/t}var d=class extends v{constructor(t){super(),this[0]=t}};var A=class extends v{};var mi=new WeakMap,lr=new DataView(new ArrayBuffer(8)),ar=0;function ur(e){let t=mi.get(e);if(t!==void 0)return t;let n=ar++;return ar===2147483647&&(ar=0),mi.set(e,n),n}function fr(e,t){return e^t+2654435769+(e<<6)+(e>>2)|0}function dr(e){let t=0,n=e.length;for(let r=0;r<n;r++)t=Math.imul(31,t)+e.charCodeAt(r)|0;return t}function wi(e){lr.setFloat64(0,e);let t=lr.getInt32(0),n=lr.getInt32(4);return Math.imul(73244475,t>>16^t)^n}function ao(e){return dr(e.toString())}function uo(e){let t=Object.getPrototypeOf(e);if(t!==null&&typeof t.hashCode=="function")try{let r=e.hashCode(e);if(typeof r=="number")return r}catch{}if(e instanceof Promise||e instanceof WeakSet||e instanceof WeakMap)return ur(e);if(e instanceof Date)return wi(e.getTime());let n=0;if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),Array.isArray(e)||e instanceof Uint8Array)for(let r=0;r<e.length;r++)n=Math.imul(31,n)+pe(e[r])|0;else if(e instanceof Set)e.forEach(r=>{n=n+pe(r)|0});else if(e instanceof Map)e.forEach((r,i)=>{n=n+fr(pe(r),pe(i))|0});else{let r=Object.keys(e);for(let i=0;i<r.length;i++){let s=r[i],l=e[s];n=n+fr(pe(l),dr(s))|0}}return n}function pe(e){if(e===null)return 1108378658;if(e===void 0)return 1108378659;if(e===!0)return 1108378657;if(e===!1)return 1108378656;switch(typeof e){case"number":return wi(e);case"string":return dr(e);case"bigint":return ao(e);case"object":return uo(e);case"symbol":return ur(e);case"function":return ur(e);default:return 0}}var Ee=5,pr=Math.pow(2,Ee),fo=pr-1,co=pr/2,po=pr/4,ne=0,Se=1,le=2,He=3,$r={type:le,bitmap:0,array:[]};function qt(e,t){return e>>>t&fo}function gn(e,t){return 1<<qt(e,t)}function $o(e){return e-=e>>1&1431655765,e=(e&858993459)+(e>>2&858993459),e=e+(e>>4)&252645135,e+=e>>8,e+=e>>16,e&127}function _r(e,t){return $o(e&t-1)}function $e(e,t,n){let r=e.length,i=new Array(r);for(let s=0;s<r;++s)i[s]=e[s];return i[t]=n,i}function _o(e,t,n){let r=e.length,i=new Array(r+1),s=0,l=0;for(;s<t;)i[l++]=e[s++];for(i[l++]=n;s<r;)i[l++]=e[s++];return i}function cr(e,t){let n=e.length,r=new Array(n-1),i=0,s=0;for(;i<t;)r[s++]=e[i++];for(++i;i<n;)r[s++]=e[i++];return r}function xi(e,t,n,r,i,s){let l=pe(t);if(l===r)return{type:He,hash:l,array:[{type:ne,k:t,v:n},{type:ne,k:i,v:s}]};let a={val:!1};return Ut(mr($r,e,l,t,n,a),e,r,i,s,a)}function Ut(e,t,n,r,i,s){switch(e.type){case Se:return mo(e,t,n,r,i,s);case le:return mr(e,t,n,r,i,s);case He:return ho(e,t,n,r,i,s)}}function mo(e,t,n,r,i,s){let l=qt(n,t),a=e.array[l];if(a===void 0)return s.val=!0,{type:Se,size:e.size+1,array:$e(e.array,l,{type:ne,k:r,v:i})};if(a.type===ne)return D(r,a.k)?i===a.v?e:{type:Se,size:e.size,array:$e(e.array,l,{type:ne,k:r,v:i})}:(s.val=!0,{type:Se,size:e.size,array:$e(e.array,l,xi(t+Ee,a.k,a.v,n,r,i))});let f=Ut(a,t+Ee,n,r,i,s);return f===a?e:{type:Se,size:e.size,array:$e(e.array,l,f)}}function mr(e,t,n,r,i,s){let l=gn(n,t),a=_r(e.bitmap,l);if((e.bitmap&l)!==0){let f=e.array[a];if(f.type!==ne){let $=Ut(f,t+Ee,n,r,i,s);return $===f?e:{type:le,bitmap:e.bitmap,array:$e(e.array,a,$)}}let c=f.k;return D(r,c)?i===f.v?e:{type:le,bitmap:e.bitmap,array:$e(e.array,a,{type:ne,k:r,v:i})}:(s.val=!0,{type:le,bitmap:e.bitmap,array:$e(e.array,a,xi(t+Ee,c,f.v,n,r,i))})}else{let f=e.array.length;if(f>=co){let c=new Array(32),$=qt(n,t);c[$]=mr($r,t+Ee,n,r,i,s);let _=0,x=e.bitmap;for(let g=0;g<32;g++){if((x&1)!==0){let S=e.array[_++];c[g]=S}x=x>>>1}return{type:Se,size:f+1,array:c}}else{let c=_o(e.array,a,{type:ne,k:r,v:i});return s.val=!0,{type:le,bitmap:e.bitmap|l,array:c}}}}function ho(e,t,n,r,i,s){if(n===e.hash){let l=hr(e,r);if(l!==-1)return e.array[l].v===i?e:{type:He,hash:n,array:$e(e.array,l,{type:ne,k:r,v:i})};let a=e.array.length;return s.val=!0,{type:He,hash:n,array:$e(e.array,a,{type:ne,k:r,v:i})}}return Ut({type:le,bitmap:gn(e.hash,t),array:[e]},t,n,r,i,s)}function hr(e,t){let n=e.array.length;for(let r=0;r<n;r++)if(D(t,e.array[r].k))return r;return-1}function yn(e,t,n,r){switch(e.type){case Se:return wo(e,t,n,r);case le:return xo(e,t,n,r);case He:return yo(e,r)}}function wo(e,t,n,r){let i=qt(n,t),s=e.array[i];if(s!==void 0){if(s.type!==ne)return yn(s,t+Ee,n,r);if(D(r,s.k))return s}}function xo(e,t,n,r){let i=gn(n,t);if((e.bitmap&i)===0)return;let s=_r(e.bitmap,i),l=e.array[s];if(l.type!==ne)return yn(l,t+Ee,n,r);if(D(r,l.k))return l}function yo(e,t){let n=hr(e,t);if(!(n<0))return e.array[n]}function wr(e,t,n,r){switch(e.type){case Se:return go(e,t,n,r);case le:return bo(e,t,n,r);case He:return vo(e,r)}}function go(e,t,n,r){let i=qt(n,t),s=e.array[i];if(s===void 0)return e;let l;if(s.type===ne){if(!D(s.k,r))return e}else if(l=wr(s,t+Ee,n,r),l===s)return e;if(l===void 0){if(e.size<=po){let a=e.array,f=new Array(e.size-1),c=0,$=0,_=0;for(;c<i;){let x=a[c];x!==void 0&&(f[$]=x,_|=1<<c,++$),++c}for(++c;c<a.length;){let x=a[c];x!==void 0&&(f[$]=x,_|=1<<c,++$),++c}return{type:le,bitmap:_,array:f}}return{type:Se,size:e.size-1,array:$e(e.array,i,l)}}return{type:Se,size:e.size,array:$e(e.array,i,l)}}function bo(e,t,n,r){let i=gn(n,t);if((e.bitmap&i)===0)return e;let s=_r(e.bitmap,i),l=e.array[s];if(l.type!==ne){let a=wr(l,t+Ee,n,r);return a===l?e:a!==void 0?{type:le,bitmap:e.bitmap,array:$e(e.array,s,a)}:e.bitmap===i?void 0:{type:le,bitmap:e.bitmap^i,array:cr(e.array,s)}}return D(r,l.k)?e.bitmap===i?void 0:{type:le,bitmap:e.bitmap^i,array:cr(e.array,s)}:e}function vo(e,t){let n=hr(e,t);if(n<0)return e;if(e.array.length!==1)return{type:He,hash:e.hash,array:cr(e.array,n)}}function yi(e,t){if(e===void 0)return;let n=e.array,r=n.length;for(let i=0;i<r;i++){let s=n[i];if(s!==void 0){if(s.type===ne){t(s.v,s.k);continue}yi(s,t)}}}var ye=class e{static fromObject(t){let n=Object.keys(t),r=e.new();for(let i=0;i<n.length;i++){let s=n[i];r=r.set(s,t[s])}return r}static fromMap(t){let n=e.new();return t.forEach((r,i)=>{n=n.set(i,r)}),n}static new(){return new e(void 0,0)}constructor(t,n){this.root=t,this.size=n}get(t,n){if(this.root===void 0)return n;let r=yn(this.root,0,pe(t),t);return r===void 0?n:r.v}set(t,n){let r={val:!1},i=this.root===void 0?$r:this.root,s=Ut(i,0,pe(t),t,n,r);return s===this.root?this:new e(s,r.val?this.size+1:this.size)}delete(t){if(this.root===void 0)return this;let n=wr(this.root,0,pe(t),t);return n===this.root?this:n===void 0?e.new():new e(n,this.size-1)}has(t){return this.root===void 0?!1:yn(this.root,0,pe(t),t)!==void 0}entries(){if(this.root===void 0)return[];let t=[];return this.forEach((n,r)=>t.push([r,n])),t}forEach(t){yi(this.root,t)}hashCode(){let t=0;return this.forEach((n,r)=>{t=t+fr(pe(n),pe(r))|0}),t}equals(t){if(!(t instanceof e)||this.size!==t.size)return!1;try{return this.forEach((n,r)=>{if(!D(t.get(r,!n),n))throw hi}),!0}catch(n){if(n===hi)return!1;throw n}}},hi=Symbol();function xr(e){return jn(e)===0}function _e(e,t,n){return gi(t,n,e)}function jo(e,t){for(;;){let n=e,r=t;if(n instanceof y)return r;{let i=n.tail,s=n.head[0],l=n.head[1];e=i,t=_e(r,s,l)}}}function bn(e){return jo(e,ee())}function ko(e,t){for(;;){let n=e,r=t;if(n instanceof y)return r;{let i=n.head;e=n.tail,t=F(i,r)}}}function So(e,t){for(;;){let n=e,r=t;if(n instanceof y)return ko(r,h([]));{let i=n.tail,s=n.head[0];e=i,t=F(s,r)}}}function vn(e){return So(Ft(e),h([]))}function Eo(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return i;{let l=r.tail,a=r.head[0],f=r.head[1];e=l,t=s(i,a,f),n=s}}}function me(e,t,n){return Eo(Ft(e),t,n)}function zo(e,t){for(;;){let n=e,r=t;if(n instanceof y)return r;e=n.tail,t=r+1}}function he(e){return zo(e,0)}function Ao(e,t){for(;;){let n=e,r=t;if(n instanceof y)return r;{let i=n.head;e=n.tail,t=F(i,r)}}}function be(e){return Ao(e,h([]))}function Ye(e){return D(e,h([]))}function rt(e,t){for(;;){let n=e,r=t;if(n instanceof y)return!1;{let i=n.head;if(D(i,r))return!0;e=n.tail,t=r}}}function Oo(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return be(s);{let l=r.head,a=r.tail,f;i(l)?f=F(l,s):f=s;let $=f;e=a,t=i,n=$}}}function kn(e,t){return Oo(e,t,h([]))}function Co(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return be(s);{let l=r.head,a=r.tail,f,c=i(l);if(c instanceof o){let _=c[0];f=F(_,s)}else f=s;let $=f;e=a,t=i,n=$}}}function re(e,t){return Co(e,t,h([]))}function Bo(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return be(s);{let l=r.head;e=r.tail,t=i,n=F(i(l),s)}}}function Ne(e,t){return Bo(e,t,h([]))}function Mo(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return new o(be(s));{let l=r.head,a=r.tail,f=i(l);if(f instanceof o){let c=f[0];e=a,t=i,n=F(c,s)}else return f}}}function it(e,t){return Mo(e,t,h([]))}function Do(e,t){for(;;){let n=e,r=t;if(n instanceof y)return r;{let i=n.head;e=n.tail,t=F(i,r)}}}function vi(e,t){return Do(be(e),t)}function Sn(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return i;{let l=r.head;e=r.tail,t=s(i,l),n=s}}}function Lo(e,t,n,r){for(;;){let i=e,s=t,l=n,a=r;if(i instanceof y)return s;{let f=i.head;e=i.tail,t=l(s,f,a),n=l,r=a+1}}}function st(e,t,n){return Lo(e,t,n,0)}function K(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return new o(i);{let l=r.head,a=r.tail,f=s(i,l);if(f instanceof o){let c=f[0];e=a,t=c,n=s}else return f}}}function ji(e,t){for(;;){let n=e,r=t;if(n instanceof y)return new u(void 0);{let i=n.head,s=n.tail;if(r(i))return new o(i);e=s,t=r}}}function En(e,t){for(;;){let n=e,r=t;if(n instanceof y)return!1;{let i=n.head,s=n.tail,l=r(i);if(l)return l;e=s,t=r}}}function ki(e){for(;;){let t=e;if(t instanceof y)return new u(void 0);{let n=t.tail;if(n instanceof y){let r=t.head;return new o(r)}else e=n}}}var De=class extends v{constructor(t,n,r){super(),this.expected=t,this.found=n,this.path=r}};var we=class extends v{constructor(t){super(),this.function=t}};function j(e,t){let n=t.function(e),r,i;return r=n[0],i=n[1],i instanceof y?new o(r):new u(i)}function Io(e){return[e,h([])]}function No(e,t){return new we(n=>{let r=e.function(n),i,s;return i=r[0],s=r[1],[t(i),s]})}function qo(e,t,n){for(;;){let r=e,i=t,s=n;if(s instanceof y)return i;{let l=s.head,a=s.tail,f=l.function(r),c,$;if(c=f,$=f[1],$ instanceof y)return c;e=r,t=i,n=a}}}function Uo(e,t){return new we(n=>{let r=e.function(n),i,s;return i=r,s=r[1],s instanceof y?i:qo(n,i,t)})}var ue=new we(Io);function zi(e,t){return h([new De(e,ge(t),h([]))])}function vr(e,t,n){let r=n(e);return r instanceof o?[r[0],h([])]:[r[0],h([new De(t,ge(e),h([]))])]}function Fo(e){return D(!0,e)?[!0,h([])]:D(!1,e)?[!1,h([])]:[!1,zi("Bool",e)]}function Vo(e){return vr(e,"Int",Di)}function Ro(e){return vr(e,"Float",Mi)}var zn=new we(Fo),qe=new we(Vo),Ai=new we(Ro);function Po(e){return vr(e,"String",Li)}var L=new we(Po);function Jo(e,t,n,r,i){let s=r(t),l=s[1];if(l instanceof y){let a=s[0],f=i(n),c=f[1];if(c instanceof y){let $=f[0];return[_e(e[0],a,$),e[1]]}else{let $=c;return ot([ee(),$],h(["values"]))}}else{let a=l;return ot([ee(),a],h(["keys"]))}}function Pt(e,t){return new we(n=>{let r=Bi(n);if(r instanceof o){let i=r[0];return me(i,[ee(),h([])],(s,l,a)=>s[1]instanceof y?Jo(s,l,a,e.function,t.function):s)}else return[ee(),zi("Dict",n)]})}function Jt(e){return new we(t=>Ci(t,e.function,(n,r)=>ot(n,h([r])),0,h([])))}function ot(e,t){let n=Uo(L,h([No(qe,B)])),r=Ne(t,s=>{let l=s,a=j(l,n);return a instanceof o?a[0]:"<"+ge(l)+">"}),i=Ne(e[1],s=>new De(s.expected,s.found,vi(r,s.path)));return[e[0],i]}function Go(e,t,n,r,i){for(;;){let s=e,l=t,a=n,f=r,c=i;if(s instanceof y){let _=a(f);return ot(_,be(l))}else{let $=s.head,_=s.tail,x=Oi(f,$);if(x instanceof o){let g=x[0];if(g instanceof d){let S=g[0];e=_,t=F($,l),n=a,r=S,i=c}else return c(f,F($,l))}else{let g=x[0],S=a(f),E;E=S[0];let I=[E,h([new De(g,ge(f),h([]))])];return ot(I,be(l))}}}}function lt(e,t){return new we(n=>Go(e,h([]),t.function,n,(r,i)=>{let s=t.function(r),l;l=s[0];let a=[l,h([new De("Field","Nothing",h([]))])];return ot(a,be(i))}))}var kr=void 0,Ti={};function Y(e){return e}function Sr(e){return/^[-+]?(\d+)$/.test(e)?new o(parseInt(e)):new u(kr)}function B(e){return e.toString()}function G(e){if(e==="")return 0;let t=Er(e);if(t){let n=0;for(let r of t)n++;return n}else return e.match(/./gsu).length}function Gt(e){let t=Er(e);return t?Q.fromArray(Array.from(t).map(n=>n.segment)):Q.fromArray(e.match(/./gsu))}var Ii;function Er(e){if(globalThis.Intl&&Intl.Segmenter)return Ii||=new Intl.Segmenter,Ii.segment(e)[Symbol.iterator]()}function zr(e,t){return Q.fromArray(e.split(t))}function Ni(e,t,n){return e.slice(t,t+n)}function An(e,t,n){if(n<=0||t>=e.length)return"";let r=Er(e);if(r){for(;t-- >0;)r.next();let i="";for(;n-- >0;){let s=r.next().value;if(s===void 0)break;i+=s.segment}return i}else return e.match(/./gsu).slice(t,t+n).join("")}function Ue(e,t){return e.indexOf(t)>=0}function Z(e,t){return e.startsWith(t)}function Oe(e,t){return e.endsWith(t)}var qi=[" "," ",` 2 - `,"\v","\f","\r","\x85","\u2028","\u2029"].join(""),Iu=new RegExp(`^[${qi}]*`),Nu=new RegExp(`[${qi}]*$`);function On(e){return hn([pi(e)])}function Cn(e){return e.byteSize}function ee(){return ye.new()}function jn(e){return e.size}function Ft(e){return Q.fromArray(e.entries())}function ae(e,t){let n=e.get(t,Ti);return n===Ti?new u(kr):new o(n)}function gi(e,t,n){return n.set(e,t)}function Ui(e){try{let t=atob(e),n=t.length,r=new Uint8Array(n);for(let i=0;i<n;i++)r[i]=t.charCodeAt(i);return new o(new X(r))}catch{return new u(kr)}}function ge(e){if(typeof e=="string")return"String";if(typeof e=="boolean")return"Bool";if(e instanceof nt)return"Result";if(e instanceof Q)return"List";if(e instanceof X)return"BitArray";if(e instanceof ye)return"Dict";if(Number.isInteger(e))return"Int";if(Array.isArray(e))return"Array";if(typeof e=="number")return"Float";if(e===null)return"Nil";if(e===void 0)return"Nil";{let t=typeof e;return t.charAt(0).toUpperCase()+t.slice(1)}}function Zt(e){return new TextEncoder().encode(e).length}function Fi(e){return new jr().inspect(e)}function Vi(e){let t=e.toString().replace("+","");if(t.indexOf(".")>=0)return t;{let n=t.indexOf("e");return n>=0?t.slice(0,n)+".0"+t.slice(n):t+".0"}}var jr=class{#e=new Set;inspect(t){let n=typeof t;if(t===!0)return"True";if(t===!1)return"False";if(t===null)return"//js(null)";if(t===void 0)return"Nil";if(n==="string")return this.#s(t);if(n==="bigint"||Number.isInteger(t))return t.toString();if(n==="number")return Vi(t);if(t instanceof mn)return this.#o(t);if(t instanceof X)return this.#l(t);if(t instanceof RegExp)return`//js(${t})`;if(t instanceof Date)return`//js(Date("${t.toISOString()}"))`;if(t instanceof globalThis.Error)return`//js(${t.toString()})`;if(t instanceof Function){let i=[];for(let s of Array(t.length).keys())i.push(String.fromCharCode(s+97));return`//fn(${i.join(", ")}) { ... }`}if(this.#e.size===this.#e.add(t).size)return"//js(circular reference)";let r;if(Array.isArray(t))r=`#(${t.map(i=>this.inspect(i)).join(", ")})`;else if(t instanceof Q)r=this.#i(t);else if(t instanceof v)r=this.#r(t);else if(t instanceof ye)r=this.#n(t);else{if(t instanceof Set)return`//js(Set(${[...t].map(i=>this.inspect(i)).join(", ")}))`;r=this.#t(t)}return this.#e.delete(t),r}#t(t){let n=Object.getPrototypeOf(t)?.constructor?.name||"Object",r=[];for(let l of Object.keys(t))r.push(`${this.inspect(l)}: ${this.inspect(t[l])}`);let i=r.length?" "+r.join(", ")+" ":"";return`//js(${n==="Object"?"":n+" "}{${i}})`}#n(t){let n="dict.from_list([",r=!0;return t.forEach((i,s)=>{r||(n=n+", "),n=n+"#("+this.inspect(s)+", "+this.inspect(i)+")",r=!1}),n+"])"}#r(t){let n=Object.keys(t).map(r=>{let i=this.inspect(t[r]);return isNaN(parseInt(r))?`${r}: ${i}`:i}).join(", ");return n?`${t.constructor.name}(${n})`:t.constructor.name}#i(t){if(t instanceof y)return"[]";let n='charlist.from_string("',r="[",i=t;for(;i instanceof Te;){let s=i.head;i=i.tail,r!=="["&&(r+=", "),r+=this.inspect(s),n&&(Number.isInteger(s)&&s>=32&&s<=126?n+=String.fromCharCode(s):n=null)}return n?n+'")':r+"]"}#s(t){let n='"';for(let r=0;r<t.length;r++){let i=t[r];switch(i){case` 3 - `:n+="\\n";break;case"\r":n+="\\r";break;case" ":n+="\\t";break;case"\f":n+="\\f";break;case"\\":n+="\\\\";break;case'"':n+='\\"';break;default:i<" "||i>"~"&&i<"\xA0"?n+="\\u{"+i.charCodeAt(0).toString(16).toUpperCase().padStart(4,"0")+"}":n+=i}}return n+='"',n}#o(t){return`//utfcodepoint(${String.fromCodePoint(t.value)})`}#l(t){if(t.bitSize===0)return"<<>>";let n="<<";for(let r=0;r<t.byteSize-1;r++)n+=t.byteAt(r).toString(),n+=", ";if(t.byteSize*8===t.bitSize)n+=t.byteAt(t.byteSize-1).toString();else{let r=t.bitSize%8;n+=t.byteAt(t.byteSize-1)>>8-r,n+=`:size(${r})`}return n+=">>",n}};function Oi(e,t){if(e instanceof ye||e instanceof WeakMap||e instanceof Map){let r={},i=e.get(t,r);return i===r?new o(new A):new o(new d(i))}let n=Number.isInteger(t);if(n&&t>=0&&t<8&&e instanceof Q){let r=0;for(let i of e){if(r===t)return new o(new d(i));r++}return new u("Indexable")}return n&&Array.isArray(e)||e&&typeof e=="object"||e&&Object.getPrototypeOf(e)===Object.prototype?t in e?new o(new d(e[t])):new o(new A):new u(n?"Indexable":"Dict")}function Ci(e,t,n,r,i){if(!(e instanceof Q||Array.isArray(e))){let l=new De("List",ge(e),i);return[i,Q.fromArray([l])]}let s=[];for(let l of e){let a=t(l),[f,c]=a;if(c instanceof Te){let[$,_]=n(a,r.toString());return[i,_]}s.push(f),r++}return[Q.fromArray(s),i]}function Bi(e){if(e instanceof ye)return new o(e);if(e instanceof Map||e instanceof WeakMap)return new o(ye.fromMap(e));if(e==null)return new u("Dict");if(typeof e!="object")return new u("Dict");let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null?new o(ye.fromObject(e)):new u("Dict")}function Mi(e){return typeof e=="number"?new o(e):new u(0)}function Di(e){return Number.isInteger(e)?new o(e):new u(0)}function Li(e){return typeof e=="string"?new o(e):new u("")}function Ce(e){return e===""}function Wt(e,t,n){if(n<=0)return"";if(t<0){let s=G(e)+t;return s<0?"":An(e,s,n)}else return An(e,t,n)}function Ri(e,t){return t<=0?e:Wt(e,0,G(e)-t)}function Or(e,t){return e+t}function Xo(e,t,n){for(;;){let r=e,i=t,s=n,l;r%2===0?l=s:l=s+i;let f=l,c=globalThis.Math.trunc(r/2);if(c<=0)return f;e=c,t=i+i,n=f}}function Pi(e,t){return t<=0?"":Xo(t,e,"")}function Qo(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return s;{let l=r.head;e=r.tail,t=i,n=s+i+l}}}function Fe(e,t){if(e instanceof y)return"";{let n=e.head,r=e.tail;return Qo(r,t,n)}}function fe(e,t){if(t==="")return Gt(e);{let r=e,i=zr(r,t);return Ne(i,Y)}}function Ht(e){let n=Fi(e);return n}function Ve(e,t){if(t<=0)return e;{let r=An(e,0,t),i=Zt(r);return Ni(e,i,Zt(e)-i)}}function Ji(e){let t,n=Cn(On(e))%4;return n===0?t=e:t=Or(e,Pi("=",4-n)),Ui(t)}function Gi(e){return e instanceof o}function Ke(e,t){if(e instanceof o)return e;{let n=e[0];return new u(t(n))}}function p(e,t){if(e instanceof o){let n=e[0];return t(n)}else return e}function Br(e){return JSON.stringify(e)}function Zi(e){return Object.fromEntries(e)}function Wi(e){let t=[];for(;fi(e);)t.push(ci(e)),e=di(e);return t}function Hi(){return null}function Yi(e){try{let t=JSON.parse(e);return $i(t)}catch(t){return _i(tl(t,e))}}function tl(e,t){return nl(e)?Ki():rl(e,t)}function nl(e){return/((unexpected (end|eof))|(end of data)|(unterminated string)|(json( parse error|\.parse)\: expected '(\:|\}|\])'))/i.test(e.message)}function rl(e,t){let n=[il,sl,ll,ol];for(let r of n){let i=r(e,t);if(i)return i}return at("")}function il(e){let n=/unexpected token '(.)', ".+" is not valid JSON/i.exec(e.message);if(!n)return null;let r=Bn(n[1]);return at(r)}function sl(e){let n=/unexpected token (.) in JSON at position (\d+)/i.exec(e.message);if(!n)return null;let r=Bn(n[1]);return at(r)}function ol(e,t){let r=/(unexpected character|expected .*) at line (\d+) column (\d+)/i.exec(e.message);if(!r)return null;let i=Number(r[2]),s=Number(r[3]),l=al(i,s,t),a=Bn(t[l]);return at(a)}function ll(e){let n=/unexpected (identifier|token) "(.)"/i.exec(e.message);if(!n)return null;let r=Bn(n[2]);return at(r)}function Bn(e){return"0x"+e.charCodeAt(0).toString(16).toUpperCase()}function al(e,t,n){if(e===1)return t-1;let r=1,i=0;return n.split("").find((s,l)=>(s===` 4 - `&&(r+=1),r===e?(i=l+t,!0):!1)),i}var Mr=class extends v{},Ki=()=>new Mr;var Dr=class extends v{constructor(t){super(),this[0]=t}},at=e=>new Dr(e);var Lr=class extends v{constructor(t){super(),this[0]=t}};function ul(e,t){return p(Yi(e),n=>{let r=j(n,t);return Ke(r,i=>new Lr(i))})}function Mn(e,t){return ul(e,t)}function je(e){return Br(e)}function Xi(e){return e}function Qi(e){return e}function es(e){return e}function ts(e){return e}function ns(){return Hi()}function rs(e){return Zi(e)}function fl(e){return Wi(e)}function is(e,t){let r=Ne(e,t);return fl(r)}var ft=class extends v{constructor(t){super(),this.collection=t}};var ct=class extends v{constructor(t){super(),this.message=t}};var Ir=class extends v{constructor(t){super(),this.message=t}};function Nr(e){return e instanceof ft?"Lexicon not found for collection: "+e.collection:e instanceof ct?"Invalid lexicon schema: "+e.message:"Data validation failed: "+e.message}function m(e){return new ct(e)}function w(e){return new Ir(e)}function qr(e){return new ft(e)}function ce(e){let t=je(e),n=Mn(t,ue);return Ke(n,r=>"Failed to parse JSON")}function dt(e){return je(e)==="null"}function Re(e){let t=ce(e);if(t instanceof o){let n=t[0];return j(n,L)instanceof o}else return!1}function pt(e){let t=ce(e);if(t instanceof o){let n=t[0];return j(n,qe)instanceof o}else return!1}function $t(e){let t=ce(e);if(t instanceof o){let n=t[0];return j(n,zn)instanceof o}else return!1}function Yt(e){let t=ce(e);if(t instanceof o){let n=t[0];return j(n,Jt(ue))instanceof o}else return!1}function q(e){let t=ce(e);if(t instanceof o){let n=t[0];return j(n,Pt(L,ue))instanceof o}else return!1}function k(e,t){let n=ce(e);if(n instanceof o){let r=n[0],i=j(r,lt(h([t]),L));if(i instanceof o){let s=i[0];return new d(s)}else return new A}else return new A}function M(e,t){let n=ce(e);if(n instanceof o){let r=n[0],i=j(r,lt(h([t]),qe));if(i instanceof o){let s=i[0];return new d(s)}else return new A}else return new A}function Pe(e,t){let n=ce(e);if(n instanceof o){let r=n[0],i=j(r,lt(h([t]),zn));if(i instanceof o){let s=i[0];return new d(s)}else return new A}else return new A}function T(e,t){let n=ce(e);if(n instanceof o){let r=n[0],i=j(r,lt(h([t]),Jt(ue)));if(i instanceof o){let s=i[0];return new d(s)}else return new A}else return new A}function z(e){let t=ce(e);if(t instanceof o){let n=t[0],r=j(n,Pt(L,ue));if(r instanceof o){let i=r[0];return vn(i)}else return h([])}else return h([])}function Ur(e){let t=ce(e);if(t instanceof o){let n=t[0],r=j(n,Jt(ue));if(r instanceof o){let i=r[0];return new d(i)}else return new A}else return new A}function ss(e){return ge(e)==="Nil"}function ke(e){let t=ce(e);if(t instanceof o){let n=t[0],r=j(n,Pt(L,ue));return r instanceof o?r:new u(w("Failed to convert JSON to dictionary"))}else return new u(w("Failed to parse JSON as dynamic"))}function se(e){let t=ge(e);if(t==="Nil")return new o(ns());if(t==="String"){let n=j(e,L);if(n instanceof o){let r=n[0];return new o(Xi(r))}else return new u(w("Failed to decode string"))}else if(t==="Int"){let n=j(e,qe);if(n instanceof o){let r=n[0];return new o(es(r))}else return new u(w("Failed to decode int"))}else if(t==="Float"){let n=j(e,Ai);if(n instanceof o){let r=n[0];return new o(ts(r))}else return new u(w("Failed to decode float"))}else if(t==="Bool"){let n=j(e,zn);if(n instanceof o){let r=n[0];return new o(Qi(r))}else return new u(w("Failed to decode bool"))}else if(t==="List"){let n=j(e,Jt(ue));if(n instanceof o){let r=n[0],i=it(r,se);if(i instanceof o){let s=i[0];return new o(is(s,l=>l))}else return i}else return new u(w("Failed to decode list"))}else if(t==="Dict"){let n=j(e,Pt(L,ue));if(n instanceof o){let r=n[0],i=Ft(r),s=it(i,l=>{let a,f;a=l[0],f=l[1];let c=se(f);if(c instanceof o){let $=c[0];return new o([a,$])}else return c});if(s instanceof o){let l=s[0];return new o(rs(l))}else return s}else return new u(w("Failed to decode dict"))}else{let n=t;return new u(w("Unsupported type for JSON conversion: "+n))}}function C(e,t){let n=ce(e);if(n instanceof o){let r=n[0],i=j(r,lt(h([t]),ue));if(i instanceof o){let s=i[0],l=se(s);if(l instanceof o){let a=l[0];return new d(a)}else return new A}else return new A}else return new A}function Dn(){return ee()}function Xe(e,t){return ae(e,t)instanceof o}function Ln(e,t,n){return me(e,t,n)}var Tn=class extends v{constructor(t,n){super(),this.id=t,this.defs=n}};var _t=class extends v{};var mt=class extends v{};var ht=class extends v{};var wt=class extends v{};var xt=class extends v{};var yt=class extends v{};var gt=class extends v{};var bt=class extends v{};var vt=class extends v{};var jt=class extends v{};var Fr=class extends v{};function Vr(e){return e==="datetime"?new o(new _t):e==="uri"?new o(new mt):e==="at-uri"?new o(new ht):e==="did"?new o(new wt):e==="handle"?new o(new xt):e==="at-identifier"?new o(new yt):e==="nsid"?new o(new gt):e==="cid"?new o(new bt):e==="language"?new o(new vt):e==="tid"?new o(new jt):e==="record-key"?new o(new Fr):new u(void 0)}function In(e){return e instanceof _t?"datetime":e instanceof mt?"uri":e instanceof ht?"at-uri":e instanceof wt?"did":e instanceof xt?"handle":e instanceof yt?"at-identifier":e instanceof gt?"nsid":e instanceof bt?"cid":e instanceof vt?"language":e instanceof jt?"tid":"record-key"}var qn=class extends v{constructor(t){super(),this.dict=t}};function Rr(){return new qn(ee())}function Pr(e,t){let n=e.dict,r=ae(n,t);return Gi(r)}var cl=void 0;function Jr(e,t){return new qn(_e(e.dict,t,cl))}function ls(e,t){return e.lastIndex=0,e.test(t)}function as(e,t){try{let n="gu";return t.case_insensitive&&(n+="i"),t.multi_line&&(n+="m"),new o(new RegExp(e,n))}catch(n){let r=(n.columnNumber||0)|0;return new u(new Un(n.message,r))}}var Un=class extends v{constructor(t,n){super(),this.error=t,this.byte_index=n}};var Gr=class extends v{constructor(t,n){super(),this.case_insensitive=t,this.multi_line=n}};function dl(e,t){return as(e,t)}function Be(e){return dl(e,new Gr(!1,!1))}function Me(e,t){return ls(e,t)}var Xt=class extends v{constructor(t,n){super(),this.seconds=t,this.nanoseconds=n}};function wl(e){let t=1e9,n=It(e.nanoseconds,t),r=e.nanoseconds-n,i=e.seconds+Nt(r,t);return n>=0?new Xt(i,n):new Xt(i-1,t+n)}function xl(e){return e%4===0&&(e%100!==0||e%400===0)}function yl(e){if(e.bitSize>=8)if(e.byteAt(0)===43)if((e.bitSize-8)%8===0){let t=oe(e,8);return new o(["+",t])}else return new u(void 0);else if(e.byteAt(0)===45&&(e.bitSize-8)%8===0){let t=oe(e,8);return new o(["-",t])}else return new u(void 0);else return new u(void 0)}function Kt(e,t){if(e.bitSize>=8&&(e.bitSize-8)%8===0)if(e.byteAt(0)===t){let r=oe(e,8);return new o(r)}else return new u(void 0);else return new u(void 0)}function gl(e){return e.bitSize===0?new o(void 0):new u(void 0)}function bl(e,t,n){let r=globalThis.Math.trunc((14-t)/12),i=e+4800-r,s=t+12*r-3;return n+globalThis.Math.trunc((153*s+2)/5)+365*i+globalThis.Math.trunc(i/4)-globalThis.Math.trunc(i/100)+globalThis.Math.trunc(i/400)-32045}var vl=86400,cs=3600,ds=60;function jl(e,t,n){let r=t*cs+n*ds;return e==="-"?-r:r}function kl(e,t,n,r,i,s){return bl(e,t,n)*vl+r*cs+i*ds+s}var Sl=1e9,Wr=58,fs=45;function El(e,t,n){for(;;){let r=e,i=t,s=n,l=globalThis.Math.trunc(s/10);if(r.bitSize>=8&&(r.bitSize-8)%8===0){let a=r.byteAt(0);if(48<=a&&a<=57&&l<1)e=oe(r,8),t=i,n=l;else{let f=r.byteAt(0);if(48<=f&&f<=57){let c=oe(r,8),$=f-48;e=c,t=i+$*l,n=l}else return new o([i,r])}}else return new o([i,r])}}function zl(e){if(e.bitSize>=8&&e.byteAt(0)===46)if(e.bitSize>=16&&(e.bitSize-16)%8===0){let t=e.byteAt(1);if(48<=t&&t<=57){let n=oe(e,16);return El(hn([t,n]),0,Sl)}else return(e.bitSize-8)%8===0?new u(void 0):new o([0,e])}else return(e.bitSize-8)%8===0?new u(void 0):new o([0,e]);else return new o([0,e])}function Al(e,t,n,r){for(;;){let i=e,s=t,l=n,a=r;if(a>=s)return new o([l,i]);if(i.bitSize>=8&&(i.bitSize-8)%8===0){let f=i.byteAt(0);if(48<=f&&f<=57)e=oe(i,8),t=s,n=l*10+(f-48),r=a+1;else return new u(void 0)}else return new u(void 0)}}function kt(e,t){return Al(e,t,0,0)}function Ol(e){return kt(e,4)}function Cl(e){return p(kt(e,2),t=>{let n,r;return n=t[0],r=t[1],1<=n&&n<=12?new o([n,r]):new u(void 0)})}function Bl(e,t,n){return p(kt(e,2),r=>{let i,s;return i=r[0],s=r[1],p(n===1?new o(31):n===3?new o(31):n===5?new o(31):n===7?new o(31):n===8?new o(31):n===10?new o(31):n===12?new o(31):n===4?new o(30):n===6?new o(30):n===9?new o(30):n===11?new o(30):n===2?xl(t)?new o(29):new o(28):new u(void 0),l=>1<=i&&i<=l?new o([i,s]):new u(void 0))})}function ps(e){return p(kt(e,2),t=>{let n,r;return n=t[0],r=t[1],0<=n&&n<=23?new o([n,r]):new u(void 0)})}function $s(e){return p(kt(e,2),t=>{let n,r;return n=t[0],r=t[1],0<=n&&n<=59?new o([n,r]):new u(void 0)})}function Ml(e){return p(kt(e,2),t=>{let n,r;return n=t[0],r=t[1],0<=n&&n<=60?new o([n,r]):new u(void 0)})}function Zr(e){return p(yl(e),t=>{let n,r;return n=t[0],r=t[1],p(ps(r),i=>{let s,l;return s=i[0],l=i[1],p(Kt(l,Wr),a=>p($s(a),f=>{let c,$;c=f[0],$=f[1];let _=jl(n,s,c);return new o([_,$])}))})})}function Dl(e){if(e.bitSize>=8)if(e.byteAt(0)===90)if((e.bitSize-8)%8===0){let t=oe(e,8);return new o([0,t])}else return Zr(e);else if(e.byteAt(0)===122&&(e.bitSize-8)%8===0){let t=oe(e,8);return new o([0,t])}else return Zr(e);else return Zr(e)}function Ll(e){if(e.bitSize>=8&&(e.bitSize-8)%8===0){let t=e.byteAt(0);if(t===84||t===116||t===32){let n=oe(e,8);return new o(n)}else return new u(void 0)}else return new u(void 0)}var Tl=210866803200;function Il(e,t,n,r,i,s,l,a){let c=kl(e,t,n,r,i,s)-Tl,$=new Xt(c-a,l);return wl($)}function _s(e){let t=On(e);return p(Ol(t),n=>{let r,i;return r=n[0],i=n[1],p(Kt(i,fs),s=>p(Cl(s),l=>{let a,f;return a=l[0],f=l[1],p(Kt(f,fs),c=>p(Bl(c,r,a),$=>{let _,x;return _=$[0],x=$[1],p(Ll(x),g=>p(ps(g),S=>{let E,I;return E=S[0],I=S[1],p(Kt(I,Wr),xe=>p($s(xe),H=>{let J,de;return J=H[0],de=H[1],p(Kt(de,Wr),Ze=>p(Ml(Ze),Le=>{let ir,_n;return ir=Le[0],_n=Le[1],p(zl(_n),Lt=>{let Tt,We;return Tt=Lt[0],We=Lt[1],p(Dl(We),ri=>{let ii,si;return ii=ri[0],si=ri[1],p(gl(si),iu=>new o(Il(r,a,_,E,J,ir,Tt,ii)))})})}))}))}))}))}))})}function ql(e){let t=G(e);if(t===0||t>64)return!1;{let i=Be("^[0-9]{4}-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9](\\.[0-9]{1,20})?(Z|([+-][0-2][0-9]:[0-5][0-9]))$");if(i instanceof o){let s=i[0],l=Me(s,e);return l&&(Oe(e,"-00:00")?!1:_s(e)instanceof o)}else return!1}}function Ul(e){let t=G(e);if(t===0||t>8192)return!1;{let i=Be("^[a-z][a-z.-]{0,80}:[!-~]+$");if(i instanceof o){let s=i[0];return Me(s,e)}else return!1}}function Qt(e){let t=G(e);if(t===0||t>2048)return!1;{let r=Z(e,"did:");if(r){let s=Be("^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$");if(s instanceof o){let l=s[0];return Me(l,e)}else return!1}else return r}}function en(e){let t="^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$",n=G(e)===0||G(e)>253,r=Be(t);if(n)return!1;if(r instanceof o){let i=r[0],s=Me(i,e);if(s){let l=fe(e,"."),a=ki(l);if(a instanceof o){let f=a[0];return f==="local"||f==="arpa"||f==="invalid"||f==="localhost"||f==="internal"||f==="example"||f==="onion"?!1:f!=="alt"}else return!1}else return s}else return n}function Fl(e){return Qt(e)||en(e)}function Qe(e){let n=Be("^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$");if(n instanceof o){let r=n[0],i=Me(r,e);if(i){let s=fe(e,".");return he(s)>=3&&G(e)<=317}else return i}else return!1}function Fn(e){let t=G(e);if(t<8||t>256)return!1;if(Z(e,"Qmb"))return!1;{let s=Be("^[a-zA-Z0-9+=]{8,256}$");if(s instanceof o){let l=s[0];return Me(l,e)}else return!1}}function ms(e){let t=Fn(e);return t&&Z(e,"bafkrei")}function Vl(e){let t=G(e);if(t===0||t>128)return!1;{let i=Be("^(i|[a-z]{2,3})(-[a-zA-Z0-9]+)*$");if(i instanceof o){let s=i[0];return Me(s,e)}else return!1}}function hs(e){let t="^[234567abcdefghij][234567abcdefghijklmnopqrstuvwxyz]{12}$",n=G(e)===13,r=Be(t);if(n&&r instanceof o){let i=r[0];return Me(i,e)}else return!1}function ws(e){let t=G(e);if(e==="."||e==="..")return!1;{let r=t>=1&&t<=512;if(r){let i=hs(e);if(i)return i;{let l=Be("^[a-zA-Z0-9_~.:-]+$");if(l instanceof o){let a=l[0];return Me(a,e)}else return!1}}else return r}}function Rl(e){let t=G(e);if(t===0||t>8192)return!1;{let r=Z(e,"at://");if(r){let i=Ve(e,5),s=fe(i,"/");if(s instanceof y)return!1;{let l=s.tail;if(l instanceof y){let a=s.head;return Qt(a)||en(a)}else{let a=l.tail;if(a instanceof y){let f=s.head,c=l.head,$=Qt(f)||en(f);return $&&Qe(c)}else if(a.tail instanceof y){let c=s.head,$=l.head,_=a.head,x=Qt(c)||en(c);if(x){let g=Qe($);return g&&ws(_)}else return x}else return!1}}}else return r}}function Vn(e,t){return t instanceof _t?ql(e):t instanceof mt?Ul(e):t instanceof ht?Rl(e):t instanceof wt?Qt(e):t instanceof xt?en(e):t instanceof yt?Fl(e):t instanceof gt?Qe(e):t instanceof bt?Fn(e):t instanceof vt?Vl(e):t instanceof jt?hs(e):ws(e)}var St=class extends v{constructor(t,n,r,i,s){super(),this.lexicons=t,this.path=n,this.current_lexicon_id=r,this.reference_stack=i,this.validator=s}};var Rn=class extends v{constructor(t,n){super(),this.lexicons=t,this.validator=n}};function Hr(){return new Rn(ee(),new A)}function Yr(e){let t,n=e.validator;n instanceof d?t=n[0]:t=(i,s,l)=>new o(void 0);let r=t;return new o(new St(e.lexicons,"",new A,Rr(),r))}function Pn(e,t){let n=ae(e.lexicons,t);if(n instanceof o){let r=n[0];return new d(r)}else return new A}function b(e){return e.path}function N(e,t){let n;e.path===""?n=t:n=e.path+"."+t;let i=n;return new St(e.lexicons,i,e.current_lexicon_id,e.reference_stack,e.validator)}function Et(e){return e.current_lexicon_id}function nn(e,t){return new St(e.lexicons,e.path,new d(t),e.reference_stack,e.validator)}function xs(e,t){return new St(e.lexicons,e.path,e.current_lexicon_id,Jr(e.reference_stack,t),e.validator)}function Kr(e,t){return Pr(e.reference_stack,t)}function ys(e,t){let n=fe(t,"#");if(n instanceof y)return new u(m("Invalid reference format: "+t));{let r=n.tail;if(r instanceof y){let i=n.head;return i!==""?new o([i,"main"]):new u(m("Invalid reference format: "+t))}else if(r.tail instanceof y){let s=n.head;if(s===""){let l=r.head,a=e.current_lexicon_id;if(a instanceof d){let f=a[0];return new o([f,l])}else return new u(m("Local reference '"+t+"' used without current lexicon context"))}else{let l=s,a=r.head;return l!==""&&a!==""?new o([l,a]):new u(m("Invalid reference format: "+t))}}else return new u(m("Invalid reference format: "+t))}}function Pl(e){let t,n=k(e,"id");if(n instanceof d){let i=n[0];t=new o(i)}else t=new u(m("Lexicon missing required 'id' field"));return p(t,i=>p(Qe(i)?new o(void 0):new u(m("Lexicon 'id' field is not a valid NSID: "+i)),s=>{let l,a=C(e,"defs");if(a instanceof d){let c=a[0];q(c)?l=new o(c):l=new u(m("Lexicon 'defs' must be an object at "+i))}else l=new u(m("Lexicon missing required 'defs' field at "+i));return p(l,c=>new o(new Tn(i,c)))}))}function Xr(e,t){return K(t,e,(n,r)=>{let i=Pl(r);if(i instanceof o){let s=i[0],l=_e(n.lexicons,s.id,s);return new o(new Rn(l,n.validator))}else return i})}function Qr(e,t,n,r,i){let s;if(n instanceof d){let a=n[0];t<a?s=new u(w(e+": "+i+" length "+B(t)+" is less than minLength "+B(a))):s=new o(void 0)}else s=new o(void 0);return p(s,a=>{if(r instanceof d){let f=r[0];return t>f?new u(w(e+": "+i+" length "+B(t)+" exceeds maxLength "+B(f))):new o(void 0)}else return new o(void 0)})}function et(e,t,n,r){if(t instanceof d&&n instanceof d){let i=t[0],s=n[0];return i>s?new u(m(e+": "+r+" minLength ("+B(i)+") cannot be greater than maxLength ("+B(s)+")")):new o(void 0)}else return new o(void 0)}function gs(e,t,n,r){let i;if(n instanceof d){let l=n[0];t<l?i=new u(w(e+": value "+B(t)+" is less than minimum "+B(l))):i=new o(void 0)}else i=new o(void 0);return p(i,l=>{if(r instanceof d){let a=r[0];return t>a?new u(w(e+": value "+B(t)+" exceeds maximum "+B(a))):new o(void 0)}else return new o(void 0)})}function bs(e,t,n){if(t instanceof d&&n instanceof d){let r=t[0],i=n[0];return r>i?new u(m(e+": minimum ("+B(r)+") cannot be greater than maximum ("+B(i)+")")):new o(void 0)}else return new o(void 0)}function Jn(e,t,n,r,i,s){return En(n,a=>s(t,a))?new o(void 0):new u(w(e+": "+r+" value '"+i(t)+"' is not in enum"))}function zt(e,t,n,r){return t&&n?new u(m(e+": "+r+" cannot have both 'const' and 'default'")):new o(void 0)}function O(e,t,n,r){let i=kn(t,s=>!rt(n,s));if(i instanceof y)return new o(void 0);{let s=i;return new u(m(e+": "+r+" has unknown fields: "+Fe(s,", ")+". Allowed fields: "+Fe(n,", ")))}}function At(e,t,n){let r=nn(t,n),i=ys(r,e);if(i instanceof o){let s=i[0][0],l=i[0][1],a=Pn(r,s);if(a instanceof d){let f=a[0],c=C(f.defs,l);if(c instanceof d){let $=c[0];return new o(new d($))}else return new u(m("Definition '"+l+"' not found in lexicon '"+s+"'"))}else return new u(m("Referenced lexicon not found: "+s))}else return i}function Gn(e,t,n){let r=b(n);return p((()=>{let i=k(t,"ref");if(i instanceof d){let s=i[0];return new o(s)}else return new u(w(r+": ref schema missing 'ref' field"))})(),i=>{if(Kr(n,i))return new u(w(r+": circular reference detected: "+i));{let l=xs(n,i);return p((()=>{let a=Et(l);if(a instanceof d){let f=a[0];return new o(f)}else return new u(w(r+": no current lexicon set for resolving reference"))})(),a=>p(At(i,l,a),f=>p((()=>{if(f instanceof d){let c=f[0];return new o(c)}else return new u(w(r+": reference not found: "+i))})(),c=>{let $=l.validator;return $(e,c,l)})))}})}function Jl(e,t){let n=fe(e,"#");if(n instanceof y)return new u(m(t+": global reference can only contain one # character"));{let r=n.tail;if(r instanceof y)return new u(m(t+": global reference can only contain one # character"));if(r.tail instanceof y){let s=n.head,l=r.head;return Ce(s)?new u(m(t+": NSID part of reference cannot be empty")):Ce(l)?new u(m(t+": definition name part of reference cannot be empty")):new o(void 0)}else return new u(m(t+": global reference can only contain one # character"))}}function Gl(e,t){if(Ce(e))return new u(m(t+": reference cannot be empty"));if(Z(e,"#")){let i=Ve(e,1);return Ce(i)?new u(m(t+": local reference must have a definition name after #")):new o(void 0)}else return Ue(e,"#")?Jl(e,t):new o(void 0)}var Zl=h(["type","ref","description"]);function rn(e,t){let n=b(t),r=z(e);return p(O(n,r,Zl,"ref"),i=>{let s,l=k(e,"ref");if(l instanceof d){let f=l[0];s=new o(f)}else s=new u(m(n+": ref missing required 'ref' field"));return p(s,f=>p(Gl(f,n),c=>{if(Z(f,"#"))return new o(void 0);{let _=Et(t);if(_ instanceof d){let x=_[0];return p(At(f,t,x),g=>g instanceof d?new o(void 0):new u(m(n+": reference not found: "+f)))}else return new o(void 0)}}))})}function Wl(e,t,n){let r=re(e,i=>j(i,L));return K(r,void 0,(i,s)=>{let l=Et(t);if(l instanceof d){let a=l[0];return p(At(s,t,a),f=>f instanceof d?new o(void 0):new u(m(n+": reference not found: "+s)))}else return new o(void 0)})}function Hl(e,t,n,r){let i=Et(n);if(i instanceof d){let s=i[0];return p(At(t,n,s),l=>{if(l instanceof d){let a=l[0],f=n.validator;return f(e,a,n)}else return new u(w(r+": reference not found: "+t))})}else return new o(void 0)}function Yl(e,t){let n=e===t;if(n)return n;if(Z(e,"#")){let i=Ve(e,1),s=t===i;return s||Oe(t,"#"+i)}else if(Oe(t,"#main")){let s=Ri(t,5);return e===s}else{if(Ue(t,"#"))return!1;{let l=t+"#main";return e===l}}}function Kl(e){return dt(e)?"null":$t(e)?"boolean":pt(e)?"number":Re(e)?"string":Yt(e)?"array":q(e)?"object":"unknown"}function Zn(e,t,n){let r=b(n);if(q(e)){let s,l=k(e,"$type");if(l instanceof d){let f=l[0];s=new o(f)}else s=new u(w(r+': union data must be an object which includes the "$type" property'));return p(s,f=>{let c,$=T(t,"refs");if($ instanceof d){let x=$[0];c=new o(x)}else c=new u(w(r+": union schema missing or invalid 'refs' field"));return p(c,x=>{if(Ye(x))return new u(w(r+": union schema has empty refs array"));{let S=re(x,I=>j(I,L)),E=ji(S,I=>Yl(I,f));if(E instanceof o){let I=E[0];return Hl(e,I,n,r)}else{let I,xe=Pe(t,"closed");return xe instanceof d?I=xe[0]:I=!1,I?new u(w(r+": union data $type must be one of "+Fe(S,", ")+", found '"+f+"'")):new o(void 0)}}})})}else{let s=Kl(e);return new u(w(r+': union data must be an object which includes the "$type" property, found '+s))}}var Xl=h(["type","refs","closed","description"]);function Wn(e,t){let n=b(t),r=z(e);return p(O(n,r,Xl,"union"),i=>{let s,l=T(e,"refs");if(l instanceof d){let f=l[0];s=new o(f)}else s=new u(m(n+": union missing required 'refs' field"));return p(s,f=>p(st(f,new o(void 0),(c,$,_)=>p(c,x=>j($,L)instanceof o?new o(void 0):new u(m(n+": refs["+Ht(_)+"] must be a string")))),c=>p((()=>{let $=Pe(e,"closed");return $ instanceof d?$[0]&&Ye(f)?new u(m(n+": union cannot be closed with empty refs array")):new o(void 0):new o(void 0)})(),$=>p((()=>{if(Ye(f)){let x=Pe(e,"closed");return x instanceof d?x[0]?new u(m(n+": union cannot have empty refs array when closed=true")):new o(void 0):new o(void 0)}else return new o(void 0)})(),_=>Wl(f,t,n)))))})}function js(e,t,n){let r=b(n);if(Re(e)){let s=je(e),l;return Z(s,'"')&&Oe(s,'"')?l=Wt(s,1,G(s)-2):l=s,Ce(l)?new u(w(r+": token value cannot be empty string")):new o(void 0)}else return new u(w(r+": expected string for token data, got other type"))}var Ql=h(["type","description"]);function Yn(e,t){let n=b(t),r=z(e);return O(n,r,Ql,"token")}function sn(e,t,n){let r=b(n);if(q(e)){if(k(e,"$bytes")instanceof d)return new u(w(r+": unknown type cannot be a bytes object"));{let l=k(e,"$type");return l instanceof d?l[0]==="blob"?new u(w(r+": unknown type cannot be a blob object")):new o(void 0):new o(void 0)}}else return new u(w(r+": unknown type must be an object, not a primitive or array"))}var ea=h(["type","description"]);function Ot(e,t){let n=b(t),r=z(e);return O(n,r,ea,"unknown")}function ta(e,t){let n=C(e,"ref");if(n instanceof d){let r=n[0];if(q(r)){let s=k(r,"$link");if(s instanceof d){let l=s[0];return ms(l)?new o(void 0):new u(w(t+": blob ref.$link must be a valid CID with raw multicodec (bafkrei prefix)"))}else return new u(w(t+": blob ref must have $link field"))}else return new u(w(t+": blob ref must be an object"))}else return new u(w(t+": blob missing required 'ref' field"))}function Ss(e,t,n,r){return Ue(t,"*")?t==="*"?new o(void 0):new u(m(e+": blob MIME type '"+r+"' can only use '*' as a complete wildcard for "+n)):new o(void 0)}function na(e,t,n){if(Ce(t))return new u(m(e+": blob MIME type cannot be empty"));if(t==="*/*")return new o(void 0);if(Ue(t,"/")){let s=fe(t,"/");if(s instanceof y)return new u(m(e+": blob MIME type '"+t+"' must have exactly one '/' character"));{let l=s.tail;if(l instanceof y)return new u(m(e+": blob MIME type '"+t+"' must have exactly one '/' character"));if(l.tail instanceof y){let f=s.head,c=l.head;return p(Ss(e,f,"type",t),$=>Ss(e,c,"subtype",t))}else return new u(m(e+": blob MIME type '"+t+"' must have exactly one '/' character"))}}else return new u(m(e+": blob MIME type '"+t+"' must contain a '/' character"))}function ra(e,t){return st(t,new o(void 0),(n,r,i)=>p(n,s=>{let l=j(r,L);if(l instanceof o){let a=l[0];return na(e,a,i)}else return new u(m(e+": blob accept["+B(i)+"] must be a string"))}))}function ia(e,t){if(t==="*/*")return!0;{let n=fe(e,"/"),r=fe(t,"/");if(n instanceof y)return!1;if(r instanceof y)return!1;{let i=n.tail;if(i instanceof y)return!1;{let s=r.tail;if(s instanceof y)return!1;if(i.tail instanceof y)if(s.tail instanceof y){let f=n.head,c=r.head,$=i.head,_=s.head,x;c==="*"?x=!0:x=f===c;let g=x,S;return _==="*"?S=!0:S=$===_,g&&S}else return!1;else return!1}}}}function sa(e,t,n){let r=re(n,s=>j(s,L));return En(r,s=>ia(t,s))?new o(void 0):new u(w(e+": blob mimeType '"+t+"' not accepted. Allowed: "+Fe(r,", ")))}var oa=h(["type","accept","maxSize","description"]);function Kn(e,t){let n=b(t),r=z(e);return p(O(n,r,oa,"blob"),i=>p((()=>{let s=T(e,"accept");if(s instanceof d){let l=s[0];return ra(n,l)}else return new o(void 0)})(),s=>{let l=M(e,"maxSize");return l instanceof d?l[0]>0?new o(void 0):new u(m(n+": blob maxSize must be greater than 0")):new o(void 0)}))}var la=h(["$type","ref","mimeType","size"]);function aa(e,t){let n=kn(t,r=>!rt(la,r));if(n instanceof y)return new o(void 0);{let r=n.head;return new u(w(e+": blob has unexpected field '"+r+"'"))}}function Es(e,t,n){let r=b(n);if(q(e)){let s=z(e);return p(aa(r,s),l=>p((()=>{let a=k(e,"$type");if(a instanceof d){let f=a[0];if(f==="blob")return new o(void 0);{let c=f;return new u(w(r+": blob $type must be 'blob', got '"+c+"'"))}}else return new u(w(r+": blob missing required '$type' field"))})(),a=>p(ta(e,r),f=>p((()=>{let c=k(e,"mimeType");if(c instanceof d){let $=c[0];return Ce($)?new u(w(r+": blob mimeType cannot be empty")):new o($)}else return new u(w(r+": blob missing required 'mimeType' field"))})(),c=>p((()=>{let $=M(e,"size");if($ instanceof d){let _=$[0];return _>=0?new o(_):new u(w(r+": blob size must be non-negative"))}else return new u(w(r+": blob missing or invalid 'size' field"))})(),$=>p((()=>{let _=T(t,"accept");if(_ instanceof d){let x=_[0];return sa(r,c,x)}else return new o(void 0)})(),_=>{let x=M(t,"maxSize");if(x instanceof d){let g=x[0];return $<=g?new o(void 0):new u(w(r+": blob size "+B($)+" exceeds maxSize "+B(g)))}else return new o(void 0)}))))))}else return new u(w(r+": expected blob object"))}function ln(e,t,n){let r=b(n);if($t(e)){let s=je(e),l=s==="true";if(l||s==="false"){let c=l,$=Pe(t,"const");if($ instanceof d){let _=$[0];return _!==c?new u(w(r+": must be constant value "+(_?"true":"false"))):new o(void 0)}else return new o(void 0)}else return new u(w(r+": invalid boolean representation"))}else return new u(w(r+": expected boolean, got other type"))}var ua=h(["type","const","default","description"]);function Ct(e,t){let n=b(t),r=z(e);return p(O(n,r,ua,"boolean"),i=>{let s=!D(Pe(e,"const"),new A),l=!D(Pe(e,"default"),new A);return zt(n,s,l,"boolean")})}function As(e,t,n){let r=b(n);if(q(e)){let s=z(e);return p(he(s)===1?new o(void 0):new u(w(r+": $bytes objects must have a single field")),l=>{let a=k(e,"$bytes");if(a instanceof d){let f=a[0],c=Ji(f);if(c instanceof o){let $=c[0],_=Cn($),x=M(t,"minLength"),g=M(t,"maxLength");return p((()=>{if(x instanceof d){let S=x[0];return _<S?new u(w(r+": bytes size out of bounds: "+Ht(_))):new o(void 0)}else return new o(void 0)})(),S=>p((()=>{if(g instanceof d){let E=g[0];return _>E?new u(w(r+": bytes size out of bounds: "+Ht(_))):new o(void 0)}else return new o(void 0)})(),E=>new o(void 0)))}else return new u(w(r+": decoding $bytes value: invalid base64 encoding"))}else return new u(w(r+": $bytes field missing or not a string"))})}else return new u(w(r+": expecting bytes"))}var fa=h(["type","minLength","maxLength","description"]);function Xn(e,t){let n=b(t),r=z(e);return p(O(n,r,fa,"bytes"),i=>{let s=M(e,"minLength"),l=M(e,"maxLength");return p(s instanceof d?s[0]<0?new u(m(n+": bytes schema minLength below zero")):new o(void 0):new o(void 0),a=>p(l instanceof d?l[0]<0?new u(m(n+": bytes schema maxLength below zero")):new o(void 0):new o(void 0),f=>et(n,s,l,"bytes")))})}function Cs(e,t,n){let r=b(n);if(q(e)){let s=k(e,"$link");if(s instanceof d){let l=s[0];return Fn(l)?new o(void 0):new u(w(r+": invalid CID format in $link"))}else return new u(w(r+": CID link must have $link field"))}else return new u(w(r+": expected CID link object"))}var ca=h(["type","description"]);function Qn(e,t){let n=b(t),r=z(e);return O(n,r,ca,"cid-link")}function da(e,t,n){return Jn(n,e,t,"integer",B,(r,i)=>r===i)}function un(e,t,n){let r=b(n);if(pt(e)){let s=je(e),l=Sr(s);if(l instanceof o){let a=l[0],f=M(t,"const");if(f instanceof d){let c=f[0];return c!==a?new u(w(r+": must be constant value "+B(c)+", found "+B(a))):new o(void 0)}else return p((()=>{let c=T(t,"enum");if(c instanceof d){let $=c[0],_=re($,x=>j(x,qe));return da(a,_,r)}else return new o(void 0)})(),c=>{let $=M(t,"minimum"),_=M(t,"maximum");return gs(r,a,$,_)})}else return new u(w(r+": failed to parse integer value"))}else return new u(w(r+": expected integer, got other type"))}var pa=h(["type","minimum","maximum","enum","const","default","description"]);function Bt(e,t){let n=b(t),r=z(e);return p(O(n,r,pa,"integer"),i=>{let s=M(e,"minimum"),l=M(e,"maximum");return p(bs(n,s,l),a=>p((()=>{let f=T(e,"enum");if(f instanceof d){let c=f[0];return K(c,void 0,($,_)=>j(_,qe)instanceof o?new o(void 0):new u(m(n+": enum values must be integers")))}else return new o(void 0)})(),f=>{let c=!D(M(e,"const"),new A),$=!D(M(e,"default"),new A);return zt(n,c,$,"integer")}))})}function Ms(e,t,n){let r=b(n);return dt(e)?new o(void 0):new u(w(r+": expected null, got other type"))}var $a=h(["type","description"]);function er(e,t){let n=b(t),r=z(e);return O(n,r,$a,"null")}function _a(e,t,n,r){let i=Zt(e);return Qr(r,i,t,n,"string")}function ma(e,t,n,r){let i,l=Gt(e);return i=he(l),Qr(r,i,t,n,"string (graphemes)")}function ha(e,t,n){if(Vn(e,t))return new o(void 0);{let i=In(t);return new u(w(n+": string does not match format '"+i+"'"))}}function wa(e,t,n){return Jn(n,e,t,"string",r=>r,(r,i)=>r===i)}function cn(e,t,n){let r=b(n);if(Re(e)){let s=je(e),l;Z(s,'"')&&Oe(s,'"')?l=Wt(s,1,G(s)-2):l=s;let f=l,c=M(t,"minLength"),$=M(t,"maxLength");return p(_a(f,c,$,r),_=>{let x=M(t,"minGraphemes"),g=M(t,"maxGraphemes");return p(ma(f,x,g,r),S=>{let E,I=k(t,"format");if(I instanceof d){let H=I[0],J=Vr(H);if(J instanceof o){let de=J[0];E=ha(f,de,r)}else E=new o(void 0)}else E=new o(void 0);return p(E,H=>{let J=T(t,"enum");if(J instanceof d){let de=J[0],Ze=re(de,Le=>j(Le,L));return wa(f,Ze,r)}else return new o(void 0)})})})}else return new u(w(r+": expected string, got other type"))}var xa=h(["type","format","minLength","maxLength","minGraphemes","maxGraphemes","enum","knownValues","const","default","description"]);function Mt(e,t){let n=b(t),r=z(e);return p(O(n,r,xa,"string"),i=>{let s,l=k(e,"format");if(l instanceof d){let _=l[0];Vr(_)instanceof o?s=new o(void 0):s=new u(m(n+": unknown format '"+_+"'. Valid formats: datetime, uri, at-uri, did, handle, at-identifier, nsid, cid, language, tid, record-key"))}else s=new o(void 0);let f=p(s,_=>{let x=M(e,"minLength"),g=M(e,"maxLength"),S=M(e,"minGraphemes"),E=M(e,"maxGraphemes");return p(x instanceof d?x[0]<0?new u(m(n+": string schema minLength below zero")):new o(void 0):new o(void 0),I=>p(g instanceof d?g[0]<0?new u(m(n+": string schema maxLength below zero")):new o(void 0):new o(void 0),xe=>p(S instanceof d?S[0]<0?new u(m(n+": string schema minGraphemes below zero")):new o(void 0):new o(void 0),H=>p(E instanceof d?E[0]<0?new u(m(n+": string schema maxGraphemes below zero")):new o(void 0):new o(void 0),J=>p(et(n,x,g,"string"),de=>et(n,S,E,"string (graphemes)"))))))}),c=p(f,_=>{let x=T(e,"enum");if(x instanceof d){let g=x[0];return K(g,void 0,(S,E)=>j(E,L)instanceof o?new o(void 0):new u(m(n+": enum values must be strings")))}else return new o(void 0)}),$=p(c,_=>{let x=T(e,"knownValues");if(x instanceof d){let g=x[0];return K(g,void 0,(S,E)=>j(E,L)instanceof o?new o(void 0):new u(m(n+": knownValues must be strings")))}else return new o(void 0)});return p($,_=>{let x=!D(k(e,"const"),new A),g=!D(k(e,"default"),new A);return zt(n,x,g,"string")})})}function ya(e,t,n){let r=re(t,i=>j(i,L));return p(he(r)===he(t)?new o(void 0):new u(m(e+": required fields must be strings")),i=>{if(n instanceof d){let s=n[0],l=ke(s);if(l instanceof o){let a=l[0];return K(r,void 0,(f,c)=>Xe(a,c)?new o(void 0):new u(m(e+": required field '"+c+"' not found in properties")))}else return new o(void 0)}else return Ye(r)?new o(void 0):new u(m(e+": required fields specified but no properties defined"))})}function ga(e,t,n){let r=re(t,i=>j(i,L));return p(he(r)===he(t)?new o(void 0):new u(m(e+": nullable fields must be strings")),i=>{if(n instanceof d){let s=n[0],l=ke(s);if(l instanceof o){let a=l[0];return K(r,void 0,(f,c)=>Xe(a,c)?new o(void 0):new u(m(e+": nullable field '"+c+"' not found in properties")))}else return new o(void 0)}else return Ye(r)?new o(void 0):new u(m(e+": nullable fields specified but no properties defined"))})}function ba(e,t,n){let r=re(t,i=>j(i,L));return K(r,void 0,(i,s)=>{if(C(n,s)instanceof d)return new o(void 0);{let a;e===""?a="required field '"+s+"' is missing":a=e+": required field '"+s+"' is missing";let f=a;return new u(w(f))}})}function Ls(e){return dt(e)?"null":$t(e)?"boolean":pt(e)?"number":Re(e)?"string":Yt(e)?"array":"object"}var va=h(["type","properties","required","nullable","description"]),ja=h(["type","items","minLength","maxLength","description"]);function ka(e,t,n){return ti(e,t,n)}function ti(e,t,n){let r=k(t,"type");if(r instanceof d){let i=r[0];if(i==="string")return cn(e,t,n);if(i==="integer")return un(e,t,n);if(i==="boolean")return ln(e,t,n);if(i==="bytes")return As(e,t,n);if(i==="blob")return Es(e,t,n);if(i==="cid-link")return Cs(e,t,n);if(i==="null")return Ms(e,t,n);if(i==="object")return tr(e,t,n);if(i==="array")return nr(e,t,n);if(i==="union")return Zn(e,t,n);if(i==="ref")return Gn(e,t,n);if(i==="token")return js(e,t,n);if(i==="unknown")return sn(e,t,n);{let s=i;return new u(w("Unknown schema type '"+s+"' at '"+b(n)+"'"))}}else return new u(w("Schema missing type field at '"+b(n)+"'"))}function tr(e,t,n){let r=b(n);if(q(e))return p((()=>{let s=T(t,"required");if(s instanceof d){let l=s[0];return ba(r,l,e)}else return new o(void 0)})(),s=>{let l,a=T(t,"nullable");if(a instanceof d){let $=a[0];l=re($,_=>j(_,L))}else l=h([]);let f=l,c=C(t,"properties");if(c instanceof d){let $=c[0];return Sa(e,$,f,n)}else return new o(void 0)});{let s=Ls(e);return new u(w("Expected object at '"+r+"', found "+s))}}function Sa(e,t,n,r){let i=ke(e);if(i instanceof o){let s=i[0],l=ke(t);if(l instanceof o){let a=l[0];return me(s,new o(void 0),(f,c,$)=>p(f,_=>{let x=ae(a,c);if(x instanceof o){let g=x[0],S=se(g);if(S instanceof o){let E=S[0],I=N(r,c);if(ss($))return rt(n,c)?new o(void 0):new u(w("Field '"+c+"' at '"+b(r)+"' cannot be null"));{let H=se($);if(H instanceof o){let J=H[0];return ka(J,E,I)}else return H}}else return S}else return new o(void 0)}))}else return l}else return i}function Ea(e,t,n){let r=se(e);return p(r,i=>{let s=k(t,"type");return s instanceof d&&s[0]==="ref"?Gn(i,t,n):ti(i,t,n)})}function nr(e,t,n){let r=b(n);if(Yt(e)){let s,l=Ur(e);if(l instanceof d){let f=l[0];s=new o(f)}else s=new u(w(r+": failed to parse array"));return p(s,f=>{let c=he(f);return p((()=>{let $=M(t,"minLength");if($ instanceof d){let _=$[0];return c<_?new u(w(r+": array has length "+B(c)+" but minimum length is "+B(_))):new o(void 0)}else return new o(void 0)})(),$=>p((()=>{let _=M(t,"maxLength");if(_ instanceof d){let x=_[0];return c>x?new u(w(r+": array has length "+B(c)+" but maximum length is "+B(x))):new o(void 0)}else return new o(void 0)})(),_=>{let x=C(t,"items");if(x instanceof d){let g=x[0];return st(f,new o(void 0),(S,E,I)=>p(S,xe=>{let H=N(n,"["+B(I)+"]");return Ea(E,g,H)}))}else return new o(void 0)}))})}else{let s=Ls(e);return new u(w(r+": expected array, found "+s))}}function za(e,t){return ni(e,t)}function ni(e,t){let n=k(e,"type");if(n instanceof d){let r=n[0];if(r==="string")return Mt(e,t);if(r==="integer")return Bt(e,t);if(r==="boolean")return Ct(e,t);if(r==="bytes")return Xn(e,t);if(r==="blob")return Kn(e,t);if(r==="cid-link")return Qn(e,t);if(r==="null")return er(e,t);if(r==="object")return pn(e,t);if(r==="array")return $n(e,t);if(r==="union")return Wn(e,t);if(r==="ref")return rn(e,t);if(r==="token")return Yn(e,t);if(r==="unknown")return Ot(e,t);{let i=r;return new u(m(b(t)+": unknown type '"+i+"'"))}}else return new u(m(b(t)+": schema missing type field"))}function pn(e,t){let n=b(t),r=z(e);return p(O(n,r,va,"object"),i=>{let s;return T(e,"properties")instanceof d?s=new u(m(n+": properties must be an object, not an array")):q(e)?s=new o(new A):s=new o(new A),p(s,f=>{let c=C(e,"properties");return p((()=>{let $=T(e,"required");if($ instanceof d){let _=$[0];return ya(n,_,c)}else return new o(void 0)})(),$=>p((()=>{let _=T(e,"nullable");if(_ instanceof d){let x=_[0];return ga(n,x,c)}else return new o(void 0)})(),_=>{if(c instanceof d){let x=c[0];return q(x)?Aa(x,t):new o(void 0)}else return new o(void 0)}))})})}function Aa(e,t){let n=ke(e);if(n instanceof o){let r=n[0];return me(r,new o(void 0),(i,s,l)=>p(i,a=>{let f=se(l);if(f instanceof o){let c=f[0],$=N(t,"properties."+s);return za(c,$)}else return f}))}else return n}function Oa(e,t){let n=k(e,"type");return n instanceof d&&n[0]==="ref"?rn(e,t):ni(e,t)}function $n(e,t){let n=b(t),r=z(e);return p(O(n,r,ja,"array"),i=>{let s,l=C(e,"items");if(l instanceof d){let f=l[0];s=new o(f)}else s=new u(m(n+": array missing required 'items' field"));return p(s,f=>{let c=N(t,".items");return p(Oa(f,c),$=>{let _=M(e,"minLength"),x=M(e,"maxLength");return p(et(n,_,x,"array"),g=>new o(void 0))})})})}function Ca(e,t,n){if(t instanceof d){let r=t[0];return K(r,void 0,(i,s)=>{let l=j(s,L);if(l instanceof o){let a=l[0];return Xe(n,a)?new o(void 0):new u(m(e+": required field '"+a+"' not found in properties"))}else return new u(m(e+": required field must be a string"))})}else return new o(void 0)}function Je(e,t){let n=k(e,"type");if(n instanceof d){let r=n[0];if(r==="boolean")return Ct(e,t);if(r==="integer")return Bt(e,t);if(r==="string")return Mt(e,t);if(r==="unknown")return Ot(e,t);if(r==="array")return $n(e,t);{let i=r;return new u(m(b(t)+": unknown type '"+i+"'"))}}else return new u(m(b(t)+": schema missing type field"))}function Ba(e,t,n,r){let i=e+".properties."+t,s=k(n,"type");if(s instanceof d){let l=s[0];if(l==="boolean"){let a=N(r,"properties."+t);return Je(n,a)}else if(l==="integer"){let a=N(r,"properties."+t);return Je(n,a)}else if(l==="string"){let a=N(r,"properties."+t);return Je(n,a)}else if(l==="unknown"){let a=N(r,"properties."+t);return Je(n,a)}else if(l==="array"){let a=C(n,"items");if(a instanceof d){let f=a[0],c=k(f,"type");if(c instanceof d){let $=c[0];if($==="boolean"){let _=N(r,"properties."+t);return Je(n,_)}else if($==="integer"){let _=N(r,"properties."+t);return Je(n,_)}else if($==="string"){let _=N(r,"properties."+t);return Je(n,_)}else if($==="unknown"){let _=N(r,"properties."+t);return Je(n,_)}else{let _=$;return new u(m(i+": params array items must be boolean, integer, string, or unknown, got '"+_+"'"))}}else return new u(m(i+": array items missing type field"))}else return new u(m(i+": array property missing items field"))}else{let a=l;return new u(m(i+": params properties must be boolean, integer, string, unknown, or arrays of these, got '"+a+"'"))}}else return new u(m(i+": property missing type field"))}function Ma(e,t,n){return Ln(t,new o(void 0),(r,i,s)=>r instanceof o?p(i===""?new u(m(e+": empty property name not allowed")):new o(void 0),l=>p((()=>{let a=se(s);return a instanceof o?a:new u(m(e+": invalid property value for '"+i+"'"))})(),a=>Ba(e,i,a,n))):r)}var Da=h(["type","description","properties","required"]);function Ge(e,t){let n=b(t),r=z(e);return p(O(n,r,Da,"params"),i=>p((()=>{let s=k(e,"type");if(s instanceof d){let l=s[0];if(l==="params")return new o(void 0);{let a=l;return new u(m(n+": expected type 'params', got '"+a+"'"))}}else return new u(m(n+": params missing type field"))})(),s=>{let l,a=C(e,"properties");if(a instanceof d){let x=a[0];l=ke(x)}else l=new o(Dn());let f=l,c,$=T(e,"required");$ instanceof d,c=$;let _=c;return p(f,x=>p(Ca(n,_,x),g=>Ma(n,x,t)))}))}function La(e,t){let n=N(t,"parameters");return Ge(e,n)}function Is(e,t,n){return k(t,"encoding")instanceof d?new o(void 0):new u(m(e+": procedure "+n+" missing encoding field"))}var Ta=h(["type","parameters","input","output","errors","description"]);function Ns(e,t){let n=b(t),r=z(e);return p(O(n,r,Ta,"procedure"),i=>p((()=>{let s=C(e,"parameters");if(s instanceof d){let l=s[0];return La(l,t)}else return new o(void 0)})(),s=>p((()=>{let l=C(e,"input");if(l instanceof d){let a=l[0];return Is(n,a,"input")}else return new o(void 0)})(),l=>p((()=>{let a=C(e,"output");if(a instanceof d){let f=a[0];return Is(n,f,"output")}else return new o(void 0)})(),a=>T(e,"errors")instanceof d?new o(void 0):new o(void 0)))))}function Na(e,t){let n=N(t,"parameters");return Ge(e,n)}function qa(e,t){return k(t,"encoding")instanceof d?new o(void 0):new u(m(e+": query output missing encoding field"))}var Ua=h(["type","parameters","output","errors","description"]);function qs(e,t){let n=b(t),r=z(e);return p(O(n,r,Ua,"query"),i=>p((()=>{let s=C(e,"parameters");if(s instanceof d){let l=s[0];return Na(l,t)}else return new o(void 0)})(),s=>p((()=>{let l=C(e,"output");if(l instanceof d){let a=l[0];return qa(n,a)}else return new o(void 0)})(),l=>T(e,"errors")instanceof d?new o(void 0):new o(void 0))))}function Us(e,t,n){let r=b(n);if(q(e)){let s=C(t,"record");if(s instanceof d){let l=s[0];return tr(e,l,n)}else return new u(w(r+": record schema missing 'record' field"))}else return new u(w(r+": expected object for record"))}function Va(e,t){return t==="tid"?new o(void 0):t==="any"?new o(void 0):t==="nsid"?new o(void 0):Z(t,"literal:")?new o(void 0):new u(m(e+": record has invalid key type '"+t+"'. Must be 'tid', 'any', 'nsid', or 'literal:*'"))}var Ra=h(["type","key","record","description"]),Pa=h(["type","properties","required","nullable","description"]);function Ja(e,t){let n=k(t,"type");if(n instanceof d){let r=n[0];if(r==="object"){let i=z(t);return p(O(e,i,Pa,"record object"),s=>p((()=>{let l=C(t,"properties");if(l instanceof d){let a=l[0];return q(a)?new o(void 0):new u(m(e+": record properties must be an object"))}else return new o(void 0)})(),l=>T(t,"nullable")instanceof d?new o(void 0):C(t,"nullable")instanceof d?new u(m(e+": record nullable field must be an array")):new o(void 0)))}else{let i=r;return new u(m(e+": record field must be type 'object', got '"+i+"'"))}}else return new u(m(e+": record field missing type"))}function Fs(e,t){let n=b(t),r=z(e);return p(O(n,r,Ra,"record"),i=>{let s,l=k(e,"key");if(l instanceof d){let f=l[0];s=new o(f)}else s=new u(m(n+": record missing required 'key' field"));return p(s,f=>p(Va(n,f),c=>{let $,_=C(e,"record");if(_ instanceof d){let g=_[0];$=new o(g)}else $=new u(m(n+": record missing required 'record' field"));return p($,g=>p(Ja(n,g),S=>{let E=N(t,".record");return pn(g,E)}))}))})}function Za(e,t){let n=N(t,"parameters");return Ge(e,n)}function Wa(e,t){let n=C(t,"schema");if(n instanceof d){let r=n[0],i=k(r,"type");if(i instanceof d){let s=i[0];if(s==="union")return new o(void 0);{let l=s;return new u(m(e+": subscription message schema must be type 'union', got '"+l+"'"))}}else return new u(m(e+": subscription message schema missing type field"))}else return new u(m(e+": subscription message missing schema field"))}var Ha=h(["type","parameters","message","errors","description"]);function Vs(e,t){let n=b(t),r=z(e);return p(O(n,r,Ha,"subscription"),i=>p((()=>{let s=C(e,"parameters");if(s instanceof d){let l=s[0];return Za(l,t)}else return new o(void 0)})(),s=>p((()=>{let l=C(e,"message");if(l instanceof d){let a=l[0];return Wa(n,a)}else return new o(void 0)})(),l=>T(e,"errors")instanceof d?new o(void 0):new o(void 0))))}function Ka(e,t){let n=k(e,"type");if(n instanceof d){let r=n[0];if(r==="record")return Fs(e,t);if(r==="query")return qs(e,t);if(r==="procedure")return Ns(e,t);if(r==="subscription")return Vs(e,t);if(r==="params")return Ge(e,t);if(r==="object")return pn(e,t);if(r==="array")return $n(e,t);if(r==="union")return Wn(e,t);if(r==="string")return Mt(e,t);if(r==="integer")return Bt(e,t);if(r==="boolean")return Ct(e,t);if(r==="bytes")return Xn(e,t);if(r==="blob")return Kn(e,t);if(r==="cid-link")return Qn(e,t);if(r==="null")return er(e,t);if(r==="ref")return rn(e,t);if(r==="token")return Yn(e,t);if(r==="unknown")return Ot(e,t);{let i=r;return new u(m("Unknown type: "+i))}}else return new u(m("Definition missing type field"))}function Xa(e){let t,n=Hr();t=Xr(n,e);let r=t;if(r instanceof o){let i=r[0],s=Yr(i);if(s instanceof o){let l=s[0],a=me(l.lexicons,ee(),(c,$,_)=>{let x=z(_.defs),g=nn(l,$);return Sn(x,c,(S,E)=>{let I=C(_.defs,E);if(I instanceof d){let xe=I[0],H=Ka(xe,g);if(H instanceof o)return S;{let J=H[0],de;J instanceof ft?de="Lexicon not found: "+J.collection:(J instanceof ct,de=J.message);let Ze=de,Le;Z(Ze,": ")?Le=Ve(Ze,2):Le=Ze;let _n=Le,Lt=$+"#"+E+": "+_n,Tt=ae(S,$);if(Tt instanceof o){let We=Tt[0];return _e(S,$,F(Lt,We))}else return _e(S,$,h([Lt]))}}else return S})});return xr(a)?new o(void 0):new u(a)}else{let l=s[0];return new u(bn(h([["builder",h([Nr(l)])]])))}}else{let i=r[0];return new u(bn(h([["builder",h([Nr(i)])]])))}}function Rs(e){let t,n=Hr();return t=Xr(n,e),p(t,i=>Yr(i))}function Ps(e,t,n){let r=Pn(e,t);if(r instanceof d){let i=r[0],s=C(i.defs,"main");if(s instanceof d){let l=s[0],a=nn(e,t),f=N(a,"defs.main");return Us(n,l,f)}else return new u(m("Lexicon '"+t+"' has no main definition"))}else return new u(qr(t))}function Qa(e,t,n){return p(Rs(e),r=>Ps(r,t,n))}function eu(e){return Qe(e)}function tu(e,t){if(Vn(e,t))return new o(void 0);{let r=In(t);return new u("Value does not match format: "+r)}}function Js(e){return se(e)}function Gs(e){return p((()=>{let t=Mn(e,ue);return Ke(t,n=>m("Failed to parse JSON string"))})(),t=>Js(t))}function nu(e){let n=it(e,Gs);return Ke(n,r=>m("Failed to parse JSON strings"))}return Xs(ru);})(); 1 + var honk=(()=>{var sr=Object.defineProperty;var Zs=Object.getOwnPropertyDescriptor;var Ws=Object.getOwnPropertyNames;var Hs=Object.prototype.hasOwnProperty;var Ys=(e,t)=>{for(var n in t)sr(e,n,{get:t[n],enumerable:!0})},Ks=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ws(t))!Hs.call(e,i)&&i!==n&&sr(e,i,{get:()=>t[i],enumerable:!(r=Zs(t,i))||r.enumerable});return e};var Xs=e=>Ks(sr({},"__esModule",{value:!0}),e);var ru={};Ys(ru,{build_validation_context:()=>Rs,dynamic_to_json:()=>Js,is_valid_nsid:()=>eu,parse_json_string:()=>Gs,parse_json_strings:()=>nu,toList:()=>w,validate:()=>Xa,validate_record:()=>Qa,validate_record_with_context:()=>Ps,validate_string_format:()=>tu});var v=class{withFields(t){let n=Object.keys(this).map(r=>r in t?t[r]:this[r]);return new this.constructor(...n)}},Q=class{static fromArray(t,n){let r=n||new y;for(let i=t.length-1;i>=0;--i)r=new Te(t[i],r);return r}[Symbol.iterator](){return new or(this)}toArray(){return[...this]}atLeastLength(t){let n=this;for(;t-- >0&&n;)n=n.tail;return n!==void 0}hasLength(t){let n=this;for(;t-- >0&&n;)n=n.tail;return t===-1&&n instanceof y}countLength(){let t=this,n=0;for(;t;)t=t.tail,n++;return n-1}};function F(e,t){return new Te(e,t)}function w(e,t){return Q.fromArray(e,t)}var or=class{#e;constructor(t){this.#e=t}next(){if(this.#e instanceof y)return{done:!0};{let{head:t,tail:n}=this.#e;return this.#e=n,{value:t,done:!1}}}},y=class extends Q{};var Te=class extends Q{constructor(t,n){super(),this.head=t,this.tail=n}};var di=e=>e instanceof Te,pi=e=>e.head,$i=e=>e.tail,X=class{bitSize;byteSize;bitOffset;rawBuffer;constructor(t,n,r){if(!(t instanceof Uint8Array))throw globalThis.Error("BitArray can only be constructed from a Uint8Array");if(this.bitSize=n??t.length*8,this.byteSize=Math.trunc((this.bitSize+7)/8),this.bitOffset=r??0,this.bitSize<0)throw globalThis.Error(`BitArray bit size is invalid: ${this.bitSize}`);if(this.bitOffset<0||this.bitOffset>7)throw globalThis.Error(`BitArray bit offset is invalid: ${this.bitOffset}`);if(t.length!==Math.trunc((this.bitOffset+this.bitSize+7)/8))throw globalThis.Error("BitArray buffer length is invalid");this.rawBuffer=t}byteAt(t){if(!(t<0||t>=this.byteSize))return nt(this.rawBuffer,this.bitOffset,t)}equals(t){if(this.bitSize!==t.bitSize)return!1;let n=Math.trunc(this.bitSize/8);if(this.bitOffset===0&&t.bitOffset===0){for(let i=0;i<n;i++)if(this.rawBuffer[i]!==t.rawBuffer[i])return!1;let r=this.bitSize%8;if(r){let i=8-r;if(this.rawBuffer[n]>>i!==t.rawBuffer[n]>>i)return!1}}else{for(let i=0;i<n;i++){let s=nt(this.rawBuffer,this.bitOffset,i),l=nt(t.rawBuffer,t.bitOffset,i);if(s!==l)return!1}let r=this.bitSize%8;if(r){let i=nt(this.rawBuffer,this.bitOffset,n),s=nt(t.rawBuffer,t.bitOffset,n),l=8-r;if(i>>l!==s>>l)return!1}}return!0}get buffer(){if(ui("buffer","Use BitArray.byteAt() or BitArray.rawBuffer instead"),this.bitOffset!==0||this.bitSize%8!==0)throw new globalThis.Error("BitArray.buffer does not support unaligned bit arrays");return this.rawBuffer}get length(){if(ui("length","Use BitArray.bitSize or BitArray.byteSize instead"),this.bitOffset!==0||this.bitSize%8!==0)throw new globalThis.Error("BitArray.length does not support unaligned bit arrays");return this.rawBuffer.length}};function nt(e,t,n){if(t===0)return e[n]??0;{let r=e[n]<<t&255,i=e[n+1]>>8-t;return r|i}}var mn=class{constructor(t){this.value=t}},ai={};function ui(e,t){ai[e]||(console.warn(`Deprecated BitArray.${e} property used in JavaScript FFI code. ${t}.`),ai[e]=!0)}function le(e,t,n){if(n??=e.bitSize,Qs(e,t,n),t===n)return new X(new Uint8Array);if(t===0&&n===e.bitSize)return e;t+=e.bitOffset,n+=e.bitOffset;let r=Math.trunc(t/8),s=Math.trunc((n+7)/8)-r,l;return r===0&&s===e.rawBuffer.byteLength?l=e.rawBuffer:l=new Uint8Array(e.rawBuffer.buffer,e.rawBuffer.byteOffset+r,s),new X(l,n-t,t%8)}function hn(e){if(e.length===0)return new X(new Uint8Array);if(e.length===1){let l=e[0];return l instanceof X?l:l instanceof Uint8Array?new X(l):new X(new Uint8Array(e))}let t=0,n=!0;for(let l of e)l instanceof X?(t+=l.bitSize,n=!1):l instanceof Uint8Array?(t+=l.byteLength*8,n=!1):t+=8;if(n)return new X(new Uint8Array(e));let r=new Uint8Array(Math.trunc((t+7)/8)),i=0;for(let l of e){let a=i%8===0;if(l instanceof X)if(a&&l.bitOffset===0){r.set(l.rawBuffer,i/8),i+=l.bitSize;let f=l.bitSize%8;if(f!==0){let c=Math.trunc(i/8);r[c]>>=8-f,r[c]<<=8-f}}else s(l.rawBuffer,l.bitSize,l.bitOffset);else l instanceof Uint8Array?a?(r.set(l,i/8),i+=l.byteLength*8):s(l,l.byteLength*8,0):a?(r[i/8]=l,i+=8):s(new Uint8Array([l]),8,0)}function s(l,a,f){if(a===0)return;let c=Math.trunc(a+7/8),$=i%8,_=8-$,x=Math.trunc(i/8);for(let g=0;g<c;g++){let S=nt(l,f,g);a<8&&(S>>=8-a,S<<=8-a),r[x]|=S>>$;let E=a-Math.max(0,a-_);if(a-=E,i+=E,a===0)break;r[++x]=S<<_,E=a-Math.max(0,a-$),a-=E,i+=E}}return new X(r,t)}function Qs(e,t,n){if(t<0||t>e.bitSize||n<t||n>e.bitSize){let r=`Invalid bit array slice: start = ${t}, end = ${n}, bit size = ${e.bitSize}`;throw new globalThis.Error(r)}}var fi;function _i(e){return fi??=new TextEncoder,fi.encode(e)}var rt=class e extends v{static isResult(t){return t instanceof e}},o=class extends rt{constructor(t){super(),this[0]=t}isOk(){return!0}},mi=e=>new o(e);var u=class extends rt{constructor(t){super(),this[0]=t}isOk(){return!1}},hi=e=>new u(e);function D(e,t){let n=[e,t];for(;n.length;){let r=n.pop(),i=n.pop();if(r===i)continue;if(!ci(r)||!ci(i)||!lo(r,i)||to(r,i)||no(r,i)||ro(r,i)||io(r,i)||so(r,i)||oo(r,i))return!1;let l=Object.getPrototypeOf(r);if(l!==null&&typeof l.equals=="function")try{if(r.equals(i))continue;return!1}catch{}let[a,f]=eo(r),c=a(r),$=a(i);if(c.length!==$.length)return!1;for(let _ of c)n.push(f(r,_),f(i,_))}return!0}function eo(e){if(e instanceof Map)return[t=>t.keys(),(t,n)=>t.get(n)];{let t=e instanceof globalThis.Error?["message"]:[];return[n=>[...t,...Object.keys(n)],(n,r)=>n[r]]}}function to(e,t){return e instanceof Date&&(e>t||e<t)}function no(e,t){return!(e instanceof X)&&e.buffer instanceof ArrayBuffer&&e.BYTES_PER_ELEMENT&&!(e.byteLength===t.byteLength&&e.every((n,r)=>n===t[r]))}function ro(e,t){return Array.isArray(e)&&e.length!==t.length}function io(e,t){return e instanceof Map&&e.size!==t.size}function so(e,t){return e instanceof Set&&(e.size!=t.size||[...e].some(n=>!t.has(n)))}function oo(e,t){return e instanceof RegExp&&(e.source!==t.source||e.flags!==t.flags)}function ci(e){return typeof e=="object"&&e!==null}function lo(e,t){return typeof e!="object"&&typeof t!="object"&&(!e||!t)||[Promise,WeakSet,WeakMap,Function].some(r=>e instanceof r)?!1:e.constructor===t.constructor}function Ut(e,t){return t===0?0:e%t}function Ft(e,t){return Math.trunc(wn(e,t))}function wn(e,t){return t===0?0:e/t}var d=class extends v{constructor(t){super(),this[0]=t}};var A=class extends v{};var wi=new WeakMap,lr=new DataView(new ArrayBuffer(8)),ar=0;function ur(e){let t=wi.get(e);if(t!==void 0)return t;let n=ar++;return ar===2147483647&&(ar=0),wi.set(e,n),n}function fr(e,t){return e^t+2654435769+(e<<6)+(e>>2)|0}function dr(e){let t=0,n=e.length;for(let r=0;r<n;r++)t=Math.imul(31,t)+e.charCodeAt(r)|0;return t}function yi(e){lr.setFloat64(0,e);let t=lr.getInt32(0),n=lr.getInt32(4);return Math.imul(73244475,t>>16^t)^n}function ao(e){return dr(e.toString())}function uo(e){let t=Object.getPrototypeOf(e);if(t!==null&&typeof t.hashCode=="function")try{let r=e.hashCode(e);if(typeof r=="number")return r}catch{}if(e instanceof Promise||e instanceof WeakSet||e instanceof WeakMap)return ur(e);if(e instanceof Date)return yi(e.getTime());let n=0;if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),Array.isArray(e)||e instanceof Uint8Array)for(let r=0;r<e.length;r++)n=Math.imul(31,n)+pe(e[r])|0;else if(e instanceof Set)e.forEach(r=>{n=n+pe(r)|0});else if(e instanceof Map)e.forEach((r,i)=>{n=n+fr(pe(r),pe(i))|0});else{let r=Object.keys(e);for(let i=0;i<r.length;i++){let s=r[i],l=e[s];n=n+fr(pe(l),dr(s))|0}}return n}function pe(e){if(e===null)return 1108378658;if(e===void 0)return 1108378659;if(e===!0)return 1108378657;if(e===!1)return 1108378656;switch(typeof e){case"number":return yi(e);case"string":return dr(e);case"bigint":return ao(e);case"object":return uo(e);case"symbol":return ur(e);case"function":return ur(e);default:return 0}}var Ee=5,pr=Math.pow(2,Ee),fo=pr-1,co=pr/2,po=pr/4,re=0,Se=1,ae=2,Ye=3,$r={type:ae,bitmap:0,array:[]};function Vt(e,t){return e>>>t&fo}function gn(e,t){return 1<<Vt(e,t)}function $o(e){return e-=e>>1&1431655765,e=(e&858993459)+(e>>2&858993459),e=e+(e>>4)&252645135,e+=e>>8,e+=e>>16,e&127}function _r(e,t){return $o(e&t-1)}function $e(e,t,n){let r=e.length,i=new Array(r);for(let s=0;s<r;++s)i[s]=e[s];return i[t]=n,i}function _o(e,t,n){let r=e.length,i=new Array(r+1),s=0,l=0;for(;s<t;)i[l++]=e[s++];for(i[l++]=n;s<r;)i[l++]=e[s++];return i}function cr(e,t){let n=e.length,r=new Array(n-1),i=0,s=0;for(;i<t;)r[s++]=e[i++];for(++i;i<n;)r[s++]=e[i++];return r}function gi(e,t,n,r,i,s){let l=pe(t);if(l===r)return{type:Ye,hash:l,array:[{type:re,k:t,v:n},{type:re,k:i,v:s}]};let a={val:!1};return Rt(mr($r,e,l,t,n,a),e,r,i,s,a)}function Rt(e,t,n,r,i,s){switch(e.type){case Se:return mo(e,t,n,r,i,s);case ae:return mr(e,t,n,r,i,s);case Ye:return ho(e,t,n,r,i,s)}}function mo(e,t,n,r,i,s){let l=Vt(n,t),a=e.array[l];if(a===void 0)return s.val=!0,{type:Se,size:e.size+1,array:$e(e.array,l,{type:re,k:r,v:i})};if(a.type===re)return D(r,a.k)?i===a.v?e:{type:Se,size:e.size,array:$e(e.array,l,{type:re,k:r,v:i})}:(s.val=!0,{type:Se,size:e.size,array:$e(e.array,l,gi(t+Ee,a.k,a.v,n,r,i))});let f=Rt(a,t+Ee,n,r,i,s);return f===a?e:{type:Se,size:e.size,array:$e(e.array,l,f)}}function mr(e,t,n,r,i,s){let l=gn(n,t),a=_r(e.bitmap,l);if((e.bitmap&l)!==0){let f=e.array[a];if(f.type!==re){let $=Rt(f,t+Ee,n,r,i,s);return $===f?e:{type:ae,bitmap:e.bitmap,array:$e(e.array,a,$)}}let c=f.k;return D(r,c)?i===f.v?e:{type:ae,bitmap:e.bitmap,array:$e(e.array,a,{type:re,k:r,v:i})}:(s.val=!0,{type:ae,bitmap:e.bitmap,array:$e(e.array,a,gi(t+Ee,c,f.v,n,r,i))})}else{let f=e.array.length;if(f>=co){let c=new Array(32),$=Vt(n,t);c[$]=mr($r,t+Ee,n,r,i,s);let _=0,x=e.bitmap;for(let g=0;g<32;g++){if((x&1)!==0){let S=e.array[_++];c[g]=S}x=x>>>1}return{type:Se,size:f+1,array:c}}else{let c=_o(e.array,a,{type:re,k:r,v:i});return s.val=!0,{type:ae,bitmap:e.bitmap|l,array:c}}}}function ho(e,t,n,r,i,s){if(n===e.hash){let l=hr(e,r);if(l!==-1)return e.array[l].v===i?e:{type:Ye,hash:n,array:$e(e.array,l,{type:re,k:r,v:i})};let a=e.array.length;return s.val=!0,{type:Ye,hash:n,array:$e(e.array,a,{type:re,k:r,v:i})}}return Rt({type:ae,bitmap:gn(e.hash,t),array:[e]},t,n,r,i,s)}function hr(e,t){let n=e.array.length;for(let r=0;r<n;r++)if(D(t,e.array[r].k))return r;return-1}function yn(e,t,n,r){switch(e.type){case Se:return wo(e,t,n,r);case ae:return xo(e,t,n,r);case Ye:return yo(e,r)}}function wo(e,t,n,r){let i=Vt(n,t),s=e.array[i];if(s!==void 0){if(s.type!==re)return yn(s,t+Ee,n,r);if(D(r,s.k))return s}}function xo(e,t,n,r){let i=gn(n,t);if((e.bitmap&i)===0)return;let s=_r(e.bitmap,i),l=e.array[s];if(l.type!==re)return yn(l,t+Ee,n,r);if(D(r,l.k))return l}function yo(e,t){let n=hr(e,t);if(!(n<0))return e.array[n]}function wr(e,t,n,r){switch(e.type){case Se:return go(e,t,n,r);case ae:return bo(e,t,n,r);case Ye:return vo(e,r)}}function go(e,t,n,r){let i=Vt(n,t),s=e.array[i];if(s===void 0)return e;let l;if(s.type===re){if(!D(s.k,r))return e}else if(l=wr(s,t+Ee,n,r),l===s)return e;if(l===void 0){if(e.size<=po){let a=e.array,f=new Array(e.size-1),c=0,$=0,_=0;for(;c<i;){let x=a[c];x!==void 0&&(f[$]=x,_|=1<<c,++$),++c}for(++c;c<a.length;){let x=a[c];x!==void 0&&(f[$]=x,_|=1<<c,++$),++c}return{type:ae,bitmap:_,array:f}}return{type:Se,size:e.size-1,array:$e(e.array,i,l)}}return{type:Se,size:e.size,array:$e(e.array,i,l)}}function bo(e,t,n,r){let i=gn(n,t);if((e.bitmap&i)===0)return e;let s=_r(e.bitmap,i),l=e.array[s];if(l.type!==re){let a=wr(l,t+Ee,n,r);return a===l?e:a!==void 0?{type:ae,bitmap:e.bitmap,array:$e(e.array,s,a)}:e.bitmap===i?void 0:{type:ae,bitmap:e.bitmap^i,array:cr(e.array,s)}}return D(r,l.k)?e.bitmap===i?void 0:{type:ae,bitmap:e.bitmap^i,array:cr(e.array,s)}:e}function vo(e,t){let n=hr(e,t);if(n<0)return e;if(e.array.length!==1)return{type:Ye,hash:e.hash,array:cr(e.array,n)}}function bi(e,t){if(e===void 0)return;let n=e.array,r=n.length;for(let i=0;i<r;i++){let s=n[i];if(s!==void 0){if(s.type===re){t(s.v,s.k);continue}bi(s,t)}}}var ye=class e{static fromObject(t){let n=Object.keys(t),r=e.new();for(let i=0;i<n.length;i++){let s=n[i];r=r.set(s,t[s])}return r}static fromMap(t){let n=e.new();return t.forEach((r,i)=>{n=n.set(i,r)}),n}static new(){return new e(void 0,0)}constructor(t,n){this.root=t,this.size=n}get(t,n){if(this.root===void 0)return n;let r=yn(this.root,0,pe(t),t);return r===void 0?n:r.v}set(t,n){let r={val:!1},i=this.root===void 0?$r:this.root,s=Rt(i,0,pe(t),t,n,r);return s===this.root?this:new e(s,r.val?this.size+1:this.size)}delete(t){if(this.root===void 0)return this;let n=wr(this.root,0,pe(t),t);return n===this.root?this:n===void 0?e.new():new e(n,this.size-1)}has(t){return this.root===void 0?!1:yn(this.root,0,pe(t),t)!==void 0}entries(){if(this.root===void 0)return[];let t=[];return this.forEach((n,r)=>t.push([r,n])),t}forEach(t){bi(this.root,t)}hashCode(){let t=0;return this.forEach((n,r)=>{t=t+fr(pe(n),pe(r))|0}),t}equals(t){if(!(t instanceof e)||this.size!==t.size)return!1;try{return this.forEach((n,r)=>{if(!D(t.get(r,!n),n))throw xi}),!0}catch(n){if(n===xi)return!1;throw n}}},xi=Symbol();function xr(e){return jn(e)===0}function _e(e,t,n){return vi(t,n,e)}function jo(e,t){for(;;){let n=e,r=t;if(n instanceof y)return r;{let i=n.tail,s=n.head[0],l=n.head[1];e=i,t=_e(r,s,l)}}}function bn(e){return jo(e,ee())}function ko(e,t){for(;;){let n=e,r=t;if(n instanceof y)return r;{let i=n.head;e=n.tail,t=F(i,r)}}}function So(e,t){for(;;){let n=e,r=t;if(n instanceof y)return ko(r,w([]));{let i=n.tail,s=n.head[0];e=i,t=F(s,r)}}}function vn(e){return So(it(e),w([]))}function Eo(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return i;{let l=r.tail,a=r.head[0],f=r.head[1];e=l,t=s(i,a,f),n=s}}}function me(e,t,n){return Eo(it(e),t,n)}function zo(e,t){for(;;){let n=e,r=t;if(n instanceof y)return r;e=n.tail,t=r+1}}function he(e){return zo(e,0)}function Ao(e,t){for(;;){let n=e,r=t;if(n instanceof y)return r;{let i=n.head;e=n.tail,t=F(i,r)}}}function be(e){return Ao(e,w([]))}function Ke(e){return D(e,w([]))}function st(e,t){for(;;){let n=e,r=t;if(n instanceof y)return!1;{let i=n.head;if(D(i,r))return!0;e=n.tail,t=r}}}function Oo(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return be(s);{let l=r.head,a=r.tail,f;i(l)?f=F(l,s):f=s;let $=f;e=a,t=i,n=$}}}function kn(e,t){return Oo(e,t,w([]))}function Co(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return be(s);{let l=r.head,a=r.tail,f,c=i(l);if(c instanceof o){let _=c[0];f=F(_,s)}else f=s;let $=f;e=a,t=i,n=$}}}function ie(e,t){return Co(e,t,w([]))}function Bo(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return be(s);{let l=r.head;e=r.tail,t=i,n=F(i(l),s)}}}function Ne(e,t){return Bo(e,t,w([]))}function Mo(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return new o(be(s));{let l=r.head,a=r.tail,f=i(l);if(f instanceof o){let c=f[0];e=a,t=i,n=F(c,s)}else return f}}}function qe(e,t){return Mo(e,t,w([]))}function Do(e,t){for(;;){let n=e,r=t;if(n instanceof y)return r;{let i=n.head;e=n.tail,t=F(i,r)}}}function ki(e,t){return Do(be(e),t)}function Sn(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return i;{let l=r.head;e=r.tail,t=s(i,l),n=s}}}function Lo(e,t,n,r){for(;;){let i=e,s=t,l=n,a=r;if(i instanceof y)return s;{let f=i.head;e=i.tail,t=l(s,f,a),n=l,r=a+1}}}function ot(e,t,n){return Lo(e,t,n,0)}function K(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return new o(i);{let l=r.head,a=r.tail,f=s(i,l);if(f instanceof o){let c=f[0];e=a,t=c,n=s}else return f}}}function Si(e,t){for(;;){let n=e,r=t;if(n instanceof y)return new u(void 0);{let i=n.head,s=n.tail;if(r(i))return new o(i);e=s,t=r}}}function En(e,t){for(;;){let n=e,r=t;if(n instanceof y)return!1;{let i=n.head,s=n.tail,l=r(i);if(l)return l;e=s,t=r}}}function Ei(e){for(;;){let t=e;if(t instanceof y)return new u(void 0);{let n=t.tail;if(n instanceof y){let r=t.head;return new o(r)}else e=n}}}var De=class extends v{constructor(t,n,r){super(),this.expected=t,this.found=n,this.path=r}};var we=class extends v{constructor(t){super(),this.function=t}};function j(e,t){let n=t.function(e),r,i;return r=n[0],i=n[1],i instanceof y?new o(r):new u(i)}function Io(e){return[e,w([])]}function No(e,t){return new we(n=>{let r=e.function(n),i,s;return i=r[0],s=r[1],[t(i),s]})}function qo(e,t,n){for(;;){let r=e,i=t,s=n;if(s instanceof y)return i;{let l=s.head,a=s.tail,f=l.function(r),c,$;if(c=f,$=f[1],$ instanceof y)return c;e=r,t=i,n=a}}}function Uo(e,t){return new we(n=>{let r=e.function(n),i,s;return i=r,s=r[1],s instanceof y?i:qo(n,i,t)})}var se=new we(Io);function Oi(e,t){return w([new De(e,ge(t),w([]))])}function vr(e,t,n){let r=n(e);return r instanceof o?[r[0],w([])]:[r[0],w([new De(t,ge(e),w([]))])]}function Fo(e){return D(!0,e)?[!0,w([])]:D(!1,e)?[!1,w([])]:[!1,Oi("Bool",e)]}function Vo(e){return vr(e,"Int",Ti)}function Ro(e){return vr(e,"Float",Li)}var zn=new we(Fo),Ue=new we(Vo),Ci=new we(Ro);function Po(e){return vr(e,"String",Ii)}var L=new we(Po);function Jo(e,t,n,r,i){let s=r(t),l=s[1];if(l instanceof y){let a=s[0],f=i(n),c=f[1];if(c instanceof y){let $=f[0];return[_e(e[0],a,$),e[1]]}else{let $=c;return lt([ee(),$],w(["values"]))}}else{let a=l;return lt([ee(),a],w(["keys"]))}}function at(e,t){return new we(n=>{let r=Di(n);if(r instanceof o){let i=r[0];return me(i,[ee(),w([])],(s,l,a)=>s[1]instanceof y?Jo(s,l,a,e.function,t.function):s)}else return[ee(),Oi("Dict",n)]})}function ut(e){return new we(t=>Mi(t,e.function,(n,r)=>lt(n,w([r])),0,w([])))}function lt(e,t){let n=Uo(L,w([No(Ue,B)])),r=Ne(t,s=>{let l=s,a=j(l,n);return a instanceof o?a[0]:"<"+ge(l)+">"}),i=Ne(e[1],s=>new De(s.expected,s.found,ki(r,s.path)));return[e[0],i]}function Go(e,t,n,r,i){for(;;){let s=e,l=t,a=n,f=r,c=i;if(s instanceof y){let _=a(f);return lt(_,be(l))}else{let $=s.head,_=s.tail,x=Bi(f,$);if(x instanceof o){let g=x[0];if(g instanceof d){let S=g[0];e=_,t=F($,l),n=a,r=S,i=c}else return c(f,F($,l))}else{let g=x[0],S=a(f),E;E=S[0];let I=[E,w([new De(g,ge(f),w([]))])];return lt(I,be(l))}}}}function ft(e,t){return new we(n=>Go(e,w([]),t.function,n,(r,i)=>{let s=t.function(r),l;l=s[0];let a=[l,w([new De("Field","Nothing",w([]))])];return lt(a,be(i))}))}var kr=void 0,Ni={};function Y(e){return e}function Sr(e){return/^[-+]?(\d+)$/.test(e)?new o(parseInt(e)):new u(kr)}function B(e){return e.toString()}function G(e){if(e==="")return 0;let t=Er(e);if(t){let n=0;for(let r of t)n++;return n}else return e.match(/./gsu).length}function Gt(e){let t=Er(e);return t?Q.fromArray(Array.from(t).map(n=>n.segment)):Q.fromArray(e.match(/./gsu))}var qi;function Er(e){if(globalThis.Intl&&Intl.Segmenter)return qi||=new Intl.Segmenter,qi.segment(e)[Symbol.iterator]()}function zr(e,t){return Q.fromArray(e.split(t))}function Ui(e,t,n){return e.slice(t,t+n)}function An(e,t,n){if(n<=0||t>=e.length)return"";let r=Er(e);if(r){for(;t-- >0;)r.next();let i="";for(;n-- >0;){let s=r.next().value;if(s===void 0)break;i+=s.segment}return i}else return e.match(/./gsu).slice(t,t+n).join("")}function Fe(e,t){return e.indexOf(t)>=0}function Z(e,t){return e.startsWith(t)}function Oe(e,t){return e.endsWith(t)}var Fi=[" "," ",` 2 + `,"\v","\f","\r","\x85","\u2028","\u2029"].join(""),Iu=new RegExp(`^[${Fi}]*`),Nu=new RegExp(`[${Fi}]*$`);function On(e){return hn([_i(e)])}function Cn(e){return e.byteSize}function ee(){return ye.new()}function jn(e){return e.size}function it(e){return Q.fromArray(e.entries())}function ue(e,t){let n=e.get(t,Ni);return n===Ni?new u(kr):new o(n)}function vi(e,t,n){return n.set(e,t)}function Vi(e){try{let t=atob(e),n=t.length,r=new Uint8Array(n);for(let i=0;i<n;i++)r[i]=t.charCodeAt(i);return new o(new X(r))}catch{return new u(kr)}}function ge(e){if(typeof e=="string")return"String";if(typeof e=="boolean")return"Bool";if(e instanceof rt)return"Result";if(e instanceof Q)return"List";if(e instanceof X)return"BitArray";if(e instanceof ye)return"Dict";if(Number.isInteger(e))return"Int";if(Array.isArray(e))return"Array";if(typeof e=="number")return"Float";if(e===null)return"Nil";if(e===void 0)return"Nil";{let t=typeof e;return t.charAt(0).toUpperCase()+t.slice(1)}}function Zt(e){return new TextEncoder().encode(e).length}function Ri(e){return new jr().inspect(e)}function Pi(e){let t=e.toString().replace("+","");if(t.indexOf(".")>=0)return t;{let n=t.indexOf("e");return n>=0?t.slice(0,n)+".0"+t.slice(n):t+".0"}}var jr=class{#e=new Set;inspect(t){let n=typeof t;if(t===!0)return"True";if(t===!1)return"False";if(t===null)return"//js(null)";if(t===void 0)return"Nil";if(n==="string")return this.#s(t);if(n==="bigint"||Number.isInteger(t))return t.toString();if(n==="number")return Pi(t);if(t instanceof mn)return this.#o(t);if(t instanceof X)return this.#l(t);if(t instanceof RegExp)return`//js(${t})`;if(t instanceof Date)return`//js(Date("${t.toISOString()}"))`;if(t instanceof globalThis.Error)return`//js(${t.toString()})`;if(t instanceof Function){let i=[];for(let s of Array(t.length).keys())i.push(String.fromCharCode(s+97));return`//fn(${i.join(", ")}) { ... }`}if(this.#e.size===this.#e.add(t).size)return"//js(circular reference)";let r;if(Array.isArray(t))r=`#(${t.map(i=>this.inspect(i)).join(", ")})`;else if(t instanceof Q)r=this.#i(t);else if(t instanceof v)r=this.#r(t);else if(t instanceof ye)r=this.#n(t);else{if(t instanceof Set)return`//js(Set(${[...t].map(i=>this.inspect(i)).join(", ")}))`;r=this.#t(t)}return this.#e.delete(t),r}#t(t){let n=Object.getPrototypeOf(t)?.constructor?.name||"Object",r=[];for(let l of Object.keys(t))r.push(`${this.inspect(l)}: ${this.inspect(t[l])}`);let i=r.length?" "+r.join(", ")+" ":"";return`//js(${n==="Object"?"":n+" "}{${i}})`}#n(t){let n="dict.from_list([",r=!0;return t.forEach((i,s)=>{r||(n=n+", "),n=n+"#("+this.inspect(s)+", "+this.inspect(i)+")",r=!1}),n+"])"}#r(t){let n=Object.keys(t).map(r=>{let i=this.inspect(t[r]);return isNaN(parseInt(r))?`${r}: ${i}`:i}).join(", ");return n?`${t.constructor.name}(${n})`:t.constructor.name}#i(t){if(t instanceof y)return"[]";let n='charlist.from_string("',r="[",i=t;for(;i instanceof Te;){let s=i.head;i=i.tail,r!=="["&&(r+=", "),r+=this.inspect(s),n&&(Number.isInteger(s)&&s>=32&&s<=126?n+=String.fromCharCode(s):n=null)}return n?n+'")':r+"]"}#s(t){let n='"';for(let r=0;r<t.length;r++){let i=t[r];switch(i){case` 3 + `:n+="\\n";break;case"\r":n+="\\r";break;case" ":n+="\\t";break;case"\f":n+="\\f";break;case"\\":n+="\\\\";break;case'"':n+='\\"';break;default:i<" "||i>"~"&&i<"\xA0"?n+="\\u{"+i.charCodeAt(0).toString(16).toUpperCase().padStart(4,"0")+"}":n+=i}}return n+='"',n}#o(t){return`//utfcodepoint(${String.fromCodePoint(t.value)})`}#l(t){if(t.bitSize===0)return"<<>>";let n="<<";for(let r=0;r<t.byteSize-1;r++)n+=t.byteAt(r).toString(),n+=", ";if(t.byteSize*8===t.bitSize)n+=t.byteAt(t.byteSize-1).toString();else{let r=t.bitSize%8;n+=t.byteAt(t.byteSize-1)>>8-r,n+=`:size(${r})`}return n+=">>",n}};function Bi(e,t){if(e instanceof ye||e instanceof WeakMap||e instanceof Map){let r={},i=e.get(t,r);return i===r?new o(new A):new o(new d(i))}let n=Number.isInteger(t);if(n&&t>=0&&t<8&&e instanceof Q){let r=0;for(let i of e){if(r===t)return new o(new d(i));r++}return new u("Indexable")}return n&&Array.isArray(e)||e&&typeof e=="object"||e&&Object.getPrototypeOf(e)===Object.prototype?t in e?new o(new d(e[t])):new o(new A):new u(n?"Indexable":"Dict")}function Mi(e,t,n,r,i){if(!(e instanceof Q||Array.isArray(e))){let l=new De("List",ge(e),i);return[i,Q.fromArray([l])]}let s=[];for(let l of e){let a=t(l),[f,c]=a;if(c instanceof Te){let[$,_]=n(a,r.toString());return[i,_]}s.push(f),r++}return[Q.fromArray(s),i]}function Di(e){if(e instanceof ye)return new o(e);if(e instanceof Map||e instanceof WeakMap)return new o(ye.fromMap(e));if(e==null)return new u("Dict");if(typeof e!="object")return new u("Dict");let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null?new o(ye.fromObject(e)):new u("Dict")}function Li(e){return typeof e=="number"?new o(e):new u(0)}function Ti(e){return Number.isInteger(e)?new o(e):new u(0)}function Ii(e){return typeof e=="string"?new o(e):new u("")}function Ce(e){return e===""}function Wt(e,t,n){if(n<=0)return"";if(t<0){let s=G(e)+t;return s<0?"":An(e,s,n)}else return An(e,t,n)}function Ji(e,t){return t<=0?e:Wt(e,0,G(e)-t)}function Or(e,t){return e+t}function Xo(e,t,n){for(;;){let r=e,i=t,s=n,l;r%2===0?l=s:l=s+i;let f=l,c=globalThis.Math.trunc(r/2);if(c<=0)return f;e=c,t=i+i,n=f}}function Gi(e,t){return t<=0?"":Xo(t,e,"")}function Qo(e,t,n){for(;;){let r=e,i=t,s=n;if(r instanceof y)return s;{let l=r.head;e=r.tail,t=i,n=s+i+l}}}function Ve(e,t){if(e instanceof y)return"";{let n=e.head,r=e.tail;return Qo(r,t,n)}}function fe(e,t){if(t==="")return Gt(e);{let r=e,i=zr(r,t);return Ne(i,Y)}}function Ht(e){let n=Ri(e);return n}function Re(e,t){if(t<=0)return e;{let r=An(e,0,t),i=Zt(r);return Ui(e,i,Zt(e)-i)}}function Zi(e){let t,n=Cn(On(e))%4;return n===0?t=e:t=Or(e,Gi("=",4-n)),Vi(t)}function Wi(e){return e instanceof o}function Xe(e,t){if(e instanceof o)return e;{let n=e[0];return new u(t(n))}}function p(e,t){if(e instanceof o){let n=e[0];return t(n)}else return e}function Br(e){return JSON.stringify(e)}function Hi(e){return Object.fromEntries(e)}function Yi(e){let t=[];for(;di(e);)t.push(pi(e)),e=$i(e);return t}function Ki(){return null}function Xi(e){try{let t=JSON.parse(e);return mi(t)}catch(t){return hi(tl(t,e))}}function tl(e,t){return nl(e)?Qi():rl(e,t)}function nl(e){return/((unexpected (end|eof))|(end of data)|(unterminated string)|(json( parse error|\.parse)\: expected '(\:|\}|\])'))/i.test(e.message)}function rl(e,t){let n=[il,sl,ll,ol];for(let r of n){let i=r(e,t);if(i)return i}return ct("")}function il(e){let n=/unexpected token '(.)', ".+" is not valid JSON/i.exec(e.message);if(!n)return null;let r=Bn(n[1]);return ct(r)}function sl(e){let n=/unexpected token (.) in JSON at position (\d+)/i.exec(e.message);if(!n)return null;let r=Bn(n[1]);return ct(r)}function ol(e,t){let r=/(unexpected character|expected .*) at line (\d+) column (\d+)/i.exec(e.message);if(!r)return null;let i=Number(r[2]),s=Number(r[3]),l=al(i,s,t),a=Bn(t[l]);return ct(a)}function ll(e){let n=/unexpected (identifier|token) "(.)"/i.exec(e.message);if(!n)return null;let r=Bn(n[2]);return ct(r)}function Bn(e){return"0x"+e.charCodeAt(0).toString(16).toUpperCase()}function al(e,t,n){if(e===1)return t-1;let r=1,i=0;return n.split("").find((s,l)=>(s===` 4 + `&&(r+=1),r===e?(i=l+t,!0):!1)),i}var Mr=class extends v{},Qi=()=>new Mr;var Dr=class extends v{constructor(t){super(),this[0]=t}},ct=e=>new Dr(e);var Lr=class extends v{constructor(t){super(),this[0]=t}};function ul(e,t){return p(Xi(e),n=>{let r=j(n,t);return Xe(r,i=>new Lr(i))})}function Mn(e,t){return ul(e,t)}function je(e){return Br(e)}function es(e){return e}function ts(e){return e}function ns(e){return e}function rs(e){return e}function is(){return Ki()}function Ir(e){return Hi(e)}function fl(e){return Yi(e)}function Nr(e,t){let r=Ne(e,t);return fl(r)}var pt=class extends v{constructor(t){super(),this.collection=t}};var $t=class extends v{constructor(t){super(),this.message=t}};var qr=class extends v{constructor(t){super(),this.message=t}};function Ur(e){return e instanceof pt?"Lexicon not found for collection: "+e.collection:e instanceof $t?"Invalid lexicon schema: "+e.message:"Data validation failed: "+e.message}function m(e){return new $t(e)}function h(e){return new qr(e)}function Fr(e){return new pt(e)}function ce(e){let t=je(e),n=Mn(t,se);return Xe(n,r=>"Failed to parse JSON")}function _t(e){return je(e)==="null"}function Pe(e){let t=ce(e);if(t instanceof o){let n=t[0];return j(n,L)instanceof o}else return!1}function mt(e){let t=ce(e);if(t instanceof o){let n=t[0];return j(n,Ue)instanceof o}else return!1}function ht(e){let t=ce(e);if(t instanceof o){let n=t[0];return j(n,zn)instanceof o}else return!1}function Yt(e){let t=ce(e);if(t instanceof o){let n=t[0];return j(n,ut(se))instanceof o}else return!1}function q(e){let t=ce(e);if(t instanceof o){let n=t[0];return j(n,at(L,se))instanceof o}else return!1}function k(e,t){let n=ce(e);if(n instanceof o){let r=n[0],i=j(r,ft(w([t]),L));if(i instanceof o){let s=i[0];return new d(s)}else return new A}else return new A}function M(e,t){let n=ce(e);if(n instanceof o){let r=n[0],i=j(r,ft(w([t]),Ue));if(i instanceof o){let s=i[0];return new d(s)}else return new A}else return new A}function Je(e,t){let n=ce(e);if(n instanceof o){let r=n[0],i=j(r,ft(w([t]),zn));if(i instanceof o){let s=i[0];return new d(s)}else return new A}else return new A}function T(e,t){let n=ce(e);if(n instanceof o){let r=n[0],i=j(r,ft(w([t]),ut(se)));if(i instanceof o){let s=i[0];return new d(s)}else return new A}else return new A}function z(e){let t=ce(e);if(t instanceof o){let n=t[0],r=j(n,at(L,se));if(r instanceof o){let i=r[0];return vn(i)}else return w([])}else return w([])}function Vr(e){let t=ce(e);if(t instanceof o){let n=t[0],r=j(n,ut(se));if(r instanceof o){let i=r[0];return new d(i)}else return new A}else return new A}function ss(e){return ge(e)==="Nil"}function ke(e){let t=ce(e);if(t instanceof o){let n=t[0],r=j(n,at(L,se));return r instanceof o?r:new u(h("Failed to convert JSON to dictionary"))}else return new u(h("Failed to parse JSON as dynamic"))}function te(e){let t=ge(e);if(t==="Nil")return new o(is());if(t==="String"){let n=j(e,L);if(n instanceof o){let r=n[0];return new o(es(r))}else return new u(h("Failed to decode string"))}else if(t==="Int"){let n=j(e,Ue);if(n instanceof o){let r=n[0];return new o(ns(r))}else return new u(h("Failed to decode int"))}else if(t==="Float"){let n=j(e,Ci);if(n instanceof o){let r=n[0];return new o(rs(r))}else return new u(h("Failed to decode float"))}else if(t==="Bool"){let n=j(e,zn);if(n instanceof o){let r=n[0];return new o(ts(r))}else return new u(h("Failed to decode bool"))}else if(t==="List"){let n=j(e,ut(se));if(n instanceof o){let r=n[0],i=qe(r,te);if(i instanceof o){let s=i[0];return new o(Nr(s,l=>l))}else return i}else return new u(h("Failed to decode list"))}else if(t==="Array"){let n=j(e,ut(se));if(n instanceof o){let r=n[0],i=qe(r,te);if(i instanceof o){let s=i[0];return new o(Nr(s,l=>l))}else return i}else return new u(h("Failed to decode list"))}else if(t==="Dict"){let n=j(e,at(L,se));if(n instanceof o){let r=n[0],i=it(r),s=qe(i,l=>{let a,f;a=l[0],f=l[1];let c=te(f);if(c instanceof o){let $=c[0];return new o([a,$])}else return c});if(s instanceof o){let l=s[0];return new o(Ir(l))}else return s}else return new u(h("Failed to decode dict"))}else if(t==="Object"){let n=j(e,at(L,se));if(n instanceof o){let r=n[0],i=it(r),s=qe(i,l=>{let a,f;a=l[0],f=l[1];let c=te(f);if(c instanceof o){let $=c[0];return new o([a,$])}else return c});if(s instanceof o){let l=s[0];return new o(Ir(l))}else return s}else return new u(h("Failed to decode dict"))}else{let n=t;return new u(h("Unsupported type for JSON conversion: "+n))}}function C(e,t){let n=ce(e);if(n instanceof o){let r=n[0],i=j(r,ft(w([t]),se));if(i instanceof o){let s=i[0],l=te(s);if(l instanceof o){let a=l[0];return new d(a)}else return new A}else return new A}else return new A}function Dn(){return ee()}function Qe(e,t){return ue(e,t)instanceof o}function Ln(e,t,n){return me(e,t,n)}var Tn=class extends v{constructor(t,n){super(),this.id=t,this.defs=n}};var wt=class extends v{};var xt=class extends v{};var yt=class extends v{};var gt=class extends v{};var bt=class extends v{};var vt=class extends v{};var jt=class extends v{};var kt=class extends v{};var St=class extends v{};var Et=class extends v{};var Rr=class extends v{};function Pr(e){return e==="datetime"?new o(new wt):e==="uri"?new o(new xt):e==="at-uri"?new o(new yt):e==="did"?new o(new gt):e==="handle"?new o(new bt):e==="at-identifier"?new o(new vt):e==="nsid"?new o(new jt):e==="cid"?new o(new kt):e==="language"?new o(new St):e==="tid"?new o(new Et):e==="record-key"?new o(new Rr):new u(void 0)}function In(e){return e instanceof wt?"datetime":e instanceof xt?"uri":e instanceof yt?"at-uri":e instanceof gt?"did":e instanceof bt?"handle":e instanceof vt?"at-identifier":e instanceof jt?"nsid":e instanceof kt?"cid":e instanceof St?"language":e instanceof Et?"tid":"record-key"}var qn=class extends v{constructor(t){super(),this.dict=t}};function Jr(){return new qn(ee())}function Gr(e,t){let n=e.dict,r=ue(n,t);return Wi(r)}var cl=void 0;function Zr(e,t){return new qn(_e(e.dict,t,cl))}function ls(e,t){return e.lastIndex=0,e.test(t)}function as(e,t){try{let n="gu";return t.case_insensitive&&(n+="i"),t.multi_line&&(n+="m"),new o(new RegExp(e,n))}catch(n){let r=(n.columnNumber||0)|0;return new u(new Un(n.message,r))}}var Un=class extends v{constructor(t,n){super(),this.error=t,this.byte_index=n}};var Wr=class extends v{constructor(t,n){super(),this.case_insensitive=t,this.multi_line=n}};function dl(e,t){return as(e,t)}function Be(e){return dl(e,new Wr(!1,!1))}function Me(e,t){return ls(e,t)}var Xt=class extends v{constructor(t,n){super(),this.seconds=t,this.nanoseconds=n}};function wl(e){let t=1e9,n=Ut(e.nanoseconds,t),r=e.nanoseconds-n,i=e.seconds+Ft(r,t);return n>=0?new Xt(i,n):new Xt(i-1,t+n)}function xl(e){return e%4===0&&(e%100!==0||e%400===0)}function yl(e){if(e.bitSize>=8)if(e.byteAt(0)===43)if((e.bitSize-8)%8===0){let t=le(e,8);return new o(["+",t])}else return new u(void 0);else if(e.byteAt(0)===45&&(e.bitSize-8)%8===0){let t=le(e,8);return new o(["-",t])}else return new u(void 0);else return new u(void 0)}function Kt(e,t){if(e.bitSize>=8&&(e.bitSize-8)%8===0)if(e.byteAt(0)===t){let r=le(e,8);return new o(r)}else return new u(void 0);else return new u(void 0)}function gl(e){return e.bitSize===0?new o(void 0):new u(void 0)}function bl(e,t,n){let r=globalThis.Math.trunc((14-t)/12),i=e+4800-r,s=t+12*r-3;return n+globalThis.Math.trunc((153*s+2)/5)+365*i+globalThis.Math.trunc(i/4)-globalThis.Math.trunc(i/100)+globalThis.Math.trunc(i/400)-32045}var vl=86400,cs=3600,ds=60;function jl(e,t,n){let r=t*cs+n*ds;return e==="-"?-r:r}function kl(e,t,n,r,i,s){return bl(e,t,n)*vl+r*cs+i*ds+s}var Sl=1e9,Yr=58,fs=45;function El(e,t,n){for(;;){let r=e,i=t,s=n,l=globalThis.Math.trunc(s/10);if(r.bitSize>=8&&(r.bitSize-8)%8===0){let a=r.byteAt(0);if(48<=a&&a<=57&&l<1)e=le(r,8),t=i,n=l;else{let f=r.byteAt(0);if(48<=f&&f<=57){let c=le(r,8),$=f-48;e=c,t=i+$*l,n=l}else return new o([i,r])}}else return new o([i,r])}}function zl(e){if(e.bitSize>=8&&e.byteAt(0)===46)if(e.bitSize>=16&&(e.bitSize-16)%8===0){let t=e.byteAt(1);if(48<=t&&t<=57){let n=le(e,16);return El(hn([t,n]),0,Sl)}else return(e.bitSize-8)%8===0?new u(void 0):new o([0,e])}else return(e.bitSize-8)%8===0?new u(void 0):new o([0,e]);else return new o([0,e])}function Al(e,t,n,r){for(;;){let i=e,s=t,l=n,a=r;if(a>=s)return new o([l,i]);if(i.bitSize>=8&&(i.bitSize-8)%8===0){let f=i.byteAt(0);if(48<=f&&f<=57)e=le(i,8),t=s,n=l*10+(f-48),r=a+1;else return new u(void 0)}else return new u(void 0)}}function zt(e,t){return Al(e,t,0,0)}function Ol(e){return zt(e,4)}function Cl(e){return p(zt(e,2),t=>{let n,r;return n=t[0],r=t[1],1<=n&&n<=12?new o([n,r]):new u(void 0)})}function Bl(e,t,n){return p(zt(e,2),r=>{let i,s;return i=r[0],s=r[1],p(n===1?new o(31):n===3?new o(31):n===5?new o(31):n===7?new o(31):n===8?new o(31):n===10?new o(31):n===12?new o(31):n===4?new o(30):n===6?new o(30):n===9?new o(30):n===11?new o(30):n===2?xl(t)?new o(29):new o(28):new u(void 0),l=>1<=i&&i<=l?new o([i,s]):new u(void 0))})}function ps(e){return p(zt(e,2),t=>{let n,r;return n=t[0],r=t[1],0<=n&&n<=23?new o([n,r]):new u(void 0)})}function $s(e){return p(zt(e,2),t=>{let n,r;return n=t[0],r=t[1],0<=n&&n<=59?new o([n,r]):new u(void 0)})}function Ml(e){return p(zt(e,2),t=>{let n,r;return n=t[0],r=t[1],0<=n&&n<=60?new o([n,r]):new u(void 0)})}function Hr(e){return p(yl(e),t=>{let n,r;return n=t[0],r=t[1],p(ps(r),i=>{let s,l;return s=i[0],l=i[1],p(Kt(l,Yr),a=>p($s(a),f=>{let c,$;c=f[0],$=f[1];let _=jl(n,s,c);return new o([_,$])}))})})}function Dl(e){if(e.bitSize>=8)if(e.byteAt(0)===90)if((e.bitSize-8)%8===0){let t=le(e,8);return new o([0,t])}else return Hr(e);else if(e.byteAt(0)===122&&(e.bitSize-8)%8===0){let t=le(e,8);return new o([0,t])}else return Hr(e);else return Hr(e)}function Ll(e){if(e.bitSize>=8&&(e.bitSize-8)%8===0){let t=e.byteAt(0);if(t===84||t===116||t===32){let n=le(e,8);return new o(n)}else return new u(void 0)}else return new u(void 0)}var Tl=210866803200;function Il(e,t,n,r,i,s,l,a){let c=kl(e,t,n,r,i,s)-Tl,$=new Xt(c-a,l);return wl($)}function _s(e){let t=On(e);return p(Ol(t),n=>{let r,i;return r=n[0],i=n[1],p(Kt(i,fs),s=>p(Cl(s),l=>{let a,f;return a=l[0],f=l[1],p(Kt(f,fs),c=>p(Bl(c,r,a),$=>{let _,x;return _=$[0],x=$[1],p(Ll(x),g=>p(ps(g),S=>{let E,I;return E=S[0],I=S[1],p(Kt(I,Yr),xe=>p($s(xe),H=>{let J,de;return J=H[0],de=H[1],p(Kt(de,Yr),We=>p(Ml(We),Le=>{let ir,_n;return ir=Le[0],_n=Le[1],p(zl(_n),Nt=>{let qt,He;return qt=Nt[0],He=Nt[1],p(Dl(He),si=>{let oi,li;return oi=si[0],li=si[1],p(gl(li),iu=>new o(Il(r,a,_,E,J,ir,qt,oi)))})})}))}))}))}))}))})}function ql(e){let t=G(e);if(t===0||t>64)return!1;{let i=Be("^[0-9]{4}-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9](\\.[0-9]{1,20})?(Z|([+-][0-2][0-9]:[0-5][0-9]))$");if(i instanceof o){let s=i[0],l=Me(s,e);return l&&(Oe(e,"-00:00")?!1:_s(e)instanceof o)}else return!1}}function Ul(e){let t=G(e);if(t===0||t>8192)return!1;{let i=Be("^[a-z][a-z.-]{0,80}:[!-~]+$");if(i instanceof o){let s=i[0];return Me(s,e)}else return!1}}function Qt(e){let t=G(e);if(t===0||t>2048)return!1;{let r=Z(e,"did:");if(r){let s=Be("^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$");if(s instanceof o){let l=s[0];return Me(l,e)}else return!1}else return r}}function en(e){let t="^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$",n=G(e)===0||G(e)>253,r=Be(t);if(n)return!1;if(r instanceof o){let i=r[0],s=Me(i,e);if(s){let l=fe(e,"."),a=Ei(l);if(a instanceof o){let f=a[0];return f==="local"||f==="arpa"||f==="invalid"||f==="localhost"||f==="internal"||f==="example"||f==="onion"?!1:f!=="alt"}else return!1}else return s}else return n}function Fl(e){return Qt(e)||en(e)}function et(e){let n=Be("^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$");if(n instanceof o){let r=n[0],i=Me(r,e);if(i){let s=fe(e,".");return he(s)>=3&&G(e)<=317}else return i}else return!1}function Fn(e){let t=G(e);if(t<8||t>256)return!1;if(Z(e,"Qmb"))return!1;{let s=Be("^[a-zA-Z0-9+=]{8,256}$");if(s instanceof o){let l=s[0];return Me(l,e)}else return!1}}function ms(e){let t=Fn(e);return t&&Z(e,"bafkrei")}function Vl(e){let t=G(e);if(t===0||t>128)return!1;{let i=Be("^(i|[a-z]{2,3})(-[a-zA-Z0-9]+)*$");if(i instanceof o){let s=i[0];return Me(s,e)}else return!1}}function hs(e){let t="^[234567abcdefghij][234567abcdefghijklmnopqrstuvwxyz]{12}$",n=G(e)===13,r=Be(t);if(n&&r instanceof o){let i=r[0];return Me(i,e)}else return!1}function ws(e){let t=G(e);if(e==="."||e==="..")return!1;{let r=t>=1&&t<=512;if(r){let i=hs(e);if(i)return i;{let l=Be("^[a-zA-Z0-9_~.:-]+$");if(l instanceof o){let a=l[0];return Me(a,e)}else return!1}}else return r}}function Rl(e){let t=G(e);if(t===0||t>8192)return!1;{let r=Z(e,"at://");if(r){let i=Re(e,5),s=fe(i,"/");if(s instanceof y)return!1;{let l=s.tail;if(l instanceof y){let a=s.head;return Qt(a)||en(a)}else{let a=l.tail;if(a instanceof y){let f=s.head,c=l.head,$=Qt(f)||en(f);return $&&et(c)}else if(a.tail instanceof y){let c=s.head,$=l.head,_=a.head,x=Qt(c)||en(c);if(x){let g=et($);return g&&ws(_)}else return x}else return!1}}}else return r}}function Vn(e,t){return t instanceof wt?ql(e):t instanceof xt?Ul(e):t instanceof yt?Rl(e):t instanceof gt?Qt(e):t instanceof bt?en(e):t instanceof vt?Fl(e):t instanceof jt?et(e):t instanceof kt?Fn(e):t instanceof St?Vl(e):t instanceof Et?hs(e):ws(e)}var At=class extends v{constructor(t,n,r,i,s){super(),this.lexicons=t,this.path=n,this.current_lexicon_id=r,this.reference_stack=i,this.validator=s}};var Rn=class extends v{constructor(t,n){super(),this.lexicons=t,this.validator=n}};function Kr(){return new Rn(ee(),new A)}function Xr(e){let t,n=e.validator;n instanceof d?t=n[0]:t=(i,s,l)=>new o(void 0);let r=t;return new o(new At(e.lexicons,"",new A,Jr(),r))}function Pn(e,t){let n=ue(e.lexicons,t);if(n instanceof o){let r=n[0];return new d(r)}else return new A}function b(e){return e.path}function N(e,t){let n;e.path===""?n=t:n=e.path+"."+t;let i=n;return new At(e.lexicons,i,e.current_lexicon_id,e.reference_stack,e.validator)}function Ot(e){return e.current_lexicon_id}function nn(e,t){return new At(e.lexicons,e.path,new d(t),e.reference_stack,e.validator)}function xs(e,t){return new At(e.lexicons,e.path,e.current_lexicon_id,Zr(e.reference_stack,t),e.validator)}function Qr(e,t){return Gr(e.reference_stack,t)}function ys(e,t){let n=fe(t,"#");if(n instanceof y)return new u(m("Invalid reference format: "+t));{let r=n.tail;if(r instanceof y){let i=n.head;return i!==""?new o([i,"main"]):new u(m("Invalid reference format: "+t))}else if(r.tail instanceof y){let s=n.head;if(s===""){let l=r.head,a=e.current_lexicon_id;if(a instanceof d){let f=a[0];return new o([f,l])}else return new u(m("Local reference '"+t+"' used without current lexicon context"))}else{let l=s,a=r.head;return l!==""&&a!==""?new o([l,a]):new u(m("Invalid reference format: "+t))}}else return new u(m("Invalid reference format: "+t))}}function Pl(e){let t,n=k(e,"id");if(n instanceof d){let i=n[0];t=new o(i)}else t=new u(m("Lexicon missing required 'id' field"));return p(t,i=>p(et(i)?new o(void 0):new u(m("Lexicon 'id' field is not a valid NSID: "+i)),s=>{let l,a=C(e,"defs");if(a instanceof d){let c=a[0];q(c)?l=new o(c):l=new u(m("Lexicon 'defs' must be an object at "+i))}else l=new u(m("Lexicon missing required 'defs' field at "+i));return p(l,c=>new o(new Tn(i,c)))}))}function ei(e,t){return K(t,e,(n,r)=>{let i=Pl(r);if(i instanceof o){let s=i[0],l=_e(n.lexicons,s.id,s);return new o(new Rn(l,n.validator))}else return i})}function ti(e,t,n,r,i){let s;if(n instanceof d){let a=n[0];t<a?s=new u(h(e+": "+i+" length "+B(t)+" is less than minLength "+B(a))):s=new o(void 0)}else s=new o(void 0);return p(s,a=>{if(r instanceof d){let f=r[0];return t>f?new u(h(e+": "+i+" length "+B(t)+" exceeds maxLength "+B(f))):new o(void 0)}else return new o(void 0)})}function tt(e,t,n,r){if(t instanceof d&&n instanceof d){let i=t[0],s=n[0];return i>s?new u(m(e+": "+r+" minLength ("+B(i)+") cannot be greater than maxLength ("+B(s)+")")):new o(void 0)}else return new o(void 0)}function gs(e,t,n,r){let i;if(n instanceof d){let l=n[0];t<l?i=new u(h(e+": value "+B(t)+" is less than minimum "+B(l))):i=new o(void 0)}else i=new o(void 0);return p(i,l=>{if(r instanceof d){let a=r[0];return t>a?new u(h(e+": value "+B(t)+" exceeds maximum "+B(a))):new o(void 0)}else return new o(void 0)})}function bs(e,t,n){if(t instanceof d&&n instanceof d){let r=t[0],i=n[0];return r>i?new u(m(e+": minimum ("+B(r)+") cannot be greater than maximum ("+B(i)+")")):new o(void 0)}else return new o(void 0)}function Jn(e,t,n,r,i,s){return En(n,a=>s(t,a))?new o(void 0):new u(h(e+": "+r+" value '"+i(t)+"' is not in enum"))}function Ct(e,t,n,r){return t&&n?new u(m(e+": "+r+" cannot have both 'const' and 'default'")):new o(void 0)}function O(e,t,n,r){let i=kn(t,s=>!st(n,s));if(i instanceof y)return new o(void 0);{let s=i;return new u(m(e+": "+r+" has unknown fields: "+Ve(s,", ")+". Allowed fields: "+Ve(n,", ")))}}function Bt(e,t,n){let r=nn(t,n),i=ys(r,e);if(i instanceof o){let s=i[0][0],l=i[0][1],a=Pn(r,s);if(a instanceof d){let f=a[0],c=C(f.defs,l);if(c instanceof d){let $=c[0];return new o(new d($))}else return new u(m("Definition '"+l+"' not found in lexicon '"+s+"'"))}else return new u(m("Referenced lexicon not found: "+s))}else return i}function Gn(e,t,n){let r=b(n);return p((()=>{let i=k(t,"ref");if(i instanceof d){let s=i[0];return new o(s)}else return new u(h(r+": ref schema missing 'ref' field"))})(),i=>{if(Qr(n,i))return new u(h(r+": circular reference detected: "+i));{let l=xs(n,i);return p((()=>{let a=Ot(l);if(a instanceof d){let f=a[0];return new o(f)}else return new u(h(r+": no current lexicon set for resolving reference"))})(),a=>p(Bt(i,l,a),f=>p((()=>{if(f instanceof d){let c=f[0];return new o(c)}else return new u(h(r+": reference not found: "+i))})(),c=>{let $=l.validator;return $(e,c,l)})))}})}function Jl(e,t){let n=fe(e,"#");if(n instanceof y)return new u(m(t+": global reference can only contain one # character"));{let r=n.tail;if(r instanceof y)return new u(m(t+": global reference can only contain one # character"));if(r.tail instanceof y){let s=n.head,l=r.head;return Ce(s)?new u(m(t+": NSID part of reference cannot be empty")):Ce(l)?new u(m(t+": definition name part of reference cannot be empty")):new o(void 0)}else return new u(m(t+": global reference can only contain one # character"))}}function Gl(e,t){if(Ce(e))return new u(m(t+": reference cannot be empty"));if(Z(e,"#")){let i=Re(e,1);return Ce(i)?new u(m(t+": local reference must have a definition name after #")):new o(void 0)}else return Fe(e,"#")?Jl(e,t):new o(void 0)}var Zl=w(["type","ref","description"]);function rn(e,t){let n=b(t),r=z(e);return p(O(n,r,Zl,"ref"),i=>{let s,l=k(e,"ref");if(l instanceof d){let f=l[0];s=new o(f)}else s=new u(m(n+": ref missing required 'ref' field"));return p(s,f=>p(Gl(f,n),c=>{if(Z(f,"#"))return new o(void 0);{let _=Ot(t);if(_ instanceof d){let x=_[0];return p(Bt(f,t,x),g=>g instanceof d?new o(void 0):new u(m(n+": reference not found: "+f)))}else return new o(void 0)}}))})}function Wl(e,t,n){let r=ie(e,i=>j(i,L));return K(r,void 0,(i,s)=>{let l=Ot(t);if(l instanceof d){let a=l[0];return p(Bt(s,t,a),f=>f instanceof d?new o(void 0):new u(m(n+": reference not found: "+s)))}else return new o(void 0)})}function Hl(e,t,n,r){let i=Ot(n);if(i instanceof d){let s=i[0];return p(Bt(t,n,s),l=>{if(l instanceof d){let a=l[0],f=n.validator;return f(e,a,n)}else return new u(h(r+": reference not found: "+t))})}else return new o(void 0)}function Yl(e,t){let n=e===t;if(n)return n;if(Z(e,"#")){let i=Re(e,1),s=t===i;return s||Oe(t,"#"+i)}else if(Oe(t,"#main")){let s=Ji(t,5);return e===s}else{if(Fe(t,"#"))return!1;{let l=t+"#main";return e===l}}}function Kl(e){return _t(e)?"null":ht(e)?"boolean":mt(e)?"number":Pe(e)?"string":Yt(e)?"array":q(e)?"object":"unknown"}function Zn(e,t,n){let r=b(n);if(q(e)){let s,l=k(e,"$type");if(l instanceof d){let f=l[0];s=new o(f)}else s=new u(h(r+': union data must be an object which includes the "$type" property'));return p(s,f=>{let c,$=T(t,"refs");if($ instanceof d){let x=$[0];c=new o(x)}else c=new u(h(r+": union schema missing or invalid 'refs' field"));return p(c,x=>{if(Ke(x))return new u(h(r+": union schema has empty refs array"));{let S=ie(x,I=>j(I,L)),E=Si(S,I=>Yl(I,f));if(E instanceof o){let I=E[0];return Hl(e,I,n,r)}else{let I,xe=Je(t,"closed");return xe instanceof d?I=xe[0]:I=!1,I?new u(h(r+": union data $type must be one of "+Ve(S,", ")+", found '"+f+"'")):new o(void 0)}}})})}else{let s=Kl(e);return new u(h(r+': union data must be an object which includes the "$type" property, found '+s))}}var Xl=w(["type","refs","closed","description"]);function Wn(e,t){let n=b(t),r=z(e);return p(O(n,r,Xl,"union"),i=>{let s,l=T(e,"refs");if(l instanceof d){let f=l[0];s=new o(f)}else s=new u(m(n+": union missing required 'refs' field"));return p(s,f=>p(ot(f,new o(void 0),(c,$,_)=>p(c,x=>j($,L)instanceof o?new o(void 0):new u(m(n+": refs["+Ht(_)+"] must be a string")))),c=>p((()=>{let $=Je(e,"closed");return $ instanceof d?$[0]&&Ke(f)?new u(m(n+": union cannot be closed with empty refs array")):new o(void 0):new o(void 0)})(),$=>p((()=>{if(Ke(f)){let x=Je(e,"closed");return x instanceof d?x[0]?new u(m(n+": union cannot have empty refs array when closed=true")):new o(void 0):new o(void 0)}else return new o(void 0)})(),_=>Wl(f,t,n)))))})}function js(e,t,n){let r=b(n);if(Pe(e)){let s=je(e),l;return Z(s,'"')&&Oe(s,'"')?l=Wt(s,1,G(s)-2):l=s,Ce(l)?new u(h(r+": token value cannot be empty string")):new o(void 0)}else return new u(h(r+": expected string for token data, got other type"))}var Ql=w(["type","description"]);function Yn(e,t){let n=b(t),r=z(e);return O(n,r,Ql,"token")}function sn(e,t,n){let r=b(n);if(q(e)){if(k(e,"$bytes")instanceof d)return new u(h(r+": unknown type cannot be a bytes object"));{let l=k(e,"$type");return l instanceof d?l[0]==="blob"?new u(h(r+": unknown type cannot be a blob object")):new o(void 0):new o(void 0)}}else return new u(h(r+": unknown type must be an object, not a primitive or array"))}var ea=w(["type","description"]);function Mt(e,t){let n=b(t),r=z(e);return O(n,r,ea,"unknown")}function ta(e,t){let n=C(e,"ref");if(n instanceof d){let r=n[0];if(q(r)){let s=k(r,"$link");if(s instanceof d){let l=s[0];return ms(l)?new o(void 0):new u(h(t+": blob ref.$link must be a valid CID with raw multicodec (bafkrei prefix)"))}else return new u(h(t+": blob ref must have $link field"))}else return new u(h(t+": blob ref must be an object"))}else return new u(h(t+": blob missing required 'ref' field"))}function Ss(e,t,n,r){return Fe(t,"*")?t==="*"?new o(void 0):new u(m(e+": blob MIME type '"+r+"' can only use '*' as a complete wildcard for "+n)):new o(void 0)}function na(e,t,n){if(Ce(t))return new u(m(e+": blob MIME type cannot be empty"));if(t==="*/*")return new o(void 0);if(Fe(t,"/")){let s=fe(t,"/");if(s instanceof y)return new u(m(e+": blob MIME type '"+t+"' must have exactly one '/' character"));{let l=s.tail;if(l instanceof y)return new u(m(e+": blob MIME type '"+t+"' must have exactly one '/' character"));if(l.tail instanceof y){let f=s.head,c=l.head;return p(Ss(e,f,"type",t),$=>Ss(e,c,"subtype",t))}else return new u(m(e+": blob MIME type '"+t+"' must have exactly one '/' character"))}}else return new u(m(e+": blob MIME type '"+t+"' must contain a '/' character"))}function ra(e,t){return ot(t,new o(void 0),(n,r,i)=>p(n,s=>{let l=j(r,L);if(l instanceof o){let a=l[0];return na(e,a,i)}else return new u(m(e+": blob accept["+B(i)+"] must be a string"))}))}function ia(e,t){if(t==="*/*")return!0;{let n=fe(e,"/"),r=fe(t,"/");if(n instanceof y)return!1;if(r instanceof y)return!1;{let i=n.tail;if(i instanceof y)return!1;{let s=r.tail;if(s instanceof y)return!1;if(i.tail instanceof y)if(s.tail instanceof y){let f=n.head,c=r.head,$=i.head,_=s.head,x;c==="*"?x=!0:x=f===c;let g=x,S;return _==="*"?S=!0:S=$===_,g&&S}else return!1;else return!1}}}}function sa(e,t,n){let r=ie(n,s=>j(s,L));return En(r,s=>ia(t,s))?new o(void 0):new u(h(e+": blob mimeType '"+t+"' not accepted. Allowed: "+Ve(r,", ")))}var oa=w(["type","accept","maxSize","description"]);function Kn(e,t){let n=b(t),r=z(e);return p(O(n,r,oa,"blob"),i=>p((()=>{let s=T(e,"accept");if(s instanceof d){let l=s[0];return ra(n,l)}else return new o(void 0)})(),s=>{let l=M(e,"maxSize");return l instanceof d?l[0]>0?new o(void 0):new u(m(n+": blob maxSize must be greater than 0")):new o(void 0)}))}var la=w(["$type","ref","mimeType","size"]);function aa(e,t){let n=kn(t,r=>!st(la,r));if(n instanceof y)return new o(void 0);{let r=n.head;return new u(h(e+": blob has unexpected field '"+r+"'"))}}function Es(e,t,n){let r=b(n);if(q(e)){let s=z(e);return p(aa(r,s),l=>p((()=>{let a=k(e,"$type");if(a instanceof d){let f=a[0];if(f==="blob")return new o(void 0);{let c=f;return new u(h(r+": blob $type must be 'blob', got '"+c+"'"))}}else return new u(h(r+": blob missing required '$type' field"))})(),a=>p(ta(e,r),f=>p((()=>{let c=k(e,"mimeType");if(c instanceof d){let $=c[0];return Ce($)?new u(h(r+": blob mimeType cannot be empty")):new o($)}else return new u(h(r+": blob missing required 'mimeType' field"))})(),c=>p((()=>{let $=M(e,"size");if($ instanceof d){let _=$[0];return _>=0?new o(_):new u(h(r+": blob size must be non-negative"))}else return new u(h(r+": blob missing or invalid 'size' field"))})(),$=>p((()=>{let _=T(t,"accept");if(_ instanceof d){let x=_[0];return sa(r,c,x)}else return new o(void 0)})(),_=>{let x=M(t,"maxSize");if(x instanceof d){let g=x[0];return $<=g?new o(void 0):new u(h(r+": blob size "+B($)+" exceeds maxSize "+B(g)))}else return new o(void 0)}))))))}else return new u(h(r+": expected blob object"))}function ln(e,t,n){let r=b(n);if(ht(e)){let s=je(e),l=s==="true";if(l||s==="false"){let c=l,$=Je(t,"const");if($ instanceof d){let _=$[0];return _!==c?new u(h(r+": must be constant value "+(_?"true":"false"))):new o(void 0)}else return new o(void 0)}else return new u(h(r+": invalid boolean representation"))}else return new u(h(r+": expected boolean, got other type"))}var ua=w(["type","const","default","description"]);function Dt(e,t){let n=b(t),r=z(e);return p(O(n,r,ua,"boolean"),i=>{let s=!D(Je(e,"const"),new A),l=!D(Je(e,"default"),new A);return Ct(n,s,l,"boolean")})}function As(e,t,n){let r=b(n);if(q(e)){let s=z(e);return p(he(s)===1?new o(void 0):new u(h(r+": $bytes objects must have a single field")),l=>{let a=k(e,"$bytes");if(a instanceof d){let f=a[0],c=Zi(f);if(c instanceof o){let $=c[0],_=Cn($),x=M(t,"minLength"),g=M(t,"maxLength");return p((()=>{if(x instanceof d){let S=x[0];return _<S?new u(h(r+": bytes size out of bounds: "+Ht(_))):new o(void 0)}else return new o(void 0)})(),S=>p((()=>{if(g instanceof d){let E=g[0];return _>E?new u(h(r+": bytes size out of bounds: "+Ht(_))):new o(void 0)}else return new o(void 0)})(),E=>new o(void 0)))}else return new u(h(r+": decoding $bytes value: invalid base64 encoding"))}else return new u(h(r+": $bytes field missing or not a string"))})}else return new u(h(r+": expecting bytes"))}var fa=w(["type","minLength","maxLength","description"]);function Xn(e,t){let n=b(t),r=z(e);return p(O(n,r,fa,"bytes"),i=>{let s=M(e,"minLength"),l=M(e,"maxLength");return p(s instanceof d?s[0]<0?new u(m(n+": bytes schema minLength below zero")):new o(void 0):new o(void 0),a=>p(l instanceof d?l[0]<0?new u(m(n+": bytes schema maxLength below zero")):new o(void 0):new o(void 0),f=>tt(n,s,l,"bytes")))})}function Cs(e,t,n){let r=b(n);if(q(e)){let s=k(e,"$link");if(s instanceof d){let l=s[0];return Fn(l)?new o(void 0):new u(h(r+": invalid CID format in $link"))}else return new u(h(r+": CID link must have $link field"))}else return new u(h(r+": expected CID link object"))}var ca=w(["type","description"]);function Qn(e,t){let n=b(t),r=z(e);return O(n,r,ca,"cid-link")}function da(e,t,n){return Jn(n,e,t,"integer",B,(r,i)=>r===i)}function un(e,t,n){let r=b(n);if(mt(e)){let s=je(e),l=Sr(s);if(l instanceof o){let a=l[0],f=M(t,"const");if(f instanceof d){let c=f[0];return c!==a?new u(h(r+": must be constant value "+B(c)+", found "+B(a))):new o(void 0)}else return p((()=>{let c=T(t,"enum");if(c instanceof d){let $=c[0],_=ie($,x=>j(x,Ue));return da(a,_,r)}else return new o(void 0)})(),c=>{let $=M(t,"minimum"),_=M(t,"maximum");return gs(r,a,$,_)})}else return new u(h(r+": failed to parse integer value"))}else return new u(h(r+": expected integer, got other type"))}var pa=w(["type","minimum","maximum","enum","const","default","description"]);function Lt(e,t){let n=b(t),r=z(e);return p(O(n,r,pa,"integer"),i=>{let s=M(e,"minimum"),l=M(e,"maximum");return p(bs(n,s,l),a=>p((()=>{let f=T(e,"enum");if(f instanceof d){let c=f[0];return K(c,void 0,($,_)=>j(_,Ue)instanceof o?new o(void 0):new u(m(n+": enum values must be integers")))}else return new o(void 0)})(),f=>{let c=!D(M(e,"const"),new A),$=!D(M(e,"default"),new A);return Ct(n,c,$,"integer")}))})}function Ms(e,t,n){let r=b(n);return _t(e)?new o(void 0):new u(h(r+": expected null, got other type"))}var $a=w(["type","description"]);function er(e,t){let n=b(t),r=z(e);return O(n,r,$a,"null")}function _a(e,t,n,r){let i=Zt(e);return ti(r,i,t,n,"string")}function ma(e,t,n,r){let i,l=Gt(e);return i=he(l),ti(r,i,t,n,"string (graphemes)")}function ha(e,t,n){if(Vn(e,t))return new o(void 0);{let i=In(t);return new u(h(n+": string does not match format '"+i+"'"))}}function wa(e,t,n){return Jn(n,e,t,"string",r=>r,(r,i)=>r===i)}function cn(e,t,n){let r=b(n);if(Pe(e)){let s=je(e),l;Z(s,'"')&&Oe(s,'"')?l=Wt(s,1,G(s)-2):l=s;let f=l,c=M(t,"minLength"),$=M(t,"maxLength");return p(_a(f,c,$,r),_=>{let x=M(t,"minGraphemes"),g=M(t,"maxGraphemes");return p(ma(f,x,g,r),S=>{let E,I=k(t,"format");if(I instanceof d){let H=I[0],J=Pr(H);if(J instanceof o){let de=J[0];E=ha(f,de,r)}else E=new o(void 0)}else E=new o(void 0);return p(E,H=>{let J=T(t,"enum");if(J instanceof d){let de=J[0],We=ie(de,Le=>j(Le,L));return wa(f,We,r)}else return new o(void 0)})})})}else return new u(h(r+": expected string, got other type"))}var xa=w(["type","format","minLength","maxLength","minGraphemes","maxGraphemes","enum","knownValues","const","default","description"]);function Tt(e,t){let n=b(t),r=z(e);return p(O(n,r,xa,"string"),i=>{let s,l=k(e,"format");if(l instanceof d){let _=l[0];Pr(_)instanceof o?s=new o(void 0):s=new u(m(n+": unknown format '"+_+"'. Valid formats: datetime, uri, at-uri, did, handle, at-identifier, nsid, cid, language, tid, record-key"))}else s=new o(void 0);let f=p(s,_=>{let x=M(e,"minLength"),g=M(e,"maxLength"),S=M(e,"minGraphemes"),E=M(e,"maxGraphemes");return p(x instanceof d?x[0]<0?new u(m(n+": string schema minLength below zero")):new o(void 0):new o(void 0),I=>p(g instanceof d?g[0]<0?new u(m(n+": string schema maxLength below zero")):new o(void 0):new o(void 0),xe=>p(S instanceof d?S[0]<0?new u(m(n+": string schema minGraphemes below zero")):new o(void 0):new o(void 0),H=>p(E instanceof d?E[0]<0?new u(m(n+": string schema maxGraphemes below zero")):new o(void 0):new o(void 0),J=>p(tt(n,x,g,"string"),de=>tt(n,S,E,"string (graphemes)"))))))}),c=p(f,_=>{let x=T(e,"enum");if(x instanceof d){let g=x[0];return K(g,void 0,(S,E)=>j(E,L)instanceof o?new o(void 0):new u(m(n+": enum values must be strings")))}else return new o(void 0)}),$=p(c,_=>{let x=T(e,"knownValues");if(x instanceof d){let g=x[0];return K(g,void 0,(S,E)=>j(E,L)instanceof o?new o(void 0):new u(m(n+": knownValues must be strings")))}else return new o(void 0)});return p($,_=>{let x=!D(k(e,"const"),new A),g=!D(k(e,"default"),new A);return Ct(n,x,g,"string")})})}function ya(e,t,n){let r=ie(t,i=>j(i,L));return p(he(r)===he(t)?new o(void 0):new u(m(e+": required fields must be strings")),i=>{if(n instanceof d){let s=n[0],l=ke(s);if(l instanceof o){let a=l[0];return K(r,void 0,(f,c)=>Qe(a,c)?new o(void 0):new u(m(e+": required field '"+c+"' not found in properties")))}else return new o(void 0)}else return Ke(r)?new o(void 0):new u(m(e+": required fields specified but no properties defined"))})}function ga(e,t,n){let r=ie(t,i=>j(i,L));return p(he(r)===he(t)?new o(void 0):new u(m(e+": nullable fields must be strings")),i=>{if(n instanceof d){let s=n[0],l=ke(s);if(l instanceof o){let a=l[0];return K(r,void 0,(f,c)=>Qe(a,c)?new o(void 0):new u(m(e+": nullable field '"+c+"' not found in properties")))}else return new o(void 0)}else return Ke(r)?new o(void 0):new u(m(e+": nullable fields specified but no properties defined"))})}function ba(e,t,n){let r=ie(t,i=>j(i,L));return K(r,void 0,(i,s)=>{if(C(n,s)instanceof d)return new o(void 0);{let a;e===""?a="required field '"+s+"' is missing":a=e+": required field '"+s+"' is missing";let f=a;return new u(h(f))}})}function Ls(e){return _t(e)?"null":ht(e)?"boolean":mt(e)?"number":Pe(e)?"string":Yt(e)?"array":"object"}var va=w(["type","properties","required","nullable","description"]),ja=w(["type","items","minLength","maxLength","description"]);function ka(e,t,n){return ri(e,t,n)}function ri(e,t,n){let r=k(t,"type");if(r instanceof d){let i=r[0];if(i==="string")return cn(e,t,n);if(i==="integer")return un(e,t,n);if(i==="boolean")return ln(e,t,n);if(i==="bytes")return As(e,t,n);if(i==="blob")return Es(e,t,n);if(i==="cid-link")return Cs(e,t,n);if(i==="null")return Ms(e,t,n);if(i==="object")return tr(e,t,n);if(i==="array")return nr(e,t,n);if(i==="union")return Zn(e,t,n);if(i==="ref")return Gn(e,t,n);if(i==="token")return js(e,t,n);if(i==="unknown")return sn(e,t,n);{let s=i;return new u(h("Unknown schema type '"+s+"' at '"+b(n)+"'"))}}else return new u(h("Schema missing type field at '"+b(n)+"'"))}function tr(e,t,n){let r=b(n);if(q(e))return p((()=>{let s=T(t,"required");if(s instanceof d){let l=s[0];return ba(r,l,e)}else return new o(void 0)})(),s=>{let l,a=T(t,"nullable");if(a instanceof d){let $=a[0];l=ie($,_=>j(_,L))}else l=w([]);let f=l,c=C(t,"properties");if(c instanceof d){let $=c[0];return Sa(e,$,f,n)}else return new o(void 0)});{let s=Ls(e);return new u(h("Expected object at '"+r+"', found "+s))}}function Sa(e,t,n,r){let i=ke(e);if(i instanceof o){let s=i[0],l=ke(t);if(l instanceof o){let a=l[0];return me(s,new o(void 0),(f,c,$)=>p(f,_=>{let x=ue(a,c);if(x instanceof o){let g=x[0],S=te(g);if(S instanceof o){let E=S[0],I=N(r,c);if(ss($))return st(n,c)?new o(void 0):new u(h("Field '"+c+"' at '"+b(r)+"' cannot be null"));{let H=te($);if(H instanceof o){let J=H[0];return ka(J,E,I)}else return H}}else return S}else return new o(void 0)}))}else return l}else return i}function Ea(e,t,n){let r=te(e);return p(r,i=>{let s=k(t,"type");return s instanceof d&&s[0]==="ref"?Gn(i,t,n):ri(i,t,n)})}function nr(e,t,n){let r=b(n);if(Yt(e)){let s,l=Vr(e);if(l instanceof d){let f=l[0];s=new o(f)}else s=new u(h(r+": failed to parse array"));return p(s,f=>{let c=he(f);return p((()=>{let $=M(t,"minLength");if($ instanceof d){let _=$[0];return c<_?new u(h(r+": array has length "+B(c)+" but minimum length is "+B(_))):new o(void 0)}else return new o(void 0)})(),$=>p((()=>{let _=M(t,"maxLength");if(_ instanceof d){let x=_[0];return c>x?new u(h(r+": array has length "+B(c)+" but maximum length is "+B(x))):new o(void 0)}else return new o(void 0)})(),_=>{let x=C(t,"items");if(x instanceof d){let g=x[0];return ot(f,new o(void 0),(S,E,I)=>p(S,xe=>{let H=N(n,"["+B(I)+"]");return Ea(E,g,H)}))}else return new o(void 0)}))})}else{let s=Ls(e);return new u(h(r+": expected array, found "+s))}}function za(e,t){return ii(e,t)}function ii(e,t){let n=k(e,"type");if(n instanceof d){let r=n[0];if(r==="string")return Tt(e,t);if(r==="integer")return Lt(e,t);if(r==="boolean")return Dt(e,t);if(r==="bytes")return Xn(e,t);if(r==="blob")return Kn(e,t);if(r==="cid-link")return Qn(e,t);if(r==="null")return er(e,t);if(r==="object")return pn(e,t);if(r==="array")return $n(e,t);if(r==="union")return Wn(e,t);if(r==="ref")return rn(e,t);if(r==="token")return Yn(e,t);if(r==="unknown")return Mt(e,t);{let i=r;return new u(m(b(t)+": unknown type '"+i+"'"))}}else return new u(m(b(t)+": schema missing type field"))}function pn(e,t){let n=b(t),r=z(e);return p(O(n,r,va,"object"),i=>{let s;return T(e,"properties")instanceof d?s=new u(m(n+": properties must be an object, not an array")):q(e)?s=new o(new A):s=new o(new A),p(s,f=>{let c=C(e,"properties");return p((()=>{let $=T(e,"required");if($ instanceof d){let _=$[0];return ya(n,_,c)}else return new o(void 0)})(),$=>p((()=>{let _=T(e,"nullable");if(_ instanceof d){let x=_[0];return ga(n,x,c)}else return new o(void 0)})(),_=>{if(c instanceof d){let x=c[0];return q(x)?Aa(x,t):new o(void 0)}else return new o(void 0)}))})})}function Aa(e,t){let n=ke(e);if(n instanceof o){let r=n[0];return me(r,new o(void 0),(i,s,l)=>p(i,a=>{let f=te(l);if(f instanceof o){let c=f[0],$=N(t,"properties."+s);return za(c,$)}else return f}))}else return n}function Oa(e,t){let n=k(e,"type");return n instanceof d&&n[0]==="ref"?rn(e,t):ii(e,t)}function $n(e,t){let n=b(t),r=z(e);return p(O(n,r,ja,"array"),i=>{let s,l=C(e,"items");if(l instanceof d){let f=l[0];s=new o(f)}else s=new u(m(n+": array missing required 'items' field"));return p(s,f=>{let c=N(t,".items");return p(Oa(f,c),$=>{let _=M(e,"minLength"),x=M(e,"maxLength");return p(tt(n,_,x,"array"),g=>new o(void 0))})})})}function Ca(e,t,n){if(t instanceof d){let r=t[0];return K(r,void 0,(i,s)=>{let l=j(s,L);if(l instanceof o){let a=l[0];return Qe(n,a)?new o(void 0):new u(m(e+": required field '"+a+"' not found in properties"))}else return new u(m(e+": required field must be a string"))})}else return new o(void 0)}function Ge(e,t){let n=k(e,"type");if(n instanceof d){let r=n[0];if(r==="boolean")return Dt(e,t);if(r==="integer")return Lt(e,t);if(r==="string")return Tt(e,t);if(r==="unknown")return Mt(e,t);if(r==="array")return $n(e,t);{let i=r;return new u(m(b(t)+": unknown type '"+i+"'"))}}else return new u(m(b(t)+": schema missing type field"))}function Ba(e,t,n,r){let i=e+".properties."+t,s=k(n,"type");if(s instanceof d){let l=s[0];if(l==="boolean"){let a=N(r,"properties."+t);return Ge(n,a)}else if(l==="integer"){let a=N(r,"properties."+t);return Ge(n,a)}else if(l==="string"){let a=N(r,"properties."+t);return Ge(n,a)}else if(l==="unknown"){let a=N(r,"properties."+t);return Ge(n,a)}else if(l==="array"){let a=C(n,"items");if(a instanceof d){let f=a[0],c=k(f,"type");if(c instanceof d){let $=c[0];if($==="boolean"){let _=N(r,"properties."+t);return Ge(n,_)}else if($==="integer"){let _=N(r,"properties."+t);return Ge(n,_)}else if($==="string"){let _=N(r,"properties."+t);return Ge(n,_)}else if($==="unknown"){let _=N(r,"properties."+t);return Ge(n,_)}else{let _=$;return new u(m(i+": params array items must be boolean, integer, string, or unknown, got '"+_+"'"))}}else return new u(m(i+": array items missing type field"))}else return new u(m(i+": array property missing items field"))}else{let a=l;return new u(m(i+": params properties must be boolean, integer, string, unknown, or arrays of these, got '"+a+"'"))}}else return new u(m(i+": property missing type field"))}function Ma(e,t,n){return Ln(t,new o(void 0),(r,i,s)=>r instanceof o?p(i===""?new u(m(e+": empty property name not allowed")):new o(void 0),l=>p((()=>{let a=te(s);return a instanceof o?a:new u(m(e+": invalid property value for '"+i+"'"))})(),a=>Ba(e,i,a,n))):r)}var Da=w(["type","description","properties","required"]);function Ze(e,t){let n=b(t),r=z(e);return p(O(n,r,Da,"params"),i=>p((()=>{let s=k(e,"type");if(s instanceof d){let l=s[0];if(l==="params")return new o(void 0);{let a=l;return new u(m(n+": expected type 'params', got '"+a+"'"))}}else return new u(m(n+": params missing type field"))})(),s=>{let l,a=C(e,"properties");if(a instanceof d){let x=a[0];l=ke(x)}else l=new o(Dn());let f=l,c,$=T(e,"required");$ instanceof d,c=$;let _=c;return p(f,x=>p(Ca(n,_,x),g=>Ma(n,x,t)))}))}function La(e,t){let n=N(t,"parameters");return Ze(e,n)}function Is(e,t,n){return k(t,"encoding")instanceof d?new o(void 0):new u(m(e+": procedure "+n+" missing encoding field"))}var Ta=w(["type","parameters","input","output","errors","description"]);function Ns(e,t){let n=b(t),r=z(e);return p(O(n,r,Ta,"procedure"),i=>p((()=>{let s=C(e,"parameters");if(s instanceof d){let l=s[0];return La(l,t)}else return new o(void 0)})(),s=>p((()=>{let l=C(e,"input");if(l instanceof d){let a=l[0];return Is(n,a,"input")}else return new o(void 0)})(),l=>p((()=>{let a=C(e,"output");if(a instanceof d){let f=a[0];return Is(n,f,"output")}else return new o(void 0)})(),a=>T(e,"errors")instanceof d?new o(void 0):new o(void 0)))))}function Na(e,t){let n=N(t,"parameters");return Ze(e,n)}function qa(e,t){return k(t,"encoding")instanceof d?new o(void 0):new u(m(e+": query output missing encoding field"))}var Ua=w(["type","parameters","output","errors","description"]);function qs(e,t){let n=b(t),r=z(e);return p(O(n,r,Ua,"query"),i=>p((()=>{let s=C(e,"parameters");if(s instanceof d){let l=s[0];return Na(l,t)}else return new o(void 0)})(),s=>p((()=>{let l=C(e,"output");if(l instanceof d){let a=l[0];return qa(n,a)}else return new o(void 0)})(),l=>T(e,"errors")instanceof d?new o(void 0):new o(void 0))))}function Us(e,t,n){let r=b(n);if(q(e)){let s=C(t,"record");if(s instanceof d){let l=s[0];return tr(e,l,n)}else return new u(h(r+": record schema missing 'record' field"))}else return new u(h(r+": expected object for record"))}function Va(e,t){return t==="tid"?new o(void 0):t==="any"?new o(void 0):t==="nsid"?new o(void 0):Z(t,"literal:")?new o(void 0):new u(m(e+": record has invalid key type '"+t+"'. Must be 'tid', 'any', 'nsid', or 'literal:*'"))}var Ra=w(["type","key","record","description"]),Pa=w(["type","properties","required","nullable","description"]);function Ja(e,t){let n=k(t,"type");if(n instanceof d){let r=n[0];if(r==="object"){let i=z(t);return p(O(e,i,Pa,"record object"),s=>p((()=>{let l=C(t,"properties");if(l instanceof d){let a=l[0];return q(a)?new o(void 0):new u(m(e+": record properties must be an object"))}else return new o(void 0)})(),l=>T(t,"nullable")instanceof d?new o(void 0):C(t,"nullable")instanceof d?new u(m(e+": record nullable field must be an array")):new o(void 0)))}else{let i=r;return new u(m(e+": record field must be type 'object', got '"+i+"'"))}}else return new u(m(e+": record field missing type"))}function Fs(e,t){let n=b(t),r=z(e);return p(O(n,r,Ra,"record"),i=>{let s,l=k(e,"key");if(l instanceof d){let f=l[0];s=new o(f)}else s=new u(m(n+": record missing required 'key' field"));return p(s,f=>p(Va(n,f),c=>{let $,_=C(e,"record");if(_ instanceof d){let g=_[0];$=new o(g)}else $=new u(m(n+": record missing required 'record' field"));return p($,g=>p(Ja(n,g),S=>{let E=N(t,".record");return pn(g,E)}))}))})}function Za(e,t){let n=N(t,"parameters");return Ze(e,n)}function Wa(e,t){let n=C(t,"schema");if(n instanceof d){let r=n[0],i=k(r,"type");if(i instanceof d){let s=i[0];if(s==="union")return new o(void 0);{let l=s;return new u(m(e+": subscription message schema must be type 'union', got '"+l+"'"))}}else return new u(m(e+": subscription message schema missing type field"))}else return new u(m(e+": subscription message missing schema field"))}var Ha=w(["type","parameters","message","errors","description"]);function Vs(e,t){let n=b(t),r=z(e);return p(O(n,r,Ha,"subscription"),i=>p((()=>{let s=C(e,"parameters");if(s instanceof d){let l=s[0];return Za(l,t)}else return new o(void 0)})(),s=>p((()=>{let l=C(e,"message");if(l instanceof d){let a=l[0];return Wa(n,a)}else return new o(void 0)})(),l=>T(e,"errors")instanceof d?new o(void 0):new o(void 0))))}function Ka(e,t){let n=k(e,"type");if(n instanceof d){let r=n[0];if(r==="record")return Fs(e,t);if(r==="query")return qs(e,t);if(r==="procedure")return Ns(e,t);if(r==="subscription")return Vs(e,t);if(r==="params")return Ze(e,t);if(r==="object")return pn(e,t);if(r==="array")return $n(e,t);if(r==="union")return Wn(e,t);if(r==="string")return Tt(e,t);if(r==="integer")return Lt(e,t);if(r==="boolean")return Dt(e,t);if(r==="bytes")return Xn(e,t);if(r==="blob")return Kn(e,t);if(r==="cid-link")return Qn(e,t);if(r==="null")return er(e,t);if(r==="ref")return rn(e,t);if(r==="token")return Yn(e,t);if(r==="unknown")return Mt(e,t);{let i=r;return new u(m("Unknown type: "+i))}}else return new u(m("Definition missing type field"))}function Xa(e){let t,n=Kr();t=ei(n,e);let r=t;if(r instanceof o){let i=r[0],s=Xr(i);if(s instanceof o){let l=s[0],a=me(l.lexicons,ee(),(c,$,_)=>{let x=z(_.defs),g=nn(l,$);return Sn(x,c,(S,E)=>{let I=C(_.defs,E);if(I instanceof d){let xe=I[0],H=Ka(xe,g);if(H instanceof o)return S;{let J=H[0],de;J instanceof pt?de="Lexicon not found: "+J.collection:(J instanceof $t,de=J.message);let We=de,Le;Z(We,": ")?Le=Re(We,2):Le=We;let _n=Le,Nt=$+"#"+E+": "+_n,qt=ue(S,$);if(qt instanceof o){let He=qt[0];return _e(S,$,F(Nt,He))}else return _e(S,$,w([Nt]))}}else return S})});return xr(a)?new o(void 0):new u(a)}else{let l=s[0];return new u(bn(w([["builder",w([Ur(l)])]])))}}else{let i=r[0];return new u(bn(w([["builder",w([Ur(i)])]])))}}function Rs(e){let t,n=Kr();return t=ei(n,e),p(t,i=>Xr(i))}function Ps(e,t,n){let r=Pn(e,t);if(r instanceof d){let i=r[0],s=C(i.defs,"main");if(s instanceof d){let l=s[0],a=nn(e,t),f=N(a,"defs.main");return Us(n,l,f)}else return new u(m("Lexicon '"+t+"' has no main definition"))}else return new u(Fr(t))}function Qa(e,t,n){return p(Rs(e),r=>Ps(r,t,n))}function eu(e){return et(e)}function tu(e,t){if(Vn(e,t))return new o(void 0);{let r=In(t);return new u("Value does not match format: "+r)}}function Js(e){return te(e)}function Gs(e){return p((()=>{let t=Mn(e,se);return Xe(t,n=>m("Failed to parse JSON string"))})(),t=>Js(t))}function nu(e){let n=qe(e,Gs);return Xe(n,r=>m("Failed to parse JSON strings"))}return Xs(ru);})();
+2 -2
src/honk/internal/json_helpers.gleam
··· 267 267 Error(_) -> Error(data_validation("Failed to decode bool")) 268 268 } 269 269 } 270 - "List" -> { 270 + "List" | "Array" -> { 271 271 case decode.run(dyn, decode.list(decode.dynamic)) { 272 272 Ok(arr) -> { 273 273 case list.try_map(arr, dynamic_to_json) { ··· 278 278 Error(_) -> Error(data_validation("Failed to decode list")) 279 279 } 280 280 } 281 - "Dict" -> { 281 + "Dict" | "Object" -> { 282 282 case decode.run(dyn, decode.dict(decode.string, decode.dynamic)) { 283 283 Ok(dict_val) -> { 284 284 let pairs = dict.to_list(dict_val)