API/api.medcify.app/node_modules/sequelize/lib/utils/sql.js.map
2022-09-26 11:41:44 +05:30

8 lines
9.6 KiB
Plaintext

{
"version": 3,
"sources": ["../../src/utils/sql.ts"],
"sourcesContent": ["import isPlainObject from 'lodash/isPlainObject';\nimport type { AbstractDialect } from '../dialects/abstract/index.js';\nimport { escape as escapeSqlValue } from '../sql-string';\n\ntype BindOrReplacements = { [key: string]: unknown } | unknown[];\n\n/**\n * Inlines replacements in places where they would be valid SQL values.\n *\n * @param sqlString The SQL that contains the replacements\n * @param dialect The dialect of the SQL\n * @param replacements if provided, this method will replace ':named' replacements & positional replacements (?)\n *\n * @returns The SQL with replacements rewritten in their dialect-specific syntax.\n */\nexport function injectReplacements(\n sqlString: string,\n dialect: AbstractDialect,\n replacements: BindOrReplacements\n): string {\n if (replacements == null) {\n return sqlString;\n }\n\n if (!Array.isArray(replacements) && !isPlainObject(replacements)) {\n throw new TypeError(`\"replacements\" must be an array or a plain object, but received ${JSON.stringify(replacements)} instead.`);\n }\n\n const isNamedReplacements = isPlainObject(replacements);\n const isPositionalReplacements = Array.isArray(replacements);\n let lastConsumedPositionalReplacementIndex = -1;\n\n let output = '';\n\n let currentDollarStringTagName = null;\n let isString = false;\n let isColumn = false;\n let previousSliceEnd = 0;\n let isSingleLineComment = false;\n let isCommentBlock = false;\n\n for (let i = 0; i < sqlString.length; i++) {\n const char = sqlString[i];\n\n if (isColumn) {\n if (char === dialect.TICK_CHAR_RIGHT) {\n isColumn = false;\n }\n\n continue;\n }\n\n if (isString) {\n if (char === '\\'' && !isBackslashEscaped(sqlString, i - 1)) {\n isString = false;\n }\n\n continue;\n }\n\n if (currentDollarStringTagName !== null) {\n if (char !== '$') {\n continue;\n }\n\n const remainingString = sqlString.slice(i, sqlString.length);\n\n const dollarStringStartMatch = remainingString.match(/^\\$(?<name>[a-z_][0-9a-z_])?(\\$)/i);\n const tagName = dollarStringStartMatch?.groups?.name;\n if (currentDollarStringTagName === tagName) {\n currentDollarStringTagName = null;\n }\n\n continue;\n }\n\n if (isSingleLineComment) {\n if (char === '\\n') {\n isSingleLineComment = false;\n }\n\n continue;\n }\n\n if (isCommentBlock) {\n if (char === '*' && sqlString[i + 1] === '/') {\n isCommentBlock = false;\n }\n\n continue;\n }\n\n if (char === dialect.TICK_CHAR_LEFT) {\n isColumn = true;\n continue;\n }\n\n if (char === '\\'') {\n isString = true;\n continue;\n }\n\n if (char === '-' && sqlString.slice(i, i + 3) === '-- ') {\n isSingleLineComment = true;\n continue;\n }\n\n if (char === '/' && sqlString.slice(i, i + 2) === '/*') {\n isCommentBlock = true;\n continue;\n }\n\n // either the start of a $bind parameter, or the start of a $tag$string$tag$\n if (char === '$') {\n const previousChar = sqlString[i - 1];\n\n // we are part of an identifier\n if (/[0-9a-z_]/i.test(previousChar)) {\n continue;\n }\n\n const remainingString = sqlString.slice(i, sqlString.length);\n\n const dollarStringStartMatch = remainingString.match(/^\\$(?<name>[a-z_][0-9a-z_]*)?\\$/i);\n if (dollarStringStartMatch) {\n currentDollarStringTagName = dollarStringStartMatch.groups?.name ?? '';\n\n continue;\n }\n\n continue;\n }\n\n if (isNamedReplacements && char === ':') {\n const previousChar = sqlString[i - 1];\n // we want to be conservative with what we consider to be a replacement to avoid risk of conflict with potential operators\n // users need to add a space before the bind parameter (except after '(', ',', and '=', '[' (for arrays))\n if (previousChar !== undefined && !/[\\s(,=[]/.test(previousChar)) {\n continue;\n }\n\n const remainingString = sqlString.slice(i, sqlString.length);\n\n const match = remainingString.match(/^:(?<name>[a-z_][0-9a-z_]*)(?:\\)|,|$|\\s|::|;|])/i);\n const replacementName = match?.groups?.name;\n if (!replacementName) {\n continue;\n }\n\n // @ts-expect-error -- isPlainObject does not tell typescript that replacements is a plain object, not an array\n const replacementValue = replacements[replacementName];\n if (!Object.prototype.hasOwnProperty.call(replacements, replacementName) || replacementValue === undefined) {\n throw new Error(`Named replacement \":${replacementName}\" has no entry in the replacement map.`);\n }\n\n const escapedReplacement = escapeSqlValue(replacementValue, undefined, dialect.name, true);\n\n // add everything before the bind parameter name\n output += sqlString.slice(previousSliceEnd, i);\n // continue after the bind parameter name\n previousSliceEnd = i + replacementName.length + 1;\n\n output += escapedReplacement;\n\n continue;\n }\n\n if (isPositionalReplacements && char === '?') {\n const previousChar = sqlString[i - 1];\n\n // we want to be conservative with what we consider to be a replacement to avoid risk of conflict with potential operators\n // users need to add a space before the bind parameter (except after '(', ',', and '=', '[' (for arrays))\n if (previousChar !== undefined && !/[\\s(,=[]/.test(previousChar)) {\n continue;\n }\n\n // don't parse ?| and ?& operators as replacements\n const nextChar = sqlString[i + 1];\n if (nextChar === '|' || nextChar === '&') {\n continue;\n }\n\n const replacementIndex = ++lastConsumedPositionalReplacementIndex;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore -- ts < 4.4 loses the information that 'replacements' is an array when using 'isPositionalReplacements' instead of 'Array.isArray'\n // but performance matters here.\n const replacementValue = replacements[lastConsumedPositionalReplacementIndex];\n\n if (replacementValue === undefined) {\n throw new Error(`Positional replacement (?) ${replacementIndex} has no entry in the replacement map (replacements[${replacementIndex}] is undefined).`);\n }\n\n const escapedReplacement = escapeSqlValue(replacementValue as any, undefined, dialect.name, true);\n\n // add everything before the bind parameter name\n output += sqlString.slice(previousSliceEnd, i);\n // continue after the bind parameter name\n previousSliceEnd = i + 1;\n\n output += escapedReplacement;\n }\n }\n\n output += sqlString.slice(previousSliceEnd, sqlString.length);\n\n return output;\n}\n\nfunction isBackslashEscaped(string: string, pos: number): boolean {\n let escaped = false;\n for (let i = pos; i >= 0; i--) {\n const char = string[i];\n if (char !== '\\\\') {\n break;\n }\n\n escaped = !escaped;\n }\n\n return escaped;\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,2BAA0B;AAE1B,wBAAyC;AAalC,4BACL,WACA,SACA,cACQ;AAnBV;AAoBE,MAAI,gBAAgB,MAAM;AACxB,WAAO;AAAA;AAGT,MAAI,CAAC,M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