@@ -12,17 +12,33 @@ export class ClassTransformer {
12
12
/**
13
13
* Converts class (constructor) object to plain (literal) object. Also works with arrays.
14
14
*/
15
- classToPlain < T extends Record < string , any > > ( object : T , options ?: ClassTransformOptions ) : Record < string , any > ;
16
- classToPlain < T extends Record < string , any > > ( object : T [ ] , options ?: ClassTransformOptions ) : Record < string , any > [ ] ;
15
+ classToPlain < T extends Record < string , any > > (
16
+ object : T ,
17
+ options ?: ClassTransformOptions
18
+ ) : Record < string , any > ;
19
+ classToPlain < T extends Record < string , any > > (
20
+ object : T [ ] ,
21
+ options ?: ClassTransformOptions
22
+ ) : Record < string , any > [ ] ;
17
23
classToPlain < T extends Record < string , any > > (
18
24
object : T | T [ ] ,
19
25
options ?: ClassTransformOptions
20
26
) : Record < string , any > | Record < string , any > [ ] {
21
- const executor = new TransformOperationExecutor ( TransformationType . CLASS_TO_PLAIN , {
22
- ...defaultOptions ,
23
- ...options ,
24
- } ) ;
25
- return executor . transform ( undefined , object , undefined , undefined , undefined , undefined ) ;
27
+ const executor = new TransformOperationExecutor (
28
+ TransformationType . CLASS_TO_PLAIN ,
29
+ {
30
+ ...defaultOptions ,
31
+ ...options ,
32
+ }
33
+ ) ;
34
+ return executor . transform (
35
+ undefined ,
36
+ object ,
37
+ undefined ,
38
+ undefined ,
39
+ undefined ,
40
+ undefined
41
+ ) ;
26
42
}
27
43
28
44
/**
@@ -45,11 +61,21 @@ export class ClassTransformer {
45
61
plainObject : P | P [ ] ,
46
62
options ?: ClassTransformOptions
47
63
) : T | T [ ] {
48
- const executor = new TransformOperationExecutor ( TransformationType . CLASS_TO_PLAIN , {
49
- ...defaultOptions ,
50
- ...options ,
51
- } ) ;
52
- return executor . transform ( plainObject , object , undefined , undefined , undefined , undefined ) ;
64
+ const executor = new TransformOperationExecutor (
65
+ TransformationType . CLASS_TO_PLAIN ,
66
+ {
67
+ ...defaultOptions ,
68
+ ...options ,
69
+ }
70
+ ) ;
71
+ return executor . transform (
72
+ plainObject ,
73
+ object ,
74
+ undefined ,
75
+ undefined ,
76
+ undefined ,
77
+ undefined
78
+ ) ;
53
79
}
54
80
55
81
/**
@@ -70,11 +96,21 @@ export class ClassTransformer {
70
96
plain : V | V [ ] ,
71
97
options ?: ClassTransformOptions
72
98
) : T | T [ ] {
73
- const executor = new TransformOperationExecutor ( TransformationType . PLAIN_TO_CLASS , {
74
- ...defaultOptions ,
75
- ...options ,
76
- } ) ;
77
- return executor . transform ( undefined , plain , cls , undefined , undefined , undefined ) ;
99
+ const executor = new TransformOperationExecutor (
100
+ TransformationType . PLAIN_TO_CLASS ,
101
+ {
102
+ ...defaultOptions ,
103
+ ...options ,
104
+ }
105
+ ) ;
106
+ return executor . transform (
107
+ undefined ,
108
+ plain ,
109
+ cls ,
110
+ undefined ,
111
+ undefined ,
112
+ undefined
113
+ ) ;
78
114
}
79
115
80
116
/**
@@ -87,17 +123,31 @@ export class ClassTransformer {
87
123
plain : V ,
88
124
options ?: ClassTransformOptions
89
125
) : T ;
90
- plainToClassFromExist < T extends Record < string , any > , V > ( clsObject : T , plain : V , options ?: ClassTransformOptions ) : T [ ] ;
126
+ plainToClassFromExist < T extends Record < string , any > , V > (
127
+ clsObject : T ,
128
+ plain : V ,
129
+ options ?: ClassTransformOptions
130
+ ) : T [ ] ;
91
131
plainToClassFromExist < T extends Record < string , any > , V > (
92
132
clsObject : T ,
93
133
plain : V | V [ ] ,
94
134
options ?: ClassTransformOptions
95
135
) : T | T [ ] {
96
- const executor = new TransformOperationExecutor ( TransformationType . PLAIN_TO_CLASS , {
97
- ...defaultOptions ,
98
- ...options ,
99
- } ) ;
100
- return executor . transform ( clsObject , plain , undefined , undefined , undefined , undefined ) ;
136
+ const executor = new TransformOperationExecutor (
137
+ TransformationType . PLAIN_TO_CLASS ,
138
+ {
139
+ ...defaultOptions ,
140
+ ...options ,
141
+ }
142
+ ) ;
143
+ return executor . transform (
144
+ clsObject ,
145
+ plain ,
146
+ undefined ,
147
+ undefined ,
148
+ undefined ,
149
+ undefined
150
+ ) ;
101
151
}
102
152
103
153
/**
@@ -106,26 +156,58 @@ export class ClassTransformer {
106
156
classToClass < T > ( object : T , options ?: ClassTransformOptions ) : T ;
107
157
classToClass < T > ( object : T [ ] , options ?: ClassTransformOptions ) : T [ ] ;
108
158
classToClass < T > ( object : T | T [ ] , options ?: ClassTransformOptions ) : T | T [ ] {
109
- const executor = new TransformOperationExecutor ( TransformationType . CLASS_TO_CLASS , {
110
- ...defaultOptions ,
111
- ...options ,
112
- } ) ;
113
- return executor . transform ( undefined , object , undefined , undefined , undefined , undefined ) ;
159
+ const executor = new TransformOperationExecutor (
160
+ TransformationType . CLASS_TO_CLASS ,
161
+ {
162
+ ...defaultOptions ,
163
+ ...options ,
164
+ }
165
+ ) ;
166
+ return executor . transform (
167
+ undefined ,
168
+ object ,
169
+ undefined ,
170
+ undefined ,
171
+ undefined ,
172
+ undefined
173
+ ) ;
114
174
}
115
175
116
176
/**
117
177
* Converts class (constructor) object to plain (literal) object.
118
178
* Uses given plain object as source object (it means fills given plain object with data from class object).
119
179
* Also works with arrays.
120
180
*/
121
- classToClassFromExist < T > ( object : T , fromObject : T , options ?: ClassTransformOptions ) : T ;
122
- classToClassFromExist < T > ( object : T , fromObjects : T [ ] , options ?: ClassTransformOptions ) : T [ ] ;
123
- classToClassFromExist < T > ( object : T , fromObject : T | T [ ] , options ?: ClassTransformOptions ) : T | T [ ] {
124
- const executor = new TransformOperationExecutor ( TransformationType . CLASS_TO_CLASS , {
125
- ...defaultOptions ,
126
- ...options ,
127
- } ) ;
128
- return executor . transform ( fromObject , object , undefined , undefined , undefined , undefined ) ;
181
+ classToClassFromExist < T > (
182
+ object : T ,
183
+ fromObject : T ,
184
+ options ?: ClassTransformOptions
185
+ ) : T ;
186
+ classToClassFromExist < T > (
187
+ object : T ,
188
+ fromObjects : T [ ] ,
189
+ options ?: ClassTransformOptions
190
+ ) : T [ ] ;
191
+ classToClassFromExist < T > (
192
+ object : T ,
193
+ fromObject : T | T [ ] ,
194
+ options ?: ClassTransformOptions
195
+ ) : T | T [ ] {
196
+ const executor = new TransformOperationExecutor (
197
+ TransformationType . CLASS_TO_CLASS ,
198
+ {
199
+ ...defaultOptions ,
200
+ ...options ,
201
+ }
202
+ ) ;
203
+ return executor . transform (
204
+ fromObject ,
205
+ object ,
206
+ undefined ,
207
+ undefined ,
208
+ undefined ,
209
+ undefined
210
+ ) ;
129
211
}
130
212
131
213
/**
@@ -140,15 +222,23 @@ export class ClassTransformer {
140
222
/**
141
223
* Deserializes given JSON string to a object of the given class.
142
224
*/
143
- deserialize < T > ( cls : ClassConstructor < T > , json : string , options ?: ClassTransformOptions ) : T {
225
+ deserialize < T > (
226
+ cls : ClassConstructor < T > ,
227
+ json : string ,
228
+ options ?: ClassTransformOptions
229
+ ) : T {
144
230
const jsonObject : T = JSON . parse ( json ) ;
145
231
return this . plainToClass ( cls , jsonObject , options ) ;
146
232
}
147
233
148
234
/**
149
235
* Deserializes given JSON string to an array of objects of the given class.
150
236
*/
151
- deserializeArray < T > ( cls : ClassConstructor < T > , json : string , options ?: ClassTransformOptions ) : T [ ] {
237
+ deserializeArray < T > (
238
+ cls : ClassConstructor < T > ,
239
+ json : string ,
240
+ options ?: ClassTransformOptions
241
+ ) : T [ ] {
152
242
const jsonObject : any [ ] = JSON . parse ( json ) ;
153
243
return this . plainToClass ( cls , jsonObject , options ) ;
154
244
}
0 commit comments