Skip to content

Commit 8afc3f7

Browse files
Copilothotlong
andcommitted
refactor: address code review feedback - extract getValueType helper, simplify string comparison switch
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 573401a commit 8afc3f7

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

  • packages/services/service-automation/src

packages/services/service-automation/src/engine.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,15 @@ export class AutomationEngine implements IAutomationService {
392392
}
393393
}
394394

395+
/**
396+
* Get the runtime type name of a value for schema validation.
397+
*/
398+
private getValueType(value: unknown): string {
399+
if (Array.isArray(value)) return 'array';
400+
if (typeof value === 'object' && value !== null) return 'object';
401+
return typeof value;
402+
}
403+
395404
/**
396405
* Validate node input schemas before execution.
397406
* Checks that node config matches declared inputSchema if present.
@@ -407,9 +416,7 @@ export class AutomationEngine implements IAutomationService {
407416
}
408417
const value = (node.config as Record<string, unknown>)[paramName];
409418
if (value !== undefined) {
410-
const actualType = Array.isArray(value) ? 'array'
411-
: typeof value === 'object' && value !== null ? 'object'
412-
: typeof value;
419+
const actualType = this.getValueType(value);
413420
if (actualType !== paramDef.type) {
414421
throw new Error(
415422
`Node '${node.id}' parameter '${paramName}' expected type '${paramDef.type}' but got '${actualType}'`,
@@ -659,7 +666,11 @@ export class AutomationEngine implements IAutomationService {
659666
switch (op) {
660667
case '==': case '===': return left === right;
661668
case '!=': case '!==': return left !== right;
662-
default: return left > right ? op === '>' || op === '>=' : left < right ? op === '<' || op === '<=' : op === '>=' || op === '<=';
669+
case '>': return left > right;
670+
case '<': return left < right;
671+
case '>=': return left >= right;
672+
case '<=': return left <= right;
673+
default: return false;
663674
}
664675
}
665676

0 commit comments

Comments
 (0)