UNPKG

@bs-plugins/postgresql

Version:

Bamboo Shell plugin for PostgreSQL

1 lines 338 kB
{"version":3,"file":"plugin.mjs","sources":["../../../node_modules/.pnpm/postgres-array@2.0.0/node_modules/postgres-array/index.js","../../../node_modules/.pnpm/pg-types@2.2.0/node_modules/pg-types/lib/arrayParser.js","../../../node_modules/.pnpm/postgres-date@1.0.7/node_modules/postgres-date/index.js","../../../node_modules/.pnpm/xtend@4.0.2/node_modules/xtend/mutable.js","../../../node_modules/.pnpm/postgres-interval@1.2.0/node_modules/postgres-interval/index.js","../../../node_modules/.pnpm/postgres-bytea@1.0.0/node_modules/postgres-bytea/index.js","../../../node_modules/.pnpm/pg-types@2.2.0/node_modules/pg-types/lib/textParsers.js","../../../node_modules/.pnpm/pg-int8@1.0.1/node_modules/pg-int8/index.js","../../../node_modules/.pnpm/pg-types@2.2.0/node_modules/pg-types/lib/binaryParsers.js","../../../node_modules/.pnpm/pg-types@2.2.0/node_modules/pg-types/lib/builtins.js","../../../node_modules/.pnpm/pg-types@2.2.0/node_modules/pg-types/index.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/defaults.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/utils.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/crypto/utils-legacy.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/crypto/utils-webcrypto.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/crypto/utils.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/crypto/sasl.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/type-overrides.js","../../../node_modules/.pnpm/pg-connection-string@2.7.0/node_modules/pg-connection-string/index.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/connection-parameters.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/result.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/query.js","../../../node_modules/.pnpm/pg-protocol@1.7.0/node_modules/pg-protocol/dist/messages.js","../../../node_modules/.pnpm/pg-protocol@1.7.0/node_modules/pg-protocol/dist/buffer-writer.js","../../../node_modules/.pnpm/pg-protocol@1.7.0/node_modules/pg-protocol/dist/serializer.js","../../../node_modules/.pnpm/pg-protocol@1.7.0/node_modules/pg-protocol/dist/buffer-reader.js","../../../node_modules/.pnpm/pg-protocol@1.7.0/node_modules/pg-protocol/dist/parser.js","../../../node_modules/.pnpm/pg-protocol@1.7.0/node_modules/pg-protocol/dist/index.js","../../../node_modules/.pnpm/pg-cloudflare@1.1.1/node_modules/pg-cloudflare/dist/empty.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/stream.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/connection.js","../../../node_modules/.pnpm/split2@4.2.0/node_modules/split2/index.js","../../../node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/helper.js","../../../node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/index.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/client.js","../../../node_modules/.pnpm/pg-pool@3.7.0_pg@8.13.1/node_modules/pg-pool/index.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/native/query.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/native/client.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/native/index.js","../../../node_modules/.pnpm/pg@8.13.1/node_modules/pg/lib/index.js","../out/main.js"],"sourcesContent":["'use strict'\n\nexports.parse = function (source, transform) {\n return new ArrayParser(source, transform).parse()\n}\n\nclass ArrayParser {\n constructor (source, transform) {\n this.source = source\n this.transform = transform || identity\n this.position = 0\n this.entries = []\n this.recorded = []\n this.dimension = 0\n }\n\n isEof () {\n return this.position >= this.source.length\n }\n\n nextCharacter () {\n var character = this.source[this.position++]\n if (character === '\\\\') {\n return {\n value: this.source[this.position++],\n escaped: true\n }\n }\n return {\n value: character,\n escaped: false\n }\n }\n\n record (character) {\n this.recorded.push(character)\n }\n\n newEntry (includeEmpty) {\n var entry\n if (this.recorded.length > 0 || includeEmpty) {\n entry = this.recorded.join('')\n if (entry === 'NULL' && !includeEmpty) {\n entry = null\n }\n if (entry !== null) entry = this.transform(entry)\n this.entries.push(entry)\n this.recorded = []\n }\n }\n\n consumeDimensions () {\n if (this.source[0] === '[') {\n while (!this.isEof()) {\n var char = this.nextCharacter()\n if (char.value === '=') break\n }\n }\n }\n\n parse (nested) {\n var character, parser, quote\n this.consumeDimensions()\n while (!this.isEof()) {\n character = this.nextCharacter()\n if (character.value === '{' && !quote) {\n this.dimension++\n if (this.dimension > 1) {\n parser = new ArrayParser(this.source.substr(this.position - 1), this.transform)\n this.entries.push(parser.parse(true))\n this.position += parser.position - 2\n }\n } else if (character.value === '}' && !quote) {\n this.dimension--\n if (!this.dimension) {\n this.newEntry()\n if (nested) return this.entries\n }\n } else if (character.value === '\"' && !character.escaped) {\n if (quote) this.newEntry(true)\n quote = !quote\n } else if (character.value === ',' && !quote) {\n this.newEntry()\n } else {\n this.record(character.value)\n }\n }\n if (this.dimension !== 0) {\n throw new Error('array dimension not balanced')\n }\n return this.entries\n }\n}\n\nfunction identity (value) {\n return value\n}\n","var array = require('postgres-array');\n\nmodule.exports = {\n create: function (source, transform) {\n return {\n parse: function() {\n return array.parse(source, transform);\n }\n };\n }\n};\n","'use strict'\n\nvar DATE_TIME = /(\\d{1,})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,})?.*?( BC)?$/\nvar DATE = /^(\\d{1,})-(\\d{2})-(\\d{2})( BC)?$/\nvar TIME_ZONE = /([Z+-])(\\d{2})?:?(\\d{2})?:?(\\d{2})?/\nvar INFINITY = /^-?infinity$/\n\nmodule.exports = function parseDate (isoDate) {\n if (INFINITY.test(isoDate)) {\n // Capitalize to Infinity before passing to Number\n return Number(isoDate.replace('i', 'I'))\n }\n var matches = DATE_TIME.exec(isoDate)\n\n if (!matches) {\n // Force YYYY-MM-DD dates to be parsed as local time\n return getDate(isoDate) || null\n }\n\n var isBC = !!matches[8]\n var year = parseInt(matches[1], 10)\n if (isBC) {\n year = bcYearToNegativeYear(year)\n }\n\n var month = parseInt(matches[2], 10) - 1\n var day = matches[3]\n var hour = parseInt(matches[4], 10)\n var minute = parseInt(matches[5], 10)\n var second = parseInt(matches[6], 10)\n\n var ms = matches[7]\n ms = ms ? 1000 * parseFloat(ms) : 0\n\n var date\n var offset = timeZoneOffset(isoDate)\n if (offset != null) {\n date = new Date(Date.UTC(year, month, day, hour, minute, second, ms))\n\n // Account for years from 0 to 99 being interpreted as 1900-1999\n // by Date.UTC / the multi-argument form of the Date constructor\n if (is0To99(year)) {\n date.setUTCFullYear(year)\n }\n\n if (offset !== 0) {\n date.setTime(date.getTime() - offset)\n }\n } else {\n date = new Date(year, month, day, hour, minute, second, ms)\n\n if (is0To99(year)) {\n date.setFullYear(year)\n }\n }\n\n return date\n}\n\nfunction getDate (isoDate) {\n var matches = DATE.exec(isoDate)\n if (!matches) {\n return\n }\n\n var year = parseInt(matches[1], 10)\n var isBC = !!matches[4]\n if (isBC) {\n year = bcYearToNegativeYear(year)\n }\n\n var month = parseInt(matches[2], 10) - 1\n var day = matches[3]\n // YYYY-MM-DD will be parsed as local time\n var date = new Date(year, month, day)\n\n if (is0To99(year)) {\n date.setFullYear(year)\n }\n\n return date\n}\n\n// match timezones:\n// Z (UTC)\n// -05\n// +06:30\nfunction timeZoneOffset (isoDate) {\n if (isoDate.endsWith('+00')) {\n return 0\n }\n\n var zone = TIME_ZONE.exec(isoDate.split(' ')[1])\n if (!zone) return\n var type = zone[1]\n\n if (type === 'Z') {\n return 0\n }\n var sign = type === '-' ? -1 : 1\n var offset = parseInt(zone[2], 10) * 3600 +\n parseInt(zone[3] || 0, 10) * 60 +\n parseInt(zone[4] || 0, 10)\n\n return offset * sign * 1000\n}\n\nfunction bcYearToNegativeYear (year) {\n // Account for numerical difference between representations of BC years\n // See: https://github.com/bendrucker/postgres-date/issues/5\n return -(year - 1)\n}\n\nfunction is0To99 (num) {\n return num >= 0 && num < 100\n}\n","module.exports = extend\n\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\n\nfunction extend(target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i]\n\n for (var key in source) {\n if (hasOwnProperty.call(source, key)) {\n target[key] = source[key]\n }\n }\n }\n\n return target\n}\n","'use strict'\n\nvar extend = require('xtend/mutable')\n\nmodule.exports = PostgresInterval\n\nfunction PostgresInterval (raw) {\n if (!(this instanceof PostgresInterval)) {\n return new PostgresInterval(raw)\n }\n extend(this, parse(raw))\n}\nvar properties = ['seconds', 'minutes', 'hours', 'days', 'months', 'years']\nPostgresInterval.prototype.toPostgres = function () {\n var filtered = properties.filter(this.hasOwnProperty, this)\n\n // In addition to `properties`, we need to account for fractions of seconds.\n if (this.milliseconds && filtered.indexOf('seconds') < 0) {\n filtered.push('seconds')\n }\n\n if (filtered.length === 0) return '0'\n return filtered\n .map(function (property) {\n var value = this[property] || 0\n\n // Account for fractional part of seconds,\n // remove trailing zeroes.\n if (property === 'seconds' && this.milliseconds) {\n value = (value + this.milliseconds / 1000).toFixed(6).replace(/\\.?0+$/, '')\n }\n\n return value + ' ' + property\n }, this)\n .join(' ')\n}\n\nvar propertiesISOEquivalent = {\n years: 'Y',\n months: 'M',\n days: 'D',\n hours: 'H',\n minutes: 'M',\n seconds: 'S'\n}\nvar dateProperties = ['years', 'months', 'days']\nvar timeProperties = ['hours', 'minutes', 'seconds']\n// according to ISO 8601\nPostgresInterval.prototype.toISOString = PostgresInterval.prototype.toISO = function () {\n var datePart = dateProperties\n .map(buildProperty, this)\n .join('')\n\n var timePart = timeProperties\n .map(buildProperty, this)\n .join('')\n\n return 'P' + datePart + 'T' + timePart\n\n function buildProperty (property) {\n var value = this[property] || 0\n\n // Account for fractional part of seconds,\n // remove trailing zeroes.\n if (property === 'seconds' && this.milliseconds) {\n value = (value + this.milliseconds / 1000).toFixed(6).replace(/0+$/, '')\n }\n\n return value + propertiesISOEquivalent[property]\n }\n}\n\nvar NUMBER = '([+-]?\\\\d+)'\nvar YEAR = NUMBER + '\\\\s+years?'\nvar MONTH = NUMBER + '\\\\s+mons?'\nvar DAY = NUMBER + '\\\\s+days?'\nvar TIME = '([+-])?([\\\\d]*):(\\\\d\\\\d):(\\\\d\\\\d)\\\\.?(\\\\d{1,6})?'\nvar INTERVAL = new RegExp([YEAR, MONTH, DAY, TIME].map(function (regexString) {\n return '(' + regexString + ')?'\n})\n .join('\\\\s*'))\n\n// Positions of values in regex match\nvar positions = {\n years: 2,\n months: 4,\n days: 6,\n hours: 9,\n minutes: 10,\n seconds: 11,\n milliseconds: 12\n}\n// We can use negative time\nvar negatives = ['hours', 'minutes', 'seconds', 'milliseconds']\n\nfunction parseMilliseconds (fraction) {\n // add omitted zeroes\n var microseconds = fraction + '000000'.slice(fraction.length)\n return parseInt(microseconds, 10) / 1000\n}\n\nfunction parse (interval) {\n if (!interval) return {}\n var matches = INTERVAL.exec(interval)\n var isNegative = matches[8] === '-'\n return Object.keys(positions)\n .reduce(function (parsed, property) {\n var position = positions[property]\n var value = matches[position]\n // no empty string\n if (!value) return parsed\n // milliseconds are actually microseconds (up to 6 digits)\n // with omitted trailing zeroes.\n value = property === 'milliseconds'\n ? parseMilliseconds(value)\n : parseInt(value, 10)\n // no zeros\n if (!value) return parsed\n if (isNegative && ~negatives.indexOf(property)) {\n value *= -1\n }\n parsed[property] = value\n return parsed\n }, {})\n}\n","'use strict'\n\nmodule.exports = function parseBytea (input) {\n if (/^\\\\x/.test(input)) {\n // new 'hex' style response (pg >9.0)\n return new Buffer(input.substr(2), 'hex')\n }\n var output = ''\n var i = 0\n while (i < input.length) {\n if (input[i] !== '\\\\') {\n output += input[i]\n ++i\n } else {\n if (/[0-7]{3}/.test(input.substr(i + 1, 3))) {\n output += String.fromCharCode(parseInt(input.substr(i + 1, 3), 8))\n i += 4\n } else {\n var backslashes = 1\n while (i + backslashes < input.length && input[i + backslashes] === '\\\\') {\n backslashes++\n }\n for (var k = 0; k < Math.floor(backslashes / 2); ++k) {\n output += '\\\\'\n }\n i += Math.floor(backslashes / 2) * 2\n }\n }\n }\n return new Buffer(output, 'binary')\n}\n","var array = require('postgres-array')\nvar arrayParser = require('./arrayParser');\nvar parseDate = require('postgres-date');\nvar parseInterval = require('postgres-interval');\nvar parseByteA = require('postgres-bytea');\n\nfunction allowNull (fn) {\n return function nullAllowed (value) {\n if (value === null) return value\n return fn(value)\n }\n}\n\nfunction parseBool (value) {\n if (value === null) return value\n return value === 'TRUE' ||\n value === 't' ||\n value === 'true' ||\n value === 'y' ||\n value === 'yes' ||\n value === 'on' ||\n value === '1';\n}\n\nfunction parseBoolArray (value) {\n if (!value) return null\n return array.parse(value, parseBool)\n}\n\nfunction parseBaseTenInt (string) {\n return parseInt(string, 10)\n}\n\nfunction parseIntegerArray (value) {\n if (!value) return null\n return array.parse(value, allowNull(parseBaseTenInt))\n}\n\nfunction parseBigIntegerArray (value) {\n if (!value) return null\n return array.parse(value, allowNull(function (entry) {\n return parseBigInteger(entry).trim()\n }))\n}\n\nvar parsePointArray = function(value) {\n if(!value) { return null; }\n var p = arrayParser.create(value, function(entry) {\n if(entry !== null) {\n entry = parsePoint(entry);\n }\n return entry;\n });\n\n return p.parse();\n};\n\nvar parseFloatArray = function(value) {\n if(!value) { return null; }\n var p = arrayParser.create(value, function(entry) {\n if(entry !== null) {\n entry = parseFloat(entry);\n }\n return entry;\n });\n\n return p.parse();\n};\n\nvar parseStringArray = function(value) {\n if(!value) { return null; }\n\n var p = arrayParser.create(value);\n return p.parse();\n};\n\nvar parseDateArray = function(value) {\n if (!value) { return null; }\n\n var p = arrayParser.create(value, function(entry) {\n if (entry !== null) {\n entry = parseDate(entry);\n }\n return entry;\n });\n\n return p.parse();\n};\n\nvar parseIntervalArray = function(value) {\n if (!value) { return null; }\n\n var p = arrayParser.create(value, function(entry) {\n if (entry !== null) {\n entry = parseInterval(entry);\n }\n return entry;\n });\n\n return p.parse();\n};\n\nvar parseByteAArray = function(value) {\n if (!value) { return null; }\n\n return array.parse(value, allowNull(parseByteA));\n};\n\nvar parseInteger = function(value) {\n return parseInt(value, 10);\n};\n\nvar parseBigInteger = function(value) {\n var valStr = String(value);\n if (/^\\d+$/.test(valStr)) { return valStr; }\n return value;\n};\n\nvar parseJsonArray = function(value) {\n if (!value) { return null; }\n\n return array.parse(value, allowNull(JSON.parse));\n};\n\nvar parsePoint = function(value) {\n if (value[0] !== '(') { return null; }\n\n value = value.substring( 1, value.length - 1 ).split(',');\n\n return {\n x: parseFloat(value[0])\n , y: parseFloat(value[1])\n };\n};\n\nvar parseCircle = function(value) {\n if (value[0] !== '<' && value[1] !== '(') { return null; }\n\n var point = '(';\n var radius = '';\n var pointParsed = false;\n for (var i = 2; i < value.length - 1; i++){\n if (!pointParsed) {\n point += value[i];\n }\n\n if (value[i] === ')') {\n pointParsed = true;\n continue;\n } else if (!pointParsed) {\n continue;\n }\n\n if (value[i] === ','){\n continue;\n }\n\n radius += value[i];\n }\n var result = parsePoint(point);\n result.radius = parseFloat(radius);\n\n return result;\n};\n\nvar init = function(register) {\n register(20, parseBigInteger); // int8\n register(21, parseInteger); // int2\n register(23, parseInteger); // int4\n register(26, parseInteger); // oid\n register(700, parseFloat); // float4/real\n register(701, parseFloat); // float8/double\n register(16, parseBool);\n register(1082, parseDate); // date\n register(1114, parseDate); // timestamp without timezone\n register(1184, parseDate); // timestamp\n register(600, parsePoint); // point\n register(651, parseStringArray); // cidr[]\n register(718, parseCircle); // circle\n register(1000, parseBoolArray);\n register(1001, parseByteAArray);\n register(1005, parseIntegerArray); // _int2\n register(1007, parseIntegerArray); // _int4\n register(1028, parseIntegerArray); // oid[]\n register(1016, parseBigIntegerArray); // _int8\n register(1017, parsePointArray); // point[]\n register(1021, parseFloatArray); // _float4\n register(1022, parseFloatArray); // _float8\n register(1231, parseFloatArray); // _numeric\n register(1014, parseStringArray); //char\n register(1015, parseStringArray); //varchar\n register(1008, parseStringArray);\n register(1009, parseStringArray);\n register(1040, parseStringArray); // macaddr[]\n register(1041, parseStringArray); // inet[]\n register(1115, parseDateArray); // timestamp without time zone[]\n register(1182, parseDateArray); // _date\n register(1185, parseDateArray); // timestamp with time zone[]\n register(1186, parseInterval);\n register(1187, parseIntervalArray);\n register(17, parseByteA);\n register(114, JSON.parse.bind(JSON)); // json\n register(3802, JSON.parse.bind(JSON)); // jsonb\n register(199, parseJsonArray); // json[]\n register(3807, parseJsonArray); // jsonb[]\n register(3907, parseStringArray); // numrange[]\n register(2951, parseStringArray); // uuid[]\n register(791, parseStringArray); // money[]\n register(1183, parseStringArray); // time[]\n register(1270, parseStringArray); // timetz[]\n};\n\nmodule.exports = {\n init: init\n};\n","'use strict';\n\n// selected so (BASE - 1) * 0x100000000 + 0xffffffff is a safe integer\nvar BASE = 1000000;\n\nfunction readInt8(buffer) {\n\tvar high = buffer.readInt32BE(0);\n\tvar low = buffer.readUInt32BE(4);\n\tvar sign = '';\n\n\tif (high < 0) {\n\t\thigh = ~high + (low === 0);\n\t\tlow = (~low + 1) >>> 0;\n\t\tsign = '-';\n\t}\n\n\tvar result = '';\n\tvar carry;\n\tvar t;\n\tvar digits;\n\tvar pad;\n\tvar l;\n\tvar i;\n\n\t{\n\t\tcarry = high % BASE;\n\t\thigh = high / BASE >>> 0;\n\n\t\tt = 0x100000000 * carry + low;\n\t\tlow = t / BASE >>> 0;\n\t\tdigits = '' + (t - BASE * low);\n\n\t\tif (low === 0 && high === 0) {\n\t\t\treturn sign + digits + result;\n\t\t}\n\n\t\tpad = '';\n\t\tl = 6 - digits.length;\n\n\t\tfor (i = 0; i < l; i++) {\n\t\t\tpad += '0';\n\t\t}\n\n\t\tresult = pad + digits + result;\n\t}\n\n\t{\n\t\tcarry = high % BASE;\n\t\thigh = high / BASE >>> 0;\n\n\t\tt = 0x100000000 * carry + low;\n\t\tlow = t / BASE >>> 0;\n\t\tdigits = '' + (t - BASE * low);\n\n\t\tif (low === 0 && high === 0) {\n\t\t\treturn sign + digits + result;\n\t\t}\n\n\t\tpad = '';\n\t\tl = 6 - digits.length;\n\n\t\tfor (i = 0; i < l; i++) {\n\t\t\tpad += '0';\n\t\t}\n\n\t\tresult = pad + digits + result;\n\t}\n\n\t{\n\t\tcarry = high % BASE;\n\t\thigh = high / BASE >>> 0;\n\n\t\tt = 0x100000000 * carry + low;\n\t\tlow = t / BASE >>> 0;\n\t\tdigits = '' + (t - BASE * low);\n\n\t\tif (low === 0 && high === 0) {\n\t\t\treturn sign + digits + result;\n\t\t}\n\n\t\tpad = '';\n\t\tl = 6 - digits.length;\n\n\t\tfor (i = 0; i < l; i++) {\n\t\t\tpad += '0';\n\t\t}\n\n\t\tresult = pad + digits + result;\n\t}\n\n\t{\n\t\tcarry = high % BASE;\n\t\tt = 0x100000000 * carry + low;\n\t\tdigits = '' + t % BASE;\n\n\t\treturn sign + digits + result;\n\t}\n}\n\nmodule.exports = readInt8;\n","var parseInt64 = require('pg-int8');\n\nvar parseBits = function(data, bits, offset, invert, callback) {\n offset = offset || 0;\n invert = invert || false;\n callback = callback || function(lastValue, newValue, bits) { return (lastValue * Math.pow(2, bits)) + newValue; };\n var offsetBytes = offset >> 3;\n\n var inv = function(value) {\n if (invert) {\n return ~value & 0xff;\n }\n\n return value;\n };\n\n // read first (maybe partial) byte\n var mask = 0xff;\n var firstBits = 8 - (offset % 8);\n if (bits < firstBits) {\n mask = (0xff << (8 - bits)) & 0xff;\n firstBits = bits;\n }\n\n if (offset) {\n mask = mask >> (offset % 8);\n }\n\n var result = 0;\n if ((offset % 8) + bits >= 8) {\n result = callback(0, inv(data[offsetBytes]) & mask, firstBits);\n }\n\n // read bytes\n var bytes = (bits + offset) >> 3;\n for (var i = offsetBytes + 1; i < bytes; i++) {\n result = callback(result, inv(data[i]), 8);\n }\n\n // bits to read, that are not a complete byte\n var lastBits = (bits + offset) % 8;\n if (lastBits > 0) {\n result = callback(result, inv(data[bytes]) >> (8 - lastBits), lastBits);\n }\n\n return result;\n};\n\nvar parseFloatFromBits = function(data, precisionBits, exponentBits) {\n var bias = Math.pow(2, exponentBits - 1) - 1;\n var sign = parseBits(data, 1);\n var exponent = parseBits(data, exponentBits, 1);\n\n if (exponent === 0) {\n return 0;\n }\n\n // parse mantissa\n var precisionBitsCounter = 1;\n var parsePrecisionBits = function(lastValue, newValue, bits) {\n if (lastValue === 0) {\n lastValue = 1;\n }\n\n for (var i = 1; i <= bits; i++) {\n precisionBitsCounter /= 2;\n if ((newValue & (0x1 << (bits - i))) > 0) {\n lastValue += precisionBitsCounter;\n }\n }\n\n return lastValue;\n };\n\n var mantissa = parseBits(data, precisionBits, exponentBits + 1, false, parsePrecisionBits);\n\n // special cases\n if (exponent == (Math.pow(2, exponentBits + 1) - 1)) {\n if (mantissa === 0) {\n return (sign === 0) ? Infinity : -Infinity;\n }\n\n return NaN;\n }\n\n // normale number\n return ((sign === 0) ? 1 : -1) * Math.pow(2, exponent - bias) * mantissa;\n};\n\nvar parseInt16 = function(value) {\n if (parseBits(value, 1) == 1) {\n return -1 * (parseBits(value, 15, 1, true) + 1);\n }\n\n return parseBits(value, 15, 1);\n};\n\nvar parseInt32 = function(value) {\n if (parseBits(value, 1) == 1) {\n return -1 * (parseBits(value, 31, 1, true) + 1);\n }\n\n return parseBits(value, 31, 1);\n};\n\nvar parseFloat32 = function(value) {\n return parseFloatFromBits(value, 23, 8);\n};\n\nvar parseFloat64 = function(value) {\n return parseFloatFromBits(value, 52, 11);\n};\n\nvar parseNumeric = function(value) {\n var sign = parseBits(value, 16, 32);\n if (sign == 0xc000) {\n return NaN;\n }\n\n var weight = Math.pow(10000, parseBits(value, 16, 16));\n var result = 0;\n\n var digits = [];\n var ndigits = parseBits(value, 16);\n for (var i = 0; i < ndigits; i++) {\n result += parseBits(value, 16, 64 + (16 * i)) * weight;\n weight /= 10000;\n }\n\n var scale = Math.pow(10, parseBits(value, 16, 48));\n return ((sign === 0) ? 1 : -1) * Math.round(result * scale) / scale;\n};\n\nvar parseDate = function(isUTC, value) {\n var sign = parseBits(value, 1);\n var rawValue = parseBits(value, 63, 1);\n\n // discard usecs and shift from 2000 to 1970\n var result = new Date((((sign === 0) ? 1 : -1) * rawValue / 1000) + 946684800000);\n\n if (!isUTC) {\n result.setTime(result.getTime() + result.getTimezoneOffset() * 60000);\n }\n\n // add microseconds to the date\n result.usec = rawValue % 1000;\n result.getMicroSeconds = function() {\n return this.usec;\n };\n result.setMicroSeconds = function(value) {\n this.usec = value;\n };\n result.getUTCMicroSeconds = function() {\n return this.usec;\n };\n\n return result;\n};\n\nvar parseArray = function(value) {\n var dim = parseBits(value, 32);\n\n var flags = parseBits(value, 32, 32);\n var elementType = parseBits(value, 32, 64);\n\n var offset = 96;\n var dims = [];\n for (var i = 0; i < dim; i++) {\n // parse dimension\n dims[i] = parseBits(value, 32, offset);\n offset += 32;\n\n // ignore lower bounds\n offset += 32;\n }\n\n var parseElement = function(elementType) {\n // parse content length\n var length = parseBits(value, 32, offset);\n offset += 32;\n\n // parse null values\n if (length == 0xffffffff) {\n return null;\n }\n\n var result;\n if ((elementType == 0x17) || (elementType == 0x14)) {\n // int/bigint\n result = parseBits(value, length * 8, offset);\n offset += length * 8;\n return result;\n }\n else if (elementType == 0x19) {\n // string\n result = value.toString(this.encoding, offset >> 3, (offset += (length << 3)) >> 3);\n return result;\n }\n else {\n console.log(\"ERROR: ElementType not implemented: \" + elementType);\n }\n };\n\n var parse = function(dimension, elementType) {\n var array = [];\n var i;\n\n if (dimension.length > 1) {\n var count = dimension.shift();\n for (i = 0; i < count; i++) {\n array[i] = parse(dimension, elementType);\n }\n dimension.unshift(count);\n }\n else {\n for (i = 0; i < dimension[0]; i++) {\n array[i] = parseElement(elementType);\n }\n }\n\n return array;\n };\n\n return parse(dims, elementType);\n};\n\nvar parseText = function(value) {\n return value.toString('utf8');\n};\n\nvar parseBool = function(value) {\n if(value === null) return null;\n return (parseBits(value, 8) > 0);\n};\n\nvar init = function(register) {\n register(20, parseInt64);\n register(21, parseInt16);\n register(23, parseInt32);\n register(26, parseInt32);\n register(1700, parseNumeric);\n register(700, parseFloat32);\n register(701, parseFloat64);\n register(16, parseBool);\n register(1114, parseDate.bind(null, false));\n register(1184, parseDate.bind(null, true));\n register(1000, parseArray);\n register(1007, parseArray);\n register(1016, parseArray);\n register(1008, parseArray);\n register(1009, parseArray);\n register(25, parseText);\n};\n\nmodule.exports = {\n init: init\n};\n","/**\n * Following query was used to generate this file:\n\n SELECT json_object_agg(UPPER(PT.typname), PT.oid::int4 ORDER BY pt.oid)\n FROM pg_type PT\n WHERE typnamespace = (SELECT pgn.oid FROM pg_namespace pgn WHERE nspname = 'pg_catalog') -- Take only builting Postgres types with stable OID (extension types are not guaranted to be stable)\n AND typtype = 'b' -- Only basic types\n AND typelem = 0 -- Ignore aliases\n AND typisdefined -- Ignore undefined types\n */\n\nmodule.exports = {\n BOOL: 16,\n BYTEA: 17,\n CHAR: 18,\n INT8: 20,\n INT2: 21,\n INT4: 23,\n REGPROC: 24,\n TEXT: 25,\n OID: 26,\n TID: 27,\n XID: 28,\n CID: 29,\n JSON: 114,\n XML: 142,\n PG_NODE_TREE: 194,\n SMGR: 210,\n PATH: 602,\n POLYGON: 604,\n CIDR: 650,\n FLOAT4: 700,\n FLOAT8: 701,\n ABSTIME: 702,\n RELTIME: 703,\n TINTERVAL: 704,\n CIRCLE: 718,\n MACADDR8: 774,\n MONEY: 790,\n MACADDR: 829,\n INET: 869,\n ACLITEM: 1033,\n BPCHAR: 1042,\n VARCHAR: 1043,\n DATE: 1082,\n TIME: 1083,\n TIMESTAMP: 1114,\n TIMESTAMPTZ: 1184,\n INTERVAL: 1186,\n TIMETZ: 1266,\n BIT: 1560,\n VARBIT: 1562,\n NUMERIC: 1700,\n REFCURSOR: 1790,\n REGPROCEDURE: 2202,\n REGOPER: 2203,\n REGOPERATOR: 2204,\n REGCLASS: 2205,\n REGTYPE: 2206,\n UUID: 2950,\n TXID_SNAPSHOT: 2970,\n PG_LSN: 3220,\n PG_NDISTINCT: 3361,\n PG_DEPENDENCIES: 3402,\n TSVECTOR: 3614,\n TSQUERY: 3615,\n GTSVECTOR: 3642,\n REGCONFIG: 3734,\n REGDICTIONARY: 3769,\n JSONB: 3802,\n REGNAMESPACE: 4089,\n REGROLE: 4096\n};\n","var textParsers = require('./lib/textParsers');\nvar binaryParsers = require('./lib/binaryParsers');\nvar arrayParser = require('./lib/arrayParser');\nvar builtinTypes = require('./lib/builtins');\n\nexports.getTypeParser = getTypeParser;\nexports.setTypeParser = setTypeParser;\nexports.arrayParser = arrayParser;\nexports.builtins = builtinTypes;\n\nvar typeParsers = {\n text: {},\n binary: {}\n};\n\n//the empty parse function\nfunction noParse (val) {\n return String(val);\n};\n\n//returns a function used to convert a specific type (specified by\n//oid) into a result javascript type\n//note: the oid can be obtained via the following sql query:\n//SELECT oid FROM pg_type WHERE typname = 'TYPE_NAME_HERE';\nfunction getTypeParser (oid, format) {\n format = format || 'text';\n if (!typeParsers[format]) {\n return noParse;\n }\n return typeParsers[format][oid] || noParse;\n};\n\nfunction setTypeParser (oid, format, parseFn) {\n if(typeof format == 'function') {\n parseFn = format;\n format = 'text';\n }\n typeParsers[format][oid] = parseFn;\n};\n\ntextParsers.init(function(oid, converter) {\n typeParsers.text[oid] = converter;\n});\n\nbinaryParsers.init(function(oid, converter) {\n typeParsers.binary[oid] = converter;\n});\n","'use strict'\n\nmodule.exports = {\n // database host. defaults to localhost\n host: 'localhost',\n\n // database user's name\n user: process.platform === 'win32' ? process.env.USERNAME : process.env.USER,\n\n // name of database to connect\n database: undefined,\n\n // database user's password\n password: null,\n\n // a Postgres connection string to be used instead of setting individual connection items\n // NOTE: Setting this value will cause it to override any other value (such as database or user) defined\n // in the defaults object.\n connectionString: undefined,\n\n // database port\n port: 5432,\n\n // number of rows to return at a time from a prepared statement's\n // portal. 0 will return all rows at once\n rows: 0,\n\n // binary result mode\n binary: false,\n\n // Connection pool options - see https://github.com/brianc/node-pg-pool\n\n // number of connections to use in connection pool\n // 0 will disable connection pooling\n max: 10,\n\n // max milliseconds a client can go unused before it is removed\n // from the pool and destroyed\n idleTimeoutMillis: 30000,\n\n client_encoding: '',\n\n ssl: false,\n\n application_name: undefined,\n\n fallback_application_name: undefined,\n\n options: undefined,\n\n parseInputDatesAsUTC: false,\n\n // max milliseconds any query using this connection will execute for before timing out in error.\n // false=unlimited\n statement_timeout: false,\n\n // Abort any statement that waits longer than the specified duration in milliseconds while attempting to acquire a lock.\n // false=unlimited\n lock_timeout: false,\n\n // Terminate any session with an open transaction that has been idle for longer than the specified duration in milliseconds\n // false=unlimited\n idle_in_transaction_session_timeout: false,\n\n // max milliseconds to wait for query to complete (client side)\n query_timeout: false,\n\n connect_timeout: 0,\n\n keepalives: 1,\n\n keepalives_idle: 0,\n}\n\nvar pgTypes = require('pg-types')\n// save default parsers\nvar parseBigInteger = pgTypes.getTypeParser(20, 'text')\nvar parseBigIntegerArray = pgTypes.getTypeParser(1016, 'text')\n\n// parse int8 so you can get your count values as actual numbers\nmodule.exports.__defineSetter__('parseInt8', function (val) {\n pgTypes.setTypeParser(20, 'text', val ? pgTypes.getTypeParser(23, 'text') : parseBigInteger)\n pgTypes.setTypeParser(1016, 'text', val ? pgTypes.getTypeParser(1007, 'text') : parseBigIntegerArray)\n})\n","'use strict'\n\nconst defaults = require('./defaults')\n\nfunction escapeElement(elementRepresentation) {\n var escaped = elementRepresentation.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"')\n\n return '\"' + escaped + '\"'\n}\n\n// convert a JS array to a postgres array literal\n// uses comma separator so won't work for types like box that use\n// a different array separator.\nfunction arrayString(val) {\n var result = '{'\n for (var i = 0; i < val.length; i++) {\n if (i > 0) {\n result = result + ','\n }\n if (val[i] === null || typeof val[i] === 'undefined') {\n result = result + 'NULL'\n } else if (Array.isArray(val[i])) {\n result = result + arrayString(val[i])\n } else if (ArrayBuffer.isView(val[i])) {\n var item = val[i]\n if (!(item instanceof Buffer)) {\n var buf = Buffer.from(item.buffer, item.byteOffset, item.byteLength)\n if (buf.length === item.byteLength) {\n item = buf\n } else {\n item = buf.slice(item.byteOffset, item.byteOffset + item.byteLength)\n }\n }\n result += '\\\\\\\\x' + item.toString('hex')\n } else {\n result += escapeElement(prepareValue(val[i]))\n }\n }\n result = result + '}'\n return result\n}\n\n// converts values from javascript types\n// to their 'raw' counterparts for use as a postgres parameter\n// note: you can override this function to provide your own conversion mechanism\n// for complex types, etc...\nvar prepareValue = function (val, seen) {\n // null and undefined are both null for postgres\n if (val == null) {\n return null\n }\n if (val instanceof Buffer) {\n return val\n }\n if (ArrayBuffer.isView(val)) {\n var buf = Buffer.from(val.buffer, val.byteOffset, val.byteLength)\n if (buf.length === val.byteLength) {\n return buf\n }\n return buf.slice(val.byteOffset, val.byteOffset + val.byteLength) // Node.js v4 does not support those Buffer.from params\n }\n if (val instanceof Date) {\n if (defaults.parseInputDatesAsUTC) {\n return dateToStringUTC(val)\n } else {\n return dateToString(val)\n }\n }\n if (Array.isArray(val)) {\n return arrayString(val)\n }\n if (typeof val === 'object') {\n return prepareObject(val, seen)\n }\n return val.toString()\n}\n\nfunction prepareObject(val, seen) {\n if (val && typeof val.toPostgres === 'function') {\n seen = seen || []\n if (seen.indexOf(val) !== -1) {\n throw new Error('circular reference detected while preparing \"' + val + '\" for query')\n }\n seen.push(val)\n\n return prepareValue(val.toPostgres(prepareValue), seen)\n }\n return JSON.stringify(val)\n}\n\nfunction pad(number, digits) {\n number = '' + number\n while (number.length < digits) {\n number = '0' + number\n }\n return number\n}\n\nfunction dateToString(date) {\n var offset = -date.getTimezoneOffset()\n\n var year = date.getFullYear()\n var isBCYear = year < 1\n if (isBCYear) year = Math.abs(year) + 1 // negative years are 1 off their BC representation\n\n var ret =\n pad(year, 4) +\n '-' +\n pad(date.getMonth() + 1, 2) +\n '-' +\n pad(date.getDate(), 2) +\n 'T' +\n pad(date.getHours(), 2) +\n ':' +\n pad(date.getMinutes(), 2) +\n ':' +\n pad(date.getSeconds(), 2) +\n '.' +\n pad(date.getMilliseconds(), 3)\n\n if (offset < 0) {\n ret += '-'\n offset *= -1\n } else {\n ret += '+'\n }\n\n ret += pad(Math.floor(offset / 60), 2) + ':' + pad(offset % 60, 2)\n if (isBCYear) ret += ' BC'\n return ret\n}\n\nfunction dateToStringUTC(date) {\n var year = date.getUTCFullYear()\n var isBCYear = year < 1\n if (isBCYear) year = Math.abs(year) + 1 // negative years are 1 off their BC representation\n\n var ret =\n pad(year, 4) +\n '-' +\n pad(date.getUTCMonth() + 1, 2) +\n '-' +\n pad(date.getUTCDate(), 2) +\n 'T' +\n pad(date.getUTCHours(), 2) +\n ':' +\n pad(date.getUTCMinutes(), 2) +\n ':' +\n pad(date.getUTCSeconds(), 2) +\n '.' +\n pad(date.getUTCMilliseconds(), 3)\n\n ret += '+00:00'\n if (isBCYear) ret += ' BC'\n return ret\n}\n\nfunction normalizeQueryConfig(config, values, callback) {\n // can take in strings or config objects\n config = typeof config === 'string' ? { text: config } : config\n if (values) {\n if (typeof values === 'function') {\n config.callback = values\n } else {\n config.values = values\n }\n }\n if (callback) {\n config.callback = callback\n }\n return config\n}\n\n// Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c\nconst escapeIdentifier = function (str) {\n return '\"' + str.replace(/\"/g, '\"\"') + '\"'\n}\n\nconst escapeLiteral = function (str) {\n var hasBackslash = false\n var escaped = \"'\"\n\n for (var i = 0; i < str.length; i++) {\n var c = str[i]\n if (c === \"'\") {\n escaped += c + c\n } else if (c === '\\\\') {\n escaped += c + c\n hasBackslash = true\n } else {\n escaped += c\n }\n }\n\n escaped += \"'\"\n\n if (hasBackslash === true) {\n escaped = ' E' + escaped\n }\n\n return escaped\n}\n\nmodule.exports = {\n prepareValue: function prepareValueWrapper(value) {\n // this ensures that extra arguments do not get passed into prepareValue\n // by accident, eg: from calling values.map(utils.prepareValue)\n return prepareValue(value)\n },\n normalizeQueryConfig,\n escapeIdentifier,\n escapeLiteral,\n}\n","'use strict'\n// This file contains crypto utility functions for versions of Node.js < 15.0.0,\n// which does not support the WebCrypto.subtle API.\n\nconst nodeCrypto = require('crypto')\n\nfunction md5(string) {\n return nodeCrypto.createHash('md5').update(string, 'utf-8').digest('hex')\n}\n\n// See AuthenticationMD5Password at https://www.postgresql.org/docs/current/static/protocol-flow.html\nfunction postgresMd5PasswordHash(user, password, salt) {\n var inner = md5(password + user)\n var outer = md5(Buffer.concat([Buffer.from(inner), salt]))\n return 'md5' + outer\n}\n\nfunction sha256(text) {\n return nodeCrypto.createHash('sha256').update(text).digest()\n}\n\nfunction hmacSha256(key, msg) {\n return nodeCrypto.createHmac('sha256', key).update(msg).digest()\n}\n\nasync function deriveKey(password, salt, iterations) {\n return nodeCrypto.pbkdf2Sync(password, salt, iterations, 32, 'sha256')\n}\n\nmodule.exports = {\n postgresMd5PasswordHash,\n randomBytes: nodeCrypto.randomBytes,\n deriveKey,\n sha256,\n hmacSha256,\n md5,\n}\n","const nodeCrypto = require('crypto')\n\nmodule.exports = {\n postgresMd5PasswordHash,\n randomBytes,\n deriveKey,\n sha256,\n hmacSha256,\n md5,\n}\n\n/**\n * The Web Crypto API - grabbed from the Node.js library or the global\n * @type Crypto\n */\nconst webCrypto = nodeCrypto.webcrypto || globalThis.crypto\n/**\n * The SubtleCrypto API for low level crypto operations.\n * @type SubtleCrypto\n */\nconst subtleCrypto = webCrypto.subtle\nconst textEncoder = new TextEncoder()\n\n/**\n *\n * @param {*} length\n * @returns\n */\nfunction randomBytes(length) {\n return webCrypto.getRandomValues(Buffer.alloc(length))\n}\n\nasync function md5(string) {\n try {\n return nodeCrypto.createHash('md5').update(string, 'utf-8').digest('hex')\n } catch (e) {\n // `createHash()` failed so we are probably not in Node.js, use the WebCrypto API instead.\n // Note that the MD5 algorithm on WebCrypto is not available in Node.js.\n // This is why we cannot just use WebCrypto in all environments.\n const data = typeof string === 'string' ? textEncoder.encode(string) : string\n const hash = await subtleCrypto.digest('MD5', data)\n return Array.from(new Uint8Array(hash))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n }\n}\n\n// See AuthenticationMD5Password at https://www.postgresql.org/docs/current/static/protocol-flow.html\nasync function postgresMd5PasswordHash(user, password, salt) {\n var inner = await md5(password + user)\n var outer = await md5(Buffer.concat([Buffer.from(inner), salt]))\n return 'md5' + outer\n}\n\n/**\n * Create a SHA-256 digest of the given data\n * @param {Buffer} data\n */\nasync function sha256(text) {\n return await subtleCrypto.digest('SHA-256', text)\n}\n\n/**\n * Sign the message with the given key\n * @param {ArrayBuffer} keyBuffer\n * @param {string} msg\n */\nasync function hmacSha256(keyBuffer, msg) {\n const key = await subtleCrypto.importKey('raw', keyBuffer, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'])\n return await subtleCrypto.sign('HMAC', key, textEncoder.encode(msg))\n}\n\n/**\n * Derive a key from the password and salt\n * @param {string} password\n * @param {Uint8Array} salt\n * @param {number} iterations\n */\nasync function deriveKey(password, salt, iterations) {\n const key = await subtleCrypto.importKey('raw', textEncoder.encode(password), 'PBKDF2', false, ['deriveBits'])\n const params = { name: 'PBKDF2', hash: 'SHA-256', salt: salt, iterations: iterations }\n return await subtleCrypto.deriveBits(params, key, 32 * 8, ['deriveBits'])\n}\n","'use strict'\n\nconst useLegacyCrypto = parseInt(process.versions && process.versions.node && process.versions.node.split('.')[0]) < 15\nif (useLegacyCrypto) {\n // We are on an old version of Node.js that requires legacy crypto utilities.\n module.exports = require('./utils-legacy')\n} else {\n module.exports = require('./utils-webcrypto')\n}\n","'use strict'\nconst crypto = require('./utils')\n\nfunction startSession(mechanisms) {\n if (mechanisms.indexOf('SCRAM-SHA-256') === -1) {\n throw new Error('SASL: Only mechanism SCRAM-SHA-256 is currently supported')\n }\n\n const clientNonce = crypto.randomBytes(18).toString('base64')\n\n return {\n mechanism: 'SCRAM-SHA-256',\n clientNonce,\n response: 'n,,n=*,r=' + clientNonce,\n message: 'SASLInitialResponse',\n }\n}\n\nasync function continueSession(session, password, serverData) {\n if (session.message !== 'SASLInitialResponse') {\n throw new Error('SASL: Last message was not SASLInitialResponse')\n }\n if (typeof password !== 'string') {\n throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string')\n }\n if (password === '') {\n throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a non-empty string')\n }\n if (typeof serverData !== 'string') {\n throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: serverData must be a string')\n }\n\n const sv = parseServerFirstMessage(serverData)\n\n if (!sv.nonce.startsWith(session.clientNonce)) {\n throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: server nonce does not start with client nonce')\n } else if (sv.nonce.length === session.clientNonce.length) {\n throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: server nonce is too short')\n }\n\n var clientFirstMessageBare = 'n=*,r=' + session.clientNonce\n var serverFirstMessage = 'r=' + sv.nonce + ',s=' + sv.salt + ',i=' + sv.iteration\n var clientFinalMessageWithoutProof = 'c=biws,r=' + sv.nonce\n var authMessage = clientFirstMessageBare + ',' + serverFirstMessage + ',' + clientFinalMessageWithoutProof\n\n var saltBytes = Buffer.from(sv.salt, 'base64')\n var saltedPassword = await crypto.deriveKey(password, saltBytes, sv.iteration)\n var clientKey = await crypto.hmacSha256(saltedPassword, 'Client Key')\n var storedKey = await crypto.sha256(clientKey)\n var clientSignature = await crypto.hmacSha256(storedKey, authMessage)\n var clientProof = xorBuffers(Buffer.from(clientKey), Buffer.from(clientSignature)).toString('base64')\n var serverKey = await crypto.hmacSha256(saltedPassword, 'Server Key')\n var serverSignatureBytes = await crypto.hmacSha256(serverKey, authMessage)\n\n session.message = 'SASLResponse'\n session.serverSignature = Buffer.from(serverSignatureBytes).toString('base64')\n session.response = clientFinalMessageWithoutProof + ',p=' + clientProof\n}\n\nfunction finalizeSession(session, serverData) {\n if (session.message !== 'SASLResponse') {\n throw new Error('SASL: Last message was not SASLResponse')\n }\n if (typeof serverData !== 'string') {\n throw new Error('SASL: SCRAM-SERVER-FINAL-MESSAGE: serverData must be a string')\n }\n\n const { serverSignature } = parseServerFinalMessage(serverData)\n\n if (serverSignature !== session.serverSignature) {\n throw new Error('SASL: SCRAM-SERVER-FINAL-MESSAGE: server signature does not match')\n }\n}\n\n/**\n * printable = %x21-2B / %x2D-7E\n * ;; Printable ASCII except \",\".\n * ;; Note that any \"printable\" is also\n * ;; a valid \"value\".\n */\nfunction isPrintableChars(text) {\n if (typeof text !== 'string') {\n throw new TypeError('SASL: text must be a string')\n }\n return text\n .split('')\n .map((_, i) => text.charCodeAt(i))\n .every((c) => (c >= 0x21 && c <= 0x2b) || (c >= 0x2d && c <= 0x7e))\n}\n\n/**\n * base64-char = ALPHA / DIGIT / \"/\" / \"+\"\n *\n * base64-4 = 4base64-char\n *\n * base64-3 = 3base64-char \"=\"\n *\n * base64-2 = 2base64-char \"==\"\n *\n * base64 = *base64-4 [base64-3 / base64-2]\n */\nfunction isBase64(text) {\n return /^(?:[a-zA-Z0-9+/]{4})*(?:[a-zA-Z0-9+/]{2}==|[a-zA-Z0-9+/]{3}=)?$/.test(text)\n}\n\nfunction parseAttributePairs(text) {\n if (typeof text !== 'string') {\n throw new TypeError('SASL: attribute pairs text must be a string')\n }\n\n return new Map(\n text.split(',').map((attrValue) => {\n if (!/^.=/.test(attrValue)) {\n throw new Error('SASL: Invalid attribute pair entry')\n }\n const name = attrValue[0]\n const value = attrValue.substring(2)\n return [name, value]\n })\n )\n}\n\nfunction parseServerFirstMessage(data) {\n const attrPairs = parseAttributePairs(data)\n\n const nonce = attrPairs.get('r')\n if (!nonce) {\n throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce missing')\n } else if (!isPrintableChars(nonce)) {\n throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce must only contain printable characters')\n }\n const salt = attrPairs.get('s')\n if (!salt) {\n throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: salt missing')\n } else if (!isBase64(salt)) {\n throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: salt must be base64')\n }\n const iterationText = attrPairs.get('i')\n if (!iterationText) {\n throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: iteration missing')\n } else if (!/^[1-9][0-9]*$/.test(iterationText)) {\n throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: invalid iteration count')\n }\n const iteration = parseInt(iterationText, 10)\n\n return {\n nonce,\n salt,\n iteration,\n }\n}\n\nfunction parseServerFinalMessage(serverData) {\n const attrPairs = parseAttributePairs(serverData)\n const serverSignature = attrPairs.get('v')\n if (!serverSignature) {\n throw new Error('SASL: SCRAM-SERVER-FINAL-MESSAGE: server signature is missing')\n } else if (!isBase64(serverSignature)) {\n throw new Error('SASL: SCRAM-SERVER-FINAL-MESSAGE: server signature must be base64')\n }\n return {\n serverSignature,\n }\n}\n\nfunction xorBuffers(a, b) {\n if (!Buffer.isBuffer(a)) {\n throw new TypeError('first argument must be a Buffer')\n }\n if (!Buffer.isBuffer(b)) {\n throw new TypeError('second argument must be a Buffer')\n }\n if (a.length !== b.length) {\n throw new Error('Buffer lengths must match')\n }\n if (a.length === 0) {\n throw new Error('Buffers cannot be empty')\n }\n return Buffer.from(a.map((_, i) => a[i] ^ b[i]))\n}\n\nmodule.exports = {\n startSession,\n continueSession,\n finalizeSession,\n}\n","'use strict'\n\nvar types = require('pg-types')\n\nfunction TypeOverrides(userTypes) {\n this._types = userTypes || types\n this.text = {}\n this.binary = {}\n}\n\nTypeOverrides.prototype.getOverrides = function (format) {\n switch (format) {\n case 'text':\n return this.text\n case 'binary':\n return this.binary\n default:\n return {}\n }\n}\n\nTypeOverrides.prototype.setTypeParser = function (oid, format, parseFn) {\n if (typeof format === 'function') {\n parseFn = format\n format = 'text'\n }\n this.getOverrides(format)[oid] = parseFn\n}\n\nTypeOverrides.prototype.getTypeParser = function (oid, format) {\n format = format || 'text'\n return this.getOverrides(format)[oid] || this._types.getTypeParser(oid, format)\n}\n\nmodule.exports = TypeOverrides\n","'use strict'\n\n//Parse method copied from https://github.com/brianc/node-postgres\n//Copyright (c) 2010-2014 Brian Carlson (brian.m.carlson@gmail.com)\n//MIT License\n\n//parses a connection string\nfunction parse(str) {\n //unix socket\n if (str.charAt(0) === '/') {\n const config = str.split(' ')\n return { host: config[0], database: config[1] }\n }\n\n // Check for empty host in URL\n\n const config = {}\n let result\n let dummyHost = false\n if (/ |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(str)) {\n // Ensure spaces are encoded as %20\n str = encodeURI(str).replace(/\\%25(\\d\\d)/g, '%$1')\n }\n\n try {\n result = new URL(str, 'p