neonctl 2.22.2 → 2.23.1

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 +268 -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 +43 -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,159 @@
1
+ /**
2
+ * Filename quoting / escaping for psql backslash commands.
3
+ *
4
+ * psql's `\copy`, `\i`, `\o`, `\ir`, `\g`, `\edit` etc. accept a path
5
+ * argument that follows shell-like quoting rules:
6
+ *
7
+ * - Bare words may contain alphanumerics, plus a small allowlist of
8
+ * punctuation that does not need quoting (`-._/+@:`).
9
+ * - Words containing whitespace or shell metacharacters must be wrapped
10
+ * in single or double quotes.
11
+ * - Inside double quotes, backslash escapes apply to `"` and `\`.
12
+ * - Inside single quotes, nothing is escaped — to embed a `'`, the user
13
+ * must close, escape, and reopen (`'foo'\''bar'`).
14
+ *
15
+ * The completer uses this to decide how to render a filename candidate
16
+ * given the partial input the user has typed. If they're already inside
17
+ * quotes, we preserve the quote style and escape only what's needed.
18
+ */
19
+ const NEEDS_QUOTE_RE = /[\s"'\\$`*?[\](){}<>|;&!~#]/;
20
+ /** Characters that always require quoting (whitespace or shell-special). */
21
+ export const needsQuoting = (s) => {
22
+ if (s.length === 0)
23
+ return true;
24
+ return NEEDS_QUOTE_RE.test(s);
25
+ };
26
+ /**
27
+ * Wrap a filename in single quotes, escaping any embedded `'` via the
28
+ * `'\''` trick used by POSIX shells (close, literal backslash-quote, reopen).
29
+ */
30
+ export const singleQuote = (s) => `'${s.replace(/'/g, "'\\''")}'`;
31
+ /**
32
+ * Wrap a filename in double quotes, escaping `"`, `\`, `$`, and backticks.
33
+ */
34
+ export const doubleQuote = (s) => `"${s.replace(/[\\"$`]/g, (m) => `\\${m}`)}"`;
35
+ export const detectQuoteStyle = (prefix) => {
36
+ // Walk left-to-right tracking the current quote state. A naive last-quote
37
+ // approach gets fooled by escaped quotes inside doublequotes.
38
+ let style = 'none';
39
+ let i = 0;
40
+ while (i < prefix.length) {
41
+ const ch = prefix[i];
42
+ if (style === 'none') {
43
+ if (ch === "'") {
44
+ style = 'single';
45
+ i++;
46
+ continue;
47
+ }
48
+ if (ch === '"') {
49
+ style = 'double';
50
+ i++;
51
+ continue;
52
+ }
53
+ if (ch === '\\' && i + 1 < prefix.length) {
54
+ // Escaped char outside quotes: skip the escape.
55
+ i += 2;
56
+ continue;
57
+ }
58
+ i++;
59
+ continue;
60
+ }
61
+ if (style === 'single') {
62
+ if (ch === "'")
63
+ style = 'none';
64
+ i++;
65
+ continue;
66
+ }
67
+ // double-quoted
68
+ if (ch === '"') {
69
+ style = 'none';
70
+ i++;
71
+ continue;
72
+ }
73
+ if (ch === '\\' && i + 1 < prefix.length) {
74
+ i += 2;
75
+ continue;
76
+ }
77
+ i++;
78
+ }
79
+ return style;
80
+ };
81
+ /**
82
+ * Quote `name` so it fits as a completion of an in-progress token whose
83
+ * current quoting state is `style`. Returns the bare suffix to append
84
+ * (the completer is responsible for splicing it into the line).
85
+ *
86
+ * - `none`: pick the smallest safe quoting. Bare if safe, else single.
87
+ * - `single`: emit the name escaped for inside single quotes; no closing
88
+ * quote (the user may continue typing).
89
+ * - `double`: emit the name escaped for inside double quotes; no closing
90
+ * quote.
91
+ */
92
+ export const quoteForCompletion = (name, style) => {
93
+ switch (style) {
94
+ case 'none':
95
+ return needsQuoting(name) ? singleQuote(name) : name;
96
+ case 'single':
97
+ // Inside single quotes, only `'` is special.
98
+ return name.replace(/'/g, "'\\''");
99
+ case 'double':
100
+ // Inside double quotes: \, ", $, ` need escaping.
101
+ return name.replace(/[\\"$`]/g, (m) => `\\${m}`);
102
+ }
103
+ };
104
+ /**
105
+ * Strip the quoting from a token to recover the raw filename. Used when
106
+ * the caller wants to feed the partial input to a filesystem lookup.
107
+ */
108
+ export const unquote = (s) => {
109
+ let out = '';
110
+ let style = 'none';
111
+ let i = 0;
112
+ while (i < s.length) {
113
+ const ch = s[i];
114
+ if (style === 'none') {
115
+ if (ch === "'") {
116
+ style = 'single';
117
+ i++;
118
+ continue;
119
+ }
120
+ if (ch === '"') {
121
+ style = 'double';
122
+ i++;
123
+ continue;
124
+ }
125
+ if (ch === '\\' && i + 1 < s.length) {
126
+ out += s[i + 1];
127
+ i += 2;
128
+ continue;
129
+ }
130
+ out += ch;
131
+ i++;
132
+ continue;
133
+ }
134
+ if (style === 'single') {
135
+ if (ch === "'") {
136
+ style = 'none';
137
+ i++;
138
+ continue;
139
+ }
140
+ out += ch;
141
+ i++;
142
+ continue;
143
+ }
144
+ // double-quoted
145
+ if (ch === '"') {
146
+ style = 'none';
147
+ i++;
148
+ continue;
149
+ }
150
+ if (ch === '\\' && i + 1 < s.length) {
151
+ out += s[i + 1];
152
+ i += 2;
153
+ continue;
154
+ }
155
+ out += ch;
156
+ i++;
157
+ }
158
+ return out;
159
+ };