@jacebenson/jsn 4.3.13-dev.95.1 → 4.3.13-dev.97.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/commands/history.js +34 -3
package/package.json
CHANGED
package/src/commands/history.js
CHANGED
|
@@ -5,11 +5,10 @@ export function historyCmd(wrap) {
|
|
|
5
5
|
declareCapabilities('history', { noInstance: true, skipDailyChecks: true });
|
|
6
6
|
const list = wrap(async (argv, app) => {
|
|
7
7
|
const entries = listHistory({ ...argv, instance: argv['instance-url'], profile: argv['profile-name'] });
|
|
8
|
-
app.ok({ entries, retentionDays: 7, _formatted: entries.
|
|
9
|
-
? entries.map(e => `${e.timestamp} ${e.operation} ${e.table}/${e.sys_id || '(unknown ID)'} ${e.outcome} ${e.instance}${e.reason ? ` — ${e.reason}` : ''}`).join('\n')
|
|
10
|
-
: 'No local mutations in the last seven days.' });
|
|
8
|
+
app.ok({ entries, retentionDays: 7, _formatted: renderHistory(entries, { details: argv.details }) });
|
|
11
9
|
});
|
|
12
10
|
const filters = b => b
|
|
11
|
+
.option('details', { type: 'boolean', default: false, describe: 'Show full record IDs, instance URLs and reasons' })
|
|
13
12
|
.option('since', { type: 'string', describe: 'Earliest ISO timestamp' })
|
|
14
13
|
.option('until', { type: 'string', describe: 'Latest ISO timestamp' })
|
|
15
14
|
.option('instance-url', { type: 'string', describe: 'Filter by instance origin' })
|
|
@@ -24,3 +23,35 @@ export function historyCmd(wrap) {
|
|
|
24
23
|
app.ok({ ...pruneHistory(), _formatted: 'Expired local history removed; seven days retained.' });
|
|
25
24
|
}) }), handler: list };
|
|
26
25
|
}
|
|
26
|
+
|
|
27
|
+
export function renderHistory(entries, { details = false, timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone } = {}) {
|
|
28
|
+
if (!entries.length) return 'No local mutations in the last seven days.';
|
|
29
|
+
const date = new Intl.DateTimeFormat('en-GB', { timeZone, month: 'short', day: '2-digit',
|
|
30
|
+
hour: '2-digit', minute: '2-digit', hourCycle: 'h23' });
|
|
31
|
+
// Strip terminal control characters from stored identifiers and labels.
|
|
32
|
+
// eslint-disable-next-line no-control-regex
|
|
33
|
+
const clean = value => String(value ?? '').replace(/[\x00-\x1f\x7f]/g, ' ');
|
|
34
|
+
const clip = (value, length) => value.length > length ? `${value.slice(0, length - 1)}…` : value;
|
|
35
|
+
const rows = entries.map(entry => {
|
|
36
|
+
let connection = entry.profile;
|
|
37
|
+
if (!connection) {
|
|
38
|
+
try { connection = new URL(entry.instance).host; } catch { connection = entry.instance; }
|
|
39
|
+
}
|
|
40
|
+
return [date.format(new Date(entry.timestamp)), entry.operation, clip(clean(entry.table), 22),
|
|
41
|
+
clip(clean(entry.sys_id || '(unknown)'), 12), entry.outcome, clip(clean(connection), 22)];
|
|
42
|
+
});
|
|
43
|
+
const headers = ['WHEN', 'ACTION', 'TABLE', 'RECORD', 'RESULT', 'CONNECTION'];
|
|
44
|
+
const widths = headers.map((header, i) => Math.max(header.length, ...rows.map(row => row[i].length)));
|
|
45
|
+
const format = row => row.map((cell, i) => cell.padEnd(widths[i])).join(' ').trimEnd();
|
|
46
|
+
const lines = [`Recent mutations · ${timeZone}`, '', format(headers)];
|
|
47
|
+
rows.forEach((row, i) => {
|
|
48
|
+
lines.push(format(row));
|
|
49
|
+
if (details) {
|
|
50
|
+
const entry = entries[i];
|
|
51
|
+
lines.push(` ${clean(entry.timestamp)} · ${clean(entry.table)}/${clean(entry.sys_id || '(unknown)')}`,
|
|
52
|
+
` ${clean(entry.instance)}${entry.reason ? ` · ${clean(entry.reason)}` : ''}`);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
if (!details) lines.push('', 'Use --details for full IDs, URLs and reasons; --json for structured history.');
|
|
56
|
+
return lines.join('\n');
|
|
57
|
+
}
|