From f696736dc98d135d2195ab125bccfc5cfc7f201a Mon Sep 17 00:00:00 2001 From: y9vad9 Date: Wed, 27 Sep 2023 02:29:24 +0200 Subject: [PATCH 01/13] feat(#43): rsocket transport --- gradle/libs.versions.toml | 6 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../api/grpc/GrpcTimeMatesRequestsEngine.kt | 2 +- .../api/grpc/mappers/AuthorizationsMapper.kt | 4 +- rsocket-engine/build.gradle.kts | 20 +++++ .../timemates/api/rsocket/CommandsRegistry.kt | 20 +++++ .../rsocket/RSocketTimeMatesRequestsEngine.kt | 58 +++++++++++++ .../commands/AuthorizationCommandsRegistry.kt | 23 +++++ .../commands/ConfigureNewAccountCommand.kt | 25 ++++++ .../commands/ConfirmAuthorizationCommand.kt | 24 ++++++ .../GetAuthorizationSessionsCommand.kt | 28 +++++++ .../commands/RenewAuthorizationCommand.kt | 24 ++++++ .../commands/StartAuthorizationCommand.kt | 33 ++++++++ .../TerminateCurrentAuthorizationCommand.kt | 18 ++++ .../requests/ConfigureAccountRequest.kt | 17 ++++ .../requests/ConfirmAuthorizationRequest.kt | 16 ++++ .../requests/GetAuthorizationsRequest.kt | 14 ++++ .../requests/RenewAuthorizationRequest.kt | 12 +++ .../requests/StartAuthorizationRequest.kt | 18 ++++ .../requests/TerminateAuthorizationRequest.kt | 15 ++++ .../types/SerializableAuthMetadata.kt | 17 ++++ .../types/SerializableAuthorization.kt | 19 +++++ .../types/SerializableAuthorizationScope.kt | 34 ++++++++ .../rsocket/common/commands/RSocketCommand.kt | 26 ++++++ .../common/commands/RSocketCommands.kt | 38 +++++++++ .../commands/RSocketCommandsBuilderScope.kt | 37 ++++++++ .../api/rsocket/common/ext/RSocketExt.kt | 84 +++++++++++++++++++ .../rsocket/common/markers/RSocketRequest.kt | 8 ++ .../common/metadata/AuthorizationMetadata.kt | 37 ++++++++ .../rsocket/common/serialization/JsonExt.kt | 23 +++++ .../files/commands/FilesCommandsRegistry.kt | 11 +++ .../rsocket/files/commands/GetFileCommand.kt | 22 +++++ .../rsocket/files/requests/GetFileRequest.kt | 19 +++++ .../files/requests/UploadFileRequest.kt | 17 ++++ .../rsocket/files/types/SerializableFile.kt | 15 ++++ .../files/types/SerializableFileType.kt | 10 +++ .../timers/commands/CreateTimerCommand.kt | 26 ++++++ .../timers/commands/EditTimerCommand.kt | 22 +++++ .../timers/commands/GetTimerCommand.kt | 27 ++++++ .../timers/commands/GetUserTimersCommand.kt | 30 +++++++ .../timers/commands/RemoveTimerCommand.kt | 18 ++++ .../timers/commands/TimersCommandsRegistry.kt | 24 ++++++ .../commands/GetTimerMembersCommand.kt | 36 ++++++++ .../commands/KickTimerMemberCommand.kt | 19 +++++ .../commands/TimerMembersCommandsRegistry.kt | 20 +++++ .../invites/commands/CreateInviteCommand.kt | 28 +++++++ .../invites/commands/GetInvitesCommand.kt | 31 +++++++ .../commands/JoinTimerByCodeCommand.kt | 27 ++++++ .../invites/commands/RemoveInviteCommand.kt | 24 ++++++ .../commands/TimerMembersCommandsRegistry.kt | 17 ++++ .../requests/RSocketCreateInviteRequest.kt | 13 +++ .../requests/RSocketGetInvitesListRequest.kt | 17 ++++ .../requests/RSocketJoinTimerByCodeRequest.kt | 12 +++ .../requests/RSocketRemoveInviteRequest.kt | 10 +++ .../invites/types/SerializableInvite.kt | 24 ++++++ .../requests/RSocketGetMembersListRequest.kt | 17 ++++ .../requests/RSocketKickMemberRequest.kt | 6 ++ .../requests/RSocketCreateTimerRequest.kt | 15 ++++ .../requests/RSocketDeleteTimerRequest.kt | 9 ++ .../requests/RSocketEditTimerRequest.kt | 13 +++ .../timers/requests/RSocketGetTimerRequest.kt | 13 +++ .../requests/RSocketGetUserTimersRequest.kt | 16 ++++ .../commands/ConfirmSessionCommand.kt | 18 ++++ .../commands/GetCurrentSessionCommand.kt | 19 +++++ .../sessions/commands/GetTimerStateCommand.kt | 32 +++++++ .../sessions/commands/JoinSessionCommand.kt | 20 +++++ .../sessions/commands/LeaveSessionCommand.kt | 18 ++++ .../sessions/commands/PingSessionCommand.kt | 18 ++++ .../sessions/commands/StartSessionCommand.kt | 20 +++++ .../sessions/commands/StopSessionCommand.kt | 20 +++++ .../commands/TimerSessionsCommandsRegistry.kt | 25 ++++++ .../requests/RSocketConfirmSessionRequest.kt | 7 ++ .../RSocketGetCurrentSessionRequest.kt | 11 +++ .../RSocketGetCurrentTimerStateRequest.kt | 10 +++ .../requests/RSocketJoinSessionRequest.kt | 9 ++ .../requests/RSocketLeaveSessionRequest.kt | 7 ++ .../RSocketPingCurrentSessionRequest.kt | 6 ++ .../requests/RSocketStartSessionRequest.kt | 9 ++ .../requests/RSocketStopSessionRequest.kt | 9 ++ .../sessions/types/SerializableTimerState.kt | 62 ++++++++++++++ .../rsocket/timers/types/SerializableTimer.kt | 33 ++++++++ .../timers/types/SerializableTimerSettings.kt | 42 ++++++++++ .../types/SerializableTimerSettingsPatch.kt | 15 ++++ .../users/commands/EditEmailCommand.kt | 24 ++++++ .../users/commands/EditProfileCommand.kt | 23 +++++ .../rsocket/users/commands/GetUsersCommand.kt | 20 +++++ .../users/commands/UsersCommandsRegistry.kt | 17 ++++ .../users/requests/EditEmailRequest.kt | 9 ++ .../users/requests/EditUserProfileRequest.kt | 12 +++ .../rsocket/users/requests/GetUsersRequest.kt | 13 +++ .../rsocket/users/types/SerializableAvatar.kt | 29 +++++++ .../rsocket/users/types/SerializableUser.kt | 28 +++++++ .../email/EmailAuthorizationApi.kt | 11 ++- .../requests/ConfigureNewAccountRequest.kt | 7 +- .../requests/ConfirmAuthorizationRequest.kt | 11 ++- .../requests/StartAuthorizationRequest.kt | 10 ++- .../sessions/AuthorizedSessionsApi.kt | 3 - .../GetAuthorizationSessionsRequest.kt | 11 ++- .../requests/RenewAuthorizationRequest.kt | 22 +++++ ...inateCurrentAuthorizationSessionRequest.kt | 9 +- .../sessions/types/Authorization.kt | 4 +- .../sessions/types/value/ApplicationName.kt | 12 +++ .../sessions/types/value/ClientName.kt | 12 --- ...ntalApi.kt => ExperimentalTimeMatesApi.kt} | 2 +- .../exceptions/handler/SafeExceptionResult.kt | 18 ++-- .../sdk/common/pagination/PagesIterator.kt | 8 +- .../types/AuthorizedTimeMatesRequest.kt | 18 ++++ .../sdk/common/types/TimeMatesRequest.kt | 13 ++- .../sdk/files/requests/GetFileBytesRequest.kt | 4 + .../sdk/files/requests/UploadFileRequest.kt | 6 +- .../io/timemates/sdk/files/types/FileType.kt | 2 - .../invites/requests/CreateInviteRequest.kt | 10 ++- .../invites/requests/GetInvitesRequest.kt | 10 ++- .../requests/JoinTimerByCodeRequest.kt | 18 ++++ .../invites/requests/RemoveInviteRequest.kt | 9 +- .../members/requests/GetMembersRequest.kt | 10 ++- .../members/requests/KickMemberRequest.kt | 6 +- .../sdk/timers/requests/CreateTimerRequest.kt | 9 +- .../sdk/timers/requests/EditTimerRequest.kt | 9 +- .../sdk/timers/requests/GetTimerRequest.kt | 9 +- .../timers/requests/GetUserTimersRequest.kt | 9 +- .../sdk/timers/requests/RemoveTimerRequest.kt | 6 +- .../requests/ConfirmTimerRoundRequest.kt | 10 ++- .../sessions/requests/GetTimerStateRequest.kt | 10 ++- .../requests/GetUserCurrentSessionRequest.kt | 10 ++- .../requests/JoinTimerSessionRequest.kt | 9 +- .../requests/LeaveTimerSessionRequest.kt | 10 ++- .../sessions/requests/PingSessionRequest.kt | 10 ++- .../sessions/requests/StartTimerRequest.kt | 9 +- .../sessions/requests/StopTimerRequest.kt | 9 +- .../kotlin/io/timemates/sdk/users/UserApi.kt | 3 +- .../timemates/sdk/users/profile/ProfileApi.kt | 3 +- .../profile/requests/EditProfileRequest.kt | 12 ++- .../users/profile/requests/GetUsersRequest.kt | 4 + .../timemates/sdk/users/profile/types/User.kt | 4 +- .../sdk/users/settings/UserSettingsApi.kt | 1 - .../settings/requests/EditEmailRequest.kt | 18 +++- settings.gradle.kts | 1 + 138 files changed, 2198 insertions(+), 108 deletions(-) create mode 100644 rsocket-engine/build.gradle.kts create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/CommandsRegistry.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/AuthorizationCommandsRegistry.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfigureAccountRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfirmAuthorizationRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/GetAuthorizationsRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RenewAuthorizationRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/StartAuthorizationRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/TerminateAuthorizationRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthMetadata.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorization.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorizationScope.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommands.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommandsBuilderScope.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/ext/RSocketExt.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/markers/RSocketRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/metadata/AuthorizationMetadata.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/serialization/JsonExt.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/FilesCommandsRegistry.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/GetFileCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/GetFileRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/UploadFileRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFile.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFileType.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/EditTimerCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetTimerCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/RemoveTimerCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/TimersCommandsRegistry.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/GetTimerMembersCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/KickTimerMemberCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/TimerMembersCommandsRegistry.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/CreateInviteCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/RemoveInviteCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/TimerMembersCommandsRegistry.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketCreateInviteRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketGetInvitesListRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketJoinTimerByCodeRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketRemoveInviteRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/types/SerializableInvite.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketGetMembersListRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketKickMemberRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketCreateTimerRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketDeleteTimerRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketEditTimerRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetTimerRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetUserTimersRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/ConfirmSessionCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetCurrentSessionCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetTimerStateCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/JoinSessionCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/LeaveSessionCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StartSessionCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StopSessionCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/TimerSessionsCommandsRegistry.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketConfirmSessionRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentSessionRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentTimerStateRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketJoinSessionRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketLeaveSessionRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketPingCurrentSessionRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStartSessionRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStopSessionRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/types/SerializableTimerState.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimer.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettings.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettingsPatch.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/UsersCommandsRegistry.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/EditEmailRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/EditUserProfileRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/GetUsersRequest.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableAvatar.kt create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableUser.kt create mode 100644 sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/RenewAuthorizationRequest.kt create mode 100644 sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ApplicationName.kt delete mode 100644 sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ClientName.kt rename sdk/src/commonMain/kotlin/io/timemates/sdk/common/annotations/{ExperimentalApi.kt => ExperimentalTimeMatesApi.kt} (81%) create mode 100644 sdk/src/commonMain/kotlin/io/timemates/sdk/common/types/AuthorizedTimeMatesRequest.kt create mode 100644 sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/JoinTimerByCodeRequest.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b0098e7..2d20235 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -kotlin = "1.8.21" +kotlin = "1.9.20-Beta" kotlinx-coroutines = "1.6.4" kotlinx-serialization = "1.4.1" ktor = "2.0.1" @@ -7,7 +7,7 @@ kafka = "3.3.1" jupiter = "5.4.0" exposed = "0.41.1" kmongo = "4.8.0" -androidGradlePlugin = "8.2.0-alpha13" +androidGradlePlugin = "8.3.0-alpha05" androidComposeVersion = "1.4.0-alpha02" grpc = "1.3.0" protobuf = "3.22.0" @@ -66,6 +66,8 @@ grpc-android = { module = "io.grpc:grpc-android", version.require = "1.56.1" } protobuf-kotlin = { module = "com.google.protobuf:protobuf-kotlin", version.ref = "protobuf" } protobuf-java = { module = "com.google.protobuf:protobuf-java", version.ref = "protobuf" } +rsocket-client = { module = "io.rsocket.kotlin:rsocket-ktor-client", version.require = "0.15.4" } + [plugins] kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 15de902..b982b3c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-rc-2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/GrpcTimeMatesRequestsEngine.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/GrpcTimeMatesRequestsEngine.kt index ef9f211..cdda75b 100644 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/GrpcTimeMatesRequestsEngine.kt +++ b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/GrpcTimeMatesRequestsEngine.kt @@ -143,7 +143,7 @@ public class GrpcTimeMatesRequestsEngine( .setVerificationHash(request.verificationHash.string) .build() ).let { response -> - ConfirmAuthorizationRequest.Response( + ConfirmAuthorizationRequest.Result( isNewAccount = response.isNewAccount, authorization = response.authorization.takeIf { !response.isNewAccount } ?.let(authMapper::grpcAuthorizationToSdkAuthorization), diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/AuthorizationsMapper.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/AuthorizationsMapper.kt index 15fc28c..a07e38a 100644 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/AuthorizationsMapper.kt +++ b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/AuthorizationsMapper.kt @@ -2,7 +2,7 @@ package io.timemates.api.grpc.mappers import io.timemates.api.authorizations.types.AuthorizationOuterClass.Authorization import io.timemates.sdk.authorization.sessions.types.value.ClientIpAddress -import io.timemates.sdk.authorization.sessions.types.value.ClientName +import io.timemates.sdk.authorization.sessions.types.value.ApplicationName import io.timemates.sdk.authorization.sessions.types.value.ClientVersion import io.timemates.sdk.authorization.types.value.HashValue import io.timemates.sdk.common.constructor.createOrThrow @@ -31,7 +31,7 @@ internal class AuthorizationsMapper { metadata: Authorization.Metadata, ): SdkAuthorization.Metadata = with(metadata) { return@with SdkAuthorization.Metadata( - clientName = ClientName.createOrThrow(clientName), + applicationName = ApplicationName.createOrThrow(clientName), clientVersion = ClientVersion.createOrThrow(clientVersion), clientIpAddress = ClientIpAddress.createOrThrow(clientIpAddress), ) diff --git a/rsocket-engine/build.gradle.kts b/rsocket-engine/build.gradle.kts new file mode 100644 index 0000000..1421908 --- /dev/null +++ b/rsocket-engine/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.kotlinx.serialization) + alias(libs.plugins.library.publish) +} + +kotlin { + jvm() + jvmToolchain(17) + + explicitApi() +} + +dependencies { + commonMainImplementation(projects.sdk) + + commonMainImplementation(libs.kotlinx.serialization) + commonMainImplementation(libs.kotlinx.datetime) + commonMainImplementation(libs.rsocket.client) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/CommandsRegistry.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/CommandsRegistry.kt new file mode 100644 index 0000000..ce6cd4e --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/CommandsRegistry.kt @@ -0,0 +1,20 @@ +package io.timemates.api.rsocket + +import io.timemates.api.rsocket.authorizations.commands.authorizations +import io.timemates.api.rsocket.common.commands.rSocketCommands +import io.timemates.api.rsocket.files.commands.files +import io.timemates.api.rsocket.timers.commands.timers +import io.timemates.api.rsocket.users.commands.users + +/** + * Registry for RSocket commands used in the TimeMates application. + * + * The [rSocketCommandsRegistry] is responsible for initializing and registering RSocket commands + * for specific TimeMates features or functionalities. + */ +internal val rSocketCommandsRegistry = rSocketCommands { + authorizations() + users() + files() + timers() +} diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt new file mode 100644 index 0000000..b099d39 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt @@ -0,0 +1,58 @@ +package io.timemates.api.rsocket + +import io.ktor.client.HttpClient +import io.rsocket.kotlin.ExperimentalMetadataApi +import io.rsocket.kotlin.RSocket +import io.rsocket.kotlin.ktor.client.rSocket +import io.rsocket.kotlin.metadata.RoutingMetadata +import io.rsocket.kotlin.metadata.compositeMetadata +import io.rsocket.kotlin.payload.buildPayload +import io.timemates.api.rsocket.common.markers.RSocketRequest +import io.timemates.api.rsocket.common.metadata.AuthorizationMetadata +import io.timemates.api.rsocket.common.serialization.decodeFromJson +import io.timemates.api.rsocket.common.serialization.encodeToJson +import io.timemates.api.rsocket.timers.types.sdk +import io.timemates.sdk.common.engine.TimeMatesRequestsEngine +import io.timemates.sdk.common.exceptions.UnsupportedException +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.common.types.TimeMatesEntity +import io.timemates.sdk.common.types.TimeMatesRequest +import io.timemates.sdk.timers.requests.EditTimerRequest +import io.timemates.sdk.timers.requests.GetTimerRequest +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.CoroutineStart +import kotlinx.coroutines.async +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.serializer +import io.timemates.api.rsocket.timers.requests.RSocketEditTimerRequest as RSocketEditTimerRequest +import io.timemates.api.rsocket.timers.requests.RSocketGetTimerRequest as RSocketGetTimerRequest + +/** + * Represents an engine for making requests using RSocket. + * + * @property client An instance of [HttpClient] for making HTTP requests. + * @param endpoint The RSocket endpoint URL. Defaults to "wss://api.timemates.io/v0/rsocket". + * @param coroutineScope A [CoroutineScope] tied to the RSocket lifecycle. + */ +public class RSocketTimeMatesRequestsEngine private constructor( + private val client: HttpClient, + endpoint: String = "wss://api.timemates.io/v0/rsocket", + coroutineScope: CoroutineScope, +) : TimeMatesRequestsEngine { + public companion object { + public const val API_VERSION: Int = 1 + } + + private val rSocket = coroutineScope.async(start = CoroutineStart.LAZY) { + client.rSocket(endpoint) + } + + override suspend fun execute( + request: TimeMatesRequest, + ): Result = runCatching { + val rSocket = rSocket.await() + return@runCatching rSocketCommandsRegistry.execute(rSocket, request) + ?: throw UnsupportedException("This type of request is not supported in RSocket engine.") + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/AuthorizationCommandsRegistry.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/AuthorizationCommandsRegistry.kt new file mode 100644 index 0000000..c7820d2 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/AuthorizationCommandsRegistry.kt @@ -0,0 +1,23 @@ +package io.timemates.api.rsocket.authorizations.commands + +import io.timemates.api.rsocket.common.commands.RSocketCommandsBuilderScope +import io.timemates.sdk.authorization.email.requests.ConfigureNewAccountRequest +import io.timemates.sdk.authorization.email.requests.ConfirmAuthorizationRequest +import io.timemates.sdk.authorization.email.requests.StartAuthorizationRequest +import io.timemates.sdk.authorization.sessions.requests.GetAuthorizationSessionsRequest +import io.timemates.sdk.authorization.sessions.requests.RenewAuthorizationRequest +import io.timemates.sdk.authorization.sessions.requests.TerminateCurrentAuthorizationSessionRequest +import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi + +/** + * The commands that is connected to the authorization feature. + */ +@OptIn(ExperimentalTimeMatesApi::class) +internal fun RSocketCommandsBuilderScope.authorizations() { + StartAuthorizationCommand associatedWith StartAuthorizationRequest + ConfirmAuthorizationCommand associatedWith ConfirmAuthorizationRequest + ConfigureNewAccountCommand associatedWith ConfigureNewAccountRequest + GetAuthorizationSessionsCommand associatedWith GetAuthorizationSessionsRequest + TerminateCurrentAuthorizationCommand associatedWith TerminateCurrentAuthorizationSessionRequest + RenewAuthorizationCommand associatedWith RenewAuthorizationRequest +} diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt new file mode 100644 index 0000000..5345bcd --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt @@ -0,0 +1,25 @@ +package io.timemates.api.rsocket.authorizations.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.authorizations.types.sdk +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.sdk.authorization.email.requests.ConfigureNewAccountRequest +import io.timemates.api.rsocket.authorizations.requests.ConfigureAccountRequest as RSocketConfigureAccountRequest + +internal object ConfigureNewAccountCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: ConfigureNewAccountRequest): ConfigureNewAccountRequest.Result { + return rSocket.requestResponse( + route = "authorizations.account.configure", + data = RSocketConfigureAccountRequest( + verificationHash = input.verificationHash.string, + name = input.name.string, + description = input.description?.string, + ) + ).let { result -> + ConfigureNewAccountRequest.Result( + authorization = result.authorization.sdk() + ) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt new file mode 100644 index 0000000..bdfebe8 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt @@ -0,0 +1,24 @@ +package io.timemates.api.rsocket.authorizations.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.authorizations.types.sdk +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.sdk.authorization.email.requests.ConfirmAuthorizationRequest +import io.timemates.api.rsocket.authorizations.requests.ConfirmAuthorizationRequest as RSocketConfirmAuthorizationRequest + +internal object ConfirmAuthorizationCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: ConfirmAuthorizationRequest): ConfirmAuthorizationRequest.Result { + return rSocket.requestResponse( + route = "authorizations.email.confirm", + data = RSocketConfirmAuthorizationRequest( + input.verificationHash.string, input.confirmationCode.string + ) + ).let { result -> + ConfirmAuthorizationRequest.Result( + isNewAccount = result.isNewAccount, + authorization = result.authorization?.sdk(), + ) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt new file mode 100644 index 0000000..33b0b84 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt @@ -0,0 +1,28 @@ +package io.timemates.api.rsocket.authorizations.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.authorizations.requests.GetAuthorizationsRequest +import io.timemates.api.rsocket.authorizations.types.SerializableAuthorization +import io.timemates.api.rsocket.authorizations.types.sdk +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.sdk.authorization.sessions.requests.GetAuthorizationSessionsRequest +import io.timemates.sdk.authorization.sessions.types.Authorization +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.common.pagination.Page +import io.timemates.sdk.common.pagination.PageToken + +internal object GetAuthorizationSessionsCommand : RSocketCommand> { + override suspend fun execute(rSocket: RSocket, input: GetAuthorizationSessionsRequest): Page { + return rSocket.requestResponse( + route = "authorizations.list", + data = GetAuthorizationsRequest(input.nextPageToken?.string), + accessHash = input.accessHash.string, + ).let { result -> + Page( + results = result.list.map(SerializableAuthorization::sdk), + nextPageToken = result.nextPageToken?.let { PageToken.createOrThrow(it) } + ) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt new file mode 100644 index 0000000..ba7bbfd --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt @@ -0,0 +1,24 @@ +package io.timemates.api.rsocket.authorizations.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.sdk.authorization.sessions.requests.RenewAuthorizationRequest +import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.api.rsocket.authorizations.requests.RenewAuthorizationRequest as RSocketRenewAuthorizationRequest + +@OptIn(ExperimentalTimeMatesApi::class) +internal object RenewAuthorizationCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: RenewAuthorizationRequest): RenewAuthorizationRequest.Result { + return rSocket.requestResponse( + route = "authorizations.renew", + data = RSocketRenewAuthorizationRequest(input.refreshHash.string), + ).let { result -> + RenewAuthorizationRequest.Result( + AccessHash.createOrThrow(result.accessHash) + ) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt new file mode 100644 index 0000000..8394eb8 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt @@ -0,0 +1,33 @@ +package io.timemates.api.rsocket.authorizations.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.authorizations.types.serializable +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.sdk.authorization.email.requests.StartAuthorizationRequest +import io.timemates.sdk.authorization.email.types.value.VerificationHash +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.common.types.value.Count +import kotlinx.datetime.Instant +import io.timemates.api.rsocket.authorizations.requests.StartAuthorizationRequest as RSocketStartAuthorizationRequest + +internal object StartAuthorizationCommand : RSocketCommand { + override suspend fun execute( + rSocket: RSocket, + input: StartAuthorizationRequest, + ): StartAuthorizationRequest.Result { + return rSocket.requestResponse( + route = "authorizations.email.start", + data = RSocketStartAuthorizationRequest( + input.emailAddress.string, + input.metadata.serializable(), + ) + ).let { result -> + StartAuthorizationRequest.Result( + verificationHash = VerificationHash.createOrThrow(result.verificationHash), + attempts = Count.createOrThrow(result.attempts), + expiresAt = Instant.fromEpochMilliseconds(result.expiresAt), + ) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt new file mode 100644 index 0000000..c99e1f9 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt @@ -0,0 +1,18 @@ +package io.timemates.api.rsocket.authorizations.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.authorizations.requests.TerminateAuthorizationRequest +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.sdk.authorization.sessions.requests.TerminateCurrentAuthorizationSessionRequest +import io.timemates.sdk.common.types.Empty + +internal object TerminateCurrentAuthorizationCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: TerminateCurrentAuthorizationSessionRequest): Empty { + return rSocket.requestResponse( + route = "authorizations.terminate", + data = TerminateAuthorizationRequest.Current, + accessHash = input.accessHash.string, + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfigureAccountRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfigureAccountRequest.kt new file mode 100644 index 0000000..8f0a72a --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfigureAccountRequest.kt @@ -0,0 +1,17 @@ +package io.timemates.api.rsocket.authorizations.requests + +import io.timemates.api.rsocket.authorizations.types.SerializableAuthorization +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data class ConfigureAccountRequest( + val verificationHash: String, + val name: String, + val description: String?, +) : RSocketRequest { + @Serializable + data class Result( + val authorization: SerializableAuthorization, + ) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfirmAuthorizationRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfirmAuthorizationRequest.kt new file mode 100644 index 0000000..a8fb57d --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfirmAuthorizationRequest.kt @@ -0,0 +1,16 @@ +package io.timemates.api.rsocket.authorizations.requests + +import io.timemates.api.rsocket.authorizations.types.SerializableAuthorization +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data class ConfirmAuthorizationRequest( + val verificationHash: String, + val confirmationCode: String, +) : RSocketRequest { + data class Response( + val isNewAccount: Boolean, + val authorization: SerializableAuthorization?, + ) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/GetAuthorizationsRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/GetAuthorizationsRequest.kt new file mode 100644 index 0000000..f191ad6 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/GetAuthorizationsRequest.kt @@ -0,0 +1,14 @@ +package io.timemates.api.rsocket.authorizations.requests + +import io.timemates.api.rsocket.authorizations.types.SerializableAuthorization +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data class GetAuthorizationsRequest( + val pageToken: String? = null, +) : RSocketRequest { + + @Serializable + data class Result(val list: List, val nextPageToken: String?) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RenewAuthorizationRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RenewAuthorizationRequest.kt new file mode 100644 index 0000000..1656599 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RenewAuthorizationRequest.kt @@ -0,0 +1,12 @@ +package io.timemates.api.rsocket.authorizations.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data class RenewAuthorizationRequest( + val refreshHash: String, +) : RSocketRequest { + @Serializable + data class Result(val accessHash: String) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/StartAuthorizationRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/StartAuthorizationRequest.kt new file mode 100644 index 0000000..8904e26 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/StartAuthorizationRequest.kt @@ -0,0 +1,18 @@ +package io.timemates.api.rsocket.authorizations.requests + +import io.timemates.api.rsocket.authorizations.types.SerializableAuthMetadata +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data class StartAuthorizationRequest( + val email: String, + val clientMetadata: SerializableAuthMetadata, +) : RSocketRequest { + @Serializable + data class Result( + val verificationHash: String, + val expiresAt: Long, + val attempts: Int, + ) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/TerminateAuthorizationRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/TerminateAuthorizationRequest.kt new file mode 100644 index 0000000..5bcdba0 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/TerminateAuthorizationRequest.kt @@ -0,0 +1,15 @@ +package io.timemates.api.rsocket.authorizations.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +internal sealed class TerminateAuthorizationRequest : RSocketRequest { + /** + * This type of termination request terminates authorization with which + * user has sent termination request. + */ + @SerialName("current") + data object Current : TerminateAuthorizationRequest() +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthMetadata.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthMetadata.kt new file mode 100644 index 0000000..e9c7ac5 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthMetadata.kt @@ -0,0 +1,17 @@ +package io.timemates.api.rsocket.authorizations.types + +import io.timemates.sdk.authorization.sessions.types.Authorization +import kotlinx.serialization.Serializable + +@Serializable +internal data class SerializableAuthMetadata( + val applicationName: String, + val clientVersion: String, + val clientIpAddress: String?, +) + +internal fun Authorization.Metadata.serializable(): SerializableAuthMetadata = SerializableAuthMetadata( + applicationName = applicationName.string, + clientVersion = clientVersion.string, + clientIpAddress = clientIpAddress.string, +) \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorization.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorization.kt new file mode 100644 index 0000000..b3eabca --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorization.kt @@ -0,0 +1,19 @@ +package io.timemates.api.rsocket.authorizations.types + +import io.timemates.sdk.authorization.sessions.types.Authorization +import kotlinx.serialization.Serializable + +@Serializable +internal data class SerializableAuthorization( + val userId: Long, + val accessHash: String, + val refreshAccessHash: String, + val scopes: List, + // todo expiresAt for refresh hash + val expiresAt: Long, + val createdAt: Long, + val clientMetadata: SerializableAuthMetadata, +) + +// todo expiresAt for refresh hash +internal fun SerializableAuthorization.sdk(): Authorization = TODO() \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorizationScope.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorizationScope.kt new file mode 100644 index 0000000..3840ab7 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorizationScope.kt @@ -0,0 +1,34 @@ +package io.timemates.api.rsocket.authorizations.types + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +internal sealed interface SerializableAuthorizationScope { + @SerialName("super") + data object All : SerializableAuthorizationScope + + @SerialName("auth:read") + data object AuthRead : SerializableAuthorizationScope + + @SerialName("auth:write") + data object AuthWrite : SerializableAuthorizationScope + + @SerialName("users:read") + data object UsersRead : SerializableAuthorizationScope + + @SerialName("users:write") + data object UsersWrite : SerializableAuthorizationScope + + @SerialName("timers:read") + data object TimersRead : SerializableAuthorizationScope + + @SerialName("timers:write") + data object TimersWrite : SerializableAuthorizationScope + + @SerialName("files:read") + data object FilesRead : SerializableAuthorizationScope + + @SerialName("files:write") + data object FilesWrite : SerializableAuthorizationScope +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommand.kt new file mode 100644 index 0000000..5c2f583 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommand.kt @@ -0,0 +1,26 @@ +package io.timemates.api.rsocket.common.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.sdk.common.types.TimeMatesEntity +import io.timemates.sdk.common.types.TimeMatesRequest + +/** + * An interface representing a command that can be executed via an RSocket connection. + * + * This interface is used to decouple logic by accepting an SDK entity of type [T] + * and converting it into the engine's entity type [R] within the implementation. + * + * @param T The type of the SDK entity that serves as the command's input. + * @param R The type of the engine's entity that represents the command's result. + */ +internal interface RSocketCommand, R : TimeMatesEntity> { + /** + * Executes the command using the provided RSocket connection and input of type [T]. + * + * @param rSocket The RSocket connection over which the command will be executed. + * @param input The SDK entity representing the command's input. + * @return The engine's entity representing the result of executing the command. + * @throws RSocketException if there is an issue with the RSocket communication. + */ + suspend fun execute(rSocket: RSocket, input: T): R +} diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommands.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommands.kt new file mode 100644 index 0000000..a235cc4 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommands.kt @@ -0,0 +1,38 @@ +package io.timemates.api.rsocket.common.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.sdk.common.types.TimeMatesEntity +import io.timemates.sdk.common.types.TimeMatesRequest + +/** + * An inline class that encapsulates a set of RSocket commands for executing TimeMates requests. + * + * The [RSocketCommands] class allows you to execute TimeMates requests using the provided RSocket + * instance. It maintains a map of commands associated with request keys, which are used to look up + * the appropriate command for a given request. + * + * @param commands A map of request keys to RSocket command implementations. + */ +@JvmInline +internal value class RSocketCommands( + private val commands: Map, RSocketCommand<*, *>>, +) { + /** + * Executes a TimeMates request using the specified RSocket instance. + * + * This function looks up the appropriate RSocket command based on the request's [requestKey] + * and executes it with the provided RSocket and request object. + * + * @param T The specific type of the TimeMates request. + * @param R The type of the response expected from the request. + * @param rSocket The RSocket instance to use for executing the request. + * @param request The TimeMates request to execute. + */ + suspend inline fun , R : TimeMatesEntity> execute( + rSocket: RSocket, + request: T, + ): R? { + @Suppress("UNCHECKED_CAST") + return (commands[request.requestKey] as? RSocketCommand)?.execute(rSocket, request) + } +} diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommandsBuilderScope.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommandsBuilderScope.kt new file mode 100644 index 0000000..2889876 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommandsBuilderScope.kt @@ -0,0 +1,37 @@ +package io.timemates.api.rsocket.common.commands + +import io.timemates.sdk.common.types.TimeMatesEntity +import io.timemates.sdk.common.types.TimeMatesRequest + +@RSocketCommandsDsl +@JvmInline +internal value class RSocketCommandsBuilderScope( + private val commands: MutableMap, RSocketCommand<*, *>> = + mutableMapOf(), +) { + fun , R : TimeMatesEntity> associate( + key: TimeMatesRequest.Key, + command: RSocketCommand, + ) { + commands += key to command + } + + + infix fun , R : TimeMatesEntity> RSocketCommand.associatedWith( + key: TimeMatesRequest.Key, + ) { + associate(key, this) + } + + fun build(): RSocketCommands = RSocketCommands(commands) +} + +@DslMarker +internal annotation class RSocketCommandsDsl + +@RSocketCommandsDsl +internal inline fun rSocketCommands( + block: RSocketCommandsBuilderScope.() -> Unit, +): RSocketCommands { + return RSocketCommandsBuilderScope().apply(block).build() +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/ext/RSocketExt.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/ext/RSocketExt.kt new file mode 100644 index 0000000..853e9dd --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/ext/RSocketExt.kt @@ -0,0 +1,84 @@ +package io.timemates.api.rsocket.common.ext + +import io.rsocket.kotlin.ExperimentalMetadataApi +import io.rsocket.kotlin.RSocket +import io.rsocket.kotlin.metadata.RoutingMetadata +import io.rsocket.kotlin.metadata.compositeMetadata +import io.rsocket.kotlin.payload.Payload +import io.rsocket.kotlin.payload.buildPayload +import io.timemates.api.rsocket.common.markers.RSocketRequest +import io.timemates.api.rsocket.common.metadata.AuthorizationMetadata +import io.timemates.api.rsocket.common.serialization.decodeFromJson +import io.timemates.api.rsocket.common.serialization.encodeToJson +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.serializer + +internal suspend inline fun , reified R> RSocket.requestResponse( + route: String, + data: T, + accessHash: String? = null, +): R = requestResponse(route, serializer(), serializer(), data, accessHash) + +internal suspend inline fun > RSocket.fireAndForget( + route: String, + data: T, + accessHash: String? = null, +): Unit = fireAndForget(route, serializer(), data, accessHash) + +internal inline fun , reified R> RSocket.requestStream( + route: String, + data: T, + accessHash: String? = null, +): Flow = requestStream(route, serializer(), serializer(), data, accessHash) + +internal suspend fun RSocket.requestResponse( + route: String, + dataSerStrategy: SerializationStrategy, + resultDeSerStrategy: DeserializationStrategy, + data: T, + accessHash: String? = null, +): R { + val payload = createPayload(route, data, dataSerStrategy, accessHash) + return requestResponse(payload).decodeFromJson(resultDeSerStrategy) +} + +internal fun RSocket.requestStream( + route: String, + dataSerStrategy: SerializationStrategy, + resultDeSerStrategy: DeserializationStrategy, + data: T, + accessHash: String? = null, +): Flow { + val payload = createPayload(route, data, dataSerStrategy, accessHash) + return requestStream(payload).map { it.decodeFromJson(resultDeSerStrategy) } +} + +internal suspend fun RSocket.fireAndForget( + route: String, + dataSerStrategy: SerializationStrategy, + data: T, + accessHash: String? = null, +) { + val payload = createPayload(route, data, dataSerStrategy, accessHash) + return fireAndForget(payload) +} + +@OptIn(ExperimentalMetadataApi::class) +private fun createPayload( + route: String, + data: T, + dataSerStrategy: SerializationStrategy, + accessHash: String?, +): Payload { + return buildPayload { + compositeMetadata { + add(RoutingMetadata(route)) + if (accessHash != null) + add(AuthorizationMetadata(accessHash)) + } + data(data.encodeToJson(dataSerStrategy)) + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/markers/RSocketRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/markers/RSocketRequest.kt new file mode 100644 index 0000000..1a545ea --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/markers/RSocketRequest.kt @@ -0,0 +1,8 @@ +package io.timemates.api.rsocket.common.markers + +/** + * Interface-marker for all RSocket requests. + * + * @param R response type of the request. + */ +internal interface RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/metadata/AuthorizationMetadata.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/metadata/AuthorizationMetadata.kt new file mode 100644 index 0000000..38401da --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/metadata/AuthorizationMetadata.kt @@ -0,0 +1,37 @@ +package io.timemates.api.rsocket.common.metadata + +import io.ktor.utils.io.core.BytePacketBuilder +import io.ktor.utils.io.core.ByteReadPacket +import io.ktor.utils.io.core.internal.ChunkBuffer +import io.ktor.utils.io.core.isNotEmpty +import io.ktor.utils.io.core.readTextExactBytes +import io.ktor.utils.io.core.writeFully +import io.ktor.utils.io.pool.ObjectPool +import io.rsocket.kotlin.ExperimentalMetadataApi +import io.rsocket.kotlin.core.MimeType +import io.rsocket.kotlin.core.WellKnownMimeType +import io.rsocket.kotlin.metadata.Metadata +import io.rsocket.kotlin.metadata.MetadataReader + +@ExperimentalMetadataApi +internal class AuthorizationMetadata(val authorization: String) : Metadata { + + override val mimeType: MimeType get() = Reader.mimeType + + override fun BytePacketBuilder.writeSelf() { + val bytes = authorization.encodeToByteArray() + writeByte(bytes.size.toByte()) + writeFully(bytes) + } + + override fun close(): Unit = Unit + + companion object Reader : MetadataReader { + override val mimeType: MimeType get() = WellKnownMimeType.MessageRSocketRouting + override fun ByteReadPacket.read(pool: ObjectPool): AuthorizationMetadata { + return AuthorizationMetadata( + readTextExactBytes(readByte().toInt() and 0xFF) + ) + } + } +} diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/serialization/JsonExt.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/serialization/JsonExt.kt new file mode 100644 index 0000000..ee8b7ff --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/serialization/JsonExt.kt @@ -0,0 +1,23 @@ +package io.timemates.api.rsocket.common.serialization + +import io.ktor.utils.io.core.ByteReadPacket +import io.ktor.utils.io.streams.inputStream +import io.rsocket.kotlin.payload.Payload +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.decodeFromStream + +private val json = Json { + ignoreUnknownKeys = true +} + +internal fun T.encodeToJson(serializationStrategy: SerializationStrategy): ByteReadPacket { + return ByteReadPacket(json.encodeToString(serializationStrategy, this).encodeToByteArray()) +} + +@OptIn(ExperimentalSerializationApi::class) +internal fun Payload.decodeFromJson(deserializationStrategy: DeserializationStrategy): T { + return json.decodeFromStream(deserializationStrategy, data.inputStream()) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/FilesCommandsRegistry.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/FilesCommandsRegistry.kt new file mode 100644 index 0000000..5b18e95 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/FilesCommandsRegistry.kt @@ -0,0 +1,11 @@ +package io.timemates.api.rsocket.files.commands + +import io.timemates.api.rsocket.common.commands.RSocketCommandsBuilderScope +import io.timemates.sdk.files.requests.GetFileBytesRequest + +/** + * RSocket commands related to timers. + */ +internal fun RSocketCommandsBuilderScope.files() { + GetFileCommand associatedWith GetFileBytesRequest +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/GetFileCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/GetFileCommand.kt new file mode 100644 index 0000000..9115fb6 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/GetFileCommand.kt @@ -0,0 +1,22 @@ +package io.timemates.api.rsocket.files.commands + +import io.rsocket.kotlin.RSocket +import io.rsocket.kotlin.payload.buildPayload +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.serialization.encodeToJson +import io.timemates.api.rsocket.files.requests.GetFileRequest +import io.timemates.sdk.files.requests.GetFileBytesRequest +import kotlinx.serialization.serializer + +internal object GetFileCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: GetFileBytesRequest): GetFileBytesRequest.Result { + return rSocket.requestResponse( + buildPayload { + data(GetFileRequest(input.fileId.string).encodeToJson(serializer())) + } + ).let { result -> +// GetFileBytesRequest.Result(result.data) + TODO() + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/GetFileRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/GetFileRequest.kt new file mode 100644 index 0000000..8858a0f --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/GetFileRequest.kt @@ -0,0 +1,19 @@ +package io.timemates.api.rsocket.files.requests + +import io.timemates.api.rsocket.files.types.SerializableFileType +import kotlinx.serialization.Serializable + +@Serializable +internal data class GetFileRequest( + val fileId: String, +) { + @Serializable + sealed interface Response { + data class Metadata( + val fileType: SerializableFileType, + ) : Response + + @JvmInline + value class Chunk(val bytes: ByteArray) : Response + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/UploadFileRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/UploadFileRequest.kt new file mode 100644 index 0000000..ccc8809 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/UploadFileRequest.kt @@ -0,0 +1,17 @@ +package io.timemates.api.rsocket.files.requests + +import io.timemates.api.rsocket.files.types.SerializableFileType +import kotlinx.coroutines.flow.Flow +import kotlinx.serialization.Serializable + +@Serializable +internal data class UploadFileRequest( + val fileType: SerializableFileType, + val bytes: Flow, +) { + @Serializable + data class Metadata(val fileName: String, val fileType: SerializableFileType) + + @Serializable + data class Response(val fileId: String) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFile.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFile.kt new file mode 100644 index 0000000..9a48d2b --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFile.kt @@ -0,0 +1,15 @@ +package io.timemates.api.rsocket.files.types + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +internal sealed class SerializableFile { + abstract val fileId: String + + /** + * File with image. + */ + @SerialName("image") + data class Image(override val fileId: String) : SerializableFile() +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFileType.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFileType.kt new file mode 100644 index 0000000..0c6f69e --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFileType.kt @@ -0,0 +1,10 @@ +package io.timemates.api.rsocket.files.types + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +internal enum class SerializableFileType { + @SerialName("image") + IMAGE, +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt new file mode 100644 index 0000000..0c615fd --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt @@ -0,0 +1,26 @@ +package io.timemates.api.rsocket.timers.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.timers.types.serializable +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.timers.requests.CreateTimerRequest +import io.timemates.sdk.timers.types.value.TimerId +import io.timemates.api.rsocket.timers.requests.RSocketCreateTimerRequest as RSocketCreateTimerRequest + +internal object CreateTimerCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: CreateTimerRequest): CreateTimerRequest.Result { + return rSocket.requestResponse( + route = "timers.create", + data = RSocketCreateTimerRequest( + name = input.name.string, + description = input.description.string, + settings = input.settings.serializable() + ), + accessHash = input.accessHash.string, + ).let { result -> + CreateTimerRequest.Result(TimerId.createOrThrow(result.timerId)) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/EditTimerCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/EditTimerCommand.kt new file mode 100644 index 0000000..4c9e078 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/EditTimerCommand.kt @@ -0,0 +1,22 @@ +package io.timemates.api.rsocket.timers.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.requests.CreateTimerRequest +import io.timemates.sdk.timers.requests.EditTimerRequest +import io.timemates.api.rsocket.timers.requests.RSocketEditTimerRequest as RSocketEditTimerRequest + +internal object EditTimerCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: EditTimerRequest): Empty { + return rSocket.requestResponse( + route = "timers.edit", + data = RSocketEditTimerRequest( + timerId = input.timerId.long, + name = input.name?.string, + ), + accessHash = input.accessHash.string, + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetTimerCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetTimerCommand.kt new file mode 100644 index 0000000..4c8ad12 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetTimerCommand.kt @@ -0,0 +1,27 @@ +package io.timemates.api.rsocket.timers.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.timers.requests.RSocketGetTimerRequest +import io.timemates.api.rsocket.timers.types.sdk +import io.timemates.api.rsocket.timers.types.serializable +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.timers.requests.CreateTimerRequest +import io.timemates.sdk.timers.requests.GetTimerRequest +import io.timemates.sdk.timers.types.value.TimerId +import io.timemates.api.rsocket.timers.requests.RSocketCreateTimerRequest as RSocketCreateTimerRequest + +internal object GetTimerCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: GetTimerRequest): GetTimerRequest.Result { + return rSocket.requestResponse( + route = "timers.get", + data = RSocketGetTimerRequest( + timerId = input.timerId.long, + ), + accessHash = input.accessHash.string, + ).let { result -> + GetTimerRequest.Result(result.timer.sdk()) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt new file mode 100644 index 0000000..54b983a --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt @@ -0,0 +1,30 @@ +package io.timemates.api.rsocket.timers.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.timers.requests.RSocketGetUserTimersRequest +import io.timemates.api.rsocket.timers.types.SerializableTimer +import io.timemates.api.rsocket.timers.types.sdk +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.common.pagination.Page +import io.timemates.sdk.common.pagination.PageToken +import io.timemates.sdk.timers.requests.GetUserTimersRequest +import io.timemates.sdk.timers.types.Timer + +internal object GetUserTimersCommand : RSocketCommand> { + override suspend fun execute(rSocket: RSocket, input: GetUserTimersRequest): Page { + return rSocket.requestResponse( + route = "timers.user.list", + data = RSocketGetUserTimersRequest( + pageToken = input.pageToken?.string, + ), + accessHash = input.accessHash.string, + ).let { result -> + Page( + results = result.list.map(SerializableTimer::sdk), + nextPageToken = result.nextPageToken?.let { PageToken.createOrThrow(it) }, + ) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/RemoveTimerCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/RemoveTimerCommand.kt new file mode 100644 index 0000000..8a19ffb --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/RemoveTimerCommand.kt @@ -0,0 +1,18 @@ +package io.timemates.api.rsocket.timers.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.requests.RemoveTimerRequest +import io.timemates.api.rsocket.timers.requests.RSocketDeleteTimerRequest as RSocketDeleteTimerRequest + +internal object RemoveTimerCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: RemoveTimerRequest): Empty { + return rSocket.requestResponse( + route = "timers.delete", + data = RSocketDeleteTimerRequest(input.timerId.long), + accessHash = input.accessHash.string, + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/TimersCommandsRegistry.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/TimersCommandsRegistry.kt new file mode 100644 index 0000000..ad3f892 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/TimersCommandsRegistry.kt @@ -0,0 +1,24 @@ +package io.timemates.api.rsocket.timers.commands + +import io.timemates.api.rsocket.common.commands.RSocketCommandsBuilderScope +import io.timemates.api.rsocket.timers.members.commands.timerMembers +import io.timemates.api.rsocket.timers.sessions.commands.timerSessions +import io.timemates.sdk.timers.requests.CreateTimerRequest +import io.timemates.sdk.timers.requests.EditTimerRequest +import io.timemates.sdk.timers.requests.GetTimerRequest +import io.timemates.sdk.timers.requests.GetUserTimersRequest +import io.timemates.sdk.timers.requests.RemoveTimerRequest + +/** + * RSocket commands related to timers. + */ +internal fun RSocketCommandsBuilderScope.timers() { + timerMembers() + timerSessions() + + CreateTimerCommand associatedWith CreateTimerRequest + EditTimerCommand associatedWith EditTimerRequest + GetTimerCommand associatedWith GetTimerRequest + RemoveTimerCommand associatedWith RemoveTimerRequest + GetUserTimersCommand associatedWith GetUserTimersRequest +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/GetTimerMembersCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/GetTimerMembersCommand.kt new file mode 100644 index 0000000..f7a1cdb --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/GetTimerMembersCommand.kt @@ -0,0 +1,36 @@ +package io.timemates.api.rsocket.timers.members.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.timers.members.requests.RSocketGetMembersListRequest +import io.timemates.api.rsocket.timers.requests.RSocketGetUserTimersRequest +import io.timemates.api.rsocket.timers.types.SerializableTimer +import io.timemates.api.rsocket.timers.types.sdk +import io.timemates.api.rsocket.users.types.SerializableUser +import io.timemates.api.rsocket.users.types.sdk +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.common.pagination.Page +import io.timemates.sdk.common.pagination.PageToken +import io.timemates.sdk.timers.members.requests.GetMembersRequest +import io.timemates.sdk.timers.requests.GetUserTimersRequest +import io.timemates.sdk.timers.types.Timer +import io.timemates.sdk.users.profile.types.User + +internal object GetTimerMembersCommand : RSocketCommand> { + override suspend fun execute(rSocket: RSocket, input: GetMembersRequest): Page { + return rSocket.requestResponse( + route = "timers.user.list", + data = RSocketGetMembersListRequest( + timerId = input.timerId.long, + pageToken = input.pageToken?.string, + ), + accessHash = input.accessHash.string, + ).let { result -> + Page( + results = result.list.map(SerializableUser::sdk), + nextPageToken = result.nextPageToken?.let { PageToken.createOrThrow(it) }, + ) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/KickTimerMemberCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/KickTimerMemberCommand.kt new file mode 100644 index 0000000..758cc86 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/KickTimerMemberCommand.kt @@ -0,0 +1,19 @@ +package io.timemates.api.rsocket.timers.members.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.members.requests.KickMemberRequest +import io.timemates.sdk.timers.requests.RemoveTimerRequest +import io.timemates.api.rsocket.timers.requests.RSocketDeleteTimerRequest as RSocketDeleteTimerRequest + +internal object KickTimerMemberCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: KickMemberRequest): Empty { + return rSocket.requestResponse( + route = "timers.members.kick", + data = RSocketDeleteTimerRequest(input.timerId.long), + accessHash = input.accessHash.string, + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/TimerMembersCommandsRegistry.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/TimerMembersCommandsRegistry.kt new file mode 100644 index 0000000..e21024f --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/TimerMembersCommandsRegistry.kt @@ -0,0 +1,20 @@ +package io.timemates.api.rsocket.timers.members.commands + +import io.timemates.api.rsocket.common.commands.RSocketCommandsBuilderScope +import io.timemates.api.rsocket.timers.members.invites.commands.timerMemberInvites +import io.timemates.sdk.timers.members.requests.GetMembersRequest +import io.timemates.sdk.timers.members.requests.KickMemberRequest +import io.timemates.sdk.timers.requests.CreateTimerRequest +import io.timemates.sdk.timers.requests.EditTimerRequest +import io.timemates.sdk.timers.requests.GetTimerRequest +import io.timemates.sdk.timers.requests.RemoveTimerRequest + +/** + * RSocket commands related to timer members. + */ +internal fun RSocketCommandsBuilderScope.timerMembers() { + timerMemberInvites() + + GetTimerMembersCommand associatedWith GetMembersRequest + KickTimerMemberCommand associatedWith KickMemberRequest +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/CreateInviteCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/CreateInviteCommand.kt new file mode 100644 index 0000000..b552478 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/CreateInviteCommand.kt @@ -0,0 +1,28 @@ +package io.timemates.api.rsocket.timers.members.invites.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.timers.members.invites.requests.RSocketCreateInviteRequest +import io.timemates.api.rsocket.timers.types.serializable +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.timers.members.invites.requests.CreateInviteRequest +import io.timemates.sdk.timers.members.invites.types.value.InviteCode +import io.timemates.sdk.timers.requests.CreateTimerRequest +import io.timemates.sdk.timers.types.value.TimerId +import io.timemates.api.rsocket.timers.requests.RSocketCreateTimerRequest as RSocketCreateTimerRequest + +internal object CreateInviteCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: CreateInviteRequest): CreateInviteRequest.Result { + return rSocket.requestResponse( + route = "timers.members.invites.create", + data = RSocketCreateInviteRequest( + timerId = input.timerId.long, + maxJoiners = input.maxJoinersCount.int, + ), + accessHash = input.accessHash.string, + ).let { result -> + CreateInviteRequest.Result(InviteCode.createOrThrow(result.inviteCode)) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt new file mode 100644 index 0000000..9ae809f --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt @@ -0,0 +1,31 @@ +package io.timemates.api.rsocket.timers.members.invites.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.timers.members.invites.requests.RSocketGetInvitesListRequest +import io.timemates.api.rsocket.timers.members.invites.types.SerializableInvite +import io.timemates.api.rsocket.timers.members.invites.types.sdk +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.common.pagination.Page +import io.timemates.sdk.common.pagination.PageToken +import io.timemates.sdk.timers.members.invites.requests.GetInvitesRequest +import io.timemates.sdk.timers.members.invites.types.Invite + +internal object GetInvitesCommand : RSocketCommand> { + override suspend fun execute(rSocket: RSocket, input: GetInvitesRequest): Page { + return rSocket.requestResponse( + route = "timers.user.list", + data = RSocketGetInvitesListRequest( + timerId = input.timerId.long, + pageToken = input.pageToken?.string, + ), + accessHash = input.accessHash.string, + ).let { result -> + Page( + results = result.invites.map(SerializableInvite::sdk), + nextPageToken = result.nextPageToken?.let { PageToken.createOrThrow(it) }, + ) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt new file mode 100644 index 0000000..99348f8 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt @@ -0,0 +1,27 @@ +package io.timemates.api.rsocket.timers.members.invites.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.timers.members.invites.requests.RSocketCreateInviteRequest +import io.timemates.api.rsocket.timers.members.invites.requests.RSocketJoinTimerByCodeRequest +import io.timemates.api.rsocket.timers.types.serializable +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.timers.members.invites.requests.JoinTimerByCodeRequest +import io.timemates.sdk.timers.requests.CreateTimerRequest +import io.timemates.sdk.timers.types.value.TimerId +import io.timemates.api.rsocket.timers.requests.RSocketCreateTimerRequest as RSocketCreateTimerRequest + +internal object JoinTimerByCodeCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: JoinTimerByCodeRequest): JoinTimerByCodeRequest.Result { + return rSocket.requestResponse( + route = "timers.create", + data = RSocketJoinTimerByCodeRequest( + code = input.code.string, + ), + accessHash = input.accessHash.string, + ).let { result -> + JoinTimerByCodeRequest.Result(TimerId.createOrThrow(result.timerId)) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/RemoveInviteCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/RemoveInviteCommand.kt new file mode 100644 index 0000000..5de7b45 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/RemoveInviteCommand.kt @@ -0,0 +1,24 @@ +package io.timemates.api.rsocket.timers.members.invites.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.timers.members.invites.requests.RSocketRemoveInviteRequest +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.members.invites.requests.RemoveInviteRequest +import io.timemates.sdk.timers.members.requests.KickMemberRequest +import io.timemates.sdk.timers.requests.RemoveTimerRequest +import io.timemates.api.rsocket.timers.requests.RSocketDeleteTimerRequest as RSocketDeleteTimerRequest + +internal object RemoveInviteCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: RemoveInviteRequest): Empty { + return rSocket.requestResponse( + route = "timers.members.kick", + data = RSocketRemoveInviteRequest( + timerId = input.timerId.long, + code = input.inviteCode.string, + ), + accessHash = input.accessHash.string, + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/TimerMembersCommandsRegistry.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/TimerMembersCommandsRegistry.kt new file mode 100644 index 0000000..ad64e2a --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/TimerMembersCommandsRegistry.kt @@ -0,0 +1,17 @@ +package io.timemates.api.rsocket.timers.members.invites.commands + +import io.timemates.api.rsocket.common.commands.RSocketCommandsBuilderScope +import io.timemates.sdk.timers.members.invites.requests.CreateInviteRequest +import io.timemates.sdk.timers.members.invites.requests.GetInvitesRequest +import io.timemates.sdk.timers.members.invites.requests.JoinTimerByCodeRequest +import io.timemates.sdk.timers.members.invites.requests.RemoveInviteRequest + +/** + * RSocket commands related to timer members. + */ +internal fun RSocketCommandsBuilderScope.timerMemberInvites() { + CreateInviteCommand associatedWith CreateInviteRequest + GetInvitesCommand associatedWith GetInvitesRequest + JoinTimerByCodeCommand associatedWith JoinTimerByCodeRequest + RemoveInviteCommand associatedWith RemoveInviteRequest +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketCreateInviteRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketCreateInviteRequest.kt new file mode 100644 index 0000000..5b39f57 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketCreateInviteRequest.kt @@ -0,0 +1,13 @@ +package io.timemates.api.rsocket.timers.members.invites.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data class RSocketCreateInviteRequest( + val timerId: Long, + val maxJoiners: Int, +) : RSocketRequest { + @Serializable + data class Result(val inviteCode: String) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketGetInvitesListRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketGetInvitesListRequest.kt new file mode 100644 index 0000000..bac07b2 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketGetInvitesListRequest.kt @@ -0,0 +1,17 @@ +package io.timemates.api.rsocket.timers.members.invites.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import io.timemates.api.rsocket.timers.members.invites.types.SerializableInvite +import kotlinx.serialization.Serializable + +@Serializable +internal data class RSocketGetInvitesListRequest( + val timerId: Long, + val pageToken: String? = null, +) : RSocketRequest { + @Serializable + data class Result( + val invites: List, + val nextPageToken: String? = null, + ) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketJoinTimerByCodeRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketJoinTimerByCodeRequest.kt new file mode 100644 index 0000000..ccbded7 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketJoinTimerByCodeRequest.kt @@ -0,0 +1,12 @@ +package io.timemates.api.rsocket.timers.members.invites.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data class RSocketJoinTimerByCodeRequest( + val code: String, +) : RSocketRequest { + @Serializable + data class Result(val timerId: Long) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketRemoveInviteRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketRemoveInviteRequest.kt new file mode 100644 index 0000000..90e0380 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketRemoveInviteRequest.kt @@ -0,0 +1,10 @@ +package io.timemates.api.rsocket.timers.members.invites.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data class RSocketRemoveInviteRequest( + val timerId: Long, + val code: String, +) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/types/SerializableInvite.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/types/SerializableInvite.kt new file mode 100644 index 0000000..1333e4b --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/types/SerializableInvite.kt @@ -0,0 +1,24 @@ +package io.timemates.api.rsocket.timers.members.invites.types + +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.common.types.value.Count +import io.timemates.sdk.timers.members.invites.types.Invite +import io.timemates.sdk.timers.members.invites.types.value.InviteCode +import kotlinx.datetime.Instant +import kotlinx.serialization.Serializable + +@Serializable +internal data class SerializableInvite( + val timerId: Long, + val code: String, + val creationTime: Long, + val limit: Int, +) + +internal fun SerializableInvite.sdk(): Invite { + return Invite( + inviteCode = InviteCode.createOrThrow(code), + creationTime = Instant.fromEpochMilliseconds(creationTime), + limit = Count.createOrThrow(limit), + ) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketGetMembersListRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketGetMembersListRequest.kt new file mode 100644 index 0000000..1383216 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketGetMembersListRequest.kt @@ -0,0 +1,17 @@ +package io.timemates.api.rsocket.timers.members.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import io.timemates.api.rsocket.users.types.SerializableUser +import kotlinx.serialization.Serializable + +@Serializable +internal data class RSocketGetMembersListRequest( + val timerId: Long, + val pageToken: String? = null, +) : RSocketRequest { + @Serializable + data class Result( + val list: List, + val nextPageToken: String? = null, + ) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketKickMemberRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketKickMemberRequest.kt new file mode 100644 index 0000000..a68a527 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketKickMemberRequest.kt @@ -0,0 +1,6 @@ +package io.timemates.api.rsocket.timers.members.requests + +internal data class RSocketKickMemberRequest( + val timerId: Long, + val userId: Long, +) \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketCreateTimerRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketCreateTimerRequest.kt new file mode 100644 index 0000000..e4352f8 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketCreateTimerRequest.kt @@ -0,0 +1,15 @@ +package io.timemates.api.rsocket.timers.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import io.timemates.api.rsocket.timers.types.SerializableTimerSettings +import kotlinx.serialization.Serializable + +@Serializable +internal data class RSocketCreateTimerRequest( + val name: String, + val description: String = "", + val settings: SerializableTimerSettings? = null, +) : RSocketRequest { + @Serializable + data class Result(val timerId: Long) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketDeleteTimerRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketDeleteTimerRequest.kt new file mode 100644 index 0000000..9b78b94 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketDeleteTimerRequest.kt @@ -0,0 +1,9 @@ +package io.timemates.api.rsocket.timers.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data class RSocketDeleteTimerRequest( + val timerId: Long, +) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketEditTimerRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketEditTimerRequest.kt new file mode 100644 index 0000000..a526724 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketEditTimerRequest.kt @@ -0,0 +1,13 @@ +package io.timemates.api.rsocket.timers.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import io.timemates.api.rsocket.timers.types.SerializableTimerSettingsPatch +import kotlinx.serialization.Serializable + +@Serializable +internal data class RSocketEditTimerRequest( + val timerId: Long, + val name: String? = null, + val description: String? = null, + val settings: SerializableTimerSettingsPatch? = null, +) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetTimerRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetTimerRequest.kt new file mode 100644 index 0000000..b3a91df --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetTimerRequest.kt @@ -0,0 +1,13 @@ +package io.timemates.api.rsocket.timers.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import io.timemates.api.rsocket.timers.types.SerializableTimer +import kotlinx.serialization.Serializable + +@Serializable +internal data class RSocketGetTimerRequest( + val timerId: Long, +) : RSocketRequest { + @Serializable + data class Result(val timer: SerializableTimer) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetUserTimersRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetUserTimersRequest.kt new file mode 100644 index 0000000..8dbe072 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetUserTimersRequest.kt @@ -0,0 +1,16 @@ +package io.timemates.api.rsocket.timers.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import io.timemates.api.rsocket.timers.types.SerializableTimer +import kotlinx.serialization.Serializable + +@Serializable +internal data class RSocketGetUserTimersRequest( + val pageToken: String? = null, +) : RSocketRequest { + @Serializable + data class Result( + val nextPageToken: String? = null, + val list: List, + ) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/ConfirmSessionCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/ConfirmSessionCommand.kt new file mode 100644 index 0000000..ee7f7c1 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/ConfirmSessionCommand.kt @@ -0,0 +1,18 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.timers.sessions.requests.RSocketConfirmSessionRequest +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.sessions.requests.ConfirmTimerRoundRequest + +internal object ConfirmSessionCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: ConfirmTimerRoundRequest): Empty { + return rSocket.requestResponse( + route = "timers.sessions.attendance.confirm", + data = RSocketConfirmSessionRequest, + accessHash = input.accessHash.string, + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetCurrentSessionCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetCurrentSessionCommand.kt new file mode 100644 index 0000000..40c1cd4 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetCurrentSessionCommand.kt @@ -0,0 +1,19 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.timers.sessions.requests.RSocketGetCurrentSessionRequest +import io.timemates.api.rsocket.timers.types.sdk +import io.timemates.sdk.timers.sessions.requests.GetUserCurrentSessionRequest +import io.timemates.sdk.timers.types.Timer + +internal object GetCurrentSessionCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: GetUserCurrentSessionRequest): Timer { + return rSocket.requestResponse( + route = "timers.sessions.ping", + data = RSocketGetCurrentSessionRequest, + accessHash = input.accessHash.string, + ).timer.sdk() + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetTimerStateCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetTimerStateCommand.kt new file mode 100644 index 0000000..06cf6ec --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetTimerStateCommand.kt @@ -0,0 +1,32 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.common.ext.requestStream +import io.timemates.api.rsocket.timers.requests.RSocketGetTimerRequest +import io.timemates.api.rsocket.timers.sessions.requests.RSocketGetCurrentTimerStateRequest +import io.timemates.api.rsocket.timers.sessions.types.sdk +import io.timemates.api.rsocket.timers.types.sdk +import io.timemates.api.rsocket.timers.types.serializable +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.timers.requests.CreateTimerRequest +import io.timemates.sdk.timers.requests.GetTimerRequest +import io.timemates.sdk.timers.sessions.requests.GetTimerStateRequest +import io.timemates.sdk.timers.types.value.TimerId +import kotlinx.coroutines.flow.map +import io.timemates.api.rsocket.timers.requests.RSocketCreateTimerRequest as RSocketCreateTimerRequest + +internal object GetTimerStateCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: GetTimerStateRequest): GetTimerStateRequest.Result { + return rSocket.requestStream( + route = "timers.get", + data = RSocketGetCurrentTimerStateRequest( + timerId = input.timerId.long, + ), + accessHash = input.accessHash.string, + ).let { result -> + GetTimerStateRequest.Result(result.map { it.sdk() }) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/JoinSessionCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/JoinSessionCommand.kt new file mode 100644 index 0000000..fa800a1 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/JoinSessionCommand.kt @@ -0,0 +1,20 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.timers.sessions.requests.RSocketJoinSessionRequest +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.sessions.requests.JoinTimerSessionRequest + +internal object JoinSessionCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: JoinTimerSessionRequest): Empty { + return rSocket.requestResponse( + route = "timers.sessions.join", + data = RSocketJoinSessionRequest( + timerId = input.timerId.long, + ), + accessHash = input.accessHash.string, + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/LeaveSessionCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/LeaveSessionCommand.kt new file mode 100644 index 0000000..16b3fb7 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/LeaveSessionCommand.kt @@ -0,0 +1,18 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.timers.sessions.requests.RSocketLeaveSessionRequest +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.sessions.requests.LeaveTimerSessionRequest + +internal object LeaveSessionCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: LeaveTimerSessionRequest): Empty { + return rSocket.requestResponse( + route = "timers.sessions.leave", + data = RSocketLeaveSessionRequest, + accessHash = input.accessHash.string, + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt new file mode 100644 index 0000000..4dec5d6 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt @@ -0,0 +1,18 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.fireAndForget +import io.timemates.api.rsocket.timers.sessions.requests.RSocketLeaveSessionRequest +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.sessions.requests.PingSessionRequest + +internal object PingSessionCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: PingSessionRequest): Empty { + return rSocket.fireAndForget( + route = "timers.sessions.ping", + data = RSocketLeaveSessionRequest, + accessHash = input.accessHash.string, + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StartSessionCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StartSessionCommand.kt new file mode 100644 index 0000000..9eba5f2 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StartSessionCommand.kt @@ -0,0 +1,20 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.timers.sessions.requests.RSocketStartSessionRequest +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.sessions.requests.StartTimerRequest + +internal object StartSessionCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: StartTimerRequest): Empty { + return rSocket.requestResponse( + route = "timers.sessions.start", + data = RSocketStartSessionRequest( + timerId = input.timerId.long, + ), + accessHash = input.accessHash.string, + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StopSessionCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StopSessionCommand.kt new file mode 100644 index 0000000..94f0dd6 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StopSessionCommand.kt @@ -0,0 +1,20 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.timers.sessions.requests.RSocketStopSessionRequest +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.sessions.requests.StopTimerRequest + +internal object StopSessionCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: StopTimerRequest): Empty { + return rSocket.requestResponse( + route = "timers.sessions.start", + data = RSocketStopSessionRequest( + timerId = input.timerId.long, + ), + accessHash = input.accessHash.string, + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/TimerSessionsCommandsRegistry.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/TimerSessionsCommandsRegistry.kt new file mode 100644 index 0000000..bd38fb0 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/TimerSessionsCommandsRegistry.kt @@ -0,0 +1,25 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.timemates.api.rsocket.common.commands.RSocketCommandsBuilderScope +import io.timemates.sdk.timers.sessions.requests.ConfirmTimerRoundRequest +import io.timemates.sdk.timers.sessions.requests.GetTimerStateRequest +import io.timemates.sdk.timers.sessions.requests.GetUserCurrentSessionRequest +import io.timemates.sdk.timers.sessions.requests.JoinTimerSessionRequest +import io.timemates.sdk.timers.sessions.requests.LeaveTimerSessionRequest +import io.timemates.sdk.timers.sessions.requests.PingSessionRequest +import io.timemates.sdk.timers.sessions.requests.StartTimerRequest +import io.timemates.sdk.timers.sessions.requests.StopTimerRequest + +/** + * RSocket commands related to timer members. + */ +internal fun RSocketCommandsBuilderScope.timerSessions() { + ConfirmSessionCommand associatedWith ConfirmTimerRoundRequest + LeaveSessionCommand associatedWith LeaveTimerSessionRequest + PingSessionCommand associatedWith PingSessionRequest + GetCurrentSessionCommand associatedWith GetUserCurrentSessionRequest + StartSessionCommand associatedWith StartTimerRequest + StopSessionCommand associatedWith StopTimerRequest + JoinSessionCommand associatedWith JoinTimerSessionRequest + GetTimerStateCommand associatedWith GetTimerStateRequest +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketConfirmSessionRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketConfirmSessionRequest.kt new file mode 100644 index 0000000..13a7f10 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketConfirmSessionRequest.kt @@ -0,0 +1,7 @@ +package io.timemates.api.rsocket.timers.sessions.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data object RSocketConfirmSessionRequest : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentSessionRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentSessionRequest.kt new file mode 100644 index 0000000..e23b1d8 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentSessionRequest.kt @@ -0,0 +1,11 @@ +package io.timemates.api.rsocket.timers.sessions.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import io.timemates.api.rsocket.timers.types.SerializableTimer +import kotlinx.serialization.Serializable + +@Serializable +internal data object RSocketGetCurrentSessionRequest : RSocketRequest { + @Serializable + data class Result(val timer: SerializableTimer) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentTimerStateRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentTimerStateRequest.kt new file mode 100644 index 0000000..70deed1 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentTimerStateRequest.kt @@ -0,0 +1,10 @@ +package io.timemates.api.rsocket.timers.sessions.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import io.timemates.api.rsocket.timers.sessions.types.SerializableTimerState +import kotlinx.serialization.Serializable + +@Serializable +internal data class RSocketGetCurrentTimerStateRequest( + val timerId: Long, +) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketJoinSessionRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketJoinSessionRequest.kt new file mode 100644 index 0000000..fbf2afd --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketJoinSessionRequest.kt @@ -0,0 +1,9 @@ +package io.timemates.api.rsocket.timers.sessions.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data class RSocketJoinSessionRequest( + val timerId: Long, +) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketLeaveSessionRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketLeaveSessionRequest.kt new file mode 100644 index 0000000..0bf9d29 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketLeaveSessionRequest.kt @@ -0,0 +1,7 @@ +package io.timemates.api.rsocket.timers.sessions.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data object RSocketLeaveSessionRequest : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketPingCurrentSessionRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketPingCurrentSessionRequest.kt new file mode 100644 index 0000000..61d7c66 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketPingCurrentSessionRequest.kt @@ -0,0 +1,6 @@ +package io.timemates.api.rsocket.timers.sessions.requests + +import kotlinx.serialization.Serializable + +@Serializable +internal data object RSocketPingCurrentSessionRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStartSessionRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStartSessionRequest.kt new file mode 100644 index 0000000..bbf6bb9 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStartSessionRequest.kt @@ -0,0 +1,9 @@ +package io.timemates.api.rsocket.timers.sessions.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data class RSocketStartSessionRequest( + val timerId: Long, +) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStopSessionRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStopSessionRequest.kt new file mode 100644 index 0000000..3d7c22d --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStopSessionRequest.kt @@ -0,0 +1,9 @@ +package io.timemates.api.rsocket.timers.sessions.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data class RSocketStopSessionRequest( + val timerId: Long, +) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/types/SerializableTimerState.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/types/SerializableTimerState.kt new file mode 100644 index 0000000..3856e86 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/types/SerializableTimerState.kt @@ -0,0 +1,62 @@ +package io.timemates.api.rsocket.timers.sessions.types + +import io.timemates.sdk.timers.types.Timer +import kotlinx.datetime.Instant +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Represents current timer state. + * @see SDK Source + */ +@Serializable +internal sealed class SerializableTimerState { + abstract val endsAt: Long? + abstract val publishTime: Long + + @SerialName("inactive") + data class Inactive(override val publishTime: Long) : SerializableTimerState() { + override val endsAt: Long? get() = null + } + + @SerialName("pause") + data class Pause(override val publishTime: Long) : SerializableTimerState() { + override val endsAt: Long? get() = null + } + + @SerialName("running") + data class Running(override val endsAt: Long, override val publishTime: Long) : SerializableTimerState() + + @SerialName("rest") + data class Rest(override val endsAt: Long, override val publishTime: Long) : SerializableTimerState() + + @SerialName("confirmation") + data class Confirmation(override val endsAt: Long, override val publishTime: Long) : SerializableTimerState() +} + +internal fun SerializableTimerState.sdk(): Timer.State { + val endsAt = endsAt?.let { Instant.fromEpochMilliseconds(it) } + val publishTime = Instant.fromEpochMilliseconds(publishTime) + + return when (this) { + is SerializableTimerState.Confirmation -> + Timer.State.ConfirmationWaiting( + endsAt = endsAt!!, + publishTime = publishTime, + ) + is SerializableTimerState.Inactive -> Timer.State.Inactive( + publishTime = publishTime, + ) + is SerializableTimerState.Pause -> Timer.State.Paused( + publishTime = publishTime, + ) + is SerializableTimerState.Rest -> Timer.State.Rest( + endsAt = endsAt!!, + publishTime = publishTime, + ) + is SerializableTimerState.Running -> Timer.State.Running( + endsAt = endsAt!!, + publishTime = publishTime, + ) + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimer.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimer.kt new file mode 100644 index 0000000..02c45a6 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimer.kt @@ -0,0 +1,33 @@ +package io.timemates.api.rsocket.timers.types + +import io.timemates.api.rsocket.timers.sessions.types.SerializableTimerState +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.common.types.value.Count +import io.timemates.sdk.timers.types.Timer +import io.timemates.sdk.timers.types.value.TimerDescription +import io.timemates.sdk.timers.types.value.TimerId +import io.timemates.sdk.timers.types.value.TimerName +import io.timemates.sdk.users.profile.types.value.UserId +import kotlinx.serialization.Serializable + +@Serializable +internal data class SerializableTimer( + val id: Long, + val name: String, + val description: String, + val ownerId: Long, + val settings: SerializableTimerSettings, + val membersCount: Int, + val state: SerializableTimerState, +) + +internal fun SerializableTimer.sdk(): Timer { + return Timer( + timerId = TimerId.createOrThrow(id), + name = TimerName.createOrThrow(name), + description = TimerDescription.createOrThrow(description), + ownerId = UserId.createOrThrow(ownerId), + membersCount = Count.createOrThrow(membersCount), + settings = settings.sdk(), + ) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettings.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettings.kt new file mode 100644 index 0000000..b4a410f --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettings.kt @@ -0,0 +1,42 @@ +package io.timemates.api.rsocket.timers.types + +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.common.types.value.Count +import io.timemates.sdk.timers.types.TimerSettings +import kotlinx.serialization.Serializable +import kotlin.time.Duration + +@Serializable +internal data class SerializableTimerSettings( + val workTime: Duration, + val restTime: Duration, + val bigRestTime: Duration, + val bigRestEnabled: Boolean, + val bigRestPer: Int, + val isEveryoneCanPause: Boolean, + val isConfirmationRequired: Boolean, +) + +internal fun TimerSettings.serializable(): SerializableTimerSettings { + return SerializableTimerSettings( + workTime = workTime, + restTime = restTime, + bigRestTime = bigRestTime, + bigRestEnabled = bigRestEnabled, + bigRestPer = bigRestPer.int, + isEveryoneCanPause = isEveryoneCanPause, + isConfirmationRequired = isConfirmationRequired, + ) +} + +internal fun SerializableTimerSettings.sdk(): TimerSettings { + return TimerSettings( + workTime = workTime, + restTime = restTime, + bigRestTime = bigRestTime, + bigRestEnabled = bigRestEnabled, + bigRestPer = Count.createOrThrow(bigRestPer), + isEveryoneCanPause = isEveryoneCanPause, + isConfirmationRequired = isConfirmationRequired, + ) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettingsPatch.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettingsPatch.kt new file mode 100644 index 0000000..cefb805 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettingsPatch.kt @@ -0,0 +1,15 @@ +package io.timemates.api.rsocket.timers.types + +import kotlinx.serialization.Serializable +import kotlin.time.Duration + +@Serializable +internal data class SerializableTimerSettingsPatch( + val workTime: Duration? = null, + val restTime: Duration? = null, + val bigRestTime: Duration? = null, + val bigRestEnabled: Boolean? = null, + val bigRestPer: Int? = null, + val isEveryoneCanPause: Boolean? = null, + val isConfirmationRequired: Boolean? = null, +) \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt new file mode 100644 index 0000000..9de520a --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt @@ -0,0 +1,24 @@ +package io.timemates.api.rsocket.users.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.users.requests.EditUserProfileRequest +import io.timemates.api.rsocket.users.types.serializable +import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.users.profile.requests.EditProfileRequest +import io.timemates.sdk.users.settings.requests.EditEmailRequest + +@OptIn(ExperimentalTimeMatesApi::class) +internal object EditEmailCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: EditEmailRequest): Empty { + return rSocket.requestResponse( + route = "users.email.edit", + data = io.timemates.api.rsocket.users.requests.EditEmailRequest( + email = input.newEmail.string, + ), + accessHash = input.accessHash.string, + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt new file mode 100644 index 0000000..556a5b5 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt @@ -0,0 +1,23 @@ +package io.timemates.api.rsocket.users.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.users.requests.EditUserProfileRequest +import io.timemates.api.rsocket.users.types.serializable +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.users.profile.requests.EditProfileRequest + +internal object EditProfileCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: EditProfileRequest): Empty { + return rSocket.requestResponse( + route = "users.profile.edit", + data = EditUserProfileRequest( + name = input.name?.string, + description = input.description?.string, + avatar = input.avatar?.serializable(), + ), + accessHash = input.accessHash.string, + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt new file mode 100644 index 0000000..02c6e93 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt @@ -0,0 +1,20 @@ +package io.timemates.api.rsocket.users.commands + +import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.ext.requestResponse +import io.timemates.api.rsocket.users.types.SerializableUser +import io.timemates.api.rsocket.users.types.sdk +import io.timemates.sdk.users.profile.requests.GetUsersRequest +import io.timemates.api.rsocket.users.requests.GetUsersRequest as RSocketGetUsersRequest + +internal object GetUsersCommand : RSocketCommand { + override suspend fun execute(rSocket: RSocket, input: GetUsersRequest): GetUsersRequest.Result { + return rSocket.requestResponse( + route = "users.profile.list", + data = RSocketGetUsersRequest(ids = input.users.map { it.long }) + ).let { result -> + GetUsersRequest.Result(result.list.map(SerializableUser::sdk)) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/UsersCommandsRegistry.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/UsersCommandsRegistry.kt new file mode 100644 index 0000000..89ee76c --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/UsersCommandsRegistry.kt @@ -0,0 +1,17 @@ +package io.timemates.api.rsocket.users.commands + +import io.timemates.api.rsocket.common.commands.RSocketCommandsBuilderScope +import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi +import io.timemates.sdk.users.profile.requests.EditProfileRequest +import io.timemates.sdk.users.profile.requests.GetUsersRequest +import io.timemates.sdk.users.settings.requests.EditEmailRequest + +/** + * RSocket commands related to user operations. + */ +@OptIn(ExperimentalTimeMatesApi::class) +internal fun RSocketCommandsBuilderScope.users() { + EditProfileCommand associatedWith EditProfileRequest + GetUsersCommand associatedWith GetUsersRequest + EditEmailCommand associatedWith EditEmailRequest +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/EditEmailRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/EditEmailRequest.kt new file mode 100644 index 0000000..7a10739 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/EditEmailRequest.kt @@ -0,0 +1,9 @@ +package io.timemates.api.rsocket.users.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import kotlinx.serialization.Serializable + +@Serializable +internal data class EditEmailRequest( + val email: String, +) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/EditUserProfileRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/EditUserProfileRequest.kt new file mode 100644 index 0000000..405e4a1 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/EditUserProfileRequest.kt @@ -0,0 +1,12 @@ +package io.timemates.api.rsocket.users.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import io.timemates.api.rsocket.users.types.SerializableAvatar +import kotlinx.serialization.Serializable + +@Serializable +internal data class EditUserProfileRequest( + val avatar: SerializableAvatar?, + val name: String?, + val description: String?, +) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/GetUsersRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/GetUsersRequest.kt new file mode 100644 index 0000000..ae4a011 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/GetUsersRequest.kt @@ -0,0 +1,13 @@ +package io.timemates.api.rsocket.users.requests + +import io.timemates.api.rsocket.common.markers.RSocketRequest +import io.timemates.api.rsocket.users.types.SerializableUser +import kotlinx.serialization.Serializable + +@Serializable +internal data class GetUsersRequest( + val ids: List, +) : RSocketRequest { + @Serializable + data class Result(val list: List) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableAvatar.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableAvatar.kt new file mode 100644 index 0000000..92497a6 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableAvatar.kt @@ -0,0 +1,29 @@ +package io.timemates.api.rsocket.users.types + +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.users.profile.types.Avatar +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +internal sealed interface SerializableAvatar { + @SerialName("gravatar") + data class Gravatar(val gravatarId: String) : SerializableAvatar + + @SerialName("timemates") + data class TimeMates(val fileId: String) : SerializableAvatar +} + +internal fun Avatar.serializable(): SerializableAvatar { + return when (this) { + is Avatar.GravatarId -> SerializableAvatar.Gravatar(string) + is Avatar.FileId -> SerializableAvatar.TimeMates(string) + } +} + +internal fun SerializableAvatar.sdk(): Avatar { + return when (this) { + is SerializableAvatar.TimeMates -> Avatar.GravatarId.createOrThrow(fileId) + is SerializableAvatar.Gravatar -> Avatar.FileId.createOrThrow(gravatarId) + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableUser.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableUser.kt new file mode 100644 index 0000000..858073b --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableUser.kt @@ -0,0 +1,28 @@ +package io.timemates.api.rsocket.users.types + +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.users.profile.types.User +import io.timemates.sdk.users.profile.types.value.EmailAddress +import io.timemates.sdk.users.profile.types.value.UserDescription +import io.timemates.sdk.users.profile.types.value.UserId +import io.timemates.sdk.users.profile.types.value.UserName +import kotlinx.serialization.Serializable + +@Serializable +internal data class SerializableUser( + val id: Long, + val name: String, + val emailAddress: String?, + val description: String?, + val avatar: SerializableAvatar?, +) + +internal fun SerializableUser.sdk(): User { + return User( + id = UserId.createOrThrow(id), + name = UserName.createOrThrow(name), + description = description?.let { UserDescription.createOrThrow(it) }, + emailAddress = emailAddress?.let { EmailAddress.createOrThrow(it) }, + avatar = avatar?.sdk() + ) +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/EmailAuthorizationApi.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/EmailAuthorizationApi.kt index 011a199..3a85a35 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/EmailAuthorizationApi.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/EmailAuthorizationApi.kt @@ -4,6 +4,7 @@ import io.timemates.sdk.authorization.email.requests.ConfigureNewAccountRequest import io.timemates.sdk.authorization.email.requests.ConfirmAuthorizationRequest import io.timemates.sdk.authorization.email.requests.StartAuthorizationRequest import io.timemates.sdk.authorization.email.types.value.VerificationHash +import io.timemates.sdk.authorization.sessions.types.Authorization import io.timemates.sdk.authorization.sessions.types.value.ConfirmationCode import io.timemates.sdk.common.engine.TimeMatesRequestsEngine import io.timemates.sdk.users.profile.types.value.EmailAddress @@ -21,8 +22,12 @@ public class EmailAuthorizationApi(private val engine: TimeMatesRequestsEngine) * * @see confirm */ - public suspend fun authorize(emailAddress: EmailAddress): Result { - return engine.execute(StartAuthorizationRequest(emailAddress)).map { it.verificationHash } + public suspend fun authorize( + emailAddress: EmailAddress, + metadata: Authorization.Metadata, + ): Result { + return engine.execute(StartAuthorizationRequest(emailAddress, metadata)) + .map { it.verificationHash } } /** @@ -36,7 +41,7 @@ public class EmailAuthorizationApi(private val engine: TimeMatesRequestsEngine) public suspend fun confirm( verificationHash: VerificationHash, confirmationCode: ConfirmationCode, - ): Result { + ): Result { return engine.execute(ConfirmAuthorizationRequest(verificationHash, confirmationCode)) } diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/requests/ConfigureNewAccountRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/requests/ConfigureNewAccountRequest.kt index 8a11ec5..cb4f74c 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/requests/ConfigureNewAccountRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/requests/ConfigureNewAccountRequest.kt @@ -10,7 +10,12 @@ import io.timemates.sdk.users.profile.types.value.UserName public data class ConfigureNewAccountRequest( val verificationHash: VerificationHash, val name: UserName, - val description: UserDescription, + val description: UserDescription?, ) : TimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + public data class Result(val authorization: Authorization) : TimeMatesEntity() + + override val requestKey: Key + get() = Key } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/requests/ConfirmAuthorizationRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/requests/ConfirmAuthorizationRequest.kt index 6e9d3a4..3296000 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/requests/ConfirmAuthorizationRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/requests/ConfirmAuthorizationRequest.kt @@ -1,17 +1,22 @@ package io.timemates.sdk.authorization.email.requests +import io.timemates.sdk.authorization.email.types.value.VerificationHash import io.timemates.sdk.authorization.sessions.types.Authorization import io.timemates.sdk.authorization.sessions.types.value.ConfirmationCode -import io.timemates.sdk.authorization.email.types.value.VerificationHash import io.timemates.sdk.common.types.TimeMatesEntity import io.timemates.sdk.common.types.TimeMatesRequest public data class ConfirmAuthorizationRequest( val verificationHash: VerificationHash, val confirmationCode: ConfirmationCode, -) : TimeMatesRequest() { - public data class Response( +) : TimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + public data class Result( val isNewAccount: Boolean, val authorization: Authorization?, ) : TimeMatesEntity() + + override val requestKey: Key + get() = Key } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/requests/StartAuthorizationRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/requests/StartAuthorizationRequest.kt index 7c103d4..cf1411b 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/requests/StartAuthorizationRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/email/requests/StartAuthorizationRequest.kt @@ -1,18 +1,24 @@ package io.timemates.sdk.authorization.email.requests -import io.timemates.sdk.users.profile.types.value.EmailAddress import io.timemates.sdk.authorization.email.types.value.VerificationHash +import io.timemates.sdk.authorization.sessions.types.Authorization import io.timemates.sdk.common.types.TimeMatesEntity import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.common.types.value.Count +import io.timemates.sdk.users.profile.types.value.EmailAddress import kotlinx.datetime.Instant public data class StartAuthorizationRequest( - val emailAddress: EmailAddress + val emailAddress: EmailAddress, + val metadata: Authorization.Metadata, ) : TimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + public data class Result( val verificationHash: VerificationHash, val attempts: Count, val expiresAt: Instant, ) : TimeMatesEntity() + + override val requestKey: Key get() = Key } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/AuthorizedSessionsApi.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/AuthorizedSessionsApi.kt index 6150783..147bf8e 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/AuthorizedSessionsApi.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/AuthorizedSessionsApi.kt @@ -16,9 +16,6 @@ import io.timemates.sdk.common.providers.AccessHashProvider import io.timemates.sdk.common.providers.getAsResult import io.timemates.sdk.common.types.Empty import io.timemates.sdk.common.types.value.Count -import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flow import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/GetAuthorizationSessionsRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/GetAuthorizationSessionsRequest.kt index d727df4..96d605b 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/GetAuthorizationSessionsRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/GetAuthorizationSessionsRequest.kt @@ -4,10 +4,15 @@ import io.timemates.sdk.authorization.sessions.types.Authorization import io.timemates.sdk.authorization.types.value.AccessHash import io.timemates.sdk.common.pagination.Page import io.timemates.sdk.common.pagination.PageToken -import io.timemates.sdk.common.types.TimeMatesEntity +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.TimeMatesRequest public data class GetAuthorizationSessionsRequest( val nextPageToken: PageToken?, - val accessHash: AccessHash, -) : TimeMatesRequest>() \ No newline at end of file + override val accessHash: AccessHash, +) : AuthorizedTimeMatesRequest>() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key + get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/RenewAuthorizationRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/RenewAuthorizationRequest.kt new file mode 100644 index 0000000..b9875b6 --- /dev/null +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/RenewAuthorizationRequest.kt @@ -0,0 +1,22 @@ +package io.timemates.sdk.authorization.sessions.requests + +import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.authorization.types.value.HashValue +import io.timemates.sdk.common.annotations.ApiStatus +import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi +import io.timemates.sdk.common.types.TimeMatesEntity +import io.timemates.sdk.common.types.TimeMatesRequest + +@ExperimentalTimeMatesApi(status = ApiStatus.IN_PROGRESS) +public data class RenewAuthorizationRequest( + val refreshHash: HashValue, +) : TimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + @ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) + public data class Result( + val accessHash: AccessHash, + ) : TimeMatesEntity() + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/TerminateCurrentAuthorizationSessionRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/TerminateCurrentAuthorizationSessionRequest.kt index 2406b88..5eee55f 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/TerminateCurrentAuthorizationSessionRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/TerminateCurrentAuthorizationSessionRequest.kt @@ -1,9 +1,14 @@ package io.timemates.sdk.authorization.sessions.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.Empty import io.timemates.sdk.common.types.TimeMatesRequest public data class TerminateCurrentAuthorizationSessionRequest( - val accessHash: AccessHash -) : TimeMatesRequest() \ No newline at end of file + override val accessHash: AccessHash, +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/Authorization.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/Authorization.kt index 57260ac..d10796a 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/Authorization.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/Authorization.kt @@ -1,7 +1,7 @@ package io.timemates.sdk.authorization.sessions.types +import io.timemates.sdk.authorization.sessions.types.value.ApplicationName import io.timemates.sdk.authorization.sessions.types.value.ClientIpAddress -import io.timemates.sdk.authorization.sessions.types.value.ClientName import io.timemates.sdk.authorization.sessions.types.value.ClientVersion import io.timemates.sdk.authorization.types.value.HashValue import io.timemates.sdk.common.types.TimeMatesEntity @@ -19,7 +19,7 @@ public data class Authorization( ) : TimeMatesEntity() public data class Metadata( - val clientName: ClientName, + val applicationName: ApplicationName, val clientVersion: ClientVersion, val clientIpAddress: ClientIpAddress, ) : TimeMatesEntity() diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ApplicationName.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ApplicationName.kt new file mode 100644 index 0000000..aad89c8 --- /dev/null +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ApplicationName.kt @@ -0,0 +1,12 @@ +package io.timemates.sdk.authorization.sessions.types.value + +import io.timemates.sdk.common.constructor.Factory + +@JvmInline +public value class ApplicationName private constructor(public val string: String) { + public companion object : Factory() { + override fun create(input: String): Result { + return Result.success(ApplicationName(input)) + } + } +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ClientName.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ClientName.kt deleted file mode 100644 index f2eb3ca..0000000 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ClientName.kt +++ /dev/null @@ -1,12 +0,0 @@ -package io.timemates.sdk.authorization.sessions.types.value - -import io.timemates.sdk.common.constructor.Factory - -@JvmInline -public value class ClientName private constructor(public val string: String) { - public companion object : Factory() { - override fun create(input: String): Result { - return Result.success(ClientName(input)) - } - } -} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/annotations/ExperimentalApi.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/annotations/ExperimentalTimeMatesApi.kt similarity index 81% rename from sdk/src/commonMain/kotlin/io/timemates/sdk/common/annotations/ExperimentalApi.kt rename to sdk/src/commonMain/kotlin/io/timemates/sdk/common/annotations/ExperimentalTimeMatesApi.kt index a920340..a45ed91 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/annotations/ExperimentalApi.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/annotations/ExperimentalTimeMatesApi.kt @@ -4,7 +4,7 @@ package io.timemates.sdk.common.annotations * Annotation used to indicate that a given SDK API is experimental. */ @RequiresOptIn(message = "Given SDK API is experimental", level = RequiresOptIn.Level.ERROR) -public annotation class ExperimentalApi(val status: ApiStatus) +public annotation class ExperimentalTimeMatesApi(val status: ApiStatus) public enum class ApiStatus { PROTOTYPE, diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/handler/SafeExceptionResult.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/handler/SafeExceptionResult.kt index 352fdc8..416c51c 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/handler/SafeExceptionResult.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/handler/SafeExceptionResult.kt @@ -1,12 +1,16 @@ -@file:OptIn(InternalApi::class, ExperimentalApi::class) +@file:OptIn(InternalApi::class, ExperimentalTimeMatesApi::class) package io.timemates.sdk.common.exceptions.handler import io.timemates.sdk.common.annotations.ApiStatus -import io.timemates.sdk.common.annotations.ExperimentalApi +import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi import io.timemates.sdk.common.annotations.InternalApi +import io.timemates.sdk.common.exceptions.NotFoundException +import io.timemates.sdk.common.exceptions.TimeMatesException +import io.timemates.sdk.common.exceptions.TooManyRequestsException +import io.timemates.sdk.common.exceptions.UnauthorizedException +import io.timemates.sdk.common.exceptions.UnavailableException import io.timemates.sdk.common.types.TimeMatesEntity -import io.timemates.sdk.common.exceptions.* /** * Represents a type-safe wrapper class for handling exceptions in the context of an operation's result. @@ -18,7 +22,7 @@ import io.timemates.sdk.common.exceptions.* * @param E The type of the exception. * @property result The original result of the operation. */ -@ExperimentalApi(status = ApiStatus.NEEDS_REVISION) +@ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) @JvmInline public value class SafeExceptionResult @InternalApi constructor( @property:InternalApi public val result: Result @@ -33,7 +37,7 @@ public value class SafeExceptionResult @InternalApi constructo * @receiver The original result of the operation. * @return The [SafeExceptionResult] containing the original result. */ -@ExperimentalApi(status = ApiStatus.NEEDS_REVISION) +@ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) public fun Result.safeResult(): SafeExceptionResult { return SafeExceptionResult(this) } @@ -138,7 +142,7 @@ public fun SafeExceptionResult.ignoreNotFound(): SafeE * @param block The block of code to be executed if any exception is encountered. * @return The [SafeExceptionResult] after executing the block. */ -@ExperimentalApi(status = ApiStatus.NEEDS_REVISION) +@ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) public inline fun SafeExceptionResult.whenOtherError( block: (E) -> Unit ): SafeExceptionResult { @@ -157,7 +161,7 @@ public inline fun SafeExceptionResult.whenOtherError( * * But, if it's possible, it's better to use just [Result] API instead of [SafeExceptionResult]. */ -@ExperimentalApi(status = ApiStatus.NEEDS_REVISION) +@ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) public inline fun SafeExceptionResult.whenAnyError( block: (Throwable) -> Unit ): SafeExceptionResult { diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/pagination/PagesIterator.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/pagination/PagesIterator.kt index fddd1d7..647c137 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/pagination/PagesIterator.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/pagination/PagesIterator.kt @@ -1,7 +1,7 @@ package io.timemates.sdk.common.pagination import io.timemates.sdk.common.annotations.ApiStatus -import io.timemates.sdk.common.annotations.ExperimentalApi +import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi import io.timemates.sdk.common.constructor.createOrThrow import io.timemates.sdk.common.exceptions.TimeMatesException import io.timemates.sdk.common.pagination.PagesIteratorImpl.State @@ -60,7 +60,7 @@ public fun PagesIterator.asFlow(): Flow>> = flow { * * @return A [List] containing all elements from the page iterator. */ -@ExperimentalApi(status = ApiStatus.NEEDS_REVISION) +@ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) public suspend fun PagesIterator.toList(): List> { return buildList { for (result in this@toList) { @@ -78,7 +78,7 @@ public suspend fun PagesIterator.toList(): List> { * * @return A [Sequence] containing all elements from the page iterator. */ -@ExperimentalApi(status = ApiStatus.NEEDS_REVISION) +@ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) public suspend fun PagesIterator.asSequence(): Sequence> { return toList().asSequence() } @@ -99,7 +99,7 @@ public suspend inline fun PagesIterator.forEachPage(block: (Result PagesIterator.forEach(block: (Result) -> Unit) { forEachPage { page -> if (page.isSuccess) { diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/types/AuthorizedTimeMatesRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/types/AuthorizedTimeMatesRequest.kt new file mode 100644 index 0000000..36bffc7 --- /dev/null +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/types/AuthorizedTimeMatesRequest.kt @@ -0,0 +1,18 @@ +package io.timemates.sdk.common.types + +import io.timemates.sdk.authorization.types.value.AccessHash + +/** + * An abstract class representing an authorized request within the TimeMates system. + * Subclasses of this class are used to perform operations that require valid + * authorization via an access hash. + * + * @param R The response type expected from the request. + */ +public abstract class AuthorizedTimeMatesRequest : TimeMatesRequest() { + /** + * The access hash associated with this authorized request. + * It is used for authentication and authorization purposes. + */ + public abstract val accessHash: AccessHash +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/types/TimeMatesRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/types/TimeMatesRequest.kt index b74177f..531a182 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/types/TimeMatesRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/types/TimeMatesRequest.kt @@ -8,4 +8,15 @@ package io.timemates.sdk.common.types * * @param R The type of the response expected from the request. */ -public abstract class TimeMatesRequest internal constructor() : TimeMatesEntity() \ No newline at end of file +public abstract class TimeMatesRequest internal constructor() : TimeMatesEntity() { + /** + * A unique key that identifies this request type. + */ + public abstract val requestKey: Key<*> + + /** + * An interface representing the key associated with a [TimeMatesRequest]. + * @param T The specific type of the [TimeMatesRequest]. + */ + public interface Key> +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/GetFileBytesRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/GetFileBytesRequest.kt index 8aa4b3e..d5faea7 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/GetFileBytesRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/GetFileBytesRequest.kt @@ -8,7 +8,11 @@ import kotlinx.coroutines.flow.Flow public data class GetFileBytesRequest( val fileId: FileId, ) : TimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + public data class Result( val bytes: Flow ) : TimeMatesEntity() + + override val requestKey: Key = Key } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/UploadFileRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/UploadFileRequest.kt index 00e1c44..2d2d9bb 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/UploadFileRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/UploadFileRequest.kt @@ -1,18 +1,18 @@ package io.timemates.sdk.files.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.TimeMatesEntity -import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.files.types.FileType import io.timemates.sdk.files.types.value.FileId import io.timemates.sdk.files.types.value.FileName import kotlinx.coroutines.flow.Flow public data class UploadFileRequest( - val accessHash: AccessHash, + override val accessHash: AccessHash, val bytes: Flow, val fileName: FileName, val fileType: FileType, -) : TimeMatesRequest() { +) : AuthorizedTimeMatesRequest() { public data class Result(val fileId: FileId) : TimeMatesEntity() } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/files/types/FileType.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/files/types/FileType.kt index 986a99d..8cd32c8 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/files/types/FileType.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/files/types/FileType.kt @@ -1,7 +1,5 @@ package io.timemates.sdk.files.types -import io.timemates.sdk.common.types.TimeMatesEntity - public enum class FileType { IMAGE, } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/CreateInviteRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/CreateInviteRequest.kt index fbe8f2b..c4279f6 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/CreateInviteRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/CreateInviteRequest.kt @@ -1,17 +1,21 @@ package io.timemates.sdk.timers.members.invites.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.TimeMatesEntity import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.common.types.value.Count import io.timemates.sdk.timers.members.invites.types.value.InviteCode -import io.timemates.sdk.timers.members.invites.types.value.InviteName import io.timemates.sdk.timers.types.value.TimerId public data class CreateInviteRequest( - val accessHash: AccessHash, + override val accessHash: AccessHash, val timerId: TimerId, val maxJoinersCount: Count, -) : TimeMatesRequest() { +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key + public data class Result(public val inviteCode: InviteCode) : TimeMatesEntity() } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/GetInvitesRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/GetInvitesRequest.kt index 3a22851..bdef1d1 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/GetInvitesRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/GetInvitesRequest.kt @@ -3,13 +3,17 @@ package io.timemates.sdk.timers.members.invites.requests import io.timemates.sdk.authorization.types.value.AccessHash import io.timemates.sdk.common.pagination.Page import io.timemates.sdk.common.pagination.PageToken -import io.timemates.sdk.common.types.TimeMatesEntity +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.timers.members.invites.types.Invite import io.timemates.sdk.timers.types.value.TimerId public data class GetInvitesRequest( - val accessHash: AccessHash, + override val accessHash: AccessHash, val timerId: TimerId, val pageToken: PageToken?, -) : TimeMatesRequest>() \ No newline at end of file +) : AuthorizedTimeMatesRequest>() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/JoinTimerByCodeRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/JoinTimerByCodeRequest.kt new file mode 100644 index 0000000..b698124 --- /dev/null +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/JoinTimerByCodeRequest.kt @@ -0,0 +1,18 @@ +package io.timemates.sdk.timers.members.invites.requests + +import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.TimeMatesEntity +import io.timemates.sdk.common.types.TimeMatesRequest +import io.timemates.sdk.timers.members.invites.types.value.InviteCode +import io.timemates.sdk.timers.types.value.TimerId + +public data class JoinTimerByCodeRequest( + public val code: InviteCode, + public val accessHash: AccessHash, +) : TimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key + + public data class Result(val timerId: TimerId) : TimeMatesEntity() +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/RemoveInviteRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/RemoveInviteRequest.kt index f26c260..df6152a 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/RemoveInviteRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/RemoveInviteRequest.kt @@ -1,13 +1,18 @@ package io.timemates.sdk.timers.members.invites.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.Empty import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.timers.members.invites.types.value.InviteCode import io.timemates.sdk.timers.types.value.TimerId public data class RemoveInviteRequest( - val accessHash: AccessHash, + override val accessHash: AccessHash, val timerId: TimerId, val inviteCode: InviteCode, -) : TimeMatesRequest() \ No newline at end of file +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/requests/GetMembersRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/requests/GetMembersRequest.kt index c8e4d1b..bdaac90 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/requests/GetMembersRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/requests/GetMembersRequest.kt @@ -3,13 +3,17 @@ package io.timemates.sdk.timers.members.requests import io.timemates.sdk.authorization.types.value.AccessHash import io.timemates.sdk.common.pagination.Page import io.timemates.sdk.common.pagination.PageToken -import io.timemates.sdk.common.types.TimeMatesEntity +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.timers.types.value.TimerId import io.timemates.sdk.users.profile.types.User public data class GetMembersRequest( - val accessHash: AccessHash, + override val accessHash: AccessHash, val timerId: TimerId, val pageToken: PageToken?, -) : TimeMatesRequest>() \ No newline at end of file +) : AuthorizedTimeMatesRequest>() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/requests/KickMemberRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/requests/KickMemberRequest.kt index 8b8909a..a3005f8 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/requests/KickMemberRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/requests/KickMemberRequest.kt @@ -10,4 +10,8 @@ public data class KickMemberRequest( val accessHash: AccessHash, val timerId: TimerId, val userId: UserId, -) : TimeMatesRequest() \ No newline at end of file +) : TimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/CreateTimerRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/CreateTimerRequest.kt index 759de46..be3e950 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/CreateTimerRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/CreateTimerRequest.kt @@ -1,6 +1,7 @@ package io.timemates.sdk.timers.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.TimeMatesEntity import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.timers.types.TimerSettings @@ -9,10 +10,14 @@ import io.timemates.sdk.timers.types.value.TimerId import io.timemates.sdk.timers.types.value.TimerName public data class CreateTimerRequest( - val accessHash: AccessHash, + override val accessHash: AccessHash, val name: TimerName, val description: TimerDescription, val settings: TimerSettings, -) : TimeMatesRequest() { +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key + public data class Result(val timerId: TimerId) : TimeMatesEntity() } diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/EditTimerRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/EditTimerRequest.kt index b194b7b..4a72708 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/EditTimerRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/EditTimerRequest.kt @@ -1,6 +1,7 @@ package io.timemates.sdk.timers.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.Empty import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.timers.types.TimerSettings @@ -9,9 +10,13 @@ import io.timemates.sdk.timers.types.value.TimerId import io.timemates.sdk.timers.types.value.TimerName public data class EditTimerRequest( - val accessHash: AccessHash, + override val accessHash: AccessHash, val timerId: TimerId, val name: TimerName? = null, val description: TimerDescription? = null, val settings: TimerSettings.Patch? = null, -) : TimeMatesRequest() \ No newline at end of file +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/GetTimerRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/GetTimerRequest.kt index 2b6f6b8..d84b5c3 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/GetTimerRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/GetTimerRequest.kt @@ -1,15 +1,20 @@ package io.timemates.sdk.timers.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.TimeMatesEntity import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.timers.types.Timer import io.timemates.sdk.timers.types.value.TimerId public data class GetTimerRequest( - val accessHash: AccessHash, + override val accessHash: AccessHash, val timerId: TimerId, -) : TimeMatesRequest() { +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key + public data class Result( val timer: Timer, ) : TimeMatesEntity() diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/GetUserTimersRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/GetUserTimersRequest.kt index f5f86e2..68a9f61 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/GetUserTimersRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/GetUserTimersRequest.kt @@ -3,10 +3,15 @@ package io.timemates.sdk.timers.requests import io.timemates.sdk.authorization.types.value.AccessHash import io.timemates.sdk.common.pagination.Page import io.timemates.sdk.common.pagination.PageToken +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.timers.types.Timer public data class GetUserTimersRequest( - val accessHash: AccessHash, + override val accessHash: AccessHash, val pageToken: PageToken?, -) : TimeMatesRequest>() \ No newline at end of file +) : AuthorizedTimeMatesRequest>() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/RemoveTimerRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/RemoveTimerRequest.kt index 262a9e6..60f4b72 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/RemoveTimerRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/requests/RemoveTimerRequest.kt @@ -8,4 +8,8 @@ import io.timemates.sdk.timers.types.value.TimerId public data class RemoveTimerRequest( val accessHash: AccessHash, val timerId: TimerId, -) : TimeMatesRequest() \ No newline at end of file +) : TimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/ConfirmTimerRoundRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/ConfirmTimerRoundRequest.kt index 07e7533..07d97ad 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/ConfirmTimerRoundRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/ConfirmTimerRoundRequest.kt @@ -1,10 +1,14 @@ package io.timemates.sdk.timers.sessions.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.Empty import io.timemates.sdk.common.types.TimeMatesRequest -import io.timemates.sdk.timers.types.value.TimerId public data class ConfirmTimerRoundRequest( - val accessHash: AccessHash, -) : TimeMatesRequest() \ No newline at end of file + override val accessHash: AccessHash, +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/GetTimerStateRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/GetTimerStateRequest.kt index 8f5fc45..096e887 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/GetTimerStateRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/GetTimerStateRequest.kt @@ -1,7 +1,7 @@ package io.timemates.sdk.timers.sessions.requests import io.timemates.sdk.authorization.types.value.AccessHash -import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.TimeMatesEntity import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.timers.types.Timer @@ -12,8 +12,12 @@ import kotlinx.coroutines.flow.Flow * Gets timer session state. */ public data class GetTimerStateRequest( - val accessHash: AccessHash, + override val accessHash: AccessHash, val timerId: TimerId, -) : TimeMatesRequest() { +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key + public data class Result(val flow: Flow) : TimeMatesEntity() } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/GetUserCurrentSessionRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/GetUserCurrentSessionRequest.kt index b87f957..bbab4bf 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/GetUserCurrentSessionRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/GetUserCurrentSessionRequest.kt @@ -1,6 +1,7 @@ package io.timemates.sdk.timers.sessions.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.timers.types.Timer @@ -8,5 +9,10 @@ import io.timemates.sdk.timers.types.Timer * Gets current timer session. */ public data class GetUserCurrentSessionRequest( - val accessHash: AccessHash, -) : TimeMatesRequest() \ No newline at end of file + override val accessHash: AccessHash, +) : AuthorizedTimeMatesRequest() { + + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/JoinTimerSessionRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/JoinTimerSessionRequest.kt index 0727f89..c60c0de 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/JoinTimerSessionRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/JoinTimerSessionRequest.kt @@ -1,11 +1,16 @@ package io.timemates.sdk.timers.sessions.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.Empty import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.timers.types.value.TimerId public data class JoinTimerSessionRequest( - val accessHash: AccessHash, + override val accessHash: AccessHash, val timerId: TimerId, -) : TimeMatesRequest() \ No newline at end of file +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/LeaveTimerSessionRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/LeaveTimerSessionRequest.kt index b93e0cb..ff23c1b 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/LeaveTimerSessionRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/LeaveTimerSessionRequest.kt @@ -1,10 +1,14 @@ package io.timemates.sdk.timers.sessions.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.Empty import io.timemates.sdk.common.types.TimeMatesRequest -import io.timemates.sdk.timers.types.value.TimerId public data class LeaveTimerSessionRequest( - val accessHash: AccessHash, -) : TimeMatesRequest() \ No newline at end of file + override val accessHash: AccessHash, +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/PingSessionRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/PingSessionRequest.kt index bbb741b..8c48343 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/PingSessionRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/PingSessionRequest.kt @@ -1,10 +1,14 @@ package io.timemates.sdk.timers.sessions.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.Empty import io.timemates.sdk.common.types.TimeMatesRequest -import io.timemates.sdk.timers.types.value.TimerId public data class PingSessionRequest( - val accessHash: AccessHash, -) : TimeMatesRequest() \ No newline at end of file + override val accessHash: AccessHash, +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/StartTimerRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/StartTimerRequest.kt index 3591187..d79d4f5 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/StartTimerRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/StartTimerRequest.kt @@ -1,6 +1,7 @@ package io.timemates.sdk.timers.sessions.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.Empty import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.timers.types.value.TimerId @@ -9,6 +10,10 @@ import io.timemates.sdk.timers.types.value.TimerId * Starts timer session if user didn't joined any yet. */ public data class StartTimerRequest( - val accessHash: AccessHash, + override val accessHash: AccessHash, val timerId: TimerId, -) : TimeMatesRequest() \ No newline at end of file +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/StopTimerRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/StopTimerRequest.kt index d8849d0..77af17c 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/StopTimerRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/sessions/requests/StopTimerRequest.kt @@ -1,6 +1,7 @@ package io.timemates.sdk.timers.sessions.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.Empty import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.timers.types.value.TimerId @@ -9,6 +10,10 @@ import io.timemates.sdk.timers.types.value.TimerId * Stops timer session. */ public data class StopTimerRequest( - val accessHash: AccessHash, + override val accessHash: AccessHash, val timerId: TimerId, -) : TimeMatesRequest() \ No newline at end of file +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/UserApi.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/UserApi.kt index 50e6cf5..3ed3b49 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/UserApi.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/UserApi.kt @@ -1,6 +1,5 @@ package io.timemates.sdk.users -import io.timemates.sdk.authorization.types.value.AccessHash import io.timemates.sdk.common.engine.TimeMatesRequestsEngine import io.timemates.sdk.common.providers.AccessHashProvider import io.timemates.sdk.users.profile.ProfileApi @@ -10,7 +9,7 @@ import io.timemates.sdk.users.settings.UserSettingsApi * Provides access to user-related functionality through the API. * * @param engine The TimeMatesRequestsEngine instance used for making API requests. - * @param accessHash The access hash for authentication purposes. + * @param tokenProvider The provider of access hash for authentication purposes. */ public class UserApi(engine: TimeMatesRequestsEngine, tokenProvider: AccessHashProvider) { /** diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/ProfileApi.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/ProfileApi.kt index eda56f8..769edf7 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/ProfileApi.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/ProfileApi.kt @@ -9,7 +9,6 @@ import io.timemates.sdk.users.profile.requests.EditProfileRequest import io.timemates.sdk.users.profile.requests.GetUsersRequest import io.timemates.sdk.users.profile.types.Avatar import io.timemates.sdk.users.profile.types.User -import io.timemates.sdk.users.profile.types.value.EmailAddress import io.timemates.sdk.users.profile.types.value.UserDescription import io.timemates.sdk.users.profile.types.value.UserId import io.timemates.sdk.users.profile.types.value.UserName @@ -18,7 +17,7 @@ import io.timemates.sdk.users.profile.types.value.UserName * Provides functionality for accessing and modifying user profiles through the API. * * @property engine The TimeMatesRequestsEngine instance used for making API requests. - * @property accessHash The access hash for authentication purposes. + * @property tokenProvider The provider of access hash for authentication purposes. */ public class ProfileApi( private val engine: TimeMatesRequestsEngine, diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/requests/EditProfileRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/requests/EditProfileRequest.kt index cbe97af..3bfe96b 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/requests/EditProfileRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/requests/EditProfileRequest.kt @@ -1,16 +1,20 @@ package io.timemates.sdk.users.profile.requests import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.Empty import io.timemates.sdk.common.types.TimeMatesRequest -import io.timemates.sdk.files.types.value.FileId import io.timemates.sdk.users.profile.types.Avatar import io.timemates.sdk.users.profile.types.value.UserDescription import io.timemates.sdk.users.profile.types.value.UserName public data class EditProfileRequest( - val accessHash: AccessHash, + override val accessHash: AccessHash, val name: UserName?, val description: UserDescription?, - val avatar: Avatar? -) : TimeMatesRequest() \ No newline at end of file + val avatar: Avatar?, +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/requests/GetUsersRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/requests/GetUsersRequest.kt index 353e241..9c8af86 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/requests/GetUsersRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/requests/GetUsersRequest.kt @@ -8,5 +8,9 @@ import io.timemates.sdk.users.profile.types.value.UserId public data class GetUsersRequest( val users: List, ) : TimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + public data class Result(val users: List) : TimeMatesEntity() + + override val requestKey: Key get() = Key } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/User.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/User.kt index 9f4b62f..70bbc93 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/User.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/User.kt @@ -12,13 +12,13 @@ import io.timemates.sdk.users.profile.types.value.UserName * @property id The unique identifier of the user. * @property name The name of the user. * @property description The description of the user. - * @property avatarFileId The unique identifier of the user's avatar file. + * @property avatar The user's avatar file. * @property emailAddress The email address associated with the user (null if not available). */ public data class User( val id: UserId, val name: UserName, - val description: UserDescription, + val description: UserDescription?, val emailAddress: EmailAddress?, val avatar: Avatar?, ) : TimeMatesEntity() \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/settings/UserSettingsApi.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/settings/UserSettingsApi.kt index bb09758..5833f98 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/settings/UserSettingsApi.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/settings/UserSettingsApi.kt @@ -1,6 +1,5 @@ package io.timemates.sdk.users.settings -import io.timemates.sdk.authorization.types.value.AccessHash import io.timemates.sdk.common.annotations.UnimplementedApi import io.timemates.sdk.common.engine.TimeMatesRequestsEngine import io.timemates.sdk.common.providers.AccessHashProvider diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/settings/requests/EditEmailRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/settings/requests/EditEmailRequest.kt index b697a52..c487b9b 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/settings/requests/EditEmailRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/settings/requests/EditEmailRequest.kt @@ -1,9 +1,25 @@ package io.timemates.sdk.users.settings.requests +import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.common.annotations.ApiStatus +import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi +import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.Empty import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.users.profile.types.value.EmailAddress +/** + * This request is not implemented on server yet. Always throws + * [io.timemates.sdk.common.exceptions.UnsupportedException]. + * + * TODO: remove notice once implemented + */ +@ExperimentalTimeMatesApi(status = ApiStatus.IN_PROGRESS) public data class EditEmailRequest( val newEmail: EmailAddress, -) : TimeMatesRequest() \ No newline at end of file + override val accessHash: AccessHash, +) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + + override val requestKey: Key get() = Key +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index bd3faff..52e3530 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -24,4 +24,5 @@ includeBuild("build-logic/publish-library-plugin") include(":sdk") include(":grpc-engine") +include(":rsocket-engine") include(":grpc-engine:android") From 87e0c798169853f22948efcb7dcc44f26fa93f9d Mon Sep 17 00:00:00 2001 From: y9vad9 Date: Wed, 27 Sep 2023 18:49:55 +0200 Subject: [PATCH 02/13] feat: `files` api --- .../rsocket/common/serialization/JsonExt.kt | 5 +++ .../files/commands/FilesCommandsRegistry.kt | 2 + .../rsocket/files/commands/GetFileCommand.kt | 20 ++++----- .../files/commands/UploadFileCommand.kt | 43 +++++++++++++++++++ ...ileRequest.kt => RSocketGetFileRequest.kt} | 8 +++- ...Request.kt => RSocketUploadFileRequest.kt} | 2 +- .../files/types/SerializableFileType.kt | 9 ++++ .../sdk/files/requests/GetFileBytesRequest.kt | 2 + .../sdk/files/requests/UploadFileRequest.kt | 5 +++ 9 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/UploadFileCommand.kt rename rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/{GetFileRequest.kt => RSocketGetFileRequest.kt} (64%) rename rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/{UploadFileRequest.kt => RSocketUploadFileRequest.kt} (90%) diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/serialization/JsonExt.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/serialization/JsonExt.kt index ee8b7ff..4e6a368 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/serialization/JsonExt.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/serialization/JsonExt.kt @@ -6,6 +6,7 @@ import io.rsocket.kotlin.payload.Payload import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import kotlinx.serialization.json.decodeFromStream @@ -17,6 +18,10 @@ internal fun T.encodeToJson(serializationStrategy: SerializationStrategy) return ByteReadPacket(json.encodeToString(serializationStrategy, this).encodeToByteArray()) } +internal inline fun ByteArray.decodeFromJson(): T { + return json.decodeFromString(String(this)) +} + @OptIn(ExperimentalSerializationApi::class) internal fun Payload.decodeFromJson(deserializationStrategy: DeserializationStrategy): T { return json.decodeFromStream(deserializationStrategy, data.inputStream()) diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/FilesCommandsRegistry.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/FilesCommandsRegistry.kt index 5b18e95..4918e7e 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/FilesCommandsRegistry.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/FilesCommandsRegistry.kt @@ -2,10 +2,12 @@ package io.timemates.api.rsocket.files.commands import io.timemates.api.rsocket.common.commands.RSocketCommandsBuilderScope import io.timemates.sdk.files.requests.GetFileBytesRequest +import io.timemates.sdk.files.requests.UploadFileRequest /** * RSocket commands related to timers. */ internal fun RSocketCommandsBuilderScope.files() { GetFileCommand associatedWith GetFileBytesRequest + UploadFileCommand associatedWith UploadFileRequest } \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/GetFileCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/GetFileCommand.kt index 9115fb6..c4f6066 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/GetFileCommand.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/GetFileCommand.kt @@ -1,22 +1,22 @@ package io.timemates.api.rsocket.files.commands import io.rsocket.kotlin.RSocket -import io.rsocket.kotlin.payload.buildPayload import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.serialization.encodeToJson -import io.timemates.api.rsocket.files.requests.GetFileRequest +import io.timemates.api.rsocket.common.ext.requestStream +import io.timemates.api.rsocket.common.serialization.decodeFromJson +import io.timemates.api.rsocket.files.requests.RSocketGetFileRequest +import io.timemates.api.rsocket.files.types.sdk import io.timemates.sdk.files.requests.GetFileBytesRequest -import kotlinx.serialization.serializer +import kotlinx.coroutines.flow.first internal object GetFileCommand : RSocketCommand { override suspend fun execute(rSocket: RSocket, input: GetFileBytesRequest): GetFileBytesRequest.Result { - return rSocket.requestResponse( - buildPayload { - data(GetFileRequest(input.fileId.string).encodeToJson(serializer())) - } + return rSocket.requestStream( + route = "files.get", + data = RSocketGetFileRequest(input.fileId.string), ).let { result -> -// GetFileBytesRequest.Result(result.data) - TODO() + val metadata = result.first().decodeFromJson() + GetFileBytesRequest.Result(metadata.fileType.sdk(), result) } } } \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/UploadFileCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/UploadFileCommand.kt new file mode 100644 index 0000000..452b632 --- /dev/null +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/UploadFileCommand.kt @@ -0,0 +1,43 @@ +package io.timemates.api.rsocket.files.commands + +import io.ktor.utils.io.core.ByteReadPacket +import io.rsocket.kotlin.ExperimentalMetadataApi +import io.rsocket.kotlin.RSocket +import io.rsocket.kotlin.metadata.RoutingMetadata +import io.rsocket.kotlin.metadata.compositeMetadata +import io.rsocket.kotlin.payload.Payload +import io.rsocket.kotlin.payload.buildPayload +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.common.serialization.decodeFromJson +import io.timemates.api.rsocket.common.serialization.encodeToJson +import io.timemates.api.rsocket.files.requests.RSocketUploadFileRequest +import io.timemates.api.rsocket.files.types.serializable +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.files.requests.UploadFileRequest +import io.timemates.sdk.files.types.value.FileId +import kotlinx.coroutines.flow.last +import kotlinx.coroutines.flow.map +import kotlinx.serialization.serializer + +internal object UploadFileCommand : RSocketCommand { + @OptIn(ExperimentalMetadataApi::class) + override suspend fun execute(rSocket: RSocket, input: UploadFileRequest): UploadFileRequest.Result { + return rSocket.requestChannel( + initPayload = buildPayload { + data( + RSocketUploadFileRequest.Metadata( + fileName = input.fileName.string, + fileType = input.fileType.serializable(), + ).encodeToJson(serializer()) + ) + compositeMetadata { + add(RoutingMetadata("files.upload")) + } + }, + payloads = input.bytes.map { Payload(data = ByteReadPacket(it)) } + ).let { result -> + val serialized = result.last().decodeFromJson(serializer()) + UploadFileRequest.Result(fileId = FileId.createOrThrow(serialized.fileId)) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/GetFileRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/RSocketGetFileRequest.kt similarity index 64% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/GetFileRequest.kt rename to rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/RSocketGetFileRequest.kt index 8858a0f..878f02f 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/GetFileRequest.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/RSocketGetFileRequest.kt @@ -1,18 +1,22 @@ package io.timemates.api.rsocket.files.requests +import io.timemates.api.rsocket.common.markers.RSocketRequest import io.timemates.api.rsocket.files.types.SerializableFileType +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -internal data class GetFileRequest( +internal data class RSocketGetFileRequest( val fileId: String, -) { +) : RSocketRequest { @Serializable sealed interface Response { + @SerialName("metadata") data class Metadata( val fileType: SerializableFileType, ) : Response + @SerialName("chunk") @JvmInline value class Chunk(val bytes: ByteArray) : Response } diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/UploadFileRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/RSocketUploadFileRequest.kt similarity index 90% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/UploadFileRequest.kt rename to rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/RSocketUploadFileRequest.kt index ccc8809..d92091b 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/UploadFileRequest.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/RSocketUploadFileRequest.kt @@ -5,7 +5,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.serialization.Serializable @Serializable -internal data class UploadFileRequest( +internal data class RSocketUploadFileRequest( val fileType: SerializableFileType, val bytes: Flow, ) { diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFileType.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFileType.kt index 0c6f69e..a5ff0f8 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFileType.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFileType.kt @@ -1,5 +1,6 @@ package io.timemates.api.rsocket.files.types +import io.timemates.sdk.files.types.FileType import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -7,4 +8,12 @@ import kotlinx.serialization.Serializable internal enum class SerializableFileType { @SerialName("image") IMAGE, +} + +internal fun SerializableFileType.sdk(): FileType = when (this) { + SerializableFileType.IMAGE -> FileType.IMAGE +} + +internal fun FileType.serializable(): SerializableFileType = when (this) { + FileType.IMAGE -> SerializableFileType.IMAGE } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/GetFileBytesRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/GetFileBytesRequest.kt index d5faea7..e95b864 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/GetFileBytesRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/GetFileBytesRequest.kt @@ -2,6 +2,7 @@ package io.timemates.sdk.files.requests import io.timemates.sdk.common.types.TimeMatesEntity import io.timemates.sdk.common.types.TimeMatesRequest +import io.timemates.sdk.files.types.FileType import io.timemates.sdk.files.types.value.FileId import kotlinx.coroutines.flow.Flow @@ -11,6 +12,7 @@ public data class GetFileBytesRequest( public companion object Key : TimeMatesRequest.Key public data class Result( + val fileType: FileType, val bytes: Flow ) : TimeMatesEntity() diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/UploadFileRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/UploadFileRequest.kt index 2d2d9bb..36c13a7 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/UploadFileRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/files/requests/UploadFileRequest.kt @@ -3,6 +3,7 @@ package io.timemates.sdk.files.requests import io.timemates.sdk.authorization.types.value.AccessHash import io.timemates.sdk.common.types.AuthorizedTimeMatesRequest import io.timemates.sdk.common.types.TimeMatesEntity +import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.files.types.FileType import io.timemates.sdk.files.types.value.FileId import io.timemates.sdk.files.types.value.FileName @@ -14,5 +15,9 @@ public data class UploadFileRequest( val fileName: FileName, val fileType: FileType, ) : AuthorizedTimeMatesRequest() { + public companion object Key : TimeMatesRequest.Key + public data class Result(val fileId: FileId) : TimeMatesEntity() + + override val requestKey: Key get() = Key } \ No newline at end of file From ac2113994981f7d1e60946f58eb0880513e92efc Mon Sep 17 00:00:00 2001 From: y9vad9 Date: Wed, 27 Sep 2023 20:32:24 +0200 Subject: [PATCH 03/13] refactor: `grpc-engine` removal --- grpc-engine/android/build.gradle.kts | 48 -- .../android/grpc/AndroidGrpcEngineBuilder.kt | 15 - grpc-engine/build.gradle.kts | 72 --- .../api/grpc/GrpcTimeMatesRequestsEngine.kt | 429 ------------------ .../grpc/factory/DefaultGrpcEngineBuilder.kt | 12 - .../api/grpc/factory/GrpcEngineBuilder.kt | 7 - .../timemates/api/grpc/internal/ResultExt.kt | 16 - .../api/grpc/mappers/AuthorizationsMapper.kt | 39 -- .../timemates/api/grpc/mappers/FilesMapper.kt | 13 - .../api/grpc/mappers/TimersMapper.kt | 116 ----- .../timemates/api/grpc/mappers/UsersMapper.kt | 23 - .../authorizations/AuthorizationService.proto | 49 -- .../options/OmitAuthorizationOption.proto | 13 - .../ConfirmAuthorizationRequest.proto | 15 - .../requests/CreateProfileRequest.proto | 22 - .../requests/GetAuthorizationsRequest.proto | 14 - .../requests/StartAuthorizationRequest.proto | 13 - .../authorizations/types/Authorization.proto | 40 -- .../io/timemates/api/files/FilesService.proto | 23 - .../files/requests/GetFileBytesRequest.proto | 14 - .../files/requests/UploadFileRequest.proto | 31 -- .../timemates/api/timers/TimersService.proto | 68 --- .../requests/CreateInviteRequest.proto | 13 - .../invites/requests/GetInvitesRequest.proto | 15 - .../requests/RemoveInviteRequest.proto | 8 - .../timers/members/invites/types/Invite.proto | 9 - .../members/requests/GetMembersRequest.proto | 14 - .../members/requests/KickMemberRequest.proto | 8 - .../timers/requests/CreateTimerRequest.proto | 24 - .../requests/EditTimerInfoRequest.proto | 23 - .../api/timers/requests/GetTimerRequest.proto | 7 - .../timers/requests/GetTimersRequest.proto | 13 - .../timers/requests/RemoveTimerRequest.proto | 9 - .../sessions/TimerSessionsService.proto | 71 --- .../requests/ConfirmTimerSessionRequest.proto | 7 - .../requests/GetTimerStateRequest.proto | 7 - .../GetUserCurrentSessionRequest.proto | 11 - .../requests/JoinTimerSessionRequest.proto | 7 - .../requests/StartTimerSessionRequest.proto | 7 - .../requests/StopTimerSessionRequest.proto | 7 - .../timers/sessions/types/TimerState.proto | 76 ---- .../io/timemates/api/timers/types/Timer.proto | 111 ----- .../io/timemates/api/users/UsersService.proto | 32 -- .../api/users/requests/EditEmailRequest.proto | 7 - .../api/users/requests/EditUserRequest.proto | 22 - .../api/users/requests/GetUsersRequest.proto | 7 - .../io/timemates/api/users/types/User.proto | 39 -- rsocket-engine/build.gradle.kts | 18 + .../exceptions/handler/SafeExceptionResult.kt | 225 --------- settings.gradle.kts | 2 - 50 files changed, 18 insertions(+), 1873 deletions(-) delete mode 100644 grpc-engine/android/build.gradle.kts delete mode 100644 grpc-engine/android/src/main/kotlin/io/timemates/android/grpc/AndroidGrpcEngineBuilder.kt delete mode 100644 grpc-engine/build.gradle.kts delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/GrpcTimeMatesRequestsEngine.kt delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/DefaultGrpcEngineBuilder.kt delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/GrpcEngineBuilder.kt delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/internal/ResultExt.kt delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/AuthorizationsMapper.kt delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/FilesMapper.kt delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/TimersMapper.kt delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/UsersMapper.kt delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/authorizations/options/OmitAuthorizationOption.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/CreateProfileRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/files/FilesService.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/files/requests/GetFileBytesRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/files/requests/UploadFileRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/TimersService.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/types/Invite.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/GetMembersRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/KickMemberRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/requests/CreateTimerRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/requests/EditTimerInfoRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimerRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimersRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/requests/RemoveTimerRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/TimerSessionsService.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetUserCurrentSessionRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/types/TimerState.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/types/Timer.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/users/UsersService.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/users/requests/EditEmailRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/users/requests/EditUserRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/users/requests/GetUsersRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/users/types/User.proto delete mode 100644 sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/handler/SafeExceptionResult.kt diff --git a/grpc-engine/android/build.gradle.kts b/grpc-engine/android/build.gradle.kts deleted file mode 100644 index 27b1883..0000000 --- a/grpc-engine/android/build.gradle.kts +++ /dev/null @@ -1,48 +0,0 @@ -plugins { - alias(libs.plugins.android.library) - alias(libs.plugins.kotlin.android) - alias(libs.plugins.library.publish) -} - -android { - compileSdk = libs.versions.android.target.get().toInt() - - defaultConfig { - minSdk = libs.versions.android.min.get().toInt() - } - - compileOptions { - targetCompatibility = JavaVersion.VERSION_17 - sourceCompatibility = JavaVersion.VERSION_17 - } - - namespace = "io.timemates.android.grpc" -} - -dependencies { - implementation(projects.grpcEngine) - - implementation(libs.grpc.android) -} - -kotlin { - jvmToolchain(17) -} - -deployLibrary { - ssh(tag = "maven.timemates.io") { - host = System.getenv("TIMEMATES_SSH_HOST") - user = System.getenv("TIMEMATES_SSH_USER") - password = System.getenv("TIMEMATES_SSH_PASSWORD") - deployPath = System.getenv("TIMEMATES_SSH_DEPLOY_PATH") - - group = "io.timemates" - componentName = "release" - artifactId = "grpc-engine-android" - name = "grpc-engine-android" - - description = "TimeMates android grpc adapter for SDK" - - version = System.getenv("TIMEMATES_SDK_VERSION") - } -} \ No newline at end of file diff --git a/grpc-engine/android/src/main/kotlin/io/timemates/android/grpc/AndroidGrpcEngineBuilder.kt b/grpc-engine/android/src/main/kotlin/io/timemates/android/grpc/AndroidGrpcEngineBuilder.kt deleted file mode 100644 index 377b055..0000000 --- a/grpc-engine/android/src/main/kotlin/io/timemates/android/grpc/AndroidGrpcEngineBuilder.kt +++ /dev/null @@ -1,15 +0,0 @@ -package io.timemates.android.grpc - -import android.content.Context -import io.grpc.ManagedChannel -import io.grpc.android.AndroidChannelBuilder -import io.timemates.api.grpc.factory.GrpcEngineBuilder - -class AndroidGrpcEngineBuilder(private val context: Context) : GrpcEngineBuilder { - override fun createGrpcEngine(endpoint: String): ManagedChannel { - return AndroidChannelBuilder.forTarget(endpoint) - .useTransportSecurity() - .context(context) - .build() - } -} \ No newline at end of file diff --git a/grpc-engine/build.gradle.kts b/grpc-engine/build.gradle.kts deleted file mode 100644 index cae6d30..0000000 --- a/grpc-engine/build.gradle.kts +++ /dev/null @@ -1,72 +0,0 @@ -import org.gradle.kotlin.dsl.dependencies -import org.gradle.kotlin.dsl.implementation -import org.gradle.kotlin.dsl.projects -import com.google.protobuf.gradle.id - -plugins { - alias(libs.plugins.kotlin.jvm) - alias(libs.plugins.google.protobuf) - alias(libs.plugins.library.publish) -} - -dependencies { - implementation(libs.kotlinx.coroutines) - implementation(libs.grpc.kotlin.stub) - implementation(libs.grpc.protobuf) - implementation(libs.grpc.netty) - implementation(libs.protobuf.kotlin) - implementation(libs.protobuf.java) - - implementation(libs.kotlinx.datetime) - implementation(projects.sdk) -} - -kotlin { - explicitApi() - jvmToolchain(17) -} - -protobuf { - protoc { - artifact = "com.google.protobuf:protoc:3.22.2" - } - plugins { - id("grpc") { - artifact = "io.grpc:protoc-gen-grpc-java:1.54.0" - } - id("grpckt") { - artifact = "io.grpc:protoc-gen-grpc-kotlin:1.3.0:jdk8@jar" - } - } - generateProtoTasks { - all().forEach { - it.plugins { - id("grpc") - id("grpckt") - } - it.builtins { - id("kotlin") - } - } - } -} - -group = "io.timemates" - -deployLibrary { - ssh(tag = "maven.timemates.io") { - host = System.getenv("TIMEMATES_SSH_HOST") - user = System.getenv("TIMEMATES_SSH_USER") - password = System.getenv("TIMEMATES_SSH_PASSWORD") - deployPath = System.getenv("TIMEMATES_SSH_DEPLOY_PATH") - - group = "io.timemates" - componentName = "kotlin" - artifactId = "grpc-engine" - name = "grpc-engine" - - description = "TimeMates grpc adapter for SDK" - - version = System.getenv("TIMEMATES_SDK_VERSION") - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/GrpcTimeMatesRequestsEngine.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/GrpcTimeMatesRequestsEngine.kt deleted file mode 100644 index cdda75b..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/GrpcTimeMatesRequestsEngine.kt +++ /dev/null @@ -1,429 +0,0 @@ -@file:Suppress("UNCHECKED_CAST") - -package io.timemates.api.grpc - -import com.google.protobuf.Empty -import com.google.protobuf.kotlin.toByteString -import io.grpc.Metadata -import io.grpc.Status -import io.grpc.StatusException -import io.timemates.api.authorizations.AuthorizationServiceGrpcKt -import io.timemates.api.files.FilesServiceGrpcKt -import io.timemates.api.files.requests.UploadFileRequestKt.fileMetadata -import io.timemates.api.grpc.factory.GrpcEngineBuilder -import io.timemates.api.grpc.internal.mapException -import io.timemates.api.grpc.mappers.AuthorizationsMapper -import io.timemates.api.grpc.mappers.FilesMapper -import io.timemates.api.grpc.mappers.TimersMapper -import io.timemates.api.grpc.mappers.UsersMapper -import io.timemates.api.timers.TimerSessionsServiceGrpcKt -import io.timemates.api.timers.TimersServiceGrpcKt -import io.timemates.api.timers.sessions.requests.getTimerStateRequest -import io.timemates.api.users.UsersServiceGrpcKt -import io.timemates.sdk.authorization.email.requests.ConfigureNewAccountRequest -import io.timemates.sdk.authorization.email.requests.ConfirmAuthorizationRequest -import io.timemates.sdk.authorization.email.requests.StartAuthorizationRequest -import io.timemates.sdk.authorization.email.types.value.VerificationHash -import io.timemates.sdk.authorization.sessions.requests.GetAuthorizationSessionsRequest -import io.timemates.sdk.authorization.sessions.requests.TerminateCurrentAuthorizationSessionRequest -import io.timemates.sdk.authorization.types.value.AccessHash -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.common.engine.TimeMatesRequestsEngine -import io.timemates.sdk.common.exceptions.AlreadyExistsException -import io.timemates.sdk.common.exceptions.InternalServerError -import io.timemates.sdk.common.exceptions.InvalidArgumentException -import io.timemates.sdk.common.exceptions.NotFoundException -import io.timemates.sdk.common.exceptions.PermissionDeniedException -import io.timemates.sdk.common.exceptions.TooManyRequestsException -import io.timemates.sdk.common.exceptions.UnauthorizedException -import io.timemates.sdk.common.exceptions.UnavailableException -import io.timemates.sdk.common.exceptions.UnsupportedException -import io.timemates.sdk.common.pagination.Page -import io.timemates.sdk.common.pagination.PageToken -import io.timemates.sdk.common.types.TimeMatesEntity -import io.timemates.sdk.common.types.TimeMatesRequest -import io.timemates.sdk.common.types.value.Count -import io.timemates.sdk.files.requests.GetFileBytesRequest -import io.timemates.sdk.files.requests.UploadFileRequest -import io.timemates.sdk.files.types.value.FileId -import io.timemates.sdk.timers.members.invites.requests.CreateInviteRequest -import io.timemates.sdk.timers.members.invites.requests.GetInvitesRequest -import io.timemates.sdk.timers.members.invites.requests.RemoveInviteRequest -import io.timemates.sdk.timers.members.invites.types.value.InviteCode -import io.timemates.sdk.timers.members.requests.GetMembersRequest -import io.timemates.sdk.timers.members.requests.KickMemberRequest -import io.timemates.sdk.timers.requests.* -import io.timemates.sdk.timers.sessions.requests.ConfirmTimerRoundRequest -import io.timemates.sdk.timers.sessions.requests.GetTimerStateRequest -import io.timemates.sdk.timers.sessions.requests.GetUserCurrentSessionRequest -import io.timemates.sdk.timers.sessions.requests.JoinTimerSessionRequest -import io.timemates.sdk.timers.sessions.requests.LeaveTimerSessionRequest -import io.timemates.sdk.timers.sessions.requests.PingSessionRequest -import io.timemates.sdk.timers.sessions.requests.StartTimerRequest -import io.timemates.sdk.timers.sessions.requests.StopTimerRequest -import io.timemates.sdk.timers.types.value.TimerId -import io.timemates.sdk.users.profile.requests.EditProfileRequest -import io.timemates.sdk.users.profile.requests.GetUsersRequest -import io.timemates.sdk.users.profile.types.Avatar -import io.timemates.sdk.users.settings.requests.EditEmailRequest -import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.flow.map -import kotlinx.datetime.Instant -import kotlin.reflect.KClass -import io.timemates.api.authorizations.requests.ConfirmAuthorizationRequestOuterClass.ConfirmAuthorizationRequest as GrpcConfirmAuthorizationRequest -import io.timemates.api.authorizations.requests.GetAuthorizationsRequestOuterClass.GetAuthorizationsRequest as GrpcGetAuthorizationsRequest -import io.timemates.api.authorizations.requests.StartAuthorizationRequestOuterClass.StartAuthorizationRequest as GrpcStartAuthorizationRequest -import io.timemates.api.files.requests.GetFileBytesRequestOuterClass.GetFileBytesRequest as GrpcGetFileBytesRequest -import io.timemates.api.files.requests.uploadFileRequest as buildUploadFileGrpcRequest -import io.timemates.api.timers.members.invites.requests.getInvitesRequest as buildGetInvitesGrpcRequest -import io.timemates.api.timers.members.invites.requests.inviteMemberRequest as buildCreateInviteGrpcRequest -import io.timemates.api.timers.members.invites.requests.removeInviteRequest as buildRemoveInviteGrpcRequest -import io.timemates.api.timers.members.requests.getMembersRequest as buildGetMembersGrpcRequest -import io.timemates.api.timers.members.requests.kickMemberRequest as buildKickMemberGrpcRequest -import io.timemates.api.timers.requests.CreateTimerRequestOuterClass.CreateTimerRequest as GrpcCreateTimerRequest -import io.timemates.api.timers.requests.EditTimerInfoRequest.EditTimerRequest as GrpcEditTimerRequest -import io.timemates.api.timers.requests.getTimerRequest as buildGetTimerGrpcRequest -import io.timemates.api.timers.requests.getTimersRequest as buildGetTimersGrpcRequest -import io.timemates.api.timers.requests.removeTimerRequest as buildRemoveTimerGrpcRequest -import io.timemates.api.timers.sessions.requests.joinTimerSessionRequest as buildJoinTimerSessionGrpcRequest -import io.timemates.api.timers.sessions.requests.startTimerRequest as buildStartTimerGrpcRequest -import io.timemates.api.timers.sessions.requests.stopTimerRequest as buildStopTimerGrpcRequest -import io.timemates.api.users.requests.CreateProfileRequestOuterClass.CreateProfileRequest as GrpcCreateProfileRequest -import io.timemates.api.users.requests.EditUserRequestOuterClass.EditUserRequest as GrpcEditUserRequest -import io.timemates.api.users.requests.GetUsersRequestOuterClass.GetUsersRequest as GrpcGetUsersRequest -import io.timemates.sdk.common.types.Empty as SdkEmpty - -/** - * gRPC-based implementation of the TimeMatesRequestsEngine interface. - * - * @param endpoint The endpoint URL for the gRPC API. Default value is "https://api.timemates.io". - */ -public class GrpcTimeMatesRequestsEngine( - endpoint: String = "api.timemates.io", - grpcEngineBuilder: GrpcEngineBuilder, -) : TimeMatesRequestsEngine { - private companion object { - val ACCESS_TOKEN: Metadata.Key = Metadata.Key.of("access-token", Metadata.ASCII_STRING_MARSHALLER) - } - - private val channel = grpcEngineBuilder.createGrpcEngine(endpoint) - - private val authorizationService = AuthorizationServiceGrpcKt.AuthorizationServiceCoroutineStub(channel) - private val authMapper = AuthorizationsMapper() - - private val filesService = FilesServiceGrpcKt.FilesServiceCoroutineStub(channel) - private val filesMapper = FilesMapper() - - private val usersService = UsersServiceGrpcKt.UsersServiceCoroutineStub(channel) - private val usersMapper = UsersMapper() - - private val timersService = TimersServiceGrpcKt.TimersServiceCoroutineStub(channel) - private val timerSessionsService = TimerSessionsServiceGrpcKt.TimerSessionsServiceCoroutineStub(channel) - private val timersMapper = TimersMapper() - - override suspend fun execute(request: TimeMatesRequest): Result = runCatching { - when (request) { - is StartAuthorizationRequest -> authorizationService.startAuthorization( - GrpcStartAuthorizationRequest - .newBuilder() - .setEmailAddress(request.emailAddress.string) - .build() - ).let { - StartAuthorizationRequest.Result( - verificationHash = VerificationHash.createOrThrow(it.verificationHash), - attempts = Count.createOrThrow(it.attempts), - expiresAt = Instant.fromEpochMilliseconds(it.expiresAt), - ) - } - - is ConfirmAuthorizationRequest -> authorizationService.confirmAuthorization( - GrpcConfirmAuthorizationRequest - .newBuilder() - .setConfirmationCode(request.confirmationCode.string) - .setVerificationHash(request.verificationHash.string) - .build() - ).let { response -> - ConfirmAuthorizationRequest.Result( - isNewAccount = response.isNewAccount, - authorization = response.authorization.takeIf { !response.isNewAccount } - ?.let(authMapper::grpcAuthorizationToSdkAuthorization), - ) - } - - is ConfigureNewAccountRequest -> authorizationService.createProfile( - GrpcCreateProfileRequest.newBuilder() - .setName(request.name.string) - .setDescription(request.description.string) - .setVerificationHash(request.verificationHash.string) - .build() - ).let { - ConfigureNewAccountRequest.Result( - authMapper.grpcAuthorizationToSdkAuthorization(it.authorization) - ) - } - - is GetAuthorizationSessionsRequest -> authorizationService.getAuthorizations( - GrpcGetAuthorizationsRequest.newBuilder() - .setPageToken(request.nextPageToken?.string) - .build(), - headers = authorizedMetadata(request.accessHash), - ).let { response -> - Page( - response.authorizationsList.map(authMapper::grpcAuthorizationToSdkAuthorization), - nextPageToken = response.nextPageToken.takeIf { it.isNotEmpty() } - ?.let(PageToken::createOrThrow), - ) - } - - is TerminateCurrentAuthorizationSessionRequest -> - authorizationService.terminateAuthorization(Empty.getDefaultInstance()) - .let { SdkEmpty } - - is GetFileBytesRequest -> - filesService.getFileBytes( - GrpcGetFileBytesRequest - .newBuilder() - .setFileId(request.fileId.string) - .build(), - ).map { it.chunk.toByteArray() }.let { GetFileBytesRequest.Result(it) } - - is UploadFileRequest -> filesService.uploadFile( - requests = flow { - emit(buildUploadFileGrpcRequest { - metadata = fileMetadata { - fileName = request.fileName.string - fileType = filesMapper.sdkFileTypeToGrpcFileType(request.fileType) - } - }) - - request.bytes.collect { - emit(buildUploadFileGrpcRequest { - chunk = it.toByteString() - }) - } - }, - headers = authorizedMetadata(request.accessHash), - ).let { UploadFileRequest.Result(FileId.createOrThrow(it.fileId)) } - - is EditProfileRequest -> usersService.setUser( - GrpcEditUserRequest.newBuilder() - .apply { - request.name?.let { name = it.string } - request.description?.let { description = it.string } - request.avatar?.let { - avatarId = (it as? Avatar.FileId)?.string - gravatarId = (it as? Avatar.GravatarId)?.string - } - }.build(), - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is GetUsersRequest -> usersService.getUsers( - GrpcGetUsersRequest.newBuilder() - .addAllUserId(request.users.map { it.long }) - .build(), - ).let { GetUsersRequest.Result(it.usersList.map { usersMapper.grpcUserToSdkUser(it) }) } - - is EditEmailRequest -> unsupported() - - is CreateTimerRequest -> timersService.createTimer( - GrpcCreateTimerRequest.newBuilder() - .setName(request.name.string) - .setDescription(request.description.string) - .setSettings(timersMapper.sdkSettingsToGrpcSettings(request.settings)) - .build(), - headers = authorizedMetadata(request.accessHash) - ).let { CreateTimerRequest.Result(TimerId.createOrThrow(it.timerId)) } - - is EditTimerRequest -> timersService.editTimer( - GrpcEditTimerRequest.newBuilder() - .setTimerId(request.timerId.long) - .apply { - request.name?.let { name = it.string } - request.description?.let { description = it.string } - request.settings?.let { - settings = timersMapper.sdkSettingsPatchToGrpcSettingsPatch(it) - } - }.build(), - headers = authorizedMetadata(request.accessHash) - ).let { SdkEmpty } - - is GetTimerRequest -> timersService.getTimer( - buildGetTimerGrpcRequest { - timerId = request.timerId.long - }, - headers = authorizedMetadata(request.accessHash) - ).let { timersMapper.grpcTimerToSdkTimer(it) } - - is GetUserTimersRequest -> timersService.getTimers( - buildGetTimersGrpcRequest { - request.pageToken?.let { nextPageToken = it.string } - }, - headers = authorizedMetadata(request.accessHash) - ).let { response -> - Page( - response.timersList.map { timersMapper.grpcTimerToSdkTimer(it) }, - nextPageToken = response.nextPageToken.takeIf { - response.hasNextPageToken() - }?.let { - PageToken.createOrThrow(it) - }, - ) - } - - is RemoveTimerRequest -> timersService.removeTimer( - buildRemoveTimerGrpcRequest { - timerId = request.timerId.long - }, - headers = authorizedMetadata(request.accessHash) - ).let { SdkEmpty } - - is GetMembersRequest -> timersService.getMembers( - buildGetMembersGrpcRequest { - timerId = request.timerId.long - request.pageToken?.let { nextPageToken = it.string } - }, - headers = authorizedMetadata(request.accessHash) - ).let { response -> - Page( - response.usersList.map { usersMapper.grpcUserToSdkUser(it) }, - nextPageToken = response.nextPageToken?.takeIf { it.isNotEmpty() } - ?.let { PageToken.createOrThrow(it) } - ) - } - - is KickMemberRequest -> timersService.kickMember( - buildKickMemberGrpcRequest { - timerId = request.timerId.long - userId = request.userId.long - }, - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is CreateInviteRequest -> timersService.createInvite( - buildCreateInviteGrpcRequest { - timerId = request.timerId.long - maxJoiners = request.maxJoinersCount.int - }, - headers = authorizedMetadata(request.accessHash), - ).let { CreateInviteRequest.Result(InviteCode.createOrThrow(it.inviteCode)) } - - is GetInvitesRequest -> timersService.getInvites( - buildGetInvitesGrpcRequest { - timerId = request.timerId.long - request.pageToken?.let { nextPageToken = it.string } - }, - headers = authorizedMetadata(request.accessHash), - ).let { response -> - Page( - results = response.invitesList.map { timersMapper.grpcInviteToSdkInvite(it) }, - nextPageToken = response.nextPageToken.takeIf { it.isNotEmpty() } - ?.let { PageToken.createOrThrow(it) } - ) - } - - is RemoveInviteRequest -> timersService.removeInvite( - buildRemoveInviteGrpcRequest { - timerId = request.timerId.long - inviteCode = request.inviteCode.string - }, - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is StartTimerRequest -> timerSessionsService.startTimer( - buildStartTimerGrpcRequest { - timerId = request.timerId.long - }, - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is StopTimerRequest -> timerSessionsService.stopTimer( - buildStopTimerGrpcRequest { - timerId = request.timerId.long - }, - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is JoinTimerSessionRequest -> timerSessionsService.joinSession( - buildJoinTimerSessionGrpcRequest { - timerId = request.timerId.long - }, - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is LeaveTimerSessionRequest -> timerSessionsService.leaveSession( - Empty.getDefaultInstance(), - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is ConfirmTimerRoundRequest -> timerSessionsService.pingSession( - Empty.getDefaultInstance(), - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is PingSessionRequest -> timerSessionsService.pingSession( - Empty.getDefaultInstance(), - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is GetUserCurrentSessionRequest -> timerSessionsService.getUserCurrentSession( - request = Empty.getDefaultInstance(), - headers = authorizedMetadata(request.accessHash), - ).let { timersMapper.grpcTimerToSdkTimer(it) } - - is GetTimerStateRequest -> timerSessionsService.getState( - request = getTimerStateRequest { - - }, - headers = authorizedMetadata(request.accessHash) - ).let { states -> - GetTimerStateRequest.Result( - states.map { state -> timersMapper.grpcStateToSdkState(state) } - ) - } - - else -> unsupported(request::class) - } as T - }.mapException { - val exception = (it as? StatusException) ?: return@mapException it - val status = exception.status - - val message = exception.message ?: NO_MESSAGE - - when (status) { - Status.RESOURCE_EXHAUSTED -> - TooManyRequestsException("Too many requests.", exception) - - Status.INVALID_ARGUMENT, Status.FAILED_PRECONDITION -> - InvalidArgumentException(message, exception) - - Status.UNAUTHENTICATED -> - UnauthorizedException(message, exception) - - Status.INTERNAL -> - InternalServerError(message, exception) - - Status.NOT_FOUND -> - NotFoundException(message, exception) - - Status.ALREADY_EXISTS -> - AlreadyExistsException(message, exception) - - Status.PERMISSION_DENIED -> PermissionDeniedException(message, exception) - Status.UNAVAILABLE -> UnavailableException(message, exception) - - else -> InternalServerError(message, exception) - } - } - - private fun authorizedMetadata(accessHash: AccessHash) = Metadata().apply { - put(ACCESS_TOKEN, accessHash.string) - } - - private fun unsupported(kClass: KClass<*>): Nothing = - throw UnsupportedException("Request of type ${kClass.simpleName} is not supported") - - private inline fun unsupported(): Nothing = unsupported(T::class) -} - -private const val NO_MESSAGE = "No message is provided." \ No newline at end of file diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/DefaultGrpcEngineBuilder.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/DefaultGrpcEngineBuilder.kt deleted file mode 100644 index 5137877..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/DefaultGrpcEngineBuilder.kt +++ /dev/null @@ -1,12 +0,0 @@ -package io.timemates.api.grpc.factory - -import io.grpc.ManagedChannel -import io.grpc.ManagedChannelBuilder - -public class DefaultGrpcEngineBuilder : GrpcEngineBuilder { - override fun createGrpcEngine(endpoint: String): ManagedChannel { - return ManagedChannelBuilder.forTarget(endpoint) - .useTransportSecurity() - .build() - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/GrpcEngineBuilder.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/GrpcEngineBuilder.kt deleted file mode 100644 index c9318f8..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/GrpcEngineBuilder.kt +++ /dev/null @@ -1,7 +0,0 @@ -package io.timemates.api.grpc.factory - -import io.grpc.ManagedChannel - -public interface GrpcEngineBuilder { - public fun createGrpcEngine(endpoint: String): ManagedChannel -} \ No newline at end of file diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/internal/ResultExt.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/internal/ResultExt.kt deleted file mode 100644 index 4564846..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/internal/ResultExt.kt +++ /dev/null @@ -1,16 +0,0 @@ -package io.timemates.api.grpc.internal - -/** - * Applies the given transformation function to the exception contained in the `Result` and returns a new `Result` - * with the transformed exception. If the `Result` does not contain an exception, - * it returns the original `Result` unchanged. - * - * @param transform The transformation function to apply to the exception. - * @return A new `Result` with the transformed exception, or the original `Result` if no exception is present. - */ -@JvmSynthetic -internal inline fun Result.mapException(transform: (Throwable) -> Throwable): Result { - val exception = exceptionOrNull() ?: return this - - return Result.failure(transform(exception)) -} diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/AuthorizationsMapper.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/AuthorizationsMapper.kt deleted file mode 100644 index a07e38a..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/AuthorizationsMapper.kt +++ /dev/null @@ -1,39 +0,0 @@ -package io.timemates.api.grpc.mappers - -import io.timemates.api.authorizations.types.AuthorizationOuterClass.Authorization -import io.timemates.sdk.authorization.sessions.types.value.ClientIpAddress -import io.timemates.sdk.authorization.sessions.types.value.ApplicationName -import io.timemates.sdk.authorization.sessions.types.value.ClientVersion -import io.timemates.sdk.authorization.types.value.HashValue -import io.timemates.sdk.common.constructor.createOrThrow -import kotlinx.datetime.Instant -import io.timemates.sdk.authorization.sessions.types.Authorization as SdkAuthorization - -internal class AuthorizationsMapper { - fun grpcAuthorizationToSdkAuthorization( - authorization: Authorization - ): SdkAuthorization = with(authorization) { - return@with SdkAuthorization( - accessHash = SdkAuthorization.Hash( - value = HashValue.createOrThrow(accessHash.value), - expiresAt = Instant.fromEpochMilliseconds(accessHash.expiresAt), - ), - refreshHash = SdkAuthorization.Hash( - value = HashValue.createOrThrow(refreshHash.value), - expiresAt = Instant.fromEpochMilliseconds(refreshHash.expiresAt), - ), - generationTime = Instant.fromEpochMilliseconds(generationTime), - metadata = grpcMetadataToSdkMetadata(metadata), - ) - } - - private fun grpcMetadataToSdkMetadata( - metadata: Authorization.Metadata, - ): SdkAuthorization.Metadata = with(metadata) { - return@with SdkAuthorization.Metadata( - applicationName = ApplicationName.createOrThrow(clientName), - clientVersion = ClientVersion.createOrThrow(clientVersion), - clientIpAddress = ClientIpAddress.createOrThrow(clientIpAddress), - ) - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/FilesMapper.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/FilesMapper.kt deleted file mode 100644 index e10877a..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/FilesMapper.kt +++ /dev/null @@ -1,13 +0,0 @@ -package io.timemates.api.grpc.mappers - -import io.timemates.api.files.requests.UploadFileRequestOuterClass -import io.timemates.sdk.files.types.FileType -import io.timemates.api.files.requests.UploadFileRequestOuterClass.UploadFileRequest.FileMetadata.FileType as GrpcFileType - -internal class FilesMapper { - fun sdkFileTypeToGrpcFileType(fileType: FileType): GrpcFileType { - return when (fileType) { - FileType.IMAGE -> GrpcFileType.IMAGE - } - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/TimersMapper.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/TimersMapper.kt deleted file mode 100644 index 37b5659..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/TimersMapper.kt +++ /dev/null @@ -1,116 +0,0 @@ -package io.timemates.api.grpc.mappers - -import io.timemates.api.timers.members.invites.types.InviteOuterClass.Invite -import io.timemates.api.timers.sessions.types.TimerStateOuterClass.TimerState -import io.timemates.api.timers.types.TimerKt -import io.timemates.api.timers.types.TimerOuterClass.Timer -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.common.exceptions.UnsupportedException -import io.timemates.sdk.common.types.value.Count -import io.timemates.sdk.timers.members.invites.types.value.InviteCode -import io.timemates.sdk.timers.types.value.TimerDescription -import io.timemates.sdk.timers.types.value.TimerId -import io.timemates.sdk.timers.types.value.TimerName -import io.timemates.sdk.users.profile.types.value.UserId -import kotlinx.datetime.Instant -import kotlin.time.Duration.Companion.seconds -import kotlin.time.DurationUnit -import io.timemates.sdk.timers.members.invites.types.Invite as SdkInvite -import io.timemates.sdk.timers.types.Timer as SdkTimer -import io.timemates.sdk.timers.types.TimerSettings as SdkTimerSettings - -internal class TimersMapper { - fun grpcTimerToSdkTimer(timer: Timer): SdkTimer = with(timer) { - return SdkTimer( - timerId = TimerId.createOrThrow(id), - name = TimerName.createOrThrow(name), - description = TimerDescription.createOrThrow(description), - ownerId = UserId.createOrThrow(ownerId), - membersCount = Count.createOrThrow(membersCount), - state = grpcStateToSdkState(currentState), - settings = grpcSettingsToSdkSettings(settings), - ) - } - - fun grpcStateToSdkState(timerState: TimerState): SdkTimer.State = with(timerState) { - val publishTime = Instant.fromEpochMilliseconds(publishTime) - - return when { - hasPaused() -> SdkTimer.State.Paused(publishTime) - hasRunning() -> SdkTimer.State.Running( - publishTime = publishTime, - endsAt = Instant.fromEpochMilliseconds(running.endsAt), - ) - - hasConfirmationWaiting() -> SdkTimer.State.ConfirmationWaiting( - publishTime = publishTime, - endsAt = Instant.fromEpochMilliseconds(confirmationWaiting.endsAt), - ) - - hasRest() -> SdkTimer.State.Rest( - publishTime = publishTime, - endsAt = Instant.fromEpochMilliseconds(rest.endsAt), - ) - - hasInactive() -> SdkTimer.State.Inactive( - publishTime = publishTime, - ) - - else -> throw UnsupportedException("Unsupported timer state.") - } - } - - fun grpcSettingsToSdkSettings(settings: Timer.Settings): SdkTimerSettings = with(settings) { - return SdkTimerSettings( - workTime = workTime.seconds, - restTime = restTime.seconds, - bigRestTime = bigRestTime.seconds, - bigRestEnabled = bigRestEnabled, - bigRestPer = Count.createOrThrow(bigRestPer), - isEveryoneCanPause = isEveryoneCanPause, - isConfirmationRequired = isConfirmationRequired, - ) - } - fun sdkTimerToGrpcTimer(sdkTimer: SdkTimer): Timer = with(sdkTimer) { - return Timer.newBuilder() - .setId(timerId.long) - .setName(name.string) - .setDescription(description.string) - .setOwnerId(ownerId.long) - .setMembersCount(membersCount.int) - .setSettings(sdkSettingsToGrpcSettings(settings)) - .build() - } - - fun sdkSettingsToGrpcSettings(sdkSettings: SdkTimerSettings): Timer.Settings = with(sdkSettings) { - return Timer.Settings.newBuilder() - .setWorkTime(workTime.toInt(DurationUnit.MINUTES)) - .setRestTime(restTime.toInt(DurationUnit.MINUTES)) - .setBigRestTime(bigRestTime.toInt(DurationUnit.MINUTES)) - .setBigRestEnabled(bigRestEnabled) - .setBigRestPer(bigRestPer.int) - .setIsEveryoneCanPause(isEveryoneCanPause) - .setIsConfirmationRequired(isConfirmationRequired) - .build() - } - - fun sdkSettingsPatchToGrpcSettingsPatch( - sdkSettings: SdkTimerSettings.Patch - ): Timer.Settings.Patch = TimerKt.SettingsKt.patch { - sdkSettings.workTime?.let { workTime = it.toInt(DurationUnit.MINUTES) } - sdkSettings.restTime?.let { restTime = it.toInt(DurationUnit.MINUTES) } - sdkSettings.bigRestTime?.let { bigRestTime = it.toInt(DurationUnit.MINUTES) } - sdkSettings.bigRestPer?.let { bigRestPer = it.int } - sdkSettings.bigRestEnabled?.let { bigRestEnabled = it } - sdkSettings.isConfirmationRequired?.let { isConfirmationRequired = it } - sdkSettings.isEveryoneCanPause?.let { isEveryoneCanPause = it } - } - - fun grpcInviteToSdkInvite(invite: Invite): SdkInvite { - return SdkInvite( - inviteCode = InviteCode.createOrThrow(invite.code), - creationTime = Instant.fromEpochMilliseconds(invite.creationTime), - limit = Count.createOrThrow(invite.limit), - ) - } -} diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/UsersMapper.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/UsersMapper.kt deleted file mode 100644 index 4fc1a08..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/UsersMapper.kt +++ /dev/null @@ -1,23 +0,0 @@ -package io.timemates.api.grpc.mappers - -import io.timemates.api.users.types.UserOuterClass -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.users.profile.types.Avatar -import io.timemates.sdk.users.profile.types.value.EmailAddress -import io.timemates.sdk.users.profile.types.value.UserDescription -import io.timemates.sdk.users.profile.types.value.UserId -import io.timemates.sdk.users.profile.types.value.UserName -import io.timemates.sdk.users.profile.types.User as SdkUser - -internal class UsersMapper { - fun grpcUserToSdkUser(user: UserOuterClass.User): SdkUser = with(user) { - return SdkUser( - id = UserId.createOrThrow(id), - name = UserName.createOrThrow(name), - description = UserDescription.createOrThrow(description), - emailAddress = email?.takeIf { it.isNotEmpty() }?.let { EmailAddress.createOrThrow(it) }, - avatar = gravatarId?.let { Avatar.GravatarId.createOrThrow(it) } ?: - avatarId?.let { Avatar.FileId.createOrThrow(it) } - ) - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto b/grpc-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto deleted file mode 100644 index 059cfea..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto +++ /dev/null @@ -1,49 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto"; -import "io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto"; -import "io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto"; -import "io/timemates/api/authorizations/options/OmitAuthorizationOption.proto"; -import "io/timemates/api/authorizations/requests/CreateProfileRequest.proto"; -import "io/timemates/api/authorizations/types/Authorization.proto"; -import "google/protobuf/empty.proto"; - -option java_package = "io.timemates.api.authorizations"; - -service AuthorizationService { - /** - * Starts authorization by sending corresponding email to email address. - * - * Has next restrictions: - * – 3 requests per email is max. - */ - rpc startAuthorization(StartAuthorizationRequest) returns (StartAuthorizationRequest.Result) { - option (omit_authorization) = true; - } - - /** - * Confirms authorization by sending authorization verification code. - * - * Has next restrictions: - * – 3 attempts per verification code. - */ - rpc confirmAuthorization(ConfirmAuthorizationRequest) returns (ConfirmAuthorizationRequest.Response) { - option (omit_authorization) = true; - } - - rpc createProfile(CreateProfileRequest) returns (CreateProfileRequest.Response) { - option (omit_authorization) = true; - } - - /** - * Gets all active authorizations. - */ - rpc getAuthorizations(GetAuthorizationsRequest) returns (GetAuthorizationsRequest.Response); - - /** - * Terminates authorization by given identifier. - * - * Returns [Status] - */ - rpc terminateAuthorization(google.protobuf.Empty) returns (google.protobuf.Empty); -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/authorizations/options/OmitAuthorizationOption.proto b/grpc-engine/src/main/proto/io/timemates/api/authorizations/options/OmitAuthorizationOption.proto deleted file mode 100644 index e1f69d3..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/authorizations/options/OmitAuthorizationOption.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; - -import "google/protobuf/descriptor.proto"; - -option java_package = "io.timemates.api.authorizations.options"; - -extend google.protobuf.MethodOptions { - /** - * Some methods should not be checked on authorization as they provide - * registration / authentication features or just safe to be called by anyone. - */ - bool omit_authorization = 50001; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto deleted file mode 100644 index e34d950..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; -import "io/timemates/api/authorizations/types/Authorization.proto"; - -option java_package = "io.timemates.api.authorizations.requests"; - -message ConfirmAuthorizationRequest { - string verificationHash = 1; - string confirmationCode = 2; - - message Response { - bool isNewAccount = 1; - // if it's a new account, there's no authorization returned - optional Authorization authorization = 2; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/CreateProfileRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/CreateProfileRequest.proto deleted file mode 100644 index b01a69a..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/CreateProfileRequest.proto +++ /dev/null @@ -1,22 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/authorizations/types/Authorization.proto"; - -option java_package = "io.timemates.api.users.requests"; - -message CreateProfileRequest { - string verificationHash = 1; - /** - * User's name - */ - string name = 2; - - /** - * User's description. - */ - optional string description = 3; - - message Response { - Authorization authorization = 1; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto deleted file mode 100644 index bb46c28..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; -import "io/timemates/api/authorizations/types/Authorization.proto"; - -option java_package = "io.timemates.api.authorizations.requests"; - -message GetAuthorizationsRequest { - // null if it's start of pagination - optional string pageToken = 1; - - message Response { - repeated Authorization authorizations = 1; - string nextPageToken = 2; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto deleted file mode 100644 index 605b36e..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.authorizations.requests"; - -message StartAuthorizationRequest { - string emailAddress = 1; - - message Result { - string verificationHash = 1; - int64 expiresAt = 2; - int32 attempts = 3; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto b/grpc-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto deleted file mode 100644 index db61522..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto +++ /dev/null @@ -1,40 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.authorizations.types"; - -message Authorization { - /** - * Hash that used to identify user. - * - * Has null if it's not new authorization. - */ - optional Hash accessHash = 2; - - /** - * Hash that used to identify user. - * - * Has null if it's not new authorization. - */ - optional Hash refreshHash = 3; - - /** - * Denotes when authorization was generated. - */ - int64 generationTime = 4; - - /** - * Additional information about authorization. - */ - optional Metadata metadata = 5; - - message Hash { - string value = 1; - int64 expiresAt = 2; - } - - message Metadata { - string clientName = 1; - string clientVersion = 2; - string clientIpAddress = 3; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/files/FilesService.proto b/grpc-engine/src/main/proto/io/timemates/api/files/FilesService.proto deleted file mode 100644 index 00f5cad..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/files/FilesService.proto +++ /dev/null @@ -1,23 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/files/requests/GetFileBytesRequest.proto"; -import "io/timemates/api/files/requests/UploadFileRequest.proto"; -import "io/timemates/api/authorizations/options/OmitAuthorizationOption.proto"; -import "google/protobuf/empty.proto"; - -option java_package = "io.timemates.api.files"; - -service FilesService { - /** - * Returns a sequence of bytes of the file's content. - */ - rpc getFileBytes(GetFileBytesRequest) returns (stream GetFileBytesRequest.Response) { - option (omit_authorization) = true; - } - - /* - * Uploads file to server. - * Returns status after upload file stream ends. - */ - rpc uploadFile(stream UploadFileRequest) returns (UploadFileRequest.Response); -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/files/requests/GetFileBytesRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/files/requests/GetFileBytesRequest.proto deleted file mode 100644 index 625ea0d..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/files/requests/GetFileBytesRequest.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.files.requests"; - -message GetFileBytesRequest { - string fileId = 1; - - message Response { - /** - * Chunked file content bytes. - */ - bytes chunk = 1; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/files/requests/UploadFileRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/files/requests/UploadFileRequest.proto deleted file mode 100644 index f32c786..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/files/requests/UploadFileRequest.proto +++ /dev/null @@ -1,31 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.files.requests"; - -message UploadFileRequest { - oneof request { - /** - * Should always be sent as first request. - * Should not be repeated. - */ - FileMetadata metadata = 1; - /** - * Bytes of file included into given chunk. - */ - bytes chunk = 2; - } - - message Response { - string fileId = 1; - } - - message FileMetadata { - FileType fileType = 1; - string fileName = 2; - - enum FileType { - BINARY = 0; // unsupported by default - IMAGE = 1; - } - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/TimersService.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/TimersService.proto deleted file mode 100644 index ff8cfc5..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/TimersService.proto +++ /dev/null @@ -1,68 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/requests/CreateTimerRequest.proto"; -import "io/timemates/api/timers/requests/EditTimerInfoRequest.proto"; -import "io/timemates/api/timers/requests/RemoveTimerRequest.proto"; -import "io/timemates/api/timers/requests/GetTimerRequest.proto"; -import "io/timemates/api/timers/requests/GetTimersRequest.proto"; -import "io/timemates/api/timers/members/requests/KickMemberRequest.proto"; -import "io/timemates/api/timers/members/requests/GetMembersRequest.proto"; -import "io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto"; -import "io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto"; -import "io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto"; -import "io/timemates/api/timers/types/Timer.proto"; -import "google/protobuf/empty.proto"; - -option java_package = "io.timemates.api.timers"; - -service TimersService { - /** - * Creates timer. - */ - rpc createTimer(CreateTimerRequest) returns (CreateTimerRequest.Response); - - /** - * Gets timer by id. - */ - rpc getTimer(GetTimerRequest) returns (Timer); - - /* - * Gets timers by page token. - */ - rpc getTimers(GetTimersRequest) returns (GetTimersRequest.Response); - - /** - * Edits timer information & settings (name, description). - */ - rpc editTimer(EditTimerRequest) returns (google.protobuf.Empty); - - /** - * Kicks member out of timer. - */ - rpc kickMember(KickMemberRequest) returns (google.protobuf.Empty); - - /* - * Gets members of a timer. - */ - rpc getMembers(GetMembersRequest) returns (GetMembersRequest.Response); - - /* - * Creates invite for joining a timer. - */ - rpc createInvite(InviteMemberRequest) returns (InviteMemberRequest.Response); - - /** - * Gets invites of a timer. - */ - rpc getInvites(GetInvitesRequest) returns (GetInvitesRequest.Response); - - /** - * Gets invites of a timer. - */ - rpc removeInvite(RemoveInviteRequest) returns (google.protobuf.Empty); - - /** - * Removes timer. - */ - rpc removeTimer(RemoveTimerRequest) returns (google.protobuf.Empty); -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto deleted file mode 100644 index bbeead2..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; -import "io/timemates/api/users/types/User.proto"; - -option java_package = "io.timemates.api.timers.members.invites.requests"; - -message InviteMemberRequest { - int64 timerId = 1; - int32 maxJoiners = 2; - - message Response { - string inviteCode = 1; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto deleted file mode 100644 index 3947777..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/members/invites/types/Invite.proto"; - -option java_package = "io.timemates.api.timers.members.invites.requests"; - -message GetInvitesRequest { - int64 timerId = 1; - optional string nextPageToken = 2; - - message Response { - repeated Invite invites = 1; - optional string nextPageToken = 3; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto deleted file mode 100644 index 82b3325..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto +++ /dev/null @@ -1,8 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.members.invites.requests"; - -message RemoveInviteRequest { - int64 timerId = 1; - string inviteCode = 2; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/types/Invite.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/types/Invite.proto deleted file mode 100644 index 7717238..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/types/Invite.proto +++ /dev/null @@ -1,9 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.members.invites.types"; - -message Invite { - string code = 1; - int64 creationTime = 2; - int32 limit = 3; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/GetMembersRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/GetMembersRequest.proto deleted file mode 100644 index b9dee63..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/GetMembersRequest.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; -import "io/timemates/api/users/types/User.proto"; - -option java_package = "io.timemates.api.timers.members.requests"; - -message GetMembersRequest { - int64 timerId = 1; - optional string nextPageToken = 2; - - message Response { - repeated User users = 1; - optional string nextPageToken = 2; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/KickMemberRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/KickMemberRequest.proto deleted file mode 100644 index 13918ef..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/KickMemberRequest.proto +++ /dev/null @@ -1,8 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.members.requests"; - -message KickMemberRequest { - int64 timerId = 1; - int64 userId = 2; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/CreateTimerRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/requests/CreateTimerRequest.proto deleted file mode 100644 index 945ec05..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/CreateTimerRequest.proto +++ /dev/null @@ -1,24 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/types/Timer.proto"; - -option java_package = "io.timemates.api.timers.requests"; - -message CreateTimerRequest { - int64 timerId = 1; - /** - * Timer's name. Up to 50 symbols. - */ - string name = 2; - - /** - * Timer's name. Up to 500 symbols. - */ - optional string description = 3; - - optional Timer.Settings settings = 4; - - message Response { - int64 timerId = 1; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/EditTimerInfoRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/requests/EditTimerInfoRequest.proto deleted file mode 100644 index 2d266b7..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/EditTimerInfoRequest.proto +++ /dev/null @@ -1,23 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/types/Timer.proto"; - -option java_package = "io.timemates.api.timers.requests"; - -message EditTimerRequest { - int64 timerId = 1; - /** - * Timer's name. Up to 50 symbols. - */ - optional string name = 2; - - /** - * Timer's name. Up to 500 symbols. - */ - optional string description = 3; - - /** - * Timer's settings - */ - optional Timer.Settings.Patch settings = 4; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimerRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimerRequest.proto deleted file mode 100644 index 70143b6..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimerRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.requests"; - -message GetTimerRequest { - int64 timerId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimersRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimersRequest.proto deleted file mode 100644 index e409eeb..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimersRequest.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; -import "io/timemates/api/timers/types/Timer.proto"; - -option java_package = "io.timemates.api.timers.requests"; - -message GetTimersRequest { - optional string nextPageToken = 1; - - message Response { - repeated Timer timers = 1; - optional string nextPageToken = 2; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/RemoveTimerRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/requests/RemoveTimerRequest.proto deleted file mode 100644 index 10684d5..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/RemoveTimerRequest.proto +++ /dev/null @@ -1,9 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/types/Timer.proto"; - -option java_package = "io.timemates.api.timers.requests"; - -message RemoveTimerRequest { - int64 timerId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/TimerSessionsService.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/TimerSessionsService.proto deleted file mode 100644 index fcfe1ce..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/TimerSessionsService.proto +++ /dev/null @@ -1,71 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto"; -import "io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto"; -import "io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto"; -import "io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto"; -import "io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto"; -import "io/timemates/api/timers/sessions/requests/GetUserCurrentSessionRequest.proto"; -import "io/timemates/api/timers/sessions/types/TimerState.proto"; -import "io/timemates/api/timers/types/Timer.proto"; -import "google/protobuf/empty.proto"; - -option java_package = "io.timemates.api.timers"; - -/** - * The TimerSessionsService provides operations related to timer sessions. - */ -service TimerSessionsService { - - /** - * Starts the timer session. - * This RPC method starts the timer session. - */ - rpc startTimer(StartTimerRequest) returns (google.protobuf.Empty); - - /** - * Stops the timer session. - * This RPC method stops the timer session. - */ - rpc stopTimer(StopTimerRequest) returns (google.protobuf.Empty); - - /** - * Joins the timer session. - * This RPC method allows a user to join the timer session. - */ - rpc joinSession(JoinTimerSessionRequest) returns (google.protobuf.Empty); - - /** - * Leaves the timer session. - * This RPC method allows a user to leave the timer session. - */ - rpc leaveSession(google.protobuf.Empty) returns (google.protobuf.Empty); - - /** - * Confirms the user's attendance of the next round. - * This RPC method confirms the user's attendance of the next round. - * This is needed if the corresponding setting is enabled, usually you should - * just await for [TimerState.ConfirmationWaiting] state. - * - * Server will automatically determine your session. - */ - rpc confirmRound(google.protobuf.Empty) returns (google.protobuf.Empty); - - /** - * Sends a ping request that says that client currently online and active. - * Client should send such request once per 5 minutes. - */ - rpc pingSession(google.protobuf.Empty) returns (google.protobuf.Empty); - - /** - * Retrieves the current state of the timer. - * This RPC method always returns the current state of the timer and then updates of it. - * The state is returned as a stream of TimerState messages. - */ - rpc getState(GetTimerStateRequest) returns (stream TimerState); - - /** - * Gets current timer session - */ - rpc getUserCurrentSession(google.protobuf.Empty) returns (Timer); -} diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto deleted file mode 100644 index 6fad59a..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.sessions.requests"; - -message ConfirmTimerSessionRequest { - int64 timerId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto deleted file mode 100644 index ef4e16c..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.sessions.requests"; - -message GetTimerStateRequest { - int64 timerId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetUserCurrentSessionRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetUserCurrentSessionRequest.proto deleted file mode 100644 index c73a7eb..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetUserCurrentSessionRequest.proto +++ /dev/null @@ -1,11 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/types/Timer.proto"; - -option java_package = "io.timemates.api.timers.sessions.requests"; - -message GetUserCurrentSessionRequest { - message Response { - optional Timer timer = 1; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto deleted file mode 100644 index 209cc2f..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.sessions.requests"; - -message JoinTimerSessionRequest { - int64 timerId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto deleted file mode 100644 index 168e5b6..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.sessions.requests"; - -message StartTimerRequest { - int64 timerId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto deleted file mode 100644 index 15dcba0..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.sessions.requests"; - -message StopTimerRequest { - int64 timerId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/types/TimerState.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/types/TimerState.proto deleted file mode 100644 index ebe39bf..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/types/TimerState.proto +++ /dev/null @@ -1,76 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.sessions.types"; - -/** - * Represents the state of a timer. - */ -message TimerState { - - /** - * The publish time of the timer state. - * This field represents the time when the timer state was started. - */ - int64 publishTime = 1; - - /** - * The phase of the timer state. - * This field is a oneof field, indicating the current phase of the timer. - * Only one of the phase options can be set at a time. - */ - oneof phase { - Rest rest = 2; - Paused paused = 3; - Running running = 4; - ConfirmationWaiting confirmationWaiting = 5; - Inactive inactive = 6; - } - - /** - * Represents the inactive phase of the timer. - * This phase indicates that the timer is inactive. - */ - message Inactive {} - - /** - * Represents the rest phase of the timer. - * This phase indicates that the timer is in a resting state. - */ - message Rest { - /** - * The end time of the rest phase. - * This field represents the time when the rest phase ends. - */ - int64 endsAt = 1; - } - - /** - * Represents the paused phase of the timer. - * This phase indicates that the timer is paused. - */ - message Paused {} - - /** - * Represents the running phase of the timer. - * This phase indicates that the timer is currently running. - */ - message Running { - /** - * The end time of the running phase. - * This field represents the time when the running phase ends. - */ - int64 endsAt = 1; - } - - /** - * Represents the confirmation waiting phase of the timer. - * This phase indicates that the timer is waiting for confirmation. - */ - message ConfirmationWaiting { - /** - * The end time of the confirmation waiting phase. - * This field represents the time when the confirmation waiting phase ends. - */ - int64 endsAt = 1; - } -} diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/types/Timer.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/types/Timer.proto deleted file mode 100644 index cf60797..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/types/Timer.proto +++ /dev/null @@ -1,111 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/sessions/types/TimerState.proto"; - -option java_package = "io.timemates.api.timers.types"; - -/** - * Represents a timer. - */ -message Timer { - - /** - * The ID of the timer. - */ - int64 id = 1; - - /** - * The name of the timer. - * This field represents the name of the timer and can contain up to 50 characters. - */ - string name = 2; - - /** - * The description of the timer. - * This field represents an optional description for the timer and can contain up to 500 characters. - */ - optional string description = 3; - - /** - * The ID of the owner of the timer. - * This field represents the ID of the user who owns the timer. - */ - int64 ownerId = 4; - - /** - * The settings of the timer. - * This field represents the settings for the timer. - */ - Settings settings = 5; - - /** - * The number of members in the timer. - * This field represents the count of members associated with the timer. - */ - int32 membersCount = 6; - - /** - * The current state of the timer. - * This field represents the current state of the timer. - */ - TimerState currentState = 7; - - /** - * Represents the settings of the timer. - */ - message Settings { - /** - * The work time duration in seconds. - * This field represents the duration of the work time in milliseconds. - */ - int32 workTime = 1; - - /** - * The rest time duration in seconds. - * This field represents the duration of the rest time in seconds. - */ - int32 restTime = 2; - - /** - * The big rest time duration in seconds. - * This field represents the duration of the big rest time in seconds. - */ - int32 bigRestTime = 3; - - /** - * Indicates if big rest is enabled. - * This field indicates whether the big rest is enabled or not. - */ - bool bigRestEnabled = 4; - - /** - * The number of work cycles before big rest. - * This field represents the number of work rounds before the big rest is triggered. - */ - int32 bigRestPer = 5; - - /** - * Indicates if everyone can pause the timer. - * This field indicates whether everyone can pause the timer or not. - * - * Also, it denotes whether all users can start the timer. - */ - bool isEveryoneCanPause = 6; - - /** - * Indicates if confirmation is required for timer round start. - * This field indicates whether confirmation is required for timer actions or not. - */ - bool isConfirmationRequired = 7; - - message Patch { - optional int32 workTime = 2; - optional int32 restTime = 3; - optional int32 bigRestTime = 4; - optional bool bigRestEnabled = 5; - optional int32 bigRestPer = 6; - optional bool isEveryoneCanPause = 7; - optional bool isConfirmationRequired = 8; - } - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/users/UsersService.proto b/grpc-engine/src/main/proto/io/timemates/api/users/UsersService.proto deleted file mode 100644 index 4f7fc7d..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/users/UsersService.proto +++ /dev/null @@ -1,32 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/users/requests/GetUsersRequest.proto"; -import "io/timemates/api/users/requests/EditUserRequest.proto"; -import "io/timemates/api/users/requests/EditEmailRequest.proto"; -import "io/timemates/api/users/types/User.proto"; -import "google/protobuf/empty.proto"; - -option java_package = "io.timemates.api.users"; - -service UsersService { - /** - * Gets users by given identifiers. - * - * Returns [User] or null - */ - rpc getUsers(GetUsersRequest) returns (Users); - - /** - * Sets user information (name / description / avatar file id). - * - * Returns [Status] - */ - rpc setUser(EditUserRequest) returns (google.protobuf.Empty); - - /** - * Sets new email for current user. - * - * Returns [Status] - */ - rpc setEmail(EditEmailRequest) returns (google.protobuf.Empty); -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/users/requests/EditEmailRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/users/requests/EditEmailRequest.proto deleted file mode 100644 index d22dc87..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/users/requests/EditEmailRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.users.requests"; - -message EditEmailRequest { - string email = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/users/requests/EditUserRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/users/requests/EditUserRequest.proto deleted file mode 100644 index aa19215..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/users/requests/EditUserRequest.proto +++ /dev/null @@ -1,22 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.users.requests"; - -message EditUserRequest { - /** - * User's avatar id - */ - oneof avatar { - string avatarId = 1; - string gravatarId = 2; - } - /** - * User's name - */ - optional string name = 3; - - /** - * User's description. - */ - optional string description = 4; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/users/requests/GetUsersRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/users/requests/GetUsersRequest.proto deleted file mode 100644 index 2ab5057..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/users/requests/GetUsersRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.users.requests"; - -message GetUsersRequest { - repeated int64 userId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/users/types/User.proto b/grpc-engine/src/main/proto/io/timemates/api/users/types/User.proto deleted file mode 100644 index b5b69c0..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/users/types/User.proto +++ /dev/null @@ -1,39 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.users.types"; - -message User { - /** - * User's identifier - */ - int64 id = 1; - - /** - * String identifier of 128 length. Can be null - * if there is no avatar. - */ - oneof avatar { - string avatarId = 2; - string gravatarId = 3; - } - - /** - * User's name - */ - string name = 4; - - /** - * User's description. - */ - string description = 5; - - /** - * User's email up to 200 symbols. - * Can be null if there is no access. - */ - optional string email = 6; -} - -message Users { - repeated User users = 1; -} \ No newline at end of file diff --git a/rsocket-engine/build.gradle.kts b/rsocket-engine/build.gradle.kts index 1421908..51945db 100644 --- a/rsocket-engine/build.gradle.kts +++ b/rsocket-engine/build.gradle.kts @@ -17,4 +17,22 @@ dependencies { commonMainImplementation(libs.kotlinx.serialization) commonMainImplementation(libs.kotlinx.datetime) commonMainImplementation(libs.rsocket.client) +} + +deployLibrary { + ssh(tag = "rsocket-engine to maven.timemates.io") { + host = System.getenv("TIMEMATES_SSH_HOST") + user = System.getenv("TIMEMATES_SSH_USER") + password = System.getenv("TIMEMATES_SSH_PASSWORD") + deployPath = System.getenv("TIMEMATES_SSH_DEPLOY_PATH") + + group = "io.timemates" + componentName = "kotlin" + artifactId = "rsocket-engine" + name = "rsocket-engine" + + description = "TimeMates rsocket adapter for SDK" + + version = System.getenv("TIMEMATES_SDK_VERSION") + } } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/handler/SafeExceptionResult.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/handler/SafeExceptionResult.kt deleted file mode 100644 index 416c51c..0000000 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/handler/SafeExceptionResult.kt +++ /dev/null @@ -1,225 +0,0 @@ -@file:OptIn(InternalApi::class, ExperimentalTimeMatesApi::class) - -package io.timemates.sdk.common.exceptions.handler - -import io.timemates.sdk.common.annotations.ApiStatus -import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi -import io.timemates.sdk.common.annotations.InternalApi -import io.timemates.sdk.common.exceptions.NotFoundException -import io.timemates.sdk.common.exceptions.TimeMatesException -import io.timemates.sdk.common.exceptions.TooManyRequestsException -import io.timemates.sdk.common.exceptions.UnauthorizedException -import io.timemates.sdk.common.exceptions.UnavailableException -import io.timemates.sdk.common.types.TimeMatesEntity - -/** - * Represents a type-safe wrapper class for handling exceptions in the context of an operation's result. - * - * The [SafeExceptionResult] class provides a convenient way to handle exceptions and control the flow of execution based on the encountered exception types. - * It is designed to ensure type safety by using the generic type parameters [T] for the result value and [E] for the exception type. - * - * @param T The type of the result value. - * @param E The type of the exception. - * @property result The original result of the operation. - */ -@ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) -@JvmInline -public value class SafeExceptionResult @InternalApi constructor( - @property:InternalApi public val result: Result -) - -/** - * Converts a [Result] into a [SafeExceptionResult] for safe exception handling. - * - * The [safeResult] function is used to wrap the original [Result] in a [SafeExceptionResult], - * which allows for more controlled handling of exceptions within the operation's result. - * - * @receiver The original result of the operation. - * @return The [SafeExceptionResult] containing the original result. - */ -@ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) -public fun Result.safeResult(): SafeExceptionResult { - return SafeExceptionResult(this) -} - -/** - * Executes a specified block if the encountered exception is of type [UnauthorizedException]. - * - * The [whenUnauthorized] function enables controlled handling of the [UnauthorizedException] by executing the provided block - * if the encountered exception matches the type [UnauthorizedException]. - * - * @param block The block of code to be executed if the encountered exception is [UnauthorizedException]. - * @return The [SafeExceptionResult] after executing the block. - */ -public inline fun SafeExceptionResult.whenUnauthorized( - block: (UnauthorizedException) -> Unit -): SafeExceptionResult { - val exception = result.exceptionOrNull() - if (exception is UnauthorizedException) - block(exception) - - return SafeExceptionResult(result) -} - -/** - * Executes a specified block if the encountered exception is of type [UnavailableException]. - * - * The [whenUnavailable] function allows for controlled handling of the [UnavailableException] by executing the provided block - * if the encountered exception matches the type [UnavailableException]. - * - * @param block The block of code to be executed if the encountered exception is [UnavailableException]. - * @return The [SafeExceptionResult] after executing the block. - */ -public inline fun SafeExceptionResult.whenUnavailable( - block: (UnavailableException) -> Unit -): SafeExceptionResult { - val exception = result.exceptionOrNull() - if (exception is UnavailableException) - block(exception) - - return SafeExceptionResult(result) -} - -/** - * Executes a specified block if the encountered exception is of type [TooManyRequestsException]. - * - * The [whenTooManyRequests] function allows for controlled handling of the [TooManyRequestsException] by executing the provided block - * if the encountered exception matches the type [TooManyRequestsException]. - * - * @param block The block of code to be executed if the encountered exception is [TooManyRequestsException]. - * @return The [SafeExceptionResult] after executing the block. - */ -public inline fun SafeExceptionResult.whenTooManyRequests( - block: (TooManyRequestsException) -> Unit -): SafeExceptionResult { - val exception = result.exceptionOrNull() - if (exception is TooManyRequestsException) - block(exception) - - return SafeExceptionResult(result) -} - -/** - * Executes a specified block if the encountered exception is of type [NotFoundException]. - * - * The [whenNotFound] function allows for controlled handling of the [NotFoundException] by executing the provided block - * if the encountered exception matches the type [NotFoundException]. - * - * @param block The block of code to be executed if the encountered exception is [NotFoundException]. - * @return The [SafeExceptionResult] after executing the block. - */ -public inline fun SafeExceptionResult.whenNotFound( - block: (NotFoundException) -> Unit -): SafeExceptionResult { - val exception = result.exceptionOrNull() - if (exception is NotFoundException) - block(exception) - - return SafeExceptionResult(result) -} - -/** - * Ignores the [NotFoundException] exception and continues execution. - * - * The [ignoreNotFound] function allows for ignoring the [NotFoundException] exception - * and continuing the flow of execution without interruption. - * - * @receiver The [SafeExceptionResult]. - * @return The [SafeExceptionResult] after ignoring the [NotFoundException]. - */ -public fun SafeExceptionResult.ignoreNotFound(): SafeExceptionResult { - return SafeExceptionResult(result) -} - -/** - * Executes a specified block if any exception is encountered. - * - * **Any inheritor of [TimeMatesException] are ignored here.** - * - * The [whenOtherError] function allows for handling any encountered exception by executing the provided block. - * It is useful for executing common error-handling code regardless of the specific exception type. - * - * @param block The block of code to be executed if any exception is encountered. - * @return The [SafeExceptionResult] after executing the block. - */ -@ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) -public inline fun SafeExceptionResult.whenOtherError( - block: (E) -> Unit -): SafeExceptionResult { - result.exceptionOrNull()?.takeIf { it !is TimeMatesException }?.let { - @Suppress("UNCHECKED_CAST") - block(it as E) - } - - return SafeExceptionResult(result) -} - -/** - * Handles **ANY** throwable, even inheritors of [TimeMatesException]. You should use it if - * you want to handle some failure logic more than one time or when you want to ignore type-safe - * way of handling failures with [whenUnauthorized], [whenUnavailable], etc. - * - * But, if it's possible, it's better to use just [Result] API instead of [SafeExceptionResult]. - */ -@ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) -public inline fun SafeExceptionResult.whenAnyError( - block: (Throwable) -> Unit -): SafeExceptionResult { - result.exceptionOrNull()?.let(block) - - return SafeExceptionResult(result) -} - -/** - * Executes a specified block if the operation is successful. - * - * The [whenSuccess] function allows for executing a block of code if the operation is successful, - * providing access to the result value for further processing. - * - * @param block The block of code to be executed if the operation is successful. - */ -public inline fun SafeExceptionResult.whenSuccess( - block: (T) -> Unit -) { - if(result.isSuccess) - block(result.getOrThrow()) -} - -/** - * Ignores the [UnauthorizedException] exception and continues execution. - * - * The [ignoreUnauthorized] function allows for ignoring the [UnauthorizedException] exception - * and continuing the flow of execution without interruption. - * - * @receiver The [SafeExceptionResult]. - * @return The [SafeExceptionResult] after ignoring the [UnauthorizedException]. - */ -public fun SafeExceptionResult.ignoreUnauthorized(): SafeExceptionResult { - return SafeExceptionResult(result) -} - -/** - * Ignores the [TooManyRequestsException] exception and continues execution. - * - * The [ignoreTooManyRequests] function allows for ignoring the [TooManyRequestsException] exception - * and continuing the flow of execution without interruption. - * - * @receiver The [SafeExceptionResult]. - * @return The [SafeExceptionResult] after ignoring the [TooManyRequestsException]. - */ -public fun SafeExceptionResult.ignoreTooManyRequests(): SafeExceptionResult { - return SafeExceptionResult(result) -} - -/** - * Ignores the [UnavailableException] exception and continues execution. - * - * The [ignoreUnavailable] function allows for ignoring the [UnavailableException] exception - * and continuing the flow of execution without interruption. - * - * @receiver The [SafeExceptionResult]. - * @return The [SafeExceptionResult] after ignoring the [UnavailableException]. - */ -public fun SafeExceptionResult.ignoreUnavailable(): SafeExceptionResult { - return SafeExceptionResult(result) -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 52e3530..6c84a0e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,6 +23,4 @@ rootProject.name = "timemates-sdk" includeBuild("build-logic/publish-library-plugin") include(":sdk") -include(":grpc-engine") include(":rsocket-engine") -include(":grpc-engine:android") From 4b063bf69d28209223bc54eafcfe7004389c67b9 Mon Sep 17 00:00:00 2001 From: y9vad9 Date: Wed, 27 Sep 2023 20:32:43 +0200 Subject: [PATCH 04/13] feat: factory function for RSocket transport engine --- .../rsocket/RSocketTimeMatesRequestsEngine.kt | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt index b099d39..5d80ed0 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt @@ -1,11 +1,17 @@ package io.timemates.api.rsocket import io.ktor.client.HttpClient +import io.ktor.client.HttpClientConfig +import io.ktor.client.plugins.websocket.WebSockets import io.rsocket.kotlin.ExperimentalMetadataApi import io.rsocket.kotlin.RSocket +import io.rsocket.kotlin.core.WellKnownMimeType +import io.rsocket.kotlin.keepalive.KeepAlive +import io.rsocket.kotlin.ktor.client.RSocketSupport import io.rsocket.kotlin.ktor.client.rSocket import io.rsocket.kotlin.metadata.RoutingMetadata import io.rsocket.kotlin.metadata.compositeMetadata +import io.rsocket.kotlin.payload.PayloadMimeType import io.rsocket.kotlin.payload.buildPayload import io.timemates.api.rsocket.common.markers.RSocketRequest import io.timemates.api.rsocket.common.metadata.AuthorizationMetadata @@ -25,9 +31,57 @@ import kotlinx.coroutines.async import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.serializer +import kotlin.time.Duration.Companion.minutes +import kotlin.time.Duration.Companion.seconds import io.timemates.api.rsocket.timers.requests.RSocketEditTimerRequest as RSocketEditTimerRequest import io.timemates.api.rsocket.timers.requests.RSocketGetTimerRequest as RSocketGetTimerRequest +/** + * Creates an RSocket-based TimeMates request engine. + * + * This function configures and creates an RSocket-based TimeMates request engine + * that communicates with the TimeMates API over WebSockets. You can customize the + * WebSocket endpoint, coroutine scope, and HTTP client configuration using the + * provided parameters. + * + * **Note**: You should implement ktor client engine to use it. + * + * @param endpoint The WebSocket endpoint URL for the TimeMates API. + * @param coroutineScope The coroutine scope used for RSocket lifecycle. + * @param config Configuration lambda for customizing the underlying HTTP client. + * @return An instance of the RSocketTimeMatesRequestsEngine. + */ +public fun RSocketTimeMatesRequestsEngine( + endpoint: String = "wss://api.timemates.io/v0/rsocket", + coroutineScope: CoroutineScope, + config: HttpClientConfig<*>.() -> Unit = {}, +): RSocketTimeMatesRequestsEngine { + val client = HttpClient { + install(RSocketSupport) { + connector { + maxFragmentSize = 1024 + + connectionConfig { + keepAlive = KeepAlive( + interval = 30.seconds, + maxLifetime = 2.minutes + ) + + payloadMimeType = PayloadMimeType( + data = WellKnownMimeType.ApplicationJson, + metadata = WellKnownMimeType.MessageRSocketCompositeMetadata, + ) + } + } + } + config() + } + + return RSocketTimeMatesRequestsEngine( + client, endpoint, coroutineScope, + ) +} + /** * Represents an engine for making requests using RSocket. * @@ -35,7 +89,7 @@ import io.timemates.api.rsocket.timers.requests.RSocketGetTimerRequest as RSocke * @param endpoint The RSocket endpoint URL. Defaults to "wss://api.timemates.io/v0/rsocket". * @param coroutineScope A [CoroutineScope] tied to the RSocket lifecycle. */ -public class RSocketTimeMatesRequestsEngine private constructor( +public class RSocketTimeMatesRequestsEngine internal constructor( private val client: HttpClient, endpoint: String = "wss://api.timemates.io/v0/rsocket", coroutineScope: CoroutineScope, From ec9df374599274e86ff3c408e290ccb23639ebd5 Mon Sep 17 00:00:00 2001 From: y9vad9 Date: Wed, 27 Sep 2023 20:51:23 +0200 Subject: [PATCH 05/13] fix: build --- rsocket-engine/build.gradle.kts | 4 ++++ .../sessions/types/SerializableTimerState.kt | 20 +++++++++++++++++++ .../rsocket/timers/types/SerializableTimer.kt | 2 ++ sdk/build.gradle.kts | 4 ++++ 4 files changed, 30 insertions(+) diff --git a/rsocket-engine/build.gradle.kts b/rsocket-engine/build.gradle.kts index 51945db..8b144bf 100644 --- a/rsocket-engine/build.gradle.kts +++ b/rsocket-engine/build.gradle.kts @@ -35,4 +35,8 @@ deployLibrary { version = System.getenv("TIMEMATES_SDK_VERSION") } +} + +tasks.withType { + useJUnitPlatform() } \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/types/SerializableTimerState.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/types/SerializableTimerState.kt index 3856e86..eb54b71 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/types/SerializableTimerState.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/types/SerializableTimerState.kt @@ -59,4 +59,24 @@ internal fun SerializableTimerState.sdk(): Timer.State { publishTime = publishTime, ) } +} + +internal fun Timer.State.serializable(): SerializableTimerState { + return when (this) { + is Timer.State.ConfirmationWaiting -> SerializableTimerState.Confirmation( + endsAt.toEpochMilliseconds(), publishTime.toEpochMilliseconds(), + ) + is Timer.State.Inactive -> SerializableTimerState.Inactive( + publishTime.toEpochMilliseconds(), + ) + is Timer.State.Paused -> SerializableTimerState.Pause( + publishTime.toEpochMilliseconds(), + ) + is Timer.State.Rest -> SerializableTimerState.Rest( + endsAt.toEpochMilliseconds(), publishTime.toEpochMilliseconds(), + ) + is Timer.State.Running -> SerializableTimerState.Running( + endsAt.toEpochMilliseconds(), publishTime.toEpochMilliseconds(), + ) + } } \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimer.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimer.kt index 02c45a6..d108c6b 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimer.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimer.kt @@ -1,6 +1,7 @@ package io.timemates.api.rsocket.timers.types import io.timemates.api.rsocket.timers.sessions.types.SerializableTimerState +import io.timemates.api.rsocket.timers.sessions.types.sdk import io.timemates.sdk.common.constructor.createOrThrow import io.timemates.sdk.common.types.value.Count import io.timemates.sdk.timers.types.Timer @@ -29,5 +30,6 @@ internal fun SerializableTimer.sdk(): Timer { ownerId = UserId.createOrThrow(ownerId), membersCount = Count.createOrThrow(membersCount), settings = settings.sdk(), + state = state.sdk() ) } \ No newline at end of file diff --git a/sdk/build.gradle.kts b/sdk/build.gradle.kts index bdad811..8c72269 100644 --- a/sdk/build.gradle.kts +++ b/sdk/build.gradle.kts @@ -33,4 +33,8 @@ deployLibrary { version = System.getenv("TIMEMATES_SDK_VERSION") } +} + +tasks.withType { + useJUnitPlatform() } \ No newline at end of file From 07632af010e20fce63bb9d31404d322b8b0708bb Mon Sep 17 00:00:00 2001 From: y9vad9 Date: Wed, 27 Sep 2023 20:56:00 +0200 Subject: [PATCH 06/13] docs: removal of grpc-engine notes, adding `RSocketTimeMatesRequestsEngine` --- README.md | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d6fafaf..0b05aed 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,9 @@ platform and integrate its features into your own applications. To demonstrate the usage of the SDK, consider the following example: ```kotlin -val engineBuilder = DefaultGrpcEngineBuilder() -val engine = GrpcTimeMatesRequestsEngine(engineBuilder) +val engine = RSocketTimeMatesRequestsEngine( + coroutineScope = Dispatchers.IO, +) val emailAuth = AccountLoginApi(engineBuilder).email val email = EmailAddress.create("developer@y9vad9.com").getOrElse { return } @@ -24,12 +25,6 @@ val authorizationResult = emailAuth.authorize(email) // until we complete our registration .map { (isNewAccount, authorization) -> ... } ``` -> **Note**
-> For android use [AndroidGrpcEngineBuilder](/grpc-engine/android/src/main/kotlin/io/timemates/android/grpc/AndroidGrpcEngineBuilder.kt) ->```kotlin -> val engineBuilder = AndroidGrpcEngineBuilder(applicationContext) ->``` - In the provided code snippet, the SDK utilizes the Kotlin Result API extensively. It's important to note that the SDK's value objects, such as `EmailAddress` @@ -77,9 +72,7 @@ repositories { dependencies { implementation("io.timemates:sdk:$version") - implementation("io.timemates:grpc-engine:$version") - // for android - implementation("io.timemates:grpc-engine-android:$version") + implementation("io.timemates:rsocket-engine:$version") } ``` From 8a80b9ee543c23bdbd89bb6857b2d4cba9b7f6e3 Mon Sep 17 00:00:00 2001 From: y9vad9 Date: Wed, 27 Sep 2023 20:56:57 +0200 Subject: [PATCH 07/13] fix: run tests --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a6ea7ce..e8ebb4b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -17,4 +17,4 @@ jobs: distribution: 'corretto' java-version: '17' cache: 'gradle' - - run: ./gradlew test --no-daemon + - run: ./gradlew build --no-daemon From 3df324f0ac323685ea5893caf84494a80d0dbb91 Mon Sep 17 00:00:00 2001 From: y9vad9 Date: Wed, 27 Sep 2023 20:59:12 +0200 Subject: [PATCH 08/13] fix: names --- .../authorizations/commands/ConfigureNewAccountCommand.kt | 2 +- .../authorizations/commands/ConfirmAuthorizationCommand.kt | 2 +- .../commands/GetAuthorizationSessionsCommand.kt | 4 ++-- .../authorizations/commands/RenewAuthorizationCommand.kt | 2 +- .../authorizations/commands/StartAuthorizationCommand.kt | 2 +- .../commands/TerminateCurrentAuthorizationCommand.kt | 4 ++-- ...reAccountRequest.kt => RSocketConfigureAccountRequest.kt} | 4 ++-- ...ationRequest.kt => RSocketConfirmAuthorizationRequest.kt} | 4 ++-- ...izationsRequest.kt => RSocketGetAuthorizationsRequest.kt} | 4 ++-- ...izationRequest.kt => RSocketRenewAuthorizationRequest.kt} | 4 ++-- ...izationRequest.kt => RSocketStartAuthorizationRequest.kt} | 4 ++-- ...ionRequest.kt => RSocketTerminateAuthorizationRequest.kt} | 4 ++-- .../timemates/api/rsocket/users/commands/EditEmailCommand.kt | 5 +---- .../api/rsocket/users/commands/EditProfileCommand.kt | 4 ++-- .../timemates/api/rsocket/users/commands/GetUsersCommand.kt | 2 +- .../{EditEmailRequest.kt => RSocketEditEmailRequest.kt} | 2 +- ...serProfileRequest.kt => RSocketEditUserProfileRequest.kt} | 2 +- .../{GetUsersRequest.kt => RSocketGetUsersRequest.kt} | 4 ++-- 18 files changed, 28 insertions(+), 31 deletions(-) rename rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/{ConfigureAccountRequest.kt => RSocketConfigureAccountRequest.kt} (79%) rename rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/{ConfirmAuthorizationRequest.kt => RSocketConfirmAuthorizationRequest.kt} (78%) rename rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/{GetAuthorizationsRequest.kt => RSocketGetAuthorizationsRequest.kt} (77%) rename rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/{RenewAuthorizationRequest.kt => RSocketRenewAuthorizationRequest.kt} (70%) rename rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/{StartAuthorizationRequest.kt => RSocketStartAuthorizationRequest.kt} (80%) rename rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/{TerminateAuthorizationRequest.kt => RSocketTerminateAuthorizationRequest.kt} (70%) rename rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/{EditEmailRequest.kt => RSocketEditEmailRequest.kt} (82%) rename rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/{EditUserProfileRequest.kt => RSocketEditUserProfileRequest.kt} (87%) rename rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/{GetUsersRequest.kt => RSocketGetUsersRequest.kt} (77%) diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt index 5345bcd..0af6d1f 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt @@ -5,7 +5,7 @@ import io.timemates.api.rsocket.authorizations.types.sdk import io.timemates.api.rsocket.common.commands.RSocketCommand import io.timemates.api.rsocket.common.ext.requestResponse import io.timemates.sdk.authorization.email.requests.ConfigureNewAccountRequest -import io.timemates.api.rsocket.authorizations.requests.ConfigureAccountRequest as RSocketConfigureAccountRequest +import io.timemates.api.rsocket.authorizations.requests.RSocketConfigureAccountRequest as RSocketConfigureAccountRequest internal object ConfigureNewAccountCommand : RSocketCommand { override suspend fun execute(rSocket: RSocket, input: ConfigureNewAccountRequest): ConfigureNewAccountRequest.Result { diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt index bdfebe8..a6c0a1d 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt @@ -5,7 +5,7 @@ import io.timemates.api.rsocket.authorizations.types.sdk import io.timemates.api.rsocket.common.commands.RSocketCommand import io.timemates.api.rsocket.common.ext.requestResponse import io.timemates.sdk.authorization.email.requests.ConfirmAuthorizationRequest -import io.timemates.api.rsocket.authorizations.requests.ConfirmAuthorizationRequest as RSocketConfirmAuthorizationRequest +import io.timemates.api.rsocket.authorizations.requests.RSocketConfirmAuthorizationRequest as RSocketConfirmAuthorizationRequest internal object ConfirmAuthorizationCommand : RSocketCommand { override suspend fun execute(rSocket: RSocket, input: ConfirmAuthorizationRequest): ConfirmAuthorizationRequest.Result { diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt index 33b0b84..433260b 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt @@ -1,7 +1,7 @@ package io.timemates.api.rsocket.authorizations.commands import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.authorizations.requests.GetAuthorizationsRequest +import io.timemates.api.rsocket.authorizations.requests.RSocketGetAuthorizationsRequest import io.timemates.api.rsocket.authorizations.types.SerializableAuthorization import io.timemates.api.rsocket.authorizations.types.sdk import io.timemates.api.rsocket.common.commands.RSocketCommand @@ -16,7 +16,7 @@ internal object GetAuthorizationSessionsCommand : RSocketCommand { return rSocket.requestResponse( route = "authorizations.list", - data = GetAuthorizationsRequest(input.nextPageToken?.string), + data = RSocketGetAuthorizationsRequest(input.nextPageToken?.string), accessHash = input.accessHash.string, ).let { result -> Page( diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt index ba7bbfd..63a83fa 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt @@ -7,7 +7,7 @@ import io.timemates.sdk.authorization.sessions.requests.RenewAuthorizationReques import io.timemates.sdk.authorization.types.value.AccessHash import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.api.rsocket.authorizations.requests.RenewAuthorizationRequest as RSocketRenewAuthorizationRequest +import io.timemates.api.rsocket.authorizations.requests.RSocketRenewAuthorizationRequest as RSocketRenewAuthorizationRequest @OptIn(ExperimentalTimeMatesApi::class) internal object RenewAuthorizationCommand : RSocketCommand { diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt index 8394eb8..7832cac 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt @@ -9,7 +9,7 @@ import io.timemates.sdk.authorization.email.types.value.VerificationHash import io.timemates.sdk.common.constructor.createOrThrow import io.timemates.sdk.common.types.value.Count import kotlinx.datetime.Instant -import io.timemates.api.rsocket.authorizations.requests.StartAuthorizationRequest as RSocketStartAuthorizationRequest +import io.timemates.api.rsocket.authorizations.requests.RSocketStartAuthorizationRequest as RSocketStartAuthorizationRequest internal object StartAuthorizationCommand : RSocketCommand { override suspend fun execute( diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt index c99e1f9..2bb1e29 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt @@ -1,7 +1,7 @@ package io.timemates.api.rsocket.authorizations.commands import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.authorizations.requests.TerminateAuthorizationRequest +import io.timemates.api.rsocket.authorizations.requests.RSocketTerminateAuthorizationRequest import io.timemates.api.rsocket.common.commands.RSocketCommand import io.timemates.api.rsocket.common.ext.requestResponse import io.timemates.sdk.authorization.sessions.requests.TerminateCurrentAuthorizationSessionRequest @@ -11,7 +11,7 @@ internal object TerminateCurrentAuthorizationCommand : RSocketCommand Empty } } diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfigureAccountRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketConfigureAccountRequest.kt similarity index 79% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfigureAccountRequest.kt rename to rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketConfigureAccountRequest.kt index 8f0a72a..88319b1 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfigureAccountRequest.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketConfigureAccountRequest.kt @@ -5,11 +5,11 @@ import io.timemates.api.rsocket.common.markers.RSocketRequest import kotlinx.serialization.Serializable @Serializable -internal data class ConfigureAccountRequest( +internal data class RSocketConfigureAccountRequest( val verificationHash: String, val name: String, val description: String?, -) : RSocketRequest { +) : RSocketRequest { @Serializable data class Result( val authorization: SerializableAuthorization, diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfirmAuthorizationRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketConfirmAuthorizationRequest.kt similarity index 78% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfirmAuthorizationRequest.kt rename to rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketConfirmAuthorizationRequest.kt index a8fb57d..0568cd6 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfirmAuthorizationRequest.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketConfirmAuthorizationRequest.kt @@ -5,10 +5,10 @@ import io.timemates.api.rsocket.common.markers.RSocketRequest import kotlinx.serialization.Serializable @Serializable -internal data class ConfirmAuthorizationRequest( +internal data class RSocketConfirmAuthorizationRequest( val verificationHash: String, val confirmationCode: String, -) : RSocketRequest { +) : RSocketRequest { data class Response( val isNewAccount: Boolean, val authorization: SerializableAuthorization?, diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/GetAuthorizationsRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketGetAuthorizationsRequest.kt similarity index 77% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/GetAuthorizationsRequest.kt rename to rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketGetAuthorizationsRequest.kt index f191ad6..4ec8464 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/GetAuthorizationsRequest.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketGetAuthorizationsRequest.kt @@ -5,9 +5,9 @@ import io.timemates.api.rsocket.common.markers.RSocketRequest import kotlinx.serialization.Serializable @Serializable -internal data class GetAuthorizationsRequest( +internal data class RSocketGetAuthorizationsRequest( val pageToken: String? = null, -) : RSocketRequest { +) : RSocketRequest { @Serializable data class Result(val list: List, val nextPageToken: String?) diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RenewAuthorizationRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketRenewAuthorizationRequest.kt similarity index 70% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RenewAuthorizationRequest.kt rename to rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketRenewAuthorizationRequest.kt index 1656599..1d52739 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RenewAuthorizationRequest.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketRenewAuthorizationRequest.kt @@ -4,9 +4,9 @@ import io.timemates.api.rsocket.common.markers.RSocketRequest import kotlinx.serialization.Serializable @Serializable -internal data class RenewAuthorizationRequest( +internal data class RSocketRenewAuthorizationRequest( val refreshHash: String, -) : RSocketRequest { +) : RSocketRequest { @Serializable data class Result(val accessHash: String) } \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/StartAuthorizationRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketStartAuthorizationRequest.kt similarity index 80% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/StartAuthorizationRequest.kt rename to rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketStartAuthorizationRequest.kt index 8904e26..33d6e2e 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/StartAuthorizationRequest.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketStartAuthorizationRequest.kt @@ -5,10 +5,10 @@ import io.timemates.api.rsocket.common.markers.RSocketRequest import kotlinx.serialization.Serializable @Serializable -internal data class StartAuthorizationRequest( +internal data class RSocketStartAuthorizationRequest( val email: String, val clientMetadata: SerializableAuthMetadata, -) : RSocketRequest { +) : RSocketRequest { @Serializable data class Result( val verificationHash: String, diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/TerminateAuthorizationRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketTerminateAuthorizationRequest.kt similarity index 70% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/TerminateAuthorizationRequest.kt rename to rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketTerminateAuthorizationRequest.kt index 5bcdba0..f46d8a0 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/TerminateAuthorizationRequest.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketTerminateAuthorizationRequest.kt @@ -5,11 +5,11 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -internal sealed class TerminateAuthorizationRequest : RSocketRequest { +internal sealed class RSocketTerminateAuthorizationRequest : RSocketRequest { /** * This type of termination request terminates authorization with which * user has sent termination request. */ @SerialName("current") - data object Current : TerminateAuthorizationRequest() + data object Current : RSocketTerminateAuthorizationRequest() } \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt index 9de520a..b5b8080 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt @@ -3,11 +3,8 @@ package io.timemates.api.rsocket.users.commands import io.rsocket.kotlin.RSocket import io.timemates.api.rsocket.common.commands.RSocketCommand import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.users.requests.EditUserProfileRequest -import io.timemates.api.rsocket.users.types.serializable import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi import io.timemates.sdk.common.types.Empty -import io.timemates.sdk.users.profile.requests.EditProfileRequest import io.timemates.sdk.users.settings.requests.EditEmailRequest @OptIn(ExperimentalTimeMatesApi::class) @@ -15,7 +12,7 @@ internal object EditEmailCommand : RSocketCommand { override suspend fun execute(rSocket: RSocket, input: EditEmailRequest): Empty { return rSocket.requestResponse( route = "users.email.edit", - data = io.timemates.api.rsocket.users.requests.EditEmailRequest( + data = io.timemates.api.rsocket.users.requests.RSocketEditEmailRequest( email = input.newEmail.string, ), accessHash = input.accessHash.string, diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt index 556a5b5..14b44dc 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt @@ -3,7 +3,7 @@ package io.timemates.api.rsocket.users.commands import io.rsocket.kotlin.RSocket import io.timemates.api.rsocket.common.commands.RSocketCommand import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.users.requests.EditUserProfileRequest +import io.timemates.api.rsocket.users.requests.RSocketEditUserProfileRequest import io.timemates.api.rsocket.users.types.serializable import io.timemates.sdk.common.types.Empty import io.timemates.sdk.users.profile.requests.EditProfileRequest @@ -12,7 +12,7 @@ internal object EditProfileCommand : RSocketCommand { override suspend fun execute(rSocket: RSocket, input: EditProfileRequest): Empty { return rSocket.requestResponse( route = "users.profile.edit", - data = EditUserProfileRequest( + data = RSocketEditUserProfileRequest( name = input.name?.string, description = input.description?.string, avatar = input.avatar?.serializable(), diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt index 02c6e93..8bb7a8c 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt @@ -6,7 +6,7 @@ import io.timemates.api.rsocket.common.ext.requestResponse import io.timemates.api.rsocket.users.types.SerializableUser import io.timemates.api.rsocket.users.types.sdk import io.timemates.sdk.users.profile.requests.GetUsersRequest -import io.timemates.api.rsocket.users.requests.GetUsersRequest as RSocketGetUsersRequest +import io.timemates.api.rsocket.users.requests.RSocketGetUsersRequest as RSocketGetUsersRequest internal object GetUsersCommand : RSocketCommand { override suspend fun execute(rSocket: RSocket, input: GetUsersRequest): GetUsersRequest.Result { diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/EditEmailRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketEditEmailRequest.kt similarity index 82% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/EditEmailRequest.kt rename to rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketEditEmailRequest.kt index 7a10739..6407e4c 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/EditEmailRequest.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketEditEmailRequest.kt @@ -4,6 +4,6 @@ import io.timemates.api.rsocket.common.markers.RSocketRequest import kotlinx.serialization.Serializable @Serializable -internal data class EditEmailRequest( +internal data class RSocketEditEmailRequest( val email: String, ) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/EditUserProfileRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketEditUserProfileRequest.kt similarity index 87% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/EditUserProfileRequest.kt rename to rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketEditUserProfileRequest.kt index 405e4a1..1b754b3 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/EditUserProfileRequest.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketEditUserProfileRequest.kt @@ -5,7 +5,7 @@ import io.timemates.api.rsocket.users.types.SerializableAvatar import kotlinx.serialization.Serializable @Serializable -internal data class EditUserProfileRequest( +internal data class RSocketEditUserProfileRequest( val avatar: SerializableAvatar?, val name: String?, val description: String?, diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/GetUsersRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketGetUsersRequest.kt similarity index 77% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/GetUsersRequest.kt rename to rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketGetUsersRequest.kt index ae4a011..d502374 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/GetUsersRequest.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketGetUsersRequest.kt @@ -5,9 +5,9 @@ import io.timemates.api.rsocket.users.types.SerializableUser import kotlinx.serialization.Serializable @Serializable -internal data class GetUsersRequest( +internal data class RSocketGetUsersRequest( val ids: List, -) : RSocketRequest { +) : RSocketRequest { @Serializable data class Result(val list: List) } \ No newline at end of file From b5faeacdf3f9d90c01adc30e9b4a7d5eee39f7d8 Mon Sep 17 00:00:00 2001 From: Vadym Yaroshchuk Date: Wed, 27 Sep 2023 22:09:52 +0200 Subject: [PATCH 09/13] fix: workflow --- .github/workflows/publish-release-version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-release-version.yml b/.github/workflows/publish-release-version.yml index 993c931..7d6c94b 100644 --- a/.github/workflows/publish-release-version.yml +++ b/.github/workflows/publish-release-version.yml @@ -30,7 +30,7 @@ jobs: - name: Build and Publish env: - TIMEMATES_SDK_VERSION: ${{ github.ref }} + TIMEMATES_SDK_VERSION: ${{ github.ref_name }} TIMEMATES_SSH_DEPLOY_PATH: ${{ secrets.TIMEMATES_SSH_DEPLOY_PATH }} TIMEMATES_SSH_HOST: ${{ secrets.TIMEMATES_SSH_HOST }} TIMEMATES_SSH_PASSWORD: ${{ secrets.TIMEMATES_SSH_PASSWORD }} From a2f3c62748410789ef3e8c144a7bcd1c92c46f9c Mon Sep 17 00:00:00 2001 From: y9vad9 Date: Fri, 29 Sep 2023 14:47:01 +0200 Subject: [PATCH 10/13] fix: websockets should be installed before rsocket --- .../io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt index 5d80ed0..07aadf6 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt +++ b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt @@ -57,6 +57,7 @@ public fun RSocketTimeMatesRequestsEngine( config: HttpClientConfig<*>.() -> Unit = {}, ): RSocketTimeMatesRequestsEngine { val client = HttpClient { + install(WebSockets) install(RSocketSupport) { connector { maxFragmentSize = 1024 From 6c50f2d8c906e7832aae1b453ba96e6d9904992f Mon Sep 17 00:00:00 2001 From: y9vad9 Date: Mon, 18 Dec 2023 23:34:42 +0100 Subject: [PATCH 11/13] refactor: move to `rsocket` --- gradle/libs.versions.toml | 5 + rsocket-engine/build.gradle.kts | 18 +++ .../commands/ConfigureNewAccountCommand.kt | 25 ---- .../GetAuthorizationSessionsCommand.kt | 28 ----- .../commands/RenewAuthorizationCommand.kt | 24 ---- .../TerminateCurrentAuthorizationCommand.kt | 18 --- .../RSocketConfigureAccountRequest.kt | 17 --- .../RSocketConfirmAuthorizationRequest.kt | 16 --- .../RSocketGetAuthorizationsRequest.kt | 14 --- .../RSocketRenewAuthorizationRequest.kt | 12 -- .../RSocketStartAuthorizationRequest.kt | 18 --- .../RSocketTerminateAuthorizationRequest.kt | 15 --- .../types/SerializableAuthMetadata.kt | 17 --- .../types/SerializableAuthorization.kt | 19 --- .../types/SerializableAuthorizationScope.kt | 34 ------ .../api/rsocket/common/ext/RSocketExt.kt | 84 ------------- .../rsocket/common/markers/RSocketRequest.kt | 8 -- .../common/metadata/AuthorizationMetadata.kt | 37 ------ .../rsocket/common/serialization/JsonExt.kt | 28 ----- .../files/commands/FilesCommandsRegistry.kt | 13 -- .../rsocket/files/commands/GetFileCommand.kt | 22 ---- .../files/commands/UploadFileCommand.kt | 43 ------- .../files/requests/RSocketGetFileRequest.kt | 23 ---- .../requests/RSocketUploadFileRequest.kt | 17 --- .../rsocket/files/types/SerializableFile.kt | 15 --- .../files/types/SerializableFileType.kt | 19 --- .../timers/commands/EditTimerCommand.kt | 22 ---- .../timers/commands/GetTimerCommand.kt | 27 ----- .../timers/commands/GetUserTimersCommand.kt | 30 ----- .../timers/commands/RemoveTimerCommand.kt | 18 --- .../commands/GetTimerMembersCommand.kt | 36 ------ .../commands/KickTimerMemberCommand.kt | 19 --- .../invites/commands/CreateInviteCommand.kt | 28 ----- .../invites/commands/GetInvitesCommand.kt | 31 ----- .../commands/JoinTimerByCodeCommand.kt | 27 ----- .../invites/commands/RemoveInviteCommand.kt | 24 ---- .../requests/RSocketCreateInviteRequest.kt | 13 -- .../requests/RSocketGetInvitesListRequest.kt | 17 --- .../requests/RSocketJoinTimerByCodeRequest.kt | 12 -- .../requests/RSocketRemoveInviteRequest.kt | 10 -- .../invites/types/SerializableInvite.kt | 24 ---- .../requests/RSocketGetMembersListRequest.kt | 17 --- .../requests/RSocketKickMemberRequest.kt | 6 - .../requests/RSocketCreateTimerRequest.kt | 15 --- .../requests/RSocketDeleteTimerRequest.kt | 9 -- .../requests/RSocketEditTimerRequest.kt | 13 -- .../timers/requests/RSocketGetTimerRequest.kt | 13 -- .../requests/RSocketGetUserTimersRequest.kt | 16 --- .../commands/ConfirmSessionCommand.kt | 18 --- .../commands/GetCurrentSessionCommand.kt | 19 --- .../sessions/commands/GetTimerStateCommand.kt | 32 ----- .../sessions/commands/JoinSessionCommand.kt | 20 ---- .../sessions/commands/LeaveSessionCommand.kt | 18 --- .../sessions/commands/StartSessionCommand.kt | 20 ---- .../sessions/commands/StopSessionCommand.kt | 20 ---- .../requests/RSocketConfirmSessionRequest.kt | 7 -- .../RSocketGetCurrentSessionRequest.kt | 11 -- .../RSocketGetCurrentTimerStateRequest.kt | 10 -- .../requests/RSocketJoinSessionRequest.kt | 9 -- .../requests/RSocketLeaveSessionRequest.kt | 7 -- .../RSocketPingCurrentSessionRequest.kt | 6 - .../requests/RSocketStartSessionRequest.kt | 9 -- .../requests/RSocketStopSessionRequest.kt | 9 -- .../sessions/types/SerializableTimerState.kt | 82 ------------- .../rsocket/timers/types/SerializableTimer.kt | 35 ------ .../timers/types/SerializableTimerSettings.kt | 42 ------- .../types/SerializableTimerSettingsPatch.kt | 15 --- .../users/commands/EditProfileCommand.kt | 23 ---- .../rsocket/users/commands/GetUsersCommand.kt | 20 ---- .../users/requests/RSocketEditEmailRequest.kt | 9 -- .../requests/RSocketEditUserProfileRequest.kt | 12 -- .../users/requests/RSocketGetUsersRequest.kt | 13 -- .../rsocket/users/types/SerializableAvatar.kt | 29 ----- .../rsocket/users/types/SerializableUser.kt | 28 ----- .../io/timemates/api/rsocket/ApiContainer.kt | 13 ++ .../timemates/api/rsocket/CommandsRegistry.kt | 2 - .../rsocket/RSocketTimeMatesRequestsEngine.kt | 43 +++---- .../api/rsocket/authorizations/AuthMappers.kt | 40 +++++++ .../commands/AuthorizationCommandsRegistry.kt | 0 .../commands/ConfigureNewAccountCommand.kt | 23 ++++ .../commands/ConfirmAuthorizationCommand.kt | 14 +-- .../GetAuthorizationSessionsCommand.kt | 28 +++++ .../commands/RenewAuthorizationCommand.kt | 21 ++++ .../commands/StartAuthorizationCommand.kt | 16 ++- .../TerminateCurrentAuthorizationCommand.kt | 17 +++ .../rsocket/common/commands/RSocketCommand.kt | 6 +- .../common/commands/RSocketCommands.kt | 3 +- .../commands/RSocketCommandsBuilderScope.kt | 0 .../api/rsocket/timers/TimerMappers.kt | 89 ++++++++++++++ .../timers/commands/CreateTimerCommand.kt | 19 ++- .../timers/commands/EditTimerCommand.kt | 20 ++++ .../timers/commands/GetTimerCommand.kt | 21 ++++ .../timers/commands/GetUserTimersCommand.kt | 30 +++++ .../timers/commands/RemoveTimerCommand.kt | 17 +++ .../timers/commands/TimersCommandsRegistry.kt | 0 .../commands/GetTimerMembersCommand.kt | 31 +++++ .../commands/KickTimerMemberCommand.kt | 17 +++ .../commands/TimerMembersCommandsRegistry.kt | 0 .../invites/commands/CreateInviteCommand.kt | 23 ++++ .../invites/commands/GetInvitesCommand.kt | 31 +++++ .../commands/JoinTimerByCodeCommand.kt | 20 ++++ .../invites/commands/RemoveInviteCommand.kt | 20 ++++ .../commands/TimerMembersCommandsRegistry.kt | 0 .../commands/ConfirmSessionCommand.kt | 17 +++ .../commands/GetCurrentSessionCommand.kt | 18 +++ .../sessions/commands/GetTimerStateCommand.kt | 20 ++++ .../sessions/commands/JoinSessionCommand.kt | 19 +++ .../sessions/commands/LeaveSessionCommand.kt | 17 +++ .../sessions/commands/PingSessionCommand.kt | 4 +- .../sessions/commands/StartSessionCommand.kt | 19 +++ .../sessions/commands/StopSessionCommand.kt | 19 +++ .../commands/TimerSessionsCommandsRegistry.kt | 0 .../api/rsocket/users/UsersMapper.kt | 20 ++++ .../users/commands/EditEmailCommand.kt | 14 +-- .../users/commands/EditProfileCommand.kt | 22 ++++ .../rsocket/users/commands/GetUsersCommand.kt | 17 +++ .../users/commands/UsersCommandsRegistry.kt | 0 .../authorizations/AuthorizationService.proto | 49 ++++++++ .../options/OmitAuthorizationOption.proto | 13 ++ .../ConfirmAuthorizationRequest.proto | 15 +++ .../requests/CreateProfileRequest.proto | 22 ++++ .../requests/GetAuthorizationsRequest.proto | 14 +++ .../requests/StartAuthorizationRequest.proto | 18 +++ .../authorizations/types/Authorization.proto | 36 ++++++ .../api/authorizations/types/Metadata.proto | 8 ++ .../timemates/api/timers/TimersService.proto | 68 +++++++++++ .../requests/CreateInviteRequest.proto | 13 ++ .../invites/requests/GetInvitesRequest.proto | 15 +++ .../requests/RemoveInviteRequest.proto | 8 ++ .../timers/members/invites/types/Invite.proto | 9 ++ .../members/requests/GetMembersRequest.proto | 14 +++ .../members/requests/KickMemberRequest.proto | 8 ++ .../timers/requests/CreateTimerRequest.proto | 23 ++++ .../requests/EditTimerInfoRequest.proto | 23 ++++ .../api/timers/requests/GetTimerRequest.proto | 7 ++ .../timers/requests/GetTimersRequest.proto | 13 ++ .../timers/requests/RemoveTimerRequest.proto | 9 ++ .../sessions/TimerSessionsService.proto | 71 +++++++++++ .../requests/ConfirmTimerSessionRequest.proto | 7 ++ .../GetCurrentTimerSessionRequest.proto | 11 ++ .../requests/GetTimerStateRequest.proto | 7 ++ .../requests/JoinTimerSessionRequest.proto | 7 ++ .../requests/StartTimerSessionRequest.proto | 7 ++ .../requests/StopTimerSessionRequest.proto | 7 ++ .../timers/sessions/types/TimerState.proto | 76 ++++++++++++ .../io/timemates/api/timers/types/Timer.proto | 111 ++++++++++++++++++ .../io/timemates/api/users/UsersService.proto | 32 +++++ .../api/users/requests/EditEmailRequest.proto | 7 ++ .../api/users/requests/EditUserRequest.proto | 19 +++ .../api/users/requests/GetUsersRequest.proto | 7 ++ .../io/timemates/api/users/types/User.proto | 32 +++++ .../sessions/AuthorizedSessionsApi.kt | 1 + .../sessions/types/value/ClientVersion.kt | 6 +- .../sdk/users/profile/types/Avatar.kt | 12 -- settings.gradle.kts | 2 + 155 files changed, 1522 insertions(+), 1594 deletions(-) delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketConfigureAccountRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketConfirmAuthorizationRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketGetAuthorizationsRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketRenewAuthorizationRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketStartAuthorizationRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketTerminateAuthorizationRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthMetadata.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorization.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorizationScope.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/ext/RSocketExt.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/markers/RSocketRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/metadata/AuthorizationMetadata.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/serialization/JsonExt.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/FilesCommandsRegistry.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/GetFileCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/UploadFileCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/RSocketGetFileRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/RSocketUploadFileRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFile.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFileType.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/EditTimerCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetTimerCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/RemoveTimerCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/GetTimerMembersCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/KickTimerMemberCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/CreateInviteCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/RemoveInviteCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketCreateInviteRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketGetInvitesListRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketJoinTimerByCodeRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketRemoveInviteRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/types/SerializableInvite.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketGetMembersListRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketKickMemberRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketCreateTimerRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketDeleteTimerRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketEditTimerRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetTimerRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetUserTimersRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/ConfirmSessionCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetCurrentSessionCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetTimerStateCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/JoinSessionCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/LeaveSessionCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StartSessionCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StopSessionCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketConfirmSessionRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentSessionRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentTimerStateRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketJoinSessionRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketLeaveSessionRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketPingCurrentSessionRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStartSessionRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStopSessionRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/types/SerializableTimerState.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimer.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettings.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettingsPatch.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketEditEmailRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketEditUserProfileRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketGetUsersRequest.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableAvatar.kt delete mode 100644 rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableUser.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/ApiContainer.kt rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/CommandsRegistry.kt (90%) rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt (73%) create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/AuthMappers.kt rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/authorizations/commands/AuthorizationCommandsRegistry.kt (100%) create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt (53%) create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt (67%) create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommand.kt (84%) rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommands.kt (95%) rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommandsBuilderScope.kt (100%) create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/TimerMappers.kt rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt (51%) create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/EditTimerCommand.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/GetTimerCommand.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/RemoveTimerCommand.kt rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/timers/commands/TimersCommandsRegistry.kt (100%) create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/commands/GetTimerMembersCommand.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/commands/KickTimerMemberCommand.kt rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/timers/members/commands/TimerMembersCommandsRegistry.kt (100%) create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/CreateInviteCommand.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/RemoveInviteCommand.kt rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/TimerMembersCommandsRegistry.kt (100%) create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/ConfirmSessionCommand.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetCurrentSessionCommand.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetTimerStateCommand.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/JoinSessionCommand.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/LeaveSessionCommand.kt rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt (83%) create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StartSessionCommand.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StopSessionCommand.kt rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/timers/sessions/commands/TimerSessionsCommandsRegistry.kt (100%) create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/UsersMapper.kt rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt (55%) create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt create mode 100644 rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt rename rsocket-engine/src/{commonMain => main}/kotlin/io/timemates/api/rsocket/users/commands/UsersCommandsRegistry.kt (100%) create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/authorizations/options/OmitAuthorizationOption.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/CreateProfileRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/authorizations/types/Metadata.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/TimersService.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/types/Invite.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/members/requests/GetMembersRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/members/requests/KickMemberRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/requests/CreateTimerRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/requests/EditTimerInfoRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/requests/GetTimerRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/requests/GetTimersRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/requests/RemoveTimerRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/TimerSessionsService.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetCurrentTimerSessionRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/types/TimerState.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/types/Timer.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/users/UsersService.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/users/requests/EditEmailRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/users/requests/EditUserRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/users/requests/GetUsersRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/users/types/User.proto diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2d20235..362fe81 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,6 +15,7 @@ protobuf-plugin = "0.9.2" grpc-netty = "1.55.1" android-target = "33" android-min = "24" +rsproto = "0.3.2" [libraries] kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } @@ -68,6 +69,9 @@ protobuf-java = { module = "com.google.protobuf:protobuf-java", version.ref = "p rsocket-client = { module = "io.rsocket.kotlin:rsocket-ktor-client", version.require = "0.15.4" } +timemates-rsproto-client = { module = "io.timemates.rsproto:client-core", version.ref = "rsproto" } +timemates-rsproto-common = { module = "io.timemates.rsproto:common-core", version.ref = "rsproto" } + [plugins] kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } @@ -78,3 +82,4 @@ android-library = { id = "com.android.library", version.ref = "androidGradlePlug android-application = { id = "com.android.library", version.ref = "androidGradlePlugin" } google-protobuf = { id = "com.google.protobuf", version.ref = "protobuf-plugin" } library-publish = { id = "publish-library", version.require = "SNAPSHOT" } +timemates-rsproto = { id = "io.timemates.rsproto", version.ref = "rsproto" } diff --git a/rsocket-engine/build.gradle.kts b/rsocket-engine/build.gradle.kts index 8b144bf..08c2ada 100644 --- a/rsocket-engine/build.gradle.kts +++ b/rsocket-engine/build.gradle.kts @@ -2,18 +2,28 @@ plugins { alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.kotlinx.serialization) alias(libs.plugins.library.publish) + alias(libs.plugins.timemates.rsproto) } kotlin { jvm() jvmToolchain(17) + sourceSets { + val commonMain by getting { + kotlin.srcDirs("src/main/kotlin", "build/generated/rsproto/kotlin") + } + } + explicitApi() } dependencies { commonMainImplementation(projects.sdk) + commonMainImplementation(libs.timemates.rsproto.common) + commonMainImplementation(libs.timemates.rsproto.client) + commonMainImplementation(libs.kotlinx.serialization) commonMainImplementation(libs.kotlinx.datetime) commonMainImplementation(libs.rsocket.client) @@ -37,6 +47,14 @@ deployLibrary { } } +rsproto { + protoSourcePath = "src/main/proto/" + generationOutputPath = "generated/rsproto/kotlin" + + clientGeneration = true + serverGeneration = false +} + tasks.withType { useJUnitPlatform() } \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt deleted file mode 100644 index 0af6d1f..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt +++ /dev/null @@ -1,25 +0,0 @@ -package io.timemates.api.rsocket.authorizations.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.authorizations.types.sdk -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.sdk.authorization.email.requests.ConfigureNewAccountRequest -import io.timemates.api.rsocket.authorizations.requests.RSocketConfigureAccountRequest as RSocketConfigureAccountRequest - -internal object ConfigureNewAccountCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: ConfigureNewAccountRequest): ConfigureNewAccountRequest.Result { - return rSocket.requestResponse( - route = "authorizations.account.configure", - data = RSocketConfigureAccountRequest( - verificationHash = input.verificationHash.string, - name = input.name.string, - description = input.description?.string, - ) - ).let { result -> - ConfigureNewAccountRequest.Result( - authorization = result.authorization.sdk() - ) - } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt deleted file mode 100644 index 433260b..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt +++ /dev/null @@ -1,28 +0,0 @@ -package io.timemates.api.rsocket.authorizations.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.authorizations.requests.RSocketGetAuthorizationsRequest -import io.timemates.api.rsocket.authorizations.types.SerializableAuthorization -import io.timemates.api.rsocket.authorizations.types.sdk -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.sdk.authorization.sessions.requests.GetAuthorizationSessionsRequest -import io.timemates.sdk.authorization.sessions.types.Authorization -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.common.pagination.Page -import io.timemates.sdk.common.pagination.PageToken - -internal object GetAuthorizationSessionsCommand : RSocketCommand> { - override suspend fun execute(rSocket: RSocket, input: GetAuthorizationSessionsRequest): Page { - return rSocket.requestResponse( - route = "authorizations.list", - data = RSocketGetAuthorizationsRequest(input.nextPageToken?.string), - accessHash = input.accessHash.string, - ).let { result -> - Page( - results = result.list.map(SerializableAuthorization::sdk), - nextPageToken = result.nextPageToken?.let { PageToken.createOrThrow(it) } - ) - } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt deleted file mode 100644 index 63a83fa..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt +++ /dev/null @@ -1,24 +0,0 @@ -package io.timemates.api.rsocket.authorizations.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.sdk.authorization.sessions.requests.RenewAuthorizationRequest -import io.timemates.sdk.authorization.types.value.AccessHash -import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.api.rsocket.authorizations.requests.RSocketRenewAuthorizationRequest as RSocketRenewAuthorizationRequest - -@OptIn(ExperimentalTimeMatesApi::class) -internal object RenewAuthorizationCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: RenewAuthorizationRequest): RenewAuthorizationRequest.Result { - return rSocket.requestResponse( - route = "authorizations.renew", - data = RSocketRenewAuthorizationRequest(input.refreshHash.string), - ).let { result -> - RenewAuthorizationRequest.Result( - AccessHash.createOrThrow(result.accessHash) - ) - } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt deleted file mode 100644 index 2bb1e29..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt +++ /dev/null @@ -1,18 +0,0 @@ -package io.timemates.api.rsocket.authorizations.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.authorizations.requests.RSocketTerminateAuthorizationRequest -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.sdk.authorization.sessions.requests.TerminateCurrentAuthorizationSessionRequest -import io.timemates.sdk.common.types.Empty - -internal object TerminateCurrentAuthorizationCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: TerminateCurrentAuthorizationSessionRequest): Empty { - return rSocket.requestResponse( - route = "authorizations.terminate", - data = RSocketTerminateAuthorizationRequest.Current, - accessHash = input.accessHash.string, - ).let { _ -> Empty } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketConfigureAccountRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketConfigureAccountRequest.kt deleted file mode 100644 index 88319b1..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketConfigureAccountRequest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package io.timemates.api.rsocket.authorizations.requests - -import io.timemates.api.rsocket.authorizations.types.SerializableAuthorization -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketConfigureAccountRequest( - val verificationHash: String, - val name: String, - val description: String?, -) : RSocketRequest { - @Serializable - data class Result( - val authorization: SerializableAuthorization, - ) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketConfirmAuthorizationRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketConfirmAuthorizationRequest.kt deleted file mode 100644 index 0568cd6..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketConfirmAuthorizationRequest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package io.timemates.api.rsocket.authorizations.requests - -import io.timemates.api.rsocket.authorizations.types.SerializableAuthorization -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketConfirmAuthorizationRequest( - val verificationHash: String, - val confirmationCode: String, -) : RSocketRequest { - data class Response( - val isNewAccount: Boolean, - val authorization: SerializableAuthorization?, - ) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketGetAuthorizationsRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketGetAuthorizationsRequest.kt deleted file mode 100644 index 4ec8464..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketGetAuthorizationsRequest.kt +++ /dev/null @@ -1,14 +0,0 @@ -package io.timemates.api.rsocket.authorizations.requests - -import io.timemates.api.rsocket.authorizations.types.SerializableAuthorization -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketGetAuthorizationsRequest( - val pageToken: String? = null, -) : RSocketRequest { - - @Serializable - data class Result(val list: List, val nextPageToken: String?) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketRenewAuthorizationRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketRenewAuthorizationRequest.kt deleted file mode 100644 index 1d52739..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketRenewAuthorizationRequest.kt +++ /dev/null @@ -1,12 +0,0 @@ -package io.timemates.api.rsocket.authorizations.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketRenewAuthorizationRequest( - val refreshHash: String, -) : RSocketRequest { - @Serializable - data class Result(val accessHash: String) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketStartAuthorizationRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketStartAuthorizationRequest.kt deleted file mode 100644 index 33d6e2e..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketStartAuthorizationRequest.kt +++ /dev/null @@ -1,18 +0,0 @@ -package io.timemates.api.rsocket.authorizations.requests - -import io.timemates.api.rsocket.authorizations.types.SerializableAuthMetadata -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketStartAuthorizationRequest( - val email: String, - val clientMetadata: SerializableAuthMetadata, -) : RSocketRequest { - @Serializable - data class Result( - val verificationHash: String, - val expiresAt: Long, - val attempts: Int, - ) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketTerminateAuthorizationRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketTerminateAuthorizationRequest.kt deleted file mode 100644 index f46d8a0..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/requests/RSocketTerminateAuthorizationRequest.kt +++ /dev/null @@ -1,15 +0,0 @@ -package io.timemates.api.rsocket.authorizations.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -internal sealed class RSocketTerminateAuthorizationRequest : RSocketRequest { - /** - * This type of termination request terminates authorization with which - * user has sent termination request. - */ - @SerialName("current") - data object Current : RSocketTerminateAuthorizationRequest() -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthMetadata.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthMetadata.kt deleted file mode 100644 index e9c7ac5..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthMetadata.kt +++ /dev/null @@ -1,17 +0,0 @@ -package io.timemates.api.rsocket.authorizations.types - -import io.timemates.sdk.authorization.sessions.types.Authorization -import kotlinx.serialization.Serializable - -@Serializable -internal data class SerializableAuthMetadata( - val applicationName: String, - val clientVersion: String, - val clientIpAddress: String?, -) - -internal fun Authorization.Metadata.serializable(): SerializableAuthMetadata = SerializableAuthMetadata( - applicationName = applicationName.string, - clientVersion = clientVersion.string, - clientIpAddress = clientIpAddress.string, -) \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorization.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorization.kt deleted file mode 100644 index b3eabca..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorization.kt +++ /dev/null @@ -1,19 +0,0 @@ -package io.timemates.api.rsocket.authorizations.types - -import io.timemates.sdk.authorization.sessions.types.Authorization -import kotlinx.serialization.Serializable - -@Serializable -internal data class SerializableAuthorization( - val userId: Long, - val accessHash: String, - val refreshAccessHash: String, - val scopes: List, - // todo expiresAt for refresh hash - val expiresAt: Long, - val createdAt: Long, - val clientMetadata: SerializableAuthMetadata, -) - -// todo expiresAt for refresh hash -internal fun SerializableAuthorization.sdk(): Authorization = TODO() \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorizationScope.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorizationScope.kt deleted file mode 100644 index 3840ab7..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/types/SerializableAuthorizationScope.kt +++ /dev/null @@ -1,34 +0,0 @@ -package io.timemates.api.rsocket.authorizations.types - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -internal sealed interface SerializableAuthorizationScope { - @SerialName("super") - data object All : SerializableAuthorizationScope - - @SerialName("auth:read") - data object AuthRead : SerializableAuthorizationScope - - @SerialName("auth:write") - data object AuthWrite : SerializableAuthorizationScope - - @SerialName("users:read") - data object UsersRead : SerializableAuthorizationScope - - @SerialName("users:write") - data object UsersWrite : SerializableAuthorizationScope - - @SerialName("timers:read") - data object TimersRead : SerializableAuthorizationScope - - @SerialName("timers:write") - data object TimersWrite : SerializableAuthorizationScope - - @SerialName("files:read") - data object FilesRead : SerializableAuthorizationScope - - @SerialName("files:write") - data object FilesWrite : SerializableAuthorizationScope -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/ext/RSocketExt.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/ext/RSocketExt.kt deleted file mode 100644 index 853e9dd..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/ext/RSocketExt.kt +++ /dev/null @@ -1,84 +0,0 @@ -package io.timemates.api.rsocket.common.ext - -import io.rsocket.kotlin.ExperimentalMetadataApi -import io.rsocket.kotlin.RSocket -import io.rsocket.kotlin.metadata.RoutingMetadata -import io.rsocket.kotlin.metadata.compositeMetadata -import io.rsocket.kotlin.payload.Payload -import io.rsocket.kotlin.payload.buildPayload -import io.timemates.api.rsocket.common.markers.RSocketRequest -import io.timemates.api.rsocket.common.metadata.AuthorizationMetadata -import io.timemates.api.rsocket.common.serialization.decodeFromJson -import io.timemates.api.rsocket.common.serialization.encodeToJson -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.map -import kotlinx.serialization.DeserializationStrategy -import kotlinx.serialization.SerializationStrategy -import kotlinx.serialization.serializer - -internal suspend inline fun , reified R> RSocket.requestResponse( - route: String, - data: T, - accessHash: String? = null, -): R = requestResponse(route, serializer(), serializer(), data, accessHash) - -internal suspend inline fun > RSocket.fireAndForget( - route: String, - data: T, - accessHash: String? = null, -): Unit = fireAndForget(route, serializer(), data, accessHash) - -internal inline fun , reified R> RSocket.requestStream( - route: String, - data: T, - accessHash: String? = null, -): Flow = requestStream(route, serializer(), serializer(), data, accessHash) - -internal suspend fun RSocket.requestResponse( - route: String, - dataSerStrategy: SerializationStrategy, - resultDeSerStrategy: DeserializationStrategy, - data: T, - accessHash: String? = null, -): R { - val payload = createPayload(route, data, dataSerStrategy, accessHash) - return requestResponse(payload).decodeFromJson(resultDeSerStrategy) -} - -internal fun RSocket.requestStream( - route: String, - dataSerStrategy: SerializationStrategy, - resultDeSerStrategy: DeserializationStrategy, - data: T, - accessHash: String? = null, -): Flow { - val payload = createPayload(route, data, dataSerStrategy, accessHash) - return requestStream(payload).map { it.decodeFromJson(resultDeSerStrategy) } -} - -internal suspend fun RSocket.fireAndForget( - route: String, - dataSerStrategy: SerializationStrategy, - data: T, - accessHash: String? = null, -) { - val payload = createPayload(route, data, dataSerStrategy, accessHash) - return fireAndForget(payload) -} - -@OptIn(ExperimentalMetadataApi::class) -private fun createPayload( - route: String, - data: T, - dataSerStrategy: SerializationStrategy, - accessHash: String?, -): Payload { - return buildPayload { - compositeMetadata { - add(RoutingMetadata(route)) - if (accessHash != null) - add(AuthorizationMetadata(accessHash)) - } - data(data.encodeToJson(dataSerStrategy)) - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/markers/RSocketRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/markers/RSocketRequest.kt deleted file mode 100644 index 1a545ea..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/markers/RSocketRequest.kt +++ /dev/null @@ -1,8 +0,0 @@ -package io.timemates.api.rsocket.common.markers - -/** - * Interface-marker for all RSocket requests. - * - * @param R response type of the request. - */ -internal interface RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/metadata/AuthorizationMetadata.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/metadata/AuthorizationMetadata.kt deleted file mode 100644 index 38401da..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/metadata/AuthorizationMetadata.kt +++ /dev/null @@ -1,37 +0,0 @@ -package io.timemates.api.rsocket.common.metadata - -import io.ktor.utils.io.core.BytePacketBuilder -import io.ktor.utils.io.core.ByteReadPacket -import io.ktor.utils.io.core.internal.ChunkBuffer -import io.ktor.utils.io.core.isNotEmpty -import io.ktor.utils.io.core.readTextExactBytes -import io.ktor.utils.io.core.writeFully -import io.ktor.utils.io.pool.ObjectPool -import io.rsocket.kotlin.ExperimentalMetadataApi -import io.rsocket.kotlin.core.MimeType -import io.rsocket.kotlin.core.WellKnownMimeType -import io.rsocket.kotlin.metadata.Metadata -import io.rsocket.kotlin.metadata.MetadataReader - -@ExperimentalMetadataApi -internal class AuthorizationMetadata(val authorization: String) : Metadata { - - override val mimeType: MimeType get() = Reader.mimeType - - override fun BytePacketBuilder.writeSelf() { - val bytes = authorization.encodeToByteArray() - writeByte(bytes.size.toByte()) - writeFully(bytes) - } - - override fun close(): Unit = Unit - - companion object Reader : MetadataReader { - override val mimeType: MimeType get() = WellKnownMimeType.MessageRSocketRouting - override fun ByteReadPacket.read(pool: ObjectPool): AuthorizationMetadata { - return AuthorizationMetadata( - readTextExactBytes(readByte().toInt() and 0xFF) - ) - } - } -} diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/serialization/JsonExt.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/serialization/JsonExt.kt deleted file mode 100644 index 4e6a368..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/serialization/JsonExt.kt +++ /dev/null @@ -1,28 +0,0 @@ -package io.timemates.api.rsocket.common.serialization - -import io.ktor.utils.io.core.ByteReadPacket -import io.ktor.utils.io.streams.inputStream -import io.rsocket.kotlin.payload.Payload -import kotlinx.serialization.DeserializationStrategy -import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.SerializationStrategy -import kotlinx.serialization.decodeFromString -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.decodeFromStream - -private val json = Json { - ignoreUnknownKeys = true -} - -internal fun T.encodeToJson(serializationStrategy: SerializationStrategy): ByteReadPacket { - return ByteReadPacket(json.encodeToString(serializationStrategy, this).encodeToByteArray()) -} - -internal inline fun ByteArray.decodeFromJson(): T { - return json.decodeFromString(String(this)) -} - -@OptIn(ExperimentalSerializationApi::class) -internal fun Payload.decodeFromJson(deserializationStrategy: DeserializationStrategy): T { - return json.decodeFromStream(deserializationStrategy, data.inputStream()) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/FilesCommandsRegistry.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/FilesCommandsRegistry.kt deleted file mode 100644 index 4918e7e..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/FilesCommandsRegistry.kt +++ /dev/null @@ -1,13 +0,0 @@ -package io.timemates.api.rsocket.files.commands - -import io.timemates.api.rsocket.common.commands.RSocketCommandsBuilderScope -import io.timemates.sdk.files.requests.GetFileBytesRequest -import io.timemates.sdk.files.requests.UploadFileRequest - -/** - * RSocket commands related to timers. - */ -internal fun RSocketCommandsBuilderScope.files() { - GetFileCommand associatedWith GetFileBytesRequest - UploadFileCommand associatedWith UploadFileRequest -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/GetFileCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/GetFileCommand.kt deleted file mode 100644 index c4f6066..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/GetFileCommand.kt +++ /dev/null @@ -1,22 +0,0 @@ -package io.timemates.api.rsocket.files.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestStream -import io.timemates.api.rsocket.common.serialization.decodeFromJson -import io.timemates.api.rsocket.files.requests.RSocketGetFileRequest -import io.timemates.api.rsocket.files.types.sdk -import io.timemates.sdk.files.requests.GetFileBytesRequest -import kotlinx.coroutines.flow.first - -internal object GetFileCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: GetFileBytesRequest): GetFileBytesRequest.Result { - return rSocket.requestStream( - route = "files.get", - data = RSocketGetFileRequest(input.fileId.string), - ).let { result -> - val metadata = result.first().decodeFromJson() - GetFileBytesRequest.Result(metadata.fileType.sdk(), result) - } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/UploadFileCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/UploadFileCommand.kt deleted file mode 100644 index 452b632..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/commands/UploadFileCommand.kt +++ /dev/null @@ -1,43 +0,0 @@ -package io.timemates.api.rsocket.files.commands - -import io.ktor.utils.io.core.ByteReadPacket -import io.rsocket.kotlin.ExperimentalMetadataApi -import io.rsocket.kotlin.RSocket -import io.rsocket.kotlin.metadata.RoutingMetadata -import io.rsocket.kotlin.metadata.compositeMetadata -import io.rsocket.kotlin.payload.Payload -import io.rsocket.kotlin.payload.buildPayload -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.serialization.decodeFromJson -import io.timemates.api.rsocket.common.serialization.encodeToJson -import io.timemates.api.rsocket.files.requests.RSocketUploadFileRequest -import io.timemates.api.rsocket.files.types.serializable -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.files.requests.UploadFileRequest -import io.timemates.sdk.files.types.value.FileId -import kotlinx.coroutines.flow.last -import kotlinx.coroutines.flow.map -import kotlinx.serialization.serializer - -internal object UploadFileCommand : RSocketCommand { - @OptIn(ExperimentalMetadataApi::class) - override suspend fun execute(rSocket: RSocket, input: UploadFileRequest): UploadFileRequest.Result { - return rSocket.requestChannel( - initPayload = buildPayload { - data( - RSocketUploadFileRequest.Metadata( - fileName = input.fileName.string, - fileType = input.fileType.serializable(), - ).encodeToJson(serializer()) - ) - compositeMetadata { - add(RoutingMetadata("files.upload")) - } - }, - payloads = input.bytes.map { Payload(data = ByteReadPacket(it)) } - ).let { result -> - val serialized = result.last().decodeFromJson(serializer()) - UploadFileRequest.Result(fileId = FileId.createOrThrow(serialized.fileId)) - } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/RSocketGetFileRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/RSocketGetFileRequest.kt deleted file mode 100644 index 878f02f..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/RSocketGetFileRequest.kt +++ /dev/null @@ -1,23 +0,0 @@ -package io.timemates.api.rsocket.files.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import io.timemates.api.rsocket.files.types.SerializableFileType -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketGetFileRequest( - val fileId: String, -) : RSocketRequest { - @Serializable - sealed interface Response { - @SerialName("metadata") - data class Metadata( - val fileType: SerializableFileType, - ) : Response - - @SerialName("chunk") - @JvmInline - value class Chunk(val bytes: ByteArray) : Response - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/RSocketUploadFileRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/RSocketUploadFileRequest.kt deleted file mode 100644 index d92091b..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/requests/RSocketUploadFileRequest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package io.timemates.api.rsocket.files.requests - -import io.timemates.api.rsocket.files.types.SerializableFileType -import kotlinx.coroutines.flow.Flow -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketUploadFileRequest( - val fileType: SerializableFileType, - val bytes: Flow, -) { - @Serializable - data class Metadata(val fileName: String, val fileType: SerializableFileType) - - @Serializable - data class Response(val fileId: String) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFile.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFile.kt deleted file mode 100644 index 9a48d2b..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFile.kt +++ /dev/null @@ -1,15 +0,0 @@ -package io.timemates.api.rsocket.files.types - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -internal sealed class SerializableFile { - abstract val fileId: String - - /** - * File with image. - */ - @SerialName("image") - data class Image(override val fileId: String) : SerializableFile() -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFileType.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFileType.kt deleted file mode 100644 index a5ff0f8..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/files/types/SerializableFileType.kt +++ /dev/null @@ -1,19 +0,0 @@ -package io.timemates.api.rsocket.files.types - -import io.timemates.sdk.files.types.FileType -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -internal enum class SerializableFileType { - @SerialName("image") - IMAGE, -} - -internal fun SerializableFileType.sdk(): FileType = when (this) { - SerializableFileType.IMAGE -> FileType.IMAGE -} - -internal fun FileType.serializable(): SerializableFileType = when (this) { - FileType.IMAGE -> SerializableFileType.IMAGE -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/EditTimerCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/EditTimerCommand.kt deleted file mode 100644 index 4c9e078..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/EditTimerCommand.kt +++ /dev/null @@ -1,22 +0,0 @@ -package io.timemates.api.rsocket.timers.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.sdk.common.types.Empty -import io.timemates.sdk.timers.requests.CreateTimerRequest -import io.timemates.sdk.timers.requests.EditTimerRequest -import io.timemates.api.rsocket.timers.requests.RSocketEditTimerRequest as RSocketEditTimerRequest - -internal object EditTimerCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: EditTimerRequest): Empty { - return rSocket.requestResponse( - route = "timers.edit", - data = RSocketEditTimerRequest( - timerId = input.timerId.long, - name = input.name?.string, - ), - accessHash = input.accessHash.string, - ).let { _ -> Empty } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetTimerCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetTimerCommand.kt deleted file mode 100644 index 4c8ad12..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetTimerCommand.kt +++ /dev/null @@ -1,27 +0,0 @@ -package io.timemates.api.rsocket.timers.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.timers.requests.RSocketGetTimerRequest -import io.timemates.api.rsocket.timers.types.sdk -import io.timemates.api.rsocket.timers.types.serializable -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.timers.requests.CreateTimerRequest -import io.timemates.sdk.timers.requests.GetTimerRequest -import io.timemates.sdk.timers.types.value.TimerId -import io.timemates.api.rsocket.timers.requests.RSocketCreateTimerRequest as RSocketCreateTimerRequest - -internal object GetTimerCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: GetTimerRequest): GetTimerRequest.Result { - return rSocket.requestResponse( - route = "timers.get", - data = RSocketGetTimerRequest( - timerId = input.timerId.long, - ), - accessHash = input.accessHash.string, - ).let { result -> - GetTimerRequest.Result(result.timer.sdk()) - } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt deleted file mode 100644 index 54b983a..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt +++ /dev/null @@ -1,30 +0,0 @@ -package io.timemates.api.rsocket.timers.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.timers.requests.RSocketGetUserTimersRequest -import io.timemates.api.rsocket.timers.types.SerializableTimer -import io.timemates.api.rsocket.timers.types.sdk -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.common.pagination.Page -import io.timemates.sdk.common.pagination.PageToken -import io.timemates.sdk.timers.requests.GetUserTimersRequest -import io.timemates.sdk.timers.types.Timer - -internal object GetUserTimersCommand : RSocketCommand> { - override suspend fun execute(rSocket: RSocket, input: GetUserTimersRequest): Page { - return rSocket.requestResponse( - route = "timers.user.list", - data = RSocketGetUserTimersRequest( - pageToken = input.pageToken?.string, - ), - accessHash = input.accessHash.string, - ).let { result -> - Page( - results = result.list.map(SerializableTimer::sdk), - nextPageToken = result.nextPageToken?.let { PageToken.createOrThrow(it) }, - ) - } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/RemoveTimerCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/RemoveTimerCommand.kt deleted file mode 100644 index 8a19ffb..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/RemoveTimerCommand.kt +++ /dev/null @@ -1,18 +0,0 @@ -package io.timemates.api.rsocket.timers.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.sdk.common.types.Empty -import io.timemates.sdk.timers.requests.RemoveTimerRequest -import io.timemates.api.rsocket.timers.requests.RSocketDeleteTimerRequest as RSocketDeleteTimerRequest - -internal object RemoveTimerCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: RemoveTimerRequest): Empty { - return rSocket.requestResponse( - route = "timers.delete", - data = RSocketDeleteTimerRequest(input.timerId.long), - accessHash = input.accessHash.string, - ).let { _ -> Empty } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/GetTimerMembersCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/GetTimerMembersCommand.kt deleted file mode 100644 index f7a1cdb..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/GetTimerMembersCommand.kt +++ /dev/null @@ -1,36 +0,0 @@ -package io.timemates.api.rsocket.timers.members.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.timers.members.requests.RSocketGetMembersListRequest -import io.timemates.api.rsocket.timers.requests.RSocketGetUserTimersRequest -import io.timemates.api.rsocket.timers.types.SerializableTimer -import io.timemates.api.rsocket.timers.types.sdk -import io.timemates.api.rsocket.users.types.SerializableUser -import io.timemates.api.rsocket.users.types.sdk -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.common.pagination.Page -import io.timemates.sdk.common.pagination.PageToken -import io.timemates.sdk.timers.members.requests.GetMembersRequest -import io.timemates.sdk.timers.requests.GetUserTimersRequest -import io.timemates.sdk.timers.types.Timer -import io.timemates.sdk.users.profile.types.User - -internal object GetTimerMembersCommand : RSocketCommand> { - override suspend fun execute(rSocket: RSocket, input: GetMembersRequest): Page { - return rSocket.requestResponse( - route = "timers.user.list", - data = RSocketGetMembersListRequest( - timerId = input.timerId.long, - pageToken = input.pageToken?.string, - ), - accessHash = input.accessHash.string, - ).let { result -> - Page( - results = result.list.map(SerializableUser::sdk), - nextPageToken = result.nextPageToken?.let { PageToken.createOrThrow(it) }, - ) - } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/KickTimerMemberCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/KickTimerMemberCommand.kt deleted file mode 100644 index 758cc86..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/KickTimerMemberCommand.kt +++ /dev/null @@ -1,19 +0,0 @@ -package io.timemates.api.rsocket.timers.members.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.sdk.common.types.Empty -import io.timemates.sdk.timers.members.requests.KickMemberRequest -import io.timemates.sdk.timers.requests.RemoveTimerRequest -import io.timemates.api.rsocket.timers.requests.RSocketDeleteTimerRequest as RSocketDeleteTimerRequest - -internal object KickTimerMemberCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: KickMemberRequest): Empty { - return rSocket.requestResponse( - route = "timers.members.kick", - data = RSocketDeleteTimerRequest(input.timerId.long), - accessHash = input.accessHash.string, - ).let { _ -> Empty } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/CreateInviteCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/CreateInviteCommand.kt deleted file mode 100644 index b552478..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/CreateInviteCommand.kt +++ /dev/null @@ -1,28 +0,0 @@ -package io.timemates.api.rsocket.timers.members.invites.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.timers.members.invites.requests.RSocketCreateInviteRequest -import io.timemates.api.rsocket.timers.types.serializable -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.timers.members.invites.requests.CreateInviteRequest -import io.timemates.sdk.timers.members.invites.types.value.InviteCode -import io.timemates.sdk.timers.requests.CreateTimerRequest -import io.timemates.sdk.timers.types.value.TimerId -import io.timemates.api.rsocket.timers.requests.RSocketCreateTimerRequest as RSocketCreateTimerRequest - -internal object CreateInviteCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: CreateInviteRequest): CreateInviteRequest.Result { - return rSocket.requestResponse( - route = "timers.members.invites.create", - data = RSocketCreateInviteRequest( - timerId = input.timerId.long, - maxJoiners = input.maxJoinersCount.int, - ), - accessHash = input.accessHash.string, - ).let { result -> - CreateInviteRequest.Result(InviteCode.createOrThrow(result.inviteCode)) - } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt deleted file mode 100644 index 9ae809f..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt +++ /dev/null @@ -1,31 +0,0 @@ -package io.timemates.api.rsocket.timers.members.invites.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.timers.members.invites.requests.RSocketGetInvitesListRequest -import io.timemates.api.rsocket.timers.members.invites.types.SerializableInvite -import io.timemates.api.rsocket.timers.members.invites.types.sdk -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.common.pagination.Page -import io.timemates.sdk.common.pagination.PageToken -import io.timemates.sdk.timers.members.invites.requests.GetInvitesRequest -import io.timemates.sdk.timers.members.invites.types.Invite - -internal object GetInvitesCommand : RSocketCommand> { - override suspend fun execute(rSocket: RSocket, input: GetInvitesRequest): Page { - return rSocket.requestResponse( - route = "timers.user.list", - data = RSocketGetInvitesListRequest( - timerId = input.timerId.long, - pageToken = input.pageToken?.string, - ), - accessHash = input.accessHash.string, - ).let { result -> - Page( - results = result.invites.map(SerializableInvite::sdk), - nextPageToken = result.nextPageToken?.let { PageToken.createOrThrow(it) }, - ) - } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt deleted file mode 100644 index 99348f8..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt +++ /dev/null @@ -1,27 +0,0 @@ -package io.timemates.api.rsocket.timers.members.invites.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.timers.members.invites.requests.RSocketCreateInviteRequest -import io.timemates.api.rsocket.timers.members.invites.requests.RSocketJoinTimerByCodeRequest -import io.timemates.api.rsocket.timers.types.serializable -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.timers.members.invites.requests.JoinTimerByCodeRequest -import io.timemates.sdk.timers.requests.CreateTimerRequest -import io.timemates.sdk.timers.types.value.TimerId -import io.timemates.api.rsocket.timers.requests.RSocketCreateTimerRequest as RSocketCreateTimerRequest - -internal object JoinTimerByCodeCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: JoinTimerByCodeRequest): JoinTimerByCodeRequest.Result { - return rSocket.requestResponse( - route = "timers.create", - data = RSocketJoinTimerByCodeRequest( - code = input.code.string, - ), - accessHash = input.accessHash.string, - ).let { result -> - JoinTimerByCodeRequest.Result(TimerId.createOrThrow(result.timerId)) - } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/RemoveInviteCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/RemoveInviteCommand.kt deleted file mode 100644 index 5de7b45..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/RemoveInviteCommand.kt +++ /dev/null @@ -1,24 +0,0 @@ -package io.timemates.api.rsocket.timers.members.invites.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.timers.members.invites.requests.RSocketRemoveInviteRequest -import io.timemates.sdk.common.types.Empty -import io.timemates.sdk.timers.members.invites.requests.RemoveInviteRequest -import io.timemates.sdk.timers.members.requests.KickMemberRequest -import io.timemates.sdk.timers.requests.RemoveTimerRequest -import io.timemates.api.rsocket.timers.requests.RSocketDeleteTimerRequest as RSocketDeleteTimerRequest - -internal object RemoveInviteCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: RemoveInviteRequest): Empty { - return rSocket.requestResponse( - route = "timers.members.kick", - data = RSocketRemoveInviteRequest( - timerId = input.timerId.long, - code = input.inviteCode.string, - ), - accessHash = input.accessHash.string, - ).let { _ -> Empty } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketCreateInviteRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketCreateInviteRequest.kt deleted file mode 100644 index 5b39f57..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketCreateInviteRequest.kt +++ /dev/null @@ -1,13 +0,0 @@ -package io.timemates.api.rsocket.timers.members.invites.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketCreateInviteRequest( - val timerId: Long, - val maxJoiners: Int, -) : RSocketRequest { - @Serializable - data class Result(val inviteCode: String) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketGetInvitesListRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketGetInvitesListRequest.kt deleted file mode 100644 index bac07b2..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketGetInvitesListRequest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package io.timemates.api.rsocket.timers.members.invites.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import io.timemates.api.rsocket.timers.members.invites.types.SerializableInvite -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketGetInvitesListRequest( - val timerId: Long, - val pageToken: String? = null, -) : RSocketRequest { - @Serializable - data class Result( - val invites: List, - val nextPageToken: String? = null, - ) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketJoinTimerByCodeRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketJoinTimerByCodeRequest.kt deleted file mode 100644 index ccbded7..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketJoinTimerByCodeRequest.kt +++ /dev/null @@ -1,12 +0,0 @@ -package io.timemates.api.rsocket.timers.members.invites.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketJoinTimerByCodeRequest( - val code: String, -) : RSocketRequest { - @Serializable - data class Result(val timerId: Long) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketRemoveInviteRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketRemoveInviteRequest.kt deleted file mode 100644 index 90e0380..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/requests/RSocketRemoveInviteRequest.kt +++ /dev/null @@ -1,10 +0,0 @@ -package io.timemates.api.rsocket.timers.members.invites.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketRemoveInviteRequest( - val timerId: Long, - val code: String, -) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/types/SerializableInvite.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/types/SerializableInvite.kt deleted file mode 100644 index 1333e4b..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/types/SerializableInvite.kt +++ /dev/null @@ -1,24 +0,0 @@ -package io.timemates.api.rsocket.timers.members.invites.types - -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.common.types.value.Count -import io.timemates.sdk.timers.members.invites.types.Invite -import io.timemates.sdk.timers.members.invites.types.value.InviteCode -import kotlinx.datetime.Instant -import kotlinx.serialization.Serializable - -@Serializable -internal data class SerializableInvite( - val timerId: Long, - val code: String, - val creationTime: Long, - val limit: Int, -) - -internal fun SerializableInvite.sdk(): Invite { - return Invite( - inviteCode = InviteCode.createOrThrow(code), - creationTime = Instant.fromEpochMilliseconds(creationTime), - limit = Count.createOrThrow(limit), - ) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketGetMembersListRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketGetMembersListRequest.kt deleted file mode 100644 index 1383216..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketGetMembersListRequest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package io.timemates.api.rsocket.timers.members.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import io.timemates.api.rsocket.users.types.SerializableUser -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketGetMembersListRequest( - val timerId: Long, - val pageToken: String? = null, -) : RSocketRequest { - @Serializable - data class Result( - val list: List, - val nextPageToken: String? = null, - ) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketKickMemberRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketKickMemberRequest.kt deleted file mode 100644 index a68a527..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/requests/RSocketKickMemberRequest.kt +++ /dev/null @@ -1,6 +0,0 @@ -package io.timemates.api.rsocket.timers.members.requests - -internal data class RSocketKickMemberRequest( - val timerId: Long, - val userId: Long, -) \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketCreateTimerRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketCreateTimerRequest.kt deleted file mode 100644 index e4352f8..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketCreateTimerRequest.kt +++ /dev/null @@ -1,15 +0,0 @@ -package io.timemates.api.rsocket.timers.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import io.timemates.api.rsocket.timers.types.SerializableTimerSettings -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketCreateTimerRequest( - val name: String, - val description: String = "", - val settings: SerializableTimerSettings? = null, -) : RSocketRequest { - @Serializable - data class Result(val timerId: Long) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketDeleteTimerRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketDeleteTimerRequest.kt deleted file mode 100644 index 9b78b94..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketDeleteTimerRequest.kt +++ /dev/null @@ -1,9 +0,0 @@ -package io.timemates.api.rsocket.timers.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketDeleteTimerRequest( - val timerId: Long, -) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketEditTimerRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketEditTimerRequest.kt deleted file mode 100644 index a526724..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketEditTimerRequest.kt +++ /dev/null @@ -1,13 +0,0 @@ -package io.timemates.api.rsocket.timers.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import io.timemates.api.rsocket.timers.types.SerializableTimerSettingsPatch -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketEditTimerRequest( - val timerId: Long, - val name: String? = null, - val description: String? = null, - val settings: SerializableTimerSettingsPatch? = null, -) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetTimerRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetTimerRequest.kt deleted file mode 100644 index b3a91df..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetTimerRequest.kt +++ /dev/null @@ -1,13 +0,0 @@ -package io.timemates.api.rsocket.timers.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import io.timemates.api.rsocket.timers.types.SerializableTimer -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketGetTimerRequest( - val timerId: Long, -) : RSocketRequest { - @Serializable - data class Result(val timer: SerializableTimer) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetUserTimersRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetUserTimersRequest.kt deleted file mode 100644 index 8dbe072..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/requests/RSocketGetUserTimersRequest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package io.timemates.api.rsocket.timers.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import io.timemates.api.rsocket.timers.types.SerializableTimer -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketGetUserTimersRequest( - val pageToken: String? = null, -) : RSocketRequest { - @Serializable - data class Result( - val nextPageToken: String? = null, - val list: List, - ) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/ConfirmSessionCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/ConfirmSessionCommand.kt deleted file mode 100644 index ee7f7c1..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/ConfirmSessionCommand.kt +++ /dev/null @@ -1,18 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.timers.sessions.requests.RSocketConfirmSessionRequest -import io.timemates.sdk.common.types.Empty -import io.timemates.sdk.timers.sessions.requests.ConfirmTimerRoundRequest - -internal object ConfirmSessionCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: ConfirmTimerRoundRequest): Empty { - return rSocket.requestResponse( - route = "timers.sessions.attendance.confirm", - data = RSocketConfirmSessionRequest, - accessHash = input.accessHash.string, - ).let { _ -> Empty } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetCurrentSessionCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetCurrentSessionCommand.kt deleted file mode 100644 index 40c1cd4..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetCurrentSessionCommand.kt +++ /dev/null @@ -1,19 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.timers.sessions.requests.RSocketGetCurrentSessionRequest -import io.timemates.api.rsocket.timers.types.sdk -import io.timemates.sdk.timers.sessions.requests.GetUserCurrentSessionRequest -import io.timemates.sdk.timers.types.Timer - -internal object GetCurrentSessionCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: GetUserCurrentSessionRequest): Timer { - return rSocket.requestResponse( - route = "timers.sessions.ping", - data = RSocketGetCurrentSessionRequest, - accessHash = input.accessHash.string, - ).timer.sdk() - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetTimerStateCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetTimerStateCommand.kt deleted file mode 100644 index 06cf6ec..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetTimerStateCommand.kt +++ /dev/null @@ -1,32 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.common.ext.requestStream -import io.timemates.api.rsocket.timers.requests.RSocketGetTimerRequest -import io.timemates.api.rsocket.timers.sessions.requests.RSocketGetCurrentTimerStateRequest -import io.timemates.api.rsocket.timers.sessions.types.sdk -import io.timemates.api.rsocket.timers.types.sdk -import io.timemates.api.rsocket.timers.types.serializable -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.timers.requests.CreateTimerRequest -import io.timemates.sdk.timers.requests.GetTimerRequest -import io.timemates.sdk.timers.sessions.requests.GetTimerStateRequest -import io.timemates.sdk.timers.types.value.TimerId -import kotlinx.coroutines.flow.map -import io.timemates.api.rsocket.timers.requests.RSocketCreateTimerRequest as RSocketCreateTimerRequest - -internal object GetTimerStateCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: GetTimerStateRequest): GetTimerStateRequest.Result { - return rSocket.requestStream( - route = "timers.get", - data = RSocketGetCurrentTimerStateRequest( - timerId = input.timerId.long, - ), - accessHash = input.accessHash.string, - ).let { result -> - GetTimerStateRequest.Result(result.map { it.sdk() }) - } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/JoinSessionCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/JoinSessionCommand.kt deleted file mode 100644 index fa800a1..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/JoinSessionCommand.kt +++ /dev/null @@ -1,20 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.timers.sessions.requests.RSocketJoinSessionRequest -import io.timemates.sdk.common.types.Empty -import io.timemates.sdk.timers.sessions.requests.JoinTimerSessionRequest - -internal object JoinSessionCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: JoinTimerSessionRequest): Empty { - return rSocket.requestResponse( - route = "timers.sessions.join", - data = RSocketJoinSessionRequest( - timerId = input.timerId.long, - ), - accessHash = input.accessHash.string, - ).let { _ -> Empty } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/LeaveSessionCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/LeaveSessionCommand.kt deleted file mode 100644 index 16b3fb7..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/LeaveSessionCommand.kt +++ /dev/null @@ -1,18 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.timers.sessions.requests.RSocketLeaveSessionRequest -import io.timemates.sdk.common.types.Empty -import io.timemates.sdk.timers.sessions.requests.LeaveTimerSessionRequest - -internal object LeaveSessionCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: LeaveTimerSessionRequest): Empty { - return rSocket.requestResponse( - route = "timers.sessions.leave", - data = RSocketLeaveSessionRequest, - accessHash = input.accessHash.string, - ).let { _ -> Empty } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StartSessionCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StartSessionCommand.kt deleted file mode 100644 index 9eba5f2..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StartSessionCommand.kt +++ /dev/null @@ -1,20 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.timers.sessions.requests.RSocketStartSessionRequest -import io.timemates.sdk.common.types.Empty -import io.timemates.sdk.timers.sessions.requests.StartTimerRequest - -internal object StartSessionCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: StartTimerRequest): Empty { - return rSocket.requestResponse( - route = "timers.sessions.start", - data = RSocketStartSessionRequest( - timerId = input.timerId.long, - ), - accessHash = input.accessHash.string, - ).let { _ -> Empty } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StopSessionCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StopSessionCommand.kt deleted file mode 100644 index 94f0dd6..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StopSessionCommand.kt +++ /dev/null @@ -1,20 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.timers.sessions.requests.RSocketStopSessionRequest -import io.timemates.sdk.common.types.Empty -import io.timemates.sdk.timers.sessions.requests.StopTimerRequest - -internal object StopSessionCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: StopTimerRequest): Empty { - return rSocket.requestResponse( - route = "timers.sessions.start", - data = RSocketStopSessionRequest( - timerId = input.timerId.long, - ), - accessHash = input.accessHash.string, - ).let { _ -> Empty } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketConfirmSessionRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketConfirmSessionRequest.kt deleted file mode 100644 index 13a7f10..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketConfirmSessionRequest.kt +++ /dev/null @@ -1,7 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data object RSocketConfirmSessionRequest : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentSessionRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentSessionRequest.kt deleted file mode 100644 index e23b1d8..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentSessionRequest.kt +++ /dev/null @@ -1,11 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import io.timemates.api.rsocket.timers.types.SerializableTimer -import kotlinx.serialization.Serializable - -@Serializable -internal data object RSocketGetCurrentSessionRequest : RSocketRequest { - @Serializable - data class Result(val timer: SerializableTimer) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentTimerStateRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentTimerStateRequest.kt deleted file mode 100644 index 70deed1..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketGetCurrentTimerStateRequest.kt +++ /dev/null @@ -1,10 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import io.timemates.api.rsocket.timers.sessions.types.SerializableTimerState -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketGetCurrentTimerStateRequest( - val timerId: Long, -) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketJoinSessionRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketJoinSessionRequest.kt deleted file mode 100644 index fbf2afd..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketJoinSessionRequest.kt +++ /dev/null @@ -1,9 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketJoinSessionRequest( - val timerId: Long, -) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketLeaveSessionRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketLeaveSessionRequest.kt deleted file mode 100644 index 0bf9d29..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketLeaveSessionRequest.kt +++ /dev/null @@ -1,7 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data object RSocketLeaveSessionRequest : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketPingCurrentSessionRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketPingCurrentSessionRequest.kt deleted file mode 100644 index 61d7c66..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketPingCurrentSessionRequest.kt +++ /dev/null @@ -1,6 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.requests - -import kotlinx.serialization.Serializable - -@Serializable -internal data object RSocketPingCurrentSessionRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStartSessionRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStartSessionRequest.kt deleted file mode 100644 index bbf6bb9..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStartSessionRequest.kt +++ /dev/null @@ -1,9 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketStartSessionRequest( - val timerId: Long, -) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStopSessionRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStopSessionRequest.kt deleted file mode 100644 index 3d7c22d..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/requests/RSocketStopSessionRequest.kt +++ /dev/null @@ -1,9 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketStopSessionRequest( - val timerId: Long, -) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/types/SerializableTimerState.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/types/SerializableTimerState.kt deleted file mode 100644 index eb54b71..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/types/SerializableTimerState.kt +++ /dev/null @@ -1,82 +0,0 @@ -package io.timemates.api.rsocket.timers.sessions.types - -import io.timemates.sdk.timers.types.Timer -import kotlinx.datetime.Instant -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -/** - * Represents current timer state. - * @see SDK Source - */ -@Serializable -internal sealed class SerializableTimerState { - abstract val endsAt: Long? - abstract val publishTime: Long - - @SerialName("inactive") - data class Inactive(override val publishTime: Long) : SerializableTimerState() { - override val endsAt: Long? get() = null - } - - @SerialName("pause") - data class Pause(override val publishTime: Long) : SerializableTimerState() { - override val endsAt: Long? get() = null - } - - @SerialName("running") - data class Running(override val endsAt: Long, override val publishTime: Long) : SerializableTimerState() - - @SerialName("rest") - data class Rest(override val endsAt: Long, override val publishTime: Long) : SerializableTimerState() - - @SerialName("confirmation") - data class Confirmation(override val endsAt: Long, override val publishTime: Long) : SerializableTimerState() -} - -internal fun SerializableTimerState.sdk(): Timer.State { - val endsAt = endsAt?.let { Instant.fromEpochMilliseconds(it) } - val publishTime = Instant.fromEpochMilliseconds(publishTime) - - return when (this) { - is SerializableTimerState.Confirmation -> - Timer.State.ConfirmationWaiting( - endsAt = endsAt!!, - publishTime = publishTime, - ) - is SerializableTimerState.Inactive -> Timer.State.Inactive( - publishTime = publishTime, - ) - is SerializableTimerState.Pause -> Timer.State.Paused( - publishTime = publishTime, - ) - is SerializableTimerState.Rest -> Timer.State.Rest( - endsAt = endsAt!!, - publishTime = publishTime, - ) - is SerializableTimerState.Running -> Timer.State.Running( - endsAt = endsAt!!, - publishTime = publishTime, - ) - } -} - -internal fun Timer.State.serializable(): SerializableTimerState { - return when (this) { - is Timer.State.ConfirmationWaiting -> SerializableTimerState.Confirmation( - endsAt.toEpochMilliseconds(), publishTime.toEpochMilliseconds(), - ) - is Timer.State.Inactive -> SerializableTimerState.Inactive( - publishTime.toEpochMilliseconds(), - ) - is Timer.State.Paused -> SerializableTimerState.Pause( - publishTime.toEpochMilliseconds(), - ) - is Timer.State.Rest -> SerializableTimerState.Rest( - endsAt.toEpochMilliseconds(), publishTime.toEpochMilliseconds(), - ) - is Timer.State.Running -> SerializableTimerState.Running( - endsAt.toEpochMilliseconds(), publishTime.toEpochMilliseconds(), - ) - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimer.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimer.kt deleted file mode 100644 index d108c6b..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimer.kt +++ /dev/null @@ -1,35 +0,0 @@ -package io.timemates.api.rsocket.timers.types - -import io.timemates.api.rsocket.timers.sessions.types.SerializableTimerState -import io.timemates.api.rsocket.timers.sessions.types.sdk -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.common.types.value.Count -import io.timemates.sdk.timers.types.Timer -import io.timemates.sdk.timers.types.value.TimerDescription -import io.timemates.sdk.timers.types.value.TimerId -import io.timemates.sdk.timers.types.value.TimerName -import io.timemates.sdk.users.profile.types.value.UserId -import kotlinx.serialization.Serializable - -@Serializable -internal data class SerializableTimer( - val id: Long, - val name: String, - val description: String, - val ownerId: Long, - val settings: SerializableTimerSettings, - val membersCount: Int, - val state: SerializableTimerState, -) - -internal fun SerializableTimer.sdk(): Timer { - return Timer( - timerId = TimerId.createOrThrow(id), - name = TimerName.createOrThrow(name), - description = TimerDescription.createOrThrow(description), - ownerId = UserId.createOrThrow(ownerId), - membersCount = Count.createOrThrow(membersCount), - settings = settings.sdk(), - state = state.sdk() - ) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettings.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettings.kt deleted file mode 100644 index b4a410f..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettings.kt +++ /dev/null @@ -1,42 +0,0 @@ -package io.timemates.api.rsocket.timers.types - -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.common.types.value.Count -import io.timemates.sdk.timers.types.TimerSettings -import kotlinx.serialization.Serializable -import kotlin.time.Duration - -@Serializable -internal data class SerializableTimerSettings( - val workTime: Duration, - val restTime: Duration, - val bigRestTime: Duration, - val bigRestEnabled: Boolean, - val bigRestPer: Int, - val isEveryoneCanPause: Boolean, - val isConfirmationRequired: Boolean, -) - -internal fun TimerSettings.serializable(): SerializableTimerSettings { - return SerializableTimerSettings( - workTime = workTime, - restTime = restTime, - bigRestTime = bigRestTime, - bigRestEnabled = bigRestEnabled, - bigRestPer = bigRestPer.int, - isEveryoneCanPause = isEveryoneCanPause, - isConfirmationRequired = isConfirmationRequired, - ) -} - -internal fun SerializableTimerSettings.sdk(): TimerSettings { - return TimerSettings( - workTime = workTime, - restTime = restTime, - bigRestTime = bigRestTime, - bigRestEnabled = bigRestEnabled, - bigRestPer = Count.createOrThrow(bigRestPer), - isEveryoneCanPause = isEveryoneCanPause, - isConfirmationRequired = isConfirmationRequired, - ) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettingsPatch.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettingsPatch.kt deleted file mode 100644 index cefb805..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/types/SerializableTimerSettingsPatch.kt +++ /dev/null @@ -1,15 +0,0 @@ -package io.timemates.api.rsocket.timers.types - -import kotlinx.serialization.Serializable -import kotlin.time.Duration - -@Serializable -internal data class SerializableTimerSettingsPatch( - val workTime: Duration? = null, - val restTime: Duration? = null, - val bigRestTime: Duration? = null, - val bigRestEnabled: Boolean? = null, - val bigRestPer: Int? = null, - val isEveryoneCanPause: Boolean? = null, - val isConfirmationRequired: Boolean? = null, -) \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt deleted file mode 100644 index 14b44dc..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt +++ /dev/null @@ -1,23 +0,0 @@ -package io.timemates.api.rsocket.users.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.users.requests.RSocketEditUserProfileRequest -import io.timemates.api.rsocket.users.types.serializable -import io.timemates.sdk.common.types.Empty -import io.timemates.sdk.users.profile.requests.EditProfileRequest - -internal object EditProfileCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: EditProfileRequest): Empty { - return rSocket.requestResponse( - route = "users.profile.edit", - data = RSocketEditUserProfileRequest( - name = input.name?.string, - description = input.description?.string, - avatar = input.avatar?.serializable(), - ), - accessHash = input.accessHash.string, - ).let { _ -> Empty } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt deleted file mode 100644 index 8bb7a8c..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt +++ /dev/null @@ -1,20 +0,0 @@ -package io.timemates.api.rsocket.users.commands - -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.users.types.SerializableUser -import io.timemates.api.rsocket.users.types.sdk -import io.timemates.sdk.users.profile.requests.GetUsersRequest -import io.timemates.api.rsocket.users.requests.RSocketGetUsersRequest as RSocketGetUsersRequest - -internal object GetUsersCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: GetUsersRequest): GetUsersRequest.Result { - return rSocket.requestResponse( - route = "users.profile.list", - data = RSocketGetUsersRequest(ids = input.users.map { it.long }) - ).let { result -> - GetUsersRequest.Result(result.list.map(SerializableUser::sdk)) - } - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketEditEmailRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketEditEmailRequest.kt deleted file mode 100644 index 6407e4c..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketEditEmailRequest.kt +++ /dev/null @@ -1,9 +0,0 @@ -package io.timemates.api.rsocket.users.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketEditEmailRequest( - val email: String, -) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketEditUserProfileRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketEditUserProfileRequest.kt deleted file mode 100644 index 1b754b3..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketEditUserProfileRequest.kt +++ /dev/null @@ -1,12 +0,0 @@ -package io.timemates.api.rsocket.users.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import io.timemates.api.rsocket.users.types.SerializableAvatar -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketEditUserProfileRequest( - val avatar: SerializableAvatar?, - val name: String?, - val description: String?, -) : RSocketRequest \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketGetUsersRequest.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketGetUsersRequest.kt deleted file mode 100644 index d502374..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/requests/RSocketGetUsersRequest.kt +++ /dev/null @@ -1,13 +0,0 @@ -package io.timemates.api.rsocket.users.requests - -import io.timemates.api.rsocket.common.markers.RSocketRequest -import io.timemates.api.rsocket.users.types.SerializableUser -import kotlinx.serialization.Serializable - -@Serializable -internal data class RSocketGetUsersRequest( - val ids: List, -) : RSocketRequest { - @Serializable - data class Result(val list: List) -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableAvatar.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableAvatar.kt deleted file mode 100644 index 92497a6..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableAvatar.kt +++ /dev/null @@ -1,29 +0,0 @@ -package io.timemates.api.rsocket.users.types - -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.users.profile.types.Avatar -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -internal sealed interface SerializableAvatar { - @SerialName("gravatar") - data class Gravatar(val gravatarId: String) : SerializableAvatar - - @SerialName("timemates") - data class TimeMates(val fileId: String) : SerializableAvatar -} - -internal fun Avatar.serializable(): SerializableAvatar { - return when (this) { - is Avatar.GravatarId -> SerializableAvatar.Gravatar(string) - is Avatar.FileId -> SerializableAvatar.TimeMates(string) - } -} - -internal fun SerializableAvatar.sdk(): Avatar { - return when (this) { - is SerializableAvatar.TimeMates -> Avatar.GravatarId.createOrThrow(fileId) - is SerializableAvatar.Gravatar -> Avatar.FileId.createOrThrow(gravatarId) - } -} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableUser.kt b/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableUser.kt deleted file mode 100644 index 858073b..0000000 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/types/SerializableUser.kt +++ /dev/null @@ -1,28 +0,0 @@ -package io.timemates.api.rsocket.users.types - -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.users.profile.types.User -import io.timemates.sdk.users.profile.types.value.EmailAddress -import io.timemates.sdk.users.profile.types.value.UserDescription -import io.timemates.sdk.users.profile.types.value.UserId -import io.timemates.sdk.users.profile.types.value.UserName -import kotlinx.serialization.Serializable - -@Serializable -internal data class SerializableUser( - val id: Long, - val name: String, - val emailAddress: String?, - val description: String?, - val avatar: SerializableAvatar?, -) - -internal fun SerializableUser.sdk(): User { - return User( - id = UserId.createOrThrow(id), - name = UserName.createOrThrow(name), - description = description?.let { UserDescription.createOrThrow(it) }, - emailAddress = emailAddress?.let { EmailAddress.createOrThrow(it) }, - avatar = avatar?.sdk() - ) -} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/ApiContainer.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/ApiContainer.kt new file mode 100644 index 0000000..9dc9a29 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/ApiContainer.kt @@ -0,0 +1,13 @@ +package io.timemates.api.rsocket + +import io.timemates.api.authorizations.AuthorizationServiceApi +import io.timemates.api.timers.TimerSessionsServiceApi +import io.timemates.api.timers.TimersServiceApi +import io.timemates.api.users.UsersServiceApi + +internal class ApiContainer ( + val auth: AuthorizationServiceApi, + val users: UsersServiceApi, + val timers: TimersServiceApi, + val timerSessions: TimerSessionsServiceApi, +) \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/CommandsRegistry.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/CommandsRegistry.kt similarity index 90% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/CommandsRegistry.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/CommandsRegistry.kt index ce6cd4e..8f30c77 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/CommandsRegistry.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/CommandsRegistry.kt @@ -2,7 +2,6 @@ package io.timemates.api.rsocket import io.timemates.api.rsocket.authorizations.commands.authorizations import io.timemates.api.rsocket.common.commands.rSocketCommands -import io.timemates.api.rsocket.files.commands.files import io.timemates.api.rsocket.timers.commands.timers import io.timemates.api.rsocket.users.commands.users @@ -15,6 +14,5 @@ import io.timemates.api.rsocket.users.commands.users internal val rSocketCommandsRegistry = rSocketCommands { authorizations() users() - files() timers() } diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt similarity index 73% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt index 07aadf6..2dceb03 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt @@ -3,38 +3,27 @@ package io.timemates.api.rsocket import io.ktor.client.HttpClient import io.ktor.client.HttpClientConfig import io.ktor.client.plugins.websocket.WebSockets -import io.rsocket.kotlin.ExperimentalMetadataApi -import io.rsocket.kotlin.RSocket import io.rsocket.kotlin.core.WellKnownMimeType import io.rsocket.kotlin.keepalive.KeepAlive import io.rsocket.kotlin.ktor.client.RSocketSupport import io.rsocket.kotlin.ktor.client.rSocket -import io.rsocket.kotlin.metadata.RoutingMetadata -import io.rsocket.kotlin.metadata.compositeMetadata import io.rsocket.kotlin.payload.PayloadMimeType -import io.rsocket.kotlin.payload.buildPayload -import io.timemates.api.rsocket.common.markers.RSocketRequest -import io.timemates.api.rsocket.common.metadata.AuthorizationMetadata -import io.timemates.api.rsocket.common.serialization.decodeFromJson -import io.timemates.api.rsocket.common.serialization.encodeToJson -import io.timemates.api.rsocket.timers.types.sdk +import io.timemates.api.authorizations.AuthorizationServiceApi +import io.timemates.api.timers.TimerSessionsServiceApi +import io.timemates.api.timers.TimersServiceApi +import io.timemates.api.users.UsersServiceApi import io.timemates.sdk.common.engine.TimeMatesRequestsEngine import io.timemates.sdk.common.exceptions.UnsupportedException -import io.timemates.sdk.common.types.Empty import io.timemates.sdk.common.types.TimeMatesEntity import io.timemates.sdk.common.types.TimeMatesRequest -import io.timemates.sdk.timers.requests.EditTimerRequest -import io.timemates.sdk.timers.requests.GetTimerRequest import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineStart +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async -import kotlinx.serialization.DeserializationStrategy -import kotlinx.serialization.SerializationStrategy -import kotlinx.serialization.serializer +import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.protobuf.ProtoBuf import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds -import io.timemates.api.rsocket.timers.requests.RSocketEditTimerRequest as RSocketEditTimerRequest -import io.timemates.api.rsocket.timers.requests.RSocketGetTimerRequest as RSocketGetTimerRequest /** * Creates an RSocket-based TimeMates request engine. @@ -92,22 +81,34 @@ public fun RSocketTimeMatesRequestsEngine( */ public class RSocketTimeMatesRequestsEngine internal constructor( private val client: HttpClient, - endpoint: String = "wss://api.timemates.io/v0/rsocket", + endpoint: String = "wss://api.timemates.io/rsocket", coroutineScope: CoroutineScope, ) : TimeMatesRequestsEngine { public companion object { - public const val API_VERSION: Int = 1 + public const val API_VERSION: Double = 0.1 } private val rSocket = coroutineScope.async(start = CoroutineStart.LAZY) { client.rSocket(endpoint) } + @OptIn(ExperimentalSerializationApi::class) + private val container = coroutineScope.async(start = CoroutineStart.LAZY) { + val rSocket = rSocket.await() + + ApiContainer( + auth = AuthorizationServiceApi(rSocket, ProtoBuf), + users = UsersServiceApi(rSocket, ProtoBuf), + timers = TimersServiceApi(rSocket, ProtoBuf), + timerSessions = TimerSessionsServiceApi(rSocket, ProtoBuf) + ) + } + override suspend fun execute( request: TimeMatesRequest, ): Result = runCatching { val rSocket = rSocket.await() - return@runCatching rSocketCommandsRegistry.execute(rSocket, request) + return@runCatching rSocketCommandsRegistry.execute(container.await(), request) ?: throw UnsupportedException("This type of request is not supported in RSocket engine.") } } \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/AuthMappers.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/AuthMappers.kt new file mode 100644 index 0000000..dc1480f --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/AuthMappers.kt @@ -0,0 +1,40 @@ +package io.timemates.api.rsocket.authorizations + +import io.timemates.api.authorizations.types.Metadata +import io.timemates.sdk.authorization.sessions.types.value.ApplicationName +import io.timemates.sdk.authorization.sessions.types.value.ClientIpAddress +import io.timemates.sdk.authorization.sessions.types.value.ClientVersion +import io.timemates.sdk.authorization.types.value.AccessHash +import io.timemates.sdk.authorization.types.value.HashValue +import io.timemates.sdk.common.constructor.createOrThrow +import kotlinx.datetime.Instant +import io.timemates.api.authorizations.types.Authorization as RSAuthorization +import io.timemates.sdk.authorization.sessions.types.Authorization as SdkAuth + +internal fun Metadata.sdk(): SdkAuth.Metadata { + return SdkAuth.Metadata( + applicationName = ApplicationName.createOrThrow(clientName), + clientVersion = ClientVersion.createOrThrow(clientVersion), + clientIpAddress = ClientIpAddress.createOrThrow("UNDEFINED") + ) +} + +internal fun SdkAuth.Metadata.rs(): Metadata { + return Metadata( + clientName = applicationName.string, + clientVersion = clientVersion.double, + ) +} + +internal fun RSAuthorization.sdk(): SdkAuth { + return SdkAuth( + accessHash = accessHash?.let { SdkAuth.Hash(HashValue.createOrThrow(it.value), Instant.fromEpochMilliseconds(it.expiresAt)) }, + refreshHash = refreshHash?.let { SdkAuth.Hash(HashValue.createOrThrow(it.value), Instant.fromEpochMilliseconds(it.expiresAt)) }, + generationTime = Instant.fromEpochMilliseconds(generationTime), + metadata = metadata?.sdk(), + ) +} + +internal fun AccessHash.toExtra(): Map { + return mapOf("access_hash" to string.toByteArray()) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/AuthorizationCommandsRegistry.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/AuthorizationCommandsRegistry.kt similarity index 100% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/AuthorizationCommandsRegistry.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/AuthorizationCommandsRegistry.kt diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt new file mode 100644 index 0000000..ed7ee83 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt @@ -0,0 +1,23 @@ +package io.timemates.api.rsocket.authorizations.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.sdk +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.authorization.email.requests.ConfigureNewAccountRequest +import io.timemates.api.users.requests.CreateProfileRequest as RSCreateProfileRequest + +internal object ConfigureNewAccountCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: ConfigureNewAccountRequest): ConfigureNewAccountRequest.Result { + return apis.auth.createProfile( + message = RSCreateProfileRequest( + verificationHash = input.verificationHash.string, + name = input.name.string, + description = input.description?.string.orEmpty(), + ) + ).let { result -> + ConfigureNewAccountRequest.Result( + authorization = result.authorization!!.sdk() + ) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt similarity index 53% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt index a6c0a1d..2d19215 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt @@ -1,17 +1,15 @@ package io.timemates.api.rsocket.authorizations.commands -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.authorizations.types.sdk +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.sdk import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse import io.timemates.sdk.authorization.email.requests.ConfirmAuthorizationRequest -import io.timemates.api.rsocket.authorizations.requests.RSocketConfirmAuthorizationRequest as RSocketConfirmAuthorizationRequest +import io.timemates.api.authorizations.requests.ConfirmAuthorizationRequest as RSConfirmAuthorizationRequest internal object ConfirmAuthorizationCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: ConfirmAuthorizationRequest): ConfirmAuthorizationRequest.Result { - return rSocket.requestResponse( - route = "authorizations.email.confirm", - data = RSocketConfirmAuthorizationRequest( + override suspend fun execute(apis: ApiContainer, input: ConfirmAuthorizationRequest): ConfirmAuthorizationRequest.Result { + return apis.auth.confirmAuthorization( + message = RSConfirmAuthorizationRequest( input.verificationHash.string, input.confirmationCode.string ) ).let { result -> diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt new file mode 100644 index 0000000..7e3dd5b --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt @@ -0,0 +1,28 @@ +package io.timemates.api.rsocket.authorizations.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.sdk +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.authorization.sessions.requests.GetAuthorizationSessionsRequest +import io.timemates.sdk.authorization.sessions.types.Authorization +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.common.pagination.Page +import io.timemates.sdk.common.pagination.PageToken +import io.timemates.api.authorizations.requests.GetAuthorizationsRequest as RSGetAuthorizationsRequest + +internal object GetAuthorizationSessionsCommand : RSocketCommand> { + override suspend fun execute(apis: ApiContainer, input: GetAuthorizationSessionsRequest): Page { + return apis.auth.getAuthorizations( + message = RSGetAuthorizationsRequest(input.nextPageToken?.string.orEmpty()), + extra = input.accessHash.toExtra(), + ).let { result -> + Page( + results = result.authorizations.map { it.sdk() }, + nextPageToken = result.nextPageToken + .takeIf { it.isNotEmpty() } + ?.let { PageToken.createOrThrow(it) }, + ) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt new file mode 100644 index 0000000..7dc15d7 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt @@ -0,0 +1,21 @@ +package io.timemates.api.rsocket.authorizations.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.authorization.sessions.requests.RenewAuthorizationRequest +import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi + +@OptIn(ExperimentalTimeMatesApi::class) +internal object RenewAuthorizationCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: RenewAuthorizationRequest): RenewAuthorizationRequest.Result { + TODO() +// return apis.auth.requestResponse( +// route = "authorizations.renew", +// data = RSocketRenewAuthorizationRequest(input.refreshHash.string), +// ).let { result -> +// RenewAuthorizationRequest.Result( +// AccessHash.createOrThrow(result.accessHash) +// ) +// } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt similarity index 67% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt index 7832cac..cc892ee 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt @@ -1,26 +1,24 @@ package io.timemates.api.rsocket.authorizations.commands -import io.rsocket.kotlin.RSocket -import io.timemates.api.rsocket.authorizations.types.serializable +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.rs import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse import io.timemates.sdk.authorization.email.requests.StartAuthorizationRequest import io.timemates.sdk.authorization.email.types.value.VerificationHash import io.timemates.sdk.common.constructor.createOrThrow import io.timemates.sdk.common.types.value.Count import kotlinx.datetime.Instant -import io.timemates.api.rsocket.authorizations.requests.RSocketStartAuthorizationRequest as RSocketStartAuthorizationRequest +import io.timemates.api.authorizations.requests.StartAuthorizationRequest as RSStartAuthorizationRequest internal object StartAuthorizationCommand : RSocketCommand { override suspend fun execute( - rSocket: RSocket, + apis: ApiContainer, input: StartAuthorizationRequest, ): StartAuthorizationRequest.Result { - return rSocket.requestResponse( - route = "authorizations.email.start", - data = RSocketStartAuthorizationRequest( + return apis.auth.startAuthorization( + message = RSStartAuthorizationRequest( input.emailAddress.string, - input.metadata.serializable(), + input.metadata.rs(), ) ).let { result -> StartAuthorizationRequest.Result( diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt new file mode 100644 index 0000000..7e12e41 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt @@ -0,0 +1,17 @@ +package io.timemates.api.rsocket.authorizations.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.authorization.sessions.requests.TerminateCurrentAuthorizationSessionRequest +import io.timemates.sdk.common.types.Empty +import com.google.protobuf.Empty.Companion as RSEmpty + +internal object TerminateCurrentAuthorizationCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: TerminateCurrentAuthorizationSessionRequest): Empty { + return apis.auth.terminateAuthorization( + message = RSEmpty.Default, + input.accessHash.toExtra(), + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommand.kt similarity index 84% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommand.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommand.kt index 5c2f583..6403b51 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommand.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommand.kt @@ -1,6 +1,6 @@ package io.timemates.api.rsocket.common.commands -import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.ApiContainer import io.timemates.sdk.common.types.TimeMatesEntity import io.timemates.sdk.common.types.TimeMatesRequest @@ -17,10 +17,10 @@ internal interface RSocketCommand, R : TimeMatesEntity> /** * Executes the command using the provided RSocket connection and input of type [T]. * - * @param rSocket The RSocket connection over which the command will be executed. + * @param apis The RSocket connection over which the command will be executed. * @param input The SDK entity representing the command's input. * @return The engine's entity representing the result of executing the command. * @throws RSocketException if there is an issue with the RSocket communication. */ - suspend fun execute(rSocket: RSocket, input: T): R + suspend fun execute(apis: ApiContainer, input: T): R } diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommands.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommands.kt similarity index 95% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommands.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommands.kt index a235cc4..902aa47 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommands.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommands.kt @@ -1,6 +1,7 @@ package io.timemates.api.rsocket.common.commands import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.ApiContainer import io.timemates.sdk.common.types.TimeMatesEntity import io.timemates.sdk.common.types.TimeMatesRequest @@ -29,7 +30,7 @@ internal value class RSocketCommands( * @param request The TimeMates request to execute. */ suspend inline fun , R : TimeMatesEntity> execute( - rSocket: RSocket, + rSocket: ApiContainer, request: T, ): R? { @Suppress("UNCHECKED_CAST") diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommandsBuilderScope.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommandsBuilderScope.kt similarity index 100% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommandsBuilderScope.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/common/commands/RSocketCommandsBuilderScope.kt diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/TimerMappers.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/TimerMappers.kt new file mode 100644 index 0000000..218b64a --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/TimerMappers.kt @@ -0,0 +1,89 @@ +package io.timemates.api.rsocket.timers + +import io.timemates.api.timers.sessions.types.TimerState +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.common.types.value.Count +import io.timemates.sdk.timers.members.invites.types.value.InviteCode +import io.timemates.sdk.timers.types.Timer +import io.timemates.sdk.timers.types.TimerSettings +import io.timemates.sdk.timers.types.value.TimerDescription +import io.timemates.sdk.timers.types.value.TimerId +import io.timemates.sdk.timers.types.value.TimerName +import io.timemates.sdk.users.profile.types.value.UserId +import kotlinx.datetime.Instant +import kotlin.time.Duration.Companion.minutes +import kotlin.time.DurationUnit +import io.timemates.api.timers.members.invites.types.Invite as RSInvite +import io.timemates.api.timers.sessions.types.TimerState as RSTimerState +import io.timemates.api.timers.types.Timer as RSTimer +import io.timemates.sdk.timers.members.invites.types.Invite as SdkInvite +import io.timemates.sdk.timers.types.Timer as SdkTimer +import io.timemates.sdk.timers.types.Timer.State as SdkTimerState +import io.timemates.sdk.timers.types.TimerSettings as SdkTimerSettings + +internal fun RSTimer.sdk(): SdkTimer { + return SdkTimer( + timerId = TimerId.createOrThrow(id), + name = TimerName.createOrThrow(name), + description = TimerDescription.createOrThrow(description), + ownerId = UserId.createOrThrow(ownerId), + membersCount = Count.createOrThrow(membersCount), + state = currentState?.sdk() ?: SdkTimerState.Inactive(Instant.DISTANT_PAST), + settings = settings?.sdk() ?: TimerSettings(), + ) +} + +internal fun RSTimerState.sdk(): SdkTimerState { + val publishTime = Instant.fromEpochMilliseconds(publishTime) + return when (phase) { + is TimerState.PhaseOneOf.ConfirmationWaiting -> SdkTimerState.ConfirmationWaiting( + endsAt = Instant.fromEpochMilliseconds(phase.value!!.endsAt), + publishTime = publishTime, + ) + is TimerState.PhaseOneOf.Inactive -> SdkTimerState.Inactive( + publishTime = publishTime, + ) + is TimerState.PhaseOneOf.Paused -> SdkTimerState.Paused( + publishTime = publishTime, + ) + is TimerState.PhaseOneOf.Rest -> SdkTimerState.Rest( + endsAt = Instant.fromEpochMilliseconds(phase.value!!.endsAt), + publishTime = publishTime, + ) + is TimerState.PhaseOneOf.Running -> SdkTimerState.Running( + endsAt = Instant.fromEpochMilliseconds(phase.value!!.endsAt), + publishTime = publishTime, + ) + null -> SdkTimerState.Inactive(Instant.DISTANT_PAST) + } +} + +internal fun RSTimer.Settings.sdk(): SdkTimerSettings { + return SdkTimerSettings( + workTime = workTime.minutes, + restTime = restTime.minutes, + bigRestTime = bigRestTime.minutes, + bigRestEnabled = bigRestEnabled, + bigRestPer = Count.createOrThrow(bigRestPer), + isEveryoneCanPause = isEveryoneCanPause, + isConfirmationRequired = isConfirmationRequired, + ) +} + +internal fun SdkTimerSettings.rs(): RSTimer.Settings { + return RSTimer.Settings( + workTime = workTime.toInt(DurationUnit.MINUTES), + restTime = restTime.toInt(DurationUnit.MINUTES), + bigRestEnabled = bigRestEnabled, + bigRestTime = bigRestTime.toInt(DurationUnit.MINUTES), + isConfirmationRequired = isConfirmationRequired, + ) +} + +internal fun RSInvite.sdk(): SdkInvite { + return SdkInvite( + inviteCode = InviteCode.createOrThrow(code), + creationTime = Instant.fromEpochMilliseconds(creationTime), + limit = Count.createOrThrow(limit), + ) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt similarity index 51% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt index 0c615fd..e3b0cea 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt @@ -1,24 +1,23 @@ package io.timemates.api.rsocket.timers.commands -import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse -import io.timemates.api.rsocket.timers.types.serializable +import io.timemates.api.rsocket.timers.rs import io.timemates.sdk.common.constructor.createOrThrow import io.timemates.sdk.timers.requests.CreateTimerRequest import io.timemates.sdk.timers.types.value.TimerId -import io.timemates.api.rsocket.timers.requests.RSocketCreateTimerRequest as RSocketCreateTimerRequest +import io.timemates.api.timers.requests.CreateTimerRequest as RSCreateTimerRequest internal object CreateTimerCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: CreateTimerRequest): CreateTimerRequest.Result { - return rSocket.requestResponse( - route = "timers.create", - data = RSocketCreateTimerRequest( + override suspend fun execute(apis: ApiContainer, input: CreateTimerRequest): CreateTimerRequest.Result { + return apis.timers.createTimer( + message = RSCreateTimerRequest( name = input.name.string, description = input.description.string, - settings = input.settings.serializable() + settings = input.settings.rs(), ), - accessHash = input.accessHash.string, + extra = input.accessHash.toExtra(), ).let { result -> CreateTimerRequest.Result(TimerId.createOrThrow(result.timerId)) } diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/EditTimerCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/EditTimerCommand.kt new file mode 100644 index 0000000..6ccea2c --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/EditTimerCommand.kt @@ -0,0 +1,20 @@ +package io.timemates.api.rsocket.timers.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.requests.EditTimerRequest +import io.timemates.api.timers.requests.EditTimerRequest as RSEditTimerRequest + +internal object EditTimerCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: EditTimerRequest): Empty { + return apis.timers.editTimer( + message = RSEditTimerRequest( + timerId = input.timerId.long, + name = input.name?.string.orEmpty(), + ), + extra = input.accessHash.toExtra(), + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/GetTimerCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/GetTimerCommand.kt new file mode 100644 index 0000000..4769722 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/GetTimerCommand.kt @@ -0,0 +1,21 @@ +package io.timemates.api.rsocket.timers.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.timers.sdk +import io.timemates.sdk.timers.requests.GetTimerRequest +import io.timemates.api.timers.requests.GetTimerRequest as RSGetTimerRequest + +internal object GetTimerCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: GetTimerRequest): GetTimerRequest.Result { + return apis.timers.getTimer( + message = RSGetTimerRequest( + timerId = input.timerId.long, + ), + extra = input.accessHash.toExtra(), + ).let { result -> + GetTimerRequest.Result(result.sdk()) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt new file mode 100644 index 0000000..cbfb139 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt @@ -0,0 +1,30 @@ +package io.timemates.api.rsocket.timers.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.timers.sdk +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.common.pagination.Page +import io.timemates.sdk.common.pagination.PageToken +import io.timemates.sdk.timers.requests.GetUserTimersRequest +import io.timemates.sdk.timers.types.Timer +import io.timemates.api.timers.requests.GetTimersRequest as RSGetTimersRequest + +internal object GetUserTimersCommand : RSocketCommand> { + override suspend fun execute(apis: ApiContainer, input: GetUserTimersRequest): Page { + return apis.timers.getTimers( + message = RSGetTimersRequest( + nextPageToken = input.pageToken?.string.orEmpty(), + ), + extra = input.accessHash.toExtra(), + ).let { result -> + Page( + results = result.timers.map { it.sdk() }, + nextPageToken = result.nextPageToken + .takeIf { it.isNotEmpty() } + ?.let { PageToken.createOrThrow(it) }, + ) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/RemoveTimerCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/RemoveTimerCommand.kt new file mode 100644 index 0000000..5abfeb5 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/RemoveTimerCommand.kt @@ -0,0 +1,17 @@ +package io.timemates.api.rsocket.timers.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.requests.RemoveTimerRequest +import io.timemates.api.timers.requests.RemoveTimerRequest as RSRemoveTimerRequest + +internal object RemoveTimerCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: RemoveTimerRequest): Empty { + return apis.timers.removeTimer( + message = RSRemoveTimerRequest(input.timerId.long), + extra = input.accessHash.toExtra(), + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/TimersCommandsRegistry.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/TimersCommandsRegistry.kt similarity index 100% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/commands/TimersCommandsRegistry.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/commands/TimersCommandsRegistry.kt diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/commands/GetTimerMembersCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/commands/GetTimerMembersCommand.kt new file mode 100644 index 0000000..91fdbb2 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/commands/GetTimerMembersCommand.kt @@ -0,0 +1,31 @@ +package io.timemates.api.rsocket.timers.members.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.users.sdk +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.common.pagination.Page +import io.timemates.sdk.common.pagination.PageToken +import io.timemates.sdk.timers.members.requests.GetMembersRequest +import io.timemates.sdk.users.profile.types.User +import io.timemates.api.timers.members.requests.GetMembersRequest as RSGetMembersRequest + +internal object GetTimerMembersCommand : RSocketCommand> { + override suspend fun execute(apis: ApiContainer, input: GetMembersRequest): Page { + return apis.timers.getMembers( + message = RSGetMembersRequest( + timerId = input.timerId.long, + nextPageToken = input.pageToken?.string.orEmpty(), + ), + extra = input.accessHash.toExtra(), + ).let { result -> + Page( + results = result.users.map { it.sdk() }, + nextPageToken = result.nextPageToken + .takeIf { it.isNotEmpty() } + ?.let { PageToken.createOrThrow(it) }, + ) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/commands/KickTimerMemberCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/commands/KickTimerMemberCommand.kt new file mode 100644 index 0000000..557c09b --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/commands/KickTimerMemberCommand.kt @@ -0,0 +1,17 @@ +package io.timemates.api.rsocket.timers.members.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.members.requests.KickMemberRequest +import io.timemates.api.timers.members.requests.KickMemberRequest as RSKickMemberRequest + +internal object KickTimerMemberCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: KickMemberRequest): Empty { + return apis.timers.kickMember( + message = RSKickMemberRequest(timerId = input.timerId.long), + extra = input.accessHash.toExtra(), + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/TimerMembersCommandsRegistry.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/commands/TimerMembersCommandsRegistry.kt similarity index 100% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/commands/TimerMembersCommandsRegistry.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/commands/TimerMembersCommandsRegistry.kt diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/CreateInviteCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/CreateInviteCommand.kt new file mode 100644 index 0000000..801e38e --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/CreateInviteCommand.kt @@ -0,0 +1,23 @@ +package io.timemates.api.rsocket.timers.members.invites.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.timers.members.invites.requests.InviteMemberRequest +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.timers.members.invites.requests.CreateInviteRequest +import io.timemates.sdk.timers.members.invites.types.value.InviteCode + +internal object CreateInviteCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: CreateInviteRequest): CreateInviteRequest.Result { + return apis.timers.createInvite( + message = InviteMemberRequest( + timerId = input.timerId.long, + maxJoiners = input.maxJoinersCount.int, + ), + extra = input.accessHash.toExtra(), + ).let { result -> + CreateInviteRequest.Result(InviteCode.createOrThrow(result.inviteCode)) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt new file mode 100644 index 0000000..08c4f18 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt @@ -0,0 +1,31 @@ +package io.timemates.api.rsocket.timers.members.invites.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.timers.sdk +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.common.pagination.Page +import io.timemates.sdk.common.pagination.PageToken +import io.timemates.sdk.timers.members.invites.requests.GetInvitesRequest +import io.timemates.sdk.timers.members.invites.types.Invite +import io.timemates.api.timers.members.invites.requests.GetInvitesRequest as RSGetInvitesRequest + +internal object GetInvitesCommand : RSocketCommand> { + override suspend fun execute(apis: ApiContainer, input: GetInvitesRequest): Page { + return apis.timers.getInvites( + message = RSGetInvitesRequest( + timerId = input.timerId.long, + nextPageToken = input.pageToken?.string.orEmpty(), + ), + extra = input.accessHash.toExtra(), + ).let { result -> + Page( + results = result.invites.map { it.sdk() }, + nextPageToken = result.nextPageToken + .takeIf { it.isNotEmpty() } + ?.let { PageToken.createOrThrow(it) }, + ) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt new file mode 100644 index 0000000..1d5b112 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt @@ -0,0 +1,20 @@ +package io.timemates.api.rsocket.timers.members.invites.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.timers.members.invites.requests.JoinTimerByCodeRequest + +internal object JoinTimerByCodeCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: JoinTimerByCodeRequest): JoinTimerByCodeRequest.Result { + TODO() +// return apis.timers( +// route = "timers.create", +// data = RSocketJoinTimerByCodeRequest( +// code = input.code.string, +// ), +// accessHash = input.accessHash.string, +// ).let { result -> +// JoinTimerByCodeRequest.Result(TimerId.createOrThrow(result.timerId)) +// } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/RemoveInviteCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/RemoveInviteCommand.kt new file mode 100644 index 0000000..65821c9 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/RemoveInviteCommand.kt @@ -0,0 +1,20 @@ +package io.timemates.api.rsocket.timers.members.invites.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.members.invites.requests.RemoveInviteRequest +import io.timemates.api.timers.members.invites.requests.RemoveInviteRequest as RSRemoveInviteRequest + +internal object RemoveInviteCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: RemoveInviteRequest): Empty { + return apis.timers.removeInvite( + message = RSRemoveInviteRequest( + timerId = input.timerId.long, + inviteCode = input.inviteCode.string, + ), + extra = input.accessHash.toExtra(), + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/TimerMembersCommandsRegistry.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/TimerMembersCommandsRegistry.kt similarity index 100% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/TimerMembersCommandsRegistry.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/TimerMembersCommandsRegistry.kt diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/ConfirmSessionCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/ConfirmSessionCommand.kt new file mode 100644 index 0000000..ccc2dc5 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/ConfirmSessionCommand.kt @@ -0,0 +1,17 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.sessions.requests.ConfirmTimerRoundRequest +import com.google.protobuf.Empty.Companion as RSEmpty + +internal object ConfirmSessionCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: ConfirmTimerRoundRequest): Empty { + return apis.timerSessions.confirmRound( + message = RSEmpty.Default, + extra = input.accessHash.toExtra(), + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetCurrentSessionCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetCurrentSessionCommand.kt new file mode 100644 index 0000000..0172b9f --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetCurrentSessionCommand.kt @@ -0,0 +1,18 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import com.google.protobuf.Empty +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.timers.sdk +import io.timemates.sdk.timers.sessions.requests.GetUserCurrentSessionRequest +import io.timemates.sdk.timers.types.Timer + +internal object GetCurrentSessionCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: GetUserCurrentSessionRequest): Timer { + return apis.timerSessions.getCurrentTimerSession( + message = Empty.Default, + extra = input.accessHash.toExtra(), + ).sdk() + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetTimerStateCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetTimerStateCommand.kt new file mode 100644 index 0000000..8828690 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/GetTimerStateCommand.kt @@ -0,0 +1,20 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.timers.sdk +import io.timemates.sdk.timers.sessions.requests.GetTimerStateRequest +import kotlinx.coroutines.flow.map +import io.timemates.api.timers.sessions.requests.GetTimerStateRequest as RSGetTimerStateRequest + +internal object GetTimerStateCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: GetTimerStateRequest): GetTimerStateRequest.Result { + return apis.timerSessions.getState( + message = RSGetTimerStateRequest(timerId = input.timerId.long), + extra = input.accessHash.toExtra(), + ).let { result -> + GetTimerStateRequest.Result(result.map { it.sdk() }) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/JoinSessionCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/JoinSessionCommand.kt new file mode 100644 index 0000000..114f20f --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/JoinSessionCommand.kt @@ -0,0 +1,19 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.sessions.requests.JoinTimerSessionRequest +import io.timemates.api.timers.sessions.requests.JoinTimerSessionRequest as RSJoinTimerSessionRequest + +internal object JoinSessionCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: JoinTimerSessionRequest): Empty { + return apis.timerSessions.joinSession( + message = RSJoinTimerSessionRequest( + timerId = input.timerId.long, + ), + extra = input.accessHash.toExtra(), + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/LeaveSessionCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/LeaveSessionCommand.kt new file mode 100644 index 0000000..9753d39 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/LeaveSessionCommand.kt @@ -0,0 +1,17 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.sessions.requests.LeaveTimerSessionRequest +import com.google.protobuf.Empty.Companion as RSEmpty + +internal object LeaveSessionCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: LeaveTimerSessionRequest): Empty { + return apis.timerSessions.leaveSession( + message = RSEmpty.Default, + extra = input.accessHash.toExtra(), + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt similarity index 83% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt index 4dec5d6..9d1aa92 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt @@ -3,7 +3,7 @@ package io.timemates.api.rsocket.timers.sessions.commands import io.rsocket.kotlin.RSocket import io.timemates.api.rsocket.common.commands.RSocketCommand import io.timemates.api.rsocket.common.ext.fireAndForget -import io.timemates.api.rsocket.timers.sessions.requests.RSocketLeaveSessionRequest +import io.timemates.api.rsocket.serializable.requests.timers.sessions.LeaveSessionRequest import io.timemates.sdk.common.types.Empty import io.timemates.sdk.timers.sessions.requests.PingSessionRequest @@ -11,7 +11,7 @@ internal object PingSessionCommand : RSocketCommand { override suspend fun execute(rSocket: RSocket, input: PingSessionRequest): Empty { return rSocket.fireAndForget( route = "timers.sessions.ping", - data = RSocketLeaveSessionRequest, + data = LeaveSessionRequest, accessHash = input.accessHash.string, ).let { _ -> Empty } } diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StartSessionCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StartSessionCommand.kt new file mode 100644 index 0000000..c782ab8 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StartSessionCommand.kt @@ -0,0 +1,19 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.sessions.requests.StartTimerRequest +import io.timemates.api.timers.sessions.requests.StartTimerRequest as RSStartTimerRequest + +internal object StartSessionCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: StartTimerRequest): Empty { + return apis.timerSessions.startTimer( + message = RSStartTimerRequest( + timerId = input.timerId.long, + ), + extra = input.accessHash.toExtra(), + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StopSessionCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StopSessionCommand.kt new file mode 100644 index 0000000..e497cbf --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/StopSessionCommand.kt @@ -0,0 +1,19 @@ +package io.timemates.api.rsocket.timers.sessions.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.timers.sessions.requests.StopTimerRequest +import io.timemates.api.timers.sessions.requests.StopTimerRequest as RSStopTimerRequest + +internal object StopSessionCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: StopTimerRequest): Empty { + return apis.timerSessions.stopTimer( + message = RSStopTimerRequest( + timerId = input.timerId.long, + ), + extra = input.accessHash.toExtra(), + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/TimerSessionsCommandsRegistry.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/TimerSessionsCommandsRegistry.kt similarity index 100% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/timers/sessions/commands/TimerSessionsCommandsRegistry.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/TimerSessionsCommandsRegistry.kt diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/UsersMapper.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/UsersMapper.kt new file mode 100644 index 0000000..84d7da2 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/UsersMapper.kt @@ -0,0 +1,20 @@ +package io.timemates.api.rsocket.users + +import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.users.profile.types.Avatar +import io.timemates.sdk.users.profile.types.value.EmailAddress +import io.timemates.sdk.users.profile.types.value.UserDescription +import io.timemates.sdk.users.profile.types.value.UserId +import io.timemates.sdk.users.profile.types.value.UserName +import io.timemates.api.users.types.User as RSUser +import io.timemates.sdk.users.profile.types.User as SdkUser + +internal fun RSUser.sdk(): SdkUser { + return SdkUser( + id = UserId.createOrThrow(id), + name = UserName.createOrThrow(name), + description = description.takeIf { it.isNotEmpty() }?.let { UserDescription.createOrThrow(it) }, + emailAddress = email.takeIf { it.isNotEmpty() }?.let { EmailAddress.createOrThrow(it) }, + avatar = gravatarId.takeIf { it.isNotBlank() }?.let { Avatar.GravatarId.createOrThrow(it) }, + ) +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt similarity index 55% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt index b5b8080..c56ea5a 100644 --- a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt @@ -1,21 +1,21 @@ package io.timemates.api.rsocket.users.commands import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra import io.timemates.api.rsocket.common.commands.RSocketCommand import io.timemates.api.rsocket.common.ext.requestResponse import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi import io.timemates.sdk.common.types.Empty import io.timemates.sdk.users.settings.requests.EditEmailRequest +import io.timemates.api.users.requests.EditEmailRequest as RSEditEmailRequest @OptIn(ExperimentalTimeMatesApi::class) internal object EditEmailCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: EditEmailRequest): Empty { - return rSocket.requestResponse( - route = "users.email.edit", - data = io.timemates.api.rsocket.users.requests.RSocketEditEmailRequest( - email = input.newEmail.string, - ), - accessHash = input.accessHash.string, + override suspend fun execute(apis: ApiContainer, input: EditEmailRequest): Empty { + return apis.users.setEmail( + message = RSEditEmailRequest(email = input.newEmail.string), + extra = input.accessHash.toExtra() ).let { _ -> Empty } } } \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt new file mode 100644 index 0000000..0b6ec97 --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/EditProfileCommand.kt @@ -0,0 +1,22 @@ +package io.timemates.api.rsocket.users.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.sdk.common.types.Empty +import io.timemates.sdk.users.profile.requests.EditProfileRequest +import io.timemates.sdk.users.profile.types.Avatar +import io.timemates.api.users.requests.EditUserRequest as RSEditUserRequest + +internal object EditProfileCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: EditProfileRequest): Empty { + return apis.users.setUser( + message = RSEditUserRequest( + gravatarId = (input.avatar as? Avatar.GravatarId)?.string.orEmpty(), + name = input.name?.string.orEmpty(), + description = input.description?.string.orEmpty(), + ), + extra = input.accessHash.toExtra(), + ).let { _ -> Empty } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt new file mode 100644 index 0000000..85e7a5b --- /dev/null +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/GetUsersCommand.kt @@ -0,0 +1,17 @@ +package io.timemates.api.rsocket.users.commands + +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.users.sdk +import io.timemates.sdk.users.profile.requests.GetUsersRequest +import io.timemates.api.users.requests.GetUsersRequest as RSGetUsersRequest + +internal object GetUsersCommand : RSocketCommand { + override suspend fun execute(apis: ApiContainer, input: GetUsersRequest): GetUsersRequest.Result { + return apis.users.getUsers( + message = RSGetUsersRequest(userId = input.users.map { it.long }), + ).let { result -> + GetUsersRequest.Result(result.users.map { it.sdk() }) + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/UsersCommandsRegistry.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/UsersCommandsRegistry.kt similarity index 100% rename from rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/users/commands/UsersCommandsRegistry.kt rename to rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/UsersCommandsRegistry.kt diff --git a/rsocket-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto new file mode 100644 index 0000000..059cfea --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto @@ -0,0 +1,49 @@ +syntax = "proto3"; + +import "io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto"; +import "io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto"; +import "io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto"; +import "io/timemates/api/authorizations/options/OmitAuthorizationOption.proto"; +import "io/timemates/api/authorizations/requests/CreateProfileRequest.proto"; +import "io/timemates/api/authorizations/types/Authorization.proto"; +import "google/protobuf/empty.proto"; + +option java_package = "io.timemates.api.authorizations"; + +service AuthorizationService { + /** + * Starts authorization by sending corresponding email to email address. + * + * Has next restrictions: + * – 3 requests per email is max. + */ + rpc startAuthorization(StartAuthorizationRequest) returns (StartAuthorizationRequest.Result) { + option (omit_authorization) = true; + } + + /** + * Confirms authorization by sending authorization verification code. + * + * Has next restrictions: + * – 3 attempts per verification code. + */ + rpc confirmAuthorization(ConfirmAuthorizationRequest) returns (ConfirmAuthorizationRequest.Response) { + option (omit_authorization) = true; + } + + rpc createProfile(CreateProfileRequest) returns (CreateProfileRequest.Response) { + option (omit_authorization) = true; + } + + /** + * Gets all active authorizations. + */ + rpc getAuthorizations(GetAuthorizationsRequest) returns (GetAuthorizationsRequest.Response); + + /** + * Terminates authorization by given identifier. + * + * Returns [Status] + */ + rpc terminateAuthorization(google.protobuf.Empty) returns (google.protobuf.Empty); +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/authorizations/options/OmitAuthorizationOption.proto b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/options/OmitAuthorizationOption.proto new file mode 100644 index 0000000..e1f69d3 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/options/OmitAuthorizationOption.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +import "google/protobuf/descriptor.proto"; + +option java_package = "io.timemates.api.authorizations.options"; + +extend google.protobuf.MethodOptions { + /** + * Some methods should not be checked on authorization as they provide + * registration / authentication features or just safe to be called by anyone. + */ + bool omit_authorization = 50001; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto new file mode 100644 index 0000000..e34d950 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +import "io/timemates/api/authorizations/types/Authorization.proto"; + +option java_package = "io.timemates.api.authorizations.requests"; + +message ConfirmAuthorizationRequest { + string verificationHash = 1; + string confirmationCode = 2; + + message Response { + bool isNewAccount = 1; + // if it's a new account, there's no authorization returned + optional Authorization authorization = 2; + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/CreateProfileRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/CreateProfileRequest.proto new file mode 100644 index 0000000..b01a69a --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/CreateProfileRequest.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; + +import "io/timemates/api/authorizations/types/Authorization.proto"; + +option java_package = "io.timemates.api.users.requests"; + +message CreateProfileRequest { + string verificationHash = 1; + /** + * User's name + */ + string name = 2; + + /** + * User's description. + */ + optional string description = 3; + + message Response { + Authorization authorization = 1; + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto new file mode 100644 index 0000000..bb46c28 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +import "io/timemates/api/authorizations/types/Authorization.proto"; + +option java_package = "io.timemates.api.authorizations.requests"; + +message GetAuthorizationsRequest { + // null if it's start of pagination + optional string pageToken = 1; + + message Response { + repeated Authorization authorizations = 1; + string nextPageToken = 2; + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto new file mode 100644 index 0000000..1992b67 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +import "io/timemates/api/authorizations/types/Authorization.proto"; +import "io/timemates/api/authorizations/types/Metadata.proto"; + +option java_package = "io.timemates.api.authorizations.requests"; + +message StartAuthorizationRequest { + string emailAddress = 1; + + optional Metadata metadata = 2; + + message Result { + string verificationHash = 1; + int64 expiresAt = 2; + int32 attempts = 3; + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto new file mode 100644 index 0000000..cd585d9 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto @@ -0,0 +1,36 @@ +syntax = "proto3"; + +import "io/timemates/api/authorizations/types/Metadata.proto"; + +option java_package = "io.timemates.api.authorizations.types"; + +message Authorization { + /** + * Hash that used to identify user. + * + * Has null if it's not new authorization. + */ + optional Hash accessHash = 2; + + /** + * Hash that used to identify user. + * + * Has null if it's not new authorization. + */ + optional Hash refreshHash = 3; + + /** + * Denotes when authorization was generated. + */ + int64 generationTime = 4; + + /** + * Additional information about authorization. + */ + optional Metadata metadata = 5; + + message Hash { + string value = 1; + int64 expiresAt = 2; + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/authorizations/types/Metadata.proto b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/types/Metadata.proto new file mode 100644 index 0000000..75d00a1 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/types/Metadata.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.authorizations.types"; + +message Metadata { + string clientName = 1; + double clientVersion = 2; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/TimersService.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/TimersService.proto new file mode 100644 index 0000000..ff8cfc5 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/TimersService.proto @@ -0,0 +1,68 @@ +syntax = "proto3"; + +import "io/timemates/api/timers/requests/CreateTimerRequest.proto"; +import "io/timemates/api/timers/requests/EditTimerInfoRequest.proto"; +import "io/timemates/api/timers/requests/RemoveTimerRequest.proto"; +import "io/timemates/api/timers/requests/GetTimerRequest.proto"; +import "io/timemates/api/timers/requests/GetTimersRequest.proto"; +import "io/timemates/api/timers/members/requests/KickMemberRequest.proto"; +import "io/timemates/api/timers/members/requests/GetMembersRequest.proto"; +import "io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto"; +import "io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto"; +import "io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto"; +import "io/timemates/api/timers/types/Timer.proto"; +import "google/protobuf/empty.proto"; + +option java_package = "io.timemates.api.timers"; + +service TimersService { + /** + * Creates timer. + */ + rpc createTimer(CreateTimerRequest) returns (CreateTimerRequest.Response); + + /** + * Gets timer by id. + */ + rpc getTimer(GetTimerRequest) returns (Timer); + + /* + * Gets timers by page token. + */ + rpc getTimers(GetTimersRequest) returns (GetTimersRequest.Response); + + /** + * Edits timer information & settings (name, description). + */ + rpc editTimer(EditTimerRequest) returns (google.protobuf.Empty); + + /** + * Kicks member out of timer. + */ + rpc kickMember(KickMemberRequest) returns (google.protobuf.Empty); + + /* + * Gets members of a timer. + */ + rpc getMembers(GetMembersRequest) returns (GetMembersRequest.Response); + + /* + * Creates invite for joining a timer. + */ + rpc createInvite(InviteMemberRequest) returns (InviteMemberRequest.Response); + + /** + * Gets invites of a timer. + */ + rpc getInvites(GetInvitesRequest) returns (GetInvitesRequest.Response); + + /** + * Gets invites of a timer. + */ + rpc removeInvite(RemoveInviteRequest) returns (google.protobuf.Empty); + + /** + * Removes timer. + */ + rpc removeTimer(RemoveTimerRequest) returns (google.protobuf.Empty); +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto new file mode 100644 index 0000000..bbeead2 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; +import "io/timemates/api/users/types/User.proto"; + +option java_package = "io.timemates.api.timers.members.invites.requests"; + +message InviteMemberRequest { + int64 timerId = 1; + int32 maxJoiners = 2; + + message Response { + string inviteCode = 1; + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto new file mode 100644 index 0000000..3947777 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +import "io/timemates/api/timers/members/invites/types/Invite.proto"; + +option java_package = "io.timemates.api.timers.members.invites.requests"; + +message GetInvitesRequest { + int64 timerId = 1; + optional string nextPageToken = 2; + + message Response { + repeated Invite invites = 1; + optional string nextPageToken = 3; + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto new file mode 100644 index 0000000..82b3325 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.timers.members.invites.requests"; + +message RemoveInviteRequest { + int64 timerId = 1; + string inviteCode = 2; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/types/Invite.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/types/Invite.proto new file mode 100644 index 0000000..7717238 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/types/Invite.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.timers.members.invites.types"; + +message Invite { + string code = 1; + int64 creationTime = 2; + int32 limit = 3; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/members/requests/GetMembersRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/members/requests/GetMembersRequest.proto new file mode 100644 index 0000000..b9dee63 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/members/requests/GetMembersRequest.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +import "io/timemates/api/users/types/User.proto"; + +option java_package = "io.timemates.api.timers.members.requests"; + +message GetMembersRequest { + int64 timerId = 1; + optional string nextPageToken = 2; + + message Response { + repeated User users = 1; + optional string nextPageToken = 2; + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/members/requests/KickMemberRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/members/requests/KickMemberRequest.proto new file mode 100644 index 0000000..13918ef --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/members/requests/KickMemberRequest.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.timers.members.requests"; + +message KickMemberRequest { + int64 timerId = 1; + int64 userId = 2; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/CreateTimerRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/CreateTimerRequest.proto new file mode 100644 index 0000000..144ff68 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/CreateTimerRequest.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; + +import "io/timemates/api/timers/types/Timer.proto"; + +option java_package = "io.timemates.api.timers.requests"; + +message CreateTimerRequest { + /** + * Timer's name. Up to 50 symbols. + */ + string name = 1; + + /** + * Timer's name. Up to 500 symbols. + */ + optional string description = 2; + + optional Timer.Settings settings = 3; + + message Response { + int64 timerId = 1; + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/EditTimerInfoRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/EditTimerInfoRequest.proto new file mode 100644 index 0000000..2d266b7 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/EditTimerInfoRequest.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; + +import "io/timemates/api/timers/types/Timer.proto"; + +option java_package = "io.timemates.api.timers.requests"; + +message EditTimerRequest { + int64 timerId = 1; + /** + * Timer's name. Up to 50 symbols. + */ + optional string name = 2; + + /** + * Timer's name. Up to 500 symbols. + */ + optional string description = 3; + + /** + * Timer's settings + */ + optional Timer.Settings.Patch settings = 4; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/GetTimerRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/GetTimerRequest.proto new file mode 100644 index 0000000..70143b6 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/GetTimerRequest.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.timers.requests"; + +message GetTimerRequest { + int64 timerId = 1; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/GetTimersRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/GetTimersRequest.proto new file mode 100644 index 0000000..e409eeb --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/GetTimersRequest.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; +import "io/timemates/api/timers/types/Timer.proto"; + +option java_package = "io.timemates.api.timers.requests"; + +message GetTimersRequest { + optional string nextPageToken = 1; + + message Response { + repeated Timer timers = 1; + optional string nextPageToken = 2; + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/RemoveTimerRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/RemoveTimerRequest.proto new file mode 100644 index 0000000..10684d5 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/requests/RemoveTimerRequest.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +import "io/timemates/api/timers/types/Timer.proto"; + +option java_package = "io.timemates.api.timers.requests"; + +message RemoveTimerRequest { + int64 timerId = 1; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/TimerSessionsService.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/TimerSessionsService.proto new file mode 100644 index 0000000..d34518d --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/TimerSessionsService.proto @@ -0,0 +1,71 @@ +syntax = "proto3"; + +import "io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto"; +import "io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto"; +import "io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto"; +import "io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto"; +import "io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto"; +import "io/timemates/api/timers/sessions/types/TimerState.proto"; +import "google/protobuf/empty.proto"; +import "io/timemates/api/timers/sessions/requests/GetCurrentTimerSessionRequest.proto"; +import "io/timemates/api/timers/types/Timer.proto"; + +option java_package = "io.timemates.api.timers"; + +/** + * The TimerSessionsService provides operations related to timer sessions. + */ +service TimerSessionsService { + + /** + * Starts the timer session. + * This RPC method starts the timer session. + */ + rpc startTimer(StartTimerRequest) returns (google.protobuf.Empty); + + /** + * Stops the timer session. + * This RPC method stops the timer session. + */ + rpc stopTimer(StopTimerRequest) returns (google.protobuf.Empty); + + /** + * Joins the timer session. + * This RPC method allows a user to join the timer session. + */ + rpc joinSession(JoinTimerSessionRequest) returns (google.protobuf.Empty); + + /** + * Leaves the timer session. + * This RPC method allows a user to leave the timer session. + */ + rpc leaveSession(google.protobuf.Empty) returns (google.protobuf.Empty); + + /** + * Confirms the user's attendance of the next round. + * This RPC method confirms the user's attendance of the next round. + * This is needed if the corresponding setting is enabled, usually you should + * just await for [TimerState.ConfirmationWaiting] state. + * + * Server will automatically determine your session. + */ + rpc confirmRound(google.protobuf.Empty) returns (google.protobuf.Empty); + + /** + * Sends a ping request that says that client currently online and active. + * Client should send such request once per 5 minutes. + */ + rpc pingSession(google.protobuf.Empty) returns (google.protobuf.Empty); + + /** + * Retrieves the current state of the timer. + * This RPC method always returns the current state of the timer and then updates of it. + * The state is returned as a stream of TimerState messages. + */ + rpc getState(GetTimerStateRequest) returns (stream TimerState); + + /** + * Gets current timer session + */ + rpc getCurrentTimerSession(google.protobuf.Empty) returns (Timer); +} diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto new file mode 100644 index 0000000..6fad59a --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.timers.sessions.requests"; + +message ConfirmTimerSessionRequest { + int64 timerId = 1; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetCurrentTimerSessionRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetCurrentTimerSessionRequest.proto new file mode 100644 index 0000000..150599d --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetCurrentTimerSessionRequest.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +import "io/timemates/api/timers/types/Timer.proto"; + +option java_package = "io.timemates.api.timers.requests"; + +message GetCurrentTimerSessionRequest { + message Response { + Timer timer = 1; + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto new file mode 100644 index 0000000..ef4e16c --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.timers.sessions.requests"; + +message GetTimerStateRequest { + int64 timerId = 1; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto new file mode 100644 index 0000000..209cc2f --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.timers.sessions.requests"; + +message JoinTimerSessionRequest { + int64 timerId = 1; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto new file mode 100644 index 0000000..168e5b6 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.timers.sessions.requests"; + +message StartTimerRequest { + int64 timerId = 1; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto new file mode 100644 index 0000000..15dcba0 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.timers.sessions.requests"; + +message StopTimerRequest { + int64 timerId = 1; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/types/TimerState.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/types/TimerState.proto new file mode 100644 index 0000000..ebe39bf --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/sessions/types/TimerState.proto @@ -0,0 +1,76 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.timers.sessions.types"; + +/** + * Represents the state of a timer. + */ +message TimerState { + + /** + * The publish time of the timer state. + * This field represents the time when the timer state was started. + */ + int64 publishTime = 1; + + /** + * The phase of the timer state. + * This field is a oneof field, indicating the current phase of the timer. + * Only one of the phase options can be set at a time. + */ + oneof phase { + Rest rest = 2; + Paused paused = 3; + Running running = 4; + ConfirmationWaiting confirmationWaiting = 5; + Inactive inactive = 6; + } + + /** + * Represents the inactive phase of the timer. + * This phase indicates that the timer is inactive. + */ + message Inactive {} + + /** + * Represents the rest phase of the timer. + * This phase indicates that the timer is in a resting state. + */ + message Rest { + /** + * The end time of the rest phase. + * This field represents the time when the rest phase ends. + */ + int64 endsAt = 1; + } + + /** + * Represents the paused phase of the timer. + * This phase indicates that the timer is paused. + */ + message Paused {} + + /** + * Represents the running phase of the timer. + * This phase indicates that the timer is currently running. + */ + message Running { + /** + * The end time of the running phase. + * This field represents the time when the running phase ends. + */ + int64 endsAt = 1; + } + + /** + * Represents the confirmation waiting phase of the timer. + * This phase indicates that the timer is waiting for confirmation. + */ + message ConfirmationWaiting { + /** + * The end time of the confirmation waiting phase. + * This field represents the time when the confirmation waiting phase ends. + */ + int64 endsAt = 1; + } +} diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/types/Timer.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/types/Timer.proto new file mode 100644 index 0000000..cf60797 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/types/Timer.proto @@ -0,0 +1,111 @@ +syntax = "proto3"; + +import "io/timemates/api/timers/sessions/types/TimerState.proto"; + +option java_package = "io.timemates.api.timers.types"; + +/** + * Represents a timer. + */ +message Timer { + + /** + * The ID of the timer. + */ + int64 id = 1; + + /** + * The name of the timer. + * This field represents the name of the timer and can contain up to 50 characters. + */ + string name = 2; + + /** + * The description of the timer. + * This field represents an optional description for the timer and can contain up to 500 characters. + */ + optional string description = 3; + + /** + * The ID of the owner of the timer. + * This field represents the ID of the user who owns the timer. + */ + int64 ownerId = 4; + + /** + * The settings of the timer. + * This field represents the settings for the timer. + */ + Settings settings = 5; + + /** + * The number of members in the timer. + * This field represents the count of members associated with the timer. + */ + int32 membersCount = 6; + + /** + * The current state of the timer. + * This field represents the current state of the timer. + */ + TimerState currentState = 7; + + /** + * Represents the settings of the timer. + */ + message Settings { + /** + * The work time duration in seconds. + * This field represents the duration of the work time in milliseconds. + */ + int32 workTime = 1; + + /** + * The rest time duration in seconds. + * This field represents the duration of the rest time in seconds. + */ + int32 restTime = 2; + + /** + * The big rest time duration in seconds. + * This field represents the duration of the big rest time in seconds. + */ + int32 bigRestTime = 3; + + /** + * Indicates if big rest is enabled. + * This field indicates whether the big rest is enabled or not. + */ + bool bigRestEnabled = 4; + + /** + * The number of work cycles before big rest. + * This field represents the number of work rounds before the big rest is triggered. + */ + int32 bigRestPer = 5; + + /** + * Indicates if everyone can pause the timer. + * This field indicates whether everyone can pause the timer or not. + * + * Also, it denotes whether all users can start the timer. + */ + bool isEveryoneCanPause = 6; + + /** + * Indicates if confirmation is required for timer round start. + * This field indicates whether confirmation is required for timer actions or not. + */ + bool isConfirmationRequired = 7; + + message Patch { + optional int32 workTime = 2; + optional int32 restTime = 3; + optional int32 bigRestTime = 4; + optional bool bigRestEnabled = 5; + optional int32 bigRestPer = 6; + optional bool isEveryoneCanPause = 7; + optional bool isConfirmationRequired = 8; + } + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/users/UsersService.proto b/rsocket-engine/src/main/proto/io/timemates/api/users/UsersService.proto new file mode 100644 index 0000000..f9e6524 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/users/UsersService.proto @@ -0,0 +1,32 @@ +syntax = "proto3"; + +import "io/timemates/api/users/requests/GetUsersRequest.proto"; +import "io/timemates/api/users/requests/EditUserRequest.proto"; +import "io/timemates/api/users/requests/EditEmailRequest.proto"; +import "io/timemates/api/users/types/User.proto"; +import "google/protobuf/empty.proto"; + +option java_package = "io.timemates.api.users"; + +service UsersService { + /** + * Gets users by given identifiers. + * + * Returns [User] or null. + */ + rpc getUsers(GetUsersRequest) returns (Users); + + /** + * Sets user information (name / description / avatar file id). + * + * Returns [Status] + */ + rpc setUser(EditUserRequest) returns (google.protobuf.Empty); + + /** + * Sets new email for current user. + * + * Returns [Status] + */ + rpc setEmail(EditEmailRequest) returns (google.protobuf.Empty); +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/users/requests/EditEmailRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/users/requests/EditEmailRequest.proto new file mode 100644 index 0000000..d22dc87 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/users/requests/EditEmailRequest.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.users.requests"; + +message EditEmailRequest { + string email = 1; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/users/requests/EditUserRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/users/requests/EditUserRequest.proto new file mode 100644 index 0000000..53b072c --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/users/requests/EditUserRequest.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.users.requests"; + +message EditUserRequest { + /** + * User's avatar id + */ + string gravatarId = 1; + /** + * User's name + */ + optional string name = 2; + + /** + * User's description. + */ + optional string description = 3; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/users/requests/GetUsersRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/users/requests/GetUsersRequest.proto new file mode 100644 index 0000000..2ab5057 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/users/requests/GetUsersRequest.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.users.requests"; + +message GetUsersRequest { + repeated int64 userId = 1; +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/users/types/User.proto b/rsocket-engine/src/main/proto/io/timemates/api/users/types/User.proto new file mode 100644 index 0000000..62e9437 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/users/types/User.proto @@ -0,0 +1,32 @@ +syntax = "proto3"; + +option java_package = "io.timemates.api.users.types"; + +message User { + /** + * User's identifier + */ + int64 id = 1; + + string gravatarId = 3; + + /** + * User's name + */ + string name = 4; + + /** + * User's description. + */ + string description = 5; + + /** + * User's email up to 200 symbols. + * Can be null if there is no access. + */ + optional string email = 6; +} + +message Users { + repeated User users = 1; +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/AuthorizedSessionsApi.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/AuthorizedSessionsApi.kt index 147bf8e..5510830 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/AuthorizedSessionsApi.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/AuthorizedSessionsApi.kt @@ -52,6 +52,7 @@ public class AuthorizedSessionsApi( } } +@Suppress("NAME_SHADOWING") public fun AuthorizedSessionsApi.getSessionsPages( pageToken: PageToken?, maxRetries: Count = Count.createOrThrow(5), diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ClientVersion.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ClientVersion.kt index d5f2767..c43e388 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ClientVersion.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/value/ClientVersion.kt @@ -3,9 +3,9 @@ package io.timemates.sdk.authorization.sessions.types.value import io.timemates.sdk.common.constructor.Factory @JvmInline -public value class ClientVersion private constructor(public val string: String) { - public companion object : Factory() { - override fun create(input: String): Result { +public value class ClientVersion private constructor(public val double: Double) { + public companion object : Factory() { + override fun create(input: Double): Result { return Result.success(ClientVersion(input)) } } diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/Avatar.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/Avatar.kt index 671d622..1394f4f 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/Avatar.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/users/profile/types/Avatar.kt @@ -15,16 +15,4 @@ public sealed interface Avatar { } } } - - @JvmInline - public value class FileId private constructor(public val string: String) : Avatar { - public companion object : Factory() { - override fun create(input: String): Result { - return when { - input.isBlank() -> Result.failure(CreationFailure.ofBlank()) - else -> Result.success(FileId(input)) - } - } - } - } } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 6c84a0e..57a9b30 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,6 +3,7 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") pluginManagement { repositories { gradlePluginPortal() + maven("https://maven.timemates.io") mavenCentral() google() } @@ -15,6 +16,7 @@ dependencyResolutionManagement { mavenCentral() maven("https://jitpack.io") maven("https://maven.y9vad9.com") + maven("https://maven.timemates.io") } } From b3132a9e2658d1621f80b998ea8d3e736bb3e150 Mon Sep 17 00:00:00 2001 From: y9vad9 Date: Tue, 19 Dec 2023 01:01:45 +0100 Subject: [PATCH 12/13] fix: build, missing requests --- .../commands/RenewAuthorizationCommand.kt | 18 +++++++-------- .../commands/JoinTimerByCodeCommand.kt | 23 +++++++++++-------- .../sessions/commands/PingSessionCommand.kt | 15 ++++++------ .../users/commands/EditEmailCommand.kt | 2 -- .../authorizations/AuthorizationService.proto | 13 +++++++++++ .../requests/RenewAuthorizationRequest.proto | 13 +++++++++++ .../timemates/api/timers/TimersService.proto | 6 +++++ .../JoinTimerByInviteCodeRequest.proto | 13 +++++++++++ .../requests/RenewAuthorizationRequest.kt | 3 ++- .../requests/JoinTimerByCodeRequest.kt | 3 ++- 10 files changed, 78 insertions(+), 31 deletions(-) create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/RenewAuthorizationRequest.proto create mode 100644 rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/JoinTimerByInviteCodeRequest.proto diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt index 7dc15d7..245143a 100644 --- a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt @@ -1,21 +1,21 @@ package io.timemates.api.rsocket.authorizations.commands import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.sdk import io.timemates.api.rsocket.common.commands.RSocketCommand import io.timemates.sdk.authorization.sessions.requests.RenewAuthorizationRequest import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi +import io.timemates.api.authorizations.requests.RenewAuthorizationRequest as RSRenewAuthorizationRequest @OptIn(ExperimentalTimeMatesApi::class) internal object RenewAuthorizationCommand : RSocketCommand { override suspend fun execute(apis: ApiContainer, input: RenewAuthorizationRequest): RenewAuthorizationRequest.Result { - TODO() -// return apis.auth.requestResponse( -// route = "authorizations.renew", -// data = RSocketRenewAuthorizationRequest(input.refreshHash.string), -// ).let { result -> -// RenewAuthorizationRequest.Result( -// AccessHash.createOrThrow(result.accessHash) -// ) -// } + return apis.auth.renewAuthorization( + message = RSRenewAuthorizationRequest(input.refreshHash.string), + ).let { result -> + RenewAuthorizationRequest.Result( + authorization = result.authorization!!.sdk() + ) + } } } \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt index 1d5b112..11b1c67 100644 --- a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/members/invites/commands/JoinTimerByCodeCommand.kt @@ -1,20 +1,23 @@ package io.timemates.api.rsocket.timers.members.invites.commands import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra import io.timemates.api.rsocket.common.commands.RSocketCommand +import io.timemates.api.rsocket.timers.sdk +import io.timemates.sdk.common.constructor.createOrThrow import io.timemates.sdk.timers.members.invites.requests.JoinTimerByCodeRequest +import io.timemates.sdk.timers.types.value.TimerId +import io.timemates.api.timers.requests.JoinTimerByInviteCodeRequest as RSJoinTimerByInviteCodeRequest internal object JoinTimerByCodeCommand : RSocketCommand { override suspend fun execute(apis: ApiContainer, input: JoinTimerByCodeRequest): JoinTimerByCodeRequest.Result { - TODO() -// return apis.timers( -// route = "timers.create", -// data = RSocketJoinTimerByCodeRequest( -// code = input.code.string, -// ), -// accessHash = input.accessHash.string, -// ).let { result -> -// JoinTimerByCodeRequest.Result(TimerId.createOrThrow(result.timerId)) -// } + return apis.timers.joinByInvite( + message = RSJoinTimerByInviteCodeRequest( + inviteCode = input.code.string, + ), + extra = input.accessHash.toExtra(), + ).let { result -> + JoinTimerByCodeRequest.Result(result.timer!!.sdk()) + } } } \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt index 9d1aa92..3c63c6e 100644 --- a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/timers/sessions/commands/PingSessionCommand.kt @@ -1,18 +1,17 @@ package io.timemates.api.rsocket.timers.sessions.commands -import io.rsocket.kotlin.RSocket +import io.timemates.api.rsocket.ApiContainer +import io.timemates.api.rsocket.authorizations.toExtra import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.fireAndForget -import io.timemates.api.rsocket.serializable.requests.timers.sessions.LeaveSessionRequest import io.timemates.sdk.common.types.Empty import io.timemates.sdk.timers.sessions.requests.PingSessionRequest +import com.google.protobuf.Empty.Companion as RSEmpty internal object PingSessionCommand : RSocketCommand { - override suspend fun execute(rSocket: RSocket, input: PingSessionRequest): Empty { - return rSocket.fireAndForget( - route = "timers.sessions.ping", - data = LeaveSessionRequest, - accessHash = input.accessHash.string, + override suspend fun execute(apis: ApiContainer, input: PingSessionRequest): Empty { + return apis.timerSessions.pingSession( + message = RSEmpty.Default, + extra = input.accessHash.toExtra(), ).let { _ -> Empty } } } \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt index c56ea5a..b0bb573 100644 --- a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/users/commands/EditEmailCommand.kt @@ -1,10 +1,8 @@ package io.timemates.api.rsocket.users.commands -import io.rsocket.kotlin.RSocket import io.timemates.api.rsocket.ApiContainer import io.timemates.api.rsocket.authorizations.toExtra import io.timemates.api.rsocket.common.commands.RSocketCommand -import io.timemates.api.rsocket.common.ext.requestResponse import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi import io.timemates.sdk.common.types.Empty import io.timemates.sdk.users.settings.requests.EditEmailRequest diff --git a/rsocket-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto index 059cfea..c27c867 100644 --- a/rsocket-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto +++ b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto @@ -5,6 +5,7 @@ import "io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.pro import "io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto"; import "io/timemates/api/authorizations/options/OmitAuthorizationOption.proto"; import "io/timemates/api/authorizations/requests/CreateProfileRequest.proto"; +import "io/timemates/api/authorizations/requests/RenewAuthorizationRequest.proto"; import "io/timemates/api/authorizations/types/Authorization.proto"; import "google/protobuf/empty.proto"; @@ -31,6 +32,18 @@ service AuthorizationService { option (omit_authorization) = true; } + /** + * Renews authorization using refresh token. + * + * Returns: new [Authorization]. + */ + rpc renewAuthorization(RenewAuthorizationRequest) returns (RenewAuthorizationRequest.Response) { + option (omit_authorization) = true; + } + + /** + * Creates a user's profile if it's a new account. + */ rpc createProfile(CreateProfileRequest) returns (CreateProfileRequest.Response) { option (omit_authorization) = true; } diff --git a/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/RenewAuthorizationRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/RenewAuthorizationRequest.proto new file mode 100644 index 0000000..f5ad398 --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/requests/RenewAuthorizationRequest.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +import "io/timemates/api/authorizations/types/Authorization.proto"; + +option java_package = "io.timemates.api.authorizations.requests"; + +message RenewAuthorizationRequest { + string refreshHash = 1; + + message Response { + Authorization authorization = 1; + } +} \ No newline at end of file diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/TimersService.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/TimersService.proto index ff8cfc5..3300089 100644 --- a/rsocket-engine/src/main/proto/io/timemates/api/timers/TimersService.proto +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/TimersService.proto @@ -10,6 +10,7 @@ import "io/timemates/api/timers/members/requests/GetMembersRequest.proto"; import "io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto"; import "io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto"; import "io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto"; +import "io/timemates/api/timers/members/invites/requests/JoinTimerByInviteCodeRequest.proto"; import "io/timemates/api/timers/types/Timer.proto"; import "google/protobuf/empty.proto"; @@ -61,6 +62,11 @@ service TimersService { */ rpc removeInvite(RemoveInviteRequest) returns (google.protobuf.Empty); + /** + * Joins timer by invite code. + */ + rpc joinByInvite(JoinTimerByInviteCodeRequest) returns (JoinTimerByInviteCodeRequest.Response); + /** * Removes timer. */ diff --git a/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/JoinTimerByInviteCodeRequest.proto b/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/JoinTimerByInviteCodeRequest.proto new file mode 100644 index 0000000..448bb0e --- /dev/null +++ b/rsocket-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/JoinTimerByInviteCodeRequest.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +import "io/timemates/api/timers/types/Timer.proto"; + +option java_package = "io.timemates.api.timers.requests"; + +message JoinTimerByInviteCodeRequest { + string inviteCode = 1; + + message Response { + Timer timer = 1; + } +} \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/RenewAuthorizationRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/RenewAuthorizationRequest.kt index b9875b6..6b9adb2 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/RenewAuthorizationRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/requests/RenewAuthorizationRequest.kt @@ -1,5 +1,6 @@ package io.timemates.sdk.authorization.sessions.requests +import io.timemates.sdk.authorization.sessions.types.Authorization import io.timemates.sdk.authorization.types.value.AccessHash import io.timemates.sdk.authorization.types.value.HashValue import io.timemates.sdk.common.annotations.ApiStatus @@ -15,7 +16,7 @@ public data class RenewAuthorizationRequest( @ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) public data class Result( - val accessHash: AccessHash, + val authorization: Authorization, ) : TimeMatesEntity() override val requestKey: Key get() = Key diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/JoinTimerByCodeRequest.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/JoinTimerByCodeRequest.kt index b698124..ace017c 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/JoinTimerByCodeRequest.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/timers/members/invites/requests/JoinTimerByCodeRequest.kt @@ -4,6 +4,7 @@ import io.timemates.sdk.authorization.types.value.AccessHash import io.timemates.sdk.common.types.TimeMatesEntity import io.timemates.sdk.common.types.TimeMatesRequest import io.timemates.sdk.timers.members.invites.types.value.InviteCode +import io.timemates.sdk.timers.types.Timer import io.timemates.sdk.timers.types.value.TimerId public data class JoinTimerByCodeRequest( @@ -14,5 +15,5 @@ public data class JoinTimerByCodeRequest( override val requestKey: Key get() = Key - public data class Result(val timerId: TimerId) : TimeMatesEntity() + public data class Result(val timer: Timer) : TimeMatesEntity() } \ No newline at end of file From 70cbcd5d408fd8c01db4537e66b4a1f5f5134d0d Mon Sep 17 00:00:00 2001 From: y9vad9 Date: Tue, 19 Dec 2023 17:43:25 +0100 Subject: [PATCH 13/13] fix & userId in auth model --- .../api/rsocket/RSocketTimeMatesRequestsEngine.kt | 7 +++---- .../io/timemates/api/rsocket/authorizations/AuthMappers.kt | 2 ++ .../timemates/api/authorizations/types/Authorization.proto | 5 +++++ .../sdk/authorization/sessions/types/Authorization.kt | 4 +++- .../timemates/sdk/common/providers/AccessHashProvider.kt | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt index 2dceb03..42c577b 100644 --- a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt @@ -58,8 +58,8 @@ public fun RSocketTimeMatesRequestsEngine( ) payloadMimeType = PayloadMimeType( - data = WellKnownMimeType.ApplicationJson, - metadata = WellKnownMimeType.MessageRSocketCompositeMetadata, + data = WellKnownMimeType.ApplicationProtoBuf, + metadata = WellKnownMimeType.ApplicationProtoBuf, ) } } @@ -85,7 +85,7 @@ public class RSocketTimeMatesRequestsEngine internal constructor( coroutineScope: CoroutineScope, ) : TimeMatesRequestsEngine { public companion object { - public const val API_VERSION: Double = 0.1 + public const val API_VERSION: Double = 1.0 } private val rSocket = coroutineScope.async(start = CoroutineStart.LAZY) { @@ -107,7 +107,6 @@ public class RSocketTimeMatesRequestsEngine internal constructor( override suspend fun execute( request: TimeMatesRequest, ): Result = runCatching { - val rSocket = rSocket.await() return@runCatching rSocketCommandsRegistry.execute(container.await(), request) ?: throw UnsupportedException("This type of request is not supported in RSocket engine.") } diff --git a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/AuthMappers.kt b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/AuthMappers.kt index dc1480f..b6bf406 100644 --- a/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/AuthMappers.kt +++ b/rsocket-engine/src/main/kotlin/io/timemates/api/rsocket/authorizations/AuthMappers.kt @@ -7,6 +7,7 @@ import io.timemates.sdk.authorization.sessions.types.value.ClientVersion import io.timemates.sdk.authorization.types.value.AccessHash import io.timemates.sdk.authorization.types.value.HashValue import io.timemates.sdk.common.constructor.createOrThrow +import io.timemates.sdk.users.profile.types.value.UserId import kotlinx.datetime.Instant import io.timemates.api.authorizations.types.Authorization as RSAuthorization import io.timemates.sdk.authorization.sessions.types.Authorization as SdkAuth @@ -32,6 +33,7 @@ internal fun RSAuthorization.sdk(): SdkAuth { refreshHash = refreshHash?.let { SdkAuth.Hash(HashValue.createOrThrow(it.value), Instant.fromEpochMilliseconds(it.expiresAt)) }, generationTime = Instant.fromEpochMilliseconds(generationTime), metadata = metadata?.sdk(), + userId = UserId.createOrThrow(userId), ) } diff --git a/rsocket-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto index cd585d9..a7908e3 100644 --- a/rsocket-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto +++ b/rsocket-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto @@ -29,6 +29,11 @@ message Authorization { */ optional Metadata metadata = 5; + /** + * Owner's id. + */ + int64 userId = 6; + message Hash { string value = 1; int64 expiresAt = 2; diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/Authorization.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/Authorization.kt index d10796a..f956ac5 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/Authorization.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/authorization/sessions/types/Authorization.kt @@ -5,13 +5,15 @@ import io.timemates.sdk.authorization.sessions.types.value.ClientIpAddress import io.timemates.sdk.authorization.sessions.types.value.ClientVersion import io.timemates.sdk.authorization.types.value.HashValue import io.timemates.sdk.common.types.TimeMatesEntity +import io.timemates.sdk.users.profile.types.value.UserId import kotlinx.datetime.Instant public data class Authorization( val accessHash: Hash?, val refreshHash: Hash?, val generationTime: Instant, - val metadata: Metadata? + val metadata: Metadata?, + val userId: UserId, ) : TimeMatesEntity() { public data class Hash( val value: HashValue, diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/providers/AccessHashProvider.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/providers/AccessHashProvider.kt index 83b8b23..ae80877 100644 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/providers/AccessHashProvider.kt +++ b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/providers/AccessHashProvider.kt @@ -6,7 +6,7 @@ import io.timemates.sdk.common.exceptions.UnauthorizedException /** * Interface for providing access token hashes. */ -public interface AccessHashProvider { +public fun interface AccessHashProvider { /** * Retrieves the access hash or null if not available. * @return The [AccessHash] or null.