• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / atala-prism-building-blocks / 8802276486

23 Apr 2024 02:32PM UTC coverage: 31.946% (+0.1%) from 31.837%
8802276486

Pull #973

FabioPinheiro
Rename 'connect' package

Signed-off-by: FabioPinheiro <fabiomgpinheiro@gmail.com>
Pull Request #973: [wip] Align the repo with new name identus-cloud-agent

0 of 5 new or added lines in 3 files covered. (0.0%)

405 existing lines in 84 files now uncovered.

4521 of 14152 relevant lines covered (31.95%)

0.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/shared/core/src/main/scala/io/iohk/atala/shared/db/ContextAwareTask.scala
1
package io.iohk.atala.shared.db
2

3
import doobie.*
4
import doobie.postgres.implicits.*
5
import doobie.syntax.ConnectionIOOps
6
import doobie.util.transactor.Transactor
7
import io.iohk.atala.shared.models.WalletAccessContext
8
import io.iohk.atala.shared.models.WalletId
9
import zio.*
10
import zio.interop.catz.*
11

12
import java.util.UUID
13

14
trait ContextAware
15
type ContextAwareTask[T] = Task[T] with ContextAware
16

17
object Implicits {
18

1✔
UNCOV
19
  given walletIdGet: Get[WalletId] = Get[UUID].map(WalletId.fromUUID)
×
20
  given walletIdPut: Put[WalletId] = Put[UUID].contramap(_.toUUID)
21

22
  private val WalletIdVariableName = "app.current_wallet_id"
23

24
  extension [A](ma: ConnectionIO[A]) {
1✔
25
    def transactWithoutContext(xa: Transactor[ContextAwareTask]): Task[A] = {
×
26
      ConnectionIOOps(ma).transact(xa.asInstanceOf[Transactor[Task]])
27
    }
28

1✔
29
    def transactWallet(xa: Transactor[ContextAwareTask]): RIO[WalletAccessContext, A] = {
1✔
30
      def walletCxnIO(ctx: WalletAccessContext) = {
1✔
31
        for {
1✔
32
          _ <- doobie.free.connection.createStatement.map { statement =>
×
33
            statement.execute(s"SET LOCAL $WalletIdVariableName TO '${ctx.walletId}'")
34
          }
1✔
35
          result <- ma
36
        } yield result
37
      }
38

1✔
39
      for {
×
40
        ctx <- ZIO.service[WalletAccessContext]
1✔
41
        result <- ConnectionIOOps(walletCxnIO(ctx)).transact(xa.asInstanceOf[Transactor[Task]])
42
      } yield result
43
    }
44

45
  }
46

47
  extension [Int](ma: RIO[WalletAccessContext, Int]) {
1✔
48
    def ensureOneAffectedRowOrDie: URIO[WalletAccessContext, Unit] = ma.flatMap {
1✔
49
      case 1     => ZIO.unit
1✔
50
      case count => ZIO.fail(RuntimeException(s"Unexpected affected row count: $count"))
51
    }.orDie
52
  }
53

54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc