# dynamoo

> Serialize and parse DynamoDB items

Latest version **0.1.0** (published 2019-11-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install dynamoo
pnpm add dynamoo
yarn add dynamoo
bun add dynamoo
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2019-11-22 |
| First published | 2018-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | articulate |
| Maintainers | flintinatux |
| Keywords | aws, dynamodb, serialize, parse |

## Links

- npm: https://www.npmjs.com/package/dynamoo
- Repository: https://github.com/articulate/dynamoo
- Homepage: https://github.com/articulate/dynamoo#readme
- Issues: https://github.com/articulate/dynamoo/issues
- npm.io page: https://npm.io/package/dynamoo

## Dependencies (1)

- [tinyfunk](https://npm.io/package/tinyfunk.md) ^1.6.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2019-11-22
- 0.0.2 — 2019-02-22
- 0.0.1 — 2018-11-19

## README

```
_______
< dynamoo >
 -------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
```

# dynamoo
[![npm version](https://img.shields.io/npm/v/dynamoo.svg)](https://www.npmjs.com/package/dynamoo)
[![npm downloads](https://img.shields.io/npm/dm/dynamoo.svg)](https://www.npmjs.com/package/dynamoo)
[![Build Status](https://travis-ci.org/articulate/dynamoo.svg?branch=master)](https://travis-ci.org/articulate/dynamoo)
[![Coverage Status](https://coveralls.io/repos/github/articulate/dynamoo/badge.svg?branch=master)](https://coveralls.io/github/articulate/dynamoo?branch=master)

Serialize and parse DynamoDB items.

## API

- [`serialize`](#serialize)
- [`parse`](#parse)
- [Caveat emptor](#caveat-emptor)

### `serialize`

Serializing data to store in DynamoDB is hard, but `dynamoo` makes it easier.  Suppose you have this item you want to `putItem` to DynamoDB:

```js
const item = {
  bool: true,
  func: Function.prototype,
  list: ['a', 1, false, null, { key: 'val' }],
  map: { key: 'val', nested: ['list'] },
  null: null,
  num: 42,
  set: new Set(['a', 'a', 'b']),
  string: 'strung',
  undef: undefined
}
```

Just `serialize` that data before sending, like this:

```js
const AWS = require('aws-sdk')
const { serialize } = require('dynamoo')

const dynamo = new AWS.DynamoDB()

dynamo.putItem({ Item: serialize(item), TableName }, console.log)
```

The serialized `Item` that gets sent looks like this:

```js
const Item = {
  bool: { BOOL: true },
  list: {
    L: [
      { S: 'a' },
      { N: '1' },
      { BOOL: false },
      { NULL: true },
      { M: { key: { S: 'val' } } }
    ]
  },
  map: {
    M: {
      key: { S: 'val' },
      nested: { L: [{ S: 'list' }] }
    }
  },
  null: { NULL: true },
  num: { N: '42' },
  set: { SS: ['a', 'b'] },
  string: { S: 'strung' }
}
```

Wow!  It's like magic!  Notice that any `Function` or `undefined` attributes are ignored, since the former doesn't serialize, and the latter technically doesn't exist.

### `parse`

But wait... what about querying DynamoDB?  The `data.Items` that are found need to be parsed.  Got you covered on that as well:

```js
const { parse } = require('dynamoo')

dynamo.query(params, (err, data) =>
  console.log(data.Items.map(parse))
)
```

Notice that `parse` accepts a single `Item`.  So for `query` you'll need to `.map()`, but for `getItem`, you can use it like this:

```js
dynamo.getItem({ Key, TableName }, (err, data) =>
  console.log(parse(data.Item))
)
```

The careful observer will notice that - with the exception of `Function` and `undefined` attributes - the `serialize` and `parse` functions are isomorphic!  :heart_eyes:

```js
const { expect } = require('chai')

expect(parse(serialize(item))).to.eql(item)
```

### Caveat emptor

By design, `dynamoo` only supports the following data types for attributes:

  - `Array`
  - `Boolean`
  - `null`
  - `Number`
  - `Object`
  - `Set` (of strings)
  - `String`

If you want to use any other fancier types, such as `Map`, or `Set` of numbers, etc., then you may need to do some additional work.  Or file an issue.  :wink:

---
_Source: https://npm.io/package/dynamoo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
