Skip to content

dataconnect(chore): Create AuthUid value class to add some type safety compared to raw strings#8198

Merged
dconeybe merged 6 commits into
mainfrom
dconeybe/dataconnect/AuthUidInlineClass
May 22, 2026
Merged

dataconnect(chore): Create AuthUid value class to add some type safety compared to raw strings#8198
dconeybe merged 6 commits into
mainfrom
dconeybe/dataconnect/AuthUidInlineClass

Conversation

@dconeybe
Copy link
Copy Markdown
Contributor

@dconeybe dconeybe commented May 21, 2026

This PR improves the internals of the data connect sdk by introducing a dedicated @JvmInline value class AuthUid inside DataConnectAuth to replace raw strings for representing Auth UIDs across the firebase-dataconnect module. This change enhances compile-time type safety throughout the module's core code—including authentication, GRPC network stream layers, SQLite offline cache persistence, and their associated testing suites.

This is an internal-only change with no customer-visible side effects.

Highlights

  • Core Type Safety Wrapper: Defined a type-safe wrapper @JvmInline value class AuthUid to encapsulate Auth UIDs instead of representing them as raw strings.
  • Network and RPC Layer Integration: Updated GRPC connection metadata, RPC handlers, and bidirectional streaming structures (DataConnectBidiConnectStream, DataConnectGrpcMetadata, and DataConnectGrpcRPCs) to strictly accept and propagate the new AuthUid wrapper type.
  • Database Caching Plumbing: Adjusted the SQLite offline cache persistence layer (DataConnectCacheDatabase) to use the type-safe AuthUid, extracting the raw string field dynamically for SQL bind parameters and query variables.
  • Test Utility & Assertion Refactoring: Migrated Kotest property testing random generators, JUnit unit assertions, custom print utilities, and test data structures (DataConnectAuthUnitTest, DataConnectCacheDatabaseUnitTest, KotestPrinters, and arbitrary generators) to utilize and validate AuthUid instances correctly.
Changelog
  • DataConnectAuth.kt
    • Defined the @JvmInline value class AuthUid wrapper class.
    • Modified GetAuthTokenResult to wrap the authUid field in the new AuthUid type.
    • Updated the GetTokenResult.getAuthUid() extension helper to return an optional AuthUid instead of a raw String?.
  • DataConnectBidiConnectStream.kt
    • Swapped type declarations of the GRPC bidirectional event channels and subscription state objects to accept and propagate the type-safe AuthUid? in place of String?.
  • DataConnectGrpcMetadata.kt
    • Refactored Metadata.toStructProto and StructProtoBuilder.putHeaders to accept AuthUid? and to extract the raw string representation for network header serialization.
  • DataConnectGrpcRPCs.kt
    • Updated the QueryCacheInfo structural cache, stream listeners, and internal logging formattings to handle the structured AuthUid wrapper class instead of raw strings.
  • DataConnectCacheDatabase.kt
    • Refactored database operations getOrInsertAuthUid, getQueryResult, and insertQueryResult to accept AuthUid instances, projecting the enclosed string values to SQLite database queries.
  • ProtoUtil.kt
    • Refactored StreamRequest.toCompactString and StreamRequest.toStructProto to use the wrapped AuthUid type signature.
  • DataConnectAuthUnitTest.kt
    • Adjusted the authentication fetch result assertions to match on AuthUid instances.
  • DataConnectCacheDatabaseUnitTest.kt
    • Ported cache database tests to construct and serialize mock AuthUid sample entities.
  • KotestPrinters.kt
    • Adjusted test custom StreamRequestProtoPrint output assertion helper to instantiate custom type-safe AuthUid mocks.
  • src/test/.../arbs.kt
    • Defined DataConnectArb.authUid arbitrary generator helper and adjusted the authTokenResult generator function to produce mock AuthUid objects instead of strings.
  • testutil/.../arbs.kt
    • Removed the obsolete alphanumeric raw string authUid generator extension.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

@dconeybe
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a type-safe AuthUid value class to replace raw String usage for authentication UIDs throughout the SDK, including gRPC metadata handling, SQLite caching, and bidirectional streams. The feedback provided suggests renaming the internal property of the AuthUid class to avoid repetitive accessors and using more idiomatic Kotlin null checks.

@dconeybe dconeybe merged commit 85ee4b4 into main May 22, 2026
52 checks passed
@dconeybe dconeybe deleted the dconeybe/dataconnect/AuthUidInlineClass branch May 22, 2026 14:48
@github-actions github-actions Bot mentioned this pull request May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants