postgrejs 2.16.0 → 2.17.1
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 +15 -0
- package/esm/connection/bind-param.js +1 -5
- package/esm/connection/connection.js +16 -20
- package/esm/connection/cursor.js +10 -15
- package/esm/connection/intl-connection.js +41 -46
- package/esm/connection/pool.js +28 -32
- package/esm/connection/portal.js +27 -31
- package/esm/connection/prepared-statement.js +31 -35
- package/esm/constants.js +122 -125
- package/esm/data-type-map.js +71 -75
- package/esm/data-types/bool-type.js +7 -10
- package/esm/data-types/box-type.js +7 -10
- package/esm/data-types/bytea-type.js +9 -13
- package/esm/data-types/char-type.js +7 -10
- package/esm/data-types/circle-type.js +7 -10
- package/esm/data-types/date-type.js +12 -15
- package/esm/data-types/float4-type.js +7 -10
- package/esm/data-types/float8-type.js +7 -10
- package/esm/data-types/int2-type.js +10 -13
- package/esm/data-types/int2-vector-type.js +13 -16
- package/esm/data-types/int4-type.js +10 -13
- package/esm/data-types/int8-type.js +9 -12
- package/esm/data-types/json-type.js +9 -12
- package/esm/data-types/jsonb-type.js +11 -14
- package/esm/data-types/lseg-type.js +7 -10
- package/esm/data-types/numeric-type.js +8 -12
- package/esm/data-types/oid-type.js +15 -18
- package/esm/data-types/point-type.js +7 -10
- package/esm/data-types/time-type.js +13 -16
- package/esm/data-types/timestamp-type.js +12 -15
- package/esm/data-types/timestamptz-type.js +12 -15
- package/esm/data-types/uuid-type.js +7 -10
- package/esm/data-types/varchar-type.js +7 -10
- package/esm/index.js +25 -28
- package/esm/interfaces/command-result.js +1 -2
- package/esm/interfaces/data-mapping-options.js +1 -2
- package/esm/interfaces/data-type.js +1 -2
- package/esm/interfaces/database-connection-params.js +1 -2
- package/esm/interfaces/field-info.js +1 -2
- package/esm/interfaces/query-options.js +1 -2
- package/esm/interfaces/query-result.js +1 -2
- package/esm/interfaces/script-execute-options.js +1 -2
- package/esm/interfaces/script-result.js +1 -2
- package/esm/interfaces/statement-prepare-options.js +1 -2
- package/esm/protocol/backend.js +24 -28
- package/esm/protocol/buffer-reader.js +1 -5
- package/esm/protocol/database-error.js +1 -5
- package/esm/protocol/frontend.js +27 -31
- package/esm/protocol/pg-socket.js +48 -53
- package/esm/protocol/protocol.js +2 -5
- package/esm/protocol/sasl.js +7 -11
- package/esm/protocol/smart-buffer.js +5 -10
- package/esm/safe-event-emitter.js +2 -6
- package/esm/types.js +1 -2
- package/esm/util/array-calculatedim.js +1 -4
- package/esm/util/bigint-methods.js +2 -6
- package/esm/util/config-from-env.js +5 -8
- package/esm/util/connection-config.js +8 -13
- package/esm/util/convert-row-to-object.js +1 -4
- package/esm/util/decode-binaryarray.js +3 -6
- package/esm/util/encode-binaryarray.js +5 -8
- package/esm/util/escape-literal.js +1 -4
- package/esm/util/fast-parseint.js +1 -4
- package/esm/util/get-parsers.js +8 -11
- package/esm/util/parse-array.js +1 -4
- package/esm/util/parse-datetime.js +5 -8
- package/esm/util/parse-row.js +1 -4
- package/esm/util/parse-time.js +8 -12
- package/esm/util/stringify-arrayliteral.js +3 -6
- package/esm/util/stringify-for-sql.js +8 -12
- package/esm/util/wrap-row-description.js +6 -9
- package/package.json +3 -3
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ArrayTimeType = exports.TimeType = void 0;
|
|
4
|
-
const constants_js_1 = require("../constants.js");
|
|
5
|
-
const parse_time_js_1 = require("../util/parse-time.js");
|
|
1
|
+
import { DataTypeOIDs } from '../constants.js';
|
|
2
|
+
import { parseTime, STRICT_TIME_PATTERN } from '../util/parse-time.js';
|
|
6
3
|
const timeMul = 4294967296;
|
|
7
|
-
|
|
4
|
+
export const TimeType = {
|
|
8
5
|
name: 'time',
|
|
9
|
-
oid:
|
|
6
|
+
oid: DataTypeOIDs.time,
|
|
10
7
|
jsType: 'string',
|
|
11
8
|
parseBinary(v, options) {
|
|
12
|
-
const fetchAsString = options.fetchAsString && options.fetchAsString.includes(
|
|
9
|
+
const fetchAsString = options.fetchAsString && options.fetchAsString.includes(DataTypeOIDs.time);
|
|
13
10
|
const hi = v.readInt32BE();
|
|
14
11
|
const lo = v.readUInt32BE(4);
|
|
15
12
|
let d = new Date((lo + hi * timeMul) / 1000);
|
|
@@ -20,7 +17,7 @@ exports.TimeType = {
|
|
|
20
17
|
},
|
|
21
18
|
encodeBinary(buf, v, options) {
|
|
22
19
|
if (typeof v === 'string')
|
|
23
|
-
v =
|
|
20
|
+
v = parseTime(v, false, options.utcDates);
|
|
24
21
|
if (!(v instanceof Date))
|
|
25
22
|
v = new Date(v);
|
|
26
23
|
// Postgresql ignores timezone data so we are
|
|
@@ -32,13 +29,13 @@ exports.TimeType = {
|
|
|
32
29
|
buf.writeUInt32BE(lo);
|
|
33
30
|
},
|
|
34
31
|
parseText(v, options) {
|
|
35
|
-
if (options.fetchAsString && options.fetchAsString.includes(
|
|
32
|
+
if (options.fetchAsString && options.fetchAsString.includes(DataTypeOIDs.time))
|
|
36
33
|
return v;
|
|
37
|
-
return
|
|
34
|
+
return parseTime(v, false, options.utcDates);
|
|
38
35
|
},
|
|
39
36
|
isType(v) {
|
|
40
37
|
return ((v instanceof Date && v.getFullYear() === 1970 && v.getMonth() === 0 && v.getDate() === 1) ||
|
|
41
|
-
(typeof v === 'string' &&
|
|
38
|
+
(typeof v === 'string' && STRICT_TIME_PATTERN.test(v)));
|
|
42
39
|
},
|
|
43
40
|
};
|
|
44
41
|
function padZero(v) {
|
|
@@ -47,9 +44,9 @@ function padZero(v) {
|
|
|
47
44
|
function dateToTimeString(d) {
|
|
48
45
|
return padZero(d.getHours()) + ':' + padZero(d.getMinutes()) + ':' + padZero(d.getSeconds());
|
|
49
46
|
}
|
|
50
|
-
|
|
51
|
-
...
|
|
47
|
+
export const ArrayTimeType = {
|
|
48
|
+
...TimeType,
|
|
52
49
|
name: '_time',
|
|
53
|
-
oid:
|
|
54
|
-
elementsOID:
|
|
50
|
+
oid: DataTypeOIDs._time,
|
|
51
|
+
elementsOID: DataTypeOIDs.time,
|
|
55
52
|
};
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ArrayTimestampType = exports.TimestampType = void 0;
|
|
4
|
-
const constants_js_1 = require("../constants.js");
|
|
5
|
-
const parse_datetime_js_1 = require("../util/parse-datetime.js");
|
|
1
|
+
import { DataTypeOIDs } from '../constants.js';
|
|
2
|
+
import { parseDateTime } from '../util/parse-datetime.js';
|
|
6
3
|
const timeShift = 946684800000;
|
|
7
4
|
const timeMul = 4294967296;
|
|
8
|
-
|
|
5
|
+
export const TimestampType = {
|
|
9
6
|
name: 'timestamp',
|
|
10
|
-
oid:
|
|
7
|
+
oid: DataTypeOIDs.timestamp,
|
|
11
8
|
jsType: 'Date',
|
|
12
9
|
parseBinary(v, options) {
|
|
13
|
-
const fetchAsString = options.fetchAsString && options.fetchAsString.includes(
|
|
10
|
+
const fetchAsString = options.fetchAsString && options.fetchAsString.includes(DataTypeOIDs.timestamp);
|
|
14
11
|
const hi = v.readInt32BE();
|
|
15
12
|
const lo = v.readUInt32BE(4);
|
|
16
13
|
if (lo === 0xffffffff && hi === 0x7fffffff)
|
|
@@ -26,7 +23,7 @@ exports.TimestampType = {
|
|
|
26
23
|
},
|
|
27
24
|
encodeBinary(buf, v, options) {
|
|
28
25
|
if (typeof v === 'string')
|
|
29
|
-
v =
|
|
26
|
+
v = parseDateTime(v, true, false, options.utcDates);
|
|
30
27
|
if (v === Infinity) {
|
|
31
28
|
buf.writeInt32BE(0x7fffffff); // hi
|
|
32
29
|
buf.writeUInt32BE(0xffffffff); // lo
|
|
@@ -48,9 +45,9 @@ exports.TimestampType = {
|
|
|
48
45
|
buf.writeUInt32BE(lo);
|
|
49
46
|
},
|
|
50
47
|
parseText(v, options) {
|
|
51
|
-
if (options.fetchAsString && options.fetchAsString.includes(
|
|
48
|
+
if (options.fetchAsString && options.fetchAsString.includes(DataTypeOIDs.timestamp))
|
|
52
49
|
return v;
|
|
53
|
-
return
|
|
50
|
+
return parseDateTime(v, true, false, options.utcDates);
|
|
54
51
|
},
|
|
55
52
|
isType(v) {
|
|
56
53
|
return (v instanceof Date &&
|
|
@@ -74,9 +71,9 @@ function dateToTimestampString(d) {
|
|
|
74
71
|
':' +
|
|
75
72
|
padZero(d.getSeconds()));
|
|
76
73
|
}
|
|
77
|
-
|
|
78
|
-
...
|
|
74
|
+
export const ArrayTimestampType = {
|
|
75
|
+
...TimestampType,
|
|
79
76
|
name: '_timestamp',
|
|
80
|
-
oid:
|
|
81
|
-
elementsOID:
|
|
77
|
+
oid: DataTypeOIDs._timestamp,
|
|
78
|
+
elementsOID: DataTypeOIDs.timestamp,
|
|
82
79
|
};
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ArrayTimestamptzType = exports.TimestamptzType = void 0;
|
|
4
|
-
const constants_js_1 = require("../constants.js");
|
|
5
|
-
const parse_datetime_js_1 = require("../util/parse-datetime.js");
|
|
1
|
+
import { DataTypeOIDs } from '../constants.js';
|
|
2
|
+
import { parseDateTime } from '../util/parse-datetime.js';
|
|
6
3
|
const timeShift = 946684800000;
|
|
7
4
|
const timeMul = 4294967296;
|
|
8
|
-
|
|
5
|
+
export const TimestamptzType = {
|
|
9
6
|
name: 'timestamptz',
|
|
10
|
-
oid:
|
|
7
|
+
oid: DataTypeOIDs.timestamptz,
|
|
11
8
|
jsType: 'Date',
|
|
12
9
|
parseBinary(v, options) {
|
|
13
|
-
const fetchAsString = options.fetchAsString && options.fetchAsString.includes(
|
|
10
|
+
const fetchAsString = options.fetchAsString && options.fetchAsString.includes(DataTypeOIDs.timestamptz);
|
|
14
11
|
const hi = v.readInt32BE();
|
|
15
12
|
const lo = v.readUInt32BE(4);
|
|
16
13
|
if (lo === 0xffffffff && hi === 0x7fffffff)
|
|
@@ -26,7 +23,7 @@ exports.TimestamptzType = {
|
|
|
26
23
|
},
|
|
27
24
|
encodeBinary(buf, v, options) {
|
|
28
25
|
if (typeof v === 'string')
|
|
29
|
-
v =
|
|
26
|
+
v = parseDateTime(v, true, true, options.utcDates);
|
|
30
27
|
if (v === Infinity) {
|
|
31
28
|
buf.writeInt32BE(0x7fffffff); // hi
|
|
32
29
|
buf.writeUInt32BE(0xffffffff); // lo
|
|
@@ -47,8 +44,8 @@ exports.TimestamptzType = {
|
|
|
47
44
|
buf.writeUInt32BE(lo);
|
|
48
45
|
},
|
|
49
46
|
parseText(v, options) {
|
|
50
|
-
const d =
|
|
51
|
-
if (options.fetchAsString && options.fetchAsString.includes(
|
|
47
|
+
const d = parseDateTime(v, true, true, options.utcDates);
|
|
48
|
+
if (options.fetchAsString && options.fetchAsString.includes(DataTypeOIDs.timestamptz)) {
|
|
52
49
|
if (d instanceof Date)
|
|
53
50
|
return dateToTimestamptzString(d);
|
|
54
51
|
if (d === Infinity)
|
|
@@ -66,9 +63,9 @@ exports.TimestamptzType = {
|
|
|
66
63
|
function dateToTimestamptzString(d) {
|
|
67
64
|
return d.toISOString().replace('T', ' ');
|
|
68
65
|
}
|
|
69
|
-
|
|
70
|
-
...
|
|
66
|
+
export const ArrayTimestamptzType = {
|
|
67
|
+
...TimestamptzType,
|
|
71
68
|
name: '_timestamptz',
|
|
72
|
-
oid:
|
|
73
|
-
elementsOID:
|
|
69
|
+
oid: DataTypeOIDs._timestamptz,
|
|
70
|
+
elementsOID: DataTypeOIDs.timestamptz,
|
|
74
71
|
};
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ArrayUuidType = exports.UuidType = void 0;
|
|
4
|
-
const constants_js_1 = require("../constants.js");
|
|
1
|
+
import { DataTypeOIDs } from '../constants.js';
|
|
5
2
|
const GUID_PATTERN = /^[0-9a-fA-F]{8}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{12}$/;
|
|
6
|
-
|
|
3
|
+
export const UuidType = {
|
|
7
4
|
name: 'uuid',
|
|
8
|
-
oid:
|
|
5
|
+
oid: DataTypeOIDs.uuid,
|
|
9
6
|
jsType: 'String',
|
|
10
7
|
parseBinary(v) {
|
|
11
8
|
return (v.toString('hex', 0, 4) +
|
|
@@ -31,9 +28,9 @@ exports.UuidType = {
|
|
|
31
28
|
return typeof v === 'string' && GUID_PATTERN.test(v);
|
|
32
29
|
},
|
|
33
30
|
};
|
|
34
|
-
|
|
35
|
-
...
|
|
31
|
+
export const ArrayUuidType = {
|
|
32
|
+
...UuidType,
|
|
36
33
|
name: '_uuid',
|
|
37
|
-
oid:
|
|
38
|
-
elementsOID:
|
|
34
|
+
oid: DataTypeOIDs._uuid,
|
|
35
|
+
elementsOID: DataTypeOIDs.uuid,
|
|
39
36
|
};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ArrayVarcharType = exports.VarcharType = void 0;
|
|
4
|
-
const constants_js_1 = require("../constants.js");
|
|
5
|
-
exports.VarcharType = {
|
|
1
|
+
import { DataTypeOIDs } from '../constants.js';
|
|
2
|
+
export const VarcharType = {
|
|
6
3
|
name: 'varchar',
|
|
7
|
-
oid:
|
|
4
|
+
oid: DataTypeOIDs.varchar,
|
|
8
5
|
jsType: 'string',
|
|
9
6
|
parseBinary(v) {
|
|
10
7
|
return v.toString('utf8');
|
|
@@ -19,9 +16,9 @@ exports.VarcharType = {
|
|
|
19
16
|
return typeof v === 'string';
|
|
20
17
|
},
|
|
21
18
|
};
|
|
22
|
-
|
|
23
|
-
...
|
|
19
|
+
export const ArrayVarcharType = {
|
|
20
|
+
...VarcharType,
|
|
24
21
|
name: '_varchar',
|
|
25
|
-
oid:
|
|
26
|
-
elementsOID:
|
|
22
|
+
oid: DataTypeOIDs._varchar,
|
|
23
|
+
elementsOID: DataTypeOIDs.varchar,
|
|
27
24
|
};
|
package/esm/index.js
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
tslib_1.__exportStar(require("./util/parse-datetime.js"), exports);
|
|
27
|
-
tslib_1.__exportStar(require("./util/stringify-arrayliteral.js"), exports);
|
|
28
|
-
tslib_1.__exportStar(require("./util/stringify-for-sql.js"), exports);
|
|
1
|
+
export * from './connection/bind-param.js';
|
|
2
|
+
export * from './connection/connection.js';
|
|
3
|
+
export * from './connection/cursor.js';
|
|
4
|
+
export * from './connection/pool.js';
|
|
5
|
+
export * from './connection/prepared-statement.js';
|
|
6
|
+
export * from './constants.js';
|
|
7
|
+
export * from './data-type-map.js';
|
|
8
|
+
export * from './interfaces/command-result.js';
|
|
9
|
+
export * from './interfaces/data-mapping-options.js';
|
|
10
|
+
export * from './interfaces/data-type.js';
|
|
11
|
+
export * from './interfaces/database-connection-params.js';
|
|
12
|
+
export * from './interfaces/field-info.js';
|
|
13
|
+
export * from './interfaces/query-options.js';
|
|
14
|
+
export * from './interfaces/query-result.js';
|
|
15
|
+
export * from './interfaces/script-execute-options.js';
|
|
16
|
+
export * from './interfaces/script-result.js';
|
|
17
|
+
export * from './interfaces/statement-prepare-options.js';
|
|
18
|
+
export * from './protocol/database-error.js';
|
|
19
|
+
export * from './protocol/smart-buffer.js';
|
|
20
|
+
export * from './types.js';
|
|
21
|
+
export * from './util/connection-config.js';
|
|
22
|
+
export * from './util/escape-literal.js';
|
|
23
|
+
export * from './util/parse-datetime.js';
|
|
24
|
+
export * from './util/stringify-arrayliteral.js';
|
|
25
|
+
export * from './util/stringify-for-sql.js';
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/esm/protocol/backend.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Backend = void 0;
|
|
4
|
-
const buffer_reader_js_1 = require("./buffer-reader.js");
|
|
5
|
-
const protocol_js_1 = require("./protocol.js");
|
|
1
|
+
import { BufferReader } from './buffer-reader.js';
|
|
2
|
+
import { Protocol } from './protocol.js';
|
|
6
3
|
// 1 byte message type, 4 byte frame length
|
|
7
4
|
const HEADER_LENGTH = 5;
|
|
8
5
|
const ErrorFieldTypes = {
|
|
@@ -25,7 +22,7 @@ const ErrorFieldTypes = {
|
|
|
25
22
|
L: 'line',
|
|
26
23
|
R: 'routine',
|
|
27
24
|
};
|
|
28
|
-
class Backend {
|
|
25
|
+
export class Backend {
|
|
29
26
|
reset() {
|
|
30
27
|
this._buf = undefined;
|
|
31
28
|
}
|
|
@@ -34,7 +31,7 @@ class Backend {
|
|
|
34
31
|
data = Buffer.concat([this._buf, data]);
|
|
35
32
|
this._buf = undefined;
|
|
36
33
|
}
|
|
37
|
-
const io = new
|
|
34
|
+
const io = new BufferReader(data);
|
|
38
35
|
let offsetBookmark;
|
|
39
36
|
while (io.length - io.offset >= HEADER_LENGTH) {
|
|
40
37
|
offsetBookmark = io.offset;
|
|
@@ -56,25 +53,24 @@ class Backend {
|
|
|
56
53
|
this._buf = io.readBuffer(io.length - io.offset);
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
|
-
exports.Backend = Backend;
|
|
60
56
|
const MessageParsers = {
|
|
61
|
-
[
|
|
62
|
-
[
|
|
63
|
-
[
|
|
64
|
-
[
|
|
65
|
-
[
|
|
66
|
-
[
|
|
67
|
-
[
|
|
68
|
-
[
|
|
69
|
-
[
|
|
70
|
-
[
|
|
71
|
-
[
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
[
|
|
75
|
-
[
|
|
76
|
-
[
|
|
77
|
-
[
|
|
57
|
+
[Protocol.BackendMessageCode.Authentication]: parseAuthentication,
|
|
58
|
+
[Protocol.BackendMessageCode.BackendKeyData]: parseBackendKeyData,
|
|
59
|
+
[Protocol.BackendMessageCode.CommandComplete]: parseCommandComplete,
|
|
60
|
+
[Protocol.BackendMessageCode.CopyData]: parseCopyData,
|
|
61
|
+
[Protocol.BackendMessageCode.CopyInResponse]: parseCopyResponse,
|
|
62
|
+
[Protocol.BackendMessageCode.CopyOutResponse]: parseCopyResponse,
|
|
63
|
+
[Protocol.BackendMessageCode.CopyBothResponse]: parseCopyResponse,
|
|
64
|
+
[Protocol.BackendMessageCode.DataRow]: parseDataRow,
|
|
65
|
+
[Protocol.BackendMessageCode.ErrorResponse]: parseErrorResponse,
|
|
66
|
+
[Protocol.BackendMessageCode.NoticeResponse]: parseErrorResponse,
|
|
67
|
+
[Protocol.BackendMessageCode.NotificationResponse]: parseNotificationResponse,
|
|
68
|
+
[Protocol.BackendMessageCode.FunctionCallResponse]: parseFunctionCallResponse,
|
|
69
|
+
[Protocol.BackendMessageCode.NegotiateProtocolVersion]: parseNegotiateProtocolVersion,
|
|
70
|
+
[Protocol.BackendMessageCode.ParameterDescription]: parseParameterDescription,
|
|
71
|
+
[Protocol.BackendMessageCode.ParameterStatus]: parseParameterStatus,
|
|
72
|
+
[Protocol.BackendMessageCode.ReadyForQuery]: parseReadyForQuery,
|
|
73
|
+
[Protocol.BackendMessageCode.RowDescription]: parseRowDescription,
|
|
78
74
|
};
|
|
79
75
|
function parseAuthentication(io, code, len) {
|
|
80
76
|
const kind = io.readUInt32BE();
|
|
@@ -154,13 +150,13 @@ function parseCopyData(io, code, len) {
|
|
|
154
150
|
}
|
|
155
151
|
function parseCopyResponse(io) {
|
|
156
152
|
const out = {
|
|
157
|
-
overallFormat: io.readUInt8() === 0 ?
|
|
153
|
+
overallFormat: io.readUInt8() === 0 ? Protocol.DataFormat.text : Protocol.DataFormat.binary,
|
|
158
154
|
columnCount: io.readUInt16BE(),
|
|
159
155
|
};
|
|
160
156
|
if (out.columnCount) {
|
|
161
157
|
out.columnFormats = [];
|
|
162
158
|
for (let i = 0; i < out.columnCount; i++) {
|
|
163
|
-
out.columnFormats.push(io.readUInt16BE() === 0 ?
|
|
159
|
+
out.columnFormats.push(io.readUInt16BE() === 0 ? Protocol.DataFormat.text : Protocol.DataFormat.binary);
|
|
164
160
|
}
|
|
165
161
|
}
|
|
166
162
|
return out;
|
|
@@ -248,7 +244,7 @@ function parseRowDescription(io) {
|
|
|
248
244
|
dataTypeId: io.readInt32BE(),
|
|
249
245
|
fixedSize: io.readInt16BE(),
|
|
250
246
|
modifier: io.readInt32BE(),
|
|
251
|
-
format: io.readInt16BE() === 0 ?
|
|
247
|
+
format: io.readInt16BE() === 0 ? Protocol.DataFormat.text : Protocol.DataFormat.binary,
|
|
252
248
|
};
|
|
253
249
|
out.fields.push(field);
|
|
254
250
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BufferReader = void 0;
|
|
4
|
-
class BufferReader {
|
|
1
|
+
export class BufferReader {
|
|
5
2
|
constructor(buffer) {
|
|
6
3
|
this.offset = 0;
|
|
7
4
|
this.buffer = buffer;
|
|
@@ -75,4 +72,3 @@ class BufferReader {
|
|
|
75
72
|
throw new Error('Eof in buffer detected');
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
|
-
exports.BufferReader = BufferReader;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DatabaseError = void 0;
|
|
4
|
-
class DatabaseError extends Error {
|
|
1
|
+
export class DatabaseError extends Error {
|
|
5
2
|
constructor(msg) {
|
|
6
3
|
super(msg.message);
|
|
7
4
|
Object.assign(this, {
|
|
@@ -14,4 +11,3 @@ class DatabaseError extends Error {
|
|
|
14
11
|
this.position = parseInt(msg.position, 10) || undefined;
|
|
15
12
|
}
|
|
16
13
|
}
|
|
17
|
-
exports.DatabaseError = DatabaseError;
|
package/esm/protocol/frontend.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const StaticTerminateBuffer = Buffer.from([protocol_js_1.Protocol.FrontendMessageCode.Terminate, 0x00, 0x00, 0x00, 0x04]);
|
|
12
|
-
const StaticSyncBuffer = Buffer.from([protocol_js_1.Protocol.FrontendMessageCode.Sync, 0x00, 0x00, 0x00, 0x04]);
|
|
13
|
-
class Frontend {
|
|
1
|
+
import { DEFAULT_COLUMN_FORMAT } from '../constants.js';
|
|
2
|
+
import { encodeBinaryArray } from '../util/encode-binaryarray.js';
|
|
3
|
+
import { stringifyArrayLiteral } from '../util/stringify-arrayliteral.js';
|
|
4
|
+
import { Protocol } from './protocol.js';
|
|
5
|
+
import { SmartBuffer } from './smart-buffer.js';
|
|
6
|
+
const DataFormat = Protocol.DataFormat;
|
|
7
|
+
const StaticFlushBuffer = Buffer.from([Protocol.FrontendMessageCode.Flush, 0x00, 0x00, 0x00, 0x04]);
|
|
8
|
+
const StaticTerminateBuffer = Buffer.from([Protocol.FrontendMessageCode.Terminate, 0x00, 0x00, 0x00, 0x04]);
|
|
9
|
+
const StaticSyncBuffer = Buffer.from([Protocol.FrontendMessageCode.Sync, 0x00, 0x00, 0x00, 0x04]);
|
|
10
|
+
export class Frontend {
|
|
14
11
|
constructor(options) {
|
|
15
|
-
this._io = new
|
|
12
|
+
this._io = new SmartBuffer(options?.buffer);
|
|
16
13
|
}
|
|
17
14
|
getSSLRequestMessage() {
|
|
18
15
|
return this._io
|
|
@@ -26,8 +23,8 @@ class Frontend {
|
|
|
26
23
|
const io = this._io
|
|
27
24
|
.start()
|
|
28
25
|
.writeInt32BE(0) // Preserve length
|
|
29
|
-
.writeInt16BE(
|
|
30
|
-
.writeInt16BE(
|
|
26
|
+
.writeInt16BE(Protocol.VERSION_MAJOR)
|
|
27
|
+
.writeInt16BE(Protocol.VERSION_MINOR);
|
|
31
28
|
for (const [k, v] of Object.entries(args)) {
|
|
32
29
|
if (k !== 'client_encoding')
|
|
33
30
|
io.writeCString(k, 'utf8').writeCString(v, 'utf8');
|
|
@@ -38,7 +35,7 @@ class Frontend {
|
|
|
38
35
|
getPasswordMessage(password) {
|
|
39
36
|
const io = this._io
|
|
40
37
|
.start()
|
|
41
|
-
.writeInt8(
|
|
38
|
+
.writeInt8(Protocol.FrontendMessageCode.PasswordMessage)
|
|
42
39
|
.writeInt32BE(0) // Preserve header
|
|
43
40
|
.writeCString(password, 'utf8');
|
|
44
41
|
return setLengthAndFlush(io, 1);
|
|
@@ -46,7 +43,7 @@ class Frontend {
|
|
|
46
43
|
getSASLMessage(sasl) {
|
|
47
44
|
const io = this._io
|
|
48
45
|
.start()
|
|
49
|
-
.writeInt8(
|
|
46
|
+
.writeInt8(Protocol.FrontendMessageCode.PasswordMessage)
|
|
50
47
|
.writeInt32BE(0) // Preserve header
|
|
51
48
|
.writeCString(sasl.mechanism, 'utf8')
|
|
52
49
|
.writeLString(sasl.clientFirstMessage);
|
|
@@ -55,7 +52,7 @@ class Frontend {
|
|
|
55
52
|
getSASLFinalMessage(session) {
|
|
56
53
|
const io = this._io
|
|
57
54
|
.start()
|
|
58
|
-
.writeInt8(
|
|
55
|
+
.writeInt8(Protocol.FrontendMessageCode.PasswordMessage)
|
|
59
56
|
.writeInt32BE(0) // Preserve header
|
|
60
57
|
.writeString(session.clientFinalMessage);
|
|
61
58
|
return setLengthAndFlush(io, 1);
|
|
@@ -65,7 +62,7 @@ class Frontend {
|
|
|
65
62
|
throw new Error('Query name length must be lower than 63');
|
|
66
63
|
const io = this._io
|
|
67
64
|
.start()
|
|
68
|
-
.writeInt8(
|
|
65
|
+
.writeInt8(Protocol.FrontendMessageCode.Parse)
|
|
69
66
|
.writeInt32BE(0) // Preserve header
|
|
70
67
|
.writeCString(args.statement || '', 'utf8')
|
|
71
68
|
.writeCString(args.sql, 'utf8')
|
|
@@ -84,12 +81,12 @@ class Frontend {
|
|
|
84
81
|
throw new Error('Query name length must be lower than 63');
|
|
85
82
|
const io = this._io
|
|
86
83
|
.start()
|
|
87
|
-
.writeInt8(
|
|
84
|
+
.writeInt8(Protocol.FrontendMessageCode.Bind)
|
|
88
85
|
.writeInt32BE(0) // Preserve header
|
|
89
86
|
.writeCString(args.portal || '', 'utf8')
|
|
90
87
|
.writeCString(args.statement || '', 'utf8');
|
|
91
88
|
const { params, paramTypes, queryOptions } = args;
|
|
92
|
-
const columnFormat = queryOptions.columnFormat != null ? queryOptions.columnFormat :
|
|
89
|
+
const columnFormat = queryOptions.columnFormat != null ? queryOptions.columnFormat : DEFAULT_COLUMN_FORMAT;
|
|
93
90
|
if (params && params.length) {
|
|
94
91
|
io.writeInt16BE(params.length);
|
|
95
92
|
const formatOffset = io.offset;
|
|
@@ -109,14 +106,14 @@ class Frontend {
|
|
|
109
106
|
if (dt) {
|
|
110
107
|
if (typeof dt.encodeBinary === 'function') {
|
|
111
108
|
// Set param format to binary
|
|
112
|
-
io.buffer.writeInt16BE(
|
|
109
|
+
io.buffer.writeInt16BE(Protocol.DataFormat.binary, formatOffset + i * 2);
|
|
113
110
|
// Preserve data length
|
|
114
111
|
io.writeInt32BE(0);
|
|
115
112
|
const dataOffset = io.offset;
|
|
116
113
|
if (dt.elementsOID) {
|
|
117
114
|
// If data type is array
|
|
118
115
|
v = Array.isArray(v) ? v : [v];
|
|
119
|
-
|
|
116
|
+
encodeBinaryArray(io, v, dt.elementsOID, queryOptions, dt.encodeBinary, dt.encodeCalculateDim);
|
|
120
117
|
}
|
|
121
118
|
else {
|
|
122
119
|
dt.encodeBinary(io, v, queryOptions);
|
|
@@ -124,13 +121,13 @@ class Frontend {
|
|
|
124
121
|
io.buffer.writeInt32BE(io.length - dataOffset, dataOffset - 4); // Update length
|
|
125
122
|
}
|
|
126
123
|
else if (typeof dt.encodeText === 'function') {
|
|
127
|
-
v = dt.elementsOID ?
|
|
124
|
+
v = dt.elementsOID ? stringifyArrayLiteral(v, queryOptions, dt.encodeText) : dt.encodeText(v, queryOptions);
|
|
128
125
|
io.writeLString(v, 'utf8');
|
|
129
126
|
}
|
|
130
127
|
}
|
|
131
128
|
else if (Buffer.isBuffer(v)) {
|
|
132
129
|
// Set param format to binary
|
|
133
|
-
io.buffer.writeInt16BE(
|
|
130
|
+
io.buffer.writeInt16BE(Protocol.DataFormat.binary, formatOffset + i * 2);
|
|
134
131
|
// Preserve data length
|
|
135
132
|
io.writeInt32BE(0);
|
|
136
133
|
const dataOffset = io.offset;
|
|
@@ -166,7 +163,7 @@ class Frontend {
|
|
|
166
163
|
}
|
|
167
164
|
const io = this._io
|
|
168
165
|
.start()
|
|
169
|
-
.writeInt8(
|
|
166
|
+
.writeInt8(Protocol.FrontendMessageCode.Describe)
|
|
170
167
|
.writeInt32BE(0) // Preserve header
|
|
171
168
|
.writeUInt8(args.type.charCodeAt(0))
|
|
172
169
|
.writeCString(args.name || '', 'utf8');
|
|
@@ -178,7 +175,7 @@ class Frontend {
|
|
|
178
175
|
}
|
|
179
176
|
const io = this._io
|
|
180
177
|
.start()
|
|
181
|
-
.writeInt8(
|
|
178
|
+
.writeInt8(Protocol.FrontendMessageCode.Execute)
|
|
182
179
|
.writeInt32BE(0) // Preserve header
|
|
183
180
|
.writeCString(args.portal || '', 'utf8')
|
|
184
181
|
.writeUInt32BE(args.fetchCount || 0);
|
|
@@ -190,7 +187,7 @@ class Frontend {
|
|
|
190
187
|
}
|
|
191
188
|
const io = this._io
|
|
192
189
|
.start()
|
|
193
|
-
.writeInt8(
|
|
190
|
+
.writeInt8(Protocol.FrontendMessageCode.Close)
|
|
194
191
|
.writeInt32BE(0) // Preserve header
|
|
195
192
|
.writeUInt8(args.type.charCodeAt(0))
|
|
196
193
|
.writeCString(args.name || '', 'utf8');
|
|
@@ -199,7 +196,7 @@ class Frontend {
|
|
|
199
196
|
getQueryMessage(sql) {
|
|
200
197
|
const io = this._io
|
|
201
198
|
.start()
|
|
202
|
-
.writeInt8(
|
|
199
|
+
.writeInt8(Protocol.FrontendMessageCode.Query)
|
|
203
200
|
.writeInt32BE(0) // Preserve header
|
|
204
201
|
.writeCString(sql || '', 'utf8');
|
|
205
202
|
return setLengthAndFlush(io, 1);
|
|
@@ -214,7 +211,6 @@ class Frontend {
|
|
|
214
211
|
return StaticSyncBuffer;
|
|
215
212
|
}
|
|
216
213
|
}
|
|
217
|
-
exports.Frontend = Frontend;
|
|
218
214
|
function setLengthAndFlush(io, lengthOffset) {
|
|
219
215
|
io.buffer.writeUInt32BE(io.length - lengthOffset, lengthOffset);
|
|
220
216
|
return io.flush();
|