@saptools/service-flow 0.1.35 → 0.1.36

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.
@@ -1335,16 +1335,32 @@ async function importsFor(repoPath, filePath, sf) {
1335
1335
  }
1336
1336
  return imports;
1337
1337
  }
1338
- function collectReturnedObjectBindings(fn) {
1338
+ function collectLocalBindingFacts(fn) {
1339
1339
  const bindings = /* @__PURE__ */ new Map();
1340
- const returns = /* @__PURE__ */ new Map();
1341
1340
  function visit(node) {
1342
1341
  if (node !== fn && (ts5.isFunctionDeclaration(node) || ts5.isArrowFunction(node) || ts5.isFunctionExpression(node)))
1343
1342
  return;
1344
1343
  if (ts5.isVariableDeclaration(node) && ts5.isIdentifier(node.name) && node.initializer) {
1345
1344
  const fact = findConnectInExpression(node.initializer);
1346
1345
  if (fact) bindings.set(node.name.text, fact);
1346
+ const call = unwrapCall(node.initializer);
1347
+ if (call && ts5.isPropertyAccessExpression(call.expression) && call.expression.name.text === "tx" && ts5.isIdentifier(call.expression.expression)) {
1348
+ const sourceName = call.expression.expression.text;
1349
+ const source = bindings.get(sourceName);
1350
+ if (source) bindings.set(node.name.text, { ...source, helperChain: [...source.helperChain ?? [], { aliasOf: sourceName, callerVariable: node.name.text, aliasKind: "transaction", transactionAliasSource: sourceName }] });
1351
+ }
1347
1352
  }
1353
+ ts5.forEachChild(node, visit);
1354
+ }
1355
+ visit(fn);
1356
+ return bindings;
1357
+ }
1358
+ function collectReturnedObjectBindings(fn) {
1359
+ const bindings = collectLocalBindingFacts(fn);
1360
+ const returns = /* @__PURE__ */ new Map();
1361
+ function visit(node) {
1362
+ if (node !== fn && (ts5.isFunctionDeclaration(node) || ts5.isArrowFunction(node) || ts5.isFunctionExpression(node)))
1363
+ return;
1348
1364
  if (ts5.isReturnStatement(node) && node.expression && ts5.isObjectLiteralExpression(node.expression)) {
1349
1365
  for (const prop of node.expression.properties) {
1350
1366
  if (ts5.isShorthandPropertyAssignment(prop)) returns.set(prop.name.text, prop.name.text);
@@ -1370,15 +1386,11 @@ function functionLikeInitializer(expr) {
1370
1386
  return void 0;
1371
1387
  }
1372
1388
  function directReturnConnectFact(fn) {
1373
- const localBindings = /* @__PURE__ */ new Map();
1389
+ const localBindings = collectLocalBindingFacts(fn);
1374
1390
  let returned;
1375
1391
  function visit(node) {
1376
1392
  if (node !== fn && (ts5.isFunctionDeclaration(node) || ts5.isArrowFunction(node) || ts5.isFunctionExpression(node)))
1377
1393
  return;
1378
- if (ts5.isVariableDeclaration(node) && ts5.isIdentifier(node.name) && node.initializer) {
1379
- const fact = findConnectInExpression(node.initializer);
1380
- if (fact) localBindings.set(node.name.text, fact);
1381
- }
1382
1394
  if (!returned && ts5.isReturnStatement(node) && node.expression)
1383
1395
  returned = node.expression;
1384
1396
  if (!returned) ts5.forEachChild(node, visit);
@@ -1482,8 +1494,11 @@ async function parseServiceBindings(repoPath, filePath) {
1482
1494
  const helperCache = /* @__PURE__ */ new Map();
1483
1495
  const classHelpers = collectClassHelpers(sourceFileAst);
1484
1496
  const localObjectHelpers = /* @__PURE__ */ new Map();
1497
+ const localDirectHelpers = /* @__PURE__ */ new Map();
1485
1498
  for (const stmt of sourceFileAst.statements) {
1486
1499
  if (ts5.isFunctionDeclaration(stmt) && stmt.name) {
1500
+ const directFact = directConnectFactFromFunctionLike(stmt);
1501
+ if (directFact) localDirectHelpers.set(stmt.name.text, { ...directFact, exportedName: stmt.name.text, sourceFile: normalizePath(filePath), sourceLine: lineOf4(sourceFileAst, stmt) });
1487
1502
  const rows2 = [];
1488
1503
  for (const [returnedProperty, fact] of collectReturnedObjectBindings(stmt))
1489
1504
  rows2.push({ ...fact, exportedName: stmt.name.text, returnedProperty, sourceFile: normalizePath(filePath), sourceLine: lineOf4(sourceFileAst, stmt) });
@@ -1494,6 +1509,8 @@ async function parseServiceBindings(repoPath, filePath) {
1494
1509
  if (!ts5.isIdentifier(decl.name)) continue;
1495
1510
  const helper = functionLikeInitializer(decl.initializer);
1496
1511
  if (!helper) continue;
1512
+ const directFact = directConnectFactFromFunctionLike(helper);
1513
+ if (directFact) localDirectHelpers.set(decl.name.text, { ...directFact, exportedName: decl.name.text, sourceFile: normalizePath(filePath), sourceLine: lineOf4(sourceFileAst, decl) });
1497
1514
  const rows2 = [];
1498
1515
  for (const [returnedProperty, fact] of collectReturnedObjectBindings(helper))
1499
1516
  rows2.push({ ...fact, exportedName: decl.name.text, returnedProperty, sourceFile: normalizePath(filePath), sourceLine: lineOf4(sourceFileAst, decl) });
@@ -1555,7 +1572,8 @@ async function parseServiceBindings(repoPath, filePath) {
1555
1572
  helperChain: aliasKind === "assignment" ? [{ callerVariable: targetName, assignedFrom: call.expression.getText(sourceFileAst), aliasKind, scopeRule: "same-file-source-order" }] : void 0
1556
1573
  });
1557
1574
  else if (ts5.isIdentifier(call.expression)) {
1558
- const resolved2 = await importedHelper(call.expression.text);
1575
+ const localDirect = localDirectHelpers.get(call.expression.text);
1576
+ const resolved2 = localDirect ? { helper: localDirect, imp: void 0 } : await importedHelper(call.expression.text);
1559
1577
  if (resolved2)
1560
1578
  out.push({
1561
1579
  variableName: targetName,
@@ -1568,12 +1586,13 @@ async function parseServiceBindings(repoPath, filePath) {
1568
1586
  sourceFile: normalizePath(filePath),
1569
1587
  sourceLine: lineOf4(sourceFileAst, node),
1570
1588
  helperChain: [
1589
+ ...resolved2.helper.helperChain ?? [],
1571
1590
  {
1572
1591
  callerVariable: targetName,
1573
1592
  ...aliasKind === "assignment" ? { assignedFrom: call.expression.text, aliasKind, scopeRule: "same-file-source-order" } : {},
1574
1593
  importedHelper: call.expression.text,
1575
- importSource: resolved2.imp.sourceFile,
1576
- exportedSymbol: resolved2.imp.exportedName,
1594
+ importSource: resolved2.imp?.sourceFile,
1595
+ exportedSymbol: resolved2.imp?.exportedName ?? resolved2.helper.exportedName,
1577
1596
  helperSourceFile: resolved2.helper.sourceFile,
1578
1597
  helperSourceLine: resolved2.helper.sourceLine
1579
1598
  }
@@ -1613,7 +1632,7 @@ async function parseServiceBindings(repoPath, filePath) {
1613
1632
  placeholders: resolved2.helper.placeholders,
1614
1633
  sourceFile: normalizePath(filePath),
1615
1634
  sourceLine: lineOf4(sourceFileAst, decl),
1616
- helperChain: [{ callerVariable: el.name.text, helperFunction: call.expression.getText(sourceFileAst), returnedProperty: propertyName, importSource: resolved2.imp?.sourceFile, exportedSymbol: resolved2.imp?.exportedName, helperSourceFile: resolved2.helper.sourceFile, helperSourceLine: resolved2.helper.sourceLine }]
1635
+ helperChain: [...resolved2.helper.helperChain ?? [], { callerVariable: el.name.text, helperFunction: call.expression.getText(sourceFileAst), returnedProperty: propertyName, importSource: resolved2.imp?.sourceFile, exportedSymbol: resolved2.imp?.exportedName, helperSourceFile: resolved2.helper.sourceFile, helperSourceLine: resolved2.helper.sourceLine }]
1617
1636
  });
1618
1637
  }
1619
1638
  }
@@ -1646,7 +1665,7 @@ async function parseServiceBindings(repoPath, filePath) {
1646
1665
  placeholders: resolved2.helper.placeholders,
1647
1666
  sourceFile: normalizePath(filePath),
1648
1667
  sourceLine: lineOf4(sourceFileAst, node),
1649
- helperChain: [{ callerVariable: targetName, assignedFrom: call.expression.getText(sourceFileAst), aliasKind: "assignment", scopeRule: "same-file-source-order", returnedProperty: propertyName, importSource: resolved2.imp?.sourceFile, exportedSymbol: resolved2.imp?.exportedName, helperSourceFile: resolved2.helper.sourceFile, helperSourceLine: resolved2.helper.sourceLine }]
1668
+ helperChain: [...resolved2.helper.helperChain ?? [], { callerVariable: targetName, assignedFrom: call.expression.getText(sourceFileAst), aliasKind: "assignment", scopeRule: "same-file-source-order", returnedProperty: propertyName, importSource: resolved2.imp?.sourceFile, exportedSymbol: resolved2.imp?.exportedName, helperSourceFile: resolved2.helper.sourceFile, helperSourceLine: resolved2.helper.sourceLine }]
1650
1669
  });
1651
1670
  }
1652
1671
  }
@@ -1682,6 +1701,68 @@ async function parseServiceBindings(repoPath, filePath) {
1682
1701
  });
1683
1702
  }
1684
1703
  }
1704
+ function arrayElementsFromExpression(expr) {
1705
+ const unwrapped = unwrapIdentityExpression(expr);
1706
+ if (ts5.isArrayLiteralExpression(unwrapped)) return { elements: unwrapped.elements, promiseAll: false };
1707
+ const call = unwrapCall(expr);
1708
+ if (!call) return void 0;
1709
+ if (!ts5.isPropertyAccessExpression(call.expression) || call.expression.name.text !== "all" || call.expression.expression.getText(sourceFileAst) !== "Promise") return void 0;
1710
+ const first = call.arguments[0];
1711
+ if (!first) return void 0;
1712
+ const container = unwrapIdentityExpression(first);
1713
+ if (!ts5.isArrayLiteralExpression(container)) return void 0;
1714
+ return { elements: container.elements, promiseAll: true };
1715
+ }
1716
+ async function recordArrayElementBinding(targetName, expr, node, arrayIndex, promiseAll) {
1717
+ const before = out.length;
1718
+ await recordBindingFromExpression(targetName, expr, node, "declaration");
1719
+ if (out.length > before) {
1720
+ const row = out[out.length - 1];
1721
+ row.helperChain = [
1722
+ ...row.helperChain ?? [],
1723
+ { callerVariable: targetName, targetVariable: targetName, arrayIndex, promiseAll, arrayContainer: promiseAll ? "Promise.all" : "array_literal" }
1724
+ ];
1725
+ return;
1726
+ }
1727
+ const unwrapped = unwrapIdentityExpression(expr);
1728
+ if (ts5.isIdentifier(unwrapped)) {
1729
+ const existing = bindingForVariable(unwrapped.text);
1730
+ if (!existing) return;
1731
+ out.push({
1732
+ ...existing,
1733
+ variableName: targetName,
1734
+ sourceLine: lineOf4(sourceFileAst, node),
1735
+ helperChain: [
1736
+ ...existing.helperChain ?? [],
1737
+ { callerVariable: targetName, targetVariable: targetName, sourceVariable: unwrapped.text, aliasKind: "array-destructuring", arrayIndex, promiseAll, arrayContainer: promiseAll ? "Promise.all" : "array_literal" }
1738
+ ]
1739
+ });
1740
+ }
1741
+ }
1742
+ async function recordArrayDestructuredVariable(decl) {
1743
+ if (!ts5.isArrayBindingPattern(decl.name) || !decl.initializer) return;
1744
+ const container = arrayElementsFromExpression(decl.initializer);
1745
+ if (!container) return;
1746
+ for (let index = 0; index < decl.name.elements.length; index += 1) {
1747
+ const el = decl.name.elements[index];
1748
+ if (!el || ts5.isOmittedExpression(el) || ts5.isBindingElement(el) && el.dotDotDotToken) continue;
1749
+ if (!ts5.isBindingElement(el) || !ts5.isIdentifier(el.name)) continue;
1750
+ const source = container.elements[index];
1751
+ if (!source || ts5.isOmittedExpression(source)) continue;
1752
+ await recordArrayElementBinding(el.name.text, source, decl, index, container.promiseAll);
1753
+ }
1754
+ }
1755
+ async function recordArrayDestructuredAssignment(pattern, expr, node) {
1756
+ const container = arrayElementsFromExpression(expr);
1757
+ if (!container) return;
1758
+ for (let index = 0; index < pattern.elements.length; index += 1) {
1759
+ const el = pattern.elements[index];
1760
+ if (!el || ts5.isOmittedExpression(el) || ts5.isSpreadElement(el) || !ts5.isIdentifier(el)) continue;
1761
+ const source = container.elements[index];
1762
+ if (!source || ts5.isOmittedExpression(source)) continue;
1763
+ await recordArrayElementBinding(el.text, source, node, index, container.promiseAll);
1764
+ }
1765
+ }
1685
1766
  const events = [];
1686
1767
  function collectEvents(node) {
1687
1768
  if (ts5.isVariableDeclaration(node)) events.push({ pos: node.getStart(sourceFileAst), node });
@@ -1695,6 +1776,7 @@ async function parseServiceBindings(repoPath, filePath) {
1695
1776
  if (ts5.isVariableDeclaration(event.node)) {
1696
1777
  const decl = event.node;
1697
1778
  await recordDestructuredHelper(decl);
1779
+ await recordArrayDestructuredVariable(decl);
1698
1780
  recordDestructuredClassHelper(decl);
1699
1781
  await recordVariable(decl);
1700
1782
  recordIdentityAlias(decl);
@@ -1716,6 +1798,8 @@ async function parseServiceBindings(repoPath, filePath) {
1716
1798
  const left = ts5.isParenthesizedExpression(assignment.left) ? assignment.left.expression : assignment.left;
1717
1799
  if (ts5.isObjectLiteralExpression(left))
1718
1800
  await recordDestructuredAssignment(left, assignment.right, assignment);
1801
+ if (ts5.isArrayLiteralExpression(left))
1802
+ await recordArrayDestructuredAssignment(left, assignment.right, assignment);
1719
1803
  }
1720
1804
  return out;
1721
1805
  }
@@ -2974,4 +3058,4 @@ export {
2974
3058
  linkWorkspace,
2975
3059
  trace
2976
3060
  };
2977
- //# sourceMappingURL=chunk-R47GA5VW.js.map
3061
+ //# sourceMappingURL=chunk-2UOIY2NI.js.map