Skip to content
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

Support referencing services by aws name #78

Merged
merged 1 commit into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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