awaitly-analyze 0.23.2 → 0.23.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +29 -20
- package/package.json +5 -5
package/dist/cli.js
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __cr } from 'module'; import { fileURLToPath as __ftp } from 'url'; import { dirname as __dn } from 'path'; const require = __cr(import.meta.url); const __filename = __ftp(import.meta.url); const __dirname = __dn(__filename);
|
|
3
|
-
import{resolve as
|
|
3
|
+
import{resolve as nt,dirname as Fe,basename as ln,extname as cn,join as ve}from"path";import{writeFileSync as We}from"fs";import{existsSync as Nt}from"fs";import{extname as mn}from"path";import{createRequire as at}from"module";var ge=null,he=null;function N(){if(ge)return ge;try{return ge=at(import.meta.url)("ts-morph"),ge}catch{throw new Error(`awaitly-analyze-ts-morph requires ts-morph as a peer dependency.
|
|
4
4
|
|
|
5
5
|
Install it with:
|
|
6
6
|
npm install ts-morph
|
|
7
7
|
# or
|
|
8
|
-
pnpm add ts-morph`)}}function
|
|
8
|
+
pnpm add ts-morph`)}}function lt(){if(he)return he;try{return he=at(import.meta.url)("typescript"),he}catch{throw new Error(`awaitly-analyze requires typescript as a peer dependency.
|
|
9
9
|
|
|
10
10
|
Install it with:
|
|
11
11
|
npm install typescript
|
|
12
12
|
# or
|
|
13
|
-
pnpm add typescript`)}}function
|
|
13
|
+
pnpm add typescript`)}}function Se(e,t,n={}){return ct(e,t)?fn(e,t):we(e,t)?ut(e,t):un(e,t)?dn(e,t):null}function ct(e,t){return t.typeToString(e).startsWith("AsyncResult<")||e.getSymbol()?.getName()==="AsyncResult"?!0:e.isIntersection?.()?e.types.some(o=>ct(o,t)):!1}function we(e,t){return t.typeToString(e).startsWith("Result<")||e.getSymbol()?.getName()==="Result"?!0:e.isIntersection?.()?e.types.some(o=>we(o,t)):!1}function un(e,t){let n=t.typeToString(e);return!!(n.startsWith("Promise<Result<")||n.startsWith("PromiseLike<Result<"))}function fn(e,t){let n=ye(e,t);return n.length===1&&n[0]&&we(n[0],t)&&(n=ye(n[0],t)),{okType:Q(n[0],t,"asyncResult"),errorType:Q(n[1],t,"asyncResult"),causeType:n[2]?Q(n[2],t,"asyncResult"):void 0,kind:"asyncResult"}}function ut(e,t){let n=ye(e,t);return{okType:Q(n[0],t,"result"),errorType:Q(n[1],t,"result"),causeType:n[2]?Q(n[2],t,"result"):void 0,kind:"result"}}function dn(e,t){let n=ye(e,t);if(!n[0])return null;let r=n[0];return we(r,t)?{...ut(r,t),kind:"promiseResult"}:null}function ye(e,t){let n=e;return n.typeArguments?.length?n.typeArguments:n.aliasTypeArguments?.length?n.aliasTypeArguments:n.resolvedTypeArguments?.length?[...n.resolvedTypeArguments]:[]}function Q(e,t,n){if(!e)return{display:"unknown",canonical:"unknown",kind:"unknown",confidence:"fallback",source:"fallback"};let r=t.typeToString(e),o=pn(e,t);return{display:r,canonical:o,kind:"plain",confidence:"exact",source:"checker"}}function pn(e,t){let n=t.typeToString(e);return n=n.replace(/\s+/g," ").trim(),n=n.replace(/import\(".*?"\)\./g,""),n=n.replace(/\s*,\s*/g,", "),n=n.replace(/\s*<\s*/g,"<"),n=n.replace(/\s*>\s*/g,">"),n}function $(e){switch(e.type){case"sequence":case"parallel":case"race":return e.children;case"conditional":case"decision":return[...e.consequent,...e.alternate??[]];case"switch":return e.cases.flatMap(t=>t.body);case"loop":return e.body;default:return[]}}function E(e){if(!e)return"";let t=e.split(".");return t[t.length-1]}var kt={tsConfigPath:"./tsconfig.json",resolveReferences:!0,maxReferenceDepth:5,includeLocations:!0,assumeImported:!1,detect:"all"};function gn(e){if(!Nt(e))throw new Error(`File not found: ${e}
|
|
14
14
|
|
|
15
|
-
Ensure the path is correct and the file exists.`);let t=
|
|
15
|
+
Ensure the path is correct and the file exists.`);let t=mn(e).toLowerCase();if(t!==".ts"&&t!==".tsx")throw new Error(`Invalid file type: ${t}
|
|
16
16
|
|
|
17
|
-
awaitly-analyze only supports TypeScript files (.ts, .tsx).`)}function
|
|
17
|
+
awaitly-analyze only supports TypeScript files (.ts, .tsx).`)}function hn(e){if(e.maxReferenceDepth!==void 0&&e.maxReferenceDepth<1)throw new Error(`Invalid maxReferenceDepth: ${e.maxReferenceDepth}
|
|
18
18
|
|
|
19
|
-
maxReferenceDepth must be at least 1.`);if(e.tsConfigPath&&!
|
|
19
|
+
maxReferenceDepth must be at least 1.`);if(e.tsConfigPath&&!Nt(e.tsConfigPath))throw new Error(`tsconfig not found: ${e.tsConfigPath}
|
|
20
20
|
|
|
21
|
-
Check the path or omit tsConfigPath to use default.`)}function ht(e,t={}){fn(e),dn(t);let n={...yt,...t},{ts:r}=N(),i=un(n).addSourceFileAtPath(e),s=wt(i,n);if(s.length===0)return[];let a=[];for(let l of s){let c=[],f=Rt(),u=kt(l,i,n,c,f);a.push({root:u,metadata:{analyzedAt:Date.now(),filePath:e,tsVersion:r.version,warnings:c,stats:f},references:new Map})}return a}function te(e,t,n={}){let r={...yt,assumeImported:!0,...n},{ts:o,Project:i}=N(),a=new i({useInMemoryFileSystem:!0,compilerOptions:{target:o.ScriptTarget.ESNext,module:o.ModuleKind.ESNext,moduleResolution:o.ModuleResolutionKind.Bundler,strict:!0,esModuleInterop:!0}}).createSourceFile("workflow.ts",e),l=wt(a,r);if(l.length===0)return[];let c=t?l.filter(u=>u.name===t):l,f=[];for(let u of c){let p=[],d=Rt(),m=kt(u,a,r,p,d);f.push({root:m,metadata:{analyzedAt:Date.now(),filePath:"<source>",tsVersion:o.version,warnings:p,stats:d},references:new Map})}return f}function un(e){let{Project:t,ts:n}=N();try{return new t({tsConfigFilePath:e.tsConfigPath,skipAddingFilesFromTsConfig:!0})}catch{return new t({compilerOptions:{target:n.ScriptTarget.ESNext,module:n.ModuleKind.ESNext,moduleResolution:n.ModuleResolutionKind.Bundler,strict:!0,esModuleInterop:!0}})}}function St(e){let{Node:t}=N(),n=e;for(;t.isParenthesizedExpression(n);)n=n.getExpression();return n.getText()}function Ne(e){let{Node:t}=N(),n=e;for(;t.isParenthesizedExpression(n);)n=n.getExpression();return n}function we(e){let{Node:t}=N(),n=e;for(;;){for(;t.isParenthesizedExpression(n);)n=n.getExpression();if(t.isAwaitExpression(n)){n=n.getExpression();continue}break}return t.isIdentifier(n)?n:void 0}function wt(e,t){let{Node:n}=N(),r=[],o=pn(e,t),i=mn(e);function s(a){if(a)return n.isStringLiteral(a)||n.isNoSubstitutionTemplateLiteral(a)?a.getLiteralText():a.getText()}return e.forEachDescendant(a=>{if(!n.isCallExpression(a))return;let l=a.getExpression(),c=Ne(l),f=St(l),u=n.isPropertyAccessExpression(c)?c.getExpression().getText():"",p=o.namespaceImports.has(u)||o.defaultImports.has(u);if((f==="createWorkflow"||o.namedImportAliases.get(f)==="createWorkflow"||n.isPropertyAccessExpression(c)&&c.getName()==="createWorkflow"&&p)&&(t.detect==="all"||t.detect==="createWorkflow")&&(o.namedImports.has("createWorkflow")||o.namespaceImports.size>0||o.defaultImports.size>0||t.assumeImported)){let S=a.getArguments(),b=a.getParent(),g,h,k,x;if(n.isVariableDeclaration(b)?(g=b.getName(),h=b):n.isPropertyAssignment(b)&&(g=b.getName()),S.length>=1&&S[0]){let R=s(S[0])??g??"anonymous";k=S.length>=2?S[1]:void 0,S.length>=3&&S[2]&&n.isObjectLiteralExpression(S[2])&&(x=S[2]),r.push({name:R,bindingName:g,callExpression:a,depsObject:k,optionsObject:x,callbackFunction:void 0,variableDeclaration:h,source:"createWorkflow"})}}if((f==="createSagaWorkflow"||o.namedImportAliases.get(f)==="createSagaWorkflow"||n.isPropertyAccessExpression(c)&&c.getName()==="createSagaWorkflow"&&p)&&(t.detect==="all"||t.detect==="createSagaWorkflow")&&(o.namedImports.has("createSagaWorkflow")||o.namespaceImports.size>0||o.defaultImports.size>0||t.assumeImported)){let S=a.getArguments(),b=a.getParent(),g,h,k,x;if(n.isVariableDeclaration(b)?(g=b.getName(),h=b):n.isPropertyAssignment(b)&&(g=b.getName()),S.length>=2&&S[0]){let R=s(S[0])??g??"anonymous";k=S[1],S[2]&&n.isObjectLiteralExpression(S[2])&&(x=S[2]),r.push({name:R,callExpression:a,bindingName:g,depsObject:k,optionsObject:x,callbackFunction:void 0,variableDeclaration:h,source:"createSagaWorkflow"})}}if((f==="runSaga"||o.namedImportAliases.get(f)==="runSaga"||n.isPropertyAccessExpression(c)&&c.getName()==="runSaga"&&p)&&(t.detect==="all"||t.detect==="createSagaWorkflow")&&(o.namedImports.has("runSaga")||o.namespaceImports.size>0||o.defaultImports.size>0||t.assumeImported)){let S=a.getArguments(),b=a.getStartLineNumber(),g=e.getFilePath(),h=g.includes("/")&&g.split("/").pop()||g;r.push({name:`runSaga@${h}:${b}`,callExpression:a,depsObject:void 0,optionsObject:void 0,callbackFunction:S[0],variableDeclaration:void 0,source:"runSaga"})}if((f==="run"||o.namedImportAliases.get(f)==="run"||n.isPropertyAccessExpression(c)&&c.getName()==="run"&&p)&&(t.detect==="all"||t.detect==="run")){let S=o.namedImports.has("run")||o.namedImportAliases.get(f)==="run"||o.namespaceImports.size>0||o.defaultImports.size>0||t.assumeImported,b=gn("run",a,i),g=n.isPropertyAccessExpression(c)&&p;if(S&&!b&&(g||!n.isPropertyAccessExpression(c))){let h=a.getArguments(),k=a.getStartLineNumber(),x=e.getFilePath(),R=x.includes("/")&&x.split("/").pop()||x;r.push({name:`run@${R}:${k}`,callExpression:a,depsObject:void 0,optionsObject:void 0,callbackFunction:h[0],variableDeclaration:void 0,source:"run"})}}}),r}function pn(e,t){let n={namedImports:new Set,namedImportAliases:new Map,namespaceImports:new Set,defaultImports:new Set};for(let r of e.getImportDeclarations()){let o=r.getModuleSpecifierValue();if(o==="awaitly"||o.startsWith("awaitly/")){if(r.isTypeOnly())continue;let i=r.getNamedImports();for(let l of i){if(l.isTypeOnly())continue;let c=l.getName(),f=l.getAliasNode(),u=f?f.getText():c;n.namedImports.add(c),n.namedImportAliases.set(u,c)}let s=r.getDefaultImport();s&&n.defaultImports.add(s.getText());let a=r.getNamespaceImport();a&&n.namespaceImports.add(a.getText())}}return n}function mn(e){let{Node:t}=N(),n=new Map,r=(i,s)=>{let a=n.get(i)||[];a.push(s),n.set(i,a)},o=(i,s)=>{if(t.isIdentifier(i))r(i.getText(),s);else if(t.isObjectBindingPattern(i))for(let a of i.getElements()){let l=a.getNameNode();o(l,s)}else if(t.isArrayBindingPattern(i)){for(let a of i.getElements())if(t.isBindingElement(a)){let l=a.getNameNode();o(l,s)}}};return e.forEachDescendant(i=>{if(t.isVariableDeclaration(i)){let s=i.getNameNode();o(s,i)}else if(t.isFunctionDeclaration(i)){let s=i.getName();s&&r(s,i)}else if(t.isParameterDeclaration(i)){let s=i.getNameNode();o(s,i)}}),n}function gn(e,t,n){let{Node:r}=N(),o=n.get(e);if(!o||o.length===0)return!1;let i=t.getStart();for(let s of o){if(!s.getParent())continue;let l=Nt(s);if((r.isVariableDeclaration(s)?s.getVariableStatement()?.getDeclarationKind():void 0)==="var"){let u=Me(s),p=Me(t);if(u===p)return!0}else if(l&&yn(l,t)&&s.getEnd()<=i)return!0}return!1}function Nt(e){let{Node:t}=N(),n=e.getParent();for(;n;){if(t.isBlock(n)||t.isFunctionDeclaration(n)||t.isArrowFunction(n)||t.isFunctionExpression(n)||t.isSourceFile(n))return n;n=n.getParent()}}function Me(e){let{Node:t}=N(),n=e.getParent();for(;n;){if(t.isFunctionDeclaration(n)||t.isArrowFunction(n)||t.isFunctionExpression(n)||t.isSourceFile(n))return n;n=n.getParent()}}function yn(e,t){let n=t.getParent();for(;n;){if(n===e)return!0;n=n.getParent()}return!1}function kt(e,t,n,r,o){let{name:i,callExpression:s,depsObject:a,optionsObject:l,source:c}=e;(c==="createSagaWorkflow"||c==="runSaga")&&(o.sagaWorkflowCount=(o.sagaWorkflowCount||0)+1);let f=a?Jn(a,r):[],u=nr(f),p=l?at(l):{description:void 0,markdown:void 0},d=a?at(a):{description:void 0,markdown:void 0},m={description:p.description||d.description,markdown:p.markdown||d.markdown},y=l?lt(l):a?lt(a):{strict:void 0,declaredErrors:void 0},w=c==="createSagaWorkflow"||c==="runSaga",S={isSagaWorkflow:w},b=[],g;if(c==="run"||c==="runSaga"){if(g=e.callbackFunction,e.callbackFunction){c==="runSaga"&&(S.sagaParamInfo=ct(e.callbackFunction));let k=st(e.callbackFunction),x=dt(e.callbackFunction,n,r,o,S,k);b.push(...x)}}else{let k=Sn(e,t);k.length>0&&k[0].callbackArg&&(g=k[0].callbackArg);for(let x of k){let R=x.callbackArg;if(R){w&&(S.sagaParamInfo=ct(R));let D=st(R),Qe=dt(R,n,r,o,S,D);b.push(...Qe)}}}let h={id:C(),type:"workflow",workflowName:i,source:c,dependencies:f,errorTypes:u,children:b,description:m.description,markdown:m.markdown,location:n.includeLocations?I(s):void 0,strict:y.strict,declaredErrors:y.declaredErrors};try{let k=g&&hn(g,t);if(k)h.workflowReturnType=k;else if(g){let x=bt(g);x&&(h.workflowReturnType=x)}}catch{}if(Gn(h),Hn(h),Zn(h),Xn(h),e.variableDeclaration){let k=e.variableDeclaration,x=typeof k.getVariableStatement=="function"?k.getVariableStatement():(()=>{let{Node:R}=N(),D=e.variableDeclaration.getParent();return R.isVariableStatement(D)?D:e.variableDeclaration})();if(x){let R=V(x);R&&(h.jsdocDescription=R);let D=q(x);D&&(D.params?.length&&(h.jsdocParams=D.params),D.returns&&(h.jsdocReturns=D.returns),D.throws?.length&&(h.jsdocThrows=D.throws),D.example&&(h.jsdocExample=D.example))}}return h}function st(e){let{Node:t}=N(),n=[];if((t.isArrowFunction(e)||t.isFunctionExpression(e))&&(n=e.getParameters()),n.length===0)return;let r=n[0];if(!t.isParameterDeclaration(r))return;let o=r.getNameNode();if(t.isObjectBindingPattern(o)){let i={isDestructured:!0};for(let s of o.getElements()){let a=s.getPropertyNameNode()?.getText()||s.getName(),l=s.getName();a==="step"&&(i.stepAlias=l)}return i}return{name:o.getText(),isDestructured:!1}}function hn(e,t){let{Node:n}=N(),r=e;for(;n.isParenthesizedExpression(r);)r=r.getExpression();try{let s=t.getProject().getTypeChecker().compilerObject,a=r.compilerNode,f=(s.getTypeAtLocation(a).getCallSignatures?.()??[])[0];if(!f)return;let u=f.getReturnType();return s.typeToString(u)}catch{return}}function bt(e){if(!e)return;let{Node:t}=N(),n=e;for(;t.isParenthesizedExpression(n);)n=n.getExpression();if(t.isArrowFunction(n)||t.isFunctionExpression(n))return n.getReturnType?.()?.getText();if(t.isIdentifier(n)){let o=n.getDefinitionNodes?.();if(!o?.length)return;for(let i of o){if(t.isVariableDeclaration(i)){let s=i.getInitializer();if(!s)break;if(t.isArrowFunction(s)||t.isFunctionExpression(s)){let a=s.getReturnType?.();if(a)return a.getText()}else if(t.isIdentifier(s))return bt(s);break}if(t.isFunctionDeclaration(i)){let s=i.getReturnType?.();if(s)return s.getText();break}}}}function at(e){let{Node:t}=N(),n={};if(!t.isObjectLiteralExpression(e))return n;for(let r of e.getProperties()){if(!t.isPropertyAssignment(r))continue;let o=r.getName(),i=r.getInitializer();o==="description"&&i?n.description=E(i):o==="markdown"&&i&&(n.markdown=E(i))}return n}function lt(e){let{Node:t}=N(),n={};if(!t.isObjectLiteralExpression(e))return n;for(let r of e.getProperties()){if(!t.isPropertyAssignment(r))continue;let o=r.getName(),i=r.getInitializer();o==="strict"&&i?t.isTrueLiteral(i)?n.strict=!0:t.isFalseLiteral(i)&&(n.strict=!1):o==="errors"&&i&&(n.declaredErrors=B(i))}return n}function ct(e){let{Node:t}=N(),n=[];if((t.isArrowFunction(e)||t.isFunctionExpression(e))&&(n=e.getParameters()),n.length===0)return;let r=n[0];if(!t.isParameterDeclaration(r))return;let o=r.getNameNode();if(t.isObjectBindingPattern(o)){let i={isDestructured:!0};for(let s of o.getElements()){let a=s.getPropertyNameNode()?.getText()||s.getName(),l=s.getName();a==="saga"?i.sagaAlias=l:a==="step"?i.stepAlias=l:a==="tryStep"&&(i.tryStepAlias=l)}return i}return{name:o.getText(),isDestructured:!1}}function ft(e,t){let n=e.getParent();for(;n;){if(n===t)return!0;n=n.getParent()}return!1}function Sn(e,t){let{Node:n}=N(),r=[],o=e.bindingName??e.name,i=e.variableDeclaration||e.callExpression,s=i.getStart(),a;e.variableDeclaration&&n.isVariableDeclaration(e.variableDeclaration)&&e.variableDeclaration.getVariableStatement()?.getDeclarationKind()==="var"&&(a=Me(i)),a??=Nt(i);let l=[];function c(f){let u=[];if(n.isIdentifier(f))u.push(f.getText());else if(n.isObjectBindingPattern(f))for(let p of f.getElements()){let d=p.getNameNode();u.push(...c(d))}else if(n.isArrayBindingPattern(f)){for(let p of f.getElements())if(n.isBindingElement(p)){let d=p.getNameNode();u.push(...c(d))}}return u}if(t.forEachDescendant(f=>{if(n.isVariableDeclaration(f)){if(f.getStart()<=s)return;let u=f.getNameNode();if(c(u).includes(o)){let d=f.getParent(),m=d&&n.isVariableDeclarationList(d)&&d.getDeclarationKind()==="var",y=f.getParent();if(m)for(;y&&!n.isFunctionDeclaration(y)&&!n.isFunctionExpression(y)&&!n.isArrowFunction(y)&&!n.isSourceFile(y);)y=y.getParent();else for(;y&&!n.isFunctionDeclaration(y)&&!n.isFunctionExpression(y)&&!n.isArrowFunction(y)&&!n.isBlock(y)&&!n.isSourceFile(y);)y=y.getParent();y&&!n.isSourceFile(y)&&l.push(y)}return}if(n.isFunctionDeclaration(f)){if(f.getStart()<=s)return;if(f.getName()===o){let p=f.getParent();for(;p&&!n.isFunctionDeclaration(p)&&!n.isFunctionExpression(p)&&!n.isArrowFunction(p)&&!n.isBlock(p)&&!n.isSourceFile(p);)p=p.getParent();p&&!n.isSourceFile(p)&&l.push(p)}}if(n.isFunctionDeclaration(f)||n.isFunctionExpression(f)||n.isArrowFunction(f)||n.isMethodDeclaration(f)){if(f.getStart()<=s)return;let u=f.getParameters();for(let p of u){let d=p.getNameNode();if(c(d).includes(o)){l.push(f);break}}}}),t.forEachDescendant(f=>{if(!n.isCallExpression(f))return;let u=f.getExpression(),p=St(u);if(p===o||p===`await ${o}`||p===`(await ${o})`||p===`${o}.run`||p===`await ${o}.run`){if(e.variableDeclaration){let y=we(u);if(!y){let w=Ne(u);if(n.isPropertyAccessExpression(w)){let S=w.getExpression();n.isIdentifier(S)&&(y=S)}}if(y){let w=y.getSymbol();if(w&&!w.getDeclarations().some(g=>g===e.variableDeclaration))return}}let d=!a||ft(f,a),m=l.some(y=>ft(f,y));if(d&&!m){let y=f.getArguments();r.push({callExpression:f,callbackArg:y[0]})}}}),r.length===0&&!e.bindingName){let f,u,p=e.callExpression.getParent();for(;p;){if(n.isReturnStatement(p)||n.isArrowFunction(p)){let d=p.getParent();for(;d;){if(n.isFunctionDeclaration(d)){f=d.getName?.(),u=d;break}if(n.isVariableDeclaration(d)){let m=d.getInitializer();if(m&&(n.isArrowFunction(m)||n.isFunctionExpression(m))){f=d.getName(),u=d;break}}d=d.getParent()}break}p=p.getParent()}if(f&&u){let d=[];t.forEachDescendant(m=>{if(!n.isCallExpression(m))return;let y=m.getExpression(),w=we(y);if(!w||w.getText()!==f)return;let S=w.getSymbol();if(!S||!S.getDeclarations().some(k=>k===u))return;let h=m.getParent();h&&n.isVariableDeclaration(h)&&d.push(h)}),t.forEachDescendant(m=>{if(!n.isCallExpression(m))return;let y=m.getExpression(),w=we(y);if(!w){let k=Ne(y);if(n.isPropertyAccessExpression(k)){let x=k.getExpression();n.isIdentifier(x)&&(w=x)}}if(!w)return;let S=w.getSymbol();if(!S||!S.getDeclarations().some(k=>d.includes(k)))return;let h=m.getArguments();if(h.length>0){let k=h[0];(n.isArrowFunction(k)||n.isFunctionExpression(k))&&r.push({callExpression:m,callbackArg:k})}})}if(r.length===0&&e.depsObject){let d=Un(e.depsObject);d.length>0&&t.forEachDescendant(m=>{if(!n.isCallExpression(m))return;let y=m.getExpression(),w=we(y);if(!w){let F=Ne(y);if(n.isPropertyAccessExpression(F)){let oe=F.getExpression();n.isIdentifier(oe)&&(w=oe)}}if(!w)return;let S=w.getSymbol();if(!S||!S.getDeclarations().some(F=>n.isParameterDeclaration(F)))return;let g=m.getArguments();if(g.length===0)return;let h=g[0];if(!n.isArrowFunction(h)&&!n.isFunctionExpression(h))return;let k=h.getParameters();if(k.length!==1)return;let x=k[0];if(!n.isParameterDeclaration(x))return;let R=x.getNameNode();if(!n.isObjectBindingPattern(R))return;let D=R.getElements();if(!D.some(F=>(F.getPropertyNameNode?.()?.getText()||F.getName())==="step"))return;let Xe=D.find(F=>(F.getPropertyNameNode?.()?.getText()||F.getName())==="deps");if(!Xe)return;let $e=Xe.getNameNode?.(),et;if($e&&n.isObjectBindingPattern($e))et=$e.getElements().map(F=>F.getName());else return;if(d.every(F=>et.includes(F))){if(w&&(w.getDefinitionNodes?.()??[]).some(tt=>n.isFunctionDeclaration(tt)||n.isVariableDeclaration(tt)))return;r.push({callExpression:m,callbackArg:h})}})}}return r}function dt(e,t,n,r,o={isSagaWorkflow:!1},i){let{Node:s}=N(),a;if((s.isArrowFunction(e)||s.isFunctionExpression(e))&&(a=e.getBody()),!a)return n.push({code:"CALLBACK_NO_BODY",message:"Could not extract callback body",location:I(e)}),[];let l={stepNames:new Set,isInWorkflowCallback:!0,depth:0};return i&&(i.isDestructured&&i.stepAlias?l.stepNames.add(i.stepAlias):i.name&&l.stepNames.add(i.name)),l.stepNames.size===0&&l.stepNames.add("step"),T(a,t,n,r,o,l)}function T(e,t,n,r,o={isSagaWorkflow:!1},i={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:s}=N(),a=[];if(s.isBlock(e)){for(let l of e.getStatements())a.push(...T(l,t,n,r,o,i));return Ct(a,t)}if(s.isExpressionStatement(e)||s.isAwaitExpression(e)||s.isParenthesizedExpression(e))return T(e.getExpression(),t,n,r,o,i);if(s.isVariableStatement(e)){for(let l of e.getDeclarationList().getDeclarations()){let c=l.getInitializer();c&&a.push(...T(c,t,n,r,o,i))}return a}if(s.isVariableDeclaration(e)){let l=e.getInitializer();if(l)if(s.isArrowFunction(l)||s.isFunctionExpression(l)){let c=l.getBody(),f={...i,isInWorkflowCallback:i.isInWorkflowCallback,depth:i.depth+1};a.push(...T(c,t,n,r,o,f))}else a.push(...T(l,t,n,r,o,i));return a}if(s.isCallExpression(e)){let l=Nn(e,t,n,r,o,i);return l&&a.push(l),a}if(s.isIfStatement(e)){let l=vn(e,t,n,r,o,i);return l&&a.push(l),a}if(s.isSwitchStatement(e)){let l=Mn(e,t,n,r,o,i);return l&&a.push(l),a}if(s.isForStatement(e)){let l=zn(e,t,n,r,o,i);return l&&a.push(l),a}if(s.isForOfStatement(e)){let l=_n(e,t,n,r,o,i);return l&&a.push(l),a}if(s.isForInStatement(e)){let l=Bn(e,t,n,r,o,i);return l&&a.push(l),a}if(s.isWhileStatement(e)){let l=qn(e,t,n,r,o,i);return l&&a.push(l),a}if(s.isTryStatement(e)){let l=wn(e,t,n,r,o,i);return a.push(...l),a}if(s.isReturnStatement(e)){let l=e.getExpression();return l?T(l,t,n,r,o,i):a}if(s.isConditionalExpression(e)){let l=T(e.getWhenTrue(),t,n,r,o,i),c=T(e.getWhenFalse(),t,n,r,o,i);return a.push(...l,...c),a}if(s.isArrayLiteralExpression(e)){for(let l of e.getElements())a.push(...T(l,t,n,r,o,i));return a}if(s.isObjectLiteralExpression(e)){for(let l of e.getProperties())if(s.isPropertyAssignment(l)){let c=l.getInitializer();if(c){if(s.isArrowFunction(c)||s.isFunctionExpression(c)){let f=c.getBody(),u={...i,isInWorkflowCallback:i.isInWorkflowCallback,depth:i.depth+1};a.push(...T(f,t,n,r,o,u))}else if(s.isObjectLiteralExpression(c))a.push(...T(c,t,n,r,o,i));else if(s.isCallExpression(c))for(let f of c.getArguments())a.push(...T(f,t,n,r,o,i))}}else if(s.isMethodDeclaration(l)){let c=l.getBody();if(c){let f={...i,isInWorkflowCallback:i.isInWorkflowCallback,depth:i.depth+1};a.push(...T(c,t,n,r,o,f))}}return a}if(s.isArrowFunction(e)){let l=e.getBody(),c={...i,isInWorkflowCallback:i.isInWorkflowCallback,depth:i.depth+1};return T(l,t,n,r,o,c)}if(s.isFunctionExpression(e)){let l=e.getBody(),c={...i,isInWorkflowCallback:i.isInWorkflowCallback,depth:i.depth+1};return T(l,t,n,r,o,c)}return a}function wn(e,t,n,r,o,i){let{Node:s}=N();if(!s.isTryStatement(e))return[];let a=[],l=e.getTryBlock();a.push(...T(l,t,n,r,o,i));let c=e.getCatchClause();c&&a.push(...T(c.getBlock(),t,n,r,o,i));let f=e.getFinallyBlock();return f&&a.push(...T(f,t,n,r,o,i)),a}function O(e,t,n,r,o={isSagaWorkflow:!1},i={stepNames:new Set(["step"]),isInWorkflowCallback:!0,depth:0}){let{Node:s}=N();if(s.isArrowFunction(e)){let a=e.getBody();return T(a,t,n,r,o,i)}if(s.isFunctionExpression(e)){let a=e.getBody();return T(a,t,n,r,o,i)}return T(e,t,n,r,o,i)}function Nn(e,t,n,r,o={isSagaWorkflow:!1},i={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:s}=N();if(!s.isCallExpression(e))return;let a=e.getExpression(),l=a.getText(),c=e.getArguments();if(o.isSagaWorkflow&&o.sagaParamInfo){let u=o.sagaParamInfo;if(u.isDestructured&&u.sagaAlias){if(l===`${u.sagaAlias}.step`)return Q(e,c,!1,t,n,r);if(l===`${u.sagaAlias}.tryStep`)return Q(e,c,!0,t,n,r)}if(u.isDestructured){if(u.stepAlias&&l===u.stepAlias)return Q(e,c,!1,t,n,r);if(u.tryStepAlias&&l===u.tryStepAlias)return Q(e,c,!0,t,n,r)}else if(u.name){if(l===`${u.name}.step`)return Q(e,c,!1,t,n,r);if(l===`${u.name}.tryStep`)return Q(e,c,!0,t,n,r)}}if(kn(l,i))return _(e,c,t,n,r);if(L(l,"sleep",i))return bn(e,c,t,r);if(L(l,"retry",i))return Cn(e,c,t,n,r);if(L(l,"withTimeout",i))return Rn(e,c,t,n,r);if(L(l,"try",i))return En(e,c,t,n,r);if(L(l,"fromResult",i))return An(e,c,t,n,r);if(L(l,"withFallback",i))return _(e,c,t,n,r,{displayCallee:"step.withFallback"});if(L(l,"withResource",i)){let u=_(e,c,t,n,r,{displayCallee:"step.withResource"});if(u.stepKind="withResource",c[1]&&s.isObjectLiteralExpression(c[1])){let p={};for(let d of c[1].getProperties()){if(!s.isPropertyAssignment(d))continue;let m=d.getName();if(m!=="acquire"&&m!=="use"&&m!=="release")continue;let y=d.getInitializer();if(y){let w=$n(y);w&&(p[m]=w)}}Object.keys(p).length>0&&(u.resourceOps=p)}return u}if(L(l,"workflow",i)){let u=c[1]?O(c[1],t,n,r,o,i):[],p=_(e,c,t,n,r,{displayCallee:"step.workflow"});return u.length===0?p:{id:C(),type:"sequence",children:[p,...u]}}if(L(l,"run",i))return _(e,c,t,n,r,{displayCallee:"step.run"});if(L(l,"andThen",i))return _(e,c,t,n,r,{displayCallee:"step.andThen"});if(L(l,"match",i))return _(e,c,t,n,r,{displayCallee:"step.match"});if(L(l,"all",i))return We(e,c,"all",t,n,r,o,i);if(L(l,"allSettled",i))return We(e,c,"allSettled",t,n,r,o,i);if(L(l,"map",i))return _(e,c,t,n,r,{displayCallee:"step.map"});if(L(l,"parallel",i))return We(e,c,"all",t,n,r,o,i);if(L(l,"race",i))return Wn(e,c,t,n,r,o,i);if(L(l,"forEach",i))return Ln(e,c,t,n,r,o,i);if(L(l,"branch",i))return Dn(e,c,t,n,r,o,i);if(L(l,"getWritable",i))return Pe(e,"write",t,r);if(L(l,"getReadable",i))return Pe(e,"read",t,r);if(L(l,"streamForEach",i))return Pe(e,"forEach",t,r);if(l==="allAsync")return pt(e,c,"all",t,n,r,o,i);if(l==="allSettledAsync")return pt(e,c,"allSettled",t,n,r,o,i);if(l==="anyAsync")return Fn(e,c,t,n,r,o,i);if(["when","unless","whenOr","unlessOr"].includes(l))return jn(e,l,c,t,n,r,o,i);if(l==="Promise.all")return xn(e,c,t,n,r,o,i);if(s.isPropertyAccessExpression(a)){let u=a.getName();if(["map","forEach","filter","reduce","some","every","find","flatMap"].includes(u)&&c[0]){let d=O(c[0],t,n,r,o,i);if(d.length>0)return d.length===1?d[0]:{id:C(),type:"sequence",children:d}}}if(Kn(e))return Vn(e,l,t,n,r)}function kn(e,t){return!!t.stepNames.has(e)}function L(e,t,n){for(let r of n.stepNames)if(e===`${r}.${t}`)return!0;return!1}function bn(e,t,n,r){let{Node:o}=N();r.totalSteps++;let i="<missing>";t[0]&&(o.isStringLiteral(t[0])||o.isNoSubstitutionTemplateLiteral(t[0])?i=t[0].getLiteralValue():i="<dynamic>");let s;t[1]&&(o.isStringLiteral(t[1])||o.isNoSubstitutionTemplateLiteral(t[1])?s=t[1].getLiteralValue():s=t[1].getText());let a={id:C(),type:"step",stepId:i,callee:"step.sleep",stepKind:"sleep",sleepDuration:s,location:n.includeLocations?I(e):void 0};if(t[2]&&o.isObjectLiteralExpression(t[2])){let c=ne(t[2]);c.key&&(a.key=c.key),c.description&&(a.description=c.description),c.markdown&&(a.markdown=c.markdown),c.intent&&(a.intent=c.intent),c.domain&&(a.domain=c.domain),c.owner&&(a.owner=c.owner),c.tags&&(a.tags=c.tags)}a.name||(a.name=i);let l=Z(e);if(l){let c=V(l);c&&(a.jsdocDescription=c);let f=q(l);f&&(f.params?.length&&(a.jsdocParams=f.params),f.returns&&(a.jsdocReturns=f.returns),f.throws?.length&&(a.jsdocThrows=f.throws),f.example&&(a.jsdocExample=f.example))}return a}function xn(e,t,n,r,o,i,s={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:a}=N();if(t[0]){if(a.isArrayLiteralExpression(t[0])){let l=[];for(let c of t[0].getElements())l.push(...T(c,n,r,o,i,s));if(l.length>0)return Ct(l,n)[0]}if(a.isCallExpression(t[0])){let l=t[0],c=l.getExpression();if(a.isPropertyAccessExpression(c)){let f=c.getName();if(["map","flatMap","filter"].includes(f)){let p=l.getArguments();if(p[0])return O(p[0],n,r,o,i,s)[0]}}}}}function _(e,t,n,r,o,i){let{Node:s}=N();o.totalSteps++;let a=t[0],l=a&&s.isStringLiteral(a),c=a&&s.isNoSubstitutionTemplateLiteral(a),f=a&&s.isTemplateExpression(a),u=a&&s.isIdentifier(a),p;l&&s.isStringLiteral(a)||c&&s.isNoSubstitutionTemplateLiteral(a)?p=a.getLiteralValue():f||u?p="<dynamic>":(p="<missing>",r.push({code:"STEP_MISSING_ID",message:'step() requires an explicit string ID as the first argument. Example: step("fetchUser", () => fetchUser(id))',location:n.includeLocations?I(e):void 0}));let d={id:C(),type:"step",stepId:p,location:n.includeLocations?I(e):void 0},m=p!=="<missing>",y=m?t[1]:t[0],w=m?t[2]:t[1],S;if(y){if(s.isCallExpression(y)){let g=y.getExpression();if(s.isPropertyAccessExpression(g)&&g.getName()==="dep"){let h=y.getArguments();h[0]&&s.isStringLiteral(h[0])&&(d.depSource=h[0].getLiteralValue()),h[1]&&(y=h[1])}}if(s.isArrowFunction(y)||s.isFunctionExpression(y)){let g=y.getBody();for(;s.isParenthesizedExpression(g);)g=g.getExpression();if(s.isCallExpression(g))d.callee=g.getExpression().getText(),S=g;else if(s.isBlock(g)){let k=g.getStatements();for(let x of k)if(s.isReturnStatement(x)){let R=x.getExpression();if(R&&s.isCallExpression(R)){d.callee=R.getExpression().getText(),S=R;break}}d.callee||(d.callee=g.getText())}else g&&(d.callee=g.getText());let h=Tn(y);if(h&&(d.reads=h.reads,d.readParamIndices=h.paramIndices),!d.depSource&&d.callee){let k=d.callee.match(/^(?:deps|ctx\.deps)\.([a-zA-Z_$][a-zA-Z0-9_$]*)/);k&&(d.depSource=k[1])}}else s.isCallExpression(y)?(d.callee=y.getExpression().getText(),S=y):d.callee=y.getText()}if(le(e,S,d),w&&s.isObjectLiteralExpression(w)){let g=ne(w);if(g.key&&(d.key=g.key),g.description&&(d.description=g.description),g.markdown&&(d.markdown=g.markdown),g.retry&&(d.retry=g.retry),g.timeout&&(d.timeout=g.timeout),g.errors&&(d.errors=g.errors,d.errorsSource="explicit"),g.out&&(d.out=g.out),g.dep&&(d.depSource=g.dep),g.reads){let h=d.reads??[],k=new Set([...h,...g.reads]);d.reads=Array.from(k)}if(g.intent&&(d.intent=g.intent),g.domain&&(d.domain=g.domain),g.owner&&(d.owner=g.owner),g.tags&&(d.tags=g.tags),g.stateChanges&&(d.stateChanges=g.stateChanges),g.emits&&(d.emits=g.emits),g.calls&&(d.calls=g.calls),g.errorMeta&&(d.errorMeta=g.errorMeta),g.ttl!=null&&(d.ttl=g.ttl),g.errorMeta&&g.errors)for(let h of Object.keys(g.errorMeta))g.errors.includes(h)||r.push({code:"errorMeta-unknown-key",message:`errorMeta key "${h}" is not declared in errors array`,location:d.location})}d.name||(d.name=d.stepId);let b=Z(e);if(b){let g=V(b);g&&(d.jsdocDescription=g);let h=q(b);h&&(h.params?.length&&(d.jsdocParams=h.params),h.returns&&(d.jsdocReturns=h.returns),h.throws?.length&&(d.jsdocThrows=h.throws),h.example&&(d.jsdocExample=h.example))}if(n.includeLocations&&S){let{Node:g}=N();if(g.isCallExpression(S)){let h=S.getExpression();d.depLocation=ce(h)??I(h)}}return i?.displayCallee&&(d.callee=i.displayCallee),d}function In(e,t){let n=t;for(;n;){if(n===e)return!0;n=n.getParent()}return!1}function Tn(e){let{Node:t}=N(),n=[],r=[];return e.forEachDescendant(o=>{if(!t.isCallExpression(o))return;let i=o.getExpression();if(!t.isPropertyAccessExpression(i))return;let s=i.getName(),a=i.getExpression();if(s!=="ref"||a.getText()!=="ctx")return;let l=o.getArguments();if(!l[0]||!t.isStringLiteral(l[0]))return;let c=l[0].getLiteralValue(),f=0,u=o.getParent();for(;u;){if(t.isCallExpression(u)){let p=u.getExpression().getText();if(p.startsWith("deps.")||p.startsWith("ctx.deps.")){let m=u.getArguments().findIndex(y=>In(y,o));m>=0&&(f=m);break}}u=u.getParent()}n.push(c),r.push(f)}),n.length>0?{reads:n,paramIndices:r}:void 0}function Cn(e,t,n,r,o){let{Node:i}=N();o.totalSteps++;let s="<missing>";t[0]&&(i.isStringLiteral(t[0])||i.isNoSubstitutionTemplateLiteral(t[0])?s=t[0].getLiteralValue():s="<dynamic>");let{operation:a,depSourceOverride:l}=ke(t[1]),c=a?ae(a):void 0,f=a?be(a):void 0,u={id:C(),type:"step",stepId:s,callee:"step.retry",stepKind:"retry",depSource:l??xe(c),name:s,location:n.includeLocations?I(e):void 0};if(le(e,f,u),t[2]&&i.isObjectLiteralExpression(t[2])){u.retry=It(t[2]);let d=ne(t[2]);d.key&&(u.key=d.key),d.dep&&(u.depSource=d.dep),d.errors&&(u.errors=d.errors,u.errorsSource="explicit"),d.out&&(u.out=d.out),d.reads&&(u.reads=d.reads),d.intent&&(u.intent=d.intent),d.domain&&(u.domain=d.domain),d.owner&&(u.owner=d.owner),d.tags&&(u.tags=d.tags),d.stateChanges&&(u.stateChanges=d.stateChanges),d.emits&&(u.emits=d.emits),d.calls&&(u.calls=d.calls),d.errorMeta&&(u.errorMeta=d.errorMeta),d.ttl!=null&&(u.ttl=d.ttl)}if(n.includeLocations&&f&&i.isCallExpression(f)){let d=f.getExpression();u.depLocation=ce(d)??I(d)}let p=Z(e);if(p){let d=V(p);d&&(u.jsdocDescription=d);let m=q(p);m&&(m.params?.length&&(u.jsdocParams=m.params),m.returns&&(u.jsdocReturns=m.returns),m.throws?.length&&(u.jsdocThrows=m.throws),m.example&&(u.jsdocExample=m.example))}return u}function Rn(e,t,n,r,o){let{Node:i}=N();o.totalSteps++;let s="<missing>";t[0]&&(i.isStringLiteral(t[0])||i.isNoSubstitutionTemplateLiteral(t[0])?s=t[0].getLiteralValue():s="<dynamic>");let{operation:a,depSourceOverride:l}=ke(t[1]),c=a?ae(a):void 0,f=a?be(a):void 0,u={id:C(),type:"step",stepId:s,callee:"step.withTimeout",stepKind:"withTimeout",depSource:l??xe(c),name:s,location:n.includeLocations?I(e):void 0};if(le(e,f,u),t[2]&&i.isObjectLiteralExpression(t[2])){u.timeout=Tt(t[2]);let d=ne(t[2]);d.key&&(u.key=d.key),d.dep&&(u.depSource=d.dep),d.intent&&(u.intent=d.intent),d.domain&&(u.domain=d.domain),d.owner&&(u.owner=d.owner),d.tags&&(u.tags=d.tags)}if(n.includeLocations&&f&&i.isCallExpression(f)){let d=f.getExpression();u.depLocation=ce(d)??I(d)}let p=Z(e);if(p){let d=V(p);d&&(u.jsdocDescription=d);let m=q(p);m&&(m.params?.length&&(u.jsdocParams=m.params),m.returns&&(u.jsdocReturns=m.returns),m.throws?.length&&(u.jsdocThrows=m.throws),m.example&&(u.jsdocExample=m.example))}return u}function En(e,t,n,r,o){let{Node:i}=N();o.totalSteps++;let s="<missing>";t[0]&&(i.isStringLiteral(t[0])||i.isNoSubstitutionTemplateLiteral(t[0])?s=t[0].getLiteralValue():s="<dynamic>");let{operation:a,depSourceOverride:l}=ke(t[1]),c=a?ae(a):void 0,f=a?be(a):void 0,u={id:C(),type:"step",stepId:s,callee:"step.try",stepKind:"try",depSource:l??xe(c),name:s,location:n.includeLocations?I(e):void 0};if(le(e,f,u),t[2]&&i.isObjectLiteralExpression(t[2])){let d=ne(t[2]);d.key&&(u.key=d.key),d.dep&&(u.depSource=d.dep),d.intent&&(u.intent=d.intent),d.domain&&(u.domain=d.domain),d.owner&&(u.owner=d.owner),d.tags&&(u.tags=d.tags)}if(n.includeLocations&&f&&i.isCallExpression(f)){let d=f.getExpression();u.depLocation=ce(d)??I(d)}let p=Z(e);if(p){let d=V(p);d&&(u.jsdocDescription=d);let m=q(p);m&&(m.params?.length&&(u.jsdocParams=m.params),m.returns&&(u.jsdocReturns=m.returns),m.throws?.length&&(u.jsdocThrows=m.throws),m.example&&(u.jsdocExample=m.example))}return u}function An(e,t,n,r,o){let{Node:i}=N();o.totalSteps++;let s="<missing>";t[0]&&(i.isStringLiteral(t[0])||i.isNoSubstitutionTemplateLiteral(t[0])?s=t[0].getLiteralValue():s="<dynamic>");let{operation:a,depSourceOverride:l}=ke(t[1]),c=a?ae(a):void 0,f=a?be(a):void 0,u={id:C(),type:"step",stepId:s,callee:"step.fromResult",stepKind:"fromResult",depSource:l??xe(c),name:s,location:n.includeLocations?I(e):void 0};if(le(e,f,u),t[2]&&i.isObjectLiteralExpression(t[2])){let d=ne(t[2]);d.key&&(u.key=d.key),d.dep&&(u.depSource=d.dep),d.intent&&(u.intent=d.intent),d.domain&&(u.domain=d.domain),d.owner&&(u.owner=d.owner),d.tags&&(u.tags=d.tags)}if(n.includeLocations&&f&&i.isCallExpression(f)){let d=f.getExpression();u.depLocation=ce(d)??I(d)}let p=Z(e);if(p){let d=V(p);d&&(u.jsdocDescription=d);let m=q(p);m&&(m.params?.length&&(u.jsdocParams=m.params),m.returns&&(u.jsdocReturns=m.returns),m.throws?.length&&(u.jsdocThrows=m.throws),m.example&&(u.jsdocExample=m.example))}return u}function We(e,t,n,r,o,i,s={isSagaWorkflow:!1},a={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:l}=N();i.parallelCount++;let c={id:C(),type:"parallel",mode:n,children:[],callee:n==="allSettled"?"step.allSettled":"step.parallel",location:r.includeLocations?I(e):void 0};if(t[0]&&t[1]&&(l.isStringLiteral(t[0])||!l.isObjectLiteralExpression(t[0])&&!l.isArrayLiteralExpression(t[0]))&&l.isObjectLiteralExpression(t[1])){let f=t[0];c.name=l.isStringLiteral(f)?f.getLiteralValue():f.getText();let p=t[1].getProperties();for(let d=0;d<p.length;d++){let m=p[d];if(l.isPropertyAssignment(m)){let y=m.getName(),w=m.getInitializer();if(w){let S=`parallel.${c.name??d}.`;if(l.isObjectLiteralExpression(w)){let g=w.getProperty("fn"),h=w.getProperty("errors");if(g&&l.isPropertyAssignment(g)){let k=g.getInitializer();if(k){let x=se(k,r,i,S);if(x){if(x.name=y,x.depSource=A(x.callee??""),h&&l.isPropertyAssignment(h)){let R=h.getInitializer();R&&(x.errors=B(R))}c.children.push(x);continue}}}}let b=se(w,r,i,S);if(b)b.name=y,b.depSource=A(b.callee??""),c.children.push(b);else{let g=O(w,r,o,i,s,a);if(g.length>0){let h=g[0];if(h.name=y,h.type==="step"){let k=h;k.stepId?.startsWith("implicit:")&&(k.stepId=S+(k.name??k.stepId.slice(9)))}c.children.push(h)}}}}}return c}if(t[0]&&l.isStringLiteral(t[0])){if(c.name=t[0].getLiteralValue(),t[1]){let f=O(t[1],r,o,i,s,a);if(f.length===1&&f[0].type==="parallel"){let u=f[0];return c.children=u.children,c.mode=u.mode,c}c.children.push(...f)}return c}if(t[0]&&!l.isObjectLiteralExpression(t[0])&&!l.isArrayLiteralExpression(t[0])&&t[1]){c.name=t[0].getText();let f=O(t[1],r,o,i,s,a);if(f.length===1&&f[0].type==="parallel"){let u=f[0];return c.children=u.children,c.mode=u.mode,c}return c.children.push(...f),c}return c}function Ln(e,t,n,r,o,i={isSagaWorkflow:!1},s={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:a}=N();o.loopCount++;let l={id:C(),type:"loop",loopType:"step.forEach",body:[],boundKnown:!1,location:n.includeLocations?I(e):void 0};if(t[0]&&a.isStringLiteral(t[0])&&(l.loopId=t[0].getLiteralValue(),l.name=l.loopId),t[1]&&(l.iterSource=t[1].getText()),t[2]&&a.isObjectLiteralExpression(t[2]))for(let c of t[2].getProperties()){if(!a.isPropertyAssignment(c))continue;let f=c.getName(),u=c.getInitializer();if(u){if(f==="maxIterations"&&a.isNumericLiteral(u))l.maxIterations=u.getLiteralValue(),l.boundKnown=!0,l.boundCount=l.maxIterations;else if(f==="stepIdPattern"){let p=E(u);p&&(l.stepIdPattern=p)}else if(f==="errors")l.errors=B(u);else if(f==="out"){let p=E(u);p&&(l.out=p)}else if(f==="collect"){let p=E(u);(p==="array"||p==="last")&&(l.collect=p)}else if(f==="run"&&(a.isArrowFunction(u)||a.isFunctionExpression(u))){let p=`forEach.${l.loopId??"forEach"}.`,d=se(u,n,o,p);if(d)!d.depSource&&d.callee&&(d.depSource=A(d.callee)),l.body=[d];else{let m=T(u.getBody(),n,r,o,i,s);l.body=m}}else if(f==="item"&&a.isCallExpression(u)){let p=u.getArguments();if(p[0]&&(a.isArrowFunction(p[0])||a.isFunctionExpression(p[0]))){let d=T(p[0].getBody(),n,r,o,i,s);l.body=d}}}}return l}function Dn(e,t,n,r,o,i={isSagaWorkflow:!1},s={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:a}=N();o.conditionalCount++;let l="<dynamic>",c="<dynamic>",f="<dynamic>",u,p,d,m=[],y=[];if(t[0]&&a.isStringLiteral(t[0])&&(l=t[0].getLiteralValue()),t[1]&&a.isObjectLiteralExpression(t[1]))for(let S of t[1].getProperties()){if(!a.isPropertyAssignment(S))continue;let b=S.getName(),g=S.getInitializer();if(g)if(b==="conditionLabel"){let h=E(g);h&&(c=h)}else if(b==="condition")a.isArrowFunction(g)||a.isFunctionExpression(g)?f=g.getBody().getText():f=g.getText();else if(b==="out")d=E(g);else if(b==="then"){let h=ut(g,n,r,o,i,s);h&&(m=h)}else if(b==="thenErrors")u=B(g);else if(b==="else"){let h=ut(g,n,r,o,i,s);h&&(y=h)}else b==="elseErrors"&&(p=B(g))}let w={id:C(),type:"decision",decisionId:l,conditionLabel:c,condition:f,consequent:m,alternate:y,location:n.includeLocations?I(e):void 0};return u&&m.length===1&&m[0].type==="step"&&(m[0].errors=u),p&&y.length===1&&y[0].type==="step"&&(y[0].errors=p),d&&(m.length===1&&m[0].type==="step"&&(m[0].out=d),y.length===1&&y[0].type==="step"&&(y[0].out=d)),w}function ut(e,t,n,r,o,i){let{Node:s}=N();if(s.isCallExpression(e)){let a=e.getExpression();if(s.isPropertyAccessExpression(a)&&a.getName()==="arm"){let l=e.getArguments();if(l[0]){if(s.isObjectLiteralExpression(l[0])){let c,f;for(let u of l[0].getProperties()){if(!s.isPropertyAssignment(u))continue;let p=u.getName(),d=u.getInitializer();p==="fn"&&d?c=d:p==="errors"&&d&&(f=B(d))}if(c){let u=Fe(c,t,r);return f&&u.length===1&&u[0].type==="step"&&(u[0].errors=f),u}}else if(s.isArrowFunction(l[0])||s.isFunctionExpression(l[0]))return Fe(l[0],t,r)}}}return s.isArrowFunction(e)||s.isFunctionExpression(e)?Fe(e,t,r):ie(e,t,r)}function Fe(e,t,n){let{Node:r}=N();if(r.isArrowFunction(e)||r.isFunctionExpression(e)){let o=e.getBody();for(;r.isParenthesizedExpression(o);)o=o.getExpression();if(r.isCallExpression(o))return ie(o,t,n);if(r.isBlock(o)){let i=o.getStatements();for(let s of i)if(r.isReturnStatement(s)){let a=s.getExpression();if(a&&r.isCallExpression(a))return ie(a,t,n)}}return ie(o,t,n)}return ie(e,t,n)}function ie(e,t,n){let{Node:r}=N();n.totalSteps++;let o,i,s;if(r.isCallExpression(e)){o=e.getExpression().getText();let l=o.match(/^(?:deps|ctx\.deps)\.([a-zA-Z_$][a-zA-Z0-9_$]*)/);l?(s=l[1],i=l[1]):i=o}else o=e.getText(),i=o;return[{id:C(),type:"step",stepId:`implicit:${i}`,callee:o,name:i,depSource:s,location:t.includeLocations?I(e):void 0}]}function $n(e){let{Node:t}=N();if(t.isArrowFunction(e)){let n=e.getBody();if(t.isCallExpression(n))return n.getExpression().getText();if(t.isBlock(n)){let r=n.getStatements();if(r.length===0)return"inline";if(r.length===1&&t.isReturnStatement(r[0])){let o=r[0].getExpression();if(o&&t.isCallExpression(o))return o.getExpression().getText()}return"inline"}}if(t.isFunctionExpression(e)){let n=e.getBody();if(!t.isBlock(n))return;let r=n.getStatements();if(r.length===0)return"inline";if(r.length===1&&t.isReturnStatement(r[0])){let o=r[0].getExpression();if(o&&t.isCallExpression(o))return o.getExpression().getText()}return"inline"}}function se(e,t,n,r){let{Node:o}=N(),i=(s,a,l)=>({id:C(),type:"step",stepId:r?r+s:`implicit:${s}`,location:t.includeLocations?I(l):void 0,callee:a,name:s});if(o.isArrowFunction(e)){let s=e.getBody();if(o.isCallExpression(s)){let a=s.getExpression().getText(),l=A(a);return n.totalSteps++,i(l,a,s)}}if(o.isFunctionExpression(e)){let s=e.getBody();if(!o.isBlock(s))return;let a=s.getStatements();if(a.length===1&&o.isReturnStatement(a[0])){let l=a[0].getExpression();if(l&&o.isCallExpression(l)){let c=l.getExpression().getText(),f=A(c);return n.totalSteps++,i(f,c,l)}}}}function pt(e,t,n,r,o,i,s={isSagaWorkflow:!1},a={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:l}=N();i.parallelCount++;let c={id:C(),type:"parallel",mode:n,children:[],callee:n==="all"?"allAsync":"allSettledAsync",location:r.includeLocations?I(e):void 0};if(t[0]&&l.isArrayLiteralExpression(t[0])){let f=t[0].getElements();for(let u=0;u<f.length;u++){let p=f[u],d=O(p,r,o,i,s,a);if(d.length>0){let m=`parallel.${u}.`;for(let y of d)if(y.type==="step"){let w=y;!w.depSource&&w.callee&&(w.depSource=A(w.callee)),w.stepId?.startsWith("implicit:")&&(w.stepId=m+(w.name??w.stepId.slice(9)))}d.length>1?c.children.push({id:C(),type:"sequence",children:d}):c.children.push(...d)}else if(l.isCallExpression(p)){let m=p.getExpression().getText(),y=A(m);i.totalSteps++;let w={id:C(),type:"step",stepId:`parallel.${u}.${y}`,location:r.includeLocations?I(p):void 0,callee:m,name:y,depSource:y};c.children.push(w)}}}return c}function Wn(e,t,n,r,o,i={isSagaWorkflow:!1},s={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:a}=N();o.raceCount++;let l={id:C(),type:"race",children:[],callee:"step.race",location:n.includeLocations?I(e):void 0};if(t[0]&&a.isArrayLiteralExpression(t[0])){let c=t[0].getElements();for(let f=0;f<c.length;f++){let u=c[f],p=`race.${f}.`,d=se(u,n,o,p);if(d)d.depSource=d.name??A(d.callee??""),l.children.push(d);else{let m=O(u,n,r,o,i,s);for(let y of m)if(y.type==="step"){let w=y;!w.depSource&&w.callee&&(w.depSource=A(w.callee)),w.stepId?.startsWith("implicit:")&&(w.stepId=p+(w.name??w.stepId.slice(9)))}l.children.push(...m)}}}else if(t[0]&&a.isObjectLiteralExpression(t[0])){for(let c of t[0].getProperties())if(a.isPropertyAssignment(c)){let f=c.getName(),u=c.getInitializer();if(u){let p=`race.${f}.`,d=se(u,n,o,p);if(d)d.name=f,d.depSource=f,l.children.push(d);else{let m=O(u,n,r,o,i,s);if(m.length>0){let y=m[0];if(y.name=f,y.type==="step"){let w=y;w.depSource=w.depSource??f,w.stepId?.startsWith("implicit:")&&(w.stepId=p+(w.name??w.stepId.slice(9)))}l.children.push(y)}}}}}return l}function Fn(e,t,n,r,o,i={isSagaWorkflow:!1},s={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:a}=N();o.raceCount++;let l={id:C(),type:"race",children:[],callee:"anyAsync",location:n.includeLocations?I(e):void 0};if(t[0]&&a.isArrayLiteralExpression(t[0]))for(let c of t[0].getElements()){let f=O(c,n,r,o,i,s);l.children.push(...f)}return l}function Pe(e,t,n,r){let{Node:o}=N();if(r.streamCount=(r.streamCount||0)+1,!o.isCallExpression(e))return{id:C(),type:"stream",streamType:t,callee:`step.${t==="write"?"getWritable":t==="read"?"getReadable":"streamForEach"}`,location:n.includeLocations?I(e):void 0};let i=e.getArguments(),s={id:C(),type:"stream",streamType:t,callee:e.getExpression().getText(),location:n.includeLocations?I(e):void 0};return i[0]&&o.isStringLiteral(i[0])&&(s.namespace=i[0].getLiteralValue()),s}function Q(e,t,n,r,o,i){let{Node:s}=N();i.totalSteps++;let a={id:C(),type:"saga-step",hasCompensation:!1,isTryStep:n,location:r.includeLocations?I(e):void 0},l=t[0],c=t[1],f=t[2];if(l){let p=E(l);p&&p!=="<dynamic>"&&(a.name=p)}if(c&&(a.callee=ae(c),a.callee&&(a.depSource=A(a.callee)),a.name||(a.name=a.callee)),f&&s.isObjectLiteralExpression(f)){let p=Pn(f);p.description&&(a.description=p.description),p.markdown&&(a.markdown=p.markdown),p.hasCompensation&&(a.hasCompensation=!0,a.compensationCallee=p.compensationCallee,i.compensatedStepCount=(i.compensatedStepCount||0)+1)}let u=Z(e);if(u){let p=V(u);p&&(a.jsdocDescription=p);let d=q(u);d&&(d.params?.length&&(a.jsdocParams=d.params),d.returns&&(a.jsdocReturns=d.returns),d.throws?.length&&(a.jsdocThrows=d.throws),d.example&&(a.jsdocExample=d.example))}return a}function Pn(e){let{Node:t}=N(),n={description:void 0,markdown:void 0,hasCompensation:!1,compensationCallee:void 0};if(!t.isObjectLiteralExpression(e))return n;for(let r of e.getProperties()){if(!t.isPropertyAssignment(r))continue;let o=r.getName(),i=r.getInitializer();if(o!=="name"){if(o==="description"&&i)n.description=E(i);else if(o==="markdown"&&i)n.markdown=E(i);else if(o==="compensate"&&i&&(n.hasCompensation=!0,t.isArrowFunction(i)||t.isFunctionExpression(i))){let s=i.getBody();if(t.isCallExpression(s))n.compensationCallee=s.getExpression().getText();else if(t.isBlock(s)){let a=s.getStatements().find(l=>t.isReturnStatement(l));if(a&&t.isReturnStatement(a)){let l=a.getExpression();l&&t.isCallExpression(l)&&(n.compensationCallee=l.getExpression().getText())}}}}}return n}function vn(e,t,n,r,o={isSagaWorkflow:!1},i={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:s}=N();if(!s.isIfStatement(e))return;let a=e.getExpression(),l=a.getText(),c=e.getThenStatement(),f=e.getElseStatement(),u=T(c,t,n,r,o,i),p=f?T(f,t,n,r,o,i):void 0;if(i.isInWorkflowCallback)r.conditionalCount++;else{if(u.length===0&&(!p||p.length===0))return;r.conditionalCount++}if(u.length===0&&(!p||p.length===0))return;let d;try{let y=a.getType();y&&(d=y.getText())}catch{}let m=On(a,i);return m?{id:C(),type:"decision",decisionId:m.decisionId,conditionLabel:m.conditionLabel,condition:m.condition,consequent:u,alternate:p,location:t.includeLocations?I(e):void 0,conditionType:d}:{id:C(),type:"conditional",condition:l,helper:null,consequent:u,alternate:p,location:t.includeLocations?I(e):void 0,conditionType:d}}function On(e,t){let{Node:n}=N();if(!n.isCallExpression(e))return;let r=e.getExpression();if(!n.isPropertyAccessExpression(r))return;let o=r.getName(),i=r.getExpression();if(o!=="if"&&o!=="label"||!t.stepNames.has(i.getText()))return;let s=e.getArguments();if(s.length<3||!n.isStringLiteral(s[0]))return;let a=s[0].getLiteralValue();if(!n.isStringLiteral(s[1]))return;let l=s[1].getLiteralValue(),c=s[2].getText();return(n.isArrowFunction(s[2])||n.isFunctionExpression(s[2]))&&(c=s[2].getBody().getText()),{decisionId:a,conditionLabel:l,condition:c}}function Mn(e,t,n,r,o={isSagaWorkflow:!1},i={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:s}=N();if(!s.isSwitchStatement(e))return;let a=e.getExpression().getText(),l=e.getClauses(),c=[],f=!1;for(let u of l){let p=s.isDefaultClause(u),d;s.isCaseClause(u)&&(d=u.getExpression().getText());let m=u.getStatements(),y=[];for(let w of m){let S=T(w,t,n,r,o,i);y.push(...S)}y.length>0&&(f=!0),c.push({value:d,isDefault:p,body:y})}if(i.isInWorkflowCallback)r.conditionalCount++;else if(f)r.conditionalCount++;else return;if(f)return{id:C(),type:"switch",expression:a,cases:c,location:t.includeLocations?I(e):void 0}}function jn(e,t,n,r,o,i,s={isSagaWorkflow:!1},a={stepNames:new Set(["step"]),isInWorkflowCallback:!0,depth:0}){i.conditionalCount++;let l={id:C(),type:"conditional",condition:n[0]?.getText()??"<unknown>",helper:t,consequent:[],location:r.includeLocations?I(e):void 0};return n[1]&&(l.consequent=O(n[1],r,o,i,s,a)),(t==="whenOr"||t==="unlessOr")&&n[2]&&(l.defaultValue=n[2].getText()),l}function zn(e,t,n,r,o={isSagaWorkflow:!1},i={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:s}=N();if(!s.isForStatement(e))return;let a=e.getStatement(),l=T(a,t,n,r,o,i);if(i.isInWorkflowCallback)r.loopCount++;else{if(l.length===0)return;r.loopCount++}if(l.length!==0)return{id:C(),type:"loop",loopType:"for",body:l,boundKnown:!1,location:t.includeLocations?I(e):void 0}}function _n(e,t,n,r,o={isSagaWorkflow:!1},i={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:s}=N();if(!s.isForOfStatement(e))return;let a=e.getStatement(),l=T(a,t,n,r,o,i);if(i.isInWorkflowCallback)r.loopCount++;else{if(l.length===0)return;r.loopCount++}if(l.length!==0)return{id:C(),type:"loop",loopType:"for-of",iterSource:e.getExpression().getText(),body:l,boundKnown:!1,location:t.includeLocations?I(e):void 0}}function Bn(e,t,n,r,o={isSagaWorkflow:!1},i={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:s}=N();if(!s.isForInStatement(e))return;let a=e.getStatement(),l=T(a,t,n,r,o,i);if(i.isInWorkflowCallback)r.loopCount++;else{if(l.length===0)return;r.loopCount++}if(l.length!==0)return{id:C(),type:"loop",loopType:"for-in",iterSource:e.getExpression().getText(),body:l,boundKnown:!1,location:t.includeLocations?I(e):void 0}}function qn(e,t,n,r,o={isSagaWorkflow:!1},i={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:s}=N();if(!s.isWhileStatement(e))return;let a=e.getStatement(),l=T(a,t,n,r,o,i);if(i.isInWorkflowCallback)r.loopCount++;else{if(l.length===0)return;r.loopCount++}if(l.length!==0)return{id:C(),type:"loop",loopType:"while",body:l,boundKnown:!1,location:t.includeLocations?I(e):void 0}}function Vn(e,t,n,r,o){o.workflowRefCount++;let i=t.replace(/\.runWithState$/,"").replace(/\.run$/,"");return{id:C(),type:"workflow-ref",workflowName:i,resolved:!1,location:n.includeLocations?I(e):void 0}}function Kn(e){let{Node:t}=N();if(!t.isCallExpression(e))return!1;let n=e.getArguments();if(n.length===0)return!1;let r=n[0];if(t.isArrowFunction(r)||t.isFunctionExpression(r)){let i=r.getParameters().map(s=>s.getText()).join(",");return i.includes("step")||i.includes("deps"),!0}return!1}function Un(e){let{Node:t}=N(),n=[];if(!t.isObjectLiteralExpression(e))return n;for(let r of e.getProperties())(t.isPropertyAssignment(r)||t.isShorthandPropertyAssignment(r))&&n.push(r.getName());return n}function Jn(e,t){let{Node:n}=N(),r=[];if(!n.isObjectLiteralExpression(e))return r;for(let o of e.getProperties()){let i,s,a;if(n.isPropertyAssignment(o)){i=o.getName();let c=o.getInitializer();if(c&&typeof c.getType=="function")try{let f=c.getType();s=f.getText(),a=mt(c,f)}catch{}}else if(n.isShorthandPropertyAssignment(o)){i=o.getName();let c=o.getNameNode();if(c&&typeof c.getType=="function")try{let f=c.getType();s=f.getText(),a=mt(c,f)}catch{}}else continue;let l=tr(s);r.push({name:i,typeSignature:s,errorTypes:l,signature:a})}return r}function Gn(e){let t=new Map(e.dependencies.map(r=>[r.name,r]));function n(r){if(r.type==="step"){let o=r,i=o.reads,s=o.callee??o.name;if(i?.length&&s){let l=(t.get(s)??t.get(A(s)))?.signature;if(l?.params?.length){let c={},f=o.readParamIndices;i.forEach((u,p)=>{let d=f?.[p];if(d===void 0)return;let m=l.params[d];m?.type&&(c[u]=m.type)}),Object.keys(c).length>0&&(o.readTypes=c)}}}for(let o of P(r))n(o)}for(let r of e.children)n(r)}function Hn(e){let t=new Map(e.dependencies.map(r=>[r.name,r]));function n(r){if(r.type==="step"){let o=r;if(o.outputTypeInfo)return;let i=o.callee??o.name;if(!i)return;let a=(t.get(i)??t.get(A(i)))?.signature;if(!a?.returnType)return;let l=or(a.returnType.display);l&&(o.outputTypeInfo=l.okType,o.errorTypeInfo=l.errorType,o.causeTypeInfo=l.causeType,o.outputTypeKind="declared")}for(let o of P(r))n(o)}for(let r of e.children)n(r)}function Zn(e){function t(n){if(n.type==="step"){let r=n;if(r.errors!==void 0)return;let o=r.errorTypeInfo?.display;if(!o||o==="unknown"||o==="never")return;let i=Yn(o).filter(s=>s&&s!=="unknown"&&s!=="never");i.length>0&&(r.errors=i,r.errorsSource="inferred")}for(let r of P(n))t(r)}for(let n of e.children)t(n)}function Yn(e){let t=[],n=0,r=null,o=0;for(let i=0;i<e.length;i++){let s=e[i];if(r){if(s==="\\"){i++;continue}s===r&&(r=null);continue}if(s==='"'||s==="'"||s==="`"){r=s;continue}s==="<"||s==="("||s==="{"||s==="["?n++:s===">"||s===")"||s==="}"||s==="]"?n--:s==="|"&&n===0&&(t.push(e.slice(o,i).trim()),o=i+1)}return t.push(e.slice(o).trim()),t}var Qn=new Set(["step.sleep","step.withResource","step.retry","step.withTimeout","step.try","step.fromResult"]);function Xn(e){function t(n){if(n.type==="step"){let r=n;if(!r.callee)return;let o=A(r.callee);Qn.has(r.callee)?r.stepKind||(r.stepKind=o):r.depSource||(r.depSource=o)}for(let r of P(n))t(r)}for(let n of e.children)t(n)}function mt(e,t){let n=rt(),r=e.compilerNode;if(!r)return;let o=r.kind,i=o===n.SyntaxKind.FunctionDeclaration||o===n.SyntaxKind.ArrowFunction||o===n.SyntaxKind.FunctionExpression||o===n.SyntaxKind.MethodDeclaration;try{let l=e.getSourceFile().getProject().getTypeChecker().compilerObject,c;if(i)c=l.getSignatureFromDeclaration(r);else if(o===n.SyntaxKind.Identifier){let w=t.compilerType.getCallSignatures?.();c=w?.length?w[0]:void 0}if(!c)return;let f=c.getParameters().map((y,w)=>{let S=y.valueDeclaration,b=S?l.getTypeOfSymbolAtLocation(y,S):l.getAnyType(),g=l.typeToString(b);return{name:y.getName()??`param${w}`,type:{display:g,canonical:g.replace(/\s+/g," ").trim(),kind:"plain",confidence:"exact",source:"checker"}}}),u=c.getReturnType(),p=l.typeToString(u),d={display:p,canonical:p.replace(/\s+/g," ").trim(),kind:er(p),confidence:"exact",source:"checker"},m=he(u,l);return{params:f,returnType:d,resultLike:m?{okType:m.okType,errorType:m.errorType,causeType:m.causeType}:void 0}}catch{return}}function er(e){return e.includes("AsyncResult")?"asyncResult":e.includes("Promise<Result")?"promiseResult":e.includes("Result")?"result":"plain"}function tr(e){if(!e)return[];let t=e.match(/Result\s*</);if(!t)return[];let n=t.index+t[0].length,r=1,o=n,i=-1;for(;o<e.length&&r>0;){let l=e[o];l==="<"||l==="["||l==="{"||l==="("?r++:l===">"||l==="]"||l==="}"||l===")"?r--:l===","&&r===1&&i<0&&(i=o),o++}return i<0||r!==0?[]:e.slice(i+1,o-1).trim().split(/\s*\|\s*/).map(l=>l.trim().replace(/^["']|["']$/g,"")).filter(l=>l.length>0&&/^[A-Z_][A-Z0-9_]*$/i.test(l))}function nr(e){let t=new Set;for(let n of e)for(let r of n.errorTypes)t.add(r);return Array.from(t)}function ne(e){let{Node:t}=N(),n={};if(!t.isObjectLiteralExpression(e))return n;for(let r of e.getProperties()){if(!t.isPropertyAssignment(r))continue;let o=r.getName(),i=r.getInitializer();o!=="name"&&(o==="key"&&i?n.key=E(i):o==="description"&&i?n.description=E(i):o==="markdown"&&i?n.markdown=E(i):o==="retry"&&i&&t.isObjectLiteralExpression(i)?n.retry=It(i):o==="timeout"&&i&&t.isObjectLiteralExpression(i)?n.timeout=Tt(i):o==="errors"&&i?n.errors=B(i):o==="out"&&i?n.out=E(i):o==="dep"&&i?n.dep=E(i):o==="reads"&&i?n.reads=X(i):o==="intent"&&i?n.intent=E(i):o==="domain"&&i?n.domain=E(i):o==="owner"&&i?n.owner=E(i):o==="tags"&&i?n.tags=X(i):o==="stateChanges"&&i?n.stateChanges=X(i):o==="emits"&&i?n.emits=X(i):o==="calls"&&i?n.calls=X(i):o==="errorMeta"&&i&&t.isObjectLiteralExpression(i)?n.errorMeta=rr(i):o==="ttl"&&i&&(n.ttl=ee(i)))}return n}function rr(e){let{Node:t}=N();if(!t.isObjectLiteralExpression(e))return;let n={};for(let r of e.getProperties()){if(!t.isPropertyAssignment(r))continue;let o=r.getName(),i=r.getInitializer();if(!i||!t.isObjectLiteralExpression(i))continue;let s={};for(let a of i.getProperties()){if(!t.isPropertyAssignment(a))continue;let l=a.getName(),c=a.getInitializer();if(c){if(l==="retryable")s.retryable=je(c);else if(l==="severity"){let f=E(c);f&&f!=="<dynamic>"&&(s.severity=f)}else if(l==="description"){let f=E(c);f&&f!=="<dynamic>"&&(s.description=f)}}}n[o]=s}return Object.keys(n).length>0?n:void 0}function X(e){let{Node:t}=N();if(t.isArrayLiteralExpression(e)){let n=[];for(let r of e.getElements()){let o=E(r);o&&o!=="<dynamic>"&&n.push(o)}return n.length>0?n:void 0}if(t.isIdentifier(e)){let n=xt(e);if(n)return X(n)}}function B(e){let{Node:t}=N();if(t.isArrayLiteralExpression(e)){let n=[];for(let r of e.getElements()){let o=E(r);o&&o!=="<dynamic>"&&n.push(o)}return n}if(t.isCallExpression(e)){let r=e.getExpression().getText();if(r==="tags"||r==="err"){let o=[];for(let i of e.getArguments()){let s=E(i);s&&s!=="<dynamic>"&&o.push(s)}return o}}if(t.isIdentifier(e)){let n=xt(e);if(n)return B(n)}}function xt(e){let{Node:t}=N();if(!t.isIdentifier(e))return;let n=e.getSourceFile(),r=e.getText();for(let o of n.getStatements())if(t.isVariableStatement(o)){let i=o.getDeclarationList();if(i.getDeclarationKind()!=="const")continue;for(let s of i.getDeclarations())if(s.getName()===r)return s.getInitializer()}}function It(e){let{Node:t}=N(),n={};if(!t.isObjectLiteralExpression(e))return n;for(let r of e.getProperties()){if(!t.isPropertyAssignment(r))continue;let o=r.getName(),i=r.getInitializer();if(o==="attempts"&&i)n.attempts=ee(i);else if(o==="backoff"&&i){let s=E(i);s==="fixed"||s==="linear"||s==="exponential"?n.backoff=s:n.backoff="<dynamic>"}else o==="baseDelay"&&i?n.baseDelay=ee(i):o==="retryOn"&&i?n.retryOn=i.getText():o==="initialDelay"&&i?n.initialDelay=ee(i):o==="maxDelay"&&i?n.maxDelay=ee(i):o==="jitter"&&i&&(n.jitter=je(i)??"<dynamic>")}return n}function Tt(e){let{Node:t}=N(),n={};if(!t.isObjectLiteralExpression(e))return n;for(let r of e.getProperties()){if(!t.isPropertyAssignment(r))continue;let o=r.getName(),i=r.getInitializer();if(o==="ms"&&i)n.ms=ee(i);else if(o==="signal"&&i)n.signal=je(i)??"<dynamic>";else if(o==="onTimeout"&&i){let s=E(i);s==="error"||s==="option"||s==="disconnect"?n.onTimeout=s:n.onTimeout="<dynamic>"}}return n}function E(e){let{Node:t}=N();return t.isStringLiteral(e)?e.getLiteralValue():t.isTemplateExpression(e)?"<dynamic>":t.isNoSubstitutionTemplateLiteral(e)?e.getLiteralValue():e.getText()}function ee(e){let{Node:t}=N();return t.isNumericLiteral(e)?e.getLiteralValue():"<dynamic>"}function je(e){let{Node:t}=N();if(t.isTrueLiteral(e))return!0;if(t.isFalseLiteral(e))return!1}function ae(e){let{Node:t}=N();if(t.isArrowFunction(e)||t.isFunctionExpression(e)){let n=e.getBody();if(t.isCallExpression(n))return n.getExpression().getText();if(t.isBlock(n)){for(let r of n.getStatements())if(t.isReturnStatement(r)){let o=r.getExpression();if(o&&t.isCallExpression(o))return o.getExpression().getText();break}}return n?.getText()??"<unknown>"}return t.isCallExpression(e)?e.getExpression().getText():e.getText()}function I(e){let t=e.getSourceFile(),n=e.getStart(),r=e.getEnd(),o=t.getLineAndColumnAtPos(n),i=t.getLineAndColumnAtPos(r);return{filePath:t.getFilePath(),line:o.line,column:o.column-1,endLine:i.line,endColumn:i.column-1}}function le(e,t,n){let{Node:r}=N();if(!(!t||!r.isCallExpression(t)))try{let s=e.getSourceFile().getProject().getTypeChecker().compilerObject,a=t.compilerNode,l=t.getType(),c=l.compilerType;n.outputType=l.getText();let f=he(c,s);if(!f||n.outputType==="any"||n.outputType==="unknown"){let d=a.expression,w=(s.getTypeAtLocation(d).getCallSignatures?.()??[])[0];if(w){let S=w.getReturnType(),b=s.typeToString(S);n.outputType=b,f=he(S,s)}}f?(n.outputTypeInfo=f.okType,n.errorTypeInfo=f.errorType,n.causeTypeInfo=f.causeType,n.outputTypeKind="declared"):n.outputTypeKind=n.outputType==="any"?"unknown":"inferred";let p=s.getResolvedSignature(a);if(!p){let d=a.expression;p=(s.getTypeAtLocation(d).getCallSignatures?.()??[])[0]}if(p){let d=p.getDeclaration();if(d&&"parameters"in d&&Array.isArray(d.parameters)){let m=d.parameters;if(m.length>0){let y=m.map(w=>w.type?s.getTypeFromTypeNode(w.type):null).filter(w=>w!=null).map(w=>s.typeToString(w));y.length>0&&(n.inputType=y.join(", "))}}}}catch{}}function or(e){let t=e,n=e.match(/^Promise<\s*([\s\S]+)\s*>$/);n&&(t=n[1].trim());let r,o,i=t.indexOf("AsyncResult<"),s=t.indexOf("Result<");if(i!==-1)r="asyncResult",o=i+12;else if(s!==-1)r=n?"promiseResult":"result",o=s+7;else return null;let a=1,l=o;for(let u=o;u<t.length;u++){let p=t[u];if(p==="<"||p==="("||p==="{"||p==="[")a++;else if((p===">"||p===")"||p==="}"||p==="]")&&(a--,a===0)){l=u;break}}let c=t.slice(o,l),f=ir(c);return f.length<2?null:{okType:ve(f[0],r),errorType:ve(f[1],r),causeType:f[2]?ve(f[2],r):void 0}}function ir(e){let t=[],n=0,r=null,o=0;for(let i=0;i<e.length;i++){let s=e[i];if(r){if(s==="\\"){i++;continue}s===r&&(r=null);continue}if(s==='"'||s==="'"||s==="`"){r=s;continue}s==="<"||s==="("||s==="{"||s==="["?n++:s===">"||s===")"||s==="}"||s==="]"?n--:s===","&&n===0&&(t.push(e.slice(o,i).trim()),o=i+1)}return t.push(e.slice(o).trim()),t}function ve(e,t){return{display:e,canonical:e.replace(/\s+/g," ").trim(),kind:"plain",confidence:"inferred",source:"checker"}}function ke(e){if(!e)return{operation:void 0};let{Node:t}=N();if(!t.isCallExpression(e))return{operation:e};let n=e.getExpression();if(!t.isPropertyAccessExpression(n)||n.getName()!=="dep")return{operation:e};let r=e.getArguments(),o;return r[0]&&t.isStringLiteral(r[0])&&(o=r[0].getLiteralValue()),{operation:r[1]??e,depSourceOverride:o}}function be(e){let{Node:t}=N();if(!e)return;let n;if(t.isArrowFunction(e)||t.isFunctionExpression(e)){for(n=e.getBody();t.isParenthesizedExpression(n);)n=n.getExpression();if(t.isCallExpression(n))return n;if(t.isBlock(n)){for(let r of n.getStatements())if(t.isReturnStatement(r)){let o=r.getExpression();if(o&&t.isCallExpression(o))return o;break}}}else if(t.isCallExpression(e))return e}function xe(e){if(!e)return;let t=e.match(/^(?:deps|ctx\.deps)\.([a-zA-Z_$][a-zA-Z0-9_$]*)/);return t?t[1]:void 0}function ce(e){let{Node:t}=N();try{let r=e.getSourceFile().getProject().getTypeChecker(),o=e,i=r.getSymbolAtLocation(o);if(!i&&t.isPropertyAccessExpression(e)){let m=e.getNameNode();m&&(i=r.getSymbolAtLocation(m))}if(!i){let m=e.getType().compilerType;if(m){let y=m.getSymbol?.()??m.symbol;y&&(i=y)}}if(!i)return;let s=i.getDeclarations();if(!s?.length)return;let a=s[0],l=a.compilerNode??a,c=l.getSourceFile(),f=l.getStart(),u=l.getEnd(),p=c.getLineAndCharacterOfPosition(f),d=c.getLineAndCharacterOfPosition(u);return{filePath:c.fileName,line:p.line+1,column:p.character,endLine:d.line+1,endColumn:d.character}}catch{return}}function Z(e){let{Node:t}=N(),n=e;for(;n;){let r=n.getParent();if(!r)return n;if(t.isExpressionStatement(r)||t.isVariableStatement(r))return r;if(t.isBlock(r))return n;n=r}}function Oe(e){return e.replace(/^\s*\/\*\*?\s*/,"").replace(/\s*\*\/\s*$/,"").replace(/^\s*\*\s?/gm,`
|
|
22
|
-
`).trim().split(/\s*@/)[0].trim()||void 0}function
|
|
21
|
+
Check the path or omit tsConfigPath to use default.`)}function bt(e,t={}){gn(e),hn(t);let n={...kt,...t},{ts:r}=N(),s=yn(n).addSourceFileAtPath(e),i=It(s,n);if(i.length===0)return[];let a=[];for(let l of i){let c=[],u=$t(),d=Ct(l,s,n,c,u);a.push({root:d,metadata:{analyzedAt:Date.now(),filePath:e,tsVersion:r.version,warnings:c,stats:u},references:new Map})}return a}function ne(e,t,n={}){let r={...kt,assumeImported:!0,...n},{ts:o,Project:s}=N(),a=new s({useInMemoryFileSystem:!0,compilerOptions:{target:o.ScriptTarget.ESNext,module:o.ModuleKind.ESNext,moduleResolution:o.ModuleResolutionKind.Bundler,strict:!0,esModuleInterop:!0}}).createSourceFile("workflow.ts",e),l=It(a,r);if(l.length===0)return[];let c=t?l.filter(d=>d.name===t):l,u=[];for(let d of c){let p=[],f=$t(),m=Ct(d,a,r,p,f);u.push({root:m,metadata:{analyzedAt:Date.now(),filePath:"<source>",tsVersion:o.version,warnings:p,stats:f},references:new Map})}return u}function yn(e){let{Project:t,ts:n}=N();try{return new t({tsConfigFilePath:e.tsConfigPath,skipAddingFilesFromTsConfig:!0})}catch{return new t({compilerOptions:{target:n.ScriptTarget.ESNext,module:n.ModuleKind.ESNext,moduleResolution:n.ModuleResolutionKind.Bundler,strict:!0,esModuleInterop:!0}})}}function xt(e){let{Node:t}=N(),n=e;for(;t.isParenthesizedExpression(n);)n=n.getExpression();return n.getText()}function ke(e){let{Node:t}=N(),n=e;for(;t.isParenthesizedExpression(n);)n=n.getExpression();return n}function Ne(e){let{Node:t}=N(),n=e;for(;;){for(;t.isParenthesizedExpression(n);)n=n.getExpression();if(t.isAwaitExpression(n)){n=n.getExpression();continue}break}return t.isIdentifier(n)?n:void 0}function It(e,t){let{Node:n}=N(),r=[],o=Sn(e,t),s=wn(e);function i(a){if(a)return n.isStringLiteral(a)||n.isNoSubstitutionTemplateLiteral(a)?a.getLiteralText():a.getText()}return e.forEachDescendant(a=>{if(!n.isCallExpression(a))return;let l=a.getExpression(),c=ke(l),u=xt(l),d=n.isPropertyAccessExpression(c)?c.getExpression().getText():"",p=o.namespaceImports.has(d)||o.defaultImports.has(d);if((u==="createWorkflow"||o.namedImportAliases.get(u)==="createWorkflow"||n.isPropertyAccessExpression(c)&&c.getName()==="createWorkflow"&&p)&&(t.detect==="all"||t.detect==="createWorkflow")&&(o.namedImports.has("createWorkflow")||o.namespaceImports.size>0||o.defaultImports.size>0||t.assumeImported)){let S=a.getArguments(),b=a.getParent(),g,y,k,x;if(n.isVariableDeclaration(b)?(g=b.getName(),y=b):n.isPropertyAssignment(b)&&(g=b.getName()),S.length>=1&&S[0]){let R=i(S[0])??g??"anonymous";k=S.length>=2?S[1]:void 0,S.length>=3&&S[2]&&n.isObjectLiteralExpression(S[2])&&(x=S[2]),r.push({name:R,bindingName:g,callExpression:a,depsObject:k,optionsObject:x,callbackFunction:void 0,variableDeclaration:y,source:"createWorkflow"})}}if((u==="createSagaWorkflow"||o.namedImportAliases.get(u)==="createSagaWorkflow"||n.isPropertyAccessExpression(c)&&c.getName()==="createSagaWorkflow"&&p)&&(t.detect==="all"||t.detect==="createSagaWorkflow")&&(o.namedImports.has("createSagaWorkflow")||o.namespaceImports.size>0||o.defaultImports.size>0||t.assumeImported)){let S=a.getArguments(),b=a.getParent(),g,y,k,x;if(n.isVariableDeclaration(b)?(g=b.getName(),y=b):n.isPropertyAssignment(b)&&(g=b.getName()),S.length>=2&&S[0]){let R=i(S[0])??g??"anonymous";k=S[1],S[2]&&n.isObjectLiteralExpression(S[2])&&(x=S[2]),r.push({name:R,callExpression:a,bindingName:g,depsObject:k,optionsObject:x,callbackFunction:void 0,variableDeclaration:y,source:"createSagaWorkflow"})}}if((u==="runSaga"||o.namedImportAliases.get(u)==="runSaga"||n.isPropertyAccessExpression(c)&&c.getName()==="runSaga"&&p)&&(t.detect==="all"||t.detect==="createSagaWorkflow")&&(o.namedImports.has("runSaga")||o.namespaceImports.size>0||o.defaultImports.size>0||t.assumeImported)){let S=a.getArguments(),b=a.getStartLineNumber(),g=e.getFilePath(),y=g.includes("/")&&g.split("/").pop()||g;r.push({name:`runSaga@${y}:${b}`,callExpression:a,depsObject:void 0,optionsObject:void 0,callbackFunction:S[0],variableDeclaration:void 0,source:"runSaga"})}if((u==="run"||o.namedImportAliases.get(u)==="run"||n.isPropertyAccessExpression(c)&&c.getName()==="run"&&p)&&(t.detect==="all"||t.detect==="run")){let S=o.namedImports.has("run")||o.namedImportAliases.get(u)==="run"||o.namespaceImports.size>0||o.defaultImports.size>0||t.assumeImported,b=Nn("run",a,s),g=n.isPropertyAccessExpression(c)&&p;if(S&&!b&&(g||!n.isPropertyAccessExpression(c))){let y=a.getArguments(),k=a.getStartLineNumber(),x=e.getFilePath(),R=x.includes("/")&&x.split("/").pop()||x;r.push({name:`run@${R}:${k}`,callExpression:a,depsObject:void 0,optionsObject:void 0,callbackFunction:y[0],variableDeclaration:void 0,source:"run"})}}}),r}function Sn(e,t){let n={namedImports:new Set,namedImportAliases:new Map,namespaceImports:new Set,defaultImports:new Set};for(let r of e.getImportDeclarations()){let o=r.getModuleSpecifierValue();if(o==="awaitly"||o.startsWith("awaitly/")){if(r.isTypeOnly())continue;let s=r.getNamedImports();for(let l of s){if(l.isTypeOnly())continue;let c=l.getName(),u=l.getAliasNode(),d=u?u.getText():c;n.namedImports.add(c),n.namedImportAliases.set(d,c)}let i=r.getDefaultImport();i&&n.defaultImports.add(i.getText());let a=r.getNamespaceImport();a&&n.namespaceImports.add(a.getText())}}return n}function wn(e){let{Node:t}=N(),n=new Map,r=(s,i)=>{let a=n.get(s)||[];a.push(i),n.set(s,a)},o=(s,i)=>{if(t.isIdentifier(s))r(s.getText(),i);else if(t.isObjectBindingPattern(s))for(let a of s.getElements()){let l=a.getNameNode();o(l,i)}else if(t.isArrayBindingPattern(s)){for(let a of s.getElements())if(t.isBindingElement(a)){let l=a.getNameNode();o(l,i)}}};return e.forEachDescendant(s=>{if(t.isVariableDeclaration(s)){let i=s.getNameNode();o(i,s)}else if(t.isFunctionDeclaration(s)){let i=s.getName();i&&r(i,s)}else if(t.isParameterDeclaration(s)){let i=s.getNameNode();o(i,s)}}),n}function Nn(e,t,n){let{Node:r}=N(),o=n.get(e);if(!o||o.length===0)return!1;let s=t.getStart();for(let i of o){if(!i.getParent())continue;let l=Tt(i);if((r.isVariableDeclaration(i)?i.getVariableStatement()?.getDeclarationKind():void 0)==="var"){let d=qe(i),p=qe(t);if(d===p)return!0}else if(l&&kn(l,t)&&i.getEnd()<=s)return!0}return!1}function Tt(e){let{Node:t}=N(),n=e.getParent();for(;n;){if(t.isBlock(n)||t.isFunctionDeclaration(n)||t.isArrowFunction(n)||t.isFunctionExpression(n)||t.isSourceFile(n))return n;n=n.getParent()}}function qe(e){let{Node:t}=N(),n=e.getParent();for(;n;){if(t.isFunctionDeclaration(n)||t.isArrowFunction(n)||t.isFunctionExpression(n)||t.isSourceFile(n))return n;n=n.getParent()}}function kn(e,t){let n=t.getParent();for(;n;){if(n===e)return!0;n=n.getParent()}return!1}function Ct(e,t,n,r,o){let{name:s,callExpression:i,depsObject:a,optionsObject:l,source:c}=e;(c==="createSagaWorkflow"||c==="runSaga")&&(o.sagaWorkflowCount=(o.sagaWorkflowCount||0)+1);let u=a?Qn(a,r):[],d=ar(u),p=l?dt(l):{description:void 0,markdown:void 0},f=a?dt(a):{description:void 0,markdown:void 0},m={description:p.description||f.description,markdown:p.markdown||f.markdown},h=l?pt(l):a?pt(a):{strict:void 0,declaredErrors:void 0},w=c==="createSagaWorkflow"||c==="runSaga",S={isSagaWorkflow:w},b=[],g;if(c==="run"||c==="runSaga"){if(g=e.callbackFunction,e.callbackFunction){c==="runSaga"&&(S.sagaParamInfo=mt(e.callbackFunction));let k=ft(e.callbackFunction),x=ht(e.callbackFunction,n,r,o,S,k);b.push(...x)}}else{let k=xn(e,t);k.length>0&&k[0].callbackArg&&(g=k[0].callbackArg);for(let x of k){let R=x.callbackArg;if(R){w&&(S.sagaParamInfo=mt(R));let P=ft(R),rt=ht(R,n,r,o,S,P);b.push(...rt)}}}let y={id:C(),type:"workflow",workflowName:s,source:c,dependencies:u,errorTypes:d,children:b,description:m.description,markdown:m.markdown,location:n.includeLocations?I(i):void 0,strict:h.strict,declaredErrors:h.declaredErrors};try{let k=g&&bn(g,t);if(k)y.workflowReturnType=k;else if(g){let x=Rt(g);x&&(y.workflowReturnType=x)}}catch{}if(Xn(y),er(y),tr(y),or(y),e.variableDeclaration){let k=e.variableDeclaration,x=typeof k.getVariableStatement=="function"?k.getVariableStatement():(()=>{let{Node:R}=N(),P=e.variableDeclaration.getParent();return R.isVariableStatement(P)?P:e.variableDeclaration})();if(x){let R=V(x);R&&(y.jsdocDescription=R);let P=U(x);P&&(P.params?.length&&(y.jsdocParams=P.params),P.returns&&(y.jsdocReturns=P.returns),P.throws?.length&&(y.jsdocThrows=P.throws),P.example&&(y.jsdocExample=P.example))}}return y}function ft(e){let{Node:t}=N(),n=[];if((t.isArrowFunction(e)||t.isFunctionExpression(e))&&(n=e.getParameters()),n.length===0)return;let r=n[0];if(!t.isParameterDeclaration(r))return;let o=r.getNameNode();if(t.isObjectBindingPattern(o)){let s={isDestructured:!0};for(let i of o.getElements()){let a=i.getPropertyNameNode()?.getText()||i.getName(),l=i.getName();a==="step"&&(s.stepAlias=l)}return s}return{name:o.getText(),isDestructured:!1}}function bn(e,t){let{Node:n}=N(),r=e;for(;n.isParenthesizedExpression(r);)r=r.getExpression();try{let i=t.getProject().getTypeChecker().compilerObject,a=r.compilerNode,u=(i.getTypeAtLocation(a).getCallSignatures?.()??[])[0];if(!u)return;let d=u.getReturnType();return i.typeToString(d)}catch{return}}function Rt(e){if(!e)return;let{Node:t}=N(),n=e;for(;t.isParenthesizedExpression(n);)n=n.getExpression();if(t.isArrowFunction(n)||t.isFunctionExpression(n))return n.getReturnType?.()?.getText();if(t.isIdentifier(n)){let o=n.getDefinitionNodes?.();if(!o?.length)return;for(let s of o){if(t.isVariableDeclaration(s)){let i=s.getInitializer();if(!i)break;if(t.isArrowFunction(i)||t.isFunctionExpression(i)){let a=i.getReturnType?.();if(a)return a.getText()}else if(t.isIdentifier(i))return Rt(i);break}if(t.isFunctionDeclaration(s)){let i=s.getReturnType?.();if(i)return i.getText();break}}}}function dt(e){let{Node:t}=N(),n={};if(!t.isObjectLiteralExpression(e))return n;for(let r of e.getProperties()){if(!t.isPropertyAssignment(r))continue;let o=r.getName(),s=r.getInitializer();o==="description"&&s?n.description=A(s):o==="markdown"&&s&&(n.markdown=A(s))}return n}function pt(e){let{Node:t}=N(),n={};if(!t.isObjectLiteralExpression(e))return n;for(let r of e.getProperties()){if(!t.isPropertyAssignment(r))continue;let o=r.getName(),s=r.getInitializer();o==="strict"&&s?t.isTrueLiteral(s)?n.strict=!0:t.isFalseLiteral(s)&&(n.strict=!1):o==="errors"&&s&&(n.declaredErrors=q(s))}return n}function mt(e){let{Node:t}=N(),n=[];if((t.isArrowFunction(e)||t.isFunctionExpression(e))&&(n=e.getParameters()),n.length===0)return;let r=n[0];if(!t.isParameterDeclaration(r))return;let o=r.getNameNode();if(t.isObjectBindingPattern(o)){let s={isDestructured:!0};for(let i of o.getElements()){let a=i.getPropertyNameNode()?.getText()||i.getName(),l=i.getName();a==="saga"?s.sagaAlias=l:a==="step"?s.stepAlias=l:a==="tryStep"&&(s.tryStepAlias=l)}return s}return{name:o.getText(),isDestructured:!1}}function gt(e,t){let n=e.getParent();for(;n;){if(n===t)return!0;n=n.getParent()}return!1}function xn(e,t){let{Node:n}=N(),r=[],o=e.bindingName??e.name,s=e.variableDeclaration||e.callExpression,i=s.getStart(),a;e.variableDeclaration&&n.isVariableDeclaration(e.variableDeclaration)&&e.variableDeclaration.getVariableStatement()?.getDeclarationKind()==="var"&&(a=qe(s)),a??=Tt(s);let l=[];function c(u){let d=[];if(n.isIdentifier(u))d.push(u.getText());else if(n.isObjectBindingPattern(u))for(let p of u.getElements()){let f=p.getNameNode();d.push(...c(f))}else if(n.isArrayBindingPattern(u)){for(let p of u.getElements())if(n.isBindingElement(p)){let f=p.getNameNode();d.push(...c(f))}}return d}if(t.forEachDescendant(u=>{if(n.isVariableDeclaration(u)){if(u.getStart()<=i)return;let d=u.getNameNode();if(c(d).includes(o)){let f=u.getParent(),m=f&&n.isVariableDeclarationList(f)&&f.getDeclarationKind()==="var",h=u.getParent();if(m)for(;h&&!n.isFunctionDeclaration(h)&&!n.isFunctionExpression(h)&&!n.isArrowFunction(h)&&!n.isSourceFile(h);)h=h.getParent();else for(;h&&!n.isFunctionDeclaration(h)&&!n.isFunctionExpression(h)&&!n.isArrowFunction(h)&&!n.isBlock(h)&&!n.isSourceFile(h);)h=h.getParent();h&&!n.isSourceFile(h)&&l.push(h)}return}if(n.isFunctionDeclaration(u)){if(u.getStart()<=i)return;if(u.getName()===o){let p=u.getParent();for(;p&&!n.isFunctionDeclaration(p)&&!n.isFunctionExpression(p)&&!n.isArrowFunction(p)&&!n.isBlock(p)&&!n.isSourceFile(p);)p=p.getParent();p&&!n.isSourceFile(p)&&l.push(p)}}if(n.isFunctionDeclaration(u)||n.isFunctionExpression(u)||n.isArrowFunction(u)||n.isMethodDeclaration(u)){if(u.getStart()<=i)return;let d=u.getParameters();for(let p of d){let f=p.getNameNode();if(c(f).includes(o)){l.push(u);break}}}}),t.forEachDescendant(u=>{if(!n.isCallExpression(u))return;let d=u.getExpression(),p=xt(d);if(p===o||p===`await ${o}`||p===`(await ${o})`||p===`${o}.run`||p===`await ${o}.run`){if(e.variableDeclaration){let h=Ne(d);if(!h){let w=ke(d);if(n.isPropertyAccessExpression(w)){let S=w.getExpression();n.isIdentifier(S)&&(h=S)}}if(h){let w=h.getSymbol();if(w&&!w.getDeclarations().some(g=>g===e.variableDeclaration))return}}let f=!a||gt(u,a),m=l.some(h=>gt(u,h));if(f&&!m){let h=u.getArguments();r.push({callExpression:u,callbackArg:h[0]})}}}),r.length===0&&!e.bindingName){let u,d,p=e.callExpression.getParent();for(;p;){if(n.isReturnStatement(p)||n.isArrowFunction(p)){let f=p.getParent();for(;f;){if(n.isFunctionDeclaration(f)){u=f.getName?.(),d=f;break}if(n.isVariableDeclaration(f)){let m=f.getInitializer();if(m&&(n.isArrowFunction(m)||n.isFunctionExpression(m))){u=f.getName(),d=f;break}}f=f.getParent()}break}p=p.getParent()}if(u&&d){let f=[];t.forEachDescendant(m=>{if(!n.isCallExpression(m))return;let h=m.getExpression(),w=Ne(h);if(!w||w.getText()!==u)return;let S=w.getSymbol();if(!S||!S.getDeclarations().some(k=>k===d))return;let y=m.getParent();y&&n.isVariableDeclaration(y)&&f.push(y)}),t.forEachDescendant(m=>{if(!n.isCallExpression(m))return;let h=m.getExpression(),w=Ne(h);if(!w){let k=ke(h);if(n.isPropertyAccessExpression(k)){let x=k.getExpression();n.isIdentifier(x)&&(w=x)}}if(!w)return;let S=w.getSymbol();if(!S||!S.getDeclarations().some(k=>f.includes(k)))return;let y=m.getArguments();if(y.length>0){let k=y[0];(n.isArrowFunction(k)||n.isFunctionExpression(k))&&r.push({callExpression:m,callbackArg:k})}})}if(r.length===0&&e.depsObject){let f=Yn(e.depsObject);f.length>0&&t.forEachDescendant(m=>{if(!n.isCallExpression(m))return;let h=m.getExpression(),w=Ne(h);if(!w){let F=ke(h);if(n.isPropertyAccessExpression(F)){let se=F.getExpression();n.isIdentifier(se)&&(w=se)}}if(!w)return;let S=w.getSymbol();if(!S||!S.getDeclarations().some(F=>n.isParameterDeclaration(F)))return;let g=m.getArguments();if(g.length===0)return;let y=g[0];if(!n.isArrowFunction(y)&&!n.isFunctionExpression(y))return;let k=y.getParameters();if(k.length!==1)return;let x=k[0];if(!n.isParameterDeclaration(x))return;let R=x.getNameNode();if(!n.isObjectBindingPattern(R))return;let P=R.getElements();if(!P.some(F=>(F.getPropertyNameNode?.()?.getText()||F.getName())==="step"))return;let ot=P.find(F=>(F.getPropertyNameNode?.()?.getText()||F.getName())==="deps");if(!ot)return;let Oe=ot.getNameNode?.(),st;if(Oe&&n.isObjectBindingPattern(Oe))st=Oe.getElements().map(F=>F.getName());else return;if(f.every(F=>st.includes(F))){if(w&&(w.getDefinitionNodes?.()??[]).some(it=>n.isFunctionDeclaration(it)||n.isVariableDeclaration(it)))return;r.push({callExpression:m,callbackArg:y})}})}}return r}function ht(e,t,n,r,o={isSagaWorkflow:!1},s){let{Node:i}=N(),a;if((i.isArrowFunction(e)||i.isFunctionExpression(e))&&(a=e.getBody()),!a)return n.push({code:"CALLBACK_NO_BODY",message:"Could not extract callback body",location:I(e)}),[];let l={stepNames:new Set,isInWorkflowCallback:!0,depth:0};return s&&(s.isDestructured&&s.stepAlias?l.stepNames.add(s.stepAlias):s.name&&l.stepNames.add(s.name)),l.stepNames.size===0&&l.stepNames.add("step"),T(a,t,n,r,o,l)}function T(e,t,n,r,o={isSagaWorkflow:!1},s={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:i}=N(),a=[];if(i.isBlock(e)){for(let l of e.getStatements())a.push(...T(l,t,n,r,o,s));return Pt(a,t)}if(i.isExpressionStatement(e)||i.isAwaitExpression(e)||i.isParenthesizedExpression(e))return T(e.getExpression(),t,n,r,o,s);if(i.isVariableStatement(e)){for(let l of e.getDeclarationList().getDeclarations()){let c=l.getInitializer();c&&a.push(...T(c,t,n,r,o,s))}return a}if(i.isVariableDeclaration(e)){let l=e.getInitializer();if(l)if(i.isArrowFunction(l)||i.isFunctionExpression(l)){let c=l.getBody(),u={...s,isInWorkflowCallback:s.isInWorkflowCallback,depth:s.depth+1};a.push(...T(c,t,n,r,o,u))}else a.push(...T(l,t,n,r,o,s));return a}if(i.isCallExpression(e)){let l=Tn(e,t,n,r,o,s);return l&&a.push(l),a}if(i.isIfStatement(e)){let l=_n(e,t,n,r,o,s);return l&&a.push(l),a}if(i.isSwitchStatement(e)){let l=qn(e,t,n,r,o,s);return l&&a.push(l),a}if(i.isForStatement(e)){let l=Vn(e,t,n,r,o,s);return l&&a.push(l),a}if(i.isForOfStatement(e)){let l=Kn(e,t,n,r,o,s);return l&&a.push(l),a}if(i.isForInStatement(e)){let l=Hn(e,t,n,r,o,s);return l&&a.push(l),a}if(i.isWhileStatement(e)){let l=Gn(e,t,n,r,o,s);return l&&a.push(l),a}if(i.isTryStatement(e)){let l=In(e,t,n,r,o,s);return a.push(...l),a}if(i.isReturnStatement(e)){let l=e.getExpression();return l?T(l,t,n,r,o,s):a}if(i.isConditionalExpression(e)){let l=T(e.getWhenTrue(),t,n,r,o,s),c=T(e.getWhenFalse(),t,n,r,o,s);return a.push(...l,...c),a}if(i.isArrayLiteralExpression(e)){for(let l of e.getElements())a.push(...T(l,t,n,r,o,s));return a}if(i.isObjectLiteralExpression(e)){for(let l of e.getProperties())if(i.isPropertyAssignment(l)){let c=l.getInitializer();if(c){if(i.isArrowFunction(c)||i.isFunctionExpression(c)){let u=c.getBody(),d={...s,isInWorkflowCallback:s.isInWorkflowCallback,depth:s.depth+1};a.push(...T(u,t,n,r,o,d))}else if(i.isObjectLiteralExpression(c))a.push(...T(c,t,n,r,o,s));else if(i.isCallExpression(c))for(let u of c.getArguments())a.push(...T(u,t,n,r,o,s))}}else if(i.isMethodDeclaration(l)){let c=l.getBody();if(c){let u={...s,isInWorkflowCallback:s.isInWorkflowCallback,depth:s.depth+1};a.push(...T(c,t,n,r,o,u))}}return a}if(i.isArrowFunction(e)){let l=e.getBody(),c={...s,isInWorkflowCallback:s.isInWorkflowCallback,depth:s.depth+1};return T(l,t,n,r,o,c)}if(i.isFunctionExpression(e)){let l=e.getBody(),c={...s,isInWorkflowCallback:s.isInWorkflowCallback,depth:s.depth+1};return T(l,t,n,r,o,c)}return a}function In(e,t,n,r,o,s){let{Node:i}=N();if(!i.isTryStatement(e))return[];let a=[],l=e.getTryBlock();a.push(...T(l,t,n,r,o,s));let c=e.getCatchClause();c&&a.push(...T(c.getBlock(),t,n,r,o,s));let u=e.getFinallyBlock();return u&&a.push(...T(u,t,n,r,o,s)),a}function O(e,t,n,r,o={isSagaWorkflow:!1},s={stepNames:new Set(["step"]),isInWorkflowCallback:!0,depth:0}){let{Node:i}=N();if(i.isArrowFunction(e)){let a=e.getBody();return T(a,t,n,r,o,s)}if(i.isFunctionExpression(e)){let a=e.getBody();return T(a,t,n,r,o,s)}return T(e,t,n,r,o,s)}function Tn(e,t,n,r,o={isSagaWorkflow:!1},s={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:i}=N();if(!i.isCallExpression(e))return;let a=e.getExpression(),l=a.getText(),c=e.getArguments();if(o.isSagaWorkflow&&o.sagaParamInfo){let d=o.sagaParamInfo;if(d.isDestructured&&d.sagaAlias){if(l===`${d.sagaAlias}.step`)return X(e,c,!1,t,n,r);if(l===`${d.sagaAlias}.tryStep`)return X(e,c,!0,t,n,r)}if(d.isDestructured){if(d.stepAlias&&l===d.stepAlias)return X(e,c,!1,t,n,r);if(d.tryStepAlias&&l===d.tryStepAlias)return X(e,c,!0,t,n,r)}else if(d.name){if(l===`${d.name}.step`)return X(e,c,!1,t,n,r);if(l===`${d.name}.tryStep`)return X(e,c,!0,t,n,r)}}if(Cn(l,s))return B(e,c,t,n,r);if(L(l,"sleep",s))return Rn(e,c,t,r);if(L(l,"retry",s))return Pn(e,c,t,n,r);if(L(l,"withTimeout",s))return $n(e,c,t,n,r);if(L(l,"try",s))return Dn(e,c,t,n,r);if(L(l,"fromResult",s))return Wn(e,c,t,n,r);if(L(l,"withFallback",s))return B(e,c,t,n,r,{displayCallee:"step.withFallback"});if(L(l,"withResource",s)){let d=B(e,c,t,n,r,{displayCallee:"step.withResource"});if(d.stepKind="withResource",c[1]&&i.isObjectLiteralExpression(c[1])){let p={};for(let f of c[1].getProperties()){if(!i.isPropertyAssignment(f))continue;let m=f.getName();if(m!=="acquire"&&m!=="use"&&m!=="release")continue;let h=f.getInitializer();if(h){let w=On(h);w&&(p[m]=w)}}Object.keys(p).length>0&&(d.resourceOps=p)}return d}if(L(l,"workflow",s)){let d=c[1]?O(c[1],t,n,r,o,s):[],p=B(e,c,t,n,r,{displayCallee:"step.workflow"});return d.length===0?p:{id:C(),type:"sequence",children:[p,...d]}}if(L(l,"run",s))return B(e,c,t,n,r,{displayCallee:"step.run"});if(L(l,"andThen",s))return B(e,c,t,n,r,{displayCallee:"step.andThen"});if(L(l,"match",s))return B(e,c,t,n,r,{displayCallee:"step.match"});if(L(l,"all",s))return Me(e,c,"all",t,n,r,o,s);if(L(l,"allSettled",s))return Me(e,c,"allSettled",t,n,r,o,s);if(L(l,"map",s))return B(e,c,t,n,r,{displayCallee:"step.map"});if(L(l,"parallel",s))return Me(e,c,"all",t,n,r,o,s);if(L(l,"race",s))return Mn(e,c,t,n,r,o,s);if(L(l,"forEach",s))return Fn(e,c,t,n,r,o,s);if(L(l,"branch",s))return vn(e,c,t,n,r,o,s);if(L(l,"getWritable",s))return ze(e,"write",t,r);if(L(l,"getReadable",s))return ze(e,"read",t,r);if(L(l,"streamForEach",s))return ze(e,"forEach",t,r);if(l==="allAsync")return St(e,c,"all",t,n,r,o,s);if(l==="allSettledAsync")return St(e,c,"allSettled",t,n,r,o,s);if(l==="anyAsync")return jn(e,c,t,n,r,o,s);if(["when","unless","whenOr","unlessOr"].includes(l))return Un(e,l,c,t,n,r,o,s);if(l==="Promise.all")return En(e,c,t,n,r,o,s);if(i.isPropertyAccessExpression(a)){let d=a.getName();if(["map","forEach","filter","reduce","some","every","find","flatMap"].includes(d)&&c[0]){let f=O(c[0],t,n,r,o,s);if(f.length>0)return f.length===1?f[0]:{id:C(),type:"sequence",children:f}}}if(Zn(e))return Jn(e,l,t,n,r)}function Cn(e,t){return!!t.stepNames.has(e)}function L(e,t,n){for(let r of n.stepNames)if(e===`${r}.${t}`)return!0;return!1}function Rn(e,t,n,r){let{Node:o}=N();r.totalSteps++;let s="<missing>";t[0]&&(o.isStringLiteral(t[0])||o.isNoSubstitutionTemplateLiteral(t[0])?s=t[0].getLiteralValue():s="<dynamic>");let i;t[1]&&(o.isStringLiteral(t[1])||o.isNoSubstitutionTemplateLiteral(t[1])?i=t[1].getLiteralValue():i=t[1].getText());let a={id:C(),type:"step",stepId:s,callee:"step.sleep",stepKind:"sleep",sleepDuration:i,location:n.includeLocations?I(e):void 0};if(t[2]&&o.isObjectLiteralExpression(t[2])){let c=re(t[2]);c.key&&(a.key=c.key),c.description&&(a.description=c.description),c.markdown&&(a.markdown=c.markdown),c.intent&&(a.intent=c.intent),c.domain&&(a.domain=c.domain),c.owner&&(a.owner=c.owner),c.tags&&(a.tags=c.tags)}a.name||(a.name=s);let l=Y(e);if(l){let c=V(l);c&&(a.jsdocDescription=c);let u=U(l);u&&(u.params?.length&&(a.jsdocParams=u.params),u.returns&&(a.jsdocReturns=u.returns),u.throws?.length&&(a.jsdocThrows=u.throws),u.example&&(a.jsdocExample=u.example))}return a}function En(e,t,n,r,o,s,i={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:a}=N();if(t[0]){if(a.isArrayLiteralExpression(t[0])){let l=[];for(let c of t[0].getElements())l.push(...T(c,n,r,o,s,i));if(l.length>0)return Pt(l,n)[0]}if(a.isCallExpression(t[0])){let l=t[0],c=l.getExpression();if(a.isPropertyAccessExpression(c)){let u=c.getName();if(["map","flatMap","filter"].includes(u)){let p=l.getArguments();if(p[0])return O(p[0],n,r,o,s,i)[0]}}}}}function B(e,t,n,r,o,s){let{Node:i}=N();o.totalSteps++;let a=t[0],l=a&&i.isStringLiteral(a),c=a&&i.isNoSubstitutionTemplateLiteral(a),u=a&&i.isTemplateExpression(a),d=a&&i.isIdentifier(a),p;l&&i.isStringLiteral(a)||c&&i.isNoSubstitutionTemplateLiteral(a)?p=a.getLiteralValue():u||d?p="<dynamic>":(p="<missing>",r.push({code:"STEP_MISSING_ID",message:'step() requires an explicit string ID as the first argument. Example: step("fetchUser", () => fetchUser(id))',location:n.includeLocations?I(e):void 0}));let f={id:C(),type:"step",stepId:p,location:n.includeLocations?I(e):void 0},m=p!=="<missing>",h=m?t[1]:t[0],w=m?t[2]:t[1],S;if(h){if(i.isCallExpression(h)){let g=h.getExpression();if(i.isPropertyAccessExpression(g)&&g.getName()==="dep"){let y=h.getArguments();y[0]&&i.isStringLiteral(y[0])&&(f.depSource=y[0].getLiteralValue()),y[1]&&(h=y[1])}}if(i.isArrowFunction(h)||i.isFunctionExpression(h)){let g=h.getBody();for(;i.isParenthesizedExpression(g);)g=g.getExpression();if(i.isCallExpression(g))f.callee=g.getExpression().getText(),S=g;else if(i.isBlock(g)){let k=g.getStatements();for(let x of k)if(i.isReturnStatement(x)){let R=x.getExpression();if(R&&i.isCallExpression(R)){f.callee=R.getExpression().getText(),S=R;break}}f.callee||(f.callee=g.getText())}else g&&(f.callee=g.getText());let y=Ln(h);if(y&&(f.reads=y.reads,f.readParamIndices=y.paramIndices),!f.depSource&&f.callee){let k=f.callee.match(/^(?:deps|ctx\.deps)\.([a-zA-Z_$][a-zA-Z0-9_$]*)/);k&&(f.depSource=k[1])}}else i.isCallExpression(h)?(f.callee=h.getExpression().getText(),S=h):f.callee=h.getText()}if(ce(e,S,f),w&&i.isObjectLiteralExpression(w)){let g=re(w);if(g.key&&(f.key=g.key),g.description&&(f.description=g.description),g.markdown&&(f.markdown=g.markdown),g.retry&&(f.retry=g.retry),g.timeout&&(f.timeout=g.timeout),g.errors&&(f.errors=g.errors,f.errorsSource="explicit"),g.out&&(f.out=g.out),g.dep&&(f.depSource=g.dep),g.reads){let y=f.reads??[],k=new Set([...y,...g.reads]);f.reads=Array.from(k)}if(g.intent&&(f.intent=g.intent),g.domain&&(f.domain=g.domain),g.owner&&(f.owner=g.owner),g.tags&&(f.tags=g.tags),g.stateChanges&&(f.stateChanges=g.stateChanges),g.emits&&(f.emits=g.emits),g.calls&&(f.calls=g.calls),g.errorMeta&&(f.errorMeta=g.errorMeta),g.ttl!=null&&(f.ttl=g.ttl),g.errorMeta&&g.errors)for(let y of Object.keys(g.errorMeta))g.errors.includes(y)||r.push({code:"errorMeta-unknown-key",message:`errorMeta key "${y}" is not declared in errors array`,location:f.location})}f.name||(f.name=f.stepId);let b=Y(e);if(b){let g=V(b);g&&(f.jsdocDescription=g);let y=U(b);y&&(y.params?.length&&(f.jsdocParams=y.params),y.returns&&(f.jsdocReturns=y.returns),y.throws?.length&&(f.jsdocThrows=y.throws),y.example&&(f.jsdocExample=y.example))}if(n.includeLocations&&S){let{Node:g}=N();if(g.isCallExpression(S)){let y=S.getExpression();f.depLocation=ue(y)??I(y)}}return s?.displayCallee&&(f.callee=s.displayCallee),f}function An(e,t){let n=t;for(;n;){if(n===e)return!0;n=n.getParent()}return!1}function Ln(e){let{Node:t}=N(),n=[],r=[];return e.forEachDescendant(o=>{if(!t.isCallExpression(o))return;let s=o.getExpression();if(!t.isPropertyAccessExpression(s))return;let i=s.getName(),a=s.getExpression();if(i!=="ref"||a.getText()!=="ctx")return;let l=o.getArguments();if(!l[0]||!t.isStringLiteral(l[0]))return;let c=l[0].getLiteralValue(),u=0,d=o.getParent();for(;d;){if(t.isCallExpression(d)){let p=d.getExpression().getText();if(p.startsWith("deps.")||p.startsWith("ctx.deps.")){let m=d.getArguments().findIndex(h=>An(h,o));m>=0&&(u=m);break}}d=d.getParent()}n.push(c),r.push(u)}),n.length>0?{reads:n,paramIndices:r}:void 0}function Pn(e,t,n,r,o){let{Node:s}=N();o.totalSteps++;let i="<missing>";t[0]&&(s.isStringLiteral(t[0])||s.isNoSubstitutionTemplateLiteral(t[0])?i=t[0].getLiteralValue():i="<dynamic>");let{operation:a,depSourceOverride:l}=be(t[1]),c=a?le(a):void 0,u=a?xe(a):void 0,d={id:C(),type:"step",stepId:i,callee:"step.retry",stepKind:"retry",depSource:l??Ie(c),name:i,location:n.includeLocations?I(e):void 0};if(ce(e,u,d),t[2]&&s.isObjectLiteralExpression(t[2])){d.retry=At(t[2]);let f=re(t[2]);f.key&&(d.key=f.key),f.dep&&(d.depSource=f.dep),f.errors&&(d.errors=f.errors,d.errorsSource="explicit"),f.out&&(d.out=f.out),f.reads&&(d.reads=f.reads),f.intent&&(d.intent=f.intent),f.domain&&(d.domain=f.domain),f.owner&&(d.owner=f.owner),f.tags&&(d.tags=f.tags),f.stateChanges&&(d.stateChanges=f.stateChanges),f.emits&&(d.emits=f.emits),f.calls&&(d.calls=f.calls),f.errorMeta&&(d.errorMeta=f.errorMeta),f.ttl!=null&&(d.ttl=f.ttl)}if(n.includeLocations&&u&&s.isCallExpression(u)){let f=u.getExpression();d.depLocation=ue(f)??I(f)}let p=Y(e);if(p){let f=V(p);f&&(d.jsdocDescription=f);let m=U(p);m&&(m.params?.length&&(d.jsdocParams=m.params),m.returns&&(d.jsdocReturns=m.returns),m.throws?.length&&(d.jsdocThrows=m.throws),m.example&&(d.jsdocExample=m.example))}return d}function $n(e,t,n,r,o){let{Node:s}=N();o.totalSteps++;let i="<missing>";t[0]&&(s.isStringLiteral(t[0])||s.isNoSubstitutionTemplateLiteral(t[0])?i=t[0].getLiteralValue():i="<dynamic>");let{operation:a,depSourceOverride:l}=be(t[1]),c=a?le(a):void 0,u=a?xe(a):void 0,d={id:C(),type:"step",stepId:i,callee:"step.withTimeout",stepKind:"withTimeout",depSource:l??Ie(c),name:i,location:n.includeLocations?I(e):void 0};if(ce(e,u,d),t[2]&&s.isObjectLiteralExpression(t[2])){d.timeout=Lt(t[2]);let f=re(t[2]);f.key&&(d.key=f.key),f.dep&&(d.depSource=f.dep),f.intent&&(d.intent=f.intent),f.domain&&(d.domain=f.domain),f.owner&&(d.owner=f.owner),f.tags&&(d.tags=f.tags)}if(n.includeLocations&&u&&s.isCallExpression(u)){let f=u.getExpression();d.depLocation=ue(f)??I(f)}let p=Y(e);if(p){let f=V(p);f&&(d.jsdocDescription=f);let m=U(p);m&&(m.params?.length&&(d.jsdocParams=m.params),m.returns&&(d.jsdocReturns=m.returns),m.throws?.length&&(d.jsdocThrows=m.throws),m.example&&(d.jsdocExample=m.example))}return d}function Dn(e,t,n,r,o){let{Node:s}=N();o.totalSteps++;let i="<missing>";t[0]&&(s.isStringLiteral(t[0])||s.isNoSubstitutionTemplateLiteral(t[0])?i=t[0].getLiteralValue():i="<dynamic>");let{operation:a,depSourceOverride:l}=be(t[1]),c=a?le(a):void 0,u=a?xe(a):void 0,d={id:C(),type:"step",stepId:i,callee:"step.try",stepKind:"try",depSource:l??Ie(c),name:i,location:n.includeLocations?I(e):void 0};if(ce(e,u,d),t[2]&&s.isObjectLiteralExpression(t[2])){let f=re(t[2]);f.key&&(d.key=f.key),f.dep&&(d.depSource=f.dep),f.intent&&(d.intent=f.intent),f.domain&&(d.domain=f.domain),f.owner&&(d.owner=f.owner),f.tags&&(d.tags=f.tags)}if(n.includeLocations&&u&&s.isCallExpression(u)){let f=u.getExpression();d.depLocation=ue(f)??I(f)}let p=Y(e);if(p){let f=V(p);f&&(d.jsdocDescription=f);let m=U(p);m&&(m.params?.length&&(d.jsdocParams=m.params),m.returns&&(d.jsdocReturns=m.returns),m.throws?.length&&(d.jsdocThrows=m.throws),m.example&&(d.jsdocExample=m.example))}return d}function Wn(e,t,n,r,o){let{Node:s}=N();o.totalSteps++;let i="<missing>";t[0]&&(s.isStringLiteral(t[0])||s.isNoSubstitutionTemplateLiteral(t[0])?i=t[0].getLiteralValue():i="<dynamic>");let{operation:a,depSourceOverride:l}=be(t[1]),c=a?le(a):void 0,u=a?xe(a):void 0,d={id:C(),type:"step",stepId:i,callee:"step.fromResult",stepKind:"fromResult",depSource:l??Ie(c),name:i,location:n.includeLocations?I(e):void 0};if(ce(e,u,d),t[2]&&s.isObjectLiteralExpression(t[2])){let f=re(t[2]);f.key&&(d.key=f.key),f.dep&&(d.depSource=f.dep),f.intent&&(d.intent=f.intent),f.domain&&(d.domain=f.domain),f.owner&&(d.owner=f.owner),f.tags&&(d.tags=f.tags)}if(n.includeLocations&&u&&s.isCallExpression(u)){let f=u.getExpression();d.depLocation=ue(f)??I(f)}let p=Y(e);if(p){let f=V(p);f&&(d.jsdocDescription=f);let m=U(p);m&&(m.params?.length&&(d.jsdocParams=m.params),m.returns&&(d.jsdocReturns=m.returns),m.throws?.length&&(d.jsdocThrows=m.throws),m.example&&(d.jsdocExample=m.example))}return d}function Me(e,t,n,r,o,s,i={isSagaWorkflow:!1},a={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:l}=N();s.parallelCount++;let c={id:C(),type:"parallel",mode:n,children:[],callee:n==="allSettled"?"step.allSettled":"step.parallel",location:r.includeLocations?I(e):void 0};if(t[0]&&t[1]&&(l.isStringLiteral(t[0])||!l.isObjectLiteralExpression(t[0])&&!l.isArrayLiteralExpression(t[0]))&&l.isObjectLiteralExpression(t[1])){let u=t[0];c.name=l.isStringLiteral(u)?u.getLiteralValue():u.getText();let p=t[1].getProperties();for(let f=0;f<p.length;f++){let m=p[f];if(l.isPropertyAssignment(m)){let h=m.getName(),w=m.getInitializer();if(w){let S=`parallel.${c.name??f}.`;if(l.isObjectLiteralExpression(w)){let g=w.getProperty("fn"),y=w.getProperty("errors");if(g&&l.isPropertyAssignment(g)){let k=g.getInitializer();if(k){let x=ae(k,r,s,S);if(x){if(x.name=h,x.depSource=E(x.callee??""),y&&l.isPropertyAssignment(y)){let R=y.getInitializer();R&&(x.errors=q(R))}c.children.push(x);continue}}}}let b=ae(w,r,s,S);if(b)b.name=h,b.depSource=E(b.callee??""),c.children.push(b);else{let g=O(w,r,o,s,i,a);if(g.length>0){let y=g[0];if(y.name=h,y.type==="step"){let k=y;k.stepId?.startsWith("implicit:")&&(k.stepId=S+(k.name??k.stepId.slice(9)))}c.children.push(y)}}}}}return c}if(t[0]&&l.isStringLiteral(t[0])){if(c.name=t[0].getLiteralValue(),t[1]){let u=O(t[1],r,o,s,i,a);if(u.length===1&&u[0].type==="parallel"){let d=u[0];return c.children=d.children,c.mode=d.mode,c}c.children.push(...u)}return c}if(t[0]&&!l.isObjectLiteralExpression(t[0])&&!l.isArrayLiteralExpression(t[0])&&t[1]){c.name=t[0].getText();let u=O(t[1],r,o,s,i,a);if(u.length===1&&u[0].type==="parallel"){let d=u[0];return c.children=d.children,c.mode=d.mode,c}return c.children.push(...u),c}return c}function Fn(e,t,n,r,o,s={isSagaWorkflow:!1},i={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:a}=N();o.loopCount++;let l={id:C(),type:"loop",loopType:"step.forEach",body:[],boundKnown:!1,location:n.includeLocations?I(e):void 0};if(t[0]&&a.isStringLiteral(t[0])&&(l.loopId=t[0].getLiteralValue(),l.name=l.loopId),t[1]&&(l.iterSource=t[1].getText()),t[2]&&a.isObjectLiteralExpression(t[2]))for(let c of t[2].getProperties()){if(!a.isPropertyAssignment(c))continue;let u=c.getName(),d=c.getInitializer();if(d){if(u==="maxIterations"&&a.isNumericLiteral(d))l.maxIterations=d.getLiteralValue(),l.boundKnown=!0,l.boundCount=l.maxIterations;else if(u==="stepIdPattern"){let p=A(d);p&&(l.stepIdPattern=p)}else if(u==="errors")l.errors=q(d);else if(u==="out"){let p=A(d);p&&(l.out=p)}else if(u==="collect"){let p=A(d);(p==="array"||p==="last")&&(l.collect=p)}else if(u==="run"&&(a.isArrowFunction(d)||a.isFunctionExpression(d))){let p=`forEach.${l.loopId??"forEach"}.`,f=ae(d,n,o,p);if(f)!f.depSource&&f.callee&&(f.depSource=E(f.callee)),l.body=[f];else{let m=T(d.getBody(),n,r,o,s,i);l.body=m}}else if(u==="item"&&a.isCallExpression(d)){let p=d.getArguments();if(p[0]&&(a.isArrowFunction(p[0])||a.isFunctionExpression(p[0]))){let f=T(p[0].getBody(),n,r,o,s,i);l.body=f}}}}return l}function vn(e,t,n,r,o,s={isSagaWorkflow:!1},i={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:a}=N();o.conditionalCount++;let l="<dynamic>",c="<dynamic>",u="<dynamic>",d,p,f,m=[],h=[];if(t[0]&&a.isStringLiteral(t[0])&&(l=t[0].getLiteralValue()),t[1]&&a.isObjectLiteralExpression(t[1]))for(let S of t[1].getProperties()){if(!a.isPropertyAssignment(S))continue;let b=S.getName(),g=S.getInitializer();if(g)if(b==="conditionLabel"){let y=A(g);y&&(c=y)}else if(b==="condition")a.isArrowFunction(g)||a.isFunctionExpression(g)?u=g.getBody().getText():u=g.getText();else if(b==="out")f=A(g);else if(b==="then"){let y=yt(g,n,r,o,s,i);y&&(m=y)}else if(b==="thenErrors")d=q(g);else if(b==="else"){let y=yt(g,n,r,o,s,i);y&&(h=y)}else b==="elseErrors"&&(p=q(g))}let w={id:C(),type:"decision",decisionId:l,conditionLabel:c,condition:u,consequent:m,alternate:h,location:n.includeLocations?I(e):void 0};return d&&m.length===1&&m[0].type==="step"&&(m[0].errors=d),p&&h.length===1&&h[0].type==="step"&&(h[0].errors=p),f&&(m.length===1&&m[0].type==="step"&&(m[0].out=f),h.length===1&&h[0].type==="step"&&(h[0].out=f)),w}function yt(e,t,n,r,o,s){let{Node:i}=N();if(i.isCallExpression(e)){let a=e.getExpression();if(i.isPropertyAccessExpression(a)&&a.getName()==="arm"){let l=e.getArguments();if(l[0]){if(i.isObjectLiteralExpression(l[0])){let c,u;for(let d of l[0].getProperties()){if(!i.isPropertyAssignment(d))continue;let p=d.getName(),f=d.getInitializer();p==="fn"&&f?c=f:p==="errors"&&f&&(u=q(f))}if(c){let d=je(c,t,r);return u&&d.length===1&&d[0].type==="step"&&(d[0].errors=u),d}}else if(i.isArrowFunction(l[0])||i.isFunctionExpression(l[0]))return je(l[0],t,r)}}}return i.isArrowFunction(e)||i.isFunctionExpression(e)?je(e,t,r):ie(e,t,r)}function je(e,t,n){let{Node:r}=N();if(r.isArrowFunction(e)||r.isFunctionExpression(e)){let o=e.getBody();for(;r.isParenthesizedExpression(o);)o=o.getExpression();if(r.isCallExpression(o))return ie(o,t,n);if(r.isBlock(o)){let s=o.getStatements();for(let i of s)if(r.isReturnStatement(i)){let a=i.getExpression();if(a&&r.isCallExpression(a))return ie(a,t,n)}}return ie(o,t,n)}return ie(e,t,n)}function ie(e,t,n){let{Node:r}=N();n.totalSteps++;let o,s,i;if(r.isCallExpression(e)){o=e.getExpression().getText();let l=o.match(/^(?:deps|ctx\.deps)\.([a-zA-Z_$][a-zA-Z0-9_$]*)/);l?(i=l[1],s=l[1]):s=o}else o=e.getText(),s=o;return[{id:C(),type:"step",stepId:`implicit:${s}`,callee:o,name:s,depSource:i,location:t.includeLocations?I(e):void 0}]}function On(e){let{Node:t}=N();if(t.isArrowFunction(e)){let n=e.getBody();if(t.isCallExpression(n))return n.getExpression().getText();if(t.isBlock(n)){let r=n.getStatements();if(r.length===0)return"inline";if(r.length===1&&t.isReturnStatement(r[0])){let o=r[0].getExpression();if(o&&t.isCallExpression(o))return o.getExpression().getText()}return"inline"}}if(t.isFunctionExpression(e)){let n=e.getBody();if(!t.isBlock(n))return;let r=n.getStatements();if(r.length===0)return"inline";if(r.length===1&&t.isReturnStatement(r[0])){let o=r[0].getExpression();if(o&&t.isCallExpression(o))return o.getExpression().getText()}return"inline"}}function ae(e,t,n,r){let{Node:o}=N(),s=(i,a,l)=>({id:C(),type:"step",stepId:r?r+i:`implicit:${i}`,location:t.includeLocations?I(l):void 0,callee:a,name:i});if(o.isArrowFunction(e)){let i=e.getBody();if(o.isCallExpression(i)){let a=i.getExpression().getText(),l=E(a);return n.totalSteps++,s(l,a,i)}}if(o.isFunctionExpression(e)){let i=e.getBody();if(!o.isBlock(i))return;let a=i.getStatements();if(a.length===1&&o.isReturnStatement(a[0])){let l=a[0].getExpression();if(l&&o.isCallExpression(l)){let c=l.getExpression().getText(),u=E(c);return n.totalSteps++,s(u,c,l)}}}}function St(e,t,n,r,o,s,i={isSagaWorkflow:!1},a={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:l}=N();s.parallelCount++;let c={id:C(),type:"parallel",mode:n,children:[],callee:n==="all"?"allAsync":"allSettledAsync",location:r.includeLocations?I(e):void 0};if(t[0]&&l.isArrayLiteralExpression(t[0])){let u=t[0].getElements();for(let d=0;d<u.length;d++){let p=u[d],f=O(p,r,o,s,i,a);if(f.length>0){let m=`parallel.${d}.`;for(let h of f)if(h.type==="step"){let w=h;!w.depSource&&w.callee&&(w.depSource=E(w.callee)),w.stepId?.startsWith("implicit:")&&(w.stepId=m+(w.name??w.stepId.slice(9)))}f.length>1?c.children.push({id:C(),type:"sequence",children:f}):c.children.push(...f)}else if(l.isCallExpression(p)){let m=p.getExpression().getText(),h=E(m);s.totalSteps++;let w={id:C(),type:"step",stepId:`parallel.${d}.${h}`,location:r.includeLocations?I(p):void 0,callee:m,name:h,depSource:h};c.children.push(w)}}}return c}function Mn(e,t,n,r,o,s={isSagaWorkflow:!1},i={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:a}=N();o.raceCount++;let l={id:C(),type:"race",children:[],callee:"step.race",location:n.includeLocations?I(e):void 0};if(t[0]&&a.isArrayLiteralExpression(t[0])){let c=t[0].getElements();for(let u=0;u<c.length;u++){let d=c[u],p=`race.${u}.`,f=ae(d,n,o,p);if(f)f.depSource=f.name??E(f.callee??""),l.children.push(f);else{let m=O(d,n,r,o,s,i);for(let h of m)if(h.type==="step"){let w=h;!w.depSource&&w.callee&&(w.depSource=E(w.callee)),w.stepId?.startsWith("implicit:")&&(w.stepId=p+(w.name??w.stepId.slice(9)))}l.children.push(...m)}}}else if(t[0]&&a.isObjectLiteralExpression(t[0])){for(let c of t[0].getProperties())if(a.isPropertyAssignment(c)){let u=c.getName(),d=c.getInitializer();if(d){let p=`race.${u}.`,f=ae(d,n,o,p);if(f)f.name=u,f.depSource=u,l.children.push(f);else{let m=O(d,n,r,o,s,i);if(m.length>0){let h=m[0];if(h.name=u,h.type==="step"){let w=h;w.depSource=w.depSource??u,w.stepId?.startsWith("implicit:")&&(w.stepId=p+(w.name??w.stepId.slice(9)))}l.children.push(h)}}}}}return l}function jn(e,t,n,r,o,s={isSagaWorkflow:!1},i={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:a}=N();o.raceCount++;let l={id:C(),type:"race",children:[],callee:"anyAsync",location:n.includeLocations?I(e):void 0};if(t[0]&&a.isArrayLiteralExpression(t[0]))for(let c of t[0].getElements()){let u=O(c,n,r,o,s,i);l.children.push(...u)}return l}function ze(e,t,n,r){let{Node:o}=N();if(r.streamCount=(r.streamCount||0)+1,!o.isCallExpression(e))return{id:C(),type:"stream",streamType:t,callee:`step.${t==="write"?"getWritable":t==="read"?"getReadable":"streamForEach"}`,location:n.includeLocations?I(e):void 0};let s=e.getArguments(),i={id:C(),type:"stream",streamType:t,callee:e.getExpression().getText(),location:n.includeLocations?I(e):void 0};return s[0]&&o.isStringLiteral(s[0])&&(i.namespace=s[0].getLiteralValue()),i}function X(e,t,n,r,o,s){let{Node:i}=N();s.totalSteps++;let a={id:C(),type:"saga-step",hasCompensation:!1,isTryStep:n,location:r.includeLocations?I(e):void 0},l=t[0],c=t[1],u=t[2];if(l){let p=A(l);p&&p!=="<dynamic>"&&(a.name=p)}if(c&&(a.callee=le(c),a.callee&&(a.depSource=E(a.callee)),a.name||(a.name=a.callee)),u&&i.isObjectLiteralExpression(u)){let p=zn(u);p.description&&(a.description=p.description),p.markdown&&(a.markdown=p.markdown),p.hasCompensation&&(a.hasCompensation=!0,a.compensationCallee=p.compensationCallee,s.compensatedStepCount=(s.compensatedStepCount||0)+1)}let d=Y(e);if(d){let p=V(d);p&&(a.jsdocDescription=p);let f=U(d);f&&(f.params?.length&&(a.jsdocParams=f.params),f.returns&&(a.jsdocReturns=f.returns),f.throws?.length&&(a.jsdocThrows=f.throws),f.example&&(a.jsdocExample=f.example))}return a}function zn(e){let{Node:t}=N(),n={description:void 0,markdown:void 0,hasCompensation:!1,compensationCallee:void 0};if(!t.isObjectLiteralExpression(e))return n;for(let r of e.getProperties()){if(!t.isPropertyAssignment(r))continue;let o=r.getName(),s=r.getInitializer();if(o!=="name"){if(o==="description"&&s)n.description=A(s);else if(o==="markdown"&&s)n.markdown=A(s);else if(o==="compensate"&&s&&(n.hasCompensation=!0,t.isArrowFunction(s)||t.isFunctionExpression(s))){let i=s.getBody();if(t.isCallExpression(i))n.compensationCallee=i.getExpression().getText();else if(t.isBlock(i)){let a=i.getStatements().find(l=>t.isReturnStatement(l));if(a&&t.isReturnStatement(a)){let l=a.getExpression();l&&t.isCallExpression(l)&&(n.compensationCallee=l.getExpression().getText())}}}}}return n}function _n(e,t,n,r,o={isSagaWorkflow:!1},s={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:i}=N();if(!i.isIfStatement(e))return;let a=e.getExpression(),l=a.getText(),c=e.getThenStatement(),u=e.getElseStatement(),d=T(c,t,n,r,o,s),p=u?T(u,t,n,r,o,s):void 0;if(s.isInWorkflowCallback)r.conditionalCount++;else{if(d.length===0&&(!p||p.length===0))return;r.conditionalCount++}if(d.length===0&&(!p||p.length===0))return;let f;try{let h=a.getType();h&&(f=h.getText())}catch{}let m=Bn(a,s);return m?{id:C(),type:"decision",decisionId:m.decisionId,conditionLabel:m.conditionLabel,condition:m.condition,consequent:d,alternate:p,location:t.includeLocations?I(e):void 0,conditionType:f}:{id:C(),type:"conditional",condition:l,helper:null,consequent:d,alternate:p,location:t.includeLocations?I(e):void 0,conditionType:f}}function Bn(e,t){let{Node:n}=N();if(!n.isCallExpression(e))return;let r=e.getExpression();if(!n.isPropertyAccessExpression(r))return;let o=r.getName(),s=r.getExpression();if(o!=="if"&&o!=="label"||!t.stepNames.has(s.getText()))return;let i=e.getArguments();if(i.length<3||!n.isStringLiteral(i[0]))return;let a=i[0].getLiteralValue();if(!n.isStringLiteral(i[1]))return;let l=i[1].getLiteralValue(),c=i[2].getText();return(n.isArrowFunction(i[2])||n.isFunctionExpression(i[2]))&&(c=i[2].getBody().getText()),{decisionId:a,conditionLabel:l,condition:c}}function qn(e,t,n,r,o={isSagaWorkflow:!1},s={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:i}=N();if(!i.isSwitchStatement(e))return;let a=e.getExpression().getText(),l=e.getClauses(),c=[],u=!1;for(let d of l){let p=i.isDefaultClause(d),f;i.isCaseClause(d)&&(f=d.getExpression().getText());let m=d.getStatements(),h=[];for(let w of m){let S=T(w,t,n,r,o,s);h.push(...S)}h.length>0&&(u=!0),c.push({value:f,isDefault:p,body:h})}if(s.isInWorkflowCallback)r.conditionalCount++;else if(u)r.conditionalCount++;else return;if(u)return{id:C(),type:"switch",expression:a,cases:c,location:t.includeLocations?I(e):void 0}}function Un(e,t,n,r,o,s,i={isSagaWorkflow:!1},a={stepNames:new Set(["step"]),isInWorkflowCallback:!0,depth:0}){s.conditionalCount++;let l={id:C(),type:"conditional",condition:n[0]?.getText()??"<unknown>",helper:t,consequent:[],location:r.includeLocations?I(e):void 0};return n[1]&&(l.consequent=O(n[1],r,o,s,i,a)),(t==="whenOr"||t==="unlessOr")&&n[2]&&(l.defaultValue=n[2].getText()),l}function Vn(e,t,n,r,o={isSagaWorkflow:!1},s={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:i}=N();if(!i.isForStatement(e))return;let a=e.getStatement(),l=T(a,t,n,r,o,s);if(s.isInWorkflowCallback)r.loopCount++;else{if(l.length===0)return;r.loopCount++}if(l.length!==0)return{id:C(),type:"loop",loopType:"for",body:l,boundKnown:!1,location:t.includeLocations?I(e):void 0}}function Kn(e,t,n,r,o={isSagaWorkflow:!1},s={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:i}=N();if(!i.isForOfStatement(e))return;let a=e.getStatement(),l=T(a,t,n,r,o,s);if(s.isInWorkflowCallback)r.loopCount++;else{if(l.length===0)return;r.loopCount++}if(l.length!==0)return{id:C(),type:"loop",loopType:"for-of",iterSource:e.getExpression().getText(),body:l,boundKnown:!1,location:t.includeLocations?I(e):void 0}}function Hn(e,t,n,r,o={isSagaWorkflow:!1},s={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:i}=N();if(!i.isForInStatement(e))return;let a=e.getStatement(),l=T(a,t,n,r,o,s);if(s.isInWorkflowCallback)r.loopCount++;else{if(l.length===0)return;r.loopCount++}if(l.length!==0)return{id:C(),type:"loop",loopType:"for-in",iterSource:e.getExpression().getText(),body:l,boundKnown:!1,location:t.includeLocations?I(e):void 0}}function Gn(e,t,n,r,o={isSagaWorkflow:!1},s={stepNames:new Set(["step"]),isInWorkflowCallback:!1,depth:0}){let{Node:i}=N();if(!i.isWhileStatement(e))return;let a=e.getStatement(),l=T(a,t,n,r,o,s);if(s.isInWorkflowCallback)r.loopCount++;else{if(l.length===0)return;r.loopCount++}if(l.length!==0)return{id:C(),type:"loop",loopType:"while",body:l,boundKnown:!1,location:t.includeLocations?I(e):void 0}}function Jn(e,t,n,r,o){o.workflowRefCount++;let s=t.replace(/\.runWithState$/,"").replace(/\.run$/,"");return{id:C(),type:"workflow-ref",workflowName:s,resolved:!1,location:n.includeLocations?I(e):void 0}}function Zn(e){let{Node:t}=N();if(!t.isCallExpression(e))return!1;let n=e.getArguments();if(n.length===0)return!1;let r=n[0];if(t.isArrowFunction(r)||t.isFunctionExpression(r)){let s=r.getParameters().map(i=>i.getText()).join(",");return s.includes("step")||s.includes("deps"),!0}return!1}function Yn(e){let{Node:t}=N(),n=[];if(!t.isObjectLiteralExpression(e))return n;for(let r of e.getProperties())(t.isPropertyAssignment(r)||t.isShorthandPropertyAssignment(r))&&n.push(r.getName());return n}function Qn(e,t){let{Node:n}=N(),r=[];if(!n.isObjectLiteralExpression(e))return r;for(let o of e.getProperties()){let s,i,a;if(n.isPropertyAssignment(o)){s=o.getName();let c=o.getInitializer();if(c&&typeof c.getType=="function")try{let u=c.getType();i=u.getText(),a=wt(c,u)}catch{}}else if(n.isShorthandPropertyAssignment(o)){s=o.getName();let c=o.getNameNode();if(c&&typeof c.getType=="function")try{let u=c.getType();i=u.getText(),a=wt(c,u)}catch{}}else continue;let l=ir(i);r.push({name:s,typeSignature:i,errorTypes:l,signature:a})}return r}function Xn(e){let t=new Map(e.dependencies.map(r=>[r.name,r]));function n(r){if(r.type==="step"){let o=r,s=o.reads,i=o.callee??o.name;if(s?.length&&i){let l=(t.get(i)??t.get(E(i)))?.signature;if(l?.params?.length){let c={},u=o.readParamIndices;s.forEach((d,p)=>{let f=u?.[p];if(f===void 0)return;let m=l.params[f];m?.type&&(c[d]=m.type)}),Object.keys(c).length>0&&(o.readTypes=c)}}}for(let o of $(r))n(o)}for(let r of e.children)n(r)}function er(e){let t=new Map(e.dependencies.map(r=>[r.name,r]));function n(r){if(r.type==="step"){let o=r;if(o.outputTypeInfo)return;let s=o.callee??o.name;if(!s)return;let a=(t.get(s)??t.get(E(s)))?.signature;if(!a?.returnType)return;let l=cr(a.returnType.display);l&&(o.outputTypeInfo=l.okType,o.errorTypeInfo=l.errorType,o.causeTypeInfo=l.causeType,o.outputTypeKind="declared")}for(let o of $(r))n(o)}for(let r of e.children)n(r)}function tr(e){function t(n){if(n.type==="step"){let r=n;if(r.errors!==void 0)return;let o=r.errorTypeInfo?.display;if(!o||o==="unknown"||o==="never")return;let s=nr(o).filter(i=>i&&i!=="unknown"&&i!=="never");s.length>0&&(r.errors=s,r.errorsSource="inferred")}for(let r of $(n))t(r)}for(let n of e.children)t(n)}function nr(e){let t=[],n=0,r=null,o=0;for(let s=0;s<e.length;s++){let i=e[s];if(r){if(i==="\\"){s++;continue}i===r&&(r=null);continue}if(i==='"'||i==="'"||i==="`"){r=i;continue}i==="<"||i==="("||i==="{"||i==="["?n++:i===">"||i===")"||i==="}"||i==="]"?n--:i==="|"&&n===0&&(t.push(e.slice(o,s).trim()),o=s+1)}return t.push(e.slice(o).trim()),t}var rr=new Set(["step.sleep","step.withResource","step.retry","step.withTimeout","step.try","step.fromResult"]);function or(e){function t(n){if(n.type==="step"){let r=n;if(!r.callee)return;let o=E(r.callee);rr.has(r.callee)?r.stepKind||(r.stepKind=o):r.depSource||(r.depSource=o)}for(let r of $(n))t(r)}for(let n of e.children)t(n)}function wt(e,t){let n=lt(),r=e.compilerNode;if(!r)return;let o=r.kind,s=o===n.SyntaxKind.FunctionDeclaration||o===n.SyntaxKind.ArrowFunction||o===n.SyntaxKind.FunctionExpression||o===n.SyntaxKind.MethodDeclaration;try{let l=e.getSourceFile().getProject().getTypeChecker().compilerObject,c;if(s)c=l.getSignatureFromDeclaration(r);else if(o===n.SyntaxKind.Identifier){let w=t.compilerType.getCallSignatures?.();c=w?.length?w[0]:void 0}if(!c)return;let u=c.getParameters().map((h,w)=>{let S=h.valueDeclaration,b=S?l.getTypeOfSymbolAtLocation(h,S):l.getAnyType(),g=l.typeToString(b);return{name:h.getName()??`param${w}`,type:{display:g,canonical:g.replace(/\s+/g," ").trim(),kind:"plain",confidence:"exact",source:"checker"}}}),d=c.getReturnType(),p=l.typeToString(d),f={display:p,canonical:p.replace(/\s+/g," ").trim(),kind:sr(p),confidence:"exact",source:"checker"},m=Se(d,l);return{params:u,returnType:f,resultLike:m?{okType:m.okType,errorType:m.errorType,causeType:m.causeType}:void 0}}catch{return}}function sr(e){return e.includes("AsyncResult")?"asyncResult":e.includes("Promise<Result")?"promiseResult":e.includes("Result")?"result":"plain"}function ir(e){if(!e)return[];let t=e.match(/Result\s*</);if(!t)return[];let n=t.index+t[0].length,r=1,o=n,s=-1;for(;o<e.length&&r>0;){let l=e[o];l==="<"||l==="["||l==="{"||l==="("?r++:l===">"||l==="]"||l==="}"||l===")"?r--:l===","&&r===1&&s<0&&(s=o),o++}return s<0||r!==0?[]:e.slice(s+1,o-1).trim().split(/\s*\|\s*/).map(l=>l.trim().replace(/^["']|["']$/g,"")).filter(l=>l.length>0&&/^[A-Z_][A-Z0-9_]*$/i.test(l))}function ar(e){let t=new Set;for(let n of e)for(let r of n.errorTypes)t.add(r);return Array.from(t)}function re(e){let{Node:t}=N(),n={};if(!t.isObjectLiteralExpression(e))return n;for(let r of e.getProperties()){if(!t.isPropertyAssignment(r))continue;let o=r.getName(),s=r.getInitializer();o!=="name"&&(o==="key"&&s?n.key=A(s):o==="description"&&s?n.description=A(s):o==="markdown"&&s?n.markdown=A(s):o==="retry"&&s&&t.isObjectLiteralExpression(s)?n.retry=At(s):o==="timeout"&&s&&t.isObjectLiteralExpression(s)?n.timeout=Lt(s):o==="errors"&&s?n.errors=q(s):o==="out"&&s?n.out=A(s):o==="dep"&&s?n.dep=A(s):o==="reads"&&s?n.reads=ee(s):o==="intent"&&s?n.intent=A(s):o==="domain"&&s?n.domain=A(s):o==="owner"&&s?n.owner=A(s):o==="tags"&&s?n.tags=ee(s):o==="stateChanges"&&s?n.stateChanges=ee(s):o==="emits"&&s?n.emits=ee(s):o==="calls"&&s?n.calls=ee(s):o==="errorMeta"&&s&&t.isObjectLiteralExpression(s)?n.errorMeta=lr(s):o==="ttl"&&s&&(n.ttl=te(s)))}return n}function lr(e){let{Node:t}=N();if(!t.isObjectLiteralExpression(e))return;let n={};for(let r of e.getProperties()){if(!t.isPropertyAssignment(r))continue;let o=r.getName(),s=r.getInitializer();if(!s||!t.isObjectLiteralExpression(s))continue;let i={};for(let a of s.getProperties()){if(!t.isPropertyAssignment(a))continue;let l=a.getName(),c=a.getInitializer();if(c){if(l==="retryable")i.retryable=Ue(c);else if(l==="severity"){let u=A(c);u&&u!=="<dynamic>"&&(i.severity=u)}else if(l==="description"){let u=A(c);u&&u!=="<dynamic>"&&(i.description=u)}}}n[o]=i}return Object.keys(n).length>0?n:void 0}function ee(e){let{Node:t}=N();if(t.isArrayLiteralExpression(e)){let n=[];for(let r of e.getElements()){let o=A(r);o&&o!=="<dynamic>"&&n.push(o)}return n.length>0?n:void 0}if(t.isIdentifier(e)){let n=Et(e);if(n)return ee(n)}}function q(e){let{Node:t}=N();if(t.isArrayLiteralExpression(e)){let n=[];for(let r of e.getElements()){let o=A(r);o&&o!=="<dynamic>"&&n.push(o)}return n}if(t.isCallExpression(e)){let r=e.getExpression().getText();if(r==="tags"||r==="err"){let o=[];for(let s of e.getArguments()){let i=A(s);i&&i!=="<dynamic>"&&o.push(i)}return o}}if(t.isIdentifier(e)){let n=Et(e);if(n)return q(n)}}function Et(e){let{Node:t}=N();if(!t.isIdentifier(e))return;let n=e.getSourceFile(),r=e.getText();for(let o of n.getStatements())if(t.isVariableStatement(o)){let s=o.getDeclarationList();if(s.getDeclarationKind()!=="const")continue;for(let i of s.getDeclarations())if(i.getName()===r)return i.getInitializer()}}function At(e){let{Node:t}=N(),n={};if(!t.isObjectLiteralExpression(e))return n;for(let r of e.getProperties()){if(!t.isPropertyAssignment(r))continue;let o=r.getName(),s=r.getInitializer();if(o==="attempts"&&s)n.attempts=te(s);else if(o==="backoff"&&s){let i=A(s);i==="fixed"||i==="linear"||i==="exponential"?n.backoff=i:n.backoff="<dynamic>"}else o==="baseDelay"&&s?n.baseDelay=te(s):o==="retryOn"&&s?n.retryOn=s.getText():o==="initialDelay"&&s?n.initialDelay=te(s):o==="maxDelay"&&s?n.maxDelay=te(s):o==="jitter"&&s&&(n.jitter=Ue(s)??"<dynamic>")}return n}function Lt(e){let{Node:t}=N(),n={};if(!t.isObjectLiteralExpression(e))return n;for(let r of e.getProperties()){if(!t.isPropertyAssignment(r))continue;let o=r.getName(),s=r.getInitializer();if(o==="ms"&&s)n.ms=te(s);else if(o==="signal"&&s)n.signal=Ue(s)??"<dynamic>";else if(o==="onTimeout"&&s){let i=A(s);i==="error"||i==="option"||i==="disconnect"?n.onTimeout=i:n.onTimeout="<dynamic>"}}return n}function A(e){let{Node:t}=N();return t.isStringLiteral(e)?e.getLiteralValue():t.isTemplateExpression(e)?"<dynamic>":t.isNoSubstitutionTemplateLiteral(e)?e.getLiteralValue():e.getText()}function te(e){let{Node:t}=N();return t.isNumericLiteral(e)?e.getLiteralValue():"<dynamic>"}function Ue(e){let{Node:t}=N();if(t.isTrueLiteral(e))return!0;if(t.isFalseLiteral(e))return!1}function le(e){let{Node:t}=N();if(t.isArrowFunction(e)||t.isFunctionExpression(e)){let n=e.getBody();if(t.isCallExpression(n))return n.getExpression().getText();if(t.isBlock(n)){for(let r of n.getStatements())if(t.isReturnStatement(r)){let o=r.getExpression();if(o&&t.isCallExpression(o))return o.getExpression().getText();break}}return n?.getText()??"<unknown>"}return t.isCallExpression(e)?e.getExpression().getText():e.getText()}function I(e){let t=e.getSourceFile(),n=e.getStart(),r=e.getEnd(),o=t.getLineAndColumnAtPos(n),s=t.getLineAndColumnAtPos(r);return{filePath:t.getFilePath(),line:o.line,column:o.column-1,endLine:s.line,endColumn:s.column-1}}function ce(e,t,n){let{Node:r}=N();if(!(!t||!r.isCallExpression(t)))try{let i=e.getSourceFile().getProject().getTypeChecker().compilerObject,a=t.compilerNode,l=t.getType(),c=l.compilerType;n.outputType=l.getText();let u=Se(c,i);if(!u||n.outputType==="any"||n.outputType==="unknown"){let f=a.expression,w=(i.getTypeAtLocation(f).getCallSignatures?.()??[])[0];if(w){let S=w.getReturnType(),b=i.typeToString(S);n.outputType=b,u=Se(S,i)}}u?(n.outputTypeInfo=u.okType,n.errorTypeInfo=u.errorType,n.causeTypeInfo=u.causeType,n.outputTypeKind="declared"):n.outputTypeKind=n.outputType==="any"?"unknown":"inferred";let p=i.getResolvedSignature(a);if(!p){let f=a.expression;p=(i.getTypeAtLocation(f).getCallSignatures?.()??[])[0]}if(p){let f=p.getDeclaration();if(f&&"parameters"in f&&Array.isArray(f.parameters)){let m=f.parameters;if(m.length>0){let h=m.map(w=>w.type?i.getTypeFromTypeNode(w.type):null).filter(w=>w!=null).map(w=>i.typeToString(w));h.length>0&&(n.inputType=h.join(", "))}}}}catch{}}function cr(e){let t=e,n=e.match(/^Promise<\s*([\s\S]+)\s*>$/);n&&(t=n[1].trim());let r,o,s=t.indexOf("AsyncResult<"),i=t.indexOf("Result<");if(s!==-1)r="asyncResult",o=s+12;else if(i!==-1)r=n?"promiseResult":"result",o=i+7;else return null;let a=1,l=o;for(let d=o;d<t.length;d++){let p=t[d];if(p==="<"||p==="("||p==="{"||p==="[")a++;else if((p===">"||p===")"||p==="}"||p==="]")&&(a--,a===0)){l=d;break}}let c=t.slice(o,l),u=ur(c);return u.length<2?null:{okType:_e(u[0],r),errorType:_e(u[1],r),causeType:u[2]?_e(u[2],r):void 0}}function ur(e){let t=[],n=0,r=null,o=0;for(let s=0;s<e.length;s++){let i=e[s];if(r){if(i==="\\"){s++;continue}i===r&&(r=null);continue}if(i==='"'||i==="'"||i==="`"){r=i;continue}i==="<"||i==="("||i==="{"||i==="["?n++:i===">"||i===")"||i==="}"||i==="]"?n--:i===","&&n===0&&(t.push(e.slice(o,s).trim()),o=s+1)}return t.push(e.slice(o).trim()),t}function _e(e,t){return{display:e,canonical:e.replace(/\s+/g," ").trim(),kind:"plain",confidence:"inferred",source:"checker"}}function be(e){if(!e)return{operation:void 0};let{Node:t}=N();if(!t.isCallExpression(e))return{operation:e};let n=e.getExpression();if(!t.isPropertyAccessExpression(n)||n.getName()!=="dep")return{operation:e};let r=e.getArguments(),o;return r[0]&&t.isStringLiteral(r[0])&&(o=r[0].getLiteralValue()),{operation:r[1]??e,depSourceOverride:o}}function xe(e){let{Node:t}=N();if(!e)return;let n;if(t.isArrowFunction(e)||t.isFunctionExpression(e)){for(n=e.getBody();t.isParenthesizedExpression(n);)n=n.getExpression();if(t.isCallExpression(n))return n;if(t.isBlock(n)){for(let r of n.getStatements())if(t.isReturnStatement(r)){let o=r.getExpression();if(o&&t.isCallExpression(o))return o;break}}}else if(t.isCallExpression(e))return e}function Ie(e){if(!e)return;let t=e.match(/^(?:deps|ctx\.deps)\.([a-zA-Z_$][a-zA-Z0-9_$]*)/);return t?t[1]:void 0}function ue(e){let{Node:t}=N();try{let r=e.getSourceFile().getProject().getTypeChecker(),o=e,s=r.getSymbolAtLocation(o);if(!s&&t.isPropertyAccessExpression(e)){let m=e.getNameNode();m&&(s=r.getSymbolAtLocation(m))}if(!s){let m=e.getType().compilerType;if(m){let h=m.getSymbol?.()??m.symbol;h&&(s=h)}}if(!s)return;let i=s.getDeclarations();if(!i?.length)return;let a=i[0],l=a.compilerNode??a,c=l.getSourceFile(),u=l.getStart(),d=l.getEnd(),p=c.getLineAndCharacterOfPosition(u),f=c.getLineAndCharacterOfPosition(d);return{filePath:c.fileName,line:p.line+1,column:p.character,endLine:f.line+1,endColumn:f.character}}catch{return}}function Y(e){let{Node:t}=N(),n=e;for(;n;){let r=n.getParent();if(!r)return n;if(t.isExpressionStatement(r)||t.isVariableStatement(r))return r;if(t.isBlock(r))return n;n=r}}function Be(e){return e.replace(/^\s*\/\*\*?\s*/,"").replace(/\s*\*\/\s*$/,"").replace(/^\s*\*\s?/gm,`
|
|
22
|
+
`).trim().split(/\s*@/)[0].trim()||void 0}function U(e){let t=e;if(typeof t.getJsDocs=="function")try{let n=t.getJsDocs();if(!n||n.length===0)return;let o=n[0].getTags?.();if(!o||o.length===0)return;let s={};for(let i of o){let a=i.getTagName?.()??i.getName?.(),l=typeof a=="string"?a.toLowerCase():void 0,c=i.getText().trim();if(l){if(l==="param"||l==="argument"||l==="arg"){let u=c.match(/^(?:@?\w+\s+)?(?:\{[^}]*\}\s*)?\[?(\w+)\]?\s*[-–—]\s*(.*)$/s),d=c.split(/\s+/),p=["@param","param","@argument","argument","@arg","arg"],f=b=>/^\{.*\}$/.test(b),m=d.find(b=>!p.includes(b)&&!f(b))??d[0]??"?",h=u?u[1].trim():m,w=h.replace(/^@/,"").replace(/^\[|\]$/g,"").split("=")[0].trim(),S;if(u)S=u[2].trim().replace(/\s*\*+\s*$/,"");else{let b=d.filter(x=>!f(x)),g=h.replace(/^@/,""),y=b.indexOf(g);S=(y>=0?b.slice(y+1).join(" "):b.slice(1).join(" ")).replace(/^\s*[-–—]\s*/,"").trim().replace(/\s*\*+\s*$/,"")||void 0}s.params=s.params??[],s.params.push({name:w,description:S||void 0})}else if(l==="returns"||l==="return"){let d=c.replace(/^@?(?:returns?|return)\s+/i,"").trim().replace(/^\s*\{[^}]*\}\s*/,"").trim().replace(/\s*\*+\s*$/,"");s.returns=d||void 0}else if(l==="throws"||l==="exception"){let p=c.trim().replace(/^@?(?:throws|exception)\s+/i,"").trim().replace(/^\s*\{[^}]*\}\s*/,"").trim().replace(/\s*\*+\s*$/,"");s.throws=s.throws??[],s.throws.push(p||"")}else if(l==="example"){let u=c.replace(/^@?example\s*/i,"").trim();s.example=u||void 0}}}return Object.keys(s).length>0?s:void 0}catch{return}}function V(e){let t=e;if(typeof t.getJsDocs=="function")try{let c=t.getJsDocs();if(c&&c.length>0){let u=c[0],d=u.getDescription?.();if(d&&d.trim())return d.trim();let p=u.getInnerText?.();if(p){let f=p.split(/\s*@/)[0].trim();if(f)return f}}}catch{}if(typeof e.getLeadingCommentRanges=="function"){let c=e.getLeadingCommentRanges();if(c&&c.length>0)for(let u=c.length-1;u>=0;u--){let p=c[u].getText();if(p.startsWith("/**")){let f=Be(p);if(f)return f;break}}}let r=e.getSourceFile().getFullText(),o=e.getStart();if(r.slice(o,o+3)==="/**"){let c=r.slice(o),u=c.match(/\*\/\s*/);if(u&&u.index!=null){let d=c.slice(0,u.index+2),p=Be(d);if(p)return p}}let s=r.slice(0,o),i=/\/\*\*([\s\S]*?)\*\//g,a,l=null;for(;(a=i.exec(s))!==null;)l=a;if(l){let c=l.index+l[0].length,u=s.slice(c);if(/^\s*$/.test(u)){let d=Be(l[0]);if(d)return d}}}function Pt(e,t){return e.length<=1?e:[{id:C(),type:"sequence",children:e}]}function $t(){return{totalSteps:0,conditionalCount:0,parallelCount:0,raceCount:0,loopCount:0,streamCount:0,workflowRefCount:0,unknownCount:0,sagaWorkflowCount:0,compensatedStepCount:0}}var fr=0;function C(){return`static-${++fr}`}function Dt(e){return{single(){if(e.length!==1){let t=e.map(n=>n.root.workflowName).join(", ");throw new Error(`Expected exactly 1 workflow, found ${e.length}.
|
|
23
23
|
|
|
24
24
|
`+(e.length>1?`Available workflows: ${t}
|
|
25
25
|
|
|
26
|
-
Use .named('workflowName') to select one.`:"Ensure the file contains a createWorkflow() or run() call."))}return e[0]},singleOrNull(){return e.length===1?e[0]:null},all(){return e},named(t){let n=e.find(r=>r.root.workflowName===t);if(!n){let r=e.map(o=>o.root.workflowName).join(", ");throw new Error(`Workflow "${t}" not found. Available: ${r||"(none)"}`)}return n},first(){if(e.length===0)throw new Error("No workflows found");return e[0]},firstOrNull(){return e[0]??null}}}function
|
|
27
|
-
`)}function K(e,t,n){if(e.length===0)return{firstNodeId:null,lastNodeIds:[]};let r=null,o=[];for(let i of e){let s=_e(i,t,n);if(r===null&&s.firstNodeId&&(r=s.firstNodeId),s.firstNodeId)for(let a of o)t.edges.push({from:a,to:s.firstNodeId});o=s.lastNodeIds}return{firstNodeId:r,lastNodeIds:o}}function _e(e,t,n){switch(e.type){case"step":return cr(e,t,n);case"saga-step":return fr(e,t,n);case"stream":return dr(e,t,n);case"sequence":return ur(e,t,n);case"parallel":return pr(e,t,n);case"race":return mr(e,t,n);case"conditional":return gr(e,t,n);case"decision":return yr(e,t,n);case"switch":return hr(e,t,n);case"loop":return Sr(e,t,n);case"workflow-ref":return wr(e,t,n);case"unknown":return Nr(e,t,n);default:return{firstNodeId:null,lastNodeIds:[]}}}function lr(e){let t=e.callee;if(!t)return"";if(t==="step.sleep")return e.sleepDuration?` (Sleep: ${e.sleepDuration})`:" (Sleep)";if(t==="step.retry"){let n=e.retry?.attempts;return n!=null&&n!=="<dynamic>"?` (Retry: ${n})`:" (Retry)"}if(t==="step.withTimeout"){let n=e.timeout?.ms;return n!=null&&n!=="<dynamic>"?` (Timeout: ${n}ms)`:" (Timeout)"}return t==="step.try"?" (Try)":t==="step.fromResult"?" (FromResult)":t==="step.run"?" (Run)":t==="step.andThen"?" (AndThen)":t==="step.match"?" (Match)":t==="step.map"?" (Map)":t==="step.withFallback"?" (Fallback)":t==="step.withResource"?" (Resource)":t==="step.workflow"?" (Workflow)":""}function cr(e,t,n){let r=`step_${++t.nodeCounter}`,o=e.name??(e.callee?A(e.callee):"step"),i=e.callee==="step.retry"||!e.callee?.startsWith("step.")&&e.retry,s=t.opts.expandRetry&&i&&e.retry,a=lr(e);if(s)a&&!a.includes("Retry")&&(o+=a);else if(a)o+=a;else{if(e.retry){let c=e.retry.attempts;o+=c!=null&&c!=="<dynamic>"?` (Retry: ${c})`:" (Retry)"}if(e.timeout){let c=e.timeout.ms;o+=c!=null&&c!=="<dynamic>"?` (Timeout: ${c}ms)`:" (Timeout)"}}if(t.opts.showKeys&&e.key&&(o=`${o}\\n[${e.key}]`),t.stepLabelAnnotations&&e.stepId){let c=t.stepLabelAnnotations.get(e.stepId);if(c)for(let f of c)o+=`\\n${f}`}if(e.tags&&e.tags.length>0&&(o+=`\\n[${e.tags.join(", ")}]`),n.push(` ${r}["${v(o)}"]`),t.styleClasses.set(r,"stepStyle"),e.stepId&&t.stepIdMap.set(e.stepId,r),t.opts.groupByDomain&&e.domain){let c=t.domainNodes.get(e.domain);c?c.push(r):t.domainNodes.set(e.domain,[r])}let l=[r];if(s){let c=`retry_${t.nodeCounter}`,f=e.retry.attempts,u=f!=null&&f!=="<dynamic>"?`Retry Logic (${f} attempts)`:"Retry Logic";n.push(` ${c}{"${v(u)}"}`),t.styleClasses.set(c,"retryLogicStyle"),t.edges.push({from:r,to:c});let p=`retry_ok_${t.nodeCounter}`;n.push(` ${p}["Success"]`),t.styleClasses.set(p,"stepStyle"),t.edges.push({from:c,to:p,label:"Success"});let d=`retry_fail_${t.nodeCounter}`;n.push(` ${d}["Retries Exhausted"]`),t.styleClasses.set(d,"errorExitStyle"),t.edges.push({from:c,to:d,label:"Retries Exhausted"}),l=[p]}if(t.opts.showInlineErrors&&e.errors&&e.errors.length>0)for(let c of e.errors){let f=`err_${r}_${ze(c)}`;n.push(` ${f}["${v(c)}"]`),t.styleClasses.set(f,"errorExitStyle"),t.edges.push({from:r,to:f,label:c})}return{firstNodeId:r,lastNodeIds:l}}function fr(e,t,n){let r=`saga_step_${++t.nodeCounter}`,o=e.name??(e.callee?A(e.callee):"saga-step");return t.opts.showKeys&&e.key&&(o=`${o}\\n[${e.key}]`),e.hasCompensation&&(o+="\\n(compensable)"),e.isTryStep&&(o+="\\n(try)"),n.push(` ${r}["${v(o)}"]`),t.styleClasses.set(r,"sagaStepStyle"),{firstNodeId:r,lastNodeIds:[r]}}function dr(e,t,n){let r=`stream_${++t.nodeCounter}`,o=e.namespace?`stream:${e.namespace}`:`stream:${e.streamType}`;return n.push(` ${r}[/"${v(o)}"/]`),t.styleClasses.set(r,"streamStyle"),{firstNodeId:r,lastNodeIds:[r]}}function ur(e,t,n){return K(e.children,t,n)}function pr(e,t,n){let r=`parallel_fork_${++t.nodeCounter}`,o=`parallel_join_${++t.nodeCounter}`,i=e.mode==="allSettled"?"AllSettled":e.mode,s=e.name?`${v(e.name)} (${i})`:`Parallel (${i})`;n.push(` ${r}{{"${s}"}}`),t.styleClasses.set(r,"parallelStyle"),n.push(` ${o}{{"Join"}}`),t.styleClasses.set(o,"parallelStyle");for(let a=0;a<e.children.length;a++){let l=e.children[a],c=_e(l,t,n);c.firstNodeId&&t.edges.push({from:r,to:c.firstNodeId,label:`branch ${a+1}`});for(let f of c.lastNodeIds)t.edges.push({from:f,to:o})}return{firstNodeId:r,lastNodeIds:[o]}}function mr(e,t,n){let r=`race_fork_${++t.nodeCounter}`,o=`race_join_${++t.nodeCounter}`,i=e.name?v(e.name):"Race";n.push(` ${r}{{"${i}"}}`),t.styleClasses.set(r,"raceStyle"),n.push(` ${o}{{"Winner"}}`),t.styleClasses.set(o,"raceStyle");for(let s=0;s<e.children.length;s++){let a=e.children[s],l=_e(a,t,n);l.firstNodeId&&t.edges.push({from:r,to:l.firstNodeId,label:`racer ${s+1}`});for(let c of l.lastNodeIds)t.edges.push({from:c,to:o})}return{firstNodeId:r,lastNodeIds:[o]}}function gr(e,t,n){let r=`decision_${++t.nodeCounter}`,o=fe(e.condition,30);n.push(` ${r}{"${v(o)}"}`),t.styleClasses.set(r,"conditionalStyle");let i=[],s=K(e.consequent,t,n);if(s.firstNodeId){let a=e.helper==="unless"||e.helper==="unlessOr"?"false":"true";t.edges.push({from:r,to:s.firstNodeId,label:a}),i.push(...s.lastNodeIds)}if(e.alternate&&e.alternate.length>0){let a=K(e.alternate,t,n);if(a.firstNodeId){let l=e.helper==="unless"||e.helper==="unlessOr"?"true":"false";t.edges.push({from:r,to:a.firstNodeId,label:l}),i.push(...a.lastNodeIds)}}else i.push(r);if(t.opts.sameLevelConditionals&&i.length>0){let a=`merge_${++t.nodeCounter}`;n.push(` ${a}["Merge"]`),t.styleClasses.set(a,"mergeStyle");for(let l of i)t.edges.push({from:l,to:a});return{firstNodeId:r,lastNodeIds:[a]}}return{firstNodeId:r,lastNodeIds:i}}function yr(e,t,n){let r=`decision_${++t.nodeCounter}`,o=e.conditionLabel||fe(e.condition,30);n.push(` ${r}{"${v(o)}"}`),t.styleClasses.set(r,"conditionalStyle");let i=[],s=e.conditionLabel&&e.conditionLabel!=="<dynamic>",a=s?e.conditionLabel:"true",l=s?`Not ${e.conditionLabel}`:"false",c=K(e.consequent,t,n);if(c.firstNodeId&&(t.edges.push({from:r,to:c.firstNodeId,label:a}),i.push(...c.lastNodeIds)),e.alternate&&e.alternate.length>0){let f=K(e.alternate,t,n);f.firstNodeId&&(t.edges.push({from:r,to:f.firstNodeId,label:l}),i.push(...f.lastNodeIds))}else i.push(r);if(t.opts.sameLevelConditionals&&i.length>0){let f=`merge_${++t.nodeCounter}`;n.push(` ${f}["Merge"]`),t.styleClasses.set(f,"mergeStyle");for(let u of i)t.edges.push({from:u,to:f});return{firstNodeId:r,lastNodeIds:[f]}}return{firstNodeId:r,lastNodeIds:i}}function hr(e,t,n){let r=`switch_${++t.nodeCounter}`,o=fe(e.expression,30);n.push(` ${r}{"${v(`switch: ${o}`)}"}`),t.styleClasses.set(r,"switchStyle");let i=[];for(let s of e.cases){if(s.body.length===0)continue;let a=K(s.body,t,n);if(a.firstNodeId){let l=s.isDefault?"default":fe(s.value??"",15);t.edges.push({from:r,to:a.firstNodeId,label:l}),i.push(...a.lastNodeIds)}}return i.length===0&&i.push(r),{firstNodeId:r,lastNodeIds:i}}function Sr(e,t,n){let r=`loop_start_${++t.nodeCounter}`,o=`loop_end_${++t.nodeCounter}`,i=e.iterSource?`${e.loopType}: ${fe(e.iterSource,20)}`:e.loopType;n.push(` ${r}(["${v(i)}"])`),t.styleClasses.set(r,"loopStyle");let s=t.inLoop;t.inLoop={loopType:e.loopType,iterSource:e.iterSource};let a=K(e.body,t,n);t.inLoop=s,a.firstNodeId&&t.edges.push({from:r,to:a.firstNodeId,label:"iterate"}),n.push(` ${o}(["Continue?"])`),t.styleClasses.set(o,"loopStyle");for(let l of a.lastNodeIds)t.edges.push({from:l,to:o});return t.edges.push({from:o,to:r,label:"next"}),{firstNodeId:r,lastNodeIds:[o]}}function wr(e,t,n){let r=`workflow_ref_${++t.nodeCounter}`,o=`[[${e.workflowName}]]`;return n.push(` ${r}${o}`),t.styleClasses.set(r,"workflowRefStyle"),{firstNodeId:r,lastNodeIds:[r]}}function Nr(e,t,n){let r=`unknown_${++t.nodeCounter}`;return n.push(` ${r}[/"Unknown: ${v(e.reason)}"/]`),{firstNodeId:r,lastNodeIds:[r]}}function v(e){return e.replace(/\\n/g," ").replace(/\r?\n/g," ").replace(/"/g,"'").replace(/\[/g,"(").replace(/\]/g,")").replace(/\{/g,"(").replace(/\}/g,")").replace(/</g,"<").replace(/>/g,">").replace(/#/g,"#").replace(/\|/g,"|")}function fe(e,t){return e.length<=t?e:e.slice(0,t-3)+"..."}var Ao={...At,showDataFlow:!0,showErrors:!0,showErrorNodes:!1,highlightMissingErrors:!0};function ze(e){return e.replace(/[^a-zA-Z0-9_]/g,"_")}function Lt(e,t,n={}){let{pretty:r=!0,includeMetadata:o=!0}=n,i={file:t,analyzedAt:Date.now(),workflowCount:e.length,workflows:e.map(s=>({root:s.root,metadata:o?s.metadata:void 0,references:s.references.size>0?Object.fromEntries(Array.from(s.references.entries()).map(([a,l])=>[a,{root:l.root,metadata:o?l.metadata:void 0}])):void 0}))};return r?JSON.stringify(i,null,2):JSON.stringify(i)}function J(e){if(e)return{filePath:e.filePath,line:e.line,column:e.column,endLine:e.endLine,endColumn:e.endColumn}}function Dt(e){return e.key?e.key:e.type==="step"?e.stepId??e.id:e.id}function ue(e,t){return e.length<=t?e:e.slice(0,t-3)+"..."}function W(e,t,n,r,o){e.states.push({id:t,label:n,type:r,...o})}function $(e,t,n,r,o){e.transitions.push({fromStateId:t,toStateId:n,event:r,...o?{conditionLabel:o}:{}})}function U(e,t,n){if(e.length===0)return{firstId:null,lastIds:n};let r=null,o=n;for(let i of e){let s=Be(i,t);if(s.firstId){r===null&&(r=s.firstId);for(let a of o)$(t,a,s.firstId,"done")}o=s.lastIds}return{firstId:r,lastIds:o}}function Be(e,t){switch(e.type){case"step":return br(e,t);case"saga-step":return xr(e,t);case"stream":return Ir(e,t);case"sequence":return Tr(e,t);case"parallel":return Cr(e,t);case"race":return Rr(e,t);case"conditional":return Er(e,t);case"decision":return Ar(e,t);case"switch":return Lr(e,t);case"loop":return Dr(e,t);case"workflow-ref":return $r(e,t);case"unknown":return Wr(e,t);default:return{firstId:null,lastIds:[]}}}function kr(e){let t=e.callee;if(!t)return"";if(t==="step.sleep")return e.sleepDuration?` (Sleep: ${e.sleepDuration})`:" (Sleep)";if(t==="step.retry"){let n=e.retry?.attempts;return n!=null&&n!=="<dynamic>"?` (Retry: ${n})`:" (Retry)"}if(t==="step.withTimeout"){let n=e.timeout?.ms;return n!=null&&n!=="<dynamic>"?` (Timeout: ${n}ms)`:" (Timeout)"}return t==="step.try"?" (Try)":t==="step.fromResult"?" (FromResult)":t==="step.run"?" (Run)":t==="step.andThen"?" (AndThen)":t==="step.match"?" (Match)":t==="step.map"?" (Map)":t==="step.withFallback"?" (Fallback)":t==="step.withResource"?" (Resource)":t==="step.workflow"?" (Workflow)":""}function br(e,t){let n=Dt(e),r=e.name??(e.callee?A(e.callee):"step"),o=kr(e);if(o)r+=o;else{if(e.retry){let s=e.retry.attempts;r+=s!=null&&s!=="<dynamic>"?` (Retry: ${s})`:" (Retry)"}if(e.timeout){let s=e.timeout.ms;r+=s!=null&&s!=="<dynamic>"?` (Timeout: ${s}ms)`:" (Timeout)"}}let i=e.depSource??e.stepKind;return i&&(r+=` (dep: ${i})`),W(t,n,r,"step",{outputType:e.outputType,inputType:e.inputType,location:J(e.location)}),{firstId:n,lastIds:[n]}}function xr(e,t){let n=Dt(e),r=e.name??(e.callee?A(e.callee):"saga-step");return W(t,n,r,"step",{location:J(e.location)}),{firstId:n,lastIds:[n]}}function Ir(e,t){let n=`stream_${++t.nodeCounter}`,r=e.namespace?`stream:${e.namespace}`:`stream:${e.streamType}`;return W(t,n,r,"step",{location:J(e.location)}),{firstId:n,lastIds:[n]}}function Tr(e,t){return U(e.children,t,[])}function Cr(e,t){let n=`parallel_fork_${++t.nodeCounter}`,r=`parallel_join_${++t.nodeCounter}`,o=e.mode==="allSettled"?"AllSettled":e.mode,i=e.name?`${e.name} (${o})`:`Parallel (${o})`;W(t,n,i,"decision"),W(t,r,"Join","join");let s=[];for(let a=0;a<e.children.length;a++){let l=Be(e.children[a],t);if(l.firstId){$(t,n,l.firstId,`branch:${a}`);for(let c of l.lastIds)$(t,c,r,"done"),s.push(r)}}return{firstId:n,lastIds:[r]}}function Rr(e,t){let n=`race_fork_${++t.nodeCounter}`,r=`race_join_${++t.nodeCounter}`;W(t,n,"Race","decision"),W(t,r,"Winner","join");for(let o=0;o<e.children.length;o++){let i=Be(e.children[o],t);if(i.firstId){$(t,n,i.firstId,`racer:${o}`);for(let s of i.lastIds)$(t,s,r,"done")}}return{firstId:n,lastIds:[r]}}function Er(e,t){let n=`decision_${++t.nodeCounter}`,r=ue(e.condition,40);W(t,n,r,"decision",{location:J(e.location)});let o=[],i=U(e.consequent,t,[]);if(i.firstId&&($(t,n,i.firstId,e.helper==="unless"||e.helper==="unlessOr"?"false":"true"),o.push(...i.lastIds)),e.alternate&&e.alternate.length>0){let s=U(e.alternate,t,[]);s.firstId&&($(t,n,s.firstId,e.helper==="unless"||e.helper==="unlessOr"?"true":"false"),o.push(...s.lastIds))}else o.push(n);return{firstId:n,lastIds:o}}function Ar(e,t){let n=`decision_${++t.nodeCounter}`,r=e.conditionLabel||ue(e.condition,40);W(t,n,r,"decision",{location:J(e.location)});let o=e.conditionLabel&&e.conditionLabel!=="<dynamic>",i=o?e.conditionLabel:"true",s=o?`Not ${e.conditionLabel}`:"false",a=[],l=U(e.consequent,t,[]);if(l.firstId&&($(t,n,l.firstId,i,e.conditionLabel),a.push(...l.lastIds)),e.alternate&&e.alternate.length>0){let c=U(e.alternate,t,[]);c.firstId&&($(t,n,c.firstId,s,e.conditionLabel),a.push(...c.lastIds))}else a.push(n);return{firstId:n,lastIds:a}}function Lr(e,t){let n=`switch_${++t.nodeCounter}`,r=ue(`switch: ${e.expression}`,40);W(t,n,r,"decision",{location:J(e.location)});let o=[];for(let i of e.cases){if(i.body.length===0)continue;let s=U(i.body,t,[]);if(s.firstId){let a=i.isDefault?"default":i.value??"case";$(t,n,s.firstId,a),o.push(...s.lastIds)}}return o.length===0&&o.push(n),{firstId:n,lastIds:o}}function Dr(e,t){let n=`loop_entry_${++t.nodeCounter}`,r=e.iterSource?`${e.loopType}: ${ue(e.iterSource,20)}`:e.loopType;W(t,n,r,"decision",{location:J(e.location)});let o=U(e.body,t,[]);if(!o.firstId)return{firstId:n,lastIds:[n]};$(t,n,o.firstId,"iterate");for(let s of o.lastIds)$(t,s,n,"next");let i=`loop_exit_${++t.nodeCounter}`;return W(t,i,"Loop done","join"),$(t,n,i,"done"),{firstId:n,lastIds:[i]}}function $r(e,t){let n=`workflow_ref_${++t.nodeCounter}`;return W(t,n,`[[${e.workflowName}]]`,"step",{location:J(e.location)}),{firstId:n,lastIds:[n]}}function Wr(e,t){let n=`unknown_${++t.nodeCounter}`;return W(t,n,`Unknown: ${ue(e.reason,30)}`,"step"),{firstId:n,lastIds:[n]}}var Te="start",Ce="end";function $t(e){let t={states:[],transitions:[],nodeCounter:0,lastNodeIds:[]};W(t,Te,"Start","initial"),W(t,Ce,"End","terminal");let n=U(e.root.children,t,[]);if(n.firstId){$(t,Te,n.firstId,"start");for(let r of n.lastIds)$(t,r,Ce,"done")}else $(t,Te,Ce,"done");return{workflowName:e.root.workflowName,states:t.states,transitions:t.transitions,initialStateId:Te,terminalStateIds:[Ce],workflowReturnType:e.root.workflowReturnType}}import{generateInteractiveHTML as Mt}from"awaitly-visualizer";function Wt(e){let t={},n={value:0};return G(e.root.children,t,n),{workflowName:e.root.workflowName,description:e.root.description??e.root.jsdocDescription,filePath:e.metadata.filePath,stats:{totalSteps:e.metadata.stats.totalSteps,conditionalCount:e.metadata.stats.conditionalCount,parallelCount:e.metadata.stats.parallelCount,raceCount:e.metadata.stats.raceCount,loopCount:e.metadata.stats.loopCount},nodes:t}}function Ft(e){let t={},n={value:0};return Pt(e.root.children,t,n),{workflowName:e.root.workflowName,description:e.root.description??e.root.jsdocDescription,filePath:e.metadata.filePath,stats:{totalSteps:e.metadata.stats.totalSteps,conditionalCount:e.metadata.stats.conditionalCount,parallelCount:e.metadata.stats.parallelCount,raceCount:e.metadata.stats.raceCount,loopCount:e.metadata.stats.loopCount},nodes:t}}function Pt(e,t,n){for(let r of e){r.type==="step"?vt(r,t,n):r.type==="saga-step"&&Ot(r,t,n);let o=P(r);o.length>0&&Pt(o,t,n)}}function G(e,t,n){for(let r of e)qe(r,t,n)}function qe(e,t,n){switch(e.type){case"step":vt(e,t,n);break;case"saga-step":Ot(e,t,n);break;case"stream":Fr(e,t,n);break;case"sequence":G(e.children,t,n);break;case"parallel":Pr(e,t,n);break;case"race":vr(e,t,n);break;case"conditional":Or(e,t,n);break;case"decision":Mr(e,t,n);break;case"switch":jr(e,t,n);break;case"loop":zr(e,t,n);break;case"workflow-ref":_r(e,t,n);break;case"unknown":Br(e,t,n);break}}function vt(e,t,n){let r=`step_${++n.value}`,o={mermaidId:r,type:"step",name:e.name??e.callee??"step",stepId:e.stepId,callee:e.callee,description:e.description??e.jsdocDescription,location:e.location,retry:e.retry,timeout:e.timeout,errors:e.errors,inputType:e.inputType,outputType:e.outputTypeInfo?.display??(e.outputType!=="any"||e.outputTypeKind==="unknown"?e.outputType:void 0),out:e.out,reads:e.reads};e.errorTypeInfo?.display&&(o.errorType=e.errorTypeInfo.display),t[r]=o}function Ot(e,t,n){let r=`saga_step_${++n.value}`;t[r]={mermaidId:r,type:"saga-step",name:e.name??e.callee??"saga-step",callee:e.callee,description:e.description??e.jsdocDescription,location:e.location,hasCompensation:e.hasCompensation,compensationCallee:e.compensationCallee}}function Fr(e,t,n){let r=`stream_${++n.value}`;t[r]={mermaidId:r,type:"stream",name:e.namespace?`stream:${e.namespace}`:`stream:${e.streamType}`,streamType:e.streamType,namespace:e.namespace,location:e.location}}function Pr(e,t,n){let r=`parallel_fork_${++n.value}`,o=`parallel_join_${++n.value}`;t[r]={mermaidId:r,type:"parallel-fork",name:e.name??`Parallel (${e.mode})`,mode:e.mode,childCount:e.children.length,location:e.location};for(let i of e.children)qe(i,t,n);t[o]={mermaidId:o,type:"parallel-join",name:"Join"}}function vr(e,t,n){let r=`race_fork_${++n.value}`,o=`race_join_${++n.value}`;t[r]={mermaidId:r,type:"race-fork",name:e.name??"Race",childCount:e.children.length,location:e.location};for(let i of e.children)qe(i,t,n);t[o]={mermaidId:o,type:"race-join",name:"Winner"}}function Or(e,t,n){let r=`decision_${++n.value}`;t[r]={mermaidId:r,type:"conditional",name:e.condition,condition:e.condition,helper:e.helper??void 0,location:e.location},G(e.consequent,t,n),e.alternate&&e.alternate.length>0&&G(e.alternate,t,n)}function Mr(e,t,n){let r=`decision_${++n.value}`;t[r]={mermaidId:r,type:"decision",name:e.conditionLabel||e.condition,condition:e.condition,location:e.location},G(e.consequent,t,n),e.alternate&&e.alternate.length>0&&G(e.alternate,t,n)}function jr(e,t,n){let r=`switch_${++n.value}`;t[r]={mermaidId:r,type:"switch",name:`switch: ${e.expression}`,expression:e.expression,cases:e.cases.map(o=>({value:o.value,isDefault:o.isDefault})),location:e.location};for(let o of e.cases)o.body.length>0&&G(o.body,t,n)}function zr(e,t,n){let r=`loop_start_${++n.value}`,o=`loop_end_${++n.value}`;t[r]={mermaidId:r,type:"loop-start",name:e.iterSource?`${e.loopType}: ${e.iterSource}`:e.loopType,loopType:e.loopType,iterSource:e.iterSource,boundCount:e.boundCount,location:e.location},G(e.body,t,n),t[o]={mermaidId:o,type:"loop-end",name:"Continue?"}}function _r(e,t,n){let r=`workflow_ref_${++n.value}`;t[r]={mermaidId:r,type:"workflow-ref",name:e.workflowName,workflowName:e.workflowName,resolved:e.resolved,location:e.location}}function Br(e,t,n){let r=`unknown_${++n.value}`;t[r]={mermaidId:r,type:"unknown",name:`Unknown: ${e.reason}`,location:e.location}}import{mkdirSync as qr,writeFileSync as Vr}from"fs";import{join as Ve,isAbsolute as Kr}from"path";var Ur=".awaitly",Jr="dsl",jt=".awaitly";function Gr(e){let t=e.rootDir??process.cwd();return e.outputDir?Kr(e.outputDir)?e.outputDir:Ve(t,e.outputDir):Ve(t,Ur,Jr)}function zt(e,t={}){let{filename:n,pretty:r=!0}=t,o=Hr(e.workflowName),i=n??`${o}.dsl.json`,s=Gr(t);qr(s,{recursive:!0});let a=Ve(s,i),l=r?JSON.stringify(e,null,2):JSON.stringify(e);return Vr(a,l,"utf-8"),a}function Hr(e){return e.replace(/[^a-zA-Z0-9_-]/g,"_")}function _t(e){let t=[],n=0;function r(o,i){if(o.type==="step"){let s=o;t.push({stepId:s.stepId,callee:s.callee,containerType:i,index:n++});return}if(o.type==="saga-step"){let s=o;t.push({stepId:s.name??s.id,callee:s.callee,containerType:i,index:n++});return}for(let s of P(o))r(s,o.type)}for(let o of e.root.children)r(o,"workflow");return t}var Zr=["parallel","race","conditional","decision","switch","loop","stream","sequence"];function Bt(e){let t=new Map;function n(r){Zr.includes(r.type)&&t.set(r.type,(t.get(r.type)??0)+1);for(let o of P(r))n(o)}for(let r of e.root.children)n(r);return t}function Ke(e,t,n){let r=n?.detectRenames??!0,o=n?.regressionMode??!1,i=_t(e),s=_t(t),a=new Map;for(let S of i)a.set(S.stepId,S);let l=new Map;for(let S of s)l.set(S.stepId,S);let c=[],f=new Set,u=new Set;for(let[S,b]of a){let g=l.get(S);g&&(f.add(S),u.add(S),b.containerType!==g.containerType?c.push({kind:"moved",stepId:S,callee:g.callee,containerBefore:b.containerType,containerAfter:g.containerType}):c.push({kind:"unchanged",stepId:S,callee:g.callee}))}if(r){let S=i.filter(g=>!f.has(g.stepId)),b=s.filter(g=>!u.has(g.stepId));for(let g of S){if(f.has(g.stepId))continue;let h=b.find(k=>!u.has(k.stepId)&&k.callee!==void 0&&g.callee!==void 0&&k.callee===g.callee&&k.index===g.index);h&&(f.add(g.stepId),u.add(h.stepId),c.push({kind:"renamed",stepId:h.stepId,previousStepId:g.stepId,callee:h.callee}))}}for(let S of i)f.has(S.stepId)||c.push({kind:"removed",stepId:S.stepId,callee:S.callee});for(let S of s)u.has(S.stepId)||c.push({kind:"added",stepId:S.stepId,callee:S.callee});let p=Bt(e),d=Bt(t),m=new Set([...p.keys(),...d.keys()]),y=[];for(let S of m){let b=p.get(S)??0,g=d.get(S)??0;if(g>b){let h=g-b;y.push({kind:"added",nodeType:S,description:`${h} ${S} block${h>1?"s":""}`})}else if(b>g){let h=b-g;y.push({kind:"removed",nodeType:S,description:`${h} ${S} block${h>1?"s":""}`})}}let w={stepsAdded:c.filter(S=>S.kind==="added").length,stepsRemoved:c.filter(S=>S.kind==="removed").length,stepsRenamed:c.filter(S=>S.kind==="renamed").length,stepsMoved:c.filter(S=>S.kind==="moved").length,stepsUnchanged:c.filter(S=>S.kind==="unchanged").length,structuralChanges:y.length,hasRegressions:o&&c.some(S=>S.kind==="removed")};return{beforeName:e.root.workflowName,afterName:t.root.workflowName,diffedAt:Date.now(),steps:c,structuralChanges:y,summary:w}}function Je(e,t){let n=t?.showUnchanged??!0,r=t?.title??`Workflow Diff: ${e.beforeName} \u2192 ${e.afterName}`,o=[];o.push(`# ${r}`),o.push(""),o.push("## Summary"),o.push(`- ${e.summary.stepsAdded} added, ${e.summary.stepsRemoved} removed, ${e.summary.stepsRenamed} renamed, ${e.summary.stepsMoved} moved, ${e.summary.stepsUnchanged} unchanged`),e.summary.structuralChanges>0&&o.push(`- ${e.summary.structuralChanges} structural change${e.summary.structuralChanges!==1?"s":""}`),o.push("");let i=e.steps.filter(c=>c.kind==="added");if(i.length>0){o.push("## Added Steps");for(let c of i)o.push(`- ${Ue(c)}`);o.push("")}let s=e.steps.filter(c=>c.kind==="removed");if(s.length>0){let c=e.summary.hasRegressions?"\u26A0\uFE0F ":"";o.push(`## ${c}Removed Steps`);for(let f of s)o.push(`- ${Ue(f)}`);o.push("")}let a=e.steps.filter(c=>c.kind==="renamed");if(a.length>0){o.push("## Renamed Steps");for(let c of a){let f=c.callee?` (${c.callee})`:"";o.push(`- \`${c.previousStepId}\` \u2192 \`${c.stepId}\`${f}`)}o.push("")}let l=e.steps.filter(c=>c.kind==="moved");if(l.length>0){o.push("## Moved Steps");for(let c of l)o.push(`- \`${c.stepId}\` moved from ${c.containerBefore??"unknown"} \u2192 ${c.containerAfter??"unknown"}`);o.push("")}if(e.structuralChanges.length>0){o.push("## Structural Changes");for(let c of e.structuralChanges){let f=c.kind==="added"?"Added":"Removed";o.push(`- ${f}: ${c.description}`)}o.push("")}if(n){let c=e.steps.filter(f=>f.kind==="unchanged");if(c.length>0){o.push("## Unchanged Steps");for(let f of c)o.push(`- ${Ue(f)}`);o.push("")}}return o.join(`
|
|
26
|
+
Use .named('workflowName') to select one.`:"Ensure the file contains a createWorkflow() or run() call."))}return e[0]},singleOrNull(){return e.length===1?e[0]:null},all(){return e},named(t){let n=e.find(r=>r.root.workflowName===t);if(!n){let r=e.map(o=>o.root.workflowName).join(", ");throw new Error(`Workflow "${t}" not found. Available: ${r||"(none)"}`)}return n},first(){if(e.length===0)throw new Error("No workflows found");return e[0]},firstOrNull(){return e[0]??null}}}function Te(e,t){let n=bt(e,t);return Dt(n)}Te.source=function(e,t){let n=ne(e,void 0,t);return Dt(n)};var Wt={direction:"TD",showKeys:!1,showConditions:!0,useSubgraphs:!0,showInlineErrors:!1,expandRetry:!1,sameLevelConditionals:!1,groupByDomain:!1,styles:{step:"fill:#e1f5fe,stroke:#01579b",sagaStep:"fill:#e8eaf6,stroke:#1a237e",stream:"fill:#e0f7fa,stroke:#006064",parallel:"fill:#e8f5e9,stroke:#1b5e20",race:"fill:#fff3e0,stroke:#e65100",conditional:"fill:#fce4ec,stroke:#880e4f",merge:"fill:#e3f2fd,stroke:#1565c0",switch:"fill:#f3e5f5,stroke:#4a148c",loop:"fill:#f3e5f5,stroke:#4a148c",workflowRef:"fill:#e0f2f1,stroke:#004d40",start:"fill:#c8e6c9,stroke:#2e7d32",end:"fill:#ffcdd2,stroke:#c62828",errorExit:"fill:#ffcdd2,stroke:#c62828,stroke-width:2px",retryLogic:"fill:#fff3e0,stroke:#e65100"}};function dr(e,t,n){let r={opts:t,nodeCounter:0,edges:[],subgraphs:[],styleClasses:new Map,stepIdMap:new Map,stepLabelAnnotations:n,domainNodes:new Map},o=[];o.push(`flowchart ${t.direction}`),o.push(""),o.push(` %% Workflow: ${e.root.workflowName}`),o.push("");let s="start";o.push(` ${s}((Start))`);let{firstNodeId:i,lastNodeIds:a}=K(e.root.children,r,o);i&&r.edges.push({from:s,to:i});let l="end_node";o.push(` ${l}((End))`);for(let c of a)r.edges.push({from:c,to:l});for(let c of r.subgraphs){o.push(""),o.push(` subgraph ${c.id}[${c.label}]`);for(let u of c.content)o.push(` ${u}`);o.push(" end")}if(t.groupByDomain&&r.domainNodes.size>0){let c=new Set;for(let[u,d]of r.domainNodes){let p=`domain_${Ve(u)}`,f=2;for(;c.has(p);)p=`domain_${Ve(u)}_${f++}`;c.add(p),o.push(""),o.push(` subgraph ${p}["${v(u)}"]`);for(let m of d)o.push(` ${m}`);o.push(" end")}}o.push(""),o.push(" %% Edges");for(let c of r.edges)c.label&&t.showConditions?o.push(` ${c.from} -->|${v(c.label)}| ${c.to}`):o.push(` ${c.from} --> ${c.to}`);o.push(""),o.push(" %% Styles"),o.push(` classDef stepStyle ${t.styles.step}`),o.push(` classDef sagaStepStyle ${t.styles.sagaStep}`),o.push(` classDef streamStyle ${t.styles.stream}`),o.push(` classDef parallelStyle ${t.styles.parallel}`),o.push(` classDef raceStyle ${t.styles.race}`),o.push(` classDef conditionalStyle ${t.styles.conditional}`),o.push(` classDef mergeStyle ${t.styles.merge}`),o.push(` classDef switchStyle ${t.styles.switch}`),o.push(` classDef loopStyle ${t.styles.loop}`),o.push(` classDef workflowRefStyle ${t.styles.workflowRef}`),o.push(` classDef startStyle ${t.styles.start}`),o.push(` classDef endStyle ${t.styles.end}`),t.showInlineErrors&&o.push(` classDef errorExitStyle ${t.styles.errorExit}`),t.expandRetry&&o.push(` classDef retryLogicStyle ${t.styles.retryLogic}`),o.push(` class ${s} startStyle`),o.push(` class ${l} endStyle`);for(let[c,u]of r.styleClasses)o.push(` class ${c} ${u}`);return{lines:o,context:r}}function de(e,t={}){let n={...Wt,...t},{lines:r}=dr(e,n);return r.join(`
|
|
27
|
+
`)}function K(e,t,n){if(e.length===0)return{firstNodeId:null,lastNodeIds:[]};let r=null,o=[];for(let s of e){let i=Ke(s,t,n);if(r===null&&i.firstNodeId&&(r=i.firstNodeId),i.firstNodeId)for(let a of o)t.edges.push({from:a,to:i.firstNodeId});o=i.lastNodeIds}return{firstNodeId:r,lastNodeIds:o}}function Ke(e,t,n){switch(e.type){case"step":return mr(e,t,n);case"saga-step":return gr(e,t,n);case"stream":return hr(e,t,n);case"sequence":return yr(e,t,n);case"parallel":return Sr(e,t,n);case"race":return wr(e,t,n);case"conditional":return Nr(e,t,n);case"decision":return kr(e,t,n);case"switch":return br(e,t,n);case"loop":return xr(e,t,n);case"workflow-ref":return Ir(e,t,n);case"unknown":return Tr(e,t,n);default:return{firstNodeId:null,lastNodeIds:[]}}}function pr(e){let t=e.callee;if(!t)return"";if(t==="step.sleep")return e.sleepDuration?` (Sleep: ${e.sleepDuration})`:" (Sleep)";if(t==="step.retry"){let n=e.retry?.attempts;return n!=null&&n!=="<dynamic>"?` (Retry: ${n})`:" (Retry)"}if(t==="step.withTimeout"){let n=e.timeout?.ms;return n!=null&&n!=="<dynamic>"?` (Timeout: ${n}ms)`:" (Timeout)"}return t==="step.try"?" (Try)":t==="step.fromResult"?" (FromResult)":t==="step.run"?" (Run)":t==="step.andThen"?" (AndThen)":t==="step.match"?" (Match)":t==="step.map"?" (Map)":t==="step.withFallback"?" (Fallback)":t==="step.withResource"?" (Resource)":t==="step.workflow"?" (Workflow)":""}function mr(e,t,n){let r=`step_${++t.nodeCounter}`,o=e.name??(e.callee?E(e.callee):"step"),s=e.callee==="step.retry"||!e.callee?.startsWith("step.")&&e.retry,i=t.opts.expandRetry&&s&&e.retry,a=pr(e);if(i)a&&!a.includes("Retry")&&(o+=a);else if(a)o+=a;else{if(e.retry){let c=e.retry.attempts;o+=c!=null&&c!=="<dynamic>"?` (Retry: ${c})`:" (Retry)"}if(e.timeout){let c=e.timeout.ms;o+=c!=null&&c!=="<dynamic>"?` (Timeout: ${c}ms)`:" (Timeout)"}}if(t.opts.showKeys&&e.key&&(o=`${o}\\n[${e.key}]`),t.stepLabelAnnotations&&e.stepId){let c=t.stepLabelAnnotations.get(e.stepId);if(c)for(let u of c)o+=`\\n${u}`}if(e.tags&&e.tags.length>0&&(o+=`\\n[${e.tags.join(", ")}]`),n.push(` ${r}["${v(o)}"]`),t.styleClasses.set(r,"stepStyle"),e.stepId&&t.stepIdMap.set(e.stepId,r),t.opts.groupByDomain&&e.domain){let c=t.domainNodes.get(e.domain);c?c.push(r):t.domainNodes.set(e.domain,[r])}let l=[r];if(i){let c=`retry_${t.nodeCounter}`,u=e.retry.attempts,d=u!=null&&u!=="<dynamic>"?`Retry Logic (${u} attempts)`:"Retry Logic";n.push(` ${c}{"${v(d)}"}`),t.styleClasses.set(c,"retryLogicStyle"),t.edges.push({from:r,to:c});let p=`retry_ok_${t.nodeCounter}`;n.push(` ${p}["Success"]`),t.styleClasses.set(p,"stepStyle"),t.edges.push({from:c,to:p,label:"Success"});let f=`retry_fail_${t.nodeCounter}`;n.push(` ${f}["Retries Exhausted"]`),t.styleClasses.set(f,"errorExitStyle"),t.edges.push({from:c,to:f,label:"Retries Exhausted"}),l=[p]}if(t.opts.showInlineErrors&&e.errors&&e.errors.length>0)for(let c of e.errors){let u=`err_${r}_${Ve(c)}`;n.push(` ${u}["${v(c)}"]`),t.styleClasses.set(u,"errorExitStyle"),t.edges.push({from:r,to:u,label:c})}return{firstNodeId:r,lastNodeIds:l}}function gr(e,t,n){let r=`saga_step_${++t.nodeCounter}`,o=e.name??(e.callee?E(e.callee):"saga-step");return t.opts.showKeys&&e.key&&(o=`${o}\\n[${e.key}]`),e.hasCompensation&&(o+="\\n(compensable)"),e.isTryStep&&(o+="\\n(try)"),n.push(` ${r}["${v(o)}"]`),t.styleClasses.set(r,"sagaStepStyle"),{firstNodeId:r,lastNodeIds:[r]}}function hr(e,t,n){let r=`stream_${++t.nodeCounter}`,o=e.namespace?`stream:${e.namespace}`:`stream:${e.streamType}`;return n.push(` ${r}[/"${v(o)}"/]`),t.styleClasses.set(r,"streamStyle"),{firstNodeId:r,lastNodeIds:[r]}}function yr(e,t,n){return K(e.children,t,n)}function Sr(e,t,n){let r=`parallel_fork_${++t.nodeCounter}`,o=`parallel_join_${++t.nodeCounter}`,s=e.mode==="allSettled"?"AllSettled":e.mode,i=e.name?`${v(e.name)} (${s})`:`Parallel (${s})`;n.push(` ${r}{{"${i}"}}`),t.styleClasses.set(r,"parallelStyle"),n.push(` ${o}{{"Join"}}`),t.styleClasses.set(o,"parallelStyle");for(let a=0;a<e.children.length;a++){let l=e.children[a],c=Ke(l,t,n);c.firstNodeId&&t.edges.push({from:r,to:c.firstNodeId,label:`branch ${a+1}`});for(let u of c.lastNodeIds)t.edges.push({from:u,to:o})}return{firstNodeId:r,lastNodeIds:[o]}}function wr(e,t,n){let r=`race_fork_${++t.nodeCounter}`,o=`race_join_${++t.nodeCounter}`,s=e.name?v(e.name):"Race";n.push(` ${r}{{"${s}"}}`),t.styleClasses.set(r,"raceStyle"),n.push(` ${o}{{"Winner"}}`),t.styleClasses.set(o,"raceStyle");for(let i=0;i<e.children.length;i++){let a=e.children[i],l=Ke(a,t,n);l.firstNodeId&&t.edges.push({from:r,to:l.firstNodeId,label:`racer ${i+1}`});for(let c of l.lastNodeIds)t.edges.push({from:c,to:o})}return{firstNodeId:r,lastNodeIds:[o]}}function Nr(e,t,n){let r=`decision_${++t.nodeCounter}`,o=fe(e.condition,30);n.push(` ${r}{"${v(o)}"}`),t.styleClasses.set(r,"conditionalStyle");let s=[],i=K(e.consequent,t,n);if(i.firstNodeId){let a=e.helper==="unless"||e.helper==="unlessOr"?"false":"true";t.edges.push({from:r,to:i.firstNodeId,label:a}),s.push(...i.lastNodeIds)}if(e.alternate&&e.alternate.length>0){let a=K(e.alternate,t,n);if(a.firstNodeId){let l=e.helper==="unless"||e.helper==="unlessOr"?"true":"false";t.edges.push({from:r,to:a.firstNodeId,label:l}),s.push(...a.lastNodeIds)}}else s.push(r);if(t.opts.sameLevelConditionals&&s.length>0){let a=`merge_${++t.nodeCounter}`;n.push(` ${a}["Merge"]`),t.styleClasses.set(a,"mergeStyle");for(let l of s)t.edges.push({from:l,to:a});return{firstNodeId:r,lastNodeIds:[a]}}return{firstNodeId:r,lastNodeIds:s}}function kr(e,t,n){let r=`decision_${++t.nodeCounter}`,o=e.conditionLabel||fe(e.condition,30);n.push(` ${r}{"${v(o)}"}`),t.styleClasses.set(r,"conditionalStyle");let s=[],i=e.conditionLabel&&e.conditionLabel!=="<dynamic>",a=i?e.conditionLabel:"true",l=i?`Not ${e.conditionLabel}`:"false",c=K(e.consequent,t,n);if(c.firstNodeId&&(t.edges.push({from:r,to:c.firstNodeId,label:a}),s.push(...c.lastNodeIds)),e.alternate&&e.alternate.length>0){let u=K(e.alternate,t,n);u.firstNodeId&&(t.edges.push({from:r,to:u.firstNodeId,label:l}),s.push(...u.lastNodeIds))}else s.push(r);if(t.opts.sameLevelConditionals&&s.length>0){let u=`merge_${++t.nodeCounter}`;n.push(` ${u}["Merge"]`),t.styleClasses.set(u,"mergeStyle");for(let d of s)t.edges.push({from:d,to:u});return{firstNodeId:r,lastNodeIds:[u]}}return{firstNodeId:r,lastNodeIds:s}}function br(e,t,n){let r=`switch_${++t.nodeCounter}`,o=fe(e.expression,30);n.push(` ${r}{"${v(`switch: ${o}`)}"}`),t.styleClasses.set(r,"switchStyle");let s=[];for(let i of e.cases){if(i.body.length===0)continue;let a=K(i.body,t,n);if(a.firstNodeId){let l=i.isDefault?"default":fe(i.value??"",15);t.edges.push({from:r,to:a.firstNodeId,label:l}),s.push(...a.lastNodeIds)}}return s.length===0&&s.push(r),{firstNodeId:r,lastNodeIds:s}}function xr(e,t,n){let r=`loop_start_${++t.nodeCounter}`,o=`loop_end_${++t.nodeCounter}`,s=e.iterSource?`${e.loopType}: ${fe(e.iterSource,20)}`:e.loopType;n.push(` ${r}(["${v(s)}"])`),t.styleClasses.set(r,"loopStyle");let i=t.inLoop;t.inLoop={loopType:e.loopType,iterSource:e.iterSource};let a=K(e.body,t,n);t.inLoop=i,a.firstNodeId&&t.edges.push({from:r,to:a.firstNodeId,label:"iterate"}),n.push(` ${o}(["Continue?"])`),t.styleClasses.set(o,"loopStyle");for(let l of a.lastNodeIds)t.edges.push({from:l,to:o});return t.edges.push({from:o,to:r,label:"next"}),{firstNodeId:r,lastNodeIds:[o]}}function Ir(e,t,n){let r=`workflow_ref_${++t.nodeCounter}`,o=`[[${e.workflowName}]]`;return n.push(` ${r}${o}`),t.styleClasses.set(r,"workflowRefStyle"),{firstNodeId:r,lastNodeIds:[r]}}function Tr(e,t,n){let r=`unknown_${++t.nodeCounter}`;return n.push(` ${r}[/"Unknown: ${v(e.reason)}"/]`),{firstNodeId:r,lastNodeIds:[r]}}function v(e){return e.replace(/\\n/g," ").replace(/\r?\n/g," ").replace(/"/g,"'").replace(/\[/g,"(").replace(/\]/g,")").replace(/\{/g,"(").replace(/\}/g,")").replace(/</g,"<").replace(/>/g,">").replace(/#/g,"#").replace(/\|/g,"|")}function fe(e,t){return e.length<=t?e:e.slice(0,t-3)+"..."}var ss={...Wt,showDataFlow:!0,showErrors:!0,showErrorNodes:!1,highlightMissingErrors:!0};function Ve(e){return e.replace(/[^a-zA-Z0-9_]/g,"_")}var Cr={testNamePrefix:"should",testNameGenerator:Ar,includeLoopPaths:!0};function Ft(e,t={},n){let r={...Cr,...t},o=n?Fr(n):new Map,s=e;r.includeLoopPaths||(s=e.filter(c=>!c.hasLoops));let i=s.map(c=>Rr(c,r,o)),a=$r(s),l=Dr(i,a);return{paths:i,conditions:a,summary:l}}function Rr(e,t,n){let r=t.testNameGenerator(e),o=Er(e,n),s=e.conditions.map(a=>{let l=a.mustBe?"be truthy":"be falsy";return`Set up ${a.expression} to ${l}`}),i=e.steps.map(a=>{let l=a.name??a.nodeId;return a.repeated?`${l} (may repeat)`:l});return{id:e.id,suggestedTestName:r,description:e.description,setupConditions:s,expectedSteps:i,priority:o}}function Er(e,t){if(e.conditions.length===0&&!e.hasLoops)return"high";if(t.size>0){let n=!1,r=!0,o=!1,s=!1;for(let i of e.steps){let a=t.get(i.nodeId);if(a){if(a.errors?.length&&!a.errorMeta){s=!0;continue}if(a.errorMeta){if(a.errors?.length){let l=new Set(Object.keys(a.errorMeta));a.errors.some(c=>!l.has(c))&&(s=!0)}for(let l of Object.values(a.errorMeta))o=!0,l.severity==="business"&&(n=!0),l.severity==="infrastructure"&&l.retryable||(r=!1)}}}if(n)return"high";if(o&&r&&!s)return"low"}return e.hasLoops&&e.conditions.length>2?"low":"medium"}function Ar(e){let t=["should"];if(e.steps.length>0){let n=e.steps.filter(r=>!r.repeated).slice(0,3);if(n.length>0){let r=n.map(o=>Lr(o.name??o.nodeId));t.push(r.join(" then "))}}if(e.conditions.length>0){t.push("when");let n=e.conditions.slice(0,2).map(r=>{let o=Pr(r.expression);return r.mustBe?o:`not ${o}`});t.push(n.join(" and "))}return e.hasLoops&&t.push("(with iteration)"),t.join(" ")}function Lr(e){return e.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/([A-Z])([A-Z][a-z])/g,"$1 $2").toLowerCase()}function Pr(e){return e.replace(/\s*===\s*true/g,"").replace(/\s*===\s*false/g," is false").replace(/\s*===\s*/g," is ").replace(/\s*!==\s*/g," is not ").replace(/\s*>\s*/g," greater than ").replace(/\s*<\s*/g," less than ").replace(/\s*>=\s*/g," at least ").replace(/\s*<=\s*/g," at most ").replace(/&&/g," and ").replace(/\|\|/g," or ").trim()}function $r(e){let t=new Map;for(let n of e)for(let r of n.conditions){let o=r.expression;t.has(o)||t.set(o,{whenTrue:[],whenFalse:[]});let s=t.get(o);r.mustBe?s.whenTrue.push(n.id):s.whenFalse.push(n.id)}return Array.from(t.entries()).map(([n,r])=>({expression:n,affectedPathsWhenTrue:r.whenTrue,affectedPathsWhenFalse:r.whenFalse}))}function Dr(e,t){let n=e.filter(o=>o.priority==="high").length,r=Math.max(1,t.length*2);return{totalPaths:e.length,highPriorityPaths:n,totalConditions:t.length,minTestsForCoverage:r}}function vt(e,t={}){let n=t.testRunner??"vitest",r=t.workflowName??"workflow",o=[];n==="vitest"?o.push("import { describe, it, expect } from 'vitest';"):n==="jest"?o.push("// Jest test file"):(o.push("import { describe, it } from 'mocha';"),o.push("import { expect } from 'chai';")),o.push(""),o.push(`describe('${r}', () => {`);for(let s of e.paths){o.push(""),o.push(` it('${Wr(s.suggestedTestName)}', async () => {`),o.push(" // Setup");for(let i of s.setupConditions)o.push(` // TODO: ${i}`);o.push(""),o.push(" // Execute workflow"),o.push(` // const result = await ${r}(...);`),o.push(""),o.push(" // Verify expected steps executed");for(let i of s.expectedSteps)o.push(` // TODO: Verify ${i} was called`);o.push(" });")}return o.push("});"),o.push(""),o.join(`
|
|
28
|
+
`)}function Wr(e){return e.replace(/'/g,"\\'").replace(/"/g,'\\"')}function Fr(e){let t=new Map;function n(r){r.type==="step"&&t.set(r.id,r);for(let o of $(r))n(o)}for(let r of e.root.children)n(r);return t}var vr={maxPaths:1e3,expandWorkflowRefs:!1,expandLoops:!1,maxLoopIterations:3};function Ot(e,t={}){return Or(e,t).paths}function Or(e,t={}){let r={opts:{...vr,...t},pathCount:0,hasHitLimit:!1},o={steps:[],conditions:[],hasLoops:!1,hasUnresolvedRefs:!1};return{paths:M(e.root.children,o,r).map((a,l)=>({id:`path-${l+1}`,description:Jr(a),steps:a.steps,conditions:a.conditions,hasLoops:a.hasLoops,hasUnresolvedRefs:a.hasUnresolvedRefs})),limitHit:r.hasHitLimit}}function M(e,t,n){if(e.length===0)return[t];let r=[t];for(let o of e){let s=[];for(let i of r){let a=Ce(o,i,n);s.push(...a)}r=s}return r}function Ce(e,t,n){switch(e.type){case"step":return Mr(e,t);case"saga-step":return jr(e,t);case"sequence":return zr(e,t,n);case"parallel":return _r(e,t,n);case"race":return Br(e,t,n);case"conditional":return qr(e,t,n);case"decision":return Ur(e,t,n);case"switch":return Vr(e,t,n);case"loop":return Kr(e,t,n);case"stream":return Hr(e,t);case"workflow-ref":return Gr(e,t,n);case"unknown":return[t];default:return[t]}}function Mr(e,t){let n={nodeId:e.id,key:e.key,name:e.name??(e.callee?E(e.callee):void 0),repeated:!1};return[{...t,steps:[...t.steps,n]}]}function jr(e,t){let n={nodeId:e.id,key:e.key,name:e.name??(e.callee?E(e.callee):void 0),repeated:!1};return[{...t,steps:[...t.steps,n]}]}function zr(e,t,n){return M(e.children,t,n)}function _r(e,t,n){let r=[t];for(let o of e.children){let s=[];for(let i of r){let a=Ce(o,i,n);for(let l of a)s.push({steps:l.steps,conditions:l.conditions,hasLoops:i.hasLoops||l.hasLoops,hasUnresolvedRefs:i.hasUnresolvedRefs||l.hasUnresolvedRefs})}r=s}return r}function Br(e,t,n){if(e.children.length===0)return[t];let r=n.pathCount+1;if(n.hasHitLimit||r>=n.opts.maxPaths)return n.hasHitLimit=!0,Ce(e.children[0],t,n);let s=n.pathCount,i=n.opts.maxPaths,a=[];for(let l of e.children){if(a.length>=i){n.hasHitLimit=!0;break}let c=Ce(l,t,n),u=i-a.length,d=c.slice(0,u);a.push(...d),d.length<c.length&&(n.hasHitLimit=!0)}return n.pathCount=s+(a.length-1),a}function qr(e,t,n){let r=n.pathCount+1,o=n.hasHitLimit||r>=n.opts.maxPaths;o&&(n.hasHitLimit=!0);let s={expression:e.condition,mustBe:!(e.helper==="unless"||e.helper==="unlessOr"),location:e.location},i={...t,conditions:[...t.conditions,s]},a=M(e.consequent,i,n);if(o||n.hasHitLimit)return a;let l=[...a],c={expression:e.condition,mustBe:e.helper==="unless"||e.helper==="unlessOr",location:e.location},u={...t,conditions:[...t.conditions,c]};if(e.alternate&&e.alternate.length>0){let d=M(e.alternate,u,n);l.push(...d)}else l.push(u);return n.pathCount+=l.length-1,n.pathCount+1>=n.opts.maxPaths&&(n.hasHitLimit=!0),l}function Ur(e,t,n){let r=n.pathCount+1,o=n.hasHitLimit||r>=n.opts.maxPaths;o&&(n.hasHitLimit=!0);let s={expression:e.conditionLabel||e.condition,mustBe:!0,location:e.location},i={...t,conditions:[...t.conditions,s]},a=M(e.consequent,i,n);if(o||n.hasHitLimit)return a;let l=[...a],c={expression:e.conditionLabel||e.condition,mustBe:!1,location:e.location},u={...t,conditions:[...t.conditions,c]};if(e.alternate&&e.alternate.length>0){let d=M(e.alternate,u,n);l.push(...d)}else l.push(u);return n.pathCount+=l.length-1,n.pathCount+1>=n.opts.maxPaths&&(n.hasHitLimit=!0),l}function Vr(e,t,n){let r=[];for(let o of e.cases){let s={expression:o.isDefault?`${e.expression} === default`:`${e.expression} === ${o.value}`,mustBe:!0,location:e.location},i={...t,conditions:[...t.conditions,s]},a=M(o.body,i,n);if(r.push(...a),n.hasHitLimit)break}return r.length>0?r:[t]}function Kr(e,t,n){return M(e.body,t,n).map(o=>({...o,steps:o.steps.map((s,i)=>i>=t.steps.length?{...s,repeated:!0}:s),hasLoops:!0}))}function Hr(e,t){let n={nodeId:e.id,name:e.namespace?`stream:${e.namespace}`:`stream:${e.streamType}`,repeated:!1};return[{...t,steps:[...t.steps,n]}]}function Gr(e,t,n){if(n.opts.expandWorkflowRefs&&e.resolved&&e.inlinedIR)return M(e.inlinedIR.root.children,t,n);let r={nodeId:e.id,name:`[workflow: ${e.workflowName}]`,repeated:!1};return[{...t,steps:[...t.steps,r],hasUnresolvedRefs:!e.resolved}]}function Jr(e){let t=[];if(e.conditions.length>0){let r=e.conditions.map(o=>{let s=o.mustBe?"is true":"is false";return`${o.expression.length>30?o.expression.slice(0,30)+"...":o.expression} ${s}`});t.push(`When ${r.join(" AND ")}`)}let n=e.steps.map(r=>{let o=r.name??r.nodeId;return r.repeated?`${o} (repeated)`:o}).join(" \u2192 ");return n&&t.push(`Steps: ${n}`),e.hasLoops&&t.push("[contains loops]"),e.hasUnresolvedRefs&&t.push("[has unresolved workflow refs]"),t.join(". ")||"Empty path"}function Mt(e,t,n={}){let{pretty:r=!0,includeMetadata:o=!0}=n,s={file:t,analyzedAt:Date.now(),workflowCount:e.length,workflows:e.map(i=>({root:i.root,metadata:o?i.metadata:void 0,references:i.references.size>0?Object.fromEntries(Array.from(i.references.entries()).map(([a,l])=>[a,{root:l.root,metadata:o?l.metadata:void 0}])):void 0}))};return r?JSON.stringify(s,null,2):JSON.stringify(s)}function G(e){if(e)return{filePath:e.filePath,line:e.line,column:e.column,endLine:e.endLine,endColumn:e.endColumn}}function jt(e){return e.key?e.key:e.type==="step"?e.stepId??e.id:e.id}function pe(e,t){return e.length<=t?e:e.slice(0,t-3)+"..."}function W(e,t,n,r,o){e.states.push({id:t,label:n,type:r,...o})}function D(e,t,n,r,o){e.transitions.push({fromStateId:t,toStateId:n,event:r,...o?{conditionLabel:o}:{}})}function H(e,t,n){if(e.length===0)return{firstId:null,lastIds:n};let r=null,o=n;for(let s of e){let i=He(s,t);if(i.firstId){r===null&&(r=i.firstId);for(let a of o)D(t,a,i.firstId,"done")}o=i.lastIds}return{firstId:r,lastIds:o}}function He(e,t){switch(e.type){case"step":return Yr(e,t);case"saga-step":return Qr(e,t);case"stream":return Xr(e,t);case"sequence":return eo(e,t);case"parallel":return to(e,t);case"race":return no(e,t);case"conditional":return ro(e,t);case"decision":return oo(e,t);case"switch":return so(e,t);case"loop":return io(e,t);case"workflow-ref":return ao(e,t);case"unknown":return lo(e,t);default:return{firstId:null,lastIds:[]}}}function Zr(e){let t=e.callee;if(!t)return"";if(t==="step.sleep")return e.sleepDuration?` (Sleep: ${e.sleepDuration})`:" (Sleep)";if(t==="step.retry"){let n=e.retry?.attempts;return n!=null&&n!=="<dynamic>"?` (Retry: ${n})`:" (Retry)"}if(t==="step.withTimeout"){let n=e.timeout?.ms;return n!=null&&n!=="<dynamic>"?` (Timeout: ${n}ms)`:" (Timeout)"}return t==="step.try"?" (Try)":t==="step.fromResult"?" (FromResult)":t==="step.run"?" (Run)":t==="step.andThen"?" (AndThen)":t==="step.match"?" (Match)":t==="step.map"?" (Map)":t==="step.withFallback"?" (Fallback)":t==="step.withResource"?" (Resource)":t==="step.workflow"?" (Workflow)":""}function Yr(e,t){let n=jt(e),r=e.name??(e.callee?E(e.callee):"step"),o=Zr(e);if(o)r+=o;else{if(e.retry){let i=e.retry.attempts;r+=i!=null&&i!=="<dynamic>"?` (Retry: ${i})`:" (Retry)"}if(e.timeout){let i=e.timeout.ms;r+=i!=null&&i!=="<dynamic>"?` (Timeout: ${i}ms)`:" (Timeout)"}}let s=e.depSource??e.stepKind;return s&&(r+=` (dep: ${s})`),W(t,n,r,"step",{outputType:e.outputType,inputType:e.inputType,location:G(e.location)}),{firstId:n,lastIds:[n]}}function Qr(e,t){let n=jt(e),r=e.name??(e.callee?E(e.callee):"saga-step");return W(t,n,r,"step",{location:G(e.location)}),{firstId:n,lastIds:[n]}}function Xr(e,t){let n=`stream_${++t.nodeCounter}`,r=e.namespace?`stream:${e.namespace}`:`stream:${e.streamType}`;return W(t,n,r,"step",{location:G(e.location)}),{firstId:n,lastIds:[n]}}function eo(e,t){return H(e.children,t,[])}function to(e,t){let n=`parallel_fork_${++t.nodeCounter}`,r=`parallel_join_${++t.nodeCounter}`,o=e.mode==="allSettled"?"AllSettled":e.mode,s=e.name?`${e.name} (${o})`:`Parallel (${o})`;W(t,n,s,"decision"),W(t,r,"Join","join");let i=[];for(let a=0;a<e.children.length;a++){let l=He(e.children[a],t);if(l.firstId){D(t,n,l.firstId,`branch:${a}`);for(let c of l.lastIds)D(t,c,r,"done"),i.push(r)}}return{firstId:n,lastIds:[r]}}function no(e,t){let n=`race_fork_${++t.nodeCounter}`,r=`race_join_${++t.nodeCounter}`;W(t,n,"Race","decision"),W(t,r,"Winner","join");for(let o=0;o<e.children.length;o++){let s=He(e.children[o],t);if(s.firstId){D(t,n,s.firstId,`racer:${o}`);for(let i of s.lastIds)D(t,i,r,"done")}}return{firstId:n,lastIds:[r]}}function ro(e,t){let n=`decision_${++t.nodeCounter}`,r=pe(e.condition,40);W(t,n,r,"decision",{location:G(e.location)});let o=[],s=H(e.consequent,t,[]);if(s.firstId&&(D(t,n,s.firstId,e.helper==="unless"||e.helper==="unlessOr"?"false":"true"),o.push(...s.lastIds)),e.alternate&&e.alternate.length>0){let i=H(e.alternate,t,[]);i.firstId&&(D(t,n,i.firstId,e.helper==="unless"||e.helper==="unlessOr"?"true":"false"),o.push(...i.lastIds))}else o.push(n);return{firstId:n,lastIds:o}}function oo(e,t){let n=`decision_${++t.nodeCounter}`,r=e.conditionLabel||pe(e.condition,40);W(t,n,r,"decision",{location:G(e.location)});let o=e.conditionLabel&&e.conditionLabel!=="<dynamic>",s=o?e.conditionLabel:"true",i=o?`Not ${e.conditionLabel}`:"false",a=[],l=H(e.consequent,t,[]);if(l.firstId&&(D(t,n,l.firstId,s,e.conditionLabel),a.push(...l.lastIds)),e.alternate&&e.alternate.length>0){let c=H(e.alternate,t,[]);c.firstId&&(D(t,n,c.firstId,i,e.conditionLabel),a.push(...c.lastIds))}else a.push(n);return{firstId:n,lastIds:a}}function so(e,t){let n=`switch_${++t.nodeCounter}`,r=pe(`switch: ${e.expression}`,40);W(t,n,r,"decision",{location:G(e.location)});let o=[];for(let s of e.cases){if(s.body.length===0)continue;let i=H(s.body,t,[]);if(i.firstId){let a=s.isDefault?"default":s.value??"case";D(t,n,i.firstId,a),o.push(...i.lastIds)}}return o.length===0&&o.push(n),{firstId:n,lastIds:o}}function io(e,t){let n=`loop_entry_${++t.nodeCounter}`,r=e.iterSource?`${e.loopType}: ${pe(e.iterSource,20)}`:e.loopType;W(t,n,r,"decision",{location:G(e.location)});let o=H(e.body,t,[]);if(!o.firstId)return{firstId:n,lastIds:[n]};D(t,n,o.firstId,"iterate");for(let i of o.lastIds)D(t,i,n,"next");let s=`loop_exit_${++t.nodeCounter}`;return W(t,s,"Loop done","join"),D(t,n,s,"done"),{firstId:n,lastIds:[s]}}function ao(e,t){let n=`workflow_ref_${++t.nodeCounter}`;return W(t,n,`[[${e.workflowName}]]`,"step",{location:G(e.location)}),{firstId:n,lastIds:[n]}}function lo(e,t){let n=`unknown_${++t.nodeCounter}`;return W(t,n,`Unknown: ${pe(e.reason,30)}`,"step"),{firstId:n,lastIds:[n]}}var Re="start",Ee="end";function zt(e){let t={states:[],transitions:[],nodeCounter:0,lastNodeIds:[]};W(t,Re,"Start","initial"),W(t,Ee,"End","terminal");let n=H(e.root.children,t,[]);if(n.firstId){D(t,Re,n.firstId,"start");for(let r of n.lastIds)D(t,r,Ee,"done")}else D(t,Re,Ee,"done");return{workflowName:e.root.workflowName,states:t.states,transitions:t.transitions,initialStateId:Re,terminalStateIds:[Ee],workflowReturnType:e.root.workflowReturnType}}import{generateInteractiveHTML as Kt}from"awaitly-visualizer";function _t(e){let t={},n={value:0};return J(e.root.children,t,n),{workflowName:e.root.workflowName,description:e.root.description??e.root.jsdocDescription,filePath:e.metadata.filePath,stats:{totalSteps:e.metadata.stats.totalSteps,conditionalCount:e.metadata.stats.conditionalCount,parallelCount:e.metadata.stats.parallelCount,raceCount:e.metadata.stats.raceCount,loopCount:e.metadata.stats.loopCount},nodes:t}}function Bt(e){let t={},n={value:0};return qt(e.root.children,t,n),{workflowName:e.root.workflowName,description:e.root.description??e.root.jsdocDescription,filePath:e.metadata.filePath,stats:{totalSteps:e.metadata.stats.totalSteps,conditionalCount:e.metadata.stats.conditionalCount,parallelCount:e.metadata.stats.parallelCount,raceCount:e.metadata.stats.raceCount,loopCount:e.metadata.stats.loopCount},nodes:t}}function qt(e,t,n){for(let r of e){r.type==="step"?Ut(r,t,n):r.type==="saga-step"&&Vt(r,t,n);let o=$(r);o.length>0&&qt(o,t,n)}}function J(e,t,n){for(let r of e)Ge(r,t,n)}function Ge(e,t,n){switch(e.type){case"step":Ut(e,t,n);break;case"saga-step":Vt(e,t,n);break;case"stream":co(e,t,n);break;case"sequence":J(e.children,t,n);break;case"parallel":uo(e,t,n);break;case"race":fo(e,t,n);break;case"conditional":po(e,t,n);break;case"decision":mo(e,t,n);break;case"switch":go(e,t,n);break;case"loop":ho(e,t,n);break;case"workflow-ref":yo(e,t,n);break;case"unknown":So(e,t,n);break}}function Ut(e,t,n){let r=`step_${++n.value}`,o={mermaidId:r,type:"step",name:e.name??e.callee??"step",stepId:e.stepId,callee:e.callee,description:e.description??e.jsdocDescription,location:e.location,retry:e.retry,timeout:e.timeout,errors:e.errors,inputType:e.inputType,outputType:e.outputTypeInfo?.display??(e.outputType!=="any"||e.outputTypeKind==="unknown"?e.outputType:void 0),out:e.out,reads:e.reads};e.errorTypeInfo?.display&&(o.errorType=e.errorTypeInfo.display),t[r]=o}function Vt(e,t,n){let r=`saga_step_${++n.value}`;t[r]={mermaidId:r,type:"saga-step",name:e.name??e.callee??"saga-step",callee:e.callee,description:e.description??e.jsdocDescription,location:e.location,hasCompensation:e.hasCompensation,compensationCallee:e.compensationCallee}}function co(e,t,n){let r=`stream_${++n.value}`;t[r]={mermaidId:r,type:"stream",name:e.namespace?`stream:${e.namespace}`:`stream:${e.streamType}`,streamType:e.streamType,namespace:e.namespace,location:e.location}}function uo(e,t,n){let r=`parallel_fork_${++n.value}`,o=`parallel_join_${++n.value}`;t[r]={mermaidId:r,type:"parallel-fork",name:e.name??`Parallel (${e.mode})`,mode:e.mode,childCount:e.children.length,location:e.location};for(let s of e.children)Ge(s,t,n);t[o]={mermaidId:o,type:"parallel-join",name:"Join"}}function fo(e,t,n){let r=`race_fork_${++n.value}`,o=`race_join_${++n.value}`;t[r]={mermaidId:r,type:"race-fork",name:e.name??"Race",childCount:e.children.length,location:e.location};for(let s of e.children)Ge(s,t,n);t[o]={mermaidId:o,type:"race-join",name:"Winner"}}function po(e,t,n){let r=`decision_${++n.value}`;t[r]={mermaidId:r,type:"conditional",name:e.condition,condition:e.condition,helper:e.helper??void 0,location:e.location},J(e.consequent,t,n),e.alternate&&e.alternate.length>0&&J(e.alternate,t,n)}function mo(e,t,n){let r=`decision_${++n.value}`;t[r]={mermaidId:r,type:"decision",name:e.conditionLabel||e.condition,condition:e.condition,location:e.location},J(e.consequent,t,n),e.alternate&&e.alternate.length>0&&J(e.alternate,t,n)}function go(e,t,n){let r=`switch_${++n.value}`;t[r]={mermaidId:r,type:"switch",name:`switch: ${e.expression}`,expression:e.expression,cases:e.cases.map(o=>({value:o.value,isDefault:o.isDefault})),location:e.location};for(let o of e.cases)o.body.length>0&&J(o.body,t,n)}function ho(e,t,n){let r=`loop_start_${++n.value}`,o=`loop_end_${++n.value}`;t[r]={mermaidId:r,type:"loop-start",name:e.iterSource?`${e.loopType}: ${e.iterSource}`:e.loopType,loopType:e.loopType,iterSource:e.iterSource,boundCount:e.boundCount,location:e.location},J(e.body,t,n),t[o]={mermaidId:o,type:"loop-end",name:"Continue?"}}function yo(e,t,n){let r=`workflow_ref_${++n.value}`;t[r]={mermaidId:r,type:"workflow-ref",name:e.workflowName,workflowName:e.workflowName,resolved:e.resolved,location:e.location}}function So(e,t,n){let r=`unknown_${++n.value}`;t[r]={mermaidId:r,type:"unknown",name:`Unknown: ${e.reason}`,location:e.location}}import{mkdirSync as wo,writeFileSync as No}from"fs";import{join as Je,isAbsolute as ko}from"path";var bo=".awaitly",xo="dsl",Ht=".awaitly";function Io(e){let t=e.rootDir??process.cwd();return e.outputDir?ko(e.outputDir)?e.outputDir:Je(t,e.outputDir):Je(t,bo,xo)}function Gt(e,t={}){let{filename:n,pretty:r=!0}=t,o=To(e.workflowName),s=n??`${o}.dsl.json`,i=Io(t);wo(i,{recursive:!0});let a=Je(i,s),l=r?JSON.stringify(e,null,2):JSON.stringify(e);return No(a,l,"utf-8"),a}function To(e){return e.replace(/[^a-zA-Z0-9_-]/g,"_")}function Jt(e){let t=[],n=0;function r(o,s){if(o.type==="step"){let i=o;t.push({stepId:i.stepId,callee:i.callee,containerType:s,index:n++});return}if(o.type==="saga-step"){let i=o;t.push({stepId:i.name??i.id,callee:i.callee,containerType:s,index:n++});return}for(let i of $(o))r(i,o.type)}for(let o of e.root.children)r(o,"workflow");return t}var Co=["parallel","race","conditional","decision","switch","loop","stream","sequence"];function Zt(e){let t=new Map;function n(r){Co.includes(r.type)&&t.set(r.type,(t.get(r.type)??0)+1);for(let o of $(r))n(o)}for(let r of e.root.children)n(r);return t}function Ze(e,t,n){let r=n?.detectRenames??!0,o=n?.regressionMode??!1,s=Jt(e),i=Jt(t),a=new Map;for(let S of s)a.set(S.stepId,S);let l=new Map;for(let S of i)l.set(S.stepId,S);let c=[],u=new Set,d=new Set;for(let[S,b]of a){let g=l.get(S);g&&(u.add(S),d.add(S),b.containerType!==g.containerType?c.push({kind:"moved",stepId:S,callee:g.callee,containerBefore:b.containerType,containerAfter:g.containerType}):c.push({kind:"unchanged",stepId:S,callee:g.callee}))}if(r){let S=s.filter(g=>!u.has(g.stepId)),b=i.filter(g=>!d.has(g.stepId));for(let g of S){if(u.has(g.stepId))continue;let y=b.find(k=>!d.has(k.stepId)&&k.callee!==void 0&&g.callee!==void 0&&k.callee===g.callee&&k.index===g.index);y&&(u.add(g.stepId),d.add(y.stepId),c.push({kind:"renamed",stepId:y.stepId,previousStepId:g.stepId,callee:y.callee}))}}for(let S of s)u.has(S.stepId)||c.push({kind:"removed",stepId:S.stepId,callee:S.callee});for(let S of i)d.has(S.stepId)||c.push({kind:"added",stepId:S.stepId,callee:S.callee});let p=Zt(e),f=Zt(t),m=new Set([...p.keys(),...f.keys()]),h=[];for(let S of m){let b=p.get(S)??0,g=f.get(S)??0;if(g>b){let y=g-b;h.push({kind:"added",nodeType:S,description:`${y} ${S} block${y>1?"s":""}`})}else if(b>g){let y=b-g;h.push({kind:"removed",nodeType:S,description:`${y} ${S} block${y>1?"s":""}`})}}let w={stepsAdded:c.filter(S=>S.kind==="added").length,stepsRemoved:c.filter(S=>S.kind==="removed").length,stepsRenamed:c.filter(S=>S.kind==="renamed").length,stepsMoved:c.filter(S=>S.kind==="moved").length,stepsUnchanged:c.filter(S=>S.kind==="unchanged").length,structuralChanges:h.length,hasRegressions:o&&c.some(S=>S.kind==="removed")};return{beforeName:e.root.workflowName,afterName:t.root.workflowName,diffedAt:Date.now(),steps:c,structuralChanges:h,summary:w}}function Qe(e,t){let n=t?.showUnchanged??!0,r=t?.title??`Workflow Diff: ${e.beforeName} \u2192 ${e.afterName}`,o=[];o.push(`# ${r}`),o.push(""),o.push("## Summary"),o.push(`- ${e.summary.stepsAdded} added, ${e.summary.stepsRemoved} removed, ${e.summary.stepsRenamed} renamed, ${e.summary.stepsMoved} moved, ${e.summary.stepsUnchanged} unchanged`),e.summary.structuralChanges>0&&o.push(`- ${e.summary.structuralChanges} structural change${e.summary.structuralChanges!==1?"s":""}`),o.push("");let s=e.steps.filter(c=>c.kind==="added");if(s.length>0){o.push("## Added Steps");for(let c of s)o.push(`- ${Ye(c)}`);o.push("")}let i=e.steps.filter(c=>c.kind==="removed");if(i.length>0){let c=e.summary.hasRegressions?"\u26A0\uFE0F ":"";o.push(`## ${c}Removed Steps`);for(let u of i)o.push(`- ${Ye(u)}`);o.push("")}let a=e.steps.filter(c=>c.kind==="renamed");if(a.length>0){o.push("## Renamed Steps");for(let c of a){let u=c.callee?` (${c.callee})`:"";o.push(`- \`${c.previousStepId}\` \u2192 \`${c.stepId}\`${u}`)}o.push("")}let l=e.steps.filter(c=>c.kind==="moved");if(l.length>0){o.push("## Moved Steps");for(let c of l)o.push(`- \`${c.stepId}\` moved from ${c.containerBefore??"unknown"} \u2192 ${c.containerAfter??"unknown"}`);o.push("")}if(e.structuralChanges.length>0){o.push("## Structural Changes");for(let c of e.structuralChanges){let u=c.kind==="added"?"Added":"Removed";o.push(`- ${u}: ${c.description}`)}o.push("")}if(n){let c=e.steps.filter(u=>u.kind==="unchanged");if(c.length>0){o.push("## Unchanged Steps");for(let u of c)o.push(`- ${Ye(u)}`);o.push("")}}return o.join(`
|
|
28
29
|
`).trimEnd()+`
|
|
29
|
-
`}function
|
|
30
|
-
`),
|
|
31
|
-
`)}function
|
|
32
|
-
Done((Success))`;let
|
|
33
|
-
`)}function
|
|
30
|
+
`}function Ye(e){let t=e.callee?` (${e.callee})`:"";return`\`${e.stepId}\`${t}`}function Xe(e,t){return t?.pretty??!0?JSON.stringify(e,null,2):JSON.stringify(e)}var Yt=["classDef diffAddedStyle fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px","classDef diffRemovedStyle fill:#ffcdd2,stroke:#c62828,stroke-width:2px,stroke-dasharray:5","classDef diffRenamedStyle fill:#fff3e0,stroke:#e65100,stroke-width:2px","classDef diffMovedStyle fill:#e3f2fd,stroke:#1565c0,stroke-width:2px"];function et(e,t,n){let r=n?.showRemovedSteps??!0,s=de(e,{direction:n?.direction}).split(`
|
|
31
|
+
`),i=Ro(s),a=[];for(let d of t.steps){if(d.kind==="unchanged"||d.kind==="removed")continue;let p=i.get(d.stepId);if(!p)continue;let f=Eo(d.kind);f&&a.push(` class ${p} ${f}`)}let l=[];if(r){let d=t.steps.filter(p=>p.kind==="removed");for(let p=0;p<d.length;p++){let f=d[p],m=`removed_${p+1}`;l.push(` ${m}["\u274C ${f.stepId}"]`),a.push(` class ${m} diffRemovedStyle`)}}let c=s.findIndex(d=>d.trim()==="%% Styles"),u=[];for(let d=0;d<s.length;d++){if(d===c){u.push(""),u.push(" %% Diff Styles");for(let p of Yt)u.push(` ${p}`);u.push("")}u.push(s[d])}if(c===-1){u.push(""),u.push(" %% Diff Styles");for(let d of Yt)u.push(` ${d}`)}if(l.length>0){u.push(""),u.push(" %% Removed Steps (ghost nodes)");for(let d of l)u.push(d)}if(a.length>0){u.push(""),u.push(" %% Diff class assignments");for(let d of a)u.push(d)}return u.join(`
|
|
32
|
+
`)}function Ro(e){let t=new Map,n=/^\s+((?:saga_)?step_\d+)\["([^"]*)"\]/;for(let r of e){let o=r.match(n);if(!o)continue;let[,s,i]=o,a=i.indexOf(":"),l=i.indexOf(" ("),c=i.indexOf("\\"),u=i.length;a!==-1&&a<u&&(u=a),l!==-1&&l<u&&(u=l),c!==-1&&c<u&&(u=c);let d=i.substring(0,u).trim();d&&t.set(d,s)}return t}function Eo(e){switch(e){case"added":return"diffAddedStyle";case"renamed":return"diffRenamedStyle";case"moved":return"diffMovedStyle";default:return null}}import{execSync as Ae}from"child_process";function Le(e){let t=e.match(/^gh:#(\d+)$/);if(t)return{type:"github",prNumber:parseInt(t[1],10)};let n=e.indexOf(":");return n>0?{type:"git",ref:e.slice(0,n),path:e.slice(n+1)}:{type:"local",path:e}}function Qt(e,t){let n;try{n=Ae(`gh pr view ${e} --json baseRefName,headRefName,files`,{encoding:"utf-8"})}catch(i){let a=i instanceof Error?i.message:String(i);throw a.includes("command not found")||a.includes("ENOENT")?new Error("GitHub PR diff requires the GitHub CLI (gh). Install: https://cli.github.com",{cause:i}):a.includes("authentication")||a.includes("auth login")?new Error("GitHub CLI not authenticated. Run: gh auth login",{cause:i}):a.includes("Could not resolve")||a.includes("not found")?new Error(`PR #${e} not found. Check the number and repo.`,{cause:i}):new Error(`Failed to fetch PR #${e}: ${a}`,{cause:i})}let r=JSON.parse(n),o=r.files;if(t&&(o=o.filter(i=>i.path===t),o.length===0))throw new Error(`File '${t}' not found in PR #${e}.`);o=o.filter(i=>i.path.endsWith(".ts")||i.path.endsWith(".tsx"));let s=[];for(let i of o)try{let a=Ae(`git show ${r.baseRefName}:${i.path}`,{encoding:"utf-8"}),l=Ae(`git show ${r.headRefName}:${i.path}`,{encoding:"utf-8"});s.push({path:i.path,before:a,after:l})}catch{continue}return s}function Xt(e,t){try{return Ae(`git show ${e}:${t}`,{encoding:"utf-8"})}catch(n){let r=n instanceof Error?n.message:String(n);throw r.includes("does not exist")?new Error(`File '${t}' not found at ref '${e}'.`,{cause:n}):r.includes("invalid object name")||r.includes("unknown revision")?new Error(`Git ref '${e}' not found.`,{cause:n}):r.includes("not a git repository")?new Error("Git ref diff requires a git repository. Run from within a repo.",{cause:n}):new Error(`Failed to read '${e}:${t}': ${r}`,{cause:n})}}function tt(e,t){let n=t?.direction??"LR",r=t?.stepLabel??"callee",o=t?.showRetry??!1,s=t?.showTimeout??!1,i=t?.showKeys??!1,a=t?.useNodeIds??!1,l=t?.styles,c=t?.includeInferredErrors!==!1,u=en(e.root.children);if(u.length===0)return`flowchart ${n}
|
|
33
|
+
Done((Success))`;let d=new Map,p=0,f=u.map(y=>{let k=Ao(y,r,o,s,i),x;a?(p++,x=`${y.type==="saga-step"?"saga_step":"step"}_${p}`):x=Po(k,d);let R=Lo(y,c);return{node:y,label:k,shortId:x,errors:R}}),m=[];m.push(`flowchart ${n}`);for(let y=0;y<f.length;y++){let k=f[y],x=f[y+1];x?m.push(` ${k.shortId}["${Pe(k.label)}"] -->|ok| ${x.shortId}["${Pe(x.label)}"]`):m.push(` ${k.shortId}["${Pe(k.label)}"] -->|ok| Done((Success))`)}for(let y of f){if(y.errors.length===0)continue;let k=y.errors.join(" / "),x=`${y.shortId}E`;m.push(` ${y.shortId} -->|err| ${x}["${Pe(k)}"]`)}let h=l?.step??"fill:#e1f5fe,stroke:#01579b",w=l?.error??"fill:#ffcdd2,stroke:#c62828",S=l?.success??"fill:#c8e6c9,stroke:#2e7d32";m.push(""),m.push(` classDef stepStyle ${h}`),m.push(` classDef errorStyle ${w}`),m.push(` classDef successStyle ${S}`);let b=f.map(y=>y.shortId).join(",");m.push(` class ${b} stepStyle`);let g=f.filter(y=>y.errors.length>0).map(y=>`${y.shortId}E`);return g.length>0&&m.push(` class ${g.join(",")} errorStyle`),m.push(" class Done successStyle"),m.join(`
|
|
34
|
+
`)}function en(e){let t=[];for(let n of e){(n.type==="step"||n.type==="saga-step")&&t.push(n);let r=$(n);r.length>0&&t.push(...en(r))}return t}function Ao(e,t,n,r,o){let s;switch(t){case"stepId":s=e.type==="step"?e.stepId??e.name??e.id:e.name??e.id;break;case"description":s=e.description??(e.callee?E(e.callee):null)??e.name??e.id;break;default:s=(e.callee?E(e.callee):null)??e.name??e.id;break}if(o&&e.key&&(s+=` [${e.key}]`),e.type==="step"){let i=e,a=[];n&&i.retry&&a.push(`retry:${i.retry.attempts}`),r&&i.timeout&&a.push(`timeout:${i.timeout.ms}ms`),a.length>0&&(s+=` (${a.join(", ")})`)}return s}function Lo(e,t){if(e.type==="step"){let n=e;return!t&&n.errorsSource==="inferred"?[]:n.errors??[]}return[]}function Po(e,t){let n=e.replace(/([a-z])([A-Z])/g,"$1 $2").split(/[\s\-_]+/).filter(Boolean),r;n.length>=2?r=n.map(s=>s[0].toUpperCase()).join(""):n.length===1?r=n[0][0].toUpperCase():r="N";let o=t.get(r)??0;return t.set(r,o+1),o===0?r:`${r}${o+1}`}function Pe(e){return e.replace(/\\n/g," ").replace(/\r?\n/g," ").replace(/"/g,"'").replace(/\[/g,"(").replace(/]/g,")")}function tn(e){let t=e.root.children,n=$o(t),r=Do(t),o=Wo(t),s=Fo(t),i=vo(t),a=Oo(t);return{cyclomaticComplexity:n,cognitiveComplexity:r,pathCount:o,maxDepth:s,maxParallelBreadth:i,decisionPoints:a}}function $o(e){let t=1;for(let n of e)t+=z(n);return t}function z(e){let t=0;switch(e.type){case"conditional":case"decision":t+=1;for(let n of e.consequent)t+=z(n);if(e.alternate)for(let n of e.alternate)t+=z(n);break;case"switch":t+=e.cases.length;for(let n of e.cases)for(let r of n.body)t+=z(r);break;case"race":t+=Math.max(0,e.children.length-1);for(let n of e.children)t+=z(n);break;case"loop":t+=1;for(let n of e.body)t+=z(n);break;case"sequence":case"parallel":for(let n of e.children)t+=z(n);break;case"workflow-ref":if(e.inlinedIR)for(let n of e.inlinedIR.root.children)t+=z(n);break;case"step":case"saga-step":case"stream":case"unknown":break}return t}function Do(e){return oe(e,0)}function oe(e,t){let n=0;for(let r of e)n+=$e(r,t);return n}function $e(e,t){let n=0;switch(e.type){case"conditional":case"decision":n+=1+t,n+=oe(e.consequent,t+1),e.alternate&&(n+=1,n+=oe(e.alternate,t+1));break;case"switch":n+=1+t;for(let r of e.cases)n+=oe(r.body,t+1);break;case"loop":n+=1+t,n+=oe(e.body,t+1);break;case"race":n+=e.children.length;for(let r of e.children)n+=$e(r,t+1);break;case"parallel":n+=Math.max(0,e.children.length-1);for(let r of e.children)n+=$e(r,t);break;case"sequence":for(let r of e.children)n+=$e(r,t);break;case"workflow-ref":n+=1,e.inlinedIR&&(n+=oe(e.inlinedIR.root.children,t+1));break;case"step":case"saga-step":case"stream":case"unknown":break}return n}function Wo(e){let t=1,n=!1;for(let r of e){let o=De(r);o==="unbounded"?n=!0:t*=o}return n?"unbounded":t}function De(e){switch(e.type){case"conditional":case"decision":{let t=me(e.consequent),n=e.alternate?me(e.alternate):1;return t==="unbounded"||n==="unbounded"?"unbounded":t+n}case"switch":{let t=0;for(let n of e.cases){let r=me(n.body);if(r==="unbounded")return"unbounded";t+=r}return Math.max(1,t)}case"race":{let t=0;for(let n of e.children){let r=De(n);if(r==="unbounded")return"unbounded";t+=r}return Math.max(1,t)}case"parallel":{let t=1;for(let n of e.children){let r=De(n);if(r==="unbounded")return"unbounded";t*=r}return t}case"loop":return"unbounded";case"sequence":return me(e.children);case"workflow-ref":return e.inlinedIR?me(e.inlinedIR.root.children):1;case"step":case"saga-step":case"stream":case"unknown":return 1}}function me(e){let t=1;for(let n of e){let r=De(n);if(r==="unbounded")return"unbounded";t*=r}return t}function Fo(e){let t=0;for(let n of e)t=Math.max(t,Z(n,0));return t}function Z(e,t){let n=t;switch(e.type){case"conditional":case"decision":for(let r of e.consequent)n=Math.max(n,Z(r,t+1));if(e.alternate)for(let r of e.alternate)n=Math.max(n,Z(r,t+1));break;case"switch":for(let r of e.cases)for(let o of r.body)n=Math.max(n,Z(o,t+1));break;case"loop":for(let r of e.body)n=Math.max(n,Z(r,t+1));break;case"parallel":case"race":for(let r of e.children)n=Math.max(n,Z(r,t+1));break;case"sequence":for(let r of e.children)n=Math.max(n,Z(r,t));break;case"workflow-ref":if(e.inlinedIR)for(let r of e.inlinedIR.root.children)n=Math.max(n,Z(r,t+1));break;case"step":case"saga-step":case"stream":case"unknown":break}return n}function vo(e){let t=0;for(let n of e)t=Math.max(t,j(n));return t}function j(e){let t=0;switch(e.type){case"parallel":t=e.children.length;for(let n of e.children)t=Math.max(t,j(n));break;case"race":t=e.children.length;for(let n of e.children)t=Math.max(t,j(n));break;case"conditional":case"decision":for(let n of e.consequent)t=Math.max(t,j(n));if(e.alternate)for(let n of e.alternate)t=Math.max(t,j(n));break;case"switch":for(let n of e.cases)for(let r of n.body)t=Math.max(t,j(r));break;case"loop":for(let n of e.body)t=Math.max(t,j(n));break;case"sequence":for(let n of e.children)t=Math.max(t,j(n));break;case"workflow-ref":if(e.inlinedIR)for(let n of e.inlinedIR.root.children)t=Math.max(t,j(n));break;case"step":case"saga-step":case"stream":case"unknown":break}return t}function Oo(e){let t=0;for(let n of e)t+=z(n);return t}function nn(e){let t=e.root.children;if(_(t,"parallel")||_(t,"race")||_(t,"switch")||_(t,"loop")||_(t,"conditional")||_(t,"decision"))return"mermaid";if(_(t,"saga-step"))return"railway";let n=tn(e);return n.cyclomaticComplexity<=3&&n.decisionPoints<=1&&n.maxDepth<=2?"railway":"mermaid"}function _(e,t){for(let n of e){if(n.type===t||n.type==="workflow-ref"&&n.inlinedIR&&_(n.inlinedIR.root.children,t))return!0;let r=$(n);if(r.length>0&&_(r,t))return!0}return!1}import{watch as Mo}from"fs";function rn(e){let{filePath:t,debounceMs:n=300,onRebuild:r,onError:o}=e,s=null,i=null;i=Mo(t,c=>{c!=="change"&&c!=="rename"||(s&&clearTimeout(s),s=setTimeout(()=>{s=null;try{r()}catch(u){o(u instanceof Error?u:new Error(String(u)))}},n))});function a(){s&&(clearTimeout(s),s=null),i&&(i.close(),i=null),process.removeListener("SIGINT",l),process.removeListener("SIGTERM",l)}function l(){a(),process.exit(0)}return process.on("SIGINT",l),process.on("SIGTERM",l),{stop:a}}function on(){console.log(`
|
|
34
35
|
awaitly-analyze - Static workflow analysis tool
|
|
35
36
|
|
|
36
37
|
Usage:
|
|
@@ -59,6 +60,10 @@ Options:
|
|
|
59
60
|
--regression Flag removed steps as regressions (use with --diff)
|
|
60
61
|
--railway Generate railway-style flow diagram (LR or TD with ok/err branches)
|
|
61
62
|
--watch Watch source file and re-analyze on changes
|
|
63
|
+
--types / --no-types Generate TypeScript types file (default: on)
|
|
64
|
+
--test / --no-test Generate test stubs (default: off)
|
|
65
|
+
--test-runner=<runner> Test runner: vitest (default), jest, or mocha
|
|
66
|
+
--errors / --no-errors Show error nodes in diagrams (default: on)
|
|
62
67
|
--help, -h Show this help message
|
|
63
68
|
|
|
64
69
|
Auto-detection:
|
|
@@ -81,11 +86,15 @@ Examples:
|
|
|
81
86
|
awaitly-analyze --diff v1.ts v2.ts
|
|
82
87
|
awaitly-analyze --diff v1.ts v2.ts --format=json
|
|
83
88
|
awaitly-analyze --diff v1.ts v2.ts --format=mermaid --regression
|
|
84
|
-
`)}function
|
|
89
|
+
`)}function jo(e){let t={filePath:"",format:"mermaid",showKeys:!1,direction:"TB",help:!1,outputAdjacent:!1,suffix:"workflow",noStdout:!1,dslOutput:"off",html:!1,htmlOutput:"",diff:!1,diffSources:[],regressionMode:!1,formatExplicit:!1,directionExplicit:!1,railway:!1,auto:!0,watch:!1,types:!0,test:!1,testRunner:"vitest",errors:!0};for(let n of e)if(n==="--help"||n==="-h")t.help=!0;else if(n==="--html")t.html=!0;else if(n.startsWith("--html-output=")){let r=n.slice(14).trim();r.length===0&&(console.error("Error: --html-output requires a non-empty path."),process.exit(1)),t.htmlOutput=r,t.html=!0}else if(n==="--keys")t.showKeys=!0;else if(n==="--output-adjacent"||n==="-o")t.outputAdjacent=!0;else if(n==="--no-stdout")t.noStdout=!0;else if(n==="--write-dsl")t.dslOutput=Ht;else if(n.startsWith("--dsl-output=")){let r=n.slice(13).trim();r==="off"||r===".awaitly"||r.length>0?t.dslOutput=r:(console.error("Error: --dsl-output requires a value (off, .awaitly, or a path)."),process.exit(1))}else if(n.startsWith("--format=")){let r=n.slice(9).toLowerCase();r==="json"||r==="mermaid"||r==="markdown"?(t.format=r,t.formatExplicit=!0):(console.error(`Unknown format: ${r}. Use 'mermaid', 'json', or 'markdown'.`),process.exit(1))}else if(n.startsWith("--direction=")){let r=n.slice(12).toUpperCase();["TB","TD","LR","BT","RL"].includes(r)?(t.direction=r,t.directionExplicit=!0):(console.error(`Unknown direction: ${r}. Use TB, TD, LR, BT, or RL.`),process.exit(1))}else if(n.startsWith("--suffix=")){let r=n.slice(9);(r.includes("/")||r.includes("\\"))&&(console.error("Error: suffix cannot contain path separators."),process.exit(1)),t.suffix=r}else if(n==="--diff")t.diff=!0;else if(n==="--railway")t.railway=!0;else if(n==="--regression")t.regressionMode=!0;else if(n==="--watch")t.watch=!0;else if(n==="--types"||n==="--no-types")t.types=n==="--types";else if(n==="--test"||n==="--no-test")t.test=n==="--test";else if(n.startsWith("--test-runner=")){let r=n.slice(14).trim();r==="vitest"||r==="jest"||r==="mocha"?t.testRunner=r:(console.error(`Unknown test runner: ${r}. Use vitest, jest, or mocha.`),process.exit(1))}else n==="--errors"||n==="--no-errors"?t.errors=n==="--errors":n.startsWith("-")?(console.error(`Unknown option: ${n}`),process.exit(1)):t.diff?t.diffSources.push(n):t.filePath||(t.filePath=n);return t.auto=!t.railway&&!t.formatExplicit,t}function zo(e,t,n){let r=Fe(e),o=cn(e),s=ln(e,o);return ve(r,`${s}.${t}${n==="json"?".json":".md"}`)}function _o(){let e=process.argv.slice(2),t=jo(e);if(t.help&&(on(),process.exit(0)),t.diff){let a=function(p){let f=Le(p);if(f.type==="local")return Te(nt(f.path)).firstOrNull();if(f.type==="git"){let m=Xt(f.ref,f.path);return ne(m)[0]??null}return null};var r=a;t.railway&&(console.error("Error: --railway is not supported with --diff."),process.exit(1)),t.watch&&(console.error("Error: --watch is not supported with --diff."),process.exit(1));let o=t.diffSources;t.outputAdjacent&&o.some(p=>p.startsWith("gh:#"))&&(console.error("Error: --output-adjacent is not supported with GitHub PR sources."),process.exit(1));let s=t.formatExplicit?t.format:"markdown",i=o.find(p=>p.startsWith("gh:#"));if(i){let p=Le(i);p.type!=="github"&&(console.error("Error: invalid GitHub PR syntax. Use gh:#<number>."),process.exit(1));let f=o.find(w=>!w.startsWith("gh:#")),m;try{m=Qt(p.prNumber,f)}catch(w){console.error(`Error: ${w instanceof Error?w.message:String(w)}`),process.exit(1)}m.length===0&&(console.error(`No awaitly workflow files found in PR #${p.prNumber}.`),process.exit(1));let h=[];for(let w of m){let S=ne(w.before),b=ne(w.after),g=S[0]??null,y=b[0]??null;if(!g&&!y||!g||!y)continue;let k=Ze(g,y,{regressionMode:t.regressionMode});s==="json"?h.push(Xe(k)):s==="mermaid"?h.push(et(y,k,{direction:t.direction})):h.push(Qe(k,{showUnchanged:!0}))}h.length===0&&(console.error(`No awaitly workflow files found in PR #${p.prNumber}.`),process.exit(1)),console.log(h.join(`
|
|
85
90
|
|
|
86
91
|
---
|
|
87
92
|
|
|
88
|
-
`));return}if(o.length===1){let p=
|
|
89
|
-
`),
|
|
90
|
-
`)}
|
|
91
|
-
`)}if(e.dslOutput!=="off"){let o=process.cwd(),
|
|
93
|
+
`));return}if(o.length===1){let p=Le(o[0]);p.type==="local"?o.unshift(`HEAD:${p.path}`):(console.error("Error: --diff with a single argument requires a local file path."),process.exit(1))}o.length!==2&&(console.error("Error: --diff requires one file (HEAD vs working copy), two sources, or gh:#<number>."),process.exit(1));let l,c;try{l=a(o[0]),c=a(o[1])}catch(p){console.error(`Error: ${p instanceof Error?p.message:String(p)}`),process.exit(1)}(!l||!c)&&(console.error("Error: Both sources must contain at least one workflow."),process.exit(1));let u=Ze(l,c,{regressionMode:t.regressionMode}),d;s==="json"?d=Xe(u):s==="mermaid"?d=et(c,u,{direction:t.direction}):d=Qe(u,{showUnchanged:!0}),console.log(d);return}t.filePath||(console.error(`Error: No file path provided.
|
|
94
|
+
`),on(),process.exit(1)),t.noStdout&&!t.outputAdjacent&&!t.html&&(console.error("Error: --no-stdout requires --output-adjacent (-o) or --html."),process.exit(1)),t.format==="markdown"&&!t.diff&&(console.error("Error: markdown format is only supported with --diff. Use 'mermaid' or 'json'."),process.exit(1)),t.railway&&t.format==="json"&&(console.error("Error: --railway cannot be used with --format=json. Railway output is always Mermaid."),process.exit(1)),t.railway&&t.direction!=="LR"&&t.direction!=="TD"&&(t.direction==="TB"&&!t.directionExplicit?t.direction="LR":(console.error(`Error: --railway only supports LR or TD directions, got ${t.direction}.`),process.exit(1)));let n=nt(t.filePath);if(t.watch){let o=()=>{console.clear();let s=new Date().toLocaleTimeString();console.error(`[${s}] Analyzing ${t.filePath}...`),an(t,n),console.error(`[${s}] Watching for changes... (Ctrl+C to exit)`)};o(),rn({filePath:n,onRebuild:o,onError:s=>{let i=new Date().toLocaleTimeString();console.error(`[${i}] Error: ${s.message}`),console.error(`[${i}] Watching for changes...`)}});return}an(t,n)}function sn(e,t){return e.railway?!0:e.format==="json"?!1:e.auto?nn(t)==="railway":!1}function an(e,t){try{let n=Te(t).all();if(n.length===0)throw new Error(`No workflows found in ${e.filePath}`);if(e.html){if(e.htmlOutput&&n.length>1)throw new Error("cannot use --html-output with multiple workflows; each workflow needs its own file.");for(let o of n){let s=sn(e,o),i=s&&!e.directionExplicit?"LR":e.direction,a=s?tt(o,{direction:i==="LR"?"LR":"TD",showKeys:e.showKeys,useNodeIds:!0,includeInferredErrors:e.errors}):de(o,{direction:i,showKeys:e.showKeys,showInlineErrors:e.errors}),l=s?Bt(o):_t(o),c=Kt(a,l,{direction:i==="TD"?"TB":i}),u;if(e.htmlOutput)u=nt(e.htmlOutput);else{let d=Fe(t),p=cn(t),f=ln(t,p),m=n.length>1?`.${o.root.workflowName}`:"";u=ve(d,`${f}${m}.html`)}We(u,c,"utf-8"),console.error(`Wrote HTML: ${u}`)}}let r;if(e.format==="json")r=Mt(n,t,{pretty:!0});else{let o=[];for(let s of n){let i=sn(e,s),a=i&&!e.directionExplicit?"LR":e.direction;if(n.length>1){let l=e.auto?` (auto: ${i?"railway":"mermaid"})`:"";o.push(`## Workflow: ${s.root.workflowName}${l}
|
|
95
|
+
`)}i?o.push(tt(s,{direction:a==="LR"?"LR":"TD",showKeys:e.showKeys,includeInferredErrors:e.errors})):o.push(de(s,{direction:a,showKeys:e.showKeys,showInlineErrors:e.errors})),n.length>1&&o.push("")}r=o.join(`
|
|
96
|
+
`)}if(e.dslOutput!=="off"){let o=process.cwd(),s=e.dslOutput===".awaitly"?{rootDir:o}:{rootDir:o,outputDir:e.dslOutput};for(let i of n){let a=zt(i),l=Gt(a,s);console.error(`Wrote DSL: ${l}`)}}if(e.test)for(let o of n){let s=Ot(o),i=Ft(s),a=vt(i,{testRunner:e.testRunner,workflowName:o.root.workflowName}),l=Fe(t),c=ve(l,`${o.root.workflowName}.test.ts`);We(c,a,"utf-8"),console.error(`Wrote test: ${c}`)}if(e.types)for(let o of n){let s=Bo(o),i=Fe(t),a=ve(i,`${o.root.workflowName}.types.ts`);We(a,s,"utf-8"),console.error(`Wrote types: ${a}`)}if(e.outputAdjacent){let o=zo(t,e.suffix,e.format);We(o,r,"utf-8"),console.error(`Wrote ${o}`)}e.noStdout||console.log(r)}catch(n){n instanceof Error?console.error(`Error: ${n.message}`):console.error("An unknown error occurred"),e.watch||process.exit(1)}}function Bo(e){let t=[],n=e.root.workflowName,r=e.root.dependencies,o=e.root.errorTypes,s=e.root.declaredErrors;t.push(`/**
|
|
97
|
+
* Types for ${n} workflow
|
|
98
|
+
* Generated by awaitly-analyze
|
|
99
|
+
*/`),t.push(""),t.push('import type { AsyncResult } from "awaitly";'),t.push("");let i=r.flatMap(c=>c.signature?.params??[]).filter(Boolean);if(i.length>0){t.push(`export type ${n}Input = {`);for(let c of i)t.push(` ${c.name}: ${c.type??"unknown"},`);t.push("};"),t.push("")}let a=e.root.workflowReturnType??"unknown";t.push(`export type ${n}Output = ${a};`),t.push("");let l=[...new Set([...s??[],...o])];return l.length>0?(t.push(`export type ${n}Error = ${l.map(c=>`'${c}'`).join(" | ")};`),t.push(""),t.push(`export type ${n}Result = AsyncResult<${n}Output, ${n}Error>;`)):(t.push(`export type ${n}Error = never;`),t.push(""),t.push(`export type ${n}Result = AsyncResult<${n}Output, never>;`)),t.join(`
|
|
100
|
+
`)}var qo=process.argv[1]&&(process.argv[1]===__filename||process.argv[1].endsWith("/cli.js")||process.argv[1].endsWith("/cli.ts"));qo&&_o();export{jo as parseArgs};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "awaitly-analyze",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Static workflow analysis for awaitly. Analyze workflow source code to extract structure, types, and generate visualizations.",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"awaitly": "1.
|
|
45
|
-
"awaitly-visualizer": "
|
|
44
|
+
"awaitly": "1.33.0",
|
|
45
|
+
"awaitly-visualizer": "22.0.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"ts-morph": ">=27.0.2",
|
|
@@ -59,13 +59,13 @@
|
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
61
61
|
"@total-typescript/tsconfig": "^1.0.4",
|
|
62
|
-
"@types/node": "^25.
|
|
62
|
+
"@types/node": "^25.6.0",
|
|
63
63
|
"mermaid": "^11.13.0",
|
|
64
64
|
"ts-morph": "^27.0.2",
|
|
65
65
|
"tsup": "^8.5.1",
|
|
66
66
|
"tsx": "^4.21.0",
|
|
67
67
|
"typescript": "^5.9.3",
|
|
68
|
-
"vitest": "^4.1.
|
|
68
|
+
"vitest": "^4.1.5"
|
|
69
69
|
},
|
|
70
70
|
"engines": {
|
|
71
71
|
"node": ">=22"
|