-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.d.mts
815 lines (745 loc) · 32.5 KB
/
index.d.mts
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
/// <reference types="node" />
import { BindConfig } from 'pg';
import { Client as Client_2 } from 'pg';
import type { ClientBase as ClientBase_2 } from 'pg';
import { ClientConfig } from 'pg';
import { Connection } from 'pg';
import { ConnectionConfig } from 'pg';
import { CustomTypesConfig } from 'pg';
import { DatabaseError } from 'pg';
import { Defaults } from 'pg';
import { defaults } from 'pg';
import { EventEmitter } from 'events';
import { Events } from 'pg';
import { ExecuteConfig } from 'pg';
import { FieldDef } from 'pg';
import { MessageConfig } from 'pg';
import { Notification } from 'pg';
import { Pool as Pool_2 } from 'pg';
import type { PoolClient as PoolClient_2 } from 'pg';
import { PoolConfig } from 'pg';
import { Query } from 'pg';
import { QueryArrayConfig } from 'pg';
import { QueryArrayResult } from 'pg';
import { QueryConfig } from 'pg';
import type { QueryConfigValues } from 'pg';
import { QueryParse } from 'pg';
import { QueryResult } from 'pg';
import { QueryResultBase } from 'pg';
import { QueryResultRow } from 'pg';
import { ResultBuilder } from 'pg';
import { Submittable } from 'pg';
import { types } from 'pg';
declare const allKeyUsages: readonly ["digitalSignature", "nonRepudiation", "keyEncipherment", "dataEncipherment", "keyAgreement", "keyCertSign", "cRLSign", "encipherOnly", "decipherOnly"];
declare class ASN1Bytes extends Bytes {
readASN1Length(comment?: string): Promise<number>;
expectASN1Length(comment?: string): Promise<readonly [() => void, () => number]>;
expectASN1TypeAndLength(typeNum: number, typeDesc: string, comment?: string): Promise<readonly [() => void, () => number]>;
readASN1OID(comment?: string): Promise<string>;
readASN1Boolean(comment?: string): Promise<boolean>;
readASN1UTCTime(comment?: string): Promise<Date>;
readASN1GeneralizedTime(comment?: string): Promise<Date>;
readASN1Time(comment?: string): Promise<Date>;
readASN1BitString(comment?: string): Promise<Uint8Array<ArrayBuffer>>;
expectASN1Sequence(comment?: string): Promise<readonly [() => void, () => number]>;
expectASN1OctetString(comment?: string): Promise<readonly [() => void, () => number]>;
expectASN1DERDoc(): Promise<readonly [() => void, () => number]>;
expectASN1Null(comment?: string): Promise<void>;
}
export { BindConfig }
export declare const _bundleExt: 'js' | 'mjs';
declare class Bytes {
indent: number;
fetchFn: undefined | ((bytes: number) => Promise<Uint8Array | undefined>);
endOfReadableData: number;
offset: number;
dataView: DataView;
data: Uint8Array;
comments: Record<number, string>;
indents: Record<number, number>;
/**
* @param data -
* * If data is a `Uint8Array`, this is the initial data
* * If data is a `number`, this is the initial size in bytes (all zeroes)
* * If data is a `function`, this function is called to retrieve data when required
*/
constructor(data?: Uint8Array | number | ((bytes: number) => Promise<Uint8Array | undefined>), indent?: number);
readRemaining(): number;
resizeTo(newSize: number): void;
ensureReadAvailable(bytes: number): Promise<void>;
ensureWriteAvailable(bytes: number): void;
expectLength(length: number, indentDelta?: number): readonly [() => void, () => number];
comment(s: string, offset?: number): this;
lengthComment(length: number, comment?: string, inclusive?: boolean): string;
subarrayForRead(length: number): Promise<Uint8Array<ArrayBufferLike>>;
skipRead(length: number, comment?: string): Promise<this>;
readBytes(length: number): Promise<Uint8Array<ArrayBuffer>>;
readUTF8String(length: number): Promise<string>;
readUTF8StringNullTerminated(): Promise<string>;
readUint8(comment?: string): Promise<number>;
readUint16(comment?: string): Promise<number>;
readUint24(comment?: string): Promise<number>;
readUint32(comment?: string): Promise<number>;
expectBytes(expected: Uint8Array | number[], comment?: string): Promise<void>;
expectUint8(expectedValue: number, comment?: string): Promise<void>;
expectUint16(expectedValue: number, comment?: string): Promise<void>;
expectUint24(expectedValue: number, comment?: string): Promise<void>;
expectUint32(expectedValue: number, comment?: string): Promise<void>;
expectReadLength(length: number, indentDelta?: number): Promise<readonly [() => void, () => number]>;
expectLengthUint8(comment?: string): Promise<readonly [() => void, () => number]>;
expectLengthUint16(comment?: string): Promise<readonly [() => void, () => number]>;
expectLengthUint24(comment?: string): Promise<readonly [() => void, () => number]>;
expectLengthUint32(comment?: string): Promise<readonly [() => void, () => number]>;
expectLengthUint8Incl(comment?: string): Promise<readonly [() => void, () => number]>;
expectLengthUint16Incl(comment?: string): Promise<readonly [() => void, () => number]>;
expectLengthUint24Incl(comment?: string): Promise<readonly [() => void, () => number]>;
expectLengthUint32Incl(comment?: string): Promise<readonly [() => void, () => number]>;
subarrayForWrite(length: number): Uint8Array<ArrayBufferLike>;
skipWrite(length: number, comment?: string): this;
writeBytes(bytes: number[] | Uint8Array): this;
writeUTF8String(s: string): this;
writeUTF8StringNullTerminated(s: string): this;
writeUint8(value: number, comment?: string): Bytes;
writeUint16(value: number, comment?: string): Bytes;
writeUint24(value: number, comment?: string): Bytes;
writeUint32(value: number, comment?: string): Bytes;
_writeLengthGeneric(lengthBytes: number, inclusive: boolean, comment?: string): () => void;
writeLengthUint8(comment?: string): () => void;
writeLengthUint16(comment?: string): () => void;
writeLengthUint24(comment?: string): () => void;
writeLengthUint32(comment?: string): () => void;
writeLengthUint8Incl(comment?: string): () => void;
writeLengthUint16Incl(comment?: string): () => void;
writeLengthUint24Incl(comment?: string): () => void;
writeLengthUint32Incl(comment?: string): () => void;
expectWriteLength(length: number, indentDelta?: number): readonly [() => void, () => number];
array(): Uint8Array<ArrayBufferLike>;
commentedString(all?: boolean): string;
}
declare class Cert {
serialNumber: Uint8Array;
algorithm: OID;
issuer: DistinguishedName;
validityPeriod: {
notBefore: Date;
notAfter: Date;
};
subject: DistinguishedName;
publicKey: {
identifiers: OID[];
data: Uint8Array;
all: Uint8Array;
};
signature: Uint8Array;
keyUsage?: {
critical?: boolean;
usages: Set<typeof allKeyUsages[number]>;
};
subjectAltNames?: string[];
extKeyUsage?: {
clientTls?: true;
serverTls?: true;
};
authorityKeyIdentifier?: Uint8Array;
subjectKeyIdentifier?: Uint8Array;
basicConstraints?: {
critical?: boolean;
ca?: boolean;
pathLength?: number;
} | undefined;
signedData: Uint8Array;
rawData: Uint8Array;
constructor();
static distinguishedNamesAreEqual(dn1: DistinguishedName, dn2: DistinguishedName): boolean;
static stringFromDistinguishedName(dn: DistinguishedName): string;
static create(certData: Uint8Array | ASN1Bytes | CertJSON): Promise<Cert>;
subjectAltNameMatchingHost(host: string): string | undefined;
isValidAtMoment(moment?: Date): boolean;
description(): string;
toJSON(): {
serialNumber: string;
algorithm: string;
issuer: DistinguishedName;
validityPeriod: {
notBefore: string;
notAfter: string;
};
subject: DistinguishedName;
publicKey: {
identifiers: string[];
data: string;
all: string;
};
signature: string;
keyUsage: {
critical: boolean | undefined;
usages: ("digitalSignature" | "nonRepudiation" | "keyEncipherment" | "dataEncipherment" | "keyAgreement" | "keyCertSign" | "cRLSign" | "encipherOnly" | "decipherOnly")[];
};
subjectAltNames: string[] | undefined;
extKeyUsage: {
clientTls?: true;
serverTls?: true;
} | undefined;
authorityKeyIdentifier: string | undefined;
subjectKeyIdentifier: string | undefined;
basicConstraints: {
critical?: boolean;
ca?: boolean;
pathLength?: number;
} | undefined;
signedData: string;
rawData: string;
};
static uint8ArraysFromPEM(pem: string): Uint8Array<ArrayBuffer>[];
static fromPEM(pem: string): Promise<Cert[]>;
}
declare type CertJSON = ReturnType<typeof Cert.prototype.toJSON>;
export declare interface Client {
connection: Connection & {
stream: neonConfig;
sendSCRAMClientFinalMessage: (response: any) => void;
ssl: any;
};
_handleReadyForQuery: any;
_handleAuthCleartextPassword: any;
startup: any;
getStartupConf: any;
saslSession: any;
}
/**
* The node-postgres `Client` object re-exported with minor modifications.
* https://node-postgres.com/apis/client
*/
export declare class Client extends Client_2 {
config: any;
get neonConfig(): neonConfig;
constructor(config: any);
connect(): Promise<void>;
connect(callback: (err?: Error) => void): void;
_handleAuthSASLContinue(msg: any): Promise<void>;
}
export declare interface ClientBase extends ClientBase_2 {
neonConfig: NeonConfigGlobalAndClient;
}
export { ClientConfig }
export { Connection }
export { ConnectionConfig }
export { CustomTypesConfig }
export { DatabaseError }
declare interface DataRequest {
bytes: number;
resolve: (data: Uint8Array | undefined) => void;
readMode: ReadMode;
}
export { Defaults }
export { defaults }
declare type DistinguishedName = Record<string, string | string[]>;
export { Events }
export { ExecuteConfig }
export declare interface FetchEndpointOptions {
jwtAuth?: boolean;
}
export { FieldDef }
export declare interface FullQueryResults<ArrayMode extends boolean> {
fields: FieldDef[];
command: string;
rowCount: number;
rows: QueryRows<ArrayMode>;
rowAsArray: ArrayMode;
}
export declare interface HTTPQueryOptions<ArrayMode extends boolean, FullResults extends boolean> {
/**
* When `arrayMode` is `false`, which is the default, result rows are
* returned as objects whose keys represent column names, such as
* `{ id: 1 }`).
*
* When `arrayMode` is `true`, rows are returned as arrays (and keys are not
* provided), e.g. `[1]`.
*/
arrayMode?: ArrayMode;
/**
* When `fullResults` is `false`, which is the default, only result rows are
* returned, e.g. `[{ id: 1 }]`).
*
* When `fullResults` is `true`, a result object is returned that matches
* what's returned by node-postgres. This has a `rows` property, which is an
* array of result rows, plus `fields`, which provides column names and
* types, `command` and `rowCount`.
*/
fullResults?: FullResults;
/**
* Any options in `fetchOptions` are merged in to the options passed to
* `fetch`. In case of conflict with what would otherwise be passed, these
* options take precedence.
*/
fetchOptions?: Record<string, any>;
/**
* JWT auth token to be passed as the Bearer token in the Authorization header.
* Can be string, or a function (sync or async) returning a string.
*
* Default: `undefined`
*/
authToken?: string | (() => Promise<string> | string);
/**
* Custom type parsers. See https://github.com/brianc/node-pg-types.
*/
types?: typeof types;
queryCallback?: (query: ParameterizedQuery) => void;
resultCallback?: (query: ParameterizedQuery, result: any, rows: any, opts: any) => void;
}
export declare interface HTTPTransactionOptions<ArrayMode extends boolean, FullResults extends boolean> extends HTTPQueryOptions<ArrayMode, FullResults> {
/**
* Postgres transaction isolation level: see https://www.postgresql.org/docs/current/transaction-iso.html.
* Note that `ReadUncommitted` actually gets you `ReadCommitted` in Postgres.
* */
isolationLevel?: 'ReadUncommitted' | 'ReadCommitted' | 'RepeatableRead' | 'Serializable';
/**
* When `readOnly` is `false`, which is the default, a `READ WRITE` Postgres
* transaction is used.
*
* When `readOnly` is `true`, a `READ ONLY` Postgres transaction is used.
* */
readOnly?: boolean;
/**
* When `deferrable` is `false`, which is the default, a `NOT DEFERRABLE`
* Postgres transaction is used.
*
* When `deferrable` is `true` (and `isolationLevel` is `Serializable` and
* `readOnly` is `true`), a `DEFERRABLE` Postgres transaction is used.
* */
deferrable?: boolean;
}
export { MessageConfig }
/**
* This function returns an async tagged-template function that runs a single
* SQL query (no session or transactions) with low latency over https. Support
* for multiple queries (as a non-interactive transaction) is provided by
* the `transaction` property of the query function.
*
* By default, the query function returns database rows directly. Types should
* match those returned by this driver (i.e. Pool or Client) over WebSockets.
*
* The returned function can also be called directly (i.e. not as a template
* function). In that case, pass it a query string with embedded `$1`, `$2`
* (etc.), followed by an array of query parameters, followed (optionally) by
* any of the same options you can pass to this function.
*
* Some examples:
* ```
* import { neon } from "@neondatabase/serverless";
* const h = "hello", w = "world";
*
* // example 1: default options, tagged-template usage
* const sql = neon("postgres://user:pass@host/db");
* const rows = await sql`SELECT ${h} || ' ' || ${w} AS greeting`;
* // -> [ { greeting: "hello world" } ]
*
* // example 2: `arrayMode` and `fullResults` options, ordinary function usage
* const options = { arrayMode: true, fullResults: true };
* const sql = neon("postgres://user:pass@host/db", options);
* const rows = await sql("SELECT $1 || ' ' || $2 AS greeting", [h, w]);
* // -> {
* // command: "SELECT",
* // fields: [ { name: "greeting", dataTypeID: 25 } ],
* // rowAsArray: true,
* // rowCount: 1,
* // rows: [ [ "hello world" ] ]
* // }
*
* // example 3: `fetchOptions` option, ordinary function usage
* const sql = neon("postgres://user:pass@host/db");
* const rows = await sql(
* "SELECT $1 || ' ' || $2 AS greeting", [h, w],
* { fetchOptions: { priority: "high" } }
* );
* // -> [ { greeting: "hello world" } ]
* ```
*
* @param connectionString - this has the format `postgres://user:pass@host/db`
* @param options - pass `arrayMode: true` to receive results as an array of
* arrays, instead of the default array of objects; pass `fullResults: true`
* to receive a complete result object similar to one returned by node-postgres
* (with properties `rows`, `fields`, `command`, `rowCount`, `rowAsArray`);
* pass as `fetchOptions` an object which will be merged into the options
* passed to `fetch`.
*/
export declare function neon<ArrayMode extends boolean = false, FullResults extends boolean = false>(connectionString: string, { arrayMode: neonOptArrayMode, fullResults: neonOptFullResults, fetchOptions: neonOptFetchOptions, isolationLevel: neonOptIsolationLevel, readOnly: neonOptReadOnly, deferrable: neonOptDeferrable, queryCallback, resultCallback, authToken, }?: HTTPTransactionOptions<ArrayMode, FullResults>): NeonQueryFunction<ArrayMode, FullResults>;
export declare interface NeonConfig {
poolQueryViaFetch: boolean;
fetchEndpoint: string | ((host: string, port: number | string, options?: FetchEndpointOptions) => string);
fetchConnectionCache: boolean;
fetchFunction: any;
webSocketConstructor: WebSocketConstructor | undefined;
wsProxy: string | ((host: string, port: number | string) => string);
useSecureWebSocket: boolean;
forceDisablePgSSL: boolean;
coalesceWrites: boolean;
pipelineConnect: 'password' | false;
subtls: subtls | undefined;
rootCerts: string;
pipelineTLS: boolean;
disableSNI: boolean;
}
export declare class neonConfig extends EventEmitter {
static defaults: NeonConfig;
static opts: Partial<NeonConfig>;
/**
* **Experimentally**, when `poolQueryViaFetch` is `true`, and no listeners
* for the `"connect"`, `"acquire"`, `"release"` or `"remove"` events are set
* on the `Pool`, queries via `Pool.query()` will be sent by low-latency HTTP
* fetch request.
*
* Default: `false`.
*/
static get poolQueryViaFetch(): NeonConfig["poolQueryViaFetch"];
static set poolQueryViaFetch(newValue: NeonConfig['poolQueryViaFetch']);
/**
* Set `fetchEndpoint` to set the server endpoint to be sent queries via http
* fetch. May be useful in local development (e.g. to set a port that's not
* the default 443).
*
* Provide either the full endpoint URL, or a function that takes the
* database host address, port and options, and returns the full endpoint URL
* (including protocol).
*
* Default: custom logic to connect to Neon endpoints.
*/
static get fetchEndpoint(): NeonConfig["fetchEndpoint"];
static set fetchEndpoint(newValue: NeonConfig['fetchEndpoint']);
/**
* **DEPRECATED**. Previously, only when `fetchConnectionCache` was `true`
* did queries carried via HTTP fetch make use of a connection pool/cache
* on the server. All queries now use the connection pool/cache: this setting
* is ignored.
*
* Default: `true`.
*/
static get fetchConnectionCache(): NeonConfig["fetchConnectionCache"];
static set fetchConnectionCache(newValue: NeonConfig['fetchConnectionCache']);
/**
* The `fetchFunction` option allows you to supply an alternative function
* for making http requests. The function must accept the same arguments as
* native `fetch`.
*
* Default: `undefined`.
*/
static get fetchFunction(): NeonConfig["fetchFunction"];
static set fetchFunction(newValue: NeonConfig['fetchFunction']);
/**
* Only if no global `WebSocket` object is available, such as in older
* versions of Node, set `webSocketConstructor` to the constructor for a
* custom WebSocket implementation, such as those provided by `ws` or
* `undici`.
*
* Default: `undefined`.
*/
static get webSocketConstructor(): NeonConfig["webSocketConstructor"];
static set webSocketConstructor(newValue: NeonConfig['webSocketConstructor']);
get webSocketConstructor(): NeonConfig["webSocketConstructor"];
set webSocketConstructor(newValue: NeonConfig['webSocketConstructor']);
/**
* Set `wsProxy` to use your own WebSocket proxy server.
*
* Provide either the proxy server’s domain name, or a function that takes
* the database host and port and returns the proxy server address (without
* protocol).
*
* Example: `(host, port) => "myproxy.example.net?address=" + host + ":" + port`
*
* Default: `host => host + '/v2'`
*/
static get wsProxy(): NeonConfig["wsProxy"];
static set wsProxy(newValue: NeonConfig['wsProxy']);
get wsProxy(): NeonConfig["wsProxy"];
set wsProxy(newValue: NeonConfig['wsProxy']);
/**
* Batch multiple network writes per run-loop into a single outgoing
* WebSocket message.
*
* Default: `true`.
*/
static get coalesceWrites(): NeonConfig["coalesceWrites"];
static set coalesceWrites(newValue: NeonConfig['coalesceWrites']);
get coalesceWrites(): NeonConfig["coalesceWrites"];
set coalesceWrites(newValue: NeonConfig['coalesceWrites']);
/**
* Use a secure (`wss:`) connection to the WebSocket proxy.
*
* Default: `true`.
*/
static get useSecureWebSocket(): NeonConfig["useSecureWebSocket"];
static set useSecureWebSocket(newValue: NeonConfig['useSecureWebSocket']);
get useSecureWebSocket(): NeonConfig["useSecureWebSocket"];
set useSecureWebSocket(newValue: NeonConfig['useSecureWebSocket']);
/**
* Disable TLS encryption in the Postgres protocol (as set via e.g.
* `?sslmode=require` in the connection string). Connection remains secure
* as long as `useSecureWebSocket` is `true`, which is the default.
*
* Default: `true`
*/
static get forceDisablePgSSL(): NeonConfig["forceDisablePgSSL"];
static set forceDisablePgSSL(newValue: NeonConfig['forceDisablePgSSL']);
get forceDisablePgSSL(): NeonConfig["forceDisablePgSSL"];
set forceDisablePgSSL(newValue: NeonConfig['forceDisablePgSSL']);
/**
* When using subtls with `forceDisablePgSSL = false` and Postgres connection
* parameters that specify TLS, setting `disableSNI = true` means that no SNI
* data in included in the Postgres TLS handshake.
*
* On Neon, disabling SNI and including the Neon project name in the password
* avoids CPU-intensive SCRAM authentication, but this is only relevant for
* earlier iterations of Neon's WebSocket support.
*
* Default: `false`.
*/
static get disableSNI(): NeonConfig["disableSNI"];
static set disableSNI(newValue: NeonConfig['disableSNI']);
get disableSNI(): NeonConfig["disableSNI"];
set disableSNI(newValue: NeonConfig['disableSNI']);
/**
* Pipelines the startup message, cleartext password message and first query
* when set to `"password"`. This works only for cleartext password auth.
*
* Default: `"password"`.
*/
static get pipelineConnect(): NeonConfig["pipelineConnect"];
static set pipelineConnect(newValue: NeonConfig['pipelineConnect']);
get pipelineConnect(): NeonConfig["pipelineConnect"];
set pipelineConnect(newValue: NeonConfig['pipelineConnect']);
/**
* If `forceDisablePgSSL` is `false` and the Postgres connection parameters
* specify TLS, you must supply the subtls TLS library to this option:
*
* ```
* import { neonConfig } from '@neondatabase/serverless';
* import * as subtls from 'subtls';
* neonConfig.subtls = subtls;
* ```
*
* Default: `undefined`.
*/
static get subtls(): NeonConfig["subtls"];
static set subtls(newValue: NeonConfig['subtls']);
get subtls(): NeonConfig["subtls"];
set subtls(newValue: NeonConfig['subtls']);
/**
* Pipeline the pg SSL request and TLS handshake when `forceDisablePgSSL` is
* `false` and the Postgres connection parameters specify TLS. Currently
* compatible only with Neon hosts.
*
* Default: `false`.
*/
static get pipelineTLS(): NeonConfig["pipelineTLS"];
static set pipelineTLS(newValue: NeonConfig['pipelineTLS']);
get pipelineTLS(): NeonConfig["pipelineTLS"];
set pipelineTLS(newValue: NeonConfig['pipelineTLS']);
/**
* Set `rootCerts` to a string comprising one or more PEM files. These are
* the trusted root certificates for a TLS connection to Postgres when
* `forceDisablePgSSL` is `false` and the Postgres connection parameters
* specify TLS.
*
* Default: `""`.
*/
static get rootCerts(): NeonConfig["rootCerts"];
static set rootCerts(newValue: NeonConfig['rootCerts']);
get rootCerts(): NeonConfig["rootCerts"];
set rootCerts(newValue: NeonConfig['rootCerts']);
wsProxyAddrForHost(host: string, port: number): string;
connecting: boolean;
pending: boolean;
writable: boolean;
encrypted: boolean;
authorized: boolean;
destroyed: boolean;
setNoDelay(): this;
setKeepAlive(): this;
ref(): this;
unref(): this;
connect(port: number | string, host: string, connectListener?: () => void): void;
startTls(host: string): Promise<void>;
tlsReadLoop(): Promise<void>;
rawWrite(data: Uint8Array): void;
write(data: Buffer | string, encoding?: string, callback?: (err?: any) => void): boolean;
end(data?: Buffer | string, encoding?: string, callback?: () => void): this;
destroy(): this;
}
export declare type NeonConfigGlobalAndClient = Omit<NeonConfig, keyof NeonConfigGlobalOnly>;
export declare type NeonConfigGlobalOnly = Pick<NeonConfig, 'fetchEndpoint' | 'poolQueryViaFetch' | 'fetchConnectionCache' | 'fetchFunction'>;
export declare class NeonDbError extends Error {
name: "NeonDbError";
severity: string | undefined;
code: string | undefined;
detail: string | undefined;
hint: string | undefined;
position: string | undefined;
internalPosition: string | undefined;
internalQuery: string | undefined;
where: string | undefined;
schema: string | undefined;
table: string | undefined;
column: string | undefined;
dataType: string | undefined;
constraint: string | undefined;
file: string | undefined;
line: string | undefined;
routine: string | undefined;
sourceError: Error | undefined;
constructor(message: string);
}
export declare interface NeonQueryFunction<ArrayMode extends boolean, FullResults extends boolean> {
(strings: TemplateStringsArray, ...params: any[]): NeonQueryPromise<ArrayMode, FullResults, FullResults extends true ? FullQueryResults<ArrayMode> : QueryRows<ArrayMode>>;
<ArrayModeOverride extends boolean = ArrayMode, FullResultsOverride extends boolean = FullResults>(string: string, params?: any[], opts?: HTTPQueryOptions<ArrayModeOverride, FullResultsOverride>): NeonQueryPromise<ArrayModeOverride, FullResultsOverride, FullResultsOverride extends true ? FullQueryResults<ArrayModeOverride> : QueryRows<ArrayModeOverride>>;
/**
* The `transaction()` function allows multiple queries to be submitted (over
* HTTP) as a single, non-interactive Postgres transaction.
*
* For example:
* ```
* import { neon } from "@neondatabase/serverless";
* const sql = neon("postgres://user:pass@host/db");
*
* const results = await sql.transaction([
* sql`SELECT 1 AS num`,
* sql`SELECT 'a' AS str`,
* ]);
* // -> [[{ num: 1 }], [{ str: "a" }]]
*
* // or equivalently:
* const results = await sql.transaction(txn => [
* txn`SELECT 1 AS num`,
* txn`SELECT 'a' AS str`,
* ]);
* // -> [[{ num: 1 }], [{ str: "a" }]]
* ```
* @param queriesOrFn - Either an array of queries, or a (non-`async`) function
* that receives a query function and returns an array of queries.
* @param opts - The same options that may be set on individual queries in a
* non-transaction setting -- that is, `arrayMode` `fullResults` and
* `fetchOptions` -- plus the transaction options `isolationLevel`,
* `readOnly` and `deferrable`. Note that none of these options can be set on
* individual queries within a transaction.
* @returns An array of results. The structure of each result object depends
* on the `arrayMode` and `fullResults` options.
*/
transaction: <ArrayModeOverride extends boolean = ArrayMode, FullResultsOverride extends boolean = FullResults>(queriesOrFn: NeonQueryPromise<ArrayMode, FullResults>[] | ((sql: NeonQueryFunctionInTransaction<ArrayModeOverride, FullResultsOverride>) => NeonQueryInTransaction[]), opts?: HTTPTransactionOptions<ArrayModeOverride, FullResultsOverride>) => Promise<FullResultsOverride extends true ? FullQueryResults<ArrayModeOverride>[] : QueryRows<ArrayModeOverride>[]>;
}
export declare interface NeonQueryFunctionInTransaction<ArrayMode extends boolean, FullResults extends boolean> {
(strings: TemplateStringsArray, ...params: any[]): NeonQueryPromise<ArrayMode, FullResults, FullResults extends true ? FullQueryResults<ArrayMode> : QueryRows<ArrayMode>>;
(string: string, params?: any[]): NeonQueryPromise<ArrayMode, FullResults, FullResults extends true ? FullQueryResults<ArrayMode> : QueryRows<ArrayMode>>;
}
export declare interface NeonQueryInTransaction {
parameterizedQuery: ParameterizedQuery;
}
export declare interface NeonQueryPromise<ArrayMode extends boolean, FullResults extends boolean, T = any> extends Promise<T> {
parameterizedQuery: ParameterizedQuery;
opts?: HTTPQueryOptions<ArrayMode, FullResults>;
}
export { Notification }
declare type OID = string;
export declare interface ParameterizedQuery {
query: string;
params: any[];
}
export declare interface Pool {
Promise: typeof Promise;
}
/**
* The node-postgres `Pool` object re-exported with minor modifications.
* https://node-postgres.com/apis/pool
*/
export declare class Pool extends Pool_2 {
Client: typeof Client;
hasFetchUnsupportedListeners: boolean;
on(event: 'error' | 'connect' | 'acquire' | 'release' | 'remove', listener: any): this;
addListener: (event: "error" | "connect" | "acquire" | "release" | "remove", listener: any) => this;
query<T extends Submittable>(queryStream: T): T;
query<R extends any[] = any[], I = any[]>(queryConfig: QueryArrayConfig<I>, values?: QueryConfigValues<I>): Promise<QueryArrayResult<R>>;
query<R extends QueryResultRow = any, I = any[]>(queryConfig: QueryConfig<I>): Promise<QueryResult<R>>;
query<R extends QueryResultRow = any, I = any[]>(queryTextOrConfig: string | QueryConfig<I>, values?: QueryConfigValues<I>): Promise<QueryResult<R>>;
query<R extends any[] = any[], I = any[]>(queryConfig: QueryArrayConfig<I>, callback: (err: Error, result: QueryArrayResult<R>) => void): void;
query<R extends QueryResultRow = any, I = any[]>(queryTextOrConfig: string | QueryConfig<I>, callback: (err: Error, result: QueryResult<R>) => void): void;
query<R extends QueryResultRow = any, I = any[]>(queryText: string, values: QueryConfigValues<I>, callback: (err: Error, result: QueryResult<R>) => void): void;
}
export declare interface PoolClient extends PoolClient_2 {
neonConfig: NeonConfigGlobalAndClient;
}
export { PoolConfig }
export declare interface ProcessQueryResultOptions {
arrayMode: boolean;
fullResults: boolean;
parameterizedQuery: ParameterizedQuery;
resultCallback: HTTPQueryOptions<false, false>['resultCallback'];
types?: typeof types;
}
export { Query }
export { QueryArrayConfig }
export { QueryArrayResult }
export { QueryConfig }
export { QueryParse }
export { QueryResult }
export { QueryResultBase }
export { QueryResultRow }
export declare type QueryRows<ArrayMode extends boolean> = ArrayMode extends true ? any[][] : Record<string, any>[];
declare enum ReadMode {
CONSUME = 0,
PEEK = 1
}
declare abstract class ReadQueue {
queue: Uint8Array[];
outstandingRequest: DataRequest | undefined;
constructor();
abstract moreDataMayFollow(): boolean;
enqueue(data: Uint8Array): void;
dequeue(): void;
bytesInQueue(): number;
read(bytes: number, readMode?: ReadMode): Promise<Uint8Array<ArrayBufferLike> | undefined>;
}
export { ResultBuilder }
declare type RootCertsData = Uint8Array;
declare interface RootCertsDatabase {
index: RootCertsIndex;
data: RootCertsData;
}
declare interface RootCertsIndex {
offsets: number[];
subjects: Record<string, number>;
}
export declare function startTls(host: string, rootCertsDatabase: RootCertsDatabase | string, networkRead: (bytes: number) => Promise<Uint8Array | undefined>, networkWrite: (data: Uint8Array) => void, { useSNI, requireServerTlsExtKeyUsage, requireDigitalSigKeyUsage, writePreData, expectPreData, commentPreData }?: {
useSNI?: boolean;
requireServerTlsExtKeyUsage?: boolean;
requireDigitalSigKeyUsage?: boolean;
writePreData?: Uint8Array;
expectPreData?: Uint8Array;
commentPreData?: string;
}): Promise<{
readonly read: () => Promise<Uint8Array<ArrayBufferLike> | undefined>;
readonly write: (data: Uint8Array) => Promise<void>;
readonly userCert: Cert;
}>;
export { Submittable }
export declare interface subtls {
startTls: typeof startTls;
TrustedCert: typeof TrustedCert;
WebSocketReadQueue: typeof WebSocketReadQueue;
}
export declare class TrustedCert extends Cert {
static databaseFromPEM(pem: string): Promise<RootCertsDatabase>;
static findInDatabase(subjectOrSubjectKeyId: DistinguishedName | string, db: RootCertsDatabase): Promise<Cert | undefined>;
}
export { types }
export declare interface WebSocketConstructor {
new (...args: any[]): WebSocketLike;
}
export declare interface WebSocketLike {
readonly readyState: number;
binaryType: string;
close(code?: number, reason?: string): void;
send(data: any): void;
addEventListener(type: 'open' | 'message' | 'close' | 'error', listener: (this: WebSocketLike, ev: any) => any, options?: any): void;
}
export declare class WebSocketReadQueue extends ReadQueue {
constructor(socket: WebSocket);
moreDataMayFollow(): boolean;
}