@m1cro/js-bootstrap 0.1.0-beta.12 → 0.1.0-beta.14
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 dr=Object.defineProperty;var Q=(t,e)=>{for(var r in e)dr(t,r,{get:e[r],enumerable:!0})};import rn from"@EntryPoint";var Z={};Q(Z,{guest:()=>fr,host:()=>ur});import*as L from"m1cro:common/host";var ur={getTenant:()=>L.getTenant(),getArtifact:t=>L.getArtifact(t),getCRD:t=>L.getCRD(t),listProviders:t=>L.listProviders(t)},fr={getManifest:()=>ht.manifest};var P={};Q(P,{host:()=>pr});import*as O from"m1cro:crypto/host";var pr={deriveKey:(t,e)=>O.deriveKey(t,e),aesGcmEncrypt:t=>O.aesGcmEncrypt(t),aesGcmDecrypt:t=>O.aesGcmDecrypt(t),argon2Hash:(t,e,r,n,s,i)=>O.argon2Hash(t,e,r,n,s,i),argon2Verify:(t,e,r,n,s,i,o)=>O.argon2Verify(t,e,r,n,s,i,o)};var I={};Q(I,{host:()=>hr});import*as F from"m1cro:entity/host";var hr={find:async t=>await F.find(t),insert:async t=>await F.insert(t),update:async t=>await F.update(t),remove:async t=>await F.remove(t)};var K={};Q(K,{host:()=>lr});import*as $ from"m1cro:kv/host";var lr={get:async t=>await $.get(t),getDel:async t=>await $.getDel(t),set:async(t,e,r)=>await $.set(t,e,r),delete:async t=>await $.delete(t)};var k={};Q(k,{fromRequest:()=>yr,fromResponse:()=>wr,guest:()=>gr,host:()=>mr,toRequest:()=>br,toResponse:()=>Er,types:()=>ae});import*as ae from"m1cro:rpc/types";import*as lt from"m1cro:rpc/host";var ie=class{get tenant(){return Z.host.getTenant()}};var mr={call:async t=>await lt.call(t)},gr={call:async(t,e,r,n)=>{let i=new ie().tenant;console.log("Tenant:",i),console.log("Index:",t),console.log("Middlewares:",e),console.log("Request:",r),console.log("Source:",n);let o=JSON.stringify({success:!0});return new Response(o,{headers:{"content-type":"application/json"}})}},yr=async t=>{let e=new ae.Request,r=t.method.toLowerCase();switch(r){case"get":case"post":case"put":case"patch":case"delete":e.setMethod({tag:r});break;default:throw new Error(`Invalid method: ${r}`)}e.setUrl(t.url),e.setHeaders(Array.from(t.headers.entries()));let n=await t.bytes();return e.setBody(n),e},br=async t=>{let e=t.getUrl(),r={method:t.getMethod().tag,headers:t.getHeaders()},n=t.getBody();return n.length>0&&(r.body=n.buffer),new Request(e,r)},wr=async t=>{let e=new ae.Response;e.setStatus(t.status),e.setHeaders(Array.from(t.headers.entries()));let r=await t.bytes();return e.setBody(r),e},Er=async t=>{let e=t.body();return new Response(e.length>0?e.buffer:null,{headers:t.getHeaders(),status:t.getStatus()})};import*as Tr from"m1cro:log/host";var X={};Q(X,{guest:()=>Sr,host:()=>Ir});import*as mt from"m1cro:pub-sub/host";var Ir={publish:async(t,e,r)=>await mt.publish(t,e,r)},Sr={invokeEventHandler:async(t,e)=>{}};var Ee={};Q(Ee,{host:()=>Nr});import*as gt from"m1cro:sse/host";var Nr={push:async(t,e)=>await gt.push(t,e)};var Qe=class{#e=[];add(e){this.#e.push(e)}get get(){return this.#e}},Te=class t{#e;#t;constructor(e=new Qe,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 Re=class{roles;capabilities;router;entities;events;constructor(e){let r=new Ke;e(r),this.roles=r._roles,this.capabilities=r._capabilities,this.router=r._router,this.entities=r._entities,this.events=r._events}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}))}}},Ke=class{_roles=[];_capabilities={};_router=new Te;_entities=[];_events=[];on(){return this}role(e){return this._roles.push(e),this}capability(e,r){return this._capabilities[e]||=new Set,r.forEach(n=>this._capabilities[e].add(n)),this}capabilities(e){return Object.entries(e).forEach(([r,n])=>this.capability(r,n)),this}routes(e){return e(this._router),this}entity(e,r){let n={name:e,schema:new TextEncoder().encode(JSON.stringify(r)),indexes:[],scoped:!1};return this._entities.push(n),this}event(e,r){return this._events.push({pattern:e,handler:r}),this}};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},A={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 j(t){if(t!=null&&typeof t=="object")return t[y.ENCODED]}function yt(t){if(t!=null&&typeof t=="object")return t[y.LENGTH]}function q(t,e){Object.defineProperty(t,y.ENCODED,{configurable:!0,enumerable:!1,value:e})}function G(t,e){let r=Object(t);return q(r,e),r}var Ye=Symbol("CBOR_RANGES");function bt(t,e){Object.defineProperty(t,Ye,{configurable:!1,enumerable:!1,writable:!1,value:e})}function ce(t){return t[Ye]}function xr(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&&bt(n,i)}return n}function Ie(t){let e=Math.ceil(t.length/2),r=new Uint8Array(e);e--;for(let n=t.length,s=n-2;n>=0;n=s,s-=2,e--)r[e]=parseInt(t.substring(s,n),16);return r}function E(t){return t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")}function wt(t){let e=t.reduce((o,a)=>o+a.length,0),r=t.some(o=>xr(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[Ye]??[[0,o.length]];for(let d of a)d[0]+=i;n.push(...a)}i+=o.length}return r&&bt(s,n),s}function ue(t){let e=atob(t);return Uint8Array.from(e,r=>r.codePointAt(0))}var Or={"-":"+",_:"/"};function Et(t){let e=t.replace(/[_-]/g,r=>Or[r]);return ue(e.padEnd(Math.ceil(e.length/4)*4,"="))}function Tt(){let t=new Uint8Array(4),e=new Uint32Array(t.buffer);return!((e[0]=1)&t[0])}function We(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 Se(t,e){let[r,n,s]=t,[i,o,a]=e,d=Math.min(s.length,a.length);for(let u=0;u<d;u++){let f=s[u]-a[u];if(f!==0)return f}return 0}var 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 Je=1n<<15n,pe=0b11111n<<10n,At=1n<<9n,vt=At-1n,Rt=At|vt,Ze=1n<<31n,he=0b11111111n<<23n,Ut=1n<<22n,_t=Ut-1n,It=Ut|_t,Ne=1n<<63n,D=0b11111111111n<<52n,le=1n<<51n,xe=le-1n,St=le|xe,Nt=xe-(vt<<42n),xt=xe-(_t<<29n),Ar={2:"0b",8:"0o",16:"0x"},Dt=(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))(Dt||{});function Ot(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=Ne,e=-e),e>=le)throw new Error(`Payload too large: ${s}`);let o=r?le:0n;switch(this.#e=i|D|o|e,n){case-2:throw new Error("NAN_SIZE.NATURAL only valid for bigint constructor");case-1:n=this.preferredSize;break;case 2:if(this.#e&Nt)throw new Error("Invalid size for payload");break;case 4:if(this.#e&xt)throw new Error("Invalid size for payload");break;case 8:break;default:throw new Error(`Invalid size: ${n}`)}this.#t=n}else if(typeof e=="bigint"){let i=-1;if((e&D)===D)this.#e=e,i=8;else if((e&he)===he){let o=(e&Ze)<<32n;this.#e=o|D|(e&It)<<29n,i=4}else if((e&pe)===pe){let o=(e&Je)<<48n;this.#e=o|D|(e&Rt)<<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&Je)<<48n;this.#e=a|D|(o&Rt)<<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&Ze)<<32n;this.#e=a|D|(o&It)<<29n,this.#t=4;break}case 9:{if(e[0]!==251)throw new Error("Invalid CBOR encoding for double float");if(this.#e=i.getBigUint64(1,!1),(this.#e&D)!==D)throw new Error("Not a NaN (NaNaN)");this.#t=8;break}default:throw new RangeError(`Invalid NAN size (should be 2, 4, or 8): ${e.length-1}`)}}if(!this.payload&&!this.quiet)throw new Error("Signalling NaN with zero payload")}get bytes(){let e=new ArrayBuffer(this.#t+1),r=new DataView(e);switch(this.#t){case 2:{r.setUint8(0,249);let n=(this.#e&Ne?Je:0n)|pe|(this.#e&St)>>42n;r.setUint16(1,Number(n),!1);break}case 4:{r.setUint8(0,250);let n=(this.#e&Ne?Ze:0n)|he|(this.#e&St)>>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&Ne?-1:1}get payload(){return Number(this.#e&xe)*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&Nt)===0n?2:(this.#e&xt)===0n?4:8}get isShortestEncoding(){return this.preferredSize===this.#t}toCBOR(e){e.write(this.bytes)}toString(e=10){return Ot(this,1,{},r=>(Ar[e]??"")+r.toString(e))}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return Ot(this,e,r,n)}};function Xe(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 Oe(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 Mt(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 Bt(t){switch(t.length){case 2:Xe(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")}},Ae=class extends RangeError{code="ERR_ENCODING_NOT_SUPPORTED";constructor(e){super(`Invalid encoding: "${e}"`)}};var ve=new Uint8Array(0);var et=55296,Lt=56320,Pt=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):ve}var Dr=[0,0,0,0,0,0,0,0,-1,-1,-1,-1,1,1,2,3],Y=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 Ae(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++]=Pt},f=()=>{let g=this.#r;for(let x=0;x<g;x++)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 x=this.#t-65536;o[d++]=x>>>10&1023|et,o[d++]=x&1023|Lt}this.#t=0,this.#r=0,this.#n=!1}}};for(let g of s)d>=a&&(i.push(String.fromCharCode.apply(null,o.subarray(0,d))),d=0),m(g);return n||(this.#n=!0,(this.#t||this.#e)&&f()),d>0&&i.push(String.fromCharCode.apply(null,o.subarray(0,d))),i.join("")}};function Mr(t){let e=0;for(let r of t){let n=r.codePointAt(0);n<128?e++:n<2048?e+=2:n<65536?e+=3:e+=4}return e}var re=class{encoding=Ue;encode(e){if(!e)return ve;let r=new Uint8Array(Mr(String(e)));return this.encodeInto(e,r),r}encodeInto(e,r){let n=String(e),s=n.length,i=r.length,o=0,a=0;for(a=0;a<s;a++){let d=n.codePointAt(a);if(d<128){if(o>=i)break;r[o++]=d}else if(d<2048){if(o>=i-1)break;r[o++]=192|d>>6,r[o++]=128|d&63}else if(d<65536){if(o>=i-2)break;r[o++]=224|d>>12,r[o++]=128|d>>6&63,r[o++]=128|d&63}else{if(o>=i-3)break;r[o++]=240|d>>18,r[o++]=128|d>>12&63,r[o++]=128|d>>6&63,r[o++]=128|d&63,a++}}return{read:a,written:o}}};var{ENCODED:Jn}=y,Ft=c.SIMPLE_FLOAT<<5|h.TWO,Br=c.SIMPLE_FLOAT<<5|h.FOUR,Lr=c.SIMPLE_FLOAT<<5|h.EIGHT,Pr=c.SIMPLE_FLOAT<<5|A.TRUE,Fr=c.SIMPLE_FLOAT<<5|A.FALSE,$r=c.SIMPLE_FLOAT<<5|A.UNDEFINED,kr=c.SIMPLE_FLOAT<<5|A.NULL,jr=new TextEncoder,qr=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},rt={cde:!0,ignoreOriginalEncoding:!0,sortKeys:Se},$t={...rt,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 tt(t,e,r){if(r.rejectFloats)throw new Error(`Attempt to encode an unwanted floating point number: ${t}`);if(isNaN(t))e.writeUint8(Ft),e.writeUint16(32256);else if(!r.float64&&Math.fround(t)===t){let n=Oe(t);n===null?(e.writeUint8(Br),e.writeFloat32(t)):(e.writeUint8(Ft),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 jt(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 Gr(t,e,r){r.flushToZero&&(t=Mt(t)),Object.is(t,-0)?r.simplifyNegativeZero?r.avoidInts?tt(0,e,r):R(0,e):tt(t,e,r):!r.avoidInts&&Number.isSafeInteger(t)?R(t,e):r.reduceUnsafeNumbers&&Math.floor(t)===t&&t>=ee.MIN&&t<=ee.MAX?jt(BigInt(t),e,r):tt(t,e,r)}function Cr(t,e,r){let n=r.stringNormalization?t.normalize(r.stringNormalization):t;if(r.wtf8&&!t.isWellFormed()){let s=qr.encode(n);ne(l.WTF8,e,r),R(s.length,e,c.BYTE_STRING),e.write(s)}else{let s=jr.encode(n);R(s.length,e,c.UTF8_STRING),e.write(s)}}function Hr(t,e,r){let n=t;Me(n,n.length,c.ARRAY,e,r);for(let s of n)C(s,e,r)}function zr(t,e){R(t.length,e,c.BYTE_STRING),e.write(t)}var _e=new fe;_e.registerEncoder(Array,Hr),_e.registerEncoder(Uint8Array,zr);function b(t,e){return _e.registerEncoder(t,e)}function Me(t,e,r,n,s){let i=yt(t);i&&!s.ignoreOriginalEncoding?n.write(i):R(e,n,r)}function Vr(t,e,r){if(t===null){e.writeUint8(kr);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),C(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),C(i[1],e,r));return}if(typeof t.toJSON=="function"){C(t.toJSON(),e,r);return}let s=Object.entries(t).map(i=>[i[0],i[1],v(i[0],r)]);r.sortKeys&&s.sort(r.sortKeys),Me(t,s.length,c.MAP,e,r);for(let[i,o,a]of s)e.write(a),C(o,e,r)}function C(t,e,r){switch(typeof t){case"number":Gr(t,e,r);break;case"bigint":jt(t,e,r);break;case"string":Cr(t,e,r);break;case"boolean":e.writeUint8(t?Pr:Fr);break;case"undefined":if(r.rejectUndefined)throw new Error("Attempt to encode unwanted undefined.");e.writeUint8($r);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 v(t,e={}){let r={...De};e.dcbor?Object.assign(r,$t):e.cde&&Object.assign(r,rt),Object.assign(r,e);let n=new te(r);return C(t,n,r),n.read()}var W=(t=>(t[t.NEVER=-1]="NEVER",t[t.PREFERRED=0]="PREFERRED",t[t.ALWAYS=1]="ALWAYS",t))(W||{});var N=class t{static KnownSimple=new Map([[A.FALSE,!1],[A.TRUE,!0],[A.NULL,null],[A.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 Qr=new TextDecoder("utf8",{fatal:!0,ignoreBOM:!0}),U=class t{static defaultOptions={maxDepth:1024,encoding:"hex",requirePreferred:!1};#e;#t;#r=0;#n;constructor(e,r){if(this.#n={...t.defaultOptions,...r},typeof e=="string")switch(this.#n.encoding){case"hex":this.#e=Ie(e);break;case"base64":this.#e=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=Xe(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,Qr.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=N.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 Kr=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 w=class t{static defaultDecodeOptions={...U.defaultOptions,ParentType:t,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:W.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:Se};static dcborDecodeOptions={...this.cdeDecodeOptions,dcbor:!0,convertUnsafeIntsToFloat:!0,rejectDuplicateKeys:!0,rejectLargeNegatives:!0,rejectLongLoundNaN:!0,rejectLongFloats:!0,rejectNegativeZero:!0,rejectSimple:!0,rejectUndefined:!0,rejectUnsafeFloatInts:!0,rejectStringsNotNormalizedAs:"NFC"};parent;mt;ai;left;offset;count=0;children=[];depth=0;#e;#t=null;constructor(e,r,n,s){if([this.mt,this.ai,,this.offset]=e,this.left=r,this.parent=n,this.#e=s,n&&(this.depth=n.depth+1),this.mt===c.MAP&&(this.#e.sortKeys||this.#e.rejectDuplicateKeys)&&(this.#t=[]),this.#e.rejectStreaming&&this.ai===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?G(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&&Bt(s.toHere(d+1)),n.rejectLongFloats){let u=v(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<Kr.get(o))throw new Error(`Number should have been encoded shorter: ${a}`)}if(typeof a=="number"&&n.boxed)return G(a,s.toHere(d))}else{if(n.rejectSimple&&a instanceof N)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 [${We(a)}] instead of [${We(u)}]`)}return n.boxed?G(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=j(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=j(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 wt(this.children);case c.UTF8_STRING:{let n=this.children.join("");r=this.#e.boxed?G(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"&&q(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 nt=" ",Jr=new TextEncoder,Be=class extends w{close="";quote='"';get isEmptyStream(){return(this.mt===c.UTF8_STRING||this.mt===c.BYTE_STRING)&&this.count===0}};function H(t,e,r,n){let s="";if(e===h.INDEFINITE)s+="_";else{if(n.diagnosticSizes===W.NEVER)return"";{let i=n.diagnosticSizes===W.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?Oe(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 st(t,e){let r={...w.defaultDecodeOptions,...e,ParentType:Be},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
|
-
${
|
|
3
|
-
${
|
|
4
|
-
${
|
|
5
|
-
`,s.length>i+1){let d=
|
|
6
|
-
`,n+=Pe(
|
|
7
|
-
`);if(m>i)for(let
|
|
1
|
+
var hr=Object.defineProperty;var K=(t,e)=>{for(var r in e)hr(t,r,{get:e[r],enumerable:!0})};var mr={};var We=["trace","debug","log","warn","error","none"];var ce=t=>We.indexOf(t)>=We.indexOf(console.logLevel);Object.defineProperty(globalThis.console,"logLevel",{get(){return process.env.LOG_LEVEL||"info"}});var de=console;globalThis.console={...globalThis.console,trace:(t,...e)=>{ce("trace")&&de.trace(t,...e)},debug:(t,...e)=>{ce("debug")&&de.debug(t,...e)},log:(t,...e)=>{ce("log")&&de.log(t,...e)},warn:(t,...e)=>{ce("warn")&&de.warn(t,...e)},error:(t,...e)=>{ce("error")&&de.error(t,...e)}};import an from"@EntryPoint";var X={};K(X,{guest:()=>yr,host:()=>gr});import*as P from"m1cro:common/host";var gr={getTenant:()=>P.getTenant(),getArtifact:t=>P.getArtifact(t),getCRD:t=>P.getCRD(t),listProviders:t=>P.listProviders(t)},yr={getManifest:()=>Y.manifest};var F={};K(F,{host:()=>br});import*as N from"m1cro:crypto/host";var br={deriveKey:(t,e)=>N.deriveKey(t,e),aesGcmEncrypt:t=>N.aesGcmEncrypt(t),aesGcmDecrypt:t=>N.aesGcmDecrypt(t),argon2Hash:(t,e,r,n,s,i)=>N.argon2Hash(t,e,r,n,s,i),argon2Verify:(t,e,r,n,s,i,o)=>N.argon2Verify(t,e,r,n,s,i,o)};var I={};K(I,{host:()=>wr});import*as $ from"m1cro:entity/host";var wr={find:async t=>await $.find(t),insert:async t=>await $.insert(t),update:async t=>await $.update(t),remove:async t=>await $.remove(t)};var W={};K(W,{host:()=>Er});import*as k from"m1cro:kv/host";var Er={get:async t=>await k.get(t),getDel:async t=>await k.getDel(t),set:async(t,e,r)=>await k.set(t,e,r),delete:async t=>await k.delete(t)};var j={};K(j,{fromRequest:()=>Ir,fromResponse:()=>wt,guest:()=>Rr,host:()=>Tr,toRequest:()=>bt,toResponse:()=>Sr,types:()=>ue});import*as ue from"m1cro:rpc/types";import*as yt from"m1cro:rpc/host";var ee=class{get tenant(){return X.host.getTenant()}};var Tr={call:async t=>await yt.call(t)},Rr={call:async(t,e,r,n)=>{let s=Y.router.routes[t];if(!s)throw new Error(`Route not found for index ${t}`);let i=new ee;console.debug("converting request to m1cro request");let o=await bt(r);console.debug("calling route handler");let a=await s.handler(o,i);return console.debug("converting response to m1cro response"),await wt(a)}},Ir=async t=>{let e=new ue.Request,r=t.method.toLowerCase();switch(r){case"get":case"post":case"put":case"patch":case"delete":e.setMethod({tag:r});break;default:throw new Error(`Invalid method: ${r}`)}e.setUrl(t.url),e.setHeaders(Array.from(t.headers.entries()));let n=await t.bytes();return e.setBody(n),e},bt=async t=>{let e=t.getUrl(),r={method:t.getMethod().tag,headers:t.getHeaders()},n=t.getBody();return n.length>0&&(r.body=n.buffer),new Request(e,r)},wt=async t=>{let e=new ue.Response;e.setStatus(t.status),e.setHeaders(Array.from(t.headers.entries()));let r=await t.bytes();return e.setBody(r),e},Sr=async t=>{let e=t.body();return new Response(e.length>0?e.buffer:null,{headers:t.getHeaders(),status:t.getStatus()})};import*as xr from"m1cro:log/host";var oe={};K(oe,{guest:()=>sn,host:()=>nn});var c={POS_INT:0,NEG_INT:1,BYTE_STRING:2,UTF8_STRING:3,ARRAY:4,MAP:5,TAG:6,SIMPLE_FLOAT:7},h={DATE_STRING:0,DATE_EPOCH:1,POS_BIGINT:2,NEG_BIGINT:3,DECIMAL_FRAC:4,BIGFLOAT:5,BASE64URL_EXPECTED:21,BASE64_EXPECTED:22,BASE16_EXPECTED:23,CBOR:24,URI:32,BASE64URL:33,BASE64:34,MIME:36,DATE_EPOCH_DAYS:100,SET:258,JSON:262,WTF8:273,DATE_FULL:1004,REGEXP:21066,SELF_DESCRIBED:55799,INVALID_16:65535,INVALID_32:4294967295,INVALID_64:0xffffffffffffffffn},l={ZERO:0,ONE:24,TWO:25,FOUR:26,EIGHT:27,INDEFINITE:31},v={FALSE:20,TRUE:21,NULL:22,UNDEFINED:23},y=class{static BREAK=Symbol.for("github.com/hildjj/cbor2/break");static ENCODED=Symbol.for("github.com/hildjj/cbor2/cbor-encoded");static LENGTH=Symbol.for("github.com/hildjj/cbor2/length")},te={MIN:-(2n**63n),MAX:2n**64n-1n};var p=class t{static#e=new Map;tag;contents;constructor(e,r=void 0){this.tag=e,this.contents=r}get noChildren(){return!!t.#e.get(this.tag)?.noChildren}static registerDecoder(e,r,n){let s=this.#e.get(e);return this.#e.set(e,r),s&&("comment"in r||(r.comment=s.comment),"noChildren"in r||(r.noChildren=s.noChildren)),n&&!r.comment&&(r.comment=()=>`(${n})`),s}static clearDecoder(e){let r=this.#e.get(e);return this.#e.delete(e),r}static getDecoder(e){return this.#e.get(e)}static getAllDecoders(){return new Map(this.#e)}*[Symbol.iterator](){yield this.contents}push(e){return this.contents=e,1}decode(e){let r=e?.tags?.get(this.tag)??(e?.ignoreGlobalTags?void 0:t.#e.get(this.tag));return r?r(this,e):this}comment(e,r){let n=e?.tags?.get(this.tag)??(e?.ignoreGlobalTags?void 0:t.#e.get(this.tag));if(n?.comment)return n.comment(this,e,r)}toCBOR(){return[this.tag,this.contents]}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return`${this.tag}(${n(this.contents,r)})`}};function q(t){if(t!=null&&typeof t=="object")return t[y.ENCODED]}function Et(t){if(t!=null&&typeof t=="object")return t[y.LENGTH]}function G(t,e){Object.defineProperty(t,y.ENCODED,{configurable:!0,enumerable:!1,value:e})}function C(t,e){let r=Object(t);return G(r,e),r}var Je=Symbol("CBOR_RANGES");function Tt(t,e){Object.defineProperty(t,Je,{configurable:!1,enumerable:!1,writable:!1,value:e})}function fe(t){return t[Je]}function Nr(t){return fe(t)!==void 0}function pe(t,e=0,r=t.length-1){let n=t.subarray(e,r),s=fe(t);if(s){let i=[];for(let o of s)if(o[0]>=e&&o[0]+o[1]<=r){let a=[...o];a[0]-=e,i.push(a)}i.length&&Tt(n,i)}return n}function Ie(t){let e=Math.ceil(t.length/2),r=new Uint8Array(e);e--;for(let n=t.length,s=n-2;n>=0;n=s,s-=2,e--)r[e]=parseInt(t.substring(s,n),16);return r}function E(t){return t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")}function Rt(t){let e=t.reduce((o,a)=>o+a.length,0),r=t.some(o=>Nr(o)),n=[],s=new Uint8Array(e),i=0;for(let o of t){if(!(o instanceof Uint8Array))throw new TypeError(`Invalid array: ${o}`);if(s.set(o,i),r){let a=o[Je]??[[0,o.length]];for(let d of a)d[0]+=i;n.push(...a)}i+=o.length}return r&&Tt(s,n),s}function le(t){let e=atob(t);return Uint8Array.from(e,r=>r.codePointAt(0))}var vr={"-":"+",_:"/"};function It(t){let e=t.replace(/[_-]/g,r=>vr[r]);return le(e.padEnd(Math.ceil(e.length/4)*4,"="))}function St(){let t=new Uint8Array(4),e=new Uint32Array(t.buffer);return!((e[0]=1)&t[0])}function Ze(t){let e="";for(let r of t){let n=r.codePointAt(0)?.toString(16).padStart(4,"0");e&&(e+=", "),e+=`U+${n}`}return e}var he=class{#e=new Map;registerEncoder(e,r){let n=this.#e.get(e);return this.#e.set(e,r),n}get(e){return this.#e.get(e)}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}};function Se(t,e){let[r,n,s]=t,[i,o,a]=e,d=Math.min(s.length,a.length);for(let u=0;u<d;u++){let f=s[u]-a[u];if(f!==0)return f}return 0}var re=class t{static defaultOptions={chunkSize:4096};#e;#t=[];#r=null;#n=0;#s=0;constructor(e={}){if(this.#e={...t.defaultOptions,...e},this.#e.chunkSize<8)throw new RangeError(`Expected size >= 8, got ${this.#e.chunkSize}`);this.#o()}get length(){return this.#s}read(){this.#c();let e=new Uint8Array(this.#s),r=0;for(let n of this.#t)e.set(n,r),r+=n.length;return this.#o(),e}write(e){let r=e.length;r>this.#d()?(this.#c(),r>this.#e.chunkSize?(this.#t.push(e),this.#o()):(this.#o(),this.#t[this.#t.length-1].set(e),this.#n=r)):(this.#t[this.#t.length-1].set(e,this.#n),this.#n+=r),this.#s+=r}writeUint8(e){this.#i(1),this.#r.setUint8(this.#n,e),this.#a(1)}writeUint16(e,r=!1){this.#i(2),this.#r.setUint16(this.#n,e,r),this.#a(2)}writeUint32(e,r=!1){this.#i(4),this.#r.setUint32(this.#n,e,r),this.#a(4)}writeBigUint64(e,r=!1){this.#i(8),this.#r.setBigUint64(this.#n,e,r),this.#a(8)}writeInt16(e,r=!1){this.#i(2),this.#r.setInt16(this.#n,e,r),this.#a(2)}writeInt32(e,r=!1){this.#i(4),this.#r.setInt32(this.#n,e,r),this.#a(4)}writeBigInt64(e,r=!1){this.#i(8),this.#r.setBigInt64(this.#n,e,r),this.#a(8)}writeFloat32(e,r=!1){this.#i(4),this.#r.setFloat32(this.#n,e,r),this.#a(4)}writeFloat64(e,r=!1){this.#i(8),this.#r.setFloat64(this.#n,e,r),this.#a(8)}clear(){this.#s=0,this.#t=[],this.#o()}#o(){let e=new Uint8Array(this.#e.chunkSize);this.#t.push(e),this.#n=0,this.#r=new DataView(e.buffer,e.byteOffset,e.byteLength)}#c(){if(this.#n===0){this.#t.pop();return}let e=this.#t.length-1;this.#t[e]=this.#t[e].subarray(0,this.#n),this.#n=0,this.#r=null}#d(){let e=this.#t.length-1;return this.#t[e].length-this.#n}#i(e){this.#d()<e&&(this.#c(),this.#o())}#a(e){this.#n+=e,this.#s+=e}};var Xe=1n<<15n,me=0b11111n<<10n,_t=1n<<9n,Dt=_t-1n,xt=_t|Dt,et=1n<<31n,ge=0b11111111n<<23n,Mt=1n<<22n,Bt=Mt-1n,Ot=Mt|Bt,xe=1n<<63n,D=0b11111111111n<<52n,ye=1n<<51n,Oe=ye-1n,Nt=ye|Oe,vt=Oe-(Dt<<42n),At=Oe-(Bt<<29n),Ar={2:"0b",8:"0o",16:"0x"},Lt=(t=>(t[t.NATURAL=-2]="NATURAL",t[t.UNKNOWN=-1]="UNKNOWN",t[t.F16=2]="F16",t[t.F32=4]="F32",t[t.F64=8]="F64",t))(Lt||{});function Ut(t,e,r,n){let s="nan'";return t.quiet||(s+="!"),t.sign===-1&&(s+="-"),s+=n(Math.abs(t.payload),r),s+="'",s+=t.encodingIndicator,s}var be=class extends Number{#e;#t=-1;constructor(e,r=!0,n=-1){super(NaN);let s=e;if(typeof e=="number"){if(!Number.isSafeInteger(e))throw new Error(`Invalid NAN payload: ${e}`);e=BigInt(e);let i=0n;if(e<0&&(i=xe,e=-e),e>=ye)throw new Error(`Payload too large: ${s}`);let o=r?ye:0n;switch(this.#e=i|D|o|e,n){case-2:throw new Error("NAN_SIZE.NATURAL only valid for bigint constructor");case-1:n=this.preferredSize;break;case 2:if(this.#e&vt)throw new Error("Invalid size for payload");break;case 4:if(this.#e&At)throw new Error("Invalid size for payload");break;case 8:break;default:throw new Error(`Invalid size: ${n}`)}this.#t=n}else if(typeof e=="bigint"){let i=-1;if((e&D)===D)this.#e=e,i=8;else if((e&ge)===ge){let o=(e&et)<<32n;this.#e=o|D|(e&Ot)<<29n,i=4}else if((e&me)===me){let o=(e&Xe)<<48n;this.#e=o|D|(e&xt)<<42n,i=2}else throw new Error(`Invalid raw NaN value: ${e}`);if(n===-1)this.#t=this.preferredSize;else if(n===-2)this.#t=i;else{if(n<i)throw new Error("Invalid bigint NaN size");this.#t=n}}else{let i=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.length){case 3:{if(e[0]!==249)throw new Error("Invalid CBOR encoding for half float");let o=BigInt(i.getUint16(1,!1));if((o&me)!==me)throw new Error("Not a NaN");let a=(o&Xe)<<48n;this.#e=a|D|(o&xt)<<42n,this.#t=2;break}case 5:{if(e[0]!==250)throw new Error("Invalid CBOR encoding for single float");let o=BigInt(i.getUint32(1,!1));if((o&ge)!==ge)throw new Error("Not a NaN");let a=(o&et)<<32n;this.#e=a|D|(o&Ot)<<29n,this.#t=4;break}case 9:{if(e[0]!==251)throw new Error("Invalid CBOR encoding for double float");if(this.#e=i.getBigUint64(1,!1),(this.#e&D)!==D)throw new Error("Not a NaN (NaNaN)");this.#t=8;break}default:throw new RangeError(`Invalid NAN size (should be 2, 4, or 8): ${e.length-1}`)}}if(!this.payload&&!this.quiet)throw new Error("Signalling NaN with zero payload")}get bytes(){let e=new ArrayBuffer(this.#t+1),r=new DataView(e);switch(this.#t){case 2:{r.setUint8(0,249);let n=(this.#e&xe?Xe:0n)|me|(this.#e&Nt)>>42n;r.setUint16(1,Number(n),!1);break}case 4:{r.setUint8(0,250);let n=(this.#e&xe?et:0n)|ge|(this.#e&Nt)>>29n;r.setUint32(1,Number(n),!1);break}case 8:r.setUint8(0,251),r.setBigUint64(1,this.#e);break}return new Uint8Array(e)}get quiet(){return!!(this.#e&ye)}get sign(){return this.#e&xe?-1:1}get payload(){return Number(this.#e&Oe)*this.sign}get raw(){return this.#e}get encodingIndicator(){switch(this.#t){case 2:return"_1";case 4:return"_2"}return"_3"}get size(){return this.#t}get preferredSize(){return(this.#e&vt)===0n?2:(this.#e&At)===0n?4:8}get isShortestEncoding(){return this.preferredSize===this.#t}toCBOR(e){e.write(this.bytes)}toString(e=10){return Ut(this,1,{},r=>(Ar[e]??"")+r.toString(e))}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return Ut(this,e,r,n)}};function tt(t,e=0,r=!1){let n=t[e]&128?-1:1,s=(t[e]&124)>>2,i=(t[e]&3)<<8|t[e+1];if(s===0){if(r&&i!==0)throw new Error(`Unwanted subnormal: ${n*5960464477539063e-23*i}`);return n*5960464477539063e-23*i}else if(s===31)return i?NaN:n*(1/0);return n*2**(s-25)*(1024+i)}function Ne(t){let e=new DataView(new ArrayBuffer(4));e.setFloat32(0,t,!1);let r=e.getUint32(0,!1);if((r&8191)!==0)return null;let n=r>>16&32768,s=r>>23&255,i=r&8388607;if(!(s===0&&i===0))if(s>=113&&s<=142)n+=(s-112<<10)+(i>>13);else if(s>=103&&s<113){if(i&(1<<126-s)-1)return null;n+=i+8388608>>126-s}else if(s===255)n|=31744,n|=i>>13;else return null;return n}function Pt(t){if(t!==0){let e=new ArrayBuffer(8),r=new DataView(e);r.setFloat64(0,t,!1);let n=r.getBigUint64(0,!1);if((n&0x7ff0000000000000n)===0n)return n&0x8000000000000000n?-0:0}return t}function Ft(t){switch(t.length){case 2:tt(t,0,!0);break;case 4:{let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=e.getUint32(0,!1);if((r&2139095040)===0&&r&8388607)throw new Error(`Unwanted subnormal: ${e.getFloat32(0,!1)}`);break}case 8:{let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=e.getBigUint64(0,!1);if((r&0x7ff0000000000000n)===0n&&r&0x000fffffffffffn)throw new Error(`Unwanted subnormal: ${e.getFloat64(0,!1)}`);break}default:throw new TypeError(`Bad input to isSubnormal: ${t}`)}}var we=class extends TypeError{code="ERR_ENCODING_INVALID_ENCODED_DATA";constructor(){super("The encoded data was not valid for encoding wtf-8")}},ve=class extends RangeError{code="ERR_ENCODING_NOT_SUPPORTED";constructor(e){super(`Invalid encoding: "${e}"`)}};var Ae=new Uint8Array(0);var rt=55296,$t=56320,kt=65533,Ue="wtf-8";function _r(t){return t&&!(t instanceof ArrayBuffer)&&t.buffer instanceof ArrayBuffer}function Dr(t){return t?t instanceof Uint8Array?t:_r(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t):Ae}var Mr=[0,0,0,0,0,0,0,0,-1,-1,-1,-1,1,1,2,3],J=class t{static DEFAULT_BUFFERSIZE=4096;encoding=Ue;fatal;ignoreBOM;bufferSize;#e=0;#t=0;#r=0;#n=!0;#s;constructor(e="wtf8",r=void 0){if(e.toLowerCase().replace("-","")!=="wtf8")throw new ve(e);if(this.fatal=!!r?.fatal,this.ignoreBOM=!!r?.ignoreBOM,this.bufferSize=Math.floor(r?.bufferSize??t.DEFAULT_BUFFERSIZE),isNaN(this.bufferSize)||this.bufferSize<1)throw new RangeError(`Invalid buffer size: ${r?.bufferSize}`);this.#s=new Uint16Array(this.bufferSize)}decode(e,r){let n=!!r?.stream,s=Dr(e),i=[],o=this.#s,a=this.bufferSize-3,d=0,u=()=>{if(this.#t=0,this.#e=0,this.#r=0,this.fatal)throw new we;o[d++]=kt},f=()=>{let g=this.#r;for(let O=0;O<g;O++)u()},m=g=>{if(this.#e===0)switch(Mr[g>>4]){case-1:u();break;case 0:o[d++]=g;break;case 1:this.#t=g&31,(this.#t&30)===0?u():(this.#e=1,this.#r=1);break;case 2:this.#t=g&15,this.#e=2,this.#r=1;break;case 3:g&8?u():(this.#t=g&7,this.#e=3,this.#r=1);break}else{if((g&192)!==128||this.#r===1&&this.#e===2&&this.#t===0&&(g&32)===0||this.#e===3&&this.#t===0&&(g&48)===0)return f(),m(g);if(this.#t=this.#t<<6|g&63,this.#r++,--this.#e===0){if(this.ignoreBOM||!this.#n||this.#t!==65279)if(this.#t<65536)o[d++]=this.#t;else{let O=this.#t-65536;o[d++]=O>>>10&1023|rt,o[d++]=O&1023|$t}this.#t=0,this.#r=0,this.#n=!1}}};for(let g of s)d>=a&&(i.push(String.fromCharCode.apply(null,o.subarray(0,d))),d=0),m(g);return n||(this.#n=!0,(this.#t||this.#e)&&f()),d>0&&i.push(String.fromCharCode.apply(null,o.subarray(0,d))),i.join("")}};function 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 ne=class{encoding=Ue;encode(e){if(!e)return Ae;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:es}=y,jt=c.SIMPLE_FLOAT<<5|l.TWO,Lr=c.SIMPLE_FLOAT<<5|l.FOUR,Pr=c.SIMPLE_FLOAT<<5|l.EIGHT,Fr=c.SIMPLE_FLOAT<<5|v.TRUE,$r=c.SIMPLE_FLOAT<<5|v.FALSE,kr=c.SIMPLE_FLOAT<<5|v.UNDEFINED,jr=c.SIMPLE_FLOAT<<5|v.NULL,qr=new TextEncoder,Gr=new ne,De={...re.defaultOptions,avoidInts:!1,cde:!1,collapseBigInts:!0,dateTag:h.DATE_EPOCH,dcbor:!1,float64:!1,flushToZero:!1,forceEndian:null,ignoreOriginalEncoding:!1,largeNegativeAsBigInt:!1,reduceUnsafeNumbers:!1,rejectBigInts:!1,rejectCustomSimples:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectUndefined:!1,simplifyNegativeZero:!1,sortKeys:null,stringNormalization:null,types:null,wtf8:!1,ignoreGlobalTags:!1},st={cde:!0,ignoreOriginalEncoding:!0,sortKeys:Se},qt={...st,dcbor:!0,largeNegativeAsBigInt:!0,reduceUnsafeNumbers:!0,rejectCustomSimples:!0,rejectDuplicateKeys:!0,rejectUndefined:!0,simplifyNegativeZero:!0,stringNormalization:"NFC"};function Gt(t){let e=t<0;return typeof t=="bigint"?[e?-t-1n:t,e]:[e?-t-1:t,e]}function nt(t,e,r){if(r.rejectFloats)throw new Error(`Attempt to encode an unwanted floating point number: ${t}`);if(isNaN(t))e.writeUint8(jt),e.writeUint16(32256);else if(!r.float64&&Math.fround(t)===t){let n=Ne(t);n===null?(e.writeUint8(Lr),e.writeFloat32(t)):(e.writeUint8(jt),e.writeUint16(n))}else e.writeUint8(Pr),e.writeFloat64(t)}function R(t,e,r){let[n,s]=Gt(t);if(s&&r)throw new TypeError(`Negative size: ${t}`);r??=s?c.NEG_INT:c.POS_INT,r<<=5,n<24?e.writeUint8(r|n):n<=255?(e.writeUint8(r|l.ONE),e.writeUint8(n)):n<=65535?(e.writeUint8(r|l.TWO),e.writeUint16(n)):n<=4294967295?(e.writeUint8(r|l.FOUR),e.writeUint32(n)):(e.writeUint8(r|l.EIGHT),e.writeBigUint64(BigInt(n)))}function se(t,e,r){typeof t=="number"?R(t,e,c.TAG):typeof t=="object"&&!r.ignoreOriginalEncoding&&y.ENCODED in t?e.write(t[y.ENCODED]):t<=Number.MAX_SAFE_INTEGER?R(Number(t),e,c.TAG):(e.writeUint8(c.TAG<<5|l.EIGHT),e.writeBigUint64(BigInt(t)))}function Ct(t,e,r){let[n,s]=Gt(t);if(r.collapseBigInts&&(!r.largeNegativeAsBigInt||t>=-0x8000000000000000n)){if(n<=0xffffffffn){R(Number(t),e);return}if(n<=0xffffffffffffffffn){let u=(s?c.NEG_INT:c.POS_INT)<<5;e.writeUint8(u|l.EIGHT),e.writeBigUint64(n);return}}if(r.rejectBigInts)throw new Error(`Attempt to encode unwanted bigint: ${t}`);let i=s?h.NEG_BIGINT:h.POS_BIGINT,o=n.toString(16),a=o.length%2?"0":"";se(i,e,r);let d=Ie(a+o);R(d.length,e,c.BYTE_STRING),e.write(d)}function Cr(t,e,r){r.flushToZero&&(t=Pt(t)),Object.is(t,-0)?r.simplifyNegativeZero?r.avoidInts?nt(0,e,r):R(0,e):nt(t,e,r):!r.avoidInts&&Number.isSafeInteger(t)?R(t,e):r.reduceUnsafeNumbers&&Math.floor(t)===t&&t>=te.MIN&&t<=te.MAX?Ct(BigInt(t),e,r):nt(t,e,r)}function Hr(t,e,r){let n=r.stringNormalization?t.normalize(r.stringNormalization):t;if(r.wtf8&&!t.isWellFormed()){let s=Gr.encode(n);se(h.WTF8,e,r),R(s.length,e,c.BYTE_STRING),e.write(s)}else{let s=qr.encode(n);R(s.length,e,c.UTF8_STRING),e.write(s)}}function Vr(t,e,r){let n=t;Me(n,n.length,c.ARRAY,e,r);for(let s of n)H(s,e,r)}function zr(t,e){R(t.length,e,c.BYTE_STRING),e.write(t)}var _e=new he;_e.registerEncoder(Array,Vr),_e.registerEncoder(Uint8Array,zr);function b(t,e){return _e.registerEncoder(t,e)}function Me(t,e,r,n,s){let i=Et(t);i&&!s.ignoreOriginalEncoding?n.write(i):R(e,n,r)}function Qr(t,e,r){if(t===null){e.writeUint8(jr);return}if(!r.ignoreOriginalEncoding&&y.ENCODED in t){e.write(t[y.ENCODED]);return}let n=t.constructor;if(n){let i=r.types?.get(n)??(r.ignoreGlobalTags?void 0:_e.get(n));if(i){let o=i(t,e,r);if(o!==void 0){if(!Array.isArray(o)||o.length!==2)throw new Error("Invalid encoder return value");(typeof o[0]=="bigint"||isFinite(Number(o[0])))&&se(o[0],e,r),H(o[1],e,r)}return}}if(typeof t.toCBOR=="function"){let i=t.toCBOR(e,r);i&&((typeof i[0]=="bigint"||isFinite(Number(i[0])))&&se(i[0],e,r),H(i[1],e,r));return}if(typeof t.toJSON=="function"){H(t.toJSON(),e,r);return}let s=Object.entries(t).map(i=>[i[0],i[1],A(i[0],r)]);r.sortKeys&&s.sort(r.sortKeys),Me(t,s.length,c.MAP,e,r);for(let[i,o,a]of s)e.write(a),H(o,e,r)}function H(t,e,r){switch(typeof t){case"number":Cr(t,e,r);break;case"bigint":Ct(t,e,r);break;case"string":Hr(t,e,r);break;case"boolean":e.writeUint8(t?Fr:$r);break;case"undefined":if(r.rejectUndefined)throw new Error("Attempt to encode unwanted undefined.");e.writeUint8(kr);break;case"object":Qr(t,e,r);break;case"symbol":throw new TypeError(`Unknown symbol: ${t.toString()}`);default:throw new TypeError(`Unknown type: ${typeof t}, ${String(t)}`)}}function A(t,e={}){let r={...De};e.dcbor?Object.assign(r,qt):e.cde&&Object.assign(r,st),Object.assign(r,e);let n=new re(r);return H(t,n,r),n.read()}var Z=(t=>(t[t.NEVER=-1]="NEVER",t[t.PREFERRED=0]="PREFERRED",t[t.ALWAYS=1]="ALWAYS",t))(Z||{});var x=class t{static KnownSimple=new Map([[v.FALSE,!1],[v.TRUE,!0],[v.NULL,null],[v.UNDEFINED,void 0]]);value;constructor(e){this.value=e}static create(e){return t.KnownSimple.has(e)?t.KnownSimple.get(e):new t(e)}toCBOR(e,r){if(r.rejectCustomSimples)throw new Error(`Cannot encode non-standard Simple value: ${this.value}`);R(this.value,e,c.SIMPLE_FLOAT)}toString(){return`simple(${this.value})`}decode(){return t.KnownSimple.has(this.value)?t.KnownSimple.get(this.value):this}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return`simple(${n(this.value,r)})`}};var Kr=new TextDecoder("utf8",{fatal:!0,ignoreBOM:!0}),U=class t{static defaultOptions={maxDepth:1024,encoding:"hex",requirePreferred:!1};#e;#t;#r=0;#n;constructor(e,r){if(this.#n={...t.defaultOptions,...r},typeof e=="string")switch(this.#n.encoding){case"hex":this.#e=Ie(e);break;case"base64":this.#e=le(e);break;default:throw new TypeError(`Encoding not implemented: "${this.#n.encoding}"`)}else this.#e=e;this.#t=new DataView(this.#e.buffer,this.#e.byteOffset,this.#e.byteLength)}toHere(e){return pe(this.#e,e,this.#r)}*[Symbol.iterator](){if(yield*this.#s(0),this.#r!==this.#e.length)throw new Error("Extra data in input")}*seq(){for(;this.#r<this.#e.length;)yield*this.#s(0)}*#s(e){if(e++>this.#n.maxDepth)throw new Error(`Maximum depth ${this.#n.maxDepth} exceeded`);let r=this.#r,n=this.#t.getUint8(this.#r++),s=n>>5,i=n&31,o=i,a=!1,d=0;switch(i){case l.ONE:if(d=1,o=this.#t.getUint8(this.#r),s===c.SIMPLE_FLOAT){if(o<32)throw new Error(`Invalid simple encoding in extra byte: ${o}`);a=!0}else if(this.#n.requirePreferred&&o<24)throw new Error(`Unexpectedly long integer encoding (1) for ${o}`);break;case l.TWO:if(d=2,s===c.SIMPLE_FLOAT)o=tt(this.#e,this.#r);else if(o=this.#t.getUint16(this.#r,!1),this.#n.requirePreferred&&o<=255)throw new Error(`Unexpectedly long integer encoding (2) for ${o}`);break;case l.FOUR:if(d=4,s===c.SIMPLE_FLOAT)o=this.#t.getFloat32(this.#r,!1);else if(o=this.#t.getUint32(this.#r,!1),this.#n.requirePreferred&&o<=65535)throw new Error(`Unexpectedly long integer encoding (4) for ${o}`);break;case l.EIGHT:{if(d=8,s===c.SIMPLE_FLOAT)o=this.#t.getFloat64(this.#r,!1);else if(o=this.#t.getBigUint64(this.#r,!1),o<=Number.MAX_SAFE_INTEGER&&(o=Number(o)),this.#n.requirePreferred&&o<=4294967295)throw new Error(`Unexpectedly long integer encoding (8) for ${o}`);break}case 28:case 29:case 30:throw new Error(`Additional info not implemented: ${i}`);case l.INDEFINITE:switch(s){case c.POS_INT:case c.NEG_INT:case c.TAG:throw new Error(`Invalid indefinite encoding for MT ${s}`);case c.SIMPLE_FLOAT:yield[s,i,y.BREAK,r,0];return}o=1/0;break;default:a=!0}switch(this.#r+=d,s){case c.POS_INT:yield[s,i,o,r,d];break;case c.NEG_INT:yield[s,i,typeof o=="bigint"?-1n-o:-1-Number(o),r,d];break;case c.BYTE_STRING:o===1/0?yield*this.#c(s,e,r):yield[s,i,this.#o(o),r,o];break;case c.UTF8_STRING:o===1/0?yield*this.#c(s,e,r):yield[s,i,Kr.decode(this.#o(o)),r,o];break;case c.ARRAY:if(o===1/0)yield*this.#c(s,e,r,!1);else{let u=Number(o);yield[s,i,u,r,d];for(let f=0;f<u;f++)yield*this.#s(e+1)}break;case c.MAP:if(o===1/0)yield*this.#c(s,e,r,!1);else{let u=Number(o);yield[s,i,u,r,d];for(let f=0;f<u;f++)yield*this.#s(e),yield*this.#s(e)}break;case c.TAG:yield[s,i,o,r,d],yield*this.#s(e);break;case c.SIMPLE_FLOAT:{let u=o;a&&(o=x.create(Number(o))),yield[s,i,o,r,u];break}}}#o(e){let r=pe(this.#e,this.#r,this.#r+=e);if(r.length!==e)throw new Error(`Unexpected end of stream reading ${e} bytes, got ${r.length}`);return r}*#c(e,r,n,s=!0){for(yield[e,l.INDEFINITE,1/0,n,1/0];;){let i=this.#s(r),o=i.next(),[a,d,u]=o.value;if(u===y.BREAK){yield o.value,i.next();return}if(s){if(a!==e)throw new Error(`Unmatched major type. Expected ${e}, got ${a}.`);if(d===l.INDEFINITE)throw new Error("New stream started in typed stream")}yield o.value,yield*i}}};var Yr=new Map([[l.ZERO,1],[l.ONE,2],[l.TWO,3],[l.FOUR,5],[l.EIGHT,9]]),Wr=new Uint8Array(0);function Jr(t,e){return!e.boxed&&!e.preferMap&&t.every(([r])=>typeof r=="string")?Object.fromEntries(t):new Map(t)}var w=class t{static defaultDecodeOptions={...U.defaultOptions,ParentType:t,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:Z.PREFERRED,collapseBigInts:!1,convertUnsafeIntsToFloat:!1,createObject:Jr,keepNanPayloads:!1,pretty:!1,preferBigInt:!1,preferMap:!1,rejectLargeNegatives:!1,rejectBigInts:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectInts:!1,rejectLongLoundNaN:!1,rejectLongFloats:!1,rejectNegativeZero:!1,rejectSimple:!1,rejectStreaming:!1,rejectStringsNotNormalizedAs:null,rejectSubnormals:!1,rejectUndefined:!1,rejectUnsafeFloatInts:!1,saveOriginal:!1,sortKeys:null,tags:null,ignoreGlobalTags:!1};static cdeDecodeOptions={cde:!0,rejectStreaming:!0,requirePreferred:!0,sortKeys:Se};static dcborDecodeOptions={...this.cdeDecodeOptions,dcbor:!0,convertUnsafeIntsToFloat:!0,rejectDuplicateKeys:!0,rejectLargeNegatives:!0,rejectLongLoundNaN:!0,rejectLongFloats:!0,rejectNegativeZero:!0,rejectSimple:!0,rejectUndefined:!0,rejectUnsafeFloatInts:!0,rejectStringsNotNormalizedAs:"NFC"};parent;mt;ai;left;offset;count=0;children=[];depth=0;#e;#t=null;constructor(e,r,n,s){if([this.mt,this.ai,,this.offset]=e,this.left=r,this.parent=n,this.#e=s,n&&(this.depth=n.depth+1),this.mt===c.MAP&&(this.#e.sortKeys||this.#e.rejectDuplicateKeys)&&(this.#t=[]),this.#e.rejectStreaming&&this.ai===l.INDEFINITE)throw new Error("Streaming not supported")}get isStreaming(){return this.left===1/0}get done(){return this.left===0}static create(e,r,n,s){let[i,o,a,d]=e;switch(i){case c.POS_INT:case c.NEG_INT:{if(n.rejectInts)throw new Error(`Unexpected integer: ${a}`);if(n.rejectLargeNegatives&&a<-0x8000000000000000n)throw new Error(`Invalid 65bit negative number: ${a}`);let u=a;return n.preferBigInt?u=BigInt(u):n.convertUnsafeIntsToFloat&&u>=te.MIN&&u<=te.MAX&&(u=Number(a)),n.boxed?C(u,s.toHere(d)):u}case c.SIMPLE_FLOAT:if(o>l.ONE){if(typeof a=="symbol")return a;if(n.rejectFloats)throw new Error(`Decoding unwanted floating point number: ${a}`);if(n.rejectNegativeZero&&Object.is(a,-0))throw new Error("Decoding negative zero");if(isNaN(a)){let u=s.toHere(d),f=new be(u);if(n.rejectLongLoundNaN){if(f.payload||u.length>3)throw new Error(`Invalid NaN encoding: "${E(u)}"`)}else if(n.keepNanPayloads&&(f.payload||f.sign===-1)){if(n.rejectLongFloats&&!f.isShortestEncoding)throw new Error(`NaN should have been encoded shorter: ${a}`);return f}}if(n.rejectSubnormals&&Ft(s.toHere(d+1)),n.rejectLongFloats){let u=A(a,{chunkSize:9,reduceUnsafeNumbers:n.rejectUnsafeFloatInts});if(u[0]>>5!==i)throw new Error(`Should have been encoded as int, not float: ${a}`);if(u.length<Yr.get(o))throw new Error(`Number should have been encoded shorter: ${a}`)}if(typeof a=="number"&&n.boxed)return C(a,s.toHere(d))}else{if(n.rejectSimple&&a instanceof x)throw new Error(`Invalid simple value: ${a}`);if(n.rejectUndefined&&a===void 0)throw new Error("Unexpected undefined")}return a;case c.BYTE_STRING:case c.UTF8_STRING:if(a===1/0)return new n.ParentType(e,1/0,r,n);if(n.rejectStringsNotNormalizedAs&&typeof a=="string"){let u=a.normalize(n.rejectStringsNotNormalizedAs);if(a!==u)throw new Error(`String not normalized as "${n.rejectStringsNotNormalizedAs}", got [${Ze(a)}] instead of [${Ze(u)}]`)}return n.boxed?C(a,s.toHere(d)):a;case c.ARRAY:return new n.ParentType(e,a,r,n);case c.MAP:return new n.ParentType(e,a*2,r,n);case c.TAG:{let u=new n.ParentType(e,1,r,n);return u.children=new p(a),u}}throw new TypeError(`Invalid major type: ${i}`)}static decodeToEncodeOpts(e){return{...De,avoidInts:e.rejectInts,float64:!e.rejectLongFloats,flushToZero:e.rejectSubnormals,largeNegativeAsBigInt:e.rejectLargeNegatives,sortKeys:e.sortKeys}}push(e,r,n){if(this.children.push(e),this.#t){let s=q(e)||r.toHere(n);this.#t.push(s)}return--this.left}replaceLast(e,r,n){let s,i=-1/0;if(this.children instanceof p?(i=0,s=this.children.contents,this.children.contents=e):(i=this.children.length-1,s=this.children[i],this.children[i]=e),this.#t){let o=q(e)||n.toHere(r.offset);this.#t[i]=o}return s}convert(e){let r;switch(this.mt){case c.ARRAY:r=this.children;break;case c.MAP:{let n=this.#r();if(this.#e.sortKeys){let s;for(let i of n){if(s&&this.#e.sortKeys(s,i)>=0)throw new Error(`Duplicate or out of order key: "0x${i[2]}"`);s=i}}else if(this.#e.rejectDuplicateKeys){let s=new Set;for(let[i,o,a]of n){let d=E(a);if(s.has(d))throw new Error(`Duplicate key: "0x${d}"`);s.add(d)}}r=this.#e.createObject(n,this.#e);break}case c.BYTE_STRING:return Rt(this.children);case c.UTF8_STRING:{let n=this.children.join("");r=this.#e.boxed?C(n,e.toHere(this.offset)):n;break}case c.TAG:r=this.children.decode(this.#e);break;default:throw new TypeError(`Invalid mt on convert: ${this.mt}`)}return this.#e.saveOriginal&&r&&typeof r=="object"&&G(r,e.toHere(this.offset)),r}#r(){let e=this.children,r=e.length;if(r%2)throw new Error("Missing map value");let n=new Array(r/2);if(this.#t)for(let s=0;s<r;s+=2)n[s>>1]=[e[s],e[s+1],this.#t[s]];else for(let s=0;s<r;s+=2)n[s>>1]=[e[s],e[s+1],Wr];return n}};var ot=" ",Zr=new TextEncoder,Be=class extends w{close="";quote='"';get isEmptyStream(){return(this.mt===c.UTF8_STRING||this.mt===c.BYTE_STRING)&&this.count===0}};function V(t,e,r,n){let s="";if(e===l.INDEFINITE)s+="_";else{if(n.diagnosticSizes===Z.NEVER)return"";{let i=n.diagnosticSizes===Z.ALWAYS;if(!i){let o=l.ZERO;if(Object.is(r,-0))o=l.TWO;else if(t===c.POS_INT||t===c.NEG_INT){let a=r<0,d=typeof r=="bigint"?1n:1,u=a?-r-d:r;u<=23?o=Number(u):u<=255?o=l.ONE:u<=65535?o=l.TWO:u<=4294967295?o=l.FOUR:o=l.EIGHT}else isFinite(r)?Math.fround(r)===r?Ne(r)==null?o=l.FOUR:o=l.TWO:o=l.EIGHT:o=l.TWO;i=o!==e}i&&(s+="_",e<l.ONE?s+="i":s+=String(e-24))}}return s}function it(t,e){let r={...w.defaultDecodeOptions,...e,ParentType:Be},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+=V(d,u,f,r);break;case c.SIMPLE_FLOAT:if(f!==y.BREAK)if(typeof f=="number"){let m=Object.is(f,-0)?"-0.0":String(f);o+=m,isFinite(f)&&!/[.e]/.test(m)&&(o+=".0"),o+=V(d,u,f,r)}else f instanceof x?(o+="simple(",o+=String(f.value),o+=V(c.POS_INT,u,f.value,r),o+=")"):o+=String(f);break;case c.BYTE_STRING:f===1/0?(o+="(_ ",i.close=")",i.quote="'"):(o+="h'",o+=E(f),o+="'",o+=V(c.POS_INT,u,f.length,r));break;case c.UTF8_STRING:f===1/0?(o+="(_ ",i.close=")"):(o+=JSON.stringify(f),o+=V(c.POS_INT,u,Zr.encode(f).length,r));break;case c.ARRAY:{o+="[";let m=V(c.POS_INT,u,f,r);o+=m,m&&(o+=" "),r.pretty&&f?i.close=`
|
|
3
|
+
${ot.repeat(i.depth)}]`:i.close="]";break}case c.MAP:{o+="{";let m=V(c.POS_INT,u,f,r);o+=m,m&&(o+=" "),r.pretty&&f?i.close=`
|
|
4
|
+
${ot.repeat(i.depth)}}`:i.close="}";break}case c.TAG:o+=String(f),o+=V(c.POS_INT,u,f,r),o+="(",i.close=")";break}if(i===y.BREAK)if(s?.isStreaming)s.left=0;else throw new Error("Unexpected BREAK");else s&&(s.count++,s.left--);for(i instanceof Be&&(s=i);s?.done;){if(s.isEmptyStream)o=o.slice(0,-3),o+=`${s.quote}${s.quote}_`;else{if(s.mt===c.MAP&&s.count%2!==0)throw new Error(`Odd streaming map size: ${s.count}`);o+=s.close}s=s.parent}}return o}var Xr=new TextDecoder,Te=class extends w{depth=0;leaf=!1;value;length;[y.ENCODED];constructor(e,r,n,s){super(e,r,n,s),this.parent?this.depth=this.parent.depth+1:this.depth=s.initialDepth,[,,this.value,,this.length]=e}numBytes(){switch(this.ai){case l.ONE:return 1;case l.TWO:return 2;case l.FOUR:return 4;case l.EIGHT:return 8}return 0}};function Ht(t){return t instanceof Te}function Le(t,e){return t===1/0?"Indefinite":e?`${t} ${e}${t!==1&&t!==1n?"s":""}`:String(t)}function Ee(t){return"".padStart(t," ")}function Vt(t,e,r){let n="";n+=Ee(t.depth*2);let s=q(t);n+=E(s.subarray(0,1));let i=t.numBytes();i&&(n+=" ",n+=E(s.subarray(1,i+1))),n=n.padEnd(e.minCol+1," "),n+="-- ",r!==void 0&&(n+=Ee(t.depth*2),r!==""&&(n+=`[${r}] `));let o=!1,[a]=t.children;switch(t.mt){case c.POS_INT:n+=`Unsigned: ${a}`,typeof a=="bigint"&&(n+="n");break;case c.NEG_INT:n+=`Negative: ${a}`,typeof a=="bigint"&&(n+="n");break;case c.BYTE_STRING:n+=`Bytes (Length: ${Le(t.length)})`;break;case c.UTF8_STRING:n+=`UTF8 (Length: ${Le(t.length)})`,t.length!==1/0&&(n+=`: ${JSON.stringify(a)}`);break;case c.ARRAY:n+=`Array (Length: ${Le(t.value,"item")})`;break;case c.MAP:n+=`Map (Length: ${Le(t.value,"pair")})`;break;case c.TAG:{n+=`Tag #${t.value}`;let d=t.children,[u]=d.contents.children,f=new p(d.tag,u);G(f,s);let m=f.comment(e,t.depth);m&&(n+=": ",n+=m),o||=f.noChildren;break}case c.SIMPLE_FLOAT:a===y.BREAK?n+="BREAK":t.ai>l.ONE?Object.is(a,-0)?n+="Float: -0":n+=`Float: ${a}`:(n+="Simple: ",a instanceof x?n+=a.value:n+=a);break}if(!o)if(t.leaf){if(n+=`
|
|
5
|
+
`,s.length>i+1){let d=Ee((t.depth+1)*2),u=fe(s);if(u?.length){u.sort((m,g)=>m[0]-g[0]||g[1]-m[1]);let f=0;for(let[m,g,O]of u)if(!(m<f)){if(f=m+g,O==="<<"){n+=Ee(e.minCol+1),n+="--",n+=d,n+="<< ";let L=pe(s,m,m+g),ae=fe(L);if(ae){let gt=ae.findIndex(([fr,pr,lr])=>fr===0&&pr===g&&lr==="<<");gt>=0&&ae.splice(gt,1)}n+=it(L),n+=` >>
|
|
6
|
+
`,n+=Pe(L,{initialDepth:t.depth+1,minCol:e.minCol,noPrefixHex:!0});continue}else O==="'"&&(n+=Ee(e.minCol+1),n+="--",n+=d,n+="'",n+=Xr.decode(s.subarray(m,m+g)),n+=`'
|
|
7
|
+
`);if(m>i)for(let L=m;L<m+g;L+=8){let ae=Math.min(L+8,m+g);n+=d,n+=E(s.subarray(L,ae)),n+=`
|
|
8
8
|
`}}}else for(let f=i+1;f<s.length;f+=8)n+=d,n+=E(s.subarray(f,f+8)),n+=`
|
|
9
9
|
`}}else{n+=`
|
|
10
|
-
`;let d=0;for(let u of t.children){if(
|
|
11
|
-
`;return o+=
|
|
10
|
+
`;let d=0;for(let u of t.children){if(Ht(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+=Vt(u,e,f)}d++}}return n}var en={...w.defaultDecodeOptions,initialDepth:0,noPrefixHex:!1,minCol:0};function Pe(t,e){let r={...en,...e,ParentType:Te,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(!Ht(i)){let f=new Te(a,0,s,r);f.leaf=!0,f.children.push(i),G(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||G(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+=Vt(i,r),o}var zt=!St();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 Q(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 M(t){if(!(t instanceof Uint8Array))throw new Error(`Expected Uint8Array: ${t}`)}function Zt(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),Me(t,t.size,c.MAP,e,r);for(let[s,i,o]of n)e.write(o),H(i,e,r)});function at(t){return Q(t.contents),new Date(t.contents)}at.comment=t=>{Q(t.contents);let e=new Date(t.contents);return`(String ${t.tag===h.DATE_FULL?"Full ":""}Date) ${e.toISOString()}`},p.registerDecoder(h.DATE_STRING,at),p.registerDecoder(h.DATE_FULL,at);function Qt(t){return ke(t.contents),new Date(t.contents*1e3)}Qt.comment=t=>(ke(t.contents),`(Epoch Date) ${new Date(t.contents*1e3).toISOString()}`),p.registerDecoder(h.DATE_EPOCH,Qt);var ut=1e3*60*60*24;function Kt(t){return ke(t.contents),new Date(t.contents*ut)}Kt.comment=t=>(ke(t.contents),`(Epoch Date) ${new Date(t.contents*ut).toISOString()}`),p.registerDecoder(h.DATE_EPOCH_DAYS,Kt),b(Date,(t,e,r)=>{switch(r.dateTag){case h.DATE_EPOCH:return[r.dateTag,t.valueOf()/1e3];case h.DATE_STRING:return[r.dateTag,t.toISOString().replace(/\.000Z$/,"Z")];case h.DATE_EPOCH_DAYS:return[r.dateTag,Math.floor(t.valueOf()/ut)];case h.DATE_FULL:return[r.dateTag,t.toISOString().split("T")[0]];default:throw new Error(`Unsupported date tag: ${r.dateTag}`)}});function $e(t,e,r){if(M(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?C(n,e.contents):n}var Yt=$e.bind(null,!1),Wt=$e.bind(null,!0);Yt.comment=(t,e)=>`(Positive BigInt) ${$e(!1,t,e)}n`,Wt.comment=(t,e)=>`(Negative BigInt) ${$e(!0,t,e)}n`,p.registerDecoder(h.POS_BIGINT,Yt),p.registerDecoder(h.NEG_BIGINT,Wt);function ct(t,e){return M(t.contents),t}ct.comment=(t,e,r)=>{M(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=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=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},it.noChildren=!0,p.registerDecoder(l.CBOR,it),p.registerDecoder(l.URI,t=>(V(t.contents),new URL(t.contents)),"URI"),b(URL,t=>[l.URI,t.toString()]),p.registerDecoder(l.BASE64URL,t=>(V(t.contents),Et(t.contents)),"Base64url-encoded"),p.registerDecoder(l.BASE64,t=>(V(t.contents),ue(t.contents)),"Base64-encoded"),p.registerDecoder(35,t=>(V(t.contents),new RegExp(t.contents)),"RegExp"),p.registerDecoder(21065,t=>{V(t.contents);let e=`^(?:${t.contents})$`;return new RegExp(e,"u")},"I-RegExp"),p.registerDecoder(l.REGEXP,t=>{if(Yt(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=>(M(t.contents),t.contents),"uint8 Typed Array");function T(t,e,r){M(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 z(t,e,r,n,s){let i=s.forceEndian??Ct;if(ne(i?e:r,t,s),R(n.byteLength,t,c.BYTE_STRING),Ct===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=>(M(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)=>z(e,69,65,t,r)),p.registerDecoder(70,t=>T(t,Uint32Array,!0),"uint32, little endian, Typed Array"),b(Uint32Array,(t,e,r)=>z(e,70,66,t,r)),p.registerDecoder(71,t=>T(t,BigUint64Array,!0),"uint64, little endian, Typed Array"),b(BigUint64Array,(t,e,r)=>z(e,71,67,t,r)),p.registerDecoder(72,t=>(M(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)=>z(e,77,73,t,r)),p.registerDecoder(78,t=>T(t,Int32Array,!0),"sint32, little endian, Typed Array"),b(Int32Array,(t,e,r)=>z(e,78,74,t,r)),p.registerDecoder(79,t=>T(t,BigInt64Array,!0),"sint64, little endian, Typed Array"),b(BigInt64Array,(t,e,r)=>z(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)=>z(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)=>z(e,86,82,t,r)),p.registerDecoder(l.SET,(t,e)=>{if(Yt(t.contents),e.sortKeys){let r=w.decodeToEncodeOpts(e),n=null;for(let s of t.contents){let i=[s,void 0,v(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,v(i,r)]);s.sort(r.sortKeys),n=s.map(([i])=>i)}return[l.SET,n]}),p.registerDecoder(l.JSON,t=>(V(t.contents),JSON.parse(t.contents)),"JSON-encoded");function Kt(t){return M(t.contents),new Y().decode(t.contents)}Kt.comment=t=>{M(t.contents);let e=new Y;return`(WTF8 string): ${JSON.stringify(e.decode(t.contents))}`},p.registerDecoder(l.WTF8,Kt),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 at(t){throw new Error(`Encoding ${t.constructor.name} intentionally unimplmented. It is not concrete enough to interoperate. Convert to Uint8Array first.`)}b(ArrayBuffer,at),b(DataView,at),typeof SharedArrayBuffer<"u"&&b(SharedArrayBuffer,at);function Fe(t){return[NaN,t.valueOf()]}b(Boolean,Fe),b(Number,Fe),b(String,Fe),b(BigInt,Fe);function en(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 dt=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 ut(t,e={}){let r=en(e),n=new U(t,r),s=new dt;for(let i of n)s.step(i,r,n);return s.ret}var{cdeDecodeOptions:lo,dcborDecodeOptions:mo,defaultDecodeOptions:go}=w;var J={encode:t=>v(t),decode:t=>ut(t)};var Wt=19*1024,Jt=2,Zt=1,Xt=32,er={deriveKey:(t,e)=>P.host.deriveKey(t,e),aesGcmEncrypt:t=>{let e=J.encode(t);return P.host.aesGcmEncrypt(e)},aesGcmDecrypt:t=>{let e=P.host.aesGcmDecrypt(t);return J.decode(e)},argon2Hash:(t,e,r)=>P.host.argon2Hash({tag:t},new TextEncoder().encode(e),r?.mCost??Wt,r?.tCost??Jt,r?.pCost??Zt,r?.outputLen??Xt),argon2Verify:(t,e,r,n)=>P.host.argon2Verify({tag:t},new TextEncoder().encode(e),new TextEncoder().encode(r),n?.mCost??Wt,n?.tCost??Jt,n?.pCost??Zt,n?.outputLen??Xt)};var _=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 we=class extends _{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))}},je=class{_query;constructor(e,r){this._query=new we(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 qe=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)}}},Ge=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 Ce=class t extends _{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 _{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 _{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 _{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 tr={entity:t=>new ft(t)},ft=class{constructor(e){this.name=e}find(e){return new we(this,e)}findOne(e){return new je(this,e)}insert(e){return new qe(this,e,"insertedIds")}insertOne(e){return new Ge(this,e,"insertedId")}update(e,r){return new Ce(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 rr={publish:async(t,e,r)=>{let n=J.encode(e);return r=r??["public"],await X.host.publish(t,n,r.map(s=>({tag:s})))}};var nr={get:async t=>{let e=await K.host.get(t);return JSON.parse(e)},getDel:async t=>{let e=await K.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 K.host.set(t,JSON.stringify(e),n)},delete:async t=>await K.host.delete(t)};var sr={call:async(t,e)=>{let r=k.fromRequest(new Request(t,e)),n=await k.host.call(r);return k.toResponse(n)}};var or={push:async(t,e)=>{let r=J.encode(t);return await Ee.host.push(r,e)}};var ht=new Re(rn),se=(t,e)=>Object.defineProperty(globalThis,t,{value:Object.freeze(e),enumerable:!1,configurable:!1,writable:!1});se("$crypto",er);se("$db",tr);se("$event",rr);se("$kv",nr);se("$rpc",sr);se("$sse",or);var ni={};var si=Z.guest;var oi=X.guest;var ii=k.guest;export{ht as app,ni as guest,si as"m1cro:common/guest",oi as"m1cro:pub-sub/guest",ii as"m1cro:rpc/guest"};
|
|
13
|
+
`,u+=d,u},ct.noChildren=!0,p.registerDecoder(h.CBOR,ct),p.registerDecoder(h.URI,t=>(Q(t.contents),new URL(t.contents)),"URI"),b(URL,t=>[h.URI,t.toString()]),p.registerDecoder(h.BASE64URL,t=>(Q(t.contents),It(t.contents)),"Base64url-encoded"),p.registerDecoder(h.BASE64,t=>(Q(t.contents),le(t.contents)),"Base64-encoded"),p.registerDecoder(35,t=>(Q(t.contents),new RegExp(t.contents)),"RegExp"),p.registerDecoder(21065,t=>{Q(t.contents);let e=`^(?:${t.contents})$`;return new RegExp(e,"u")},"I-RegExp"),p.registerDecoder(h.REGEXP,t=>{if(Zt(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=>[h.REGEXP,[t.source,t.flags]]),p.registerDecoder(64,t=>(M(t.contents),t.contents),"uint8 Typed Array");function T(t,e,r){M(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 z(t,e,r,n,s){let i=s.forceEndian??zt;if(se(i?e:r,t,s),R(n.byteLength,t,c.BYTE_STRING),zt===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=>(M(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)=>z(e,69,65,t,r)),p.registerDecoder(70,t=>T(t,Uint32Array,!0),"uint32, little endian, Typed Array"),b(Uint32Array,(t,e,r)=>z(e,70,66,t,r)),p.registerDecoder(71,t=>T(t,BigUint64Array,!0),"uint64, little endian, Typed Array"),b(BigUint64Array,(t,e,r)=>z(e,71,67,t,r)),p.registerDecoder(72,t=>(M(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)=>z(e,77,73,t,r)),p.registerDecoder(78,t=>T(t,Int32Array,!0),"sint32, little endian, Typed Array"),b(Int32Array,(t,e,r)=>z(e,78,74,t,r)),p.registerDecoder(79,t=>T(t,BigInt64Array,!0),"sint64, little endian, Typed Array"),b(BigInt64Array,(t,e,r)=>z(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)=>z(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)=>z(e,86,82,t,r)),p.registerDecoder(h.SET,(t,e)=>{if(Zt(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 #${h.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[h.SET,n]}),p.registerDecoder(h.JSON,t=>(Q(t.contents),JSON.parse(t.contents)),"JSON-encoded");function Jt(t){return M(t.contents),new J().decode(t.contents)}Jt.comment=t=>{M(t.contents);let e=new J;return`(WTF8 string): ${JSON.stringify(e.decode(t.contents))}`},p.registerDecoder(h.WTF8,Jt),p.registerDecoder(h.SELF_DESCRIBED,t=>t.contents,"Self-Described"),p.registerDecoder(h.INVALID_16,()=>{throw new Error(`Tag always invalid: ${h.INVALID_16}`)},"Invalid"),p.registerDecoder(h.INVALID_32,()=>{throw new Error(`Tag always invalid: ${h.INVALID_32}`)},"Invalid"),p.registerDecoder(h.INVALID_64,()=>{throw new Error(`Tag always invalid: ${h.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 Fe(t){return[NaN,t.valueOf()]}b(Boolean,Fe),b(Number,Fe),b(String,Fe),b(BigInt,Fe);function tn(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=tn(e),n=new U(t,r),s=new ft;for(let i of n)s.step(i,r,n);return s.ret}var{cdeDecodeOptions:yo,dcborDecodeOptions:bo,defaultDecodeOptions:wo}=w;var B={encode:t=>A(t),decode:t=>pt(t)};import*as Xt from"m1cro:pub-sub/host";var nn={publish:async(t,e,r)=>await Xt.publish(t,e,r)},sn={invokeEventHandler:async(t,e,r)=>{let n=Y.events[t]?.handler;if(!n)throw new Error(`Event handler not found for index ${t}`);let s=B.decode(r),i=Y.context();await n(e,s,i)}};var je={};K(je,{host:()=>on});import*as er from"m1cro:sse/host";var on={push:async(t,e)=>await er.push(t,e)};var lt=class{#e=[];add(e){this.#e.push(e)}get get(){return this.#e}},qe=class t{#e;#t;constructor(e=new lt,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 Ge=class{roles;capabilities;router;entities;events;constructor(e){let r=new ht;e(r),this.roles=r._roles,this.capabilities=r._capabilities,this.router=r._router,this.entities=r._entities,this.events=r._events}context(){return new ee}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}))}}},ht=class{_roles=[];_capabilities={};_router=new qe;_entities=[];_events=[];on(){return this}role(e){return this._roles.push(e),this}capability(e,r){return this._capabilities[e]||=new Set,r.forEach(n=>this._capabilities[e].add(n)),this}capabilities(e){return Object.entries(e).forEach(([r,n])=>this.capability(r,n)),this}routes(e){return e(this._router),this}entity(e,r){let n={name:e,schema:new TextEncoder().encode(JSON.stringify(r)),indexes:[],scoped:!1};return this._entities.push(n),this}event(e,r){return this._events.push({pattern:e,handler:r}),this}};var tr=19*1024,rr=2,nr=1,sr=32,or={deriveKey:(t,e)=>F.host.deriveKey(t,e),aesGcmEncrypt:t=>{let e=B.encode(t);return F.host.aesGcmEncrypt(e)},aesGcmDecrypt:t=>{let e=F.host.aesGcmDecrypt(t);return B.decode(e)},argon2Hash:(t,e,r)=>F.host.argon2Hash({tag:t},new TextEncoder().encode(e),r?.mCost??tr,r?.tCost??rr,r?.pCost??nr,r?.outputLen??sr),argon2Verify:(t,e,r,n)=>F.host.argon2Verify({tag:t},new TextEncoder().encode(e),new TextEncoder().encode(r),n?.mCost??tr,n?.tCost??rr,n?.pCost??nr,n?.outputLen??sr)};var _=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 Re=class extends _{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))}},Ce=class{_query;constructor(e,r){this._query=new Re(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)}}},Ve=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 ze=class t extends _{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)}}},Qe=class t extends _{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 Ke=class t extends _{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)}}},Ye=class t extends _{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 ir={entity:t=>new mt(t)},mt=class{constructor(e){this.name=e}find(e){return new Re(this,e)}findOne(e){return new Ce(this,e)}insert(e){return new He(this,e,"insertedIds")}insertOne(e){return new Ve(this,e,"insertedId")}update(e,r){return new ze(this,e,r,"affectedRows")}updateOne(e,r){return new Qe(this,e,r,"success")}remove(e){return new Ke(this,e,"affectedRows")}removeOne(e){return new Ye(this,e,"success")}};var ar={publish:async(t,e,r)=>{let n=B.encode(e);return r=r??["public"],await oe.host.publish(t,n,r.map(s=>({tag:s})))}};var cr={get:async t=>{let e=await W.host.get(t);return JSON.parse(e)},getDel:async t=>{let e=await W.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 W.host.set(t,JSON.stringify(e),n)},delete:async t=>await W.host.delete(t)};var dr={call:async(t,e)=>{let r=j.fromRequest(new Request(t,e)),n=await j.host.call(r);return j.toResponse(n)}};var ur={push:async(t,e)=>{let r=B.encode(t);return await je.host.push(r,e)}};var Y=new Ge(an),ie=(t,e)=>Object.defineProperty(globalThis,t,{value:Object.freeze(e),enumerable:!1,configurable:!1,writable:!1});ie("$crypto",or);ie("$db",ir);ie("$event",ar);ie("$kv",cr);ie("$rpc",dr);ie("$sse",ur);var li={};var hi=X.guest;var mi=oe.guest;var gi=j.guest;export{Y as app,mr as console,li as guest,hi as"m1cro:common/guest",mi as"m1cro:pub-sub/guest",gi 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.
|
|
3
|
+
"version": "0.1.0-beta.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/bootstrap.js",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@types/json-schema": "^7.0.15",
|
|
18
|
+
"@types/node": "^25.2.0",
|
|
18
19
|
"esbuild": "^0.27.2"
|
|
19
20
|
}
|
|
20
21
|
}
|
|
@@ -17,7 +17,7 @@ interface host {
|
|
|
17
17
|
interface guest {
|
|
18
18
|
use types.{error};
|
|
19
19
|
|
|
20
|
-
invoke-event-handler: func(idx: u32, payload: list<u8>) -> result<_, error>;
|
|
20
|
+
invoke-event-handler: func(idx: u32, event: string, payload: list<u8>) -> result<_, error>;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
world bindings {
|
|
@@ -20,6 +20,7 @@ interface types {
|
|
|
20
20
|
get-all-headers: func(name: string) -> list<string>;
|
|
21
21
|
insert-header: func(name: string, value: string);
|
|
22
22
|
append-header: func(name: string, value: string);
|
|
23
|
+
set-headers: func(headers: list<tuple<string, string>>);
|
|
23
24
|
get-cookie: func(name: string) -> option<cookie>;
|
|
24
25
|
set-cookie: func(cookie: cookie);
|
|
25
26
|
get-param: func(key: string) -> option<string>;
|