prettier-plugin-postgresql 0.1.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.
Files changed (40) hide show
  1. package/README.md +197 -0
  2. package/bin/dotnet/Google.Protobuf.dll +0 -0
  3. package/bin/dotnet/PgScriptDom.deps.json +95 -0
  4. package/bin/dotnet/PgScriptDom.dll +0 -0
  5. package/bin/dotnet/PrettierSql.Core.dll +0 -0
  6. package/bin/dotnet/libpg_query.dylib +0 -0
  7. package/bin/dotnet/pgsqlparser.dll +0 -0
  8. package/bin/dotnet/runtimes/linux-x64/native/libpg_query.so +0 -0
  9. package/bin/dotnet/runtimes/osx-arm64/native/libpg_query.dylib +0 -0
  10. package/bin/dotnet/runtimes/osx-x64/native/libpg_query.dylib +0 -0
  11. package/bin/dotnet/runtimes/win-x64/native/libpg_query.dll +0 -0
  12. package/dist/index.d.ts +5 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +21 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/language.d.ts +3 -0
  17. package/dist/language.d.ts.map +1 -0
  18. package/dist/language.js +9 -0
  19. package/dist/language.js.map +1 -0
  20. package/dist/parser/index.d.ts +5 -0
  21. package/dist/parser/index.d.ts.map +1 -0
  22. package/dist/parser/index.js +58 -0
  23. package/dist/parser/index.js.map +1 -0
  24. package/dist/printer/expressions.d.ts +8 -0
  25. package/dist/printer/expressions.d.ts.map +1 -0
  26. package/dist/printer/expressions.js +623 -0
  27. package/dist/printer/expressions.js.map +1 -0
  28. package/dist/printer/helpers.d.ts +6 -0
  29. package/dist/printer/helpers.d.ts.map +1 -0
  30. package/dist/printer/helpers.js +18 -0
  31. package/dist/printer/helpers.js.map +1 -0
  32. package/dist/printer/index.d.ts +4 -0
  33. package/dist/printer/index.d.ts.map +1 -0
  34. package/dist/printer/index.js +23 -0
  35. package/dist/printer/index.js.map +1 -0
  36. package/dist/printer/statements.d.ts +11 -0
  37. package/dist/printer/statements.d.ts.map +1 -0
  38. package/dist/printer/statements.js +1533 -0
  39. package/dist/printer/statements.js.map +1 -0
  40. package/package.json +59 -0
package/README.md ADDED
@@ -0,0 +1,197 @@
1
+ # prettier-plugin-postgresql
2
+
3
+ > **Beta** — covers the core PostgreSQL DML and DDL statement set. A small number of advanced or uncommon constructs fall back to a `/* unknown */` comment placeholder while support is being added.
4
+
5
+ A [Prettier](https://prettier.io) plugin for PostgreSQL SQL. Parses SQL with [libpg_query](https://github.com/pganalyze/libpg_query) (the actual PostgreSQL parser) and formats it using Prettier's document IR for consistent, readable output.
6
+
7
+ ---
8
+
9
+ ## Features
10
+
11
+ ### DML
12
+
13
+ - **SELECT** — column lists, table aliases, all JOIN types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL), WHERE, GROUP BY / HAVING, ORDER BY, LIMIT / OFFSET, DISTINCT, DISTINCT ON
14
+ - **Set operations** — UNION / UNION ALL / INTERSECT / EXCEPT
15
+ - **Subqueries** — correlated subqueries, EXISTS, scalar sublinks, LATERAL
16
+ - **CTEs** — WITH / WITH RECURSIVE, data-modifying CTEs (WITH ... DELETE/INSERT/UPDATE)
17
+ - **Window functions** — OVER (PARTITION BY, ORDER BY, frame clauses: ROWS/RANGE/GROUPS BETWEEN)
18
+ - **Aggregate functions** — FILTER (WHERE ...), ORDER BY inside aggregate (e.g. `string_agg`)
19
+ - **GROUP BY extensions** — ROLLUP, CUBE, GROUPING SETS
20
+ - **Locking** — FOR UPDATE / FOR SHARE / FOR NO KEY UPDATE / FOR KEY SHARE with OF, NOWAIT, SKIP LOCKED
21
+ - **INSERT** — VALUES (single and multi-row), DEFAULT VALUES, ON CONFLICT DO NOTHING / DO UPDATE SET, RETURNING, OVERRIDING USER/SYSTEM VALUE, WITH clause
22
+ - **UPDATE** — SET, FROM, WHERE, RETURNING, WITH clause
23
+ - **DELETE** — WHERE, RETURNING, WITH clause
24
+ - **TRUNCATE** — with RESTART IDENTITY and CASCADE
25
+ - **Transaction control** — BEGIN / START TRANSACTION / COMMIT / ROLLBACK / SAVEPOINT / RELEASE SAVEPOINT / ROLLBACK TO SAVEPOINT / SET TRANSACTION (isolation level, READ ONLY/WRITE, DEFERRABLE) / PREPARE TRANSACTION / COMMIT PREPARED / ROLLBACK PREPARED
26
+ - **MERGE** — WHEN MATCHED / WHEN NOT MATCHED / WHEN NOT MATCHED BY SOURCE; UPDATE SET, INSERT, DELETE, DO NOTHING actions; conditional AND clause; RETURNING
27
+ - **CALL** — stored-procedure invocation
28
+
29
+ ### DDL
30
+
31
+ - **CREATE TABLE** — column definitions with full constraint support: NOT NULL, DEFAULT, PRIMARY KEY, FOREIGN KEY (column-level and table-level, with ON UPDATE/DELETE actions), CHECK, UNIQUE, GENERATED ALWAYS AS (stored), GENERATED AS IDENTITY, named constraints, DEFERRABLE; type modifiers (`VARCHAR(100)`, `NUMERIC(10,2)`), array types (`TEXT[]`)
32
+ - **ALTER TABLE** — ADD COLUMN, DROP COLUMN, ADD CONSTRAINT, RENAME COLUMN, ALTER COLUMN TYPE, SET/DROP DEFAULT, SET/DROP NOT NULL, RENAME TABLE
33
+ - **CREATE VIEW** / **CREATE MATERIALIZED VIEW**
34
+ - **CREATE TABLE AS** — `CREATE TABLE foo AS SELECT ...`
35
+ - **CREATE INDEX** / CREATE UNIQUE INDEX
36
+ - **CREATE FUNCTION** — RETURNS, LANGUAGE, dollar-quoted `$$...$$` body, parameter lists with modes (IN, OUT, INOUT)
37
+ - **CREATE TYPE** — composite (`AS (...)`) and enum (`AS ENUM (...)`)
38
+ - **ALTER TYPE** — ADD VALUE for enums (with BEFORE/AFTER placement, IF NOT EXISTS)
39
+ - **CREATE / ALTER SEQUENCE** — START WITH, INCREMENT BY, MINVALUE, MAXVALUE, CACHE, CYCLE, RESTART WITH
40
+ - **CREATE SCHEMA** — with IF NOT EXISTS and AUTHORIZATION
41
+ - **CREATE EXTENSION** — with IF NOT EXISTS
42
+ - **CREATE TRIGGER** — BEFORE/AFTER/INSTEAD OF, INSERT/UPDATE/DELETE/TRUNCATE, FOR EACH ROW/STATEMENT
43
+ - **DROP** — TABLE, VIEW, INDEX, FUNCTION
44
+ - **GRANT / REVOKE** — on TABLE, SCHEMA, FUNCTION, and ALL ... IN SCHEMA; WITH GRANT OPTION; CASCADE
45
+ - **CREATE / ALTER ROLE** — with LOGIN, PASSWORD, SUPERUSER, CREATEDB, CREATEROLE, INHERIT, REPLICATION, BYPASSRLS, CONNECTION LIMIT
46
+ - **COMMENT ON** — TABLE, COLUMN, SCHEMA, DATABASE, INDEX, SEQUENCE, VIEW, FUNCTION, TYPE
47
+ - **CREATE TABLE LIKE** — `CREATE TABLE new (LIKE existing INCLUDING ALL)`
48
+ - **Table partitioning** — `PARTITION BY RANGE/LIST/HASH`, `CREATE TABLE ... PARTITION OF`, partition bounds (`FOR VALUES FROM/TO`, `IN`, `WITH`, `DEFAULT`)
49
+ - **TABLESAMPLE** — `FROM t TABLESAMPLE BERNOULLI(10)` / `SYSTEM(5) REPEATABLE (42)`
50
+ - **VACUUM / ANALYZE / CLUSTER / REINDEX** — maintenance statements with options
51
+ - **Foreign data wrappers** — `CREATE SERVER`, `CREATE FOREIGN TABLE`, `CREATE USER MAPPING`, `IMPORT FOREIGN SCHEMA`
52
+ - **Logical replication** — `CREATE / ALTER / DROP PUBLICATION` and `SUBSCRIPTION`
53
+ - **CREATE AGGREGATE** — `CREATE AGGREGATE name (SFUNC = ..., STYPE = ...)`
54
+ - **CREATE OPERATOR** — `CREATE OPERATOR op (LEFTARG = ..., PROCEDURE = ...)`
55
+ - **CREATE COLLATION** — `CREATE COLLATION name (LOCALE = ...)` and `FROM existing`
56
+ - **SECURITY LABEL** — `SECURITY LABEL FOR provider ON object IS label`
57
+
58
+ ### Expressions
59
+
60
+ - **SQL standard functions** — `SUBSTRING(str FROM pattern)`, `EXTRACT(field FROM expr)`, `TRIM(LEADING/TRAILING/BOTH ... FROM str)`, `POSITION(x IN y)`, `expr AT TIME ZONE tz`, `OVERLAY(...)`
61
+ - **Type casting** — `expr::type` (PostgreSQL style), `INTERVAL '1 day'` literals with optional field modifiers (`HOUR TO MINUTE`, `DAY TO SECOND`, etc.)
62
+ - **Array subscripts** — `arr[1]`, `arr[2:4]`, `arr[:3]`
63
+ - **Named arguments** — `func(param => value)`
64
+ - **Conditional** — CASE / WHEN / THEN / ELSE, COALESCE, NULLIF, GREATEST, LEAST
65
+ - **XML functions** — `XMLELEMENT` (with `XMLATTRIBUTES`), `XMLFOREST`, `XMLCONCAT`, `XMLPI`, `XMLAGG`
66
+ - **SQL/JSON functions** — `JSON_QUERY`, `JSON_EXISTS`, `JSON_VALUE` (with `RETURNING` type) — PostgreSQL 16+
67
+ - **Predicates** — IN / NOT IN, BETWEEN / NOT BETWEEN, LIKE / NOT LIKE, ILIKE / NOT ILIKE, SIMILAR TO, IS NULL / IS NOT NULL, IS DISTINCT FROM, ANY / ALL
68
+ - **SQL value functions** — CURRENT_DATE, CURRENT_TIMESTAMP, CURRENT_USER, SESSION_USER, LOCALTIME, LOCALTIMESTAMP, and others
69
+ - **GROUPING()** — `GROUPING(col)` predicate used alongside GROUPING SETS
70
+
71
+ ### DML (continued)
72
+
73
+ - **SET / SHOW / RESET** — `SET search_path = myschema`, `SHOW work_mem`, `RESET ALL`
74
+ - **SELECT INTO** — `SELECT ... INTO [TEMP] table`
75
+ - **COPY** — `COPY table FROM/TO`, `COPY (query) TO`; program and option list
76
+ - **EXPLAIN** — `EXPLAIN`, `EXPLAIN ANALYZE`, `EXPLAIN (ANALYZE, VERBOSE, FORMAT JSON) stmt`
77
+ - **PREPARE / EXECUTE / DEALLOCATE** — server-side prepared statements
78
+ - **LISTEN / UNLISTEN / NOTIFY** — async pub/sub with optional payload
79
+ - **LOCK TABLE** — `LOCK TABLE t IN ACCESS EXCLUSIVE MODE [NOWAIT]`
80
+ - **Cursors** — `DECLARE CURSOR`, `FETCH`, `MOVE`, `CLOSE`
81
+ - **Comment preservation** — line comments (`-- ...`) and block comments (`/* ... */`) are preserved: leading comments before a statement stay before it; inline trailing comments stay on the statement's final line
82
+
83
+ ### DDL (continued)
84
+
85
+ - **ALTER FUNCTION** — SET COST, SET ROWS, SET VOLATILE/STABLE/IMMUTABLE, RENAME TO, OWNER TO, SET SCHEMA
86
+ - **REFRESH MATERIALIZED VIEW** — with CONCURRENTLY
87
+ - **CREATE RULE** — BEFORE/AFTER/INSTEAD, INSERT/UPDATE/DELETE/SELECT, DO ALSO/INSTEAD
88
+ - **Row Security Policies** — `CREATE / ALTER POLICY` with USING and WITH CHECK
89
+
90
+ ### Pending Implementation
91
+
92
+ | Feature | Notes |
93
+ |---|---|
94
+ | **XMLTABLE** | `XMLTABLE(xpath COLUMNS ...)` — tabular XML query |
95
+ | **JSON_TABLE** | `JSON_TABLE(data, path COLUMNS ...)` — tabular JSON query (PostgreSQL 16+) |
96
+ | **PL/pgSQL** | Full procedural language (IF/ELSIF, LOOP, RETURN, EXCEPTION, DECLARE) — out of scope for a SQL formatter |
97
+
98
+ ---
99
+
100
+ ## Requirements
101
+
102
+ | Requirement | Version |
103
+ |---|---|
104
+ | Node.js | 20 or later |
105
+ | .NET Runtime | 8.0 or later |
106
+ | Prettier | 3.x |
107
+
108
+ ---
109
+
110
+ ## Installation
111
+
112
+ ```sh
113
+ npm install --save-dev prettier prettier-plugin-postgresql
114
+ ```
115
+
116
+ Then add the plugin to your Prettier configuration:
117
+
118
+ ```js
119
+ // prettier.config.js
120
+ export default {
121
+ plugins: ['prettier-plugin-postgresql'],
122
+ overrides: [
123
+ {
124
+ files: ['*.sql', '*.pgsql'],
125
+ options: {
126
+ parser: 'pgsql',
127
+ },
128
+ },
129
+ ],
130
+ };
131
+ ```
132
+
133
+ See [Getting Started](docs/getting-started.md) for VS Code setup and build-from-source instructions.
134
+
135
+ ---
136
+
137
+ ## Quick Example
138
+
139
+ **Input** (unformatted):
140
+ ```sql
141
+ SELECT id,title,price,author_id FROM books WHERE in_stock=TRUE AND price<50 ORDER BY price ASC;
142
+ ```
143
+
144
+ **Output** (default options — lowercase keywords, standard density, trailing commas):
145
+ ```sql
146
+ select
147
+ id,
148
+ title,
149
+ price,
150
+ author_id
151
+ from
152
+ books
153
+ where
154
+ in_stock = true
155
+ and price < 50
156
+ order by
157
+ price asc;
158
+ ```
159
+
160
+ ---
161
+
162
+ ## Configuration
163
+
164
+ Three formatting options are available. See [Options](docs/options.md) for full details and examples.
165
+
166
+ | Option | Values | Default | Description |
167
+ |---|---|---|---|
168
+ | `sqlKeywordCase` | `lower` \| `upper` \| `preserve` | `lower` | Case for SQL keywords |
169
+ | `sqlDensity` | `compact` \| `standard` \| `spacious` | `standard` | Whitespace density |
170
+ | `sqlCommaStyle` | `trailing` \| `leading` | `trailing` | Comma placement in lists |
171
+
172
+ ```js
173
+ // prettier.config.js
174
+ export default {
175
+ plugins: ['prettier-plugin-postgresql'],
176
+ overrides: [
177
+ {
178
+ files: '*.sql',
179
+ options: {
180
+ parser: 'pgsql',
181
+ sqlKeywordCase: 'upper',
182
+ sqlDensity: 'standard',
183
+ sqlCommaStyle: 'trailing',
184
+ },
185
+ },
186
+ ],
187
+ };
188
+ ```
189
+
190
+ ---
191
+
192
+ ## Documentation
193
+
194
+ - [Getting Started](docs/getting-started.md) — installation, VS Code setup, building from source
195
+ - [Options](docs/options.md) — all formatting options with examples
196
+ - [Examples](docs/examples.md) — before/after formatting examples for common patterns
197
+ - [Formatting Reference](docs/formatting.md) — comprehensive formatting rules by statement type
Binary file
@@ -0,0 +1,95 @@
1
+ {
2
+ "runtimeTarget": {
3
+ "name": ".NETCoreApp,Version=v8.0",
4
+ "signature": ""
5
+ },
6
+ "compilationOptions": {},
7
+ "targets": {
8
+ ".NETCoreApp,Version=v8.0": {
9
+ "PgScriptDom/1.0.0": {
10
+ "dependencies": {
11
+ "PrettierSql.Core": "1.0.0",
12
+ "pgsqlparser": "1.0.0"
13
+ },
14
+ "runtime": {
15
+ "PgScriptDom.dll": {}
16
+ }
17
+ },
18
+ "Google.Protobuf/3.33.0": {
19
+ "runtime": {
20
+ "lib/net5.0/Google.Protobuf.dll": {
21
+ "assemblyVersion": "3.33.0.0",
22
+ "fileVersion": "3.33.0.0"
23
+ }
24
+ }
25
+ },
26
+ "pgsqlparser/1.0.0": {
27
+ "dependencies": {
28
+ "Google.Protobuf": "3.33.0"
29
+ },
30
+ "runtime": {
31
+ "lib/net8.0/pgsqlparser.dll": {
32
+ "assemblyVersion": "1.0.0.0",
33
+ "fileVersion": "1.0.0.0"
34
+ }
35
+ },
36
+ "runtimeTargets": {
37
+ "runtimes/linux-x64/native/libpg_query.so": {
38
+ "rid": "linux-x64",
39
+ "assetType": "native",
40
+ "fileVersion": "0.0.0.0"
41
+ },
42
+ "runtimes/osx-arm64/native/libpg_query.dylib": {
43
+ "rid": "osx-arm64",
44
+ "assetType": "native",
45
+ "fileVersion": "0.0.0.0"
46
+ },
47
+ "runtimes/osx-x64/native/libpg_query.dylib": {
48
+ "rid": "osx-x64",
49
+ "assetType": "native",
50
+ "fileVersion": "0.0.0.0"
51
+ },
52
+ "runtimes/win-x64/native/libpg_query.dll": {
53
+ "rid": "win-x64",
54
+ "assetType": "native",
55
+ "fileVersion": "0.0.0.0"
56
+ }
57
+ }
58
+ },
59
+ "PrettierSql.Core/1.0.0": {
60
+ "runtime": {
61
+ "PrettierSql.Core.dll": {
62
+ "assemblyVersion": "1.0.0.0",
63
+ "fileVersion": "1.0.0.0"
64
+ }
65
+ }
66
+ }
67
+ }
68
+ },
69
+ "libraries": {
70
+ "PgScriptDom/1.0.0": {
71
+ "type": "project",
72
+ "serviceable": false,
73
+ "sha512": ""
74
+ },
75
+ "Google.Protobuf/3.33.0": {
76
+ "type": "package",
77
+ "serviceable": true,
78
+ "sha512": "sha512-+kIa03YipuiSDeRuZwcDcXS1xBQAFeGLIjuLbgJr2i+TlwBPYAqdnQZJ2SDVzIgDyy+q+n/400WyWyrJ5ZqCgQ==",
79
+ "path": "google.protobuf/3.33.0",
80
+ "hashPath": "google.protobuf.3.33.0.nupkg.sha512"
81
+ },
82
+ "pgsqlparser/1.0.0": {
83
+ "type": "package",
84
+ "serviceable": true,
85
+ "sha512": "sha512-7WHTeB7dFrF1TDqNowsN6SE1pX5UBWxIsdycz7XnWK0yMM70NaAuFFZAYFedfgDPF+COfrGBArgkTuPj3ClR1w==",
86
+ "path": "pgsqlparser/1.0.0",
87
+ "hashPath": "pgsqlparser.1.0.0.nupkg.sha512"
88
+ },
89
+ "PrettierSql.Core/1.0.0": {
90
+ "type": "project",
91
+ "serviceable": false,
92
+ "sha512": ""
93
+ }
94
+ }
95
+ }
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from 'prettier';
2
+ import type { SqlNode } from '@prettier-sql/core/types';
3
+ declare const plugin: Plugin<SqlNode>;
4
+ export default plugin;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/plugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAMxD,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,OAAO,CAc3B,CAAC;AAEF,eAAe,MAAM,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ import { languages } from './language.js';
2
+ import { options } from '@prettier-sql/core/options';
3
+ import { parse, locStart, locEnd } from './parser/index.js';
4
+ import { printer } from './printer/index.js';
5
+ const plugin = {
6
+ languages,
7
+ parsers: {
8
+ pgsql: {
9
+ parse,
10
+ astFormat: 'pgsql-ast',
11
+ locStart,
12
+ locEnd,
13
+ },
14
+ },
15
+ printers: {
16
+ 'pgsql-ast': printer,
17
+ },
18
+ options,
19
+ };
20
+ export default plugin;
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/plugin/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,MAAM,MAAM,GAAoB;IAC5B,SAAS;IACT,OAAO,EAAE;QACL,KAAK,EAAE;YACH,KAAK;YACL,SAAS,EAAE,WAAW;YACtB,QAAQ;YACR,MAAM;SACT;KACJ;IACD,QAAQ,EAAE;QACN,WAAW,EAAE,OAAO;KACvB;IACD,OAAO;CACV,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { SupportLanguage } from 'prettier';
2
+ export declare const languages: SupportLanguage[];
3
+ //# sourceMappingURL=language.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"language.d.ts","sourceRoot":"","sources":["../src/plugin/language.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD,eAAO,MAAM,SAAS,EAAE,eAAe,EAOtC,CAAC"}
@@ -0,0 +1,9 @@
1
+ export const languages = [
2
+ {
3
+ name: 'PostgreSQL',
4
+ parsers: ['pgsql'],
5
+ extensions: ['.sql', '.pgsql'],
6
+ vscodeLanguageIds: ['sql'],
7
+ },
8
+ ];
9
+ //# sourceMappingURL=language.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"language.js","sourceRoot":"","sources":["../src/plugin/language.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAsB;IACxC;QACI,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,CAAC,OAAO,CAAC;QAClB,UAAU,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;QAC9B,iBAAiB,EAAE,CAAC,KAAK,CAAC;KAC7B;CACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { SqlNode } from '@prettier-sql/core/types';
2
+ export declare function parse(text: string): SqlNode;
3
+ export declare function locStart(node: SqlNode): number;
4
+ export declare function locEnd(node: SqlNode): number;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/parser/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,0BAA0B,CAAC;AAuBtE,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAsB3C;AA8BD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAE9C;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAE5C"}
@@ -0,0 +1,58 @@
1
+ import { loadDotnetDll } from '@prettier-sql/core/parser';
2
+ let dotnetModule = null;
3
+ function loadDotnet() {
4
+ if (dotnetModule)
5
+ return dotnetModule;
6
+ dotnetModule = loadDotnetDll(import.meta.url, 'PgScriptDom.dll', 'prettier-plugin-postgresql');
7
+ return dotnetModule;
8
+ }
9
+ // ---------------------------------------------------------------------------
10
+ // Public parse entry point
11
+ // ---------------------------------------------------------------------------
12
+ export function parse(text) {
13
+ const { SqlParser } = loadDotnet().PrettierPgsql;
14
+ const result = JSON.parse(SqlParser.Parse(text));
15
+ if (result.errors?.length) {
16
+ const e = result.errors[0];
17
+ throw new SyntaxError(`PostgreSQL parse error at ${e.line}:${e.column}: ${e.message}`);
18
+ }
19
+ if (!result.ast) {
20
+ throw new Error('Parser returned no AST and no errors');
21
+ }
22
+ if (result.comments?.length) {
23
+ attachComments(result.ast, result.comments);
24
+ }
25
+ return result.ast;
26
+ }
27
+ // ---------------------------------------------------------------------------
28
+ // Comment attachment
29
+ // ---------------------------------------------------------------------------
30
+ function attachComments(ast, comments) {
31
+ const used = new Set();
32
+ const statements = (ast.props?.['statements'] ?? []);
33
+ for (const c of comments.sort((a, b) => a.startOffset - b.startOffset)) {
34
+ const target = statements.find((s) => s.endOffset >= c.endOffset);
35
+ if (target) {
36
+ target.leadingComments = target.leadingComments ?? [];
37
+ target.leadingComments.push(c.text);
38
+ used.add(c);
39
+ }
40
+ else {
41
+ const last = statements.at(-1);
42
+ if (last) {
43
+ last.trailingComment = last.trailingComment ? last.trailingComment + '\n' + c.text : c.text;
44
+ used.add(c);
45
+ }
46
+ }
47
+ }
48
+ }
49
+ // ---------------------------------------------------------------------------
50
+ // Prettier loc helpers
51
+ // ---------------------------------------------------------------------------
52
+ export function locStart(node) {
53
+ return node.startOffset;
54
+ }
55
+ export function locEnd(node) {
56
+ return node.endOffset;
57
+ }
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugin/parser/index.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,8 @@
1
+ import type { Doc } from 'prettier';
2
+ import type { SqlNode } from '@prettier-sql/core/types';
3
+ import type { Options } from '@prettier-sql/core/printer/utils';
4
+ type PrintFn = (node: SqlNode) => Doc;
5
+ export declare function printExpression(node: SqlNode, opts: Options, printNode: PrintFn): Doc;
6
+ export declare function printWindowDef(node: SqlNode, opts: Options, printNode: PrintFn): Doc;
7
+ export {};
8
+ //# sourceMappingURL=expressions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../../src/plugin/printer/expressions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAKhE,KAAK,OAAO,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,GAAG,CAAC;AAEtC,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,GAAG,GAAG,CAsDrF;AA4ID,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,GAAG,GAAG,CAiCpF"}