Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #8

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open

V2 #8

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
module.exports = {
extends: ['@kyeotic/eslint-config/node'],
rules: {}
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
parserOptions: {
ecmaVersion: 2019, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
},
extends: [
// Uses the recommended rules from the @typescript-eslint/eslint-plugin
'plugin:@typescript-eslint/recommended',
// Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'prettier/@typescript-eslint',
// Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
'plugin:prettier/recommended',
],
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
},
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ coverage/
.DS_STORE
.history
.vscode
/xunit.xml
/xunit.xml
lib/
4 changes: 4 additions & 0 deletions .prettierrc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tabWidth = 2
semi = false
singleQuote = true
printWidth = 100
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.0.0] - Unreleased
## Changed
- Re-write based on AWS SDK v3 DyanmoDB Client

## [1.2.0] - 2020-10-07
## Added
Passthrough for other dynamo options (e.g. `credentials`)
- Passthrough for other dynamo options (e.g. `credentials`)

## [1.1.0] - 2019-12-0
## Added
`LastEvaluatedKey` to `scanAll` and `queryAll` response
- `LastEvaluatedKey` to `scanAll` and `queryAll` response

## [1.0.0] - 2019-05-01
## Added
Initial OSS Release
- Initial OSS Release
41 changes: 22 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
dynamo-butter
======

> If you are going to use the AWS "Thick" Client, you might as well add butter
> For a smoother, richer experience use Butter

**dynamo-butter** is inspired by the [AWS Dynamo Thin Client](https://github.com/Nike-Inc/aws-thin-dynamo-node). It uses `util.promsify` of the client methods, adds the same Quality-of-Life methods (e.g. `batchGetAll`), and sets up the `keep-alive` agent by default.
## Why

Since AWS Lambda provides `aws-sdk` by default, this library does not declare a dependency on it. However, it is required. If you need to run unit tests, make sure to add `aws-sdk` to your own `devDepdendencies`.
The new AWS SDK v3 uses a modular design with typescript-generated code, providing faster startup, tree-shaking, and great intellisense. However it doesn't automatically marshall DyanmoDB's types into JS objects the way the v2 `DocumentClient` did and there is [strong internal resistance](https://github.com/aws/aws-sdk-js-v3/issues/1223) to providing this functionality.

Butter marshalls DynamoDB types for all operations. It also provides [automatic paging methods](#automatic-paging) for `query|scan|batchGet|batchWrite`. It's written in Typescript so you keep the intellisense and its built with rollup to retain tree-shakability.

## Installation
```
Expand Down Expand Up @@ -41,30 +43,31 @@ If you want to configure the DynamoDB DocumentClient yourself, you can pass it t

```javascript
const Butter = require('dynamo-butter')
const Dynamo = require('aws-sdk/clients/dynamodb')
const dynamo = new Dynamo.DocumentClient({
convertEmptyValues,
service: new Dynamo({
region,
endpoint
})
const { Agent } = require("https");
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
const { NodeHttpHandler } = require("@aws-sdk/node-http-handler");

// Disable keep-alive if you want bad performance
const dynamo = new DynamoDBClient({
requestHandler: new NodeHttpHandler({
httpsAgent: new Agent({ keepAlive: false }),
}),
})
const client = Butter.up(dynamo)
```

#### Config Options
The second parameter to `Butter.up()` is an options object for butter. It is optional, and each property is optional and defaults to true.

* **includeAutoPagingMethods**: set to `false` to not add `batchWriteAll` `batchGetAll` `queryAll` and `scanAll` to the client.
* **useKeepAlive**: set to false to disable `keepAlive` on the configured agent.
The second parameter to `Butter.up()` is an options object for butter. It is optional; each property is also optional and defaults to true.

```javascript
const client = Butter.up({
region: 'us-west-2',
endpoint: IS_TESTING && TEST_SERVER_ENDPOINT,
convertEmptyValues: true // optional, defaults to true
}, {
includeAutoPagingMethods: true,
useKeepAlive: true
convertEmptyValues: true,
removeUndefinedValues: true,
}
```
```

## Automatic Paging

Butter provides 4 methods for automatically paging through the methods that can return unfinished results: `query`, `scan`, `batchGet` and `batchWrite`. Be warned that you can easily run out of memory, or cause very large cost-usage, when using these methods. Make sure you understand the scan-space before using them.
16 changes: 16 additions & 0 deletions fixup
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
#
# Add package.json files to cjs/mjs subtrees
#

cat >dist/cjs/package.json <<!EOF
{
"type": "commonjs"
}
!EOF

cat >dist/mjs/package.json <<!EOF
{
"type": "module"
}
!EOF
12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
roots: ['<rootDir>/src', '<rootDir>/test'],
testMatch: [
'**/__tests__/**/*.+(ts|tsx|js)',
'**/?(*.)+(spec|test).+(ts|tsx|js)',
],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
collectCoverage: true,
coverageReporters: ['json', 'html'],
}
Loading