postgrejs 2.22.1 → 2.22.3

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 (67) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/cjs/connection/connection.js +20 -14
  3. package/cjs/connection/intl-connection.js +12 -5
  4. package/cjs/connection/pool.js +4 -0
  5. package/cjs/connection/portal.js +10 -3
  6. package/cjs/connection/prepared-statement.js +9 -3
  7. package/cjs/constants.js +0 -1
  8. package/cjs/data-type-map.js +15 -3
  9. package/cjs/data-types/bool-type.js +7 -1
  10. package/cjs/data-types/circle-type.js +4 -1
  11. package/cjs/data-types/date-type.js +12 -4
  12. package/cjs/data-types/int2-type.js +1 -1
  13. package/cjs/data-types/int2-vector-type.js +5 -1
  14. package/cjs/data-types/int4-type.js +3 -1
  15. package/cjs/data-types/int8-type.js +7 -2
  16. package/cjs/data-types/json-type.js +4 -2
  17. package/cjs/data-types/jsonb-type.js +4 -2
  18. package/cjs/data-types/lseg-type.js +4 -1
  19. package/cjs/data-types/point-type.js +4 -1
  20. package/cjs/data-types/time-type.js +16 -5
  21. package/cjs/data-types/timestamp-type.js +11 -4
  22. package/cjs/data-types/timestamptz-type.js +4 -2
  23. package/cjs/protocol/backend.js +9 -3
  24. package/cjs/protocol/frontend.js +40 -10
  25. package/cjs/protocol/pg-socket.js +5 -2
  26. package/cjs/protocol/sasl.js +2 -2
  27. package/cjs/protocol/smart-buffer.js +1 -2
  28. package/cjs/safe-event-emitter.js +1 -1
  29. package/cjs/tsconfig-build-cjs.tsbuildinfo +1 -1
  30. package/cjs/util/bigint-methods.js +5 -2
  31. package/cjs/util/connection-config.js +5 -6
  32. package/cjs/util/parse-datetime.js +4 -4
  33. package/cjs/util/parse-row.js +2 -1
  34. package/cjs/util/parse-time.js +3 -2
  35. package/esm/connection/connection.js +20 -14
  36. package/esm/connection/intl-connection.js +12 -5
  37. package/esm/connection/pool.js +5 -1
  38. package/esm/connection/portal.js +10 -3
  39. package/esm/connection/prepared-statement.js +9 -3
  40. package/esm/constants.js +0 -1
  41. package/esm/data-type-map.js +18 -6
  42. package/esm/data-types/bool-type.js +7 -1
  43. package/esm/data-types/circle-type.js +4 -1
  44. package/esm/data-types/date-type.js +12 -4
  45. package/esm/data-types/int2-type.js +1 -1
  46. package/esm/data-types/int2-vector-type.js +5 -1
  47. package/esm/data-types/int4-type.js +3 -1
  48. package/esm/data-types/int8-type.js +7 -2
  49. package/esm/data-types/json-type.js +4 -2
  50. package/esm/data-types/jsonb-type.js +4 -2
  51. package/esm/data-types/lseg-type.js +4 -1
  52. package/esm/data-types/point-type.js +4 -1
  53. package/esm/data-types/time-type.js +16 -5
  54. package/esm/data-types/timestamp-type.js +11 -4
  55. package/esm/data-types/timestamptz-type.js +4 -2
  56. package/esm/protocol/backend.js +9 -3
  57. package/esm/protocol/frontend.js +40 -10
  58. package/esm/protocol/pg-socket.js +5 -2
  59. package/esm/protocol/sasl.js +2 -2
  60. package/esm/protocol/smart-buffer.js +1 -2
  61. package/esm/safe-event-emitter.js +1 -1
  62. package/esm/util/bigint-methods.js +5 -2
  63. package/esm/util/connection-config.js +2 -2
  64. package/esm/util/parse-datetime.js +4 -4
  65. package/esm/util/parse-row.js +2 -1
  66. package/esm/util/parse-time.js +3 -2
  67. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
+ # v2.22.3
2
+ [2025-01-21]
3
+
4
+ ### Changes
5
+
6
+ * dev: Moved to ESLing 9 ([`ce0306a`](https://github.com/panates/postgrejs/commit/ce0306a0ed7dd08ed60c6c05d120c1c7132d3d01))
7
+ * refactor: Updated dependencies ([`8a1eafc`](https://github.com/panates/postgrejs/commit/8a1eafcffae0249a7a4a04330f4d49326c94752b))
8
+ * refactor: Fixed typescript check ([`8e2b843`](https://github.com/panates/postgrejs/commit/8e2b843a1fcd3f871c1103d20ab2672a53ecfef6))
9
+ * ci: Fix purge pg error ([`0c69a55`](https://github.com/panates/postgrejs/commit/0c69a55be31c96a03fb1f2550cc9c7b31a0b02b3))
10
+ * ci: Fix purge pg error ([`bd2ce09`](https://github.com/panates/postgrejs/commit/bd2ce09f50e044e8affc6f0510be38b711f6fc4f))
11
+ * ci: Fix purge pg error ([`e6d8828`](https://github.com/panates/postgrejs/commit/e6d88283d0250141717b3f6587cb7c518ea188fc))
12
+ * ci: Fix purge pg error ([`f1121f3`](https://github.com/panates/postgrejs/commit/f1121f3fd346617e81e1cec0a5592bb3b8643556))
13
+
14
+ # v2.22.2
15
+ [2024-11-04]
16
+
17
+ ### Changes
18
+
19
+ * refactor: Improved displaying error line ([`3a6bbe9`](https://github.com/panates/postgrejs/commit/3a6bbe929efdb4f46a38c7b9626b4f28739ad341))
20
+
1
21
  # v2.22.1
2
- [2024-10-15]
22
+ [2024-10-16]
3
23
 
4
24
  # v2.22.0
5
25
  [2024-10-15]
@@ -12,7 +12,9 @@ class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
12
12
  super();
13
13
  this._notificationListeners = new safe_event_emitter_js_1.SafeEventEmitter();
14
14
  this._closing = false;
15
- if (arg0 && typeof arg0 === 'object' && typeof arg0.acquire === 'function') {
15
+ if (arg0 &&
16
+ typeof arg0 === 'object' &&
17
+ typeof arg0.acquire === 'function') {
16
18
  if (!(arg1 instanceof intl_connection_js_1.IntlConnection))
17
19
  throw new TypeError('Invalid argument');
18
20
  this._pool = arg0;
@@ -94,7 +96,9 @@ class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
94
96
  });
95
97
  }
96
98
  this._closing = true;
97
- if (this._intlCon.refCount > 0 && typeof terminateWait === 'number' && terminateWait > 0) {
99
+ if (this._intlCon.refCount > 0 &&
100
+ typeof terminateWait === 'number' &&
101
+ terminateWait > 0) {
98
102
  const startTime = Date.now();
99
103
  return this._captureErrorStack(new Promise((resolve, reject) => {
100
104
  /* istanbul ignore next */
@@ -106,7 +110,8 @@ class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
106
110
  });
107
111
  }
108
112
  const timer = setInterval(() => {
109
- if (this._intlCon.refCount <= 0 || Date.now() > startTime + terminateWait) {
113
+ if (this._intlCon.refCount <= 0 ||
114
+ Date.now() > startTime + terminateWait) {
110
115
  clearInterval(timer);
111
116
  if (this._intlCon.refCount > 0) {
112
117
  /* istanbul ignore next */
@@ -133,6 +138,7 @@ class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
133
138
  * @param options {ScriptExecuteOptions} - Execute options
134
139
  */
135
140
  async execute(sql, options) {
141
+ this.emit('execute', sql, options);
136
142
  return this._captureErrorStack(this._intlCon.execute(sql, options)).catch((e) => {
137
143
  throw this._handleError(e, sql);
138
144
  });
@@ -148,13 +154,14 @@ class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
148
154
  sql,
149
155
  });
150
156
  }
157
+ this.emit('query', sql, options);
151
158
  const typeMap = options?.typeMap || data_type_map_js_1.GlobalTypeMap;
152
159
  const paramTypes = options?.params?.map(prm => prm instanceof bind_param_js_1.BindParam ? prm.oid : typeMap.determine(prm));
153
160
  const statement = await this.prepare(sql, { paramTypes, typeMap }).catch((e) => {
154
161
  throw this._handleError(e, sql);
155
162
  });
156
163
  try {
157
- const params = options?.params?.map(prm => (prm instanceof bind_param_js_1.BindParam ? prm.value : prm));
164
+ const params = options?.params?.map(prm => prm instanceof bind_param_js_1.BindParam ? prm.value : prm);
158
165
  return await this._captureErrorStack(statement.execute({ ...options, params }));
159
166
  }
160
167
  finally {
@@ -251,17 +258,16 @@ class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
251
258
  this._closing = false;
252
259
  }
253
260
  _handleError(err, script) {
254
- if (err.position) {
255
- const i1 = script.lastIndexOf('\n', err.position) + 1;
256
- let i2 = script.indexOf('\n', err.position);
257
- if (i2 < 0)
258
- i2 = Number.MAX_SAFE_INTEGER;
259
- err.line = script.substring(i1, i2);
260
- err.lineNr = [...script.substring(0, i1).matchAll(/\n/g)].length;
261
+ if (err.position != null) {
262
+ const i1 = script.lastIndexOf('\n', err.position - 1) + 1;
263
+ err.lineNr = [...script.substring(0, i1).matchAll(/\n/g)].length + 1;
261
264
  err.colNr = err.position - i1;
262
- err.message +=
263
- `\nAt line ${err.lineNr} column ${err.colNr}` +
264
- `\n | ${err.line}\n | ${' '.repeat(Math.max(err.colNr - 2, 0))}-^-`;
265
+ const lines = script.split('\n');
266
+ err.line = lines[err.lineNr - 1];
267
+ err.message += `\n at line ${err.lineNr} column ${err.colNr}`;
268
+ if (err.lineNr > 1)
269
+ err.message += `\n${String(err.lineNr - 1).padStart(3)}| ${lines[err.lineNr - 2]}`;
270
+ err.message += `\n${String(err.lineNr).padStart(3)}| ${err.line}\n .${'-'.repeat(Math.max(err.colNr - 1, 0))}^`;
265
271
  }
266
272
  return err;
267
273
  }
@@ -65,9 +65,11 @@ class IntlConnection extends safe_event_emitter_js_1.SafeEventEmitter {
65
65
  });
66
66
  let startupCommand = '';
67
67
  if (this.config.schema)
68
- startupCommand += 'SET search_path = ' + (0, escape_literal_js_1.escapeLiteral)(this.config.schema) + ';';
68
+ startupCommand +=
69
+ 'SET search_path = ' + (0, escape_literal_js_1.escapeLiteral)(this.config.schema) + ';';
69
70
  if (this.config.timezone)
70
- startupCommand += 'SET timezone TO ' + (0, escape_literal_js_1.escapeLiteral)(this.config.timezone) + ';';
71
+ startupCommand +=
72
+ 'SET timezone TO ' + (0, escape_literal_js_1.escapeLiteral)(this.config.timezone) + ';';
71
73
  if (startupCommand)
72
74
  await this.execute(startupCommand, { autoCommit: true });
73
75
  this.emit('ready');
@@ -95,7 +97,9 @@ class IntlConnection extends safe_event_emitter_js_1.SafeEventEmitter {
95
97
  let commitLast = false;
96
98
  if (!transactionCommand) {
97
99
  if (!this.inTransaction &&
98
- (options?.autoCommit != null ? options?.autoCommit : this.config.autoCommit) === false) {
100
+ (options?.autoCommit != null
101
+ ? options?.autoCommit
102
+ : this.config.autoCommit) === false) {
99
103
  beginFirst = true;
100
104
  }
101
105
  if (this.inTransaction && options?.autoCommit)
@@ -211,12 +215,15 @@ class IntlConnection extends safe_event_emitter_js_1.SafeEventEmitter {
211
215
  case protocol_js_1.Protocol.BackendMessageCode.CommandComplete:
212
216
  // Ignore BEGIN command that we added to sql
213
217
  current.command = msg.command;
214
- if (current.command === 'DELETE' || current.command === 'INSERT' || current.command === 'UPDATE') {
218
+ if (current.command === 'DELETE' ||
219
+ current.command === 'INSERT' ||
220
+ current.command === 'UPDATE') {
215
221
  current.rowsAffected = msg.rowCount;
216
222
  }
217
223
  current.executeTime = Date.now() - currentStart;
218
224
  if (current.rows)
219
- current.rowType = opts.objectRows && current.fields ? 'object' : 'array';
225
+ current.rowType =
226
+ opts.objectRows && current.fields ? 'object' : 'array';
220
227
  result.results.push(current);
221
228
  if (cb)
222
229
  cb('command-complete', current);
@@ -135,6 +135,10 @@ class Pool extends safe_event_emitter_js_1.SafeEventEmitter {
135
135
  /* istanbul ignore next */
136
136
  if (this.listenerCount('debug'))
137
137
  connection.on('debug', (...args) => this.emit('debug', ...args));
138
+ if (this.listenerCount('execute'))
139
+ connection.on('execute', (...args) => this.emit('execute', ...args));
140
+ if (this.listenerCount('query'))
141
+ connection.on('query', (...args) => this.emit('query', ...args));
138
142
  return connection;
139
143
  }
140
144
  /**
@@ -22,7 +22,10 @@ class Portal {
22
22
  intoCon.ref();
23
23
  try {
24
24
  const socket = intoCon.socket;
25
- this._columnFormat = queryOptions.columnFormat != null ? queryOptions.columnFormat : protocol_js_1.Protocol.DataFormat.binary;
25
+ this._columnFormat =
26
+ queryOptions.columnFormat != null
27
+ ? queryOptions.columnFormat
28
+ : protocol_js_1.Protocol.DataFormat.binary;
26
29
  socket.sendBindMessage({
27
30
  typeMap: queryOptions.typeMap || data_type_map_js_1.GlobalTypeMap,
28
31
  statement: this._statement.name,
@@ -79,7 +82,10 @@ class Portal {
79
82
  intoCon.ref();
80
83
  try {
81
84
  const socket = intoCon.socket;
82
- socket.sendExecuteMessage({ portal: this.name, fetchCount: fetchCount || 100 });
85
+ socket.sendExecuteMessage({
86
+ portal: this.name,
87
+ fetchCount: fetchCount || 100,
88
+ });
83
89
  socket.sendFlushMessage();
84
90
  const rows = [];
85
91
  return await socket.capture(async (code, msg, done) => {
@@ -91,7 +97,8 @@ class Portal {
91
97
  break;
92
98
  case protocol_js_1.Protocol.BackendMessageCode.DataRow:
93
99
  if (Array.isArray(this._columnFormat)) {
94
- rows.push(msg.columns.map((buf, i) => this._columnFormat[i] === protocol_js_1.Protocol.DataFormat.text
100
+ rows.push(msg.columns.map((buf, i) => this._columnFormat[i] ===
101
+ protocol_js_1.Protocol.DataFormat.text
95
102
  ? buf.toString('utf8')
96
103
  : buf));
97
104
  }
@@ -85,7 +85,9 @@ class PreparedStatement extends safe_event_emitter_js_1.SafeEventEmitter {
85
85
  let commitLast = false;
86
86
  if (!transactionCommand) {
87
87
  if (!intlCon.inTransaction &&
88
- (options?.autoCommit != null ? options?.autoCommit : intlCon.config.autoCommit) === false) {
88
+ (options?.autoCommit != null
89
+ ? options?.autoCommit
90
+ : intlCon.config.autoCommit) === false) {
89
91
  beginFirst = true;
90
92
  }
91
93
  if (intlCon.inTransaction && options?.autoCommit)
@@ -100,7 +102,9 @@ class PreparedStatement extends safe_event_emitter_js_1.SafeEventEmitter {
100
102
  if (intlCon.inTransaction && rollbackOnError)
101
103
  await intlCon.execute('SAVEPOINT ' + this._onErrorSavePoint);
102
104
  try {
103
- const result = await intlCon.statementQueue.enqueue(() => this._execute(options)).toPromise();
105
+ const result = await intlCon.statementQueue
106
+ .enqueue(() => this._execute(options))
107
+ .toPromise();
104
108
  if (commitLast)
105
109
  await intlCon.execute('COMMIT');
106
110
  else if (intlCon.inTransaction && rollbackOnError) {
@@ -171,7 +175,9 @@ class PreparedStatement extends safe_event_emitter_js_1.SafeEventEmitter {
171
175
  }
172
176
  }
173
177
  }
174
- if (result.command === 'DELETE' || result.command === 'INSERT' || result.command === 'UPDATE') {
178
+ if (result.command === 'DELETE' ||
179
+ result.command === 'INSERT' ||
180
+ result.command === 'UPDATE') {
175
181
  result.rowsAffected = executeResult.rowCount;
176
182
  }
177
183
  result.executeTime = Date.now() - startTime;
package/cjs/constants.js CHANGED
@@ -71,7 +71,6 @@ exports.DataTypeOIDs = {
71
71
  anyarray: 2277,
72
72
  void: 2278,
73
73
  trigger: 2279,
74
- // eslint-disable-next-line camelcase
75
74
  language_handler: 2280,
76
75
  internal: 2281,
77
76
  anyelement: 2283,
@@ -82,21 +82,33 @@ exports.GlobalTypeMap.register([point_type_js_1.PointType, point_type_js_1.Array
82
82
  exports.GlobalTypeMap.register([lseg_type_js_1.LsegType, lseg_type_js_1.ArrayLsegType]);
83
83
  exports.GlobalTypeMap.register([box_type_js_1.BoxType, box_type_js_1.ArrayBoxType]);
84
84
  exports.GlobalTypeMap.register([int2_vector_type_js_1.Int2VectorType, int2_vector_type_js_1.ArrayInt2VectorType]);
85
- exports.GlobalTypeMap.register({ ...varchar_type_js_1.VarcharType, name: 'bpchar', oid: constants_js_1.DataTypeOIDs.bpchar });
85
+ exports.GlobalTypeMap.register({
86
+ ...varchar_type_js_1.VarcharType,
87
+ name: 'bpchar',
88
+ oid: constants_js_1.DataTypeOIDs.bpchar,
89
+ });
86
90
  exports.GlobalTypeMap.register({
87
91
  ...varchar_type_js_1.ArrayVarcharType,
88
92
  name: '_bpchar',
89
93
  oid: constants_js_1.DataTypeOIDs._bpchar,
90
94
  elementsOID: constants_js_1.DataTypeOIDs.bpchar,
91
95
  });
92
- exports.GlobalTypeMap.register({ ...varchar_type_js_1.VarcharType, name: 'name', oid: constants_js_1.DataTypeOIDs.name });
96
+ exports.GlobalTypeMap.register({
97
+ ...varchar_type_js_1.VarcharType,
98
+ name: 'name',
99
+ oid: constants_js_1.DataTypeOIDs.name,
100
+ });
93
101
  exports.GlobalTypeMap.register({
94
102
  ...varchar_type_js_1.ArrayVarcharType,
95
103
  name: '_name',
96
104
  oid: constants_js_1.DataTypeOIDs._name,
97
105
  elementsOID: constants_js_1.DataTypeOIDs.name,
98
106
  });
99
- exports.GlobalTypeMap.register({ ...varchar_type_js_1.VarcharType, name: 'text', oid: constants_js_1.DataTypeOIDs.text });
107
+ exports.GlobalTypeMap.register({
108
+ ...varchar_type_js_1.VarcharType,
109
+ name: 'text',
110
+ oid: constants_js_1.DataTypeOIDs.text,
111
+ });
100
112
  exports.GlobalTypeMap.register({
101
113
  ...varchar_type_js_1.ArrayVarcharType,
102
114
  name: '_text',
@@ -13,7 +13,13 @@ exports.BoolType = {
13
13
  buf.writeInt8(v ? 1 : 0);
14
14
  },
15
15
  parseText(v) {
16
- return v === 'TRUE' || v === 't' || v === 'true' || v === 'y' || v === 'yes' || v === 'on' || v === '1';
16
+ return (v === 'TRUE' ||
17
+ v === 't' ||
18
+ v === 'true' ||
19
+ v === 'y' ||
20
+ v === 'yes' ||
21
+ v === 'on' ||
22
+ v === '1');
17
23
  },
18
24
  isType(v) {
19
25
  return typeof v === 'boolean';
@@ -23,7 +23,10 @@ exports.CircleType = {
23
23
  buf.writeDoubleBE(v.r);
24
24
  },
25
25
  parseText(v) {
26
- const m = v.match(CIRCLE_PATTERN1) || v.match(CIRCLE_PATTERN2) || v.match(CIRCLE_PATTERN3) || v.match(CIRCLE_PATTERN4);
26
+ const m = v.match(CIRCLE_PATTERN1) ||
27
+ v.match(CIRCLE_PATTERN2) ||
28
+ v.match(CIRCLE_PATTERN3) ||
29
+ v.match(CIRCLE_PATTERN4);
27
30
  if (!m)
28
31
  return undefined;
29
32
  return {
@@ -9,7 +9,8 @@ exports.DateType = {
9
9
  oid: constants_js_1.DataTypeOIDs.date,
10
10
  jsType: 'Date',
11
11
  parseBinary(v, options) {
12
- const fetchAsString = options.fetchAsString && options.fetchAsString.includes(constants_js_1.DataTypeOIDs.date);
12
+ const fetchAsString = options.fetchAsString &&
13
+ options.fetchAsString.includes(constants_js_1.DataTypeOIDs.date);
13
14
  const t = v.readInt32BE();
14
15
  if (t === 0x7fffffff)
15
16
  return fetchAsString ? 'infinity' : Infinity;
@@ -34,13 +35,16 @@ exports.DateType = {
34
35
  }
35
36
  if (!(v instanceof Date))
36
37
  v = new Date(v);
37
- let n = options.utcDates ? v.getTime() : v.getTime() - v.getTimezoneOffset() * 60 * 1000;
38
+ let n = options.utcDates
39
+ ? v.getTime()
40
+ : v.getTime() - v.getTimezoneOffset() * 60 * 1000;
38
41
  n = (n - timeShift) / 1000 / 86400;
39
42
  const t = Math.trunc(n + Number.EPSILON);
40
43
  buf.writeInt32BE(t);
41
44
  },
42
45
  parseText(v, options) {
43
- const fetchAsString = options.fetchAsString && options.fetchAsString.includes(constants_js_1.DataTypeOIDs.date);
46
+ const fetchAsString = options.fetchAsString &&
47
+ options.fetchAsString.includes(constants_js_1.DataTypeOIDs.date);
44
48
  if (fetchAsString)
45
49
  return v;
46
50
  return (0, parse_datetime_js_1.parseDateTime)(v, false, false, options.utcDates);
@@ -57,7 +61,11 @@ function padZero(v) {
57
61
  return v < 9 ? '0' + v : '' + v;
58
62
  }
59
63
  function dateToDateString(d) {
60
- return d.getFullYear() + '-' + padZero(d.getMonth() + 1) + '-' + padZero(d.getDate());
64
+ return (d.getFullYear() +
65
+ '-' +
66
+ padZero(d.getMonth() + 1) +
67
+ '-' +
68
+ padZero(d.getDate()));
61
69
  }
62
70
  exports.ArrayDateType = {
63
71
  ...exports.DateType,
@@ -15,7 +15,7 @@ exports.Int2Type = {
15
15
  },
16
16
  parseText: fast_parseint_js_1.fastParseInt,
17
17
  isType(v) {
18
- return typeof v === 'number' && Number.isInteger(v) && v >= -32768 && v <= 32767;
18
+ return (typeof v === 'number' && Number.isInteger(v) && v >= -32768 && v <= 32767);
19
19
  },
20
20
  };
21
21
  exports.ArrayInt2Type = {
@@ -27,7 +27,11 @@ exports.Int2VectorType = {
27
27
  return v.join(' ');
28
28
  },
29
29
  isType(v) {
30
- return (Array.isArray(v) && !v.find(x => !(typeof x === 'number' && Number.isInteger(x) && x >= -32768 && x <= 32767)));
30
+ return (Array.isArray(v) &&
31
+ !v.find(x => !(typeof x === 'number' &&
32
+ Number.isInteger(x) &&
33
+ x >= -32768 &&
34
+ x <= 32767)));
31
35
  },
32
36
  };
33
37
  exports.ArrayInt2VectorType = {
@@ -15,7 +15,9 @@ exports.Int4Type = {
15
15
  },
16
16
  parseText: fast_parseint_js_1.fastParseInt,
17
17
  isType(v) {
18
- return typeof v === 'number' && Number.isInteger(v) && v <= Number.MAX_SAFE_INTEGER;
18
+ return (typeof v === 'number' &&
19
+ Number.isInteger(v) &&
20
+ v <= Number.MAX_SAFE_INTEGER);
19
21
  },
20
22
  };
21
23
  exports.ArrayInt4Type = {
@@ -9,7 +9,9 @@ exports.Int8Type = {
9
9
  oid: constants_js_1.DataTypeOIDs.int8,
10
10
  jsType: 'BigInt',
11
11
  parseBinary(buf) {
12
- const v = typeof buf.readBigInt64BE === 'function' ? buf.readBigInt64BE(0) : (0, bigint_methods_js_1.readBigInt64BE)(buf);
12
+ const v = typeof buf.readBigInt64BE === 'function'
13
+ ? buf.readBigInt64BE(0)
14
+ : (0, bigint_methods_js_1.readBigInt64BE)(buf);
13
15
  return v >= -maxSafeInteger && v <= maxSafeInteger ? Number(v) : v;
14
16
  },
15
17
  encodeBinary(buf, v) {
@@ -20,7 +22,10 @@ exports.Int8Type = {
20
22
  return v >= -maxSafeInteger && v <= maxSafeInteger ? Number(v) : v;
21
23
  },
22
24
  isType(v) {
23
- return typeof v === 'bigint' || (typeof v === 'number' && Number.isInteger(v) && v > Number.MAX_SAFE_INTEGER);
25
+ return (typeof v === 'bigint' ||
26
+ (typeof v === 'number' &&
27
+ Number.isInteger(v) &&
28
+ v > Number.MAX_SAFE_INTEGER));
24
29
  },
25
30
  };
26
31
  exports.ArrayInt8Type = {
@@ -8,7 +8,8 @@ exports.JsonType = {
8
8
  jsType: 'string',
9
9
  parseBinary(v, options) {
10
10
  const content = v.toString('utf8');
11
- const fetchAsString = options.fetchAsString && options.fetchAsString.includes(constants_js_1.DataTypeOIDs.jsonb);
11
+ const fetchAsString = options.fetchAsString &&
12
+ options.fetchAsString.includes(constants_js_1.DataTypeOIDs.jsonb);
12
13
  if (fetchAsString)
13
14
  return content;
14
15
  return content ? JSON.parse(content) : undefined;
@@ -21,7 +22,8 @@ exports.JsonType = {
21
22
  return '' + v;
22
23
  },
23
24
  parseText(v, options) {
24
- const fetchAsString = options.fetchAsString && options.fetchAsString.includes(constants_js_1.DataTypeOIDs.jsonb);
25
+ const fetchAsString = options.fetchAsString &&
26
+ options.fetchAsString.includes(constants_js_1.DataTypeOIDs.jsonb);
25
27
  if (fetchAsString)
26
28
  return v;
27
29
  return v ? JSON.parse(v) : null;
@@ -11,7 +11,8 @@ exports.JsonbType = {
11
11
  const buf = new buffer_reader_js_1.BufferReader(v);
12
12
  if (buf.readUInt8() !== 1)
13
13
  throw new Error('Unexpected Jsonb version value in header');
14
- const fetchAsString = options.fetchAsString && options.fetchAsString.includes(constants_js_1.DataTypeOIDs.json);
14
+ const fetchAsString = options.fetchAsString &&
15
+ options.fetchAsString.includes(constants_js_1.DataTypeOIDs.json);
15
16
  const content = buf.readLString(buf.length - buf.offset);
16
17
  if (fetchAsString)
17
18
  return content;
@@ -25,7 +26,8 @@ exports.JsonbType = {
25
26
  return '\x0001' + v;
26
27
  },
27
28
  parseText(v, options) {
28
- const fetchAsString = options.fetchAsString && options.fetchAsString.includes(constants_js_1.DataTypeOIDs.json);
29
+ const fetchAsString = options.fetchAsString &&
30
+ options.fetchAsString.includes(constants_js_1.DataTypeOIDs.json);
29
31
  if (fetchAsString)
30
32
  return v;
31
33
  return v ? JSON.parse(v) : null;
@@ -25,7 +25,10 @@ exports.LsegType = {
25
25
  buf.writeDoubleBE(v.y2);
26
26
  },
27
27
  parseText(v) {
28
- const m = v.match(LSEG_PATTERN1) || v.match(LSEG_PATTERN2) || v.match(LSEG_PATTERN3) || v.match(LSEG_PATTERN4);
28
+ const m = v.match(LSEG_PATTERN1) ||
29
+ v.match(LSEG_PATTERN2) ||
30
+ v.match(LSEG_PATTERN3) ||
31
+ v.match(LSEG_PATTERN4);
29
32
  if (!m)
30
33
  return undefined;
31
34
  return {
@@ -28,7 +28,10 @@ exports.PointType = {
28
28
  };
29
29
  },
30
30
  isType(v) {
31
- return typeof v === 'object' && Object.keys(v).length === 2 && typeof v.x === 'number' && typeof v.y === 'number';
31
+ return (typeof v === 'object' &&
32
+ Object.keys(v).length === 2 &&
33
+ typeof v.x === 'number' &&
34
+ typeof v.y === 'number');
32
35
  },
33
36
  };
34
37
  exports.ArrayPointType = {
@@ -9,7 +9,8 @@ exports.TimeType = {
9
9
  oid: constants_js_1.DataTypeOIDs.time,
10
10
  jsType: 'string',
11
11
  parseBinary(v, options) {
12
- const fetchAsString = options.fetchAsString && options.fetchAsString.includes(constants_js_1.DataTypeOIDs.time);
12
+ const fetchAsString = options.fetchAsString &&
13
+ options.fetchAsString.includes(constants_js_1.DataTypeOIDs.time);
13
14
  const hi = v.readInt32BE();
14
15
  const lo = v.readUInt32BE(4);
15
16
  let d = new Date((lo + hi * timeMul) / 1000);
@@ -24,7 +25,9 @@ exports.TimeType = {
24
25
  if (!(v instanceof Date))
25
26
  v = new Date(v);
26
27
  // Postgresql ignores timezone data so we are
27
- let n = options.utcDates ? v.getTime() : v.getTime() - v.getTimezoneOffset() * 60 * 1000;
28
+ let n = options.utcDates
29
+ ? v.getTime()
30
+ : v.getTime() - v.getTimezoneOffset() * 60 * 1000;
28
31
  n = n * 1000;
29
32
  const hi = Math.floor(n / timeMul);
30
33
  const lo = n - hi * timeMul;
@@ -32,12 +35,16 @@ exports.TimeType = {
32
35
  buf.writeUInt32BE(lo);
33
36
  },
34
37
  parseText(v, options) {
35
- if (options.fetchAsString && options.fetchAsString.includes(constants_js_1.DataTypeOIDs.time))
38
+ if (options.fetchAsString &&
39
+ options.fetchAsString.includes(constants_js_1.DataTypeOIDs.time))
36
40
  return v;
37
41
  return (0, parse_time_js_1.parseTime)(v, false, options.utcDates);
38
42
  },
39
43
  isType(v) {
40
- return ((v instanceof Date && v.getFullYear() === 1970 && v.getMonth() === 0 && v.getDate() === 1) ||
44
+ return ((v instanceof Date &&
45
+ v.getFullYear() === 1970 &&
46
+ v.getMonth() === 0 &&
47
+ v.getDate() === 1) ||
41
48
  (typeof v === 'string' && parse_time_js_1.STRICT_TIME_PATTERN.test(v)));
42
49
  },
43
50
  };
@@ -45,7 +52,11 @@ function padZero(v) {
45
52
  return v < 9 ? '0' + v : '' + v;
46
53
  }
47
54
  function dateToTimeString(d) {
48
- return padZero(d.getHours()) + ':' + padZero(d.getMinutes()) + ':' + padZero(d.getSeconds());
55
+ return (padZero(d.getHours()) +
56
+ ':' +
57
+ padZero(d.getMinutes()) +
58
+ ':' +
59
+ padZero(d.getSeconds()));
49
60
  }
50
61
  exports.ArrayTimeType = {
51
62
  ...exports.TimeType,
@@ -10,7 +10,8 @@ exports.TimestampType = {
10
10
  oid: constants_js_1.DataTypeOIDs.timestamp,
11
11
  jsType: 'Date',
12
12
  parseBinary(v, options) {
13
- const fetchAsString = options.fetchAsString && options.fetchAsString.includes(constants_js_1.DataTypeOIDs.timestamp);
13
+ const fetchAsString = options.fetchAsString &&
14
+ options.fetchAsString.includes(constants_js_1.DataTypeOIDs.timestamp);
14
15
  const hi = v.readInt32BE();
15
16
  const lo = v.readUInt32BE(4);
16
17
  if (lo === 0xffffffff && hi === 0x7fffffff)
@@ -40,7 +41,9 @@ exports.TimestampType = {
40
41
  if (!(v instanceof Date))
41
42
  v = new Date(v);
42
43
  // Postgresql ignores timezone data so we are
43
- let n = options.utcDates ? v.getTime() : v.getTime() - v.getTimezoneOffset() * 60 * 1000;
44
+ let n = options.utcDates
45
+ ? v.getTime()
46
+ : v.getTime() - v.getTimezoneOffset() * 60 * 1000;
44
47
  n = (n - timeShift) * 1000;
45
48
  const hi = Math.floor(n / timeMul);
46
49
  const lo = n - hi * timeMul;
@@ -48,14 +51,18 @@ exports.TimestampType = {
48
51
  buf.writeUInt32BE(lo);
49
52
  },
50
53
  parseText(v, options) {
51
- if (options.fetchAsString && options.fetchAsString.includes(constants_js_1.DataTypeOIDs.timestamp))
54
+ if (options.fetchAsString &&
55
+ options.fetchAsString.includes(constants_js_1.DataTypeOIDs.timestamp))
52
56
  return v;
53
57
  return (0, parse_datetime_js_1.parseDateTime)(v, true, false, options.utcDates);
54
58
  },
55
59
  isType(v) {
56
60
  return (v instanceof Date &&
57
61
  !(v.getFullYear() === 1970 && v.getMonth() === 0 && v.getDate() === 1) &&
58
- !(v.getHours() === 0 && v.getMinutes() === 0 && v.getSeconds() === 0 && v.getMilliseconds() === 0));
62
+ !(v.getHours() === 0 &&
63
+ v.getMinutes() === 0 &&
64
+ v.getSeconds() === 0 &&
65
+ v.getMilliseconds() === 0));
59
66
  },
60
67
  };
61
68
  function padZero(v) {
@@ -10,7 +10,8 @@ exports.TimestamptzType = {
10
10
  oid: constants_js_1.DataTypeOIDs.timestamptz,
11
11
  jsType: 'Date',
12
12
  parseBinary(v, options) {
13
- const fetchAsString = options.fetchAsString && options.fetchAsString.includes(constants_js_1.DataTypeOIDs.timestamptz);
13
+ const fetchAsString = options.fetchAsString &&
14
+ options.fetchAsString.includes(constants_js_1.DataTypeOIDs.timestamptz);
14
15
  const hi = v.readInt32BE();
15
16
  const lo = v.readUInt32BE(4);
16
17
  if (lo === 0xffffffff && hi === 0x7fffffff)
@@ -48,7 +49,8 @@ exports.TimestamptzType = {
48
49
  },
49
50
  parseText(v, options) {
50
51
  const d = (0, parse_datetime_js_1.parseDateTime)(v, true, true, options.utcDates);
51
- if (options.fetchAsString && options.fetchAsString.includes(constants_js_1.DataTypeOIDs.timestamptz)) {
52
+ if (options.fetchAsString &&
53
+ options.fetchAsString.includes(constants_js_1.DataTypeOIDs.timestamptz)) {
52
54
  if (d instanceof Date)
53
55
  return dateToTimestamptzString(d);
54
56
  if (d === Infinity)
@@ -154,13 +154,17 @@ function parseCopyData(io, code, len) {
154
154
  }
155
155
  function parseCopyResponse(io) {
156
156
  const out = {
157
- overallFormat: io.readUInt8() === 0 ? protocol_js_1.Protocol.DataFormat.text : protocol_js_1.Protocol.DataFormat.binary,
157
+ overallFormat: io.readUInt8() === 0
158
+ ? protocol_js_1.Protocol.DataFormat.text
159
+ : protocol_js_1.Protocol.DataFormat.binary,
158
160
  columnCount: io.readUInt16BE(),
159
161
  };
160
162
  if (out.columnCount) {
161
163
  out.columnFormats = [];
162
164
  for (let i = 0; i < out.columnCount; i++) {
163
- out.columnFormats.push(io.readUInt16BE() === 0 ? protocol_js_1.Protocol.DataFormat.text : protocol_js_1.Protocol.DataFormat.binary);
165
+ out.columnFormats.push(io.readUInt16BE() === 0
166
+ ? protocol_js_1.Protocol.DataFormat.text
167
+ : protocol_js_1.Protocol.DataFormat.binary);
164
168
  }
165
169
  }
166
170
  return out;
@@ -248,7 +252,9 @@ function parseRowDescription(io) {
248
252
  dataTypeId: io.readInt32BE(),
249
253
  fixedSize: io.readInt16BE(),
250
254
  modifier: io.readInt32BE(),
251
- format: io.readInt16BE() === 0 ? protocol_js_1.Protocol.DataFormat.text : protocol_js_1.Protocol.DataFormat.binary,
255
+ format: io.readInt16BE() === 0
256
+ ? protocol_js_1.Protocol.DataFormat.text
257
+ : protocol_js_1.Protocol.DataFormat.binary,
252
258
  };
253
259
  out.fields.push(field);
254
260
  }