Skip to content

feat: Rewrite and simplify the ResourceId API#9

Merged
mark-dropbear merged 4 commits into
mainfrom
rewrite
Jan 15, 2026
Merged

feat: Rewrite and simplify the ResourceId API#9
mark-dropbear merged 4 commits into
mainfrom
rewrite

Conversation

@mark-dropbear
Copy link
Copy Markdown
Contributor

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.'

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.'
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 ResourceId API, aiming to simplify its interface and enhance its flexibility based on practical usage feedback. The changes focus on making resource identifier management more intuitive by refining how hierarchical structures are represented, providing direct access to underlying byte data for storage, and improving the generation and validation processes. This refactoring results in a cleaner, more robust API for handling resource IDs.

Highlights

  • Simplified API: The explicit parent concept has been removed, with hierarchical context now implicitly captured within the type field, which includes the full path prefix (e.g., books/123/pages).
  • Flexible Storage: Database-specific serialization methods like fromBigInt, asBigInt, and fromValue have been removed. The API now directly exposes raw bytes, allowing for more adaptable storage strategies.
  • Improved Generation: The generate constructor has been streamlined, no longer requiring a resourceType and defaulting to a 15-byte random payload for easier out-of-the-box use.
  • New Validation Method: A static ResourceId.isValid() method has been introduced, providing a way to validate resource IDs without throwing exceptions.
  • Corrected Equality: The == operator and hashCode implementations have been updated to correctly reflect the object's state, ensuring reliable use in collections.
  • Breaking Changes: This update is a complete overhaul of the public API, including changes to ResourceId.generate's signature, how ResourceId.parse handles types, and the removal of parent, asBigInt, fromBigInt, fromBytes, and fromValue.
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 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 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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 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.

Comment thread example/resource_id_example.dart
Comment thread lib/src/resource_id.dart Outdated
Comment thread lib/src/resource_id.dart Outdated
mark-dropbear and others added 3 commits January 15, 2026 08:41
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@mark-dropbear mark-dropbear merged commit 0ace747 into main Jan 15, 2026
1 check passed
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.

1 participant