postgrejs 2.22.7 → 2.23.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 (216) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/{esm/connection → connection}/bind-param.js +2 -0
  3. package/{esm/connection → connection}/connection.js +4 -2
  4. package/{esm/connection → connection}/cursor.js +8 -3
  5. package/{esm/connection → connection}/intl-connection.js +6 -3
  6. package/{esm/connection → connection}/pool.js +4 -1
  7. package/{esm/connection → connection}/portal.js +3 -1
  8. package/{esm/connection → connection}/prepared-statement.js +6 -3
  9. package/{esm/constants.js → constants.js} +1 -1
  10. package/{esm/data-type-map.js → data-type-map.js} +2 -2
  11. package/package.json +13 -32
  12. package/{esm/protocol → protocol}/backend.js +1 -0
  13. package/{esm/protocol → protocol}/buffer-reader.js +2 -1
  14. package/{esm/protocol → protocol}/database-error.js +16 -0
  15. package/{esm/protocol → protocol}/frontend.js +1 -0
  16. package/{esm/protocol → protocol}/pg-socket.js +9 -3
  17. package/{types/protocol → protocol}/smart-buffer.d.ts +1 -0
  18. package/{esm/protocol → protocol}/smart-buffer.js +29 -19
  19. package/{esm/util → util}/bigint-methods.js +1 -0
  20. package/cjs/connection/bind-param.js +0 -10
  21. package/cjs/connection/connection.js +0 -295
  22. package/cjs/connection/cursor.js +0 -91
  23. package/cjs/connection/intl-connection.js +0 -258
  24. package/cjs/connection/pool.js +0 -236
  25. package/cjs/connection/portal.js +0 -157
  26. package/cjs/connection/prepared-statement.js +0 -226
  27. package/cjs/constants.js +0 -249
  28. package/cjs/data-type-map.js +0 -131
  29. package/cjs/data-types/bool-type.js +0 -33
  30. package/cjs/data-types/box-type.js +0 -52
  31. package/cjs/data-types/bytea-type.js +0 -28
  32. package/cjs/data-types/char-type.js +0 -27
  33. package/cjs/data-types/circle-type.js +0 -51
  34. package/cjs/data-types/date-type.js +0 -75
  35. package/cjs/data-types/float4-type.js +0 -25
  36. package/cjs/data-types/float8-type.js +0 -25
  37. package/cjs/data-types/int2-type.js +0 -26
  38. package/cjs/data-types/int2-vector-type.js +0 -42
  39. package/cjs/data-types/int4-type.js +0 -28
  40. package/cjs/data-types/int8-type.js +0 -36
  41. package/cjs/data-types/json-type.js +0 -40
  42. package/cjs/data-types/jsonb-type.js +0 -44
  43. package/cjs/data-types/lseg-type.js +0 -55
  44. package/cjs/data-types/numeric-type.js +0 -125
  45. package/cjs/data-types/oid-type.js +0 -32
  46. package/cjs/data-types/point-type.js +0 -42
  47. package/cjs/data-types/time-type.js +0 -66
  48. package/cjs/data-types/timestamp-type.js +0 -89
  49. package/cjs/data-types/timestamptz-type.js +0 -76
  50. package/cjs/data-types/uuid-type.js +0 -39
  51. package/cjs/data-types/varchar-type.js +0 -27
  52. package/cjs/index.js +0 -28
  53. package/cjs/interfaces/command-result.js +0 -2
  54. package/cjs/interfaces/data-mapping-options.js +0 -2
  55. package/cjs/interfaces/data-type.js +0 -2
  56. package/cjs/interfaces/database-connection-params.js +0 -2
  57. package/cjs/interfaces/field-info.js +0 -2
  58. package/cjs/interfaces/query-options.js +0 -2
  59. package/cjs/interfaces/query-result.js +0 -2
  60. package/cjs/interfaces/script-execute-options.js +0 -2
  61. package/cjs/interfaces/script-result.js +0 -2
  62. package/cjs/interfaces/statement-prepare-options.js +0 -2
  63. package/cjs/package.json +0 -3
  64. package/cjs/protocol/backend.js +0 -262
  65. package/cjs/protocol/buffer-reader.js +0 -78
  66. package/cjs/protocol/database-error.js +0 -17
  67. package/cjs/protocol/frontend.js +0 -255
  68. package/cjs/protocol/pg-socket.js +0 -367
  69. package/cjs/protocol/protocol.js +0 -71
  70. package/cjs/protocol/sasl.js +0 -108
  71. package/cjs/protocol/smart-buffer.js +0 -172
  72. package/cjs/safe-event-emitter.js +0 -17
  73. package/cjs/tsconfig-build-cjs.tsbuildinfo +0 -1
  74. package/cjs/types.js +0 -2
  75. package/cjs/util/array-calculatedim.js +0 -18
  76. package/cjs/util/bigint-methods.js +0 -44
  77. package/cjs/util/config-from-env.js +0 -29
  78. package/cjs/util/connection-config.js +0 -61
  79. package/cjs/util/convert-row-to-object.js +0 -12
  80. package/cjs/util/decode-binaryarray.js +0 -38
  81. package/cjs/util/encode-binaryarray.js +0 -44
  82. package/cjs/util/escape-literal.js +0 -26
  83. package/cjs/util/fast-parseint.js +0 -31
  84. package/cjs/util/get-parsers.js +0 -41
  85. package/cjs/util/parse-array.js +0 -60
  86. package/cjs/util/parse-datetime.js +0 -37
  87. package/cjs/util/parse-row.js +0 -11
  88. package/cjs/util/parse-time.js +0 -30
  89. package/cjs/util/stringify-arrayliteral.js +0 -37
  90. package/cjs/util/stringify-for-sql.js +0 -29
  91. package/cjs/util/wrap-row-description.js +0 -34
  92. package/esm/package.json +0 -3
  93. package/types/index.d.cts +0 -25
  94. /package/{types/connection → connection}/bind-param.d.ts +0 -0
  95. /package/{types/connection → connection}/connection.d.ts +0 -0
  96. /package/{types/connection → connection}/cursor.d.ts +0 -0
  97. /package/{types/connection → connection}/intl-connection.d.ts +0 -0
  98. /package/{types/connection → connection}/pool.d.ts +0 -0
  99. /package/{types/connection → connection}/portal.d.ts +0 -0
  100. /package/{types/connection → connection}/prepared-statement.d.ts +0 -0
  101. /package/{types/constants.d.ts → constants.d.ts} +0 -0
  102. /package/{types/data-type-map.d.ts → data-type-map.d.ts} +0 -0
  103. /package/{types/data-types → data-types}/bool-type.d.ts +0 -0
  104. /package/{esm/data-types → data-types}/bool-type.js +0 -0
  105. /package/{types/data-types → data-types}/box-type.d.ts +0 -0
  106. /package/{esm/data-types → data-types}/box-type.js +0 -0
  107. /package/{types/data-types → data-types}/bytea-type.d.ts +0 -0
  108. /package/{esm/data-types → data-types}/bytea-type.js +0 -0
  109. /package/{types/data-types → data-types}/char-type.d.ts +0 -0
  110. /package/{esm/data-types → data-types}/char-type.js +0 -0
  111. /package/{types/data-types → data-types}/circle-type.d.ts +0 -0
  112. /package/{esm/data-types → data-types}/circle-type.js +0 -0
  113. /package/{types/data-types → data-types}/date-type.d.ts +0 -0
  114. /package/{esm/data-types → data-types}/date-type.js +0 -0
  115. /package/{types/data-types → data-types}/float4-type.d.ts +0 -0
  116. /package/{esm/data-types → data-types}/float4-type.js +0 -0
  117. /package/{types/data-types → data-types}/float8-type.d.ts +0 -0
  118. /package/{esm/data-types → data-types}/float8-type.js +0 -0
  119. /package/{types/data-types → data-types}/int2-type.d.ts +0 -0
  120. /package/{esm/data-types → data-types}/int2-type.js +0 -0
  121. /package/{types/data-types → data-types}/int2-vector-type.d.ts +0 -0
  122. /package/{esm/data-types → data-types}/int2-vector-type.js +0 -0
  123. /package/{types/data-types → data-types}/int4-type.d.ts +0 -0
  124. /package/{esm/data-types → data-types}/int4-type.js +0 -0
  125. /package/{types/data-types → data-types}/int8-type.d.ts +0 -0
  126. /package/{esm/data-types → data-types}/int8-type.js +0 -0
  127. /package/{types/data-types → data-types}/json-type.d.ts +0 -0
  128. /package/{esm/data-types → data-types}/json-type.js +0 -0
  129. /package/{types/data-types → data-types}/jsonb-type.d.ts +0 -0
  130. /package/{esm/data-types → data-types}/jsonb-type.js +0 -0
  131. /package/{types/data-types → data-types}/lseg-type.d.ts +0 -0
  132. /package/{esm/data-types → data-types}/lseg-type.js +0 -0
  133. /package/{types/data-types → data-types}/numeric-type.d.ts +0 -0
  134. /package/{esm/data-types → data-types}/numeric-type.js +0 -0
  135. /package/{types/data-types → data-types}/oid-type.d.ts +0 -0
  136. /package/{esm/data-types → data-types}/oid-type.js +0 -0
  137. /package/{types/data-types → data-types}/point-type.d.ts +0 -0
  138. /package/{esm/data-types → data-types}/point-type.js +0 -0
  139. /package/{types/data-types → data-types}/time-type.d.ts +0 -0
  140. /package/{esm/data-types → data-types}/time-type.js +0 -0
  141. /package/{types/data-types → data-types}/timestamp-type.d.ts +0 -0
  142. /package/{esm/data-types → data-types}/timestamp-type.js +0 -0
  143. /package/{types/data-types → data-types}/timestamptz-type.d.ts +0 -0
  144. /package/{esm/data-types → data-types}/timestamptz-type.js +0 -0
  145. /package/{types/data-types → data-types}/uuid-type.d.ts +0 -0
  146. /package/{esm/data-types → data-types}/uuid-type.js +0 -0
  147. /package/{types/data-types → data-types}/varchar-type.d.ts +0 -0
  148. /package/{esm/data-types → data-types}/varchar-type.js +0 -0
  149. /package/{types/index.d.ts → index.d.ts} +0 -0
  150. /package/{esm/index.js → index.js} +0 -0
  151. /package/{types/interfaces → interfaces}/command-result.d.ts +0 -0
  152. /package/{esm/interfaces → interfaces}/command-result.js +0 -0
  153. /package/{types/interfaces → interfaces}/data-mapping-options.d.ts +0 -0
  154. /package/{esm/interfaces → interfaces}/data-mapping-options.js +0 -0
  155. /package/{types/interfaces → interfaces}/data-type.d.ts +0 -0
  156. /package/{esm/interfaces → interfaces}/data-type.js +0 -0
  157. /package/{types/interfaces → interfaces}/database-connection-params.d.ts +0 -0
  158. /package/{esm/interfaces → interfaces}/database-connection-params.js +0 -0
  159. /package/{types/interfaces → interfaces}/field-info.d.ts +0 -0
  160. /package/{esm/interfaces → interfaces}/field-info.js +0 -0
  161. /package/{types/interfaces → interfaces}/query-options.d.ts +0 -0
  162. /package/{esm/interfaces → interfaces}/query-options.js +0 -0
  163. /package/{types/interfaces → interfaces}/query-result.d.ts +0 -0
  164. /package/{esm/interfaces → interfaces}/query-result.js +0 -0
  165. /package/{types/interfaces → interfaces}/script-execute-options.d.ts +0 -0
  166. /package/{esm/interfaces → interfaces}/script-execute-options.js +0 -0
  167. /package/{types/interfaces → interfaces}/script-result.d.ts +0 -0
  168. /package/{esm/interfaces → interfaces}/script-result.js +0 -0
  169. /package/{types/interfaces → interfaces}/statement-prepare-options.d.ts +0 -0
  170. /package/{esm/interfaces → interfaces}/statement-prepare-options.js +0 -0
  171. /package/{types/protocol → protocol}/backend.d.ts +0 -0
  172. /package/{types/protocol → protocol}/buffer-reader.d.ts +0 -0
  173. /package/{types/protocol → protocol}/database-error.d.ts +0 -0
  174. /package/{types/protocol → protocol}/frontend.d.ts +0 -0
  175. /package/{types/protocol → protocol}/pg-socket.d.ts +0 -0
  176. /package/{types/protocol → protocol}/protocol.d.ts +0 -0
  177. /package/{esm/protocol → protocol}/protocol.js +0 -0
  178. /package/{types/protocol → protocol}/sasl.d.ts +0 -0
  179. /package/{esm/protocol → protocol}/sasl.js +0 -0
  180. /package/{types/safe-event-emitter.d.ts → safe-event-emitter.d.ts} +0 -0
  181. /package/{esm/safe-event-emitter.js → safe-event-emitter.js} +0 -0
  182. /package/{types/types.d.ts → types.d.ts} +0 -0
  183. /package/{esm/types.js → types.js} +0 -0
  184. /package/{types/util → util}/array-calculatedim.d.ts +0 -0
  185. /package/{esm/util → util}/array-calculatedim.js +0 -0
  186. /package/{types/util → util}/bigint-methods.d.ts +0 -0
  187. /package/{types/util → util}/config-from-env.d.ts +0 -0
  188. /package/{esm/util → util}/config-from-env.js +0 -0
  189. /package/{types/util → util}/connection-config.d.ts +0 -0
  190. /package/{esm/util → util}/connection-config.js +0 -0
  191. /package/{types/util → util}/convert-row-to-object.d.ts +0 -0
  192. /package/{esm/util → util}/convert-row-to-object.js +0 -0
  193. /package/{types/util → util}/decode-binaryarray.d.ts +0 -0
  194. /package/{esm/util → util}/decode-binaryarray.js +0 -0
  195. /package/{types/util → util}/encode-binaryarray.d.ts +0 -0
  196. /package/{esm/util → util}/encode-binaryarray.js +0 -0
  197. /package/{types/util → util}/escape-literal.d.ts +0 -0
  198. /package/{esm/util → util}/escape-literal.js +0 -0
  199. /package/{types/util → util}/fast-parseint.d.ts +0 -0
  200. /package/{esm/util → util}/fast-parseint.js +0 -0
  201. /package/{types/util → util}/get-parsers.d.ts +0 -0
  202. /package/{esm/util → util}/get-parsers.js +0 -0
  203. /package/{types/util → util}/parse-array.d.ts +0 -0
  204. /package/{esm/util → util}/parse-array.js +0 -0
  205. /package/{types/util → util}/parse-datetime.d.ts +0 -0
  206. /package/{esm/util → util}/parse-datetime.js +0 -0
  207. /package/{types/util → util}/parse-row.d.ts +0 -0
  208. /package/{esm/util → util}/parse-row.js +0 -0
  209. /package/{types/util → util}/parse-time.d.ts +0 -0
  210. /package/{esm/util → util}/parse-time.js +0 -0
  211. /package/{types/util → util}/stringify-arrayliteral.d.ts +0 -0
  212. /package/{esm/util → util}/stringify-arrayliteral.js +0 -0
  213. /package/{types/util → util}/stringify-for-sql.d.ts +0 -0
  214. /package/{esm/util → util}/stringify-for-sql.js +0 -0
  215. /package/{types/util → util}/wrap-row-description.d.ts +0 -0
  216. /package/{esm/util → util}/wrap-row-description.js +0 -0
package/CHANGELOG.md CHANGED
@@ -1,6 +1,25 @@
1
1
  ## Changelog
2
2
 
3
- ### [v2.22.7](https://github.com/panates/postgrejs/compare/v2.22.6...v2.22.7) -
3
+ ### [v2.23.0](https://github.com/panates/postgrejs/compare/v2.22.9...v2.23.0) -
4
+
5
+ #### 🛠 Refactoring and Updates
6
+
7
+ - dev: Updated deps to support latest TypeScript and NodeJS. @Eray Hanoğlu
8
+ - dev: Updated deps to support latest TypeScript and NodeJS. @Eray Hanoğlu
9
+
10
+ ### [v2.22.9](https://github.com/panates/postgrejs/compare/v2.22.8...v2.22.9) - 4 December 2025
11
+
12
+ ### [v2.22.8](https://github.com/panates/postgrejs/compare/v2.22.7...v2.22.8) - 27 October 2025
13
+
14
+ #### 🪲 Fixes
15
+
16
+ - fix: SmartBuffer grows when offset isn't at last @Eray Hanoğlu
17
+
18
+ #### 💬 General Changes
19
+
20
+ - dev: npm Trusted publishing update @Eray Hanoğlu
21
+
22
+ ### [v2.22.7](https://github.com/panates/postgrejs/compare/v2.22.6...v2.22.7) - 21 October 2025
4
23
 
5
24
  #### 💬 General Changes
6
25
 
@@ -1,4 +1,6 @@
1
1
  export class BindParam {
2
+ oid;
3
+ value;
2
4
  constructor(oid, value) {
3
5
  this.oid = oid;
4
6
  this.value = value;
@@ -5,10 +5,12 @@ import { BindParam } from './bind-param.js';
5
5
  import { IntlConnection } from './intl-connection.js';
6
6
  import { PreparedStatement } from './prepared-statement.js';
7
7
  export class Connection extends SafeEventEmitter {
8
+ _pool;
9
+ _intlCon;
10
+ _notificationListeners = new SafeEventEmitter();
11
+ _closing = false;
8
12
  constructor(arg0, arg1) {
9
13
  super();
10
- this._notificationListeners = new SafeEventEmitter();
11
- this._closing = false;
12
14
  if (arg0 &&
13
15
  typeof arg0 === 'object' &&
14
16
  typeof arg0.acquire === 'function') {
@@ -4,11 +4,16 @@ import { SafeEventEmitter } from '../safe-event-emitter.js';
4
4
  import { convertRowToObject } from '../util/convert-row-to-object.js';
5
5
  import { parseRow } from '../util/parse-row.js';
6
6
  export class Cursor extends SafeEventEmitter {
7
+ _statement;
8
+ _portal;
9
+ _parsers;
10
+ _queryOptions;
11
+ _taskQueue = new TaskQueue({ concurrency: 1 });
12
+ _rows = new DoublyLinked();
13
+ _closed = false;
14
+ fields;
7
15
  constructor(statement, portal, fields, parsers, queryOptions) {
8
16
  super();
9
- this._taskQueue = new TaskQueue({ concurrency: 1 });
10
- this._rows = new DoublyLinked();
11
- this._closed = false;
12
17
  this._statement = statement;
13
18
  this._portal = portal;
14
19
  this._parsers = parsers;
@@ -13,11 +13,14 @@ import { parseRow } from '../util/parse-row.js';
13
13
  import { wrapRowDescription } from '../util/wrap-row-description.js';
14
14
  const DataFormat = Protocol.DataFormat;
15
15
  export class IntlConnection extends SafeEventEmitter {
16
+ _refCount = 0;
17
+ _config;
18
+ _onErrorSavePoint;
19
+ transactionStatus = 'I';
20
+ socket;
21
+ statementQueue = new TaskQueue({ concurrency: 1 });
16
22
  constructor(config) {
17
23
  super();
18
- this._refCount = 0;
19
- this.transactionStatus = 'I';
20
- this.statementQueue = new TaskQueue({ concurrency: 1 });
21
24
  this._config = Object.freeze(getConnectionConfig(config));
22
25
  this.socket = new PgSocket(this._config);
23
26
  this.socket.on('error', err => this._onError(err));
@@ -6,9 +6,12 @@ import { getConnectionConfig } from '../util/connection-config.js';
6
6
  import { Connection } from './connection.js';
7
7
  import { getIntlConnection, IntlConnection } from './intl-connection.js';
8
8
  export class Pool extends SafeEventEmitter {
9
+ _pool;
10
+ _notificationListeners = new SafeEventEmitter();
11
+ _notificationConnection;
12
+ config;
9
13
  constructor(config) {
10
14
  super();
11
- this._notificationListeners = new SafeEventEmitter();
12
15
  const cfg = getConnectionConfig(config);
13
16
  this.config = Object.freeze(cfg);
14
17
  const poolOptions = {};
@@ -3,8 +3,10 @@ import { GlobalTypeMap } from '../data-type-map.js';
3
3
  import { Protocol } from '../protocol/protocol.js';
4
4
  import { getIntlConnection } from './intl-connection.js';
5
5
  export class Portal {
6
+ _statement;
7
+ _name;
8
+ _columnFormat = DEFAULT_COLUMN_FORMAT;
6
9
  constructor(statement, name) {
7
- this._columnFormat = DEFAULT_COLUMN_FORMAT;
8
10
  this._statement = statement;
9
11
  this._name = name;
10
12
  }
@@ -13,11 +13,14 @@ import { Portal } from './portal.js';
13
13
  let statementCounter = 0;
14
14
  let portalCounter = 0;
15
15
  export class PreparedStatement extends SafeEventEmitter {
16
+ _connection;
17
+ _sql = '';
18
+ _name = '';
19
+ _paramTypes;
20
+ _onErrorSavePoint;
21
+ _refCount = 0;
16
22
  constructor(connection, sql, paramTypes) {
17
23
  super();
18
- this._sql = '';
19
- this._name = '';
20
- this._refCount = 0;
21
24
  this._connection = connection;
22
25
  this._name = 'S_' + ++statementCounter;
23
26
  this._sql = sql;
@@ -1,7 +1,7 @@
1
1
  import { Protocol } from './protocol/protocol.js';
2
2
  var DataFormat = Protocol.DataFormat;
3
3
  // @ts-ignore
4
- Symbol.asyncDispose ?? (Symbol.asyncDispose = Symbol('Symbol.asyncDispose'));
4
+ Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose');
5
5
  export { DataFormat };
6
6
  export const DEFAULT_COLUMN_FORMAT = DataFormat.binary;
7
7
  export var ConnectionState;
@@ -23,9 +23,9 @@ import { ArrayTimestamptzType, TimestamptzType, } from './data-types/timestamptz
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 {
26
+ _itemsByOID = {};
27
+ _items = [];
26
28
  constructor(other) {
27
- this._itemsByOID = {};
28
- this._items = [];
29
29
  if (other instanceof DataTypeMap)
30
30
  Object.assign(this._items, other._items);
31
31
  }
package/package.json CHANGED
@@ -1,37 +1,32 @@
1
1
  {
2
2
  "name": "postgrejs",
3
3
  "description": "Professional PostgreSQL client NodeJS",
4
- "version": "2.22.7",
4
+ "version": "2.23.0",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "@jsopen/objects": "^2.0.2",
8
+ "@jsopen/objects": "^2.2.0",
9
9
  "doublylinked": "^2.5.6",
10
- "lightning-pool": "^4.11.1",
10
+ "lightning-pool": "^4.12.0",
11
11
  "postgres-bytea": "^3.0.0",
12
- "power-tasks": "^1.11.1",
12
+ "power-tasks": "^1.14.2",
13
13
  "putil-promisify": "^1.10.1",
14
- "putil-varhelpers": "^1.6.5",
14
+ "putil-varhelpers": "^1.7.0",
15
15
  "tslib": "^2.8.1"
16
16
  },
17
17
  "type": "module",
18
+ "module": "./index.js",
19
+ "types": "./index.d.ts",
18
20
  "exports": {
19
21
  ".": {
20
- "import": {
21
- "types": "./types/index.d.ts",
22
- "default": "./esm/index.js"
23
- },
24
- "require": {
25
- "types": "./types/index.d.cts",
26
- "default": "./cjs/index.js"
27
- },
28
- "default": "./esm/index.js"
22
+ "types": "./index.d.ts",
23
+ "default": "./index.js"
29
24
  },
30
25
  "./package.json": "./package.json"
31
26
  },
32
- "main": "./cjs/index.js",
33
- "module": "./esm/index.js",
34
- "types": "./types/index.d.ts",
27
+ "engines": {
28
+ "node": ">=20.0"
29
+ },
35
30
  "homepage": "https://postgrejs.panates.com/",
36
31
  "contributors": [
37
32
  "Eray Hanoglu <e.hanoglu@panates.com>"
@@ -40,17 +35,6 @@
40
35
  "type": "git",
41
36
  "url": "https://github.com/panates/postgrejs.git"
42
37
  },
43
- "engines": {
44
- "node": ">=16.0"
45
- },
46
- "files": [
47
- "cjs/",
48
- "esm/",
49
- "types/",
50
- "LICENSE",
51
- "README.md",
52
- "CHANGELOG.md"
53
- ],
54
38
  "keywords": [
55
39
  "postgresql",
56
40
  "postgres",
@@ -62,10 +46,7 @@
62
46
  "client",
63
47
  "backend",
64
48
  "rdbms",
65
- "sql",
66
- "typescript",
67
- "ts",
68
- "esm"
49
+ "sql"
69
50
  ],
70
51
  "publishConfig": {
71
52
  "access": "public"
@@ -23,6 +23,7 @@ const ErrorFieldTypes = {
23
23
  R: 'routine',
24
24
  };
25
25
  export class Backend {
26
+ _buf;
26
27
  reset() {
27
28
  this._buf = undefined;
28
29
  }
@@ -1,6 +1,7 @@
1
1
  export class BufferReader {
2
+ buffer;
3
+ offset = 0;
2
4
  constructor(buffer) {
3
- this.offset = 0;
4
5
  this.buffer = buffer;
5
6
  }
6
7
  get length() {
@@ -1,4 +1,20 @@
1
1
  export class DatabaseError extends Error {
2
+ severity;
3
+ code;
4
+ detail;
5
+ hint;
6
+ position;
7
+ internalPosition;
8
+ internalQuery;
9
+ where;
10
+ schema;
11
+ table;
12
+ column;
13
+ dataType;
14
+ constraint;
15
+ lineNr;
16
+ colNr;
17
+ line;
2
18
  constructor(msg) {
3
19
  super(msg.message);
4
20
  Object.assign(this, {
@@ -26,6 +26,7 @@ const StaticSyncBuffer = Buffer.from([
26
26
  0x04,
27
27
  ]);
28
28
  export class Frontend {
29
+ _io;
29
30
  constructor(options) {
30
31
  this._io = new SmartBuffer(options?.buffer);
31
32
  }
@@ -13,12 +13,18 @@ import { SASL } from './sasl.js';
13
13
  const DEFAULT_PORT_NUMBER = 5432;
14
14
  const COMMAND_RESULT_PATTERN = /^([^\d]+)(?: (\d+)(?: (\d+))?)?$/;
15
15
  export class PgSocket extends SafeEventEmitter {
16
+ options;
17
+ _state = ConnectionState.CLOSED;
18
+ _socket;
19
+ _backend = new Backend();
20
+ _frontend;
21
+ _sessionParameters = {};
22
+ _saslSession;
23
+ _processID;
24
+ _secretKey;
16
25
  constructor(options) {
17
26
  super();
18
27
  this.options = options;
19
- this._state = ConnectionState.CLOSED;
20
- this._backend = new Backend();
21
- this._sessionParameters = {};
22
28
  this._frontend = new Frontend({ buffer: options.buffer });
23
29
  this.setMaxListeners(99);
24
30
  }
@@ -34,5 +34,6 @@ export declare class SmartBuffer extends BufferReader {
34
34
  writeFloatBE(n: number): this;
35
35
  writeDoubleBE(n: number): this;
36
36
  writeBuffer(buffer: Buffer): this;
37
+ private ensureSize;
37
38
  private _houseKeep;
38
39
  }
@@ -2,11 +2,17 @@ import * as os from 'os';
2
2
  import { writeBigUInt64BE } from '../util/bigint-methods.js';
3
3
  import { BufferReader } from './buffer-reader.js';
4
4
  export class SmartBuffer extends BufferReader {
5
+ static DEFAULT_PAGE_SIZE = 4096;
6
+ static DEFAULT_MAX_SIZE = Math.min(Math.floor(os.totalmem() / 2), 1024 * 1024 * 1024 * 2);
7
+ _houseKeepInterval;
8
+ _houseKeepTimer;
9
+ _lastHouseKeep = 0;
10
+ _stMaxPages = 1;
11
+ _length = 0;
12
+ pageSize;
13
+ maxSize;
5
14
  constructor(cfg) {
6
15
  super(Buffer.allocUnsafe(cfg?.pageSize || SmartBuffer.DEFAULT_PAGE_SIZE));
7
- this._lastHouseKeep = 0;
8
- this._stMaxPages = 1;
9
- this._length = 0;
10
16
  this._houseKeepInterval = cfg?.houseKeepInterval || 5000;
11
17
  this.pageSize = this.buffer.length;
12
18
  this.maxSize = cfg?.maxLength || SmartBuffer.DEFAULT_MAX_SIZE;
@@ -57,14 +63,14 @@ export class SmartBuffer extends BufferReader {
57
63
  return this;
58
64
  }
59
65
  fill(value = 0, len = 1) {
60
- this.growSize(len);
66
+ this.ensureSize(len);
61
67
  this.buffer.fill(value, this.offset, this.offset + len);
62
68
  this.offset += len;
63
69
  return this;
64
70
  }
65
71
  writeCString(str, encoding) {
66
72
  const len = str ? Buffer.byteLength(str, encoding) : 0;
67
- this.growSize(len + 1);
73
+ this.ensureSize(len + 1);
68
74
  if (str) {
69
75
  this.buffer.write(str, this.offset, encoding);
70
76
  this.offset += len;
@@ -74,7 +80,7 @@ export class SmartBuffer extends BufferReader {
74
80
  }
75
81
  writeLString(str, encoding) {
76
82
  const len = str ? Buffer.byteLength(str, encoding) : 0;
77
- this.growSize(len + 4);
83
+ this.ensureSize(len + 4);
78
84
  this.writeInt32BE(str == null ? -1 : len);
79
85
  if (str) {
80
86
  if (encoding)
@@ -87,50 +93,50 @@ export class SmartBuffer extends BufferReader {
87
93
  writeString(str, encoding) {
88
94
  if (str) {
89
95
  const len = Buffer.byteLength(str, encoding);
90
- this.growSize(len);
96
+ this.ensureSize(len);
91
97
  this.offset += this.buffer.write(str, this.offset, encoding);
92
98
  }
93
99
  return this;
94
100
  }
95
101
  writeInt8(n) {
96
- this.growSize(1);
102
+ this.ensureSize(1);
97
103
  this.buffer.writeInt8(n, this.offset);
98
104
  this.offset++;
99
105
  return this;
100
106
  }
101
107
  writeUInt8(n) {
102
- this.growSize(1);
108
+ this.ensureSize(1);
103
109
  this.buffer.writeUInt8(n, this.offset);
104
110
  this.offset++;
105
111
  return this;
106
112
  }
107
113
  writeUInt16BE(n) {
108
- this.growSize(2);
114
+ this.ensureSize(2);
109
115
  this.buffer.writeUInt16BE(n, this.offset);
110
116
  this.offset += 2;
111
117
  return this;
112
118
  }
113
119
  writeUInt32BE(n) {
114
- this.growSize(4);
120
+ this.ensureSize(4);
115
121
  this.buffer.writeUInt32BE(n, this.offset);
116
122
  this.offset += 4;
117
123
  return this;
118
124
  }
119
125
  writeInt16BE(n) {
120
- this.growSize(2);
126
+ this.ensureSize(2);
121
127
  this.buffer.writeInt16BE(n, this.offset);
122
128
  this.offset += 2;
123
129
  return this;
124
130
  }
125
131
  writeInt32BE(n) {
126
- this.growSize(4);
132
+ this.ensureSize(4);
127
133
  this.buffer.writeInt32BE(n, this.offset);
128
134
  this.offset += 4;
129
135
  return this;
130
136
  }
131
137
  writeBigInt64BE(n) {
132
138
  n = typeof n === 'bigint' ? n : BigInt(n);
133
- this.growSize(8);
139
+ this.ensureSize(8);
134
140
  if (typeof this.buffer.writeBigInt64BE === 'function')
135
141
  this.buffer.writeBigInt64BE(n, this.offset);
136
142
  else
@@ -139,23 +145,29 @@ export class SmartBuffer extends BufferReader {
139
145
  return this;
140
146
  }
141
147
  writeFloatBE(n) {
142
- this.growSize(4);
148
+ this.ensureSize(4);
143
149
  this.buffer.writeFloatBE(n, this.offset);
144
150
  this.offset += 4;
145
151
  return this;
146
152
  }
147
153
  writeDoubleBE(n) {
148
- this.growSize(8);
154
+ this.ensureSize(8);
149
155
  this.buffer.writeDoubleBE(n, this.offset);
150
156
  this.offset += 8;
151
157
  return this;
152
158
  }
153
159
  writeBuffer(buffer) {
154
- this.growSize(buffer.length);
160
+ this.ensureSize(buffer.length);
155
161
  buffer.copy(this.buffer, this.offset, 0, buffer.length);
156
162
  this.offset += buffer.length;
157
163
  return this;
158
164
  }
165
+ ensureSize(len) {
166
+ const n = this.offset + len - this.length;
167
+ if (n > 0)
168
+ this.growSize(n);
169
+ return this;
170
+ }
159
171
  _houseKeep() {
160
172
  const needSize = this._stMaxPages * this.pageSize;
161
173
  if (this.buffer.length > needSize)
@@ -163,5 +175,3 @@ export class SmartBuffer extends BufferReader {
163
175
  this._stMaxPages = this.length ? Math.ceil(this.length / this.pageSize) : 1;
164
176
  }
165
177
  }
166
- SmartBuffer.DEFAULT_PAGE_SIZE = 4096;
167
- SmartBuffer.DEFAULT_MAX_SIZE = Math.min(Math.floor(os.totalmem() / 2), 1024 * 1024 * 1024 * 2);
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-useless-assignment */
1
2
  const big0 = BigInt(0);
2
3
  const beAnd = BigInt('0xffffffff');
3
4
  const big32 = BigInt(32);
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BindParam = void 0;
4
- class BindParam {
5
- constructor(oid, value) {
6
- this.oid = oid;
7
- this.value = value;
8
- }
9
- }
10
- exports.BindParam = BindParam;