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.
Files changed (145) hide show
  1. package/dist/index.d.ts +21 -7
  2. package/dist/index.js +2637 -55
  3. package/package.json +3 -2
  4. package/dist/CstToDocMap.d.ts +0 -11
  5. package/dist/CstToDocMap.js +0 -1
  6. package/dist/PrintFn.d.ts +0 -17
  7. package/dist/PrintFn.js +0 -1
  8. package/dist/embed.d.ts +0 -3
  9. package/dist/embed.js +0 -6
  10. package/dist/embedJs.d.ts +0 -3
  11. package/dist/embedJs.js +0 -43
  12. package/dist/embedJson.d.ts +0 -3
  13. package/dist/embedJson.js +0 -34
  14. package/dist/embedSql.d.ts +0 -3
  15. package/dist/embedSql.js +0 -39
  16. package/dist/node_utils.d.ts +0 -38
  17. package/dist/node_utils.js +0 -44
  18. package/dist/options.d.ts +0 -15
  19. package/dist/options.js +0 -147
  20. package/dist/printComment.d.ts +0 -3
  21. package/dist/printComment.js +0 -12
  22. package/dist/printSql.d.ts +0 -5
  23. package/dist/printSql.js +0 -61
  24. package/dist/print_utils.d.ts +0 -13
  25. package/dist/print_utils.js +0 -49
  26. package/dist/syntax/alias.d.ts +0 -3
  27. package/dist/syntax/alias.js +0 -3
  28. package/dist/syntax/alter_action.d.ts +0 -3
  29. package/dist/syntax/alter_action.js +0 -120
  30. package/dist/syntax/alter_table.d.ts +0 -3
  31. package/dist/syntax/alter_table.js +0 -19
  32. package/dist/syntax/analyze.d.ts +0 -3
  33. package/dist/syntax/analyze.js +0 -4
  34. package/dist/syntax/base.d.ts +0 -3
  35. package/dist/syntax/base.js +0 -19
  36. package/dist/syntax/cast.d.ts +0 -3
  37. package/dist/syntax/cast.js +0 -4
  38. package/dist/syntax/comment.d.ts +0 -3
  39. package/dist/syntax/comment.js +0 -54
  40. package/dist/syntax/constraint.d.ts +0 -6
  41. package/dist/syntax/constraint.js +0 -80
  42. package/dist/syntax/create_table.d.ts +0 -3
  43. package/dist/syntax/create_table.js +0 -69
  44. package/dist/syntax/data_type.d.ts +0 -3
  45. package/dist/syntax/data_type.js +0 -29
  46. package/dist/syntax/dcl.d.ts +0 -3
  47. package/dist/syntax/dcl.js +0 -83
  48. package/dist/syntax/delete.d.ts +0 -3
  49. package/dist/syntax/delete.js +0 -5
  50. package/dist/syntax/dialects/bigquery.d.ts +0 -3
  51. package/dist/syntax/dialects/bigquery.js +0 -84
  52. package/dist/syntax/dialects/mysql.d.ts +0 -3
  53. package/dist/syntax/dialects/mysql.js +0 -3
  54. package/dist/syntax/dialects/postgresql.d.ts +0 -3
  55. package/dist/syntax/dialects/postgresql.js +0 -9
  56. package/dist/syntax/dialects/sqlite.d.ts +0 -3
  57. package/dist/syntax/dialects/sqlite.js +0 -9
  58. package/dist/syntax/do.d.ts +0 -3
  59. package/dist/syntax/do.js +0 -4
  60. package/dist/syntax/domain.d.ts +0 -3
  61. package/dist/syntax/domain.js +0 -11
  62. package/dist/syntax/drop_table.d.ts +0 -3
  63. package/dist/syntax/drop_table.js +0 -11
  64. package/dist/syntax/explain.d.ts +0 -3
  65. package/dist/syntax/explain.js +0 -7
  66. package/dist/syntax/expr.d.ts +0 -5
  67. package/dist/syntax/expr.js +0 -224
  68. package/dist/syntax/extension.d.ts +0 -3
  69. package/dist/syntax/extension.js +0 -13
  70. package/dist/syntax/frame.d.ts +0 -3
  71. package/dist/syntax/frame.js +0 -13
  72. package/dist/syntax/function.d.ts +0 -4
  73. package/dist/syntax/function.js +0 -55
  74. package/dist/syntax/index.d.ts +0 -3
  75. package/dist/syntax/index.js +0 -60
  76. package/dist/syntax/insert.d.ts +0 -3
  77. package/dist/syntax/insert.js +0 -33
  78. package/dist/syntax/merge.d.ts +0 -3
  79. package/dist/syntax/merge.js +0 -30
  80. package/dist/syntax/other_clauses.d.ts +0 -3
  81. package/dist/syntax/other_clauses.js +0 -9
  82. package/dist/syntax/parameter.d.ts +0 -3
  83. package/dist/syntax/parameter.js +0 -18
  84. package/dist/syntax/policy.d.ts +0 -3
  85. package/dist/syntax/policy.js +0 -27
  86. package/dist/syntax/prepared_statements.d.ts +0 -3
  87. package/dist/syntax/prepared_statements.js +0 -31
  88. package/dist/syntax/proc_clause.d.ts +0 -3
  89. package/dist/syntax/proc_clause.js +0 -14
  90. package/dist/syntax/procedural_language.d.ts +0 -3
  91. package/dist/syntax/procedural_language.js +0 -104
  92. package/dist/syntax/procedure.d.ts +0 -3
  93. package/dist/syntax/procedure.js +0 -38
  94. package/dist/syntax/program.d.ts +0 -3
  95. package/dist/syntax/program.js +0 -39
  96. package/dist/syntax/publication.d.ts +0 -3
  97. package/dist/syntax/publication.js +0 -27
  98. package/dist/syntax/rename_table.d.ts +0 -3
  99. package/dist/syntax/rename_table.js +0 -8
  100. package/dist/syntax/role.d.ts +0 -3
  101. package/dist/syntax/role.js +0 -31
  102. package/dist/syntax/schema.d.ts +0 -3
  103. package/dist/syntax/schema.js +0 -18
  104. package/dist/syntax/select.d.ts +0 -3
  105. package/dist/syntax/select.js +0 -226
  106. package/dist/syntax/sequence.d.ts +0 -3
  107. package/dist/syntax/sequence.js +0 -36
  108. package/dist/syntax/subscription.d.ts +0 -3
  109. package/dist/syntax/subscription.js +0 -10
  110. package/dist/syntax/transaction.d.ts +0 -3
  111. package/dist/syntax/transaction.js +0 -19
  112. package/dist/syntax/transformMap.d.ts +0 -3
  113. package/dist/syntax/transformMap.js +0 -100
  114. package/dist/syntax/trigger.d.ts +0 -3
  115. package/dist/syntax/trigger.js +0 -52
  116. package/dist/syntax/truncate.d.ts +0 -3
  117. package/dist/syntax/truncate.js +0 -10
  118. package/dist/syntax/type.d.ts +0 -3
  119. package/dist/syntax/type.js +0 -12
  120. package/dist/syntax/unsupported_grammar.d.ts +0 -3
  121. package/dist/syntax/unsupported_grammar.js +0 -4
  122. package/dist/syntax/update.d.ts +0 -3
  123. package/dist/syntax/update.js +0 -14
  124. package/dist/syntax/view.d.ts +0 -3
  125. package/dist/syntax/view.js +0 -48
  126. package/dist/transform/addFinalSemicolon.d.ts +0 -2
  127. package/dist/transform/addFinalSemicolon.js +0 -9
  128. package/dist/transform/aliasAs.d.ts +0 -2
  129. package/dist/transform/aliasAs.js +0 -10
  130. package/dist/transform/canonicKeywords.d.ts +0 -2
  131. package/dist/transform/canonicKeywords.js +0 -62
  132. package/dist/transform/canonicOperators.d.ts +0 -3
  133. package/dist/transform/canonicOperators.js +0 -28
  134. package/dist/transform/comments.d.ts +0 -12
  135. package/dist/transform/comments.js +0 -22
  136. package/dist/transform/stripTrailingCommas.d.ts +0 -2
  137. package/dist/transform/stripTrailingCommas.js +0 -15
  138. package/dist/transform/transformCst.d.ts +0 -5
  139. package/dist/transform/transformCst.js +0 -21
  140. package/dist/transform/transformUtils.d.ts +0 -2
  141. package/dist/transform/transformUtils.js +0 -3
  142. package/dist/utils.d.ts +0 -9
  143. package/dist/utils.js +0 -9
  144. package/dist/visitAllNodes.d.ts +0 -2
  145. 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,3 +0,0 @@
1
- import { Program } from "sql-parser-cst";
2
- import { AllPrettierOptions } from "src/options";
3
- export declare const canonicOperators: (cst: Program, originalText: string, options: AllPrettierOptions) => Program;
@@ -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,2 +0,0 @@
1
- import { Program } from "sql-parser-cst";
2
- export declare const stripTrailingCommas: (cst: Program) => Program;
@@ -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,5 +0,0 @@
1
- import { Program } from "sql-parser-cst";
2
- import { AllPrettierOptions } from "src/options";
3
- export declare const transformCst: TransformFn;
4
- type TransformFn = (cst: Program, originalText: string, options: AllPrettierOptions) => Program;
5
- export {};
@@ -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
- };
@@ -1,2 +0,0 @@
1
- import { Keyword } from "sql-parser-cst";
2
- export declare function keyword<T extends string>(name: T): Keyword<T>;
@@ -1,3 +0,0 @@
1
- export function keyword(name) {
2
- return { type: "keyword", name, text: name };
3
- }
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];
@@ -1,2 +0,0 @@
1
- import { Node } from "sql-parser-cst";
2
- export declare const visitAllNodes: (node: Node, visit: (node: Node) => void) => void;
@@ -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
- };