import * as selectively from "selectively" export interface Fraudio { score: number recommendation: "green" | "yellow" | "red" id: string notes: string transaction: string } export namespace Fraudio { export function is(value: Fraudio | any): value is Fraudio { return ( value && typeof value == "object" && typeof value.score == "number" && ["green", "yellow", "red"].includes(value.recommendation) && typeof value.id == "string" && typeof value.notes == "string" && typeof value.transaction == "string" ) } export function from(value: Record): Fraudio | undefined { const result: any = { score: +value.Score, recommendation: value.Recommendation, id: value.Fraudio_Transaction_ID, notes: value.Notes, transaction: value.Transaction_ID, } return is(result) ? result : undefined } export const template = new selectively.Type.Object({ score: new selectively.Type.Number(), recommendation: new selectively.Type.Union(["green", "yellow", "red"].map(r => new selectively.Type.String(r))), id: new selectively.Type.String(), notes: new selectively.Type.String(), transaction: new selectively.Type.String(), }) }