/
mapper.interface.ts
78 lines (72 loc) · 2.99 KB
/
mapper.interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { ObjectType, AbstractObjectType } from '../types/object-type';
import { PrimitiveTypeNames } from '../types/primitive';
import { TypeInstance } from '../types/type-instance';
import { Nullable } from '../types/nullable';
import { Undefinable } from '../types/undefinable';
import { Optional } from '../types/optional';
import { DynamicCastType } from '../functions/dynamic-cast';
/** Represents an object mapper. */
export interface IMapper {
/**
* Checks whether or not a mapping from `sourceType` to `destinationType` exists.
* @param sourceType Source type to check.
* @param destinationType Destination type to check.
* @returns `true`, if mapping exists, otherwise `false`.
*/
has<
TSource extends PrimitiveTypeNames | ObjectType | AbstractObjectType,
TDestination extends PrimitiveTypeNames | ObjectType | AbstractObjectType>(
sourceType: TSource,
destinationType: TDestination):
boolean;
/**
* Maps an object to the destination type.
* @param destinationType Destination type to map to.
* @param source An object to map.
* @returns A mapping result.
*/
map<TDestination extends PrimitiveTypeNames | object>(
destinationType: DynamicCastType<TDestination>,
source: any):
TypeInstance<DynamicCastType<TDestination>>;
/**
* Maps a nullable object to the destination type.
* @param destinationType Destination type to map to.
* @param source An object to map.
* @returns A nullable mapping result.
*/
mapNullable<TDestination extends PrimitiveTypeNames | object>(
destinationType: DynamicCastType<TDestination>,
source: any):
Nullable<TypeInstance<DynamicCastType<TDestination>>>;
/**
* Maps an undefinable object to the destination type.
* @param destinationType Destination type to map to.
* @param source An object to map.
* @returns An undefinable mapping result.
*/
mapUndefinable<TDestination extends PrimitiveTypeNames | object>(
destinationType: DynamicCastType<TDestination>,
source: any):
Undefinable<TypeInstance<DynamicCastType<TDestination>>>;
/**
* Maps an optional object to the destination type.
* @param destinationType Destination type to map to.
* @param source An object to map.
* @returns An optional mapping result.
*/
mapOptional<TDestination extends PrimitiveTypeNames | object>(
destinationType: DynamicCastType<TDestination>,
source: any):
Optional<TypeInstance<DynamicCastType<TDestination>>>;
/**
* Maps a range of objects to the destination type.
* @param destinationType Destination type to map to.
* @param source A range of objects to map.
* @returns A range mapping result.
*/
mapRange<TDestination extends PrimitiveTypeNames | object>(
destinationType: DynamicCastType<TDestination>,
source: Iterable<any>):
TypeInstance<DynamicCastType<TDestination>>[];
}