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3B","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n DBSYSTEMVALUES_SQLITE,\n DBSYSTEMVALUES_POSTGRESQL,\n} from '@opentelemetry/semantic-conventions';\n\ntype Exception = {\n new (message: string): Exception;\n constructor: Exception;\n errno?: number;\n code?: string;\n stack?: string;\n};\n\nexport const getFormatter = (runner: any) => {\n if (runner) {\n if (runner.client) {\n if (runner.client._formatQuery) {\n return runner.client._formatQuery.bind(runner.client);\n } else if (runner.client.SqlString) {\n return runner.client.SqlString.format.bind(runner.client.SqlString);\n }\n }\n if (runner.builder) {\n return runner.builder.toString.bind(runner.builder);\n }\n }\n return () => '';\n};\n\nexport const cloneErrorWithNewMessage = (err: Exception, message: string) => {\n if (err && err instanceof Error) {\n const clonedError = new (err.constructor as Exception)(message);\n clonedError.code = err.code;\n clonedError.stack = err.stack;\n clonedError.errno = err.errno;\n return clonedError;\n }\n return err;\n};\n\nconst systemMap = new Map([\n ['sqlite3', DBSYSTEMVALUES_SQLITE],\n ['pg', DBSYSTEMVALUES_POSTGRESQL],\n]);\nexport const mapSystem = (knexSystem: string) => {\n return systemMap.get(knexSystem) || knexSystem;\n};\n\nexport const getName = (db: string, operation?: string, table?: string) => {\n if (operation) {\n if (table) {\n return `${operation} ${db}.${table}`;\n }\n return `${operation} ${db}`;\n }\n return db;\n};\n\nexport const limitLength = (str: string, maxLength: number) => {\n if (\n typeof str === 'string' &&\n typeof maxLength === 'number' &&\n 0 < maxLength &&\n maxLength < str.length\n ) {\n return str.substr(0, maxLength) + '..';\n }\n return str;\n};\n\nexport const extractTableName = (builder: any): string => {\n const table = builder?._single?.table;\n if (typeof table === 'object') {\n return extractTableName(table);\n }\n return table;\n};\n"]}