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