@tsplc/debug 0.2.17 → 0.2.18

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.
@@ -1,4 +1,13 @@
1
- import { type Health, type View, deviceHealth, empty, h, healthBadge } from "./dom.ts";
1
+ import {
2
+ type Health,
3
+ type View,
4
+ deviceHealth,
5
+ deviceHref,
6
+ devicesWithHealth,
7
+ empty,
8
+ h,
9
+ healthBadge,
10
+ } from "./dom.ts";
2
11
  import { formatAge, formatClock, formatInterval } from "./format.ts";
3
12
  import { isActive, jobRow, jobTable } from "./jobs.ts";
4
13
  import { recentEntry } from "./recent.ts";
@@ -8,116 +17,151 @@ const HEALTH_ORDER: Health[] = ["fault", "stale", "unknown", "ok"];
8
17
  const RECENT_EVENTS = 12;
9
18
 
10
19
  export const overviewView = (store: Store): View => {
11
- const connection = h("section", { class: "panel" });
12
- const devices = h("section", { class: "panel" });
13
- const jobs = h("section", { class: "panel wide" });
14
- const events = h("section", { class: "panel wide" });
20
+ const connection = h("section", { class: "panel" });
21
+ const devices = h("section", { class: "panel" });
22
+ const jobs = h("section", { class: "panel wide" });
23
+ const events = h("section", { class: "panel wide" });
15
24
 
16
- const renderConnection = () => {
17
- const { session } = store;
18
- connection.replaceChildren(
19
- h("h2", {}, "Connection"),
20
- h(
21
- "dl",
22
- { class: "facts" },
23
- h("dt", {}, "Values"),
24
- h(
25
- "dd",
26
- {},
27
- h("span", { class: `st st-${session.connection.state}` }, session.connection.state),
28
- ` since ${formatClock(session.connection.since)} (${formatAge(store.ageOf(session.connection.since))})`,
29
- ),
30
- h("dt", {}, "Endpoint"),
31
- h("dd", { class: "mono" }, session.connection.endpoint),
32
- session.connection.error && h("dt", {}, "Error"),
33
- session.connection.error && h("dd", { class: "err" }, session.connection.error),
34
- h("dt", {}, "Debugger host"),
35
- h("dd", {}, store.stream === "open" ? "streaming" : `${store.stream}…`),
36
- h("dt", {}, "Reading"),
37
- h(
38
- "dd",
39
- {},
40
- `${session.reading.method}, every ${formatInterval(session.reading.intervalMs)}; values older than ${formatInterval(3 * session.reading.intervalMs)} are marked stale`,
41
- ),
42
- ),
43
- );
44
- };
25
+ const renderConnection = () => {
26
+ const { session } = store;
27
+ connection.replaceChildren(
28
+ h("h2", {}, "Connection"),
29
+ h(
30
+ "dl",
31
+ { class: "facts" },
32
+ h("dt", {}, "Values"),
33
+ h(
34
+ "dd",
35
+ {},
36
+ h(
37
+ "span",
38
+ { class: `st st-${session.connection.state}` },
39
+ session.connection.state,
40
+ ),
41
+ ` since ${formatClock(session.connection.since)} (${formatAge(store.ageOf(session.connection.since))})`,
42
+ ),
43
+ h("dt", {}, "Endpoint"),
44
+ h("dd", { class: "mono" }, session.connection.endpoint),
45
+ session.connection.error && h("dt", {}, "Error"),
46
+ session.connection.error &&
47
+ h("dd", { class: "err" }, session.connection.error),
48
+ h("dt", {}, "Debugger host"),
49
+ h("dd", {}, store.stream === "open" ? "streaming" : `${store.stream}…`),
50
+ h("dt", {}, "Reading"),
51
+ h(
52
+ "dd",
53
+ {},
54
+ `${session.reading.method}, every ${formatInterval(session.reading.intervalMs)}; values older than ${formatInterval(3 * session.reading.intervalMs)} are marked stale`,
55
+ ),
56
+ ),
57
+ );
58
+ };
45
59
 
46
- const renderDevices = () => {
47
- const healths = store.manifest.devices.map((device) => ({
48
- device,
49
- health: deviceHealth(store, device),
50
- }));
51
- const attention = healths.filter(({ health }) => health.health !== "ok");
52
- devices.replaceChildren(
53
- h("h2", {}, h("a", { href: "#/hardware" }, "Devices")),
54
- h(
55
- "div",
56
- { class: "counts" },
57
- ...HEALTH_ORDER.map((health) =>
58
- h(
59
- "div",
60
- { class: `count-box h-${health}` },
61
- h("b", {}, String(healths.filter((entry) => entry.health.health === health).length)),
62
- h("span", {}, health),
63
- ),
64
- ),
65
- ),
66
- ...attention.map(({ device, health }) =>
67
- h(
68
- "div",
69
- { class: "device-line" },
70
- healthBadge(health),
71
- " ",
72
- h("a", { href: `#/hardware/${encodeURIComponent(device.id)}`, class: "mono" }, device.id),
73
- h("span", { class: "dim" }, ` ${health.detail}`),
74
- ),
75
- ),
76
- );
77
- };
60
+ const renderDevices = () => {
61
+ const healths = store.manifest.devices.map((device) => ({
62
+ device,
63
+ health: deviceHealth(store, device),
64
+ }));
65
+ const attention = healths.filter(({ health }) => health.health !== "ok");
66
+ devices.replaceChildren(
67
+ h("h2", {}, h("a", { href: "#/hardware" }, "Devices")),
68
+ h(
69
+ "div",
70
+ { class: "counts" },
71
+ ...HEALTH_ORDER.map((health) =>
72
+ h(
73
+ "div",
74
+ { class: `count-box h-${health}` },
75
+ h(
76
+ "b",
77
+ {},
78
+ String(
79
+ healths.filter((entry) => entry.health.health === health)
80
+ .length,
81
+ ),
82
+ ),
83
+ h("span", {}, health),
84
+ ),
85
+ ),
86
+ ),
87
+ ...attention.map(({ device, health }) =>
88
+ h(
89
+ "div",
90
+ { class: "device-line" },
91
+ healthBadge(health),
92
+ " ",
93
+ h(
94
+ "a",
95
+ {
96
+ href: deviceHref(device.id),
97
+ class: "mono",
98
+ },
99
+ device.id,
100
+ ),
101
+ h("span", { class: "dim" }, ` ${health.detail}`),
102
+ ),
103
+ ),
104
+ );
105
+ };
78
106
 
79
- // The jobs this page reads: the program's own, as the Jobs page shows them by default.
80
- const shown = new Set(store.manifest.jobs.filter((job) => !job.generated).map(({ id }) => id));
81
- const renderJobs = () => {
82
- const active = [...store.jobs.values()].filter((job) => shown.has(job.id) && isActive(job));
83
- jobs.replaceChildren(
84
- h("h2", {}, h("a", { href: "#/jobs" }, "Active jobs")),
85
- h("p", { class: "hint" }, "Busy, or failed since they last started."),
86
- active.length
87
- ? jobTable(active.map((job) => jobRow(store, job)))
88
- : empty("No job is busy or failed."),
89
- );
90
- };
107
+ // The jobs this page reads: the program's own, as the Jobs page shows them by default.
108
+ const shown = new Set(
109
+ store.manifest.jobs.filter((job) => !job.generated).map(({ id }) => id),
110
+ );
111
+ const renderJobs = () => {
112
+ const active = [...store.jobs.values()].filter(
113
+ (job) => shown.has(job.id) && isActive(job),
114
+ );
115
+ jobs.replaceChildren(
116
+ h("h2", {}, h("a", { href: "#/jobs" }, "Active jobs")),
117
+ h("p", { class: "hint" }, "Busy, or failed since they last started."),
118
+ active.length
119
+ ? jobTable(active.map((job) => jobRow(store, job)))
120
+ : empty("No job is busy or failed."),
121
+ );
122
+ };
91
123
 
92
- const renderEvents = () => {
93
- const recent = store.timeline
94
- .filter((entry) => entry.kind === "app" || entry.kind === "trace")
95
- .slice(-RECENT_EVENTS)
96
- .reverse();
97
- events.replaceChildren(
98
- h("h2", {}, h("a", { href: "#/recent" }, "Recent events")),
99
- ...(recent.length
100
- ? recent.map((entry) => recentEntry(store, entry))
101
- : [empty("The program has reported nothing recently.")]),
102
- );
103
- };
124
+ const renderEvents = () => {
125
+ const recent = store.timeline
126
+ .filter((entry) => entry.kind === "app" || entry.kind === "trace")
127
+ .slice(-RECENT_EVENTS)
128
+ .reverse();
129
+ events.replaceChildren(
130
+ h("h2", {}, h("a", { href: "#/recent" }, "Recent events")),
131
+ ...(recent.length
132
+ ? recent.map((entry) => recentEntry(store, entry))
133
+ : [empty("The program has reported nothing recently.")]),
134
+ );
135
+ };
104
136
 
105
- renderConnection();
106
- renderDevices();
107
- renderJobs();
108
- renderEvents();
109
- store.show({
110
- health: store.manifest.devices.filter((device) => device.health).map(({ id }) => id),
111
- jobs: [...shown],
112
- });
113
- return {
114
- element: h("div", { class: "page overview" }, connection, devices, jobs, events),
115
- update(topics) {
116
- const live = topics.has("session") || topics.has("stream");
117
- if (live || topics.has("clock")) renderConnection();
118
- if (live || topics.has("devices")) renderDevices();
119
- if (live || topics.has("jobs") || topics.has("timeline")) renderJobs();
120
- if (topics.has("timeline")) renderEvents();
121
- },
122
- };
137
+ renderConnection();
138
+ renderDevices();
139
+ renderJobs();
140
+ renderEvents();
141
+ store.show({ health: devicesWithHealth(store), jobs: [...shown] });
142
+ return {
143
+ element: h(
144
+ "div",
145
+ { class: "page overview" },
146
+ connection,
147
+ devices,
148
+ jobs,
149
+ events,
150
+ ),
151
+ update(topics) {
152
+ const live = topics.has("session") || topics.has("stream");
153
+ if (live || topics.has("clock")) {
154
+ renderConnection();
155
+ }
156
+ if (live || topics.has("devices")) {
157
+ renderDevices();
158
+ }
159
+ if (live || topics.has("jobs") || topics.has("timeline")) {
160
+ renderJobs();
161
+ }
162
+ if (topics.has("timeline")) {
163
+ renderEvents();
164
+ }
165
+ },
166
+ };
123
167
  };