@m1cro/js-bootstrap 0.1.0-beta.16 → 0.1.0-beta.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bootstrap.js +1 -1
- package/package.json +1 -1
package/dist/bootstrap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var hr=Object.defineProperty;var K=(t,e)=>{for(var r in e)hr(t,r,{get:e[r],enumerable:!0})};var mr={};var We=["trace","debug","info","warn","error","none"];var X=t=>We.indexOf(t)>=We.indexOf(console.logLevel);Object.defineProperty(globalThis.console,"logLevel",{get(){return process.env.LOG_LEVEL||"info"}});var ee=console;globalThis.console={...globalThis.console,trace:(...t)=>{X("trace")&&ee.trace("[TRACE]",...t)},debug:(...t)=>{X("debug")&&ee.debug("[DEBUG]",...t)},info:(...t)=>{X("info")&&ee.info("[INFO]",...t)},log:(...t)=>{X("info")&&ee.log("[INFO]",...t)},warn:(...t)=>{X("warn")&&ee.warn("[WARN]",...t)},error:(...t)=>{X("error")&&ee.error("[ERROR]",...t)}};import an from"@EntryPoint";var te={};K(te,{guest:()=>yr,host:()=>gr});import*as P from"m1cro:common/host";var gr={getTenant:()=>P.getTenant(),getArtifact:t=>P.getArtifact(t),getCRD:t=>P.getCRD(t),listProviders:t=>P.listProviders(t)},yr={getManifest:()=>Y.manifest};var F={};K(F,{host:()=>br});import*as N from"m1cro:crypto/host";var br={deriveKey:(t,e)=>N.deriveKey(t,e),aesGcmEncrypt:t=>N.aesGcmEncrypt(t),aesGcmDecrypt:t=>N.aesGcmDecrypt(t),argon2Hash:(t,e,r,n,s,i)=>N.argon2Hash(t,e,r,n,s,i),argon2Verify:(t,e,r,n,s,i,o)=>N.argon2Verify(t,e,r,n,s,i,o)};var I={};K(I,{host:()=>wr});import*as $ from"m1cro:entity/host";var wr={find:async t=>await $.find(t),insert:async t=>await $.insert(t),update:async t=>await $.update(t),remove:async t=>await $.remove(t)};var W={};K(W,{host:()=>Er});import*as k from"m1cro:kv/host";var Er={get:async t=>await k.get(t),getDel:async t=>await k.getDel(t),set:async(t,e,r)=>await k.set(t,e,r),delete:async t=>await k.delete(t)};var j={};K(j,{fromRequest:()=>Ir,fromResponse:()=>wt,guest:()=>Rr,host:()=>Tr,toRequest:()=>bt,toResponse:()=>Sr,types:()=>ue});import*as ue from"m1cro:rpc/types";import*as yt from"m1cro:rpc/host";var re=class{get tenant(){return te.host.getTenant()}};var Tr={call:async t=>await yt.call(t)},Rr={call:async(t,e,r,n)=>{let s=Y.router.routes[t];if(!s)throw new Error(`Route not found for index ${t}`);let i=new re;console.debug("converting request to m1cro request");let o=await bt(r);console.debug("calling route handler");let a=await s.handler(o,i);return console.debug("converting response to m1cro response"),await wt(a)}},Ir=async t=>{let e=new ue.Request,r=t.method.toLowerCase();switch(r){case"get":case"post":case"put":case"patch":case"delete":e.setMethod({tag:r});break;default:throw new Error(`Invalid method: ${r}`)}e.setUrl(t.url),e.setHeaders(Array.from(t.headers.entries()));let n=await t.bytes();return e.setBody(n),e},bt=async t=>{let e=t.getUrl(),r={method:t.getMethod().tag,headers:t.getHeaders()},n=t.getBody();n.length>0&&(r.body=n.buffer),console.trace("request url",e),console.debug("request init",r);let s=new Request(e,r);return console.debug("converted request",s),s},wt=async t=>{let e=new ue.Response;e.setStatus(t.status),e.setHeaders(Array.from(t.headers.entries()));let r=await t.bytes();return e.setBody(r),e},Sr=async t=>{let e=t.body();return new Response(e.length>0?e.buffer:null,{headers:t.getHeaders(),status:t.getStatus()})};import*as xr from"m1cro:log/host";var ae={};K(ae,{guest:()=>sn,host:()=>nn});var c={POS_INT:0,NEG_INT:1,BYTE_STRING:2,UTF8_STRING:3,ARRAY:4,MAP:5,TAG:6,SIMPLE_FLOAT:7},h={DATE_STRING:0,DATE_EPOCH:1,POS_BIGINT:2,NEG_BIGINT:3,DECIMAL_FRAC:4,BIGFLOAT:5,BASE64URL_EXPECTED:21,BASE64_EXPECTED:22,BASE16_EXPECTED:23,CBOR:24,URI:32,BASE64URL:33,BASE64:34,MIME:36,DATE_EPOCH_DAYS:100,SET:258,JSON:262,WTF8:273,DATE_FULL:1004,REGEXP:21066,SELF_DESCRIBED:55799,INVALID_16:65535,INVALID_32:4294967295,INVALID_64:0xffffffffffffffffn},l={ZERO:0,ONE:24,TWO:25,FOUR:26,EIGHT:27,INDEFINITE:31},v={FALSE:20,TRUE:21,NULL:22,UNDEFINED:23},y=class{static BREAK=Symbol.for("github.com/hildjj/cbor2/break");static ENCODED=Symbol.for("github.com/hildjj/cbor2/cbor-encoded");static LENGTH=Symbol.for("github.com/hildjj/cbor2/length")},ne={MIN:-(2n**63n),MAX:2n**64n-1n};var p=class t{static#e=new Map;tag;contents;constructor(e,r=void 0){this.tag=e,this.contents=r}get noChildren(){return!!t.#e.get(this.tag)?.noChildren}static registerDecoder(e,r,n){let s=this.#e.get(e);return this.#e.set(e,r),s&&("comment"in r||(r.comment=s.comment),"noChildren"in r||(r.noChildren=s.noChildren)),n&&!r.comment&&(r.comment=()=>`(${n})`),s}static clearDecoder(e){let r=this.#e.get(e);return this.#e.delete(e),r}static getDecoder(e){return this.#e.get(e)}static getAllDecoders(){return new Map(this.#e)}*[Symbol.iterator](){yield this.contents}push(e){return this.contents=e,1}decode(e){let r=e?.tags?.get(this.tag)??(e?.ignoreGlobalTags?void 0:t.#e.get(this.tag));return r?r(this,e):this}comment(e,r){let n=e?.tags?.get(this.tag)??(e?.ignoreGlobalTags?void 0:t.#e.get(this.tag));if(n?.comment)return n.comment(this,e,r)}toCBOR(){return[this.tag,this.contents]}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return`${this.tag}(${n(this.contents,r)})`}};function q(t){if(t!=null&&typeof t=="object")return t[y.ENCODED]}function Et(t){if(t!=null&&typeof t=="object")return t[y.LENGTH]}function G(t,e){Object.defineProperty(t,y.ENCODED,{configurable:!0,enumerable:!1,value:e})}function C(t,e){let r=Object(t);return G(r,e),r}var Je=Symbol("CBOR_RANGES");function Tt(t,e){Object.defineProperty(t,Je,{configurable:!1,enumerable:!1,writable:!1,value:e})}function fe(t){return t[Je]}function Nr(t){return fe(t)!==void 0}function pe(t,e=0,r=t.length-1){let n=t.subarray(e,r),s=fe(t);if(s){let i=[];for(let o of s)if(o[0]>=e&&o[0]+o[1]<=r){let a=[...o];a[0]-=e,i.push(a)}i.length&&Tt(n,i)}return n}function Ie(t){let e=Math.ceil(t.length/2),r=new Uint8Array(e);e--;for(let n=t.length,s=n-2;n>=0;n=s,s-=2,e--)r[e]=parseInt(t.substring(s,n),16);return r}function E(t){return t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")}function Rt(t){let e=t.reduce((o,a)=>o+a.length,0),r=t.some(o=>Nr(o)),n=[],s=new Uint8Array(e),i=0;for(let o of t){if(!(o instanceof Uint8Array))throw new TypeError(`Invalid array: ${o}`);if(s.set(o,i),r){let a=o[Je]??[[0,o.length]];for(let d of a)d[0]+=i;n.push(...a)}i+=o.length}return r&&Tt(s,n),s}function le(t){let e=atob(t);return Uint8Array.from(e,r=>r.codePointAt(0))}var vr={"-":"+",_:"/"};function It(t){let e=t.replace(/[_-]/g,r=>vr[r]);return le(e.padEnd(Math.ceil(e.length/4)*4,"="))}function St(){let t=new Uint8Array(4),e=new Uint32Array(t.buffer);return!((e[0]=1)&t[0])}function Ze(t){let e="";for(let r of t){let n=r.codePointAt(0)?.toString(16).padStart(4,"0");e&&(e+=", "),e+=`U+${n}`}return e}var he=class{#e=new Map;registerEncoder(e,r){let n=this.#e.get(e);return this.#e.set(e,r),n}get(e){return this.#e.get(e)}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}};function Se(t,e){let[r,n,s]=t,[i,o,a]=e,d=Math.min(s.length,a.length);for(let u=0;u<d;u++){let f=s[u]-a[u];if(f!==0)return f}return 0}var se=class t{static defaultOptions={chunkSize:4096};#e;#t=[];#r=null;#n=0;#s=0;constructor(e={}){if(this.#e={...t.defaultOptions,...e},this.#e.chunkSize<8)throw new RangeError(`Expected size >= 8, got ${this.#e.chunkSize}`);this.#o()}get length(){return this.#s}read(){this.#c();let e=new Uint8Array(this.#s),r=0;for(let n of this.#t)e.set(n,r),r+=n.length;return this.#o(),e}write(e){let r=e.length;r>this.#d()?(this.#c(),r>this.#e.chunkSize?(this.#t.push(e),this.#o()):(this.#o(),this.#t[this.#t.length-1].set(e),this.#n=r)):(this.#t[this.#t.length-1].set(e,this.#n),this.#n+=r),this.#s+=r}writeUint8(e){this.#i(1),this.#r.setUint8(this.#n,e),this.#a(1)}writeUint16(e,r=!1){this.#i(2),this.#r.setUint16(this.#n,e,r),this.#a(2)}writeUint32(e,r=!1){this.#i(4),this.#r.setUint32(this.#n,e,r),this.#a(4)}writeBigUint64(e,r=!1){this.#i(8),this.#r.setBigUint64(this.#n,e,r),this.#a(8)}writeInt16(e,r=!1){this.#i(2),this.#r.setInt16(this.#n,e,r),this.#a(2)}writeInt32(e,r=!1){this.#i(4),this.#r.setInt32(this.#n,e,r),this.#a(4)}writeBigInt64(e,r=!1){this.#i(8),this.#r.setBigInt64(this.#n,e,r),this.#a(8)}writeFloat32(e,r=!1){this.#i(4),this.#r.setFloat32(this.#n,e,r),this.#a(4)}writeFloat64(e,r=!1){this.#i(8),this.#r.setFloat64(this.#n,e,r),this.#a(8)}clear(){this.#s=0,this.#t=[],this.#o()}#o(){let e=new Uint8Array(this.#e.chunkSize);this.#t.push(e),this.#n=0,this.#r=new DataView(e.buffer,e.byteOffset,e.byteLength)}#c(){if(this.#n===0){this.#t.pop();return}let e=this.#t.length-1;this.#t[e]=this.#t[e].subarray(0,this.#n),this.#n=0,this.#r=null}#d(){let e=this.#t.length-1;return this.#t[e].length-this.#n}#i(e){this.#d()<e&&(this.#c(),this.#o())}#a(e){this.#n+=e,this.#s+=e}};var Xe=1n<<15n,me=0b11111n<<10n,_t=1n<<9n,Dt=_t-1n,xt=_t|Dt,et=1n<<31n,ge=0b11111111n<<23n,Bt=1n<<22n,Mt=Bt-1n,Ot=Bt|Mt,xe=1n<<63n,D=0b11111111111n<<52n,ye=1n<<51n,Oe=ye-1n,Nt=ye|Oe,vt=Oe-(Dt<<42n),At=Oe-(Mt<<29n),Ar={2:"0b",8:"0o",16:"0x"},Lt=(t=>(t[t.NATURAL=-2]="NATURAL",t[t.UNKNOWN=-1]="UNKNOWN",t[t.F16=2]="F16",t[t.F32=4]="F32",t[t.F64=8]="F64",t))(Lt||{});function Ut(t,e,r,n){let s="nan'";return t.quiet||(s+="!"),t.sign===-1&&(s+="-"),s+=n(Math.abs(t.payload),r),s+="'",s+=t.encodingIndicator,s}var be=class extends Number{#e;#t=-1;constructor(e,r=!0,n=-1){super(NaN);let s=e;if(typeof e=="number"){if(!Number.isSafeInteger(e))throw new Error(`Invalid NAN payload: ${e}`);e=BigInt(e);let i=0n;if(e<0&&(i=xe,e=-e),e>=ye)throw new Error(`Payload too large: ${s}`);let o=r?ye:0n;switch(this.#e=i|D|o|e,n){case-2:throw new Error("NAN_SIZE.NATURAL only valid for bigint constructor");case-1:n=this.preferredSize;break;case 2:if(this.#e&vt)throw new Error("Invalid size for payload");break;case 4:if(this.#e&At)throw new Error("Invalid size for payload");break;case 8:break;default:throw new Error(`Invalid size: ${n}`)}this.#t=n}else if(typeof e=="bigint"){let i=-1;if((e&D)===D)this.#e=e,i=8;else if((e&ge)===ge){let o=(e&et)<<32n;this.#e=o|D|(e&Ot)<<29n,i=4}else if((e&me)===me){let o=(e&Xe)<<48n;this.#e=o|D|(e&xt)<<42n,i=2}else throw new Error(`Invalid raw NaN value: ${e}`);if(n===-1)this.#t=this.preferredSize;else if(n===-2)this.#t=i;else{if(n<i)throw new Error("Invalid bigint NaN size");this.#t=n}}else{let i=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.length){case 3:{if(e[0]!==249)throw new Error("Invalid CBOR encoding for half float");let o=BigInt(i.getUint16(1,!1));if((o&me)!==me)throw new Error("Not a NaN");let a=(o&Xe)<<48n;this.#e=a|D|(o&xt)<<42n,this.#t=2;break}case 5:{if(e[0]!==250)throw new Error("Invalid CBOR encoding for single float");let o=BigInt(i.getUint32(1,!1));if((o&ge)!==ge)throw new Error("Not a NaN");let a=(o&et)<<32n;this.#e=a|D|(o&Ot)<<29n,this.#t=4;break}case 9:{if(e[0]!==251)throw new Error("Invalid CBOR encoding for double float");if(this.#e=i.getBigUint64(1,!1),(this.#e&D)!==D)throw new Error("Not a NaN (NaNaN)");this.#t=8;break}default:throw new RangeError(`Invalid NAN size (should be 2, 4, or 8): ${e.length-1}`)}}if(!this.payload&&!this.quiet)throw new Error("Signalling NaN with zero payload")}get bytes(){let e=new ArrayBuffer(this.#t+1),r=new DataView(e);switch(this.#t){case 2:{r.setUint8(0,249);let n=(this.#e&xe?Xe:0n)|me|(this.#e&Nt)>>42n;r.setUint16(1,Number(n),!1);break}case 4:{r.setUint8(0,250);let n=(this.#e&xe?et:0n)|ge|(this.#e&Nt)>>29n;r.setUint32(1,Number(n),!1);break}case 8:r.setUint8(0,251),r.setBigUint64(1,this.#e);break}return new Uint8Array(e)}get quiet(){return!!(this.#e&ye)}get sign(){return this.#e&xe?-1:1}get payload(){return Number(this.#e&Oe)*this.sign}get raw(){return this.#e}get encodingIndicator(){switch(this.#t){case 2:return"_1";case 4:return"_2"}return"_3"}get size(){return this.#t}get preferredSize(){return(this.#e&vt)===0n?2:(this.#e&At)===0n?4:8}get isShortestEncoding(){return this.preferredSize===this.#t}toCBOR(e){e.write(this.bytes)}toString(e=10){return Ut(this,1,{},r=>(Ar[e]??"")+r.toString(e))}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return Ut(this,e,r,n)}};function tt(t,e=0,r=!1){let n=t[e]&128?-1:1,s=(t[e]&124)>>2,i=(t[e]&3)<<8|t[e+1];if(s===0){if(r&&i!==0)throw new Error(`Unwanted subnormal: ${n*5960464477539063e-23*i}`);return n*5960464477539063e-23*i}else if(s===31)return i?NaN:n*(1/0);return n*2**(s-25)*(1024+i)}function Ne(t){let e=new DataView(new ArrayBuffer(4));e.setFloat32(0,t,!1);let r=e.getUint32(0,!1);if((r&8191)!==0)return null;let n=r>>16&32768,s=r>>23&255,i=r&8388607;if(!(s===0&&i===0))if(s>=113&&s<=142)n+=(s-112<<10)+(i>>13);else if(s>=103&&s<113){if(i&(1<<126-s)-1)return null;n+=i+8388608>>126-s}else if(s===255)n|=31744,n|=i>>13;else return null;return n}function Pt(t){if(t!==0){let e=new ArrayBuffer(8),r=new DataView(e);r.setFloat64(0,t,!1);let n=r.getBigUint64(0,!1);if((n&0x7ff0000000000000n)===0n)return n&0x8000000000000000n?-0:0}return t}function Ft(t){switch(t.length){case 2:tt(t,0,!0);break;case 4:{let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=e.getUint32(0,!1);if((r&2139095040)===0&&r&8388607)throw new Error(`Unwanted subnormal: ${e.getFloat32(0,!1)}`);break}case 8:{let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=e.getBigUint64(0,!1);if((r&0x7ff0000000000000n)===0n&&r&0x000fffffffffffn)throw new Error(`Unwanted subnormal: ${e.getFloat64(0,!1)}`);break}default:throw new TypeError(`Bad input to isSubnormal: ${t}`)}}var we=class extends TypeError{code="ERR_ENCODING_INVALID_ENCODED_DATA";constructor(){super("The encoded data was not valid for encoding wtf-8")}},ve=class extends RangeError{code="ERR_ENCODING_NOT_SUPPORTED";constructor(e){super(`Invalid encoding: "${e}"`)}};var Ae=new Uint8Array(0);var rt=55296,$t=56320,kt=65533,Ue="wtf-8";function _r(t){return t&&!(t instanceof ArrayBuffer)&&t.buffer instanceof ArrayBuffer}function Dr(t){return t?t instanceof Uint8Array?t:_r(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t):Ae}var Br=[0,0,0,0,0,0,0,0,-1,-1,-1,-1,1,1,2,3],J=class t{static DEFAULT_BUFFERSIZE=4096;encoding=Ue;fatal;ignoreBOM;bufferSize;#e=0;#t=0;#r=0;#n=!0;#s;constructor(e="wtf8",r=void 0){if(e.toLowerCase().replace("-","")!=="wtf8")throw new ve(e);if(this.fatal=!!r?.fatal,this.ignoreBOM=!!r?.ignoreBOM,this.bufferSize=Math.floor(r?.bufferSize??t.DEFAULT_BUFFERSIZE),isNaN(this.bufferSize)||this.bufferSize<1)throw new RangeError(`Invalid buffer size: ${r?.bufferSize}`);this.#s=new Uint16Array(this.bufferSize)}decode(e,r){let n=!!r?.stream,s=Dr(e),i=[],o=this.#s,a=this.bufferSize-3,d=0,u=()=>{if(this.#t=0,this.#e=0,this.#r=0,this.fatal)throw new we;o[d++]=kt},f=()=>{let g=this.#r;for(let O=0;O<g;O++)u()},m=g=>{if(this.#e===0)switch(Br[g>>4]){case-1:u();break;case 0:o[d++]=g;break;case 1:this.#t=g&31,(this.#t&30)===0?u():(this.#e=1,this.#r=1);break;case 2:this.#t=g&15,this.#e=2,this.#r=1;break;case 3:g&8?u():(this.#t=g&7,this.#e=3,this.#r=1);break}else{if((g&192)!==128||this.#r===1&&this.#e===2&&this.#t===0&&(g&32)===0||this.#e===3&&this.#t===0&&(g&48)===0)return f(),m(g);if(this.#t=this.#t<<6|g&63,this.#r++,--this.#e===0){if(this.ignoreBOM||!this.#n||this.#t!==65279)if(this.#t<65536)o[d++]=this.#t;else{let O=this.#t-65536;o[d++]=O>>>10&1023|rt,o[d++]=O&1023|$t}this.#t=0,this.#r=0,this.#n=!1}}};for(let g of s)d>=a&&(i.push(String.fromCharCode.apply(null,o.subarray(0,d))),d=0),m(g);return n||(this.#n=!0,(this.#t||this.#e)&&f()),d>0&&i.push(String.fromCharCode.apply(null,o.subarray(0,d))),i.join("")}};function Mr(t){let e=0;for(let r of t){let n=r.codePointAt(0);n<128?e++:n<2048?e+=2:n<65536?e+=3:e+=4}return e}var oe=class{encoding=Ue;encode(e){if(!e)return Ae;let r=new Uint8Array(Mr(String(e)));return this.encodeInto(e,r),r}encodeInto(e,r){let n=String(e),s=n.length,i=r.length,o=0,a=0;for(a=0;a<s;a++){let d=n.codePointAt(a);if(d<128){if(o>=i)break;r[o++]=d}else if(d<2048){if(o>=i-1)break;r[o++]=192|d>>6,r[o++]=128|d&63}else if(d<65536){if(o>=i-2)break;r[o++]=224|d>>12,r[o++]=128|d>>6&63,r[o++]=128|d&63}else{if(o>=i-3)break;r[o++]=240|d>>18,r[o++]=128|d>>12&63,r[o++]=128|d>>6&63,r[o++]=128|d&63,a++}}return{read:a,written:o}}};var{ENCODED:es}=y,jt=c.SIMPLE_FLOAT<<5|l.TWO,Lr=c.SIMPLE_FLOAT<<5|l.FOUR,Pr=c.SIMPLE_FLOAT<<5|l.EIGHT,Fr=c.SIMPLE_FLOAT<<5|v.TRUE,$r=c.SIMPLE_FLOAT<<5|v.FALSE,kr=c.SIMPLE_FLOAT<<5|v.UNDEFINED,jr=c.SIMPLE_FLOAT<<5|v.NULL,qr=new TextEncoder,Gr=new oe,De={...se.defaultOptions,avoidInts:!1,cde:!1,collapseBigInts:!0,dateTag:h.DATE_EPOCH,dcbor:!1,float64:!1,flushToZero:!1,forceEndian:null,ignoreOriginalEncoding:!1,largeNegativeAsBigInt:!1,reduceUnsafeNumbers:!1,rejectBigInts:!1,rejectCustomSimples:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectUndefined:!1,simplifyNegativeZero:!1,sortKeys:null,stringNormalization:null,types:null,wtf8:!1,ignoreGlobalTags:!1},st={cde:!0,ignoreOriginalEncoding:!0,sortKeys:Se},qt={...st,dcbor:!0,largeNegativeAsBigInt:!0,reduceUnsafeNumbers:!0,rejectCustomSimples:!0,rejectDuplicateKeys:!0,rejectUndefined:!0,simplifyNegativeZero:!0,stringNormalization:"NFC"};function Gt(t){let e=t<0;return typeof t=="bigint"?[e?-t-1n:t,e]:[e?-t-1:t,e]}function nt(t,e,r){if(r.rejectFloats)throw new Error(`Attempt to encode an unwanted floating point number: ${t}`);if(isNaN(t))e.writeUint8(jt),e.writeUint16(32256);else if(!r.float64&&Math.fround(t)===t){let n=Ne(t);n===null?(e.writeUint8(Lr),e.writeFloat32(t)):(e.writeUint8(jt),e.writeUint16(n))}else e.writeUint8(Pr),e.writeFloat64(t)}function R(t,e,r){let[n,s]=Gt(t);if(s&&r)throw new TypeError(`Negative size: ${t}`);r??=s?c.NEG_INT:c.POS_INT,r<<=5,n<24?e.writeUint8(r|n):n<=255?(e.writeUint8(r|l.ONE),e.writeUint8(n)):n<=65535?(e.writeUint8(r|l.TWO),e.writeUint16(n)):n<=4294967295?(e.writeUint8(r|l.FOUR),e.writeUint32(n)):(e.writeUint8(r|l.EIGHT),e.writeBigUint64(BigInt(n)))}function ie(t,e,r){typeof t=="number"?R(t,e,c.TAG):typeof t=="object"&&!r.ignoreOriginalEncoding&&y.ENCODED in t?e.write(t[y.ENCODED]):t<=Number.MAX_SAFE_INTEGER?R(Number(t),e,c.TAG):(e.writeUint8(c.TAG<<5|l.EIGHT),e.writeBigUint64(BigInt(t)))}function Ct(t,e,r){let[n,s]=Gt(t);if(r.collapseBigInts&&(!r.largeNegativeAsBigInt||t>=-0x8000000000000000n)){if(n<=0xffffffffn){R(Number(t),e);return}if(n<=0xffffffffffffffffn){let u=(s?c.NEG_INT:c.POS_INT)<<5;e.writeUint8(u|l.EIGHT),e.writeBigUint64(n);return}}if(r.rejectBigInts)throw new Error(`Attempt to encode unwanted bigint: ${t}`);let i=s?h.NEG_BIGINT:h.POS_BIGINT,o=n.toString(16),a=o.length%2?"0":"";ie(i,e,r);let d=Ie(a+o);R(d.length,e,c.BYTE_STRING),e.write(d)}function Cr(t,e,r){r.flushToZero&&(t=Pt(t)),Object.is(t,-0)?r.simplifyNegativeZero?r.avoidInts?nt(0,e,r):R(0,e):nt(t,e,r):!r.avoidInts&&Number.isSafeInteger(t)?R(t,e):r.reduceUnsafeNumbers&&Math.floor(t)===t&&t>=ne.MIN&&t<=ne.MAX?Ct(BigInt(t),e,r):nt(t,e,r)}function Hr(t,e,r){let n=r.stringNormalization?t.normalize(r.stringNormalization):t;if(r.wtf8&&!t.isWellFormed()){let s=Gr.encode(n);ie(h.WTF8,e,r),R(s.length,e,c.BYTE_STRING),e.write(s)}else{let s=qr.encode(n);R(s.length,e,c.UTF8_STRING),e.write(s)}}function Vr(t,e,r){let n=t;Be(n,n.length,c.ARRAY,e,r);for(let s of n)H(s,e,r)}function zr(t,e){R(t.length,e,c.BYTE_STRING),e.write(t)}var _e=new he;_e.registerEncoder(Array,Vr),_e.registerEncoder(Uint8Array,zr);function b(t,e){return _e.registerEncoder(t,e)}function Be(t,e,r,n,s){let i=Et(t);i&&!s.ignoreOriginalEncoding?n.write(i):R(e,n,r)}function Qr(t,e,r){if(t===null){e.writeUint8(jr);return}if(!r.ignoreOriginalEncoding&&y.ENCODED in t){e.write(t[y.ENCODED]);return}let n=t.constructor;if(n){let i=r.types?.get(n)??(r.ignoreGlobalTags?void 0:_e.get(n));if(i){let o=i(t,e,r);if(o!==void 0){if(!Array.isArray(o)||o.length!==2)throw new Error("Invalid encoder return value");(typeof o[0]=="bigint"||isFinite(Number(o[0])))&&ie(o[0],e,r),H(o[1],e,r)}return}}if(typeof t.toCBOR=="function"){let i=t.toCBOR(e,r);i&&((typeof i[0]=="bigint"||isFinite(Number(i[0])))&&ie(i[0],e,r),H(i[1],e,r));return}if(typeof t.toJSON=="function"){H(t.toJSON(),e,r);return}let s=Object.entries(t).map(i=>[i[0],i[1],A(i[0],r)]);r.sortKeys&&s.sort(r.sortKeys),Be(t,s.length,c.MAP,e,r);for(let[i,o,a]of s)e.write(a),H(o,e,r)}function H(t,e,r){switch(typeof t){case"number":Cr(t,e,r);break;case"bigint":Ct(t,e,r);break;case"string":Hr(t,e,r);break;case"boolean":e.writeUint8(t?Fr:$r);break;case"undefined":if(r.rejectUndefined)throw new Error("Attempt to encode unwanted undefined.");e.writeUint8(kr);break;case"object":Qr(t,e,r);break;case"symbol":throw new TypeError(`Unknown symbol: ${t.toString()}`);default:throw new TypeError(`Unknown type: ${typeof t}, ${String(t)}`)}}function A(t,e={}){let r={...De};e.dcbor?Object.assign(r,qt):e.cde&&Object.assign(r,st),Object.assign(r,e);let n=new se(r);return H(t,n,r),n.read()}var Z=(t=>(t[t.NEVER=-1]="NEVER",t[t.PREFERRED=0]="PREFERRED",t[t.ALWAYS=1]="ALWAYS",t))(Z||{});var x=class t{static KnownSimple=new Map([[v.FALSE,!1],[v.TRUE,!0],[v.NULL,null],[v.UNDEFINED,void 0]]);value;constructor(e){this.value=e}static create(e){return t.KnownSimple.has(e)?t.KnownSimple.get(e):new t(e)}toCBOR(e,r){if(r.rejectCustomSimples)throw new Error(`Cannot encode non-standard Simple value: ${this.value}`);R(this.value,e,c.SIMPLE_FLOAT)}toString(){return`simple(${this.value})`}decode(){return t.KnownSimple.has(this.value)?t.KnownSimple.get(this.value):this}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return`simple(${n(this.value,r)})`}};var Kr=new TextDecoder("utf8",{fatal:!0,ignoreBOM:!0}),U=class t{static defaultOptions={maxDepth:1024,encoding:"hex",requirePreferred:!1};#e;#t;#r=0;#n;constructor(e,r){if(this.#n={...t.defaultOptions,...r},typeof e=="string")switch(this.#n.encoding){case"hex":this.#e=Ie(e);break;case"base64":this.#e=le(e);break;default:throw new TypeError(`Encoding not implemented: "${this.#n.encoding}"`)}else this.#e=e;this.#t=new DataView(this.#e.buffer,this.#e.byteOffset,this.#e.byteLength)}toHere(e){return pe(this.#e,e,this.#r)}*[Symbol.iterator](){if(yield*this.#s(0),this.#r!==this.#e.length)throw new Error("Extra data in input")}*seq(){for(;this.#r<this.#e.length;)yield*this.#s(0)}*#s(e){if(e++>this.#n.maxDepth)throw new Error(`Maximum depth ${this.#n.maxDepth} exceeded`);let r=this.#r,n=this.#t.getUint8(this.#r++),s=n>>5,i=n&31,o=i,a=!1,d=0;switch(i){case l.ONE:if(d=1,o=this.#t.getUint8(this.#r),s===c.SIMPLE_FLOAT){if(o<32)throw new Error(`Invalid simple encoding in extra byte: ${o}`);a=!0}else if(this.#n.requirePreferred&&o<24)throw new Error(`Unexpectedly long integer encoding (1) for ${o}`);break;case l.TWO:if(d=2,s===c.SIMPLE_FLOAT)o=tt(this.#e,this.#r);else if(o=this.#t.getUint16(this.#r,!1),this.#n.requirePreferred&&o<=255)throw new Error(`Unexpectedly long integer encoding (2) for ${o}`);break;case l.FOUR:if(d=4,s===c.SIMPLE_FLOAT)o=this.#t.getFloat32(this.#r,!1);else if(o=this.#t.getUint32(this.#r,!1),this.#n.requirePreferred&&o<=65535)throw new Error(`Unexpectedly long integer encoding (4) for ${o}`);break;case l.EIGHT:{if(d=8,s===c.SIMPLE_FLOAT)o=this.#t.getFloat64(this.#r,!1);else if(o=this.#t.getBigUint64(this.#r,!1),o<=Number.MAX_SAFE_INTEGER&&(o=Number(o)),this.#n.requirePreferred&&o<=4294967295)throw new Error(`Unexpectedly long integer encoding (8) for ${o}`);break}case 28:case 29:case 30:throw new Error(`Additional info not implemented: ${i}`);case l.INDEFINITE:switch(s){case c.POS_INT:case c.NEG_INT:case c.TAG:throw new Error(`Invalid indefinite encoding for MT ${s}`);case c.SIMPLE_FLOAT:yield[s,i,y.BREAK,r,0];return}o=1/0;break;default:a=!0}switch(this.#r+=d,s){case c.POS_INT:yield[s,i,o,r,d];break;case c.NEG_INT:yield[s,i,typeof o=="bigint"?-1n-o:-1-Number(o),r,d];break;case c.BYTE_STRING:o===1/0?yield*this.#c(s,e,r):yield[s,i,this.#o(o),r,o];break;case c.UTF8_STRING:o===1/0?yield*this.#c(s,e,r):yield[s,i,Kr.decode(this.#o(o)),r,o];break;case c.ARRAY:if(o===1/0)yield*this.#c(s,e,r,!1);else{let u=Number(o);yield[s,i,u,r,d];for(let f=0;f<u;f++)yield*this.#s(e+1)}break;case c.MAP:if(o===1/0)yield*this.#c(s,e,r,!1);else{let u=Number(o);yield[s,i,u,r,d];for(let f=0;f<u;f++)yield*this.#s(e),yield*this.#s(e)}break;case c.TAG:yield[s,i,o,r,d],yield*this.#s(e);break;case c.SIMPLE_FLOAT:{let u=o;a&&(o=x.create(Number(o))),yield[s,i,o,r,u];break}}}#o(e){let r=pe(this.#e,this.#r,this.#r+=e);if(r.length!==e)throw new Error(`Unexpected end of stream reading ${e} bytes, got ${r.length}`);return r}*#c(e,r,n,s=!0){for(yield[e,l.INDEFINITE,1/0,n,1/0];;){let i=this.#s(r),o=i.next(),[a,d,u]=o.value;if(u===y.BREAK){yield o.value,i.next();return}if(s){if(a!==e)throw new Error(`Unmatched major type. Expected ${e}, got ${a}.`);if(d===l.INDEFINITE)throw new Error("New stream started in typed stream")}yield o.value,yield*i}}};var Yr=new Map([[l.ZERO,1],[l.ONE,2],[l.TWO,3],[l.FOUR,5],[l.EIGHT,9]]),Wr=new Uint8Array(0);function Jr(t,e){return!e.boxed&&!e.preferMap&&t.every(([r])=>typeof r=="string")?Object.fromEntries(t):new Map(t)}var w=class t{static defaultDecodeOptions={...U.defaultOptions,ParentType:t,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:Z.PREFERRED,collapseBigInts:!1,convertUnsafeIntsToFloat:!1,createObject:Jr,keepNanPayloads:!1,pretty:!1,preferBigInt:!1,preferMap:!1,rejectLargeNegatives:!1,rejectBigInts:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectInts:!1,rejectLongLoundNaN:!1,rejectLongFloats:!1,rejectNegativeZero:!1,rejectSimple:!1,rejectStreaming:!1,rejectStringsNotNormalizedAs:null,rejectSubnormals:!1,rejectUndefined:!1,rejectUnsafeFloatInts:!1,saveOriginal:!1,sortKeys:null,tags:null,ignoreGlobalTags:!1};static cdeDecodeOptions={cde:!0,rejectStreaming:!0,requirePreferred:!0,sortKeys:Se};static dcborDecodeOptions={...this.cdeDecodeOptions,dcbor:!0,convertUnsafeIntsToFloat:!0,rejectDuplicateKeys:!0,rejectLargeNegatives:!0,rejectLongLoundNaN:!0,rejectLongFloats:!0,rejectNegativeZero:!0,rejectSimple:!0,rejectUndefined:!0,rejectUnsafeFloatInts:!0,rejectStringsNotNormalizedAs:"NFC"};parent;mt;ai;left;offset;count=0;children=[];depth=0;#e;#t=null;constructor(e,r,n,s){if([this.mt,this.ai,,this.offset]=e,this.left=r,this.parent=n,this.#e=s,n&&(this.depth=n.depth+1),this.mt===c.MAP&&(this.#e.sortKeys||this.#e.rejectDuplicateKeys)&&(this.#t=[]),this.#e.rejectStreaming&&this.ai===l.INDEFINITE)throw new Error("Streaming not supported")}get isStreaming(){return this.left===1/0}get done(){return this.left===0}static create(e,r,n,s){let[i,o,a,d]=e;switch(i){case c.POS_INT:case c.NEG_INT:{if(n.rejectInts)throw new Error(`Unexpected integer: ${a}`);if(n.rejectLargeNegatives&&a<-0x8000000000000000n)throw new Error(`Invalid 65bit negative number: ${a}`);let u=a;return n.preferBigInt?u=BigInt(u):n.convertUnsafeIntsToFloat&&u>=ne.MIN&&u<=ne.MAX&&(u=Number(a)),n.boxed?C(u,s.toHere(d)):u}case c.SIMPLE_FLOAT:if(o>l.ONE){if(typeof a=="symbol")return a;if(n.rejectFloats)throw new Error(`Decoding unwanted floating point number: ${a}`);if(n.rejectNegativeZero&&Object.is(a,-0))throw new Error("Decoding negative zero");if(isNaN(a)){let u=s.toHere(d),f=new be(u);if(n.rejectLongLoundNaN){if(f.payload||u.length>3)throw new Error(`Invalid NaN encoding: "${E(u)}"`)}else if(n.keepNanPayloads&&(f.payload||f.sign===-1)){if(n.rejectLongFloats&&!f.isShortestEncoding)throw new Error(`NaN should have been encoded shorter: ${a}`);return f}}if(n.rejectSubnormals&&Ft(s.toHere(d+1)),n.rejectLongFloats){let u=A(a,{chunkSize:9,reduceUnsafeNumbers:n.rejectUnsafeFloatInts});if(u[0]>>5!==i)throw new Error(`Should have been encoded as int, not float: ${a}`);if(u.length<Yr.get(o))throw new Error(`Number should have been encoded shorter: ${a}`)}if(typeof a=="number"&&n.boxed)return C(a,s.toHere(d))}else{if(n.rejectSimple&&a instanceof x)throw new Error(`Invalid simple value: ${a}`);if(n.rejectUndefined&&a===void 0)throw new Error("Unexpected undefined")}return a;case c.BYTE_STRING:case c.UTF8_STRING:if(a===1/0)return new n.ParentType(e,1/0,r,n);if(n.rejectStringsNotNormalizedAs&&typeof a=="string"){let u=a.normalize(n.rejectStringsNotNormalizedAs);if(a!==u)throw new Error(`String not normalized as "${n.rejectStringsNotNormalizedAs}", got [${Ze(a)}] instead of [${Ze(u)}]`)}return n.boxed?C(a,s.toHere(d)):a;case c.ARRAY:return new n.ParentType(e,a,r,n);case c.MAP:return new n.ParentType(e,a*2,r,n);case c.TAG:{let u=new n.ParentType(e,1,r,n);return u.children=new p(a),u}}throw new TypeError(`Invalid major type: ${i}`)}static decodeToEncodeOpts(e){return{...De,avoidInts:e.rejectInts,float64:!e.rejectLongFloats,flushToZero:e.rejectSubnormals,largeNegativeAsBigInt:e.rejectLargeNegatives,sortKeys:e.sortKeys}}push(e,r,n){if(this.children.push(e),this.#t){let s=q(e)||r.toHere(n);this.#t.push(s)}return--this.left}replaceLast(e,r,n){let s,i=-1/0;if(this.children instanceof p?(i=0,s=this.children.contents,this.children.contents=e):(i=this.children.length-1,s=this.children[i],this.children[i]=e),this.#t){let o=q(e)||n.toHere(r.offset);this.#t[i]=o}return s}convert(e){let r;switch(this.mt){case c.ARRAY:r=this.children;break;case c.MAP:{let n=this.#r();if(this.#e.sortKeys){let s;for(let i of n){if(s&&this.#e.sortKeys(s,i)>=0)throw new Error(`Duplicate or out of order key: "0x${i[2]}"`);s=i}}else if(this.#e.rejectDuplicateKeys){let s=new Set;for(let[i,o,a]of n){let d=E(a);if(s.has(d))throw new Error(`Duplicate key: "0x${d}"`);s.add(d)}}r=this.#e.createObject(n,this.#e);break}case c.BYTE_STRING:return Rt(this.children);case c.UTF8_STRING:{let n=this.children.join("");r=this.#e.boxed?C(n,e.toHere(this.offset)):n;break}case c.TAG:r=this.children.decode(this.#e);break;default:throw new TypeError(`Invalid mt on convert: ${this.mt}`)}return this.#e.saveOriginal&&r&&typeof r=="object"&&G(r,e.toHere(this.offset)),r}#r(){let e=this.children,r=e.length;if(r%2)throw new Error("Missing map value");let n=new Array(r/2);if(this.#t)for(let s=0;s<r;s+=2)n[s>>1]=[e[s],e[s+1],this.#t[s]];else for(let s=0;s<r;s+=2)n[s>>1]=[e[s],e[s+1],Wr];return n}};var ot=" ",Zr=new TextEncoder,Me=class extends w{close="";quote='"';get isEmptyStream(){return(this.mt===c.UTF8_STRING||this.mt===c.BYTE_STRING)&&this.count===0}};function V(t,e,r,n){let s="";if(e===l.INDEFINITE)s+="_";else{if(n.diagnosticSizes===Z.NEVER)return"";{let i=n.diagnosticSizes===Z.ALWAYS;if(!i){let o=l.ZERO;if(Object.is(r,-0))o=l.TWO;else if(t===c.POS_INT||t===c.NEG_INT){let a=r<0,d=typeof r=="bigint"?1n:1,u=a?-r-d:r;u<=23?o=Number(u):u<=255?o=l.ONE:u<=65535?o=l.TWO:u<=4294967295?o=l.FOUR:o=l.EIGHT}else isFinite(r)?Math.fround(r)===r?Ne(r)==null?o=l.FOUR:o=l.TWO:o=l.EIGHT:o=l.TWO;i=o!==e}i&&(s+="_",e<l.ONE?s+="i":s+=String(e-24))}}return s}function it(t,e){let r={...w.defaultDecodeOptions,...e,ParentType:Me},n=new U(t,r),s,i,o="";for(let a of n){let[d,u,f]=a;switch(s&&(s.count>0&&f!==y.BREAK&&(s.mt===c.MAP&&s.count%2?o+=": ":(o+=",",r.pretty||(o+=" "))),r.pretty&&(s.mt!==c.MAP||s.count%2===0)&&(o+=`
|
|
1
|
+
var hr=Object.defineProperty;var K=(t,e)=>{for(var r in e)hr(t,r,{get:e[r],enumerable:!0})};var mr={};var We=["trace","debug","info","warn","error","none"];var X=t=>We.indexOf(t)>=We.indexOf(console.logLevel);Object.defineProperty(globalThis.console,"logLevel",{get(){return process.env.LOG_LEVEL||"info"}});var ee=console;globalThis.console={...globalThis.console,trace:(...t)=>{X("trace")&&ee.trace("[TRACE]",...t)},debug:(...t)=>{X("debug")&&ee.debug("[DEBUG]",...t)},info:(...t)=>{X("info")&&ee.info("[INFO]",...t)},log:(...t)=>{X("info")&&ee.log("[INFO]",...t)},warn:(...t)=>{X("warn")&&ee.warn("[WARN]",...t)},error:(...t)=>{X("error")&&ee.error("[ERROR]",...t)}};import an from"@EntryPoint";var te={};K(te,{guest:()=>yr,host:()=>gr});import*as P from"m1cro:common/host";var gr={getTenant:()=>P.getTenant(),getArtifact:t=>P.getArtifact(t),getCRD:t=>P.getCRD(t),listProviders:t=>P.listProviders(t)},yr={getManifest:()=>Y.manifest};var F={};K(F,{host:()=>br});import*as N from"m1cro:crypto/host";var br={deriveKey:(t,e)=>N.deriveKey(t,e),aesGcmEncrypt:t=>N.aesGcmEncrypt(t),aesGcmDecrypt:t=>N.aesGcmDecrypt(t),argon2Hash:(t,e,r,n,s,i)=>N.argon2Hash(t,e,r,n,s,i),argon2Verify:(t,e,r,n,s,i,o)=>N.argon2Verify(t,e,r,n,s,i,o)};var I={};K(I,{host:()=>wr});import*as $ from"m1cro:entity/host";var wr={find:async t=>await $.find(t),insert:async t=>await $.insert(t),update:async t=>await $.update(t),remove:async t=>await $.remove(t)};var W={};K(W,{host:()=>Er});import*as k from"m1cro:kv/host";var Er={get:async t=>await k.get(t),getDel:async t=>await k.getDel(t),set:async(t,e,r)=>await k.set(t,e,r),delete:async t=>await k.delete(t)};var j={};K(j,{fromRequest:()=>Ir,fromResponse:()=>wt,guest:()=>Rr,host:()=>Tr,toRequest:()=>bt,toResponse:()=>Sr,types:()=>ue});import*as ue from"m1cro:rpc/types";import*as yt from"m1cro:rpc/host";var re=class{get tenant(){return te.host.getTenant()}};var Tr={call:async t=>await yt.call(t)},Rr={call:async(t,e,r,n)=>{let s=Y.router.routes[t];if(!s)throw new Error(`Route not found for index ${t}`);let i=new re;console.debug("converting request to m1cro request");let o=await bt(r);console.debug("calling route handler");let a=await s.handler(o,i);return console.debug("converting response to m1cro response"),await wt(a)}},Ir=async t=>{let e=new ue.Request,r=t.method.toLowerCase();switch(r){case"get":case"post":case"put":case"patch":case"delete":e.setMethod({tag:r});break;default:throw new Error(`Invalid method: ${r}`)}e.setUrl(t.url),e.setHeaders(Array.from(t.headers.entries()));let n=await t.bytes();return e.setBody(n),e},bt=async t=>{let e="http://"+t.getUrl(),r={method:t.getMethod().tag,headers:new Headers(t.getHeaders())},n=t.getBody();return n.length>0&&(r.body=n.buffer),new Request(e,r)},wt=async t=>{let e=new ue.Response;e.setStatus(t.status),e.setHeaders(Array.from(t.headers.entries()));let r=await t.arrayBuffer();return e.setBody(r),e},Sr=async t=>{let e=t.body();return new Response(e.length>0?e.buffer:null,{headers:t.getHeaders(),status:t.getStatus()})};import*as xr from"m1cro:log/host";var ae={};K(ae,{guest:()=>sn,host:()=>nn});var c={POS_INT:0,NEG_INT:1,BYTE_STRING:2,UTF8_STRING:3,ARRAY:4,MAP:5,TAG:6,SIMPLE_FLOAT:7},h={DATE_STRING:0,DATE_EPOCH:1,POS_BIGINT:2,NEG_BIGINT:3,DECIMAL_FRAC:4,BIGFLOAT:5,BASE64URL_EXPECTED:21,BASE64_EXPECTED:22,BASE16_EXPECTED:23,CBOR:24,URI:32,BASE64URL:33,BASE64:34,MIME:36,DATE_EPOCH_DAYS:100,SET:258,JSON:262,WTF8:273,DATE_FULL:1004,REGEXP:21066,SELF_DESCRIBED:55799,INVALID_16:65535,INVALID_32:4294967295,INVALID_64:0xffffffffffffffffn},l={ZERO:0,ONE:24,TWO:25,FOUR:26,EIGHT:27,INDEFINITE:31},v={FALSE:20,TRUE:21,NULL:22,UNDEFINED:23},y=class{static BREAK=Symbol.for("github.com/hildjj/cbor2/break");static ENCODED=Symbol.for("github.com/hildjj/cbor2/cbor-encoded");static LENGTH=Symbol.for("github.com/hildjj/cbor2/length")},ne={MIN:-(2n**63n),MAX:2n**64n-1n};var p=class t{static#e=new Map;tag;contents;constructor(e,r=void 0){this.tag=e,this.contents=r}get noChildren(){return!!t.#e.get(this.tag)?.noChildren}static registerDecoder(e,r,n){let s=this.#e.get(e);return this.#e.set(e,r),s&&("comment"in r||(r.comment=s.comment),"noChildren"in r||(r.noChildren=s.noChildren)),n&&!r.comment&&(r.comment=()=>`(${n})`),s}static clearDecoder(e){let r=this.#e.get(e);return this.#e.delete(e),r}static getDecoder(e){return this.#e.get(e)}static getAllDecoders(){return new Map(this.#e)}*[Symbol.iterator](){yield this.contents}push(e){return this.contents=e,1}decode(e){let r=e?.tags?.get(this.tag)??(e?.ignoreGlobalTags?void 0:t.#e.get(this.tag));return r?r(this,e):this}comment(e,r){let n=e?.tags?.get(this.tag)??(e?.ignoreGlobalTags?void 0:t.#e.get(this.tag));if(n?.comment)return n.comment(this,e,r)}toCBOR(){return[this.tag,this.contents]}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return`${this.tag}(${n(this.contents,r)})`}};function q(t){if(t!=null&&typeof t=="object")return t[y.ENCODED]}function Et(t){if(t!=null&&typeof t=="object")return t[y.LENGTH]}function G(t,e){Object.defineProperty(t,y.ENCODED,{configurable:!0,enumerable:!1,value:e})}function C(t,e){let r=Object(t);return G(r,e),r}var Je=Symbol("CBOR_RANGES");function Tt(t,e){Object.defineProperty(t,Je,{configurable:!1,enumerable:!1,writable:!1,value:e})}function fe(t){return t[Je]}function Nr(t){return fe(t)!==void 0}function pe(t,e=0,r=t.length-1){let n=t.subarray(e,r),s=fe(t);if(s){let i=[];for(let o of s)if(o[0]>=e&&o[0]+o[1]<=r){let a=[...o];a[0]-=e,i.push(a)}i.length&&Tt(n,i)}return n}function Ie(t){let e=Math.ceil(t.length/2),r=new Uint8Array(e);e--;for(let n=t.length,s=n-2;n>=0;n=s,s-=2,e--)r[e]=parseInt(t.substring(s,n),16);return r}function E(t){return t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")}function Rt(t){let e=t.reduce((o,a)=>o+a.length,0),r=t.some(o=>Nr(o)),n=[],s=new Uint8Array(e),i=0;for(let o of t){if(!(o instanceof Uint8Array))throw new TypeError(`Invalid array: ${o}`);if(s.set(o,i),r){let a=o[Je]??[[0,o.length]];for(let d of a)d[0]+=i;n.push(...a)}i+=o.length}return r&&Tt(s,n),s}function le(t){let e=atob(t);return Uint8Array.from(e,r=>r.codePointAt(0))}var vr={"-":"+",_:"/"};function It(t){let e=t.replace(/[_-]/g,r=>vr[r]);return le(e.padEnd(Math.ceil(e.length/4)*4,"="))}function St(){let t=new Uint8Array(4),e=new Uint32Array(t.buffer);return!((e[0]=1)&t[0])}function Ze(t){let e="";for(let r of t){let n=r.codePointAt(0)?.toString(16).padStart(4,"0");e&&(e+=", "),e+=`U+${n}`}return e}var he=class{#e=new Map;registerEncoder(e,r){let n=this.#e.get(e);return this.#e.set(e,r),n}get(e){return this.#e.get(e)}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}};function Se(t,e){let[r,n,s]=t,[i,o,a]=e,d=Math.min(s.length,a.length);for(let u=0;u<d;u++){let f=s[u]-a[u];if(f!==0)return f}return 0}var se=class t{static defaultOptions={chunkSize:4096};#e;#t=[];#r=null;#n=0;#s=0;constructor(e={}){if(this.#e={...t.defaultOptions,...e},this.#e.chunkSize<8)throw new RangeError(`Expected size >= 8, got ${this.#e.chunkSize}`);this.#o()}get length(){return this.#s}read(){this.#c();let e=new Uint8Array(this.#s),r=0;for(let n of this.#t)e.set(n,r),r+=n.length;return this.#o(),e}write(e){let r=e.length;r>this.#d()?(this.#c(),r>this.#e.chunkSize?(this.#t.push(e),this.#o()):(this.#o(),this.#t[this.#t.length-1].set(e),this.#n=r)):(this.#t[this.#t.length-1].set(e,this.#n),this.#n+=r),this.#s+=r}writeUint8(e){this.#i(1),this.#r.setUint8(this.#n,e),this.#a(1)}writeUint16(e,r=!1){this.#i(2),this.#r.setUint16(this.#n,e,r),this.#a(2)}writeUint32(e,r=!1){this.#i(4),this.#r.setUint32(this.#n,e,r),this.#a(4)}writeBigUint64(e,r=!1){this.#i(8),this.#r.setBigUint64(this.#n,e,r),this.#a(8)}writeInt16(e,r=!1){this.#i(2),this.#r.setInt16(this.#n,e,r),this.#a(2)}writeInt32(e,r=!1){this.#i(4),this.#r.setInt32(this.#n,e,r),this.#a(4)}writeBigInt64(e,r=!1){this.#i(8),this.#r.setBigInt64(this.#n,e,r),this.#a(8)}writeFloat32(e,r=!1){this.#i(4),this.#r.setFloat32(this.#n,e,r),this.#a(4)}writeFloat64(e,r=!1){this.#i(8),this.#r.setFloat64(this.#n,e,r),this.#a(8)}clear(){this.#s=0,this.#t=[],this.#o()}#o(){let e=new Uint8Array(this.#e.chunkSize);this.#t.push(e),this.#n=0,this.#r=new DataView(e.buffer,e.byteOffset,e.byteLength)}#c(){if(this.#n===0){this.#t.pop();return}let e=this.#t.length-1;this.#t[e]=this.#t[e].subarray(0,this.#n),this.#n=0,this.#r=null}#d(){let e=this.#t.length-1;return this.#t[e].length-this.#n}#i(e){this.#d()<e&&(this.#c(),this.#o())}#a(e){this.#n+=e,this.#s+=e}};var Xe=1n<<15n,me=0b11111n<<10n,_t=1n<<9n,Dt=_t-1n,xt=_t|Dt,et=1n<<31n,ge=0b11111111n<<23n,Bt=1n<<22n,Mt=Bt-1n,Ot=Bt|Mt,xe=1n<<63n,D=0b11111111111n<<52n,ye=1n<<51n,Oe=ye-1n,Nt=ye|Oe,vt=Oe-(Dt<<42n),At=Oe-(Mt<<29n),Ar={2:"0b",8:"0o",16:"0x"},Lt=(t=>(t[t.NATURAL=-2]="NATURAL",t[t.UNKNOWN=-1]="UNKNOWN",t[t.F16=2]="F16",t[t.F32=4]="F32",t[t.F64=8]="F64",t))(Lt||{});function Ut(t,e,r,n){let s="nan'";return t.quiet||(s+="!"),t.sign===-1&&(s+="-"),s+=n(Math.abs(t.payload),r),s+="'",s+=t.encodingIndicator,s}var be=class extends Number{#e;#t=-1;constructor(e,r=!0,n=-1){super(NaN);let s=e;if(typeof e=="number"){if(!Number.isSafeInteger(e))throw new Error(`Invalid NAN payload: ${e}`);e=BigInt(e);let i=0n;if(e<0&&(i=xe,e=-e),e>=ye)throw new Error(`Payload too large: ${s}`);let o=r?ye:0n;switch(this.#e=i|D|o|e,n){case-2:throw new Error("NAN_SIZE.NATURAL only valid for bigint constructor");case-1:n=this.preferredSize;break;case 2:if(this.#e&vt)throw new Error("Invalid size for payload");break;case 4:if(this.#e&At)throw new Error("Invalid size for payload");break;case 8:break;default:throw new Error(`Invalid size: ${n}`)}this.#t=n}else if(typeof e=="bigint"){let i=-1;if((e&D)===D)this.#e=e,i=8;else if((e&ge)===ge){let o=(e&et)<<32n;this.#e=o|D|(e&Ot)<<29n,i=4}else if((e&me)===me){let o=(e&Xe)<<48n;this.#e=o|D|(e&xt)<<42n,i=2}else throw new Error(`Invalid raw NaN value: ${e}`);if(n===-1)this.#t=this.preferredSize;else if(n===-2)this.#t=i;else{if(n<i)throw new Error("Invalid bigint NaN size");this.#t=n}}else{let i=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.length){case 3:{if(e[0]!==249)throw new Error("Invalid CBOR encoding for half float");let o=BigInt(i.getUint16(1,!1));if((o&me)!==me)throw new Error("Not a NaN");let a=(o&Xe)<<48n;this.#e=a|D|(o&xt)<<42n,this.#t=2;break}case 5:{if(e[0]!==250)throw new Error("Invalid CBOR encoding for single float");let o=BigInt(i.getUint32(1,!1));if((o&ge)!==ge)throw new Error("Not a NaN");let a=(o&et)<<32n;this.#e=a|D|(o&Ot)<<29n,this.#t=4;break}case 9:{if(e[0]!==251)throw new Error("Invalid CBOR encoding for double float");if(this.#e=i.getBigUint64(1,!1),(this.#e&D)!==D)throw new Error("Not a NaN (NaNaN)");this.#t=8;break}default:throw new RangeError(`Invalid NAN size (should be 2, 4, or 8): ${e.length-1}`)}}if(!this.payload&&!this.quiet)throw new Error("Signalling NaN with zero payload")}get bytes(){let e=new ArrayBuffer(this.#t+1),r=new DataView(e);switch(this.#t){case 2:{r.setUint8(0,249);let n=(this.#e&xe?Xe:0n)|me|(this.#e&Nt)>>42n;r.setUint16(1,Number(n),!1);break}case 4:{r.setUint8(0,250);let n=(this.#e&xe?et:0n)|ge|(this.#e&Nt)>>29n;r.setUint32(1,Number(n),!1);break}case 8:r.setUint8(0,251),r.setBigUint64(1,this.#e);break}return new Uint8Array(e)}get quiet(){return!!(this.#e&ye)}get sign(){return this.#e&xe?-1:1}get payload(){return Number(this.#e&Oe)*this.sign}get raw(){return this.#e}get encodingIndicator(){switch(this.#t){case 2:return"_1";case 4:return"_2"}return"_3"}get size(){return this.#t}get preferredSize(){return(this.#e&vt)===0n?2:(this.#e&At)===0n?4:8}get isShortestEncoding(){return this.preferredSize===this.#t}toCBOR(e){e.write(this.bytes)}toString(e=10){return Ut(this,1,{},r=>(Ar[e]??"")+r.toString(e))}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return Ut(this,e,r,n)}};function tt(t,e=0,r=!1){let n=t[e]&128?-1:1,s=(t[e]&124)>>2,i=(t[e]&3)<<8|t[e+1];if(s===0){if(r&&i!==0)throw new Error(`Unwanted subnormal: ${n*5960464477539063e-23*i}`);return n*5960464477539063e-23*i}else if(s===31)return i?NaN:n*(1/0);return n*2**(s-25)*(1024+i)}function Ne(t){let e=new DataView(new ArrayBuffer(4));e.setFloat32(0,t,!1);let r=e.getUint32(0,!1);if((r&8191)!==0)return null;let n=r>>16&32768,s=r>>23&255,i=r&8388607;if(!(s===0&&i===0))if(s>=113&&s<=142)n+=(s-112<<10)+(i>>13);else if(s>=103&&s<113){if(i&(1<<126-s)-1)return null;n+=i+8388608>>126-s}else if(s===255)n|=31744,n|=i>>13;else return null;return n}function Pt(t){if(t!==0){let e=new ArrayBuffer(8),r=new DataView(e);r.setFloat64(0,t,!1);let n=r.getBigUint64(0,!1);if((n&0x7ff0000000000000n)===0n)return n&0x8000000000000000n?-0:0}return t}function Ft(t){switch(t.length){case 2:tt(t,0,!0);break;case 4:{let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=e.getUint32(0,!1);if((r&2139095040)===0&&r&8388607)throw new Error(`Unwanted subnormal: ${e.getFloat32(0,!1)}`);break}case 8:{let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=e.getBigUint64(0,!1);if((r&0x7ff0000000000000n)===0n&&r&0x000fffffffffffn)throw new Error(`Unwanted subnormal: ${e.getFloat64(0,!1)}`);break}default:throw new TypeError(`Bad input to isSubnormal: ${t}`)}}var we=class extends TypeError{code="ERR_ENCODING_INVALID_ENCODED_DATA";constructor(){super("The encoded data was not valid for encoding wtf-8")}},ve=class extends RangeError{code="ERR_ENCODING_NOT_SUPPORTED";constructor(e){super(`Invalid encoding: "${e}"`)}};var Ae=new Uint8Array(0);var rt=55296,$t=56320,kt=65533,Ue="wtf-8";function _r(t){return t&&!(t instanceof ArrayBuffer)&&t.buffer instanceof ArrayBuffer}function Dr(t){return t?t instanceof Uint8Array?t:_r(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t):Ae}var Br=[0,0,0,0,0,0,0,0,-1,-1,-1,-1,1,1,2,3],J=class t{static DEFAULT_BUFFERSIZE=4096;encoding=Ue;fatal;ignoreBOM;bufferSize;#e=0;#t=0;#r=0;#n=!0;#s;constructor(e="wtf8",r=void 0){if(e.toLowerCase().replace("-","")!=="wtf8")throw new ve(e);if(this.fatal=!!r?.fatal,this.ignoreBOM=!!r?.ignoreBOM,this.bufferSize=Math.floor(r?.bufferSize??t.DEFAULT_BUFFERSIZE),isNaN(this.bufferSize)||this.bufferSize<1)throw new RangeError(`Invalid buffer size: ${r?.bufferSize}`);this.#s=new Uint16Array(this.bufferSize)}decode(e,r){let n=!!r?.stream,s=Dr(e),i=[],o=this.#s,a=this.bufferSize-3,d=0,u=()=>{if(this.#t=0,this.#e=0,this.#r=0,this.fatal)throw new we;o[d++]=kt},f=()=>{let g=this.#r;for(let O=0;O<g;O++)u()},m=g=>{if(this.#e===0)switch(Br[g>>4]){case-1:u();break;case 0:o[d++]=g;break;case 1:this.#t=g&31,(this.#t&30)===0?u():(this.#e=1,this.#r=1);break;case 2:this.#t=g&15,this.#e=2,this.#r=1;break;case 3:g&8?u():(this.#t=g&7,this.#e=3,this.#r=1);break}else{if((g&192)!==128||this.#r===1&&this.#e===2&&this.#t===0&&(g&32)===0||this.#e===3&&this.#t===0&&(g&48)===0)return f(),m(g);if(this.#t=this.#t<<6|g&63,this.#r++,--this.#e===0){if(this.ignoreBOM||!this.#n||this.#t!==65279)if(this.#t<65536)o[d++]=this.#t;else{let O=this.#t-65536;o[d++]=O>>>10&1023|rt,o[d++]=O&1023|$t}this.#t=0,this.#r=0,this.#n=!1}}};for(let g of s)d>=a&&(i.push(String.fromCharCode.apply(null,o.subarray(0,d))),d=0),m(g);return n||(this.#n=!0,(this.#t||this.#e)&&f()),d>0&&i.push(String.fromCharCode.apply(null,o.subarray(0,d))),i.join("")}};function Mr(t){let e=0;for(let r of t){let n=r.codePointAt(0);n<128?e++:n<2048?e+=2:n<65536?e+=3:e+=4}return e}var oe=class{encoding=Ue;encode(e){if(!e)return Ae;let r=new Uint8Array(Mr(String(e)));return this.encodeInto(e,r),r}encodeInto(e,r){let n=String(e),s=n.length,i=r.length,o=0,a=0;for(a=0;a<s;a++){let d=n.codePointAt(a);if(d<128){if(o>=i)break;r[o++]=d}else if(d<2048){if(o>=i-1)break;r[o++]=192|d>>6,r[o++]=128|d&63}else if(d<65536){if(o>=i-2)break;r[o++]=224|d>>12,r[o++]=128|d>>6&63,r[o++]=128|d&63}else{if(o>=i-3)break;r[o++]=240|d>>18,r[o++]=128|d>>12&63,r[o++]=128|d>>6&63,r[o++]=128|d&63,a++}}return{read:a,written:o}}};var{ENCODED:es}=y,jt=c.SIMPLE_FLOAT<<5|l.TWO,Lr=c.SIMPLE_FLOAT<<5|l.FOUR,Pr=c.SIMPLE_FLOAT<<5|l.EIGHT,Fr=c.SIMPLE_FLOAT<<5|v.TRUE,$r=c.SIMPLE_FLOAT<<5|v.FALSE,kr=c.SIMPLE_FLOAT<<5|v.UNDEFINED,jr=c.SIMPLE_FLOAT<<5|v.NULL,qr=new TextEncoder,Gr=new oe,De={...se.defaultOptions,avoidInts:!1,cde:!1,collapseBigInts:!0,dateTag:h.DATE_EPOCH,dcbor:!1,float64:!1,flushToZero:!1,forceEndian:null,ignoreOriginalEncoding:!1,largeNegativeAsBigInt:!1,reduceUnsafeNumbers:!1,rejectBigInts:!1,rejectCustomSimples:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectUndefined:!1,simplifyNegativeZero:!1,sortKeys:null,stringNormalization:null,types:null,wtf8:!1,ignoreGlobalTags:!1},st={cde:!0,ignoreOriginalEncoding:!0,sortKeys:Se},qt={...st,dcbor:!0,largeNegativeAsBigInt:!0,reduceUnsafeNumbers:!0,rejectCustomSimples:!0,rejectDuplicateKeys:!0,rejectUndefined:!0,simplifyNegativeZero:!0,stringNormalization:"NFC"};function Gt(t){let e=t<0;return typeof t=="bigint"?[e?-t-1n:t,e]:[e?-t-1:t,e]}function nt(t,e,r){if(r.rejectFloats)throw new Error(`Attempt to encode an unwanted floating point number: ${t}`);if(isNaN(t))e.writeUint8(jt),e.writeUint16(32256);else if(!r.float64&&Math.fround(t)===t){let n=Ne(t);n===null?(e.writeUint8(Lr),e.writeFloat32(t)):(e.writeUint8(jt),e.writeUint16(n))}else e.writeUint8(Pr),e.writeFloat64(t)}function R(t,e,r){let[n,s]=Gt(t);if(s&&r)throw new TypeError(`Negative size: ${t}`);r??=s?c.NEG_INT:c.POS_INT,r<<=5,n<24?e.writeUint8(r|n):n<=255?(e.writeUint8(r|l.ONE),e.writeUint8(n)):n<=65535?(e.writeUint8(r|l.TWO),e.writeUint16(n)):n<=4294967295?(e.writeUint8(r|l.FOUR),e.writeUint32(n)):(e.writeUint8(r|l.EIGHT),e.writeBigUint64(BigInt(n)))}function ie(t,e,r){typeof t=="number"?R(t,e,c.TAG):typeof t=="object"&&!r.ignoreOriginalEncoding&&y.ENCODED in t?e.write(t[y.ENCODED]):t<=Number.MAX_SAFE_INTEGER?R(Number(t),e,c.TAG):(e.writeUint8(c.TAG<<5|l.EIGHT),e.writeBigUint64(BigInt(t)))}function Ct(t,e,r){let[n,s]=Gt(t);if(r.collapseBigInts&&(!r.largeNegativeAsBigInt||t>=-0x8000000000000000n)){if(n<=0xffffffffn){R(Number(t),e);return}if(n<=0xffffffffffffffffn){let u=(s?c.NEG_INT:c.POS_INT)<<5;e.writeUint8(u|l.EIGHT),e.writeBigUint64(n);return}}if(r.rejectBigInts)throw new Error(`Attempt to encode unwanted bigint: ${t}`);let i=s?h.NEG_BIGINT:h.POS_BIGINT,o=n.toString(16),a=o.length%2?"0":"";ie(i,e,r);let d=Ie(a+o);R(d.length,e,c.BYTE_STRING),e.write(d)}function Cr(t,e,r){r.flushToZero&&(t=Pt(t)),Object.is(t,-0)?r.simplifyNegativeZero?r.avoidInts?nt(0,e,r):R(0,e):nt(t,e,r):!r.avoidInts&&Number.isSafeInteger(t)?R(t,e):r.reduceUnsafeNumbers&&Math.floor(t)===t&&t>=ne.MIN&&t<=ne.MAX?Ct(BigInt(t),e,r):nt(t,e,r)}function Hr(t,e,r){let n=r.stringNormalization?t.normalize(r.stringNormalization):t;if(r.wtf8&&!t.isWellFormed()){let s=Gr.encode(n);ie(h.WTF8,e,r),R(s.length,e,c.BYTE_STRING),e.write(s)}else{let s=qr.encode(n);R(s.length,e,c.UTF8_STRING),e.write(s)}}function Vr(t,e,r){let n=t;Be(n,n.length,c.ARRAY,e,r);for(let s of n)H(s,e,r)}function zr(t,e){R(t.length,e,c.BYTE_STRING),e.write(t)}var _e=new he;_e.registerEncoder(Array,Vr),_e.registerEncoder(Uint8Array,zr);function b(t,e){return _e.registerEncoder(t,e)}function Be(t,e,r,n,s){let i=Et(t);i&&!s.ignoreOriginalEncoding?n.write(i):R(e,n,r)}function Qr(t,e,r){if(t===null){e.writeUint8(jr);return}if(!r.ignoreOriginalEncoding&&y.ENCODED in t){e.write(t[y.ENCODED]);return}let n=t.constructor;if(n){let i=r.types?.get(n)??(r.ignoreGlobalTags?void 0:_e.get(n));if(i){let o=i(t,e,r);if(o!==void 0){if(!Array.isArray(o)||o.length!==2)throw new Error("Invalid encoder return value");(typeof o[0]=="bigint"||isFinite(Number(o[0])))&&ie(o[0],e,r),H(o[1],e,r)}return}}if(typeof t.toCBOR=="function"){let i=t.toCBOR(e,r);i&&((typeof i[0]=="bigint"||isFinite(Number(i[0])))&&ie(i[0],e,r),H(i[1],e,r));return}if(typeof t.toJSON=="function"){H(t.toJSON(),e,r);return}let s=Object.entries(t).map(i=>[i[0],i[1],A(i[0],r)]);r.sortKeys&&s.sort(r.sortKeys),Be(t,s.length,c.MAP,e,r);for(let[i,o,a]of s)e.write(a),H(o,e,r)}function H(t,e,r){switch(typeof t){case"number":Cr(t,e,r);break;case"bigint":Ct(t,e,r);break;case"string":Hr(t,e,r);break;case"boolean":e.writeUint8(t?Fr:$r);break;case"undefined":if(r.rejectUndefined)throw new Error("Attempt to encode unwanted undefined.");e.writeUint8(kr);break;case"object":Qr(t,e,r);break;case"symbol":throw new TypeError(`Unknown symbol: ${t.toString()}`);default:throw new TypeError(`Unknown type: ${typeof t}, ${String(t)}`)}}function A(t,e={}){let r={...De};e.dcbor?Object.assign(r,qt):e.cde&&Object.assign(r,st),Object.assign(r,e);let n=new se(r);return H(t,n,r),n.read()}var Z=(t=>(t[t.NEVER=-1]="NEVER",t[t.PREFERRED=0]="PREFERRED",t[t.ALWAYS=1]="ALWAYS",t))(Z||{});var x=class t{static KnownSimple=new Map([[v.FALSE,!1],[v.TRUE,!0],[v.NULL,null],[v.UNDEFINED,void 0]]);value;constructor(e){this.value=e}static create(e){return t.KnownSimple.has(e)?t.KnownSimple.get(e):new t(e)}toCBOR(e,r){if(r.rejectCustomSimples)throw new Error(`Cannot encode non-standard Simple value: ${this.value}`);R(this.value,e,c.SIMPLE_FLOAT)}toString(){return`simple(${this.value})`}decode(){return t.KnownSimple.has(this.value)?t.KnownSimple.get(this.value):this}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return`simple(${n(this.value,r)})`}};var Kr=new TextDecoder("utf8",{fatal:!0,ignoreBOM:!0}),U=class t{static defaultOptions={maxDepth:1024,encoding:"hex",requirePreferred:!1};#e;#t;#r=0;#n;constructor(e,r){if(this.#n={...t.defaultOptions,...r},typeof e=="string")switch(this.#n.encoding){case"hex":this.#e=Ie(e);break;case"base64":this.#e=le(e);break;default:throw new TypeError(`Encoding not implemented: "${this.#n.encoding}"`)}else this.#e=e;this.#t=new DataView(this.#e.buffer,this.#e.byteOffset,this.#e.byteLength)}toHere(e){return pe(this.#e,e,this.#r)}*[Symbol.iterator](){if(yield*this.#s(0),this.#r!==this.#e.length)throw new Error("Extra data in input")}*seq(){for(;this.#r<this.#e.length;)yield*this.#s(0)}*#s(e){if(e++>this.#n.maxDepth)throw new Error(`Maximum depth ${this.#n.maxDepth} exceeded`);let r=this.#r,n=this.#t.getUint8(this.#r++),s=n>>5,i=n&31,o=i,a=!1,d=0;switch(i){case l.ONE:if(d=1,o=this.#t.getUint8(this.#r),s===c.SIMPLE_FLOAT){if(o<32)throw new Error(`Invalid simple encoding in extra byte: ${o}`);a=!0}else if(this.#n.requirePreferred&&o<24)throw new Error(`Unexpectedly long integer encoding (1) for ${o}`);break;case l.TWO:if(d=2,s===c.SIMPLE_FLOAT)o=tt(this.#e,this.#r);else if(o=this.#t.getUint16(this.#r,!1),this.#n.requirePreferred&&o<=255)throw new Error(`Unexpectedly long integer encoding (2) for ${o}`);break;case l.FOUR:if(d=4,s===c.SIMPLE_FLOAT)o=this.#t.getFloat32(this.#r,!1);else if(o=this.#t.getUint32(this.#r,!1),this.#n.requirePreferred&&o<=65535)throw new Error(`Unexpectedly long integer encoding (4) for ${o}`);break;case l.EIGHT:{if(d=8,s===c.SIMPLE_FLOAT)o=this.#t.getFloat64(this.#r,!1);else if(o=this.#t.getBigUint64(this.#r,!1),o<=Number.MAX_SAFE_INTEGER&&(o=Number(o)),this.#n.requirePreferred&&o<=4294967295)throw new Error(`Unexpectedly long integer encoding (8) for ${o}`);break}case 28:case 29:case 30:throw new Error(`Additional info not implemented: ${i}`);case l.INDEFINITE:switch(s){case c.POS_INT:case c.NEG_INT:case c.TAG:throw new Error(`Invalid indefinite encoding for MT ${s}`);case c.SIMPLE_FLOAT:yield[s,i,y.BREAK,r,0];return}o=1/0;break;default:a=!0}switch(this.#r+=d,s){case c.POS_INT:yield[s,i,o,r,d];break;case c.NEG_INT:yield[s,i,typeof o=="bigint"?-1n-o:-1-Number(o),r,d];break;case c.BYTE_STRING:o===1/0?yield*this.#c(s,e,r):yield[s,i,this.#o(o),r,o];break;case c.UTF8_STRING:o===1/0?yield*this.#c(s,e,r):yield[s,i,Kr.decode(this.#o(o)),r,o];break;case c.ARRAY:if(o===1/0)yield*this.#c(s,e,r,!1);else{let u=Number(o);yield[s,i,u,r,d];for(let f=0;f<u;f++)yield*this.#s(e+1)}break;case c.MAP:if(o===1/0)yield*this.#c(s,e,r,!1);else{let u=Number(o);yield[s,i,u,r,d];for(let f=0;f<u;f++)yield*this.#s(e),yield*this.#s(e)}break;case c.TAG:yield[s,i,o,r,d],yield*this.#s(e);break;case c.SIMPLE_FLOAT:{let u=o;a&&(o=x.create(Number(o))),yield[s,i,o,r,u];break}}}#o(e){let r=pe(this.#e,this.#r,this.#r+=e);if(r.length!==e)throw new Error(`Unexpected end of stream reading ${e} bytes, got ${r.length}`);return r}*#c(e,r,n,s=!0){for(yield[e,l.INDEFINITE,1/0,n,1/0];;){let i=this.#s(r),o=i.next(),[a,d,u]=o.value;if(u===y.BREAK){yield o.value,i.next();return}if(s){if(a!==e)throw new Error(`Unmatched major type. Expected ${e}, got ${a}.`);if(d===l.INDEFINITE)throw new Error("New stream started in typed stream")}yield o.value,yield*i}}};var Yr=new Map([[l.ZERO,1],[l.ONE,2],[l.TWO,3],[l.FOUR,5],[l.EIGHT,9]]),Wr=new Uint8Array(0);function Jr(t,e){return!e.boxed&&!e.preferMap&&t.every(([r])=>typeof r=="string")?Object.fromEntries(t):new Map(t)}var w=class t{static defaultDecodeOptions={...U.defaultOptions,ParentType:t,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:Z.PREFERRED,collapseBigInts:!1,convertUnsafeIntsToFloat:!1,createObject:Jr,keepNanPayloads:!1,pretty:!1,preferBigInt:!1,preferMap:!1,rejectLargeNegatives:!1,rejectBigInts:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectInts:!1,rejectLongLoundNaN:!1,rejectLongFloats:!1,rejectNegativeZero:!1,rejectSimple:!1,rejectStreaming:!1,rejectStringsNotNormalizedAs:null,rejectSubnormals:!1,rejectUndefined:!1,rejectUnsafeFloatInts:!1,saveOriginal:!1,sortKeys:null,tags:null,ignoreGlobalTags:!1};static cdeDecodeOptions={cde:!0,rejectStreaming:!0,requirePreferred:!0,sortKeys:Se};static dcborDecodeOptions={...this.cdeDecodeOptions,dcbor:!0,convertUnsafeIntsToFloat:!0,rejectDuplicateKeys:!0,rejectLargeNegatives:!0,rejectLongLoundNaN:!0,rejectLongFloats:!0,rejectNegativeZero:!0,rejectSimple:!0,rejectUndefined:!0,rejectUnsafeFloatInts:!0,rejectStringsNotNormalizedAs:"NFC"};parent;mt;ai;left;offset;count=0;children=[];depth=0;#e;#t=null;constructor(e,r,n,s){if([this.mt,this.ai,,this.offset]=e,this.left=r,this.parent=n,this.#e=s,n&&(this.depth=n.depth+1),this.mt===c.MAP&&(this.#e.sortKeys||this.#e.rejectDuplicateKeys)&&(this.#t=[]),this.#e.rejectStreaming&&this.ai===l.INDEFINITE)throw new Error("Streaming not supported")}get isStreaming(){return this.left===1/0}get done(){return this.left===0}static create(e,r,n,s){let[i,o,a,d]=e;switch(i){case c.POS_INT:case c.NEG_INT:{if(n.rejectInts)throw new Error(`Unexpected integer: ${a}`);if(n.rejectLargeNegatives&&a<-0x8000000000000000n)throw new Error(`Invalid 65bit negative number: ${a}`);let u=a;return n.preferBigInt?u=BigInt(u):n.convertUnsafeIntsToFloat&&u>=ne.MIN&&u<=ne.MAX&&(u=Number(a)),n.boxed?C(u,s.toHere(d)):u}case c.SIMPLE_FLOAT:if(o>l.ONE){if(typeof a=="symbol")return a;if(n.rejectFloats)throw new Error(`Decoding unwanted floating point number: ${a}`);if(n.rejectNegativeZero&&Object.is(a,-0))throw new Error("Decoding negative zero");if(isNaN(a)){let u=s.toHere(d),f=new be(u);if(n.rejectLongLoundNaN){if(f.payload||u.length>3)throw new Error(`Invalid NaN encoding: "${E(u)}"`)}else if(n.keepNanPayloads&&(f.payload||f.sign===-1)){if(n.rejectLongFloats&&!f.isShortestEncoding)throw new Error(`NaN should have been encoded shorter: ${a}`);return f}}if(n.rejectSubnormals&&Ft(s.toHere(d+1)),n.rejectLongFloats){let u=A(a,{chunkSize:9,reduceUnsafeNumbers:n.rejectUnsafeFloatInts});if(u[0]>>5!==i)throw new Error(`Should have been encoded as int, not float: ${a}`);if(u.length<Yr.get(o))throw new Error(`Number should have been encoded shorter: ${a}`)}if(typeof a=="number"&&n.boxed)return C(a,s.toHere(d))}else{if(n.rejectSimple&&a instanceof x)throw new Error(`Invalid simple value: ${a}`);if(n.rejectUndefined&&a===void 0)throw new Error("Unexpected undefined")}return a;case c.BYTE_STRING:case c.UTF8_STRING:if(a===1/0)return new n.ParentType(e,1/0,r,n);if(n.rejectStringsNotNormalizedAs&&typeof a=="string"){let u=a.normalize(n.rejectStringsNotNormalizedAs);if(a!==u)throw new Error(`String not normalized as "${n.rejectStringsNotNormalizedAs}", got [${Ze(a)}] instead of [${Ze(u)}]`)}return n.boxed?C(a,s.toHere(d)):a;case c.ARRAY:return new n.ParentType(e,a,r,n);case c.MAP:return new n.ParentType(e,a*2,r,n);case c.TAG:{let u=new n.ParentType(e,1,r,n);return u.children=new p(a),u}}throw new TypeError(`Invalid major type: ${i}`)}static decodeToEncodeOpts(e){return{...De,avoidInts:e.rejectInts,float64:!e.rejectLongFloats,flushToZero:e.rejectSubnormals,largeNegativeAsBigInt:e.rejectLargeNegatives,sortKeys:e.sortKeys}}push(e,r,n){if(this.children.push(e),this.#t){let s=q(e)||r.toHere(n);this.#t.push(s)}return--this.left}replaceLast(e,r,n){let s,i=-1/0;if(this.children instanceof p?(i=0,s=this.children.contents,this.children.contents=e):(i=this.children.length-1,s=this.children[i],this.children[i]=e),this.#t){let o=q(e)||n.toHere(r.offset);this.#t[i]=o}return s}convert(e){let r;switch(this.mt){case c.ARRAY:r=this.children;break;case c.MAP:{let n=this.#r();if(this.#e.sortKeys){let s;for(let i of n){if(s&&this.#e.sortKeys(s,i)>=0)throw new Error(`Duplicate or out of order key: "0x${i[2]}"`);s=i}}else if(this.#e.rejectDuplicateKeys){let s=new Set;for(let[i,o,a]of n){let d=E(a);if(s.has(d))throw new Error(`Duplicate key: "0x${d}"`);s.add(d)}}r=this.#e.createObject(n,this.#e);break}case c.BYTE_STRING:return Rt(this.children);case c.UTF8_STRING:{let n=this.children.join("");r=this.#e.boxed?C(n,e.toHere(this.offset)):n;break}case c.TAG:r=this.children.decode(this.#e);break;default:throw new TypeError(`Invalid mt on convert: ${this.mt}`)}return this.#e.saveOriginal&&r&&typeof r=="object"&&G(r,e.toHere(this.offset)),r}#r(){let e=this.children,r=e.length;if(r%2)throw new Error("Missing map value");let n=new Array(r/2);if(this.#t)for(let s=0;s<r;s+=2)n[s>>1]=[e[s],e[s+1],this.#t[s]];else for(let s=0;s<r;s+=2)n[s>>1]=[e[s],e[s+1],Wr];return n}};var ot=" ",Zr=new TextEncoder,Me=class extends w{close="";quote='"';get isEmptyStream(){return(this.mt===c.UTF8_STRING||this.mt===c.BYTE_STRING)&&this.count===0}};function V(t,e,r,n){let s="";if(e===l.INDEFINITE)s+="_";else{if(n.diagnosticSizes===Z.NEVER)return"";{let i=n.diagnosticSizes===Z.ALWAYS;if(!i){let o=l.ZERO;if(Object.is(r,-0))o=l.TWO;else if(t===c.POS_INT||t===c.NEG_INT){let a=r<0,d=typeof r=="bigint"?1n:1,u=a?-r-d:r;u<=23?o=Number(u):u<=255?o=l.ONE:u<=65535?o=l.TWO:u<=4294967295?o=l.FOUR:o=l.EIGHT}else isFinite(r)?Math.fround(r)===r?Ne(r)==null?o=l.FOUR:o=l.TWO:o=l.EIGHT:o=l.TWO;i=o!==e}i&&(s+="_",e<l.ONE?s+="i":s+=String(e-24))}}return s}function it(t,e){let r={...w.defaultDecodeOptions,...e,ParentType:Me},n=new U(t,r),s,i,o="";for(let a of n){let[d,u,f]=a;switch(s&&(s.count>0&&f!==y.BREAK&&(s.mt===c.MAP&&s.count%2?o+=": ":(o+=",",r.pretty||(o+=" "))),r.pretty&&(s.mt!==c.MAP||s.count%2===0)&&(o+=`
|
|
2
2
|
${ot.repeat(s.depth+1)}`)),i=w.create(a,s,r,n),d){case c.POS_INT:case c.NEG_INT:o+=String(f),o+=V(d,u,f,r);break;case c.SIMPLE_FLOAT:if(f!==y.BREAK)if(typeof f=="number"){let m=Object.is(f,-0)?"-0.0":String(f);o+=m,isFinite(f)&&!/[.e]/.test(m)&&(o+=".0"),o+=V(d,u,f,r)}else f instanceof x?(o+="simple(",o+=String(f.value),o+=V(c.POS_INT,u,f.value,r),o+=")"):o+=String(f);break;case c.BYTE_STRING:f===1/0?(o+="(_ ",i.close=")",i.quote="'"):(o+="h'",o+=E(f),o+="'",o+=V(c.POS_INT,u,f.length,r));break;case c.UTF8_STRING:f===1/0?(o+="(_ ",i.close=")"):(o+=JSON.stringify(f),o+=V(c.POS_INT,u,Zr.encode(f).length,r));break;case c.ARRAY:{o+="[";let m=V(c.POS_INT,u,f,r);o+=m,m&&(o+=" "),r.pretty&&f?i.close=`
|
|
3
3
|
${ot.repeat(i.depth)}]`:i.close="]";break}case c.MAP:{o+="{";let m=V(c.POS_INT,u,f,r);o+=m,m&&(o+=" "),r.pretty&&f?i.close=`
|
|
4
4
|
${ot.repeat(i.depth)}}`:i.close="}";break}case c.TAG:o+=String(f),o+=V(c.POS_INT,u,f,r),o+="(",i.close=")";break}if(i===y.BREAK)if(s?.isStreaming)s.left=0;else throw new Error("Unexpected BREAK");else s&&(s.count++,s.left--);for(i instanceof Me&&(s=i);s?.done;){if(s.isEmptyStream)o=o.slice(0,-3),o+=`${s.quote}${s.quote}_`;else{if(s.mt===c.MAP&&s.count%2!==0)throw new Error(`Odd streaming map size: ${s.count}`);o+=s.close}s=s.parent}}return o}var Xr=new TextDecoder,Te=class extends w{depth=0;leaf=!1;value;length;[y.ENCODED];constructor(e,r,n,s){super(e,r,n,s),this.parent?this.depth=this.parent.depth+1:this.depth=s.initialDepth,[,,this.value,,this.length]=e}numBytes(){switch(this.ai){case l.ONE:return 1;case l.TWO:return 2;case l.FOUR:return 4;case l.EIGHT:return 8}return 0}};function Ht(t){return t instanceof Te}function Le(t,e){return t===1/0?"Indefinite":e?`${t} ${e}${t!==1&&t!==1n?"s":""}`:String(t)}function Ee(t){return"".padStart(t," ")}function Vt(t,e,r){let n="";n+=Ee(t.depth*2);let s=q(t);n+=E(s.subarray(0,1));let i=t.numBytes();i&&(n+=" ",n+=E(s.subarray(1,i+1))),n=n.padEnd(e.minCol+1," "),n+="-- ",r!==void 0&&(n+=Ee(t.depth*2),r!==""&&(n+=`[${r}] `));let o=!1,[a]=t.children;switch(t.mt){case c.POS_INT:n+=`Unsigned: ${a}`,typeof a=="bigint"&&(n+="n");break;case c.NEG_INT:n+=`Negative: ${a}`,typeof a=="bigint"&&(n+="n");break;case c.BYTE_STRING:n+=`Bytes (Length: ${Le(t.length)})`;break;case c.UTF8_STRING:n+=`UTF8 (Length: ${Le(t.length)})`,t.length!==1/0&&(n+=`: ${JSON.stringify(a)}`);break;case c.ARRAY:n+=`Array (Length: ${Le(t.value,"item")})`;break;case c.MAP:n+=`Map (Length: ${Le(t.value,"pair")})`;break;case c.TAG:{n+=`Tag #${t.value}`;let d=t.children,[u]=d.contents.children,f=new p(d.tag,u);G(f,s);let m=f.comment(e,t.depth);m&&(n+=": ",n+=m),o||=f.noChildren;break}case c.SIMPLE_FLOAT:a===y.BREAK?n+="BREAK":t.ai>l.ONE?Object.is(a,-0)?n+="Float: -0":n+=`Float: ${a}`:(n+="Simple: ",a instanceof x?n+=a.value:n+=a);break}if(!o)if(t.leaf){if(n+=`
|