postgrejs 2.22.2 → 2.22.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/cjs/connection/connection.js +9 -4
- package/cjs/connection/intl-connection.js +12 -5
- package/cjs/connection/portal.js +10 -3
- package/cjs/connection/prepared-statement.js +9 -3
- package/cjs/constants.js +0 -1
- package/cjs/data-type-map.js +15 -3
- package/cjs/data-types/bool-type.js +7 -1
- package/cjs/data-types/circle-type.js +4 -1
- package/cjs/data-types/date-type.js +12 -4
- package/cjs/data-types/int2-type.js +1 -1
- package/cjs/data-types/int2-vector-type.js +5 -1
- package/cjs/data-types/int4-type.js +3 -1
- package/cjs/data-types/int8-type.js +7 -2
- package/cjs/data-types/json-type.js +4 -2
- package/cjs/data-types/jsonb-type.js +4 -2
- package/cjs/data-types/lseg-type.js +4 -1
- package/cjs/data-types/point-type.js +4 -1
- package/cjs/data-types/time-type.js +16 -5
- package/cjs/data-types/timestamp-type.js +11 -4
- package/cjs/data-types/timestamptz-type.js +4 -2
- package/cjs/protocol/backend.js +9 -3
- package/cjs/protocol/frontend.js +40 -10
- package/cjs/protocol/pg-socket.js +5 -2
- package/cjs/protocol/sasl.js +2 -2
- package/cjs/protocol/smart-buffer.js +1 -2
- package/cjs/safe-event-emitter.js +1 -1
- package/cjs/tsconfig-build-cjs.tsbuildinfo +1 -1
- package/cjs/util/bigint-methods.js +5 -2
- package/cjs/util/connection-config.js +5 -6
- package/cjs/util/parse-datetime.js +4 -4
- package/cjs/util/parse-row.js +2 -1
- package/cjs/util/parse-time.js +3 -2
- package/esm/connection/connection.js +9 -4
- package/esm/connection/intl-connection.js +12 -5
- package/esm/connection/pool.js +1 -1
- package/esm/connection/portal.js +10 -3
- package/esm/connection/prepared-statement.js +9 -3
- package/esm/constants.js +0 -1
- package/esm/data-type-map.js +18 -6
- package/esm/data-types/bool-type.js +7 -1
- package/esm/data-types/circle-type.js +4 -1
- package/esm/data-types/date-type.js +12 -4
- package/esm/data-types/int2-type.js +1 -1
- package/esm/data-types/int2-vector-type.js +5 -1
- package/esm/data-types/int4-type.js +3 -1
- package/esm/data-types/int8-type.js +7 -2
- package/esm/data-types/json-type.js +4 -2
- package/esm/data-types/jsonb-type.js +4 -2
- package/esm/data-types/lseg-type.js +4 -1
- package/esm/data-types/point-type.js +4 -1
- package/esm/data-types/time-type.js +16 -5
- package/esm/data-types/timestamp-type.js +11 -4
- package/esm/data-types/timestamptz-type.js +4 -2
- package/esm/protocol/backend.js +9 -3
- package/esm/protocol/frontend.js +40 -10
- package/esm/protocol/pg-socket.js +5 -2
- package/esm/protocol/sasl.js +2 -2
- package/esm/protocol/smart-buffer.js +1 -2
- package/esm/safe-event-emitter.js +1 -1
- package/esm/util/bigint-methods.js +5 -2
- package/esm/util/connection-config.js +2 -2
- package/esm/util/parse-datetime.js +4 -4
- package/esm/util/parse-row.js +2 -1
- package/esm/util/parse-time.js +3 -2
- package/package.json +3 -3
|
@@ -6,7 +6,9 @@ export const Int8Type = {
|
|
|
6
6
|
oid: DataTypeOIDs.int8,
|
|
7
7
|
jsType: 'BigInt',
|
|
8
8
|
parseBinary(buf) {
|
|
9
|
-
const v = typeof buf.readBigInt64BE === 'function'
|
|
9
|
+
const v = typeof buf.readBigInt64BE === 'function'
|
|
10
|
+
? buf.readBigInt64BE(0)
|
|
11
|
+
: readBigInt64BE(buf);
|
|
10
12
|
return v >= -maxSafeInteger && v <= maxSafeInteger ? Number(v) : v;
|
|
11
13
|
},
|
|
12
14
|
encodeBinary(buf, v) {
|
|
@@ -17,7 +19,10 @@ export const Int8Type = {
|
|
|
17
19
|
return v >= -maxSafeInteger && v <= maxSafeInteger ? Number(v) : v;
|
|
18
20
|
},
|
|
19
21
|
isType(v) {
|
|
20
|
-
return typeof v === 'bigint' ||
|
|
22
|
+
return (typeof v === 'bigint' ||
|
|
23
|
+
(typeof v === 'number' &&
|
|
24
|
+
Number.isInteger(v) &&
|
|
25
|
+
v > Number.MAX_SAFE_INTEGER));
|
|
21
26
|
},
|
|
22
27
|
};
|
|
23
28
|
export const ArrayInt8Type = {
|
|
@@ -5,7 +5,8 @@ export const JsonType = {
|
|
|
5
5
|
jsType: 'string',
|
|
6
6
|
parseBinary(v, options) {
|
|
7
7
|
const content = v.toString('utf8');
|
|
8
|
-
const fetchAsString = options.fetchAsString &&
|
|
8
|
+
const fetchAsString = options.fetchAsString &&
|
|
9
|
+
options.fetchAsString.includes(DataTypeOIDs.jsonb);
|
|
9
10
|
if (fetchAsString)
|
|
10
11
|
return content;
|
|
11
12
|
return content ? JSON.parse(content) : undefined;
|
|
@@ -18,7 +19,8 @@ export const JsonType = {
|
|
|
18
19
|
return '' + v;
|
|
19
20
|
},
|
|
20
21
|
parseText(v, options) {
|
|
21
|
-
const fetchAsString = options.fetchAsString &&
|
|
22
|
+
const fetchAsString = options.fetchAsString &&
|
|
23
|
+
options.fetchAsString.includes(DataTypeOIDs.jsonb);
|
|
22
24
|
if (fetchAsString)
|
|
23
25
|
return v;
|
|
24
26
|
return v ? JSON.parse(v) : null;
|
|
@@ -8,7 +8,8 @@ export const JsonbType = {
|
|
|
8
8
|
const buf = new BufferReader(v);
|
|
9
9
|
if (buf.readUInt8() !== 1)
|
|
10
10
|
throw new Error('Unexpected Jsonb version value in header');
|
|
11
|
-
const fetchAsString = options.fetchAsString &&
|
|
11
|
+
const fetchAsString = options.fetchAsString &&
|
|
12
|
+
options.fetchAsString.includes(DataTypeOIDs.json);
|
|
12
13
|
const content = buf.readLString(buf.length - buf.offset);
|
|
13
14
|
if (fetchAsString)
|
|
14
15
|
return content;
|
|
@@ -22,7 +23,8 @@ export const JsonbType = {
|
|
|
22
23
|
return '\x0001' + v;
|
|
23
24
|
},
|
|
24
25
|
parseText(v, options) {
|
|
25
|
-
const fetchAsString = options.fetchAsString &&
|
|
26
|
+
const fetchAsString = options.fetchAsString &&
|
|
27
|
+
options.fetchAsString.includes(DataTypeOIDs.json);
|
|
26
28
|
if (fetchAsString)
|
|
27
29
|
return v;
|
|
28
30
|
return v ? JSON.parse(v) : null;
|
|
@@ -22,7 +22,10 @@ export const LsegType = {
|
|
|
22
22
|
buf.writeDoubleBE(v.y2);
|
|
23
23
|
},
|
|
24
24
|
parseText(v) {
|
|
25
|
-
const m = v.match(LSEG_PATTERN1) ||
|
|
25
|
+
const m = v.match(LSEG_PATTERN1) ||
|
|
26
|
+
v.match(LSEG_PATTERN2) ||
|
|
27
|
+
v.match(LSEG_PATTERN3) ||
|
|
28
|
+
v.match(LSEG_PATTERN4);
|
|
26
29
|
if (!m)
|
|
27
30
|
return undefined;
|
|
28
31
|
return {
|
|
@@ -25,7 +25,10 @@ export const PointType = {
|
|
|
25
25
|
};
|
|
26
26
|
},
|
|
27
27
|
isType(v) {
|
|
28
|
-
return typeof v === 'object' &&
|
|
28
|
+
return (typeof v === 'object' &&
|
|
29
|
+
Object.keys(v).length === 2 &&
|
|
30
|
+
typeof v.x === 'number' &&
|
|
31
|
+
typeof v.y === 'number');
|
|
29
32
|
},
|
|
30
33
|
};
|
|
31
34
|
export const ArrayPointType = {
|
|
@@ -6,7 +6,8 @@ export const TimeType = {
|
|
|
6
6
|
oid: DataTypeOIDs.time,
|
|
7
7
|
jsType: 'string',
|
|
8
8
|
parseBinary(v, options) {
|
|
9
|
-
const fetchAsString = options.fetchAsString &&
|
|
9
|
+
const fetchAsString = options.fetchAsString &&
|
|
10
|
+
options.fetchAsString.includes(DataTypeOIDs.time);
|
|
10
11
|
const hi = v.readInt32BE();
|
|
11
12
|
const lo = v.readUInt32BE(4);
|
|
12
13
|
let d = new Date((lo + hi * timeMul) / 1000);
|
|
@@ -21,7 +22,9 @@ export const TimeType = {
|
|
|
21
22
|
if (!(v instanceof Date))
|
|
22
23
|
v = new Date(v);
|
|
23
24
|
// Postgresql ignores timezone data so we are
|
|
24
|
-
let n = options.utcDates
|
|
25
|
+
let n = options.utcDates
|
|
26
|
+
? v.getTime()
|
|
27
|
+
: v.getTime() - v.getTimezoneOffset() * 60 * 1000;
|
|
25
28
|
n = n * 1000;
|
|
26
29
|
const hi = Math.floor(n / timeMul);
|
|
27
30
|
const lo = n - hi * timeMul;
|
|
@@ -29,12 +32,16 @@ export const TimeType = {
|
|
|
29
32
|
buf.writeUInt32BE(lo);
|
|
30
33
|
},
|
|
31
34
|
parseText(v, options) {
|
|
32
|
-
if (options.fetchAsString &&
|
|
35
|
+
if (options.fetchAsString &&
|
|
36
|
+
options.fetchAsString.includes(DataTypeOIDs.time))
|
|
33
37
|
return v;
|
|
34
38
|
return parseTime(v, false, options.utcDates);
|
|
35
39
|
},
|
|
36
40
|
isType(v) {
|
|
37
|
-
return ((v instanceof Date &&
|
|
41
|
+
return ((v instanceof Date &&
|
|
42
|
+
v.getFullYear() === 1970 &&
|
|
43
|
+
v.getMonth() === 0 &&
|
|
44
|
+
v.getDate() === 1) ||
|
|
38
45
|
(typeof v === 'string' && STRICT_TIME_PATTERN.test(v)));
|
|
39
46
|
},
|
|
40
47
|
};
|
|
@@ -42,7 +49,11 @@ function padZero(v) {
|
|
|
42
49
|
return v < 9 ? '0' + v : '' + v;
|
|
43
50
|
}
|
|
44
51
|
function dateToTimeString(d) {
|
|
45
|
-
return padZero(d.getHours()) +
|
|
52
|
+
return (padZero(d.getHours()) +
|
|
53
|
+
':' +
|
|
54
|
+
padZero(d.getMinutes()) +
|
|
55
|
+
':' +
|
|
56
|
+
padZero(d.getSeconds()));
|
|
46
57
|
}
|
|
47
58
|
export const ArrayTimeType = {
|
|
48
59
|
...TimeType,
|
|
@@ -7,7 +7,8 @@ export const TimestampType = {
|
|
|
7
7
|
oid: DataTypeOIDs.timestamp,
|
|
8
8
|
jsType: 'Date',
|
|
9
9
|
parseBinary(v, options) {
|
|
10
|
-
const fetchAsString = options.fetchAsString &&
|
|
10
|
+
const fetchAsString = options.fetchAsString &&
|
|
11
|
+
options.fetchAsString.includes(DataTypeOIDs.timestamp);
|
|
11
12
|
const hi = v.readInt32BE();
|
|
12
13
|
const lo = v.readUInt32BE(4);
|
|
13
14
|
if (lo === 0xffffffff && hi === 0x7fffffff)
|
|
@@ -37,7 +38,9 @@ export const TimestampType = {
|
|
|
37
38
|
if (!(v instanceof Date))
|
|
38
39
|
v = new Date(v);
|
|
39
40
|
// Postgresql ignores timezone data so we are
|
|
40
|
-
let n = options.utcDates
|
|
41
|
+
let n = options.utcDates
|
|
42
|
+
? v.getTime()
|
|
43
|
+
: v.getTime() - v.getTimezoneOffset() * 60 * 1000;
|
|
41
44
|
n = (n - timeShift) * 1000;
|
|
42
45
|
const hi = Math.floor(n / timeMul);
|
|
43
46
|
const lo = n - hi * timeMul;
|
|
@@ -45,14 +48,18 @@ export const TimestampType = {
|
|
|
45
48
|
buf.writeUInt32BE(lo);
|
|
46
49
|
},
|
|
47
50
|
parseText(v, options) {
|
|
48
|
-
if (options.fetchAsString &&
|
|
51
|
+
if (options.fetchAsString &&
|
|
52
|
+
options.fetchAsString.includes(DataTypeOIDs.timestamp))
|
|
49
53
|
return v;
|
|
50
54
|
return parseDateTime(v, true, false, options.utcDates);
|
|
51
55
|
},
|
|
52
56
|
isType(v) {
|
|
53
57
|
return (v instanceof Date &&
|
|
54
58
|
!(v.getFullYear() === 1970 && v.getMonth() === 0 && v.getDate() === 1) &&
|
|
55
|
-
!(v.getHours() === 0 &&
|
|
59
|
+
!(v.getHours() === 0 &&
|
|
60
|
+
v.getMinutes() === 0 &&
|
|
61
|
+
v.getSeconds() === 0 &&
|
|
62
|
+
v.getMilliseconds() === 0));
|
|
56
63
|
},
|
|
57
64
|
};
|
|
58
65
|
function padZero(v) {
|
|
@@ -7,7 +7,8 @@ export const TimestamptzType = {
|
|
|
7
7
|
oid: DataTypeOIDs.timestamptz,
|
|
8
8
|
jsType: 'Date',
|
|
9
9
|
parseBinary(v, options) {
|
|
10
|
-
const fetchAsString = options.fetchAsString &&
|
|
10
|
+
const fetchAsString = options.fetchAsString &&
|
|
11
|
+
options.fetchAsString.includes(DataTypeOIDs.timestamptz);
|
|
11
12
|
const hi = v.readInt32BE();
|
|
12
13
|
const lo = v.readUInt32BE(4);
|
|
13
14
|
if (lo === 0xffffffff && hi === 0x7fffffff)
|
|
@@ -45,7 +46,8 @@ export const TimestamptzType = {
|
|
|
45
46
|
},
|
|
46
47
|
parseText(v, options) {
|
|
47
48
|
const d = parseDateTime(v, true, true, options.utcDates);
|
|
48
|
-
if (options.fetchAsString &&
|
|
49
|
+
if (options.fetchAsString &&
|
|
50
|
+
options.fetchAsString.includes(DataTypeOIDs.timestamptz)) {
|
|
49
51
|
if (d instanceof Date)
|
|
50
52
|
return dateToTimestamptzString(d);
|
|
51
53
|
if (d === Infinity)
|
package/esm/protocol/backend.js
CHANGED
|
@@ -150,13 +150,17 @@ function parseCopyData(io, code, len) {
|
|
|
150
150
|
}
|
|
151
151
|
function parseCopyResponse(io) {
|
|
152
152
|
const out = {
|
|
153
|
-
overallFormat: io.readUInt8() === 0
|
|
153
|
+
overallFormat: io.readUInt8() === 0
|
|
154
|
+
? Protocol.DataFormat.text
|
|
155
|
+
: Protocol.DataFormat.binary,
|
|
154
156
|
columnCount: io.readUInt16BE(),
|
|
155
157
|
};
|
|
156
158
|
if (out.columnCount) {
|
|
157
159
|
out.columnFormats = [];
|
|
158
160
|
for (let i = 0; i < out.columnCount; i++) {
|
|
159
|
-
out.columnFormats.push(io.readUInt16BE() === 0
|
|
161
|
+
out.columnFormats.push(io.readUInt16BE() === 0
|
|
162
|
+
? Protocol.DataFormat.text
|
|
163
|
+
: Protocol.DataFormat.binary);
|
|
160
164
|
}
|
|
161
165
|
}
|
|
162
166
|
return out;
|
|
@@ -244,7 +248,9 @@ function parseRowDescription(io) {
|
|
|
244
248
|
dataTypeId: io.readInt32BE(),
|
|
245
249
|
fixedSize: io.readInt16BE(),
|
|
246
250
|
modifier: io.readInt32BE(),
|
|
247
|
-
format: io.readInt16BE() === 0
|
|
251
|
+
format: io.readInt16BE() === 0
|
|
252
|
+
? Protocol.DataFormat.text
|
|
253
|
+
: Protocol.DataFormat.binary,
|
|
248
254
|
};
|
|
249
255
|
out.fields.push(field);
|
|
250
256
|
}
|
package/esm/protocol/frontend.js
CHANGED
|
@@ -4,9 +4,27 @@ import { stringifyArrayLiteral } from '../util/stringify-arrayliteral.js';
|
|
|
4
4
|
import { Protocol } from './protocol.js';
|
|
5
5
|
import { SmartBuffer } from './smart-buffer.js';
|
|
6
6
|
const DataFormat = Protocol.DataFormat;
|
|
7
|
-
const StaticFlushBuffer = Buffer.from([
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const StaticFlushBuffer = Buffer.from([
|
|
8
|
+
Protocol.FrontendMessageCode.Flush,
|
|
9
|
+
0x00,
|
|
10
|
+
0x00,
|
|
11
|
+
0x00,
|
|
12
|
+
0x04,
|
|
13
|
+
]);
|
|
14
|
+
const StaticTerminateBuffer = Buffer.from([
|
|
15
|
+
Protocol.FrontendMessageCode.Terminate,
|
|
16
|
+
0x00,
|
|
17
|
+
0x00,
|
|
18
|
+
0x00,
|
|
19
|
+
0x04,
|
|
20
|
+
]);
|
|
21
|
+
const StaticSyncBuffer = Buffer.from([
|
|
22
|
+
Protocol.FrontendMessageCode.Sync,
|
|
23
|
+
0x00,
|
|
24
|
+
0x00,
|
|
25
|
+
0x00,
|
|
26
|
+
0x04,
|
|
27
|
+
]);
|
|
10
28
|
export class Frontend {
|
|
11
29
|
constructor(options) {
|
|
12
30
|
this._io = new SmartBuffer(options?.buffer);
|
|
@@ -29,7 +47,9 @@ export class Frontend {
|
|
|
29
47
|
if (k !== 'client_encoding')
|
|
30
48
|
io.writeCString(k, 'utf8').writeCString(v, 'utf8');
|
|
31
49
|
}
|
|
32
|
-
io.writeCString('client_encoding', 'utf8')
|
|
50
|
+
io.writeCString('client_encoding', 'utf8')
|
|
51
|
+
.writeCString('UTF8', 'utf8')
|
|
52
|
+
.writeUInt8(0);
|
|
33
53
|
return setLengthAndFlush(io, 0);
|
|
34
54
|
}
|
|
35
55
|
getPasswordMessage(password) {
|
|
@@ -86,7 +106,9 @@ export class Frontend {
|
|
|
86
106
|
.writeCString(args.portal || '', 'utf8')
|
|
87
107
|
.writeCString(args.statement || '', 'utf8');
|
|
88
108
|
const { params, paramTypes, queryOptions } = args;
|
|
89
|
-
const columnFormat = queryOptions.columnFormat != null
|
|
109
|
+
const columnFormat = queryOptions.columnFormat != null
|
|
110
|
+
? queryOptions.columnFormat
|
|
111
|
+
: DEFAULT_COLUMN_FORMAT;
|
|
90
112
|
if (params && params.length) {
|
|
91
113
|
io.writeInt16BE(params.length);
|
|
92
114
|
const formatOffset = io.offset;
|
|
@@ -104,7 +126,8 @@ export class Frontend {
|
|
|
104
126
|
const dataTypeOid = paramTypes ? paramTypes[i] : undefined;
|
|
105
127
|
const dt = dataTypeOid ? args.typeMap.get(dataTypeOid) : undefined;
|
|
106
128
|
if (dt) {
|
|
107
|
-
if (typeof dt.encodeAsNull === 'function' &&
|
|
129
|
+
if (typeof dt.encodeAsNull === 'function' &&
|
|
130
|
+
dt.encodeAsNull(v, queryOptions)) {
|
|
108
131
|
io.writeInt32BE(-1);
|
|
109
132
|
continue;
|
|
110
133
|
}
|
|
@@ -125,7 +148,9 @@ export class Frontend {
|
|
|
125
148
|
io.buffer.writeInt32BE(io.length - dataOffset, dataOffset - 4); // Update length
|
|
126
149
|
}
|
|
127
150
|
else if (typeof dt.encodeText === 'function') {
|
|
128
|
-
v = dt.elementsOID
|
|
151
|
+
v = dt.elementsOID
|
|
152
|
+
? stringifyArrayLiteral(v, queryOptions, dt.encodeText)
|
|
153
|
+
: dt.encodeText(v, queryOptions);
|
|
129
154
|
io.writeLString(v, 'utf8');
|
|
130
155
|
}
|
|
131
156
|
}
|
|
@@ -163,7 +188,9 @@ export class Frontend {
|
|
|
163
188
|
}
|
|
164
189
|
getDescribeMessage(args) {
|
|
165
190
|
if (args.name && args.name.length > 63) {
|
|
166
|
-
throw new Error(args.type === 'P'
|
|
191
|
+
throw new Error(args.type === 'P'
|
|
192
|
+
? 'Portal'
|
|
193
|
+
: 'Statement name length must be lower than 63');
|
|
167
194
|
}
|
|
168
195
|
const io = this._io
|
|
169
196
|
.start()
|
|
@@ -174,7 +201,8 @@ export class Frontend {
|
|
|
174
201
|
return setLengthAndFlush(io, 1);
|
|
175
202
|
}
|
|
176
203
|
getExecuteMessage(args) {
|
|
177
|
-
if (args.fetchCount &&
|
|
204
|
+
if (args.fetchCount &&
|
|
205
|
+
(args.fetchCount < 0 || args.fetchCount > 4294967295)) {
|
|
178
206
|
throw new Error('fetchCount can be between 0 and 4294967295');
|
|
179
207
|
}
|
|
180
208
|
const io = this._io
|
|
@@ -187,7 +215,9 @@ export class Frontend {
|
|
|
187
215
|
}
|
|
188
216
|
getCloseMessage(args) {
|
|
189
217
|
if (args.name && args.name.length > 63) {
|
|
190
|
-
throw new Error(args.type === 'P'
|
|
218
|
+
throw new Error(args.type === 'P'
|
|
219
|
+
? 'Portal'
|
|
220
|
+
: 'Statement name length must be lower than 63');
|
|
191
221
|
}
|
|
192
222
|
const io = this._io
|
|
193
223
|
.start()
|
|
@@ -153,7 +153,8 @@ export class PgSocket extends SafeEventEmitter {
|
|
|
153
153
|
this._send(this._frontend.getSyncMessage());
|
|
154
154
|
}
|
|
155
155
|
capture(callback) {
|
|
156
|
-
if (this._state === ConnectionState.CLOSING ||
|
|
156
|
+
if (this._state === ConnectionState.CLOSING ||
|
|
157
|
+
this._state === ConnectionState.CLOSED) {
|
|
157
158
|
return Promise.reject(new Error('Connection closed'));
|
|
158
159
|
}
|
|
159
160
|
if (this._state !== ConnectionState.READY)
|
|
@@ -275,7 +276,9 @@ export class PgSocket extends SafeEventEmitter {
|
|
|
275
276
|
}
|
|
276
277
|
_resolvePassword(cb) {
|
|
277
278
|
(async () => {
|
|
278
|
-
const pass = typeof this.options.password === 'function'
|
|
279
|
+
const pass = typeof this.options.password === 'function'
|
|
280
|
+
? await this.options.password()
|
|
281
|
+
: this.options.password;
|
|
279
282
|
cb(pass || '');
|
|
280
283
|
})().catch(err => this._handleError(err));
|
|
281
284
|
}
|
package/esm/protocol/sasl.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable no-bitwise */
|
|
2
1
|
import crypto from 'crypto';
|
|
3
2
|
export var SASL;
|
|
4
3
|
(function (SASL) {
|
|
@@ -57,7 +56,8 @@ export var SASL;
|
|
|
57
56
|
const serverKey = hmac(saltPass, SERVER_KEY);
|
|
58
57
|
const serverSignatureBytes = hmac(serverKey, authMessage);
|
|
59
58
|
session.serverSignature = serverSignatureBytes.toString('base64');
|
|
60
|
-
session.clientFinalMessage =
|
|
59
|
+
session.clientFinalMessage =
|
|
60
|
+
clientFinalMessageWithoutProof + ',p=' + clientProof;
|
|
61
61
|
}
|
|
62
62
|
SASL.continueSession = continueSession;
|
|
63
63
|
function finalizeSession(session, data) {
|
|
@@ -3,8 +3,7 @@ import { writeBigUInt64BE } from '../util/bigint-methods.js';
|
|
|
3
3
|
import { BufferReader } from './buffer-reader.js';
|
|
4
4
|
export class SmartBuffer extends BufferReader {
|
|
5
5
|
constructor(cfg) {
|
|
6
|
-
|
|
7
|
-
super(Buffer.allocUnsafe((cfg?.pageSize ? parseInt(cfg.pageSize, 10) : 0) || SmartBuffer.DEFAULT_PAGE_SIZE));
|
|
6
|
+
super(Buffer.allocUnsafe(cfg?.pageSize || SmartBuffer.DEFAULT_PAGE_SIZE));
|
|
8
7
|
this._lastHouseKeep = 0;
|
|
9
8
|
this._stMaxPages = 1;
|
|
10
9
|
this._length = 0;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable no-bitwise */
|
|
2
1
|
const big0 = BigInt(0);
|
|
3
2
|
const beAnd = BigInt('0xffffffff');
|
|
4
3
|
const big32 = BigInt(32);
|
|
@@ -12,7 +11,11 @@ export function readBigInt64BE(buf, offset = 0) {
|
|
|
12
11
|
buf[++offset] * 2 ** 16 +
|
|
13
12
|
buf[++offset] * 2 ** 8 +
|
|
14
13
|
buf[++offset];
|
|
15
|
-
return ((BigInt(val) << big32) +
|
|
14
|
+
return ((BigInt(val) << big32) +
|
|
15
|
+
BigInt(buf[++offset] * 2 ** 24 +
|
|
16
|
+
buf[++offset] * 2 ** 16 +
|
|
17
|
+
buf[++offset] * 2 ** 8 +
|
|
18
|
+
last));
|
|
16
19
|
}
|
|
17
20
|
export function writeBigUInt64BE(buf, value, offset = 0) {
|
|
18
21
|
// @ts-ignore
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import merge from '
|
|
1
|
+
import { merge } from '@jsopen/objects';
|
|
2
2
|
import { configFromEnv } from './config-from-env.js';
|
|
3
3
|
export function getConnectionConfig(config) {
|
|
4
4
|
const cfg = configFromEnv();
|
|
@@ -23,7 +23,7 @@ export function parseConnectionString(str) {
|
|
|
23
23
|
if (!str.includes('://'))
|
|
24
24
|
str = 'postgres://' + str;
|
|
25
25
|
const parsed = new URL(str);
|
|
26
|
-
const getFirst = (v) =>
|
|
26
|
+
const getFirst = (v) => typeof v === 'string' ? v : Array.isArray(v) ? v[0] : '';
|
|
27
27
|
const cfg = {};
|
|
28
28
|
cfg.host = decodeURI(parsed.hostname || '');
|
|
29
29
|
if (parsed.port)
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
2
2
|
import { fastParseInt } from './fast-parseint.js';
|
|
3
3
|
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
4
|
-
const TIMESTAMP_PATTERN =
|
|
5
|
-
// eslint-disable-next-line
|
|
6
|
-
/^(\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])?))?)?$/;
|
|
4
|
+
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])?))?)?$/;
|
|
7
5
|
const INFINITY_PATTERN = /^-?infinity$/;
|
|
8
6
|
export function parseDateTime(str, parseTime, parseTimeZone, utc) {
|
|
9
7
|
let m = str.match(TIMESTAMP_PATTERN);
|
|
@@ -13,7 +11,9 @@ export function parseDateTime(str, parseTime, parseTimeZone, utc) {
|
|
|
13
11
|
return Number(str.replace('i', 'I'));
|
|
14
12
|
return new Date('invalid');
|
|
15
13
|
}
|
|
16
|
-
const args = [
|
|
14
|
+
const args = [
|
|
15
|
+
1970, 0, 1, 0, 0, 0, 0,
|
|
16
|
+
];
|
|
17
17
|
const l = parseTime ? 7 : 3;
|
|
18
18
|
for (let i = 0; i < l; i++) {
|
|
19
19
|
const s = m[i + 1];
|
package/esm/util/parse-row.js
CHANGED
|
@@ -2,6 +2,7 @@ export function parseRow(parsers, row, options) {
|
|
|
2
2
|
const l = row.length;
|
|
3
3
|
let i;
|
|
4
4
|
for (i = 0; i < l; i++) {
|
|
5
|
-
row[i] =
|
|
5
|
+
row[i] =
|
|
6
|
+
row[i] == null ? null : parsers[i].call(undefined, row[i], options);
|
|
6
7
|
}
|
|
7
8
|
}
|
package/esm/util/parse-time.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { fastParseInt } from './fast-parseint.js';
|
|
2
|
-
// eslint-disable-next-line
|
|
3
2
|
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
4
3
|
export const STRICT_TIME_PATTERN = /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(?:\.(\d+))?(?:(Z)|(?:([+-])([01]?[0-9]|2[0-3]):?([0-5][0-9])?))?$/;
|
|
5
4
|
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
@@ -8,7 +7,9 @@ export function parseTime(str, parseTimeZone, utc) {
|
|
|
8
7
|
const m = str.match(TIME_PATTERN);
|
|
9
8
|
if (!m)
|
|
10
9
|
return new Date('invalid');
|
|
11
|
-
const args = [
|
|
10
|
+
const args = [
|
|
11
|
+
1970, 0, 1, 0, 0, 0, 0,
|
|
12
|
+
];
|
|
12
13
|
for (let i = 1; i < 4; i++) {
|
|
13
14
|
const s = m[i];
|
|
14
15
|
args[i + 2] = fastParseInt(s) || 0;
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postgrejs",
|
|
3
3
|
"description": "Professional PostgreSQL client NodeJS",
|
|
4
|
-
"version": "2.22.
|
|
4
|
+
"version": "2.22.3",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"
|
|
8
|
+
"@jsopen/objects": "^1.5.0",
|
|
9
|
+
"doublylinked": "^2.5.5",
|
|
9
10
|
"lightning-pool": "^4.10.0",
|
|
10
11
|
"postgres-bytea": "^3.0.0",
|
|
11
12
|
"power-tasks": "^1.11.0",
|
|
12
|
-
"putil-merge": "^3.13.0",
|
|
13
13
|
"putil-promisify": "^1.10.1",
|
|
14
14
|
"putil-varhelpers": "^1.6.5",
|
|
15
15
|
"tslib": "^2.8.1"
|