MCPcopy Index your code
hub / github.com/simstudioai/sim / evaluateOutputCondition

Function evaluateOutputCondition

apps/sim/lib/workflows/blocks/block-outputs.ts:55–97  ·  view source on GitHub ↗

* Evaluates an output condition against subBlock values. * Returns true if the condition is met and the output should be shown.

(
  condition: OutputCondition,
  subBlocks: Record<string, SubBlockWithValue> | undefined
)

Source from the content-addressed store, hash-verified

53 * Returns true if the condition is met and the output should be shown.
54 */
55function evaluateOutputCondition(
56 condition: OutputCondition,
57 subBlocks: Record<string, SubBlockWithValue> | undefined
58): boolean {
59 if (!subBlocks) return false
60
61 const fieldValue = subBlocks[condition.field]?.value
62
63 let matches: boolean
64 if (Array.isArray(condition.value)) {
65 // For array conditions, check if fieldValue is a valid primitive and included
66 matches = isConditionPrimitive(fieldValue) && condition.value.includes(fieldValue)
67 } else {
68 matches = fieldValue === condition.value
69 }
70
71 if (condition.not) {
72 matches = !matches
73 }
74
75 if (condition.and) {
76 const andFieldValue = subBlocks[condition.and.field]?.value
77 let andMatches: boolean
78
79 if (Array.isArray(condition.and.value)) {
80 const primitiveMatch =
81 isConditionPrimitive(andFieldValue) && condition.and.value.includes(andFieldValue)
82 const undefinedMatch = andFieldValue === undefined && condition.and.value.includes(undefined)
83 const nullMatch = andFieldValue === null && condition.and.value.includes(null)
84 andMatches = primitiveMatch || undefinedMatch || nullMatch
85 } else {
86 andMatches = andFieldValue === condition.and.value
87 }
88
89 if (condition.and.not) {
90 andMatches = !andMatches
91 }
92
93 matches = matches && andMatches
94 }
95
96 return matches
97}
98
99/**
100 * Filters outputs based on their conditions and hiddenFromDisplay flag.

Callers 1

filterOutputsByConditionFunction · 0.85

Calls 1

isConditionPrimitiveFunction · 0.85

Tested by

no test coverage detected