prettier-plugin-sql-cst 0.18.0 → 0.19.1

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 (76) hide show
  1. package/dist/CstToDocMap.d.ts +2 -2
  2. package/dist/CstToDocMap.js +1 -2
  3. package/dist/PrintFn.js +1 -2
  4. package/dist/embed.js +5 -13
  5. package/dist/embedJs.js +28 -84
  6. package/dist/embedJson.js +29 -85
  7. package/dist/embedSql.js +26 -76
  8. package/dist/index.js +28 -34
  9. package/dist/node_utils.d.ts +1 -0
  10. package/dist/node_utils.js +44 -54
  11. package/dist/options.js +1 -4
  12. package/dist/printComment.js +2 -6
  13. package/dist/printSql.js +29 -39
  14. package/dist/print_utils.js +19 -38
  15. package/dist/syntax/alias.js +2 -5
  16. package/dist/syntax/alter_action.js +115 -208
  17. package/dist/syntax/alter_table.js +18 -27
  18. package/dist/syntax/analyze.js +3 -8
  19. package/dist/syntax/base.js +6 -9
  20. package/dist/syntax/cast.js +3 -6
  21. package/dist/syntax/comment.js +53 -122
  22. package/dist/syntax/constraint.d.ts +1 -1
  23. package/dist/syntax/constraint.js +54 -90
  24. package/dist/syntax/create_table.js +49 -87
  25. package/dist/syntax/data_type.js +25 -44
  26. package/dist/syntax/dcl.js +78 -136
  27. package/dist/syntax/delete.js +4 -9
  28. package/dist/syntax/dialects/bigquery.js +70 -116
  29. package/dist/syntax/dialects/mysql.js +2 -5
  30. package/dist/syntax/dialects/postgresql.js +8 -13
  31. package/dist/syntax/dialects/sqlite.js +8 -17
  32. package/dist/syntax/do.js +3 -6
  33. package/dist/syntax/domain.js +10 -19
  34. package/dist/syntax/drop_table.js +10 -15
  35. package/dist/syntax/explain.js +6 -11
  36. package/dist/syntax/expr.js +124 -173
  37. package/dist/syntax/extension.js +12 -21
  38. package/dist/syntax/frame.js +11 -16
  39. package/dist/syntax/function.js +53 -63
  40. package/dist/syntax/index.js +54 -81
  41. package/dist/syntax/insert.js +32 -49
  42. package/dist/syntax/merge.js +25 -30
  43. package/dist/syntax/other_clauses.js +5 -14
  44. package/dist/syntax/parameter.js +13 -26
  45. package/dist/syntax/policy.js +26 -41
  46. package/dist/syntax/prepared_statements.js +23 -43
  47. package/dist/syntax/proc_clause.js +10 -15
  48. package/dist/syntax/procedural_language.js +80 -111
  49. package/dist/syntax/procedure.js +36 -40
  50. package/dist/syntax/program.js +15 -22
  51. package/dist/syntax/publication.js +26 -47
  52. package/dist/syntax/rename_table.js +7 -12
  53. package/dist/syntax/role.js +30 -55
  54. package/dist/syntax/schema.js +17 -35
  55. package/dist/syntax/select.js +157 -226
  56. package/dist/syntax/sequence.js +35 -52
  57. package/dist/syntax/subscription.js +9 -24
  58. package/dist/syntax/transaction.js +18 -33
  59. package/dist/syntax/transformMap.js +99 -63
  60. package/dist/syntax/trigger.js +48 -72
  61. package/dist/syntax/truncate.js +9 -14
  62. package/dist/syntax/type.js +11 -22
  63. package/dist/syntax/unsupported_grammar.js +3 -6
  64. package/dist/syntax/update.js +7 -14
  65. package/dist/syntax/view.js +32 -43
  66. package/dist/transform/addFinalSemicolon.js +5 -9
  67. package/dist/transform/aliasAs.js +4 -8
  68. package/dist/transform/canonicKeywords.js +16 -20
  69. package/dist/transform/canonicOperators.js +8 -12
  70. package/dist/transform/comments.js +10 -31
  71. package/dist/transform/stripTrailingCommas.js +7 -11
  72. package/dist/transform/transformCst.js +13 -17
  73. package/dist/transform/transformUtils.js +2 -6
  74. package/dist/utils.js +9 -30
  75. package/dist/visitAllNodes.js +8 -13
  76. package/package.json +9 -8
package/dist/printSql.js CHANGED
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printSql = void 0;
4
- var utils_1 = require("./utils");
5
- var transformMap_1 = require("./syntax/transformMap");
6
- var print_utils_1 = require("./print_utils");
7
- function printSql(path, options, oldPrint) {
1
+ import { arrayWrap, isArray, isDefined, isEmptyArray, isString } from "./utils";
2
+ import { transformMap } from "./syntax/transformMap";
3
+ import { containsNewline, hardline, join, line } from "./print_utils";
4
+ export function printSql(path, options, oldPrint) {
8
5
  return printNode(path, options, createPrintFn(path, oldPrint, options));
9
6
  }
10
- exports.printSql = printSql;
11
- var cachedPrintFn;
12
- var cachedPath;
7
+ let cachedPrintFn;
8
+ let cachedPath;
13
9
  function createPrintFn(path, oldPrint, opts) {
14
10
  // The path parameter will reference the same AstPath instance
15
11
  // during the whole printing cycle.
@@ -19,53 +15,47 @@ function createPrintFn(path, oldPrint, opts) {
19
15
  return cachedPrintFn;
20
16
  }
21
17
  cachedPath = path;
22
- cachedPrintFn = (function (selector) {
23
- if ((0, utils_1.isArray)(selector)) {
24
- var node_1 = path.node;
25
- return selector.filter(function (sel) { return (0, utils_1.isDefined)(node_1[sel]); }).map(oldPrint);
18
+ cachedPrintFn = ((selector) => {
19
+ if (isArray(selector)) {
20
+ const node = path.node;
21
+ return selector.filter((sel) => isDefined(node[sel])).map(oldPrint);
26
22
  }
27
23
  else {
28
24
  return oldPrint(selector);
29
25
  }
30
26
  });
31
- cachedPrintFn.separated = function (separator, selector) {
32
- var node = path.node;
33
- var docs = (0, utils_1.arrayWrap)(selector)
34
- .filter(function (sel) { return (0, utils_1.isDefined)(node[sel]); })
35
- .map(function (sel) { return [sel, oldPrint(sel)]; })
27
+ cachedPrintFn.separated = (separator, selector) => {
28
+ const node = path.node;
29
+ const docs = arrayWrap(selector)
30
+ .filter((sel) => isDefined(node[sel]))
31
+ .map((sel) => [sel, oldPrint(sel)])
36
32
  // skip empty arrays
37
- .filter(function (_a) {
38
- var sel = _a[0], doc = _a[1];
39
- return !(0, utils_1.isEmptyArray)(doc);
40
- })
33
+ .filter(([sel, doc]) => !isEmptyArray(doc))
41
34
  // only join with spaces when input to print was Node[]
42
- .map(function (_a) {
43
- var sel = _a[0], doc = _a[1];
44
- return ((0, utils_1.isArray)(node[sel]) ? (0, print_utils_1.join)(" ", doc) : doc);
45
- });
46
- return docs.length > 0 ? [(0, print_utils_1.join)(separator, docs)] : [];
35
+ .map(([sel, doc]) => (isArray(node[sel]) ? join(" ", doc) : doc));
36
+ return docs.length > 0 ? [join(separator, docs)] : [];
47
37
  };
48
- cachedPrintFn.spaced = function (selector) { return cachedPrintFn.separated(" ", selector); };
49
- cachedPrintFn.dynamicLine = function () {
50
- var node = path.node;
51
- return (0, print_utils_1.containsNewline)(node, opts) ? print_utils_1.hardline : print_utils_1.line;
38
+ cachedPrintFn.spaced = (selector) => cachedPrintFn.separated(" ", selector);
39
+ cachedPrintFn.dynamicLine = () => {
40
+ const node = path.node;
41
+ return containsNewline(node, opts) ? hardline : line;
52
42
  };
53
43
  return cachedPrintFn;
54
44
  }
55
45
  function printNode(path, options, print) {
56
- var node = path.node;
57
- if ((0, utils_1.isArray)(node)) {
46
+ const node = path.node;
47
+ if (isArray(node)) {
58
48
  return path.map(print);
59
49
  }
60
- if ((0, utils_1.isString)(node)) {
50
+ if (isString(node)) {
61
51
  return node;
62
52
  }
63
- if (!(node === null || node === void 0 ? void 0 : node.type)) {
64
- throw new Error("No type field on node: ".concat(JSON.stringify(node)));
53
+ if (!node?.type) {
54
+ throw new Error(`No type field on node: ${JSON.stringify(node)}`);
65
55
  }
66
- var fn = transformMap_1.transformMap[node.type];
56
+ const fn = transformMap[node.type];
67
57
  if (!fn) {
68
- throw new Error("Unexpected node type: ".concat(node.type));
58
+ throw new Error(`Unexpected node type: ${node.type}`);
69
59
  }
70
60
  return fn(print, node, path, options);
71
61
  }
@@ -1,57 +1,38 @@
1
- "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
- var _a;
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.hasEmptyLineBetweenNodes = exports.containsNewline = exports.join = exports.stripTrailingHardline = exports.breakParent = exports.ifBreak = exports.lineSuffix = exports.group = exports.indent = exports.softline = exports.hardline = exports.line = void 0;
14
- var prettier_1 = require("prettier");
15
- var utils_1 = require("./utils");
16
- exports.line = (_a = prettier_1.doc.builders, _a.line), exports.hardline = _a.hardline, exports.softline = _a.softline, exports.indent = _a.indent, exports.group = _a.group, exports.lineSuffix = _a.lineSuffix, exports.ifBreak = _a.ifBreak, exports.breakParent = _a.breakParent;
17
- var origJoin = prettier_1.doc.builders.join;
18
- exports.stripTrailingHardline = prettier_1.doc.utils.stripTrailingHardline;
1
+ import { doc, util } from "prettier";
2
+ import { isArray } from "./utils";
3
+ export const { line, hardline, softline, indent, group, lineSuffix, ifBreak, breakParent, } = doc.builders;
4
+ const { join: origJoin } = doc.builders;
5
+ export const { stripTrailingHardline } = doc.utils;
19
6
  /** Improved join() that also accepts a non-array docs parameter */
20
- var join = function (sep, docs) {
21
- return (0, utils_1.isArray)(docs) ? origJoin(sep, docs) : docs;
22
- };
23
- exports.join = join;
7
+ export const join = (sep, docs) => isArray(docs) ? origJoin(sep, docs) : docs;
24
8
  /** True when the Node contains a newline in original source code */
25
- var containsNewline = function (node, opts) {
9
+ export const containsNewline = (node, opts) => {
26
10
  if (!node.range) {
27
11
  throw new Error("containsNewline() expected a Node with range info");
28
12
  }
29
- return prettier_1.util.hasNewlineInRange(opts.originalText, node.range[0], node.range[1]);
13
+ return util.hasNewlineInRange(opts.originalText, node.range[0], node.range[1]);
30
14
  };
31
- exports.containsNewline = containsNewline;
32
- var hasEmptyLineBetweenNodes = function (node1, node2, opts) {
33
- var _a, _b;
15
+ export const hasEmptyLineBetweenNodes = (node1, node2, opts) => {
34
16
  if (!node1.range || !node2.range) {
35
17
  throw new Error("emptyLineBetweenNodes() expects Nodes with range info");
36
18
  }
37
- var start = node1.range[1];
38
- var end = node2.range[0];
39
- var indexes = emptyLineIndexes(opts.originalText.slice(start, end)).map(function (i) { return start + i; });
19
+ const start = node1.range[1];
20
+ const end = node2.range[0];
21
+ const indexes = emptyLineIndexes(opts.originalText.slice(start, end)).map((i) => start + i);
40
22
  // when no empty lines between nodes, we can return early
41
23
  if (indexes.length === 0) {
42
24
  return false;
43
25
  }
44
26
  // otherwise we need to check whether the empty line happens to be
45
27
  // inside a comment or between comments
46
- var comments = __spreadArray(__spreadArray([], ((_a = node1.trailing) !== null && _a !== void 0 ? _a : []), true), ((_b = node2.leading) !== null && _b !== void 0 ? _b : []), true);
47
- return (indexes.filter(function (index) { return !isIndexInsideOrBetweenComments(index, comments); })
28
+ const comments = [...(node1.trailing ?? []), ...(node2.leading ?? [])];
29
+ return (indexes.filter((index) => !isIndexInsideOrBetweenComments(index, comments))
48
30
  .length > 0);
49
31
  };
50
- exports.hasEmptyLineBetweenNodes = hasEmptyLineBetweenNodes;
51
32
  function emptyLineIndexes(text) {
52
- var indexes = [];
53
- var re = /\n[ \t]*\r?\n/g;
54
- var match;
33
+ const indexes = [];
34
+ const re = /\n[ \t]*\r?\n/g;
35
+ let match;
55
36
  while ((match = re.exec(text))) {
56
37
  indexes.push(match.index);
57
38
  }
@@ -62,7 +43,7 @@ function isIndexInsideOrBetweenComments(index, comments) {
62
43
  return false;
63
44
  }
64
45
  // Assume all nodes have range info
65
- var start = comments[0].range[0];
66
- var end = comments[comments.length - 1].range[1];
46
+ const start = comments[0].range[0];
47
+ const end = comments[comments.length - 1].range[1];
67
48
  return start <= index && index <= end;
68
49
  }
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.aliasMap = void 0;
4
- exports.aliasMap = {
5
- alias: function (print) { return print.spaced(["expr", "asKw", "alias", "columnAliases"]); },
1
+ export const aliasMap = {
2
+ alias: (print) => print.spaced(["expr", "asKw", "alias", "columnAliases"]),
6
3
  };
@@ -1,213 +1,120 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.alterActionMap = void 0;
4
- var print_utils_1 = require("../print_utils");
5
- var constraint_1 = require("./constraint");
6
- exports.alterActionMap = {
7
- alter_action_rename: function (print) { return print.spaced(["renameKw", "newName"]); },
8
- alter_action_rename_column: function (print) {
9
- return print.spaced(["renameKw", "ifExistsKw", "oldName", "toKw", "newName"]);
10
- },
11
- alter_action_add_column: function (print) {
12
- return print.spaced(["addKw", "ifNotExistsKw", "column"]);
13
- },
14
- alter_action_drop_column: function (print) {
15
- return print.spaced(["dropKw", "ifExistsKw", "column", "behaviorKw"]);
16
- },
17
- alter_action_set_bigquery_options: function (print) {
18
- return print.spaced(["setKw", "options"]);
19
- },
20
- alter_action_set_default_collate: function (print) {
21
- return print.spaced(["setDefaultCollateKw", "collation"]);
22
- },
1
+ import { group, indent, join, line } from "../print_utils";
2
+ import { printUnnamedConstraint } from "./constraint";
3
+ export const alterActionMap = {
4
+ alter_action_rename: (print) => print.spaced(["renameKw", "newName"]),
5
+ alter_action_rename_column: (print) => print.spaced(["renameKw", "ifExistsKw", "oldName", "toKw", "newName"]),
6
+ alter_action_add_column: (print) => print.spaced(["addKw", "ifNotExistsKw", "column"]),
7
+ alter_action_drop_column: (print) => print.spaced(["dropKw", "ifExistsKw", "column", "behaviorKw"]),
8
+ alter_action_set_bigquery_options: (print) => print.spaced(["setKw", "options"]),
9
+ alter_action_set_default_collate: (print) => print.spaced(["setDefaultCollateKw", "collation"]),
23
10
  /** cst-ignore: constraint, modifiers */
24
- alter_action_add_constraint: function (print, node) {
25
- return (0, print_utils_1.group)([
26
- print.spaced(["addKw", "name"]),
27
- (0, print_utils_1.indent)([print_utils_1.line, (0, constraint_1.printUnnamedConstraint)(print, node)]),
28
- ]);
29
- },
30
- alter_action_add_constraint_constraint_name: function (print) {
31
- return print.spaced(["constraintKw", "ifNotExistsKw", "name"]);
32
- },
33
- alter_action_drop_constraint: function (print) {
34
- return print.spaced([
35
- "dropConstraintKw",
36
- "ifExistsKw",
37
- "constraint",
38
- "behaviorKw",
39
- ]);
40
- },
41
- alter_action_drop_primary_key: function (print) {
42
- return print.spaced(["dropPrimaryKeyKw", "ifExistsKw"]);
43
- },
44
- alter_action_alter_constraint: function (print) {
45
- return print.spaced(["alterConstraintKw", "constraint", "modifiers"]);
46
- },
47
- alter_action_rename_constraint: function (print) {
48
- return print.spaced(["renameConstraintKw", "oldName", "toKw", "newName"]);
49
- },
50
- alter_action_validate_constraint: function (print) {
51
- return print.spaced(["validateConstraintKw", "constraint"]);
52
- },
53
- alter_action_set_visible: function (print) { return print.spaced("setVisibleKw"); },
54
- alter_action_set_invisible: function (print) { return print.spaced("setInvisibleKw"); },
55
- alter_action_set_tablespace: function (print) {
56
- return print.spaced(["setTablespaceKw", "tablespace", "nowaitKw"]);
57
- },
58
- alter_action_set_schema: function (print) { return print.spaced(["setSchemaKw", "schema"]); },
59
- alter_action_enable: function (print) { return print.spaced(["enableKw", "modeKw", "item"]); },
60
- alter_action_disable: function (print) { return print.spaced(["disableKw", "item"]); },
61
- alter_action_force: function (print) { return print.spaced(["forceKw", "item"]); },
62
- alter_action_no_force: function (print) { return print.spaced(["noForceKw", "item"]); },
63
- alter_action_cluster_on: function (print) { return print.spaced(["clusterOnKw", "index"]); },
64
- alter_action_set_without_cluster: function (print) {
65
- return print.spaced("setWithoutClusterKw");
66
- },
67
- alter_action_set_without_oids: function (print) { return print.spaced("setWithoutOidsKw"); },
68
- alter_action_set_access_method: function (print) {
69
- return print.spaced(["setAccessMethodKw", "method"]);
70
- },
71
- alter_action_set_logged: function (print) { return print.spaced("setLoggedKw"); },
72
- alter_action_set_unlogged: function (print) { return print.spaced("setUnloggedKw"); },
73
- alter_action_inherit: function (print) { return print.spaced(["inheritKw", "table"]); },
74
- alter_action_no_inherit: function (print) { return print.spaced(["noInheritKw", "table"]); },
75
- alter_action_of_type: function (print) { return print.spaced(["ofKw", "typeName"]); },
76
- alter_action_not_of_type: function (print) { return print.spaced("notOfKw"); },
77
- alter_action_owner_to: function (print) { return print.spaced(["ownerToKw", "owner"]); },
78
- alter_action_replica_identity: function (print) {
79
- return print.spaced(["replicaIdentityKw", "identity"]);
80
- },
81
- replica_identity_using_index: function (print) {
82
- return print.spaced(["usingIndexKw", "index"]);
83
- },
84
- alter_action_set_postgresql_options: function (print) {
85
- return print.spaced(["setKw", "options"]);
86
- },
87
- alter_action_reset_postgresql_options: function (print) {
88
- return print.spaced(["resetKw", "options"]);
89
- },
90
- alter_action_depends_on_extension: function (print) {
91
- return print.spaced(["dependsOnExtensionKw", "extension"]);
92
- },
93
- alter_action_no_depends_on_extension: function (print) {
94
- return print.spaced(["noDependsOnExtensionKw", "extension"]);
95
- },
96
- alter_action_attach_partition: function (print) {
97
- return print.spaced(["attachPartitionKw", "index"]);
98
- },
99
- alter_action_add_enum_value: function (print) {
100
- return print.spaced(["addValueKw", "ifNotExistsKw", "value", "position"]);
101
- },
102
- alter_action_add_enum_value_position: function (print) {
103
- return print.spaced(["positionKw", "value"]);
104
- },
105
- alter_action_rename_enum_value: function (print) {
106
- return print.spaced(["renameValueKw", "oldValue", "toKw", "newValue"]);
107
- },
108
- alter_action_add_attribute: function (print) {
109
- return print.spaced([
110
- "addAttributeKw",
111
- "name",
112
- "dataType",
113
- "constraint",
114
- "behaviorKw",
115
- ]);
116
- },
117
- alter_action_drop_attribute: function (print) {
118
- return print.spaced(["dropAttributeKw", "ifExistsKw", "name", "behaviorKw"]);
119
- },
120
- alter_action_alter_attribute: function (print) {
121
- return print.spaced([
122
- "alterAttributeKw",
123
- "name",
124
- "setDataTypeKw",
125
- "dataType",
126
- "constraint",
127
- "behaviorKw",
128
- ]);
129
- },
130
- alter_action_rename_attribute: function (print) {
131
- return print.spaced([
132
- "renameAttributeKw",
133
- "oldName",
134
- "toKw",
135
- "newName",
136
- "behaviorKw",
137
- ]);
138
- },
11
+ alter_action_add_constraint: (print, node) => group([
12
+ print.spaced(["addKw", "name"]),
13
+ indent([line, printUnnamedConstraint(print, node)]),
14
+ ]),
15
+ alter_action_add_constraint_constraint_name: (print) => print.spaced(["constraintKw", "ifNotExistsKw", "name"]),
16
+ alter_action_drop_constraint: (print) => print.spaced([
17
+ "dropConstraintKw",
18
+ "ifExistsKw",
19
+ "constraint",
20
+ "behaviorKw",
21
+ ]),
22
+ alter_action_drop_primary_key: (print) => print.spaced(["dropPrimaryKeyKw", "ifExistsKw"]),
23
+ alter_action_alter_constraint: (print) => print.spaced(["alterConstraintKw", "constraint", "modifiers"]),
24
+ alter_action_rename_constraint: (print) => print.spaced(["renameConstraintKw", "oldName", "toKw", "newName"]),
25
+ alter_action_validate_constraint: (print) => print.spaced(["validateConstraintKw", "constraint"]),
26
+ alter_action_set_visible: (print) => print.spaced("setVisibleKw"),
27
+ alter_action_set_invisible: (print) => print.spaced("setInvisibleKw"),
28
+ alter_action_set_tablespace: (print) => print.spaced(["setTablespaceKw", "tablespace", "nowaitKw"]),
29
+ alter_action_set_schema: (print) => print.spaced(["setSchemaKw", "schema"]),
30
+ alter_action_enable: (print) => print.spaced(["enableKw", "modeKw", "item"]),
31
+ alter_action_disable: (print) => print.spaced(["disableKw", "item"]),
32
+ alter_action_force: (print) => print.spaced(["forceKw", "item"]),
33
+ alter_action_no_force: (print) => print.spaced(["noForceKw", "item"]),
34
+ alter_action_cluster_on: (print) => print.spaced(["clusterOnKw", "index"]),
35
+ alter_action_set_without_cluster: (print) => print.spaced("setWithoutClusterKw"),
36
+ alter_action_set_without_oids: (print) => print.spaced("setWithoutOidsKw"),
37
+ alter_action_set_access_method: (print) => print.spaced(["setAccessMethodKw", "method"]),
38
+ alter_action_set_logged: (print) => print.spaced("setLoggedKw"),
39
+ alter_action_set_unlogged: (print) => print.spaced("setUnloggedKw"),
40
+ alter_action_inherit: (print) => print.spaced(["inheritKw", "table"]),
41
+ alter_action_no_inherit: (print) => print.spaced(["noInheritKw", "table"]),
42
+ alter_action_of_type: (print) => print.spaced(["ofKw", "typeName"]),
43
+ alter_action_not_of_type: (print) => print.spaced("notOfKw"),
44
+ alter_action_owner_to: (print) => print.spaced(["ownerToKw", "owner"]),
45
+ alter_action_replica_identity: (print) => print.spaced(["replicaIdentityKw", "identity"]),
46
+ replica_identity_using_index: (print) => print.spaced(["usingIndexKw", "index"]),
47
+ alter_action_set_postgresql_options: (print) => print.spaced(["setKw", "options"]),
48
+ alter_action_reset_postgresql_options: (print) => print.spaced(["resetKw", "options"]),
49
+ alter_action_depends_on_extension: (print) => print.spaced(["dependsOnExtensionKw", "extension"]),
50
+ alter_action_no_depends_on_extension: (print) => print.spaced(["noDependsOnExtensionKw", "extension"]),
51
+ alter_action_attach_partition: (print) => print.spaced(["attachPartitionKw", "index"]),
52
+ alter_action_add_enum_value: (print) => print.spaced(["addValueKw", "ifNotExistsKw", "value", "position"]),
53
+ alter_action_add_enum_value_position: (print) => print.spaced(["positionKw", "value"]),
54
+ alter_action_rename_enum_value: (print) => print.spaced(["renameValueKw", "oldValue", "toKw", "newValue"]),
55
+ alter_action_add_attribute: (print) => print.spaced([
56
+ "addAttributeKw",
57
+ "name",
58
+ "dataType",
59
+ "constraint",
60
+ "behaviorKw",
61
+ ]),
62
+ alter_action_drop_attribute: (print) => print.spaced(["dropAttributeKw", "ifExistsKw", "name", "behaviorKw"]),
63
+ alter_action_alter_attribute: (print) => print.spaced([
64
+ "alterAttributeKw",
65
+ "name",
66
+ "setDataTypeKw",
67
+ "dataType",
68
+ "constraint",
69
+ "behaviorKw",
70
+ ]),
71
+ alter_action_rename_attribute: (print) => print.spaced([
72
+ "renameAttributeKw",
73
+ "oldName",
74
+ "toKw",
75
+ "newName",
76
+ "behaviorKw",
77
+ ]),
139
78
  // ALTER COLUMN
140
- alter_action_alter_column: function (print) {
141
- return (0, print_utils_1.group)([
142
- print.spaced(["alterKw", "ifExistsKw", "column"]),
143
- print.dynamicLine(),
144
- print("action"),
145
- ]);
146
- },
147
- alter_action_set_default: function (print) { return print.spaced(["setDefaultKw", "expr"]); },
148
- alter_action_drop_default: function (print) { return print.spaced("dropDefaultKw"); },
149
- alter_action_set_not_null: function (print) { return print.spaced("setNotNullKw"); },
150
- alter_action_drop_not_null: function (print) { return print.spaced("dropNotNullKw"); },
151
- alter_action_set_data_type: function (print) {
152
- return print.spaced(["setDataTypeKw", "dataType", "clauses"]);
153
- },
154
- alter_action_set_statistics: function (print) {
155
- return print.spaced(["setStatisticsKw", "value"]);
156
- },
157
- alter_action_set_compression: function (print) {
158
- return print.spaced(["setCompressionKw", "method"]);
159
- },
160
- alter_action_set_storage: function (print) { return print.spaced(["setStorageKw", "typeKw"]); },
161
- alter_action_drop_expression: function (print) {
162
- return print.spaced(["dropExpressionKw", "ifExistsKw"]);
163
- },
164
- alter_action_drop_identity: function (print) {
165
- return print.spaced(["dropIdentityKw", "ifExistsKw"]);
166
- },
167
- alter_action_add_identity: function (print) {
168
- return print.spaced([
169
- "addGeneratedKw",
170
- "whenKw",
171
- "asIdentityKw",
172
- "sequenceOptions",
173
- ]);
174
- },
175
- alter_action_alter_identity: function (print) { return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.line, print("actions"))); },
176
- alter_action_set_generated: function (print) {
177
- return print.spaced(["setGeneratedKw", "whenKw"]);
178
- },
179
- alter_action_restart: function (print) {
180
- return print.spaced(["restartKw", "withKw", "value"]);
181
- },
182
- alter_action_set_sequence_option: function (print) {
183
- return print.spaced(["setKw", "option"]);
184
- },
185
- alter_action_with_role_options: function (print, node) {
186
- return node.withKw
187
- ? (0, print_utils_1.group)([print("withKw"), (0, print_utils_1.indent)([print_utils_1.line, (0, print_utils_1.join)(print_utils_1.line, print("options"))])])
188
- : // This works in tandem with the logic inside alter_role_stmt
189
- (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.line, print("options")));
190
- },
191
- alter_action_set_postgresql_option: function (print) {
192
- return print.spaced(["setKw", "name", "operator", "value"]);
193
- },
194
- alter_action_set_postgresql_option_from_current: function (print) {
195
- return print.spaced(["setKw", "name", "fromCurrentKw"]);
196
- },
197
- alter_action_reset_postgresql_option: function (print) {
198
- return print.spaced(["resetKw", "name"]);
199
- },
200
- alter_action_add_user: function (print) { return (0, print_utils_1.group)(print.spaced(["addUserKw", "users"])); },
201
- alter_action_drop_user: function (print) {
202
- return (0, print_utils_1.group)(print.spaced(["dropUserKw", "users"]));
203
- },
79
+ alter_action_alter_column: (print) => group([
80
+ print.spaced(["alterKw", "ifExistsKw", "column"]),
81
+ print.dynamicLine(),
82
+ print("action"),
83
+ ]),
84
+ alter_action_set_default: (print) => print.spaced(["setDefaultKw", "expr"]),
85
+ alter_action_drop_default: (print) => print.spaced("dropDefaultKw"),
86
+ alter_action_set_not_null: (print) => print.spaced("setNotNullKw"),
87
+ alter_action_drop_not_null: (print) => print.spaced("dropNotNullKw"),
88
+ alter_action_set_data_type: (print) => print.spaced(["setDataTypeKw", "dataType", "clauses"]),
89
+ alter_action_set_statistics: (print) => print.spaced(["setStatisticsKw", "value"]),
90
+ alter_action_set_compression: (print) => print.spaced(["setCompressionKw", "method"]),
91
+ alter_action_set_storage: (print) => print.spaced(["setStorageKw", "typeKw"]),
92
+ alter_action_drop_expression: (print) => print.spaced(["dropExpressionKw", "ifExistsKw"]),
93
+ alter_action_drop_identity: (print) => print.spaced(["dropIdentityKw", "ifExistsKw"]),
94
+ alter_action_add_identity: (print) => print.spaced([
95
+ "addGeneratedKw",
96
+ "whenKw",
97
+ "asIdentityKw",
98
+ "sequenceOptions",
99
+ ]),
100
+ alter_action_alter_identity: (print) => group(join(line, print("actions"))),
101
+ alter_action_set_generated: (print) => print.spaced(["setGeneratedKw", "whenKw"]),
102
+ alter_action_restart: (print) => print.spaced(["restartKw", "withKw", "value"]),
103
+ alter_action_set_sequence_option: (print) => print.spaced(["setKw", "option"]),
104
+ alter_action_with_role_options: (print, node) => node.withKw
105
+ ? group([print("withKw"), indent([line, join(line, print("options"))])])
106
+ : // This works in tandem with the logic inside alter_role_stmt
107
+ group(join(line, print("options"))),
108
+ alter_action_set_postgresql_option: (print) => print.spaced(["setKw", "name", "operator", "value"]),
109
+ alter_action_set_postgresql_option_from_current: (print) => print.spaced(["setKw", "name", "fromCurrentKw"]),
110
+ alter_action_reset_postgresql_option: (print) => print.spaced(["resetKw", "name"]),
111
+ alter_action_add_user: (print) => group(print.spaced(["addUserKw", "users"])),
112
+ alter_action_drop_user: (print) => group(print.spaced(["dropUserKw", "users"])),
204
113
  // ENABLE/DISABLE ..
205
- toggle_trigger: function (print) { return print.spaced(["triggerKw", "name"]); },
206
- toggle_rule: function (print) { return print.spaced(["ruleKw", "name"]); },
207
- toggle_row_level_security: function (print) { return print.spaced("rowLevelSecurityKw"); },
114
+ toggle_trigger: (print) => print.spaced(["triggerKw", "name"]),
115
+ toggle_rule: (print) => print.spaced(["ruleKw", "name"]),
116
+ toggle_row_level_security: (print) => print.spaced("rowLevelSecurityKw"),
208
117
  // SET DATA TYPE ...
209
- set_data_type_collate_clause: function (print) {
210
- return print.spaced(["collateKw", "collation"]);
211
- },
212
- set_data_type_using_clause: function (print) { return print.spaced(["usingKw", "expr"]); },
118
+ set_data_type_collate_clause: (print) => print.spaced(["collateKw", "collation"]),
119
+ set_data_type_using_clause: (print) => print.spaced(["usingKw", "expr"]),
213
120
  };
@@ -1,28 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.alterTableMap = void 0;
4
- var print_utils_1 = require("../print_utils");
5
- exports.alterTableMap = {
6
- alter_table_stmt: function (print) {
7
- return (0, print_utils_1.group)([
8
- print.spaced(["alterTableKw", "ifExistsKw", "table"]),
9
- print.dynamicLine(),
10
- print("actions"),
11
- ]);
12
- },
13
- alter_table_all_in_tablespace_stmt: function (print) {
14
- return (0, print_utils_1.group)([
15
- print.spaced([
16
- "alterTableKw",
17
- "allInTablespaceKw",
18
- "tablespace",
19
- "ownedBy",
20
- ]),
21
- print.dynamicLine(),
22
- print("action"),
23
- ]);
24
- },
25
- owned_by_clause: function (print) {
26
- return (0, print_utils_1.group)([print.spaced("ownedByKw"), (0, print_utils_1.indent)([print_utils_1.line, print("owners")])]);
27
- },
1
+ import { group, indent, line } from "../print_utils";
2
+ export const alterTableMap = {
3
+ alter_table_stmt: (print) => group([
4
+ print.spaced(["alterTableKw", "ifExistsKw", "table"]),
5
+ print.dynamicLine(),
6
+ print("actions"),
7
+ ]),
8
+ alter_table_all_in_tablespace_stmt: (print) => group([
9
+ print.spaced([
10
+ "alterTableKw",
11
+ "allInTablespaceKw",
12
+ "tablespace",
13
+ "ownedBy",
14
+ ]),
15
+ print.dynamicLine(),
16
+ print("action"),
17
+ ]),
18
+ owned_by_clause: (print) => group([print.spaced("ownedByKw"), indent([line, print("owners")])]),
28
19
  };
@@ -1,9 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.analyzeMap = void 0;
4
- var print_utils_1 = require("../print_utils");
5
- exports.analyzeMap = {
6
- analyze_stmt: function (print) {
7
- return (0, print_utils_1.group)(print.spaced(["analyzeKw", "tableKw", "tables"]));
8
- },
1
+ import { group } from "../print_utils";
2
+ export const analyzeMap = {
3
+ analyze_stmt: (print) => group(print.spaced(["analyzeKw", "tableKw", "tables"])),
9
4
  };
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.baseMap = void 0;
4
- var node_utils_1 = require("../node_utils");
5
- exports.baseMap = {
1
+ import { isDataType } from "../node_utils";
2
+ export const baseMap = {
6
3
  /** cst-ignore: name */
7
- keyword: function (print, node, path, options) {
8
- var keywordCase = (0, node_utils_1.isDataType)(path.ancestors)
4
+ keyword: (print, node, path, options) => {
5
+ const keywordCase = isDataType(path.ancestors)
9
6
  ? options.sqlTypeCase
10
7
  : options.sqlKeywordCase;
11
8
  switch (keywordCase) {
@@ -17,6 +14,6 @@ exports.baseMap = {
17
14
  return path.node.text.toLowerCase();
18
15
  }
19
16
  },
20
- all_columns: function () { return "*"; },
21
- empty: function () { return []; },
17
+ all_columns: () => "*",
18
+ empty: () => [],
22
19
  };