toilscript 0.1.51 → 0.1.53
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.generated.d.ts +14 -0
- package/dist/cli.js +140 -82
- package/dist/cli.js.map +2 -2
- package/dist/importmap.json +2 -2
- package/dist/toilscript.generated.d.ts +14 -0
- package/dist/toilscript.js +37 -35
- package/dist/toilscript.js.map +3 -3
- package/dist/web.js +3 -3
- package/package.json +1 -1
- package/std/assembly/bindings/toildb.ts +4 -0
- package/std/assembly/toildb.ts +132 -78
- package/std/assembly/toilscript.d.ts +64 -44
package/dist/cli.generated.d.ts
CHANGED
|
@@ -3398,6 +3398,14 @@ declare module "types:toilscript/src/parser" {
|
|
|
3398
3398
|
* `AuthUser` (a natural compile error).
|
|
3399
3399
|
*/
|
|
3400
3400
|
private injectUserBinding;
|
|
3401
|
+
/** Built-in auth (`server.auth`) reserves `toilUserId` + `username` as the FIRST two `@user` fields, so an
|
|
3402
|
+
* app can add its own fields to the authenticated user without repeating the identity boilerplate. Errors
|
|
3403
|
+
* if the class already declares either reserved name. Prepended toilUserId-first so `AuthService.userId()`
|
|
3404
|
+
* recovers the stable id straight from the session codec. Runs before `injectDataCodec` so the codec
|
|
3405
|
+
* covers the injected fields. */
|
|
3406
|
+
private injectAuthIdentityFields;
|
|
3407
|
+
/** Parse one synthesized field for {@link injectAuthIdentityFields}: returns the member (does not push). */
|
|
3408
|
+
private parseAuthField;
|
|
3401
3409
|
/** True if `decorators` carries a decorator of `kind` (e.g. `@auth`). */
|
|
3402
3410
|
private hasDecoratorKind;
|
|
3403
3411
|
/** The mount prefix from `@rest("api")` -> "/api"; "" for the bare/object form (root). */
|
|
@@ -9501,6 +9509,10 @@ declare module "types:toilscript/src/compiler" {
|
|
|
9501
9509
|
/** Toil compile surface mode. null = default request artifact. "hot" = request + stream surface.
|
|
9502
9510
|
* "cold" = daemon surface. */
|
|
9503
9511
|
targetMode: string | null;
|
|
9512
|
+
/** Built-in auth (`server.auth`): inject the reserved `toilUserId` + `username` identity fields into the
|
|
9513
|
+
* single `@user` so an app can extend the authenticated user with its own fields. Set by the toiljs build
|
|
9514
|
+
* when it detects the app declares its own `@user` under `server.auth`. */
|
|
9515
|
+
authUser: boolean;
|
|
9504
9516
|
/** Runtime type. Defaults to Incremental GC. */
|
|
9505
9517
|
runtime: Runtime;
|
|
9506
9518
|
/** If true, indicates that debug information will be emitted by Binaryen. */
|
|
@@ -10135,6 +10147,8 @@ declare module "types:toilscript/src/index-wasm" {
|
|
|
10135
10147
|
export function setNoUnsafe(options: Options, noUnsafe: boolean): void;
|
|
10136
10148
|
/** Sets the `targetMode` option ("hot", "cold", or null for the default request artifact). */
|
|
10137
10149
|
export function setTargetMode(options: Options, targetMode: string | null): void;
|
|
10150
|
+
/** Enables built-in-auth `@user` field injection (reserved `toilUserId` + `username`). */
|
|
10151
|
+
export function setAuthUser(options: Options, authUser: boolean): void;
|
|
10138
10152
|
/** Sets the `lowMemoryLimit` option. */
|
|
10139
10153
|
export function setLowMemoryLimit(options: Options, lowMemoryLimit: number): void;
|
|
10140
10154
|
/** Sets the `exportRuntime` option. */
|
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* SPDX-License-Identifier: Apache-2.0
|
|
6
6
|
*/
|
|
7
7
|
var le=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var Ve=Object.prototype.hasOwnProperty;var dn=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(a){throw n=[a],a}};var nn=(e,t)=>{for(var n in t)le(e,n,{get:t[n],enumerable:!0})},se=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Pe(t))!Ve.call(e,s)&&s!==n&&le(e,s,{get:()=>t[s],enumerable:!(a=Me(t,s))||a.enumerable});return e},In=(e,t,n)=>(se(e,t,"default"),n&&se(n,t,"default"));var ue={};nn(ue,{promises:()=>Ge});var Ge,fe=dn(()=>{"use strict";Ge={}});var ce={};nn(ce,{createRequire:()=>He});function He(){return function(t){throw new Error(`Cannot find module: '${t}'`)}}var de=dn(()=>{"use strict"});var kn={};nn(kn,{argv:()=>Xe,cwd:()=>On,exit:()=>qe,hrtime:()=>Ye,platform:()=>je,umask:()=>Ke});function On(){return"."}function Ke(){return 0}function qe(e=0){throw Error(`exit ${e}`)}function Ye(e){var t=We.call(pe),n=Math.floor(t*.001),a=Math.floor(t*1e6-n*1e9);return e&&(n-=e[0],a-=e[1],a<0&&(n--,a+=1e9)),[n,a]}var je,Xe,pe,We,Ln=dn(()=>{"use strict";je="linux";Xe=[];pe=globalThis.performance||{},We=pe.now||function(){return new Date().getTime()}});var Nn={};nn(Nn,{basename:()=>et,delimiter:()=>at,dirname:()=>nt,extname:()=>tt,format:()=>it,isAbsolute:()=>Ze,join:()=>$e,normalize:()=>xe,parse:()=>rt,relative:()=>Qe,resolve:()=>pn,sep:()=>Rn,win32:()=>ot});function G(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function he(e,t){for(var n="",a=0,s=-1,o=0,c,d=0;d<=e.length;++d){if(d<e.length)c=e.charCodeAt(d);else{if(c===47)break;c=47}if(c===47){if(!(s===d-1||o===1))if(s!==d-1&&o===2){if(n.length<2||a!==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="",a=0):(n=n.slice(0,x),a=n.length-1-n.lastIndexOf("/")),s=d,o=0;continue}}else if(n.length===2||n.length===1){n="",a=0,s=d,o=0;continue}}t&&(n.length>0?n+="/..":n="..",a=2)}else n.length>0?n+="/"+e.slice(s+1,d):n=e.slice(s+1,d),a=d-s-1;s=d,o=0}else c===46&&o!==-1?++o:o=-1}return n}function Je(e,t){var n=t.dir||t.root,a=t.base||(t.name||"")+(t.ext||"");return n?n===t.root?n+a:n+e+a:a}function pn(){for(var e="",t=!1,n,a=arguments.length-1;a>=-1&&!t;a--){var s;a>=0?s=arguments[a]:(n===void 0&&(n=On()),s=n),G(s),s.length!==0&&(e=s+"/"+e,t=s.charCodeAt(0)===47)}return e=he(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."}function xe(e){if(G(e),e.length===0)return".";var t=e.charCodeAt(0)===47,n=e.charCodeAt(e.length-1)===47;return e=he(e,!t),e.length===0&&!t&&(e="."),e.length>0&&n&&(e+="/"),t?"/"+e:e}function Ze(e){return G(e),e.length>0&&e.charCodeAt(0)===47}function $e(){if(arguments.length===0)return".";for(var e,t=0;t<arguments.length;++t){var n=arguments[t];G(n),n.length>0&&(e===void 0?e=n:e+="/"+n)}return e===void 0?".":xe(e)}function Qe(e,t){if(G(e),G(t),e===t||(e=pn(e),t=pn(t),e===t))return"";if(e===".")return t;for(var n=1;n<e.length&&e.charCodeAt(n)===47;++n);for(var a=e.length,s=a-n,o=1;o<t.length&&t.charCodeAt(o)===47;++o);for(var c=t.length,d=c-o,x=s<d?s:d,b=-1,p=0;p<=x;++p){if(p===x){if(d>x){if(t.charCodeAt(o+p)===47)return t.slice(o+p+1);if(p===0)return t.slice(o+p)}else s>x&&(e.charCodeAt(n+p)===47?b=p:p===0&&(b=0));break}var g=e.charCodeAt(n+p),y=t.charCodeAt(o+p);if(g!==y)break;g===47&&(b=p)}var m="";for(p=n+b+1;p<=a;++p)(p===a||e.charCodeAt(p)===47)&&(m.length===0?m+="..":m+="/..");return m.length>0?m+t.slice(o+b):(o+=b,t.charCodeAt(o)===47&&++o,t.slice(o))}function nt(e){if(G(e),e.length===0)return".";for(var t=e.charCodeAt(0),n=t===47,a=-1,s=!0,o=e.length-1;o>=1;--o)if(t=e.charCodeAt(o),t===47){if(!s){a=o;break}}else s=!1;return a===-1?n?"/":".":n&&a===1?"//":e.slice(0,a)}function et(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');G(e);var n=0,a=-1,s=!0,o;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var c=t.length-1,d=-1;for(o=e.length-1;o>=0;--o){var x=e.charCodeAt(o);if(x===47){if(!s){n=o+1;break}}else d===-1&&(s=!1,d=o+1),c>=0&&(x===t.charCodeAt(c)?--c===-1&&(a=o):(c=-1,a=d))}return n===a?a=d:a===-1&&(a=e.length),e.slice(n,a)}else{for(o=e.length-1;o>=0;--o)if(e.charCodeAt(o)===47){if(!s){n=o+1;break}}else a===-1&&(s=!1,a=o+1);return a===-1?"":e.slice(n,a)}}function tt(e){G(e);for(var t=-1,n=0,a=-1,s=!0,o=0,c=e.length-1;c>=0;--c){var d=e.charCodeAt(c);if(d===47){if(!s){n=c+1;break}continue}a===-1&&(s=!1,a=c+1),d===46?t===-1?t=c:o!==1&&(o=1):t!==-1&&(o=-1)}return t===-1||a===-1||o===0||o===1&&t===a-1&&t===n+1?"":e.slice(t,a)}function it(e){if(e===null||typeof e!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return Je("/",e)}function rt(e){G(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return t;var n=e.charCodeAt(0),a=n===47,s;a?(t.root="/",s=1):s=0;for(var o=-1,c=0,d=-1,x=!0,b=e.length-1,p=0;b>=s;--b){if(n=e.charCodeAt(b),n===47){if(!x){c=b+1;break}continue}d===-1&&(x=!1,d=b+1),n===46?o===-1?o=b:p!==1&&(p=1):o!==-1&&(p=-1)}return o===-1||d===-1||p===0||p===1&&o===d-1&&o===c+1?d!==-1&&(c===0&&a?t.base=t.name=e.slice(1,d):t.base=t.name=e.slice(c,d)):(c===0&&a?(t.name=e.slice(1,o),t.base=e.slice(1,d)):(t.name=e.slice(c,o),t.base=e.slice(c,d)),t.ext=e.slice(o,d)),c>0?t.dir=e.slice(0,c-1):a&&(t.dir="/"),t}var Rn,at,ot,Un=dn(()=>{"use strict";Ln();Rn="/",at=":",ot=null});var ge={};nn(ge,{pathToFileURL:()=>lt});function st(e){return e.replace(/%/g,"%25").replace(/\\/g,"%5C").replace(/\n/g,"%0A").replace(/\r/g,"%0D").replace(/\t/g,"%09")}function lt(e){let t=pn(e);e.charCodeAt(e.length-1)===47&&t[t.length-1]!==Rn&&(t+="/");let n=new URL("file://");return n.pathname=st(t),n}var me=dn(()=>{"use strict";Un()});var Yn={};nn(Yn,{Stats:()=>zn,checkDiagnostics:()=>mn,compileString:()=>Dt,configToArguments:()=>Wn,createMemoryStream:()=>Xn,default:()=>Yn,defaultOptimizeLevel:()=>we,defaultShrinkLevel:()=>Be,definitionFiles:()=>Bt,libraryFiles:()=>j,libraryPrefix:()=>V,main:()=>De,options:()=>wt,tscOptions:()=>It,version:()=>Kn});var ut=Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]",M,sn,E,P,hn;ut?(M=await import("fs"),sn=await import("module"),E=await import("path"),P=globalThis.process,hn=await import("url")):(M=await Promise.resolve().then(()=>(fe(),ue)),sn=await Promise.resolve().then(()=>(de(),ce)),E=await Promise.resolve().then(()=>(Un(),Nn)),P=await Promise.resolve().then(()=>(Ln(),kn)),hn=await Promise.resolve().then(()=>(me(),ge)));var _n=typeof process<"u"&&process||{},ft=_n.env&&"CI"in _n.env,ct="\x1B[90m",dt="\x1B[91m",pt="\x1B[92m",ht="\x1B[93m",xt="\x1B[94m",gt="\x1B[95m",mt="\x1B[96m",bt="\x1B[97m",W="\x1B[0m",en=class{constructor(t){this.stream=t,this.enabled=!!(this.stream&&this.stream.isTTY||ft)}gray(t){return this.enabled?ct+t+W:t}red(t){return this.enabled?dt+t+W:t}green(t){return this.enabled?pt+t+W:t}yellow(t){return this.enabled?ht+t+W:t}blue(t){return this.enabled?xt+t+W:t}magenta(t){return this.enabled?gt+t+W:t}cyan(t){return this.enabled?mt+t+W:t}white(t){return this.enabled?bt+t+W:t}},Tn=new en(_n.stdout),Lt=new en(_n.stderr);function yt(e){for(var t=0,n=0,a=e.length;n<a;++n){let s=e.charCodeAt(n);s<128?t+=1:s<2048?t+=2:(s&64512)===55296&&n+1<a&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3}return t}function vt(e,t,n){var a=n-t;if(a<1)return"";for(var s=null,o=[],c=0,d;t<n;)d=e[t++],d<128?o[c++]=d:d>191&&d<224?o[c++]=(d&31)<<6|e[t++]&63:d>239&&d<365?(d=((d&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,o[c++]=55296+(d>>10),o[c++]=56320+(d&1023)):o[c++]=(d&15)<<12|(e[t++]&63)<<6|e[t++]&63,c>=8192&&((s||(s=[])).push(String.fromCharCode(...o)),c=0);return s?(c&&s.push(String.fromCharCode(...o.slice(0,c))),s.join("")):String.fromCharCode(...o.slice(0,c))}function Ft(e,t,n){for(var a=n,s=0,o=e.length;s<o;++s){let c=e.charCodeAt(s),d;c<128?t[n++]=c:c<2048?(t[n++]=c>>6|192,t[n++]=c&63|128):(c&64512)===55296&&s+1<o&&((d=e.charCodeAt(s+1))&64512)===56320?(c=65536+((c&1023)<<10)+(d&1023),++s,t[n++]=c>>18|240,t[n++]=c>>12&63|128,t[n++]=c>>6&63|128,t[n++]=c&63|128):(t[n++]=c>>12|224,t[n++]=c>>6&63|128,t[n++]=c&63|128)}return n-a}var Cn={length:yt,read:vt,write:Ft};var be=sn.createRequire(import.meta.url);function ve(e,t,n=!0){var a={},s=[],o=[],c=[],d={};Object.keys(t).forEach(p=>{if(!p.startsWith(" ")){var g=t[p];g.alias!=null&&(typeof g.alias=="string"?d[g.alias]=p:Array.isArray(g.alias)&&g.alias.forEach(y=>d[y]=p)),n&&g.default!=null&&(a[p]=g.default)}});for(var x=0,b=(e=e.slice()).length;x<b;++x){let p=e[x];if(p=="--"){++x;break}let g=/^(?:(-\w)(?:=(.*))?|(--\w{2,})(?:=(.*))?)$/.exec(p),y,m;if(g)t[p]?y=t[m=p]:g[1]!=null?(y=t[m=d[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(p.charCodeAt(0)==45)y=t[m=p];else{o.push(p);continue}if(y)if(y.value)Object.keys(y.value).forEach(i=>a[i]=y.value[i]);else if(y.type==null||y.type==="b")a[m]=!0;else if(x+1<e.length&&e[x+1].charCodeAt(0)!=45)switch(y.type){case"i":a[m]=parseInt(e[++x],10);break;case"I":a[m]=(a[m]||[]).concat(parseInt(e[++x],10));break;case"f":a[m]=parseFloat(e[++x]);break;case"F":a[m]=(a[m]||[]).concat(parseFloat(e[++x]));break;case"s":a[m]=String(e[++x]);break;case"S":a[m]=(a[m]||[]).concat(e[++x].split(","));break;default:s.push(p),--x}else switch(y.type){case"i":case"f":a[m]=y.default||0;break;case"s":a[m]=y.default||"";break;case"I":case"F":case"S":a[m]=y.default||[];break;default:s.push(p)}else s.push(p)}for(;x<b;)c.push(e[x++]);return n&&Pn(t,a),{options:a,unknown:s,arguments:o,trailing:c}}function Fe(e,t){t||(t={});var n=t.indent||2,a=t.padding||24,s=t.eol||`
|
|
8
|
-
`,o={},c=[];Object.keys(e).forEach(b=>{var p=e[b];if(p.description!=null){for(var g="";g.length<n;)g+=" ";for(g+="--"+b,p.alias&&(g+=", -"+p.alias);g.length<a;)g+=" ";var y;!t.noCategories&&p.category?(y=o[p.category])||(o[p.category]=y=[]):y=c,Array.isArray(p.description)?y.push(g+p.description[0]+p.description.slice(1).map(m=>{for(let i=0;i<a;++i)m=" "+m;return s+m}).join("")):y.push(g+p.description)}});var d=[],x=!1;return Object.keys(o).forEach(b=>{x=!0,d.push(s+" "+Tn.gray(b)+s),d.push(o[b].join(s))}),x&&c.length&&d.push(s+" "+Tn.gray("Other")+s),d.push(c.join(s)),d.join(s)}function ye(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 Mn(e,t,n,a){let s={};for(let[o,{type:c,mutuallyExclusive:d,isPath:x,useNodeResolution:b,cliOnly:p}]of Object.entries(e)){let g=ye(t[o],c),y=ye(n[o],c);if(g==null){if(y!=null){if(p)continue;if(Array.isArray(y)){let m;x&&(y=y.map(i=>tn(i,a,b))),d!=null&&(m=t[d])?s[o]=y.filter(i=>!m.includes(i)):s[o]=y.slice()}else x&&(y=tn(y,a,b)),s[o]=y}}else if(y==null)Array.isArray(g)?s[o]=g.slice():s[o]=g;else if(Array.isArray(g)){if(p){s[o]=g.slice();continue}let m;x&&(y=y.map(i=>tn(i,a,b))),d!=null&&(m=t[d])?s[o]=[...g,...y.filter(i=>!g.includes(i)&&!m.includes(i))]:s[o]=[...g,...y.filter(i=>!g.includes(i))]}else s[o]=g}return s}function Et(e){let t=E.parse(e);return t.root||(t.root="./"),E.format(t)}function tn(e,t,n=!1){return E.isAbsolute(e)?e:n&&!e.startsWith(".")&&be.resolve?be.resolve(e,{paths:[t]}):Et(E.join(t,e))}function Pn(e,t){for(let[n,{default:a}]of Object.entries(e))t[n]==null&&a!=null&&(t[n]=a)}var Ee="0.1.51",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},targetMode:{category:"General",description:"Toil compile surface mode: 'hot' (request/stream) or 'cold' (daemon). Omit for the default request artifact.",type:"s"},noConfigEntries:{category:"General",description:"Ignore the toilconfig 'entries' array and compile ONLY the entry files given on the command line. Used by the toiljs multi-artifact build, which hands each pass (request/stream/daemon) its own entry subset.",type:"b"},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},rpcSurfaceFiles:{category:"Output",description:"Files parsed for the rpc module's @rest/@stream client surface but NOT compiled into this artifact (folds a sibling tier's @stream classes into the 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}}},Ae="~lib/",_e={array:`/// <reference path="./rt/index.d.ts" />
|
|
8
|
+
`,o={},c=[];Object.keys(e).forEach(b=>{var p=e[b];if(p.description!=null){for(var g="";g.length<n;)g+=" ";for(g+="--"+b,p.alias&&(g+=", -"+p.alias);g.length<a;)g+=" ";var y;!t.noCategories&&p.category?(y=o[p.category])||(o[p.category]=y=[]):y=c,Array.isArray(p.description)?y.push(g+p.description[0]+p.description.slice(1).map(m=>{for(let i=0;i<a;++i)m=" "+m;return s+m}).join("")):y.push(g+p.description)}});var d=[],x=!1;return Object.keys(o).forEach(b=>{x=!0,d.push(s+" "+Tn.gray(b)+s),d.push(o[b].join(s))}),x&&c.length&&d.push(s+" "+Tn.gray("Other")+s),d.push(c.join(s)),d.join(s)}function ye(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 Mn(e,t,n,a){let s={};for(let[o,{type:c,mutuallyExclusive:d,isPath:x,useNodeResolution:b,cliOnly:p}]of Object.entries(e)){let g=ye(t[o],c),y=ye(n[o],c);if(g==null){if(y!=null){if(p)continue;if(Array.isArray(y)){let m;x&&(y=y.map(i=>tn(i,a,b))),d!=null&&(m=t[d])?s[o]=y.filter(i=>!m.includes(i)):s[o]=y.slice()}else x&&(y=tn(y,a,b)),s[o]=y}}else if(y==null)Array.isArray(g)?s[o]=g.slice():s[o]=g;else if(Array.isArray(g)){if(p){s[o]=g.slice();continue}let m;x&&(y=y.map(i=>tn(i,a,b))),d!=null&&(m=t[d])?s[o]=[...g,...y.filter(i=>!g.includes(i)&&!m.includes(i))]:s[o]=[...g,...y.filter(i=>!g.includes(i))]}else s[o]=g}return s}function Et(e){let t=E.parse(e);return t.root||(t.root="./"),E.format(t)}function tn(e,t,n=!1){return E.isAbsolute(e)?e:n&&!e.startsWith(".")&&be.resolve?be.resolve(e,{paths:[t]}):Et(E.join(t,e))}function Pn(e,t){for(let[n,{default:a}]of Object.entries(e))t[n]==null&&a!=null&&(t[n]=a)}var Ee="0.1.53",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},targetMode:{category:"General",description:"Toil compile surface mode: 'hot' (request/stream) or 'cold' (daemon). Omit for the default request artifact.",type:"s"},authUser:{category:"General",description:"Built-in auth: inject the reserved toilUserId + username fields into the single @user (used by the toiljs server.auth build when the app declares its own @user).",type:"b"},noConfigEntries:{category:"General",description:"Ignore the toilconfig 'entries' array and compile ONLY the entry files given on the command line. Used by the toiljs multi-artifact build, which hands each pass (request/stream/daemon) its own entry subset.",type:"b"},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},rpcSurfaceFiles:{category:"Output",description:"Files parsed for the rpc module's @rest/@stream client surface but NOT compiled into this artifact (folds a sibling tier's @stream classes into the 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}}},Ae="~lib/",_e={array:`/// <reference path="./rt/index.d.ts" />
|
|
9
9
|
|
|
10
10
|
import { BLOCK_MAXSIZE } from "./rt/common";
|
|
11
11
|
import { Runtime } from "shared/runtime";
|
|
@@ -4807,6 +4807,10 @@ export namespace toildbHost {
|
|
|
4807
4807
|
@external("env", "data.latest")
|
|
4808
4808
|
export declare function latest(handle: u32, keyPtr: usize, keyLen: i32, limit: i32): i32;
|
|
4809
4809
|
|
|
4810
|
+
// @ts-ignore: decorator
|
|
4811
|
+
@external("env", "data.events_since")
|
|
4812
|
+
export declare function eventsSince(handle: u32, keyPtr: usize, keyLen: i32, limit: i32): i32;
|
|
4813
|
+
|
|
4810
4814
|
// events.append_once -> 1 appended | 0 duplicate (deduped on eventId) | <0 error.
|
|
4811
4815
|
// Idempotent append: a retried call with the same eventId never doubles the event.
|
|
4812
4816
|
// @ts-ignore: decorator
|
|
@@ -19190,7 +19194,7 @@ export class Counter<K> {
|
|
|
19190
19194
|
|
|
19191
19195
|
/// Every per-domain metric, by stable numeric id. This is the WIRE CONTRACT shared with the edge
|
|
19192
19196
|
/// (\`src/analytics/metric_id.rs\`) and the dev server; it orders the snapshot frame and addresses a
|
|
19193
|
-
/// time-series. Ids \`0..=
|
|
19197
|
+
/// time-series. Ids \`0..=42\` are cumulative COUNTERS (a rate is \`value / seconds\`); \`43..=46\` are the
|
|
19194
19198
|
/// avg/peak series of the two GAUGES. Append-only: never renumber.
|
|
19195
19199
|
export enum MetricId {
|
|
19196
19200
|
Requests = 0,
|
|
@@ -19201,48 +19205,49 @@ export enum MetricId {
|
|
|
19201
19205
|
Status4xx = 5,
|
|
19202
19206
|
Status5xx = 6,
|
|
19203
19207
|
StaticHits = 7,
|
|
19204
|
-
|
|
19205
|
-
|
|
19206
|
-
|
|
19207
|
-
|
|
19208
|
-
|
|
19209
|
-
|
|
19210
|
-
|
|
19211
|
-
|
|
19212
|
-
|
|
19213
|
-
|
|
19214
|
-
|
|
19215
|
-
|
|
19216
|
-
|
|
19217
|
-
|
|
19218
|
-
|
|
19219
|
-
|
|
19220
|
-
|
|
19221
|
-
|
|
19222
|
-
|
|
19223
|
-
|
|
19224
|
-
|
|
19225
|
-
|
|
19226
|
-
|
|
19227
|
-
|
|
19228
|
-
|
|
19229
|
-
|
|
19230
|
-
|
|
19231
|
-
|
|
19232
|
-
|
|
19233
|
-
|
|
19234
|
-
|
|
19235
|
-
|
|
19236
|
-
|
|
19237
|
-
|
|
19238
|
-
|
|
19239
|
-
|
|
19240
|
-
|
|
19241
|
-
|
|
19242
|
-
|
|
19243
|
-
|
|
19208
|
+
ExecutorFullRejects = 8,
|
|
19209
|
+
UnknownHostRejects = 9,
|
|
19210
|
+
RateLimitedRejects = 10,
|
|
19211
|
+
GasUsed = 11,
|
|
19212
|
+
DbOps = 12,
|
|
19213
|
+
DbReads = 13,
|
|
19214
|
+
DbWrites = 14,
|
|
19215
|
+
DbErrors = 15,
|
|
19216
|
+
DbLatencyNsSum = 16,
|
|
19217
|
+
StreamAccepts = 17,
|
|
19218
|
+
StreamRejectWrongNode = 18,
|
|
19219
|
+
StreamRejectCapacity = 19,
|
|
19220
|
+
StreamRejectArtifact = 20,
|
|
19221
|
+
StreamRejectGuest = 21,
|
|
19222
|
+
StreamTraps = 22,
|
|
19223
|
+
StreamIdleTimeouts = 23,
|
|
19224
|
+
StreamBytesIn = 24,
|
|
19225
|
+
StreamBytesOut = 25,
|
|
19226
|
+
StreamBackpressureEvents = 26,
|
|
19227
|
+
StreamCloses = 27,
|
|
19228
|
+
StreamDisconnects = 28,
|
|
19229
|
+
DaemonStarts = 29,
|
|
19230
|
+
DaemonStartFailures = 30,
|
|
19231
|
+
DaemonTicksFired = 31,
|
|
19232
|
+
DaemonTicksSkippedNotLeader = 32,
|
|
19233
|
+
DaemonTicksFailed = 33,
|
|
19234
|
+
DaemonLeaderAcquires = 34,
|
|
19235
|
+
DaemonLeaderFenced = 35,
|
|
19236
|
+
DaemonHttpCallAttempts = 36,
|
|
19237
|
+
DaemonHttpCallFailures = 37,
|
|
19238
|
+
MemGrownBytes = 38,
|
|
19239
|
+
Emails = 39,
|
|
19240
|
+
CacheHits = 40,
|
|
19241
|
+
CacheMisses = 41,
|
|
19242
|
+
ConnectedStreamsAvg = 42,
|
|
19243
|
+
ConnectedStreamsPeak = 43,
|
|
19244
|
+
CommittedMemoryAvg = 44,
|
|
19245
|
+
CommittedMemoryPeak = 45,
|
|
19246
|
+
}
|
|
19247
|
+
|
|
19248
|
+
/// The number of cumulative counter metrics (\`MetricId 0..=41\`) = the length of the snapshot's lifetime
|
|
19244
19249
|
/// section.
|
|
19245
|
-
export const METRIC_COUNTERS: i32 =
|
|
19250
|
+
export const METRIC_COUNTERS: i32 = 42;
|
|
19246
19251
|
|
|
19247
19252
|
/// A dashboard time range for \`Analytics.series\`. Short ranges (1h/6h) read the per-MINUTE ring; the rest
|
|
19248
19253
|
/// read the per-HOUR ring (30-day retention).
|
|
@@ -19262,56 +19267,80 @@ export enum AnalyticsRange {
|
|
|
19262
19267
|
/// value either by the typed getter (\`stats.requests\`) or by id (\`stats.metric(MetricId.Requests)\`).
|
|
19263
19268
|
export class TenantStats {
|
|
19264
19269
|
/// Lifetime totals indexed by \`MetricId\` (length \`METRIC_COUNTERS\`). Prefer the named getters below.
|
|
19265
|
-
life: StaticArray<
|
|
19270
|
+
life: StaticArray<u64> = new StaticArray<u64>(METRIC_COUNTERS);
|
|
19266
19271
|
/// Live gauges (current level, not a total).
|
|
19267
|
-
connectedStreams:
|
|
19268
|
-
committedMemory:
|
|
19272
|
+
connectedStreams: u64 = 0;
|
|
19273
|
+
committedMemory: u64 = 0;
|
|
19269
19274
|
/// Request windows: current bucket usage + plan cap (0 = unlimited).
|
|
19270
|
-
reqMinuteUsed:
|
|
19275
|
+
reqMinuteUsed: u64 = 0;
|
|
19271
19276
|
reqMinuteCap: u64 = 0;
|
|
19272
|
-
reqDayUsed:
|
|
19277
|
+
reqDayUsed: u64 = 0;
|
|
19273
19278
|
reqDayCap: u64 = 0;
|
|
19274
19279
|
/// Edge wall-clock (ms) when the snapshot was read.
|
|
19275
19280
|
nowMs: u64 = 0;
|
|
19276
19281
|
|
|
19277
19282
|
/// Any counter metric by id (0 for an out-of-range id).
|
|
19278
|
-
metric(id: MetricId):
|
|
19283
|
+
metric(id: MetricId): u64 {
|
|
19279
19284
|
return <i32>id < METRIC_COUNTERS ? this.life[<i32>id] : 0;
|
|
19280
19285
|
}
|
|
19281
19286
|
|
|
19282
19287
|
// Typed getters for every counter (the catalog: no magic strings, self-documenting).
|
|
19283
|
-
get requests():
|
|
19284
|
-
get bytesOutL1():
|
|
19285
|
-
get bytesInL1():
|
|
19286
|
-
get status2xx():
|
|
19287
|
-
get status3xx():
|
|
19288
|
-
get status4xx():
|
|
19289
|
-
get status5xx():
|
|
19290
|
-
get staticHits():
|
|
19291
|
-
get
|
|
19292
|
-
get
|
|
19293
|
-
get
|
|
19294
|
-
get
|
|
19295
|
-
get
|
|
19296
|
-
get
|
|
19297
|
-
get
|
|
19298
|
-
get
|
|
19299
|
-
get
|
|
19300
|
-
get
|
|
19301
|
-
get
|
|
19302
|
-
get
|
|
19303
|
-
get
|
|
19304
|
-
get
|
|
19305
|
-
get
|
|
19306
|
-
get
|
|
19307
|
-
get
|
|
19308
|
-
get
|
|
19288
|
+
get requests(): u64 { return this.life[MetricId.Requests]; }
|
|
19289
|
+
get bytesOutL1(): u64 { return this.life[MetricId.BytesOutL1]; }
|
|
19290
|
+
get bytesInL1(): u64 { return this.life[MetricId.BytesInL1]; }
|
|
19291
|
+
get status2xx(): u64 { return this.life[MetricId.Status2xx]; }
|
|
19292
|
+
get status3xx(): u64 { return this.life[MetricId.Status3xx]; }
|
|
19293
|
+
get status4xx(): u64 { return this.life[MetricId.Status4xx]; }
|
|
19294
|
+
get status5xx(): u64 { return this.life[MetricId.Status5xx]; }
|
|
19295
|
+
get staticHits(): u64 { return this.life[MetricId.StaticHits]; }
|
|
19296
|
+
get executorFullRejects(): u64 { return this.life[MetricId.ExecutorFullRejects]; }
|
|
19297
|
+
get unknownHostRejects(): u64 { return this.life[MetricId.UnknownHostRejects]; }
|
|
19298
|
+
get rateLimitedRejects(): u64 { return this.life[MetricId.RateLimitedRejects]; }
|
|
19299
|
+
get gasUsed(): u64 { return this.life[MetricId.GasUsed]; }
|
|
19300
|
+
get dbOps(): u64 { return this.life[MetricId.DbOps]; }
|
|
19301
|
+
get dbReads(): u64 { return this.life[MetricId.DbReads]; }
|
|
19302
|
+
get dbWrites(): u64 { return this.life[MetricId.DbWrites]; }
|
|
19303
|
+
get dbErrors(): u64 { return this.life[MetricId.DbErrors]; }
|
|
19304
|
+
get dbLatencyNsSum(): u64 { return this.life[MetricId.DbLatencyNsSum]; }
|
|
19305
|
+
get streamAccepts(): u64 { return this.life[MetricId.StreamAccepts]; }
|
|
19306
|
+
get streamRejectWrongNode(): u64 { return this.life[MetricId.StreamRejectWrongNode]; }
|
|
19307
|
+
get streamRejectCapacity(): u64 { return this.life[MetricId.StreamRejectCapacity]; }
|
|
19308
|
+
get streamRejectArtifact(): u64 { return this.life[MetricId.StreamRejectArtifact]; }
|
|
19309
|
+
get streamRejectGuest(): u64 { return this.life[MetricId.StreamRejectGuest]; }
|
|
19310
|
+
get streamTraps(): u64 { return this.life[MetricId.StreamTraps]; }
|
|
19311
|
+
get streamIdleTimeouts(): u64 { return this.life[MetricId.StreamIdleTimeouts]; }
|
|
19312
|
+
get streamBytesIn(): u64 { return this.life[MetricId.StreamBytesIn]; }
|
|
19313
|
+
get streamBytesOut(): u64 { return this.life[MetricId.StreamBytesOut]; }
|
|
19314
|
+
get streamBackpressureEvents(): u64 { return this.life[MetricId.StreamBackpressureEvents]; }
|
|
19315
|
+
get streamCloses(): u64 { return this.life[MetricId.StreamCloses]; }
|
|
19316
|
+
get streamDisconnects(): u64 { return this.life[MetricId.StreamDisconnects]; }
|
|
19317
|
+
get daemonStarts(): u64 { return this.life[MetricId.DaemonStarts]; }
|
|
19318
|
+
get daemonStartFailures(): u64 { return this.life[MetricId.DaemonStartFailures]; }
|
|
19319
|
+
get daemonTicksFired(): u64 { return this.life[MetricId.DaemonTicksFired]; }
|
|
19320
|
+
get daemonTicksSkippedNotLeader(): u64 { return this.life[MetricId.DaemonTicksSkippedNotLeader]; }
|
|
19321
|
+
get daemonTicksFailed(): u64 { return this.life[MetricId.DaemonTicksFailed]; }
|
|
19322
|
+
get daemonLeaderAcquires(): u64 { return this.life[MetricId.DaemonLeaderAcquires]; }
|
|
19323
|
+
get daemonLeaderFenced(): u64 { return this.life[MetricId.DaemonLeaderFenced]; }
|
|
19324
|
+
get daemonHttpCallAttempts(): u64 { return this.life[MetricId.DaemonHttpCallAttempts]; }
|
|
19325
|
+
get daemonHttpCallFailures(): u64 { return this.life[MetricId.DaemonHttpCallFailures]; }
|
|
19326
|
+
get memGrownBytes(): u64 { return this.life[MetricId.MemGrownBytes]; }
|
|
19327
|
+
get emails(): u64 { return this.life[MetricId.Emails]; }
|
|
19328
|
+
get cacheHits(): u64 { return this.life[MetricId.CacheHits]; }
|
|
19329
|
+
get cacheMisses(): u64 { return this.life[MetricId.CacheMisses]; }
|
|
19309
19330
|
|
|
19310
19331
|
/// Mean host-observed DB op latency (ns), or 0 with no ops.
|
|
19311
|
-
get meanDbLatencyNs():
|
|
19332
|
+
get meanDbLatencyNs(): u64 {
|
|
19312
19333
|
const ops = this.dbOps;
|
|
19313
19334
|
return ops > 0 ? this.dbLatencyNsSum / ops : 0;
|
|
19314
19335
|
}
|
|
19336
|
+
|
|
19337
|
+
/// Fraction of cacheable responses served from cache (\`hits / (hits + misses)\`),
|
|
19338
|
+
/// 0.0 when there were no cacheable responses.
|
|
19339
|
+
get cacheRatio(): f64 {
|
|
19340
|
+
const hits = this.cacheHits;
|
|
19341
|
+
const total = hits + this.cacheMisses;
|
|
19342
|
+
return total > 0 ? <f64>hits / <f64>total : 0.0;
|
|
19343
|
+
}
|
|
19315
19344
|
}
|
|
19316
19345
|
|
|
19317
19346
|
/// One metric's time series for a range: \`points\` oldest\u2192newest, \`bucketSecs\` the per-bucket width, and
|
|
@@ -19349,14 +19378,15 @@ export class Analytics {
|
|
|
19349
19378
|
stats.nowMs = r.readU64();
|
|
19350
19379
|
const count = <i32>r.readU32();
|
|
19351
19380
|
for (let i: i32 = 0; i < count && r.ok; i++) {
|
|
19352
|
-
|
|
19381
|
+
// Wire fields are non-negative i64; read the same bytes as u64.
|
|
19382
|
+
const v = r.readU64();
|
|
19353
19383
|
if (i < METRIC_COUNTERS) stats.life[i] = v; // ignore any extra (forward-compat)
|
|
19354
19384
|
}
|
|
19355
|
-
stats.connectedStreams = r.
|
|
19356
|
-
stats.committedMemory = r.
|
|
19357
|
-
stats.reqMinuteUsed = r.
|
|
19385
|
+
stats.connectedStreams = r.readU64();
|
|
19386
|
+
stats.committedMemory = r.readU64();
|
|
19387
|
+
stats.reqMinuteUsed = r.readU64();
|
|
19358
19388
|
stats.reqMinuteCap = r.readU64();
|
|
19359
|
-
stats.reqDayUsed = r.
|
|
19389
|
+
stats.reqDayUsed = r.readU64();
|
|
19360
19390
|
stats.reqDayCap = r.readU64();
|
|
19361
19391
|
return stats;
|
|
19362
19392
|
}
|
|
@@ -19457,6 +19487,34 @@ export class Events<K, V> {
|
|
|
19457
19487
|
return status == 1;
|
|
19458
19488
|
}
|
|
19459
19489
|
|
|
19490
|
+
/// The NEXT batch of events for \`key\` past this derive's checkpoint, OLDEST first, up to \`limit\`. The
|
|
19491
|
+
/// host owns the resumable cursor (seeded from the durable checkpoint and advanced/committed around the
|
|
19492
|
+
/// fold), so repeated calls drain an unbounded log in bounded batches and return an empty array once
|
|
19493
|
+
/// caught up. Use it in a \`@derive\` (or \`@job\`) to fold a growing log incrementally instead of rescanning:
|
|
19494
|
+
/// \`for (const e of this.events.since(key, 500)) { ...update the view... }\`, looping until it is empty.
|
|
19495
|
+
/// The fold must be idempotent per event (a heal can trigger a full re-read). Same frame as \`latest\`.
|
|
19496
|
+
since(key: K, limit: i32): V[] {
|
|
19497
|
+
const kb = key.encode();
|
|
19498
|
+
const status = toildbHost.eventsSince(this.__handle, kb.dataStart, kb.byteLength, limit);
|
|
19499
|
+
if (status < 0) unreachable();
|
|
19500
|
+
const blob = __toildbTake(status);
|
|
19501
|
+
const out = new Array<V>();
|
|
19502
|
+
let off: i32 = 0;
|
|
19503
|
+
const count = load<u32>(blob.dataStart + off);
|
|
19504
|
+
off += 4;
|
|
19505
|
+
for (let i: u32 = 0; i < count; i++) {
|
|
19506
|
+
const ver = <i64>load<u32>(blob.dataStart + off);
|
|
19507
|
+
off += 4;
|
|
19508
|
+
const len = <i32>load<u32>(blob.dataStart + off);
|
|
19509
|
+
off += 4;
|
|
19510
|
+
const ev = instantiate<V>();
|
|
19511
|
+
ev.decodeIntoVersioned(blob.subarray(off, off + len), ver);
|
|
19512
|
+
out.push(ev);
|
|
19513
|
+
off += len;
|
|
19514
|
+
}
|
|
19515
|
+
return out;
|
|
19516
|
+
}
|
|
19517
|
+
|
|
19460
19518
|
/// The newest \`limit\` events, newest first. Decodes each framed event into a
|
|
19461
19519
|
/// \`V\`. The host frames them as \`u32 count\` then per event
|
|
19462
19520
|
/// \`u32 schema_version + u32 len + bytes\`.
|
|
@@ -30554,5 +30612,5 @@ declare function offsetof<T>(fieldName?: string): usize;
|
|
|
30554
30612
|
declare function idof<T>(): u32;
|
|
30555
30613
|
`};var xn={};nn(xn,{default:()=>gn});In(xn,Vt);import*as Vt from"binaryen";import{default as gn}from"binaryen";import*as Tt from"toilscript";var h=Tt,Vn=P.argv.indexOf("--wasm");if(~Vn){let e=String(P.argv[Vn+1]);P.argv.splice(Vn,2),h=await import(new URL(e,hn.pathToFileURL(P.cwd()+"/")))}var Gn=sn.createRequire(import.meta.url),qn=P.platform==="win32",T=qn?`\r
|
|
30556
30614
|
`:`
|
|
30557
|
-
`,Hn=qn?"\\":"/",_=".ts",Ct=`.d${_}`,ln=new RegExp("\\"+_+"$"),zt=new RegExp("^(?!.*\\.d\\"+_+"$).*\\"+_+"$");function Ce(e){return e.replace(/-/g,"_").toUpperCase()}function St(e){return typeof e=="string"&&e!==""}var Kn=Ee,wt=Y,V=Ae,j=_e,Bt=Te,we=3,Be=0;function Wn(e,t=[]){return Object.keys(e||{}).forEach(n=>{let a=e[n],s=Y[n];s&&s.type==="b"?a&&t.push(`--${n}`):Array.isArray(a)?a.forEach(o=>{t.push(`--${n}`,String(o))}):t.push(`--${n}`,String(a))}),t}async function Dt(e,t={}){typeof e=="string"&&(e={[`input${_}`]:e});let n=["--outFile","binary","--textFile","text"];Wn(t,n);let a={},s=await De(n.concat(Object.keys(e)),{readFile:o=>Object.prototype.hasOwnProperty.call(e,o)?e[o]:null,writeFile:(o,c)=>{a[o]=c},listFiles:()=>[]});return Object.assign(s,a)}async function De(e,t){Array.isArray(e)||(e=Wn(e)),t||(t={});let n=t.stats||new zn,a=n.begin(),s=0,o=0,c=0,d=(Kn||"").split(".");d.length===3&&(o=parseInt(d[0])|0,s=parseInt(d[1])|0,c=parseInt(d[2])|0);let x=t.stdout||Xn(),b=t.stderr||Xn(),p=t.readFile||te,g=t.writeFile||ie,y=t.listFiles||re,m=ve(e,Y,!1),i=m.options;e=m.arguments;let Sn=new en(x),H=new en(b);i.noColors&&(Sn.enabled=!1,H.enabled=!1);let Jn=m.unknown;Jn.length&&Jn.forEach(r=>{b.write(`${H.yellow("WARNING ")}Unknown option '${r}'${T}`)});let Zn=m.trailing;Zn.length&&b.write(`${H.yellow("WARNING ")}Unsupported trailing arguments: ${Zn.join(" ")}${T}`);let K=null,R=null,z=(r,l={})=>(r&&b.write(`${H.red("FAILURE ")}${r.stack.replace(/^ERROR: /i,"")}${T}`),R&&R.dispose(),n.total||(n.total=n.end(a)),Object.assign({error:r,stdout:x,stderr:b,stats:n},l));if(i.version)return x.write(`Version ${Kn}${T}`),z(null);let S=E.normalize(i.baseDir||"."),X=tn(i.config||"toilconfig.json",S),wn=E.basename(X),J=E.dirname(X),N=await ze(wn,J,p),Ie=N!=null&&Array.isArray(N.entries)&&N.entries.length;if(i.help||!e.length&&!Ie){let r=i.help?x:b,l=i.help?Sn:H;return r.write([l.white("SYNTAX")," "+l.cyan("toilscript")+" [entryFile ...] [options]","",l.white("EXAMPLES")," "+l.cyan("toilscript")+" hello"+_," "+l.cyan("toilscript")+" hello"+_+" -o hello.wasm -t hello.wat"," "+l.cyan("toilscript")+" hello1"+_+" hello2"+_+" -o -O > hello.wasm"," "+l.cyan("toilscript")+" --config toilconfig.json --target release","",l.white("OPTIONS")].concat(Fe(Y,24,T)).join(T)+T),z(null)}if(!(M.promises&&M.promises.readFile)){if(p===te)throw Error("'options.readFile' must be specified");if(g===ie)throw Error("'options.writeFile' must be specified");if(y===re)throw Error("'options.listFiles' must be specified")}let Bn=new Set;Bn.add(X);let Oe=!!i.noConfigEntries,ke=i.target||"release";for(;N;){if(N.targets){let l=N.targets[ke];l&&(i=Mn(Y,i,l,J))}let r=N.options;if(r&&(i=Mn(Y,i,r,J)),N.entries&&!Oe)for(let l of N.entries)e.push(tn(l,J));if(N.extends){if(X=tn(N.extends,J,!0),wn=E.basename(X),J=E.dirname(X),Bn.has(X))break;Bn.add(X),N=await ze(wn,J,p)}else break}if(Pn(Y,i),i.showConfig)return b.write(JSON.stringify({options:i,entries:e},null,2)),z(null);function $n(r){return[...new Set(r)]}let w,rn,bn,C=h.newOptions();switch(i.runtime){case"stub":rn=0;break;case"minimal":rn=1;break;case"memory":rn=3;break;default:rn=2;break}switch(i.uncheckedBehavior){default:bn=0;break;case"never":bn=1;break;case"always":bn=2;break}let un=null;if(i.targetMode!=null&&String(i.targetMode).length>0&&(un=String(i.targetMode),un!=="hot"&&un!=="cold"))return z(Error(`Target mode '${un}' is invalid; expected 'hot' or 'cold'.`));if(h.setTargetMode(C,un),h.setTarget(C,0),h.setDebugInfo(C,!!i.debug),h.setRuntime(C,rn),h.setNoAssert(C,i.noAssert),h.setExportMemory(C,!i.noExportMemory),h.setImportMemory(C,i.importMemory),h.setInitialMemory(C,i.initialMemory>>>0),h.setMaximumMemory(C,i.maximumMemory>>>0),h.setSharedMemory(C,i.sharedMemory),h.setImportTable(C,i.importTable),h.setExportTable(C,i.exportTable),i.exportStart!=null&&h.setExportStart(C,St(i.exportStart)?i.exportStart:"_start"),h.setMemoryBase(C,i.memoryBase>>>0),h.setTableBase(C,i.tableBase>>>0),h.setSourceMap(C,i.sourceMap!=null),h.setUncheckedBehavior(C,bn),h.setNoUnsafe(C,i.noUnsafe),h.setPedantic(C,i.pedantic),h.setLowMemoryLimit(C,i.lowMemoryLimit>>>0),h.setExportRuntime(C,i.exportRuntime),h.setBundleVersion(C,o,s,c),!i.stackSize&&rn===2&&(i.stackSize=h.DEFAULT_STACK_SIZE),h.setStackSize(C,i.stackSize),h.setBindingsHint(C,i.bindings&&i.bindings.length>0),i.use){let r=i.use;for(let l=0,f=r.length;l<f;++l){let u=r[l],v=u.indexOf("=");if(v<0)return z(Error(`Global alias '${u}' is invalid.`));let F=u.substring(0,v).trim(),A=u.substring(v+1).trim();if(!F.length)return z(Error(`Global alias '${u}' is invalid.`));h.addGlobalAlias(C,F,A)}}let U;if((U=i.disable)!=null){typeof U=="string"&&(U=U.split(","));for(let r=0,l=U.length;r<l;++r){let f=U[r].trim(),u=h[`FEATURE_${Ce(f)}`];if(!u)return z(Error(`Feature '${f}' is unknown.`));h.setFeature(C,u,!1)}}if((U=i.enable)!=null){typeof U=="string"&&(U=U.split(","));for(let r=0,l=U.length;r<l;++r){let f=U[r].trim(),u=h[`FEATURE_${Ce(f)}`];if(!u)return z(Error(`Feature '${f}' is unknown.`));h.setFeature(C,u,!0)}}let Z=0,$=0;i.optimize&&(Z=we,$=Be),typeof i.optimizeLevel=="number"&&(Z=i.optimizeLevel),typeof i.shrinkLevel=="number"&&($=i.shrinkLevel),Z=Math.min(Math.max(Z,0),3),$=Math.min(Math.max($,0),2),h.setOptimizeLevelHints(C,Z,$),w=h.newProgram(C);let an=[];if(Array.isArray(t.transforms)&&an.push(...t.transforms),i.transform){let r=$n(i.transform);for(let l=0,f=r.length;l<f;++l){let u=r[l].trim(),v,F;if(Gn.resolve)try{v=Gn.resolve(u,{paths:[P.cwd(),S]}),F=await import(hn.pathToFileURL(v)),F.default&&(F=F.default)}catch(A){try{F=Gn(v)}catch{return z(A)}}else try{F=await import(new URL(u,import.meta.url)),F.default&&(F=F.default)}catch(A){return z(A)}if(!F||typeof F!="function"&&typeof F!="object")return z(Error("not a transform: "+r[l]));an.push(F)}}try{an=an.map(r=>(typeof r=="function"&&(Object.assign(r.prototype,{program:w,binaryen:gn,baseDir:S,stdout:x,stderr:b,log:console.error,readFile:p,writeFile:g,listFiles:y}),r=new r),r))}catch(r){return z(r)}async function Dn(r,...l){for(let f=0,u=an.length;f<u;++f){let v=an[f];if(typeof v[r]=="function")try{let F=n.begin();n.transformCount++,await v[r](...l),n.transformTime+=n.end(F)}catch(F){return F}}}Object.keys(j).forEach(r=>{if(r.includes("/"))return;let l=n.begin();n.parseCount++,h.parse(w,j[r],V+r+_,!1),n.parseTime+=n.end(l)});let on=[];if(i.lib){let r=i.lib;typeof r=="string"&&(r=r.split(",")),on.push(...r.map(l=>l.trim())),on=$n(on);for(let l=0,f=on.length;l<f;++l){let u=on[l],v;u.endsWith(_)?(v=[E.basename(u)],u=E.dirname(u)):v=await y(u,S)||[];for(let F of v){let A=await p(F,u);if(A==null)return z(Error(`Library file '${F}' not found.`));j[F.replace(ln,"")]=A;let O=n.begin();n.parseCount++,h.parse(w,A,V+F,!1),n.parseTime+=n.end(O)}}}i.path=i.path||[];let yn=new Map;async function Le(r,l){let f=null,u=null;if(!r.startsWith(V))(f=await p(u=r+_,S))==null&&(f=await p(u=r+"/index"+_,S))==null&&(u=r+_,f=await p(r+Ct,S));else{let v=r.substring(V.length),F=`${v}/index`;if(Object.prototype.hasOwnProperty.call(j,v))f=j[v],u=V+v+_;else if(Object.prototype.hasOwnProperty.call(j,F))f=j[F],u=V+F+_;else{for(let A of on)if((f=await p(v+_,A))!=null){u=V+v+_;break}else if((f=await p(F+_,A))!=null){u=V+F+_;break}if(f==null){let A=r.match(/^~lib\/((?:@[^/]+\/)?[^/]+)(?:\/(.+))?/);if(A){let O=A[1],q=A[2]||"index",En=yn.has(l)?yn.get(l):".",k=[],D=E.resolve(S,En).split(Hn);for(let B=D.length,L=qn?1:0;B>=L;--B)D[B-1]!=="node_modules"&&k.push(`${D.slice(0,B).join(Hn)}${Hn}node_modules`);k.push(...i.path);for(let B of k.map(L=>E.relative(S,L))){let L=q;if((f=await p(E.join(B,O,L+_),S))!=null){u=`${V}${O}/${L}${_}`,yn.set(u.replace(ln,""),E.join(B,O));break}let cn=`${q}/index`;if((f=await p(E.join(B,O,cn+_),S))!=null){u=`${V}${O}/${cn}${_}`,yn.set(u.replace(ln,""),E.join(B,O));break}}}}}}return f==null?null:{sourceText:f,sourcePath:u}}function Re(r=[]){do{let l=h.nextFile(w);if(l==null)break;r.push(l)}while(!0);return r}async function Qn(){let r;for(;(r=Re()).length;){let f=[];for(let u of r){let v=h.getDependee(w,u);f.push(Le(u,v))}f=await Promise.all(f);for(let u=0,v=r.length;u<v;++u){let F=r[u],A=f[u],O=n.begin();n.parseCount++,A?h.parse(w,A.sourceText,A.sourcePath,!1):h.parse(w,null,F+_,!1),n.parseTime+=n.end(O)}}let l=mn(w,b,i.disableWarning,t.reportDiagnostic,H.enabled);if(l){let f=Error(`${l} parse error(s)`);return f.stack=f.message,z(f)}}{let r=String(i.runtime),l=`rt/index-${r}`,f=j[l];if(f==null){if(l=r,f=await p(l+_,S),f==null)return z(Error(`Runtime '${E.resolve(S,l+_)}' is not found.`))}else l=`~lib/${l}`;let u=n.begin();n.parseCount++,h.parse(w,f,l+_,!0),n.parseTime+=n.end(u)}for(let r=0,l=e.length;r<l;++r){let f=String(e[r]),u=E.isAbsolute(f)?E.relative(S,f):E.normalize(f);u=u.replace(/\\/g,"/").replace(ln,"").replace(/\/$/,"");let v=await p(u+_,S);if(v==null){let A=`${u}/index${_}`;v=await p(A,S),v!=null?u=A:u+=_}else u+=_;let F=n.begin();n.parseCount++,h.parse(w,v,u,!0),n.parseTime+=n.end(F)}if(i.rpcSurfaceFiles!=null&&i.rpcSurfaceFiles.length)for(let r=0,l=i.rpcSurfaceFiles.length;r<l;++r){let f=String(i.rpcSurfaceFiles[r]),u=E.isAbsolute(f)?E.relative(S,f):E.normalize(f);u=u.replace(/\\/g,"/").replace(ln,"").replace(/\/$/,"");let v=await p(u+_,S);if(v==null){let F=`${u}/index${_}`;v=await p(F,S),v!=null?u=F:u+=_}else u+=_;v!=null?(n.parseCount++,h.parse(w,v,u,!1)):h.parse(w,null,u,!1)}if(M.promises&&M.promises.readdir){let r=[],l=async(f,u)=>{let v;try{v=await M.promises.readdir(f,{withFileTypes:!0})}catch{return}for(let F of v){let A=F.name;if(F.isDirectory()){if(A==="node_modules"||A==="build"||A==="dist"||A.charAt(0)===".")continue;await l(E.join(f,A),u?u+"/"+A:A)}else A.endsWith(".migration"+_)&&r.push(u?u+"/"+A:A)}};await l(E.resolve(S),"");for(let f of r){let u=f.replace(/\\/g,"/"),v=await p(u,S);v!=null&&(n.parseCount++,h.parse(w,v,u,!1))}}{let r=await Qn();if(r)return r}{let r=await Dn("afterParse",w.parser);if(r)return z(r)}{let r=await Qn();if(r)return r}{let r=n.begin();n.initializeCount++;try{h.initializeProgram(w)}catch(l){I("initialize",l)}n.initializeTime+=n.end(r)}{let r=await Dn("afterInitialize",w);if(r)return z(r)}{let r=n.begin();n.compileCount++;try{K=h.compile(w)}catch(l){let f=mn(w,b,i.disableWarning,t.reportDiagnostic,H.enabled);if(f){let u=Error(`${f} compile error(s)`);return u.stack=u.message,z(u)}I("compile",l)}n.compileTime+=n.end(r)}R=gn.wrapModule(typeof K=="number"||K instanceof Number?h.getBinaryenModuleRef(K):K.ref);let fn=mn(w,b,i.disableWarning,t.reportDiagnostic,H.enabled);if(fn){let r=Error(`${fn} compile error(s)`);return r.stack=r.message,z(r)}{let r=await Dn("afterCompile",R);if(r)return z(r)}if(fn=mn(w,b,i.disableWarning,t.reportDiagnostic,H.enabled),fn){let r=Error(`${fn} afterCompile error(s)`);return r.stack=r.message,z(r)}if(!i.noValidate){let r=n.begin();n.validateCount++;let l=h.validate(K);if(n.validateTime+=n.end(r),!l)return z(Error("validate error"))}if(i.trapMode==="clamp"||i.trapMode==="js"){let r=n.begin();try{R.runPasses([`trap-mode-${i.trapMode}`])}catch(l){I("runPasses",l)}n.compileTime+=n.end(r)}else if(i.trapMode!=="allow")return z(Error("Unsupported trap mode"));let ne=i.debug,Ne=i.converge,ee=i.importMemory?i.zeroFilledMemory:!1,vn=[];i.runPasses&&(typeof i.runPasses=="string"&&(i.runPasses=i.runPasses.split(",")),i.runPasses.length&&i.runPasses.forEach(r=>{vn.includes(r=r.trim())||vn.push(r)}));{let r=n.begin();try{n.optimizeCount++,h.optimize(K,Z,$,ne,ee)}catch(l){I("optimize",l)}try{R.runPasses(vn)}catch(l){I("runPasses",l)}if(Ne){let l;try{let f=n.begin();n.emitCount++,l=R.emitBinary(),n.emitTime+=n.end(f)}catch(f){I("emitBinary (converge)",f)}do{try{n.optimizeCount++,h.optimize(K,Z,$,ne,ee)}catch(u){I("optimize (converge)",u)}try{R.runPasses(vn)}catch(u){I("runPasses (converge)",u)}let f;try{let u=n.begin();n.emitCount++,f=R.emitBinary(),n.emitTime+=n.end(u)}catch(u){I("emitBinary (converge)",u)}if(f.length>=l.length){f.length>l.length&&b.write(`Last converge was suboptimal.${T}`);break}l=f}while(!0)}n.optimizeTime+=n.end(r)}let Q=[];if(!i.noEmit){if(i.binaryFile)return z(Error("Usage of the --binaryFile compiler option is no longer supported. Use --outFile instead."));let r=i.bindings||[],l=!1,f=i.outFile!=null,u=i.textFile!=null,v=f||u,F=f&&i.outFile.length>0||u&&i.textFile.length>0,A=F?(i.outFile||i.textFile).replace(/\.\w+$/,""):null,O=F?E.basename(A):"output";if(h.setBasenameHint(C,O),i.outFile!=null){let k=i.sourceMap!=null?i.sourceMap.length?i.sourceMap:`./${O}.wasm.map`:null,D=n.begin();n.emitCount++;let B;try{B=R.emitBinary(k)}catch(L){I("emitBinary",L)}if(n.emitTime+=n.end(D),i.outFile.length?Q.push(g(i.outFile,B.binary,S)):(l=!0,Fn(B.binary)),B.sourceMap!="")if(i.outFile.length){let L=JSON.parse(B.sourceMap);L.sourceRoot=`./${O}`;let cn=[];for(let An=0,Ue=L.sources.length;An<Ue;++An){let ae=L.sources[An],oe=h.getSource(w,ae.replace(ln,""));if(oe==null)return z(Error(`Source of file '${ae}' not found.`));cn[An]=oe}L.sourcesContent=cn,Q.push(g(E.join(E.dirname(i.outFile),E.basename(k)).replace(/^\.\//,""),JSON.stringify(L),S))}else b.write(`Skipped source map (no output path)${T}`)}if(i.textFile!=null||!v){let k=n.begin();n.emitCount++;let D;try{gn.setOptimizeStackIR(!0),D=i.textFile?.endsWith(".wast")?R.emitText():R.emitStackIR()}catch(B){I("emitText",B)}n.emitTime+=n.end(k),i.textFile!=null&&i.textFile.length?Q.push(g(i.textFile,D,S)):l||Fn(D)}let q=r.includes("esm"),En=!q&&r.includes("raw");if(q||En)if(A){let k=n.begin();n.emitCount++;let D;try{D=h.buildTSD(w,q)}catch(B){I("buildTSD",B)}n.emitTime+=n.end(k),Q.push(g(A+".d.ts",D,S))}else b.write(`Skipped TypeScript binding (no output path)${T}`);if(q||En)if(A){let k=n.begin();n.emitCount++;let D;try{D=h.buildJS(w,q)}catch(B){I("buildJS",B)}n.emitTime+=n.end(k),Q.push(g(A+".js",D,S))}else b.write(`Skipped JavaScript binding (no output path)${T}`);if(i.rpcModule!=null&&i.rpcModule.length){let k=n.begin();n.emitCount++;let D;try{D=h.buildServerModule(w,i.rpcRuntime||"toiljs/io")}catch(B){I("buildServerModule",B)}n.emitTime+=n.end(k),D!=null&&Q.push(g(i.rpcModule,D,S))}}try{await Promise.all(Q)}catch(r){return z(r)}return n.total=n.end(a),i.stats&&b.write(n.toString()),z(null);async function te(r,l){let f=E.resolve(l,r);try{return n.readCount++,await M.promises.readFile(f,"utf8")}catch{return null}}async function ie(r,l,f){try{n.writeCount++;let u=E.resolve(f,E.dirname(r)),v=E.join(u,E.basename(r));return await M.promises.mkdir(u,{recursive:!0}),await M.promises.writeFile(v,l),!0}catch{return!1}}async function re(r,l){try{return n.readCount++,(await M.promises.readdir(E.join(l,r))).filter(f=>zt.test(f))}catch{return null}}function Fn(r){Fn.used||(Fn.used=!0,n.writeCount++),x.write(r)}function I(r,l){let f=Sn.red("\u258C ");console.error([T,f,"Whoops, the ToilScript compiler has crashed during ",r," :-(",T,f,T,(typeof l.stack=="string"?[f,"Here is the stack trace hinting at the problem, perhaps it's useful?",T,f,T,l.stack.replace(/^/mg,f),T]:[f,"There is no stack trace. Perhaps a Binaryen exception above / in console?",T,f,T,f,"> "+l.stack,T]).join(""),f,T,f,"If you see where the error is, feel free to send us a pull request. If not,",T,f,"please let us know: https://github.com/dacely-cloud/toilscript/issues",T,f,T,f,"Thank you!",T].join("")),P.exit(1)}}function jn(e){return Object.prototype.toString.call(e)==="[object Object]"}async function ze(e,t,n){let a=await n(e,t),s=E.join(t,e);if(!a)return null;let o;try{o=JSON.parse(a)}catch(c){throw new Error(`Toilconfig is not valid json: ${s}`,{cause:c})}if(o.options&&!jn(o.options))throw new Error(`Toilconfig.options is not an object: ${s}`);if(o.include&&!Array.isArray(o.include))throw new Error(`Toilconfig.include is not an array: ${s}`);if(o.targets){if(!jn(o.targets))throw new Error(`Toilconfig.targets is not an object: ${s}`);let c=Object.keys(o.targets);for(let d=0;d<c.length;d++){let x=c[d];if(!jn(o.targets[x]))throw new Error(`Toilconfig.targets.${x} is not an object: ${s}`)}}if(o.extends&&typeof o.extends!="string")throw new Error(`Toilconfig.extends is not a string: ${s}`);return o}function mn(e,t,n,a,s){typeof s>"u"&&t&&(s=t.isTTY);let o=0;do{let x=h.nextDiagnostic(e);if(!x)break;if(t){let b=p=>{if(n==null)return!1;if(!n.length)return!0;let g=h.getDiagnosticCode(p);return n.includes(g)};(h.isError(x)||!b(x))&&t.write(h.formatDiagnostic(x,s,!0)+T+T)}if(a){let b=function(g){return g&&{start:h.getRangeStart(g),end:h.getRangeEnd(g),source:p(h.getRangeSource(g))}||null},p=function(g){return g&&{normalizedPath:h.getSourceNormalizedPath(g)}||null};var c=b,d=p;a({message:h.getDiagnosticMessage(x),code:h.getDiagnosticCode(x),category:h.getDiagnosticCategory(x),range:b(h.getDiagnosticRange(x)),relatedRange:b(h.getDiagnosticRelatedRange(x))})}h.isError(x)&&++o}while(!0);return o}var zn=class{readCount=0;writeCount=0;parseTime=0;parseCount=0;initializeTime=0;initializeCount=0;compileTime=0;compileCount=0;emitTime=0;emitCount=0;validateTime=0;validateCount=0;optimizeTime=0;optimizeCount=0;transformTime=0;transformCount=0;begin(){return P.hrtime()}end(t){let n=P.hrtime(t);return n[0]*1e9+n[1]}toString(){let t=m=>m?`${(m/1e6).toFixed(3)} ms`:"n/a",n=Object.keys(this).filter(m=>m.endsWith("Time")).map(m=>m.substring(0,m.length-4)),a=n.map(m=>t(this[`${m}Time`])),s=n.map(m=>this[`${m}Count`].toString()),o=n.reduce((m,i)=>Math.max(i.length,m),0),c=a.reduce((m,i)=>Math.max(i.length,m),0),d=s.reduce((m,i)=>Math.max(i.length,m),0),x=o+c+d+6,b=[];b.push(`\u256D\u2500${"\u2500".repeat(x)}\u2500\u256E${T}`);let p="Stats";b.push(`\u2502 ${p}${" ".repeat(x-p.length)} \u2502${T}`),b.push(`\u255E\u2550${"\u2550".repeat(o)}\u2550\u2564\u2550${"\u2550".repeat(c)}\u2550\u2564\u2550${"\u2550".repeat(d)}\u2550\u2561${T}`);for(let m=0,i=n.length;m<i;++m)b.push(`\u2502 ${n[m].padEnd(o)} \u2502 ${a[m].padStart(c)} \u2502 ${s[m].padStart(d)} \u2502${T}`);b.push(`\u251C\u2500${"\u2500".repeat(o)}\u2500\u2534\u2500${"\u2500".repeat(c)}\u2500\u2534\u2500${"\u2500".repeat(d)}\u2500\u2524${T}`);let g=`Took ${t(this.total)}`;b.push(`\u2502 ${g}${" ".repeat(x-g.length)} \u2502${T}`);let y=`${this.readCount} reads, ${this.writeCount} writes`;return b.push(`\u2502 ${y}${" ".repeat(x-y.length)} \u2502${T}`),b.push(`\u2570\u2500${"\u2500".repeat(x)}\u2500\u256F${T}`),b.join("")}},Se=typeof global<"u"&&global.Buffer?global.Buffer.allocUnsafe||(e=>new global.Buffer(e)):e=>new Uint8Array(e);function Xn(e){let t=[];return t.write=function(n){if(e&&e(n),typeof n=="string"){let a=Se(Cn.length(n));Cn.write(n,a,0),n=a}this.push(n)},t.reset=function(){t.length=0},t.toBuffer=function(){let n=0,a=0,s=this.length;for(;a<s;)n+=this[a++].length;let o=Se(n);for(n=a=0;a<s;)o.set(this[a],n),n+=this[a].length,++a;return o},t.toString=function(){let n=this.toBuffer();return Cn.read(n,0,n.length)},t}var It={alwaysStrict:!0,strictNullChecks:!0,noImplicitAny:!0,noImplicitReturns:!0,noImplicitThis:!0,noEmitOnError:!0,noPropertyAccessFromIndexSignature:!0,experimentalDecorators:!0,target:"esnext",noLib:!0,types:[],allowJs:!1};export{zn as Stats,mn as checkDiagnostics,Dt as compileString,Wn as configToArguments,Xn as createMemoryStream,Yn as default,we as defaultOptimizeLevel,Be as defaultShrinkLevel,Bt as definitionFiles,j as libraryFiles,V as libraryPrefix,De as main,wt as options,It as tscOptions,Kn as version};
|
|
30615
|
+
`,Hn=qn?"\\":"/",_=".ts",Ct=`.d${_}`,ln=new RegExp("\\"+_+"$"),zt=new RegExp("^(?!.*\\.d\\"+_+"$).*\\"+_+"$");function Ce(e){return e.replace(/-/g,"_").toUpperCase()}function St(e){return typeof e=="string"&&e!==""}var Kn=Ee,wt=Y,V=Ae,j=_e,Bt=Te,we=3,Be=0;function Wn(e,t=[]){return Object.keys(e||{}).forEach(n=>{let a=e[n],s=Y[n];s&&s.type==="b"?a&&t.push(`--${n}`):Array.isArray(a)?a.forEach(o=>{t.push(`--${n}`,String(o))}):t.push(`--${n}`,String(a))}),t}async function Dt(e,t={}){typeof e=="string"&&(e={[`input${_}`]:e});let n=["--outFile","binary","--textFile","text"];Wn(t,n);let a={},s=await De(n.concat(Object.keys(e)),{readFile:o=>Object.prototype.hasOwnProperty.call(e,o)?e[o]:null,writeFile:(o,c)=>{a[o]=c},listFiles:()=>[]});return Object.assign(s,a)}async function De(e,t){Array.isArray(e)||(e=Wn(e)),t||(t={});let n=t.stats||new zn,a=n.begin(),s=0,o=0,c=0,d=(Kn||"").split(".");d.length===3&&(o=parseInt(d[0])|0,s=parseInt(d[1])|0,c=parseInt(d[2])|0);let x=t.stdout||Xn(),b=t.stderr||Xn(),p=t.readFile||te,g=t.writeFile||ie,y=t.listFiles||re,m=ve(e,Y,!1),i=m.options;e=m.arguments;let Sn=new en(x),H=new en(b);i.noColors&&(Sn.enabled=!1,H.enabled=!1);let Jn=m.unknown;Jn.length&&Jn.forEach(r=>{b.write(`${H.yellow("WARNING ")}Unknown option '${r}'${T}`)});let Zn=m.trailing;Zn.length&&b.write(`${H.yellow("WARNING ")}Unsupported trailing arguments: ${Zn.join(" ")}${T}`);let K=null,R=null,z=(r,l={})=>(r&&b.write(`${H.red("FAILURE ")}${r.stack.replace(/^ERROR: /i,"")}${T}`),R&&R.dispose(),n.total||(n.total=n.end(a)),Object.assign({error:r,stdout:x,stderr:b,stats:n},l));if(i.version)return x.write(`Version ${Kn}${T}`),z(null);let S=E.normalize(i.baseDir||"."),X=tn(i.config||"toilconfig.json",S),wn=E.basename(X),J=E.dirname(X),N=await ze(wn,J,p),Ie=N!=null&&Array.isArray(N.entries)&&N.entries.length;if(i.help||!e.length&&!Ie){let r=i.help?x:b,l=i.help?Sn:H;return r.write([l.white("SYNTAX")," "+l.cyan("toilscript")+" [entryFile ...] [options]","",l.white("EXAMPLES")," "+l.cyan("toilscript")+" hello"+_," "+l.cyan("toilscript")+" hello"+_+" -o hello.wasm -t hello.wat"," "+l.cyan("toilscript")+" hello1"+_+" hello2"+_+" -o -O > hello.wasm"," "+l.cyan("toilscript")+" --config toilconfig.json --target release","",l.white("OPTIONS")].concat(Fe(Y,24,T)).join(T)+T),z(null)}if(!(M.promises&&M.promises.readFile)){if(p===te)throw Error("'options.readFile' must be specified");if(g===ie)throw Error("'options.writeFile' must be specified");if(y===re)throw Error("'options.listFiles' must be specified")}let Bn=new Set;Bn.add(X);let Oe=!!i.noConfigEntries,ke=i.target||"release";for(;N;){if(N.targets){let l=N.targets[ke];l&&(i=Mn(Y,i,l,J))}let r=N.options;if(r&&(i=Mn(Y,i,r,J)),N.entries&&!Oe)for(let l of N.entries)e.push(tn(l,J));if(N.extends){if(X=tn(N.extends,J,!0),wn=E.basename(X),J=E.dirname(X),Bn.has(X))break;Bn.add(X),N=await ze(wn,J,p)}else break}if(Pn(Y,i),i.showConfig)return b.write(JSON.stringify({options:i,entries:e},null,2)),z(null);function $n(r){return[...new Set(r)]}let w,rn,bn,C=h.newOptions();switch(i.runtime){case"stub":rn=0;break;case"minimal":rn=1;break;case"memory":rn=3;break;default:rn=2;break}switch(i.uncheckedBehavior){default:bn=0;break;case"never":bn=1;break;case"always":bn=2;break}let un=null;if(i.targetMode!=null&&String(i.targetMode).length>0&&(un=String(i.targetMode),un!=="hot"&&un!=="cold"))return z(Error(`Target mode '${un}' is invalid; expected 'hot' or 'cold'.`));if(h.setTargetMode(C,un),h.setAuthUser(C,!!i.authUser),h.setTarget(C,0),h.setDebugInfo(C,!!i.debug),h.setRuntime(C,rn),h.setNoAssert(C,i.noAssert),h.setExportMemory(C,!i.noExportMemory),h.setImportMemory(C,i.importMemory),h.setInitialMemory(C,i.initialMemory>>>0),h.setMaximumMemory(C,i.maximumMemory>>>0),h.setSharedMemory(C,i.sharedMemory),h.setImportTable(C,i.importTable),h.setExportTable(C,i.exportTable),i.exportStart!=null&&h.setExportStart(C,St(i.exportStart)?i.exportStart:"_start"),h.setMemoryBase(C,i.memoryBase>>>0),h.setTableBase(C,i.tableBase>>>0),h.setSourceMap(C,i.sourceMap!=null),h.setUncheckedBehavior(C,bn),h.setNoUnsafe(C,i.noUnsafe),h.setPedantic(C,i.pedantic),h.setLowMemoryLimit(C,i.lowMemoryLimit>>>0),h.setExportRuntime(C,i.exportRuntime),h.setBundleVersion(C,o,s,c),!i.stackSize&&rn===2&&(i.stackSize=h.DEFAULT_STACK_SIZE),h.setStackSize(C,i.stackSize),h.setBindingsHint(C,i.bindings&&i.bindings.length>0),i.use){let r=i.use;for(let l=0,f=r.length;l<f;++l){let u=r[l],v=u.indexOf("=");if(v<0)return z(Error(`Global alias '${u}' is invalid.`));let F=u.substring(0,v).trim(),A=u.substring(v+1).trim();if(!F.length)return z(Error(`Global alias '${u}' is invalid.`));h.addGlobalAlias(C,F,A)}}let U;if((U=i.disable)!=null){typeof U=="string"&&(U=U.split(","));for(let r=0,l=U.length;r<l;++r){let f=U[r].trim(),u=h[`FEATURE_${Ce(f)}`];if(!u)return z(Error(`Feature '${f}' is unknown.`));h.setFeature(C,u,!1)}}if((U=i.enable)!=null){typeof U=="string"&&(U=U.split(","));for(let r=0,l=U.length;r<l;++r){let f=U[r].trim(),u=h[`FEATURE_${Ce(f)}`];if(!u)return z(Error(`Feature '${f}' is unknown.`));h.setFeature(C,u,!0)}}let Z=0,$=0;i.optimize&&(Z=we,$=Be),typeof i.optimizeLevel=="number"&&(Z=i.optimizeLevel),typeof i.shrinkLevel=="number"&&($=i.shrinkLevel),Z=Math.min(Math.max(Z,0),3),$=Math.min(Math.max($,0),2),h.setOptimizeLevelHints(C,Z,$),w=h.newProgram(C);let an=[];if(Array.isArray(t.transforms)&&an.push(...t.transforms),i.transform){let r=$n(i.transform);for(let l=0,f=r.length;l<f;++l){let u=r[l].trim(),v,F;if(Gn.resolve)try{v=Gn.resolve(u,{paths:[P.cwd(),S]}),F=await import(hn.pathToFileURL(v)),F.default&&(F=F.default)}catch(A){try{F=Gn(v)}catch{return z(A)}}else try{F=await import(new URL(u,import.meta.url)),F.default&&(F=F.default)}catch(A){return z(A)}if(!F||typeof F!="function"&&typeof F!="object")return z(Error("not a transform: "+r[l]));an.push(F)}}try{an=an.map(r=>(typeof r=="function"&&(Object.assign(r.prototype,{program:w,binaryen:gn,baseDir:S,stdout:x,stderr:b,log:console.error,readFile:p,writeFile:g,listFiles:y}),r=new r),r))}catch(r){return z(r)}async function Dn(r,...l){for(let f=0,u=an.length;f<u;++f){let v=an[f];if(typeof v[r]=="function")try{let F=n.begin();n.transformCount++,await v[r](...l),n.transformTime+=n.end(F)}catch(F){return F}}}Object.keys(j).forEach(r=>{if(r.includes("/"))return;let l=n.begin();n.parseCount++,h.parse(w,j[r],V+r+_,!1),n.parseTime+=n.end(l)});let on=[];if(i.lib){let r=i.lib;typeof r=="string"&&(r=r.split(",")),on.push(...r.map(l=>l.trim())),on=$n(on);for(let l=0,f=on.length;l<f;++l){let u=on[l],v;u.endsWith(_)?(v=[E.basename(u)],u=E.dirname(u)):v=await y(u,S)||[];for(let F of v){let A=await p(F,u);if(A==null)return z(Error(`Library file '${F}' not found.`));j[F.replace(ln,"")]=A;let O=n.begin();n.parseCount++,h.parse(w,A,V+F,!1),n.parseTime+=n.end(O)}}}i.path=i.path||[];let yn=new Map;async function Le(r,l){let f=null,u=null;if(!r.startsWith(V))(f=await p(u=r+_,S))==null&&(f=await p(u=r+"/index"+_,S))==null&&(u=r+_,f=await p(r+Ct,S));else{let v=r.substring(V.length),F=`${v}/index`;if(Object.prototype.hasOwnProperty.call(j,v))f=j[v],u=V+v+_;else if(Object.prototype.hasOwnProperty.call(j,F))f=j[F],u=V+F+_;else{for(let A of on)if((f=await p(v+_,A))!=null){u=V+v+_;break}else if((f=await p(F+_,A))!=null){u=V+F+_;break}if(f==null){let A=r.match(/^~lib\/((?:@[^/]+\/)?[^/]+)(?:\/(.+))?/);if(A){let O=A[1],q=A[2]||"index",En=yn.has(l)?yn.get(l):".",k=[],D=E.resolve(S,En).split(Hn);for(let B=D.length,L=qn?1:0;B>=L;--B)D[B-1]!=="node_modules"&&k.push(`${D.slice(0,B).join(Hn)}${Hn}node_modules`);k.push(...i.path);for(let B of k.map(L=>E.relative(S,L))){let L=q;if((f=await p(E.join(B,O,L+_),S))!=null){u=`${V}${O}/${L}${_}`,yn.set(u.replace(ln,""),E.join(B,O));break}let cn=`${q}/index`;if((f=await p(E.join(B,O,cn+_),S))!=null){u=`${V}${O}/${cn}${_}`,yn.set(u.replace(ln,""),E.join(B,O));break}}}}}}return f==null?null:{sourceText:f,sourcePath:u}}function Re(r=[]){do{let l=h.nextFile(w);if(l==null)break;r.push(l)}while(!0);return r}async function Qn(){let r;for(;(r=Re()).length;){let f=[];for(let u of r){let v=h.getDependee(w,u);f.push(Le(u,v))}f=await Promise.all(f);for(let u=0,v=r.length;u<v;++u){let F=r[u],A=f[u],O=n.begin();n.parseCount++,A?h.parse(w,A.sourceText,A.sourcePath,!1):h.parse(w,null,F+_,!1),n.parseTime+=n.end(O)}}let l=mn(w,b,i.disableWarning,t.reportDiagnostic,H.enabled);if(l){let f=Error(`${l} parse error(s)`);return f.stack=f.message,z(f)}}{let r=String(i.runtime),l=`rt/index-${r}`,f=j[l];if(f==null){if(l=r,f=await p(l+_,S),f==null)return z(Error(`Runtime '${E.resolve(S,l+_)}' is not found.`))}else l=`~lib/${l}`;let u=n.begin();n.parseCount++,h.parse(w,f,l+_,!0),n.parseTime+=n.end(u)}for(let r=0,l=e.length;r<l;++r){let f=String(e[r]),u=E.isAbsolute(f)?E.relative(S,f):E.normalize(f);u=u.replace(/\\/g,"/").replace(ln,"").replace(/\/$/,"");let v=await p(u+_,S);if(v==null){let A=`${u}/index${_}`;v=await p(A,S),v!=null?u=A:u+=_}else u+=_;let F=n.begin();n.parseCount++,h.parse(w,v,u,!0),n.parseTime+=n.end(F)}if(i.rpcSurfaceFiles!=null&&i.rpcSurfaceFiles.length)for(let r=0,l=i.rpcSurfaceFiles.length;r<l;++r){let f=String(i.rpcSurfaceFiles[r]),u=E.isAbsolute(f)?E.relative(S,f):E.normalize(f);u=u.replace(/\\/g,"/").replace(ln,"").replace(/\/$/,"");let v=await p(u+_,S);if(v==null){let F=`${u}/index${_}`;v=await p(F,S),v!=null?u=F:u+=_}else u+=_;v!=null?(n.parseCount++,h.parse(w,v,u,!1)):h.parse(w,null,u,!1)}if(M.promises&&M.promises.readdir){let r=[],l=async(f,u)=>{let v;try{v=await M.promises.readdir(f,{withFileTypes:!0})}catch{return}for(let F of v){let A=F.name;if(F.isDirectory()){if(A==="node_modules"||A==="build"||A==="dist"||A.charAt(0)===".")continue;await l(E.join(f,A),u?u+"/"+A:A)}else A.endsWith(".migration"+_)&&r.push(u?u+"/"+A:A)}};await l(E.resolve(S),"");for(let f of r){let u=f.replace(/\\/g,"/"),v=await p(u,S);v!=null&&(n.parseCount++,h.parse(w,v,u,!1))}}{let r=await Qn();if(r)return r}{let r=await Dn("afterParse",w.parser);if(r)return z(r)}{let r=await Qn();if(r)return r}{let r=n.begin();n.initializeCount++;try{h.initializeProgram(w)}catch(l){I("initialize",l)}n.initializeTime+=n.end(r)}{let r=await Dn("afterInitialize",w);if(r)return z(r)}{let r=n.begin();n.compileCount++;try{K=h.compile(w)}catch(l){let f=mn(w,b,i.disableWarning,t.reportDiagnostic,H.enabled);if(f){let u=Error(`${f} compile error(s)`);return u.stack=u.message,z(u)}I("compile",l)}n.compileTime+=n.end(r)}R=gn.wrapModule(typeof K=="number"||K instanceof Number?h.getBinaryenModuleRef(K):K.ref);let fn=mn(w,b,i.disableWarning,t.reportDiagnostic,H.enabled);if(fn){let r=Error(`${fn} compile error(s)`);return r.stack=r.message,z(r)}{let r=await Dn("afterCompile",R);if(r)return z(r)}if(fn=mn(w,b,i.disableWarning,t.reportDiagnostic,H.enabled),fn){let r=Error(`${fn} afterCompile error(s)`);return r.stack=r.message,z(r)}if(!i.noValidate){let r=n.begin();n.validateCount++;let l=h.validate(K);if(n.validateTime+=n.end(r),!l)return z(Error("validate error"))}if(i.trapMode==="clamp"||i.trapMode==="js"){let r=n.begin();try{R.runPasses([`trap-mode-${i.trapMode}`])}catch(l){I("runPasses",l)}n.compileTime+=n.end(r)}else if(i.trapMode!=="allow")return z(Error("Unsupported trap mode"));let ne=i.debug,Ne=i.converge,ee=i.importMemory?i.zeroFilledMemory:!1,vn=[];i.runPasses&&(typeof i.runPasses=="string"&&(i.runPasses=i.runPasses.split(",")),i.runPasses.length&&i.runPasses.forEach(r=>{vn.includes(r=r.trim())||vn.push(r)}));{let r=n.begin();try{n.optimizeCount++,h.optimize(K,Z,$,ne,ee)}catch(l){I("optimize",l)}try{R.runPasses(vn)}catch(l){I("runPasses",l)}if(Ne){let l;try{let f=n.begin();n.emitCount++,l=R.emitBinary(),n.emitTime+=n.end(f)}catch(f){I("emitBinary (converge)",f)}do{try{n.optimizeCount++,h.optimize(K,Z,$,ne,ee)}catch(u){I("optimize (converge)",u)}try{R.runPasses(vn)}catch(u){I("runPasses (converge)",u)}let f;try{let u=n.begin();n.emitCount++,f=R.emitBinary(),n.emitTime+=n.end(u)}catch(u){I("emitBinary (converge)",u)}if(f.length>=l.length){f.length>l.length&&b.write(`Last converge was suboptimal.${T}`);break}l=f}while(!0)}n.optimizeTime+=n.end(r)}let Q=[];if(!i.noEmit){if(i.binaryFile)return z(Error("Usage of the --binaryFile compiler option is no longer supported. Use --outFile instead."));let r=i.bindings||[],l=!1,f=i.outFile!=null,u=i.textFile!=null,v=f||u,F=f&&i.outFile.length>0||u&&i.textFile.length>0,A=F?(i.outFile||i.textFile).replace(/\.\w+$/,""):null,O=F?E.basename(A):"output";if(h.setBasenameHint(C,O),i.outFile!=null){let k=i.sourceMap!=null?i.sourceMap.length?i.sourceMap:`./${O}.wasm.map`:null,D=n.begin();n.emitCount++;let B;try{B=R.emitBinary(k)}catch(L){I("emitBinary",L)}if(n.emitTime+=n.end(D),i.outFile.length?Q.push(g(i.outFile,B.binary,S)):(l=!0,Fn(B.binary)),B.sourceMap!="")if(i.outFile.length){let L=JSON.parse(B.sourceMap);L.sourceRoot=`./${O}`;let cn=[];for(let An=0,Ue=L.sources.length;An<Ue;++An){let ae=L.sources[An],oe=h.getSource(w,ae.replace(ln,""));if(oe==null)return z(Error(`Source of file '${ae}' not found.`));cn[An]=oe}L.sourcesContent=cn,Q.push(g(E.join(E.dirname(i.outFile),E.basename(k)).replace(/^\.\//,""),JSON.stringify(L),S))}else b.write(`Skipped source map (no output path)${T}`)}if(i.textFile!=null||!v){let k=n.begin();n.emitCount++;let D;try{gn.setOptimizeStackIR(!0),D=i.textFile?.endsWith(".wast")?R.emitText():R.emitStackIR()}catch(B){I("emitText",B)}n.emitTime+=n.end(k),i.textFile!=null&&i.textFile.length?Q.push(g(i.textFile,D,S)):l||Fn(D)}let q=r.includes("esm"),En=!q&&r.includes("raw");if(q||En)if(A){let k=n.begin();n.emitCount++;let D;try{D=h.buildTSD(w,q)}catch(B){I("buildTSD",B)}n.emitTime+=n.end(k),Q.push(g(A+".d.ts",D,S))}else b.write(`Skipped TypeScript binding (no output path)${T}`);if(q||En)if(A){let k=n.begin();n.emitCount++;let D;try{D=h.buildJS(w,q)}catch(B){I("buildJS",B)}n.emitTime+=n.end(k),Q.push(g(A+".js",D,S))}else b.write(`Skipped JavaScript binding (no output path)${T}`);if(i.rpcModule!=null&&i.rpcModule.length){let k=n.begin();n.emitCount++;let D;try{D=h.buildServerModule(w,i.rpcRuntime||"toiljs/io")}catch(B){I("buildServerModule",B)}n.emitTime+=n.end(k),D!=null&&Q.push(g(i.rpcModule,D,S))}}try{await Promise.all(Q)}catch(r){return z(r)}return n.total=n.end(a),i.stats&&b.write(n.toString()),z(null);async function te(r,l){let f=E.resolve(l,r);try{return n.readCount++,await M.promises.readFile(f,"utf8")}catch{return null}}async function ie(r,l,f){try{n.writeCount++;let u=E.resolve(f,E.dirname(r)),v=E.join(u,E.basename(r));return await M.promises.mkdir(u,{recursive:!0}),await M.promises.writeFile(v,l),!0}catch{return!1}}async function re(r,l){try{return n.readCount++,(await M.promises.readdir(E.join(l,r))).filter(f=>zt.test(f))}catch{return null}}function Fn(r){Fn.used||(Fn.used=!0,n.writeCount++),x.write(r)}function I(r,l){let f=Sn.red("\u258C ");console.error([T,f,"Whoops, the ToilScript compiler has crashed during ",r," :-(",T,f,T,(typeof l.stack=="string"?[f,"Here is the stack trace hinting at the problem, perhaps it's useful?",T,f,T,l.stack.replace(/^/mg,f),T]:[f,"There is no stack trace. Perhaps a Binaryen exception above / in console?",T,f,T,f,"> "+l.stack,T]).join(""),f,T,f,"If you see where the error is, feel free to send us a pull request. If not,",T,f,"please let us know: https://github.com/dacely-cloud/toilscript/issues",T,f,T,f,"Thank you!",T].join("")),P.exit(1)}}function jn(e){return Object.prototype.toString.call(e)==="[object Object]"}async function ze(e,t,n){let a=await n(e,t),s=E.join(t,e);if(!a)return null;let o;try{o=JSON.parse(a)}catch(c){throw new Error(`Toilconfig is not valid json: ${s}`,{cause:c})}if(o.options&&!jn(o.options))throw new Error(`Toilconfig.options is not an object: ${s}`);if(o.include&&!Array.isArray(o.include))throw new Error(`Toilconfig.include is not an array: ${s}`);if(o.targets){if(!jn(o.targets))throw new Error(`Toilconfig.targets is not an object: ${s}`);let c=Object.keys(o.targets);for(let d=0;d<c.length;d++){let x=c[d];if(!jn(o.targets[x]))throw new Error(`Toilconfig.targets.${x} is not an object: ${s}`)}}if(o.extends&&typeof o.extends!="string")throw new Error(`Toilconfig.extends is not a string: ${s}`);return o}function mn(e,t,n,a,s){typeof s>"u"&&t&&(s=t.isTTY);let o=0;do{let x=h.nextDiagnostic(e);if(!x)break;if(t){let b=p=>{if(n==null)return!1;if(!n.length)return!0;let g=h.getDiagnosticCode(p);return n.includes(g)};(h.isError(x)||!b(x))&&t.write(h.formatDiagnostic(x,s,!0)+T+T)}if(a){let b=function(g){return g&&{start:h.getRangeStart(g),end:h.getRangeEnd(g),source:p(h.getRangeSource(g))}||null},p=function(g){return g&&{normalizedPath:h.getSourceNormalizedPath(g)}||null};var c=b,d=p;a({message:h.getDiagnosticMessage(x),code:h.getDiagnosticCode(x),category:h.getDiagnosticCategory(x),range:b(h.getDiagnosticRange(x)),relatedRange:b(h.getDiagnosticRelatedRange(x))})}h.isError(x)&&++o}while(!0);return o}var zn=class{readCount=0;writeCount=0;parseTime=0;parseCount=0;initializeTime=0;initializeCount=0;compileTime=0;compileCount=0;emitTime=0;emitCount=0;validateTime=0;validateCount=0;optimizeTime=0;optimizeCount=0;transformTime=0;transformCount=0;begin(){return P.hrtime()}end(t){let n=P.hrtime(t);return n[0]*1e9+n[1]}toString(){let t=m=>m?`${(m/1e6).toFixed(3)} ms`:"n/a",n=Object.keys(this).filter(m=>m.endsWith("Time")).map(m=>m.substring(0,m.length-4)),a=n.map(m=>t(this[`${m}Time`])),s=n.map(m=>this[`${m}Count`].toString()),o=n.reduce((m,i)=>Math.max(i.length,m),0),c=a.reduce((m,i)=>Math.max(i.length,m),0),d=s.reduce((m,i)=>Math.max(i.length,m),0),x=o+c+d+6,b=[];b.push(`\u256D\u2500${"\u2500".repeat(x)}\u2500\u256E${T}`);let p="Stats";b.push(`\u2502 ${p}${" ".repeat(x-p.length)} \u2502${T}`),b.push(`\u255E\u2550${"\u2550".repeat(o)}\u2550\u2564\u2550${"\u2550".repeat(c)}\u2550\u2564\u2550${"\u2550".repeat(d)}\u2550\u2561${T}`);for(let m=0,i=n.length;m<i;++m)b.push(`\u2502 ${n[m].padEnd(o)} \u2502 ${a[m].padStart(c)} \u2502 ${s[m].padStart(d)} \u2502${T}`);b.push(`\u251C\u2500${"\u2500".repeat(o)}\u2500\u2534\u2500${"\u2500".repeat(c)}\u2500\u2534\u2500${"\u2500".repeat(d)}\u2500\u2524${T}`);let g=`Took ${t(this.total)}`;b.push(`\u2502 ${g}${" ".repeat(x-g.length)} \u2502${T}`);let y=`${this.readCount} reads, ${this.writeCount} writes`;return b.push(`\u2502 ${y}${" ".repeat(x-y.length)} \u2502${T}`),b.push(`\u2570\u2500${"\u2500".repeat(x)}\u2500\u256F${T}`),b.join("")}},Se=typeof global<"u"&&global.Buffer?global.Buffer.allocUnsafe||(e=>new global.Buffer(e)):e=>new Uint8Array(e);function Xn(e){let t=[];return t.write=function(n){if(e&&e(n),typeof n=="string"){let a=Se(Cn.length(n));Cn.write(n,a,0),n=a}this.push(n)},t.reset=function(){t.length=0},t.toBuffer=function(){let n=0,a=0,s=this.length;for(;a<s;)n+=this[a++].length;let o=Se(n);for(n=a=0;a<s;)o.set(this[a],n),n+=this[a].length,++a;return o},t.toString=function(){let n=this.toBuffer();return Cn.read(n,0,n.length)},t}var It={alwaysStrict:!0,strictNullChecks:!0,noImplicitAny:!0,noImplicitReturns:!0,noImplicitThis:!0,noEmitOnError:!0,noPropertyAccessFromIndexSignature:!0,experimentalDecorators:!0,target:"esnext",noLib:!0,types:[],allowJs:!1};export{zn as Stats,mn as checkDiagnostics,Dt as compileString,Wn as configToArguments,Xn as createMemoryStream,Yn as default,we as defaultOptimizeLevel,Be as defaultShrinkLevel,Bt as definitionFiles,j as libraryFiles,V as libraryPrefix,De as main,wt as options,It as tscOptions,Kn as version};
|
|
30558
30616
|
//# sourceMappingURL=cli.js.map
|