postgrejs 2.16.0 → 2.17.0

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 (72) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/esm/connection/bind-param.js +1 -5
  3. package/esm/connection/connection.js +16 -20
  4. package/esm/connection/cursor.js +10 -15
  5. package/esm/connection/intl-connection.js +41 -46
  6. package/esm/connection/pool.js +28 -32
  7. package/esm/connection/portal.js +27 -31
  8. package/esm/connection/prepared-statement.js +31 -35
  9. package/esm/constants.js +122 -125
  10. package/esm/data-type-map.js +71 -75
  11. package/esm/data-types/bool-type.js +7 -10
  12. package/esm/data-types/box-type.js +7 -10
  13. package/esm/data-types/bytea-type.js +9 -13
  14. package/esm/data-types/char-type.js +7 -10
  15. package/esm/data-types/circle-type.js +7 -10
  16. package/esm/data-types/date-type.js +12 -15
  17. package/esm/data-types/float4-type.js +7 -10
  18. package/esm/data-types/float8-type.js +7 -10
  19. package/esm/data-types/int2-type.js +10 -13
  20. package/esm/data-types/int2-vector-type.js +13 -16
  21. package/esm/data-types/int4-type.js +10 -13
  22. package/esm/data-types/int8-type.js +9 -12
  23. package/esm/data-types/json-type.js +9 -12
  24. package/esm/data-types/jsonb-type.js +11 -14
  25. package/esm/data-types/lseg-type.js +7 -10
  26. package/esm/data-types/numeric-type.js +8 -12
  27. package/esm/data-types/oid-type.js +15 -18
  28. package/esm/data-types/point-type.js +7 -10
  29. package/esm/data-types/time-type.js +13 -16
  30. package/esm/data-types/timestamp-type.js +12 -15
  31. package/esm/data-types/timestamptz-type.js +12 -15
  32. package/esm/data-types/uuid-type.js +7 -10
  33. package/esm/data-types/varchar-type.js +7 -10
  34. package/esm/index.js +25 -28
  35. package/esm/interfaces/command-result.js +1 -2
  36. package/esm/interfaces/data-mapping-options.js +1 -2
  37. package/esm/interfaces/data-type.js +1 -2
  38. package/esm/interfaces/database-connection-params.js +1 -2
  39. package/esm/interfaces/field-info.js +1 -2
  40. package/esm/interfaces/query-options.js +1 -2
  41. package/esm/interfaces/query-result.js +1 -2
  42. package/esm/interfaces/script-execute-options.js +1 -2
  43. package/esm/interfaces/script-result.js +1 -2
  44. package/esm/interfaces/statement-prepare-options.js +1 -2
  45. package/esm/protocol/backend.js +24 -28
  46. package/esm/protocol/buffer-reader.js +1 -5
  47. package/esm/protocol/database-error.js +1 -5
  48. package/esm/protocol/frontend.js +27 -31
  49. package/esm/protocol/pg-socket.js +48 -53
  50. package/esm/protocol/protocol.js +2 -5
  51. package/esm/protocol/sasl.js +7 -11
  52. package/esm/protocol/smart-buffer.js +5 -10
  53. package/esm/safe-event-emitter.js +2 -6
  54. package/esm/types.js +1 -2
  55. package/esm/util/array-calculatedim.js +1 -4
  56. package/esm/util/bigint-methods.js +2 -6
  57. package/esm/util/config-from-env.js +5 -8
  58. package/esm/util/connection-config.js +8 -13
  59. package/esm/util/convert-row-to-object.js +1 -4
  60. package/esm/util/decode-binaryarray.js +3 -6
  61. package/esm/util/encode-binaryarray.js +5 -8
  62. package/esm/util/escape-literal.js +1 -4
  63. package/esm/util/fast-parseint.js +1 -4
  64. package/esm/util/get-parsers.js +8 -11
  65. package/esm/util/parse-array.js +1 -4
  66. package/esm/util/parse-datetime.js +5 -8
  67. package/esm/util/parse-row.js +1 -4
  68. package/esm/util/parse-time.js +8 -12
  69. package/esm/util/stringify-arrayliteral.js +3 -6
  70. package/esm/util/stringify-for-sql.js +8 -12
  71. package/esm/util/wrap-row-description.js +6 -9
  72. package/package.json +2 -2
@@ -1,33 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PgSocket = void 0;
4
- const tslib_1 = require("tslib");
5
- const crypto_1 = tslib_1.__importDefault(require("crypto"));
6
- const net_1 = tslib_1.__importDefault(require("net"));
7
- const putil_promisify_1 = tslib_1.__importDefault(require("putil-promisify"));
8
- const tls_1 = tslib_1.__importDefault(require("tls"));
9
- const constants_js_1 = require("../constants.js");
10
- const safe_event_emitter_js_1 = require("../safe-event-emitter.js");
11
- const backend_js_1 = require("./backend.js");
12
- const database_error_js_1 = require("./database-error.js");
13
- const frontend_js_1 = require("./frontend.js");
14
- const protocol_js_1 = require("./protocol.js");
15
- const sasl_js_1 = require("./sasl.js");
1
+ import crypto from 'crypto';
2
+ import net from 'net';
3
+ import promisify from 'putil-promisify';
4
+ import tls from 'tls';
5
+ import { ConnectionState } from '../constants.js';
6
+ import { SafeEventEmitter } from '../safe-event-emitter.js';
7
+ import { Backend } from './backend.js';
8
+ import { DatabaseError } from './database-error.js';
9
+ import { Frontend } from './frontend.js';
10
+ import { Protocol } from './protocol.js';
11
+ import { SASL } from './sasl.js';
16
12
  const DEFAULT_PORT_NUMBER = 5432;
17
13
  const COMMAND_RESULT_PATTERN = /^([^\d]+)(?: (\d+)(?: (\d+))?)?$/;
18
- class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
14
+ export class PgSocket extends SafeEventEmitter {
19
15
  constructor(options) {
20
16
  super();
21
17
  this.options = options;
22
- this._state = constants_js_1.ConnectionState.CLOSED;
23
- this._backend = new backend_js_1.Backend();
18
+ this._state = ConnectionState.CLOSED;
19
+ this._backend = new Backend();
24
20
  this._sessionParameters = {};
25
- this._frontend = new frontend_js_1.Frontend({ buffer: options.buffer });
21
+ this._frontend = new Frontend({ buffer: options.buffer });
26
22
  this.setMaxListeners(99);
27
23
  }
28
24
  get state() {
29
25
  if (!this._socket || this._socket.destroyed)
30
- this._state = constants_js_1.ConnectionState.CLOSED;
26
+ this._state = ConnectionState.CLOSED;
31
27
  return this._state;
32
28
  }
33
29
  get processID() {
@@ -42,11 +38,11 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
42
38
  connect() {
43
39
  if (this._socket)
44
40
  return;
45
- this._state = constants_js_1.ConnectionState.CONNECTING;
41
+ this._state = ConnectionState.CONNECTING;
46
42
  const options = this.options;
47
- const socket = (this._socket = new net_1.default.Socket());
43
+ const socket = (this._socket = new net.Socket());
48
44
  const errorHandler = err => {
49
- this._state = constants_js_1.ConnectionState.CLOSED;
45
+ this._state = ConnectionState.CLOSED;
50
46
  this._removeListeners();
51
47
  this._reset();
52
48
  socket.destroy();
@@ -62,9 +58,9 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
62
58
  this._removeListeners();
63
59
  if (x.toString() === 'S') {
64
60
  const tslOptions = { ...options.ssl, socket };
65
- if (options.host && net_1.default.isIP(options.host) === 0)
61
+ if (options.host && net.isIP(options.host) === 0)
66
62
  tslOptions.servername = options.host;
67
- const tlsSocket = (this._socket = tls_1.default.connect(tslOptions));
63
+ const tlsSocket = (this._socket = tls.connect(tslOptions));
68
64
  tlsSocket.once('error', errorHandler);
69
65
  tlsSocket.once('secureConnect', () => {
70
66
  this._removeListeners();
@@ -95,15 +91,15 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
95
91
  }
96
92
  close() {
97
93
  if (!this._socket || this._socket.destroyed) {
98
- this._state = constants_js_1.ConnectionState.CLOSED;
94
+ this._state = ConnectionState.CLOSED;
99
95
  this._socket = undefined;
100
96
  this._reset();
101
97
  return;
102
98
  }
103
- if (this._state === constants_js_1.ConnectionState.CLOSING)
99
+ if (this._state === ConnectionState.CLOSING)
104
100
  return;
105
101
  const socket = this._socket;
106
- this._state = constants_js_1.ConnectionState.CLOSING;
102
+ this._state = ConnectionState.CLOSING;
107
103
  this._removeListeners();
108
104
  socket.once('close', () => this._handleClose());
109
105
  socket.destroy();
@@ -169,7 +165,7 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
169
165
  };
170
166
  const msgHandler = (code, msg) => {
171
167
  const x = callback(code, msg, done);
172
- if (putil_promisify_1.default.isPromise(x))
168
+ if (promisify.isPromise(x))
173
169
  x.catch(err => done(err));
174
170
  };
175
171
  this.once('error', errorHandler);
@@ -195,7 +191,7 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
195
191
  const socket = this._socket;
196
192
  if (!socket)
197
193
  return;
198
- this._state = constants_js_1.ConnectionState.AUTHORIZING;
194
+ this._state = ConnectionState.AUTHORIZING;
199
195
  this._reset();
200
196
  socket.on('data', (data) => this._handleData(data));
201
197
  socket.on('error', (err) => this._handleError(err));
@@ -208,11 +204,11 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
208
204
  _handleClose() {
209
205
  this._reset();
210
206
  this._socket = undefined;
211
- this._state = constants_js_1.ConnectionState.CLOSED;
207
+ this._state = ConnectionState.CLOSED;
212
208
  this.emit('close');
213
209
  }
214
210
  _handleError(err) {
215
- if (this._state !== constants_js_1.ConnectionState.READY) {
211
+ if (this._state !== ConnectionState.READY) {
216
212
  this._socket?.end();
217
213
  }
218
214
  this.emit('error', err);
@@ -221,33 +217,33 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
221
217
  this._backend.parse(data, (code, payload) => {
222
218
  try {
223
219
  switch (code) {
224
- case protocol_js_1.Protocol.BackendMessageCode.Authentication:
220
+ case Protocol.BackendMessageCode.Authentication:
225
221
  this._handleAuthenticationMessage(payload);
226
222
  break;
227
- case protocol_js_1.Protocol.BackendMessageCode.ErrorResponse:
228
- this.emit('error', new database_error_js_1.DatabaseError(payload));
223
+ case Protocol.BackendMessageCode.ErrorResponse:
224
+ this.emit('error', new DatabaseError(payload));
229
225
  break;
230
- case protocol_js_1.Protocol.BackendMessageCode.NoticeResponse:
226
+ case Protocol.BackendMessageCode.NoticeResponse:
231
227
  this.emit('notice', payload);
232
228
  break;
233
- case protocol_js_1.Protocol.BackendMessageCode.NotificationResponse:
229
+ case Protocol.BackendMessageCode.NotificationResponse:
234
230
  this.emit('notification', payload);
235
231
  break;
236
- case protocol_js_1.Protocol.BackendMessageCode.ParameterStatus:
232
+ case Protocol.BackendMessageCode.ParameterStatus:
237
233
  this._handleParameterStatus(payload);
238
234
  break;
239
- case protocol_js_1.Protocol.BackendMessageCode.BackendKeyData:
235
+ case Protocol.BackendMessageCode.BackendKeyData:
240
236
  this._handleBackendKeyData(payload);
241
237
  break;
242
- case protocol_js_1.Protocol.BackendMessageCode.ReadyForQuery:
243
- if (this._state !== constants_js_1.ConnectionState.READY) {
244
- this._state = constants_js_1.ConnectionState.READY;
238
+ case Protocol.BackendMessageCode.ReadyForQuery:
239
+ if (this._state !== ConnectionState.READY) {
240
+ this._state = ConnectionState.READY;
245
241
  this.emit('ready');
246
242
  }
247
243
  else
248
244
  this.emit('message', code, payload);
249
245
  break;
250
- case protocol_js_1.Protocol.BackendMessageCode.CommandComplete: {
246
+ case Protocol.BackendMessageCode.CommandComplete: {
251
247
  const msg = this._handleCommandComplete(payload);
252
248
  this.emit('message', code, msg);
253
249
  break;
@@ -273,44 +269,44 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
273
269
  return;
274
270
  }
275
271
  switch (msg.kind) {
276
- case protocol_js_1.Protocol.AuthenticationMessageKind.CleartextPassword:
272
+ case Protocol.AuthenticationMessageKind.CleartextPassword:
277
273
  this._resolvePassword(password => {
278
274
  this._send(this._frontend.getPasswordMessage(password));
279
275
  });
280
276
  break;
281
- case protocol_js_1.Protocol.AuthenticationMessageKind.MD5Password:
277
+ case Protocol.AuthenticationMessageKind.MD5Password:
282
278
  this._resolvePassword(password => {
283
- const md5 = (x) => crypto_1.default.createHash('md5').update(x, 'utf8').digest('hex');
279
+ const md5 = (x) => crypto.createHash('md5').update(x, 'utf8').digest('hex');
284
280
  const l = md5(password + this.options.user);
285
281
  const r = md5(Buffer.concat([Buffer.from(l), msg.salt]));
286
282
  const pass = 'md5' + r;
287
283
  this._send(this._frontend.getPasswordMessage(pass));
288
284
  });
289
285
  break;
290
- case protocol_js_1.Protocol.AuthenticationMessageKind.SASL: {
286
+ case Protocol.AuthenticationMessageKind.SASL: {
291
287
  if (!msg.mechanisms.includes('SCRAM-SHA-256')) {
292
288
  throw new Error('SASL: Only mechanism SCRAM-SHA-256 is currently supported');
293
289
  }
294
- const saslSession = (this._saslSession = sasl_js_1.SASL.createSession(this.options.user || '', 'SCRAM-SHA-256'));
290
+ const saslSession = (this._saslSession = SASL.createSession(this.options.user || '', 'SCRAM-SHA-256'));
295
291
  this._send(this._frontend.getSASLMessage(saslSession));
296
292
  break;
297
293
  }
298
- case protocol_js_1.Protocol.AuthenticationMessageKind.SASLContinue: {
294
+ case Protocol.AuthenticationMessageKind.SASLContinue: {
299
295
  const saslSession = this._saslSession;
300
296
  if (!saslSession)
301
297
  throw new Error('SASL: Session not started yet');
302
298
  this._resolvePassword(password => {
303
- sasl_js_1.SASL.continueSession(saslSession, password, msg.data);
299
+ SASL.continueSession(saslSession, password, msg.data);
304
300
  const buf = this._frontend.getSASLFinalMessage(saslSession);
305
301
  this._send(buf);
306
302
  });
307
303
  break;
308
304
  }
309
- case protocol_js_1.Protocol.AuthenticationMessageKind.SASLFinal: {
305
+ case Protocol.AuthenticationMessageKind.SASLFinal: {
310
306
  const session = this._saslSession;
311
307
  if (!session)
312
308
  throw new Error('SASL: Session not started yet');
313
- sasl_js_1.SASL.finalizeSession(session, msg.data);
309
+ SASL.finalizeSession(session, msg.data);
314
310
  this._saslSession = undefined;
315
311
  break;
316
312
  }
@@ -344,4 +340,3 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
344
340
  }
345
341
  }
346
342
  }
347
- exports.PgSocket = PgSocket;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Protocol = void 0;
4
- var Protocol;
1
+ export var Protocol;
5
2
  (function (Protocol) {
6
3
  Protocol.VERSION_MAJOR = 3;
7
4
  Protocol.VERSION_MINOR = 0;
@@ -68,4 +65,4 @@ var Protocol;
68
65
  DataFormat[DataFormat["text"] = 0] = "text";
69
66
  DataFormat[DataFormat["binary"] = 1] = "binary";
70
67
  })(DataFormat = Protocol.DataFormat || (Protocol.DataFormat = {}));
71
- })(Protocol || (exports.Protocol = Protocol = {}));
68
+ })(Protocol || (Protocol = {}));
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SASL = void 0;
4
- const tslib_1 = require("tslib");
5
1
  /* eslint-disable no-bitwise */
6
- const crypto_1 = tslib_1.__importDefault(require("crypto"));
7
- var SASL;
2
+ import crypto from 'crypto';
3
+ export var SASL;
8
4
  (function (SASL) {
9
5
  const CLIENT_KEY = 'Client Key';
10
6
  const SERVER_KEY = 'Server Key';
11
7
  const GS2_HEADER = 'n,,';
12
8
  function createSession(username, mechanism) {
13
- const nonce = crypto_1.default.randomBytes(18).toString('base64');
9
+ const nonce = crypto.randomBytes(18).toString('base64');
14
10
  const clientFirstMessage = `${GS2_HEADER}${firstMessageBare(username, nonce)}`;
15
11
  return {
16
12
  username,
@@ -84,14 +80,14 @@ var SASL;
84
80
  * HMAC() == output length of H()
85
81
  */
86
82
  const hi = function (text, salt, iterations) {
87
- return crypto_1.default.pbkdf2Sync(text, Buffer.from(salt, 'base64'), iterations, 32, 'sha256');
83
+ return crypto.pbkdf2Sync(text, Buffer.from(salt, 'base64'), iterations, 32, 'sha256');
88
84
  };
89
85
  const encode64 = str => Buffer.from(str).toString('base64');
90
86
  const hmac = function (key, msg) {
91
- return crypto_1.default.createHmac('sha256', key).update(msg).digest();
87
+ return crypto.createHmac('sha256', key).update(msg).digest();
92
88
  };
93
89
  const hash = function (data) {
94
- return crypto_1.default.createHash('sha256').update(data).digest();
90
+ return crypto.createHash('sha256').update(data).digest();
95
91
  };
96
92
  const xor = function (a, b) {
97
93
  a = Buffer.isBuffer(a) ? a : Buffer.from(a);
@@ -105,4 +101,4 @@ var SASL;
105
101
  }
106
102
  return out;
107
103
  };
108
- })(SASL || (exports.SASL = SASL = {}));
104
+ })(SASL || (SASL = {}));
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SmartBuffer = void 0;
4
- const tslib_1 = require("tslib");
5
- const os = tslib_1.__importStar(require("os"));
6
- const bigint_methods_js_1 = require("../util/bigint-methods.js");
7
- const buffer_reader_js_1 = require("./buffer-reader.js");
8
- class SmartBuffer extends buffer_reader_js_1.BufferReader {
1
+ import * as os from 'os';
2
+ import { writeBigUInt64BE } from '../util/bigint-methods.js';
3
+ import { BufferReader } from './buffer-reader.js';
4
+ export class SmartBuffer extends BufferReader {
9
5
  constructor(cfg) {
10
6
  // @ts-ignore
11
7
  super(Buffer.allocUnsafe((cfg?.pageSize ? parseInt(cfg.pageSize, 10) : 0) || SmartBuffer.DEFAULT_PAGE_SIZE));
@@ -139,7 +135,7 @@ class SmartBuffer extends buffer_reader_js_1.BufferReader {
139
135
  if (typeof this.buffer.writeBigInt64BE === 'function')
140
136
  this.buffer.writeBigInt64BE(n, this.offset);
141
137
  else
142
- (0, bigint_methods_js_1.writeBigUInt64BE)(this.buffer, n, this.offset);
138
+ writeBigUInt64BE(this.buffer, n, this.offset);
143
139
  this.offset += 8;
144
140
  return this;
145
141
  }
@@ -168,6 +164,5 @@ class SmartBuffer extends buffer_reader_js_1.BufferReader {
168
164
  this._stMaxPages = this.length ? Math.ceil(this.length / this.pageSize) : 1;
169
165
  }
170
166
  }
171
- exports.SmartBuffer = SmartBuffer;
172
167
  SmartBuffer.DEFAULT_PAGE_SIZE = 4096;
173
168
  SmartBuffer.DEFAULT_MAX_SIZE = Math.min(Math.floor(os.totalmem() / 2), 1024 * 1024 * 1024 * 2);
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SafeEventEmitter = void 0;
4
- const events_1 = require("events");
5
- class SafeEventEmitter extends events_1.EventEmitter {
1
+ import { EventEmitter } from 'events';
2
+ export class SafeEventEmitter extends EventEmitter {
6
3
  emit(event, ...args) {
7
4
  try {
8
5
  if (event === 'error' && !this.listenerCount('error'))
@@ -14,4 +11,3 @@ class SafeEventEmitter extends events_1.EventEmitter {
14
11
  }
15
12
  }
16
13
  }
17
- exports.SafeEventEmitter = SafeEventEmitter;
package/esm/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.arrayCalculateDim = arrayCalculateDim;
4
- function arrayCalculateDim(arr) {
1
+ export function arrayCalculateDim(arr) {
5
2
  if (!arr || arr.length === 0)
6
3
  return [0];
7
4
  const dim = [arr.length];
@@ -1,13 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readBigInt64BE = readBigInt64BE;
4
- exports.writeBigUInt64BE = writeBigUInt64BE;
5
1
  /* eslint-disable no-bitwise */
6
2
  const big0 = BigInt(0);
7
3
  const beAnd = BigInt('0xffffffff');
8
4
  const big32 = BigInt(32);
9
5
  // https://github.com/nodejs/node/blob/v13.9.0/lib/internal/buffer.js
10
- function readBigInt64BE(buf, offset = 0) {
6
+ export function readBigInt64BE(buf, offset = 0) {
11
7
  const first = buf[offset];
12
8
  const last = buf[offset + 7];
13
9
  if (first === undefined || last === undefined)
@@ -18,7 +14,7 @@ function readBigInt64BE(buf, offset = 0) {
18
14
  buf[++offset];
19
15
  return ((BigInt(val) << big32) + BigInt(buf[++offset] * 2 ** 24 + buf[++offset] * 2 ** 16 + buf[++offset] * 2 ** 8 + last));
20
16
  }
21
- function writeBigUInt64BE(buf, value, offset = 0) {
17
+ export function writeBigUInt64BE(buf, value, offset = 0) {
22
18
  // @ts-ignore
23
19
  let lo = Number(value & beAnd);
24
20
  buf[offset + 7] = lo;
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configFromEnv = configFromEnv;
4
- const putil_varhelpers_1 = require("putil-varhelpers");
5
- function configFromEnv() {
1
+ import { toInt, toIntDef } from 'putil-varhelpers';
2
+ export function configFromEnv() {
6
3
  const env = process.env;
7
4
  const result = {};
8
5
  result.host = env.PGHOST || env.PGHOSTADDR;
9
6
  if (env.PGPORT)
10
- result.port = (0, putil_varhelpers_1.toIntDef)(env.PGPORT, 5432);
7
+ result.port = toIntDef(env.PGPORT, 5432);
11
8
  if (env.PGDATABASE)
12
9
  result.database = env.PGDATABASE;
13
10
  if (env.PGUSER)
@@ -21,9 +18,9 @@ function configFromEnv() {
21
18
  if (env.PGSCHEMA)
22
19
  result.schema = env.PGSCHEMA;
23
20
  if (env.PGCONNECT_TIMEOUT)
24
- result.connectTimeoutMs = (0, putil_varhelpers_1.toIntDef)(env.PGCONNECT_TIMEOUT, 30000);
21
+ result.connectTimeoutMs = toIntDef(env.PGCONNECT_TIMEOUT, 30000);
25
22
  if (env.PGMAX_BUFFER_SIZE) {
26
- result.buffer = { maxLength: (0, putil_varhelpers_1.toInt)(env.PGMAX_BUFFER_SIZE) };
23
+ result.buffer = { maxLength: toInt(env.PGMAX_BUFFER_SIZE) };
27
24
  }
28
25
  return result;
29
26
  }
@@ -1,28 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConnectionConfig = getConnectionConfig;
4
- exports.parseConnectionString = parseConnectionString;
5
- const tslib_1 = require("tslib");
6
- const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
7
- const config_from_env_js_1 = require("./config-from-env.js");
8
- function getConnectionConfig(config) {
9
- const cfg = (0, config_from_env_js_1.configFromEnv)();
1
+ import merge from 'putil-merge';
2
+ import { configFromEnv } from './config-from-env.js';
3
+ export function getConnectionConfig(config) {
4
+ const cfg = configFromEnv();
10
5
  if (typeof config === 'string') {
11
- (0, putil_merge_1.default)(cfg, parseConnectionString(config));
6
+ merge(cfg, parseConnectionString(config));
12
7
  }
13
8
  else if (typeof config === 'object') {
14
- (0, putil_merge_1.default)(cfg, config);
9
+ merge(cfg, config);
15
10
  }
16
11
  if (cfg.host) {
17
12
  const x = parseConnectionString('' + cfg.host);
18
- (0, putil_merge_1.default)(cfg, x);
13
+ merge(cfg, x);
19
14
  }
20
15
  cfg.user = cfg.user || 'postgres';
21
16
  cfg.database = cfg.database || 'postgres';
22
17
  cfg.host = cfg.host || '127.0.0.1';
23
18
  return cfg;
24
19
  }
25
- function parseConnectionString(str) {
20
+ export function parseConnectionString(str) {
26
21
  if (str.startsWith('/'))
27
22
  str = 'socket:/' + str;
28
23
  if (!str.includes('://'))
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertRowToObject = convertRowToObject;
4
- function convertRowToObject(fields, row) {
1
+ export function convertRowToObject(fields, row) {
5
2
  const out = {};
6
3
  const l = row.length;
7
4
  let i;
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decodeBinaryArray = decodeBinaryArray;
4
- const buffer_reader_js_1 = require("../protocol/buffer-reader.js");
5
- function decodeBinaryArray(buf, decoder, options = {}) {
1
+ import { BufferReader } from '../protocol/buffer-reader.js';
2
+ export function decodeBinaryArray(buf, decoder, options = {}) {
6
3
  if (!buf.length)
7
4
  return null;
8
- const io = new buffer_reader_js_1.BufferReader(buf);
5
+ const io = new BufferReader(buf);
9
6
  const ndims = io.readInt32BE();
10
7
  io.readInt32BE(); // hasNulls
11
8
  const elementOID = io.readInt32BE(); // element oid
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeBinaryArray = encodeBinaryArray;
4
- const constants_js_1 = require("../constants.js");
5
- const array_calculatedim_js_1 = require("./array-calculatedim.js");
6
- function encodeBinaryArray(io, value, itemOid, options, encode, encodeCalculateDimFn) {
7
- encodeCalculateDimFn = encodeCalculateDimFn || array_calculatedim_js_1.arrayCalculateDim;
8
- itemOid = itemOid || constants_js_1.DataTypeOIDs.varchar;
1
+ import { DataTypeOIDs } from '../constants.js';
2
+ import { arrayCalculateDim } from './array-calculatedim.js';
3
+ export function encodeBinaryArray(io, value, itemOid, options, encode, encodeCalculateDimFn) {
4
+ encodeCalculateDimFn = encodeCalculateDimFn || arrayCalculateDim;
5
+ itemOid = itemOid || DataTypeOIDs.varchar;
9
6
  const dim = encodeCalculateDimFn(value);
10
7
  const ndims = dim.length;
11
8
  const zeroOffset = io.offset;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.escapeLiteral = escapeLiteral;
4
1
  // Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
5
- function escapeLiteral(str) {
2
+ export function escapeLiteral(str) {
6
3
  let backSlash = false;
7
4
  let out = "'";
8
5
  let i;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fastParseInt = fastParseInt;
4
- function fastParseInt(str) {
1
+ export function fastParseInt(str) {
5
2
  /* istanbul ignore next */
6
3
  if (typeof str === 'number')
7
4
  return Math.floor(str);
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getParsers = getParsers;
4
- const constants_js_1 = require("../constants.js");
5
- const decode_binaryarray_js_1 = require("./decode-binaryarray.js");
6
- const parse_array_js_1 = require("./parse-array.js");
1
+ import { DataFormat } from '../constants.js';
2
+ import { decodeBinaryArray } from './decode-binaryarray.js';
3
+ import { parsePostgresArray } from './parse-array.js';
7
4
  const DefaultColumnParser = (v) => v;
8
- function getParsers(typeMap, fields) {
5
+ export function getParsers(typeMap, fields) {
9
6
  const parsers = new Array(fields.length);
10
7
  const l = fields.length;
11
8
  let f;
@@ -15,20 +12,20 @@ function getParsers(typeMap, fields) {
15
12
  const dataTypeReg = typeMap.get(f.dataTypeId);
16
13
  if (dataTypeReg) {
17
14
  const isArray = !!dataTypeReg.elementsOID;
18
- if (f.format === constants_js_1.DataFormat.binary) {
15
+ if (f.format === DataFormat.binary) {
19
16
  const decode = dataTypeReg.parseBinary;
20
17
  if (decode) {
21
18
  parsers[i] = !isArray
22
19
  ? decode
23
- : (v, options) => (0, decode_binaryarray_js_1.decodeBinaryArray)(v, decode, options);
20
+ : (v, options) => decodeBinaryArray(v, decode, options);
24
21
  }
25
22
  }
26
- else if (f.format === constants_js_1.DataFormat.text) {
23
+ else if (f.format === DataFormat.text) {
27
24
  const parse = dataTypeReg.parseText;
28
25
  if (parse) {
29
26
  parsers[i] = !isArray
30
27
  ? parse
31
- : (v, options) => (0, parse_array_js_1.parsePostgresArray)(v, {
28
+ : (v, options) => parsePostgresArray(v, {
32
29
  transform: x => parse(x, options),
33
30
  separator: dataTypeReg.arraySeparator,
34
31
  });
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parsePostgresArray = parsePostgresArray;
4
- function parsePostgresArray(s, opts) {
1
+ export function parsePostgresArray(s, opts) {
5
2
  if (!s)
6
3
  return;
7
4
  const sep = (opts?.separator || ',').substring(0, 1);
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseDateTime = parseDateTime;
4
1
  // noinspection RegExpUnnecessaryNonCapturingGroup
5
- const fast_parseint_js_1 = require("./fast-parseint.js");
2
+ import { fastParseInt } from './fast-parseint.js';
6
3
  // noinspection RegExpUnnecessaryNonCapturingGroup
7
4
  const TIMESTAMP_PATTERN =
8
5
  // eslint-disable-next-line
9
6
  /^(\d{4})-?(0[1-9]|1[012])?-?([123]0|[012][1-9]|31)?(?:[T ]?([01][0-9]|2[0-3]):?([0-5][0-9]):?([0-5][0-9])?(?:\.(\d+))?(?:(Z)|(?:([+-])([01]?[0-9]|2[0-3]):?([0-5][0-9])?))?)?$/;
10
7
  const INFINITY_PATTERN = /^-?infinity$/;
11
- function parseDateTime(str, parseTime, parseTimeZone, utc) {
8
+ export function parseDateTime(str, parseTime, parseTimeZone, utc) {
12
9
  let m = str.match(TIMESTAMP_PATTERN);
13
10
  if (!m) {
14
11
  m = str.match(INFINITY_PATTERN);
@@ -20,15 +17,15 @@ function parseDateTime(str, parseTime, parseTimeZone, utc) {
20
17
  const l = parseTime ? 7 : 3;
21
18
  for (let i = 0; i < l; i++) {
22
19
  const s = m[i + 1];
23
- args[i] = (0, fast_parseint_js_1.fastParseInt)(s) || 0;
20
+ args[i] = fastParseInt(s) || 0;
24
21
  }
25
22
  // Months starts from 0
26
23
  if (args[1] > 0)
27
24
  args[1]--;
28
25
  if (parseTimeZone && parseTime && m[9]) {
29
26
  const r = m[9] === '-' ? -1 : 1;
30
- args[3] -= ((0, fast_parseint_js_1.fastParseInt)(m[10]) || 0) * r;
31
- args[4] -= ((0, fast_parseint_js_1.fastParseInt)(m[11]) || 0) * r;
27
+ args[3] -= (fastParseInt(m[10]) || 0) * r;
28
+ args[4] -= (fastParseInt(m[11]) || 0) * r;
32
29
  return new Date(Date.UTC(...args));
33
30
  }
34
31
  if (m[8] || utc)
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseRow = parseRow;
4
- function parseRow(parsers, row, options) {
1
+ export function parseRow(parsers, row, options) {
5
2
  const l = row.length;
6
3
  let i;
7
4
  for (i = 0; i < l; i++) {
@@ -1,26 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TIME_PATTERN = exports.STRICT_TIME_PATTERN = void 0;
4
- exports.parseTime = parseTime;
5
- const fast_parseint_js_1 = require("./fast-parseint.js");
1
+ import { fastParseInt } from './fast-parseint.js';
6
2
  // eslint-disable-next-line
7
3
  // noinspection RegExpUnnecessaryNonCapturingGroup
8
- exports.STRICT_TIME_PATTERN = /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(?:\.(\d+))?(?:(Z)|(?:([+-])([01]?[0-9]|2[0-3]):?([0-5][0-9])?))?$/;
4
+ export const STRICT_TIME_PATTERN = /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(?:\.(\d+))?(?:(Z)|(?:([+-])([01]?[0-9]|2[0-3]):?([0-5][0-9])?))?$/;
9
5
  // noinspection RegExpUnnecessaryNonCapturingGroup
10
- exports.TIME_PATTERN = /^([01][0-9]|2[0-3]):?([0-5][0-9]):?([0-5][0-9])?(?:\.(\d+))?(?:(Z)|(?:([+-])([01]?[0-9]|2[0-3]):?([0-5][0-9])?))?$/;
11
- function parseTime(str, parseTimeZone, utc) {
12
- const m = str.match(exports.TIME_PATTERN);
6
+ export const TIME_PATTERN = /^([01][0-9]|2[0-3]):?([0-5][0-9]):?([0-5][0-9])?(?:\.(\d+))?(?:(Z)|(?:([+-])([01]?[0-9]|2[0-3]):?([0-5][0-9])?))?$/;
7
+ export function parseTime(str, parseTimeZone, utc) {
8
+ const m = str.match(TIME_PATTERN);
13
9
  if (!m)
14
10
  return new Date('invalid');
15
11
  const args = [1970, 0, 1, 0, 0, 0, 0];
16
12
  for (let i = 1; i < 4; i++) {
17
13
  const s = m[i];
18
- args[i + 2] = (0, fast_parseint_js_1.fastParseInt)(s) || 0;
14
+ args[i + 2] = fastParseInt(s) || 0;
19
15
  }
20
16
  if (parseTimeZone && m[6]) {
21
17
  const r = m[9] === '-' ? -1 : 1;
22
- args[3] -= ((0, fast_parseint_js_1.fastParseInt)(m[7]) || 0) * r;
23
- args[4] -= ((0, fast_parseint_js_1.fastParseInt)(m[8]) || 0) * r;
18
+ args[3] -= (fastParseInt(m[7]) || 0) * r;
19
+ args[4] -= (fastParseInt(m[8]) || 0) * r;
24
20
  return new Date(Date.UTC(...args));
25
21
  }
26
22
  if (m[5] || utc)