Skip to content

feat: accept Expression for v2 RTDB instance option#1869

Open
IzaakGough wants to merge 6 commits intomasterfrom
@invertase/fix-rtdb-instance-params
Open

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

Conversation

@IzaakGough
Copy link
Copy Markdown

Summary

Allows the v2 Realtime Database trigger instance option to be a deploy-time param (Expression<string>), not only a plain string, so functions can target different RTDB instances per environment without TypeScript rejecting valid code.

Fixes #1613

Problem

#1613 reports that ReferenceOptions.instance was typed as string only. Using defineString('REALTIME_INSTANCE') (or similar) for instance failed at compile time, even though multi-environment setups need different instance IDs (e.g. staging vs production).

Solution

  • Widen ReferenceOptions.instance to string | Expression<string>.
  • In getOpts, when instance is an Expression, resolve it with .value() so the runtime/trigger options get the resolved string (same pattern as other param-backed options elsewhere in the SDK).

Testing

  • Added a unit test that defines a string param backed by process.env, passes it as instance, and asserts getOpts includes the resolved instance string.

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

2 participants