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

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

24 Apr 2024 03:32PM UTC coverage: 50.082% (+18.2%) from 31.912%
8819221863

Pull #973

mineme0110
minor cleanup

Signed-off-by: mineme0110 <shailesh.patil@iohk.io>
Pull Request #973: feat: Align the repo with new name identus-cloud-agent

1 of 6 new or added lines in 4 files covered. (16.67%)

2998 existing lines in 264 files now uncovered.

7340 of 14656 relevant lines covered (50.08%)

0.5 hits per line

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

0.0
/shared/core/src/main/scala/io/iohk/atala/shared/utils/proto/package.scala
1
package io.iohk.atala.shared.utils
2

3
import com.google.protobuf.ByteString
4
import io.iohk.atala.shared.utils.proto.ValidationError.{InvalidValue, MissingValue}
5

6
package object proto {
7

8
  /** Value with path explaining its location if protobuf message */
9
  case class ValueAtPath[M](value: M, path: Path) {
10

11
    /** Extracts the value, potentially applying some transformation on it */
UNCOV
12
    def apply[T](f: M => T): T = f(value)
×
13

14
    /** Extracts child from the value
15
      *
16
      * @param f
17
      *   function used to extract the child value
18
      * @param axis
19
      *   name of the child - field name or array index
20
      * @tparam MM
21
      *   type of the child
22
      * @return
23
      *   ValueAtPath representing the child
24
      */
25
    def child[MM](f: M => MM, axis: String): ValueAtPath[MM] =
×
UNCOV
26
      ValueAtPath(f(value), path / axis)
×
27

28
    /** Extracts child from the value
29
      *
30
      * @param f
31
      *   function used to extract the child value
32
      * @param axis
33
      *   name of the child - field name or array index
34
      * @tparam MM
35
      *   type of the child
36
      * @return
37
      *   ValueAtPath representing the child
38
      */
39
    def children[MM](f: M => Seq[MM], axis: String): Seq[ValueAtPath[MM]] = {
×
40
      f(value).zipWithIndex.map { case (v, i) =>
×
UNCOV
41
        ValueAtPath(v, path / axis / i.toString)
×
42
      }
43
    }
44

45
    /** Variant of child extracting it from option
46
      *
47
      * @param f
48
      *   function to extract option of child value
49
      * @param axis
50
      *   name of the child - field name or array index
51
      * @tparam MM
52
      *   type of the child
53
      * @return
54
      *   ValueAtPath representing the child or MissingValue error if f returns empty Option
55
      */
UNCOV
56
    def childGet[MM](
×
57
        f: M => Option[MM],
58
        axis: String
59
    ): Either[MissingValue, ValueAtPath[MM]] = {
60
      f(value)
×
61
        .map(ValueAtPath(_, path / axis))
×
UNCOV
62
        .toRight(MissingValue(path / axis))
×
63
    }
64

65
    /** Generates InvalidValue error for this path */
UNCOV
66
    def invalid(message: String): InvalidValue =
×
67
      InvalidValue(path, value.toString, message)
68

69
    /** Generates MissingValue error for this path */
UNCOV
70
    def missing(): MissingValue = MissingValue(path)
×
71

72
    // to string with special case for ByteString, which is useful, as it often occurs in protobuf
UNCOV
73
    protected def valueToString(value: Any): String = {
×
74
      value match {
75
        case v: ByteString =>
×
UNCOV
76
          if (v.isEmpty) "0x0"
×
77
          else "0x" + v.toByteArray.map("%02x".format(_)).mkString("")
×
UNCOV
78
        case v => v.toString
×
79
      }
80
    }
81

82
    /** Attempts to apply potentially failing transform to the value
83
      *
84
      * @param f
85
      *   the transform, should return either result or error message
86
      * @tparam MM
87
      *   the result type of the transform
88
      * @return
89
      *   transformed value or InvalidError for this path with provided message
90
      */
91
    def parse[MM](f: M => Either[String, MM]): Either[InvalidValue, MM] = {
×
UNCOV
92
      f(value).left.map(message => InvalidValue(path, valueToString(value), message))
×
93
    }
94
  }
95
}
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