Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/permutive-engineering/common-types-gcp
GPC common types that can be used on any Scala services or libraries
https://github.com/permutive-engineering/common-types-gcp
gcp google-cloud google-cloud-platform scala
Last synced: about 1 month ago
JSON representation
GPC common types that can be used on any Scala services or libraries
- Host: GitHub
- URL: https://github.com/permutive-engineering/common-types-gcp
- Owner: permutive-engineering
- License: apache-2.0
- Created: 2024-02-17T19:02:50.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-12-01T05:03:52.000Z (about 1 month ago)
- Last Synced: 2024-12-01T06:22:13.275Z (about 1 month ago)
- Topics: gcp, google-cloud, google-cloud-platform, scala
- Language: Scala
- Homepage:
- Size: 59.6 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# `common-types-gcp`
GPC common types that can be used on any Scala services or libraries.
The list of common types are:
- [`DatasetName`](modules/common-types-gcp/src/main/scala/com/permutive/common/types/gcp/DatasetName.scala)
- [`DatasetMultiRegion`](modules/common-types-gcp/src/main/scala/com/permutive/common/types/gcp/DatasetMultiRegion.scala)
- [`ProjectId`](modules/common-types-gcp/src/main/scala/com/permutive/common/types/gcp/ProjectId.scala)---
- [Installation](#installation)
- [Usage](#usage)
- [Integrations](#integrations)
- [`common-types-gcp-circe`](#common-types-gcp-circe)
- [Installation](#installation)
- [Usage](#usage)
- [`common-types-gcp-http4s`](#common-types-gcp-http4s)
- [Installation](#installation)
- [Usage](#usage)
- [`common-types-gcp-pureconfig`](#common-types-gcp-pureconfig)
- [Installation](#installation)
- [Usage](#usage)
- [`common-types-gcp-tapir`](#common-types-gcp-tapir)
- [Installation](#installation)
- [Usage](#usage)
- [`common-types-gcp-scalacheck`](#common-types-gcp-scalacheck)
- [Installation](#installation)
- [Usage](#usage)
- [Contributors to this project](#contributors-to-this-project)## Installation
Add the following dependency to your project:
```sbt
"com.permutive" %% "common-types-gcp" % "1.1.0"
```## Usage
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:**
```scala
import cats.Evalval projectId: Eval[ProjectId] = ProjectId.unsafeFromGCP()
```> 👆🏼 This method will only return a valid project ID if run inside a workload.
**Creating a random value:**
```scala
val projectId: ProjectId = ProjectId.random()
```> 👆🏼 It will raise a warning if used outside `Test` or `IntegrationTest` configurations
**Creating a value from a string (returning `Either`):**
```scala
val projectId: Either[String, ProjectId]=
ProjectId.fromString("test-project")
```**Effectful alternative:**
```scala
val projectId: IO[ProjectId]=
ProjectId.fromStringF[IO]("test-project")
```**Creating a value from a literal string:**
```scala
val projectId: ProjectId = ProjectId("test-project")
```> 👆🏼 It will fail at compile time if not a project ID or not using a literal.
## Integrations
### `common-types-gcp-circe`
#### Installation
Add the following dependency to your project:
```sbt
"com.permutive" %% "common-types-gcp-circe" % "1.1.0"
```#### Usage
Just add the following import:
```scala
import com.permutive.common.types.gcp.circe._
```It will bring `Encoder`, `Decoder`, `KeyEncoder` & `KeyDecoder` instances for the
available types into scope.### `common-types-gcp-http4s`
#### Installation
Add the following dependency to your project:
```sbt
"com.permutive" %% "common-types-gcp-http4s" % "1.1.0"
```#### Usage
Just add the following import:
```scala
import com.permutive.common.types.gcp.http4s._
```It will bring `SegmentEncoder`, `QueryParamEncoder` & `QueryParamDecoder`
instances for the available types into scope.### `common-types-gcp-pureconfig`
#### Installation
Add the following dependency to your project:
```sbt
"com.permutive" %% "common-types-gcp-pureconfig" % "1.1.0"
```#### Usage
Just add the following import:
```scala
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.### `common-types-gcp-tapir`
#### Installation
Add the following dependency to your project:
```sbt
"com.permutive" %% "common-types-gcp-tapir" % "1.1.0"
```#### Usage
Just add the following import:
```scala
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:
```scala
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..this.type.Out, Unit, Unit, Any] = Endpoint(
// securityInput = Empty(
// codec = sttp.tapir.Codec$$anon$4@7cc62914,
// 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@7cc62914,
// info = Info(
// description = None,
// examples = List(),
// deprecated = false,
// attributes = AttributeMap(storage = Map())
// )
// ),
// right = FixedMethod(
// m = Method(method = "GET"),
// codec = sttp.tapir.Codec$$anon$4@24e399bf,
// info = Info(
// description = None,
// examples = List(),
// deprecated = false,
// attributes = AttributeMap(storage = Map())
// )
// ),
// combine = sttp.tapir.internal.package$$$Lambda$14987/0x00007f4b5697e6e0@6836a99b,
// split = sttp.tapir.internal.package$$$Lambda$14988/0x00007f4b5697ec88@45bf623a
// ),
// right = FixedPath(
// s = "projects",
// codec = sttp.tapir.Codec$$anon$4@4a282bc6,
// info = Info(
// description = None,
// examples = List(),
// deprecated = false,
// attributes = AttributeMap(storage = Map())
// )
// ),
// combine = sttp.tapir.internal.package$$$Lambda$14989/0x00007f4b5697f7c8@72be7d5d,
// ...
```### `common-types-gcp-scalacheck`
#### Installation
Add the following dependency to your project:
```sbt
"com.permutive" %% "common-types-gcp-scalacheck" % "1.1.0"
```#### Usage
Just add the following import:
```scala
import com.permutive.common.types.gcp.scalacheck._
```It will bring `Arbitrary` instances for the available types into scope.
## Contributors to this project
| |
| :--: |
| alejandrohdezma |