generated from y9vad9/kotlin-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
138 changed files
with
2,198 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
20 changes: 20 additions & 0 deletions
20
rsocket-engine/src/commonMain/kotlin/io/timemates/api/rsocket/CommandsRegistry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
58 changes: 58 additions & 0 deletions
58
...t-engine/src/commonMain/kotlin/io/timemates/api/rsocket/RSocketTimeMatesRequestsEngine.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <T : TimeMatesEntity> execute( | ||
request: TimeMatesRequest<T>, | ||
): Result<T> = runCatching { | ||
val rSocket = rSocket.await() | ||
return@runCatching rSocketCommandsRegistry.execute(rSocket, request) | ||
?: throw UnsupportedException("This type of request is not supported in RSocket engine.") | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../kotlin/io/timemates/api/rsocket/authorizations/commands/AuthorizationCommandsRegistry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
25 changes: 25 additions & 0 deletions
25
...ain/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfigureNewAccountCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ConfigureNewAccountRequest, ConfigureNewAccountRequest.Result> { | ||
override suspend fun execute(rSocket: RSocket, input: ConfigureNewAccountRequest): ConfigureNewAccountRequest.Result { | ||
return rSocket.requestResponse<RSocketConfigureAccountRequest, RSocketConfigureAccountRequest.Result>( | ||
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() | ||
) | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...in/kotlin/io/timemates/api/rsocket/authorizations/commands/ConfirmAuthorizationCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ConfirmAuthorizationRequest, ConfirmAuthorizationRequest.Result> { | ||
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(), | ||
) | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...otlin/io/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<GetAuthorizationSessionsRequest, Page<Authorization>> { | ||
override suspend fun execute(rSocket: RSocket, input: GetAuthorizationSessionsRequest): Page<Authorization> { | ||
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) } | ||
) | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...Main/kotlin/io/timemates/api/rsocket/authorizations/commands/RenewAuthorizationCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<RenewAuthorizationRequest, RenewAuthorizationRequest.Result> { | ||
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) | ||
) | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...Main/kotlin/io/timemates/api/rsocket/authorizations/commands/StartAuthorizationCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<StartAuthorizationRequest, StartAuthorizationRequest.Result> { | ||
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), | ||
) | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../io/timemates/api/rsocket/authorizations/commands/TerminateCurrentAuthorizationCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TerminateCurrentAuthorizationSessionRequest, Empty> { | ||
override suspend fun execute(rSocket: RSocket, input: TerminateCurrentAuthorizationSessionRequest): Empty { | ||
return rSocket.requestResponse( | ||
route = "authorizations.terminate", | ||
data = TerminateAuthorizationRequest.Current, | ||
accessHash = input.accessHash.string, | ||
).let { _ -> Empty } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...onMain/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfigureAccountRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ConfigureAccountRequest.Result> { | ||
@Serializable | ||
data class Result( | ||
val authorization: SerializableAuthorization, | ||
) | ||
} |
16 changes: 16 additions & 0 deletions
16
...in/kotlin/io/timemates/api/rsocket/authorizations/requests/ConfirmAuthorizationRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ConfirmAuthorizationRequest.Response> { | ||
data class Response( | ||
val isNewAccount: Boolean, | ||
val authorization: SerializableAuthorization?, | ||
) | ||
} |
Oops, something went wrong.