generated from y9vad9/kotlin-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix&refactor&chore: fix build errors, server metadata service is rena…
…med to schema service and also reworked, small improvements
- Loading branch information
Showing
130 changed files
with
2,536 additions
and
1,022 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
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
6 changes: 3 additions & 3 deletions
6
...timemates/rrpc/client/RSPServiceClient.kt → ...imemates/rrpc/client/RRpcServiceClient.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
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,2 @@ | ||
# Server Schema Client | ||
This module is used to communicate with [server-schema](../../server/schema). |
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,43 @@ | ||
plugins { | ||
id(libs.plugins.conventions.multiplatform.library.get().pluginId) | ||
alias(libs.plugins.kotlinx.serialization) | ||
} | ||
|
||
group = "org.timemates.rrpc" | ||
version = System.getenv("LIB_VERSION") ?: "SNAPSHOT" | ||
|
||
dependencies { | ||
// -- Project -- | ||
commonMainImplementation(projects.common.core) | ||
commonMainImplementation(projects.common.schema) | ||
commonMainImplementation(projects.client.core) | ||
|
||
// -- Test -- | ||
jvmTestImplementation(libs.kotlin.test) | ||
jvmTestImplementation(libs.mockk) | ||
} | ||
|
||
|
||
kotlin { | ||
jvm() | ||
// js(IR) { | ||
// browser() | ||
// nodejs() | ||
// } | ||
// iosArm64() | ||
// iosX64() | ||
// iosSimulatorArm64() | ||
} | ||
|
||
mavenPublishing { | ||
coordinates( | ||
groupId = "org.timemates.rrpc", | ||
artifactId = "server-metadata-client", | ||
version = System.getenv("LIB_VERSION") ?: return@mavenPublishing, | ||
) | ||
|
||
pom { | ||
name.set("RRpc Server Metadata Client") | ||
description.set("Multiplatform Kotlin Library for working with Server Metadata.") | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
client/schema/src/commonMain/kotlin/org/timemates/rrpc/client/schema/SchemaClient.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,127 @@ | ||
package org.timemates.rrpc.client.schema | ||
|
||
import org.timemates.rrpc.annotations.InternalRRpcAPI | ||
import org.timemates.rrpc.client.RRpcServiceClient | ||
import org.timemates.rrpc.client.config.RRpcClientConfig | ||
import org.timemates.rrpc.client.options.RPCsOptions | ||
import org.timemates.rrpc.client.schema.request.PagedRequest | ||
import org.timemates.rrpc.common.schema.RMFile | ||
import org.timemates.rrpc.common.schema.RMService | ||
import org.timemates.rrpc.metadata.ClientMetadata | ||
import org.timemates.rrpc.options.OptionsWithValue | ||
import org.timemates.rrpc.client.schema.request.BatchedRequest | ||
import org.timemates.rrpc.common.schema.RMExtend | ||
import org.timemates.rrpc.common.schema.RMType | ||
import io.rsocket.kotlin.RSocketError | ||
|
||
/** | ||
* A client to interact with the `SchemaService` of the server, which provides metadata about | ||
* available services, types, and extensions. This client sends requests to the server and | ||
* receives the corresponding responses using the RSocket-based communication framework. | ||
* | ||
* @param config The configuration for the `RRpcServiceClient`, which defines connection settings. | ||
*/ | ||
@OptIn(InternalRRpcAPI::class) | ||
public class SchemaClient( | ||
config: RRpcClientConfig, | ||
) : RRpcServiceClient(config) { | ||
|
||
public companion object { | ||
private const val SERVICE_NAME: String = "timemates.rrpc.server.schema.SchemaService" | ||
} | ||
|
||
/** | ||
* Creates an instance of the client using a configuration builder. | ||
* | ||
* @param creator A lambda to configure and build the `RRpcClientConfig` object. | ||
*/ | ||
public constructor( | ||
creator: RRpcClientConfig.Builder.() -> Unit, | ||
) : this(RRpcClientConfig.create(creator)) | ||
|
||
override val rpcsOptions: RPCsOptions = RPCsOptions.EMPTY | ||
|
||
/** | ||
* Fetches a paged list of available services from the server. | ||
* | ||
* @param request A [PagedRequest] defining pagination settings. | ||
* @return A [PagedRequest.Response] containing a list of [RMService] and the next page token. | ||
* | ||
* @throws RSocketError if the request fails. | ||
*/ | ||
public suspend fun getAvailableServices(request: PagedRequest): PagedRequest.Response<RMService> { | ||
return handler.requestResponse( | ||
metadata = ClientMetadata( | ||
serviceName = SERVICE_NAME, | ||
procedureName = "GetAvailableServices", | ||
), | ||
data = request, | ||
options = OptionsWithValue.EMPTY, | ||
serializationStrategy = PagedRequest.serializer(), | ||
deserializationStrategy = PagedRequest.Response.serializer(RMService.serializer()), | ||
) | ||
} | ||
|
||
/** | ||
* Fetches a paged list of available files from the server. | ||
* | ||
* @param request A [PagedRequest] specifying pagination options. | ||
* @return A [PagedRequest.Response] containing a list of [RMFile] and the next page token. | ||
* | ||
* @throws RSocketError if the request fails. | ||
*/ | ||
public suspend fun getAvailableFiles(request: PagedRequest): PagedRequest.Response<RMFile> { | ||
return handler.requestResponse( | ||
metadata = ClientMetadata( | ||
serviceName = SERVICE_NAME, | ||
procedureName = "GetAvailableFiles", | ||
), | ||
data = request, | ||
options = OptionsWithValue.EMPTY, | ||
serializationStrategy = PagedRequest.serializer(), | ||
deserializationStrategy = PagedRequest.Response.serializer(RMFile.serializer()), | ||
) | ||
} | ||
|
||
/** | ||
* Retrieves detailed information about multiple types in a batched request. | ||
* | ||
* @param request A [BatchedRequest] containing a list of [RMDeclarationUrl]s for the requested types. | ||
* @return A [BatchedRequest.Response] containing a map of each requested [RMDeclarationUrl] to its associated [RMType]. | ||
* | ||
* @throws RSocketError if the request fails. | ||
*/ | ||
public suspend fun getTypeDetailsBatch(request: BatchedRequest): BatchedRequest.Response<RMType> { | ||
return handler.requestResponse( | ||
metadata = ClientMetadata( | ||
serviceName = SERVICE_NAME, | ||
procedureName = "GetTypeDetailsBatch", | ||
), | ||
data = request, | ||
options = OptionsWithValue.EMPTY, | ||
serializationStrategy = BatchedRequest.serializer(), | ||
deserializationStrategy = BatchedRequest.Response.serializer(RMType.serializer()), | ||
) | ||
} | ||
|
||
/** | ||
* Retrieves detailed information about multiple extensions in a batched request. | ||
* | ||
* @param request A [BatchedRequest] containing a list of [RMDeclarationUrl]s for the requested extensions. | ||
* @return A [BatchedRequest.Response] containing a map of each requested [RMDeclarationUrl] to its associated [RMExtend]. | ||
* | ||
* @throws RSocketError if the request fails. | ||
*/ | ||
public suspend fun getExtendDetailsBatch(request: BatchedRequest): BatchedRequest.Response<RMExtend> { | ||
return handler.requestResponse( | ||
metadata = ClientMetadata( | ||
serviceName = SERVICE_NAME, | ||
procedureName = "GetExtendDetailsBatch", | ||
), | ||
data = request, | ||
options = OptionsWithValue.EMPTY, | ||
serializationStrategy = BatchedRequest.serializer(), | ||
deserializationStrategy = BatchedRequest.Response.serializer(RMExtend.serializer()), | ||
) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...t/schema/src/commonMain/kotlin/org/timemates/rrpc/client/schema/request/BatchedRequest.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,22 @@ | ||
package org.timemates.rrpc.client.schema.request | ||
|
||
import kotlinx.serialization.Serializable | ||
import org.timemates.rrpc.common.schema.RMNode | ||
import org.timemates.rrpc.common.schema.value.RMDeclarationUrl | ||
|
||
/** | ||
* Represents a batched request to retrieve multiple metadata entities by their declaration URLs. | ||
* | ||
* @property urls A list of RMDeclarationUrl objects, representing the metadata to retrieve. | ||
*/ | ||
@Serializable | ||
public data class BatchedRequest(val urls: List<RMDeclarationUrl>) { | ||
/** | ||
* Response structure for batched requests. | ||
* Contains a map of RMDeclarationUrl to the corresponding resolved metadata (or null if not found). | ||
* | ||
* @param results A map where each RMDeclarationUrl is associated with the corresponding RMNode (or null if not found). | ||
*/ | ||
@Serializable | ||
public data class Response<R : RMNode>(public val services: Map<RMDeclarationUrl, R?>) | ||
} |
40 changes: 40 additions & 0 deletions
40
client/schema/src/commonMain/kotlin/org/timemates/rrpc/client/schema/request/PagedRequest.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,40 @@ | ||
package org.timemates.rrpc.client.schema.request | ||
|
||
import kotlinx.serialization.Serializable | ||
import kotlin.io.encoding.Base64 | ||
import kotlin.io.encoding.ExperimentalEncodingApi | ||
|
||
/** | ||
* Represents a paginated request to retrieve metadata entities. | ||
* | ||
* @property cursor A token used for retrieving the next page of results. | ||
* @property size The maximum number of results to retrieve per page. | ||
*/ | ||
@Serializable | ||
public data class PagedRequest( | ||
public val cursor: String? = null, | ||
public val size: Int? = null, | ||
) { | ||
public companion object { | ||
@OptIn(ExperimentalEncodingApi::class) | ||
internal fun encoded(string: String): String { | ||
return Base64.encode(string.toByteArray()) | ||
} | ||
} | ||
|
||
/** | ||
* Response structure for paginated requests. | ||
* Contains the list of metadata nodes retrieved and a token for the next page. | ||
* | ||
* @param list A list of RMNode objects representing the metadata retrieved. | ||
* @param nextCursor A token to retrieve the next page of results, or null if no more results. | ||
*/ | ||
@Serializable | ||
public data class Response<T>( | ||
public val list: List<T>, | ||
public val nextCursor: String?, | ||
) | ||
} | ||
|
||
@OptIn(ExperimentalEncodingApi::class) | ||
internal fun PagedRequest.decoded(): String? = this@decoded.cursor?.let { String(Base64.decode(it)) } |
Oops, something went wrong.