postgrejs 2.22.9 → 2.23.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 (216) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/{esm/connection → connection}/bind-param.js +2 -0
  3. package/{esm/connection → connection}/connection.js +4 -2
  4. package/{esm/connection → connection}/cursor.js +8 -3
  5. package/{esm/connection → connection}/intl-connection.js +6 -3
  6. package/{esm/connection → connection}/pool.js +4 -1
  7. package/{esm/connection → connection}/portal.js +3 -1
  8. package/{esm/connection → connection}/prepared-statement.js +6 -3
  9. package/{esm/constants.js → constants.js} +1 -1
  10. package/{types/data-type-map.d.ts → data-type-map.d.ts} +2 -2
  11. package/{esm/data-type-map.js → data-type-map.js} +2 -2
  12. package/{esm/data-types → data-types}/int2-vector-type.js +1 -0
  13. package/{types/data-types → data-types}/timestamptz-type.d.ts +1 -1
  14. package/{esm/data-types → data-types}/timestamptz-type.js +1 -0
  15. package/package.json +12 -31
  16. package/{esm/protocol → protocol}/backend.js +1 -0
  17. package/{esm/protocol → protocol}/buffer-reader.js +2 -1
  18. package/{esm/protocol → protocol}/database-error.js +17 -0
  19. package/{esm/protocol → protocol}/frontend.js +2 -0
  20. package/{types/protocol → protocol}/pg-socket.d.ts +1 -1
  21. package/{esm/protocol → protocol}/pg-socket.js +9 -3
  22. package/{esm/protocol → protocol}/smart-buffer.js +9 -5
  23. package/{esm/util → util}/bigint-methods.js +1 -0
  24. package/cjs/connection/bind-param.js +0 -10
  25. package/cjs/connection/connection.js +0 -295
  26. package/cjs/connection/cursor.js +0 -91
  27. package/cjs/connection/intl-connection.js +0 -258
  28. package/cjs/connection/pool.js +0 -236
  29. package/cjs/connection/portal.js +0 -157
  30. package/cjs/connection/prepared-statement.js +0 -226
  31. package/cjs/constants.js +0 -249
  32. package/cjs/data-type-map.js +0 -131
  33. package/cjs/data-types/bool-type.js +0 -33
  34. package/cjs/data-types/box-type.js +0 -52
  35. package/cjs/data-types/bytea-type.js +0 -28
  36. package/cjs/data-types/char-type.js +0 -27
  37. package/cjs/data-types/circle-type.js +0 -51
  38. package/cjs/data-types/date-type.js +0 -75
  39. package/cjs/data-types/float4-type.js +0 -25
  40. package/cjs/data-types/float8-type.js +0 -25
  41. package/cjs/data-types/int2-type.js +0 -26
  42. package/cjs/data-types/int2-vector-type.js +0 -42
  43. package/cjs/data-types/int4-type.js +0 -28
  44. package/cjs/data-types/int8-type.js +0 -36
  45. package/cjs/data-types/json-type.js +0 -40
  46. package/cjs/data-types/jsonb-type.js +0 -44
  47. package/cjs/data-types/lseg-type.js +0 -55
  48. package/cjs/data-types/numeric-type.js +0 -125
  49. package/cjs/data-types/oid-type.js +0 -32
  50. package/cjs/data-types/point-type.js +0 -42
  51. package/cjs/data-types/time-type.js +0 -66
  52. package/cjs/data-types/timestamp-type.js +0 -89
  53. package/cjs/data-types/timestamptz-type.js +0 -76
  54. package/cjs/data-types/uuid-type.js +0 -39
  55. package/cjs/data-types/varchar-type.js +0 -27
  56. package/cjs/index.js +0 -28
  57. package/cjs/interfaces/command-result.js +0 -2
  58. package/cjs/interfaces/data-mapping-options.js +0 -2
  59. package/cjs/interfaces/data-type.js +0 -2
  60. package/cjs/interfaces/database-connection-params.js +0 -2
  61. package/cjs/interfaces/field-info.js +0 -2
  62. package/cjs/interfaces/query-options.js +0 -2
  63. package/cjs/interfaces/query-result.js +0 -2
  64. package/cjs/interfaces/script-execute-options.js +0 -2
  65. package/cjs/interfaces/script-result.js +0 -2
  66. package/cjs/interfaces/statement-prepare-options.js +0 -2
  67. package/cjs/package.json +0 -3
  68. package/cjs/protocol/backend.js +0 -262
  69. package/cjs/protocol/buffer-reader.js +0 -78
  70. package/cjs/protocol/database-error.js +0 -17
  71. package/cjs/protocol/frontend.js +0 -255
  72. package/cjs/protocol/pg-socket.js +0 -367
  73. package/cjs/protocol/protocol.js +0 -71
  74. package/cjs/protocol/sasl.js +0 -108
  75. package/cjs/protocol/smart-buffer.js +0 -178
  76. package/cjs/safe-event-emitter.js +0 -17
  77. package/cjs/tsconfig-build-cjs.tsbuildinfo +0 -1
  78. package/cjs/types.js +0 -2
  79. package/cjs/util/array-calculatedim.js +0 -18
  80. package/cjs/util/bigint-methods.js +0 -44
  81. package/cjs/util/config-from-env.js +0 -29
  82. package/cjs/util/connection-config.js +0 -61
  83. package/cjs/util/convert-row-to-object.js +0 -12
  84. package/cjs/util/decode-binaryarray.js +0 -38
  85. package/cjs/util/encode-binaryarray.js +0 -44
  86. package/cjs/util/escape-literal.js +0 -26
  87. package/cjs/util/fast-parseint.js +0 -31
  88. package/cjs/util/get-parsers.js +0 -41
  89. package/cjs/util/parse-array.js +0 -60
  90. package/cjs/util/parse-datetime.js +0 -37
  91. package/cjs/util/parse-row.js +0 -11
  92. package/cjs/util/parse-time.js +0 -30
  93. package/cjs/util/stringify-arrayliteral.js +0 -37
  94. package/cjs/util/stringify-for-sql.js +0 -29
  95. package/cjs/util/wrap-row-description.js +0 -34
  96. package/esm/package.json +0 -3
  97. package/types/index.d.cts +0 -25
  98. /package/{types/connection → connection}/bind-param.d.ts +0 -0
  99. /package/{types/connection → connection}/connection.d.ts +0 -0
  100. /package/{types/connection → connection}/cursor.d.ts +0 -0
  101. /package/{types/connection → connection}/intl-connection.d.ts +0 -0
  102. /package/{types/connection → connection}/pool.d.ts +0 -0
  103. /package/{types/connection → connection}/portal.d.ts +0 -0
  104. /package/{types/connection → connection}/prepared-statement.d.ts +0 -0
  105. /package/{types/constants.d.ts → constants.d.ts} +0 -0
  106. /package/{types/data-types → data-types}/bool-type.d.ts +0 -0
  107. /package/{esm/data-types → data-types}/bool-type.js +0 -0
  108. /package/{types/data-types → data-types}/box-type.d.ts +0 -0
  109. /package/{esm/data-types → data-types}/box-type.js +0 -0
  110. /package/{types/data-types → data-types}/bytea-type.d.ts +0 -0
  111. /package/{esm/data-types → data-types}/bytea-type.js +0 -0
  112. /package/{types/data-types → data-types}/char-type.d.ts +0 -0
  113. /package/{esm/data-types → data-types}/char-type.js +0 -0
  114. /package/{types/data-types → data-types}/circle-type.d.ts +0 -0
  115. /package/{esm/data-types → data-types}/circle-type.js +0 -0
  116. /package/{types/data-types → data-types}/date-type.d.ts +0 -0
  117. /package/{esm/data-types → data-types}/date-type.js +0 -0
  118. /package/{types/data-types → data-types}/float4-type.d.ts +0 -0
  119. /package/{esm/data-types → data-types}/float4-type.js +0 -0
  120. /package/{types/data-types → data-types}/float8-type.d.ts +0 -0
  121. /package/{esm/data-types → data-types}/float8-type.js +0 -0
  122. /package/{types/data-types → data-types}/int2-type.d.ts +0 -0
  123. /package/{esm/data-types → data-types}/int2-type.js +0 -0
  124. /package/{types/data-types → data-types}/int2-vector-type.d.ts +0 -0
  125. /package/{types/data-types → data-types}/int4-type.d.ts +0 -0
  126. /package/{esm/data-types → data-types}/int4-type.js +0 -0
  127. /package/{types/data-types → data-types}/int8-type.d.ts +0 -0
  128. /package/{esm/data-types → data-types}/int8-type.js +0 -0
  129. /package/{types/data-types → data-types}/json-type.d.ts +0 -0
  130. /package/{esm/data-types → data-types}/json-type.js +0 -0
  131. /package/{types/data-types → data-types}/jsonb-type.d.ts +0 -0
  132. /package/{esm/data-types → data-types}/jsonb-type.js +0 -0
  133. /package/{types/data-types → data-types}/lseg-type.d.ts +0 -0
  134. /package/{esm/data-types → data-types}/lseg-type.js +0 -0
  135. /package/{types/data-types → data-types}/numeric-type.d.ts +0 -0
  136. /package/{esm/data-types → data-types}/numeric-type.js +0 -0
  137. /package/{types/data-types → data-types}/oid-type.d.ts +0 -0
  138. /package/{esm/data-types → data-types}/oid-type.js +0 -0
  139. /package/{types/data-types → data-types}/point-type.d.ts +0 -0
  140. /package/{esm/data-types → data-types}/point-type.js +0 -0
  141. /package/{types/data-types → data-types}/time-type.d.ts +0 -0
  142. /package/{esm/data-types → data-types}/time-type.js +0 -0
  143. /package/{types/data-types → data-types}/timestamp-type.d.ts +0 -0
  144. /package/{esm/data-types → data-types}/timestamp-type.js +0 -0
  145. /package/{types/data-types → data-types}/uuid-type.d.ts +0 -0
  146. /package/{esm/data-types → data-types}/uuid-type.js +0 -0
  147. /package/{types/data-types → data-types}/varchar-type.d.ts +0 -0
  148. /package/{esm/data-types → data-types}/varchar-type.js +0 -0
  149. /package/{types/index.d.ts → index.d.ts} +0 -0
  150. /package/{esm/index.js → index.js} +0 -0
  151. /package/{types/interfaces → interfaces}/command-result.d.ts +0 -0
  152. /package/{esm/interfaces → interfaces}/command-result.js +0 -0
  153. /package/{types/interfaces → interfaces}/data-mapping-options.d.ts +0 -0
  154. /package/{esm/interfaces → interfaces}/data-mapping-options.js +0 -0
  155. /package/{types/interfaces → interfaces}/data-type.d.ts +0 -0
  156. /package/{esm/interfaces → interfaces}/data-type.js +0 -0
  157. /package/{types/interfaces → interfaces}/database-connection-params.d.ts +0 -0
  158. /package/{esm/interfaces → interfaces}/database-connection-params.js +0 -0
  159. /package/{types/interfaces → interfaces}/field-info.d.ts +0 -0
  160. /package/{esm/interfaces → interfaces}/field-info.js +0 -0
  161. /package/{types/interfaces → interfaces}/query-options.d.ts +0 -0
  162. /package/{esm/interfaces → interfaces}/query-options.js +0 -0
  163. /package/{types/interfaces → interfaces}/query-result.d.ts +0 -0
  164. /package/{esm/interfaces → interfaces}/query-result.js +0 -0
  165. /package/{types/interfaces → interfaces}/script-execute-options.d.ts +0 -0
  166. /package/{esm/interfaces → interfaces}/script-execute-options.js +0 -0
  167. /package/{types/interfaces → interfaces}/script-result.d.ts +0 -0
  168. /package/{esm/interfaces → interfaces}/script-result.js +0 -0
  169. /package/{types/interfaces → interfaces}/statement-prepare-options.d.ts +0 -0
  170. /package/{esm/interfaces → interfaces}/statement-prepare-options.js +0 -0
  171. /package/{types/protocol → protocol}/backend.d.ts +0 -0
  172. /package/{types/protocol → protocol}/buffer-reader.d.ts +0 -0
  173. /package/{types/protocol → protocol}/database-error.d.ts +0 -0
  174. /package/{types/protocol → protocol}/frontend.d.ts +0 -0
  175. /package/{types/protocol → protocol}/protocol.d.ts +0 -0
  176. /package/{esm/protocol → protocol}/protocol.js +0 -0
  177. /package/{types/protocol → protocol}/sasl.d.ts +0 -0
  178. /package/{esm/protocol → protocol}/sasl.js +0 -0
  179. /package/{types/protocol → protocol}/smart-buffer.d.ts +0 -0
  180. /package/{types/safe-event-emitter.d.ts → safe-event-emitter.d.ts} +0 -0
  181. /package/{esm/safe-event-emitter.js → safe-event-emitter.js} +0 -0
  182. /package/{types/types.d.ts → types.d.ts} +0 -0
  183. /package/{esm/types.js → types.js} +0 -0
  184. /package/{types/util → util}/array-calculatedim.d.ts +0 -0
  185. /package/{esm/util → util}/array-calculatedim.js +0 -0
  186. /package/{types/util → util}/bigint-methods.d.ts +0 -0
  187. /package/{types/util → util}/config-from-env.d.ts +0 -0
  188. /package/{esm/util → util}/config-from-env.js +0 -0
  189. /package/{types/util → util}/connection-config.d.ts +0 -0
  190. /package/{esm/util → util}/connection-config.js +0 -0
  191. /package/{types/util → util}/convert-row-to-object.d.ts +0 -0
  192. /package/{esm/util → util}/convert-row-to-object.js +0 -0
  193. /package/{types/util → util}/decode-binaryarray.d.ts +0 -0
  194. /package/{esm/util → util}/decode-binaryarray.js +0 -0
  195. /package/{types/util → util}/encode-binaryarray.d.ts +0 -0
  196. /package/{esm/util → util}/encode-binaryarray.js +0 -0
  197. /package/{types/util → util}/escape-literal.d.ts +0 -0
  198. /package/{esm/util → util}/escape-literal.js +0 -0
  199. /package/{types/util → util}/fast-parseint.d.ts +0 -0
  200. /package/{esm/util → util}/fast-parseint.js +0 -0
  201. /package/{types/util → util}/get-parsers.d.ts +0 -0
  202. /package/{esm/util → util}/get-parsers.js +0 -0
  203. /package/{types/util → util}/parse-array.d.ts +0 -0
  204. /package/{esm/util → util}/parse-array.js +0 -0
  205. /package/{types/util → util}/parse-datetime.d.ts +0 -0
  206. /package/{esm/util → util}/parse-datetime.js +0 -0
  207. /package/{types/util → util}/parse-row.d.ts +0 -0
  208. /package/{esm/util → util}/parse-row.js +0 -0
  209. /package/{types/util → util}/parse-time.d.ts +0 -0
  210. /package/{esm/util → util}/parse-time.js +0 -0
  211. /package/{types/util → util}/stringify-arrayliteral.d.ts +0 -0
  212. /package/{esm/util → util}/stringify-arrayliteral.js +0 -0
  213. /package/{types/util → util}/stringify-for-sql.d.ts +0 -0
  214. /package/{esm/util → util}/stringify-for-sql.js +0 -0
  215. /package/{types/util → util}/wrap-row-description.d.ts +0 -0
  216. /package/{esm/util → util}/wrap-row-description.js +0 -0
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayFloat8Type = exports.Float8Type = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- exports.Float8Type = {
6
- name: 'float8',
7
- oid: constants_js_1.DataTypeOIDs.float8,
8
- jsType: 'number',
9
- parseBinary(v) {
10
- return v.readDoubleBE(0);
11
- },
12
- encodeBinary(buf, v) {
13
- buf.writeDoubleBE(typeof v === 'number' ? v : parseFloat(v));
14
- },
15
- parseText: parseFloat,
16
- isType(v) {
17
- return typeof v === 'number';
18
- },
19
- };
20
- exports.ArrayFloat8Type = {
21
- ...exports.Float8Type,
22
- name: '_float8',
23
- oid: constants_js_1.DataTypeOIDs._float8,
24
- elementsOID: constants_js_1.DataTypeOIDs.float8,
25
- };
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayInt2Type = exports.Int2Type = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- const fast_parseint_js_1 = require("../util/fast-parseint.js");
6
- exports.Int2Type = {
7
- name: 'int2',
8
- oid: constants_js_1.DataTypeOIDs.int2,
9
- jsType: 'number',
10
- parseBinary(v) {
11
- return v.readInt16BE(0);
12
- },
13
- encodeBinary(buf, v) {
14
- buf.writeInt16BE((0, fast_parseint_js_1.fastParseInt)(v));
15
- },
16
- parseText: fast_parseint_js_1.fastParseInt,
17
- isType(v) {
18
- return (typeof v === 'number' && Number.isInteger(v) && v >= -32768 && v <= 32767);
19
- },
20
- };
21
- exports.ArrayInt2Type = {
22
- ...exports.Int2Type,
23
- name: '_int2',
24
- oid: constants_js_1.DataTypeOIDs._int2,
25
- elementsOID: constants_js_1.DataTypeOIDs.int2,
26
- };
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayInt2VectorType = exports.Int2VectorType = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- const decode_binaryarray_js_1 = require("../util/decode-binaryarray.js");
6
- const encode_binaryarray_js_1 = require("../util/encode-binaryarray.js");
7
- const fast_parseint_js_1 = require("../util/fast-parseint.js");
8
- exports.Int2VectorType = {
9
- name: 'int2vector',
10
- oid: constants_js_1.DataTypeOIDs.int2vector,
11
- jsType: 'array',
12
- parseBinary(v) {
13
- return (0, decode_binaryarray_js_1.decodeBinaryArray)(v, b => b.readInt16BE()) || undefined;
14
- },
15
- encodeBinary(buf, v) {
16
- (0, encode_binaryarray_js_1.encodeBinaryArray)(buf, v, constants_js_1.DataTypeOIDs.int2, {}, (io, x) => {
17
- io.writeInt16BE(x);
18
- });
19
- },
20
- encodeCalculateDim(v) {
21
- return [v.length];
22
- },
23
- parseText(str) {
24
- return str.split(' ').map(fast_parseint_js_1.fastParseInt);
25
- },
26
- encodeText(v) {
27
- return v.join(' ');
28
- },
29
- isType(v) {
30
- return (Array.isArray(v) &&
31
- !v.find(x => !(typeof x === 'number' &&
32
- Number.isInteger(x) &&
33
- x >= -32768 &&
34
- x <= 32767)));
35
- },
36
- };
37
- exports.ArrayInt2VectorType = {
38
- ...exports.Int2VectorType,
39
- name: '_int2vector',
40
- oid: constants_js_1.DataTypeOIDs._int2vector,
41
- elementsOID: constants_js_1.DataTypeOIDs.int2vector,
42
- };
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayInt4Type = exports.Int4Type = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- const fast_parseint_js_1 = require("../util/fast-parseint.js");
6
- exports.Int4Type = {
7
- name: 'int4',
8
- oid: constants_js_1.DataTypeOIDs.int4,
9
- jsType: 'number',
10
- parseBinary(v) {
11
- return v.readInt32BE(0);
12
- },
13
- encodeBinary(buf, v) {
14
- buf.writeInt32BE((0, fast_parseint_js_1.fastParseInt)(v));
15
- },
16
- parseText: fast_parseint_js_1.fastParseInt,
17
- isType(v) {
18
- return (typeof v === 'number' &&
19
- Number.isInteger(v) &&
20
- v <= Number.MAX_SAFE_INTEGER);
21
- },
22
- };
23
- exports.ArrayInt4Type = {
24
- ...exports.Int4Type,
25
- name: '_int4',
26
- oid: constants_js_1.DataTypeOIDs._int4,
27
- elementsOID: constants_js_1.DataTypeOIDs.int4,
28
- };
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayInt8Type = exports.Int8Type = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- const bigint_methods_js_1 = require("../util/bigint-methods.js");
6
- const maxSafeInteger = BigInt(Number.MAX_SAFE_INTEGER);
7
- exports.Int8Type = {
8
- name: 'int8',
9
- oid: constants_js_1.DataTypeOIDs.int8,
10
- jsType: 'BigInt',
11
- parseBinary(buf) {
12
- const v = typeof buf.readBigInt64BE === 'function'
13
- ? buf.readBigInt64BE(0)
14
- : (0, bigint_methods_js_1.readBigInt64BE)(buf);
15
- return v >= -maxSafeInteger && v <= maxSafeInteger ? Number(v) : v;
16
- },
17
- encodeBinary(buf, v) {
18
- buf.writeBigInt64BE(v);
19
- },
20
- parseText(s) {
21
- const v = BigInt(s);
22
- return v >= -maxSafeInteger && v <= maxSafeInteger ? Number(v) : v;
23
- },
24
- isType(v) {
25
- return (typeof v === 'bigint' ||
26
- (typeof v === 'number' &&
27
- Number.isInteger(v) &&
28
- v > Number.MAX_SAFE_INTEGER));
29
- },
30
- };
31
- exports.ArrayInt8Type = {
32
- ...exports.Int8Type,
33
- name: '_int8',
34
- oid: constants_js_1.DataTypeOIDs._int8,
35
- elementsOID: constants_js_1.DataTypeOIDs.int8,
36
- };
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayJsonType = exports.JsonType = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- exports.JsonType = {
6
- name: 'json',
7
- oid: constants_js_1.DataTypeOIDs.json,
8
- jsType: 'string',
9
- parseBinary(v, options) {
10
- const content = v.toString('utf8');
11
- const fetchAsString = options.fetchAsString &&
12
- options.fetchAsString.includes(constants_js_1.DataTypeOIDs.jsonb);
13
- if (fetchAsString)
14
- return content;
15
- return content ? JSON.parse(content) : undefined;
16
- },
17
- encodeText(v) {
18
- if (typeof v === 'object' || typeof v === 'bigint')
19
- return JSON.stringify(v);
20
- if (typeof v === 'boolean')
21
- return v ? 'true' : 'false';
22
- return '' + v;
23
- },
24
- parseText(v, options) {
25
- const fetchAsString = options.fetchAsString &&
26
- options.fetchAsString.includes(constants_js_1.DataTypeOIDs.jsonb);
27
- if (fetchAsString)
28
- return v;
29
- return v ? JSON.parse(v) : null;
30
- },
31
- isType(v) {
32
- return v && typeof v === 'object';
33
- },
34
- };
35
- exports.ArrayJsonType = {
36
- ...exports.JsonType,
37
- name: '_json',
38
- oid: constants_js_1.DataTypeOIDs._json,
39
- elementsOID: constants_js_1.DataTypeOIDs.json,
40
- };
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayJsonbType = exports.JsonbType = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- const buffer_reader_js_1 = require("../protocol/buffer-reader.js");
6
- exports.JsonbType = {
7
- name: 'jsonb',
8
- oid: constants_js_1.DataTypeOIDs.jsonb,
9
- jsType: 'string',
10
- parseBinary(v, options) {
11
- const buf = new buffer_reader_js_1.BufferReader(v);
12
- if (buf.readUInt8() !== 1)
13
- throw new Error('Unexpected Jsonb version value in header');
14
- const fetchAsString = options.fetchAsString &&
15
- options.fetchAsString.includes(constants_js_1.DataTypeOIDs.json);
16
- const content = buf.readLString(buf.length - buf.offset);
17
- if (fetchAsString)
18
- return content;
19
- return content ? JSON.parse(content) : undefined;
20
- },
21
- encodeText(v) {
22
- if (typeof v === 'object' || typeof v === 'bigint')
23
- return JSON.stringify(v);
24
- if (typeof v === 'boolean')
25
- return v ? 'true' : 'false';
26
- return '\x0001' + v;
27
- },
28
- parseText(v, options) {
29
- const fetchAsString = options.fetchAsString &&
30
- options.fetchAsString.includes(constants_js_1.DataTypeOIDs.json);
31
- if (fetchAsString)
32
- return v;
33
- return v ? JSON.parse(v) : null;
34
- },
35
- isType(v) {
36
- return v && typeof v === 'object';
37
- },
38
- };
39
- exports.ArrayJsonbType = {
40
- ...exports.JsonbType,
41
- name: '_jsonb',
42
- oid: constants_js_1.DataTypeOIDs._jsonb,
43
- elementsOID: constants_js_1.DataTypeOIDs.jsonb,
44
- };
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayLsegType = exports.LsegType = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- const LSEG_PATTERN1 = /^\[ *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *, *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *]$/;
6
- const LSEG_PATTERN2 = /^\( *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *, *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *\)$/;
7
- const LSEG_PATTERN3 = /^\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *, *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\)$/;
8
- const LSEG_PATTERN4 = /^(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *, *(-?\d+\.?\d*)$/;
9
- exports.LsegType = {
10
- name: 'lseg',
11
- oid: constants_js_1.DataTypeOIDs.lseg,
12
- jsType: 'object',
13
- parseBinary(v) {
14
- return {
15
- x1: v.readDoubleBE(0),
16
- y1: v.readDoubleBE(8),
17
- x2: v.readDoubleBE(16),
18
- y2: v.readDoubleBE(24),
19
- };
20
- },
21
- encodeBinary(buf, v) {
22
- buf.writeDoubleBE(v.x1);
23
- buf.writeDoubleBE(v.y1);
24
- buf.writeDoubleBE(v.x2);
25
- buf.writeDoubleBE(v.y2);
26
- },
27
- parseText(v) {
28
- const m = v.match(LSEG_PATTERN1) ||
29
- v.match(LSEG_PATTERN2) ||
30
- v.match(LSEG_PATTERN3) ||
31
- v.match(LSEG_PATTERN4);
32
- if (!m)
33
- return undefined;
34
- return {
35
- x1: parseFloat(m[1]),
36
- y1: parseFloat(m[2]),
37
- x2: parseFloat(m[3]),
38
- y2: parseFloat(m[4]),
39
- };
40
- },
41
- isType(v) {
42
- return (typeof v === 'object' &&
43
- Object.keys(v).length === 4 &&
44
- typeof v.x1 === 'number' &&
45
- typeof v.y1 === 'number' &&
46
- typeof v.x2 === 'number' &&
47
- typeof v.y2 === 'number');
48
- },
49
- };
50
- exports.ArrayLsegType = {
51
- ...exports.LsegType,
52
- name: '_lseg',
53
- oid: constants_js_1.DataTypeOIDs._lseg,
54
- elementsOID: constants_js_1.DataTypeOIDs.lseg,
55
- };
@@ -1,125 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayNumericType = exports.NumericType = void 0;
4
- exports.numberBytesToString = numberBytesToString;
5
- const constants_js_1 = require("../constants.js");
6
- const NUMERIC_NEG = 0x4000;
7
- const NUMERIC_NAN = 0xc000;
8
- const DEC_DIGITS = 4;
9
- const ROUND_POWERS = [0, 1000, 100, 10];
10
- exports.NumericType = {
11
- name: 'numeric',
12
- oid: constants_js_1.DataTypeOIDs.numeric,
13
- jsType: 'number',
14
- parseBinary(v) {
15
- const len = v.readInt16BE();
16
- const weight = v.readInt16BE(2);
17
- const sign = v.readInt16BE(4);
18
- const scale = v.readInt16BE(6);
19
- if (sign === NUMERIC_NAN)
20
- return NaN;
21
- const digits = [];
22
- for (let i = 0; i < len; i++) {
23
- digits[i] = v.readInt16BE(8 + i * 2);
24
- }
25
- const numString = numberBytesToString(digits, scale, weight, sign);
26
- return parseFloat(numString);
27
- },
28
- encodeText(v) {
29
- const n = typeof v === 'number' ? v : parseFloat(v);
30
- return '' + n;
31
- },
32
- parseText: parseFloat,
33
- isType(v) {
34
- return typeof v === 'number';
35
- },
36
- };
37
- exports.ArrayNumericType = {
38
- ...exports.NumericType,
39
- name: '_numeric',
40
- oid: constants_js_1.DataTypeOIDs._numeric,
41
- elementsOID: constants_js_1.DataTypeOIDs.numeric,
42
- };
43
- /* https://github.com/pgjdbc/pgjdbc/blob/3eca3a76aa4a04cb28cb960ed674cb67db30b5e3/pgjdbc/src/main/java/org/postgresql/util/ByteConverter.java */
44
- /**
45
- * Convert a number from binary representation to text representation.
46
- * @param digits array of shorts that can be decoded as the number String
47
- * @param scale the scale of the number binary representation
48
- * @param weight the weight of the number binary representation
49
- * @param sign the sign of the number
50
- * @return String the number as String
51
- */
52
- function numberBytesToString(digits, scale, weight, sign) {
53
- let i;
54
- let d;
55
- /*
56
- * Allocate space for the result.
57
- *
58
- * i is set to the # of decimal digits before decimal point.
59
- * dscale is the # of decimal digits we will print after decimal point.
60
- * We may generate as many as DEC_DIGITS-1 excess digits at the end, and in addition we
61
- * need room for sign, decimal point, null terminator.
62
- */
63
- i = (weight + 1) * DEC_DIGITS;
64
- if (i <= 0)
65
- i = 1;
66
- /*
67
- * Output a dash for negative values
68
- */
69
- let out = sign === NUMERIC_NEG ? '-' : '';
70
- /*
71
- * Output all digits before the decimal point
72
- */
73
- if (weight < 0) {
74
- d = weight + 1;
75
- out += '0';
76
- }
77
- else {
78
- for (d = 0; d <= weight; d++) {
79
- /* In the first digit, suppress extra leading decimal zeroes */
80
- out += digitToString(d, digits, d !== 0);
81
- }
82
- }
83
- /*
84
- * If requested, output a decimal point and all the digits that follow it.
85
- * We initially put out a multiple of DEC_DIGITS digits, then truncate if
86
- * needed.
87
- */
88
- if (scale > 0) {
89
- out += '.';
90
- for (i = 0; i < scale; d++, i += DEC_DIGITS) {
91
- out += digitToString(d, digits, true);
92
- }
93
- }
94
- const extra = (i - scale) % DEC_DIGITS;
95
- return out.substr(0, out.length - extra);
96
- }
97
- /* https://github.com/pgjdbc/pgjdbc/blob/3eca3a76aa4a04cb28cb960ed674cb67db30b5e3/pgjdbc/src/main/java/org/postgresql/util/ByteConverter.java */
98
- /**
99
- * Convert a number from binary representation to text representation.
100
- * @param idx index of the digit to be converted in the digits array
101
- * @param digits array of shorts that can be decoded as the number String
102
- * @param alwaysPutIt a flag that indicate whether or not to put the digit char even if it is zero
103
- * @return String the number as String
104
- */
105
- function digitToString(idx, digits, alwaysPutIt) {
106
- let out = '';
107
- let dig = idx >= 0 && idx < digits.length ? digits[idx] : 0;
108
- // Each dig represents 4 decimal digits (e.g. 9999)
109
- // If we continue the number, then we need to print 0 as 0000 (alwaysPutIt parameter is true)
110
- for (let p = 1; p < ROUND_POWERS.length; p++) {
111
- const pow = ROUND_POWERS[p];
112
- const d1 = Math.trunc(dig / pow);
113
- dig -= d1 * pow;
114
- const putit = d1 > 0;
115
- if (putit || alwaysPutIt) {
116
- out += d1;
117
- // We printed a character, so we need to print the rest of the current digits in dig
118
- // For instance, we need to keep printing 000 from 1000 even if idx==0 (== it is the very
119
- // beginning)
120
- alwaysPutIt = true;
121
- }
122
- }
123
- out += dig;
124
- return out;
125
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VectorOidType = exports.ArrayOidType = exports.OidType = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- const fast_parseint_js_1 = require("../util/fast-parseint.js");
6
- exports.OidType = {
7
- name: 'oid',
8
- oid: constants_js_1.DataTypeOIDs.oid,
9
- jsType: 'number',
10
- parseBinary(v) {
11
- return v.readUInt32BE(0);
12
- },
13
- encodeBinary(buf, v) {
14
- buf.writeUInt32BE((0, fast_parseint_js_1.fastParseInt)(v));
15
- },
16
- parseText: fast_parseint_js_1.fastParseInt,
17
- isType(v) {
18
- return typeof v === 'number' && Number.isInteger(v) && !!constants_js_1.DataTypeNames[v];
19
- },
20
- };
21
- exports.ArrayOidType = {
22
- ...exports.OidType,
23
- name: '_oid',
24
- oid: constants_js_1.DataTypeOIDs._oid,
25
- elementsOID: constants_js_1.DataTypeOIDs.oid,
26
- };
27
- exports.VectorOidType = {
28
- ...exports.OidType,
29
- name: '_oidvector',
30
- oid: constants_js_1.DataTypeOIDs.oidvector,
31
- elementsOID: constants_js_1.DataTypeOIDs.oid,
32
- };
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayPointType = exports.PointType = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- const POINT_PATTERN1 = /^\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\)$/;
6
- const POINT_PATTERN2 = /^(-?\d+\.?\d*) *, *(-?\d+\.?\d*)$/;
7
- exports.PointType = {
8
- name: 'point',
9
- oid: constants_js_1.DataTypeOIDs.point,
10
- jsType: 'object',
11
- parseBinary(v) {
12
- return {
13
- x: v.readDoubleBE(0),
14
- y: v.readDoubleBE(8),
15
- };
16
- },
17
- encodeBinary(buf, v) {
18
- buf.writeDoubleBE(v.x);
19
- buf.writeDoubleBE(v.y);
20
- },
21
- parseText(v) {
22
- const m = v.match(POINT_PATTERN1) || v.match(POINT_PATTERN2);
23
- if (!m)
24
- return undefined;
25
- return {
26
- x: parseFloat(m[1]),
27
- y: parseFloat(m[2]),
28
- };
29
- },
30
- isType(v) {
31
- return (typeof v === 'object' &&
32
- Object.keys(v).length === 2 &&
33
- typeof v.x === 'number' &&
34
- typeof v.y === 'number');
35
- },
36
- };
37
- exports.ArrayPointType = {
38
- ...exports.PointType,
39
- name: '_point',
40
- oid: constants_js_1.DataTypeOIDs._point,
41
- elementsOID: constants_js_1.DataTypeOIDs.point,
42
- };
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayTimeType = exports.TimeType = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- const parse_time_js_1 = require("../util/parse-time.js");
6
- const timeMul = 4294967296;
7
- exports.TimeType = {
8
- name: 'time',
9
- oid: constants_js_1.DataTypeOIDs.time,
10
- jsType: 'string',
11
- parseBinary(v, options) {
12
- const fetchAsString = options.fetchAsString &&
13
- options.fetchAsString.includes(constants_js_1.DataTypeOIDs.time);
14
- const hi = v.readInt32BE();
15
- const lo = v.readUInt32BE(4);
16
- let d = new Date((lo + hi * timeMul) / 1000);
17
- if (fetchAsString || !options.utcDates) {
18
- d = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
19
- }
20
- return fetchAsString ? dateToTimeString(d) : d;
21
- },
22
- encodeBinary(buf, v, options) {
23
- if (typeof v === 'string')
24
- v = (0, parse_time_js_1.parseTime)(v, false, options.utcDates);
25
- if (!(v instanceof Date))
26
- v = new Date(v);
27
- // Postgresql ignores timezone data so we are
28
- let n = options.utcDates
29
- ? v.getTime()
30
- : v.getTime() - v.getTimezoneOffset() * 60 * 1000;
31
- n = n * 1000;
32
- const hi = Math.floor(n / timeMul);
33
- const lo = n - hi * timeMul;
34
- buf.writeInt32BE(hi);
35
- buf.writeUInt32BE(lo);
36
- },
37
- parseText(v, options) {
38
- if (options.fetchAsString &&
39
- options.fetchAsString.includes(constants_js_1.DataTypeOIDs.time))
40
- return v;
41
- return (0, parse_time_js_1.parseTime)(v, false, options.utcDates);
42
- },
43
- isType(v) {
44
- return ((v instanceof Date &&
45
- v.getFullYear() === 1970 &&
46
- v.getMonth() === 0 &&
47
- v.getDate() === 1) ||
48
- (typeof v === 'string' && parse_time_js_1.STRICT_TIME_PATTERN.test(v)));
49
- },
50
- };
51
- function padZero(v) {
52
- return v < 9 ? '0' + v : '' + v;
53
- }
54
- function dateToTimeString(d) {
55
- return (padZero(d.getHours()) +
56
- ':' +
57
- padZero(d.getMinutes()) +
58
- ':' +
59
- padZero(d.getSeconds()));
60
- }
61
- exports.ArrayTimeType = {
62
- ...exports.TimeType,
63
- name: '_time',
64
- oid: constants_js_1.DataTypeOIDs._time,
65
- elementsOID: constants_js_1.DataTypeOIDs.time,
66
- };
@@ -1,89 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayTimestampType = exports.TimestampType = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- const parse_datetime_js_1 = require("../util/parse-datetime.js");
6
- const timeShift = 946684800000;
7
- const timeMul = 4294967296;
8
- exports.TimestampType = {
9
- name: 'timestamp',
10
- oid: constants_js_1.DataTypeOIDs.timestamp,
11
- jsType: 'Date',
12
- parseBinary(v, options) {
13
- const fetchAsString = options.fetchAsString &&
14
- options.fetchAsString.includes(constants_js_1.DataTypeOIDs.timestamp);
15
- const hi = v.readInt32BE();
16
- const lo = v.readUInt32BE(4);
17
- if (lo === 0xffffffff && hi === 0x7fffffff)
18
- return fetchAsString ? 'infinity' : Infinity;
19
- if (lo === 0x00000000 && hi === -0x80000000)
20
- return fetchAsString ? '-infinity' : -Infinity;
21
- // Shift from 2000 to 1970
22
- let d = new Date((lo + hi * timeMul) / 1000 + timeShift);
23
- if (fetchAsString || !options.utcDates) {
24
- d = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
25
- }
26
- return fetchAsString ? dateToTimestampString(d) : d;
27
- },
28
- encodeBinary(buf, v, options) {
29
- if (typeof v === 'string')
30
- v = (0, parse_datetime_js_1.parseDateTime)(v, true, false, options.utcDates);
31
- if (v === Infinity) {
32
- buf.writeInt32BE(0x7fffffff); // hi
33
- buf.writeUInt32BE(0xffffffff); // lo
34
- return;
35
- }
36
- if (v === -Infinity) {
37
- buf.writeInt32BE(-0x80000000); // hi
38
- buf.writeUInt32BE(0x00000000); // lo
39
- return;
40
- }
41
- if (!(v instanceof Date))
42
- v = new Date(v);
43
- // Postgresql ignores timezone data so we are
44
- let n = options.utcDates
45
- ? v.getTime()
46
- : v.getTime() - v.getTimezoneOffset() * 60 * 1000;
47
- n = (n - timeShift) * 1000;
48
- const hi = Math.floor(n / timeMul);
49
- const lo = n - hi * timeMul;
50
- buf.writeInt32BE(hi);
51
- buf.writeUInt32BE(lo);
52
- },
53
- parseText(v, options) {
54
- if (options.fetchAsString &&
55
- options.fetchAsString.includes(constants_js_1.DataTypeOIDs.timestamp))
56
- return v;
57
- return (0, parse_datetime_js_1.parseDateTime)(v, true, false, options.utcDates);
58
- },
59
- isType(v) {
60
- return (v instanceof Date &&
61
- !(v.getFullYear() === 1970 && v.getMonth() === 0 && v.getDate() === 1) &&
62
- !(v.getHours() === 0 &&
63
- v.getMinutes() === 0 &&
64
- v.getSeconds() === 0 &&
65
- v.getMilliseconds() === 0));
66
- },
67
- };
68
- function padZero(v) {
69
- return v < 9 ? '0' + v : '' + v;
70
- }
71
- function dateToTimestampString(d) {
72
- return (d.getFullYear() +
73
- '-' +
74
- padZero(d.getMonth() + 1) +
75
- '-' +
76
- padZero(d.getDate()) +
77
- ' ' +
78
- padZero(d.getHours()) +
79
- ':' +
80
- padZero(d.getMinutes()) +
81
- ':' +
82
- padZero(d.getSeconds()));
83
- }
84
- exports.ArrayTimestampType = {
85
- ...exports.TimestampType,
86
- name: '_timestamp',
87
- oid: constants_js_1.DataTypeOIDs._timestamp,
88
- elementsOID: constants_js_1.DataTypeOIDs.timestamp,
89
- };