UNPKG

@cheetah.js/orm

Version:
96 lines (95 loc) 2.84 kB
type VoExtended<T, Vo> = Vo extends ValueObject<T, Vo> ? Vo : ValueObject<T, Vo>; type DatabaseValues = { max?: number; min?: number; precision?: number; scale?: number; }; export declare abstract class ValueObject<T, Vo> { /** * Validates the value of the Value Object. * It is abstract so that each Value Object can implement its own validation. * It is protected from being called directly. * * @param value * @protected */ protected abstract validate(value: T): boolean; /** * The maximum length of the Value Object. * It value is optional and will be used in database if this Value Object is used as a column. * If the value is string, it will be the maximum number of characters. * If the value is number, it will be the maximum number. */ protected max?: number; /** * The minimum length of the Value Object. * It value is optional. * If the value is string, it will be the minimum number of characters. * If the value is number, it will be the minimum number. */ protected min?: number; /** * The precision of the Value Object. * It value is optional and will be used in database if this Value Object is used as a column. * It is the number of digits in a number. */ protected precision?: number; /** * The scale of the Value Object. * It value is optional and will be used in database if this Value Object is used as a column. * It is the number of digits to the right of the decimal point in a number. */ protected scale?: number; /** * Valor do Value Object. * É privado para não ser alterado diretamente. * O valor também é imutável. * * @private */ private value; constructor(value: T, skipValidation?: boolean); /** * Creates a Value Object instance from a value. * * @example * Email.from('test@test.com'); * * @param value */ static from<T, Vo>(this: new (value: T) => VoExtended<T, Vo>, value: T): VoExtended<T, Vo>; /** * Returns the scalar value of the Value Object. * */ getValue(): T; /** * Compares the value of the Value Object with another Value Object. * * @param vo */ equals(vo: ValueObject<T, Vo>): boolean; /** * Returns the database settings of the Value Object. * * @returns */ getDatabaseValues(): DatabaseValues; /** * Sets the value of the Value Object. * * @param value * @private */ private setValue; /** * Validates the value of the Value Object. * It is private so that it can only be called by the constructor. * * @param value * @returns */ private validateDatabase; } export {};