@moicky/dynamodb 2.4.4 → 2.4.5

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,5 +1,8 @@
1
- import { BatchWriteItemCommandInput, BatchWriteItemCommandOutput, PutItemCommandInput, PutItemCommandOutput } from "@aws-sdk/client-dynamodb";
1
+ import { BatchWriteItemCommandInput, BatchWriteItemCommandOutput, PutItemCommandOutput, PutItemCommandInput as _PutItemCommandInput } from "@aws-sdk/client-dynamodb";
2
2
  import { DynamoDBItem } from "../types";
3
+ type PutItemCommandInput = Omit<_PutItemCommandInput, "ReturnValues"> & {
4
+ ReturnValues?: "NONE" | "ALL_OLD" | "ALL_NEW";
5
+ };
3
6
  /**
4
7
  * Inserts an item into the DynamoDB table.
5
8
  * @param item - The item to insert into the table.
@@ -6,16 +6,20 @@ const lib_1 = require("../lib");
6
6
  async function putItem(item, args) {
7
7
  const argsWithDefaults = (0, lib_1.withDefaults)(args || {}, "putItem");
8
8
  if (!Object.keys(item).includes("createdAt")) {
9
- item.createdAt = Date.now();
9
+ item = { ...item, createdAt: Date.now() };
10
10
  }
11
+ const { ReturnValues, ...otherArgs } = argsWithDefaults;
11
12
  return (0, lib_1.getClient)()
12
13
  .send(new client_dynamodb_1.PutItemCommand({
13
14
  Item: (0, lib_1.marshallWithOptions)(item),
14
- ...argsWithDefaults,
15
- TableName: argsWithDefaults?.TableName || (0, lib_1.getDefaultTable)(),
15
+ ...otherArgs,
16
+ ...(ReturnValues && ReturnValues !== "ALL_NEW" && { ReturnValues }),
17
+ TableName: otherArgs?.TableName || (0, lib_1.getDefaultTable)(),
16
18
  }))
17
- .then((res) => argsWithDefaults?.ReturnValues
18
- ? (0, lib_1.unmarshallWithOptions)(res?.Attributes)
19
+ .then((res) => ReturnValues
20
+ ? ReturnValues === "ALL_NEW"
21
+ ? item
22
+ : (0, lib_1.unmarshallWithOptions)(res?.Attributes)
19
23
  : res);
20
24
  }
21
25
  exports.putItem = putItem;
@@ -6,7 +6,7 @@ const lib_1 = require("../lib");
6
6
  async function updateItem(key, data, args) {
7
7
  const argsWithDefaults = (0, lib_1.withDefaults)(args || {}, "updateItem");
8
8
  if (!Object.keys(data).includes("updatedAt")) {
9
- data.updatedAt = Date.now();
9
+ data = { ...data, updatedAt: Date.now() };
10
10
  }
11
11
  const valuesInCondition = (0, lib_1.getAttributesFromExpression)(argsWithDefaults?.ConditionExpression || "", ":");
12
12
  const namesInCondition = (0, lib_1.getAttributesFromExpression)(argsWithDefaults?.ConditionExpression || "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moicky/dynamodb",
3
- "version": "2.4.4",
3
+ "version": "2.4.5",
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",