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CAAC,EAAE;YACnB,QAAQ,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;YACrD,QAAQ,GAAG,mBAAmB,CAAC,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;SACzD;QACK,IAAA,8CAAqC,EAApC,YAAI,EAAE,YAA8B,CAAC;QAE5C,OAAO;YACH,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,IAAI;YACV,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC;YACtC,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC;YACtC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;YACvC,QAAQ,EAAE,SAAS,IAAI,SAAS;SACnC,CAAC;IACN,CAAC;IACL,kBAAC;AAAD,CAzFA,AAyFC,IAAA","file":"DriverUtils.js","sourcesContent":["import { Driver } from \"./Driver\";\nimport { shorten } from \"../util/StringUtils\";\n\n /**\n * Common driver utility functions.\n */\nexport class DriverUtils {\n\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Normalizes and builds a new driver options.\n * Extracts settings from connection url and sets to a new options object.\n */\n static buildDriverOptions(options: any, buildOptions?: { useSid: boolean }): any {\n if (options.url) {\n const parsedUrl = this.parseConnectionUrl(options.url);\n let urlDriverOptions: any = {\n type: parsedUrl.type,\n host: parsedUrl.host,\n username: parsedUrl.username,\n password: parsedUrl.password,\n port: parsedUrl.port,\n database: parsedUrl.database\n };\n if (buildOptions && buildOptions.useSid) {\n urlDriverOptions.sid = parsedUrl.database;\n }\n return Object.assign({}, options, urlDriverOptions);\n }\n return Object.assign({}, options);\n }\n\n /**\n * Builds column alias from given alias name and column name,\n * If alias length is greater than the limit (if any) allowed by the current\n * driver, abbreviates the longest part (alias or column name) in the resulting\n * alias.\n *\n * @param driver Current `Driver`.\n * @param alias Alias part.\n * @param column Name of the column to be concatened to `alias`.\n *\n * @return An alias allowing to select/transform the target `column`.\n */\n static buildColumnAlias({ maxAliasLength }: Driver, alias: string, column: string): string {\n const columnAliasName = alias + \"_\" + column;\n\n if (maxAliasLength && maxAliasLength > 0 && columnAliasName.length > maxAliasLength)\n return alias.length > column.length\n ? `${shorten(alias)}_${column}`\n : `${alias}_${shorten(column)}`;\n\n return columnAliasName;\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Extracts connection data from the connection url.\n */\n private static parseConnectionUrl(url: string) {\n const type = url.split(\":\")[0];\n const firstSlashes = url.indexOf(\"//\");\n const preBase = url.substr(firstSlashes + 2);\n const secondSlash = preBase.indexOf(\"/\");\n const base = (secondSlash !== -1) ? preBase.substr(0, secondSlash) : preBase;\n const afterBase = (secondSlash !== -1) ? preBase.substr(secondSlash + 1) : undefined;\n\n const lastAtSign = base.lastIndexOf(\"@\");\n const usernameAndPassword = base.substr(0, lastAtSign);\n const hostAndPort = base.substr(lastAtSign + 1);\n\n let username = usernameAndPassword;\n let password = \"\";\n const firstColon = usernameAndPassword.indexOf(\":\");\n if (firstColon !== -1) {\n username = usernameAndPassword.substr(0, firstColon);\n password = usernameAndPassword.substr(firstColon + 1);\n }\n const [host, port] = hostAndPort.split(\":\");\n\n return {\n type: type,\n host: host,\n username: decodeURIComponent(username),\n password: decodeURIComponent(password),\n port: port ? parseInt(port) : undefined,\n database: afterBase || undefined\n };\n }\n}\n"],"sourceRoot":".."}
|