Skip to content

Commit

Permalink
Adjust control flow with some placeholder TODOs.
Browse files Browse the repository at this point in the history
  • Loading branch information
rosalyntan committed Dec 13, 2024
1 parent ed6caa4 commit 3ee2f24
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
52 changes: 32 additions & 20 deletions src/dataconnect/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,48 @@ import * as experiments from "../experiments";
import { prettify } from "./graphqlError";
import { DeploymentMetadata } from "./types";

export async function build(options: Options, configDir: string, dryRun?: boolean): Promise<DeploymentMetadata> {
var args: {configDir: string, projectId?: string} = { configDir }
export async function build(

Check warning on line 8 in src/dataconnect/build.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
options: Options,
configDir: string,
dryRun?: boolean,
): Promise<DeploymentMetadata> {
const args: { configDir: string; projectId?: string } = { configDir };
if (experiments.isEnabled("fdcconnectorevolution") && options.projectId) {
process.env["DATA_CONNECT_PREVIEW"] = "conn_evolution"
args.projectId = options.projectId
process.env["DATA_CONNECT_PREVIEW"] = "conn_evolution";
args.projectId = options.projectId;
}
const buildResult = await DataConnectEmulator.build(args);
if (buildResult?.errors?.length) {
if (buildResult.errors.filter(e => !e.warningLevel)) {
if (buildResult.errors.filter((w) => !w.warningLevel).length) {
// Throw immediately if there are any build errors in the GraphQL schema or connectors.
throw new FirebaseError(
`There are errors in your schema and connector files:\n${buildResult.errors.map(prettify).join("\n")}`,
);
} else {
for (let e of buildResult.errors) {
if (options.interactive) {
if (dryRun || options.force) {
// TODO: Log messages in output.
} else {
// TODO: Prompt messages and error if rejected.
// Interactive default to accept, required default to reject.
}
} else if (options.nonInteractive) {
}
}
const interactiveAcks = buildResult.errors.filter(
(w) => w.warningLevel && w.warningLevel === "INTERACTIVE_ACK",
);
const requiredAcks = buildResult.errors.filter(
(w) => w.warningLevel && w.warningLevel === "REQUIRE_ACK",
);
if (requiredAcks.length) {
if (options.nonInteractive && !options.force) {
throw new FirebaseError(
`There are changes in your schema or connectors that may break your existing applications. These changes require explicit acknowledgement to deploy:\n${requiredAcks.map(prettify).join("\n")}`,
);
} else if (options.interactive && !options.force && !dryRun) {
// TODO: Prompt message and error if rejected. Default to reject.
} else {
// TODO: Log messages in output.
}
}
if (interactiveAcks.length) {
if (options.interactive && !options.force && !dryRun) {
// TODO: Prompt message and error if rejected. Default to accept.
} else {
// TODO: Log messages in output.
}
}
}
return buildResult?.metadata ?? {};
}

async function prompt(options: Options): Promise<boolean> {
return true;
}
2 changes: 1 addition & 1 deletion src/emulator/dataconnectEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class DataConnectEmulator implements EmulatorInstance {
const commandInfo = await downloadIfNecessary(Emulators.DATACONNECT);
const cmd = ["--logtostderr", "-v=2", "build", `--config_dir=${args.configDir}`];
if (args.projectId) {
cmd.push(`--project_id=${args.projectId}`)
cmd.push(`--project_id=${args.projectId}`);
}

const res = childProcess.spawnSync(commandInfo.binary, cmd, { encoding: "utf-8" });
Expand Down

0 comments on commit 3ee2f24

Please sign in to comment.