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
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # v2.16.0
2
+ [2024-08-09]
3
+
4
+ ### Changes
5
+
6
+ * Made ready for Node16 moduleResolution ([`6632dc0`](https://github.com/panates/postgrejs/commit/6632dc03f3c47edd1a4b2b6fea8a07aa671a10bb))
7
+
1
8
  # v2.15.4
2
9
  [2024-08-03]
3
10
 
@@ -1,6 +1,10 @@
1
- export class BindParam {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BindParam = void 0;
4
+ class BindParam {
2
5
  constructor(oid, value) {
3
6
  this.oid = oid;
4
7
  this.value = value;
5
8
  }
6
9
  }
10
+ exports.BindParam = BindParam;
@@ -1,22 +1,25 @@
1
- import { ConnectionState } from '../constants.js';
2
- import { GlobalTypeMap } from '../data-type-map.js';
3
- import { SafeEventEmitter } from '../safe-event-emitter.js';
4
- import { BindParam } from './bind-param.js';
5
- import { IntlConnection } from './intl-connection.js';
6
- import { PreparedStatement } from './prepared-statement.js';
7
- export class Connection extends SafeEventEmitter {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Connection = void 0;
4
+ const constants_js_1 = require("../constants.js");
5
+ const data_type_map_js_1 = require("../data-type-map.js");
6
+ const safe_event_emitter_js_1 = require("../safe-event-emitter.js");
7
+ const bind_param_js_1 = require("./bind-param.js");
8
+ const intl_connection_js_1 = require("./intl-connection.js");
9
+ const prepared_statement_js_1 = require("./prepared-statement.js");
10
+ class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
8
11
  constructor(arg0, arg1) {
9
12
  super();
10
- this._notificationListeners = new SafeEventEmitter();
13
+ this._notificationListeners = new safe_event_emitter_js_1.SafeEventEmitter();
11
14
  this._closing = false;
12
15
  if (arg0 && typeof arg0 === 'object' && typeof arg0.acquire === 'function') {
13
- if (!(arg1 instanceof IntlConnection))
16
+ if (!(arg1 instanceof intl_connection_js_1.IntlConnection))
14
17
  throw new TypeError('Invalid argument');
15
18
  this._pool = arg0;
16
19
  this._intlCon = arg1;
17
20
  }
18
21
  else {
19
- this._intlCon = new IntlConnection(arg0);
22
+ this._intlCon = new intl_connection_js_1.IntlConnection(arg0);
20
23
  }
21
24
  this._intlCon.on('ready', (...args) => this.emit('ready', ...args));
22
25
  this._intlCon.on('error', (...args) => this.emit('error', ...args));
@@ -67,7 +70,7 @@ export class Connection extends SafeEventEmitter {
67
70
  */
68
71
  async connect() {
69
72
  await this._captureErrorStack(this._intlCon.connect());
70
- if (this.state === ConnectionState.READY)
73
+ if (this.state === constants_js_1.ConnectionState.READY)
71
74
  this._closing = false;
72
75
  }
73
76
  /**
@@ -80,7 +83,7 @@ export class Connection extends SafeEventEmitter {
80
83
  async close(terminateWait) {
81
84
  this._notificationListeners.removeAllListeners();
82
85
  this._intlCon.statementQueue.clearQueue();
83
- if (this.state === ConnectionState.CLOSED || this._closing)
86
+ if (this.state === constants_js_1.ConnectionState.CLOSED || this._closing)
84
87
  return;
85
88
  /* istanbul ignore next */
86
89
  if (this.listenerCount('debug')) {
@@ -145,13 +148,13 @@ export class Connection extends SafeEventEmitter {
145
148
  sql,
146
149
  });
147
150
  }
148
- const typeMap = options?.typeMap || GlobalTypeMap;
149
- const paramTypes = options?.params?.map(prm => prm instanceof BindParam ? prm.oid : typeMap.determine(prm));
151
+ const typeMap = options?.typeMap || data_type_map_js_1.GlobalTypeMap;
152
+ const paramTypes = options?.params?.map(prm => prm instanceof bind_param_js_1.BindParam ? prm.oid : typeMap.determine(prm));
150
153
  const statement = await this.prepare(sql, { paramTypes, typeMap }).catch((e) => {
151
154
  throw this._handleError(e, sql);
152
155
  });
153
156
  try {
154
- const params = options?.params?.map(prm => (prm instanceof BindParam ? prm.value : prm));
157
+ const params = options?.params?.map(prm => (prm instanceof bind_param_js_1.BindParam ? prm.value : prm));
155
158
  return await this._captureErrorStack(statement.execute({ ...options, params }));
156
159
  }
157
160
  finally {
@@ -173,7 +176,7 @@ export class Connection extends SafeEventEmitter {
173
176
  sql,
174
177
  });
175
178
  }
176
- return await this._captureErrorStack(PreparedStatement.prepare(this, sql, options));
179
+ return await this._captureErrorStack(prepared_statement_js_1.PreparedStatement.prepare(this, sql, options));
177
180
  }
178
181
  /**
179
182
  * Starts a transaction
@@ -278,3 +281,4 @@ export class Connection extends SafeEventEmitter {
278
281
  return this.close();
279
282
  }
280
283
  }
284
+ exports.Connection = Connection;
@@ -1,13 +1,17 @@
1
- import DoublyLinked from 'doublylinked';
2
- import { TaskQueue } from 'power-tasks';
3
- import { SafeEventEmitter } from '../safe-event-emitter.js';
4
- import { convertRowToObject } from '../util/convert-row-to-object.js';
5
- import { parseRow } from '../util/parse-row.js';
6
- export class Cursor extends SafeEventEmitter {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Cursor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const doublylinked_1 = tslib_1.__importDefault(require("doublylinked"));
6
+ const power_tasks_1 = require("power-tasks");
7
+ const safe_event_emitter_js_1 = require("../safe-event-emitter.js");
8
+ const convert_row_to_object_js_1 = require("../util/convert-row-to-object.js");
9
+ const parse_row_js_1 = require("../util/parse-row.js");
10
+ class Cursor extends safe_event_emitter_js_1.SafeEventEmitter {
7
11
  constructor(statement, portal, fields, parsers, queryOptions) {
8
12
  super();
9
- this._taskQueue = new TaskQueue({ concurrency: 1 });
10
- this._rows = new DoublyLinked();
13
+ this._taskQueue = new power_tasks_1.TaskQueue({ concurrency: 1 });
14
+ this._rows = new doublylinked_1.default();
11
15
  this._closed = false;
12
16
  this._statement = statement;
13
17
  this._portal = portal;
@@ -66,9 +70,9 @@ export class Cursor extends SafeEventEmitter {
66
70
  const rows = r.rows;
67
71
  for (let i = 0; i < rows.length; i++) {
68
72
  const row = rows[i];
69
- parseRow(this._parsers, row, this._queryOptions);
73
+ (0, parse_row_js_1.parseRow)(this._parsers, row, this._queryOptions);
70
74
  if (objectRows)
71
- rows[i] = convertRowToObject(fields, row);
75
+ rows[i] = (0, convert_row_to_object_js_1.convertRowToObject)(fields, row);
72
76
  }
73
77
  }
74
78
  this._rows.push(...r.rows);
@@ -84,3 +88,4 @@ export class Cursor extends SafeEventEmitter {
84
88
  return this.close();
85
89
  }
86
90
  }
91
+ exports.Cursor = Cursor;
@@ -1,25 +1,29 @@
1
- import { TaskQueue } from 'power-tasks';
2
- import { coerceToBoolean } from 'putil-varhelpers';
3
- import { ConnectionState } from '../constants.js';
4
- import { GlobalTypeMap } from '../data-type-map.js';
5
- import { PgSocket } from '../protocol/pg-socket.js';
6
- import { Protocol } from '../protocol/protocol.js';
7
- import { SafeEventEmitter } from '../safe-event-emitter.js';
8
- import { getConnectionConfig } from '../util/connection-config.js';
9
- import { convertRowToObject } from '../util/convert-row-to-object.js';
10
- import { escapeLiteral } from '../util/escape-literal.js';
11
- import { getParsers } from '../util/get-parsers.js';
12
- import { parseRow } from '../util/parse-row.js';
13
- import { wrapRowDescription } from '../util/wrap-row-description.js';
14
- const DataFormat = Protocol.DataFormat;
15
- export class IntlConnection extends SafeEventEmitter {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IntlConnection = void 0;
4
+ exports.getIntlConnection = getIntlConnection;
5
+ const power_tasks_1 = require("power-tasks");
6
+ const putil_varhelpers_1 = require("putil-varhelpers");
7
+ const constants_js_1 = require("../constants.js");
8
+ const data_type_map_js_1 = require("../data-type-map.js");
9
+ const pg_socket_js_1 = require("../protocol/pg-socket.js");
10
+ const protocol_js_1 = require("../protocol/protocol.js");
11
+ const safe_event_emitter_js_1 = require("../safe-event-emitter.js");
12
+ const connection_config_js_1 = require("../util/connection-config.js");
13
+ const convert_row_to_object_js_1 = require("../util/convert-row-to-object.js");
14
+ const escape_literal_js_1 = require("../util/escape-literal.js");
15
+ const get_parsers_js_1 = require("../util/get-parsers.js");
16
+ const parse_row_js_1 = require("../util/parse-row.js");
17
+ const wrap_row_description_js_1 = require("../util/wrap-row-description.js");
18
+ const DataFormat = protocol_js_1.Protocol.DataFormat;
19
+ class IntlConnection extends safe_event_emitter_js_1.SafeEventEmitter {
16
20
  constructor(config) {
17
21
  super();
18
22
  this._refCount = 0;
19
23
  this.transactionStatus = 'I';
20
- this.statementQueue = new TaskQueue({ concurrency: 1 });
21
- this._config = Object.freeze(getConnectionConfig(config));
22
- this.socket = new PgSocket(this._config);
24
+ this.statementQueue = new power_tasks_1.TaskQueue({ concurrency: 1 });
25
+ this._config = Object.freeze((0, connection_config_js_1.getConnectionConfig)(config));
26
+ this.socket = new pg_socket_js_1.PgSocket(this._config);
23
27
  this.socket.on('error', err => this._onError(err));
24
28
  this.socket.on('close', () => this.emit('close'));
25
29
  this.socket.on('notification', payload => this.emit('notification', payload));
@@ -48,7 +52,7 @@ export class IntlConnection extends SafeEventEmitter {
48
52
  return this.socket.sessionParameters;
49
53
  }
50
54
  async connect() {
51
- if (this.socket.state === ConnectionState.READY)
55
+ if (this.socket.state === constants_js_1.ConnectionState.READY)
52
56
  return;
53
57
  await new Promise((resolve, reject) => {
54
58
  const handleConnectError = err => reject(err);
@@ -61,19 +65,19 @@ export class IntlConnection extends SafeEventEmitter {
61
65
  });
62
66
  let startupCommand = '';
63
67
  if (this.config.schema)
64
- startupCommand += 'SET search_path = ' + escapeLiteral(this.config.schema) + ';';
68
+ startupCommand += 'SET search_path = ' + (0, escape_literal_js_1.escapeLiteral)(this.config.schema) + ';';
65
69
  if (this.config.timezone)
66
- startupCommand += 'SET timezone TO ' + escapeLiteral(this.config.timezone) + ';';
70
+ startupCommand += 'SET timezone TO ' + (0, escape_literal_js_1.escapeLiteral)(this.config.timezone) + ';';
67
71
  if (startupCommand)
68
72
  await this.execute(startupCommand, { autoCommit: true });
69
73
  this.emit('ready');
70
74
  }
71
75
  async close() {
72
- if (this.state === ConnectionState.CLOSED)
76
+ if (this.state === constants_js_1.ConnectionState.CLOSED)
73
77
  return;
74
78
  this.statementQueue.clearQueue();
75
79
  return new Promise(resolve => {
76
- if (this.socket.state === ConnectionState.CLOSED)
80
+ if (this.socket.state === constants_js_1.ConnectionState.CLOSED)
77
81
  return;
78
82
  this.socket.once('close', resolve);
79
83
  this.socket.sendTerminateMessage(() => {
@@ -102,7 +106,7 @@ export class IntlConnection extends SafeEventEmitter {
102
106
  const rollbackOnError = !transactionCommand &&
103
107
  (options?.rollbackOnError != null
104
108
  ? options.rollbackOnError
105
- : coerceToBoolean(this.config.rollbackOnError, true));
109
+ : (0, putil_varhelpers_1.coerceToBoolean)(this.config.rollbackOnError, true));
106
110
  if (this.inTransaction && rollbackOnError)
107
111
  await this._execute('SAVEPOINT ' + this._onErrorSavePoint);
108
112
  try {
@@ -157,9 +161,9 @@ export class IntlConnection extends SafeEventEmitter {
157
161
  return !this._refCount;
158
162
  }
159
163
  assertConnected() {
160
- if (this.state === ConnectionState.CLOSING)
164
+ if (this.state === constants_js_1.ConnectionState.CLOSING)
161
165
  throw new Error('Connection is closing');
162
- if (this.state === ConnectionState.CLOSED)
166
+ if (this.state === constants_js_1.ConnectionState.CLOSED)
163
167
  throw new Error('Connection closed');
164
168
  }
165
169
  async _execute(sql, options, cb) {
@@ -177,33 +181,33 @@ export class IntlConnection extends SafeEventEmitter {
177
181
  let parsers;
178
182
  let current = { command: undefined };
179
183
  let fields;
180
- const typeMap = opts.typeMap || GlobalTypeMap;
184
+ const typeMap = opts.typeMap || data_type_map_js_1.GlobalTypeMap;
181
185
  return await this.socket.capture(async (code, msg, done) => {
182
186
  switch (code) {
183
- case Protocol.BackendMessageCode.NoticeResponse:
184
- case Protocol.BackendMessageCode.CopyInResponse:
185
- case Protocol.BackendMessageCode.CopyOutResponse:
186
- case Protocol.BackendMessageCode.EmptyQueryResponse:
187
+ case protocol_js_1.Protocol.BackendMessageCode.NoticeResponse:
188
+ case protocol_js_1.Protocol.BackendMessageCode.CopyInResponse:
189
+ case protocol_js_1.Protocol.BackendMessageCode.CopyOutResponse:
190
+ case protocol_js_1.Protocol.BackendMessageCode.EmptyQueryResponse:
187
191
  break;
188
- case Protocol.BackendMessageCode.RowDescription:
192
+ case protocol_js_1.Protocol.BackendMessageCode.RowDescription:
189
193
  fields = msg.fields;
190
- parsers = getParsers(typeMap, fields);
191
- current.fields = wrapRowDescription(typeMap, fields, DataFormat.text);
194
+ parsers = (0, get_parsers_js_1.getParsers)(typeMap, fields);
195
+ current.fields = (0, wrap_row_description_js_1.wrapRowDescription)(typeMap, fields, DataFormat.text);
192
196
  current.rows = [];
193
197
  break;
194
- case Protocol.BackendMessageCode.DataRow:
198
+ case protocol_js_1.Protocol.BackendMessageCode.DataRow:
195
199
  {
196
200
  let row = msg.columns.map((x) => x.toString('utf8'));
197
- parseRow(parsers, row, opts);
201
+ (0, parse_row_js_1.parseRow)(parsers, row, opts);
198
202
  if (opts.objectRows && current.fields)
199
- row = convertRowToObject(current.fields, row);
203
+ row = (0, convert_row_to_object_js_1.convertRowToObject)(current.fields, row);
200
204
  if (cb)
201
205
  cb('row', row);
202
206
  current.rows = current.rows || [];
203
207
  current.rows.push(row);
204
208
  }
205
209
  break;
206
- case Protocol.BackendMessageCode.CommandComplete:
210
+ case protocol_js_1.Protocol.BackendMessageCode.CommandComplete:
207
211
  // Ignore BEGIN command that we added to sql
208
212
  current.command = msg.command;
209
213
  if (current.command === 'DELETE' || current.command === 'INSERT' || current.command === 'UPDATE') {
@@ -218,7 +222,7 @@ export class IntlConnection extends SafeEventEmitter {
218
222
  current = { command: undefined };
219
223
  currentStart = Date.now();
220
224
  break;
221
- case Protocol.BackendMessageCode.ReadyForQuery:
225
+ case protocol_js_1.Protocol.BackendMessageCode.ReadyForQuery:
222
226
  this.transactionStatus = msg.status;
223
227
  result.totalTime = Date.now() - startTime;
224
228
  // Ignore COMMIT command that we added to sql
@@ -235,11 +239,12 @@ export class IntlConnection extends SafeEventEmitter {
235
239
  }
236
240
  }
237
241
  _onError(err) {
238
- if (this.socket.state !== ConnectionState.READY)
242
+ if (this.socket.state !== constants_js_1.ConnectionState.READY)
239
243
  return;
240
244
  this.emit('error', err);
241
245
  }
242
246
  }
243
- export function getIntlConnection(connection) {
247
+ exports.IntlConnection = IntlConnection;
248
+ function getIntlConnection(connection) {
244
249
  return connection._intlCon;
245
250
  }
@@ -1,27 +1,30 @@
1
- import { Pool as LightningPool } from 'lightning-pool';
2
- import { coerceToBoolean, coerceToInt } from 'putil-varhelpers';
3
- import { ConnectionState } from '../constants.js';
4
- import { SafeEventEmitter } from '../safe-event-emitter.js';
5
- import { getConnectionConfig } from '../util/connection-config.js';
6
- import { Connection } from './connection.js';
7
- import { getIntlConnection, IntlConnection } from './intl-connection.js';
8
- export class Pool extends SafeEventEmitter {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pool = void 0;
4
+ const lightning_pool_1 = require("lightning-pool");
5
+ const putil_varhelpers_1 = require("putil-varhelpers");
6
+ const constants_js_1 = require("../constants.js");
7
+ const safe_event_emitter_js_1 = require("../safe-event-emitter.js");
8
+ const connection_config_js_1 = require("../util/connection-config.js");
9
+ const connection_js_1 = require("./connection.js");
10
+ const intl_connection_js_1 = require("./intl-connection.js");
11
+ class Pool extends safe_event_emitter_js_1.SafeEventEmitter {
9
12
  constructor(config) {
10
13
  super();
11
- this._notificationListeners = new SafeEventEmitter();
12
- const cfg = getConnectionConfig(config);
14
+ this._notificationListeners = new safe_event_emitter_js_1.SafeEventEmitter();
15
+ const cfg = (0, connection_config_js_1.getConnectionConfig)(config);
13
16
  this.config = Object.freeze(cfg);
14
17
  const poolOptions = {};
15
- poolOptions.acquireMaxRetries = coerceToInt(cfg.acquireMaxRetries, 0);
16
- poolOptions.acquireRetryWait = coerceToInt(cfg.acquireRetryWait, 2000);
17
- poolOptions.acquireTimeoutMillis = coerceToInt(cfg.acquireTimeoutMillis, 0);
18
- poolOptions.idleTimeoutMillis = coerceToInt(cfg.idleTimeoutMillis, 30000);
19
- poolOptions.max = coerceToInt(cfg.max, 10);
20
- poolOptions.maxQueue = coerceToInt(cfg.maxQueue, 1000);
21
- poolOptions.max = coerceToInt(cfg.max, 10);
22
- poolOptions.min = coerceToInt(cfg.min, 0);
23
- poolOptions.minIdle = coerceToInt(cfg.minIdle, 0);
24
- poolOptions.validation = coerceToBoolean(cfg.validation, false);
18
+ poolOptions.acquireMaxRetries = (0, putil_varhelpers_1.coerceToInt)(cfg.acquireMaxRetries, 0);
19
+ poolOptions.acquireRetryWait = (0, putil_varhelpers_1.coerceToInt)(cfg.acquireRetryWait, 2000);
20
+ poolOptions.acquireTimeoutMillis = (0, putil_varhelpers_1.coerceToInt)(cfg.acquireTimeoutMillis, 0);
21
+ poolOptions.idleTimeoutMillis = (0, putil_varhelpers_1.coerceToInt)(cfg.idleTimeoutMillis, 30000);
22
+ poolOptions.max = (0, putil_varhelpers_1.coerceToInt)(cfg.max, 10);
23
+ poolOptions.maxQueue = (0, putil_varhelpers_1.coerceToInt)(cfg.maxQueue, 1000);
24
+ poolOptions.max = (0, putil_varhelpers_1.coerceToInt)(cfg.max, 10);
25
+ poolOptions.min = (0, putil_varhelpers_1.coerceToInt)(cfg.min, 0);
26
+ poolOptions.minIdle = (0, putil_varhelpers_1.coerceToInt)(cfg.minIdle, 0);
27
+ poolOptions.validation = (0, putil_varhelpers_1.coerceToBoolean)(cfg.validation, false);
25
28
  const poolFactory = {
26
29
  create: async () => {
27
30
  /* istanbul ignore next */
@@ -32,7 +35,7 @@ export class Pool extends SafeEventEmitter {
32
35
  message: `new connection creating`,
33
36
  });
34
37
  }
35
- const intlCon = new IntlConnection(cfg);
38
+ const intlCon = new intl_connection_js_1.IntlConnection(cfg);
36
39
  await intlCon.connect();
37
40
  intlCon.on('close', () => this._pool.destroy(intlCon));
38
41
  /* istanbul ignore next */
@@ -66,7 +69,7 @@ export class Pool extends SafeEventEmitter {
66
69
  });
67
70
  }
68
71
  try {
69
- if (intlCon.state === ConnectionState.READY) {
72
+ if (intlCon.state === constants_js_1.ConnectionState.READY) {
70
73
  await intlCon.execute('ROLLBACK;UNLISTEN *');
71
74
  }
72
75
  }
@@ -85,12 +88,12 @@ export class Pool extends SafeEventEmitter {
85
88
  message: `[${intlCon.processID}] connection validate`,
86
89
  });
87
90
  }
88
- if (intlCon.state !== ConnectionState.READY)
91
+ if (intlCon.state !== constants_js_1.ConnectionState.READY)
89
92
  throw new Error('Connection is not active');
90
93
  await intlCon.execute('select 1;');
91
94
  },
92
95
  };
93
- this._pool = new LightningPool(poolFactory, poolOptions);
96
+ this._pool = new lightning_pool_1.Pool(poolFactory, poolOptions);
94
97
  this._pool.on('return', (...args) => this.emit('release', ...args));
95
98
  this._pool.on('error', (...args) => this.emit('error', ...args));
96
99
  this._pool.on('acquire', (...args) => this.emit('acquire', ...args));
@@ -128,7 +131,7 @@ export class Pool extends SafeEventEmitter {
128
131
  message: `[${intlCon.processID}] acquired`,
129
132
  });
130
133
  }
131
- const connection = new Connection(this, intlCon);
134
+ const connection = new connection_js_1.Connection(this, intlCon);
132
135
  /* istanbul ignore next */
133
136
  if (this.listenerCount('debug'))
134
137
  connection.on('debug', (...args) => this.emit('debug', ...args));
@@ -170,11 +173,11 @@ export class Pool extends SafeEventEmitter {
170
173
  async prepare(sql, options) {
171
174
  const connection = await this.acquire();
172
175
  const statement = await connection.prepare(sql, options);
173
- statement.once('close', () => this._pool.release(getIntlConnection(connection)));
176
+ statement.once('close', () => this._pool.release((0, intl_connection_js_1.getIntlConnection)(connection)));
174
177
  return statement;
175
178
  }
176
179
  release(connection) {
177
- return this._pool.releaseAsync(getIntlConnection(connection));
180
+ return this._pool.releaseAsync((0, intl_connection_js_1.getIntlConnection)(connection));
178
181
  }
179
182
  async listen(channel, callback) {
180
183
  if (!/^[A-Z]\w+$/i.test(channel))
@@ -203,7 +206,7 @@ export class Pool extends SafeEventEmitter {
203
206
  async _initNotificationConnection() {
204
207
  if (this._notificationConnection)
205
208
  return;
206
- const conn = (this._notificationConnection = new Connection(this.config));
209
+ const conn = (this._notificationConnection = new connection_js_1.Connection(this.config));
207
210
  // Reconnect on connection lost
208
211
  conn.on('close', () => reConnect());
209
212
  const registerEvents = async () => {
@@ -226,3 +229,4 @@ export class Pool extends SafeEventEmitter {
226
229
  await registerEvents();
227
230
  }
228
231
  }
232
+ exports.Pool = Pool;
@@ -1,10 +1,13 @@
1
- import { DEFAULT_COLUMN_FORMAT } from '../constants.js';
2
- import { GlobalTypeMap } from '../data-type-map.js';
3
- import { Protocol } from '../protocol/protocol.js';
4
- import { getIntlConnection } from './intl-connection.js';
5
- export class Portal {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Portal = void 0;
4
+ const constants_js_1 = require("../constants.js");
5
+ const data_type_map_js_1 = require("../data-type-map.js");
6
+ const protocol_js_1 = require("../protocol/protocol.js");
7
+ const intl_connection_js_1 = require("./intl-connection.js");
8
+ class Portal {
6
9
  constructor(statement, name) {
7
- this._columnFormat = DEFAULT_COLUMN_FORMAT;
10
+ this._columnFormat = constants_js_1.DEFAULT_COLUMN_FORMAT;
8
11
  this._statement = statement;
9
12
  this._name = name;
10
13
  }
@@ -15,13 +18,13 @@ export class Portal {
15
18
  return this._name;
16
19
  }
17
20
  async bind(params, queryOptions) {
18
- const intoCon = getIntlConnection(this.connection);
21
+ const intoCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
19
22
  intoCon.ref();
20
23
  try {
21
24
  const socket = intoCon.socket;
22
- this._columnFormat = queryOptions.columnFormat != null ? queryOptions.columnFormat : Protocol.DataFormat.binary;
25
+ this._columnFormat = queryOptions.columnFormat != null ? queryOptions.columnFormat : protocol_js_1.Protocol.DataFormat.binary;
23
26
  socket.sendBindMessage({
24
- typeMap: queryOptions.typeMap || GlobalTypeMap,
27
+ typeMap: queryOptions.typeMap || data_type_map_js_1.GlobalTypeMap,
25
28
  statement: this._statement.name,
26
29
  portal: this.name,
27
30
  paramTypes: this._statement.paramTypes,
@@ -31,10 +34,10 @@ export class Portal {
31
34
  socket.sendFlushMessage();
32
35
  return await socket.capture(async (code, msg, done) => {
33
36
  switch (code) {
34
- case Protocol.BackendMessageCode.BindComplete:
37
+ case protocol_js_1.Protocol.BackendMessageCode.BindComplete:
35
38
  done();
36
39
  break;
37
- case Protocol.BackendMessageCode.NoticeResponse:
40
+ case protocol_js_1.Protocol.BackendMessageCode.NoticeResponse:
38
41
  break;
39
42
  default:
40
43
  done(new Error(`Server returned unexpected response message (${String.fromCharCode(code)})`));
@@ -46,7 +49,7 @@ export class Portal {
46
49
  }
47
50
  }
48
51
  async retrieveFields() {
49
- const intoCon = getIntlConnection(this.connection);
52
+ const intoCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
50
53
  intoCon.ref();
51
54
  try {
52
55
  const socket = intoCon.socket;
@@ -54,12 +57,12 @@ export class Portal {
54
57
  socket.sendFlushMessage();
55
58
  return await socket.capture(async (code, msg, done) => {
56
59
  switch (code) {
57
- case Protocol.BackendMessageCode.NoticeResponse:
60
+ case protocol_js_1.Protocol.BackendMessageCode.NoticeResponse:
58
61
  break;
59
- case Protocol.BackendMessageCode.NoData:
62
+ case protocol_js_1.Protocol.BackendMessageCode.NoData:
60
63
  done();
61
64
  break;
62
- case Protocol.BackendMessageCode.RowDescription:
65
+ case protocol_js_1.Protocol.BackendMessageCode.RowDescription:
63
66
  done(undefined, msg.fields);
64
67
  break;
65
68
  default:
@@ -72,7 +75,7 @@ export class Portal {
72
75
  }
73
76
  }
74
77
  async execute(fetchCount) {
75
- const intoCon = getIntlConnection(this.connection);
78
+ const intoCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
76
79
  intoCon.ref();
77
80
  try {
78
81
  const socket = intoCon.socket;
@@ -81,24 +84,24 @@ export class Portal {
81
84
  const rows = [];
82
85
  return await socket.capture(async (code, msg, done) => {
83
86
  switch (code) {
84
- case Protocol.BackendMessageCode.NoticeResponse:
87
+ case protocol_js_1.Protocol.BackendMessageCode.NoticeResponse:
85
88
  break;
86
- case Protocol.BackendMessageCode.NoData:
89
+ case protocol_js_1.Protocol.BackendMessageCode.NoData:
87
90
  done(undefined, { code });
88
91
  break;
89
- case Protocol.BackendMessageCode.DataRow:
92
+ case protocol_js_1.Protocol.BackendMessageCode.DataRow:
90
93
  if (Array.isArray(this._columnFormat)) {
91
- rows.push(msg.columns.map((buf, i) => this._columnFormat[i] === Protocol.DataFormat.text ? buf.toString('utf8') : buf));
94
+ rows.push(msg.columns.map((buf, i) => this._columnFormat[i] === protocol_js_1.Protocol.DataFormat.text ? buf.toString('utf8') : buf));
92
95
  }
93
- else if (this._columnFormat === Protocol.DataFormat.binary)
96
+ else if (this._columnFormat === protocol_js_1.Protocol.DataFormat.binary)
94
97
  rows.push(msg.columns);
95
98
  else
96
99
  rows.push(msg.columns.map((buf) => buf.toString('utf8')));
97
100
  break;
98
- case Protocol.BackendMessageCode.PortalSuspended:
101
+ case protocol_js_1.Protocol.BackendMessageCode.PortalSuspended:
99
102
  done(undefined, { code, rows });
100
103
  break;
101
- case Protocol.BackendMessageCode.CommandComplete:
104
+ case protocol_js_1.Protocol.BackendMessageCode.CommandComplete:
102
105
  done(undefined, {
103
106
  code,
104
107
  rows,
@@ -116,7 +119,7 @@ export class Portal {
116
119
  }
117
120
  }
118
121
  async close() {
119
- const intoCon = getIntlConnection(this.connection);
122
+ const intoCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
120
123
  intoCon.ref();
121
124
  try {
122
125
  const socket = intoCon.socket;
@@ -124,11 +127,11 @@ export class Portal {
124
127
  socket.sendSyncMessage();
125
128
  return await socket.capture(async (code, msg, done) => {
126
129
  switch (code) {
127
- case Protocol.BackendMessageCode.NoticeResponse:
130
+ case protocol_js_1.Protocol.BackendMessageCode.NoticeResponse:
128
131
  break;
129
- case Protocol.BackendMessageCode.CloseComplete:
132
+ case protocol_js_1.Protocol.BackendMessageCode.CloseComplete:
130
133
  break;
131
- case Protocol.BackendMessageCode.ReadyForQuery:
134
+ case protocol_js_1.Protocol.BackendMessageCode.ReadyForQuery:
132
135
  intoCon.transactionStatus = msg.status;
133
136
  done();
134
137
  break;
@@ -142,3 +145,4 @@ export class Portal {
142
145
  }
143
146
  }
144
147
  }
148
+ exports.Portal = Portal;