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.
- package/CHANGELOG.md +8 -1
- package/{esm/connection → connection}/bind-param.js +2 -0
- package/{esm/connection → connection}/connection.js +4 -2
- package/{esm/connection → connection}/cursor.js +8 -3
- package/{esm/connection → connection}/intl-connection.js +6 -3
- package/{esm/connection → connection}/pool.js +4 -1
- package/{esm/connection → connection}/portal.js +3 -1
- package/{esm/connection → connection}/prepared-statement.js +6 -3
- package/{esm/constants.js → constants.js} +1 -1
- package/{esm/data-type-map.js → data-type-map.js} +2 -2
- package/package.json +12 -31
- package/{esm/protocol → protocol}/backend.js +1 -0
- package/{esm/protocol → protocol}/buffer-reader.js +2 -1
- package/{esm/protocol → protocol}/database-error.js +16 -0
- package/{esm/protocol → protocol}/frontend.js +1 -0
- package/{esm/protocol → protocol}/pg-socket.js +9 -3
- package/{esm/protocol → protocol}/smart-buffer.js +9 -5
- package/{esm/util → util}/bigint-methods.js +1 -0
- package/cjs/connection/bind-param.js +0 -10
- package/cjs/connection/connection.js +0 -295
- package/cjs/connection/cursor.js +0 -91
- package/cjs/connection/intl-connection.js +0 -258
- package/cjs/connection/pool.js +0 -236
- package/cjs/connection/portal.js +0 -157
- package/cjs/connection/prepared-statement.js +0 -226
- package/cjs/constants.js +0 -249
- package/cjs/data-type-map.js +0 -131
- package/cjs/data-types/bool-type.js +0 -33
- package/cjs/data-types/box-type.js +0 -52
- package/cjs/data-types/bytea-type.js +0 -28
- package/cjs/data-types/char-type.js +0 -27
- package/cjs/data-types/circle-type.js +0 -51
- package/cjs/data-types/date-type.js +0 -75
- package/cjs/data-types/float4-type.js +0 -25
- package/cjs/data-types/float8-type.js +0 -25
- package/cjs/data-types/int2-type.js +0 -26
- package/cjs/data-types/int2-vector-type.js +0 -42
- package/cjs/data-types/int4-type.js +0 -28
- package/cjs/data-types/int8-type.js +0 -36
- package/cjs/data-types/json-type.js +0 -40
- package/cjs/data-types/jsonb-type.js +0 -44
- package/cjs/data-types/lseg-type.js +0 -55
- package/cjs/data-types/numeric-type.js +0 -125
- package/cjs/data-types/oid-type.js +0 -32
- package/cjs/data-types/point-type.js +0 -42
- package/cjs/data-types/time-type.js +0 -66
- package/cjs/data-types/timestamp-type.js +0 -89
- package/cjs/data-types/timestamptz-type.js +0 -76
- package/cjs/data-types/uuid-type.js +0 -39
- package/cjs/data-types/varchar-type.js +0 -27
- package/cjs/index.js +0 -28
- package/cjs/interfaces/command-result.js +0 -2
- package/cjs/interfaces/data-mapping-options.js +0 -2
- package/cjs/interfaces/data-type.js +0 -2
- package/cjs/interfaces/database-connection-params.js +0 -2
- package/cjs/interfaces/field-info.js +0 -2
- package/cjs/interfaces/query-options.js +0 -2
- package/cjs/interfaces/query-result.js +0 -2
- package/cjs/interfaces/script-execute-options.js +0 -2
- package/cjs/interfaces/script-result.js +0 -2
- package/cjs/interfaces/statement-prepare-options.js +0 -2
- package/cjs/package.json +0 -3
- package/cjs/protocol/backend.js +0 -262
- package/cjs/protocol/buffer-reader.js +0 -78
- package/cjs/protocol/database-error.js +0 -17
- package/cjs/protocol/frontend.js +0 -255
- package/cjs/protocol/pg-socket.js +0 -367
- package/cjs/protocol/protocol.js +0 -71
- package/cjs/protocol/sasl.js +0 -108
- package/cjs/protocol/smart-buffer.js +0 -178
- package/cjs/safe-event-emitter.js +0 -17
- package/cjs/tsconfig-build-cjs.tsbuildinfo +0 -1
- package/cjs/types.js +0 -2
- package/cjs/util/array-calculatedim.js +0 -18
- package/cjs/util/bigint-methods.js +0 -44
- package/cjs/util/config-from-env.js +0 -29
- package/cjs/util/connection-config.js +0 -61
- package/cjs/util/convert-row-to-object.js +0 -12
- package/cjs/util/decode-binaryarray.js +0 -38
- package/cjs/util/encode-binaryarray.js +0 -44
- package/cjs/util/escape-literal.js +0 -26
- package/cjs/util/fast-parseint.js +0 -31
- package/cjs/util/get-parsers.js +0 -41
- package/cjs/util/parse-array.js +0 -60
- package/cjs/util/parse-datetime.js +0 -37
- package/cjs/util/parse-row.js +0 -11
- package/cjs/util/parse-time.js +0 -30
- package/cjs/util/stringify-arrayliteral.js +0 -37
- package/cjs/util/stringify-for-sql.js +0 -29
- package/cjs/util/wrap-row-description.js +0 -34
- package/esm/package.json +0 -3
- package/types/index.d.cts +0 -25
- /package/{types/connection → connection}/bind-param.d.ts +0 -0
- /package/{types/connection → connection}/connection.d.ts +0 -0
- /package/{types/connection → connection}/cursor.d.ts +0 -0
- /package/{types/connection → connection}/intl-connection.d.ts +0 -0
- /package/{types/connection → connection}/pool.d.ts +0 -0
- /package/{types/connection → connection}/portal.d.ts +0 -0
- /package/{types/connection → connection}/prepared-statement.d.ts +0 -0
- /package/{types/constants.d.ts → constants.d.ts} +0 -0
- /package/{types/data-type-map.d.ts → data-type-map.d.ts} +0 -0
- /package/{types/data-types → data-types}/bool-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/bool-type.js +0 -0
- /package/{types/data-types → data-types}/box-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/box-type.js +0 -0
- /package/{types/data-types → data-types}/bytea-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/bytea-type.js +0 -0
- /package/{types/data-types → data-types}/char-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/char-type.js +0 -0
- /package/{types/data-types → data-types}/circle-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/circle-type.js +0 -0
- /package/{types/data-types → data-types}/date-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/date-type.js +0 -0
- /package/{types/data-types → data-types}/float4-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/float4-type.js +0 -0
- /package/{types/data-types → data-types}/float8-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/float8-type.js +0 -0
- /package/{types/data-types → data-types}/int2-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/int2-type.js +0 -0
- /package/{types/data-types → data-types}/int2-vector-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/int2-vector-type.js +0 -0
- /package/{types/data-types → data-types}/int4-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/int4-type.js +0 -0
- /package/{types/data-types → data-types}/int8-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/int8-type.js +0 -0
- /package/{types/data-types → data-types}/json-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/json-type.js +0 -0
- /package/{types/data-types → data-types}/jsonb-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/jsonb-type.js +0 -0
- /package/{types/data-types → data-types}/lseg-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/lseg-type.js +0 -0
- /package/{types/data-types → data-types}/numeric-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/numeric-type.js +0 -0
- /package/{types/data-types → data-types}/oid-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/oid-type.js +0 -0
- /package/{types/data-types → data-types}/point-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/point-type.js +0 -0
- /package/{types/data-types → data-types}/time-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/time-type.js +0 -0
- /package/{types/data-types → data-types}/timestamp-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/timestamp-type.js +0 -0
- /package/{types/data-types → data-types}/timestamptz-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/timestamptz-type.js +0 -0
- /package/{types/data-types → data-types}/uuid-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/uuid-type.js +0 -0
- /package/{types/data-types → data-types}/varchar-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/varchar-type.js +0 -0
- /package/{types/index.d.ts → index.d.ts} +0 -0
- /package/{esm/index.js → index.js} +0 -0
- /package/{types/interfaces → interfaces}/command-result.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/command-result.js +0 -0
- /package/{types/interfaces → interfaces}/data-mapping-options.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/data-mapping-options.js +0 -0
- /package/{types/interfaces → interfaces}/data-type.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/data-type.js +0 -0
- /package/{types/interfaces → interfaces}/database-connection-params.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/database-connection-params.js +0 -0
- /package/{types/interfaces → interfaces}/field-info.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/field-info.js +0 -0
- /package/{types/interfaces → interfaces}/query-options.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/query-options.js +0 -0
- /package/{types/interfaces → interfaces}/query-result.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/query-result.js +0 -0
- /package/{types/interfaces → interfaces}/script-execute-options.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/script-execute-options.js +0 -0
- /package/{types/interfaces → interfaces}/script-result.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/script-result.js +0 -0
- /package/{types/interfaces → interfaces}/statement-prepare-options.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/statement-prepare-options.js +0 -0
- /package/{types/protocol → protocol}/backend.d.ts +0 -0
- /package/{types/protocol → protocol}/buffer-reader.d.ts +0 -0
- /package/{types/protocol → protocol}/database-error.d.ts +0 -0
- /package/{types/protocol → protocol}/frontend.d.ts +0 -0
- /package/{types/protocol → protocol}/pg-socket.d.ts +0 -0
- /package/{types/protocol → protocol}/protocol.d.ts +0 -0
- /package/{esm/protocol → protocol}/protocol.js +0 -0
- /package/{types/protocol → protocol}/sasl.d.ts +0 -0
- /package/{esm/protocol → protocol}/sasl.js +0 -0
- /package/{types/protocol → protocol}/smart-buffer.d.ts +0 -0
- /package/{types/safe-event-emitter.d.ts → safe-event-emitter.d.ts} +0 -0
- /package/{esm/safe-event-emitter.js → safe-event-emitter.js} +0 -0
- /package/{types/types.d.ts → types.d.ts} +0 -0
- /package/{esm/types.js → types.js} +0 -0
- /package/{types/util → util}/array-calculatedim.d.ts +0 -0
- /package/{esm/util → util}/array-calculatedim.js +0 -0
- /package/{types/util → util}/bigint-methods.d.ts +0 -0
- /package/{types/util → util}/config-from-env.d.ts +0 -0
- /package/{esm/util → util}/config-from-env.js +0 -0
- /package/{types/util → util}/connection-config.d.ts +0 -0
- /package/{esm/util → util}/connection-config.js +0 -0
- /package/{types/util → util}/convert-row-to-object.d.ts +0 -0
- /package/{esm/util → util}/convert-row-to-object.js +0 -0
- /package/{types/util → util}/decode-binaryarray.d.ts +0 -0
- /package/{esm/util → util}/decode-binaryarray.js +0 -0
- /package/{types/util → util}/encode-binaryarray.d.ts +0 -0
- /package/{esm/util → util}/encode-binaryarray.js +0 -0
- /package/{types/util → util}/escape-literal.d.ts +0 -0
- /package/{esm/util → util}/escape-literal.js +0 -0
- /package/{types/util → util}/fast-parseint.d.ts +0 -0
- /package/{esm/util → util}/fast-parseint.js +0 -0
- /package/{types/util → util}/get-parsers.d.ts +0 -0
- /package/{esm/util → util}/get-parsers.js +0 -0
- /package/{types/util → util}/parse-array.d.ts +0 -0
- /package/{esm/util → util}/parse-array.js +0 -0
- /package/{types/util → util}/parse-datetime.d.ts +0 -0
- /package/{esm/util → util}/parse-datetime.js +0 -0
- /package/{types/util → util}/parse-row.d.ts +0 -0
- /package/{esm/util → util}/parse-row.js +0 -0
- /package/{types/util → util}/parse-time.d.ts +0 -0
- /package/{esm/util → util}/parse-time.js +0 -0
- /package/{types/util → util}/stringify-arrayliteral.d.ts +0 -0
- /package/{esm/util → util}/stringify-arrayliteral.js +0 -0
- /package/{types/util → util}/stringify-for-sql.d.ts +0 -0
- /package/{esm/util → util}/stringify-for-sql.js +0 -0
- /package/{types/util → util}/wrap-row-description.d.ts +0 -0
- /package/{esm/util → util}/wrap-row-description.js +0 -0
package/cjs/protocol/backend.js
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Backend = void 0;
|
|
4
|
-
const buffer_reader_js_1 = require("./buffer-reader.js");
|
|
5
|
-
const protocol_js_1 = require("./protocol.js");
|
|
6
|
-
// 1 byte message type, 4 byte frame length
|
|
7
|
-
const HEADER_LENGTH = 5;
|
|
8
|
-
const ErrorFieldTypes = {
|
|
9
|
-
M: 'message',
|
|
10
|
-
S: 'severity',
|
|
11
|
-
V: 'severity',
|
|
12
|
-
C: 'code',
|
|
13
|
-
D: 'detail',
|
|
14
|
-
H: 'hint',
|
|
15
|
-
P: 'position',
|
|
16
|
-
p: 'internalPosition',
|
|
17
|
-
q: 'internalQuery',
|
|
18
|
-
W: 'where',
|
|
19
|
-
s: 'schema',
|
|
20
|
-
t: 'table',
|
|
21
|
-
c: 'column',
|
|
22
|
-
d: 'dataType',
|
|
23
|
-
n: 'constraint',
|
|
24
|
-
F: 'file',
|
|
25
|
-
L: 'line',
|
|
26
|
-
R: 'routine',
|
|
27
|
-
};
|
|
28
|
-
class Backend {
|
|
29
|
-
reset() {
|
|
30
|
-
this._buf = undefined;
|
|
31
|
-
}
|
|
32
|
-
parse(data, callback) {
|
|
33
|
-
if (this._buf) {
|
|
34
|
-
data = Buffer.concat([this._buf, data]);
|
|
35
|
-
this._buf = undefined;
|
|
36
|
-
}
|
|
37
|
-
const io = new buffer_reader_js_1.BufferReader(data);
|
|
38
|
-
let offsetBookmark;
|
|
39
|
-
while (io.length - io.offset >= HEADER_LENGTH) {
|
|
40
|
-
offsetBookmark = io.offset;
|
|
41
|
-
const code = io.readUInt8();
|
|
42
|
-
const len = io.readUInt32BE();
|
|
43
|
-
// Check if frame data not received yet
|
|
44
|
-
if (io.length - io.offset < len - 4) {
|
|
45
|
-
io.offset = offsetBookmark;
|
|
46
|
-
this._buf = io.readBuffer();
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const parser = MessageParsers[code];
|
|
50
|
-
const v = parser && parser(io, code, len);
|
|
51
|
-
callback(code, v);
|
|
52
|
-
// Set offset to next message
|
|
53
|
-
io.offset = offsetBookmark + len + 1;
|
|
54
|
-
}
|
|
55
|
-
if (io.offset < io.length)
|
|
56
|
-
this._buf = io.readBuffer(io.length - io.offset);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.Backend = Backend;
|
|
60
|
-
const MessageParsers = {
|
|
61
|
-
[protocol_js_1.Protocol.BackendMessageCode.Authentication]: parseAuthentication,
|
|
62
|
-
[protocol_js_1.Protocol.BackendMessageCode.BackendKeyData]: parseBackendKeyData,
|
|
63
|
-
[protocol_js_1.Protocol.BackendMessageCode.CommandComplete]: parseCommandComplete,
|
|
64
|
-
[protocol_js_1.Protocol.BackendMessageCode.CopyData]: parseCopyData,
|
|
65
|
-
[protocol_js_1.Protocol.BackendMessageCode.CopyInResponse]: parseCopyResponse,
|
|
66
|
-
[protocol_js_1.Protocol.BackendMessageCode.CopyOutResponse]: parseCopyResponse,
|
|
67
|
-
[protocol_js_1.Protocol.BackendMessageCode.CopyBothResponse]: parseCopyResponse,
|
|
68
|
-
[protocol_js_1.Protocol.BackendMessageCode.DataRow]: parseDataRow,
|
|
69
|
-
[protocol_js_1.Protocol.BackendMessageCode.ErrorResponse]: parseErrorResponse,
|
|
70
|
-
[protocol_js_1.Protocol.BackendMessageCode.NoticeResponse]: parseErrorResponse,
|
|
71
|
-
[protocol_js_1.Protocol.BackendMessageCode.NotificationResponse]: parseNotificationResponse,
|
|
72
|
-
[protocol_js_1.Protocol.BackendMessageCode.FunctionCallResponse]: parseFunctionCallResponse,
|
|
73
|
-
[protocol_js_1.Protocol.BackendMessageCode.NegotiateProtocolVersion]: parseNegotiateProtocolVersion,
|
|
74
|
-
[protocol_js_1.Protocol.BackendMessageCode.ParameterDescription]: parseParameterDescription,
|
|
75
|
-
[protocol_js_1.Protocol.BackendMessageCode.ParameterStatus]: parseParameterStatus,
|
|
76
|
-
[protocol_js_1.Protocol.BackendMessageCode.ReadyForQuery]: parseReadyForQuery,
|
|
77
|
-
[protocol_js_1.Protocol.BackendMessageCode.RowDescription]: parseRowDescription,
|
|
78
|
-
};
|
|
79
|
-
function parseAuthentication(io, code, len) {
|
|
80
|
-
const kind = io.readUInt32BE();
|
|
81
|
-
switch (kind) {
|
|
82
|
-
case 0:
|
|
83
|
-
return; // AuthenticationOk
|
|
84
|
-
case 2:
|
|
85
|
-
return {
|
|
86
|
-
kind: 'KerberosV5',
|
|
87
|
-
};
|
|
88
|
-
case 3:
|
|
89
|
-
return {
|
|
90
|
-
kind: 'CleartextPassword',
|
|
91
|
-
};
|
|
92
|
-
case 5:
|
|
93
|
-
return {
|
|
94
|
-
kind: 'MD5Password',
|
|
95
|
-
salt: io.readBuffer(len - 8),
|
|
96
|
-
};
|
|
97
|
-
case 6:
|
|
98
|
-
return {
|
|
99
|
-
kind: 'SCMCredential',
|
|
100
|
-
};
|
|
101
|
-
case 7:
|
|
102
|
-
return {
|
|
103
|
-
kind: 'GSS',
|
|
104
|
-
};
|
|
105
|
-
case 9:
|
|
106
|
-
return {
|
|
107
|
-
kind: 'SSPI',
|
|
108
|
-
};
|
|
109
|
-
case 8:
|
|
110
|
-
return {
|
|
111
|
-
kind: 'GSSContinue',
|
|
112
|
-
data: io.readBuffer(len - 8),
|
|
113
|
-
};
|
|
114
|
-
case 10: {
|
|
115
|
-
const out = {
|
|
116
|
-
kind: 'SASL',
|
|
117
|
-
mechanisms: [],
|
|
118
|
-
};
|
|
119
|
-
let mechanism;
|
|
120
|
-
while ((mechanism = io.readCString())) {
|
|
121
|
-
out.mechanisms.push(mechanism);
|
|
122
|
-
}
|
|
123
|
-
return out;
|
|
124
|
-
}
|
|
125
|
-
case 11:
|
|
126
|
-
return {
|
|
127
|
-
kind: 'SASLContinue',
|
|
128
|
-
data: io.readLString(len - 8, 'utf8'),
|
|
129
|
-
};
|
|
130
|
-
case 12:
|
|
131
|
-
return {
|
|
132
|
-
kind: 'SASLFinal',
|
|
133
|
-
data: io.readLString(len - 8, 'utf8'),
|
|
134
|
-
};
|
|
135
|
-
default:
|
|
136
|
-
throw new Error(`Unknown authentication kind (${kind})`);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
function parseBackendKeyData(io) {
|
|
140
|
-
return {
|
|
141
|
-
processID: io.readUInt32BE(),
|
|
142
|
-
secretKey: io.readUInt32BE(),
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
function parseCommandComplete(io) {
|
|
146
|
-
return {
|
|
147
|
-
command: io.readCString('utf8'),
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
function parseCopyData(io, code, len) {
|
|
151
|
-
return {
|
|
152
|
-
data: io.readBuffer(len - 4),
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
function parseCopyResponse(io) {
|
|
156
|
-
const out = {
|
|
157
|
-
overallFormat: io.readUInt8() === 0
|
|
158
|
-
? protocol_js_1.Protocol.DataFormat.text
|
|
159
|
-
: protocol_js_1.Protocol.DataFormat.binary,
|
|
160
|
-
columnCount: io.readUInt16BE(),
|
|
161
|
-
};
|
|
162
|
-
if (out.columnCount) {
|
|
163
|
-
out.columnFormats = [];
|
|
164
|
-
for (let i = 0; i < out.columnCount; i++) {
|
|
165
|
-
out.columnFormats.push(io.readUInt16BE() === 0
|
|
166
|
-
? protocol_js_1.Protocol.DataFormat.text
|
|
167
|
-
: protocol_js_1.Protocol.DataFormat.binary);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return out;
|
|
171
|
-
}
|
|
172
|
-
function parseDataRow(io) {
|
|
173
|
-
const out = {
|
|
174
|
-
columnCount: io.readUInt16BE(),
|
|
175
|
-
};
|
|
176
|
-
if (out.columnCount) {
|
|
177
|
-
out.columns = [];
|
|
178
|
-
for (let i = 0; i < out.columnCount; i++) {
|
|
179
|
-
// The length of the column value, in bytes (this count does not include itself).
|
|
180
|
-
// Can be zero. As a special case, -1 indicates a NULL column value.
|
|
181
|
-
// No value bytes follow in the NULL case.
|
|
182
|
-
const l = io.readInt32BE();
|
|
183
|
-
if (l < 0)
|
|
184
|
-
out.columns.push(null);
|
|
185
|
-
else
|
|
186
|
-
out.columns.push(io.readBuffer(l));
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return out;
|
|
190
|
-
}
|
|
191
|
-
function parseErrorResponse(io) {
|
|
192
|
-
const out = {};
|
|
193
|
-
let fieldType;
|
|
194
|
-
while ((fieldType = io.readLString(1)) !== '\0') {
|
|
195
|
-
const value = io.readCString('utf8');
|
|
196
|
-
const key = ErrorFieldTypes[fieldType];
|
|
197
|
-
if (key)
|
|
198
|
-
out[key] = value;
|
|
199
|
-
}
|
|
200
|
-
return out;
|
|
201
|
-
}
|
|
202
|
-
function parseNotificationResponse(io) {
|
|
203
|
-
return {
|
|
204
|
-
processId: io.readUInt32BE(),
|
|
205
|
-
channel: io.readCString(),
|
|
206
|
-
payload: io.readCString(),
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
function parseFunctionCallResponse(io, code, len) {
|
|
210
|
-
return {
|
|
211
|
-
result: io.readBuffer(len - 4),
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
function parseNegotiateProtocolVersion(io) {
|
|
215
|
-
return {
|
|
216
|
-
supportedVersionMinor: io.readUInt32BE(),
|
|
217
|
-
numberOfNotSupportedVersions: io.readUInt32BE(),
|
|
218
|
-
option: io.readCString('utf8'),
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
function parseParameterDescription(io) {
|
|
222
|
-
const out = {
|
|
223
|
-
parameterCount: io.readUInt32BE(),
|
|
224
|
-
parameterIds: [],
|
|
225
|
-
};
|
|
226
|
-
for (let i = 0; i < out.parameterCount; i++) {
|
|
227
|
-
out.parameterIds.push(io.readUInt32BE());
|
|
228
|
-
}
|
|
229
|
-
return out;
|
|
230
|
-
}
|
|
231
|
-
function parseParameterStatus(io) {
|
|
232
|
-
return {
|
|
233
|
-
name: io.readCString('utf8'),
|
|
234
|
-
value: io.readCString('utf8'),
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
function parseReadyForQuery(io) {
|
|
238
|
-
return {
|
|
239
|
-
status: io.readLString(1),
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
function parseRowDescription(io) {
|
|
243
|
-
const fieldCount = io.readUInt16BE();
|
|
244
|
-
const out = {
|
|
245
|
-
fields: [],
|
|
246
|
-
};
|
|
247
|
-
for (let i = 0; i < fieldCount; i++) {
|
|
248
|
-
const field = {
|
|
249
|
-
fieldName: io.readCString('utf8'),
|
|
250
|
-
tableId: io.readInt32BE(),
|
|
251
|
-
columnId: io.readInt16BE(),
|
|
252
|
-
dataTypeId: io.readInt32BE(),
|
|
253
|
-
fixedSize: io.readInt16BE(),
|
|
254
|
-
modifier: io.readInt32BE(),
|
|
255
|
-
format: io.readInt16BE() === 0
|
|
256
|
-
? protocol_js_1.Protocol.DataFormat.text
|
|
257
|
-
: protocol_js_1.Protocol.DataFormat.binary,
|
|
258
|
-
};
|
|
259
|
-
out.fields.push(field);
|
|
260
|
-
}
|
|
261
|
-
return out;
|
|
262
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BufferReader = void 0;
|
|
4
|
-
class BufferReader {
|
|
5
|
-
constructor(buffer) {
|
|
6
|
-
this.offset = 0;
|
|
7
|
-
this.buffer = buffer;
|
|
8
|
-
}
|
|
9
|
-
get length() {
|
|
10
|
-
return this.buffer.length;
|
|
11
|
-
}
|
|
12
|
-
readUInt8() {
|
|
13
|
-
this._checkReadable(1);
|
|
14
|
-
const v = this.buffer.readUInt8(this.offset);
|
|
15
|
-
this.offset++;
|
|
16
|
-
return v;
|
|
17
|
-
}
|
|
18
|
-
readUInt16BE() {
|
|
19
|
-
this._checkReadable(2);
|
|
20
|
-
const v = this.buffer.readUInt16BE(this.offset);
|
|
21
|
-
this.offset += 2;
|
|
22
|
-
return v;
|
|
23
|
-
}
|
|
24
|
-
readInt16BE() {
|
|
25
|
-
this._checkReadable(2);
|
|
26
|
-
const v = this.buffer.readInt16BE(this.offset);
|
|
27
|
-
this.offset += 2;
|
|
28
|
-
return v;
|
|
29
|
-
}
|
|
30
|
-
readUInt32BE() {
|
|
31
|
-
this._checkReadable(4);
|
|
32
|
-
const v = this.buffer.readUInt32BE(this.offset);
|
|
33
|
-
this.offset += 4;
|
|
34
|
-
return v;
|
|
35
|
-
}
|
|
36
|
-
readInt32BE() {
|
|
37
|
-
this._checkReadable(4);
|
|
38
|
-
const v = this.buffer.readInt32BE(this.offset);
|
|
39
|
-
this.offset += 4;
|
|
40
|
-
return v;
|
|
41
|
-
}
|
|
42
|
-
readCString(encoding) {
|
|
43
|
-
const idx = this.buffer.indexOf(0, this.offset);
|
|
44
|
-
const v = this.buffer.toString(encoding, this.offset, idx);
|
|
45
|
-
this.offset = idx + 1;
|
|
46
|
-
return v;
|
|
47
|
-
}
|
|
48
|
-
readLString(len, encoding) {
|
|
49
|
-
if (len < 0)
|
|
50
|
-
return null;
|
|
51
|
-
this._checkReadable(len);
|
|
52
|
-
const v = this.buffer.toString(encoding, this.offset, this.offset + len);
|
|
53
|
-
this.offset += len;
|
|
54
|
-
return v;
|
|
55
|
-
}
|
|
56
|
-
readBuffer(len) {
|
|
57
|
-
if (len)
|
|
58
|
-
this._checkReadable(len);
|
|
59
|
-
const end = len !== undefined ? this.offset + len : this.length;
|
|
60
|
-
const buf = this.buffer.slice(this.offset, end);
|
|
61
|
-
this.offset = end;
|
|
62
|
-
return buf;
|
|
63
|
-
}
|
|
64
|
-
moveBy(n) {
|
|
65
|
-
return this.moveTo(this.offset + n);
|
|
66
|
-
}
|
|
67
|
-
moveTo(pos) {
|
|
68
|
-
if (pos >= this.length)
|
|
69
|
-
throw new Error('Eof in buffer detected');
|
|
70
|
-
this.offset = pos;
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
_checkReadable(size) {
|
|
74
|
-
if (this.offset + size - 1 >= this.length)
|
|
75
|
-
throw new Error('Eof in buffer detected');
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.BufferReader = BufferReader;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DatabaseError = void 0;
|
|
4
|
-
class DatabaseError extends Error {
|
|
5
|
-
constructor(msg) {
|
|
6
|
-
super(msg.message);
|
|
7
|
-
Object.assign(this, {
|
|
8
|
-
...msg,
|
|
9
|
-
line: undefined,
|
|
10
|
-
file: undefined,
|
|
11
|
-
routine: undefined,
|
|
12
|
-
});
|
|
13
|
-
if (msg.position)
|
|
14
|
-
this.position = parseInt(msg.position, 10) || undefined;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.DatabaseError = DatabaseError;
|
package/cjs/protocol/frontend.js
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Frontend = void 0;
|
|
4
|
-
const constants_js_1 = require("../constants.js");
|
|
5
|
-
const encode_binaryarray_js_1 = require("../util/encode-binaryarray.js");
|
|
6
|
-
const stringify_arrayliteral_js_1 = require("../util/stringify-arrayliteral.js");
|
|
7
|
-
const protocol_js_1 = require("./protocol.js");
|
|
8
|
-
const smart_buffer_js_1 = require("./smart-buffer.js");
|
|
9
|
-
const DataFormat = protocol_js_1.Protocol.DataFormat;
|
|
10
|
-
const StaticFlushBuffer = Buffer.from([
|
|
11
|
-
protocol_js_1.Protocol.FrontendMessageCode.Flush,
|
|
12
|
-
0x00,
|
|
13
|
-
0x00,
|
|
14
|
-
0x00,
|
|
15
|
-
0x04,
|
|
16
|
-
]);
|
|
17
|
-
const StaticTerminateBuffer = Buffer.from([
|
|
18
|
-
protocol_js_1.Protocol.FrontendMessageCode.Terminate,
|
|
19
|
-
0x00,
|
|
20
|
-
0x00,
|
|
21
|
-
0x00,
|
|
22
|
-
0x04,
|
|
23
|
-
]);
|
|
24
|
-
const StaticSyncBuffer = Buffer.from([
|
|
25
|
-
protocol_js_1.Protocol.FrontendMessageCode.Sync,
|
|
26
|
-
0x00,
|
|
27
|
-
0x00,
|
|
28
|
-
0x00,
|
|
29
|
-
0x04,
|
|
30
|
-
]);
|
|
31
|
-
class Frontend {
|
|
32
|
-
constructor(options) {
|
|
33
|
-
this._io = new smart_buffer_js_1.SmartBuffer(options?.buffer);
|
|
34
|
-
}
|
|
35
|
-
getSSLRequestMessage() {
|
|
36
|
-
return this._io
|
|
37
|
-
.start()
|
|
38
|
-
.writeUInt32BE(8) // Length of message contents in bytes, including self.
|
|
39
|
-
.writeUInt16BE(1234)
|
|
40
|
-
.writeUInt16BE(5679)
|
|
41
|
-
.flush();
|
|
42
|
-
}
|
|
43
|
-
getStartupMessage(args) {
|
|
44
|
-
const io = this._io
|
|
45
|
-
.start()
|
|
46
|
-
.writeInt32BE(0) // Preserve length
|
|
47
|
-
.writeInt16BE(protocol_js_1.Protocol.VERSION_MAJOR)
|
|
48
|
-
.writeInt16BE(protocol_js_1.Protocol.VERSION_MINOR);
|
|
49
|
-
for (const [k, v] of Object.entries(args)) {
|
|
50
|
-
if (k !== 'client_encoding')
|
|
51
|
-
io.writeCString(k, 'utf8').writeCString(v, 'utf8');
|
|
52
|
-
}
|
|
53
|
-
io.writeCString('client_encoding', 'utf8')
|
|
54
|
-
.writeCString('UTF8', 'utf8')
|
|
55
|
-
.writeUInt8(0);
|
|
56
|
-
return setLengthAndFlush(io, 0);
|
|
57
|
-
}
|
|
58
|
-
getPasswordMessage(password) {
|
|
59
|
-
const io = this._io
|
|
60
|
-
.start()
|
|
61
|
-
.writeInt8(protocol_js_1.Protocol.FrontendMessageCode.PasswordMessage)
|
|
62
|
-
.writeInt32BE(0) // Preserve header
|
|
63
|
-
.writeCString(password, 'utf8');
|
|
64
|
-
return setLengthAndFlush(io, 1);
|
|
65
|
-
}
|
|
66
|
-
getSASLMessage(sasl) {
|
|
67
|
-
const io = this._io
|
|
68
|
-
.start()
|
|
69
|
-
.writeInt8(protocol_js_1.Protocol.FrontendMessageCode.PasswordMessage)
|
|
70
|
-
.writeInt32BE(0) // Preserve header
|
|
71
|
-
.writeCString(sasl.mechanism, 'utf8')
|
|
72
|
-
.writeLString(sasl.clientFirstMessage);
|
|
73
|
-
return setLengthAndFlush(io, 1);
|
|
74
|
-
}
|
|
75
|
-
getSASLFinalMessage(session) {
|
|
76
|
-
const io = this._io
|
|
77
|
-
.start()
|
|
78
|
-
.writeInt8(protocol_js_1.Protocol.FrontendMessageCode.PasswordMessage)
|
|
79
|
-
.writeInt32BE(0) // Preserve header
|
|
80
|
-
.writeString(session.clientFinalMessage);
|
|
81
|
-
return setLengthAndFlush(io, 1);
|
|
82
|
-
}
|
|
83
|
-
getParseMessage(args) {
|
|
84
|
-
if (args.statement && args.statement.length > 63)
|
|
85
|
-
throw new Error('Query name length must be lower than 63');
|
|
86
|
-
const io = this._io
|
|
87
|
-
.start()
|
|
88
|
-
.writeInt8(protocol_js_1.Protocol.FrontendMessageCode.Parse)
|
|
89
|
-
.writeInt32BE(0) // Preserve header
|
|
90
|
-
.writeCString(args.statement || '', 'utf8')
|
|
91
|
-
.writeCString(args.sql, 'utf8')
|
|
92
|
-
.writeUInt16BE(args.paramTypes ? args.paramTypes.length : 0);
|
|
93
|
-
if (args.paramTypes) {
|
|
94
|
-
for (const t of args.paramTypes) {
|
|
95
|
-
io.writeUInt32BE(t || 0);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return setLengthAndFlush(io, 1);
|
|
99
|
-
}
|
|
100
|
-
getBindMessage(args) {
|
|
101
|
-
if (args.portal && args.portal.length > 63)
|
|
102
|
-
throw new Error('Portal name length must be lower than 63');
|
|
103
|
-
if (args.statement && args.statement.length > 63)
|
|
104
|
-
throw new Error('Query name length must be lower than 63');
|
|
105
|
-
const io = this._io
|
|
106
|
-
.start()
|
|
107
|
-
.writeInt8(protocol_js_1.Protocol.FrontendMessageCode.Bind)
|
|
108
|
-
.writeInt32BE(0) // Preserve header
|
|
109
|
-
.writeCString(args.portal || '', 'utf8')
|
|
110
|
-
.writeCString(args.statement || '', 'utf8');
|
|
111
|
-
const { params, paramTypes, queryOptions } = args;
|
|
112
|
-
const columnFormat = queryOptions.columnFormat != null
|
|
113
|
-
? queryOptions.columnFormat
|
|
114
|
-
: constants_js_1.DEFAULT_COLUMN_FORMAT;
|
|
115
|
-
if (params && params.length) {
|
|
116
|
-
io.writeInt16BE(params.length);
|
|
117
|
-
const formatOffset = io.offset;
|
|
118
|
-
for (let i = 0; i < params.length; i++) {
|
|
119
|
-
io.writeInt16BE(0); // Preserve
|
|
120
|
-
}
|
|
121
|
-
// Write parameter values
|
|
122
|
-
io.writeUInt16BE(params.length);
|
|
123
|
-
for (let i = 0; i < params?.length; i++) {
|
|
124
|
-
let v = params[i];
|
|
125
|
-
if (v === null || v === undefined) {
|
|
126
|
-
io.writeInt32BE(-1);
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
const dataTypeOid = paramTypes ? paramTypes[i] : undefined;
|
|
130
|
-
const dt = dataTypeOid ? args.typeMap.get(dataTypeOid) : undefined;
|
|
131
|
-
if (dt) {
|
|
132
|
-
if (typeof dt.encodeAsNull === 'function' &&
|
|
133
|
-
dt.encodeAsNull(v, queryOptions)) {
|
|
134
|
-
io.writeInt32BE(-1);
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
if (typeof dt.encodeBinary === 'function') {
|
|
138
|
-
// Set param format to binary
|
|
139
|
-
io.buffer.writeInt16BE(protocol_js_1.Protocol.DataFormat.binary, formatOffset + i * 2);
|
|
140
|
-
// Preserve data length
|
|
141
|
-
io.writeInt32BE(0);
|
|
142
|
-
const dataOffset = io.offset;
|
|
143
|
-
if (dt.elementsOID) {
|
|
144
|
-
// If data type is array
|
|
145
|
-
v = Array.isArray(v) ? v : [v];
|
|
146
|
-
(0, encode_binaryarray_js_1.encodeBinaryArray)(io, v, dt.elementsOID, queryOptions, dt.encodeBinary, dt.encodeCalculateDim);
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
dt.encodeBinary(io, v, queryOptions);
|
|
150
|
-
}
|
|
151
|
-
io.buffer.writeInt32BE(io.length - dataOffset, dataOffset - 4); // Update length
|
|
152
|
-
}
|
|
153
|
-
else if (typeof dt.encodeText === 'function') {
|
|
154
|
-
v = dt.elementsOID
|
|
155
|
-
? (0, stringify_arrayliteral_js_1.stringifyArrayLiteral)(v, queryOptions, dt.encodeText)
|
|
156
|
-
: dt.encodeText(v, queryOptions);
|
|
157
|
-
io.writeLString(v, 'utf8');
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
else if (Buffer.isBuffer(v)) {
|
|
161
|
-
// Set param format to binary
|
|
162
|
-
io.buffer.writeInt16BE(protocol_js_1.Protocol.DataFormat.binary, formatOffset + i * 2);
|
|
163
|
-
// Preserve data length
|
|
164
|
-
io.writeInt32BE(0);
|
|
165
|
-
const dataOffset = io.offset;
|
|
166
|
-
io.writeBuffer(v);
|
|
167
|
-
io.buffer.writeInt32BE(io.length - dataOffset, dataOffset - 4); // Update length
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
io.writeLString('' + v, 'utf8');
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
io.writeUInt16BE(0);
|
|
176
|
-
io.writeUInt16BE(0);
|
|
177
|
-
}
|
|
178
|
-
if (Array.isArray(columnFormat)) {
|
|
179
|
-
io.writeUInt16BE(columnFormat.length);
|
|
180
|
-
for (let i = 0; i < columnFormat.length; i++) {
|
|
181
|
-
io.writeUInt16BE(columnFormat[i]);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
else if (columnFormat === DataFormat.binary) {
|
|
185
|
-
io.writeUInt16BE(1);
|
|
186
|
-
io.writeUInt16BE(DataFormat.binary);
|
|
187
|
-
}
|
|
188
|
-
else
|
|
189
|
-
io.writeUInt16BE(0);
|
|
190
|
-
return setLengthAndFlush(io, 1);
|
|
191
|
-
}
|
|
192
|
-
getDescribeMessage(args) {
|
|
193
|
-
if (args.name && args.name.length > 63) {
|
|
194
|
-
throw new Error(args.type === 'P'
|
|
195
|
-
? 'Portal'
|
|
196
|
-
: 'Statement name length must be lower than 63');
|
|
197
|
-
}
|
|
198
|
-
const io = this._io
|
|
199
|
-
.start()
|
|
200
|
-
.writeInt8(protocol_js_1.Protocol.FrontendMessageCode.Describe)
|
|
201
|
-
.writeInt32BE(0) // Preserve header
|
|
202
|
-
.writeUInt8(args.type.charCodeAt(0))
|
|
203
|
-
.writeCString(args.name || '', 'utf8');
|
|
204
|
-
return setLengthAndFlush(io, 1);
|
|
205
|
-
}
|
|
206
|
-
getExecuteMessage(args) {
|
|
207
|
-
if (args.fetchCount &&
|
|
208
|
-
(args.fetchCount < 0 || args.fetchCount > 4294967295)) {
|
|
209
|
-
throw new Error('fetchCount can be between 0 and 4294967295');
|
|
210
|
-
}
|
|
211
|
-
const io = this._io
|
|
212
|
-
.start()
|
|
213
|
-
.writeInt8(protocol_js_1.Protocol.FrontendMessageCode.Execute)
|
|
214
|
-
.writeInt32BE(0) // Preserve header
|
|
215
|
-
.writeCString(args.portal || '', 'utf8')
|
|
216
|
-
.writeUInt32BE(args.fetchCount || 0);
|
|
217
|
-
return setLengthAndFlush(io, 1);
|
|
218
|
-
}
|
|
219
|
-
getCloseMessage(args) {
|
|
220
|
-
if (args.name && args.name.length > 63) {
|
|
221
|
-
throw new Error(args.type === 'P'
|
|
222
|
-
? 'Portal'
|
|
223
|
-
: 'Statement name length must be lower than 63');
|
|
224
|
-
}
|
|
225
|
-
const io = this._io
|
|
226
|
-
.start()
|
|
227
|
-
.writeInt8(protocol_js_1.Protocol.FrontendMessageCode.Close)
|
|
228
|
-
.writeInt32BE(0) // Preserve header
|
|
229
|
-
.writeUInt8(args.type.charCodeAt(0))
|
|
230
|
-
.writeCString(args.name || '', 'utf8');
|
|
231
|
-
return setLengthAndFlush(io, 1);
|
|
232
|
-
}
|
|
233
|
-
getQueryMessage(sql) {
|
|
234
|
-
const io = this._io
|
|
235
|
-
.start()
|
|
236
|
-
.writeInt8(protocol_js_1.Protocol.FrontendMessageCode.Query)
|
|
237
|
-
.writeInt32BE(0) // Preserve header
|
|
238
|
-
.writeCString(sql || '', 'utf8');
|
|
239
|
-
return setLengthAndFlush(io, 1);
|
|
240
|
-
}
|
|
241
|
-
getFlushMessage() {
|
|
242
|
-
return StaticFlushBuffer;
|
|
243
|
-
}
|
|
244
|
-
getTerminateMessage() {
|
|
245
|
-
return StaticTerminateBuffer;
|
|
246
|
-
}
|
|
247
|
-
getSyncMessage() {
|
|
248
|
-
return StaticSyncBuffer;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
exports.Frontend = Frontend;
|
|
252
|
-
function setLengthAndFlush(io, lengthOffset) {
|
|
253
|
-
io.buffer.writeUInt32BE(io.length - lengthOffset, lengthOffset);
|
|
254
|
-
return io.flush();
|
|
255
|
-
}
|