declare module 'automapper-nartc/automapper' { import { ExposeOptions, TypeHelpOptions, TypeOptions } from 'class-transformer'; import { AutoMapperBase } from 'automapper-nartc/base'; import { Configuration, Constructable, CreateMapFluentFunctions, MapActionOptions, MappingProfile } from 'automapper-nartc/types'; /** * Combined Expose and Type from class-transformer * * @param {(type?: TypeHelpOptions) => Function} typeFn * @param {ExposeOptions} exposeOptions * @param {TypeOptions} typeOptions */ export const ExposedType: (typeFn: (type?: TypeHelpOptions | undefined) => Function, exposeOptions?: ExposeOptions | undefined, typeOptions?: TypeOptions | undefined) => PropertyDecorator; export class AutoMapper extends AutoMapperBase { private static _instance; private readonly _profiles; /** * @static - Get the Mapper instance */ static getInstance(): AutoMapper; constructor(); /** * Initialize Mapper * * @example * * * ```ts * Mapper.initialize(config => { * config.addProfile(new Profile()); * config.createMap(Source, Destination); * }) * ``` * * @param {(config: Configuration) => void} configFn - Config function callback * */ initialize(configFn: (config: Configuration) => void): void; /** * Map from Source to Destination * * @example * * * ```ts * const user = new User(); * user.firstName = 'John'; * user.lastName = 'Doe'; * * const userVm = Mapper.map(user, UserVm); * ``` * * @param {TSource} sourceObj - the sourceObj that are going to be mapped * @param {Constructable} destination - the Destination model to receive the * mapped values * @param {MapActionOptions} option - Optional mapping option */ map(sourceObj: TSource, destination: Constructable, option?: MapActionOptions): TDestination; /** * Map from Source to Destination Async. Mapping operation will be run as a micro task. * * @example * * * ```ts * const user = new User(); * user.firstName = 'John'; * user.lastName = 'Doe'; * * const userVm = await Mapper.mapAsync(user, UserVm); * ``` * * @param {TSource} sourceObj - the sourceObj that are going to be mapped * @param {Constructable} destination - the Destination model to receive the * mapped values * * @param {MapActionOptions} option - Optional mapping option * @returns {Promise} Promise that resolves TDestination */ mapAsync(sourceObj: TSource, destination: Constructable, option?: MapActionOptions): Promise; /** * Map from a list of Source to a list of Destination * * @example * * * ```ts * const addresses = []; * addresses.push(new Address(), new Address()); * * const addressesVm = Mapper.mapArray(addresses, AddressVm); * ``` * * @param {TSource} sourceObj - the sourceObj that are going to be mapped * @param {Constructable} destination - the Destination model to receive the * mapped values * @param {MapActionOptions} option - Optional mapping option */ mapArray(sourceObj: TSource[], destination: Constructable, option?: MapActionOptions): TDestination[]; /** * Map from a list of Source to a list of Destination async. Mapping operation will be run * as a micro task. * * @example * * * ```ts * const addresses = []; * addresses.push(new Address(), new Address()); * * const addressesVm = await Mapper.mapArrayAsync(addresses, AddressVm); * ``` * * @param {TSource} sourceObj - the sourceObj that are going to be mapped * @param {Constructable} destination - the Destination model to receive the * mapped values * @param {MapActionOptions} option - Optional mapping option * @returns {Promise>} Promise that resolves a TDestination[] */ mapArrayAsync(sourceObj: TSource[], destination: Constructable, option?: MapActionOptions): Promise; /** * Add MappingProfile to the current instance of AutoMapper * * @param {MappingProfile} profile - Profile being added */ addProfile(profile: MappingProfile): AutoMapper; /** * Create a mapping between Source and Destination without initializing the Mapper * * @param {Constructable} source - the Source model * @param {Constructable} destination - the Destination model */ createMap(source: Constructable, destination: Constructable): CreateMapFluentFunctions; /** * Dispose Mappings and Profiles created on the Mapper singleton */ dispose(): void; private _createMappingFluentFunctions; private _createMapForMember; private _createReverseMap; private _createMapForPath; } /** * @instance AutoMapper singleton */ export const Mapper: AutoMapper; } declare module 'automapper-nartc/base' { import { Constructable, ForMemberExpression, ForPathDestinationFn, MapActionOptions, Mapping, TransformationType } from 'automapper-nartc/types'; export abstract class AutoMapperBase { protected readonly _mappings: { [key: string]: Mapping; }; protected constructor(); protected getTransformationType(forMemberFn: ForMemberExpression): TransformationType; protected _mapArray(sourceArray: TSource[], mapping: Mapping, option?: MapActionOptions): TDestination[]; protected _map(sourceObj: TSource, mapping: Mapping, option?: MapActionOptions, isArrayMap?: boolean): TDestination; protected _mapAsync(sourceObj: TSource, mapping: Mapping, option?: MapActionOptions): Promise; protected _mapArrayAsync(sourceArray: TSource[], mapping: Mapping, option?: MapActionOptions): Promise; private static _assertMappingErrors; protected _createMappingObject(source: Constructable, destination: Constructable): Mapping; protected _createReverseMappingObject(mapping: Mapping): Mapping; protected _getKeyFromMemberFn(fn: ForPathDestinationFn): keyof T; protected _getMapping(source: Constructable, destination: Constructable): Mapping; protected _getMappingForDestination(destination: Constructable): Mapping; protected _dispose(): void; private _hasMapping; private static _getMappingKey; private static _isClass; private static _isDate; private static _isArray; private static _isResolver; private _getMappingForNestedKey; private static _getSourcePropertyKey; } } declare module 'automapper-nartc/index' { export * from 'automapper-nartc/base'; export * from 'automapper-nartc/types'; export * from 'automapper-nartc/automapper'; export * from 'automapper-nartc/profile'; export * from 'automapper-nartc/naming/index'; } declare module 'automapper-nartc/naming/camel-case-naming-convention' { import { NamingConvention } from 'automapper-nartc/types'; export class CamelCaseNamingConvention implements NamingConvention { separatorCharacter: string; splittingExpression: RegExp; transformPropertyName(sourceNameParts: string[]): string; } } declare module 'automapper-nartc/naming/index' { export * from 'automapper-nartc/naming/camel-case-naming-convention'; export * from 'automapper-nartc/naming/pascal-case-naming-convention'; } declare module 'automapper-nartc/naming/pascal-case-naming-convention' { import { NamingConvention } from 'automapper-nartc/types'; export class PascalCaseNamingConvention implements NamingConvention { separatorCharacter: string; splittingExpression: RegExp; transformPropertyName(sourceNameParts: string[]): string; } } declare module 'automapper-nartc/profile' { import { AutoMapper } from 'automapper-nartc/automapper'; import { MappingProfile } from 'automapper-nartc/types'; /** * Abstract class for all mapping Profiles * */ export abstract class MappingProfileBase implements MappingProfile { /** * @property {string} profileName - the name of the Profile */ profileName: string; /** * @constructor - initialize the profile with the profileName */ protected constructor(); /** * @abstract configure() method to be called when using with Mapper.initialize() * * @param {AutoMapper} mapper - AutoMapper instance to add this Profile on */ abstract configure(mapper: AutoMapper): void; } } declare module 'automapper-nartc/types' { import { AutoMapper } from 'automapper-nartc/automapper'; export type Unpacked = T extends (infer U)[] ? U : T extends (...args: any[]) => infer U ? U : T extends Promise ? U : T; export enum TransformationType { /** * when `opts.ignore()` is used on `forMember()` */ Ignore = 0, /** * when `opts.mapFrom()` is used on `forMember()` */ MapFrom = 1, /** * when `opts.condition()` is used on `forMember()` */ Condition = 2, /** * when `opts.fromValue()` is used on `forMember()` */ FromValue = 3, /** * when `opts.mapWith()` is used on `forMember()` */ MapWith = 4, /** * when `opts.convertUsing()` is used on `forMember()` */ ConvertUsing = 5 } /** * A new-able type */ export type Constructable = new (...args: any[]) => T; export type MapActionOptions = { beforeMap?: BeforeAfterMapAction; afterMap?: BeforeAfterMapAction; }; export type BeforeAfterMapAction = (source: TSource, destination: TDestination, mapping?: Mapping) => void; export interface Converter { convert(source: TSource): TDestination; } export interface Resolver { resolve(source: TSource, destination: TDestination, transformation: MappingTransformation): K; } /** * Value Selector from a source type * * @example * * ```ts * source => source.foo.bar * ``` */ export type ValueSelector = (source: TSource) => TDestination[K]; export type MapFromCallback = ValueSelector | Resolver; /** * Condition Predicate from a source */ export type ConditionPredicate = (source: TSource) => boolean; /** * Options for mapWith */ export type MapWithOptions = { destination: Constructable>; value: ValueSelector; }; export type ConvertUsingOptions = { converter: Converter; value?: (source: TSource) => TSource[keyof TSource]; }; export interface DestinationMemberConfigOptions { mapFrom(cb: MapFromCallback): void; mapWith(destination: Constructable>, value: ValueSelector): void; condition(predicate: ConditionPredicate): void; fromValue(value: TDestination[K]): void; ignore(): void; convertUsing(converter: Converter, value?: (source: TSource) => TConvertSource): void; } export interface ForMemberExpression { (opts: DestinationMemberConfigOptions): void; } export type ForPathDestinationFn = (destination: TDestination) => TDestination[keyof TDestination]; export interface CreateReverseMapFluentFunctions { forPath(destination: ForPathDestinationFn, forPathFn: ForMemberExpression): CreateReverseMapFluentFunctions; } export interface CreateMapFluentFunctions { forMember(key: K, expression: ForMemberExpression): CreateMapFluentFunctions; beforeMap(action: BeforeAfterMapAction): CreateMapFluentFunctions; afterMap(action: BeforeAfterMapAction): CreateMapFluentFunctions; reverseMap(): CreateReverseMapFluentFunctions; setSourceNamingConvention(namingConvention: NamingConvention): CreateMapFluentFunctions; setDestinationNamingConvention(namingConvention: NamingConvention): CreateMapFluentFunctions; } export interface Configuration { addProfile(profile: MappingProfile): void; createMap(source: Constructable, destination: Constructable): CreateMapFluentFunctions; } export interface MappingTransformation { transformationType: TransformationType; mapFrom: MapFromCallback; mapWith: MapWithOptions; condition: ConditionPredicate; fromValue: TDestination[keyof TDestination]; convertUsing: ConvertUsingOptions; } export interface MappingProperty { destinationKey: keyof TDestination; transformation: MappingTransformation; } export interface Mapping { source: Constructable; destination: Constructable; sourceKey: string; destinationKey: string; properties: Map>; sourceMemberNamingConvention: NamingConvention; destinationMemberNamingConvention: NamingConvention; beforeMapAction?: BeforeAfterMapAction; afterMapAction?: BeforeAfterMapAction; } export interface MappingProfile { profileName: string; configure: (mapper: AutoMapper) => void; } export type NamingConvention = { splittingExpression: RegExp; separatorCharacter: string; transformPropertyName: (sourcePropNameParts: string[]) => string; }; } declare module 'automapper-nartc' { import main = require('automapper-nartc/index'); export = main; }