neon 2.47.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.
- package/README.md +54 -0
- package/dist/_shared/auth_selection.js +76 -79
- package/dist/_shared/credentials.js +166 -187
- package/dist/_shared/env-core/env.js +395 -0
- package/dist/_shared/env-core/reuse-secrets.js +179 -0
- package/dist/_shared/paths.js +129 -126
- package/dist/_shared/profiles.js +192 -242
- package/dist/_shared/secure_file.js +36 -38
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/analytics.js +163 -207
- package/dist/api.js +815 -758
- package/dist/auth.js +121 -141
- package/dist/auth_context.js +39 -53
- package/dist/cli.js +4 -7
- package/dist/commands/api.js +220 -250
- package/dist/commands/api_keys.js +251 -314
- package/dist/commands/auth.js +283 -328
- package/dist/commands/bootstrap.js +372 -437
- package/dist/commands/branches.js +304 -455
- package/dist/commands/bucket.js +374 -514
- package/dist/commands/checkout.js +213 -298
- package/dist/commands/config.js +575 -658
- package/dist/commands/connection_string.js +137 -165
- package/dist/commands/data_api.js +238 -260
- package/dist/commands/databases.js +67 -76
- package/dist/commands/deploy.js +31 -25
- package/dist/commands/dev.js +642 -681
- package/dist/commands/diff.js +156 -200
- package/dist/commands/env.js +243 -303
- package/dist/commands/functions.js +275 -341
- package/dist/commands/index.js +70 -65
- package/dist/commands/init.js +84 -119
- package/dist/commands/inspect.js +55 -55
- package/dist/commands/ip_allow.js +88 -120
- package/dist/commands/link.js +874 -1019
- package/dist/commands/logs.js +291 -0
- package/dist/commands/neon_auth.js +725 -933
- package/dist/commands/operations.js +34 -25
- package/dist/commands/orgs.js +28 -18
- package/dist/commands/profile.js +614 -845
- package/dist/commands/projects.js +313 -373
- package/dist/commands/psql.js +60 -58
- package/dist/commands/roles.js +55 -58
- package/dist/commands/schema_diff.js +87 -131
- package/dist/commands/set_context.js +34 -26
- package/dist/commands/snapshots.js +288 -413
- package/dist/commands/status.js +41 -37
- package/dist/commands/user.js +21 -10
- package/dist/commands/vpc_endpoints.js +85 -113
- package/dist/config.js +7 -6
- package/dist/config_format.js +50 -66
- package/dist/config_template.js +128 -157
- package/dist/context.js +183 -235
- package/dist/current_branch_fast_path.js +40 -49
- package/dist/dev/env.js +313 -394
- package/dist/dev/functions.js +54 -64
- package/dist/dev/inputs.js +46 -58
- package/dist/dev/runtime.js +135 -164
- package/dist/dev/websocket.js +766 -959
- package/dist/env.js +27 -33
- package/dist/env_file.js +118 -132
- package/dist/env_services.js +36 -38
- package/dist/errors.js +57 -68
- package/dist/functions_api.js +45 -43
- package/dist/help.js +189 -140
- package/dist/index.js +182 -257
- package/dist/init/agents.js +137 -118
- package/dist/init/auth.js +58 -68
- package/dist/init/bootstrap.js +325 -396
- package/dist/init/build_config.js +4 -2
- package/dist/init/detect_agent.js +56 -101
- package/dist/init/editors.js +35 -52
- package/dist/init/enrich_output.js +51 -66
- package/dist/init/extension.js +134 -171
- package/dist/init/inspect.js +179 -266
- package/dist/init/interactive.js +510 -622
- package/dist/init/neonctl.js +117 -168
- package/dist/init/orchestrate.js +157 -173
- package/dist/init/phases/auth.js +188 -202
- package/dist/init/phases/cleanup.js +23 -23
- package/dist/init/phases/db.js +251 -277
- package/dist/init/phases/getting_started.js +213 -223
- package/dist/init/phases/mcp.js +174 -224
- package/dist/init/phases/migrations.js +247 -248
- package/dist/init/phases/neon_auth.js +114 -133
- package/dist/init/phases/setup.js +546 -703
- package/dist/init/phases/skills.js +75 -86
- package/dist/init/phases/status.js +72 -67
- package/dist/init/resolve_context.js +102 -99
- package/dist/init/route_command.js +91 -98
- package/dist/init/skills.js +174 -218
- package/dist/init/vsix.js +77 -99
- package/dist/log.js +17 -16
- package/dist/neon_services.js +104 -129
- package/dist/parameters.gen.js +481 -471
- package/dist/pkg.js +17 -19
- package/dist/profile_keys.js +44 -47
- package/dist/psql/cli.js +44 -47
- package/dist/psql/command/cmd_cond.js +231 -406
- package/dist/psql/command/cmd_connect.js +557 -764
- package/dist/psql/command/cmd_copy.js +727 -983
- package/dist/psql/command/cmd_describe.js +1499 -1688
- package/dist/psql/command/cmd_format.js +733 -905
- package/dist/psql/command/cmd_io.js +1293 -2082
- package/dist/psql/command/cmd_lo.js +297 -359
- package/dist/psql/command/cmd_meta.js +727 -878
- package/dist/psql/command/cmd_misc.js +138 -172
- package/dist/psql/command/cmd_pipeline.js +547 -1099
- package/dist/psql/command/cmd_restrict.js +119 -155
- package/dist/psql/command/cmd_show.js +529 -688
- package/dist/psql/command/dispatch.js +261 -325
- package/dist/psql/command/inputQueue.js +35 -33
- package/dist/psql/command/shared.js +49 -63
- package/dist/psql/complete/filenames.js +90 -133
- package/dist/psql/complete/index.js +59 -97
- package/dist/psql/complete/matcher.js +236 -300
- package/dist/psql/complete/psqlVars.js +218 -223
- package/dist/psql/complete/queries.js +159 -177
- package/dist/psql/complete/rules.js +1493 -2299
- package/dist/psql/core/common.js +762 -1180
- package/dist/psql/core/help.js +456 -546
- package/dist/psql/core/mainloop.js +692 -1302
- package/dist/psql/core/prompt.js +391 -408
- package/dist/psql/core/settings.js +429 -644
- package/dist/psql/core/sqlHelp.js +480 -554
- package/dist/psql/core/startup.js +626 -815
- package/dist/psql/core/syncVars.js +67 -110
- package/dist/psql/core/variables.js +156 -278
- package/dist/psql/describe/formatters.js +884 -1285
- package/dist/psql/describe/processNamePattern.js +173 -260
- package/dist/psql/describe/queries.js +1368 -2403
- package/dist/psql/describe/versionGate.js +32 -41
- package/dist/psql/index.js +1414 -1927
- package/dist/psql/io/history.js +232 -271
- package/dist/psql/io/input.js +103 -108
- package/dist/psql/io/lineEditor/buffer.js +238 -319
- package/dist/psql/io/lineEditor/complete.js +135 -213
- package/dist/psql/io/lineEditor/filename.js +139 -148
- package/dist/psql/io/lineEditor/index.js +653 -870
- package/dist/psql/io/lineEditor/keymap.js +544 -702
- package/dist/psql/io/lineEditor/vt100.js +294 -341
- package/dist/psql/io/pgpass.js +158 -187
- package/dist/psql/io/pgservice.js +146 -183
- package/dist/psql/io/psqlrc.js +328 -403
- package/dist/psql/print/aligned.js +1020 -1683
- package/dist/psql/print/asciidoc.js +180 -214
- package/dist/psql/print/crosstab.js +281 -442
- package/dist/psql/print/csv.js +48 -70
- package/dist/psql/print/html.js +195 -226
- package/dist/psql/print/json.js +75 -88
- package/dist/psql/print/latex.js +291 -364
- package/dist/psql/print/pager.js +171 -242
- package/dist/psql/print/troff.js +194 -226
- package/dist/psql/print/unaligned.js +69 -95
- package/dist/psql/print/units.js +167 -169
- package/dist/psql/scanner/slash.js +428 -483
- package/dist/psql/scanner/sql.js +445 -889
- package/dist/psql/scanner/stringutils.js +309 -379
- package/dist/psql/types/index.js +2 -7
- package/dist/psql/types/scanner.js +25 -22
- package/dist/psql/wire/connection.js +2042 -2803
- package/dist/psql/wire/copy.js +84 -100
- package/dist/psql/wire/notify.js +39 -59
- package/dist/psql/wire/pipeline.js +305 -518
- package/dist/psql/wire/protocol.js +349 -417
- package/dist/psql/wire/sasl.js +180 -265
- package/dist/psql/wire/tls.js +400 -561
- package/dist/storage_api.js +115 -129
- package/dist/test_utils/fixtures.js +94 -113
- package/dist/test_utils/oauth_server.js +10 -7
- package/dist/test_utils/project_dir.js +33 -0
- package/dist/utils/ai_gateway_notice.js +131 -162
- package/dist/utils/api_enums.js +21 -28
- package/dist/utils/auth.js +10 -4
- package/dist/utils/branch_notice.js +20 -19
- package/dist/utils/branch_picker.js +83 -89
- package/dist/utils/cli_name.js +15 -12
- package/dist/utils/compute_units.js +20 -27
- package/dist/utils/config_diff.js +127 -158
- package/dist/utils/enrichers.js +95 -148
- package/dist/utils/esbuild.js +133 -147
- package/dist/utils/flags.js +35 -47
- package/dist/utils/formats.js +8 -15
- package/dist/utils/git_diff.js +69 -80
- package/dist/utils/inspect_db.js +101 -143
- package/dist/utils/inspect_queries.js +179 -142
- package/dist/utils/middlewares.js +37 -44
- package/dist/utils/openapi.js +87 -99
- package/dist/utils/package_manager.js +312 -110
- package/dist/utils/point_in_time.js +49 -53
- package/dist/utils/psql.js +89 -106
- package/dist/utils/service_picker.js +55 -58
- package/dist/utils/string.js +5 -5
- package/dist/utils/ui.js +38 -55
- package/dist/utils/write_sync.js +26 -35
- package/dist/utils/zip.js +4 -3
- package/dist/writer.js +67 -87
- package/package.json +9 -7
package/dist/psql/print/troff.js
CHANGED
|
@@ -1,240 +1,208 @@
|
|
|
1
1
|
import { boolDisplayOf, renderCellValue } from "./units.js";
|
|
2
|
+
//#region src/psql/print/troff.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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 };
|