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

Function convertCondition

packages/graph/src/astToSteps.ts:2338–2465  ·  view source on GitHub ↗

* Convert AST condition to Step condition format. * @param condition - The AST condition to convert * @param useDirectPropertyAccess - If true, use direct property access (e.g., for shortestPath target conditions) * instead of propertyRef (which requires variable

(
  condition: Condition,
  useDirectPropertyAccess: boolean = false,
)

Source from the content-addressed store, hash-verified

2336 * instead of propertyRef (which requires variable bindings)
2337 */
2338function convertCondition(
2339 condition: Condition,
2340 useDirectPropertyAccess: boolean = false,
2341): StepCondition {
2342 switch (condition.type) {
2343 case "PropertyCondition": {
2344 const propCondition = condition as PropertyCondition;
2345 // Convert the condition value - handle variable and property references
2346 const conditionValue = convertConditionValue(propCondition.value);
2347
2348 // When useDirectPropertyAccess is true (e.g., shortestPath target conditions),
2349 // use simple property access that evaluates against the current vertex
2350 if (useDirectPropertyAccess) {
2351 return [propCondition.operator, propCondition.property, conditionValue] as StepCondition;
2352 }
2353
2354 // Use ExpressionCondition with propertyRef to properly resolve the variable
2355 // This ensures the condition looks up the variable from the path bindings
2356 // rather than assuming the current element
2357 return [
2358 "expr",
2359 propCondition.operator as BinaryOperator,
2360 {
2361 type: "propertyRef",
2362 variable: propCondition.variable,
2363 property: propCondition.property,
2364 },
2365 conditionValue,
2366 ] as StepCondition;
2367 }
2368
2369 case "ExistsCondition": {
2370 const existsCondition = condition as ExistsCondition;
2371 return ["exists", existsCondition.property] as StepCondition;
2372 }
2373
2374 case "AndCondition": {
2375 const andCondition = condition as AndCondition;
2376 return [
2377 "and",
2378 convertCondition(andCondition.left, useDirectPropertyAccess),
2379 convertCondition(andCondition.right, useDirectPropertyAccess),
2380 ] as StepCondition;
2381 }
2382
2383 case "OrCondition": {
2384 const orCondition = condition as OrCondition;
2385 return [
2386 "or",
2387 convertCondition(orCondition.left, useDirectPropertyAccess),
2388 convertCondition(orCondition.right, useDirectPropertyAccess),
2389 ] as StepCondition;
2390 }
2391
2392 case "XorCondition": {
2393 const xorCondition = condition as XorCondition;
2394 return [
2395 "xor",

Callers 6

convertWithClauseFunction · 0.85
convertPatternFunction · 0.85
convertMultiPatternFunction · 0.85
convertConditionValueFunction · 0.85

Calls 2

convertConditionValueFunction · 0.85
convertLabelExpressionFunction · 0.85

Tested by

no test coverage detected