tjs-lang 0.2.0
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/CONTEXT.md +594 -0
- package/LICENSE +190 -0
- package/README.md +220 -0
- package/bin/benchmarks.ts +351 -0
- package/bin/dev.ts +205 -0
- package/bin/docs.js +170 -0
- package/bin/install-cursor.sh +71 -0
- package/bin/install-vscode.sh +71 -0
- package/bin/select-local-models.d.ts +1 -0
- package/bin/select-local-models.js +28 -0
- package/bin/select-local-models.ts +31 -0
- package/demo/autocomplete.test.ts +232 -0
- package/demo/docs.json +186 -0
- package/demo/examples.test.ts +598 -0
- package/demo/index.html +91 -0
- package/demo/src/autocomplete.ts +482 -0
- package/demo/src/capabilities.ts +859 -0
- package/demo/src/demo-nav.ts +2097 -0
- package/demo/src/examples.test.ts +161 -0
- package/demo/src/examples.ts +476 -0
- package/demo/src/imports.test.ts +196 -0
- package/demo/src/imports.ts +421 -0
- package/demo/src/index.ts +639 -0
- package/demo/src/module-store.ts +635 -0
- package/demo/src/module-sw.ts +132 -0
- package/demo/src/playground.ts +949 -0
- package/demo/src/service-host.ts +389 -0
- package/demo/src/settings.ts +440 -0
- package/demo/src/style.ts +280 -0
- package/demo/src/tjs-playground.ts +1605 -0
- package/demo/src/ts-examples.ts +478 -0
- package/demo/src/ts-playground.ts +1092 -0
- package/demo/static/favicon.svg +30 -0
- package/demo/static/photo-1.jpg +0 -0
- package/demo/static/photo-2.jpg +0 -0
- package/demo/static/texts/ai-history.txt +9 -0
- package/demo/static/texts/coffee-origins.txt +9 -0
- package/demo/static/texts/renewable-energy.txt +9 -0
- package/dist/index.js +256 -0
- package/dist/index.js.map +37 -0
- package/dist/tjs-batteries.js +4 -0
- package/dist/tjs-batteries.js.map +15 -0
- package/dist/tjs-full.js +256 -0
- package/dist/tjs-full.js.map +37 -0
- package/dist/tjs-transpiler.js +220 -0
- package/dist/tjs-transpiler.js.map +21 -0
- package/dist/tjs-vm.js +4 -0
- package/dist/tjs-vm.js.map +14 -0
- package/docs/CNAME +1 -0
- package/docs/favicon.svg +30 -0
- package/docs/index.html +91 -0
- package/docs/index.js +10468 -0
- package/docs/index.js.map +92 -0
- package/docs/photo-1.jpg +0 -0
- package/docs/photo-1.webp +0 -0
- package/docs/photo-2.jpg +0 -0
- package/docs/photo-2.webp +0 -0
- package/docs/texts/ai-history.txt +9 -0
- package/docs/texts/coffee-origins.txt +9 -0
- package/docs/texts/renewable-energy.txt +9 -0
- package/docs/tjs-lang.svg +31 -0
- package/docs/tosijs-agent.svg +31 -0
- package/editors/README.md +325 -0
- package/editors/ace/ajs-mode.js +328 -0
- package/editors/ace/ajs-mode.ts +269 -0
- package/editors/ajs-syntax.ts +212 -0
- package/editors/build-grammars.ts +510 -0
- package/editors/codemirror/ajs-language.js +287 -0
- package/editors/codemirror/ajs-language.ts +1447 -0
- package/editors/codemirror/autocomplete.test.ts +531 -0
- package/editors/codemirror/component.ts +404 -0
- package/editors/monaco/ajs-monarch.js +243 -0
- package/editors/monaco/ajs-monarch.ts +225 -0
- package/editors/tjs-syntax.ts +115 -0
- package/editors/vscode/language-configuration.json +37 -0
- package/editors/vscode/package.json +65 -0
- package/editors/vscode/syntaxes/ajs-injection.tmLanguage.json +107 -0
- package/editors/vscode/syntaxes/ajs.tmLanguage.json +252 -0
- package/editors/vscode/syntaxes/tjs.tmLanguage.json +333 -0
- package/package.json +83 -0
- package/src/cli/commands/check.ts +41 -0
- package/src/cli/commands/convert.ts +133 -0
- package/src/cli/commands/emit.ts +260 -0
- package/src/cli/commands/run.ts +68 -0
- package/src/cli/commands/test.ts +194 -0
- package/src/cli/commands/types.ts +20 -0
- package/src/cli/create-app.ts +236 -0
- package/src/cli/playground.ts +250 -0
- package/src/cli/tjs.ts +166 -0
- package/src/cli/tjsx.ts +160 -0
- package/tjs-lang.svg +31 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
var o6=(X,Y)=>()=>(Y||X((Y={exports:{}}).exports,Y),Y.exports);var b6=o6((r5,F5)=>{F5.exports={name:"tjs-lang",version:"0.2.0",license:"Apache-2.0",main:"./dist/index.js",exports:{".":"./dist/index.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","docs","src/cli","editors","bin","demo","tjs-lang.svg","CONTEXT.md"],sideEffects:!1,repository:{type:"git",url:"https://github.com/tonioloewald/tjs-lang.git"},devDependencies:{"@codemirror/lang-javascript":"^6.2.4","@codemirror/state":"^6.5.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",eslint:"^8.57.1",marked:"^9.1.6",prettier:"^2.8.8",tosijs:"^1.0.0","tosijs-ui":"^1.0.0",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 run docs && bun build ./demo/src/index.ts --outdir=docs --minify --sourcemap=external --target=browser && cp demo/index.html demo/static/favicon.svg demo/static/photo-*.jpg tjs-lang.svg docs/ && cp -r demo/static/texts docs/","build:cli":"bun build src/cli/tjs.ts --compile --outfile=dist/tjs && bun build src/cli/tjsx.ts --compile --outfile=dist/tjsx",start:"bun run build:demo && bun run dev"},dependencies:{"@codemirror/lang-css":"^6.3.1","@codemirror/lang-html":"^6.4.11","@codemirror/lang-markdown":"^6.5.0","@codemirror/theme-one-dark":"^6.1.3",acorn:"^8.15.0","tosijs-schema":"^1.2.0"}}});import*as F6 from"acorn";class V extends Error{line;column;source;filename;constructor(X,Y,Z,K){let H=`${K||"<source>"}:${Y.line}:${Y.column}`;super(`${X} at ${H}`);this.name="TranspileError",this.line=Y.line,this.column=Y.column,this.source=Z,this.filename=K}}class u extends V{constructor(X,Y,Z,K){super(X,Y,Z,K);this.name="SyntaxError"}formatWithContext(X=2){if(!this.source)return this.message;let Y=this.source.split(`
|
|
2
|
+
`),Z=this.line-1,K=Math.max(0,Z-X),H=Math.min(Y.length-1,Z+X),$=[],J=String(H+1).length;for(let W=K;W<=H;W++){let z=String(W+1).padStart(J),Q=W===Z?">":" ";if($.push(`${Q} ${z} | ${Y[W]}`),W===Z){let _=" ".repeat(J+4+this.column);$.push(`${_}^ ${this.message.split(" at ")[0]}`)}}return $.join(`
|
|
3
|
+
`)}}function v(X){return{depth:X.depth+1,locals:new Map,parent:X,parameters:X.parameters,atoms:X.atoms,warnings:X.warnings,source:X.source,filename:X.filename,options:X.options}}function C(X){if(X.loc)return{line:X.loc.start.line,column:X.loc.start.column};return{line:1,column:0}}function V0(X,Y){let Z="",K=0,H,$,J="normal",W=[],z=[{type:"top-level",braceDepth:0}],Q=0,_=()=>z[z.length-1]?.type||"top-level",U=()=>{let G=z[z.length-1];return G?.type==="class-body"&&Q===G.braceDepth+1};while(K<X.length){let G=X[K],F=X[K+1];switch(J){case"single-string":if(Z+=G,G==="\\"&&K+1<X.length){Z+=F,K+=2;continue}if(G==="'")J="normal";K++;continue;case"double-string":if(Z+=G,G==="\\"&&K+1<X.length){Z+=F,K+=2;continue}if(G==='"')J="normal";K++;continue;case"template-string":if(Z+=G,G==="\\"&&K+1<X.length){Z+=F,K+=2;continue}if(G==="$"&&F==="{"){Z+=F,K+=2,W.push(1),J="normal";continue}if(G==="`")J="normal";K++;continue;case"line-comment":if(Z+=G,G===`
|
|
4
|
+
`)J="normal";K++;continue;case"block-comment":if(Z+=G,G==="*"&&F==="/"){Z+=F,K+=2,J="normal";continue}K++;continue;case"regex":if(Z+=G,G==="\\"&&K+1<X.length){Z+=F,K+=2;continue}if(G==="["){K++;while(K<X.length&&X[K]!=="]")if(Z+=X[K],X[K]==="\\"&&K+1<X.length)Z+=X[K+1],K+=2;else K++;if(K<X.length)Z+=X[K],K++;continue}if(G==="/"){K++;while(K<X.length&&/[gimsuy]/.test(X[K]))Z+=X[K],K++;J="normal";continue}K++;continue;case"normal":if(W.length>0){if(G==="{")W[W.length-1]++;else if(G==="}"){if(W[W.length-1]--,W[W.length-1]===0){W.pop(),Z+=G,K++,J="template-string";continue}}}if(G==="'"){Z+=G,K++,J="single-string";continue}if(G==='"'){Z+=G,K++,J="double-string";continue}if(G==="`"){Z+=G,K++,J="template-string";continue}if(G==="/"&&F==="/"){Z+=G+F,K+=2,J="line-comment";continue}if(G==="/"&&F==="*"){Z+=G+F,K+=2,J="block-comment";continue}if(G==="/"){let B=Z.trimEnd();if(!B[B.length-1]||/[=(!,;:{[&|?+\-*%<>~^]$/.test(B)||/\b(return|case|throw|in|of|typeof|instanceof|new|delete|void)\s*$/.test(B)){Z+=G,K++,J="regex";continue}}break}if(G==="{"){Q++,Z+=G,K++;continue}if(G==="}"){Q--;let B=z[z.length-1];if(B&&Q===B.braceDepth)z.pop();Z+=G,K++;continue}let D=X.slice(K).match(/^class\s+\w+(?:\s+extends\s+\w+)?\s*\{/);if(D){let B=D[0].slice(0,-1);Z+=B,K+=B.length,z.push({type:"class-body",braceDepth:Q});continue}let A=X.slice(K).match(/^function\s+(\w+)\s*\(/);if(A){let B=A[1],R=A[0].length,O=X[K+R],L=null,I=K+R;if(O==="?"||O==="!")if(L=O,I++,L==="!")Y.unsafeFunctions.add(B);else Y.safeFunctions.add(B);Z+=`function ${B}(`,K=I;let P=F0(X,K,"(",")");if(!P){Z+=X[K],K++;continue}let{content:N,endPos:j}=P;K=j;let S=T0(N,Y,!0);Z+=S+")";let M=K;while(M<X.length&&/\s/.test(X[M]))M++;let T=X.slice(M,M+2);if(T==="->"||T==="-?"||T==="-!"){M+=2;while(M<X.length&&/\s/.test(X[M]))M++;let y=_0(X,M);if(y){let{type:x,endPos:j0}=y;if(H===void 0){if(H=x,T==="-?")$="safe";else if(T==="-!")$="unsafe"}K=j0}}continue}let w=X.slice(K).match(/^(constructor|(?:get|set)\s+\w+|async\s+\w+|\w+)\s*\(/);if(w&&U()){let B=w[1],R=w[0].length,O=K+R;Z+=B+"(",K=O;let L=F0(X,K,"(",")");if(!L){Z+=X[K],K++;continue}let{content:I,endPos:P}=L;K=P;let N=T0(I,Y,!0);Z+=N+")";let j=K;while(j<X.length&&/\s/.test(X[j]))j++;if(X.slice(j,j+2)==="->"){j+=2;while(j<X.length&&/\s/.test(X[j]))j++;let M=_0(X,j);if(M)K=M.endPos}else if(X[j]===":"){j++;while(j<X.length&&/\s/.test(X[j]))j++;let M=_0(X,j);if(M)K=M.endPos}continue}if(X[K]==="("){let B=F0(X,K+1,"(",")");if(!B){Z+=X[K],K++;continue}let{content:R,endPos:O}=B,L=O;while(L<X.length&&/\s/.test(X[L]))L++;let I,P=X.slice(L,L+2);if(P==="->"||P==="-?"||P==="-!"){L+=2;while(L<X.length&&/\s/.test(X[L]))L++;let N=_0(X,L);if(N){I=N.type,L=N.endPos;while(L<X.length&&/\s/.test(X[L]))L++}}if(X.slice(L,L+2)==="=>"){let N=null,j=R,S=R.trimStart();if(S.startsWith("?")&&(S.length===1||/\s/.test(S[1])))N="?",j=S.slice(1);else if(S.startsWith("!")&&(S.length===1||/\s/.test(S[1])))N="!",j=S.slice(1);let M=T0(j,Y,!1);Z+=`(${N==="?"?"/* safe */ ":N==="!"?"/* unsafe */ ":""}${M})`,K=O;while(K<L&&/\s/.test(X[K]))Z+=X[K],K++;if(I)K=L}else{let N=V0(R,Y);Z+=`(${N.source})`,K=O}continue}Z+=X[K],K++}return{source:Z,returnType:H,returnSafety:$}}function F0(X,Y,Z,K){let H=1,$=Y,J=!1,W="";while($<X.length&&H>0){let z=X[$];if(!J&&(z==="'"||z==='"'||z==="`"))J=!0,W=z;else if(J&&z===W&&X[$-1]!=="\\")J=!1;else if(!J){if(z===Z)H++;else if(z===K)H--}$++}if(H!==0)return null;return{content:X.slice(Y,$-1),endPos:$}}function c6(X,Y){let Z=Y;while(Z<X.length&&/\s/.test(X[Z]))Z++;if(Z>=X.length)return null;let K=Z,H=X[Z];if(H==="{"||H==="["){let J=H==="{"?"}":"]",W=F0(X,Z+1,H,J);if(!W)return null;return{value:X.slice(K,W.endPos),endPos:W.endPos}}if(H==="'"||H==='"'||H==="`"){Z++;while(Z<X.length){if(X[Z]===H&&X[Z-1]!=="\\")return Z++,{value:X.slice(K,Z),endPos:Z};Z++}return null}if(/[-+\d]/.test(H)){while(Z<X.length&&/[\d.eE+-]/.test(X[Z]))Z++;return{value:X.slice(K,Z),endPos:Z}}let $=X.slice(Z).match(/^(true|false|null|undefined)\b/);if($)return{value:$[1],endPos:Z+$[1].length};return null}function H0(X){return X.replace(/(?<!\|)\|(?!\|)/g," || ")}function _0(X,Y){let Z=Y,K=0,H=!1,$="",J=!1,W=(z)=>({type:H0(X.slice(Y,z).trim()),endPos:z});while(Z<X.length){let z=X[Z];if(!H&&(z==="'"||z==='"'||z==="`")){H=!0,$=z,J=!0,Z++;continue}if(H){if(z===$&&X[Z-1]!=="\\"){if(H=!1,Z++,K===0){let Q=Z;while(Q<X.length&&/\s/.test(X[Q]))Q++;if(X[Q]==="{"){if(!X.slice(Q+1).match(/^\s*(\w+)\s*:/))return W(Z)}if(X[Q]!=="|"&&X[Q]!=="&")return W(Z)}continue}Z++;continue}if(z==="{"||z==="["||z==="("){K++,J=!0,Z++;continue}if(z==="}"||z==="]"||z===")"){if(K--,K===0){Z++;let Q=Z;while(Q<X.length&&/\s/.test(X[Q]))Q++;if(X[Q]==="|"||X[Q]==="&")continue;return W(Z)}Z++;continue}if(K===0&&z==="{"){if(J)return W(Z);if(X.slice(Z+1).match(/^\s*(\w+)\s*:/)){K++,J=!0,Z++;continue}return W(Z)}if(K===0&&(z==="|"||z==="&")){if(Z++,Z<X.length&&X[Z]==="|")Z++;while(Z<X.length&&/\s/.test(X[Z]))Z++;continue}if(K===0&&(/\d/.test(z)||z==="-"&&/\d/.test(X[Z+1]))){let Q=Z;if(X[Q]==="-")Q++;while(Q<X.length&&/\d/.test(X[Q]))Q++;if(Q<X.length&&X[Q]==="."&&/\d/.test(X[Q+1])){Q++;while(Q<X.length&&/\d/.test(X[Q]))Q++}if(Q<X.length&&(X[Q]==="e"||X[Q]==="E")){if(Q++,Q<X.length&&(X[Q]==="+"||X[Q]==="-"))Q++;while(Q<X.length&&/\d/.test(X[Q]))Q++}J=!0,Z=Q;while(Z<X.length&&/\s/.test(X[Z]))Z++;if(Z<X.length&&X[Z]==="{")return{type:H0(X.slice(Y,Q).trim()),endPos:Q};if(X[Z]!=="|"&&X[Z]!=="&")return{type:H0(X.slice(Y,Q).trim()),endPos:Q};continue}if(K===0&&/[a-zA-Z_]/.test(z)){let Q=Z;while(Q<X.length&&/\w/.test(X[Q]))Q++;J=!0,Z=Q;while(Z<X.length&&/\s/.test(X[Z]))Z++;if(Z<X.length&&X[Z]==="{"){if(!X.slice(Z+1).match(/^\s*(\w+)\s*:/)){let U=Q;while(U>Y&&/\s/.test(X[U-1]))U--;return{type:H0(X.slice(Y,U).trim()),endPos:Q}}}if(X[Z]!=="|"&&X[Z]!=="&")return{type:H0(X.slice(Y,Q).trim()),endPos:Q};continue}Z++}if(J)return W(Z);return null}function T0(X,Y,Z){let K=V0(X,{originalSource:X,requiredParams:Y.requiredParams,unsafeFunctions:Y.unsafeFunctions,safeFunctions:Y.safeFunctions}).source,H=q0(K),$=!1,J=new Set,W=(Q)=>{if(Z&&/^\w+$/.test(Q)){if(J.has(Q))throw Error(`Duplicate parameter name '${Q}'`);J.add(Q)}};return H.map((Q)=>{let _=Q.trim();if(!_)return Q;if(Z&&_.startsWith("{")&&_.endsWith("}")){let F=_.slice(1,-1);return`{ ${G6(F,Y)} }`}if(Z&&_.startsWith("[")&&_.endsWith("]")){let F=_.slice(1,-1);return`[ ${G6(F,Y)} ]`}let U=_.match(/^(\w+)\s*\?\s*:\s*(.+)$/);if(U){let[,F,D]=U;return W(F),$=!0,`${F} = ${D}`}if(!s6(_)){let F=_.match(/^(\w+)\s*=/);if(F)W(F[1]);return $=!0,Q}let G=a6(_);if(G!==-1){let F=_.slice(0,G).trim(),D=_.slice(G+1).trim();if(W(F),$&&Z&&/^\w+$/.test(F))throw Error(`Required parameter '${F}' cannot follow optional parameter`);if(Z&&/^\w+$/.test(F))Y.requiredParams.add(F);return`${F} = ${D}`}return Q}).join(",")}function G6(X,Y){return q0(X).map((H)=>{let $=H.trim();if(!$)return H;let J=$.match(/^(\w+)\s*:\s*(\{[\s\S]*\})$/);if(J){let[,Q,_]=J;Y.requiredParams.add(Q);let U=U0(_);return`${Q} = ${U}`}let W=$.match(/^(\w+)\s*:\s*(\[[\s\S]*\])$/);if(W){let[,Q,_]=W;Y.requiredParams.add(Q);let U=D0(_);return`${Q} = ${U}`}let z=$.match(/^(\w+)\s*:\s*([\s\S]+)$/);if(z){let[,Q,_]=z;return Y.requiredParams.add(Q),`${Q} = ${_}`}return H}).join(", ")}function U0(X){let Y=X.slice(1,-1).trim();return`{ ${q0(Y).map((H)=>{let $=H.trim();if(!$)return H;let J=$.match(/^(\w+)\s*:\s*(\{[\s\S]*\})$/);if(J){let[,U,G]=J;return`${U}: ${U0(G)}`}let W=$.match(/^(\w+)\s*=\s*(\{[\s\S]*\})$/);if(W){let[,U,G]=W;return`${U}: ${U0(G)}`}let z=$.match(/^(\w+)\s*:\s*(\[[\s\S]*\])$/);if(z){let[,U,G]=z;return`${U}: ${D0(G)}`}let Q=$.match(/^(\w+)\s*=\s*(\[[\s\S]*\])$/);if(Q){let[,U,G]=Q;return`${U}: ${D0(G)}`}let _=$.match(/^(\w+)\s*=\s*([\s\S]+)$/);if(_){let[,U,G]=_;return`${U}: ${G}`}return H}).join(", ")} }`}function D0(X){let Y=X.slice(1,-1).trim();return`[ ${q0(Y).map((H)=>{let $=H.trim();if(!$)return H;if($.startsWith("{")&&$.endsWith("}"))return U0($);if($.startsWith("[")&&$.endsWith("]"))return D0($);return H}).join(", ")} ]`}function s6(X){let Y=0,Z=!1,K=!1,H=!1,$="";for(let J=0;J<X.length;J++){let W=X[J];if(!H&&(W==="'"||W==='"'||W==="`")){H=!0,$=W;continue}if(H){if(W===$&&X[J-1]!=="\\")H=!1;continue}if(W==="("||W==="{"||W==="[")Y++;else if(W===")"||W==="}"||W==="]")Y--;else if(Y===0){if(W===":")Z=!0;if(W==="="&&X[J+1]!==">")K=!0}}return Z&&!K}function a6(X){let Y=0,Z=!1,K="";for(let H=0;H<X.length;H++){let $=X[H];if(!Z&&($==="'"||$==='"'||$==="`")){Z=!0,K=$;continue}if(Z){if($===K&&X[H-1]!=="\\")Z=!1;continue}if($==="("||$==="{"||$==="[")Y++;else if($===")"||$==="}"||$==="]")Y--;else if(Y===0&&$===":")return H}return-1}function A0(X,Y={}){let Z=X,K,H=new Set,$=new Set,J=new Set,W={tjsEquals:!1,tjsClass:!1,tjsDate:!1,tjsNoeval:!1,tjsStandard:!1},z=X.match(/^(\s*(?:\/\/[^\n]*\n|\/\*[\s\S]*?\*\/\s*)*)\s*safety\s+(none|inputs|all)\b/);if(z)K=z[2],X=X.replace(/^(\s*(?:\/\/[^\n]*\n|\/\*[\s\S]*?\*\/\s*)*)\s*safety\s+(none|inputs|all)\s*/,"$1");let Q=/^(\s*(?:\/\/[^\n]*\n|\/\*[\s\S]*?\*\/\s*)*)\s*(TjsStrict|TjsEquals|TjsClass|TjsDate|TjsNoeval|TjsStandard|LegacyEquals)\b/,_;while(_=X.match(Q)){let w=_[2];if(w==="TjsStrict")W.tjsEquals=!0,W.tjsClass=!0,W.tjsDate=!0,W.tjsNoeval=!0,W.tjsStandard=!0;else if(w==="TjsEquals")W.tjsEquals=!0;else if(w==="TjsClass")W.tjsClass=!0;else if(w==="TjsDate")W.tjsDate=!0;else if(w==="TjsNoeval")W.tjsNoeval=!0;else if(w==="TjsStandard")W.tjsStandard=!0;else if(w==="LegacyEquals")console.warn("LegacyEquals is deprecated: JS equality is now the default. Use TjsEquals to enable structural equality.");X=X.replace(new RegExp(`^(\\s*(?:\\/\\/[^\\n]*\\n|\\/\\*[\\s\\S]*?\\*\\/\\s*)*)\\s*${w}\\s*`),"$1")}if(W.tjsStandard)X=Z1(X);if(X=X1(X),W.tjsEquals&&!Y.vmTarget)X=Y1(X);X=J1(X),X=$1(X),X=W1(X),X=Q1(X),X=G1(X);let{source:U,returnType:G,returnSafety:F}=V0(X,{originalSource:Z,requiredParams:H,unsafeFunctions:$,safeFunctions:J});X=U,X=t6(X);let D=r6(X);X=D.source;let A=_1(X,Y.dangerouslySkipTests);if(X=A.source,W.tjsClass)X=F1(X);if(W.tjsDate)X=U1(X);if(W.tjsNoeval)X=D1(X);return{source:X,returnType:G,returnSafety:F,moduleSafety:K,tjsModes:W,originalSource:Z,requiredParams:H,unsafeFunctions:$,safeFunctions:J,wasmBlocks:D.blocks,tests:A.tests,testErrors:A.errors}}function t6(X){let Y="",Z=0;while(Z<X.length){let K=X.slice(Z).match(/^\btry\s*\{/);if(K){let $=Z+K[0].length-1+1,J=1,W=$;while(W<X.length&&J>0){let Q=X[W];if(Q==="{")J++;else if(Q==="}")J--;W++}if(J!==0){Y+=X[Z],Z++;continue}if(X.slice(W).match(/^\s*(catch|finally)\b/))Y+=X.slice(Z,W),Z=W;else{let Q=X.slice($,W-1);Y+=`try {${Q}} catch (__try_err) { return { $error: true, message: __try_err?.message || String(__try_err), op: 'try', cause: __try_err, stack: globalThis.__tjs?.getStack?.() } }`,Z=W}}else Y+=X[Z],Z++}return Y}function r6(X){let Y=[],Z="",K=0,H=0;while(K<X.length){let $=X.slice(K).match(/^\bwasm\s*\{/);if($){let J=K,W=K+$[0].length,z=1,Q=W;while(Q<X.length&&z>0){let L=X[Q];if(L==="{")z++;else if(L==="}")z--;Q++}if(z!==0){Z+=X[K],K++;continue}let _=X.slice(W,Q-1),U,G=Q,F=X.slice(Q).match(/^\s*fallback\s*\{/);if(F){let L=Q+F[0].length;z=1;let I=L;while(I<X.length&&z>0){let P=X[I];if(P==="{")z++;else if(P==="}")z--;I++}if(z===0)U=X.slice(L,I-1),G=I}let D=e6(_),A={id:`__tjs_wasm_${H}`,body:_,fallback:U,captures:D,start:J,end:G};Y.push(A);let w=U??_,B=D.length>0?D.join(", "):"",R=D.length>0?`globalThis.${A.id}(${B})`:`globalThis.${A.id}()`,O=`(globalThis.${A.id} ? ${R} : (() => {${w}})())`;Z+=O,K=G,H++}else Z+=X[K],K++}return{source:Z,blocks:Y}}function e6(X){let Y=/\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g,Z=new Set,K;while((K=Y.exec(X))!==null)Z.add(K[1]);let H=new Set,$=/\b(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;while((K=$.exec(X))!==null)H.add(K[1]);let J=/\bfor\s*\(\s*(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;while((K=J.exec(X))!==null)H.add(K[1]);let W=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"]),z=[];for(let Q of Z)if(!H.has(Q)&&!W.has(Q))z.push(Q);return z.sort()}function q0(X){let Y=[],Z="",K=0,H=!1,$=!1,J=0;while(J<X.length){let W=X[J],z=X[J+1];if(!$&&W==="/"&&z==="/"){H=!0,Z+="//",J+=2;continue}if(!H&&W==="/"&&z==="*"){$=!0,Z+="/*",J+=2;continue}if(H&&W===`
|
|
5
|
+
`){H=!1,Z+=W,J++;continue}if($&&W==="*"&&z==="/"){$=!1,Z+="*/",J+=2;continue}if(H||$){Z+=W,J++;continue}if(W==="("||W==="{"||W==="[")K++,Z+=W;else if(W===")"||W==="}"||W==="]")K--,Z+=W;else if(W===","&&K===0)Y.push(Z),Z="";else Z+=W;J++}if(Z.trim())Y.push(Z);return Y}function X1(X){let Z=new RegExp(`([\\w][\\w.\\[\\]()]*|null|undefined|true|false|\\d+(?:\\.\\d+)?|'[^']*'|"[^"]*")\\s+IsNot\\s+([\\w][\\w.\\[\\]()]*|null|undefined|true|false|\\d+(?:\\.\\d+)?|'[^']*'|"[^"]*")`,"g");X=X.replace(Z,"IsNot($1, $2)");let K=new RegExp(`([\\w][\\w.\\[\\]()]*|null|undefined|true|false|\\d+(?:\\.\\d+)?|'[^']*'|"[^"]*")\\s+Is\\s+([\\w][\\w.\\[\\]()]*|null|undefined|true|false|\\d+(?:\\.\\d+)?|'[^']*'|"[^"]*")`,"g");return X=X.replace(K,"Is($1, $2)"),X}function Z1(X){let Y=/^[\s]*[([/+\-`]/,Z=/[{([,;:+\-*/%=&|?<>!~^]\s*$|^\s*$/,K=/\b(return|throw|yield|await|case|default|extends|new|typeof|void|delete|in|of|instanceof)\s*$/,H=X.split(`
|
|
6
|
+
`),$=[];for(let J=0;J<H.length;J++){let W=H[J],z=J>0?H[J-1]:"";if(J>0&&Y.test(W)){let Q=z.replace(/\/\/.*$/,"").replace(/\/\*.*\*\/\s*$/,"");if(!Z.test(Q)&&!K.test(Q)){let _=W.match(/^(\s*)/),U=_?_[1]:"",G=W.slice(U.length);$.push(U+";"+G);continue}}$.push(W)}return $.join(`
|
|
7
|
+
`)}function Y1(X){let Y=[],Z=0,K="normal",H=[];while(Z<X.length){let J=X[Z],W=X[Z+1];switch(K){case"single-string":if(J==="\\"&&Z+1<X.length){Z+=2;continue}if(J==="'")K="normal";Z++;continue;case"double-string":if(J==="\\"&&Z+1<X.length){Z+=2;continue}if(J==='"')K="normal";Z++;continue;case"template-string":if(J==="\\"&&Z+1<X.length){Z+=2;continue}if(J==="$"&&W==="{"){Z+=2,H.push(1),K="normal";continue}if(J==="`")K="normal";Z++;continue;case"line-comment":if(J===`
|
|
8
|
+
`)K="normal";Z++;continue;case"block-comment":if(J==="*"&&W==="/"){Z+=2,K="normal";continue}Z++;continue;case"regex":if(J==="\\"&&Z+1<X.length){Z+=2;continue}if(J==="["){Z++;while(Z<X.length&&X[Z]!=="]")if(X[Z]==="\\"&&Z+1<X.length)Z+=2;else Z++;if(Z<X.length)Z++;continue}if(J==="/"){Z++;while(Z<X.length&&/[gimsuy]/.test(X[Z]))Z++;K="normal";continue}Z++;continue;case"normal":if(H.length>0){if(J==="{")H[H.length-1]++;else if(J==="}"){if(H[H.length-1]--,H[H.length-1]===0){H.pop(),Z++,K="template-string";continue}}}if(J==="'"){Z++,K="single-string";continue}if(J==='"'){Z++,K="double-string";continue}if(J==="`"){Z++,K="template-string";continue}if(J==="/"&&W==="/"){Z+=2,K="line-comment";continue}if(J==="/"&&W==="*"){Z+=2,K="block-comment";continue}if(J==="/"){let z=Z-1;while(z>=0&&/\s/.test(X[z]))z--;let Q=z>=0?X[z]:"";if(!Q||/[=(!,;:{[&|?+\-*%<>~^]/.test(Q)||z>=5&&/\b(return|case|throw|in|of|typeof|instanceof|new|delete|void)$/.test(X.slice(Math.max(0,z-10),z+1))){Z++,K="regex";continue}}if(J==="="&&W==="="&&X[Z+2]!=="="&&X[Z-1]!=="!"){Y.push({pos:Z,op:"=="}),Z+=2;continue}if(J==="!"&&W==="="&&X[Z+2]!=="="){Y.push({pos:Z,op:"!="}),Z+=2;continue}break}Z++}if(Y.length===0)return X;let $=X;for(let J=Y.length-1;J>=0;J--){let{pos:W,op:z}=Y[J],Q=z==="=="?"Is":"IsNot",_=K1($,W),U=H1($,W+2),G=$.slice(_,W).trim(),F=$.slice(W+2,U).trim();if(G&&F){let D=$.slice(0,_),A=$.slice(U),B=/[a-zA-Z0-9_$]$/.test(D)?" ":"";$=`${D}${B}${Q}(${G}, ${F})${A}`}}return $}function K1(X,Y){let Z=Y-1;while(Z>=0&&/\s/.test(X[Z]))Z--;if(Z<0)return 0;let K=0,H=!1,$="";while(Z>=0){let J=X[Z],W=Z>0?X[Z-1]:"";if(H){if(J===$&&W!=="\\")H=!1;Z--;continue}if((J==='"'||J==="'"||J==="`")&&W!=="\\"){H=!0,$=J,Z--;continue}if(J===")"||J==="]"){K++,Z--;continue}if(J==="("||J==="["){if(K>0){K--,Z--;continue}return Z+1}if(K>0){Z--;continue}if(J===";"||J==="{"||J==="}")return Z+1;if(/[a-z]/.test(J)){let z=Z+1,Q=Z;while(Q>0&&/[a-z]/i.test(X[Q-1]))Q--;let _=X.slice(Q,z),U=Q>0?X[Q-1]:"";if(!/[a-zA-Z0-9_$]/.test(U)){if(["return","throw","case","typeof","void","delete","await","yield","new"].includes(_))return z}}if(J===">"&&W==="=")return Z+1;if(J==="="&&W!=="="&&W!=="!"&&W!=="<"&&W!==">")return Z+1;if(J==="&"&&W==="&")return Z+1;if(J==="|"&&W==="|")return Z+1;if(J==="?"||J===":")return Z+1;if(J===",")return Z+1;Z--}return 0}function H1(X,Y){let Z=Y;while(Z<X.length&&/\s/.test(X[Z]))Z++;if(Z>=X.length)return X.length;let K=0,H=!1,$="";while(Z<X.length){let J=X[Z],W=Z+1<X.length?X[Z+1]:"";if(H){if(J===$&&X[Z-1]!=="\\")H=!1;Z++;continue}if((J==='"'||J==="'"||J==="`")&&X[Z-1]!=="\\"){H=!0,$=J,Z++;continue}if(J==="("||J==="["||J==="{"){K++,Z++;continue}if(J===")"||J==="]"||J==="}"){if(K>0){K--,Z++;continue}return Z}if(K>0){Z++;continue}if(J===";")return Z;if(J==="&"&&W==="&")return Z;if(J==="|"&&W==="|")return Z;if(J==="?")return Z;if(J===":")return Z;if(J===",")return Z;if((J==="="||J==="!")&&W==="="&&X[Z+2]!=="=")return Z;Z++}return X.length}function J1(X){let Y="",Z=0;while(Z<X.length){let K=X.slice(Z).match(/^\bType\s+([A-Z][a-zA-Z0-9_]*)\s*/);if(K){let H=K[1],$=Z+K[0].length,J=H,W=!1,z=X.slice($).match(/^(['"`])([^]*?)\1\s*/);if(z){let G=$+z[0].length,F=X[G],D=F===void 0||G>=X.length||F!=="="&&F!=="{";if(F==="="||F==="{")J=z[2],W=!0,$=G;else if(D){let A=z[0].trim(),w=z[0].slice(A.length);Y+=`const ${H} = Type('${H}', ${A})${w}`,Z=G;continue}}let Q,_=$,U=X.slice($).match(/^=\s*/);if(U){$+=U[0].length;let G=X.slice($).match(/^(\+?\d+(?:\.\d+)?|['"`][^'"`]*['"`]|\{[^}]*\}|\[[^\]]*\]|true|false|null)/);if(G){Q=G[0],$+=G[0].length,_=$;let F=X.slice($).match(/^\s*/);if(F)$+=F[0].length}}if(X[$]==="{"){let G=$+1,F=1,D=G;while(D<X.length&&F>0){let I=X[D];if(I==="{")F++;else if(I==="}")F--;D++}if(F!==0){Y+=X[Z],Z++;continue}let A=X.slice(G,D-1).trim(),w=D,B=A.match(/description\s*:\s*(['"`])([^]*?)\1/);if(B&&!W)J=B[2];let R,O=A.match(/example\s*:\s*/);if(O){let I=O.index+O[0].length,P=c6(A,I);if(P)R=P.value.trim()}let L=A.match(/predicate\s*\(([^)]*)\)\s*\{([^]*)\}/);if(L&&R){let I=L[1].trim(),P=L[2].trim(),N=Q?`, ${Q}`:"";Y+=`const ${H} = Type('${J}', (${I}) => { if (!globalThis.__tjs?.validate(${I}, globalThis.__tjs?.infer(${R}))) return false; ${P} }, ${R}${N})`}else if(L){let I=L[1].trim(),P=L[2].trim(),N=Q?`, undefined, ${Q}`:"";Y+=`const ${H} = Type('${J}', (${I}) => { ${P} }${N})`}else if(R){let I=Q?`, ${Q}`:"";Y+=`const ${H} = Type('${J}', undefined, ${R}${I})`}else if(Q)Y+=`const ${H} = Type('${J}', ${Q})`;else Y+=`const ${H} = Type('${J}')`;Z=w;continue}else if(Q){Y+=`const ${H} = Type('${J}', ${Q})`,Z=_;continue}else if(!z){let G=X.slice($).match(/^(['"`][^]*?['"`]|\+?\d+(?:\.\d+)?|true|false|null|\{[^]*?\}|\[[^]*?\])/);if(G){let F=G[0];Y+=`const ${H} = Type('${H}', ${F})`,Z=$+G[0].length;continue}}}Y+=X[Z],Z++}return Y}function $1(X){let Y="",Z=0;while(Z<X.length){let K=X.slice(Z).match(/^\bGeneric\s+([A-Z][a-zA-Z0-9_]*)\s*<([^>]+)>\s*\{/);if(K){let H=K[1],$=K[2],W=Z+K[0].length-1+1,z=1,Q=W;while(Q<X.length&&z>0){let w=X[Q];if(w==="{")z++;else if(w==="}")z--;Q++}if(z!==0){Y+=X[Z],Z++;continue}let _=X.slice(W,Q-1).trim(),U=Q,G=$.split(",").map((w)=>{let B=w.trim().split("=").map((R)=>R.trim());if(B.length===2)return`['${B[0]}', ${B[1]}]`;return`'${B[0]}'`}),F=_.match(/description\s*:\s*(['"`])([^]*?)\1/),D=_.match(/predicate\s*\(([^)]*)\)\s*\{([^]*)\}/),A=F?F[2]:H;if(D){let w=D[1].trim().split(",").map((I)=>I.trim()),B=D[2].trim(),R=w[0]||"x",O=w.slice(1),L=O.map((I)=>`check${I}`);O.forEach((I,P)=>{B=B.replace(new RegExp(`\\b${I}\\s*\\(`,"g"),`${L[P]}(`)}),Y+=`const ${H} = Generic([${G.join(", ")}], (${R}, ${L.join(", ")}) => { ${B} }, '${A}')`}else Y+=`const ${H} = Generic([${G.join(", ")}], () => true, '${A}')`;Z=U;continue}Y+=X[Z],Z++}return Y}function W1(X){let Y="",Z=0;while(Z<X.length){let K=X.slice(Z).match(/^\bUnion\s+([A-Z][a-zA-Z0-9_]*)\s+(['"`])([^]*?)\2\s*/);if(K){let H=K[1],$=K[3],J=Z+K[0].length;if(X[J]==="{"){let W=J+1,z=1,Q=W;while(Q<X.length&&z>0){let F=X[Q];if(F==="{")z++;else if(F==="}")z--;Q++}if(z!==0){Y+=X[Z],Z++;continue}let _=X.slice(W,Q-1).trim(),U=Q,G=_6(_);Y+=`const ${H} = Union('${$}', [${G.join(", ")}])`,Z=U;continue}else{let W=X.indexOf(`
|
|
9
|
+
`,J);if(W===-1)W=X.length;let z=X.slice(J,W).trim();if(z){let Q=_6(z);Y+=`const ${H} = Union('${$}', [${Q.join(", ")}])`,Z=W;continue}}}Y+=X[Z],Z++}return Y}function _6(X){let Y=[],Z=X.split("|").map((K)=>K.trim());for(let K of Z){if(!K)continue;Y.push(K)}return Y}function Q1(X){let Y="",Z=0;while(Z<X.length){let K=X.slice(Z).match(/^\bEnum\s+([A-Z][a-zA-Z0-9_]*)\s+(['"`])([^]*?)\2\s*\{/);if(K){let H=K[1],$=K[3],W=Z+K[0].length-1+1,z=1,Q=W;while(Q<X.length&&z>0){let D=X[Q];if(D==="{")z++;else if(D==="}")z--;Q++}if(z!==0){Y+=X[Z],Z++;continue}let _=X.slice(W,Q-1).trim(),U=Q,F=z1(_).map(([D,A])=>`${D}: ${A}`).join(", ");Y+=`const ${H} = Enum('${$}', { ${F} })`,Z=U;continue}Y+=X[Z],Z++}return Y}function z1(X){let Y=[],Z=0,K=X.split(/[\n,]/).map((H)=>H.trim()).filter((H)=>H&&!H.startsWith("//"));for(let H of K){let $=H.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(?:=\s*(.+))?$/);if($){let J=$[1],W=$[2]?.trim();if(W!==void 0){Y.push([J,W]);let z=Number(W);if(!isNaN(z))Z=z+1}else Y.push([J,String(Z)]),Z++}}return Y}function G1(X){return X.replace(/(?<=^|[;\n{])\s*([A-Z][a-zA-Z0-9_]*)\s*=(?!=)/gm,(Y,Z)=>{return Y.replace(Z,`const ${Z}`)})}function o(X,Y={}){let{filename:Z="<source>",colonShorthand:K=!0,vmTarget:H=!1}=Y,{source:$,returnType:J,returnSafety:W,moduleSafety:z,originalSource:Q,requiredParams:_,unsafeFunctions:U,safeFunctions:G,wasmBlocks:F,tests:D,testErrors:A}=K?A0(X,{vmTarget:H}):{source:X,returnType:void 0,returnSafety:void 0,moduleSafety:void 0,originalSource:X,requiredParams:new Set,unsafeFunctions:new Set,safeFunctions:new Set,wasmBlocks:[],tests:[],testErrors:[]};try{return{ast:F6.parse($,{ecmaVersion:2022,sourceType:"module",locations:!0,allowReturnOutsideFunction:!1}),returnType:J,returnSafety:W,moduleSafety:z,originalSource:Q,requiredParams:_,unsafeFunctions:U,safeFunctions:G,wasmBlocks:F,tests:D,testErrors:A}}catch(w){let B=w.loc||{line:1,column:0};throw new u(w.message.replace(/\s*\(\d+:\d+\)$/,""),B,Q,Z)}}function U6(X,Y){for(let K of X.body){if(K.type==="ImportDeclaration")throw new u("Imports are not supported. All atoms must be registered with the VM.",K.loc?.start||{line:1,column:0},void 0,Y);if(K.type==="ExportNamedDeclaration"||K.type==="ExportDefaultDeclaration")throw new u("Exports are not supported. The function is automatically exported.",K.loc?.start||{line:1,column:0},void 0,Y);if(K.type==="ClassDeclaration")throw new u("Classes are not supported. Agent99 uses functional composition.",K.loc?.start||{line:1,column:0},void 0,Y)}let Z=X.body.filter((K)=>K.type==="FunctionDeclaration");if(Z.length===0)throw new u("Source must contain a function declaration",{line:1,column:0},void 0,Y);if(Z.length>1){let K=Z[1];throw new u("Only a single function per agent is allowed",K.loc?.start||{line:1,column:0},void 0,Y)}return Z[0]}function J0(X,Y){let Z={params:{}};if(!Y.loc)return Z;let K=X.substring(0,Y.start),H=[...K.matchAll(/\/\*#([\s\S]*?)\*\//g)];if(H.length>0){let _=H[H.length-1],U=K.substring(_.index+_[0].length);if(/^(?:\s|\/\/[^\n]*)*$/.test(U)){let G=_[1],F=G.split(`
|
|
10
|
+
`),D=F.filter((A)=>A.trim().length>0).reduce((A,w)=>{let B=w.match(/^(\s*)/)?.[1].length||0;return Math.min(A,B)},1/0);if(D>0&&D<1/0)G=F.map((A)=>A.slice(D)).join(`
|
|
11
|
+
`);return Z.description=G.trim(),Z}}let $=K.match(/\/\*\*[\s\S]*?\*\/\s*$/);if(!$)return Z;let J=$[0],W=J.match(/\/\*\*\s*\n?\s*\*?\s*([^@\n][^\n]*)/m);if(W)Z.description=W[1].trim();let z=/@param\s+(?:\{[^}]+\}\s+)?(\w+)\s*-?\s*(.*)/g,Q;while((Q=z.exec(J))!==null)Z.params[Q[1]]=Q[2].trim();return Z}function _1(X,Y=!1){let Z=[],K=[],H="",$=0;while($<X.length){let J=X.slice($).match(/^\btest\s+/);if(J){let W=$,z=$+J[0].length,Q,_=X.slice(z).match(/^(['"`])([^]*?)\1\s*/);if(_)Q=_[2],z+=_[0].length;if(X[z]==="{"){let U=z+1,G=1,F=U;while(F<X.length&&G>0){let D=X[F];if(D==="{")G++;else if(D==="}")G--;F++}if(G===0){let D=X.slice(U,F-1).trim(),A=F;if(Z.push({description:Q,body:D,start:W,end:A}),!Y)try{Function(D)()}catch(R){let O=Q||`test at position ${W}`;K.push(`Test failed: ${O}
|
|
12
|
+
${R.message||R}`)}let B=(X.slice(W,A).match(/\n/g)||[]).length;H+=`
|
|
13
|
+
`.repeat(B),$=A;continue}}}H+=X[$],$++}return{source:H,tests:Z,errors:K}}function F1(X){let Y=/\bclass\s+(\w+)(\s+extends\s+\w+)?\s*\{/g,Z="",K=0,H;while((H=Y.exec(X))!==null){let $=H[1],J=H[2]||"",W=H.index,z=W+H[0].length-1,Q=1,_=z+1;while(_<X.length&&Q>0){let U=X[_];if(U==="{")Q++;else if(U==="}")Q--;_++}if(Q===0){let U=_,G=X.slice(z,U);Z+=X.slice(K,W),Z+=`let ${$} = class ${$}${J} ${G}; `,Z+=`${$} = new Proxy(${$}, { apply(t, _, a) { return Reflect.construct(t, a) } });`,K=U}}return Z+=X.slice(K),Z}function U1(X){let Y=[{pattern:/\bnew\s+Date\b/,message:"new Date() is not allowed in TjsDate mode. Use Timestamp.now() or Timestamp.from()"},{pattern:/\bDate\.now\b/,message:"Date.now() is not allowed in TjsDate mode. Use Timestamp.now()"},{pattern:/\bDate\.parse\b/,message:"Date.parse() is not allowed in TjsDate mode. Use Timestamp.parse()"},{pattern:/\bDate\.UTC\b/,message:"Date.UTC() is not allowed in TjsDate mode. Use Timestamp.from()"}];for(let{pattern:Z,message:K}of Y)if(Z.test(X))throw Error(K);return X}function D1(X){if(/(?<![A-Za-z_$])\beval\s*\(/.test(X))throw Error("eval() is not allowed in TjsNoeval mode. Use Eval() from TJS runtime for safe evaluation.");if(/\bnew\s+Function\s*\(/.test(X))throw Error("new Function() is not allowed in TjsNoeval mode. Use SafeFunction() from TJS runtime.");return X}import{parseExpressionAt as A1}from"acorn";function f(X){switch(X.type){case"Literal":{let Y=X.value;if(Y===null)return{kind:"null"};if(typeof Y==="string")return{kind:"string"};if(typeof Y==="number")return{kind:"number"};if(typeof Y==="boolean")return{kind:"boolean"};return{kind:"any"}}case"ArrayExpression":{let Y=X.elements;if(Y.length===0)return{kind:"array",items:{kind:"any"}};return{kind:"array",items:f(Y[0])}}case"ObjectExpression":{let Y=X.properties,Z={};for(let K of Y)if(K.type==="Property"&&K.key.type==="Identifier"){let H=K.key.name;Z[H]=f(K.value)}return{kind:"object",shape:Z}}case"LogicalExpression":{let{operator:Y,left:Z,right:K}=X;if(Y==="||"){let H=f(Z),$=f(K);if($.kind==="null")return{...H,nullable:!0};if(H.kind==="null")return{...$,nullable:!0};return{kind:"union",members:[H,$]}}if(Y==="&&")return f(K);if(Y==="??")return f(K);return{kind:"any"}}case"Identifier":{if(X.name==="undefined")return{kind:"undefined"};return{kind:"any"}}case"UnaryExpression":{if(X.operator==="-"&&X.argument.type==="Literal"){if(typeof X.argument.value==="number")return{kind:"number"}}return{kind:"any"}}default:return{kind:"any"}}}function n(X,Y){if(X.type==="Identifier")return{name:X.name,type:{kind:"any"},required:!0};if(X.type==="AssignmentPattern"){let{left:Z,right:K}=X;if(Z.type!=="Identifier")throw new V("Only simple parameter names are supported",C(X));let H=Z.name,$=Y?.has(H)??!1,J=f(K),W=i(K);return{name:H,type:J,required:$,default:$?null:W,example:W,loc:{start:X.start,end:X.end}}}if(X.type==="ObjectPattern"){let Z=X.properties,K={},H={};for(let $ of Z)if($.type==="Property"){let J=$.key.type==="Identifier"?$.key.name:String($.key.value);if($.value.type==="Identifier")K[J]={kind:"any"},H[J]={name:J,type:{kind:"any"},required:!0};else if($.value.type==="AssignmentPattern"){let W=n($.value,Y),z=Y?.has(J)??!1;K[J]=W.type,H[J]={name:J,type:W.type,required:z,default:z?null:W.example,example:W.example}}}return{name:"__destructured__",type:{kind:"object",shape:K,destructuredParams:H},required:!0}}throw new V(`Unsupported parameter pattern: ${X.type}`,C(X))}function i(X){switch(X.type){case"Literal":return X.value;case"ArrayExpression":return X.elements.map((Y)=>Y?i(Y):null);case"ObjectExpression":{let Y={};for(let Z of X.properties)if(Z.type==="Property"&&Z.key.type==="Identifier")Y[Z.key.name]=i(Z.value);return Y}case"UnaryExpression":if(X.operator==="-"){let Y=i(X.argument);return typeof Y==="number"?-Y:void 0}return;case"LogicalExpression":{let{operator:Y,left:Z,right:K}=X;if(Y==="&&"){if(Z.type==="Literal"&&Z.value===null)return null}if(Y==="||")return i(Z)??i(K);if(Y==="??")return i(Z)??i(K);return}default:return}}function D6(X){try{let Y=A1(X,0,{ecmaVersion:2022});return f(Y)}catch{return{kind:"any"}}}function C0(X){switch(X.kind){case"string":return X.nullable?"string | null":"string";case"number":return X.nullable?"number | null":"number";case"boolean":return X.nullable?"boolean | null":"boolean";case"null":return"null";case"any":return"any";case"array":{let Y=X.items?C0(X.items):"any";return X.nullable?`${Y}[] | null`:`${Y}[]`}case"object":{if(!X.shape||Object.keys(X.shape).length===0)return X.nullable?"object | null":"object";let Y=Object.entries(X.shape).map(([Z,K])=>`${Z}: ${C0(K)}`).join(", ");return X.nullable?`{ ${Y} } | null`:`{ ${Y} }`}case"union":return X.members?.map(C0).join(" | ")||"any";default:return"any"}}function B0(X){switch(X.kind){case"string":return{type:"string"};case"number":return{type:"number"};case"boolean":return{type:"boolean"};case"null":return{};case"undefined":return{};case"any":return{};case"array":return{type:"array",items:X.items?B0(X.items):{}};case"object":if(X.shape){let Y={};for(let[Z,K]of Object.entries(X.shape))Y[Z]=B0(K);return{type:"object",properties:Y,additionalProperties:!1}}return{type:"object"};case"union":if(X.members)return{oneOf:X.members.map(B0)};return{};default:return{}}}function q1(X){let Y={},Z=[];for(let[K,H]of Object.entries(X))if(Y[K]=B0(H.type),H.required)Z.push(K);return{type:"object",properties:Y,required:Z.length>0?Z:void 0,additionalProperties:!1}}function N0(X,Y,Z,K={},H){let $=J0(Y,X),J=new Map;for(let w of X.params){let B=n(w,H);if(B.name==="__destructured__"&&B.type.kind==="object"&&B.type.destructuredParams)for(let[R,O]of Object.entries(B.type.destructuredParams))J.set(R,{...O,description:$.params[R]});else B.description=$.params[B.name],J.set(B.name,B)}let W;if(Z)W=D6(Z);let z={depth:0,locals:new Map,parameters:J,atoms:new Set(Object.keys(K.atoms||{})),warnings:[],source:Y,filename:K.filename||"<source>",options:K},Q=h(X.body,z),_=[],U=[],G=[];for(let[w,B]of J.entries())if(B.required)U.push(w);else if(B.default!==void 0)G.push({name:w,defaultValue:B.default});else U.push(w);if(U.length>0)_.push({op:"varsImport",keys:U});for(let{name:w,defaultValue:B}of G)_.push({op:"varsImport",keys:[w]}),_.push({op:"if",condition:{$expr:"binary",op:"==",left:{$expr:"ident",name:w},right:{$expr:"literal",value:null}},then:[{op:"varSet",key:w,value:B}]});_.push(...Q);let F=Object.fromEntries(J),D={name:X.id?.name||"anonymous",description:$.description,parameters:F,returns:W},A=q1(F);return{ast:{op:"seq",steps:_,inputSchema:A},signature:D,warnings:z.warnings}}function h(X,Y){let Z=[];for(let K of X.body){let H=$0(K,Y);if(H)if(Array.isArray(H))Z.push(...H);else Z.push(H)}return Z}function $0(X,Y){switch(X.type){case"VariableDeclaration":return B1(X,Y);case"ExpressionStatement":return w1(X,Y);case"IfStatement":return I1(X,Y);case"WhileStatement":return R1(X,Y);case"ForOfStatement":return O1(X,Y);case"TryStatement":return M1(X,Y);case"ReturnStatement":return P1(X,Y);case"ThrowStatement":throw new V("'throw' is not supported in AsyncJS. Use Error('message') to trigger error flow",C(X),Y.source,Y.filename);case"BlockStatement":return{op:"scope",steps:h(X,v(Y))};case"EmptyStatement":return null;default:throw new V(`Unsupported statement type: ${X.type}`,C(X),Y.source,Y.filename)}}function B1(X,Y){let Z=[],K=X.kind==="const",H=K?"constSet":"varSet";for(let $ of X.declarations){if($.id.type!=="Identifier")throw new V("Only simple variable names are supported",C($),Y.source,Y.filename);let J=$.id.name;if($.init){let{step:W,resultVar:z}=c($.init,Y,J,K);if(W)Z.push(W);else if(z!==J)Z.push({op:H,key:J,value:z});let Q=f($.init);Y.locals.set(J,Q)}else{if(K)throw new V("const declarations must be initialized",C($),Y.source,Y.filename);Z.push({op:"varSet",key:J,value:null}),Y.locals.set(J,{kind:"any",nullable:!0})}}return Z}function w1(X,Y){let Z=X.expression;if(Z.type==="AssignmentExpression")return L1(Z,Y);if(Z.type==="CallExpression"){let{step:K,resultVar:H}=c(Z,Y);if(K)return K;if(H)return{op:"varSet",key:"_",value:H};return null}return Y.warnings.push({message:"Expression statement has no effect",line:C(X).line,column:C(X).column}),null}function L1(X,Y){if(X.left.type!=="Identifier")throw new V("Only simple variable assignment is supported",C(X),Y.source,Y.filename);let Z=X.left.name,{step:K,resultVar:H}=c(X.right,Y,Z);if(K)return K;return{op:"varSet",key:Z,value:H}}function I1(X,Y){let Z=E(X.test,Y),K=X.consequent.type==="BlockStatement"?h(X.consequent,v(Y)):[$0(X.consequent,Y)].filter(Boolean),H;if(X.alternate)H=X.alternate.type==="BlockStatement"?h(X.alternate,v(Y)):[$0(X.alternate,Y)].filter(Boolean);return{op:"if",condition:Z,then:K,...H&&{else:H}}}function R1(X,Y){let Z=E(X.test,Y),K=X.body.type==="BlockStatement"?h(X.body,v(Y)):[$0(X.body,Y)].filter(Boolean);return{op:"while",condition:Z,body:K}}function O1(X,Y){let Z;if(X.left.type==="VariableDeclaration"){let J=X.left.declarations[0];if(J.id.type!=="Identifier")throw new V("Only simple variable names are supported in for...of",C(X.left),Y.source,Y.filename);Z=J.id.name}else if(X.left.type==="Identifier")Z=X.left.name;else throw new V("Unsupported for...of left-hand side",C(X.left),Y.source,Y.filename);let K=g(X.right,Y),H=v(Y);H.locals.set(Z,{kind:"any"});let $=X.body.type==="BlockStatement"?h(X.body,H):[$0(X.body,H)].filter(Boolean);return{op:"map",items:K,as:Z,steps:$}}function M1(X,Y){let Z=h(X.block,v(Y)),K,H;if(X.handler){let $=v(Y);if(X.handler.param?.type==="Identifier")H=X.handler.param.name,$.locals.set(H,{kind:"any"});K=h(X.handler.body,$)}return{op:"try",try:Z,...K&&{catch:K},...H&&{catchParam:H}}}function P1(X,Y){if(!X.argument)return{op:"return",value:{}};let{step:Z,resultVar:K}=c(X.argument,Y,"__returnVal__");if(Z)return[Z,{op:"return",value:K}];return{op:"return",value:g(X.argument,Y)}}var q6=new Set(["Math","JSON","Array","Object","String","Number","console","Date","Schema"]),j1=new Set(["parseInt","parseFloat","isNaN","isFinite","encodeURI","decodeURI","encodeURIComponent","decodeURIComponent","Set","Date","filter"]),W0=new Set(["RegExp","Promise","Map","WeakSet","WeakMap","Symbol","Proxy","Reflect","Function","eval","setTimeout","setInterval","fetch","require","import","process","window","document","global","globalThis"]),E1=new Set(["toUpperCase","toLowerCase","trim","trimStart","trimEnd","charAt","charCodeAt","codePointAt","concat","includes","indexOf","lastIndexOf","startsWith","endsWith","slice","substring","substr","replace","replaceAll","match","search","padStart","padEnd","repeat","normalize","localeCompare","toString","valueOf","at","reverse","sort","fill","copyWithin","flat","flatMap","every","some","forEach","add","remove","has","clear","toArray","union","intersection","diff","format","isBefore","isAfter"]);function T1(X){if(X.callee.type==="Identifier"){let Y=X.callee.name;return j1.has(Y)||W0.has(Y)}if(X.callee.type==="MemberExpression"){let Y=X.callee;if(Y.object.type==="Identifier"){let Z=Y.object.name;if(q6.has(Z)||W0.has(Z))return!0}if(Y.property.type==="Identifier"){let Z=Y.property.name;if(E1.has(Z))return!0}}return!1}function V1(X){if(X.object.type==="Identifier"){let Y=X.object.name;return q6.has(Y)||W0.has(Y)}return!1}var A6={RegExp:"RegExp is not available. Use string methods or the regexMatch atom.",Promise:"Promise is not needed. All operations are implicitly async.",Map:"Map is not available. Use plain objects instead.",WeakSet:"WeakSet is not available.",WeakMap:"WeakMap is not available.",Symbol:"Symbol is not available.",Proxy:"Proxy is not available.",Reflect:"Reflect is not available.",Function:"Function constructor is not available. Define functions normally.",eval:"eval is not available. Code is compiled, not evaluated.",setTimeout:"setTimeout is not available. Use the delay atom.",setInterval:"setInterval is not available. Use while loops with delay.",fetch:"fetch is not available. Use the httpFetch atom.",require:"require is not available. Atoms must be registered with the VM.",import:"import is not available. Atoms must be registered with the VM.",process:"process is not available. AsyncJS runs in a sandboxed environment.",window:"window is not available. AsyncJS runs in a sandboxed environment.",document:"document is not available. AsyncJS runs in a sandboxed environment.",global:"global is not available. AsyncJS runs in a sandboxed environment.",globalThis:"globalThis is not available. Use builtins directly."};function C1(X){if(X.callee.type==="Identifier"){let Y=X.callee.name;if(W0.has(Y))return A6[Y]||`${Y} is not available in AsyncJS.`}if(X.callee.type==="MemberExpression"){let Y=X.callee;if(Y.object.type==="Identifier"){let Z=Y.object.name;if(W0.has(Z))return A6[Z]||`${Z} is not available in AsyncJS.`}}return null}function B6(X){return{Date:" Use Date() or Date('2024-01-15') instead - no 'new' needed.",Set:" Use Set([items]) instead - no 'new' needed.",Map:" Use plain objects instead of Map.",Array:" Use array literals like [1, 2, 3] instead.",Object:" Use object literals like { key: value } instead.",Error:" Return an error object like { error: 'message' } instead.",RegExp:" Use string methods or the regexMatch atom.",Promise:" Not needed - all operations are implicitly async.",WeakSet:" WeakSet is not available.",WeakMap:" WeakMap is not available."}[X]||" Use factory functions or object literals instead."}function c(X,Y,Z,K){let H=K?"constSet":"varSet";if(X.type==="ChainExpression")return c(X.expression,Y,Z,K);if(X.type==="NewExpression"){let J=X,W="constructor";if(J.callee.type==="Identifier")W=J.callee.name;let z=B6(W);throw new V(`The 'new' keyword is not supported in AsyncJS.${z}`,C(X),Y.source,Y.filename)}if(X.type==="CallExpression"){let J=C1(X);if(J)throw new V(J,C(X),Y.source,Y.filename)}if(X.type==="CallExpression"&&T1(X)){let J=E(X,Y);if(Z)return{step:{op:H,key:Z,value:J},resultVar:Z};return{step:null,resultVar:J}}if(X.type==="MemberExpression"&&V1(X)){let J=E(X,Y);if(Z)return{step:{op:H,key:Z,value:J},resultVar:Z};return{step:null,resultVar:J}}if(X.type==="CallExpression")return N1(X,Y,Z,K);if(X.type==="TemplateLiteral")return k1(X,Y,Z,K);if(X.type==="BinaryExpression"||X.type==="LogicalExpression"||X.type==="UnaryExpression"){let J=E(X,Y);if(Z)return{step:{op:H,key:Z,value:J},resultVar:Z};return{step:null,resultVar:J}}return{step:null,resultVar:g(X,Y)}}function N1(X,Y,Z,K){let H,$=!1,J;if(X.callee.type==="Identifier")H=X.callee.name;else if(X.callee.type==="MemberExpression"){let z=X.callee;if(z.property.type==="Identifier")H=z.property.name,$=!0,J=g(z.object,Y);else throw new V("Computed method names are not supported",C(X),Y.source,Y.filename)}else throw new V("Only named function calls are supported",C(X),Y.source,Y.filename);if($)return S1(H,J,X.arguments,Y,Z,K);if(H==="console"&&X.callee.type==="MemberExpression");let W=g1(X,Y);return{step:{op:H,...W,...Z&&{result:Z},...Z&&K&&{resultConst:!0}},resultVar:Z}}function S1(X,Y,Z,K,H,$){switch(X){case"map":if(Z.length>0&&(Z[0].type==="ArrowFunctionExpression"||Z[0].type==="FunctionExpression")){let J=Z[0],W=J.params[0],z=W?.type==="Identifier"?W.name:"item",Q=v(K);Q.locals.set(z,{kind:"any"});let _;if(J.body.type==="BlockStatement")_=h(J.body,Q);else{let{step:U,resultVar:G}=c(J.body,Q,"result");_=U?[U]:[{op:"varSet",key:"result",value:G}]}return{step:{op:"map",items:Y,as:z,steps:_,...H&&{result:H},...H&&$&&{resultConst:!0}},resultVar:H}}break;case"filter":if(Z.length>0&&(Z[0].type==="ArrowFunctionExpression"||Z[0].type==="FunctionExpression")){let J=Z[0],W=J.params[0],z=W?.type==="Identifier"?W.name:"item",Q=v(K);Q.locals.set(z,{kind:"any"});let _;if(J.body.type==="BlockStatement")throw new V("filter callback must be an expression, not a block",C(Z[0]),K.source,K.filename);else _=E(J.body,Q);return{step:{op:"filter",items:Y,as:z,condition:_,...H&&{result:H},...H&&$&&{resultConst:!0}},resultVar:H}}break;case"find":if(Z.length>0&&(Z[0].type==="ArrowFunctionExpression"||Z[0].type==="FunctionExpression")){let J=Z[0],W=J.params[0],z=W?.type==="Identifier"?W.name:"item",Q=v(K);Q.locals.set(z,{kind:"any"});let _;if(J.body.type==="BlockStatement")throw new V("find callback must be an expression, not a block",C(Z[0]),K.source,K.filename);else _=E(J.body,Q);return{step:{op:"find",items:Y,as:z,condition:_,...H&&{result:H},...H&&$&&{resultConst:!0}},resultVar:H}}break;case"reduce":if(Z.length>=2&&(Z[0].type==="ArrowFunctionExpression"||Z[0].type==="FunctionExpression")){let J=Z[0],W=J.params[0],z=J.params[1],Q=W?.type==="Identifier"?W.name:"acc",_=z?.type==="Identifier"?z.name:"item",U=v(K);U.locals.set(Q,{kind:"any"}),U.locals.set(_,{kind:"any"});let G;if(J.body.type==="BlockStatement")G=h(J.body,U);else{let{step:D,resultVar:A}=c(J.body,U,"result");G=D?[D]:[{op:"varSet",key:"result",value:A}]}let F=g(Z[1],K);return{step:{op:"reduce",items:Y,as:_,accumulator:Q,initial:F,steps:G,...H&&{result:H},...H&&$&&{resultConst:!0}},resultVar:H}}break;case"slice":break;case"push":return{step:{op:"push",list:Y,item:g(Z[0],K),...H&&{result:H},...H&&$&&{resultConst:!0}},resultVar:H};case"join":return{step:{op:"join",list:Y,sep:Z.length>0?g(Z[0],K):"",...H&&{result:H},...H&&$&&{resultConst:!0}},resultVar:H};case"split":return{step:{op:"split",str:Y,sep:Z.length>0?g(Z[0],K):"",...H&&{result:H},...H&&$&&{resultConst:!0}},resultVar:H}}return K.warnings.push({message:`Unknown method '${X}' - treating as atom call`,line:0,column:0}),{step:{op:X,receiver:Y,args:Z.map((J)=>g(J,K)),...H&&{result:H},...H&&$&&{resultConst:!0}},resultVar:H}}function k1(X,Y,Z,K){let H="",$={};for(let J=0;J<X.quasis.length;J++)if(H+=X.quasis[J].value.cooked||X.quasis[J].value.raw,J<X.expressions.length){let W=X.expressions[J],z=`_${J}`;$[z]=g(W,Y),H+=`{{${z}}}`}return{step:{op:"template",tmpl:H,vars:$,...Z&&{result:Z},...Z&&K&&{resultConst:!0}},resultVar:Z}}function E(X,Y){switch(X.type){case"Literal":return{$expr:"literal",value:X.value};case"Identifier":return{$expr:"ident",name:X.name};case"MemberExpression":{let Z=X,K=E(Z.object,Y),H=Z.optional===!0;if(Z.computed){let J=Z.property;if(J.type==="Literal")return{$expr:"member",object:K,property:String(J.value),computed:!0,...H&&{optional:!0}};throw new V("Computed member access with variables not yet supported",C(X),Y.source,Y.filename)}let $=Z.property.name;return{$expr:"member",object:K,property:$,...H&&{optional:!0}}}case"ChainExpression":return E(X.expression,Y);case"BinaryExpression":{let Z=X;return{$expr:"binary",op:Z.operator,left:E(Z.left,Y),right:E(Z.right,Y)}}case"LogicalExpression":{let Z=X;return{$expr:"logical",op:Z.operator,left:E(Z.left,Y),right:E(Z.right,Y)}}case"UnaryExpression":{let Z=X;return{$expr:"unary",op:Z.operator,argument:E(Z.argument,Y)}}case"ConditionalExpression":{let Z=X;return{$expr:"conditional",test:E(Z.test,Y),consequent:E(Z.consequent,Y),alternate:E(Z.alternate,Y)}}case"ArrayExpression":return{$expr:"array",elements:X.elements.filter((K)=>K!==null).map((K)=>E(K,Y))};case"ObjectExpression":{let Z=X,K=[];for(let H of Z.properties)if(H.type==="Property"){let $=H.key.type==="Identifier"?H.key.name:String(H.key.value);K.push({key:$,value:E(H.value,Y)})}return{$expr:"object",properties:K}}case"CallExpression":{let Z=X;if(Z.callee.type==="MemberExpression"){let K=Z.callee,H=K.property.type==="Identifier"?K.property.name:String(K.property.value),$=K.optional===!0||Z.optional===!0;return{$expr:"methodCall",object:E(K.object,Y),method:H,arguments:Z.arguments.map((J)=>E(J,Y)),...$&&{optional:!0}}}if(Z.callee.type==="Identifier")return{$expr:"call",callee:Z.callee.name,arguments:Z.arguments.map((H)=>E(H,Y))};throw new V("Complex function calls in expressions should be lifted to statements",C(X),Y.source,Y.filename)}case"NewExpression":{let Z=X,K="constructor";if(Z.callee.type==="Identifier")K=Z.callee.name;let H=B6(K);throw new V(`The 'new' keyword is not supported in AsyncJS.${H}`,C(X),Y.source,Y.filename)}case"TemplateLiteral":throw new V("Template literals inside expressions are not supported. Assign to a variable first: const msg = `hello ${name}`; then use msg",C(X),Y.source,Y.filename);default:throw new V(`Unsupported expression type in condition: ${X.type}`,C(X),Y.source,Y.filename)}}function g(X,Y){switch(X.type){case"Literal":return X.value;case"Identifier":return X.name;case"MemberExpression":{let Z=X;if(Z.optional===!0)return E(X,Y);let H=g(Z.object,Y);if(H&&typeof H==="object"&&H.$expr){let J=Z.computed?String(Z.property.value):Z.property.name;return{$expr:"member",object:H,property:J,...Z.computed&&{computed:!0}}}if(Z.computed)return`${H}[${g(Z.property,Y)}]`;let $=Z.property.name;if(typeof H==="string")return`${H}.${$}`;if(H&&H.$kind==="arg")return{$kind:"arg",path:`${H.path}.${$}`};return`${H}.${$}`}case"ChainExpression":return g(X.expression,Y);case"ArrayExpression":return X.elements.map((Z)=>Z?g(Z,Y):null);case"ObjectExpression":{let Z={};for(let K of X.properties)if(K.type==="Property"){let H=K.key.type==="Identifier"?K.key.name:String(K.key.value);Z[H]=g(K.value,Y)}return Z}case"TemplateLiteral":return E(X,Y);case"CallExpression":return E(X,Y);case"BinaryExpression":case"LogicalExpression":case"UnaryExpression":case"ConditionalExpression":return E(X,Y);default:return null}}function g1(X,Y){if(X.arguments.length===1&&X.arguments[0].type==="ObjectExpression"){let Z=X.arguments[0],K={};for(let H of Z.properties)if(H.type==="Property"){let $=H.key.type==="Identifier"?H.key.name:String(H.key.value);K[$]=g(H.value,Y)}return K}return{args:X.arguments.map((Z)=>g(Z,Y))}}function w0(X,Y={}){let{ast:Z,returnType:K,originalSource:H,requiredParams:$}=o(X,{filename:Y.filename,colonShorthand:!0,vmTarget:!0}),J=U6(Z,Y.filename),{ast:W,signature:z,warnings:Q}=N0(J,H,K,Y,$);return{ast:W,signature:z,warnings:Q}}function b1(X,...Y){if(typeof X==="string")return w0(X).ast;let Z=X.reduce((K,H,$)=>K+H+(Y[$]!==void 0?String(Y[$]):""),"");return w0(Z).ast}function v1(X,Y,Z){let{ast:K,signature:H}=w0(X),$=async(J)=>{return(await Y.run(K,J,Z)).result};return $.signature=H,$.ast=K,$}function f1(X){return Object.entries(X).map(([Y,Z])=>{let K=Z.signature,H={},$=[];for(let[J,W]of Object.entries(K.parameters)){if(H[J]=W.schema||{type:"any"},W.description)H[J].description=W.description;if(W.required)$.push(J)}return{type:"function",function:{name:Y,description:K.description,parameters:{type:"object",properties:H,required:$}}}})}import{parseExpressionAt as m1}from"acorn";function y1(X,Y){let Z=Y;while(Z>0&&X[Z-1]!==`
|
|
14
|
+
`)Z--;if(X.slice(Z,Y).includes("//"))return!0;let H=0,$=!1;while(H<Y)if(!$&&X.slice(H,H+2)==="/*")$=!0,H+=2;else if($&&X.slice(H,H+2)==="*/")$=!1,H+=2;else H++;return $}function x1(X){let Y=[],Z=/\/\*test\s+(['"`])([^'"`]*)\1\s*\{([\s\S]*?)\}\s*\*\/|\/\*test\s*\{([\s\S]*?)\}\s*\*\//g,K;while((K=Z.exec(X))!==null){let H=K[2]||`embedded test ${Y.length+1}`,$=(K[3]||K[4]||"").trim();Y.push({description:H,body:$,line:S0(X,K.index)})}return Y}function k0(X){let Y=[],Z=[],K=x1(X);Y.push(...K);let H=/test\s+(['"`])([^'"`]*)\1\s*\{|test\s*\(\s*(['"`])([^'"`]*)\3\s*\)\s*\{|test\s*\{/g,$=/mock\s*\{/g,J=X,W,z=[];while((W=H.exec(X))!==null){let G=W.index;if(y1(X,G))continue;let F=W[2]||W[4]||`test ${Y.length+1}`,D=W.index+W[0].length,A=w6(X,D-1);if(A===-1)continue;let w=X.slice(D,A).trim();Y.push({description:F,body:w,line:S0(X,G)}),z.push({start:G,end:A+1,desc:F})}let Q=[];while((W=$.exec(X))!==null){let G=W.index,F=W.index+W[0].length,D=w6(X,F-1);if(D===-1)continue;let A=X.slice(F,D).trim();Z.push({body:A,line:S0(X,G)}),Q.push({start:G,end:D+1})}let _=[...z,...Q].sort((G,F)=>F.start-G.start);for(let G of _)J=J.slice(0,G.start)+J.slice(G.end);J=J.replace(/\n\s*\n\s*\n/g,`
|
|
15
|
+
|
|
16
|
+
`).trim();let U=h1(Y,Z);return{code:J,tests:Y,mocks:Z,testRunner:U}}function w6(X,Y){let Z=0,K=null,H=!1;for(let $=Y;$<X.length;$++){let J=X[$];if(H){H=!1;continue}if(J==="\\"){H=!0;continue}if(!K&&(J==='"'||J==="'"||J==="`")){K=J;continue}if(K===J){K=null;continue}if(K)continue;if(J==="{")Z++;if(J==="}"){if(Z--,Z===0)return $}}return-1}function S0(X,Y){return X.slice(0,Y).split(`
|
|
17
|
+
`).length}function h1(X,Y){if(X.length===0)return"// No tests defined";let Z=Y.map((H)=>H.body).join(`
|
|
18
|
+
`);return`(async () => {
|
|
19
|
+
const __results = []
|
|
20
|
+
|
|
21
|
+
${X.map((H,$)=>`
|
|
22
|
+
// Test ${$+1}: ${H.description}
|
|
23
|
+
try {
|
|
24
|
+
${Z}
|
|
25
|
+
await (async () => {
|
|
26
|
+
${H.body}
|
|
27
|
+
})()
|
|
28
|
+
__results.push({ description: ${JSON.stringify(H.description)}, passed: true })
|
|
29
|
+
} catch (__e) {
|
|
30
|
+
__results.push({ description: ${JSON.stringify(H.description)}, passed: false, error: __e.message })
|
|
31
|
+
}`).join(`
|
|
32
|
+
`)}
|
|
33
|
+
|
|
34
|
+
// Report results
|
|
35
|
+
const __passed = __results.filter(r => r.passed).length
|
|
36
|
+
const __failed = __results.filter(r => !r.passed).length
|
|
37
|
+
console.log(\`Tests: \${__passed} passed, \${__failed} failed\`)
|
|
38
|
+
__results.filter(r => !r.passed).forEach(r => {
|
|
39
|
+
console.log(\` ✗ \${r.description}: \${r.error}\`)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// Return summary
|
|
43
|
+
return { passed: __passed, failed: __failed, results: __results }
|
|
44
|
+
})()`.trim()}var L6=`
|
|
45
|
+
function assert(condition, message) {
|
|
46
|
+
if (!condition) {
|
|
47
|
+
throw new Error(message || 'Assertion failed')
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
`,I6=`
|
|
51
|
+
function expect(actual) {
|
|
52
|
+
const deepEqual = (a, b) => {
|
|
53
|
+
if (a === b) return true
|
|
54
|
+
if (a === null || b === null) return a === b
|
|
55
|
+
if (a === undefined || b === undefined) return a === undefined && b === undefined
|
|
56
|
+
if (typeof a !== typeof b) return false
|
|
57
|
+
if (typeof a !== 'object') return a === b
|
|
58
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false
|
|
59
|
+
if (Array.isArray(a)) {
|
|
60
|
+
if (a.length !== b.length) return false
|
|
61
|
+
return a.every((v, i) => deepEqual(v, b[i]))
|
|
62
|
+
}
|
|
63
|
+
const keysA = Object.keys(a)
|
|
64
|
+
const keysB = Object.keys(b)
|
|
65
|
+
if (keysA.length !== keysB.length) return false
|
|
66
|
+
return keysA.every(k => deepEqual(a[k], b[k]))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const format = (v) => {
|
|
70
|
+
if (v === null) return 'null'
|
|
71
|
+
if (v === undefined) return 'undefined'
|
|
72
|
+
if (typeof v === 'string') return JSON.stringify(v)
|
|
73
|
+
if (typeof v === 'object') return JSON.stringify(v)
|
|
74
|
+
return String(v)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
toBe(expected) {
|
|
79
|
+
if (!deepEqual(actual, expected)) {
|
|
80
|
+
throw new Error(\`Expected \${format(expected)} but got \${format(actual)}\`)
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
toEqual(expected) {
|
|
84
|
+
if (!deepEqual(actual, expected)) {
|
|
85
|
+
throw new Error(\`Expected \${format(expected)} but got \${format(actual)}\`)
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
toContain(item) {
|
|
89
|
+
if (!Array.isArray(actual) || !actual.some(v => deepEqual(v, item))) {
|
|
90
|
+
throw new Error(\`Expected \${format(actual)} to contain \${format(item)}\`)
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
toThrow(message) {
|
|
94
|
+
let threw = false
|
|
95
|
+
let thrownMessage = ''
|
|
96
|
+
try {
|
|
97
|
+
if (typeof actual === 'function') actual()
|
|
98
|
+
} catch (e) {
|
|
99
|
+
threw = true
|
|
100
|
+
thrownMessage = e.message || String(e)
|
|
101
|
+
}
|
|
102
|
+
if (!threw) {
|
|
103
|
+
throw new Error('Expected function to throw but it did not')
|
|
104
|
+
}
|
|
105
|
+
if (message && !thrownMessage.includes(message)) {
|
|
106
|
+
throw new Error(\`Expected error containing "\${message}" but got "\${thrownMessage}"\`)
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
toBeTruthy() {
|
|
110
|
+
if (!actual) {
|
|
111
|
+
throw new Error(\`Expected \${format(actual)} to be truthy\`)
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
toBeFalsy() {
|
|
115
|
+
if (actual) {
|
|
116
|
+
throw new Error(\`Expected \${format(actual)} to be falsy\`)
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
toBeNull() {
|
|
120
|
+
if (actual !== null) {
|
|
121
|
+
throw new Error(\`Expected null but got \${format(actual)}\`)
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
toBeUndefined() {
|
|
125
|
+
if (actual !== undefined) {
|
|
126
|
+
throw new Error(\`Expected undefined but got \${format(actual)}\`)
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
toBeGreaterThan(n) {
|
|
130
|
+
if (!(actual > n)) {
|
|
131
|
+
throw new Error(\`Expected \${format(actual)} to be greater than \${n}\`)
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
toBeLessThan(n) {
|
|
135
|
+
if (!(actual < n)) {
|
|
136
|
+
throw new Error(\`Expected \${format(actual)} to be less than \${n}\`)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
`,d1=L6+`
|
|
142
|
+
`+I6;function l1(X,Y,Z,K){let H=[],$=J0(Y,X),J={},W=!1,z,Q;if(X.params.length===1&&(X.params[0].type==="ObjectPattern"||X.params[0].type==="AssignmentPattern"&&X.params[0].left.type==="ObjectPattern")){W=!0;let G=X.params[0],F=G.type==="ObjectPattern"?G:G.left,D=n(F,Z);if(D.type.kind==="object"&&D.type.destructuredParams){z={},Q=new Set;for(let[A,w]of Object.entries(D.type.destructuredParams))if(J[A]={...w,description:$.params[A]},z[A]=w.type,w.required)Q.add(A)}}else for(let G of X.params)if(G.type==="Identifier"){let F=n(G,Z);J[G.name]={...F,required:Z.has(G.name),description:$.params[G.name]}}else if(G.type==="AssignmentPattern"&&G.left.type==="Identifier"){let F=n(G,Z);J[G.left.name]={...F,required:Z.has(G.left.name),description:$.params[G.left.name]}}else if(G.type==="ObjectPattern"){let F=n(G,Z);if(F.type.kind==="object"&&F.type.destructuredParams)for(let[D,A]of Object.entries(F.type.destructuredParams))J[D]={...A,description:$.params[D]}}let _;if(K)try{let G=m1(K,0,{ecmaVersion:2022});_=f(G)}catch{_={kind:"any"},H.push(`Could not parse return type: ${K}`)}return{types:{name:X.id?.name||"anonymous",params:J,returns:_,description:$.description,isDestructuredParam:W,destructuredShape:z,destructuredRequired:Q},warnings:H}}function p1(X,Y,Z){let K=[],H=Z?`${Z}:`:"",$=Z?`${Z}:${X}`:X;if(K.push(`__tjs.pushStack('${$}');`),Y.isDestructuredParam&&Y.destructuredShape){let W=Y.destructuredShape,z=Y.destructuredRequired||new Set,Q=Object.keys(W);if(Q.length===0)return null;for(let _ of Q)K.push(`if (${_} instanceof Error) return ${_};`);for(let[_,U]of Object.entries(W)){let G=z.has(_),F=`${H}${X}.${_}`,D=R6(_,U);if(D){let A=U.kind;if(G)K.push(`if (${D}) return __tjs.typeError('${F}', '${A}', ${_});`);else K.push(`if (${_} !== undefined && ${D}) return __tjs.typeError('${F}', '${A}', ${_});`)}}return K.length>0?K.join(`
|
|
143
|
+
`):null}let J=Object.entries(Y.params);if(J.length===0)return null;for(let[W]of J)K.push(`if (${W} instanceof Error) return ${W};`);for(let[W,z]of J){let Q=`${H}${X}.${W}`,_=R6(W,z.type);if(_){let U=z.type.kind;if(z.required)K.push(`if (${_}) return __tjs.typeError('${Q}', '${U}', ${W});`);else K.push(`if (${W} !== undefined && ${_}) return __tjs.typeError('${Q}', '${U}', ${W});`)}}return K.length>0?K.join(`
|
|
144
|
+
`):null}function u1(X,Y){let K=new RegExp(`function\\s+${Y}\\s*\\([^)]*\\)\\s*(-[>?!])\\s*`,"g").exec(X);if(!K)return null;let H=X.slice(K.index+K[0].length);return M6(H)}function i1(X,Y){let K=new RegExp(`function\\s+${Y}\\s*\\([^)]*\\)\\s*-([>?!])`,"g").exec(X);if(!K)return;let H=K[1];if(H==="?")return"safe";if(H==="!")return"unsafe";return}function n1(X){let Y=X.match(/^\/\*\s*tjs\s*<-\s*([^*]+?)\s*\*\//);return Y?Y[1].trim():void 0}function o1(X,Y){let Z=new RegExp(`\\/\\*\\s*line\\s+(\\d+)\\s*\\*\\/\\s*(?:async\\s+)?function\\s+${Y}\\s*\\(`,"m"),K=X.match(Z);return K?parseInt(K[1],10):void 0}function c1(X,Y={}){let{filename:Z="<source>",runTests:K=!0,debug:H=!1,resolvedImports:$={}}=Y,J=[],z=n1(X)||Z,{code:Q,tests:_,mocks:U,testRunner:G}=k0(X),{ast:F,originalSource:D,requiredParams:A,unsafeFunctions:w}=o(Q,{filename:Z,colonShorthand:!0}),B=s1(F),R=A0(Q),O={},L=[];for(let M of B){let T=M.id?.name||"anonymous",y=u1(Q,T),{types:x,warnings:j0}=l1(M,D,A,y);J.push(...j0),O[T]=x;let Q6=R.moduleSafety==="none"||w.has(T),l6=R.safeFunctions.has(T),p6=i1(Q,T),u6=o1(X,T),E0={file:z,line:u6??M.loc?.start.line??0,column:M.loc?.start.column??0},i6=a1(T,x,{unsafe:Q6,safe:l6,returnSafety:p6},{debug:H,source:E0});if(L.push({position:M.end,text:`
|
|
145
|
+
${i6}`}),!Q6){let n6=`${E0.file}:${E0.line}`,z6=p1(T,x,n6);if(z6&&M.body&&M.body.start!==void 0)L.push({position:M.body.start+1,text:`
|
|
146
|
+
${z6}
|
|
147
|
+
`})}}L.sort((M,T)=>T.position-M.position);let I=R.source;for(let{position:M,text:T}of L)I=I.slice(0,M)+T+I.slice(M);let P=I.includes("__tjs.typeError("),N=I.includes("Is("),j=I.includes("IsNot(");if(P||N||j){let M=`const __tjs = globalThis.__tjs?.createRuntime?.() ?? globalThis.__tjs;
|
|
148
|
+
`;if(N||j){let T=[N&&"Is",j&&"IsNot"].filter(Boolean).join(", ");M+=`const { ${T} } = __tjs ?? {};
|
|
149
|
+
`}I=M+I}let S;if(K){if(S=[],_.length>0){let y=e1(_,U,I,$);S.push(...y)}let M=X5(X,I,$);S.push(...M);let T=S.filter((y)=>!y.passed);if(T.length>0&&K===!0){let y=T.map((x)=>{if(x.isSignatureTest)return` Function signature example is inconsistent:
|
|
150
|
+
${x.error}`;return` Test '${x.description}' failed:
|
|
151
|
+
${x.error}`});throw Error(`Transpile-time test failures:
|
|
152
|
+
${y.join(`
|
|
153
|
+
`)}`)}}if(K==="only")return{code:"",types:O,metadata:O,testResults:S,testCount:S?.length};return{code:I,types:O,metadata:O,warnings:J.length>0?J:void 0,testRunner:_.length>0?G:void 0,testCount:_.length>0?_.length:void 0,testResults:S}}function s1(X){let Y=[];for(let Z of X.body)if(Z.type==="FunctionDeclaration")Y.push(Z);else if(Z.type==="ExportNamedDeclaration"&&Z.declaration?.type==="FunctionDeclaration")Y.push(Z.declaration);else if(Z.type==="ExportDefaultDeclaration"&&Z.declaration?.type==="FunctionDeclaration")Y.push(Z.declaration);return Y}function Q0(X){let Y={kind:X.kind};if(X.nullable)Y.nullable=!0;if(X.items)Y.items=Q0(X.items);if(X.shape)Y.shape=Object.fromEntries(Object.entries(X.shape).map(([Z,K])=>[Z,Q0(K)]));if(X.members)Y.members=X.members.map(Q0);return Y}function a1(X,Y,Z={},K={}){let H={};for(let[J,W]of Object.entries(Y.params)){if(H[J]={type:Q0(W.type),required:W.required},W.default!==void 0)H[J].default=W.default;if(W.description)H[J].description=W.description}let $={params:H};if(Y.returns){if($.returns={type:Q0(Y.returns)},Z.returnSafety==="safe")$.safeReturn=!0;else if(Z.returnSafety==="unsafe")$.unsafeReturn=!0}if(Y.description)$.description=Y.description;if(Z.unsafe)$.unsafe=!0;if(Z.safe)$.safe=!0;if(K.source){let{file:J,line:W}=K.source;$.source=`${J}:${W}`}return`${X}.__tjs = ${JSON.stringify($,null,2)}`}function R6(X,Y){switch(Y.kind){case"string":return`typeof ${X} !== 'string'`;case"number":return`typeof ${X} !== 'number'`;case"boolean":return`typeof ${X} !== 'boolean'`;case"null":return`${X} !== null`;case"undefined":return`${X} !== undefined`;case"array":return`!Array.isArray(${X})`;case"object":return`(typeof ${X} !== 'object' || ${X} === null || Array.isArray(${X}))`;case"any":return null;default:return null}}function t1(X,Y,Z=0.000000001){if(X===Y)return!0;if(typeof X==="number"&&typeof Y==="number"){if(!Number.isInteger(X)||!Number.isInteger(Y)){let K=Math.abs(X-Y),H=Math.max(Math.abs(X),Math.abs(Y),1);return K/H<Z}}return!1}function g0(X,Y){if(X===Y)return!0;if(t1(X,Y))return!0;if(X===null||Y===null)return X===Y;if(X===void 0||Y===void 0)return X===Y;if(typeof X!==typeof Y)return!1;if(typeof X!=="object")return!1;if(Array.isArray(X)&&Array.isArray(Y)){if(X.length!==Y.length)return!1;return X.every((H,$)=>g0(H,Y[$]))}if(Array.isArray(X)!==Array.isArray(Y))return!1;let Z=Object.keys(X),K=Object.keys(Y);if(Z.length!==K.length)return!1;return Z.every((H)=>g0(X[H],Y[H]))}function b0(X,Y,Z=""){if(Y===null){if(X===null)return{matches:!0};return{matches:!1,error:`Expected null at '${Z}', got ${s(X)}`}}if(Y===void 0){if(X===void 0)return{matches:!0};return{matches:!1,error:`Expected undefined at '${Z}', got ${s(X)}`}}if(typeof Y==="number"){if(typeof X==="number")return{matches:!0};return{matches:!1,error:`Expected number at '${Z}', got ${s(X)}`}}if(typeof Y==="string"){if(typeof X==="string")return{matches:!0};return{matches:!1,error:`Expected string at '${Z}', got ${s(X)}`}}if(typeof Y==="boolean"){if(typeof X==="boolean")return{matches:!0};return{matches:!1,error:`Expected boolean at '${Z}', got ${s(X)}`}}if(Array.isArray(Y)){if(!Array.isArray(X))return{matches:!1,error:`Expected array at '${Z}', got ${s(X)}`};if(Y.length===0)return{matches:!0};let K=Y[0];for(let H=0;H<X.length;H++){let $=b0(X[H],K,`${Z}[${H}]`);if(!$.matches)return $}return{matches:!0}}if(typeof Y==="object"&&Y!==null){if(typeof X!=="object"||X===null||Array.isArray(X))return{matches:!1,error:`Expected object at '${Z}', got ${s(X)}`};for(let K of Object.keys(Y)){let H=Z?`${Z}.${K}`:K;if(!(K in X))return{matches:!1,error:`Missing property '${H}'`};let $=b0(X[K],Y[K],H);if(!$.matches)return $}return{matches:!0}}if(X===Y)return{matches:!0};return{matches:!1,error:`Type mismatch at '${Z}'`}}function s(X){if(X===null)return"null";if(X===void 0)return"undefined";if(Array.isArray(X))return"array";return typeof X}function Z0(X,Y=0){if(X===null)return"null";if(X===void 0)return"undefined";if(typeof X==="string")return JSON.stringify(X);if(typeof X==="number")return String(X);if(typeof X==="boolean")return String(X);if(Array.isArray(X)){if(X.length===0)return"[]";if(X.length<=3)return`[${X.map((Z)=>Z0(Z,Y)).join(", ")}]`;return`[${X.slice(0,3).map((Z)=>Z0(Z,Y)).join(", ")}, ...]`}if(typeof X==="object"){let Z=Object.entries(X);if(Z.length===0)return"{}";let K=(z)=>/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(z)?z:JSON.stringify(z);if(Z.length<=2)return`{${Z.map(([Q,_])=>`${K(Q)}: ${Z0(_,Y)}`).join(", ")}}`;let H=" ".repeat(Y+1),$=" ".repeat(Y),J=Z.slice(0,8).map(([z,Q])=>`${H}${K(z)}: ${Z0(Q,Y+1)}`).join(`,
|
|
154
|
+
`),W=Z.length>8?`,
|
|
155
|
+
${H}...`:"";return`{
|
|
156
|
+
${J}${W}
|
|
157
|
+
${$}}`}return String(X)}function r1(X){let Y=X.replace(/\/\*[\s\S]*?\*\//g,(Z)=>{let K=Z.split(`
|
|
158
|
+
`).length-1;return`
|
|
159
|
+
`.repeat(K)});return Y=Y.replace(/\/\/[^\n]*/g,""),Y}function v0(X){let Y=X.replace(/^import\s+.*?from\s+['"][^'"]+['"];?\s*$/gm,"");return Y=Y.replace(/^import\s+['"][^'"]+['"];?\s*$/gm,""),Y=Y.replace(/^export\s+default\s+/gm,""),Y=Y.replace(/^export\s+/gm,""),Y}function f0(X){let Y=X.replace(/^const __tjs = globalThis\.__tjs\?\.createRuntime\?\.\(\) \?\? globalThis\.__tjs;\n?/m,"");return Y=Y.replace(/^const \{ (?:Is|IsNot|Is, IsNot) \} = __tjs \?\? \{\};\n?/m,""),Y}function O6(X){if(Object.keys(X).length===0)return"";let Y=[];for(let[Z,K]of Object.entries(X)){let H=v0(K);H=f0(H),Y.push(`// Resolved import: ${Z}`),Y.push(H)}return Y.join(`
|
|
160
|
+
`)}function e1(X,Y,Z,K={}){let H=[],$=v0(Z);$=f0($);let J=O6(K),W=Y.map((z)=>z.body).join(`
|
|
161
|
+
`);for(let z of X)try{let U=`
|
|
162
|
+
|
|
163
|
+
const __saved_tjs = globalThis.__tjs;
|
|
164
|
+
const __stub_tjs = { version: '0.0.0', pushStack: () => {}, typeError: (path, expected, value) => new Error(\`Type error at \${path}: expected \${expected}\`), createRuntime: function() { return this; } };
|
|
165
|
+
globalThis.__tjs = __stub_tjs;
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
// Inject resolved imports first (they may be dependencies)
|
|
169
|
+
${J}
|
|
170
|
+
${$}
|
|
171
|
+
${W}
|
|
172
|
+
|
|
173
|
+
// Test assertions
|
|
174
|
+
function assert(condition, message) {
|
|
175
|
+
if (!condition) throw new Error(message || 'Assertion failed')
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function expect(actual) {
|
|
179
|
+
return {
|
|
180
|
+
toBe(expected) {
|
|
181
|
+
if (!__deepEqual(actual, expected)) {
|
|
182
|
+
throw new Error('Expected ' + __format(expected) + ' but got ' + __format(actual))
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
toEqual(expected) {
|
|
186
|
+
if (!__deepEqual(actual, expected)) {
|
|
187
|
+
throw new Error('Expected ' + __format(expected) + ' but got ' + __format(actual))
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Run the test body
|
|
194
|
+
${z.body}
|
|
195
|
+
} finally {
|
|
196
|
+
globalThis.__tjs = __saved_tjs;
|
|
197
|
+
}
|
|
198
|
+
`;Function("__deepEqual","__format",U)(g0,Z0),H.push({description:z.description,passed:!0,line:z.line})}catch(Q){H.push({description:z.description,passed:!1,error:Q.message||String(Q),line:z.line})}return H}function X5(X,Y,Z={}){let K=[],H=r1(X),$=/function\s+(\w+)\s*\(([^)]*)\)\s*(-[>?])\s*/g,J;while((J=$.exec(H))!==null){let W=J[1],z=J[2],Q=J[3],_=H.slice(0,J.index).split(`
|
|
199
|
+
`).length;if(Q==="-!")continue;let U=H.slice(J.index+J[0].length),G=M6(U);if(!G)continue;let F=Z5(z);if(z.trim()&&F.length===0)continue;try{let A=Function(`return ${G}`)(),w=F.map((R)=>Function(`return ${R}`)()),B=K5(W,Y,w,A,Z);B.line=_,K.push(B)}catch(D){K.push({description:`${W} signature example`,passed:!1,error:`Failed to parse signature: ${D.message}`,isSignatureTest:!0,line:_})}}return K}function M6(X){let Y="",Z=0,K=!1;for(let $=0;$<X.length;$++){let J=X[$];if(J==="{"||J==="["||J==="("){if(J==="{"&&Z===0&&K)break;Z++,Y+=J,K=!0}else if(J==="}"||J==="]"||J===")")Z--,Y+=J;else if(!/\s/.test(J))Y+=J,K=!0;else Y+=J}return Y.trim()||null}function Z5(X){if(!X.trim())return[];let Y=[],Z=Y5(X);for(let K of Z){let H=K.match(/(?:\(\s*[?!]\s*)?(\w+)\s*[:=]\s*(.+?)(?:\))?$/);if(H)Y.push(H[2].trim());else return[]}return Y}function Y5(X){let Y=[],Z="",K=0;for(let H of X){if(H==="("||H==="["||H==="{")K++;else if(H===")"||H==="]"||H==="}")K--;else if(H===","&&K===0){Y.push(Z.trim()),Z="";continue}Z+=H}if(Z.trim())Y.push(Z.trim());return Y}function K5(X,Y,Z,K,H={}){let $=`${X} signature example`,J=v0(Y);J=f0(J);let W=O6(H);try{let _=`
|
|
200
|
+
|
|
201
|
+
const __saved_tjs = globalThis.__tjs;
|
|
202
|
+
const __stub_tjs = { version: '0.0.0', pushStack: () => {}, typeError: (path, expected, value) => new Error(\`Type error at \${path}: expected \${expected}\`), createRuntime: function() { return this; } };
|
|
203
|
+
globalThis.__tjs = __stub_tjs;
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
// Inject resolved imports first (they may be dependencies)
|
|
207
|
+
${W}
|
|
208
|
+
${J}
|
|
209
|
+
return ${X}(${Z.map((D)=>JSON.stringify(D)).join(", ")})
|
|
210
|
+
} finally {
|
|
211
|
+
globalThis.__tjs = __saved_tjs;
|
|
212
|
+
}
|
|
213
|
+
`,G=Function(_)(),F=b0(G,K,X);if(!F.matches)return{description:$,passed:!1,error:F.error||`Type mismatch: got ${Z0(G)}`,isSignatureTest:!0};return{description:$,passed:!0,isSignatureTest:!0}}catch(z){return{description:$,passed:!1,error:z.message||String(z),isSignatureTest:!0}}}import{s as P6}from"tosijs-schema";function j6(X){if(X===null)return"null";if(X===void 0)return"undefined";if(Array.isArray(X))return"array";return typeof X}function L0(X){return P6.infer(X)}function y0(X){return L0(X)}y0.type=j6;y0.infer=L0;var H5=new Proxy(y0,{get(X,Y){if(Y==="type")return j6;if(Y==="infer")return L0;return P6[Y]},apply(X,Y,Z){return L0(Z[0])}});function I0(X,Y,Z,K,H){if(!Z)Z=q;(function $(J,W,z){var Q=z||J.type;if(Z[Q](J,W,$),Y[Q])Y[Q](J,W)})(X,K,H)}function E6(X,Y,Z,K,H){var $=[];if(!Z)Z=q;(function J(W,z,Q){var _=Q||W.type,U=W!==$[$.length-1];if(U)$.push(W);if(Z[_](W,z,J),Y[_])Y[_](W,z||$,$);if(U)$.pop()})(X,K,H)}function x0(X,Y,Z){Z(X,Y)}function a(X,Y,Z){}var q={};q.Program=q.BlockStatement=q.StaticBlock=function(X,Y,Z){for(var K=0,H=X.body;K<H.length;K+=1){var $=H[K];Z($,Y,"Statement")}};q.Statement=x0;q.EmptyStatement=a;q.ExpressionStatement=q.ParenthesizedExpression=q.ChainExpression=function(X,Y,Z){return Z(X.expression,Y,"Expression")};q.IfStatement=function(X,Y,Z){if(Z(X.test,Y,"Expression"),Z(X.consequent,Y,"Statement"),X.alternate)Z(X.alternate,Y,"Statement")};q.LabeledStatement=function(X,Y,Z){return Z(X.body,Y,"Statement")};q.BreakStatement=q.ContinueStatement=a;q.WithStatement=function(X,Y,Z){Z(X.object,Y,"Expression"),Z(X.body,Y,"Statement")};q.SwitchStatement=function(X,Y,Z){Z(X.discriminant,Y,"Expression");for(var K=0,H=X.cases;K<H.length;K+=1){var $=H[K];Z($,Y)}};q.SwitchCase=function(X,Y,Z){if(X.test)Z(X.test,Y,"Expression");for(var K=0,H=X.consequent;K<H.length;K+=1){var $=H[K];Z($,Y,"Statement")}};q.ReturnStatement=q.YieldExpression=q.AwaitExpression=function(X,Y,Z){if(X.argument)Z(X.argument,Y,"Expression")};q.ThrowStatement=q.SpreadElement=function(X,Y,Z){return Z(X.argument,Y,"Expression")};q.TryStatement=function(X,Y,Z){if(Z(X.block,Y,"Statement"),X.handler)Z(X.handler,Y);if(X.finalizer)Z(X.finalizer,Y,"Statement")};q.CatchClause=function(X,Y,Z){if(X.param)Z(X.param,Y,"Pattern");Z(X.body,Y,"Statement")};q.WhileStatement=q.DoWhileStatement=function(X,Y,Z){Z(X.test,Y,"Expression"),Z(X.body,Y,"Statement")};q.ForStatement=function(X,Y,Z){if(X.init)Z(X.init,Y,"ForInit");if(X.test)Z(X.test,Y,"Expression");if(X.update)Z(X.update,Y,"Expression");Z(X.body,Y,"Statement")};q.ForInStatement=q.ForOfStatement=function(X,Y,Z){Z(X.left,Y,"ForInit"),Z(X.right,Y,"Expression"),Z(X.body,Y,"Statement")};q.ForInit=function(X,Y,Z){if(X.type==="VariableDeclaration")Z(X,Y);else Z(X,Y,"Expression")};q.DebuggerStatement=a;q.FunctionDeclaration=function(X,Y,Z){return Z(X,Y,"Function")};q.VariableDeclaration=function(X,Y,Z){for(var K=0,H=X.declarations;K<H.length;K+=1){var $=H[K];Z($,Y)}};q.VariableDeclarator=function(X,Y,Z){if(Z(X.id,Y,"Pattern"),X.init)Z(X.init,Y,"Expression")};q.Function=function(X,Y,Z){if(X.id)Z(X.id,Y,"Pattern");for(var K=0,H=X.params;K<H.length;K+=1){var $=H[K];Z($,Y,"Pattern")}Z(X.body,Y,X.expression?"Expression":"Statement")};q.Pattern=function(X,Y,Z){if(X.type==="Identifier")Z(X,Y,"VariablePattern");else if(X.type==="MemberExpression")Z(X,Y,"MemberPattern");else Z(X,Y)};q.VariablePattern=a;q.MemberPattern=x0;q.RestElement=function(X,Y,Z){return Z(X.argument,Y,"Pattern")};q.ArrayPattern=function(X,Y,Z){for(var K=0,H=X.elements;K<H.length;K+=1){var $=H[K];if($)Z($,Y,"Pattern")}};q.ObjectPattern=function(X,Y,Z){for(var K=0,H=X.properties;K<H.length;K+=1){var $=H[K];if($.type==="Property"){if($.computed)Z($.key,Y,"Expression");Z($.value,Y,"Pattern")}else if($.type==="RestElement")Z($.argument,Y,"Pattern")}};q.Expression=x0;q.ThisExpression=q.Super=q.MetaProperty=a;q.ArrayExpression=function(X,Y,Z){for(var K=0,H=X.elements;K<H.length;K+=1){var $=H[K];if($)Z($,Y,"Expression")}};q.ObjectExpression=function(X,Y,Z){for(var K=0,H=X.properties;K<H.length;K+=1){var $=H[K];Z($,Y)}};q.FunctionExpression=q.ArrowFunctionExpression=q.FunctionDeclaration;q.SequenceExpression=function(X,Y,Z){for(var K=0,H=X.expressions;K<H.length;K+=1){var $=H[K];Z($,Y,"Expression")}};q.TemplateLiteral=function(X,Y,Z){for(var K=0,H=X.quasis;K<H.length;K+=1){var $=H[K];Z($,Y)}for(var J=0,W=X.expressions;J<W.length;J+=1){var z=W[J];Z(z,Y,"Expression")}};q.TemplateElement=a;q.UnaryExpression=q.UpdateExpression=function(X,Y,Z){Z(X.argument,Y,"Expression")};q.BinaryExpression=q.LogicalExpression=function(X,Y,Z){Z(X.left,Y,"Expression"),Z(X.right,Y,"Expression")};q.AssignmentExpression=q.AssignmentPattern=function(X,Y,Z){Z(X.left,Y,"Pattern"),Z(X.right,Y,"Expression")};q.ConditionalExpression=function(X,Y,Z){Z(X.test,Y,"Expression"),Z(X.consequent,Y,"Expression"),Z(X.alternate,Y,"Expression")};q.NewExpression=q.CallExpression=function(X,Y,Z){if(Z(X.callee,Y,"Expression"),X.arguments)for(var K=0,H=X.arguments;K<H.length;K+=1){var $=H[K];Z($,Y,"Expression")}};q.MemberExpression=function(X,Y,Z){if(Z(X.object,Y,"Expression"),X.computed)Z(X.property,Y,"Expression")};q.ExportNamedDeclaration=q.ExportDefaultDeclaration=function(X,Y,Z){if(X.declaration)Z(X.declaration,Y,X.type==="ExportNamedDeclaration"||X.declaration.id?"Statement":"Expression");if(X.source)Z(X.source,Y,"Expression")};q.ExportAllDeclaration=function(X,Y,Z){if(X.exported)Z(X.exported,Y);Z(X.source,Y,"Expression")};q.ImportDeclaration=function(X,Y,Z){for(var K=0,H=X.specifiers;K<H.length;K+=1){var $=H[K];Z($,Y)}Z(X.source,Y,"Expression")};q.ImportExpression=function(X,Y,Z){Z(X.source,Y,"Expression")};q.ImportSpecifier=q.ImportDefaultSpecifier=q.ImportNamespaceSpecifier=q.Identifier=q.PrivateIdentifier=q.Literal=a;q.TaggedTemplateExpression=function(X,Y,Z){Z(X.tag,Y,"Expression"),Z(X.quasi,Y,"Expression")};q.ClassDeclaration=q.ClassExpression=function(X,Y,Z){return Z(X,Y,"Class")};q.Class=function(X,Y,Z){if(X.id)Z(X.id,Y,"Pattern");if(X.superClass)Z(X.superClass,Y,"Expression");Z(X.body,Y)};q.ClassBody=function(X,Y,Z){for(var K=0,H=X.body;K<H.length;K+=1){var $=H[K];Z($,Y)}};q.MethodDefinition=q.PropertyDefinition=q.Property=function(X,Y,Z){if(X.computed)Z(X.key,Y,"Expression");if(X.value)Z(X.value,Y,"Expression")};var $5={unusedVariables:!0,undefinedVariables:!0,unreachableCode:!0,noExplicitNew:!0};function W5(X,Y={}){let Z={...$5,...Y},K=[],H;try{H=o(X,{filename:Z.filename,colonShorthand:!0}).ast}catch(J){return{diagnostics:[{severity:"error",message:J.message,line:J.loc?.line,column:J.loc?.column,rule:"parse-error"}],valid:!1}}let $=[T6()];if(E6(H,{FunctionDeclaration(J,W,z){let Q=T6();$.push(Q);for(let _ of J.params)Q5(Q,_,"parameter");if(J.id)($[$.length-2]||$[0]).declarations.set(J.id.name,{node:J.id,kind:"function",used:!1})},VariableDeclaration(J){let W=$[$.length-1];for(let z of J.declarations)if(z.id.type==="Identifier")W.declarations.set(z.id.name,{node:z.id,kind:J.kind,used:!1})}}),I0(H,{Identifier(J){for(let W=$.length-1;W>=0;W--){let z=$[W].declarations.get(J.name);if(z){z.used=!0;break}}}}),Z.unusedVariables)for(let J of $)for(let[W,z]of J.declarations){if(W.startsWith("_"))continue;if(!z.used&&z.kind!=="function")K.push({severity:"warning",message:`'${W}' is declared but never used`,line:z.node.loc?.start?.line,column:z.node.loc?.start?.column,rule:"no-unused-vars"})}if(Z.unreachableCode)I0(H,{BlockStatement(J){let W=!1;for(let z of J.body){if(W){K.push({severity:"warning",message:"Unreachable code after return statement",line:z.loc?.start?.line,column:z.loc?.start?.column,rule:"no-unreachable"});break}if(z.type==="ReturnStatement")W=!0}}});if(Z.noExplicitNew)I0(H,{NewExpression(J){let W="class";if(J.callee.type==="Identifier")W=J.callee.name;else if(J.callee.type==="MemberExpression"){if(J.callee.property.type==="Identifier")W=J.callee.property.name}K.push({severity:"warning",message:`Unnecessary 'new' keyword. In TJS, classes are callable without 'new': ${W}(...) instead of new ${W}(...)`,line:J.loc?.start?.line,column:J.loc?.start?.column,rule:"no-explicit-new"})}});return{diagnostics:K,valid:K.filter((J)=>J.severity==="error").length===0}}function T6(){return{declarations:new Map}}function Q5(X,Y,Z){if(Y.type==="Identifier")X.declarations.set(Y.name,{node:Y,kind:Z,used:!1});else if(Y.type==="AssignmentPattern"&&Y.left.type==="Identifier")X.declarations.set(Y.left.name,{node:Y.left,kind:Z,used:!1})}import{validate as v6,s as M0}from"tosijs-schema";import{validate as h0,s as R0}from"tosijs-schema";function t(X){return X!==null&&typeof X==="object"&&"__runtimeType"in X&&X.__runtimeType===!0}function V6(X){return X!==null&&typeof X==="object"&&"schema"in X&&typeof X.schema==="object"}function z5(X){return X!==null&&typeof X==="object"&&"type"in X&&typeof X.type==="string"}function k(X,Y,Z,K){let H,$,J,W=Z,z=K;if(typeof X==="string")if(H=X,typeof Y==="function"){if($=Y,W!==void 0)J=R0.infer(W)}else if(Y===void 0&&W!==void 0)J=R0.infer(W);else if(V6(Y))J=Y;else if(z5(Y))J=Y;else if(Y!==void 0)W=Y,z=W,J=R0.infer(W);else throw Error("Type(description) requires a predicate, schema, or example");else{if(V6(X))J=X;else J=X;H=G5(J)}return{description:H,check:(_)=>{if($)return $(_);if(J)return h0(_,J);return!1},schema:J,predicate:$,example:W,default:z,__runtimeType:!0}}function G5(X){let Y=X?.schema??X;if(Y&&typeof Y==="object"&&"type"in Y){let Z=Y;switch(Z.type){case"string":if(Z.format)return`string (${Z.format})`;if(Z.pattern)return`string matching ${Z.pattern}`;if(Z.minLength!==void 0&&Z.maxLength!==void 0)return`string (${Z.minLength}-${Z.maxLength} chars)`;return"string";case"number":case"integer":if(Z.minimum!==void 0&&Z.maximum!==void 0)return`${Z.type} (${Z.minimum}-${Z.maximum})`;if(Z.minimum!==void 0)return`${Z.type} >= ${Z.minimum}`;if(Z.maximum!==void 0)return`${Z.type} <= ${Z.maximum}`;return Z.type;case"boolean":return"boolean";case"array":return"array";case"object":return"object";case"null":return"null"}}return"value"}var d0=k("string",(X)=>typeof X==="string"),m0=k("number",(X)=>typeof X==="number"),l0=k("boolean",(X)=>typeof X==="boolean"),p0=k("integer",(X)=>typeof X==="number"&&Number.isInteger(X)),u0=k("positive integer",(X)=>typeof X==="number"&&Number.isInteger(X)&&X>0),i0=k("non-empty string",(X)=>typeof X==="string"&&X.length>0),n0=k("email address",(X)=>typeof X==="string"&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(X)),C6=(X)=>{try{return new URL(X),!0}catch{return!1}},o0=k("URL",(X)=>typeof X==="string"&&C6(X)),c0=k("UUID",(X)=>typeof X==="string"&&/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(X)),N6=(X)=>{let Y=new Date(X);return!isNaN(Y.getTime())&&X.includes("T")},S6=(X)=>{if(!/^\d{4}-\d{2}-\d{2}$/.test(X))return!1;let Y=new Date(X+"T00:00:00Z");return!isNaN(Y.getTime())},k6=k("ISO 8601 timestamp",(X)=>typeof X==="string"&&N6(X)),g6=k("date (YYYY-MM-DD)",(X)=>typeof X==="string"&&S6(X));function s0(X){return k(`${X.description} or null`,(Y)=>Y===null||X.check(Y))}function a0(X){return k(`${X.description} (optional)`,(Y)=>Y===null||Y===void 0||X.check(Y))}function t0(X,Y,...Z){if(typeof X==="string"&&Array.isArray(Y)){let $=X,J=Y,W=new Set(J);return{description:$,check:(Q)=>W.has(Q),__runtimeType:!0,values:J}}let K=[];if(t(X))K.push(X);if(t(Y))K.push(Y);K.push(...Z);let H=K.map(($)=>$.description).join(" | ");return k(H,($)=>K.some((J)=>J.check($)))}function r0(X){return k(`array of ${X.description}`,(Y)=>Array.isArray(Y)&&Y.every((Z)=>X.check(Z)))}function _5(X){if(t(X))return(Z)=>X.check(Z);if(X&&typeof X==="object"&&"schema"in X)return(Z)=>h0(Z,X);let Y=R0.infer(X);return(Z)=>h0(Z,Y)}function z0(X,Y,Z){let K=[],H=[];for(let J of X)if(typeof J==="string")K.push(J),H.push(void 0);else K.push(J[0]),H.push(J[1]);let $=(...J)=>{let W=K.map((Q,_)=>{let U=_<J.length?J[_]:H[_];if(U===void 0)return()=>!0;return _5(U)}),z=Z;return K.forEach((Q,_)=>{let U=_<J.length?J[_]:H[_],G="any";if(t(U))G=U.description;else if(U!==void 0)G=typeof U==="string"?"string":JSON.stringify(U);z=z.replace(new RegExp(`\\b${Q}\\b`,"g"),G)}),k(z,(Q)=>Y(Q,...W))};return $.params=K,$.description=Z,$}var e0=z0(["T","U"],(X,Y,Z)=>Array.isArray(X)&&X.length===2&&Y(X[0])&&Z(X[1]),"Pair<T, U>"),X6=z0(["V"],(X,Y)=>typeof X==="object"&&X!==null&&!Array.isArray(X)&&Object.values(X).every(Y),"Record<string, V>");function Z6(X,Y){let Z=Object.values(Y),K=new Set(Z),H=Object.keys(Y),$={};for(let[W,z]of Object.entries(Y))$[z]=W;return{description:X,check:(W)=>K.has(W),__runtimeType:!0,members:Y,names:$,values:Z,keys:H}}var U5=b6(),m=U5.version;function P0(X){let[Y=0,Z=0,K=0]=X.split(".").map(Number);return{major:Y,minor:Z,patch:K}}function Y6(X,Y){let Z=P0(X),K=P0(Y);if(Z.major!==K.major)return Z.major<K.major?-1:1;if(Z.minor!==K.minor)return Z.minor<K.minor?-1:1;if(Z.patch!==K.patch)return Z.patch<K.patch?-1:1;return 0}function K6(X,Y){let Z=P0(X),K=P0(Y);return Z.major===K.major}class X0 extends Error{path;expected;actual;callStack;constructor(X,Y,Z,K,H){super(X);if(this.name="MonadicError",this.path=Y,this.expected=Z,this.actual=K,this.callStack=H,Error.captureStackTrace)Error.captureStackTrace(this,X0)}}function D5(X,Y,Z){let K=Z===null?"null":typeof Z,H=b.debug?x6():void 0;return new X0(`Expected ${Y} for '${X}', got ${K}`,X,Y,K,H)}function f6(X){return X instanceof X0}var H6={debug:!1,safety:"inputs",requireReturnTypes:!1,maxStackSize:100},b={...H6},p=[],K0=0;function A5(){K0++}function q5(){if(K0>0)K0--}function B5(){return K0>0}function w5(X){b={...b,...X}}function L5(){return{...b}}function y6(X){if(b.debug&&X){p.push(X);let Y=b.maxStackSize??100;while(p.length>Y)p.shift()}}function O0(){if(b.debug)p.pop()}function x6(){return[...p]}function I5(){b={...H6},p.length=0,K0=0}function G0(X,Y){if(X!==null&&typeof X==="object"&&typeof X.Equals==="function")return X.Equals(Y);if(Y!==null&&typeof Y==="object"&&typeof Y.Equals==="function")return Y.Equals(X);if(X===Y)return!0;if((X===null||X===void 0)&&(Y===null||Y===void 0))return!0;if(X===null||X===void 0||Y===null||Y===void 0)return!1;if(typeof X!==typeof Y)return!1;if(typeof X!=="object")return!1;if(Array.isArray(X)&&Array.isArray(Y)){if(X.length!==Y.length)return!1;return X.every((H,$)=>G0(H,Y[$]))}if(Array.isArray(X)!==Array.isArray(Y))return!1;let Z=Object.keys(X),K=Object.keys(Y);if(Z.length!==K.length)return!1;return Z.every((H)=>G0(X[H],Y[H]))}function h6(X,Y){return!G0(X,Y)}function l(X){return X!==null&&typeof X==="object"&&X.$error===!0}function d(X,Y){let Z={$error:!0,message:X,...Y};if(b.debug&&p.length>0){let K=Y?.path?[...p,Y.path]:[...p];Z.stack=K}return Z}function J6(X,Y){if(X.length===0)return d("Unknown error");if(X.length===1)return X[0];let Z=X.map((H)=>{if(H.path){let $=H.path.split(".");return $[$.length-1]}return"unknown"}).join(", "),K=`Multiple parameter errors in ${Y||"function"}: ${Z}`;return d(K,{path:Y,errors:X})}function Y0(X){if(X===null)return"null";if(X===void 0)return"undefined";if(Array.isArray(X))return"array";let Y=typeof X;if(Y!=="object")return Y;let Z=X.constructor?.name;if(Z&&Z!=="Object")return Z;return"object"}function d6(X,Y){if(X===null||X===void 0)return!1;if(typeof X!=="object"&&typeof X!=="function")return!1;let Z=X;while(Z!==null){if(Z.constructor?.name===Y)return!0;Z=Object.getPrototypeOf(Z)}return!1}function e(X,Y,Z){if(l(X))return X;if(typeof Y==="object"&&Y!==null&&"check"in Y){if(Y.check(X))return null;return d(`Expected ${Y.description} but got ${Y0(X)}`,{path:Z,expected:Y.description,actual:Y0(X)})}let K=Y0(X);if(Y==="any")return null;if(Y===K)return null;if(Y==="number"&&K==="number")return null;if(Y==="integer"&&K==="number"&&Number.isInteger(X))return null;if(Y==="object"&&K==="object")return null;return d(`Expected ${Y} but got ${K}`,{path:Z,expected:Y,actual:K})}function $6(X,Y,Z){for(let[K,H]of Object.entries(Y.params)){let $=X[K];if(l($))return $;if(H.required&&$===void 0){let W=typeof H.type==="string"?H.type:H.type.description;return d(`Missing required parameter '${K}'`,{path:Z?`${Z}.${K}`:K,expected:W,actual:"undefined",loc:H.loc})}if($===void 0)continue;let J=e($,H.type,Z?`${Z}.${K}`:K);if(J){if(H.loc)J.loc=H.loc;return J}}return null}function W6(X,Y){if(X.__tjs=Y,!(Y.safe||Y.safeReturn||b.safety!=="none"&&!Y.unsafe||Y.returns&&b.safety==="all"&&!Y.unsafeReturn))return X;let K=!!Y.returns,H=!!Y.unsafe,$=!!Y.safe,J=!!Y.unsafeReturn,W=!!Y.safeReturn,z=Object.entries(Y.params),Q=z.length,_=X.name||Y.name||"anonymous",U=function(...G){if(K0>0)return X.apply(this,G);let F=$||!H&&b.safety!=="none",D=K&&(W||!J&&b.safety==="all");if(!F&&!D)return X.apply(this,G);if(G.length>0&&l(G[0]))return G[0];if(F){let A=G.length===1&&typeof G[0]==="object"&&G[0]!==null&&!Array.isArray(G[0]),w=[];if(!A)for(let B=0;B<Q;B++){let[R,O]=z[B],L=G[B];if(l(L)){w.push(L);continue}if(O.required&&L===void 0){w.push(d(`Missing required parameter '${R}'`,{path:`${_}.${R}`,expected:typeof O.type==="string"?O.type:O.type?.description||"value",actual:"undefined",loc:O.loc}));continue}if(L!==void 0){let I=e(L,O.type,`${_}.${R}`);if(I){if(O.loc)I.loc=O.loc;w.push(I)}}}else{let B=G[0];for(let R=0;R<Q;R++){let[O,L]=z[R],I=B[O];if(l(I)){w.push(I);continue}if(L.required&&I===void 0){w.push(d(`Missing required parameter '${O}'`,{path:`${_}.${O}`,expected:typeof L.type==="string"?L.type:L.type?.description||"value",actual:"undefined",loc:L.loc}));continue}if(I!==void 0){let P=e(I,L.type,`${_}.${O}`);if(P){if(L.loc)P.loc=L.loc;w.push(P)}}}}if(w.length>0)return J6(w,_)}y6(_);try{let A=X.apply(this,G);if(D&&Y.returns&&!l(A)){let w=e(A,Y.returns.type,`${_}()`);if(w)return O0(),w}return O0(),A}catch(A){return O0(),d(A.message||String(A),{path:_,cause:A})}};return Object.defineProperty(U,"name",{value:X.name}),U.__tjs=Y,U}function m6(X){let Y=new Proxy(X,{construct(Z,K,H){return Reflect.construct(Z,K,H)},apply(Z,K,H){return Reflect.construct(Z,H)}});Object.defineProperty(Y,"name",{value:X.name});for(let Z of Object.getOwnPropertyNames(X))if(Z!=="length"&&Z!=="name"&&Z!=="prototype")Object.defineProperty(Y,Z,Object.getOwnPropertyDescriptor(X,Z));return Y}function R5(){let X={...b},Y=[],Z=0;function K(D){X={...X,...D}}function H(){return{...X}}function $(D){if(X.debug&&D){Y.push(D);let A=X.maxStackSize??100;while(Y.length>A)Y.shift()}}function J(){if(X.debug)Y.pop()}function W(){return[...Y]}function z(){X={...H6},Y.length=0,Z=0}function Q(){Z++}function _(){if(Z>0)Z--}function U(){return Z>0}function G(D,A,w){let B=w===null?"null":typeof w,R=X.debug?W():void 0;return new X0(`Expected ${A} for '${D}', got ${B}`,D,A,B,R)}function F(D,A){let w={$error:!0,message:D,...A};if(X.debug&&Y.length>0){let B=A?.path?[...Y,A.path]:[...Y];w.stack=B}return w}return{version:m,MonadicError:X0,typeError:G,isMonadicError:f6,isError:l,error:F,composeErrors:J6,typeOf:Y0,isNativeType:d6,checkType:e,validateArgs:$6,wrap:W6,wrapClass:m6,compareVersions:Y6,versionsCompatible:K6,configure:K,getConfig:H,pushStack:$,popStack:J,getStack:W,resetRuntime:z,enterUnsafe:Q,exitUnsafe:_,isUnsafeMode:U,validate:v6,infer:M0.infer.bind(M0),Type:k,isRuntimeType:t,Union:t0,Generic:z0,Enum:Z6,Nullable:s0,Optional:a0,TArray:r0,TString:d0,TNumber:m0,TBoolean:l0,TInteger:p0,TPositiveInt:u0,TNonEmptyString:i0,TEmail:n0,TUrl:o0,TUuid:c0,TPair:e0,TRecord:X6,Is:G0,IsNot:h6}}var r={version:m,MonadicError:X0,typeError:D5,isMonadicError:f6,isError:l,error:d,composeErrors:J6,typeOf:Y0,isNativeType:d6,checkType:e,validateArgs:$6,wrap:W6,wrapClass:m6,compareVersions:Y6,versionsCompatible:K6,configure:w5,getConfig:L5,pushStack:y6,popStack:O0,getStack:x6,resetRuntime:I5,enterUnsafe:A5,exitUnsafe:q5,isUnsafeMode:B5,createRuntime:R5,validate:v6,infer:M0.infer.bind(M0),Type:k,isRuntimeType:t,Union:t0,Generic:z0,Enum:Z6,Nullable:s0,Optional:a0,TArray:r0,TString:d0,TNumber:m0,TBoolean:l0,TInteger:p0,TPositiveInt:u0,TNonEmptyString:i0,TEmail:n0,TUrl:o0,TUuid:c0,Timestamp:k6,LegalDate:g6,TPair:e0,TRecord:X6,Is:G0,IsNot:h6};function O5(){let X=globalThis;if(X.__tjs){let Y=X.__tjs.version;if(typeof Y!=="string")return X.__tjs=r,r;let Z=Y6(m,Y);if(Z===0)return X.__tjs;if(K6(m,Y))if(Z>0)console.info(`TJS runtime: upgrading ${Y} → ${m}`),X.__tjs=r;else console.info(`TJS runtime: keeping ${Y} (newer than ${m})`);else if(console.warn(`TJS runtime version conflict: ${Y} vs ${m} (major version mismatch)`),Z>0)console.warn(`Upgrading to ${m} - check for breaking changes`),X.__tjs=r;return X.__tjs}return X.__tjs=r,r}function M5(X){return`
|
|
214
|
+
// TJS runtime wrapper (skips unsafe functions)
|
|
215
|
+
if (typeof ${X}.__tjs === 'object' && !${X}.__tjs.unsafe && typeof globalThis.__tjs?.wrap === 'function') {
|
|
216
|
+
${X} = globalThis.__tjs.wrap(${X}, ${X}.__tjs)
|
|
217
|
+
}
|
|
218
|
+
`.trim()}export{W6 as wrap,$6 as validateArgs,C0 as typeToString,Y0 as typeOf,c1 as transpileToJS,w0 as transpile,N0 as transformFunction,d1 as testUtils,r as runtime,A0 as preprocess,D6 as parseReturnType,n as parseParameter,o as parse,W5 as lint,l as isError,O5 as installRuntime,f as inferTypeFromValue,f1 as getToolDefinitions,k0 as extractTests,J0 as extractTDoc,i as extractLiteralValue,I6 as expectFunction,d as error,M5 as emitRuntimeWrapper,v1 as createAgent,e as checkType,L6 as assertFunction,b1 as ajs,m as TJS_VERSION,H5 as Schema};
|
|
219
|
+
|
|
220
|
+
//# debugId=FC3AC8E18381E48464756E2164756E21
|