neon 2.47.0 → 3.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.
- package/README.md +54 -0
- package/dist/_shared/auth_selection.js +76 -79
- package/dist/_shared/credentials.js +166 -187
- package/dist/_shared/env-core/env.js +395 -0
- package/dist/_shared/env-core/reuse-secrets.js +179 -0
- package/dist/_shared/paths.js +129 -126
- package/dist/_shared/profiles.js +192 -242
- package/dist/_shared/secure_file.js +36 -38
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/analytics.js +163 -207
- package/dist/api.js +815 -758
- package/dist/auth.js +121 -141
- package/dist/auth_context.js +39 -53
- package/dist/cli.js +4 -7
- package/dist/commands/api.js +220 -250
- package/dist/commands/api_keys.js +251 -314
- package/dist/commands/auth.js +283 -328
- package/dist/commands/bootstrap.js +372 -437
- package/dist/commands/branches.js +304 -455
- package/dist/commands/bucket.js +374 -514
- package/dist/commands/checkout.js +213 -298
- package/dist/commands/config.js +575 -658
- package/dist/commands/connection_string.js +137 -165
- package/dist/commands/data_api.js +238 -260
- package/dist/commands/databases.js +67 -76
- package/dist/commands/deploy.js +31 -25
- package/dist/commands/dev.js +642 -681
- package/dist/commands/diff.js +156 -200
- package/dist/commands/env.js +243 -303
- package/dist/commands/functions.js +275 -341
- package/dist/commands/index.js +70 -65
- package/dist/commands/init.js +84 -119
- package/dist/commands/inspect.js +55 -55
- package/dist/commands/ip_allow.js +88 -120
- package/dist/commands/link.js +874 -1019
- package/dist/commands/logs.js +291 -0
- package/dist/commands/neon_auth.js +725 -933
- package/dist/commands/operations.js +34 -25
- package/dist/commands/orgs.js +28 -18
- package/dist/commands/profile.js +614 -845
- package/dist/commands/projects.js +313 -373
- package/dist/commands/psql.js +60 -58
- package/dist/commands/roles.js +55 -58
- package/dist/commands/schema_diff.js +87 -131
- package/dist/commands/set_context.js +34 -26
- package/dist/commands/snapshots.js +288 -413
- package/dist/commands/status.js +41 -37
- package/dist/commands/user.js +21 -10
- package/dist/commands/vpc_endpoints.js +85 -113
- package/dist/config.js +7 -6
- package/dist/config_format.js +50 -66
- package/dist/config_template.js +128 -157
- package/dist/context.js +183 -235
- package/dist/current_branch_fast_path.js +40 -49
- package/dist/dev/env.js +313 -394
- package/dist/dev/functions.js +54 -64
- package/dist/dev/inputs.js +46 -58
- package/dist/dev/runtime.js +135 -164
- package/dist/dev/websocket.js +766 -959
- package/dist/env.js +27 -33
- package/dist/env_file.js +118 -132
- package/dist/env_services.js +36 -38
- package/dist/errors.js +57 -68
- package/dist/functions_api.js +45 -43
- package/dist/help.js +189 -140
- package/dist/index.js +182 -257
- package/dist/init/agents.js +137 -118
- package/dist/init/auth.js +58 -68
- package/dist/init/bootstrap.js +325 -396
- package/dist/init/build_config.js +4 -2
- package/dist/init/detect_agent.js +56 -101
- package/dist/init/editors.js +35 -52
- package/dist/init/enrich_output.js +51 -66
- package/dist/init/extension.js +134 -171
- package/dist/init/inspect.js +179 -266
- package/dist/init/interactive.js +510 -622
- package/dist/init/neonctl.js +117 -168
- package/dist/init/orchestrate.js +157 -173
- package/dist/init/phases/auth.js +188 -202
- package/dist/init/phases/cleanup.js +23 -23
- package/dist/init/phases/db.js +251 -277
- package/dist/init/phases/getting_started.js +213 -223
- package/dist/init/phases/mcp.js +174 -224
- package/dist/init/phases/migrations.js +247 -248
- package/dist/init/phases/neon_auth.js +114 -133
- package/dist/init/phases/setup.js +546 -703
- package/dist/init/phases/skills.js +75 -86
- package/dist/init/phases/status.js +72 -67
- package/dist/init/resolve_context.js +102 -99
- package/dist/init/route_command.js +91 -98
- package/dist/init/skills.js +174 -218
- package/dist/init/vsix.js +77 -99
- package/dist/log.js +17 -16
- package/dist/neon_services.js +104 -129
- package/dist/parameters.gen.js +481 -471
- package/dist/pkg.js +17 -19
- package/dist/profile_keys.js +44 -47
- package/dist/psql/cli.js +44 -47
- package/dist/psql/command/cmd_cond.js +231 -406
- package/dist/psql/command/cmd_connect.js +557 -764
- package/dist/psql/command/cmd_copy.js +727 -983
- package/dist/psql/command/cmd_describe.js +1499 -1688
- package/dist/psql/command/cmd_format.js +733 -905
- package/dist/psql/command/cmd_io.js +1293 -2082
- package/dist/psql/command/cmd_lo.js +297 -359
- package/dist/psql/command/cmd_meta.js +727 -878
- package/dist/psql/command/cmd_misc.js +138 -172
- package/dist/psql/command/cmd_pipeline.js +547 -1099
- package/dist/psql/command/cmd_restrict.js +119 -155
- package/dist/psql/command/cmd_show.js +529 -688
- package/dist/psql/command/dispatch.js +261 -325
- package/dist/psql/command/inputQueue.js +35 -33
- package/dist/psql/command/shared.js +49 -63
- package/dist/psql/complete/filenames.js +90 -133
- package/dist/psql/complete/index.js +59 -97
- package/dist/psql/complete/matcher.js +236 -300
- package/dist/psql/complete/psqlVars.js +218 -223
- package/dist/psql/complete/queries.js +159 -177
- package/dist/psql/complete/rules.js +1493 -2299
- package/dist/psql/core/common.js +762 -1180
- package/dist/psql/core/help.js +456 -546
- package/dist/psql/core/mainloop.js +692 -1302
- package/dist/psql/core/prompt.js +391 -408
- package/dist/psql/core/settings.js +429 -644
- package/dist/psql/core/sqlHelp.js +480 -554
- package/dist/psql/core/startup.js +626 -815
- package/dist/psql/core/syncVars.js +67 -110
- package/dist/psql/core/variables.js +156 -278
- package/dist/psql/describe/formatters.js +884 -1285
- package/dist/psql/describe/processNamePattern.js +173 -260
- package/dist/psql/describe/queries.js +1368 -2403
- package/dist/psql/describe/versionGate.js +32 -41
- package/dist/psql/index.js +1414 -1927
- package/dist/psql/io/history.js +232 -271
- package/dist/psql/io/input.js +103 -108
- package/dist/psql/io/lineEditor/buffer.js +238 -319
- package/dist/psql/io/lineEditor/complete.js +135 -213
- package/dist/psql/io/lineEditor/filename.js +139 -148
- package/dist/psql/io/lineEditor/index.js +653 -870
- package/dist/psql/io/lineEditor/keymap.js +544 -702
- package/dist/psql/io/lineEditor/vt100.js +294 -341
- package/dist/psql/io/pgpass.js +158 -187
- package/dist/psql/io/pgservice.js +146 -183
- package/dist/psql/io/psqlrc.js +328 -403
- package/dist/psql/print/aligned.js +1020 -1683
- package/dist/psql/print/asciidoc.js +180 -214
- package/dist/psql/print/crosstab.js +281 -442
- package/dist/psql/print/csv.js +48 -70
- package/dist/psql/print/html.js +195 -226
- package/dist/psql/print/json.js +75 -88
- package/dist/psql/print/latex.js +291 -364
- package/dist/psql/print/pager.js +171 -242
- package/dist/psql/print/troff.js +194 -226
- package/dist/psql/print/unaligned.js +69 -95
- package/dist/psql/print/units.js +167 -169
- package/dist/psql/scanner/slash.js +428 -483
- package/dist/psql/scanner/sql.js +445 -889
- package/dist/psql/scanner/stringutils.js +309 -379
- package/dist/psql/types/index.js +2 -7
- package/dist/psql/types/scanner.js +25 -22
- package/dist/psql/wire/connection.js +2042 -2803
- package/dist/psql/wire/copy.js +84 -100
- package/dist/psql/wire/notify.js +39 -59
- package/dist/psql/wire/pipeline.js +305 -518
- package/dist/psql/wire/protocol.js +349 -417
- package/dist/psql/wire/sasl.js +180 -265
- package/dist/psql/wire/tls.js +400 -561
- package/dist/storage_api.js +115 -129
- package/dist/test_utils/fixtures.js +94 -113
- package/dist/test_utils/oauth_server.js +10 -7
- package/dist/test_utils/project_dir.js +33 -0
- package/dist/utils/ai_gateway_notice.js +131 -162
- package/dist/utils/api_enums.js +21 -28
- package/dist/utils/auth.js +10 -4
- package/dist/utils/branch_notice.js +20 -19
- package/dist/utils/branch_picker.js +83 -89
- package/dist/utils/cli_name.js +15 -12
- package/dist/utils/compute_units.js +20 -27
- package/dist/utils/config_diff.js +127 -158
- package/dist/utils/enrichers.js +95 -148
- package/dist/utils/esbuild.js +133 -147
- package/dist/utils/flags.js +35 -47
- package/dist/utils/formats.js +8 -15
- package/dist/utils/git_diff.js +69 -80
- package/dist/utils/inspect_db.js +101 -143
- package/dist/utils/inspect_queries.js +179 -142
- package/dist/utils/middlewares.js +37 -44
- package/dist/utils/openapi.js +87 -99
- package/dist/utils/package_manager.js +312 -110
- package/dist/utils/point_in_time.js +49 -53
- package/dist/utils/psql.js +89 -106
- package/dist/utils/service_picker.js +55 -58
- package/dist/utils/string.js +5 -5
- package/dist/utils/ui.js +38 -55
- package/dist/utils/write_sync.js +26 -35
- package/dist/utils/zip.js +4 -3
- package/dist/writer.js +67 -87
- package/package.json +9 -7
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Each template returns a single column of completion candidates and takes
|
|
5
|
-
* one parameter — the LIKE pattern (i.e. the user's partial prefix with a
|
|
6
|
-
* trailing `%`). We use `pg_catalog.quote_ident()` so identifiers that need
|
|
7
|
-
* quoting come back already wrapped in `"..."`.
|
|
8
|
-
*
|
|
9
|
-
* The templates are intentionally narrow: psql's upstream tab-complete uses
|
|
10
|
-
* elaborate `SchemaQuery` structs that synthesize visibility predicates
|
|
11
|
-
* (search-path awareness) at runtime. We trade that nuance for portability
|
|
12
|
-
* — these queries just `LIKE` against the system catalogs and let the user
|
|
13
|
-
* see everything they have access to, sorted alphabetically.
|
|
14
|
-
*
|
|
15
|
-
* Every query takes a single `$1` parameter (the LIKE pattern) and is
|
|
16
|
-
* capped at 1000 rows so a wildcard `%` doesn't dump entire databases.
|
|
17
|
-
*/
|
|
18
|
-
const LIMIT = 1000;
|
|
1
|
+
//#region src/psql/complete/queries.ts
|
|
2
|
+
const LIMIT = 1e3;
|
|
19
3
|
/** Tables (incl. partitioned tables). */
|
|
20
|
-
|
|
4
|
+
const Query_for_list_of_tables = `
|
|
21
5
|
SELECT pg_catalog.quote_ident(c.relname)
|
|
22
6
|
FROM pg_catalog.pg_class c
|
|
23
7
|
WHERE c.relkind IN ('r','p')
|
|
@@ -27,7 +11,7 @@ export const Query_for_list_of_tables = `
|
|
|
27
11
|
LIMIT ${LIMIT}
|
|
28
12
|
`;
|
|
29
13
|
/** Views. */
|
|
30
|
-
|
|
14
|
+
const Query_for_list_of_views = `
|
|
31
15
|
SELECT pg_catalog.quote_ident(c.relname)
|
|
32
16
|
FROM pg_catalog.pg_class c
|
|
33
17
|
WHERE c.relkind = 'v'
|
|
@@ -37,7 +21,7 @@ export const Query_for_list_of_views = `
|
|
|
37
21
|
LIMIT ${LIMIT}
|
|
38
22
|
`;
|
|
39
23
|
/** Materialized views. */
|
|
40
|
-
|
|
24
|
+
const Query_for_list_of_matviews = `
|
|
41
25
|
SELECT pg_catalog.quote_ident(c.relname)
|
|
42
26
|
FROM pg_catalog.pg_class c
|
|
43
27
|
WHERE c.relkind = 'm'
|
|
@@ -47,7 +31,7 @@ export const Query_for_list_of_matviews = `
|
|
|
47
31
|
LIMIT ${LIMIT}
|
|
48
32
|
`;
|
|
49
33
|
/** Sequences. */
|
|
50
|
-
|
|
34
|
+
const Query_for_list_of_sequences = `
|
|
51
35
|
SELECT pg_catalog.quote_ident(c.relname)
|
|
52
36
|
FROM pg_catalog.pg_class c
|
|
53
37
|
WHERE c.relkind = 'S'
|
|
@@ -57,7 +41,7 @@ export const Query_for_list_of_sequences = `
|
|
|
57
41
|
LIMIT ${LIMIT}
|
|
58
42
|
`;
|
|
59
43
|
/** Indexes. */
|
|
60
|
-
|
|
44
|
+
const Query_for_list_of_indexes = `
|
|
61
45
|
SELECT pg_catalog.quote_ident(c.relname)
|
|
62
46
|
FROM pg_catalog.pg_class c
|
|
63
47
|
WHERE c.relkind IN ('i','I')
|
|
@@ -67,7 +51,7 @@ export const Query_for_list_of_indexes = `
|
|
|
67
51
|
LIMIT ${LIMIT}
|
|
68
52
|
`;
|
|
69
53
|
/** Foreign tables. */
|
|
70
|
-
|
|
54
|
+
const Query_for_list_of_foreign_tables = `
|
|
71
55
|
SELECT pg_catalog.quote_ident(c.relname)
|
|
72
56
|
FROM pg_catalog.pg_class c
|
|
73
57
|
WHERE c.relkind = 'f'
|
|
@@ -77,7 +61,7 @@ export const Query_for_list_of_foreign_tables = `
|
|
|
77
61
|
LIMIT ${LIMIT}
|
|
78
62
|
`;
|
|
79
63
|
/** Any relation (tables, views, mviews, indexes, sequences, foreign tables). */
|
|
80
|
-
|
|
64
|
+
const Query_for_list_of_relations = `
|
|
81
65
|
SELECT pg_catalog.quote_ident(c.relname)
|
|
82
66
|
FROM pg_catalog.pg_class c
|
|
83
67
|
WHERE c.relkind IN ('r','v','m','S','f','p')
|
|
@@ -87,7 +71,7 @@ export const Query_for_list_of_relations = `
|
|
|
87
71
|
LIMIT ${LIMIT}
|
|
88
72
|
`;
|
|
89
73
|
/** Tables + views + matviews (what FROM/UPDATE/INSERT INTO accept). */
|
|
90
|
-
|
|
74
|
+
const Query_for_list_of_tables_views = `
|
|
91
75
|
SELECT pg_catalog.quote_ident(c.relname)
|
|
92
76
|
FROM pg_catalog.pg_class c
|
|
93
77
|
WHERE c.relkind IN ('r','v','m','p','f')
|
|
@@ -97,7 +81,7 @@ export const Query_for_list_of_tables_views = `
|
|
|
97
81
|
LIMIT ${LIMIT}
|
|
98
82
|
`;
|
|
99
83
|
/** Schemas. */
|
|
100
|
-
|
|
84
|
+
const Query_for_list_of_schemas = `
|
|
101
85
|
SELECT pg_catalog.quote_ident(nspname)
|
|
102
86
|
FROM pg_catalog.pg_namespace
|
|
103
87
|
WHERE nspname ILIKE $1
|
|
@@ -105,7 +89,7 @@ export const Query_for_list_of_schemas = `
|
|
|
105
89
|
LIMIT ${LIMIT}
|
|
106
90
|
`;
|
|
107
91
|
/** Functions (not procedures). */
|
|
108
|
-
|
|
92
|
+
const Query_for_list_of_functions = `
|
|
109
93
|
SELECT pg_catalog.quote_ident(p.proname)
|
|
110
94
|
FROM pg_catalog.pg_proc p
|
|
111
95
|
WHERE p.proname ILIKE $1
|
|
@@ -114,7 +98,7 @@ export const Query_for_list_of_functions = `
|
|
|
114
98
|
LIMIT ${LIMIT}
|
|
115
99
|
`;
|
|
116
100
|
/** Roles. */
|
|
117
|
-
|
|
101
|
+
const Query_for_list_of_roles = `
|
|
118
102
|
SELECT pg_catalog.quote_ident(rolname)
|
|
119
103
|
FROM pg_catalog.pg_roles
|
|
120
104
|
WHERE rolname ILIKE $1
|
|
@@ -122,7 +106,7 @@ export const Query_for_list_of_roles = `
|
|
|
122
106
|
LIMIT ${LIMIT}
|
|
123
107
|
`;
|
|
124
108
|
/** Extensions. */
|
|
125
|
-
|
|
109
|
+
const Query_for_list_of_extensions = `
|
|
126
110
|
SELECT pg_catalog.quote_ident(extname)
|
|
127
111
|
FROM pg_catalog.pg_extension
|
|
128
112
|
WHERE extname ILIKE $1
|
|
@@ -130,7 +114,7 @@ export const Query_for_list_of_extensions = `
|
|
|
130
114
|
LIMIT ${LIMIT}
|
|
131
115
|
`;
|
|
132
116
|
/** Available extensions (installable). */
|
|
133
|
-
|
|
117
|
+
const Query_for_list_of_available_extensions = `
|
|
134
118
|
SELECT pg_catalog.quote_ident(name)
|
|
135
119
|
FROM pg_catalog.pg_available_extensions
|
|
136
120
|
WHERE name ILIKE $1
|
|
@@ -138,7 +122,7 @@ export const Query_for_list_of_available_extensions = `
|
|
|
138
122
|
LIMIT ${LIMIT}
|
|
139
123
|
`;
|
|
140
124
|
/** Databases. */
|
|
141
|
-
|
|
125
|
+
const Query_for_list_of_databases = `
|
|
142
126
|
SELECT pg_catalog.quote_ident(datname)
|
|
143
127
|
FROM pg_catalog.pg_database
|
|
144
128
|
WHERE datname ILIKE $1
|
|
@@ -146,7 +130,7 @@ export const Query_for_list_of_databases = `
|
|
|
146
130
|
LIMIT ${LIMIT}
|
|
147
131
|
`;
|
|
148
132
|
/** Types. */
|
|
149
|
-
|
|
133
|
+
const Query_for_list_of_types = `
|
|
150
134
|
SELECT pg_catalog.quote_ident(t.typname)
|
|
151
135
|
FROM pg_catalog.pg_type t
|
|
152
136
|
WHERE (t.typrelid = 0 OR
|
|
@@ -158,7 +142,7 @@ export const Query_for_list_of_types = `
|
|
|
158
142
|
LIMIT ${LIMIT}
|
|
159
143
|
`;
|
|
160
144
|
/** Languages. */
|
|
161
|
-
|
|
145
|
+
const Query_for_list_of_languages = `
|
|
162
146
|
SELECT pg_catalog.quote_ident(lanname)
|
|
163
147
|
FROM pg_catalog.pg_language
|
|
164
148
|
WHERE lanname != 'internal'
|
|
@@ -167,7 +151,7 @@ export const Query_for_list_of_languages = `
|
|
|
167
151
|
LIMIT ${LIMIT}
|
|
168
152
|
`;
|
|
169
153
|
/** Tablespaces. */
|
|
170
|
-
|
|
154
|
+
const Query_for_list_of_tablespaces = `
|
|
171
155
|
SELECT pg_catalog.quote_ident(spcname)
|
|
172
156
|
FROM pg_catalog.pg_tablespace
|
|
173
157
|
WHERE spcname ILIKE $1
|
|
@@ -175,7 +159,7 @@ export const Query_for_list_of_tablespaces = `
|
|
|
175
159
|
LIMIT ${LIMIT}
|
|
176
160
|
`;
|
|
177
161
|
/** Operators. */
|
|
178
|
-
|
|
162
|
+
const Query_for_list_of_operators = `
|
|
179
163
|
SELECT pg_catalog.quote_ident(o.oprname)
|
|
180
164
|
FROM pg_catalog.pg_operator o
|
|
181
165
|
WHERE o.oprname ILIKE $1
|
|
@@ -184,7 +168,7 @@ export const Query_for_list_of_operators = `
|
|
|
184
168
|
LIMIT ${LIMIT}
|
|
185
169
|
`;
|
|
186
170
|
/** Casts (no quoting; format is "type AS type" — used rarely). */
|
|
187
|
-
|
|
171
|
+
const Query_for_list_of_casts = `
|
|
188
172
|
SELECT pg_catalog.format_type(castsource, NULL)
|
|
189
173
|
|| ' AS '
|
|
190
174
|
|| pg_catalog.format_type(casttarget, NULL) AS cast
|
|
@@ -196,7 +180,7 @@ export const Query_for_list_of_casts = `
|
|
|
196
180
|
LIMIT ${LIMIT}
|
|
197
181
|
`;
|
|
198
182
|
/** Configuration parameter (GUC) names — `pg_settings`. */
|
|
199
|
-
|
|
183
|
+
const Query_for_list_of_set_vars = `
|
|
200
184
|
SELECT pg_catalog.lower(name)
|
|
201
185
|
FROM pg_catalog.pg_settings
|
|
202
186
|
WHERE name ILIKE $1
|
|
@@ -204,18 +188,18 @@ export const Query_for_list_of_set_vars = `
|
|
|
204
188
|
LIMIT ${LIMIT}
|
|
205
189
|
`;
|
|
206
190
|
/**
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
191
|
+
* Allowed values of an enum-typed GUC — `pg_settings.enumvals`.
|
|
192
|
+
*
|
|
193
|
+
* The GUC name is the first parameter (matched case-insensitively against
|
|
194
|
+
* `pg_settings.name`, since names like `IntervalStyle` appear mixed-case in
|
|
195
|
+
* the catalog but are addressed in lowercase from user input). The ILIKE
|
|
196
|
+
* prefix on the unnested values is the trailing parameter.
|
|
197
|
+
*
|
|
198
|
+
* Mirrors upstream `tab-complete.in.c`'s `Query_for_values_of_enum_GUC`. The
|
|
199
|
+
* catalog stores enum values in lowercase (e.g. `iso_8601`, `use_column`),
|
|
200
|
+
* which matches how `SET <name> TO <value>` expects them.
|
|
201
|
+
*/
|
|
202
|
+
const Query_for_values_of_enum_GUC = `
|
|
219
203
|
SELECT val
|
|
220
204
|
FROM (
|
|
221
205
|
SELECT pg_catalog.unnest(enumvals) AS val
|
|
@@ -228,7 +212,7 @@ export const Query_for_values_of_enum_GUC = `
|
|
|
228
212
|
LIMIT ${LIMIT}
|
|
229
213
|
`;
|
|
230
214
|
/** Access methods (index AMs primarily). */
|
|
231
|
-
|
|
215
|
+
const Query_for_list_of_access_methods = `
|
|
232
216
|
SELECT pg_catalog.quote_ident(amname)
|
|
233
217
|
FROM pg_catalog.pg_am
|
|
234
218
|
WHERE amname ILIKE $1
|
|
@@ -236,7 +220,7 @@ export const Query_for_list_of_access_methods = `
|
|
|
236
220
|
LIMIT ${LIMIT}
|
|
237
221
|
`;
|
|
238
222
|
/** Index access methods only (`amtype = 'i'`). */
|
|
239
|
-
|
|
223
|
+
const Query_for_list_of_index_access_methods = `
|
|
240
224
|
SELECT pg_catalog.quote_ident(amname)
|
|
241
225
|
FROM pg_catalog.pg_am
|
|
242
226
|
WHERE amname ILIKE $1
|
|
@@ -245,7 +229,7 @@ export const Query_for_list_of_index_access_methods = `
|
|
|
245
229
|
LIMIT ${LIMIT}
|
|
246
230
|
`;
|
|
247
231
|
/** Built-in type names — for CREATE TABLE column-type completion. */
|
|
248
|
-
|
|
232
|
+
const Query_for_list_of_datatypes = `
|
|
249
233
|
SELECT pg_catalog.format_type(t.oid, NULL)
|
|
250
234
|
FROM pg_catalog.pg_type t
|
|
251
235
|
WHERE (t.typrelid = 0 OR
|
|
@@ -260,7 +244,7 @@ export const Query_for_list_of_datatypes = `
|
|
|
260
244
|
LIMIT ${LIMIT}
|
|
261
245
|
`;
|
|
262
246
|
/** Publications. */
|
|
263
|
-
|
|
247
|
+
const Query_for_list_of_publications = `
|
|
264
248
|
SELECT pg_catalog.quote_ident(pubname)
|
|
265
249
|
FROM pg_catalog.pg_publication
|
|
266
250
|
WHERE pubname ILIKE $1
|
|
@@ -268,7 +252,7 @@ export const Query_for_list_of_publications = `
|
|
|
268
252
|
LIMIT ${LIMIT}
|
|
269
253
|
`;
|
|
270
254
|
/** Subscriptions. */
|
|
271
|
-
|
|
255
|
+
const Query_for_list_of_subscriptions = `
|
|
272
256
|
SELECT pg_catalog.quote_ident(subname)
|
|
273
257
|
FROM pg_catalog.pg_subscription
|
|
274
258
|
WHERE subname ILIKE $1
|
|
@@ -276,17 +260,17 @@ export const Query_for_list_of_subscriptions = `
|
|
|
276
260
|
LIMIT ${LIMIT}
|
|
277
261
|
`;
|
|
278
262
|
/**
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
263
|
+
* Relations qualified by an explicit schema. The caller passes the schema
|
|
264
|
+
* name as $1 and the ILIKE prefix as $2 — this lets `SELECT * FROM pg_catalog.x`
|
|
265
|
+
* complete to `pg_catalog.xxxx`. The schema name is matched
|
|
266
|
+
* case-insensitively so `PUBLIC.t` resolves to relations in `public`.
|
|
267
|
+
*
|
|
268
|
+
* Note: deliberately excludes `relkind = 'i'` (indexes) so that
|
|
269
|
+
* `SELECT * FROM public.tab<tab>` doesn't include `tab1_pkey` alongside
|
|
270
|
+
* `tab1`. Index-qualifying completions (REINDEX, DROP INDEX, ALTER INDEX)
|
|
271
|
+
* have their own table-kind queries and don't route through this helper.
|
|
272
|
+
*/
|
|
273
|
+
const Query_for_list_of_relations_in_schema = `
|
|
290
274
|
SELECT pg_catalog.quote_ident(c.relname)
|
|
291
275
|
FROM pg_catalog.pg_class c
|
|
292
276
|
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
|
|
@@ -297,20 +281,20 @@ export const Query_for_list_of_relations_in_schema = `
|
|
|
297
281
|
LIMIT ${LIMIT}
|
|
298
282
|
`;
|
|
299
283
|
/**
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
284
|
+
* Constraint names attached to a referenced table. Mirrors upstream's
|
|
285
|
+
* `Query_for_constraint_of_table` (tab-complete.in.c ~line 453), which
|
|
286
|
+
* joins `pg_constraint` to `pg_class` via `conrelid` and filters by the
|
|
287
|
+
* referenced table name.
|
|
288
|
+
*
|
|
289
|
+
* Caller passes `[refName]` (the table the user typed between
|
|
290
|
+
* `ALTER TABLE` and `DROP CONSTRAINT`, already case-folded for unquoted
|
|
291
|
+
* input — see `parseTableRef` in rules.ts) and the ILIKE prefix.
|
|
292
|
+
*
|
|
293
|
+
* Visibility is checked via `pg_table_is_visible(c.oid)` so the user's
|
|
294
|
+
* `search_path` controls which schema's `tab1` is matched when the user
|
|
295
|
+
* gives an unqualified reference.
|
|
296
|
+
*/
|
|
297
|
+
const Query_for_constraint_of_table = `
|
|
314
298
|
SELECT pg_catalog.quote_ident(con.conname)
|
|
315
299
|
FROM pg_catalog.pg_constraint con, pg_catalog.pg_class c
|
|
316
300
|
WHERE con.conrelid = c.oid
|
|
@@ -321,16 +305,16 @@ export const Query_for_constraint_of_table = `
|
|
|
321
305
|
LIMIT ${LIMIT}
|
|
322
306
|
`;
|
|
323
307
|
/**
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
308
|
+
* Constraint names attached to a referenced table within a specific
|
|
309
|
+
* schema. Used when the user qualified the reference, e.g.
|
|
310
|
+
* `ALTER TABLE public."tab1" DROP CONSTRAINT t<TAB>`. The schema name is
|
|
311
|
+
* matched case-insensitively against `pg_namespace.nspname` so
|
|
312
|
+
* `PUBLIC.tab1` still resolves to constraints in the `public` schema.
|
|
313
|
+
*
|
|
314
|
+
* Caller passes `[schema, refName]` (with `refName` already case-folded
|
|
315
|
+
* for the unquoted form), and the ILIKE prefix as the trailing parameter.
|
|
316
|
+
*/
|
|
317
|
+
const Query_for_constraint_of_table_in_schema = `
|
|
334
318
|
SELECT pg_catalog.quote_ident(con.conname)
|
|
335
319
|
FROM pg_catalog.pg_constraint con
|
|
336
320
|
JOIN pg_catalog.pg_class c ON con.conrelid = c.oid
|
|
@@ -342,20 +326,20 @@ export const Query_for_constraint_of_table_in_schema = `
|
|
|
342
326
|
LIMIT ${LIMIT}
|
|
343
327
|
`;
|
|
344
328
|
/**
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
329
|
+
* Tables (regular + partitioned) that have a constraint with the given
|
|
330
|
+
* name. The reverse direction of `Query_for_constraint_of_table` — used by
|
|
331
|
+
* the `COMMENT ON CONSTRAINT <name> ON <prefix>` completion to resolve the
|
|
332
|
+
* relation that owns the named constraint.
|
|
333
|
+
*
|
|
334
|
+
* Caller passes `[constraintName]`, then the ILIKE prefix on the relname.
|
|
335
|
+
* Mirrors upstream's `Query_for_list_of_tables_for_constraint` SchemaQuery
|
|
336
|
+
* (tab-complete.in.c ~line 694), which uses
|
|
337
|
+
* `selcondition = "c.oid=con.conrelid and c.relkind IN ('r','p')"` and
|
|
338
|
+
* `refname = "con.conname"`. The `quote_ident()` wrapper ensures
|
|
339
|
+
* names that need quoting (mixed case, reserved words) come back in a
|
|
340
|
+
* paste-safe form.
|
|
341
|
+
*/
|
|
342
|
+
const Query_for_list_of_tables_for_constraint = `
|
|
359
343
|
SELECT DISTINCT pg_catalog.quote_ident(c.relname)
|
|
360
344
|
FROM pg_catalog.pg_class c, pg_catalog.pg_constraint con
|
|
361
345
|
WHERE c.oid = con.conrelid
|
|
@@ -367,14 +351,14 @@ export const Query_for_list_of_tables_for_constraint = `
|
|
|
367
351
|
LIMIT ${LIMIT}
|
|
368
352
|
`;
|
|
369
353
|
/**
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
354
|
+
* Same as `Query_for_list_of_tables_for_constraint` but scoped to a
|
|
355
|
+
* specific schema (so `COMMENT ON CONSTRAINT foo ON public.<TAB>` only
|
|
356
|
+
* shows relations in `public`).
|
|
357
|
+
*
|
|
358
|
+
* Caller passes `[constraintName, schema]`, then the ILIKE prefix. Schema
|
|
359
|
+
* is matched case-insensitively to handle `PUBLIC.<TAB>` → `public.*`.
|
|
360
|
+
*/
|
|
361
|
+
const Query_for_list_of_tables_for_constraint_in_schema = `
|
|
378
362
|
SELECT DISTINCT pg_catalog.quote_ident(c.relname)
|
|
379
363
|
FROM pg_catalog.pg_class c
|
|
380
364
|
JOIN pg_catalog.pg_constraint con ON c.oid = con.conrelid
|
|
@@ -387,19 +371,19 @@ export const Query_for_list_of_tables_for_constraint_in_schema = `
|
|
|
387
371
|
LIMIT ${LIMIT}
|
|
388
372
|
`;
|
|
389
373
|
/**
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
374
|
+
* Enum label values for the named enum type. Mirrors upstream's
|
|
375
|
+
* `Query_for_list_of_enum_values_quoted` / `…_unquoted` (tab-complete.in.c
|
|
376
|
+
* ~line 602-618), with a parameter-bound type name in place of upstream's
|
|
377
|
+
* `set_completion_reference()` macro state.
|
|
378
|
+
*
|
|
379
|
+
* The caller picks the variant based on whether the user is mid-string-
|
|
380
|
+
* literal (current word starts with `'`), and passes `[typeName]` along
|
|
381
|
+
* with the ILIKE prefix as the trailing parameter. The quoted variant
|
|
382
|
+
* uses `quote_literal` so candidates come back as `'BLACK'` rather than
|
|
383
|
+
* bare `BLACK`, and the case-sensitive `enumlabel LIKE` ensures upstream
|
|
384
|
+
* parity for tests like `RENAME VALUE 'B<TAB>` → `'BLACK'`.
|
|
385
|
+
*/
|
|
386
|
+
const Query_for_list_of_enum_values_quoted = `
|
|
403
387
|
SELECT pg_catalog.quote_literal(e.enumlabel)
|
|
404
388
|
FROM pg_catalog.pg_enum e, pg_catalog.pg_type t
|
|
405
389
|
WHERE t.oid = e.enumtypid
|
|
@@ -409,7 +393,7 @@ export const Query_for_list_of_enum_values_quoted = `
|
|
|
409
393
|
ORDER BY 1
|
|
410
394
|
LIMIT ${LIMIT}
|
|
411
395
|
`;
|
|
412
|
-
|
|
396
|
+
const Query_for_list_of_enum_values_unquoted = `
|
|
413
397
|
SELECT e.enumlabel
|
|
414
398
|
FROM pg_catalog.pg_enum e, pg_catalog.pg_type t
|
|
415
399
|
WHERE t.oid = e.enumtypid
|
|
@@ -420,44 +404,44 @@ export const Query_for_list_of_enum_values_unquoted = `
|
|
|
420
404
|
LIMIT ${LIMIT}
|
|
421
405
|
`;
|
|
422
406
|
/**
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
407
|
+
* Timezone names from `pg_timezone_names()`. Three variants mirror
|
|
408
|
+
* upstream's `COMPLETE_WITH_TIMEZONE_NAME()` macro (tab-complete.in.c
|
|
409
|
+
* ~line 1160-1173) — different result shapes for the three contexts:
|
|
410
|
+
*
|
|
411
|
+
* - `…_unquoted` emits the bare name `America/New_York`. Used when
|
|
412
|
+
* the cursor is already inside an opened single-
|
|
413
|
+
* quoted string (`SET timezone TO 'America/New_<TAB>`),
|
|
414
|
+
* so the editor inserts the rest of the name and the
|
|
415
|
+
* closing quote.
|
|
416
|
+
* - `…_quoted_out` emits the candidate wrapped in single quotes —
|
|
417
|
+
* `'America/New_York'`. Used when the user hasn't
|
|
418
|
+
* typed any quote yet (`SET timezone TO am<TAB>` →
|
|
419
|
+
* `'America/`).
|
|
420
|
+
* - `…_quoted_in` emits the quoted form AND matches the quoted form
|
|
421
|
+
* against the LIKE pattern. Used when the user's
|
|
422
|
+
* partial word itself starts with `'` (so we feed
|
|
423
|
+
* `'am%` to the LIKE), so the editor can complete
|
|
424
|
+
* from inside the literal.
|
|
425
|
+
*
|
|
426
|
+
* All three are case-insensitive on the name (lower(name) LIKE lower(pat))
|
|
427
|
+
* because IANA names like `America/New_York` mix case but should still
|
|
428
|
+
* match a lowercase prefix.
|
|
429
|
+
*/
|
|
430
|
+
const Query_for_list_of_timezone_names_unquoted = `
|
|
447
431
|
SELECT name
|
|
448
432
|
FROM pg_catalog.pg_timezone_names()
|
|
449
433
|
WHERE pg_catalog.lower(name) LIKE pg_catalog.lower($1)
|
|
450
434
|
ORDER BY 1
|
|
451
435
|
LIMIT ${LIMIT}
|
|
452
436
|
`;
|
|
453
|
-
|
|
437
|
+
const Query_for_list_of_timezone_names_quoted_out = `
|
|
454
438
|
SELECT pg_catalog.quote_literal(name) AS name
|
|
455
439
|
FROM pg_catalog.pg_timezone_names()
|
|
456
440
|
WHERE pg_catalog.lower(name) LIKE pg_catalog.lower($1)
|
|
457
441
|
ORDER BY 1
|
|
458
442
|
LIMIT ${LIMIT}
|
|
459
443
|
`;
|
|
460
|
-
|
|
444
|
+
const Query_for_list_of_timezone_names_quoted_in = `
|
|
461
445
|
SELECT pg_catalog.quote_literal(name) AS name
|
|
462
446
|
FROM pg_catalog.pg_timezone_names()
|
|
463
447
|
WHERE pg_catalog.quote_literal(pg_catalog.lower(name)) LIKE pg_catalog.lower($1)
|
|
@@ -465,29 +449,27 @@ export const Query_for_list_of_timezone_names_quoted_in = `
|
|
|
465
449
|
LIMIT ${LIMIT}
|
|
466
450
|
`;
|
|
467
451
|
/**
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
}
|
|
490
|
-
catch {
|
|
491
|
-
return [];
|
|
492
|
-
}
|
|
452
|
+
* Run one of the templates above against a connection and return the
|
|
453
|
+
* single-column results as a string array. Empty array on any error so the
|
|
454
|
+
* completer degrades gracefully — a flaky catalog query shouldn't crash the
|
|
455
|
+
* REPL.
|
|
456
|
+
*
|
|
457
|
+
* `pattern` is the user's partial input; we append `%` automatically.
|
|
458
|
+
*/
|
|
459
|
+
const runCatalogQuery = async (conn, sql, pattern, extraParams = []) => {
|
|
460
|
+
try {
|
|
461
|
+
const likePattern = pattern + "%";
|
|
462
|
+
const params = extraParams.length > 0 ? [...extraParams, likePattern] : [likePattern];
|
|
463
|
+
const rs = await conn.query(sql, params);
|
|
464
|
+
const out = [];
|
|
465
|
+
for (const row of rs.rows) {
|
|
466
|
+
const v = row[0];
|
|
467
|
+
if (typeof v === "string") out.push(v);
|
|
468
|
+
}
|
|
469
|
+
return out;
|
|
470
|
+
} catch {
|
|
471
|
+
return [];
|
|
472
|
+
}
|
|
493
473
|
};
|
|
474
|
+
//#endregion
|
|
475
|
+
export { Query_for_constraint_of_table, Query_for_constraint_of_table_in_schema, Query_for_list_of_access_methods, Query_for_list_of_available_extensions, Query_for_list_of_casts, Query_for_list_of_databases, Query_for_list_of_datatypes, Query_for_list_of_enum_values_quoted, Query_for_list_of_enum_values_unquoted, Query_for_list_of_extensions, Query_for_list_of_foreign_tables, Query_for_list_of_functions, Query_for_list_of_index_access_methods, Query_for_list_of_indexes, Query_for_list_of_languages, Query_for_list_of_matviews, Query_for_list_of_operators, Query_for_list_of_publications, Query_for_list_of_relations, Query_for_list_of_relations_in_schema, Query_for_list_of_roles, Query_for_list_of_schemas, Query_for_list_of_sequences, Query_for_list_of_set_vars, Query_for_list_of_subscriptions, Query_for_list_of_tables, Query_for_list_of_tables_for_constraint, Query_for_list_of_tables_for_constraint_in_schema, Query_for_list_of_tables_views, Query_for_list_of_tablespaces, Query_for_list_of_timezone_names_quoted_in, Query_for_list_of_timezone_names_quoted_out, Query_for_list_of_timezone_names_unquoted, Query_for_list_of_types, Query_for_list_of_views, Query_for_values_of_enum_GUC, runCatalogQuery };
|