postgrejs 3.12.0 → 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 (183) 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 +14 -0
  10. package/connection/intl-connection.js +95 -15
  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 +68 -0
  20. package/connection/prepared-statement.js +71 -2
  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 +2 -0
  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 +2 -0
  51. package/data-types/int8-type.d.ts +2 -0
  52. package/data-types/int8-type.js +2 -0
  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 +2 -0
  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 +6 -0
  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/bigint-methods.d.ts +7 -0
  141. package/util/bigint-methods.js +9 -0
  142. package/util/config-from-env.d.ts +10 -0
  143. package/util/config-from-env.js +10 -0
  144. package/util/connection-config.d.ts +17 -0
  145. package/util/connection-config.js +17 -0
  146. package/util/copy-from-rows.d.ts +12 -0
  147. package/util/copy-from-rows.js +9 -0
  148. package/util/decimal-as-string.d.ts +6 -0
  149. package/util/decimal-as-string.js +6 -0
  150. package/util/decode-binaryarray.d.ts +9 -0
  151. package/util/decode-binaryarray.js +9 -0
  152. package/util/escape-literal.d.ts +11 -0
  153. package/util/escape-literal.js +13 -0
  154. package/util/fast-parseint.d.ts +14 -0
  155. package/util/fast-parseint.js +14 -0
  156. package/util/format-datetime.d.ts +26 -0
  157. package/util/format-datetime.js +26 -0
  158. package/util/get-parsers.d.ts +9 -0
  159. package/util/get-parsers.js +9 -0
  160. package/util/hex-text.d.ts +13 -21
  161. package/util/hex-text.js +24 -21
  162. package/util/local-date.d.ts +2 -41
  163. package/util/local-date.js +39 -41
  164. package/util/parse-array.d.ts +8 -0
  165. package/util/parse-array.js +8 -0
  166. package/util/parse-bytea.d.ts +15 -0
  167. package/util/parse-bytea.js +15 -0
  168. package/util/parse-datetime.d.ts +26 -0
  169. package/util/parse-datetime.js +26 -0
  170. package/util/parse-row.d.ts +23 -2
  171. package/util/parse-row.js +56 -36
  172. package/util/parse-time.d.ts +10 -0
  173. package/util/parse-time.js +10 -0
  174. package/util/resolve-column-formats.d.ts +1 -0
  175. package/util/row-decoder.d.ts +32 -0
  176. package/util/row-decoder.js +22 -0
  177. package/util/stringify-arrayliteral.d.ts +33 -0
  178. package/util/stringify-arrayliteral.js +220 -20
  179. package/util/stringify-for-sql.d.ts +17 -0
  180. package/util/stringify-for-sql.js +17 -0
  181. package/util/wrap-row-description.d.ts +10 -0
  182. package/util/wrap-row-description.js +10 -0
  183. package/CHANGELOG.md +0 -1453
@@ -1,4 +1,17 @@
1
1
  // Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
2
+ /**
3
+ * Quotes a string as an SQL literal, escaping what has to be escaped.
4
+ *
5
+ * For the `sql` tag and anything else that has to put a value into the
6
+ * statement text; a parameter never needs this.
7
+ *
8
+ * @param str The value to quote.
9
+ * @returns The quoted literal, `E`-prefixed when it carries a backslash.
10
+ * @throws Error When the string holds a NUL byte, which PostgreSQL text
11
+ * cannot.
12
+ */
13
+ /* Ported from PostgreSQL's own src/interfaces/libpq/fe-exec.c (9.2.4),
14
+ so it quotes what libpq quotes, the way libpq quotes it. */
2
15
  export function escapeLiteral(str) {
3
16
  if (str.indexOf('\0') >= 0) {
4
17
  throw new Error('PostgreSQL text values cannot contain NUL (\\0) bytes');
@@ -1,2 +1,16 @@
1
+ /**
2
+ * Reads an integer out of what a decoder was handed.
3
+ *
4
+ * @param str The text, or a number already.
5
+ * @returns The integer, or NaN when there is none to read.
6
+ */
1
7
  export declare function fastParseInt(str: string | number): number;
8
+ /**
9
+ * The same, straight from the wire bytes - no string is made.
10
+ *
11
+ * @param buf The buffer holding the digits.
12
+ * @param offset Where they start.
13
+ * @param len How many bytes they run for.
14
+ * @returns The integer the digits spell.
15
+ */
2
16
  export declare function fastParseIntBuffer(buf: Buffer, offset?: number, len?: number): number;
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Reads an integer out of what a decoder was handed.
3
+ *
4
+ * @param str The text, or a number already.
5
+ * @returns The integer, or NaN when there is none to read.
6
+ */
1
7
  export function fastParseInt(str) {
2
8
  /* c8 ignore next */
3
9
  if (typeof str === 'number')
@@ -7,6 +13,14 @@ export function fastParseInt(str) {
7
13
  return NaN;
8
14
  return parseInt(str, 10);
9
15
  }
16
+ /**
17
+ * The same, straight from the wire bytes - no string is made.
18
+ *
19
+ * @param buf The buffer holding the digits.
20
+ * @param offset Where they start.
21
+ * @param len How many bytes they run for.
22
+ * @returns The integer the digits spell.
23
+ */
10
24
  export function fastParseIntBuffer(buf, offset = 0, len = buf.length - offset) {
11
25
  const end = offset + len;
12
26
  let i = offset;
@@ -1,6 +1,32 @@
1
1
  import type { DataMappingOptions } from '../interfaces/data-mapping-options.js';
2
+ /**
3
+ * Renders a value as the `YYYY-MM-DD` a `date` parameter goes out as.
4
+ *
5
+ * @param v The date, an epoch milliseconds, or text to pass through.
6
+ * @param options `utcDates` decides which clock its components are read
7
+ * from.
8
+ * @returns The date's text.
9
+ */
2
10
  export declare function formatDate(v: Date | number | string, options?: DataMappingOptions): string;
11
+ /**
12
+ * Renders a value as the `HH:MM:SS.mmm` a `time` parameter goes out as.
13
+ *
14
+ * @param v The time, an epoch milliseconds, or text to pass through.
15
+ * @param options `utcDates` decides which clock its components are read
16
+ * from.
17
+ * @returns The time's text.
18
+ */
3
19
  export declare function formatTime(v: Date | number | string, options?: DataMappingOptions): string;
20
+ /**
21
+ * Renders a value as the `YYYY-MM-DD HH:MM:SS.mmm` a `timestamp`
22
+ * parameter goes out as.
23
+ *
24
+ * @param v The timestamp, an epoch milliseconds, or text to pass
25
+ * through.
26
+ * @param options `utcDates` decides which clock its components are read
27
+ * from.
28
+ * @returns The timestamp's text.
29
+ */
4
30
  export declare function formatTimestamp(v: Date | number | string, options?: DataMappingOptions): string;
5
31
  /**
6
32
  * timestamptz is an absolute instant - its binary encoder uses getTime()
@@ -38,6 +38,14 @@ function coerce(v) {
38
38
  return '-infinity';
39
39
  return v instanceof Date ? v : new Date(v);
40
40
  }
41
+ /**
42
+ * Renders a value as the `YYYY-MM-DD` a `date` parameter goes out as.
43
+ *
44
+ * @param v The date, an epoch milliseconds, or text to pass through.
45
+ * @param options `utcDates` decides which clock its components are read
46
+ * from.
47
+ * @returns The date's text.
48
+ */
41
49
  export function formatDate(v, options) {
42
50
  const d = coerce(v);
43
51
  if (typeof d === 'string')
@@ -45,6 +53,14 @@ export function formatDate(v, options) {
45
53
  const p = parts(d, options);
46
54
  return `${pad(p.year, 4)}-${pad(p.month)}-${pad(p.day)}`;
47
55
  }
56
+ /**
57
+ * Renders a value as the `HH:MM:SS.mmm` a `time` parameter goes out as.
58
+ *
59
+ * @param v The time, an epoch milliseconds, or text to pass through.
60
+ * @param options `utcDates` decides which clock its components are read
61
+ * from.
62
+ * @returns The time's text.
63
+ */
48
64
  export function formatTime(v, options) {
49
65
  const d = coerce(v);
50
66
  if (typeof d === 'string')
@@ -52,6 +68,16 @@ export function formatTime(v, options) {
52
68
  const p = parts(d, options);
53
69
  return `${pad(p.hour)}:${pad(p.minute)}:${pad(p.second)}.${pad(p.ms, 3)}`;
54
70
  }
71
+ /**
72
+ * Renders a value as the `YYYY-MM-DD HH:MM:SS.mmm` a `timestamp`
73
+ * parameter goes out as.
74
+ *
75
+ * @param v The timestamp, an epoch milliseconds, or text to pass
76
+ * through.
77
+ * @param options `utcDates` decides which clock its components are read
78
+ * from.
79
+ * @returns The timestamp's text.
80
+ */
55
81
  export function formatTimestamp(v, options) {
56
82
  const d = coerce(v);
57
83
  if (typeof d === 'string')
@@ -2,4 +2,13 @@ import type { DataTypeMap } from '../data-type-map.js';
2
2
  import type { DataMappingOptions } from '../interfaces/data-mapping-options.js';
3
3
  import type { Protocol } from '../protocol/protocol.js';
4
4
  import type { AnyParseFunction } from '../types.js';
5
+ /**
6
+ * Chooses one parser per column, for the format that column is coming
7
+ * back in.
8
+ *
9
+ * @param typeMap Where the types are registered.
10
+ * @param fields The columns, as the server described them.
11
+ * @param options `fetchAsString` and the rest of the mapping options.
12
+ * @returns One parser per column, in order.
13
+ */
5
14
  export declare function getParsers(typeMap: DataTypeMap, fields: Protocol.RowDescription[], mappingOptions?: DataMappingOptions): AnyParseFunction[];
@@ -4,6 +4,15 @@ import { fetchAsStringNamesElement, fetchAsStringNamesOid, } from './fetch-as-st
4
4
  import { parsePostgresArray } from './parse-array.js';
5
5
  const DefaultColumnParser = (data, offset, len) => data.subarray(offset, offset + len);
6
6
  const DefaultTextColumnParser = (data, offset, len) => data.toString('utf8', offset, offset + len);
7
+ /**
8
+ * Chooses one parser per column, for the format that column is coming
9
+ * back in.
10
+ *
11
+ * @param typeMap Where the types are registered.
12
+ * @param fields The columns, as the server described them.
13
+ * @param options `fetchAsString` and the rest of the mapping options.
14
+ * @returns One parser per column, in order.
15
+ */
7
16
  export function getParsers(typeMap, fields, mappingOptions) {
8
17
  const parsers = new Array(fields.length);
9
18
  const asString = mappingOptions?.fetchAsString;
@@ -1,26 +1,18 @@
1
1
  /**
2
- * Writes `count` bytes of `src` into `scratch` as lowercase hex, each
3
- * byte's two characters starting at `positions[i]` - so the separators
4
- * a type writes between its bytes are put in once, when the scratch is
5
- * built, and never again.
2
+ * Writes `count` bytes of `src` into `scratch` as lowercase hex, two
3
+ * characters per byte, the first at `positions[i]`.
6
4
  *
7
- * The scratch is then read back with `latin1`, which is what the text
8
- * paths of these types already use: the output is fixed-format ASCII,
9
- * so it decodes identically to `utf8` and skips V8's multi-byte-sequence
10
- * detection.
5
+ * The positions are what let a type keep the separators of its own text
6
+ * form - a uuid's dashes, a macaddr's colons - in the scratch, written
7
+ * once when it is built and never again. The scratch is read back with
8
+ * `latin1`, which is what these types' text paths already use: the
9
+ * output is fixed-format ASCII, so it decodes identically to `utf8` and
10
+ * skips V8's multi-byte-sequence detection.
11
11
  *
12
- * Why not `Buffer.toString('hex')`: a type whose text has separators in
13
- * it has to call that once per group and join the pieces. For `uuid`
14
- * that was five calls and four concatenations per value - 25 000 strings
15
- * and 20 000 concatenations for a 5 000-row column, which is more work
16
- * than `pg` does for the same column despite this client reading half
17
- * the bytes. Measured over 5 000 values, medians of nine runs:
18
- *
19
- * ```
20
- * five toString + concat 1.86 ms
21
- * one toString, then slice 0.81 ms
22
- * a byte -> two-char table 0.64 ms
23
- * this 0.33 ms
24
- * ```
12
+ * @param scratch The buffer to write into, reused across values.
13
+ * @param positions Where each byte's two characters go.
14
+ * @param src The bytes to render.
15
+ * @param offset Where they start in `src`.
16
+ * @param count How many to render.
25
17
  */
26
18
  export declare function writeHexBytes(scratch: Buffer, positions: number[], src: Buffer, offset: number, count: number): void;
package/util/hex-text.js CHANGED
@@ -1,30 +1,33 @@
1
1
  /** `0`-`f` as bytes, so a nibble indexes straight into it. */
2
2
  const HEX = Buffer.from('0123456789abcdef', 'latin1');
3
3
  /**
4
- * Writes `count` bytes of `src` into `scratch` as lowercase hex, each
5
- * byte's two characters starting at `positions[i]` - so the separators
6
- * a type writes between its bytes are put in once, when the scratch is
7
- * built, and never again.
4
+ * Writes `count` bytes of `src` into `scratch` as lowercase hex, two
5
+ * characters per byte, the first at `positions[i]`.
8
6
  *
9
- * The scratch is then read back with `latin1`, which is what the text
10
- * paths of these types already use: the output is fixed-format ASCII,
11
- * so it decodes identically to `utf8` and skips V8's multi-byte-sequence
12
- * detection.
7
+ * The positions are what let a type keep the separators of its own text
8
+ * form - a uuid's dashes, a macaddr's colons - in the scratch, written
9
+ * once when it is built and never again. The scratch is read back with
10
+ * `latin1`, which is what these types' text paths already use: the
11
+ * output is fixed-format ASCII, so it decodes identically to `utf8` and
12
+ * skips V8's multi-byte-sequence detection.
13
13
  *
14
- * Why not `Buffer.toString('hex')`: a type whose text has separators in
15
- * it has to call that once per group and join the pieces. For `uuid`
16
- * that was five calls and four concatenations per value - 25 000 strings
17
- * and 20 000 concatenations for a 5 000-row column, which is more work
18
- * than `pg` does for the same column despite this client reading half
19
- * the bytes. Measured over 5 000 values, medians of nine runs:
20
- *
21
- * ```
22
- * five toString + concat 1.86 ms
23
- * one toString, then slice 0.81 ms
24
- * a byte -> two-char table 0.64 ms
25
- * this 0.33 ms
26
- * ```
14
+ * @param scratch The buffer to write into, reused across values.
15
+ * @param positions Where each byte's two characters go.
16
+ * @param src The bytes to render.
17
+ * @param offset Where they start in `src`.
18
+ * @param count How many to render.
27
19
  */
20
+ /* Why not Buffer.toString('hex'): a type whose text has separators in it
21
+ has to call that once per group and join the pieces. For uuid that was
22
+ five calls and four concatenations per value - 25 000 strings and
23
+ 20 000 concatenations for a 5 000-row column, more work than pg does
24
+ for the same column despite this client reading half the bytes.
25
+ Measured over 5 000 values, medians of nine runs:
26
+
27
+ five toString + concat 1.86 ms
28
+ one toString, then slice 0.81 ms
29
+ a byte -> two-char table 0.64 ms
30
+ this 0.33 ms */
28
31
  export function writeHexBytes(scratch, positions, src, offset, count) {
29
32
  let i;
30
33
  let p;
@@ -7,46 +7,7 @@
7
7
  * comes back as a Date reading 10:30 locally rather than the instant
8
8
  * 10:30Z.
9
9
  *
10
- * Doing that by reading the seven `getUTC*` components off one Date and
11
- * handing them to another was the most expensive thing left in the
12
- * common decode path - the getters alone cost more than either Date:
13
- *
14
- * ```
15
- * new Date(epochMs) 43.6 ns
16
- * getUTC* x 7 97.4 ns
17
- * new Date(y, m, d, h, mi, s, ms) 61.7 ns
18
- * ```
19
- *
20
- * Shifting the instant by the zone's own offset lands on the same wall
21
- * clock for a fraction of that, but only where the offset is a whole
22
- * number of minutes and holds either side of where the shift lands.
23
- * Two guards and a floor make that exact rather than usually-right:
24
- *
25
- * - **The offset must survive the shift.** Where it does not, the shift
26
- * crossed a transition and the wall clock it landed on is not the one
27
- * that was asked for - or does not exist at all.
28
- * - **The offset must hold for the hour before the landing too.** That
29
- * is the hour a backward transition repeats, where both instants read
30
- * the same wall clock and the shift keeps the wrong one of the two.
31
- * Pacific/Chatham found this: `2024-04-07T03:00Z` is `03:00` in both
32
- * +12:45 and +13:45, an hour apart.
33
- * - **Nothing before 1970.** A zone's pre-standard offset carries
34
- * seconds - Europe/Istanbul was +01:55:52 - and `getTimezoneOffset()`
35
- * answers in whole minutes, so the shift lands up to 59 seconds off.
36
- * The tz database does not claim correctness before 1970 either.
37
- *
38
- * Whatever fails those goes back to the component route, which is what
39
- * this has always answered. Checked against it over 1850-2040 at
40
- * 90-minute steps - 1.1 million instants - in ten zones including the
41
- * 45-minute and 30-minute DST ones: no disagreement, and
42
- *
43
- * ```
44
- * before after
45
- * Europe/Istanbul 157.5 ns 123.0 ns
46
- * America/New_York 245.6 ns 131.2 ns
47
- * ```
48
- *
49
- * The DST zone was dearer before because V8 pays for a transition lookup
50
- * on every local construction; here it pays for one instant instead.
10
+ * @param ms The instant whose UTC components are the wall clock wanted.
11
+ * @returns A Date reading that wall clock in the local zone.
51
12
  */
52
13
  export declare function utcPartsAsLocal(ms: number): Date;
@@ -7,48 +7,46 @@
7
7
  * comes back as a Date reading 10:30 locally rather than the instant
8
8
  * 10:30Z.
9
9
  *
10
- * Doing that by reading the seven `getUTC*` components off one Date and
11
- * handing them to another was the most expensive thing left in the
12
- * common decode path - the getters alone cost more than either Date:
13
- *
14
- * ```
15
- * new Date(epochMs) 43.6 ns
16
- * getUTC* x 7 97.4 ns
17
- * new Date(y, m, d, h, mi, s, ms) 61.7 ns
18
- * ```
19
- *
20
- * Shifting the instant by the zone's own offset lands on the same wall
21
- * clock for a fraction of that, but only where the offset is a whole
22
- * number of minutes and holds either side of where the shift lands.
23
- * Two guards and a floor make that exact rather than usually-right:
24
- *
25
- * - **The offset must survive the shift.** Where it does not, the shift
26
- * crossed a transition and the wall clock it landed on is not the one
27
- * that was asked for - or does not exist at all.
28
- * - **The offset must hold for the hour before the landing too.** That
29
- * is the hour a backward transition repeats, where both instants read
30
- * the same wall clock and the shift keeps the wrong one of the two.
31
- * Pacific/Chatham found this: `2024-04-07T03:00Z` is `03:00` in both
32
- * +12:45 and +13:45, an hour apart.
33
- * - **Nothing before 1970.** A zone's pre-standard offset carries
34
- * seconds - Europe/Istanbul was +01:55:52 - and `getTimezoneOffset()`
35
- * answers in whole minutes, so the shift lands up to 59 seconds off.
36
- * The tz database does not claim correctness before 1970 either.
37
- *
38
- * Whatever fails those goes back to the component route, which is what
39
- * this has always answered. Checked against it over 1850-2040 at
40
- * 90-minute steps - 1.1 million instants - in ten zones including the
41
- * 45-minute and 30-minute DST ones: no disagreement, and
42
- *
43
- * ```
44
- * before after
45
- * Europe/Istanbul 157.5 ns 123.0 ns
46
- * America/New_York 245.6 ns 131.2 ns
47
- * ```
48
- *
49
- * The DST zone was dearer before because V8 pays for a transition lookup
50
- * on every local construction; here it pays for one instant instead.
10
+ * @param ms The instant whose UTC components are the wall clock wanted.
11
+ * @returns A Date reading that wall clock in the local zone.
51
12
  */
13
+ /* Doing this by reading the seven getUTC* components off one Date and
14
+ handing them to another was the most expensive thing left in the
15
+ common decode path - the getters alone cost more than either Date:
16
+
17
+ new Date(epochMs) 43.6 ns
18
+ getUTC* x 7 97.4 ns
19
+ new Date(y, m, d, h, mi, s, ms) 61.7 ns
20
+
21
+ Shifting the instant by the zone's own offset lands on the same wall
22
+ clock for a fraction of that, but only where the offset is a whole
23
+ number of minutes and holds either side of where the shift lands. Two
24
+ guards and a floor make that exact rather than usually-right:
25
+
26
+ - The offset must survive the shift. Where it does not, the shift
27
+ crossed a transition and the wall clock it landed on is not the one
28
+ that was asked for - or does not exist at all.
29
+ - The offset must hold for the hour before the landing too. That is
30
+ the hour a backward transition repeats, where both instants read the
31
+ same wall clock and the shift keeps the wrong one of the two.
32
+ Pacific/Chatham found this: 2024-04-07T03:00Z is 03:00 in both
33
+ +12:45 and +13:45, an hour apart.
34
+ - Nothing before 1970. A zone's pre-standard offset carries seconds -
35
+ Europe/Istanbul was +01:55:52 - and getTimezoneOffset() answers in
36
+ whole minutes, so the shift lands up to 59 seconds off. The tz
37
+ database does not claim correctness before 1970 either.
38
+
39
+ Whatever fails those goes back to the component route, which is what
40
+ this has always answered. Checked against it over 1850-2040 at
41
+ 90-minute steps - 1.1 million instants - in ten zones including the
42
+ 45-minute and 30-minute DST ones: no disagreement, and
43
+
44
+ before after
45
+ Europe/Istanbul 157.5 ns 123.0 ns
46
+ America/New_York 245.6 ns 131.2 ns
47
+
48
+ The DST zone was dearer before because V8 pays for a transition lookup
49
+ on every local construction; here it pays for one instant instead. */
52
50
  export function utcPartsAsLocal(ms) {
53
51
  if (ms >= 0) {
54
52
  const offset = new Date(ms).getTimezoneOffset();
@@ -1,4 +1,12 @@
1
1
  import type { Maybe } from '../types.js';
2
+ /**
3
+ * Reads an array literal - `{1,2,{3,4}}` - into a nested array.
4
+ *
5
+ * @param s The literal, as the server wrote it.
6
+ * @param opts `transform` reads each element's text into a value, and
7
+ * `separator` is for the types that do not use a comma.
8
+ * @returns The array, or `undefined` when there was no literal.
9
+ */
2
10
  export declare function parsePostgresArray(s: string, opts?: {
3
11
  transform?: (v: string) => any;
4
12
  separator?: string;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Reads an array literal - `{1,2,{3,4}}` - into a nested array.
3
+ *
4
+ * @param s The literal, as the server wrote it.
5
+ * @param opts `transform` reads each element's text into a value, and
6
+ * `separator` is for the types that do not use a comma.
7
+ * @returns The array, or `undefined` when there was no literal.
8
+ */
1
9
  export function parsePostgresArray(s, opts) {
2
10
  if (!s)
3
11
  return;
@@ -1,2 +1,17 @@
1
+ /**
2
+ * Reads a `bytea`'s text form into its bytes.
3
+ *
4
+ * @param v The value as the server wrote it - `\\x` hex, or the older
5
+ * escape form.
6
+ * @returns The bytes.
7
+ */
1
8
  export declare function parseBytea(v: string): Buffer;
9
+ /**
10
+ * The same, straight from the wire bytes - no string is made.
11
+ *
12
+ * @param buf The buffer holding the value.
13
+ * @param offset Where it starts.
14
+ * @param len How many bytes it runs for.
15
+ * @returns The decoded bytes.
16
+ */
2
17
  export declare function parseByteaBuffer(buf: Buffer, offset: number, len: number): Buffer;
@@ -36,6 +36,13 @@ function parseByteaEscape(input) {
36
36
  }
37
37
  return Buffer.from(output, 'binary');
38
38
  }
39
+ /**
40
+ * Reads a `bytea`'s text form into its bytes.
41
+ *
42
+ * @param v The value as the server wrote it - `\\x` hex, or the older
43
+ * escape form.
44
+ * @returns The bytes.
45
+ */
39
46
  export function parseBytea(v) {
40
47
  // PostgreSQL's default bytea_output is "hex" (`\x`-prefixed) - check the
41
48
  // two marker chars directly rather than a regex test, and hex-decode
@@ -65,6 +72,14 @@ const HEX_NIBBLE = (() => {
65
72
  // format via a single 'latin1' string conversion - its own grammar (\ddd
66
73
  // octal triplets, ASCII digits, or a literal backslash) is pure ASCII, same
67
74
  // as the hex path, so 'latin1' is safe there too.
75
+ /**
76
+ * The same, straight from the wire bytes - no string is made.
77
+ *
78
+ * @param buf The buffer holding the value.
79
+ * @param offset Where it starts.
80
+ * @param len How many bytes it runs for.
81
+ * @returns The decoded bytes.
82
+ */
68
83
  export function parseByteaBuffer(buf, offset, len) {
69
84
  if (buf[offset] === 0x5c /* '\' */ && buf[offset + 1] === 0x78 /* 'x' */) {
70
85
  // Truncate a trailing odd nibble instead of throwing, matching
@@ -1,4 +1,30 @@
1
1
  import { type PgDateStyle } from './date-style.js';
2
+ /**
3
+ * Reads a `date` as the server wrote it.
4
+ *
5
+ * @param str The value's text.
6
+ * @param utc Whether to build the Date in UTC rather than locally.
7
+ * @param dateStyle The session's DateStyle, when it is not ISO - which
8
+ * is what says whether `01/02/2024` is January or February.
9
+ * @returns The date, or ±Infinity for the two that are not dates.
10
+ */
2
11
  export declare function parseDate(str: string, utc?: boolean, dateStyle?: PgDateStyle): Date | number;
12
+ /**
13
+ * Reads a `timestamp` (without time zone) as the server wrote it.
14
+ *
15
+ * @param str The value's text.
16
+ * @param utc Whether to build the Date in UTC rather than locally.
17
+ * @param dateStyle The session's DateStyle, when it is not ISO.
18
+ * @returns The timestamp, or ±Infinity.
19
+ */
3
20
  export declare function parseDateTime(str: string, utc?: boolean, dateStyle?: PgDateStyle): Date | number;
21
+ /**
22
+ * Reads a `timestamptz` as the server wrote it, offset included.
23
+ *
24
+ * @param str The value's text.
25
+ * @param utc Whether to build the Date in UTC rather than locally, for
26
+ * a value that carries no offset.
27
+ * @param dateStyle The session's DateStyle, when it is not ISO.
28
+ * @returns The instant, or ±Infinity.
29
+ */
4
30
  export declare function parseDateTimeTz(str: string, utc?: boolean, dateStyle?: PgDateStyle): Date | number;
@@ -22,6 +22,15 @@ function fillTimeArgs(m, args) {
22
22
  }
23
23
  }
24
24
  }
25
+ /**
26
+ * Reads a `date` as the server wrote it.
27
+ *
28
+ * @param str The value's text.
29
+ * @param utc Whether to build the Date in UTC rather than locally.
30
+ * @param dateStyle The session's DateStyle, when it is not ISO - which
31
+ * is what says whether `01/02/2024` is January or February.
32
+ * @returns The date, or ±Infinity for the two that are not dates.
33
+ */
25
34
  export function parseDate(str, utc, dateStyle) {
26
35
  if (dateStyle) {
27
36
  const styled = parseStyledDateTime(str, dateStyle, utc);
@@ -46,6 +55,14 @@ export function parseDate(str, utc, dateStyle) {
46
55
  return new Date(Date.UTC(...args));
47
56
  return new Date(...args);
48
57
  }
58
+ /**
59
+ * Reads a `timestamp` (without time zone) as the server wrote it.
60
+ *
61
+ * @param str The value's text.
62
+ * @param utc Whether to build the Date in UTC rather than locally.
63
+ * @param dateStyle The session's DateStyle, when it is not ISO.
64
+ * @returns The timestamp, or ±Infinity.
65
+ */
49
66
  export function parseDateTime(str, utc, dateStyle) {
50
67
  if (dateStyle) {
51
68
  const styled = parseStyledDateTime(str, dateStyle, utc);
@@ -88,6 +105,15 @@ export function parseDateTime(str, utc, dateStyle) {
88
105
  return new Date(Date.UTC(...args));
89
106
  return new Date(...args);
90
107
  }
108
+ /**
109
+ * Reads a `timestamptz` as the server wrote it, offset included.
110
+ *
111
+ * @param str The value's text.
112
+ * @param utc Whether to build the Date in UTC rather than locally, for
113
+ * a value that carries no offset.
114
+ * @param dateStyle The session's DateStyle, when it is not ISO.
115
+ * @returns The instant, or ±Infinity.
116
+ */
91
117
  export function parseDateTimeTz(str, utc, dateStyle) {
92
118
  if (dateStyle) {
93
119
  const styled = parseStyledDateTime(str, dateStyle, utc);
@@ -1,5 +1,26 @@
1
1
  import type { DataMappingOptions } from '../interfaces/data-mapping-options.js';
2
2
  import type { FieldInfo } from '../interfaces/field-info.js';
3
3
  import type { AnyParseFunction } from '../types.js';
4
- export declare function parseRow(parsers: AnyParseFunction[], data: Buffer, columnCount: number, options: DataMappingOptions): any[];
5
- export declare function parseObjectRow(parsers: AnyParseFunction[], data: Buffer, columnCount: number, options: DataMappingOptions, fields: FieldInfo[]): object;
4
+ /**
5
+ * Reads one row into an array of values.
6
+ *
7
+ * @param parsers One per column, already chosen for its format.
8
+ * @param data The row's own bytes, from the DataRow message.
9
+ * @param columnCount How many values it holds.
10
+ * @param options Passed to each parser.
11
+ * @param start Where the row's values begin in `data`.
12
+ * @returns The values, in column order.
13
+ */
14
+ export declare function parseRow(parsers: AnyParseFunction[], data: Buffer, columnCount: number, options: DataMappingOptions, start?: number): any[];
15
+ /**
16
+ * Reads one row into an object keyed by column name.
17
+ *
18
+ * @param parsers One per column, already chosen for its format.
19
+ * @param data The row's own bytes, from the DataRow message.
20
+ * @param columnCount How many values it holds.
21
+ * @param options Passed to each parser.
22
+ * @param fields The columns, whose names become the keys.
23
+ * @param start Where the row's values begin in `data`.
24
+ * @returns The row as an object.
25
+ */
26
+ export declare function parseObjectRow(parsers: AnyParseFunction[], data: Buffer, columnCount: number, options: DataMappingOptions, fields: FieldInfo[], start?: number): object;