@jacebenson/jsn 5.5.3-dev.178.1 → 5.5.3-dev.179.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.
- package/package.json +1 -1
- package/src/output.js +18 -4
package/package.json
CHANGED
package/src/output.js
CHANGED
|
@@ -93,6 +93,7 @@ export class OutputWriter {
|
|
|
93
93
|
constructor(opts = {}) {
|
|
94
94
|
this.format = opts.format || FormatAuto;
|
|
95
95
|
this.writer = opts.writer || process.stdout;
|
|
96
|
+
this.errorWriter = opts.errorWriter || process.stderr;
|
|
96
97
|
this.jqFilter = opts.jqFilter || '';
|
|
97
98
|
this.verbose = opts.verbose === true;
|
|
98
99
|
this.raw = opts.raw === true;
|
|
@@ -289,14 +290,27 @@ export class OutputWriter {
|
|
|
289
290
|
}
|
|
290
291
|
}
|
|
291
292
|
|
|
292
|
-
writeCSV(data,
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
293
|
+
writeCSV(data, _opts) {
|
|
294
|
+
// CSV stdout contains only the table, even on a terminal. Pagination is
|
|
295
|
+
// diagnostic output, not an extra row that spreadsheet readers must skip.
|
|
296
296
|
if (Array.isArray(data)) {
|
|
297
297
|
this.writeCSVTable(data);
|
|
298
298
|
} else if (data && typeof data === 'object' && Array.isArray(data.records)) {
|
|
299
299
|
this.writeCSVTable(data.records);
|
|
300
|
+
const page = data.pagination;
|
|
301
|
+
if (page?.hasMore === true) {
|
|
302
|
+
const count = data.records.length;
|
|
303
|
+
const total = Number.isSafeInteger(page.total) && page.total >= 0
|
|
304
|
+
? ` of ${page.total}` : '';
|
|
305
|
+
const unknown = total ? '' : '; total unknown';
|
|
306
|
+
// List commands advance the requested window, including short pages.
|
|
307
|
+
// Do not guess an offset when the envelope lacks that context.
|
|
308
|
+
const nextOffset = Number.isSafeInteger(page.offset) && page.offset >= 0
|
|
309
|
+
&& Number.isSafeInteger(page.limit) && page.limit > 0
|
|
310
|
+
&& Number.isSafeInteger(page.offset + page.limit)
|
|
311
|
+
? `; next offset ${page.offset + page.limit}` : '';
|
|
312
|
+
this.errorWriter.write(`CSV pagination: returned ${count}${total} records${unknown}; more available${nextOffset}.\n`);
|
|
313
|
+
}
|
|
300
314
|
} else {
|
|
301
315
|
this.writeCSVTable([data]);
|
|
302
316
|
}
|