Skip to content

feat: accept Expression for v2 RTDB instance option#1869

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

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

Conversation

@IzaakGough

@IzaakGough IzaakGough commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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

@CorieW CorieW left a comment

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.

lgtm

@IzaakGough IzaakGough added this pull request to the merge queue Jun 25, 2026
@IzaakGough IzaakGough removed this pull request from the merge queue due to a manual request Jun 25, 2026
const event = raw as RawRTDBCloudEvent;
const instanceUrl = getInstance(event);
const params = makeParams(event, pathPattern, instancePattern) as unknown as ParamsOf<Ref>;
const resolvedInstancePattern = resolveInstancePattern(instancePattern);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

some duplication here, can we clean up

event,
pathPattern,
resolvedInstancePattern
) as unknown as ParamsOf<Ref>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this casting necessary - can we double check

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