neon 3.0.0 → 3.1.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 (207) hide show
  1. package/README.md +70 -5
  2. package/dist/_chunks/auth_selection-DGgq6ifc.js +83 -0
  3. package/dist/_chunks/cmd_pipeline-CUbBO9U_.js +2818 -0
  4. package/dist/_chunks/credentials-MYdHdKah.js +188 -0
  5. package/dist/_chunks/env-NbA61JR3.js +585 -0
  6. package/dist/_chunks/env_services-Tz9G4JeT.js +531 -0
  7. package/dist/_chunks/paths-DMq0Lt7a.js +151 -0
  8. package/dist/_chunks/profiles-Ir29rqns.js +217 -0
  9. package/dist/_chunks/psql-DWH-kc69.js +2169 -0
  10. package/dist/_chunks/rolldown-runtime-D7D4PA-g.js +13 -0
  11. package/dist/_chunks/secure_file-BucZj4yQ.js +39 -0
  12. package/dist/analytics.js +163 -207
  13. package/dist/api.js +815 -758
  14. package/dist/auth.js +121 -141
  15. package/dist/auth_context.js +39 -53
  16. package/dist/cli.js +4 -7
  17. package/dist/commands/api.js +220 -250
  18. package/dist/commands/api_keys.js +251 -314
  19. package/dist/commands/auth.js +283 -328
  20. package/dist/commands/bootstrap.js +372 -437
  21. package/dist/commands/branches.js +304 -455
  22. package/dist/commands/bucket.js +374 -514
  23. package/dist/commands/checkout.js +213 -298
  24. package/dist/commands/config.js +573 -690
  25. package/dist/commands/connection_string.js +137 -165
  26. package/dist/commands/data_api.js +238 -260
  27. package/dist/commands/databases.js +67 -76
  28. package/dist/commands/deploy.js +31 -25
  29. package/dist/commands/dev.js +639 -719
  30. package/dist/commands/diff.js +156 -200
  31. package/dist/commands/env.js +255 -305
  32. package/dist/commands/functions.js +275 -355
  33. package/dist/commands/index.js +70 -65
  34. package/dist/commands/init.js +84 -119
  35. package/dist/commands/inspect.js +55 -55
  36. package/dist/commands/ip_allow.js +88 -120
  37. package/dist/commands/link.js +874 -1019
  38. package/dist/commands/logs.js +291 -0
  39. package/dist/commands/neon_auth.js +725 -933
  40. package/dist/commands/operations.js +34 -25
  41. package/dist/commands/orgs.js +28 -18
  42. package/dist/commands/profile.js +615 -846
  43. package/dist/commands/projects.js +313 -373
  44. package/dist/commands/psql.js +60 -58
  45. package/dist/commands/roles.js +55 -58
  46. package/dist/commands/schema_diff.js +87 -131
  47. package/dist/commands/set_context.js +34 -26
  48. package/dist/commands/snapshots.js +288 -413
  49. package/dist/commands/status.js +41 -37
  50. package/dist/commands/user.js +21 -10
  51. package/dist/commands/vpc_endpoints.js +85 -113
  52. package/dist/config.js +7 -6
  53. package/dist/config_format.js +50 -66
  54. package/dist/config_template.js +128 -157
  55. package/dist/context.js +183 -235
  56. package/dist/current_branch_fast_path.js +40 -49
  57. package/dist/dev/env.js +2 -446
  58. package/dist/dev/functions.js +54 -68
  59. package/dist/dev/inputs.js +46 -58
  60. package/dist/dev/runtime.js +135 -164
  61. package/dist/dev/websocket.js +766 -959
  62. package/dist/env.js +27 -33
  63. package/dist/env_file.js +118 -132
  64. package/dist/env_services.js +2 -51
  65. package/dist/errors.js +57 -68
  66. package/dist/functions_api.js +45 -43
  67. package/dist/help.js +189 -140
  68. package/dist/index.js +182 -257
  69. package/dist/init/agents.js +137 -118
  70. package/dist/init/auth.js +58 -68
  71. package/dist/init/bootstrap.js +325 -396
  72. package/dist/init/build_config.js +4 -2
  73. package/dist/init/detect_agent.js +56 -101
  74. package/dist/init/editors.js +35 -52
  75. package/dist/init/enrich_output.js +51 -66
  76. package/dist/init/extension.js +134 -171
  77. package/dist/init/inspect.js +179 -266
  78. package/dist/init/interactive.js +510 -622
  79. package/dist/init/neonctl.js +117 -168
  80. package/dist/init/orchestrate.js +157 -173
  81. package/dist/init/phases/auth.js +188 -202
  82. package/dist/init/phases/cleanup.js +23 -23
  83. package/dist/init/phases/db.js +251 -277
  84. package/dist/init/phases/getting_started.js +213 -223
  85. package/dist/init/phases/mcp.js +174 -224
  86. package/dist/init/phases/migrations.js +247 -248
  87. package/dist/init/phases/neon_auth.js +114 -133
  88. package/dist/init/phases/setup.js +546 -703
  89. package/dist/init/phases/skills.js +75 -86
  90. package/dist/init/phases/status.js +72 -67
  91. package/dist/init/resolve_context.js +102 -99
  92. package/dist/init/route_command.js +91 -98
  93. package/dist/init/skills.js +174 -218
  94. package/dist/init/vsix.js +77 -99
  95. package/dist/log.js +17 -16
  96. package/dist/neon_services.js +104 -129
  97. package/dist/parameters.gen.js +481 -471
  98. package/dist/pkg.js +17 -19
  99. package/dist/profile_keys.js +44 -47
  100. package/dist/psql/cli.js +44 -47
  101. package/dist/psql/command/cmd_cond.js +231 -406
  102. package/dist/psql/command/cmd_connect.js +557 -764
  103. package/dist/psql/command/cmd_copy.js +728 -984
  104. package/dist/psql/command/cmd_describe.js +1499 -1688
  105. package/dist/psql/command/cmd_format.js +733 -905
  106. package/dist/psql/command/cmd_io.js +2 -2193
  107. package/dist/psql/command/cmd_lo.js +297 -359
  108. package/dist/psql/command/cmd_meta.js +727 -878
  109. package/dist/psql/command/cmd_misc.js +138 -172
  110. package/dist/psql/command/cmd_pipeline.js +2 -1148
  111. package/dist/psql/command/cmd_restrict.js +119 -155
  112. package/dist/psql/command/cmd_show.js +529 -688
  113. package/dist/psql/command/dispatch.js +260 -325
  114. package/dist/psql/command/inputQueue.js +35 -33
  115. package/dist/psql/command/shared.js +49 -63
  116. package/dist/psql/complete/filenames.js +90 -133
  117. package/dist/psql/complete/index.js +59 -97
  118. package/dist/psql/complete/matcher.js +236 -300
  119. package/dist/psql/complete/psqlVars.js +218 -223
  120. package/dist/psql/complete/queries.js +159 -177
  121. package/dist/psql/complete/rules.js +1493 -2299
  122. package/dist/psql/core/common.js +2 -1253
  123. package/dist/psql/core/help.js +456 -546
  124. package/dist/psql/core/mainloop.js +692 -1303
  125. package/dist/psql/core/prompt.js +391 -408
  126. package/dist/psql/core/settings.js +429 -644
  127. package/dist/psql/core/sqlHelp.js +480 -554
  128. package/dist/psql/core/startup.js +2 -846
  129. package/dist/psql/core/syncVars.js +67 -110
  130. package/dist/psql/core/variables.js +156 -278
  131. package/dist/psql/describe/formatters.js +884 -1285
  132. package/dist/psql/describe/processNamePattern.js +173 -260
  133. package/dist/psql/describe/queries.js +1368 -2403
  134. package/dist/psql/describe/versionGate.js +32 -41
  135. package/dist/psql/index.js +2 -2030
  136. package/dist/psql/io/history.js +232 -271
  137. package/dist/psql/io/input.js +103 -108
  138. package/dist/psql/io/lineEditor/buffer.js +238 -319
  139. package/dist/psql/io/lineEditor/complete.js +135 -213
  140. package/dist/psql/io/lineEditor/filename.js +139 -148
  141. package/dist/psql/io/lineEditor/index.js +653 -870
  142. package/dist/psql/io/lineEditor/keymap.js +544 -702
  143. package/dist/psql/io/lineEditor/vt100.js +294 -341
  144. package/dist/psql/io/pgpass.js +158 -187
  145. package/dist/psql/io/pgservice.js +146 -183
  146. package/dist/psql/io/psqlrc.js +328 -403
  147. package/dist/psql/print/aligned.js +1020 -1683
  148. package/dist/psql/print/asciidoc.js +180 -214
  149. package/dist/psql/print/crosstab.js +281 -442
  150. package/dist/psql/print/csv.js +48 -70
  151. package/dist/psql/print/html.js +195 -226
  152. package/dist/psql/print/json.js +75 -88
  153. package/dist/psql/print/latex.js +291 -364
  154. package/dist/psql/print/pager.js +171 -242
  155. package/dist/psql/print/troff.js +194 -226
  156. package/dist/psql/print/unaligned.js +69 -95
  157. package/dist/psql/print/units.js +167 -169
  158. package/dist/psql/scanner/slash.js +428 -483
  159. package/dist/psql/scanner/sql.js +445 -889
  160. package/dist/psql/scanner/stringutils.js +309 -379
  161. package/dist/psql/types/index.js +8 -7
  162. package/dist/psql/types/scanner.js +25 -22
  163. package/dist/psql/wire/connection.js +2042 -2803
  164. package/dist/psql/wire/copy.js +84 -100
  165. package/dist/psql/wire/notify.js +39 -59
  166. package/dist/psql/wire/pipeline.js +305 -518
  167. package/dist/psql/wire/protocol.js +349 -417
  168. package/dist/psql/wire/sasl.js +180 -265
  169. package/dist/psql/wire/tls.js +400 -561
  170. package/dist/storage_api.js +115 -129
  171. package/dist/test_utils/fixtures.js +94 -113
  172. package/dist/test_utils/oauth_server.js +10 -7
  173. package/dist/test_utils/project_dir.js +33 -0
  174. package/dist/utils/ai_gateway_notice.js +131 -162
  175. package/dist/utils/api_enums.js +21 -28
  176. package/dist/utils/auth.js +10 -4
  177. package/dist/utils/branch_notice.js +20 -19
  178. package/dist/utils/branch_picker.js +83 -89
  179. package/dist/utils/cli_name.js +15 -12
  180. package/dist/utils/compute_units.js +20 -27
  181. package/dist/utils/config_diff.js +127 -158
  182. package/dist/utils/enrichers.js +95 -148
  183. package/dist/utils/esbuild.js +130 -189
  184. package/dist/utils/flags.js +35 -47
  185. package/dist/utils/formats.js +8 -15
  186. package/dist/utils/git_diff.js +69 -80
  187. package/dist/utils/inspect_db.js +101 -143
  188. package/dist/utils/inspect_queries.js +179 -142
  189. package/dist/utils/middlewares.js +39 -45
  190. package/dist/utils/openapi.js +87 -99
  191. package/dist/utils/package_manager.js +312 -110
  192. package/dist/utils/point_in_time.js +49 -53
  193. package/dist/utils/psql.js +89 -106
  194. package/dist/utils/service_picker.js +55 -58
  195. package/dist/utils/string.js +5 -5
  196. package/dist/utils/ui.js +38 -55
  197. package/dist/utils/write_sync.js +26 -35
  198. package/dist/utils/zip.js +4 -3
  199. package/dist/writer.js +67 -87
  200. package/package.json +11 -6
  201. package/dist/_shared/auth_selection.js +0 -86
  202. package/dist/_shared/credentials.js +0 -209
  203. package/dist/_shared/env-core/env.js +0 -558
  204. package/dist/_shared/env-core/reuse-secrets.js +0 -223
  205. package/dist/_shared/paths.js +0 -148
  206. package/dist/_shared/profiles.js +0 -276
  207. package/dist/_shared/secure_file.js +0 -43
@@ -1,576 +1,486 @@
1
- /**
2
- * psql help text — TypeScript port of upstream `src/bin/psql/help.c`.
3
- *
4
- * Phase-0 (WP-18). The literal text matches PostgreSQL master; whitespace and
5
- * line breaks are load-bearing because output is compared against upstream
6
- * psql. Runtime-dependent fields (current DB name, format toggles, timing,
7
- * default field/CSV separators, etc.) are accepted via the optional `opts`
8
- * object so that callers can wire them in without this module reaching into
9
- * `pset` directly.
10
- *
11
- * `helpSQL` ships a curated subset of upstream's auto-generated `sql_help.h`
12
- * — ~70 commands covering the everyday DML/DDL/transaction/role surface. See
13
- * {@link ./sqlHelp.ts} for the data and lookup logic. Rarer commands resolve
14
- * through the docs URL on each entry rather than being inlined here.
15
- */
16
1
  import { openPager } from "../print/pager.js";
17
- import { findMatches, formatEntry, SQL_HELP } from "./sqlHelp.js";
2
+ import { SQL_HELP, findMatches, formatEntry } from "./sqlHelp.js";
3
+ //#region src/psql/core/help.ts
4
+ /**
5
+ * psql help text — TypeScript port of upstream `src/bin/psql/help.c`.
6
+ *
7
+ * Phase-0 (WP-18). The literal text matches PostgreSQL master; whitespace and
8
+ * line breaks are load-bearing because output is compared against upstream
9
+ * psql. Runtime-dependent fields (current DB name, format toggles, timing,
10
+ * default field/CSV separators, etc.) are accepted via the optional `opts`
11
+ * object so that callers can wire them in without this module reaching into
12
+ * `pset` directly.
13
+ *
14
+ * `helpSQL` ships a curated subset of upstream's auto-generated `sql_help.h`
15
+ * — ~70 commands covering the everyday DML/DDL/transaction/role surface. See
16
+ * {@link ./sqlHelp.ts} for the data and lookup logic. Rarer commands resolve
17
+ * through the docs URL on each entry rather than being inlined here.
18
+ */
18
19
  let pagerOpener = openPager;
19
20
  /** Override the pager opener (tests only). Returns a restore function. */
20
- export const setHelpPagerOpener = (opener) => {
21
- const prev = pagerOpener;
22
- pagerOpener = opener;
23
- return () => {
24
- pagerOpener = prev;
25
- };
21
+ const setHelpPagerOpener = (opener) => {
22
+ const prev = pagerOpener;
23
+ pagerOpener = opener;
24
+ return () => {
25
+ pagerOpener = prev;
26
+ };
26
27
  };
27
28
  /** True when `out` is a TTY whose height we can sensibly page against. */
28
29
  const isInteractive = (out) => Boolean(out.isTTY);
29
30
  /**
30
- * Emit help text. When `pager` is requested and `out` is interactive, route
31
- * the text through the external pager (upstream `PageOutput`); otherwise write
32
- * it straight to `out`.
33
- *
34
- * The pager decision (TTY, line count vs. terminal height, resolved pager
35
- * command) is delegated to {@link openPager}, which falls back to a no-op
36
- * handle wrapping `out` when paging isn't warranted. We pass the help text's
37
- * own line count so the auto threshold matches what the user will see.
38
- */
31
+ * Emit help text. When `pager` is requested and `out` is interactive, route
32
+ * the text through the external pager (upstream `PageOutput`); otherwise write
33
+ * it straight to `out`.
34
+ *
35
+ * The pager decision (TTY, line count vs. terminal height, resolved pager
36
+ * command) is delegated to {@link openPager}, which falls back to a no-op
37
+ * handle wrapping `out` when paging isn't warranted. We pass the help text's
38
+ * own line count so the auto threshold matches what the user will see.
39
+ */
39
40
  const emitHelp = (out, text, pager) => {
40
- if (!pager || !isInteractive(out)) {
41
- out.write(text);
42
- return;
43
- }
44
- // Count lines so `openPager`'s auto-mode threshold reflects the real output.
45
- const lines = text.length === 0 ? 0 : text.split("\n").length;
46
- const handle = pagerOpener({
47
- pager: "on",
48
- pagerMinLines: 0,
49
- lines,
50
- stdout: out,
51
- });
52
- handle.out.write(text);
53
- // `close()` waits for the pager to drain & exit and never rejects (spawn
54
- // failures settle to a non-zero code), so detaching it here cannot produce
55
- // an unhandled rejection. When no pager spawned, this resolves immediately.
56
- void handle.close();
41
+ if (!pager || !isInteractive(out)) {
42
+ out.write(text);
43
+ return;
44
+ }
45
+ const lines = text.length === 0 ? 0 : text.split("\n").length;
46
+ const handle = pagerOpener({
47
+ pager: "on",
48
+ pagerMinLines: 0,
49
+ lines,
50
+ stdout: out
51
+ });
52
+ handle.out.write(text);
53
+ handle.close();
57
54
  };
58
55
  const DEFAULTS = {
59
- progname: "psql",
60
- defaultFieldSep: "|",
61
- defaultCsvFieldSep: ",",
62
- defaultWatchInterval: "2",
63
- packageBugReport: "pgsql-bugs@lists.postgresql.org",
64
- packageName: "PostgreSQL",
65
- packageUrl: "https://www.postgresql.org/",
66
- currentDb: null,
67
- htmlMode: false,
68
- tuplesOnly: false,
69
- expanded: false,
70
- timing: false,
71
- win32: false,
72
- useReadline: true,
56
+ progname: "psql",
57
+ defaultFieldSep: "|",
58
+ defaultCsvFieldSep: ",",
59
+ defaultWatchInterval: "2",
60
+ packageBugReport: "pgsql-bugs@lists.postgresql.org",
61
+ packageName: "PostgreSQL",
62
+ packageUrl: "https://www.postgresql.org/",
63
+ currentDb: null,
64
+ htmlMode: false,
65
+ tuplesOnly: false,
66
+ expanded: false,
67
+ timing: false,
68
+ win32: false,
69
+ useReadline: true
73
70
  };
74
71
  const resolve = (opts) => ({
75
- ...DEFAULTS,
76
- ...opts,
72
+ ...DEFAULTS,
73
+ ...opts
77
74
  });
78
- const on = (v) => (v ? "on" : "off");
75
+ const on = (v) => v ? "on" : "off";
79
76
  const expandedLabel = (v) => v === "auto" ? "auto" : on(v);
80
77
  /**
81
- * `psql --help` text — top-level command-line options.
82
- *
83
- * Always written inline: this is the `--help` path (and `\? options`), which
84
- * upstream emits without a pager. Interactive `\?` paging is handled by
85
- * {@link slashUsage} via its `pager` flag.
86
- */
87
- export const usage = (out, opts) => {
88
- const o = resolve(opts);
89
- const buf = [];
90
- const w = (s) => {
91
- buf.push(s);
92
- };
93
- w(`${o.progname} is the PostgreSQL interactive terminal.\n\n`);
94
- w("Usage:\n");
95
- w(` ${o.progname} [OPTION]... [DBNAME [USERNAME]]\n\n`);
96
- w("General options:\n");
97
- w(" -c, --command=COMMAND run only single command (SQL or internal) and exit\n");
98
- w(" -d, --dbname=DBNAME database name to connect to\n");
99
- w(" -f, --file=FILENAME execute commands from file, then exit\n");
100
- w(" -l, --list list available databases, then exit\n");
101
- w(" -v, --set=, --variable=NAME=VALUE\n" +
102
- " set psql variable NAME to VALUE\n" +
103
- " (e.g., -v ON_ERROR_STOP=1)\n");
104
- w(" -V, --version output version information, then exit\n");
105
- w(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n");
106
- w(' -1 ("one"), --single-transaction\n' +
107
- " execute as a single transaction (if non-interactive)\n");
108
- w(" -?, --help[=options] show this help, then exit\n");
109
- w(" --help=commands list backslash commands, then exit\n");
110
- w(" --help=variables list special variables, then exit\n");
111
- w("\nInput and output options:\n");
112
- w(" -a, --echo-all echo all input from script\n");
113
- w(" -b, --echo-errors echo failed commands\n");
114
- w(" -e, --echo-queries echo commands sent to server\n");
115
- w(" -E, --echo-hidden display queries that internal commands generate\n");
116
- w(" -L, --log-file=FILENAME send session log to file\n");
117
- w(" -n, --no-readline disable enhanced command line editing (readline)\n");
118
- w(" -o, --output=FILENAME send query results to file (or |pipe)\n");
119
- w(" -q, --quiet run quietly (no messages, only query output)\n");
120
- w(" -s, --single-step single-step mode (confirm each query)\n");
121
- w(" -S, --single-line single-line mode (end of line terminates SQL command)\n");
122
- w("\nOutput format options:\n");
123
- w(" -A, --no-align unaligned table output mode\n");
124
- w(" --csv CSV (Comma-Separated Values) table output mode\n");
125
- w(" -F, --field-separator=STRING\n" +
126
- ` field separator for unaligned output (default: "${o.defaultFieldSep}")\n`);
127
- w(" -H, --html HTML table output mode\n");
128
- w(" -P, --pset=VAR[=ARG] set printing option VAR to ARG (see \\pset command)\n");
129
- w(" -R, --record-separator=STRING\n" +
130
- " record separator for unaligned output (default: newline)\n");
131
- w(" -t, --tuples-only print rows only\n");
132
- w(" -T, --table-attr=TEXT set HTML table tag attributes (e.g., width, border)\n");
133
- w(" -x, --expanded turn on expanded table output\n");
134
- w(" -z, --field-separator-zero\n" +
135
- " set field separator for unaligned output to zero byte\n");
136
- w(" -0, --record-separator-zero\n" +
137
- " set record separator for unaligned output to zero byte\n");
138
- w("\nConnection options:\n");
139
- w(" -h, --host=HOSTNAME database server host or socket directory\n");
140
- w(" -p, --port=PORT database server port\n");
141
- w(" -U, --username=USERNAME database user name\n");
142
- w(" -w, --no-password never prompt for password\n");
143
- w(" -W, --password force password prompt (should happen automatically)\n");
144
- w('\nFor more information, type "\\?" (for internal commands) or "\\help" (for SQL\n' +
145
- "commands) from within psql, or consult the psql section in the PostgreSQL\n" +
146
- "documentation.\n\n");
147
- w(`Report bugs to <${o.packageBugReport}>.\n`);
148
- w(`${o.packageName} home page: <${o.packageUrl}>\n`);
149
- out.write(buf.join(""));
78
+ * `psql --help` text — top-level command-line options.
79
+ *
80
+ * Always written inline: this is the `--help` path (and `\? options`), which
81
+ * upstream emits without a pager. Interactive `\?` paging is handled by
82
+ * {@link slashUsage} via its `pager` flag.
83
+ */
84
+ const usage = (out, opts) => {
85
+ const o = resolve(opts);
86
+ const buf = [];
87
+ const w = (s) => {
88
+ buf.push(s);
89
+ };
90
+ w(`${o.progname} is the PostgreSQL interactive terminal.\n\n`);
91
+ w("Usage:\n");
92
+ w(` ${o.progname} [OPTION]... [DBNAME [USERNAME]]\n\n`);
93
+ w("General options:\n");
94
+ w(" -c, --command=COMMAND run only single command (SQL or internal) and exit\n");
95
+ w(" -d, --dbname=DBNAME database name to connect to\n");
96
+ w(" -f, --file=FILENAME execute commands from file, then exit\n");
97
+ w(" -l, --list list available databases, then exit\n");
98
+ w(" -v, --set=, --variable=NAME=VALUE\n set psql variable NAME to VALUE\n (e.g., -v ON_ERROR_STOP=1)\n");
99
+ w(" -V, --version output version information, then exit\n");
100
+ w(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n");
101
+ w(" -1 (\"one\"), --single-transaction\n execute as a single transaction (if non-interactive)\n");
102
+ w(" -?, --help[=options] show this help, then exit\n");
103
+ w(" --help=commands list backslash commands, then exit\n");
104
+ w(" --help=variables list special variables, then exit\n");
105
+ w("\nInput and output options:\n");
106
+ w(" -a, --echo-all echo all input from script\n");
107
+ w(" -b, --echo-errors echo failed commands\n");
108
+ w(" -e, --echo-queries echo commands sent to server\n");
109
+ w(" -E, --echo-hidden display queries that internal commands generate\n");
110
+ w(" -L, --log-file=FILENAME send session log to file\n");
111
+ w(" -n, --no-readline disable enhanced command line editing (readline)\n");
112
+ w(" -o, --output=FILENAME send query results to file (or |pipe)\n");
113
+ w(" -q, --quiet run quietly (no messages, only query output)\n");
114
+ w(" -s, --single-step single-step mode (confirm each query)\n");
115
+ w(" -S, --single-line single-line mode (end of line terminates SQL command)\n");
116
+ w("\nOutput format options:\n");
117
+ w(" -A, --no-align unaligned table output mode\n");
118
+ w(" --csv CSV (Comma-Separated Values) table output mode\n");
119
+ w(` -F, --field-separator=STRING
120
+ field separator for unaligned output (default: "${o.defaultFieldSep}")\n`);
121
+ w(" -H, --html HTML table output mode\n");
122
+ w(" -P, --pset=VAR[=ARG] set printing option VAR to ARG (see \\pset command)\n");
123
+ w(" -R, --record-separator=STRING\n record separator for unaligned output (default: newline)\n");
124
+ w(" -t, --tuples-only print rows only\n");
125
+ w(" -T, --table-attr=TEXT set HTML table tag attributes (e.g., width, border)\n");
126
+ w(" -x, --expanded turn on expanded table output\n");
127
+ w(" -z, --field-separator-zero\n set field separator for unaligned output to zero byte\n");
128
+ w(" -0, --record-separator-zero\n set record separator for unaligned output to zero byte\n");
129
+ w("\nConnection options:\n");
130
+ w(" -h, --host=HOSTNAME database server host or socket directory\n");
131
+ w(" -p, --port=PORT database server port\n");
132
+ w(" -U, --username=USERNAME database user name\n");
133
+ w(" -w, --no-password never prompt for password\n");
134
+ w(" -W, --password force password prompt (should happen automatically)\n");
135
+ w("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\ncommands) from within psql, or consult the psql section in the PostgreSQL\ndocumentation.\n\n");
136
+ w(`Report bugs to <${o.packageBugReport}>.\n`);
137
+ w(`${o.packageName} home page: <${o.packageUrl}>\n`);
138
+ out.write(buf.join(""));
150
139
  };
151
140
  /**
152
- * `\?` general output — help for the backslash commands.
153
- *
154
- * When `pager` is true and `out` is interactive, the rendered text is routed
155
- * through the external pager (see {@link emitHelp}); otherwise it is written
156
- * straight to `out`.
157
- */
158
- export const slashUsage = (out, pager, opts) => {
159
- const o = resolve(opts);
160
- const buf = [];
161
- const w = (s) => {
162
- buf.push(s);
163
- };
164
- w("General\n");
165
- w(" \\copyright show PostgreSQL usage and distribution terms\n");
166
- w(" \\crosstabview [COLUMNS] execute query and display result in crosstab\n");
167
- w(" \\errverbose show most recent error message at maximum verbosity\n");
168
- w(" \\g [(OPTIONS)] [FILE] execute query (and send result to file or |pipe);\n" +
169
- " \\g with no arguments is equivalent to a semicolon\n");
170
- w(" \\gdesc describe result of query, without executing it\n");
171
- w(" \\gexec execute query, then execute each value in its result\n");
172
- w(" \\gset [PREFIX] execute query and store result in psql variables\n");
173
- w(" \\gx [(OPTIONS)] [FILE] as \\g, but forces expanded output mode\n");
174
- w(" \\q quit psql\n");
175
- w(" \\restrict RESTRICT_KEY\n" +
176
- " enter restricted mode with provided key\n");
177
- w(" \\unrestrict RESTRICT_KEY\n" +
178
- " exit restricted mode if key matches\n");
179
- w(" \\watch [[i=]SEC] [c=N] [m=MIN]\n" +
180
- " execute query every SEC seconds, up to N times,\n" +
181
- " stop if less than MIN rows are returned\n");
182
- w("\n");
183
- w("Help\n");
184
- w(" \\? [commands] show help on backslash commands\n");
185
- w(" \\? options show help on psql command-line options\n");
186
- w(" \\? variables show help on special variables\n");
187
- w(" \\h [NAME] help on syntax of SQL commands, * for all commands\n");
188
- w("\n");
189
- w("Query Buffer\n");
190
- w(" \\e [FILE] [LINE] edit the query buffer (or file) with external editor\n");
191
- w(" \\ef [FUNCNAME [LINE]] edit function definition with external editor\n");
192
- w(" \\ev [VIEWNAME [LINE]] edit view definition with external editor\n");
193
- w(" \\p show the contents of the query buffer\n");
194
- w(" \\r reset (clear) the query buffer\n");
195
- if (o.useReadline) {
196
- w(" \\s [FILE] display history or save it to file\n");
197
- }
198
- w(" \\w FILE write query buffer to file\n");
199
- w("\n");
200
- w("Input/Output\n");
201
- w(" \\copy ... perform SQL COPY with data stream to the client host\n");
202
- w(" \\echo [-n] [STRING] write string to standard output (-n for no newline)\n");
203
- w(" \\i FILE execute commands from file\n");
204
- w(" \\ir FILE as \\i, but relative to location of current script\n");
205
- w(" \\o [FILE] send all query results to file or |pipe\n");
206
- w(" \\qecho [-n] [STRING] write string to \\o output stream (-n for no newline)\n");
207
- w(" \\warn [-n] [STRING] write string to standard error (-n for no newline)\n");
208
- w("\n");
209
- w("Conditional\n");
210
- w(" \\if EXPR begin conditional block\n");
211
- w(" \\elif EXPR alternative within current conditional block\n");
212
- w(" \\else final alternative within current conditional block\n");
213
- w(" \\endif end conditional block\n");
214
- w("\n");
215
- w("Informational\n");
216
- w(" (options: S = show system objects, x = expanded mode, + = additional detail)\n");
217
- w(" \\d[Sx+] list tables, views, sequences, and property graphs\n");
218
- w(" \\d[S+] NAME describe table, view, sequence, index, or property graph\n");
219
- w(" \\da[Sx] [PATTERN] list aggregates\n");
220
- w(" \\dA[x+] [PATTERN] list access methods\n");
221
- w(" \\dAc[x+] [AMPTRN [TYPEPTRN]] list operator classes\n");
222
- w(" \\dAf[x+] [AMPTRN [TYPEPTRN]] list operator families\n");
223
- w(" \\dAo[x+] [AMPTRN [OPFPTRN]] list operators of operator families\n");
224
- w(" \\dAp[x+] [AMPTRN [OPFPTRN]] list support functions of operator families\n");
225
- w(" \\db[x+] [PATTERN] list tablespaces\n");
226
- w(" \\dc[Sx+] [PATTERN] list conversions\n");
227
- w(" \\dconfig[x+] [PATTERN] list configuration parameters\n");
228
- w(" \\dC[x+] [PATTERN] list casts\n");
229
- w(" \\dd[Sx] [PATTERN] show object descriptions not displayed elsewhere\n");
230
- w(" \\dD[Sx+] [PATTERN] list domains\n");
231
- w(" \\ddp[x] [PATTERN] list default privileges\n");
232
- w(" \\dE[Sx+] [PATTERN] list foreign tables\n");
233
- w(" \\des[x+] [PATTERN] list foreign servers\n");
234
- w(" \\det[x+] [PATTERN] list foreign tables\n");
235
- w(" \\deu[x+] [PATTERN] list user mappings\n");
236
- w(" \\dew[x+] [PATTERN] list foreign-data wrappers\n");
237
- w(" \\df[anptw][Sx+] [FUNCPTRN [TYPEPTRN ...]]\n" +
238
- " list [only agg/normal/procedure/trigger/window] functions\n");
239
- w(" \\dF[x+] [PATTERN] list text search configurations\n");
240
- w(" \\dFd[x+] [PATTERN] list text search dictionaries\n");
241
- w(" \\dFp[x+] [PATTERN] list text search parsers\n");
242
- w(" \\dFt[x+] [PATTERN] list text search templates\n");
243
- w(" \\dg[Sx+] [PATTERN] list roles\n");
244
- w(" \\dG[Sx+] [PATTERN] list property graphs\n");
245
- w(" \\di[Sx+] [PATTERN] list indexes\n");
246
- w(" \\dl[x+] list large objects, same as \\lo_list\n");
247
- w(" \\dL[Sx+] [PATTERN] list procedural languages\n");
248
- w(" \\dm[Sx+] [PATTERN] list materialized views\n");
249
- w(" \\dn[Sx+] [PATTERN] list schemas\n");
250
- w(" \\do[Sx+] [OPPTRN [TYPEPTRN [TYPEPTRN]]]\n" +
251
- " list operators\n");
252
- w(" \\dO[Sx+] [PATTERN] list collations\n");
253
- w(" \\dp[Sx] [PATTERN] list table, view, and sequence access privileges\n");
254
- w(" \\dP[itnx+] [PATTERN] list [only index/table] partitioned relations [n=nested]\n");
255
- w(" \\drds[x] [ROLEPTRN [DBPTRN]]\n" +
256
- " list per-database role settings\n");
257
- w(" \\drg[Sx] [PATTERN] list role grants\n");
258
- w(" \\dRp[x+] [PATTERN] list replication publications\n");
259
- w(" \\dRs[x+] [PATTERN] list replication subscriptions\n");
260
- w(" \\ds[Sx+] [PATTERN] list sequences\n");
261
- w(" \\dt[Sx+] [PATTERN] list tables\n");
262
- w(" \\dT[Sx+] [PATTERN] list data types\n");
263
- w(" \\du[Sx+] [PATTERN] list roles\n");
264
- w(" \\dv[Sx+] [PATTERN] list views\n");
265
- w(" \\dx[x+] [PATTERN] list extensions\n");
266
- w(" \\dX[x+] [PATTERN] list extended statistics\n");
267
- w(" \\dy[x+] [PATTERN] list event triggers\n");
268
- w(" \\l[x+] [PATTERN] list databases\n");
269
- w(" \\sf[+] FUNCNAME show a function's definition\n");
270
- w(" \\sv[+] VIEWNAME show a view's definition\n");
271
- w(" \\z[Sx] [PATTERN] same as \\dp\n");
272
- w("\n");
273
- w("Large Objects\n");
274
- w(" \\lo_export LOBOID FILE write large object to file\n");
275
- w(" \\lo_import FILE [COMMENT]\n" +
276
- " read large object from file\n");
277
- w(" \\lo_list[x+] list large objects\n");
278
- w(" \\lo_unlink LOBOID delete a large object\n");
279
- w("\n");
280
- w("Formatting\n");
281
- w(" \\a toggle between unaligned and aligned output mode\n");
282
- w(" \\C [STRING] set table title, or unset if none\n");
283
- w(" \\f [STRING] show or set field separator for unaligned query output\n");
284
- w(` \\H toggle HTML output mode (currently ${on(o.htmlMode)})\n`);
285
- w(" \\pset [NAME [VALUE]] set table output option\n" +
286
- ' see "\\? variables" for valid options\n');
287
- w(` \\t [on|off] show only rows (currently ${on(o.tuplesOnly)})\n`);
288
- w(" \\T [STRING] set HTML <table> tag attributes, or unset if none\n");
289
- w(` \\x [on|off|auto] toggle expanded output (currently ${expandedLabel(o.expanded)})\n`);
290
- w("\n");
291
- w("Connection\n");
292
- if (o.currentDb) {
293
- w(" \\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}\n" +
294
- ` connect to new database (currently "${o.currentDb}")\n`);
295
- }
296
- else {
297
- w(" \\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}\n" +
298
- " connect to new database (currently no connection)\n");
299
- }
300
- w(" \\conninfo display information about current connection\n");
301
- w(" \\encoding [ENCODING] show or set client encoding\n");
302
- w(" \\password [USERNAME] securely change the password for a user\n");
303
- w("\n");
304
- w("Operating System\n");
305
- w(" \\cd [DIR] change the current working directory\n");
306
- w(" \\getenv PSQLVAR ENVVAR fetch environment variable\n");
307
- w(" \\setenv NAME [VALUE] set or unset environment variable\n");
308
- w(` \\timing [on|off] toggle timing of commands (currently ${on(o.timing)})\n`);
309
- w(" \\! [COMMAND] execute command in shell or start interactive shell\n");
310
- w("\n");
311
- w("Variables\n");
312
- w(" \\prompt [TEXT] NAME prompt user to set internal variable\n");
313
- w(" \\set [NAME [VALUE]] set internal variable, or list all if no parameters\n");
314
- w(" \\unset NAME unset (delete) internal variable\n");
315
- w("\n");
316
- w("Extended Query Protocol\n");
317
- w(" \\bind [PARAM]... set query parameters\n");
318
- w(" \\bind_named STMT_NAME [PARAM]...\n" +
319
- " set query parameters for an existing prepared statement\n");
320
- w(" \\close_prepared STMT_NAME\n" +
321
- " close an existing prepared statement\n");
322
- w(" \\endpipeline exit pipeline mode\n");
323
- w(" \\flush flush output data to the server\n");
324
- w(" \\flushrequest send request to the server to flush its output buffer\n");
325
- w(" \\getresults [NUM_RES] read NUM_RES pending results, or all if no argument\n");
326
- w(" \\parse STMT_NAME create a prepared statement\n");
327
- w(" \\sendpipeline send an extended query to an ongoing pipeline\n");
328
- w(" \\startpipeline enter pipeline mode\n");
329
- w(" \\syncpipeline add a synchronisation point to an ongoing pipeline\n");
330
- emitHelp(out, buf.join(""), pager);
141
+ * `\?` general output — help for the backslash commands.
142
+ *
143
+ * When `pager` is true and `out` is interactive, the rendered text is routed
144
+ * through the external pager (see {@link emitHelp}); otherwise it is written
145
+ * straight to `out`.
146
+ */
147
+ const slashUsage = (out, pager, opts) => {
148
+ const o = resolve(opts);
149
+ const buf = [];
150
+ const w = (s) => {
151
+ buf.push(s);
152
+ };
153
+ w("General\n");
154
+ w(" \\copyright show PostgreSQL usage and distribution terms\n");
155
+ w(" \\crosstabview [COLUMNS] execute query and display result in crosstab\n");
156
+ w(" \\errverbose show most recent error message at maximum verbosity\n");
157
+ w(" \\g [(OPTIONS)] [FILE] execute query (and send result to file or |pipe);\n \\g with no arguments is equivalent to a semicolon\n");
158
+ w(" \\gdesc describe result of query, without executing it\n");
159
+ w(" \\gexec execute query, then execute each value in its result\n");
160
+ w(" \\gset [PREFIX] execute query and store result in psql variables\n");
161
+ w(" \\gx [(OPTIONS)] [FILE] as \\g, but forces expanded output mode\n");
162
+ w(" \\q quit psql\n");
163
+ w(" \\restrict RESTRICT_KEY\n enter restricted mode with provided key\n");
164
+ w(" \\unrestrict RESTRICT_KEY\n exit restricted mode if key matches\n");
165
+ w(" \\watch [[i=]SEC] [c=N] [m=MIN]\n execute query every SEC seconds, up to N times,\n stop if less than MIN rows are returned\n");
166
+ w("\n");
167
+ w("Help\n");
168
+ w(" \\? [commands] show help on backslash commands\n");
169
+ w(" \\? options show help on psql command-line options\n");
170
+ w(" \\? variables show help on special variables\n");
171
+ w(" \\h [NAME] help on syntax of SQL commands, * for all commands\n");
172
+ w("\n");
173
+ w("Query Buffer\n");
174
+ w(" \\e [FILE] [LINE] edit the query buffer (or file) with external editor\n");
175
+ w(" \\ef [FUNCNAME [LINE]] edit function definition with external editor\n");
176
+ w(" \\ev [VIEWNAME [LINE]] edit view definition with external editor\n");
177
+ w(" \\p show the contents of the query buffer\n");
178
+ w(" \\r reset (clear) the query buffer\n");
179
+ if (o.useReadline) w(" \\s [FILE] display history or save it to file\n");
180
+ w(" \\w FILE write query buffer to file\n");
181
+ w("\n");
182
+ w("Input/Output\n");
183
+ w(" \\copy ... perform SQL COPY with data stream to the client host\n");
184
+ w(" \\echo [-n] [STRING] write string to standard output (-n for no newline)\n");
185
+ w(" \\i FILE execute commands from file\n");
186
+ w(" \\ir FILE as \\i, but relative to location of current script\n");
187
+ w(" \\o [FILE] send all query results to file or |pipe\n");
188
+ w(" \\qecho [-n] [STRING] write string to \\o output stream (-n for no newline)\n");
189
+ w(" \\warn [-n] [STRING] write string to standard error (-n for no newline)\n");
190
+ w("\n");
191
+ w("Conditional\n");
192
+ w(" \\if EXPR begin conditional block\n");
193
+ w(" \\elif EXPR alternative within current conditional block\n");
194
+ w(" \\else final alternative within current conditional block\n");
195
+ w(" \\endif end conditional block\n");
196
+ w("\n");
197
+ w("Informational\n");
198
+ w(" (options: S = show system objects, x = expanded mode, + = additional detail)\n");
199
+ w(" \\d[Sx+] list tables, views, sequences, and property graphs\n");
200
+ w(" \\d[S+] NAME describe table, view, sequence, index, or property graph\n");
201
+ w(" \\da[Sx] [PATTERN] list aggregates\n");
202
+ w(" \\dA[x+] [PATTERN] list access methods\n");
203
+ w(" \\dAc[x+] [AMPTRN [TYPEPTRN]] list operator classes\n");
204
+ w(" \\dAf[x+] [AMPTRN [TYPEPTRN]] list operator families\n");
205
+ w(" \\dAo[x+] [AMPTRN [OPFPTRN]] list operators of operator families\n");
206
+ w(" \\dAp[x+] [AMPTRN [OPFPTRN]] list support functions of operator families\n");
207
+ w(" \\db[x+] [PATTERN] list tablespaces\n");
208
+ w(" \\dc[Sx+] [PATTERN] list conversions\n");
209
+ w(" \\dconfig[x+] [PATTERN] list configuration parameters\n");
210
+ w(" \\dC[x+] [PATTERN] list casts\n");
211
+ w(" \\dd[Sx] [PATTERN] show object descriptions not displayed elsewhere\n");
212
+ w(" \\dD[Sx+] [PATTERN] list domains\n");
213
+ w(" \\ddp[x] [PATTERN] list default privileges\n");
214
+ w(" \\dE[Sx+] [PATTERN] list foreign tables\n");
215
+ w(" \\des[x+] [PATTERN] list foreign servers\n");
216
+ w(" \\det[x+] [PATTERN] list foreign tables\n");
217
+ w(" \\deu[x+] [PATTERN] list user mappings\n");
218
+ w(" \\dew[x+] [PATTERN] list foreign-data wrappers\n");
219
+ w(" \\df[anptw][Sx+] [FUNCPTRN [TYPEPTRN ...]]\n list [only agg/normal/procedure/trigger/window] functions\n");
220
+ w(" \\dF[x+] [PATTERN] list text search configurations\n");
221
+ w(" \\dFd[x+] [PATTERN] list text search dictionaries\n");
222
+ w(" \\dFp[x+] [PATTERN] list text search parsers\n");
223
+ w(" \\dFt[x+] [PATTERN] list text search templates\n");
224
+ w(" \\dg[Sx+] [PATTERN] list roles\n");
225
+ w(" \\dG[Sx+] [PATTERN] list property graphs\n");
226
+ w(" \\di[Sx+] [PATTERN] list indexes\n");
227
+ w(" \\dl[x+] list large objects, same as \\lo_list\n");
228
+ w(" \\dL[Sx+] [PATTERN] list procedural languages\n");
229
+ w(" \\dm[Sx+] [PATTERN] list materialized views\n");
230
+ w(" \\dn[Sx+] [PATTERN] list schemas\n");
231
+ w(" \\do[Sx+] [OPPTRN [TYPEPTRN [TYPEPTRN]]]\n list operators\n");
232
+ w(" \\dO[Sx+] [PATTERN] list collations\n");
233
+ w(" \\dp[Sx] [PATTERN] list table, view, and sequence access privileges\n");
234
+ w(" \\dP[itnx+] [PATTERN] list [only index/table] partitioned relations [n=nested]\n");
235
+ w(" \\drds[x] [ROLEPTRN [DBPTRN]]\n list per-database role settings\n");
236
+ w(" \\drg[Sx] [PATTERN] list role grants\n");
237
+ w(" \\dRp[x+] [PATTERN] list replication publications\n");
238
+ w(" \\dRs[x+] [PATTERN] list replication subscriptions\n");
239
+ w(" \\ds[Sx+] [PATTERN] list sequences\n");
240
+ w(" \\dt[Sx+] [PATTERN] list tables\n");
241
+ w(" \\dT[Sx+] [PATTERN] list data types\n");
242
+ w(" \\du[Sx+] [PATTERN] list roles\n");
243
+ w(" \\dv[Sx+] [PATTERN] list views\n");
244
+ w(" \\dx[x+] [PATTERN] list extensions\n");
245
+ w(" \\dX[x+] [PATTERN] list extended statistics\n");
246
+ w(" \\dy[x+] [PATTERN] list event triggers\n");
247
+ w(" \\l[x+] [PATTERN] list databases\n");
248
+ w(" \\sf[+] FUNCNAME show a function's definition\n");
249
+ w(" \\sv[+] VIEWNAME show a view's definition\n");
250
+ w(" \\z[Sx] [PATTERN] same as \\dp\n");
251
+ w("\n");
252
+ w("Large Objects\n");
253
+ w(" \\lo_export LOBOID FILE write large object to file\n");
254
+ w(" \\lo_import FILE [COMMENT]\n read large object from file\n");
255
+ w(" \\lo_list[x+] list large objects\n");
256
+ w(" \\lo_unlink LOBOID delete a large object\n");
257
+ w("\n");
258
+ w("Formatting\n");
259
+ w(" \\a toggle between unaligned and aligned output mode\n");
260
+ w(" \\C [STRING] set table title, or unset if none\n");
261
+ w(" \\f [STRING] show or set field separator for unaligned query output\n");
262
+ w(` \\H toggle HTML output mode (currently ${on(o.htmlMode)})\n`);
263
+ w(" \\pset [NAME [VALUE]] set table output option\n see \"\\? variables\" for valid options\n");
264
+ w(` \\t [on|off] show only rows (currently ${on(o.tuplesOnly)})\n`);
265
+ w(" \\T [STRING] set HTML <table> tag attributes, or unset if none\n");
266
+ w(` \\x [on|off|auto] toggle expanded output (currently ${expandedLabel(o.expanded)})\n`);
267
+ w("\n");
268
+ w("Connection\n");
269
+ if (o.currentDb) w(` \\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}
270
+ connect to new database (currently "${o.currentDb}")\n`);
271
+ else w(" \\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}\n connect to new database (currently no connection)\n");
272
+ w(" \\conninfo display information about current connection\n");
273
+ w(" \\encoding [ENCODING] show or set client encoding\n");
274
+ w(" \\password [USERNAME] securely change the password for a user\n");
275
+ w("\n");
276
+ w("Operating System\n");
277
+ w(" \\cd [DIR] change the current working directory\n");
278
+ w(" \\getenv PSQLVAR ENVVAR fetch environment variable\n");
279
+ w(" \\setenv NAME [VALUE] set or unset environment variable\n");
280
+ w(` \\timing [on|off] toggle timing of commands (currently ${on(o.timing)})\n`);
281
+ w(" \\! [COMMAND] execute command in shell or start interactive shell\n");
282
+ w("\n");
283
+ w("Variables\n");
284
+ w(" \\prompt [TEXT] NAME prompt user to set internal variable\n");
285
+ w(" \\set [NAME [VALUE]] set internal variable, or list all if no parameters\n");
286
+ w(" \\unset NAME unset (delete) internal variable\n");
287
+ w("\n");
288
+ w("Extended Query Protocol\n");
289
+ w(" \\bind [PARAM]... set query parameters\n");
290
+ w(" \\bind_named STMT_NAME [PARAM]...\n set query parameters for an existing prepared statement\n");
291
+ w(" \\close_prepared STMT_NAME\n close an existing prepared statement\n");
292
+ w(" \\endpipeline exit pipeline mode\n");
293
+ w(" \\flush flush output data to the server\n");
294
+ w(" \\flushrequest send request to the server to flush its output buffer\n");
295
+ w(" \\getresults [NUM_RES] read NUM_RES pending results, or all if no argument\n");
296
+ w(" \\parse STMT_NAME create a prepared statement\n");
297
+ w(" \\sendpipeline send an extended query to an ongoing pipeline\n");
298
+ w(" \\startpipeline enter pipeline mode\n");
299
+ w(" \\syncpipeline add a synchronisation point to an ongoing pipeline\n");
300
+ emitHelp(out, buf.join(""), pager);
331
301
  };
332
302
  /**
333
- * `\?` with a topic argument. Routes to the appropriate help renderer:
334
- * - `commands` → `slashUsage` (backslash commands)
335
- * - `options` → `usage` (CLI options)
336
- * - `variables` → `helpVariables`
337
- */
338
- export const slashUsageHelp = (out, topic, opts) => {
339
- switch (topic) {
340
- case "commands":
341
- slashUsage(out, false, opts);
342
- return;
343
- case "options":
344
- usage(out, opts);
345
- return;
346
- case "variables":
347
- helpVariables(out, opts);
348
- return;
349
- }
303
+ * `\?` with a topic argument. Routes to the appropriate help renderer:
304
+ * - `commands` → `slashUsage` (backslash commands)
305
+ * - `options` → `usage` (CLI options)
306
+ * - `variables` → `helpVariables`
307
+ */
308
+ const slashUsageHelp = (out, topic, opts) => {
309
+ switch (topic) {
310
+ case "commands":
311
+ slashUsage(out, false, opts);
312
+ return;
313
+ case "options":
314
+ usage(out, opts);
315
+ return;
316
+ case "variables":
317
+ helpVariables(out, opts);
318
+ return;
319
+ }
350
320
  };
351
321
  /**
352
- * `\? variables` output — list of specially treated psql variables, display
353
- * settings, and environment variables.
354
- */
355
- export const helpVariables = (out, opts) => {
356
- const o = resolve(opts);
357
- const buf = [];
358
- const w = (s) => {
359
- buf.push(s);
360
- };
361
- w("List of specially treated variables\n\n");
362
- w("psql variables:\n");
363
- w("Usage:\n");
364
- w(` ${o.progname} --set=NAME=VALUE\n or \\set NAME VALUE inside psql\n\n`);
365
- w(" AUTOCOMMIT\n" +
366
- " if set, successful SQL commands are automatically committed\n");
367
- w(" COMP_KEYWORD_CASE\n" +
368
- " determines the case used to complete SQL key words\n" +
369
- " [lower, upper, preserve-lower, preserve-upper]\n");
370
- w(" DBNAME\n the currently connected database name\n");
371
- w(" ECHO\n" +
372
- " controls what input is written to standard output\n" +
373
- " [all, errors, none, queries]\n");
374
- w(" ECHO_HIDDEN\n" +
375
- " if set, display internal queries executed by backslash commands;\n" +
376
- ' if set to "noexec", just show them without execution\n');
377
- w(" ENCODING\n current client character set encoding\n");
378
- w(' ERROR\n "true" if last query failed, else "false"\n');
379
- w(" FETCH_COUNT\n" +
380
- " the number of result rows to fetch and display at a time (0 = unlimited)\n");
381
- w(" HIDE_TABLEAM\n if set, table access methods are not displayed\n");
382
- w(" HIDE_TOAST_COMPRESSION\n" +
383
- " if set, compression methods are not displayed\n");
384
- w(" HISTCONTROL\n" +
385
- " controls command history [ignorespace, ignoredups, ignoreboth]\n");
386
- w(" HISTFILE\n file name used to store the command history\n");
387
- w(" HISTSIZE\n" +
388
- " maximum number of commands to store in the command history\n");
389
- w(" HOST\n the currently connected database server host\n");
390
- w(" IGNOREEOF\n" +
391
- " number of EOFs needed to terminate an interactive session\n");
392
- w(" LASTOID\n value of the last affected OID\n");
393
- w(" LAST_ERROR_MESSAGE\n" +
394
- " LAST_ERROR_SQLSTATE\n" +
395
- ' message and SQLSTATE of last error, or empty string and "00000" if none\n');
396
- w(" ON_ERROR_ROLLBACK\n" +
397
- " if set, an error doesn't stop a transaction (uses implicit savepoints)\n");
398
- w(" ON_ERROR_STOP\n stop batch execution after error\n");
399
- w(" PORT\n server port of the current connection\n");
400
- w(" PROMPT1\n specifies the standard psql prompt\n");
401
- w(" PROMPT2\n" +
402
- " specifies the prompt used when a statement continues from a previous line\n");
403
- w(" PROMPT3\n specifies the prompt used during COPY ... FROM STDIN\n");
404
- w(" QUIET\n run quietly (same as -q option)\n");
405
- w(" ROW_COUNT\n" +
406
- " number of rows returned or affected by last query, or 0\n");
407
- w(" SERVER_VERSION_NAME\n" +
408
- " SERVER_VERSION_NUM\n" +
409
- " server's version (in short string or numeric format)\n");
410
- w(" SHELL_ERROR\n" +
411
- ' "true" if the last shell command failed, "false" if it succeeded\n');
412
- w(" SHELL_EXIT_CODE\n exit status of the last shell command\n");
413
- w(" SHOW_ALL_RESULTS\n" +
414
- " show all results of a combined query (\\;) instead of only the last\n");
415
- w(" SHOW_CONTEXT\n" +
416
- " controls display of message context fields [never, errors, always]\n");
417
- w(" SINGLELINE\n" +
418
- " if set, end of line terminates SQL commands (same as -S option)\n");
419
- w(" SINGLESTEP\n single-step mode (same as -s option)\n");
420
- w(' SQLSTATE\n SQLSTATE of last query, or "00000" if no error\n');
421
- w(" USER\n the currently connected database user\n");
422
- w(" VERBOSITY\n" +
423
- " controls verbosity of error reports [default, verbose, terse, sqlstate]\n");
424
- w(" VERSION\n" +
425
- " VERSION_NAME\n" +
426
- " VERSION_NUM\n" +
427
- " psql's version (in verbose string, short string, or numeric format)\n");
428
- w(" WATCH_INTERVAL\n" +
429
- ` number of seconds \\watch waits between executions (default ${o.defaultWatchInterval})\n`);
430
- w("\nDisplay settings:\n");
431
- w("Usage:\n");
432
- w(` ${o.progname} --pset=NAME[=VALUE]\n or \\pset NAME [VALUE] inside psql\n\n`);
433
- w(" border\n border style (number)\n");
434
- w(" columns\n target width for the wrapped format\n");
435
- w(" csv_fieldsep\n" +
436
- ` field separator for CSV output format (default "${o.defaultCsvFieldSep}")\n`);
437
- w(" display_false\n" +
438
- " set the string to be printed in place of a boolean 'false'\n");
439
- w(" display_true\n" +
440
- " set the string to be printed in place of a boolean 'true'\n");
441
- w(" expanded (or x)\n expanded output [on, off, auto]\n");
442
- w(" fieldsep\n" +
443
- ` field separator for unaligned output (default "${o.defaultFieldSep}")\n`);
444
- w(" fieldsep_zero\n" +
445
- " set field separator for unaligned output to a zero byte\n");
446
- w(" footer\n" +
447
- " enable or disable display of the table footer [on, off]\n");
448
- w(" format\n" +
449
- " set output format [unaligned, aligned, wrapped, html, asciidoc, ...]\n");
450
- w(" linestyle\n" +
451
- " set the border line drawing style [ascii, old-ascii, unicode]\n");
452
- w(" null\n set the string to be printed in place of a null value\n");
453
- w(" numericlocale\n" +
454
- " enable display of a locale-specific character to separate groups of digits\n");
455
- w(" pager\n" +
456
- " control when an external pager is used [yes, no, always]\n");
457
- w(" recordsep\n record (line) separator for unaligned output\n");
458
- w(" recordsep_zero\n" +
459
- " set record separator for unaligned output to a zero byte\n");
460
- w(" tableattr (or T)\n" +
461
- " specify attributes for table tag in html format, or proportional\n" +
462
- " column widths for left-aligned data types in latex-longtable format\n");
463
- w(" title\n set the table title for subsequently printed tables\n");
464
- w(" tuples_only\n if set, only actual table data is shown\n");
465
- w(" unicode_border_linestyle\n" +
466
- " unicode_column_linestyle\n" +
467
- " unicode_header_linestyle\n" +
468
- " set the style of Unicode line drawing [single, double]\n");
469
- w(" xheader_width\n" +
470
- " set the maximum width of the header for expanded output\n" +
471
- " [full, column, page, integer value]\n");
472
- w("\nEnvironment variables:\n");
473
- w("Usage:\n");
474
- if (!o.win32) {
475
- w(` NAME=VALUE [NAME=VALUE] ${o.progname} ...\n or \\setenv NAME [VALUE] inside psql\n\n`);
476
- }
477
- else {
478
- w(` set NAME=VALUE\n ${o.progname} ...\n or \\setenv NAME [VALUE] inside psql\n\n`);
479
- }
480
- w(" COLUMNS\n number of columns for wrapped format\n");
481
- w(" PGAPPNAME\n same as the application_name connection parameter\n");
482
- w(" PGDATABASE\n same as the dbname connection parameter\n");
483
- w(" PGHOST\n same as the host connection parameter\n");
484
- w(" PGPASSFILE\n password file name\n");
485
- w(" PGPASSWORD\n connection password (not recommended)\n");
486
- w(" PGPORT\n same as the port connection parameter\n");
487
- w(" PGUSER\n same as the user connection parameter\n");
488
- w(" PSQL_EDITOR, EDITOR, VISUAL\n" +
489
- " editor used by the \\e, \\ef, and \\ev commands\n");
490
- w(" PSQL_EDITOR_LINENUMBER_ARG\n" +
491
- " how to specify a line number when invoking the editor\n");
492
- w(" PSQL_HISTORY\n" +
493
- " alternative location for the command history file\n");
494
- w(" PSQL_PAGER, PAGER\n name of external pager program\n");
495
- if (!o.win32) {
496
- w(" PSQL_WATCH_PAGER\n" +
497
- " name of external pager program used for \\watch\n");
498
- }
499
- w(" PSQLRC\n alternative location for the user's .psqlrc file\n");
500
- w(" SHELL\n shell used by the \\! command\n");
501
- w(" TMPDIR\n directory for temporary files\n");
502
- out.write(buf.join(""));
322
+ * `\? variables` output — list of specially treated psql variables, display
323
+ * settings, and environment variables.
324
+ */
325
+ const helpVariables = (out, opts) => {
326
+ const o = resolve(opts);
327
+ const buf = [];
328
+ const w = (s) => {
329
+ buf.push(s);
330
+ };
331
+ w("List of specially treated variables\n\n");
332
+ w("psql variables:\n");
333
+ w("Usage:\n");
334
+ w(` ${o.progname} --set=NAME=VALUE\n or \\set NAME VALUE inside psql\n\n`);
335
+ w(" AUTOCOMMIT\n if set, successful SQL commands are automatically committed\n");
336
+ w(" COMP_KEYWORD_CASE\n determines the case used to complete SQL key words\n [lower, upper, preserve-lower, preserve-upper]\n");
337
+ w(" DBNAME\n the currently connected database name\n");
338
+ w(" ECHO\n controls what input is written to standard output\n [all, errors, none, queries]\n");
339
+ w(" ECHO_HIDDEN\n if set, display internal queries executed by backslash commands;\n if set to \"noexec\", just show them without execution\n");
340
+ w(" ENCODING\n current client character set encoding\n");
341
+ w(" ERROR\n \"true\" if last query failed, else \"false\"\n");
342
+ w(" FETCH_COUNT\n the number of result rows to fetch and display at a time (0 = unlimited)\n");
343
+ w(" HIDE_TABLEAM\n if set, table access methods are not displayed\n");
344
+ w(" HIDE_TOAST_COMPRESSION\n if set, compression methods are not displayed\n");
345
+ w(" HISTCONTROL\n controls command history [ignorespace, ignoredups, ignoreboth]\n");
346
+ w(" HISTFILE\n file name used to store the command history\n");
347
+ w(" HISTSIZE\n maximum number of commands to store in the command history\n");
348
+ w(" HOST\n the currently connected database server host\n");
349
+ w(" IGNOREEOF\n number of EOFs needed to terminate an interactive session\n");
350
+ w(" LASTOID\n value of the last affected OID\n");
351
+ w(" LAST_ERROR_MESSAGE\n LAST_ERROR_SQLSTATE\n message and SQLSTATE of last error, or empty string and \"00000\" if none\n");
352
+ w(" ON_ERROR_ROLLBACK\n if set, an error doesn't stop a transaction (uses implicit savepoints)\n");
353
+ w(" ON_ERROR_STOP\n stop batch execution after error\n");
354
+ w(" PORT\n server port of the current connection\n");
355
+ w(" PROMPT1\n specifies the standard psql prompt\n");
356
+ w(" PROMPT2\n specifies the prompt used when a statement continues from a previous line\n");
357
+ w(" PROMPT3\n specifies the prompt used during COPY ... FROM STDIN\n");
358
+ w(" QUIET\n run quietly (same as -q option)\n");
359
+ w(" ROW_COUNT\n number of rows returned or affected by last query, or 0\n");
360
+ w(" SERVER_VERSION_NAME\n SERVER_VERSION_NUM\n server's version (in short string or numeric format)\n");
361
+ w(" SHELL_ERROR\n \"true\" if the last shell command failed, \"false\" if it succeeded\n");
362
+ w(" SHELL_EXIT_CODE\n exit status of the last shell command\n");
363
+ w(" SHOW_ALL_RESULTS\n show all results of a combined query (\\;) instead of only the last\n");
364
+ w(" SHOW_CONTEXT\n controls display of message context fields [never, errors, always]\n");
365
+ w(" SINGLELINE\n if set, end of line terminates SQL commands (same as -S option)\n");
366
+ w(" SINGLESTEP\n single-step mode (same as -s option)\n");
367
+ w(" SQLSTATE\n SQLSTATE of last query, or \"00000\" if no error\n");
368
+ w(" USER\n the currently connected database user\n");
369
+ w(" VERBOSITY\n controls verbosity of error reports [default, verbose, terse, sqlstate]\n");
370
+ w(" VERSION\n VERSION_NAME\n VERSION_NUM\n psql's version (in verbose string, short string, or numeric format)\n");
371
+ w(` WATCH_INTERVAL
372
+ number of seconds \\watch waits between executions (default ${o.defaultWatchInterval})\n`);
373
+ w("\nDisplay settings:\n");
374
+ w("Usage:\n");
375
+ w(` ${o.progname} --pset=NAME[=VALUE]\n or \\pset NAME [VALUE] inside psql\n\n`);
376
+ w(" border\n border style (number)\n");
377
+ w(" columns\n target width for the wrapped format\n");
378
+ w(` csv_fieldsep
379
+ field separator for CSV output format (default "${o.defaultCsvFieldSep}")\n`);
380
+ w(" display_false\n set the string to be printed in place of a boolean 'false'\n");
381
+ w(" display_true\n set the string to be printed in place of a boolean 'true'\n");
382
+ w(" expanded (or x)\n expanded output [on, off, auto]\n");
383
+ w(` fieldsep
384
+ field separator for unaligned output (default "${o.defaultFieldSep}")\n`);
385
+ w(" fieldsep_zero\n set field separator for unaligned output to a zero byte\n");
386
+ w(" footer\n enable or disable display of the table footer [on, off]\n");
387
+ w(" format\n set output format [unaligned, aligned, wrapped, html, asciidoc, ...]\n");
388
+ w(" linestyle\n set the border line drawing style [ascii, old-ascii, unicode]\n");
389
+ w(" null\n set the string to be printed in place of a null value\n");
390
+ w(" numericlocale\n enable display of a locale-specific character to separate groups of digits\n");
391
+ w(" pager\n control when an external pager is used [yes, no, always]\n");
392
+ w(" recordsep\n record (line) separator for unaligned output\n");
393
+ w(" recordsep_zero\n set record separator for unaligned output to a zero byte\n");
394
+ w(" tableattr (or T)\n specify attributes for table tag in html format, or proportional\n column widths for left-aligned data types in latex-longtable format\n");
395
+ w(" title\n set the table title for subsequently printed tables\n");
396
+ w(" tuples_only\n if set, only actual table data is shown\n");
397
+ w(" unicode_border_linestyle\n unicode_column_linestyle\n unicode_header_linestyle\n set the style of Unicode line drawing [single, double]\n");
398
+ w(" xheader_width\n set the maximum width of the header for expanded output\n [full, column, page, integer value]\n");
399
+ w("\nEnvironment variables:\n");
400
+ w("Usage:\n");
401
+ if (!o.win32) w(` NAME=VALUE [NAME=VALUE] ${o.progname} ...\n or \\setenv NAME [VALUE] inside psql\n\n`);
402
+ else w(` set NAME=VALUE\n ${o.progname} ...\n or \\setenv NAME [VALUE] inside psql\n\n`);
403
+ w(" COLUMNS\n number of columns for wrapped format\n");
404
+ w(" PGAPPNAME\n same as the application_name connection parameter\n");
405
+ w(" PGDATABASE\n same as the dbname connection parameter\n");
406
+ w(" PGHOST\n same as the host connection parameter\n");
407
+ w(" PGPASSFILE\n password file name\n");
408
+ w(" PGPASSWORD\n connection password (not recommended)\n");
409
+ w(" PGPORT\n same as the port connection parameter\n");
410
+ w(" PGUSER\n same as the user connection parameter\n");
411
+ w(" PSQL_EDITOR, EDITOR, VISUAL\n editor used by the \\e, \\ef, and \\ev commands\n");
412
+ w(" PSQL_EDITOR_LINENUMBER_ARG\n how to specify a line number when invoking the editor\n");
413
+ w(" PSQL_HISTORY\n alternative location for the command history file\n");
414
+ w(" PSQL_PAGER, PAGER\n name of external pager program\n");
415
+ if (!o.win32) w(" PSQL_WATCH_PAGER\n name of external pager program used for \\watch\n");
416
+ w(" PSQLRC\n alternative location for the user's .psqlrc file\n");
417
+ w(" SHELL\n shell used by the \\! command\n");
418
+ w(" TMPDIR\n directory for temporary files\n");
419
+ out.write(buf.join(""));
503
420
  };
504
421
  /**
505
- * Render the "Available help:" overview — every command name in the table,
506
- * laid out in fixed-width columns that fit `screenWidth`. Mirrors upstream
507
- * `print_topic_list` in `help.c`: 4-column default falling back to fewer
508
- * columns on narrow terminals. Column width is `max(cmd.length) + 2` so the
509
- * tallest CREATE * entries line up cleanly.
510
- */
422
+ * Render the "Available help:" overview — every command name in the table,
423
+ * laid out in fixed-width columns that fit `screenWidth`. Mirrors upstream
424
+ * `print_topic_list` in `help.c`: 4-column default falling back to fewer
425
+ * columns on narrow terminals. Column width is `max(cmd.length) + 2` so the
426
+ * tallest CREATE * entries line up cleanly.
427
+ */
511
428
  const writeCommandList = (out, screenWidth) => {
512
- out.write("Available help:\n");
513
- const names = SQL_HELP.map((e) => e.cmd);
514
- const maxLen = names.reduce((m, n) => Math.max(m, n.length), 0);
515
- const colW = maxLen + 2;
516
- // 2-space left margin per upstream; ensure at least one column fits.
517
- const usable = Math.max(colW, screenWidth - 2);
518
- const cols = Math.max(1, Math.floor(usable / colW));
519
- const rows = Math.ceil(names.length / cols);
520
- for (let r = 0; r < rows; r++) {
521
- let line = " ";
522
- for (let c = 0; c < cols; c++) {
523
- const i = c * rows + r;
524
- if (i >= names.length)
525
- break;
526
- const name = names[i];
527
- // Last cell on the row: no trailing padding.
528
- const isLast = c === cols - 1 || (c + 1) * rows + r >= names.length;
529
- line += isLast ? name : name.padEnd(colW, " ");
530
- }
531
- out.write(line.replace(/\s+$/u, "") + "\n");
532
- }
429
+ out.write("Available help:\n");
430
+ const names = SQL_HELP.map((e) => e.cmd);
431
+ const colW = names.reduce((m, n) => Math.max(m, n.length), 0) + 2;
432
+ const usable = Math.max(colW, screenWidth - 2);
433
+ const cols = Math.max(1, Math.floor(usable / colW));
434
+ const rows = Math.ceil(names.length / cols);
435
+ for (let r = 0; r < rows; r++) {
436
+ let line = " ";
437
+ for (let c = 0; c < cols; c++) {
438
+ const i = c * rows + r;
439
+ if (i >= names.length) break;
440
+ const name = names[i];
441
+ const isLast = c === cols - 1 || (c + 1) * rows + r >= names.length;
442
+ line += isLast ? name : name.padEnd(colW, " ");
443
+ }
444
+ out.write(line.replace(/\s+$/u, "") + "\n");
445
+ }
533
446
  };
534
447
  /** Render a single matched entry; pure formatter, exported for tests. */
535
448
  const writeEntry = (out, entry) => {
536
- out.write(formatEntry(entry));
449
+ out.write(formatEntry(entry));
537
450
  };
538
451
  /**
539
- * `\h` SQL command help.
540
- *
541
- * Behaviour matches upstream psql:
542
- * - No topic → list every command name in fixed-width columns.
543
- * - Unknown topic → "No help available for ..." hint.
544
- * - One or more prefix matches → render the full synopsis of each match
545
- * (blank-line separated), exactly as upstream does.
546
- *
547
- * Lookups are case-insensitive and prefix-matched per token. "create t"
548
- * matches CREATE TABLE / CREATE TRIGGER / CREATE TYPE.
549
- *
550
- * @param out output stream
551
- * @param topic SQL command name (e.g. "SELECT"), or null/empty for the
552
- * "available help" overview
553
- * @param screenWidth column count, used to lay out the overview list. Line
554
- * wrapping of the synopsis itself is a follow-up.
555
- */
556
- export const helpSQL = (out, topic, screenWidth) => {
557
- if (topic === null || topic.length === 0 || topic.trim().length === 0) {
558
- writeCommandList(out, screenWidth);
559
- return;
560
- }
561
- const matches = findMatches(topic);
562
- if (matches.length === 0) {
563
- out.write(`No help available for "${topic}".\n` +
564
- "Try \\h with no arguments to see available help.\n");
565
- return;
566
- }
567
- // psql has no "several matches" name listing — it prints the full help
568
- // block for every command whose name prefix-matches the topic, whether one
569
- // or many. Blocks are separated by a blank line, mirroring
570
- // upstream's trailing newline after each entry's `URL:` line.
571
- matches.forEach((m, idx) => {
572
- if (idx > 0)
573
- out.write("\n");
574
- writeEntry(out, m);
575
- });
452
+ * `\h` SQL command help.
453
+ *
454
+ * Behaviour matches upstream psql:
455
+ * - No topic → list every command name in fixed-width columns.
456
+ * - Unknown topic → "No help available for ..." hint.
457
+ * - One or more prefix matches → render the full synopsis of each match
458
+ * (blank-line separated), exactly as upstream does.
459
+ *
460
+ * Lookups are case-insensitive and prefix-matched per token. "create t"
461
+ * matches CREATE TABLE / CREATE TRIGGER / CREATE TYPE.
462
+ *
463
+ * @param out output stream
464
+ * @param topic SQL command name (e.g. "SELECT"), or null/empty for the
465
+ * "available help" overview
466
+ * @param screenWidth column count, used to lay out the overview list. Line
467
+ * wrapping of the synopsis itself is a follow-up.
468
+ */
469
+ const helpSQL = (out, topic, screenWidth) => {
470
+ if (topic === null || topic.length === 0 || topic.trim().length === 0) {
471
+ writeCommandList(out, screenWidth);
472
+ return;
473
+ }
474
+ const matches = findMatches(topic);
475
+ if (matches.length === 0) {
476
+ out.write(`No help available for "${topic}".\nTry \\h with no arguments to see available help.
477
+ `);
478
+ return;
479
+ }
480
+ matches.forEach((m, idx) => {
481
+ if (idx > 0) out.write("\n");
482
+ writeEntry(out, m);
483
+ });
576
484
  };
485
+ //#endregion
486
+ export { helpSQL, helpVariables, setHelpPagerOpener, slashUsage, slashUsageHelp, usage };