awaitly-analyze 2.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.cjs +7 -5
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +7 -5
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +16 -9
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +16 -9
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +7 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/{json-BmPLmXkF.d.cts → json-D5vAh1AZ.d.cts} +84 -4
- package/dist/{json-BmPLmXkF.d.ts → json-D5vAh1AZ.d.ts} +84 -4
- package/package.json +5 -2
package/dist/browser.cjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var ze=Object.create;var P=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var Re=Object.getPrototypeOf,We=Object.prototype.hasOwnProperty;var Le=(t,e)=>{for(var o in e)P(t,o,{get:e[o],enumerable:!0})},Q=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of $e(e))!We.call(t,a)&&a!==o&&P(t,a,{get:()=>e[a],enumerable:!(n=Ie(e,a))||n.enumerable});return t};var Pe=(t,e,o)=>(o=t!=null?ze(Re(t)):{},Q(e||!t||!t.__esModule?P(o,"default",{value:t,enumerable:!0}):o,t)),ve=t=>Q(P({},"__esModule",{value:!0}),t);var Rt={};Le(Rt,{analyzeWorkflowSource:()=>He,clearTreeSitterBrowserCache:()=>te,getWasmBasePath:()=>Z,renderMultipleStaticJSON:()=>B,renderPathsMermaid:()=>j,renderStaticJSON:()=>q,renderStaticMermaid:()=>x,resetIdCounter:()=>Ve,setWasmBasePath:()=>X});module.exports=ve(Rt);var v="/wasm/";function X(t){v=t.endsWith("/")?t:`${t}/`}function Z(){return v}var W=null;async function Te(){let t=`${v}tree-sitter-typescript.wasm`,e=await fetch(t);if(!e.ok)throw new Error(`Failed to load TypeScript grammar WASM from: ${t}
|
|
2
2
|
HTTP ${e.status}: ${e.statusText}
|
|
3
3
|
|
|
4
|
-
Make sure the WASM file is available at this path. You can configure the path using setWasmBasePath().`);let
|
|
5
|
-
`),f=
|
|
6
|
-
`)}function _(t,e,
|
|
7
|
-
`)}function T(t,e={}){let{pretty:n=!0,includeMetadata:o=!0}=e,r={root:t.root,metadata:o?t.metadata:void 0,references:t.references.size>0?Object.fromEntries(Array.from(t.references.entries()).map(([s,a])=>[s,{root:a.root,metadata:o?a.metadata:void 0}])):void 0};return n?JSON.stringify(r,null,2):JSON.stringify(r)}function x(t,e,n={}){let{pretty:o=!0,includeMetadata:r=!0}=n,s={file:e,analyzedAt:Date.now(),workflowCount:t.length,workflows:t.map(a=>({root:a.root,metadata:r?a.metadata:void 0,references:a.references.size>0?Object.fromEntries(Array.from(a.references.entries()).map(([i,l])=>[i,{root:l.root,metadata:r?l.metadata:void 0}])):void 0}))};return o?JSON.stringify(s,null,2):JSON.stringify(s)}var ke={tsConfigPath:"./tsconfig.json",resolveReferences:!1,maxReferenceDepth:5,includeLocations:!0,detect:"all",assumeImported:!1},Q=0;function be(){Q=0}function p(){return`ts-${++Q}`}async function Ae(t,e={}){let n={...ke,...e},{parser:o}=await K(),r=o.parse(t);if(!r)throw new Error("Failed to parse source code");let s={sourceCode:t,filePath:"<source>",opts:n,warnings:[],stats:j(),workflowNames:new Set};M(r.rootNode,s).forEach(l=>s.workflowNames.add(l.name));let i=[];if(n.detect==="all"||n.detect==="createWorkflow"){let l=_e(r.rootNode,s);for(let d of l){let f=Pe(d,s);f&&i.push(f)}}if(n.detect==="all"||n.detect==="run"){let l=$e(r.rootNode,s);for(let d of l){let f=Oe(d,s);f&&i.push(f)}}return i}function Ie(t,e){let n={};if(t.type!=="object")return n;for(let o of t.namedChildren)if(o.type==="pair"){let r=o.childForFieldName("key"),s=o.childForFieldName("value");if(r&&s){let a=c(r,e);if(a==="description"){let i=C(s,e);i&&(n.description=i)}else if(a==="markdown"){let i=C(s,e);i&&(n.markdown=i)}}}return n}function M(t,e){let n=[];return k(t,o=>{if(o.type==="call_expression"){let r=o.childForFieldName("function");if(r&&c(r,e)==="createWorkflow"){let a=Le(o,e);if(a){let l=o.childForFieldName("arguments")?.namedChildren[1],d=l?Ie(l,e):{};n.push({name:a,createWorkflowCall:o,description:d.description,markdown:d.markdown})}}}}),n}function _e(t,e){let n=M(t,e),o=new Set(n.map(s=>s.name)),r=[];return k(t,s=>{if(s.type==="call_expression"){let a=s.childForFieldName("function");if(a){let i=c(a,e);if(o.has(i)){let l=s.childForFieldName("arguments");if(l){let d=l.namedChildren[0];(d?.type==="arrow_function"||d?.type==="function_expression")&&r.push(s)}}}}}),r}function Re(t,e,n){let o=new Set;return k(t,r=>{if(r.type==="import_statement"){let s=!1;for(let i=0;i<r.childCount;i++){let l=r.children[i];if(l&&l.type==="type"){s=!0;break}}if(s)return;let a=r.childForFieldName("source");if(a){let l=c(a,n).slice(1,-1);if(l==="awaitly"||l.startsWith("@awaitly/")){for(let d of r.namedChildren)if(d.type==="import_clause"){for(let f of d.namedChildren)if(f.type==="named_imports"){for(let m of f.namedChildren)if(m.type==="import_specifier"){let y=!1;for(let N of m.children)if(N.type==="type"){y=!0;break}if(y)continue;let b=m.childForFieldName("name"),S=m.childForFieldName("alias");if(b){let N=c(b,n);if(N===e){let A=S?c(S,n):N;o.add(A)}}}}}}}}}),o}function ze(t,e,n){let o=t.parent;for(;o;){if(o.type==="statement_block"||o.type==="program")for(let r of o.namedChildren){if(r.startIndex>=t.startIndex)break;if(r.type==="lexical_declaration"||r.type==="variable_declaration"){for(let s of r.namedChildren)if(s.type==="variable_declarator"){let a=s.childForFieldName("name");if(a&&c(a,n)===e)return!0}}else if(r.type==="function_declaration"){let s=r.childForFieldName("name");if(s&&c(s,n)===e)return!0}}if(o.type==="arrow_function"||o.type==="function_expression"||o.type==="function_declaration"||o.type==="method_definition"){let r=o.childForFieldName("parameters");if(r)for(let s of r.namedChildren){if(s.type==="identifier"&&c(s,n)===e)return!0;if(s.type==="object_pattern"||s.type==="array_pattern"){let a=!1;if(k(s,i=>{i.type==="identifier"&&c(i,n)===e&&(a=!0)}),a)return!0}if(s.type==="assignment_pattern"){let a=s.childForFieldName("left");if(a?.type==="identifier"&&c(a,n)===e)return!0}}}if(o.type==="program")break;o=o.parent}return!1}function $e(t,e){let n=Re(t,"run",e);if(e.opts.assumeImported&&n.add("run"),n.size===0)return[];let o=[];return k(t,r=>{if(r.type==="call_expression"){let s=r.childForFieldName("function");if(s&&s.type==="identifier"){let a=c(s,e);if(n.has(a)){if(ze(r,a,e))return;let l=r.childForFieldName("arguments")?.namedChildren[0];(l?.type==="arrow_function"||l?.type==="function_expression")&&o.push(r)}}}}),o}function We(t,e){let n=t.startPosition.row+1,o=e.filePath;return`run@${o.includes("/")?o.split("/").pop()||o:o.includes("\\")&&o.split("\\").pop()||o}:${n}`}function Oe(t,e){let o=t.childForFieldName("arguments")?.namedChildren[0],r=[],s=j(),a={...e,warnings:r,stats:s};if(!o||o.type!=="arrow_function"&&o.type!=="function_expression")return r.push({code:"CALLBACK_NOT_FOUND",message:"Could not find callback for run()",location:u(t,a)}),null;let i=We(t,a),l=X(o,a),d=a.stepParameterName;a.stepParameterName=l;let f=Z(o,a);a.stepParameterName=d;let m={id:p(),type:"workflow",workflowName:i,source:"run",dependencies:[],errorTypes:[],children:F(f),location:a.opts.includeLocations?u(t,a):void 0},y={analyzedAt:Date.now(),filePath:a.filePath,warnings:r,stats:s};return{root:m,metadata:y,references:new Map}}function Pe(t,e){let n=t.childForFieldName("function"),o=n?c(n,e):"<unknown>",s=t.childForFieldName("arguments")?.namedChildren[0],a=[],i=j(),l={...e,warnings:a,stats:i};if(!s||s.type!=="arrow_function"&&s.type!=="function_expression")return a.push({code:"CALLBACK_NOT_FOUND",message:`Could not find callback for workflow ${o}`,location:u(t,l)}),null;let d=l.currentWorkflow;l.currentWorkflow=o;let f=X(s,l),m=l.stepParameterName;l.stepParameterName=f;let y=Z(s,l);l.currentWorkflow=d,l.stepParameterName=m;let S=M(t.tree?.rootNode||t,e).find(ae=>ae.name===o),N={id:p(),type:"workflow",workflowName:o,source:"createWorkflow",dependencies:[],errorTypes:[],children:F(y),description:S?.description,markdown:S?.markdown},A={analyzedAt:Date.now(),filePath:l.filePath,warnings:a,stats:i};return{root:N,metadata:A,references:new Map}}function Le(t,e){let n=t;for(;n;){if(n.type==="variable_declarator"){let o=n.childForFieldName("name");if(o)return c(o,e)}n=n.parent}return null}function X(t,e){let n=t.childForFieldName("parameters");if(!n)return;let o=n.namedChildren[0];if(o){if(o.type==="identifier")return c(o,e);if(o.type==="required_parameter"){let r=o.childForFieldName("pattern");if(r)return r.type==="object_pattern"?Y(r,e):c(r,e)}if(o.type==="object_pattern")return Y(o,e)}}function Y(t,e){for(let n of t.namedChildren){if(n.type==="pair_pattern"){let o=n.childForFieldName("key"),r=n.childForFieldName("value");if(o&&r&&c(o,e)==="step"){if(r.type==="assignment_pattern"){let a=r.childForFieldName("left");if(a)return c(a,e)}return c(r,e)}}if(n.type==="shorthand_property_identifier_pattern"&&c(n,e)==="step")return"step";if(n.type==="assignment_pattern"){let o=n.childForFieldName("left");if(o&&c(o,e)==="step")return"step"}}}function Z(t,e){let n=t.childForFieldName("body");return n?n.type==="statement_block"?D(n.namedChildren,e):h(n,e):[]}function D(t,e){let n=[];for(let o of t){let r=ee(o,e);n.push(...r)}return n}function ee(t,e){switch(t.type){case"expression_statement":{let n=t.namedChildren[0];return n?h(n,e):[]}case"variable_declaration":case"lexical_declaration":return Te(t,e);case"return_statement":{let n=t.childForFieldName("value");return n?h(n,e):[]}case"if_statement":return qe(t,e);case"for_statement":return Ve(t,e);case"for_in_statement":return He(t,e);case"while_statement":return Ge(t,e);default:return[]}}function h(t,e){if(t.type==="await_expression"){let n=t.namedChildren[0];return n?h(n,e):[]}if(t.type==="parenthesized_expression"){let n=t.namedChildren[0];return n?h(n,e):[]}return t.type==="call_expression"?E(t,e):[]}function Te(t,e){let n=[];for(let o of t.namedChildren)if(o.type==="variable_declarator"){let r=o.childForFieldName("value");r&&n.push(...h(r,e))}return n}function E(t,e){let n=t.childForFieldName("function");if(!n)return[];let o=c(n,e),r=e.stepParameterName||"step";return o===r?[Me(t,e)]:o===`${r}.retry`?[De(t,e)]:o===`${r}.withTimeout`?[Ee(t,e)]:o===`${r}.parallel`?Be(t,e):o===`${r}.race`?je(t,e):["when","unless","whenOr","unlessOr"].includes(o)?Je(t,o,e):o==="allAsync"||o==="allSettledAsync"?Ue(t,o==="allAsync"?"all":"allSettled",e):o==="anyAsync"?Ke(t,e):xe(t,o,e)?ve(t,o,e):[]}function xe(t,e,n){if(e===n.currentWorkflow)return!1;let r=t.childForFieldName("arguments")?.namedChildren[0];if(!r)return!1;if(r.type==="arrow_function"||r.type==="function_expression"){if(n.workflowNames.has(e))return!0;let s=r.childForFieldName("parameters");if(s){let a=c(s,n);if(a.includes("step")||a.includes("deps"))return!0}}return!1}function ve(t,e,n){return n.stats.workflowRefCount++,[{id:p(),type:"workflow-ref",workflowName:e,resolved:!1,location:n.opts.includeLocations?u(t,n):void 0}]}function B(t,e){if(t.type==="call_expression"){let n=t.childForFieldName("function");if(n)return c(n,e)}if(t.type==="statement_block"){for(let n of t.namedChildren)if(n.type==="return_statement"){let o=n.namedChildren[0];if(o?.type==="call_expression"){let r=o.childForFieldName("function");if(r)return c(r,e)}else if(o)return c(o,e)}}return c(t,e)}function Me(t,e){e.stats.totalSteps++;let n=t.childForFieldName("arguments"),o=n?.namedChildren[0],r=n?.namedChildren[1],s="<unknown>";if(o)if(o.type==="arrow_function"||o.type==="function_expression"){let l=o.childForFieldName("body");l&&(s=B(l,e))}else s=c(o,e);let a=r?$(r,e):{};return{id:p(),type:"step",callee:s,key:a.key,name:a.name,retry:a.retry,timeout:a.timeout,location:e.opts.includeLocations?u(t,e):void 0}}function De(t,e){e.stats.totalSteps++;let o=t.childForFieldName("arguments")?.namedChildren||[],r=o[0],s="<unknown>";if(r)if(r.type==="arrow_function"||r.type==="function_expression"){let d=r.childForFieldName("body");d&&(s=B(d,e))}else s=c(r,e);let a=o[1],i=a?$(a,e):{},l=a?te(a,e):void 0;return{id:p(),type:"step",callee:s,key:i.key,name:i.name,retry:l,timeout:i.timeout,location:e.opts.includeLocations?u(t,e):void 0}}function Ee(t,e){e.stats.totalSteps++;let o=t.childForFieldName("arguments")?.namedChildren||[],r=o[0],s="<unknown>";if(r)if(r.type==="arrow_function"||r.type==="function_expression"){let d=r.childForFieldName("body");d&&(s=B(d,e))}else s=c(r,e);let a=o[1],i=a?$(a,e):{},l=a?ne(a,e):void 0;return{id:p(),type:"step",callee:s,key:i.key,name:i.name,retry:i.retry,timeout:l,location:e.opts.includeLocations?u(t,e):void 0}}function $(t,e){let n={};if(t.type!=="object")return n;for(let o of t.namedChildren)if(o.type==="pair"){let r=o.childForFieldName("key"),s=o.childForFieldName("value");if(r&&s){let a=c(r,e);if(a==="key"){let i=C(s,e);i&&(n.key=i)}else if(a==="name"){let i=C(s,e);i&&(n.name=i)}else a==="retry"?n.retry=te(s,e):a==="timeout"&&(n.timeout=ne(s,e))}}return n}function te(t,e){let n={};if(t.type!=="object")return n;for(let o of t.namedChildren)if(o.type==="pair"){let r=o.childForFieldName("key"),s=o.childForFieldName("value");if(r&&s){let a=c(r,e);if(a==="attempts"){let i=v(s,e);n.attempts=i}else if(a==="backoff"){let i=C(s,e);i==="fixed"||i==="linear"||i==="exponential"?n.backoff=i:n.backoff="<dynamic>"}else if(a==="baseDelay"){let i=v(s,e);n.baseDelay=i}else a==="retryOn"&&(n.retryOn=c(s,e))}}return n}function ne(t,e){let n={};if(t.type!=="object")return n;for(let o of t.namedChildren)if(o.type==="pair"){let r=o.childForFieldName("key"),s=o.childForFieldName("value");if(r&&s&&c(r,e)==="ms"){let i=v(s,e);n.ms=i}}return n}function v(t,e){let n=c(t,e);if(t.type==="number"){let o=parseFloat(n);return isNaN(o)?"<dynamic>":o}return"<dynamic>"}function Be(t,e){let n=t.childForFieldName("arguments"),o=n?.namedChildren[0];if(!o)return[];if(o.type==="string"||o.type==="identifier"||o.type==="member_expression"){let i=o.type==="string"?C(o,e):c(o,e),l=n?.namedChildren[1];if(l&&(l.type==="arrow_function"||l.type==="function_expression")){let d=W(l,e);if(d.length>0){for(let f of d)f.type==="parallel"&&i&&(f.name=i);return d}}return[]}if(o.type!=="object")return[];e.stats.parallelCount++;let r=[];for(let i of o.namedChildren)if(i.type==="pair"){let l=i.childForFieldName("key"),d=i.childForFieldName("value");if(l&&d){let f=oe(l,d,e);f&&r.push(f)}}let s=n?.namedChildren[1],a=s?$(s,e):{};return[{id:p(),type:"parallel",mode:"all",name:a.name,children:r,callee:"step.parallel",location:e.opts.includeLocations?u(t,e):void 0}]}function oe(t,e,n){n.stats.totalSteps++;let o=c(t,n),r="<unknown>";if(e.type==="arrow_function"||e.type==="function_expression"){let s=e.childForFieldName("body");if(s?.type==="call_expression"){let a=s.childForFieldName("function");a&&(r=c(a,n))}}return{id:p(),type:"step",callee:r,name:o,location:n.opts.includeLocations?u(e,n):void 0}}function je(t,e){e.stats.raceCount++;let o=t.childForFieldName("arguments")?.namedChildren[0];if(!o||o.type!=="object")return[];let r=[];for(let s of o.namedChildren)if(s.type==="pair"){let a=s.childForFieldName("key"),i=s.childForFieldName("value");if(a&&i){let l=oe(a,i,e);l&&r.push(l)}}return[{id:p(),type:"race",children:r,callee:"step.race",location:e.opts.includeLocations?u(t,e):void 0}]}function qe(t,e){e.stats.conditionalCount++;let n=t.childForFieldName("condition"),o=t.childForFieldName("consequence"),r=t.childForFieldName("alternative"),s=n?c(n,e).replace(/^\(|\)$/g,""):"<unknown>",a=o?w(o,e):[],i;if(r)if(r.type==="else_clause"){let l=r.namedChildren[0];l&&(i=w(l,e))}else i=w(r,e);return[{id:p(),type:"conditional",condition:s,helper:null,consequent:a,alternate:i?.length?i:void 0,location:e.opts.includeLocations?u(t,e):void 0}]}function w(t,e){return t.type==="statement_block"?D(t.namedChildren,e):ee(t,e)}function Je(t,e,n){n.stats.conditionalCount++;let r=t.childForFieldName("arguments")?.namedChildren||[],s=r[0],a=s?c(s,n):"<unknown>",i=r[1],l=i?W(i,n):[],d;return(e==="whenOr"||e==="unlessOr")&&r[2]&&(d=c(r[2],n)),[{id:p(),type:"conditional",condition:a,helper:e,consequent:l,defaultValue:d,location:n.opts.includeLocations?u(t,n):void 0}]}function W(t,e){if(t.type==="arrow_function"||t.type==="function_expression"){let n=t.childForFieldName("body");if(n)return n.type==="statement_block"?D(n.namedChildren,e):h(n,e)}return h(t,e)}function Ue(t,e,n){n.stats.parallelCount++;let r=t.childForFieldName("arguments")?.namedChildren[0];if(!r||r.type!=="array")return[];let s=[];for(let a of r.namedChildren)if(a.type==="call_expression"){let i=E(a,n);if(i.length>0)s.push(...F(i));else{let l=re(a,n);l&&s.push(l)}}else{let i=W(a,n);s.push(...F(i))}return[{id:p(),type:"parallel",mode:e,children:s,callee:e==="all"?"allAsync":"allSettledAsync",location:n.opts.includeLocations?u(t,n):void 0}]}function Ke(t,e){e.stats.raceCount++;let o=t.childForFieldName("arguments")?.namedChildren[0];if(!o||o.type!=="array")return[];let r=[];for(let a of o.namedChildren)if(a.type==="call_expression"){let i=E(a,e);if(i.length>0)r.push(...F(i));else{let l=re(a,e);l&&r.push(l)}}else{let i=W(a,e);r.push(...F(i))}return[{id:p(),type:"race",children:r,callee:"anyAsync",location:e.opts.includeLocations?u(t,e):void 0}]}function re(t,e){e.stats.totalSteps++;let n=t.childForFieldName("function"),o=n?c(n,e):"<unknown>",r=o.includes(".")?o.split(".").pop():o;return{id:p(),type:"step",name:r,callee:o,location:e.opts.includeLocations?u(t,e):void 0}}function Ve(t,e){let n=t.childForFieldName("body");if(!n)return[];let o=w(n,e);return o.length===0?[]:(e.stats.loopCount++,[{id:p(),type:"loop",loopType:"for",body:o,boundKnown:!1,location:e.opts.includeLocations?u(t,e):void 0}])}function He(t,e){let n=t.childForFieldName("body");if(!n)return[];let o=w(n,e);if(o.length===0)return[];e.stats.loopCount++;let s=c(t,e).includes(" of "),a=t.childForFieldName("right"),i=a?c(a,e):void 0;return[{id:p(),type:"loop",loopType:s?"for-of":"for-in",iterSource:i,body:o,boundKnown:!1,location:e.opts.includeLocations?u(t,e):void 0}]}function Ge(t,e){let n=t.childForFieldName("body");if(!n)return[];let o=w(n,e);return o.length===0?[]:(e.stats.loopCount++,[{id:p(),type:"loop",loopType:"while",body:o,boundKnown:!1,location:e.opts.includeLocations?u(t,e):void 0}])}function c(t,e){return e.sourceCode.slice(t.startIndex,t.endIndex)}function C(t,e){let n=c(t,e);return t.type==="string"?n.slice(1,-1):t.type==="template_string"?"<dynamic>":n}function u(t,e){return{filePath:e.filePath,line:t.startPosition.row+1,column:t.startPosition.column,endLine:t.endPosition.row+1,endColumn:t.endPosition.column}}function k(t,e){e(t);for(let n of t.namedChildren)k(n,e)}function F(t){return t.length<=1?t:[{id:p(),type:"sequence",children:t}]}function j(){return{totalSteps:0,conditionalCount:0,parallelCount:0,raceCount:0,loopCount:0,workflowRefCount:0,unknownCount:0}}0&&(module.exports={analyzeWorkflowSource,clearTreeSitterBrowserCache,getWasmBasePath,renderMultipleStaticJSON,renderPathsMermaid,renderStaticJSON,renderStaticMermaid,resetIdCounter,setWasmBasePath});
|
|
4
|
+
Make sure the WASM file is available at this path. You can configure the path using setWasmBasePath().`);let o=await e.arrayBuffer();return new Uint8Array(o)}async function ee(){if(W)return W;let{Parser:t,Language:e}=await import("web-tree-sitter");await t.init({locateFile:s=>`${v}${s}`});let o=await Te(),n=await e.load(o),a=new t;return a.setLanguage(n),W={parser:a,language:n},W}function te(){W=null}var ne={direction:"TB",showKeys:!1,showStepDescriptions:!1,includeStepMarkdown:!1,showConditions:!0,useSubgraphs:!0,styles:{step:"fill:#e1f5fe,stroke:#01579b,color:#01579b",parallel:"fill:#e8f5e9,stroke:#1b5e20,color:#1b5e20",race:"fill:#fff3e0,stroke:#e65100,color:#bf360c",conditional:"fill:#fce4ec,stroke:#880e4f,color:#880e4f",loop:"fill:#f3e5f5,stroke:#4a148c,color:#4a148c",workflowRef:"fill:#e0f2f1,stroke:#004d40,color:#004d40",sagaStep:"fill:#fff8e1,stroke:#ff6f00,color:#e65100",sagaCompensation:"fill:#ffebee,stroke:#c62828,color:#b71c1c",start:"fill:#c8e6c9,stroke:#2e7d32,color:#1b5e20",end:"fill:#ffcdd2,stroke:#c62828,color:#b71c1c"},maxMarkdownLines:10,includeMarkdown:!0};function x(t,e={}){let o={...ne,...e},n={opts:o,nodeCounter:0,edges:[],subgraphs:[],styleClasses:new Map},a=[];if(a.push(`flowchart ${o.direction}`),a.push(""),a.push(` %% Workflow: ${t.root.workflowName}`),t.root.description&&a.push(` %% ${t.root.description}`),o.includeMarkdown&&t.root.markdown){a.push(" %%");let d=t.root.markdown.trim().split(`
|
|
5
|
+
`),f=o.maxMarkdownLines,p=d.slice(0,f);for(let m of p)a.push(` %% ${m}`);d.length>f&&a.push(` %% ... (${d.length-f} more lines)`)}a.push("");let s="start";a.push(` ${s}((Start))`);let{firstNodeId:r,lastNodeIds:i}=_(t.root.children,n,a);r&&n.edges.push({from:s,to:r});let l="end_node";a.push(` ${l}((End))`);for(let d of i)n.edges.push({from:d,to:l});for(let d of n.subgraphs){a.push(""),a.push(` subgraph ${d.id}[${d.label}]`);for(let f of d.content)a.push(` ${f}`);a.push(" end")}a.push(""),a.push(" %% Edges");for(let d of n.edges)d.label&&o.showConditions?a.push(` ${d.from} -->|${F(d.label)}| ${d.to}`):a.push(` ${d.from} --> ${d.to}`);a.push(""),a.push(" %% Styles"),a.push(` classDef stepStyle ${o.styles.step}`),a.push(` classDef parallelStyle ${o.styles.parallel}`),a.push(` classDef raceStyle ${o.styles.race}`),a.push(` classDef conditionalStyle ${o.styles.conditional}`),a.push(` classDef loopStyle ${o.styles.loop}`),a.push(` classDef workflowRefStyle ${o.styles.workflowRef}`),a.push(` classDef sagaStepStyle ${o.styles.sagaStep}`),a.push(` classDef sagaCompensationStyle ${o.styles.sagaCompensation}`),a.push(` classDef startStyle ${o.styles.start}`),a.push(` classDef endStyle ${o.styles.end}`),a.push(` class ${s} startStyle`),a.push(` class ${l} endStyle`);for(let[d,f]of n.styleClasses)a.push(` class ${d} ${f}`);return a.join(`
|
|
6
|
+
`)}function _(t,e,o){if(t.length===0)return{firstNodeId:null,lastNodeIds:[]};let n=null,a=[];for(let s of t){let r=E(s,e,o);if(n===null&&r.firstNodeId&&(n=r.firstNodeId),r.firstNodeId)for(let i of a)e.edges.push({from:i,to:r.firstNodeId});a=r.lastNodeIds}return{firstNodeId:n,lastNodeIds:a}}function E(t,e,o){switch(t.type){case"step":return Oe(t,e,o);case"sequence":return De(t,e,o);case"parallel":return Me(t,e,o);case"race":return xe(t,e,o);case"conditional":return Ee(t,e,o);case"switch":return je(t,e,o);case"loop":return qe(t,e,o);case"workflow-ref":return Be(t,e,o);case"saga-step":return Je(t,e,o);case"unknown":return Ke(t,e,o);default:return{firstNodeId:null,lastNodeIds:[]}}}function Oe(t,e,o){let n=`step_${++e.nodeCounter}`,a=t.name??t.callee??"step";if(e.opts.showKeys&&t.key&&(a=`${a}\\n[${t.key}]`),e.opts.showStepDescriptions&&t.description&&(a=`${a}\\n${z(t.description,40)}`),t.retry&&(a+="\\n(retry)"),t.timeout&&(a+="\\n(timeout)"),e.opts.includeStepMarkdown&&t.markdown){let s=t.markdown.trim().split(`
|
|
7
|
+
`),r=e.opts.maxMarkdownLines,i=s.slice(0,r);o.push(` %% Step: ${t.name??t.callee??"step"}`);for(let l of i)o.push(` %% ${l}`);s.length>r&&o.push(` %% ... (${s.length-r} more lines)`)}return o.push(` ${n}[${F(a)}]`),e.styleClasses.set(n,"stepStyle"),{firstNodeId:n,lastNodeIds:[n]}}function De(t,e,o){return _(t.children,e,o)}function Me(t,e,o){let n=`parallel_fork_${++e.nodeCounter}`,a=`parallel_join_${++e.nodeCounter}`,s=t.name?`${t.name} (${t.mode})`:`Parallel (${t.mode})`;o.push(` ${n}{{"${s}"}}`),e.styleClasses.set(n,"parallelStyle"),o.push(` ${a}{{"Join"}}`),e.styleClasses.set(a,"parallelStyle");for(let r=0;r<t.children.length;r++){let i=t.children[r],l=E(i,e,o);l.firstNodeId&&e.edges.push({from:n,to:l.firstNodeId,label:`branch ${r+1}`});for(let d of l.lastNodeIds)e.edges.push({from:d,to:a})}return{firstNodeId:n,lastNodeIds:[a]}}function xe(t,e,o){let n=`race_fork_${++e.nodeCounter}`,a=`race_join_${++e.nodeCounter}`,s=t.name?t.name:"Race";o.push(` ${n}{{{"${s}"}}}`),e.styleClasses.set(n,"raceStyle"),o.push(` ${a}{{{"Winner"}}}`),e.styleClasses.set(a,"raceStyle");for(let r=0;r<t.children.length;r++){let i=t.children[r],l=E(i,e,o);l.firstNodeId&&e.edges.push({from:n,to:l.firstNodeId,label:`racer ${r+1}`});for(let d of l.lastNodeIds)e.edges.push({from:d,to:a})}return{firstNodeId:n,lastNodeIds:[a]}}function Ee(t,e,o){let n=`decision_${++e.nodeCounter}`,a=z(t.condition,30);o.push(` ${n}{${F(a)}}`),e.styleClasses.set(n,"conditionalStyle");let s=[],r=_(t.consequent,e,o);if(r.firstNodeId){let i=t.helper==="unless"||t.helper==="unlessOr"?"false":"true";e.edges.push({from:n,to:r.firstNodeId,label:i}),s.push(...r.lastNodeIds)}if(t.alternate&&t.alternate.length>0){let i=_(t.alternate,e,o);if(i.firstNodeId){let l=t.helper==="unless"||t.helper==="unlessOr"?"true":"false";e.edges.push({from:n,to:i.firstNodeId,label:l}),s.push(...i.lastNodeIds)}}else s.push(n);return{firstNodeId:n,lastNodeIds:s}}function je(t,e,o){let n=`switch_${++e.nodeCounter}`,a=z(t.expression,30);o.push(` ${n}{${F(a)}}`),e.styleClasses.set(n,"conditionalStyle");let s=[];for(let r of t.cases){let i=r.isDefault?"default":r.value||"?";if(r.body.length>0){let l=_(r.body,e,o);l.firstNodeId&&(e.edges.push({from:n,to:l.firstNodeId,label:z(i,20)}),s.push(...l.lastNodeIds))}else s.push(n)}return s.length===0&&s.push(n),{firstNodeId:n,lastNodeIds:s}}function qe(t,e,o){let n=`loop_start_${++e.nodeCounter}`,a=`loop_end_${++e.nodeCounter}`,s=t.iterSource?`${t.loopType}: ${z(t.iterSource,20)}`:t.loopType;o.push(` ${n}([${F(s)}])`),e.styleClasses.set(n,"loopStyle");let r=_(t.body,e,o);r.firstNodeId&&e.edges.push({from:n,to:r.firstNodeId,label:"iterate"}),o.push(` ${a}([Continue?])`),e.styleClasses.set(a,"loopStyle");for(let i of r.lastNodeIds)e.edges.push({from:i,to:a});return e.edges.push({from:a,to:n,label:"next"}),{firstNodeId:n,lastNodeIds:[a]}}function Be(t,e,o){let n=`workflow_ref_${++e.nodeCounter}`,a=`[[${t.workflowName}]]`;return o.push(` ${n}${a}`),e.styleClasses.set(n,"workflowRefStyle"),{firstNodeId:n,lastNodeIds:[n]}}function Je(t,e,o){let n=`saga_step_${++e.nodeCounter}`,a=t.name??t.callee??"saga step";if(e.opts.showKeys&&t.key&&(a=`${a}\\n[${t.key}]`),e.opts.showStepDescriptions&&t.description&&(a=`${a}\\n${z(t.description,40)}`),t.hasCompensation){let r=t.compensationCallee?`\u{1F504} ${t.compensationCallee}`:"\u{1F504} compensated";a=`${a}\\n${r}`}if(t.isTryStep&&(a=`${a}\\n(try)`),e.opts.includeStepMarkdown&&t.markdown){let r=t.markdown.trim().split(`
|
|
8
|
+
`),i=e.opts.maxMarkdownLines,l=r.slice(0,i);o.push(` %% Saga Step: ${t.name??t.callee??"saga step"}`);for(let d of l)o.push(` %% ${d}`);r.length>i&&o.push(` %% ... (${r.length-i} more lines)`)}o.push(` ${n}[${F(a)}]`);let s=t.hasCompensation?"sagaCompensationStyle":"sagaStepStyle";return e.styleClasses.set(n,s),{firstNodeId:n,lastNodeIds:[n]}}function Ke(t,e,o){let n=`unknown_${++e.nodeCounter}`;return o.push(` ${n}[/"Unknown: ${F(t.reason)}"/]`),{firstNodeId:n,lastNodeIds:[n]}}function F(t){return t.replace(/"/g,"'").replace(/\[/g,"(").replace(/\]/g,")").replace(/\{/g,"(").replace(/\}/g,")").replace(/</g,"<").replace(/>/g,">")}function z(t,e){return t.length<=e?t:t.slice(0,e-3)+"..."}function j(t,e={}){let o={...ne,...e},n=[];n.push(`flowchart ${o.direction}`),n.push("");let a=new Map,s=0;for(let i of t)for(let l of i.steps)a.has(l.nodeId)||a.set(l.nodeId,{id:`step_${++s}`,label:l.name??l.nodeId});n.push(" start((Start))"),n.push(" end_node((End))"),n.push("");for(let[,{id:i,label:l}]of a)n.push(` ${i}[${F(l)}]`);n.push("");let r=new Set;for(let i of t){if(i.steps.length===0)continue;let l=i.steps[0],d=a.get(l.nodeId).id;r.add(`start --> ${d}`);for(let m=0;m<i.steps.length-1;m++){let N=i.steps[m],S=i.steps[m+1],h=a.get(N.nodeId).id,C=a.get(S.nodeId).id;r.add(`${h} --> ${C}`)}let f=i.steps[i.steps.length-1],p=a.get(f.nodeId).id;r.add(`${p} --> end_node`)}n.push(" %% Edges");for(let i of r)n.push(` ${i}`);return n.join(`
|
|
9
|
+
`)}function q(t,e={}){let{pretty:o=!0,includeMetadata:n=!0}=e,a={root:t.root,metadata:n?t.metadata:void 0,references:t.references.size>0?Object.fromEntries(Array.from(t.references.entries()).map(([s,r])=>[s,{root:r.root,metadata:n?r.metadata:void 0}])):void 0};return o?JSON.stringify(a,null,2):JSON.stringify(a)}function B(t,e,o={}){let{pretty:n=!0,includeMetadata:a=!0}=o,s={file:e,analyzedAt:Date.now(),workflowCount:t.length,workflows:t.map(r=>({root:r.root,metadata:a?r.metadata:void 0,references:r.references.size>0?Object.fromEntries(Array.from(r.references.entries()).map(([i,l])=>[i,{root:l.root,metadata:a?l.metadata:void 0}])):void 0}))};return n?JSON.stringify(s,null,2):JSON.stringify(s)}var Ue={tsConfigPath:"./tsconfig.json",resolveReferences:!1,maxReferenceDepth:5,includeLocations:!0,detect:"all",assumeImported:!1},ie=0;function Ve(){ie=0}function y(){return`ts-${++ie}`}async function He(t,e={}){let o={...Ue,...e},{parser:n}=await ee(),a=n.parse(t);if(!a)throw new Error("Failed to parse source code");let s={sourceCode:t,filePath:"<source>",opts:o,warnings:[],stats:L(),workflowNames:new Set};K(a.rootNode,s).forEach(l=>s.workflowNames.add(l.name));let i=[];if(o.detect==="all"||o.detect==="createWorkflow"){let l=Ge(a.rootNode,s);for(let d of l){let f=dt(d,s);f&&i.push(f)}}if(o.detect==="all"||o.detect==="run"){let l=Ye(a.rootNode,s);for(let d of l){let f=lt(d,s);f&&i.push(f)}}if(o.detect==="all"||o.detect==="createSagaWorkflow"){U(a.rootNode,s).forEach(f=>s.workflowNames.add(f.name));let d=Qe(a.rootNode,s);for(let f of d){let p=Ze(f,s);p&&i.push(p)}}if(o.detect==="all"||o.detect==="runSaga"){let l=Xe(a.rootNode,s);for(let d of l){let f=et(d,s);f&&i.push(f)}}return i}function le(t,e){let o={};if(t.type!=="object")return o;for(let n of t.namedChildren)if(n.type==="pair"){let a=n.childForFieldName("key"),s=n.childForFieldName("value");if(a&&s){let r=c(a,e);if(r==="description"){let i=g(s,e);i&&(o.description=i)}else if(r==="markdown"){let i=g(s,e);i&&(o.markdown=i)}}}return o}function K(t,e){let o=[];return w(t,n=>{if(n.type==="call_expression"){let a=n.childForFieldName("function");if(a&&c(a,e)==="createWorkflow"){let r=me(n,e);if(r){let l=n.childForFieldName("arguments")?.namedChildren[1],d=l?le(l,e):{};o.push({name:r,createWorkflowCall:n,description:d.description,markdown:d.markdown})}}}}),o}function Ge(t,e){let o=K(t,e),n=new Set(o.map(s=>s.name)),a=[];return w(t,s=>{if(s.type==="call_expression"){let r=s.childForFieldName("function");if(r){let i=c(r,e);if(n.has(i)){let l=s.childForFieldName("arguments");if(l){let d=l.namedChildren[0];(d?.type==="arrow_function"||d?.type==="function_expression")&&a.push(s)}}}}}),a}function de(t,e,o){let n=new Set;return w(t,a=>{if(a.type==="import_statement"){let s=!1;for(let i=0;i<a.childCount;i++){let l=a.children[i];if(l&&l.type==="type"){s=!0;break}}if(s)return;let r=a.childForFieldName("source");if(r){let l=c(r,o).slice(1,-1);if(l==="awaitly"||l.startsWith("@awaitly/")){for(let d of a.namedChildren)if(d.type==="import_clause"){for(let f of d.namedChildren)if(f.type==="named_imports"){for(let p of f.namedChildren)if(p.type==="import_specifier"){let m=!1;for(let h of p.children)if(h.type==="type"){m=!0;break}if(m)continue;let N=p.childForFieldName("name"),S=p.childForFieldName("alias");if(N){let h=c(N,o);if(h===e){let C=S?c(S,o):h;n.add(C)}}}}}}}}}),n}function J(t,e,o){if(t.type==="variable_declaration"){for(let n of t.namedChildren)if(n.type==="variable_declarator"){let a=n.childForFieldName("name");if(a&&c(a,o)===e)return!0}}if(t.type==="arrow_function"||t.type==="function_expression"||t.type==="function_declaration")return!1;for(let n of t.namedChildren)if(J(n,e,o))return!0;return!1}function ce(t,e,o){let n=t.parent;for(;n;){if(n.type==="statement_block"||n.type==="program"){for(let a of n.namedChildren)if(a.type==="lexical_declaration"){for(let s of a.namedChildren)if(s.type==="variable_declarator"){let r=s.childForFieldName("name");if(r&&c(r,o)===e)return!0}}else if(a.type==="variable_declaration"){for(let s of a.namedChildren)if(s.type==="variable_declarator"){let r=s.childForFieldName("name");if(r&&c(r,o)===e)return!0}}else if(a.type==="function_declaration"){let s=a.childForFieldName("name");if(s&&c(s,o)===e)return!0}if(n.type==="program"&&J(n,e,o))return!0}if(n.type==="arrow_function"||n.type==="function_expression"||n.type==="function_declaration"||n.type==="method_definition"){let a=n.childForFieldName("parameters");if(a)for(let r of a.namedChildren){if(r.type==="identifier"&&c(r,o)===e)return!0;if(r.type==="object_pattern"||r.type==="array_pattern"){let i=!1;if(w(r,l=>{l.type==="identifier"&&c(l,o)===e&&(i=!0)}),i)return!0}if(r.type==="assignment_pattern"){let i=r.childForFieldName("left");if(i?.type==="identifier"&&c(i,o)===e)return!0}}let s=n.childForFieldName("body");if(s&&J(s,e,o))return!0}if(n.type==="program")break;n=n.parent}return!1}function Ye(t,e){let o=de(t,"run",e);if(e.opts.assumeImported&&o.add("run"),o.size===0)return[];let n=[];return w(t,a=>{if(a.type==="call_expression"){let s=a.childForFieldName("function");if(s&&s.type==="identifier"){let r=c(s,e);if(o.has(r)){if(ce(a,r,e))return;let l=a.childForFieldName("arguments")?.namedChildren[0];(l?.type==="arrow_function"||l?.type==="function_expression")&&n.push(a)}}}}),n}function U(t,e){let o=[];return w(t,n=>{if(n.type==="call_expression"){let a=n.childForFieldName("function");if(a&&c(a,e)==="createSagaWorkflow"){let r=me(n,e);if(r){let l=n.childForFieldName("arguments")?.namedChildren[1],d=l?le(l,e):{};o.push({name:r,createSagaWorkflowCall:n,description:d.description,markdown:d.markdown})}}}}),o}function Qe(t,e){let o=U(t,e),n=new Set(o.map(s=>s.name)),a=[];return w(t,s=>{if(s.type==="call_expression"){let r=s.childForFieldName("function");if(r){let i=c(r,e);if(n.has(i)){let l=s.childForFieldName("arguments");if(l){let d=l.namedChildren[0];(d?.type==="arrow_function"||d?.type==="function_expression")&&a.push(s)}}}}}),a}function Xe(t,e){let o=de(t,"runSaga",e);if(e.opts.assumeImported&&o.add("runSaga"),o.size===0)return[];let n=[];return w(t,a=>{if(a.type==="call_expression"){let s=a.childForFieldName("function");if(s&&s.type==="identifier"){let r=c(s,e);if(o.has(r)){if(ce(a,r,e))return;let l=a.childForFieldName("arguments")?.namedChildren[0];(l?.type==="arrow_function"||l?.type==="function_expression")&&n.push(a)}}}}),n}function Ze(t,e){let o=t.childForFieldName("function"),n=o?c(o,e):"<unknown>",s=t.childForFieldName("arguments")?.namedChildren[0],r=[],i=L();i.sagaWorkflowCount=1;let l={...e,warnings:r,stats:i};if(!s||s.type!=="arrow_function"&&s.type!=="function_expression")return r.push({code:"CALLBACK_NOT_FOUND",message:`Could not find callback for saga workflow ${n}`,location:u(t,l)}),null;let d=l.currentWorkflow;l.currentWorkflow=n;let f=fe(s,l),p=l.stepParameterName,m=l.isSagaDestructured,N=l.sagaStepAlias,S=l.sagaTryStepAlias;l.stepParameterName=f?.name,l.isSagaDestructured=f?.isDestructured,l.sagaStepAlias=f?.stepAlias,l.sagaTryStepAlias=f?.tryStepAlias;let h=ue(s,l);l.currentWorkflow=d,l.stepParameterName=p,l.isSagaDestructured=m,l.sagaStepAlias=N,l.sagaTryStepAlias=S;let C=t.tree?.rootNode,Y=(C?U(C,e):[]).find(_e=>_e.name===n),be={id:y(),type:"workflow",workflowName:n,source:"createSagaWorkflow",dependencies:[],errorTypes:[],children:b(h),description:Y?.description,markdown:Y?.markdown},Ae={analyzedAt:Date.now(),filePath:l.filePath,warnings:r,stats:i};return{root:be,metadata:Ae,references:new Map}}function et(t,e){let n=t.childForFieldName("arguments")?.namedChildren[0],a=[],s=L();s.sagaWorkflowCount=1;let r={...e,warnings:a,stats:s};if(!n||n.type!=="arrow_function"&&n.type!=="function_expression")return a.push({code:"CALLBACK_NOT_FOUND",message:"Could not find callback for runSaga()",location:u(t,r)}),null;let i=tt(t,r),l=fe(n,r),d=r.stepParameterName,f=r.isSagaDestructured,p=r.sagaStepAlias,m=r.sagaTryStepAlias;r.stepParameterName=l?.name,r.isSagaDestructured=l?.isDestructured,r.sagaStepAlias=l?.stepAlias,r.sagaTryStepAlias=l?.tryStepAlias;let N=ue(n,r);r.stepParameterName=d,r.isSagaDestructured=f,r.sagaStepAlias=p,r.sagaTryStepAlias=m;let S={id:y(),type:"workflow",workflowName:i,source:"runSaga",dependencies:[],errorTypes:[],children:b(N),location:r.opts.includeLocations?u(t,r):void 0},h={analyzedAt:Date.now(),filePath:r.filePath,warnings:a,stats:s};return{root:S,metadata:h,references:new Map}}function tt(t,e){let o=t.startPosition.row+1,n=e.filePath;return`runSaga@${n.includes("/")?n.split("/").pop()||n:n.includes("\\")&&n.split("\\").pop()||n}:${o}`}function fe(t,e){let o=t.childForFieldName("parameters");if(!o)return;let n=o.namedChildren[0];if(n){if(n.type==="identifier")return{name:c(n,e),isDestructured:!1};if(n.type==="required_parameter"){let a=n.childForFieldName("pattern");if(a){if(a.type==="object_pattern"){let s=oe(a,e);if(s.stepAlias||s.tryStepAlias)return{isDestructured:!0,...s}}return{name:c(a,e),isDestructured:!1}}}if(n.type==="object_pattern"){let a=oe(n,e);if(a.stepAlias||a.tryStepAlias)return{isDestructured:!0,...a}}}}function oe(t,e){let o={};for(let n of t.namedChildren){if(n.type==="pair_pattern"){let a=n.childForFieldName("key"),s=n.childForFieldName("value");if(a&&s){let r=c(a,e);if(r==="step"||r==="tryStep"){let i;if(s.type==="assignment_pattern"){let l=s.childForFieldName("left");i=c(l||s,e)}else i=c(s,e);r==="step"?o.stepAlias=i:o.tryStepAlias=i}}}if(n.type==="shorthand_property_identifier_pattern"){let a=c(n,e);a==="step"?o.stepAlias="step":a==="tryStep"&&(o.tryStepAlias="tryStep")}if(n.type==="assignment_pattern"){let a=n.childForFieldName("left");if(a){let s=c(a,e);s==="step"?o.stepAlias="step":s==="tryStep"&&(o.tryStepAlias="tryStep")}}}return o}function ue(t,e){let o=t.childForFieldName("body");return o?o.type==="statement_block"?V(o.namedChildren,e):$(o,e):[]}function V(t,e){let o=[];for(let n of t){let a=pe(n,e);o.push(...a)}return o}function pe(t,e){switch(t.type){case"expression_statement":{let o=t.namedChildren[0];return o?$(o,e):[]}case"variable_declaration":case"lexical_declaration":return nt(t,e);case"return_statement":{let o=t.childForFieldName("value");return o?$(o,e):[]}case"if_statement":return ot(t,e);case"for_statement":case"for_in_statement":case"while_statement":return at(t,e);case"switch_statement":return rt(t,e);default:return[]}}function $(t,e){if(t.type==="await_expression"){let o=t.namedChildren[0];return o?$(o,e):[]}if(t.type==="parenthesized_expression"){let o=t.namedChildren[0];return o?$(o,e):[]}return t.type==="call_expression"?st(t,e):[]}function nt(t,e){let o=[];for(let n of t.namedChildren)if(n.type==="variable_declarator"){let a=n.childForFieldName("value");a&&o.push(...$(a,e))}return o}function ot(t,e){e.stats.conditionalCount++;let o=t.childForFieldName("condition"),n=t.childForFieldName("consequence"),a=t.childForFieldName("alternative"),s=o?c(o,e).replace(/^\(|\)$/g,""):"<unknown>",r=n?T(n,e):[],i;if(a)if(a.type==="else_clause"){let l=a.namedChildren[0];l&&(i=T(l,e))}else i=T(a,e);return[{id:y(),type:"conditional",condition:s,helper:null,consequent:r,alternate:i?.length?i:void 0,location:e.opts.includeLocations?u(t,e):void 0}]}function T(t,e){return t.type==="statement_block"?V(t.namedChildren,e):pe(t,e)}function at(t,e){let o=t.childForFieldName("body");if(!o)return[];let n=T(o,e);if(n.length===0)return[];e.stats.loopCount++;let a="for";t.type==="while_statement"?a="while":t.type==="for_in_statement"&&(a=c(t,e).includes(" of ")?"for-of":"for-in");let s=t.childForFieldName("right"),r=s?c(s,e):void 0;return[{id:y(),type:"loop",loopType:a,iterSource:r,body:n,boundKnown:!1,location:e.opts.includeLocations?u(t,e):void 0}]}function rt(t,e){let o=t.childForFieldName("value"),n=t.childForFieldName("body"),a=o?c(o,e).replace(/^\(|\)$/g,""):"<unknown>",s=[],r=!1;if(n){for(let l of n.namedChildren)if(l.type==="switch_case"||l.type==="switch_default"){let d=l.childForFieldName("value"),f=l.type==="switch_default"||!d,p=d?c(d,e):void 0,m=l.namedChildren.filter(S=>S!==d),N=V(m,e);N.length>0&&(r=!0),s.push({value:p,isDefault:f,body:N})}}return r&&e.stats.conditionalCount++,r?[{id:y(),type:"switch",expression:a,cases:s,location:e.opts.includeLocations?u(t,e):void 0}]:[]}function st(t,e){let o=t.childForFieldName("function");if(!o)return[];let n=c(o,e),a=e.stepParameterName||"saga";return e.isSagaDestructured?e.sagaStepAlias&&n===e.sagaStepAlias?[ae(t,e)]:e.sagaTryStepAlias&&n===e.sagaTryStepAlias?[re(t,e)]:[]:n===`${a}.step`?[ae(t,e)]:n===`${a}.tryStep`?[re(t,e)]:[]}function ae(t,e){e.stats.totalSteps++;let o=t.childForFieldName("arguments"),n=o?.namedChildren[0],a=o?.namedChildren[1],s="<unknown>";if(n)if(n.type==="arrow_function"||n.type==="function_expression"){let p=n.childForFieldName("body");p&&(s=R(p,e))}else s=c(n,e);let{hasCompensation:r,compensationCallee:i,name:l,description:d,markdown:f}=ye(a,e);return r&&(e.stats.compensatedStepCount=(e.stats.compensatedStepCount||0)+1),{id:y(),type:"saga-step",callee:s,name:l,description:d,markdown:f,hasCompensation:r,compensationCallee:i,location:e.opts.includeLocations?u(t,e):void 0}}function re(t,e){e.stats.totalSteps++;let o=t.childForFieldName("arguments"),n=o?.namedChildren[0],a=o?.namedChildren[1],s="<unknown>";if(n)if(n.type==="arrow_function"||n.type==="function_expression"){let p=n.childForFieldName("body");p&&(s=R(p,e))}else s=c(n,e);let{hasCompensation:r,compensationCallee:i,name:l,description:d,markdown:f}=ye(a,e);return r&&(e.stats.compensatedStepCount=(e.stats.compensatedStepCount||0)+1),{id:y(),type:"saga-step",callee:s,name:l,description:d,markdown:f,hasCompensation:r,compensationCallee:i,isTryStep:!0,location:e.opts.includeLocations?u(t,e):void 0}}function ye(t,e){let o={hasCompensation:!1,compensationCallee:void 0,name:void 0,description:void 0,markdown:void 0};if(!t||t.type!=="object")return o;for(let n of t.namedChildren)if(n.type==="pair"){let a=n.childForFieldName("key"),s=n.childForFieldName("value");if(a&&s){let r=c(a,e);if(r==="compensate"){if(o.hasCompensation=!0,s.type==="arrow_function"||s.type==="function_expression"){let i=s.childForFieldName("body");i&&(o.compensationCallee=R(i,e))}}else if(r==="name"){let i=g(s,e);i&&(o.name=i)}else if(r==="description"){let i=g(s,e);i&&(o.description=i)}else if(r==="markdown"){let i=g(s,e);i&&(o.markdown=i)}}}return o}function it(t,e){let o=t.startPosition.row+1,n=e.filePath;return`run@${n.includes("/")?n.split("/").pop()||n:n.includes("\\")&&n.split("\\").pop()||n}:${o}`}function lt(t,e){let n=t.childForFieldName("arguments")?.namedChildren[0],a=[],s=L(),r={...e,warnings:a,stats:s};if(!n||n.type!=="arrow_function"&&n.type!=="function_expression")return a.push({code:"CALLBACK_NOT_FOUND",message:"Could not find callback for run()",location:u(t,r)}),null;let i=it(t,r),l=Ne(n,r),d=r.stepParameterName;r.stepParameterName=l;let f=Se(n,r);r.stepParameterName=d;let p={id:y(),type:"workflow",workflowName:i,source:"run",dependencies:[],errorTypes:[],children:b(f),location:r.opts.includeLocations?u(t,r):void 0},m={analyzedAt:Date.now(),filePath:r.filePath,warnings:a,stats:s};return{root:p,metadata:m,references:new Map}}function dt(t,e){let o=t.childForFieldName("function"),n=o?c(o,e):"<unknown>",s=t.childForFieldName("arguments")?.namedChildren[0],r=[],i=L(),l={...e,warnings:r,stats:i};if(!s||s.type!=="arrow_function"&&s.type!=="function_expression")return r.push({code:"CALLBACK_NOT_FOUND",message:`Could not find callback for workflow ${n}`,location:u(t,l)}),null;let d=l.currentWorkflow;l.currentWorkflow=n;let f=Ne(s,l),p=l.stepParameterName;l.stepParameterName=f;let m=Se(s,l);l.currentWorkflow=d,l.stepParameterName=p;let S=K(t.tree?.rootNode||t,e).find(G=>G.name===n),h={id:y(),type:"workflow",workflowName:n,source:"createWorkflow",dependencies:[],errorTypes:[],children:b(m),description:S?.description,markdown:S?.markdown},C={analyzedAt:Date.now(),filePath:l.filePath,warnings:r,stats:i};return{root:h,metadata:C,references:new Map}}function me(t,e){let o=t;for(;o;){if(o.type==="variable_declarator"){let n=o.childForFieldName("name");if(n)return c(n,e)}o=o.parent}return null}function Ne(t,e){let o=t.childForFieldName("parameters");if(!o)return;let n=o.namedChildren[0];if(n){if(n.type==="identifier")return c(n,e);if(n.type==="required_parameter"){let a=n.childForFieldName("pattern");if(a)return a.type==="object_pattern"?se(a,e):c(a,e)}if(n.type==="object_pattern")return se(n,e)}}function se(t,e){for(let o of t.namedChildren){if(o.type==="pair_pattern"){let n=o.childForFieldName("key"),a=o.childForFieldName("value");if(n&&a&&c(n,e)==="step"){if(a.type==="assignment_pattern"){let r=a.childForFieldName("left");if(r)return c(r,e)}return c(a,e)}}if(o.type==="shorthand_property_identifier_pattern"&&c(o,e)==="step")return"step";if(o.type==="assignment_pattern"){let n=o.childForFieldName("left");if(n&&c(n,e)==="step")return"step"}}}function Se(t,e){let o=t.childForFieldName("body");return o?o.type==="statement_block"?O(o.namedChildren,e):k(o,e):[]}function O(t,e){let o=[];for(let n of t){let a=he(n,e);o.push(...a)}return o}function he(t,e){switch(t.type){case"expression_statement":{let o=t.namedChildren[0];return o?k(o,e):[]}case"variable_declaration":case"lexical_declaration":return ct(t,e);case"return_statement":{let o=t.childForFieldName("value");return o?k(o,e):[]}case"if_statement":return Ft(t,e);case"for_statement":return zt(t,e);case"for_in_statement":return It(t,e);case"while_statement":return $t(t,e);case"switch_statement":return kt(t,e);default:return[]}}function k(t,e){if(t.type==="await_expression"){let o=t.namedChildren[0];return o?k(o,e):[]}if(t.type==="parenthesized_expression"){let o=t.namedChildren[0];return o?k(o,e):[]}return t.type==="call_expression"?H(t,e):[]}function ct(t,e){let o=[];for(let n of t.namedChildren)if(n.type==="variable_declarator"){let a=n.childForFieldName("value");a&&o.push(...k(a,e))}return o}function ft(t,e){e.stats.streamCount++;let n=t.childForFieldName("arguments")?.namedChildren[0],a=n?ge(n,e):{};return{id:y(),type:"stream",streamType:"write",namespace:a.namespace,options:a.highWaterMark!==void 0?{highWaterMark:a.highWaterMark}:void 0,callee:"step.getWritable",location:e.opts.includeLocations?u(t,e):void 0}}function ut(t,e){e.stats.streamCount++;let n=t.childForFieldName("arguments")?.namedChildren[0],a=n?ge(n,e):{};return{id:y(),type:"stream",streamType:"read",namespace:a.namespace,options:a.startIndex!==void 0?{startIndex:a.startIndex}:void 0,callee:"step.getReadable",location:e.opts.includeLocations?u(t,e):void 0}}function pt(t,e){e.stats.streamCount++;let n=t.childForFieldName("arguments")?.namedChildren[2],a=n?yt(n,e):{};return{id:y(),type:"stream",streamType:"forEach",options:{...a.concurrency!==void 0?{concurrency:a.concurrency}:{},...a.checkpointInterval!==void 0?{checkpointInterval:a.checkpointInterval}:{}},callee:"step.streamForEach",location:e.opts.includeLocations?u(t,e):void 0}}function ge(t,e){let o={};if(t.type!=="object")return o;for(let n of t.namedChildren)if(n.type==="pair"){let a=n.childForFieldName("key"),s=n.childForFieldName("value");if(a&&s){let r=c(a,e);if(r==="namespace"){let i=g(s,e);i&&i!=="<dynamic>"&&(o.namespace=i)}else r==="highWaterMark"?o.highWaterMark=A(s,e):r==="startIndex"&&(o.startIndex=A(s,e))}}return o}function yt(t,e){let o={};if(t.type!=="object")return o;for(let n of t.namedChildren)if(n.type==="pair"){let a=n.childForFieldName("key"),s=n.childForFieldName("value");if(a&&s){let r=c(a,e);r==="concurrency"?o.concurrency=A(s,e):r==="checkpointInterval"&&(o.checkpointInterval=A(s,e))}}return o}function H(t,e){let o=t.childForFieldName("function");if(!o)return[];let n=c(o,e),a=e.stepParameterName||"step";return n===a?[St(t,e)]:n===`${a}.retry`?[ht(t,e)]:n===`${a}.withTimeout`?[gt(t,e)]:n===`${a}.parallel`?wt(t,e):n===`${a}.race`?Ct(t,e):n===`${a}.getWritable`?[ft(t,e)]:n===`${a}.getReadable`?[ut(t,e)]:n===`${a}.streamForEach`?[pt(t,e)]:["when","unless","whenOr","unlessOr"].includes(n)?bt(t,n,e):n==="allAsync"||n==="allSettledAsync"?At(t,n==="allAsync"?"all":"allSettled",e):n==="anyAsync"?_t(t,e):mt(t,n,e)?Nt(t,n,e):[]}function mt(t,e,o){if(e===o.currentWorkflow)return!1;let a=t.childForFieldName("arguments")?.namedChildren[0];if(!a)return!1;if(a.type==="arrow_function"||a.type==="function_expression"){if(o.workflowNames.has(e))return!0;let s=a.childForFieldName("parameters");if(s){let r=c(s,o);if(r.includes("step")||r.includes("deps"))return!0}}return!1}function Nt(t,e,o){return o.stats.workflowRefCount++,[{id:y(),type:"workflow-ref",workflowName:e,resolved:!1,location:o.opts.includeLocations?u(t,o):void 0}]}function R(t,e){if(t.type==="call_expression"){let o=t.childForFieldName("function");if(o)return c(o,e)}if(t.type==="statement_block"){for(let o of t.namedChildren)if(o.type==="return_statement"){let n=o.namedChildren[0];if(n?.type==="call_expression"){let a=n.childForFieldName("function");if(a)return c(a,e)}else if(n)return c(n,e)}}return c(t,e)}function St(t,e){e.stats.totalSteps++;let o=t.childForFieldName("arguments"),n=o?.namedChildren[0],a=o?.namedChildren[1],s="<unknown>";if(n)if(n.type==="arrow_function"||n.type==="function_expression"){let l=n.childForFieldName("body");l&&(s=R(l,e))}else s=c(n,e);let r=a?D(a,e):{};return{id:y(),type:"step",callee:s,key:r.key,name:r.name,retry:r.retry,timeout:r.timeout,location:e.opts.includeLocations?u(t,e):void 0}}function ht(t,e){e.stats.totalSteps++;let n=t.childForFieldName("arguments")?.namedChildren||[],a=n[0],s="<unknown>";if(a)if(a.type==="arrow_function"||a.type==="function_expression"){let d=a.childForFieldName("body");d&&(s=R(d,e))}else s=c(a,e);let r=n[1],i=r?D(r,e):{},l=r?we(r,e):void 0;return{id:y(),type:"step",callee:s,key:i.key,name:i.name,retry:l,timeout:i.timeout,location:e.opts.includeLocations?u(t,e):void 0}}function gt(t,e){e.stats.totalSteps++;let n=t.childForFieldName("arguments")?.namedChildren||[],a=n[0],s="<unknown>";if(a)if(a.type==="arrow_function"||a.type==="function_expression"){let d=a.childForFieldName("body");d&&(s=R(d,e))}else s=c(a,e);let r=n[1],i=r?D(r,e):{},l=r?Ce(r,e):void 0;return{id:y(),type:"step",callee:s,key:i.key,name:i.name,retry:i.retry,timeout:l,location:e.opts.includeLocations?u(t,e):void 0}}function D(t,e){let o={};if(t.type!=="object")return o;for(let n of t.namedChildren)if(n.type==="pair"){let a=n.childForFieldName("key"),s=n.childForFieldName("value");if(a&&s){let r=c(a,e);if(r==="key"){let i=g(s,e);i&&(o.key=i)}else if(r==="name"){let i=g(s,e);i&&(o.name=i)}else r==="retry"?o.retry=we(s,e):r==="timeout"&&(o.timeout=Ce(s,e))}}return o}function we(t,e){let o={};if(t.type!=="object")return o;for(let n of t.namedChildren)if(n.type==="pair"){let a=n.childForFieldName("key"),s=n.childForFieldName("value");if(a&&s){let r=c(a,e);if(r==="attempts"){let i=A(s,e);o.attempts=i}else if(r==="backoff"){let i=g(s,e);i==="fixed"||i==="linear"||i==="exponential"?o.backoff=i:o.backoff="<dynamic>"}else if(r==="baseDelay"){let i=A(s,e);o.baseDelay=i}else r==="retryOn"&&(o.retryOn=c(s,e))}}return o}function Ce(t,e){let o={};if(t.type!=="object")return o;for(let n of t.namedChildren)if(n.type==="pair"){let a=n.childForFieldName("key"),s=n.childForFieldName("value");if(a&&s&&c(a,e)==="ms"){let i=A(s,e);o.ms=i}}return o}function A(t,e){let o=c(t,e);if(t.type==="number"){let n=parseFloat(o);return isNaN(n)?"<dynamic>":n}return"<dynamic>"}function wt(t,e){let o=t.childForFieldName("arguments"),n=o?.namedChildren[0];if(!n)return[];if(n.type==="string"||n.type==="identifier"||n.type==="member_expression"){let i=n.type==="string"?g(n,e):c(n,e),l=o?.namedChildren[1];if(l&&(l.type==="arrow_function"||l.type==="function_expression")){let d=M(l,e);if(d.length>0){for(let f of d)f.type==="parallel"&&i&&(f.name=i);return d}}return[]}if(n.type!=="object")return[];e.stats.parallelCount++;let a=[];for(let i of n.namedChildren)if(i.type==="pair"){let l=i.childForFieldName("key"),d=i.childForFieldName("value");if(l&&d){let f=Fe(l,d,e);f&&a.push(f)}}let s=o?.namedChildren[1],r=s?D(s,e):{};return[{id:y(),type:"parallel",mode:"all",name:r.name,children:a,callee:"step.parallel",location:e.opts.includeLocations?u(t,e):void 0}]}function Fe(t,e,o){o.stats.totalSteps++;let n=c(t,o),a="<unknown>";if(e.type==="arrow_function"||e.type==="function_expression"){let s=e.childForFieldName("body");if(s?.type==="call_expression"){let r=s.childForFieldName("function");r&&(a=c(r,o))}}return{id:y(),type:"step",callee:a,name:n,location:o.opts.includeLocations?u(e,o):void 0}}function Ct(t,e){e.stats.raceCount++;let n=t.childForFieldName("arguments")?.namedChildren[0];if(!n||n.type!=="object")return[];let a=[];for(let s of n.namedChildren)if(s.type==="pair"){let r=s.childForFieldName("key"),i=s.childForFieldName("value");if(r&&i){let l=Fe(r,i,e);l&&a.push(l)}}return[{id:y(),type:"race",children:a,callee:"step.race",location:e.opts.includeLocations?u(t,e):void 0}]}function Ft(t,e){e.stats.conditionalCount++;let o=t.childForFieldName("condition"),n=t.childForFieldName("consequence"),a=t.childForFieldName("alternative"),s=o?c(o,e).replace(/^\(|\)$/g,""):"<unknown>",r=n?I(n,e):[],i;if(a)if(a.type==="else_clause"){let l=a.namedChildren[0];l&&(i=I(l,e))}else i=I(a,e);return[{id:y(),type:"conditional",condition:s,helper:null,consequent:r,alternate:i?.length?i:void 0,location:e.opts.includeLocations?u(t,e):void 0}]}function I(t,e){return t.type==="statement_block"?O(t.namedChildren,e):he(t,e)}function kt(t,e){let o=t.childForFieldName("value"),n=t.childForFieldName("body"),a=o?c(o,e).replace(/^\(|\)$/g,""):"<unknown>",s=[],r=!1;if(n){for(let l of n.namedChildren)if(l.type==="switch_case"||l.type==="switch_default"){let d=l.childForFieldName("value"),f=l.type==="switch_default"||!d,p=d?c(d,e):void 0,m=l.namedChildren.filter(S=>S!==d),N=O(m,e);N.length>0&&(r=!0),s.push({value:p,isDefault:f,body:N})}}return r&&e.stats.conditionalCount++,r?[{id:y(),type:"switch",expression:a,cases:s,location:e.opts.includeLocations?u(t,e):void 0}]:[]}function bt(t,e,o){o.stats.conditionalCount++;let a=t.childForFieldName("arguments")?.namedChildren||[],s=a[0],r=s?c(s,o):"<unknown>",i=a[1],l=i?M(i,o):[],d;return(e==="whenOr"||e==="unlessOr")&&a[2]&&(d=c(a[2],o)),[{id:y(),type:"conditional",condition:r,helper:e,consequent:l,defaultValue:d,location:o.opts.includeLocations?u(t,o):void 0}]}function M(t,e){if(t.type==="arrow_function"||t.type==="function_expression"){let o=t.childForFieldName("body");if(o)return o.type==="statement_block"?O(o.namedChildren,e):k(o,e)}return k(t,e)}function At(t,e,o){o.stats.parallelCount++;let a=t.childForFieldName("arguments")?.namedChildren[0];if(!a||a.type!=="array")return[];let s=[];for(let r of a.namedChildren)if(r.type==="call_expression"){let i=H(r,o);if(i.length>0)s.push(...b(i));else{let l=ke(r,o);l&&s.push(l)}}else{let i=M(r,o);s.push(...b(i))}return[{id:y(),type:"parallel",mode:e,children:s,callee:e==="all"?"allAsync":"allSettledAsync",location:o.opts.includeLocations?u(t,o):void 0}]}function _t(t,e){e.stats.raceCount++;let n=t.childForFieldName("arguments")?.namedChildren[0];if(!n||n.type!=="array")return[];let a=[];for(let r of n.namedChildren)if(r.type==="call_expression"){let i=H(r,e);if(i.length>0)a.push(...b(i));else{let l=ke(r,e);l&&a.push(l)}}else{let i=M(r,e);a.push(...b(i))}return[{id:y(),type:"race",children:a,callee:"anyAsync",location:e.opts.includeLocations?u(t,e):void 0}]}function ke(t,e){e.stats.totalSteps++;let o=t.childForFieldName("function"),n=o?c(o,e):"<unknown>",a=n.includes(".")?n.split(".").pop():n;return{id:y(),type:"step",name:a,callee:n,location:e.opts.includeLocations?u(t,e):void 0}}function zt(t,e){let o=t.childForFieldName("body");if(!o)return[];let n=I(o,e);return n.length===0?[]:(e.stats.loopCount++,[{id:y(),type:"loop",loopType:"for",body:n,boundKnown:!1,location:e.opts.includeLocations?u(t,e):void 0}])}function It(t,e){let o=t.childForFieldName("body");if(!o)return[];let n=I(o,e);if(n.length===0)return[];e.stats.loopCount++;let s=c(t,e).includes(" of "),r=t.childForFieldName("right"),i=r?c(r,e):void 0;return[{id:y(),type:"loop",loopType:s?"for-of":"for-in",iterSource:i,body:n,boundKnown:!1,location:e.opts.includeLocations?u(t,e):void 0}]}function $t(t,e){let o=t.childForFieldName("body");if(!o)return[];let n=I(o,e);return n.length===0?[]:(e.stats.loopCount++,[{id:y(),type:"loop",loopType:"while",body:n,boundKnown:!1,location:e.opts.includeLocations?u(t,e):void 0}])}function c(t,e){return e.sourceCode.slice(t.startIndex,t.endIndex)}function g(t,e){let o=c(t,e);return t.type==="string"?o.slice(1,-1):t.type==="template_string"?"<dynamic>":o}function u(t,e){return{filePath:e.filePath,line:t.startPosition.row+1,column:t.startPosition.column,endLine:t.endPosition.row+1,endColumn:t.endPosition.column}}function w(t,e){e(t);for(let o of t.namedChildren)w(o,e)}function b(t){return t.length<=1?t:[{id:y(),type:"sequence",children:t}]}function L(){return{totalSteps:0,conditionalCount:0,parallelCount:0,raceCount:0,loopCount:0,streamCount:0,workflowRefCount:0,unknownCount:0,sagaWorkflowCount:0}}0&&(module.exports={analyzeWorkflowSource,clearTreeSitterBrowserCache,getWasmBasePath,renderMultipleStaticJSON,renderPathsMermaid,renderStaticJSON,renderStaticMermaid,resetIdCounter,setWasmBasePath});
|
|
8
10
|
//# sourceMappingURL=browser.cjs.map
|