-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
668 aspect oriented middleware #669
Open
ValdemarGr
wants to merge
9
commits into
typelevel:main
Choose a base branch
from
ValdemarGr:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0b639fc
initial work an aspects
ValdemarGr 2aa969e
more work
ValdemarGr e00ab12
dsl
ValdemarGr 8b954b2
generalize effect type
ValdemarGr dc5e409
work on api consistency
ValdemarGr 7f574db
removed req/res typeclasses
ValdemarGr 113bab3
test resource
ValdemarGr 584c51a
very big test
ValdemarGr 8f9b947
tracing test done
ValdemarGr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ fileOverride { | |
"glob:**/scala-3/**" { | ||
runner.dialect = scala3 | ||
} | ||
} | ||
} |
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
101 changes: 101 additions & 0 deletions
101
runtime/src/main/scala/fs2/grpc/client/ClientAspect.scala
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,101 @@ | ||
package fs2.grpc.client | ||
|
||
import io.grpc._ | ||
import cats._ | ||
import cats.syntax.all._ | ||
import fs2.Stream | ||
|
||
final case class ClientCallContext[Req, Res, Dom[_], Cod[_], A]( | ||
ctx: A, | ||
methodDescriptor: MethodDescriptor[Req, Res], | ||
dom: Dom[Req], | ||
cod: Cod[Res] | ||
) | ||
|
||
trait ClientAspect[F[_], Dom[_], Cod[_], A] { self => | ||
def visitUnaryToUnary[Req, Res]( | ||
callCtx: ClientCallContext[Req, Res, Dom, Cod, A], | ||
req: Req, | ||
request: (Req, Metadata) => F[Res] | ||
): F[Res] | ||
|
||
def visitUnaryToStreaming[Req, Res]( | ||
callCtx: ClientCallContext[Req, Res, Dom, Cod, A], | ||
req: Req, | ||
request: (Req, Metadata) => Stream[F, Res] | ||
): Stream[F, Res] | ||
|
||
def visitStreamingToUnary[Req, Res]( | ||
callCtx: ClientCallContext[Req, Res, Dom, Cod, A], | ||
req: Stream[F, Req], | ||
request: (Stream[F, Req], Metadata) => F[Res] | ||
): F[Res] | ||
|
||
def visitStreamingToStreaming[Req, Res]( | ||
callCtx: ClientCallContext[Req, Res, Dom, Cod, A], | ||
req: Stream[F, Req], | ||
request: (Stream[F, Req], Metadata) => Stream[F, Res] | ||
): Stream[F, Res] | ||
|
||
def contraModify[B](f: B => F[A])(implicit F: Monad[F]): ClientAspect[F, Dom, Cod, B] = | ||
new ClientAspect[F, Dom, Cod, B] { | ||
def modCtx[Req, Res](ccc: ClientCallContext[Req, Res, Dom, Cod, B]): F[ClientCallContext[Req, Res, Dom, Cod, A]] = | ||
f(ccc.ctx).map(a => ccc.copy(ctx = a)) | ||
|
||
override def visitUnaryToUnary[Req, Res]( | ||
callCtx: ClientCallContext[Req, Res, Dom, Cod, B], | ||
req: Req, | ||
request: (Req, Metadata) => F[Res] | ||
): F[Res] = | ||
modCtx(callCtx).flatMap(self.visitUnaryToUnary(_, req, request)) | ||
|
||
override def visitUnaryToStreaming[Req, Res]( | ||
callCtx: ClientCallContext[Req, Res, Dom, Cod, B], | ||
req: Req, | ||
request: (Req, Metadata) => Stream[F, Res] | ||
): Stream[F, Res] = | ||
Stream.eval(modCtx(callCtx)).flatMap(self.visitUnaryToStreaming(_, req, request)) | ||
|
||
override def visitStreamingToUnary[Req, Res]( | ||
callCtx: ClientCallContext[Req, Res, Dom, Cod, B], | ||
req: Stream[F, Req], | ||
request: (Stream[F, Req], Metadata) => F[Res] | ||
): F[Res] = | ||
modCtx(callCtx).flatMap(self.visitStreamingToUnary(_, req, request)) | ||
|
||
override def visitStreamingToStreaming[Req, Res]( | ||
callCtx: ClientCallContext[Req, Res, Dom, Cod, B], | ||
req: Stream[F, Req], | ||
request: (Stream[F, Req], Metadata) => Stream[F, Res] | ||
): Stream[F, Res] = | ||
Stream.eval(modCtx(callCtx)).flatMap(self.visitStreamingToStreaming(_, req, request)) | ||
} | ||
} | ||
|
||
object ClientAspect { | ||
def default[F[_], Dom[_], Cod[_]] = new ClientAspect[F, Dom, Cod, Metadata] { | ||
override def visitUnaryToUnary[Req, Res]( | ||
callCtx: ClientCallContext[Req, Res, Dom, Cod, Metadata], | ||
req: Req, | ||
request: (Req, Metadata) => F[Res] | ||
): F[Res] = request(req, callCtx.ctx) | ||
|
||
override def visitUnaryToStreaming[Req, Res]( | ||
callCtx: ClientCallContext[Req, Res, Dom, Cod, Metadata], | ||
req: Req, | ||
request: (Req, Metadata) => Stream[F, Res] | ||
): Stream[F, Res] = request(req, callCtx.ctx) | ||
|
||
override def visitStreamingToUnary[Req, Res]( | ||
callCtx: ClientCallContext[Req, Res, Dom, Cod, Metadata], | ||
req: Stream[F, Req], | ||
request: (Stream[F, Req], Metadata) => F[Res] | ||
): F[Res] = request(req, callCtx.ctx) | ||
|
||
override def visitStreamingToStreaming[Req, Res]( | ||
callCtx: ClientCallContext[Req, Res, Dom, Cod, Metadata], | ||
req: Stream[F, Req], | ||
request: (Stream[F, Req], Metadata) => Stream[F, Res] | ||
): Stream[F, Res] = request(req, callCtx.ctx) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected?