feat: Rewrite and simplify the ResourceId API#9
Conversation
This change is a complete rewrite of the `ResourceId` implementation to simplify the API based on feedback from real-world usage. The core changes include: - **Simplified API**: The concept of an explicit `parent` has been removed. Hierarchical context is now captured implicitly in the `type` field, which includes the full path prefix (e.g., `books/123/pages`). - **Flexible Storage**: Database-specific serialization methods (`fromBigInt`, `asBigInt`, `fromValue`) have been removed. The API now exposes the raw `bytes` directly, allowing for more flexible storage strategies. - **Improved Generation**: The `generate` constructor has been simplified. It no longer requires a `resourceType` and defaults to a 15-byte random payload, making it easier to use out of the box. - **New `isValid()` method**: A new static method, `ResourceId.isValid()`, is introduced for validation without throwing exceptions. - **Correct Equality**: The `==` operator and `hashCode` are now implemented correctly based on the object's state for reliable use in collections. BREAKING CHANGE: This is a complete overhaul of the public API. - `ResourceId.generate` signature has changed. - `ResourceId.parse` now treats the entire path before the final segment as the `type`. - `parent`, `asBigInt`, `fromBigInt`, `fromBytes`, and `fromValue` have been removed.'
Summary of ChangesHello @mark-dropbear, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant rewrite of the Highlights
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 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 counter productive. 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a significant and well-executed rewrite of the ResourceId API. The simplification of the API by removing explicit parents and database-specific serialization methods makes it much cleaner and more flexible. The new isValid() method and correct implementation of equality are also great additions.
I've left a few comments with suggestions for improvement, mainly concerning API consistency in ResourceId and clarity in the example code. Overall, this is a fantastic improvement to the library.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This change is a complete rewrite of the
ResourceIdimplementation to simplify the API based on feedback from real-world usage.The core changes include:
parenthas been removed. Hierarchical context is now captured implicitly in thetypefield, which includes the full path prefix (e.g.,books/123/pages).fromBigInt,asBigInt,fromValue) have been removed. The API now exposes the rawbytesdirectly, allowing for more flexible storage strategies.generateconstructor has been simplified. It no longer requires aresourceTypeand defaults to a 15-byte random payload, making it easier to use out of the box.isValid()method: A new static method,ResourceId.isValid(), is introduced for validation without throwing exceptions.==operator andhashCodeare now implemented correctly based on the object's state for reliable use in collections.BREAKING CHANGE: This is a complete overhaul of the public API.
ResourceId.generatesignature has changed.ResourceId.parsenow treats the entire path before the final segment as thetype.parent,asBigInt,fromBigInt,fromBytes, andfromValuehave been removed.'