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.
Files changed (113) hide show
  1. package/README.md +84 -0
  2. package/analytics.js +5 -2
  3. package/commands/branches.js +9 -1
  4. package/commands/connection_string.js +9 -1
  5. package/commands/functions.js +277 -0
  6. package/commands/index.js +4 -0
  7. package/commands/neon_auth.js +1013 -0
  8. package/commands/projects.js +9 -1
  9. package/commands/psql.js +6 -1
  10. package/functions_api.js +44 -0
  11. package/package.json +15 -5
  12. package/psql/cli.js +51 -0
  13. package/psql/command/cmd_cond.js +437 -0
  14. package/psql/command/cmd_connect.js +815 -0
  15. package/psql/command/cmd_copy.js +1025 -0
  16. package/psql/command/cmd_describe.js +1810 -0
  17. package/psql/command/cmd_format.js +909 -0
  18. package/psql/command/cmd_io.js +2187 -0
  19. package/psql/command/cmd_lo.js +385 -0
  20. package/psql/command/cmd_meta.js +970 -0
  21. package/psql/command/cmd_misc.js +187 -0
  22. package/psql/command/cmd_pipeline.js +1141 -0
  23. package/psql/command/cmd_restrict.js +171 -0
  24. package/psql/command/cmd_show.js +751 -0
  25. package/psql/command/dispatch.js +343 -0
  26. package/psql/command/inputQueue.js +42 -0
  27. package/psql/command/shared.js +71 -0
  28. package/psql/complete/filenames.js +139 -0
  29. package/psql/complete/index.js +104 -0
  30. package/psql/complete/matcher.js +314 -0
  31. package/psql/complete/psqlVars.js +247 -0
  32. package/psql/complete/queries.js +491 -0
  33. package/psql/complete/rules.js +2387 -0
  34. package/psql/core/common.js +1250 -0
  35. package/psql/core/help.js +576 -0
  36. package/psql/core/mainloop.js +1353 -0
  37. package/psql/core/prompt.js +437 -0
  38. package/psql/core/settings.js +684 -0
  39. package/psql/core/sqlHelp.js +1066 -0
  40. package/psql/core/startup.js +840 -0
  41. package/psql/core/syncVars.js +116 -0
  42. package/psql/core/variables.js +287 -0
  43. package/psql/describe/formatters.js +1277 -0
  44. package/psql/describe/processNamePattern.js +270 -0
  45. package/psql/describe/queries.js +2373 -0
  46. package/psql/describe/versionGate.js +43 -0
  47. package/psql/index.js +2005 -0
  48. package/psql/io/history.js +299 -0
  49. package/psql/io/input.js +120 -0
  50. package/psql/io/lineEditor/buffer.js +323 -0
  51. package/psql/io/lineEditor/complete.js +227 -0
  52. package/psql/io/lineEditor/filename.js +159 -0
  53. package/psql/io/lineEditor/index.js +891 -0
  54. package/psql/io/lineEditor/keymap.js +738 -0
  55. package/psql/io/lineEditor/vt100.js +363 -0
  56. package/psql/io/pgpass.js +202 -0
  57. package/psql/io/pgservice.js +194 -0
  58. package/psql/io/psqlrc.js +422 -0
  59. package/psql/print/aligned.js +1756 -0
  60. package/psql/print/asciidoc.js +248 -0
  61. package/psql/print/crosstab.js +460 -0
  62. package/psql/print/csv.js +92 -0
  63. package/psql/print/html.js +258 -0
  64. package/psql/print/json.js +96 -0
  65. package/psql/print/latex.js +396 -0
  66. package/psql/print/pager.js +265 -0
  67. package/psql/print/troff.js +258 -0
  68. package/psql/print/unaligned.js +118 -0
  69. package/psql/print/units.js +135 -0
  70. package/psql/scanner/slash.js +513 -0
  71. package/psql/scanner/sql.js +910 -0
  72. package/psql/scanner/stringutils.js +390 -0
  73. package/psql/types/backslash.js +1 -0
  74. package/psql/types/connection.js +1 -0
  75. package/psql/types/index.js +7 -0
  76. package/psql/types/printer.js +1 -0
  77. package/psql/types/repl.js +1 -0
  78. package/psql/types/scanner.js +24 -0
  79. package/psql/types/settings.js +1 -0
  80. package/psql/types/variables.js +1 -0
  81. package/psql/wire/connection.js +2844 -0
  82. package/psql/wire/copy.js +108 -0
  83. package/psql/wire/notify.js +59 -0
  84. package/psql/wire/pipeline.js +519 -0
  85. package/psql/wire/protocol.js +466 -0
  86. package/psql/wire/sasl.js +296 -0
  87. package/psql/wire/tls.js +596 -0
  88. package/test_utils/fixtures.js +1 -0
  89. package/utils/esbuild.js +147 -0
  90. package/utils/psql.js +107 -11
  91. package/utils/zip.js +4 -0
  92. package/writer.js +1 -1
  93. package/commands/auth.test.js +0 -211
  94. package/commands/branches.test.js +0 -460
  95. package/commands/checkout.test.js +0 -170
  96. package/commands/connection_string.test.js +0 -196
  97. package/commands/data_api.test.js +0 -169
  98. package/commands/databases.test.js +0 -39
  99. package/commands/help.test.js +0 -9
  100. package/commands/init.test.js +0 -56
  101. package/commands/ip_allow.test.js +0 -59
  102. package/commands/link.test.js +0 -381
  103. package/commands/operations.test.js +0 -7
  104. package/commands/orgs.test.js +0 -7
  105. package/commands/projects.test.js +0 -144
  106. package/commands/psql.test.js +0 -49
  107. package/commands/roles.test.js +0 -37
  108. package/commands/set_context.test.js +0 -159
  109. package/commands/vpc_endpoints.test.js +0 -69
  110. package/context.test.js +0 -119
  111. package/env.test.js +0 -55
  112. package/utils/formats.test.js +0 -32
  113. package/writer.test.js +0 -104
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Public entrypoint for psql tab completion.
3
+ *
4
+ * The `LineEditor` (WP-24) accepts a `Completer` of shape
5
+ * `(input, cursor) => Promise<CompletionResult>`. We return a CURRIED
6
+ * factory `psqlCompleter(ctx)` that captures the settings reference so the
7
+ * completer can read `ctx.settings.db` lazily on every call — important
8
+ * because `\c` swaps out the live connection.
9
+ *
10
+ * `CompletionResult` (defined in lineEditor/complete.ts):
11
+ *
12
+ * - candidates: string[] the list shown / inserted
13
+ * - commonPrefix: string longest prefix the editor can insert without
14
+ * making a choice (`apply` walks this)
15
+ * - replaceLength: number code-points to chop off the buffer before
16
+ * inserting `candidates[i]` / commonPrefix
17
+ *
18
+ * Our `findCompletions` returns raw candidate strings; we compute the common
19
+ * prefix here. `replaceLength` is the code-point length of the partial word
20
+ * the cursor was sitting on (`currentWord`), which we already compute in
21
+ * `splitForCompletion` during tokenization.
22
+ */
23
+ import { splitForCompletion } from './matcher.js';
24
+ import { findCompletions } from './rules.js';
25
+ /**
26
+ * Build a completer bound to the given settings. The settings reference is
27
+ * captured by closure; we never snapshot, so changes to `settings.db` (via
28
+ * `\c`) take effect immediately.
29
+ */
30
+ export const psqlCompleter = (ctx) => {
31
+ const completer = async (input, cursor) => {
32
+ const { prevWords, currentWord, replaceLength } = splitForCompletion(input, cursor);
33
+ const ruleCtx = {
34
+ settings: ctx.settings,
35
+ queryBuf: ctx.getQueryBuf?.() ?? '',
36
+ };
37
+ const { candidates } = await findCompletions(prevWords, currentWord, ruleCtx);
38
+ // De-duplicate while preserving order.
39
+ const seen = new Set();
40
+ const deduped = [];
41
+ for (const c of candidates) {
42
+ if (!seen.has(c)) {
43
+ seen.add(c);
44
+ deduped.push(c);
45
+ }
46
+ }
47
+ // Stable sort so the listing is predictable. The first-character sort
48
+ // key uses lowercase so case-mixed candidate lists don't look chaotic.
49
+ deduped.sort((a, b) => {
50
+ const la = a.toLowerCase();
51
+ const lb = b.toLowerCase();
52
+ if (la < lb)
53
+ return -1;
54
+ if (la > lb)
55
+ return 1;
56
+ return 0;
57
+ });
58
+ const commonPrefix = longestCommonPrefix(deduped, currentWord);
59
+ return {
60
+ candidates: deduped,
61
+ commonPrefix,
62
+ replaceLength,
63
+ };
64
+ };
65
+ return completer;
66
+ };
67
+ // ---------------------------------------------------------------------------
68
+ // Helpers.
69
+ // ---------------------------------------------------------------------------
70
+ /**
71
+ * Return the longest common prefix of all candidates, but never shorter
72
+ * than the user's partial input (so we don't backtrack the buffer when the
73
+ * completion is a no-op).
74
+ *
75
+ * If there's a single candidate, returns it whole.
76
+ */
77
+ const longestCommonPrefix = (candidates, fallback) => {
78
+ if (candidates.length === 0)
79
+ return fallback;
80
+ if (candidates.length === 1)
81
+ return candidates[0];
82
+ // Use code-point iteration so multi-byte characters don't get cut.
83
+ const arrs = candidates.map((c) => Array.from(c));
84
+ const minLen = arrs.reduce((m, a) => Math.min(m, a.length), Infinity);
85
+ const out = [];
86
+ for (let i = 0; i < minLen; i++) {
87
+ const first = arrs[0][i];
88
+ let ok = true;
89
+ for (let j = 1; j < arrs.length; j++) {
90
+ if (arrs[j][i] !== first) {
91
+ ok = false;
92
+ break;
93
+ }
94
+ }
95
+ if (!ok)
96
+ break;
97
+ out.push(first);
98
+ }
99
+ // Common prefix should not be shorter than what's already typed.
100
+ const candidatePrefix = out.join('');
101
+ if (candidatePrefix.length >= fallback.length)
102
+ return candidatePrefix;
103
+ return fallback;
104
+ };
@@ -0,0 +1,314 @@
1
+ /**
2
+ * Matches / TailMatches / HeadMatches DSL.
3
+ *
4
+ * TypeScript port of the pattern-matching helpers in psql's tab-complete.in.c.
5
+ * The C source uses a varargs macro layered on top of `word_matches()` to
6
+ * decide whether a sequence of "previous words" matches a pattern. We
7
+ * reproduce the same shape with plain functions because (a) JS has no
8
+ * preprocessor macros and (b) array spread is the natural varargs analogue.
9
+ *
10
+ * Matches('SELECT', MatchAny, 'FROM') — exact word-count match.
11
+ * TailMatches('SELECT', MatchAny, 'FROM') — match the last N words.
12
+ * HeadMatches('ALTER', 'TABLE') — match the first N words.
13
+ *
14
+ * Wildcards and special tokens (mirroring the upstream constants):
15
+ *
16
+ * MatchAny — any single word (`NULL` upstream).
17
+ * MatchAnyExcept(x) — any word that doesn't match `x` (upstream `"!x"`).
18
+ * '*' inside a pattern — wildcard within a single word (e.g. `'pg_*'`).
19
+ * '|' inside a pattern — alternation (e.g. `'TABLE|VIEW'`).
20
+ *
21
+ * Comparisons are case-insensitive by default (SQL keywords); pass
22
+ * `caseSensitive: true` to the DSL helpers when matching strictly.
23
+ *
24
+ * The tokenizer is exported separately because the `index.ts` entry point
25
+ * needs to do the same word-split-then-match dance.
26
+ */
27
+ export const MatchAny = null;
28
+ export const MatchAnyExcept = (pattern) => '!' + pattern;
29
+ const cimatch = (s1, s2, n, caseSensitive) => {
30
+ if (s1.length < n || s2.length < n)
31
+ return false;
32
+ const a = s1.slice(0, n);
33
+ const b = s2.slice(0, n);
34
+ if (caseSensitive)
35
+ return a === b;
36
+ return a.toLowerCase() === b.toLowerCase();
37
+ };
38
+ /**
39
+ * Return true iff `word` matches `pattern`. `null`/`MatchAny` matches
40
+ * everything. A leading `!` inverts the match. `|` separates alternatives.
41
+ * `*` is a single-word wildcard.
42
+ */
43
+ export const wordMatches = (pattern, word, caseSensitive = false) => {
44
+ if (pattern === null)
45
+ return true;
46
+ if (pattern.startsWith('!')) {
47
+ return !wordMatches(pattern.slice(1), word, caseSensitive);
48
+ }
49
+ const wordlen = word.length;
50
+ let cursor = pattern;
51
+ for (;;) {
52
+ let starIdx = -1;
53
+ let i = 0;
54
+ while (i < cursor.length && cursor[i] !== '|') {
55
+ if (cursor[i] === '*')
56
+ starIdx = i;
57
+ i++;
58
+ }
59
+ if (starIdx >= 0) {
60
+ const beforeLen = starIdx;
61
+ const afterLen = i - starIdx - 1;
62
+ if (wordlen >= beforeLen + afterLen &&
63
+ cimatch(word, cursor, beforeLen, caseSensitive) &&
64
+ cimatch(word.slice(wordlen - afterLen), cursor.slice(starIdx + 1), afterLen, caseSensitive)) {
65
+ return true;
66
+ }
67
+ }
68
+ else {
69
+ if (wordlen === i && cimatch(word, cursor, wordlen, caseSensitive)) {
70
+ return true;
71
+ }
72
+ }
73
+ if (i >= cursor.length)
74
+ break;
75
+ cursor = cursor.slice(i + 1);
76
+ }
77
+ return false;
78
+ };
79
+ /**
80
+ * Exact-length match: every word in `words` must match the corresponding
81
+ * pattern. `words` here is "previous words" — i.e. the words BEFORE the
82
+ * current (in-progress) word.
83
+ *
84
+ * The upstream uses `previous_words_count + 1 == narg` because the C array
85
+ * includes both prev words AND the current. Our representation only stores
86
+ * prev words; the caller passes the in-progress word separately.
87
+ *
88
+ * prev = ['SELECT'], pattern = ['SELECT'] → true (1 == 1)
89
+ * prev = ['SELECT', 'a'], pattern = ['SELECT'] → false (2 != 1)
90
+ */
91
+ export const Matches = (prev, patterns, caseSensitive = false) => {
92
+ if (prev.length !== patterns.length)
93
+ return false;
94
+ for (let k = 0; k < patterns.length; k++) {
95
+ if (!wordMatches(patterns[k], prev[k], caseSensitive))
96
+ return false;
97
+ }
98
+ return true;
99
+ };
100
+ /**
101
+ * Tail match: the LAST N words of `prev` must match the patterns.
102
+ *
103
+ * prev = ['SELECT', 'a', 'FROM'], patterns = ['FROM'] → true
104
+ * prev = ['SELECT'], patterns = ['SELECT', 'FROM'] → false (too few)
105
+ */
106
+ export const TailMatches = (prev, patterns, caseSensitive = false) => {
107
+ if (prev.length < patterns.length)
108
+ return false;
109
+ const offset = prev.length - patterns.length;
110
+ for (let k = 0; k < patterns.length; k++) {
111
+ if (!wordMatches(patterns[k], prev[offset + k], caseSensitive))
112
+ return false;
113
+ }
114
+ return true;
115
+ };
116
+ /**
117
+ * Head match: the FIRST N words of `prev` must match.
118
+ *
119
+ * prev = ['ALTER', 'TABLE', 'foo'], patterns = ['ALTER', 'TABLE'] → true
120
+ */
121
+ export const HeadMatches = (prev, patterns, caseSensitive = false) => {
122
+ if (prev.length < patterns.length)
123
+ return false;
124
+ for (let k = 0; k < patterns.length; k++) {
125
+ if (!wordMatches(patterns[k], prev[k], caseSensitive))
126
+ return false;
127
+ }
128
+ return true;
129
+ };
130
+ /**
131
+ * Split `input` into psql-style words for completion purposes.
132
+ *
133
+ * - Whitespace is the basic separator.
134
+ * - "..." treated as ONE word (quoted identifier).
135
+ * - '...' treated as ONE word (string literal).
136
+ * - \backslash... treated as ONE word (the backslash command).
137
+ * - Punctuation (commas, parens, semicolons) is broken into its own word.
138
+ * - Embedded `.` (schema-qualifier) keeps the dotted name as a single word
139
+ * so completion sees `pg_catalog.pg_class` whole.
140
+ *
141
+ * The tokenizer is intentionally pragmatic — it doesn't validate SQL, it
142
+ * just slices well enough for the rule body to inspect previous words.
143
+ */
144
+ export const tokenize = (input) => {
145
+ const out = [];
146
+ let i = 0;
147
+ while (i < input.length) {
148
+ const ch = input[i];
149
+ // Whitespace.
150
+ if (ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r') {
151
+ i++;
152
+ continue;
153
+ }
154
+ // Backslash command. Capture the entire backslash word as one token.
155
+ if (ch === '\\') {
156
+ const start = i;
157
+ i++;
158
+ // Single-char commands like `\!` and `\?` are valid; otherwise read
159
+ // letters until we hit whitespace or punctuation.
160
+ if (i < input.length && /[!?]/.test(input[i])) {
161
+ i++;
162
+ }
163
+ else {
164
+ while (i < input.length && /[A-Za-z_]/.test(input[i]))
165
+ i++;
166
+ // Fold a trailing `+` run (the verbose suffix) into the command word
167
+ // so `\dt+ <TAB>` tokenizes as a single word and the describe rules
168
+ // that key on `prevWords.length === 1` still fire. The
169
+ // `S` (system-objects) suffix is already a letter, so it's consumed
170
+ // above; only `+` needs explicit handling here.
171
+ while (i < input.length && input[i] === '+')
172
+ i++;
173
+ }
174
+ out.push({
175
+ text: input.slice(start, i),
176
+ raw: input.slice(start, i),
177
+ start,
178
+ end: i,
179
+ });
180
+ continue;
181
+ }
182
+ // Double-quoted identifier.
183
+ if (ch === '"') {
184
+ const start = i;
185
+ i++;
186
+ while (i < input.length) {
187
+ if (input[i] === '"') {
188
+ // "" inside quotes is an escaped quote.
189
+ if (input[i + 1] === '"') {
190
+ i += 2;
191
+ continue;
192
+ }
193
+ i++;
194
+ break;
195
+ }
196
+ i++;
197
+ }
198
+ out.push({
199
+ text: input.slice(start, i),
200
+ raw: input.slice(start, i),
201
+ start,
202
+ end: i,
203
+ });
204
+ continue;
205
+ }
206
+ // Single-quoted string literal.
207
+ if (ch === "'") {
208
+ const start = i;
209
+ i++;
210
+ while (i < input.length) {
211
+ if (input[i] === '\\' && i + 1 < input.length) {
212
+ i += 2;
213
+ continue;
214
+ }
215
+ if (input[i] === "'") {
216
+ if (input[i + 1] === "'") {
217
+ i += 2;
218
+ continue;
219
+ }
220
+ i++;
221
+ break;
222
+ }
223
+ i++;
224
+ }
225
+ out.push({
226
+ text: input.slice(start, i),
227
+ raw: input.slice(start, i),
228
+ start,
229
+ end: i,
230
+ });
231
+ continue;
232
+ }
233
+ // Punctuation that splits words.
234
+ if (ch === ',' ||
235
+ ch === ';' ||
236
+ ch === '(' ||
237
+ ch === ')' ||
238
+ ch === '[' ||
239
+ ch === ']') {
240
+ out.push({ text: ch, raw: ch, start: i, end: i + 1 });
241
+ i++;
242
+ continue;
243
+ }
244
+ // Bareword: letters, digits, underscore, `.` (schema qualifier), `:` (var
245
+ // expansion marker is kept inside the word), `$` (positional param).
246
+ const start = i;
247
+ while (i < input.length) {
248
+ const c = input[i];
249
+ if (c === ' ' ||
250
+ c === '\t' ||
251
+ c === '\n' ||
252
+ c === '\r' ||
253
+ c === ',' ||
254
+ c === ';' ||
255
+ c === '(' ||
256
+ c === ')' ||
257
+ c === '[' ||
258
+ c === ']' ||
259
+ c === '"' ||
260
+ c === "'" ||
261
+ c === '\\') {
262
+ break;
263
+ }
264
+ i++;
265
+ }
266
+ out.push({
267
+ text: input.slice(start, i),
268
+ raw: input.slice(start, i),
269
+ start,
270
+ end: i,
271
+ });
272
+ }
273
+ return out;
274
+ };
275
+ /**
276
+ * Slice `input` at `cursor`, then determine what's being completed:
277
+ *
278
+ * - `prevWords`: the completed words ENTIRELY before the cursor.
279
+ * - `currentWord`: the partial word the cursor is sitting in (may be '').
280
+ * - `replaceLength`: number of code points to chop off the input before
281
+ * inserting the completion (= length of currentWord in code points).
282
+ *
283
+ * The tokenizer is run on `input.slice(0, cursor)` and the LAST token, if
284
+ * it ends exactly at cursor and didn't start with whitespace/punctuation,
285
+ * becomes the current word. Otherwise the current word is empty (the user
286
+ * just typed a space and is starting a new word).
287
+ */
288
+ export const splitForCompletion = (input, cursor) => {
289
+ const head = input.slice(0, cursor);
290
+ const tokens = tokenize(head);
291
+ if (tokens.length === 0) {
292
+ return { prevWords: [], currentWord: '', replaceLength: 0 };
293
+ }
294
+ const last = tokens[tokens.length - 1];
295
+ // The cursor is sitting inside the last token if (a) it ends exactly at
296
+ // cursor AND (b) the last char before cursor isn't whitespace.
297
+ const charBefore = head[head.length - 1];
298
+ const inWhitespace = charBefore === ' ' ||
299
+ charBefore === '\t' ||
300
+ charBefore === '\n' ||
301
+ charBefore === '\r';
302
+ if (last.end === head.length && !inWhitespace) {
303
+ return {
304
+ prevWords: tokens.slice(0, -1).map((t) => t.text),
305
+ currentWord: last.text,
306
+ replaceLength: Array.from(last.text).length,
307
+ };
308
+ }
309
+ return {
310
+ prevWords: tokens.map((t) => t.text),
311
+ currentWord: '',
312
+ replaceLength: 0,
313
+ };
314
+ };
@@ -0,0 +1,247 @@
1
+ /**
2
+ * Static-list completion candidates for psql special variables, settings,
3
+ * and the small enums their values take.
4
+ *
5
+ * The values come from `pset_lookup_option` and the var-hook table in psql
6
+ * (`src/bin/psql/variables.c` + `command.c`). We keep this module pure data
7
+ * so it's trivial to extend as new variables are added in later WPs.
8
+ */
9
+ /** All psql special variables (anything that has a hook in variables.c). */
10
+ export const SPECIAL_VARIABLES = [
11
+ 'AUTOCOMMIT',
12
+ 'COMP_KEYWORD_CASE',
13
+ 'DBNAME',
14
+ 'ECHO',
15
+ 'ECHO_HIDDEN',
16
+ 'ENCODING',
17
+ 'ERROR',
18
+ 'FETCH_COUNT',
19
+ 'HIDE_TABLEAM',
20
+ 'HIDE_TOAST_COMPRESSION',
21
+ 'HISTCONTROL',
22
+ 'HISTFILE',
23
+ 'HISTSIZE',
24
+ 'HOST',
25
+ 'IGNOREEOF',
26
+ 'LASTOID',
27
+ 'LAST_ERROR_MESSAGE',
28
+ 'LAST_ERROR_SQLSTATE',
29
+ 'ON_ERROR_ROLLBACK',
30
+ 'ON_ERROR_STOP',
31
+ 'PORT',
32
+ 'PROMPT1',
33
+ 'PROMPT2',
34
+ 'PROMPT3',
35
+ 'QUIET',
36
+ 'ROW_COUNT',
37
+ 'SERVER_VERSION_NAME',
38
+ 'SERVER_VERSION_NUM',
39
+ 'SHELL_ERROR',
40
+ 'SHELL_EXIT_CODE',
41
+ 'SHOW_ALL_RESULTS',
42
+ 'SHOW_CONTEXT',
43
+ 'SINGLELINE',
44
+ 'SINGLESTEP',
45
+ 'SQLSTATE',
46
+ 'USER',
47
+ 'VERBOSITY',
48
+ 'VERSION',
49
+ 'VERSION_NAME',
50
+ 'VERSION_NUM',
51
+ ];
52
+ /** `\pset` option names. */
53
+ export const PSET_OPTIONS = [
54
+ 'border',
55
+ 'columns',
56
+ 'csv_fieldsep',
57
+ 'expanded',
58
+ 'fieldsep',
59
+ 'fieldsep_zero',
60
+ 'footer',
61
+ 'format',
62
+ 'linestyle',
63
+ 'null',
64
+ 'numericlocale',
65
+ 'pager',
66
+ 'pager_min_lines',
67
+ 'recordsep',
68
+ 'recordsep_zero',
69
+ 'tableattr',
70
+ 'title',
71
+ 'tuples_only',
72
+ 'unicode_border_linestyle',
73
+ 'unicode_column_linestyle',
74
+ 'unicode_header_linestyle',
75
+ 'xheader_width',
76
+ ];
77
+ /** Output formats accepted by `\pset format`. */
78
+ export const PSET_FORMATS = [
79
+ 'aligned',
80
+ 'asciidoc',
81
+ 'csv',
82
+ 'html',
83
+ 'latex',
84
+ 'latex-longtable',
85
+ 'troff-ms',
86
+ 'unaligned',
87
+ 'wrapped',
88
+ ];
89
+ /** Line styles accepted by `\pset linestyle`. */
90
+ export const PSET_LINESTYLES = [
91
+ 'ascii',
92
+ 'old-ascii',
93
+ 'unicode',
94
+ ];
95
+ /** Unicode border/column/header line styles. */
96
+ export const PSET_UNICODE_STYLES = ['single', 'double'];
97
+ /** `xheader_width` argument forms. */
98
+ export const PSET_XHEADER_WIDTHS = [
99
+ 'column',
100
+ 'full',
101
+ 'page',
102
+ ];
103
+ /** On/off/auto enum, used by many variables. */
104
+ export const ON_OFF = ['on', 'off'];
105
+ export const ON_OFF_AUTO = ['on', 'off', 'auto'];
106
+ /** Echo modes. */
107
+ export const ECHO_MODES = [
108
+ 'none',
109
+ 'errors',
110
+ 'queries',
111
+ 'all',
112
+ ];
113
+ export const ECHO_HIDDEN_MODES = ['off', 'on', 'noexec'];
114
+ export const ON_ERROR_ROLLBACK_MODES = [
115
+ 'off',
116
+ 'on',
117
+ 'interactive',
118
+ ];
119
+ export const VERBOSITY_MODES = [
120
+ 'default',
121
+ 'verbose',
122
+ 'terse',
123
+ 'sqlstate',
124
+ ];
125
+ export const SHOW_CONTEXT_MODES = [
126
+ 'never',
127
+ 'errors',
128
+ 'always',
129
+ ];
130
+ export const COMP_KEYWORD_CASE_MODES = [
131
+ 'lower',
132
+ 'upper',
133
+ 'preserve-lower',
134
+ 'preserve-upper',
135
+ ];
136
+ export const HIST_CONTROL_MODES = [
137
+ 'none',
138
+ 'ignorespace',
139
+ 'ignoredups',
140
+ 'ignoreboth',
141
+ ];
142
+ /** A handful of common client encodings — enough to be useful at `\encoding`. */
143
+ export const ENCODINGS = [
144
+ 'BIG5',
145
+ 'EUC_CN',
146
+ 'EUC_JIS_2004',
147
+ 'EUC_JP',
148
+ 'EUC_KR',
149
+ 'EUC_TW',
150
+ 'GB18030',
151
+ 'GBK',
152
+ 'ISO_8859_5',
153
+ 'ISO_8859_6',
154
+ 'ISO_8859_7',
155
+ 'ISO_8859_8',
156
+ 'JOHAB',
157
+ 'KOI8R',
158
+ 'KOI8U',
159
+ 'LATIN1',
160
+ 'LATIN2',
161
+ 'LATIN3',
162
+ 'LATIN4',
163
+ 'LATIN5',
164
+ 'LATIN6',
165
+ 'LATIN7',
166
+ 'LATIN8',
167
+ 'LATIN9',
168
+ 'LATIN10',
169
+ 'MULE_INTERNAL',
170
+ 'SJIS',
171
+ 'SHIFT_JIS_2004',
172
+ 'SQL_ASCII',
173
+ 'UHC',
174
+ 'UTF8',
175
+ 'WIN866',
176
+ 'WIN874',
177
+ 'WIN1250',
178
+ 'WIN1251',
179
+ 'WIN1252',
180
+ 'WIN1253',
181
+ 'WIN1254',
182
+ 'WIN1255',
183
+ 'WIN1256',
184
+ 'WIN1257',
185
+ 'WIN1258',
186
+ ];
187
+ /**
188
+ * For a given `\pset` option, return the list of values it accepts. Returns
189
+ * `null` for free-form options (title, fieldsep, etc.).
190
+ */
191
+ export const psetValuesFor = (option) => {
192
+ switch (option) {
193
+ case 'format':
194
+ return PSET_FORMATS;
195
+ case 'linestyle':
196
+ return PSET_LINESTYLES;
197
+ case 'unicode_border_linestyle':
198
+ case 'unicode_column_linestyle':
199
+ case 'unicode_header_linestyle':
200
+ return PSET_UNICODE_STYLES;
201
+ case 'xheader_width':
202
+ return PSET_XHEADER_WIDTHS;
203
+ case 'expanded':
204
+ case 'pager':
205
+ return ON_OFF_AUTO;
206
+ case 'footer':
207
+ case 'tuples_only':
208
+ case 'numericlocale':
209
+ case 'fieldsep_zero':
210
+ case 'recordsep_zero':
211
+ return ON_OFF;
212
+ default:
213
+ return null;
214
+ }
215
+ };
216
+ /**
217
+ * For a given special variable, return acceptable values, or `null` if free-form.
218
+ */
219
+ export const variableValuesFor = (name) => {
220
+ switch (name) {
221
+ case 'AUTOCOMMIT':
222
+ case 'ON_ERROR_STOP':
223
+ case 'QUIET':
224
+ case 'SINGLELINE':
225
+ case 'SINGLESTEP':
226
+ case 'SHOW_ALL_RESULTS':
227
+ case 'HIDE_TOAST_COMPRESSION':
228
+ case 'HIDE_TABLEAM':
229
+ return ON_OFF;
230
+ case 'ECHO':
231
+ return ECHO_MODES;
232
+ case 'ECHO_HIDDEN':
233
+ return ECHO_HIDDEN_MODES;
234
+ case 'ON_ERROR_ROLLBACK':
235
+ return ON_ERROR_ROLLBACK_MODES;
236
+ case 'VERBOSITY':
237
+ return VERBOSITY_MODES;
238
+ case 'SHOW_CONTEXT':
239
+ return SHOW_CONTEXT_MODES;
240
+ case 'COMP_KEYWORD_CASE':
241
+ return COMP_KEYWORD_CASE_MODES;
242
+ case 'HISTCONTROL':
243
+ return HIST_CONTROL_MODES;
244
+ default:
245
+ return null;
246
+ }
247
+ };