Skip to content

refactor(mapper): rename methods from ToItem/FromItem to FromModel/ToModel#46

Closed
j-d-ha wants to merge 2 commits intomainfrom
refactor/update-naming-convention
Closed

refactor(mapper): rename methods from ToItem/FromItem to FromModel/ToModel#46
j-d-ha wants to merge 2 commits intomainfrom
refactor/update-naming-convention

Conversation

@j-d-ha
Copy link
Collaborator

@j-d-ha j-d-ha commented Jan 15, 2026

🚀 Pull Request

📋 Summary

This PR implements a comprehensive refactoring to change the naming convention for mapper methods from FromItem/ToItem to FromModel/ToModel with semantic reversal:

  • ToItemFromModel (Model → DynamoDB mapping)
  • FromItemToModel (DynamoDB → Model mapping)
  • Hook names also reversed: BeforeToItemBeforeFromModel, AfterToItemAfterFromModel, etc.

This makes the API more intuitive by naming methods based on their relationship TO or FROM the model (domain object), rather than the DynamoDB item representation.


🔧 Changes Made

Phase 1: Generator & Runtime Code (12 files)

  • Updated all core generator files:
    • MapperClassInfo.cs - Swapped method detection logic and renamed properties
    • GeneratorContext.cs - Renamed context flags (HasFromModelMethod, HasToModelMethod)
    • PropertyMappingSpecBuilder.cs - Renamed all builder methods
    • PropertyMappingCodeRenderer.cs - Updated rendering methods
    • Mapper.scriban - Updated template variables
    • MapperEmitter.cs - Updated data passed to template
    • TypeMappingStrategyResolver.cs - Updated context flag references
  • Updated runtime IgnoreMapping.cs XML documentation

Phase 2: Test Files (25 files)

  • Updated 3 test class files with new method names
  • Updated all 22 verified snapshot files
  • Fixed property names in DynamoIgnoreVerifyTests (IgnoreInFromModel/IgnoreInToModel)

Phase 3: Example Projects (5 files)

  • Updated DynamoMapper.SimpleExample/Program.cs
  • Updated DynamoMapper.FieldLevelOverride/Program.cs
  • Fixed 3 temp files

Phase 4: Documentation (12 files)

  • Updated README.md, CLAUDE.md
  • Updated all files in docs/:
    • getting-started/, core-concepts/, usage/, examples/, roadmap/
  • Updated hook names throughout documentation
  • Updated dynamo-field-attribute-checklist.md

✅ Checklist

  • My changes build cleanly
  • I've added/updated relevant tests (all 22 generator tests passing)
  • I've added/updated documentation or README
  • I've followed the coding style for this project
  • I've tested the changes locally (all tests passing)

🧪 Test Results

  • ✅ Build succeeded with 0 errors (3 warnings in temp files)
  • ✅ All 22 generator tests passing
  • ✅ All 192 runtime tests passing

💬 Notes for Reviewers

Breaking Change

This is a MAJOR breaking change:

  • All existing mapper classes must update method names from ToItem/FromItem to FromModel/ToModel
  • Hook method names must be updated if used
  • Generated code structure changes completely

Key Design Decision

The refactoring uses semantic reversal rather than simple renaming:

  • Methods starting with "To" prefix (e.g., ToModel) now map DynamoDB → Model
  • Methods starting with "From" prefix (e.g., FromModel) now map Model → DynamoDB
  • The method prefix constants (ToMethodPrefix = "To", FromMethodPrefix = "From") remain unchanged, but their semantic interpretation is reversed

This aligns the naming with the model-centric design philosophy where methods are described relative to the model, not the item representation.

Files Changed

51 files changed, 507 insertions(+), 487 deletions(-)

Recommendation

Consider bumping version to 0.2.0-alpha or 1.0.0 to reflect the breaking change.

- Renamed methods to ensure clearer and standardized naming conventions.
- Changed `ToItem` to `FromModel`, and `FromItem` to `ToModel`.
- Updated related tests, documentation, and snapshots to reflect this change.
- Adjusted parameter/property names and method signatures accordingly.
- Fixed improper formatting in `TypeMappingStrategyResolver` for nullable enums.
- Resolved misplacement of enum name in the expression.
Copy link
Contributor

@ncipollina ncipollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM

@j-d-ha j-d-ha closed this Jan 15, 2026
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