Skip to content

Commit

Permalink
fix when set to NONE
Browse files Browse the repository at this point in the history
  • Loading branch information
sasumaki committed Jun 6, 2024
1 parent efe9e98 commit bd2c659
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 22 deletions.
12 changes: 10 additions & 2 deletions src/queryBuilders/deleteItemQueryBuilder.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe("DeleteItemQueryBuilder", () => {

expect(res).toBeDefined();
});
it("doesn't return values if no returnValues is specified", async () => {
it("doesn't return values if no returnValues is specified or its set to NONE", async () => {
await tsynamoClient
.putItem("myTable")
.item({
Expand All @@ -101,8 +101,16 @@ describe("DeleteItemQueryBuilder", () => {
.execute();

expectTypeOf(res).toBeNever();

expect(res).toBeUndefined();

const res2 = await tsynamoClient
.deleteItem("myTable")
.keys({ userId: "1", dataTimestamp: 2 })
.returnValues("NONE")
.execute();

expectTypeOf(res2).toBeNever();
expect(res2).toBeUndefined();
});
it("does return values if returnValues is specified", async () => {
await tsynamoClient
Expand Down
42 changes: 29 additions & 13 deletions src/queryBuilders/deleteItemQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,21 @@ export interface DeleteItemQueryBuilderInterface<
...args: BuilderExprArg<DDB, Table, Key>
): DeleteItemQueryBuilder<DDB, Table, O>;

returnValues(
option: Extract<ReturnValuesOptions, "NONE" | "ALL_OLD">
): DeleteItemQueryBuilder<DDB, Table, ExecuteOutput<DDB[Table]>>;

returnValuesOnConditionCheckFailure(
option: Extract<ReturnValuesOptions, "NONE" | "ALL_OLD">
): DeleteItemQueryBuilder<DDB, Table, ExecuteOutput<DDB[Table]>>;
returnValues<Choice extends "NONE" | "ALL_OLD">(
option: Extract<ReturnValuesOptions, Choice>
): DeleteItemQueryBuilder<
DDB,
Table,
"NONE" extends Choice ? O : ExecuteOutput<DDB[Table]>
>;

returnValuesOnConditionCheckFailure<Choice extends "NONE" | "ALL_OLD">(
option: Extract<ReturnValuesOptions, Choice>
): DeleteItemQueryBuilder<
DDB,
Table,
"NONE" extends Choice ? O : ExecuteOutput<DDB[Table]>
>;

keys<Keys extends PickPk<DDB[Table]> & PickSkRequired<DDB[Table]>>(
pk: Keys
Expand Down Expand Up @@ -148,9 +156,13 @@ export class DeleteItemQueryBuilder<DDB, Table extends keyof DDB, O>
});
}

returnValues(
option: Extract<ReturnValuesOptions, "NONE" | "ALL_OLD">
): DeleteItemQueryBuilder<DDB, Table, ExecuteOutput<DDB[Table]>> {
returnValues<Choice extends "NONE" | "ALL_OLD">(
option: Extract<ReturnValuesOptions, Choice>
): DeleteItemQueryBuilder<
DDB,
Table,
"NONE" extends Choice ? O : ExecuteOutput<DDB[Table]>
> {
return new DeleteItemQueryBuilder({
...this.#props,
node: {
Expand All @@ -163,9 +175,13 @@ export class DeleteItemQueryBuilder<DDB, Table extends keyof DDB, O>
});
}

returnValuesOnConditionCheckFailure(
option: Extract<ReturnValuesOptions, "NONE" | "ALL_OLD">
): DeleteItemQueryBuilder<DDB, Table, ExecuteOutput<DDB[Table]>> {
returnValuesOnConditionCheckFailure<Choice extends "NONE" | "ALL_OLD">(
option: Extract<ReturnValuesOptions, Choice>
): DeleteItemQueryBuilder<
DDB,
Table,
"NONE" extends Choice ? O : ExecuteOutput<DDB[Table]>
> {
return new DeleteItemQueryBuilder({
...this.#props,
node: {
Expand Down
11 changes: 10 additions & 1 deletion src/queryBuilders/putItemQueryBuilder.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,23 @@ describe("PutItemQueryBuilder", () => {
expect(result).toEqual(itemToPut);
});

it("doesnt return values without returnValues", async () => {
it("doesnt return values without returnValues or when its set to NONE", async () => {
let result = await tsynamoClient
.putItem("myTable")
.item(itemToPut)
.execute();

expectTypeOf(result).toBeNever();
expect(result).toBeUndefined();

let result2 = await tsynamoClient
.putItem("myTable")
.item(itemToPut)
.returnValues("NONE")
.execute();

expectTypeOf(result2).toBeNever();
expect(result2).toBeUndefined();
});

it("handles ReturnValues option", async () => {
Expand Down
20 changes: 14 additions & 6 deletions src/queryBuilders/putItemQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ export interface PutItemQueryBuilderInterface<DDB, Table extends keyof DDB, O> {
...args: BuilderExprArg<DDB, Table, Key>
): PutItemQueryBuilder<DDB, Table, O>;

returnValues(
option: Extract<ReturnValuesOptions, "NONE" | "ALL_OLD">
): PutItemQueryBuilder<DDB, Table, ExecuteOutput<DDB[Table]>>;
returnValues<Choice extends "NONE" | "ALL_OLD">(
option: Extract<ReturnValuesOptions, Choice>
): PutItemQueryBuilder<
DDB,
Table,
"NONE" extends Choice ? O : ExecuteOutput<DDB[Table]>
>;

item<Item extends ExecuteOutput<DDB[Table]>>(
item: Item
Expand Down Expand Up @@ -147,9 +151,13 @@ export class PutItemQueryBuilder<DDB, Table extends keyof DDB, O>
});
}

returnValues(
option: Extract<ReturnValuesOptions, "NONE" | "ALL_OLD">
): PutItemQueryBuilder<DDB, Table, ExecuteOutput<DDB[Table]>> {
returnValues<Choice extends "NONE" | "ALL_OLD">(
option: Extract<ReturnValuesOptions, Choice>
): PutItemQueryBuilder<
DDB,
Table,
"NONE" extends Choice ? O : ExecuteOutput<DDB[Table]>
> {
return new PutItemQueryBuilder({
...this.#props,
node: {
Expand Down

0 comments on commit bd2c659

Please sign in to comment.