import type { NodeDef } from '../../NodeRegistry'; import { asNumber } from '../../values'; import { bool, num } from '../shared'; const OPERATORS: Record boolean> = { '==': (a, b) => a === b, '!=': (a, b) => a !== b, '<': (a, b) => a < b, '<=': (a, b) => a <= b, '>': (a, b) => a > b, '>=': (a, b) => a >= b, }; export const Compare: NodeDef = { type: 'Compare', label: 'Compare', category: 'data', description: 'Compares two numbers.', inputs: [num('a'), num('b')], outputs: [bool('result')], params: [ { key: 'op', label: 'Operator', kind: 'enum', default: '<', options: Object.keys(OPERATORS).map((op) => ({ value: op, label: op })), }, ], run: (_ctx, inputs, params) => { // The fallback matches the param's declared default, so a node with no setting behaves // like a freshly created one. const compare = OPERATORS[String(params.op)] ?? OPERATORS['<']!; return { outputs: { result: compare(asNumber(inputs.a), asNumber(inputs.b)) } }; }, };