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

WIP: Unused field policies, Merging transformations, Recursive Patchers #614

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from

Conversation

MateuszKubuszok
Copy link
Member

@MateuszKubuszok MateuszKubuszok commented Oct 3, 2024

This PR will implement the long awaited:

  1. transformations from more than 1 value - Support for mapping multiple case classes #115
  2. setting policy for unused fields/unmatched subtypes - Policy for checking which fields were used for transformation #248
  3. using the 2 above to reimplement Patchers - Rewrite Patchers as a special case of multiple case classes mapping #538
  4. enhance Patchers:
    1. make them recursive - Nested patchers don't work with subset of fields #119
    2. allow using implicit Patcher in nested fields - Support nested patchers that look for implicits #133
    3. allow using custom logic for setting fields - Support custom patching logic #134
    4. allow ignoring some fields in Patch - Allow to ignore specific field in patchers #161, Patching from another instance of the same case class #57

No ETA at the moment.

Plan

  1. kick-off policies
  2. kick off fallbacks
  3. implement product to product merge
  4. impliment Optional values merge
  5. reimplement Patchers special case as special case of merging transformtion
  6. add support to corresponding merges and Patchers rules at once
  7. more detailed tests and docs last

Progress

  • unused field policy/unmatched subtype policy - Policy for checking which fields were used for transformation #248

    • unused fields
      • add flags
      • add DSL
      • parse new flags
      • use new flags
      • test new flags
      • add withFieldUnused to suppress errors per field with policy enabled
      • test suppressing
      • mkdocs
      • scaladocs + mkdocs links
    • unmatched subtypes
      • add flags
      • add DSL
      • parse new flags
      • use new flags
      • test new flags
      • add withSubtypeUnmatched to suppress errors per subtype with policy enabled
      • test suppressing
      • mkdocs
      • scaladocs + mkdocs links
  • merging transformations - Support for mapping multiple case classes #115

    • add Fallback to TransformerOverrides
    • add withFallback DSL method
    • add withFallbackFrom DSL method
    • add val fallbacks: List[(Path, ExistentialExpr)] to TransformationContext
    • parse TransformerOverrides.Fallback type in TransformerConfiguration
    • add ability to update fallbacks list next to src: Expr[From] in recursion
    • new mkdocs section
    • ProductToProduct
      • lazily, obtain extractors for each fallback
      • find first extractor matching to pass value down in field resolution
      • convert current type's fallbacks list into a fallback list for the handled field
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • OptionToOption/ToOption/UnwrapOption
      • add a flag to decide how option should be handled: source only, orElse chain
      • filter out non-Option fallbacks for recursion, leave others
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • IterableToIterable/MapToMap
      • add a flag to decide how collections should be treated: source only, append
      • filter-out collection-fallbacks for recursion, leave other
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • EitherToEither
      • Either orElse (with 2.12 workaround)
      • add a flag to decide how option should be handled: source only, orElse chain
      • filter out non-Either fallbacks for recursion, leave others
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • SealedToSealed
      • sealed to sealed - pass fallbacks unchanged
      • product + exactly one sealed fallback - match on fallback BUT keep order of values to merge
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • AnyVal rules
      • unwrap fallbacks
      • tests
      • mkdocs
      • scaladocs + mkdocs links
  • recursive Patchers - Rewrite Patchers as a special case of multiple case classes mapping #538, Nested patchers don't work with subset of fields #119, Support nested patchers that look for implicits #133

    • translate PatchingContext -> TransformationContext
    • override rules (add implicit Patcher rule!)
    • delegate patching to merging transformations
    • new section in mkdocs
    • providing custom patching values - Support custom patching logic #134
      • withFieldConst+withFieldComputed
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • ignoring patcher fields - Allow to ignore specific field in patchers #161, Patching from another instance of the same case class #57
      • withFieldUnused
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • scoped flags
      • withPatchedFlag
      • mkdocs
      • scaladocs + mkdocs links
      • tests
    • Products
      • new rule
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • Options
      • new rule
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • collections
      • new rule
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • Eithers
      • new rule
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • sealed
      • new rule
      • tests
      • mkdocs
      • scaladocs + mkdocs links
  • other docs

    • update all @since TODO
    • make sure all new DSL types have scaladoc
    • update landing page with merged and patchers
    • update feature list
    • update macro settings section
    • update Ducktape section - allMatching can we replaced with merge transformers in many cases
    • update under the hood

Copy link

codecov bot commented Jan 5, 2025

Codecov Report

Attention: Patch coverage is 71.55361% with 260 lines in your changes missing coverage. Please review.

Project coverage is 84.52%. Comparing base (19d7233) to head (7d8e346).

Files with missing lines Patch % Lines
...letime/derivation/transformer/Configurations.scala 57.83% 70 Missing ⚠️
.../rules/TransformIterableToIterableRuleModule.scala 49.25% 34 Missing ⚠️
...rmer/rules/TransformEitherToEitherRuleModule.scala 53.70% 25 Missing ⚠️
...rmSealedHierarchyToSealedHierarchyRuleModule.scala 31.03% 20 Missing ⚠️
...ey/internal/compiletime/ChimneyTypesPlatform.scala 67.27% 18 Missing ⚠️
...ey/internal/compiletime/ChimneyTypesPlatform.scala 59.09% 18 Missing ⚠️
...ransformer/rules/TransformMapToMapRuleModule.scala 76.00% 12 Missing ⚠️
...etime/dsl/PartialTransformerDefinitionMacros.scala 41.17% 10 Missing ⚠️
...laland/chimney/dsl/TransformerTargetFlagsDsl.scala 37.50% 10 Missing ⚠️
...nd/chimney/internal/compiletime/fp/Implicits.scala 45.45% 6 Missing ⚠️
... and 15 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #614      +/-   ##
==========================================
- Coverage   86.40%   84.52%   -1.89%     
==========================================
  Files         160      168       +8     
  Lines        6872     7588     +716     
  Branches      577      714     +137     
==========================================
+ Hits         5938     6414     +476     
- Misses        934     1174     +240     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MateuszKubuszok MateuszKubuszok force-pushed the merging-transformations branch from d2f1c6d to 0d8b516 Compare January 7, 2025 13:03
@MateuszKubuszok MateuszKubuszok changed the title WIP: Merging transformations WIP: Unused field policies, Merging transformations Jan 13, 2025
@MateuszKubuszok MateuszKubuszok changed the title WIP: Unused field policies, Merging transformations WIP: Unused field policies, Merging transformations, Recursive Patchers Jan 14, 2025
@MateuszKubuszok MateuszKubuszok force-pushed the merging-transformations branch from 3b2e151 to fb092d6 Compare January 15, 2025 17:32
@MateuszKubuszok MateuszKubuszok force-pushed the merging-transformations branch from fb092d6 to 643a60b Compare January 16, 2025 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment