Skip to content

Commit

Permalink
Merge pull request #78 from kubukoz/service-name-aws
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Aug 12, 2022
2 parents 1bbf57c + a77a7fc commit fc3b99a
Show file tree
Hide file tree
Showing 6 changed files with 8,981 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/playground/CompletionProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object CompletionProvider {
dsi
.allServices
.map { service =>
QualifiedIdentifier.fromShapeId(service.service.id) -> service
QualifiedIdentifier.forService(service.service) -> service
}
.toMap

Expand Down
15 changes: 15 additions & 0 deletions core/src/main/scala/playground/ServiceNameExtractor.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package playground

import aws.api
import playground.smithyql.QualifiedIdentifier
import smithy4s.Service

object ServiceNameExtractor {

def fromService[Alg[_[_, _, _, _, _]], Op[_, _, _, _, _]](
service: Service[Alg, Op]
): QualifiedIdentifier = QualifiedIdentifier.fromShapeId(
service.id.copy(name = service.hints.get(api.Service).map(_.sdkId).getOrElse(service.id.name))
)

}
6 changes: 3 additions & 3 deletions core/src/main/scala/playground/run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ object Compiler {
.map { svc =>
// todo: deprecated services (here / in completions)
QualifiedIdentifier
.fromShapeId(svc.service.id) -> Compiler.fromService[svc.Alg, svc.Op](svc.service)
.forService(svc.service) -> Compiler.fromService[svc.Alg, svc.Op](svc.service)
}
.toMap

Expand Down Expand Up @@ -127,7 +127,7 @@ private class ServiceCompiler[Alg[_[_, _, _, _, _]], Op[_, _, _, _, _]](
type E = Err
type O = Out
val input: I = compiled
val serviceId: QualifiedIdentifier = QualifiedIdentifier.fromShapeId(service.id)
val serviceId: QualifiedIdentifier = QualifiedIdentifier.forService(service)
val endpoint: Endpoint[Op, I, E, O, _, _] = e
val writeOutput: NodeEncoder[Out] = outputEncoder
val writeError: Option[NodeEncoder[Err]] = errorEncoder
Expand Down Expand Up @@ -262,7 +262,7 @@ object Runner {
dsi
.allServices
.map { svc =>
QualifiedIdentifier.fromShapeId(svc.service.id) ->
QualifiedIdentifier.forService(svc.service) ->
Runner.forService[svc.Alg, svc.Op, F](
svc.service,
client,
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/scala/playground/smithyql/AST.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import smithy4s.ShapeId
import cats.Show
import cats.kernel.Eq
import cats.Id
import playground.ServiceNameExtractor
import smithy4s.Service

sealed trait AST[F[_]] extends Product with Serializable {
def mapK[G[_]: Functor](fk: F ~> G): AST[G]
Expand Down Expand Up @@ -54,7 +56,12 @@ object QualifiedIdentifier {
shapeId.name,
)

def forService[Alg[_[_, _, _, _, _]], Op[_, _, _, _, _]](
service: Service[Alg, Op]
): QualifiedIdentifier = ServiceNameExtractor.fromService(service)

implicit val show: Show[QualifiedIdentifier] = Show.fromToString
implicit val eq: Eq[QualifiedIdentifier] = Eq.fromUniversalEquals

}

Expand Down
24 changes: 24 additions & 0 deletions core/src/test/scala/playground/ServiceNameExtractorTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package playground

import cats.data.NonEmptyList
import com.amazonaws.lambda.LambdaGen
import demo.smithy.DemoServiceGen
import playground.smithyql.QualifiedIdentifier
import weaver._

object ServiceNameExtractorTests extends FunSuite {
test("extract name of service with an AWS hint") {
assert.eql(
ServiceNameExtractor.fromService(LambdaGen.service),
QualifiedIdentifier(NonEmptyList.of("com", "amazonaws", "lambda"), "Lambda"),
)
}

test("extract name of demo service") {

assert.eql(
ServiceNameExtractor.fromService(DemoServiceGen.service),
QualifiedIdentifier(NonEmptyList.of("demo", "smithy"), "DemoService"),
)
}
}
Loading

0 comments on commit fc3b99a

Please sign in to comment.