All files / src/shared/lib/scriptDataTable types.ts

100% Statements 8/8
90.48% Branches 19/21
100% Functions 4/4
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 4966x                               66x 12x                 27x         66x 11x                 19x              
import {
  ConstScriptValue,
  isConstScriptValue,
} from "shared/lib/scriptValue/types";
 
export type ScriptDataTableRow = {
  label?: string;
  values: (ConstScriptValue | undefined)[];
};
 
export type ScriptDataTable = {
  label?: string;
  variables: string[];
  rows: ScriptDataTableRow[];
};
 
const isScriptDataTableRow = (obj: unknown): obj is ScriptDataTableRow => {
  return (
    typeof obj === "object" &&
    obj !== null &&
    (!("label" in obj) ||
      typeof (obj as { label: unknown }).label === "string" ||
      typeof (obj as { label: unknown }).label === "undefined") &&
    "values" in obj &&
    Array.isArray((obj as { values: unknown }).values) &&
    (obj as { values: unknown[] }).values.every(
      (v: unknown) => isConstScriptValue(v) || v === undefined,
    )
  );
};
 
export const isScriptDataTable = (obj: unknown): obj is ScriptDataTable => {
  return (
    typeof obj === "object" &&
    obj !== null &&
    (!("label" in obj) ||
      typeof (obj as { label: unknown }).label === "string" ||
      typeof (obj as { label: unknown }).label === "undefined") &&
    "variables" in obj &&
    Array.isArray((obj as { variables: unknown }).variables) &&
    (obj as { variables: unknown[] }).variables.every(
      (v: unknown) => typeof v === "string",
    ) &&
    "rows" in obj &&
    Array.isArray((obj as { rows: unknown }).rows) &&
    (obj as { rows: unknown[] }).rows.every(isScriptDataTableRow)
  );
};