Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scalafmt-core to 3.8.6 #147

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

# Scala Steward: Reformat with scalafmt 3.8.1
702f0803380ce018d650c341b8875b6627b59841

# Scala Steward: Reformat with scalafmt 3.8.6
6c4d49e59539bf0ccb3bb0a580ddfa122e4d3cc6
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.8.5"
version = "3.8.6"
project.git = true
runner.dialect = scala3
align.preset = none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ case class MockedServiceResponse[
})

// be sure ServiceOut is set!
def unsafeBody: ServiceOut = respBody.toOption.get
def unsafeBody: ServiceOut = respBody.toOption.get
def headersAsMap: Map[String, String] =
respHeaders
.map(_.toList)
Expand Down Expand Up @@ -73,11 +73,11 @@ object MockedServiceResponse:
: InOutEncoder[MockedServiceResponse[ServiceOut]] =
Encoder.instance { response =>
Json.obj(
"respStatus" -> Json.fromInt(response.respStatus),
"respBody" -> (
"respStatus" -> Json.fromInt(response.respStatus),
"respBody" -> (
response.respBody match
case Right(value) => value.asJson.deepDropNullValues
case Left(err) => err.getOrElse(Json.Null)
case Left(err) => err.getOrElse(Json.Null)
),
"respHeaders" -> response.respHeaders
.map(_.map(Json.fromString))
Expand All @@ -89,8 +89,8 @@ object MockedServiceResponse:
: InOutDecoder[MockedServiceResponse[ServiceOut]] =
Decoder.instance { cursor =>
for
respStatus <- cursor.downField("respStatus").as[Int]
respBody <-
respStatus <- cursor.downField("respStatus").as[Int]
respBody <-
if respStatus < 300 then
cursor.downField("respBody").as[ServiceOut].map(Right(_))
else cursor.downField("respBody").as[Option[Json]].map(Left(_))
Expand Down
104 changes: 54 additions & 50 deletions 01-domain/src/main/scala/camundala/domain/exports.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,38 @@ import scala.language.implicitConversions
export io.circe.Codec as CirceCodec
export io.circe.{Decoder, HCursor, Json}

type InOutCodec[T] = io.circe.Codec[T]
type InOutCodec[T] = io.circe.Codec[T]
type InOutEncoder[T] = io.circe.Encoder[T]
type InOutDecoder[T] = io.circe.Decoder[T]

// Circe Enum codec

inline def deriveInOutCodec[A](using inline A: Mirror.Of[A]): InOutCodec[A] =
inline def deriveInOutCodec[A](using inline A: Mirror.Of[A]): InOutCodec[A] =
deriveInOutCodec("type")
inline def deriveInOutCodec[A](discriminator: String)(using inline A: Mirror.Of[A]): InOutCodec[A] =
io.circe.derivation.ConfiguredCodec.derived(using
Configuration.default // .withDefaults
.withDiscriminator(discriminator))
Configuration.default // .withDefaults
.withDiscriminator(discriminator)
)
inline def deriveInOutEncoder[A](using inline A: Mirror.Of[A]): InOutEncoder[A] =
deriveInOutEncoder("type")
inline def deriveInOutEncoder[A](discriminator: String)(using
inline A: Mirror.Of[A]
): InOutEncoder[A] =
io.circe.derivation.ConfiguredEncoder.derived(using
Configuration.default // .withDefaults
.withDiscriminator(discriminator))
Configuration.default // .withDefaults
.withDiscriminator(discriminator)
)
inline def deriveInOutDecoder[A](using inline A: Mirror.Of[A]): InOutDecoder[A] =
deriveInOutDecoder("type")

inline def deriveInOutDecoder[A](discriminator: String)(using
inline A: Mirror.Of[A]
): InOutDecoder[A] =
io.circe.derivation.ConfiguredDecoder.derived(using
Configuration.default // .withDefaults
.withDiscriminator(discriminator))
Configuration.default // .withDefaults
.withDiscriminator(discriminator)
)

inline def deriveEnumInOutCodec[A](using inline A: Mirror.SumOf[A]): InOutCodec[A] =
given Configuration = Configuration.default
Expand All @@ -70,7 +73,7 @@ def customDecodeAccumulating[T](c: HCursor)(using InOutDecoder[T]): Either[Decod
.left.map:
case err if err.size == 1 =>
err.head
case errors =>
case errors =>
errors.head.copy(
message =
errors.foldLeft("")((result, error) =>
Expand Down Expand Up @@ -108,14 +111,14 @@ given InOutCodec[IntOrString] = CirceCodec.from(
new Encoder[IntOrString]:
final def apply(a: IntOrString): Json = a match
case s: String => Json.fromString(s)
case i: Int => Json.fromInt(i)
case i: Int => Json.fromInt(i)
)
type IntOrString = Int | String
given ApiSchema[IntOrString] = Schema.derivedUnion
given ApiSchema[IntOrString] = Schema.derivedUnion

type IntOrBoolean = Int | Boolean

given ApiSchema[IntOrBoolean] = Schema.derivedUnion
given ApiSchema[IntOrBoolean] = Schema.derivedUnion
given InOutCodec[IntOrBoolean] = CirceCodec.from(
new Decoder[IntOrBoolean]:
final def apply(c: HCursor): Decoder.Result[IntOrBoolean] =
Expand All @@ -126,60 +129,60 @@ given InOutCodec[IntOrBoolean] = CirceCodec.from(
new Encoder[IntOrBoolean]:
final def apply(a: IntOrBoolean): Json = a match
case s: Boolean => Json.fromBoolean(s)
case i: Int => Json.fromInt(i)
case i: Int => Json.fromInt(i)
)

case class NoInput()
object NoInput:
given ApiSchema[NoInput] = deriveApiSchema
given ApiSchema[NoInput] = deriveApiSchema
given InOutCodec[NoInput] = deriveCodec

case class NoConfig()
object NoConfig:
given ApiSchema[NoConfig] = deriveApiSchema
given ApiSchema[NoConfig] = deriveApiSchema
given InOutCodec[NoConfig] = deriveCodec

case class NoOutput()
object NoOutput:
given ApiSchema[NoOutput] = deriveApiSchema
given ApiSchema[NoOutput] = deriveApiSchema
given InOutCodec[NoOutput] = deriveCodec

enum ProcessStatus:
case succeeded, `output-mocked`, failed, notValid, canceled
object ProcessStatus:
given ApiSchema[ProcessStatus] = deriveEnumApiSchema
given ApiSchema[ProcessStatus.succeeded.type] = deriveEnumApiSchema
given ApiSchema[ProcessStatus.`output-mocked`.type] = deriveEnumApiSchema
given ApiSchema[ProcessStatus.failed.type] = deriveEnumApiSchema
given ApiSchema[ProcessStatus.notValid.type] = deriveEnumApiSchema
given ApiSchema[ProcessStatus.canceled.type] = deriveEnumApiSchema
given InOutCodec[ProcessStatus] = deriveEnumInOutCodec
given InOutCodec[ProcessStatus.succeeded.type] = deriveEnumValueInOutCodec
given ApiSchema[ProcessStatus] = deriveEnumApiSchema
given ApiSchema[ProcessStatus.succeeded.type] = deriveEnumApiSchema
given ApiSchema[ProcessStatus.`output-mocked`.type] = deriveEnumApiSchema
given ApiSchema[ProcessStatus.failed.type] = deriveEnumApiSchema
given ApiSchema[ProcessStatus.notValid.type] = deriveEnumApiSchema
given ApiSchema[ProcessStatus.canceled.type] = deriveEnumApiSchema
given InOutCodec[ProcessStatus] = deriveEnumInOutCodec
given InOutCodec[ProcessStatus.succeeded.type] = deriveEnumValueInOutCodec
given InOutCodec[ProcessStatus.`output-mocked`.type] = deriveEnumValueInOutCodec
given InOutCodec[ProcessStatus.failed.type] = deriveEnumValueInOutCodec
given InOutCodec[ProcessStatus.notValid.type] = deriveEnumValueInOutCodec
given InOutCodec[ProcessStatus.canceled.type] = deriveEnumValueInOutCodec
given InOutCodec[ProcessStatus.failed.type] = deriveEnumValueInOutCodec
given InOutCodec[ProcessStatus.notValid.type] = deriveEnumValueInOutCodec
given InOutCodec[ProcessStatus.canceled.type] = deriveEnumValueInOutCodec
end ProcessStatus

@deprecated("Use _ProcessStatus_")
enum ProcessEndStatus:
case succeeded, `output-mocked`
object ProcessEndStatus:
given ApiSchema[ProcessEndStatus] = deriveEnumApiSchema
given ApiSchema[ProcessEndStatus] = deriveEnumApiSchema
given InOutCodec[ProcessEndStatus] = deriveEnumInOutCodec

@deprecated("Use _ProcessStatus_")
enum NotValidStatus:
case notValid, canceled
object NotValidStatus:
given ApiSchema[NotValidStatus] = deriveEnumApiSchema
given ApiSchema[NotValidStatus] = deriveEnumApiSchema
given InOutCodec[NotValidStatus] = deriveEnumInOutCodec

@deprecated("Use _ProcessStatus_")
enum CanceledStatus:
case canceled
object CanceledStatus:
given ApiSchema[CanceledStatus] = deriveEnumApiSchema
given ApiSchema[CanceledStatus] = deriveEnumApiSchema
given InOutCodec[CanceledStatus] = deriveEnumInOutCodec

@deprecated
Expand All @@ -194,8 +197,9 @@ object GenericServiceIn:
val name = serviceName.split("-")
.last
if Seq("get", "post", "put", "delete").contains(name.toLowerCase)
then serviceName // keep the name as it is
then serviceName // keep the name as it is
else name
end shortServiceName

end GenericServiceIn

Expand All @@ -209,7 +213,7 @@ case class FileInOut(
end FileInOut

object FileInOut:
given ApiSchema[FileInOut] = deriveApiSchema
given ApiSchema[FileInOut] = deriveApiSchema
given InOutCodec[FileInOut] = deriveCodec

/** In Camunda 8 only json is allowed!
Expand All @@ -222,7 +226,7 @@ case class FileRefInOut(
)

object FileRefInOut:
given ApiSchema[FileRefInOut] = deriveApiSchema
given ApiSchema[FileRefInOut] = deriveApiSchema
given InOutCodec[FileRefInOut] = deriveCodec

// Use this in the DSL to avoid Option[?]
Expand All @@ -231,22 +235,22 @@ case class Optable[Out](value: Option[Out])

object Optable:
given fromOpt[T]: Conversion[Option[T], Optable[T]] = Optable(_)
given fromValue[T]: Conversion[T, Optable[T]] = v => Optable(Option(v))
given fromValue[T]: Conversion[T, Optable[T]] = v => Optable(Option(v))

//json
def throwErr(err: String) =
throw new IllegalArgumentException(err)

def toJson(json: String): Json =
parser.parse(json) match
case Right(v) => v.deepDropNullValues
case Right(v) => v.deepDropNullValues
case Left(exc) =>
throwErr(s"Could not create Json from your String -> $exc")
val testModeDescr =
val testModeDescr =
"This flag indicades that this is a test - in the process it can behave accordingly."

// descriptions
val deprecatedDescr =
val deprecatedDescr =
"See https://pme123.github.io/camundala/specification.html#supported-general-variables"
@deprecated("Change to serviceTask")
def serviceNameDescr(serviceName: String) =
Expand Down Expand Up @@ -300,7 +304,7 @@ def outputServiceMockDescr[ServiceOut: InOutEncoder](mock: ServiceOut) =
|""".stripMargin

@deprecated(deprecatedDescr)
val handledErrorsDescr =
val handledErrorsDescr =
"A comma separated list of HTTP-Status-Codes, that are modelled in the BPMN as Business-Exceptions - see Outputs. z.B: `404,500`"
val regexHandledErrorsDescr =
"""If you specified _handledErrors_, you can specify Regexes that all must match the error messages.
Expand All @@ -317,7 +321,7 @@ extension (str: String)
val result = str.foldLeft(""):
case r -> c if c.isUpper =>
s"$r $c"
case r -> c =>
case r -> c =>
s"$r$c"
result.split("-")
.map: p =>
Expand All @@ -326,32 +330,32 @@ extension (str: String)
end niceName
end extension

def prettyUriString(uri: Uri) =
def prettyUriString(uri: Uri) =
URLDecoder.decode(
uri.toString,
Charset.defaultCharset()
)
def prettyString(obj: Any, depth: Int = 0, paramName: Option[String] = None): String =
val indent = " " * depth
val prettyName = paramName.fold("")(x => s"$x: ")
val ptype = obj match
val indent = " " * depth
val prettyName = paramName.fold("")(x => s"$x: ")
val ptype = obj match
case _: Iterable[Any] => ""
case obj: Product => obj.productPrefix
case _ => obj.toString
case obj: Product => obj.productPrefix
case _ => obj.toString
val nameWithType = s"\n$indent$prettyName$ptype"

obj match
case None => ""
case Some(value) => s"${prettyString(value, depth, paramName)}"
case uri: Uri => s"\n$indent$prettyName${prettyUriString(uri)}"
case None => ""
case Some(value) => s"${prettyString(value, depth, paramName)}"
case uri: Uri => s"\n$indent$prettyName${prettyUriString(uri)}"
case seq: Iterable[Any] =>
val seqStr = seq.map(prettyString(_, depth + 1))
if seqStr.isEmpty then "" else s"$nameWithType[${seqStr.mkString}\n$indent]"
case obj: Product =>
case obj: Product =>
val objStr = (obj.productIterator zip obj.productElementNames)
.map { case (subObj, paramName) => prettyString(subObj, depth + 1, Some(paramName)) }
if objStr.isEmpty then s"$nameWithType" else s"$nameWithType{${objStr.mkString}\n$indent}"
case _ =>
case _ =>
s"$nameWithType"
end match
end prettyString
5 changes: 2 additions & 3 deletions 01-domain/src/test/scala/camundala/domain/EnumValueTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package camundala.domain
import io.circe.*
import io.circe.Decoder.Result


class EnumValueTest extends munit.FunSuite:

inline def deriveEnumValueEncoder[A]: Encoder[A] =
Expand All @@ -20,7 +19,7 @@ class EnumValueTest extends munit.FunSuite:
CirceCodec.from(deriveEnumValueDecoder[A], deriveEnumValueEncoder[A])

test("CmsTest encode and decode enum type"):
val obj = MyClass(MyEnum.Y)
val obj = MyClass(MyEnum.Y)
val json = obj.asJson
assertEquals(Json.obj("processStatus" -> Json.fromString("Y")), json)
assertEquals(Right(obj), json.as[MyClass])
Expand All @@ -31,7 +30,7 @@ class EnumValueTest extends munit.FunSuite:

case class MyClass(processStatus: MyEnum.Y.type)
object MyClass:
given InOutCodec[MyClass] = deriveInOutCodec
given InOutCodec[MyClass] = deriveInOutCodec
given InOutCodec[MyEnum.Y.type] = deriveEnumValueInOutCodec

enum MyEnum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ case class TestWithMock(
)

object TestWithMock:
given ApiSchema[TestWithMock] = deriveApiSchema
given ApiSchema[TestWithMock] = deriveApiSchema
given InOutCodec[TestWithMock] = deriveCodec
end TestWithMock

case class Error(msg: String = "failed")
object Error:
given ApiSchema[Error] = deriveApiSchema
given ApiSchema[Error] = deriveApiSchema
given InOutCodec[Error] = deriveCodec
end Error

case class Success(ok: String = "hello")

object Success:
given ApiSchema[Success] = deriveApiSchema
given ApiSchema[Success] = deriveApiSchema
given InOutCodec[Success] = deriveCodec
end Success
6 changes: 3 additions & 3 deletions 02-bpmn/src/main/scala/camundala/bpmn/BpmnProcessDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ trait BpmnProcessDsl extends BpmnDsl:
def process[
In <: Product: InOutEncoder: InOutDecoder: Schema,
Out <: Product: InOutEncoder: InOutDecoder: Schema,
InitIn <: Product: InOutEncoder: Schema,
InitIn <: Product: InOutEncoder: Schema
](
in: In = NoInput(),
out: Out = NoOutput(),
initIn: InitIn = NoInput(),
initIn: InitIn = NoInput()
): Process[In, Out, InitIn] =
Process(InOutDescr(processName, in, out, Some(description)), initIn, processLabels)

def process[
In <: Product: InOutEncoder: InOutDecoder: Schema,
Out <: Product: InOutEncoder: InOutDecoder: Schema
Expand Down
Loading
Loading