postgrejs 3.11.1 → 3.12.1

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.
Files changed (187) hide show
  1. package/connection/bind-param.d.ts +21 -0
  2. package/connection/bind-param.js +21 -0
  3. package/connection/connection.d.ts +136 -0
  4. package/connection/connection.js +132 -5
  5. package/connection/copy-stream.d.ts +2 -0
  6. package/connection/copy-stream.js +2 -0
  7. package/connection/cursor.d.ts +67 -5
  8. package/connection/cursor.js +88 -15
  9. package/connection/intl-connection.d.ts +22 -0
  10. package/connection/intl-connection.js +107 -17
  11. package/connection/large-object.d.ts +18 -0
  12. package/connection/large-object.js +17 -0
  13. package/connection/logical-replication.d.ts +15 -0
  14. package/connection/logical-replication.js +6 -0
  15. package/connection/pool.d.ts +80 -0
  16. package/connection/pool.js +82 -9
  17. package/connection/portal.d.ts +37 -0
  18. package/connection/portal.js +29 -0
  19. package/connection/prepared-statement.d.ts +109 -0
  20. package/connection/prepared-statement.js +150 -7
  21. package/constants.d.ts +18 -0
  22. package/constants.js +18 -0
  23. package/data-type-map.d.ts +38 -0
  24. package/data-type-map.js +38 -0
  25. package/data-types/bit-type.d.ts +4 -0
  26. package/data-types/bit-type.js +4 -0
  27. package/data-types/bool-type.d.ts +2 -0
  28. package/data-types/bool-type.js +2 -0
  29. package/data-types/box-type.d.ts +2 -0
  30. package/data-types/box-type.js +2 -0
  31. package/data-types/bytea-type.d.ts +2 -0
  32. package/data-types/bytea-type.js +2 -0
  33. package/data-types/char-type.d.ts +2 -0
  34. package/data-types/char-type.js +2 -0
  35. package/data-types/circle-type.d.ts +2 -0
  36. package/data-types/circle-type.js +2 -0
  37. package/data-types/date-type.d.ts +2 -0
  38. package/data-types/date-type.js +2 -0
  39. package/data-types/float4-type.d.ts +2 -0
  40. package/data-types/float4-type.js +2 -0
  41. package/data-types/float8-type.d.ts +2 -0
  42. package/data-types/float8-type.js +2 -0
  43. package/data-types/inet-type.d.ts +4 -0
  44. package/data-types/inet-type.js +4 -0
  45. package/data-types/int2-type.d.ts +2 -0
  46. package/data-types/int2-type.js +3 -1
  47. package/data-types/int2-vector-type.d.ts +2 -0
  48. package/data-types/int2-vector-type.js +2 -0
  49. package/data-types/int4-type.d.ts +2 -0
  50. package/data-types/int4-type.js +3 -1
  51. package/data-types/int8-type.d.ts +2 -0
  52. package/data-types/int8-type.js +4 -2
  53. package/data-types/interval-type.d.ts +9 -0
  54. package/data-types/interval-type.js +9 -0
  55. package/data-types/json-type.d.ts +2 -0
  56. package/data-types/json-type.js +2 -0
  57. package/data-types/jsonb-type.d.ts +2 -0
  58. package/data-types/jsonb-type.js +2 -0
  59. package/data-types/jsonpath-type.d.ts +2 -0
  60. package/data-types/jsonpath-type.js +2 -0
  61. package/data-types/line-type.d.ts +2 -0
  62. package/data-types/line-type.js +2 -0
  63. package/data-types/lseg-type.d.ts +2 -0
  64. package/data-types/lseg-type.js +2 -0
  65. package/data-types/macaddr-type.d.ts +4 -0
  66. package/data-types/macaddr-type.js +4 -0
  67. package/data-types/money-type.d.ts +1 -0
  68. package/data-types/money-type.js +17 -10
  69. package/data-types/numeric-type.d.ts +2 -0
  70. package/data-types/numeric-type.js +2 -0
  71. package/data-types/oid-type.d.ts +2 -0
  72. package/data-types/oid-type.js +3 -1
  73. package/data-types/oid-vector-type.d.ts +1 -0
  74. package/data-types/oid-vector-type.js +1 -0
  75. package/data-types/path-type.d.ts +4 -0
  76. package/data-types/path-type.js +4 -0
  77. package/data-types/pg-lsn-type.d.ts +2 -0
  78. package/data-types/pg-lsn-type.js +2 -0
  79. package/data-types/point-type.d.ts +2 -0
  80. package/data-types/point-type.js +2 -0
  81. package/data-types/range-type.d.ts +4 -0
  82. package/data-types/range-type.js +4 -0
  83. package/data-types/snapshot-type.d.ts +4 -0
  84. package/data-types/snapshot-type.js +4 -0
  85. package/data-types/tid-type.d.ts +2 -0
  86. package/data-types/tid-type.js +2 -0
  87. package/data-types/time-type.d.ts +2 -0
  88. package/data-types/time-type.js +2 -0
  89. package/data-types/timestamp-type.d.ts +2 -0
  90. package/data-types/timestamp-type.js +2 -0
  91. package/data-types/timestamptz-type.d.ts +2 -0
  92. package/data-types/timestamptz-type.js +2 -0
  93. package/data-types/timetz-type.d.ts +2 -0
  94. package/data-types/timetz-type.js +2 -0
  95. package/data-types/tsvector-type.d.ts +4 -0
  96. package/data-types/tsvector-type.js +4 -0
  97. package/data-types/uuid-type.d.ts +2 -0
  98. package/data-types/uuid-type.js +2 -0
  99. package/data-types/varchar-type.d.ts +2 -0
  100. package/data-types/varchar-type.js +2 -0
  101. package/data-types/xid-type.d.ts +6 -0
  102. package/data-types/xid-type.js +8 -1
  103. package/interfaces/command-result.d.ts +7 -0
  104. package/interfaces/copy-from-rows-options.d.ts +4 -0
  105. package/interfaces/data-mapping-options.d.ts +6 -0
  106. package/interfaces/data-type.d.ts +37 -0
  107. package/interfaces/database-connection-params.d.ts +31 -0
  108. package/interfaces/field-info.d.ts +8 -0
  109. package/interfaces/function-call-options.d.ts +1 -0
  110. package/interfaces/function-call-result.d.ts +6 -0
  111. package/interfaces/pipeline-request.d.ts +2 -0
  112. package/interfaces/query-options.d.ts +7 -0
  113. package/interfaces/query-result.d.ts +7 -0
  114. package/interfaces/script-execute-options.d.ts +4 -0
  115. package/interfaces/script-result.d.ts +1 -0
  116. package/interfaces/statement-prepare-options.d.ts +1 -0
  117. package/package.json +5 -5
  118. package/protocol/backend.d.ts +6 -0
  119. package/protocol/backend.js +35 -5
  120. package/protocol/cert-signature.d.ts +8 -0
  121. package/protocol/cert-signature.js +8 -0
  122. package/protocol/database-error.d.ts +8 -0
  123. package/protocol/database-error.js +8 -0
  124. package/protocol/frontend.d.ts +16 -0
  125. package/protocol/frontend.js +13 -6
  126. package/protocol/pg-socket.d.ts +10 -0
  127. package/protocol/pg-socket.js +14 -7
  128. package/protocol/pgoutput.d.ts +15 -0
  129. package/protocol/pgoutput.js +7 -0
  130. package/protocol/protocol.d.ts +50 -2
  131. package/protocol/protocol.js +17 -1
  132. package/protocol/sasl.d.ts +22 -0
  133. package/protocol/sasl.js +21 -0
  134. package/protocol/smart-buffer.d.ts +4 -0
  135. package/safe-event-emitter.d.ts +7 -0
  136. package/safe-event-emitter.js +7 -0
  137. package/types.d.ts +21 -0
  138. package/util/array-calculatedim.d.ts +10 -0
  139. package/util/array-calculatedim.js +10 -0
  140. package/util/assert-integer.d.ts +40 -25
  141. package/util/assert-integer.js +97 -32
  142. package/util/bigint-methods.d.ts +7 -0
  143. package/util/bigint-methods.js +9 -0
  144. package/util/config-from-env.d.ts +10 -0
  145. package/util/config-from-env.js +10 -0
  146. package/util/connection-config.d.ts +17 -0
  147. package/util/connection-config.js +17 -0
  148. package/util/copy-from-rows.d.ts +12 -0
  149. package/util/copy-from-rows.js +9 -0
  150. package/util/decimal-as-string.d.ts +6 -0
  151. package/util/decimal-as-string.js +6 -0
  152. package/util/decode-binaryarray.d.ts +9 -0
  153. package/util/decode-binaryarray.js +9 -0
  154. package/util/escape-literal.d.ts +11 -0
  155. package/util/escape-literal.js +13 -0
  156. package/util/fast-parseint.d.ts +14 -0
  157. package/util/fast-parseint.js +14 -0
  158. package/util/format-datetime.d.ts +26 -0
  159. package/util/format-datetime.js +26 -0
  160. package/util/get-parsers.d.ts +9 -0
  161. package/util/get-parsers.js +9 -0
  162. package/util/hex-text.d.ts +13 -21
  163. package/util/hex-text.js +24 -21
  164. package/util/local-date.d.ts +2 -41
  165. package/util/local-date.js +39 -41
  166. package/util/parse-array.d.ts +8 -0
  167. package/util/parse-array.js +8 -0
  168. package/util/parse-bytea.d.ts +15 -0
  169. package/util/parse-bytea.js +15 -0
  170. package/util/parse-datetime.d.ts +26 -0
  171. package/util/parse-datetime.js +26 -0
  172. package/util/parse-row.d.ts +23 -2
  173. package/util/parse-row.js +56 -36
  174. package/util/parse-time.d.ts +10 -0
  175. package/util/parse-time.js +10 -0
  176. package/util/resolve-column-formats.d.ts +1 -0
  177. package/util/row-decoder.d.ts +32 -0
  178. package/util/row-decoder.js +22 -0
  179. package/util/stringify-arrayliteral.d.ts +33 -0
  180. package/util/stringify-arrayliteral.js +242 -7
  181. package/util/stringify-for-sql.d.ts +17 -0
  182. package/util/stringify-for-sql.js +17 -0
  183. package/util/unspecified-param.d.ts +26 -2
  184. package/util/unspecified-param.js +26 -2
  185. package/util/wrap-row-description.d.ts +10 -0
  186. package/util/wrap-row-description.js +10 -0
  187. package/CHANGELOG.md +0 -1426
@@ -11,6 +11,7 @@ import { DataTypeOIDs } from '../constants.js';
11
11
  * leaves it a string too.
12
12
  */
13
13
  const TID_PATTERN = /^\(\s*(\d+)\s*,\s*(\d+)\s*\)$/;
14
+ /** `tid`, a physical row address, as the `(block,offset)` text the server prints. */
14
15
  export const TidType = {
15
16
  name: 'tid',
16
17
  oid: DataTypeOIDs.tid,
@@ -42,6 +43,7 @@ export const TidType = {
42
43
  return typeof v === 'string' && TID_PATTERN.test(v);
43
44
  },
44
45
  };
46
+ /** The `_tid` array of {@link TidType}. */
45
47
  export const ArrayTidType = {
46
48
  ...TidType,
47
49
  name: '_tid',
@@ -1,3 +1,5 @@
1
1
  import type { DataType } from '../interfaces/data-type.js';
2
+ /** `time`, as a `Date` on the epoch day carrying that clock time. */
2
3
  export declare const TimeType: DataType;
4
+ /** The `_time` array of {@link TimeType}. */
3
5
  export declare const ArrayTimeType: DataType;
@@ -3,6 +3,7 @@ import { formatTime } from '../util/format-datetime.js';
3
3
  import { utcPartsAsLocal } from '../util/local-date.js';
4
4
  import { parseTime, STRICT_TIME_PATTERN } from '../util/parse-time.js';
5
5
  const timeMul = 4294967296;
6
+ /** `time`, as a `Date` on the epoch day carrying that clock time. */
6
7
  export const TimeType = {
7
8
  name: 'time',
8
9
  oid: DataTypeOIDs.time,
@@ -46,6 +47,7 @@ export const TimeType = {
46
47
  (typeof v === 'string' && STRICT_TIME_PATTERN.test(v)));
47
48
  },
48
49
  };
50
+ /** The `_time` array of {@link TimeType}. */
49
51
  export const ArrayTimeType = {
50
52
  ...TimeType,
51
53
  name: '_time',
@@ -1,3 +1,5 @@
1
1
  import type { DataType } from '../interfaces/data-type.js';
2
+ /** `timestamp` (without time zone), as a `Date` reading that wall clock locally - or in UTC with `utcDates`. */
2
3
  export declare const TimestampType: DataType;
4
+ /** The `_timestamp` array of {@link TimestampType}. */
3
5
  export declare const ArrayTimestampType: DataType;
@@ -5,6 +5,7 @@ import { parseDateTime } from '../util/parse-datetime.js';
5
5
  import { parsePgTimestampBuffer } from '../util/parse-pg-timestamp.js';
6
6
  const timeShift = 946684800000;
7
7
  const timeMul = 4294967296;
8
+ /** `timestamp` (without time zone), as a `Date` reading that wall clock locally - or in UTC with `utcDates`. */
8
9
  export const TimestampType = {
9
10
  name: 'timestamp',
10
11
  oid: DataTypeOIDs.timestamp,
@@ -72,6 +73,7 @@ export const TimestampType = {
72
73
  !(v.getFullYear() === 1970 && v.getMonth() === 0 && v.getDate() === 1));
73
74
  },
74
75
  };
76
+ /** The `_timestamp` array of {@link TimestampType}. */
75
77
  export const ArrayTimestampType = {
76
78
  ...TimestampType,
77
79
  name: '_timestamp',
@@ -1,3 +1,5 @@
1
1
  import type { DataType } from '../interfaces/data-type.js';
2
+ /** `timestamptz`, as a `Date` at the instant it names, which is what the type stores. */
2
3
  export declare const TimestamptzType: DataType;
4
+ /** The `_timestamptz` array of {@link TimestamptzType}. */
3
5
  export declare const ArrayTimestamptzType: DataType;
@@ -5,6 +5,7 @@ import { parseDateTimeTz } from '../util/parse-datetime.js';
5
5
  import { parsePgTimestampBuffer } from '../util/parse-pg-timestamp.js';
6
6
  const timeShift = 946684800000;
7
7
  const timeMul = 4294967296;
8
+ /** `timestamptz`, as a `Date` at the instant it names, which is what the type stores. */
8
9
  export const TimestamptzType = {
9
10
  name: 'timestamptz',
10
11
  oid: DataTypeOIDs.timestamptz,
@@ -80,6 +81,7 @@ export const TimestamptzType = {
80
81
  return v instanceof Date;
81
82
  },
82
83
  };
84
+ /** The `_timestamptz` array of {@link TimestamptzType}. */
83
85
  export const ArrayTimestamptzType = {
84
86
  ...TimestamptzType,
85
87
  name: '_timestamptz',
@@ -1,3 +1,5 @@
1
1
  import type { DataType } from '../interfaces/data-type.js';
2
+ /** `timetz`, as a string: the clock time and its offset, which a `Date` has nowhere to keep. */
2
3
  export declare const TimeTzType: DataType;
4
+ /** The `_timetz` array of {@link TimeTzType}. */
3
5
  export declare const ArrayTimeTzType: DataType;
@@ -117,6 +117,7 @@ function formatTimeTz(micros, zone) {
117
117
  out += ':' + pad(zs);
118
118
  return out;
119
119
  }
120
+ /** `timetz`, as a string: the clock time and its offset, which a `Date` has nowhere to keep. */
120
121
  export const TimeTzType = {
121
122
  name: 'timetz',
122
123
  oid: DataTypeOIDs.timetz,
@@ -176,6 +177,7 @@ export const TimeTzType = {
176
177
  }
177
178
  },
178
179
  };
180
+ /** The `_timetz` array of {@link TimeTzType}. */
179
181
  export const ArrayTimeTzType = {
180
182
  ...TimeTzType,
181
183
  name: '_timetz',
@@ -1,5 +1,9 @@
1
1
  import type { DataType } from '../interfaces/data-type.js';
2
+ /** `tsvector`, as its own text - the lexemes with their positions and weights. */
2
3
  export declare const TsVectorType: DataType;
4
+ /** The `_tsvector` array of {@link TsVectorType}. */
3
5
  export declare const ArrayTsVectorType: DataType;
6
+ /** `tsquery`, as its own text. */
4
7
  export declare const TsQueryType: DataType;
8
+ /** The `_tsquery` array of {@link TsQueryType}. */
5
9
  export declare const ArrayTsQueryType: DataType;
@@ -170,6 +170,7 @@ function printQuery(node, parentPriority, rightPhraseOp) {
170
170
  ? '( ' + out + ' )'
171
171
  : out;
172
172
  }
173
+ /** `tsvector`, as its own text - the lexemes with their positions and weights. */
173
174
  export const TsVectorType = {
174
175
  name: 'tsvector',
175
176
  oid: DataTypeOIDs.tsvector,
@@ -190,12 +191,14 @@ export const TsVectorType = {
190
191
  return typeof v === 'string';
191
192
  },
192
193
  };
194
+ /** The `_tsvector` array of {@link TsVectorType}. */
193
195
  export const ArrayTsVectorType = {
194
196
  ...TsVectorType,
195
197
  name: '_tsvector',
196
198
  oid: DataTypeOIDs._tsvector,
197
199
  elementsOID: DataTypeOIDs.tsvector,
198
200
  };
201
+ /** `tsquery`, as its own text. */
199
202
  export const TsQueryType = {
200
203
  ...TsVectorType,
201
204
  name: 'tsquery',
@@ -208,6 +211,7 @@ export const TsQueryType = {
208
211
  return printQuery(readQueryNode(v, { p: offset + 4 }), 0, false);
209
212
  },
210
213
  };
214
+ /** The `_tsquery` array of {@link TsQueryType}. */
211
215
  export const ArrayTsQueryType = {
212
216
  ...TsQueryType,
213
217
  name: '_tsquery',
@@ -1,3 +1,5 @@
1
1
  import type { DataType } from '../interfaces/data-type.js';
2
+ /** `uuid`, as its canonical 36-character text. */
2
3
  export declare const UuidType: DataType;
4
+ /** The `_uuid` array of {@link UuidType}. */
3
5
  export declare const ArrayUuidType: DataType;
@@ -11,6 +11,7 @@ TEXT[8] = TEXT[13] = TEXT[18] = TEXT[23] = 45; /* - */
11
11
  /** Where each of the sixteen bytes writes its two characters. */
12
12
  const POSITIONS = [0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34];
13
13
  const GUID_PATTERN = /^[0-9a-fA-F]{8}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{12}$/;
14
+ /** `uuid`, as its canonical 36-character text. */
14
15
  export const UuidType = {
15
16
  name: 'uuid',
16
17
  oid: DataTypeOIDs.uuid,
@@ -41,6 +42,7 @@ export const UuidType = {
41
42
  return typeof v === 'string' && GUID_PATTERN.test(v);
42
43
  },
43
44
  };
45
+ /** The `_uuid` array of {@link UuidType}. */
44
46
  export const ArrayUuidType = {
45
47
  ...UuidType,
46
48
  name: '_uuid',
@@ -1,3 +1,5 @@
1
1
  import type { DataType } from '../interfaces/data-type.js';
2
+ /** `varchar`, `text`, `name` and the other string types, as strings. */
2
3
  export declare const VarcharType: DataType;
4
+ /** The `_varchar` array of {@link VarcharType}. */
3
5
  export declare const ArrayVarcharType: DataType;
@@ -1,4 +1,5 @@
1
1
  import { DataTypeOIDs } from '../constants.js';
2
+ /** `varchar`, `text`, `name` and the other string types, as strings. */
2
3
  export const VarcharType = {
3
4
  name: 'varchar',
4
5
  oid: DataTypeOIDs.varchar,
@@ -28,6 +29,7 @@ export const VarcharType = {
28
29
  return typeof v === 'string';
29
30
  },
30
31
  };
32
+ /** The `_varchar` array of {@link VarcharType}. */
31
33
  export const ArrayVarcharType = {
32
34
  ...VarcharType,
33
35
  name: '_varchar',
@@ -1,7 +1,13 @@
1
1
  import type { DataType } from '../interfaces/data-type.js';
2
+ /** `xid`, a 32-bit transaction id, as a number. */
2
3
  export declare const XidType: DataType;
4
+ /** The `_xid` array of {@link XidType}. */
3
5
  export declare const ArrayXidType: DataType;
6
+ /** `cid`, a command id within a transaction, as a number. */
4
7
  export declare const CidType: DataType;
8
+ /** The `_cid` array of {@link CidType}. */
5
9
  export declare const ArrayCidType: DataType;
10
+ /** `xid8`, the 64-bit transaction id, as a number while one is exact and a `BigInt` beyond. */
6
11
  export declare const Xid8Type: DataType;
12
+ /** The `_xid8` array of {@link Xid8Type}. */
7
13
  export declare const ArrayXid8Type: DataType;
@@ -1,4 +1,5 @@
1
1
  import { DataTypeOIDs } from '../constants.js';
2
+ import { assertInteger } from '../util/assert-integer.js';
2
3
  import { fastParseInt, fastParseIntBuffer } from '../util/fast-parseint.js';
3
4
  /**
4
5
  * `xid`, `xid8` and `cid` - the transaction and command counters behind
@@ -41,7 +42,7 @@ function createUInt32Type(name, oid) {
41
42
  return '' + v;
42
43
  },
43
44
  encodeBinary(buf, v) {
44
- buf.writeUInt32BE(fastParseInt(v));
45
+ buf.writeUInt32BE(assertInteger(v, name, 0, 4294967295));
45
46
  },
46
47
  decodeBinary(v, offset = 0) {
47
48
  return v.readUInt32BE(offset);
@@ -56,20 +57,25 @@ function createUInt32Type(name, oid) {
56
57
  },
57
58
  };
58
59
  }
60
+ /** `xid`, a 32-bit transaction id, as a number. */
59
61
  export const XidType = createUInt32Type('xid', DataTypeOIDs.xid);
62
+ /** The `_xid` array of {@link XidType}. */
60
63
  export const ArrayXidType = {
61
64
  ...XidType,
62
65
  name: '_xid',
63
66
  oid: DataTypeOIDs._xid,
64
67
  elementsOID: DataTypeOIDs.xid,
65
68
  };
69
+ /** `cid`, a command id within a transaction, as a number. */
66
70
  export const CidType = createUInt32Type('cid', DataTypeOIDs.cid);
71
+ /** The `_cid` array of {@link CidType}. */
67
72
  export const ArrayCidType = {
68
73
  ...CidType,
69
74
  name: '_cid',
70
75
  oid: DataTypeOIDs._cid,
71
76
  elementsOID: DataTypeOIDs.cid,
72
77
  };
78
+ /** `xid8`, the 64-bit transaction id, as a number while one is exact and a `BigInt` beyond. */
73
79
  export const Xid8Type = {
74
80
  name: 'xid8',
75
81
  oid: DataTypeOIDs.xid8,
@@ -102,6 +108,7 @@ export const Xid8Type = {
102
108
  (typeof v === 'number' && Number.isInteger(v) && v >= 0));
103
109
  },
104
110
  };
111
+ /** The `_xid8` array of {@link Xid8Type}. */
105
112
  export const ArrayXid8Type = {
106
113
  ...Xid8Type,
107
114
  name: '_xid8',
@@ -1,5 +1,12 @@
1
1
  import type { Row } from '../types.js';
2
2
  import type { FieldInfo } from './field-info.js';
3
+ /**
4
+ * What one statement answered with: its rows, what its columns were, and
5
+ * what the server said it did.
6
+ *
7
+ * `QueryResult` is this plus a cursor; a script's results are a list of
8
+ * these, one per statement in it.
9
+ */
3
10
  export interface CommandResult {
4
11
  /**
5
12
  * Name of the command (INSERT, SELECT, UPDATE, etc.)
@@ -1,6 +1,10 @@
1
1
  import type { DataTypeMap } from '../data-type-map.js';
2
2
  import type { OID } from '../types.js';
3
3
  import type { DataMappingOptions } from './data-mapping-options.js';
4
+ /**
5
+ * What `copyFromRows()` takes: which columns the rows line up with, how
6
+ * to encode their values, and how to stop.
7
+ */
4
8
  export interface CopyFromRowsOptions extends DataMappingOptions {
5
9
  /** Type registry used to encode values; defaults to GlobalTypeMap. */
6
10
  typeMap?: DataTypeMap;
@@ -34,6 +34,12 @@ export interface FetchAsStringSelector {
34
34
  */
35
35
  ranges?: boolean;
36
36
  }
37
+ /**
38
+ * How values are turned into JavaScript and back.
39
+ *
40
+ * Set on the connection to apply to everything it runs, or per call to
41
+ * apply to one - a call that says nothing takes the connection's.
42
+ */
37
43
  export interface DataMappingOptions {
38
44
  /**
39
45
  * Decode `numeric` and `money` into the exact decimal string they
@@ -1,11 +1,34 @@
1
1
  import type { DecodeBinaryFunction, DecodeTextBufferFunction, DecodeTextFunction, EncodeAsNullFunction, EncodeBinaryFunction, EncodeCalculateDimFunction, EncodeTextFunction, OID } from '../types.js';
2
+ /**
3
+ * How one PostgreSQL type is read and written.
4
+ *
5
+ * One of these per type in a `DataTypeMap`, and the extension point for
6
+ * a type this client does not know: register it on the global map or on
7
+ * one of a connection's own, and every column and parameter of that OID
8
+ * goes through it.
9
+ *
10
+ * A type needs to decode - both formats, since which one arrives depends
11
+ * on what the column asked for - and needs to encode only what callers
12
+ * will send. Registering the array counterpart is a separate entry, with
13
+ * `elementsOID` pointing back at this one.
14
+ */
2
15
  export interface DataType {
16
+ /** The type's own OID, as `pg_type` gives it. */
3
17
  oid: OID;
18
+ /** The type's name, for `FieldInfo.dataTypeName` and for errors. */
4
19
  name: string;
20
+ /** For an array type, the OID of what it is an array of. */
5
21
  elementsOID?: OID;
22
+ /** Whether this entry is the array counterpart. */
6
23
  isArray?: boolean;
24
+ /** What a decoded value is, named for `FieldInfo.jsType`. */
7
25
  jsType: string;
26
+ /** What separates elements in this type's array literal - a comma for all but `box`. */
8
27
  arraySeparator?: string;
28
+ /**
29
+ * Whether a JavaScript value could be of this type, asked when nothing
30
+ * declared one - see `inferrable` for when it is asked at all.
31
+ */
9
32
  isType: (v: any) => boolean;
10
33
  /**
11
34
  * Whether DataTypeMap.determine() may pick this type for a value, which
@@ -18,12 +41,22 @@ export interface DataType {
18
41
  * `new BindParam(oid, value)`.
19
42
  */
20
43
  inferrable?: boolean;
44
+ /** Reads a value out of the binary wire format. */
21
45
  decodeBinary: DecodeBinaryFunction;
46
+ /** Reads a value out of the text the server rendered. */
22
47
  decodeText: DecodeTextFunction;
48
+ /**
49
+ * Reads a text value straight from the wire buffer, when the type can
50
+ * do better than being handed a string.
51
+ */
23
52
  decodeTextBuffer?: DecodeTextBufferFunction;
53
+ /** Whether a value should go out as SQL NULL rather than be encoded. */
24
54
  encodeAsNull?: EncodeAsNullFunction;
55
+ /** Writes a value in the binary wire format. */
25
56
  encodeBinary?: EncodeBinaryFunction;
57
+ /** Renders a value as the text the server parses. */
26
58
  encodeText?: EncodeTextFunction;
59
+ /** Measures an array's dimensions, for a type whose values are arrays themselves. */
27
60
  encodeCalculateDim?: EncodeCalculateDimFunction;
28
61
  }
29
62
  /**
@@ -35,8 +68,12 @@ export interface DataType {
35
68
  * object of these four numbers is still accepted as a parameter.
36
69
  */
37
70
  export interface Rectangle {
71
+ /** First corner's x. */
38
72
  x1: number;
73
+ /** First corner's y. */
39
74
  y1: number;
75
+ /** Second corner's x. */
40
76
  x2: number;
77
+ /** Second corner's y. */
41
78
  y2: number;
42
79
  }
@@ -4,6 +4,14 @@ import type { SmartBufferConfig } from '../protocol/smart-buffer.js';
4
4
  import type { DebugLogger } from '../types.js';
5
5
  import type { DataMappingOptions } from './data-mapping-options.js';
6
6
  import type { QueryOptions } from './query-options.js';
7
+ /**
8
+ * Where the server is and how to log in.
9
+ *
10
+ * Every field is optional: what is left out is taken from the
11
+ * environment - `PGHOST`, `PGPORT`, `PGUSER`, `PGPASSWORD`, `PGDATABASE`
12
+ * and the rest, the same variables `psql` reads - and what neither
13
+ * gives falls back to PostgreSQL's own defaults.
14
+ */
7
15
  export interface DatabaseConnectionParams {
8
16
  /**
9
17
  * A whole connection string, as an alternative to the fields below -
@@ -15,11 +23,20 @@ export interface DatabaseConnectionParams {
15
23
  * by one that was left in the object.
16
24
  */
17
25
  connectionString?: string;
26
+ /** Host name, IP, or the directory of a unix socket. */
18
27
  host?: string;
28
+ /** Port the server listens on. */
19
29
  port?: number;
30
+ /** Role to connect as. */
20
31
  user?: string;
32
+ /**
33
+ * The password, or a function asked for one when the server wants it -
34
+ * which is where a rotating credential or a secret store goes.
35
+ */
21
36
  password?: string | (() => string | Promise<string>);
37
+ /** Database to connect to. */
22
38
  database?: string;
39
+ /** What this connection calls itself, shown in `pg_stat_activity`. */
23
40
  applicationName?: string;
24
41
  /**
25
42
  * Opens the connection in replication mode, which is what lets it run
@@ -155,8 +172,14 @@ export interface DatabaseConnectionParams {
155
172
  timing?: boolean;
156
173
  debugLogger?: DebugLogger;
157
174
  }
175
+ /**
176
+ * Which server in a list is acceptable, checked after connecting - the
177
+ * same values `libpq` takes, and how a client finds the primary.
178
+ */
158
179
  export type TargetSessionAttrs = 'read-write' | 'read-only' | 'primary' | 'standby' | 'prefer-standby';
180
+ /** Options passed down to the socket itself. */
159
181
  export interface SocketOptions {
182
+ /** Whether TCP keep-alive is turned on. */
160
183
  keepAlive?: boolean;
161
184
  }
162
185
  /**
@@ -169,6 +192,10 @@ export interface SocketOptions {
169
192
  * about - see `fetchAsString` in QueryOptions.
170
193
  */
171
194
  export type ConnectionMappingDefaults = DataMappingOptions & Pick<QueryOptions, 'objectRows' | 'rowDecoder' | 'typeMap' | 'columnFormat'>;
195
+ /**
196
+ * Everything a `Connection` can be given: where the server is, how to
197
+ * talk to it, and the defaults every statement on it inherits.
198
+ */
172
199
  export interface ConnectionConfiguration extends DatabaseConnectionParams, SocketOptions, ConnectionMappingDefaults {
173
200
  buffer?: SmartBufferConfig;
174
201
  /**
@@ -186,6 +213,10 @@ export interface ConnectionConfiguration extends DatabaseConnectionParams, Socke
186
213
  */
187
214
  pipeline?: boolean;
188
215
  }
216
+ /**
217
+ * A connection's configuration, plus how many of them to keep and how
218
+ * long an idle one lives.
219
+ */
189
220
  export interface PoolConfiguration extends ConnectionConfiguration, LPoolConfiguration {
190
221
  /**
191
222
  * How many of Pool.query()'s one-shot queries may share a single pooled
@@ -1,3 +1,11 @@
1
+ /**
2
+ * One column of a result, as the server described it and this client
3
+ * mapped it.
4
+ *
5
+ * The server's half - name, type OID, table and column - comes from the
6
+ * RowDescription; `jsType`, the element type of an array and the fixed
7
+ * size are what the type map made of it.
8
+ */
1
9
  export interface FieldInfo {
2
10
  /**
3
11
  * Name of the field
@@ -1,4 +1,5 @@
1
1
  import type { DataFormat } from '../constants.js';
2
+ /** How a `Connection.callFunction()` sends its arguments and reads back its result. */
2
3
  export interface FunctionCallOptions {
3
4
  /**
4
5
  * Format of each argument, applied positionally - omit for text (the
@@ -1,3 +1,9 @@
1
+ /**
2
+ * What a function call answered with, undecoded.
3
+ *
4
+ * The fast-call protocol says nothing about the return type, so the
5
+ * bytes are handed over as they arrived for the caller to read.
6
+ */
1
7
  export interface FunctionCallResult {
2
8
  /**
3
9
  * The function's return value, in the wire format requested via
@@ -5,7 +5,9 @@ import type { Maybe, OID } from '../types.js';
5
5
  * tagged templates without any conversion.
6
6
  */
7
7
  export interface PipelineRequest {
8
+ /** The statement text. */
8
9
  sql: string;
10
+ /** Its parameters, for `$1`, `$2` and so on. */
9
11
  params?: any[];
10
12
  /**
11
13
  * Parameter type OIDs for this statement. Per statement rather than per
@@ -3,6 +3,13 @@ import type { DataFormat } from '../constants.js';
3
3
  import type { DataTypeMap } from '../data-type-map.js';
4
4
  import type { RowDecoder } from '../util/row-decoder.js';
5
5
  import type { DataMappingOptions } from './data-mapping-options.js';
6
+ /**
7
+ * What `query()` and `execute()` take: the parameters, the shape of the
8
+ * rows, how much of the result to read, and how to stop.
9
+ *
10
+ * Everything a `DataMappingOptions` carries applies here too, and a value
11
+ * left out falls back to the connection's own setting.
12
+ */
6
13
  export interface QueryOptions extends DataMappingOptions {
7
14
  /**
8
15
  * Specifies weather execute query in auto-commit mode
@@ -1,5 +1,12 @@
1
1
  import type { Cursor } from '../connection/cursor.js';
2
2
  import type { CommandResult } from './command-result.js';
3
+ /**
4
+ * What `query()` answered with - a `CommandResult`, plus the cursor when
5
+ * one was asked for.
6
+ *
7
+ * With `cursor: true` the rows are read through `cursor` instead of
8
+ * `rows`, which stays empty.
9
+ */
3
10
  export interface QueryResult extends CommandResult {
4
11
  /**
5
12
  * Cursor instance
@@ -1,6 +1,10 @@
1
1
  import type { DataTypeMap } from '../data-type-map.js';
2
2
  import type { RowDecoder } from '../util/row-decoder.js';
3
3
  import type { DataMappingOptions } from './data-mapping-options.js';
4
+ /**
5
+ * What `execute()` takes for a script of several statements - how much of
6
+ * each result to keep, and how to read the rows it does.
7
+ */
4
8
  export interface ScriptExecuteOptions extends DataMappingOptions {
5
9
  /**
6
10
  * Specifies weather execute query in auto-commit mode
@@ -1,4 +1,5 @@
1
1
  import type { CommandResult } from './command-result.js';
2
+ /** What `execute()` answered with: one result per statement in the script. */
2
3
  export interface ScriptResult {
3
4
  /**
4
5
  * Array of command result for each sql command in the script
@@ -1,5 +1,6 @@
1
1
  import type { DataTypeMap } from '../data-type-map.js';
2
2
  import type { OID } from '../types.js';
3
+ /** What `prepare()` takes: the parameter types to declare, and which type map to read them with. */
3
4
  export interface StatementPrepareOptions {
4
5
  /**
5
6
  * Specifies data type for each parameter
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "postgrejs",
3
3
  "description": "Professional PostgreSQL client NodeJS",
4
- "version": "3.11.1",
4
+ "version": "3.12.1",
5
5
  "author": "Panates",
6
6
  "license": "BSD-3-Clause",
7
7
  "dependencies": {
8
- "@jsopen/objects": "^2.2.3",
8
+ "@jsopen/objects": "^2.3.4",
9
9
  "doublylinked": "^2.5.6",
10
- "flexy-buffer": "^1.1.0",
11
- "lightning-pool": "^4.12.0",
10
+ "flexy-buffer": "^1.1.1",
11
+ "lightning-pool": "^4.14.0",
12
12
  "power-tasks": "^1.14.2",
13
13
  "putil-promisify": "^1.10.1",
14
14
  "putil-varhelpers": "^1.7.0",
@@ -65,4 +65,4 @@
65
65
  "publishConfig": {
66
66
  "access": "public"
67
67
  }
68
- }
68
+ }
@@ -1,5 +1,11 @@
1
1
  import { Protocol } from './protocol.js';
2
2
  declare type ParseCallback = (code: Protocol.BackendMessageCode, data?: any) => void;
3
+ /**
4
+ * Reads the server's messages out of the bytes as they arrive.
5
+ *
6
+ * Keeps whatever a chunk left half-finished, so a message split across
7
+ * reads - or several in one read - comes out whole exactly once.
8
+ */
3
9
  export declare class Backend {
4
10
  private readonly _headerBuf;
5
11
  private _headerFilled;
@@ -22,6 +22,12 @@ const ErrorFieldTypes = {
22
22
  L: 'line',
23
23
  R: 'routine',
24
24
  };
25
+ /**
26
+ * Reads the server's messages out of the bytes as they arrive.
27
+ *
28
+ * Keeps whatever a chunk left half-finished, so a message split across
29
+ * reads - or several in one read - comes out whole exactly once.
30
+ */
25
31
  export class Backend {
26
32
  _headerBuf = Buffer.allocUnsafe(HEADER_LENGTH);
27
33
  _headerFilled = 0;
@@ -47,10 +53,17 @@ export class Backend {
47
53
  const bodyStart = pos + HEADER_LENGTH;
48
54
  const bodyEnd = bodyStart + (len - 4);
49
55
  if (bodyEnd <= dataLen) {
50
- const io = new BufferReader(data.subarray(bodyStart, bodyEnd));
51
- const parser = MessageParsers[code];
52
- const v = parser && parser(io, code, len);
53
- callback(code, v);
56
+ if (code === Protocol.BackendMessageCode.DataRow) {
57
+ // Straight out of the read buffer: no view of the body, no
58
+ // reader over it, and no view of the row's own bytes either.
59
+ callback(code, dataRowMessage(data, bodyStart, bodyEnd));
60
+ }
61
+ else {
62
+ const io = new BufferReader(data.subarray(bodyStart, bodyEnd));
63
+ const parser = MessageParsers[code];
64
+ const v = parser && parser(io, code, len);
65
+ callback(code, v);
66
+ }
54
67
  pos = bodyEnd;
55
68
  continue;
56
69
  }
@@ -206,10 +219,27 @@ function parseCopyResponse(io) {
206
219
  }
207
220
  return out;
208
221
  }
222
+ /**
223
+ * One row, pointing into the read buffer rather than copying out of it.
224
+ *
225
+ * A consumer that needs a `Buffer` of its own - a caller's RowDecoder,
226
+ * or a path that sets the row aside and reads it later - builds the view
227
+ * with `dataRowBytes()`. The decoders that read the row in place never
228
+ * do, which is the point.
229
+ */
230
+ function dataRowMessage(buffer, bodyStart, bodyEnd) {
231
+ const offset = bodyStart + 2;
232
+ return {
233
+ columnCount: buffer.readUInt16BE(bodyStart),
234
+ buffer,
235
+ offset,
236
+ len: bodyEnd - offset,
237
+ };
238
+ }
209
239
  function parseDataRow(io, code, len) {
210
240
  const columnCount = io.readUInt16BE();
211
241
  const data = io.readBytes(len - 6);
212
- return { columnCount, data };
242
+ return { columnCount, buffer: data, offset: 0, len: data.length };
213
243
  }
214
244
  function parseErrorResponse(io) {
215
245
  const out = {};