@@ -7,42 +7,74 @@ import { ObjectMapper } from "../../../ObjectMapper";
7
7
@singleton ( )
8
8
export class EventMapper
9
9
implements
10
- ObjectMapper < { eventName : string ; data : Field [ ] } , Prisma . JsonObject >
10
+ ObjectMapper <
11
+ {
12
+ eventName : string ;
13
+ data : Field [ ] ;
14
+ source : "afterTxHook" | "beforeTxHook" | "runtime" ;
15
+ } ,
16
+ Prisma . JsonObject
17
+ >
11
18
{
12
- public mapIn ( input : Prisma . JsonObject ) : { eventName : string ; data : Field [ ] } {
13
- if ( input === undefined ) return { eventName : "" , data : [ ] } ;
19
+ public mapIn ( input : Prisma . JsonObject ) : {
20
+ eventName : string ;
21
+ data : Field [ ] ;
22
+ source : "afterTxHook" | "beforeTxHook" | "runtime" ;
23
+ } {
24
+ if ( input === undefined )
25
+ return { eventName : "" , data : [ ] , source : "runtime" } ;
14
26
return {
15
27
eventName : input . eventName as string ,
16
28
data : ( input . data as Prisma . JsonArray ) . map ( ( field ) =>
17
29
Field . fromJSON ( field as string )
18
30
) ,
31
+ source : this . sourceConvert ( input . source as string ) ,
19
32
} ;
20
33
}
21
34
22
35
public mapOut ( input : {
23
36
eventName : string ;
24
37
data : Field [ ] ;
38
+ source : "afterTxHook" | "beforeTxHook" | "runtime" ;
25
39
} ) : Prisma . JsonObject {
26
40
return {
27
41
eventName : input . eventName ,
28
42
data : input . data . map ( ( field ) => field . toString ( ) ) ,
43
+ source : input . source ,
29
44
} as Prisma . JsonObject ;
30
45
}
46
+
47
+ private sourceConvert ( input : string ) {
48
+ if (
49
+ input === "beforeTxHook" ||
50
+ input === "afterTxHook" ||
51
+ input === "runtime"
52
+ ) {
53
+ return input ;
54
+ }
55
+ throw new Error ( ) ;
56
+ }
31
57
}
32
58
33
59
@singleton ( )
34
60
export class EventArrayMapper
35
61
implements
36
62
ObjectMapper <
37
- { eventName : string ; data : Field [ ] } [ ] ,
63
+ {
64
+ eventName : string ;
65
+ data : Field [ ] ;
66
+ source : "afterTxHook" | "beforeTxHook" | "runtime" ;
67
+ } [ ] ,
38
68
Prisma . JsonValue | undefined
39
69
>
40
70
{
41
71
public constructor ( private readonly eventMapper : EventMapper ) { }
42
72
43
- public mapIn (
44
- input : Prisma . JsonValue | undefined
45
- ) : { eventName : string ; data : Field [ ] } [ ] {
73
+ public mapIn ( input : Prisma . JsonValue | undefined ) : {
74
+ eventName : string ;
75
+ data : Field [ ] ;
76
+ source : "afterTxHook" | "beforeTxHook" | "runtime" ;
77
+ } [ ] {
46
78
if ( input === undefined ) return [ ] ;
47
79
48
80
if ( Array . isArray ( input ) ) {
@@ -54,7 +86,11 @@ export class EventArrayMapper
54
86
}
55
87
56
88
public mapOut (
57
- input : { eventName : string ; data : Field [ ] } [ ]
89
+ input : {
90
+ eventName : string ;
91
+ data : Field [ ] ;
92
+ source : "afterTxHook" | "beforeTxHook" | "runtime" ;
93
+ } [ ]
58
94
) : Prisma . JsonValue {
59
95
return input . map ( ( event ) =>
60
96
this . eventMapper . mapOut ( event )
0 commit comments