From 343f4acb2aa7c917e98d9d00aa54e37c9213571f Mon Sep 17 00:00:00 2001 From: Daniel Getu Date: Wed, 7 Sep 2022 17:27:21 +0000 Subject: [PATCH 1/5] Add overloads to `TableTransaction.updateEntity` --- .../data-tables/review/data-tables.api.md | 4 +- .../data-tables/src/TableTransaction.ts | 43 ++++++++++++++++++- .../test/internal/tableTransaction.spec.ts | 17 ++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/sdk/tables/data-tables/review/data-tables.api.md b/sdk/tables/data-tables/review/data-tables.api.md index 2e413c9eea8b..2ec9d245627d 100644 --- a/sdk/tables/data-tables/review/data-tables.api.md +++ b/sdk/tables/data-tables/review/data-tables.api.md @@ -416,7 +416,9 @@ export class TableTransaction { actions: TransactionAction[]; createEntity>(entity: TableEntity): void; deleteEntity(partitionKey: string, rowKey: string): void; - updateEntity>(entity: TableEntity, updateMode?: UpdateMode, updateOptions?: UpdateTableEntityOptions): void; + updateEntity>(entity: TableEntity, updateMode?: UpdateMode): void; + updateEntity>(entity: TableEntity, updateOptions?: UpdateTableEntityOptions): void; + updateEntity>(entity: TableEntity, updateMode: UpdateMode, updateOptions?: UpdateTableEntityOptions): void; upsertEntity>(entity: TableEntity, updateMode?: UpdateMode): void; } diff --git a/sdk/tables/data-tables/src/TableTransaction.ts b/sdk/tables/data-tables/src/TableTransaction.ts index d80c6b1d1ee6..b6280f201c20 100644 --- a/sdk/tables/data-tables/src/TableTransaction.ts +++ b/sdk/tables/data-tables/src/TableTransaction.ts @@ -73,6 +73,40 @@ export class TableTransaction { this.actions.push(["delete", { partitionKey, rowKey }]); } + /** + * Adds an update action to the transaction + * @param entity - entity to update + * @param updateMode - update mode + * @param updateOptions - options for the update operation + */ + updateEntity>( + entity: TableEntity, + updateMode?: UpdateMode + ): void; + + /** + * Adds an update action to the transaction + * @param entity - entity to update + * @param updateMode - update mode + * @param updateOptions - options for the update operation + */ + updateEntity>( + entity: TableEntity, + updateOptions?: UpdateTableEntityOptions + ): void; + + /** + * Adds an update action to the transaction + * @param entity - entity to update + * @param updateMode - update mode + * @param updateOptions - options for the update operation + */ + updateEntity>( + entity: TableEntity, + updateMode: UpdateMode, + updateOptions?: UpdateTableEntityOptions + ): void; + /** * Adds an update action to the transaction * @param entity - entity to update @@ -81,10 +115,15 @@ export class TableTransaction { */ updateEntity>( entity: TableEntity, - updateMode: UpdateMode = "Merge", + updateModeOrOptions: UpdateMode | UpdateTableEntityOptions | undefined, updateOptions?: UpdateTableEntityOptions ): void { - this.actions.push(["update", entity, updateMode, updateOptions]); + // UpdateMode is a string union + const realUpdateMode: UpdateMode | undefined = + typeof updateModeOrOptions === "string" ? updateModeOrOptions : undefined; + const realUpdateOptions: UpdateTableEntityOptions | undefined = + typeof updateModeOrOptions === "object" ? updateModeOrOptions : updateOptions; + this.actions.push(["update", entity, realUpdateMode ?? "Merge", realUpdateOptions ?? {}]); } /** diff --git a/sdk/tables/data-tables/test/internal/tableTransaction.spec.ts b/sdk/tables/data-tables/test/internal/tableTransaction.spec.ts index a17fbf733106..26e40e3e4c19 100644 --- a/sdk/tables/data-tables/test/internal/tableTransaction.spec.ts +++ b/sdk/tables/data-tables/test/internal/tableTransaction.spec.ts @@ -69,4 +69,21 @@ describe("TableTransaction", () => { assert.isTrue(isProxy); }); }); + + describe("updateEntity", () => { + it("should have ergonomic overloads", () => { + const transaction = new TableTransaction(); + const entity = { partitionKey: "1", rowKey: "1" }; + transaction.updateEntity(entity); + transaction.updateEntity(entity, "Replace"); + transaction.updateEntity(entity, { etag: "" }); + transaction.updateEntity(entity, "Merge", { etag: "" }); + assert.deepEqual(transaction.actions, [ + ["update", { partitionKey: "1", rowKey: "1" }, "Merge", {}], + ["update", { partitionKey: "1", rowKey: "1" }, "Replace", {}], + ["update", { partitionKey: "1", rowKey: "1" }, "Merge", { etag: "" }], + ["update", { partitionKey: "1", rowKey: "1" }, "Merge", { etag: "" }], + ]); + }); + }); }); From a898fdf494705a3c4cfae331dd753631f754cebf Mon Sep 17 00:00:00 2001 From: Daniel Getu Date: Wed, 7 Sep 2022 17:36:41 +0000 Subject: [PATCH 2/5] Log changes --- sdk/tables/data-tables/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/tables/data-tables/CHANGELOG.md b/sdk/tables/data-tables/CHANGELOG.md index 89714671970e..ecb059190f1b 100644 --- a/sdk/tables/data-tables/CHANGELOG.md +++ b/sdk/tables/data-tables/CHANGELOG.md @@ -10,6 +10,8 @@ ### Other Changes +- Add overloads to `TableTransaction.updateEntity` so `undefined` doesn't need to be passed explicitly for an optional argument. [#23132](https://github.com/Azure/azure-sdk-for-js/pull/23132) + ## 13.1.2 (2022-06-07) ### Features Added From e3484d7f81156a3608c93302cad3adfb93272baa Mon Sep 17 00:00:00 2001 From: Daniel Getu Date: Wed, 7 Sep 2022 17:39:22 +0000 Subject: [PATCH 3/5] Remove unnecessary overload --- sdk/tables/data-tables/src/TableTransaction.ts | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/sdk/tables/data-tables/src/TableTransaction.ts b/sdk/tables/data-tables/src/TableTransaction.ts index b6280f201c20..c338b2390ca4 100644 --- a/sdk/tables/data-tables/src/TableTransaction.ts +++ b/sdk/tables/data-tables/src/TableTransaction.ts @@ -76,18 +76,6 @@ export class TableTransaction { /** * Adds an update action to the transaction * @param entity - entity to update - * @param updateMode - update mode - * @param updateOptions - options for the update operation - */ - updateEntity>( - entity: TableEntity, - updateMode?: UpdateMode - ): void; - - /** - * Adds an update action to the transaction - * @param entity - entity to update - * @param updateMode - update mode * @param updateOptions - options for the update operation */ updateEntity>( @@ -110,8 +98,8 @@ export class TableTransaction { /** * Adds an update action to the transaction * @param entity - entity to update - * @param updateMode - update mode - * @param options - options for the update operation + * @param updateModeOrOptions - update mode or update options + * @param updateOptions - options for the update operation */ updateEntity>( entity: TableEntity, From c622da8fa4cc7438be47c219482a14f194242805 Mon Sep 17 00:00:00 2001 From: Daniel Getu Date: Wed, 7 Sep 2022 17:41:10 +0000 Subject: [PATCH 4/5] Edit changelog --- sdk/tables/data-tables/CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk/tables/data-tables/CHANGELOG.md b/sdk/tables/data-tables/CHANGELOG.md index 8ed46872ef82..bc3b30e153df 100644 --- a/sdk/tables/data-tables/CHANGELOG.md +++ b/sdk/tables/data-tables/CHANGELOG.md @@ -1,17 +1,16 @@ # Release History -## 13.2.0 (2022-09-06) +## 13.2.0 (2022-09-07) ### Features Added - Add option to `transaction.updateEntity()` [#22562](https://github.com/Azure/azure-sdk-for-js/pull/22562). (A community contribution, courtesy of _[tmcgannon](https://github.com/tmcgannon))_ + - Add overloads to `TableTransaction.updateEntity` so `undefined` doesn't need to be passed explicitly for an optional argument. [#23132](https://github.com/Azure/azure-sdk-for-js/pull/23132) ### Bugs Fixed - Fix encoding for Date objects when filtering on a DateTime field [#23058](https://github.com/Azure/azure-sdk-for-js/pull/23058) -- Add overloads to `TableTransaction.updateEntity` so `undefined` doesn't need to be passed explicitly for an optional argument. [#23132](https://github.com/Azure/azure-sdk-for-js/pull/23132) - ## 13.1.2 (2022-06-07) ### Features Added From 0eeb36790c33a05698f84c3fad6de54b84cb5f8e Mon Sep 17 00:00:00 2001 From: Daniel Getu Date: Wed, 7 Sep 2022 17:56:17 +0000 Subject: [PATCH 5/5] Update API documentation --- sdk/tables/data-tables/review/data-tables.api.md | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/tables/data-tables/review/data-tables.api.md b/sdk/tables/data-tables/review/data-tables.api.md index 2ec9d245627d..3276f7ffe268 100644 --- a/sdk/tables/data-tables/review/data-tables.api.md +++ b/sdk/tables/data-tables/review/data-tables.api.md @@ -416,7 +416,6 @@ export class TableTransaction { actions: TransactionAction[]; createEntity>(entity: TableEntity): void; deleteEntity(partitionKey: string, rowKey: string): void; - updateEntity>(entity: TableEntity, updateMode?: UpdateMode): void; updateEntity>(entity: TableEntity, updateOptions?: UpdateTableEntityOptions): void; updateEntity>(entity: TableEntity, updateMode: UpdateMode, updateOptions?: UpdateTableEntityOptions): void; upsertEntity>(entity: TableEntity, updateMode?: UpdateMode): void;