Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Item batch operation method signature #23652

Merged
merged 7 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/review/cosmos.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ export class ItemResponse<T extends ItemDefinition> extends ResourceResponse<T &
// @public
export class Items {
constructor(container: Container, clientContext: ClientContext);
batch(operations: OperationInput[], partitionKey?: string, options?: RequestOptions): Promise<Response_2<any>>;
batch(operations: OperationInput[], partitionKey?: string, options?: RequestOptions): Promise<Response_2<OperationResponse[]>>;
bulk(operations: OperationInput[], bulkOptions?: BulkOptions, options?: RequestOptions): Promise<OperationResponse[]>;
changeFeed(partitionKey: string | number | boolean, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>;
changeFeed(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>;
Expand Down
4 changes: 2 additions & 2 deletions sdk/cosmosdb/cosmos/src/client/Item/Items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ export class Items {
operations: OperationInput[],
partitionKey: string = "[{}]",
options?: RequestOptions
): Promise<Response<any>> {
): Promise<Response<OperationResponse[]>> {
operations.map((operation) => decorateBatchOperation(operation, options));

const path = getPathFromLink(this.container.url, ResourceType.item);
Expand All @@ -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<OperationResponse[]> = await this.clientContext.batch({
body: operations,
partitionKey,
path,
Expand Down
19 changes: 18 additions & 1 deletion sdk/cosmosdb/cosmos/test/public/functional/item.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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 () {
Expand Down