neon 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/README.md +54 -0
  2. package/dist/_shared/auth_selection.js +76 -79
  3. package/dist/_shared/credentials.js +166 -187
  4. package/dist/_shared/env-core/env.js +354 -517
  5. package/dist/_shared/env-core/reuse-secrets.js +159 -203
  6. package/dist/_shared/paths.js +129 -126
  7. package/dist/_shared/profiles.js +192 -242
  8. package/dist/_shared/secure_file.js +36 -38
  9. package/dist/_virtual/_rolldown/runtime.js +13 -0
  10. package/dist/analytics.js +163 -207
  11. package/dist/api.js +815 -758
  12. package/dist/auth.js +121 -141
  13. package/dist/auth_context.js +39 -53
  14. package/dist/cli.js +4 -7
  15. package/dist/commands/api.js +220 -250
  16. package/dist/commands/api_keys.js +251 -314
  17. package/dist/commands/auth.js +283 -328
  18. package/dist/commands/bootstrap.js +372 -437
  19. package/dist/commands/branches.js +304 -455
  20. package/dist/commands/bucket.js +374 -514
  21. package/dist/commands/checkout.js +213 -298
  22. package/dist/commands/config.js +573 -690
  23. package/dist/commands/connection_string.js +137 -165
  24. package/dist/commands/data_api.js +238 -260
  25. package/dist/commands/databases.js +67 -76
  26. package/dist/commands/deploy.js +31 -25
  27. package/dist/commands/dev.js +639 -719
  28. package/dist/commands/diff.js +156 -200
  29. package/dist/commands/env.js +243 -303
  30. package/dist/commands/functions.js +275 -355
  31. package/dist/commands/index.js +70 -65
  32. package/dist/commands/init.js +84 -119
  33. package/dist/commands/inspect.js +55 -55
  34. package/dist/commands/ip_allow.js +88 -120
  35. package/dist/commands/link.js +874 -1019
  36. package/dist/commands/logs.js +291 -0
  37. package/dist/commands/neon_auth.js +725 -933
  38. package/dist/commands/operations.js +34 -25
  39. package/dist/commands/orgs.js +28 -18
  40. package/dist/commands/profile.js +614 -845
  41. package/dist/commands/projects.js +313 -373
  42. package/dist/commands/psql.js +60 -58
  43. package/dist/commands/roles.js +55 -58
  44. package/dist/commands/schema_diff.js +87 -131
  45. package/dist/commands/set_context.js +34 -26
  46. package/dist/commands/snapshots.js +288 -413
  47. package/dist/commands/status.js +41 -37
  48. package/dist/commands/user.js +21 -10
  49. package/dist/commands/vpc_endpoints.js +85 -113
  50. package/dist/config.js +7 -6
  51. package/dist/config_format.js +50 -66
  52. package/dist/config_template.js +128 -157
  53. package/dist/context.js +183 -235
  54. package/dist/current_branch_fast_path.js +40 -49
  55. package/dist/dev/env.js +313 -394
  56. package/dist/dev/functions.js +54 -68
  57. package/dist/dev/inputs.js +46 -58
  58. package/dist/dev/runtime.js +135 -164
  59. package/dist/dev/websocket.js +766 -959
  60. package/dist/env.js +27 -33
  61. package/dist/env_file.js +118 -132
  62. package/dist/env_services.js +36 -38
  63. package/dist/errors.js +57 -68
  64. package/dist/functions_api.js +45 -43
  65. package/dist/help.js +189 -140
  66. package/dist/index.js +182 -257
  67. package/dist/init/agents.js +137 -118
  68. package/dist/init/auth.js +58 -68
  69. package/dist/init/bootstrap.js +325 -396
  70. package/dist/init/build_config.js +4 -2
  71. package/dist/init/detect_agent.js +56 -101
  72. package/dist/init/editors.js +35 -52
  73. package/dist/init/enrich_output.js +51 -66
  74. package/dist/init/extension.js +134 -171
  75. package/dist/init/inspect.js +179 -266
  76. package/dist/init/interactive.js +510 -622
  77. package/dist/init/neonctl.js +117 -168
  78. package/dist/init/orchestrate.js +157 -173
  79. package/dist/init/phases/auth.js +188 -202
  80. package/dist/init/phases/cleanup.js +23 -23
  81. package/dist/init/phases/db.js +251 -277
  82. package/dist/init/phases/getting_started.js +213 -223
  83. package/dist/init/phases/mcp.js +174 -224
  84. package/dist/init/phases/migrations.js +247 -248
  85. package/dist/init/phases/neon_auth.js +114 -133
  86. package/dist/init/phases/setup.js +546 -703
  87. package/dist/init/phases/skills.js +75 -86
  88. package/dist/init/phases/status.js +72 -67
  89. package/dist/init/resolve_context.js +102 -99
  90. package/dist/init/route_command.js +91 -98
  91. package/dist/init/skills.js +174 -218
  92. package/dist/init/vsix.js +77 -99
  93. package/dist/log.js +17 -16
  94. package/dist/neon_services.js +104 -129
  95. package/dist/parameters.gen.js +481 -471
  96. package/dist/pkg.js +17 -19
  97. package/dist/profile_keys.js +44 -47
  98. package/dist/psql/cli.js +44 -47
  99. package/dist/psql/command/cmd_cond.js +231 -406
  100. package/dist/psql/command/cmd_connect.js +557 -764
  101. package/dist/psql/command/cmd_copy.js +727 -983
  102. package/dist/psql/command/cmd_describe.js +1499 -1688
  103. package/dist/psql/command/cmd_format.js +733 -905
  104. package/dist/psql/command/cmd_io.js +1293 -2082
  105. package/dist/psql/command/cmd_lo.js +297 -359
  106. package/dist/psql/command/cmd_meta.js +727 -878
  107. package/dist/psql/command/cmd_misc.js +138 -172
  108. package/dist/psql/command/cmd_pipeline.js +547 -1099
  109. package/dist/psql/command/cmd_restrict.js +119 -155
  110. package/dist/psql/command/cmd_show.js +529 -688
  111. package/dist/psql/command/dispatch.js +261 -325
  112. package/dist/psql/command/inputQueue.js +35 -33
  113. package/dist/psql/command/shared.js +49 -63
  114. package/dist/psql/complete/filenames.js +90 -133
  115. package/dist/psql/complete/index.js +59 -97
  116. package/dist/psql/complete/matcher.js +236 -300
  117. package/dist/psql/complete/psqlVars.js +218 -223
  118. package/dist/psql/complete/queries.js +159 -177
  119. package/dist/psql/complete/rules.js +1493 -2299
  120. package/dist/psql/core/common.js +762 -1180
  121. package/dist/psql/core/help.js +456 -546
  122. package/dist/psql/core/mainloop.js +692 -1302
  123. package/dist/psql/core/prompt.js +391 -408
  124. package/dist/psql/core/settings.js +429 -644
  125. package/dist/psql/core/sqlHelp.js +480 -554
  126. package/dist/psql/core/startup.js +626 -815
  127. package/dist/psql/core/syncVars.js +67 -110
  128. package/dist/psql/core/variables.js +156 -278
  129. package/dist/psql/describe/formatters.js +884 -1285
  130. package/dist/psql/describe/processNamePattern.js +173 -260
  131. package/dist/psql/describe/queries.js +1368 -2403
  132. package/dist/psql/describe/versionGate.js +32 -41
  133. package/dist/psql/index.js +1414 -1927
  134. package/dist/psql/io/history.js +232 -271
  135. package/dist/psql/io/input.js +103 -108
  136. package/dist/psql/io/lineEditor/buffer.js +238 -319
  137. package/dist/psql/io/lineEditor/complete.js +135 -213
  138. package/dist/psql/io/lineEditor/filename.js +139 -148
  139. package/dist/psql/io/lineEditor/index.js +653 -870
  140. package/dist/psql/io/lineEditor/keymap.js +544 -702
  141. package/dist/psql/io/lineEditor/vt100.js +294 -341
  142. package/dist/psql/io/pgpass.js +158 -187
  143. package/dist/psql/io/pgservice.js +146 -183
  144. package/dist/psql/io/psqlrc.js +328 -403
  145. package/dist/psql/print/aligned.js +1020 -1683
  146. package/dist/psql/print/asciidoc.js +180 -214
  147. package/dist/psql/print/crosstab.js +281 -442
  148. package/dist/psql/print/csv.js +48 -70
  149. package/dist/psql/print/html.js +195 -226
  150. package/dist/psql/print/json.js +75 -88
  151. package/dist/psql/print/latex.js +291 -364
  152. package/dist/psql/print/pager.js +171 -242
  153. package/dist/psql/print/troff.js +194 -226
  154. package/dist/psql/print/unaligned.js +69 -95
  155. package/dist/psql/print/units.js +167 -169
  156. package/dist/psql/scanner/slash.js +428 -483
  157. package/dist/psql/scanner/sql.js +445 -889
  158. package/dist/psql/scanner/stringutils.js +309 -379
  159. package/dist/psql/types/index.js +2 -7
  160. package/dist/psql/types/scanner.js +25 -22
  161. package/dist/psql/wire/connection.js +2042 -2803
  162. package/dist/psql/wire/copy.js +84 -100
  163. package/dist/psql/wire/notify.js +39 -59
  164. package/dist/psql/wire/pipeline.js +305 -518
  165. package/dist/psql/wire/protocol.js +349 -417
  166. package/dist/psql/wire/sasl.js +180 -265
  167. package/dist/psql/wire/tls.js +400 -561
  168. package/dist/storage_api.js +115 -129
  169. package/dist/test_utils/fixtures.js +94 -113
  170. package/dist/test_utils/oauth_server.js +10 -7
  171. package/dist/test_utils/project_dir.js +33 -0
  172. package/dist/utils/ai_gateway_notice.js +131 -162
  173. package/dist/utils/api_enums.js +21 -28
  174. package/dist/utils/auth.js +10 -4
  175. package/dist/utils/branch_notice.js +20 -19
  176. package/dist/utils/branch_picker.js +83 -89
  177. package/dist/utils/cli_name.js +15 -12
  178. package/dist/utils/compute_units.js +20 -27
  179. package/dist/utils/config_diff.js +127 -158
  180. package/dist/utils/enrichers.js +95 -148
  181. package/dist/utils/esbuild.js +130 -189
  182. package/dist/utils/flags.js +35 -47
  183. package/dist/utils/formats.js +8 -15
  184. package/dist/utils/git_diff.js +69 -80
  185. package/dist/utils/inspect_db.js +101 -143
  186. package/dist/utils/inspect_queries.js +179 -142
  187. package/dist/utils/middlewares.js +37 -44
  188. package/dist/utils/openapi.js +87 -99
  189. package/dist/utils/package_manager.js +312 -110
  190. package/dist/utils/point_in_time.js +49 -53
  191. package/dist/utils/psql.js +89 -106
  192. package/dist/utils/service_picker.js +55 -58
  193. package/dist/utils/string.js +5 -5
  194. package/dist/utils/ui.js +38 -55
  195. package/dist/utils/write_sync.js +26 -35
  196. package/dist/utils/zip.js +4 -3
  197. package/dist/writer.js +67 -87
  198. package/package.json +7 -5
@@ -1,240 +1,208 @@
1
1
  import { boolDisplayOf, renderCellValue } from "./units.js";
2
+ //#region src/psql/print/troff.ts
2
3
  /**
3
- * Troff MS printer.
4
- *
5
- * Mirrors print.c `print_troff_ms_text` and `print_troff_ms_vertical`.
6
- *
7
- * Output shape (flat, with title and one footer):
8
- * .LP
9
- * .DS C
10
- * title
11
- * .DE
12
- * .LP
13
- * .TS
14
- * center;
15
- * l | l | r.
16
- * \fIcol1\fP \fIcol2\fP \fIcol3\fP
17
- * _
18
- * val1 val2 val3
19
- * .TE
20
- * .DS L
21
- * (N rows)
22
- * .DE
23
- *
24
- * Output shape (expanded, `\pset expanded on`):
25
- * .LP
26
- * .TS
27
- * center;
28
- * c s.
29
- * \fIRecord 1\fP
30
- * _ # if border>=1
31
- * .T&
32
- * c | l. # `c l.` when border != 1
33
- * colname1 val1
34
- * colname2 val2
35
- * ...
36
- * .T&
37
- * c s.
38
- * \fIRecord 2\fP
39
- * ...
40
- * .TE
41
- * .DS L
42
- * .DE
43
- *
44
- * - `topt.border` is clamped to 0..2. `border == 2` uses `center box;`;
45
- * otherwise just `center;`. Border > 0 inserts ` | ` between column
46
- * spec letters.
47
- * - Numeric columns get `r`, others `l` (per the OID heuristic).
48
- * - Tab is the field separator (consistent with `.TS` defaults).
49
- * - The only structurally-hostile character is `\\`, which becomes
50
- * `\(rs` (troff's "reverse solidus" glyph). Everything else passes
51
- * through verbatim — troff ms is a byte stream.
52
- * - Expanded mode emits a `.T&\n<spec>.\n` re-spec block between the
53
- * "Record N" header (`c s.`) and the body (`c l.` / `c | l.`); under
54
- * tuples-only the body spec is set once as `c l;` after the table
55
- * header. No default `(N rows)` footer.
56
- */
57
- // INT2, INT4, INT8, FLOAT4, FLOAT8, NUMERIC, INTERVAL.
58
- const NUMERIC_OIDS = new Set([21, 23, 20, 700, 701, 1700, 1186]);
59
- export const troffMsPrinter = {
60
- format: "troff-ms",
61
- printQuery(rs, opts, out) {
62
- const topt = opts.topt;
63
- if (topt.expanded === "on") {
64
- return printExpanded(rs, opts, out);
65
- }
66
- return printFlat(rs, opts, out);
67
- },
4
+ * Troff MS printer.
5
+ *
6
+ * Mirrors print.c `print_troff_ms_text` and `print_troff_ms_vertical`.
7
+ *
8
+ * Output shape (flat, with title and one footer):
9
+ * .LP
10
+ * .DS C
11
+ * title
12
+ * .DE
13
+ * .LP
14
+ * .TS
15
+ * center;
16
+ * l | l | r.
17
+ * \fIcol1\fP \fIcol2\fP \fIcol3\fP
18
+ * _
19
+ * val1 val2 val3
20
+ * .TE
21
+ * .DS L
22
+ * (N rows)
23
+ * .DE
24
+ *
25
+ * Output shape (expanded, `\pset expanded on`):
26
+ * .LP
27
+ * .TS
28
+ * center;
29
+ * c s.
30
+ * \fIRecord 1\fP
31
+ * _ # if border>=1
32
+ * .T&
33
+ * c | l. # `c l.` when border != 1
34
+ * colname1 val1
35
+ * colname2 val2
36
+ * ...
37
+ * .T&
38
+ * c s.
39
+ * \fIRecord 2\fP
40
+ * ...
41
+ * .TE
42
+ * .DS L
43
+ * .DE
44
+ *
45
+ * - `topt.border` is clamped to 0..2. `border == 2` uses `center box;`;
46
+ * otherwise just `center;`. Border > 0 inserts ` | ` between column
47
+ * spec letters.
48
+ * - Numeric columns get `r`, others `l` (per the OID heuristic).
49
+ * - Tab is the field separator (consistent with `.TS` defaults).
50
+ * - The only structurally-hostile character is `\\`, which becomes
51
+ * `\(rs` (troff's "reverse solidus" glyph). Everything else passes
52
+ * through verbatim — troff ms is a byte stream.
53
+ * - Expanded mode emits a `.T&\n<spec>.\n` re-spec block between the
54
+ * "Record N" header (`c s.`) and the body (`c l.` / `c | l.`); under
55
+ * tuples-only the body spec is set once as `c l;` after the table
56
+ * header. No default `(N rows)` footer.
57
+ */
58
+ const NUMERIC_OIDS = /* @__PURE__ */ new Set([
59
+ 21,
60
+ 23,
61
+ 20,
62
+ 700,
63
+ 701,
64
+ 1700,
65
+ 1186
66
+ ]);
67
+ const troffMsPrinter = {
68
+ format: "troff-ms",
69
+ printQuery(rs, opts, out) {
70
+ if (opts.topt.expanded === "on") return printExpanded(rs, opts, out);
71
+ return printFlat(rs, opts, out);
72
+ }
68
73
  };
69
74
  const printFlat = (rs, opts, out) => {
70
- const topt = opts.topt;
71
- const tuplesOnly = topt.tuplesOnly;
72
- const startTable = topt.startTable;
73
- const stopTable = topt.stopTable;
74
- const border = clampBorder(topt.border);
75
- const nullPrint = opts.nullPrint !== "" ? opts.nullPrint : topt.nullPrint;
76
- const title = opts.title ?? topt.title;
77
- const footers = opts.footers ?? topt.footers;
78
- const headers = rs.fields.map((f) => f.name);
79
- const ncols = rs.fields.length;
80
- const aligns = rs.fields.map((f) => NUMERIC_OIDS.has(f.dataTypeID) ? "r" : "l");
81
- const boolDisplay = boolDisplayOf(topt);
82
- const cells = rs.rows.map((row) => row.map((cell, i) => renderCell(cell, nullPrint, topt.numericLocale, rs.fields[i]?.dataTypeID, boolDisplay)));
83
- let buf = "";
84
- if (startTable) {
85
- if (!tuplesOnly && title) {
86
- buf += ".LP\n.DS C\n";
87
- buf += escapeTroff(title);
88
- buf += "\n.DE\n";
89
- }
90
- buf += ".LP\n.TS\n";
91
- buf += border === 2 ? "center box;\n" : "center;\n";
92
- aligns.forEach((a, idx) => {
93
- buf += a;
94
- if (border > 0 && idx < ncols - 1)
95
- buf += " | ";
96
- });
97
- buf += ".\n";
98
- if (!tuplesOnly) {
99
- headers.forEach((h, idx) => {
100
- if (idx !== 0)
101
- buf += "\t";
102
- buf += "\\fI" + escapeTroff(h) + "\\fP";
103
- });
104
- buf += "\n_\n";
105
- }
106
- }
107
- cells.forEach((row) => {
108
- row.forEach((value, idx) => {
109
- buf += escapeTroff(value);
110
- if (idx === ncols - 1)
111
- buf += "\n";
112
- else
113
- buf += "\t";
114
- });
115
- });
116
- if (stopTable) {
117
- buf += ".TE\n.DS L\n";
118
- if (!tuplesOnly) {
119
- const effective = effectiveFooters(rs, topt, footers);
120
- for (const f of effective) {
121
- buf += escapeTroff(f) + "\n";
122
- }
123
- }
124
- buf += ".DE\n";
125
- }
126
- out.write(buf);
127
- return Promise.resolve();
75
+ const topt = opts.topt;
76
+ const tuplesOnly = topt.tuplesOnly;
77
+ const startTable = topt.startTable;
78
+ const stopTable = topt.stopTable;
79
+ const border = clampBorder(topt.border);
80
+ const nullPrint = opts.nullPrint !== "" ? opts.nullPrint : topt.nullPrint;
81
+ const title = opts.title ?? topt.title;
82
+ const footers = opts.footers ?? topt.footers;
83
+ const headers = rs.fields.map((f) => f.name);
84
+ const ncols = rs.fields.length;
85
+ const aligns = rs.fields.map((f) => NUMERIC_OIDS.has(f.dataTypeID) ? "r" : "l");
86
+ const boolDisplay = boolDisplayOf(topt);
87
+ const cells = rs.rows.map((row) => row.map((cell, i) => renderCell(cell, nullPrint, topt.numericLocale, rs.fields[i]?.dataTypeID, boolDisplay)));
88
+ let buf = "";
89
+ if (startTable) {
90
+ if (!tuplesOnly && title) {
91
+ buf += ".LP\n.DS C\n";
92
+ buf += escapeTroff(title);
93
+ buf += "\n.DE\n";
94
+ }
95
+ buf += ".LP\n.TS\n";
96
+ buf += border === 2 ? "center box;\n" : "center;\n";
97
+ aligns.forEach((a, idx) => {
98
+ buf += a;
99
+ if (border > 0 && idx < ncols - 1) buf += " | ";
100
+ });
101
+ buf += ".\n";
102
+ if (!tuplesOnly) {
103
+ headers.forEach((h, idx) => {
104
+ if (idx !== 0) buf += " ";
105
+ buf += "\\fI" + escapeTroff(h) + "\\fP";
106
+ });
107
+ buf += "\n_\n";
108
+ }
109
+ }
110
+ cells.forEach((row) => {
111
+ row.forEach((value, idx) => {
112
+ buf += escapeTroff(value);
113
+ if (idx === ncols - 1) buf += "\n";
114
+ else buf += " ";
115
+ });
116
+ });
117
+ if (stopTable) {
118
+ buf += ".TE\n.DS L\n";
119
+ if (!tuplesOnly) {
120
+ const effective = effectiveFooters(rs, topt, footers);
121
+ for (const f of effective) buf += escapeTroff(f) + "\n";
122
+ }
123
+ buf += ".DE\n";
124
+ }
125
+ out.write(buf);
126
+ return Promise.resolve();
128
127
  };
129
128
  const printExpanded = (rs, opts, out) => {
130
- const topt = opts.topt;
131
- const tuplesOnly = topt.tuplesOnly;
132
- const startTable = topt.startTable;
133
- const stopTable = topt.stopTable;
134
- const border = clampBorder(topt.border);
135
- const nullPrint = opts.nullPrint !== "" ? opts.nullPrint : topt.nullPrint;
136
- const title = opts.title ?? topt.title;
137
- const footers = opts.footers ?? topt.footers;
138
- const headers = rs.fields.map((f) => f.name);
139
- const boolDisplay = boolDisplayOf(topt);
140
- const cells = rs.rows.map((row) => row.map((cell, i) => renderCell(cell, nullPrint, topt.numericLocale, rs.fields[i]?.dataTypeID, boolDisplay)));
141
- let buf = "";
142
- // currentFormat: 0 = none yet, 1 = "Record N" header (c s),
143
- // 2 = body (c l or c | l). Upstream uses the same tri-state to
144
- // decide when to emit `.T&` separators.
145
- let currentFormat = 0;
146
- if (startTable) {
147
- if (!tuplesOnly && title) {
148
- buf += ".LP\n.DS C\n";
149
- buf += escapeTroff(title);
150
- buf += "\n.DE\n";
151
- }
152
- buf += ".LP\n.TS\n";
153
- buf += border === 2 ? "center box;\n" : "center;\n";
154
- // Under tuples-only, upstream emits a one-shot `c l;` body spec
155
- // here so each Record's first .T& block is omitted.
156
- if (tuplesOnly) {
157
- buf += "c l;\n";
158
- }
159
- }
160
- else {
161
- // Continuation: assume body spec is already in effect.
162
- currentFormat = 2;
163
- }
164
- let record = topt.prior + 1;
165
- cells.forEach((row, rowIdx) => {
166
- if (!tuplesOnly) {
167
- if (currentFormat !== 1) {
168
- if (border === 2 && rowIdx > 0)
169
- buf += "_\n";
170
- if (currentFormat !== 0)
171
- buf += ".T&\n";
172
- buf += "c s.\n";
173
- currentFormat = 1;
174
- }
175
- buf += `\\fIRecord ${String(record)}\\fP\n`;
176
- record += 1;
177
- }
178
- if (border >= 1)
179
- buf += "_\n";
180
- if (!tuplesOnly) {
181
- if (currentFormat !== 2) {
182
- if (currentFormat !== 0)
183
- buf += ".T&\n";
184
- buf += border !== 1 ? "c l.\n" : "c | l.\n";
185
- currentFormat = 2;
186
- }
187
- }
188
- row.forEach((value, idx) => {
189
- buf += escapeTroff(headers[idx]);
190
- buf += "\t";
191
- buf += escapeTroff(value);
192
- buf += "\n";
193
- });
194
- });
195
- if (stopTable) {
196
- buf += ".TE\n.DS L\n";
197
- // Expanded mode does NOT emit the default "(N rows)" footer.
198
- if (!tuplesOnly && footers && footers.length > 0) {
199
- for (const f of footers) {
200
- buf += escapeTroff(f) + "\n";
201
- }
202
- }
203
- buf += ".DE\n";
204
- }
205
- out.write(buf);
206
- return Promise.resolve();
129
+ const topt = opts.topt;
130
+ const tuplesOnly = topt.tuplesOnly;
131
+ const startTable = topt.startTable;
132
+ const stopTable = topt.stopTable;
133
+ const border = clampBorder(topt.border);
134
+ const nullPrint = opts.nullPrint !== "" ? opts.nullPrint : topt.nullPrint;
135
+ const title = opts.title ?? topt.title;
136
+ const footers = opts.footers ?? topt.footers;
137
+ const headers = rs.fields.map((f) => f.name);
138
+ const boolDisplay = boolDisplayOf(topt);
139
+ const cells = rs.rows.map((row) => row.map((cell, i) => renderCell(cell, nullPrint, topt.numericLocale, rs.fields[i]?.dataTypeID, boolDisplay)));
140
+ let buf = "";
141
+ let currentFormat = 0;
142
+ if (startTable) {
143
+ if (!tuplesOnly && title) {
144
+ buf += ".LP\n.DS C\n";
145
+ buf += escapeTroff(title);
146
+ buf += "\n.DE\n";
147
+ }
148
+ buf += ".LP\n.TS\n";
149
+ buf += border === 2 ? "center box;\n" : "center;\n";
150
+ if (tuplesOnly) buf += "c l;\n";
151
+ } else currentFormat = 2;
152
+ let record = topt.prior + 1;
153
+ cells.forEach((row, rowIdx) => {
154
+ if (!tuplesOnly) {
155
+ if (currentFormat !== 1) {
156
+ if (border === 2 && rowIdx > 0) buf += "_\n";
157
+ if (currentFormat !== 0) buf += ".T&\n";
158
+ buf += "c s.\n";
159
+ currentFormat = 1;
160
+ }
161
+ buf += `\\fIRecord ${String(record)}\\fP\n`;
162
+ record += 1;
163
+ }
164
+ if (border >= 1) buf += "_\n";
165
+ if (!tuplesOnly) {
166
+ if (currentFormat !== 2) {
167
+ if (currentFormat !== 0) buf += ".T&\n";
168
+ buf += border !== 1 ? "c l.\n" : "c | l.\n";
169
+ currentFormat = 2;
170
+ }
171
+ }
172
+ row.forEach((value, idx) => {
173
+ buf += escapeTroff(headers[idx]);
174
+ buf += " ";
175
+ buf += escapeTroff(value);
176
+ buf += "\n";
177
+ });
178
+ });
179
+ if (stopTable) {
180
+ buf += ".TE\n.DS L\n";
181
+ if (!tuplesOnly && footers && footers.length > 0) for (const f of footers) buf += escapeTroff(f) + "\n";
182
+ buf += ".DE\n";
183
+ }
184
+ out.write(buf);
185
+ return Promise.resolve();
207
186
  };
208
187
  const clampBorder = (b) => {
209
- if (b > 2)
210
- return 2;
211
- if (b < 0)
212
- return 0;
213
- return b;
188
+ if (b > 2) return 2;
189
+ if (b < 0) return 0;
190
+ return b;
214
191
  };
215
192
  const effectiveFooters = (rs, topt, footers) => {
216
- if (footers && footers.length > 0)
217
- return footers;
218
- if (topt.defaultFooter) {
219
- const n = rs.rows.length;
220
- return [`(${String(n)} ${n === 1 ? "row" : "rows"})`];
221
- }
222
- return [];
193
+ if (footers && footers.length > 0) return footers;
194
+ if (topt.defaultFooter) {
195
+ const n = rs.rows.length;
196
+ return [`(${String(n)} ${n === 1 ? "row" : "rows"})`];
197
+ }
198
+ return [];
223
199
  };
224
200
  const escapeTroff = (input) => {
225
- // Only `\` is dangerous (it begins a troff escape). Map it to `\(rs`,
226
- // which renders the reverse-solidus glyph. Newlines flow through
227
- // unchanged — `.TS` treats each line as a new row, so we never want
228
- // raw newlines inside a cell; that constraint is enforced upstream
229
- // by the caller, not here. (`renderCell` similarly never emits a raw
230
- // newline today.)
231
- let out = "";
232
- for (const ch of input) {
233
- if (ch === "\\")
234
- out += "\\(rs";
235
- else
236
- out += ch;
237
- }
238
- return out;
201
+ let out = "";
202
+ for (const ch of input) if (ch === "\\") out += "\\(rs";
203
+ else out += ch;
204
+ return out;
239
205
  };
240
206
  const renderCell = (cell, nullPrint, numericLocale, dataTypeID, boolDisplay) => renderCellValue(cell, nullPrint, numericLocale, dataTypeID, boolDisplay);
207
+ //#endregion
208
+ export { troffMsPrinter };
@@ -1,99 +1,73 @@
1
1
  import { boolDisplayOf, renderCellValue } from "./units.js";
2
+ //#region src/psql/print/unaligned.ts
2
3
  /**
3
- * Unaligned tabular printer.
4
- *
5
- * Mirrors print.c `print_unaligned_text` / `print_unaligned_vertical`.
6
- *
7
- * Field separator defaults to `|`, record separator defaults to `\n`,
8
- * both honor `opts.topt.fieldSep` / `recordSep`. NULL cells render
9
- * `opts.nullPrint` (which falls back to `topt.nullPrint`, default `''`).
10
- *
11
- * Expanded (`\x`) mode prints `colname|value` per line with a blank
12
- * record-sep gap between rows.
13
- *
14
- * The default footer `(N rows)` is only emitted when not in expanded
15
- * mode and `topt.defaultFooter` is true; same as upstream psql.
16
- */
17
- export const unalignedPrinter = {
18
- format: "unaligned",
19
- printQuery(rs, opts, out) {
20
- const topt = opts.topt;
21
- const fieldSep = topt.fieldSep !== "" ? topt.fieldSep : "|";
22
- const recordSep = topt.recordSep !== "" ? topt.recordSep : "\n";
23
- const nullPrint = opts.nullPrint !== "" ? opts.nullPrint : topt.nullPrint;
24
- const expanded = topt.expanded === "on";
25
- const tuplesOnly = topt.tuplesOnly;
26
- const headers = rs.fields.map((f) => f.name);
27
- const boolDisplay = boolDisplayOf(topt);
28
- const cells = rs.rows.map((row) => row.map((cell, i) => renderCell(cell, nullPrint, topt.numericLocale, rs.fields[i]?.dataTypeID, boolDisplay)));
29
- let outBuf = "";
30
- if (expanded) {
31
- // Vertical mode mirrors print.c `print_unaligned_vertical`: each
32
- // record gap is a DOUBLE recordSep, the title (if any) emits
33
- // without a trailing separator (the loop handles that), inter-
34
- // column lines get one recordSep, and the closing footer block is
35
- // preceded by a recordSep with one more recordSep separating each
36
- // footer entry.
37
- let needRecordSep = false;
38
- if (!tuplesOnly && opts.title) {
39
- outBuf += opts.title;
40
- needRecordSep = true;
41
- }
42
- cells.forEach((row) => {
43
- if (needRecordSep) {
44
- outBuf += recordSep + recordSep;
45
- needRecordSep = false;
46
- }
47
- row.forEach((value, colIdx) => {
48
- outBuf += headers[colIdx] + fieldSep + value;
49
- if (colIdx < row.length - 1) {
50
- outBuf += recordSep;
51
- }
52
- else {
53
- needRecordSep = true;
54
- }
55
- });
56
- });
57
- if (!tuplesOnly && opts.footers && opts.footers.length > 0) {
58
- outBuf += recordSep;
59
- for (const footer of opts.footers) {
60
- outBuf += recordSep + footer;
61
- }
62
- needRecordSep = true;
63
- }
64
- if (needRecordSep)
65
- outBuf += recordSep;
66
- }
67
- else {
68
- // Horizontal mode.
69
- if (!tuplesOnly && opts.title) {
70
- outBuf += opts.title + recordSep;
71
- }
72
- if (!tuplesOnly) {
73
- outBuf += headers.join(fieldSep) + recordSep;
74
- }
75
- cells.forEach((row) => {
76
- outBuf += row.join(fieldSep) + recordSep;
77
- });
78
- // Default `(N rows)` footer is suppressed when the caller supplied its
79
- // own footers — upstream (and aligned.ts) print user footers INSTEAD of
80
- // the row count, not in addition (review: unaligned footer duplication).
81
- const hasUserFooters = opts.footers !== undefined &&
82
- opts.footers !== null &&
83
- opts.footers.length > 0;
84
- if (!tuplesOnly && topt.defaultFooter && !hasUserFooters) {
85
- const n = rs.rows.length;
86
- outBuf +=
87
- `(${String(n)} ${n === 1 ? "row" : "rows"})` + recordSep;
88
- }
89
- if (!tuplesOnly && hasUserFooters) {
90
- for (const footer of opts.footers ?? []) {
91
- outBuf += footer + recordSep;
92
- }
93
- }
94
- }
95
- out.write(outBuf);
96
- return Promise.resolve();
97
- },
4
+ * Unaligned tabular printer.
5
+ *
6
+ * Mirrors print.c `print_unaligned_text` / `print_unaligned_vertical`.
7
+ *
8
+ * Field separator defaults to `|`, record separator defaults to `\n`,
9
+ * both honor `opts.topt.fieldSep` / `recordSep`. NULL cells render
10
+ * `opts.nullPrint` (which falls back to `topt.nullPrint`, default `''`).
11
+ *
12
+ * Expanded (`\x`) mode prints `colname|value` per line with a blank
13
+ * record-sep gap between rows.
14
+ *
15
+ * The default footer `(N rows)` is only emitted when not in expanded
16
+ * mode and `topt.defaultFooter` is true; same as upstream psql.
17
+ */
18
+ const unalignedPrinter = {
19
+ format: "unaligned",
20
+ printQuery(rs, opts, out) {
21
+ const topt = opts.topt;
22
+ const fieldSep = topt.fieldSep !== "" ? topt.fieldSep : "|";
23
+ const recordSep = topt.recordSep !== "" ? topt.recordSep : "\n";
24
+ const nullPrint = opts.nullPrint !== "" ? opts.nullPrint : topt.nullPrint;
25
+ const expanded = topt.expanded === "on";
26
+ const tuplesOnly = topt.tuplesOnly;
27
+ const headers = rs.fields.map((f) => f.name);
28
+ const boolDisplay = boolDisplayOf(topt);
29
+ const cells = rs.rows.map((row) => row.map((cell, i) => renderCell(cell, nullPrint, topt.numericLocale, rs.fields[i]?.dataTypeID, boolDisplay)));
30
+ let outBuf = "";
31
+ if (expanded) {
32
+ let needRecordSep = false;
33
+ if (!tuplesOnly && opts.title) {
34
+ outBuf += opts.title;
35
+ needRecordSep = true;
36
+ }
37
+ cells.forEach((row) => {
38
+ if (needRecordSep) {
39
+ outBuf += recordSep + recordSep;
40
+ needRecordSep = false;
41
+ }
42
+ row.forEach((value, colIdx) => {
43
+ outBuf += headers[colIdx] + fieldSep + value;
44
+ if (colIdx < row.length - 1) outBuf += recordSep;
45
+ else needRecordSep = true;
46
+ });
47
+ });
48
+ if (!tuplesOnly && opts.footers && opts.footers.length > 0) {
49
+ outBuf += recordSep;
50
+ for (const footer of opts.footers) outBuf += recordSep + footer;
51
+ needRecordSep = true;
52
+ }
53
+ if (needRecordSep) outBuf += recordSep;
54
+ } else {
55
+ if (!tuplesOnly && opts.title) outBuf += opts.title + recordSep;
56
+ if (!tuplesOnly) outBuf += headers.join(fieldSep) + recordSep;
57
+ cells.forEach((row) => {
58
+ outBuf += row.join(fieldSep) + recordSep;
59
+ });
60
+ const hasUserFooters = opts.footers !== void 0 && opts.footers !== null && opts.footers.length > 0;
61
+ if (!tuplesOnly && topt.defaultFooter && !hasUserFooters) {
62
+ const n = rs.rows.length;
63
+ outBuf += `(${String(n)} ${n === 1 ? "row" : "rows"})` + recordSep;
64
+ }
65
+ if (!tuplesOnly && hasUserFooters) for (const footer of opts.footers ?? []) outBuf += footer + recordSep;
66
+ }
67
+ out.write(outBuf);
68
+ return Promise.resolve();
69
+ }
98
70
  };
99
71
  const renderCell = (cell, nullPrint, numericLocale, dataTypeID, boolDisplay) => renderCellValue(cell, nullPrint, numericLocale, dataTypeID, boolDisplay);
72
+ //#endregion
73
+ export { unalignedPrinter };