/
update-item.ts
66 lines (62 loc) · 2.26 KB
/
update-item.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { JsonFormat } from "typesafe-dynamodb";
import { FormatObject } from "typesafe-dynamodb/lib/json-format";
import { TableKey } from "typesafe-dynamodb/lib/key";
import { Narrow } from "typesafe-dynamodb/lib/narrow";
import { DynamoDBAppsyncExpression } from "./appsync";
import { ReturnValues } from "./return-value";
import { AttributeKeyToObject } from "./util";
export type UpdateItemInput<
Item extends object,
PartitionKey extends keyof Item,
RangeKey extends keyof Item | undefined,
Key extends TableKey<Item, PartitionKey, RangeKey, Format>,
ReturnValue extends ReturnValues | undefined,
Format extends JsonFormat
> = Omit<
Format extends JsonFormat.Document
? AWS.DynamoDB.DocumentClient.UpdateItemInput
: AWS.DynamoDB.UpdateItemInput,
"TableName" | "Key"
> & {
Key: Key;
ReturnValues?: ReturnValue;
};
export interface UpdateItemOutput<
Item extends object,
PartitionKey extends keyof Item,
RangeKey extends keyof Item | undefined,
Key extends TableKey<Item, PartitionKey, RangeKey, Format>,
ReturnValue extends ReturnValues | undefined,
Format extends JsonFormat = JsonFormat.Document
> extends Omit<AWS.DynamoDB.DocumentClient.UpdateItemOutput, "TableName"> {
Attributes?: ReturnValue extends undefined | "NONE"
? undefined
: ReturnValue extends "ALL_OLD" | "ALL_NEW"
? FormatObject<Narrow<Item, Key, Format>, Format>
: Partial<FormatObject<Narrow<Item, Key, Format>, Format>>;
}
export type UpdateItem<
Item extends object,
PartitionKey extends keyof Item,
RangeKey extends keyof Item | undefined,
Format extends JsonFormat
> = <
Key extends TableKey<Item, PartitionKey, RangeKey, Format>,
Return extends ReturnValues | undefined = undefined
>(
input: UpdateItemInput<Item, PartitionKey, RangeKey, Key, Return, Format>
) => Promise<
UpdateItemOutput<Item, PartitionKey, RangeKey, Key, Return, Format>
>;
export type UpdateItemAppsync<
Item extends object,
PartitionKey extends keyof Item,
RangeKey extends keyof Item | undefined
> = <
Key extends TableKey<Item, PartitionKey, RangeKey, JsonFormat.AttributeValue>
>(input: {
key: Key;
update: DynamoDBAppsyncExpression;
condition?: DynamoDBAppsyncExpression;
_version?: number;
}) => Promise<Narrow<Item, AttributeKeyToObject<Key>, JsonFormat.Document>>;