-
Notifications
You must be signed in to change notification settings - Fork 3
Mapper
Main class of the library.
It is usually used as a singleton, with an initial configuration.
The methods of the class are:
-
withConfiguration(mapperConfiguration: TMapperConfigurationSetter)
for the mapperConfiguration refer to the Mapper configuration page. -
createMap<Source, Destination>(signature: MapSignature, destination: { new(): Destination})
refer to Map and Map configuration -
map<Source, Destination>(signature: MapSignature, source: Source, destination?: Destination, mapActionConfiguration?: TMapConfigurationSetter)
for the mapActionConfiguration refer to Map action configuration page mapMany<Source, Destination>(signature: MapSignature, source: Source[], destination?: Destination[], mapActionConfiguration?: TMapConfigurationSetter)
For initiliazing a map or executing a map function a signature is required.
It is an object that represents the source class type and the destination class type.
Its shape is:
type MapSignature = {
source: symbol;
destination: symbol;
};
So, for each couple of source-destination types, a signature is required.
The withConfiguration
method lets you define a configuration for the mapper.
Read more in the Mapper configuration documentation page.
A map is a ruleset of properties that need to be mapped into the destination object.
The syntax of the method is:
createMap<Source, Destination>(signature: MapSignature, destinationEntity: { new(): Destination }): IMap<Source, Destination>
It requires a signature and the destination class itself.
e.g.
class Source {}
class Destination {}
createMap<Source, Destination>(signature: sourceDestinationSignature, Destination);
It returns a map object which can be configured to set properties that will be mapped.
Read more in the Operation configuration documentation page.
The map
method performs the mapping.
Its syntax is
map<Source, Destination>(signature: MapSignature, source: S, destination?: D, mapActionConfiguration?: TMapActionConfigurationSetter)
The signature and the source object are required.
If not set, the destination will be generated with a new
call.
Additional configuration for this action only can be set with the mapActionConfiguration function.
More info about the configuration in the Map action configuration documentation page.
The mapMany
method is the same as map, it just returns an array of destination instead a single one, if automatically map arrays is set to true
(default).
The mapArray
method has the same syntax of map
, but is used to map array of objects, even it automatically map arrays is set to false.