Skip to content

Re-merge already-reviewed changes#1846

Merged
inlined merged 15 commits intomasterfrom
inlined.destructuring.base
Mar 20, 2026
Merged

Re-merge already-reviewed changes#1846
inlined merged 15 commits intomasterfrom
inlined.destructuring.base

Conversation

@inlined
Copy link
Member

@inlined inlined commented Mar 20, 2026

Accidentally forgot to set the base of the merge back to master after the inital PR

inlined and others added 13 commits March 19, 2026 12:45
* Add destructuring support for tasks

* Add destructuring support for tasks
* Add destructuring support for firestore

* Add destructuring support for pubsub

* Lint

* Initial pass for new webhook (#1836)

* Checkpoint. Need to ensure tests use real express and want to support Any decoding

* Ready for review

* Resore depency files

* PR feedback

* Rewriting error preambles

* test memoization

* Remove unnecessary casts or anys

* Format

* checkpoint

* Fix typing
* Add destructuring support for storage

* better typing and formatting
* Add destructuring support for scheduler

* PR feedback

* Format
* Add destructuring support for remoteConfig

* Format
* Add destructuring support for database

* DRY

* Remove unnecessary anys

* Format
@inlined inlined requested a review from shettyvarun268 March 20, 2026 17:18
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 significantly enhances the V1 compatibility layer within the v2 SDK by introducing a flexible and generic addV1Compat utility. This new mechanism allows for the consistent and idempotent injection of V1-style properties, such as context, message, change, snapshot, version, and object, into v2 CloudEvents across a wide range of Firebase and Google Cloud event providers. The changes aim to streamline the developer experience for those working with or migrating from V1 event structures, ensuring that essential V1 properties are readily accessible on v2 events through memoized getters. This refactoring also includes extensive test updates and type signature improvements to ensure robustness and clarity.

Highlights

  • Refactored V1 Compatibility Layer: Replaced the specific patchV1Compat function with a generic addV1Compat utility, which dynamically adds memoized V1-style getters to v2 CloudEvents.
  • Expanded V1 Compatibility: Integrated the new addV1Compat utility across various Firebase and Google Cloud providers (Realtime Database, Firestore, Pub/Sub, Remote Config, Scheduler, Storage, and Tasks) to expose V1-like context, message, change, snapshot, version, and object properties on v2 events.
  • Improved Test Coverage: Added comprehensive test cases for the new addV1Compat utility, verifying its idempotency, lazy evaluation, and memoization, along with new tests for V1 compatibility getters in each affected provider.
  • Enhanced Type Safety: Updated function signatures and types across providers to reflect the addition of V1Compat properties, improving type inference and developer experience.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

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
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 refactors the V1 compatibility patching mechanism by introducing a generic addV1Compat utility function that attaches V1-compatible properties (like context, message, snapshot, change, object, version) to V2 CloudEvent objects using lazy-evaluated, memoized getters. This new function replaces the previous patchV1Compat and is applied across various event providers including Pub/Sub, Realtime Database, Firestore, Remote Config, Storage, and Tasks, along with corresponding test updates. Review comments suggest improving error handling in Pub/Sub by using more specific error types and including event IDs, extracting duplicated context creation logic in Firestore into a shared function, clarifying the complex return type of addV1Compat with a comment, and consistently using addV1Compat for context properties in the Scheduler and Tasks providers to prevent serialization issues.

Comment on lines 221 to +223
): TaskQueueFunction<Args>;
export function onTaskDispatched<Args = any>(
optsOrHandler: TaskQueueOptions | ((request: Request<Args>) => void | Promise<void>),
handler?: (request: Request<Args>) => void | Promise<void>
optsOrHandler: TaskQueueOptions | ((request: any) => void | Promise<void>),
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Adding the context property directly to the arg object might cause unexpected behavior if the user tries to serialize the object. It's better to use Object.defineProperty to define a getter for the context property, which will prevent it from being serialized.

        Object.defineProperty(arg, "context", {
          get: () => context,
        });

Comment on lines +24 to +27
export function addV1Compat<T extends CloudEvent<unknown>, U extends Record<string, () => any>>(
event: T,
getters: U
): T & { [K in keyof U]: ReturnType<U[K]> } {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The return type T & { [K in keyof U]: ReturnType<U[K]> } is quite complex. Consider adding a comment to explain what this type represents, as it's not immediately obvious.

):
  T & { [K in keyof U]: ReturnType<U[K]> } /* Returns a new type by merging the properties of T and the return types of all getters in U */ {

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in comments

Comment on lines +209 to +211
Object.defineProperty(event, "context", {
get: () => v1Context,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider using addV1Compat to add the context property instead of directly defining it on the event object.

@inlined inlined marked this pull request as ready for review March 20, 2026 17:32
Copy link
Contributor

@shettyvarun268 shettyvarun268 left a comment

Choose a reason for hiding this comment

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

LGTM

@inlined inlined added this pull request to the merge queue Mar 20, 2026
Merged via the queue into master with commit bd97ef7 Mar 20, 2026
32 checks 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.

3 participants