Skip to content

Latest commit

 

History

History
322 lines (249 loc) · 11 KB

API.md

File metadata and controls

322 lines (249 loc) · 11 KB

serializr-fp API documentation

npm

(De)serialize complex object graphs to/from JSON

Constants

SKIP : symbol
DATE_ONLY : ModelSchema.<Date, string>
DATE : ModelSchema.<Date, string>
PRIMITIVE : ModelSchema.<TYPE, TYPE>

Functions

alias(property, schema)PropertySchema.<OBJECT, JSON>
array(schema)ModelSchema.<Array.<OBJECT>, Array.<JSON>>
computed(compute)PropertySchema.<OBJECT, JSON>
object(schema)ObjectModelSchema.<OBJECT>
omitBy(predicate, schema)ObjectModelSchema.<OBJECT>

Omit values after serialization.

While skipBy is useful to skip single values from an object, there are situations where you want to skip all properties if they are a certain value. In this case, it's easier to use this omitBy schema on the object schema.

omitNull(schema)ObjectModelSchema.<OBJECT>

Omit null values after serialization.

optional(schema)PropertySchema.<OBJECT, JSON>
skipBy(predicate, schema)PropertySchema.<OBJECT, JSON>

Skip the value after serialization if predicate returns true, in case the BE doesn't want to receive certain values.

Some REST API's rather have the key not being there than having a certain value they see as a nil value, like null, "" or {}. In that case, this skip schema can be used with a predicate function to check.

skipNull(schema)PropertySchema.<OBJECT, JSON>

Skip null value after serialization.

Also checks undefined values, to avoid conflicts with required properties. The required check is done as last and turns values into null if needed.

withDefault(defaultValue, schema)ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON>

Use a default value after deserialization, in cae the value turns up undefined.

withJsonDefault(defaultValue, schema)ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON>

Use a default json value before deserialization, in case the original value is undefined.

This can be very handy in case a sub-object is undefined, but you want the object to always be there, having it's properties initialized. For example, a patient object which has a person property to hold all it's name parts. In that case, you always want the person object to be there and have the name parts set to null instead, so you can use it in a form to fill out.

Typedefs

ComputeObjectModelOBJECT
ObjectModelSchema : ModelSchema.<OBJECT, Object>
ObjectSchema : Object.<string, PropertySchema>
PropertySchema : Object
PropertyTransformerTARGET
ModelSchema : Object
ModelTransformerTARGET

SKIP : symbol

Kind: global constant

DATE_ONLY : ModelSchema.<Date, string>

Kind: global constant

DATE : ModelSchema.<Date, string>

Kind: global constant

PRIMITIVE : ModelSchema.<TYPE, TYPE>

Kind: global constant
Template: TYPE

alias(property, schema) ⇒ PropertySchema.<OBJECT, JSON>

Kind: global function
Template: OBJECT, JSON

Param Type
property string
schema ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON>

array(schema) ⇒ ModelSchema.<Array.<OBJECT>, Array.<JSON>>

Kind: global function
Template: OBJECT, JSON

Param Type
schema ModelSchema.<OBJECT, JSON>

computed(compute) ⇒ PropertySchema.<OBJECT, JSON>

Kind: global function
Template: OBJECT, JSON

Param Type
compute ComputeObjectModel.<OBJECT, JSON>

object(schema) ⇒ ObjectModelSchema.<OBJECT>

Kind: global function
Template: OBJECT

Param Type
schema ObjectSchema

omitBy(predicate, schema) ⇒ ObjectModelSchema.<OBJECT>

Omit values after serialization.

While skipBy is useful to skip single values from an object, there are situations where you want to skip all properties if they are a certain value. In this case, it's easier to use this omitBy schema on the object schema.

Kind: global function
Template: OBJECT
See: skipBy

Param Type
predicate function
schema ObjectModelSchema.<OBJECT>

omitNull(schema) ⇒ ObjectModelSchema.<OBJECT>

Omit null values after serialization.

Kind: global function
Template: OBJECT
See: omitBy

Param Type
schema ObjectModelSchema.<OBJECT>

optional(schema) ⇒ PropertySchema.<OBJECT, JSON>

Kind: global function
Template: OBJECT, JSON

Param Type
schema ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON>

skipBy(predicate, schema) ⇒ PropertySchema.<OBJECT, JSON>

Skip the value after serialization if predicate returns true, in case the BE doesn't want to receive certain values.

Some REST API's rather have the key not being there than having a certain value they see as a nil value, like null, "" or {}. In that case, this skip schema can be used with a predicate function to check.

Kind: global function
Template: OBJECT, JSON

Param Type
predicate function
schema ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON>

skipNull(schema) ⇒ PropertySchema.<OBJECT, JSON>

Skip null value after serialization.

Also checks undefined values, to avoid conflicts with required properties. The required check is done as last and turns values into null if needed.

Kind: global function
Template: OBJECT, JSON
See: skipBy

Param Type
schema ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON>

withDefault(defaultValue, schema) ⇒ ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON>

Use a default value after deserialization, in cae the value turns up undefined.

Kind: global function
Template: OBJECT, JSON

Param Type
defaultValue OBJECT
schema ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON>

withJsonDefault(defaultValue, schema) ⇒ ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON>

Use a default json value before deserialization, in case the original value is undefined.

This can be very handy in case a sub-object is undefined, but you want the object to always be there, having it's properties initialized. For example, a patient object which has a person property to hold all it's name parts. In that case, you always want the person object to be there and have the name parts set to null instead, so you can use it in a form to fill out.

Kind: global function
Template: OBJECT, JSON

Param Type
defaultValue JSON
schema ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON>

ComputeObjectModel ⇒ OBJECT

Kind: global typedef
Template: OBJECT, JSON

Param Type Description
json Object
property string
{JSON) value

ObjectModelSchema : ModelSchema.<OBJECT, Object>

Kind: global typedef
Template: OBJECT

ObjectSchema : Object.<string, PropertySchema>

Kind: global typedef

PropertySchema : Object

Kind: global typedef
Template: OBJECT, JSON
Properties

Name Type
[property] string
serialize PropertyTransformer.<OBJECT, JSON>
deserialize PropertyTransformer.<JSON, OBJECT>

PropertyTransformer ⇒ TARGET

Kind: global typedef
Template: SOURCE, TARGET

Param Type
value SOURCE
source Object
property string

ModelSchema : Object

Kind: global typedef
Template: OBJECT, JSON
Properties

Name Type
serialize ModelTransformer.<OBJECT, JSON>
deserialize ModelTransformer.<JSON, OBJECT>

ModelTransformer ⇒ TARGET

Kind: global typedef
Template: SOURCE, TARGET

Param Type
value SOURCE