@intellectual-frontiers/telemetry 0.0.0-stage → 0.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/src/render.ts ADDED
@@ -0,0 +1,489 @@
1
+ // Spec: 0001-telemetry FR-021
2
+ /**
3
+ * The console as a rendering of OpenTelemetry signals (commons 0001-telemetry FR-021 to FR-023): a pure reducer from a state, an input (a
4
+ * span that started, recorded an event or ended, a log record, an export that failed, a tick of the clock, the end of the run) and the
5
+ * time, to the next state and the frames to write. The runtime's `console.ts` feeds it and writes what it returns; a test feeds it and
6
+ * reads the frames through `vt.ts`'s screen.
7
+ *
8
+ * Five modes (FR-021):
9
+ * - `attended`: a live region of the spans in progress, nested by parent, each with its elapsed time and its progress (FR-023), redrawn in
10
+ * place (cursor up, erase in display); a line that is final (a span that ended, a log record) is written above the region and stays.
11
+ * Every line is cut to the terminal's width by display width, so nothing wraps.
12
+ * - `plain`: the final lines only, appended, with no escape sequence at all (no colour, no cursor movement), for a log or a pipe; a line
13
+ * is not cut.
14
+ * - `quiet`: the final lines that are warnings, errors (a span that failed, a log record of the role `warning` or `error`, or of severity
15
+ * WARN or more), actions (the role `action`: a step that is the person's to take, FR-027) or results (the role `result`), appended;
16
+ * coloured where the look allows it.
17
+ * - `silent`: nothing.
18
+ * - `json`: one OTLP JSON document per line, each an `ExportLogsServiceRequest` (`otlp.ts`'s `encodeLogs`) holding one log record: a log
19
+ * record as it is; a span that ended as a log record whose `eventName` is the span's name, whose time is its end, whose severity is
20
+ * ERROR where it failed and INFO otherwise, whose body is its line as `plain` writes it (without indentation, with ASCII marks), with
21
+ * its attributes and its trace and span ids; the export warning as a WARN record named `ifc.console.export`.
22
+ *
23
+ * Only a signal whose kind has a presentation role (`signals.ts`'s `roleOf`) other than `none` is shown; an undeclared kind is not. A span
24
+ * that is not shown still nests: its children are shown at its depth. How a span ended: ⏭️ where it recorded an event named `skipped`,
25
+ * ⏹️ where it recorded one named `cancelled` (and for a span still open at the end of the run), ❌ where its status is an error, ✅
26
+ * otherwise; marks and colours come from `palette.ts`, with its ASCII fallbacks and colour only where the look allows (FR-022).
27
+ *
28
+ * An export that failed is said once, dimmed, at the end of the run, and nowhere else (FR-024). Text from a signal is cleaned of control
29
+ * characters, so a signal never moves the cursor. Time comes only from the `now` given (nanoseconds since the Unix epoch, as signals' times).
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import { initial, render } from "./render.ts";
34
+ * import { defineSignals } from "./signals.ts";
35
+ * const registry = defineSignals({ "build.step": { signal: "span", role: "step", attributes: { target: "string" } } });
36
+ * let state = initial({ mode: "plain", look: { colour: false, emoji: true, columns: 80 }, registry });
37
+ * // ...for each signal: ({ state, frames } = render(state, { kind: "span-end", span, source }, now)); write(frames);
38
+ * ```
39
+ *
40
+ * @module
41
+ */
42
+ import { absurd } from "@intellectual-frontiers/core";
43
+ import {
44
+ type AnyValue,
45
+ type Attributes,
46
+ type AttributeValue,
47
+ type LogRecord,
48
+ SEVERITY,
49
+ type SeverityNumber,
50
+ severityText,
51
+ type SpanData,
52
+ type SpanEvent,
53
+ } from "./otel.ts";
54
+ import { encodeLogs } from "./otlp.ts";
55
+ import { type Capabilities, label, type MarkKind, mark, paint } from "@intellectual-frontiers/terminal/palette";
56
+ import { type Declarations, type Registry, type Role, roleOf, type Source, type SpanStart } from "./signals.ts";
57
+ import { cutToWidth } from "@intellectual-frontiers/terminal/width";
58
+
59
+ /** How the console writes: see the module. */
60
+ export type Mode = "attended" | "plain" | "quiet" | "silent" | "json";
61
+
62
+ /** Every mode, in a fixed order. */
63
+ export const MODES: readonly Mode[] = ["attended", "plain", "quiet", "silent", "json"];
64
+
65
+ /** A mode by its name; undefined for another text. */
66
+ export function parseMode(text: string): Mode | undefined {
67
+ return MODES.find((m) => m === text.trim().toLowerCase());
68
+ }
69
+
70
+ /** The mode to use: the one asked for where it names one, else `attended` at a terminal and `plain` elsewhere (FR-026). */
71
+ export function chooseMode(facts: { readonly requested?: string | undefined; readonly tty: boolean }): Mode {
72
+ const asked = facts.requested === undefined ? undefined : parseMode(facts.requested);
73
+ return asked ?? (facts.tty ? "attended" : "plain");
74
+ }
75
+
76
+ /** What the renderer is given: the processor's signals, a failed export, a tick of the clock (to redraw elapsed times), the end of the run. */
77
+ export type Input =
78
+ | { readonly kind: "span-start"; readonly span: SpanStart; readonly source: Source }
79
+ | { readonly kind: "span-event"; readonly span: SpanStart; readonly event: SpanEvent; readonly source: Source }
80
+ | { readonly kind: "span-end"; readonly span: SpanData; readonly source: Source }
81
+ | { readonly kind: "log"; readonly record: LogRecord; readonly source: Source }
82
+ | { readonly kind: "export-warning"; readonly message: string }
83
+ | { readonly kind: "tick" }
84
+ | { readonly kind: "finish" };
85
+
86
+ /** What a renderer is made with. */
87
+ export type RenderConfig = {
88
+ readonly mode: Mode;
89
+ /** What the terminal shows: colour, emoji, its width (a `Look` of `system/tty` is one). */
90
+ readonly look: Capabilities;
91
+ /** The registry that gives each kind its presentation role. */
92
+ readonly registry: Registry<Declarations>;
93
+ /** A signal's text from its kind and attributes; `defaultText` where not given (a log record's string body comes first). */
94
+ readonly text?: (name: string, attributes: Attributes) => string;
95
+ /** The most lines the live region takes (10 by default, at least 2); the spans beyond are counted on its last line. */
96
+ readonly maxLive?: number;
97
+ };
98
+
99
+ type Known = { readonly depth: number; readonly shown: boolean; readonly anchor: string | undefined };
100
+
101
+ type Progress = { readonly done: number; readonly total: number | undefined };
102
+
103
+ type Live = {
104
+ readonly key: string;
105
+ readonly anchor: string | undefined;
106
+ readonly depth: number;
107
+ readonly text: string;
108
+ readonly start: bigint;
109
+ readonly progress: Progress | undefined;
110
+ };
111
+
112
+ /** The renderer's state: what is open, what the screen shows of the live region, the warnings kept for the end. */
113
+ export type State = {
114
+ readonly config: RenderConfig;
115
+ /** Every span started and not ended, shown or not, by trace and span id. */
116
+ readonly spans: ReadonlyMap<string, Known>;
117
+ /** The shown spans in progress, in the order they started. */
118
+ readonly live: readonly Live[];
119
+ /** The lines of the live region on the screen (attended). */
120
+ readonly drawn: number;
121
+ /** The export warnings, each once, said at the end. */
122
+ readonly warnings: readonly string[];
123
+ /** The last source seen, for the records `json` writes of its own. */
124
+ readonly source: Source | undefined;
125
+ /** Whether the run has finished; nothing is written after. */
126
+ readonly finished: boolean;
127
+ };
128
+
129
+ /** A reducer's step: the next state and the frames to write (empty for none). */
130
+ export type Step = { readonly state: State; readonly frames: string };
131
+
132
+ /** The state a renderer starts in. */
133
+ export function initial(config: RenderConfig): State {
134
+ return { config, spans: new Map(), live: [], drawn: 0, warnings: [], source: undefined, finished: false };
135
+ }
136
+
137
+ const ESC = String.fromCharCode(0x1b);
138
+ const CONTROL = new RegExp(
139
+ `[${String.fromCharCode(0)}-${String.fromCharCode(0x1f)}${String.fromCharCode(0x7f)}-${String.fromCharCode(0x9f)}]`,
140
+ "g",
141
+ );
142
+ const NS_PER_MS = 1_000_000n;
143
+
144
+ /** A text with every control character but the line feed replaced (a tab by a space, the rest by `?`), so it never moves the cursor. */
145
+ export function clean(text: string): string {
146
+ return text
147
+ .split("\n")
148
+ .map((l) => l.replace(CONTROL, (c) => (c === "\t" ? " " : "?")))
149
+ .join("\n");
150
+ }
151
+
152
+ function valueText(v: AttributeValue): string {
153
+ if (v instanceof Uint8Array) return `${v.length} bytes`;
154
+ if (Array.isArray(v)) return (v as readonly (string | number | bigint | boolean)[]).map(String).join(",");
155
+ return String(v);
156
+ }
157
+
158
+ /**
159
+ * The text of a signal by default: a span's is its kind and its attributes' values, in their order, separated by spaces (`build site`); a
160
+ * log record's is its attributes' values alone, or its kind where it has none (a log record with a string body shows the body).
161
+ */
162
+ export function defaultText(name: string, attributes: Attributes, signal: "span" | "log" = "span"): string {
163
+ const values = Object.values(attributes).map(valueText);
164
+ return signal === "log" && values.length > 0 ? values.join(" ") : [name, ...values].join(" ");
165
+ }
166
+
167
+ /** A duration in nanoseconds as a person reads it: `420ms`, `1.2s`, `3m04s`, `2h05m` (cut, never rounded up; a negative one is `0ms`). */
168
+ export function duration(ns: bigint): string {
169
+ const ms = ns < 0n ? 0 : Number(ns / NS_PER_MS);
170
+ if (ms < 1000) return `${ms}ms`;
171
+ if (ms < 60_000) return `${(Math.floor(ms / 100) / 10).toFixed(1)}s`;
172
+ const s = Math.floor(ms / 1000);
173
+ const pad = (n: number): string => String(n).padStart(2, "0");
174
+ if (s < 3600) return `${Math.floor(s / 60)}m${pad(s % 60)}s`;
175
+ return `${Math.floor(s / 3600)}h${pad(Math.floor(s / 60) % 60)}m`;
176
+ }
177
+
178
+ /** How far a span has come: `done/total` and the percentage where there is a positive total, else `done`. */
179
+ export function progressText(done: number, total?: number): string {
180
+ if (total === undefined || !(total > 0)) return `${done}`;
181
+ const pct = Math.max(0, Math.min(100, Math.floor((done / total) * 100)));
182
+ return `${done}/${total} ${pct}%`;
183
+ }
184
+
185
+ const keyOf = (traceId: string, spanId: string): string => `${traceId}:${spanId}`;
186
+
187
+ const shownRole = (role: Role | undefined): role is Exclude<Role, "none"> => role !== undefined && role !== "none";
188
+
189
+ const numberOf = (v: AttributeValue | undefined): number | undefined =>
190
+ typeof v === "number" ? v : typeof v === "bigint" ? Number(v) : undefined;
191
+
192
+ /** How a span ended, as a mark: a `skipped` or `cancelled` event first, then its status. */
193
+ export function outcomeOf(span: SpanData): MarkKind {
194
+ if (span.events.some((e) => e.name === "skipped")) return "skipped";
195
+ if (span.events.some((e) => e.name === "cancelled")) return "cancelled";
196
+ return span.status.kind === "error" ? "failed" : "done";
197
+ }
198
+
199
+ /** A line to write, and whether `quiet` writes it. */
200
+ type Line = { readonly text: string; readonly quiet: boolean };
201
+
202
+ /** What colour and emoji a mode may use: `plain` none of the colour, whatever the look. */
203
+ function capsOf(config: RenderConfig): { readonly colour: boolean; readonly emoji: boolean } {
204
+ const colour = (config.mode === "attended" || config.mode === "quiet") && config.look.colour;
205
+ return { colour, emoji: config.look.emoji };
206
+ }
207
+
208
+ const indent = (depth: number): string => " ".repeat(depth);
209
+
210
+ /** Lines of a text that may hold line feeds: the first after `head`, the rest under it, two columns further in. */
211
+ function block(depth: number, head: (first: string) => string, text: string): readonly string[] {
212
+ const [first = "", ...rest] = clean(text).split("\n");
213
+ return [indent(depth) + head(first), ...rest.map((l) => indent(depth + 1) + l)];
214
+ }
215
+
216
+ function endedLines(
217
+ config: RenderConfig,
218
+ depth: number,
219
+ text: string,
220
+ kind: MarkKind,
221
+ message: string | undefined,
222
+ took: bigint,
223
+ ): string[] {
224
+ const caps = capsOf(config);
225
+ const after =
226
+ (message === undefined || message === "" ? "" : `: ${paint("failure", clean(message).split("\n")[0] ?? "", caps)}`) +
227
+ ` ${paint("dim", duration(took), caps)}`;
228
+ const lines = [...block(depth, (first) => label(kind, first, caps), text)];
229
+ const last = lines.length - 1;
230
+ lines[last] = `${lines[last] ?? ""}${after}`;
231
+ return lines;
232
+ }
233
+
234
+ function logLines(
235
+ config: RenderConfig,
236
+ depth: number,
237
+ role: Exclude<Role, "none">,
238
+ severity: SeverityNumber,
239
+ text: string,
240
+ ): readonly string[] {
241
+ const caps = capsOf(config);
242
+ const marked =
243
+ (kind: MarkKind) =>
244
+ (first: string): string =>
245
+ label(kind, first, caps);
246
+ switch (role) {
247
+ case "hint":
248
+ return block(depth, marked("hint"), text);
249
+ case "warning":
250
+ return block(depth, marked("warning"), text);
251
+ case "pending":
252
+ return block(depth, marked("pending"), text);
253
+ case "action":
254
+ return block(depth, marked("action"), text);
255
+ case "error":
256
+ return block(depth, marked("failed"), text);
257
+ case "detail":
258
+ return block(depth, (first) => paint("dim", first, caps), text);
259
+ case "step":
260
+ case "progress":
261
+ case "result":
262
+ return severity >= SEVERITY.ERROR
263
+ ? block(depth, marked("failed"), text)
264
+ : severity >= SEVERITY.WARN
265
+ ? block(depth, marked("warning"), text)
266
+ : block(depth, (first) => first, text);
267
+ default:
268
+ return absurd(role);
269
+ }
270
+ }
271
+
272
+ function bodyText(body: AnyValue | undefined): string | undefined {
273
+ return typeof body === "string" ? body : undefined;
274
+ }
275
+
276
+ function textOf(config: RenderConfig, name: string, attributes: Attributes, signal: "span" | "log" = "span"): string {
277
+ return config.text === undefined ? defaultText(name, attributes, signal) : config.text(name, attributes);
278
+ }
279
+
280
+ /** The live region's lines, nested by parent: each span under the nearest shown ancestor still in progress. */
281
+ function regionLines(state: State, now: bigint): readonly string[] {
282
+ const { config, live } = state;
283
+ const caps = capsOf(config);
284
+ const liveKeys = new Set(live.map((l) => l.key));
285
+ const ordered: Live[] = [];
286
+ const visit = (l: Live): void => {
287
+ ordered.push(l);
288
+ for (const child of live) if (child.anchor === l.key) visit(child);
289
+ };
290
+ for (const l of live) if (l.anchor === undefined || !liveKeys.has(l.anchor)) visit(l);
291
+ const lineOf = (l: Live): string => {
292
+ const first = clean(l.text).split("\n")[0] ?? "";
293
+ const progress = l.progress === undefined ? "" : ` ${paint("hint", progressText(l.progress.done, l.progress.total), caps)}`;
294
+ return `${indent(l.depth)}${paint("accent", `${first}…`, caps)} ${paint("dim", duration(now - l.start), caps)}${progress}`;
295
+ };
296
+ const max = Math.max(2, config.maxLive ?? 10);
297
+ if (ordered.length <= max) return ordered.map(lineOf);
298
+ const kept = ordered.slice(0, max - 1).map(lineOf);
299
+ return [...kept, paint("dim", `… ${ordered.length - kept.length} more`, caps)];
300
+ }
301
+
302
+ /** The frames that erase the live region, write the final lines above it, and draw it again (attended), with the next state. */
303
+ function redraw(state: State, permanent: readonly string[], now: bigint, region = true): Step {
304
+ const cols = Math.max(1, state.config.look.columns);
305
+ const erase = state.drawn > 0 ? `\r${ESC}[${state.drawn}A${ESC}[J` : "";
306
+ const lines = region ? regionLines(state, now) : [];
307
+ const out = [...permanent, ...lines].map((l) => `${cutToWidth(l, cols)}\n`).join("");
308
+ return { state: { ...state, drawn: lines.length }, frames: erase + out };
309
+ }
310
+
311
+ /** The frames of final lines in the state's mode (not `json`). */
312
+ function emit(state: State, lines: readonly Line[], now: bigint): Step {
313
+ const mode = state.config.mode;
314
+ switch (mode) {
315
+ case "attended":
316
+ return lines.length === 0
317
+ ? { state, frames: "" }
318
+ : redraw(
319
+ state,
320
+ lines.map((l) => l.text),
321
+ now,
322
+ );
323
+ case "plain":
324
+ return { state, frames: lines.map((l) => `${l.text}\n`).join("") };
325
+ case "quiet":
326
+ return { state, frames: lines.flatMap((l) => (l.quiet ? [`${l.text}\n`] : [])).join("") };
327
+ case "silent":
328
+ case "json":
329
+ return { state, frames: "" };
330
+ default:
331
+ return absurd(mode);
332
+ }
333
+ }
334
+
335
+ function jsonLine(source: Source | undefined, record: LogRecord): string {
336
+ const s = source ?? { resource: { attributes: {} }, scope: { name: "ifc.console" } };
337
+ return `${JSON.stringify(encodeLogs([{ resource: s.resource, scope: s.scope, records: [record] }]))}\n`;
338
+ }
339
+
340
+ const isLoud = (role: Role, severity: SeverityNumber): boolean =>
341
+ role === "result" || role === "warning" || role === "error" || role === "action" || severity >= SEVERITY.WARN;
342
+
343
+ /** The line `plain` writes for a span still open at the end of the run: cancelled. */
344
+ function leftoverLines(state: State, now: bigint): readonly Line[] {
345
+ return state.live
346
+ .flatMap((l) => endedLines(state.config, l.depth, l.text, "cancelled", undefined, now - l.start))
347
+ .map((text) => ({ text, quiet: false }));
348
+ }
349
+
350
+ function warningLines(state: State): readonly Line[] {
351
+ const caps = capsOf(state.config);
352
+ return state.warnings.map((w) => ({
353
+ text: paint("dim", `${mark("warning", caps)} ${clean(w).split("\n").join(" ")}`, caps),
354
+ quiet: true,
355
+ }));
356
+ }
357
+
358
+ /**
359
+ * The next state and the frames to write for an input at the time `now` (nanoseconds since the Unix epoch). Pure: the same state, input
360
+ * and time give the same step. After `finish`, every input gives no frame.
361
+ */
362
+ export function render(state: State, input: Input, now: bigint): Step {
363
+ if (state.finished) return { state, frames: "" };
364
+ const { config } = state;
365
+ switch (input.kind) {
366
+ case "span-start": {
367
+ const s = input.span;
368
+ const key = keyOf(s.context.traceId, s.context.spanId);
369
+ const pk = s.parentSpanId === undefined ? undefined : keyOf(s.context.traceId, s.parentSpanId);
370
+ const parent = pk === undefined ? undefined : state.spans.get(pk);
371
+ const shown = shownRole(roleOf(config.registry, s.name));
372
+ const depth = parent === undefined ? 0 : parent.shown ? parent.depth + 1 : parent.depth;
373
+ const anchor = parent === undefined ? undefined : parent.shown ? pk : parent.anchor;
374
+ const spans = new Map(state.spans).set(key, { depth, shown, anchor });
375
+ const live = shown
376
+ ? [...state.live, { key, anchor, depth, text: textOf(config, s.name, s.attributes), start: s.startTime, progress: undefined }]
377
+ : state.live;
378
+ const next: State = { ...state, spans, live, source: input.source };
379
+ return shown && config.mode === "attended" ? redraw(next, [], now) : { state: next, frames: "" };
380
+ }
381
+ case "span-event": {
382
+ if (input.event.name !== "progress") return { state, frames: "" };
383
+ const key = keyOf(input.span.context.traceId, input.span.context.spanId);
384
+ const done = numberOf(input.event.attributes["progress.done"]);
385
+ if (done === undefined || !state.live.some((l) => l.key === key)) return { state, frames: "" };
386
+ const progress: Progress = { done, total: numberOf(input.event.attributes["progress.total"]) };
387
+ const next: State = { ...state, live: state.live.map((l) => (l.key === key ? { ...l, progress } : l)) };
388
+ return config.mode === "attended" ? redraw(next, [], now) : { state: next, frames: "" };
389
+ }
390
+ case "span-end": {
391
+ const s = input.span;
392
+ const key = keyOf(s.context.traceId, s.context.spanId);
393
+ const known = state.spans.get(key);
394
+ const spans = new Map(state.spans);
395
+ spans.delete(key);
396
+ const next: State = { ...state, spans, live: state.live.filter((l) => l.key !== key), source: input.source };
397
+ const role = roleOf(config.registry, s.name);
398
+ if (!shownRole(role)) return { state: next, frames: "" };
399
+ const kind = outcomeOf(s);
400
+ const message = s.status.kind === "error" ? s.status.message : undefined;
401
+ const text = textOf(config, s.name, s.attributes);
402
+ const took = s.endTime - s.startTime;
403
+ if (config.mode === "json") {
404
+ const body = endedLines({ ...config, look: { ...config.look, colour: false, emoji: false } }, 0, text, kind, message, took).join(
405
+ "\n",
406
+ );
407
+ const severity = kind === "failed" ? SEVERITY.ERROR : SEVERITY.INFO;
408
+ const record: LogRecord = {
409
+ time: s.endTime,
410
+ observedTime: s.endTime,
411
+ severityNumber: severity,
412
+ severityText: severityText(severity),
413
+ body,
414
+ attributes: s.attributes,
415
+ droppedAttributesCount: 0,
416
+ eventName: s.name,
417
+ traceId: s.context.traceId,
418
+ spanId: s.context.spanId,
419
+ traceFlags: s.context.traceFlags,
420
+ };
421
+ return { state: next, frames: jsonLine(input.source, record) };
422
+ }
423
+ const quiet = kind === "failed" || role === "result" || role === "warning" || role === "error";
424
+ const lines = endedLines(config, known?.depth ?? 0, text, kind, message, took).map((t) => ({ text: t, quiet }));
425
+ return emit(next, lines, now);
426
+ }
427
+ case "log": {
428
+ const r = input.record;
429
+ const next: State = { ...state, source: input.source };
430
+ const role = r.eventName === undefined ? undefined : roleOf(config.registry, r.eventName);
431
+ if (!shownRole(role)) return { state: next, frames: "" };
432
+ if (config.mode === "json") return { state: next, frames: jsonLine(input.source, r) };
433
+ const known = r.traceId === undefined || r.spanId === undefined ? undefined : state.spans.get(keyOf(r.traceId, r.spanId));
434
+ const depth = known === undefined ? 0 : known.shown ? known.depth + 1 : known.depth;
435
+ const text = bodyText(r.body) ?? textOf(config, r.eventName ?? r.severityText, r.attributes, "log");
436
+ const quiet = isLoud(role, r.severityNumber);
437
+ return emit(
438
+ next,
439
+ logLines(config, depth, role, r.severityNumber, text).map((t) => ({ text: t, quiet })),
440
+ now,
441
+ );
442
+ }
443
+ case "export-warning":
444
+ return {
445
+ state: state.warnings.includes(input.message) ? state : { ...state, warnings: [...state.warnings, input.message] },
446
+ frames: "",
447
+ };
448
+ case "tick":
449
+ return config.mode === "attended" && state.live.length > 0 ? redraw(state, [], now) : { state, frames: "" };
450
+ case "finish": {
451
+ const done: State = { ...state, live: [], spans: new Map(), finished: true };
452
+ switch (config.mode) {
453
+ case "attended":
454
+ return redraw(
455
+ done,
456
+ [...leftoverLines(state, now), ...warningLines(state)].map((l) => l.text),
457
+ now,
458
+ false,
459
+ );
460
+ case "plain":
461
+ case "quiet":
462
+ return emit(done, [...leftoverLines(state, now), ...warningLines(state)], now);
463
+ case "silent":
464
+ return { state: done, frames: "" };
465
+ case "json": {
466
+ const frames = state.warnings
467
+ .map((w) =>
468
+ jsonLine(state.source, {
469
+ time: now,
470
+ observedTime: now,
471
+ severityNumber: SEVERITY.WARN,
472
+ severityText: severityText(SEVERITY.WARN),
473
+ body: w,
474
+ attributes: {},
475
+ droppedAttributesCount: 0,
476
+ eventName: "ifc.console.export",
477
+ }),
478
+ )
479
+ .join("");
480
+ return { state: done, frames };
481
+ }
482
+ default:
483
+ return absurd(config.mode);
484
+ }
485
+ }
486
+ default:
487
+ return absurd(input);
488
+ }
489
+ }