postgrejs 2.22.7 → 2.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -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 +13 -32
- 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/{types/protocol → protocol}/smart-buffer.d.ts +1 -0
- package/{esm/protocol → protocol}/smart-buffer.js +29 -19
- 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 -172
- 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/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/protocol.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Protocol = void 0;
|
|
4
|
-
var Protocol;
|
|
5
|
-
(function (Protocol) {
|
|
6
|
-
Protocol.VERSION_MAJOR = 3;
|
|
7
|
-
Protocol.VERSION_MINOR = 0;
|
|
8
|
-
// https://www.postgresql.org/docs/9.3/protocol-message-formats.html
|
|
9
|
-
let BackendMessageCode;
|
|
10
|
-
(function (BackendMessageCode) {
|
|
11
|
-
BackendMessageCode[BackendMessageCode["Authentication"] = 82] = "Authentication";
|
|
12
|
-
BackendMessageCode[BackendMessageCode["BackendKeyData"] = 75] = "BackendKeyData";
|
|
13
|
-
BackendMessageCode[BackendMessageCode["BindComplete"] = 50] = "BindComplete";
|
|
14
|
-
BackendMessageCode[BackendMessageCode["CloseComplete"] = 51] = "CloseComplete";
|
|
15
|
-
BackendMessageCode[BackendMessageCode["CommandComplete"] = 67] = "CommandComplete";
|
|
16
|
-
BackendMessageCode[BackendMessageCode["CopyData"] = 100] = "CopyData";
|
|
17
|
-
BackendMessageCode[BackendMessageCode["CopyDone"] = 99] = "CopyDone";
|
|
18
|
-
BackendMessageCode[BackendMessageCode["CopyInResponse"] = 103] = "CopyInResponse";
|
|
19
|
-
BackendMessageCode[BackendMessageCode["CopyOutResponse"] = 72] = "CopyOutResponse";
|
|
20
|
-
BackendMessageCode[BackendMessageCode["CopyBothResponse"] = 87] = "CopyBothResponse";
|
|
21
|
-
BackendMessageCode[BackendMessageCode["DataRow"] = 68] = "DataRow";
|
|
22
|
-
BackendMessageCode[BackendMessageCode["EmptyQueryResponse"] = 73] = "EmptyQueryResponse";
|
|
23
|
-
BackendMessageCode[BackendMessageCode["ErrorResponse"] = 69] = "ErrorResponse";
|
|
24
|
-
BackendMessageCode[BackendMessageCode["FunctionCallResponse"] = 86] = "FunctionCallResponse";
|
|
25
|
-
BackendMessageCode[BackendMessageCode["NegotiateProtocolVersion"] = 118] = "NegotiateProtocolVersion";
|
|
26
|
-
BackendMessageCode[BackendMessageCode["NoData"] = 110] = "NoData";
|
|
27
|
-
BackendMessageCode[BackendMessageCode["NoticeResponse"] = 78] = "NoticeResponse";
|
|
28
|
-
BackendMessageCode[BackendMessageCode["NotificationResponse"] = 65] = "NotificationResponse";
|
|
29
|
-
BackendMessageCode[BackendMessageCode["ParameterDescription"] = 116] = "ParameterDescription";
|
|
30
|
-
BackendMessageCode[BackendMessageCode["ParameterStatus"] = 83] = "ParameterStatus";
|
|
31
|
-
BackendMessageCode[BackendMessageCode["ParseComplete"] = 49] = "ParseComplete";
|
|
32
|
-
BackendMessageCode[BackendMessageCode["PortalSuspended"] = 115] = "PortalSuspended";
|
|
33
|
-
BackendMessageCode[BackendMessageCode["ReadyForQuery"] = 90] = "ReadyForQuery";
|
|
34
|
-
BackendMessageCode[BackendMessageCode["RowDescription"] = 84] = "RowDescription";
|
|
35
|
-
})(BackendMessageCode = Protocol.BackendMessageCode || (Protocol.BackendMessageCode = {}));
|
|
36
|
-
let FrontendMessageCode;
|
|
37
|
-
(function (FrontendMessageCode) {
|
|
38
|
-
FrontendMessageCode[FrontendMessageCode["Bind"] = 66] = "Bind";
|
|
39
|
-
FrontendMessageCode[FrontendMessageCode["Close"] = 67] = "Close";
|
|
40
|
-
FrontendMessageCode[FrontendMessageCode["CopyData"] = 100] = "CopyData";
|
|
41
|
-
FrontendMessageCode[FrontendMessageCode["CopyDone"] = 99] = "CopyDone";
|
|
42
|
-
FrontendMessageCode[FrontendMessageCode["CopyFail"] = 102] = "CopyFail";
|
|
43
|
-
FrontendMessageCode[FrontendMessageCode["Describe"] = 68] = "Describe";
|
|
44
|
-
FrontendMessageCode[FrontendMessageCode["Execute"] = 69] = "Execute";
|
|
45
|
-
FrontendMessageCode[FrontendMessageCode["Flush"] = 72] = "Flush";
|
|
46
|
-
FrontendMessageCode[FrontendMessageCode["FunctionCall"] = 70] = "FunctionCall";
|
|
47
|
-
FrontendMessageCode[FrontendMessageCode["Parse"] = 80] = "Parse";
|
|
48
|
-
FrontendMessageCode[FrontendMessageCode["PasswordMessage"] = 112] = "PasswordMessage";
|
|
49
|
-
FrontendMessageCode[FrontendMessageCode["Query"] = 81] = "Query";
|
|
50
|
-
FrontendMessageCode[FrontendMessageCode["Sync"] = 83] = "Sync";
|
|
51
|
-
FrontendMessageCode[FrontendMessageCode["Terminate"] = 88] = "Terminate";
|
|
52
|
-
})(FrontendMessageCode = Protocol.FrontendMessageCode || (Protocol.FrontendMessageCode = {}));
|
|
53
|
-
let AuthenticationMessageKind;
|
|
54
|
-
(function (AuthenticationMessageKind) {
|
|
55
|
-
AuthenticationMessageKind["KerberosV5"] = "KerberosV5";
|
|
56
|
-
AuthenticationMessageKind["CleartextPassword"] = "CleartextPassword";
|
|
57
|
-
AuthenticationMessageKind["MD5Password"] = "MD5Password";
|
|
58
|
-
AuthenticationMessageKind["SCMCredential"] = "SCMCredential";
|
|
59
|
-
AuthenticationMessageKind["GSS"] = "GSS";
|
|
60
|
-
AuthenticationMessageKind["SSPI"] = "SSPI";
|
|
61
|
-
AuthenticationMessageKind["GSSContinue"] = "GSSContinue";
|
|
62
|
-
AuthenticationMessageKind["SASL"] = "SASL";
|
|
63
|
-
AuthenticationMessageKind["SASLContinue"] = "SASLContinue";
|
|
64
|
-
AuthenticationMessageKind["SASLFinal"] = "SASLFinal";
|
|
65
|
-
})(AuthenticationMessageKind = Protocol.AuthenticationMessageKind || (Protocol.AuthenticationMessageKind = {}));
|
|
66
|
-
let DataFormat;
|
|
67
|
-
(function (DataFormat) {
|
|
68
|
-
DataFormat[DataFormat["text"] = 0] = "text";
|
|
69
|
-
DataFormat[DataFormat["binary"] = 1] = "binary";
|
|
70
|
-
})(DataFormat = Protocol.DataFormat || (Protocol.DataFormat = {}));
|
|
71
|
-
})(Protocol || (exports.Protocol = Protocol = {}));
|
package/cjs/protocol/sasl.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SASL = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
6
|
-
var SASL;
|
|
7
|
-
(function (SASL) {
|
|
8
|
-
const CLIENT_KEY = 'Client Key';
|
|
9
|
-
const SERVER_KEY = 'Server Key';
|
|
10
|
-
const GS2_HEADER = 'n,,';
|
|
11
|
-
function createSession(username, mechanism) {
|
|
12
|
-
const nonce = crypto_1.default.randomBytes(18).toString('base64');
|
|
13
|
-
const clientFirstMessage = `${GS2_HEADER}${firstMessageBare(username, nonce)}`;
|
|
14
|
-
return {
|
|
15
|
-
username,
|
|
16
|
-
mechanism,
|
|
17
|
-
nonce,
|
|
18
|
-
clientFirstMessage,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
SASL.createSession = createSession;
|
|
22
|
-
function continueSession(session, password, data) {
|
|
23
|
-
const s = data.toString();
|
|
24
|
-
const items = s.split(',');
|
|
25
|
-
let nonce = '';
|
|
26
|
-
let salt = '';
|
|
27
|
-
let iteration = 0;
|
|
28
|
-
for (const i of items) {
|
|
29
|
-
switch (i[0]) {
|
|
30
|
-
case 'r':
|
|
31
|
-
nonce = i.substring(2);
|
|
32
|
-
break;
|
|
33
|
-
case 's':
|
|
34
|
-
salt = i.substring(2);
|
|
35
|
-
break;
|
|
36
|
-
case 'i':
|
|
37
|
-
iteration = parseInt(i.substring(2), 10);
|
|
38
|
-
break;
|
|
39
|
-
default:
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (!nonce)
|
|
44
|
-
throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce missing');
|
|
45
|
-
if (!salt)
|
|
46
|
-
throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: salt missing');
|
|
47
|
-
if (!iteration)
|
|
48
|
-
throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: iteration missing');
|
|
49
|
-
if (!nonce.startsWith(session.nonce))
|
|
50
|
-
throw new Error('SASL: Server nonce does not start with client nonce');
|
|
51
|
-
const serverFirstMessage = `r=${nonce},s=${salt},i=${iteration}`;
|
|
52
|
-
const clientFinalMessageWithoutProof = `c=${encode64(GS2_HEADER)},r=${nonce}`;
|
|
53
|
-
const authMessage = `${firstMessageBare(session.username, session.nonce)},${serverFirstMessage},${clientFinalMessageWithoutProof}`;
|
|
54
|
-
const saltPass = hi(password, salt, iteration);
|
|
55
|
-
const clientKey = hmac(saltPass, CLIENT_KEY);
|
|
56
|
-
const storedKey = hash(clientKey);
|
|
57
|
-
const clientSignature = hmac(storedKey, authMessage);
|
|
58
|
-
const clientProofBytes = xor(clientKey, clientSignature);
|
|
59
|
-
const clientProof = clientProofBytes.toString('base64');
|
|
60
|
-
const serverKey = hmac(saltPass, SERVER_KEY);
|
|
61
|
-
const serverSignatureBytes = hmac(serverKey, authMessage);
|
|
62
|
-
session.serverSignature = serverSignatureBytes.toString('base64');
|
|
63
|
-
session.clientFinalMessage =
|
|
64
|
-
clientFinalMessageWithoutProof + ',p=' + clientProof;
|
|
65
|
-
}
|
|
66
|
-
SASL.continueSession = continueSession;
|
|
67
|
-
function finalizeSession(session, data) {
|
|
68
|
-
let serverSignature = '';
|
|
69
|
-
const arr = data.split(',');
|
|
70
|
-
for (const s of arr) {
|
|
71
|
-
if (s[0] === 'v')
|
|
72
|
-
serverSignature = s.substr(2);
|
|
73
|
-
}
|
|
74
|
-
if (serverSignature !== session.serverSignature)
|
|
75
|
-
throw new Error('SASL: Server signature does not match');
|
|
76
|
-
}
|
|
77
|
-
SASL.finalizeSession = finalizeSession;
|
|
78
|
-
const firstMessageBare = function (username, nonce) {
|
|
79
|
-
return `n=${username},r=${nonce}`;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Hi() is, essentially, PBKDF2 [RFC2898] with HMAC() as the
|
|
83
|
-
* pseudorandom function (PRF) and with dkLen == output length of
|
|
84
|
-
* HMAC() == output length of H()
|
|
85
|
-
*/
|
|
86
|
-
const hi = function (text, salt, iterations) {
|
|
87
|
-
return crypto_1.default.pbkdf2Sync(text, Buffer.from(salt, 'base64'), iterations, 32, 'sha256');
|
|
88
|
-
};
|
|
89
|
-
const encode64 = (str) => Buffer.from(str).toString('base64');
|
|
90
|
-
const hmac = function (key, msg) {
|
|
91
|
-
return crypto_1.default.createHmac('sha256', key).update(msg).digest();
|
|
92
|
-
};
|
|
93
|
-
const hash = function (data) {
|
|
94
|
-
return crypto_1.default.createHash('sha256').update(data).digest();
|
|
95
|
-
};
|
|
96
|
-
const xor = function (a, b) {
|
|
97
|
-
a = Buffer.isBuffer(a) ? a : Buffer.from(a);
|
|
98
|
-
b = Buffer.isBuffer(b) ? b : Buffer.from(b);
|
|
99
|
-
if (a.length !== b.length)
|
|
100
|
-
throw new Error('Buffers must be of the same length');
|
|
101
|
-
const l = a.length;
|
|
102
|
-
const out = Buffer.allocUnsafe(l);
|
|
103
|
-
for (let i = 0; i < l; i++) {
|
|
104
|
-
out[i] = a[i] ^ b[i];
|
|
105
|
-
}
|
|
106
|
-
return out;
|
|
107
|
-
};
|
|
108
|
-
})(SASL || (exports.SASL = SASL = {}));
|
|
@@ -1,172 +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.growSize(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.growSize(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.growSize(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.growSize(len);
|
|
95
|
-
this.offset += this.buffer.write(str, this.offset, encoding);
|
|
96
|
-
}
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
writeInt8(n) {
|
|
100
|
-
this.growSize(1);
|
|
101
|
-
this.buffer.writeInt8(n, this.offset);
|
|
102
|
-
this.offset++;
|
|
103
|
-
return this;
|
|
104
|
-
}
|
|
105
|
-
writeUInt8(n) {
|
|
106
|
-
this.growSize(1);
|
|
107
|
-
this.buffer.writeUInt8(n, this.offset);
|
|
108
|
-
this.offset++;
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
writeUInt16BE(n) {
|
|
112
|
-
this.growSize(2);
|
|
113
|
-
this.buffer.writeUInt16BE(n, this.offset);
|
|
114
|
-
this.offset += 2;
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
|
-
writeUInt32BE(n) {
|
|
118
|
-
this.growSize(4);
|
|
119
|
-
this.buffer.writeUInt32BE(n, this.offset);
|
|
120
|
-
this.offset += 4;
|
|
121
|
-
return this;
|
|
122
|
-
}
|
|
123
|
-
writeInt16BE(n) {
|
|
124
|
-
this.growSize(2);
|
|
125
|
-
this.buffer.writeInt16BE(n, this.offset);
|
|
126
|
-
this.offset += 2;
|
|
127
|
-
return this;
|
|
128
|
-
}
|
|
129
|
-
writeInt32BE(n) {
|
|
130
|
-
this.growSize(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.growSize(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.growSize(4);
|
|
147
|
-
this.buffer.writeFloatBE(n, this.offset);
|
|
148
|
-
this.offset += 4;
|
|
149
|
-
return this;
|
|
150
|
-
}
|
|
151
|
-
writeDoubleBE(n) {
|
|
152
|
-
this.growSize(8);
|
|
153
|
-
this.buffer.writeDoubleBE(n, this.offset);
|
|
154
|
-
this.offset += 8;
|
|
155
|
-
return this;
|
|
156
|
-
}
|
|
157
|
-
writeBuffer(buffer) {
|
|
158
|
-
this.growSize(buffer.length);
|
|
159
|
-
buffer.copy(this.buffer, this.offset, 0, buffer.length);
|
|
160
|
-
this.offset += buffer.length;
|
|
161
|
-
return this;
|
|
162
|
-
}
|
|
163
|
-
_houseKeep() {
|
|
164
|
-
const needSize = this._stMaxPages * this.pageSize;
|
|
165
|
-
if (this.buffer.length > needSize)
|
|
166
|
-
this.buffer = Buffer.allocUnsafe(needSize);
|
|
167
|
-
this._stMaxPages = this.length ? Math.ceil(this.length / this.pageSize) : 1;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
exports.SmartBuffer = SmartBuffer;
|
|
171
|
-
SmartBuffer.DEFAULT_PAGE_SIZE = 4096;
|
|
172
|
-
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,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
|
-
}
|