MCPcopy Create free account
hub / github.com/codemix/graph / extractConditionsForVariable

Function extractConditionsForVariable

packages/graph/src/astToSteps.ts:1291–1363  ·  view source on GitHub ↗

* Extract conditions that specifically reference a given variable.

(
  condition: Condition,
  variable: string,
)

Source from the content-addressed store, hash-verified

1289 * Extract conditions that specifically reference a given variable.
1290 */
1291function extractConditionsForVariable(
1292 condition: Condition,
1293 variable: string,
1294): Condition | undefined {
1295 if (
1296 condition.type === "AndCondition" ||
1297 condition.type === "OrCondition" ||
1298 condition.type === "XorCondition"
1299 ) {
1300 const leftExtracted = extractConditionsForVariable(
1301 (condition as AndCondition | OrCondition | XorCondition).left,
1302 variable,
1303 );
1304 const rightExtracted = extractConditionsForVariable(
1305 (condition as AndCondition | OrCondition | XorCondition).right,
1306 variable,
1307 );
1308
1309 const parts = [leftExtracted, rightExtracted].filter((c): c is Condition => c !== undefined);
1310
1311 if (parts.length === 0) return undefined;
1312 if (parts.length === 1) return parts[0];
1313 if (condition.type === "AndCondition") {
1314 return {
1315 type: "AndCondition",
1316 left: parts[0]!,
1317 right: parts[1]!,
1318 } as AndCondition;
1319 } else if (condition.type === "OrCondition") {
1320 return {
1321 type: "OrCondition",
1322 left: parts[0]!,
1323 right: parts[1]!,
1324 } as OrCondition;
1325 } else {
1326 return {
1327 type: "XorCondition",
1328 left: parts[0]!,
1329 right: parts[1]!,
1330 } as XorCondition;
1331 }
1332 }
1333
1334 // For simple conditions, check if they reference the target variable
1335 if (
1336 condition.type === "PropertyCondition" ||
1337 condition.type === "ExistsCondition" ||
1338 condition.type === "InCondition" ||
1339 condition.type === "IsNullCondition" ||
1340 condition.type === "RegexCondition" ||
1341 condition.type === "StringPredicateCondition"
1342 ) {
1343 const condVar = (
1344 condition as
1345 | PropertyCondition
1346 | ExistsCondition
1347 | InCondition
1348 | IsNullCondition

Callers 1

Calls 1

filterMethod · 0.80

Tested by

no test coverage detected