Skip to content

Commit

Permalink
fix: deleteItem signature should accept Key instead of Item (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
sam authored Feb 9, 2022
1 parent 7be12fa commit e49962d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ export interface TypeSafeDynamoDB<
>;

deleteItem<
Key extends KeyAttribute<Item, PartitionKey, RangeKey>,
ConditionExpression extends string | undefined,
ReturnValue extends DynamoDB.ReturnValue = "NONE"
>(
params: DeleteItemInput<Item, ConditionExpression, ReturnValue>,
params: DeleteItemInput<
Item,
PartitionKey,
RangeKey,
Key,
ConditionExpression,
ReturnValue
>,
callback?: Callback<DeleteItemOutput<Item, ReturnValue>, AWSError>
): Request<DeleteItemOutput<Item, ReturnValue>, AWSError>;

Expand Down
6 changes: 5 additions & 1 deletion src/delete-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import {
ExpressionAttributeNames,
ExpressionAttributeValues,
} from "./expression-attributes";
import { KeyAttribute } from "./key";

export type DeleteItemInput<
Item extends object,
PartitionKey extends keyof Item,
RangeKey extends keyof Item | undefined,
Key extends KeyAttribute<Item, PartitionKey, RangeKey>,
ConditionExpression extends string | undefined,
ReturnValue extends DynamoDB.ReturnValue = "NONE"
> = Omit<
Expand All @@ -19,7 +23,7 @@ export type DeleteItemInput<
> &
ExpressionAttributeNames<ConditionExpression> &
ExpressionAttributeValues<ConditionExpression> & {
Item: ToAttributeMap<Item>;
Key: Key;
ReturnValues?: ReturnValue;
ConditionExpression?: ConditionExpression;
};
Expand Down
14 changes: 14 additions & 0 deletions test/dummy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ export async function foo() {
})
.promise();

await table
.deleteItem({
TableName: "",
Key: {
pk: {
S: "",
},
sk: {
S: "",
},
},
})
.promise();

await table
.putItem({
TableName: "",
Expand Down

0 comments on commit e49962d

Please sign in to comment.