Skip to content

Commit 1780c27

Browse files
committed
improving typescript.
1 parent 549c53e commit 1780c27

File tree

5 files changed

+54
-39
lines changed

5 files changed

+54
-39
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pg-promise",
3-
"version": "5.2.1",
3+
"version": "5.2.2",
44
"description": "Promises interface for PostgreSQL",
55
"main": "lib/index.js",
66
"scripts": {

test/typescript/connection.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ import * as pgPromise from 'pg-promise';
55
var pgp:pgPromise.IMain = pgPromise();
66
var db = pgp('connection');
77

8+
type t = pgPromise.IConfig;
9+
var r:t;
10+
r.application_name = 'hello';
11+
r.ssl = {
12+
ca: ''
13+
};
14+
15+
var db2 = pgp({
16+
binary: true
17+
});
18+
819
db.connect()
920
.then(ctx=> {
1021
var cn = ctx.client.connectionParameters;

test/typescript/pg.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ var db = pgp('connection');
88

99
var pg = pgp.pg;
1010

11-
var client = new pg.Client({});
11+
var client = new pg.Client({
12+
ssl: {
13+
rejectUnauthorized:true
14+
}
15+
});
1216

1317
db.connect()
1418
.then(t=> {

typescript/pg-promise.d.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -570,20 +570,7 @@ declare module 'pg-promise' {
570570
$config:ILibConfig<Ext>;
571571
}
572572

573-
// Database connection configuration interface;
574-
// See: https://github.com/brianc/node-postgres/blob/master/lib/connection-parameters.js#L36
575-
interface IConfig {
576-
host?:string,
577-
port?:number,
578-
database:string,
579-
user?:string,
580-
password?:string,
581-
ssl?:boolean,
582-
binary?:boolean,
583-
client_encoding?:string,
584-
application_name?:string,
585-
fallback_application_name?:string
586-
}
573+
type IConfig = pg.IConnectionParameters;
587574

588575
// Post-initialization interface;
589576
// API: http://vitaly-t.github.io/pg-promise/module-pg-promise.html

typescript/pg-subset.d.ts

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
declare module 'pg-subset' {
1515

16-
import { EventEmitter } from 'events';
16+
import {EventEmitter} from 'events';
1717

1818
namespace pg {
1919

2020
interface IColumn {
2121
name:string,
2222
dataTypeID:number,
2323

24-
// the ones below are not available with the Native Bindings;
24+
// properties below are not available within Native Bindings:
2525

2626
tableID:number,
2727
columnID:number,
@@ -38,23 +38,36 @@ declare module 'pg-subset' {
3838

3939
duration:number, // pg-promise extension
4040

41-
// the ones below are not available with the Native Bindings;
41+
// properties below are not available within Native Bindings:
4242

4343
rowAsArray:boolean
4444
}
4545

46+
// SSL configuration;
47+
// For property types and documentation see:
48+
// http://nodejs.org/api/tls.html#tls_tls_connect_options_callback
49+
interface ISSLConfig {
50+
ca?:string|string[]|Buffer|Buffer[];
51+
pfx?:string|Buffer;
52+
cert?:string|string[]|Buffer|Buffer[];
53+
key?:string|string[]|Buffer|Buffer[];
54+
passphrase?:string;
55+
rejectUnauthorized?:boolean;
56+
NPNProtocols?:string[]|Buffer;
57+
}
58+
4659
interface IConnectionParameters {
47-
database:string;
48-
user:string;
49-
password:string;
50-
port:number;
51-
host:string;
52-
ssl:boolean;
53-
binary:boolean;
54-
client_encoding:string;
55-
application_name:string;
56-
fallback_application_name:string;
57-
isDomainSocket:boolean;
60+
database?:string;
61+
user?:string;
62+
password?:string;
63+
port?:number;
64+
host?:string;
65+
ssl?:boolean|ISSLConfig;
66+
binary?:boolean;
67+
client_encoding?:string;
68+
application_name?:string;
69+
fallback_application_name?:string;
70+
isDomainSocket?:boolean;
5871
}
5972

6073
// Interface of 'pg-types' module;
@@ -105,7 +118,7 @@ declare module 'pg-subset' {
105118

106119
client_encoding:string,
107120

108-
ssl:boolean,
121+
ssl:boolean|ISSLConfig,
109122

110123
application_name?:string,
111124

@@ -124,15 +137,15 @@ declare module 'pg-subset' {
124137

125138
class Client extends EventEmitter {
126139

127-
constructor(config:any);
140+
constructor(cn:string | IConnectionParameters);
128141

129142
query:(config:any, values:any, callback:(err:Error, result:IResult)=>void)=>Query;
130143

131-
on(event: 'drain', listener: () => void): this;
132-
on(event: 'error', listener: (err: Error) => void): this;
133-
on(event: 'notification', listener: (message: any) => void): this;
134-
on(event: 'notice', listener: (message: any) => void): this;
135-
on(event: string, listener: Function): this;
144+
on(event:'drain', listener:() => void):this;
145+
on(event:'error', listener:(err:Error) => void):this;
146+
on(event:'notification', listener:(message:any) => void):this;
147+
on(event:'notice', listener:(message:any) => void):this;
148+
on(event:string, listener:Function):this;
136149

137150
connectionParameters:IConnectionParameters;
138151
database:string;
@@ -141,11 +154,11 @@ declare module 'pg-subset' {
141154
port:number;
142155
host:string;
143156

144-
// these are not available with Native Bindings:
157+
// properties below are not available within Native Bindings:
145158

146159
queryQueue:Array<Query>;
147160
binary:boolean;
148-
ssl:boolean;
161+
ssl:boolean|ISSLConfig;
149162
secretKey:number;
150163
processID:number;
151164
encoding:string;

0 commit comments

Comments
 (0)