forked from mobxjs/serializr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raw.ts
29 lines (28 loc) · 957 Bytes
/
raw.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
import { processAdditionalPropArgs } from "../utils/utils"
import { PropSchema, AdditionalPropArgs } from "../api/types"
/**
* Indicates that this field is only need to putted in the serialized json or
* deserialized instance, without any transformations. Stay with its original value
*
* @example
* createModelSchema(Model, {
* rawData: raw(),
* })
*
* serialize(new Model({ rawData: { a: 1, b: [], c: {} } } }))
* // { "rawData": { a: 1, b: [], c: {} } } }
*
* @param additionalArgs optional object that contains beforeDeserialize and/or afterDeserialize handlers
*/
export default function raw(additionalArgs?: AdditionalPropArgs) {
let result: PropSchema = {
serializer: function (value) {
return value
},
deserializer: function (jsonValue, done) {
return void done(null, jsonValue)
},
}
result = processAdditionalPropArgs(result, additionalArgs)
return result
}