convertSteps function exported

Last updated: 2026-03-05T10:53:28.863Z

Metrics

LOC: 74 Complexity: 23 Params: 1

Signature

convertSteps(recorded: RecordedStep[]): : FlowStep[]

Summary

Convert standalone RecordedStep[] into FlowStep[]. Useful when you only have steps without a full session.

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'convertSteps' has cyclomatic complexity 23 (max 10)

Source Code

export function convertSteps(recorded: RecordedStep[]): FlowStep[] {
  const result: FlowStep[] = [];
  let prevTimestamp: number | null = null;

  for (const rec of recorded) {
    const action = mapActionType(rec.type);
    if (!action) continue;

    const flowStep: FlowStep = {
      id: nextStepId(),
      action,
      label: rec.label,
    };

    // Selector
    if (rec.selector) {
      flowStep.selector = rec.selector;
    }
    if (rec.smartSelectors?.length) {
      flowStep.smartSelectors = rec.smartSelectors;
    }

    // Value source for fill steps
    if (action === "fill" && rec.value != null) {
      const fieldType = isValidFieldType(rec.fieldType) ? rec.fieldType : null;
      flowStep.valueSource = mapValueToSource(rec.value, fieldType);
    }

    // Navigation URL
    if (action === "navigate" && rec.url) {
      flowStep.url = rec.url;
    }

    // Select
    if (action === "select" && rec.value != null) {
      flowStep.selectText = rec.value;
    }

    // Key press
    if (action === "press-key" && rec.key) {
      flowStep.key = rec.key;
    }

    // Wait timeout
    if (action === "wait") {
      flowStep.waitTimeout = rec.waitTimeout ?? 10_000;
    }

    // Scroll
    if (action === "scroll" && rec.scrollPosition) {
      flowStep.scrollPosition = rec.scrollPosition;
    }

    // Assert
    if (action === "assert") {
      flowStep.assertion = mapAssertion(rec);
    }

    // Timing delta from previous step
    if (prevTimestamp !== null && rec.timestamp > 0) {
      const delta = rec.timestamp - prevTimestamp;
      if (delta > 0) {
        flowStep.delayBefore = delta;
      }
    }
    if (rec.timestamp > 0) {
      prevTimestamp = rec.timestamp;
    }

    result.push(flowStep);
  }

  return result;
}

Dependencies (Outgoing)

graph LR convertSteps["convertSteps"] mapActionType["mapActionType"] nextStepId["nextStepId"] isValidFieldType["isValidFieldType"] mapValueToSource["mapValueToSource"] mapAssertion["mapAssertion"] convertSteps -->|calls| mapActionType convertSteps -->|calls| nextStepId convertSteps -->|calls| isValidFieldType convertSteps -->|calls| mapValueToSource convertSteps -->|calls| mapAssertion style convertSteps fill:#dbeafe,stroke:#2563eb,stroke-width:2px click convertSteps "9420198414a645f6.html" click mapActionType "13e0c919e8b27254.html" click nextStepId "60b2ffaea2f7c890.html" click isValidFieldType "a95b73445027ba7e.html" click mapValueToSource "095f23c1feace9fe.html" click mapAssertion "a4c2e86108e15f2e.html"
TargetType
mapActionType calls
nextStepId calls
isValidFieldType calls
mapValueToSource calls
mapAssertion calls

Impact (Incoming)

graph LR convertSteps["convertSteps"] convertRecordingToFlow["convertRecordingToFlow"] makeSession["makeSession"] convertRecordingToFlow -->|calls| convertSteps makeSession -->|uses| convertSteps style convertSteps fill:#dbeafe,stroke:#2563eb,stroke-width:2px click convertSteps "9420198414a645f6.html" click convertRecordingToFlow "757a5ffbc62eadcc.html" click makeSession "5a9b47b0cc679d94.html"
SourceType
convertRecordingToFlow calls
makeSession uses