From a16eb2eb33357a62e8a0e85612cdd0f509923832 Mon Sep 17 00:00:00 2001 From: joehan Date: Wed, 15 Jan 2025 13:54:22 -0800 Subject: [PATCH] Suggest DNS friendly service ids (#8118) --- CHANGELOG.md | 1 + src/init/features/dataconnect/index.spec.ts | 37 ++++++++++++++++++++- src/init/features/dataconnect/index.ts | 21 +++++++++++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6669dc6f1f3..3f1f30c550b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,3 @@ - Updated `cross-env` and `cross-spawn` dependencies to avoid vulnerable versions. (#7979) - Fixed an issue with the Data Connect emulator where `dataDir` and `--export` were relative to the current directory insead of `firebase.json`. +- `init dataconnect` now suggests DNS compatible service IDs. diff --git a/src/init/features/dataconnect/index.spec.ts b/src/init/features/dataconnect/index.spec.ts index c221868fdc7..4b75846a75c 100644 --- a/src/init/features/dataconnect/index.spec.ts +++ b/src/init/features/dataconnect/index.spec.ts @@ -54,7 +54,7 @@ describe("init dataconnect", () => { expectEnsureSchemaGQL: false, }, { - desc: "exiting project should use existing directory", + desc: "existing project should use existing directory", requiredInfo: mockRequiredInfo(), config: mockConfig({ dataconnect: { source: "not-dataconnect" } }), expectedSource: "not-dataconnect", @@ -161,6 +161,41 @@ describe("init dataconnect", () => { }); } }); + + describe("toDNSCompatibleId", () => { + const cases: { description: string; input: string; expected: string }[] = [ + { + description: "Should noop compatible strings", + input: "this-is-compatible", + expected: "this-is-compatible", + }, + { + description: "Should lower case", + input: "This-Is-Compatible", + expected: "this-is-compatible", + }, + { + description: "Should strip special characters", + input: "this-is-compatible?~!@#$%^&*()_+=", + expected: "this-is-compatible", + }, + { + description: "Should strip trailing and leading -", + input: "---this-is-compatible---", + expected: "this-is-compatible", + }, + { + description: "Should cut to 63 characters", + input: "a".repeat(1000), + expected: "a".repeat(63), + }, + ]; + for (const c of cases) { + it(c.description, () => { + expect(init.toDNSCompatibleId(c.input)).to.equal(c.expected); + }); + } + }); }); function mockConfig(data: Record = {}): Config { diff --git a/src/init/features/dataconnect/index.ts b/src/init/features/dataconnect/index.ts index 0b8550de500..c2357560fbf 100644 --- a/src/init/features/dataconnect/index.ts +++ b/src/init/features/dataconnect/index.ts @@ -141,7 +141,9 @@ async function askQuestions(setup: Setup, isBillingEnabled: boolean): Promise