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

Function evalCond

apps/sim/lib/webhooks/deploy.ts:169–202  ·  view source on GitHub ↗
(
    cond: {
      field: string
      value: string | number | boolean | Array<string | number | boolean>
      not?: boolean
      and?: {
        field: string
        value: string | number | boolean | Array<string | number | boolean> | undefined
        not?: boolean
      }
    },
    values: Record<string, { value?: unknown }>
  )

Source from the content-addressed store, hash-verified

167 if (typeof config.required === 'boolean') return config.required
168
169 const evalCond = (
170 cond: {
171 field: string
172 value: string | number | boolean | Array<string | number | boolean>
173 not?: boolean
174 and?: {
175 field: string
176 value: string | number | boolean | Array<string | number | boolean> | undefined
177 not?: boolean
178 }
179 },
180 values: Record<string, { value?: unknown }>
181 ): boolean => {
182 const fieldValue = values[cond.field]?.value
183 const condValue = cond.value
184
185 let match = Array.isArray(condValue)
186 ? condValue.includes(fieldValue as string | number | boolean)
187 : fieldValue === condValue
188
189 if (cond.not) match = !match
190
191 if (cond.and) {
192 const andFieldValue = values[cond.and.field]?.value
193 const andCondValue = cond.and.value
194 let andMatch = Array.isArray(andCondValue)
195 ? (andCondValue || []).includes(andFieldValue as string | number | boolean)
196 : andFieldValue === andCondValue
197 if (cond.and.not) andMatch = !andMatch
198 match = match && andMatch
199 }
200
201 return match
202 }
203
204 const condition = typeof config.required === 'function' ? config.required() : config.required
205 return evalCond(condition, subBlockValues)

Callers 1

isFieldRequiredFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected