custom-automapper
Version:
A powerful, type-safe object mapping library for TypeScript and NestJS
83 lines • 2.6 kB
TypeScript
export type ClassType<T = any> = new (...args: any[]) => T;
export type MapperFunction<S, D, K extends keyof D = keyof D> = (source: S, context?: MappingContext) => D[K] | any;
export type MappingConfig<S extends object, D extends object> = {
[K in keyof D]?: MapperFunction<S, D, K>;
};
export interface MappingRegistryEntry<S extends object, D extends object> {
source: ClassType<S>;
destination: ClassType<D>;
config?: MappingConfig<S, D>;
options?: MappingEntryOptions<S, D>;
}
export interface MappingEntryOptions<S = any, D = any> {
skipNulls?: boolean;
skipUndefined?: boolean;
deepClone?: boolean;
strict?: boolean;
namingConvention?: NamingConvention;
beforeMap?: (source: S) => S | Promise<S>;
afterMap?: (destination: D, source: S) => D | Promise<D>;
cache?: Partial<CacheConfig>;
ignore?: Array<string | keyof D | symbol>;
include?: Array<string | keyof D | symbol>;
deepCloneBeforeMap?: boolean;
}
export interface NamingConvention {
splittingExpression: RegExp;
separatingCharacter: string;
transformPropertyName: (name: string) => string;
}
export interface MappingContext {
source?: unknown;
destination?: unknown;
parent?: MappingContext;
depth?: number;
options?: Record<string, any>;
}
export interface ConditionalMapping<S, D> {
condition: (source: S) => boolean;
map: MapperFunction<S, D>;
}
export interface TransformOptions {
ignore?: string[];
include?: string[];
convertNaming?: {
from: 'camelCase' | 'snake_case' | 'PascalCase' | 'kebab-case';
to: 'camelCase' | 'snake_case' | 'PascalCase' | 'kebab-case';
};
}
export interface MappingResult<D> {
data: D;
metadata: {
mappedProperties: string[];
skippedProperties: string[];
errors: Array<{
property: string;
error: string;
}>;
executionTime: number;
};
}
export type AsyncMapperFunction<S> = (source: S, context?: MappingContext) => Promise<any>;
export interface ValidationRule<T = any> {
validate: (value: T) => boolean | Promise<boolean>;
message: string;
}
export interface MappingError {
sourceType: string;
destinationType: string;
property?: string;
message: string;
originalError?: Error;
}
export interface CacheConfig {
enabled?: boolean;
strategy?: 'memory' | 'lru' | 'redis';
ttlMs?: number;
[k: string]: any;
}
export interface MapperConstructorOptions {
globalOptions?: MappingEntryOptions;
cache?: CacheConfig;
}
//# sourceMappingURL=types.d.ts.map