@@ -3,15 +3,7 @@ import { Socket } from '../shims/net';
3
3
import { neon , NeonDbError } from './httpQuery' ;
4
4
import type { NeonConfigGlobalAndClient } from './neonConfig' ;
5
5
6
- // @ts -ignore -- this isn't officially exported by pg
7
- import ConnectionParameters from '../node_modules/pg/lib/connection-parameters' ;
8
-
9
- interface ConnectionParameters {
10
- user : string ;
11
- password : string ;
12
- host : string ;
13
- database : string ;
14
- }
6
+ import ConnectionParameters from 'pg/lib/connection-parameters' ;
15
7
16
8
/**
17
9
* We export the pg library mostly unchanged, but we do make a few tweaks.
@@ -290,6 +282,15 @@ function promisify(Promise: any, callback: any) {
290
282
return { callback : cb , result : result } ;
291
283
}
292
284
285
+ // Type augmentation for pg Pool internals that don't have publicly exported types
286
+ // - https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
287
+ declare module 'pg' {
288
+ interface Pool {
289
+ options : ConstructorParameters < typeof Pool > [ 0 ] ;
290
+ Promise : PromiseConstructorLike ;
291
+ }
292
+ }
293
+
293
294
class NeonPool extends Pool {
294
295
Client = NeonClient ;
295
296
hasFetchUnsupportedListeners = false ;
@@ -302,7 +303,6 @@ class NeonPool extends Pool {
302
303
return super . on ( event as any , listener ) ;
303
304
}
304
305
305
- // @ts -ignore -- is it even possible to make TS happy with these overloaded function types?
306
306
query ( config ?: any , values ?: any , cb ?: any ) {
307
307
if (
308
308
! Socket . poolQueryViaFetch ||
@@ -319,15 +319,11 @@ class NeonPool extends Pool {
319
319
}
320
320
321
321
// create a synthetic callback that resolves the returned Promise
322
- // @ts -ignore -- TS doesn't know about this.Promise
323
322
const response = promisify ( this . Promise , cb ) ;
324
323
cb = response . callback ;
325
324
326
325
try {
327
- const cp = new ConnectionParameters (
328
- // @ts -expect-error -- TS doesn't know about this.options
329
- this . options ,
330
- ) as ConnectionParameters ;
326
+ const cp = new ConnectionParameters ( this . options ) ;
331
327
const euc = encodeURIComponent ,
332
328
eu = encodeURI ;
333
329
const connectionString = `postgresql://${ euc ( cp . user ) } :${ euc ( cp . password ) } @${ euc ( cp . host ) } /${ eu ( cp . database ) } ` ;
@@ -341,7 +337,6 @@ class NeonPool extends Pool {
341
337
} ) ;
342
338
343
339
sql ( queryText , queryValues , {
344
- // @ts -expect-error -- TS doesn't know about this.options
345
340
types : config . types ?? this . options ?. types ,
346
341
} )
347
342
. then ( ( result ) => cb ( undefined , result ) )
0 commit comments