diff --git a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt index 616f574..f247fe2 100644 --- a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt +++ b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt @@ -23,7 +23,7 @@ internal object StartAuthorizationCommand : RSocketCommand StartAuthorizationRequest.Result( verificationHash = VerificationHash.createOrThrow(result.verificationHash), - attempts = Count.createOrThrow(result.attempts), + attempts = Count.factory.createOrThrow(result.attempts), expiresAt = Instant.fromEpochMilliseconds(result.expiresAt), ) } diff --git a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/TimerMappers.kt b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/TimerMappers.kt index bd623ca..a54dba3 100644 --- a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/TimerMappers.kt +++ b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/TimerMappers.kt @@ -27,7 +27,7 @@ internal fun RSTimer.sdk(): SdkTimer { name = TimerName.createOrThrow(name), description = TimerDescription.createOrThrow(description), ownerId = UserId.createOrThrow(ownerId), - membersCount = Count.createOrThrow(membersCount), + membersCount = Count.factory.createOrThrow(membersCount), state = currentState?.sdk() ?: SdkTimerState.Inactive(Instant.DISTANT_PAST), settings = settings?.sdk() ?: TimerSettings(), ) @@ -64,7 +64,7 @@ internal fun RSTimer.Settings.sdk(): SdkTimerSettings { restTime = restTime.minutes, bigRestTime = bigRestTime.minutes, bigRestEnabled = bigRestEnabled, - bigRestPer = Count.createOrThrow(bigRestPer), + bigRestPer = Count.factory.createOrThrow(bigRestPer), isEveryoneCanPause = isEveryoneCanPause, isConfirmationRequired = isConfirmationRequired, ) @@ -84,6 +84,6 @@ internal fun RSInvite.sdk(): SdkInvite { return SdkInvite( inviteCode = InviteCode.createOrThrow(code), creationTime = Instant.fromEpochMilliseconds(creationTime), - limit = Count.createOrThrow(limit), + limit = Count.factory.createOrThrow(limit), ) } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/email/types/value/VerificationHash.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/email/types/value/VerificationHash.kt index c301c73..fd65cfb 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/email/types/value/VerificationHash.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/email/types/value/VerificationHash.kt @@ -5,13 +5,20 @@ import org.timemates.sdk.common.constructor.factory import org.timemates.sdk.common.constructor.rules.ValidationRule import org.timemates.sdk.common.constructor.rules.lengthExact import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class VerificationHash private constructor(public val string: String) { - public companion object : Factory by factory( - rules = listOf( - ValidationRule.lengthExact(128), - ), - constructor = ::VerificationHash - ) + public companion object { + @JvmStatic + public val REQUIRED_LENGTH: Int = 128 + + @JvmStatic + public val factory: Factory = factory( + rules = listOf( + ValidationRule.lengthExact(REQUIRED_LENGTH), + ), + constructor = ::VerificationHash + ) + } } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/AuthorizedSessionsApi.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/AuthorizedSessionsApi.kt index 68d3dc6..371753a 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/AuthorizedSessionsApi.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/AuthorizedSessionsApi.kt @@ -55,7 +55,7 @@ public class AuthorizedSessionsApi( @Suppress("NAME_SHADOWING") public fun AuthorizedSessionsApi.getSessionsPages( pageToken: PageToken?, - maxRetries: Count = Count.createOrThrow(5), + maxRetries: Count = Count.factory.createOrThrow(5), initialDelayOnRetries: Duration = 1.seconds, ): PagesIterator = PagesIteratorImpl( initialPageToken = pageToken, diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ApplicationName.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ApplicationName.kt index 461bbc4..59f5070 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ApplicationName.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ApplicationName.kt @@ -3,8 +3,12 @@ package org.timemates.sdk.authorization.sessions.types.value import org.timemates.sdk.common.constructor.Factory import org.timemates.sdk.common.constructor.factory import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class ApplicationName private constructor(public val string: String) { - public companion object : Factory by factory(::ApplicationName) + public companion object { + @JvmStatic + public val factory: Factory = factory(::ApplicationName) + } } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/AuthorizationId.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/AuthorizationId.kt index 46508a4..948fe44 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/AuthorizationId.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/AuthorizationId.kt @@ -3,8 +3,12 @@ package org.timemates.sdk.authorization.sessions.types.value import org.timemates.sdk.common.constructor.Factory import org.timemates.sdk.common.constructor.factory import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class AuthorizationId private constructor(public val int: Int) { - public companion object : Factory by factory(::AuthorizationId) + public companion object { + @JvmStatic + public val factory: Factory = factory(::AuthorizationId) + } } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ClientIpAddress.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ClientIpAddress.kt index 7d75e4f..23360a9 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ClientIpAddress.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ClientIpAddress.kt @@ -3,8 +3,12 @@ package org.timemates.sdk.authorization.sessions.types.value import org.timemates.sdk.common.constructor.Factory import org.timemates.sdk.common.constructor.factory import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class ClientIpAddress private constructor(public val string: String) { - public companion object : Factory by factory(::ClientIpAddress) + public companion object { + @JvmStatic + public val factory: Factory = factory(::ClientIpAddress) + } } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ClientVersion.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ClientVersion.kt index 6685125..c617248 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ClientVersion.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ClientVersion.kt @@ -3,8 +3,12 @@ package org.timemates.sdk.authorization.sessions.types.value import org.timemates.sdk.common.constructor.Factory import org.timemates.sdk.common.constructor.factory import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class ClientVersion private constructor(public val double: Double) { - public companion object : Factory by factory(::ClientVersion) + public companion object { + @JvmStatic + public val factory: Factory = factory(::ClientVersion) + } } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ConfirmationCode.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ConfirmationCode.kt index 199a024..09d5a79 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ConfirmationCode.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/sessions/types/value/ConfirmationCode.kt @@ -6,14 +6,20 @@ import org.timemates.sdk.common.constructor.rules.ValidationRule import org.timemates.sdk.common.constructor.rules.lengthExact import org.timemates.sdk.common.constructor.rules.notBlank import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class ConfirmationCode private constructor(public val string: String) { - public companion object : Factory by factory( - rules = listOf( - ValidationRule.notBlank(), - ValidationRule.lengthExact(8), - ), - constructor = ::ConfirmationCode, - ) + public companion object { + @JvmStatic + public val REQUIRED_LENGTH: Int = 8 + + public val factory: Factory = factory( + rules = listOf( + ValidationRule.notBlank(), + ValidationRule.lengthExact(REQUIRED_LENGTH), + ), + constructor = ::ConfirmationCode, + ) + } } diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/types/value/HashValue.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/types/value/HashValue.kt index dbeca81..43e35a4 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/types/value/HashValue.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/authorization/types/value/HashValue.kt @@ -3,10 +3,12 @@ package org.timemates.sdk.authorization.types.value import org.timemates.sdk.common.constructor.Factory import org.timemates.sdk.common.constructor.factory import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class HashValue private constructor(public val string: String) { - public companion object : Factory by factory( - constructor = ::HashValue, - ) + public companion object { + @JvmStatic + public val factory: Factory = factory(constructor = ::HashValue) + } } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/common/constructor/Factory.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/common/constructor/Factory.kt index dbb4731..f18fb0d 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/common/constructor/Factory.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/common/constructor/Factory.kt @@ -17,6 +17,12 @@ import org.timemates.sdk.common.constructor.results.getUnsafe * @param TRaw The type of TRaw used to create the object. */ public interface Factory { + + /** + * Validation rules that apply to the creation of [TBoxed] by contract of this factory. + * + * @see ValidationRule + */ public val rules: List> diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/common/pagination/PageToken.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/common/pagination/PageToken.kt index 1801ca7..affda23 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/common/pagination/PageToken.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/common/pagination/PageToken.kt @@ -3,6 +3,7 @@ package org.timemates.sdk.common.pagination import org.timemates.sdk.common.constructor.Factory import org.timemates.sdk.common.constructor.factory import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic /** * A value class representing a page token. @@ -13,5 +14,8 @@ import kotlin.jvm.JvmInline */ @JvmInline public value class PageToken private constructor(public val string: String) { - public companion object : Factory by factory(::PageToken) + public companion object { + @JvmStatic + public val factory: Factory = factory(::PageToken) + } } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/common/pagination/PagesIterator.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/common/pagination/PagesIterator.kt index d7aa676..81678c2 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/common/pagination/PagesIterator.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/common/pagination/PagesIterator.kt @@ -141,12 +141,12 @@ public fun PagesIterator.map(mapper: suspend (T) -> R): PagesIterator< * on every retry. */ internal class PagesIteratorImpl( - private val chunkSize: Count = Count.createOrThrow(20), + private val chunkSize: Count = Count.factory.createOrThrow(20), private val initialPageToken: PageToken?, prevPage: Page? = null, private val provider: suspend (size: Count, pageToken: PageToken?) -> Result>, private val delayOnServerErrors: Duration, - private val maxRetries: Count = Count.createOrThrow(5), + private val maxRetries: Count = Count.factory.createOrThrow(5), private val increaseDelayOnRetries: Boolean = true, ) : PagesIterator { /** diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/common/types/value/Count.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/common/types/value/Count.kt index d02ddc8..75c929c 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/common/types/value/Count.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/common/types/value/Count.kt @@ -5,13 +5,17 @@ import org.timemates.sdk.common.constructor.factory import org.timemates.sdk.common.constructor.rules.ValidationRule import org.timemates.sdk.common.constructor.rules.minValue import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class Count private constructor(public val int: Int) { - public companion object : Factory by factory( - rules = listOf(ValidationRule.minValue(Count.MIN_REQUIRED_VALUE)), - constructor = ::Count, - ) -} + public companion object { + public const val MIN_VALUE: Int = 0 -public val Count.Companion.MIN_REQUIRED_VALUE: Int get() = 0 \ No newline at end of file + @JvmStatic + public val factory: Factory = factory( + rules = listOf(ValidationRule.minValue(MIN_VALUE)), + constructor = ::Count, + ) + } +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/TimersApi.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/TimersApi.kt index a9343f8..42cd6bd 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/TimersApi.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/TimersApi.kt @@ -112,7 +112,7 @@ public class TimersApi( public fun TimersApi.getUserTimersPages( pageToken: PageToken? = null, - maxRetries: Count = Count.createOrThrow(5), + maxRetries: Count = Count.factory.createOrThrow(5), initialDelayOnRetries: Duration = 1.seconds, ): PagesIterator = PagesIteratorImpl( initialPageToken = pageToken, diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/TimerMembersApi.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/TimerMembersApi.kt index 28c0bea..217de25 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/TimerMembersApi.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/TimerMembersApi.kt @@ -64,7 +64,7 @@ public class TimerMembersApi( public fun TimerMembersApi.getMembersPages( timerId: TimerId, pageToken: PageToken? = null, - maxRetries: Count = Count.createOrThrow(5), + maxRetries: Count = Count.factory.createOrThrow(5), initialDelayOnRetries: Duration = 1.seconds, ): PagesIterator = PagesIteratorImpl( initialPageToken = pageToken, diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/invites/TimerInvitesApi.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/invites/TimerInvitesApi.kt index 1ba00b8..f93f4d8 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/invites/TimerInvitesApi.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/invites/TimerInvitesApi.kt @@ -72,7 +72,7 @@ public class TimerInvitesApi( public fun TimerInvitesApi.getInvitesPages( timerId: TimerId, pageToken: PageToken? = null, - maxRetries: Count = Count.createOrThrow(5), + maxRetries: Count = Count.factory.createOrThrow(5), initialDelayOnRetries: Duration = 1.seconds, ): PagesIterator = PagesIteratorImpl( initialPageToken = pageToken, diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/invites/types/value/InviteCode.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/invites/types/value/InviteCode.kt index 93008b5..c36efd2 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/invites/types/value/InviteCode.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/invites/types/value/InviteCode.kt @@ -5,13 +5,17 @@ import org.timemates.sdk.common.constructor.factory import org.timemates.sdk.common.constructor.rules.ValidationRule import org.timemates.sdk.common.constructor.rules.lengthExact import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class InviteCode private constructor(public val string: String) { - public companion object : Factory by factory( - rules = listOf(ValidationRule.lengthExact(InviteCode.REQUIRED_LENGTH)), - constructor = ::InviteCode, - ) -} + public companion object { + public const val REQUIRED_LENGTH: Int = 8 -public val InviteCode.Companion.REQUIRED_LENGTH: Int get() = 8 \ No newline at end of file + @JvmStatic + public val factory: Factory = factory( + rules = listOf(ValidationRule.lengthExact(InviteCode.REQUIRED_LENGTH)), + constructor = ::InviteCode, + ) + } +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/invites/types/value/InviteName.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/invites/types/value/InviteName.kt index 6796078..e8f219b 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/invites/types/value/InviteName.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/members/invites/types/value/InviteName.kt @@ -5,13 +5,17 @@ import org.timemates.sdk.common.constructor.factory import org.timemates.sdk.common.constructor.rules.ValidationRule import org.timemates.sdk.common.constructor.rules.notBlank import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class InviteName private constructor(public val string: String) { - public companion object : Factory by factory( - rules = listOf( - ValidationRule.notBlank(), - ), - constructor = ::InviteName - ) + public companion object { + @JvmStatic + public val factory: Factory = factory( + rules = listOf( + ValidationRule.notBlank(), + ), + constructor = ::InviteName + ) + } } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/TimerSettings.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/TimerSettings.kt index 2338f02..82f77b8 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/TimerSettings.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/TimerSettings.kt @@ -11,7 +11,7 @@ public data class TimerSettings( val restTime: Duration = 5.minutes, val bigRestTime: Duration = 10.minutes, val bigRestEnabled: Boolean = true, - val bigRestPer: Count = Count.createOrThrow(4), + val bigRestPer: Count = Count.factory.createOrThrow(4), val isEveryoneCanPause: Boolean = false, val isConfirmationRequired: Boolean = false, ) : TimeMatesEntity() { diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/value/TimerDescription.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/value/TimerDescription.kt index 6b0377a..a877d1b 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/value/TimerDescription.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/value/TimerDescription.kt @@ -5,15 +5,20 @@ import org.timemates.sdk.common.constructor.factory import org.timemates.sdk.common.constructor.rules.ValidationRule import org.timemates.sdk.common.constructor.rules.lengthRange import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class TimerDescription private constructor(public val string: String) { - public companion object : Factory by factory( - rules = listOf( - ValidationRule.lengthRange(TimerDescription.LENGTH_RANGE), - ), - constructor = ::TimerDescription, - ) -} + public companion object { + @JvmStatic + public val LENGTH_RANGE: IntRange = 0..500 -public val TimerDescription.Companion.LENGTH_RANGE: IntRange get() = 0..500 \ No newline at end of file + @JvmStatic + public val factory: Factory = factory( + rules = listOf( + ValidationRule.lengthRange(LENGTH_RANGE), + ), + constructor = ::TimerDescription, + ) + } +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/value/TimerId.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/value/TimerId.kt index 289343f..56cfe8e 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/value/TimerId.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/value/TimerId.kt @@ -5,13 +5,19 @@ import org.timemates.sdk.common.constructor.factory import org.timemates.sdk.common.constructor.rules.ValidationRule import org.timemates.sdk.common.constructor.rules.minValue import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class TimerId private constructor(public val long: Long) { - public companion object : Factory by factory( - rules = listOf( - ValidationRule.minValue(0), - ), - constructor = ::TimerId, - ) + public companion object { + public const val MIN_VALUE: Long = 0L + + @JvmStatic + public val factory: Factory = factory( + rules = listOf( + ValidationRule.minValue(MIN_VALUE), + ), + constructor = ::TimerId, + ) + } } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/value/TimerName.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/value/TimerName.kt index 4053592..a7379b3 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/value/TimerName.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/timers/types/value/TimerName.kt @@ -5,15 +5,20 @@ import org.timemates.sdk.common.constructor.factory import org.timemates.sdk.common.constructor.rules.ValidationRule import org.timemates.sdk.common.constructor.rules.lengthRange import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class TimerName private constructor(public val string: String) { - public companion object : Factory by factory( - rules = listOf( - ValidationRule.lengthRange(TimerName.LENGTH_RANGE), - ), - constructor = ::TimerName, - ) -} + public companion object { + @JvmStatic + public val LENGTH_RANGE: IntRange = 3..50 -public val TimerName.Companion.LENGTH_RANGE: IntRange get() = 3..50 \ No newline at end of file + @JvmStatic + public val factory: Factory = factory( + rules = listOf( + ValidationRule.lengthRange(LENGTH_RANGE), + ), + constructor = ::TimerName, + ) + } +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/Avatar.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/Avatar.kt index 3517273..cc2065c 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/Avatar.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/Avatar.kt @@ -5,13 +5,17 @@ import org.timemates.sdk.common.constructor.factory import org.timemates.sdk.common.constructor.rules.ValidationRule import org.timemates.sdk.common.constructor.rules.notBlank import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic public sealed interface Avatar { @JvmInline public value class GravatarId private constructor(public val string: String) : Avatar { - public companion object : Factory by factory( - rules = listOf(ValidationRule.notBlank()), - constructor = ::GravatarId, - ) + public companion object { + @JvmStatic + public val factory: Factory = factory( + rules = listOf(ValidationRule.notBlank()), + constructor = ::GravatarId, + ) + } } } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/EmailAddress.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/EmailAddress.kt index 388817f..b14e5e2 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/EmailAddress.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/EmailAddress.kt @@ -6,26 +6,34 @@ import org.timemates.sdk.common.constructor.rules.ValidationRule import org.timemates.sdk.common.constructor.rules.lengthRange import org.timemates.sdk.common.constructor.rules.matchesPattern import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class EmailAddress private constructor(public val string: String) { - public companion object : Factory by factory( - rules = listOf( - ValidationRule.lengthRange(EmailAddress.LENGTH_RANGE), - ValidationRule.matchesPattern(EmailAddress.EMAIL_PATTERN), - ), - constructor = ::EmailAddress, - ) -} + public companion object { + @JvmStatic + public val LENGTH_RANGE: IntRange = 5..200 -public val EmailAddress.Companion.LENGTH_RANGE: IntRange get() = 5..200 + @JvmStatic + public val EMAIL_PATTERN: Regex = Regex( + buildString { + append("[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}") + append("\\@") + append("[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}") + append("(") + append("\\.") + append("[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}") + append(")+") + } + ) -public val EmailAddress.Companion.EMAIL_PATTERN: Regex get() = Regex( - "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" + - "\\@" + - "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + - "(" + - "\\." + - "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + - ")+" -) \ No newline at end of file + @JvmStatic + public val factory: Factory = factory( + rules = listOf( + ValidationRule.lengthRange(LENGTH_RANGE), + ValidationRule.matchesPattern(EMAIL_PATTERN), + ), + constructor = ::EmailAddress, + ) + } +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/UserDescription.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/UserDescription.kt index a2c3b24..8176fda 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/UserDescription.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/UserDescription.kt @@ -5,15 +5,20 @@ import org.timemates.sdk.common.constructor.factory import org.timemates.sdk.common.constructor.rules.ValidationRule import org.timemates.sdk.common.constructor.rules.lengthRange import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class UserDescription private constructor(public val string: String) { - public companion object : Factory by factory( - rules = listOf( - ValidationRule.lengthRange(UserDescription.LENGTH_RANGE), - ), - constructor = ::UserDescription, - ) -} + public companion object { + @JvmStatic + public val LENGTH_RANGE: IntRange = 3..200 -public val UserDescription.Companion.LENGTH_RANGE: IntRange get() = 3..200 + @JvmStatic + public val factory: Factory = factory( + rules = listOf( + ValidationRule.lengthRange(LENGTH_RANGE), + ), + constructor = ::UserDescription, + ) + } +} diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/UserId.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/UserId.kt index c1c0e96..2060509 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/UserId.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/UserId.kt @@ -5,11 +5,17 @@ import org.timemates.sdk.common.constructor.factory import org.timemates.sdk.common.constructor.rules.ValidationRule import org.timemates.sdk.common.constructor.rules.minValue import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class UserId private constructor(public val long: Long) { - public companion object : Factory by factory( - rules = listOf(ValidationRule.minValue(0)), - constructor = ::UserId, - ) + public companion object { + public const val MIN_VALUE: Long = 0 + + @JvmStatic + public val factory: Factory = factory( + rules = listOf(ValidationRule.minValue(MIN_VALUE)), + constructor = ::UserId, + ) + } } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/UserName.kt b/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/UserName.kt index 18f8e74..036ff3b 100644 --- a/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/UserName.kt +++ b/sdk/src/commonMain/kotlin/org/timemates/sdk/users/profile/types/value/UserName.kt @@ -1,17 +1,25 @@ package org.timemates.sdk.users.profile.types.value import org.timemates.sdk.common.constructor.Factory +import org.timemates.sdk.common.constructor.createOrThrow import org.timemates.sdk.common.constructor.factory import org.timemates.sdk.common.constructor.rules.ValidationRule import org.timemates.sdk.common.constructor.rules.lengthRange import kotlin.jvm.JvmInline +import kotlin.jvm.JvmStatic @JvmInline public value class UserName private constructor(public val string: String) { - public companion object : Factory by factory( - rules = listOf(ValidationRule.lengthRange(UserName.LENGTH_RANGE)), - constructor = ::UserName, - ) + public companion object { + @JvmStatic + public val LENGTH_RANGE: IntRange = 3..50 + + @JvmStatic + public val factory: Factory = factory( + rules = listOf(ValidationRule.lengthRange(LENGTH_RANGE)), + constructor = ::UserName, + ) + } } -public val UserName.Companion.LENGTH_RANGE: IntRange get() = 3..50 +