@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.
@@ -1,18 +1,18 @@
1
1
  import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
2
- import * as ops from "../operations";
2
+ import { deleteItem, deleteItems, getItem, getItems, getAllItems, putItem, putItems, query, queryItems, queryAllItems, updateItem, removeAttributes } from "../operations";
3
3
  interface OperationArguments {
4
- deleteItem?: Parameters<typeof ops.deleteItem>[1];
5
- deleteItems?: Parameters<typeof ops.deleteItems>[1];
6
- getItem?: Parameters<typeof ops.getItem>[1];
7
- getItems?: Parameters<typeof ops.getItems>[1];
8
- getAllItems?: Parameters<typeof ops.getAllItems>[0];
9
- putItem?: Parameters<typeof ops.putItem>[1];
10
- putItems?: Parameters<typeof ops.putItems>[1];
11
- query?: Parameters<typeof ops.query>[2];
12
- queryItems?: Parameters<typeof ops.queryItems>[2];
13
- queryAllItems?: Parameters<typeof ops.queryAllItems>[2];
14
- updateItem?: Parameters<typeof ops.updateItem>[2];
15
- removeAttributes?: Parameters<typeof ops.removeAttributes>[2];
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moicky/dynamodb",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Contains a collection of convenience functions for working with AWS DynamoDB",
package/readme.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  ![](https://img.shields.io/github/actions/workflow/status/moicky/dynamodb/npm-publish.yml?label=build)
4
4
  ![](https://img.shields.io/github/actions/workflow/status/moicky/dynamodb/run-tests.yml?label=tests)
5
- ![](https://img.shields.io/github/languages/count/moicky/dynamodb)
6
- ![](https://img.shields.io/tokei/lines/github/moicky/dynamodb)
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
- ## Why should I use this?
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
- [./test/setup/setup-each.js](./test/setup/setup-each.js)
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