Skip to content

feat: accept Expression for v2 RTDB instance option#1869

Open
IzaakGough wants to merge 7 commits into
masterfrom
@invertase/fix-rtdb-instance-params
Open

feat: accept Expression for v2 RTDB instance option#1869
IzaakGough wants to merge 7 commits into
masterfrom
@invertase/fix-rtdb-instance-params

Conversation

@IzaakGough
Copy link
Copy Markdown
Contributor

@IzaakGough IzaakGough commented Apr 9, 2026

Fixes #1613

Summary

Allow the v2 Realtime Database trigger instance option to accept a deploy-time param (Expression<string>), not just a plain string.
This lets functions target different RTDB instances per environment without triggering the deployment-time .value() warning.

Problem

ReferenceOptions.instance was typed and handled as a plain string.

Passing defineString('REALTIME_INSTANCE') for instance either failed type-checking or caused the SDK to eagerly resolve the param during deploy, which emitted the standard .value() deployment warning.

Solution

  • Widen ReferenceOptions.instance to string | Expression<string>.
  • Preserve expression-backed instances through endpoint generation instead of resolving them in getOpts().
  • Serialize expression-backed instances into the manifest as CEL expressions.
  • Resolve the expression only at runtime when the trigger needs to construct its path pattern and event params.

Testing

  • Added unit coverage for getOpts() preserving an Expression<string>.
  • Added endpoint/manifest coverage for expression-backed instance values.
  • Added a test that verifies no deployment-time warning is emitted when defining the trigger with a param-backed instance.
  • Added a runtime test confirming instance resolution and param extraction still work.

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 enhances Realtime Database (RTDB) ReferenceOptions to allow Expression<string> for the instance property, enabling dynamic resolution of instance names. The getOpts utility function has been updated to process these expressions, and a new test case validates this functionality. The review suggests improving the new test case by replacing magic strings with named constants for better readability and maintainability.

Comment thread spec/v2/providers/database.spec.ts Outdated
@IzaakGough IzaakGough marked this pull request as ready for review April 17, 2026 08:29
@IzaakGough IzaakGough requested a review from cabljac April 17, 2026 08:30
Comment thread src/v2/providers/database.ts Outdated
instance = referenceOrOpts.instance || "*";
instance =
referenceOrOpts.instance instanceof Expression
? referenceOrOpts.instance.value()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this not cause a warning log during deployment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes you're right, thanks for spotting this. I've changed the RTDB trigger path to preserve Expression through endpoint generation and only resolve it at runtime, so the warning no longer appears during deploy.

All tests pass and I did a manual deployment test with a dummy function, seems to work fine.

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.

Realtime instance can not be configured using params for onValueWritten functions

3 participants