Skip to content

Commit ede9854

Browse files
authored
Upgrade iron 3.2.0 (#12)
* chore: upgrade Iron from 3.0.1 to 3.2.0 - Update Iron dependency to 3.2.0 to get RefinedSubtype support - RefinedSubtype enables implicit conversion to base types - This allows refined types like NetworkId, AccountId, Address to be used directly where String is expected * chore: migrate from RefinedType to RefinedSubtype - Change all RefinedType to RefinedSubtype to work with Iron 3.2.0 - RefinedSubtype provides implicit conversion to base types - This allows refined types to be used directly where base type is expected Note: db-skunk module has pre-existing compilation issues with Typer.Strategy that are unrelated to Iron upgrade * fix: update Typer.Strategy to TypingStrategy for Skunk 1.0.0-M11 - Skunk 1.0.0-M11 renamed Typer.Strategy to TypingStrategy - Move from Typer.Strategy.BuiltinsOnly to TypingStrategy.BuiltinsOnly - Move from Typer.Strategy.SearchPath to TypingStrategy.SearchPath * chore: run scalafmt * chore: add sbt-scalafmt plugin - Add sbt-scalafmt 2.5.5 plugin to project/plugins.sbt - Enables scalafmtCheckAll and scalafmtAll commands in sbt
1 parent fa2c722 commit ede9854

14 files changed

Lines changed: 58 additions & 57 deletions

File tree

modules/core/src/main/scala/pillars/Logging.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ object Logging:
4242
private type BufferSizeConstraint = Positive `DescribedAs` "Buffer size should be positive"
4343
type BufferSize = BufferSize.T
4444

45-
object BufferSize extends RefinedType[Int, BufferSizeConstraint]
45+
object BufferSize extends RefinedSubtype[Int, BufferSizeConstraint]
4646

4747
enum Format:
4848
case Json

modules/core/src/main/scala/pillars/Observability.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ object Observability:
107107

108108
private type ServiceNameConstraint = Not[Blank]
109109
type ServiceName = ServiceName.T
110-
object ServiceName extends RefinedType[String, ServiceNameConstraint]
110+
object ServiceName extends RefinedSubtype[String, ServiceNameConstraint]
111111

112112
extension [A <: String](value: A)
113113
def toAttribute(name: String): Attribute[String] = Attribute(name, value)

modules/core/src/main/scala/pillars/PillarsError.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ object PillarsError:
6262
private type CodeConstraint = (Not[Empty] & LettersUpperCase) `DescribedAs` "Code cannot be empty"
6363
type Code = Code.T
6464

65-
object Code extends RefinedType[String, CodeConstraint]
65+
object Code extends RefinedSubtype[String, CodeConstraint]
6666

6767
private type MessageConstraint = Not[Empty] `DescribedAs` "Message cannot be empty"
6868
type Message = Message.T
6969

70-
object Message extends RefinedType[String, MessageConstraint]
70+
object Message extends RefinedSubtype[String, MessageConstraint]
7171

7272
private type ErrorNumberConstraint = Positive `DescribedAs` "Number must be strictly positive"
7373
type ErrorNumber = ErrorNumber.T
7474

75-
object ErrorNumber extends RefinedType[Int, ErrorNumberConstraint]
75+
object ErrorNumber extends RefinedSubtype[Int, ErrorNumberConstraint]
7676
end PillarsError

modules/core/src/main/scala/pillars/app.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ abstract class IOApp(override val modules: ModuleSupport*) extends App(modules*)
4141
object App:
4242
private type NameConstraint = Not[Blank]
4343
type Name = Name.T
44-
object Name extends RefinedType[String, NameConstraint]
44+
object Name extends RefinedSubtype[String, NameConstraint]
4545

4646
private type VersionConstraint = SemanticVersion
4747
type Version = Version.T
48-
object Version extends RefinedType[String, VersionConstraint]
48+
object Version extends RefinedSubtype[String, VersionConstraint]
4949

5050
private type DescriptionConstraint = Not[Blank]
5151
type Description = Description.T
52-
object Description extends RefinedType[String, DescriptionConstraint]
52+
object Description extends RefinedSubtype[String, DescriptionConstraint]
5353
def apply(value: String): Description = value.asInstanceOf[Description]
5454
def unapply(description: Description): String = description.asInstanceOf[String]
5555
def assume(description: Description): String = description.asInstanceOf[String]

modules/core/src/main/scala/pillars/probes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object probes:
3232
object Component:
3333
private type NameConstraint = Not[Blank] & Not[Contain[":"]]
3434
type Name = Name.T
35-
object Name extends RefinedType[String, NameConstraint]
35+
object Name extends RefinedSubtype[String, NameConstraint]
3636

3737
enum Type:
3838
case System, Datastore, Component

modules/db-doobie/src/main/scala/pillars/db_doobie/db.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,28 @@ end StatementCacheConfig
116116
private type SizeConstraint = Positive0 `DescribedAs` "Size must be positive or zero"
117117
type Size = Size.T
118118

119-
object Size extends RefinedType[Int, SizeConstraint]
119+
object Size extends RefinedSubtype[Int, SizeConstraint]
120120

121121
private type JdbcUrlConstraint =
122122
Match["jdbc\\:[^:]+\\:.*"] `DescribedAs` "Driver class name must in jdbc:<subprotocol>:<subname> format"
123123
type JdbcUrl = JdbcUrl.T
124124

125-
object JdbcUrl extends RefinedType[String, JdbcUrlConstraint]
125+
object JdbcUrl extends RefinedSubtype[String, JdbcUrlConstraint]
126126

127127
private type DriverClassNameConstraint = Not[Blank] `DescribedAs` "Driver class name must not be blank"
128128
type DriverClassName = DriverClassName.T
129129

130-
object DriverClassName extends RefinedType[String, DriverClassNameConstraint]
130+
object DriverClassName extends RefinedSubtype[String, DriverClassNameConstraint]
131131

132132
private type DatabaseNameConstraint = Not[Blank] `DescribedAs` "Database name must not be blank"
133133
type DatabaseName = DatabaseName.T
134134

135-
object DatabaseName extends RefinedType[String, DatabaseNameConstraint]
135+
object DatabaseName extends RefinedSubtype[String, DatabaseNameConstraint]
136136

137137
private type DatabaseSchemaConstraint = Not[Blank] `DescribedAs` "Database schema must not be blank"
138138
type DatabaseSchema = DatabaseSchema.T
139139

140-
object DatabaseSchema extends RefinedType[String, DatabaseSchemaConstraint]:
140+
object DatabaseSchema extends RefinedSubtype[String, DatabaseSchemaConstraint]:
141141
val public: DatabaseSchema = DatabaseSchema("public")
142142
val pillars: DatabaseSchema = DatabaseSchema("pillars")
143143

@@ -148,25 +148,25 @@ private type DatabaseTableConstraint =
148148
]
149149
type DatabaseTable = DatabaseTable.T
150150

151-
object DatabaseTable extends RefinedType[String, DatabaseTableConstraint]
151+
object DatabaseTable extends RefinedSubtype[String, DatabaseTableConstraint]
152152

153153
private type DatabaseUserConstraint = Not[Blank] `DescribedAs` "Database user must not be blank"
154154
type DatabaseUser = DatabaseUser.T
155155

156-
object DatabaseUser extends RefinedType[String, DatabaseUserConstraint]
156+
object DatabaseUser extends RefinedSubtype[String, DatabaseUserConstraint]
157157

158158
private type DatabasePasswordConstraint = Not[Blank] `DescribedAs` "Database password must not be blank"
159159
type DatabasePassword = DatabasePassword.T
160160

161-
object DatabasePassword extends RefinedType[String, DatabasePasswordConstraint]
161+
object DatabasePassword extends RefinedSubtype[String, DatabasePasswordConstraint]
162162

163163
private type PoolSizeConstraint = GreaterEqual[1] `DescribedAs` "Pool size must be greater or equal to 1"
164164
type PoolSize = PoolSize.T
165165

166-
object PoolSize extends RefinedType[Int, PoolSizeConstraint]
166+
object PoolSize extends RefinedSubtype[Int, PoolSizeConstraint]
167167

168168
private type VersionConstraint =
169169
Not[Blank] & Match["^(\\d+\\.\\d+\\.\\d+)$"] `DescribedAs` "Schema version must be in the form of X.Y.Z"
170170
type SchemaVersion = SchemaVersion.T
171171

172-
object SchemaVersion extends RefinedType[String, Not[Blank] & Match["^(\\d+\\.\\d+\\.\\d+)$"]]
172+
object SchemaVersion extends RefinedSubtype[String, Not[Blank] & Match["^(\\d+\\.\\d+\\.\\d+)$"]]

modules/db-migration/src/main/scala/pillars/db/migrations/migrations.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@ private type JdbcUrlConstraint =
103103
Match["jdbc\\:[^:]+\\:.*"] `DescribedAs` "JDBC URL must be in jdbc:<subprotocol>:<subname> format"
104104
type JdbcUrl = JdbcUrl.T
105105

106-
object JdbcUrl extends RefinedType[String, JdbcUrlConstraint]
106+
object JdbcUrl extends RefinedSubtype[String, JdbcUrlConstraint]
107107

108108
private type DatabaseNameConstraint = Not[Blank] `DescribedAs` "Database name must not be blank"
109109
type DatabaseName = DatabaseName.T
110110

111-
object DatabaseName extends RefinedType[String, DatabaseNameConstraint]
111+
object DatabaseName extends RefinedSubtype[String, DatabaseNameConstraint]
112112

113113
private type DatabaseSchemaConstraint = Not[Blank] `DescribedAs` "Database schema must not be blank"
114114
type DatabaseSchema = DatabaseSchema.T
115115

116-
object DatabaseSchema extends RefinedType[String, DatabaseSchemaConstraint]:
116+
object DatabaseSchema extends RefinedSubtype[String, DatabaseSchemaConstraint]:
117117
val public: DatabaseSchema = DatabaseSchema("public")
118118
val pillars: DatabaseSchema = DatabaseSchema("pillars")
119119

@@ -122,14 +122,14 @@ private type DatabaseTableConstraint =
122122

123123
type DatabaseTable = DatabaseTable.T
124124

125-
object DatabaseTable extends RefinedType[String, DatabaseTableConstraint]
125+
object DatabaseTable extends RefinedSubtype[String, DatabaseTableConstraint]
126126

127127
private type DatabaseUserConstraint = Not[Blank] `DescribedAs` "Database user must not be blank"
128128
type DatabaseUser = DatabaseUser.T
129129

130-
object DatabaseUser extends RefinedType[String, DatabaseUserConstraint]
130+
object DatabaseUser extends RefinedSubtype[String, DatabaseUserConstraint]
131131

132132
private type DatabasePasswordConstraint = Not[Blank] `DescribedAs` "Database password must not be blank"
133133
type DatabasePassword = DatabasePassword.T
134134

135-
object DatabasePassword extends RefinedType[String, DatabasePasswordConstraint]
135+
object DatabasePassword extends RefinedSubtype[String, DatabasePasswordConstraint]

modules/db-skunk/src/main/scala/pillars/db/db.scala

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ final case class DatabaseConfig(
104104
probe: ProbeConfig = ProbeConfig(),
105105
logging: LoggingConfig = LoggingConfig(),
106106
tracing: Boolean = false,
107-
typerStrategy: Typer.Strategy = Typer.Strategy.BuiltinsOnly,
107+
typerStrategy: TypingStrategy = TypingStrategy.BuiltinsOnly,
108108
extraParameters: Map[String, String] = Map.empty,
109109
commandCache: Int = 1024,
110110
queryCache: Int = 1024,
@@ -119,12 +119,12 @@ object DatabaseConfig:
119119
import pillars.Logging.Config.given
120120
given Codec[LoggingConfig] = Codec.AsObject.derivedConfigured
121121

122-
given CirceEncoder[Typer.Strategy] = CirceEncoder.encodeString.contramap:
123-
case Typer.Strategy.BuiltinsOnly => "BuiltinsOnly"
124-
case Typer.Strategy.SearchPath => "SearchPath"
125-
given CirceDecoder[Typer.Strategy] = CirceDecoder.decodeString.map(_.toLowerCase).emap:
126-
case "builtinsonly" => Right(Typer.Strategy.BuiltinsOnly)
127-
case "searchpath" => Right(Typer.Strategy.SearchPath)
122+
given CirceEncoder[TypingStrategy] = CirceEncoder.encodeString.contramap:
123+
case TypingStrategy.BuiltinsOnly => "BuiltinsOnly"
124+
case TypingStrategy.SearchPath => "SearchPath"
125+
given CirceDecoder[TypingStrategy] = CirceDecoder.decodeString.map(_.toLowerCase).emap:
126+
case "builtinsonly" => Right(TypingStrategy.BuiltinsOnly)
127+
case "searchpath" => Right(TypingStrategy.SearchPath)
128128
case other => Left(s"Invalid Typer strategy: $other")
129129

130130
given CirceDecoder[SSL] = CirceDecoder.decodeString.map(_.toLowerCase).emap:
@@ -159,12 +159,12 @@ final case class LoggingConfig(
159159
private type DatabaseNameConstraint = Not[Blank] `DescribedAs` "Database name must not be blank"
160160
type DatabaseName = DatabaseName.T
161161

162-
object DatabaseName extends RefinedType[String, DatabaseNameConstraint]
162+
object DatabaseName extends RefinedSubtype[String, DatabaseNameConstraint]
163163

164164
private type DatabaseSchemaConstraint = Not[Blank] `DescribedAs` "Database schema must not be blank"
165165
type DatabaseSchema = DatabaseSchema.T
166166

167-
object DatabaseSchema extends RefinedType[String, DatabaseSchemaConstraint]:
167+
object DatabaseSchema extends RefinedSubtype[String, DatabaseSchemaConstraint]:
168168
val public: DatabaseSchema = DatabaseSchema("public")
169169
val pillars: DatabaseSchema = DatabaseSchema("pillars")
170170

@@ -175,25 +175,25 @@ private type DatabaseTableConstraint =
175175
]
176176
type DatabaseTable = DatabaseTable.T
177177

178-
object DatabaseTable extends RefinedType[String, DatabaseTableConstraint]
178+
object DatabaseTable extends RefinedSubtype[String, DatabaseTableConstraint]
179179

180180
private type DatabaseUserConstraint = Not[Blank] `DescribedAs` "Database user must not be blank"
181-
type DatabaseUser = DatabaseUser.T
182181

183-
object DatabaseUser extends RefinedType[String, DatabaseUserConstraint]
182+
type DatabaseUser = DatabaseUser.T
183+
object DatabaseUser extends RefinedSubtype[String, DatabaseUserConstraint]
184184

185185
private type DatabasePasswordConstraint = Not[Blank] `DescribedAs` "Database password must not be blank"
186-
type DatabasePassword = DatabasePassword.T
187186

188-
object DatabasePassword extends RefinedType[String, DatabasePasswordConstraint]
187+
type DatabasePassword = DatabasePassword.T
188+
object DatabasePassword extends RefinedSubtype[String, DatabasePasswordConstraint]
189189

190190
private type PoolSizeConstraint = GreaterEqual[1] `DescribedAs` "Pool size must be greater or equal to 1"
191-
type PoolSize = PoolSize.T
192191

193-
object PoolSize extends RefinedType[Int, PoolSizeConstraint]
192+
type PoolSize = PoolSize.T
193+
object PoolSize extends RefinedSubtype[Int, PoolSizeConstraint]
194194

195195
private type VersionConstraint =
196196
Not[Blank] & Match["^(\\d+\\.\\d+\\.\\d+)$"] `DescribedAs` "Schema version must be in the form of X.Y.Z"
197197
type SchemaVersion = SchemaVersion.T
198198

199-
object SchemaVersion extends RefinedType[String, Not[Blank] & Match["^(\\d+\\.\\d+\\.\\d+)$"]]
199+
object SchemaVersion extends RefinedSubtype[String, Not[Blank] & Match["^(\\d+\\.\\d+\\.\\d+)$"]]

modules/example/src/main/scala/example/model.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ import io.github.iltotore.iron.constraint.all.*
99

1010
type UsernameConstraint = (MinLength[3] & MaxLength[20]) `DescribedAs` "Must be between 3 and 20 characters"
1111
type Username = Username.T
12-
object Username extends RefinedType[String, UsernameConstraint]
12+
object Username extends RefinedSubtype[String, UsernameConstraint]
1313

1414
type AgeConstraint = (Positive & Less[150]) `DescribedAs` "Must be a positive number less than 150"
1515
type Age = Age.T
16-
object Age extends RefinedType[Int, AgeConstraint]
16+
object Age extends RefinedSubtype[Int, AgeConstraint]
1717

1818
type FirstNameConstraint = Not[Blank] `DescribedAs` "First name must not be blank"
1919
type FirstName = FirstName.T
20-
object FirstName extends RefinedType[String, FirstNameConstraint]
20+
object FirstName extends RefinedSubtype[String, FirstNameConstraint]
2121

2222
type LastNameConstraint = Not[Blank] `DescribedAs` "Last name must not be blank"
2323
type LastName = LastName.T
24-
object LastName extends RefinedType[String, LastNameConstraint]
24+
object LastName extends RefinedSubtype[String, LastNameConstraint]
2525

2626
type EmailConstraint = Match[".*@.*\\..*"] `DescribedAs` "Must be a valid e-mail"
2727
type Email = Email.T
28-
object Email extends RefinedType[String, EmailConstraint]
28+
object Email extends RefinedSubtype[String, EmailConstraint]
2929

3030
type CountryNameConstraint = Not[Blank] `DescribedAs` "Country name must not be blank"
3131
type CountryName = CountryName.T
32-
object CountryName extends RefinedType[String, CountryNameConstraint]
32+
object CountryName extends RefinedSubtype[String, CountryNameConstraint]
3333

3434
type CountryCodeConstraint = (FixedLength[2] & LettersUpperCase) `DescribedAs` "Country name must not be blank"
3535
type CountryCode = CountryCode.T
36-
object CountryCode extends RefinedType[String, CountryCodeConstraint]
36+
object CountryCode extends RefinedSubtype[String, CountryCodeConstraint]
3737

3838
case class Country(code: CountryCode, name: CountryName, niceName: String)
3939

modules/flags/src/main/scala/pillars/flags/model.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final case class FeatureFlag(name: Flag, status: Status):
1313
private type FlagConstraint = Not[Blank] `DescribedAs` "Name must not be blank"
1414
type Flag = Flag.T
1515

16-
object Flag extends RefinedType[String, FlagConstraint]
16+
object Flag extends RefinedSubtype[String, FlagConstraint]
1717

1818
enum Status:
1919
case Enabled, Disabled

0 commit comments

Comments
 (0)