-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathindex.ts
More file actions
100 lines (85 loc) · 2.72 KB
/
index.ts
File metadata and controls
100 lines (85 loc) · 2.72 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
/*
We export the pg library mostly unchanged, but we do make a few tweaks.
(1) Connecting and querying can require a lot of network round-trips. We
add a pipelining option for the connection (startup + auth + first query),
but this works with cleartext password auth only. We can also pipeline TLS
startup, but currently this works only with Neon hosts (not vanilla pg or
pgbouncer).
(2) SCRAM auth is deliberately CPU-intensive, and this is not appropriate
for a serverless environment. In case it is still used, however, we replace
the standard (synchronous) pg implementation with one that uses SubtleCrypto
for repeated SHA-256 digests. This saves some time and CPU.
(3) We now (experimentally) redirect Pool.query over a fetch request if the
circumstances are right.
*/
import type { ClientBase as PgClientBase } from 'pg';
import { type SocketDefaults } from './shims/net';
// Ensure we are very explicit while using these apis. This ensures more type safety
// specially since this library is made to run both in the browser and node.js environments.
declare global {
const window: Window | undefined;
const document: Document | undefined;
interface Window {}
interface Document {}
}
export * from './httpQuery';
export * from './sqlTemplate';
export type * from './httpTypes';
export { NeonPool as Pool, type NeonPoolClient as PoolClient } from './pool';
export { NeonClient as Client } from './client';
export { Socket as neonConfig } from './shims/net';
export type {
SocketDefaults as NeonConfig,
FetchEndpointOptions,
WebSocketConstructor,
WebSocketLike,
subtls,
startTls,
TrustedCert,
WebSocketReadQueue,
} from './shims/net';
// class 'ClientBase' exists only in @types/pg: under the hood in pg it's just a `Client extends EventEmitter`
export interface ClientBase extends PgClientBase {
neonConfig: NeonConfigGlobalAndClient;
}
export { defaults, types, DatabaseError } from 'pg';
export type {
BindConfig,
ClientConfig,
Connection,
ConnectionConfig,
CustomTypesConfig,
Defaults,
Events,
ExecuteConfig,
FieldDef,
MessageConfig,
Notification,
PoolConfig,
Query,
QueryArrayConfig,
QueryArrayResult,
QueryConfig,
QueryParse,
QueryResult,
QueryResultBase,
QueryResultRow,
ResultBuilder,
Submittable,
} from 'pg';
export type NeonConfigGlobalOnly = Pick<
SocketDefaults,
| 'fetchEndpoint'
| 'poolQueryViaFetch'
| 'fetchConnectionCache'
| 'fetchFunction'
>;
export type NeonConfigGlobalAndClient = Omit<
SocketDefaults,
keyof NeonConfigGlobalOnly
>;
// for debugging purposes, this gets defined by esbuild, so users can track
// whether they've imported .js (CJS) or .mjs (ESM) or (uh-oh) both
// @ts-ignore
const _bundleExt: 'js' | 'mjs' = BUNDLE_EXT;
export { _bundleExt };