dataconnect(chore): Create AuthUid value class to add some type safety compared to raw strings#8198
Conversation
Using Gemini Code AssistThe 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
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 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. |
📝 PRs merging into main branchOur 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. |
|
/gemini review |
There was a problem hiding this comment.
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.
…late authUid from sub claim`
This PR improves the internals of the data connect sdk by introducing a dedicated
@JvmInline value class AuthUidinsideDataConnectAuthto replace raw strings for representing Auth UIDs across thefirebase-dataconnectmodule. 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
@JvmInline value class AuthUidto encapsulate Auth UIDs instead of representing them as raw strings.DataConnectBidiConnectStream,DataConnectGrpcMetadata, andDataConnectGrpcRPCs) to strictly accept and propagate the newAuthUidwrapper type.DataConnectCacheDatabase) to use the type-safeAuthUid, extracting the raw string field dynamically for SQL bind parameters and query variables.DataConnectAuthUnitTest,DataConnectCacheDatabaseUnitTest,KotestPrinters, and arbitrary generators) to utilize and validateAuthUidinstances correctly.Changelog
@JvmInline value class AuthUidwrapper class.GetAuthTokenResultto wrap theauthUidfield in the newAuthUidtype.GetTokenResult.getAuthUid()extension helper to return an optionalAuthUidinstead of a rawString?.AuthUid?in place ofString?.Metadata.toStructProtoandStructProtoBuilder.putHeadersto acceptAuthUid?and to extract the raw string representation for network header serialization.QueryCacheInfostructural cache, stream listeners, and internal logging formattings to handle the structuredAuthUidwrapper class instead of raw strings.getOrInsertAuthUid,getQueryResult, andinsertQueryResultto acceptAuthUidinstances, projecting the enclosed string values to SQLite database queries.StreamRequest.toCompactStringandStreamRequest.toStructPrototo use the wrappedAuthUidtype signature.AuthUidinstances.AuthUidsample entities.StreamRequestProtoPrintoutput assertion helper to instantiate custom type-safeAuthUidmocks.DataConnectArb.authUidarbitrary generator helper and adjusted theauthTokenResultgenerator function to produce mockAuthUidobjects instead of strings.authUidgenerator extension.