Skip to content

Adds missing Params support in v1 configurability#1820

Open
inlined wants to merge 4 commits intomasterfrom
inlined.v1-params
Open

Adds missing Params support in v1 configurability#1820
inlined wants to merge 4 commits intomasterfrom
inlined.v1-params

Conversation

@inlined
Copy link
Member

@inlined inlined commented Mar 3, 2026

Requires adding support for new features such as string interpolation (API propsoal oustanding) and value-only transforms (API proposal not outstanding beause the API is not publicly released)

Customers can now say cool things like:

import * as functions from "firebase-functions/v1";
import { onSchedule } from "firebase-functions/scheduler"

const topic = defineString("TOPIC");
const period = defineNumber("HOW_OFTEN");

export const pubSubSample = functions.pubsub.topic(topic).onPublish(() => undefined);
export const scheduleSample = onSchedule(expr`every ${period} days`, () => undefined);

For other language implications, see proposal.

Requires adding support for new features such as string interpolation (API propsoal oustanding) and value-only transforms (API proposal not outstanding beause the API is not publicly released)
@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 configurability of Firebase Functions v1 by introducing support for dynamic parameter values. It enables developers to use string interpolation and value-only transformations within function definitions, leading to more flexible and reusable function configurations across different services.

Highlights

  • Enhanced Parameter Support: Introduced new capabilities for handling parameters in Firebase Functions v1, specifically enabling string interpolation and value-only transformations.
  • New expr Template Tag: Added an expr template tag that allows for string interpolation within parameter expressions, making it possible to embed dynamic values directly into resource paths and schedules.
  • New transform Function: Implemented a transform function to apply custom transformations to string literals or existing string expressions, providing more flexibility in parameter manipulation.
  • Provider Integration: Updated various Firebase Functions v1 providers (Analytics, Database, Firestore, PubSub, Storage) to accept Expression<string> types for trigger resources and schedule configurations, allowing dynamic parameter usage in these contexts.

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

Changelog
  • spec/params/params.spec.ts
    • Imported transform function for testing.
    • Added new test suites for the expr template tag, covering various interpolation scenarios.
    • Added new test suite for the transform function, testing both string literals and expressions.
  • src/params/index.ts
    • Exported InterpolationExpression from ./types.
    • Added a new expr function that acts as a template tag for creating InterpolationExpression instances.
  • src/params/types.ts
    • Defined InterpolationExpression class to handle string interpolation with template literals.
    • Defined TransformedStringExpression class to apply custom transformations to string values or expressions.
    • Introduced celOf function to retrieve the CEL representation of an argument, similar to valueOf.
    • Added transform function to create TransformedStringExpression instances.
  • src/v1/cloud-functions.ts
    • Imported celOf, valueOf, and Expression from ../params/types.
    • Updated MakeCloudFunctionArgs interface to allow triggerResource to return string | Expression<string>.
    • Modified makeCloudFunction to use celOf when setting the resource for event triggers and schedule triggers.
    • Added logic to convert scheduleTrigger.timeZone to its CEL representation if it's an Expression.
    • Updated _makeParams function to accept triggerResourceGetter that can return string | Expression<string>.
    • Applied valueOf to the result of triggerResourceGetter in _makeParams to get the runtime string value.
  • src/v1/function-configuration.ts
    • Updated the Schedule interface to allow schedule and timeZone properties to accept Expression<string> in addition to string or ResetValue.
  • src/v1/providers/analytics.ts
    • Imported Expression from ../../params/types and expr from ../../params.
    • Modified event and _eventWithOptions functions to accept analyticsEventType as string | Expression<string>.
    • Updated the triggerResource getter in _eventWithOptions to use the new expr template tag for constructing the resource path.
    • Updated AnalyticsEventBuilder constructor to accept triggerResource that can return string | Expression<string>.
  • src/v1/providers/database.ts
    • Imported Expression and transform from ../../params/types and expr from ../../params.
    • Modified instance and ref functions to accept instance and path as string | Expression<string>.
    • Updated _instanceWithOptions and _refWithOptions to handle instance and path as string | Expression<string>.
    • Used transform for normalizePath and expr for constructing resource paths in InstanceBuilder and _refWithOptions.
    • Updated InstanceBuilder and RefBuilder constructors to accept triggerResource that can return string | Expression<string>.
    • Corrected error message string concatenation.
  • src/v1/providers/firestore.ts
    • Imported Expression from ../../params/types and expr from ../../params.
    • Removed posix import as it's no longer directly used for path joining.
    • Modified document, namespace, database, _databaseWithOptions, _namespaceWithOptions, _documentWithOptions functions to accept string | Expression<string> for their respective parameters.
    • Updated DatabaseBuilder and NamespaceBuilder constructors to handle string | Expression<string> for database and namespace.
    • Refactored NamespaceBuilder's document method to use the expr template tag for constructing the trigger resource path, supporting dynamic namespaces and paths.
    • Updated DocumentBuilder constructor to accept triggerResource that can return string | Expression<string>.
  • src/v1/providers/pubsub.ts
    • Imported Expression from ../../params/types and expr from ../../params.
    • Modified topic and schedule functions to accept string | Expression<string> for their parameters.
    • Updated _topicWithOptions to handle topic as string | Expression<string>, including a type check for topic name validation.
    • Updated _topicWithOptions to use the expr template tag for constructing the topic resource path.
    • Updated _scheduleWithOptions to handle schedule as string | Expression<string> and to store its CEL representation in options.schedule.
    • Updated TopicBuilder and ScheduleBuilder constructors to accept triggerResource that can return string | Expression<string>.
  • src/v1/providers/storage.ts
    • Imported Expression from ../../params/types and expr from ../../params.
    • Modified bucket function to accept an optional bucket parameter as string | Expression<string>.
    • Updated _bucketWithOptions to handle bucket as string | Expression<string>, including a type check for bucket name validation.
    • Updated _bucketWithOptions to use the expr template tag for constructing the bucket resource path.
    • Updated BucketBuilder and ObjectBuilder constructors to accept triggerResource that can return string | Expression<string>.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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 adds significant configurability to v1 functions by introducing support for Expression types in trigger definitions, including a new expr template literal for string interpolation and a transform function for runtime value manipulation. The changes are extensive and well-applied across different providers. I've identified one high-severity issue in TransformedStringExpression that could lead to invalid CEL generation, and I've provided a suggestion to fix it. Overall, this is a great enhancement.

}

toString(): string {
return this.source instanceof Expression ? this.source.toCEL() : this.transformer(this.source);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The toString() implementation for TransformedStringExpression can lead to invalid CEL generation when used inside other expressions.

  1. When source is an Expression, toString() incorrectly returns this.source.toCEL(), which includes {{...}}. This causes nested braces (e.g., {{ {{...}} }}) when the TransformedStringExpression is part of another expression.
  2. When source is a string, toString() returns the transformed string without quotes. This will be treated as an identifier instead of a string literal in the generated CEL.

The toString() method should return the unwrapped CEL for expressions and a properly quoted string for literals. A test case that would have caught this is:

it("handles transformed expressions inside other expressions", () => {
  const p = params.defineString("P");
  const t = transform(p, (s) => s.toUpperCase());
  const b = params.defineBoolean("B");
  expect(b.thenElse(t, "foo").toCEL()).to.equal('{{ params.B ? params.P : "foo" }}');
});
Suggested change
return this.source instanceof Expression ? this.source.toCEL() : this.transformer(this.source);
return this.source instanceof Expression ? this.source.toString() : JSON.stringify(this.transformer(this.source));

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.

1 participant