Skip to content

Add item replace and patch commands#71

Merged
mkrueger merged 6 commits intomainfrom
dev/mkrueger/update
May 4, 2026
Merged

Add item replace and patch commands#71
mkrueger merged 6 commits intomainfrom
dev/mkrueger/update

Conversation

@mkrueger
Copy link
Copy Markdown
Contributor

@mkrueger mkrueger commented May 4, 2026

Summary

  • Add replace for replacing existing Cosmos DB items from JSON argument or piped input, including array input and ETag support
  • Add patch for single-operation partial item updates with set, add, replace, remove, and incr
  • Add mkitem --force / --upsert behavior for create-or-replace workflows
  • Update localization, docs, and integration coverage for the new command surfaces

Validation

  • dotnet build CosmosDBShell/CosmosDBShell.csproj -nologo -p:BaseOutputPath=C:\work\CosmosDBShell\obj\agent-patch-replace-review-build\
  • dotnet test CosmosDBShell.Tests/CosmosDBShell.Tests.csproj -nologo -p:BaseOutputPath=C:\work\CosmosDBShell\obj\agent-patch-replace-review-build\ --filter "FullyQualifiedName~LocalizationKeyAuditTests|FullyQualifiedName~DataOperationTests|FullyQualifiedName~HelpCommandVerificationTests"
  • VS Code diagnostics clean for touched command, test, localization, and docs files

Fixes AzureCosmosDB/cosmosdb-shell-preview#27
Fixes AzureCosmosDB/cosmosdb-shell-preview#28

@mkrueger mkrueger requested review from a team and Copilot May 4, 2026 07:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the Cosmos DB shell’s data-mutation surface by adding item replacement and single-operation patch support, while also extending mkitem with upsert behavior. It fits into the CLI’s command layer by adding new item-level write workflows, corresponding localization/help text, documentation, and integration tests.

Changes:

  • Add a new replace command for full-document replacement, including piped/array JSON input and optional ETag handling.
  • Add a new patch command for single Cosmos patch operations (set, add, replace, remove, incr).
  • Extend mkitem with --force / --upsert, and update docs/localization/tests for the new command surfaces.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
docs/commands.md Documents updated mkitem usage and adds reference docs for replace and patch.
CosmosDBShell/lang/en.ftl Adds help text, success strings, and error messages for the new/updated commands.
CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ReplaceCommand.cs Implements full-item replacement logic, including array handling and ETag support.
CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/PatchCommand.cs Implements single-operation patch execution and client-side value parsing/validation.
CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/MakeItemCommand.cs Adds --force/--upsert behavior by switching item creation to upsert when requested.
CosmosDBShell.Tests/Integration/DataOperationTests.cs Adds integration coverage for new replace/patch flows and mkitem --force.

Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/PatchCommand.cs
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ReplaceCommand.cs Outdated
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/PatchCommand.cs Outdated
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ReplaceCommand.cs Outdated
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ReplaceCommand.cs Outdated
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ReplaceCommand.cs
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/MakeItemCommand.cs Outdated
@mkrueger mkrueger requested a review from sevoku May 4, 2026 08:19
Copilot AI review requested due to automatic review settings May 4, 2026 08:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Comment thread docs/commands.md
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CosmosCommand.cs Outdated
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CosmosCommand.cs
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/MakeItemCommand.cs
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/CreateCommand.cs
- Docs: README's feature list and docs/navigation.md's pipe-aware
  command table now mention replace and patch.
- HPK numeric components no longer truncate via GetDouble(); use
  TryGetInt64 first so 64-bit integer keys above 2^53 are preserved.
- CreatePartitionKeyFromArgument now treats '{...}' as JSON too and
  throws JsonException for object-shaped roots so the patch command
  surfaces the localized invalid_pk_json error instead of falling
  through to a string PartitionKey with the raw text.
- mkitem array mode (force and non-force) now throws CommandException
  after the printed summary when failCount > 0, so scripted callers
  do not treat partial/total bulk failures as success.
- create database/container with --force/--upsert is now rejected with
  command-create-error-force_only_for_items instead of silently
  ignoring the flag.
@mkrueger mkrueger enabled auto-merge May 4, 2026 09:22
# Conflicts:
#	CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/MakeContainerCommand.cs
Copilot AI review requested due to automatic review settings May 4, 2026 11:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CosmosCommand.cs Outdated
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/PatchCommand.cs
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/CreateCommand.cs
CreatePartitionKeyFromArgument falls back to string PartitionKey for ambiguous scalar literals (e.g. 001, -svc) so existing string keys stay targetable; objects/arrays/quoted strings still surface JsonException.

PatchCommand remove rejects any supplied value including empty string.

Added unit tests for create container/database with --force.
@mkrueger mkrueger merged commit a466b6d into main May 4, 2026
8 checks passed
@mkrueger mkrueger deleted the dev/mkrueger/update branch May 4, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Add patch command for partial item updates Feature Request: Add upsertitem command for insert-or-update operations

3 participants