toilscript 0.1.26 → 0.1.28

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/cli.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * SPDX-License-Identifier: Apache-2.0
6
6
  */
7
7
  var se=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames;var Me=Object.prototype.hasOwnProperty;var fn=(e,t)=>()=>(e&&(t=e(e=0)),t);var nn=(e,t)=>{for(var n in t)se(e,n,{get:t[n],enumerable:!0})},oe=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ue(t))!Me.call(e,s)&&s!==n&&se(e,s,{get:()=>t[s],enumerable:!(o=Ne(t,s))||o.enumerable});return e},Dn=(e,t,n)=>(oe(e,t,"default"),n&&oe(n,t,"default"));var le={};nn(le,{promises:()=>Pe});var Pe,ue=fn(()=>{"use strict";Pe={}});var fe={};nn(fe,{createRequire:()=>Ve});function Ve(){return function(t){throw new Error(`Cannot find module: '${t}'`)}}var ce=fn(()=>{"use strict"});var On={};nn(On,{argv:()=>He,cwd:()=>In,exit:()=>Ke,hrtime:()=>qe,platform:()=>Ge,umask:()=>je});function In(){return"."}function je(){return 0}function Ke(e=0){throw Error(`exit ${e}`)}function qe(e){var t=Xe.call(de),n=Math.floor(t*.001),o=Math.floor(t*1e6-n*1e9);return e&&(n-=e[0],o-=e[1],o<0&&(n--,o+=1e9)),[n,o]}var Ge,He,de,Xe,Ln=fn(()=>{"use strict";Ge="linux";He=[];de=globalThis.performance||{},Xe=de.now||function(){return new Date().getTime()}});var Rn={};nn(Rn,{basename:()=>Qe,delimiter:()=>it,dirname:()=>$e,extname:()=>nt,format:()=>et,isAbsolute:()=>Ye,join:()=>Je,normalize:()=>xe,parse:()=>tt,relative:()=>Ze,resolve:()=>cn,sep:()=>kn,win32:()=>rt});function V(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function pe(e,t){for(var n="",o=0,s=-1,r=0,u,f=0;f<=e.length;++f){if(f<e.length)u=e.charCodeAt(f);else{if(u===47)break;u=47}if(u===47){if(!(s===f-1||r===1))if(s!==f-1&&r===2){if(n.length<2||o!==2||n.charCodeAt(n.length-1)!==46||n.charCodeAt(n.length-2)!==46){if(n.length>2){var x=n.lastIndexOf("/");if(x!==n.length-1){x===-1?(n="",o=0):(n=n.slice(0,x),o=n.length-1-n.lastIndexOf("/")),s=f,r=0;continue}}else if(n.length===2||n.length===1){n="",o=0,s=f,r=0;continue}}t&&(n.length>0?n+="/..":n="..",o=2)}else n.length>0?n+="/"+e.slice(s+1,f):n=e.slice(s+1,f),o=f-s-1;s=f,r=0}else u===46&&r!==-1?++r:r=-1}return n}function We(e,t){var n=t.dir||t.root,o=t.base||(t.name||"")+(t.ext||"");return n?n===t.root?n+o:n+e+o:o}function cn(){for(var e="",t=!1,n,o=arguments.length-1;o>=-1&&!t;o--){var s;o>=0?s=arguments[o]:(n===void 0&&(n=In()),s=n),V(s),s.length!==0&&(e=s+"/"+e,t=s.charCodeAt(0)===47)}return e=pe(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."}function xe(e){if(V(e),e.length===0)return".";var t=e.charCodeAt(0)===47,n=e.charCodeAt(e.length-1)===47;return e=pe(e,!t),e.length===0&&!t&&(e="."),e.length>0&&n&&(e+="/"),t?"/"+e:e}function Ye(e){return V(e),e.length>0&&e.charCodeAt(0)===47}function Je(){if(arguments.length===0)return".";for(var e,t=0;t<arguments.length;++t){var n=arguments[t];V(n),n.length>0&&(e===void 0?e=n:e+="/"+n)}return e===void 0?".":xe(e)}function Ze(e,t){if(V(e),V(t),e===t||(e=cn(e),t=cn(t),e===t))return"";if(e===".")return t;for(var n=1;n<e.length&&e.charCodeAt(n)===47;++n);for(var o=e.length,s=o-n,r=1;r<t.length&&t.charCodeAt(r)===47;++r);for(var u=t.length,f=u-r,x=s<f?s:f,b=-1,d=0;d<=x;++d){if(d===x){if(f>x){if(t.charCodeAt(r+d)===47)return t.slice(r+d+1);if(d===0)return t.slice(r+d)}else s>x&&(e.charCodeAt(n+d)===47?b=d:d===0&&(b=0));break}var g=e.charCodeAt(n+d),y=t.charCodeAt(r+d);if(g!==y)break;g===47&&(b=d)}var m="";for(d=n+b+1;d<=o;++d)(d===o||e.charCodeAt(d)===47)&&(m.length===0?m+="..":m+="/..");return m.length>0?m+t.slice(r+b):(r+=b,t.charCodeAt(r)===47&&++r,t.slice(r))}function $e(e){if(V(e),e.length===0)return".";for(var t=e.charCodeAt(0),n=t===47,o=-1,s=!0,r=e.length-1;r>=1;--r)if(t=e.charCodeAt(r),t===47){if(!s){o=r;break}}else s=!1;return o===-1?n?"/":".":n&&o===1?"//":e.slice(0,o)}function Qe(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');V(e);var n=0,o=-1,s=!0,r;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var u=t.length-1,f=-1;for(r=e.length-1;r>=0;--r){var x=e.charCodeAt(r);if(x===47){if(!s){n=r+1;break}}else f===-1&&(s=!1,f=r+1),u>=0&&(x===t.charCodeAt(u)?--u===-1&&(o=r):(u=-1,o=f))}return n===o?o=f:o===-1&&(o=e.length),e.slice(n,o)}else{for(r=e.length-1;r>=0;--r)if(e.charCodeAt(r)===47){if(!s){n=r+1;break}}else o===-1&&(s=!1,o=r+1);return o===-1?"":e.slice(n,o)}}function nt(e){V(e);for(var t=-1,n=0,o=-1,s=!0,r=0,u=e.length-1;u>=0;--u){var f=e.charCodeAt(u);if(f===47){if(!s){n=u+1;break}continue}o===-1&&(s=!1,o=u+1),f===46?t===-1?t=u:r!==1&&(r=1):t!==-1&&(r=-1)}return t===-1||o===-1||r===0||r===1&&t===o-1&&t===n+1?"":e.slice(t,o)}function et(e){if(e===null||typeof e!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return We("/",e)}function tt(e){V(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return t;var n=e.charCodeAt(0),o=n===47,s;o?(t.root="/",s=1):s=0;for(var r=-1,u=0,f=-1,x=!0,b=e.length-1,d=0;b>=s;--b){if(n=e.charCodeAt(b),n===47){if(!x){u=b+1;break}continue}f===-1&&(x=!1,f=b+1),n===46?r===-1?r=b:d!==1&&(d=1):r!==-1&&(d=-1)}return r===-1||f===-1||d===0||d===1&&r===f-1&&r===u+1?f!==-1&&(u===0&&o?t.base=t.name=e.slice(1,f):t.base=t.name=e.slice(u,f)):(u===0&&o?(t.name=e.slice(1,r),t.base=e.slice(1,f)):(t.name=e.slice(u,r),t.base=e.slice(u,f)),t.ext=e.slice(r,f)),u>0?t.dir=e.slice(0,u-1):o&&(t.dir="/"),t}var kn,it,rt,Nn=fn(()=>{"use strict";Ln();kn="/",it=":",rt=null});var he={};nn(he,{pathToFileURL:()=>ot});function at(e){return e.replace(/%/g,"%25").replace(/\\/g,"%5C").replace(/\n/g,"%0A").replace(/\r/g,"%0D").replace(/\t/g,"%09")}function ot(e){let t=cn(e);e.charCodeAt(e.length-1)===47&&t[t.length-1]!==kn&&(t+="/");let n=new URL("file://");return n.pathname=at(t),n}var ge=fn(()=>{"use strict";Nn()});var Wn={};nn(Wn,{Stats:()=>Cn,checkDiagnostics:()=>gn,compileString:()=>wt,configToArguments:()=>qn,createMemoryStream:()=>Kn,default:()=>Wn,defaultOptimizeLevel:()=>Se,defaultShrinkLevel:()=>we,definitionFiles:()=>St,libraryFiles:()=>H,libraryPrefix:()=>P,main:()=>Be,options:()=>zt,tscOptions:()=>Bt,version:()=>Hn});var st=Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]",j,sn,F,M,dn;st?(j=await import("fs"),sn=await import("module"),F=await import("path"),M=globalThis.process,dn=await import("url")):(j=await Promise.resolve().then(()=>(ue(),le)),sn=await Promise.resolve().then(()=>(ce(),fe)),F=await Promise.resolve().then(()=>(Nn(),Rn)),M=await Promise.resolve().then(()=>(Ln(),On)),dn=await Promise.resolve().then(()=>(ge(),he)));var An=typeof process<"u"&&process||{},lt=An.env&&"CI"in An.env,ut="\x1B[90m",ft="\x1B[91m",ct="\x1B[92m",dt="\x1B[93m",pt="\x1B[94m",xt="\x1B[95m",ht="\x1B[96m",gt="\x1B[97m",W="\x1B[0m",en=class{constructor(t){this.stream=t,this.enabled=!!(this.stream&&this.stream.isTTY||lt)}gray(t){return this.enabled?ut+t+W:t}red(t){return this.enabled?ft+t+W:t}green(t){return this.enabled?ct+t+W:t}yellow(t){return this.enabled?dt+t+W:t}blue(t){return this.enabled?pt+t+W:t}magenta(t){return this.enabled?xt+t+W:t}cyan(t){return this.enabled?ht+t+W:t}white(t){return this.enabled?gt+t+W:t}},_n=new en(An.stdout),Ot=new en(An.stderr);function mt(e){for(var t=0,n=0,o=e.length;n<o;++n){let s=e.charCodeAt(n);s<128?t+=1:s<2048?t+=2:(s&64512)===55296&&n+1<o&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3}return t}function bt(e,t,n){var o=n-t;if(o<1)return"";for(var s=null,r=[],u=0,f;t<n;)f=e[t++],f<128?r[u++]=f:f>191&&f<224?r[u++]=(f&31)<<6|e[t++]&63:f>239&&f<365?(f=((f&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,r[u++]=55296+(f>>10),r[u++]=56320+(f&1023)):r[u++]=(f&15)<<12|(e[t++]&63)<<6|e[t++]&63,u>=8192&&((s||(s=[])).push(String.fromCharCode(...r)),u=0);return s?(u&&s.push(String.fromCharCode(...r.slice(0,u))),s.join("")):String.fromCharCode(...r.slice(0,u))}function yt(e,t,n){for(var o=n,s=0,r=e.length;s<r;++s){let u=e.charCodeAt(s),f;u<128?t[n++]=u:u<2048?(t[n++]=u>>6|192,t[n++]=u&63|128):(u&64512)===55296&&s+1<r&&((f=e.charCodeAt(s+1))&64512)===56320?(u=65536+((u&1023)<<10)+(f&1023),++s,t[n++]=u>>18|240,t[n++]=u>>12&63|128,t[n++]=u>>6&63|128,t[n++]=u&63|128):(t[n++]=u>>12|224,t[n++]=u>>6&63|128,t[n++]=u&63|128)}return n-o}var Tn={length:mt,read:bt,write:yt};var me=sn.createRequire(import.meta.url);function ye(e,t,n=!0){var o={},s=[],r=[],u=[],f={};Object.keys(t).forEach(d=>{if(!d.startsWith(" ")){var g=t[d];g.alias!=null&&(typeof g.alias=="string"?f[g.alias]=d:Array.isArray(g.alias)&&g.alias.forEach(y=>f[y]=d)),n&&g.default!=null&&(o[d]=g.default)}});for(var x=0,b=(e=e.slice()).length;x<b;++x){let d=e[x];if(d=="--"){++x;break}let g=/^(?:(-\w)(?:=(.*))?|(--\w{2,})(?:=(.*))?)$/.exec(d),y,m;if(g)t[d]?y=t[m=d]:g[1]!=null?(y=t[m=f[g[1].substring(1)]],y&&g[2]!=null&&(e[x--]=g[2])):g[3]!=null&&(y=t[m=g[3].substring(2)],y&&g[4]!=null&&(e[x--]=g[4]));else if(d.charCodeAt(0)==45)y=t[m=d];else{r.push(d);continue}if(y)if(y.value)Object.keys(y.value).forEach(i=>o[i]=y.value[i]);else if(y.type==null||y.type==="b")o[m]=!0;else if(x+1<e.length&&e[x+1].charCodeAt(0)!=45)switch(y.type){case"i":o[m]=parseInt(e[++x],10);break;case"I":o[m]=(o[m]||[]).concat(parseInt(e[++x],10));break;case"f":o[m]=parseFloat(e[++x]);break;case"F":o[m]=(o[m]||[]).concat(parseFloat(e[++x]));break;case"s":o[m]=String(e[++x]);break;case"S":o[m]=(o[m]||[]).concat(e[++x].split(","));break;default:s.push(d),--x}else switch(y.type){case"i":case"f":o[m]=y.default||0;break;case"s":o[m]=y.default||"";break;case"I":case"F":case"S":o[m]=y.default||[];break;default:s.push(d)}else s.push(d)}for(;x<b;)u.push(e[x++]);return n&&Mn(t,o),{options:o,unknown:s,arguments:r,trailing:u}}function ve(e,t){t||(t={});var n=t.indent||2,o=t.padding||24,s=t.eol||`
8
- `,r={},u=[];Object.keys(e).forEach(b=>{var d=e[b];if(d.description!=null){for(var g="";g.length<n;)g+=" ";for(g+="--"+b,d.alias&&(g+=", -"+d.alias);g.length<o;)g+=" ";var y;!t.noCategories&&d.category?(y=r[d.category])||(r[d.category]=y=[]):y=u,Array.isArray(d.description)?y.push(g+d.description[0]+d.description.slice(1).map(m=>{for(let i=0;i<o;++i)m=" "+m;return s+m}).join("")):y.push(g+d.description)}});var f=[],x=!1;return Object.keys(r).forEach(b=>{x=!0,f.push(s+" "+_n.gray(b)+s),f.push(r[b].join(s))}),x&&u.length&&f.push(s+" "+_n.gray("Other")+s),f.push(u.join(s)),f.join(s)}function be(e,t){if(e!=null)switch(t){case void 0:case"b":return!!e;case"i":return Math.trunc(e)||0;case"f":return Number(e)||0;case"s":return e===!0?"":e===!1?null:String(e);case"I":return Array.isArray(e)||(e=[e]),e.map(n=>Math.trunc(n)||0);case"F":return Array.isArray(e)||(e=[e]),e.map(n=>Number(n)||0);case"S":return Array.isArray(e)||(e=[e]),e.map(String)}}function Un(e,t,n,o){let s={};for(let[r,{type:u,mutuallyExclusive:f,isPath:x,useNodeResolution:b,cliOnly:d}]of Object.entries(e)){let g=be(t[r],u),y=be(n[r],u);if(g==null){if(y!=null){if(d)continue;if(Array.isArray(y)){let m;x&&(y=y.map(i=>tn(i,o,b))),f!=null&&(m=t[f])?s[r]=y.filter(i=>!m.includes(i)):s[r]=y.slice()}else x&&(y=tn(y,o,b)),s[r]=y}}else if(y==null)Array.isArray(g)?s[r]=g.slice():s[r]=g;else if(Array.isArray(g)){if(d){s[r]=g.slice();continue}let m;x&&(y=y.map(i=>tn(i,o,b))),f!=null&&(m=t[f])?s[r]=[...g,...y.filter(i=>!g.includes(i)&&!m.includes(i))]:s[r]=[...g,...y.filter(i=>!g.includes(i))]}else s[r]=g}return s}function vt(e){let t=F.parse(e);return t.root||(t.root="./"),F.format(t)}function tn(e,t,n=!1){return F.isAbsolute(e)?e:n&&!e.startsWith(".")&&me.resolve?me.resolve(e,{paths:[t]}):vt(F.join(t,e))}function Mn(e,t){for(let[n,{default:o}]of Object.entries(e))t[n]==null&&o!=null&&(t[n]=o)}var Fe="0.1.26",Y={version:{category:"General",description:"Prints just the compiler's version and exits.",type:"b",alias:"v"},help:{category:"General",description:"Prints this message and exits.",type:"b",alias:"h"},config:{category:"General",description:"Configuration file to apply. CLI arguments take precedence.",type:"s",cliOnly:!0},target:{category:"General",description:"Configuration file target to use. Defaults to 'release'.",type:"s",cliOnly:!0},optimize:{category:"Optimization",description:["Optimizes the module. Typical shorthands are:",""," Default optimizations -O"," Make a release build -O --noAssert"," Make a debug build --debug"," Optimize for speed -Ospeed"," Optimize for size -Osize",""],type:"b",alias:"O"},optimizeLevel:{category:"Optimization",description:"How much to focus on optimizing code. [0-3]",type:"i"},shrinkLevel:{category:"Optimization",description:"How much to focus on shrinking code size. [0-2, s=1, z=2]",type:"i"},converge:{category:"Optimization",description:"Re-optimizes until no further improvements can be made.",type:"b",default:!1},noAssert:{category:"Optimization",description:"Replaces assertions with just their value without trapping.",type:"b",default:!1},outFile:{category:"Output",description:"Specifies the WebAssembly output file (.wasm).",type:"s",alias:"o",isPath:!0},textFile:{category:"Output",description:"Specifies the WebAssembly text output file (.wat).",type:"s",alias:"t",isPath:!0},rpcModule:{category:"Output",description:"Emits a .ts module: the @data codec + the typed client-callable Server surface.",type:"s",isPath:!0},rpcRuntime:{category:"Output",description:"Import specifier for the DataWriter/DataReader codec in the emitted RPC module.",type:"s",default:"toiljs/io"},bindings:{category:"Output",description:["Specifies the bindings to generate (.js + .d.ts).",""," esm JavaScript bindings & typings for ESM integration."," raw Like esm, but exports just the instantiate function."," Useful where modules are meant to be instantiated"," multiple times or non-ESM imports must be provided."],type:"S",alias:"b"},sourceMap:{category:"Debugging",description:["Enables source map generation. Optionally takes the URL","used to reference the source map from the binary file."],type:"s"},uncheckedBehavior:{category:"Debugging",description:["Changes the behavior of unchecked() expressions.","Using this option can potentially cause breakage.",""," default The default behavior: unchecked operations are"," only used inside of unchecked()."," never Unchecked operations are never used, even when"," inside of unchecked()."," always Unchecked operations are always used if possible,"," whether or not unchecked() is used."],type:"s",default:"default"},debug:{category:"Debugging",description:"Enables debug information in emitted binaries.",type:"b",default:!1},importMemory:{category:"Features",description:"Imports the memory from 'env.memory'.",type:"b",default:!1},noExportMemory:{category:"Features",description:"Does not export the memory as 'memory'.",type:"b",default:!1},initialMemory:{category:"Features",description:"Sets the initial memory size in pages.",type:"i",default:0},maximumMemory:{category:"Features",description:"Sets the maximum memory size in pages.",type:"i",default:0},sharedMemory:{category:"Features",description:"Declare memory as shared. Requires maximumMemory.",type:"b",default:!1},zeroFilledMemory:{category:"Features",description:"Assume imported memory is zeroed. Requires importMemory.",type:"b",default:!1},importTable:{category:"Features",description:"Imports the function table from 'env.table'.",type:"b",default:!1},exportTable:{category:"Features",description:"Exports the function table as 'table'.",type:"b",default:!1},exportStart:{category:"Features",description:["Exports the start function using the specified name instead","of calling it implicitly. Useful to obtain the exported memory","before executing any code accessing it."],type:"s"},runtime:{category:"Features",description:["Specifies the runtime variant to include in the program.",""," incremental TLSF + incremental GC (default)"," minimal TLSF + lightweight GC invoked externally"," stub Minimal runtime stub (never frees)"," ... Path to a custom runtime implementation",""],type:"s",default:"incremental"},exportRuntime:{category:"Features",description:["Always exports the runtime helpers (__new, __collect, __pin etc.).","Automatically determined when generation of --bindings is enabled."],type:"b",default:!1},stackSize:{category:"Features",description:["Overrides the stack size. Only relevant for incremental GC","or when using a custom runtime that requires stack space.","Defaults to 0 without and to 32768 with incremental GC."],default:0,type:"i"},enable:{category:"Features",description:["Enables WebAssembly features being disabled by default.",""," threads Threading and atomic operations."," simd SIMD types and operations."," reference-types Reference types and operations."," gc Garbage collection (WIP)."," stringref String reference types."," relaxed-simd Relaxed SIMD operations.",""],TODO_doesNothingYet:[" exception-handling Exception handling."," tail-calls Tail call operations."," multi-value Multi value types."," memory64 Memory64 operations."," extended-const Extended const expressions."],type:"S",mutuallyExclusive:"disable"},disable:{category:"Features",description:["Disables WebAssembly features being enabled by default.",""," mutable-globals Mutable global imports and exports."," sign-extension Sign-extension operations"," nontrapping-f2i Non-trapping float to integer ops."," bulk-memory Bulk memory operations.",""],type:"S",mutuallyExclusive:"enable"},use:{category:"Features",description:["Aliases a global object under another name, e.g., to switch","the default 'Math' implementation used: --use Math=JSMath","Can also be used to introduce an integer constant."],type:"S",alias:"u"},lowMemoryLimit:{category:"Features",description:"Enforces very low (<64k) memory constraints.",default:0,type:"i"},memoryBase:{category:"Linking",description:"Sets the start offset of emitted memory segments.",type:"i",default:0},tableBase:{category:"Linking",description:"Sets the start offset of emitted table elements.",type:"i",default:0},transform:{category:"API",description:"Specifies the path to a custom transform to load.",type:"S",isPath:!0,useNodeResolution:!0},trapMode:{category:"Binaryen",description:["Sets the trap mode to use.",""," allow Allow trapping operations. This is the default."," clamp Replace trapping operations with clamping semantics."," js Replace trapping operations with JS semantics.",""],type:"s",default:"allow"},runPasses:{category:"Binaryen",description:["Specifies additional Binaryen passes to run after other","optimizations, if any. See: Binaryen/src/passes/pass.cpp"],type:"s"},noValidate:{category:"Binaryen",description:"Skips validating the module using Binaryen.",type:"b",default:!1},baseDir:{description:"Specifies the base directory of input and output files.",type:"s",default:"."},noColors:{description:"Disables terminal colors.",type:"b",default:!1},noUnsafe:{description:["Disallows the use of unsafe features in user code.","Does not affect library files and external modules."],type:"b",default:!1},disableWarning:{description:["Disables warnings matching the given diagnostic code.","If no diagnostic code is given, all warnings are disabled."],type:"I"},noEmit:{description:"Performs compilation as usual but does not emit code.",type:"b",default:!1},showConfig:{description:"Print computed compiler options and exit.",type:"b",default:!1},stats:{description:"Prints statistics on I/O and compile times.",type:"b",default:!1},pedantic:{description:"Make yourself sad for no good reason.",type:"b",default:!1},lib:{description:["Adds one or multiple paths to custom library components and","uses exports of all top-level files at this path as globals."],type:"S",isPath:!0},path:{description:["Adds one or multiple paths to package resolution, similar","to node_modules. Prefers an 'ascMain' entry in a package's","package.json and falls back to an inner 'assembly/' folder."],type:"S",isPath:!0},wasm:{description:"Uses the specified Wasm binary of the compiler.",type:"s"}," ...":{description:"Specifies node.js options (CLI only). See: node --help"},"-Os":{value:{optimizeLevel:0,shrinkLevel:1}},"-Oz":{value:{optimizeLevel:0,shrinkLevel:2}},"-O0":{value:{optimizeLevel:0,shrinkLevel:0}},"-O1":{value:{optimizeLevel:1,shrinkLevel:0}},"-O2":{value:{optimizeLevel:2,shrinkLevel:0}},"-O3":{value:{optimizeLevel:3,shrinkLevel:0}},"-O0s":{value:{optimizeLevel:0,shrinkLevel:1}},"-O1s":{value:{optimizeLevel:1,shrinkLevel:1}},"-O2s":{value:{optimizeLevel:2,shrinkLevel:1}},"-O3s":{value:{optimizeLevel:3,shrinkLevel:1}},"-O0z":{value:{optimizeLevel:0,shrinkLevel:2}},"-O1z":{value:{optimizeLevel:1,shrinkLevel:2}},"-O2z":{value:{optimizeLevel:2,shrinkLevel:2}},"-O3z":{value:{optimizeLevel:3,shrinkLevel:2}},"-Ospeed":{value:{optimizeLevel:3,shrinkLevel:0}},"-Osize":{value:{optimizeLevel:0,shrinkLevel:2,converge:!0}},"--measure":{value:{stats:!0}}},Ee="~lib/",Ae={array:`/// <reference path="./rt/index.d.ts" />
8
+ `,r={},u=[];Object.keys(e).forEach(b=>{var d=e[b];if(d.description!=null){for(var g="";g.length<n;)g+=" ";for(g+="--"+b,d.alias&&(g+=", -"+d.alias);g.length<o;)g+=" ";var y;!t.noCategories&&d.category?(y=r[d.category])||(r[d.category]=y=[]):y=u,Array.isArray(d.description)?y.push(g+d.description[0]+d.description.slice(1).map(m=>{for(let i=0;i<o;++i)m=" "+m;return s+m}).join("")):y.push(g+d.description)}});var f=[],x=!1;return Object.keys(r).forEach(b=>{x=!0,f.push(s+" "+_n.gray(b)+s),f.push(r[b].join(s))}),x&&u.length&&f.push(s+" "+_n.gray("Other")+s),f.push(u.join(s)),f.join(s)}function be(e,t){if(e!=null)switch(t){case void 0:case"b":return!!e;case"i":return Math.trunc(e)||0;case"f":return Number(e)||0;case"s":return e===!0?"":e===!1?null:String(e);case"I":return Array.isArray(e)||(e=[e]),e.map(n=>Math.trunc(n)||0);case"F":return Array.isArray(e)||(e=[e]),e.map(n=>Number(n)||0);case"S":return Array.isArray(e)||(e=[e]),e.map(String)}}function Un(e,t,n,o){let s={};for(let[r,{type:u,mutuallyExclusive:f,isPath:x,useNodeResolution:b,cliOnly:d}]of Object.entries(e)){let g=be(t[r],u),y=be(n[r],u);if(g==null){if(y!=null){if(d)continue;if(Array.isArray(y)){let m;x&&(y=y.map(i=>tn(i,o,b))),f!=null&&(m=t[f])?s[r]=y.filter(i=>!m.includes(i)):s[r]=y.slice()}else x&&(y=tn(y,o,b)),s[r]=y}}else if(y==null)Array.isArray(g)?s[r]=g.slice():s[r]=g;else if(Array.isArray(g)){if(d){s[r]=g.slice();continue}let m;x&&(y=y.map(i=>tn(i,o,b))),f!=null&&(m=t[f])?s[r]=[...g,...y.filter(i=>!g.includes(i)&&!m.includes(i))]:s[r]=[...g,...y.filter(i=>!g.includes(i))]}else s[r]=g}return s}function vt(e){let t=F.parse(e);return t.root||(t.root="./"),F.format(t)}function tn(e,t,n=!1){return F.isAbsolute(e)?e:n&&!e.startsWith(".")&&me.resolve?me.resolve(e,{paths:[t]}):vt(F.join(t,e))}function Mn(e,t){for(let[n,{default:o}]of Object.entries(e))t[n]==null&&o!=null&&(t[n]=o)}var Fe="0.1.28",Y={version:{category:"General",description:"Prints just the compiler's version and exits.",type:"b",alias:"v"},help:{category:"General",description:"Prints this message and exits.",type:"b",alias:"h"},config:{category:"General",description:"Configuration file to apply. CLI arguments take precedence.",type:"s",cliOnly:!0},target:{category:"General",description:"Configuration file target to use. Defaults to 'release'.",type:"s",cliOnly:!0},optimize:{category:"Optimization",description:["Optimizes the module. Typical shorthands are:",""," Default optimizations -O"," Make a release build -O --noAssert"," Make a debug build --debug"," Optimize for speed -Ospeed"," Optimize for size -Osize",""],type:"b",alias:"O"},optimizeLevel:{category:"Optimization",description:"How much to focus on optimizing code. [0-3]",type:"i"},shrinkLevel:{category:"Optimization",description:"How much to focus on shrinking code size. [0-2, s=1, z=2]",type:"i"},converge:{category:"Optimization",description:"Re-optimizes until no further improvements can be made.",type:"b",default:!1},noAssert:{category:"Optimization",description:"Replaces assertions with just their value without trapping.",type:"b",default:!1},outFile:{category:"Output",description:"Specifies the WebAssembly output file (.wasm).",type:"s",alias:"o",isPath:!0},textFile:{category:"Output",description:"Specifies the WebAssembly text output file (.wat).",type:"s",alias:"t",isPath:!0},rpcModule:{category:"Output",description:"Emits a .ts module: the @data codec + the typed client-callable Server surface.",type:"s",isPath:!0},rpcRuntime:{category:"Output",description:"Import specifier for the DataWriter/DataReader codec in the emitted RPC module.",type:"s",default:"toiljs/io"},bindings:{category:"Output",description:["Specifies the bindings to generate (.js + .d.ts).",""," esm JavaScript bindings & typings for ESM integration."," raw Like esm, but exports just the instantiate function."," Useful where modules are meant to be instantiated"," multiple times or non-ESM imports must be provided."],type:"S",alias:"b"},sourceMap:{category:"Debugging",description:["Enables source map generation. Optionally takes the URL","used to reference the source map from the binary file."],type:"s"},uncheckedBehavior:{category:"Debugging",description:["Changes the behavior of unchecked() expressions.","Using this option can potentially cause breakage.",""," default The default behavior: unchecked operations are"," only used inside of unchecked()."," never Unchecked operations are never used, even when"," inside of unchecked()."," always Unchecked operations are always used if possible,"," whether or not unchecked() is used."],type:"s",default:"default"},debug:{category:"Debugging",description:"Enables debug information in emitted binaries.",type:"b",default:!1},importMemory:{category:"Features",description:"Imports the memory from 'env.memory'.",type:"b",default:!1},noExportMemory:{category:"Features",description:"Does not export the memory as 'memory'.",type:"b",default:!1},initialMemory:{category:"Features",description:"Sets the initial memory size in pages.",type:"i",default:0},maximumMemory:{category:"Features",description:"Sets the maximum memory size in pages.",type:"i",default:0},sharedMemory:{category:"Features",description:"Declare memory as shared. Requires maximumMemory.",type:"b",default:!1},zeroFilledMemory:{category:"Features",description:"Assume imported memory is zeroed. Requires importMemory.",type:"b",default:!1},importTable:{category:"Features",description:"Imports the function table from 'env.table'.",type:"b",default:!1},exportTable:{category:"Features",description:"Exports the function table as 'table'.",type:"b",default:!1},exportStart:{category:"Features",description:["Exports the start function using the specified name instead","of calling it implicitly. Useful to obtain the exported memory","before executing any code accessing it."],type:"s"},runtime:{category:"Features",description:["Specifies the runtime variant to include in the program.",""," incremental TLSF + incremental GC (default)"," minimal TLSF + lightweight GC invoked externally"," stub Minimal runtime stub (never frees)"," ... Path to a custom runtime implementation",""],type:"s",default:"incremental"},exportRuntime:{category:"Features",description:["Always exports the runtime helpers (__new, __collect, __pin etc.).","Automatically determined when generation of --bindings is enabled."],type:"b",default:!1},stackSize:{category:"Features",description:["Overrides the stack size. Only relevant for incremental GC","or when using a custom runtime that requires stack space.","Defaults to 0 without and to 32768 with incremental GC."],default:0,type:"i"},enable:{category:"Features",description:["Enables WebAssembly features being disabled by default.",""," threads Threading and atomic operations."," simd SIMD types and operations."," reference-types Reference types and operations."," gc Garbage collection (WIP)."," stringref String reference types."," relaxed-simd Relaxed SIMD operations.",""],TODO_doesNothingYet:[" exception-handling Exception handling."," tail-calls Tail call operations."," multi-value Multi value types."," memory64 Memory64 operations."," extended-const Extended const expressions."],type:"S",mutuallyExclusive:"disable"},disable:{category:"Features",description:["Disables WebAssembly features being enabled by default.",""," mutable-globals Mutable global imports and exports."," sign-extension Sign-extension operations"," nontrapping-f2i Non-trapping float to integer ops."," bulk-memory Bulk memory operations.",""],type:"S",mutuallyExclusive:"enable"},use:{category:"Features",description:["Aliases a global object under another name, e.g., to switch","the default 'Math' implementation used: --use Math=JSMath","Can also be used to introduce an integer constant."],type:"S",alias:"u"},lowMemoryLimit:{category:"Features",description:"Enforces very low (<64k) memory constraints.",default:0,type:"i"},memoryBase:{category:"Linking",description:"Sets the start offset of emitted memory segments.",type:"i",default:0},tableBase:{category:"Linking",description:"Sets the start offset of emitted table elements.",type:"i",default:0},transform:{category:"API",description:"Specifies the path to a custom transform to load.",type:"S",isPath:!0,useNodeResolution:!0},trapMode:{category:"Binaryen",description:["Sets the trap mode to use.",""," allow Allow trapping operations. This is the default."," clamp Replace trapping operations with clamping semantics."," js Replace trapping operations with JS semantics.",""],type:"s",default:"allow"},runPasses:{category:"Binaryen",description:["Specifies additional Binaryen passes to run after other","optimizations, if any. See: Binaryen/src/passes/pass.cpp"],type:"s"},noValidate:{category:"Binaryen",description:"Skips validating the module using Binaryen.",type:"b",default:!1},baseDir:{description:"Specifies the base directory of input and output files.",type:"s",default:"."},noColors:{description:"Disables terminal colors.",type:"b",default:!1},noUnsafe:{description:["Disallows the use of unsafe features in user code.","Does not affect library files and external modules."],type:"b",default:!1},disableWarning:{description:["Disables warnings matching the given diagnostic code.","If no diagnostic code is given, all warnings are disabled."],type:"I"},noEmit:{description:"Performs compilation as usual but does not emit code.",type:"b",default:!1},showConfig:{description:"Print computed compiler options and exit.",type:"b",default:!1},stats:{description:"Prints statistics on I/O and compile times.",type:"b",default:!1},pedantic:{description:"Make yourself sad for no good reason.",type:"b",default:!1},lib:{description:["Adds one or multiple paths to custom library components and","uses exports of all top-level files at this path as globals."],type:"S",isPath:!0},path:{description:["Adds one or multiple paths to package resolution, similar","to node_modules. Prefers an 'ascMain' entry in a package's","package.json and falls back to an inner 'assembly/' folder."],type:"S",isPath:!0},wasm:{description:"Uses the specified Wasm binary of the compiler.",type:"s"}," ...":{description:"Specifies node.js options (CLI only). See: node --help"},"-Os":{value:{optimizeLevel:0,shrinkLevel:1}},"-Oz":{value:{optimizeLevel:0,shrinkLevel:2}},"-O0":{value:{optimizeLevel:0,shrinkLevel:0}},"-O1":{value:{optimizeLevel:1,shrinkLevel:0}},"-O2":{value:{optimizeLevel:2,shrinkLevel:0}},"-O3":{value:{optimizeLevel:3,shrinkLevel:0}},"-O0s":{value:{optimizeLevel:0,shrinkLevel:1}},"-O1s":{value:{optimizeLevel:1,shrinkLevel:1}},"-O2s":{value:{optimizeLevel:2,shrinkLevel:1}},"-O3s":{value:{optimizeLevel:3,shrinkLevel:1}},"-O0z":{value:{optimizeLevel:0,shrinkLevel:2}},"-O1z":{value:{optimizeLevel:1,shrinkLevel:2}},"-O2z":{value:{optimizeLevel:2,shrinkLevel:2}},"-O3z":{value:{optimizeLevel:3,shrinkLevel:2}},"-Ospeed":{value:{optimizeLevel:3,shrinkLevel:0}},"-Osize":{value:{optimizeLevel:0,shrinkLevel:2,converge:!0}},"--measure":{value:{stats:!0}}},Ee="~lib/",Ae={array:`/// <reference path="./rt/index.d.ts" />
9
9
 
10
10
  import { BLOCK_MAXSIZE } from "./rt/common";
11
11
  import { Runtime } from "shared/runtime";
@@ -4582,6 +4582,175 @@ export declare namespace performance {
4582
4582
  @external("env", "process.exit")
4583
4583
  export function exit(code: i32): void;
4584
4584
  }
4585
+ `,"bindings/toildb":`// Host-import declarations for the ToilDB data API. The production edge
4586
+ // (toil-backend \`src/wasm/host/import_functions/db\`) and the toiljs dev server
4587
+ // both provide these under the \`env\` namespace. All byte regions are passed as
4588
+ // a (pointer, length) pair into guest linear memory.
4589
+ //
4590
+ // Collections are resolved by name ONCE at module init (\`resolveCollection\`),
4591
+ // which returns an opaque numeric handle; request-time ops pass the handle.
4592
+ //
4593
+ // Return convention (see toildb/ABI.md):
4594
+ // >= 0 success: a length (a value stashed for \`takeResult\`), a count, a
4595
+ // boolean (0/1), a tag, or 0 (ok).
4596
+ // -1 output buffer too small (retry \`takeResult\` with a bigger buffer).
4597
+ // -2 absent (a normal null / not-found).
4598
+ // <= -1000 a typed failure; the diagnostic is TDL(|v| - 1000).
4599
+ //
4600
+ // Variable-length results (a fetched value, a patched record, a claim owner)
4601
+ // use the two-step pull: the op returns the stashed length, then the guest
4602
+ // allocates a buffer and calls \`takeResult\` to copy the bytes out.
4603
+ //
4604
+ // \`idemPtr\` is 0 for none, otherwise a pointer to a 16-byte idempotency key.
4605
+ //
4606
+ // This is the guest half of the ABI contract; the byte framing of keys/values
4607
+ // is the \`@data\` binary codec (\`DataWriter\`/\`DataReader\`).
4608
+
4609
+ export namespace toildbHost {
4610
+ // Resolve a collection by its "<db>/<collection>" name; writes the u32 handle
4611
+ // to outHandlePtr. Returns 0 on success or a negative TDL code.
4612
+ // @ts-ignore: decorator
4613
+ @external("env", "data.resolve_collection")
4614
+ export declare function resolveCollection(namePtr: usize, nameLen: i32, outHandlePtr: usize): i32;
4615
+
4616
+ // record.get -> value length (stashed) | -2 absent | negative error.
4617
+ // @ts-ignore: decorator
4618
+ @external("env", "data.get")
4619
+ export declare function get(handle: u32, keyPtr: usize, keyLen: i32): i32;
4620
+
4621
+ // record bounded multi-get. Input at keysPtr: u32 count + per key (u32 len +
4622
+ // bytes). Result (stashed): u32 count + per item u8 present (+ u32 len + bytes
4623
+ // when present), in request order. Returns the stashed length | negative error.
4624
+ // @ts-ignore: decorator
4625
+ @external("env", "data.get_many")
4626
+ export declare function getMany(handle: u32, keysPtr: usize, keysLen: i32): i32;
4627
+
4628
+ // record.exists -> 1 | 0 | negative error.
4629
+ // @ts-ignore: decorator
4630
+ @external("env", "data.exists")
4631
+ export declare function exists(handle: u32, keyPtr: usize, keyLen: i32): i32;
4632
+
4633
+ // record.create -> 0 ok | AlreadyExists/typed code.
4634
+ // @ts-ignore: decorator
4635
+ @external("env", "data.create")
4636
+ export declare function create(
4637
+ handle: u32,
4638
+ keyPtr: usize,
4639
+ keyLen: i32,
4640
+ valPtr: usize,
4641
+ valLen: i32,
4642
+ idemPtr: usize
4643
+ ): i32;
4644
+
4645
+ // record.patch -> length of the new record (stashed) | negative error.
4646
+ // @ts-ignore: decorator
4647
+ @external("env", "data.patch")
4648
+ export declare function patch(
4649
+ handle: u32,
4650
+ keyPtr: usize,
4651
+ keyLen: i32,
4652
+ patchPtr: usize,
4653
+ patchLen: i32,
4654
+ idemPtr: usize
4655
+ ): i32;
4656
+
4657
+ // record.delete -> 0 ok | negative error.
4658
+ // @ts-ignore: decorator
4659
+ @external("env", "data.delete")
4660
+ export declare function del(handle: u32, keyPtr: usize, keyLen: i32, idemPtr: usize): i32;
4661
+
4662
+ // record consume-once fetch-and-delete -> prior value length (stashed) | -2.
4663
+ // @ts-ignore: decorator
4664
+ @external("env", "data.get_delete")
4665
+ export declare function getDelete(handle: u32, keyPtr: usize, keyLen: i32, idemPtr: usize): i32;
4666
+
4667
+ // unique.lookup -> owner value length (stashed) | -2 absent.
4668
+ // @ts-ignore: decorator
4669
+ @external("env", "data.unique_lookup")
4670
+ export declare function uniqueLookup(handle: u32, keyPtr: usize, keyLen: i32): i32;
4671
+
4672
+ // unique.claim -> 0 Claimed | 1 AlreadyClaimed (owner stashed) | 2 owned-by-caller | neg.
4673
+ // @ts-ignore: decorator
4674
+ @external("env", "data.unique_claim")
4675
+ export declare function uniqueClaim(
4676
+ handle: u32,
4677
+ keyPtr: usize,
4678
+ keyLen: i32,
4679
+ valPtr: usize,
4680
+ valLen: i32,
4681
+ idemPtr: usize
4682
+ ): i32;
4683
+
4684
+ // unique.release -> 0 ok | neg (Conflict if not the owner).
4685
+ // @ts-ignore: decorator
4686
+ @external("env", "data.unique_release")
4687
+ export declare function uniqueRelease(
4688
+ handle: u32,
4689
+ keyPtr: usize,
4690
+ keyLen: i32,
4691
+ valPtr: usize,
4692
+ valLen: i32,
4693
+ idemPtr: usize
4694
+ ): i32;
4695
+
4696
+ // view.get -> view value length (stashed) | -2 absent | negative error.
4697
+ // @ts-ignore: decorator
4698
+ @external("env", "data.view_get")
4699
+ export declare function viewGet(handle: u32, keyPtr: usize, keyLen: i32): i32;
4700
+
4701
+ // view.publish -> 0 ok | negative error (derive/job only; the host gate enforces).
4702
+ // @ts-ignore: decorator
4703
+ @external("env", "data.view_publish")
4704
+ export declare function viewPublish(
4705
+ handle: u32,
4706
+ keyPtr: usize,
4707
+ keyLen: i32,
4708
+ valPtr: usize,
4709
+ valLen: i32,
4710
+ idemPtr: usize
4711
+ ): i32;
4712
+
4713
+ // counter.get -> 8 (the i64 sum stashed as 8 LE bytes) | negative error.
4714
+ // @ts-ignore: decorator
4715
+ @external("env", "data.counter_get")
4716
+ export declare function counterGet(handle: u32, keyPtr: usize, keyLen: i32): i32;
4717
+
4718
+ // counter.add(delta: i64) -> 0 ok | negative error.
4719
+ // @ts-ignore: decorator
4720
+ @external("env", "data.counter_add")
4721
+ export declare function counterAdd(
4722
+ handle: u32,
4723
+ keyPtr: usize,
4724
+ keyLen: i32,
4725
+ delta: i64,
4726
+ idemPtr: usize
4727
+ ): i32;
4728
+
4729
+ // events.append -> 0 ok | negative error.
4730
+ // @ts-ignore: decorator
4731
+ @external("env", "data.append")
4732
+ export declare function append(
4733
+ handle: u32,
4734
+ keyPtr: usize,
4735
+ keyLen: i32,
4736
+ evPtr: usize,
4737
+ evLen: i32,
4738
+ idemPtr: usize
4739
+ ): i32;
4740
+
4741
+ // events.latest(limit) -> framed-list length (stashed) | negative error.
4742
+ // The blob is \`u32 count\` then per event \`u32 len + bytes\`, newest first.
4743
+ // @ts-ignore: decorator
4744
+ @external("env", "data.latest")
4745
+ export declare function latest(handle: u32, keyPtr: usize, keyLen: i32, limit: i32): i32;
4746
+
4747
+ // Copy the last stashed variable-length result into outPtr (outLen must equal
4748
+ // the length the producing op returned). Returns bytes written, or -1 if the
4749
+ // buffer is too small.
4750
+ // @ts-ignore: decorator
4751
+ @external("env", "data.take_result")
4752
+ export declare function takeResult(outPtr: usize, outLen: i32): i32;
4753
+ }
4585
4754
  `,"bindings/webcrypto":`// Host-import declarations for the Web Crypto surface. The production edge
4586
4755
  // (toil-backend \`src/wasm/host/import_functions/crypto\`) and the toiljs dev
4587
4756
  // server both provide these under the \`env\` namespace. All byte regions are
@@ -7625,7 +7794,16 @@ export namespace console {
7625
7794
 
7626
7795
  import { webcrypto } from "bindings/webcrypto";
7627
7796
  import { SubtleCrypto } from "crypto/subtle";
7628
- import { HmacImportParams, HmacParams, ALG_SHA_256, USAGE_SIGN } from "crypto/algorithms";
7797
+ import {
7798
+ HmacImportParams,
7799
+ HmacParams,
7800
+ ALG_SHA_1,
7801
+ ALG_SHA_256,
7802
+ ALG_SHA_384,
7803
+ ALG_SHA_512,
7804
+ FMT_RAW,
7805
+ USAGE_SIGN,
7806
+ } from "crypto/algorithms";
7629
7807
  import { Encoding } from "encoding";
7630
7808
 
7631
7809
  // Re-export the public surface so guests can import everything from "crypto".
@@ -7665,6 +7843,13 @@ export {
7665
7843
  ALG_X25519,
7666
7844
  ALG_HKDF,
7667
7845
  ALG_PBKDF2,
7846
+ ALG_SHA3_256,
7847
+ ALG_SHA3_384,
7848
+ ALG_SHA3_512,
7849
+ FMT_RAW,
7850
+ FMT_PKCS8,
7851
+ FMT_SPKI,
7852
+ FMT_JWK,
7668
7853
  CURVE_P256,
7669
7854
  CURVE_P384,
7670
7855
  USAGE_ENCRYPT,
@@ -7715,16 +7900,16 @@ export namespace crypto {
7715
7900
 
7716
7901
  // --- Ergonomic digest helpers (thin wrappers over subtle.digest) ----------
7717
7902
  export function sha1(data: Uint8Array): Uint8Array {
7718
- return subtle.digest("SHA-1", data);
7903
+ return subtle.digest(ALG_SHA_1, data);
7719
7904
  }
7720
7905
  export function sha256(data: Uint8Array): Uint8Array {
7721
- return subtle.digest("SHA-256", data);
7906
+ return subtle.digest(ALG_SHA_256, data);
7722
7907
  }
7723
7908
  export function sha384(data: Uint8Array): Uint8Array {
7724
- return subtle.digest("SHA-384", data);
7909
+ return subtle.digest(ALG_SHA_384, data);
7725
7910
  }
7726
7911
  export function sha512(data: Uint8Array): Uint8Array {
7727
- return subtle.digest("SHA-512", data);
7912
+ return subtle.digest(ALG_SHA_512, data);
7728
7913
  }
7729
7914
 
7730
7915
  // String-input variants (UTF-8 encode, then hash).
@@ -7743,7 +7928,7 @@ export namespace crypto {
7743
7928
 
7744
7929
  /// One-shot HMAC-SHA-256 over raw key + message bytes.
7745
7930
  export function hmacSha256(key: Uint8Array, msg: Uint8Array): Uint8Array {
7746
- let k = subtle.importKey("raw", key, new HmacImportParams(ALG_SHA_256), false, USAGE_SIGN);
7931
+ let k = subtle.importKey(FMT_RAW, key, new HmacImportParams(ALG_SHA_256), false, USAGE_SIGN);
7747
7932
  return subtle.sign(new HmacParams(), k, msg);
7748
7933
  }
7749
7934
  export function hmacSha256Text(key: Uint8Array, msg: string): Uint8Array {
@@ -8122,12 +8307,11 @@ import { webcrypto } from "bindings/webcrypto";
8122
8307
  import { CryptoKey } from "crypto/key";
8123
8308
  import {
8124
8309
  AlgorithmParams,
8125
- algId,
8126
- formatId,
8127
8310
  cryptoError,
8128
- FMT_JWK,
8311
+ FMT_RAW,
8129
8312
  FMT_PKCS8,
8130
8313
  FMT_SPKI,
8314
+ FMT_JWK,
8131
8315
  ALG_AES_GCM,
8132
8316
  ALG_AES_CBC,
8133
8317
  ALG_AES_CTR,
@@ -8158,26 +8342,24 @@ function isSymmetricAlg(alg: i32): bool {
8158
8342
  }
8159
8343
 
8160
8344
  export class SubtleCrypto {
8161
- digest(algorithm: string, data: Uint8Array): Uint8Array {
8162
- let id = algId(algorithm);
8163
- if (id == 0) throw new Error("Unrecognized algorithm: " + algorithm);
8164
- return drain(webcrypto.digest(id, data.dataStart, data.byteLength));
8345
+ // \`algorithm\` is a hash-id selector: an \`ALG_SHA_*\` const (NOT a magic string).
8346
+ digest(algorithm: i32, data: Uint8Array): Uint8Array {
8347
+ return drain(webcrypto.digest(algorithm, data.dataStart, data.byteLength));
8165
8348
  }
8166
8349
 
8350
+ // \`format\` is an \`FMT_*\` selector const (FMT_RAW / FMT_PKCS8 / FMT_SPKI).
8167
8351
  importKey(
8168
- format: string,
8352
+ format: i32,
8169
8353
  keyData: Uint8Array,
8170
8354
  algorithm: AlgorithmParams,
8171
8355
  extractable: bool,
8172
8356
  usages: i32
8173
8357
  ): CryptoKey {
8174
- let fmt = formatId(format);
8175
- if (fmt < 0) throw new Error("Unknown key format: " + format);
8176
- if (fmt == FMT_JWK) throw new Error("jwk key format is not supported");
8358
+ if (format == FMT_JWK) throw new Error("jwk key format is not supported");
8177
8359
  let p = algorithm.pack();
8178
8360
  let alg = load<i32>(p.dataStart); // first packed field is the alg id
8179
8361
  let handle = webcrypto.importKey(
8180
- fmt,
8362
+ format,
8181
8363
  keyData.dataStart,
8182
8364
  keyData.byteLength,
8183
8365
  p.dataStart,
@@ -8188,18 +8370,17 @@ export class SubtleCrypto {
8188
8370
  if (handle < 0) throw new Error(cryptoError(handle));
8189
8371
 
8190
8372
  let type: string;
8191
- if (fmt == FMT_PKCS8) type = "private";
8192
- else if (fmt == FMT_SPKI) type = "public";
8373
+ if (format == FMT_PKCS8) type = "private";
8374
+ else if (format == FMT_SPKI) type = "public";
8193
8375
  else type = isSymmetricAlg(alg) ? "secret" : "public";
8194
8376
 
8195
8377
  return new CryptoKey(handle, type, extractable, alg, usages);
8196
8378
  }
8197
8379
 
8198
- exportKey(format: string, key: CryptoKey): Uint8Array {
8199
- let fmt = formatId(format);
8200
- if (fmt < 0) throw new Error("Unknown key format: " + format);
8201
- if (fmt == FMT_JWK) throw new Error("jwk key format is not supported");
8202
- return drain(webcrypto.exportKey(fmt, key.handle));
8380
+ // \`format\` is an \`FMT_*\` selector const (FMT_RAW / FMT_PKCS8 / FMT_SPKI).
8381
+ exportKey(format: i32, key: CryptoKey): Uint8Array {
8382
+ if (format == FMT_JWK) throw new Error("jwk key format is not supported");
8383
+ return drain(webcrypto.exportKey(format, key.handle));
8203
8384
  }
8204
8385
 
8205
8386
  encrypt(algorithm: AlgorithmParams, key: CryptoKey, data: Uint8Array): Uint8Array {
@@ -8261,7 +8442,7 @@ export class SubtleCrypto {
8261
8442
  usages: i32
8262
8443
  ): CryptoKey {
8263
8444
  let bits = this.deriveBits(algorithm, baseKey, lengthBits);
8264
- return this.importKey("raw", bits, derivedKeyAlgorithm, extractable, usages);
8445
+ return this.importKey(FMT_RAW, bits, derivedKeyAlgorithm, extractable, usages);
8265
8446
  }
8266
8447
  }
8267
8448
  `,data:`/**
@@ -18439,6 +18620,317 @@ export namespace table {
18439
18620
  throw new Error(E_NOTIMPLEMENTED);
18440
18621
  }
18441
18622
  }
18623
+ `,toildb:`// ToilDB: the developer-facing edge-database API.
18624
+ //
18625
+ // \`@database class App { @collection(...) users!: Record<User, UserId>; ... }\`
18626
+ // declares logical collections; the compiler (see parser \`injectDatabaseBinding\`)
18627
+ // synthesizes a \`@global App\` singleton whose fields are these typed handles,
18628
+ // resolved to numeric host handles once at module init.
18629
+ //
18630
+ // The handles marshal \`@data\` keys/values to the \`env.data.*\` host imports
18631
+ // (\`bindings/toildb\`). Keys and values are \`@data\` types (they have the injected
18632
+ // \`encode(): Uint8Array\` + \`decodeInto(buf): void\` instance methods). Both
18633
+ // encode and decode go through INSTANCE methods on the generic type parameter,
18634
+ // which AssemblyScript resolves at specialization (it cannot call the \`decode\`
18635
+ // static through a type parameter, but \`instantiate<V>()\` + \`v.decodeInto(buf)\`
18636
+ // works). Value types must be default-constructible.
18637
+
18638
+ import { toildbHost } from "bindings/toildb";
18639
+ import { DataWriter } from "data";
18640
+
18641
+ /// Resolve a \`"<db>/<collection>"\` name to its numeric host handle. Called once
18642
+ /// per collection at module init by the generated \`App\` binding.
18643
+ export function __toildbResolve(name: string): u32 {
18644
+ const nb = Uint8Array.wrap(String.UTF8.encode(name));
18645
+ const out = new Uint8Array(4);
18646
+ toildbHost.resolveCollection(nb.dataStart, nb.byteLength, out.dataStart);
18647
+ return load<u32>(out.dataStart);
18648
+ }
18649
+
18650
+ /// Pull the last stashed variable-length result of \`len\` bytes into a buffer.
18651
+ function __toildbTake(len: i32): Uint8Array {
18652
+ const buf = new Uint8Array(len);
18653
+ toildbHost.takeResult(buf.dataStart, len);
18654
+ return buf;
18655
+ }
18656
+
18657
+ /// Pull a stashed result whose length is NOT known up front (e.g. the owner
18658
+ /// returned by a failed \`claim\`): grow the buffer until \`take_result\` fits.
18659
+ function __toildbTakeGrow(): Uint8Array {
18660
+ let cap = 256;
18661
+ let buf = new Uint8Array(cap);
18662
+ let n = toildbHost.takeResult(buf.dataStart, cap);
18663
+ while (n == -1) {
18664
+ cap = cap * 2;
18665
+ buf = new Uint8Array(cap);
18666
+ n = toildbHost.takeResult(buf.dataStart, cap);
18667
+ }
18668
+ return buf.subarray(0, n);
18669
+ }
18670
+
18671
+ /// A mutable keyed-entity collection (spec 7.1). \`V\` is the \`@data\` value type,
18672
+ /// \`K\` the \`@data\` key type.
18673
+ export class Record<V, K> {
18674
+ private __handle: u32;
18675
+
18676
+ constructor(handle: u32) {
18677
+ this.__handle = handle;
18678
+ }
18679
+
18680
+ /// Return the record, or \`null\` if it does not exist.
18681
+ get(key: K): V | null {
18682
+ const kb = key.encode();
18683
+ const status = toildbHost.get(this.__handle, kb.dataStart, kb.byteLength);
18684
+ if (status < 0) return null;
18685
+ const v = instantiate<V>();
18686
+ v.decodeInto(__toildbTake(status));
18687
+ return v;
18688
+ }
18689
+
18690
+ /// Like \`get\`, but traps if the record is absent.
18691
+ require(key: K): V {
18692
+ const v = this.get(key);
18693
+ if (v == null) unreachable();
18694
+ return v!;
18695
+ }
18696
+
18697
+ /// Bounded multi-get: one op, one result per key (in order), each the value
18698
+ /// or \`null\` if absent. The key count is capped by the request budget.
18699
+ getMany(keys: K[]): Array<V | null> {
18700
+ const w = new DataWriter();
18701
+ w.writeU32(<u32>keys.length);
18702
+ for (let i = 0, n = keys.length; i < n; i++) {
18703
+ w.writeBytes(keys[i].encode());
18704
+ }
18705
+ const blob = w.toBytes();
18706
+ const status = toildbHost.getMany(this.__handle, blob.dataStart, blob.byteLength);
18707
+ if (status < 0) unreachable();
18708
+ const out = __toildbTake(status);
18709
+ const results = new Array<V | null>();
18710
+ let off: i32 = 0;
18711
+ const count = load<u32>(out.dataStart + off);
18712
+ off += 4;
18713
+ for (let i: u32 = 0; i < count; i++) {
18714
+ const present = load<u8>(out.dataStart + off);
18715
+ off += 1;
18716
+ if (present == 0) {
18717
+ results.push(null);
18718
+ continue;
18719
+ }
18720
+ const len = <i32>load<u32>(out.dataStart + off);
18721
+ off += 4;
18722
+ const v = instantiate<V>();
18723
+ v.decodeInto(out.subarray(off, off + len));
18724
+ off += len;
18725
+ results.push(v);
18726
+ }
18727
+ return results;
18728
+ }
18729
+
18730
+ /// Whether the record exists.
18731
+ exists(key: K): bool {
18732
+ const kb = key.encode();
18733
+ return toildbHost.exists(this.__handle, kb.dataStart, kb.byteLength) == 1;
18734
+ }
18735
+
18736
+ /// Create the record if absent. Returns false if it already existed.
18737
+ create(key: K, value: V): bool {
18738
+ const kb = key.encode();
18739
+ const vb = value.encode();
18740
+ return toildbHost.create(
18741
+ this.__handle, kb.dataStart, kb.byteLength, vb.dataStart, vb.byteLength, 0
18742
+ ) == 0;
18743
+ }
18744
+
18745
+ /// Apply a write through the key's home cell; returns the stored record.
18746
+ patch(key: K, value: V): V {
18747
+ const kb = key.encode();
18748
+ const vb = value.encode();
18749
+ const status = toildbHost.patch(
18750
+ this.__handle, kb.dataStart, kb.byteLength, vb.dataStart, vb.byteLength, 0
18751
+ );
18752
+ if (status < 0) unreachable();
18753
+ const v = instantiate<V>();
18754
+ v.decodeInto(__toildbTake(status));
18755
+ return v;
18756
+ }
18757
+
18758
+ /// Delete the record (idempotent).
18759
+ delete(key: K): void {
18760
+ const kb = key.encode();
18761
+ toildbHost.del(this.__handle, kb.dataStart, kb.byteLength, 0);
18762
+ }
18763
+
18764
+ /// Atomic fetch-and-delete (consume-once); returns the prior value or \`null\`.
18765
+ getDelete(key: K): V | null {
18766
+ const kb = key.encode();
18767
+ const status = toildbHost.getDelete(this.__handle, kb.dataStart, kb.byteLength, 0);
18768
+ if (status < 0) return null;
18769
+ const v = instantiate<V>();
18770
+ v.decodeInto(__toildbTake(status));
18771
+ return v;
18772
+ }
18773
+ }
18774
+
18775
+ /// A precomputed, read-optimized projection (spec 7.2): home pages,
18776
+ /// leaderboards, rendered fragments. Read by any function kind; PUBLISHED only
18777
+ /// by a \`@derive\`/\`@job\` (the host kind gate enforces it). \`V\` is the \`@data\`
18778
+ /// value type, \`K\` the \`@data\` key type.
18779
+ export class View<V, K> {
18780
+ private __handle: u32;
18781
+
18782
+ constructor(handle: u32) {
18783
+ this.__handle = handle;
18784
+ }
18785
+
18786
+ /// The published view for \`key\`, or \`null\` if none has been published.
18787
+ get(key: K): V | null {
18788
+ const kb = key.encode();
18789
+ const status = toildbHost.viewGet(this.__handle, kb.dataStart, kb.byteLength);
18790
+ if (status < 0) return null;
18791
+ const v = instantiate<V>();
18792
+ v.decodeInto(__toildbTake(status));
18793
+ return v;
18794
+ }
18795
+
18796
+ /// Like \`get\`, but traps if no view is published.
18797
+ require(key: K): V {
18798
+ const v = this.get(key);
18799
+ if (v == null) unreachable();
18800
+ return v!;
18801
+ }
18802
+
18803
+ /// Publish (overwrite) the view for \`key\`. Derive/job only; the host assigns
18804
+ /// the version so a later publish always supersedes an earlier one.
18805
+ publish(key: K, value: V): void {
18806
+ const kb = key.encode();
18807
+ const vb = value.encode();
18808
+ toildbHost.viewPublish(
18809
+ this.__handle, kb.dataStart, kb.byteLength, vb.dataStart, vb.byteLength, 0
18810
+ );
18811
+ }
18812
+ }
18813
+
18814
+ /// The result of a \`unique.claim\` (spec 8.6). \`claimed\` is true when the caller
18815
+ /// owns the key (a fresh claim or an idempotent re-claim of its own); when
18816
+ /// false, \`owner\` is the value that currently holds the key.
18817
+ export class ClaimResult<V> {
18818
+ constructor(public claimed: bool, public owner: V | null) {}
18819
+ }
18820
+
18821
+ /// A globally-unique claim collection (spec 7.6): username, email, slug, ...
18822
+ /// \`V\` is the \`@data\` OWNER value type, \`K\` the \`@data\` claim-key type.
18823
+ export class Unique<V, K> {
18824
+ private __handle: u32;
18825
+
18826
+ constructor(handle: u32) {
18827
+ this.__handle = handle;
18828
+ }
18829
+
18830
+ /// The value that owns \`key\`, or \`null\` if unclaimed.
18831
+ lookup(key: K): V | null {
18832
+ const kb = key.encode();
18833
+ const status = toildbHost.uniqueLookup(this.__handle, kb.dataStart, kb.byteLength);
18834
+ if (status < 0) return null;
18835
+ const v = instantiate<V>();
18836
+ v.decodeInto(__toildbTake(status));
18837
+ return v;
18838
+ }
18839
+
18840
+ /// Claim \`key\` for \`value\`. Returns whether the caller owns it, and (when
18841
+ /// another owns it) who.
18842
+ claim(key: K, value: V): ClaimResult<V> {
18843
+ const kb = key.encode();
18844
+ const vb = value.encode();
18845
+ const tag = toildbHost.uniqueClaim(
18846
+ this.__handle, kb.dataStart, kb.byteLength, vb.dataStart, vb.byteLength, 0
18847
+ );
18848
+ if (tag < 0) unreachable();
18849
+ if (tag == 1) {
18850
+ // AlreadyClaimed: the current owner is stashed.
18851
+ const owner = instantiate<V>();
18852
+ owner.decodeInto(__toildbTakeGrow());
18853
+ return new ClaimResult<V>(false, owner);
18854
+ }
18855
+ // 0 Claimed, 2 AlreadyOwnedByCaller -> the caller owns it.
18856
+ return new ClaimResult<V>(true, null);
18857
+ }
18858
+
18859
+ /// Release \`key\` (only the current owner may; a non-owner release traps).
18860
+ release(key: K, value: V): void {
18861
+ const kb = key.encode();
18862
+ const vb = value.encode();
18863
+ toildbHost.uniqueRelease(
18864
+ this.__handle, kb.dataStart, kb.byteLength, vb.dataStart, vb.byteLength, 0
18865
+ );
18866
+ }
18867
+ }
18868
+
18869
+ /// A commutative integer counter (spec 7.4): likes, view counts, inventory.
18870
+ /// \`K\` is the \`@data\` key type; the value is a host-aggregated i64 rollup (there
18871
+ /// is no \`set\`, only \`add\` and \`get\`, so concurrent deltas never lose writes).
18872
+ export class Counter<K> {
18873
+ private __handle: u32;
18874
+
18875
+ constructor(handle: u32) {
18876
+ this.__handle = handle;
18877
+ }
18878
+
18879
+ /// The current sum (0 if no deltas have been applied).
18880
+ get(key: K): i64 {
18881
+ const kb = key.encode();
18882
+ const status = toildbHost.counterGet(this.__handle, kb.dataStart, kb.byteLength);
18883
+ if (status < 0) unreachable();
18884
+ const buf = __toildbTake(status);
18885
+ return load<i64>(buf.dataStart);
18886
+ }
18887
+
18888
+ /// Apply a (possibly negative) delta; saturates at the i64 bounds.
18889
+ add(key: K, delta: i64): void {
18890
+ const kb = key.encode();
18891
+ toildbHost.counterAdd(this.__handle, kb.dataStart, kb.byteLength, delta, 0);
18892
+ }
18893
+ }
18894
+
18895
+ /// An append-only event log (spec 7.5): activity feeds, audit trails, the
18896
+ /// fact stream a \`@derive\` consumes. \`V\` is the \`@data\` event type, \`K\` the
18897
+ /// \`@data\` stream-key type.
18898
+ export class Events<V, K> {
18899
+ private __handle: u32;
18900
+
18901
+ constructor(handle: u32) {
18902
+ this.__handle = handle;
18903
+ }
18904
+
18905
+ /// Append an event to the stream.
18906
+ append(key: K, event: V): void {
18907
+ const kb = key.encode();
18908
+ const eb = event.encode();
18909
+ toildbHost.append(this.__handle, kb.dataStart, kb.byteLength, eb.dataStart, eb.byteLength, 0);
18910
+ }
18911
+
18912
+ /// The newest \`limit\` events, newest first. Decodes each framed event into a
18913
+ /// \`V\`. The host frames them as \`u32 count\` then per event \`u32 len + bytes\`.
18914
+ latest(key: K, limit: i32): V[] {
18915
+ const kb = key.encode();
18916
+ const status = toildbHost.latest(this.__handle, kb.dataStart, kb.byteLength, limit);
18917
+ if (status < 0) unreachable();
18918
+ const blob = __toildbTake(status);
18919
+ const out = new Array<V>();
18920
+ let off: i32 = 0;
18921
+ const count = load<u32>(blob.dataStart + off);
18922
+ off += 4;
18923
+ for (let i: u32 = 0; i < count; i++) {
18924
+ const len = <i32>load<u32>(blob.dataStart + off);
18925
+ off += 4;
18926
+ const ev = instantiate<V>();
18927
+ ev.decodeInto(blob.subarray(off, off + len));
18928
+ out.push(ev);
18929
+ off += len;
18930
+ }
18931
+ return out;
18932
+ }
18933
+ }
18442
18934
  `,typedarray:`import { COMPARATOR, SORT } from "./util/sort";
18443
18935
  import { E_INDEXOUTOFRANGE, E_INVALIDLENGTH, E_NOTIMPLEMENTED } from "./util/error";
18444
18936
  import { joinIntegerArray, joinFloatArray } from "./util/string";
@@ -28923,11 +29415,14 @@ declare class X25519ImportParams extends AlgorithmParams {}
28923
29415
  declare class EcdhParams extends AlgorithmParams {
28924
29416
  constructor(alg: i32, publicKeyHandle: i32);
28925
29417
  }
28926
- /** Synchronous SubtleCrypto (no Promises). Returns values directly. */
29418
+ /** Synchronous SubtleCrypto (no Promises). Returns values directly. The hash and
29419
+ * key-format arguments are typed ABI ids (no magic strings): pass an \`ALG_SHA_*\`
29420
+ * const to \`digest\`, and an \`FMT_*\` const (\`FMT_RAW\` / \`FMT_PKCS8\` / \`FMT_SPKI\`)
29421
+ * to \`importKey\` / \`exportKey\`. */
28927
29422
  declare class SubtleCrypto {
28928
- digest(algorithm: string, data: Uint8Array): Uint8Array;
28929
- importKey(format: string, keyData: Uint8Array, algorithm: AlgorithmParams, extractable: bool, usages: i32): CryptoKey;
28930
- exportKey(format: string, key: CryptoKey): Uint8Array;
29423
+ digest(algorithm: i32, data: Uint8Array): Uint8Array;
29424
+ importKey(format: i32, keyData: Uint8Array, algorithm: AlgorithmParams, extractable: bool, usages: i32): CryptoKey;
29425
+ exportKey(format: i32, key: CryptoKey): Uint8Array;
28931
29426
  encrypt(algorithm: AlgorithmParams, key: CryptoKey, data: Uint8Array): Uint8Array;
28932
29427
  decrypt(algorithm: AlgorithmParams, key: CryptoKey, data: Uint8Array): Uint8Array;
28933
29428
  sign(algorithm: AlgorithmParams, key: CryptoKey, data: Uint8Array): Uint8Array;
@@ -28938,6 +29433,8 @@ declare class SubtleCrypto {
28938
29433
 
28939
29434
  // Algorithm / format / curve / usage ids (the Web Crypto ABI contract).
28940
29435
  declare const ALG_SHA_1: i32, ALG_SHA_256: i32, ALG_SHA_384: i32, ALG_SHA_512: i32;
29436
+ declare const ALG_SHA3_256: i32, ALG_SHA3_384: i32, ALG_SHA3_512: i32;
29437
+ declare const FMT_RAW: i32, FMT_PKCS8: i32, FMT_SPKI: i32, FMT_JWK: i32;
28941
29438
  declare const ALG_AES_GCM: i32, ALG_AES_CBC: i32, ALG_AES_CTR: i32, ALG_AES_KW: i32;
28942
29439
  declare const ALG_HMAC: i32, ALG_ECDSA: i32, ALG_ED25519: i32, ALG_ECDH: i32, ALG_X25519: i32, ALG_HKDF: i32, ALG_PBKDF2: i32;
28943
29440
  declare const CURVE_P256: i32, CURVE_P384: i32;