Skip to content

Commit

Permalink
fix&refactor&chore: fix build errors, server metadata service is rena…
Browse files Browse the repository at this point in the history
…med to schema service and also reworked, small improvements
  • Loading branch information
y9vad9 committed Oct 16, 2024
1 parent 3bf9b10 commit 1e68503
Show file tree
Hide file tree
Showing 130 changed files with 2,536 additions and 1,022 deletions.
10 changes: 5 additions & 5 deletions build-conventions/src/main/kotlin/library-convention.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

mavenPublishing {
pom {
url.set("https://github.com/rrpcroto/rrpc-kotlin")
url.set("https://github.com/RRpc/rrpc-kotlin")
inceptionYear.set("2023")

licenses {
Expand All @@ -24,14 +24,14 @@ mavenPublishing {
}

scm {
url.set("https://github.com/rrpcroto/rrpc-kotlin")
connection.set("scm:git:git://github.com/rrpcroto/rrpc-kotlin.git")
developerConnection.set("scm:git:ssh://git@github.com/rrpcroto/rrpc-kotlin.git")
url.set("https://github.com/RRpc/rrpc-kotlin")
connection.set("scm:git:git://github.com/RRpc/rrpc-kotlin.git")
developerConnection.set("scm:git:ssh://git@github.com/RRpc/rrpc-kotlin.git")
}

issueManagement {
system.set("GitHub Issues")
url.set("https://github.com/rrpcroto/rrpc-kotlin/issues")
url.set("https://github.com/RRpc/rrpc-kotlin/issues")
}
}
}
Expand Down
20 changes: 14 additions & 6 deletions client/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ group = "org.timemates.rrpc"
version = System.getenv("LIB_VERSION") ?: "SNAPSHOT"

dependencies {
commonMainImplementation(libs.rsocket.client)
commonMainApi(projects.common.core)
dependencies {
// -- Project --
commonMainImplementation(projects.common.core)

// -- RSocket --
commonMainApi(libs.rsocket.client)

// -- Test --
jvmTestImplementation(libs.kotlin.test)
jvmTestImplementation(libs.mockk)
}

jvmTestImplementation(libs.kotlin.test)
jvmTestImplementation(libs.mockk)
}

kotlin {
jvm()
// js(IR) {
// browser()
// nodejs()
Expand All @@ -32,7 +40,7 @@ mavenPublishing {
)

pom {
name.set("RRpcroto Client Core")
description.set("Multiplatform Kotlin core library for RRpcroto clients.")
name.set("RRpc Client Core")
description.set("Multiplatform Kotlin core library for RRpc clients.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.*
import kotlinx.serialization.*
import org.timemates.rrpc.*
import org.timemates.rrpc.annotations.ExperimentalInterceptorsApi
import org.timemates.rrpc.annotations.InternalRRpcrotoAPI
import org.timemates.rrpc.annotations.InternalRRpcAPI
import org.timemates.rrpc.client.config.RRpcClientConfig
import org.timemates.rrpc.instances.protobuf
import org.timemates.rrpc.interceptors.InterceptorContext
Expand All @@ -23,7 +23,7 @@ import org.timemates.rrpc.options.OptionsWithValue
*
* @property config The configuration for the RRpc client.
*/
@InternalRRpcrotoAPI
@InternalRRpcAPI
public class ClientRequestHandler(
private val config: RRpcClientConfig,
) {
Expand All @@ -39,7 +39,7 @@ public class ClientRequestHandler(
* @param deserializationStrategy Deserialization strategy for the response data.
* @return The response data.
*/
@OptIn(InternalRRpcrotoAPI::class)
@OptIn(InternalRRpcAPI::class)
public suspend fun <T : Any, R : Any> requestResponse(
metadata: ClientMetadata,
data: T,
Expand Down Expand Up @@ -111,7 +111,7 @@ public class ClientRequestHandler(
* @param deserializationStrategy Deserialization strategy for the response data.
* @return A flow of the response data.
*/
@OptIn(InternalRRpcrotoAPI::class)
@OptIn(InternalRRpcAPI::class)
public fun <T : Any, R : Any> requestStream(
metadata: ClientMetadata,
data: T,
Expand Down Expand Up @@ -154,7 +154,7 @@ public class ClientRequestHandler(
* @param deserializationStrategy Deserialization strategy for the response data.
* @return A flow of the response data.
*/
@OptIn(InternalRRpcrotoAPI::class)
@OptIn(InternalRRpcAPI::class)
public fun <T : Any, R : Any> requestChannel(
metadata: ClientMetadata,
data: Flow<T>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@file:OptIn(InternalRRpcrotoAPI::class)
@file:OptIn(InternalRRpcAPI::class)

package org.timemates.rrpc.client

import org.timemates.rrpc.annotations.InternalRRpcrotoAPI
import org.timemates.rrpc.annotations.InternalRRpcAPI
import org.timemates.rrpc.client.config.RRpcClientConfig
import org.timemates.rrpc.client.options.RPCsOptions

/**
* The abstraction for the clients that are generated by `rrpcroto`.
* The abstraction for the clients that are generated by `RRpc`.
*/
public abstract class RRpcServiceClient(
config: RRpcClientConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package org.timemates.rrpc.client.config
import io.rsocket.kotlin.RSocket
import kotlinx.serialization.ExperimentalSerializationApi
import org.timemates.rrpc.annotations.ExperimentalInterceptorsApi
import org.timemates.rrpc.annotations.InternalRRpcrotoAPI
import org.timemates.rrpc.annotations.InternalRRpcAPI
import org.timemates.rrpc.instances.*
import org.timemates.rrpc.interceptors.Interceptor
import org.timemates.rrpc.interceptors.Interceptors
Expand Down Expand Up @@ -122,7 +122,7 @@ public data class RRpcClientConfig @OptIn(ExperimentalInterceptorsApi::class) co
/**
* Appends the provided in the [builder] instances to existing ones.
*/
@OptIn(InternalRRpcrotoAPI::class)
@OptIn(InternalRRpcAPI::class)
public fun instances(builder: InstancesBuilder.() -> Unit): Builder = apply {
val instances = InstancesBuilder().apply(builder).build()
instances(instances)
Expand Down
2 changes: 2 additions & 0 deletions client/schema/README.md
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).
43 changes: 43 additions & 0 deletions client/schema/build.gradle.kts
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.")
}
}
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()),
)
}
}
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?>)
}
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)) }
Loading

0 comments on commit 1e68503

Please sign in to comment.