Skip to content

Commit

Permalink
DataConnect + PGLite prototype. (#7615)
Browse files Browse the repository at this point in the history
* Hacking away at pglite+dataconnect emulator

* Hacking away at it

* More debugging

* I THINK IT WORKSSSSS

* Saving my progress at EoD

* --amend

* Progress

* clean up

* formatting

* Use extended query patch (thanks @gregnr!)

* Format and merge master

* PR fixes

* Remove JSON comments

* format

* Fxing test compilation issues

* Cleaning up build issues

* PR fixes

* Format and generate json schema

* Patching in missing types for VSCode builds

* More type fixing

* More type fixing

* Little bit mroe code review

* Removed unused dep

* More pr fixes

* test:emualtors build fixed

* PR fixes

* Fix port disagreement
  • Loading branch information
joehan committed Sep 11, 2024
1 parent 5f0f991 commit b8326ae
Show file tree
Hide file tree
Showing 41 changed files with 2,566 additions and 93 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ module.exports = {
// TODO(jamesdaniels): add this to overrides instead
ignorePatterns: [
"src/dynamicImport.js",
"src/emulator/dataconnect/pg-gateway",
"scripts/webframeworks-deploy-tests/nextjs/**",
"scripts/webframeworks-deploy-tests/angular/**",
"scripts/frameworks-tests/vite-project/**",
Expand Down
88 changes: 10 additions & 78 deletions firebase-vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion firebase-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
"@teamsupercell/typings-for-css-modules-loader": "^2.5.1",
"@types/glob": "^8.0.0",
"@types/mocha": "^10.0.1",
"@types/node": "16.x",
"@types/node": "20.x",
"@types/react": "^18.0.9",
"@types/react-dom": "^18.0.4",
"@types/vscode": "^1.69.0",
Expand Down
1 change: 1 addition & 0 deletions firebase-vscode/src/data-connect/toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class DataConnectToolkit implements vscode.Disposable {
config,
configDir,
rc: RC,
autoconnectToPostgres: false,
enable_output_generated_sdk: true,
enable_output_schema_extensions: true,
};
Expand Down
4 changes: 2 additions & 2 deletions firebase-vscode/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"typeRoots": ["node_modules/@types", "../src/types"],
"module": "es2020",
"moduleResolution": "node",
"target": "ES2020",
"target": "ES2017",
"outDir": "dist",
"lib": ["ES2020"],
"lib": ["ES2020", "DOM" ],
"jsx": "react",
"sourceMap": true,
"rootDirs": ["src", "../src", "common"],
Expand Down
11 changes: 11 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
]
},
"dependencies": {
"@electric-sql/pglite": "^0.2.0",
"@google-cloud/cloud-sql-connector": "^1.3.3",
"@google-cloud/pubsub": "^4.5.0",
"abort-controller": "^3.0.0",
Expand Down
6 changes: 6 additions & 0 deletions schema/firebase-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@
},
"port": {
"type": "number"
},
"postgresHost": {
"type": "string"
},
"postgresPort": {
"type": "number"
}
},
"type": "object"
Expand Down
6 changes: 4 additions & 2 deletions scripts/emulator-tests/tsconfig.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
},
"include": [
"../../src/**/*",
"*",
]
"../../src/*",
"./*",
],
"exclude": [],
}
2 changes: 1 addition & 1 deletion src/dataconnect/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface WebhookBody {
content?: string;
}

export const DEFAULT_PORT = "400322"; // 6 digit default used by vscode;
export const DEFAULT_PORT = "40000"; // 6 digit default used by vscode;

// If port in use, VSCode will pass a different port to the integrated term through env var
export const port = process.env.VSCODE_WEBHOOK_PORT || DEFAULT_PORT;
Expand Down
3 changes: 3 additions & 0 deletions src/emulator/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,9 @@ export async function startAll(
configDir,
rc: options.rc,
config: options.config,
autoconnectToPostgres: true,
postgresHost: options.config.get("emulators.dataconnect.postgresHost"),
postgresPort: options.config.get("emulators.dataconnect.postgresPort"),
enable_output_generated_sdk: true, // TODO: source from arguments
enable_output_schema_extensions: true,
});
Expand Down
6 changes: 6 additions & 0 deletions src/emulator/dataconnect/pg-gateway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The code in this directory is a very slightly modified version of https://github.com/supabase-community/pg-gateway/tree/next.
Full credit for this code goes to @gregnr and the other contributors on that repo.

Due to some known issues with how PGLite handles prepared statements, this versiom of pg-gateway includes middleware
to remove the extra Ready for Query messages that break schema migration. Once these underlying issues with PGLite are fixed,
we'll migrate to a normal dependency on pg-gateway.
34 changes: 34 additions & 0 deletions src/emulator/dataconnect/pg-gateway/auth/base-auth-flow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { BufferReader } from '../buffer-reader';
import type { BufferWriter } from '../buffer-writer';
import type { ConnectionSignal } from '../connection';
import type { ConnectionState } from '../connection.types';

type BufferSource = ArrayBufferView | ArrayBuffer;

export interface AuthFlow {
createInitialAuthMessage(): Uint8Array | undefined;
handleClientMessage(message: BufferSource): AsyncGenerator<Uint8Array | ConnectionSignal>;
isCompleted: boolean;
}

export abstract class BaseAuthFlow implements AuthFlow {
protected reader: BufferReader;
protected writer: BufferWriter;
protected connectionState: ConnectionState;

constructor(params: {
reader: BufferReader;
writer: BufferWriter;
connectionState: ConnectionState;
}) {
this.reader = params.reader;
this.writer = params.writer;
this.connectionState = params.connectionState;
}

abstract createInitialAuthMessage(): Uint8Array | undefined;
abstract handleClientMessage(
message: BufferSource,
): AsyncGenerator<Uint8Array | ConnectionSignal>;
abstract get isCompleted(): boolean;
}
Loading

0 comments on commit b8326ae

Please sign in to comment.