parseResponse method ✓ 91.7%

Last updated: 2026-03-03T11:04:37.495Z

Metrics

LOC: 28 Complexity: 12 Params: 1 Coverage: 91.7% (11/12 lines, 10x executed)

Signature

parseResponse(raw: string): : FormContextOutput | null

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'parseResponse' has cyclomatic complexity 12 (max 10)

Source Code

  parseResponse(raw: string): FormContextOutput | null {
    if (!raw || raw.trim().length === 0) return null;

    // Extract first JSON object from the response (model may add extra text)
    const jsonMatch = raw.match(/\{[\s\S]*\}/);
    if (!jsonMatch) return null;

    try {
      const parsed: unknown = JSON.parse(jsonMatch[0]);
      if (
        typeof parsed !== "object" ||
        parsed === null ||
        Array.isArray(parsed)
      ) {
        return null;
      }

      // Validate all values are strings
      const result: FormContextOutput = {};
      for (const [key, val] of Object.entries(parsed)) {
        result[key] = typeof val === "string" ? val : String(val ?? "");
      }

      return Object.keys(result).length > 0 ? result : null;
    } catch {
      return null;
    }
  },

No outgoing dependencies.

No incoming dependencies.