@m1cro/js-bootstrap 0.1.0-beta.19 → 0.1.0-beta.20

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 CHANGED
@@ -1,13 +1,13 @@
1
- var mr=Object.defineProperty;var k=(t,e)=>{for(var r in e)mr(t,r,{get:e[r],enumerable:!0})};var gr={};var We=["trace","debug","info","warn","error","none"];var ee=t=>We.indexOf(t)>=We.indexOf(console.logLevel);Object.defineProperty(globalThis.console,"logLevel",{get(){return process.env.LOG_LEVEL||"info"}});var te=console;globalThis.console={...globalThis.console,trace:(...t)=>{ee("trace")&&te.trace("[TRACE]",...t)},debug:(...t)=>{ee("debug")&&te.debug("[DEBUG]",...t)},info:(...t)=>{ee("info")&&te.info("[INFO]",...t)},log:(...t)=>{ee("info")&&te.log("[INFO]",...t)},warn:(...t)=>{ee("warn")&&te.warn("[WARN]",...t)},error:(...t)=>{ee("error")&&te.error("[ERROR]",...t)}};var c={POS_INT:0,NEG_INT:1,BYTE_STRING:2,UTF8_STRING:3,ARRAY:4,MAP:5,TAG:6,SIMPLE_FLOAT:7},l={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},h={ZERO:0,ONE:24,TWO:25,FOUR:26,EIGHT:27,INDEFINITE:31},N={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")},re={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 F(t){if(t!=null&&typeof t=="object")return t[y.ENCODED]}function Rt(t){if(t!=null&&typeof t=="object")return t[y.LENGTH]}function j(t,e){Object.defineProperty(t,y.ENCODED,{configurable:!0,enumerable:!1,value:e})}function $(t,e){let r=Object(t);return j(r,e),r}var Je=Symbol("CBOR_RANGES");function It(t,e){Object.defineProperty(t,Je,{configurable:!1,enumerable:!1,writable:!1,value:e})}function ce(t){return t[Je]}function yr(t){return ce(t)!==void 0}function de(t,e=0,r=t.length-1){let n=t.subarray(e,r),s=ce(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&&It(n,i)}return n}function Te(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 St(t){let e=t.reduce((o,a)=>o+a.length,0),r=t.some(o=>yr(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&&It(s,n),s}function ue(t){let e=atob(t);return Uint8Array.from(e,r=>r.codePointAt(0))}var br={"-":"+",_:"/"};function xt(t){let e=t.replace(/[_-]/g,r=>br[r]);return ue(e.padEnd(Math.ceil(e.length/4)*4,"="))}function Ot(){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 fe=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 Re(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 ne=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,pe=0b11111n<<10n,Mt=1n<<9n,Bt=Mt-1n,vt=Mt|Bt,et=1n<<31n,he=0b11111111n<<23n,Lt=1n<<22n,Pt=Lt-1n,Nt=Lt|Pt,Ie=1n<<63n,B=0b11111111111n<<52n,le=1n<<51n,Se=le-1n,At=le|Se,Ut=Se-(Bt<<42n),_t=Se-(Pt<<29n),wr={2:"0b",8:"0o",16:"0x"},kt=(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))(kt||{});function Dt(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 me=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=Ie,e=-e),e>=le)throw new Error(`Payload too large: ${s}`);let o=r?le:0n;switch(this.#e=i|B|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&Ut)throw new Error("Invalid size for payload");break;case 4:if(this.#e&_t)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&B)===B)this.#e=e,i=8;else if((e&he)===he){let o=(e&et)<<32n;this.#e=o|B|(e&Nt)<<29n,i=4}else if((e&pe)===pe){let o=(e&Xe)<<48n;this.#e=o|B|(e&vt)<<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&pe)!==pe)throw new Error("Not a NaN");let a=(o&Xe)<<48n;this.#e=a|B|(o&vt)<<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&he)!==he)throw new Error("Not a NaN");let a=(o&et)<<32n;this.#e=a|B|(o&Nt)<<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&B)!==B)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&Ie?Xe:0n)|pe|(this.#e&At)>>42n;r.setUint16(1,Number(n),!1);break}case 4:{r.setUint8(0,250);let n=(this.#e&Ie?et:0n)|he|(this.#e&At)>>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&le)}get sign(){return this.#e&Ie?-1:1}get payload(){return Number(this.#e&Se)*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&Ut)===0n?2:(this.#e&_t)===0n?4:8}get isShortestEncoding(){return this.preferredSize===this.#t}toCBOR(e){e.write(this.bytes)}toString(e=10){return Dt(this,1,{},r=>(wr[e]??"")+r.toString(e))}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return Dt(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 xe(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 Ft(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 jt(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 ge=class extends TypeError{code="ERR_ENCODING_INVALID_ENCODED_DATA";constructor(){super("The encoded data was not valid for encoding wtf-8")}},Oe=class extends RangeError{code="ERR_ENCODING_NOT_SUPPORTED";constructor(e){super(`Invalid encoding: "${e}"`)}};var ve=new Uint8Array(0);var rt=55296,$t=56320,Gt=65533,Ne="wtf-8";function Tr(t){return t&&!(t instanceof ArrayBuffer)&&t.buffer instanceof ArrayBuffer}function Rr(t){return t?t instanceof Uint8Array?t:Tr(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t):ve}var Ir=[0,0,0,0,0,0,0,0,-1,-1,-1,-1,1,1,2,3],J=class t{static DEFAULT_BUFFERSIZE=4096;encoding=Ne;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 Oe(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=Rr(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 ge;o[d++]=Gt},f=()=>{let g=this.#r;for(let v=0;v<g;v++)u()},m=g=>{if(this.#e===0)switch(Ir[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 v=this.#t-65536;o[d++]=v>>>10&1023|rt,o[d++]=v&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 Sr(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 se=class{encoding=Ne;encode(e){if(!e)return ve;let r=new Uint8Array(Sr(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:Xn}=y,Ct=c.SIMPLE_FLOAT<<5|h.TWO,xr=c.SIMPLE_FLOAT<<5|h.FOUR,Or=c.SIMPLE_FLOAT<<5|h.EIGHT,vr=c.SIMPLE_FLOAT<<5|N.TRUE,Nr=c.SIMPLE_FLOAT<<5|N.FALSE,Ar=c.SIMPLE_FLOAT<<5|N.UNDEFINED,Ur=c.SIMPLE_FLOAT<<5|N.NULL,_r=new TextEncoder,Dr=new se,Ue={...ne.defaultOptions,avoidInts:!1,cde:!1,collapseBigInts:!0,dateTag:l.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:Re},qt={...st,dcbor:!0,largeNegativeAsBigInt:!0,reduceUnsafeNumbers:!0,rejectCustomSimples:!0,rejectDuplicateKeys:!0,rejectUndefined:!0,simplifyNegativeZero:!0,stringNormalization:"NFC"};function Ht(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(Ct),e.writeUint16(32256);else if(!r.float64&&Math.fround(t)===t){let n=xe(t);n===null?(e.writeUint8(xr),e.writeFloat32(t)):(e.writeUint8(Ct),e.writeUint16(n))}else e.writeUint8(Or),e.writeFloat64(t)}function R(t,e,r){let[n,s]=Ht(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|h.ONE),e.writeUint8(n)):n<=65535?(e.writeUint8(r|h.TWO),e.writeUint16(n)):n<=4294967295?(e.writeUint8(r|h.FOUR),e.writeUint32(n)):(e.writeUint8(r|h.EIGHT),e.writeBigUint64(BigInt(n)))}function oe(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|h.EIGHT),e.writeBigUint64(BigInt(t)))}function zt(t,e,r){let[n,s]=Ht(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|h.EIGHT),e.writeBigUint64(n);return}}if(r.rejectBigInts)throw new Error(`Attempt to encode unwanted bigint: ${t}`);let i=s?l.NEG_BIGINT:l.POS_BIGINT,o=n.toString(16),a=o.length%2?"0":"";oe(i,e,r);let d=Te(a+o);R(d.length,e,c.BYTE_STRING),e.write(d)}function Mr(t,e,r){r.flushToZero&&(t=Ft(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>=re.MIN&&t<=re.MAX?zt(BigInt(t),e,r):nt(t,e,r)}function Br(t,e,r){let n=r.stringNormalization?t.normalize(r.stringNormalization):t;if(r.wtf8&&!t.isWellFormed()){let s=Dr.encode(n);oe(l.WTF8,e,r),R(s.length,e,c.BYTE_STRING),e.write(s)}else{let s=_r.encode(n);R(s.length,e,c.UTF8_STRING),e.write(s)}}function Lr(t,e,r){let n=t;_e(n,n.length,c.ARRAY,e,r);for(let s of n)G(s,e,r)}function Pr(t,e){R(t.length,e,c.BYTE_STRING),e.write(t)}var Ae=new fe;Ae.registerEncoder(Array,Lr),Ae.registerEncoder(Uint8Array,Pr);function b(t,e){return Ae.registerEncoder(t,e)}function _e(t,e,r,n,s){let i=Rt(t);i&&!s.ignoreOriginalEncoding?n.write(i):R(e,n,r)}function kr(t,e,r){if(t===null){e.writeUint8(Ur);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:Ae.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])))&&oe(o[0],e,r),G(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])))&&oe(i[0],e,r),G(i[1],e,r));return}if(typeof t.toJSON=="function"){G(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),_e(t,s.length,c.MAP,e,r);for(let[i,o,a]of s)e.write(a),G(o,e,r)}function G(t,e,r){switch(typeof t){case"number":Mr(t,e,r);break;case"bigint":zt(t,e,r);break;case"string":Br(t,e,r);break;case"boolean":e.writeUint8(t?vr:Nr);break;case"undefined":if(r.rejectUndefined)throw new Error("Attempt to encode unwanted undefined.");e.writeUint8(Ar);break;case"object":kr(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={...Ue};e.dcbor?Object.assign(r,qt):e.cde&&Object.assign(r,st),Object.assign(r,e);let n=new ne(r);return G(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([[N.FALSE,!1],[N.TRUE,!0],[N.NULL,null],[N.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 Fr=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=Te(e);break;case"base64":this.#e=ue(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 de(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 h.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 h.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 h.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 h.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 h.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,Fr.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=de(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,h.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===h.INDEFINITE)throw new Error("New stream started in typed stream")}yield o.value,yield*i}}};var jr=new Map([[h.ZERO,1],[h.ONE,2],[h.TWO,3],[h.FOUR,5],[h.EIGHT,9]]),$r=new Uint8Array(0);function Gr(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:Gr,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:Re};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===h.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>=re.MIN&&u<=re.MAX&&(u=Number(a)),n.boxed?$(u,s.toHere(d)):u}case c.SIMPLE_FLOAT:if(o>h.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 me(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&&jt(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<jr.get(o))throw new Error(`Number should have been encoded shorter: ${a}`)}if(typeof a=="number"&&n.boxed)return $(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?$(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{...Ue,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=F(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=F(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 St(this.children);case c.UTF8_STRING:{let n=this.children.join("");r=this.#e.boxed?$(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"&&j(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],$r];return n}};var ot=" ",Cr=new TextEncoder,De=class extends w{close="";quote='"';get isEmptyStream(){return(this.mt===c.UTF8_STRING||this.mt===c.BYTE_STRING)&&this.count===0}};function C(t,e,r,n){let s="";if(e===h.INDEFINITE)s+="_";else{if(n.diagnosticSizes===Z.NEVER)return"";{let i=n.diagnosticSizes===Z.ALWAYS;if(!i){let o=h.ZERO;if(Object.is(r,-0))o=h.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=h.ONE:u<=65535?o=h.TWO:u<=4294967295?o=h.FOUR:o=h.EIGHT}else isFinite(r)?Math.fround(r)===r?xe(r)==null?o=h.FOUR:o=h.TWO:o=h.EIGHT:o=h.TWO;i=o!==e}i&&(s+="_",e<h.ONE?s+="i":s+=String(e-24))}}return s}function it(t,e){let r={...w.defaultDecodeOptions,...e,ParentType:De},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
- ${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+=C(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+=C(d,u,f,r)}else f instanceof x?(o+="simple(",o+=String(f.value),o+=C(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+=C(c.POS_INT,u,f.length,r));break;case c.UTF8_STRING:f===1/0?(o+="(_ ",i.close=")"):(o+=JSON.stringify(f),o+=C(c.POS_INT,u,Cr.encode(f).length,r));break;case c.ARRAY:{o+="[";let m=C(c.POS_INT,u,f,r);o+=m,m&&(o+=" "),r.pretty&&f?i.close=`
3
- ${ot.repeat(i.depth)}]`:i.close="]";break}case c.MAP:{o+="{";let m=C(c.POS_INT,u,f,r);o+=m,m&&(o+=" "),r.pretty&&f?i.close=`
4
- ${ot.repeat(i.depth)}}`:i.close="}";break}case c.TAG:o+=String(f),o+=C(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 De&&(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 qr=new TextDecoder,be=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 h.ONE:return 1;case h.TWO:return 2;case h.FOUR:return 4;case h.EIGHT:return 8}return 0}};function Vt(t){return t instanceof be}function Me(t,e){return t===1/0?"Indefinite":e?`${t} ${e}${t!==1&&t!==1n?"s":""}`:String(t)}function ye(t){return"".padStart(t," ")}function Kt(t,e,r){let n="";n+=ye(t.depth*2);let s=F(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+=ye(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: ${Me(t.length)})`;break;case c.UTF8_STRING:n+=`UTF8 (Length: ${Me(t.length)})`,t.length!==1/0&&(n+=`: ${JSON.stringify(a)}`);break;case c.ARRAY:n+=`Array (Length: ${Me(t.value,"item")})`;break;case c.MAP:n+=`Map (Length: ${Me(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);j(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>h.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+=`
5
- `,s.length>i+1){let d=ye((t.depth+1)*2),u=ce(s);if(u?.length){u.sort((m,g)=>m[0]-g[0]||g[1]-m[1]);let f=0;for(let[m,g,v]of u)if(!(m<f)){if(f=m+g,v==="<<"){n+=ye(e.minCol+1),n+="--",n+=d,n+="<< ";let P=de(s,m,m+g),ae=ce(P);if(ae){let Tt=ae.findIndex(([pr,hr,lr])=>pr===0&&hr===g&&lr==="<<");Tt>=0&&ae.splice(Tt,1)}n+=it(P),n+=` >>
6
- `,n+=Be(P,{initialDepth:t.depth+1,minCol:e.minCol,noPrefixHex:!0});continue}else v==="'"&&(n+=ye(e.minCol+1),n+="--",n+=d,n+="'",n+=qr.decode(s.subarray(m,m+g)),n+=`'
7
- `);if(m>i)for(let P=m;P<m+g;P+=8){let ae=Math.min(P+8,m+g);n+=d,n+=E(s.subarray(P,ae)),n+=`
8
- `}}}else for(let f=i+1;f<s.length;f+=8)n+=d,n+=E(s.subarray(f,f+8)),n+=`
1
+ var lr=Object.defineProperty;var F=(t,e)=>{for(var r in e)lr(t,r,{get:e[r],enumerable:!0})};var Te={};F(Te,{host:()=>mr});import*as It from"m1cro:app/host";var mr={getSettings(){return It.getSettings()}};var $={};F($,{guest:()=>yr,host:()=>gr});import*as j from"m1cro:common/host";var gr={getTenant(){return j.getTenant()},getArtifact(t){return j.getArtifact(t)},getCrd(t){return j.getCRD(t)},listProviders(t){return j.listProviders(t)}},yr={getManifest(){return N.manifest},async start(){await N.emit("start")},async install(){await N.emit("install")}};var G={};F(G,{host:()=>wr});import*as U from"m1cro:crypto/host";var wr={deriveKey:(t,e)=>U.deriveKey(t,e),aesGcmEncrypt:t=>U.aesGcmEncrypt(t),aesGcmDecrypt:t=>U.aesGcmDecrypt(t),argon2Hash:(t,e,r,n,s,i)=>U.argon2Hash(t,e,r,n,s,i),argon2Verify:(t,e,r,n,s,i,o)=>U.argon2Verify(t,e,r,n,s,i,o)};var I={};F(I,{host:()=>br});import*as H from"m1cro:entity/host";var br={async find(t){return await H.find(t)},async insert(t){return await H.insert(t)},async update(t){return await H.update(t)},async remove(t){return await H.remove(t)}};var J={};F(J,{host:()=>Tr});import*as C from"m1cro:kv/host";var Tr={async get(t){return await C.get(t)},async getDel(t){return await C.getDel(t)},async set(t,e,r){return await C.set(t,e,r)},async delete(t){return await C.delete(t)}};var O={};F(O,{guest:()=>Ir,host:()=>Rr,types:()=>Er});import*as Er from"m1cro:rpc/types";import*as xt from"m1cro:rpc/host";var Ee=class t{#e;#t="get";#r=new Headers;#n;constructor(e){this.#e=new URL(e)}get method(){return this.#t}withMethod(e){return this.#t=e,this}get url(){return this.#e}withUrl(e){return this.#e=new URL(e),this}header(e){return this.#r.get(e)??void 0}withHeader(e,r){return this.#r.set(e,r),this}get headers(){return this.#r}withHeaders(e){return e instanceof Headers?e.forEach((r,n)=>this.#r.set(n,r)):Array.isArray(e)?e.forEach(([r,n])=>this.#r.set(r,n)):Object.entries(e).forEach(([r,n])=>this.#r.set(r,n)),this}async body(){return this.#n===void 0?new Uint8Array:await this.#n}withBody(e){return this.#n=Promise.resolve(e),this}async text(){let e=await this.body();return new TextDecoder().decode(e)}withText(e){return this.withBody(new TextEncoder().encode(e)),this}async json(){let e=await this.text();return JSON.parse(e)}withJson(e){return this.withText(JSON.stringify(e)),this}static fromHostRequest(e){return new t("http://"+e.getUrl()).withMethod(e.getMethod().tag).withHeaders(e.getHeaders()).withBody(e.getBody())}async toHostRequest(){let e=new O.types.Request,r=this.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}`)}return e.setUrl(this.url.toString()),e.setHeaders(Array.from(this.headers.entries())),e.setBody(await this.body()),e}},Re=class t{#e;#t=new Headers;#r;constructor(e=200){this.#e=e}get status(){return this.#e}withStatus(e){return this.#e=e,this}header(e){return this.#t.get(e)??void 0}withHeader(e,r){return this.#t.set(e,r),this}get headers(){return this.#t}withHeaders(e){return e instanceof Headers?e.forEach((r,n)=>this.#t.set(n,r)):Array.isArray(e)?e.forEach(([r,n])=>this.#t.set(r,n)):Object.entries(e).forEach(([r,n])=>this.#t.set(r,n)),this}async body(){return this.#r===void 0?new Uint8Array:await this.#r}withBody(e){return this.#r=Promise.resolve(e),this}async text(){let e=await this.body();return new TextDecoder().decode(e)}withText(e){return this.withBody(new TextEncoder().encode(e)),this}async json(){let e=await this.text();return JSON.parse(e)}withJson(e){return this.withText(JSON.stringify(e)),this}static async fromHostResponse(e){return new t(e.getStatus()).withHeaders(e.getHeaders()).withBody(e.getBody())}async toHostResponse(){let e=new O.types.Response;return e.setStatus(this.status),e.setHeaders(Array.from(this.headers.entries())),e.setBody(await this.body()),e}};var Rr={call:async t=>await xt.call(t)},Ir={call:async(t,e,r,n)=>{let s=N.router.routes[t];if(!s)throw new Error(`Route not found for index ${t}`);let i=Ee.fromHostRequest(r),o=new Re;return await s.handler.bind(N)(i,o),await o.toHostResponse()}};import*as xr from"m1cro:log/host";var se={};F(se,{guest:()=>nn,host:()=>rn});var c={POS_INT:0,NEG_INT:1,BYTE_STRING:2,UTF8_STRING:3,ARRAY:4,MAP:5,TAG:6,SIMPLE_FLOAT:7},l={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},h={ZERO:0,ONE:24,TWO:25,FOUR:26,EIGHT:27,INDEFINITE:31},_={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")},ee={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 St(t){if(t!=null&&typeof t=="object")return t[y.LENGTH]}function z(t,e){Object.defineProperty(t,y.ENCODED,{configurable:!0,enumerable:!1,value:e})}function V(t,e){let r=Object(t);return z(r,e),r}var Je=Symbol("CBOR_RANGES");function Ot(t,e){Object.defineProperty(t,Je,{configurable:!1,enumerable:!1,writable:!1,value:e})}function ce(t){return t[Je]}function Or(t){return ce(t)!==void 0}function de(t,e=0,r=t.length-1){let n=t.subarray(e,r),s=ce(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&&Ot(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 T(t){return t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")}function At(t){let e=t.reduce((o,a)=>o+a.length,0),r=t.some(o=>Or(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&&Ot(s,n),s}function ue(t){let e=atob(t);return Uint8Array.from(e,r=>r.codePointAt(0))}var Ar={"-":"+",_:"/"};function vt(t){let e=t.replace(/[_-]/g,r=>Ar[r]);return ue(e.padEnd(Math.ceil(e.length/4)*4,"="))}function Nt(){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 fe=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 xe(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 te=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,pe=0b11111n<<10n,Pt=1n<<9n,kt=Pt-1n,Ut=Pt|kt,et=1n<<31n,he=0b11111111n<<23n,Ft=1n<<22n,jt=Ft-1n,_t=Ft|jt,Se=1n<<63n,L=0b11111111111n<<52n,le=1n<<51n,Oe=le-1n,Dt=le|Oe,Bt=Oe-(kt<<42n),Mt=Oe-(jt<<29n),vr={2:"0b",8:"0o",16:"0x"},$t=(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))($t||{});function Lt(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 me=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=Se,e=-e),e>=le)throw new Error(`Payload too large: ${s}`);let o=r?le:0n;switch(this.#e=i|L|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&Bt)throw new Error("Invalid size for payload");break;case 4:if(this.#e&Mt)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&L)===L)this.#e=e,i=8;else if((e&he)===he){let o=(e&et)<<32n;this.#e=o|L|(e&_t)<<29n,i=4}else if((e&pe)===pe){let o=(e&Xe)<<48n;this.#e=o|L|(e&Ut)<<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&pe)!==pe)throw new Error("Not a NaN");let a=(o&Xe)<<48n;this.#e=a|L|(o&Ut)<<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&he)!==he)throw new Error("Not a NaN");let a=(o&et)<<32n;this.#e=a|L|(o&_t)<<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&L)!==L)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&Se?Xe:0n)|pe|(this.#e&Dt)>>42n;r.setUint16(1,Number(n),!1);break}case 4:{r.setUint8(0,250);let n=(this.#e&Se?et:0n)|he|(this.#e&Dt)>>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&le)}get sign(){return this.#e&Se?-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&Bt)===0n?2:(this.#e&Mt)===0n?4:8}get isShortestEncoding(){return this.preferredSize===this.#t}toCBOR(e){e.write(this.bytes)}toString(e=10){return Lt(this,1,{},r=>(vr[e]??"")+r.toString(e))}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return Lt(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 Ae(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 Gt(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 Ht(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 ge=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 Ne=new Uint8Array(0);var rt=55296,Ct=56320,qt=65533,Ue="wtf-8";function Ur(t){return t&&!(t instanceof ArrayBuffer)&&t.buffer instanceof ArrayBuffer}function _r(t){return t?t instanceof Uint8Array?t:Ur(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t):Ne}var Dr=[0,0,0,0,0,0,0,0,-1,-1,-1,-1,1,1,2,3],Z=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=_r(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 ge;o[d++]=qt},f=()=>{let g=this.#r;for(let v=0;v<g;v++)u()},m=g=>{if(this.#e===0)switch(Dr[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 v=this.#t-65536;o[d++]=v>>>10&1023|rt,o[d++]=v&1023|Ct}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 Br(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 re=class{encoding=Ue;encode(e){if(!e)return Ne;let r=new Uint8Array(Br(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:Xn}=y,zt=c.SIMPLE_FLOAT<<5|h.TWO,Mr=c.SIMPLE_FLOAT<<5|h.FOUR,Lr=c.SIMPLE_FLOAT<<5|h.EIGHT,Pr=c.SIMPLE_FLOAT<<5|_.TRUE,kr=c.SIMPLE_FLOAT<<5|_.FALSE,Fr=c.SIMPLE_FLOAT<<5|_.UNDEFINED,jr=c.SIMPLE_FLOAT<<5|_.NULL,$r=new TextEncoder,Gr=new re,De={...te.defaultOptions,avoidInts:!1,cde:!1,collapseBigInts:!0,dateTag:l.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:xe},Vt={...st,dcbor:!0,largeNegativeAsBigInt:!0,reduceUnsafeNumbers:!0,rejectCustomSimples:!0,rejectDuplicateKeys:!0,rejectUndefined:!0,simplifyNegativeZero:!0,stringNormalization:"NFC"};function Kt(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(zt),e.writeUint16(32256);else if(!r.float64&&Math.fround(t)===t){let n=Ae(t);n===null?(e.writeUint8(Mr),e.writeFloat32(t)):(e.writeUint8(zt),e.writeUint16(n))}else e.writeUint8(Lr),e.writeFloat64(t)}function R(t,e,r){let[n,s]=Kt(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|h.ONE),e.writeUint8(n)):n<=65535?(e.writeUint8(r|h.TWO),e.writeUint16(n)):n<=4294967295?(e.writeUint8(r|h.FOUR),e.writeUint32(n)):(e.writeUint8(r|h.EIGHT),e.writeBigUint64(BigInt(n)))}function ne(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|h.EIGHT),e.writeBigUint64(BigInt(t)))}function Qt(t,e,r){let[n,s]=Kt(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|h.EIGHT),e.writeBigUint64(n);return}}if(r.rejectBigInts)throw new Error(`Attempt to encode unwanted bigint: ${t}`);let i=s?l.NEG_BIGINT:l.POS_BIGINT,o=n.toString(16),a=o.length%2?"0":"";ne(i,e,r);let d=Ie(a+o);R(d.length,e,c.BYTE_STRING),e.write(d)}function Hr(t,e,r){r.flushToZero&&(t=Gt(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>=ee.MIN&&t<=ee.MAX?Qt(BigInt(t),e,r):nt(t,e,r)}function Cr(t,e,r){let n=r.stringNormalization?t.normalize(r.stringNormalization):t;if(r.wtf8&&!t.isWellFormed()){let s=Gr.encode(n);ne(l.WTF8,e,r),R(s.length,e,c.BYTE_STRING),e.write(s)}else{let s=$r.encode(n);R(s.length,e,c.UTF8_STRING),e.write(s)}}function qr(t,e,r){let n=t;Be(n,n.length,c.ARRAY,e,r);for(let s of n)K(s,e,r)}function zr(t,e){R(t.length,e,c.BYTE_STRING),e.write(t)}var _e=new fe;_e.registerEncoder(Array,qr),_e.registerEncoder(Uint8Array,zr);function w(t,e){return _e.registerEncoder(t,e)}function Be(t,e,r,n,s){let i=St(t);i&&!s.ignoreOriginalEncoding?n.write(i):R(e,n,r)}function Vr(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])))&&ne(o[0],e,r),K(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])))&&ne(i[0],e,r),K(i[1],e,r));return}if(typeof t.toJSON=="function"){K(t.toJSON(),e,r);return}let s=Object.entries(t).map(i=>[i[0],i[1],D(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),K(o,e,r)}function K(t,e,r){switch(typeof t){case"number":Hr(t,e,r);break;case"bigint":Qt(t,e,r);break;case"string":Cr(t,e,r);break;case"boolean":e.writeUint8(t?Pr:kr);break;case"undefined":if(r.rejectUndefined)throw new Error("Attempt to encode unwanted undefined.");e.writeUint8(Fr);break;case"object":Vr(t,e,r);break;case"symbol":throw new TypeError(`Unknown symbol: ${t.toString()}`);default:throw new TypeError(`Unknown type: ${typeof t}, ${String(t)}`)}}function D(t,e={}){let r={...De};e.dcbor?Object.assign(r,Vt):e.cde&&Object.assign(r,st),Object.assign(r,e);let n=new te(r);return K(t,n,r),n.read()}var X=(t=>(t[t.NEVER=-1]="NEVER",t[t.PREFERRED=0]="PREFERRED",t[t.ALWAYS=1]="ALWAYS",t))(X||{});var A=class t{static KnownSimple=new Map([[_.FALSE,!1],[_.TRUE,!0],[_.NULL,null],[_.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}),B=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=ue(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 de(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 h.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 h.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 h.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 h.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 h.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=A.create(Number(o))),yield[s,i,o,r,u];break}}}#o(e){let r=de(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,h.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===h.INDEFINITE)throw new Error("New stream started in typed stream")}yield o.value,yield*i}}};var Qr=new Map([[h.ZERO,1],[h.ONE,2],[h.TWO,3],[h.FOUR,5],[h.EIGHT,9]]),Yr=new Uint8Array(0);function Wr(t,e){return!e.boxed&&!e.preferMap&&t.every(([r])=>typeof r=="string")?Object.fromEntries(t):new Map(t)}var b=class t{static defaultDecodeOptions={...B.defaultOptions,ParentType:t,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:X.PREFERRED,collapseBigInts:!1,convertUnsafeIntsToFloat:!1,createObject:Wr,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:xe};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===h.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>=ee.MIN&&u<=ee.MAX&&(u=Number(a)),n.boxed?V(u,s.toHere(d)):u}case c.SIMPLE_FLOAT:if(o>h.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 me(u);if(n.rejectLongLoundNaN){if(f.payload||u.length>3)throw new Error(`Invalid NaN encoding: "${T(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&&Ht(s.toHere(d+1)),n.rejectLongFloats){let u=D(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<Qr.get(o))throw new Error(`Number should have been encoded shorter: ${a}`)}if(typeof a=="number"&&n.boxed)return V(a,s.toHere(d))}else{if(n.rejectSimple&&a instanceof A)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?V(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=T(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 At(this.children);case c.UTF8_STRING:{let n=this.children.join("");r=this.#e.boxed?V(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"&&z(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],Yr];return n}};var ot=" ",Jr=new TextEncoder,Me=class extends b{close="";quote='"';get isEmptyStream(){return(this.mt===c.UTF8_STRING||this.mt===c.BYTE_STRING)&&this.count===0}};function Q(t,e,r,n){let s="";if(e===h.INDEFINITE)s+="_";else{if(n.diagnosticSizes===X.NEVER)return"";{let i=n.diagnosticSizes===X.ALWAYS;if(!i){let o=h.ZERO;if(Object.is(r,-0))o=h.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=h.ONE:u<=65535?o=h.TWO:u<=4294967295?o=h.FOUR:o=h.EIGHT}else isFinite(r)?Math.fround(r)===r?Ae(r)==null?o=h.FOUR:o=h.TWO:o=h.EIGHT:o=h.TWO;i=o!==e}i&&(s+="_",e<h.ONE?s+="i":s+=String(e-24))}}return s}function it(t,e){let r={...b.defaultDecodeOptions,...e,ParentType:Me},n=new B(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
+ ${ot.repeat(s.depth+1)}`)),i=b.create(a,s,r,n),d){case c.POS_INT:case c.NEG_INT:o+=String(f),o+=Q(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+=Q(d,u,f,r)}else f instanceof A?(o+="simple(",o+=String(f.value),o+=Q(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+=T(f),o+="'",o+=Q(c.POS_INT,u,f.length,r));break;case c.UTF8_STRING:f===1/0?(o+="(_ ",i.close=")"):(o+=JSON.stringify(f),o+=Q(c.POS_INT,u,Jr.encode(f).length,r));break;case c.ARRAY:{o+="[";let m=Q(c.POS_INT,u,f,r);o+=m,m&&(o+=" "),r.pretty&&f?i.close=`
3
+ ${ot.repeat(i.depth)}]`:i.close="]";break}case c.MAP:{o+="{";let m=Q(c.POS_INT,u,f,r);o+=m,m&&(o+=" "),r.pretty&&f?i.close=`
4
+ ${ot.repeat(i.depth)}}`:i.close="}";break}case c.TAG:o+=String(f),o+=Q(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 Zr=new TextDecoder,we=class extends b{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 h.ONE:return 1;case h.TWO:return 2;case h.FOUR:return 4;case h.EIGHT:return 8}return 0}};function Yt(t){return t instanceof we}function Le(t,e){return t===1/0?"Indefinite":e?`${t} ${e}${t!==1&&t!==1n?"s":""}`:String(t)}function ye(t){return"".padStart(t," ")}function Wt(t,e,r){let n="";n+=ye(t.depth*2);let s=q(t);n+=T(s.subarray(0,1));let i=t.numBytes();i&&(n+=" ",n+=T(s.subarray(1,i+1))),n=n.padEnd(e.minCol+1," "),n+="-- ",r!==void 0&&(n+=ye(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);z(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>h.ONE?Object.is(a,-0)?n+="Float: -0":n+=`Float: ${a}`:(n+="Simple: ",a instanceof A?n+=a.value:n+=a);break}if(!o)if(t.leaf){if(n+=`
5
+ `,s.length>i+1){let d=ye((t.depth+1)*2),u=ce(s);if(u?.length){u.sort((m,g)=>m[0]-g[0]||g[1]-m[1]);let f=0;for(let[m,g,v]of u)if(!(m<f)){if(f=m+g,v==="<<"){n+=ye(e.minCol+1),n+="--",n+=d,n+="<< ";let k=de(s,m,m+g),ae=ce(k);if(ae){let Rt=ae.findIndex(([fr,pr,hr])=>fr===0&&pr===g&&hr==="<<");Rt>=0&&ae.splice(Rt,1)}n+=it(k),n+=` >>
6
+ `,n+=Pe(k,{initialDepth:t.depth+1,minCol:e.minCol,noPrefixHex:!0});continue}else v==="'"&&(n+=ye(e.minCol+1),n+="--",n+=d,n+="'",n+=Zr.decode(s.subarray(m,m+g)),n+=`'
7
+ `);if(m>i)for(let k=m;k<m+g;k+=8){let ae=Math.min(k+8,m+g);n+=d,n+=T(s.subarray(k,ae)),n+=`
8
+ `}}}else for(let f=i+1;f<s.length;f+=8)n+=d,n+=T(s.subarray(f,f+8)),n+=`
9
9
  `}}else{n+=`
10
- `;let d=0;for(let u of t.children){if(Vt(u)){let f=String(d);t.mt===c.MAP?f=d%2?`val ${(d-1)/2}`:`key ${d/2}`:t.mt===c.TAG&&(f=""),n+=Kt(u,e,f)}d++}}return n}var Hr={...w.defaultDecodeOptions,initialDepth:0,noPrefixHex:!1,minCol:0};function Be(t,e){let r={...Hr,...e,ParentType:be,saveOriginal:!0},n=new U(t,r),s,i;for(let a of n){if(i=w.create(a,s,r,n),a[2]===y.BREAK)if(s?.isStreaming)s.left=1;else throw new Error("Unexpected BREAK");if(!Vt(i)){let f=new be(a,0,s,r);f.leaf=!0,f.children.push(i),j(f,n.toHere(a[3])),i=f}let d=(i.depth+1)*2,u=i.numBytes();for(u&&(d+=1,d+=u*2),r.minCol=Math.max(r.minCol,d),s&&s.push(i,n,a[3]),s=i;s?.done;)i=s,i.leaf||j(i,n.toHere(i.offset)),{parent:s}=s}e&&(e.minCol=r.minCol);let o=r.noPrefixHex?"":`0x${E(n.toHere(0))}
11
- `;return o+=Kt(i,r),o}var Qt=!Ot();function ke(t){if(typeof t=="object"&&t){if(t.constructor!==Number)throw new Error(`Expected number: ${t}`)}else if(typeof t!="number")throw new Error(`Expected number: ${t}`)}function H(t){if(typeof t=="object"&&t){if(t.constructor!==String)throw new Error(`Expected string: ${t}`)}else if(typeof t!="string")throw new Error(`Expected string: ${t}`)}function L(t){if(!(t instanceof Uint8Array))throw new Error(`Expected Uint8Array: ${t}`)}function er(t){if(!Array.isArray(t))throw new Error(`Expected Array: ${t}`)}b(Map,(t,e,r)=>{let n=[...t.entries()].map(s=>[s[0],s[1],A(s[0],r)]);if(r.rejectDuplicateKeys){let s=new Set;for(let[i,o,a]of n){let d=E(a);if(s.has(d))throw new Error(`Duplicate map key: 0x${d}`);s.add(d)}}r.sortKeys&&n.sort(r.sortKeys),_e(t,t.size,c.MAP,e,r);for(let[s,i,o]of n)e.write(o),G(i,e,r)});function at(t){return H(t.contents),new Date(t.contents)}at.comment=t=>{H(t.contents);let e=new Date(t.contents);return`(String ${t.tag===l.DATE_FULL?"Full ":""}Date) ${e.toISOString()}`},p.registerDecoder(l.DATE_STRING,at),p.registerDecoder(l.DATE_FULL,at);function Yt(t){return ke(t.contents),new Date(t.contents*1e3)}Yt.comment=t=>(ke(t.contents),`(Epoch Date) ${new Date(t.contents*1e3).toISOString()}`),p.registerDecoder(l.DATE_EPOCH,Yt);var ut=1e3*60*60*24;function Wt(t){return ke(t.contents),new Date(t.contents*ut)}Wt.comment=t=>(ke(t.contents),`(Epoch Date) ${new Date(t.contents*ut).toISOString()}`),p.registerDecoder(l.DATE_EPOCH_DAYS,Wt),b(Date,(t,e,r)=>{switch(r.dateTag){case l.DATE_EPOCH:return[r.dateTag,t.valueOf()/1e3];case l.DATE_STRING:return[r.dateTag,t.toISOString().replace(/\.000Z$/,"Z")];case l.DATE_EPOCH_DAYS:return[r.dateTag,Math.floor(t.valueOf()/ut)];case l.DATE_FULL:return[r.dateTag,t.toISOString().split("T")[0]];default:throw new Error(`Unsupported date tag: ${r.dateTag}`)}});function Pe(t,e,r){if(L(e.contents),r.rejectBigInts)throw new Error(`Decoding unwanted big integer: ${e}(h'${E(e.contents)}')`);if(r.requirePreferred&&e.contents[0]===0)throw new Error(`Decoding overly-large bigint: ${e.tag}(h'${E(e.contents)})`);let n=e.contents.reduce((i,o)=>i<<8n|BigInt(o),0n);t&&(n=-1n-n);let s=n>=Number.MIN_SAFE_INTEGER&&n<=Number.MAX_SAFE_INTEGER;if(r.requirePreferred&&s)throw new Error(`Decoding bigint that could have been int: ${n}n`);return r.collapseBigInts&&s&&(n=Number(n)),r.boxed?$(n,e.contents):n}var Jt=Pe.bind(null,!1),Zt=Pe.bind(null,!0);Jt.comment=(t,e)=>`(Positive BigInt) ${Pe(!1,t,e)}n`,Zt.comment=(t,e)=>`(Negative BigInt) ${Pe(!0,t,e)}n`,p.registerDecoder(l.POS_BIGINT,Jt),p.registerDecoder(l.NEG_BIGINT,Zt);function ct(t,e){return L(t.contents),t}ct.comment=(t,e,r)=>{L(t.contents);let n={...e,initialDepth:r+2,noPrefixHex:!0},s=F(t),i=2**((s[0]&31)-24)+1,o=s[i]&31,a=E(s.subarray(i,++i));o>=24&&(a+=" ",a+=E(s.subarray(i,i+2**(o-24)))),n.minCol=Math.max(n.minCol,(r+1)*2+a.length);let d=Be(t.contents,n),u=`Embedded CBOR
10
+ `;let d=0;for(let u of t.children){if(Yt(u)){let f=String(d);t.mt===c.MAP?f=d%2?`val ${(d-1)/2}`:`key ${d/2}`:t.mt===c.TAG&&(f=""),n+=Wt(u,e,f)}d++}}return n}var Xr={...b.defaultDecodeOptions,initialDepth:0,noPrefixHex:!1,minCol:0};function Pe(t,e){let r={...Xr,...e,ParentType:we,saveOriginal:!0},n=new B(t,r),s,i;for(let a of n){if(i=b.create(a,s,r,n),a[2]===y.BREAK)if(s?.isStreaming)s.left=1;else throw new Error("Unexpected BREAK");if(!Yt(i)){let f=new we(a,0,s,r);f.leaf=!0,f.children.push(i),z(f,n.toHere(a[3])),i=f}let d=(i.depth+1)*2,u=i.numBytes();for(u&&(d+=1,d+=u*2),r.minCol=Math.max(r.minCol,d),s&&s.push(i,n,a[3]),s=i;s?.done;)i=s,i.leaf||z(i,n.toHere(i.offset)),{parent:s}=s}e&&(e.minCol=r.minCol);let o=r.noPrefixHex?"":`0x${T(n.toHere(0))}
11
+ `;return o+=Wt(i,r),o}var Jt=!Nt();function je(t){if(typeof t=="object"&&t){if(t.constructor!==Number)throw new Error(`Expected number: ${t}`)}else if(typeof t!="number")throw new Error(`Expected number: ${t}`)}function W(t){if(typeof t=="object"&&t){if(t.constructor!==String)throw new Error(`Expected string: ${t}`)}else if(typeof t!="string")throw new Error(`Expected string: ${t}`)}function P(t){if(!(t instanceof Uint8Array))throw new Error(`Expected Uint8Array: ${t}`)}function nr(t){if(!Array.isArray(t))throw new Error(`Expected Array: ${t}`)}w(Map,(t,e,r)=>{let n=[...t.entries()].map(s=>[s[0],s[1],D(s[0],r)]);if(r.rejectDuplicateKeys){let s=new Set;for(let[i,o,a]of n){let d=T(a);if(s.has(d))throw new Error(`Duplicate map key: 0x${d}`);s.add(d)}}r.sortKeys&&n.sort(r.sortKeys),Be(t,t.size,c.MAP,e,r);for(let[s,i,o]of n)e.write(o),K(i,e,r)});function at(t){return W(t.contents),new Date(t.contents)}at.comment=t=>{W(t.contents);let e=new Date(t.contents);return`(String ${t.tag===l.DATE_FULL?"Full ":""}Date) ${e.toISOString()}`},p.registerDecoder(l.DATE_STRING,at),p.registerDecoder(l.DATE_FULL,at);function Zt(t){return je(t.contents),new Date(t.contents*1e3)}Zt.comment=t=>(je(t.contents),`(Epoch Date) ${new Date(t.contents*1e3).toISOString()}`),p.registerDecoder(l.DATE_EPOCH,Zt);var ut=1e3*60*60*24;function Xt(t){return je(t.contents),new Date(t.contents*ut)}Xt.comment=t=>(je(t.contents),`(Epoch Date) ${new Date(t.contents*ut).toISOString()}`),p.registerDecoder(l.DATE_EPOCH_DAYS,Xt),w(Date,(t,e,r)=>{switch(r.dateTag){case l.DATE_EPOCH:return[r.dateTag,t.valueOf()/1e3];case l.DATE_STRING:return[r.dateTag,t.toISOString().replace(/\.000Z$/,"Z")];case l.DATE_EPOCH_DAYS:return[r.dateTag,Math.floor(t.valueOf()/ut)];case l.DATE_FULL:return[r.dateTag,t.toISOString().split("T")[0]];default:throw new Error(`Unsupported date tag: ${r.dateTag}`)}});function Fe(t,e,r){if(P(e.contents),r.rejectBigInts)throw new Error(`Decoding unwanted big integer: ${e}(h'${T(e.contents)}')`);if(r.requirePreferred&&e.contents[0]===0)throw new Error(`Decoding overly-large bigint: ${e.tag}(h'${T(e.contents)})`);let n=e.contents.reduce((i,o)=>i<<8n|BigInt(o),0n);t&&(n=-1n-n);let s=n>=Number.MIN_SAFE_INTEGER&&n<=Number.MAX_SAFE_INTEGER;if(r.requirePreferred&&s)throw new Error(`Decoding bigint that could have been int: ${n}n`);return r.collapseBigInts&&s&&(n=Number(n)),r.boxed?V(n,e.contents):n}var er=Fe.bind(null,!1),tr=Fe.bind(null,!0);er.comment=(t,e)=>`(Positive BigInt) ${Fe(!1,t,e)}n`,tr.comment=(t,e)=>`(Negative BigInt) ${Fe(!0,t,e)}n`,p.registerDecoder(l.POS_BIGINT,er),p.registerDecoder(l.NEG_BIGINT,tr);function ct(t,e){return P(t.contents),t}ct.comment=(t,e,r)=>{P(t.contents);let n={...e,initialDepth:r+2,noPrefixHex:!0},s=q(t),i=2**((s[0]&31)-24)+1,o=s[i]&31,a=T(s.subarray(i,++i));o>=24&&(a+=" ",a+=T(s.subarray(i,i+2**(o-24)))),n.minCol=Math.max(n.minCol,(r+1)*2+a.length);let d=Pe(t.contents,n),u=`Embedded CBOR
12
12
  `;return u+=`${"".padStart((r+1)*2," ")}${a}`.padEnd(n.minCol+1," "),u+=`-- Bytes (Length: ${t.contents.length})
13
- `,u+=d,u},ct.noChildren=!0,p.registerDecoder(l.CBOR,ct),p.registerDecoder(l.URI,t=>(H(t.contents),new URL(t.contents)),"URI"),b(URL,t=>[l.URI,t.toString()]),p.registerDecoder(l.BASE64URL,t=>(H(t.contents),xt(t.contents)),"Base64url-encoded"),p.registerDecoder(l.BASE64,t=>(H(t.contents),ue(t.contents)),"Base64-encoded"),p.registerDecoder(35,t=>(H(t.contents),new RegExp(t.contents)),"RegExp"),p.registerDecoder(21065,t=>{H(t.contents);let e=`^(?:${t.contents})$`;return new RegExp(e,"u")},"I-RegExp"),p.registerDecoder(l.REGEXP,t=>{if(er(t.contents),t.contents.length<1||t.contents.length>2)throw new Error(`Invalid RegExp Array: ${t.contents}`);return new RegExp(t.contents[0],t.contents[1])},"RegExp"),b(RegExp,t=>[l.REGEXP,[t.source,t.flags]]),p.registerDecoder(64,t=>(L(t.contents),t.contents),"uint8 Typed Array");function T(t,e,r){L(t.contents);let n=t.contents.length;if(n%e.BYTES_PER_ELEMENT!==0)throw new Error(`Number of bytes must be divisible by ${e.BYTES_PER_ELEMENT}, got: ${n}`);n/=e.BYTES_PER_ELEMENT;let s=new e(n),i=new DataView(t.contents.buffer,t.contents.byteOffset,t.contents.byteLength),o=i[`get${e.name.replace(/Array/,"")}`].bind(i);for(let a=0;a<n;a++)s[a]=o(a*e.BYTES_PER_ELEMENT,r);return s}function q(t,e,r,n,s){let i=s.forceEndian??Qt;if(oe(i?e:r,t,s),R(n.byteLength,t,c.BYTE_STRING),Qt===i)t.write(new Uint8Array(n.buffer,n.byteOffset,n.byteLength));else{let o=`write${n.constructor.name.replace(/Array/,"")}`,a=t[o].bind(t);for(let d of n)a(d,i)}}p.registerDecoder(65,t=>T(t,Uint16Array,!1),"uint16, big endian, Typed Array"),p.registerDecoder(66,t=>T(t,Uint32Array,!1),"uint32, big endian, Typed Array"),p.registerDecoder(67,t=>T(t,BigUint64Array,!1),"uint64, big endian, Typed Array"),p.registerDecoder(68,t=>(L(t.contents),new Uint8ClampedArray(t.contents)),"uint8 Typed Array, clamped arithmetic"),b(Uint8ClampedArray,t=>[68,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)]),p.registerDecoder(69,t=>T(t,Uint16Array,!0),"uint16, little endian, Typed Array"),b(Uint16Array,(t,e,r)=>q(e,69,65,t,r)),p.registerDecoder(70,t=>T(t,Uint32Array,!0),"uint32, little endian, Typed Array"),b(Uint32Array,(t,e,r)=>q(e,70,66,t,r)),p.registerDecoder(71,t=>T(t,BigUint64Array,!0),"uint64, little endian, Typed Array"),b(BigUint64Array,(t,e,r)=>q(e,71,67,t,r)),p.registerDecoder(72,t=>(L(t.contents),new Int8Array(t.contents)),"sint8 Typed Array"),b(Int8Array,t=>[72,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)]),p.registerDecoder(73,t=>T(t,Int16Array,!1),"sint16, big endian, Typed Array"),p.registerDecoder(74,t=>T(t,Int32Array,!1),"sint32, big endian, Typed Array"),p.registerDecoder(75,t=>T(t,BigInt64Array,!1),"sint64, big endian, Typed Array"),p.registerDecoder(77,t=>T(t,Int16Array,!0),"sint16, little endian, Typed Array"),b(Int16Array,(t,e,r)=>q(e,77,73,t,r)),p.registerDecoder(78,t=>T(t,Int32Array,!0),"sint32, little endian, Typed Array"),b(Int32Array,(t,e,r)=>q(e,78,74,t,r)),p.registerDecoder(79,t=>T(t,BigInt64Array,!0),"sint64, little endian, Typed Array"),b(BigInt64Array,(t,e,r)=>q(e,79,75,t,r)),p.registerDecoder(81,t=>T(t,Float32Array,!1),"IEEE 754 binary32, big endian, Typed Array"),p.registerDecoder(82,t=>T(t,Float64Array,!1),"IEEE 754 binary64, big endian, Typed Array"),p.registerDecoder(85,t=>T(t,Float32Array,!0),"IEEE 754 binary32, little endian, Typed Array"),b(Float32Array,(t,e,r)=>q(e,85,81,t,r)),p.registerDecoder(86,t=>T(t,Float64Array,!0),"IEEE 754 binary64, big endian, Typed Array"),b(Float64Array,(t,e,r)=>q(e,86,82,t,r)),p.registerDecoder(l.SET,(t,e)=>{if(er(t.contents),e.sortKeys){let r=w.decodeToEncodeOpts(e),n=null;for(let s of t.contents){let i=[s,void 0,A(s,r)];if(n&&e.sortKeys(n,i)>=0)throw new Error(`Set items out of order in tag #${l.SET}`);n=i}}return new Set(t.contents)},"Set"),b(Set,(t,e,r)=>{let n=[...t];if(r.sortKeys){let s=n.map(i=>[i,void 0,A(i,r)]);s.sort(r.sortKeys),n=s.map(([i])=>i)}return[l.SET,n]}),p.registerDecoder(l.JSON,t=>(H(t.contents),JSON.parse(t.contents)),"JSON-encoded");function Xt(t){return L(t.contents),new J().decode(t.contents)}Xt.comment=t=>{L(t.contents);let e=new J;return`(WTF8 string): ${JSON.stringify(e.decode(t.contents))}`},p.registerDecoder(l.WTF8,Xt),p.registerDecoder(l.SELF_DESCRIBED,t=>t.contents,"Self-Described"),p.registerDecoder(l.INVALID_16,()=>{throw new Error(`Tag always invalid: ${l.INVALID_16}`)},"Invalid"),p.registerDecoder(l.INVALID_32,()=>{throw new Error(`Tag always invalid: ${l.INVALID_32}`)},"Invalid"),p.registerDecoder(l.INVALID_64,()=>{throw new Error(`Tag always invalid: ${l.INVALID_64}`)},"Invalid");function dt(t){throw new Error(`Encoding ${t.constructor.name} intentionally unimplmented. It is not concrete enough to interoperate. Convert to Uint8Array first.`)}b(ArrayBuffer,dt),b(DataView,dt),typeof SharedArrayBuffer<"u"&&b(SharedArrayBuffer,dt);function Le(t){return[NaN,t.valueOf()]}b(Boolean,Le),b(Number,Le),b(String,Le),b(BigInt,Le);function zr(t){let e={...w.defaultDecodeOptions};if(t.dcbor?Object.assign(e,w.dcborDecodeOptions):t.cde&&Object.assign(e,w.cdeDecodeOptions),Object.assign(e,t),Object.hasOwn(e,"rejectLongNumbers"))throw new TypeError("rejectLongNumbers has changed to requirePreferred");return e.boxed&&(e.saveOriginal=!0),e}var ft=class{parent=void 0;ret=void 0;step(e,r,n){if(this.ret=w.create(e,this.parent,r,n),e[2]===y.BREAK)if(this.parent?.isStreaming)this.parent.left=0;else throw new Error("Unexpected BREAK");else this.parent&&this.parent.push(this.ret,n,e[3]);for(this.ret instanceof w&&(this.parent=this.ret);this.parent?.done;){this.ret=this.parent.convert(n);let s=this.parent.parent;s?.replaceLast(this.ret,this.parent,n),this.parent=s}}};function pt(t,e={}){let r=zr(e),n=new U(t,r),s=new ft;for(let i of n)s.step(i,r,n);return s.ret}var{cdeDecodeOptions:go,dcborDecodeOptions:yo,defaultDecodeOptions:bo}=w;var S={encode(t){return A(t)},decode(t){return pt(t)}};var Fe={};k(Fe,{host:()=>Kr});import*as tr from"m1cro:app/host";var Kr={getSettings(){return tr.getSettings()}};var V={};k(V,{guest:()=>Yr,host:()=>Qr});import*as z from"m1cro:common/host";var Qr={getTenant(){return z.getTenant()},getArtifact(t){return z.getArtifact(t)},getCrd(t){return z.getCRD(t)},listProviders(t){return z.listProviders(t)}},Yr={getManifest(){return _.manifest},async start(){await _.emit("start")},async install(){await _.emit("install")}};var K={};k(K,{host:()=>Wr});import*as D from"m1cro:crypto/host";var Wr={deriveKey:(t,e)=>D.deriveKey(t,e),aesGcmEncrypt:t=>D.aesGcmEncrypt(t),aesGcmDecrypt:t=>D.aesGcmDecrypt(t),argon2Hash:(t,e,r,n,s,i)=>D.argon2Hash(t,e,r,n,s,i),argon2Verify:(t,e,r,n,s,i,o)=>D.argon2Verify(t,e,r,n,s,i,o)};var I={};k(I,{host:()=>Jr});import*as Q from"m1cro:entity/host";var Jr={async find(t){return await Q.find(t)},async insert(t){return await Q.insert(t)},async update(t){return await Q.update(t)},async remove(t){return await Q.remove(t)}};var X={};k(X,{host:()=>Zr});import*as Y from"m1cro:kv/host";var Zr={async get(t){return await Y.get(t)},async getDel(t){return await Y.getDel(t)},async set(t,e,r){return await Y.set(t,e,r)},async delete(t){return await Y.delete(t)}};var W={};k(W,{fromHostRequest:()=>nr,fromHostResponse:()=>rn,guest:()=>en,host:()=>Xr,toHostRequest:()=>tn,toHostResponse:()=>sr,types:()=>we});import*as we from"m1cro:rpc/types";import*as rr from"m1cro:rpc/host";var Xr={call:async t=>await rr.call(t)},en={call:async(t,e,r,n)=>{let s=_.router.routes[t];if(!s)throw new Error(`Route not found for index ${t}`);let i=nr(r),o=await s.handler.bind(_)(i);return await sr(o)}},nr=t=>new Request("http://"+t.getUrl()).withMethod(t.getMethod().tag).withHeaders(t.getHeaders()).withBody(t.getBody()),tn=async t=>{let e=new we.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}`)}return e.setUrl(t.url.toString()),e.setHeaders(Array.from(t.headers.entries())),e.setBody(await t.body()),e},rn=async t=>new Response(t.getStatus()).withHeaders(t.getHeaders()).withBody(t.getBody()),sr=async t=>{let e=new we.Response;return e.setStatus(t.status),e.setHeaders(Array.from(t.headers.entries())),e.setBody(await t.body()),e};import*as nn from"m1cro:log/host";var ie={};k(ie,{guest:()=>an,host:()=>on});import*as or from"m1cro:pub-sub/host";var on={publish:async(t,e,r)=>await or.publish(t,e,r)},an={async invokeEventHandler(t,e,r){let n=_.events[t]?.handler;if(!n)throw new Error(`Event handler not found for index ${t}`);let s=S.decode(r);await n.bind(_)(e,s)}};var je={};k(je,{host:()=>cn});import*as ir from"m1cro:sse/host";var cn={push:async(t,e)=>await ir.push(t,e)};var ar=19*1024,cr=2,dr=1,ur=32,ht={deriveKey:(t,e)=>K.host.deriveKey(t,e),aesGcmEncrypt:t=>{let e=S.encode(t);return K.host.aesGcmEncrypt(e)},aesGcmDecrypt:t=>{let e=K.host.aesGcmDecrypt(t);return S.decode(e)},argon2Hash:(t,e,r)=>K.host.argon2Hash({tag:t},new TextEncoder().encode(e),r?.mCost??ar,r?.tCost??cr,r?.pCost??dr,r?.outputLen??ur),argon2Verify:(t,e,r,n)=>K.host.argon2Verify({tag:t},new TextEncoder().encode(e),new TextEncoder().encode(r),n?.mCost??ar,n?.tCost??cr,n?.pCost??dr,n?.outputLen??ur)};var M=class{constructor(e,r){this._entity=e;this._query=r}_limit;_offset;_sorting;query(){let e={filter:JSON.stringify(this._query),limit:this._limit,offset:this._offset,sorting:void 0};return this._sorting&&(e.sorting={rules:Object.entries(this._sorting).map(([r,n])=>[r,{tag:n}])}),e}};var Ee=class extends M{constructor(e,r){super(e,r)}limit(e){return this._limit=e,this}offset(e){return this._offset=e,this}sort(e){return this._sorting={...this._sorting,...e},this}async exec(){let e={entity:this._entity.name,query:this.query()},{docs:r}=await I.host.find(e);return r.map(n=>JSON.parse(n))}},$e=class{_query;constructor(e,r){this._query=new Ee(e,r)}offset(e){return this._query.offset(e),this}sort(e){return this._query.sort(e),this}async exec(){return(await this._query.limit(1).exec())[0]}};var Ge=class t{constructor(e,r,n){this._entity=e;this._docs=r;this._returnMode=n}return(e){return new t(this._entity,this._docs,e)}async exec(){let e={entity:this._entity.name,docs:this._docs.map(n=>JSON.stringify(n)),returnType:{tag:"insertedIds"}};switch(this._returnMode){case"insertedIds":break;case"documents":e.returnType.tag="documents";break;default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let r=await I.host.insert(e);switch(r.tag){case"insertedIds":return r.value;case"documents":return r.value.map(o=>JSON.parse(o));default:throw new Error("Unexpected insert result",r)}}},Ce=class t{constructor(e,r,n){this._entity=e;this._doc=r;this._returnMode=n}return(e){return new t(this._entity,this._doc,e)}async exec(){let e={entity:this._entity.name,docs:[JSON.stringify(this._doc)],returnType:{tag:"insertedIds"}};switch(this._returnMode){case"insertedId":break;case"document":e.returnType.tag="documents";break;default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let r=await I.host.insert(e);switch(r.tag){case"insertedIds":let n=r.value[0];if(!n)throw new Error("Inserted ID is undefined");return n;case"documents":let s=r.value[0];if(!s)throw new Error("Document is undefined");return JSON.parse(s);default:throw new Error("Unexpected insertOne result",r)}}};var qe=class t extends M{constructor(r,n,s,i){super(r,n);this._update=s;this._returnMode=i}limit(r){return this._limit=r,this}offset(r){return this._offset=r,this}sort(r){return this._sorting={...this._sorting,...r},this}return(r){let n=new t(this._entity,this._query,this._update,r);return n._limit=this._limit,n._offset=this._offset,n._sorting=this._sorting,n}async exec(){let r={entity:this._entity.name,query:this.query(),update:JSON.stringify(this._update),upsert:!1,returnType:{tag:"affectedRows"}};switch(this._returnMode){case"affectedRows":case"oldDocuments":case"newDocuments":{r.returnType.tag=this._returnMode;break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.update(r);switch(n.tag){case"affectedRows":return n.value;case"documents":return n.value.map(o=>JSON.parse(o));default:throw new Error("Unexpected update result",n)}}},He=class t extends M{constructor(r,n,s,i){super(r,n);this._update=s;this._returnMode=i}_upsert=!1;offset(r){return this._query.offset(r),this}sort(r){return this._query.sort(r),this}upsert(r){return this._upsert=r,this}return(r){let n=new t(this._entity,this._query,this._update,r);return n._limit=this._limit,n._offset=this._offset,n._sorting=this._sorting,n}async exec(){this._limit=1;let r={entity:this._entity.name,query:this.query(),update:JSON.stringify(this._update),upsert:this._upsert,returnType:{tag:"affectedRows"}};switch(this._returnMode){case"success":break;case"oldDocument":{r.returnType.tag="oldDocuments";break}case"newDocument":{r.returnType.tag="newDocuments";break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.update(r);switch(n.tag){case"affectedRows":return n.value===1;case"documents":{let s=n.value[0];return s?JSON.parse(s):void 0}default:throw new Error("Unexpected updateOne result",n)}}};var ze=class t extends M{constructor(r,n,s){super(r,n);this._returnMode=s}limit(r){return this._limit=r,this}offset(r){return this._offset=r,this}sort(r){return this._sorting={...this._sorting,...r},this}return(r){let n=new t(this._entity,this._query,r);return n._limit=this._limit,n._offset=this._offset,n._sorting=this._sorting,n}async exec(){let r={entity:this._entity.name,query:this.query(),returnType:{tag:"affectedRows"}};switch(this._returnMode){case"affectedRows":case"documents":{r.returnType.tag=this._returnMode;break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.remove(r);switch(n.tag){case"affectedRows":return n.value;case"documents":return n.value.map(o=>JSON.parse(o));default:throw new Error("Unexpected remove result",n)}}},Ve=class t extends M{constructor(r,n,s){super(r,n);this._returnMode=s}offset(r){return this._query.offset(r),this}sort(r){return this._query.sort(r),this}return(r){let n=new t(this._entity,this._query,r);return n._offset=this._offset,n._sorting=this._sorting,n}async exec(){this._limit=1;let r={entity:this._entity.name,query:this.query(),returnType:{tag:"affectedRows"}};switch(this._returnMode){case"success":break;case"document":{r.returnType.tag="documents";break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.remove(r);switch(n.tag){case"affectedRows":return n.value===1;case"documents":{let s=n.value[0];return s?JSON.parse(s):void 0}default:throw new Error("Unexpected remove result",n)}}};var mt={entity:t=>new lt(t)},lt=class{constructor(e){this.name=e}find(e){return new Ee(this,e)}findOne(e){return new $e(this,e)}insert(e){return new Ge(this,e,"insertedIds")}insertOne(e){return new Ce(this,e,"insertedId")}update(e,r){return new qe(this,e,r,"affectedRows")}updateOne(e,r){return new He(this,e,r,"success")}remove(e){return new ze(this,e,"affectedRows")}removeOne(e){return new Ve(this,e,"success")}};var gt={get:async t=>{let e=await X.host.get(t);return JSON.parse(e)},getDel:async t=>{let e=await X.host.getDel(t);return JSON.parse(e)},set:async(t,e,r)=>{let n={};return r&&(r.ttl&&(n.ttl=r.ttl),r.existenceCheck&&(n.existenceCheck={tag:r.existenceCheck})),await X.host.set(t,JSON.stringify(e),n)},delete:async t=>await X.host.delete(t)};var yt={async publish(t,e,r){let n=S.encode(e);r=r??["public"],await ie.host.publish(t,n,r.map(s=>({tag:s})))}};var bt={async call(t,e){let r=W.fromRequest(new Request(t,e)),n=await W.host.call(r);return W.toResponse(n)},async get(t,e){return await this.call(t,{...e,method:"GET"})},async post(t,e){return await this.call(t,{...e,method:"POST",body:JSON.stringify(body)})},async put(t,e){return await this.call(t,{method:"PUT",body:JSON.stringify(e)})}};var wt={push:async(t,e)=>{let r=S.encode(t);return await je.host.push(r,e)}};var Et=class{#e=[];add(e){this.#e.push(e)}get get(){return this.#e}},Ke=class t{#e;#t;constructor(e=new Et,r="/"){this.#e=e,this.#t=this.#r(r)}get routes(){return this.#e.get}scope(e){let r=this.#t+this.#r(e);return new t(this.#e,r)}route(e,r,n,s){return r="/"+this.#t+"/"+this.#r(r),this.#e.add({method:e,path:r,handler:n,options:s}),this}get(e,r,n){return this.route("get",e,r,n)}post(e,r,n){return this.route("post",e,r,n)}put(e,r,n){return this.route("put",e,r,n)}patch(e,r,n){return this.route("patch",e,r,n)}delete(e,r,n){return this.route("delete",e,r,n)}#r(e){return e.replace(/^\/+/,"").replace(/\/+$/,"")}};var Qe=class{constructor(e,r,n,s,i,o){this.hooks=e;this.roles=r;this.capabilities=n;this.router=s;this.entities=i;this.events=o}crypto=Object.freeze(ht);kv=Object.freeze(gt);sse=Object.freeze(wt);providers=Object.freeze({list(e){let r=V.host.listProviders(e);return[]}});async emit(e,...r){let n=this.hooks[e]||[];await Promise.all(n.map(s=>s.bind(this)(...r)))}get tenant(){return V.host.getTenant()}settings(){let e=Fe.host.getSettings();return e?S.decode(e):void 0}crd(e){let r=V.host.getCrd(e);return r?S.decode(r):void 0}entity(e){return mt.entity(e)}async call(e,r){return await bt.call(e,r)}publish(e,r,n){yt.publish(e,r,n)}get manifest(){return{roles:this.roles.map(e=>{let r=e.type;if(r==="provider")return{tag:r,value:e.group};throw new Error(`Unknown role type: ${r}`)}),capabilities:Object.entries(this.capabilities).map(([e,r])=>[e,Array.from(r)]),functions:this.router.routes.map(e=>({method:{tag:e.method},path:e.path,timeoutMs:e.options?.timeoutMs??0,permissions:e.options?.permissions??[],authenticated:e.options?.authenticated??!1,visibility:{tag:e.options?.visibility??"public"}})),middlewares:[],jobs:[],entities:this.entities.map(e=>({name:e.name,schema:e.schema,indexes:e.indexes,scoped:!1})),events:this.events.map(({pattern:e})=>({pattern:e}))}}};var Ye=class{#e={};#t=[];#r={};#n=new Ke;#s=[];#o=[];on(e,r){return this.#e[e]||=[],this.#e[e].push(r),this}role(e){return this.#t.push(e),this}capability(e,r){return this.#r[e]||=new Set,r.forEach(n=>this.#r[e].add(n)),this}capabilities(e){return Object.entries(e).forEach(([r,n])=>this.capability(r,n)),this}routes(e){return e(this.#n),this}entity(e,r){let n={name:e,schema:new TextEncoder().encode(JSON.stringify(r)),indexes:[],scoped:!1};return this.#s.push(n),this}subscribe(e,r){return this.#o.push({pattern:e,handler:r}),this}build(){return new Qe(this.#e,this.#t,this.#r,this.#n,this.#s,this.#o)}};import un from"@EntryPoint";var fr=new Ye;un(fr);var _=fr.build(),yi={};var bi=V.guest;var wi=ie.guest;var Ei=W.guest;export{_ as app,gr as console,yi as guest,bi as"m1cro:common/guest",wi as"m1cro:pub-sub/guest",Ei as"m1cro:rpc/guest"};
13
+ `,u+=d,u},ct.noChildren=!0,p.registerDecoder(l.CBOR,ct),p.registerDecoder(l.URI,t=>(W(t.contents),new URL(t.contents)),"URI"),w(URL,t=>[l.URI,t.toString()]),p.registerDecoder(l.BASE64URL,t=>(W(t.contents),vt(t.contents)),"Base64url-encoded"),p.registerDecoder(l.BASE64,t=>(W(t.contents),ue(t.contents)),"Base64-encoded"),p.registerDecoder(35,t=>(W(t.contents),new RegExp(t.contents)),"RegExp"),p.registerDecoder(21065,t=>{W(t.contents);let e=`^(?:${t.contents})$`;return new RegExp(e,"u")},"I-RegExp"),p.registerDecoder(l.REGEXP,t=>{if(nr(t.contents),t.contents.length<1||t.contents.length>2)throw new Error(`Invalid RegExp Array: ${t.contents}`);return new RegExp(t.contents[0],t.contents[1])},"RegExp"),w(RegExp,t=>[l.REGEXP,[t.source,t.flags]]),p.registerDecoder(64,t=>(P(t.contents),t.contents),"uint8 Typed Array");function E(t,e,r){P(t.contents);let n=t.contents.length;if(n%e.BYTES_PER_ELEMENT!==0)throw new Error(`Number of bytes must be divisible by ${e.BYTES_PER_ELEMENT}, got: ${n}`);n/=e.BYTES_PER_ELEMENT;let s=new e(n),i=new DataView(t.contents.buffer,t.contents.byteOffset,t.contents.byteLength),o=i[`get${e.name.replace(/Array/,"")}`].bind(i);for(let a=0;a<n;a++)s[a]=o(a*e.BYTES_PER_ELEMENT,r);return s}function Y(t,e,r,n,s){let i=s.forceEndian??Jt;if(ne(i?e:r,t,s),R(n.byteLength,t,c.BYTE_STRING),Jt===i)t.write(new Uint8Array(n.buffer,n.byteOffset,n.byteLength));else{let o=`write${n.constructor.name.replace(/Array/,"")}`,a=t[o].bind(t);for(let d of n)a(d,i)}}p.registerDecoder(65,t=>E(t,Uint16Array,!1),"uint16, big endian, Typed Array"),p.registerDecoder(66,t=>E(t,Uint32Array,!1),"uint32, big endian, Typed Array"),p.registerDecoder(67,t=>E(t,BigUint64Array,!1),"uint64, big endian, Typed Array"),p.registerDecoder(68,t=>(P(t.contents),new Uint8ClampedArray(t.contents)),"uint8 Typed Array, clamped arithmetic"),w(Uint8ClampedArray,t=>[68,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)]),p.registerDecoder(69,t=>E(t,Uint16Array,!0),"uint16, little endian, Typed Array"),w(Uint16Array,(t,e,r)=>Y(e,69,65,t,r)),p.registerDecoder(70,t=>E(t,Uint32Array,!0),"uint32, little endian, Typed Array"),w(Uint32Array,(t,e,r)=>Y(e,70,66,t,r)),p.registerDecoder(71,t=>E(t,BigUint64Array,!0),"uint64, little endian, Typed Array"),w(BigUint64Array,(t,e,r)=>Y(e,71,67,t,r)),p.registerDecoder(72,t=>(P(t.contents),new Int8Array(t.contents)),"sint8 Typed Array"),w(Int8Array,t=>[72,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)]),p.registerDecoder(73,t=>E(t,Int16Array,!1),"sint16, big endian, Typed Array"),p.registerDecoder(74,t=>E(t,Int32Array,!1),"sint32, big endian, Typed Array"),p.registerDecoder(75,t=>E(t,BigInt64Array,!1),"sint64, big endian, Typed Array"),p.registerDecoder(77,t=>E(t,Int16Array,!0),"sint16, little endian, Typed Array"),w(Int16Array,(t,e,r)=>Y(e,77,73,t,r)),p.registerDecoder(78,t=>E(t,Int32Array,!0),"sint32, little endian, Typed Array"),w(Int32Array,(t,e,r)=>Y(e,78,74,t,r)),p.registerDecoder(79,t=>E(t,BigInt64Array,!0),"sint64, little endian, Typed Array"),w(BigInt64Array,(t,e,r)=>Y(e,79,75,t,r)),p.registerDecoder(81,t=>E(t,Float32Array,!1),"IEEE 754 binary32, big endian, Typed Array"),p.registerDecoder(82,t=>E(t,Float64Array,!1),"IEEE 754 binary64, big endian, Typed Array"),p.registerDecoder(85,t=>E(t,Float32Array,!0),"IEEE 754 binary32, little endian, Typed Array"),w(Float32Array,(t,e,r)=>Y(e,85,81,t,r)),p.registerDecoder(86,t=>E(t,Float64Array,!0),"IEEE 754 binary64, big endian, Typed Array"),w(Float64Array,(t,e,r)=>Y(e,86,82,t,r)),p.registerDecoder(l.SET,(t,e)=>{if(nr(t.contents),e.sortKeys){let r=b.decodeToEncodeOpts(e),n=null;for(let s of t.contents){let i=[s,void 0,D(s,r)];if(n&&e.sortKeys(n,i)>=0)throw new Error(`Set items out of order in tag #${l.SET}`);n=i}}return new Set(t.contents)},"Set"),w(Set,(t,e,r)=>{let n=[...t];if(r.sortKeys){let s=n.map(i=>[i,void 0,D(i,r)]);s.sort(r.sortKeys),n=s.map(([i])=>i)}return[l.SET,n]}),p.registerDecoder(l.JSON,t=>(W(t.contents),JSON.parse(t.contents)),"JSON-encoded");function rr(t){return P(t.contents),new Z().decode(t.contents)}rr.comment=t=>{P(t.contents);let e=new Z;return`(WTF8 string): ${JSON.stringify(e.decode(t.contents))}`},p.registerDecoder(l.WTF8,rr),p.registerDecoder(l.SELF_DESCRIBED,t=>t.contents,"Self-Described"),p.registerDecoder(l.INVALID_16,()=>{throw new Error(`Tag always invalid: ${l.INVALID_16}`)},"Invalid"),p.registerDecoder(l.INVALID_32,()=>{throw new Error(`Tag always invalid: ${l.INVALID_32}`)},"Invalid"),p.registerDecoder(l.INVALID_64,()=>{throw new Error(`Tag always invalid: ${l.INVALID_64}`)},"Invalid");function dt(t){throw new Error(`Encoding ${t.constructor.name} intentionally unimplmented. It is not concrete enough to interoperate. Convert to Uint8Array first.`)}w(ArrayBuffer,dt),w(DataView,dt),typeof SharedArrayBuffer<"u"&&w(SharedArrayBuffer,dt);function ke(t){return[NaN,t.valueOf()]}w(Boolean,ke),w(Number,ke),w(String,ke),w(BigInt,ke);function en(t){let e={...b.defaultDecodeOptions};if(t.dcbor?Object.assign(e,b.dcborDecodeOptions):t.cde&&Object.assign(e,b.cdeDecodeOptions),Object.assign(e,t),Object.hasOwn(e,"rejectLongNumbers"))throw new TypeError("rejectLongNumbers has changed to requirePreferred");return e.boxed&&(e.saveOriginal=!0),e}var ft=class{parent=void 0;ret=void 0;step(e,r,n){if(this.ret=b.create(e,this.parent,r,n),e[2]===y.BREAK)if(this.parent?.isStreaming)this.parent.left=0;else throw new Error("Unexpected BREAK");else this.parent&&this.parent.push(this.ret,n,e[3]);for(this.ret instanceof b&&(this.parent=this.ret);this.parent?.done;){this.ret=this.parent.convert(n);let s=this.parent.parent;s?.replaceLast(this.ret,this.parent,n),this.parent=s}}};function pt(t,e={}){let r=en(e),n=new B(t,r),s=new ft;for(let i of n)s.step(i,r,n);return s.ret}var{cdeDecodeOptions:go,dcborDecodeOptions:yo,defaultDecodeOptions:wo}=b;var S={encode(t){return D(t)},decode(t){return pt(t)}};import*as sr from"m1cro:pub-sub/host";var rn={publish:async(t,e,r)=>await sr.publish(t,e,r)},nn={async invokeEventHandler(t,e,r){let n=N.events[t]?.handler;if(!n)throw new Error(`Event handler not found for index ${t}`);let s=S.decode(r);await n.bind(N)(e,s)}};var $e={};F($e,{host:()=>sn});import*as or from"m1cro:sse/host";var sn={push:async(t,e)=>await or.push(t,e)};var on={};var ht=["trace","debug","info","warn","error","none"];var oe=t=>ht.indexOf(t)>=ht.indexOf(console.logLevel);Object.defineProperty(globalThis.console,"logLevel",{get(){return process.env.LOG_LEVEL||"info"}});var ie=console;globalThis.console={...globalThis.console,trace:(...t)=>{oe("trace")&&ie.trace("[TRACE]",...t)},debug:(...t)=>{oe("debug")&&ie.debug("[DEBUG]",...t)},info:(...t)=>{oe("info")&&ie.info("[INFO]",...t)},log:(...t)=>{oe("info")&&ie.log("[INFO]",...t)},warn:(...t)=>{oe("warn")&&ie.warn("[WARN]",...t)},error:(...t)=>{oe("error")&&ie.error("[ERROR]",...t)}};var ir=19*1024,ar=2,cr=1,dr=32,lt={deriveKey:(t,e)=>G.host.deriveKey(t,e),aesGcmEncrypt:t=>{let e=S.encode(t);return G.host.aesGcmEncrypt(e)},aesGcmDecrypt:t=>{let e=G.host.aesGcmDecrypt(t);return S.decode(e)},argon2Hash:(t,e,r)=>G.host.argon2Hash({tag:t},new TextEncoder().encode(e),r?.mCost??ir,r?.tCost??ar,r?.pCost??cr,r?.outputLen??dr),argon2Verify:(t,e,r,n)=>G.host.argon2Verify({tag:t},new TextEncoder().encode(e),new TextEncoder().encode(r),n?.mCost??ir,n?.tCost??ar,n?.pCost??cr,n?.outputLen??dr)};var M=class{constructor(e,r){this._entity=e;this._query=r}_limit;_offset;_sorting;query(){let e={filter:JSON.stringify(this._query),limit:this._limit,offset:this._offset,sorting:void 0};return this._sorting&&(e.sorting={rules:Object.entries(this._sorting).map(([r,n])=>[r,{tag:n}])}),e}};var be=class extends M{constructor(e,r){super(e,r)}limit(e){return this._limit=e,this}offset(e){return this._offset=e,this}sort(e){return this._sorting={...this._sorting,...e},this}async exec(){let e={entity:this._entity.name,query:this.query()},{docs:r}=await I.host.find(e);return r.map(n=>JSON.parse(n))}},Ge=class{_query;constructor(e,r){this._query=new be(e,r)}offset(e){return this._query.offset(e),this}sort(e){return this._query.sort(e),this}async exec(){return(await this._query.limit(1).exec())[0]}};var He=class t{constructor(e,r,n){this._entity=e;this._docs=r;this._returnMode=n}return(e){return new t(this._entity,this._docs,e)}async exec(){let e={entity:this._entity.name,docs:this._docs.map(n=>JSON.stringify(n)),returnType:{tag:"insertedIds"}};switch(this._returnMode){case"insertedIds":break;case"documents":e.returnType.tag="documents";break;default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let r=await I.host.insert(e);switch(r.tag){case"insertedIds":return r.value;case"documents":return r.value.map(o=>JSON.parse(o));default:throw new Error("Unexpected insert result",r)}}},Ce=class t{constructor(e,r,n){this._entity=e;this._doc=r;this._returnMode=n}return(e){return new t(this._entity,this._doc,e)}async exec(){let e={entity:this._entity.name,docs:[JSON.stringify(this._doc)],returnType:{tag:"insertedIds"}};switch(this._returnMode){case"insertedId":break;case"document":e.returnType.tag="documents";break;default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let r=await I.host.insert(e);switch(r.tag){case"insertedIds":let n=r.value[0];if(!n)throw new Error("Inserted ID is undefined");return n;case"documents":let s=r.value[0];if(!s)throw new Error("Document is undefined");return JSON.parse(s);default:throw new Error("Unexpected insertOne result",r)}}};var qe=class t extends M{constructor(r,n,s,i){super(r,n);this._update=s;this._returnMode=i}limit(r){return this._limit=r,this}offset(r){return this._offset=r,this}sort(r){return this._sorting={...this._sorting,...r},this}return(r){let n=new t(this._entity,this._query,this._update,r);return n._limit=this._limit,n._offset=this._offset,n._sorting=this._sorting,n}async exec(){let r={entity:this._entity.name,query:this.query(),update:JSON.stringify(this._update),upsert:!1,returnType:{tag:"affectedRows"}};switch(this._returnMode){case"affectedRows":case"oldDocuments":case"newDocuments":{r.returnType.tag=this._returnMode;break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.update(r);switch(n.tag){case"affectedRows":return n.value;case"documents":return n.value.map(o=>JSON.parse(o));default:throw new Error("Unexpected update result",n)}}},ze=class t extends M{constructor(r,n,s,i){super(r,n);this._update=s;this._returnMode=i}_upsert=!1;offset(r){return this._query.offset(r),this}sort(r){return this._query.sort(r),this}upsert(r){return this._upsert=r,this}return(r){let n=new t(this._entity,this._query,this._update,r);return n._limit=this._limit,n._offset=this._offset,n._sorting=this._sorting,n}async exec(){this._limit=1;let r={entity:this._entity.name,query:this.query(),update:JSON.stringify(this._update),upsert:this._upsert,returnType:{tag:"affectedRows"}};switch(this._returnMode){case"success":break;case"oldDocument":{r.returnType.tag="oldDocuments";break}case"newDocument":{r.returnType.tag="newDocuments";break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.update(r);switch(n.tag){case"affectedRows":return n.value===1;case"documents":{let s=n.value[0];return s?JSON.parse(s):void 0}default:throw new Error("Unexpected updateOne result",n)}}};var Ve=class t extends M{constructor(r,n,s){super(r,n);this._returnMode=s}limit(r){return this._limit=r,this}offset(r){return this._offset=r,this}sort(r){return this._sorting={...this._sorting,...r},this}return(r){let n=new t(this._entity,this._query,r);return n._limit=this._limit,n._offset=this._offset,n._sorting=this._sorting,n}async exec(){let r={entity:this._entity.name,query:this.query(),returnType:{tag:"affectedRows"}};switch(this._returnMode){case"affectedRows":case"documents":{r.returnType.tag=this._returnMode;break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.remove(r);switch(n.tag){case"affectedRows":return n.value;case"documents":return n.value.map(o=>JSON.parse(o));default:throw new Error("Unexpected remove result",n)}}},Ke=class t extends M{constructor(r,n,s){super(r,n);this._returnMode=s}offset(r){return this._query.offset(r),this}sort(r){return this._query.sort(r),this}return(r){let n=new t(this._entity,this._query,r);return n._offset=this._offset,n._sorting=this._sorting,n}async exec(){this._limit=1;let r={entity:this._entity.name,query:this.query(),returnType:{tag:"affectedRows"}};switch(this._returnMode){case"success":break;case"document":{r.returnType.tag="documents";break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.remove(r);switch(n.tag){case"affectedRows":return n.value===1;case"documents":{let s=n.value[0];return s?JSON.parse(s):void 0}default:throw new Error("Unexpected remove result",n)}}};var gt={entity:t=>new mt(t)},mt=class{constructor(e){this.name=e}find(e){return new be(this,e)}findOne(e){return new Ge(this,e)}insert(e){return new He(this,e,"insertedIds")}insertOne(e){return new Ce(this,e,"insertedId")}update(e,r){return new qe(this,e,r,"affectedRows")}updateOne(e,r){return new ze(this,e,r,"success")}remove(e){return new Ve(this,e,"affectedRows")}removeOne(e){return new Ke(this,e,"success")}};var yt={get:async t=>{let e=await J.host.get(t);return JSON.parse(e)},getDel:async t=>{let e=await J.host.getDel(t);return JSON.parse(e)},set:async(t,e,r)=>{let n={};return r&&(r.ttl&&(n.ttl=r.ttl),r.existenceCheck&&(n.existenceCheck={tag:r.existenceCheck})),await J.host.set(t,JSON.stringify(e),n)},delete:async t=>await J.host.delete(t)};var wt={async publish(t,e,r){let n=S.encode(e);r=r??["public"],await se.host.publish(t,n,r.map(s=>({tag:s})))}};var bt={async call(t,e){let r=O.fromRequest(new Request(t,e)),n=await O.host.call(r);return O.toResponse(n)},async get(t,e){return await this.call(t,{...e,method:"GET"})},async post(t,e){return await this.call(t,{...e,method:"POST",body:JSON.stringify(body)})},async put(t,e){return await this.call(t,{method:"PUT",body:JSON.stringify(e)})}};var Tt={push:async(t,e)=>{let r=S.encode(t);return await $e.host.push(r,e)}};var Et=class{#e=[];add(e){this.#e.push(e)}get get(){return this.#e}},Qe=class t{#e;#t;constructor(e=new Et,r="/"){this.#e=e,this.#t=this.#r(r)}get routes(){return this.#e.get}scope(e){let r=this.#t+this.#r(e);return new t(this.#e,r)}route(e,r,n,s){return r="/"+this.#t+"/"+this.#r(r),this.#e.add({method:e,path:r,handler:n,options:s}),this}get(e,r,n){return this.route("get",e,r,n)}post(e,r,n){return this.route("post",e,r,n)}put(e,r,n){return this.route("put",e,r,n)}patch(e,r,n){return this.route("patch",e,r,n)}delete(e,r,n){return this.route("delete",e,r,n)}#r(e){return e.replace(/^\/+/,"").replace(/\/+$/,"")}};var Ye=class{constructor(e,r,n,s,i,o){this.hooks=e;this.roles=r;this.capabilities=n;this.router=s;this.entities=i;this.events=o}crypto=Object.freeze(lt);kv=Object.freeze(yt);sse=Object.freeze(Tt);providers=Object.freeze({list(e){let r=$.host.listProviders(e);return[]}});async emit(e,...r){let n=this.hooks[e]||[];await Promise.all(n.map(s=>s.bind(this)(...r)))}get tenant(){return $.host.getTenant()}settings(){let e=Te.host.getSettings();return e?S.decode(e):void 0}crd(e){let r=$.host.getCrd(e);return r?S.decode(r):void 0}entity(e){return gt.entity(e)}async call(e,r){return await bt.call(e,r)}publish(e,r,n){wt.publish(e,r,n)}get manifest(){return{roles:this.roles.map(e=>{let r=e.type;if(r==="provider")return{tag:r,value:e.group};throw new Error(`Unknown role type: ${r}`)}),capabilities:Object.entries(this.capabilities).map(([e,r])=>[e,Array.from(r)]),functions:this.router.routes.map(e=>({method:{tag:e.method},path:e.path,timeoutMs:e.options?.timeoutMs??0,permissions:e.options?.permissions??[],authenticated:e.options?.authenticated??!1,visibility:{tag:e.options?.visibility??"public"}})),middlewares:[],jobs:[],entities:this.entities.map(e=>({name:e.name,schema:e.schema,indexes:e.indexes,scoped:!1})),events:this.events.map(({pattern:e})=>({pattern:e}))}}};var We=class{#e={};#t=[];#r={};#n=new Qe;#s=[];#o=[];on(e,r){return this.#e[e]||=[],this.#e[e].push(r),this}role(e){return this.#t.push(e),this}capability(e,r){return this.#r[e]||=new Set,r.forEach(n=>this.#r[e].add(n)),this}capabilities(e){return Object.entries(e).forEach(([r,n])=>this.capability(r,n)),this}routes(e){return e(this.#n),this}entity(e,r){let n={name:e,schema:new TextEncoder().encode(JSON.stringify(r)),indexes:[],scoped:!1};return this.#s.push(n),this}subscribe(e,r){return this.#o.push({pattern:e,handler:r}),this}build(){return new Ye(this.#e,this.#t,this.#r,this.#n,this.#s,this.#o)}};import cn from"@EntryPoint";var ur=new We;cn(ur);var N=ur.build(),Ti={};var Ei=$.guest;var Ri=se.guest;var Ii=O.guest;export{N as app,on as console,Ti as guest,Ei as"m1cro:common/guest",Ri as"m1cro:pub-sub/guest",Ii as"m1cro:rpc/guest"};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m1cro/js-bootstrap",
3
- "version": "0.1.0-beta.19",
3
+ "version": "0.1.0-beta.20",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist/bootstrap.js",
@@ -11,7 +11,7 @@
11
11
  "access": "public"
12
12
  },
13
13
  "scripts": {
14
- "build": "yarn fetch-wit-deps && esbuild src/index.ts --bundle --minify --format=esm --platform=browser --tsconfig=tsconfig.json --outfile=dist/bootstrap.js --external:m1cro:* --external:@EntryPoint",
14
+ "build": "yarn fetch-wit-deps && esbuild src/index.ts --bundle --minify --format=esm --platform=browser --tsconfig=tsconfig.json --outfile=dist/bootstrap.js --external:wasi:* --external:m1cro:* --external:@EntryPoint",
15
15
  "fetch-wit-deps": "wkg wit fetch --config registries.wkg.toml",
16
16
  "versioning": "yarn version --new-version",
17
17
  "deploy": "yarn publish --non-interactive"
package/wit/world.wit CHANGED
@@ -12,6 +12,7 @@ world facilities {
12
12
  }
13
13
 
14
14
  world app {
15
+ // import wasi:cli/environment@0.2.9;
15
16
  include facilities;
16
17
  include m1cro:app/bindings;
17
18
  }