import { Email, Name, Phone, Result, UniqueID } from ".."; import { UndefinedOr } from "../../../utilities"; export const ensureIdIsValid = (value: string) => UniqueID.create(value, { generateOnEmpty: false }); export const ensureNameIsValid = ( value: UndefinedOr, label: string = "name", ) => { const valueOrError = Name.create(value, { label, }); return valueOrError.isSuccess ? Result.ok(valueOrError.object) : Result.fail(valueOrError.error); }; export const ensureEmailIsValid = ( value: UndefinedOr, label: string = "email", ) => { const valueOrError = Email.create(value, { label, }); return valueOrError.isSuccess ? Result.ok(valueOrError.object) : Result.fail(valueOrError.error); }; export const ensurePhoneIsValid = ( value: UndefinedOr, label: string = "phone", ) => { const valueOrError = Phone.create(value, { label }); return valueOrError.isSuccess ? Result.ok(valueOrError.object) : Result.fail(valueOrError.error); };