diff --git a/sdk/cosmosdb/cosmos/review/cosmos.api.md b/sdk/cosmosdb/cosmos/review/cosmos.api.md index 6bb1e40c20d9..289d3102c25f 100644 --- a/sdk/cosmosdb/cosmos/review/cosmos.api.md +++ b/sdk/cosmosdb/cosmos/review/cosmos.api.md @@ -896,7 +896,7 @@ export class ItemResponse extends ResourceResponse>; + batch(operations: OperationInput[], partitionKey?: string, options?: RequestOptions): Promise>; bulk(operations: OperationInput[], bulkOptions?: BulkOptions, options?: RequestOptions): Promise; changeFeed(partitionKey: string | number | boolean, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator; changeFeed(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator; diff --git a/sdk/cosmosdb/cosmos/src/client/Item/Items.ts b/sdk/cosmosdb/cosmos/src/client/Item/Items.ts index 9f3b9502e28a..371e40f7a8e1 100644 --- a/sdk/cosmosdb/cosmos/src/client/Item/Items.ts +++ b/sdk/cosmosdb/cosmos/src/client/Item/Items.ts @@ -501,7 +501,7 @@ export class Items { operations: OperationInput[], partitionKey: string = "[{}]", options?: RequestOptions - ): Promise> { + ): Promise> { operations.map((operation) => decorateBatchOperation(operation, options)); const path = getPathFromLink(this.container.url, ResourceType.item); @@ -510,7 +510,7 @@ export class Items { throw new Error("Cannot run batch request with more than 100 operations per partition"); } try { - const response = await this.clientContext.batch({ + const response: Response = await this.clientContext.batch({ body: operations, partitionKey, path, diff --git a/sdk/cosmosdb/cosmos/test/public/functional/item.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/item.spec.ts index cfc1674f9182..c9c0a4884ea5 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/item.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/item.spec.ts @@ -2,7 +2,13 @@ // Licensed under the MIT license. import assert from "assert"; import { Suite } from "mocha"; -import { Container, CosmosClient, PatchOperation, PatchOperationType } from "../../../src"; +import { + Container, + CosmosClient, + OperationResponse, + PatchOperation, + PatchOperationType, +} from "../../../src"; import { ItemDefinition } from "../../../src"; import { bulkDeleteItems, @@ -688,6 +694,7 @@ describe("bulk/batch item operations", function () { ]; const response = await container.items.batch(operations, "A"); + assert(isOperationResponse(response.result[0])); assert.strictEqual(response.result[0].statusCode, 201); assert.strictEqual(response.result[1].statusCode, 201); assert.strictEqual(response.result[2].statusCode, 200); @@ -711,7 +718,17 @@ describe("bulk/batch item operations", function () { assert.strictEqual(deleteResponse.result[1].statusCode, 404); const { resource: readItem } = await container.item(otherItemId).read(); assert.strictEqual(readItem, undefined); + assert(isOperationResponse(deleteResponse.result[0])); }); + + function isOperationResponse(object: unknown): object is OperationResponse { + return ( + typeof object === "object" && + object !== null && + Object.prototype.hasOwnProperty.call(object, "statusCode") && + Object.prototype.hasOwnProperty.call(object, "requestCharge") + ); + } }); }); describe("patch operations", function () {