pgsql-deparser 13.3.15 → 13.4.0

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/module/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  import Deparser from './deparser';
2
- import { preparse } from './preparse';
3
2
  const deparse = Deparser.deparse;
4
- export { deparse, Deparser, preparse };
3
+ export { deparse, Deparser };
@@ -1,36 +1,34 @@
1
1
  /* eslint-disable no-restricted-syntax */
2
+
2
3
  export const cleanLines = sql => {
3
4
  return sql.split('\n').map(l => l.trim()).filter(a => a).join('\n');
4
5
  };
5
6
  export const transform = (obj, props) => {
6
- let copy = null; // Handle the 3 simple types, and null or undefined
7
-
7
+ let copy = null;
8
+ // Handle the 3 simple types, and null or undefined
8
9
  if (obj == null || typeof obj !== 'object') {
9
10
  return obj;
10
- } // Handle Date
11
-
11
+ }
12
12
 
13
+ // Handle Date
13
14
  if (obj instanceof Date) {
14
15
  copy = new Date();
15
16
  copy.setTime(obj.getTime());
16
17
  return copy;
17
- } // Handle Array
18
-
18
+ }
19
19
 
20
+ // Handle Array
20
21
  if (obj instanceof Array) {
21
22
  copy = [];
22
-
23
23
  for (let i = 0, len = obj.length; i < len; i++) {
24
24
  copy[i] = transform(obj[i], props);
25
25
  }
26
-
27
26
  return copy;
28
- } // Handle Object
29
-
27
+ }
30
28
 
29
+ // Handle Object
31
30
  if (obj instanceof Object || typeof obj === 'object') {
32
31
  copy = {};
33
-
34
32
  for (const attr in obj) {
35
33
  if (obj.hasOwnProperty(attr)) {
36
34
  if (props.hasOwnProperty(attr)) {
@@ -48,15 +46,11 @@ export const transform = (obj, props) => {
48
46
  copy[attr] = transform(obj[attr], props);
49
47
  }
50
48
  }
51
-
52
49
  return copy;
53
50
  }
54
-
55
51
  throw new Error("Unable to copy obj! Its type isn't supported.");
56
52
  };
57
-
58
53
  const noop = () => undefined;
59
-
60
54
  export const cleanTree = tree => {
61
55
  return transform(tree, {
62
56
  stmt_len: noop,
@@ -74,7 +68,6 @@ export const cleanTree = tree => {
74
68
  // do stmt
75
69
  obj.arg.String.str = obj.arg.String.str.trim();
76
70
  }
77
-
78
71
  return cleanTree(obj);
79
72
  } else {
80
73
  return cleanTree(obj);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-deparser",
3
- "version": "13.3.15",
3
+ "version": "13.4.0",
4
4
  "description": "PostgreSQL AST Deparser",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/pyramation/pgsql-parser",
@@ -65,15 +65,14 @@
65
65
  "eslint-plugin-prettier": "^3.1.2",
66
66
  "glob": "7.1.6",
67
67
  "jest": "^25.1.0",
68
- "pgsql-parser": "^13.4.1",
68
+ "pgsql-parser": "^13.5.0",
69
69
  "prettier": "^2.1.2",
70
70
  "regenerator-runtime": "^0.13.2"
71
71
  },
72
72
  "dependencies": {
73
73
  "@babel/runtime": "^7.11.2",
74
74
  "dotty": "^0.1.0",
75
- "lodash": "^4.17.20",
76
75
  "pgsql-enums": "^13.1.3"
77
76
  },
78
- "gitHead": "f2353fb8a98b0ac1d637c57d2c8be79f5495b446"
77
+ "gitHead": "3d78dc66d800eb8cdf76851337f27b972160fb41"
79
78
  }
package/main/preparse.js DELETED
@@ -1,142 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.transformArrays = exports.preparse = void 0;
9
-
10
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
-
12
- /* eslint-disable no-restricted-syntax */
13
- // import { getEnum, nodes, toStr, toInt } from 'pgsql-enums';
14
- // NOTE: this is used to get rid of List.items... and use Arrays
15
- var preparse = function preparse(tree) {
16
- return transformArrays(tree);
17
- }; // export const transform = (obj, context) => {
18
- // let copy = null;
19
- // // Handle null or undefined
20
- // if (obj == null) {
21
- // return obj;
22
- // }
23
- // // Handle the 3 simple types
24
- // if (typeof obj !== 'object') {
25
- // // if (context.enum) {
26
- // // return toInt[context.enum][obj];
27
- // // return obj;
28
- // // } else {
29
- // return obj;
30
- // // }
31
- // }
32
- // // Handle Date
33
- // if (obj instanceof Date) {
34
- // copy = new Date();
35
- // copy.setTime(obj.getTime());
36
- // return copy;
37
- // }
38
- // // Handle Array
39
- // if (obj instanceof Array) {
40
- // copy = [];
41
- // for (let i = 0, len = obj.length; i < len; i++) {
42
- // copy[i] = transform(obj[i], context);
43
- // }
44
- // return copy;
45
- // }
46
- // // Handle Object
47
- // if (obj instanceof Object || typeof obj === 'object') {
48
- // copy = {};
49
- // for (const attr in obj) {
50
- // // IF IS AST NODE
51
- // if (nodes.hasOwnProperty(attr)) {
52
- // context = { node: attr };
53
- // copy[attr] = transform(obj[attr], context);
54
- // } else {
55
- // // MUST BE A FIELD
56
- // if (context && context.node) {
57
- // const attrSchema = nodes[context.node][attr];
58
- // if (attrSchema?.enum) {
59
- // copy[attr] = transform(obj[attr], {
60
- // enum: attrSchema.type
61
- // });
62
- // } else if (nodes.hasOwnProperty(attrSchema?.type)) {
63
- // if (attrSchema.type === 'Expr') {
64
- // copy[attr] = transform(obj[attr], {
65
- // node: attrSchema.type
66
- // });
67
- // } else {
68
- // copy[attr] = {
69
- // [attrSchema.type]: transform(obj[attr], {
70
- // node: attrSchema.type
71
- // })
72
- // };
73
- // }
74
- // } else {
75
- // copy[attr] = transform(obj[attr], context);
76
- // }
77
- // } else {
78
- // copy[attr] = transform(obj[attr], context);
79
- // }
80
- // }
81
- // }
82
- // return copy;
83
- // }
84
- // throw new Error("Unable to copy obj! Its type isn't supported.");
85
- // };
86
-
87
-
88
- exports.preparse = preparse;
89
-
90
- var transformArrays = function transformArrays(obj, context) {
91
- var copy = null; // Handle null or undefined
92
-
93
- if (obj == null) {
94
- return obj;
95
- } // Handle the 3 simple types
96
-
97
-
98
- if ((0, _typeof2["default"])(obj) !== 'object') {
99
- return obj;
100
- } // Handle Date
101
-
102
-
103
- if (obj instanceof Date) {
104
- copy = new Date();
105
- copy.setTime(obj.getTime());
106
- return copy;
107
- } // Handle Array
108
-
109
-
110
- if (obj instanceof Array) {
111
- copy = [];
112
-
113
- for (var i = 0, len = obj.length; i < len; i++) {
114
- copy[i] = transformArrays(obj[i], context);
115
- }
116
-
117
- return copy;
118
- } // Handle Object
119
-
120
-
121
- if (obj instanceof Object || (0, _typeof2["default"])(obj) === 'object') {
122
- copy = {};
123
-
124
- for (var attr in obj) {
125
- if (attr === 'List') {
126
- copy = [];
127
-
128
- for (var _i = 0, _len = obj[attr].items.length; _i < _len; _i++) {
129
- copy[_i] = transformArrays(obj[attr].items[_i], context);
130
- }
131
- } else {
132
- copy[attr] = transformArrays(obj[attr], context);
133
- }
134
- }
135
-
136
- return copy;
137
- }
138
-
139
- throw new Error("Unable to copy obj! Its type isn't supported.");
140
- };
141
-
142
- exports.transformArrays = transformArrays;
@@ -1,124 +0,0 @@
1
- /* eslint-disable no-restricted-syntax */
2
- // import { getEnum, nodes, toStr, toInt } from 'pgsql-enums';
3
- // NOTE: this is used to get rid of List.items... and use Arrays
4
- export const preparse = tree => transformArrays(tree); // export const transform = (obj, context) => {
5
- // let copy = null;
6
- // // Handle null or undefined
7
- // if (obj == null) {
8
- // return obj;
9
- // }
10
- // // Handle the 3 simple types
11
- // if (typeof obj !== 'object') {
12
- // // if (context.enum) {
13
- // // return toInt[context.enum][obj];
14
- // // return obj;
15
- // // } else {
16
- // return obj;
17
- // // }
18
- // }
19
- // // Handle Date
20
- // if (obj instanceof Date) {
21
- // copy = new Date();
22
- // copy.setTime(obj.getTime());
23
- // return copy;
24
- // }
25
- // // Handle Array
26
- // if (obj instanceof Array) {
27
- // copy = [];
28
- // for (let i = 0, len = obj.length; i < len; i++) {
29
- // copy[i] = transform(obj[i], context);
30
- // }
31
- // return copy;
32
- // }
33
- // // Handle Object
34
- // if (obj instanceof Object || typeof obj === 'object') {
35
- // copy = {};
36
- // for (const attr in obj) {
37
- // // IF IS AST NODE
38
- // if (nodes.hasOwnProperty(attr)) {
39
- // context = { node: attr };
40
- // copy[attr] = transform(obj[attr], context);
41
- // } else {
42
- // // MUST BE A FIELD
43
- // if (context && context.node) {
44
- // const attrSchema = nodes[context.node][attr];
45
- // if (attrSchema?.enum) {
46
- // copy[attr] = transform(obj[attr], {
47
- // enum: attrSchema.type
48
- // });
49
- // } else if (nodes.hasOwnProperty(attrSchema?.type)) {
50
- // if (attrSchema.type === 'Expr') {
51
- // copy[attr] = transform(obj[attr], {
52
- // node: attrSchema.type
53
- // });
54
- // } else {
55
- // copy[attr] = {
56
- // [attrSchema.type]: transform(obj[attr], {
57
- // node: attrSchema.type
58
- // })
59
- // };
60
- // }
61
- // } else {
62
- // copy[attr] = transform(obj[attr], context);
63
- // }
64
- // } else {
65
- // copy[attr] = transform(obj[attr], context);
66
- // }
67
- // }
68
- // }
69
- // return copy;
70
- // }
71
- // throw new Error("Unable to copy obj! Its type isn't supported.");
72
- // };
73
-
74
- export const transformArrays = (obj, context) => {
75
- let copy = null; // Handle null or undefined
76
-
77
- if (obj == null) {
78
- return obj;
79
- } // Handle the 3 simple types
80
-
81
-
82
- if (typeof obj !== 'object') {
83
- return obj;
84
- } // Handle Date
85
-
86
-
87
- if (obj instanceof Date) {
88
- copy = new Date();
89
- copy.setTime(obj.getTime());
90
- return copy;
91
- } // Handle Array
92
-
93
-
94
- if (obj instanceof Array) {
95
- copy = [];
96
-
97
- for (let i = 0, len = obj.length; i < len; i++) {
98
- copy[i] = transformArrays(obj[i], context);
99
- }
100
-
101
- return copy;
102
- } // Handle Object
103
-
104
-
105
- if (obj instanceof Object || typeof obj === 'object') {
106
- copy = {};
107
-
108
- for (const attr in obj) {
109
- if (attr === 'List') {
110
- copy = [];
111
-
112
- for (let i = 0, len = obj[attr].items.length; i < len; i++) {
113
- copy[i] = transformArrays(obj[attr].items[i], context);
114
- }
115
- } else {
116
- copy[attr] = transformArrays(obj[attr], context);
117
- }
118
- }
119
-
120
- return copy;
121
- }
122
-
123
- throw new Error("Unable to copy obj! Its type isn't supported.");
124
- };