EntityDTO
Builds a Data Transfer Object of the Entity
.
A DTO is a JSON-stringifiable object representing the Entity
that can be transferred or saved for later use:
import { EntityDTO } from 'dynamodb-toolbox/entity/actions/dto'
const pokemonEntityDTO = PokemonEntity.build(EntityDTO)
const pokemonEntityJSON = JSON.stringify(pokemonEntityDTO)
On DTO retrieval, you can use the fromDTO
util to re-create the original Entity
:
import { fromDTO } from 'dynamodb-toolbox/entity/actions/fromDTO'
const pokemonEntityDTO = JSON.parse(pokemonEntityJSON)
// 👇 Has a similar configuration to the original
const PokemonEntity = fromDTO(pokemonEntityDTO)
note
All TS types are lost in the process.