Skip to content

Commit 3821de8

Browse files
committed
Add some scaladocs
1 parent 903ab82 commit 3821de8

File tree

6 files changed

+93
-1
lines changed

6 files changed

+93
-1
lines changed

modules/core/src/main/scala/jsonrpclib/Endpoint.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,28 @@ import io.circe.Decoder
44
import io.circe.Encoder
55
import jsonrpclib.ErrorCodec.errorPayloadCodec
66

7+
/** Represents a JSON-RPC method handler that can be invoked by the server.
8+
*
9+
* An `Endpoint[F]` defines how to decode input from a JSON-RPC message, execute some effectful logic, and optionally
10+
* return a response.
11+
*
12+
* The endpoint's `method` field is used to match incoming JSON-RPC requests.
13+
*/
714
sealed trait Endpoint[F[_]] {
15+
16+
/** The JSON-RPC method name this endpoint responds to. Used for dispatching incoming requests. */
817
def method: String
918

19+
/** Transforms the effect type of this endpoint using the provided `PolyFunction`.
20+
*
21+
* This allows reinterpreting the endpoint’s logic in a different effect context (e.g., from `IO` to `Kleisli[IO,
22+
* Ctx, *]`, or from `F` to `EitherT[F, E, *]`).
23+
*
24+
* @param f
25+
* A polymorphic function that transforms `F[_]` into `G[_]`
26+
* @return
27+
* A new `Endpoint[G]` with the same behavior but in a new effect type
28+
*/
1029
def mapK[G[_]](f: PolyFunction[F, G]): Endpoint[G]
1130
}
1231

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package jsonrpclib
22

3+
/** A polymorphic natural transformation from `F[_]` to `G[_]`.
4+
*
5+
* @tparam F
6+
* Source effect type
7+
* @tparam G
8+
* Target effect type
9+
*/
310
trait PolyFunction[F[_], G[_]] { self =>
411
def apply[A0](fa: => F[A0]): G[A0]
512
}

modules/fs2/src/main/scala/jsonrpclib/fs2/FS2Channel.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ import scala.util.Try
1919
import _root_.fs2.Pipe
2020
import _root_.fs2.Stream
2121

22+
/** A JSON-RPC communication channel built on top of `fs2.Stream`.
23+
*
24+
* `FS2Channel[F]` enables streaming JSON-RPC messages into and out of an effectful system. It provides methods to
25+
* register handlers (`Endpoint[F]`) for specific method names.
26+
*
27+
* This is the primary server-side integration point for using JSON-RPC over FS2.
28+
*/
2229
trait FS2Channel[F[_]] extends Channel[F] {
2330

2431
def input: Pipe[F, Message, Unit]
@@ -49,6 +56,20 @@ trait FS2Channel[F[_]] extends Channel[F] {
4956

5057
object FS2Channel {
5158

59+
/** Creates a new `FS2Channel[F]` as a managed resource with a configurable buffer size for bidirectional message
60+
* processing.
61+
*
62+
* Optionally, a `CancelTemplate` can be provided to support client-initiated cancellation of inflight requests via a
63+
* dedicated cancellation endpoint.
64+
*
65+
* @param bufferSize
66+
* Size of the internal outbound message queue (default: 2048)
67+
* @param cancelTemplate
68+
* Optional handler that defines how to decode and handle cancellation requests
69+
*
70+
* @return
71+
* A `Resource` that manages the lifecycle of the channel and its internal supervisor
72+
*/
5273
def resource[F[_]: Concurrent](
5374
bufferSize: Int = 2048,
5475
cancelTemplate: Option[CancelTemplate] = None

modules/smithy4s/src/main/scala/jsonrpclib/smithy4sinterop/CirceJsonCodec.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import smithy4s.Schema
88

99
object CirceJsonCodec {
1010

11+
/** Creates a Circe `Codec[A]` from a Smithy4s `Schema[A]`.
12+
*
13+
* This enables encoding values of type `A` to JSON and decoding JSON back into `A`, using the structure defined by
14+
* the Smithy schema.
15+
*/
1116
def fromSchema[A](implicit schema: Schema[A]): Codec[A] = Codec.from(
1217
c => {
1318
c.as[Json]

modules/smithy4s/src/main/scala/jsonrpclib/smithy4sinterop/ClientStub.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ import smithy4s.ShapeId
1010

1111
object ClientStub {
1212

13+
/** Creates a JSON-RPC client implementation for a Smithy service.
14+
*
15+
* Given a Smithy `Service[Alg]` and a JSON-RPC communication `Channel[F]`, this constructs a fully functional client
16+
* that translates method calls into JSON-RPC messages sent over the channel.
17+
*
18+
* Usage:
19+
* {{{
20+
* val stub: MyService[IO] = ClientStub(myService, myChannel)
21+
* val response: IO[String] = stub.hello("world")
22+
* }}}
23+
*
24+
* Supports both standard request-response and fire-and-forget notification endpoints.
25+
*/
1326
def apply[Alg[_[_, _, _, _, _]], F[_]: Monadic](service: Service[Alg], channel: Channel[F]): service.Impl[F] =
1427
new ClientStub(service, channel).compile
1528
}

modules/smithy4s/src/main/scala/jsonrpclib/smithy4sinterop/ServerEndpoints.scala

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ import _root_.smithy4s.{Endpoint => Smithy4sEndpoint}
1616

1717
object ServerEndpoints {
1818

19+
/** Creates JSON-RPC server endpoints from a Smithy service implementation.
20+
*
21+
* Given a Smithy `FunctorAlgebra[Alg, F]`, this extracts all operations and compiles them into JSON-RPC
22+
* `Endpoint[F]` handlers that can be mounted on a communication channel (e.g. `FS2Channel`).
23+
*
24+
* Supports both standard request-response and notification-style endpoints, as well as Smithy-modeled errors.
25+
*
26+
* Usage:
27+
* {{{
28+
* val endpoints = ServerEndpoints(new ServerImpl)
29+
* channel.withEndpoints(endpoints)
30+
* }}}
31+
*/
1932
def apply[Alg[_[_, _, _, _, _]], F[_]](
2033
impl: FunctorAlgebra[Alg, F]
2134
)(implicit service: Service[Alg], F: Monadic[F]): List[Endpoint[F]] = {
@@ -30,7 +43,21 @@ object ServerEndpoints {
3043
}
3144
}
3245

33-
def jsonRPCEndpoint[F[_]: Monadic, Op[_, _, _, _, _], I, E, O, SI, SO](
46+
/** Constructs a JSON-RPC endpoint from a Smithy endpoint definition.
47+
*
48+
* Translates a single Smithy4s endpoint into a JSON-RPC `Endpoint[F]`, based on the method name and interaction type
49+
* described in `EndpointSpec`.
50+
*
51+
* @param smithy4sEndpoint
52+
* The Smithy4s endpoint to expose over JSON-RPC
53+
* @param endpointSpec
54+
* JSON-RPC method name and interaction hints
55+
* @param impl
56+
* Interpreter that executes the Smithy operation in `F`
57+
* @return
58+
* A JSON-RPC-compatible `Endpoint[F]`
59+
*/
60+
private def jsonRPCEndpoint[F[_]: Monadic, Op[_, _, _, _, _], I, E, O, SI, SO](
3461
smithy4sEndpoint: Smithy4sEndpoint[Op, I, E, O, SI, SO],
3562
endpointSpec: EndpointSpec,
3663
impl: FunctorInterpreter[Op, F]

0 commit comments

Comments
 (0)