From 46c3ffa9fabb8d0955d470bb764ab32aa28ddcea Mon Sep 17 00:00:00 2001 From: IzaakGough Date: Thu, 9 Apr 2026 15:25:45 +0100 Subject: [PATCH 1/3] feat: accept Expression for v2 RTDB instance option --- spec/v2/providers/database.spec.ts | 16 ++++++++++++++++ src/v2/providers/database.ts | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/spec/v2/providers/database.spec.ts b/spec/v2/providers/database.spec.ts index 4435faeea..ae7e7b880 100644 --- a/spec/v2/providers/database.spec.ts +++ b/spec/v2/providers/database.spec.ts @@ -26,6 +26,7 @@ import * as database from "../../../src/v2/providers/database"; import { expectType } from "../../common/metaprogramming"; import { MINIMAL_V2_ENDPOINT } from "../../fixtures"; import { CloudEvent, onInit } from "../../../src/v2/core"; +import * as params from "../../../src/params"; const RAW_RTDB_EVENT: database.RawRTDBCloudEvent = { data: { @@ -146,6 +147,21 @@ describe("database", () => { }, }); }); + + it("should resolve instance Expression to runtime string", () => { + const name = "TEST_RTDB_INSTANCE_FOR_GETOPTS"; + const prev = process.env[name]; + process.env[name] = "resolved-instance"; + try { + const p = params.defineString(name); + expect( + database.getOpts({ ref: "/foo", instance: p }) + ).to.deep.include({ path: "foo", instance: "resolved-instance" }); + } finally { + if (prev === undefined) delete process.env[name]; + else process.env[name] = prev; + } + }); }); describe("makeEndpoint", () => { diff --git a/src/v2/providers/database.ts b/src/v2/providers/database.ts index 6c5f5e83c..010c531ba 100644 --- a/src/v2/providers/database.ts +++ b/src/v2/providers/database.ts @@ -117,7 +117,7 @@ export interface ReferenceOptions extends options.E * Examples: 'my-instance-1', 'my-instance-*' * Note: The capture syntax cannot be used for 'instance'. */ - instance?: string; + instance?: string | Expression; /** * If true, do not deploy or emulate this function. @@ -488,7 +488,7 @@ export function getOpts(referenceOrOpts: string | ReferenceOptions) { opts = {}; } else { path = normalizePath(referenceOrOpts.ref); - instance = referenceOrOpts.instance || "*"; + instance = referenceOrOpts.instance instanceof Expression ? referenceOrOpts.instance.value() : (referenceOrOpts.instance || '*'); opts = { ...referenceOrOpts }; delete (opts as any).ref; delete (opts as any).instance; From 821943423662bb3f63119444343f0e6cbd2b15cb Mon Sep 17 00:00:00 2001 From: IzaakGough Date: Thu, 9 Apr 2026 17:11:58 +0100 Subject: [PATCH 2/3] style: fix lint --- spec/v2/providers/database.spec.ts | 7 ++++--- src/v2/providers/database.ts | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/spec/v2/providers/database.spec.ts b/spec/v2/providers/database.spec.ts index ae7e7b880..79ff3ddab 100644 --- a/spec/v2/providers/database.spec.ts +++ b/spec/v2/providers/database.spec.ts @@ -154,9 +154,10 @@ describe("database", () => { process.env[name] = "resolved-instance"; try { const p = params.defineString(name); - expect( - database.getOpts({ ref: "/foo", instance: p }) - ).to.deep.include({ path: "foo", instance: "resolved-instance" }); + expect(database.getOpts({ ref: "/foo", instance: p })).to.deep.include({ + path: "foo", + instance: "resolved-instance", + }); } finally { if (prev === undefined) delete process.env[name]; else process.env[name] = prev; diff --git a/src/v2/providers/database.ts b/src/v2/providers/database.ts index 010c531ba..16b3b0dc0 100644 --- a/src/v2/providers/database.ts +++ b/src/v2/providers/database.ts @@ -488,7 +488,10 @@ export function getOpts(referenceOrOpts: string | ReferenceOptions) { opts = {}; } else { path = normalizePath(referenceOrOpts.ref); - instance = referenceOrOpts.instance instanceof Expression ? referenceOrOpts.instance.value() : (referenceOrOpts.instance || '*'); + instance = + referenceOrOpts.instance instanceof Expression + ? referenceOrOpts.instance.value() + : referenceOrOpts.instance || "*"; opts = { ...referenceOrOpts }; delete (opts as any).ref; delete (opts as any).instance; From 4542780db972e70e5f27e1e5605b1c6cdef69475 Mon Sep 17 00:00:00 2001 From: Izaak Gough Date: Thu, 23 Apr 2026 10:09:08 +0100 Subject: [PATCH 3/3] test: replace getOpts magic string with name constants --- spec/v2/providers/database.spec.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/spec/v2/providers/database.spec.ts b/spec/v2/providers/database.spec.ts index 79ff3ddab..9d87bed70 100644 --- a/spec/v2/providers/database.spec.ts +++ b/spec/v2/providers/database.spec.ts @@ -47,6 +47,9 @@ const RAW_RTDB_EVENT: database.RawRTDBCloudEvent = { authtype: "unauthenticated", }; +const TEST_RTDB_INSTANCE_ENV_VAR = "TEST_RTDB_INSTANCE_FOR_GETOPTS"; +const RESOLVED_RTDB_INSTANCE = "resolved-instance"; + describe("database", () => { describe("makeParams", () => { it("should make params with basic path", () => { @@ -149,18 +152,17 @@ describe("database", () => { }); it("should resolve instance Expression to runtime string", () => { - const name = "TEST_RTDB_INSTANCE_FOR_GETOPTS"; - const prev = process.env[name]; - process.env[name] = "resolved-instance"; + const prev = process.env[TEST_RTDB_INSTANCE_ENV_VAR]; + process.env[TEST_RTDB_INSTANCE_ENV_VAR] = RESOLVED_RTDB_INSTANCE; try { - const p = params.defineString(name); + const p = params.defineString(TEST_RTDB_INSTANCE_ENV_VAR); expect(database.getOpts({ ref: "/foo", instance: p })).to.deep.include({ path: "foo", - instance: "resolved-instance", + instance: RESOLVED_RTDB_INSTANCE, }); } finally { - if (prev === undefined) delete process.env[name]; - else process.env[name] = prev; + if (prev === undefined) delete process.env[TEST_RTDB_INSTANCE_ENV_VAR]; + else process.env[TEST_RTDB_INSTANCE_ENV_VAR] = prev; } }); });