sql-formatter
Advanced tools
Comparing version 7.0.4 to 8.0.0
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -16,3 +18,3 @@ value: true | ||
var _StatementFormatter = _interopRequireDefault(require("./StatementFormatter")); | ||
var _ExpressionFormatter = _interopRequireDefault(require("./ExpressionFormatter")); | ||
@@ -23,2 +25,10 @@ var _config = require("./config"); | ||
var _Layout = _interopRequireWildcard(require("./Layout")); | ||
var _Indentation = _interopRequireDefault(require("./Indentation")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -92,6 +102,24 @@ | ||
return statements.map(function (stat) { | ||
return new _StatementFormatter["default"](_this.cfg, _this.params).format(stat); | ||
return _this.formatStatement(stat); | ||
}).join('\n'.repeat(this.cfg.linesBetweenQueries + 1)); | ||
} | ||
}, { | ||
key: "formatStatement", | ||
value: function formatStatement(statement) { | ||
var layout = new _ExpressionFormatter["default"]({ | ||
cfg: this.cfg, | ||
params: this.params, | ||
layout: new _Layout["default"](new _Indentation["default"]((0, _config.indentString)(this.cfg))) | ||
}).format(statement.children); | ||
if (!statement.hasSemicolon) {// do nothing | ||
} else if (this.cfg.newlineBeforeSemicolon) { | ||
layout.add(_Layout.WS.NEWLINE, ';'); | ||
} else { | ||
layout.add(_Layout.WS.NO_SPACE, ';'); | ||
} | ||
return layout.toString(); | ||
} | ||
}, { | ||
key: "postFormat", | ||
@@ -98,0 +126,0 @@ value: function postFormat(query) { |
@@ -8,4 +8,14 @@ "use strict"; | ||
var _utils = require("../utils"); | ||
var _ast = require("./ast"); | ||
var _token = require("./token"); | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -17,4 +27,2 @@ | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
/** | ||
@@ -31,14 +39,7 @@ * Bookkeeper for inline blocks. | ||
_defineProperty(this, "level", void 0); | ||
_defineProperty(this, "expressionWidth", void 0); | ||
this.level = 0; | ||
this.expressionWidth = expressionWidth; | ||
} | ||
/** | ||
* Begins inline block when lookahead through upcoming tokens determines | ||
* that the block would be smaller than INLINE_MAX_LENGTH. | ||
* @param {Token[]} tokens Array of all tokens | ||
* @param {Number} index Current token position | ||
* Check if this should be an inline parentheses block | ||
* Examples are "NOW()", "COUNT(*)", "int(10)", key(`somecolumn`), DECIMAL(7,2) | ||
*/ | ||
@@ -48,67 +49,73 @@ | ||
_createClass(InlineBlock, [{ | ||
key: "beginIfPossible", | ||
value: function beginIfPossible(tokens, index) { | ||
if (this.level === 0 && this.isInlineBlock(tokens, index)) { | ||
this.level = 1; | ||
} else if (this.level > 0) { | ||
this.level++; | ||
} else { | ||
this.level = 0; | ||
} | ||
key: "isInlineBlock", | ||
value: function isInlineBlock(parenthesis) { | ||
return this.inlineWidth(parenthesis) <= this.expressionWidth; | ||
} | ||
/** | ||
* Finishes current inline block. | ||
* There might be several nested ones. | ||
*/ | ||
}, { | ||
key: "end", | ||
value: function end() { | ||
this.level--; | ||
} | ||
/** | ||
* True when inside an inline block | ||
*/ | ||
key: "inlineWidth", | ||
value: function inlineWidth(parenthesis) { | ||
var length = 2; // two parenthesis | ||
}, { | ||
key: "isActive", | ||
value: function isActive() { | ||
return this.level > 0; | ||
} | ||
/** | ||
* Check if this should be an inline parentheses block | ||
* Examples are "NOW()", "COUNT(*)", "int(10)", key(`somecolumn`), DECIMAL(7,2) | ||
*/ | ||
var _iterator = _createForOfIteratorHelper(parenthesis.children), | ||
_step; | ||
}, { | ||
key: "isInlineBlock", | ||
value: function isInlineBlock(tokens, index) { | ||
var length = 0; | ||
var level = 0; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var node = _step.value; | ||
for (var i = index; i < tokens.length; i++) { | ||
var token = tokens[i]; | ||
length += token.value.length; | ||
switch (node.type) { | ||
case _ast.NodeType.function_call: | ||
length += node.nameToken.value.length + this.inlineWidth(node.parenthesis); | ||
break; | ||
if (this.isForbiddenToken(token)) { | ||
return false; | ||
} // Overran max length | ||
case _ast.NodeType.array_subscript: | ||
length += node.arrayToken.value.length + this.inlineWidth(node.parenthesis); | ||
break; | ||
case _ast.NodeType.parenthesis: | ||
length += this.inlineWidth(node); | ||
break; | ||
if (length > this.expressionWidth) { | ||
return false; | ||
} | ||
case _ast.NodeType.between_predicate: | ||
length += this.betweenWidth(node); | ||
break; | ||
if (token.type === _token.TokenType.OPEN_PAREN) { | ||
level++; | ||
} else if (token.type === _token.TokenType.CLOSE_PAREN) { | ||
level--; | ||
case _ast.NodeType.clause: | ||
case _ast.NodeType.limit_clause: | ||
case _ast.NodeType.binary_clause: | ||
return Infinity; | ||
if (level === 0) { | ||
return true; | ||
case _ast.NodeType.all_columns_asterisk: | ||
length += 1; | ||
break; | ||
case _ast.NodeType.token: | ||
length += node.token.value.length; | ||
if (this.isForbiddenToken(node.token)) { | ||
return Infinity; | ||
} | ||
break; | ||
} // Overran max length | ||
if (length > this.expressionWidth) { | ||
return length; | ||
} | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
return false; | ||
return length; | ||
} | ||
}, { | ||
key: "betweenWidth", | ||
value: function betweenWidth(node) { | ||
return (0, _utils.sum)([node.betweenToken, node.expr1, node.andToken, node.expr2].map(function (token) { | ||
return token.value.length; | ||
})); | ||
} // Reserved words that cause newlines, comments and semicolons | ||
@@ -120,4 +127,3 @@ // are not allowed inside inline parentheses block | ||
value: function isForbiddenToken(token) { | ||
return token.type === _token.TokenType.RESERVED_COMMAND || token.type === _token.TokenType.RESERVED_LOGICAL_OPERATOR || // token.type === TokenType.LINE_COMMENT || | ||
token.type === _token.TokenType.BLOCK_COMMENT || token.value === ';' || _token.isToken.CASE(token) // CASE cannot have inline blocks | ||
return token.type === _token.TokenType.RESERVED_LOGICAL_OPERATOR || token.type === _token.TokenType.LINE_COMMENT || token.type === _token.TokenType.BLOCK_COMMENT || token.value === ';' || _token.isToken.CASE(token) // CASE cannot have inline blocks | ||
; | ||
@@ -124,0 +130,0 @@ } |
@@ -8,2 +8,4 @@ "use strict"; | ||
var _ast = require("./ast"); | ||
var _token = require("./token"); | ||
@@ -20,3 +22,3 @@ | ||
/** | ||
* A rudimentary parser that slices token stream into list of SQL statements. | ||
* A simple parser that creates a very rudimentary syntax tree. | ||
*/ | ||
@@ -47,16 +49,18 @@ var Parser = /*#__PURE__*/function () { | ||
value: function statement() { | ||
var tokens = []; | ||
var children = []; | ||
while (true) { | ||
if (this.look().value === ';') { | ||
tokens.push(this.next()); | ||
this.next(); | ||
return { | ||
type: 'statement', | ||
tokens: tokens | ||
type: _ast.NodeType.statement, | ||
children: children, | ||
hasSemicolon: true | ||
}; | ||
} else if (this.look().type === _token.TokenType.EOF) { | ||
if (tokens.length > 0) { | ||
if (children.length > 0) { | ||
return { | ||
type: 'statement', | ||
tokens: tokens | ||
type: _ast.NodeType.statement, | ||
children: children, | ||
hasSemicolon: false | ||
}; | ||
@@ -67,5 +71,153 @@ } else { | ||
} else { | ||
tokens.push(this.next()); | ||
children.push(this.expression()); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "expression", | ||
value: function expression() { | ||
return this.limitClause() || this.clause() || this.binaryClause() || this.functionCall() || this.arraySubscript() || this.parenthesis() || this.betweenPredicate() || this.allColumnsAsterisk() || this.nextTokenNode(); | ||
} | ||
}, { | ||
key: "clause", | ||
value: function clause() { | ||
if (this.look().type === _token.TokenType.RESERVED_COMMAND) { | ||
var name = this.next(); | ||
var children = []; | ||
while (this.look().type !== _token.TokenType.RESERVED_COMMAND && this.look().type !== _token.TokenType.RESERVED_BINARY_COMMAND && this.look().type !== _token.TokenType.EOF && this.look().type !== _token.TokenType.CLOSE_PAREN && this.look().value !== ';') { | ||
children.push(this.expression()); | ||
} | ||
return { | ||
type: _ast.NodeType.clause, | ||
nameToken: name, | ||
children: children | ||
}; | ||
} | ||
return undefined; | ||
} | ||
}, { | ||
key: "binaryClause", | ||
value: function binaryClause() { | ||
if (this.look().type === _token.TokenType.RESERVED_BINARY_COMMAND) { | ||
var name = this.next(); | ||
var children = []; | ||
while (this.look().type !== _token.TokenType.RESERVED_COMMAND && this.look().type !== _token.TokenType.RESERVED_BINARY_COMMAND && this.look().type !== _token.TokenType.EOF && this.look().type !== _token.TokenType.CLOSE_PAREN && this.look().value !== ';') { | ||
children.push(this.expression()); | ||
} | ||
return { | ||
type: _ast.NodeType.binary_clause, | ||
nameToken: name, | ||
children: children | ||
}; | ||
} | ||
return undefined; | ||
} | ||
}, { | ||
key: "functionCall", | ||
value: function functionCall() { | ||
if ((this.look().type === _token.TokenType.RESERVED_KEYWORD || this.look().type === _token.TokenType.IDENT) && this.look(1).value === '(' && !this.look(1).whitespaceBefore) { | ||
return { | ||
type: _ast.NodeType.function_call, | ||
nameToken: this.next(), | ||
parenthesis: this.parenthesis() | ||
}; | ||
} | ||
return undefined; | ||
} | ||
}, { | ||
key: "arraySubscript", | ||
value: function arraySubscript() { | ||
if ((this.look().type === _token.TokenType.RESERVED_KEYWORD || this.look().type === _token.TokenType.IDENT) && this.look(1).value === '[') { | ||
return { | ||
type: _ast.NodeType.array_subscript, | ||
arrayToken: this.next(), | ||
parenthesis: this.parenthesis() | ||
}; | ||
} | ||
return undefined; | ||
} | ||
}, { | ||
key: "parenthesis", | ||
value: function parenthesis() { | ||
if (this.look().type === _token.TokenType.OPEN_PAREN) { | ||
var children = []; | ||
var token = this.next(); | ||
var openParen = token.value; | ||
var closeParen = ''; | ||
while (this.look().type !== _token.TokenType.CLOSE_PAREN && this.look().type !== _token.TokenType.EOF) { | ||
children.push(this.expression()); | ||
} | ||
if (this.look().type === _token.TokenType.CLOSE_PAREN) { | ||
closeParen = this.next().value; | ||
} | ||
return { | ||
type: _ast.NodeType.parenthesis, | ||
children: children, | ||
openParen: openParen, | ||
closeParen: closeParen | ||
}; | ||
} | ||
return undefined; | ||
} | ||
}, { | ||
key: "betweenPredicate", | ||
value: function betweenPredicate() { | ||
if (_token.isToken.BETWEEN(this.look()) && _token.isToken.AND(this.look(2))) { | ||
return { | ||
type: _ast.NodeType.between_predicate, | ||
betweenToken: this.next(), | ||
expr1: this.next(), | ||
andToken: this.next(), | ||
expr2: this.next() | ||
}; | ||
} | ||
return undefined; | ||
} | ||
}, { | ||
key: "limitClause", | ||
value: function limitClause() { | ||
if (_token.isToken.LIMIT(this.look()) && this.look(2).value === ',') { | ||
return { | ||
type: _ast.NodeType.limit_clause, | ||
limitToken: this.next(), | ||
offsetToken: this.next(), | ||
countToken: this.next() && this.next() // Discard comma token | ||
}; | ||
} | ||
if (_token.isToken.LIMIT(this.look())) { | ||
return { | ||
type: _ast.NodeType.limit_clause, | ||
limitToken: this.next(), | ||
countToken: this.next() | ||
}; | ||
} | ||
return undefined; | ||
} | ||
}, { | ||
key: "allColumnsAsterisk", | ||
value: function allColumnsAsterisk() { | ||
if (this.look().value === '*' && _token.isToken.SELECT(this.look(-1))) { | ||
this.next(); | ||
return { | ||
type: _ast.NodeType.all_columns_asterisk | ||
}; | ||
} | ||
return undefined; | ||
} // Returns current token without advancing the pointer | ||
@@ -76,3 +228,4 @@ | ||
value: function look() { | ||
return this.tokens[this.index] || _token.EOF_TOKEN; | ||
var ahead = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
return this.tokens[this.index + ahead] || _token.EOF_TOKEN; | ||
} // Returns current token and advances the pointer to next token | ||
@@ -85,2 +238,10 @@ | ||
} | ||
}, { | ||
key: "nextTokenNode", | ||
value: function nextTokenNode() { | ||
return { | ||
type: _ast.NodeType.token, | ||
token: this.next() | ||
}; | ||
} | ||
}]); | ||
@@ -87,0 +248,0 @@ |
@@ -7,3 +7,6 @@ "use strict"; | ||
exports["default"] = toTabularFormat; | ||
exports.isTabularToken = isTabularToken; | ||
var _token = require("./token"); | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
@@ -56,4 +59,10 @@ | ||
} | ||
/** | ||
* True when the token can be formatted in tabular style | ||
*/ | ||
module.exports = exports.default; | ||
function isTabularToken(token) { | ||
return token.type === _token.TokenType.RESERVED_LOGICAL_OPERATOR || token.type === _token.TokenType.RESERVED_DEPENDENT_CLAUSE || token.type === _token.TokenType.RESERVED_COMMAND || token.type === _token.TokenType.RESERVED_BINARY_COMMAND || token.type === _token.TokenType.RESERVED_JOIN; | ||
} | ||
//# sourceMappingURL=tabularStyle.js.map |
@@ -23,2 +23,3 @@ "use strict"; | ||
TokenType["RESERVED_COMMAND"] = "RESERVED_COMMAND"; | ||
TokenType["RESERVED_JOIN"] = "RESERVED_JOIN"; | ||
TokenType["RESERVED_JOIN_CONDITION"] = "RESERVED_JOIN_CONDITION"; | ||
@@ -68,2 +69,6 @@ TokenType["RESERVED_CASE_START"] = "RESERVED_CASE_START"; | ||
}), | ||
ARRAY: testToken({ | ||
value: 'ARRAY', | ||
type: TokenType.RESERVED_KEYWORD | ||
}), | ||
BETWEEN: testToken({ | ||
@@ -105,2 +110,6 @@ value: 'BETWEEN', | ||
}), | ||
STRUCT: testToken({ | ||
value: 'STRUCT', | ||
type: TokenType.RESERVED_KEYWORD | ||
}), | ||
TABLE: testToken({ | ||
@@ -132,3 +141,3 @@ value: 'TABLE', | ||
var isReserved = function isReserved(token) { | ||
return token.type === TokenType.RESERVED_KEYWORD || token.type === TokenType.RESERVED_LOGICAL_OPERATOR || token.type === TokenType.RESERVED_DEPENDENT_CLAUSE || token.type === TokenType.RESERVED_JOIN_CONDITION || token.type === TokenType.RESERVED_COMMAND || token.type === TokenType.RESERVED_BINARY_COMMAND || token.type === TokenType.RESERVED_CASE_START || token.type === TokenType.RESERVED_CASE_END; | ||
return token.type === TokenType.RESERVED_KEYWORD || token.type === TokenType.RESERVED_LOGICAL_OPERATOR || token.type === TokenType.RESERVED_DEPENDENT_CLAUSE || token.type === TokenType.RESERVED_JOIN_CONDITION || token.type === TokenType.RESERVED_COMMAND || token.type === TokenType.RESERVED_BINARY_COMMAND || token.type === TokenType.RESERVED_JOIN || token.type === TokenType.RESERVED_CASE_START || token.type === TokenType.RESERVED_CASE_END; | ||
}; | ||
@@ -135,0 +144,0 @@ |
@@ -105,3 +105,3 @@ "use strict"; | ||
this.quotedIdentRegex = regexFactory.createQuoteRegex(cfg.identTypes); | ||
this.REGEX_MAP = (_this$REGEX_MAP = {}, _defineProperty(_this$REGEX_MAP, _token.TokenType.IDENT, regexFactory.createIdentRegex(cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.STRING, regexFactory.createQuoteRegex(cfg.stringTypes)), _defineProperty(_this$REGEX_MAP, _token.TokenType.VARIABLE, cfg.variableTypes ? regexFactory.createVariableRegex(cfg.variableTypes) : NULL_REGEX), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_KEYWORD, regexFactory.createReservedWordRegex(cfg.reservedKeywords, cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_DEPENDENT_CLAUSE, regexFactory.createReservedWordRegex((_cfg$reservedDependen = cfg.reservedDependentClauses) !== null && _cfg$reservedDependen !== void 0 ? _cfg$reservedDependen : [], cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_LOGICAL_OPERATOR, regexFactory.createReservedWordRegex((_cfg$reservedLogicalO = cfg.reservedLogicalOperators) !== null && _cfg$reservedLogicalO !== void 0 ? _cfg$reservedLogicalO : ['AND', 'OR'], cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_COMMAND, regexFactory.createReservedWordRegex(cfg.reservedCommands, cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_BINARY_COMMAND, regexFactory.createReservedWordRegex(cfg.reservedBinaryCommands, cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_JOIN_CONDITION, regexFactory.createReservedWordRegex((_cfg$reservedJoinCond = cfg.reservedJoinConditions) !== null && _cfg$reservedJoinCond !== void 0 ? _cfg$reservedJoinCond : ['ON', 'USING'], cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.OPERATOR, regexFactory.createOperatorRegex('+-/*%&|^><=.,;[]{}`:$@', ['<>', '<=', '>=', '!='].concat(_toConsumableArray((_cfg$operators = cfg.operators) !== null && _cfg$operators !== void 0 ? _cfg$operators : [])))), _defineProperty(_this$REGEX_MAP, _token.TokenType.OPEN_PAREN, regexFactory.createParenRegex((_cfg$openParens = cfg.openParens) !== null && _cfg$openParens !== void 0 ? _cfg$openParens : ['('])), _defineProperty(_this$REGEX_MAP, _token.TokenType.CLOSE_PAREN, regexFactory.createParenRegex((_cfg$closeParens = cfg.closeParens) !== null && _cfg$closeParens !== void 0 ? _cfg$closeParens : [')'])), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_CASE_START, new RegExp("(CA[S\\u017F]E)\\b", "iy")), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_CASE_END, new RegExp("(END)\\b", "iy")), _defineProperty(_this$REGEX_MAP, _token.TokenType.LINE_COMMENT, regexFactory.createLineCommentRegex((_cfg$lineCommentTypes = cfg.lineCommentTypes) !== null && _cfg$lineCommentTypes !== void 0 ? _cfg$lineCommentTypes : ['--'])), _defineProperty(_this$REGEX_MAP, _token.TokenType.BLOCK_COMMENT, new RegExp("(\\/\\*(?:(?![])[\\s\\S])*?(?:\\*\\/|$))", "y")), _defineProperty(_this$REGEX_MAP, _token.TokenType.NUMBER, new RegExp("(0x[0-9A-Fa-f]+|0b[01]+|(\\x2D[\\t-\\r \\xA0\\u1680\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000\\uFEFF]*)?[0-9]+(\\.[0-9]*)?([Ee][\\+\\x2D]?[0-9]+(\\.[0-9]+)?)?)", "y")), _defineProperty(_this$REGEX_MAP, _token.TokenType.PARAMETER, NULL_REGEX), _defineProperty(_this$REGEX_MAP, _token.TokenType.EOF, NULL_REGEX), _this$REGEX_MAP); | ||
this.REGEX_MAP = (_this$REGEX_MAP = {}, _defineProperty(_this$REGEX_MAP, _token.TokenType.IDENT, regexFactory.createIdentRegex(cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.STRING, regexFactory.createQuoteRegex(cfg.stringTypes)), _defineProperty(_this$REGEX_MAP, _token.TokenType.VARIABLE, cfg.variableTypes ? regexFactory.createVariableRegex(cfg.variableTypes) : NULL_REGEX), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_KEYWORD, regexFactory.createReservedWordRegex(cfg.reservedKeywords, cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_DEPENDENT_CLAUSE, regexFactory.createReservedWordRegex((_cfg$reservedDependen = cfg.reservedDependentClauses) !== null && _cfg$reservedDependen !== void 0 ? _cfg$reservedDependen : [], cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_LOGICAL_OPERATOR, regexFactory.createReservedWordRegex((_cfg$reservedLogicalO = cfg.reservedLogicalOperators) !== null && _cfg$reservedLogicalO !== void 0 ? _cfg$reservedLogicalO : ['AND', 'OR'], cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_COMMAND, regexFactory.createReservedWordRegex(cfg.reservedCommands, cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_BINARY_COMMAND, regexFactory.createReservedWordRegex(cfg.reservedBinaryCommands, cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_JOIN, regexFactory.createReservedWordRegex(cfg.reservedJoins, cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_JOIN_CONDITION, regexFactory.createReservedWordRegex((_cfg$reservedJoinCond = cfg.reservedJoinConditions) !== null && _cfg$reservedJoinCond !== void 0 ? _cfg$reservedJoinCond : ['ON', 'USING'], cfg.identChars)), _defineProperty(_this$REGEX_MAP, _token.TokenType.OPERATOR, regexFactory.createOperatorRegex('+-/*%&|^><=.,;[]{}`:$@', ['<>', '<=', '>=', '!='].concat(_toConsumableArray((_cfg$operators = cfg.operators) !== null && _cfg$operators !== void 0 ? _cfg$operators : [])))), _defineProperty(_this$REGEX_MAP, _token.TokenType.OPEN_PAREN, regexFactory.createParenRegex((_cfg$openParens = cfg.openParens) !== null && _cfg$openParens !== void 0 ? _cfg$openParens : ['('])), _defineProperty(_this$REGEX_MAP, _token.TokenType.CLOSE_PAREN, regexFactory.createParenRegex((_cfg$closeParens = cfg.closeParens) !== null && _cfg$closeParens !== void 0 ? _cfg$closeParens : [')'])), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_CASE_START, new RegExp("(CA[S\\u017F]E)\\b", "iy")), _defineProperty(_this$REGEX_MAP, _token.TokenType.RESERVED_CASE_END, new RegExp("(END)\\b", "iy")), _defineProperty(_this$REGEX_MAP, _token.TokenType.LINE_COMMENT, regexFactory.createLineCommentRegex((_cfg$lineCommentTypes = cfg.lineCommentTypes) !== null && _cfg$lineCommentTypes !== void 0 ? _cfg$lineCommentTypes : ['--'])), _defineProperty(_this$REGEX_MAP, _token.TokenType.BLOCK_COMMENT, new RegExp("(\\/\\*(?:(?![])[\\s\\S])*?(?:\\*\\/|$))", "y")), _defineProperty(_this$REGEX_MAP, _token.TokenType.NUMBER, new RegExp("(0x[0-9A-Fa-f]+|0b[01]+|(\\x2D[\\t-\\r \\xA0\\u1680\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000\\uFEFF]*)?[0-9]+(\\.[0-9]*)?([Ee][\\+\\x2D]?[0-9]+(\\.[0-9]+)?)?)", "y")), _defineProperty(_this$REGEX_MAP, _token.TokenType.PARAMETER, NULL_REGEX), _defineProperty(_this$REGEX_MAP, _token.TokenType.EOF, NULL_REGEX), _this$REGEX_MAP); | ||
this.paramPatterns = this.excludePatternsWithoutRegexes([{ | ||
@@ -256,3 +256,3 @@ // :name placeholders | ||
return this.matchReservedToken(_token.TokenType.RESERVED_CASE_START) || this.matchReservedToken(_token.TokenType.RESERVED_CASE_END) || this.matchReservedToken(_token.TokenType.RESERVED_COMMAND) || this.matchReservedToken(_token.TokenType.RESERVED_BINARY_COMMAND) || this.matchReservedToken(_token.TokenType.RESERVED_DEPENDENT_CLAUSE) || this.matchReservedToken(_token.TokenType.RESERVED_LOGICAL_OPERATOR) || this.matchReservedToken(_token.TokenType.RESERVED_KEYWORD) || this.matchReservedToken(_token.TokenType.RESERVED_JOIN_CONDITION); | ||
return this.matchReservedToken(_token.TokenType.RESERVED_CASE_START) || this.matchReservedToken(_token.TokenType.RESERVED_CASE_END) || this.matchReservedToken(_token.TokenType.RESERVED_COMMAND) || this.matchReservedToken(_token.TokenType.RESERVED_BINARY_COMMAND) || this.matchReservedToken(_token.TokenType.RESERVED_JOIN) || this.matchReservedToken(_token.TokenType.RESERVED_DEPENDENT_CLAUSE) || this.matchReservedToken(_token.TokenType.RESERVED_LOGICAL_OPERATOR) || this.matchReservedToken(_token.TokenType.RESERVED_KEYWORD) || this.matchReservedToken(_token.TokenType.RESERVED_JOIN_CONDITION); | ||
} // Helper for matching RESERVED_* tokens which need to be transformed to canonical form | ||
@@ -259,0 +259,0 @@ |
@@ -214,12 +214,5 @@ "use strict"; | ||
'EXPORT DATA']; | ||
var reservedBinaryCommands = ['INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT']; | ||
var reservedJoins = ['JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN']; | ||
/** | ||
* Priority 2 | ||
* commands that operate on two tables or subqueries | ||
* two main categories: joins and boolean set operators | ||
*/ | ||
var reservedBinaryCommands = [// set booleans | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', // joins | ||
'JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN']; | ||
/** | ||
* Priority 3 | ||
@@ -250,2 +243,3 @@ * keywords that follow a previous Statement, must be attached to subsequent data | ||
reservedBinaryCommands: reservedBinaryCommands, | ||
reservedJoins: reservedJoins, | ||
reservedDependentClauses: reservedDependentClauses, | ||
@@ -320,3 +314,3 @@ reservedKeywords: (0, _utils.dedupe)([].concat(_toConsumableArray(Object.values(reservedFunctions).flat()), _toConsumableArray(Object.values(reservedKeywords).flat()))), | ||
if ((token.value === 'ARRAY' || token.value === 'STRUCT') && nextToken.value === '<') { | ||
if ((_token.isToken.ARRAY(token) || _token.isToken.STRUCT(token)) && nextToken.value === '<') { | ||
var endIndex = findClosingAngleBracketIndex(tokens, i + 1); | ||
@@ -323,0 +317,0 @@ var typeDefTokens = tokens.slice(i, endIndex + 1); |
@@ -94,12 +94,5 @@ "use strict"; | ||
'FETCH FIRST', 'FROM', 'GROUP BY', 'GO', 'HAVING', 'INSERT INTO', 'LIMIT', 'OFFSET', 'ORDER BY', 'SELECT', 'SET CURRENT SCHEMA', 'WHERE', 'WITH']; | ||
var reservedBinaryCommands = ['INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT']; | ||
var reservedJoins = ['JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN']; | ||
/** | ||
* Priority 2 | ||
* commands that operate on two tables or subqueries | ||
* two main categories: joins and boolean set operators | ||
*/ | ||
var reservedBinaryCommands = [// set booleans | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', // joins | ||
'JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN']; | ||
/** | ||
* Priority 3 | ||
@@ -129,2 +122,3 @@ * keywords that follow a previous Statement, must be attached to subsequent data | ||
reservedBinaryCommands: reservedBinaryCommands, | ||
reservedJoins: reservedJoins, | ||
reservedDependentClauses: reservedDependentClauses, | ||
@@ -131,0 +125,0 @@ reservedKeywords: (0, _utils.dedupe)([].concat(_toConsumableArray(Object.values(reservedFunctions).flat()), _toConsumableArray(Object.values(reservedKeywords).flat()))), |
@@ -126,12 +126,5 @@ "use strict"; | ||
'STORED AS', 'STORED BY', 'ROW FORMAT']; | ||
var reservedBinaryCommands = ['INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT']; | ||
var reservedJoins = ['JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN']; | ||
/** | ||
* Priority 2 | ||
* commands that operate on two tables or subqueries | ||
* two main categories: joins and boolean set operators | ||
*/ | ||
var reservedBinaryCommands = [// set booleans | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', // joins | ||
'JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN']; | ||
/** | ||
* Priority 3 | ||
@@ -161,2 +154,3 @@ * keywords that follow a previous 'Statement', must be attached to subsequent data | ||
reservedBinaryCommands: reservedBinaryCommands, | ||
reservedJoins: reservedJoins, | ||
reservedDependentClauses: reservedDependentClauses, | ||
@@ -163,0 +157,0 @@ reservedKeywords: (0, _utils.dedupe)([].concat(_toConsumableArray(Object.values(reservedFunctions).flat()), _toConsumableArray(Object.values(reservedKeywords).flat()))), |
@@ -71,11 +71,4 @@ "use strict"; | ||
'ADD', 'ALTER COLUMN', 'FROM', 'GROUP BY', 'HAVING', 'INSERT INTO', 'INSERT', 'LIMIT', 'OFFSET', 'ORDER BY', 'SELECT', 'VALUES', 'WHERE']; | ||
/** | ||
* Priority 2 | ||
* commands that operate on two tables or subqueries | ||
* two main categories: joins and boolean set operators | ||
*/ | ||
var reservedBinaryCommands = [// set booleans | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', 'MINUS', 'MINUS ALL', 'MINUS DISTINCT', // joins | ||
'JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN', // non-standard joins | ||
var reservedBinaryCommands = ['INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', 'MINUS', 'MINUS ALL', 'MINUS DISTINCT']; | ||
var reservedJoins = ['JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN', // non-standard joins | ||
'STRAIGHT_JOIN', 'NATURAL LEFT JOIN', 'NATURAL LEFT OUTER JOIN', 'NATURAL RIGHT JOIN', 'NATURAL RIGHT OUTER JOIN']; | ||
@@ -107,2 +100,3 @@ /** | ||
reservedBinaryCommands: reservedBinaryCommands, | ||
reservedJoins: reservedJoins, | ||
reservedDependentClauses: reservedDependentClauses, | ||
@@ -109,0 +103,0 @@ reservedLogicalOperators: ['AND', 'OR', 'XOR'], |
@@ -74,11 +74,4 @@ "use strict"; | ||
'ADD', 'ALTER COLUMN', 'FROM', 'GROUP BY', 'HAVING', 'INSERT INTO', 'LIMIT', 'OFFSET', 'ORDER BY', 'WHERE']; | ||
/** | ||
* Priority 2 | ||
* commands that operate on two tables or subqueries | ||
* two main categories: joins and boolean set operators | ||
*/ | ||
var reservedBinaryCommands = [// set booleans | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', // joins | ||
'JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN', // non-standard joins | ||
var reservedBinaryCommands = ['INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT']; | ||
var reservedJoins = ['JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN', // non-standard joins | ||
'STRAIGHT_JOIN', 'NATURAL LEFT JOIN', 'NATURAL LEFT OUTER JOIN', 'NATURAL RIGHT JOIN', 'NATURAL RIGHT OUTER JOIN']; | ||
@@ -110,2 +103,3 @@ /** | ||
reservedBinaryCommands: reservedBinaryCommands, | ||
reservedJoins: reservedJoins, | ||
reservedDependentClauses: reservedDependentClauses, | ||
@@ -112,0 +106,0 @@ reservedLogicalOperators: ['AND', 'OR', 'XOR'], |
@@ -71,12 +71,5 @@ "use strict"; | ||
'FROM', 'GROUP BY', 'HAVING', 'INSERT INTO', 'LET', 'LIMIT', 'OFFSET', 'NEST', 'ORDER BY', 'SET CURRENT SCHEMA', 'SET SCHEMA', 'SET', 'SHOW', 'UNNEST', 'USE KEYS', 'VALUES', 'WHERE', 'WITH']; | ||
var reservedBinaryCommands = ['INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', 'MINUS', 'MINUS ALL', 'MINUS DISTINCT']; | ||
var reservedJoins = ['JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN']; | ||
/** | ||
* Priority 2 | ||
* commands that operate on two tables or subqueries | ||
* two main categories: joins and boolean set operators | ||
*/ | ||
var reservedBinaryCommands = [// set booleans | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', 'MINUS', 'MINUS ALL', 'MINUS DISTINCT', // joins | ||
'JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN']; | ||
/** | ||
* Priority 3 | ||
@@ -106,2 +99,3 @@ * keywords that follow a previous Statement, must be attached to subsequent data | ||
reservedBinaryCommands: reservedBinaryCommands, | ||
reservedJoins: reservedJoins, | ||
reservedDependentClauses: reservedDependentClauses, | ||
@@ -108,0 +102,0 @@ reservedLogicalOperators: ['AND', 'OR', 'XOR'], |
@@ -97,12 +97,6 @@ "use strict"; | ||
'DECLARE', 'DELETE', 'DELETE FROM', 'EXCEPT', 'EXCEPTION', 'FETCH FIRST', 'FROM', 'GROUP BY', 'HAVING', 'INSERT INTO', 'INSERT', 'LIMIT', 'OFFSET', 'LOOP', 'MODIFY', 'ORDER BY', 'RETURNING', 'SELECT', 'SET CURRENT SCHEMA', 'SET SCHEMA', 'SET', 'START WITH', 'UPDATE', 'VALUES', 'WHERE', 'WITH']; | ||
/** | ||
* Priority 2 | ||
* commands that operate on two tables or subqueries | ||
* two main categories: joins and boolean set operators | ||
*/ | ||
var reservedBinaryCommands = [// set booleans | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', 'MINUS', 'MINUS ALL', 'MINUS DISTINCT', // joins | ||
'JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN', // apply | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', 'MINUS', 'MINUS ALL', 'MINUS DISTINCT', // apply | ||
'CROSS APPLY', 'OUTER APPLY']; | ||
var reservedJoins = ['JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN']; | ||
/** | ||
@@ -133,2 +127,3 @@ * Priority 3 | ||
reservedBinaryCommands: reservedBinaryCommands, | ||
reservedJoins: reservedJoins, | ||
reservedDependentClauses: reservedDependentClauses, | ||
@@ -135,0 +130,0 @@ reservedLogicalOperators: ['AND', 'OR', 'XOR'], |
@@ -134,12 +134,5 @@ "use strict"; | ||
'FROM', 'GROUP BY', 'HAVING', 'LIMIT', 'OFFSET', 'ORDER BY', 'WHERE', 'WITH']; | ||
var reservedBinaryCommands = ['INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', 'MINUS', 'MINUS ALL', 'MINUS DISTINCT']; | ||
var reservedJoins = ['JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN']; | ||
/** | ||
* Priority 2 | ||
* commands that operate on two tables or subqueries | ||
* two main categories: joins and boolean set operators | ||
*/ | ||
var reservedBinaryCommands = [// set booleans | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', 'MINUS', 'MINUS ALL', 'MINUS DISTINCT', // joins | ||
'JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN']; | ||
/** | ||
* Priority 3 | ||
@@ -170,2 +163,3 @@ * keywords that follow a previous Statement, must be attached to subsequent data | ||
reservedBinaryCommands: reservedBinaryCommands, | ||
reservedJoins: reservedJoins, | ||
reservedDependentClauses: reservedDependentClauses, | ||
@@ -172,0 +166,0 @@ reservedKeywords: (0, _utils.dedupe)([].concat(_toConsumableArray(Object.values(reservedFunctions).flat()), reservedKeywords)), |
@@ -145,12 +145,5 @@ "use strict"; | ||
]; | ||
var reservedBinaryCommands = ['INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT']; | ||
var reservedJoins = ['JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN']; | ||
/** | ||
* Priority 2 | ||
* commands that operate on two tables or subqueries | ||
* two main categories: joins and boolean set operators | ||
*/ | ||
var reservedBinaryCommands = [// set booleans | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', // joins | ||
'JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN']; | ||
/** | ||
* Priority 3 | ||
@@ -180,2 +173,3 @@ * keywords that follow a previous Statement, must be attached to subsequent data | ||
reservedBinaryCommands: reservedBinaryCommands, | ||
reservedJoins: reservedJoins, | ||
reservedDependentClauses: reservedDependentClauses, | ||
@@ -182,0 +176,0 @@ reservedKeywords: (0, _utils.dedupe)([].concat(_toConsumableArray(Object.values(reservedFunctions).flat()), _toConsumableArray(Object.values(reservedKeywords).flat()))), |
@@ -106,13 +106,7 @@ "use strict"; | ||
]; | ||
/** | ||
* Priority 2 | ||
* commands that operate on two tables or subqueries | ||
* two main categories: joins and boolean set operators | ||
*/ | ||
var reservedBinaryCommands = [// set booleans | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', 'MINUS', 'MINUS ALL', 'MINUS DISTINCT', // joins | ||
'JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN', // apply | ||
'CROSS APPLY', 'OUTER APPLY', // non-standard-joins | ||
'ANTI JOIN', 'SEMI JOIN', 'LEFT ANTI JOIN', 'LEFT SEMI JOIN', 'RIGHT OUTER JOIN', 'RIGHT SEMI JOIN', 'NATURAL ANTI JOIN', 'NATURAL FULL OUTER JOIN', 'NATURAL INNER JOIN', 'NATURAL LEFT ANTI JOIN', 'NATURAL LEFT OUTER JOIN', 'NATURAL LEFT SEMI JOIN', 'NATURAL OUTER JOIN', 'NATURAL RIGHT OUTER JOIN', 'NATURAL RIGHT SEMI JOIN', 'NATURAL SEMI JOIN', 'CROSS APPLY', 'OUTER APPLY']; | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', 'MINUS', 'MINUS ALL', 'MINUS DISTINCT', // apply | ||
'CROSS APPLY', 'OUTER APPLY']; | ||
var reservedJoins = ['JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN', // non-standard-joins | ||
'ANTI JOIN', 'SEMI JOIN', 'LEFT ANTI JOIN', 'LEFT SEMI JOIN', 'RIGHT OUTER JOIN', 'RIGHT SEMI JOIN', 'NATURAL ANTI JOIN', 'NATURAL FULL OUTER JOIN', 'NATURAL INNER JOIN', 'NATURAL LEFT ANTI JOIN', 'NATURAL LEFT OUTER JOIN', 'NATURAL LEFT SEMI JOIN', 'NATURAL OUTER JOIN', 'NATURAL RIGHT OUTER JOIN', 'NATURAL RIGHT SEMI JOIN', 'NATURAL SEMI JOIN']; | ||
/** | ||
@@ -143,2 +137,3 @@ * Priority 3 | ||
reservedBinaryCommands: reservedBinaryCommands, | ||
reservedJoins: reservedJoins, | ||
reservedDependentClauses: reservedDependentClauses, | ||
@@ -145,0 +140,0 @@ reservedLogicalOperators: ['AND', 'OR', 'XOR'], |
@@ -91,12 +91,5 @@ "use strict"; | ||
var reservedCommands = ['ADD', 'ALTER COLUMN', 'ALTER TABLE', 'CREATE TABLE', 'DROP TABLE', 'DELETE FROM', 'FETCH FIRST', 'FETCH NEXT', 'FETCH PRIOR', 'FETCH LAST', 'FETCH ABSOLUTE', 'FETCH RELATIVE', 'FROM', 'GROUP BY', 'HAVING', 'INSERT INTO', 'LIMIT', 'OFFSET', 'ORDER BY', 'SELECT', 'SET SCHEMA', 'SET', 'UPDATE', 'VALUES', 'WHERE', 'WITH']; | ||
var reservedBinaryCommands = ['INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT']; | ||
var reservedJoins = ['JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN']; | ||
/** | ||
* Priority 2 | ||
* commands that operate on two tables or subqueries | ||
* two main categories: joins and boolean set operators | ||
*/ | ||
var reservedBinaryCommands = [// set booleans | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', // joins | ||
'JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN', 'NATURAL JOIN']; | ||
/** | ||
* Priority 3 | ||
@@ -126,2 +119,3 @@ * keywords that follow a previous Statement, must be attached to subsequent data | ||
reservedBinaryCommands: reservedBinaryCommands, | ||
reservedJoins: reservedJoins, | ||
reservedDependentClauses: reservedDependentClauses, | ||
@@ -128,0 +122,0 @@ reservedKeywords: (0, _utils.dedupe)([].concat(reservedKeywords, _toConsumableArray(Object.values(reservedFunctions).flat()))), |
@@ -63,5 +63,5 @@ "use strict"; | ||
var reservedCommands = ['ADD', 'ALTER COLUMN', 'ALTER TABLE', 'CREATE TABLE', 'DROP TABLE', 'DELETE', 'DELETE FROM', 'FETCH FIRST', 'FETCH NEXT', 'FETCH PRIOR', 'FETCH LAST', 'FETCH ABSOLUTE', 'FETCH RELATIVE', 'FROM', 'GROUP BY', 'HAVING', 'INSERT INTO', 'LIMIT', 'OFFSET', 'ORDER BY', 'SELECT', 'SET SCHEMA', 'SET', 'UPDATE', 'VALUES', 'WHERE', 'WITH']; | ||
var reservedBinaryCommands = [// set booleans | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', // joins - https://www.sqlite.org/syntax/join-operator.html | ||
'JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'INNER JOIN', 'CROSS JOIN', 'NATURAL JOIN', 'NATURAL LEFT JOIN', 'NATURAL LEFT OUTER JOIN', 'NATURAL INNER JOIN', 'NATURAL CROSS JOIN']; | ||
var reservedBinaryCommands = ['INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT']; // joins - https://www.sqlite.org/syntax/join-operator.html | ||
var reservedJoins = ['JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'INNER JOIN', 'CROSS JOIN', 'NATURAL JOIN', 'NATURAL LEFT JOIN', 'NATURAL LEFT OUTER JOIN', 'NATURAL INNER JOIN', 'NATURAL CROSS JOIN']; | ||
var reservedDependentClauses = ['WHEN', 'ELSE']; | ||
@@ -87,2 +87,3 @@ | ||
reservedBinaryCommands: reservedBinaryCommands, | ||
reservedJoins: reservedJoins, | ||
reservedDependentClauses: reservedDependentClauses, | ||
@@ -89,0 +90,0 @@ reservedKeywords: (0, _utils.dedupe)([].concat(reservedKeywords, _toConsumableArray(Object.values(reservedFunctions).flat()))), |
@@ -101,12 +101,5 @@ "use strict"; | ||
'LIMIT', 'OFFSET', 'ORDER BY', 'SELECT', 'VALUES', 'WHERE', 'WITH']; | ||
var reservedBinaryCommands = ['INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', 'MINUS', 'MINUS ALL', 'MINUS DISTINCT']; | ||
var reservedJoins = ['JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN']; | ||
/** | ||
* Priority 2 | ||
* commands that operate on two tables or subqueries | ||
* two main categories: joins and boolean set operators | ||
*/ | ||
var reservedBinaryCommands = [// set booleans | ||
'INTERSECT', 'INTERSECT ALL', 'INTERSECT DISTINCT', 'UNION', 'UNION ALL', 'UNION DISTINCT', 'EXCEPT', 'EXCEPT ALL', 'EXCEPT DISTINCT', 'MINUS', 'MINUS ALL', 'MINUS DISTINCT', // joins | ||
'JOIN', 'INNER JOIN', 'LEFT JOIN', 'LEFT OUTER JOIN', 'RIGHT JOIN', 'RIGHT OUTER JOIN', 'FULL JOIN', 'FULL OUTER JOIN', 'CROSS JOIN']; | ||
/** | ||
* Priority 3 | ||
@@ -136,2 +129,3 @@ * keywords that follow a previous Statement, must be attached to subsequent data | ||
reservedBinaryCommands: reservedBinaryCommands, | ||
reservedJoins: reservedJoins, | ||
reservedDependentClauses: reservedDependentClauses, | ||
@@ -138,0 +132,0 @@ reservedKeywords: (0, _utils.dedupe)([].concat(_toConsumableArray(Object.values(reservedFunctions).flat()), _toConsumableArray(Object.values(reservedKeywords).flat()))), |
@@ -34,4 +34,2 @@ "use strict"; | ||
var _utils = require("./utils"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -97,3 +95,2 @@ | ||
indentStyle: 'standard', | ||
multilineLists: 'always', | ||
logicalOperatorNewline: 'before', | ||
@@ -103,4 +100,2 @@ aliasAs: 'preserve', | ||
commaPosition: 'after', | ||
newlineBeforeOpenParen: true, | ||
newlineBeforeCloseParen: true, | ||
expressionWidth: 50, | ||
@@ -154,6 +149,14 @@ linesBetweenQueries: 1, | ||
if ((0, _utils.isNumber)(cfg.multilineLists) && cfg.multilineLists <= 0) { | ||
throw new ConfigError('multilineLists config must be a positive number.'); | ||
if ('multilineLists' in cfg) { | ||
throw new ConfigError('multilineLists config is no more supported.'); | ||
} | ||
if ('newlineBeforeOpenParen' in cfg) { | ||
throw new ConfigError('newlineBeforeOpenParen config is no more supported.'); | ||
} | ||
if ('newlineBeforeCloseParen' in cfg) { | ||
throw new ConfigError('newlineBeforeCloseParen config is no more supported.'); | ||
} | ||
if (cfg.expressionWidth <= 0) { | ||
@@ -160,0 +163,0 @@ throw new ConfigError("expressionWidth config must be positive number. Received ".concat(cfg.expressionWidth, " instead.")); |
@@ -20,3 +20,4 @@ import type { FormatOptions } from "../types"; | ||
private formatAst; | ||
private formatStatement; | ||
private postFormat; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { type Token } from './token'; | ||
import { Parenthesis } from './ast'; | ||
/** | ||
@@ -10,27 +10,12 @@ * Bookkeeper for inline blocks. | ||
export default class InlineBlock { | ||
level: number; | ||
expressionWidth: number; | ||
private expressionWidth; | ||
constructor(expressionWidth: number); | ||
/** | ||
* Begins inline block when lookahead through upcoming tokens determines | ||
* that the block would be smaller than INLINE_MAX_LENGTH. | ||
* @param {Token[]} tokens Array of all tokens | ||
* @param {Number} index Current token position | ||
*/ | ||
beginIfPossible(tokens: Token[], index: number): void; | ||
/** | ||
* Finishes current inline block. | ||
* There might be several nested ones. | ||
*/ | ||
end(): void; | ||
/** | ||
* True when inside an inline block | ||
*/ | ||
isActive(): boolean; | ||
/** | ||
* Check if this should be an inline parentheses block | ||
* Examples are "NOW()", "COUNT(*)", "int(10)", key(`somecolumn`), DECIMAL(7,2) | ||
*/ | ||
isInlineBlock(tokens: Token[], index: number): boolean; | ||
isForbiddenToken(token: Token): boolean; | ||
isInlineBlock(parenthesis: Parenthesis): boolean; | ||
private inlineWidth; | ||
private betweenWidth; | ||
private isForbiddenToken; | ||
} |
@@ -0,8 +1,5 @@ | ||
import { Statement } from './ast'; | ||
import { type Token } from './token'; | ||
export declare type Statement = { | ||
type: 'statement'; | ||
tokens: Token[]; | ||
}; | ||
/** | ||
* A rudimentary parser that slices token stream into list of SQL statements. | ||
* A simple parser that creates a very rudimentary syntax tree. | ||
*/ | ||
@@ -15,4 +12,14 @@ export default class Parser { | ||
private statement; | ||
private expression; | ||
private clause; | ||
private binaryClause; | ||
private functionCall; | ||
private arraySubscript; | ||
private parenthesis; | ||
private betweenPredicate; | ||
private limitClause; | ||
private allColumnsAsterisk; | ||
private look; | ||
private next; | ||
private nextTokenNode; | ||
} |
import type { IndentStyle } from "../types"; | ||
import { Token } from './token'; | ||
/** | ||
@@ -7,1 +8,5 @@ * When tabular style enabled, | ||
export default function toTabularFormat(tokenText: string, indentStyle: IndentStyle): string; | ||
/** | ||
* True when the token can be formatted in tabular style | ||
*/ | ||
export declare function isTabularToken(token: Token): boolean; |
@@ -11,2 +11,3 @@ /** Token type enum for all possible Token categories */ | ||
RESERVED_COMMAND = "RESERVED_COMMAND", | ||
RESERVED_JOIN = "RESERVED_JOIN", | ||
RESERVED_JOIN_CONDITION = "RESERVED_JOIN_CONDITION", | ||
@@ -50,2 +51,3 @@ RESERVED_CASE_START = "RESERVED_CASE_START", | ||
AND: (token: Token) => boolean; | ||
ARRAY: (token: Token) => boolean; | ||
BETWEEN: (token: Token) => boolean; | ||
@@ -60,2 +62,3 @@ CASE: (token: Token) => boolean; | ||
SET: (token: Token) => boolean; | ||
STRUCT: (token: Token) => boolean; | ||
TABLE: (token: Token) => boolean; | ||
@@ -62,0 +65,0 @@ WINDOW: (token: Token) => boolean; |
@@ -9,2 +9,3 @@ import * as regexFactory from './regexFactory'; | ||
reservedBinaryCommands: string[]; | ||
reservedJoins: string[]; | ||
reservedJoinConditions?: string[]; | ||
@@ -11,0 +12,0 @@ reservedKeywords: string[]; |
import { type ParamItems } from './core/Params'; | ||
export declare type IndentStyle = 'standard' | 'tabularLeft' | 'tabularRight'; | ||
export declare type KeywordCase = 'preserve' | 'upper' | 'lower'; | ||
export declare type MultilineListsMode = 'always' | 'avoid' | 'expressionWidth'; | ||
export declare type AliasMode = 'preserve' | 'always' | 'never' | 'select'; | ||
@@ -13,3 +12,2 @@ export declare type CommaPosition = 'before' | 'after' | 'tabular'; | ||
indentStyle: IndentStyle; | ||
multilineLists: MultilineListsMode | number; | ||
logicalOperatorNewline: LogicalOperatorNewline; | ||
@@ -19,4 +17,2 @@ aliasAs: AliasMode; | ||
commaPosition: CommaPosition; | ||
newlineBeforeOpenParen: boolean; | ||
newlineBeforeCloseParen: boolean; | ||
expressionWidth: number; | ||
@@ -23,0 +19,0 @@ linesBetweenQueries: number; |
@@ -11,1 +11,2 @@ export declare const dedupe: (arr: string[]) => string[]; | ||
export declare const id: <T>(x: T) => T; | ||
export declare const sum: (arr: number[]) => number; |
@@ -6,4 +6,6 @@ "use strict"; | ||
}); | ||
exports.sortByLengthDesc = exports.maxLength = exports.last = exports.isNumber = exports.isEmpty = exports.id = exports.escapeRegExp = exports.equalizeWhitespace = exports.dedupe = void 0; | ||
exports.sum = exports.sortByLengthDesc = exports.maxLength = exports.last = exports.isNumber = exports.isEmpty = exports.id = exports.escapeRegExp = exports.equalizeWhitespace = exports.dedupe = void 0; | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
@@ -84,5 +86,28 @@ | ||
return x; | ||
}; // Adds up all values in array | ||
exports.id = id; | ||
var sum = function sum(arr) { | ||
var total = 0; | ||
var _iterator = _createForOfIteratorHelper(arr), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var x = _step.value; | ||
total += x; | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
return total; | ||
}; | ||
exports.id = id; | ||
exports.sum = sum; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "sql-formatter", | ||
"version": "7.0.4", | ||
"version": "8.0.0", | ||
"description": "Format whitespace in a SQL query to make it more readable", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -152,3 +152,2 @@ <a href='https://github.com/sql-formatter-org/sql-formatter'><img src="static/prettier-sql-clean.svg" width="128"/></a> | ||
- [**`indentStyle`**](docs/indentStyle.md) defines overall indentation style. | ||
- [**`multilineLists`**](docs/multilineLists.md) **(DEPRECATED)** determines when to break lists of items to multiple lines. | ||
- [**`logicalOperatorNewline`**](docs/logicalOperatorNewline.md) newline before or after boolean operator (AND, OR, XOR). | ||
@@ -158,4 +157,2 @@ - [**`aliasAs`**](docs/aliasAs.md) enforces or forbids use of AS keyword for aliases. | ||
- [**`commaPosition`**](docs/commaPosition.md) where to place the comma in column lists. | ||
- [**`newlineBeforeOpenParen`**](docs/newlineBeforeOpenParen.md) **(DEPRECATED)** placement of opening parenthesis. | ||
- [**`newlineBeforeCloseParen`**](docs/newlineBeforeCloseParen.md) **(DEPRECATED)** placement of closing parenthesis. | ||
- [**`expressionWidth`**](docs/expressionWidth.md) maximum number of characters in parenthesized expressions to be kept on single line. | ||
@@ -182,4 +179,2 @@ - [**`linesBetweenQueries`**](docs/linesBetweenQueries.md) how many newlines to insert between queries. | ||
You can read more about how the library works in [DOC.md](DOC.md) | ||
## License | ||
@@ -186,0 +181,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1528082
155
6370
182