tjs-lang 0.7.4 → 0.7.6

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/index.js CHANGED
@@ -1,9 +1,9 @@
1
- var Bi=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var ws=Bi((mf,ko)=>{ko.exports={name:"tjs-lang",version:"0.7.3",description:"Type-safe JavaScript dialect with runtime validation, sandboxed VM execution, and AI agent orchestration. Transpiles TypeScript to validated JS with fuel-metered execution for untrusted code.",keywords:["typescript","transpiler","runtime-validation","type-safety","sandbox","virtual-machine","wasm-alternative","ai-agents","llm","orchestration","security","fuel-metering","capability-based","json-ast","untrusted-code"],license:"Apache-2.0",main:"./dist/index.js",types:"./dist/src/index.d.ts",exports:{".":{bun:"./src/index.ts",types:"./dist/src/index.d.ts",default:"./dist/index.js"},"./eval":{bun:"./src/lang/eval.ts",types:"./dist/src/lang/eval.d.ts",default:"./dist/tjs-eval.js"},"./lang":{bun:"./src/lang/transpiler.ts",types:"./dist/src/lang/transpiler.d.ts",default:"./dist/tjs-lang.js"},"./lang/from-ts":{bun:"./src/lang/emitters/from-ts.ts",types:"./dist/src/lang/emitters/from-ts.d.ts",default:"./dist/tjs-from-ts.js"},"./vm":{bun:"./src/vm/index.ts",types:"./dist/src/vm/index.d.ts",default:"./dist/tjs-vm.js"},"./batteries":{bun:"./src/batteries/index.ts",types:"./dist/src/batteries/index.d.ts",default:"./dist/tjs-batteries.js"},"./src":"./src/index.ts","./editors/monaco":"./editors/monaco/ajs-monarch.js","./editors/codemirror":"./editors/codemirror/ajs-language.js","./editors/ace":"./editors/ace/ajs-mode.js"},bin:{tjs:"./src/cli/tjs.ts",tjsx:"./src/cli/tjsx.ts","tjs-playground":"./src/cli/playground.ts","create-tjs-app":"./src/cli/create-app.ts","ajs-install-vscode":"./bin/install-vscode.sh","ajs-install-cursor":"./bin/install-cursor.sh"},type:"module",files:["dist","src","docs","editors","bin","demo","tjs-lang.svg","CONTEXT.md","CLAUDE.md"],sideEffects:!1,repository:{type:"git",url:"https://github.com/tonioloewald/tjs-lang.git"},devDependencies:{"@codemirror/lang-css":"^6.3.1","@codemirror/lang-html":"^6.4.11","@codemirror/lang-javascript":"^6.2.4","@codemirror/lang-markdown":"^6.5.0","@codemirror/state":"^6.5.3","@codemirror/theme-one-dark":"^6.1.3","@codemirror/view":"^6.39.9","@happy-dom/global-registrator":"^20.1.0","@types/bun":"latest","@types/jsdom":"^21.1.7","@typescript-eslint/eslint-plugin":"^5.62.0","@typescript-eslint/parser":"^5.62.0","acorn-walk":"^8.3.4",chokidar:"^4.0.3",codemirror:"^6.0.2",esbuild:"^0.28.0",eslint:"^8.57.1",firebase:"^10.12.0","firebase-admin":"^13.6.0","firebase-functions":"^7.0.5",marked:"^9.1.6",prettier:"^2.8.8",tosijs:"^1.5.6","tosijs-ui":"^1.4.7",typescript:"^5.6.2",valibot:"^0.36.0",vitest:"^2.0.5"},scripts:{format:"bun eslint src --fix && bun prettier --write .",lint:"eslint src","build:grammars":"bun editors/build-grammars.ts","test:fast":"SKIP_LLM_TESTS=1 SKIP_BENCHMARKS=1 bun test","test:llm":"bun test src/batteries/models.integration.test.ts",bench:"bun bin/benchmarks.ts",make:"rm -rf dist && bun format && bun run build:grammars && tsc -p tsconfig.build.json && bun scripts/build.ts","build:bundles":"bun scripts/build.ts",typecheck:"tsc --noEmit",latest:"rm -rf node_modules && bun install",docs:"node bin/docs.js",dev:"bun run bin/dev.ts","build:demo":"bun scripts/build-demo.ts","build:cli":"bun build src/cli/tjs.ts --compile --outfile=dist/tjs && bun build src/cli/tjsx.ts --compile --outfile=dist/tjsx","functions:build":"cd functions && npm run build","functions:deploy":"cd functions && npm run deploy","functions:serve":"cd functions && npm run serve","deploy:hosting":"firebase deploy --only hosting",deploy:"npm run build:demo && npm run functions:deploy && firebase deploy --only hosting",start:"bun run build:demo && bun run dev"},dependencies:{acorn:"^8.15.0","acorn-walk":"^8.3.4","tosijs-schema":"^1.3.0"}}});import*as ms from"acorn";var z=class extends Error{line;column;source;filename;constructor(t,n,r,s){let i=`${s||"<source>"}:${n.line}:${n.column}`;super(`${t} at ${i}`),this.name="TranspileError",this.line=n.line,this.column=n.column,this.source=r,this.filename=s}},ie=class extends z{constructor(t,n,r,s){super(t,n,r,s),this.name="SyntaxError"}formatWithContext(t=2){if(!this.source)return this.message;let n=this.source.split(`
1
+ var Bi=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var ws=Bi((mf,ko)=>{ko.exports={name:"tjs-lang",version:"0.7.5",description:"Type-safe JavaScript dialect with runtime validation, sandboxed VM execution, and AI agent orchestration. Transpiles TypeScript to validated JS with fuel-metered execution for untrusted code.",keywords:["typescript","transpiler","runtime-validation","type-safety","sandbox","virtual-machine","wasm-alternative","ai-agents","llm","orchestration","security","fuel-metering","capability-based","json-ast","untrusted-code"],license:"Apache-2.0",main:"./dist/index.js",types:"./dist/src/index.d.ts",exports:{".":{bun:"./src/index.ts",types:"./dist/src/index.d.ts",default:"./dist/index.js"},"./eval":{bun:"./src/lang/eval.ts",types:"./dist/src/lang/eval.d.ts",default:"./dist/tjs-eval.js"},"./lang":{bun:"./src/lang/transpiler.ts",types:"./dist/src/lang/transpiler.d.ts",default:"./dist/tjs-lang.js"},"./lang/from-ts":{bun:"./src/lang/emitters/from-ts.ts",types:"./dist/src/lang/emitters/from-ts.d.ts",default:"./dist/tjs-from-ts.js"},"./vm":{bun:"./src/vm/index.ts",types:"./dist/src/vm/index.d.ts",default:"./dist/tjs-vm.js"},"./batteries":{bun:"./src/batteries/index.ts",types:"./dist/src/batteries/index.d.ts",default:"./dist/tjs-batteries.js"},"./src":"./src/index.ts","./editors/monaco":"./editors/monaco/ajs-monarch.js","./editors/codemirror":"./editors/codemirror/ajs-language.js","./editors/ace":"./editors/ace/ajs-mode.js"},bin:{tjs:"./src/cli/tjs.ts",tjsx:"./src/cli/tjsx.ts","tjs-playground":"./src/cli/playground.ts","create-tjs-app":"./src/cli/create-app.ts","ajs-install-vscode":"./bin/install-vscode.sh","ajs-install-cursor":"./bin/install-cursor.sh"},type:"module",files:["dist","src","docs","editors","bin","demo","tjs-lang.svg","CONTEXT.md","CLAUDE.md"],sideEffects:!1,repository:{type:"git",url:"https://github.com/tonioloewald/tjs-lang.git"},devDependencies:{"@codemirror/lang-css":"^6.3.1","@codemirror/lang-html":"^6.4.11","@codemirror/lang-javascript":"^6.2.4","@codemirror/lang-markdown":"^6.5.0","@codemirror/state":"^6.5.3","@codemirror/theme-one-dark":"^6.1.3","@codemirror/view":"^6.39.9","@happy-dom/global-registrator":"^20.1.0","@types/bun":"latest","@types/jsdom":"^21.1.7","@typescript-eslint/eslint-plugin":"^5.62.0","@typescript-eslint/parser":"^5.62.0","acorn-walk":"^8.3.4",chokidar:"^4.0.3",codemirror:"^6.0.2",esbuild:"^0.28.0",eslint:"^8.57.1",firebase:"^10.12.0","firebase-admin":"^13.6.0","firebase-functions":"^7.0.5",marked:"^9.1.6",prettier:"^2.8.8",tosijs:"^1.5.6","tosijs-ui":"^1.4.7",typescript:"^5.6.2",valibot:"^0.36.0",vitest:"^2.0.5"},scripts:{format:"bun eslint src --fix && bun prettier --write .",lint:"eslint src","build:grammars":"bun editors/build-grammars.ts","test:fast":"SKIP_LLM_TESTS=1 SKIP_BENCHMARKS=1 bun test","test:llm":"bun test src/batteries/models.integration.test.ts",bench:"bun bin/benchmarks.ts",make:"rm -rf dist && bun format && bun run build:grammars && tsc -p tsconfig.build.json && bun scripts/build.ts","build:bundles":"bun scripts/build.ts",typecheck:"tsc --noEmit",latest:"rm -rf node_modules && bun install",docs:"node bin/docs.js",dev:"bun run bin/dev.ts","build:demo":"bun scripts/build-demo.ts","build:cli":"bun build src/cli/tjs.ts --compile --outfile=dist/tjs && bun build src/cli/tjsx.ts --compile --outfile=dist/tjsx","functions:build":"cd functions && npm run build","functions:deploy":"cd functions && npm run deploy","functions:serve":"cd functions && npm run serve","deploy:hosting":"firebase deploy --only hosting",deploy:"npm run build:demo && npm run functions:deploy && firebase deploy --only hosting",start:"bun run build:demo && bun run dev"},dependencies:{acorn:"^8.15.0","acorn-walk":"^8.3.4","tosijs-schema":"^1.3.0"}}});import*as ms from"acorn";var z=class extends Error{line;column;source;filename;constructor(t,n,r,s){let i=`${s||"<source>"}:${n.line}:${n.column}`;super(`${t} at ${i}`),this.name="TranspileError",this.line=n.line,this.column=n.column,this.source=r,this.filename=s}},ie=class extends z{constructor(t,n,r,s){super(t,n,r,s),this.name="SyntaxError"}formatWithContext(t=2){if(!this.source)return this.message;let n=this.source.split(`
2
2
  `),r=this.line-1,s=Math.max(0,r-t),i=Math.min(n.length-1,r+t),o=[],a=String(i+1).length;for(let c=s;c<=i;c++){let l=String(c+1).padStart(a),u=c===r?">":" ";if(o.push(`${u} ${l} | ${n[c]}`),c===r){let p=" ".repeat(a+4+this.column);o.push(`${p}^ ${this.message.split(" at ")[0]}`)}}return o.join(`
3
3
  `)}},Or=class extends z{expected;received;suggestion;constructor(t,n,r){super(t,n,r?.source,r?.filename),this.name="TypeError",this.expected=r?.expected,this.received=r?.received,this.suggestion=r?.suggestion}};function pe(e){return{depth:e.depth+1,locals:new Map,parent:e,parameters:e.parameters,atoms:e.atoms,warnings:e.warnings,source:e.source,filename:e.filename,options:e.options}}function Fi(e,t){if(t.locals.has(e))return t.locals.get(e);if(t.parameters.has(e))return t.parameters.get(e)?.type;if(t.parent)return Fi(e,t.parent)}function Z(e){return e.loc?{line:e.loc.start.line,column:e.loc.start.column}:{line:1,column:0}}function Bt(e,t){let n="",r=0,s,i,o="normal",a=[],c=[{type:"top-level",braceDepth:0}],l=0,u=()=>c[c.length-1]?.type||"top-level",p=()=>{let f=c[c.length-1];return f?.type==="class-body"&&l===f.braceDepth+1};for(;r<e.length;){let f=e[r],m=e[r+1];switch(o){case"single-string":if(n+=f,f==="\\"&&r+1<e.length){n+=m,r+=2;continue}f==="'"&&(o="normal"),r++;continue;case"double-string":if(n+=f,f==="\\"&&r+1<e.length){n+=m,r+=2;continue}f==='"'&&(o="normal"),r++;continue;case"template-string":if(n+=f,f==="\\"&&r+1<e.length){n+=m,r+=2;continue}if(f==="$"&&m==="{"){n+=m,r+=2,a.push(1),o="normal";continue}f==="`"&&(o="normal"),r++;continue;case"line-comment":n+=f,f===`
4
4
  `&&(o="normal"),r++;continue;case"block-comment":if(n+=f,f==="*"&&m==="/"){n+=m,r+=2,o="normal";continue}r++;continue;case"regex":if(n+=f,f==="\\"&&r+1<e.length){n+=m,r+=2;continue}if(f==="["){for(r++;r<e.length&&e[r]!=="]";)n+=e[r],e[r]==="\\"&&r+1<e.length?(n+=e[r+1],r+=2):r++;r<e.length&&(n+=e[r],r++);continue}if(f==="/"){for(r++;r<e.length&&/[gimsuy]/.test(e[r]);)n+=e[r],r++;o="normal";continue}r++;continue;case"normal":if(a.length>0){if(f==="{")a[a.length-1]++;else if(f==="}"&&(a[a.length-1]--,a[a.length-1]===0)){a.pop(),n+=f,r++,o="template-string";continue}}if(f==="'"){n+=f,r++,o="single-string";continue}if(f==='"'){n+=f,r++,o="double-string";continue}if(f==="`"){n+=f,r++,o="template-string";continue}if(f==="/"&&m==="/"){n+=f+m,r+=2,o="line-comment";continue}if(f==="/"&&m==="*"){n+=f+m,r+=2,o="block-comment";continue}if(f==="/"){let b=n.trimEnd();if(!b[b.length-1]||/[=(!,;:{[&|?+\-*%<>~^]$/.test(b)||/\b(return|case|throw|in|of|typeof|instanceof|new|delete|void)\s*$/.test(b)){n+=f,r++,o="regex";continue}}break}if(f==="{"){l++,n+=f,r++;continue}if(f==="}"){l--;let b=c[c.length-1];b&&l===b.braceDepth&&c.pop(),n+=f,r++;continue}let d=e.slice(r).match(/^class\s+\w+(?:\s+extends\s+\w+)?\s*\{/);if(d){let b=d[0].slice(0,-1);n+=b,r+=b.length,c.push({type:"class-body",braceDepth:l});continue}let y=e.slice(r).match(/^function\s+(\w+)\s*\(/);if(y){let b=y[1],T=y[0].length,k=e[r+T],w=null,j=r+T;(k==="?"||k==="!")&&(w=k,j++,w==="!"?t.unsafeFunctions.add(b):t.safeFunctions.add(b)),n+=`function ${b}(`,r=j;let C=Dt(e,r,"(",")");if(!C){n+=e[r],r++;continue}let{content:$,endPos:R}=C;r=R;let A=Wn($,t,!0);n+=A+")";let P=r;for(;P<e.length&&/\s/.test(e[P]);)P++;if(e[P]===":"){let v=e.slice(P,P+2),I;for(v===":?"||v===":!"?(P+=2,I=v===":?"?"safe":"unsafe"):P+=1;P<e.length&&/\s/.test(e[P]);)P++;let O=Jn(e,P);O&&(s===void 0&&(s=O.type,I&&(i=I)),r=O.endPos)}continue}let x=e.slice(r).match(/^(constructor|(?:get|set)\s+\w+|async\s+\w+|\w+)\s*\(/),E=(()=>{for(let b=n.length-1;b>=0;b--)if(!/\s/.test(n[b]))return n[b];return`
5
5
  `})(),_=E!=="="&&E!==","&&E!=="("&&E!=="["&&E!==">";if(x&&p()&&!_){let b=x[1].length;n+=e.slice(r,r+b),r+=b;continue}if(x&&p()&&_){let b=x[1],T=x[0].length,k=r+T;n+=b+"(",r=k;let w=Dt(e,r,"(",")");if(!w){n+=e[r],r++;continue}let{content:j,endPos:C}=w;r=C;let $=Wn(j,t,!0);n+=$+")";let R=r;for(;R<e.length&&/\s/.test(e[R]);)R++;if(e[R]===":"){let A=e.slice(R,R+2);for(A===":?"||A===":!"?R+=2:R++;R<e.length&&/\s/.test(e[R]);)R++;let P=Jn(e,R);P&&(r=P.endPos)}continue}if(e[r]==="("){let b=Dt(e,r+1,"(",")");if(!b){n+=e[r],r++;continue}let T=b.content,k=b.endPos,w=k;for(;w<e.length&&/\s/.test(e[w]);)w++;let j;if(e[w]===":"){let C=e.slice(w,w+2);for(C===":?"||C===":!"?w+=2:w++;w<e.length&&/\s/.test(e[w]);)w++;let $=Jn(e,w);if($)for(j=$.type,w=$.endPos;w<e.length&&/\s/.test(e[w]);)w++}if(e.slice(w,w+2)==="=>"){let C=null,$=T,R=T.trimStart();R.startsWith("?")&&(R.length===1||/\s/.test(R[1]))?(C="?",$=R.slice(1)):R.startsWith("!")&&(R.length===1||/\s/.test(R[1]))&&(C="!",$=R.slice(1));let A=Wn($,t,!1);for(n+=`(${C==="?"?"/* safe */ ":C==="!"?"/* unsafe */ ":""}${A})`,r=k;r<w&&/\s/.test(e[r]);)n+=e[r],r++;j&&(r=w)}else{let C=Bt(T,t);n+=`(${C.source})`,r=k}continue}n+=e[r],r++}return{source:n,returnType:s,returnSafety:i}}function Dt(e,t,n,r){let s=1,i=t,o=!1,a="";for(;i<e.length&&s>0;){let c=e[i];!o&&(c==="'"||c==='"'||c==="`")?(o=!0,a=c):o&&c===a&&e[i-1]!=="\\"?o=!1:o||(c===n?s++:c===r&&s--),i++}return s!==0?null:{content:e.slice(t,i-1),endPos:i}}function Fr(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;if(n>=e.length)return null;let r=n,s=e[n];if(s==="{"||s==="["){let o=s==="{"?"}":"]",a=Dt(e,n+1,s,o);return a?{value:e.slice(r,a.endPos),endPos:a.endPos}:null}if(s==="'"||s==='"'||s==="`"){for(n++;n<e.length;){if(e[n]===s&&e[n-1]!=="\\")return n++,{value:e.slice(r,n),endPos:n};n++}return null}if(/[-+\d]/.test(s)){for(;n<e.length&&/[\d.eE+-]/.test(e[n]);)n++;return{value:e.slice(r,n),endPos:n}}let i=e.slice(n).match(/^(true|false|null|undefined)\b/);return i?{value:i[1],endPos:n+i[1].length}:null}function ft(e){return e.replace(/(?<!\|)\|(?!\|)/g," || ")}function Jn(e,t){let n=t,r=0,s=!1,i="",o=!1,a=c=>({type:ft(e.slice(t,c).trim()),endPos:c});for(;n<e.length;){let c=e[n];if(!s&&(c==="'"||c==='"'||c==="`")){s=!0,i=c,o=!0,n++;continue}if(s){if(c===i&&e[n-1]!=="\\"){if(s=!1,n++,r===0){let l=n;for(;l<e.length&&/\s/.test(e[l]);)l++;if(e[l]==="{"&&!e.slice(l+1).match(/^\s*(\w+)\s*:/)||e[l]!=="|"&&e[l]!=="&")return a(n)}continue}n++;continue}if(c==="{"||c==="["||c==="("){r++,o=!0,n++;continue}if(c==="}"||c==="]"||c===")"){if(r--,r===0){n++;let l=n;for(;l<e.length&&/\s/.test(e[l]);)l++;if(e[l]==="|"||e[l]==="&")continue;return a(n)}n++;continue}if(r===0&&c==="{"){if(o)return a(n);if(e.slice(n+1).match(/^\s*(\w+)\s*:/)){r++,o=!0,n++;continue}return a(n)}if(r===0&&(c==="|"||c==="&")){for(n++,n<e.length&&e[n]==="|"&&n++;n<e.length&&/\s/.test(e[n]);)n++;continue}if(r===0&&(/\d/.test(c)||c==="-"&&/\d/.test(e[n+1]))){let l=n;for(e[l]==="-"&&l++;l<e.length&&/\d/.test(e[l]);)l++;if(l<e.length&&e[l]==="."&&/\d/.test(e[l+1]))for(l++;l<e.length&&/\d/.test(e[l]);)l++;if(l<e.length&&(e[l]==="e"||e[l]==="E"))for(l++,l<e.length&&(e[l]==="+"||e[l]==="-")&&l++;l<e.length&&/\d/.test(e[l]);)l++;for(o=!0,n=l;n<e.length&&/\s/.test(e[n]);)n++;if(n<e.length&&e[n]==="{")return{type:ft(e.slice(t,l).trim()),endPos:l};if(e[n]!=="|"&&e[n]!=="&")return{type:ft(e.slice(t,l).trim()),endPos:l};continue}if(r===0&&/[a-zA-Z_]/.test(c)){let l=n;for(;l<e.length&&/\w/.test(e[l]);)l++;for(o=!0,n=l;n<e.length&&/\s/.test(e[n]);)n++;if(n<e.length&&e[n]==="("){r++,n++;continue}if(n<e.length&&e[n]==="{"&&!e.slice(n+1).match(/^\s*(\w+)\s*:/)){let p=l;for(;p>t&&/\s/.test(e[p-1]);)p--;return{type:ft(e.slice(t,p).trim()),endPos:l}}if(e[n]!=="|"&&e[n]!=="&")return{type:ft(e.slice(t,l).trim()),endPos:l};continue}n++}return o?a(n):null}function Ft(e){let t=[],n="",r=0,s=!1,i=!1,o=0;for(;o<e.length;){let a=e[o],c=e[o+1];if(!i&&a==="/"&&c==="/"){s=!0,n+="//",o+=2;continue}if(!s&&a==="/"&&c==="*"){i=!0,n+="/*",o+=2;continue}if(s&&a===`
6
- `){s=!1,n+=a,o++;continue}if(i&&a==="*"&&c==="/"){i=!1,n+="*/",o+=2;continue}if(s||i){n+=a,o++;continue}a==="("||a==="{"||a==="["?(r++,n+=a):a===")"||a==="}"||a==="]"?(r--,n+=a):a===","&&r===0?(t.push(n),n=""):n+=a,o++}return n.trim()&&t.push(n),t}function Wn(e,t,n){let r=Bt(e,{originalSource:e,requiredParams:t.requiredParams,unsafeFunctions:t.unsafeFunctions,safeFunctions:t.safeFunctions}).source,s=Ft(r),i=!1,o=new Set,a=l=>{if(n&&/^\w+$/.test(l)){if(o.has(l))throw new Error(`Duplicate parameter name '${l}'`);o.add(l)}};return s.map(l=>{let u=l.trim();if(!u)return l;if(n&&u.startsWith("{")&&u.endsWith("}")){let m=u.slice(1,-1);return`{ ${Lr(m,t)} }`}if(n&&u.startsWith("[")&&u.endsWith("]")){let m=u.slice(1,-1);return`[ ${Lr(m,t)} ]`}if(u.startsWith("...")){let m=Br(u);return m!==-1?u.slice(0,m).trim():l}let p=u.match(/^(\w+)\s*\?\s*:\s*(.+)$/);if(p){let[,m,d]=p;return a(m),i=!0,`${m} = ${d}`}if(!Ui(u)){let m=u.match(/^(\w+)\s*=/);return m&&a(m[1]),i=!0,l}let f=Br(u);if(f!==-1){let m=u.slice(0,f).trim(),d=u.slice(f+1).trim();return a(m),i&&n&&/^\w+$/.test(m),n&&/^\w+$/.test(m)&&t.requiredParams.add(m),`${m} = ${d}`}return l}).join(",")}function Lr(e,t){return Ft(e).map(s=>{let i=s.trim();if(!i)return s;let o=i.match(/^(\w+)\s*:\s*(\{[\s\S]*\})$/);if(o){let[,l,u]=o;t.requiredParams.add(l);let p=Ot(u);return`${l} = ${p}`}let a=i.match(/^(\w+)\s*:\s*(\[[\s\S]*\])$/);if(a){let[,l,u]=a;t.requiredParams.add(l);let p=Lt(u);return`${l} = ${p}`}let c=i.match(/^(\w+)\s*:\s*([\s\S]+)$/);if(c){let[,l,u]=c;return t.requiredParams.add(l),`${l} = ${u}`}return s}).join(", ")}function Ot(e){let t=e.slice(1,-1).trim();return`{ ${Ft(t).map(s=>{let i=s.trim();if(!i)return s;let o=i.match(/^(\w+)\s*:\s*(\{[\s\S]*\})$/);if(o){let[,p,f]=o;return`${p}: ${Ot(f)}`}let a=i.match(/^(\w+)\s*=\s*(\{[\s\S]*\})$/);if(a){let[,p,f]=a;return`${p}: ${Ot(f)}`}let c=i.match(/^(\w+)\s*:\s*(\[[\s\S]*\])$/);if(c){let[,p,f]=c;return`${p}: ${Lt(f)}`}let l=i.match(/^(\w+)\s*=\s*(\[[\s\S]*\])$/);if(l){let[,p,f]=l;return`${p}: ${Lt(f)}`}let u=i.match(/^(\w+)\s*=\s*([\s\S]+)$/);if(u){let[,p,f]=u;return`${p}: ${f}`}return s}).join(", ")} }`}function Lt(e){let t=e.slice(1,-1).trim();return`[ ${Ft(t).map(s=>{let i=s.trim();return i?i.startsWith("{")&&i.endsWith("}")?Ot(i):i.startsWith("[")&&i.endsWith("]")?Lt(i):s:s}).join(", ")} ]`}function Ui(e){let t=0,n=!1,r=!1,s=!1,i="";for(let o=0;o<e.length;o++){let a=e[o];if(!s&&(a==="'"||a==='"'||a==="`")){s=!0,i=a;continue}if(s){a===i&&e[o-1]!=="\\"&&(s=!1);continue}a==="("||a==="{"||a==="["?t++:a===")"||a==="}"||a==="]"?t--:t===0&&(a===":"&&(n=!0),a==="="&&e[o+1]!==">"&&(r=!0))}return n&&!r}function Br(e){let t=0,n=!1,r="";for(let s=0;s<e.length;s++){let i=e[s];if(!n&&(i==="'"||i==='"'||i==="`")){n=!0,r=i;continue}if(n){i===r&&e[s-1]!=="\\"&&(n=!1);continue}if(i==="("||i==="{"||i==="[")t++;else if(i===")"||i==="}"||i==="]")t--;else if(t===0&&i===":")return s}return-1}function qi(e,t){let n=e.match(t);if(!n)return null;let r=n.index+n[0].length-1,s=1,i=r+1;for(;i<e.length&&s>0;)e[i]==="{"?s++:e[i]==="}"&&s--,i++;if(s!==0)return null;let o=e.slice(r,i),a=[n[0].slice(0,-1)+o,o];return a.index=n.index,a}function Vr(e){let t="",n=0;for(;n<e.length;){let r=e.slice(n).match(/^\btry\s*\{/);if(r){let i=n+r[0].length-1+1,o=1,a=i;for(;a<e.length&&o>0;){let l=e[a];l==="{"?o++:l==="}"&&o--,a++}if(o!==0){t+=e[n],n++;continue}if(e.slice(a).match(/^\s*(catch|finally)\b/))t+=e.slice(n,a),n=a;else{let l=e.slice(i,a-1);t+=`try {${l}} catch (__try_err) { return new (__tjs?.MonadicError ?? Error)(__try_err?.message || String(__try_err), 'try', undefined, undefined, __tjs?.getStack?.()) }`,n=a}}else t+=e[n],n++}return t}function Kr(e){let t=[],n="",r=0,s=0;for(;r<e.length;){let i=e.slice(r).match(/^\bwasm\s*\{/);if(i){let o=r,a=r+i[0].length,c=1,l=a;for(;l<e.length&&c>0;){let w=e[l];w==="{"?c++:w==="}"&&c--,l++}if(c!==0){n+=e[r],r++;continue}let u=e.slice(a,l-1),p,f=l,m=e.slice(l).match(/^\s*fallback\s*\{/);if(m){let w=l+m[0].length;c=1;let j=w;for(;j<e.length&&c>0;){let C=e[j];C==="{"?c++:C==="}"&&c--,j++}c===0&&(p=e.slice(w,j-1),f=j)}let y=Wi(u).map(w=>{let j=Vi(e,o,w);return j?`${w}: ${j}`:w}),x={id:`__tjs_wasm_${s}`,body:u,fallback:p,captures:y,start:o,end:f};t.push(x);let E=p??u,_=y.map(w=>w.split(":")[0].trim()),b=_.length>0?_.join(", "):"",T=_.length>0?`globalThis.${x.id}(${b})`:`globalThis.${x.id}()`,k=`(globalThis.${x.id} ? ${T} : (() => {${E}})())`;n+=k,r=f,s++}else n+=e[r],r++}return{source:n,blocks:t}}function Ji(e){return e.startsWith("f32x4_")||e.startsWith("v128_")}function Wi(e){let t=e.replace(/\/\/[^\n]*/g,"").replace(/\/\*[\s\S]*?\*\//g,""),n=new Set,r=/\.([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g,s;for(;(s=r.exec(t))!==null;)n.add(s[1]);let i=/(?<!\.)(\b[a-zA-Z_$][a-zA-Z0-9_$]*)\b/g,o=new Set;for(;(s=i.exec(t))!==null;)o.add(s[1]);for(let f of n){if(!o.has(f))continue;let m=new RegExp(`(?<!\\.)\\b${f}\\b`,"g"),d=new RegExp(`\\.${f}\\b`,"g"),y=t.match(m)?.length||0,x=t.match(d)?.length||0;y<=x&&o.delete(f)}let a=new Set,c=/\b(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;for(;(s=c.exec(t))!==null;)a.add(s[1]);let l=/\bfor\s*\(\s*(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;for(;(s=l.exec(t))!==null;)a.add(s[1]);let u=new Set(["if","else","for","while","do","switch","case","break","continue","return","function","let","const","var","new","this","true","false","null","undefined","typeof","instanceof","in","of","try","catch","finally","throw","async","await","class","extends","super","import","export","default","from","as","static","get","set","yield","console","Math","Array","Object","String","Number","Boolean","Date","JSON","Promise","Map","Set","WeakMap","WeakSet","Float32Array","Float64Array","Int8Array","Int16Array","Int32Array","Uint8Array","Uint16Array","Uint32Array","BigInt64Array","BigUint64Array","ArrayBuffer","DataView","Error","TypeError","RangeError","length","push","pop","shift","unshift","slice","splice","map","filter","reduce","forEach","find","findIndex","indexOf","includes","globalThis","window","document","Infinity","NaN","isNaN","isFinite","parseInt","parseFloat","encodeURI","decodeURI","eval","wasmBuffer"]),p=[];for(let f of o)!a.has(f)&&!u.has(f)&&!Ji(f)&&p.push(f);return p.sort()}function Vi(e,t,n){let r=e.slice(0,t),s=/function\s+\w+\s*\(([^)]*)\)\s*(?:->.*?)?\s*\{[^}]*$/,i=r.match(s);if(!i){let o=/(?:const|let|var)?\s*\w+\s*=\s*(?:async\s*)?\(([^)]*)\)\s*(?:=>|->)?\s*\{[^}]*$/,a=r.match(o);return a?Ur(a[1],n):void 0}return Ur(i[1],n)}function Ur(e,t){let n=e.split(",").map(r=>r.trim());for(let r of n){let s=r.match(new RegExp(`^${t}\\s*:\\s*([A-Za-z][A-Za-z0-9]*)`));if(s)return s[1];let i=r.match(new RegExp(`^${t}\\s*=\\s*(Float32Array|Float64Array|Int32Array|Uint8Array|Int8Array|Int16Array|Uint16Array|Uint32Array)`));if(i)return i[1]}}function zr(e){let t=`([\\w][\\w.\\[\\]()]*|null|undefined|true|false|\\d+(?:\\.\\d+)?|'[^']*'|"[^"]*")`,n=new RegExp(t+"\\s+IsNot\\s+"+t,"g");e=e.replace(n,"IsNot($1, $2)");let r=new RegExp(t+"\\s+Is\\s+"+t,"g");return e=e.replace(r,"Is($1, $2)"),e}function Gr(e){let t=/^[\s]*[([/+\-`]/,n=/[{([,;:+\-*/%=&|?<>!~^]\s*$|^\s*$/,r=/\b(return|throw|yield|await|case|default|extends|new|typeof|void|delete|in|of|instanceof)\s*$/,s=e.split(`
6
+ `){s=!1,n+=a,o++;continue}if(i&&a==="*"&&c==="/"){i=!1,n+="*/",o+=2;continue}if(s||i){n+=a,o++;continue}a==="("||a==="{"||a==="["?(r++,n+=a):a===")"||a==="}"||a==="]"?(r--,n+=a):a===","&&r===0?(t.push(n),n=""):n+=a,o++}return n.trim()&&t.push(n),t}function Wn(e,t,n){let r=Bt(e,{originalSource:e,requiredParams:t.requiredParams,unsafeFunctions:t.unsafeFunctions,safeFunctions:t.safeFunctions}).source,s=Ft(r),i=!1,o=new Set,a=l=>{if(n&&/^\w+$/.test(l)){if(o.has(l))throw new Error(`Duplicate parameter name '${l}'`);o.add(l)}};return s.map(l=>{let u=l.trim();if(!u)return l;if(n&&u.startsWith("{")&&u.endsWith("}")){let m=u.slice(1,-1);return`{ ${Lr(m,t)} }`}if(n&&u.startsWith("[")&&u.endsWith("]")){let m=u.slice(1,-1);return`[ ${Lr(m,t)} ]`}if(u.startsWith("...")){let m=Br(u);return m!==-1?u.slice(0,m).trim():l}let p=u.match(/^(\w+)\s*\?\s*:\s*(.+)$/);if(p){let[,m,d]=p;return a(m),i=!0,`${m} = ${d}`}if(!Ui(u)){let m=u.match(/^(\w+)\s*=/);return m&&a(m[1]),i=!0,l}let f=Br(u);if(f!==-1){let m=u.slice(0,f).trim(),d=u.slice(f+1).trim();return a(m),i&&n&&/^\w+$/.test(m),n&&/^\w+$/.test(m)&&t.requiredParams.add(m),`${m} = ${d}`}return l}).join(",")}function Lr(e,t){return Ft(e).map(s=>{let i=s.trim();if(!i)return s;let o=i.match(/^(\w+)\s*:\s*(\{[\s\S]*\})$/);if(o){let[,l,u]=o;t.requiredParams.add(l);let p=Ot(u);return`${l} = ${p}`}let a=i.match(/^(\w+)\s*:\s*(\[[\s\S]*\])$/);if(a){let[,l,u]=a;t.requiredParams.add(l);let p=Lt(u);return`${l} = ${p}`}let c=i.match(/^(\w+)\s*:\s*([\s\S]+)$/);if(c){let[,l,u]=c;return t.requiredParams.add(l),`${l} = ${u}`}return s}).join(", ")}function Ot(e){let t=e.slice(1,-1).trim();return`{ ${Ft(t).map(s=>{let i=s.trim();if(!i)return s;let o=i.match(/^(\w+)\s*:\s*(\{[\s\S]*\})$/);if(o){let[,p,f]=o;return`${p}: ${Ot(f)}`}let a=i.match(/^(\w+)\s*=\s*(\{[\s\S]*\})$/);if(a){let[,p,f]=a;return`${p}: ${Ot(f)}`}let c=i.match(/^(\w+)\s*:\s*(\[[\s\S]*\])$/);if(c){let[,p,f]=c;return`${p}: ${Lt(f)}`}let l=i.match(/^(\w+)\s*=\s*(\[[\s\S]*\])$/);if(l){let[,p,f]=l;return`${p}: ${Lt(f)}`}let u=i.match(/^(\w+)\s*=\s*([\s\S]+)$/);if(u){let[,p,f]=u;return`${p}: ${f}`}return s}).join(", ")} }`}function Lt(e){let t=e.slice(1,-1).trim();return`[ ${Ft(t).map(s=>{let i=s.trim();return i?i.startsWith("{")&&i.endsWith("}")?Ot(i):i.startsWith("[")&&i.endsWith("]")?Lt(i):s:s}).join(", ")} ]`}function Ui(e){let t=0,n=!1,r=!1,s=!1,i="";for(let o=0;o<e.length;o++){let a=e[o];if(!s&&(a==="'"||a==='"'||a==="`")){s=!0,i=a;continue}if(s){a===i&&e[o-1]!=="\\"&&(s=!1);continue}a==="("||a==="{"||a==="["?t++:a===")"||a==="}"||a==="]"?t--:t===0&&(a===":"&&(n=!0),a==="="&&e[o+1]!==">"&&(r=!0))}return n&&!r}function Br(e){let t=0,n=!1,r="";for(let s=0;s<e.length;s++){let i=e[s];if(!n&&(i==="'"||i==='"'||i==="`")){n=!0,r=i;continue}if(n){i===r&&e[s-1]!=="\\"&&(n=!1);continue}if(i==="("||i==="{"||i==="[")t++;else if(i===")"||i==="}"||i==="]")t--;else if(t===0&&i===":")return s}return-1}function qi(e,t){let n=e.match(t);if(!n)return null;let r=n.index+n[0].length-1,s=1,i=r+1;for(;i<e.length&&s>0;)e[i]==="{"?s++:e[i]==="}"&&s--,i++;if(s!==0)return null;let o=e.slice(r,i),a=[n[0].slice(0,-1)+o,o];return a.index=n.index,a}function Vr(e){let t="",n=0;for(;n<e.length;){let r=e.slice(n).match(/^\btry\s*\{/);if(r){let i=n+r[0].length-1+1,o=1,a=i;for(;a<e.length&&o>0;){let l=e[a];l==="{"?o++:l==="}"&&o--,a++}if(o!==0){t+=e[n],n++;continue}if(e.slice(a).match(/^\s*(catch|finally)\b/))t+=e.slice(n,a),n=a;else{let l=e.slice(i,a-1);t+=`try {${l}} catch (__try_err) { return new (__tjs?.MonadicError ?? Error)(__try_err?.message || String(__try_err), 'try', undefined, undefined, __tjs?.getStack?.()) }`,n=a}}else t+=e[n],n++}return t}function Kr(e){let t=[],n="",r=0,s=0;for(;r<e.length;){let i=e.slice(r).match(/^\bwasm\s*\{/);if(i){let o=r,a=r+i[0].length,c=1,l=a;for(;l<e.length&&c>0;){let w=e[l];w==="{"?c++:w==="}"&&c--,l++}if(c!==0){n+=e[r],r++;continue}let u=e.slice(a,l-1),p,f=l,m=e.slice(l).match(/^\s*fallback\s*\{/);if(m){let w=l+m[0].length;c=1;let j=w;for(;j<e.length&&c>0;){let C=e[j];C==="{"?c++:C==="}"&&c--,j++}c===0&&(p=e.slice(w,j-1),f=j)}let y=Wi(u).map(w=>{let j=Vi(e,o,w);return j?`${w}: ${j}`:w}),x={id:`__tjs_wasm_${s}`,body:u,fallback:p,captures:y,start:o,end:f};t.push(x);let E=p??u,_=y.map(w=>w.split(":")[0].trim()),b=_.length>0?_.join(", "):"",T=_.length>0?`globalThis.${x.id}(${b})`:`globalThis.${x.id}()`,k=`(globalThis.${x.id} ? ${T} : (() => {${E}})())`;n+=k,r=f,s++}else n+=e[r],r++}return{source:n,blocks:t}}function Ji(e){return e.startsWith("f32x4_")||e.startsWith("v128_")}function Wi(e){let t=e.replace(/\/\/[^\n]*/g,"").replace(/\/\*[\s\S]*?\*\//g,""),n=new Set,r=/\.([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g,s;for(;(s=r.exec(t))!==null;)n.add(s[1]);let i=/(?<!\.)(\b[a-zA-Z_$][a-zA-Z0-9_$]*)\b/g,o=new Set;for(;(s=i.exec(t))!==null;)o.add(s[1]);for(let f of n){if(!o.has(f))continue;let m=new RegExp(`(?<!\\.)\\b${f}\\b`,"g"),d=new RegExp(`\\.${f}\\b`,"g"),y=t.match(m)?.length||0,x=t.match(d)?.length||0;y<=x&&o.delete(f)}let a=new Set,c=/\b(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;for(;(s=c.exec(t))!==null;)a.add(s[1]);let l=/\bfor\s*\(\s*(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;for(;(s=l.exec(t))!==null;)a.add(s[1]);let u=new Set(["if","else","for","while","do","switch","case","break","continue","return","function","let","const","var","new","this","true","false","null","undefined","typeof","instanceof","in","of","try","catch","finally","throw","async","await","class","extends","super","import","export","default","from","as","static","get","set","yield","console","Math","Array","Object","String","Number","Boolean","Date","JSON","Promise","Map","Set","WeakMap","WeakSet","Float32Array","Float64Array","Int8Array","Int16Array","Int32Array","Uint8Array","Uint16Array","Uint32Array","BigInt64Array","BigUint64Array","ArrayBuffer","DataView","Error","TypeError","RangeError","length","push","pop","shift","unshift","slice","splice","map","filter","reduce","forEach","find","findIndex","indexOf","includes","globalThis","window","document","Infinity","NaN","isNaN","isFinite","parseInt","parseFloat","encodeURI","decodeURI","eval","wasmBuffer"]),p=[];for(let f of o)!a.has(f)&&!u.has(f)&&!Ji(f)&&p.push(f);return p.sort()}function Vi(e,t,n){let r=e.slice(0,t),s=/function\s+\w+\s*\(([^)]*)\)\s*(?:->.*?)?\s*\{[^}]*$/,i=r.match(s);if(!i){let o=/(?:const|let|var)?\s*\w+\s*=\s*(?:async\s*)?\(([^)]*)\)\s*(?:=>|->)?\s*\{[^}]*$/,a=r.match(o);return a?Ur(a[1],n):void 0}return Ur(i[1],n)}function Ur(e,t){let n=e.split(",").map(r=>r.trim());for(let r of n){let s=r.match(new RegExp(`^${t}\\s*:\\s*([A-Za-z][A-Za-z0-9]*)`));if(s)return s[1];let i=r.match(new RegExp(`^${t}\\s*=\\s*(Float32Array|Float64Array|Int32Array|Uint8Array|Int8Array|Int16Array|Uint16Array|Uint32Array)`));if(i)return i[1]}}function zr(e){let t=`([\\w][\\w.\\[\\]()]*|null|undefined|true|false|\\d+(?:\\.\\d+)?|'[^']*'|"[^"]*")`,n=new RegExp(t+"\\s+IsNot\\s+"+t,"g");e=e.replace(n,"IsNot($1, $2)");let r=new RegExp(t+"\\s+Is\\s+"+t,"g");return e=e.replace(r,"Is($1, $2)"),e}function Gr(e){let t=/^[\s]*[([`]/,n=/[{([,;:+\-*/%=&|?<>!~^]\s*$|^\s*$/,r=/\b(return|throw|yield|await|case|default|extends|new|typeof|void|delete|in|of|instanceof)\s*$/,s=e.split(`
7
7
  `),i=[],o=!1;for(let a=0;a<s.length;a++){let c=s[a],l=a>0?s[a-1]:"";if(o){i.push(c),c.includes("*/")&&(o=!1);continue}let u=c.indexOf("/*"),p=c.indexOf("*/");if(u!==-1&&(p===-1||p<u)){o=!0,i.push(c);continue}if(a>0&&t.test(c)){let f=l.replace(/\/\/.*$/,"").replace(/\/\*.*\*\/\s*$/,"");if(!n.test(f)&&!r.test(f)){let m=c.match(/^(\s*)/),d=m?m[1]:"",y=c.slice(d.length);i.push(d+";"+y);continue}}i.push(c)}return i.join(`
8
8
  `)}function Hr(e){e=e.replace(/\btypeof\s+([a-zA-Z_$][\w$.]*(?:\?\.[\w$]+)*)/g,"TypeOf($1)");let t=[],n=0,r="normal",s=[];for(;n<e.length;){let o=e[n],a=e[n+1];switch(r){case"single-string":if(o==="\\"&&n+1<e.length){n+=2;continue}o==="'"&&(r="normal"),n++;continue;case"double-string":if(o==="\\"&&n+1<e.length){n+=2;continue}o==='"'&&(r="normal"),n++;continue;case"template-string":if(o==="\\"&&n+1<e.length){n+=2;continue}if(o==="$"&&a==="{"){n+=2,s.push(1),r="normal";continue}o==="`"&&(r="normal"),n++;continue;case"line-comment":o===`
9
9
  `&&(r="normal"),n++;continue;case"block-comment":if(o==="*"&&a==="/"){n+=2,r="normal";continue}n++;continue;case"regex":if(o==="\\"&&n+1<e.length){n+=2;continue}if(o==="["){for(n++;n<e.length&&e[n]!=="]";)e[n]==="\\"&&n+1<e.length?n+=2:n++;n<e.length&&n++;continue}if(o==="/"){for(n++;n<e.length&&/[gimsuy]/.test(e[n]);)n++;r="normal";continue}n++;continue;case"normal":if(s.length>0){if(o==="{")s[s.length-1]++;else if(o==="}"&&(s[s.length-1]--,s[s.length-1]===0)){s.pop(),n++,r="template-string";continue}}if(o==="'"){n++,r="single-string";continue}if(o==='"'){n++,r="double-string";continue}if(o==="`"){n++,r="template-string";continue}if(o==="/"&&a==="/"){n+=2,r="line-comment";continue}if(o==="/"&&a==="*"){n+=2,r="block-comment";continue}if(o==="/"){let c=n-1;for(;c>=0&&/\s/.test(e[c]);)c--;let l=c>=0?e[c]:"";if(!l||/[=(!,;:{[&|?+\-*%<>~^]/.test(l)||c>=5&&/\b(return|case|throw|in|of|typeof|instanceof|new|delete|void)$/.test(e.slice(Math.max(0,c-10),c+1))){n++,r="regex";continue}}if(o==="="&&a==="="&&e[n+2]!=="="&&e[n-1]!=="!"){t.push({pos:n,op:"=="}),n+=2;continue}if(o==="!"&&a==="="&&e[n+2]!=="="){t.push({pos:n,op:"!="}),n+=2;continue}break}n++}if(t.length===0)return e;let i=e;for(let o=t.length-1;o>=0;o--){let{pos:a,op:c}=t[o],l=c==="=="?"Eq":"NotEq",u=Ki(i,a),p=zi(i,a+2),f=i.slice(u,a).trim(),m=i.slice(a+2,p).trim();if(f&&m){let d=i.slice(0,u),y=i.slice(p),E=/[a-zA-Z0-9_$]$/.test(d)?" ":"";i=`${d}${E}${l}(${f}, ${m})${y}`}}return i}function Ki(e,t){let n=t-1;for(;n>=0&&/\s/.test(e[n]);)n--;if(n<0)return 0;let r=0,s=!1,i="";for(;n>=0;){let o=e[n],a=n>0?e[n-1]:"";if(s){o===i&&a!=="\\"&&(s=!1),n--;continue}if((o==='"'||o==="'"||o==="`")&&a!=="\\"){s=!0,i=o,n--;continue}if(o===")"||o==="]"||o==="}"){r++,n--;continue}if(o==="("||o==="["){if(r>0){r--,n--;continue}return n+1}if(o==="{"){if(r>0){r--,n--;continue}return n+1}if(r>0){n--;continue}if(o===";")return n+1;if(/[a-z]/.test(o)){let c=n+1,l=n;for(;l>0&&/[a-z]/i.test(e[l-1]);)l--;let u=e.slice(l,c),p=l>0?e[l-1]:"";if(!/[a-zA-Z0-9_$]/.test(p)){if(["return","throw","case","typeof","void","delete","await","yield"].includes(u))return c;if(u==="new")return l}}if(o===">"&&a==="="||o==="="&&a!=="="&&a!=="!"&&a!=="<"&&a!==">"||o==="&"&&a==="&"||o==="|"&&a==="|"||o==="?"||o===":"||o===",")return n+1;n--}return 0}function zi(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;if(n>=e.length)return e.length;let r=0,s=!1,i="";for(;n<e.length;){let o=e[n],a=n+1<e.length?e[n+1]:"";if(s){o===i&&e[n-1]!=="\\"&&(s=!1),n++;continue}if((o==='"'||o==="'"||o==="`")&&e[n-1]!=="\\"){s=!0,i=o,n++;continue}if(o==="("||o==="["||o==="{"){r++,n++;continue}if(o===")"||o==="]"||o==="}"){if(r>0){r--,n++;continue}return n}if(r>0){n++;continue}if(o===";"||o==="&"&&a==="&"||o==="|"&&a==="|"||o==="?"||o===":"||o===","||(o==="="||o==="!")&&a==="="&&e[n+2]!=="=")return n;n++}return e.length}function Zr(e){let t="",n=0;for(;n<e.length;){let r=e.slice(n).match(/^\bType\s+([A-Z_][a-zA-Z0-9_]*)\s*/);if(r){let s=r[1],i=n+r[0].length,o=s,a=!1,c=e.slice(i).match(/^(['"`])([^]*?)\1\s*/);if(c){let f=i+c[0].length,m=e[f],d=m===void 0||f>=e.length||m!=="="&&m!=="{";if(m==="="||m==="{")o=c[2],a=!0,i=f;else if(d){let y=c[0].trim(),x=c[0].slice(y.length);t+=`const ${s} = Type('${s}', ${y})${x}`,n=f;continue}}let l,u=i,p=e.slice(i).match(/^=\s*/);if(p){i+=p[0].length;let f=e.slice(i).match(/^(\+?\d+(?:\.\d+)?|['"`][^'"`]*['"`]|\{[^}]*\}|\[[^\]]*\]|true|false|null)/);if(f){l=f[0],i+=f[0].length,u=i;let m=e.slice(i).match(/^\s*/);m&&(i+=m[0].length)}}if(e[i]==="{"){let f=i+1,m=1,d=f;for(;d<e.length&&m>0;){let k=e[d];k==="{"?m++:k==="}"&&m--,d++}if(m!==0){t+=e[n],n++;continue}let y=e.slice(f,d-1).trim(),x=d,E=y.match(/description\s*:\s*(['"`])([^]*?)\1/);E&&!a&&(o=E[2]);let _,b=y.match(/example\s*:\s*/);if(b){let k=b.index+b[0].length,w=Fr(y,k);w&&(_=w.value.trim())}let T=y.match(/predicate\s*\(([^)]*)\)\s*\{([^]*)\}/);if(T&&_){let k=T[1].trim(),w=T[2].trim(),j=l?`, ${l}`:"";t+=`const ${s} = Type('${o}', (${k}) => { if (!globalThis.__tjs?.validate(${k}, globalThis.__tjs?.infer(${_}))) return false; ${w} }, ${_}${j})`}else if(T){let k=T[1].trim(),w=T[2].trim(),j=l?`, undefined, ${l}`:"";t+=`const ${s} = Type('${o}', (${k}) => { ${w} }${j})`}else if(_){let k=l?`, ${l}`:"";t+=`const ${s} = Type('${o}', undefined, ${_}${k})`}else l?t+=`const ${s} = Type('${o}', ${l})`:t+=`const ${s} = Type('${o}')`;n=x;continue}else if(l){t+=`const ${s} = Type('${o}', ${l})`,n=u;continue}else if(!c){let f=e.slice(i).match(/^(['"`][^]*?['"`]|\+?\d+(?:\.\d+)?|true|false|null|\{[^]*?\}|\[[^]*?\])/);if(f){let m=f[0];t+=`const ${s} = Type('${s}', ${m})`,n=i+f[0].length;continue}}}t+=e[n],n++}return t}function Yr(e){let t="",n=0;for(;n<e.length;){let r=e.slice(n).match(/^\bFunctionPredicate\s+([A-Z_][a-zA-Z0-9_]*)\s*(?:<([^>]+)>)?\s*/);if(r){let s=r[1],i=r[2],o=n+r[0].length;if(e[o]==="{"){let a=1,c=o+1;for(;c<e.length&&a>0;)e[c]==="{"?a++:e[c]==="}"&&a--,c++;if(a===0){let l=e.slice(o+1,c-1).trim(),u=qi(l,/params\s*:\s*\{/),p=l.match(/returns\s*:\s*(.+?)(?:\n|$)/),f=l.match(/returnContract\s*:\s*['"](\w+)['"]/),m=l.match(/description\s*:\s*(['"])([^]*?)\1/),d=[];u&&d.push(`params: ${u[1]}`),p&&d.push(`returns: ${p[1].trim()}`),f&&d.push(`returnContract: '${f[1]}'`);let y=m?m[2]:s;if(i){let x=i.split(",").map(_=>{let b=_.trim().split("=").map(T=>T.trim());if(b.length===2){let T=b[1]==="any"||b[1]==="undefined"?"null":b[1];return`['${b[0]}', ${T}]`}return`'${b[0]}'`}),E=i.split(",").map(_=>_.trim().split("=")[0].trim());t+=`const ${s} = FunctionPredicate('${y}', [${x.join(", ")}], (${E.join(", ")}) => ({ ${d.join(", ")} }))`}else t+=`const ${s} = FunctionPredicate('${y}', { ${d.join(", ")} })`;n=c;continue}}if(e[o]==="("){let a=1,c=o+1;for(;c<e.length&&a>0;)e[c]==="("?a++:e[c]===")"&&a--,c++;if(a===0){let l=e.slice(o+1,c-1).trim(),u=l.indexOf(",");if(u!==-1){let p=l.slice(0,u).trim(),f=l.slice(u+1).trim();t+=`const ${s} = FunctionPredicate(${f}, ${p})`}else t+=`const ${s} = FunctionPredicate('${s}', ${l})`;n=c;continue}}}t+=e[n],n++}return t}function Xr(e){let t="",n=0;for(;n<e.length;){let r=e.slice(n).match(/^\bGeneric\s+([A-Z][a-zA-Z0-9_]*)\s*<([^>]+)>\s*\{/);if(r){let s=r[1],i=r[2],a=n+r[0].length-1+1,c=1,l=a;for(;l<e.length&&c>0;){let _=e[l];_==="{"?c++:_==="}"&&c--,l++}if(c!==0){t+=e[n],n++;continue}let u=e.slice(a,l-1).trim(),p=l,f=i.split(",").map(_=>{let b=_.trim().split("=").map(T=>T.trim());if(b.length===2){let T=b[1]==="any"||b[1]==="undefined"?"null":b[1];return`['${b[0]}', ${T}]`}return`'${b[0]}'`}),m=u,d=m.search(/\bdeclaration\s*\{/);if(d!==-1){let _=m.indexOf("{",d),b=1,T=_+1;for(;T<m.length&&b>0;)m[T]==="{"?b++:m[T]==="}"&&b--,T++;m=m.slice(0,d)+m.slice(T)}let y=m.match(/description\s*:\s*(['"`])([^]*?)\1/),x=m.match(/predicate\s*\(([^)]*)\)\s*\{([^]*)\}/),E=y?y[2]:s;if(x){let _=x[1].trim().split(",").map(j=>j.trim()),b=x[2].trim(),T=_[0]||"x",k=_.slice(1),w=k.map(j=>`check${j}`);k.forEach((j,C)=>{b=b.replace(new RegExp(`\\b${j}\\s*\\(`,"g"),`${w[C]}(`)}),t+=`const ${s} = Generic([${f.join(", ")}], (${T}, ${w.join(", ")}) => { ${b} }, '${E}')`}else t+=`const ${s} = Generic([${f.join(", ")}], () => true, '${E}')`;n=p;continue}t+=e[n],n++}return t}function Qr(e){let t="",n=0;for(;n<e.length;){let r=e.slice(n).match(/^\bUnion\s+([A-Z][a-zA-Z0-9_]*)\s+(['"`])([^]*?)\2\s*/);if(r){let s=r[1],i=r[3],o=n+r[0].length;if(e[o]==="{"){let a=o+1,c=1,l=a;for(;l<e.length&&c>0;){let m=e[l];m==="{"?c++:m==="}"&&c--,l++}if(c!==0){t+=e[n],n++;continue}let u=e.slice(a,l-1).trim(),p=l,f=qr(u);t+=`const ${s} = Union('${i}', [${f.join(", ")}])`,n=p;continue}else{let a=e.indexOf(`
@@ -167,7 +167,7 @@ function expect(actual) {
167
167
  }
168
168
  }
169
169
  `,xo=xs+`
170
- `+Ts;import{validate as Es,s as fn}from"tosijs-schema";function Ee(e){if(e.nullable)return{anyOf:[Ee({...e,nullable:!1}),{type:"null"}]};switch(e.kind){case"string":return{type:"string"};case"number":return{type:"number"};case"integer":return{type:"integer"};case"non-negative-integer":return{type:"integer",minimum:0};case"boolean":return{type:"boolean"};case"null":return{type:"null"};case"undefined":return{};case"any":return{};case"array":return e.items?{type:"array",items:Ee(e.items)}:{type:"array"};case"object":if(e.shape){let t={},n=[];for(let[r,s]of Object.entries(e.shape))t[r]=Ee(s),n.push(r);return{type:"object",properties:t,required:n,additionalProperties:!1}}return{type:"object"};case"union":return e.members?{anyOf:e.members.map(Ee)}:{};default:return{}}}function Oe(e){if(e===null)return{type:"null"};if(e===void 0)return{};switch(typeof e){case"string":return{type:"string"};case"number":return Number.isInteger(e)?{type:"integer"}:{type:"number"};case"boolean":return{type:"boolean"};case"object":{if(Array.isArray(e))return e.length===0?{type:"array"}:{type:"array",items:Oe(e[0])};let t={},n=[];for(let[r,s]of Object.entries(e))t[r]=Oe(s),n.push(r);return{type:"object",properties:t,required:n,additionalProperties:!1}}default:return{}}}function Vt(e){let t={},n=[];for(let[i,o]of Object.entries(e.params))o?.type?.kind?t[i]=Ee(o.type):o?.example!==void 0?t[i]=Oe(o.example):t[i]={},o?.required!==!1&&n.push(i),o?.example!==void 0&&(t[i].examples=[o.example]);let r={type:"object",properties:t,required:n},s;return e.returns&&(e.returns.type?.kind?s=Ee(e.returns.type):e.returns.example!==void 0&&(s=Oe(e.returns.example))),{input:r,output:s}}import{validate as Hn,filter as To,s as Kt}from"tosijs-schema";function ve(e){return e!==null&&typeof e=="object"&&"__runtimeType"in e&&e.__runtimeType===!0}function Ss(e){return e!==null&&typeof e=="object"&&"schema"in e&&typeof e.schema=="object"}function So(e){return e!==null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"}function ee(e,t,n,r){let s,i,o,a=n,c=r;if(typeof e=="string")if(s=e,typeof t=="function")i=t,a!==void 0&&(o=Kt.infer(a));else if(t===void 0&&a!==void 0)o=Kt.infer(a);else if(Ss(t))o=t;else if(So(t))o=t;else if(t!==void 0)a=t,c=a,o=Kt.infer(a);else throw new Error("Type(description) requires a predicate, schema, or example");else Ss(e),o=e,s=wo(o);let l;if(o){let p=o?.schema??o;p&&typeof p=="object"&&Array.isArray(p.examples)&&(l=p.examples)}return a===void 0&&l&&l.length>0&&(a=l[0]),{description:s,check:p=>i?i(p):o?Hn(p,o):!1,schema:o,predicate:i,example:a,examples:l,default:c,toJSONSchema(){if(o){let p=o?.schema??o;if(p&&typeof p=="object"&&"type"in p)return p}return a!==void 0?Oe(a):{description:s}},strip(p){return o?To(p,o):p},__runtimeType:!0}}function wo(e){let t=e?.schema??e;if(t&&typeof t=="object"&&"type"in t){let n=t;switch(n.type){case"string":return n.format?`string (${n.format})`:n.pattern?`string matching ${n.pattern}`:n.minLength!==void 0&&n.maxLength!==void 0?`string (${n.minLength}-${n.maxLength} chars)`:"string";case"number":case"integer":return n.minimum!==void 0&&n.maximum!==void 0?`${n.type} (${n.minimum}-${n.maximum})`:n.minimum!==void 0?`${n.type} >= ${n.minimum}`:n.maximum!==void 0?`${n.type} <= ${n.maximum}`:n.type;case"boolean":return"boolean";case"array":return"array";case"object":return"object";case"null":return"null"}}return"value"}var zt=ee("string",e=>typeof e=="string"),Gt=ee("number",e=>typeof e=="number"),Ht=ee("boolean",e=>typeof e=="boolean"),Zt=ee("integer",e=>typeof e=="number"&&Number.isInteger(e)),Yt=ee("positive integer",e=>typeof e=="number"&&Number.isInteger(e)&&e>0),Xt=ee("non-empty string",e=>typeof e=="string"&&e.length>0),Qt=ee("email address",e=>typeof e=="string"&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)),Zn=e=>{try{return new URL(e),!0}catch{return!1}},en=ee("URL",e=>typeof e=="string"&&Zn(e)),tn=ee("UUID",e=>typeof e=="string"&&/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)),Yn=e=>{let t=new Date(e);return!isNaN(t.getTime())&&e.includes("T")},Xn=e=>{if(!/^\d{4}-\d{2}-\d{2}$/.test(e))return!1;let t=new Date(e+"T00:00:00Z");return!isNaN(t.getTime())},Qn=ee("ISO 8601 timestamp",e=>typeof e=="string"&&Yn(e)),er=ee("date (YYYY-MM-DD)",e=>typeof e=="string"&&Xn(e));function nn(e){return ee(`${e.description} or null`,t=>t===null||e.check(t))}function rn(e){return ee(`${e.description} (optional)`,t=>t==null||e.check(t))}function sn(e,t,...n){if(typeof e=="string"&&Array.isArray(t)){let i=e,o=t,a=new Set(o);return{description:i,check:l=>a.has(l),toJSONSchema:()=>({enum:o}),strip:l=>l,__runtimeType:!0,values:o}}let r=[];ve(e)&&r.push(e),ve(t)&&r.push(t),r.push(...n);let s=r.map(i=>i.description).join(" | ");return ee(s,i=>r.some(o=>o.check(i)))}function on(e){return ee(`array of ${e.description}`,t=>Array.isArray(t)&&t.every(n=>e.check(n)))}function Eo(e){if(ve(e))return n=>e.check(n);if(e&&typeof e=="object"&&"schema"in e)return n=>Hn(n,e);let t=Kt.infer(e);return n=>Hn(n,t)}function Ze(e,t,n){let r=[],s=[];for(let o of e)typeof o=="string"?(r.push(o),s.push(void 0)):(r.push(o[0]),s.push(o[1]));let i=(...o)=>{let a=r.map((l,u)=>{let p=u<o.length?o[u]:s[u];return p===void 0?()=>!0:Eo(p)}),c=n;return r.forEach((l,u)=>{let p=u<o.length?o[u]:s[u],f="any";ve(p)?f=p.description:p!==void 0&&(f=typeof p=="string"?"string":JSON.stringify(p)),c=c.replace(new RegExp(`\\b${l}\\b`,"g"),f)}),ee(c,l=>t(l,...a))};return i.params=r,i.description=n,i}var an=Ze(["T","U"],(e,t,n)=>Array.isArray(e)&&e.length===2&&t(e[0])&&n(e[1]),"Pair<T, U>"),cn=Ze(["V"],(e,t)=>typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.values(e).every(t),"Record<string, V>");function ln(e,t){let n=Object.values(t),r=new Set(n),s=Object.keys(t),i={};for(let[a,c]of Object.entries(t))i[c]=a;return{description:e,check:a=>r.has(a),toJSONSchema:()=>({enum:n}),strip:a=>a,__runtimeType:!0,members:t,names:i,values:n,keys:s}}function _o(e){if(e===null)return"null";if(e===void 0)return"undefined";switch(typeof e){case"string":return"string";case"boolean":return"boolean";case"number":return Number.isInteger(e)?"integer":"number";case"object":return Array.isArray(e)?"array":"object";default:return null}}function xt(e,t,n){if(Array.isArray(t)&&n){let r=t,s=[],i=[];for(let a of r)Array.isArray(a)?(s.push(a[0]),i.push(a[1])):(s.push(a),i.push(void 0));let o=((...a)=>{let c=s.map((u,p)=>p<a.length?a[p]:i[p]),l=n(...c);return xt(e,l)});return Object.defineProperties(o,{typeParamNames:{value:s,enumerable:!0},description:{value:e,enumerable:!0},__runtimeType:{value:!0,enumerable:!0}}),o}return $o(e,t)}function $o(e,t){let n={},r,s="assertReturns";if(typeof t=="function"){let o=t.__tjs;if(o){if(o.params)for(let[a,c]of Object.entries(o.params))n[a]=c?.example??null;o.returns&&(r=o.returns?.example??null),o.safeReturn?s="checkedReturns":o.unsafe?s="assertReturns":s="returns"}}else n=t.params??{},r=t.returns,s=t.returnContract??"assertReturns";return{description:e,params:n,returns:r,returnContract:s,toJSONSchema:()=>({description:e,type:"function"}),strip:o=>o,check:o=>{if(typeof o!="function")return!1;let a=Object.keys(n).length;if(a>0){let l=o.__tjs;if(l?.params){if(Object.keys(l.params).length!==a)return!1;let p=Object.keys(n),f=Object.keys(l.params);for(let m=0;m<p.length;m++){let d=l.params[f[m]],y=n[p[m]];if(d?.type?.kind&&y!==void 0){let x=_o(y);if(x&&d.type.kind!==x&&d.type.kind!=="any")return!1}}}}return!0},__runtimeType:!0}}var jo=ws(),oe=jo.version,Tt=Symbol.for("tjs.equals");function pn(e){let[t=0,n=0,r=0]=e.split(".").map(Number);return{major:t,minor:n,patch:r}}function nr(e,t){let n=pn(e),r=pn(t);return n.major!==r.major?n.major<r.major?-1:1:n.minor!==r.minor?n.minor<r.minor?-1:1:n.patch!==r.patch?n.patch<r.patch?-1:1:0}function rr(e,t){let n=pn(e),r=pn(t);return n.major===r.major}var et=class e extends Error{path;expected;actual;callStack;constructor(t,n,r,s,i){super(t),this.name="MonadicError",this.path=n,this.expected=r,this.actual=s,this.callStack=i,Error.captureStackTrace&&Error.captureStackTrace(this,e)}};function vo(e,t,n){let r=n===null?"null":typeof n,s=V.callStacks||V.debug?ir():void 0,i=new et(`Expected ${t} for '${e}', got ${r}`,e,t,r,s);if(V.trackErrors!==!1){let o=V.maxErrors??mn;$s[Ye]=i,Ye=(Ye+1)%o,Fe<o&&Fe++,dn++}if(V.logTypeErrors&&console.error(`[TJS TypeError] ${i.message}`),V.throwTypeErrors)throw i;return i}function tr(e){return e instanceof Error&&e.name==="MonadicError"&&"path"in e}var sr={debug:!1,safety:"inputs",requireReturnTypes:!1,callStacks:!1,maxStackSize:64,trackErrors:!0,maxErrors:64},V={...sr},St=64,_s=new Array(St).fill(""),Be=0,$e=0,mn=64,$s=new Array(mn).fill(null),Ye=0,Fe=0,dn=0,tt=0;function Ao(){tt++}function Mo(){tt>0&&tt--}function Co(){return tt>0}function Ro(e){V={...V,...e}}function No(){return{...V}}function ks(e){if((V.callStacks||V.debug)&&e){let t=V.maxStackSize??St;_s[Be]=e,Be=(Be+1)%t,$e<t&&$e++}}function un(){if((V.callStacks||V.debug)&&$e>0){let e=V.maxStackSize??St;Be=(Be-1+e)%e,$e--}}function ir(){if($e===0)return[];let e=V.maxStackSize??St,t=[],n=(Be-$e+e)%e;for(let r=0;r<$e;r++)t.push(_s[(n+r)%e]);return t}function js(){if(V.trackErrors===!1||Fe===0)return[];let e=V.maxErrors??mn,t=[],n=(Ye-Fe+e)%e;for(let r=0;r<Fe;r++)t.push($s[(n+r)%e]);return t}function Po(){let e=js();return Ye=0,Fe=0,dn=0,e}function Io(){return dn}function Do(){V={...sr},Be=0,$e=0,Ye=0,Fe=0,dn=0,tt=0}function Xe(e,t){if(e!==null&&typeof e=="object"&&typeof e[Tt]=="function")return e[Tt](t);if(t!==null&&typeof t=="object"&&typeof t[Tt]=="function")return t[Tt](e);if(e!==null&&typeof e=="object"&&typeof e.Equals=="function")return e.Equals(t);if(t!==null&&typeof t=="object"&&typeof t.Equals=="function")return t.Equals(e);if((e instanceof String||e instanceof Number||e instanceof Boolean)&&(e=e.valueOf()),(t instanceof String||t instanceof Number||t instanceof Boolean)&&(t=t.valueOf()),e===t||typeof e=="number"&&typeof t=="number"&&isNaN(e)&&isNaN(t)||e==null&&t==null)return!0;if(e==null||t===null||t===void 0||typeof e!=typeof t||typeof e!="object")return!1;if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let s of e)if(!t.has(s))return!1;return!0}if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[s,i]of e)if(!t.has(s)||!Xe(i,t.get(s)))return!1;return!0}if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((s,i)=>Xe(s,t[i]));if(Array.isArray(e)!==Array.isArray(t))return!1;let n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(s=>Xe(e[s],t[s]))}function vs(e,t){return!Xe(e,t)}function As(e){return e===null?"null":typeof e}function or(e,t){return(e instanceof String||e instanceof Number||e instanceof Boolean)&&(e=e.valueOf()),(t instanceof String||t instanceof Number||t instanceof Boolean)&&(t=t.valueOf()),!!(e===t||typeof e=="number"&&typeof t=="number"&&isNaN(e)&&isNaN(t)||e==null&&t==null)}function Ms(e,t){return!or(e,t)}function _e(e){return e!==null&&typeof e=="object"&&e.$error===!0}function Se(e,t){let n={$error:!0,message:e,...t};if((V.callStacks||V.debug)&&$e>0){let r=ir(),s=t?.path?[...r,t.path]:r;n.stack=s}return n}function ar(e,t){if(e.length===0)return Se("Unknown error");if(e.length===1)return e[0];let n=e.map(s=>{if(s.path){let i=s.path.split(".");return i[i.length-1]}return"unknown"}).join(", "),r=`Multiple parameter errors in ${t||"function"}: ${n}`;return Se(r,{path:t,errors:e})}function Qe(e){if(e===null)return"null";if(e===void 0)return"undefined";if(Array.isArray(e))return"array";let t=typeof e;if(t!=="object")return t;let n=e.constructor?.name;return n&&n!=="Object"?n:"object"}function Cs(e,t){if(e==null||typeof e!="object"&&typeof e!="function")return!1;let n=e;for(;n!==null;){if(n.constructor?.name===t)return!0;n=Object.getPrototypeOf(n)}return!1}function Ue(e,t,n){if(_e(e))return e;if(typeof t=="object"&&t!==null&&"check"in t)return t.check(e)?null:Se(`Expected ${t.description} but got ${Qe(e)}`,{path:n,expected:t.description,actual:Qe(e)});let r=Qe(e);return t==="any"||t===r||t==="number"&&r==="number"||t==="integer"&&r==="number"&&Number.isInteger(e)||t==="non-negative-integer"&&r==="number"&&Number.isInteger(e)&&e>=0||t==="object"&&r==="object"?null:Se(`Expected ${t} but got ${r}`,{path:n,expected:t,actual:r})}function cr(e,t,n){for(let[r,s]of Object.entries(t.params)){let i=e[r];if(_e(i))return i;if(s.required&&i===void 0){let a=typeof s.type=="string"?s.type:s.type.description;return Se(`Missing required parameter '${r}'`,{path:n?`${n}.${r}`:r,expected:a,actual:"undefined",loc:s.loc})}if(i===void 0)continue;let o=Ue(i,s.type,n?`${n}.${r}`:r);if(o)return s.loc&&(o.loc=s.loc),o}return null}function lr(e,t){if(e.__tjs=t,e.__tjs.schema=()=>Vt(t),!(!t.polymorphic&&(t.safe||t.safeReturn||V.safety!=="none"&&!t.unsafe||t.returns&&V.safety==="all"&&!t.unsafeReturn)))return e;let r=!!t.returns,s=!!t.unsafe,i=!!t.safe,o=!!t.unsafeReturn,a=!!t.safeReturn,c=t.returns?.defaults,l=Object.entries(t.params),u=l.length,p=e.name||t.name||"anonymous",f=function(...m){if(tt>0)return e.apply(this,m);let d=i||!s&&V.safety!=="none",y=r&&(a||!o&&V.safety==="all");if(!d&&!y)return e.apply(this,m);if(m.length>0&&_e(m[0]))return m[0];if(d){let E=m.length===1&&typeof m[0]=="object"&&m[0]!==null&&!Array.isArray(m[0]),_=[];if(E){let b=m[0];for(let T=0;T<u;T++){let[k,w]=l[T],j=b[k];if(_e(j)){_.push(j);continue}if(w.required&&j===void 0){_.push(Se(`Missing required parameter '${k}'`,{path:`${p}.${k}`,expected:typeof w.type=="string"?w.type:w.type?.description||"value",actual:"undefined",loc:w.loc}));continue}if(j!==void 0){let C=Ue(j,w.type,`${p}.${k}`);C&&(w.loc&&(C.loc=w.loc),_.push(C))}}}else for(let b=0;b<u;b++){let[T,k]=l[b],w=m[b];if(_e(w)){_.push(w);continue}if(k.required&&w===void 0){_.push(Se(`Missing required parameter '${T}'`,{path:`${p}.${T}`,expected:typeof k.type=="string"?k.type:k.type?.description||"value",actual:"undefined",loc:k.loc}));continue}if(w!==void 0){let j=Ue(w,k.type,`${p}.${T}`);j&&(k.loc&&(j.loc=k.loc),_.push(j))}}if(_.length>0)return ar(_,p)}let x=V.callStacks||V.debug;x&&ks(p);try{let E=e.apply(this,m);if(y&&t.returns&&!_e(E)){let _=c&&typeof E=="object"&&E!==null?Object.assign({},c,E):E,b=Ue(_,t.returns.type,`${p}()`);if(b)return x&&un(),b}return x&&un(),E}catch(E){return x&&un(),Se(E.message||String(E),{path:p,cause:E})}};return Object.defineProperty(f,"name",{value:e.name}),f.__tjs=t,f.__tjs.schema=()=>Vt(t),f}function Rs(e){let t=new Proxy(e,{construct(n,r,s){return Reflect.construct(n,r,s)},apply(n,r,s){return Reflect.construct(n,s)}});Object.defineProperty(t,"name",{value:e.name});for(let n of Object.getOwnPropertyNames(e))n!=="length"&&n!=="name"&&n!=="prototype"&&Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n));return t}function Ns(){let e={...V},t=e.maxStackSize??St,n=new Array(t).fill(""),r=0,s=0,i=e.maxErrors??mn,o=new Array(i).fill(null),a=0,c=0,l=0,u=0;function p(v){e={...e,...v}}function f(){return{...e}}function m(v){(e.callStacks||e.debug)&&v&&(n[r]=v,r=(r+1)%t,s<t&&s++)}function d(){(e.callStacks||e.debug)&&s>0&&(r=(r-1+t)%t,s--)}function y(){if(s===0)return[];let v=[],I=(r-s+t)%t;for(let O=0;O<s;O++)v.push(n[(I+O)%t]);return v}function x(){e={...sr},r=0,s=0,a=0,c=0,l=0,u=0}function E(){u++}function _(){u>0&&u--}function b(){return u>0}let T=new Map;function k(v,I,O){T.has(v)||T.set(v,new Map),T.get(v).set(I,O)}function w(v,I){let O=typeof v,F;if(v==null)return;if(O==="string")F="String";else if(O==="number")F="Number";else if(O==="boolean")F="Boolean";else if(Array.isArray(v))F="Array";else if(O==="object")F=v.constructor?.name||"Object";else return;let H=F;for(;H;){let Ge=T.get(H);if(Ge?.has(I))return Ge.get(I);if(O==="object"&&!Array.isArray(v)){if(H=Object.getPrototypeOf(H===F?v:Object.getPrototypeOf(v))?.constructor?.name,H==="Object"||H===F)break}else break}let se=T.get("Object");if(se?.has(I))return se.get(I)}function j(v,I,O){let F=O===null?"null":typeof O,H=e.callStacks||e.debug?y():void 0,se=new et(`Expected ${I} for '${v}', got ${F}`,v,I,F,H);if(e.trackErrors!==!1&&(o[a]=se,a=(a+1)%i,c<i&&c++,l++),e.logTypeErrors&&console.error(`[TJS TypeError] ${se.message}`),e.throwTypeErrors)throw se;return se}function C(){if(e.trackErrors===!1||c===0)return[];let v=[],I=(a-c+i)%i;for(let O=0;O<c;O++)v.push(o[(I+O)%i]);return v}function $(){let v=C();return a=0,c=0,l=0,v}function R(){return l}function A(v,I){let O={$error:!0,message:v,...I};if((e.callStacks||e.debug)&&s>0){let F=I?.path?[...y(),I.path]:y();O.stack=F}return O}function P(v,I){return v==null?j(`bang.${I}`,"non-null",v):tr(v)?v:v[I]}return{version:oe,MonadicError:et,typeError:j,isMonadicError:tr,bang:P,isError:_e,error:A,composeErrors:ar,typeOf:Qe,isNativeType:Cs,checkType:Ue,validateArgs:cr,wrap:lr,wrapClass:Rs,compareVersions:nr,versionsCompatible:rr,createRuntime:Ns,configure:p,getConfig:f,pushStack:m,popStack:d,getStack:y,errors:C,clearErrors:$,getErrorCount:R,resetRuntime:x,enterUnsafe:E,exitUnsafe:_,isUnsafeMode:b,validate:Es,infer:fn.infer.bind(fn),Type:ee,isRuntimeType:ve,Union:sn,Generic:Ze,Enum:ln,FunctionPredicate:xt,Nullable:nn,Optional:rn,TArray:on,TString:zt,TNumber:Gt,TBoolean:Ht,TInteger:Zt,TPositiveInt:Yt,TNonEmptyString:Xt,TEmail:Qt,TUrl:en,TUuid:tn,TPair:an,TRecord:cn,Is:Xe,IsNot:vs,Eq:or,NotEq:Ms,TypeOf:As,tjsEquals:Tt,registerExtension:k,resolveExtension:w}}var Le={version:oe,MonadicError:et,typeError:vo,isMonadicError:tr,isError:_e,error:Se,composeErrors:ar,typeOf:Qe,isNativeType:Cs,checkType:Ue,validateArgs:cr,wrap:lr,wrapClass:Rs,compareVersions:nr,versionsCompatible:rr,configure:Ro,getConfig:No,pushStack:ks,popStack:un,getStack:ir,errors:js,clearErrors:Po,getErrorCount:Io,resetRuntime:Do,enterUnsafe:Ao,exitUnsafe:Mo,isUnsafeMode:Co,createRuntime:Ns,validate:Es,infer:fn.infer.bind(fn),Type:ee,isRuntimeType:ve,Union:sn,Generic:Ze,Enum:ln,FunctionPredicate:xt,Nullable:nn,Optional:rn,TArray:on,TString:zt,TNumber:Gt,TBoolean:Ht,TInteger:Zt,TPositiveInt:Yt,TNonEmptyString:Xt,TEmail:Qt,TUrl:en,TUuid:tn,Timestamp:Qn,LegalDate:er,TPair:an,TRecord:cn,Is:Xe,IsNot:vs,Eq:or,NotEq:Ms,TypeOf:As};function ur(){let e=globalThis;if(e.__tjs){let t=e.__tjs.version;if(typeof t!="string")return e.__tjs=Le,Le;let n=nr(oe,t);return n===0||(rr(oe,t)?n>0?(console.info(`TJS runtime: upgrading ${t} \u2192 ${oe}`),e.__tjs=Le):console.info(`TJS runtime: keeping ${t} (newer than ${oe})`):(console.warn(`TJS runtime version conflict: ${t} vs ${oe} (major version mismatch)`),n>0&&(console.warn(`Upgrading to ${oe} - check for breaking changes`),e.__tjs=Le))),e.__tjs}return e.__tjs=Le,Le}function Oo(e){return`
170
+ `+Ts;import{validate as Es,s as fn}from"tosijs-schema";function Ee(e){if(e.nullable)return{anyOf:[Ee({...e,nullable:!1}),{type:"null"}]};switch(e.kind){case"string":return{type:"string"};case"number":return{type:"number"};case"integer":return{type:"integer"};case"non-negative-integer":return{type:"integer",minimum:0};case"boolean":return{type:"boolean"};case"null":return{type:"null"};case"undefined":return{};case"any":return{};case"array":return e.items?{type:"array",items:Ee(e.items)}:{type:"array"};case"object":if(e.shape){let t={},n=[];for(let[r,s]of Object.entries(e.shape))t[r]=Ee(s),n.push(r);return{type:"object",properties:t,required:n,additionalProperties:!1}}return{type:"object"};case"union":return e.members?{anyOf:e.members.map(Ee)}:{};default:return{}}}function Oe(e){if(e===null)return{type:"null"};if(e===void 0)return{};switch(typeof e){case"string":return{type:"string"};case"number":return Number.isInteger(e)?{type:"integer"}:{type:"number"};case"boolean":return{type:"boolean"};case"object":{if(Array.isArray(e))return e.length===0?{type:"array"}:{type:"array",items:Oe(e[0])};let t={},n=[];for(let[r,s]of Object.entries(e))t[r]=Oe(s),n.push(r);return{type:"object",properties:t,required:n,additionalProperties:!1}}default:return{}}}function Vt(e){let t={},n=[];for(let[i,o]of Object.entries(e.params))o?.type?.kind?t[i]=Ee(o.type):o?.example!==void 0?t[i]=Oe(o.example):t[i]={},o?.required!==!1&&n.push(i),o?.example!==void 0&&(t[i].examples=[o.example]);let r={type:"object",properties:t,required:n},s;return e.returns&&(e.returns.type?.kind?s=Ee(e.returns.type):e.returns.example!==void 0&&(s=Oe(e.returns.example))),{input:r,output:s}}import{validate as Hn,filter as To,s as Kt}from"tosijs-schema";function ve(e){return e!==null&&typeof e=="object"&&"__runtimeType"in e&&e.__runtimeType===!0}function Ss(e){return e!==null&&typeof e=="object"&&"schema"in e&&typeof e.schema=="object"}function So(e){return e!==null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"}function ee(e,t,n,r){let s,i,o,a=n,c=r;if(typeof e=="string")if(s=e,typeof t=="function")i=t,a!==void 0&&(o=Kt.infer(a));else if(t===void 0&&a!==void 0)o=Kt.infer(a);else if(Ss(t))o=t;else if(So(t))o=t;else if(t!==void 0)a=t,c=a,o=Kt.infer(a);else throw new Error("Type(description) requires a predicate, schema, or example");else Ss(e),o=e,s=wo(o);let l;if(o){let p=o?.schema??o;p&&typeof p=="object"&&Array.isArray(p.examples)&&(l=p.examples)}return a===void 0&&l&&l.length>0&&(a=l[0]),{description:s,check:p=>i?i(p):o?Hn(p,o):!1,schema:o,predicate:i,example:a,examples:l,default:c,toJSONSchema(){if(o){let p=o?.schema??o;if(p&&typeof p=="object"&&"type"in p)return p}return a!==void 0?Oe(a):{description:s}},strip(p){return o?To(p,o):p},__runtimeType:!0}}function wo(e){let t=e?.schema??e;if(t&&typeof t=="object"&&"type"in t){let n=t;switch(n.type){case"string":return n.format?`string (${n.format})`:n.pattern?`string matching ${n.pattern}`:n.minLength!==void 0&&n.maxLength!==void 0?`string (${n.minLength}-${n.maxLength} chars)`:"string";case"number":case"integer":return n.minimum!==void 0&&n.maximum!==void 0?`${n.type} (${n.minimum}-${n.maximum})`:n.minimum!==void 0?`${n.type} >= ${n.minimum}`:n.maximum!==void 0?`${n.type} <= ${n.maximum}`:n.type;case"boolean":return"boolean";case"array":return"array";case"object":return"object";case"null":return"null"}}return"value"}var zt=ee("string",e=>typeof e=="string"?!0:`expected string, got ${e===null?"null":typeof e}`),Gt=ee("number",e=>typeof e=="number"?!0:`expected number, got ${e===null?"null":typeof e}`),Ht=ee("boolean",e=>typeof e=="boolean"?!0:`expected boolean, got ${e===null?"null":typeof e}`),Zt=ee("integer",e=>typeof e!="number"?`expected integer, got ${e===null?"null":typeof e}`:Number.isInteger(e)?!0:`${e} is not an integer`),Yt=ee("positive integer",e=>typeof e!="number"?`expected positive integer, got ${e===null?"null":typeof e}`:Number.isInteger(e)?e<=0?`${e} is not positive`:!0:`${e} is not an integer`),Xt=ee("non-empty string",e=>typeof e!="string"?`expected string, got ${e===null?"null":typeof e}`:e.length===0?"string is empty":!0),Qt=ee("email address",e=>typeof e!="string"?`expected string, got ${e===null?"null":typeof e}`:/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)?!0:`"${e}" is not a valid email`),Zn=e=>{try{return new URL(e),!0}catch{return!1}},en=ee("URL",e=>typeof e!="string"?`expected string, got ${e===null?"null":typeof e}`:Zn(e)?!0:`"${e}" is not a valid URL`),tn=ee("UUID",e=>typeof e!="string"?`expected string, got ${e===null?"null":typeof e}`:/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)?!0:`"${e}" is not a valid UUID`),Yn=e=>{let t=new Date(e);return!isNaN(t.getTime())&&e.includes("T")},Xn=e=>{if(!/^\d{4}-\d{2}-\d{2}$/.test(e))return!1;let t=new Date(e+"T00:00:00Z");return!isNaN(t.getTime())},Qn=ee("ISO 8601 timestamp",e=>typeof e=="string"&&Yn(e)),er=ee("date (YYYY-MM-DD)",e=>typeof e=="string"&&Xn(e));function nn(e){return ee(`${e.description} or null`,t=>t===null||e.check(t)===!0)}function rn(e){return ee(`${e.description} (optional)`,t=>t==null||e.check(t)===!0)}function sn(e,t,...n){if(typeof e=="string"&&Array.isArray(t)){let i=e,o=t,a=new Set(o);return{description:i,check:l=>a.has(l),toJSONSchema:()=>({enum:o}),strip:l=>l,__runtimeType:!0,values:o}}let r=[];ve(e)&&r.push(e),ve(t)&&r.push(t),r.push(...n);let s=r.map(i=>i.description).join(" | ");return ee(s,i=>r.some(o=>o.check(i)===!0))}function on(e){return ee(`array of ${e.description}`,t=>Array.isArray(t)&&t.every(n=>e.check(n)===!0))}function Eo(e){if(ve(e))return n=>e.check(n)===!0;if(e&&typeof e=="object"&&"schema"in e)return n=>Hn(n,e);let t=Kt.infer(e);return n=>Hn(n,t)}function Ze(e,t,n){let r=[],s=[];for(let o of e)typeof o=="string"?(r.push(o),s.push(void 0)):(r.push(o[0]),s.push(o[1]));let i=(...o)=>{let a=r.map((l,u)=>{let p=u<o.length?o[u]:s[u];return p===void 0?()=>!0:Eo(p)}),c=n;return r.forEach((l,u)=>{let p=u<o.length?o[u]:s[u],f="any";ve(p)?f=p.description:p!==void 0&&(f=typeof p=="string"?"string":JSON.stringify(p)),c=c.replace(new RegExp(`\\b${l}\\b`,"g"),f)}),ee(c,l=>t(l,...a))};return i.params=r,i.description=n,i}var an=Ze(["T","U"],(e,t,n)=>Array.isArray(e)&&e.length===2&&t(e[0])&&n(e[1]),"Pair<T, U>"),cn=Ze(["V"],(e,t)=>typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.values(e).every(t),"Record<string, V>");function ln(e,t){let n=Object.values(t),r=new Set(n),s=Object.keys(t),i={};for(let[a,c]of Object.entries(t))i[c]=a;return{description:e,check:a=>r.has(a),toJSONSchema:()=>({enum:n}),strip:a=>a,__runtimeType:!0,members:t,names:i,values:n,keys:s}}function _o(e){if(e===null)return"null";if(e===void 0)return"undefined";switch(typeof e){case"string":return"string";case"boolean":return"boolean";case"number":return Number.isInteger(e)?"integer":"number";case"object":return Array.isArray(e)?"array":"object";default:return null}}function xt(e,t,n){if(Array.isArray(t)&&n){let r=t,s=[],i=[];for(let a of r)Array.isArray(a)?(s.push(a[0]),i.push(a[1])):(s.push(a),i.push(void 0));let o=((...a)=>{let c=s.map((u,p)=>p<a.length?a[p]:i[p]),l=n(...c);return xt(e,l)});return Object.defineProperties(o,{typeParamNames:{value:s,enumerable:!0},description:{value:e,enumerable:!0},__runtimeType:{value:!0,enumerable:!0}}),o}return $o(e,t)}function $o(e,t){let n={},r,s="assertReturns";if(typeof t=="function"){let o=t.__tjs;if(o){if(o.params)for(let[a,c]of Object.entries(o.params))n[a]=c?.example??null;o.returns&&(r=o.returns?.example??null),o.safeReturn?s="checkedReturns":o.unsafe?s="assertReturns":s="returns"}}else n=t.params??{},r=t.returns,s=t.returnContract??"assertReturns";return{description:e,params:n,returns:r,returnContract:s,toJSONSchema:()=>({description:e,type:"function"}),strip:o=>o,check:o=>{if(typeof o!="function")return`expected function, got ${o===null?"null":typeof o}`;let a=Object.keys(n).length;if(a>0){let l=o.__tjs;if(l?.params){let u=Object.keys(l.params).length;if(u!==a)return`expected ${a} params, got ${u}`;let p=Object.keys(n),f=Object.keys(l.params);for(let m=0;m<p.length;m++){let d=l.params[f[m]],y=n[p[m]];if(d?.type?.kind&&y!==void 0){let x=_o(y);if(x&&d.type.kind!==x&&d.type.kind!=="any")return`param '${p[m]}' expected ${x}, got ${d.type.kind}`}}}}return!0},__runtimeType:!0}}var jo=ws(),oe=jo.version,Tt=Symbol.for("tjs.equals");function pn(e){let[t=0,n=0,r=0]=e.split(".").map(Number);return{major:t,minor:n,patch:r}}function nr(e,t){let n=pn(e),r=pn(t);return n.major!==r.major?n.major<r.major?-1:1:n.minor!==r.minor?n.minor<r.minor?-1:1:n.patch!==r.patch?n.patch<r.patch?-1:1:0}function rr(e,t){let n=pn(e),r=pn(t);return n.major===r.major}var et=class e extends Error{path;expected;actual;callStack;reason;constructor(t,n,r,s,i,o){super(t),this.name="MonadicError",this.path=n,this.expected=r,this.actual=s,this.callStack=i,this.reason=o,Error.captureStackTrace&&Error.captureStackTrace(this,e)}};function vo(e,t,n,r){let s=n===null?"null":typeof n,i=V.callStacks||V.debug?ir():void 0,o=r?`Expected ${t} for '${e}': ${r}`:`Expected ${t} for '${e}', got ${s}`,a=new et(o,e,t,s,i,r);if(V.trackErrors!==!1){let c=V.maxErrors??mn;$s[Ye]=a,Ye=(Ye+1)%c,Fe<c&&Fe++,dn++}if(V.logTypeErrors&&console.error(`[TJS TypeError] ${a.message}`),V.throwTypeErrors)throw a;return a}function tr(e){return e instanceof Error&&e.name==="MonadicError"&&"path"in e}var sr={debug:!1,safety:"inputs",requireReturnTypes:!1,callStacks:!1,maxStackSize:64,trackErrors:!0,maxErrors:64},V={...sr},St=64,_s=new Array(St).fill(""),Be=0,$e=0,mn=64,$s=new Array(mn).fill(null),Ye=0,Fe=0,dn=0,tt=0;function Ao(){tt++}function Mo(){tt>0&&tt--}function Co(){return tt>0}function Ro(e){V={...V,...e}}function No(){return{...V}}function ks(e){if((V.callStacks||V.debug)&&e){let t=V.maxStackSize??St;_s[Be]=e,Be=(Be+1)%t,$e<t&&$e++}}function un(){if((V.callStacks||V.debug)&&$e>0){let e=V.maxStackSize??St;Be=(Be-1+e)%e,$e--}}function ir(){if($e===0)return[];let e=V.maxStackSize??St,t=[],n=(Be-$e+e)%e;for(let r=0;r<$e;r++)t.push(_s[(n+r)%e]);return t}function js(){if(V.trackErrors===!1||Fe===0)return[];let e=V.maxErrors??mn,t=[],n=(Ye-Fe+e)%e;for(let r=0;r<Fe;r++)t.push($s[(n+r)%e]);return t}function Po(){let e=js();return Ye=0,Fe=0,dn=0,e}function Io(){return dn}function Do(){V={...sr},Be=0,$e=0,Ye=0,Fe=0,dn=0,tt=0}function Xe(e,t){if(e!==null&&typeof e=="object"&&typeof e[Tt]=="function")return e[Tt](t);if(t!==null&&typeof t=="object"&&typeof t[Tt]=="function")return t[Tt](e);if(e!==null&&typeof e=="object"&&typeof e.Equals=="function")return e.Equals(t);if(t!==null&&typeof t=="object"&&typeof t.Equals=="function")return t.Equals(e);if((e instanceof String||e instanceof Number||e instanceof Boolean)&&(e=e.valueOf()),(t instanceof String||t instanceof Number||t instanceof Boolean)&&(t=t.valueOf()),e===t||typeof e=="number"&&typeof t=="number"&&isNaN(e)&&isNaN(t)||e==null&&t==null)return!0;if(e==null||t===null||t===void 0||typeof e!=typeof t||typeof e!="object")return!1;if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let s of e)if(!t.has(s))return!1;return!0}if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[s,i]of e)if(!t.has(s)||!Xe(i,t.get(s)))return!1;return!0}if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((s,i)=>Xe(s,t[i]));if(Array.isArray(e)!==Array.isArray(t))return!1;let n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(s=>Xe(e[s],t[s]))}function vs(e,t){return!Xe(e,t)}function As(e){return e===null?"null":typeof e}function or(e,t){return(e instanceof String||e instanceof Number||e instanceof Boolean)&&(e=e.valueOf()),(t instanceof String||t instanceof Number||t instanceof Boolean)&&(t=t.valueOf()),!!(e===t||typeof e=="number"&&typeof t=="number"&&isNaN(e)&&isNaN(t)||e==null&&t==null)}function Ms(e,t){return!or(e,t)}function _e(e){return e!==null&&typeof e=="object"&&e.$error===!0}function Se(e,t){let n={$error:!0,message:e,...t};if((V.callStacks||V.debug)&&$e>0){let r=ir(),s=t?.path?[...r,t.path]:r;n.stack=s}return n}function ar(e,t){if(e.length===0)return Se("Unknown error");if(e.length===1)return e[0];let n=e.map(s=>{if(s.path){let i=s.path.split(".");return i[i.length-1]}return"unknown"}).join(", "),r=`Multiple parameter errors in ${t||"function"}: ${n}`;return Se(r,{path:t,errors:e})}function Qe(e){if(e===null)return"null";if(e===void 0)return"undefined";if(Array.isArray(e))return"array";let t=typeof e;if(t!=="object")return t;let n=e.constructor?.name;return n&&n!=="Object"?n:"object"}function Cs(e,t){if(e==null||typeof e!="object"&&typeof e!="function")return!1;let n=e;for(;n!==null;){if(n.constructor?.name===t)return!0;n=Object.getPrototypeOf(n)}return!1}function Ue(e,t,n){if(_e(e))return e;if(typeof t=="object"&&t!==null&&"check"in t){let s=t.check(e);if(s===!0)return null;let i=typeof s=="string"?s:void 0,o=i?`Expected ${t.description} for '${n}': ${i}`:`Expected ${t.description} but got ${Qe(e)}`;return Se(o,{path:n,expected:t.description,actual:Qe(e),reason:i})}let r=Qe(e);return t==="any"||t===r||t==="number"&&r==="number"||t==="integer"&&r==="number"&&Number.isInteger(e)||t==="non-negative-integer"&&r==="number"&&Number.isInteger(e)&&e>=0||t==="object"&&r==="object"?null:Se(`Expected ${t} but got ${r}`,{path:n,expected:t,actual:r})}function cr(e,t,n){for(let[r,s]of Object.entries(t.params)){let i=e[r];if(_e(i))return i;if(s.required&&i===void 0){let a=typeof s.type=="string"?s.type:s.type.description;return Se(`Missing required parameter '${r}'`,{path:n?`${n}.${r}`:r,expected:a,actual:"undefined",loc:s.loc})}if(i===void 0)continue;let o=Ue(i,s.type,n?`${n}.${r}`:r);if(o)return s.loc&&(o.loc=s.loc),o}return null}function lr(e,t){if(e.__tjs=t,e.__tjs.schema=()=>Vt(t),!(!t.polymorphic&&(t.safe||t.safeReturn||V.safety!=="none"&&!t.unsafe||t.returns&&V.safety==="all"&&!t.unsafeReturn)))return e;let r=!!t.returns,s=!!t.unsafe,i=!!t.safe,o=!!t.unsafeReturn,a=!!t.safeReturn,c=t.returns?.defaults,l=Object.entries(t.params),u=l.length,p=e.name||t.name||"anonymous",f=function(...m){if(tt>0)return e.apply(this,m);let d=i||!s&&V.safety!=="none",y=r&&(a||!o&&V.safety==="all");if(!d&&!y)return e.apply(this,m);if(m.length>0&&_e(m[0]))return m[0];if(d){let E=m.length===1&&typeof m[0]=="object"&&m[0]!==null&&!Array.isArray(m[0]),_=[];if(E){let b=m[0];for(let T=0;T<u;T++){let[k,w]=l[T],j=b[k];if(_e(j)){_.push(j);continue}if(w.required&&j===void 0){_.push(Se(`Missing required parameter '${k}'`,{path:`${p}.${k}`,expected:typeof w.type=="string"?w.type:w.type?.description||"value",actual:"undefined",loc:w.loc}));continue}if(j!==void 0){let C=Ue(j,w.type,`${p}.${k}`);C&&(w.loc&&(C.loc=w.loc),_.push(C))}}}else for(let b=0;b<u;b++){let[T,k]=l[b],w=m[b];if(_e(w)){_.push(w);continue}if(k.required&&w===void 0){_.push(Se(`Missing required parameter '${T}'`,{path:`${p}.${T}`,expected:typeof k.type=="string"?k.type:k.type?.description||"value",actual:"undefined",loc:k.loc}));continue}if(w!==void 0){let j=Ue(w,k.type,`${p}.${T}`);j&&(k.loc&&(j.loc=k.loc),_.push(j))}}if(_.length>0)return ar(_,p)}let x=V.callStacks||V.debug;x&&ks(p);try{let E=e.apply(this,m);if(y&&t.returns&&!_e(E)){let _=c&&typeof E=="object"&&E!==null?Object.assign({},c,E):E,b=Ue(_,t.returns.type,`${p}()`);if(b)return x&&un(),b}return x&&un(),E}catch(E){return x&&un(),Se(E.message||String(E),{path:p,cause:E})}};return Object.defineProperty(f,"name",{value:e.name}),f.__tjs=t,f.__tjs.schema=()=>Vt(t),f}function Rs(e){let t=new Proxy(e,{construct(n,r,s){return Reflect.construct(n,r,s)},apply(n,r,s){return Reflect.construct(n,s)}});Object.defineProperty(t,"name",{value:e.name});for(let n of Object.getOwnPropertyNames(e))n!=="length"&&n!=="name"&&n!=="prototype"&&Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n));return t}function Ns(){let e={...V},t=e.maxStackSize??St,n=new Array(t).fill(""),r=0,s=0,i=e.maxErrors??mn,o=new Array(i).fill(null),a=0,c=0,l=0,u=0;function p(v){e={...e,...v}}function f(){return{...e}}function m(v){(e.callStacks||e.debug)&&v&&(n[r]=v,r=(r+1)%t,s<t&&s++)}function d(){(e.callStacks||e.debug)&&s>0&&(r=(r-1+t)%t,s--)}function y(){if(s===0)return[];let v=[],I=(r-s+t)%t;for(let O=0;O<s;O++)v.push(n[(I+O)%t]);return v}function x(){e={...sr},r=0,s=0,a=0,c=0,l=0,u=0}function E(){u++}function _(){u>0&&u--}function b(){return u>0}let T=new Map;function k(v,I,O){T.has(v)||T.set(v,new Map),T.get(v).set(I,O)}function w(v,I){let O=typeof v,F;if(v==null)return;if(O==="string")F="String";else if(O==="number")F="Number";else if(O==="boolean")F="Boolean";else if(Array.isArray(v))F="Array";else if(O==="object")F=v.constructor?.name||"Object";else return;let H=F;for(;H;){let Ge=T.get(H);if(Ge?.has(I))return Ge.get(I);if(O==="object"&&!Array.isArray(v)){if(H=Object.getPrototypeOf(H===F?v:Object.getPrototypeOf(v))?.constructor?.name,H==="Object"||H===F)break}else break}let se=T.get("Object");if(se?.has(I))return se.get(I)}function j(v,I,O){let F=O===null?"null":typeof O,H=e.callStacks||e.debug?y():void 0,se=new et(`Expected ${I} for '${v}', got ${F}`,v,I,F,H);if(e.trackErrors!==!1&&(o[a]=se,a=(a+1)%i,c<i&&c++,l++),e.logTypeErrors&&console.error(`[TJS TypeError] ${se.message}`),e.throwTypeErrors)throw se;return se}function C(){if(e.trackErrors===!1||c===0)return[];let v=[],I=(a-c+i)%i;for(let O=0;O<c;O++)v.push(o[(I+O)%i]);return v}function $(){let v=C();return a=0,c=0,l=0,v}function R(){return l}function A(v,I){let O={$error:!0,message:v,...I};if((e.callStacks||e.debug)&&s>0){let F=I?.path?[...y(),I.path]:y();O.stack=F}return O}function P(v,I){return v==null?j(`bang.${I}`,"non-null",v):tr(v)?v:v[I]}return{version:oe,MonadicError:et,typeError:j,isMonadicError:tr,bang:P,isError:_e,error:A,composeErrors:ar,typeOf:Qe,isNativeType:Cs,checkType:Ue,validateArgs:cr,wrap:lr,wrapClass:Rs,compareVersions:nr,versionsCompatible:rr,createRuntime:Ns,configure:p,getConfig:f,pushStack:m,popStack:d,getStack:y,errors:C,clearErrors:$,getErrorCount:R,resetRuntime:x,enterUnsafe:E,exitUnsafe:_,isUnsafeMode:b,validate:Es,infer:fn.infer.bind(fn),Type:ee,isRuntimeType:ve,Union:sn,Generic:Ze,Enum:ln,FunctionPredicate:xt,Nullable:nn,Optional:rn,TArray:on,TString:zt,TNumber:Gt,TBoolean:Ht,TInteger:Zt,TPositiveInt:Yt,TNonEmptyString:Xt,TEmail:Qt,TUrl:en,TUuid:tn,TPair:an,TRecord:cn,Is:Xe,IsNot:vs,Eq:or,NotEq:Ms,TypeOf:As,tjsEquals:Tt,registerExtension:k,resolveExtension:w}}var Le={version:oe,MonadicError:et,typeError:vo,isMonadicError:tr,isError:_e,error:Se,composeErrors:ar,typeOf:Qe,isNativeType:Cs,checkType:Ue,validateArgs:cr,wrap:lr,wrapClass:Rs,compareVersions:nr,versionsCompatible:rr,configure:Ro,getConfig:No,pushStack:ks,popStack:un,getStack:ir,errors:js,clearErrors:Po,getErrorCount:Io,resetRuntime:Do,enterUnsafe:Ao,exitUnsafe:Mo,isUnsafeMode:Co,createRuntime:Ns,validate:Es,infer:fn.infer.bind(fn),Type:ee,isRuntimeType:ve,Union:sn,Generic:Ze,Enum:ln,FunctionPredicate:xt,Nullable:nn,Optional:rn,TArray:on,TString:zt,TNumber:Gt,TBoolean:Ht,TInteger:Zt,TPositiveInt:Yt,TNonEmptyString:Xt,TEmail:Qt,TUrl:en,TUuid:tn,Timestamp:Qn,LegalDate:er,TPair:an,TRecord:cn,Is:Xe,IsNot:vs,Eq:or,NotEq:Ms,TypeOf:As};function ur(){let e=globalThis;if(e.__tjs){let t=e.__tjs.version;if(typeof t!="string")return e.__tjs=Le,Le;let n=nr(oe,t);return n===0||(rr(oe,t)?n>0?(console.info(`TJS runtime: upgrading ${t} \u2192 ${oe}`),e.__tjs=Le):console.info(`TJS runtime: keeping ${t} (newer than ${oe})`):(console.warn(`TJS runtime version conflict: ${t} vs ${oe} (major version mismatch)`),n>0&&(console.warn(`Upgrading to ${oe} - check for breaking changes`),e.__tjs=Le))),e.__tjs}return e.__tjs=Le,Le}function Oo(e){return`
171
171
  // TJS runtime wrapper (skips unsafe functions)
172
172
  if (typeof ${e}.__tjs === 'object' && !${e}.__tjs.unsafe && typeof globalThis.__tjs?.wrap === 'function') {
173
173
  ${e} = globalThis.__tjs.wrap(${e}, ${e}.__tjs)
@@ -339,7 +339,7 @@ ${Un}`}),!Ir&&!Dr){let ue=`${He.file}:${He.line}`,fe=la(K,Pe,ue);fe&&L.body&&L.b
339
339
  ${fe.preamble}
340
340
  `}),fe.suffix&&T.push({position:L.body.end-1,text:`
341
341
  ${fe.suffix}
342
- `}))}}k.sort((L,K)=>K.start-L.start);let w=_.source;for(let{start:L,end:K}of k)w=w.slice(0,L)+w.slice(K);for(let L of T){let K=0;for(let J of k)J.start<L.position&&(K+=J.end-J.start);L.position-=K}T.sort((L,K)=>K.position-L.position);for(let{position:L,text:K}of T)w=w.slice(0,L)+K+w.slice(L);let j=w.includes("__tjs.typeError("),C=w.includes("__tjs.pushStack("),$=w.includes("Is("),R=w.includes("IsNot("),A=w.includes("Eq("),P=w.includes("NotEq("),v=w.includes("TypeOf("),I=/\bType\(/.test(w),O=/\bGeneric\(/.test(w),F=/\bFunctionPredicate\(/.test(w),H=/\bEnum\(/.test(w),se=/\bUnion\(/.test(w),Ge=w.includes("__tjs.bang("),Bn=_.tjsModes.tjsSafeEval;if(j||C||$||R||A||P||v||I||O||F||H||se||Ge||Bn){let L=[];j&&L.push("class MonadicError extends Error{constructor(m,p,e,a,c){super(m);this.name='MonadicError';this.path=p;this.expected=e;this.actual=a;this.callStack=c}}",`function typeError(p,e,v){const a=v===null?'null':typeof v;const err=new MonadicError('Expected '+e+" for '"+p+"', got "+a,p,e,a);const c=globalThis.__tjs?.getConfig?.();if(c?.logTypeErrors)console.error('[TJS TypeError] '+err.message);if(c?.throwTypeErrors)throw err;return err}`,"function isMonadicError(v){return v instanceof Error&&v.name==='MonadicError'&&'path' in v}"),C&&L.push("const __stack=[];function pushStack(n){__stack.push(n)}function popStack(){__stack.pop()}function getStack(){return[...__stack]}"),A&&L.push("function Eq(a,b){if(a instanceof String||a instanceof Number||a instanceof Boolean)a=a.valueOf();if(b instanceof String||b instanceof Number||b instanceof Boolean)b=b.valueOf();if(a===b)return true;if(typeof a==='number'&&typeof b==='number'&&isNaN(a)&&isNaN(b))return true;if((a===null||a===undefined)&&(b===null||b===undefined))return true;return false}"),P&&L.push("function NotEq(a,b){return!Eq(a,b)}"),v&&L.push("function TypeOf(v){return v===null?'null':typeof v}"),$&&L.push("const tjsEquals=Symbol.for('tjs.equals');function Is(a,b){if(a!=null&&typeof a==='object'&&typeof a[tjsEquals]==='function')return a[tjsEquals](b);if(b!=null&&typeof b==='object'&&typeof b[tjsEquals]==='function')return b[tjsEquals](a);if(a!=null&&typeof a==='object'&&typeof a.Equals==='function')return a.Equals(b);if(b!=null&&typeof b==='object'&&typeof b.Equals==='function')return b.Equals(a);if(a instanceof String||a instanceof Number||a instanceof Boolean)a=a.valueOf();if(b instanceof String||b instanceof Number||b instanceof Boolean)b=b.valueOf();if(a===b)return true;if(typeof a==='number'&&typeof b==='number'&&isNaN(a)&&isNaN(b))return true;if((a==null)&&(b==null))return true;if(a==null||b==null)return false;if(typeof a!==typeof b)return false;if(typeof a!=='object')return false;if(a instanceof Set&&b instanceof Set){if(a.size!==b.size)return false;for(const v of a)if(!b.has(v))return false;return true}if(a instanceof Map&&b instanceof Map){if(a.size!==b.size)return false;for(const[k,v]of a)if(!b.has(k)||!Is(v,b.get(k)))return false;return true}if(a instanceof Date&&b instanceof Date)return a.getTime()===b.getTime();if(a instanceof RegExp&&b instanceof RegExp)return a.toString()===b.toString();if(Array.isArray(a)&&Array.isArray(b)){if(a.length!==b.length)return false;return a.every((v,i)=>Is(v,b[i]))}if(Array.isArray(a)!==Array.isArray(b))return false;const ka=Object.keys(a),kb=Object.keys(b);if(ka.length!==kb.length)return false;return ka.every(k=>Is(a[k],b[k]))}"),R&&L.push("function IsNot(a,b){return!Is(a,b)}"),I&&L.push("function Type(d,p,e){const t={description:d,__runtimeType:true};if(typeof p==='function'){t.check=p;t.default=e??null}else{const ex=e??p;t.default=ex;t.check=v=>{if(ex===null)return true;return typeof v===typeof ex}}return t}"),O&&L.push("function Generic(tp,pred,d){const f=(...args)=>{const t={description:d||'generic',__runtimeType:true,check:v=>pred(v,...args)};return t};f.__runtimeType=true;f.description=d;return f}"),F&&L.push("function FunctionPredicate(n,s,b){if(Array.isArray(s)&&b){const f=(...a)=>FunctionPredicate(n,b(...a));f.typeParamNames=s.map(p=>Array.isArray(p)?p[0]:p);f.description=n;f.__runtimeType=true;return f}const spec=typeof s==='function'?{}:s||{};return{description:n,params:spec.params||{},returns:spec.returns,returnContract:spec.returnContract||'assertReturns',check:v=>typeof v==='function',__runtimeType:true}}"),H&&L.push("function Enum(d,m){const vals=typeof m==='object'?Object.values(m):[];return{description:d,check:v=>vals.includes(v),values:vals,__runtimeType:true}}"),se&&L.push("function Union(d,...v){const vals=v.flat();return{description:d,check:x=>vals.includes(x),values:vals,__runtimeType:true}}"),Ge&&(j||L.push("class MonadicError extends Error{constructor(m,p,e,a,c){super(m);this.name='MonadicError';this.path=p;this.expected=e;this.actual=a;this.callStack=c}}",`function typeError(p,e,v){const a=v===null?'null':typeof v;const err=new MonadicError('Expected '+e+" for '"+p+"', got "+a,p,e,a);const c=globalThis.__tjs?.getConfig?.();if(c?.logTypeErrors)console.error('[TJS TypeError] '+err.message);if(c?.throwTypeErrors)throw err;return err}`,"function isMonadicError(v){return v instanceof Error&&v.name==='MonadicError'&&'path' in v}"),L.push("function bang(o,p){if(o===null||o===undefined)return typeError('bang.'+p,'non-null',o);if(isMonadicError(o))return o;return o[p]}"));let K=L.length>0?L.join(`;
342
+ `}))}}k.sort((L,K)=>K.start-L.start);let w=_.source;for(let{start:L,end:K}of k)w=w.slice(0,L)+w.slice(K);for(let L of T){let K=0;for(let J of k)J.start<L.position&&(K+=J.end-J.start);L.position-=K}T.sort((L,K)=>K.position-L.position);for(let{position:L,text:K}of T)w=w.slice(0,L)+K+w.slice(L);let j=w.includes("__tjs.typeError("),C=w.includes("__tjs.pushStack("),$=w.includes("Is("),R=w.includes("IsNot("),A=w.includes("Eq("),P=w.includes("NotEq("),v=w.includes("TypeOf("),I=/\bType\(/.test(w),O=/\bGeneric\(/.test(w),F=/\bFunctionPredicate\(/.test(w),H=/\bEnum\(/.test(w),se=/\bUnion\(/.test(w),Ge=w.includes("__tjs.bang("),Bn=_.tjsModes.tjsSafeEval;if(j||C||$||R||A||P||v||I||O||F||H||se||Ge||Bn){let L=[];j&&L.push("class MonadicError extends Error{constructor(m,p,e,a,c,r){super(m);this.name='MonadicError';this.path=p;this.expected=e;this.actual=a;this.callStack=c;this.reason=r}}",`function typeError(p,e,v,r){const a=v===null?'null':typeof v;const m=r?'Expected '+e+" for '"+p+"': "+r:'Expected '+e+" for '"+p+"', got "+a;const err=new MonadicError(m,p,e,a,undefined,r);const c=globalThis.__tjs?.getConfig?.();if(c?.logTypeErrors)console.error('[TJS TypeError] '+err.message);if(c?.throwTypeErrors)throw err;return err}`,"function isMonadicError(v){return v instanceof Error&&v.name==='MonadicError'&&'path' in v}"),C&&L.push("const __stack=[];function pushStack(n){__stack.push(n)}function popStack(){__stack.pop()}function getStack(){return[...__stack]}"),A&&L.push("function Eq(a,b){if(a instanceof String||a instanceof Number||a instanceof Boolean)a=a.valueOf();if(b instanceof String||b instanceof Number||b instanceof Boolean)b=b.valueOf();if(a===b)return true;if(typeof a==='number'&&typeof b==='number'&&isNaN(a)&&isNaN(b))return true;if((a===null||a===undefined)&&(b===null||b===undefined))return true;return false}"),P&&L.push("function NotEq(a,b){return!Eq(a,b)}"),v&&L.push("function TypeOf(v){return v===null?'null':typeof v}"),$&&L.push("const tjsEquals=Symbol.for('tjs.equals');function Is(a,b){if(a!=null&&typeof a==='object'&&typeof a[tjsEquals]==='function')return a[tjsEquals](b);if(b!=null&&typeof b==='object'&&typeof b[tjsEquals]==='function')return b[tjsEquals](a);if(a!=null&&typeof a==='object'&&typeof a.Equals==='function')return a.Equals(b);if(b!=null&&typeof b==='object'&&typeof b.Equals==='function')return b.Equals(a);if(a instanceof String||a instanceof Number||a instanceof Boolean)a=a.valueOf();if(b instanceof String||b instanceof Number||b instanceof Boolean)b=b.valueOf();if(a===b)return true;if(typeof a==='number'&&typeof b==='number'&&isNaN(a)&&isNaN(b))return true;if((a==null)&&(b==null))return true;if(a==null||b==null)return false;if(typeof a!==typeof b)return false;if(typeof a!=='object')return false;if(a instanceof Set&&b instanceof Set){if(a.size!==b.size)return false;for(const v of a)if(!b.has(v))return false;return true}if(a instanceof Map&&b instanceof Map){if(a.size!==b.size)return false;for(const[k,v]of a)if(!b.has(k)||!Is(v,b.get(k)))return false;return true}if(a instanceof Date&&b instanceof Date)return a.getTime()===b.getTime();if(a instanceof RegExp&&b instanceof RegExp)return a.toString()===b.toString();if(Array.isArray(a)&&Array.isArray(b)){if(a.length!==b.length)return false;return a.every((v,i)=>Is(v,b[i]))}if(Array.isArray(a)!==Array.isArray(b))return false;const ka=Object.keys(a),kb=Object.keys(b);if(ka.length!==kb.length)return false;return ka.every(k=>Is(a[k],b[k]))}"),R&&L.push("function IsNot(a,b){return!Is(a,b)}"),I&&L.push("function Type(d,p,e){const t={description:d,__runtimeType:true};if(typeof p==='function'){t.check=p;t.default=e??null}else{const ex=e??p;t.default=ex;t.check=v=>{if(ex===null)return true;return typeof v===typeof ex}}return t}"),O&&L.push("function Generic(tp,pred,d){const f=(...args)=>{const t={description:d||'generic',__runtimeType:true,check:v=>pred(v,...args)};return t};f.__runtimeType=true;f.description=d;return f}"),F&&L.push("function FunctionPredicate(n,s,b){if(Array.isArray(s)&&b){const f=(...a)=>FunctionPredicate(n,b(...a));f.typeParamNames=s.map(p=>Array.isArray(p)?p[0]:p);f.description=n;f.__runtimeType=true;return f}const spec=typeof s==='function'?{}:s||{};return{description:n,params:spec.params||{},returns:spec.returns,returnContract:spec.returnContract||'assertReturns',check:v=>typeof v==='function',__runtimeType:true}}"),H&&L.push("function Enum(d,m){const vals=typeof m==='object'?Object.values(m):[];return{description:d,check:v=>vals.includes(v),values:vals,__runtimeType:true}}"),se&&L.push("function Union(d,...v){const vals=v.flat();return{description:d,check:x=>vals.includes(x),values:vals,__runtimeType:true}}"),Ge&&(j||L.push("class MonadicError extends Error{constructor(m,p,e,a,c,r){super(m);this.name='MonadicError';this.path=p;this.expected=e;this.actual=a;this.callStack=c;this.reason=r}}",`function typeError(p,e,v,r){const a=v===null?'null':typeof v;const m=r?'Expected '+e+" for '"+p+"': "+r:'Expected '+e+" for '"+p+"', got "+a;const err=new MonadicError(m,p,e,a,undefined,r);const c=globalThis.__tjs?.getConfig?.();if(c?.logTypeErrors)console.error('[TJS TypeError] '+err.message);if(c?.throwTypeErrors)throw err;return err}`,"function isMonadicError(v){return v instanceof Error&&v.name==='MonadicError'&&'path' in v}"),L.push("function bang(o,p){if(o===null||o===undefined)return typeError('bang.'+p,'non-null',o);if(isMonadicError(o))return o;return o[p]}"));let K=L.length>0?L.join(`;
343
343
  `)+`;
344
344
  `:"",J=[];j&&J.push("typeError","isMonadicError"),C&&J.push("pushStack","popStack","getStack"),A&&J.push("Eq"),P&&J.push("NotEq"),v&&J.push("TypeOf"),$&&J.push("Is","tjsEquals"),R&&J.push("IsNot"),I&&J.push("Type"),O&&J.push("Generic"),F&&J.push("FunctionPredicate"),H&&J.push("Enum"),se&&J.push("Union"),Ge&&(J.push("bang"),j||J.push("typeError","isMonadicError"));let ge=J.length>0?`{${J.join(",")}}`:"undefined";w=K+`const __tjs = globalThis.__tjs?.createRuntime?.() ?? ${ge};
345
345
  `+w}Bn&&(w=`import { Eval, SafeFunction } from 'tjs-lang';