-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathpostgres_p.d.ts
More file actions
110 lines (90 loc) · 3.35 KB
/
postgres_p.d.ts
File metadata and controls
110 lines (90 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import * as AWSXRay from 'aws-xray-sdk-core';
import * as PG from 'pg';
export default function capturePostgres(pg: typeof PG): capturePostgres.PatchedPostgres;
declare namespace capturePostgres {
interface CaptureQueryMethod {
<T extends PG.Submittable>(queryStream: T, segment?: AWSXRay.SegmentLike): T;
<R extends any[] = any[], I extends any[] = any[]>(
queryConfig: PG.QueryArrayConfig<I>,
values?: I,
segment?: AWSXRay.SegmentLike
): Promise<PG.QueryArrayResult<R>>;
<R extends PG.QueryResultRow = any, I extends any[] = any[]>(
queryConfig: PG.QueryConfig<I>,
segment?: AWSXRay.SegmentLike
): Promise<PG.QueryResult<R>>;
<R extends PG.QueryResultRow = any, I extends any[] = any[]>(
queryTextOrConfig: string | PG.QueryConfig<I>,
values?: I,
segment?: AWSXRay.SegmentLike
): Promise<PG.QueryResult<R>>;
<R extends any[] = any[], I extends any[] = any[]>(
queryConfig: PG.QueryArrayConfig<I>,
callback: (err: Error, result: PG.QueryArrayResult<R>) => void,
segment?: AWSXRay.SegmentLike
): void;
<R extends PG.QueryResultRow = any, I extends any[] = any[]>(
queryTextOrConfig: string | PG.QueryConfig<I>,
callback: (err: Error, result: PG.QueryResult<R>) => void,
segment?: AWSXRay.SegmentLike
): void;
<R extends PG.QueryResultRow = any, I extends any[] = any[]>(
queryText: string,
values: I,
callback: (err: Error, result: PG.QueryResult<R>) => void,
segment?: AWSXRay.SegmentLike
): void;
}
type PatchedClientBase<T extends PG.ClientBase> = {
[K in keyof T]: K extends 'query'
? CaptureQueryMethod
: T[K];
};
interface PatchedClientBaseConstructor<T extends PG.ClientBase> {
new(config?: string | PG.ClientConfig): PatchedClientBase<T>;
}
type PatchedClient = PatchedClientBase<PG.Client>;
type PatchedClientConstructor = PatchedClientBaseConstructor<PG.Client>;
type PatchedPoolClient = PatchedClientBase<PG.PoolClient>;
type PatchedPoolClientConstructor = PatchedClientBaseConstructor<PG.PoolClient>;
interface PatchedPoolConnectMethod {
(): Promise<PatchedPoolClient>;
(callback: (err: Error, client: PatchedPoolClient, done: (release?: any) => void) => void): void;
}
interface PatchedPoolOnMethod {
(event: 'error', listener: (err: Error, client: PatchedPoolClient) => void): PatchedPool;
(event: 'connect' | 'acquire' | 'remove', listener: (client: PatchedPoolClient) => void): PatchedPool;
}
type PatchedPool<T = PG.Pool> = {
[K in keyof T]: K extends 'connect'
? PatchedPoolConnectMethod
: K extends 'on'
? PatchedPoolOnMethod
: T[K];
};
interface PatchedPoolConstructor {
new(config?: PG.PoolConfig): PatchedPool;
}
interface PatchedEventsOnMethod {
(event: 'error', listener: (err: Error, client: PatchedClient) => void): PatchedEvents;
}
type PatchedEvents<T = PG.Events> = {
[K in keyof T]: K extends 'on'
? PatchedEventsOnMethod
: T[K];
};
interface PatchedEventsConstructor {
new(): PatchedEvents;
}
type PatchedPostgres<T = typeof PG> = {
[K in keyof T]: K extends 'Client'
? PatchedClientConstructor
: K extends 'PoolClient'
? PatchedPoolClientConstructor
: K extends 'Pool'
? PatchedPoolConstructor
: K extends 'Events'
? PatchedEventsConstructor
: T[K];
};
}