prettier-plugin-sql-cst 0.19.1 → 0.19.3
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/dist/index.d.ts +21 -7
- package/dist/index.js +2637 -55
- package/package.json +4 -2
- package/dist/CstToDocMap.d.ts +0 -11
- package/dist/CstToDocMap.js +0 -1
- package/dist/PrintFn.d.ts +0 -17
- package/dist/PrintFn.js +0 -1
- package/dist/embed.d.ts +0 -3
- package/dist/embed.js +0 -6
- package/dist/embedJs.d.ts +0 -3
- package/dist/embedJs.js +0 -43
- package/dist/embedJson.d.ts +0 -3
- package/dist/embedJson.js +0 -34
- package/dist/embedSql.d.ts +0 -3
- package/dist/embedSql.js +0 -39
- package/dist/node_utils.d.ts +0 -38
- package/dist/node_utils.js +0 -44
- package/dist/options.d.ts +0 -15
- package/dist/options.js +0 -147
- package/dist/printComment.d.ts +0 -3
- package/dist/printComment.js +0 -12
- package/dist/printSql.d.ts +0 -5
- package/dist/printSql.js +0 -61
- package/dist/print_utils.d.ts +0 -13
- package/dist/print_utils.js +0 -49
- package/dist/syntax/alias.d.ts +0 -3
- package/dist/syntax/alias.js +0 -3
- package/dist/syntax/alter_action.d.ts +0 -3
- package/dist/syntax/alter_action.js +0 -120
- package/dist/syntax/alter_table.d.ts +0 -3
- package/dist/syntax/alter_table.js +0 -19
- package/dist/syntax/analyze.d.ts +0 -3
- package/dist/syntax/analyze.js +0 -4
- package/dist/syntax/base.d.ts +0 -3
- package/dist/syntax/base.js +0 -19
- package/dist/syntax/cast.d.ts +0 -3
- package/dist/syntax/cast.js +0 -4
- package/dist/syntax/comment.d.ts +0 -3
- package/dist/syntax/comment.js +0 -54
- package/dist/syntax/constraint.d.ts +0 -6
- package/dist/syntax/constraint.js +0 -80
- package/dist/syntax/create_table.d.ts +0 -3
- package/dist/syntax/create_table.js +0 -69
- package/dist/syntax/data_type.d.ts +0 -3
- package/dist/syntax/data_type.js +0 -29
- package/dist/syntax/dcl.d.ts +0 -3
- package/dist/syntax/dcl.js +0 -83
- package/dist/syntax/delete.d.ts +0 -3
- package/dist/syntax/delete.js +0 -5
- package/dist/syntax/dialects/bigquery.d.ts +0 -3
- package/dist/syntax/dialects/bigquery.js +0 -84
- package/dist/syntax/dialects/mysql.d.ts +0 -3
- package/dist/syntax/dialects/mysql.js +0 -3
- package/dist/syntax/dialects/postgresql.d.ts +0 -3
- package/dist/syntax/dialects/postgresql.js +0 -9
- package/dist/syntax/dialects/sqlite.d.ts +0 -3
- package/dist/syntax/dialects/sqlite.js +0 -9
- package/dist/syntax/do.d.ts +0 -3
- package/dist/syntax/do.js +0 -4
- package/dist/syntax/domain.d.ts +0 -3
- package/dist/syntax/domain.js +0 -11
- package/dist/syntax/drop_table.d.ts +0 -3
- package/dist/syntax/drop_table.js +0 -11
- package/dist/syntax/explain.d.ts +0 -3
- package/dist/syntax/explain.js +0 -7
- package/dist/syntax/expr.d.ts +0 -5
- package/dist/syntax/expr.js +0 -224
- package/dist/syntax/extension.d.ts +0 -3
- package/dist/syntax/extension.js +0 -13
- package/dist/syntax/frame.d.ts +0 -3
- package/dist/syntax/frame.js +0 -13
- package/dist/syntax/function.d.ts +0 -4
- package/dist/syntax/function.js +0 -55
- package/dist/syntax/index.d.ts +0 -3
- package/dist/syntax/index.js +0 -60
- package/dist/syntax/insert.d.ts +0 -3
- package/dist/syntax/insert.js +0 -33
- package/dist/syntax/merge.d.ts +0 -3
- package/dist/syntax/merge.js +0 -30
- package/dist/syntax/other_clauses.d.ts +0 -3
- package/dist/syntax/other_clauses.js +0 -9
- package/dist/syntax/parameter.d.ts +0 -3
- package/dist/syntax/parameter.js +0 -18
- package/dist/syntax/policy.d.ts +0 -3
- package/dist/syntax/policy.js +0 -27
- package/dist/syntax/prepared_statements.d.ts +0 -3
- package/dist/syntax/prepared_statements.js +0 -31
- package/dist/syntax/proc_clause.d.ts +0 -3
- package/dist/syntax/proc_clause.js +0 -14
- package/dist/syntax/procedural_language.d.ts +0 -3
- package/dist/syntax/procedural_language.js +0 -104
- package/dist/syntax/procedure.d.ts +0 -3
- package/dist/syntax/procedure.js +0 -38
- package/dist/syntax/program.d.ts +0 -3
- package/dist/syntax/program.js +0 -39
- package/dist/syntax/publication.d.ts +0 -3
- package/dist/syntax/publication.js +0 -27
- package/dist/syntax/rename_table.d.ts +0 -3
- package/dist/syntax/rename_table.js +0 -8
- package/dist/syntax/role.d.ts +0 -3
- package/dist/syntax/role.js +0 -31
- package/dist/syntax/schema.d.ts +0 -3
- package/dist/syntax/schema.js +0 -18
- package/dist/syntax/select.d.ts +0 -3
- package/dist/syntax/select.js +0 -226
- package/dist/syntax/sequence.d.ts +0 -3
- package/dist/syntax/sequence.js +0 -36
- package/dist/syntax/subscription.d.ts +0 -3
- package/dist/syntax/subscription.js +0 -10
- package/dist/syntax/transaction.d.ts +0 -3
- package/dist/syntax/transaction.js +0 -19
- package/dist/syntax/transformMap.d.ts +0 -3
- package/dist/syntax/transformMap.js +0 -100
- package/dist/syntax/trigger.d.ts +0 -3
- package/dist/syntax/trigger.js +0 -52
- package/dist/syntax/truncate.d.ts +0 -3
- package/dist/syntax/truncate.js +0 -10
- package/dist/syntax/type.d.ts +0 -3
- package/dist/syntax/type.js +0 -12
- package/dist/syntax/unsupported_grammar.d.ts +0 -3
- package/dist/syntax/unsupported_grammar.js +0 -4
- package/dist/syntax/update.d.ts +0 -3
- package/dist/syntax/update.js +0 -14
- package/dist/syntax/view.d.ts +0 -3
- package/dist/syntax/view.js +0 -48
- package/dist/transform/addFinalSemicolon.d.ts +0 -2
- package/dist/transform/addFinalSemicolon.js +0 -9
- package/dist/transform/aliasAs.d.ts +0 -2
- package/dist/transform/aliasAs.js +0 -10
- package/dist/transform/canonicKeywords.d.ts +0 -2
- package/dist/transform/canonicKeywords.js +0 -62
- package/dist/transform/canonicOperators.d.ts +0 -3
- package/dist/transform/canonicOperators.js +0 -28
- package/dist/transform/comments.d.ts +0 -12
- package/dist/transform/comments.js +0 -22
- package/dist/transform/stripTrailingCommas.d.ts +0 -2
- package/dist/transform/stripTrailingCommas.js +0 -15
- package/dist/transform/transformCst.d.ts +0 -5
- package/dist/transform/transformCst.js +0 -21
- package/dist/transform/transformUtils.d.ts +0 -2
- package/dist/transform/transformUtils.js +0 -3
- package/dist/utils.d.ts +0 -9
- package/dist/utils.js +0 -9
- package/dist/visitAllNodes.d.ts +0 -2
- package/dist/visitAllNodes.js +0 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-sql-cst",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.3",
|
|
4
4
|
"description": "Prettier plugin for SQL",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Barna Magyarkuti <bmagyarkuti@gmail.com>",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"Rene Saarsoo <nene@triin.net>"
|
|
10
10
|
],
|
|
11
11
|
"license": "GPL-3.0-or-later",
|
|
12
|
+
"type": "module",
|
|
12
13
|
"main": "dist/index.js",
|
|
13
14
|
"types": "dist/index.d.ts",
|
|
14
15
|
"repository": {
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
"scripts": {
|
|
26
27
|
"prepublishOnly": "yarn analyze-field-access && yarn test && yarn build",
|
|
27
28
|
"clean": "rm -rf dist",
|
|
28
|
-
"build": "yarn clean &&
|
|
29
|
+
"build": "yarn clean && tsup src/index.ts --format esm --dts --out-dir dist",
|
|
29
30
|
"test": "yarn node --experimental-vm-modules $(yarn bin jest)",
|
|
30
31
|
"pretty": "prettier -w src/ test/",
|
|
31
32
|
"ts:check": "tsc --noEmit",
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"jest": "^30.3.0",
|
|
49
50
|
"ts-jest": "^29.4.9",
|
|
50
51
|
"ts-node": "^10.9.2",
|
|
52
|
+
"tsup": "^8.5.1",
|
|
51
53
|
"tsx": "^4.21.0",
|
|
52
54
|
"typescript": "^5.9.3"
|
|
53
55
|
}
|
package/dist/CstToDocMap.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Node } from "sql-parser-cst";
|
|
2
|
-
import { AstPath, Doc } from "prettier";
|
|
3
|
-
import { PrintableKey, PrintFn } from "./PrintFn";
|
|
4
|
-
import { AllPrettierOptions } from "./options";
|
|
5
|
-
export type NodeByType<TType, TNode> = Extract<TNode, {
|
|
6
|
-
type: TType;
|
|
7
|
-
}>;
|
|
8
|
-
export type ToDocFn<TNode> = (print: PrintFn<TNode, PrintableKey<TNode>>, node: TNode, path: AstPath<TNode>, options: AllPrettierOptions<TNode>) => Doc;
|
|
9
|
-
export type CstToDocMap<TNode extends Node> = {
|
|
10
|
-
[TType in TNode["type"]]: ToDocFn<NodeByType<TType, TNode>>;
|
|
11
|
-
};
|
package/dist/CstToDocMap.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/PrintFn.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { AstPath, Doc } from "prettier";
|
|
2
|
-
import { Node } from "sql-parser-cst";
|
|
3
|
-
export type OldPrintFn = (path: AstPath<Node> | string) => Doc;
|
|
4
|
-
export type PrintFn<T, K = PrintableKey<T>> = {
|
|
5
|
-
(path: AstPath<Node>): Doc;
|
|
6
|
-
(path: K extends keyof T ? (T[K] extends any[] ? K : never) : never): Doc[];
|
|
7
|
-
(path: K): Doc;
|
|
8
|
-
(path: K[]): Doc[];
|
|
9
|
-
spaced(path: K): Doc[];
|
|
10
|
-
spaced(path: K[]): Doc[];
|
|
11
|
-
separated(separator: Doc, path: K): Doc[];
|
|
12
|
-
separated(separator: Doc, path: K[]): Doc[];
|
|
13
|
-
dynamicLine(): Doc;
|
|
14
|
-
};
|
|
15
|
-
export type PrintableKey<T> = Exclude<keyof T, ReservedKey>;
|
|
16
|
-
type ReservedKey = "type" | "range" | "leading" | "trailing";
|
|
17
|
-
export {};
|
package/dist/PrintFn.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/embed.d.ts
DELETED
package/dist/embed.js
DELETED
package/dist/embedJs.d.ts
DELETED
package/dist/embedJs.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { isAsClause, isCreateFunctionStmt, isLanguageClause, isStringLiteral, } from "./node_utils";
|
|
2
|
-
import { hardline, indent, stripTrailingHardline } from "./print_utils";
|
|
3
|
-
export const embedJs = (path, options) => {
|
|
4
|
-
const node = path.node;
|
|
5
|
-
const parent = path.getParentNode(0);
|
|
6
|
-
const grandParent = path.getParentNode(1);
|
|
7
|
-
if (isStringLiteral(node) &&
|
|
8
|
-
isAsClause(parent) &&
|
|
9
|
-
isCreateFunctionStmt(grandParent) &&
|
|
10
|
-
grandParent.clauses.some(isJavaScriptLanguageClause)) {
|
|
11
|
-
return async (textToDoc) => {
|
|
12
|
-
const quotes = detectQuotes(node.value);
|
|
13
|
-
if (!quotes) {
|
|
14
|
-
// Give up for now. Don't format JavaScript inside the string.
|
|
15
|
-
// Perhaps tackle this corner-case in the future.
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
const js = await textToDoc(node.value, {
|
|
19
|
-
...options,
|
|
20
|
-
parser: "babel",
|
|
21
|
-
});
|
|
22
|
-
return [
|
|
23
|
-
quotes[0],
|
|
24
|
-
indent([hardline, stripTrailingHardline(js)]),
|
|
25
|
-
hardline,
|
|
26
|
-
quotes[1],
|
|
27
|
-
];
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
31
|
-
};
|
|
32
|
-
const isJavaScriptLanguageClause = (clause) => isLanguageClause(clause) && clause.name.name === "js";
|
|
33
|
-
// Whether to quote the code with single- or double-quotes.
|
|
34
|
-
// Returns undefined when neither can be used without escaping.
|
|
35
|
-
const detectQuotes = (js) => {
|
|
36
|
-
if (!/'''/.test(js)) {
|
|
37
|
-
return ["r'''", "'''"];
|
|
38
|
-
}
|
|
39
|
-
if (!/"""/.test(js)) {
|
|
40
|
-
return ['r"""', '"""'];
|
|
41
|
-
}
|
|
42
|
-
return undefined;
|
|
43
|
-
};
|
package/dist/embedJson.d.ts
DELETED
package/dist/embedJson.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { isJsonLiteral, isJsonbLiteral, isStringLiteral } from "./node_utils";
|
|
2
|
-
import { ifBreak, indent, softline, stripTrailingHardline, } from "./print_utils";
|
|
3
|
-
export const embedJson = (path, options) => {
|
|
4
|
-
const node = path.node;
|
|
5
|
-
const parent = path.getParentNode();
|
|
6
|
-
if (isStringLiteral(node) &&
|
|
7
|
-
(isJsonLiteral(parent) || isJsonbLiteral(parent))) {
|
|
8
|
-
return async (textToDoc) => {
|
|
9
|
-
if (containsTripleQuote(node.value) ||
|
|
10
|
-
containsBackslash(node.value) ||
|
|
11
|
-
isRawString(node)) {
|
|
12
|
-
// Give up for now. Don't format JSON inside the string.
|
|
13
|
-
// Tackle these corner-case in the future.
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
const json = await textToDoc(node.value, {
|
|
17
|
-
...options,
|
|
18
|
-
parser: "json",
|
|
19
|
-
});
|
|
20
|
-
const inlineQuote = containsSingleQuote(node.value) ? "'''" : "'";
|
|
21
|
-
return [
|
|
22
|
-
ifBreak("'''", inlineQuote),
|
|
23
|
-
indent([softline, stripTrailingHardline(json)]),
|
|
24
|
-
softline,
|
|
25
|
-
ifBreak("'''", inlineQuote),
|
|
26
|
-
];
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
};
|
|
31
|
-
const containsSingleQuote = (json) => /'/.test(json);
|
|
32
|
-
const containsTripleQuote = (json) => /'''/.test(json);
|
|
33
|
-
const containsBackslash = (json) => /\\/.test(json);
|
|
34
|
-
const isRawString = (node) => /^R/i.test(node.text);
|
package/dist/embedSql.d.ts
DELETED
package/dist/embedSql.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { isAsClause, isCreateFunctionStmt, isCreateProcedureStmt, isLanguageClause, isStringLiteral, } from "./node_utils";
|
|
2
|
-
import { hardline, indent, stripTrailingHardline } from "./print_utils";
|
|
3
|
-
export const embedSql = (path, options) => {
|
|
4
|
-
const node = path.node;
|
|
5
|
-
const parent = path.getParentNode(0);
|
|
6
|
-
const grandParent = path.getParentNode(1);
|
|
7
|
-
if (isStringLiteral(node) &&
|
|
8
|
-
isAsClause(parent) &&
|
|
9
|
-
(isCreateFunctionStmt(grandParent) || isCreateProcedureStmt(grandParent)) &&
|
|
10
|
-
grandParent.clauses.some(isSqlLanguageClause)) {
|
|
11
|
-
return async (textToDoc) => {
|
|
12
|
-
const quote = detectQuote(node);
|
|
13
|
-
if (!quote) {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
const sql = await textToDoc(node.value, options);
|
|
17
|
-
return [
|
|
18
|
-
quote,
|
|
19
|
-
indent([hardline, stripTrailingHardline(sql)]),
|
|
20
|
-
hardline,
|
|
21
|
-
quote,
|
|
22
|
-
];
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
26
|
-
};
|
|
27
|
-
const isSqlLanguageClause = (clause) => isLanguageClause(clause) && clause.name.name.toLowerCase() === "sql";
|
|
28
|
-
const detectQuote = (node) => {
|
|
29
|
-
const match = node.text.match(/^('|\$[^$]*\$)/);
|
|
30
|
-
const quote = match?.[1];
|
|
31
|
-
if (quote === "'") {
|
|
32
|
-
// Convert `'` quotes to `$$`.
|
|
33
|
-
// But bail out if the code already contains $$.
|
|
34
|
-
return node.value.includes("$$") ? undefined : "$$";
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
return quote;
|
|
38
|
-
}
|
|
39
|
-
};
|
package/dist/node_utils.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Node } from "sql-parser-cst";
|
|
2
|
-
export declare const isProgram: (node: any) => node is import("sql-parser-cst").Program;
|
|
3
|
-
export declare const isValuesClause: (node: any) => node is import("sql-parser-cst").ValuesClause;
|
|
4
|
-
export declare const isFuncCall: (node: any) => node is import("sql-parser-cst").FuncCall;
|
|
5
|
-
export declare const isFuncArgs: (node: any) => node is import("sql-parser-cst").FuncArgs;
|
|
6
|
-
export declare const isCreateTableStmt: (node: any) => node is import("sql-parser-cst").CreateTableStmt;
|
|
7
|
-
export declare const isKeyword: (node: any) => node is import("sql-parser-cst").Keyword<string>;
|
|
8
|
-
export declare const isEmpty: (node: any) => node is import("sql-parser-cst").Empty;
|
|
9
|
-
export declare const isJsonLiteral: (node: any) => node is import("sql-parser-cst").JsonLiteral;
|
|
10
|
-
export declare const isJsonbLiteral: (node: any) => node is import("sql-parser-cst").JsonbLiteral;
|
|
11
|
-
export declare const isStringLiteral: (node: any) => node is import("sql-parser-cst").StringLiteral;
|
|
12
|
-
export declare const isArraySubscript: (node: any) => node is import("sql-parser-cst").ArraySubscript;
|
|
13
|
-
export declare const isAsClause: (node: any) => node is import("sql-parser-cst").AsClause<Node>;
|
|
14
|
-
export declare const isParenExpr: (node: any) => node is import("sql-parser-cst").ParenExpr<Node>;
|
|
15
|
-
export declare const isMemberExpr: (node: any) => node is import("sql-parser-cst").MemberExpr;
|
|
16
|
-
export declare const isSelectStmt: (node: any) => node is import("sql-parser-cst").SelectStmt;
|
|
17
|
-
export declare const isCompoundSelectStmt: (node: any) => node is import("sql-parser-cst").CompoundSelectStmt;
|
|
18
|
-
export declare const isListExpr: (node: any) => node is import("sql-parser-cst").ListExpr<Node>;
|
|
19
|
-
export declare const isCreateFunctionStmt: (node: any) => node is import("sql-parser-cst").CreateFunctionStmt;
|
|
20
|
-
export declare const isAlterFunctionStmt: (node: any) => node is import("sql-parser-cst").AlterFunctionStmt;
|
|
21
|
-
export declare const isDropFunctionStmt: (node: any) => node is import("sql-parser-cst").DropFunctionStmt;
|
|
22
|
-
export declare const isCreateProcedureStmt: (node: any) => node is import("sql-parser-cst").CreateProcedureStmt;
|
|
23
|
-
export declare const isAlterProcedureStmt: (node: any) => node is import("sql-parser-cst").AlterProcedureStmt;
|
|
24
|
-
export declare const isDropProcedureStmt: (node: any) => node is import("sql-parser-cst").DropProcedureStmt;
|
|
25
|
-
export declare const isAlterActionRename: (node: any) => node is import("sql-parser-cst").AlterActionRename;
|
|
26
|
-
export declare const isLanguageClause: (node: any) => node is import("sql-parser-cst").LanguageClause;
|
|
27
|
-
export declare const isDynamicallyLoadedFunction: (node: any) => node is import("sql-parser-cst").DynamicallyLoadedFunction;
|
|
28
|
-
export declare const isBigqueryQuotedMemberExpr: (node: any) => node is import("sql-parser-cst").BigQueryQuotedMemberExpr;
|
|
29
|
-
export declare const isCreateTriggerStmt: (node: any) => node is import("sql-parser-cst").CreateTriggerStmt;
|
|
30
|
-
export declare const isExecuteClause: (node: any) => node is import("sql-parser-cst").ExecuteClause;
|
|
31
|
-
export declare const isFunctionSignature: (node: any) => node is import("sql-parser-cst").FunctionSignature;
|
|
32
|
-
export declare const isDataTypeName: (node: any) => node is import("sql-parser-cst").DataTypeName;
|
|
33
|
-
export declare const isIntervalDataType: (node: any) => node is import("sql-parser-cst").IntervalDataType;
|
|
34
|
-
export declare const isIntervalUnit: (node: any) => node is import("sql-parser-cst").IntervalUnit;
|
|
35
|
-
export declare const isIntervalUnitRange: (node: any) => node is import("sql-parser-cst").IntervalUnitRange;
|
|
36
|
-
export declare const isTimeDataType: (node: any) => node is import("sql-parser-cst").TimeDataType;
|
|
37
|
-
export declare const isParametricDataType: (node: any) => node is import("sql-parser-cst").ParametricDataType;
|
|
38
|
-
export declare const isDataType: ([node, ...ancestors]: any[]) => boolean;
|
package/dist/node_utils.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { isObject } from "./utils";
|
|
2
|
-
const is = (type) => (node) => isObject(node) && node.type === type;
|
|
3
|
-
export const isProgram = is("program");
|
|
4
|
-
export const isValuesClause = is("values_clause");
|
|
5
|
-
export const isFuncCall = is("func_call");
|
|
6
|
-
export const isFuncArgs = is("func_args");
|
|
7
|
-
export const isCreateTableStmt = is("create_table_stmt");
|
|
8
|
-
export const isKeyword = is("keyword");
|
|
9
|
-
export const isEmpty = is("empty");
|
|
10
|
-
export const isJsonLiteral = is("json_literal");
|
|
11
|
-
export const isJsonbLiteral = is("jsonb_literal");
|
|
12
|
-
export const isStringLiteral = is("string_literal");
|
|
13
|
-
export const isArraySubscript = is("array_subscript");
|
|
14
|
-
export const isAsClause = is("as_clause");
|
|
15
|
-
export const isParenExpr = is("paren_expr");
|
|
16
|
-
export const isMemberExpr = is("member_expr");
|
|
17
|
-
export const isSelectStmt = is("select_stmt");
|
|
18
|
-
export const isCompoundSelectStmt = is("compound_select_stmt");
|
|
19
|
-
export const isListExpr = is("list_expr");
|
|
20
|
-
export const isCreateFunctionStmt = is("create_function_stmt");
|
|
21
|
-
export const isAlterFunctionStmt = is("alter_function_stmt");
|
|
22
|
-
export const isDropFunctionStmt = is("drop_function_stmt");
|
|
23
|
-
export const isCreateProcedureStmt = is("create_procedure_stmt");
|
|
24
|
-
export const isAlterProcedureStmt = is("alter_procedure_stmt");
|
|
25
|
-
export const isDropProcedureStmt = is("drop_procedure_stmt");
|
|
26
|
-
export const isAlterActionRename = is("alter_action_rename");
|
|
27
|
-
export const isLanguageClause = is("language_clause");
|
|
28
|
-
export const isDynamicallyLoadedFunction = is("dynamically_loaded_function");
|
|
29
|
-
export const isBigqueryQuotedMemberExpr = is("bigquery_quoted_member_expr");
|
|
30
|
-
export const isCreateTriggerStmt = is("create_trigger_stmt");
|
|
31
|
-
export const isExecuteClause = is("execute_clause");
|
|
32
|
-
export const isFunctionSignature = is("function_signature");
|
|
33
|
-
export const isDataTypeName = is("data_type_name");
|
|
34
|
-
export const isIntervalDataType = is("interval_data_type");
|
|
35
|
-
export const isIntervalUnit = is("interval_unit");
|
|
36
|
-
export const isIntervalUnitRange = is("interval_unit_range");
|
|
37
|
-
export const isTimeDataType = is("time_data_type");
|
|
38
|
-
export const isParametricDataType = is("parametric_data_type");
|
|
39
|
-
export const isDataType = ([node, ...ancestors]) => isDataTypeName(node) ||
|
|
40
|
-
isIntervalDataType(node) ||
|
|
41
|
-
(isIntervalUnit(node) && isDataType(ancestors)) ||
|
|
42
|
-
(isIntervalUnitRange(node) && isDataType(ancestors)) ||
|
|
43
|
-
isTimeDataType(node) ||
|
|
44
|
-
isParametricDataType(node);
|
package/dist/options.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ParserOptions, SupportOptions } from "prettier";
|
|
2
|
-
import { Node, ParserOptions as CstParserOptions } from "sql-parser-cst";
|
|
3
|
-
export interface SqlPluginOptions {
|
|
4
|
-
sqlKeywordCase: "preserve" | "upper" | "lower";
|
|
5
|
-
sqlLiteralCase: "preserve" | "upper" | "lower";
|
|
6
|
-
sqlTypeCase: "preserve" | "upper" | "lower";
|
|
7
|
-
sqlIdentifierCase: "preserve" | "upper" | "lower";
|
|
8
|
-
sqlFunctionCase: "preserve" | "upper" | "lower";
|
|
9
|
-
sqlParamTypes: NonNullable<CstParserOptions["paramTypes"]>;
|
|
10
|
-
sqlCanonicalSyntax: boolean;
|
|
11
|
-
sqlFinalSemicolon: boolean;
|
|
12
|
-
sqlAcceptUnsupportedGrammar: boolean;
|
|
13
|
-
}
|
|
14
|
-
export type AllPrettierOptions<T = Node> = ParserOptions<T> & SqlPluginOptions;
|
|
15
|
-
export declare const options: SupportOptions;
|
package/dist/options.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
export const options = {
|
|
2
|
-
sqlKeywordCase: {
|
|
3
|
-
type: "choice",
|
|
4
|
-
category: "SQL",
|
|
5
|
-
default: "upper",
|
|
6
|
-
description: "Enforces upper/lower case for SQL keywords",
|
|
7
|
-
choices: [
|
|
8
|
-
{
|
|
9
|
-
value: "preserve",
|
|
10
|
-
description: "preserves the existing case",
|
|
11
|
-
since: "0.1.0",
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
value: "upper",
|
|
15
|
-
description: "forces all keywords to uppercase",
|
|
16
|
-
since: "0.1.0",
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
value: "lower",
|
|
20
|
-
description: "forces all keywords to lowercase",
|
|
21
|
-
since: "0.1.0",
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
sqlLiteralCase: {
|
|
26
|
-
type: "choice",
|
|
27
|
-
category: "SQL",
|
|
28
|
-
default: "upper",
|
|
29
|
-
description: "Enforces upper/lower case for SQL literals (TRUE, FALSE, NULL)",
|
|
30
|
-
choices: [
|
|
31
|
-
{
|
|
32
|
-
value: "preserve",
|
|
33
|
-
description: "preserves the existing case",
|
|
34
|
-
since: "0.14.0",
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
value: "upper",
|
|
38
|
-
description: "forces all literals to uppercase",
|
|
39
|
-
since: "0.14.0",
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
value: "lower",
|
|
43
|
-
description: "forces all literals to lowercase",
|
|
44
|
-
since: "0.14.0",
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
},
|
|
48
|
-
sqlTypeCase: {
|
|
49
|
-
type: "choice",
|
|
50
|
-
category: "SQL",
|
|
51
|
-
default: "upper",
|
|
52
|
-
description: "Enforces upper/lower case for SQL types",
|
|
53
|
-
choices: [
|
|
54
|
-
{
|
|
55
|
-
value: "preserve",
|
|
56
|
-
description: "preserves the existing case",
|
|
57
|
-
since: "0.17.0",
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
value: "upper",
|
|
61
|
-
description: "forces all type names to uppercase",
|
|
62
|
-
since: "0.17.0",
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
value: "lower",
|
|
66
|
-
description: "forces all type names to lowercase",
|
|
67
|
-
since: "0.17.0",
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
},
|
|
71
|
-
sqlIdentifierCase: {
|
|
72
|
-
type: "choice",
|
|
73
|
-
category: "SQL",
|
|
74
|
-
default: "preserve",
|
|
75
|
-
description: "Enforces upper/lower case for unquoted SQL identifiers",
|
|
76
|
-
choices: [
|
|
77
|
-
{
|
|
78
|
-
value: "preserve",
|
|
79
|
-
description: "preserves the existing case",
|
|
80
|
-
since: "0.17.0",
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
value: "upper",
|
|
84
|
-
description: "forces all unquoted identifier names to uppercase",
|
|
85
|
-
since: "0.17.0",
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
value: "lower",
|
|
89
|
-
description: "forces all unquoted identifier names to lowercase",
|
|
90
|
-
since: "0.17.0",
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
},
|
|
94
|
-
sqlFunctionCase: {
|
|
95
|
-
type: "choice",
|
|
96
|
-
category: "SQL",
|
|
97
|
-
default: "preserve",
|
|
98
|
-
description: "Enforces upper/lower case for SQL function names",
|
|
99
|
-
choices: [
|
|
100
|
-
{
|
|
101
|
-
value: "preserve",
|
|
102
|
-
description: "preserves the existing case",
|
|
103
|
-
since: "0.17.0",
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
value: "upper",
|
|
107
|
-
description: "forces all unquoted function names to uppercase",
|
|
108
|
-
since: "0.17.0",
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
value: "lower",
|
|
112
|
-
description: "forces all unquoted function names to lowercase",
|
|
113
|
-
since: "0.17.0",
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
},
|
|
117
|
-
sqlParamTypes: {
|
|
118
|
-
type: "string",
|
|
119
|
-
array: true,
|
|
120
|
-
category: "SQL",
|
|
121
|
-
default: [{ value: [] }],
|
|
122
|
-
description: "Syntax for bound parameters",
|
|
123
|
-
// Since 0.7.0
|
|
124
|
-
// Possible values in array: "?" | "?nr" | "$nr" | ":name" | "$name" | "@name" | "@`name`"
|
|
125
|
-
},
|
|
126
|
-
sqlCanonicalSyntax: {
|
|
127
|
-
type: "boolean",
|
|
128
|
-
category: "SQL",
|
|
129
|
-
default: true,
|
|
130
|
-
description: "Enforces one true style of SQL syntax (adds and removes keywords)",
|
|
131
|
-
// Since 0.11.0
|
|
132
|
-
},
|
|
133
|
-
sqlFinalSemicolon: {
|
|
134
|
-
type: "boolean",
|
|
135
|
-
category: "SQL",
|
|
136
|
-
default: true,
|
|
137
|
-
description: "Enforces a semicolon at the end of last SQL statement",
|
|
138
|
-
// Since 0.13.0
|
|
139
|
-
},
|
|
140
|
-
sqlAcceptUnsupportedGrammar: {
|
|
141
|
-
type: "boolean",
|
|
142
|
-
category: "SQL",
|
|
143
|
-
default: false,
|
|
144
|
-
description: "Skips formatting unsupported SQL statements instead of exiting with an error",
|
|
145
|
-
// Since 0.12.0
|
|
146
|
-
},
|
|
147
|
-
};
|
package/dist/printComment.d.ts
DELETED
package/dist/printComment.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const printComment = (path) => {
|
|
2
|
-
const node = path.node;
|
|
3
|
-
if (node.type === "line_comment") {
|
|
4
|
-
if (/^--[^ \t]/.test(node.text)) {
|
|
5
|
-
return node.text.replace(/^--/, "-- ");
|
|
6
|
-
}
|
|
7
|
-
if (/^#[^ \t!]/.test(node.text)) {
|
|
8
|
-
return node.text.replace(/^#/, "# ");
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return node.text;
|
|
12
|
-
};
|
package/dist/printSql.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Node } from "sql-parser-cst";
|
|
2
|
-
import { AstPath, Doc } from "prettier";
|
|
3
|
-
import { OldPrintFn } from "./PrintFn";
|
|
4
|
-
import { AllPrettierOptions } from "./options";
|
|
5
|
-
export declare function printSql(path: AstPath<Node>, options: AllPrettierOptions, oldPrint: OldPrintFn): Doc;
|
package/dist/printSql.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
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) {
|
|
5
|
-
return printNode(path, options, createPrintFn(path, oldPrint, options));
|
|
6
|
-
}
|
|
7
|
-
let cachedPrintFn;
|
|
8
|
-
let cachedPath;
|
|
9
|
-
function createPrintFn(path, oldPrint, opts) {
|
|
10
|
-
// The path parameter will reference the same AstPath instance
|
|
11
|
-
// during the whole printing cycle.
|
|
12
|
-
// So we can keep using the same print function as long as
|
|
13
|
-
// the path stays the same.
|
|
14
|
-
if (cachedPath === path) {
|
|
15
|
-
return cachedPrintFn;
|
|
16
|
-
}
|
|
17
|
-
cachedPath = path;
|
|
18
|
-
cachedPrintFn = ((selector) => {
|
|
19
|
-
if (isArray(selector)) {
|
|
20
|
-
const node = path.node;
|
|
21
|
-
return selector.filter((sel) => isDefined(node[sel])).map(oldPrint);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
return oldPrint(selector);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
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)])
|
|
32
|
-
// skip empty arrays
|
|
33
|
-
.filter(([sel, doc]) => !isEmptyArray(doc))
|
|
34
|
-
// only join with spaces when input to print was Node[]
|
|
35
|
-
.map(([sel, doc]) => (isArray(node[sel]) ? join(" ", doc) : doc));
|
|
36
|
-
return docs.length > 0 ? [join(separator, docs)] : [];
|
|
37
|
-
};
|
|
38
|
-
cachedPrintFn.spaced = (selector) => cachedPrintFn.separated(" ", selector);
|
|
39
|
-
cachedPrintFn.dynamicLine = () => {
|
|
40
|
-
const node = path.node;
|
|
41
|
-
return containsNewline(node, opts) ? hardline : line;
|
|
42
|
-
};
|
|
43
|
-
return cachedPrintFn;
|
|
44
|
-
}
|
|
45
|
-
function printNode(path, options, print) {
|
|
46
|
-
const node = path.node;
|
|
47
|
-
if (isArray(node)) {
|
|
48
|
-
return path.map(print);
|
|
49
|
-
}
|
|
50
|
-
if (isString(node)) {
|
|
51
|
-
return node;
|
|
52
|
-
}
|
|
53
|
-
if (!node?.type) {
|
|
54
|
-
throw new Error(`No type field on node: ${JSON.stringify(node)}`);
|
|
55
|
-
}
|
|
56
|
-
const fn = transformMap[node.type];
|
|
57
|
-
if (!fn) {
|
|
58
|
-
throw new Error(`Unexpected node type: ${node.type}`);
|
|
59
|
-
}
|
|
60
|
-
return fn(print, node, path, options);
|
|
61
|
-
}
|
package/dist/print_utils.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Doc, doc } from "prettier";
|
|
2
|
-
import { Node } from "sql-parser-cst";
|
|
3
|
-
export declare const line: doc.builders.Line, hardline: doc.builders.Hardline, softline: doc.builders.Softline, indent: typeof doc.builders.indent, group: typeof doc.builders.group, lineSuffix: typeof doc.builders.lineSuffix, ifBreak: typeof doc.builders.ifBreak, breakParent: doc.builders.BreakParent;
|
|
4
|
-
export declare const stripTrailingHardline: typeof doc.utils.stripTrailingHardline;
|
|
5
|
-
/** Improved join() that also accepts a non-array docs parameter */
|
|
6
|
-
export declare const join: (sep: Doc, docs: Doc) => Doc;
|
|
7
|
-
/** True when the Node contains a newline in original source code */
|
|
8
|
-
export declare const containsNewline: (node: Node, opts: {
|
|
9
|
-
originalText: string;
|
|
10
|
-
}) => boolean;
|
|
11
|
-
export declare const hasEmptyLineBetweenNodes: (node1: Node, node2: Node, opts: {
|
|
12
|
-
originalText: string;
|
|
13
|
-
}) => boolean;
|
package/dist/print_utils.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
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;
|
|
6
|
-
/** Improved join() that also accepts a non-array docs parameter */
|
|
7
|
-
export const join = (sep, docs) => isArray(docs) ? origJoin(sep, docs) : docs;
|
|
8
|
-
/** True when the Node contains a newline in original source code */
|
|
9
|
-
export const containsNewline = (node, opts) => {
|
|
10
|
-
if (!node.range) {
|
|
11
|
-
throw new Error("containsNewline() expected a Node with range info");
|
|
12
|
-
}
|
|
13
|
-
return util.hasNewlineInRange(opts.originalText, node.range[0], node.range[1]);
|
|
14
|
-
};
|
|
15
|
-
export const hasEmptyLineBetweenNodes = (node1, node2, opts) => {
|
|
16
|
-
if (!node1.range || !node2.range) {
|
|
17
|
-
throw new Error("emptyLineBetweenNodes() expects Nodes with range info");
|
|
18
|
-
}
|
|
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);
|
|
22
|
-
// when no empty lines between nodes, we can return early
|
|
23
|
-
if (indexes.length === 0) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
// otherwise we need to check whether the empty line happens to be
|
|
27
|
-
// inside a comment or between comments
|
|
28
|
-
const comments = [...(node1.trailing ?? []), ...(node2.leading ?? [])];
|
|
29
|
-
return (indexes.filter((index) => !isIndexInsideOrBetweenComments(index, comments))
|
|
30
|
-
.length > 0);
|
|
31
|
-
};
|
|
32
|
-
function emptyLineIndexes(text) {
|
|
33
|
-
const indexes = [];
|
|
34
|
-
const re = /\n[ \t]*\r?\n/g;
|
|
35
|
-
let match;
|
|
36
|
-
while ((match = re.exec(text))) {
|
|
37
|
-
indexes.push(match.index);
|
|
38
|
-
}
|
|
39
|
-
return indexes;
|
|
40
|
-
}
|
|
41
|
-
function isIndexInsideOrBetweenComments(index, comments) {
|
|
42
|
-
if (comments.length === 0) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
// Assume all nodes have range info
|
|
46
|
-
const start = comments[0].range[0];
|
|
47
|
-
const end = comments[comments.length - 1].range[1];
|
|
48
|
-
return start <= index && index <= end;
|
|
49
|
-
}
|
package/dist/syntax/alias.d.ts
DELETED
package/dist/syntax/alias.js
DELETED