@m1cro/js-bootstrap 0.1.0-beta.20 → 0.1.0-beta.7
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 +11 -11
- package/package.json +6 -10
- package/wit/deps/m1cro-app/package.wit +0 -28
- package/wit/deps/m1cro-common/package.wit +0 -109
- package/wit/deps/m1cro-crypto/package.wit +0 -34
- package/wit/deps/m1cro-entity/package.wit +0 -110
- package/wit/deps/m1cro-kv/package.wit +0 -61
- package/wit/deps/m1cro-log/package.wit +0 -26
- package/wit/deps/m1cro-pub-sub/package.wit +0 -29
- package/wit/deps/m1cro-rpc/package.wit +0 -102
- package/wit/deps/m1cro-sse/package.wit +0 -9
- package/wit/world.wit +0 -18
package/dist/bootstrap.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var lr=Object.defineProperty;var F=(t,e)=>{for(var r in e)lr(t,r,{get:e[r],enumerable:!0})};var Te={};F(Te,{host:()=>mr});import*as It from"m1cro:app/host";var mr={getSettings(){return It.getSettings()}};var $={};F($,{guest:()=>yr,host:()=>gr});import*as j from"m1cro:common/host";var gr={getTenant(){return j.getTenant()},getArtifact(t){return j.getArtifact(t)},getCrd(t){return j.getCRD(t)},listProviders(t){return j.listProviders(t)}},yr={getManifest(){return N.manifest},async start(){await N.emit("start")},async install(){await N.emit("install")}};var G={};F(G,{host:()=>wr});import*as U from"m1cro:crypto/host";var wr={deriveKey:(t,e)=>U.deriveKey(t,e),aesGcmEncrypt:t=>U.aesGcmEncrypt(t),aesGcmDecrypt:t=>U.aesGcmDecrypt(t),argon2Hash:(t,e,r,n,s,i)=>U.argon2Hash(t,e,r,n,s,i),argon2Verify:(t,e,r,n,s,i,o)=>U.argon2Verify(t,e,r,n,s,i,o)};var I={};F(I,{host:()=>br});import*as H from"m1cro:entity/host";var br={async find(t){return await H.find(t)},async insert(t){return await H.insert(t)},async update(t){return await H.update(t)},async remove(t){return await H.remove(t)}};var J={};F(J,{host:()=>Tr});import*as C from"m1cro:kv/host";var Tr={async get(t){return await C.get(t)},async getDel(t){return await C.getDel(t)},async set(t,e,r){return await C.set(t,e,r)},async delete(t){return await C.delete(t)}};var O={};F(O,{guest:()=>Ir,host:()=>Rr,types:()=>Er});import*as Er from"m1cro:rpc/types";import*as xt from"m1cro:rpc/host";var Ee=class t{#e;#t="get";#r=new Headers;#n;constructor(e){this.#e=new URL(e)}get method(){return this.#t}withMethod(e){return this.#t=e,this}get url(){return this.#e}withUrl(e){return this.#e=new URL(e),this}header(e){return this.#r.get(e)??void 0}withHeader(e,r){return this.#r.set(e,r),this}get headers(){return this.#r}withHeaders(e){return e instanceof Headers?e.forEach((r,n)=>this.#r.set(n,r)):Array.isArray(e)?e.forEach(([r,n])=>this.#r.set(r,n)):Object.entries(e).forEach(([r,n])=>this.#r.set(r,n)),this}async body(){return this.#n===void 0?new Uint8Array:await this.#n}withBody(e){return this.#n=Promise.resolve(e),this}async text(){let e=await this.body();return new TextDecoder().decode(e)}withText(e){return this.withBody(new TextEncoder().encode(e)),this}async json(){let e=await this.text();return JSON.parse(e)}withJson(e){return this.withText(JSON.stringify(e)),this}static fromHostRequest(e){return new t("http://"+e.getUrl()).withMethod(e.getMethod().tag).withHeaders(e.getHeaders()).withBody(e.getBody())}async toHostRequest(){let e=new O.types.Request,r=this.method.toLowerCase();switch(r){case"get":case"post":case"put":case"patch":case"delete":e.setMethod({tag:r});break;default:throw new Error(`Invalid method: ${r}`)}return e.setUrl(this.url.toString()),e.setHeaders(Array.from(this.headers.entries())),e.setBody(await this.body()),e}},Re=class t{#e;#t=new Headers;#r;constructor(e=200){this.#e=e}get status(){return this.#e}withStatus(e){return this.#e=e,this}header(e){return this.#t.get(e)??void 0}withHeader(e,r){return this.#t.set(e,r),this}get headers(){return this.#t}withHeaders(e){return e instanceof Headers?e.forEach((r,n)=>this.#t.set(n,r)):Array.isArray(e)?e.forEach(([r,n])=>this.#t.set(r,n)):Object.entries(e).forEach(([r,n])=>this.#t.set(r,n)),this}async body(){return this.#r===void 0?new Uint8Array:await this.#r}withBody(e){return this.#r=Promise.resolve(e),this}async text(){let e=await this.body();return new TextDecoder().decode(e)}withText(e){return this.withBody(new TextEncoder().encode(e)),this}async json(){let e=await this.text();return JSON.parse(e)}withJson(e){return this.withText(JSON.stringify(e)),this}static async fromHostResponse(e){return new t(e.getStatus()).withHeaders(e.getHeaders()).withBody(e.getBody())}async toHostResponse(){let e=new O.types.Response;return e.setStatus(this.status),e.setHeaders(Array.from(this.headers.entries())),e.setBody(await this.body()),e}};var Rr={call:async t=>await xt.call(t)},Ir={call:async(t,e,r,n)=>{let s=N.router.routes[t];if(!s)throw new Error(`Route not found for index ${t}`);let i=Ee.fromHostRequest(r),o=new Re;return await s.handler.bind(N)(i,o),await o.toHostResponse()}};import*as xr from"m1cro:log/host";var se={};F(se,{guest:()=>nn,host:()=>rn});var c={POS_INT:0,NEG_INT:1,BYTE_STRING:2,UTF8_STRING:3,ARRAY:4,MAP:5,TAG:6,SIMPLE_FLOAT:7},l={DATE_STRING:0,DATE_EPOCH:1,POS_BIGINT:2,NEG_BIGINT:3,DECIMAL_FRAC:4,BIGFLOAT:5,BASE64URL_EXPECTED:21,BASE64_EXPECTED:22,BASE16_EXPECTED:23,CBOR:24,URI:32,BASE64URL:33,BASE64:34,MIME:36,DATE_EPOCH_DAYS:100,SET:258,JSON:262,WTF8:273,DATE_FULL:1004,REGEXP:21066,SELF_DESCRIBED:55799,INVALID_16:65535,INVALID_32:4294967295,INVALID_64:0xffffffffffffffffn},h={ZERO:0,ONE:24,TWO:25,FOUR:26,EIGHT:27,INDEFINITE:31},_={FALSE:20,TRUE:21,NULL:22,UNDEFINED:23},y=class{static BREAK=Symbol.for("github.com/hildjj/cbor2/break");static ENCODED=Symbol.for("github.com/hildjj/cbor2/cbor-encoded");static LENGTH=Symbol.for("github.com/hildjj/cbor2/length")},ee={MIN:-(2n**63n),MAX:2n**64n-1n};var p=class t{static#e=new Map;tag;contents;constructor(e,r=void 0){this.tag=e,this.contents=r}get noChildren(){return!!t.#e.get(this.tag)?.noChildren}static registerDecoder(e,r,n){let s=this.#e.get(e);return this.#e.set(e,r),s&&("comment"in r||(r.comment=s.comment),"noChildren"in r||(r.noChildren=s.noChildren)),n&&!r.comment&&(r.comment=()=>`(${n})`),s}static clearDecoder(e){let r=this.#e.get(e);return this.#e.delete(e),r}static getDecoder(e){return this.#e.get(e)}static getAllDecoders(){return new Map(this.#e)}*[Symbol.iterator](){yield this.contents}push(e){return this.contents=e,1}decode(e){let r=e?.tags?.get(this.tag)??(e?.ignoreGlobalTags?void 0:t.#e.get(this.tag));return r?r(this,e):this}comment(e,r){let n=e?.tags?.get(this.tag)??(e?.ignoreGlobalTags?void 0:t.#e.get(this.tag));if(n?.comment)return n.comment(this,e,r)}toCBOR(){return[this.tag,this.contents]}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return`${this.tag}(${n(this.contents,r)})`}};function q(t){if(t!=null&&typeof t=="object")return t[y.ENCODED]}function St(t){if(t!=null&&typeof t=="object")return t[y.LENGTH]}function z(t,e){Object.defineProperty(t,y.ENCODED,{configurable:!0,enumerable:!1,value:e})}function V(t,e){let r=Object(t);return z(r,e),r}var Je=Symbol("CBOR_RANGES");function Ot(t,e){Object.defineProperty(t,Je,{configurable:!1,enumerable:!1,writable:!1,value:e})}function ce(t){return t[Je]}function Or(t){return ce(t)!==void 0}function de(t,e=0,r=t.length-1){let n=t.subarray(e,r),s=ce(t);if(s){let i=[];for(let o of s)if(o[0]>=e&&o[0]+o[1]<=r){let a=[...o];a[0]-=e,i.push(a)}i.length&&Ot(n,i)}return n}function Ie(t){let e=Math.ceil(t.length/2),r=new Uint8Array(e);e--;for(let n=t.length,s=n-2;n>=0;n=s,s-=2,e--)r[e]=parseInt(t.substring(s,n),16);return r}function T(t){return t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")}function At(t){let e=t.reduce((o,a)=>o+a.length,0),r=t.some(o=>Or(o)),n=[],s=new Uint8Array(e),i=0;for(let o of t){if(!(o instanceof Uint8Array))throw new TypeError(`Invalid array: ${o}`);if(s.set(o,i),r){let a=o[Je]??[[0,o.length]];for(let d of a)d[0]+=i;n.push(...a)}i+=o.length}return r&&Ot(s,n),s}function ue(t){let e=atob(t);return Uint8Array.from(e,r=>r.codePointAt(0))}var Ar={"-":"+",_:"/"};function vt(t){let e=t.replace(/[_-]/g,r=>Ar[r]);return ue(e.padEnd(Math.ceil(e.length/4)*4,"="))}function Nt(){let t=new Uint8Array(4),e=new Uint32Array(t.buffer);return!((e[0]=1)&t[0])}function Ze(t){let e="";for(let r of t){let n=r.codePointAt(0)?.toString(16).padStart(4,"0");e&&(e+=", "),e+=`U+${n}`}return e}var fe=class{#e=new Map;registerEncoder(e,r){let n=this.#e.get(e);return this.#e.set(e,r),n}get(e){return this.#e.get(e)}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}};function xe(t,e){let[r,n,s]=t,[i,o,a]=e,d=Math.min(s.length,a.length);for(let u=0;u<d;u++){let f=s[u]-a[u];if(f!==0)return f}return 0}var te=class t{static defaultOptions={chunkSize:4096};#e;#t=[];#r=null;#n=0;#s=0;constructor(e={}){if(this.#e={...t.defaultOptions,...e},this.#e.chunkSize<8)throw new RangeError(`Expected size >= 8, got ${this.#e.chunkSize}`);this.#o()}get length(){return this.#s}read(){this.#c();let e=new Uint8Array(this.#s),r=0;for(let n of this.#t)e.set(n,r),r+=n.length;return this.#o(),e}write(e){let r=e.length;r>this.#d()?(this.#c(),r>this.#e.chunkSize?(this.#t.push(e),this.#o()):(this.#o(),this.#t[this.#t.length-1].set(e),this.#n=r)):(this.#t[this.#t.length-1].set(e,this.#n),this.#n+=r),this.#s+=r}writeUint8(e){this.#i(1),this.#r.setUint8(this.#n,e),this.#a(1)}writeUint16(e,r=!1){this.#i(2),this.#r.setUint16(this.#n,e,r),this.#a(2)}writeUint32(e,r=!1){this.#i(4),this.#r.setUint32(this.#n,e,r),this.#a(4)}writeBigUint64(e,r=!1){this.#i(8),this.#r.setBigUint64(this.#n,e,r),this.#a(8)}writeInt16(e,r=!1){this.#i(2),this.#r.setInt16(this.#n,e,r),this.#a(2)}writeInt32(e,r=!1){this.#i(4),this.#r.setInt32(this.#n,e,r),this.#a(4)}writeBigInt64(e,r=!1){this.#i(8),this.#r.setBigInt64(this.#n,e,r),this.#a(8)}writeFloat32(e,r=!1){this.#i(4),this.#r.setFloat32(this.#n,e,r),this.#a(4)}writeFloat64(e,r=!1){this.#i(8),this.#r.setFloat64(this.#n,e,r),this.#a(8)}clear(){this.#s=0,this.#t=[],this.#o()}#o(){let e=new Uint8Array(this.#e.chunkSize);this.#t.push(e),this.#n=0,this.#r=new DataView(e.buffer,e.byteOffset,e.byteLength)}#c(){if(this.#n===0){this.#t.pop();return}let e=this.#t.length-1;this.#t[e]=this.#t[e].subarray(0,this.#n),this.#n=0,this.#r=null}#d(){let e=this.#t.length-1;return this.#t[e].length-this.#n}#i(e){this.#d()<e&&(this.#c(),this.#o())}#a(e){this.#n+=e,this.#s+=e}};var Xe=1n<<15n,pe=0b11111n<<10n,Pt=1n<<9n,kt=Pt-1n,Ut=Pt|kt,et=1n<<31n,he=0b11111111n<<23n,Ft=1n<<22n,jt=Ft-1n,_t=Ft|jt,Se=1n<<63n,L=0b11111111111n<<52n,le=1n<<51n,Oe=le-1n,Dt=le|Oe,Bt=Oe-(kt<<42n),Mt=Oe-(jt<<29n),vr={2:"0b",8:"0o",16:"0x"},$t=(t=>(t[t.NATURAL=-2]="NATURAL",t[t.UNKNOWN=-1]="UNKNOWN",t[t.F16=2]="F16",t[t.F32=4]="F32",t[t.F64=8]="F64",t))($t||{});function Lt(t,e,r,n){let s="nan'";return t.quiet||(s+="!"),t.sign===-1&&(s+="-"),s+=n(Math.abs(t.payload),r),s+="'",s+=t.encodingIndicator,s}var me=class extends Number{#e;#t=-1;constructor(e,r=!0,n=-1){super(NaN);let s=e;if(typeof e=="number"){if(!Number.isSafeInteger(e))throw new Error(`Invalid NAN payload: ${e}`);e=BigInt(e);let i=0n;if(e<0&&(i=Se,e=-e),e>=le)throw new Error(`Payload too large: ${s}`);let o=r?le:0n;switch(this.#e=i|L|o|e,n){case-2:throw new Error("NAN_SIZE.NATURAL only valid for bigint constructor");case-1:n=this.preferredSize;break;case 2:if(this.#e&Bt)throw new Error("Invalid size for payload");break;case 4:if(this.#e&Mt)throw new Error("Invalid size for payload");break;case 8:break;default:throw new Error(`Invalid size: ${n}`)}this.#t=n}else if(typeof e=="bigint"){let i=-1;if((e&L)===L)this.#e=e,i=8;else if((e&he)===he){let o=(e&et)<<32n;this.#e=o|L|(e&_t)<<29n,i=4}else if((e&pe)===pe){let o=(e&Xe)<<48n;this.#e=o|L|(e&Ut)<<42n,i=2}else throw new Error(`Invalid raw NaN value: ${e}`);if(n===-1)this.#t=this.preferredSize;else if(n===-2)this.#t=i;else{if(n<i)throw new Error("Invalid bigint NaN size");this.#t=n}}else{let i=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.length){case 3:{if(e[0]!==249)throw new Error("Invalid CBOR encoding for half float");let o=BigInt(i.getUint16(1,!1));if((o&pe)!==pe)throw new Error("Not a NaN");let a=(o&Xe)<<48n;this.#e=a|L|(o&Ut)<<42n,this.#t=2;break}case 5:{if(e[0]!==250)throw new Error("Invalid CBOR encoding for single float");let o=BigInt(i.getUint32(1,!1));if((o&he)!==he)throw new Error("Not a NaN");let a=(o&et)<<32n;this.#e=a|L|(o&_t)<<29n,this.#t=4;break}case 9:{if(e[0]!==251)throw new Error("Invalid CBOR encoding for double float");if(this.#e=i.getBigUint64(1,!1),(this.#e&L)!==L)throw new Error("Not a NaN (NaNaN)");this.#t=8;break}default:throw new RangeError(`Invalid NAN size (should be 2, 4, or 8): ${e.length-1}`)}}if(!this.payload&&!this.quiet)throw new Error("Signalling NaN with zero payload")}get bytes(){let e=new ArrayBuffer(this.#t+1),r=new DataView(e);switch(this.#t){case 2:{r.setUint8(0,249);let n=(this.#e&Se?Xe:0n)|pe|(this.#e&Dt)>>42n;r.setUint16(1,Number(n),!1);break}case 4:{r.setUint8(0,250);let n=(this.#e&Se?et:0n)|he|(this.#e&Dt)>>29n;r.setUint32(1,Number(n),!1);break}case 8:r.setUint8(0,251),r.setBigUint64(1,this.#e);break}return new Uint8Array(e)}get quiet(){return!!(this.#e&le)}get sign(){return this.#e&Se?-1:1}get payload(){return Number(this.#e&Oe)*this.sign}get raw(){return this.#e}get encodingIndicator(){switch(this.#t){case 2:return"_1";case 4:return"_2"}return"_3"}get size(){return this.#t}get preferredSize(){return(this.#e&Bt)===0n?2:(this.#e&Mt)===0n?4:8}get isShortestEncoding(){return this.preferredSize===this.#t}toCBOR(e){e.write(this.bytes)}toString(e=10){return Lt(this,1,{},r=>(vr[e]??"")+r.toString(e))}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return Lt(this,e,r,n)}};function tt(t,e=0,r=!1){let n=t[e]&128?-1:1,s=(t[e]&124)>>2,i=(t[e]&3)<<8|t[e+1];if(s===0){if(r&&i!==0)throw new Error(`Unwanted subnormal: ${n*5960464477539063e-23*i}`);return n*5960464477539063e-23*i}else if(s===31)return i?NaN:n*(1/0);return n*2**(s-25)*(1024+i)}function Ae(t){let e=new DataView(new ArrayBuffer(4));e.setFloat32(0,t,!1);let r=e.getUint32(0,!1);if((r&8191)!==0)return null;let n=r>>16&32768,s=r>>23&255,i=r&8388607;if(!(s===0&&i===0))if(s>=113&&s<=142)n+=(s-112<<10)+(i>>13);else if(s>=103&&s<113){if(i&(1<<126-s)-1)return null;n+=i+8388608>>126-s}else if(s===255)n|=31744,n|=i>>13;else return null;return n}function Gt(t){if(t!==0){let e=new ArrayBuffer(8),r=new DataView(e);r.setFloat64(0,t,!1);let n=r.getBigUint64(0,!1);if((n&0x7ff0000000000000n)===0n)return n&0x8000000000000000n?-0:0}return t}function Ht(t){switch(t.length){case 2:tt(t,0,!0);break;case 4:{let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=e.getUint32(0,!1);if((r&2139095040)===0&&r&8388607)throw new Error(`Unwanted subnormal: ${e.getFloat32(0,!1)}`);break}case 8:{let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=e.getBigUint64(0,!1);if((r&0x7ff0000000000000n)===0n&&r&0x000fffffffffffn)throw new Error(`Unwanted subnormal: ${e.getFloat64(0,!1)}`);break}default:throw new TypeError(`Bad input to isSubnormal: ${t}`)}}var ge=class extends TypeError{code="ERR_ENCODING_INVALID_ENCODED_DATA";constructor(){super("The encoded data was not valid for encoding wtf-8")}},ve=class extends RangeError{code="ERR_ENCODING_NOT_SUPPORTED";constructor(e){super(`Invalid encoding: "${e}"`)}};var Ne=new Uint8Array(0);var rt=55296,Ct=56320,qt=65533,Ue="wtf-8";function Ur(t){return t&&!(t instanceof ArrayBuffer)&&t.buffer instanceof ArrayBuffer}function _r(t){return t?t instanceof Uint8Array?t:Ur(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t):Ne}var Dr=[0,0,0,0,0,0,0,0,-1,-1,-1,-1,1,1,2,3],Z=class t{static DEFAULT_BUFFERSIZE=4096;encoding=Ue;fatal;ignoreBOM;bufferSize;#e=0;#t=0;#r=0;#n=!0;#s;constructor(e="wtf8",r=void 0){if(e.toLowerCase().replace("-","")!=="wtf8")throw new ve(e);if(this.fatal=!!r?.fatal,this.ignoreBOM=!!r?.ignoreBOM,this.bufferSize=Math.floor(r?.bufferSize??t.DEFAULT_BUFFERSIZE),isNaN(this.bufferSize)||this.bufferSize<1)throw new RangeError(`Invalid buffer size: ${r?.bufferSize}`);this.#s=new Uint16Array(this.bufferSize)}decode(e,r){let n=!!r?.stream,s=_r(e),i=[],o=this.#s,a=this.bufferSize-3,d=0,u=()=>{if(this.#t=0,this.#e=0,this.#r=0,this.fatal)throw new ge;o[d++]=qt},f=()=>{let g=this.#r;for(let v=0;v<g;v++)u()},m=g=>{if(this.#e===0)switch(Dr[g>>4]){case-1:u();break;case 0:o[d++]=g;break;case 1:this.#t=g&31,(this.#t&30)===0?u():(this.#e=1,this.#r=1);break;case 2:this.#t=g&15,this.#e=2,this.#r=1;break;case 3:g&8?u():(this.#t=g&7,this.#e=3,this.#r=1);break}else{if((g&192)!==128||this.#r===1&&this.#e===2&&this.#t===0&&(g&32)===0||this.#e===3&&this.#t===0&&(g&48)===0)return f(),m(g);if(this.#t=this.#t<<6|g&63,this.#r++,--this.#e===0){if(this.ignoreBOM||!this.#n||this.#t!==65279)if(this.#t<65536)o[d++]=this.#t;else{let v=this.#t-65536;o[d++]=v>>>10&1023|rt,o[d++]=v&1023|Ct}this.#t=0,this.#r=0,this.#n=!1}}};for(let g of s)d>=a&&(i.push(String.fromCharCode.apply(null,o.subarray(0,d))),d=0),m(g);return n||(this.#n=!0,(this.#t||this.#e)&&f()),d>0&&i.push(String.fromCharCode.apply(null,o.subarray(0,d))),i.join("")}};function Br(t){let e=0;for(let r of t){let n=r.codePointAt(0);n<128?e++:n<2048?e+=2:n<65536?e+=3:e+=4}return e}var re=class{encoding=Ue;encode(e){if(!e)return Ne;let r=new Uint8Array(Br(String(e)));return this.encodeInto(e,r),r}encodeInto(e,r){let n=String(e),s=n.length,i=r.length,o=0,a=0;for(a=0;a<s;a++){let d=n.codePointAt(a);if(d<128){if(o>=i)break;r[o++]=d}else if(d<2048){if(o>=i-1)break;r[o++]=192|d>>6,r[o++]=128|d&63}else if(d<65536){if(o>=i-2)break;r[o++]=224|d>>12,r[o++]=128|d>>6&63,r[o++]=128|d&63}else{if(o>=i-3)break;r[o++]=240|d>>18,r[o++]=128|d>>12&63,r[o++]=128|d>>6&63,r[o++]=128|d&63,a++}}return{read:a,written:o}}};var{ENCODED:Xn}=y,zt=c.SIMPLE_FLOAT<<5|h.TWO,Mr=c.SIMPLE_FLOAT<<5|h.FOUR,Lr=c.SIMPLE_FLOAT<<5|h.EIGHT,Pr=c.SIMPLE_FLOAT<<5|_.TRUE,kr=c.SIMPLE_FLOAT<<5|_.FALSE,Fr=c.SIMPLE_FLOAT<<5|_.UNDEFINED,jr=c.SIMPLE_FLOAT<<5|_.NULL,$r=new TextEncoder,Gr=new re,De={...te.defaultOptions,avoidInts:!1,cde:!1,collapseBigInts:!0,dateTag:l.DATE_EPOCH,dcbor:!1,float64:!1,flushToZero:!1,forceEndian:null,ignoreOriginalEncoding:!1,largeNegativeAsBigInt:!1,reduceUnsafeNumbers:!1,rejectBigInts:!1,rejectCustomSimples:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectUndefined:!1,simplifyNegativeZero:!1,sortKeys:null,stringNormalization:null,types:null,wtf8:!1,ignoreGlobalTags:!1},st={cde:!0,ignoreOriginalEncoding:!0,sortKeys:xe},Vt={...st,dcbor:!0,largeNegativeAsBigInt:!0,reduceUnsafeNumbers:!0,rejectCustomSimples:!0,rejectDuplicateKeys:!0,rejectUndefined:!0,simplifyNegativeZero:!0,stringNormalization:"NFC"};function Kt(t){let e=t<0;return typeof t=="bigint"?[e?-t-1n:t,e]:[e?-t-1:t,e]}function nt(t,e,r){if(r.rejectFloats)throw new Error(`Attempt to encode an unwanted floating point number: ${t}`);if(isNaN(t))e.writeUint8(zt),e.writeUint16(32256);else if(!r.float64&&Math.fround(t)===t){let n=Ae(t);n===null?(e.writeUint8(Mr),e.writeFloat32(t)):(e.writeUint8(zt),e.writeUint16(n))}else e.writeUint8(Lr),e.writeFloat64(t)}function R(t,e,r){let[n,s]=Kt(t);if(s&&r)throw new TypeError(`Negative size: ${t}`);r??=s?c.NEG_INT:c.POS_INT,r<<=5,n<24?e.writeUint8(r|n):n<=255?(e.writeUint8(r|h.ONE),e.writeUint8(n)):n<=65535?(e.writeUint8(r|h.TWO),e.writeUint16(n)):n<=4294967295?(e.writeUint8(r|h.FOUR),e.writeUint32(n)):(e.writeUint8(r|h.EIGHT),e.writeBigUint64(BigInt(n)))}function ne(t,e,r){typeof t=="number"?R(t,e,c.TAG):typeof t=="object"&&!r.ignoreOriginalEncoding&&y.ENCODED in t?e.write(t[y.ENCODED]):t<=Number.MAX_SAFE_INTEGER?R(Number(t),e,c.TAG):(e.writeUint8(c.TAG<<5|h.EIGHT),e.writeBigUint64(BigInt(t)))}function Qt(t,e,r){let[n,s]=Kt(t);if(r.collapseBigInts&&(!r.largeNegativeAsBigInt||t>=-0x8000000000000000n)){if(n<=0xffffffffn){R(Number(t),e);return}if(n<=0xffffffffffffffffn){let u=(s?c.NEG_INT:c.POS_INT)<<5;e.writeUint8(u|h.EIGHT),e.writeBigUint64(n);return}}if(r.rejectBigInts)throw new Error(`Attempt to encode unwanted bigint: ${t}`);let i=s?l.NEG_BIGINT:l.POS_BIGINT,o=n.toString(16),a=o.length%2?"0":"";ne(i,e,r);let d=Ie(a+o);R(d.length,e,c.BYTE_STRING),e.write(d)}function Hr(t,e,r){r.flushToZero&&(t=Gt(t)),Object.is(t,-0)?r.simplifyNegativeZero?r.avoidInts?nt(0,e,r):R(0,e):nt(t,e,r):!r.avoidInts&&Number.isSafeInteger(t)?R(t,e):r.reduceUnsafeNumbers&&Math.floor(t)===t&&t>=ee.MIN&&t<=ee.MAX?Qt(BigInt(t),e,r):nt(t,e,r)}function Cr(t,e,r){let n=r.stringNormalization?t.normalize(r.stringNormalization):t;if(r.wtf8&&!t.isWellFormed()){let s=Gr.encode(n);ne(l.WTF8,e,r),R(s.length,e,c.BYTE_STRING),e.write(s)}else{let s=$r.encode(n);R(s.length,e,c.UTF8_STRING),e.write(s)}}function qr(t,e,r){let n=t;Be(n,n.length,c.ARRAY,e,r);for(let s of n)K(s,e,r)}function zr(t,e){R(t.length,e,c.BYTE_STRING),e.write(t)}var _e=new fe;_e.registerEncoder(Array,qr),_e.registerEncoder(Uint8Array,zr);function w(t,e){return _e.registerEncoder(t,e)}function Be(t,e,r,n,s){let i=St(t);i&&!s.ignoreOriginalEncoding?n.write(i):R(e,n,r)}function Vr(t,e,r){if(t===null){e.writeUint8(jr);return}if(!r.ignoreOriginalEncoding&&y.ENCODED in t){e.write(t[y.ENCODED]);return}let n=t.constructor;if(n){let i=r.types?.get(n)??(r.ignoreGlobalTags?void 0:_e.get(n));if(i){let o=i(t,e,r);if(o!==void 0){if(!Array.isArray(o)||o.length!==2)throw new Error("Invalid encoder return value");(typeof o[0]=="bigint"||isFinite(Number(o[0])))&&ne(o[0],e,r),K(o[1],e,r)}return}}if(typeof t.toCBOR=="function"){let i=t.toCBOR(e,r);i&&((typeof i[0]=="bigint"||isFinite(Number(i[0])))&&ne(i[0],e,r),K(i[1],e,r));return}if(typeof t.toJSON=="function"){K(t.toJSON(),e,r);return}let s=Object.entries(t).map(i=>[i[0],i[1],D(i[0],r)]);r.sortKeys&&s.sort(r.sortKeys),Be(t,s.length,c.MAP,e,r);for(let[i,o,a]of s)e.write(a),K(o,e,r)}function K(t,e,r){switch(typeof t){case"number":Hr(t,e,r);break;case"bigint":Qt(t,e,r);break;case"string":Cr(t,e,r);break;case"boolean":e.writeUint8(t?Pr:kr);break;case"undefined":if(r.rejectUndefined)throw new Error("Attempt to encode unwanted undefined.");e.writeUint8(Fr);break;case"object":Vr(t,e,r);break;case"symbol":throw new TypeError(`Unknown symbol: ${t.toString()}`);default:throw new TypeError(`Unknown type: ${typeof t}, ${String(t)}`)}}function D(t,e={}){let r={...De};e.dcbor?Object.assign(r,Vt):e.cde&&Object.assign(r,st),Object.assign(r,e);let n=new te(r);return K(t,n,r),n.read()}var X=(t=>(t[t.NEVER=-1]="NEVER",t[t.PREFERRED=0]="PREFERRED",t[t.ALWAYS=1]="ALWAYS",t))(X||{});var A=class t{static KnownSimple=new Map([[_.FALSE,!1],[_.TRUE,!0],[_.NULL,null],[_.UNDEFINED,void 0]]);value;constructor(e){this.value=e}static create(e){return t.KnownSimple.has(e)?t.KnownSimple.get(e):new t(e)}toCBOR(e,r){if(r.rejectCustomSimples)throw new Error(`Cannot encode non-standard Simple value: ${this.value}`);R(this.value,e,c.SIMPLE_FLOAT)}toString(){return`simple(${this.value})`}decode(){return t.KnownSimple.has(this.value)?t.KnownSimple.get(this.value):this}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return`simple(${n(this.value,r)})`}};var Kr=new TextDecoder("utf8",{fatal:!0,ignoreBOM:!0}),B=class t{static defaultOptions={maxDepth:1024,encoding:"hex",requirePreferred:!1};#e;#t;#r=0;#n;constructor(e,r){if(this.#n={...t.defaultOptions,...r},typeof e=="string")switch(this.#n.encoding){case"hex":this.#e=Ie(e);break;case"base64":this.#e=ue(e);break;default:throw new TypeError(`Encoding not implemented: "${this.#n.encoding}"`)}else this.#e=e;this.#t=new DataView(this.#e.buffer,this.#e.byteOffset,this.#e.byteLength)}toHere(e){return de(this.#e,e,this.#r)}*[Symbol.iterator](){if(yield*this.#s(0),this.#r!==this.#e.length)throw new Error("Extra data in input")}*seq(){for(;this.#r<this.#e.length;)yield*this.#s(0)}*#s(e){if(e++>this.#n.maxDepth)throw new Error(`Maximum depth ${this.#n.maxDepth} exceeded`);let r=this.#r,n=this.#t.getUint8(this.#r++),s=n>>5,i=n&31,o=i,a=!1,d=0;switch(i){case h.ONE:if(d=1,o=this.#t.getUint8(this.#r),s===c.SIMPLE_FLOAT){if(o<32)throw new Error(`Invalid simple encoding in extra byte: ${o}`);a=!0}else if(this.#n.requirePreferred&&o<24)throw new Error(`Unexpectedly long integer encoding (1) for ${o}`);break;case h.TWO:if(d=2,s===c.SIMPLE_FLOAT)o=tt(this.#e,this.#r);else if(o=this.#t.getUint16(this.#r,!1),this.#n.requirePreferred&&o<=255)throw new Error(`Unexpectedly long integer encoding (2) for ${o}`);break;case h.FOUR:if(d=4,s===c.SIMPLE_FLOAT)o=this.#t.getFloat32(this.#r,!1);else if(o=this.#t.getUint32(this.#r,!1),this.#n.requirePreferred&&o<=65535)throw new Error(`Unexpectedly long integer encoding (4) for ${o}`);break;case h.EIGHT:{if(d=8,s===c.SIMPLE_FLOAT)o=this.#t.getFloat64(this.#r,!1);else if(o=this.#t.getBigUint64(this.#r,!1),o<=Number.MAX_SAFE_INTEGER&&(o=Number(o)),this.#n.requirePreferred&&o<=4294967295)throw new Error(`Unexpectedly long integer encoding (8) for ${o}`);break}case 28:case 29:case 30:throw new Error(`Additional info not implemented: ${i}`);case h.INDEFINITE:switch(s){case c.POS_INT:case c.NEG_INT:case c.TAG:throw new Error(`Invalid indefinite encoding for MT ${s}`);case c.SIMPLE_FLOAT:yield[s,i,y.BREAK,r,0];return}o=1/0;break;default:a=!0}switch(this.#r+=d,s){case c.POS_INT:yield[s,i,o,r,d];break;case c.NEG_INT:yield[s,i,typeof o=="bigint"?-1n-o:-1-Number(o),r,d];break;case c.BYTE_STRING:o===1/0?yield*this.#c(s,e,r):yield[s,i,this.#o(o),r,o];break;case c.UTF8_STRING:o===1/0?yield*this.#c(s,e,r):yield[s,i,Kr.decode(this.#o(o)),r,o];break;case c.ARRAY:if(o===1/0)yield*this.#c(s,e,r,!1);else{let u=Number(o);yield[s,i,u,r,d];for(let f=0;f<u;f++)yield*this.#s(e+1)}break;case c.MAP:if(o===1/0)yield*this.#c(s,e,r,!1);else{let u=Number(o);yield[s,i,u,r,d];for(let f=0;f<u;f++)yield*this.#s(e),yield*this.#s(e)}break;case c.TAG:yield[s,i,o,r,d],yield*this.#s(e);break;case c.SIMPLE_FLOAT:{let u=o;a&&(o=A.create(Number(o))),yield[s,i,o,r,u];break}}}#o(e){let r=de(this.#e,this.#r,this.#r+=e);if(r.length!==e)throw new Error(`Unexpected end of stream reading ${e} bytes, got ${r.length}`);return r}*#c(e,r,n,s=!0){for(yield[e,h.INDEFINITE,1/0,n,1/0];;){let i=this.#s(r),o=i.next(),[a,d,u]=o.value;if(u===y.BREAK){yield o.value,i.next();return}if(s){if(a!==e)throw new Error(`Unmatched major type. Expected ${e}, got ${a}.`);if(d===h.INDEFINITE)throw new Error("New stream started in typed stream")}yield o.value,yield*i}}};var Qr=new Map([[h.ZERO,1],[h.ONE,2],[h.TWO,3],[h.FOUR,5],[h.EIGHT,9]]),Yr=new Uint8Array(0);function Wr(t,e){return!e.boxed&&!e.preferMap&&t.every(([r])=>typeof r=="string")?Object.fromEntries(t):new Map(t)}var b=class t{static defaultDecodeOptions={...B.defaultOptions,ParentType:t,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:X.PREFERRED,collapseBigInts:!1,convertUnsafeIntsToFloat:!1,createObject:Wr,keepNanPayloads:!1,pretty:!1,preferBigInt:!1,preferMap:!1,rejectLargeNegatives:!1,rejectBigInts:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectInts:!1,rejectLongLoundNaN:!1,rejectLongFloats:!1,rejectNegativeZero:!1,rejectSimple:!1,rejectStreaming:!1,rejectStringsNotNormalizedAs:null,rejectSubnormals:!1,rejectUndefined:!1,rejectUnsafeFloatInts:!1,saveOriginal:!1,sortKeys:null,tags:null,ignoreGlobalTags:!1};static cdeDecodeOptions={cde:!0,rejectStreaming:!0,requirePreferred:!0,sortKeys:xe};static dcborDecodeOptions={...this.cdeDecodeOptions,dcbor:!0,convertUnsafeIntsToFloat:!0,rejectDuplicateKeys:!0,rejectLargeNegatives:!0,rejectLongLoundNaN:!0,rejectLongFloats:!0,rejectNegativeZero:!0,rejectSimple:!0,rejectUndefined:!0,rejectUnsafeFloatInts:!0,rejectStringsNotNormalizedAs:"NFC"};parent;mt;ai;left;offset;count=0;children=[];depth=0;#e;#t=null;constructor(e,r,n,s){if([this.mt,this.ai,,this.offset]=e,this.left=r,this.parent=n,this.#e=s,n&&(this.depth=n.depth+1),this.mt===c.MAP&&(this.#e.sortKeys||this.#e.rejectDuplicateKeys)&&(this.#t=[]),this.#e.rejectStreaming&&this.ai===h.INDEFINITE)throw new Error("Streaming not supported")}get isStreaming(){return this.left===1/0}get done(){return this.left===0}static create(e,r,n,s){let[i,o,a,d]=e;switch(i){case c.POS_INT:case c.NEG_INT:{if(n.rejectInts)throw new Error(`Unexpected integer: ${a}`);if(n.rejectLargeNegatives&&a<-0x8000000000000000n)throw new Error(`Invalid 65bit negative number: ${a}`);let u=a;return n.preferBigInt?u=BigInt(u):n.convertUnsafeIntsToFloat&&u>=ee.MIN&&u<=ee.MAX&&(u=Number(a)),n.boxed?V(u,s.toHere(d)):u}case c.SIMPLE_FLOAT:if(o>h.ONE){if(typeof a=="symbol")return a;if(n.rejectFloats)throw new Error(`Decoding unwanted floating point number: ${a}`);if(n.rejectNegativeZero&&Object.is(a,-0))throw new Error("Decoding negative zero");if(isNaN(a)){let u=s.toHere(d),f=new me(u);if(n.rejectLongLoundNaN){if(f.payload||u.length>3)throw new Error(`Invalid NaN encoding: "${T(u)}"`)}else if(n.keepNanPayloads&&(f.payload||f.sign===-1)){if(n.rejectLongFloats&&!f.isShortestEncoding)throw new Error(`NaN should have been encoded shorter: ${a}`);return f}}if(n.rejectSubnormals&&Ht(s.toHere(d+1)),n.rejectLongFloats){let u=D(a,{chunkSize:9,reduceUnsafeNumbers:n.rejectUnsafeFloatInts});if(u[0]>>5!==i)throw new Error(`Should have been encoded as int, not float: ${a}`);if(u.length<Qr.get(o))throw new Error(`Number should have been encoded shorter: ${a}`)}if(typeof a=="number"&&n.boxed)return V(a,s.toHere(d))}else{if(n.rejectSimple&&a instanceof A)throw new Error(`Invalid simple value: ${a}`);if(n.rejectUndefined&&a===void 0)throw new Error("Unexpected undefined")}return a;case c.BYTE_STRING:case c.UTF8_STRING:if(a===1/0)return new n.ParentType(e,1/0,r,n);if(n.rejectStringsNotNormalizedAs&&typeof a=="string"){let u=a.normalize(n.rejectStringsNotNormalizedAs);if(a!==u)throw new Error(`String not normalized as "${n.rejectStringsNotNormalizedAs}", got [${Ze(a)}] instead of [${Ze(u)}]`)}return n.boxed?V(a,s.toHere(d)):a;case c.ARRAY:return new n.ParentType(e,a,r,n);case c.MAP:return new n.ParentType(e,a*2,r,n);case c.TAG:{let u=new n.ParentType(e,1,r,n);return u.children=new p(a),u}}throw new TypeError(`Invalid major type: ${i}`)}static decodeToEncodeOpts(e){return{...De,avoidInts:e.rejectInts,float64:!e.rejectLongFloats,flushToZero:e.rejectSubnormals,largeNegativeAsBigInt:e.rejectLargeNegatives,sortKeys:e.sortKeys}}push(e,r,n){if(this.children.push(e),this.#t){let s=q(e)||r.toHere(n);this.#t.push(s)}return--this.left}replaceLast(e,r,n){let s,i=-1/0;if(this.children instanceof p?(i=0,s=this.children.contents,this.children.contents=e):(i=this.children.length-1,s=this.children[i],this.children[i]=e),this.#t){let o=q(e)||n.toHere(r.offset);this.#t[i]=o}return s}convert(e){let r;switch(this.mt){case c.ARRAY:r=this.children;break;case c.MAP:{let n=this.#r();if(this.#e.sortKeys){let s;for(let i of n){if(s&&this.#e.sortKeys(s,i)>=0)throw new Error(`Duplicate or out of order key: "0x${i[2]}"`);s=i}}else if(this.#e.rejectDuplicateKeys){let s=new Set;for(let[i,o,a]of n){let d=T(a);if(s.has(d))throw new Error(`Duplicate key: "0x${d}"`);s.add(d)}}r=this.#e.createObject(n,this.#e);break}case c.BYTE_STRING:return At(this.children);case c.UTF8_STRING:{let n=this.children.join("");r=this.#e.boxed?V(n,e.toHere(this.offset)):n;break}case c.TAG:r=this.children.decode(this.#e);break;default:throw new TypeError(`Invalid mt on convert: ${this.mt}`)}return this.#e.saveOriginal&&r&&typeof r=="object"&&z(r,e.toHere(this.offset)),r}#r(){let e=this.children,r=e.length;if(r%2)throw new Error("Missing map value");let n=new Array(r/2);if(this.#t)for(let s=0;s<r;s+=2)n[s>>1]=[e[s],e[s+1],this.#t[s]];else for(let s=0;s<r;s+=2)n[s>>1]=[e[s],e[s+1],Yr];return n}};var ot=" ",Jr=new TextEncoder,Me=class extends b{close="";quote='"';get isEmptyStream(){return(this.mt===c.UTF8_STRING||this.mt===c.BYTE_STRING)&&this.count===0}};function Q(t,e,r,n){let s="";if(e===h.INDEFINITE)s+="_";else{if(n.diagnosticSizes===X.NEVER)return"";{let i=n.diagnosticSizes===X.ALWAYS;if(!i){let o=h.ZERO;if(Object.is(r,-0))o=h.TWO;else if(t===c.POS_INT||t===c.NEG_INT){let a=r<0,d=typeof r=="bigint"?1n:1,u=a?-r-d:r;u<=23?o=Number(u):u<=255?o=h.ONE:u<=65535?o=h.TWO:u<=4294967295?o=h.FOUR:o=h.EIGHT}else isFinite(r)?Math.fround(r)===r?Ae(r)==null?o=h.FOUR:o=h.TWO:o=h.EIGHT:o=h.TWO;i=o!==e}i&&(s+="_",e<h.ONE?s+="i":s+=String(e-24))}}return s}function it(t,e){let r={...b.defaultDecodeOptions,...e,ParentType:Me},n=new B(t,r),s,i,o="";for(let a of n){let[d,u,f]=a;switch(s&&(s.count>0&&f!==y.BREAK&&(s.mt===c.MAP&&s.count%2?o+=": ":(o+=",",r.pretty||(o+=" "))),r.pretty&&(s.mt!==c.MAP||s.count%2===0)&&(o+=`
|
|
2
|
-
${
|
|
3
|
-
${
|
|
4
|
-
${
|
|
5
|
-
`,s.length>i+1){let d=ye((t.depth+1)*2),u=ce(s);if(u?.length){u.sort((m,g)=>m[0]-g[0]||g[1]-m[1]);let f=0;for(let[m,g,
|
|
6
|
-
`,n+=Pe(
|
|
7
|
-
`);if(m>i)for(let
|
|
8
|
-
`}}}else for(let f=i+1;f<s.length;f+=8)n+=d,n+=
|
|
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
|
+
${nt.repeat(s.depth+1)}`)),i=w.create(a,s,r,n),d){case c.POS_INT:case c.NEG_INT:o+=String(f),o+=H(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+=H(d,u,f,r)}else f instanceof N?(o+="simple(",o+=String(f.value),o+=H(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+=H(c.POS_INT,u,f.length,r));break;case c.UTF8_STRING:f===1/0?(o+="(_ ",i.close=")"):(o+=JSON.stringify(f),o+=H(c.POS_INT,u,Jr.encode(f).length,r));break;case c.ARRAY:{o+="[";let m=H(c.POS_INT,u,f,r);o+=m,m&&(o+=" "),r.pretty&&f?i.close=`
|
|
3
|
+
${nt.repeat(i.depth)}]`:i.close="]";break}case c.MAP:{o+="{";let m=H(c.POS_INT,u,f,r);o+=m,m&&(o+=" "),r.pretty&&f?i.close=`
|
|
4
|
+
${nt.repeat(i.depth)}}`:i.close="}";break}case c.TAG:o+=String(f),o+=H(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 Zr=new TextDecoder,be=class extends w{depth=0;leaf=!1;value;length;[y.ENCODED];constructor(e,r,n,s){super(e,r,n,s),this.parent?this.depth=this.parent.depth+1:this.depth=s.initialDepth,[,,this.value,,this.length]=e}numBytes(){switch(this.ai){case h.ONE:return 1;case h.TWO:return 2;case h.FOUR:return 4;case h.EIGHT:return 8}return 0}};function qt(t){return t instanceof be}function Le(t,e){return t===1/0?"Indefinite":e?`${t} ${e}${t!==1&&t!==1n?"s":""}`:String(t)}function ye(t){return"".padStart(t," ")}function Gt(t,e,r){let n="";n+=ye(t.depth*2);let s=j(t);n+=E(s.subarray(0,1));let i=t.numBytes();i&&(n+=" ",n+=E(s.subarray(1,i+1))),n=n.padEnd(e.minCol+1," "),n+="-- ",r!==void 0&&(n+=ye(t.depth*2),r!==""&&(n+=`[${r}] `));let o=!1,[a]=t.children;switch(t.mt){case c.POS_INT:n+=`Unsigned: ${a}`,typeof a=="bigint"&&(n+="n");break;case c.NEG_INT:n+=`Negative: ${a}`,typeof a=="bigint"&&(n+="n");break;case c.BYTE_STRING:n+=`Bytes (Length: ${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);q(f,s);let m=f.comment(e,t.depth);m&&(n+=": ",n+=m),o||=f.noChildren;break}case c.SIMPLE_FLOAT:a===y.BREAK?n+="BREAK":t.ai>h.ONE?Object.is(a,-0)?n+="Float: -0":n+=`Float: ${a}`:(n+="Simple: ",a instanceof N?n+=a.value:n+=a);break}if(!o)if(t.leaf){if(n+=`
|
|
5
|
+
`,s.length>i+1){let d=ye((t.depth+1)*2),u=ce(s);if(u?.length){u.sort((m,g)=>m[0]-g[0]||g[1]-m[1]);let f=0;for(let[m,g,x]of u)if(!(m<f)){if(f=m+g,x==="<<"){n+=ye(e.minCol+1),n+="--",n+=d,n+="<< ";let B=de(s,m,m+g),oe=ce(B);if(oe){let pt=oe.findIndex(([ir,ar,cr])=>ir===0&&ar===g&&cr==="<<");pt>=0&&oe.splice(pt,1)}n+=st(B),n+=` >>
|
|
6
|
+
`,n+=Pe(B,{initialDepth:t.depth+1,minCol:e.minCol,noPrefixHex:!0});continue}else x==="'"&&(n+=ye(e.minCol+1),n+="--",n+=d,n+="'",n+=Zr.decode(s.subarray(m,m+g)),n+=`'
|
|
7
|
+
`);if(m>i)for(let B=m;B<m+g;B+=8){let oe=Math.min(B+8,m+g);n+=d,n+=E(s.subarray(B,oe)),n+=`
|
|
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(qt(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+=Gt(u,e,f)}d++}}return n}var Xr={...w.defaultDecodeOptions,initialDepth:0,noPrefixHex:!1,minCol:0};function Pe(t,e){let r={...Xr,...e,ParentType:be,saveOriginal:!0},n=new U(t,r),s,i;for(let a of n){if(i=w.create(a,s,r,n),a[2]===y.BREAK)if(s?.isStreaming)s.left=1;else throw new Error("Unexpected BREAK");if(!qt(i)){let f=new be(a,0,s,r);f.leaf=!0,f.children.push(i),q(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||q(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+=Gt(i,r),o}var Ct=!Tt();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 V(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 Yt(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],v(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),C(i,e,r)});function ot(t){return V(t.contents),new Date(t.contents)}ot.comment=t=>{V(t.contents);let e=new Date(t.contents);return`(String ${t.tag===l.DATE_FULL?"Full ":""}Date) ${e.toISOString()}`},p.registerDecoder(l.DATE_STRING,ot),p.registerDecoder(l.DATE_FULL,ot);function Ht(t){return ke(t.contents),new Date(t.contents*1e3)}Ht.comment=t=>(ke(t.contents),`(Epoch Date) ${new Date(t.contents*1e3).toISOString()}`),p.registerDecoder(l.DATE_EPOCH,Ht);var ct=1e3*60*60*24;function zt(t){return ke(t.contents),new Date(t.contents*ct)}zt.comment=t=>(ke(t.contents),`(Epoch Date) ${new Date(t.contents*ct).toISOString()}`),p.registerDecoder(l.DATE_EPOCH_DAYS,zt),b(Date,(t,e,r)=>{switch(r.dateTag){case l.DATE_EPOCH:return[r.dateTag,t.valueOf()/1e3];case l.DATE_STRING:return[r.dateTag,t.toISOString().replace(/\.000Z$/,"Z")];case l.DATE_EPOCH_DAYS:return[r.dateTag,Math.floor(t.valueOf()/ct)];case l.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?G(n,e.contents):n}var Vt=$e.bind(null,!1),Qt=$e.bind(null,!0);Vt.comment=(t,e)=>`(Positive BigInt) ${$e(!1,t,e)}n`,Qt.comment=(t,e)=>`(Negative BigInt) ${$e(!0,t,e)}n`,p.registerDecoder(l.POS_BIGINT,Vt),p.registerDecoder(l.NEG_BIGINT,Qt);function it(t,e){return M(t.contents),t}it.comment=(t,e,r)=>{M(t.contents);let n={...e,initialDepth:r+2,noPrefixHex:!0},s=j(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},ct.noChildren=!0,p.registerDecoder(l.CBOR,ct),p.registerDecoder(l.URI,t=>(W(t.contents),new URL(t.contents)),"URI"),w(URL,t=>[l.URI,t.toString()]),p.registerDecoder(l.BASE64URL,t=>(W(t.contents),vt(t.contents)),"Base64url-encoded"),p.registerDecoder(l.BASE64,t=>(W(t.contents),ue(t.contents)),"Base64-encoded"),p.registerDecoder(35,t=>(W(t.contents),new RegExp(t.contents)),"RegExp"),p.registerDecoder(21065,t=>{W(t.contents);let e=`^(?:${t.contents})$`;return new RegExp(e,"u")},"I-RegExp"),p.registerDecoder(l.REGEXP,t=>{if(nr(t.contents),t.contents.length<1||t.contents.length>2)throw new Error(`Invalid RegExp Array: ${t.contents}`);return new RegExp(t.contents[0],t.contents[1])},"RegExp"),w(RegExp,t=>[l.REGEXP,[t.source,t.flags]]),p.registerDecoder(64,t=>(P(t.contents),t.contents),"uint8 Typed Array");function E(t,e,r){P(t.contents);let n=t.contents.length;if(n%e.BYTES_PER_ELEMENT!==0)throw new Error(`Number of bytes must be divisible by ${e.BYTES_PER_ELEMENT}, got: ${n}`);n/=e.BYTES_PER_ELEMENT;let s=new e(n),i=new DataView(t.contents.buffer,t.contents.byteOffset,t.contents.byteLength),o=i[`get${e.name.replace(/Array/,"")}`].bind(i);for(let a=0;a<n;a++)s[a]=o(a*e.BYTES_PER_ELEMENT,r);return s}function Y(t,e,r,n,s){let i=s.forceEndian??Jt;if(ne(i?e:r,t,s),R(n.byteLength,t,c.BYTE_STRING),Jt===i)t.write(new Uint8Array(n.buffer,n.byteOffset,n.byteLength));else{let o=`write${n.constructor.name.replace(/Array/,"")}`,a=t[o].bind(t);for(let d of n)a(d,i)}}p.registerDecoder(65,t=>E(t,Uint16Array,!1),"uint16, big endian, Typed Array"),p.registerDecoder(66,t=>E(t,Uint32Array,!1),"uint32, big endian, Typed Array"),p.registerDecoder(67,t=>E(t,BigUint64Array,!1),"uint64, big endian, Typed Array"),p.registerDecoder(68,t=>(P(t.contents),new Uint8ClampedArray(t.contents)),"uint8 Typed Array, clamped arithmetic"),w(Uint8ClampedArray,t=>[68,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)]),p.registerDecoder(69,t=>E(t,Uint16Array,!0),"uint16, little endian, Typed Array"),w(Uint16Array,(t,e,r)=>Y(e,69,65,t,r)),p.registerDecoder(70,t=>E(t,Uint32Array,!0),"uint32, little endian, Typed Array"),w(Uint32Array,(t,e,r)=>Y(e,70,66,t,r)),p.registerDecoder(71,t=>E(t,BigUint64Array,!0),"uint64, little endian, Typed Array"),w(BigUint64Array,(t,e,r)=>Y(e,71,67,t,r)),p.registerDecoder(72,t=>(P(t.contents),new Int8Array(t.contents)),"sint8 Typed Array"),w(Int8Array,t=>[72,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)]),p.registerDecoder(73,t=>E(t,Int16Array,!1),"sint16, big endian, Typed Array"),p.registerDecoder(74,t=>E(t,Int32Array,!1),"sint32, big endian, Typed Array"),p.registerDecoder(75,t=>E(t,BigInt64Array,!1),"sint64, big endian, Typed Array"),p.registerDecoder(77,t=>E(t,Int16Array,!0),"sint16, little endian, Typed Array"),w(Int16Array,(t,e,r)=>Y(e,77,73,t,r)),p.registerDecoder(78,t=>E(t,Int32Array,!0),"sint32, little endian, Typed Array"),w(Int32Array,(t,e,r)=>Y(e,78,74,t,r)),p.registerDecoder(79,t=>E(t,BigInt64Array,!0),"sint64, little endian, Typed Array"),w(BigInt64Array,(t,e,r)=>Y(e,79,75,t,r)),p.registerDecoder(81,t=>E(t,Float32Array,!1),"IEEE 754 binary32, big endian, Typed Array"),p.registerDecoder(82,t=>E(t,Float64Array,!1),"IEEE 754 binary64, big endian, Typed Array"),p.registerDecoder(85,t=>E(t,Float32Array,!0),"IEEE 754 binary32, little endian, Typed Array"),w(Float32Array,(t,e,r)=>Y(e,85,81,t,r)),p.registerDecoder(86,t=>E(t,Float64Array,!0),"IEEE 754 binary64, big endian, Typed Array"),w(Float64Array,(t,e,r)=>Y(e,86,82,t,r)),p.registerDecoder(l.SET,(t,e)=>{if(nr(t.contents),e.sortKeys){let r=b.decodeToEncodeOpts(e),n=null;for(let s of t.contents){let i=[s,void 0,D(s,r)];if(n&&e.sortKeys(n,i)>=0)throw new Error(`Set items out of order in tag #${l.SET}`);n=i}}return new Set(t.contents)},"Set"),w(Set,(t,e,r)=>{let n=[...t];if(r.sortKeys){let s=n.map(i=>[i,void 0,D(i,r)]);s.sort(r.sortKeys),n=s.map(([i])=>i)}return[l.SET,n]}),p.registerDecoder(l.JSON,t=>(W(t.contents),JSON.parse(t.contents)),"JSON-encoded");function rr(t){return P(t.contents),new Z().decode(t.contents)}rr.comment=t=>{P(t.contents);let e=new Z;return`(WTF8 string): ${JSON.stringify(e.decode(t.contents))}`},p.registerDecoder(l.WTF8,rr),p.registerDecoder(l.SELF_DESCRIBED,t=>t.contents,"Self-Described"),p.registerDecoder(l.INVALID_16,()=>{throw new Error(`Tag always invalid: ${l.INVALID_16}`)},"Invalid"),p.registerDecoder(l.INVALID_32,()=>{throw new Error(`Tag always invalid: ${l.INVALID_32}`)},"Invalid"),p.registerDecoder(l.INVALID_64,()=>{throw new Error(`Tag always invalid: ${l.INVALID_64}`)},"Invalid");function dt(t){throw new Error(`Encoding ${t.constructor.name} intentionally unimplmented. It is not concrete enough to interoperate. Convert to Uint8Array first.`)}w(ArrayBuffer,dt),w(DataView,dt),typeof SharedArrayBuffer<"u"&&w(SharedArrayBuffer,dt);function ke(t){return[NaN,t.valueOf()]}w(Boolean,ke),w(Number,ke),w(String,ke),w(BigInt,ke);function en(t){let e={...b.defaultDecodeOptions};if(t.dcbor?Object.assign(e,b.dcborDecodeOptions):t.cde&&Object.assign(e,b.cdeDecodeOptions),Object.assign(e,t),Object.hasOwn(e,"rejectLongNumbers"))throw new TypeError("rejectLongNumbers has changed to requirePreferred");return e.boxed&&(e.saveOriginal=!0),e}var ft=class{parent=void 0;ret=void 0;step(e,r,n){if(this.ret=b.create(e,this.parent,r,n),e[2]===y.BREAK)if(this.parent?.isStreaming)this.parent.left=0;else throw new Error("Unexpected BREAK");else this.parent&&this.parent.push(this.ret,n,e[3]);for(this.ret instanceof b&&(this.parent=this.ret);this.parent?.done;){this.ret=this.parent.convert(n);let s=this.parent.parent;s?.replaceLast(this.ret,this.parent,n),this.parent=s}}};function pt(t,e={}){let r=en(e),n=new B(t,r),s=new ft;for(let i of n)s.step(i,r,n);return s.ret}var{cdeDecodeOptions:go,dcborDecodeOptions:yo,defaultDecodeOptions:wo}=b;var S={encode(t){return D(t)},decode(t){return pt(t)}};import*as sr from"m1cro:pub-sub/host";var rn={publish:async(t,e,r)=>await sr.publish(t,e,r)},nn={async invokeEventHandler(t,e,r){let n=N.events[t]?.handler;if(!n)throw new Error(`Event handler not found for index ${t}`);let s=S.decode(r);await n.bind(N)(e,s)}};var $e={};F($e,{host:()=>sn});import*as or from"m1cro:sse/host";var sn={push:async(t,e)=>await or.push(t,e)};var on={};var ht=["trace","debug","info","warn","error","none"];var oe=t=>ht.indexOf(t)>=ht.indexOf(console.logLevel);Object.defineProperty(globalThis.console,"logLevel",{get(){return process.env.LOG_LEVEL||"info"}});var ie=console;globalThis.console={...globalThis.console,trace:(...t)=>{oe("trace")&&ie.trace("[TRACE]",...t)},debug:(...t)=>{oe("debug")&&ie.debug("[DEBUG]",...t)},info:(...t)=>{oe("info")&&ie.info("[INFO]",...t)},log:(...t)=>{oe("info")&&ie.log("[INFO]",...t)},warn:(...t)=>{oe("warn")&&ie.warn("[WARN]",...t)},error:(...t)=>{oe("error")&&ie.error("[ERROR]",...t)}};var ir=19*1024,ar=2,cr=1,dr=32,lt={deriveKey:(t,e)=>G.host.deriveKey(t,e),aesGcmEncrypt:t=>{let e=S.encode(t);return G.host.aesGcmEncrypt(e)},aesGcmDecrypt:t=>{let e=G.host.aesGcmDecrypt(t);return S.decode(e)},argon2Hash:(t,e,r)=>G.host.argon2Hash({tag:t},new TextEncoder().encode(e),r?.mCost??ir,r?.tCost??ar,r?.pCost??cr,r?.outputLen??dr),argon2Verify:(t,e,r,n)=>G.host.argon2Verify({tag:t},new TextEncoder().encode(e),new TextEncoder().encode(r),n?.mCost??ir,n?.tCost??ar,n?.pCost??cr,n?.outputLen??dr)};var M=class{constructor(e,r){this._entity=e;this._query=r}_limit;_offset;_sorting;query(){let e={filter:JSON.stringify(this._query),limit:this._limit,offset:this._offset,sorting:void 0};return this._sorting&&(e.sorting={rules:Object.entries(this._sorting).map(([r,n])=>[r,{tag:n}])}),e}};var be=class extends M{constructor(e,r){super(e,r)}limit(e){return this._limit=e,this}offset(e){return this._offset=e,this}sort(e){return this._sorting={...this._sorting,...e},this}async exec(){let e={entity:this._entity.name,query:this.query()},{docs:r}=await I.host.find(e);return r.map(n=>JSON.parse(n))}},Ge=class{_query;constructor(e,r){this._query=new be(e,r)}offset(e){return this._query.offset(e),this}sort(e){return this._query.sort(e),this}async exec(){return(await this._query.limit(1).exec())[0]}};var He=class t{constructor(e,r,n){this._entity=e;this._docs=r;this._returnMode=n}return(e){return new t(this._entity,this._docs,e)}async exec(){let e={entity:this._entity.name,docs:this._docs.map(n=>JSON.stringify(n)),returnType:{tag:"insertedIds"}};switch(this._returnMode){case"insertedIds":break;case"documents":e.returnType.tag="documents";break;default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let r=await I.host.insert(e);switch(r.tag){case"insertedIds":return r.value;case"documents":return r.value.map(o=>JSON.parse(o));default:throw new Error("Unexpected insert result",r)}}},Ce=class t{constructor(e,r,n){this._entity=e;this._doc=r;this._returnMode=n}return(e){return new t(this._entity,this._doc,e)}async exec(){let e={entity:this._entity.name,docs:[JSON.stringify(this._doc)],returnType:{tag:"insertedIds"}};switch(this._returnMode){case"insertedId":break;case"document":e.returnType.tag="documents";break;default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let r=await I.host.insert(e);switch(r.tag){case"insertedIds":let n=r.value[0];if(!n)throw new Error("Inserted ID is undefined");return n;case"documents":let s=r.value[0];if(!s)throw new Error("Document is undefined");return JSON.parse(s);default:throw new Error("Unexpected insertOne result",r)}}};var qe=class t extends M{constructor(r,n,s,i){super(r,n);this._update=s;this._returnMode=i}limit(r){return this._limit=r,this}offset(r){return this._offset=r,this}sort(r){return this._sorting={...this._sorting,...r},this}return(r){let n=new t(this._entity,this._query,this._update,r);return n._limit=this._limit,n._offset=this._offset,n._sorting=this._sorting,n}async exec(){let r={entity:this._entity.name,query:this.query(),update:JSON.stringify(this._update),upsert:!1,returnType:{tag:"affectedRows"}};switch(this._returnMode){case"affectedRows":case"oldDocuments":case"newDocuments":{r.returnType.tag=this._returnMode;break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.update(r);switch(n.tag){case"affectedRows":return n.value;case"documents":return n.value.map(o=>JSON.parse(o));default:throw new Error("Unexpected update result",n)}}},ze=class t extends M{constructor(r,n,s,i){super(r,n);this._update=s;this._returnMode=i}_upsert=!1;offset(r){return this._query.offset(r),this}sort(r){return this._query.sort(r),this}upsert(r){return this._upsert=r,this}return(r){let n=new t(this._entity,this._query,this._update,r);return n._limit=this._limit,n._offset=this._offset,n._sorting=this._sorting,n}async exec(){this._limit=1;let r={entity:this._entity.name,query:this.query(),update:JSON.stringify(this._update),upsert:this._upsert,returnType:{tag:"affectedRows"}};switch(this._returnMode){case"success":break;case"oldDocument":{r.returnType.tag="oldDocuments";break}case"newDocument":{r.returnType.tag="newDocuments";break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.update(r);switch(n.tag){case"affectedRows":return n.value===1;case"documents":{let s=n.value[0];return s?JSON.parse(s):void 0}default:throw new Error("Unexpected updateOne result",n)}}};var Ve=class t extends M{constructor(r,n,s){super(r,n);this._returnMode=s}limit(r){return this._limit=r,this}offset(r){return this._offset=r,this}sort(r){return this._sorting={...this._sorting,...r},this}return(r){let n=new t(this._entity,this._query,r);return n._limit=this._limit,n._offset=this._offset,n._sorting=this._sorting,n}async exec(){let r={entity:this._entity.name,query:this.query(),returnType:{tag:"affectedRows"}};switch(this._returnMode){case"affectedRows":case"documents":{r.returnType.tag=this._returnMode;break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.remove(r);switch(n.tag){case"affectedRows":return n.value;case"documents":return n.value.map(o=>JSON.parse(o));default:throw new Error("Unexpected remove result",n)}}},Ke=class t extends M{constructor(r,n,s){super(r,n);this._returnMode=s}offset(r){return this._query.offset(r),this}sort(r){return this._query.sort(r),this}return(r){let n=new t(this._entity,this._query,r);return n._offset=this._offset,n._sorting=this._sorting,n}async exec(){this._limit=1;let r={entity:this._entity.name,query:this.query(),returnType:{tag:"affectedRows"}};switch(this._returnMode){case"success":break;case"document":{r.returnType.tag="documents";break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.remove(r);switch(n.tag){case"affectedRows":return n.value===1;case"documents":{let s=n.value[0];return s?JSON.parse(s):void 0}default:throw new Error("Unexpected remove result",n)}}};var gt={entity:t=>new mt(t)},mt=class{constructor(e){this.name=e}find(e){return new be(this,e)}findOne(e){return new Ge(this,e)}insert(e){return new He(this,e,"insertedIds")}insertOne(e){return new Ce(this,e,"insertedId")}update(e,r){return new qe(this,e,r,"affectedRows")}updateOne(e,r){return new ze(this,e,r,"success")}remove(e){return new Ve(this,e,"affectedRows")}removeOne(e){return new Ke(this,e,"success")}};var yt={get:async t=>{let e=await J.host.get(t);return JSON.parse(e)},getDel:async t=>{let e=await J.host.getDel(t);return JSON.parse(e)},set:async(t,e,r)=>{let n={};return r&&(r.ttl&&(n.ttl=r.ttl),r.existenceCheck&&(n.existenceCheck={tag:r.existenceCheck})),await J.host.set(t,JSON.stringify(e),n)},delete:async t=>await J.host.delete(t)};var wt={async publish(t,e,r){let n=S.encode(e);r=r??["public"],await se.host.publish(t,n,r.map(s=>({tag:s})))}};var bt={async call(t,e){let r=O.fromRequest(new Request(t,e)),n=await O.host.call(r);return O.toResponse(n)},async get(t,e){return await this.call(t,{...e,method:"GET"})},async post(t,e){return await this.call(t,{...e,method:"POST",body:JSON.stringify(body)})},async put(t,e){return await this.call(t,{method:"PUT",body:JSON.stringify(e)})}};var Tt={push:async(t,e)=>{let r=S.encode(t);return await $e.host.push(r,e)}};var Et=class{#e=[];add(e){this.#e.push(e)}get get(){return this.#e}},Qe=class t{#e;#t;constructor(e=new Et,r="/"){this.#e=e,this.#t=this.#r(r)}get routes(){return this.#e.get}scope(e){let r=this.#t+this.#r(e);return new t(this.#e,r)}route(e,r,n,s){return r="/"+this.#t+"/"+this.#r(r),this.#e.add({method:e,path:r,handler:n,options:s}),this}get(e,r,n){return this.route("get",e,r,n)}post(e,r,n){return this.route("post",e,r,n)}put(e,r,n){return this.route("put",e,r,n)}patch(e,r,n){return this.route("patch",e,r,n)}delete(e,r,n){return this.route("delete",e,r,n)}#r(e){return e.replace(/^\/+/,"").replace(/\/+$/,"")}};var Ye=class{constructor(e,r,n,s,i,o){this.hooks=e;this.roles=r;this.capabilities=n;this.router=s;this.entities=i;this.events=o}crypto=Object.freeze(lt);kv=Object.freeze(yt);sse=Object.freeze(Tt);providers=Object.freeze({list(e){let r=$.host.listProviders(e);return[]}});async emit(e,...r){let n=this.hooks[e]||[];await Promise.all(n.map(s=>s.bind(this)(...r)))}get tenant(){return $.host.getTenant()}settings(){let e=Te.host.getSettings();return e?S.decode(e):void 0}crd(e){let r=$.host.getCrd(e);return r?S.decode(r):void 0}entity(e){return gt.entity(e)}async call(e,r){return await bt.call(e,r)}publish(e,r,n){wt.publish(e,r,n)}get manifest(){return{roles:this.roles.map(e=>{let r=e.type;if(r==="provider")return{tag:r,value:e.group};throw new Error(`Unknown role type: ${r}`)}),capabilities:Object.entries(this.capabilities).map(([e,r])=>[e,Array.from(r)]),functions:this.router.routes.map(e=>({method:{tag:e.method},path:e.path,timeoutMs:e.options?.timeoutMs??0,permissions:e.options?.permissions??[],authenticated:e.options?.authenticated??!1,visibility:{tag:e.options?.visibility??"public"}})),middlewares:[],jobs:[],entities:this.entities.map(e=>({name:e.name,schema:e.schema,indexes:e.indexes,scoped:!1})),events:this.events.map(({pattern:e})=>({pattern:e}))}}};var We=class{#e={};#t=[];#r={};#n=new Qe;#s=[];#o=[];on(e,r){return this.#e[e]||=[],this.#e[e].push(r),this}role(e){return this.#t.push(e),this}capability(e,r){return this.#r[e]||=new Set,r.forEach(n=>this.#r[e].add(n)),this}capabilities(e){return Object.entries(e).forEach(([r,n])=>this.capability(r,n)),this}routes(e){return e(this.#n),this}entity(e,r){let n={name:e,schema:new TextEncoder().encode(JSON.stringify(r)),indexes:[],scoped:!1};return this.#s.push(n),this}subscribe(e,r){return this.#o.push({pattern:e,handler:r}),this}build(){return new Ye(this.#e,this.#t,this.#r,this.#n,this.#s,this.#o)}};import cn from"@EntryPoint";var ur=new We;cn(ur);var N=ur.build(),Ti={};var Ei=$.guest;var Ri=se.guest;var Ii=O.guest;export{N as app,on as console,Ti as guest,Ei as"m1cro:common/guest",Ri as"m1cro:pub-sub/guest",Ii as"m1cro:rpc/guest"};
|
|
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 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")}},_=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 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 ii={};var ai=Z.guest;var ci=X.guest;var di=k.guest;export{ht as app,ii as guest,ai as"m1cro:common/guest",ci as"m1cro:pub-sub/guest",di as"m1cro:rpc/guest"};
|
package/package.json
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m1cro/js-bootstrap",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/bootstrap.js",
|
|
7
|
-
"wit/world.wit",
|
|
8
|
-
"wit/deps"
|
|
7
|
+
"dist/wit/world.wit",
|
|
8
|
+
"dist/wit/deps"
|
|
9
9
|
],
|
|
10
|
-
"publishConfig": {
|
|
11
|
-
"access": "public"
|
|
12
|
-
},
|
|
13
10
|
"scripts": {
|
|
14
|
-
"build": "
|
|
11
|
+
"build": "esbuild src/index.ts --bundle --minify --format=esm --platform=browser --tsconfig=tsconfig.json --outfile=dist/bootstrap.js --external:m1cro:* --external:@EntryPoint",
|
|
15
12
|
"fetch-wit-deps": "wkg wit fetch --config registries.wkg.toml",
|
|
16
13
|
"versioning": "yarn version --new-version",
|
|
17
|
-
"
|
|
14
|
+
"publish": "yarn publish --access public --non-interactive"
|
|
18
15
|
},
|
|
19
16
|
"devDependencies": {
|
|
20
17
|
"@types/json-schema": "^7.0.15",
|
|
21
|
-
"@types/node": "^25.2.0",
|
|
22
18
|
"esbuild": "^0.27.2"
|
|
23
19
|
}
|
|
24
|
-
}
|
|
20
|
+
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
package m1cro:app;
|
|
2
|
-
|
|
3
|
-
interface types {
|
|
4
|
-
record error {
|
|
5
|
-
status: u16,
|
|
6
|
-
code: string,
|
|
7
|
-
msg: option<string>,
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface host {
|
|
12
|
-
get-settings: func() -> option<list<u8>>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface guest {
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
world bindings {
|
|
19
|
-
import host;
|
|
20
|
-
import m1cro:common/types;
|
|
21
|
-
import m1cro:pub-sub/types;
|
|
22
|
-
import m1cro:rpc/types;
|
|
23
|
-
|
|
24
|
-
export guest;
|
|
25
|
-
export m1cro:common/guest;
|
|
26
|
-
export m1cro:pub-sub/guest;
|
|
27
|
-
export m1cro:rpc/guest;
|
|
28
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
package m1cro:common;
|
|
2
|
-
|
|
3
|
-
interface types {
|
|
4
|
-
record error {
|
|
5
|
-
status: u16,
|
|
6
|
-
code: string,
|
|
7
|
-
msg: option<string>,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
record tenant {
|
|
11
|
-
id: string,
|
|
12
|
-
eid: string,
|
|
13
|
-
host: string,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
variant method {
|
|
17
|
-
get,
|
|
18
|
-
post,
|
|
19
|
-
put,
|
|
20
|
-
patch,
|
|
21
|
-
delete,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
variant visibility {
|
|
25
|
-
private,
|
|
26
|
-
platform,
|
|
27
|
-
vendor,
|
|
28
|
-
public,
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
variant app-role {
|
|
32
|
-
provider(string),
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
record function-manifest {
|
|
36
|
-
method: method,
|
|
37
|
-
path: string,
|
|
38
|
-
timeout-ms: option<u64>,
|
|
39
|
-
permissions: list<string>,
|
|
40
|
-
authenticated: bool,
|
|
41
|
-
visibility: visibility,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
record middleware-manifest {
|
|
45
|
-
path: string,
|
|
46
|
-
priority: u16,
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
record job-manifest {
|
|
50
|
-
name: string,
|
|
51
|
-
timeout-ms: option<u64>,
|
|
52
|
-
schedule: option<string>,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
record entity-index-manifest {
|
|
56
|
-
unique: bool,
|
|
57
|
-
fields: list<string>,
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
record entity-manifest {
|
|
61
|
-
name: string,
|
|
62
|
-
schema: list<u8>,
|
|
63
|
-
indexes: list<entity-index-manifest>,
|
|
64
|
-
scoped: bool,
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
record event-manifest {
|
|
68
|
-
pattern: string,
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
record manifest {
|
|
72
|
-
roles: list<app-role>,
|
|
73
|
-
capabilities: list<tuple<string, list<string>>>,
|
|
74
|
-
functions: list<function-manifest>,
|
|
75
|
-
middlewares: list<middleware-manifest>,
|
|
76
|
-
jobs: list<job-manifest>,
|
|
77
|
-
entities: list<entity-manifest>,
|
|
78
|
-
events: list<event-manifest>,
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
interface host {
|
|
83
|
-
use types.{tenant};
|
|
84
|
-
|
|
85
|
-
get-tenant: func() -> tenant;
|
|
86
|
-
|
|
87
|
-
get-artifact: func(key: string) -> option<list<u8>>;
|
|
88
|
-
|
|
89
|
-
get-crd: func(key: string) -> option<list<u8>>;
|
|
90
|
-
|
|
91
|
-
list-providers: func(group: string) -> list<string>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
interface guest {
|
|
95
|
-
use types.{manifest, error};
|
|
96
|
-
|
|
97
|
-
get-manifest: func() -> result<manifest, error>;
|
|
98
|
-
|
|
99
|
-
start: func() -> result<_, error>;
|
|
100
|
-
|
|
101
|
-
install: func() -> result<_, error>;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
world bindings {
|
|
105
|
-
import types;
|
|
106
|
-
import host;
|
|
107
|
-
|
|
108
|
-
export guest;
|
|
109
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
package m1cro:crypto;
|
|
2
|
-
|
|
3
|
-
interface types {
|
|
4
|
-
record error {
|
|
5
|
-
status: u16,
|
|
6
|
-
code: string,
|
|
7
|
-
msg: option<string>,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
variant argon2-algorithm {
|
|
11
|
-
argon2d,
|
|
12
|
-
argon2i,
|
|
13
|
-
argon2id,
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface host {
|
|
18
|
-
use types.{error, argon2-algorithm};
|
|
19
|
-
|
|
20
|
-
derive-key: func(seed: string, length: u32) -> list<u8>;
|
|
21
|
-
|
|
22
|
-
aes-gcm-encrypt: func(data: list<u8>) -> result<list<u8>, error>;
|
|
23
|
-
|
|
24
|
-
aes-gcm-decrypt: func(data: list<u8>) -> result<list<u8>, error>;
|
|
25
|
-
|
|
26
|
-
argon2-hash: func(algorithm: argon2-algorithm, password: list<u8>, m-cost: u32, t-cost: u32, p-cost: u32, output-len: u64) -> result<string, error>;
|
|
27
|
-
|
|
28
|
-
argon2-verify: func(algorithm: argon2-algorithm, password: list<u8>, hash: string, m-cost: u32, t-cost: u32, p-cost: u32, output-len: u64) -> bool;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
world bindings {
|
|
32
|
-
import types;
|
|
33
|
-
import host;
|
|
34
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
package m1cro:entity;
|
|
2
|
-
|
|
3
|
-
interface types {
|
|
4
|
-
variant sort-direction {
|
|
5
|
-
asc,
|
|
6
|
-
desc,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
record sorting {
|
|
10
|
-
rules: list<tuple<string, sort-direction>>,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
record query {
|
|
14
|
-
filter: string,
|
|
15
|
-
limit: option<u64>,
|
|
16
|
-
offset: option<u64>,
|
|
17
|
-
sorting: option<sorting>,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
record find-options {
|
|
21
|
-
entity: string,
|
|
22
|
-
query: query,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
record find-result {
|
|
26
|
-
docs: list<string>,
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
variant insert-result {
|
|
30
|
-
inserted-ids(list<string>),
|
|
31
|
-
documents(list<string>),
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
variant insert-return-type {
|
|
35
|
-
inserted-ids,
|
|
36
|
-
documents,
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
record insert-options {
|
|
40
|
-
entity: string,
|
|
41
|
-
docs: list<string>,
|
|
42
|
-
return-type: insert-return-type,
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
variant update-result {
|
|
46
|
-
affected-rows(u64),
|
|
47
|
-
documents(list<string>),
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
variant update-return-type {
|
|
51
|
-
affected-rows,
|
|
52
|
-
old-documents,
|
|
53
|
-
new-documents,
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
record update-options {
|
|
57
|
-
entity: string,
|
|
58
|
-
query: query,
|
|
59
|
-
update: string,
|
|
60
|
-
upsert: bool,
|
|
61
|
-
return-type: update-return-type,
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
variant remove-result {
|
|
65
|
-
affected-rows(u64),
|
|
66
|
-
documents(list<string>),
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
variant remove-return-type {
|
|
70
|
-
affected-rows,
|
|
71
|
-
documents,
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
record remove-options {
|
|
75
|
-
entity: string,
|
|
76
|
-
query: query,
|
|
77
|
-
return-type: remove-return-type,
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
record invalid-format-error {
|
|
81
|
-
subject: string,
|
|
82
|
-
msg: string,
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
variant error {
|
|
86
|
-
db-unavailable,
|
|
87
|
-
db(string),
|
|
88
|
-
invalid-format(invalid-format-error),
|
|
89
|
-
resource-not-found,
|
|
90
|
-
entity-not-found(string),
|
|
91
|
-
other(string),
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
interface host {
|
|
96
|
-
use types.{error, find-options, find-result, insert-options, insert-result, update-options, update-result, remove-options, remove-result};
|
|
97
|
-
|
|
98
|
-
find: func(options: find-options) -> result<find-result, error>;
|
|
99
|
-
|
|
100
|
-
insert: func(options: insert-options) -> result<insert-result, error>;
|
|
101
|
-
|
|
102
|
-
update: func(options: update-options) -> result<update-result, error>;
|
|
103
|
-
|
|
104
|
-
remove: func(options: remove-options) -> result<remove-result, error>;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
world bindings {
|
|
108
|
-
import types;
|
|
109
|
-
import host;
|
|
110
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
package m1cro:kv;
|
|
2
|
-
|
|
3
|
-
interface types {
|
|
4
|
-
variant existence-check {
|
|
5
|
-
nx,
|
|
6
|
-
xx,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
record set-options {
|
|
10
|
-
ttl: option<u64>,
|
|
11
|
-
existence-check: option<existence-check>,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
variant error {
|
|
15
|
-
key-not-found(string),
|
|
16
|
-
server-error(string),
|
|
17
|
-
/// defined by redis
|
|
18
|
-
response-error(string),
|
|
19
|
-
parse-error(string),
|
|
20
|
-
authentication-failed(string),
|
|
21
|
-
type-error(string),
|
|
22
|
-
exec-abort-error(string),
|
|
23
|
-
busy-loading-error(string),
|
|
24
|
-
no-script-error(string),
|
|
25
|
-
invalid-client-config(string),
|
|
26
|
-
moved(string),
|
|
27
|
-
ask(string),
|
|
28
|
-
try-again(string),
|
|
29
|
-
cluster-down(string),
|
|
30
|
-
cross-slot(string),
|
|
31
|
-
master-down(string),
|
|
32
|
-
io-error(string),
|
|
33
|
-
client-error(string),
|
|
34
|
-
extension-error(string),
|
|
35
|
-
read-only(string),
|
|
36
|
-
master-name-not-found-by-sentinel(string),
|
|
37
|
-
no-valid-replicas-found-by-sentinel(string),
|
|
38
|
-
empty-sentinel-list(string),
|
|
39
|
-
not-busy(string),
|
|
40
|
-
cluster-connection-not-found(string),
|
|
41
|
-
no-sub(string),
|
|
42
|
-
resp3-not-supported(string),
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface host {
|
|
47
|
-
use types.{set-options, existence-check, error};
|
|
48
|
-
|
|
49
|
-
get: func(key: string) -> result<string, error>;
|
|
50
|
-
|
|
51
|
-
get-del: func(key: string) -> result<string, error>;
|
|
52
|
-
|
|
53
|
-
set: func(key: string, value: string, options: set-options) -> result<_, error>;
|
|
54
|
-
|
|
55
|
-
del: func(key: string) -> result<_, error>;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
world bindings {
|
|
59
|
-
import types;
|
|
60
|
-
import host;
|
|
61
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
package m1cro:log;
|
|
2
|
-
|
|
3
|
-
interface types {
|
|
4
|
-
variant log-level {
|
|
5
|
-
trace,
|
|
6
|
-
debug,
|
|
7
|
-
info,
|
|
8
|
-
warn,
|
|
9
|
-
error,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
variant error {
|
|
13
|
-
database-error(string),
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface host {
|
|
18
|
-
use types.{error, log-level};
|
|
19
|
-
|
|
20
|
-
log: func(level: log-level, msg: string);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
world bindings {
|
|
24
|
-
import types;
|
|
25
|
-
import host;
|
|
26
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
package m1cro:pub-sub;
|
|
2
|
-
|
|
3
|
-
interface types {
|
|
4
|
-
record error {
|
|
5
|
-
status: u16,
|
|
6
|
-
code: string,
|
|
7
|
-
msg: option<string>,
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface host {
|
|
12
|
-
use m1cro:common/types.{visibility};
|
|
13
|
-
|
|
14
|
-
publish: func(event: string, payload: list<u8>, visibility: list<visibility>);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface guest {
|
|
18
|
-
use types.{error};
|
|
19
|
-
|
|
20
|
-
invoke-event-handler: func(idx: u32, event: string, payload: list<u8>) -> result<_, error>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
world bindings {
|
|
24
|
-
import m1cro:common/types;
|
|
25
|
-
import host;
|
|
26
|
-
import types;
|
|
27
|
-
|
|
28
|
-
export guest;
|
|
29
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
package m1cro:rpc;
|
|
2
|
-
|
|
3
|
-
interface types {
|
|
4
|
-
use m1cro:common/types.{method};
|
|
5
|
-
|
|
6
|
-
record error {
|
|
7
|
-
status: u16,
|
|
8
|
-
code: string,
|
|
9
|
-
msg: option<string>,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
resource request {
|
|
13
|
-
constructor();
|
|
14
|
-
get-method: func() -> method;
|
|
15
|
-
set-method: func(method: method);
|
|
16
|
-
get-url: func() -> string;
|
|
17
|
-
set-url: func(url: string);
|
|
18
|
-
get-header: func(name: string) -> option<string>;
|
|
19
|
-
get-headers: func() -> list<tuple<string, string>>;
|
|
20
|
-
get-all-headers: func(name: string) -> list<string>;
|
|
21
|
-
insert-header: func(name: string, value: string);
|
|
22
|
-
append-header: func(name: string, value: string);
|
|
23
|
-
set-headers: func(headers: list<tuple<string, string>>);
|
|
24
|
-
get-cookie: func(name: string) -> option<cookie>;
|
|
25
|
-
set-cookie: func(cookie: cookie);
|
|
26
|
-
get-param: func(key: string) -> option<string>;
|
|
27
|
-
get-params: func() -> list<tuple<string, string>>;
|
|
28
|
-
set-param: func(key: string, value: string);
|
|
29
|
-
set-params: func(params: list<tuple<string, string>>);
|
|
30
|
-
get-body: func() -> list<u8>;
|
|
31
|
-
set-body: func(body: list<u8>);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
resource response {
|
|
35
|
-
constructor();
|
|
36
|
-
get-status: func() -> u16;
|
|
37
|
-
set-status: func(status: u16);
|
|
38
|
-
get-header: func(name: string) -> option<string>;
|
|
39
|
-
get-headers: func() -> list<tuple<string, string>>;
|
|
40
|
-
get-all-headers: func(name: string) -> list<string>;
|
|
41
|
-
insert-header: func(name: string, value: string);
|
|
42
|
-
append-header: func(name: string, value: string);
|
|
43
|
-
set-headers: func(headers: list<tuple<string, string>>);
|
|
44
|
-
get-cookie: func(name: string) -> option<cookie>;
|
|
45
|
-
set-cookie: func(cookie: cookie);
|
|
46
|
-
get-body: func() -> list<u8>;
|
|
47
|
-
set-body: func(body: list<u8>);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
variant cookie-expiration {
|
|
51
|
-
timestamp(u64),
|
|
52
|
-
session,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
variant same-site {
|
|
56
|
-
strict,
|
|
57
|
-
lax,
|
|
58
|
-
none,
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
record cookie-options {
|
|
62
|
-
domain: option<string>,
|
|
63
|
-
expires: option<cookie-expiration>,
|
|
64
|
-
http-only: option<bool>,
|
|
65
|
-
max-age: option<u64>,
|
|
66
|
-
partitioned: option<bool>,
|
|
67
|
-
path: option<string>,
|
|
68
|
-
same-site: option<same-site>,
|
|
69
|
-
secure: option<bool>,
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
record cookie {
|
|
73
|
-
name: string,
|
|
74
|
-
data: string,
|
|
75
|
-
options: cookie-options,
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
variant request-source {
|
|
79
|
-
external,
|
|
80
|
-
app(string),
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
interface host {
|
|
85
|
-
use types.{error, request, response};
|
|
86
|
-
|
|
87
|
-
call: func(req: request) -> result<response, error>;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
interface guest {
|
|
91
|
-
use types.{error, request, response, request-source};
|
|
92
|
-
|
|
93
|
-
call: func(idx: u32, middlewares: list<u32>, req: request, source: request-source) -> result<response, error>;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
world bindings {
|
|
97
|
-
import m1cro:common/types;
|
|
98
|
-
import types;
|
|
99
|
-
import host;
|
|
100
|
-
|
|
101
|
-
export guest;
|
|
102
|
-
}
|
package/wit/world.wit
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
package m1cro:runtime;
|
|
2
|
-
|
|
3
|
-
world facilities {
|
|
4
|
-
include m1cro:common/bindings;
|
|
5
|
-
include m1cro:crypto/bindings;
|
|
6
|
-
include m1cro:entity/bindings;
|
|
7
|
-
include m1cro:kv/bindings;
|
|
8
|
-
include m1cro:log/bindings;
|
|
9
|
-
include m1cro:pub-sub/bindings;
|
|
10
|
-
include m1cro:rpc/bindings;
|
|
11
|
-
include m1cro:sse/bindings;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
world app {
|
|
15
|
-
// import wasi:cli/environment@0.2.9;
|
|
16
|
-
include facilities;
|
|
17
|
-
include m1cro:app/bindings;
|
|
18
|
-
}
|