AutoMapper TypeScript
by Chau Tran (@Nartc1410)
Agenda
- What is Object Mapping?
- What is AutoMapper? Why does it exist?
- Problems in TypeScript
- AutoMapper in TypeScript
- Q/A
Object Mapping
- Sometimes called Transformation
- ORM/ODM
Object Mapping
- DTOs
What is AutoMapper
- Original .NET AutoMapper
- Mapping by Convention
- Opinionated
Why?
- Alleviate the boring tasks of mapping from Domain Models to DTOs/View Models
- Separation of Concerns
- Conventions over Configurations
Demo Time
Problems in TypeScript
- Dynamic Typings
- Weak Reflection
- Inconsistent metadata with different tsconfig
Demo Time
AutoMapper in TypeScript
- @automapper monorepo with different packages
- @automapper utilizes plugin-based approach
- classes plugin to work with TS/ES6 Classes
- pojos plugin to work with plain objects + interfaces
- @automapper/nestjs is official NestJS integration
- Main target: TypeScript Node on the Server side (NestJS and others)
AutoMapper in TypeScript
Mapper
AutoMapper in TypeScript
Mapper
AutoMapper in TypeScript
Mapping
- Contract between a Source and a Destination
- Within a Mapper, a Mapping is unidirectionally unique
- Contains all mapping configurations for all members
AutoMapper in TypeScript
MappingProperty
- Each mapping configuration on Mapping is a MappingProperty
- Each MappingProperty contains the property name and its MappingTransformation
- "Auto" configuration vs Custom Configuration
AutoMapper in TypeScript
MappingTransformation
- Instruction on how Mapper should map a MappingProperty
- Based on different TransformationType
AutoMapper in TypeScript
TransformationType
AutoMapper in TypeScript
- More to explore on Github and official documentations
- Github repo: https://github.com/nartc/mapper
- Documentations: https://automapperts.netlify.app
Demo
Q/A
Thank you
AutoMapper TypeScript
By Chau Tran
AutoMapper TypeScript
This is the deck for AutoMapper TypeScript
- 897