From 7b6248de90af55775bed1a3251db790dcb72c589 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Fri, 13 Sep 2024 15:57:23 -0600 Subject: [PATCH 1/3] docs: fix missing async in createServer callback --- README.md | 8 ++++---- examples/pglite-auth/cert.ts | 10 +++++----- examples/pglite-auth/md5.ts | 4 ++-- examples/pglite-auth/password.ts | 4 ++-- examples/pglite-auth/scram-sha-256.ts | 4 ++-- examples/pglite-auth/trust.ts | 4 ++-- examples/pglite-multiple/index.ts | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index cdd9394..72b09b6 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ import { once } from 'node:events'; import { fromNodeSocket } from 'pg-gateway/node'; // Create a TCP server and listen for connections -const server = createServer((socket) => { +const server = createServer(async (socket) => { // Returns a `PostgresConnection` which manages the protocol lifecycle const connection = await fromNodeSocket(socket); }); @@ -458,10 +458,10 @@ With `pg-gateway`, we can serve PGlite over TCP by handling the startup/auth our ```typescript import { PGlite } from '@electric-sql/pglite'; -import net from 'node:net'; +import { createServer } from 'node:net'; import { fromNodeSocket } from 'pg-gateway/node'; -const server = net.createServer((socket) => { +const server = createServer(async (socket) => { // Each connection gets a fresh PGlite database, // since PGlite runs in single-user mode // (alternatively you could queue connections) @@ -548,7 +548,7 @@ async function getServerById(id: string) { }; } -const server = createServer((socket) => { +const server = createServer(async (socket) => { const connection = await fromNodeSocket(socket, { tls, // This hook occurs before startup messages are received from the client, diff --git a/examples/pglite-auth/cert.ts b/examples/pglite-auth/cert.ts index 5f810a4..db1f414 100644 --- a/examples/pglite-auth/cert.ts +++ b/examples/pglite-auth/cert.ts @@ -1,16 +1,16 @@ import { PGlite } from '@electric-sql/pglite'; -import fs from 'node:fs'; -import net from 'node:net'; +import { readFile } from 'node:fs/promises'; +import { createServer } from 'node:net'; import { fromNodeSocket } from 'pg-gateway/node'; const db = new PGlite(); -const server = net.createServer(async (socket) => { +const server = createServer(async (socket) => { const connection = await fromNodeSocket(socket, { serverVersion: '16.3 (PGlite 0.2.0)', tls: { - key: fs.readFileSync('key.pem'), - cert: fs.readFileSync('cert.pem'), + key: await readFile('key.pem'), + cert: await readFile('cert.pem'), }, auth: { method: 'cert', diff --git a/examples/pglite-auth/md5.ts b/examples/pglite-auth/md5.ts index dfbdf60..7224553 100644 --- a/examples/pglite-auth/md5.ts +++ b/examples/pglite-auth/md5.ts @@ -1,11 +1,11 @@ import { PGlite } from '@electric-sql/pglite'; -import net from 'node:net'; +import { createServer } from 'node:net'; import { createPreHashedPassword } from 'pg-gateway'; import { fromNodeSocket } from 'pg-gateway/node'; const db = new PGlite(); -const server = net.createServer(async (socket) => { +const server = createServer(async (socket) => { const connection = await fromNodeSocket(socket, { serverVersion: '16.3 (PGlite 0.2.0)', auth: { diff --git a/examples/pglite-auth/password.ts b/examples/pglite-auth/password.ts index 2d44a06..04d6f6c 100644 --- a/examples/pglite-auth/password.ts +++ b/examples/pglite-auth/password.ts @@ -1,10 +1,10 @@ import { PGlite } from '@electric-sql/pglite'; -import net from 'node:net'; +import { createServer } from 'node:net'; import { fromNodeSocket } from 'pg-gateway/node'; const db = new PGlite(); -const server = net.createServer(async (socket) => { +const server = createServer(async (socket) => { const connection = await fromNodeSocket(socket, { serverVersion: '16.3 (PGlite 0.2.0)', auth: { diff --git a/examples/pglite-auth/scram-sha-256.ts b/examples/pglite-auth/scram-sha-256.ts index 42dcafa..d4a54ad 100644 --- a/examples/pglite-auth/scram-sha-256.ts +++ b/examples/pglite-auth/scram-sha-256.ts @@ -1,11 +1,11 @@ import { PGlite } from '@electric-sql/pglite'; -import net from 'node:net'; +import { createServer } from 'node:net'; import { createScramSha256Data } from 'pg-gateway'; import { fromNodeSocket } from 'pg-gateway/node'; const db = new PGlite(); -const server = net.createServer(async (socket) => { +const server = createServer(async (socket) => { const connection = await fromNodeSocket(socket, { serverVersion: '16.3 (PGlite 0.2.0)', auth: { diff --git a/examples/pglite-auth/trust.ts b/examples/pglite-auth/trust.ts index 8d29ddf..c5c2703 100644 --- a/examples/pglite-auth/trust.ts +++ b/examples/pglite-auth/trust.ts @@ -1,10 +1,10 @@ import { PGlite } from '@electric-sql/pglite'; -import net from 'node:net'; +import { createServer } from 'node:net'; import { fromNodeSocket } from 'pg-gateway/node'; const db = new PGlite(); -const server = net.createServer(async (socket) => { +const server = createServer(async (socket) => { const connection = await fromNodeSocket(socket, { serverVersion: '16.3 (PGlite 0.2.0)', auth: { diff --git a/examples/pglite-multiple/index.ts b/examples/pglite-multiple/index.ts index 1d88afa..e4dcb48 100644 --- a/examples/pglite-multiple/index.ts +++ b/examples/pglite-multiple/index.ts @@ -1,6 +1,6 @@ import { PGlite, type PGliteInterface } from '@electric-sql/pglite'; import { mkdir, readFile } from 'node:fs/promises'; -import net from 'node:net'; +import { createServer } from 'node:net'; import { type TlsOptionsCallback, createPreHashedPassword } from 'pg-gateway'; import { fromNodeSocket } from 'pg-gateway/node'; @@ -21,7 +21,7 @@ function getIdFromServerName(serverName: string) { return id; } -const server = net.createServer(async (socket) => { +const server = createServer(async (socket) => { let db: PGliteInterface; const connection = await fromNodeSocket(socket, { From e1f300e0796adc60b4afc1b04237efae5c8c71c1 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Fri, 13 Sep 2024 17:06:36 -0600 Subject: [PATCH 2/3] docs: fix note in pglite example now that we use trust auth method --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 72b09b6..22c5f66 100644 --- a/README.md +++ b/README.md @@ -508,7 +508,7 @@ You can test the connection using `psql`: psql -h localhost -U postgres ``` -You should be prompted for a password (`postgres`) and then brought into the `psql` REPL. At this point you are communicating directly with PGlite. +You should immediately be brought into the `psql` REPL. At this point you are communicating directly with PGlite. ### Reverse Proxy using SNI From 69f6d6966c0464d0f5871257b1d085609d1aab59 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Fri, 13 Sep 2024 17:08:55 -0600 Subject: [PATCH 3/3] docs: remove development note --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index 22c5f66..93b6bde 100644 --- a/README.md +++ b/README.md @@ -669,12 +669,6 @@ _/etc/hosts_ On Windows this file lives at `C:\Windows\System32\Drivers\etc\hosts`. -## Development - -```shell -npm run dev -``` - ## License MIT