postgrejs 2.22.2 → 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 (66) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/cjs/connection/connection.js +9 -4
  3. package/cjs/connection/intl-connection.js +12 -5
  4. package/cjs/connection/portal.js +10 -3
  5. package/cjs/connection/prepared-statement.js +9 -3
  6. package/cjs/constants.js +0 -1
  7. package/cjs/data-type-map.js +15 -3
  8. package/cjs/data-types/bool-type.js +7 -1
  9. package/cjs/data-types/circle-type.js +4 -1
  10. package/cjs/data-types/date-type.js +12 -4
  11. package/cjs/data-types/int2-type.js +1 -1
  12. package/cjs/data-types/int2-vector-type.js +5 -1
  13. package/cjs/data-types/int4-type.js +3 -1
  14. package/cjs/data-types/int8-type.js +7 -2
  15. package/cjs/data-types/json-type.js +4 -2
  16. package/cjs/data-types/jsonb-type.js +4 -2
  17. package/cjs/data-types/lseg-type.js +4 -1
  18. package/cjs/data-types/point-type.js +4 -1
  19. package/cjs/data-types/time-type.js +16 -5
  20. package/cjs/data-types/timestamp-type.js +11 -4
  21. package/cjs/data-types/timestamptz-type.js +4 -2
  22. package/cjs/protocol/backend.js +9 -3
  23. package/cjs/protocol/frontend.js +40 -10
  24. package/cjs/protocol/pg-socket.js +5 -2
  25. package/cjs/protocol/sasl.js +2 -2
  26. package/cjs/protocol/smart-buffer.js +1 -2
  27. package/cjs/safe-event-emitter.js +1 -1
  28. package/cjs/tsconfig-build-cjs.tsbuildinfo +1 -1
  29. package/cjs/util/bigint-methods.js +5 -2
  30. package/cjs/util/connection-config.js +5 -6
  31. package/cjs/util/parse-datetime.js +4 -4
  32. package/cjs/util/parse-row.js +2 -1
  33. package/cjs/util/parse-time.js +3 -2
  34. package/esm/connection/connection.js +9 -4
  35. package/esm/connection/intl-connection.js +12 -5
  36. package/esm/connection/pool.js +1 -1
  37. package/esm/connection/portal.js +10 -3
  38. package/esm/connection/prepared-statement.js +9 -3
  39. package/esm/constants.js +0 -1
  40. package/esm/data-type-map.js +18 -6
  41. package/esm/data-types/bool-type.js +7 -1
  42. package/esm/data-types/circle-type.js +4 -1
  43. package/esm/data-types/date-type.js +12 -4
  44. package/esm/data-types/int2-type.js +1 -1
  45. package/esm/data-types/int2-vector-type.js +5 -1
  46. package/esm/data-types/int4-type.js +3 -1
  47. package/esm/data-types/int8-type.js +7 -2
  48. package/esm/data-types/json-type.js +4 -2
  49. package/esm/data-types/jsonb-type.js +4 -2
  50. package/esm/data-types/lseg-type.js +4 -1
  51. package/esm/data-types/point-type.js +4 -1
  52. package/esm/data-types/time-type.js +16 -5
  53. package/esm/data-types/timestamp-type.js +11 -4
  54. package/esm/data-types/timestamptz-type.js +4 -2
  55. package/esm/protocol/backend.js +9 -3
  56. package/esm/protocol/frontend.js +40 -10
  57. package/esm/protocol/pg-socket.js +5 -2
  58. package/esm/protocol/sasl.js +2 -2
  59. package/esm/protocol/smart-buffer.js +1 -2
  60. package/esm/safe-event-emitter.js +1 -1
  61. package/esm/util/bigint-methods.js +5 -2
  62. package/esm/util/connection-config.js +2 -2
  63. package/esm/util/parse-datetime.js +4 -4
  64. package/esm/util/parse-row.js +2 -1
  65. package/esm/util/parse-time.js +3 -2
  66. package/package.json +3 -3
@@ -7,9 +7,27 @@ const stringify_arrayliteral_js_1 = require("../util/stringify-arrayliteral.js")
7
7
  const protocol_js_1 = require("./protocol.js");
8
8
  const smart_buffer_js_1 = require("./smart-buffer.js");
9
9
  const DataFormat = protocol_js_1.Protocol.DataFormat;
10
- const StaticFlushBuffer = Buffer.from([protocol_js_1.Protocol.FrontendMessageCode.Flush, 0x00, 0x00, 0x00, 0x04]);
11
- const StaticTerminateBuffer = Buffer.from([protocol_js_1.Protocol.FrontendMessageCode.Terminate, 0x00, 0x00, 0x00, 0x04]);
12
- const StaticSyncBuffer = Buffer.from([protocol_js_1.Protocol.FrontendMessageCode.Sync, 0x00, 0x00, 0x00, 0x04]);
10
+ const StaticFlushBuffer = Buffer.from([
11
+ protocol_js_1.Protocol.FrontendMessageCode.Flush,
12
+ 0x00,
13
+ 0x00,
14
+ 0x00,
15
+ 0x04,
16
+ ]);
17
+ const StaticTerminateBuffer = Buffer.from([
18
+ protocol_js_1.Protocol.FrontendMessageCode.Terminate,
19
+ 0x00,
20
+ 0x00,
21
+ 0x00,
22
+ 0x04,
23
+ ]);
24
+ const StaticSyncBuffer = Buffer.from([
25
+ protocol_js_1.Protocol.FrontendMessageCode.Sync,
26
+ 0x00,
27
+ 0x00,
28
+ 0x00,
29
+ 0x04,
30
+ ]);
13
31
  class Frontend {
14
32
  constructor(options) {
15
33
  this._io = new smart_buffer_js_1.SmartBuffer(options?.buffer);
@@ -32,7 +50,9 @@ class Frontend {
32
50
  if (k !== 'client_encoding')
33
51
  io.writeCString(k, 'utf8').writeCString(v, 'utf8');
34
52
  }
35
- io.writeCString('client_encoding', 'utf8').writeCString('UTF8', 'utf8').writeUInt8(0);
53
+ io.writeCString('client_encoding', 'utf8')
54
+ .writeCString('UTF8', 'utf8')
55
+ .writeUInt8(0);
36
56
  return setLengthAndFlush(io, 0);
37
57
  }
38
58
  getPasswordMessage(password) {
@@ -89,7 +109,9 @@ class Frontend {
89
109
  .writeCString(args.portal || '', 'utf8')
90
110
  .writeCString(args.statement || '', 'utf8');
91
111
  const { params, paramTypes, queryOptions } = args;
92
- const columnFormat = queryOptions.columnFormat != null ? queryOptions.columnFormat : constants_js_1.DEFAULT_COLUMN_FORMAT;
112
+ const columnFormat = queryOptions.columnFormat != null
113
+ ? queryOptions.columnFormat
114
+ : constants_js_1.DEFAULT_COLUMN_FORMAT;
93
115
  if (params && params.length) {
94
116
  io.writeInt16BE(params.length);
95
117
  const formatOffset = io.offset;
@@ -107,7 +129,8 @@ class Frontend {
107
129
  const dataTypeOid = paramTypes ? paramTypes[i] : undefined;
108
130
  const dt = dataTypeOid ? args.typeMap.get(dataTypeOid) : undefined;
109
131
  if (dt) {
110
- if (typeof dt.encodeAsNull === 'function' && dt.encodeAsNull(v, queryOptions)) {
132
+ if (typeof dt.encodeAsNull === 'function' &&
133
+ dt.encodeAsNull(v, queryOptions)) {
111
134
  io.writeInt32BE(-1);
112
135
  continue;
113
136
  }
@@ -128,7 +151,9 @@ class Frontend {
128
151
  io.buffer.writeInt32BE(io.length - dataOffset, dataOffset - 4); // Update length
129
152
  }
130
153
  else if (typeof dt.encodeText === 'function') {
131
- v = dt.elementsOID ? (0, stringify_arrayliteral_js_1.stringifyArrayLiteral)(v, queryOptions, dt.encodeText) : dt.encodeText(v, queryOptions);
154
+ v = dt.elementsOID
155
+ ? (0, stringify_arrayliteral_js_1.stringifyArrayLiteral)(v, queryOptions, dt.encodeText)
156
+ : dt.encodeText(v, queryOptions);
132
157
  io.writeLString(v, 'utf8');
133
158
  }
134
159
  }
@@ -166,7 +191,9 @@ class Frontend {
166
191
  }
167
192
  getDescribeMessage(args) {
168
193
  if (args.name && args.name.length > 63) {
169
- throw new Error(args.type === 'P' ? 'Portal' : 'Statement name length must be lower than 63');
194
+ throw new Error(args.type === 'P'
195
+ ? 'Portal'
196
+ : 'Statement name length must be lower than 63');
170
197
  }
171
198
  const io = this._io
172
199
  .start()
@@ -177,7 +204,8 @@ class Frontend {
177
204
  return setLengthAndFlush(io, 1);
178
205
  }
179
206
  getExecuteMessage(args) {
180
- if (args.fetchCount && (args.fetchCount < 0 || args.fetchCount > 4294967295)) {
207
+ if (args.fetchCount &&
208
+ (args.fetchCount < 0 || args.fetchCount > 4294967295)) {
181
209
  throw new Error('fetchCount can be between 0 and 4294967295');
182
210
  }
183
211
  const io = this._io
@@ -190,7 +218,9 @@ class Frontend {
190
218
  }
191
219
  getCloseMessage(args) {
192
220
  if (args.name && args.name.length > 63) {
193
- throw new Error(args.type === 'P' ? 'Portal' : 'Statement name length must be lower than 63');
221
+ throw new Error(args.type === 'P'
222
+ ? 'Portal'
223
+ : 'Statement name length must be lower than 63');
194
224
  }
195
225
  const io = this._io
196
226
  .start()
@@ -157,7 +157,8 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
157
157
  this._send(this._frontend.getSyncMessage());
158
158
  }
159
159
  capture(callback) {
160
- if (this._state === constants_js_1.ConnectionState.CLOSING || this._state === constants_js_1.ConnectionState.CLOSED) {
160
+ if (this._state === constants_js_1.ConnectionState.CLOSING ||
161
+ this._state === constants_js_1.ConnectionState.CLOSED) {
161
162
  return Promise.reject(new Error('Connection closed'));
162
163
  }
163
164
  if (this._state !== constants_js_1.ConnectionState.READY)
@@ -279,7 +280,9 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
279
280
  }
280
281
  _resolvePassword(cb) {
281
282
  (async () => {
282
- const pass = typeof this.options.password === 'function' ? await this.options.password() : this.options.password;
283
+ const pass = typeof this.options.password === 'function'
284
+ ? await this.options.password()
285
+ : this.options.password;
283
286
  cb(pass || '');
284
287
  })().catch(err => this._handleError(err));
285
288
  }
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SASL = void 0;
4
4
  const tslib_1 = require("tslib");
5
- /* eslint-disable no-bitwise */
6
5
  const crypto_1 = tslib_1.__importDefault(require("crypto"));
7
6
  var SASL;
8
7
  (function (SASL) {
@@ -61,7 +60,8 @@ var SASL;
61
60
  const serverKey = hmac(saltPass, SERVER_KEY);
62
61
  const serverSignatureBytes = hmac(serverKey, authMessage);
63
62
  session.serverSignature = serverSignatureBytes.toString('base64');
64
- session.clientFinalMessage = clientFinalMessageWithoutProof + ',p=' + clientProof;
63
+ session.clientFinalMessage =
64
+ clientFinalMessageWithoutProof + ',p=' + clientProof;
65
65
  }
66
66
  SASL.continueSession = continueSession;
67
67
  function finalizeSession(session, data) {
@@ -7,8 +7,7 @@ const bigint_methods_js_1 = require("../util/bigint-methods.js");
7
7
  const buffer_reader_js_1 = require("./buffer-reader.js");
8
8
  class SmartBuffer extends buffer_reader_js_1.BufferReader {
9
9
  constructor(cfg) {
10
- // @ts-ignore
11
- super(Buffer.allocUnsafe((cfg?.pageSize ? parseInt(cfg.pageSize, 10) : 0) || SmartBuffer.DEFAULT_PAGE_SIZE));
10
+ super(Buffer.allocUnsafe(cfg?.pageSize || SmartBuffer.DEFAULT_PAGE_SIZE));
12
11
  this._lastHouseKeep = 0;
13
12
  this._stMaxPages = 1;
14
13
  this._length = 0;
@@ -9,7 +9,7 @@ class SafeEventEmitter extends events_1.EventEmitter {
9
9
  return false;
10
10
  return super.emit(event, ...args);
11
11
  }
12
- catch (ignored) {
12
+ catch {
13
13
  return false;
14
14
  }
15
15
  }
@@ -1 +1 @@
1
- {"root":["../../src/constants.ts","../../src/data-type-map.ts","../../src/index.ts","../../src/safe-event-emitter.ts","../../src/types.ts","../../src/connection/bind-param.ts","../../src/connection/connection.ts","../../src/connection/cursor.ts","../../src/connection/intl-connection.ts","../../src/connection/pool.ts","../../src/connection/portal.ts","../../src/connection/prepared-statement.ts","../../src/data-types/bool-type.ts","../../src/data-types/box-type.ts","../../src/data-types/bytea-type.ts","../../src/data-types/char-type.ts","../../src/data-types/circle-type.ts","../../src/data-types/date-type.ts","../../src/data-types/float4-type.ts","../../src/data-types/float8-type.ts","../../src/data-types/int2-type.ts","../../src/data-types/int2-vector-type.ts","../../src/data-types/int4-type.ts","../../src/data-types/int8-type.ts","../../src/data-types/json-type.ts","../../src/data-types/jsonb-type.ts","../../src/data-types/lseg-type.ts","../../src/data-types/numeric-type.ts","../../src/data-types/oid-type.ts","../../src/data-types/point-type.ts","../../src/data-types/time-type.ts","../../src/data-types/timestamp-type.ts","../../src/data-types/timestamptz-type.ts","../../src/data-types/uuid-type.ts","../../src/data-types/varchar-type.ts","../../src/interfaces/command-result.ts","../../src/interfaces/data-mapping-options.ts","../../src/interfaces/data-type.ts","../../src/interfaces/database-connection-params.ts","../../src/interfaces/field-info.ts","../../src/interfaces/query-options.ts","../../src/interfaces/query-result.ts","../../src/interfaces/script-execute-options.ts","../../src/interfaces/script-result.ts","../../src/interfaces/statement-prepare-options.ts","../../src/protocol/backend.ts","../../src/protocol/buffer-reader.ts","../../src/protocol/database-error.ts","../../src/protocol/frontend.ts","../../src/protocol/pg-socket.ts","../../src/protocol/protocol.ts","../../src/protocol/sasl.ts","../../src/protocol/smart-buffer.ts","../../src/util/array-calculatedim.ts","../../src/util/bigint-methods.ts","../../src/util/config-from-env.ts","../../src/util/connection-config.ts","../../src/util/convert-row-to-object.ts","../../src/util/decode-binaryarray.ts","../../src/util/encode-binaryarray.ts","../../src/util/escape-literal.ts","../../src/util/fast-parseint.ts","../../src/util/get-parsers.ts","../../src/util/parse-array.ts","../../src/util/parse-datetime.ts","../../src/util/parse-row.ts","../../src/util/parse-time.ts","../../src/util/stringify-arrayliteral.ts","../../src/util/stringify-for-sql.ts","../../src/util/wrap-row-description.ts"],"version":"5.6.3"}
1
+ {"root":["../../src/constants.ts","../../src/data-type-map.ts","../../src/index.ts","../../src/safe-event-emitter.ts","../../src/types.ts","../../src/connection/bind-param.ts","../../src/connection/connection.ts","../../src/connection/cursor.ts","../../src/connection/intl-connection.ts","../../src/connection/pool.ts","../../src/connection/portal.ts","../../src/connection/prepared-statement.ts","../../src/data-types/bool-type.ts","../../src/data-types/box-type.ts","../../src/data-types/bytea-type.ts","../../src/data-types/char-type.ts","../../src/data-types/circle-type.ts","../../src/data-types/date-type.ts","../../src/data-types/float4-type.ts","../../src/data-types/float8-type.ts","../../src/data-types/int2-type.ts","../../src/data-types/int2-vector-type.ts","../../src/data-types/int4-type.ts","../../src/data-types/int8-type.ts","../../src/data-types/json-type.ts","../../src/data-types/jsonb-type.ts","../../src/data-types/lseg-type.ts","../../src/data-types/numeric-type.ts","../../src/data-types/oid-type.ts","../../src/data-types/point-type.ts","../../src/data-types/time-type.ts","../../src/data-types/timestamp-type.ts","../../src/data-types/timestamptz-type.ts","../../src/data-types/uuid-type.ts","../../src/data-types/varchar-type.ts","../../src/interfaces/command-result.ts","../../src/interfaces/data-mapping-options.ts","../../src/interfaces/data-type.ts","../../src/interfaces/database-connection-params.ts","../../src/interfaces/field-info.ts","../../src/interfaces/query-options.ts","../../src/interfaces/query-result.ts","../../src/interfaces/script-execute-options.ts","../../src/interfaces/script-result.ts","../../src/interfaces/statement-prepare-options.ts","../../src/protocol/backend.ts","../../src/protocol/buffer-reader.ts","../../src/protocol/database-error.ts","../../src/protocol/frontend.ts","../../src/protocol/pg-socket.ts","../../src/protocol/protocol.ts","../../src/protocol/sasl.ts","../../src/protocol/smart-buffer.ts","../../src/util/array-calculatedim.ts","../../src/util/bigint-methods.ts","../../src/util/config-from-env.ts","../../src/util/connection-config.ts","../../src/util/convert-row-to-object.ts","../../src/util/decode-binaryarray.ts","../../src/util/encode-binaryarray.ts","../../src/util/escape-literal.ts","../../src/util/fast-parseint.ts","../../src/util/get-parsers.ts","../../src/util/parse-array.ts","../../src/util/parse-datetime.ts","../../src/util/parse-row.ts","../../src/util/parse-time.ts","../../src/util/stringify-arrayliteral.ts","../../src/util/stringify-for-sql.ts","../../src/util/wrap-row-description.ts"],"version":"5.7.3"}
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readBigInt64BE = readBigInt64BE;
4
4
  exports.writeBigUInt64BE = writeBigUInt64BE;
5
- /* eslint-disable no-bitwise */
6
5
  const big0 = BigInt(0);
7
6
  const beAnd = BigInt('0xffffffff');
8
7
  const big32 = BigInt(32);
@@ -16,7 +15,11 @@ function readBigInt64BE(buf, offset = 0) {
16
15
  buf[++offset] * 2 ** 16 +
17
16
  buf[++offset] * 2 ** 8 +
18
17
  buf[++offset];
19
- return ((BigInt(val) << big32) + BigInt(buf[++offset] * 2 ** 24 + buf[++offset] * 2 ** 16 + buf[++offset] * 2 ** 8 + last));
18
+ return ((BigInt(val) << big32) +
19
+ BigInt(buf[++offset] * 2 ** 24 +
20
+ buf[++offset] * 2 ** 16 +
21
+ buf[++offset] * 2 ** 8 +
22
+ last));
20
23
  }
21
24
  function writeBigUInt64BE(buf, value, offset = 0) {
22
25
  // @ts-ignore
@@ -2,20 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getConnectionConfig = getConnectionConfig;
4
4
  exports.parseConnectionString = parseConnectionString;
5
- const tslib_1 = require("tslib");
6
- const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
5
+ const objects_1 = require("@jsopen/objects");
7
6
  const config_from_env_js_1 = require("./config-from-env.js");
8
7
  function getConnectionConfig(config) {
9
8
  const cfg = (0, config_from_env_js_1.configFromEnv)();
10
9
  if (typeof config === 'string') {
11
- (0, putil_merge_1.default)(cfg, parseConnectionString(config));
10
+ (0, objects_1.merge)(cfg, parseConnectionString(config));
12
11
  }
13
12
  else if (typeof config === 'object') {
14
- (0, putil_merge_1.default)(cfg, config);
13
+ (0, objects_1.merge)(cfg, config);
15
14
  }
16
15
  if (cfg.host) {
17
16
  const x = parseConnectionString('' + cfg.host);
18
- (0, putil_merge_1.default)(cfg, x);
17
+ (0, objects_1.merge)(cfg, x);
19
18
  }
20
19
  cfg.user = cfg.user || 'postgres';
21
20
  cfg.database = cfg.database || 'postgres';
@@ -28,7 +27,7 @@ function parseConnectionString(str) {
28
27
  if (!str.includes('://'))
29
28
  str = 'postgres://' + str;
30
29
  const parsed = new URL(str);
31
- const getFirst = (v) => (typeof v === 'string' ? v : Array.isArray(v) ? v[0] : '');
30
+ const getFirst = (v) => typeof v === 'string' ? v : Array.isArray(v) ? v[0] : '';
32
31
  const cfg = {};
33
32
  cfg.host = decodeURI(parsed.hostname || '');
34
33
  if (parsed.port)
@@ -4,9 +4,7 @@ exports.parseDateTime = parseDateTime;
4
4
  // noinspection RegExpUnnecessaryNonCapturingGroup
5
5
  const fast_parseint_js_1 = require("./fast-parseint.js");
6
6
  // noinspection RegExpUnnecessaryNonCapturingGroup
7
- const TIMESTAMP_PATTERN =
8
- // eslint-disable-next-line
9
- /^(\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])?))?)?$/;
7
+ const TIMESTAMP_PATTERN = /^(\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
8
  const INFINITY_PATTERN = /^-?infinity$/;
11
9
  function parseDateTime(str, parseTime, parseTimeZone, utc) {
12
10
  let m = str.match(TIMESTAMP_PATTERN);
@@ -16,7 +14,9 @@ function parseDateTime(str, parseTime, parseTimeZone, utc) {
16
14
  return Number(str.replace('i', 'I'));
17
15
  return new Date('invalid');
18
16
  }
19
- const args = [1970, 0, 1, 0, 0, 0, 0];
17
+ const args = [
18
+ 1970, 0, 1, 0, 0, 0, 0,
19
+ ];
20
20
  const l = parseTime ? 7 : 3;
21
21
  for (let i = 0; i < l; i++) {
22
22
  const s = m[i + 1];
@@ -5,6 +5,7 @@ function parseRow(parsers, row, options) {
5
5
  const l = row.length;
6
6
  let i;
7
7
  for (i = 0; i < l; i++) {
8
- row[i] = row[i] == null ? null : parsers[i].call(undefined, row[i], options);
8
+ row[i] =
9
+ row[i] == null ? null : parsers[i].call(undefined, row[i], options);
9
10
  }
10
11
  }
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TIME_PATTERN = exports.STRICT_TIME_PATTERN = void 0;
4
4
  exports.parseTime = parseTime;
5
5
  const fast_parseint_js_1 = require("./fast-parseint.js");
6
- // eslint-disable-next-line
7
6
  // noinspection RegExpUnnecessaryNonCapturingGroup
8
7
  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])?))?$/;
9
8
  // noinspection RegExpUnnecessaryNonCapturingGroup
@@ -12,7 +11,9 @@ function parseTime(str, parseTimeZone, utc) {
12
11
  const m = str.match(exports.TIME_PATTERN);
13
12
  if (!m)
14
13
  return new Date('invalid');
15
- const args = [1970, 0, 1, 0, 0, 0, 0];
14
+ const args = [
15
+ 1970, 0, 1, 0, 0, 0, 0,
16
+ ];
16
17
  for (let i = 1; i < 4; i++) {
17
18
  const s = m[i];
18
19
  args[i + 2] = (0, fast_parseint_js_1.fastParseInt)(s) || 0;
@@ -9,7 +9,9 @@ export class Connection extends SafeEventEmitter {
9
9
  super();
10
10
  this._notificationListeners = new SafeEventEmitter();
11
11
  this._closing = false;
12
- if (arg0 && typeof arg0 === 'object' && typeof arg0.acquire === 'function') {
12
+ if (arg0 &&
13
+ typeof arg0 === 'object' &&
14
+ typeof arg0.acquire === 'function') {
13
15
  if (!(arg1 instanceof IntlConnection))
14
16
  throw new TypeError('Invalid argument');
15
17
  this._pool = arg0;
@@ -91,7 +93,9 @@ export class Connection extends SafeEventEmitter {
91
93
  });
92
94
  }
93
95
  this._closing = true;
94
- if (this._intlCon.refCount > 0 && typeof terminateWait === 'number' && terminateWait > 0) {
96
+ if (this._intlCon.refCount > 0 &&
97
+ typeof terminateWait === 'number' &&
98
+ terminateWait > 0) {
95
99
  const startTime = Date.now();
96
100
  return this._captureErrorStack(new Promise((resolve, reject) => {
97
101
  /* istanbul ignore next */
@@ -103,7 +107,8 @@ export class Connection extends SafeEventEmitter {
103
107
  });
104
108
  }
105
109
  const timer = setInterval(() => {
106
- if (this._intlCon.refCount <= 0 || Date.now() > startTime + terminateWait) {
110
+ if (this._intlCon.refCount <= 0 ||
111
+ Date.now() > startTime + terminateWait) {
107
112
  clearInterval(timer);
108
113
  if (this._intlCon.refCount > 0) {
109
114
  /* istanbul ignore next */
@@ -153,7 +158,7 @@ export class Connection extends SafeEventEmitter {
153
158
  throw this._handleError(e, sql);
154
159
  });
155
160
  try {
156
- const params = options?.params?.map(prm => (prm instanceof BindParam ? prm.value : prm));
161
+ const params = options?.params?.map(prm => prm instanceof BindParam ? prm.value : prm);
157
162
  return await this._captureErrorStack(statement.execute({ ...options, params }));
158
163
  }
159
164
  finally {
@@ -61,9 +61,11 @@ export class IntlConnection extends SafeEventEmitter {
61
61
  });
62
62
  let startupCommand = '';
63
63
  if (this.config.schema)
64
- startupCommand += 'SET search_path = ' + escapeLiteral(this.config.schema) + ';';
64
+ startupCommand +=
65
+ 'SET search_path = ' + escapeLiteral(this.config.schema) + ';';
65
66
  if (this.config.timezone)
66
- startupCommand += 'SET timezone TO ' + escapeLiteral(this.config.timezone) + ';';
67
+ startupCommand +=
68
+ 'SET timezone TO ' + escapeLiteral(this.config.timezone) + ';';
67
69
  if (startupCommand)
68
70
  await this.execute(startupCommand, { autoCommit: true });
69
71
  this.emit('ready');
@@ -91,7 +93,9 @@ export class IntlConnection extends SafeEventEmitter {
91
93
  let commitLast = false;
92
94
  if (!transactionCommand) {
93
95
  if (!this.inTransaction &&
94
- (options?.autoCommit != null ? options?.autoCommit : this.config.autoCommit) === false) {
96
+ (options?.autoCommit != null
97
+ ? options?.autoCommit
98
+ : this.config.autoCommit) === false) {
95
99
  beginFirst = true;
96
100
  }
97
101
  if (this.inTransaction && options?.autoCommit)
@@ -207,12 +211,15 @@ export class IntlConnection extends SafeEventEmitter {
207
211
  case Protocol.BackendMessageCode.CommandComplete:
208
212
  // Ignore BEGIN command that we added to sql
209
213
  current.command = msg.command;
210
- if (current.command === 'DELETE' || current.command === 'INSERT' || current.command === 'UPDATE') {
214
+ if (current.command === 'DELETE' ||
215
+ current.command === 'INSERT' ||
216
+ current.command === 'UPDATE') {
211
217
  current.rowsAffected = msg.rowCount;
212
218
  }
213
219
  current.executeTime = Date.now() - currentStart;
214
220
  if (current.rows)
215
- current.rowType = opts.objectRows && current.fields ? 'object' : 'array';
221
+ current.rowType =
222
+ opts.objectRows && current.fields ? 'object' : 'array';
216
223
  result.results.push(current);
217
224
  if (cb)
218
225
  cb('command-complete', current);
@@ -1,4 +1,4 @@
1
- import { Pool as LightningPool } from 'lightning-pool';
1
+ import { Pool as LightningPool, } from 'lightning-pool';
2
2
  import { coerceToBoolean, coerceToInt } from 'putil-varhelpers';
3
3
  import { ConnectionState } from '../constants.js';
4
4
  import { SafeEventEmitter } from '../safe-event-emitter.js';
@@ -19,7 +19,10 @@ export class Portal {
19
19
  intoCon.ref();
20
20
  try {
21
21
  const socket = intoCon.socket;
22
- this._columnFormat = queryOptions.columnFormat != null ? queryOptions.columnFormat : Protocol.DataFormat.binary;
22
+ this._columnFormat =
23
+ queryOptions.columnFormat != null
24
+ ? queryOptions.columnFormat
25
+ : Protocol.DataFormat.binary;
23
26
  socket.sendBindMessage({
24
27
  typeMap: queryOptions.typeMap || GlobalTypeMap,
25
28
  statement: this._statement.name,
@@ -76,7 +79,10 @@ export class Portal {
76
79
  intoCon.ref();
77
80
  try {
78
81
  const socket = intoCon.socket;
79
- socket.sendExecuteMessage({ portal: this.name, fetchCount: fetchCount || 100 });
82
+ socket.sendExecuteMessage({
83
+ portal: this.name,
84
+ fetchCount: fetchCount || 100,
85
+ });
80
86
  socket.sendFlushMessage();
81
87
  const rows = [];
82
88
  return await socket.capture(async (code, msg, done) => {
@@ -88,7 +94,8 @@ export class Portal {
88
94
  break;
89
95
  case Protocol.BackendMessageCode.DataRow:
90
96
  if (Array.isArray(this._columnFormat)) {
91
- rows.push(msg.columns.map((buf, i) => this._columnFormat[i] === Protocol.DataFormat.text
97
+ rows.push(msg.columns.map((buf, i) => this._columnFormat[i] ===
98
+ Protocol.DataFormat.text
92
99
  ? buf.toString('utf8')
93
100
  : buf));
94
101
  }
@@ -82,7 +82,9 @@ export class PreparedStatement extends SafeEventEmitter {
82
82
  let commitLast = false;
83
83
  if (!transactionCommand) {
84
84
  if (!intlCon.inTransaction &&
85
- (options?.autoCommit != null ? options?.autoCommit : intlCon.config.autoCommit) === false) {
85
+ (options?.autoCommit != null
86
+ ? options?.autoCommit
87
+ : intlCon.config.autoCommit) === false) {
86
88
  beginFirst = true;
87
89
  }
88
90
  if (intlCon.inTransaction && options?.autoCommit)
@@ -97,7 +99,9 @@ export class PreparedStatement extends SafeEventEmitter {
97
99
  if (intlCon.inTransaction && rollbackOnError)
98
100
  await intlCon.execute('SAVEPOINT ' + this._onErrorSavePoint);
99
101
  try {
100
- const result = await intlCon.statementQueue.enqueue(() => this._execute(options)).toPromise();
102
+ const result = await intlCon.statementQueue
103
+ .enqueue(() => this._execute(options))
104
+ .toPromise();
101
105
  if (commitLast)
102
106
  await intlCon.execute('COMMIT');
103
107
  else if (intlCon.inTransaction && rollbackOnError) {
@@ -168,7 +172,9 @@ export class PreparedStatement extends SafeEventEmitter {
168
172
  }
169
173
  }
170
174
  }
171
- if (result.command === 'DELETE' || result.command === 'INSERT' || result.command === 'UPDATE') {
175
+ if (result.command === 'DELETE' ||
176
+ result.command === 'INSERT' ||
177
+ result.command === 'UPDATE') {
172
178
  result.rowsAffected = executeResult.rowCount;
173
179
  }
174
180
  result.executeTime = Date.now() - startTime;
package/esm/constants.js CHANGED
@@ -68,7 +68,6 @@ export const DataTypeOIDs = {
68
68
  anyarray: 2277,
69
69
  void: 2278,
70
70
  trigger: 2279,
71
- // eslint-disable-next-line camelcase
72
71
  language_handler: 2280,
73
72
  internal: 2281,
74
73
  anyelement: 2283,
@@ -8,7 +8,7 @@ import { ArrayDateType, DateType } from './data-types/date-type.js';
8
8
  import { ArrayFloat4Type, Float4Type } from './data-types/float4-type.js';
9
9
  import { ArrayFloat8Type, Float8Type } from './data-types/float8-type.js';
10
10
  import { ArrayInt2Type, Int2Type } from './data-types/int2-type.js';
11
- import { ArrayInt2VectorType, Int2VectorType } from './data-types/int2-vector-type.js';
11
+ import { ArrayInt2VectorType, Int2VectorType, } from './data-types/int2-vector-type.js';
12
12
  import { ArrayInt4Type, Int4Type } from './data-types/int4-type.js';
13
13
  import { ArrayInt8Type, Int8Type } from './data-types/int8-type.js';
14
14
  import { ArrayJsonType, JsonType } from './data-types/json-type.js';
@@ -18,8 +18,8 @@ import { ArrayNumericType, NumericType } from './data-types/numeric-type.js';
18
18
  import { ArrayOidType, OidType, VectorOidType } from './data-types/oid-type.js';
19
19
  import { ArrayPointType, PointType } from './data-types/point-type.js';
20
20
  import { ArrayTimeType, TimeType } from './data-types/time-type.js';
21
- import { ArrayTimestampType, TimestampType } from './data-types/timestamp-type.js';
22
- import { ArrayTimestamptzType, TimestamptzType } from './data-types/timestamptz-type.js';
21
+ import { ArrayTimestampType, TimestampType, } from './data-types/timestamp-type.js';
22
+ import { ArrayTimestamptzType, TimestamptzType, } from './data-types/timestamptz-type.js';
23
23
  import { ArrayUuidType, UuidType } from './data-types/uuid-type.js';
24
24
  import { ArrayVarcharType, VarcharType } from './data-types/varchar-type.js';
25
25
  export class DataTypeMap {
@@ -78,21 +78,33 @@ GlobalTypeMap.register([PointType, ArrayPointType]);
78
78
  GlobalTypeMap.register([LsegType, ArrayLsegType]);
79
79
  GlobalTypeMap.register([BoxType, ArrayBoxType]);
80
80
  GlobalTypeMap.register([Int2VectorType, ArrayInt2VectorType]);
81
- GlobalTypeMap.register({ ...VarcharType, name: 'bpchar', oid: DataTypeOIDs.bpchar });
81
+ GlobalTypeMap.register({
82
+ ...VarcharType,
83
+ name: 'bpchar',
84
+ oid: DataTypeOIDs.bpchar,
85
+ });
82
86
  GlobalTypeMap.register({
83
87
  ...ArrayVarcharType,
84
88
  name: '_bpchar',
85
89
  oid: DataTypeOIDs._bpchar,
86
90
  elementsOID: DataTypeOIDs.bpchar,
87
91
  });
88
- GlobalTypeMap.register({ ...VarcharType, name: 'name', oid: DataTypeOIDs.name });
92
+ GlobalTypeMap.register({
93
+ ...VarcharType,
94
+ name: 'name',
95
+ oid: DataTypeOIDs.name,
96
+ });
89
97
  GlobalTypeMap.register({
90
98
  ...ArrayVarcharType,
91
99
  name: '_name',
92
100
  oid: DataTypeOIDs._name,
93
101
  elementsOID: DataTypeOIDs.name,
94
102
  });
95
- GlobalTypeMap.register({ ...VarcharType, name: 'text', oid: DataTypeOIDs.text });
103
+ GlobalTypeMap.register({
104
+ ...VarcharType,
105
+ name: 'text',
106
+ oid: DataTypeOIDs.text,
107
+ });
96
108
  GlobalTypeMap.register({
97
109
  ...ArrayVarcharType,
98
110
  name: '_text',
@@ -10,7 +10,13 @@ export const BoolType = {
10
10
  buf.writeInt8(v ? 1 : 0);
11
11
  },
12
12
  parseText(v) {
13
- return v === 'TRUE' || v === 't' || v === 'true' || v === 'y' || v === 'yes' || v === 'on' || v === '1';
13
+ return (v === 'TRUE' ||
14
+ v === 't' ||
15
+ v === 'true' ||
16
+ v === 'y' ||
17
+ v === 'yes' ||
18
+ v === 'on' ||
19
+ v === '1');
14
20
  },
15
21
  isType(v) {
16
22
  return typeof v === 'boolean';
@@ -20,7 +20,10 @@ export const CircleType = {
20
20
  buf.writeDoubleBE(v.r);
21
21
  },
22
22
  parseText(v) {
23
- const m = v.match(CIRCLE_PATTERN1) || v.match(CIRCLE_PATTERN2) || v.match(CIRCLE_PATTERN3) || v.match(CIRCLE_PATTERN4);
23
+ const m = v.match(CIRCLE_PATTERN1) ||
24
+ v.match(CIRCLE_PATTERN2) ||
25
+ v.match(CIRCLE_PATTERN3) ||
26
+ v.match(CIRCLE_PATTERN4);
24
27
  if (!m)
25
28
  return undefined;
26
29
  return {
@@ -6,7 +6,8 @@ export const DateType = {
6
6
  oid: DataTypeOIDs.date,
7
7
  jsType: 'Date',
8
8
  parseBinary(v, options) {
9
- const fetchAsString = options.fetchAsString && options.fetchAsString.includes(DataTypeOIDs.date);
9
+ const fetchAsString = options.fetchAsString &&
10
+ options.fetchAsString.includes(DataTypeOIDs.date);
10
11
  const t = v.readInt32BE();
11
12
  if (t === 0x7fffffff)
12
13
  return fetchAsString ? 'infinity' : Infinity;
@@ -31,13 +32,16 @@ export const DateType = {
31
32
  }
32
33
  if (!(v instanceof Date))
33
34
  v = new Date(v);
34
- let n = options.utcDates ? v.getTime() : v.getTime() - v.getTimezoneOffset() * 60 * 1000;
35
+ let n = options.utcDates
36
+ ? v.getTime()
37
+ : v.getTime() - v.getTimezoneOffset() * 60 * 1000;
35
38
  n = (n - timeShift) / 1000 / 86400;
36
39
  const t = Math.trunc(n + Number.EPSILON);
37
40
  buf.writeInt32BE(t);
38
41
  },
39
42
  parseText(v, options) {
40
- const fetchAsString = options.fetchAsString && options.fetchAsString.includes(DataTypeOIDs.date);
43
+ const fetchAsString = options.fetchAsString &&
44
+ options.fetchAsString.includes(DataTypeOIDs.date);
41
45
  if (fetchAsString)
42
46
  return v;
43
47
  return parseDateTime(v, false, false, options.utcDates);
@@ -54,7 +58,11 @@ function padZero(v) {
54
58
  return v < 9 ? '0' + v : '' + v;
55
59
  }
56
60
  function dateToDateString(d) {
57
- return d.getFullYear() + '-' + padZero(d.getMonth() + 1) + '-' + padZero(d.getDate());
61
+ return (d.getFullYear() +
62
+ '-' +
63
+ padZero(d.getMonth() + 1) +
64
+ '-' +
65
+ padZero(d.getDate()));
58
66
  }
59
67
  export const ArrayDateType = {
60
68
  ...DateType,
@@ -12,7 +12,7 @@ export const Int2Type = {
12
12
  },
13
13
  parseText: fastParseInt,
14
14
  isType(v) {
15
- return typeof v === 'number' && Number.isInteger(v) && v >= -32768 && v <= 32767;
15
+ return (typeof v === 'number' && Number.isInteger(v) && v >= -32768 && v <= 32767);
16
16
  },
17
17
  };
18
18
  export const ArrayInt2Type = {
@@ -24,7 +24,11 @@ export const Int2VectorType = {
24
24
  return v.join(' ');
25
25
  },
26
26
  isType(v) {
27
- return (Array.isArray(v) && !v.find(x => !(typeof x === 'number' && Number.isInteger(x) && x >= -32768 && x <= 32767)));
27
+ return (Array.isArray(v) &&
28
+ !v.find(x => !(typeof x === 'number' &&
29
+ Number.isInteger(x) &&
30
+ x >= -32768 &&
31
+ x <= 32767)));
28
32
  },
29
33
  };
30
34
  export const ArrayInt2VectorType = {
@@ -12,7 +12,9 @@ export const Int4Type = {
12
12
  },
13
13
  parseText: fastParseInt,
14
14
  isType(v) {
15
- return typeof v === 'number' && Number.isInteger(v) && v <= Number.MAX_SAFE_INTEGER;
15
+ return (typeof v === 'number' &&
16
+ Number.isInteger(v) &&
17
+ v <= Number.MAX_SAFE_INTEGER);
16
18
  },
17
19
  };
18
20
  export const ArrayInt4Type = {