All files / src/clarity/clarity-value cv-to-json.ts

100% Statements 8/8
100% Branches 2/2
100% Functions 1/1
100% Lines 8/8

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 4021x 21x 21x                                               21x     23x     1x   1x   21x      
import { cvToValue } from './cv-to-value';
import { ClarityType } from '../common/constants';
import { getCVTypeString } from './get-cv-type-string';
import { ClarityValue } from './types';
import { ResponseErrorCV, ResponseOkCV } from '../types/responseCV';
 
export interface CvToJsonResponseErr {
  type: string;
  value: any;
  success: false;
}
 
export interface CvToJsonResponseOk {
  type: string;
  value: any;
  success: true;
}
 
export interface CvToJsonCvObject {
  type: string;
  value: any;
}
 
export function cvToJSON(val: ResponseOkCV): CvToJsonResponseOk;
export function cvToJSON(val: ResponseErrorCV): CvToJsonResponseErr;
export function cvToJSON(val: ClarityValue): CvToJsonCvObject;
export function cvToJSON(
  val: ClarityValue
): CvToJsonResponseErr | CvToJsonResponseOk | CvToJsonCvObject {
  const value = cvToValue(val, true);
  switch (val.type) {
    case ClarityType.ResponseErr:
      return { type: getCVTypeString(val), value, success: false };
    case ClarityType.ResponseOk:
      return { type: getCVTypeString(val), value, success: true };
    default:
      return { type: getCVTypeString(val), value };
  }
}