pgsql-deparser 14.0.1 → 14.1.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.
@@ -6,7 +6,7 @@ export class SqlFormatter {
6
6
  newlineChar;
7
7
  tabChar;
8
8
  prettyMode;
9
- constructor(newlineChar = '\n', tabChar = ' ', prettyMode = false) {
9
+ constructor(newlineChar = '\n', tabChar = ' ', prettyMode = true) {
10
10
  this.newlineChar = newlineChar;
11
11
  this.tabChar = tabChar;
12
12
  this.prettyMode = prettyMode;
@@ -2,6 +2,93 @@
2
2
  * Auto-generated file with types stripped for better tree-shaking
3
3
  * DO NOT EDIT - Generated by strip-deparser-types.ts
4
4
  */
5
+ import { SqlFormatter } from '../utils/sql-formatter';
6
+ export class DeparserContext {
7
+ indentLevel;
8
+ prettyMode;
9
+ isStringLiteral;
10
+ parentNodeTypes;
11
+ formatter;
12
+ select;
13
+ from;
14
+ group;
15
+ sort;
16
+ insertColumns;
17
+ update;
18
+ bool;
19
+ isColumnConstraint;
20
+ isDomainConstraint;
21
+ alterColumnOptions;
22
+ alterTableOptions;
23
+ isEnumValue;
24
+ objtype;
25
+ subtype;
26
+ constructor({ indentLevel = 0, prettyMode = true, isStringLiteral, parentNodeTypes = [], formatter, select, from, group, sort, insertColumns, update, bool, isColumnConstraint, isDomainConstraint, alterColumnOptions, alterTableOptions, isEnumValue, objtype, subtype, ...rest } = {}) {
27
+ this.indentLevel = indentLevel;
28
+ this.prettyMode = prettyMode;
29
+ this.isStringLiteral = isStringLiteral;
30
+ this.parentNodeTypes = parentNodeTypes;
31
+ this.formatter = formatter || new SqlFormatter('\n', ' ', prettyMode);
32
+ this.select = select;
33
+ this.from = from;
34
+ this.group = group;
35
+ this.sort = sort;
36
+ this.insertColumns = insertColumns;
37
+ this.update = update;
38
+ this.bool = bool;
39
+ this.isColumnConstraint = isColumnConstraint;
40
+ this.isDomainConstraint = isDomainConstraint;
41
+ this.alterColumnOptions = alterColumnOptions;
42
+ this.alterTableOptions = alterTableOptions;
43
+ this.isEnumValue = isEnumValue;
44
+ this.objtype = objtype;
45
+ this.subtype = subtype;
46
+ Object.assign(this, rest);
47
+ }
48
+ spawn(nodeType, overrides = {}) {
49
+ return new DeparserContext({
50
+ indentLevel: this.indentLevel,
51
+ prettyMode: this.prettyMode,
52
+ isStringLiteral: this.isStringLiteral,
53
+ parentNodeTypes: [...this.parentNodeTypes, nodeType],
54
+ formatter: this.formatter,
55
+ select: this.select,
56
+ from: this.from,
57
+ group: this.group,
58
+ sort: this.sort,
59
+ insertColumns: this.insertColumns,
60
+ update: this.update,
61
+ bool: this.bool,
62
+ isColumnConstraint: this.isColumnConstraint,
63
+ isDomainConstraint: this.isDomainConstraint,
64
+ alterColumnOptions: this.alterColumnOptions,
65
+ alterTableOptions: this.alterTableOptions,
66
+ isEnumValue: this.isEnumValue,
67
+ objtype: this.objtype,
68
+ subtype: this.subtype,
69
+ ...overrides,
70
+ });
71
+ }
72
+ indent(text, count) {
73
+ if (!this.prettyMode) {
74
+ return text;
75
+ }
76
+ const indentCount = count !== undefined ? count : this.indentLevel + 1;
77
+ return this.formatter.indent(text, indentCount);
78
+ }
79
+ newline() {
80
+ return this.formatter.newline();
81
+ }
82
+ parens(content) {
83
+ return this.formatter.parens(content);
84
+ }
85
+ format(parts, separator) {
86
+ return this.formatter.format(parts, separator);
87
+ }
88
+ isPretty() {
89
+ return this.formatter.isPretty();
90
+ }
91
+ }
5
92
  export class BaseVisitor {
6
93
  getNodeType(node) {
7
94
  return Object.keys(node)[0];
package/esm/v14-to-v15.js CHANGED
@@ -659,6 +659,9 @@ export class V14ToV15Transformer {
659
659
  if (node.name !== undefined) {
660
660
  result.name = node.name;
661
661
  }
662
+ if (node.num !== undefined) {
663
+ result.num = node.num;
664
+ }
662
665
  if (node.newowner !== undefined) {
663
666
  result.newowner = this.transform(node.newowner, context);
664
667
  }
package/esm/v15-to-v16.js CHANGED
@@ -332,6 +332,18 @@ export class V15ToV16Transformer {
332
332
  { String: { sval: 'json_object' } }
333
333
  ];
334
334
  }
335
+ else if (node.funcname.length === 2 &&
336
+ node.funcname[0]?.String?.sval === 'pg_catalog' &&
337
+ node.funcname[1]?.String?.sval === 'system_user' &&
338
+ node.funcformat === 'COERCE_SQL_SYNTAX') {
339
+ return {
340
+ ColumnRef: {
341
+ fields: [
342
+ { String: { sval: 'system_user' } }
343
+ ]
344
+ }
345
+ };
346
+ }
335
347
  else {
336
348
  result.funcname = Array.isArray(node.funcname)
337
349
  ? node.funcname.map((item) => this.transform(item, context))
@@ -437,6 +449,20 @@ export class V15ToV16Transformer {
437
449
  return { A_Const: result };
438
450
  }
439
451
  ColumnRef(node, context) {
452
+ if (node.fields && Array.isArray(node.fields) && node.fields.length === 1) {
453
+ const field = node.fields[0];
454
+ if (field?.String?.sval === 'system_user') {
455
+ return {
456
+ FuncCall: {
457
+ funcname: [
458
+ { String: { sval: 'pg_catalog' } },
459
+ { String: { sval: 'system_user' } }
460
+ ],
461
+ funcformat: 'COERCE_SQL_SYNTAX'
462
+ }
463
+ };
464
+ }
465
+ }
440
466
  const result = {};
441
467
  if (node.fields !== undefined) {
442
468
  result.fields = Array.isArray(node.fields)
@@ -499,6 +525,30 @@ export class V15ToV16Transformer {
499
525
  return { Alias: result };
500
526
  }
501
527
  RangeVar(node, context) {
528
+ if (node.relname === 'system_user' && node.inh === true && node.relpersistence === 'p') {
529
+ return {
530
+ RangeFunction: {
531
+ functions: [
532
+ {
533
+ List: {
534
+ items: [
535
+ {
536
+ FuncCall: {
537
+ funcname: [
538
+ { String: { sval: 'pg_catalog' } },
539
+ { String: { sval: 'system_user' } }
540
+ ],
541
+ funcformat: 'COERCE_SQL_SYNTAX'
542
+ }
543
+ },
544
+ {}
545
+ ]
546
+ }
547
+ }
548
+ ]
549
+ }
550
+ };
551
+ }
502
552
  const result = {};
503
553
  if (node.catalogname !== undefined) {
504
554
  result.catalogname = node.catalogname;
@@ -706,7 +756,13 @@ export class V15ToV16Transformer {
706
756
  const result = {};
707
757
  if (node.items !== undefined) {
708
758
  result.items = Array.isArray(node.items)
709
- ? node.items.map((item) => this.transform(item, context))
759
+ ? node.items.map((item) => {
760
+ const transformed = this.transform(item, context);
761
+ if (transformed === null) {
762
+ return {};
763
+ }
764
+ return transformed;
765
+ })
710
766
  : this.transform(node.items, context);
711
767
  }
712
768
  return { List: result };
@@ -1633,6 +1689,9 @@ export class V15ToV16Transformer {
1633
1689
  if (node.unique !== undefined) {
1634
1690
  result.unique = node.unique;
1635
1691
  }
1692
+ if (node.nulls_not_distinct !== undefined) {
1693
+ result.nulls_not_distinct = node.nulls_not_distinct;
1694
+ }
1636
1695
  if (node.primary !== undefined) {
1637
1696
  result.primary = node.primary;
1638
1697
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "author": "Dan Lynch <pyramation@gmail.com>",
3
- "homepage": "https://github.com/launchql/pgsql-parser",
2
+ "author": "Constructive <developers@constructive.io>",
3
+ "homepage": "https://github.com/constructive-io/pgsql-parser",
4
4
  "license": "MIT",
5
5
  "main": "index.js",
6
6
  "module": "esm/index.js",
@@ -18,10 +18,10 @@
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "https://github.com/launchql/pgsql-parser"
21
+ "url": "https://github.com/constructive-io/pgsql-parser"
22
22
  },
23
23
  "bugs": {
24
- "url": "https://github.com/launchql/pgsql-parser/issues"
24
+ "url": "https://github.com/constructive-io/pgsql-parser/issues"
25
25
  },
26
26
  "keywords": [
27
27
  "sql",
@@ -34,7 +34,7 @@
34
34
  "database"
35
35
  ],
36
36
  "name": "pgsql-deparser",
37
- "version": "14.0.1",
37
+ "version": "14.1.1",
38
38
  "dependencies": {
39
39
  "@pgsql/types": "^14.1.1"
40
40
  }
package/v14-to-v15.js CHANGED
@@ -662,6 +662,9 @@ class V14ToV15Transformer {
662
662
  if (node.name !== undefined) {
663
663
  result.name = node.name;
664
664
  }
665
+ if (node.num !== undefined) {
666
+ result.num = node.num;
667
+ }
665
668
  if (node.newowner !== undefined) {
666
669
  result.newowner = this.transform(node.newowner, context);
667
670
  }
package/v15-to-v16.d.ts CHANGED
@@ -41,6 +41,8 @@ export declare class V15ToV16Transformer {
41
41
  };
42
42
  FuncCall(node: any, context: any): {
43
43
  FuncCall: any;
44
+ } | {
45
+ ColumnRef: any;
44
46
  };
45
47
  FuncExpr(node: any, context: any): {
46
48
  FuncExpr: any;
@@ -50,6 +52,8 @@ export declare class V15ToV16Transformer {
50
52
  };
51
53
  ColumnRef(node: any, context: any): {
52
54
  ColumnRef: any;
55
+ } | {
56
+ FuncCall: any;
53
57
  };
54
58
  TypeName(node: any, context: any): {
55
59
  TypeName: any;
@@ -59,6 +63,8 @@ export declare class V15ToV16Transformer {
59
63
  };
60
64
  RangeVar(node: any, context: any): {
61
65
  RangeVar: any;
66
+ } | {
67
+ RangeFunction: any;
62
68
  };
63
69
  A_ArrayExpr(node: any, context: any): {
64
70
  A_ArrayExpr: any;
package/v15-to-v16.js CHANGED
@@ -335,6 +335,18 @@ class V15ToV16Transformer {
335
335
  { String: { sval: 'json_object' } }
336
336
  ];
337
337
  }
338
+ else if (node.funcname.length === 2 &&
339
+ node.funcname[0]?.String?.sval === 'pg_catalog' &&
340
+ node.funcname[1]?.String?.sval === 'system_user' &&
341
+ node.funcformat === 'COERCE_SQL_SYNTAX') {
342
+ return {
343
+ ColumnRef: {
344
+ fields: [
345
+ { String: { sval: 'system_user' } }
346
+ ]
347
+ }
348
+ };
349
+ }
338
350
  else {
339
351
  result.funcname = Array.isArray(node.funcname)
340
352
  ? node.funcname.map((item) => this.transform(item, context))
@@ -440,6 +452,20 @@ class V15ToV16Transformer {
440
452
  return { A_Const: result };
441
453
  }
442
454
  ColumnRef(node, context) {
455
+ if (node.fields && Array.isArray(node.fields) && node.fields.length === 1) {
456
+ const field = node.fields[0];
457
+ if (field?.String?.sval === 'system_user') {
458
+ return {
459
+ FuncCall: {
460
+ funcname: [
461
+ { String: { sval: 'pg_catalog' } },
462
+ { String: { sval: 'system_user' } }
463
+ ],
464
+ funcformat: 'COERCE_SQL_SYNTAX'
465
+ }
466
+ };
467
+ }
468
+ }
443
469
  const result = {};
444
470
  if (node.fields !== undefined) {
445
471
  result.fields = Array.isArray(node.fields)
@@ -502,6 +528,30 @@ class V15ToV16Transformer {
502
528
  return { Alias: result };
503
529
  }
504
530
  RangeVar(node, context) {
531
+ if (node.relname === 'system_user' && node.inh === true && node.relpersistence === 'p') {
532
+ return {
533
+ RangeFunction: {
534
+ functions: [
535
+ {
536
+ List: {
537
+ items: [
538
+ {
539
+ FuncCall: {
540
+ funcname: [
541
+ { String: { sval: 'pg_catalog' } },
542
+ { String: { sval: 'system_user' } }
543
+ ],
544
+ funcformat: 'COERCE_SQL_SYNTAX'
545
+ }
546
+ },
547
+ {}
548
+ ]
549
+ }
550
+ }
551
+ ]
552
+ }
553
+ };
554
+ }
505
555
  const result = {};
506
556
  if (node.catalogname !== undefined) {
507
557
  result.catalogname = node.catalogname;
@@ -709,7 +759,13 @@ class V15ToV16Transformer {
709
759
  const result = {};
710
760
  if (node.items !== undefined) {
711
761
  result.items = Array.isArray(node.items)
712
- ? node.items.map((item) => this.transform(item, context))
762
+ ? node.items.map((item) => {
763
+ const transformed = this.transform(item, context);
764
+ if (transformed === null) {
765
+ return {};
766
+ }
767
+ return transformed;
768
+ })
713
769
  : this.transform(node.items, context);
714
770
  }
715
771
  return { List: result };
@@ -1636,6 +1692,9 @@ class V15ToV16Transformer {
1636
1692
  if (node.unique !== undefined) {
1637
1693
  result.unique = node.unique;
1638
1694
  }
1695
+ if (node.nulls_not_distinct !== undefined) {
1696
+ result.nulls_not_distinct = node.nulls_not_distinct;
1697
+ }
1639
1698
  if (node.primary !== undefined) {
1640
1699
  result.primary = node.primary;
1641
1700
  }