postgrejs 2.22.9 → 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 +8 -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 +12 -31
  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/{esm/protocol → protocol}/smart-buffer.js +9 -5
  18. package/{esm/util → util}/bigint-methods.js +1 -0
  19. package/cjs/connection/bind-param.js +0 -10
  20. package/cjs/connection/connection.js +0 -295
  21. package/cjs/connection/cursor.js +0 -91
  22. package/cjs/connection/intl-connection.js +0 -258
  23. package/cjs/connection/pool.js +0 -236
  24. package/cjs/connection/portal.js +0 -157
  25. package/cjs/connection/prepared-statement.js +0 -226
  26. package/cjs/constants.js +0 -249
  27. package/cjs/data-type-map.js +0 -131
  28. package/cjs/data-types/bool-type.js +0 -33
  29. package/cjs/data-types/box-type.js +0 -52
  30. package/cjs/data-types/bytea-type.js +0 -28
  31. package/cjs/data-types/char-type.js +0 -27
  32. package/cjs/data-types/circle-type.js +0 -51
  33. package/cjs/data-types/date-type.js +0 -75
  34. package/cjs/data-types/float4-type.js +0 -25
  35. package/cjs/data-types/float8-type.js +0 -25
  36. package/cjs/data-types/int2-type.js +0 -26
  37. package/cjs/data-types/int2-vector-type.js +0 -42
  38. package/cjs/data-types/int4-type.js +0 -28
  39. package/cjs/data-types/int8-type.js +0 -36
  40. package/cjs/data-types/json-type.js +0 -40
  41. package/cjs/data-types/jsonb-type.js +0 -44
  42. package/cjs/data-types/lseg-type.js +0 -55
  43. package/cjs/data-types/numeric-type.js +0 -125
  44. package/cjs/data-types/oid-type.js +0 -32
  45. package/cjs/data-types/point-type.js +0 -42
  46. package/cjs/data-types/time-type.js +0 -66
  47. package/cjs/data-types/timestamp-type.js +0 -89
  48. package/cjs/data-types/timestamptz-type.js +0 -76
  49. package/cjs/data-types/uuid-type.js +0 -39
  50. package/cjs/data-types/varchar-type.js +0 -27
  51. package/cjs/index.js +0 -28
  52. package/cjs/interfaces/command-result.js +0 -2
  53. package/cjs/interfaces/data-mapping-options.js +0 -2
  54. package/cjs/interfaces/data-type.js +0 -2
  55. package/cjs/interfaces/database-connection-params.js +0 -2
  56. package/cjs/interfaces/field-info.js +0 -2
  57. package/cjs/interfaces/query-options.js +0 -2
  58. package/cjs/interfaces/query-result.js +0 -2
  59. package/cjs/interfaces/script-execute-options.js +0 -2
  60. package/cjs/interfaces/script-result.js +0 -2
  61. package/cjs/interfaces/statement-prepare-options.js +0 -2
  62. package/cjs/package.json +0 -3
  63. package/cjs/protocol/backend.js +0 -262
  64. package/cjs/protocol/buffer-reader.js +0 -78
  65. package/cjs/protocol/database-error.js +0 -17
  66. package/cjs/protocol/frontend.js +0 -255
  67. package/cjs/protocol/pg-socket.js +0 -367
  68. package/cjs/protocol/protocol.js +0 -71
  69. package/cjs/protocol/sasl.js +0 -108
  70. package/cjs/protocol/smart-buffer.js +0 -178
  71. package/cjs/safe-event-emitter.js +0 -17
  72. package/cjs/tsconfig-build-cjs.tsbuildinfo +0 -1
  73. package/cjs/types.js +0 -2
  74. package/cjs/util/array-calculatedim.js +0 -18
  75. package/cjs/util/bigint-methods.js +0 -44
  76. package/cjs/util/config-from-env.js +0 -29
  77. package/cjs/util/connection-config.js +0 -61
  78. package/cjs/util/convert-row-to-object.js +0 -12
  79. package/cjs/util/decode-binaryarray.js +0 -38
  80. package/cjs/util/encode-binaryarray.js +0 -44
  81. package/cjs/util/escape-literal.js +0 -26
  82. package/cjs/util/fast-parseint.js +0 -31
  83. package/cjs/util/get-parsers.js +0 -41
  84. package/cjs/util/parse-array.js +0 -60
  85. package/cjs/util/parse-datetime.js +0 -37
  86. package/cjs/util/parse-row.js +0 -11
  87. package/cjs/util/parse-time.js +0 -30
  88. package/cjs/util/stringify-arrayliteral.js +0 -37
  89. package/cjs/util/stringify-for-sql.js +0 -29
  90. package/cjs/util/wrap-row-description.js +0 -34
  91. package/esm/package.json +0 -3
  92. package/types/index.d.cts +0 -25
  93. /package/{types/connection → connection}/bind-param.d.ts +0 -0
  94. /package/{types/connection → connection}/connection.d.ts +0 -0
  95. /package/{types/connection → connection}/cursor.d.ts +0 -0
  96. /package/{types/connection → connection}/intl-connection.d.ts +0 -0
  97. /package/{types/connection → connection}/pool.d.ts +0 -0
  98. /package/{types/connection → connection}/portal.d.ts +0 -0
  99. /package/{types/connection → connection}/prepared-statement.d.ts +0 -0
  100. /package/{types/constants.d.ts → constants.d.ts} +0 -0
  101. /package/{types/data-type-map.d.ts → data-type-map.d.ts} +0 -0
  102. /package/{types/data-types → data-types}/bool-type.d.ts +0 -0
  103. /package/{esm/data-types → data-types}/bool-type.js +0 -0
  104. /package/{types/data-types → data-types}/box-type.d.ts +0 -0
  105. /package/{esm/data-types → data-types}/box-type.js +0 -0
  106. /package/{types/data-types → data-types}/bytea-type.d.ts +0 -0
  107. /package/{esm/data-types → data-types}/bytea-type.js +0 -0
  108. /package/{types/data-types → data-types}/char-type.d.ts +0 -0
  109. /package/{esm/data-types → data-types}/char-type.js +0 -0
  110. /package/{types/data-types → data-types}/circle-type.d.ts +0 -0
  111. /package/{esm/data-types → data-types}/circle-type.js +0 -0
  112. /package/{types/data-types → data-types}/date-type.d.ts +0 -0
  113. /package/{esm/data-types → data-types}/date-type.js +0 -0
  114. /package/{types/data-types → data-types}/float4-type.d.ts +0 -0
  115. /package/{esm/data-types → data-types}/float4-type.js +0 -0
  116. /package/{types/data-types → data-types}/float8-type.d.ts +0 -0
  117. /package/{esm/data-types → data-types}/float8-type.js +0 -0
  118. /package/{types/data-types → data-types}/int2-type.d.ts +0 -0
  119. /package/{esm/data-types → data-types}/int2-type.js +0 -0
  120. /package/{types/data-types → data-types}/int2-vector-type.d.ts +0 -0
  121. /package/{esm/data-types → data-types}/int2-vector-type.js +0 -0
  122. /package/{types/data-types → data-types}/int4-type.d.ts +0 -0
  123. /package/{esm/data-types → data-types}/int4-type.js +0 -0
  124. /package/{types/data-types → data-types}/int8-type.d.ts +0 -0
  125. /package/{esm/data-types → data-types}/int8-type.js +0 -0
  126. /package/{types/data-types → data-types}/json-type.d.ts +0 -0
  127. /package/{esm/data-types → data-types}/json-type.js +0 -0
  128. /package/{types/data-types → data-types}/jsonb-type.d.ts +0 -0
  129. /package/{esm/data-types → data-types}/jsonb-type.js +0 -0
  130. /package/{types/data-types → data-types}/lseg-type.d.ts +0 -0
  131. /package/{esm/data-types → data-types}/lseg-type.js +0 -0
  132. /package/{types/data-types → data-types}/numeric-type.d.ts +0 -0
  133. /package/{esm/data-types → data-types}/numeric-type.js +0 -0
  134. /package/{types/data-types → data-types}/oid-type.d.ts +0 -0
  135. /package/{esm/data-types → data-types}/oid-type.js +0 -0
  136. /package/{types/data-types → data-types}/point-type.d.ts +0 -0
  137. /package/{esm/data-types → data-types}/point-type.js +0 -0
  138. /package/{types/data-types → data-types}/time-type.d.ts +0 -0
  139. /package/{esm/data-types → data-types}/time-type.js +0 -0
  140. /package/{types/data-types → data-types}/timestamp-type.d.ts +0 -0
  141. /package/{esm/data-types → data-types}/timestamp-type.js +0 -0
  142. /package/{types/data-types → data-types}/timestamptz-type.d.ts +0 -0
  143. /package/{esm/data-types → data-types}/timestamptz-type.js +0 -0
  144. /package/{types/data-types → data-types}/uuid-type.d.ts +0 -0
  145. /package/{esm/data-types → data-types}/uuid-type.js +0 -0
  146. /package/{types/data-types → data-types}/varchar-type.d.ts +0 -0
  147. /package/{esm/data-types → data-types}/varchar-type.js +0 -0
  148. /package/{types/index.d.ts → index.d.ts} +0 -0
  149. /package/{esm/index.js → index.js} +0 -0
  150. /package/{types/interfaces → interfaces}/command-result.d.ts +0 -0
  151. /package/{esm/interfaces → interfaces}/command-result.js +0 -0
  152. /package/{types/interfaces → interfaces}/data-mapping-options.d.ts +0 -0
  153. /package/{esm/interfaces → interfaces}/data-mapping-options.js +0 -0
  154. /package/{types/interfaces → interfaces}/data-type.d.ts +0 -0
  155. /package/{esm/interfaces → interfaces}/data-type.js +0 -0
  156. /package/{types/interfaces → interfaces}/database-connection-params.d.ts +0 -0
  157. /package/{esm/interfaces → interfaces}/database-connection-params.js +0 -0
  158. /package/{types/interfaces → interfaces}/field-info.d.ts +0 -0
  159. /package/{esm/interfaces → interfaces}/field-info.js +0 -0
  160. /package/{types/interfaces → interfaces}/query-options.d.ts +0 -0
  161. /package/{esm/interfaces → interfaces}/query-options.js +0 -0
  162. /package/{types/interfaces → interfaces}/query-result.d.ts +0 -0
  163. /package/{esm/interfaces → interfaces}/query-result.js +0 -0
  164. /package/{types/interfaces → interfaces}/script-execute-options.d.ts +0 -0
  165. /package/{esm/interfaces → interfaces}/script-execute-options.js +0 -0
  166. /package/{types/interfaces → interfaces}/script-result.d.ts +0 -0
  167. /package/{esm/interfaces → interfaces}/script-result.js +0 -0
  168. /package/{types/interfaces → interfaces}/statement-prepare-options.d.ts +0 -0
  169. /package/{esm/interfaces → interfaces}/statement-prepare-options.js +0 -0
  170. /package/{types/protocol → protocol}/backend.d.ts +0 -0
  171. /package/{types/protocol → protocol}/buffer-reader.d.ts +0 -0
  172. /package/{types/protocol → protocol}/database-error.d.ts +0 -0
  173. /package/{types/protocol → protocol}/frontend.d.ts +0 -0
  174. /package/{types/protocol → protocol}/pg-socket.d.ts +0 -0
  175. /package/{types/protocol → protocol}/protocol.d.ts +0 -0
  176. /package/{esm/protocol → protocol}/protocol.js +0 -0
  177. /package/{types/protocol → protocol}/sasl.d.ts +0 -0
  178. /package/{esm/protocol → protocol}/sasl.js +0 -0
  179. /package/{types/protocol → protocol}/smart-buffer.d.ts +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
@@ -1,178 +0,0 @@
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 {
9
- constructor(cfg) {
10
- super(Buffer.allocUnsafe(cfg?.pageSize || SmartBuffer.DEFAULT_PAGE_SIZE));
11
- this._lastHouseKeep = 0;
12
- this._stMaxPages = 1;
13
- this._length = 0;
14
- this._houseKeepInterval = cfg?.houseKeepInterval || 5000;
15
- this.pageSize = this.buffer.length;
16
- this.maxSize = cfg?.maxLength || SmartBuffer.DEFAULT_MAX_SIZE;
17
- this._length = 0;
18
- }
19
- get capacity() {
20
- return this.buffer.length;
21
- }
22
- get length() {
23
- return this._length;
24
- }
25
- start() {
26
- this.offset = 0;
27
- this._length = 0;
28
- if (this._houseKeepTimer) {
29
- clearTimeout(this._houseKeepTimer);
30
- this._houseKeepTimer = undefined;
31
- }
32
- return this;
33
- }
34
- flush() {
35
- if (this._houseKeepTimer)
36
- clearTimeout(this._houseKeepTimer);
37
- const length = this.length;
38
- this._length = 0;
39
- const out = this.buffer.slice(0, length);
40
- const pages = length ? Math.ceil(length / this.pageSize) : 1;
41
- this._stMaxPages = Math.max(this._stMaxPages, pages);
42
- if (this._lastHouseKeep < Date.now() + this._houseKeepInterval)
43
- this._houseKeep();
44
- this._houseKeepTimer = setTimeout(() => {
45
- this._houseKeepTimer = undefined;
46
- this._houseKeep();
47
- }, this._houseKeepInterval).unref();
48
- return out;
49
- }
50
- growSize(len) {
51
- const endOffset = this.offset + len;
52
- if (this.capacity < endOffset) {
53
- if (endOffset > this.maxSize)
54
- throw new Error('Buffer limit exceeded.');
55
- const newSize = Math.ceil(endOffset / this.pageSize) * this.pageSize;
56
- const newBuffer = Buffer.allocUnsafe(newSize);
57
- this.buffer.copy(newBuffer);
58
- this.buffer = newBuffer;
59
- }
60
- this._length = Math.max(this.length, endOffset);
61
- return this;
62
- }
63
- fill(value = 0, len = 1) {
64
- this.ensureSize(len);
65
- this.buffer.fill(value, this.offset, this.offset + len);
66
- this.offset += len;
67
- return this;
68
- }
69
- writeCString(str, encoding) {
70
- const len = str ? Buffer.byteLength(str, encoding) : 0;
71
- this.ensureSize(len + 1);
72
- if (str) {
73
- this.buffer.write(str, this.offset, encoding);
74
- this.offset += len;
75
- }
76
- this.writeUInt8(0);
77
- return this;
78
- }
79
- writeLString(str, encoding) {
80
- const len = str ? Buffer.byteLength(str, encoding) : 0;
81
- this.ensureSize(len + 4);
82
- this.writeInt32BE(str == null ? -1 : len);
83
- if (str) {
84
- if (encoding)
85
- this.offset += this.buffer.write(str, this.offset, encoding);
86
- else
87
- this.offset += this.buffer.write(str, this.offset);
88
- }
89
- return this;
90
- }
91
- writeString(str, encoding) {
92
- if (str) {
93
- const len = Buffer.byteLength(str, encoding);
94
- this.ensureSize(len);
95
- this.offset += this.buffer.write(str, this.offset, encoding);
96
- }
97
- return this;
98
- }
99
- writeInt8(n) {
100
- this.ensureSize(1);
101
- this.buffer.writeInt8(n, this.offset);
102
- this.offset++;
103
- return this;
104
- }
105
- writeUInt8(n) {
106
- this.ensureSize(1);
107
- this.buffer.writeUInt8(n, this.offset);
108
- this.offset++;
109
- return this;
110
- }
111
- writeUInt16BE(n) {
112
- this.ensureSize(2);
113
- this.buffer.writeUInt16BE(n, this.offset);
114
- this.offset += 2;
115
- return this;
116
- }
117
- writeUInt32BE(n) {
118
- this.ensureSize(4);
119
- this.buffer.writeUInt32BE(n, this.offset);
120
- this.offset += 4;
121
- return this;
122
- }
123
- writeInt16BE(n) {
124
- this.ensureSize(2);
125
- this.buffer.writeInt16BE(n, this.offset);
126
- this.offset += 2;
127
- return this;
128
- }
129
- writeInt32BE(n) {
130
- this.ensureSize(4);
131
- this.buffer.writeInt32BE(n, this.offset);
132
- this.offset += 4;
133
- return this;
134
- }
135
- writeBigInt64BE(n) {
136
- n = typeof n === 'bigint' ? n : BigInt(n);
137
- this.ensureSize(8);
138
- if (typeof this.buffer.writeBigInt64BE === 'function')
139
- this.buffer.writeBigInt64BE(n, this.offset);
140
- else
141
- (0, bigint_methods_js_1.writeBigUInt64BE)(this.buffer, n, this.offset);
142
- this.offset += 8;
143
- return this;
144
- }
145
- writeFloatBE(n) {
146
- this.ensureSize(4);
147
- this.buffer.writeFloatBE(n, this.offset);
148
- this.offset += 4;
149
- return this;
150
- }
151
- writeDoubleBE(n) {
152
- this.ensureSize(8);
153
- this.buffer.writeDoubleBE(n, this.offset);
154
- this.offset += 8;
155
- return this;
156
- }
157
- writeBuffer(buffer) {
158
- this.ensureSize(buffer.length);
159
- buffer.copy(this.buffer, this.offset, 0, buffer.length);
160
- this.offset += buffer.length;
161
- return this;
162
- }
163
- ensureSize(len) {
164
- const n = this.offset + len - this.length;
165
- if (n > 0)
166
- this.growSize(n);
167
- return this;
168
- }
169
- _houseKeep() {
170
- const needSize = this._stMaxPages * this.pageSize;
171
- if (this.buffer.length > needSize)
172
- this.buffer = Buffer.allocUnsafe(needSize);
173
- this._stMaxPages = this.length ? Math.ceil(this.length / this.pageSize) : 1;
174
- }
175
- }
176
- exports.SmartBuffer = SmartBuffer;
177
- SmartBuffer.DEFAULT_PAGE_SIZE = 4096;
178
- SmartBuffer.DEFAULT_MAX_SIZE = Math.min(Math.floor(os.totalmem() / 2), 1024 * 1024 * 1024 * 2);
@@ -1,17 +0,0 @@
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 {
6
- emit(event, ...args) {
7
- try {
8
- if (event === 'error' && !this.listenerCount('error'))
9
- return false;
10
- return super.emit(event, ...args);
11
- }
12
- catch {
13
- return false;
14
- }
15
- }
16
- }
17
- exports.SafeEventEmitter = SafeEventEmitter;
@@ -1 +0,0 @@
1
- {"root":["../../src/constants.ts","../../src/data-type-map.ts","../../src/index.ts","../../src/safe-event-emitter.ts","../../src/types.ts","../../src/connection/bind-param.ts","../../src/connection/connection.ts","../../src/connection/cursor.ts","../../src/connection/intl-connection.ts","../../src/connection/pool.ts","../../src/connection/portal.ts","../../src/connection/prepared-statement.ts","../../src/data-types/bool-type.ts","../../src/data-types/box-type.ts","../../src/data-types/bytea-type.ts","../../src/data-types/char-type.ts","../../src/data-types/circle-type.ts","../../src/data-types/date-type.ts","../../src/data-types/float4-type.ts","../../src/data-types/float8-type.ts","../../src/data-types/int2-type.ts","../../src/data-types/int2-vector-type.ts","../../src/data-types/int4-type.ts","../../src/data-types/int8-type.ts","../../src/data-types/json-type.ts","../../src/data-types/jsonb-type.ts","../../src/data-types/lseg-type.ts","../../src/data-types/numeric-type.ts","../../src/data-types/oid-type.ts","../../src/data-types/point-type.ts","../../src/data-types/time-type.ts","../../src/data-types/timestamp-type.ts","../../src/data-types/timestamptz-type.ts","../../src/data-types/uuid-type.ts","../../src/data-types/varchar-type.ts","../../src/interfaces/command-result.ts","../../src/interfaces/data-mapping-options.ts","../../src/interfaces/data-type.ts","../../src/interfaces/database-connection-params.ts","../../src/interfaces/field-info.ts","../../src/interfaces/query-options.ts","../../src/interfaces/query-result.ts","../../src/interfaces/script-execute-options.ts","../../src/interfaces/script-result.ts","../../src/interfaces/statement-prepare-options.ts","../../src/protocol/backend.ts","../../src/protocol/buffer-reader.ts","../../src/protocol/database-error.ts","../../src/protocol/frontend.ts","../../src/protocol/pg-socket.ts","../../src/protocol/protocol.ts","../../src/protocol/sasl.ts","../../src/protocol/smart-buffer.ts","../../src/util/array-calculatedim.ts","../../src/util/bigint-methods.ts","../../src/util/config-from-env.ts","../../src/util/connection-config.ts","../../src/util/convert-row-to-object.ts","../../src/util/decode-binaryarray.ts","../../src/util/encode-binaryarray.ts","../../src/util/escape-literal.ts","../../src/util/fast-parseint.ts","../../src/util/get-parsers.ts","../../src/util/parse-array.ts","../../src/util/parse-datetime.ts","../../src/util/parse-row.ts","../../src/util/parse-time.ts","../../src/util/stringify-arrayliteral.ts","../../src/util/stringify-for-sql.ts","../../src/util/wrap-row-description.ts"],"version":"5.9.3"}
package/cjs/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.arrayCalculateDim = arrayCalculateDim;
4
- function arrayCalculateDim(arr) {
5
- if (!arr || arr.length === 0)
6
- return [0];
7
- const dim = [arr.length];
8
- const iterate = (a, level) => {
9
- for (let i = 0; i < a.length; i++) {
10
- if (Array.isArray(a[i])) {
11
- dim[level] = Math.max(dim[level] || 0, a[i].length);
12
- iterate(a[i], level + 1);
13
- }
14
- }
15
- };
16
- iterate(arr, 1);
17
- return dim;
18
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readBigInt64BE = readBigInt64BE;
4
- exports.writeBigUInt64BE = writeBigUInt64BE;
5
- const big0 = BigInt(0);
6
- const beAnd = BigInt('0xffffffff');
7
- const big32 = BigInt(32);
8
- // https://github.com/nodejs/node/blob/v13.9.0/lib/internal/buffer.js
9
- function readBigInt64BE(buf, offset = 0) {
10
- const first = buf[offset];
11
- const last = buf[offset + 7];
12
- if (first === undefined || last === undefined)
13
- return big0;
14
- const val = (first << 24) + // Overflow
15
- buf[++offset] * 2 ** 16 +
16
- buf[++offset] * 2 ** 8 +
17
- buf[++offset];
18
- return ((BigInt(val) << big32) +
19
- BigInt(buf[++offset] * 2 ** 24 +
20
- buf[++offset] * 2 ** 16 +
21
- buf[++offset] * 2 ** 8 +
22
- last));
23
- }
24
- function writeBigUInt64BE(buf, value, offset = 0) {
25
- // @ts-ignore
26
- let lo = Number(value & beAnd);
27
- buf[offset + 7] = lo;
28
- lo = lo >> 8;
29
- buf[offset + 6] = lo;
30
- lo = lo >> 8;
31
- buf[offset + 5] = lo;
32
- lo = lo >> 8;
33
- buf[offset + 4] = lo;
34
- // @ts-ignore
35
- let hi = Number((value >> big32) & beAnd);
36
- buf[offset + 3] = hi;
37
- hi = hi >> 8;
38
- buf[offset + 2] = hi;
39
- hi = hi >> 8;
40
- buf[offset + 1] = hi;
41
- hi = hi >> 8;
42
- buf[offset] = hi;
43
- return offset + 8;
44
- }
@@ -1,29 +0,0 @@
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() {
6
- const env = process.env;
7
- const result = {};
8
- result.host = env.PGHOST || env.PGHOSTADDR;
9
- if (env.PGPORT)
10
- result.port = (0, putil_varhelpers_1.toIntDef)(env.PGPORT, 5432);
11
- if (env.PGDATABASE)
12
- result.database = env.PGDATABASE;
13
- if (env.PGUSER)
14
- result.user = env.PGUSER;
15
- if (env.PGPASSWORD)
16
- result.password = env.PGPASSWORD;
17
- if (env.PGAPPNAME)
18
- result.applicationName = env.PGAPPNAME;
19
- if (env.PGTZ)
20
- result.timezone = env.PGTZ;
21
- if (env.PGSCHEMA)
22
- result.schema = env.PGSCHEMA;
23
- if (env.PGCONNECT_TIMEOUT)
24
- result.connectTimeoutMs = (0, putil_varhelpers_1.toIntDef)(env.PGCONNECT_TIMEOUT, 30000);
25
- if (env.PGMAX_BUFFER_SIZE) {
26
- result.buffer = { maxLength: (0, putil_varhelpers_1.toInt)(env.PGMAX_BUFFER_SIZE) };
27
- }
28
- return result;
29
- }
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConnectionConfig = getConnectionConfig;
4
- exports.parseConnectionString = parseConnectionString;
5
- const objects_1 = require("@jsopen/objects");
6
- const config_from_env_js_1 = require("./config-from-env.js");
7
- function getConnectionConfig(config) {
8
- const cfg = (0, config_from_env_js_1.configFromEnv)();
9
- if (typeof config === 'string') {
10
- (0, objects_1.merge)(cfg, parseConnectionString(config));
11
- }
12
- else if (typeof config === 'object') {
13
- (0, objects_1.merge)(cfg, config);
14
- }
15
- if (cfg.host) {
16
- const x = parseConnectionString('' + cfg.host);
17
- (0, objects_1.merge)(cfg, x);
18
- }
19
- cfg.user = cfg.user || 'postgres';
20
- cfg.database = cfg.database || 'postgres';
21
- cfg.host = cfg.host || '127.0.0.1';
22
- return cfg;
23
- }
24
- function parseConnectionString(str) {
25
- if (str.startsWith('/'))
26
- str = 'socket:/' + str;
27
- if (!str.includes('://'))
28
- str = 'postgres://' + str;
29
- const parsed = new URL(str);
30
- const getFirst = (v) => typeof v === 'string' ? v : Array.isArray(v) ? v[0] : '';
31
- const cfg = {};
32
- cfg.host = decodeURI(parsed.hostname || '');
33
- if (parsed.port)
34
- cfg.port = parseInt(parsed.port, 10);
35
- if (parsed.protocol === 'socket:' || parsed.protocol === 'unix:') {
36
- if (!cfg.host.startsWith('/'))
37
- cfg.host = '/' + cfg.host;
38
- cfg.host += decodeURI(parsed.pathname || '');
39
- if (parsed.searchParams.get('db'))
40
- cfg.database = decodeURI(getFirst(parsed.searchParams.get('db')));
41
- }
42
- else if (parsed.protocol === 'pg:' || parsed.protocol === 'postgres:') {
43
- if (parsed.pathname)
44
- cfg.database = decodeURI(parsed.pathname.substring(1));
45
- }
46
- if (parsed.searchParams.get('host'))
47
- cfg.host = decodeURI(getFirst(parsed.searchParams.get('host')));
48
- if (parsed.searchParams.get('db'))
49
- cfg.database = decodeURI(getFirst(parsed.searchParams.get('db')));
50
- if (parsed.searchParams.get('schema'))
51
- cfg.schema = decodeURI(getFirst(parsed.searchParams.get('schema')));
52
- if (parsed.searchParams.get('application_name')) {
53
- cfg.applicationName = decodeURI(getFirst(parsed.searchParams.get('application_name')));
54
- }
55
- if (parsed.username)
56
- cfg.user = parsed.username;
57
- if (parsed.password)
58
- cfg.password = parsed.password;
59
- cfg.requireSSL = parsed.searchParams.get('sslmode') === 'require';
60
- return cfg;
61
- }
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertRowToObject = convertRowToObject;
4
- function convertRowToObject(fields, row) {
5
- const out = {};
6
- const l = row.length;
7
- let i;
8
- for (i = 0; i < l; i++) {
9
- out[fields[i].fieldName] = row[i];
10
- }
11
- return out;
12
- }
@@ -1,38 +0,0 @@
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 = {}) {
6
- if (!buf.length)
7
- return null;
8
- const io = new buffer_reader_js_1.BufferReader(buf);
9
- const ndims = io.readInt32BE();
10
- io.readInt32BE(); // hasNulls
11
- const elementOID = io.readInt32BE(); // element oid
12
- if (ndims === 0)
13
- return [];
14
- const dims = [];
15
- const readDim = (level) => {
16
- const elemCount = dims[level];
17
- const target = new Array(elemCount);
18
- for (let i = 0; i < elemCount; i++) {
19
- if (level < dims.length - 1) {
20
- target[i] = readDim(level + 1);
21
- continue;
22
- }
23
- const len = io.readInt32BE();
24
- if (len === -1)
25
- target[i] = null;
26
- else {
27
- const b = io.readBuffer(len);
28
- target[i] = decoder(b, { ...options, elementOID });
29
- }
30
- }
31
- return target;
32
- };
33
- for (let d = 0; d < ndims; d++) {
34
- dims[d] = io.readInt32BE();
35
- io.readInt32BE(); // LBound
36
- }
37
- return readDim(0);
38
- }
@@ -1,44 +0,0 @@
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;
9
- const dim = encodeCalculateDimFn(value);
10
- const ndims = dim.length;
11
- const zeroOffset = io.offset;
12
- io.writeInt32BE(ndims) // Number of dimensions
13
- .writeInt32BE(0) // reserved for has-null flag
14
- .writeInt32BE(itemOid);
15
- for (let d = 0; d < ndims; d++) {
16
- io.writeInt32BE(dim[d]); // Number of items in dimension
17
- io.writeInt32BE(0); // LBound always 0.
18
- }
19
- let hasNull = false;
20
- let pos;
21
- const writeDim = (arr, level) => {
22
- const elemCount = dim[level];
23
- for (let i = 0; i < elemCount; i++) {
24
- if (level < dim.length - 1) {
25
- writeDim(arr && arr[i], level + 1);
26
- continue;
27
- }
28
- // if value is null
29
- if (!arr || arr[i] == null) {
30
- hasNull = true;
31
- io.writeInt32BE(-1);
32
- continue;
33
- }
34
- io.writeInt32BE(0); // reserved for data len
35
- pos = io.offset;
36
- encode(io, arr[i], options);
37
- // Update item data size
38
- io.buffer.writeInt32BE(io.length - pos, pos - 4);
39
- }
40
- };
41
- writeDim(value, 0);
42
- if (hasNull)
43
- io.buffer.writeInt32BE(1, zeroOffset + 4);
44
- }
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.escapeLiteral = escapeLiteral;
4
- // Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
5
- function escapeLiteral(str) {
6
- let backSlash = false;
7
- let out = "'";
8
- let i;
9
- let c;
10
- const l = str.length;
11
- for (i = 0; i < l; i++) {
12
- c = str[i];
13
- if (c === "'")
14
- out += c + c;
15
- else if (c === '\\') {
16
- out += c + c;
17
- backSlash = true;
18
- }
19
- else
20
- out += c;
21
- }
22
- out += "'";
23
- if (backSlash)
24
- out = ' E' + out;
25
- return out;
26
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fastParseInt = fastParseInt;
4
- function fastParseInt(str) {
5
- /* istanbul ignore next */
6
- if (typeof str === 'number')
7
- return Math.floor(str);
8
- // noinspection SuspiciousTypeOfGuard
9
- if (typeof str !== 'string')
10
- return NaN;
11
- const strLength = str.length;
12
- let res = 0;
13
- let i = 0;
14
- let neg = false;
15
- if (str.startsWith('-')) {
16
- neg = true;
17
- i++;
18
- }
19
- do {
20
- const charCode = str.charCodeAt(i);
21
- /* istanbul ignore next */
22
- if (charCode === 46)
23
- return res;
24
- /* istanbul ignore next */
25
- if (charCode < 48 || charCode > 57)
26
- return NaN;
27
- res *= 10;
28
- res += charCode - 48;
29
- } while (++i < strLength);
30
- return neg ? -res : res;
31
- }
@@ -1,41 +0,0 @@
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");
7
- const DefaultColumnParser = (v) => v;
8
- function getParsers(typeMap, fields) {
9
- const parsers = new Array(fields.length);
10
- const l = fields.length;
11
- let f;
12
- let i;
13
- for (i = 0; i < l; i++) {
14
- f = fields[i];
15
- const dataTypeReg = typeMap.get(f.dataTypeId);
16
- if (dataTypeReg) {
17
- const isArray = !!dataTypeReg.elementsOID;
18
- if (f.format === constants_js_1.DataFormat.binary) {
19
- const decode = dataTypeReg.parseBinary;
20
- if (decode) {
21
- parsers[i] = !isArray
22
- ? decode
23
- : (v, options) => (0, decode_binaryarray_js_1.decodeBinaryArray)(v, decode, options);
24
- }
25
- }
26
- else if (f.format === constants_js_1.DataFormat.text) {
27
- const parse = dataTypeReg.parseText;
28
- if (parse) {
29
- parsers[i] = !isArray
30
- ? parse
31
- : (v, options) => (0, parse_array_js_1.parsePostgresArray)(v, {
32
- transform: x => parse(x, options),
33
- separator: dataTypeReg.arraySeparator,
34
- });
35
- }
36
- }
37
- }
38
- parsers[i] = parsers[i] || DefaultColumnParser;
39
- }
40
- return parsers;
41
- }
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parsePostgresArray = parsePostgresArray;
4
- function parsePostgresArray(s, opts) {
5
- if (!s)
6
- return;
7
- const sep = (opts?.separator || ',').substring(0, 1);
8
- const transform = opts?.transform;
9
- const len = s.length;
10
- let idx = 0;
11
- const out = [];
12
- const iterate = (arr) => {
13
- let c;
14
- let exactlyValue = false;
15
- let token = '';
16
- let quote = '';
17
- while (idx < len) {
18
- c = s.charAt(idx++);
19
- if (!quote) {
20
- if (!token && c === '{') {
21
- const a = [];
22
- arr.push(a);
23
- iterate(a);
24
- continue;
25
- }
26
- if (c === '}' || c === sep) {
27
- if (token) {
28
- if (token === 'NULL' && !exactlyValue)
29
- arr.push(null);
30
- else
31
- arr.push(transform ? transform(token) : token);
32
- exactlyValue = false;
33
- }
34
- token = '';
35
- if (c === '}')
36
- return;
37
- continue;
38
- }
39
- }
40
- if (c === '\\') {
41
- c = s.charAt(idx++);
42
- token += c;
43
- continue;
44
- }
45
- if (c === '"' || c === "'") {
46
- if (quote && quote === c) {
47
- quote = '';
48
- }
49
- else {
50
- exactlyValue = true;
51
- quote = c;
52
- }
53
- continue;
54
- }
55
- token += c;
56
- }
57
- };
58
- iterate(out);
59
- return out.length ? out[0] : undefined;
60
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseDateTime = parseDateTime;
4
- // noinspection RegExpUnnecessaryNonCapturingGroup
5
- const fast_parseint_js_1 = require("./fast-parseint.js");
6
- // noinspection RegExpUnnecessaryNonCapturingGroup
7
- const TIMESTAMP_PATTERN = /^(\d{4})-?(0[1-9]|1[012])?-?([123]0|[012][1-9]|31)?(?:[T ]?([01][0-9]|2[0-3]):?([0-5][0-9]):?([0-5][0-9])?(?:\.(\d+))?(?:(Z)|(?:([+-])([01]?[0-9]|2[0-3]):?([0-5][0-9])?))?)?$/;
8
- const INFINITY_PATTERN = /^-?infinity$/;
9
- function parseDateTime(str, parseTime, parseTimeZone, utc) {
10
- let m = str.match(TIMESTAMP_PATTERN);
11
- if (!m) {
12
- m = str.match(INFINITY_PATTERN);
13
- if (m)
14
- return Number(str.replace('i', 'I'));
15
- return new Date('invalid');
16
- }
17
- const args = [
18
- 1970, 0, 1, 0, 0, 0, 0,
19
- ];
20
- const l = parseTime ? 7 : 3;
21
- for (let i = 0; i < l; i++) {
22
- const s = m[i + 1];
23
- args[i] = (0, fast_parseint_js_1.fastParseInt)(s) || 0;
24
- }
25
- // Months starts from 0
26
- if (args[1] > 0)
27
- args[1]--;
28
- if (parseTimeZone && parseTime && m[9]) {
29
- const r = m[9] === '-' ? -1 : 1;
30
- args[3] -= ((0, fast_parseint_js_1.fastParseInt)(m[10]) || 0) * r;
31
- args[4] -= ((0, fast_parseint_js_1.fastParseInt)(m[11]) || 0) * r;
32
- return new Date(Date.UTC(...args));
33
- }
34
- if (m[8] || utc)
35
- return new Date(Date.UTC(...args));
36
- return new Date(...args);
37
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseRow = parseRow;
4
- function parseRow(parsers, row, options) {
5
- const l = row.length;
6
- let i;
7
- for (i = 0; i < l; i++) {
8
- row[i] =
9
- row[i] == null ? null : parsers[i].call(undefined, row[i], options);
10
- }
11
- }