7.3.14 (2022-03-05)
- mikro: use getEntity as unwrap value instead of recursion (292759c)
7.3.13 (2022-03-05)
- mikro: recursively unwrap collections (a445b3b)
7.3.12 (2022-03-05)
- mikro: run toJSON on reference (a5e2a67)
7.3.11 (2022-03-05)
- mikro: ensure preMapArray run instantiate correctly (7b2ef67)
7.3.10 (2022-02-26)
- mikro: serialize reference (attempt 2) (47da73e)
7.3.9 (2022-02-26)
- mikro: serialize reference (567bd73)
7.3.8 (2022-02-25)
- mikro: adjust instantiate logic (attempt 2) (6f6ae9f)
7.3.7 (2022-02-25)
- mikro: adjust instantiate logic (attempt) (75b4367)
7.3.6 (2022-02-25)
- mikro: allow entity serializer to be customizable (f4f7d29)
7.3.5 (2022-02-25)
- mikro: assign id before serialize entity (068d25b)
7.3.4 (2022-02-25)
- mikro: adjust instantiate logic (bcf004e)
7.3.3 (2022-02-25)
- mikro: skipping symbol (83494e6)
7.3.2 (2022-02-25)
- mikro: serialize entity in instantiate as well (635fba2)
7.3.1 (2022-02-25)
- mikro: serialize entity properly (4a18543)
7.3.0 (2022-02-25)
- mikro: add mikro plugin (6f52813)
- repo: use js:swc for all packages (03e4577)
7.2.1 (2022-01-11)
- classes, core: add ability to map Date[] types (#399) (cb27b1a), closes #397 #397
- core: relax addTypeConverter return to include undefined (20c250c)
- core: skip key that is a method in getPathRecursive (5a56529), closes #396
7.2.0 (2022-01-06)
7.1.1 (2021-12-23)
- core: fallback to primitive if constructor/function is undefined (ac5030f)
7.1.0 (2021-12-20)
- core: adjust typings to support more custom type converter (6ef280f)
7.0.3 (2021-12-19)
- core: improve error message for logging (c9db5c4)
7.0.2 (2021-11-12)
- classes: rename PrimitiveWithDate to PrimitiveExtended (34d8a52)
- core: change how File is handled in map (57df4ad)
- core: rename PrimitiveWithDate to PrimitiveExtended (4c299ff)
7.0.1 (2021-11-11)
- remove types from readme (31ab69f)
7.0.0 (2021-11-11)
- types: @automapper/types is removed
@automapper/types
has been removed and the types have been moved to @automapper/core
. This is to reduce the amount of libraries that the consumers have to install. The types themselves are untouched, you can probably fix this with a simple Find and Replace.
- classes: use core types (985def8)
- core: add isFileConstructor util (54d2b65)
- core: move types into core (62ffdc6)
- core: use local types (558782d)
- nestjs: use core types (a21f5a3)
- pojos: support File as a metadata constructor (0eafe05)
- pojos: use core types (d601da2)
- sequelize: use core types (35c28a8)
- test: use core types (f562ca0)
- types: moving types to core to retire @automapper/types (ccfcf94)
- add lookup types limitation on custom type converter (#370) (9ab6023)
- core: add documentations for forSelf (e896a22)
- pojos: clean up if check (0470fb3)
6.3.1 (2021-10-28)
- types: adjust type of Primitive type converter (f30b9c4)
- classes: clean up model visitor (1126755)
- update docs (e59ce14)
6.3.0 (2021-10-26)
6.2.1 (2021-09-21)
- core: ensure applyTypeConverter to work correctly (0f1b689)
6.2.0 (2021-09-21)
- classes: store source and destination on mapping; use .name instead of toString() (6b0530c)
- core: start storing Source and Destination keys on Mapping (73d19a3)
- core: support strong type extraArguments (0cd5119)
- pojos: store source and destination on mapping (2fd60bc)
- remove 'odd-property name' limitation (99e0efd)
6.1.4 (2021-09-10)
- transformer-plugin: try get typeReference and null check for property assignment (d447783)
6.1.3 (2021-08-30)
- core: ensure properties that aren't on destination won't be mapped from forSelf (390b8bb)
6.1.2 (2021-08-30)
- nestjs: make sure to support Nest7 as well (8235720)
6.1.1 (2021-08-27)
- core: ensure forMember (custom) will always override forSelf (ef7471a)
6.1.0 (2021-08-26)
- core: add forSelf (140a37c)
6.0.2 (2021-08-22)
6.0.1 (2021-08-16)
- add @jasonmerino as a contributor (809e447)
- classes: clean up typings (45edfda)
- core: clean up core libs (ddb11e5)
- core: remove some any types (cdc2f9a)
- pojos: clean up typings (f43705a)
6.0.0 (2021-08-02)
- core:
mapWith
signature now accepts the models directly instead of a deferred function. This allows to usemapWith
easier
// before
mapWith(
() => Dto,
(s) => s.value,
() => Source
);
// after
mapWith(Dto, Source, (s) => s.value);
- classes: AutoMap only accepts an optional config object now. Positional arguments overload has been removed
// deprecated and removed
@AutoMap(() => Foo)
// please migrate
@AutoMap({typeFn: () => Foo})
- classes: remove AutoMap without config object (95479ca)
- core: add basic TypeConverter for primitives (83fd239)
Sometimes, you need to set a common converter for one type to another when the property names are matching between a Source
and a Destination
. For example, suppose we have a Source
type:
export class Source {
@AutoMap()
value1!: string;
@AutoMap()
value2!: string;
@AutoMap()
value3!: string;
}
and you would like to map it to the following Destination
type:
export class Destination {
@AutoMap()
value1!: number;
@AutoMap()
value2!: Date;
@AutoMap()
value3!: boolean;
}
If we were to try and map Source -> Destination
as-is, we would end up with mismatch values and types on the Destination
. Eg: Source.value1
will be mapped to Destination.value1
even though the types of each value1
are different. Destination.value1
will end up with string
value even though it is declared as number
. This is because AutoMapper does not know anything and will not try to make any assumptions about these value types.
To solve this issue, you must supply Custom Type Converters to a specific Mapper
:
const mapper = createMapper(/*...*/);
mapper
.addTypeConverter(String, Number, (str) => parseInt(str))
.addTypeConverter(String, Date, (str) => new Date(str))
.addTypeConverter(String, Boolean, (str) => Boolean(str));
mapper.createMap(Source, Destination);
Here, we're telling AutoMapper:
- If you are mapping a
String
to aNumber
, useparseInt()
- If you are mapping a
String
to aDate
, usenew Date()
- If you are mapping a
String
to aBoolean
, useBoolean()
const source = new Source();
source.value1 = '123';
source.value2 = '10/14/1991';
source.value3 = 'truthy';
const destination = mapper.map(source, Destination, Source);
/**
* Destination {
value1: 123, // number
value2: Mon Oct 14 1991 00:00:00 GMT-0500 (Central Daylight Time), // a Date instance
value3; true // boolean
* }
*/
- core: adjust mapWith signature (2df08ac)
- core: fail fast when mapping is not found (95a196f)
- core: null check mapping before applying typeConverters (5d87147)
- core: null check mappingProp and nestedMappingPair before continue (850cafb)
- classes: always add metaResult to nestedConstructible (to account for primitives) (5717928)
- core: clean up createMapper with less null coalescing (cdcc39a)
- core: clean up initialize mappings (8239789)
- core: reformat map (81992a1)
- pojos: always add metaResult to nestedMetadata (to account for primitives) (00cce02)
- add Custom Type Converter (05f02a5)
- classes: add comment about limitation of array properties (#326) (866e311)
- classes: fix link issue (#327) (2030b50)
5.0.1 (2021-07-22)
- nestjs: bump peerDeps (11fbc5c)
5.0.0 (2021-07-22)
- Cutting a new major version due upgrade to NestJS v8
- core: extract setMemberReturn function (b67d5ee)
- add @huybn5776 as a contributor (2414b79)
- update docusaurus and adjust extend plugin example (023b67d), closes #320
4.2.2 (2021-07-08)
- classes: use cached length for loops (21435b7)
- core: use cached length for loops; misc. variable changes (697ee81)
- pojos: use cached length for loops (6740a5d)
4.2.1 (2021-07-02)
- core: only add writable property to unmappedKeys (aa565aa)
- add @robsonhermes as a contributor (04f5755)
- clean up whitespace (6e7d199)
- component: added required tsconfig switches for @AutoMap (#309) (7d6ab91), closes #307
- core: adjust typings (23f1fa0)
4.2.0 (2021-06-15)
4.1.0 (2021-06-09)
- add @micalevisk as a contributor (29500ad)
- add @AliYusuf95 as a contributor (956aceb)
- update docusaurus beta (9e09d67)
4.0.0 (2021-05-18)
- Upgrade to Nx 12.3.3
- upgrade Nx (ea0eff6)
- upgrade packages (329828e)
- core: add partial support for ES6 computed property names (#293) (93d3f66), closes #289
3.5.2 (2021-04-09)
- types: remove all named tuples to support TS <4 (9de3c72)
- classes: add more comments to AutoMap decorator (b00a01c)
3.5.1 (2021-04-09)
- classes: only save metadata if typeFn is not null (3f03f8c)
3.5.0 (2021-04-07)
- classes: add logic to handle getter only properties (d081ac6)
- classes:
AutoMap
decorator now accepts anAutoMapOptions
instead. The other usage have been marked deprecated.
class Foo {
// before
@AutoMap(() => Bar)
bar: Bar;
// after
@AutoMap({ typeFn: () => Baz })
baz: Baz;
}
- core: allow mapWithArguments to accept Resolver (8f1dfc6)
- core: move isResolver to utils (ea2bc42)
- update docs deps and add new docs (16719ff)
3.4.2 (2021-03-22)
- core: pass extraArguments down to nested mapping (10465be)
3.4.1 (2021-03-16)
- nestjs: fix memoize util (e56887b)
3.4.0 (2021-03-14)
- nestjs: add MapPipe to transform Query and Body (d8198e0)
- core: add non-null assertion to mapMemberFn[misc] when transformation type is MapFrom/MapWith (746e94e)
- add docs about MapPipe (8a8d673)
3.3.0 (2021-03-12)
- classes: expose getMetadataList as public API (b5bde21)
- classes/mapped-types: add Mapped Types (46e02ba)
3.2.2 (2021-03-06)
- sequelize: only run intiialize on sequelize model (05c3d82)
3.2.1 (2021-03-06)
- sequelize: make options optional (8355120)
3.2.0 (2021-03-06)
- core: use postMap if available (fb22792)
- sequelize: add postMap to instantiate a Model instance from map result (9552516)
- types: add postMap to MapPlugin (bbdd895)
3.1.0 (2021-03-06)
- classes: move all single functions to exported utils (219b917)
- core: make sure to bind plugin to preMap this context (19479a3)
- types: add instantiate to MapPlugin public API (53343f9)
- classes: expose Constructible type (2c3eaf0)
- classes: expose instantiate (b2dd592)
- pojos: expose instantiate as public API (528b193)
- sequelize: add sequelize plugin (b9105bb)
3.0.11 (2021-03-04)
- core: null check for source selector on MapFrom (a489d9c)
3.0.10 (2021-02-26)
- classes: make sure to reassign metadataList (ebd53dc)
3.0.9 (2021-02-26)
- core: use isEmpty to check for nested metakey instead of using length (0329e6e)
3.0.8 (2021-02-24)
- classes: clean up optional chaining operator on function calls (e6c3299)
- core: clean up optional chaining (d223d79)
- core: run beforeMap in mapArray with an empty array instead (2975071)
- nestjs: revert back to resolved Promise. nextTick seems to run a little behind (5a91c31)
- nestjs: use process.nextTick instead of resolved Promise (4dd8da6)
- pojos: clean up optional chaining operator on function calls (65304a7)
3.0.7 (2021-02-22)
3.0.6 (2021-02-21)
- experimental/transformer-plugin: adjust transformer plugin to have a workaround for ESM (1f862d0)
3.0.5 (2021-02-19)
- classes: merge metadata from Reflection and Factory fn (393a7d3)
- experimental/transformer-plugin: fix options (bac5074)
- experimental/transformer-plugin: adjust merging options with default options (c4c123b)
3.0.2 (2021-02-19)
3.0.1 (2021-02-19)
- experimental/transformer-plugin: move into classes (05aae8a)
3.0.0 (2021-02-19)
- classes: treat property as primitives if metaResult is null. Default Date to undefined if valueAtKey is undefined (8e17527), closes #254
- core: treat null metadata/Date same as null value aka just map the value. add logic for isNullMetadata to MappingPropert (97f260d)
- pojos: treat property as primitives if metaResult is null. Date member to be returned as undefined if valueAtKey is undefined (3e474ab)
- types: add isNullMetadata to MappingTransformation (a0b39d9)
- classes: add logic to take advantage of transformer plugin if used (f3aca21)
- experimental/transformer-plugin: add transformer plugin for classes package (67cdd29)
- pojos: allow to pass in null for createMetadataMap to treat something as primitives (7357ad5)
- pojos: Previously,
null
was used to skip properties. Now, usefalse
instead,null
means something else.
2.2.1 (2021-02-14)
- core: move isDateConstructor and isPrimitiveConstructor from plugins to core (997528b)
- core: utilize extraArguments in mapArray (ac5bb40)
- core: clean up misc (61f4f65)
- classes/pojos: use
isDateConstructor
andisPrimitiveConstructor
from core (b1dc211, 66a2f33)
2.2.0 (2021-02-14)
2.1.1 (2021-02-06)
- core: null/undefined check for source in map and mapArray (b37d29a)
2.1.0 (2021-02-03)
- adjust config (b074b21)
- classes: add AUTOMAP_PROPERTIES_METADATA_KEY to public api (1165380)
2.0.1 (2021-02-02)
2.0.0 (2021-01-31)
- enable strict mode (6456bec)
- classes: strict mode friendly (bac51e9)
- core: strict mode friendly (5178c3c)
- nestjs: strict mode friendly (64abad4)
- pojos: strict mode friendly (deedc1b)
- types: strict mode friendly (f8e6211)
- This release enables strict mode for automapper. The type is stricter which might affect your current implementations.
1.2.0 (2021-01-31)
- core: add logic to run preMapArray if available when invoking mapArray (f1f97f3)
- types: add MapArrayOptions and adjust mapArray signature (9d2df49)
- Add documentation on how to extend a plugin. Please check Docs for more information.
1.1.1 (2021-01-30)
- classes: ensure to use return value of concat() (705cbec)
1.1.0 (2021-01-30)
- classes: adjust code smell (cf53a1f)
- core: adjust code smell (736f58d)
- pojos: adjust code smell (4682fbf)
- core: better error message for mapping operation error (550d8e8)
1.0.4 (2021-01-29)
- nestjs: ensure mapper is safe for accessing with optional chaining (83307f5)
1.0.3 (2021-01-28)
- pojos: add Array to isPrimitiveConstructor. This is to match with the behavior in
classes
(6415463)
1.0.2 (2021-01-28)
1.0.1 (2021-01-25)
1.0.0 (2021-01-17)
Please check out README for more information
1.0.0-beta.9 (2021-01-11)
- nestjs: use
global
options inDynamicModule
forforRoot
instead of@Global
decorator (8f05d8f)
- nestjs: adjust globalNamingConventions options to also accept a single NamingConvention (822c790)
- nestjs: add MapInterceptor (1a811e5)
1.0.0-beta.8 (2021-01-09)
- core: adjust public API of core (d86af1d)
1.0.0-beta.7 (2021-01-08)
- core: adjust getFlatteningSourcePath to take into account multiple parts path with naming conventions (811568e)
1.0.0-beta.6 (2021-01-07)
- core: add ability to pass in destinationObj and mutate on map instead of return (46e920d)
- core: adjust set() to have setMutate() and not return (bdd6d17)
1.0.0-beta.5 (2021-01-05)
- classes: rename types.d.ts to types.ts to include with bundle (3a15f72)
- pojos: adjust typings for createMetadataMap (18cc504)
1.0.0-beta.4 (2021-01-05)
- core: remove properties added by istanbul for not failing in test coverage (1dcdcdb)
1.0.0-beta.3 (2021-01-04)
- classes: skip empty metadataList before looping (88ecf9c)
- core: check null and fail fast in getPathRecursive (449da22)
1.0.0-beta.2 (2021-01-04)
1.0.0-beta.1 (2021-01-04)
- core: adjust isDefined (6187453)