postgresql-client
Advanced tools
Comparing version 2.11.0 to 2.11.2
@@ -0,1 +1,13 @@ | ||
# v2.11.2 | ||
[2024-06-29] | ||
# v2.11.1 | ||
[2024-06-29] | ||
### Changes | ||
* Migrated eslint config to @panates/eslint-config ([`718f5fd`](https://github.com/panates/postgresql-client/commit/718f5fd396f8966aef59ca3bcb4ecc6c52e8abce)) | ||
* Migrated eslint config to @panates/eslint-config ([`fb618e0`](https://github.com/panates/postgresql-client/commit/fb618e0b606ce917b482ab8ae7bba1397ec10c2e)) | ||
* Updated Node version ([`3fde2b9`](https://github.com/panates/postgresql-client/commit/3fde2b95b80567178fd6cf3f13f4f4b5d05f713c)) | ||
# v2.11.0 | ||
@@ -2,0 +14,0 @@ [2024-04-23] |
@@ -89,3 +89,3 @@ "use strict"; | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -96,2 +96,3 @@ location: 'Connection.close', | ||
}); | ||
} | ||
this._closing = true; | ||
@@ -102,3 +103,3 @@ if (this._intlCon.refCount > 0 && typeof terminateWait === 'number' && terminateWait > 0) { | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -109,2 +110,3 @@ location: 'Connection.close', | ||
}); | ||
} | ||
const timer = setInterval(() => { | ||
@@ -115,3 +117,3 @@ if (this._intlCon.refCount <= 0 || Date.now() > startTime + terminateWait) { | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -122,2 +124,3 @@ location: 'Connection.close', | ||
}); | ||
} | ||
this.emit('terminate'); | ||
@@ -146,3 +149,3 @@ } | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -154,2 +157,3 @@ location: 'Connection.query', | ||
}); | ||
} | ||
const typeMap = options?.typeMap || data_type_map_js_1.GlobalTypeMap; | ||
@@ -175,3 +179,3 @@ const paramTypes = options?.params?.map(prm => prm instanceof bind_param_js_1.BindParam ? prm.oid : typeMap.determine(prm)); | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -183,2 +187,3 @@ location: 'Connection.prepare', | ||
}); | ||
} | ||
return await this._captureErrorStack(prepared_statement_js_1.PreparedStatement.prepare(this, sql, options)); | ||
@@ -185,0 +190,0 @@ } |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Cursor = void 0; | ||
const doublylinked_1 = __importDefault(require("doublylinked")); | ||
const tslib_1 = require("tslib"); | ||
const doublylinked_1 = tslib_1.__importDefault(require("doublylinked")); | ||
const power_tasks_1 = require("power-tasks"); | ||
@@ -9,0 +7,0 @@ const safe_event_emitter_js_1 = require("../safe-event-emitter.js"); |
@@ -115,4 +115,5 @@ "use strict"; | ||
await this._execute('COMMIT'); | ||
else if (this.inTransaction && rollbackOnError) | ||
else if (this.inTransaction && rollbackOnError) { | ||
await this._execute('RELEASE ' + this._onErrorSavePoint + ';'); | ||
} | ||
return result; | ||
@@ -198,10 +199,12 @@ } | ||
case protocol_js_1.Protocol.BackendMessageCode.DataRow: | ||
let row = msg.columns.map((x) => x.toString('utf8')); | ||
(0, parse_row_js_1.parseRow)(parsers, row, opts); | ||
if (opts.objectRows && current.fields) | ||
row = (0, convert_row_to_object_js_1.convertRowToObject)(current.fields, row); | ||
if (cb) | ||
cb('row', row); | ||
current.rows = current.rows || []; | ||
current.rows.push(row); | ||
{ | ||
let row = msg.columns.map((x) => x.toString('utf8')); | ||
(0, parse_row_js_1.parseRow)(parsers, row, opts); | ||
if (opts.objectRows && current.fields) | ||
row = (0, convert_row_to_object_js_1.convertRowToObject)(current.fields, row); | ||
if (cb) | ||
cb('row', row); | ||
current.rows = current.rows || []; | ||
current.rows.push(row); | ||
} | ||
break; | ||
@@ -211,4 +214,5 @@ case protocol_js_1.Protocol.BackendMessageCode.CommandComplete: | ||
current.command = msg.command; | ||
if (current.command === 'DELETE' || current.command === 'INSERT' || current.command === 'UPDATE') | ||
if (current.command === 'DELETE' || current.command === 'INSERT' || current.command === 'UPDATE') { | ||
current.rowsAffected = msg.rowCount; | ||
} | ||
current.executeTime = Date.now() - currentStart; | ||
@@ -229,2 +233,5 @@ if (current.rows) | ||
done(undefined, result); | ||
break; | ||
default: | ||
break; | ||
} | ||
@@ -231,0 +238,0 @@ }); |
@@ -31,3 +31,3 @@ "use strict"; | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -38,2 +38,3 @@ location: 'Pool.factory.create', | ||
}); | ||
} | ||
const intlCon = new intl_connection_js_1.IntlConnection(cfg); | ||
@@ -43,3 +44,3 @@ await intlCon.connect(); | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -50,2 +51,3 @@ location: 'Pool.factory.create', | ||
}); | ||
} | ||
return intlCon; | ||
@@ -55,3 +57,3 @@ }, | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -62,2 +64,3 @@ location: 'Pool.factory.destroy', | ||
}); | ||
} | ||
return intlCon.close(); | ||
@@ -67,3 +70,3 @@ }, | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -74,2 +77,3 @@ location: 'Pool.factory.reset', | ||
}); | ||
} | ||
try { | ||
@@ -88,3 +92,3 @@ if (intlCon.state === constants_js_1.ConnectionState.READY) { | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -95,2 +99,3 @@ location: 'Pool.factory.validate', | ||
}); | ||
} | ||
if (intlCon.state !== constants_js_1.ConnectionState.READY) | ||
@@ -132,3 +137,3 @@ throw new Error('Connection is not active'); | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -139,2 +144,3 @@ location: 'Pool.acquire', | ||
}); | ||
} | ||
const connection = new connection_js_1.Connection(this, intlCon); | ||
@@ -141,0 +147,0 @@ /* istanbul ignore next */ |
@@ -106,9 +106,11 @@ "use strict"; | ||
await intlCon.execute('COMMIT'); | ||
else if (intlCon.inTransaction && rollbackOnError) | ||
else if (intlCon.inTransaction && rollbackOnError) { | ||
await intlCon.execute('RELEASE ' + this._onErrorSavePoint + ';'); | ||
} | ||
return result; | ||
} | ||
catch (e) { | ||
if (intlCon.inTransaction && rollbackOnError) | ||
if (intlCon.inTransaction && rollbackOnError) { | ||
await intlCon.execute('ROLLBACK TO ' + this._onErrorSavePoint + ';'); | ||
} | ||
throw e; | ||
@@ -173,4 +175,5 @@ } | ||
} | ||
if (result.command === 'DELETE' || result.command === 'INSERT' || result.command === 'UPDATE') | ||
if (result.command === 'DELETE' || result.command === 'INSERT' || result.command === 'UPDATE') { | ||
result.rowsAffected = executeResult.rowCount; | ||
} | ||
result.executeTime = Date.now() - startTime; | ||
@@ -177,0 +180,0 @@ return result; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ArrayByteaType = exports.ByteaType = void 0; | ||
const postgres_bytea_1 = __importDefault(require("postgres-bytea")); | ||
const tslib_1 = require("tslib"); | ||
const postgres_bytea_1 = tslib_1.__importDefault(require("postgres-bytea")); | ||
const constants_js_1 = require("../constants.js"); | ||
@@ -9,0 +7,0 @@ exports.ByteaType = { |
@@ -16,4 +16,5 @@ "use strict"; | ||
let d = new Date((lo + hi * timeMul) / 1000); | ||
if (fetchAsString || !options.utcDates) | ||
if (fetchAsString || !options.utcDates) { | ||
d = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()); | ||
} | ||
return fetchAsString ? dateToTimeString(d) : d; | ||
@@ -20,0 +21,0 @@ }, |
@@ -22,4 +22,5 @@ "use strict"; | ||
let d = new Date((lo + hi * timeMul) / 1000 + timeShift); | ||
if (fetchAsString || !options.utcDates) | ||
if (fetchAsString || !options.utcDates) { | ||
d = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()); | ||
} | ||
return fetchAsString ? dateToTimestampString(d) : d; | ||
@@ -26,0 +27,0 @@ }, |
@@ -22,4 +22,5 @@ "use strict"; | ||
let d = new Date((lo + hi * timeMul) / 1000 + timeShift); | ||
if (fetchAsString || !options.utcDates) | ||
if (fetchAsString || !options.utcDates) { | ||
d = new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()); | ||
} | ||
return fetchAsString ? dateToTimestamptzString(d) : d; | ||
@@ -26,0 +27,0 @@ }, |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./constants.js"), exports); | ||
__exportStar(require("./data-type-map.js"), exports); | ||
__exportStar(require("./types.js"), exports); | ||
__exportStar(require("./connection/bind-param.js"), exports); | ||
__exportStar(require("./connection/connection.js"), exports); | ||
__exportStar(require("./connection/cursor.js"), exports); | ||
__exportStar(require("./connection/pool.js"), exports); | ||
__exportStar(require("./connection/prepared-statement.js"), exports); | ||
__exportStar(require("./interfaces/command-result.js"), exports); | ||
__exportStar(require("./interfaces/data-mapping-options.js"), exports); | ||
__exportStar(require("./interfaces/data-type.js"), exports); | ||
__exportStar(require("./interfaces/database-connection-params.js"), exports); | ||
__exportStar(require("./interfaces/field-info.js"), exports); | ||
__exportStar(require("./interfaces/query-options.js"), exports); | ||
__exportStar(require("./interfaces/query-result.js"), exports); | ||
__exportStar(require("./interfaces/script-execute-options.js"), exports); | ||
__exportStar(require("./interfaces/script-result.js"), exports); | ||
__exportStar(require("./interfaces/statement-prepare-options.js"), exports); | ||
__exportStar(require("./util/connection-config.js"), exports); | ||
__exportStar(require("./util/escape-literal.js"), exports); | ||
__exportStar(require("./util/parse-datetime.js"), exports); | ||
__exportStar(require("./util/stringify-arrayliteral.js"), exports); | ||
__exportStar(require("./util/stringify-for-sql.js"), exports); | ||
__exportStar(require("./protocol/smart-buffer.js"), exports); | ||
__exportStar(require("./protocol/database-error.js"), exports); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./connection/bind-param.js"), exports); | ||
tslib_1.__exportStar(require("./connection/connection.js"), exports); | ||
tslib_1.__exportStar(require("./connection/cursor.js"), exports); | ||
tslib_1.__exportStar(require("./connection/pool.js"), exports); | ||
tslib_1.__exportStar(require("./connection/prepared-statement.js"), exports); | ||
tslib_1.__exportStar(require("./constants.js"), exports); | ||
tslib_1.__exportStar(require("./data-type-map.js"), exports); | ||
tslib_1.__exportStar(require("./interfaces/command-result.js"), exports); | ||
tslib_1.__exportStar(require("./interfaces/data-mapping-options.js"), exports); | ||
tslib_1.__exportStar(require("./interfaces/data-type.js"), exports); | ||
tslib_1.__exportStar(require("./interfaces/database-connection-params.js"), exports); | ||
tslib_1.__exportStar(require("./interfaces/field-info.js"), exports); | ||
tslib_1.__exportStar(require("./interfaces/query-options.js"), exports); | ||
tslib_1.__exportStar(require("./interfaces/query-result.js"), exports); | ||
tslib_1.__exportStar(require("./interfaces/script-execute-options.js"), exports); | ||
tslib_1.__exportStar(require("./interfaces/script-result.js"), exports); | ||
tslib_1.__exportStar(require("./interfaces/statement-prepare-options.js"), exports); | ||
tslib_1.__exportStar(require("./protocol/database-error.js"), exports); | ||
tslib_1.__exportStar(require("./protocol/smart-buffer.js"), exports); | ||
tslib_1.__exportStar(require("./types.js"), exports); | ||
tslib_1.__exportStar(require("./util/connection-config.js"), exports); | ||
tslib_1.__exportStar(require("./util/escape-literal.js"), exports); | ||
tslib_1.__exportStar(require("./util/parse-datetime.js"), exports); | ||
tslib_1.__exportStar(require("./util/stringify-arrayliteral.js"), exports); | ||
tslib_1.__exportStar(require("./util/stringify-for-sql.js"), exports); |
@@ -164,4 +164,5 @@ "use strict"; | ||
getDescribeMessage(args) { | ||
if (args.name && args.name.length > 63) | ||
throw new Error(args.type === 'P' ? 'Portal' : 'Statement' + 'name length must be lower than 63'); | ||
if (args.name && args.name.length > 63) { | ||
throw new Error(args.type === 'P' ? 'Portal' : 'Statement name length must be lower than 63'); | ||
} | ||
const io = this._io | ||
@@ -176,4 +177,5 @@ .start() | ||
getExecuteMessage(args) { | ||
if (args.fetchCount && (args.fetchCount < 0 || args.fetchCount > 4294967295)) | ||
if (args.fetchCount && (args.fetchCount < 0 || args.fetchCount > 4294967295)) { | ||
throw new Error('fetchCount can be between 0 and 4294967295'); | ||
} | ||
const io = this._io | ||
@@ -188,4 +190,5 @@ .start() | ||
getCloseMessage(args) { | ||
if (args.name && args.name.length > 63) | ||
throw new Error(args.type === 'P' ? 'Portal' : 'Statement' + 'name length must be lower than 63'); | ||
if (args.name && args.name.length > 63) { | ||
throw new Error(args.type === 'P' ? 'Portal' : 'Statement name length must be lower than 63'); | ||
} | ||
const io = this._io | ||
@@ -192,0 +195,0 @@ .start() |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PgSocket = void 0; | ||
const crypto_1 = __importDefault(require("crypto")); | ||
const net_1 = __importDefault(require("net")); | ||
const putil_promisify_1 = __importDefault(require("putil-promisify")); | ||
const tls_1 = __importDefault(require("tls")); | ||
const tslib_1 = require("tslib"); | ||
const crypto_1 = tslib_1.__importDefault(require("crypto")); | ||
const net_1 = tslib_1.__importDefault(require("net")); | ||
const putil_promisify_1 = tslib_1.__importDefault(require("putil-promisify")); | ||
const tls_1 = tslib_1.__importDefault(require("tls")); | ||
const constants_js_1 = require("../constants.js"); | ||
@@ -292,4 +290,5 @@ const safe_event_emitter_js_1 = require("../safe-event-emitter.js"); | ||
case protocol_js_1.Protocol.AuthenticationMessageKind.SASL: { | ||
if (!msg.mechanisms.includes('SCRAM-SHA-256')) | ||
if (!msg.mechanisms.includes('SCRAM-SHA-256')) { | ||
throw new Error('SASL: Only mechanism SCRAM-SHA-256 is currently supported'); | ||
} | ||
const saslSession = (this._saslSession = sasl_js_1.SASL.createSession(this.options.user || '', 'SCRAM-SHA-256')); | ||
@@ -318,2 +317,4 @@ this._send(this._frontend.getSASLMessage(saslSession)); | ||
} | ||
default: | ||
break; | ||
} | ||
@@ -320,0 +321,0 @@ } |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SASL = void 0; | ||
const tslib_1 = require("tslib"); | ||
/* eslint-disable no-bitwise */ | ||
const crypto_1 = __importDefault(require("crypto")); | ||
const crypto_1 = tslib_1.__importDefault(require("crypto")); | ||
var SASL; | ||
@@ -42,2 +40,4 @@ (function (SASL) { | ||
break; | ||
default: | ||
break; | ||
} | ||
@@ -79,5 +79,5 @@ } | ||
SASL.finalizeSession = finalizeSession; | ||
function firstMessageBare(username, nonce) { | ||
const firstMessageBare = function (username, nonce) { | ||
return `n=${username},r=${nonce}`; | ||
} | ||
}; | ||
/** | ||
@@ -88,13 +88,13 @@ * Hi() is, essentially, PBKDF2 [RFC2898] with HMAC() as the | ||
*/ | ||
function hi(text, salt, iterations) { | ||
const hi = function (text, salt, iterations) { | ||
return crypto_1.default.pbkdf2Sync(text, Buffer.from(salt, 'base64'), iterations, 32, 'sha256'); | ||
} | ||
}; | ||
const encode64 = str => Buffer.from(str).toString('base64'); | ||
function hmac(key, msg) { | ||
const hmac = function (key, msg) { | ||
return crypto_1.default.createHmac('sha256', key).update(msg).digest(); | ||
} | ||
function hash(data) { | ||
}; | ||
const hash = function (data) { | ||
return crypto_1.default.createHash('sha256').update(data).digest(); | ||
} | ||
function xor(a, b) { | ||
}; | ||
const xor = function (a, b) { | ||
a = Buffer.isBuffer(a) ? a : Buffer.from(a); | ||
@@ -110,3 +110,3 @@ b = Buffer.isBuffer(b) ? b : Buffer.from(b); | ||
return out; | ||
} | ||
}; | ||
})(SASL || (exports.SASL = SASL = {})); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SmartBuffer = void 0; | ||
const os = __importStar(require("os")); | ||
const tslib_1 = require("tslib"); | ||
const os = tslib_1.__importStar(require("os")); | ||
const bigint_methods_js_1 = require("../util/bigint-methods.js"); | ||
@@ -29,0 +7,0 @@ const buffer_reader_js_1 = require("./buffer-reader.js"); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseConnectionString = exports.getConnectionConfig = void 0; | ||
const putil_merge_1 = __importDefault(require("putil-merge")); | ||
const tslib_1 = require("tslib"); | ||
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge")); | ||
const config_from_env_js_1 = require("./config-from-env.js"); | ||
@@ -33,5 +31,3 @@ function getConnectionConfig(config) { | ||
const parsed = new URL(str); | ||
const getFirst = (v) => { | ||
return typeof v === 'string' ? v : Array.isArray(v) ? v[0] : ''; | ||
}; | ||
const getFirst = (v) => (typeof v === 'string' ? v : Array.isArray(v) ? v[0] : ''); | ||
const cfg = {}; | ||
@@ -58,4 +54,5 @@ cfg.host = decodeURI(parsed.hostname || ''); | ||
cfg.schema = decodeURI(getFirst(parsed.searchParams.get('schema'))); | ||
if (parsed.searchParams.get('application_name')) | ||
if (parsed.searchParams.get('application_name')) { | ||
cfg.applicationName = decodeURI(getFirst(parsed.searchParams.get('application_name'))); | ||
} | ||
if (parsed.username) | ||
@@ -62,0 +59,0 @@ cfg.user = parsed.username; |
@@ -86,3 +86,3 @@ import { ConnectionState } from '../constants.js'; | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -93,2 +93,3 @@ location: 'Connection.close', | ||
}); | ||
} | ||
this._closing = true; | ||
@@ -99,3 +100,3 @@ if (this._intlCon.refCount > 0 && typeof terminateWait === 'number' && terminateWait > 0) { | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -106,2 +107,3 @@ location: 'Connection.close', | ||
}); | ||
} | ||
const timer = setInterval(() => { | ||
@@ -112,3 +114,3 @@ if (this._intlCon.refCount <= 0 || Date.now() > startTime + terminateWait) { | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -119,2 +121,3 @@ location: 'Connection.close', | ||
}); | ||
} | ||
this.emit('terminate'); | ||
@@ -143,3 +146,3 @@ } | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -151,2 +154,3 @@ location: 'Connection.query', | ||
}); | ||
} | ||
const typeMap = options?.typeMap || GlobalTypeMap; | ||
@@ -172,3 +176,3 @@ const paramTypes = options?.params?.map(prm => prm instanceof BindParam ? prm.oid : typeMap.determine(prm)); | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -180,2 +184,3 @@ location: 'Connection.prepare', | ||
}); | ||
} | ||
return await this._captureErrorStack(PreparedStatement.prepare(this, sql, options)); | ||
@@ -182,0 +187,0 @@ } |
@@ -112,4 +112,5 @@ import { TaskQueue } from 'power-tasks'; | ||
await this._execute('COMMIT'); | ||
else if (this.inTransaction && rollbackOnError) | ||
else if (this.inTransaction && rollbackOnError) { | ||
await this._execute('RELEASE ' + this._onErrorSavePoint + ';'); | ||
} | ||
return result; | ||
@@ -195,10 +196,12 @@ } | ||
case Protocol.BackendMessageCode.DataRow: | ||
let row = msg.columns.map((x) => x.toString('utf8')); | ||
parseRow(parsers, row, opts); | ||
if (opts.objectRows && current.fields) | ||
row = convertRowToObject(current.fields, row); | ||
if (cb) | ||
cb('row', row); | ||
current.rows = current.rows || []; | ||
current.rows.push(row); | ||
{ | ||
let row = msg.columns.map((x) => x.toString('utf8')); | ||
parseRow(parsers, row, opts); | ||
if (opts.objectRows && current.fields) | ||
row = convertRowToObject(current.fields, row); | ||
if (cb) | ||
cb('row', row); | ||
current.rows = current.rows || []; | ||
current.rows.push(row); | ||
} | ||
break; | ||
@@ -208,4 +211,5 @@ case Protocol.BackendMessageCode.CommandComplete: | ||
current.command = msg.command; | ||
if (current.command === 'DELETE' || current.command === 'INSERT' || current.command === 'UPDATE') | ||
if (current.command === 'DELETE' || current.command === 'INSERT' || current.command === 'UPDATE') { | ||
current.rowsAffected = msg.rowCount; | ||
} | ||
current.executeTime = Date.now() - currentStart; | ||
@@ -226,2 +230,5 @@ if (current.rows) | ||
done(undefined, result); | ||
break; | ||
default: | ||
break; | ||
} | ||
@@ -228,0 +235,0 @@ }); |
@@ -28,3 +28,3 @@ import { Pool as LightningPool } from 'lightning-pool'; | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -35,2 +35,3 @@ location: 'Pool.factory.create', | ||
}); | ||
} | ||
const intlCon = new IntlConnection(cfg); | ||
@@ -40,3 +41,3 @@ await intlCon.connect(); | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -47,2 +48,3 @@ location: 'Pool.factory.create', | ||
}); | ||
} | ||
return intlCon; | ||
@@ -52,3 +54,3 @@ }, | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -59,2 +61,3 @@ location: 'Pool.factory.destroy', | ||
}); | ||
} | ||
return intlCon.close(); | ||
@@ -64,3 +67,3 @@ }, | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -71,2 +74,3 @@ location: 'Pool.factory.reset', | ||
}); | ||
} | ||
try { | ||
@@ -85,3 +89,3 @@ if (intlCon.state === ConnectionState.READY) { | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -92,2 +96,3 @@ location: 'Pool.factory.validate', | ||
}); | ||
} | ||
if (intlCon.state !== ConnectionState.READY) | ||
@@ -129,3 +134,3 @@ throw new Error('Connection is not active'); | ||
/* istanbul ignore next */ | ||
if (this.listenerCount('debug')) | ||
if (this.listenerCount('debug')) { | ||
this.emit('debug', { | ||
@@ -136,2 +141,3 @@ location: 'Pool.acquire', | ||
}); | ||
} | ||
const connection = new Connection(this, intlCon); | ||
@@ -138,0 +144,0 @@ /* istanbul ignore next */ |
@@ -103,9 +103,11 @@ import { coerceToBoolean } from 'putil-varhelpers'; | ||
await intlCon.execute('COMMIT'); | ||
else if (intlCon.inTransaction && rollbackOnError) | ||
else if (intlCon.inTransaction && rollbackOnError) { | ||
await intlCon.execute('RELEASE ' + this._onErrorSavePoint + ';'); | ||
} | ||
return result; | ||
} | ||
catch (e) { | ||
if (intlCon.inTransaction && rollbackOnError) | ||
if (intlCon.inTransaction && rollbackOnError) { | ||
await intlCon.execute('ROLLBACK TO ' + this._onErrorSavePoint + ';'); | ||
} | ||
throw e; | ||
@@ -170,4 +172,5 @@ } | ||
} | ||
if (result.command === 'DELETE' || result.command === 'INSERT' || result.command === 'UPDATE') | ||
if (result.command === 'DELETE' || result.command === 'INSERT' || result.command === 'UPDATE') { | ||
result.rowsAffected = executeResult.rowCount; | ||
} | ||
result.executeTime = Date.now() - startTime; | ||
@@ -174,0 +177,0 @@ return result; |
@@ -13,4 +13,5 @@ import { DataTypeOIDs } from '../constants.js'; | ||
let d = new Date((lo + hi * timeMul) / 1000); | ||
if (fetchAsString || !options.utcDates) | ||
if (fetchAsString || !options.utcDates) { | ||
d = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()); | ||
} | ||
return fetchAsString ? dateToTimeString(d) : d; | ||
@@ -17,0 +18,0 @@ }, |
@@ -19,4 +19,5 @@ import { DataTypeOIDs } from '../constants.js'; | ||
let d = new Date((lo + hi * timeMul) / 1000 + timeShift); | ||
if (fetchAsString || !options.utcDates) | ||
if (fetchAsString || !options.utcDates) { | ||
d = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()); | ||
} | ||
return fetchAsString ? dateToTimestampString(d) : d; | ||
@@ -23,0 +24,0 @@ }, |
@@ -19,4 +19,5 @@ import { DataTypeOIDs } from '../constants.js'; | ||
let d = new Date((lo + hi * timeMul) / 1000 + timeShift); | ||
if (fetchAsString || !options.utcDates) | ||
if (fetchAsString || !options.utcDates) { | ||
d = new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()); | ||
} | ||
return fetchAsString ? dateToTimestamptzString(d) : d; | ||
@@ -23,0 +24,0 @@ }, |
@@ -1,4 +0,1 @@ | ||
export * from './constants.js'; | ||
export * from './data-type-map.js'; | ||
export * from './types.js'; | ||
export * from './connection/bind-param.js'; | ||
@@ -9,2 +6,4 @@ export * from './connection/connection.js'; | ||
export * from './connection/prepared-statement.js'; | ||
export * from './constants.js'; | ||
export * from './data-type-map.js'; | ||
export * from './interfaces/command-result.js'; | ||
@@ -20,2 +19,5 @@ export * from './interfaces/data-mapping-options.js'; | ||
export * from './interfaces/statement-prepare-options.js'; | ||
export * from './protocol/database-error.js'; | ||
export * from './protocol/smart-buffer.js'; | ||
export * from './types.js'; | ||
export * from './util/connection-config.js'; | ||
@@ -26,3 +28,1 @@ export * from './util/escape-literal.js'; | ||
export * from './util/stringify-for-sql.js'; | ||
export * from './protocol/smart-buffer.js'; | ||
export * from './protocol/database-error.js'; |
@@ -161,4 +161,5 @@ import { DEFAULT_COLUMN_FORMAT } from '../constants.js'; | ||
getDescribeMessage(args) { | ||
if (args.name && args.name.length > 63) | ||
throw new Error(args.type === 'P' ? 'Portal' : 'Statement' + 'name length must be lower than 63'); | ||
if (args.name && args.name.length > 63) { | ||
throw new Error(args.type === 'P' ? 'Portal' : 'Statement name length must be lower than 63'); | ||
} | ||
const io = this._io | ||
@@ -173,4 +174,5 @@ .start() | ||
getExecuteMessage(args) { | ||
if (args.fetchCount && (args.fetchCount < 0 || args.fetchCount > 4294967295)) | ||
if (args.fetchCount && (args.fetchCount < 0 || args.fetchCount > 4294967295)) { | ||
throw new Error('fetchCount can be between 0 and 4294967295'); | ||
} | ||
const io = this._io | ||
@@ -185,4 +187,5 @@ .start() | ||
getCloseMessage(args) { | ||
if (args.name && args.name.length > 63) | ||
throw new Error(args.type === 'P' ? 'Portal' : 'Statement' + 'name length must be lower than 63'); | ||
if (args.name && args.name.length > 63) { | ||
throw new Error(args.type === 'P' ? 'Portal' : 'Statement name length must be lower than 63'); | ||
} | ||
const io = this._io | ||
@@ -189,0 +192,0 @@ .start() |
@@ -286,4 +286,5 @@ import crypto from 'crypto'; | ||
case Protocol.AuthenticationMessageKind.SASL: { | ||
if (!msg.mechanisms.includes('SCRAM-SHA-256')) | ||
if (!msg.mechanisms.includes('SCRAM-SHA-256')) { | ||
throw new Error('SASL: Only mechanism SCRAM-SHA-256 is currently supported'); | ||
} | ||
const saslSession = (this._saslSession = SASL.createSession(this.options.user || '', 'SCRAM-SHA-256')); | ||
@@ -312,2 +313,4 @@ this._send(this._frontend.getSASLMessage(saslSession)); | ||
} | ||
default: | ||
break; | ||
} | ||
@@ -314,0 +317,0 @@ } |
@@ -36,2 +36,4 @@ /* eslint-disable no-bitwise */ | ||
break; | ||
default: | ||
break; | ||
} | ||
@@ -73,5 +75,5 @@ } | ||
SASL.finalizeSession = finalizeSession; | ||
function firstMessageBare(username, nonce) { | ||
const firstMessageBare = function (username, nonce) { | ||
return `n=${username},r=${nonce}`; | ||
} | ||
}; | ||
/** | ||
@@ -82,13 +84,13 @@ * Hi() is, essentially, PBKDF2 [RFC2898] with HMAC() as the | ||
*/ | ||
function hi(text, salt, iterations) { | ||
const hi = function (text, salt, iterations) { | ||
return crypto.pbkdf2Sync(text, Buffer.from(salt, 'base64'), iterations, 32, 'sha256'); | ||
} | ||
}; | ||
const encode64 = str => Buffer.from(str).toString('base64'); | ||
function hmac(key, msg) { | ||
const hmac = function (key, msg) { | ||
return crypto.createHmac('sha256', key).update(msg).digest(); | ||
} | ||
function hash(data) { | ||
}; | ||
const hash = function (data) { | ||
return crypto.createHash('sha256').update(data).digest(); | ||
} | ||
function xor(a, b) { | ||
}; | ||
const xor = function (a, b) { | ||
a = Buffer.isBuffer(a) ? a : Buffer.from(a); | ||
@@ -104,3 +106,3 @@ b = Buffer.isBuffer(b) ? b : Buffer.from(b); | ||
return out; | ||
} | ||
}; | ||
})(SASL || (SASL = {})); |
@@ -26,5 +26,3 @@ import merge from 'putil-merge'; | ||
const parsed = new URL(str); | ||
const getFirst = (v) => { | ||
return typeof v === 'string' ? v : Array.isArray(v) ? v[0] : ''; | ||
}; | ||
const getFirst = (v) => (typeof v === 'string' ? v : Array.isArray(v) ? v[0] : ''); | ||
const cfg = {}; | ||
@@ -51,4 +49,5 @@ cfg.host = decodeURI(parsed.hostname || ''); | ||
cfg.schema = decodeURI(getFirst(parsed.searchParams.get('schema'))); | ||
if (parsed.searchParams.get('application_name')) | ||
if (parsed.searchParams.get('application_name')) { | ||
cfg.applicationName = decodeURI(getFirst(parsed.searchParams.get('application_name'))); | ||
} | ||
if (parsed.username) | ||
@@ -55,0 +54,0 @@ cfg.user = parsed.username; |
{ | ||
"name": "postgresql-client", | ||
"description": "Enterprise level PostgreSQL client for JavaScript", | ||
"version": "2.11.0", | ||
"version": "2.11.2", | ||
"author": "Panates", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -179,3 +179,3 @@ ## postgresql-client | ||
## Node Compatibility | ||
- node >= 14.x | ||
- node >= 16.x | ||
@@ -182,0 +182,0 @@ |
@@ -1,4 +0,1 @@ | ||
export * from './constants.js'; | ||
export * from './data-type-map.js'; | ||
export * from './types.js'; | ||
export * from './connection/bind-param.js'; | ||
@@ -9,2 +6,4 @@ export * from './connection/connection.js'; | ||
export * from './connection/prepared-statement.js'; | ||
export * from './constants.js'; | ||
export * from './data-type-map.js'; | ||
export * from './interfaces/command-result.js'; | ||
@@ -20,2 +19,5 @@ export * from './interfaces/data-mapping-options.js'; | ||
export * from './interfaces/statement-prepare-options.js'; | ||
export * from './protocol/database-error.js'; | ||
export * from './protocol/smart-buffer.js'; | ||
export * from './types.js'; | ||
export * from './util/connection-config.js'; | ||
@@ -26,3 +28,1 @@ export * from './util/escape-literal.js'; | ||
export * from './util/stringify-for-sql.js'; | ||
export * from './protocol/smart-buffer.js'; | ||
export * from './protocol/database-error.js'; |
10132
418477