Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Removed MCP tools and prompts that required Gemini in Firebase terms of service.
- Fixes an issue where the `--only` flag was not always respected for `firebase mcp`
- Removed timeout when connecting to Cloud SQL. Hopefully, should mitigate issue #9314. (#9725)
- Added `firebase dataconnect:compile` command.
81 changes: 81 additions & 0 deletions src/commands/dataconnect-compile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import * as clc from "colorette";

import { Command } from "../command";
import { Options } from "../options";
import { DataConnectEmulator } from "../emulator/dataconnectEmulator";
import { getProjectId } from "../projectUtils";
import { pickServices } from "../dataconnect/load";
import { getProjectDefaultAccount } from "../auth";
import { logLabeledSuccess } from "../utils";
import { EmulatorHub } from "../emulator/hub";
import { handleBuildErrors } from "../dataconnect/build";
import { FirebaseError } from "../error";

type CompileOptions = Options & { service?: string; location?: string };

export const command = new Command("dataconnect:compile")
.description("compile your Data Connect schema and connector config and GQL files.")
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 command's description is slightly incomplete. In addition to compiling schema and connector files, the command also generates typed SDKs via DataConnectEmulator.generate. To avoid user surprise and accurately reflect the command's full functionality, I recommend updating the description.

Suggested change
.description("compile your Data Connect schema and connector config and GQL files.")
.description("compile your Data Connect schema and connector config, generate GQL files, and generate typed SDKs.")

.option(
"--service <serviceId>",
"the serviceId of the Data Connect service. If not provided, compiles all services.",
)
.option(
"--location <location>",
"the location of the Data Connect service. Only needed if service ID is used in multiple locations.",
)
.action(async (options: CompileOptions) => {
const projectId = getProjectId(options);

const config = options.config;
if (!config || !config.has("dataconnect")) {
throw new FirebaseError(
`No Data Connect project directory found. Please run ${clc.bold("firebase init dataconnect")} to set it up first.`,
);
}

const serviceInfos = await pickServices(
projectId || EmulatorHub.MISSING_PROJECT_PLACEHOLDER,
config,
options.service,
options.location,
);

if (!serviceInfos.length) {
throw new FirebaseError("No Data Connect services found to compile.");
}

for (const serviceInfo of serviceInfos) {
const configDir = serviceInfo.sourceDirectory;
const account = getProjectDefaultAccount(options.projectRoot);

// 1. Build (Validate Schema/Connectors + Generate .dataconnect)
const buildArgs = {
configDir,
projectId, // Optional, passes to fdc build --project_id if present
account,
};

const buildResult = await DataConnectEmulator.build(buildArgs);

if (buildResult?.errors?.length) {
await handleBuildErrors(
buildResult.errors,
options.nonInteractive,
options.force,
!!options.dryRun,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For clarity and to avoid potential confusion, it's better to pass false directly for the dryRun parameter, as this command doesn't support a --dry-run option. Using !!options.dryRun could be misleading for future maintenance, as it implies that dryRun might be a valid property on the options object.

Suggested change
!!options.dryRun,
false,

);
}

// 2. Generate SDKs
// api-proposal says: "Generates or updates the local .dataconnect/ metadata folder and generated SDKs"
await DataConnectEmulator.generate({
configDir,
account,
});

logLabeledSuccess(
"dataconnect",
`Successfully compiled Data Connect service: ${clc.bold(serviceInfo.dataConnectYaml.serviceId)}`,
);
}
});
1 change: 1 addition & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { CLIClient } from "../command";
import * as experiments from "../experiments";

type CommandRunner = ((...args: any[]) => Promise<any>) & { load: () => void };

Check warning on line 4 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 4 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

/**
* Loads all commands for our parser.
*/
export function load(client: CLIClient): CLIClient {
function loadCommand(name: string): CommandRunner {
const load = () => {

Check warning on line 11 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function
const { command: cmd } = require(`./${name}`);

Check warning on line 12 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Require statement not part of import statement

Check warning on line 12 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
cmd.register(client);

Check warning on line 13 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value

Check warning on line 13 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .register on an `any` value
return cmd.runner();

Check warning on line 14 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value

Check warning on line 14 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .runner on an `any` value

Check warning on line 14 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe return of an `any` typed value
};

const runner = (async (...args: any[]) => {
Expand Down Expand Up @@ -254,6 +254,7 @@
client.dataconnect.sql.migrate = loadCommand("dataconnect-sql-migrate");
client.dataconnect.sql.grant = loadCommand("dataconnect-sql-grant");
client.dataconnect.sql.shell = loadCommand("dataconnect-sql-shell");
client.dataconnect.compile = loadCommand("dataconnect-compile");
client.dataconnect.sdk = {};
client.dataconnect.sdk.generate = loadCommand("dataconnect-sdk-generate");
client.target = loadCommand("target");
Expand Down
Loading