Skip to content
Open
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
4 changes: 2 additions & 2 deletions index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ export declare class Client extends Client_2 {
config?: (string | ClientConfig) | undefined;
get neonConfig(): neonConfig;
constructor(config?: (string | ClientConfig) | undefined);
connect(): Promise<void>;
connect(callback: (err?: Error) => void): void;
connect(): Promise<Client_2>;
connect(callback: ((err: Error) => void) | ((err: null, c: Client_2) => void)): void;
_handleAuthSASLContinue(msg: any): Promise<void>;
}

Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ export declare class Client extends Client_2 {
config?: (string | ClientConfig) | undefined;
get neonConfig(): neonConfig;
constructor(config?: (string | ClientConfig) | undefined);
connect(): Promise<void>;
connect(callback: (err?: Error) => void): void;
connect(): Promise<Client_2>;
connect(callback: ((err: Error) => void) | ((err: null, c: Client_2) => void)): void;
_handleAuthSASLContinue(msg: any): Promise<void>;
}

Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1318,10 +1318,10 @@ void 0||m.env.PGHOST!==void 0,s=m.env.USER??m.env.USERNAME;if(!i&&this.host==="l
s&&this.database===s&&this.password===null)throw new Error(`No database host or connection string wa\
s set, and key parameters have default values (host: localhost, user: ${s}, db: ${s}, password: null\
). Is an environment variable missing? Alternatively, if you intended to connect with these paramete\
rs, please set the host to 'localhost' explicitly.`);let o=super.connect(t),u=n.pipelineTLS&&this.ssl,
c=n.pipelineConnect==="password";if(!u&&!n.pipelineConnect)return o;let l=this.connection;if(u&&l.on(
"connect",()=>l.stream.emit("data","S")),c){l.removeAllListeners("authenticationCleartextPassword"),
l.removeAllListeners("readyForQuery"),l.once("readyForQuery",()=>l.on("readyForQuery",this._handleReadyForQuery.
rs, please set the host to 'localhost' explicitly.`);let o=t?super.connect(t):super.connect(),u=n.pipelineTLS&&
this.ssl,c=n.pipelineConnect==="password";if(!u&&!n.pipelineConnect)return o;let l=this.connection;if(u&&
l.on("connect",()=>l.stream.emit("data","S")),c){l.removeAllListeners("authenticationCleartextPasswo\
rd"),l.removeAllListeners("readyForQuery"),l.once("readyForQuery",()=>l.on("readyForQuery",this._handleReadyForQuery.
bind(this)));let f=this.ssl?"sslconnect":"connect";l.on(f,()=>{this.neonConfig.disableWarningInBrowsers||
Ke(),this._handleAuthCleartextPassword(),this._handleReadyForQuery()})}return o}async _handleAuthSASLContinue(t){
if(typeof crypto>"u"||crypto.subtle===void 0||crypto.subtle.importKey===void 0)throw new Error("Cann\
Expand Down
8 changes: 4 additions & 4 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,10 +1316,10 @@ void 0||m.env.PGHOST!==void 0,s=m.env.USER??m.env.USERNAME;if(!i&&this.host==="l
s&&this.database===s&&this.password===null)throw new Error(`No database host or connection string wa\
s set, and key parameters have default values (host: localhost, user: ${s}, db: ${s}, password: null\
). Is an environment variable missing? Alternatively, if you intended to connect with these paramete\
rs, please set the host to 'localhost' explicitly.`);let o=super.connect(t),u=n.pipelineTLS&&this.ssl,
c=n.pipelineConnect==="password";if(!u&&!n.pipelineConnect)return o;let l=this.connection;if(u&&l.on(
"connect",()=>l.stream.emit("data","S")),c){l.removeAllListeners("authenticationCleartextPassword"),
l.removeAllListeners("readyForQuery"),l.once("readyForQuery",()=>l.on("readyForQuery",this._handleReadyForQuery.
rs, please set the host to 'localhost' explicitly.`);let o=t?super.connect(t):super.connect(),u=n.pipelineTLS&&
this.ssl,c=n.pipelineConnect==="password";if(!u&&!n.pipelineConnect)return o;let l=this.connection;if(u&&
l.on("connect",()=>l.stream.emit("data","S")),c){l.removeAllListeners("authenticationCleartextPasswo\
rd"),l.removeAllListeners("readyForQuery"),l.once("readyForQuery",()=>l.on("readyForQuery",this._handleReadyForQuery.
bind(this)));let f=this.ssl?"sslconnect":"connect";l.on(f,()=>{this.neonConfig.disableWarningInBrowsers||
bt(),this._handleAuthCleartextPassword(),this._handleReadyForQuery()})}return o}async _handleAuthSASLContinue(t){
if(typeof crypto>"u"||crypto.subtle===void 0||crypto.subtle.importKey===void 0)throw new Error("Cann\
Expand Down
71 changes: 32 additions & 39 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"dependencies": {
"@types/node": "^22.15.30",
"@types/pg": "^8.8.0"
"@types/pg": "^8.20.0"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20241230.0",
Expand Down Expand Up @@ -91,7 +91,7 @@
"node-fetch": "^3.3.2",
"npm-run-all": "^4.1.5",
"path": "file:src/shims/path",
"pg": "8.8.0",
"pg": "8.20.0",
"pg-native": "file:src/shims/pg-native",
"playwright": "^1.49.1",
"prettier": "^3.4.1",
Expand Down
8 changes: 4 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export class NeonClient extends Client {
super(config);
}

override connect(): Promise<void>;
override connect(callback: (err?: Error) => void): void;
override connect(callback?: (err?: Error) => void) {
override connect(): Promise<Client>;
override connect(callback: ((err: Error) => void) | ((err: null, c: Client) => void)): void;
override connect(callback?: ((err: Error) => void) | ((err: null, c: Client) => void)) {
const { neonConfig } = this;

// disable TLS if requested
Expand Down Expand Up @@ -63,7 +63,7 @@ export class NeonClient extends Client {
`No database host or connection string was set, and key parameters have default values (host: localhost, user: ${defaultUser}, db: ${defaultUser}, password: null). Is an environment variable missing? Alternatively, if you intended to connect with these parameters, please set the host to 'localhost' explicitly.`,
);
// pipelining
const result = super.connect(callback as any) as void | Promise<void>;
const result = callback ? super.connect(callback) : super.connect();

const pipelineTLS = neonConfig.pipelineTLS && this.ssl;
const pipelineConnect = neonConfig.pipelineConnect === 'password';
Expand Down
24 changes: 17 additions & 7 deletions tests/cli/ws.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { expect, test, describe, vi, assertType } from 'vitest';
import { Pool as PgPool, type QueryResult } from 'pg';
import * as subtls from 'subtls';
import { sampleQueries } from './sampleQueries';
import { ISRGX1Cert } from './subtlsCert';
import {
neon,
neonConfig,
Pool as WsPool,
Client as WsClient,
SqlTemplate,
Client as WsClient,
Pool as WsPool,
} from '@neondatabase/serverless'; // see package.json: this points to 'file:.'
import { Pool as PgPool, type QueryResult } from 'pg';
import * as subtls from 'subtls';
import { assertType, describe, expect, test, vi } from 'vitest';
import { sampleQueries } from './sampleQueries';
import { ISRGX1Cert } from './subtlsCert';

function recursiveTransform(x: any, transform: (x: any) => any) {
if (Array.isArray(x)) {
Expand Down Expand Up @@ -118,6 +118,16 @@ describe.each([
}
});

test('client.connect() returns the client in a promise', () => {
const client = new WsClient(DB_URL);

return client.connect().then((clientInside) => {
expect(client).toEqual(clientInside);

return client.end().then(() => {});
});
});

test('client.query()', async () => {
const client = new WsClient(DB_URL);
await client.connect();
Expand Down