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

Add headers type #956

Merged
merged 17 commits into from
Sep 6, 2024
Merged

Conversation

geirolz
Copy link
Collaborator

@geirolz geirolz commented May 28, 2024

Here a recap of what's inside this PR:

❓Why so many files involved❓

  • I've extracted some classes from the model object, that has grown and became too large to handle, into model package, no breaking changes

🔄 Changes:

  • Add Headers type, a wrapper of Map[String, AmqpFieldValue] to provide utils
  • Add HeaderKey = String type alias.
  • Add AmqpFieldDecoder and AmqpFieldEncoder to decode and encode AmqpFieldValue values into scala types.
  • Add := syntax to HeaderKey in order to create a tuple of (HeaderKey, AmqpFieldValue) encoding a generic T into a AmqpFieldValue using an implicit AmqpFieldEncoder
  • Add .asAmqpFieldValue syntax to any A to encode them into AmqpFieldValue using an implicit AmqpFieldEncoder
  • Add .as[T] syntax to AmqpFieldValue to decode it to a generic T using an implicit AmqpFieldDecoder
  • Deprecates all type-specific method in EnvelopeDecoder (stringHeader, etc..) in favor of headerAs[IO, T]

💥 Breaking changes:

  • AmqpProperties now accept and return an instance of Headers instead of a Map[String, AmqpFieldValue]. The map will be accessible in any case using the .toMap method which exposes the underlying map

Some examples:

import dev.profunktor.fs2rabbit.model.Headers
 
val headers = Headers(
      "x-custom-header"   := "value", // StringVal
      "x-custom-header-2" := 123 // IntVal
)
.updated("x-custom-header-3", 123L) // LongVal
.remove("x-custom-header-3")

/**
* OR
*   val headers = Headers(
*    "x-custom-header" -> StringVal("value"),
*    "x-custom-header-2" -> IntVal(123)
*   )
*   .updated("x-custom-header-3", LongVal(123L))
*   .remove("x-custom-header-3")
* */

headers.get[IO]("x-custom-header") // IO(StringVal("value"))
headers.getOpt("x-custom-header") // Some(StringVal("value"))

headers.getAs[IO, String]("x-custom-header") // IO("value")
headers.getOptAs[String]("x-custom-header") // Some("value")
headers.getOptAsF[IO, Int]("x-custom-header-2") // IO(Some(123))

@geirolz geirolz force-pushed the add-headers-type-and-conversions branch 2 times, most recently from e4e94db to b76fa35 Compare June 4, 2024 14:03
@geirolz geirolz self-assigned this Jun 4, 2024
@geirolz geirolz requested a review from matejcerny June 4, 2024 14:22
@geirolz geirolz mentioned this pull request Jun 4, 2024
@matejcerny
Copy link
Collaborator

Quite big, not sure if I have time soon for it 😞

@geirolz
Copy link
Collaborator Author

geirolz commented Jun 4, 2024

Quite big, not sure if I have time soon for it 😞

Np, let's release now and have a look to this when you have time.
I've changed a lot but I introduced just one braking change, AmqpProperties now wants an instance of Headers instead of Map. I'll try to summarize all changes in the description in order to simplify the review

@geirolz
Copy link
Collaborator Author

geirolz commented Jun 5, 2024

@matejcerny I've updated the description. I hope it helps

@geirolz geirolz added this to the 5.3.0 milestone Sep 4, 2024
@geirolz geirolz force-pushed the add-headers-type-and-conversions branch from 6c97ade to d808bd1 Compare September 4, 2024 12:50
@geirolz geirolz merged commit c8a1c57 into profunktor:master Sep 6, 2024
3 checks passed
@geirolz geirolz deleted the add-headers-type-and-conversions branch September 6, 2024 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants