@haskou/value-objects 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/errors/BaseError.d.ts +8 -0
- package/dist/src/errors/BaseError.d.ts.map +1 -0
- package/dist/src/errors/BaseError.js +22 -0
- package/dist/src/errors/BaseError.js.map +1 -0
- package/dist/src/errors/DomainError.d.ts +7 -0
- package/dist/src/errors/DomainError.d.ts.map +1 -0
- package/dist/src/errors/DomainError.js +15 -0
- package/dist/src/errors/DomainError.js.map +1 -0
- package/dist/src/errors/InvalidColorError.d.ts +5 -0
- package/dist/src/errors/InvalidColorError.d.ts.map +1 -0
- package/dist/src/errors/InvalidColorError.js +11 -0
- package/dist/src/errors/InvalidColorError.js.map +1 -0
- package/dist/src/errors/InvalidDayError.d.ts +5 -0
- package/dist/src/errors/InvalidDayError.d.ts.map +1 -0
- package/dist/src/errors/InvalidDayError.js +11 -0
- package/dist/src/errors/InvalidDayError.js.map +1 -0
- package/dist/src/errors/InvalidDayFormatError.d.ts +5 -0
- package/dist/src/errors/InvalidDayFormatError.d.ts.map +1 -0
- package/dist/src/errors/InvalidDayFormatError.js +11 -0
- package/dist/src/errors/InvalidDayFormatError.js.map +1 -0
- package/dist/src/errors/InvalidEmailError.d.ts +5 -0
- package/dist/src/errors/InvalidEmailError.d.ts.map +1 -0
- package/dist/src/errors/InvalidEmailError.js +11 -0
- package/dist/src/errors/InvalidEmailError.js.map +1 -0
- package/dist/src/errors/InvalidFormatError.d.ts +5 -0
- package/dist/src/errors/InvalidFormatError.d.ts.map +1 -0
- package/dist/src/errors/InvalidFormatError.js +11 -0
- package/dist/src/errors/InvalidFormatError.js.map +1 -0
- package/dist/src/errors/InvalidHashError.d.ts +5 -0
- package/dist/src/errors/InvalidHashError.d.ts.map +1 -0
- package/dist/src/errors/InvalidHashError.js +11 -0
- package/dist/src/errors/InvalidHashError.js.map +1 -0
- package/dist/src/errors/InvalidHourError.d.ts +5 -0
- package/dist/src/errors/InvalidHourError.d.ts.map +1 -0
- package/dist/src/errors/InvalidHourError.js +11 -0
- package/dist/src/errors/InvalidHourError.js.map +1 -0
- package/dist/src/errors/InvalidIntegerError.d.ts +5 -0
- package/dist/src/errors/InvalidIntegerError.d.ts.map +1 -0
- package/dist/src/errors/InvalidIntegerError.js +11 -0
- package/dist/src/errors/InvalidIntegerError.js.map +1 -0
- package/dist/src/errors/InvalidLatitudeError.d.ts +5 -0
- package/dist/src/errors/InvalidLatitudeError.d.ts.map +1 -0
- package/dist/src/errors/InvalidLatitudeError.js +11 -0
- package/dist/src/errors/InvalidLatitudeError.js.map +1 -0
- package/dist/src/errors/InvalidLengthError.d.ts +5 -0
- package/dist/src/errors/InvalidLengthError.d.ts.map +1 -0
- package/dist/src/errors/InvalidLengthError.js +11 -0
- package/dist/src/errors/InvalidLengthError.js.map +1 -0
- package/dist/src/errors/InvalidLongitudeError.d.ts +5 -0
- package/dist/src/errors/InvalidLongitudeError.d.ts.map +1 -0
- package/dist/src/errors/InvalidLongitudeError.js +11 -0
- package/dist/src/errors/InvalidLongitudeError.js.map +1 -0
- package/dist/src/errors/InvalidMinutesError.d.ts +5 -0
- package/dist/src/errors/InvalidMinutesError.d.ts.map +1 -0
- package/dist/src/errors/InvalidMinutesError.js +11 -0
- package/dist/src/errors/InvalidMinutesError.js.map +1 -0
- package/dist/src/errors/InvalidNumberError.d.ts +5 -0
- package/dist/src/errors/InvalidNumberError.d.ts.map +1 -0
- package/dist/src/errors/InvalidNumberError.js +11 -0
- package/dist/src/errors/InvalidNumberError.js.map +1 -0
- package/dist/src/errors/InvalidPositiveNumberError.d.ts +5 -0
- package/dist/src/errors/InvalidPositiveNumberError.d.ts.map +1 -0
- package/dist/src/errors/InvalidPositiveNumberError.js +11 -0
- package/dist/src/errors/InvalidPositiveNumberError.js.map +1 -0
- package/dist/src/errors/InvalidStringLengthError.d.ts +5 -0
- package/dist/src/errors/InvalidStringLengthError.d.ts.map +1 -0
- package/dist/src/errors/InvalidStringLengthError.js +11 -0
- package/dist/src/errors/InvalidStringLengthError.js.map +1 -0
- package/dist/src/errors/InvalidTimestampIntervalError.d.ts +6 -0
- package/dist/src/errors/InvalidTimestampIntervalError.d.ts.map +1 -0
- package/dist/src/errors/InvalidTimestampIntervalError.js +11 -0
- package/dist/src/errors/InvalidTimestampIntervalError.js.map +1 -0
- package/dist/src/errors/InvalidValueError.d.ts +5 -0
- package/dist/src/errors/InvalidValueError.d.ts.map +1 -0
- package/dist/src/errors/InvalidValueError.js +11 -0
- package/dist/src/errors/InvalidValueError.js.map +1 -0
- package/dist/src/errors/NullObjectError.d.ts +5 -0
- package/dist/src/errors/NullObjectError.d.ts.map +1 -0
- package/dist/src/errors/NullObjectError.js +12 -0
- package/dist/src/errors/NullObjectError.js.map +1 -0
- package/dist/src/errors/ValueNotInEnumError.d.ts +5 -0
- package/dist/src/errors/ValueNotInEnumError.d.ts.map +1 -0
- package/dist/src/errors/ValueNotInEnumError.js +11 -0
- package/dist/src/errors/ValueNotInEnumError.js.map +1 -0
- package/{src/errors/index.ts → dist/src/errors/index.d.ts} +1 -0
- package/dist/src/errors/index.d.ts.map +1 -0
- package/dist/src/errors/index.js +24 -0
- package/dist/src/errors/index.js.map +1 -0
- package/{src/index.ts → dist/src/index.d.ts} +1 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/interfaces/PrimitiveOf.d.ts +5 -0
- package/dist/src/interfaces/PrimitiveOf.d.ts.map +1 -0
- package/dist/src/interfaces/PrimitiveOf.js +3 -0
- package/dist/src/interfaces/PrimitiveOf.js.map +1 -0
- package/dist/src/interfaces/index.d.ts +2 -0
- package/dist/src/interfaces/index.d.ts.map +1 -0
- package/dist/src/interfaces/index.js +5 -0
- package/dist/src/interfaces/index.js.map +1 -0
- package/dist/src/patterns/Assert.d.ts +5 -0
- package/dist/src/patterns/Assert.d.ts.map +1 -0
- package/dist/src/patterns/Assert.js +11 -0
- package/dist/src/patterns/Assert.js.map +1 -0
- package/dist/src/patterns/index.d.ts +2 -0
- package/dist/src/patterns/index.d.ts.map +1 -0
- package/dist/src/patterns/index.js +5 -0
- package/dist/src/patterns/index.js.map +1 -0
- package/{src/types/Nullish.ts → dist/src/types/Nullish.d.ts} +1 -0
- package/dist/src/types/Nullish.d.ts.map +1 -0
- package/dist/src/types/Nullish.js +3 -0
- package/dist/src/types/Nullish.js.map +1 -0
- package/{src/types/Primitive.ts → dist/src/types/Primitive.d.ts} +1 -0
- package/dist/src/types/Primitive.d.ts.map +1 -0
- package/dist/src/types/Primitive.js +3 -0
- package/dist/src/types/Primitive.js.map +1 -0
- package/{src/types/index.ts → dist/src/types/index.d.ts} +1 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +6 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/value-objects/Color.d.ts +19 -0
- package/dist/src/value-objects/Color.d.ts.map +1 -0
- package/dist/src/value-objects/Color.js +37 -0
- package/dist/src/value-objects/Color.js.map +1 -0
- package/dist/src/value-objects/Email.d.ts +6 -0
- package/dist/src/value-objects/Email.d.ts.map +1 -0
- package/dist/src/value-objects/Email.js +21 -0
- package/dist/src/value-objects/Email.js.map +1 -0
- package/dist/src/value-objects/Enum.d.ts +9 -0
- package/dist/src/value-objects/Enum.d.ts.map +1 -0
- package/dist/src/value-objects/Enum.js +24 -0
- package/dist/src/value-objects/Enum.js.map +1 -0
- package/dist/src/value-objects/Integer.d.ts +6 -0
- package/dist/src/value-objects/Integer.d.ts.map +1 -0
- package/dist/src/value-objects/Integer.js +21 -0
- package/dist/src/value-objects/Integer.js.map +1 -0
- package/dist/src/value-objects/NullObject.d.ts +8 -0
- package/dist/src/value-objects/NullObject.d.ts.map +1 -0
- package/dist/src/value-objects/NullObject.js +43 -0
- package/dist/src/value-objects/NullObject.js.map +1 -0
- package/dist/src/value-objects/NumberValueObject.d.ts +15 -0
- package/dist/src/value-objects/NumberValueObject.d.ts.map +1 -0
- package/dist/src/value-objects/NumberValueObject.js +48 -0
- package/dist/src/value-objects/NumberValueObject.js.map +1 -0
- package/dist/src/value-objects/PositiveNumber.d.ts +6 -0
- package/dist/src/value-objects/PositiveNumber.d.ts.map +1 -0
- package/dist/src/value-objects/PositiveNumber.js +21 -0
- package/dist/src/value-objects/PositiveNumber.js.map +1 -0
- package/dist/src/value-objects/StringValueObject.d.ts +7 -0
- package/dist/src/value-objects/StringValueObject.d.ts.map +1 -0
- package/dist/src/value-objects/StringValueObject.js +24 -0
- package/dist/src/value-objects/StringValueObject.js.map +1 -0
- package/dist/src/value-objects/ValueObject.d.ts +12 -0
- package/dist/src/value-objects/ValueObject.d.ts.map +1 -0
- package/dist/src/value-objects/ValueObject.js +33 -0
- package/dist/src/value-objects/ValueObject.js.map +1 -0
- package/dist/src/value-objects/coordinates/Coordinates.d.ts +12 -0
- package/dist/src/value-objects/coordinates/Coordinates.d.ts.map +1 -0
- package/dist/src/value-objects/coordinates/Coordinates.js +28 -0
- package/dist/src/value-objects/coordinates/Coordinates.js.map +1 -0
- package/dist/src/value-objects/coordinates/Latitude.d.ts +8 -0
- package/dist/src/value-objects/coordinates/Latitude.d.ts.map +1 -0
- package/dist/src/value-objects/coordinates/Latitude.js +21 -0
- package/dist/src/value-objects/coordinates/Latitude.js.map +1 -0
- package/dist/src/value-objects/coordinates/Longitude.d.ts +8 -0
- package/dist/src/value-objects/coordinates/Longitude.d.ts.map +1 -0
- package/dist/src/value-objects/coordinates/Longitude.js +21 -0
- package/dist/src/value-objects/coordinates/Longitude.js.map +1 -0
- package/{src/value-objects/coordinates/index.ts → dist/src/value-objects/coordinates/index.d.ts} +1 -0
- package/dist/src/value-objects/coordinates/index.d.ts.map +1 -0
- package/dist/src/value-objects/coordinates/index.js +7 -0
- package/dist/src/value-objects/coordinates/index.js.map +1 -0
- package/dist/src/value-objects/hashes/Hash.d.ts +7 -0
- package/dist/src/value-objects/hashes/Hash.d.ts.map +1 -0
- package/dist/src/value-objects/hashes/Hash.js +19 -0
- package/dist/src/value-objects/hashes/Hash.js.map +1 -0
- package/dist/src/value-objects/hashes/MD5Hash.d.ts +8 -0
- package/dist/src/value-objects/hashes/MD5Hash.d.ts.map +1 -0
- package/dist/src/value-objects/hashes/MD5Hash.js +26 -0
- package/dist/src/value-objects/hashes/MD5Hash.js.map +1 -0
- package/dist/src/value-objects/hashes/SHA256Hash.d.ts +9 -0
- package/dist/src/value-objects/hashes/SHA256Hash.d.ts.map +1 -0
- package/dist/src/value-objects/hashes/SHA256Hash.js +29 -0
- package/dist/src/value-objects/hashes/SHA256Hash.js.map +1 -0
- package/dist/src/value-objects/hashes/SHA512Hash.d.ts +9 -0
- package/dist/src/value-objects/hashes/SHA512Hash.d.ts.map +1 -0
- package/dist/src/value-objects/hashes/SHA512Hash.js +29 -0
- package/dist/src/value-objects/hashes/SHA512Hash.js.map +1 -0
- package/{src/value-objects/hashes/index.ts → dist/src/value-objects/hashes/index.d.ts} +1 -0
- package/dist/src/value-objects/hashes/index.d.ts.map +1 -0
- package/dist/src/value-objects/hashes/index.js +8 -0
- package/dist/src/value-objects/hashes/index.js.map +1 -0
- package/dist/src/value-objects/ids/ShortId.d.ts +10 -0
- package/dist/src/value-objects/ids/ShortId.d.ts.map +1 -0
- package/dist/src/value-objects/ids/ShortId.js +30 -0
- package/dist/src/value-objects/ids/ShortId.js.map +1 -0
- package/dist/src/value-objects/ids/UUID.d.ts +10 -0
- package/dist/src/value-objects/ids/UUID.d.ts.map +1 -0
- package/dist/src/value-objects/ids/UUID.js +29 -0
- package/dist/src/value-objects/ids/UUID.js.map +1 -0
- package/{src/value-objects/ids/index.ts → dist/src/value-objects/ids/index.d.ts} +1 -0
- package/dist/src/value-objects/ids/index.d.ts.map +1 -0
- package/dist/src/value-objects/ids/index.js +6 -0
- package/dist/src/value-objects/ids/index.js.map +1 -0
- package/{src/value-objects/index.ts → dist/src/value-objects/index.d.ts} +1 -0
- package/dist/src/value-objects/index.d.ts.map +1 -0
- package/dist/src/value-objects/index.js +16 -0
- package/dist/src/value-objects/index.js.map +1 -0
- package/dist/src/value-objects/time/CalendarDay.d.ts +25 -0
- package/dist/src/value-objects/time/CalendarDay.d.ts.map +1 -0
- package/dist/src/value-objects/time/CalendarDay.js +74 -0
- package/dist/src/value-objects/time/CalendarDay.js.map +1 -0
- package/dist/src/value-objects/time/Day.d.ts +7 -0
- package/dist/src/value-objects/time/Day.d.ts.map +1 -0
- package/dist/src/value-objects/time/Day.js +18 -0
- package/dist/src/value-objects/time/Day.js.map +1 -0
- package/dist/src/value-objects/time/DayOfWeek.d.ts +34 -0
- package/dist/src/value-objects/time/DayOfWeek.d.ts.map +1 -0
- package/dist/src/value-objects/time/DayOfWeek.js +52 -0
- package/dist/src/value-objects/time/DayOfWeek.js.map +1 -0
- package/dist/src/value-objects/time/Duration.d.ts +23 -0
- package/dist/src/value-objects/time/Duration.d.ts.map +1 -0
- package/dist/src/value-objects/time/Duration.js +79 -0
- package/dist/src/value-objects/time/Duration.js.map +1 -0
- package/dist/src/value-objects/time/Hour.d.ts +15 -0
- package/dist/src/value-objects/time/Hour.d.ts.map +1 -0
- package/dist/src/value-objects/time/Hour.js +81 -0
- package/dist/src/value-objects/time/Hour.js.map +1 -0
- package/dist/src/value-objects/time/Month.d.ts +18 -0
- package/dist/src/value-objects/time/Month.d.ts.map +1 -0
- package/dist/src/value-objects/time/Month.js +41 -0
- package/dist/src/value-objects/time/Month.js.map +1 -0
- package/dist/src/value-objects/time/MonthOfYear.d.ts +17 -0
- package/dist/src/value-objects/time/MonthOfYear.d.ts.map +1 -0
- package/dist/src/value-objects/time/MonthOfYear.js +45 -0
- package/dist/src/value-objects/time/MonthOfYear.js.map +1 -0
- package/dist/src/value-objects/time/Timestamp.d.ts +51 -0
- package/dist/src/value-objects/time/Timestamp.d.ts.map +1 -0
- package/dist/src/value-objects/time/Timestamp.js +156 -0
- package/dist/src/value-objects/time/Timestamp.js.map +1 -0
- package/dist/src/value-objects/time/TimestampInterval.d.ts +26 -0
- package/dist/src/value-objects/time/TimestampInterval.d.ts.map +1 -0
- package/dist/src/value-objects/time/TimestampInterval.js +88 -0
- package/dist/src/value-objects/time/TimestampInterval.js.map +1 -0
- package/dist/src/value-objects/time/Year.d.ts +10 -0
- package/dist/src/value-objects/time/Year.d.ts.map +1 -0
- package/dist/src/value-objects/time/Year.js +26 -0
- package/dist/src/value-objects/time/Year.js.map +1 -0
- package/{src/value-objects/time/index.ts → dist/src/value-objects/time/index.d.ts} +1 -0
- package/dist/src/value-objects/time/index.d.ts.map +1 -0
- package/dist/src/value-objects/time/index.js +14 -0
- package/dist/src/value-objects/time/index.js.map +1 -0
- package/dist/tests/errors/BaseError.spec.d.ts +2 -0
- package/dist/tests/errors/BaseError.spec.d.ts.map +1 -0
- package/dist/tests/errors/BaseError.spec.js +54 -0
- package/dist/tests/errors/BaseError.spec.js.map +1 -0
- package/dist/tests/errors/DomainError.spec.d.ts +2 -0
- package/dist/tests/errors/DomainError.spec.d.ts.map +1 -0
- package/dist/tests/errors/DomainError.spec.js +47 -0
- package/dist/tests/errors/DomainError.spec.js.map +1 -0
- package/dist/tests/patterns/Assert.spec.d.ts +2 -0
- package/dist/tests/patterns/Assert.spec.d.ts.map +1 -0
- package/dist/tests/patterns/Assert.spec.js +27 -0
- package/dist/tests/patterns/Assert.spec.js.map +1 -0
- package/dist/tests/setup.jest.d.ts +2 -0
- package/dist/tests/setup.jest.d.ts.map +1 -0
- package/dist/tests/setup.jest.js +6 -0
- package/dist/tests/setup.jest.js.map +1 -0
- package/dist/tests/value-objects/Color.spec.d.ts +2 -0
- package/dist/tests/value-objects/Color.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/Color.spec.js +171 -0
- package/dist/tests/value-objects/Color.spec.js.map +1 -0
- package/dist/tests/value-objects/Email.spec.d.ts +2 -0
- package/dist/tests/value-objects/Email.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/Email.spec.js +117 -0
- package/dist/tests/value-objects/Email.spec.js.map +1 -0
- package/dist/tests/value-objects/Enum.spec.d.ts +2 -0
- package/dist/tests/value-objects/Enum.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/Enum.spec.js +233 -0
- package/dist/tests/value-objects/Enum.spec.js.map +1 -0
- package/dist/tests/value-objects/Integer.spec.d.ts +2 -0
- package/dist/tests/value-objects/Integer.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/Integer.spec.js +31 -0
- package/dist/tests/value-objects/Integer.spec.js.map +1 -0
- package/dist/tests/value-objects/NullObject.spec.d.ts +2 -0
- package/dist/tests/value-objects/NullObject.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/NullObject.spec.js +48 -0
- package/dist/tests/value-objects/NullObject.spec.js.map +1 -0
- package/dist/tests/value-objects/NumberValueObject.spec.d.ts +2 -0
- package/dist/tests/value-objects/NumberValueObject.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/NumberValueObject.spec.js +333 -0
- package/dist/tests/value-objects/NumberValueObject.spec.js.map +1 -0
- package/dist/tests/value-objects/PositiveNumber.spec.d.ts +2 -0
- package/dist/tests/value-objects/PositiveNumber.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/PositiveNumber.spec.js +209 -0
- package/dist/tests/value-objects/PositiveNumber.spec.js.map +1 -0
- package/dist/tests/value-objects/StringValueObject.spec.d.ts +2 -0
- package/dist/tests/value-objects/StringValueObject.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/StringValueObject.spec.js +104 -0
- package/dist/tests/value-objects/StringValueObject.spec.js.map +1 -0
- package/dist/tests/value-objects/coordinates/Coordinates.spec.d.ts +2 -0
- package/dist/tests/value-objects/coordinates/Coordinates.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/coordinates/Coordinates.spec.js +76 -0
- package/dist/tests/value-objects/coordinates/Coordinates.spec.js.map +1 -0
- package/dist/tests/value-objects/coordinates/Latitude.spec.d.ts +2 -0
- package/dist/tests/value-objects/coordinates/Latitude.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/coordinates/Latitude.spec.js +23 -0
- package/dist/tests/value-objects/coordinates/Latitude.spec.js.map +1 -0
- package/dist/tests/value-objects/coordinates/Longitude.spec.d.ts +2 -0
- package/dist/tests/value-objects/coordinates/Longitude.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/coordinates/Longitude.spec.js +23 -0
- package/dist/tests/value-objects/coordinates/Longitude.spec.js.map +1 -0
- package/dist/tests/value-objects/hashes/Hashes.spec.d.ts +2 -0
- package/dist/tests/value-objects/hashes/Hashes.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/hashes/Hashes.spec.js +107 -0
- package/dist/tests/value-objects/hashes/Hashes.spec.js.map +1 -0
- package/dist/tests/value-objects/hashes/MD5Hash.spec.d.ts +2 -0
- package/dist/tests/value-objects/hashes/MD5Hash.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/hashes/MD5Hash.spec.js +147 -0
- package/dist/tests/value-objects/hashes/MD5Hash.spec.js.map +1 -0
- package/dist/tests/value-objects/hashes/SHA256Hash.spec.d.ts +2 -0
- package/dist/tests/value-objects/hashes/SHA256Hash.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/hashes/SHA256Hash.spec.js +147 -0
- package/dist/tests/value-objects/hashes/SHA256Hash.spec.js.map +1 -0
- package/dist/tests/value-objects/hashes/SHA512Hash.spec.d.ts +2 -0
- package/dist/tests/value-objects/hashes/SHA512Hash.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/hashes/SHA512Hash.spec.js +147 -0
- package/dist/tests/value-objects/hashes/SHA512Hash.spec.js.map +1 -0
- package/dist/tests/value-objects/ids/ShortId.spec.d.ts +2 -0
- package/dist/tests/value-objects/ids/ShortId.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/ids/ShortId.spec.js +30 -0
- package/dist/tests/value-objects/ids/ShortId.spec.js.map +1 -0
- package/dist/tests/value-objects/ids/UUID.spec.d.ts +2 -0
- package/dist/tests/value-objects/ids/UUID.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/ids/UUID.spec.js +30 -0
- package/dist/tests/value-objects/ids/UUID.spec.js.map +1 -0
- package/dist/tests/value-objects/time/CalendarDay.spec.d.ts +2 -0
- package/dist/tests/value-objects/time/CalendarDay.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/time/CalendarDay.spec.js +149 -0
- package/dist/tests/value-objects/time/CalendarDay.spec.js.map +1 -0
- package/dist/tests/value-objects/time/Day.spec.d.ts +2 -0
- package/dist/tests/value-objects/time/Day.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/time/Day.spec.js +28 -0
- package/dist/tests/value-objects/time/Day.spec.js.map +1 -0
- package/dist/tests/value-objects/time/DayOfWeek.spec.d.ts +2 -0
- package/dist/tests/value-objects/time/DayOfWeek.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/time/DayOfWeek.spec.js +44 -0
- package/dist/tests/value-objects/time/DayOfWeek.spec.js.map +1 -0
- package/dist/tests/value-objects/time/Duration.spec.d.ts +2 -0
- package/dist/tests/value-objects/time/Duration.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/time/Duration.spec.js +255 -0
- package/dist/tests/value-objects/time/Duration.spec.js.map +1 -0
- package/dist/tests/value-objects/time/Hour.spec.d.ts +2 -0
- package/dist/tests/value-objects/time/Hour.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/time/Hour.spec.js +168 -0
- package/dist/tests/value-objects/time/Hour.spec.js.map +1 -0
- package/dist/tests/value-objects/time/MonthOfYear.spec.d.ts +2 -0
- package/dist/tests/value-objects/time/MonthOfYear.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/time/MonthOfYear.spec.js +93 -0
- package/dist/tests/value-objects/time/MonthOfYear.spec.js.map +1 -0
- package/dist/tests/value-objects/time/Timestamp.spec.d.ts +2 -0
- package/dist/tests/value-objects/time/Timestamp.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/time/Timestamp.spec.js +391 -0
- package/dist/tests/value-objects/time/Timestamp.spec.js.map +1 -0
- package/dist/tests/value-objects/time/TimestampInterval.spec.d.ts +2 -0
- package/dist/tests/value-objects/time/TimestampInterval.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/time/TimestampInterval.spec.js +270 -0
- package/dist/tests/value-objects/time/TimestampInterval.spec.js.map +1 -0
- package/dist/tests/value-objects/time/Year.spec.d.ts +2 -0
- package/dist/tests/value-objects/time/Year.spec.d.ts.map +1 -0
- package/dist/tests/value-objects/time/Year.spec.js +41 -0
- package/dist/tests/value-objects/time/Year.spec.js.map +1 -0
- package/package.json +9 -5
- package/.editorconfig +0 -15
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -218
- package/.prettierrc.json +0 -13
- package/TECHNICAL_DOCUMENTATION.md +0 -1257
- package/jest.config.ts +0 -30
- package/src/errors/BaseError.ts +0 -20
- package/src/errors/DomainError.ts +0 -12
- package/src/errors/InvalidColorError.ts +0 -7
- package/src/errors/InvalidDayError.ts +0 -7
- package/src/errors/InvalidDayFormatError.ts +0 -7
- package/src/errors/InvalidEmailError.ts +0 -7
- package/src/errors/InvalidFormatError.ts +0 -7
- package/src/errors/InvalidHashError.ts +0 -7
- package/src/errors/InvalidHourError.ts +0 -7
- package/src/errors/InvalidIntegerError.ts +0 -7
- package/src/errors/InvalidLatitudeError.ts +0 -7
- package/src/errors/InvalidLengthError.ts +0 -9
- package/src/errors/InvalidLongitudeError.ts +0 -7
- package/src/errors/InvalidMinutesError.ts +0 -7
- package/src/errors/InvalidNumberError.ts +0 -7
- package/src/errors/InvalidPositiveNumberError.ts +0 -7
- package/src/errors/InvalidStringLengthError.ts +0 -9
- package/src/errors/InvalidTimestampIntervalError.ts +0 -10
- package/src/errors/InvalidValueError.ts +0 -7
- package/src/errors/NullObjectError.ts +0 -8
- package/src/errors/ValueNotInEnumError.ts +0 -9
- package/src/interfaces/PrimitiveOf.ts +0 -5
- package/src/interfaces/index.ts +0 -1
- package/src/patterns/Assert.ts +0 -15
- package/src/patterns/index.ts +0 -1
- package/src/value-objects/Color.ts +0 -39
- package/src/value-objects/Email.ts +0 -23
- package/src/value-objects/Enum.ts +0 -31
- package/src/value-objects/Integer.ts +0 -22
- package/src/value-objects/NullObject.ts +0 -60
- package/src/value-objects/NumberValueObject.ts +0 -56
- package/src/value-objects/PositiveNumber.ts +0 -20
- package/src/value-objects/StringValueObject.ts +0 -27
- package/src/value-objects/ValueObject.ts +0 -39
- package/src/value-objects/coordinates/Coordinates.ts +0 -30
- package/src/value-objects/coordinates/Latitude.ts +0 -22
- package/src/value-objects/coordinates/Longitude.ts +0 -25
- package/src/value-objects/hashes/Hash.ts +0 -19
- package/src/value-objects/hashes/MD5Hash.ts +0 -32
- package/src/value-objects/hashes/SHA256Hash.ts +0 -38
- package/src/value-objects/hashes/SHA512Hash.ts +0 -38
- package/src/value-objects/ids/ShortId.ts +0 -34
- package/src/value-objects/ids/UUID.ts +0 -34
- package/src/value-objects/time/CalendarDay.ts +0 -91
- package/src/value-objects/time/Day.ts +0 -17
- package/src/value-objects/time/DayOfWeek.ts +0 -60
- package/src/value-objects/time/Duration.ts +0 -142
- package/src/value-objects/time/Hour.ts +0 -105
- package/src/value-objects/time/Month.ts +0 -39
- package/src/value-objects/time/MonthOfYear.ts +0 -52
- package/src/value-objects/time/Timestamp.ts +0 -208
- package/src/value-objects/time/TimestampInterval.ts +0 -122
- package/src/value-objects/time/Year.ts +0 -27
- package/tests/errors/BaseError.spec.ts +0 -63
- package/tests/errors/DomainError.spec.ts +0 -52
- package/tests/patterns/Assert.spec.ts +0 -29
- package/tests/setup.jest.ts +0 -2
- package/tests/value-objects/Color.spec.ts +0 -214
- package/tests/value-objects/Email.spec.ts +0 -141
- package/tests/value-objects/Enum.spec.ts +0 -293
- package/tests/value-objects/Integer.spec.ts +0 -38
- package/tests/value-objects/NullObject.spec.ts +0 -55
- package/tests/value-objects/NumberValueObject.spec.ts +0 -446
- package/tests/value-objects/PositiveNumber.spec.ts +0 -274
- package/tests/value-objects/StringValueObject.spec.ts +0 -135
- package/tests/value-objects/coordinates/Coordinates.spec.ts +0 -90
- package/tests/value-objects/coordinates/Latitude.spec.ts +0 -24
- package/tests/value-objects/coordinates/Longitude.spec.ts +0 -24
- package/tests/value-objects/hashes/Hashes.spec.ts +0 -139
- package/tests/value-objects/hashes/MD5Hash.spec.ts +0 -187
- package/tests/value-objects/hashes/SHA256Hash.spec.ts +0 -220
- package/tests/value-objects/hashes/SHA512Hash.spec.ts +0 -220
- package/tests/value-objects/ids/ShortId.spec.ts +0 -34
- package/tests/value-objects/ids/UUID.spec.ts +0 -37
- package/tests/value-objects/time/CalendarDay.spec.ts +0 -182
- package/tests/value-objects/time/Day.spec.ts +0 -29
- package/tests/value-objects/time/DayOfWeek.spec.ts +0 -71
- package/tests/value-objects/time/Duration.spec.ts +0 -278
- package/tests/value-objects/time/Hour.spec.ts +0 -197
- package/tests/value-objects/time/MonthOfYear.spec.ts +0 -111
- package/tests/value-objects/time/Timestamp.spec.ts +0 -497
- package/tests/value-objects/time/TimestampInterval.spec.ts +0 -383
- package/tests/value-objects/time/Year.spec.ts +0 -48
- package/tsconfig.jest.json +0 -33
- package/tsconfig.json +0 -42
|
@@ -1,1257 +0,0 @@
|
|
|
1
|
-
# Technical Documentation
|
|
2
|
-
|
|
3
|
-
Comprehensive technical documentation for the Value Objects library.
|
|
4
|
-
|
|
5
|
-
## 📋 Table of Contents
|
|
6
|
-
|
|
7
|
-
- [API Documentation](#api-documentation)
|
|
8
|
-
- [Base Classes](#base-classes)
|
|
9
|
-
- [String Value Objects](#string-value-objects)
|
|
10
|
-
- [Number Value Objects](#number-value-objects)
|
|
11
|
-
- [Integer Value Objects](#integer-value-objects)
|
|
12
|
-
- [PositiveNumber Value Objects](#positivenumber-value-objects)
|
|
13
|
-
- [Year Value Objects](#year-value-objects)
|
|
14
|
-
- [Color Value Objects](#color-value-objects)
|
|
15
|
-
- [Email Value Objects](#email-value-objects)
|
|
16
|
-
- [ID Value Objects](#id-value-objects)
|
|
17
|
-
- [Hour Value Objects](#hour-value-objects)
|
|
18
|
-
- [Time Value Objects](#time-value-objects)
|
|
19
|
-
- [Enum Value Objects](#enum-value-objects)
|
|
20
|
-
- [Error Handling](#error-handling)
|
|
21
|
-
- [Design Principles](#design-principles)
|
|
22
|
-
|
|
23
|
-
## 📚 API Documentation
|
|
24
|
-
|
|
25
|
-
### Base Classes
|
|
26
|
-
|
|
27
|
-
#### ValueObject\<T>
|
|
28
|
-
|
|
29
|
-
The abstract base class for all value objects.
|
|
30
|
-
|
|
31
|
-
```typescript
|
|
32
|
-
abstract class ValueObject<T extends Primitive = Primitive> {
|
|
33
|
-
constructor(protected readonly value: T);
|
|
34
|
-
|
|
35
|
-
public isEqual(other: unknown): boolean;
|
|
36
|
-
public valueOf(): T;
|
|
37
|
-
public toString(): string;
|
|
38
|
-
protected clone(value: T): this;
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
**Methods:**
|
|
43
|
-
- `valueOf()`: Returns the primitive value
|
|
44
|
-
- `toString()`: Returns string representation
|
|
45
|
-
- `isEqual(other)`: Compares equality with another value
|
|
46
|
-
- `clone(value)`: Creates a new instance with the given value
|
|
47
|
-
|
|
48
|
-
### String Value Objects
|
|
49
|
-
|
|
50
|
-
#### StringValueObject
|
|
51
|
-
|
|
52
|
-
Represents immutable string values with length validation.
|
|
53
|
-
|
|
54
|
-
```typescript
|
|
55
|
-
class StringValueObject extends ValueObject<string> {
|
|
56
|
-
constructor(value: string | StringValueObject, maxLength?: number);
|
|
57
|
-
|
|
58
|
-
public toString(): string;
|
|
59
|
-
public isEmpty(): boolean;
|
|
60
|
-
}
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
**Example:**
|
|
64
|
-
```typescript
|
|
65
|
-
// Basic usage
|
|
66
|
-
const username = new StringValueObject('alice123');
|
|
67
|
-
|
|
68
|
-
// With length limit
|
|
69
|
-
const shortCode = new StringValueObject('ABC', 3);
|
|
70
|
-
|
|
71
|
-
// From another StringValueObject
|
|
72
|
-
const copy = new StringValueObject(username);
|
|
73
|
-
|
|
74
|
-
// Validation
|
|
75
|
-
try {
|
|
76
|
-
new StringValueObject('a'.repeat(600)); // Throws InvalidStringLengthError
|
|
77
|
-
} catch (error) {
|
|
78
|
-
console.error('String too long');
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### Number Value Objects
|
|
83
|
-
|
|
84
|
-
#### NumberValueObject
|
|
85
|
-
|
|
86
|
-
Represents immutable numeric values with arithmetic operations.
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
class NumberValueObject extends ValueObject<number> {
|
|
90
|
-
constructor(value: number | NumberValueObject);
|
|
91
|
-
|
|
92
|
-
// Comparison methods
|
|
93
|
-
public isZero(): boolean;
|
|
94
|
-
public isGreaterThan(other: number | NumberValueObject): boolean;
|
|
95
|
-
public isGreaterOrEqualThan(other: number | NumberValueObject): boolean;
|
|
96
|
-
public isLessThan(other: number | NumberValueObject): boolean;
|
|
97
|
-
public isLessOrEqualThan(other: number | NumberValueObject): boolean;
|
|
98
|
-
|
|
99
|
-
// Arithmetic operations
|
|
100
|
-
public add(other: number | NumberValueObject): NumberValueObject;
|
|
101
|
-
public subtract(other: number | NumberValueObject): NumberValueObject;
|
|
102
|
-
public multiply(other: number | NumberValueObject): NumberValueObject;
|
|
103
|
-
public divide(other: number | NumberValueObject): NumberValueObject;
|
|
104
|
-
}
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
**Example:**
|
|
108
|
-
```typescript
|
|
109
|
-
const a = new NumberValueObject(10);
|
|
110
|
-
const b = new NumberValueObject(5);
|
|
111
|
-
|
|
112
|
-
// Arithmetic operations (immutable)
|
|
113
|
-
const sum = a.add(b); // 15
|
|
114
|
-
const diff = a.subtract(b); // 5
|
|
115
|
-
const prod = a.multiply(b); // 50
|
|
116
|
-
const quot = a.divide(b); // 2
|
|
117
|
-
|
|
118
|
-
// Comparisons
|
|
119
|
-
console.log(a.isGreaterThan(b)); // true
|
|
120
|
-
console.log(b.isLessThan(a)); // true
|
|
121
|
-
console.log(a.isEqual(10)); // true
|
|
122
|
-
|
|
123
|
-
// Works with primitive numbers
|
|
124
|
-
const result = a.add(3); // 13
|
|
125
|
-
|
|
126
|
-
// Original values remain unchanged
|
|
127
|
-
console.log(a.valueOf()); // 10 (unchanged)
|
|
128
|
-
console.log(b.valueOf()); // 5 (unchanged)
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
### Integer Value Objects
|
|
132
|
-
|
|
133
|
-
#### Integer
|
|
134
|
-
|
|
135
|
-
Represents immutable integer values (whole numbers) with all arithmetic operations inherited from NumberValueObject.
|
|
136
|
-
|
|
137
|
-
```typescript
|
|
138
|
-
class Integer extends NumberValueObject {
|
|
139
|
-
constructor(value: number | NumberValueObject);
|
|
140
|
-
|
|
141
|
-
// Inherits all NumberValueObject methods:
|
|
142
|
-
// Comparison methods
|
|
143
|
-
public isZero(): boolean;
|
|
144
|
-
public isGreaterThan(other: number | NumberValueObject): boolean;
|
|
145
|
-
public isGreaterOrEqualThan(other: number | NumberValueObject): boolean;
|
|
146
|
-
public isLessThan(other: number | NumberValueObject): boolean;
|
|
147
|
-
public isLessOrEqualThan(other: number | NumberValueObject): boolean;
|
|
148
|
-
|
|
149
|
-
// Arithmetic operations
|
|
150
|
-
public add(other: number | NumberValueObject): NumberValueObject;
|
|
151
|
-
public subtract(other: number | NumberValueObject): NumberValueObject;
|
|
152
|
-
public multiply(other: number | NumberValueObject): NumberValueObject;
|
|
153
|
-
public divide(other: number | NumberValueObject): NumberValueObject;
|
|
154
|
-
}
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
**Example:**
|
|
158
|
-
```typescript
|
|
159
|
-
// Valid integers
|
|
160
|
-
const count = new Integer(42);
|
|
161
|
-
const negative = new Integer(-10);
|
|
162
|
-
const zero = new Integer(0);
|
|
163
|
-
|
|
164
|
-
// Arithmetic operations (inherited from NumberValueObject)
|
|
165
|
-
const sum = count.add(negative); // 32
|
|
166
|
-
const product = count.multiply(2); // 84
|
|
167
|
-
const quotient = count.divide(2); // 21
|
|
168
|
-
|
|
169
|
-
// Comparisons
|
|
170
|
-
console.log(count.isGreaterThan(zero)); // true
|
|
171
|
-
console.log(negative.isLessThan(zero)); // true
|
|
172
|
-
console.log(zero.isZero()); // true
|
|
173
|
-
|
|
174
|
-
// From another NumberValueObject
|
|
175
|
-
const numberValue = new NumberValueObject(15);
|
|
176
|
-
const integerFromNumber = new Integer(numberValue);
|
|
177
|
-
console.log(integerFromNumber.valueOf()); // 15
|
|
178
|
-
|
|
179
|
-
// String representation
|
|
180
|
-
console.log(count.toString()); // '42'
|
|
181
|
-
console.log(negative.valueOf()); // -10
|
|
182
|
-
|
|
183
|
-
// Note: Arithmetic operations return NumberValueObject, not Integer
|
|
184
|
-
// This is because operations might result in non-integer values
|
|
185
|
-
const division = count.divide(3); // Returns NumberValueObject with value 14
|
|
186
|
-
|
|
187
|
-
// Validation
|
|
188
|
-
try {
|
|
189
|
-
new Integer(42.5); // Throws InvalidIntegerError
|
|
190
|
-
new Integer(3.14159); // Throws InvalidIntegerError
|
|
191
|
-
new Integer(Infinity); // Throws InvalidIntegerError
|
|
192
|
-
new Integer(-Infinity); // Throws InvalidIntegerError
|
|
193
|
-
new Integer(NaN); // Throws InvalidNumberError
|
|
194
|
-
} catch (error) {
|
|
195
|
-
console.error('Value must be a valid integer');
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Works with large integers
|
|
199
|
-
const large = new Integer(1000000); // Valid
|
|
200
|
-
const veryLarge = new Integer(-999999); // Valid
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
### PositiveNumber Value Objects
|
|
204
|
-
|
|
205
|
-
#### PositiveNumber
|
|
206
|
-
|
|
207
|
-
Represents immutable positive numeric values (greater than 0) with all arithmetic operations inherited from NumberValueObject.
|
|
208
|
-
|
|
209
|
-
```typescript
|
|
210
|
-
class PositiveNumber extends NumberValueObject {
|
|
211
|
-
constructor(value: number | NumberValueObject);
|
|
212
|
-
|
|
213
|
-
// Inherits all NumberValueObject methods:
|
|
214
|
-
// Comparison methods
|
|
215
|
-
public isZero(): boolean; // Always returns false
|
|
216
|
-
public isGreaterThan(other: number | NumberValueObject): boolean;
|
|
217
|
-
public isGreaterOrEqualThan(other: number | NumberValueObject): boolean;
|
|
218
|
-
public isLessThan(other: number | NumberValueObject): boolean;
|
|
219
|
-
public isLessOrEqualThan(other: number | NumberValueObject): boolean;
|
|
220
|
-
|
|
221
|
-
// Arithmetic operations
|
|
222
|
-
public add(other: number | NumberValueObject): NumberValueObject;
|
|
223
|
-
public subtract(other: number | NumberValueObject): NumberValueObject;
|
|
224
|
-
public multiply(other: number | NumberValueObject): NumberValueObject;
|
|
225
|
-
public divide(other: number | NumberValueObject): NumberValueObject;
|
|
226
|
-
}
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
**Example:**
|
|
230
|
-
```typescript
|
|
231
|
-
// Valid positive numbers
|
|
232
|
-
const quantity = new PositiveNumber(5);
|
|
233
|
-
const price = new PositiveNumber(19.99);
|
|
234
|
-
const percentage = new PositiveNumber(0.15);
|
|
235
|
-
|
|
236
|
-
// Arithmetic operations (inherited from NumberValueObject)
|
|
237
|
-
const total = quantity.multiply(price); // 99.95
|
|
238
|
-
const increased = price.add(10); // 29.99
|
|
239
|
-
const half = quantity.divide(2); // 2.5
|
|
240
|
-
|
|
241
|
-
// Comparisons
|
|
242
|
-
console.log(price.isGreaterThan(quantity)); // true
|
|
243
|
-
console.log(quantity.isLessThan(price)); // true
|
|
244
|
-
console.log(quantity.isZero()); // false (always false for PositiveNumber)
|
|
245
|
-
|
|
246
|
-
// From another PositiveNumber
|
|
247
|
-
const copy = new PositiveNumber(quantity);
|
|
248
|
-
console.log(copy.valueOf()); // 5
|
|
249
|
-
|
|
250
|
-
// String representation
|
|
251
|
-
console.log(quantity.toString()); // '5'
|
|
252
|
-
console.log(price.valueOf()); // 19.99
|
|
253
|
-
|
|
254
|
-
// Note: Arithmetic operations return NumberValueObject, not PositiveNumber
|
|
255
|
-
// This is because operations might result in non-positive values
|
|
256
|
-
const result = quantity.subtract(10); // Returns NumberValueObject with value -5
|
|
257
|
-
|
|
258
|
-
// Validation
|
|
259
|
-
try {
|
|
260
|
-
new PositiveNumber(0); // Throws InvalidPositiveNumberError
|
|
261
|
-
new PositiveNumber(-5); // Throws InvalidPositiveNumberError
|
|
262
|
-
new PositiveNumber(-0.1); // Throws InvalidPositiveNumberError
|
|
263
|
-
} catch (error) {
|
|
264
|
-
console.error('Value must be greater than 0');
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// Works with decimals
|
|
268
|
-
const decimal = new PositiveNumber(0.001); // Valid
|
|
269
|
-
const large = new PositiveNumber(1000000); // Valid
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
### Year Value Objects
|
|
273
|
-
|
|
274
|
-
#### Year
|
|
275
|
-
|
|
276
|
-
Represents immutable year values with leap year calculations and date utilities. Inherits all functionality from Integer.
|
|
277
|
-
|
|
278
|
-
```typescript
|
|
279
|
-
class Year extends Integer {
|
|
280
|
-
constructor(value: number | NumberValueObject);
|
|
281
|
-
|
|
282
|
-
// Year-specific methods
|
|
283
|
-
public isLeapYear(): boolean;
|
|
284
|
-
public getNumberOfDays(): number;
|
|
285
|
-
|
|
286
|
-
// Inherits all Integer and NumberValueObject methods:
|
|
287
|
-
// Comparison methods
|
|
288
|
-
public isZero(): boolean;
|
|
289
|
-
public isGreaterThan(other: number | NumberValueObject): boolean;
|
|
290
|
-
public isGreaterOrEqualThan(other: number | NumberValueObject): boolean;
|
|
291
|
-
public isLessThan(other: number | NumberValueObject): boolean;
|
|
292
|
-
public isLessOrEqualThan(other: number | NumberValueObject): boolean;
|
|
293
|
-
|
|
294
|
-
// Arithmetic operations
|
|
295
|
-
public add(other: number | NumberValueObject): NumberValueObject;
|
|
296
|
-
public subtract(other: number | NumberValueObject): NumberValueObject;
|
|
297
|
-
public multiply(other: number | NumberValueObject): NumberValueObject;
|
|
298
|
-
public divide(other: number | NumberValueObject): NumberValueObject;
|
|
299
|
-
}
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
**Example:**
|
|
303
|
-
```typescript
|
|
304
|
-
// Valid years
|
|
305
|
-
const currentYear = new Year(2024);
|
|
306
|
-
const pastYear = new Year(1900);
|
|
307
|
-
const futureYear = new Year(2100);
|
|
308
|
-
const year2000 = new Year(2000);
|
|
309
|
-
|
|
310
|
-
// Leap year calculations
|
|
311
|
-
console.log(currentYear.isLeapYear()); // true (2024 is divisible by 4)
|
|
312
|
-
console.log(pastYear.isLeapYear()); // false (1900 is divisible by 100 but not 400)
|
|
313
|
-
console.log(futureYear.isLeapYear()); // false (2100 is divisible by 100 but not 400)
|
|
314
|
-
console.log(year2000.isLeapYear()); // true (2000 is divisible by 400)
|
|
315
|
-
|
|
316
|
-
// Number of days in year
|
|
317
|
-
console.log(currentYear.getNumberOfDays()); // 366 (leap year)
|
|
318
|
-
console.log(pastYear.getNumberOfDays()); // 365 (regular year)
|
|
319
|
-
console.log(year2000.getNumberOfDays()); // 366 (leap year)
|
|
320
|
-
|
|
321
|
-
// Arithmetic operations (inherited from NumberValueObject)
|
|
322
|
-
const nextYear = currentYear.add(1); // 2025 (as NumberValueObject)
|
|
323
|
-
const decade = currentYear.subtract(10); // 2014 (as NumberValueObject)
|
|
324
|
-
|
|
325
|
-
// Comparisons
|
|
326
|
-
console.log(currentYear.isGreaterThan(pastYear)); // true
|
|
327
|
-
console.log(pastYear.isLessThan(futureYear)); // true
|
|
328
|
-
console.log(currentYear.isEqual(2024)); // true
|
|
329
|
-
|
|
330
|
-
// From another NumberValueObject or Integer
|
|
331
|
-
const yearFromNumber = new NumberValueObject(2023);
|
|
332
|
-
const year = new Year(yearFromNumber);
|
|
333
|
-
console.log(year.valueOf()); // 2023
|
|
334
|
-
console.log(year.isLeapYear()); // false
|
|
335
|
-
|
|
336
|
-
// String representation
|
|
337
|
-
console.log(currentYear.toString()); // '2024'
|
|
338
|
-
console.log(pastYear.valueOf()); // 1900
|
|
339
|
-
|
|
340
|
-
// Common leap year patterns
|
|
341
|
-
const leapYears = [2020, 2024, 2028, 2032].map(y => new Year(y));
|
|
342
|
-
const regularYears = [2021, 2022, 2023, 2025].map(y => new Year(y));
|
|
343
|
-
|
|
344
|
-
leapYears.forEach(year => {
|
|
345
|
-
console.log(`${year.valueOf()}: ${year.getNumberOfDays()} days`); // All show 366
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
regularYears.forEach(year => {
|
|
349
|
-
console.log(`${year.valueOf()}: ${year.getNumberOfDays()} days`); // All show 365
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
// Validation (inherits Integer validation)
|
|
353
|
-
try {
|
|
354
|
-
new Year(2024.5); // Throws InvalidIntegerError
|
|
355
|
-
new Year(NaN); // Throws InvalidNumberError
|
|
356
|
-
new Year(Infinity); // Throws InvalidIntegerError
|
|
357
|
-
} catch (error) {
|
|
358
|
-
console.error('Year must be a valid integer');
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// Works with negative years (BCE)
|
|
362
|
-
const ancientYear = new Year(-500); // 500 BCE
|
|
363
|
-
console.log(ancientYear.valueOf()); // -500
|
|
364
|
-
console.log(ancientYear.isLeapYear()); // false (year -500 is not a leap year)
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
### Color Value Objects
|
|
368
|
-
|
|
369
|
-
#### Color
|
|
370
|
-
|
|
371
|
-
Represents immutable hex color values with predefined colors.
|
|
372
|
-
|
|
373
|
-
```typescript
|
|
374
|
-
class Color extends StringValueObject {
|
|
375
|
-
constructor(value: string | StringValueObject);
|
|
376
|
-
|
|
377
|
-
public isEqual(other: Color): boolean; // Case-insensitive comparison
|
|
378
|
-
|
|
379
|
-
// Predefined static colors
|
|
380
|
-
static readonly RED: Color;
|
|
381
|
-
static readonly GREEN: Color;
|
|
382
|
-
static readonly BLUE: Color;
|
|
383
|
-
static readonly BLACK: Color;
|
|
384
|
-
static readonly WHITE: Color;
|
|
385
|
-
static readonly YELLOW: Color;
|
|
386
|
-
static readonly CYAN: Color;
|
|
387
|
-
static readonly MAGENTA: Color;
|
|
388
|
-
static readonly ORANGE: Color;
|
|
389
|
-
static readonly PURPLE: Color;
|
|
390
|
-
static readonly PINK: Color;
|
|
391
|
-
static readonly BROWN: Color;
|
|
392
|
-
}
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
**Example:**
|
|
396
|
-
```typescript
|
|
397
|
-
// Valid hex colors
|
|
398
|
-
const red = new Color('#FF0000');
|
|
399
|
-
const blue = new Color('#00F');
|
|
400
|
-
const green = Color.GREEN;
|
|
401
|
-
|
|
402
|
-
// Case-insensitive comparison
|
|
403
|
-
const color1 = new Color('#ff0000');
|
|
404
|
-
const color2 = new Color('#FF0000');
|
|
405
|
-
console.log(color1.isEqual(color2)); // true
|
|
406
|
-
|
|
407
|
-
// From StringValueObject
|
|
408
|
-
const colorString = new StringValueObject('#ABCDEF');
|
|
409
|
-
const color = new Color(colorString);
|
|
410
|
-
|
|
411
|
-
// Validation
|
|
412
|
-
try {
|
|
413
|
-
new Color('invalid-color'); // Throws InvalidColorError
|
|
414
|
-
} catch (error) {
|
|
415
|
-
console.error('Invalid hex color format');
|
|
416
|
-
}
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
### Email Value Objects
|
|
420
|
-
|
|
421
|
-
#### Email
|
|
422
|
-
|
|
423
|
-
Represents immutable email addresses with comprehensive validation.
|
|
424
|
-
|
|
425
|
-
```typescript
|
|
426
|
-
class Email extends StringValueObject {
|
|
427
|
-
constructor(value: string | StringValueObject);
|
|
428
|
-
}
|
|
429
|
-
```
|
|
430
|
-
|
|
431
|
-
**Example:**
|
|
432
|
-
```typescript
|
|
433
|
-
// Valid email addresses
|
|
434
|
-
const userEmail = new Email('user@example.com');
|
|
435
|
-
const workEmail = new Email('john.doe@company.org');
|
|
436
|
-
const taggedEmail = new Email('user+newsletter@domain.co.uk');
|
|
437
|
-
|
|
438
|
-
// From StringValueObject
|
|
439
|
-
const emailString = new StringValueObject('admin@system.net');
|
|
440
|
-
const email = new Email(emailString);
|
|
441
|
-
|
|
442
|
-
// String representation
|
|
443
|
-
console.log(userEmail.toString()); // 'user@example.com'
|
|
444
|
-
console.log(userEmail.valueOf()); // 'user@example.com'
|
|
445
|
-
|
|
446
|
-
// Equality comparison
|
|
447
|
-
const email1 = new Email('test@example.com');
|
|
448
|
-
const email2 = new Email('test@example.com');
|
|
449
|
-
console.log(email1.isEqual(email2)); // true
|
|
450
|
-
console.log(email1.isEqual('test@example.com')); // true
|
|
451
|
-
|
|
452
|
-
// Inherits all StringValueObject methods
|
|
453
|
-
console.log(userEmail.isEmpty()); // false
|
|
454
|
-
|
|
455
|
-
// Validation examples
|
|
456
|
-
try {
|
|
457
|
-
new Email('invalid-email'); // Throws InvalidEmailError
|
|
458
|
-
new Email('user@'); // Throws InvalidEmailError
|
|
459
|
-
new Email('user@domain'); // Throws InvalidEmailError
|
|
460
|
-
new Email('user@@domain.com'); // Throws InvalidEmailError
|
|
461
|
-
} catch (error) {
|
|
462
|
-
console.error('Invalid email format');
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
// Supports various valid formats
|
|
466
|
-
const validEmails = [
|
|
467
|
-
'simple@example.com',
|
|
468
|
-
'user.name@domain.org',
|
|
469
|
-
'user+tag@example.co.uk',
|
|
470
|
-
'first.last@subdomain.company.travel',
|
|
471
|
-
'admin123@my-domain.museum'
|
|
472
|
-
];
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
### ID Value Objects
|
|
476
|
-
|
|
477
|
-
#### ShortId
|
|
478
|
-
|
|
479
|
-
Represents immutable MongoDB ObjectId values with automatic generation and validation.
|
|
480
|
-
|
|
481
|
-
```typescript
|
|
482
|
-
class ShortId extends ValueObject<string> {
|
|
483
|
-
public static generate(): ShortId;
|
|
484
|
-
constructor(value: string | StringValueObject);
|
|
485
|
-
}
|
|
486
|
-
```
|
|
487
|
-
|
|
488
|
-
**Example:**
|
|
489
|
-
```typescript
|
|
490
|
-
// Generate a new ObjectId
|
|
491
|
-
const id = ShortId.generate();
|
|
492
|
-
console.log(id.toString()); // '507f1f77bcf86cd799439011' (24-character hex string)
|
|
493
|
-
|
|
494
|
-
// Create from existing ObjectId string
|
|
495
|
-
const existingId = new ShortId('507f1f77bcf86cd799439011');
|
|
496
|
-
|
|
497
|
-
// From StringValueObject
|
|
498
|
-
const idString = new StringValueObject('507f1f77bcf86cd799439011');
|
|
499
|
-
const idFromString = new ShortId(idString);
|
|
500
|
-
|
|
501
|
-
// String representation
|
|
502
|
-
console.log(existingId.toString()); // '507f1f77bcf86cd799439011'
|
|
503
|
-
console.log(existingId.valueOf()); // '507f1f77bcf86cd799439011'
|
|
504
|
-
|
|
505
|
-
// Equality comparison
|
|
506
|
-
const id1 = new ShortId('507f1f77bcf86cd799439011');
|
|
507
|
-
const id2 = new ShortId('507f1f77bcf86cd799439011');
|
|
508
|
-
console.log(id1.isEqual(id2)); // true
|
|
509
|
-
|
|
510
|
-
// Validation
|
|
511
|
-
try {
|
|
512
|
-
new ShortId('invalid-id'); // Throws InvalidFormatError
|
|
513
|
-
new ShortId('short'); // Throws InvalidLengthError
|
|
514
|
-
} catch (error) {
|
|
515
|
-
console.error('Invalid ObjectId format');
|
|
516
|
-
}
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
#### UUID
|
|
520
|
-
|
|
521
|
-
Represents immutable UUID (Universally Unique Identifier) values with automatic generation and validation.
|
|
522
|
-
|
|
523
|
-
```typescript
|
|
524
|
-
class UUID extends ValueObject<string> {
|
|
525
|
-
public static generate(): UUID;
|
|
526
|
-
constructor(value: string | StringValueObject);
|
|
527
|
-
}
|
|
528
|
-
```
|
|
529
|
-
|
|
530
|
-
**Example:**
|
|
531
|
-
```typescript
|
|
532
|
-
// Generate a new UUID v4
|
|
533
|
-
const uuid = UUID.generate();
|
|
534
|
-
console.log(uuid.toString()); // '550e8400-e29b-41d4-a716-446655440000' (36-character string)
|
|
535
|
-
|
|
536
|
-
// Create from existing UUID string
|
|
537
|
-
const existingUuid = new UUID('550e8400-e29b-41d4-a716-446655440000');
|
|
538
|
-
|
|
539
|
-
// From StringValueObject
|
|
540
|
-
const uuidString = new StringValueObject('550e8400-e29b-41d4-a716-446655440000');
|
|
541
|
-
const uuidFromString = new UUID(uuidString);
|
|
542
|
-
|
|
543
|
-
// String representation
|
|
544
|
-
console.log(existingUuid.toString()); // '550e8400-e29b-41d4-a716-446655440000'
|
|
545
|
-
console.log(existingUuid.valueOf()); // '550e8400-e29b-41d4-a716-446655440000'
|
|
546
|
-
|
|
547
|
-
// Equality comparison
|
|
548
|
-
const uuid1 = new UUID('550e8400-e29b-41d4-a716-446655440000');
|
|
549
|
-
const uuid2 = new UUID('550e8400-e29b-41d4-a716-446655440000');
|
|
550
|
-
console.log(uuid1.isEqual(uuid2)); // true
|
|
551
|
-
|
|
552
|
-
// Validation
|
|
553
|
-
try {
|
|
554
|
-
new UUID('invalid-uuid'); // Throws InvalidFormatError
|
|
555
|
-
new UUID('short-uuid'); // Throws InvalidLengthError
|
|
556
|
-
} catch (error) {
|
|
557
|
-
console.error('Invalid UUID format');
|
|
558
|
-
}
|
|
559
|
-
```
|
|
560
|
-
|
|
561
|
-
### Hash Value Objects
|
|
562
|
-
|
|
563
|
-
#### MD5Hash
|
|
564
|
-
Represents immutable MD5 hashes with validation and utility methods.
|
|
565
|
-
|
|
566
|
-
```typescript
|
|
567
|
-
class MD5Hash extends Hash {
|
|
568
|
-
public static isValid(hash: string | StringValueObject): boolean;
|
|
569
|
-
public static from(buffer: Buffer | string | StringValueObject): MD5Hash;
|
|
570
|
-
constructor(source: string | StringValueObject);
|
|
571
|
-
}
|
|
572
|
-
```
|
|
573
|
-
|
|
574
|
-
**Example:**
|
|
575
|
-
```typescript
|
|
576
|
-
// Compute an MD5 hash from a string or buffer
|
|
577
|
-
const md5 = MD5Hash.from('hello');
|
|
578
|
-
console.log(md5.toString()); // '5d41402abc4b2a76b9719d911017c592'
|
|
579
|
-
console.log(md5.toBase64()); // 'XUEQKvLG6avlckeQEAXGSw=='
|
|
580
|
-
|
|
581
|
-
// Create from existing hash string
|
|
582
|
-
const existing = new MD5Hash('5d41402abc4b2a76b9719d911017c592');
|
|
583
|
-
|
|
584
|
-
// Validation
|
|
585
|
-
try {
|
|
586
|
-
new MD5Hash('invalid'); // Throws InvalidHashError
|
|
587
|
-
} catch (err) {
|
|
588
|
-
console.error('Invalid MD5 hash');
|
|
589
|
-
}
|
|
590
|
-
```
|
|
591
|
-
|
|
592
|
-
#### SHA256Hash
|
|
593
|
-
Represents immutable SHA‑256 hashes with validation and utility methods.
|
|
594
|
-
|
|
595
|
-
```typescript
|
|
596
|
-
class SHA256Hash extends ValueObject<string> {
|
|
597
|
-
public static isValid(hash: string | StringValueObject): boolean;
|
|
598
|
-
public static from(buffer: Buffer | string | StringValueObject): SHA256Hash;
|
|
599
|
-
constructor(source: string | StringValueObject);
|
|
600
|
-
}
|
|
601
|
-
```
|
|
602
|
-
|
|
603
|
-
**Example:**
|
|
604
|
-
```typescript
|
|
605
|
-
const sha256 = SHA256Hash.from('hello');
|
|
606
|
-
console.log(sha256.toString().length); // 64
|
|
607
|
-
console.log(sha256.toBase64());
|
|
608
|
-
|
|
609
|
-
try {
|
|
610
|
-
new SHA256Hash('abc'); // Throws InvalidHashError
|
|
611
|
-
} catch (err) {
|
|
612
|
-
console.error('Invalid SHA256 hash');
|
|
613
|
-
}
|
|
614
|
-
```
|
|
615
|
-
|
|
616
|
-
#### SHA512Hash
|
|
617
|
-
Represents immutable SHA‑512 hashes with validation and utility methods.
|
|
618
|
-
|
|
619
|
-
```typescript
|
|
620
|
-
class SHA512Hash extends ValueObject<string> {
|
|
621
|
-
public static isValid(hash: string | StringValueObject): boolean;
|
|
622
|
-
public static from(buffer: Buffer | string | StringValueObject): SHA512Hash;
|
|
623
|
-
constructor(source: string | StringValueObject);
|
|
624
|
-
}
|
|
625
|
-
```
|
|
626
|
-
|
|
627
|
-
**Example:**
|
|
628
|
-
```typescript
|
|
629
|
-
const sha512 = SHA512Hash.from('hello');
|
|
630
|
-
console.log(sha512.toString().length); // 128
|
|
631
|
-
console.log(sha512.toBase64());
|
|
632
|
-
|
|
633
|
-
try {
|
|
634
|
-
new SHA512Hash('abc'); // Throws InvalidHashError
|
|
635
|
-
} catch (err) {
|
|
636
|
-
console.error('Invalid SHA512 hash');
|
|
637
|
-
}
|
|
638
|
-
```
|
|
639
|
-
|
|
640
|
-
### Hour Value Objects
|
|
641
|
-
|
|
642
|
-
#### Hour
|
|
643
|
-
|
|
644
|
-
Represents immutable time values in 24-hour format with time arithmetic operations.
|
|
645
|
-
|
|
646
|
-
```typescript
|
|
647
|
-
class Hour extends StringValueObject {
|
|
648
|
-
constructor(value: string); // "HH:MM" format
|
|
649
|
-
constructor(value: number, minutes?: number); // Separate hours and minutes
|
|
650
|
-
|
|
651
|
-
// Time arithmetic
|
|
652
|
-
public addMinutes(minutes: number): Hour;
|
|
653
|
-
public diffInMinutes(other: Hour): number;
|
|
654
|
-
|
|
655
|
-
// Getters
|
|
656
|
-
public getHours(): number;
|
|
657
|
-
public getMinutes(): number;
|
|
658
|
-
|
|
659
|
-
// Comparisons
|
|
660
|
-
public isGreaterThan(hour: Hour): boolean;
|
|
661
|
-
public isLessThan(hour: Hour): boolean;
|
|
662
|
-
}
|
|
663
|
-
```
|
|
664
|
-
|
|
665
|
-
**Example:**
|
|
666
|
-
```typescript
|
|
667
|
-
// Different constructor options
|
|
668
|
-
const morning = new Hour('09:30'); // String format
|
|
669
|
-
const afternoon = new Hour(14, 45); // Separate values
|
|
670
|
-
const evening = new Hour(20, 0); // 20:00
|
|
671
|
-
|
|
672
|
-
// Time arithmetic
|
|
673
|
-
const laterTime = morning.addMinutes(90); // 11:00
|
|
674
|
-
const duration = morning.diffInMinutes(afternoon); // 315 minutes
|
|
675
|
-
|
|
676
|
-
// Getters
|
|
677
|
-
console.log(morning.getHours()); // 9
|
|
678
|
-
console.log(morning.getMinutes()); // 30
|
|
679
|
-
|
|
680
|
-
// Comparisons
|
|
681
|
-
console.log(afternoon.isGreaterThan(morning)); // true
|
|
682
|
-
console.log(morning.isLessThan(evening)); // true
|
|
683
|
-
|
|
684
|
-
// String representation
|
|
685
|
-
console.log(morning.toString()); // '09:30'
|
|
686
|
-
|
|
687
|
-
// Handles day overflow
|
|
688
|
-
const lateNight = new Hour('23:30');
|
|
689
|
-
const nextDay = lateNight.addMinutes(60); // '00:30' (next day)
|
|
690
|
-
|
|
691
|
-
// Validation
|
|
692
|
-
try {
|
|
693
|
-
new Hour('25:00'); // Throws InvalidHourError
|
|
694
|
-
new Hour(12, 65); // Throws InvalidMinutesError
|
|
695
|
-
} catch (error) {
|
|
696
|
-
console.error('Invalid time format');
|
|
697
|
-
}
|
|
698
|
-
```
|
|
699
|
-
|
|
700
|
-
### Time Value Objects
|
|
701
|
-
|
|
702
|
-
#### CalendarDay
|
|
703
|
-
|
|
704
|
-
Represents immutable calendar day values with date utilities.
|
|
705
|
-
|
|
706
|
-
```typescript
|
|
707
|
-
class CalendarDay {
|
|
708
|
-
constructor(value?: string | Date | number | Timestamp);
|
|
709
|
-
|
|
710
|
-
public static fromTimestamp(timestamp: Timestamp): CalendarDay;
|
|
711
|
-
public static fromString(value: string): CalendarDay;
|
|
712
|
-
|
|
713
|
-
public toString(): string;
|
|
714
|
-
public getDayOfWeek(): DayOfWeek;
|
|
715
|
-
public isBefore(other: CalendarDay): boolean;
|
|
716
|
-
public isAfter(other: CalendarDay): boolean;
|
|
717
|
-
public diffInDays(other: CalendarDay): number;
|
|
718
|
-
}
|
|
719
|
-
```
|
|
720
|
-
|
|
721
|
-
#### Day
|
|
722
|
-
|
|
723
|
-
Represents immutable day values (1-31) with validation.
|
|
724
|
-
|
|
725
|
-
```typescript
|
|
726
|
-
class Day extends Integer {
|
|
727
|
-
constructor(value: number | NumberValueObject);
|
|
728
|
-
}
|
|
729
|
-
```
|
|
730
|
-
|
|
731
|
-
#### DayOfWeek
|
|
732
|
-
|
|
733
|
-
Represents immutable day of week enumeration.
|
|
734
|
-
|
|
735
|
-
```typescript
|
|
736
|
-
enum EDaysOfWeek {
|
|
737
|
-
MONDAY = 'monday',
|
|
738
|
-
TUESDAY = 'tuesday',
|
|
739
|
-
WEDNESDAY = 'wednesday',
|
|
740
|
-
THURSDAY = 'thursday',
|
|
741
|
-
FRIDAY = 'friday',
|
|
742
|
-
SATURDAY = 'saturday',
|
|
743
|
-
SUNDAY = 'sunday',
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
class DayOfWeek extends Enum {
|
|
747
|
-
protected getValues() {
|
|
748
|
-
return Object.values(EDaysOfWeek);
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
```
|
|
752
|
-
|
|
753
|
-
#### Duration
|
|
754
|
-
|
|
755
|
-
Represents immutable duration values in milliseconds.
|
|
756
|
-
|
|
757
|
-
```typescript
|
|
758
|
-
class Duration extends NumberValueObject {
|
|
759
|
-
constructor(value: number | NumberValueObject);
|
|
760
|
-
|
|
761
|
-
public static fromHours(hours: number): Duration;
|
|
762
|
-
public static fromMinutes(minutes: number): Duration;
|
|
763
|
-
public static fromSeconds(seconds: number): Duration;
|
|
764
|
-
|
|
765
|
-
public toHours(): number;
|
|
766
|
-
public toMinutes(): number;
|
|
767
|
-
public toSeconds(): number;
|
|
768
|
-
}
|
|
769
|
-
```
|
|
770
|
-
|
|
771
|
-
#### Month
|
|
772
|
-
|
|
773
|
-
Represents immutable month enumeration (1-12).
|
|
774
|
-
|
|
775
|
-
```typescript
|
|
776
|
-
class Month extends Enum {
|
|
777
|
-
protected getValues() {
|
|
778
|
-
return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
```
|
|
782
|
-
|
|
783
|
-
#### MonthOfYear
|
|
784
|
-
|
|
785
|
-
Represents immutable month/year combination.
|
|
786
|
-
|
|
787
|
-
```typescript
|
|
788
|
-
class MonthOfYear extends ValueObject<string> {
|
|
789
|
-
constructor(month: number | Month, year: number | Year);
|
|
790
|
-
|
|
791
|
-
public static fromTimestamp(timestamp: Timestamp): MonthOfYear;
|
|
792
|
-
public static fromString(value: string): MonthOfYear;
|
|
793
|
-
|
|
794
|
-
public getMonth(): Month;
|
|
795
|
-
public getYear(): Year;
|
|
796
|
-
public toString(): string; // Format: "YYYY/MM"
|
|
797
|
-
}
|
|
798
|
-
```
|
|
799
|
-
|
|
800
|
-
#### Timestamp
|
|
801
|
-
|
|
802
|
-
Represents immutable timestamp values with comprehensive date/time operations.
|
|
803
|
-
|
|
804
|
-
```typescript
|
|
805
|
-
class Timestamp extends ValueObject<number> {
|
|
806
|
-
constructor(value: number | Date | Timestamp | string);
|
|
807
|
-
|
|
808
|
-
// Static factory methods
|
|
809
|
-
public static now(): Timestamp;
|
|
810
|
-
public static fromDate(date: Date): Timestamp;
|
|
811
|
-
|
|
812
|
-
// Getters
|
|
813
|
-
public getYear(): Year;
|
|
814
|
-
public getMonth(): Month;
|
|
815
|
-
public getDay(): Day;
|
|
816
|
-
public getHours(): number;
|
|
817
|
-
public getMinutes(): number;
|
|
818
|
-
public getSeconds(): number;
|
|
819
|
-
public getDayOfWeek(): DayOfWeek;
|
|
820
|
-
|
|
821
|
-
// Arithmetic operations
|
|
822
|
-
public addDays(days: number): Timestamp;
|
|
823
|
-
public addHours(hours: number): Timestamp;
|
|
824
|
-
public addMinutes(minutes: number): Timestamp;
|
|
825
|
-
public addSeconds(seconds: number): Timestamp;
|
|
826
|
-
|
|
827
|
-
// Comparisons
|
|
828
|
-
public isBefore(other: Timestamp): boolean;
|
|
829
|
-
public isAfter(other: Timestamp): boolean;
|
|
830
|
-
public diffInDays(other: Timestamp): number;
|
|
831
|
-
public diffInHours(other: Timestamp): number;
|
|
832
|
-
public diffInMinutes(other: Timestamp): number;
|
|
833
|
-
|
|
834
|
-
// Conversions
|
|
835
|
-
public toDate(): Date;
|
|
836
|
-
public toISOString(): string;
|
|
837
|
-
}
|
|
838
|
-
```
|
|
839
|
-
|
|
840
|
-
#### TimestampInterval
|
|
841
|
-
|
|
842
|
-
Represents immutable time intervals with start and end timestamps.
|
|
843
|
-
|
|
844
|
-
```typescript
|
|
845
|
-
class TimestampInterval extends ValueObject<string> {
|
|
846
|
-
constructor(start: Timestamp, end: Timestamp);
|
|
847
|
-
|
|
848
|
-
public static fromPrimitives(primitives: PrimitiveOf<TimestampInterval>): TimestampInterval;
|
|
849
|
-
|
|
850
|
-
public getStart(): Timestamp;
|
|
851
|
-
public getEnd(): Timestamp;
|
|
852
|
-
public getDuration(): Duration;
|
|
853
|
-
public contains(timestamp: Timestamp): boolean;
|
|
854
|
-
public overlaps(other: TimestampInterval): boolean;
|
|
855
|
-
public split(parts: number): TimestampInterval[];
|
|
856
|
-
}
|
|
857
|
-
```
|
|
858
|
-
|
|
859
|
-
### Enum Value Objects
|
|
860
|
-
|
|
861
|
-
#### Enum
|
|
862
|
-
|
|
863
|
-
An abstract base class for creating type-safe enumeration value objects.
|
|
864
|
-
|
|
865
|
-
```typescript
|
|
866
|
-
abstract class Enum<T extends Primitive = Primitive> extends ValueObject<T> {
|
|
867
|
-
constructor(protected readonly value: T);
|
|
868
|
-
|
|
869
|
-
public abstract getValues(): T[];
|
|
870
|
-
}
|
|
871
|
-
```
|
|
872
|
-
|
|
873
|
-
**Features:**
|
|
874
|
-
- Type-safe enumeration validation
|
|
875
|
-
- Inheritance from ValueObject
|
|
876
|
-
- Static factory methods support
|
|
877
|
-
- Immutable enum values
|
|
878
|
-
- Comprehensive error handling
|
|
879
|
-
|
|
880
|
-
**Usage:**
|
|
881
|
-
|
|
882
|
-
```typescript
|
|
883
|
-
import { Enum } from 'value-objects';
|
|
884
|
-
|
|
885
|
-
// Define your enum
|
|
886
|
-
enum UserStatus {
|
|
887
|
-
ACTIVE = 'active',
|
|
888
|
-
INACTIVE = 'inactive',
|
|
889
|
-
PENDING = 'pending',
|
|
890
|
-
SUSPENDED = 'suspended'
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
enum Priority {
|
|
894
|
-
LOW = 1,
|
|
895
|
-
MEDIUM = 2,
|
|
896
|
-
HIGH = 3,
|
|
897
|
-
URGENT = 4
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
// Create enum value object classes
|
|
901
|
-
class UserStatusEnum extends Enum {
|
|
902
|
-
public getValues() {
|
|
903
|
-
return Object.values(UserStatus);
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
// Static factory methods for convenience
|
|
907
|
-
static ACTIVE = () => new UserStatusEnum(UserStatus.ACTIVE);
|
|
908
|
-
static INACTIVE = () => new UserStatusEnum(UserStatus.INACTIVE);
|
|
909
|
-
static PENDING = () => new UserStatusEnum(UserStatus.PENDING);
|
|
910
|
-
static SUSPENDED = () => new UserStatusEnum(UserStatus.SUSPENDED);
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
class PriorityEnum extends Enum {
|
|
914
|
-
public getValues() {
|
|
915
|
-
return Object.values(Priority);
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
static LOW = () => new PriorityEnum(Priority.LOW);
|
|
919
|
-
static MEDIUM = () => new PriorityEnum(Priority.MEDIUM);
|
|
920
|
-
static HIGH = () => new PriorityEnum(Priority.HIGH);
|
|
921
|
-
static URGENT = () => new PriorityEnum(Priority.URGENT);
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
// Usage examples
|
|
925
|
-
const status = UserStatusEnum.ACTIVE();
|
|
926
|
-
const priority = new PriorityEnum(Priority.HIGH);
|
|
927
|
-
|
|
928
|
-
console.log(status.toString()); // 'active'
|
|
929
|
-
console.log(priority.valueOf()); // 3
|
|
930
|
-
console.log(status.isEqual('active')); // true
|
|
931
|
-
console.log(priority.isEqual(3)); // true
|
|
932
|
-
|
|
933
|
-
// Comparison
|
|
934
|
-
const status1 = UserStatusEnum.ACTIVE();
|
|
935
|
-
const status2 = new UserStatusEnum('active');
|
|
936
|
-
console.log(status1.isEqual(status2)); // true
|
|
937
|
-
|
|
938
|
-
// Clone
|
|
939
|
-
const statusCopy = (status as any).clone();
|
|
940
|
-
console.log(statusCopy.toString()); // 'active'
|
|
941
|
-
|
|
942
|
-
// Validation
|
|
943
|
-
try {
|
|
944
|
-
new UserStatusEnum('invalid'); // Throws ValueNotInEnumError
|
|
945
|
-
new PriorityEnum(999); // Throws ValueNotInEnumError
|
|
946
|
-
} catch (error) {
|
|
947
|
-
console.error('Invalid enum value');
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
// Mixed type enums
|
|
951
|
-
enum MixedEnum {
|
|
952
|
-
STRING_VALUE = 'text',
|
|
953
|
-
NUMBER_VALUE = 42
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
class MixedEnumValueObject extends Enum {
|
|
957
|
-
public getValues() {
|
|
958
|
-
return Object.values(MixedEnum);
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
const mixedString = new MixedEnumValueObject('text'); // Valid
|
|
963
|
-
const mixedNumber = new MixedEnumValueObject(42); // Valid
|
|
964
|
-
```
|
|
965
|
-
|
|
966
|
-
## 🚨 Error Handling
|
|
967
|
-
|
|
968
|
-
The library provides specific error types for different validation failures:
|
|
969
|
-
|
|
970
|
-
```typescript
|
|
971
|
-
import {
|
|
972
|
-
InvalidStringLengthError,
|
|
973
|
-
InvalidNumberError,
|
|
974
|
-
InvalidIntegerError,
|
|
975
|
-
InvalidColorError,
|
|
976
|
-
InvalidHourError,
|
|
977
|
-
InvalidMinutesError,
|
|
978
|
-
InvalidEmailError,
|
|
979
|
-
InvalidPositiveNumberError,
|
|
980
|
-
ValueNotInEnumError,
|
|
981
|
-
InvalidDayError,
|
|
982
|
-
InvalidDayFormatError,
|
|
983
|
-
InvalidTimestampIntervalError,
|
|
984
|
-
NullObjectError
|
|
985
|
-
} from 'value-objects';
|
|
986
|
-
|
|
987
|
-
// String length validation
|
|
988
|
-
try {
|
|
989
|
-
new StringValueObject('too long string', 5);
|
|
990
|
-
} catch (error) {
|
|
991
|
-
if (error instanceof InvalidStringLengthError) {
|
|
992
|
-
console.error('String exceeds maximum length');
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
// Number validation
|
|
997
|
-
try {
|
|
998
|
-
new NumberValueObject(NaN);
|
|
999
|
-
} catch (error) {
|
|
1000
|
-
if (error instanceof InvalidNumberError) {
|
|
1001
|
-
console.error('Invalid number provided');
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
// Integer validation
|
|
1006
|
-
try {
|
|
1007
|
-
new Integer(42.5);
|
|
1008
|
-
} catch (error) {
|
|
1009
|
-
if (error instanceof InvalidIntegerError) {
|
|
1010
|
-
console.error('Value must be a whole number');
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
try {
|
|
1015
|
-
new Integer(Infinity);
|
|
1016
|
-
} catch (error) {
|
|
1017
|
-
if (error instanceof InvalidIntegerError) {
|
|
1018
|
-
console.error('Infinity is not a valid integer');
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
// Color validation
|
|
1023
|
-
try {
|
|
1024
|
-
new Color('not-a-color');
|
|
1025
|
-
} catch (error) {
|
|
1026
|
-
if (error instanceof InvalidColorError) {
|
|
1027
|
-
console.error('Invalid hex color format');
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
// Time validation
|
|
1032
|
-
try {
|
|
1033
|
-
new Hour('25:30'); // Invalid hour
|
|
1034
|
-
} catch (error) {
|
|
1035
|
-
if (error instanceof InvalidHourError) {
|
|
1036
|
-
console.error('Hour must be between 0-23');
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
try {
|
|
1041
|
-
new Hour(12, 75); // Invalid minutes
|
|
1042
|
-
} catch (error) {
|
|
1043
|
-
if (error instanceof InvalidMinutesError) {
|
|
1044
|
-
console.error('Minutes must be between 0-59');
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
// Day validation
|
|
1049
|
-
try {
|
|
1050
|
-
new Day(32); // Invalid day
|
|
1051
|
-
} catch (error) {
|
|
1052
|
-
if (error instanceof InvalidDayError) {
|
|
1053
|
-
console.error('Day must be between 1-31');
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
// Calendar day format validation
|
|
1058
|
-
try {
|
|
1059
|
-
new CalendarDay('invalid-date-format');
|
|
1060
|
-
} catch (error) {
|
|
1061
|
-
if (error instanceof InvalidDayFormatError) {
|
|
1062
|
-
console.error('Invalid date format provided');
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
// Email validation
|
|
1067
|
-
try {
|
|
1068
|
-
new Email('invalid-email-format');
|
|
1069
|
-
} catch (error) {
|
|
1070
|
-
if (error instanceof InvalidEmailError) {
|
|
1071
|
-
console.error('Invalid email format provided');
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
try {
|
|
1076
|
-
new Email('user@domain.c'); // Domain extension too short
|
|
1077
|
-
} catch (error) {
|
|
1078
|
-
if (error instanceof InvalidEmailError) {
|
|
1079
|
-
console.error('Email domain extension must be 2-13 characters');
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
// PositiveNumber validation
|
|
1084
|
-
try {
|
|
1085
|
-
new PositiveNumber(-5);
|
|
1086
|
-
} catch (error) {
|
|
1087
|
-
if (error instanceof InvalidPositiveNumberError) {
|
|
1088
|
-
console.error('Value must be greater than 0');
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
try {
|
|
1093
|
-
new PositiveNumber(0); // Zero is not positive
|
|
1094
|
-
} catch (error) {
|
|
1095
|
-
if (error instanceof InvalidPositiveNumberError) {
|
|
1096
|
-
console.error('Zero is not a positive number');
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
// Enum validation
|
|
1101
|
-
try {
|
|
1102
|
-
new UserStatusEnum('invalid-status');
|
|
1103
|
-
} catch (error) {
|
|
1104
|
-
if (error instanceof ValueNotInEnumError) {
|
|
1105
|
-
console.error('Value not found in enum: active,inactive,pending,suspended');
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
try {
|
|
1110
|
-
new PriorityEnum(999); // Invalid number enum
|
|
1111
|
-
} catch (error) {
|
|
1112
|
-
if (error instanceof ValueNotInEnumError) {
|
|
1113
|
-
console.error('Enum value must be one of: 1,2,3,4');
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
// Timestamp interval validation
|
|
1118
|
-
try {
|
|
1119
|
-
const start = new Timestamp(Date.now() + 1000);
|
|
1120
|
-
const end = new Timestamp(Date.now());
|
|
1121
|
-
new TimestampInterval(start, end); // Start after end
|
|
1122
|
-
} catch (error) {
|
|
1123
|
-
if (error instanceof InvalidTimestampIntervalError) {
|
|
1124
|
-
console.error('Start timestamp must be before end timestamp');
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
// Null object error
|
|
1129
|
-
try {
|
|
1130
|
-
const nullValue = new StringValueObject(null);
|
|
1131
|
-
nullValue.isEmpty(); // Throws NullObjectError
|
|
1132
|
-
} catch (error) {
|
|
1133
|
-
if (error instanceof NullObjectError) {
|
|
1134
|
-
console.error('Cannot call method on null object');
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
```
|
|
1138
|
-
|
|
1139
|
-
## 🎯 Design Principles
|
|
1140
|
-
|
|
1141
|
-
### Immutability
|
|
1142
|
-
|
|
1143
|
-
All value objects are immutable. Operations that appear to modify values actually return new instances:
|
|
1144
|
-
|
|
1145
|
-
```typescript
|
|
1146
|
-
const original = new NumberValueObject(10);
|
|
1147
|
-
const modified = original.add(5);
|
|
1148
|
-
|
|
1149
|
-
console.log(original.valueOf()); // 10 (unchanged)
|
|
1150
|
-
console.log(modified.valueOf()); // 15 (new instance)
|
|
1151
|
-
```
|
|
1152
|
-
|
|
1153
|
-
### Value Equality
|
|
1154
|
-
|
|
1155
|
-
Value objects are compared by their values, not by reference:
|
|
1156
|
-
|
|
1157
|
-
```typescript
|
|
1158
|
-
const a = new StringValueObject('hello');
|
|
1159
|
-
const b = new StringValueObject('hello');
|
|
1160
|
-
|
|
1161
|
-
console.log(a === b); // false (different instances)
|
|
1162
|
-
console.log(a.isEqual(b)); // true (same value)
|
|
1163
|
-
```
|
|
1164
|
-
|
|
1165
|
-
### Null Safety
|
|
1166
|
-
|
|
1167
|
-
The library properly handles null and undefined values using the Null Object pattern:
|
|
1168
|
-
|
|
1169
|
-
```typescript
|
|
1170
|
-
const nullValue = new StringValueObject(undefined);
|
|
1171
|
-
console.log(NullObject.isNullObject(nullValue)); // true
|
|
1172
|
-
```
|
|
1173
|
-
|
|
1174
|
-
If you try to call any method from a NullObject it will throw
|
|
1175
|
-
a NullObjectError:
|
|
1176
|
-
|
|
1177
|
-
```typescript
|
|
1178
|
-
// NullObject StringValue instance
|
|
1179
|
-
const nullValue = new StringValueObject(undefined);
|
|
1180
|
-
nullValue.isEmpty(); // Throw NullObjectError!
|
|
1181
|
-
```
|
|
1182
|
-
|
|
1183
|
-
This prevents defensive programming and if-else validations
|
|
1184
|
-
|
|
1185
|
-
```typescript
|
|
1186
|
-
// Without NullObject Pattern
|
|
1187
|
-
let valueObject: StringValueObject;
|
|
1188
|
-
if (value) {
|
|
1189
|
-
valueObject = new StringValueObject(value);
|
|
1190
|
-
}
|
|
1191
|
-
else {
|
|
1192
|
-
throw Error('Invalid value');
|
|
1193
|
-
}
|
|
1194
|
-
return valueObject.isEmpty();
|
|
1195
|
-
|
|
1196
|
-
// With NullObject pattern
|
|
1197
|
-
valueObject = new StringValueObject(value);
|
|
1198
|
-
return valueObject.isEmpty();
|
|
1199
|
-
```
|
|
1200
|
-
|
|
1201
|
-
### Type Safety
|
|
1202
|
-
|
|
1203
|
-
The library provides full TypeScript support with strict typing to prevent runtime errors:
|
|
1204
|
-
|
|
1205
|
-
```typescript
|
|
1206
|
-
// Compile-time type checking
|
|
1207
|
-
const amount: NumberValueObject = new NumberValueObject(100);
|
|
1208
|
-
const price: PositiveNumber = new PositiveNumber(29.99);
|
|
1209
|
-
|
|
1210
|
-
// Type inference works correctly
|
|
1211
|
-
const total = amount.add(price); // Type: NumberValueObject
|
|
1212
|
-
const isExpensive = price.isGreaterThan(50); // Type: boolean
|
|
1213
|
-
```
|
|
1214
|
-
|
|
1215
|
-
### Validation by Construction
|
|
1216
|
-
|
|
1217
|
-
All validation happens during object construction, ensuring that invalid states are impossible:
|
|
1218
|
-
|
|
1219
|
-
```typescript
|
|
1220
|
-
// These will throw errors immediately
|
|
1221
|
-
new Email('invalid-email'); // InvalidEmailError
|
|
1222
|
-
new PositiveNumber(-1); // InvalidPositiveNumberError
|
|
1223
|
-
new Integer(3.14); // InvalidIntegerError
|
|
1224
|
-
new Color('not-a-color'); // InvalidColorError
|
|
1225
|
-
```
|
|
1226
|
-
|
|
1227
|
-
### Composition over Inheritance
|
|
1228
|
-
|
|
1229
|
-
Value objects can be composed together to create more complex domain models:
|
|
1230
|
-
|
|
1231
|
-
```typescript
|
|
1232
|
-
class Product {
|
|
1233
|
-
constructor(
|
|
1234
|
-
private readonly name: StringValueObject,
|
|
1235
|
-
private readonly price: PositiveNumber,
|
|
1236
|
-
private readonly category: CategoryEnum
|
|
1237
|
-
) {}
|
|
1238
|
-
|
|
1239
|
-
public getName(): StringValueObject {
|
|
1240
|
-
return this.name;
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
public getPrice(): PositiveNumber {
|
|
1244
|
-
return this.price;
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
public getCategory(): CategoryEnum {
|
|
1248
|
-
return this.category;
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
const product = new Product(
|
|
1253
|
-
new StringValueObject('Laptop'),
|
|
1254
|
-
new PositiveNumber(999.99),
|
|
1255
|
-
CategoryEnum.ELECTRONICS()
|
|
1256
|
-
);
|
|
1257
|
-
```
|