Skip to content

Commit 1759d1b

Browse files
committed
Merge branch 'v0.3'
2 parents 470cb06 + b810db5 commit 1759d1b

File tree

77 files changed

+7180
-4012
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+7180
-4012
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ coverage
22
node_modules
33
__tests__
44
*.test.js
5+
dist

.eslintrc.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
"sourceType": "module"
1010
},
1111
"rules": {
12-
"indent": [
13-
"error",
14-
2
15-
],
1612
"linebreak-style": [
1713
"error",
1814
"unix"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ dump.rdb
77

88
# coverage
99
coverage
10+
11+
# dist
12+
dist

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019-2020 Jeremy Daly
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 88 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
# DynamoDB Toolbox - v0.2
1+
# DynamoDB Toolbox
22

3-
[![Build Status](https://travis-ci.org/jeremydaly/dynamodb-toolbox.svg?branch=v0.2)](https://travis-ci.org/jeremydaly/dynamodb-toolbox)
3+
[![Build Status](https://travis-ci.org/jeremydaly/dynamodb-toolbox.svg?branch=master)](https://travis-ci.org/jeremydaly/dynamodb-toolbox)
44
[![npm](https://img.shields.io/npm/v/dynamodb-toolbox.svg)](https://www.npmjs.com/package/dynamodb-toolbox)
55
[![npm](https://img.shields.io/npm/l/dynamodb-toolbox.svg)](https://www.npmjs.com/package/dynamodb-toolbox)
66
[![Coverage Status](https://coveralls.io/repos/github/jeremydaly/dynamodb-toolbox/badge.svg?branch=master)](https://coveralls.io/github/jeremydaly/dynamodb-toolbox?branch=master)
77

88
![dynamodb-toolbox](https://user-images.githubusercontent.com/2053544/69847647-b7910780-1245-11ea-8403-a35a0158f3aa.png)
99

10-
11-
### **NOTE:** This project is in BETA. Please submit [issues/feedback](https://github.com/jeremydaly/dynamodb-toolbox/issues) or feel free to contact me on Twitter [@jeremy_daly](https://twitter.com/jeremy_daly).
12-
1310
## Single Table Designs have never been this easy!
1411

1512
The **DynamoDB Toolbox** is a set of tools that makes it easy to work with [Amazon DynamoDB](https://aws.amazon.com/dynamodb/) and the [DocumentClient](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/dynamodb-example-document-client.html). It's designed with **Single Tables** in mind, but works just as well with multiple tables. It lets you define your Entities (with typings and aliases) and map them to your DynamoDB tables. You can then **generate the API parameters** to `put`, `get`, `delete`, `update`, `query`, `scan`, `batchGet`, and `batchWrite` data by passing in JavaScript objects. The DynamoDB Toolbox will map aliases, validate and coerce types, and even write complex `UpdateExpression`s for you. 😉
@@ -146,12 +143,13 @@ If you like working with ORMs, that's great, and you should definitely give thes
146143
- **Projection Builder:** Specify which attributes and paths should be returned for each entity type, and automatically filter the results.
147144
- **Secondary Index Support:** Map your secondary indexes (GSIs and LSIs) to your table, and dynamically link your entity attributes.
148145
- **Batch Operations:** Full support for batch operations with a simpler interface to work with multiple entities and tables.
146+
- **Transactions:** Full support for transaction with a simpler interface to work with multiple entities and tables.
149147
- **Default Value Dependency Graphs:** Create dynamic attribute defaults by chaining other dynamic attribute defaults together.
148+
- **TypeScript Support:** v0.3 of this library was rewritten in TypeScript to provide strong typing support. Additional work is still required to support schema typing.
150149

151150
## Table of Contents
152151

153-
- [DynamoDB Toolbox - v0.2](#dynamodb-toolbox---v02)
154-
- [**NOTE:** This project is in BETA. Please submit issues/feedback or feel free to contact me on Twitter [@jeremy_daly](https://twitter.com/jeremy_daly).](#note-this-project-is-in-beta-please-submit-issuesfeedback-or-feel-free-to-contact-me-on-twitter-jeremy_daly)
152+
- [DynamoDB Toolbox](#dynamodb-toolbox)
155153
- [Single Table Designs have never been this easy!](#single-table-designs-have-never-been-this-easy)
156154
- [Installation and Basic Usage](#installation-and-basic-usage)
157155
- [This is *NOT* an ORM (at least it's not trying to be)](#this-is-not-an-orm-at-least-its-not-trying-to-be)
@@ -184,6 +182,11 @@ If you like working with ORMs, that's great, and you should definitely give thes
184182
- [Return Data](#return-data-2)
185183
- [batchWrite(items [,options] [,parameters])](#batchwriteitems-options-parameters)
186184
- [Return Data](#return-data-3)
185+
- [transactGet(items [,options] [,parameters])](#transactgetitems-options-parameters)
186+
- [Accessing items from multiple tables](#accessing-items-from-multiple-tables)
187+
- [Return Data](#return-data-4)
188+
- [transactWrite(items [,options] [,parameters])](#transactwriteitems-options-parameters)
189+
- [Return Data](#return-data-5)
187190
- [parse(entity, input [,include])](#parseentity-input-include)
188191
- [get(entity, key [,options] [,parameters])](#getentity-key-options-parameters)
189192
- [delete(entity, key [,options] [,parameters])](#deleteentity-key-options-parameters)
@@ -572,7 +575,7 @@ The `scan()` method accepts two arguments. The first argument is an `options` ob
572575
| limit | `number` | The maximum number of items to retrieve per scan. (Limit) |
573576
| consistent | `boolean` | Enable a consistent read of the items (ConsistentRead) |
574577
| capacity | `string` | Return the amount of consumed capacity. One of either `none`, `total`, or `indexes` (ReturnConsumedCapacity) |
575-
| select | `string` | The attributes to be returned in the result. One of either `string` | `all_attributes`, `all_projected_attributes`, `specific_attributes`, or `count` (Select) |
578+
| select | `string` | The attributes to be returned in the result. One of either `all_attributes`, `all_projected_attributes`, `specific_attributes`, or `count` (Select) |
576579
| filters | `array` or `object` | A complex `object` or `array` of objects that specifies the scan's filter condition. See [Filters and Conditions](#filters-and-conditions). (FilterExpression) |
577580
| attributes | `array` or `object` | An `array` or array of complex `objects` that specify which attributes should be returned. See [Projection Expression](#projection-expression) below (ProjectionExpression) |
578581
| startKey | `object` | An object that contains the `partitionKey` and `sortKey` of the first item that this operation will evaluate. (ExclusiveStartKey) |
@@ -689,6 +692,82 @@ If you prefer to specify your own parameters, the optional third argument allows
689692
#### Return Data
690693
The data is returned with the same response syntax as the [DynamoDB BatchWriteItem API](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html). If `autoExecute` and `autoParse` are enabled, a `.next()` method will be available on the returned object. Calling this function will call the `batchWrite` method again using the same options and passing any `UnprocessedItems` in as the `RequestItems`. This is a convenience method for retrying unprocessed keys.
691694

695+
696+
697+
698+
699+
### transactGet(items [,options] [,parameters])
700+
701+
> TransactGetItems is a synchronous operation that atomically retrieves multiple items from one or more tables (but not from indexes) in a single account and Region.
702+
703+
The `transactGet` method is a wrapper for the [DynamoDB TransactGetItems API](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactGetItems.html). The DynamoDB Toolbox `transactGet` method supports all **TransactGetItem** API operations. The `transactGet` method returns a `Promise` and you must use `await` or `.then()` to retrieve the results. An alternative, synchronous method named `transactGetParams` can be used, but will only retrieve the generated parameters.
704+
705+
The `transacthGet` method accepts three arguments. The first is an `array` of item keys to get. The DynamoDB Toolbox provides the `getTransaction` method on your entities to help you generate the proper key configuration. You can specify different entity types as well as entities from different tables, and this library will handle the proper payload construction.
706+
707+
The optional second argument accepts an `options` object. The following options are all optional (corresponding TransactGetItems API references in parentheses):
708+
709+
| Option | Type | Description |
710+
| -------- | :--: | ----------- |
711+
| capacity | `string` | Return the amount of consumed capacity. One of either `none`, `total`, or `indexes` (ReturnConsumedCapacity) |
712+
| execute | `boolean` | Enables/disables automatic execution of the DocumentClient method (default: *inherited from Table*) |
713+
| parse | `boolean` | Enables/disables automatic parsing of returned data when `autoExecute` evaluates to `true` (default: *inherited from Table*) |
714+
715+
#### Accessing items from multiple tables
716+
Transaction items are atomic, so each `Get` contains the table name and key necessary to retrieve the item. The library will automatically handle adding the necessary information and will parse each entity automatically for you.
717+
718+
```javascript
719+
const results = await MyTable.transactGet(
720+
[
721+
User.getTransaction({ family: 'Brady', name: 'Mike' }),
722+
User.getTransaction({ family: 'Brady', name: 'Carol' }),
723+
Pet.getTransaction({ family: 'Brady', name: 'Tiger' })
724+
],
725+
{ capacity: 'total' }
726+
)
727+
```
728+
729+
If you prefer to specify your own parameters, the optional third argument allows you to add custom parameters. [See Adding custom parameters and clauses](#adding-custom-parameters-and-clauses) for more information.
730+
731+
#### Return Data
732+
The data is returned with the same response syntax as the [DynamoDB TransactGetItems API](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactGetItems.html). If `autoExecute` and `autoParse` are enabled, any `Responses` data returned will be parsed into its corresponding Entity's aliases. Otherwise, the DocumentClient will return the unmarshalled data.
733+
734+
### transactWrite(items [,options] [,parameters])
735+
736+
> TransactWriteItems is a synchronous write operation that groups up to 25 action requests. The actions are completed atomically so that either all of them succeed, or all of them fail.
737+
738+
The `transactWrite` method is a wrapper for the [DynamoDB TransactWriteItems API](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html). The DynamoDB Toolbox `transactWrite` method supports all **TransactWriteItems** API operations. The `transactWrite` method returns a `Promise` and you must use `await` or `.then()` to retrieve the results. An alternative, synchronous method named `transactWriteParams` can be used, but will only retrieve the generated parameters.
739+
740+
The `transactWrite` method accepts three arguments. The first is an `array` of item keys to either `put`, `delete`, `update` or `conditionCheck`. The DynamoDB Toolbox provides `putTransaction`,`deleteTransaction`, `updateTransaction`, and `conditionCheck` methods on your entities to help you generate the proper configuration for each item. You can specify different entity types as well as entities from different tables, and this library will handle the proper payload construction.
741+
742+
The optional second argument accepts an `options` object. The following options are all optional (corresponding TransactWriteItems API references in parentheses):
743+
744+
| Option | Type | Description |
745+
| -------- | :--: | ----------- |
746+
| capacity | `string` | Return the amount of consumed capacity. One of either `none`, `total`, or `indexes` (ReturnConsumedCapacity) |
747+
| metrics | `string` | Return item collection metrics. If set to `size`, the response includes statistics about item collections, if any, that were modified during the operation are returned in the response. One of either `none` or `size` (ReturnItemCollectionMetrics) |
748+
| token | `string` | Optional token to make the call idempotent, meaning that multiple identical calls have the same effect as one single call. (ClientRequestToken) |
749+
| execute | `boolean` | Enables/disables automatic execution of the DocumentClient method (default: *inherited from Entity*) |
750+
| parse | `boolean` | Enables/disables automatic parsing of returned data when `autoExecute` evaluates to `true` (default: *inherited from Entity*) |
751+
752+
```javascript
753+
const result = await Default.transactWrite(
754+
[
755+
Pet.conditionCheck({ family: 'Brady', name: 'Tiger' }, { conditions: { attr: 'alive', eq: false } },
756+
Pet.deleteTransaction({ family: 'Brady', name: 'Tiger' }),
757+
User.putTransaction({ family: 'Brady', name: 'Carol', age: 40, roles: ['mother','wife'] }),
758+
User.putTransaction({ family: 'Brady', name: 'Mike', age: 42, roles: ['father','husband'] })
759+
],{
760+
capacity: 'total',
761+
metrics: 'size',
762+
}
763+
)
764+
```
765+
766+
If you prefer to specify your own parameters, the optional third argument allows you to add custom parameters. [See Adding custom parameters and clauses](#adding-custom-parameters-and-clauses) for more information.
767+
768+
#### Return Data
769+
The data is returned with the same response syntax as the [DynamoDB TransactWriteItems API](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html).
770+
692771
### parse(entity, input [,include])
693772
694773
Executes the `parse` method of the supplied `entity`. The `entity` must be a `string` that references the name of an Entity associated with the table. See the [Entity `parse` method](#parseinput-include) for additional parameters and behavior.
@@ -1182,4 +1261,4 @@ let results = await MyEntity.update(item, {}, {
11821261
<IMG SRC="https://ad.doubleclick.net/ddm/trackimp/N1116303.3950900PODSEARCH.COM/B24770737.285235234;dc_trk_aid=479074825;dc_trk_cid=139488579;ord=[timestamp];dc_lat=;dc_rdid=;tag_for_child_directed_treatment=;tfua=;gdpr=${GDPR};gdpr_consent=${GDPR_CONSENT_755}?" BORDER="0" HEIGHT="1" WIDTH="1" ALT="Advertisement">
11831262
11841263
## Contributions and Feedback
1185-
Contributions, ideas and bug reports are welcome and greatly appreciated. Please add [issues](https://github.com/jeremydaly/dynamodb-toolbox/issues) for suggestions and bug reports or create a pull request. You can also contact me on Twitter: [@jeremy_daly](https://twitter.com/jeremy_daly).
1264+
Contributions, ideas and bug reports are welcome and greatly appreciated. Please add [issues](https://github.com/jeremydaly/dynamodb-toolbox/issues) for suggestions and bug reports or create a pull request. You can also contact me on Twitter: [@jeremy_daly](https://twitter.com/jeremy_daly).

__tests__/bootstrap-tests.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)