pgsql-parser 17.7.5 → 17.7.6
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/esm/index.js +1 -1
- package/index.d.ts +1 -1
- package/package.json +4 -3
- package/esm/utils/index.js +0 -90
- package/utils/index.d.ts +0 -4
- package/utils/index.js +0 -97
package/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { parse as parse, parseSync as parseSync, loadModule as loadModule } from 'libpg-query';
|
|
2
|
-
export { deparse
|
|
2
|
+
export { deparse, deparseSync } from 'pgsql-deparser';
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { parse as parse, parseSync as parseSync, loadModule as loadModule } from 'libpg-query';
|
|
2
|
-
export { deparse
|
|
2
|
+
export { deparse, deparseSync } from 'pgsql-deparser';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pgsql-parser",
|
|
3
|
-
"version": "17.7.
|
|
3
|
+
"version": "17.7.6",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "The real PostgreSQL query parser",
|
|
6
6
|
"main": "index.js",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"lint": "eslint . --fix",
|
|
29
29
|
"test": "jest",
|
|
30
30
|
"test:watch": "jest --watch",
|
|
31
|
+
"prepare-versions": "ts-node scripts/prepare-versions.ts",
|
|
31
32
|
"test:ast": "ts-node scripts/test-ast.ts"
|
|
32
33
|
},
|
|
33
34
|
"keywords": [
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
"dependencies": {
|
|
43
44
|
"@pgsql/types": "^17.6.1",
|
|
44
45
|
"libpg-query": "17.5.5",
|
|
45
|
-
"pgsql-deparser": "^17.8.
|
|
46
|
+
"pgsql-deparser": "^17.8.4"
|
|
46
47
|
},
|
|
47
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "db3e424332bcb223c34a1caca3f37fb6fc9a1964"
|
|
48
49
|
}
|
package/esm/utils/index.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-restricted-syntax */
|
|
2
|
-
export const cleanLines = (sql) => {
|
|
3
|
-
return sql
|
|
4
|
-
.split('\n')
|
|
5
|
-
.map((l) => l.trim())
|
|
6
|
-
.filter((a) => a)
|
|
7
|
-
.join('\n');
|
|
8
|
-
};
|
|
9
|
-
export const transform = (obj, props) => {
|
|
10
|
-
let copy = null;
|
|
11
|
-
// Handle the 3 simple types, and null or undefined
|
|
12
|
-
if (obj == null || typeof obj !== 'object') {
|
|
13
|
-
return obj;
|
|
14
|
-
}
|
|
15
|
-
// Handle Date
|
|
16
|
-
if (obj instanceof Date) {
|
|
17
|
-
copy = new Date();
|
|
18
|
-
copy.setTime(obj.getTime());
|
|
19
|
-
return copy;
|
|
20
|
-
}
|
|
21
|
-
// Handle Array
|
|
22
|
-
if (obj instanceof Array) {
|
|
23
|
-
copy = [];
|
|
24
|
-
for (let i = 0, len = obj.length; i < len; i++) {
|
|
25
|
-
copy[i] = transform(obj[i], props);
|
|
26
|
-
}
|
|
27
|
-
return copy;
|
|
28
|
-
}
|
|
29
|
-
// Handle Object
|
|
30
|
-
if (obj instanceof Object || typeof obj === 'object') {
|
|
31
|
-
copy = {};
|
|
32
|
-
for (const attr in obj) {
|
|
33
|
-
if (obj.hasOwnProperty(attr)) {
|
|
34
|
-
if (props.hasOwnProperty(attr)) {
|
|
35
|
-
if (typeof props[attr] === 'function') {
|
|
36
|
-
copy[attr] = props[attr](obj[attr]);
|
|
37
|
-
}
|
|
38
|
-
else if (props[attr].hasOwnProperty(obj[attr])) {
|
|
39
|
-
copy[attr] = props[attr][obj[attr]];
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
copy[attr] = transform(obj[attr], props);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
copy[attr] = transform(obj[attr], props);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
copy[attr] = transform(obj[attr], props);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return copy;
|
|
54
|
-
}
|
|
55
|
-
throw new Error("Unable to copy obj! Its type isn't supported.");
|
|
56
|
-
};
|
|
57
|
-
const noop = () => undefined;
|
|
58
|
-
export const cleanTree = (tree) => {
|
|
59
|
-
return transform(tree, {
|
|
60
|
-
stmt_len: noop,
|
|
61
|
-
stmt_location: noop,
|
|
62
|
-
location: noop,
|
|
63
|
-
DefElem: (obj) => {
|
|
64
|
-
if (obj.defname === 'as') {
|
|
65
|
-
if (Array.isArray(obj.arg) && obj.arg.length) {
|
|
66
|
-
// function
|
|
67
|
-
obj.arg[0].String.str = obj.arg[0].String.str.trim();
|
|
68
|
-
}
|
|
69
|
-
else if (obj.arg.List && obj.arg.List.items) {
|
|
70
|
-
// function
|
|
71
|
-
obj.arg.List.items[0].String.str = obj.arg.List.items[0].String.str.trim();
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// do stmt
|
|
75
|
-
obj.arg.String.str = obj.arg.String.str.trim();
|
|
76
|
-
}
|
|
77
|
-
return cleanTree(obj);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
return cleanTree(obj);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
export const cleanTreeWithStmt = (tree) => {
|
|
86
|
-
return transform(tree, {
|
|
87
|
-
stmt_location: noop,
|
|
88
|
-
location: noop
|
|
89
|
-
});
|
|
90
|
-
};
|
package/utils/index.d.ts
DELETED
package/utils/index.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable no-restricted-syntax */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.cleanTreeWithStmt = exports.cleanTree = exports.transform = exports.cleanLines = void 0;
|
|
5
|
-
const cleanLines = (sql) => {
|
|
6
|
-
return sql
|
|
7
|
-
.split('\n')
|
|
8
|
-
.map((l) => l.trim())
|
|
9
|
-
.filter((a) => a)
|
|
10
|
-
.join('\n');
|
|
11
|
-
};
|
|
12
|
-
exports.cleanLines = cleanLines;
|
|
13
|
-
const transform = (obj, props) => {
|
|
14
|
-
let copy = null;
|
|
15
|
-
// Handle the 3 simple types, and null or undefined
|
|
16
|
-
if (obj == null || typeof obj !== 'object') {
|
|
17
|
-
return obj;
|
|
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] = (0, exports.transform)(obj[i], props);
|
|
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 (obj.hasOwnProperty(attr)) {
|
|
38
|
-
if (props.hasOwnProperty(attr)) {
|
|
39
|
-
if (typeof props[attr] === 'function') {
|
|
40
|
-
copy[attr] = props[attr](obj[attr]);
|
|
41
|
-
}
|
|
42
|
-
else if (props[attr].hasOwnProperty(obj[attr])) {
|
|
43
|
-
copy[attr] = props[attr][obj[attr]];
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
copy[attr] = (0, exports.transform)(obj[attr], props);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
copy[attr] = (0, exports.transform)(obj[attr], props);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
copy[attr] = (0, exports.transform)(obj[attr], props);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return copy;
|
|
58
|
-
}
|
|
59
|
-
throw new Error("Unable to copy obj! Its type isn't supported.");
|
|
60
|
-
};
|
|
61
|
-
exports.transform = transform;
|
|
62
|
-
const noop = () => undefined;
|
|
63
|
-
const cleanTree = (tree) => {
|
|
64
|
-
return (0, exports.transform)(tree, {
|
|
65
|
-
stmt_len: noop,
|
|
66
|
-
stmt_location: noop,
|
|
67
|
-
location: noop,
|
|
68
|
-
DefElem: (obj) => {
|
|
69
|
-
if (obj.defname === 'as') {
|
|
70
|
-
if (Array.isArray(obj.arg) && obj.arg.length) {
|
|
71
|
-
// function
|
|
72
|
-
obj.arg[0].String.str = obj.arg[0].String.str.trim();
|
|
73
|
-
}
|
|
74
|
-
else if (obj.arg.List && obj.arg.List.items) {
|
|
75
|
-
// function
|
|
76
|
-
obj.arg.List.items[0].String.str = obj.arg.List.items[0].String.str.trim();
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
// do stmt
|
|
80
|
-
obj.arg.String.str = obj.arg.String.str.trim();
|
|
81
|
-
}
|
|
82
|
-
return (0, exports.cleanTree)(obj);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
return (0, exports.cleanTree)(obj);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
exports.cleanTree = cleanTree;
|
|
91
|
-
const cleanTreeWithStmt = (tree) => {
|
|
92
|
-
return (0, exports.transform)(tree, {
|
|
93
|
-
stmt_location: noop,
|
|
94
|
-
location: noop
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
exports.cleanTreeWithStmt = cleanTreeWithStmt;
|