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

Cleaning up some leftovers from #7836 #7982

Merged
merged 6 commits into from
Nov 21, 2024
Merged
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
8 changes: 0 additions & 8 deletions firebase-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,6 @@
}
}
},
"keybindings": [
{
"command": "firebase.dataConnect.executeOperationAtCursor",
"key": "ctrl+enter",
"mac": "cmd+enter",
"when": "editorLangId == gql || editorLangId == graphql"
}
],
"viewsContainers": {
"activitybar": [
{
Expand Down
23 changes: 12 additions & 11 deletions src/emulator/dataconnect/pgliteServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// They are only available as ESM, and if we import them normally,
// our tsconfig will convert them to requires, which will cause errors
// during module resolution.
const { dynamicImport } = require(true && "../../dynamicImport");

Check warning on line 8 in src/emulator/dataconnect/pgliteServer.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 8 in src/emulator/dataconnect/pgliteServer.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Require statement not part of import statement
import * as net from "node:net";
import * as fs from "fs";

Expand All @@ -17,6 +17,17 @@
} from "./pg-gateway/index";
import { fromNodeSocket } from "./pg-gateway/platforms/node";
import { logger } from "../../logger";
export const TRUNCATE_TABLES_SQL = `
DO $do$
BEGIN
EXECUTE
(SELECT 'TRUNCATE TABLE ' || string_agg(oid::regclass::text, ', ') || ' CASCADE'
FROM pg_class
WHERE relkind = 'r'
AND relnamespace = 'public'::regnamespace
);
END
$do$;`;

export class PostgresServer {
private username: string;
Expand All @@ -25,10 +36,10 @@
private importPath?: string;

public db: PGlite | undefined = undefined;
public async createPGServer(host: string = "127.0.0.1", port: number): Promise<net.Server> {

Check warning on line 39 in src/emulator/dataconnect/pgliteServer.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Type string trivially inferred from a string literal, remove type annotation
const getDb = this.getDb.bind(this);

const server = net.createServer(async (socket) => {

Check warning on line 42 in src/emulator/dataconnect/pgliteServer.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promise returned in function argument where a void return was expected
const connection: PostgresConnection = await fromNodeSocket(socket, {
serverVersion: "16.3 (PGlite 0.2.0)",
auth: { method: "trust" },
Expand All @@ -42,11 +53,11 @@
const result = await db.execProtocolRaw(data);
// Extended query patch removes the extra Ready for Query messages that
// pglite wrongly sends.
return extendedQueryPatch.filterResponse(data, result);

Check warning on line 56 in src/emulator/dataconnect/pgliteServer.ts

View workflow job for this annotation

GitHub Actions / lint (20)

'extendedQueryPatch' was used before it was defined
},
});

const extendedQueryPatch: PGliteExtendedQueryPatch = new PGliteExtendedQueryPatch(connection);

Check warning on line 60 in src/emulator/dataconnect/pgliteServer.ts

View workflow job for this annotation

GitHub Actions / lint (20)

'PGliteExtendedQueryPatch' was used before it was defined

socket.on("end", () => {
logger.debug("Postgres client disconnected");
Expand All @@ -69,8 +80,8 @@
if (!this.db) {
// Not all schemas will need vector installed, but we don't have an good way
// to swap extensions after starting PGLite, so we always include it.
const vector = (await dynamicImport("@electric-sql/pglite/vector")).vector;

Check warning on line 83 in src/emulator/dataconnect/pgliteServer.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 83 in src/emulator/dataconnect/pgliteServer.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .vector on an `any` value

Check warning on line 83 in src/emulator/dataconnect/pgliteServer.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value
const uuidOssp = (await dynamicImport("@electric-sql/pglite/contrib/uuid_ossp")).uuid_ossp;

Check warning on line 84 in src/emulator/dataconnect/pgliteServer.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
const pgliteArgs: PGliteOptions = {
username: this.username,
database: this.database,
Expand All @@ -95,17 +106,7 @@

public async clearDb(): Promise<void> {
const db = await this.getDb();
await db.query(`
DO $do$
BEGIN
EXECUTE
(SELECT 'TRUNCATE TABLE ' || string_agg(oid::regclass::text, ', ') || ' CASCADE'
FROM pg_class
WHERE relkind = 'r'
AND relnamespace = 'public'::regnamespace
);
END
$do$;`);
await db.query(TRUNCATE_TABLES_SQL);
}

public async exportData(exportPath: string): Promise<void> {
Expand Down
7 changes: 6 additions & 1 deletion src/emulator/dataconnectEmulator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as childProcess from "child_process";
import * as pg from "pg";
import { EventEmitter } from "events";
import * as clc from "colorette";
import * as path from "path";
Expand All @@ -17,7 +18,7 @@ import { EmulatorRegistry } from "./registry";
import { logger } from "../logger";
import { load } from "../dataconnect/load";
import { Config } from "../config";
import { PostgresServer } from "./dataconnect/pgliteServer";
import { PostgresServer, TRUNCATE_TABLES_SQL } from "./dataconnect/pgliteServer";
import { cleanShutdown } from "./controller";
import { connectableHostname } from "../utils";

Expand Down Expand Up @@ -180,6 +181,10 @@ export class DataConnectEmulator implements EmulatorInstance {
async clearData(): Promise<void> {
if (this.postgresServer) {
await this.postgresServer.clearDb();
} else {
const conn = new pg.Client(dataConnectLocalConnString());
joehan marked this conversation as resolved.
Show resolved Hide resolved
await conn.query(TRUNCATE_TABLES_SQL);
await conn.end();
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/emulator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ export const DOWNLOADABLE_EMULATORS = [
Emulators.DATACONNECT,
];

export type ImportExportEmulators = Emulators.FIRESTORE | Emulators.DATABASE | Emulators.AUTH;
export type ImportExportEmulators =
| Emulators.FIRESTORE
| Emulators.DATABASE
| Emulators.AUTH
| Emulators.STORAGE
| Emulators.DATACONNECT;
export const IMPORT_EXPORT_EMULATORS = [
Emulators.FIRESTORE,
Emulators.DATABASE,
Expand Down
Loading