neonctl 2.22.2 → 2.23.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 +84 -0
- package/analytics.js +5 -2
- package/commands/branches.js +9 -1
- package/commands/connection_string.js +9 -1
- package/commands/functions.js +277 -0
- package/commands/index.js +4 -0
- package/commands/neon_auth.js +1013 -0
- package/commands/projects.js +9 -1
- package/commands/psql.js +6 -1
- package/functions_api.js +44 -0
- package/package.json +15 -5
- package/psql/cli.js +51 -0
- package/psql/command/cmd_cond.js +437 -0
- package/psql/command/cmd_connect.js +815 -0
- package/psql/command/cmd_copy.js +1025 -0
- package/psql/command/cmd_describe.js +1810 -0
- package/psql/command/cmd_format.js +909 -0
- package/psql/command/cmd_io.js +2187 -0
- package/psql/command/cmd_lo.js +385 -0
- package/psql/command/cmd_meta.js +970 -0
- package/psql/command/cmd_misc.js +187 -0
- package/psql/command/cmd_pipeline.js +1141 -0
- package/psql/command/cmd_restrict.js +171 -0
- package/psql/command/cmd_show.js +751 -0
- package/psql/command/dispatch.js +343 -0
- package/psql/command/inputQueue.js +42 -0
- package/psql/command/shared.js +71 -0
- package/psql/complete/filenames.js +139 -0
- package/psql/complete/index.js +104 -0
- package/psql/complete/matcher.js +314 -0
- package/psql/complete/psqlVars.js +247 -0
- package/psql/complete/queries.js +491 -0
- package/psql/complete/rules.js +2387 -0
- package/psql/core/common.js +1250 -0
- package/psql/core/help.js +576 -0
- package/psql/core/mainloop.js +1353 -0
- package/psql/core/prompt.js +437 -0
- package/psql/core/settings.js +684 -0
- package/psql/core/sqlHelp.js +1066 -0
- package/psql/core/startup.js +840 -0
- package/psql/core/syncVars.js +116 -0
- package/psql/core/variables.js +287 -0
- package/psql/describe/formatters.js +1277 -0
- package/psql/describe/processNamePattern.js +270 -0
- package/psql/describe/queries.js +2373 -0
- package/psql/describe/versionGate.js +43 -0
- package/psql/index.js +2005 -0
- package/psql/io/history.js +299 -0
- package/psql/io/input.js +120 -0
- package/psql/io/lineEditor/buffer.js +323 -0
- package/psql/io/lineEditor/complete.js +227 -0
- package/psql/io/lineEditor/filename.js +159 -0
- package/psql/io/lineEditor/index.js +891 -0
- package/psql/io/lineEditor/keymap.js +738 -0
- package/psql/io/lineEditor/vt100.js +363 -0
- package/psql/io/pgpass.js +202 -0
- package/psql/io/pgservice.js +194 -0
- package/psql/io/psqlrc.js +422 -0
- package/psql/print/aligned.js +1756 -0
- package/psql/print/asciidoc.js +248 -0
- package/psql/print/crosstab.js +460 -0
- package/psql/print/csv.js +92 -0
- package/psql/print/html.js +258 -0
- package/psql/print/json.js +96 -0
- package/psql/print/latex.js +396 -0
- package/psql/print/pager.js +265 -0
- package/psql/print/troff.js +258 -0
- package/psql/print/unaligned.js +118 -0
- package/psql/print/units.js +135 -0
- package/psql/scanner/slash.js +513 -0
- package/psql/scanner/sql.js +910 -0
- package/psql/scanner/stringutils.js +390 -0
- package/psql/types/backslash.js +1 -0
- package/psql/types/connection.js +1 -0
- package/psql/types/index.js +7 -0
- package/psql/types/printer.js +1 -0
- package/psql/types/repl.js +1 -0
- package/psql/types/scanner.js +24 -0
- package/psql/types/settings.js +1 -0
- package/psql/types/variables.js +1 -0
- package/psql/wire/connection.js +2844 -0
- package/psql/wire/copy.js +108 -0
- package/psql/wire/notify.js +59 -0
- package/psql/wire/pipeline.js +519 -0
- package/psql/wire/protocol.js +466 -0
- package/psql/wire/sasl.js +296 -0
- package/psql/wire/tls.js +596 -0
- package/test_utils/fixtures.js +1 -0
- package/utils/esbuild.js +147 -0
- package/utils/psql.js +107 -11
- package/utils/zip.js +4 -0
- package/writer.js +1 -1
- package/commands/auth.test.js +0 -211
- package/commands/branches.test.js +0 -460
- package/commands/checkout.test.js +0 -170
- package/commands/connection_string.test.js +0 -196
- package/commands/data_api.test.js +0 -169
- package/commands/databases.test.js +0 -39
- package/commands/help.test.js +0 -9
- package/commands/init.test.js +0 -56
- package/commands/ip_allow.test.js +0 -59
- package/commands/link.test.js +0 -381
- package/commands/operations.test.js +0 -7
- package/commands/orgs.test.js +0 -7
- package/commands/projects.test.js +0 -144
- package/commands/psql.test.js +0 -49
- package/commands/roles.test.js +0 -37
- package/commands/set_context.test.js +0 -159
- package/commands/vpc_endpoints.test.js +0 -69
- package/context.test.js +0 -119
- package/env.test.js +0 -55
- package/utils/formats.test.js +0 -32
- package/writer.test.js +0 -104
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Port of upstream `processSQLNamePattern()` from
|
|
3
|
+
* `src/fe_utils/string_utils.c`.
|
|
4
|
+
*
|
|
5
|
+
* psql's `\d*` commands accept shell-style name patterns of the form
|
|
6
|
+
* `[db.][schema.]name`. Each component supports `*` and `?` wildcards;
|
|
7
|
+
* components may be double-quoted to preserve case and treat regex
|
|
8
|
+
* metacharacters literally. This routine parses the pattern into one or
|
|
9
|
+
* more regex strings (one per dotted component) and emits the SQL
|
|
10
|
+
* conditions that constrain the relevant catalog columns.
|
|
11
|
+
*
|
|
12
|
+
* The upstream entry point writes directly into a `PQExpBuffer`; we
|
|
13
|
+
* return a structured {@link NamePatternResult} instead, leaving the
|
|
14
|
+
* actual splicing to the caller (see `applyPattern` in `formatters.ts`).
|
|
15
|
+
*
|
|
16
|
+
* Differences from the C version:
|
|
17
|
+
*
|
|
18
|
+
* - We don't have a `PGconn` so we can't issue `appendStringLiteralConn`
|
|
19
|
+
* or read `PQclientEncoding`. The regex strings are emitted as plain
|
|
20
|
+
* JS strings; the caller is expected to bind them via `$N` parameters
|
|
21
|
+
* to the prepared query. (Upstream inlines them as quoted SQL literals
|
|
22
|
+
* because libpq doesn't have a generic parameter-binding API for
|
|
23
|
+
* `psql`'s simple-query queries.) Binding via params is strictly
|
|
24
|
+
* safer and arguably more faithful to the *intent* of the C code.
|
|
25
|
+
* - `force_escape` is exposed as `forceLower` (Mac/Linux psql default
|
|
26
|
+
* is `force_escape = false`; we still always lowercase outside
|
|
27
|
+
* quotes because that's the documented psql user model).
|
|
28
|
+
* - The `dotcnt` output is implicit: callers can inspect
|
|
29
|
+
* `result.schemaConditions.length + result.nameConditions.length` if
|
|
30
|
+
* needed.
|
|
31
|
+
* - The `COLLATE pg_catalog.default` suffix that upstream emits for
|
|
32
|
+
* PG >= 12 is omitted; our regex parameters are bound as text and the
|
|
33
|
+
* server applies the default collation already. (If a follow-up WP
|
|
34
|
+
* discovers a real divergence we can revisit.)
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Lower-case ASCII letters. Mirrors upstream's `pg_tolower` for the
|
|
38
|
+
* ASCII range — we don't need full locale folding because catalog
|
|
39
|
+
* identifiers are stored as-typed and case-folding only happens for
|
|
40
|
+
* unquoted user input (which is restricted to lower-case anyway).
|
|
41
|
+
*/
|
|
42
|
+
const toLower = (ch) => ch >= 'A' && ch <= 'Z' ? String.fromCharCode(ch.charCodeAt(0) + 32) : ch;
|
|
43
|
+
const REGEX_SPECIALS = '|*+?()[]{}.^$\\';
|
|
44
|
+
/**
|
|
45
|
+
* Translate a shell-style pattern into one or more regex strings, one
|
|
46
|
+
* per `.`-separated component. Mirrors upstream `patternToSQLRegex()`.
|
|
47
|
+
*
|
|
48
|
+
* Component layout: callers requesting both schema and db split keep
|
|
49
|
+
* receiving regexes for `name`, `schema`, `db` in that *reverse* order
|
|
50
|
+
* (matching the upstream buffer-rotation trick). We expose the regexes
|
|
51
|
+
* in name-first order; the caller maps slots to columns.
|
|
52
|
+
*/
|
|
53
|
+
const patternToSQLRegex = (pattern, forceLower, wantSchema, wantDb) => {
|
|
54
|
+
// Whenever a schema column exists, accept up to 3 dotted components
|
|
55
|
+
// (`db.schema.name`) — NOT 2. Capping at 2 made `\d mydb.public.users`
|
|
56
|
+
// shift: it searched schema=`mydb`, relation=`public.users` and returned
|
|
57
|
+
// nothing. The 3rd (db) slot is the cross-db literal even without a
|
|
58
|
+
// dbnamevar column; the dispatcher validates it against the current DB
|
|
59
|
+
// (review item #23).
|
|
60
|
+
const maxComponents = wantSchema || wantDb ? 3 : 1;
|
|
61
|
+
const buffers = ['^('];
|
|
62
|
+
let leftLiteral = '';
|
|
63
|
+
// Upstream's `want_literal_dbname`: track the first component's
|
|
64
|
+
// literal text unconditionally so the dispatcher can detect
|
|
65
|
+
// cross-database references and emit the canonical error message.
|
|
66
|
+
let trackingLeft = true;
|
|
67
|
+
let inQuotes = false;
|
|
68
|
+
// Total separator count, independent of `maxComponents`. Upstream
|
|
69
|
+
// increments `dotcnt` past the budget so callers can raise
|
|
70
|
+
// "improper qualified name (too many dotted names)".
|
|
71
|
+
let dotCount = 0;
|
|
72
|
+
let cp = 0;
|
|
73
|
+
while (cp < pattern.length) {
|
|
74
|
+
const ch = pattern[cp];
|
|
75
|
+
if (ch === '"') {
|
|
76
|
+
if (inQuotes && pattern[cp + 1] === '"') {
|
|
77
|
+
buffers[buffers.length - 1] += '"';
|
|
78
|
+
if (trackingLeft)
|
|
79
|
+
leftLiteral += '"';
|
|
80
|
+
cp += 2;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
inQuotes = !inQuotes;
|
|
84
|
+
cp++;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (!inQuotes && ch >= 'A' && ch <= 'Z') {
|
|
88
|
+
const lo = toLower(ch);
|
|
89
|
+
buffers[buffers.length - 1] += lo;
|
|
90
|
+
if (trackingLeft)
|
|
91
|
+
leftLiteral += lo;
|
|
92
|
+
cp++;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (!inQuotes && ch === '*') {
|
|
96
|
+
buffers[buffers.length - 1] += '.*';
|
|
97
|
+
if (trackingLeft)
|
|
98
|
+
leftLiteral += '*';
|
|
99
|
+
cp++;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (!inQuotes && ch === '?') {
|
|
103
|
+
buffers[buffers.length - 1] += '.';
|
|
104
|
+
if (trackingLeft)
|
|
105
|
+
leftLiteral += '?';
|
|
106
|
+
cp++;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (!inQuotes && ch === '.') {
|
|
110
|
+
dotCount++;
|
|
111
|
+
trackingLeft = false;
|
|
112
|
+
if (buffers.length < maxComponents) {
|
|
113
|
+
buffers[buffers.length - 1] += ')$';
|
|
114
|
+
buffers.push('^(');
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
buffers[buffers.length - 1] += '.';
|
|
118
|
+
}
|
|
119
|
+
cp++;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (ch === '$') {
|
|
123
|
+
// Always quote $ — upstream rationale: identifiers may legitimately
|
|
124
|
+
// contain $ (e.g. function-language names) so the literal sense wins.
|
|
125
|
+
buffers[buffers.length - 1] += '\\$';
|
|
126
|
+
if (trackingLeft)
|
|
127
|
+
leftLiteral += '$';
|
|
128
|
+
cp++;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
// Ordinary data character.
|
|
132
|
+
let prefix = '';
|
|
133
|
+
if (inQuotes || forceLower) {
|
|
134
|
+
if (REGEX_SPECIALS.includes(ch))
|
|
135
|
+
prefix = '\\';
|
|
136
|
+
}
|
|
137
|
+
else if (ch === '[' && pattern[cp + 1] === ']') {
|
|
138
|
+
// Special: array-type bracket pair is always escaped to avoid
|
|
139
|
+
// psql users hitting an empty-character-class regex error.
|
|
140
|
+
prefix = '\\';
|
|
141
|
+
}
|
|
142
|
+
buffers[buffers.length - 1] += prefix + ch;
|
|
143
|
+
if (trackingLeft)
|
|
144
|
+
leftLiteral += ch;
|
|
145
|
+
cp++;
|
|
146
|
+
}
|
|
147
|
+
buffers[buffers.length - 1] += ')$';
|
|
148
|
+
// Upstream emits buffers in *reverse* assignment order: namebuf gets
|
|
149
|
+
// the *last* component, schemabuf the second-to-last, dbnamebuf the
|
|
150
|
+
// first. So we reverse for downstream consumption.
|
|
151
|
+
const regexes = [...buffers].reverse();
|
|
152
|
+
return {
|
|
153
|
+
dotCount,
|
|
154
|
+
regexes,
|
|
155
|
+
// Expose the first-component literal whenever the pattern was dotted
|
|
156
|
+
// (so the dispatcher can do the cross-db check) or when the caller
|
|
157
|
+
// explicitly asked for it via `wantDb` (the `\l` style three-part
|
|
158
|
+
// matcher).
|
|
159
|
+
dbLiteral: dotCount > 0 || wantDb ? leftLiteral : null,
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Build the SQL conditions and parameter values for a single name pattern.
|
|
164
|
+
*
|
|
165
|
+
* See module docstring for the contract. Pass-through pattern handling:
|
|
166
|
+
* an `^(.*)$` regex is optimized away (upstream does the same), so a
|
|
167
|
+
* bare `*` or empty unquoted segment emits no constraint.
|
|
168
|
+
*/
|
|
169
|
+
export const processSQLNamePattern = (opts) => {
|
|
170
|
+
const { pattern, forceLower = false, schemavar = null, namevar, altnamevar = null, visibilityrule = null, dbnamevar = null, } = opts;
|
|
171
|
+
const result = {
|
|
172
|
+
schemaConditions: [],
|
|
173
|
+
nameConditions: [],
|
|
174
|
+
visibilityConditions: [],
|
|
175
|
+
params: [],
|
|
176
|
+
dotCount: 0,
|
|
177
|
+
dbLiteral: null,
|
|
178
|
+
};
|
|
179
|
+
if (pattern === null) {
|
|
180
|
+
if (visibilityrule) {
|
|
181
|
+
result.visibilityConditions.push(visibilityrule);
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
const parts = patternToSQLRegex(pattern, forceLower, schemavar !== null, dbnamevar !== null);
|
|
186
|
+
result.dotCount = parts.dotCount;
|
|
187
|
+
result.dbLiteral = parts.dbLiteral;
|
|
188
|
+
// parts.regexes is name-first: [nameRegex, schemaRegex?, dbRegex?]
|
|
189
|
+
const nameRegex = parts.regexes[0];
|
|
190
|
+
const schemaRegex = parts.regexes[1] ?? null;
|
|
191
|
+
const dbRegex = parts.regexes[2] ?? null;
|
|
192
|
+
// Name constraint
|
|
193
|
+
if (nameRegex && nameRegex !== '^(.*)$') {
|
|
194
|
+
const placeholder = `$${result.params.length + 1}`;
|
|
195
|
+
if (altnamevar) {
|
|
196
|
+
result.nameConditions.push(`(${namevar} OPERATOR(pg_catalog.~) ${placeholder} OR ${altnamevar} OPERATOR(pg_catalog.~) ${placeholder})`);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
result.nameConditions.push(`${namevar} OPERATOR(pg_catalog.~) ${placeholder}`);
|
|
200
|
+
}
|
|
201
|
+
result.params.push(nameRegex);
|
|
202
|
+
}
|
|
203
|
+
// Schema constraint
|
|
204
|
+
if (schemavar && schemaRegex && schemaRegex !== '^(.*)$') {
|
|
205
|
+
const placeholder = `$${result.params.length + 1}`;
|
|
206
|
+
result.schemaConditions.push(`${schemavar} OPERATOR(pg_catalog.~) ${placeholder}`);
|
|
207
|
+
result.params.push(schemaRegex);
|
|
208
|
+
}
|
|
209
|
+
else if (!schemaRegex && visibilityrule) {
|
|
210
|
+
// No schema part given → use the visibility check instead.
|
|
211
|
+
result.visibilityConditions.push(visibilityrule);
|
|
212
|
+
}
|
|
213
|
+
// Database constraint (rarely used; \l)
|
|
214
|
+
if (dbnamevar && dbRegex && dbRegex !== '^(.*)$') {
|
|
215
|
+
const placeholder = `$${result.params.length + 1}`;
|
|
216
|
+
result.schemaConditions.push(`${dbnamevar} OPERATOR(pg_catalog.~) ${placeholder}`);
|
|
217
|
+
result.params.push(dbRegex);
|
|
218
|
+
}
|
|
219
|
+
return result;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Apply a {@link NamePatternResult} to a SQL string emitted by
|
|
223
|
+
* `queries.ts` (WP-19). The placeholder string the templates emit is
|
|
224
|
+
* `true /<!---->* TODO(WP-20): pattern matching *<!---->/` (literal).
|
|
225
|
+
* We substitute the conjoined conditions in its place. If no conditions
|
|
226
|
+
* were produced
|
|
227
|
+
* (e.g. pattern was null and no visibility rule), we leave the `true`
|
|
228
|
+
* tautology so the query semantics are unchanged.
|
|
229
|
+
*
|
|
230
|
+
* The placeholder may appear multiple times in a single query (e.g.
|
|
231
|
+
* `listCasts` matches both ends of a cast). All occurrences receive the
|
|
232
|
+
* same substitution and parameter list — that mirrors upstream, which
|
|
233
|
+
* threads the same pattern into both columns. Parameters get renumbered
|
|
234
|
+
* to be unique across the substituted query.
|
|
235
|
+
*/
|
|
236
|
+
export const applyPattern = (sql, result, baseParams = []) => {
|
|
237
|
+
const placeholder = 'true /* TODO(WP-20): pattern matching */';
|
|
238
|
+
if (!sql.includes(placeholder)) {
|
|
239
|
+
return { sql, params: baseParams };
|
|
240
|
+
}
|
|
241
|
+
const conditions = [
|
|
242
|
+
...result.schemaConditions,
|
|
243
|
+
...result.nameConditions,
|
|
244
|
+
...result.visibilityConditions,
|
|
245
|
+
];
|
|
246
|
+
if (conditions.length === 0) {
|
|
247
|
+
return { sql, params: baseParams };
|
|
248
|
+
}
|
|
249
|
+
// Detect occurrences. For each occurrence we need a fresh, renumbered
|
|
250
|
+
// parameter slot so the same regex appears with different `$N` values.
|
|
251
|
+
const occurrences = sql.split(placeholder).length - 1;
|
|
252
|
+
let renumbered = sql;
|
|
253
|
+
const params = [...baseParams];
|
|
254
|
+
for (let occ = 0; occ < occurrences; occ++) {
|
|
255
|
+
// For this occurrence, rewrite the conditions to use the next set
|
|
256
|
+
// of parameter slots starting at params.length + 1.
|
|
257
|
+
const slotOffset = params.length;
|
|
258
|
+
const conds = conditions.map((c) => c.replace(/\$(\d+)/g, (_, n) => `$${Number(n) + slotOffset}`));
|
|
259
|
+
params.push(...result.params);
|
|
260
|
+
const replacement = `(${conds.join(' AND ')})`;
|
|
261
|
+
// Replace just the first remaining occurrence (others stay until
|
|
262
|
+
// their iteration).
|
|
263
|
+
const idx = renumbered.indexOf(placeholder);
|
|
264
|
+
renumbered =
|
|
265
|
+
renumbered.slice(0, idx) +
|
|
266
|
+
replacement +
|
|
267
|
+
renumbered.slice(idx + placeholder.length);
|
|
268
|
+
}
|
|
269
|
+
return { sql: renumbered, params };
|
|
270
|
+
};
|