@peers-app/peers-ui 0.34.9 → 0.34.10

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 (77) hide show
  1. package/dist/apps-home/apps-home.js +6 -4
  2. package/dist/components/router.d.ts +1 -1
  3. package/dist/components/router.js +1 -1
  4. package/dist/screens/identity/identity-routes.d.ts +2 -1
  5. package/dist/screens/identity/identity-routes.js +6 -1
  6. package/dist/screens/monitoring/alerts-tab.d.ts +13 -0
  7. package/dist/screens/monitoring/alerts-tab.js +68 -0
  8. package/dist/screens/monitoring/badges.d.ts +25 -0
  9. package/dist/screens/monitoring/badges.js +68 -0
  10. package/dist/screens/monitoring/calls-tab.d.ts +30 -0
  11. package/dist/screens/monitoring/calls-tab.js +104 -0
  12. package/dist/screens/monitoring/charts/chart-math.d.ts +103 -0
  13. package/dist/screens/monitoring/charts/chart-math.js +200 -0
  14. package/dist/screens/monitoring/charts/histogram-chart.d.ts +25 -0
  15. package/dist/screens/monitoring/charts/histogram-chart.js +74 -0
  16. package/dist/screens/monitoring/charts/line-chart.d.ts +33 -0
  17. package/dist/screens/monitoring/charts/line-chart.js +103 -0
  18. package/dist/screens/monitoring/charts/sparkline.d.ts +30 -0
  19. package/dist/screens/monitoring/charts/sparkline.js +61 -0
  20. package/dist/screens/monitoring/charts/use-width.d.ts +9 -0
  21. package/dist/screens/monitoring/charts/use-width.js +31 -0
  22. package/dist/screens/monitoring/definition-forms.d.ts +113 -0
  23. package/dist/screens/monitoring/definition-forms.js +341 -0
  24. package/dist/screens/monitoring/definitions-tab.d.ts +20 -0
  25. package/dist/screens/monitoring/definitions-tab.js +110 -0
  26. package/dist/screens/monitoring/device-picker.d.ts +22 -0
  27. package/dist/screens/monitoring/device-picker.js +29 -0
  28. package/dist/screens/monitoring/form-fields.d.ts +76 -0
  29. package/dist/screens/monitoring/form-fields.js +65 -0
  30. package/dist/screens/monitoring/format.d.ts +51 -0
  31. package/dist/screens/monitoring/format.js +150 -0
  32. package/dist/screens/monitoring/log-lines.d.ts +74 -0
  33. package/dist/screens/monitoring/log-lines.js +138 -0
  34. package/dist/screens/monitoring/log-row.d.ts +12 -0
  35. package/dist/screens/monitoring/log-row.js +23 -0
  36. package/dist/screens/monitoring/logs-tab.d.ts +15 -0
  37. package/dist/screens/monitoring/logs-tab.js +256 -0
  38. package/dist/screens/monitoring/metric-definition-form.d.ts +15 -0
  39. package/dist/screens/monitoring/metric-definition-form.js +50 -0
  40. package/dist/screens/monitoring/metrics-tab.d.ts +37 -0
  41. package/dist/screens/monitoring/metrics-tab.js +149 -0
  42. package/dist/screens/monitoring/monitoring-routes.d.ts +40 -0
  43. package/dist/screens/monitoring/monitoring-routes.js +81 -0
  44. package/dist/screens/monitoring/monitoring-screen.d.ts +17 -0
  45. package/dist/screens/monitoring/monitoring-screen.js +63 -0
  46. package/dist/screens/monitoring/overview-tab.d.ts +33 -0
  47. package/dist/screens/monitoring/overview-tab.js +121 -0
  48. package/dist/screens/monitoring/telemetry-client.d.ts +48 -0
  49. package/dist/screens/monitoring/telemetry-client.js +92 -0
  50. package/dist/screens/monitoring/trigger-form.d.ts +18 -0
  51. package/dist/screens/monitoring/trigger-form.js +71 -0
  52. package/dist/screens/monitoring/use-telemetry.d.ts +39 -0
  53. package/dist/screens/monitoring/use-telemetry.js +120 -0
  54. package/dist/screens/network-viewer/remote-logs-panel.d.ts +1 -1
  55. package/dist/screens/network-viewer/remote-logs-panel.js +5 -3
  56. package/dist/system-apps/index.d.ts +1 -1
  57. package/dist/system-apps/index.js +5 -5
  58. package/dist/system-apps/monitoring.app.d.ts +6 -0
  59. package/dist/system-apps/monitoring.app.js +13 -0
  60. package/dist/tabs-layout/tabs-state.d.ts +4 -2
  61. package/dist/tabs-layout/tabs-state.js +23 -11
  62. package/dist/theme.css +32 -0
  63. package/package.json +3 -3
  64. package/dist/screens/console-logs/console-logs-list.d.ts +0 -2
  65. package/dist/screens/console-logs/console-logs-list.js +0 -284
  66. package/dist/screens/console-logs/follow-newest.d.ts +0 -11
  67. package/dist/screens/console-logs/follow-newest.js +0 -17
  68. package/dist/screens/console-logs/log-display.d.ts +0 -12
  69. package/dist/screens/console-logs/log-display.js +0 -69
  70. package/dist/screens/console-logs/log-filters.d.ts +0 -10
  71. package/dist/screens/console-logs/log-filters.js +0 -8
  72. package/dist/screens/console-logs/mobile-log-card.d.ts +0 -8
  73. package/dist/screens/console-logs/mobile-log-card.js +0 -94
  74. package/dist/screens/console-logs/resizable-table-header.d.ts +0 -14
  75. package/dist/screens/console-logs/resizable-table-header.js +0 -62
  76. package/dist/system-apps/console-logs.app.d.ts +0 -2
  77. package/dist/system-apps/console-logs.app.js +0 -8
@@ -0,0 +1,76 @@
1
+ import { type ReactNode } from "react";
2
+ /** A labeled text input, for Monitoring's definition forms. */
3
+ export declare function TextField(props: {
4
+ id: string;
5
+ label: string;
6
+ value: string;
7
+ onChange: (value: string) => void;
8
+ hint?: ReactNode;
9
+ placeholder?: string;
10
+ disabled?: boolean;
11
+ monospace?: boolean;
12
+ list?: string;
13
+ inputMode?: "numeric" | "decimal" | "text";
14
+ }): import("react/jsx-runtime").JSX.Element;
15
+ /** A labeled multi-line input. */
16
+ export declare function TextAreaField(props: {
17
+ id: string;
18
+ label: string;
19
+ value: string;
20
+ onChange: (value: string) => void;
21
+ hint?: ReactNode;
22
+ placeholder?: string;
23
+ rows?: number;
24
+ }): import("react/jsx-runtime").JSX.Element;
25
+ /** A labeled select. */
26
+ export declare function SelectField<T extends string>(props: {
27
+ id: string;
28
+ label: string;
29
+ value: T;
30
+ options: Array<{
31
+ value: T;
32
+ label: string;
33
+ }>;
34
+ onChange: (value: T) => void;
35
+ hint?: ReactNode;
36
+ }): import("react/jsx-runtime").JSX.Element;
37
+ /** A labeled checkbox. */
38
+ export declare function CheckField(props: {
39
+ id: string;
40
+ label: string;
41
+ checked: boolean;
42
+ onChange: (checked: boolean) => void;
43
+ }): import("react/jsx-runtime").JSX.Element;
44
+ /**
45
+ * Read a section again. Sections that don't refresh on their own say when they last read, so a
46
+ * view left open doesn't pass for current.
47
+ */
48
+ export declare function RefreshButton(props: {
49
+ onClick: () => void;
50
+ loading: boolean;
51
+ /** When the shown data was read; omit for a section that refreshes itself. */
52
+ readAt?: number;
53
+ className?: string;
54
+ }): import("react/jsx-runtime").JSX.Element;
55
+ /**
56
+ * The "Include Monitoring's own reads" switch: off, a view leaves out the calls Monitoring makes
57
+ * to System Telemetry as it refreshes.
58
+ */
59
+ export declare function OwnReadsSwitch(props: {
60
+ id: string;
61
+ checked: boolean;
62
+ onChange: (checked: boolean) => void;
63
+ /** Where it sits in its row; centered by default. */
64
+ className?: string;
65
+ }): import("react/jsx-runtime").JSX.Element;
66
+ /**
67
+ * A filter's input. It applies what's typed once the person pauses, presses Enter or leaves it,
68
+ * so a filter doesn't read the logs again on every key.
69
+ */
70
+ export declare function FilterInput(props: {
71
+ id: string;
72
+ label: string;
73
+ value: string;
74
+ onChange: (value: string) => void;
75
+ placeholder?: string;
76
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextField = TextField;
4
+ exports.TextAreaField = TextAreaField;
5
+ exports.SelectField = SelectField;
6
+ exports.CheckField = CheckField;
7
+ exports.RefreshButton = RefreshButton;
8
+ exports.OwnReadsSwitch = OwnReadsSwitch;
9
+ exports.FilterInput = FilterInput;
10
+ const jsx_runtime_1 = require("react/jsx-runtime");
11
+ const react_1 = require("react");
12
+ const format_1 = require("./format");
13
+ /** A labeled text input, for Monitoring's definition forms. */
14
+ function TextField(props) {
15
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "mb-2", children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: props.id, className: "form-label small mb-1", children: props.label }), (0, jsx_runtime_1.jsx)("input", { id: props.id, className: `form-control form-control-sm ${props.monospace ? "font-monospace" : ""}`, value: props.value, placeholder: props.placeholder, disabled: props.disabled, list: props.list, inputMode: props.inputMode, onChange: (event) => props.onChange(event.target.value) }), props.hint ? (0, jsx_runtime_1.jsx)("div", { className: "form-text small mt-0", children: props.hint }) : null] }));
16
+ }
17
+ /** A labeled multi-line input. */
18
+ function TextAreaField(props) {
19
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "mb-2", children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: props.id, className: "form-label small mb-1", children: props.label }), (0, jsx_runtime_1.jsx)("textarea", { id: props.id, className: "form-control form-control-sm font-monospace", rows: props.rows ?? 2, value: props.value, placeholder: props.placeholder, onChange: (event) => props.onChange(event.target.value) }), props.hint ? (0, jsx_runtime_1.jsx)("div", { className: "form-text small mt-0", children: props.hint }) : null] }));
20
+ }
21
+ /** A labeled select. */
22
+ function SelectField(props) {
23
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "mb-2", children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: props.id, className: "form-label small mb-1", children: props.label }), (0, jsx_runtime_1.jsx)("select", { id: props.id, className: "form-select form-select-sm", value: props.value, onChange: (event) => props.onChange(event.target.value), children: props.options.map((option) => ((0, jsx_runtime_1.jsx)("option", { value: option.value, children: option.label }, option.value))) }), props.hint ? (0, jsx_runtime_1.jsx)("div", { className: "form-text small mt-0", children: props.hint }) : null] }));
24
+ }
25
+ /** A labeled checkbox. */
26
+ function CheckField(props) {
27
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "form-check mb-2", children: [(0, jsx_runtime_1.jsx)("input", { id: props.id, type: "checkbox", className: "form-check-input", checked: props.checked, onChange: (event) => props.onChange(event.target.checked) }), (0, jsx_runtime_1.jsx)("label", { htmlFor: props.id, className: "form-check-label small", children: props.label })] }));
28
+ }
29
+ /**
30
+ * Read a section again. Sections that don't refresh on their own say when they last read, so a
31
+ * view left open doesn't pass for current.
32
+ */
33
+ function RefreshButton(props) {
34
+ return ((0, jsx_runtime_1.jsxs)("div", { className: `d-flex align-items-center gap-2 ${props.className ?? ""}`, children: [props.readAt ? ((0, jsx_runtime_1.jsxs)("span", { className: "small text-body-secondary text-nowrap", children: ["As of ", (0, format_1.formatClock)(props.readAt)] })) : null, (0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-outline-secondary btn-sm text-nowrap", onClick: props.onClick, disabled: props.loading, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-arrow-clockwise me-1", "aria-hidden": "true" }), "Refresh"] })] }));
35
+ }
36
+ /**
37
+ * The "Include Monitoring's own reads" switch: off, a view leaves out the calls Monitoring makes
38
+ * to System Telemetry as it refreshes.
39
+ */
40
+ function OwnReadsSwitch(props) {
41
+ return ((0, jsx_runtime_1.jsxs)("div", { className: `form-check form-switch mb-0 ${props.className ?? "align-self-center"}`, children: [(0, jsx_runtime_1.jsx)("input", { id: props.id, type: "checkbox", role: "switch", "aria-checked": props.checked, className: "form-check-input", checked: props.checked, onChange: (event) => props.onChange(event.target.checked) }), (0, jsx_runtime_1.jsx)("label", { htmlFor: props.id, className: "form-check-label small", children: "Include Monitoring's own reads" })] }));
42
+ }
43
+ /**
44
+ * A filter's input. It applies what's typed once the person pauses, presses Enter or leaves it,
45
+ * so a filter doesn't read the logs again on every key.
46
+ */
47
+ function FilterInput(props) {
48
+ const [draft, setDraft] = (0, react_1.useState)(props.value);
49
+ const { value } = props;
50
+ // The parent re-renders as lines arrive; a ref keeps that from restarting the pause.
51
+ const onChangeRef = (0, react_1.useRef)(props.onChange);
52
+ onChangeRef.current = props.onChange;
53
+ const onChange = (next) => onChangeRef.current(next);
54
+ (0, react_1.useEffect)(() => setDraft(value), [value]);
55
+ (0, react_1.useEffect)(() => {
56
+ if (draft === value)
57
+ return;
58
+ const timer = setTimeout(() => onChangeRef.current(draft), 600);
59
+ return () => clearTimeout(timer);
60
+ }, [draft, value]);
61
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "col-6 col-md-4 col-xl-2", children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: props.id, className: "form-label small text-body-secondary mb-0", children: props.label }), (0, jsx_runtime_1.jsx)("input", { id: props.id, className: "form-control form-control-sm", value: draft, placeholder: props.placeholder, onChange: (event) => setDraft(event.target.value), onBlur: () => draft !== value && onChange(draft), onKeyDown: (event) => {
62
+ if (event.key === "Enter" && draft !== value)
63
+ onChange(draft);
64
+ } })] }));
65
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * How Monitoring writes numbers, durations, sizes and times: in full under 10,000, compact above
3
+ * (12.9K), durations in the unit that reads best (850 µs, 42 ms, 3.2 s, 4.5 min).
4
+ */
5
+ /**
6
+ * A count or plain value: in full under 10,000 (1,284), compact above (12.9K).
7
+ *
8
+ * @param value - The number; `undefined` reads as a dash.
9
+ */
10
+ export declare function formatNumber(value: number | undefined): string;
11
+ /**
12
+ * A duration in milliseconds, in the unit that reads best.
13
+ *
14
+ * @param ms - Milliseconds; `undefined` reads as a dash.
15
+ */
16
+ export declare function formatDuration(ms: number | undefined): string;
17
+ /**
18
+ * A size in bytes: B, KB, MB or GB (1,024 apart).
19
+ *
20
+ * @param bytes - Bytes; `undefined` reads as a dash.
21
+ */
22
+ export declare function formatBytes(bytes: number | undefined): string;
23
+ /**
24
+ * A metric's value in its unit: durations for `ms`, sizes for `bytes` (and `MB`), otherwise the
25
+ * number with its unit after it.
26
+ *
27
+ * @param value - The value; `undefined` reads as a dash.
28
+ * @param unit - The metric's unit, if it has one.
29
+ */
30
+ export declare function formatValue(value: number | undefined, unit?: string): string;
31
+ /**
32
+ * How long ago a moment was: "just now", "4 min ago", "3 h ago", "2 d ago".
33
+ *
34
+ * @param at - Epoch milliseconds.
35
+ * @param now - The current time (for tests).
36
+ */
37
+ export declare function formatAgo(at: number | undefined, now?: number): string;
38
+ /**
39
+ * A log line's or call's time: `14:03:27.512` today, `11/28 14:03:27` on another day.
40
+ *
41
+ * @param at - Epoch milliseconds.
42
+ * @param now - The current time (for tests).
43
+ */
44
+ export declare function formatTime(at: number, now?: number): string;
45
+ /**
46
+ * A clock time to the minute: "14:00" today, "yesterday 22:00", or "Mon 14:00" further back.
47
+ *
48
+ * @param at - Epoch milliseconds.
49
+ * @param now - The current time (for tests).
50
+ */
51
+ export declare function formatClock(at: number, now?: number): string;
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ /**
3
+ * How Monitoring writes numbers, durations, sizes and times: in full under 10,000, compact above
4
+ * (12.9K), durations in the unit that reads best (850 µs, 42 ms, 3.2 s, 4.5 min).
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.formatNumber = formatNumber;
8
+ exports.formatDuration = formatDuration;
9
+ exports.formatBytes = formatBytes;
10
+ exports.formatValue = formatValue;
11
+ exports.formatAgo = formatAgo;
12
+ exports.formatTime = formatTime;
13
+ exports.formatClock = formatClock;
14
+ const fullNumber = new Intl.NumberFormat(undefined, { maximumFractionDigits: 2 });
15
+ const compactNumber = new Intl.NumberFormat(undefined, {
16
+ notation: "compact",
17
+ maximumFractionDigits: 1,
18
+ });
19
+ /**
20
+ * A count or plain value: in full under 10,000 (1,284), compact above (12.9K).
21
+ *
22
+ * @param value - The number; `undefined` reads as a dash.
23
+ */
24
+ function formatNumber(value) {
25
+ if (value === undefined || !Number.isFinite(value))
26
+ return "–";
27
+ return Math.abs(value) < 10_000 ? fullNumber.format(round(value)) : compactNumber.format(value);
28
+ }
29
+ /**
30
+ * A duration in milliseconds, in the unit that reads best.
31
+ *
32
+ * @param ms - Milliseconds; `undefined` reads as a dash.
33
+ */
34
+ function formatDuration(ms) {
35
+ if (ms === undefined || !Number.isFinite(ms))
36
+ return "–";
37
+ if (ms === 0)
38
+ return "0";
39
+ const abs = Math.abs(ms);
40
+ if (abs < 1)
41
+ return `${fullNumber.format(Math.round(ms * 1000))} µs`;
42
+ if (abs < 1_000)
43
+ return `${fullNumber.format(abs < 10 ? round(ms, 1) : Math.round(ms))} ms`;
44
+ if (abs < 60_000)
45
+ return `${fullNumber.format(round(ms / 1_000, 1))} s`;
46
+ if (abs < 3_600_000)
47
+ return `${fullNumber.format(round(ms / 60_000, 1))} min`;
48
+ return `${fullNumber.format(round(ms / 3_600_000, 1))} h`;
49
+ }
50
+ /**
51
+ * A size in bytes: B, KB, MB or GB (1,024 apart).
52
+ *
53
+ * @param bytes - Bytes; `undefined` reads as a dash.
54
+ */
55
+ function formatBytes(bytes) {
56
+ if (bytes === undefined || !Number.isFinite(bytes))
57
+ return "–";
58
+ const units = ["B", "KB", "MB", "GB", "TB"];
59
+ let value = bytes;
60
+ let unit = 0;
61
+ while (Math.abs(value) >= 1024 && unit < units.length - 1) {
62
+ value /= 1024;
63
+ unit++;
64
+ }
65
+ return `${fullNumber.format(unit === 0 ? value : round(value, 1))} ${units[unit]}`;
66
+ }
67
+ /**
68
+ * A metric's value in its unit: durations for `ms`, sizes for `bytes` (and `MB`), otherwise the
69
+ * number with its unit after it.
70
+ *
71
+ * @param value - The value; `undefined` reads as a dash.
72
+ * @param unit - The metric's unit, if it has one.
73
+ */
74
+ function formatValue(value, unit) {
75
+ if (value === undefined || !Number.isFinite(value))
76
+ return "–";
77
+ switch (unit) {
78
+ case "ms":
79
+ return formatDuration(value);
80
+ case "bytes":
81
+ return formatBytes(value);
82
+ case "MB":
83
+ return formatBytes(value * 1024 * 1024);
84
+ case "%":
85
+ return `${formatNumber(value)}%`;
86
+ case undefined:
87
+ case "":
88
+ return formatNumber(value);
89
+ default:
90
+ return `${formatNumber(value)} ${unit}`;
91
+ }
92
+ }
93
+ /**
94
+ * How long ago a moment was: "just now", "4 min ago", "3 h ago", "2 d ago".
95
+ *
96
+ * @param at - Epoch milliseconds.
97
+ * @param now - The current time (for tests).
98
+ */
99
+ function formatAgo(at, now = Date.now()) {
100
+ if (at === undefined)
101
+ return "–";
102
+ const seconds = Math.max(0, Math.round((now - at) / 1000));
103
+ if (seconds < 45)
104
+ return "just now";
105
+ const minutes = Math.round(seconds / 60);
106
+ if (minutes < 60)
107
+ return `${minutes} min ago`;
108
+ const hours = Math.round(minutes / 60);
109
+ if (hours < 48)
110
+ return `${hours} h ago`;
111
+ return `${Math.round(hours / 24)} d ago`;
112
+ }
113
+ /**
114
+ * A log line's or call's time: `14:03:27.512` today, `11/28 14:03:27` on another day.
115
+ *
116
+ * @param at - Epoch milliseconds.
117
+ * @param now - The current time (for tests).
118
+ */
119
+ function formatTime(at, now = Date.now()) {
120
+ const date = new Date(at);
121
+ const time = `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
122
+ if (new Date(now).toDateString() === date.toDateString()) {
123
+ return `${time}.${String(date.getMilliseconds()).padStart(3, "0")}`;
124
+ }
125
+ return `${date.getMonth() + 1}/${date.getDate()} ${time}`;
126
+ }
127
+ /**
128
+ * A clock time to the minute: "14:00" today, "yesterday 22:00", or "Mon 14:00" further back.
129
+ *
130
+ * @param at - Epoch milliseconds.
131
+ * @param now - The current time (for tests).
132
+ */
133
+ function formatClock(at, now = Date.now()) {
134
+ const date = new Date(at);
135
+ const time = `${pad(date.getHours())}:${pad(date.getMinutes())}`;
136
+ const today = new Date(now);
137
+ if (today.toDateString() === date.toDateString())
138
+ return time;
139
+ const yesterday = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1);
140
+ if (yesterday.toDateString() === date.toDateString())
141
+ return `yesterday ${time}`;
142
+ return `${date.toLocaleDateString(undefined, { weekday: "short" })} ${time}`;
143
+ }
144
+ function pad(value) {
145
+ return String(value).padStart(2, "0");
146
+ }
147
+ function round(value, digits = 2) {
148
+ const factor = 10 ** digits;
149
+ return Math.round(value * factor) / factor;
150
+ }
@@ -0,0 +1,74 @@
1
+ import type { ILogRecord, IReadLogsInput, LogLevel } from "@peers-app/peers-sdk";
2
+ /**
3
+ * The Logs section keeps at most this many lines: following drops the oldest past it, and loading
4
+ * older lines drops the newest.
5
+ */
6
+ export declare const MAX_LOADED_LINES = 2000;
7
+ /** Lines per page, back and forward. */
8
+ export declare const LOG_PAGE_SIZE = 200;
9
+ /** The Logs section's filters, as its inputs hold them. */
10
+ export interface ILogFilters {
11
+ /** Levels to show; empty shows every level. */
12
+ levels: LogLevel[];
13
+ search: string;
14
+ /** Comma-separated lists. */
15
+ sources: string;
16
+ packageIds: string;
17
+ groupIds: string;
18
+ processes: string;
19
+ events: string;
20
+ traceId: string;
21
+ }
22
+ /** No filters: every line. */
23
+ export declare function emptyLogFilters(traceId?: string): ILogFilters;
24
+ /**
25
+ * The `readLogs` input for a set of filters (without paging).
26
+ *
27
+ * @param filters - The section's filters.
28
+ */
29
+ export declare function toReadLogsInput(filters: ILogFilters): IReadLogsInput;
30
+ /** How many filters besides level and search are set, for the filters button's count. */
31
+ export declare function countFieldFilters(filters: ILogFilters): number;
32
+ /** Loaded lines, oldest first. */
33
+ export interface ILoadedLines {
34
+ lines: ILogRecord[];
35
+ /** Older lines match that aren't loaded. */
36
+ hasOlder: boolean;
37
+ /** Newer lines were dropped to keep the cap; reading the newest page brings them back. */
38
+ hasNewer?: boolean;
39
+ }
40
+ /**
41
+ * Add a page of older lines (as `readLogs` returns them: newest first) before the loaded ones,
42
+ * dropping the newest past {@link MAX_LOADED_LINES}.
43
+ *
44
+ * @param loaded - The loaded lines.
45
+ * @param page - The older page.
46
+ * @param hasMore - Whether `readLogs` said still older lines match.
47
+ * @param max - The most to keep.
48
+ */
49
+ export declare function addOlder(loaded: ILoadedLines, page: ILogRecord[], hasMore: boolean, max?: number): ILoadedLines;
50
+ /**
51
+ * Add newer lines (as `readLogs` returns them after a cursor: oldest first) after the loaded ones,
52
+ * dropping the oldest past {@link MAX_LOADED_LINES}.
53
+ *
54
+ * @param loaded - The loaded lines.
55
+ * @param page - The newer lines.
56
+ * @param max - The most to keep.
57
+ */
58
+ export declare function addNewer(loaded: ILoadedLines, page: ILogRecord[], max?: number): ILoadedLines;
59
+ /**
60
+ * The newest loaded line's id, the cursor to follow from.
61
+ *
62
+ * @param loaded - The loaded lines.
63
+ */
64
+ export declare function newestLogId(loaded: ILoadedLines): number | undefined;
65
+ /**
66
+ * An error logged with a line: `data.error`, as the logger records an `Error` argument.
67
+ *
68
+ * @param line - A log line.
69
+ */
70
+ export declare function lineError(line: ILogRecord): {
71
+ name?: string;
72
+ message?: string;
73
+ stack?: string;
74
+ } | undefined;
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LOG_PAGE_SIZE = exports.MAX_LOADED_LINES = void 0;
4
+ exports.emptyLogFilters = emptyLogFilters;
5
+ exports.toReadLogsInput = toReadLogsInput;
6
+ exports.countFieldFilters = countFieldFilters;
7
+ exports.addOlder = addOlder;
8
+ exports.addNewer = addNewer;
9
+ exports.newestLogId = newestLogId;
10
+ exports.lineError = lineError;
11
+ /**
12
+ * The Logs section keeps at most this many lines: following drops the oldest past it, and loading
13
+ * older lines drops the newest.
14
+ */
15
+ exports.MAX_LOADED_LINES = 2_000;
16
+ /** Lines per page, back and forward. */
17
+ exports.LOG_PAGE_SIZE = 200;
18
+ /** No filters: every line. */
19
+ function emptyLogFilters(traceId = "") {
20
+ return {
21
+ levels: [],
22
+ search: "",
23
+ sources: "",
24
+ packageIds: "",
25
+ groupIds: "",
26
+ processes: "",
27
+ events: "",
28
+ traceId,
29
+ };
30
+ }
31
+ function list(text) {
32
+ const items = text
33
+ .split(",")
34
+ .map((item) => item.trim())
35
+ .filter(Boolean);
36
+ return items.length ? items : undefined;
37
+ }
38
+ /**
39
+ * The `readLogs` input for a set of filters (without paging).
40
+ *
41
+ * @param filters - The section's filters.
42
+ */
43
+ function toReadLogsInput(filters) {
44
+ const input = {};
45
+ if (filters.levels.length)
46
+ input.levels = [...filters.levels];
47
+ const search = filters.search.trim();
48
+ if (search)
49
+ input.search = search;
50
+ const sources = list(filters.sources);
51
+ if (sources)
52
+ input.sources = sources;
53
+ const packageIds = list(filters.packageIds);
54
+ if (packageIds)
55
+ input.packageIds = packageIds;
56
+ const groupIds = list(filters.groupIds);
57
+ if (groupIds)
58
+ input.groupIds = groupIds;
59
+ const processes = list(filters.processes);
60
+ if (processes)
61
+ input.processes = processes;
62
+ const events = list(filters.events);
63
+ if (events)
64
+ input.events = events;
65
+ const traceId = filters.traceId.trim();
66
+ if (traceId)
67
+ input.traceId = traceId;
68
+ return input;
69
+ }
70
+ /** How many filters besides level and search are set, for the filters button's count. */
71
+ function countFieldFilters(filters) {
72
+ return [
73
+ filters.sources,
74
+ filters.packageIds,
75
+ filters.groupIds,
76
+ filters.processes,
77
+ filters.events,
78
+ filters.traceId,
79
+ ].filter((value) => value.trim()).length;
80
+ }
81
+ /**
82
+ * Add a page of older lines (as `readLogs` returns them: newest first) before the loaded ones,
83
+ * dropping the newest past {@link MAX_LOADED_LINES}.
84
+ *
85
+ * @param loaded - The loaded lines.
86
+ * @param page - The older page.
87
+ * @param hasMore - Whether `readLogs` said still older lines match.
88
+ * @param max - The most to keep.
89
+ */
90
+ function addOlder(loaded, page, hasMore, max = exports.MAX_LOADED_LINES) {
91
+ const known = new Set(loaded.lines.map((line) => line.logId));
92
+ const older = [...page].reverse().filter((line) => !known.has(line.logId));
93
+ const lines = [...older, ...loaded.lines];
94
+ if (lines.length <= max)
95
+ return { lines, hasOlder: hasMore, hasNewer: loaded.hasNewer };
96
+ return { lines: lines.slice(0, max), hasOlder: hasMore, hasNewer: true };
97
+ }
98
+ /**
99
+ * Add newer lines (as `readLogs` returns them after a cursor: oldest first) after the loaded ones,
100
+ * dropping the oldest past {@link MAX_LOADED_LINES}.
101
+ *
102
+ * @param loaded - The loaded lines.
103
+ * @param page - The newer lines.
104
+ * @param max - The most to keep.
105
+ */
106
+ function addNewer(loaded, page, max = exports.MAX_LOADED_LINES) {
107
+ if (page.length === 0)
108
+ return loaded;
109
+ const known = new Set(loaded.lines.map((line) => line.logId));
110
+ const lines = [...loaded.lines, ...page.filter((line) => !known.has(line.logId))].sort((a, b) => a.logId - b.logId);
111
+ if (lines.length <= max)
112
+ return { ...loaded, lines };
113
+ return { ...loaded, lines: lines.slice(lines.length - max), hasOlder: true };
114
+ }
115
+ /**
116
+ * The newest loaded line's id, the cursor to follow from.
117
+ *
118
+ * @param loaded - The loaded lines.
119
+ */
120
+ function newestLogId(loaded) {
121
+ return loaded.lines.length ? loaded.lines[loaded.lines.length - 1].logId : undefined;
122
+ }
123
+ /**
124
+ * An error logged with a line: `data.error`, as the logger records an `Error` argument.
125
+ *
126
+ * @param line - A log line.
127
+ */
128
+ function lineError(line) {
129
+ const error = line.data?.error;
130
+ if (!error || typeof error !== "object")
131
+ return undefined;
132
+ const { name, message, stack } = error;
133
+ return {
134
+ name: typeof name === "string" ? name : undefined,
135
+ message: typeof message === "string" ? message : undefined,
136
+ stack: typeof stack === "string" ? stack : undefined,
137
+ };
138
+ }
@@ -0,0 +1,12 @@
1
+ import type { ILogRecord } from "@peers-app/peers-sdk";
2
+ /** Props for {@link LogRow}. */
3
+ export interface LogRowProps {
4
+ line: ILogRecord;
5
+ /** Narrow the Logs and Calls sections to a trace. */
6
+ onTrace: (traceId: string) => void;
7
+ }
8
+ /**
9
+ * One log line: time, level, process, source, package and text; opened, its event, group, trace
10
+ * and logged data (an error's stack set apart).
11
+ */
12
+ export declare function LogRow(props: LogRowProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogRow = LogRow;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const badges_1 = require("./badges");
7
+ const format_1 = require("./format");
8
+ const log_lines_1 = require("./log-lines");
9
+ /**
10
+ * One log line: time, level, process, source, package and text; opened, its event, group, trace
11
+ * and logged data (an error's stack set apart).
12
+ */
13
+ function LogRow(props) {
14
+ const { line } = props;
15
+ const [open, setOpen] = (0, react_1.useState)(false);
16
+ const packageName = (0, badges_1.usePackageName)(line.packageId);
17
+ const error = (0, log_lines_1.lineError)(line);
18
+ const hasDetails = !!(line.data || line.event || line.groupId || line.traceId || line.packageId);
19
+ return ((0, jsx_runtime_1.jsxs)("div", { "data-log-id": line.logId, className: `border-bottom px-2 py-1 small ${line.level === "error" ? "bg-danger-subtle" : line.level === "warn" ? "bg-warning-subtle" : ""}`, children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex flex-wrap align-items-baseline gap-2", children: [(0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-link btn-sm p-0 text-body-secondary text-decoration-none font-monospace", "aria-expanded": open, "aria-label": `${open ? "Hide" : "Show"} details for line ${line.logId}`, onClick: () => setOpen((value) => !value), disabled: !hasDetails, style: { fontSize: "0.75rem", minWidth: 96, textAlign: "left" }, children: [hasDetails ? ((0, jsx_runtime_1.jsx)("i", { className: `bi ${open ? "bi-chevron-down" : "bi-chevron-right"} me-1`, "aria-hidden": "true" })) : null, (0, format_1.formatTime)(line.timestamp)] }), (0, jsx_runtime_1.jsx)(badges_1.LevelBadge, { level: line.level }), (0, jsx_runtime_1.jsx)("span", { className: "badge text-bg-light border", children: line.process }), line.source ? (0, jsx_runtime_1.jsx)("span", { className: "text-body-secondary", children: line.source }) : null, packageName ? ((0, jsx_runtime_1.jsxs)("span", { className: "text-body-secondary text-truncate", style: { maxWidth: 180 }, title: line.packageId, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-box me-1", "aria-hidden": "true" }), packageName] })) : null, (0, jsx_runtime_1.jsx)("span", { className: "flex-grow-1", style: { whiteSpace: "pre-wrap", overflowWrap: "anywhere", minWidth: "min(100%, 240px)" }, children: line.message })] }), open ? ((0, jsx_runtime_1.jsxs)("div", { className: "ms-4 mt-1 mb-2", children: [(0, jsx_runtime_1.jsxs)("dl", { className: "row mb-1 small", children: [line.event ? (0, jsx_runtime_1.jsx)(Detail, { name: "Event", value: (0, jsx_runtime_1.jsx)("code", { children: line.event }) }) : null, line.groupId ? (0, jsx_runtime_1.jsx)(Detail, { name: "Group", value: (0, jsx_runtime_1.jsx)("code", { children: line.groupId }) }) : null, line.packageId ? ((0, jsx_runtime_1.jsx)(Detail, { name: "Package", value: (0, jsx_runtime_1.jsx)("code", { children: line.packageId }) })) : null, line.traceId ? ((0, jsx_runtime_1.jsx)(Detail, { name: "Trace", value: (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm p-0 font-monospace", onClick: () => props.onTrace(line.traceId), children: line.traceId }) })) : null, (0, jsx_runtime_1.jsx)(Detail, { name: "Line", value: (0, jsx_runtime_1.jsx)("code", { children: line.logId }) })] }), error?.stack ? ((0, jsx_runtime_1.jsx)("pre", { className: "small p-2 rounded bg-danger bg-opacity-10 text-danger-emphasis mb-1", style: { maxHeight: 240, whiteSpace: "pre-wrap" }, children: error.stack })) : null, line.data ? ((0, jsx_runtime_1.jsx)("pre", { className: "small p-2 rounded bg-body-tertiary mb-0", style: { maxHeight: 320, whiteSpace: "pre-wrap", overflowWrap: "anywhere" }, children: JSON.stringify(line.data, null, 2) })) : null] })) : null] }));
20
+ }
21
+ function Detail(props) {
22
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("dt", { className: "col-3 col-md-2 fw-normal text-body-secondary", children: props.name }), (0, jsx_runtime_1.jsx)("dd", { className: "col-9 col-md-10 mb-0 text-break", children: props.value })] }));
23
+ }
@@ -0,0 +1,15 @@
1
+ import type { MonitoringSectionProps } from "./monitoring-screen";
2
+ /** How often the section asks for new lines while following: this device, and another. */
3
+ export declare const FOLLOW_MS: {
4
+ readonly local: 2000;
5
+ readonly remote: 5000;
6
+ };
7
+ /**
8
+ * Logs: a device's stored lines, oldest at the top and newest at the bottom. It follows new lines
9
+ * (by cursor) until paused, keeps the reader's place while they scroll back, and filters by level
10
+ * (several at once), words, source, package, group, process, event and trace. Paging back pauses
11
+ * following and keeps the cap by letting the newest lines go; Follow then starts again from the
12
+ * newest. If the opening read fails, following tries it again each tick. Clearing deletes this
13
+ * device's lines only.
14
+ */
15
+ export declare function LogsTab(props: MonitoringSectionProps): import("react/jsx-runtime").JSX.Element;