feat: accept Expression for v2 RTDB instance option#1869
Conversation
There was a problem hiding this comment.
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.
…ams' into @invertase/fix-rtdb-instance-params
| instance = referenceOrOpts.instance || "*"; | ||
| instance = | ||
| referenceOrOpts.instance instanceof Expression | ||
| ? referenceOrOpts.instance.value() |
There was a problem hiding this comment.
Does this not cause a warning log during deployment?
There was a problem hiding this comment.
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.
Fixes #1613
Summary
Allow the v2 Realtime Database trigger
instanceoption 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.instancewas typed and handled as a plainstring.Passing
defineString('REALTIME_INSTANCE')forinstanceeither failed type-checking or caused the SDK to eagerly resolve the param during deploy, which emitted the standard.value()deployment warning.Solution
ReferenceOptions.instancetostring | Expression<string>.getOpts().Testing
getOpts()preserving anExpression<string>.instancevalues.