Skip to content

Commit 3ee2f24

Browse files
committed
Adjust control flow with some placeholder TODOs.
1 parent ed6caa4 commit 3ee2f24

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

src/dataconnect/build.ts

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,48 @@ import * as experiments from "../experiments";
55
import { prettify } from "./graphqlError";
66
import { DeploymentMetadata } from "./types";
77

8-
export async function build(options: Options, configDir: string, dryRun?: boolean): Promise<DeploymentMetadata> {
9-
var args: {configDir: string, projectId?: string} = { configDir }
8+
export async function build(
9+
options: Options,
10+
configDir: string,
11+
dryRun?: boolean,
12+
): Promise<DeploymentMetadata> {
13+
const args: { configDir: string; projectId?: string } = { configDir };
1014
if (experiments.isEnabled("fdcconnectorevolution") && options.projectId) {
11-
process.env["DATA_CONNECT_PREVIEW"] = "conn_evolution"
12-
args.projectId = options.projectId
15+
process.env["DATA_CONNECT_PREVIEW"] = "conn_evolution";
16+
args.projectId = options.projectId;
1317
}
1418
const buildResult = await DataConnectEmulator.build(args);
1519
if (buildResult?.errors?.length) {
16-
if (buildResult.errors.filter(e => !e.warningLevel)) {
20+
if (buildResult.errors.filter((w) => !w.warningLevel).length) {
1721
// Throw immediately if there are any build errors in the GraphQL schema or connectors.
1822
throw new FirebaseError(
1923
`There are errors in your schema and connector files:\n${buildResult.errors.map(prettify).join("\n")}`,
2024
);
21-
} else {
22-
for (let e of buildResult.errors) {
23-
if (options.interactive) {
24-
if (dryRun || options.force) {
25-
// TODO: Log messages in output.
26-
} else {
27-
// TODO: Prompt messages and error if rejected.
28-
// Interactive default to accept, required default to reject.
29-
}
30-
} else if (options.nonInteractive) {
31-
}
25+
}
26+
const interactiveAcks = buildResult.errors.filter(
27+
(w) => w.warningLevel && w.warningLevel === "INTERACTIVE_ACK",
28+
);
29+
const requiredAcks = buildResult.errors.filter(
30+
(w) => w.warningLevel && w.warningLevel === "REQUIRE_ACK",
31+
);
32+
if (requiredAcks.length) {
33+
if (options.nonInteractive && !options.force) {
34+
throw new FirebaseError(
35+
`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")}`,
36+
);
37+
} else if (options.interactive && !options.force && !dryRun) {
38+
// TODO: Prompt message and error if rejected. Default to reject.
39+
} else {
40+
// TODO: Log messages in output.
41+
}
42+
}
43+
if (interactiveAcks.length) {
44+
if (options.interactive && !options.force && !dryRun) {
45+
// TODO: Prompt message and error if rejected. Default to accept.
46+
} else {
47+
// TODO: Log messages in output.
3248
}
3349
}
3450
}
3551
return buildResult?.metadata ?? {};
3652
}
37-
38-
async function prompt(options: Options): Promise<boolean> {
39-
return true;
40-
}

src/emulator/dataconnectEmulator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export class DataConnectEmulator implements EmulatorInstance {
243243
const commandInfo = await downloadIfNecessary(Emulators.DATACONNECT);
244244
const cmd = ["--logtostderr", "-v=2", "build", `--config_dir=${args.configDir}`];
245245
if (args.projectId) {
246-
cmd.push(`--project_id=${args.projectId}`)
246+
cmd.push(`--project_id=${args.projectId}`);
247247
}
248248

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

0 commit comments

Comments
 (0)