-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapping.transforms.ts
59 lines (56 loc) · 1.83 KB
/
mapping.transforms.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
/**
* Represents primitive property or nested object transformation.
* @param transformName allows to differentiate between diffrent transformations
* @type `K` output property name
* @type `X` input property type
* @type `Y` output property type
*/
export class TransformProperty<K, X, Y> {
constructor(
public readonly transformName: string,
public readonly targetKey: K,
public readonly transformer: (objectValue: X) => Y,
public readonly reverseTransformer: (entityValue: Y) => X
) {}
}
/**
* Represents array element transformation.
* @param transformArrayName allows to differentiate between diffrent transformations
* @type `K` output array name
* @type `X` input array type
* @type `Y` output array type
*/
export class TransformArray<K, X, Y> {
constructor(
public readonly transformArrayName: string,
public readonly targetKey: K,
public readonly elementTransformer: (objectValue: X) => Y,
public readonly reverseElementTransformer: (entityValue: Y) => X
) {}
}
/**
* Represents nested object transformation.
* @param transformNestedObjectName allows to differentiate between diffrent transformations
* @type `K` output nested object property name
* @type `M` nested mapping type
*/
export class TransformNestedObject<K, M> {
constructor(
public readonly transformNestedObjectName: string,
public readonly targetKey: K,
public readonly nestedMapping: M
) {}
}
/**
* Represents array's of objects element transformation.
* @param transformArrayOfObjectsName allows to differentiate between diffrent transformations
* @type `K` output array property name
* @type `M` nested mapping type
*/
export class TransformArrayOfObjects<K, M> {
constructor(
public readonly transformArrayOfObjectsName: string,
public readonly targetKey: K,
public readonly nestedMapping: M
) {}
}