From 73181a889f34c0b53dda9ffa283a802f7b558fdf Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Wed, 17 May 2023 16:47:07 -0400 Subject: [PATCH] Add stream factory method type Refs: https://github.com/brianc/node-postgres/pull/2898 --- types/pg/index.d.ts | 4 ++-- types/pg/pg-tests.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/types/pg/index.d.ts b/types/pg/index.d.ts index 48287d089c0540..980c7d9ee961e3 100644 --- a/types/pg/index.d.ts +++ b/types/pg/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for pg 8.6 +// Type definitions for pg 8.10 // Project: https://github.com/brianc/node-postgres // Definitions by: Phips Peter , Ravi van Rooijen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -21,7 +21,7 @@ export interface ClientConfig { host?: string | undefined; connectionString?: string | undefined; keepAlive?: boolean | undefined; - stream?: stream.Duplex | undefined; + stream?: () => stream.Duplex | stream.Duplex | undefined; statement_timeout?: false | number | undefined; ssl?: boolean | ConnectionOptions | undefined; query_timeout?: number | undefined; diff --git a/types/pg/pg-tests.ts b/types/pg/pg-tests.ts index f6c7c4120984f4..b1468ed2ee0cf8 100644 --- a/types/pg/pg-tests.ts +++ b/types/pg/pg-tests.ts @@ -1,3 +1,4 @@ +import { connect } from 'net'; import { types, Client, CustomTypesConfig, QueryArrayConfig, Pool, DatabaseError } from 'pg'; import TypeOverrides = require('pg/lib/type-overrides'); import { NoticeMessage } from 'pg-protocol/dist/messages'; @@ -305,6 +306,14 @@ c = new Client({ connectionTimeoutMillis: 1000, // connection timeout optionally specified }); +// using custom socket factory method +c = new Client({ + stream: () => connect({ + host: 'my.database-server.com', + port: 5334, + }), +}); + const dynamicPasswordSync = new Client({ password: () => 'sync-secret', });