Skip to content

Commit

Permalink
Merge pull request #1424 from andrewda/fix-item-save-settings
Browse files Browse the repository at this point in the history
Fix return type of ItemSaveSettings
  • Loading branch information
fishcharlie committed Jul 2, 2022
2 parents 30c3b17 + 5381c41 commit 9bc54e1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/dynamoose/lib/Item.ts
Expand Up @@ -22,7 +22,7 @@ import CustomError from "./Error";

export interface ItemSaveSettings {
overwrite?: boolean;
return?: "request" | "Item";
return?: "request" | "item";
condition?: Condition;
}
export interface ItemSettings {
Expand Down
13 changes: 13 additions & 0 deletions packages/dynamoose/test/types/Item.ts
@@ -0,0 +1,13 @@
import {User, UserTypedModel} from "./Model";

const user = new User(UserTypedModel, {"id": "1", "name": "Jane", "age": 30});

const shouldPassSave = user.save();
const shouldPassSaveWithReturnRequest = user.save({"return": "request"});
const shouldPassSaveWithReturnItem = user.save({"return": "item"});
const shouldPassSaveCallback = user.save(() => {});
const shouldPassSaveWithReturnRequestCallback = user.save({"return": "request"}, () => {});
const shouldPassSaveWithReturnItemCallback = user.save({"return": "item"}, () => {});

// @ts-expect-error
const shouldFailWithInvalidReturnType = user.save({"return": "invalid-return-type"});
5 changes: 5 additions & 0 deletions packages/dynamoose/test/types/Model.ts
Expand Up @@ -22,6 +22,8 @@ const model = dynamoose.model("User", {"id": Number});
const shouldPassTableCreateRequest = model.table.create.request();

const shouldPassCreateWithNoReturnSetting = model.create({"id": 1}, {"overwrite": true});
const shouldPassCreateWithReturnRequest = model.create({"id": 1}, {"return": "request"});
const shouldPassCreateWithReturnItem = model.create({"id": 1}, {"return": "item"});
const shouldPassGetWithNoReturnSetting = model.get({"id": 1}, {"attributes": ["something"]});
const shouldPassDeleteWithNoReturnSetting = model.delete({"id": 1}, {"condition": new dynamoose.Condition("name").eq("Charlie")});
const shouldPassUpdateWithNoReturnSetting = model.update({"id": 1}, {"name": "Charlie"}, {"condition": new dynamoose.Condition("name").eq("Bob")});
Expand All @@ -45,6 +47,9 @@ const shouldPassGetWithNumberAsKey = model.get(1);
const shouldPassUpdateWithStringAsKey = model.update("id", {"value": "hello world"});
const shouldPassUpdateWithNumberAsKey = model.update(1, {"value": "hello world"});

// @ts-expect-error
const shouldFailWithInvalidReturnType = model.create({"id": 1}, {"return": "invalid-return-type"});

// @ts-expect-error
const shouldFailWithInvalidTransaction = model.transaction.notValid();

Expand Down

0 comments on commit 9bc54e1

Please sign in to comment.