pgsql-deparser 16.1.0 → 16.2.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/README.md +23 -16
- package/deparser/deparser.d.ts +37 -28
- package/deparser/deparser.js +1413 -948
- package/deparser/index.d.ts +3 -1
- package/deparser/index.js +5 -1
- package/deparser/utils/sql-formatter.d.ts +8 -0
- package/deparser/utils/sql-formatter.js +104 -1
- package/esm/deparser/deparser.js +1396 -931
- package/esm/deparser/index.js +3 -1
- package/esm/deparser/utils/sql-formatter.js +103 -1
- package/esm/index.js +16 -7
- package/esm/v16-to-v17.js +44 -1
- package/esm/v16-to-v18-direct.js +55 -0
- package/esm/v17-to-v18.js +209 -0
- package/index.d.ts +11 -4
- package/index.js +19 -6
- package/package.json +7 -6
- package/v16-to-v17.d.ts +3 -0
- package/v16-to-v17.js +44 -1
- package/v16-to-v18-direct.d.ts +22 -0
- package/v16-to-v18-direct.js +59 -0
- package/v17-to-v18.d.ts +55 -0
- package/v17-to-v18.js +213 -0
package/deparser/index.d.ts
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
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 { Deparser, DeparserOptions } from
|
|
5
|
+
import { Deparser, DeparserOptions } from './deparser';
|
|
6
6
|
declare const deparseMethod: typeof Deparser.deparse;
|
|
7
7
|
export declare const deparseSync: typeof Deparser.deparse;
|
|
8
8
|
export declare const deparse: (...args: Parameters<typeof deparseMethod>) => Promise<ReturnType<typeof deparseMethod>>;
|
|
9
9
|
export { Deparser, DeparserOptions };
|
|
10
|
+
export { splitSqlLines } from './utils/sql-formatter';
|
|
11
|
+
export { QuoteUtils } from '@pgsql/quotes';
|
package/deparser/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* DO NOT EDIT - Generated by strip-deparser-types.ts
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.Deparser = exports.deparse = exports.deparseSync = void 0;
|
|
7
|
+
exports.QuoteUtils = exports.splitSqlLines = exports.Deparser = exports.deparse = exports.deparseSync = void 0;
|
|
8
8
|
const deparser_1 = require("./deparser");
|
|
9
9
|
Object.defineProperty(exports, "Deparser", { enumerable: true, get: function () { return deparser_1.Deparser; } });
|
|
10
10
|
const deparseMethod = deparser_1.Deparser.deparse;
|
|
@@ -15,3 +15,7 @@ const deparse = async (...args) => {
|
|
|
15
15
|
return deparseMethod(...args);
|
|
16
16
|
};
|
|
17
17
|
exports.deparse = deparse;
|
|
18
|
+
var sql_formatter_1 = require("./utils/sql-formatter");
|
|
19
|
+
Object.defineProperty(exports, "splitSqlLines", { enumerable: true, get: function () { return sql_formatter_1.splitSqlLines; } });
|
|
20
|
+
var quotes_1 = require("@pgsql/quotes");
|
|
21
|
+
Object.defineProperty(exports, "QuoteUtils", { enumerable: true, get: function () { return quotes_1.QuoteUtils; } });
|
|
@@ -2,6 +2,14 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Splits SQL text into lines, breaking only at newlines that sit between
|
|
7
|
+
* tokens. A newline inside a string literal ('...', E'...', $tag$...$tag$),
|
|
8
|
+
* a quoted identifier or a block comment is part of that token's value and
|
|
9
|
+
* stays inside its line, so callers can re-indent the lines without changing
|
|
10
|
+
* what the SQL means.
|
|
11
|
+
*/
|
|
12
|
+
export declare function splitSqlLines(text: string, newlineChar?: string): string[];
|
|
5
13
|
export declare class SqlFormatter {
|
|
6
14
|
private newlineChar;
|
|
7
15
|
private tabChar;
|
|
@@ -5,6 +5,109 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.SqlFormatter = void 0;
|
|
8
|
+
exports.splitSqlLines = splitSqlLines;
|
|
9
|
+
const isIdentChar = (ch) => ch !== undefined && (/[A-Za-z0-9_$]/.test(ch) || ch.charCodeAt(0) >= 0x80);
|
|
10
|
+
const DOLLAR_TAG = /\$(?:[A-Za-z_\u0080-\uffff][A-Za-z0-9_\u0080-\uffff]*)?\$/y;
|
|
11
|
+
/**
|
|
12
|
+
* Splits SQL text into lines, breaking only at newlines that sit between
|
|
13
|
+
* tokens. A newline inside a string literal ('...', E'...', $tag$...$tag$),
|
|
14
|
+
* a quoted identifier or a block comment is part of that token's value and
|
|
15
|
+
* stays inside its line, so callers can re-indent the lines without changing
|
|
16
|
+
* what the SQL means.
|
|
17
|
+
*/
|
|
18
|
+
function splitSqlLines(text, newlineChar = '\n') {
|
|
19
|
+
if (!newlineChar || !text.includes(newlineChar)) {
|
|
20
|
+
return [text];
|
|
21
|
+
}
|
|
22
|
+
const lines = [];
|
|
23
|
+
const length = text.length;
|
|
24
|
+
let lineStart = 0;
|
|
25
|
+
let i = 0;
|
|
26
|
+
while (i < length) {
|
|
27
|
+
const ch = text[i];
|
|
28
|
+
if (ch === "'") {
|
|
29
|
+
const prev = text[i - 1];
|
|
30
|
+
const backslashEscapes = (prev === 'E' || prev === 'e') && !isIdentChar(text[i - 2]);
|
|
31
|
+
i++;
|
|
32
|
+
while (i < length) {
|
|
33
|
+
if (backslashEscapes && text[i] === '\\') {
|
|
34
|
+
i += 2;
|
|
35
|
+
}
|
|
36
|
+
else if (text[i] === "'") {
|
|
37
|
+
if (text[i + 1] === "'") {
|
|
38
|
+
i += 2;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
i++;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
i++;
|
|
49
|
+
}
|
|
50
|
+
else if (ch === '"') {
|
|
51
|
+
i++;
|
|
52
|
+
while (i < length) {
|
|
53
|
+
if (text[i] === '"') {
|
|
54
|
+
if (text[i + 1] === '"') {
|
|
55
|
+
i += 2;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
i++;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
i++;
|
|
66
|
+
}
|
|
67
|
+
else if (ch === '$' && !isIdentChar(text[i - 1])) {
|
|
68
|
+
DOLLAR_TAG.lastIndex = i;
|
|
69
|
+
const tag = DOLLAR_TAG.exec(text);
|
|
70
|
+
if (tag) {
|
|
71
|
+
const close = text.indexOf(tag[0], i + tag[0].length);
|
|
72
|
+
i = close === -1 ? length : close + tag[0].length;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
i++;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (ch === '-' && text[i + 1] === '-') {
|
|
79
|
+
const end = text.indexOf('\n', i);
|
|
80
|
+
i = end === -1 ? length : end;
|
|
81
|
+
}
|
|
82
|
+
else if (ch === '/' && text[i + 1] === '*') {
|
|
83
|
+
let depth = 1;
|
|
84
|
+
i += 2;
|
|
85
|
+
while (i < length && depth > 0) {
|
|
86
|
+
if (text[i] === '/' && text[i + 1] === '*') {
|
|
87
|
+
depth++;
|
|
88
|
+
i += 2;
|
|
89
|
+
}
|
|
90
|
+
else if (text[i] === '*' && text[i + 1] === '/') {
|
|
91
|
+
depth--;
|
|
92
|
+
i += 2;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
i++;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (text.startsWith(newlineChar, i)) {
|
|
100
|
+
lines.push(text.slice(lineStart, i));
|
|
101
|
+
i += newlineChar.length;
|
|
102
|
+
lineStart = i;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
i++;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
lines.push(text.slice(lineStart));
|
|
109
|
+
return lines;
|
|
110
|
+
}
|
|
8
111
|
class SqlFormatter {
|
|
9
112
|
newlineChar;
|
|
10
113
|
tabChar;
|
|
@@ -22,7 +125,7 @@ class SqlFormatter {
|
|
|
22
125
|
return text;
|
|
23
126
|
}
|
|
24
127
|
const indentation = this.tabChar.repeat(count);
|
|
25
|
-
return text
|
|
128
|
+
return splitSqlLines(text, this.newlineChar).map(line => line.trim() ? indentation + line : line).join(this.newlineChar);
|
|
26
129
|
}
|
|
27
130
|
parens(content) {
|
|
28
131
|
return `(${content})`;
|