prettier-plugin-sql-cst 0.19.2 → 0.19.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +21 -7
- package/dist/index.js +2637 -55
- package/package.json +3 -2
- package/dist/CstToDocMap.d.ts +0 -11
- package/dist/CstToDocMap.js +0 -1
- package/dist/PrintFn.d.ts +0 -17
- package/dist/PrintFn.js +0 -1
- package/dist/embed.d.ts +0 -3
- package/dist/embed.js +0 -6
- package/dist/embedJs.d.ts +0 -3
- package/dist/embedJs.js +0 -43
- package/dist/embedJson.d.ts +0 -3
- package/dist/embedJson.js +0 -34
- package/dist/embedSql.d.ts +0 -3
- package/dist/embedSql.js +0 -39
- package/dist/node_utils.d.ts +0 -38
- package/dist/node_utils.js +0 -44
- package/dist/options.d.ts +0 -15
- package/dist/options.js +0 -147
- package/dist/printComment.d.ts +0 -3
- package/dist/printComment.js +0 -12
- package/dist/printSql.d.ts +0 -5
- package/dist/printSql.js +0 -61
- package/dist/print_utils.d.ts +0 -13
- package/dist/print_utils.js +0 -49
- package/dist/syntax/alias.d.ts +0 -3
- package/dist/syntax/alias.js +0 -3
- package/dist/syntax/alter_action.d.ts +0 -3
- package/dist/syntax/alter_action.js +0 -120
- package/dist/syntax/alter_table.d.ts +0 -3
- package/dist/syntax/alter_table.js +0 -19
- package/dist/syntax/analyze.d.ts +0 -3
- package/dist/syntax/analyze.js +0 -4
- package/dist/syntax/base.d.ts +0 -3
- package/dist/syntax/base.js +0 -19
- package/dist/syntax/cast.d.ts +0 -3
- package/dist/syntax/cast.js +0 -4
- package/dist/syntax/comment.d.ts +0 -3
- package/dist/syntax/comment.js +0 -54
- package/dist/syntax/constraint.d.ts +0 -6
- package/dist/syntax/constraint.js +0 -80
- package/dist/syntax/create_table.d.ts +0 -3
- package/dist/syntax/create_table.js +0 -69
- package/dist/syntax/data_type.d.ts +0 -3
- package/dist/syntax/data_type.js +0 -29
- package/dist/syntax/dcl.d.ts +0 -3
- package/dist/syntax/dcl.js +0 -83
- package/dist/syntax/delete.d.ts +0 -3
- package/dist/syntax/delete.js +0 -5
- package/dist/syntax/dialects/bigquery.d.ts +0 -3
- package/dist/syntax/dialects/bigquery.js +0 -84
- package/dist/syntax/dialects/mysql.d.ts +0 -3
- package/dist/syntax/dialects/mysql.js +0 -3
- package/dist/syntax/dialects/postgresql.d.ts +0 -3
- package/dist/syntax/dialects/postgresql.js +0 -9
- package/dist/syntax/dialects/sqlite.d.ts +0 -3
- package/dist/syntax/dialects/sqlite.js +0 -9
- package/dist/syntax/do.d.ts +0 -3
- package/dist/syntax/do.js +0 -4
- package/dist/syntax/domain.d.ts +0 -3
- package/dist/syntax/domain.js +0 -11
- package/dist/syntax/drop_table.d.ts +0 -3
- package/dist/syntax/drop_table.js +0 -11
- package/dist/syntax/explain.d.ts +0 -3
- package/dist/syntax/explain.js +0 -7
- package/dist/syntax/expr.d.ts +0 -5
- package/dist/syntax/expr.js +0 -224
- package/dist/syntax/extension.d.ts +0 -3
- package/dist/syntax/extension.js +0 -13
- package/dist/syntax/frame.d.ts +0 -3
- package/dist/syntax/frame.js +0 -13
- package/dist/syntax/function.d.ts +0 -4
- package/dist/syntax/function.js +0 -55
- package/dist/syntax/index.d.ts +0 -3
- package/dist/syntax/index.js +0 -60
- package/dist/syntax/insert.d.ts +0 -3
- package/dist/syntax/insert.js +0 -33
- package/dist/syntax/merge.d.ts +0 -3
- package/dist/syntax/merge.js +0 -30
- package/dist/syntax/other_clauses.d.ts +0 -3
- package/dist/syntax/other_clauses.js +0 -9
- package/dist/syntax/parameter.d.ts +0 -3
- package/dist/syntax/parameter.js +0 -18
- package/dist/syntax/policy.d.ts +0 -3
- package/dist/syntax/policy.js +0 -27
- package/dist/syntax/prepared_statements.d.ts +0 -3
- package/dist/syntax/prepared_statements.js +0 -31
- package/dist/syntax/proc_clause.d.ts +0 -3
- package/dist/syntax/proc_clause.js +0 -14
- package/dist/syntax/procedural_language.d.ts +0 -3
- package/dist/syntax/procedural_language.js +0 -104
- package/dist/syntax/procedure.d.ts +0 -3
- package/dist/syntax/procedure.js +0 -38
- package/dist/syntax/program.d.ts +0 -3
- package/dist/syntax/program.js +0 -39
- package/dist/syntax/publication.d.ts +0 -3
- package/dist/syntax/publication.js +0 -27
- package/dist/syntax/rename_table.d.ts +0 -3
- package/dist/syntax/rename_table.js +0 -8
- package/dist/syntax/role.d.ts +0 -3
- package/dist/syntax/role.js +0 -31
- package/dist/syntax/schema.d.ts +0 -3
- package/dist/syntax/schema.js +0 -18
- package/dist/syntax/select.d.ts +0 -3
- package/dist/syntax/select.js +0 -226
- package/dist/syntax/sequence.d.ts +0 -3
- package/dist/syntax/sequence.js +0 -36
- package/dist/syntax/subscription.d.ts +0 -3
- package/dist/syntax/subscription.js +0 -10
- package/dist/syntax/transaction.d.ts +0 -3
- package/dist/syntax/transaction.js +0 -19
- package/dist/syntax/transformMap.d.ts +0 -3
- package/dist/syntax/transformMap.js +0 -100
- package/dist/syntax/trigger.d.ts +0 -3
- package/dist/syntax/trigger.js +0 -52
- package/dist/syntax/truncate.d.ts +0 -3
- package/dist/syntax/truncate.js +0 -10
- package/dist/syntax/type.d.ts +0 -3
- package/dist/syntax/type.js +0 -12
- package/dist/syntax/unsupported_grammar.d.ts +0 -3
- package/dist/syntax/unsupported_grammar.js +0 -4
- package/dist/syntax/update.d.ts +0 -3
- package/dist/syntax/update.js +0 -14
- package/dist/syntax/view.d.ts +0 -3
- package/dist/syntax/view.js +0 -48
- package/dist/transform/addFinalSemicolon.d.ts +0 -2
- package/dist/transform/addFinalSemicolon.js +0 -9
- package/dist/transform/aliasAs.d.ts +0 -2
- package/dist/transform/aliasAs.js +0 -10
- package/dist/transform/canonicKeywords.d.ts +0 -2
- package/dist/transform/canonicKeywords.js +0 -62
- package/dist/transform/canonicOperators.d.ts +0 -3
- package/dist/transform/canonicOperators.js +0 -28
- package/dist/transform/comments.d.ts +0 -12
- package/dist/transform/comments.js +0 -22
- package/dist/transform/stripTrailingCommas.d.ts +0 -2
- package/dist/transform/stripTrailingCommas.js +0 -15
- package/dist/transform/transformCst.d.ts +0 -5
- package/dist/transform/transformCst.js +0 -21
- package/dist/transform/transformUtils.d.ts +0 -2
- package/dist/transform/transformUtils.js +0 -3
- package/dist/utils.d.ts +0 -9
- package/dist/utils.js +0 -9
- package/dist/visitAllNodes.d.ts +0 -2
- package/dist/visitAllNodes.js +0 -16
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { cstVisitor } from "sql-parser-cst";
|
|
2
|
-
import { keyword } from "./transformUtils";
|
|
3
|
-
export const canonicKeywords = (cst) => {
|
|
4
|
-
cstVisitor({
|
|
5
|
-
// Replaces TEMP with TEMPORARY
|
|
6
|
-
relation_kind: (node) => {
|
|
7
|
-
if (Array.isArray(node.kindKw)) {
|
|
8
|
-
// TODO...
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
if (node.kindKw.name === "TEMP") {
|
|
12
|
-
node.kindKw.name = "TEMPORARY";
|
|
13
|
-
node.kindKw.text = "TEMPORARY";
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
// Replaces MySQL SELECT DISTINCTROW with SELECT DISTINCT
|
|
18
|
-
select_distinct: (node) => {
|
|
19
|
-
if (node.distinctKw.name === "DISTINCTROW") {
|
|
20
|
-
node.distinctKw.name = "DISTINCT";
|
|
21
|
-
node.distinctKw.text = "DISTINCT";
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
// Replaces RENAME & RENAME AS with RENAME TO
|
|
25
|
-
alter_action_rename: (node) => {
|
|
26
|
-
if (Array.isArray(node.renameKw)) {
|
|
27
|
-
if (node.renameKw[1].name === "AS") {
|
|
28
|
-
node.renameKw[1].name = "TO";
|
|
29
|
-
node.renameKw[1].text = "TO";
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
node.renameKw = [node.renameKw, keyword("TO")];
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
// Replaces INSERT with INSERT INTO
|
|
37
|
-
insert_clause: (node) => {
|
|
38
|
-
if (!node.intoKw) {
|
|
39
|
-
node.intoKw = keyword("INTO");
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
// Replaces MERGE with MERGE INTO
|
|
43
|
-
merge_clause: (node) => {
|
|
44
|
-
if (!node.intoKw) {
|
|
45
|
-
node.intoKw = keyword("INTO");
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
// Replaces DELETE with DELETE FROM
|
|
49
|
-
delete_clause: (node) => {
|
|
50
|
-
if (!node.fromKw) {
|
|
51
|
-
node.fromKw = keyword("FROM");
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
// Replaces TRUNCATE with TRUNCATE TABLE
|
|
55
|
-
truncate_stmt: (node) => {
|
|
56
|
-
if (!node.tableKw) {
|
|
57
|
-
node.tableKw = keyword("TABLE");
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
})(cst);
|
|
61
|
-
return cst;
|
|
62
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { cstVisitor } from "sql-parser-cst";
|
|
2
|
-
import { keyword } from "./transformUtils";
|
|
3
|
-
export const canonicOperators = (cst, originalText, options) => {
|
|
4
|
-
cstVisitor({
|
|
5
|
-
binary_expr: (node) => {
|
|
6
|
-
// Replaces <> operator with !=
|
|
7
|
-
if (node.operator === "<>") {
|
|
8
|
-
node.operator = "!=";
|
|
9
|
-
}
|
|
10
|
-
// Replace MySQL && and || operators with AND and OR
|
|
11
|
-
if (options.parser === "mysql" || options.parser === "mariadb") {
|
|
12
|
-
if (node.operator === "&&") {
|
|
13
|
-
node.operator = keyword("AND");
|
|
14
|
-
}
|
|
15
|
-
if (node.operator === "||") {
|
|
16
|
-
node.operator = keyword("OR");
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
// Replaces PostgreSQL deprecated := operator with =>
|
|
21
|
-
named_arg: (node) => {
|
|
22
|
-
if (node.operator === ":=") {
|
|
23
|
-
node.operator = "=>";
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
})(cst);
|
|
27
|
-
return cst;
|
|
28
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Program, Whitespace } from "sql-parser-cst";
|
|
2
|
-
/**
|
|
3
|
-
* Gathers comments from .leading and .trailing fields of all nodes
|
|
4
|
-
* into a single .comments field in root Program node.
|
|
5
|
-
*
|
|
6
|
-
* Previously this also deleted all .leading and .trailing fields,
|
|
7
|
-
* but we need this info to check whether the empty lines between nodes
|
|
8
|
-
* are perhaps inside comments (see hasEmptyLineBetweenNodes()).
|
|
9
|
-
*/
|
|
10
|
-
export declare const moveCommentsToRoot: (cst: Program) => Program & {
|
|
11
|
-
comments: Whitespace[];
|
|
12
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { visitAllNodes } from "../visitAllNodes";
|
|
2
|
-
/**
|
|
3
|
-
* Gathers comments from .leading and .trailing fields of all nodes
|
|
4
|
-
* into a single .comments field in root Program node.
|
|
5
|
-
*
|
|
6
|
-
* Previously this also deleted all .leading and .trailing fields,
|
|
7
|
-
* but we need this info to check whether the empty lines between nodes
|
|
8
|
-
* are perhaps inside comments (see hasEmptyLineBetweenNodes()).
|
|
9
|
-
*/
|
|
10
|
-
export const moveCommentsToRoot = (cst) => {
|
|
11
|
-
return {
|
|
12
|
-
...cst,
|
|
13
|
-
comments: extractComments(cst),
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
const extractComments = (cst) => {
|
|
17
|
-
const comments = [];
|
|
18
|
-
visitAllNodes(cst, (node) => {
|
|
19
|
-
comments.push(...(node.leading || []), ...(node.trailing || []));
|
|
20
|
-
});
|
|
21
|
-
return comments;
|
|
22
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { cstVisitor } from "sql-parser-cst";
|
|
2
|
-
import { isEmpty } from "../node_utils";
|
|
3
|
-
import { last } from "../utils";
|
|
4
|
-
// Removes trailing comma from SELECT clauses
|
|
5
|
-
export const stripTrailingCommas = (cst) => {
|
|
6
|
-
// Trailing comma is represented as an empty element at the end of column list
|
|
7
|
-
cstVisitor({
|
|
8
|
-
select_clause: (node) => {
|
|
9
|
-
if (node.columns && isEmpty(last(node.columns.items))) {
|
|
10
|
-
node.columns.items = node.columns.items.slice(0, -1);
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
})(cst);
|
|
14
|
-
return cst;
|
|
15
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { moveCommentsToRoot } from "./comments";
|
|
2
|
-
import { processAliasAs } from "./aliasAs";
|
|
3
|
-
import { stripTrailingCommas } from "./stripTrailingCommas";
|
|
4
|
-
import { addFinalSemicolon } from "./addFinalSemicolon";
|
|
5
|
-
import { canonicKeywords } from "./canonicKeywords";
|
|
6
|
-
import { canonicOperators } from "./canonicOperators";
|
|
7
|
-
export const transformCst = (cst, originalText, options) => {
|
|
8
|
-
const transforms = [
|
|
9
|
-
// Note that we first perform moveCommentsToRoot transform,
|
|
10
|
-
// so we don't need to worry about comments interfering with other transforms
|
|
11
|
-
moveCommentsToRoot,
|
|
12
|
-
stripTrailingCommas,
|
|
13
|
-
];
|
|
14
|
-
if (options.sqlFinalSemicolon) {
|
|
15
|
-
transforms.push(addFinalSemicolon);
|
|
16
|
-
}
|
|
17
|
-
if (options.sqlCanonicalSyntax) {
|
|
18
|
-
transforms.push(processAliasAs, canonicOperators, canonicKeywords);
|
|
19
|
-
}
|
|
20
|
-
return transforms.reduce((cst, transform) => transform(cst, originalText, options), cst);
|
|
21
|
-
};
|
package/dist/utils.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Node } from "sql-parser-cst";
|
|
2
|
-
export declare const isDefined: <T>(value: T | undefined) => value is T;
|
|
3
|
-
export declare const isString: (value: any) => value is string;
|
|
4
|
-
export declare const isObject: (x: any) => x is Record<string, any>;
|
|
5
|
-
export declare const isArray: (x: any) => x is any[];
|
|
6
|
-
export declare const isEmptyArray: (x: any) => x is [];
|
|
7
|
-
export declare const isNode: (value: any) => value is Node;
|
|
8
|
-
export declare const arrayWrap: <T>(x: T | T[]) => T[];
|
|
9
|
-
export declare const last: <T>(arr: T[]) => T;
|
package/dist/utils.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export const isDefined = (value) => value !== undefined;
|
|
2
|
-
export const isString = (value) => typeof value === "string";
|
|
3
|
-
export const isObject = (x) => typeof x === "object" && x !== null && !(x instanceof Array);
|
|
4
|
-
export const isArray = (x) => Array.isArray(x);
|
|
5
|
-
export const isEmptyArray = (x) => isArray(x) && x.length === 0;
|
|
6
|
-
export const isNode = (value) => isObject(value) && isString(value.type) && !isCommentType(value.type);
|
|
7
|
-
const isCommentType = (type) => type === "block_comment" || type === "line_comment";
|
|
8
|
-
export const arrayWrap = (x) => (isArray(x) ? x : [x]);
|
|
9
|
-
export const last = (arr) => arr[arr.length - 1];
|
package/dist/visitAllNodes.d.ts
DELETED
package/dist/visitAllNodes.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { isArray, isNode } from "./utils";
|
|
2
|
-
/* Executes a function with all nodes in syntax tree */
|
|
3
|
-
export const visitAllNodes = (node, visit) => {
|
|
4
|
-
visit(node);
|
|
5
|
-
// Visit all children
|
|
6
|
-
for (const child of Object.values(node)) {
|
|
7
|
-
if (isNode(child)) {
|
|
8
|
-
visitAllNodes(child, visit);
|
|
9
|
-
}
|
|
10
|
-
else if (isArray(child)) {
|
|
11
|
-
child
|
|
12
|
-
.filter(isNode)
|
|
13
|
-
.forEach((childNode) => visitAllNodes(childNode, visit));
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
};
|