UNPKG

@schorts/shared-kernel

Version:

A modular, type-safe foundation for building expressive, maintainable applications. This package provides core abstractions for domain modeling, HTTP integration, authentication, state management, and more — designed to be framework-agnostic and highly ex

28 lines (22 loc) 711 B
import { ValueObject } from "./value-object"; export abstract class EnumValue<Allowed extends readonly (string | null)[]> implements ValueObject { readonly valueType = 'Enum'; readonly allowedValues: Allowed; readonly value: Allowed[number]; constructor(allowedValues: Allowed, value: Allowed[number]) { this.allowedValues = allowedValues; this.value = value; } get isValid(): boolean { return this.allowedValues.includes(this.value); } equals(valueObject: unknown): boolean { return ( valueObject instanceof EnumValue && this.isValid && valueObject.isValid && this.value === valueObject.value ); } abstract readonly attributeName: string; }