io-ts-dynamodb
Type-safe codecs for DynamoDB AttributeValue types using io-ts.
Install
npm install io-ts io-ts-types io-ts-dynamodb
Usage
import * as D from 'io-ts-dynamodb'
// Define a DynamoDB record
const User = D.record({
id: D.string,
name: D.string,
age: D.number
})
const user = { id: '123', name: 'John', age: 30 }
// Encode to DynamoDB format
const encoded = User.encode(user)
// { id: { S: '123' }, name: { S: 'John' }, age: { N: '30' } }
// Decode with validation
const decoded = User.decode(encoded)
// E.right({ id: '123', name: 'John', age: 30 })
Types
D.string
- String valuesD.number
- Numeric valuesD.bool
- Boolean valuesD.stringSet
- String setsD.numberSet
- Number setsD.null
- Null valuesD.record(props)
- Record structuresD.map(codec)
- Nested objectsD.list(codec)
- Arrays