@nartc/automapper v7.0.4
AutoMapper
An object-to-object mapper by convention for TypeScript.
Migrations to v6
initialize()has been deprecated inv6. Please usecreateMap(),addProfile(), and/orwithGlobalSettings()directly- Mapping operations have been rewritten as individual functions to support tree-shaking, please migrate your
mapping configurationsto use those
// before
Mapper.createMap(Source, Destination)
.forMember(d => d.destMember, opts => opts.mapFrom(s => s.sourceMember);
// after
Mapper.createMap(Source, Destination)
.forMember(d => d.destMember, mapFrom(s => s.sourceMember))- Pre-Condition:
preCondition()is also a separate function. Use in v6 as follow
// before
Mapper.createMap(Source, Destination).forMember(
d => d.destMember,
opts => opts.preCondition(predicate).mapFrom(s => s.sourceMember)
);
// after
Mapper.createMap(Source, Destination).forMember(
d => d.destMember,
preCondition(predicate),
mapFrom(s => s.sourceMember)
);Migrations from automapper-nartc
The only migration step you need is to modify forMember() method.
In automapper-nartc, forMember() takes in a property string as the first argument. Now, forMember() in @nartc/automapper takes in a selector instead. This wil allow reverseMap() to work better.
// Before
Mapper.createMap(User, UserVm)
.forMember('fullName', opts => opts.mapFrom(...));
// Now
Mapper.createMap(User, UserVm)
.forMember(dest => dest.fullName, opts => opts.mapFrom(...));Migrations to v3
- Change
@Expose()and@ExposedType()to@AutoMap()
// Before
class User {
@Expose()
firstName: string;
@ExposedType(() => Profile)
profile: Profile;
}
// v3
class User {
@AutoMap()
firstName: string;
@AutoMap(() => Profile)
profile: Profile;
}Features
So far, the following is supported:
- Basic Mapping between two classes
- Basic Mapping for nested classes
- Mapping Inheritance - with caveats regarding typings.
- Array/List Mapping
- Flattening
- ReverseMap
- Value Converters
- Value Resolvers
- Async (Read more at Async Support)
- Before/After Callback
- Naming Conventions
Null Substitution - @lqmanh pointed out the difference in
fromValue()andnullSubstitution()use-case, and that difference is totally valid. Hence,nullSubstitutionis now supported.Circular Dependencies
- Tree-shakable
Unsupported features:
- Type Converters
- Value Transformers
Circular Dependencies
Please check out the Circular Dependencies Documentations
Documentations
Check out the AutoMapper TypeScript Documentations
Demo
Contribution
Contribution of any kind is always welcomed.
MIT License
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago