@moicky/dynamodb 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/client.d.ts +13 -13
- package/package.json +1 -1
- package/readme.md +23 -4
package/dist/lib/client.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
2
|
-
import
|
|
2
|
+
import { deleteItem, deleteItems, getItem, getItems, getAllItems, putItem, putItems, query, queryItems, queryAllItems, updateItem, removeAttributes } from "../operations";
|
|
3
3
|
interface OperationArguments {
|
|
4
|
-
deleteItem?: Parameters<typeof
|
|
5
|
-
deleteItems?: Parameters<typeof
|
|
6
|
-
getItem?: Parameters<typeof
|
|
7
|
-
getItems?: Parameters<typeof
|
|
8
|
-
getAllItems?: Parameters<typeof
|
|
9
|
-
putItem?: Parameters<typeof
|
|
10
|
-
putItems?: Parameters<typeof
|
|
11
|
-
query?: Parameters<typeof
|
|
12
|
-
queryItems?: Parameters<typeof
|
|
13
|
-
queryAllItems?: Parameters<typeof
|
|
14
|
-
updateItem?: Parameters<typeof
|
|
15
|
-
removeAttributes?: Parameters<typeof
|
|
4
|
+
deleteItem?: Parameters<typeof deleteItem>[1];
|
|
5
|
+
deleteItems?: Parameters<typeof deleteItems>[1];
|
|
6
|
+
getItem?: Parameters<typeof getItem>[1];
|
|
7
|
+
getItems?: Parameters<typeof getItems>[1];
|
|
8
|
+
getAllItems?: Parameters<typeof getAllItems>[0];
|
|
9
|
+
putItem?: Parameters<typeof putItem>[1];
|
|
10
|
+
putItems?: Parameters<typeof putItems>[1];
|
|
11
|
+
query?: Parameters<typeof query>[2];
|
|
12
|
+
queryItems?: Parameters<typeof queryItems>[2];
|
|
13
|
+
queryAllItems?: Parameters<typeof queryAllItems>[2];
|
|
14
|
+
updateItem?: Parameters<typeof updateItem>[2];
|
|
15
|
+
removeAttributes?: Parameters<typeof removeAttributes>[2];
|
|
16
16
|
}
|
|
17
17
|
type Operation = keyof OperationArguments;
|
|
18
18
|
declare interface KeySchema {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|

|
|
5
|
-

|
|
6
|
-

|
|
7
5
|
|
|
8
6
|
## Description
|
|
9
7
|
|
|
@@ -15,6 +13,7 @@ Contains convenience functions for all major dynamodb operations. Requires very
|
|
|
15
13
|
- 🔄 Will **retry** some operations (getItems, deleteItems) **up to 3 times** on unprocessed items
|
|
16
14
|
- 🔒 When specifying an item using its keySchema, all additional attributes (apart from keySchema attributes from `initSchema` or `PK` & `SK` as default) will be removed to avoid errors
|
|
17
15
|
- 👻 Will **use placeholders** to avoid colliding with [reserved words](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html) if applicable
|
|
16
|
+
- 🌎 Supports globally defined default arguments for each operation
|
|
18
17
|
|
|
19
18
|
## Installation
|
|
20
19
|
|
|
@@ -68,6 +67,26 @@ const item = await getItem(
|
|
|
68
67
|
await deleteItem(item, { TableName: process.env.SECOND_TABLE });
|
|
69
68
|
```
|
|
70
69
|
|
|
70
|
+
## Configuring global defaults
|
|
71
|
+
|
|
72
|
+
Global defaults can be configured using the `initDefaults` function. This allows to provide but still override every property of the `args` parameter.
|
|
73
|
+
|
|
74
|
+
Should be called before any DynamoDB operations are performed.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { initDefaults } from "@moicky/dynamodb";
|
|
78
|
+
|
|
79
|
+
// Enables consistent reads for all DynamoDB operations which support it.
|
|
80
|
+
initDefaults({
|
|
81
|
+
getItem: { ConsistentRead: true },
|
|
82
|
+
getAllItems: { ConsistentRead: true },
|
|
83
|
+
|
|
84
|
+
query: { ConsistentRead: true },
|
|
85
|
+
queryItems: { ConsistentRead: true },
|
|
86
|
+
queryAllItems: { ConsistentRead: true },
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
71
90
|
## Usage Examples
|
|
72
91
|
|
|
73
92
|
### Put Items
|
|
@@ -256,7 +275,7 @@ const id4 = await getAscendingId({
|
|
|
256
275
|
console.log(id4); // "00000010"
|
|
257
276
|
```
|
|
258
277
|
|
|
259
|
-
##
|
|
278
|
+
## What are the benefits and why should I use it?
|
|
260
279
|
|
|
261
280
|
Generally it makes it easier to interact with the dynamodb from AWS. Here are some before and after examples using the new aws-sdk v3:
|
|
262
281
|
|
|
@@ -377,7 +396,7 @@ const result = await updateItem(
|
|
|
377
396
|
### Setup
|
|
378
397
|
|
|
379
398
|
Requires environment variables to be present for the tests to successfully connect to dynamodb tables. You can find a list of required environment variables here:
|
|
380
|
-
[
|
|
399
|
+
[.env.template](.env.template)
|
|
381
400
|
|
|
382
401
|
They can be obtained using the **template.yml** which can be deployed on aws using:
|
|
383
402
|
|