@moicky/dynamodb 2.4.4 → 2.4.6
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/operations/put.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { BatchWriteItemCommandInput, BatchWriteItemCommandOutput,
|
|
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.
|
package/dist/operations/put.js
CHANGED
|
@@ -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
|
|
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
|
-
...
|
|
15
|
-
|
|
15
|
+
...otherArgs,
|
|
16
|
+
...(ReturnValues && ReturnValues !== "ALL_NEW" && { ReturnValues }),
|
|
17
|
+
TableName: otherArgs?.TableName || (0, lib_1.getDefaultTable)(),
|
|
16
18
|
}))
|
|
17
|
-
.then((res) =>
|
|
18
|
-
?
|
|
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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UpdateItemCommandInput, UpdateItemCommandOutput } from "@aws-sdk/client-dynamodb";
|
|
1
|
+
import { ReturnValue, UpdateItemCommandInput, UpdateItemCommandOutput } from "@aws-sdk/client-dynamodb";
|
|
2
2
|
import { DynamoDBItem } from "../types";
|
|
3
3
|
/**
|
|
4
4
|
* Updates an item in DynamoDB. All provided fields are overwritten.
|
|
@@ -32,10 +32,13 @@ import { DynamoDBItem } from "../types";
|
|
|
32
32
|
* console.log(newItem); // { "PK": "User/1", "SK": "Book/1", "released": 2000 }
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
ReturnValues:
|
|
38
|
-
}
|
|
35
|
+
type UpdateInputWithoutReturn = Partial<Omit<UpdateItemCommandInput, "ReturnValue">>;
|
|
36
|
+
type UpdateInputWithReturn = UpdateInputWithoutReturn & {
|
|
37
|
+
ReturnValues: ReturnValue;
|
|
38
|
+
};
|
|
39
|
+
export declare function updateItem<T extends DynamoDBItem = DynamoDBItem, D extends Partial<T> = Partial<T>>(key: Partial<T>, data: D, args?: never): Promise<undefined>;
|
|
40
|
+
export declare function updateItem<T extends DynamoDBItem = DynamoDBItem, K extends UpdateInputWithReturn = UpdateInputWithReturn, D extends Partial<T> = Partial<T>>(key: Partial<T>, data: D, args: K): Promise<T>;
|
|
41
|
+
export declare function updateItem<T extends DynamoDBItem = DynamoDBItem, K extends UpdateInputWithoutReturn = UpdateInputWithoutReturn, D extends Partial<T> = Partial<T>>(key: Partial<T>, data: D, args: K): Promise<undefined>;
|
|
39
42
|
/**
|
|
40
43
|
* Removes specified attributes from an item in DynamoDB.
|
|
41
44
|
*
|
|
@@ -51,3 +54,4 @@ export declare function updateItem<T extends DynamoDBItem, K extends Partial<Upd
|
|
|
51
54
|
* ```
|
|
52
55
|
*/
|
|
53
56
|
export declare function removeAttributes<T extends DynamoDBItem = DynamoDBItem>(key: Partial<T>, attributes: Array<keyof T>, args?: Partial<UpdateItemCommandInput>): Promise<UpdateItemCommandOutput>;
|
|
57
|
+
export {};
|
|
@@ -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
|
|
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 || "");
|