Skip to content

Commit

Permalink
Housekeeping (#3111)
Browse files Browse the repository at this point in the history
  • Loading branch information
987Nabil authored Sep 8, 2024
1 parent c9dad3c commit 22caa5a
Show file tree
Hide file tree
Showing 73 changed files with 120 additions and 184 deletions.
40 changes: 18 additions & 22 deletions sbt-zio-http-grpc/src/main/scala/zio/http/grpc/ZIOHttpGRPCGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ import scala.jdk.CollectionConverters._
import zio.http.gen.grpc._
import zio.http.gen.scala.{Code, CodeGen}

import com.google.protobuf._
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse
import com.google.protobuf.{Descriptors, ExtensionRegistry}
import protocgen.{CodeGenApp, CodeGenRequest, CodeGenResponse}
import scalapb.compiler.{DescriptorImplicits, ProtobufGenerator}
import scalapb.options.Scalapb
import scalapb.compiler._

object ZIOHttpGRPCGen extends CodeGenApp {

def process(request: CodeGenRequest): CodeGenResponse =
ProtobufGenerator.parseParameters(request.parameter) match {
case Right(_) =>
val services = request.filesToGenerate.flatMap(fromProtobuf(_).files)
val schemas = services.map(getImplicitSchemas(_)).map { case (pkg, tpes) =>
val schemas = services.map(getImplicitSchemas).map { case (pkg, tpes) =>
schemasFile(pkg, tpes)
}
CodeGenResponse.succeed(
schemas ++ services.map(fileToPluginCode(_)),
schemas ++ services.map(fileToPluginCode),
Set(CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL),
)
case Left(error) =>
Expand Down Expand Up @@ -55,7 +54,7 @@ object ZIOHttpGRPCGen extends CodeGenApp {
val content =
s"package ${pkg.mkString(".")} \nobject Schemas {\n" +
"import zio.schema.{DeriveSchema, Schema}\n" +
tpes.distinct.map(tpeToSchema(_)).mkString("") +
tpes.distinct.map(tpeToSchema).mkString("") +
"\n}"
b.setContent(content)
b.build
Expand All @@ -66,39 +65,36 @@ object ZIOHttpGRPCGen extends CodeGenApp {
}

def fromDescriptor(file: Descriptors.FileDescriptor): Protobuf.File = {
val deps = file
.getDependencies()
.asScala
.toList
val deps = file.getDependencies.asScala.toList
.map(_.getName())
val opt = file.getOptions()
val pkg = if (opt.hasJavaPackage() && opt.getJavaPackage() != "") opt.getJavaPackage() else file.getPackage()
val opt = file.getOptions
val pkg = if (opt.hasJavaPackage && opt.getJavaPackage != "") opt.getJavaPackage else file.getPackage
val pkgPath = if (pkg == "") Nil else pkg.split('.').toList
val name0 =
if (opt.hasJavaOuterClassname() && opt.getJavaOuterClassname() != "") opt.getJavaOuterClassname()
else file.getName()
if (opt.hasJavaOuterClassname && opt.getJavaOuterClassname != "") opt.getJavaOuterClassname
else file.getName
val name = if (name0.endsWith(".proto")) name0.dropRight(6) else name0

def fromService(service: Descriptors.ServiceDescriptor): Protobuf.Service =
Protobuf.Service(
service.getName(),
service.getMethods.asScala.toList.map(fromMethod(_)),
service.getName,
service.getMethods.asScala.toList.map(fromMethod),
)

def fromMethod(method: Descriptors.MethodDescriptor): Protobuf.Method =
Protobuf.Method(
method.getName(),
method.getInputType().getName(),
method.getOutputType().getName(),
method.isClientStreaming(),
method.isServerStreaming(),
method.getName,
method.getInputType.getName,
method.getOutputType.getName,
method.isClientStreaming,
method.isServerStreaming,
)

Protobuf.File(
name,
pkgPath,
deps,
file.getServices().asScala.toList.map(fromService(_)),
file.getServices.asScala.toList.map(fromService),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package zio.benchmarks

import java.util.concurrent.TimeUnit

import zio.{Trace, Unsafe}

import zio.http._

import org.openjdk.jmh.annotations._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package zio.benchmarks

import java.util.concurrent.TimeUnit

import zio.{Trace, Unsafe}

import zio.http._

import org.openjdk.jmh.annotations._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package zio.benchmarks

import java.util.concurrent.TimeUnit

import zio.{Trace, Unsafe}

import zio.http._

import org.openjdk.jmh.annotations._
Expand Down
18 changes: 4 additions & 14 deletions zio-http-cli/src/main/scala/zio/http/endpoint/cli/CliRequest.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
package zio.http.endpoint.cli

import java.io.{File, IOException}
import java.nio.channels.FileChannel
import java.nio.file.Path

import scala.io.Source

import zio._
import zio.cli._
import zio.json.ast._

import zio.stream.{ZSink, ZStream}

import zio.http._

Expand All @@ -28,16 +18,16 @@ private[cli] final case class CliRequest(
saveResponse: Boolean = false,
) { self =>

def addBody(value: Retriever) =
def addBody(value: Retriever): CliRequest =
self.copy(body = self.body ++ Chunk(value))

def addHeader(name: String, value: String): CliRequest =
self.copy(headers = self.headers.addHeader(name, value))

def addPathParam(value: String) =
def addPathParam(value: String): CliRequest =
self.copy(url = self.url.copy(path = self.url.path / value))

def addQueryParam(key: String, value: String) =
def addQueryParam(key: String, value: String): CliRequest =
self.copy(url = self.url.setQueryParams(self.url.queryParams.addQueryParam(key, value)))

def method(method: Method): CliRequest =
Expand All @@ -63,6 +53,6 @@ private[cli] final case class CliRequest(

private[cli] object CliRequest {

val empty = CliRequest(Chunk.empty, Headers.empty, Method.GET, URL.empty)
val empty: CliRequest = CliRequest(Chunk.empty, Headers.empty, Method.GET, URL.empty)

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ object CliSpec extends ZIOSpecDefault {
for {
text <- body.asMultipartForm
.map(_.formData)
.map(_.map(_.stringValue.toString()))
.map(_.map(_.stringValue.toString))
.map(_.toString())
.mapError(e => Response.error(Status.BadRequest, e.getMessage))
} yield if (text == "Chunk(Some(342.76))") Response.text("received 1") else Response.text(text)
Expand Down
20 changes: 10 additions & 10 deletions zio-http-cli/src/test/scala/zio/http/endpoint/cli/CommandGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ object CommandGen {
def getSegment(segment: SegmentCodec[_]): (String, String) = {
def fromSegment[A](segment: SegmentCodec[A]): (String, String) =
segment match {
case SegmentCodec.UUID(name) => (name, "text")
case SegmentCodec.Text(name) => (name, "text")
case SegmentCodec.IntSeg(name) => (name, "integer")
case SegmentCodec.LongSeg(name) => (name, "integer")
case SegmentCodec.BoolSeg(name) => (name, "boolean")
case SegmentCodec.Literal(_) => ("", "")
case SegmentCodec.Trailing => ("", "")
case SegmentCodec.Empty => ("", "")
case SegmentCodec.Combined(left, right, combiner) =>
case SegmentCodec.UUID(name) => (name, "text")
case SegmentCodec.Text(name) => (name, "text")
case SegmentCodec.IntSeg(name) => (name, "integer")
case SegmentCodec.LongSeg(name) => (name, "integer")
case SegmentCodec.BoolSeg(name) => (name, "boolean")
case SegmentCodec.Literal(_) => ("", "")
case SegmentCodec.Trailing => ("", "")
case SegmentCodec.Empty => ("", "")
case SegmentCodec.Combined(_, _, _) =>
???
}

Expand All @@ -37,7 +37,7 @@ object CommandGen {

lazy val anyEndpoint: Gen[Any, HelpRepr[Endpoint[_, _, _, _, _]]] =
anyCodec
.map(_.map2(getCommand(_)))
.map(_.map2(getCommand))
.map(_.map(fromInputCodec(Doc.empty, _)))

def getCommand(cliEndpoint: CliEndpoint): HelpDoc = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import zio.schema.Schema

import zio.http._
import zio.http.codec._
import zio.http.codec.internal.TextBinaryCodec
import zio.http.endpoint._
import zio.http.endpoint.cli.AuxGen._
import zio.http.endpoint.cli.CliRepr.CliReprOf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import zio.schema.Schema

import zio.http._
import zio.http.codec._
import zio.http.codec.internal.TextBinaryCodec
import zio.http.endpoint.cli.AuxGen._
import zio.http.endpoint.cli.CliRepr._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package example

import zio.http.codec.HttpCodec._
import zio.http.codec._

object CombinerTypesExample extends App {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package example

import zio._

import zio.http.Header.Authorization
import zio.http._
import zio.http.codec.PathCodec.path
import zio.http.codec._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import zio.stream.ZStream
import zio.schema.{DeriveSchema, Schema}

import zio.http._
import zio.http.codec.{CodecConfig, HttpCodec}
import zio.http.codec._
import zio.http.endpoint._

object ServerSentEventAsJsonEndpoint extends ZIOAppDefault {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import zio._
import zio.stream.ZStream

import zio.http._
import zio.http.codec.{CodecConfig, HttpCodec}
import zio.http.codec._
import zio.http.endpoint._

object ServerSentEventEndpoint extends ZIOAppDefault {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import zio._
import zio.schema.{DeriveSchema, Schema}

import zio.http._
import zio.http.codec.{CodecConfig, HeaderCodec, PathCodec}
import zio.http.codec._
import zio.http.endpoint.{AuthType, Endpoint}

object EndpointWithMultipleErrorsUsingEither extends ZIOAppDefault {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import zio._
import zio.schema.{DeriveSchema, Schema}

import zio.http._
import zio.http.codec.{CodecConfig, HeaderCodec, HttpCodec, PathCodec}
import zio.http.codec._
import zio.http.endpoint.{AuthType, Endpoint}

object EndpointWithMultipleUnifiedErrors extends ZIOAppDefault {
Expand Down
2 changes: 1 addition & 1 deletion zio-http-testkit/src/main/scala/zio/http/TestChannel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package zio.http
import zio._
import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.ChannelEvent.{Unregistered, UserEvent, UserEventTriggered}
import zio.http.ChannelEvent._

case class TestChannel(
in: Queue[WebSocketChannelEvent],
Expand Down
2 changes: 0 additions & 2 deletions zio-http/js/src/main/scala/zio/http/URLPlatformSpecific.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package zio.http

import scala.util.Try

trait URLPlatformSpecific {
self: URL =>
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ package zio.http.internal

import zio.http.netty.NettyBody

trait BodyEncodingPlatformSpecific {
private[http] trait BodyEncodingPlatformSpecific {
val default: BodyEncoding = NettyBody
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import io.netty.buffer.ByteBufUtil
import io.netty.channel.{ChannelHandlerContext, SimpleChannelInboundHandler}
import io.netty.handler.codec.http.{HttpContent, LastHttpContent}

abstract class AsyncBodyReader extends SimpleChannelInboundHandler[HttpContent](true) {
private[netty] abstract class AsyncBodyReader extends SimpleChannelInboundHandler[HttpContent](true) {
import zio.http.netty.AsyncBodyReader._

private var state: State = State.Buffering
Expand Down Expand Up @@ -138,7 +138,7 @@ abstract class AsyncBodyReader extends SimpleChannelInboundHandler[HttpContent](
}
}

object AsyncBodyReader {
private[netty] object AsyncBodyReader {

sealed trait State

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private object CachedDateHeader {
lazy val default: CachedDateHeader = new CachedDateHeader()
}

final private class CachedDateHeader(
private final class CachedDateHeader(
clock: Clock = Clock.tickSeconds(ZoneOffset.UTC),
dateEncoding: DateEncoding = DateEncoding.default,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import io.netty.channel.epoll._
import io.netty.channel.kqueue._
import io.netty.channel.socket.nio._
import io.netty.incubator.channel.uring._
object ChannelFactories {
private[netty] object ChannelFactories {

private[zio] def make[A <: Channel](channel: => A)(implicit trace: Trace): UIO[ChannelFactory[A]] =
ZIO.succeed(new ChannelFactory[A] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package zio.http.netty

import java.time.temporal.TemporalUnit
import java.util.concurrent.Executor

import scala.concurrent.duration.TimeUnit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.netty.handler.codec.http.HttpUtil.getContentLength
import io.netty.handler.codec.http._
import io.netty.handler.stream.ChunkedWriteHandler

class HybridContentLengthHandler(maxAggregatedLength: Int) extends ChannelInboundHandlerAdapter {
private[netty] class HybridContentLengthHandler(maxAggregatedLength: Int) extends ChannelInboundHandlerAdapter {
var maxLength = maxAggregatedLength
override def channelRead(ctx: ChannelHandlerContext, msg: Any): Unit = {
msg match {
Expand Down
4 changes: 2 additions & 2 deletions zio-http/jvm/src/main/scala/zio/http/netty/NettyBody.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ object NettyBody extends BodyEncoding {
override def asStream(implicit trace: Trace): ZStream[Any, Throwable, Byte] =
ZStream.unwrap(asChunk.map(ZStream.fromChunk(_)))

override def toString(): String = s"Body.fromAsciiString($asciiString)"
override def toString: String = s"Body.fromAsciiString($asciiString)"

private[zio] override def unsafeAsArray(implicit unsafe: Unsafe): Array[Byte] = asciiString.array()

Expand Down Expand Up @@ -131,7 +131,7 @@ object NettyBody extends BodyEncoding {

override def isEmpty: Boolean = false

override def toString(): String = s"AsyncBody($unsafeAsync)"
override def toString: String = s"AsyncBody($unsafeAsync)"

override def contentType(newContentType: Body.ContentType): Body = copy(contentType = Some(newContentType))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import io.netty.buffer.Unpooled
import io.netty.channel._
import io.netty.handler.codec.http.{DefaultHttpContent, LastHttpContent}

object NettyBodyWriter {
private[netty] object NettyBodyWriter {

@tailrec
def writeAndFlush(
Expand Down
6 changes: 3 additions & 3 deletions zio-http/jvm/src/main/scala/zio/http/netty/NettyChannel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package zio.http.netty

import zio._
import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.{Task, Trace, UIO, ZIO}

import io.netty.channel.{Channel => JChannel, ChannelFuture => JChannelFuture}

final case class NettyChannel[-A](
private[netty] final case class NettyChannel[-A](
private val channel: JChannel,
private val convert: A => Any,
) {
Expand Down Expand Up @@ -67,6 +67,6 @@ final case class NettyChannel[-A](
}
}

object NettyChannel {
private[netty] object NettyChannel {
def make[A](channel: JChannel): NettyChannel[A] = NettyChannel(channel, identity)
}
Loading

0 comments on commit 22caa5a

Please sign in to comment.