@m1cro/js-bootstrap 0.1.0-beta.10 → 0.1.0-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bootstrap.js CHANGED
@@ -10,4 +10,4 @@ ${nt.repeat(i.depth)}}`:i.close="}";break}case c.TAG:o+=String(f),o+=H(c.POS_INT
10
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
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},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"};
13
+ `,u+=d,u},it.noChildren=!0,p.registerDecoder(l.CBOR,it),p.registerDecoder(l.URI,t=>(V(t.contents),new URL(t.contents)),"URI"),b(URL,t=>[l.URI,t.toString()]),p.registerDecoder(l.BASE64URL,t=>(V(t.contents),Et(t.contents)),"Base64url-encoded"),p.registerDecoder(l.BASE64,t=>(V(t.contents),ue(t.contents)),"Base64-encoded"),p.registerDecoder(35,t=>(V(t.contents),new RegExp(t.contents)),"RegExp"),p.registerDecoder(21065,t=>{V(t.contents);let e=`^(?:${t.contents})$`;return new RegExp(e,"u")},"I-RegExp"),p.registerDecoder(l.REGEXP,t=>{if(Yt(t.contents),t.contents.length<1||t.contents.length>2)throw new Error(`Invalid RegExp Array: ${t.contents}`);return new RegExp(t.contents[0],t.contents[1])},"RegExp"),b(RegExp,t=>[l.REGEXP,[t.source,t.flags]]),p.registerDecoder(64,t=>(M(t.contents),t.contents),"uint8 Typed Array");function T(t,e,r){M(t.contents);let n=t.contents.length;if(n%e.BYTES_PER_ELEMENT!==0)throw new Error(`Number of bytes must be divisible by ${e.BYTES_PER_ELEMENT}, got: ${n}`);n/=e.BYTES_PER_ELEMENT;let s=new e(n),i=new DataView(t.contents.buffer,t.contents.byteOffset,t.contents.byteLength),o=i[`get${e.name.replace(/Array/,"")}`].bind(i);for(let a=0;a<n;a++)s[a]=o(a*e.BYTES_PER_ELEMENT,r);return s}function z(t,e,r,n,s){let i=s.forceEndian??Ct;if(ne(i?e:r,t,s),R(n.byteLength,t,c.BYTE_STRING),Ct===i)t.write(new Uint8Array(n.buffer,n.byteOffset,n.byteLength));else{let o=`write${n.constructor.name.replace(/Array/,"")}`,a=t[o].bind(t);for(let d of n)a(d,i)}}p.registerDecoder(65,t=>T(t,Uint16Array,!1),"uint16, big endian, Typed Array"),p.registerDecoder(66,t=>T(t,Uint32Array,!1),"uint32, big endian, Typed Array"),p.registerDecoder(67,t=>T(t,BigUint64Array,!1),"uint64, big endian, Typed Array"),p.registerDecoder(68,t=>(M(t.contents),new Uint8ClampedArray(t.contents)),"uint8 Typed Array, clamped arithmetic"),b(Uint8ClampedArray,t=>[68,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)]),p.registerDecoder(69,t=>T(t,Uint16Array,!0),"uint16, little endian, Typed Array"),b(Uint16Array,(t,e,r)=>z(e,69,65,t,r)),p.registerDecoder(70,t=>T(t,Uint32Array,!0),"uint32, little endian, Typed Array"),b(Uint32Array,(t,e,r)=>z(e,70,66,t,r)),p.registerDecoder(71,t=>T(t,BigUint64Array,!0),"uint64, little endian, Typed Array"),b(BigUint64Array,(t,e,r)=>z(e,71,67,t,r)),p.registerDecoder(72,t=>(M(t.contents),new Int8Array(t.contents)),"sint8 Typed Array"),b(Int8Array,t=>[72,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)]),p.registerDecoder(73,t=>T(t,Int16Array,!1),"sint16, big endian, Typed Array"),p.registerDecoder(74,t=>T(t,Int32Array,!1),"sint32, big endian, Typed Array"),p.registerDecoder(75,t=>T(t,BigInt64Array,!1),"sint64, big endian, Typed Array"),p.registerDecoder(77,t=>T(t,Int16Array,!0),"sint16, little endian, Typed Array"),b(Int16Array,(t,e,r)=>z(e,77,73,t,r)),p.registerDecoder(78,t=>T(t,Int32Array,!0),"sint32, little endian, Typed Array"),b(Int32Array,(t,e,r)=>z(e,78,74,t,r)),p.registerDecoder(79,t=>T(t,BigInt64Array,!0),"sint64, little endian, Typed Array"),b(BigInt64Array,(t,e,r)=>z(e,79,75,t,r)),p.registerDecoder(81,t=>T(t,Float32Array,!1),"IEEE 754 binary32, big endian, Typed Array"),p.registerDecoder(82,t=>T(t,Float64Array,!1),"IEEE 754 binary64, big endian, Typed Array"),p.registerDecoder(85,t=>T(t,Float32Array,!0),"IEEE 754 binary32, little endian, Typed Array"),b(Float32Array,(t,e,r)=>z(e,85,81,t,r)),p.registerDecoder(86,t=>T(t,Float64Array,!0),"IEEE 754 binary64, big endian, Typed Array"),b(Float64Array,(t,e,r)=>z(e,86,82,t,r)),p.registerDecoder(l.SET,(t,e)=>{if(Yt(t.contents),e.sortKeys){let r=w.decodeToEncodeOpts(e),n=null;for(let s of t.contents){let i=[s,void 0,v(s,r)];if(n&&e.sortKeys(n,i)>=0)throw new Error(`Set items out of order in tag #${l.SET}`);n=i}}return new Set(t.contents)},"Set"),b(Set,(t,e,r)=>{let n=[...t];if(r.sortKeys){let s=n.map(i=>[i,void 0,v(i,r)]);s.sort(r.sortKeys),n=s.map(([i])=>i)}return[l.SET,n]}),p.registerDecoder(l.JSON,t=>(V(t.contents),JSON.parse(t.contents)),"JSON-encoded");function Kt(t){return M(t.contents),new Y().decode(t.contents)}Kt.comment=t=>{M(t.contents);let e=new Y;return`(WTF8 string): ${JSON.stringify(e.decode(t.contents))}`},p.registerDecoder(l.WTF8,Kt),p.registerDecoder(l.SELF_DESCRIBED,t=>t.contents,"Self-Described"),p.registerDecoder(l.INVALID_16,()=>{throw new Error(`Tag always invalid: ${l.INVALID_16}`)},"Invalid"),p.registerDecoder(l.INVALID_32,()=>{throw new Error(`Tag always invalid: ${l.INVALID_32}`)},"Invalid"),p.registerDecoder(l.INVALID_64,()=>{throw new Error(`Tag always invalid: ${l.INVALID_64}`)},"Invalid");function at(t){throw new Error(`Encoding ${t.constructor.name} intentionally unimplmented. It is not concrete enough to interoperate. Convert to Uint8Array first.`)}b(ArrayBuffer,at),b(DataView,at),typeof SharedArrayBuffer<"u"&&b(SharedArrayBuffer,at);function Fe(t){return[NaN,t.valueOf()]}b(Boolean,Fe),b(Number,Fe),b(String,Fe),b(BigInt,Fe);function en(t){let e={...w.defaultDecodeOptions};if(t.dcbor?Object.assign(e,w.dcborDecodeOptions):t.cde&&Object.assign(e,w.cdeDecodeOptions),Object.assign(e,t),Object.hasOwn(e,"rejectLongNumbers"))throw new TypeError("rejectLongNumbers has changed to requirePreferred");return e.boxed&&(e.saveOriginal=!0),e}var dt=class{parent=void 0;ret=void 0;step(e,r,n){if(this.ret=w.create(e,this.parent,r,n),e[2]===y.BREAK)if(this.parent?.isStreaming)this.parent.left=0;else throw new Error("Unexpected BREAK");else this.parent&&this.parent.push(this.ret,n,e[3]);for(this.ret instanceof w&&(this.parent=this.ret);this.parent?.done;){this.ret=this.parent.convert(n);let s=this.parent.parent;s?.replaceLast(this.ret,this.parent,n),this.parent=s}}};function ut(t,e={}){let r=en(e),n=new U(t,r),s=new dt;for(let i of n)s.step(i,r,n);return s.ret}var{cdeDecodeOptions:lo,dcborDecodeOptions:mo,defaultDecodeOptions:go}=w;var J={encode:t=>v(t),decode:t=>ut(t)};var Wt=19*1024,Jt=2,Zt=1,Xt=32,er={deriveKey:(t,e)=>P.host.deriveKey(t,e),aesGcmEncrypt:t=>{let e=J.encode(t);return P.host.aesGcmEncrypt(e)},aesGcmDecrypt:t=>{let e=P.host.aesGcmDecrypt(t);return J.decode(e)},argon2Hash:(t,e,r)=>P.host.argon2Hash({tag:t},new TextEncoder().encode(e),r?.mCost??Wt,r?.tCost??Jt,r?.pCost??Zt,r?.outputLen??Xt),argon2Verify:(t,e,r,n)=>P.host.argon2Verify({tag:t},new TextEncoder().encode(e),new TextEncoder().encode(r),n?.mCost??Wt,n?.tCost??Jt,n?.pCost??Zt,n?.outputLen??Xt)};var _=class{constructor(e,r){this._entity=e;this._query=r}_limit;_offset;_sorting;query(){let e={filter:JSON.stringify(this._query),limit:this._limit,offset:this._offset,sorting:void 0};return this._sorting&&(e.sorting={rules:Object.entries(this._sorting).map(([r,n])=>[r,{tag:n}])}),e}};var we=class extends _{constructor(e,r){super(e,r)}limit(e){return this._limit=e,this}offset(e){return this._offset=e,this}sort(e){return this._sorting={...this._sorting,...e},this}async exec(){let e={entity:this._entity.name,query:this.query()},{docs:r}=await I.host.find(e);return r.map(n=>JSON.parse(n))}},je=class{_query;constructor(e,r){this._query=new we(e,r)}offset(e){return this._query.offset(e),this}sort(e){return this._query.sort(e),this}async exec(){return(await this._query.limit(1).exec())[0]}};var qe=class t{constructor(e,r,n){this._entity=e;this._docs=r;this._returnMode=n}return(e){return new t(this._entity,this._docs,e)}async exec(){let e={entity:this._entity.name,docs:this._docs.map(n=>JSON.stringify(n)),returnType:{tag:"insertedIds"}};switch(this._returnMode){case"insertedIds":break;case"documents":e.returnType.tag="documents";break;default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let r=await I.host.insert(e);switch(r.tag){case"insertedIds":return r.value;case"documents":return r.value.map(o=>JSON.parse(o));default:throw new Error("Unexpected insert result",r)}}},Ge=class t{constructor(e,r,n){this._entity=e;this._doc=r;this._returnMode=n}return(e){return new t(this._entity,this._doc,e)}async exec(){let e={entity:this._entity.name,docs:[JSON.stringify(this._doc)],returnType:{tag:"insertedIds"}};switch(this._returnMode){case"insertedId":break;case"document":e.returnType.tag="documents";break;default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let r=await I.host.insert(e);switch(r.tag){case"insertedIds":let n=r.value[0];if(!n)throw new Error("Inserted ID is undefined");return n;case"documents":let s=r.value[0];if(!s)throw new Error("Document is undefined");return JSON.parse(s);default:throw new Error("Unexpected insertOne result",r)}}};var Ce=class t extends _{constructor(r,n,s,i){super(r,n);this._update=s;this._returnMode=i}limit(r){return this._limit=r,this}offset(r){return this._offset=r,this}sort(r){return this._sorting={...this._sorting,...r},this}return(r){let n=new t(this._entity,this._query,this._update,r);return n._limit=this._limit,n._offset=this._offset,n._sorting=this._sorting,n}async exec(){let r={entity:this._entity.name,query:this.query(),update:JSON.stringify(this._update),upsert:!1,returnType:{tag:"affectedRows"}};switch(this._returnMode){case"affectedRows":case"oldDocuments":case"newDocuments":{r.returnType.tag=this._returnMode;break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.update(r);switch(n.tag){case"affectedRows":return n.value;case"documents":return n.value.map(o=>JSON.parse(o));default:throw new Error("Unexpected update result",n)}}},He=class t extends _{constructor(r,n,s,i){super(r,n);this._update=s;this._returnMode=i}_upsert=!1;offset(r){return this._query.offset(r),this}sort(r){return this._query.sort(r),this}upsert(r){return this._upsert=r,this}return(r){let n=new t(this._entity,this._query,this._update,r);return n._limit=this._limit,n._offset=this._offset,n._sorting=this._sorting,n}async exec(){this._limit=1;let r={entity:this._entity.name,query:this.query(),update:JSON.stringify(this._update),upsert:this._upsert,returnType:{tag:"affectedRows"}};switch(this._returnMode){case"success":break;case"oldDocument":{r.returnType.tag="oldDocuments";break}case"newDocument":{r.returnType.tag="newDocuments";break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.update(r);switch(n.tag){case"affectedRows":return n.value===1;case"documents":{let s=n.value[0];return s?JSON.parse(s):void 0}default:throw new Error("Unexpected updateOne result",n)}}};var ze=class t extends _{constructor(r,n,s){super(r,n);this._returnMode=s}limit(r){return this._limit=r,this}offset(r){return this._offset=r,this}sort(r){return this._sorting={...this._sorting,...r},this}return(r){let n=new t(this._entity,this._query,r);return n._limit=this._limit,n._offset=this._offset,n._sorting=this._sorting,n}async exec(){let r={entity:this._entity.name,query:this.query(),returnType:{tag:"affectedRows"}};switch(this._returnMode){case"affectedRows":case"documents":{r.returnType.tag=this._returnMode;break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.remove(r);switch(n.tag){case"affectedRows":return n.value;case"documents":return n.value.map(o=>JSON.parse(o));default:throw new Error("Unexpected remove result",n)}}},Ve=class t extends _{constructor(r,n,s){super(r,n);this._returnMode=s}offset(r){return this._query.offset(r),this}sort(r){return this._query.sort(r),this}return(r){let n=new t(this._entity,this._query,r);return n._offset=this._offset,n._sorting=this._sorting,n}async exec(){this._limit=1;let r={entity:this._entity.name,query:this.query(),returnType:{tag:"affectedRows"}};switch(this._returnMode){case"success":break;case"document":{r.returnType.tag="documents";break}default:throw new Error(`Invalid return mode: ${this._returnMode}`)}let n=await I.host.remove(r);switch(n.tag){case"affectedRows":return n.value===1;case"documents":{let s=n.value[0];return s?JSON.parse(s):void 0}default:throw new Error("Unexpected remove result",n)}}};var tr={entity:t=>new ft(t)},ft=class{constructor(e){this.name=e}find(e){return new we(this,e)}findOne(e){return new je(this,e)}insert(e){return new qe(this,e,"insertedIds")}insertOne(e){return new Ge(this,e,"insertedId")}update(e,r){return new Ce(this,e,r,"affectedRows")}updateOne(e,r){return new He(this,e,r,"success")}remove(e){return new ze(this,e,"affectedRows")}removeOne(e){return new Ve(this,e,"success")}};var rr={publish:async(t,e,r)=>{let n=J.encode(e);return r=r??["public"],await X.host.publish(t,n,r.map(s=>({tag:s})))}};var nr={get:async t=>{let e=await K.host.get(t);return JSON.parse(e)},getDel:async t=>{let e=await K.host.getDel(t);return JSON.parse(e)},set:async(t,e,r)=>{let n={};return r&&(r.ttl&&(n.ttl=r.ttl),r.existenceCheck&&(n.existenceCheck={tag:r.existenceCheck})),await K.host.set(t,JSON.stringify(e),n)},delete:async t=>await K.host.delete(t)};var sr={call:async(t,e)=>{let r=k.fromRequest(new Request(t,e)),n=await k.host.call(r);return k.toResponse(n)}};var or={push:async(t,e)=>{let r=J.encode(t);return await Ee.host.push(r,e)}};var ht=new Re(rn),se=(t,e)=>Object.defineProperty(globalThis,t,{value:Object.freeze(e),enumerable:!1,configurable:!1,writable:!1});se("$crypto",er);se("$db",tr);se("$event",rr);se("$kv",nr);se("$rpc",sr);se("$sse",or);var ni={};var si=Z.guest;var oi=X.guest;var ii=k.guest;export{ht as app,ni as guest,si as"m1cro:common/guest",oi as"m1cro:pub-sub/guest",ii as"m1cro:rpc/guest"};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m1cro/js-bootstrap",
3
- "version": "0.1.0-beta.10",
3
+ "version": "0.1.0-beta.12",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist/bootstrap.js",
@@ -8,7 +8,7 @@
8
8
  "wit/deps"
9
9
  ],
10
10
  "scripts": {
11
- "build": "esbuild src/index.ts --bundle --minify --format=esm --platform=browser --tsconfig=tsconfig.json --outfile=dist/bootstrap.js --external:m1cro:* --external:@EntryPoint",
11
+ "build": "yarn fetch-wit-deps && esbuild src/index.ts --bundle --minify --format=esm --platform=browser --tsconfig=tsconfig.json --outfile=dist/bootstrap.js --external:m1cro:* --external:@EntryPoint",
12
12
  "fetch-wit-deps": "wkg wit fetch --config registries.wkg.toml",
13
13
  "versioning": "yarn version --new-version",
14
14
  "deploy": "yarn publish --access public --non-interactive"
@@ -95,13 +95,13 @@ interface types {
95
95
  interface host {
96
96
  use types.{error, find-options, find-result, insert-options, insert-result, update-options, update-result, remove-options, remove-result};
97
97
 
98
- find: async func(options: find-options) -> result<find-result, error>;
98
+ find: func(options: find-options) -> result<find-result, error>;
99
99
 
100
- insert: async func(options: insert-options) -> result<insert-result, error>;
100
+ insert: func(options: insert-options) -> result<insert-result, error>;
101
101
 
102
- update: async func(options: update-options) -> result<update-result, error>;
102
+ update: func(options: update-options) -> result<update-result, error>;
103
103
 
104
- remove: async func(options: remove-options) -> result<remove-result, error>;
104
+ remove: func(options: remove-options) -> result<remove-result, error>;
105
105
  }
106
106
 
107
107
  world bindings {