### Install Dependencies Source: https://github.com/nartc/mapper/blob/main/CONTRIBUTING.md Run this command to install all project dependencies using pnpm. ```bash pnpm install ``` -------------------------------- ### Install automapper/sequelize with npm Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/strategies/sequelize.mdx Install the core, classes, and sequelize packages using npm. ```shell npm i @automapper/core @automapper/classes @automapper/sequelize ``` -------------------------------- ### Install @automapper/core Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/api/core/index.md Install the core package using npm or yarn. ```sh npm i @automapper/core ``` ```sh yarn add @automapper/core ``` -------------------------------- ### Install Core Module with Pojo Strategy (yarn) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install the core module and the pojos strategy using yarn. ```shell yarn add @automapper/core @automapper/pojos # for pojos ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/nartc/mapper/blob/main/packages/documentation/README.md Installs all necessary project dependencies using Yarn. ```bash yarn ``` -------------------------------- ### Install Core Module with Pojo Strategy (npm) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install the core module and the pojos strategy using npm. ```shell npm i @automapper/core @automapper/pojos # for pojos ``` -------------------------------- ### Install @automapper/pojos Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/api/pojos/index.md Install the @automapper/pojos package using npm or yarn. ```sh npm i @automapper/pojos ``` ```sh yarn add @automapper/pojos ``` -------------------------------- ### Install ORM Support with MikroORM (yarn) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install core, classes strategy, reflect-metadata, and MikroORM support using yarn. ```shell yarn add @automapper/core @automapper/classes reflect-metadata @automapper/mikro # for mikro-orm ``` -------------------------------- ### Install @automapper/core and @automapper/pojos Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/strategies/pojos.mdx Install the necessary packages for using the POJOs strategy with Automapper. ```shell npm i @automapper/core @automapper/pojos ``` ```shell yarn add @automapper/core @automapper/pojos ``` -------------------------------- ### Start Local Development Server Source: https://github.com/nartc/mapper/blob/main/packages/documentation/README.md Starts a local development server for live previewing changes. The server automatically reloads on file changes. ```bash yarn start ``` -------------------------------- ### Install ORM Support with MikroORM (npm) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install core, classes strategy, reflect-metadata, and MikroORM support using npm. ```shell npm i @automapper/core @automapper/classes reflect-metadata @automapper/mikro # for mikro-orm ``` -------------------------------- ### Install @automapper/nestjs Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/api/nestjs/index.md Install the @automapper/nestjs package using npm or yarn. ```sh npm i @automapper/nestjs ``` ```sh yarn add @automapper/nestjs ``` -------------------------------- ### Install Core Module with Classes Strategy (yarn) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install the core module and the classes strategy using yarn. Requires reflect-metadata. ```shell yarn add @automapper/core @automapper/classes reflect-metadata # for classes ``` -------------------------------- ### Install @automapper/core with yarn Source: https://github.com/nartc/mapper/blob/main/packages/core/src/README.md Use this command to install the core package using yarn. ```sh yarn add @automapper/core ``` -------------------------------- ### Install ORM Support with Sequelize (yarn) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install core, classes strategy, reflect-metadata, and Sequelize support using yarn. ```shell yarn add @automapper/core @automapper/classes reflect-metadata @automapper/sequelize # for sequelize ``` -------------------------------- ### Install NestJS Integration with Classes (yarn) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install core, NestJS, classes strategy, and reflect-metadata using yarn. ```shell yarn add @automapper/core @automapper/nestjs @automapper/classes reflect-metadata # for classes ``` -------------------------------- ### Install @automapper/classes Source: https://github.com/nartc/mapper/blob/main/packages/classes/src/README.md Install the @automapper/classes package using npm or yarn. ```sh npm i @automapper/classes ``` ```sh yarn add @automapper/classes ``` -------------------------------- ### Install Core Module with Classes Strategy (npm) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install the core module and the classes strategy using npm. Requires reflect-metadata. ```shell npm i @automapper/core @automapper/classes reflect-metadata # for classes ``` -------------------------------- ### Install automapper/sequelize with yarn Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/strategies/sequelize.mdx Install the core, classes, and sequelize packages using yarn. ```shell yarn add @automapper/core @automapper/classes @automapper/sequelize ``` -------------------------------- ### Install NestJS Integration with Pojo Strategy (yarn) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install core, NestJS, and pojos strategy using yarn. ```shell yarn add @automapper/core @automapper/nestjs @automapper/pojos # for pojos ``` -------------------------------- ### Install NestJS Integration with Classes and MikroORM (npm) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install core, NestJS, classes strategy, reflect-metadata, and MikroORM support using npm. ```shell npm i @automapper/core @automapper/nestjs @automapper/classes reflect-metadata @automapper/mikro # for classes + mikro-orm ``` -------------------------------- ### Install @automapper/core with npm Source: https://github.com/nartc/mapper/blob/main/packages/core/src/README.md Use this command to install the core package using npm. ```sh npm i @automapper/core ``` -------------------------------- ### Install ORM Support with Sequelize (npm) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install core, classes strategy, reflect-metadata, and Sequelize support using npm. ```shell npm i @automapper/core @automapper/classes reflect-metadata @automapper/sequelize # for sequelize ``` -------------------------------- ### Install NestJS Integration with Classes and MikroORM (yarn) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install core, NestJS, classes strategy, reflect-metadata, and MikroORM support using yarn. ```shell yarn add @automapper/core @automapper/nestjs @automapper/classes reflect-metadata @automapper/mikro # for classes + mikro-orm ``` -------------------------------- ### Install NestJS Integration with Pojo Strategy (npm) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install core, NestJS, and pojos strategy using npm. ```shell npm i @automapper/core @automapper/nestjs @automapper/pojos # for pojos ``` -------------------------------- ### Install @automapper/core and @automapper/classes Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/strategies/classes.mdx Install the necessary packages for using the @automapper/classes strategy. This includes both the core library and the classes strategy. ```shell npm i @automapper/core @automapper/classes ``` ```shell yarn add @automapper/core @automapper/classes ``` -------------------------------- ### Install automapper/sequelize Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/strategies/sequelize.mdx Install the necessary packages for automapper core, classes, and sequelize strategy using npm or yarn. ```shell npm i @automapper/core @automapper/classes @automapper/sequelize ``` ```shell yarn add @automapper/core @automapper/classes @automapper/sequelize ``` -------------------------------- ### Install @automapper/mikro with npm Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/strategies/mikro.mdx Install the necessary @automapper/core, @automapper/classes, and @automapper/mikro packages using npm. ```shell npm i @automapper/core @automapper/classes @automapper/mikro ``` -------------------------------- ### Install NestJS Integration with Classes (npm) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install core, NestJS, classes strategy, and reflect-metadata using npm. ```shell npm i @automapper/core @automapper/nestjs @automapper/classes reflect-metadata # for classes ``` -------------------------------- ### Install @automapper/mikro with yarn Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/strategies/mikro.mdx Install the necessary @automapper/core, @automapper/classes, and @automapper/mikro packages using yarn. ```shell yarn add @automapper/core @automapper/classes @automapper/mikro ``` -------------------------------- ### Install @automapper/core and @automapper/nestjs Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/nestjs.mdx Install the necessary packages for @automapper/nestjs integration using npm or yarn. ```shell npm i @automapper/core @automapper/nestjs ``` ```shell yarn add @automapper/core @automapper/nestjs ``` -------------------------------- ### Install Peer Dependencies Source: https://github.com/nartc/mapper/blob/main/packages/classes/src/README.md Install the required peer dependencies, @automapper/core and reflect-metadata, using npm or yarn. ```sh npm i @automapper/core reflect-metadata ``` ```sh yarn add @automapper/core reflect-metadata ``` -------------------------------- ### Install Core Module with npm Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/getting-started/installation.mdx Install the core module and a strategy using npm. Use `@automapper/classes` with `reflect-metadata` for class-based mapping, or `@automapper/pojos` for plain objects. ```shell npm i @automapper/core @automapper/classes reflect-metadata # for classes ``` ```shell npm i @automapper/core @automapper/pojos # for pojos ``` -------------------------------- ### Install AutoMapper Core and Classes Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/tutorial/create-mapper.mdx Install the necessary AutoMapper packages using npm or yarn. Ensure reflect-metadata is included for decorator support. ```shell npm i @automapper/core @automapper/classes reflect-metadata ``` ```shell yarn add @automapper/core @automapper/classes reflect-metadata ``` -------------------------------- ### Install NestJS Integration with Classes and Sequelize (npm) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install core, NestJS, classes strategy, reflect-metadata, and Sequelize support using npm. ```shell npm i @automapper/core @automapper/nestjs @automapper/classes reflect-metadata @automapper/sequelize # for classes + sequelize ``` -------------------------------- ### Install NestJS Integration with Classes and Sequelize (yarn) Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/installation.mdx Install core, NestJS, classes strategy, reflect-metadata, and Sequelize support using yarn. ```shell yarn add @automapper/core @automapper/nestjs @automapper/classes reflect-metadata @automapper/sequelize # for classes + sequelize ``` -------------------------------- ### Example Models for Mapping Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/mapping-configuration/for-self.mdx Defines the Item, CartItem, and CartItemDto models used in the mapping examples. ```typescript class Item { @AutoMap() name: string; @AutoMap() price: number; @AutoMap() stock: number; } class CartItem { @AutoMap(() => Item) item: Item; @AutoMap() quantity: number; } class CartItemDto { @AutoMap() name: string; @AutoMap() price: number; @AutoMap() quantity: number; get total() { return this.price * this.quantity; } } ``` -------------------------------- ### Initialize Mapper with Classes Strategy Source: https://github.com/nartc/mapper/blob/main/packages/classes/src/README.md Create a mapper instance using the classes() strategy initializer. This example demonstrates setting up a mapping between User and UserDto classes, including a custom mapping for the fullName property. ```ts import { classes, AutoMap } from '@automapper/classes'; import { createMapper, createMap, forMember, mapFrom } from '@automapper/core'; const mapper = createMapper({ ..., strategyInitializer: classes() }); class User { @AutoMap() firstName: string; @AutoMap() lastName: string; constructor(firstName: string, lastName: string) { this.firstName = firstName; this.lastName = lastName; } } class UserDto { @AutoMap() firstName: string; @AutoMap() lastName: string; @AutoMap() fullName: string; } createMap( mapper, User, UserDto, forMember( d => d.fullName, mapFrom(s => s.firstName + ' ' + s.lastName) ) ); mapper.map(new User('Auto', 'Mapper'), User, UserDto); // UserDto { firstName: 'Auto', lastName: 'Mapper', fullName: 'Auto Mapper' } ``` -------------------------------- ### Install Core Module with yarn Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/getting-started/installation.mdx Install the core module and a strategy using yarn. Use `@automapper/classes` with `reflect-metadata` for class-based mapping, or `@automapper/pojos` for plain objects. ```shell yarn add @automapper/core @automapper/classes reflect-metadata # for classes ``` ```shell yarn add @automapper/core @automapper/pojos # for pojos ``` -------------------------------- ### Initialize Mapper with Pojo Strategy and Define Mappings Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/api/pojos/index.md Demonstrates initializing an Automapper instance with the pojos strategy, defining metadata for interfaces, creating a map between them, and performing a mapping operation. This setup is useful for transforming plain objects based on defined interface structures. ```ts import { pojos, PojosMetadataMap } from '@automapper/pojos'; import { createMapper, createMap, forMember, mapFrom } from '@automapper/core'; const mapper = createMapper({ ..., strategyInitializer: pojos() }); interface User { firstName: string; lastName: string; } interface UserDto { firstName: string; lastName: string; fullName: string; } PojosMetadataMap.create('SomeTokenForUser', { firstName: String, lastName: String }); PojosMetadataMap.create('SomeTokenForUserDto', { firstName: String, lastName: String, fullName: String }); createMap( mapper, 'SomeTokenForUser', 'SomeTokenForUserDto', forMember( d => d.fullName, mapFrom(s => s.firstName + ' ' + s.lastName) ) ); mapper.map( {firstName: 'Auto', lastName: 'Mapper'}, 'SomeTokenForUser', 'SomeTokenForUserDto' ); // { firstName: 'Auto', lastName: 'Mapper', fullName: 'Auto Mapper' } ``` -------------------------------- ### Start Conventional Commit Flow Source: https://github.com/nartc/mapper/blob/main/CONTRIBUTING.md Run this command to initiate the Conventional Commit interactive process for creating commit messages. ```bash npm run commit ``` -------------------------------- ### Install ORM Support with yarn Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/getting-started/installation.mdx Install ORM support packages with yarn. This includes the core module, `@automapper/classes`, `reflect-metadata`, and the specific ORM package. ```shell yarn add @automapper/core @automapper/classes reflect-metadata @automapper/mikro # for mikro-orm ``` ```shell yarn add @automapper/core @automapper/classes reflect-metadata @automapper/sequelize # for sequelize ``` -------------------------------- ### Example Date to String Converter Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/mapping-configuration/for-member/convert-using.mdx An example implementation of the Converter interface for converting a Date object to a string. This can include custom formatting or validation. ```typescript export const dateToStringConverter: Converter = { convert(source) { // maybe handle validation, additional parsing, or format here return source.toDateString(); }, }; ``` -------------------------------- ### Install ORM Support with npm Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/getting-started/installation.mdx Install ORM support packages with npm. This includes the core module, `@automapper/classes`, `reflect-metadata`, and the specific ORM package. ```shell npm i @automapper/core @automapper/classes reflect-metadata @automapper/mikro # for mikro-orm ``` ```shell npm i @automapper/core @automapper/classes reflect-metadata @automapper/sequelize # for sequelize ``` -------------------------------- ### Install NestJS Integration with npm Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/getting-started/installation.mdx Install the NestJS integration package with npm. Include `@automapper/classes` and `reflect-metadata` for class-based mapping, or `@automapper/pojos` for plain objects. ```shell npm i @automapper/core @automapper/nestjs @automapper/classes reflect-metadata # for classes ``` ```shell npm i @automapper/core @automapper/nestjs @automapper/classes reflect-metadata @automapper/mikro # for classes + mikro-orm ``` ```shell npm i @automapper/core @automapper/nestjs @automapper/classes reflect-metadata @automapper/sequelize # for classes + sequelize ``` ```shell npm i @automapper/core @automapper/nestjs @automapper/pojos # for pojos ``` -------------------------------- ### Install NestJS Integration with yarn Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/getting-started/installation.mdx Install the NestJS integration package with yarn. Include `@automapper/classes` and `reflect-metadata` for class-based mapping, or `@automapper/pojos` for plain objects. ```shell yarn add @automapper/core @automapper/nestjs @automapper/classes reflect-metadata # for classes ``` ```shell yarn add @automapper/core @automapper/nestjs @automapper/classes reflect-metadata @automapper/mikro # for classes + mikro-orm ``` ```shell yarn add @automapper/core @automapper/nestjs @automapper/classes reflect-metadata @automapper/sequelize # for classes + sequelize ``` ```shell yarn add @automapper/core @automapper/nestjs @automapper/pojos # for pojos ``` -------------------------------- ### Create Map with Different Source and Destination Naming Conventions Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/mapping-configuration/naming-conventions.mdx Example of creating a map with distinct naming conventions for source (SnakeCase) and destination (CamelCase). ```typescript createMap( mapper, Product, ProductDto, namingConventions({ source: new SnakeCaseNamingConvention(), destination: new CamelCaseNamingConvention(), }) ); ``` -------------------------------- ### Configure Self Mapping for Person Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/misc/self-mapping.mdx Configure a self-mapping for the Person model using a shorthand syntax. This example demonstrates mapping the 'nickname' property, falling back to 'name' if 'nickname' is null or undefined. ```typescript /** * Short-hand syntax for * * createMap( * mapper, * Person, * Person, * forMember(...) * ) */ createMap(mapper, Person, forMember(d => d.nickname, mapFrom(s => s.nickname ?? s.name)); ``` -------------------------------- ### Initial Mapping Configurations Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/tutorial/mapping-profile.mdx Demonstrates basic mapping creation for Bio and User entities with type converters and naming conventions. ```typescript createMap( mapper, Bio, BioDto, typeConverter(Date, String, (date) => date.toDateString()), namingConventions(new CamelCaseNamingConvention()) ); createMap( mapper, User, UserDto, forMember( (destination) => destination.fullName, mapFrom((source) => source.firstName + ' ' + source.lastName) ) ); ``` -------------------------------- ### Run All Test Suites Source: https://github.com/nartc/mapper/blob/main/CONTRIBUTING.md Execute this command to run all the test suites for the project. ```bash npm run test ``` -------------------------------- ### Enable Commit Hooks Source: https://github.com/nartc/mapper/blob/main/CONTRIBUTING.md Execute this command to set up Husky for managing Git commit hooks. ```bash npx husky install ``` -------------------------------- ### Configure and Map Org to OrgDto Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/misc/self-mapping.mdx Configure the mapping between `Org` and `OrgDto` using `createMap`. Then, demonstrate mapping an `Org` instance to an `OrgDto` instance. ```typescript createMap(mapper, Org, OrgDto); const dto = mapper.map(org, Org, OrgDto); ``` -------------------------------- ### AutomapperProfile with Mapping Configurations Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/nestjs.mdx Override the protected get mappingConfigurations() method to provide an array of MappingConfiguration that will be applied to all createMap() calls within get profile(). ```typescript import { AutomapperProfile, InjectMapper } from '@automapper/nestjs'; import { Injectable } from '@nestjs/common'; @Injectable() export class UserProfile extends AutomapperProfile { constructor(@InjectMapper() mapper: Mapper) { super(mapper); } get profile(): MappingProfile { return (mapper) => { createMap(mapper, UserEntity, UserDto); createMap(mapper, UserEntity, UserInformationDto); createMap(mapper, UserEntity, AuthUserDto); }; } protected get mappingConfigurations(): MappingConfiguration[] { // the 3 createMap() above will get this `extend()` return [extend(BaseEntity, BaseDto)]; } } ``` -------------------------------- ### Deploy Website Using SSH Source: https://github.com/nartc/mapper/blob/main/packages/documentation/README.md Deploys the website using SSH, suitable for environments where SSH access is configured. ```bash USE_SSH=true yarn deploy ``` -------------------------------- ### Update `AutomapperProfile` Mapping Method Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/migrate-v8.mdx The `mapProfile` method has been renamed to `get profile` in `AutomapperProfile`. ```typescript @Injectable() export class UserProfile extends AutomapperProfile { constructor(@InjectMapper() mapper: Mapper) { super(mapper); } // before override mapProfile(): MappingProfile { return (mapper) => { mapper.createMap(/*...*/); }; } // after override get profile(): MappingProfile { return (mapper) => { createMap(mapper /*...*/); }; } } ``` -------------------------------- ### User Service with Manual Mapping Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/tutorial/preface.mdx Demonstrates a service method that fetches user data and manually maps it to a DTO using the static `fromUser` method. This highlights the integration of manual mapping within application logic. ```typescript export class UserService { getUserByUsername(username: string): UserDto { const user = fetchUserByUsernameFromDb(username); return UserDto.fromUser(user); } } ``` -------------------------------- ### Define AutomapperProfile in NestJS Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/nestjs.mdx Extend AutomapperProfile and implement the get profile() method to define mappings. Inject the Mapper using @InjectMapper(). ```typescript import { AutomapperProfile, InjectMapper } from '@automapper/nestjs'; import type { Mapper } from '@automapper/core'; import { Injectable } from '@nestjs/common'; import { createMap } from '@automapper/core'; @Injectable() export class UserProfile extends AutomapperProfile { constructor(@InjectMapper() mapper: Mapper) { super(mapper); } override get profile() { return (mapper) => { createMap(mapper, User, UserDto); }; } } ``` -------------------------------- ### Build Static Website Content Source: https://github.com/nartc/mapper/blob/main/packages/documentation/README.md Generates the static content for the website, typically placed in the 'build' directory for hosting. ```bash yarn build ``` -------------------------------- ### Initialize Mapper with Sequelize Strategy Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/strategies/sequelize.mdx Create a mapper instance using the sequelize strategy, optionally providing custom preMap and destinationConstructor functions for Sequelize object handling. ```typescript const mapper = createMapper({ strategyInitializer: sequelize({ preMap: customPreMap, destinationConstructor: customDestinationConstructor, }), }); ``` -------------------------------- ### Basic Logger Usage Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/fundamentals/mapper.mdx AutoMapper exposes a logger via `AutoMapperLogger`. By default, it uses console methods with an `[AutoMapper]` prefix. This example shows a direct log and a custom log. ```typescript console.log('some log'); // some log AutoMapperLogger.log('some log'); // [AutoMapper]: some log ``` -------------------------------- ### Customize Mapping Strategy with Initializer Options Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/migrate-v8.mdx Customize the mapping strategy using `MappingStrategyInitializerOptions`. This includes options for metadata application, destination constructor, and pre/post-mapping hooks. ```typescript export interface MappingStrategyInitializerOptions { applyMetadata?: ApplyMetadata; destinationConstructor?: DestinationConstructor; preMap?>(source: TSource): TSource; postMap?< TSource extends Dictionary, TDestination extends Dictionary >( source: TSource, destination: TDestination ): TDestination; } const mapper = createMapper({ strategyInitializer: classes({ applyMetadata, // customize how a Strategy applies the metadata to a model destinationConstructor, // customize the default constructor of the Destination model preMap, // customize what to do before a map happens postMap, // customize what to do after a map happens }), }); ``` -------------------------------- ### Interactive Button with React in MDX Source: https://github.com/nartc/mapper/blob/main/packages/documentation/blog/2021-08-01-mdx-blog-post.mdx Embed a React component directly into an MDX blog post to create interactive elements. This example uses a simple button with an alert on click. ```jsx ``` -------------------------------- ### constructUsing Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/api/core/modules.md Configures a mapping to use a specific constructor for creating destination objects. This is useful when the destination type requires specific initialization logic. ```APIDOC ## constructUsing ### Description Configures mapping to use a provided constructor for the destination object. ### Signature ▸ **constructUsing**<`TSource`, `TDestination` (`destinationConstructor`: [`DestinationConstructor`](modules.md#destinationconstructor)<`TSource`, `TDestination` ): [`MappingConfiguration`](modules.md#mappingconfiguration)<`TSource`, `TDestination` ### Type Parameters * `TSource` extends [`Dictionary`](modules.md#dictionary)<`TSource` * `TDestination` extends [`Dictionary`](modules.md#dictionary)<`TDestination` ### Parameters * `destinationConstructor` (`DestinationConstructor`): The constructor function to use for creating destination objects. ### Returns [`MappingConfiguration`](modules.md#mappingconfiguration)<`TSource`, `TDestination` ### Defined in [lib/mapping-configurations/construct-using.ts:9](https://github.com/nartc/mapper/blob/efc4cb9d/packages/core/src/lib/mapping-configurations/construct-using.ts#L9) ``` -------------------------------- ### Configure Self Mapping for Person Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/misc/self-mapping.mdx Configure a self-mapping for the `Person` model using `createMap` and `forMember`. This example demonstrates mapping the `nickname` property, falling back to `name` if `nickname` is null or undefined. ```typescript /** * Short-hand syntax for * * createMap( * mapper, * Person, * Person, * forMember(...) * ) */ createMap(mapper, Person, forMember(d => d.nickname, mapFrom(s => s.nickname ?? s.name))); ``` -------------------------------- ### Stage All Changes Source: https://github.com/nartc/mapper/blob/main/CONTRIBUTING.md Use this command to stage all modified files for the next commit. ```bash git add . ``` -------------------------------- ### Update Initializer Syntax Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/migrate-v8.mdx Change from `pluginInitializer` to `strategyInitializer` and invoke the strategy. ```typescript // before const mapper = createMapper({ pluginInitializer: pojos, // no () }); // after const mapper = createMapper({ strategyInitializer: pojos(), // invoking }); ``` -------------------------------- ### Configure and Use AutoMapper for Auto Flattening Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/fundamentals/auto-flattening.mdx This example demonstrates how to configure AutoMapper with a `CamelCaseNamingConvention` and then use it to map a complex `Order` object to a flat `OrderDto`. AutoMapper automatically resolves nested properties based on the naming convention. ```typescript // complex model const product = new Product(5, 'Fried Chicken'); const customer = new Customer('Chau Tran'); const order = new Order(customer); order.addItem(product, 10); /** * Order { * customer: Customer { * name: 'Chau Tran' * }, * items: [ * OrderItem { * product: Product { * price: 5, * name: 'Fried Chicken * }, * quantity: 10 * } * ] * } */ // configure AutoMapper with NamingConvention const mapper = createMapper({ strategyInitializer: classes(), // 👇 apply the CamelCaseNamingConvention namingConventions: new CamelCaseNamingConvention(), }); createMap(mapper, Order, OrderDto); const dto = mapper.map(order, Order, OrderDto); /** * OrderDto { * customerName: 'Chau Tran', * total: 50 * } */ ``` -------------------------------- ### MappingStrategyInitializerOptions Interface Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/api/core/interfaces/MappingStrategyInitializerOptions.md The MappingStrategyInitializerOptions interface provides configuration for mapping strategies. It includes optional properties for applying metadata and specifying the destination constructor, as well as optional methods for executing logic before and after a mapping operation. ```APIDOC ## Interface: MappingStrategyInitializerOptions ### Description This interface defines the configuration options for initializing a mapping strategy. It allows for optional metadata application, specification of the destination constructor, and the definition of pre- and post-mapping hooks. ### Properties - **applyMetadata** (ApplyMetadata) - Optional - Allows for the application of metadata during the mapping process. - **destinationConstructor** (DestinationConstructor) - Optional - Specifies the constructor function for the destination object. ### Methods - **preMap**(source: TSource, mapping: Mapping): TSource - Optional - A hook that executes before the mapping process begins. It receives the source object and the mapping configuration, and returns the source object (potentially modified). - **postMap**(source: TSource, destination: TDestination, mapping: Mapping): TDestination - Optional - A hook that executes after the mapping process is complete. It receives the source object, the destination object, and the mapping configuration, and returns the destination object (potentially modified). ``` -------------------------------- ### Create a Singleton Mapper Instance Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/tutorial/create-mapper.mdx Create and export a singleton mapper instance using `createMapper`. Configure it with the `classes()` strategy initializer for class-based mapping. ```typescript import { createMapper } from '@automapper/core'; import { classes } from '@automapper/classes'; // Create and export the mapper export const mapper = createMapper({ strategyInitializer: classes(), }); ``` -------------------------------- ### Map User to UserDto with Undefined Substitution Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/mapping-configuration/for-member/undefined-substitution.mdx Use undefinedSubstitution to map a raw string value to the 'fullName' property of UserDto if the 'fullName' property in the source User object is undefined. This snippet demonstrates the basic setup for this mapping. ```typescript createMap( mapper, User, UserDto, forMember( (destination) => destination.fullName, undefinedSubstitution('raw value') ) ); mapper.map({}, User, UserDto); // UserDto { fullName: 'raw value' } ``` -------------------------------- ### Configure Decoratorless Mapping with autoMap() Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/mapping-configuration/auto-map.mdx Use autoMap() for properties with identical names and types. Configure custom mappings for properties with different types or those that need to be derived using forMember and mapFrom. This example demonstrates mapping between a DecoratorlessUserEntity and a DecoratorlessUserDto. ```typescript import { autoMap, createMap, forMember, mapFrom, Mapper, } from '@automapper/core'; export class DecoratorlessUserEntity { constructor( public readonly firstName: string, public readonly lastName: string, public readonly birthday: Date ) {} } export class DecoratorlessUserDto { firstName!: string; lastName!: string; birthday!: string; fullName!: string; } export function decoratorlessUserProfile(mapper: Mapper) { createMap( mapper, DecoratorlessUserEntity, DecoratorlessUserDto, // Use `autoMap()` on properties that can be trivially mapped. autoMap('firstName'), autoMap('lastName'), // Use more elaborate mapping configurations when necessary: // 'birthday' exists on both `Source` and `Destination`, but with // different types. forMember( (d) => d.birthday, mapFrom((s) => s.birthday.toDateString()) ), // 'fullName' doesn't exist on `Source` and must be mapped manually. forMember( (d) => d.fullName, mapFrom((s) => `${s.firstName} ${s.lastName}`) ) ); } ``` -------------------------------- ### Update `createMetadataMap` to `PojosMetadataMap.create` Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/getting-started/migrate-v8.mdx Replace `createMetadataMap` with `PojosMetadataMap.create`. Note the changes in key types, nullability, and the removal of extending previous metadata. ```typescript // before createMetadataMap('SimpleUser', { firstName: String, lastName: String, }); createMetadataMap('SimpleUserDto', 'SimpleUser', { fullName: String, }); // after PojosMetadataMap.create('SimpleUser', { firstName: String, lastName: String, }); PojosMetadataMap.create('SimpleUserDto', { firstName: String, lastName: String, fullName: String, }); ``` -------------------------------- ### Create a Mapper Instance Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/fundamentals/mapper.mdx Instantiate a Mapper by calling `createMapper()` and providing a mapping strategy initializer, such as `classes()` for TypeScript/ES6 classes. ```typescript const mapper = createMapper({ strategyInitializer: classes(), }); ``` -------------------------------- ### Share Mapping Configurations within a Profile Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/tutorial/mapping-profile.mdx Illustrates how to apply common `MappingConfiguration` to all `createMap` calls within a `MappingProfile`. ```typescript const bioProfile: MappingProfile = (mapper) => { const camelCaseNamingConvention = new CamelCaseNamingConvention(); createMap( mapper, Bio, BioDto, namingConventions(camelCaseNamingConvention), extend(Base, BaseDto) ); createMap( mapper, Bio, BioInformationDto, namingConventions(camelCaseNamingConvention), extend(Base, BaseDto) ); createMap( mapper, Bio, MinimalBioDto, namingConventions(camelCaseNamingConvention), extend(Base, BaseDto) ); }; ``` -------------------------------- ### Apply Shared Mapping Configurations with addProfile Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/tutorial/mapping-profile.mdx Demonstrates registering a `MappingProfile` with shared configurations applied via `addProfile`. ```typescript const bioProfile: MappingProfile = (mapper) => { createMap(mapper, Bio, BioDto); createMap(mapper, Bio, BioInformationDto); createMap(mapper, Bio, MinimalBioDto); }; addProfile( mapper, bioProfile, namingConventions(new CamelCaseNamingConvention()), extend(Base, BaseDto) ); ``` -------------------------------- ### createAutomapperOptions Source: https://github.com/nartc/mapper/blob/main/packages/documentations/docs/api/nestjs/interfaces/AutomapperOptionsFactory.md This method is responsible for creating and returning the Automapper configuration options. It can return options synchronously or asynchronously via a Promise. ```APIDOC ## createAutomapperOptions ### Description Creates and returns Automapper options. This method can return the options directly or as a Promise. ### Method `createAutomapperOptions()` ### Returns `CreateMapperOptions` | `Promise` ### Defined in `packages/nestjs/src/lib/options.ts:18` ``` -------------------------------- ### Create POJO Metadata Source: https://github.com/nartc/mapper/blob/main/packages/documentation/docs/strategies/pojos.mdx Use PojosMetadataMap.create() to define the metadata for a POJO interface. Ensure the type parameter is supplied for intellisense. ```typescript PojosMetadataMap.create('User', { firstName: String, lastName: String, }); ```