Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support firebase dataconnect:sdk:generate --watch #7719

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion src/commands/dataconnect-sdk-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { load } from "../dataconnect/load";
import { readFirebaseJson } from "../dataconnect/fileUtils";
import { logger } from "../logger";

type GenerateOptions = Options & { watch?: boolean };
Copy link
Contributor

@fredzqm fredzqm Sep 23, 2024

Choose a reason for hiding this comment

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

[Can be defered] [Not blocking PP, lower priority than compatible modes docs]

While we are at this. It would nice if sdk:generate also takes optional [serviceId] [connectorId] like other commands.

The rule of thumb from go/fdc:multi-data-source: if there are >1 services / connectors / datasource, it defaults to run the same routine against all relevant resources.

  dataconnect:services:list                                      list all deployed services in your Firebase 
                                                                 project
  dataconnect:sql:diff [serviceId]                               displays the differences between  a local 
                                                                 DataConnect schema and your CloudSQL database's 
                                                                 current schema
  dataconnect:sql:migrate [options] [serviceId]                  migrates your CloudSQL database's schema to 
                                                                 match your local DataConnect schema
  dataconnect:sql:grant [options] [serviceId]                    Grants the SQL role <role> to the provided user 
                                                                 or service account <email>.
  dataconnect:sdk:generate                                       generates typed SDKs for your Data Connect 
                                                                 connectors

Copy link
Member Author

Choose a reason for hiding this comment

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

Filed b/369400626 to update all commands per go/fdc:multi-data-source, as I believe right now an error is thrown in diff/migrate/grant if serviceId isn't specified and multiple services exist.


export const command = new Command("dataconnect:sdk:generate")
.description("generates typed SDKs for your Data Connect connectors")
.action(async (options: Options) => {
.action(async (options: GenerateOptions) => {
const projectId = needProjectId(options);

const services = readFirebaseJson(options.config);
Expand Down Expand Up @@ -39,6 +41,7 @@ export const command = new Command("dataconnect:sdk:generate")
const output = await DataConnectEmulator.generate({
configDir,
connectorId: conn.connectorYaml.connectorId,
watch: options.watch,
});
logger.info(output);
logger.info(`Generated SDKs for ${conn.connectorYaml.connectorId}`);
Expand Down
4 changes: 4 additions & 0 deletions src/emulator/dataconnectEmulator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as childProcess from "child_process";
import { EventEmitter } from "events";
const lsofi = require("lsofi");

Check warning on line 3 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 3 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Require statement not part of import statement

import { dataConnectLocalConnString } from "../api";
import { Constants } from "./constants";
Expand Down Expand Up @@ -35,6 +35,7 @@
export interface DataConnectGenerateArgs {
configDir: string;
connectorId: string;
watch?: boolean;
}

export interface DataConnectBuildArgs {
Expand All @@ -46,10 +47,10 @@

export class DataConnectEmulator implements EmulatorInstance {
private emulatorClient: DataConnectEmulatorClient;
private usingExistingEmulator: boolean = false;

Check warning on line 50 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Type boolean trivially inferred from a boolean literal, remove type annotation

constructor(private args: DataConnectEmulatorArgs) {
this.emulatorClient = new DataConnectEmulatorClient();

Check warning on line 53 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

'DataConnectEmulatorClient' was used before it was defined
}
private logger = EmulatorLogger.forEmulator(Emulators.DATACONNECT);

Expand All @@ -74,8 +75,8 @@
);
}
}
} catch (err: any) {

Check warning on line 78 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
this.logger.log("DEBUG", `'fdc build' failed with error: ${err.message}`);

Check warning on line 79 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression

Check warning on line 79 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .message on an `any` value
}

const info = await load(this.args.projectId, this.args.config, this.args.configDir);
Expand All @@ -100,10 +101,10 @@
} else {
const pgServer = new PostgresServer(dbId, "postgres");
if (this.args.postgresPort) {
const process = await lsofi(this.args.postgresPort);

Check warning on line 104 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 104 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value
if (process) {
const errMessage =
`Data Connect: Unable to start PGLite server on port ${this.args.postgresPort} because it is already in use by process number ${process}. This may occur if you are running another instance of Postgres.` +

Check warning on line 107 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression
` You can choose a different port by setting 'firebase.json#emulators.dataconnect.postgresPort', or you can unset that field to automatically find an open port.`;
throw new FirebaseError(errMessage);
}
Expand Down Expand Up @@ -184,6 +185,9 @@
`--config_dir=${args.configDir}`,
`--connector_id=${args.connectorId}`,
];
if (args.watch) {
cmd.push("--watch");
}
const res = childProcess.spawnSync(commandInfo.binary, cmd, { encoding: "utf-8" });

logger.info(res.stderr);
Expand Down
Loading