@@ -112,7 +112,7 @@ interface BaseOptions<T extends JSToPostgresTypeMap> {
112
112
*/
113
113
publications : string
114
114
onclose : ( connId : number ) => void ;
115
- backoff : boolean | ( ( attemptNum :number ) => number ) ;
115
+ backoff : boolean | ( ( attemptNum : number ) => number ) ;
116
116
max_lifetime : number | null ;
117
117
keep_alive : number | null ;
118
118
}
@@ -157,7 +157,7 @@ type Keys = string
157
157
158
158
type SerializableObject < T , K extends any [ ] > =
159
159
number extends K [ 'length' ] ? { } :
160
- Record < Keys & ( keyof T ) & ( K [ 'length' ] extends 0 ? string : K [ number ] ) , postgres . SerializableParameter >
160
+ ( Record < Keys & ( keyof T ) & ( K [ 'length' ] extends 0 ? string : K [ number ] ) , postgres . SerializableParameter | postgres . JSONValue > & Record < string , any > )
161
161
162
162
type First < T , K extends any [ ] > =
163
163
// Tagged template string call
@@ -167,9 +167,9 @@ type First<T, K extends any[]> =
167
167
// Dynamic values helper (depth 2)
168
168
T extends readonly any [ ] [ ] ? postgres . EscapableArray [ ] :
169
169
// Insert/update helper (depth 2)
170
- T extends ( object & infer R ) [ ] ? SerializableObject < R , K > [ ] :
171
- // Dynamic values helper (depth 1)
172
- T extends readonly any [ ] ? postgres . EscapableArray :
170
+ T extends readonly ( object & infer R ) [ ] ? ( R extends postgres . SerializableParameter ? readonly postgres . SerializableParameter [ ] : readonly SerializableObject < R , K > [ ] ) :
171
+ // Dynamic values/ANY helper (depth 1)
172
+ T extends readonly any [ ] ? ( readonly postgres . SerializableParameter [ ] ) :
173
173
// Insert/update helper (depth 1)
174
174
T extends object ? SerializableObject < T , K > :
175
175
// Unexpected type
@@ -179,7 +179,7 @@ type Rest<T> =
179
179
T extends TemplateStringsArray ? never : // force fallback to the tagged template function overload
180
180
T extends string ? string [ ] :
181
181
T extends readonly any [ ] [ ] ? [ ] :
182
- T extends ( object & infer R ) [ ] ? ( Keys & keyof R ) [ ] :
182
+ T extends readonly ( object & infer R ) [ ] ? ( Keys & keyof R ) [ ] :
183
183
T extends readonly any [ ] ? [ ] :
184
184
T extends object ? ( Keys & keyof T ) [ ] :
185
185
any
@@ -454,10 +454,10 @@ declare namespace postgres {
454
454
| null
455
455
| boolean
456
456
| number
457
+ | bigint // weak: require the `postgres.BigInt` type
457
458
| string
458
459
| Date
459
- | Uint8Array
460
- | bigint ;
460
+ | Uint8Array ;
461
461
462
462
type SerializableParameter = never
463
463
| Serializable
@@ -466,6 +466,20 @@ declare namespace postgres {
466
466
| ArrayParameter
467
467
| readonly SerializableParameter [ ] ;
468
468
469
+ type JSONValue = // using a dedicated type to detect symbols, bigints, and other non serializable types
470
+ | null
471
+ | string
472
+ | number
473
+ | Date // serialized as `string`
474
+ | JSONValue [ ]
475
+ | { toJSON ( ) : any } // `toJSON` called by `JSON.stringify`; not typing the return type, typings is strict enough anyway
476
+ | {
477
+ [ prop : string | number ] :
478
+ | undefined
479
+ | JSONValue
480
+ | ( ( ...args : any ) => any ) // serialized as `undefined`
481
+ } ;
482
+
469
483
interface Row {
470
484
[ column : string ] : any ;
471
485
}
@@ -574,7 +588,7 @@ declare namespace postgres {
574
588
* @param parameters Interpoled values of the template string
575
589
* @returns A promise resolving to the result of your query
576
590
*/
577
- < T extends readonly any [ ] = Row [ ] > ( template : TemplateStringsArray , ...parameters : ( SerializableParameter | PendingQuery < any > ) [ ] ) : PendingQuery < AsRowList < T > > ;
591
+ < T extends readonly object [ ] = Row [ ] > ( template : TemplateStringsArray , ...parameters : ( SerializableParameter | PendingQuery < any > ) [ ] ) : PendingQuery < AsRowList < T > > ;
578
592
579
593
CLOSE : { } ;
580
594
END : this[ 'CLOSE' ] ;
@@ -604,7 +618,7 @@ declare namespace postgres {
604
618
array < T extends SerializableParameter [ ] = SerializableParameter [ ] > ( value : T , type ?: number ) : ArrayParameter < T > ;
605
619
file < T extends readonly any [ ] = Row [ ] > ( path : string | Buffer | URL | number , options ?: { cache ?: boolean } ) : PendingQuery < AsRowList < T > > ;
606
620
file < T extends readonly any [ ] = Row [ ] > ( path : string | Buffer | URL | number , args : SerializableParameter [ ] , options ?: { cache ?: boolean } ) : PendingQuery < AsRowList < T > > ;
607
- json ( value : any ) : Parameter ;
621
+ json ( value : JSONValue ) : Parameter ;
608
622
}
609
623
610
624
interface UnsafeQueryOptions {
0 commit comments