@steadybrew/postgresjs 4.4.0 → 4.5.0-rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.js CHANGED
@@ -248,6 +248,11 @@ export const inferType = function inferType(x) {
248
248
  )
249
249
  }
250
250
 
251
+ export function clientSerialize(x) {
252
+ const proto = typeof x === 'object' && Object.getPrototypeOf(x)
253
+ return proto === Object.prototype || proto === null ? JSON.stringify(x) : '' + x
254
+ }
255
+
251
256
  const escapeBackslash = /\\/g
252
257
  const escapeQuote = /"/g
253
258
 
package/types/index.d.ts CHANGED
@@ -110,6 +110,10 @@ interface BaseOptions<T extends Record<string, postgres.PostgresType>> {
110
110
  * @default true
111
111
  */
112
112
  fetch_types: boolean;
113
+ /** How values whose type cannot be told from the JavaScript value are serialized: 'server' (default) asks PostgreSQL for the placeholder's type first, 'client' sends their text for PostgreSQL to parse, 'warn' does the same as 'server' and reports values 'client' would send differently */
114
+ parameter_types: 'server' | 'client' | 'warn';
115
+ /** Called in parameter_types: 'warn' mode with each query whose values would be sent differently, console.warn by default; if it throws, the error is rethrown as an uncaught exception */
116
+ ontypemismatch: (report: postgres.TypeMismatchReport) => void;
113
117
  /**
114
118
  * Publications to subscribe to (only relevant when calling `sql.subscribe()`)
115
119
  * @default 'alltables'
@@ -411,6 +415,23 @@ declare namespace postgres {
411
415
  };
412
416
  }
413
417
 
418
+ interface TypeMismatchReport {
419
+ query: string;
420
+ parameters: TypeMismatch[];
421
+ }
422
+
423
+ interface TypeMismatch {
424
+ /** The `$n` number of the placeholder */
425
+ position: number;
426
+ /** The type OID PostgreSQL inferred for the placeholder */
427
+ oid: number;
428
+ typeof: string;
429
+ /** Only set when debug is enabled */
430
+ serverText?: string;
431
+ /** Only set when debug is enabled; the error is what the 'client' mode would throw */
432
+ clientText?: string | globalThis.Error;
433
+ }
434
+
414
435
  interface Notice {
415
436
  [field: string]: string;
416
437
  }
@@ -742,6 +763,9 @@ declare namespace postgres {
742
763
 
743
764
  end(options?: { timeout?: number | undefined } | undefined): Promise<void>;
744
765
 
766
+ /** Calls `end()` with no timeout when an `await using` scope exits */
767
+ [Symbol.asyncDispose](): Promise<void>;
768
+
745
769
  listen(channel: string, onnotify: (value: string) => void, onlisten?: (() => void) | undefined): ListenRequest;
746
770
 
747
771
  /** `onerror` receives replication connection errors and errors thrown while a change is decoded; such a change is skipped. */
@@ -767,6 +791,12 @@ declare namespace postgres {
767
791
 
768
792
  interface ReservedSql<TTypes extends Record<string, unknown> = {}> extends Sql<TTypes> {
769
793
  release(): void;
794
+
795
+ /** Calls `release()` when a `using` scope exits */
796
+ [Symbol.dispose](): void;
797
+
798
+ /** Calls `release()` when an `await using` scope exits */
799
+ [Symbol.asyncDispose](): Promise<void>;
770
800
  }
771
801
  }
772
802
 
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "devDependencies": {
3
- "@types/node": "^16"
3
+ "@types/node": "^22"
4
4
  }
5
5
  }