bc-node-sdk
Version:
BetterCommerce's NodeJS SDK encapsulates the base framework for all the Next.js applications.
24 lines (23 loc) • 1.13 kB
TypeScript
import { MappingRule } from "../../domain/types";
export default class Mapper<T, U> {
private mappingRules;
/**
* Creates a new instance of the mapper with the given mapping rules.
*
* @param {MappingRule<T, U>} mappingRules The mapping rules to be used by the mapper.
*/
constructor(mappingRules: MappingRule<T, U>);
/**
* Maps an entity of type T to an object of type U using the mapping rules specified during the
* creation of the mapper. The mapping rules are used to extract values from the entity and
* assign them to the corresponding properties of the mapped object. If a mapping rule returns
* an object, the method will recursively call itself to map the object. If a mapping rule
* returns an array of objects, the method will map each object in the array. If a mapping rule
* returns a primitive value, the method will assign the value to the corresponding property of
* the mapped object.
*
* @param {T} entity The entity to be mapped.
* @returns {U} The mapped object.
*/
map(entity: T): U;
}