Skip to content

Cosmos: public RID addressing API (ResourceId/ResourceIdentity) (3/3)#4687

Open
simorenoh wants to merge 2 commits into
simorenoh/cosmos-rid-slice2-resolutionfrom
simorenoh/cosmos-rid-slice3-sdk-api
Open

Cosmos: public RID addressing API (ResourceId/ResourceIdentity) (3/3)#4687
simorenoh wants to merge 2 commits into
simorenoh/cosmos-rid-slice2-resolutionfrom
simorenoh/cosmos-rid-slice3-sdk-api

Conversation

@simorenoh

@simorenoh simorenoh commented Jul 2, 2026

Copy link
Copy Markdown
Member

Slice 3 of 3 (stacked on PR #4663) for epic #4637.

This final slice adds the SDK-facing public API in azure_data_cosmos for addressing Cosmos databases and containers by name or RID. No driver changes — it builds on the driver surface landed in slices 1 and 2.

What's added

  • ResourceId / ResourceIdentity — new public types. ResourceId wraps a RID (Cow<'static, str>, const from_static, Display, AsRef, From<&str|String|&String>). ResourceIdentity is a #[non_exhaustive] enum (Name | Rid) with From conversions so a &str/String selects name addressing and a ResourceId selects RID addressing.
  • Name-or-RID clients — CosmosClient::database_client and DatabaseClient::container_client now take impl Into. DatabaseClient gains
    ame()/
    id(), and id() now returns &ResourceIdentity.
  • Addressing guards — RID-addressed containers resolve through the driver's
    esolve_container_by_rid with a parent-database cross-check (CLIENT_INVALID_RESOURCE_ID when the resolved container's parent DB doesn't match the addressed database). Mixing name and RID across the DB/container hierarchy is rejected with CLIENT_MIXED_NAME_RID_ADDRESSING.
  • Throughput fast path — RID-addressed throughput reads/replaces reuse the RID directly and skip the extra database read (shared
    esource_id() helper).

Testing

  • 6 new
    esource_identity unit tests (run in CI).
  • New emulator e2e test cosmos_rid_addressing.rs — compile-verified in CI; runs under the emulator.

Breaking changes

  • database_client/container_client take impl Into instead of &str (deref call sites need &*value/.as_ref()).
  • DatabaseClient::id() now returns &ResourceIdentity instead of &str.

Base is targeted at simorenoh/cosmos-rid-slice2-resolution so the diff is reviewable in isolation.

Add the SDK-facing name-or-RID addressing surface to azure_data_cosmos:

- New public ResourceId/ResourceIdentity types for addressing databases and containers by user name or by RID.

- CosmosClient::database_client and DatabaseClient::container_client now accept impl Into<ResourceIdentity>; DatabaseClient gains name()/rid() and id() now returns &ResourceIdentity.

- RID-addressed containers resolve via the driver's resolve_container_by_rid with a parent-database cross-check, and mixed name/RID addressing is rejected.

- RID-addressed throughput skips the extra database read by reusing a shared resource_id() helper.

- Add compile-verified emulator e2e test for RID addressing and fix breaking call sites.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simorenoh simorenoh requested a review from a team as a code owner July 2, 2026 16:50
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Cosmos The azure_cosmos crate

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant