Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/init/features/dataconnect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@

// askQuestions prompts the user about the Data Connect service they want to init. Any prompting
// logic should live here, and _no_ actuation logic should live here.
export async function askQuestions(setup: Setup): Promise<void> {

Check warning on line 121 in src/init/features/dataconnect/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
const info: RequiredInfo = {
flow: "",
appDescription: "",
Expand Down Expand Up @@ -166,10 +166,10 @@

// actuate writes product specific files and makes product specifc API calls.
// It does not handle writing firebase.json and .firebaserc
export async function actuate(setup: Setup, config: Config, options: any): Promise<void> {

Check warning on line 169 in src/init/features/dataconnect/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 169 in src/init/features/dataconnect/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
// Most users will want to persist data between emulator runs, so set this to a reasonable default.
const dir: string = config.get("dataconnect.source", "dataconnect");

Check warning on line 171 in src/init/features/dataconnect/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
const dataDir = config.get("emulators.dataconnect.dataDir", `${dir}/.dataconnect/pgliteData`);

Check warning on line 172 in src/init/features/dataconnect/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
config.set("emulators.dataconnect.dataDir", dataDir);

const info = setup.featureInfo?.dataconnect;
Expand Down Expand Up @@ -211,7 +211,7 @@
setup.instructions.push(
`You can visualize the Data Connect Schema in Firebase Console:

https://console.firebase.google.com/project/${setup.projectId!}/dataconnect/locations/${info.locationId}/services/${info.serviceId}/schema`,

Check warning on line 214 in src/init/features/dataconnect/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
);
}
setup.instructions.push(
Expand All @@ -223,7 +223,7 @@
setup: Setup,
config: Config,
info: RequiredInfo,
options: any,

Check warning on line 226 in src/init/features/dataconnect/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
): Promise<void> {
const projectId = setup.projectId;
if (!projectId) {
Expand Down Expand Up @@ -328,7 +328,7 @@
{ schemaGql: schemaFiles, connectors: connectors, seedDataGql: seedDataGql },
options,
);
} catch (err: any) {

Check warning on line 331 in src/init/features/dataconnect/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
logLabeledError("dataconnect", `Operation Generation failed...`);
// GiF generate operation API has stability concerns.
// Fallback to save only the generated schema.
Expand Down Expand Up @@ -402,9 +402,9 @@
config: Config,
info: RequiredInfo,
serviceGql: ServiceGQL,
options: any,

Check warning on line 405 in src/init/features/dataconnect/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
): Promise<void> {
const dir: string = config.get("dataconnect.source") || "dataconnect";

Check warning on line 407 in src/init/features/dataconnect/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
const subbedDataconnectYaml = subDataconnectYamlValues(
{
...info,
Expand Down Expand Up @@ -703,12 +703,6 @@
"dataconnect",
"CloudSQL no cost trial has already been used on this project.",
);
if (!billingEnabled) {
setup.instructions.push(
upgradeInstructions(setup.projectId || "your-firebase-project", true),
);
return;
}
} else if (instrumentlessTrialEnabled || billingEnabled) {
logLabeledSuccess("dataconnect", "CloudSQL no cost trial available!");
}
Expand All @@ -729,7 +723,11 @@
if (freeTrialAvailable) {
choices.push({ name: "Create a new free trial instance", value: "", location: "" });
} else {
choices.push({ name: "Create a new CloudSQL instance", value: "", location: "" });
choices.push({
name: `Create a new CloudSQL instance${billingEnabled ? "" : " (requires billing account)"}`,
value: "",
location: "",
});
}
info.cloudSqlInstanceId = await select<string>({
message: `Which CloudSQL instance would you like to use?`,
Expand All @@ -741,6 +739,12 @@
info.locationId = choices.find((c) => c.value === info.cloudSqlInstanceId)!.location;
} else {
info.flow += "_pick_new_csql";
if (!billingEnabled && freeTrialUsed) {
setup.instructions.push(
upgradeInstructions(setup.projectId || "your-firebase-project", true),
);
Comment on lines +743 to +745
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The promptForCloudSQL function includes a guard at the beginning (if (!setup.projectId) { return; }), which ensures that setup.projectId is always defined at this point in the code. Consequently, the fallback to "your-firebase-project" is redundant.

Removing this fallback and relying on the established contract that setup.projectId exists will make the code cleaner and prevent the generation of a non-functional URL in the unlikely scenario that the initial guard is removed and setup.projectId is falsy.

Suggested change
setup.instructions.push(
upgradeInstructions(setup.projectId || "your-firebase-project", true),
);
setup.instructions.push(
upgradeInstructions(setup.projectId!, true),
);

return;
}
info.cloudSqlInstanceId = await input({
message: `What ID would you like to use for your new CloudSQL instance?`,
default: newUniqueId(
Expand Down
Loading