GPC common types that can be used on any Scala services or libraries.
The list of common types are:
Add the following dependency to your project:
"com.permutive" %% "common-types-gcp" % "1.2.1"Every type includes implicit instances for cats' Eq, Show, Order, Hash.
In addition, types like ProjectId also contain smart constructors:
Obtaining the current ProjectId from Google's metadata service:
import cats.Eval
val projectId: Eval[ProjectId] = ProjectId.unsafeFromGCP()👆🏼 This method will only return a valid project ID if run inside a workload.
Creating a random value:
val projectId: ProjectId = ProjectId.random()👆🏼 It will raise a warning if used outside
TestorIntegrationTestconfigurations
Creating a value from a string (returning Either):
val projectId: Either[String, ProjectId]=
ProjectId.fromString("test-project")Effectful alternative:
val projectId: IO[ProjectId]=
ProjectId.fromStringF[IO]("test-project")Creating a value from a literal string:
val projectId: ProjectId = ProjectId("test-project")👆🏼 It will fail at compile time if not a project ID or not using a literal.
Add the following dependency to your project:
"com.permutive" %% "common-types-gcp-circe" % "1.2.1"Just add the following import:
import com.permutive.common.types.gcp.circe._It will bring Encoder, Decoder, KeyEncoder & KeyDecoder instances for the
available types into scope.
Add the following dependency to your project:
"com.permutive" %% "common-types-gcp-http4s" % "1.2.1"Just add the following import:
import com.permutive.common.types.gcp.http4s._It will bring SegmentEncoder, QueryParamEncoder & QueryParamDecoder
instances for the available types into scope.
Add the following dependency to your project:
"com.permutive" %% "common-types-gcp-pureconfig" % "1.2.1"Just add the following import:
import com.permutive.common.types.gcp.pureconfig._It will bring ConfigReader & ConfigWriter instances for the available types
into scope.
For the case of ProjectId you can use the special value gcp on your
application.conf when running inside a workload and it will retrieve the
current ProjectId from Google's metadata service.
Add the following dependency to your project:
"com.permutive" %% "common-types-gcp-tapir" % "1.2.1"Just add the following import:
import com.permutive.common.types.gcp.tapir._It will bring Codec/Schema instances for the available types, as well as adding a new extension method (example) to common types' companion objects that can be used to add an example value to tapir endpoints:
import com.permutive.common.types.gcp.ProjectId
import com.permutive.common.types.gcp.tapir._
import sttp.tapir._
endpoint.get
.in("projects")
.in(path[ProjectId]("project_id").example(ProjectId.example))
// res12: Endpoint[Unit, typelevel.LowPriorityTupleConcat0.<refinement>.this.type.Out, Unit, Unit, Any] = Endpoint(
// securityInput = Empty(
// codec = sttp.tapir.Codec$$anon$4@5e12767b,
// info = Info(
// description = None,
// examples = List(),
// deprecated = false,
// attributes = AttributeMap(storage = Map())
// )
// ),
// input = Pair(
// left = Pair(
// left = Pair(
// left = Empty(
// codec = sttp.tapir.Codec$$anon$4@5e12767b,
// info = Info(
// description = None,
// examples = List(),
// deprecated = false,
// attributes = AttributeMap(storage = Map())
// )
// ),
// right = FixedMethod(
// m = Method(method = "GET"),
// codec = sttp.tapir.Codec$$anon$4@4c79b5bd,
// info = Info(
// description = None,
// examples = List(),
// deprecated = false,
// attributes = AttributeMap(storage = Map())
// )
// ),
// combine = sttp.tapir.internal.package$$$Lambda$14576/0x00007fcfaa923a30@3940b5ff,
// split = sttp.tapir.internal.package$$$Lambda$14577/0x00007fcfaa923fd8@16439897
// ),
// right = FixedPath(
// s = "projects",
// codec = sttp.tapir.Codec$$anon$4@4b34ab92,
// info = Info(
// description = None,
// examples = List(),
// deprecated = false,
// attributes = AttributeMap(storage = Map())
// )
// ),
// combine = sttp.tapir.internal.package$$$Lambda$14578/0x00007fcfaa924b18@4a613b14,
// ...Add the following dependency to your project:
"com.permutive" %% "common-types-gcp-scalacheck" % "1.2.1"Just add the following import:
import com.permutive.common.types.gcp.scalacheck._It will bring Arbitrary instances for the available types into scope.
| alejandrohdezma |