diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/types/value/VerificationHash.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/types/value/VerificationHash.kt index 364398b..dffe657 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/types/value/VerificationHash.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/types/value/VerificationHash.kt @@ -7,12 +7,12 @@ import io.timemates.sdk.common.constructor.CreationFailure @JvmInline public value class VerificationHash private constructor(public val string: String) { public companion object : Factory() { - private const val SIZE: Int = 128 + public const val SIZE: Int = 128 override fun create(input: String): Result { return when (input.length) { SIZE -> Result.success(VerificationHash(input)) - else -> Result.failure(CreationFailure.ofSize(SIZE)) + else -> Result.failure(CreationFailure.ofSizeExact(SIZE)) } } } diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ConfirmationCode.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ConfirmationCode.kt index 929f105..0bfaa61 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ConfirmationCode.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ConfirmationCode.kt @@ -6,13 +6,13 @@ import io.timemates.sdk.common.constructor.Factory @JvmInline public value class ConfirmationCode private constructor(public val string: String) { public companion object : Factory() { - private const val SIZE = 6 - private val PATTERN = Regex("^[0-9]+$") + public const val SIZE: Int = 6 + public val PATTERN: Regex = Regex("^[0-9]+$") override fun create(input: String): Result { return when { input.isBlank() -> Result.failure(CreationFailure.ofBlank()) - input.length != SIZE -> Result.failure(CreationFailure.ofSize(SIZE)) + input.length != SIZE -> Result.failure(CreationFailure.ofSizeExact(SIZE)) !input.matches(PATTERN) -> Result.failure(CreationFailure.ofPattern(PATTERN)) else -> Result.success(ConfirmationCode(input)) } diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/constructor/CreationFailure.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/constructor/CreationFailure.kt index d47b9d6..e9d3d3a 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/constructor/CreationFailure.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/constructor/CreationFailure.kt @@ -1,3 +1,5 @@ +@file:Suppress("CanBeParameter", "MemberVisibilityCanBePrivate") + package io.timemates.sdk.common.constructor import io.timemates.sdk.common.exceptions.TimeMatesException @@ -14,7 +16,7 @@ public sealed class CreationFailure(message: String) : TimeMatesException(messag /** * Represents a creation failure due to a size range constraint. */ - public class SizeRangeFailure(public val size: IntRange) : CreationFailure("Constraint failure: size must be in range of $size") + public class SizeRangeFailure(public val range: IntRange) : CreationFailure("Constraint failure: size must be in range of $range") /** * Represents a creation failure due to an exact size constraint. @@ -63,7 +65,7 @@ public sealed class CreationFailure(message: String) : TimeMatesException(messag * @param size The minimal value that caused the constraint failure. * @return A [MinValueFailure] object with the constraint failure message. */ - public fun ofMinValue(size: Int): CreationFailure { + public fun ofMin(size: Int): CreationFailure { return MinValueFailure(size) } @@ -72,7 +74,7 @@ public sealed class CreationFailure(message: String) : TimeMatesException(messag * * @return A [BlankValueFailure] object with the constraint failure message. */ - public fun ofBlankValue(): CreationFailure { + public fun ofBlank(): CreationFailure { return BlankValueFailure() } diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/types/value/Count.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/types/value/Count.kt index 42e62bd..90fb157 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/types/value/Count.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/types/value/Count.kt @@ -6,9 +6,11 @@ import io.timemates.sdk.common.constructor.Factory @JvmInline public value class Count internal constructor(public val int: Int) { public companion object : Factory() { + public const val MIN_VALUE: Int = 0 + override fun create(input: Int): Result { return when { - input < 0 -> Result.failure(CreationFailure.ofMin(0)) + input < MIN_VALUE -> Result.failure(CreationFailure.ofMin(MIN_VALUE)) else -> Result.success(Count(input)) } } diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/types/value/InviteCode.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/types/value/InviteCode.kt index e210f75..e45663c 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/types/value/InviteCode.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/types/value/InviteCode.kt @@ -6,12 +6,12 @@ import io.timemates.sdk.common.constructor.Factory @JvmInline public value class InviteCode private constructor(public val string: String) { public companion object : Factory() { - private const val SIZE = 8 + public const val SIZE: Int = 8 override fun create(input: String): Result { return when { input.length == SIZE -> Result.success(InviteCode(input)) - else -> Result.failure(CreationFailure.ofSize(SIZE)) + else -> Result.failure(CreationFailure.ofSizeExact(SIZE)) } } } diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/types/value/TimerDescription.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/types/value/TimerDescription.kt index 03151e6..df734bf 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/types/value/TimerDescription.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/types/value/TimerDescription.kt @@ -9,11 +9,11 @@ public value class TimerDescription private constructor(public val string: Strin /** * Size range of the timer's name. */ - private val SIZE = 3..500 + public val SIZE_RANGE: IntRange = 3..500 override fun create(input: String): Result { return when (input.length) { - !in SIZE -> Result.failure(CreationFailure.ofSize(SIZE)) + !in SIZE_RANGE -> Result.failure(CreationFailure.ofSizeRange(SIZE_RANGE)) else -> Result.success(TimerDescription(input)) } } diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/types/value/TimerName.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/types/value/TimerName.kt index 0066a54..951d803 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/types/value/TimerName.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/types/value/TimerName.kt @@ -9,11 +9,11 @@ public value class TimerName private constructor(public val string: String) { /** * Size range of the timer's name. */ - private val SIZE = 3..50 + public val SIZE_RANGE: IntRange = 3..50 override fun create(input: String): Result { return when (input.length) { - !in SIZE -> Result.failure(CreationFailure.ofSize(SIZE)) + !in SIZE_RANGE -> Result.failure(CreationFailure.ofSizeRange(SIZE_RANGE)) else -> Result.success(TimerName(input)) } } diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/EmailAddress.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/EmailAddress.kt index 90e81b6..a5aa7ba 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/EmailAddress.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/EmailAddress.kt @@ -6,9 +6,9 @@ import io.timemates.sdk.common.constructor.CreationFailure @JvmInline public value class EmailAddress private constructor(public val string: String) { public companion object : Factory() { - private val SIZE: IntRange = 5..200 + public val SIZE_RANGE: IntRange = 5..200 - private val emailPattern = Regex( + public val PATTERN: Regex = Regex( "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" + "\\@" + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + @@ -20,10 +20,10 @@ public value class EmailAddress private constructor(public val string: String) { override fun create(input: String): Result { return when { - input.length !in SIZE -> - Result.failure(CreationFailure.ofSize(SIZE)) - !emailPattern.matches(input) -> - Result.failure(CreationFailure.ofPattern(emailPattern)) + input.length !in SIZE_RANGE -> + Result.failure(CreationFailure.ofSizeRange(SIZE_RANGE)) + !PATTERN.matches(input) -> + Result.failure(CreationFailure.ofPattern(PATTERN)) else -> Result.success(EmailAddress(input)) } diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/UserDescription.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/UserDescription.kt index 7585f5f..f667524 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/UserDescription.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/UserDescription.kt @@ -11,11 +11,11 @@ public value class UserDescription private constructor(public val string: String /** * Size range of the user's short bio. */ - private val SIZE = 3..200 + public val SIZE_RANGE: IntRange = 3..200 override fun create(input: String): Result { return when (input.length) { - !in 0..200 -> failure(CreationFailure.ofSize(SIZE)) + !in 0..200 -> failure(CreationFailure.ofSizeRange(SIZE_RANGE)) else -> success(UserDescription(input)) } } diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/UserId.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/UserId.kt index 1770fc5..0fa37da 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/UserId.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/UserId.kt @@ -6,9 +6,11 @@ import io.timemates.sdk.common.constructor.Factory @JvmInline public value class UserId private constructor(public val long: Long) { public companion object : Factory() { + public const val MIN_VALUE: Int = 0 + override fun create(input: Long): Result { return when { - input < 0 -> Result.failure(CreationFailure.ofMin(0)) + input < MIN_VALUE -> Result.failure(CreationFailure.ofMin(MIN_VALUE)) else -> Result.success(UserId(input)) } } diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/UserName.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/UserName.kt index 3d7137f..3d8f536 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/UserName.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/value/UserName.kt @@ -9,11 +9,11 @@ public value class UserName private constructor(public val string: String) { /** * Size range of the user's name. */ - private val SIZE = 3..50 + public val SIZE_RANGE: IntRange = 3..50 override fun create(input: String): Result { return when (input.length) { - !in SIZE -> Result.failure(CreationFailure.ofSize(SIZE)) + !in SIZE_RANGE -> Result.failure(CreationFailure.ofSizeRange(SIZE_RANGE)) else -> Result.success(UserName(input)) } }