@overdoser/react-toolkit 0.12.0 → 0.14.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.
@@ -0,0 +1,128 @@
1
+ /**
2
+ * The trace event model shared by TraceTimeline and TraceEventDetails, plus
3
+ * the pure helpers that decide how much of an event is renderable. Kept apart
4
+ * from both components so neither has to import the other.
5
+ */
6
+ /**
7
+ * Severity/outcome of a non-request event. Colors the detail-panel and
8
+ * full-log badge the way `status` does for requests.
9
+ */
10
+ export type TraceTimelineLevel = 'debug' | 'info' | 'success' | 'warning' | 'error';
11
+ /**
12
+ * One labeled value in the detail panel — the label is rendered above the
13
+ * value, and values stack vertically (never side by side).
14
+ */
15
+ export interface TraceTimelineField {
16
+ /** Uppercase micro-label rendered above the value. */
17
+ label: string;
18
+ /**
19
+ * The value. Strings/numbers/booleans render inline (keyword-highlighted),
20
+ * React elements render as-is, anything else is pretty-printed as JSON in a
21
+ * copyable block.
22
+ */
23
+ value: unknown;
24
+ /** Monospace the value. @default true */
25
+ mono?: boolean;
26
+ /** Add a copy button beside the label (always on for JSON blocks). */
27
+ copy?: boolean;
28
+ }
29
+ /**
30
+ * One event on the trace. Only `id`, `service` and `start` are required —
31
+ * everything else enriches the chip, tooltip and detail panel *when present*,
32
+ * so a plain lifecycle/audit event (no method, no status, no bodies) renders
33
+ * as cleanly as a full HTTP call: sections with nothing behind them are
34
+ * skipped rather than shown empty. Extra fields are allowed, participate in
35
+ * keyword matching and are listed under *Other fields* in the detail panel.
36
+ */
37
+ export interface TraceTimelineEvent {
38
+ /** Stable identifier. */
39
+ id: string;
40
+ /** Target component/service the event belongs to (colors the bar). */
41
+ service: string;
42
+ /**
43
+ * Caller shown as the chip's origin badge. Defaults to `'client'` for
44
+ * request-like events and to nothing for plain events (the chip then shows
45
+ * the service alone).
46
+ */
47
+ source?: string;
48
+ /** Friendly operation id, bold in the chip (e.g. `create_manifest`). */
49
+ op?: string;
50
+ /**
51
+ * How the event is rendered. Inferred when omitted: `'request'` as soon as
52
+ * any of `method`/`url`/`status`/`query`/`reqHeaders`/`reqBody`/
53
+ * `resHeaders`/`resBody` is set, `'event'` otherwise. Request events get
54
+ * the Request/Response sections and the in-flight "Awaiting response…"
55
+ * state; plain events get Message/Payload/Details instead.
56
+ */
57
+ kind?: 'request' | 'event';
58
+ /** Severity badge for plain events (requests use `status` instead). */
59
+ level?: TraceTimelineLevel;
60
+ /** One-line human description (detail panel + full log). */
61
+ message?: string;
62
+ /**
63
+ * Generic body for events that aren't requests — pretty-printed as JSON
64
+ * (strings render verbatim) under a *Payload* heading with a copy button.
65
+ * Requests should use `reqBody`/`resBody`; an event may use `payload`
66
+ * alone and nothing else.
67
+ */
68
+ payload?: unknown;
69
+ /**
70
+ * Extra labeled values for the detail panel and full log, in order. Each
71
+ * renders label-above-value; object values become copyable JSON blocks.
72
+ */
73
+ details?: TraceTimelineField[];
74
+ /** Technical request id (fallback chip label; shown in the detail panel). */
75
+ requestId?: string;
76
+ /** HTTP method for the detail panel badge. */
77
+ method?: string;
78
+ /** Full URL (detail panel + tooltip). */
79
+ url?: string;
80
+ /** Short label for the tooltip. Defaults to `method + path`. */
81
+ label?: string;
82
+ /** Query parameters (detail panel). */
83
+ query?: Record<string, string>;
84
+ /** Request headers (detail panel; `x-request-id` is surfaced). */
85
+ reqHeaders?: Record<string, string>;
86
+ /** Request body, pretty-printed as JSON in the detail panel. */
87
+ reqBody?: unknown;
88
+ /** Response status; `>= 400` renders as an error badge. */
89
+ status?: number;
90
+ /** Response headers (detail panel). */
91
+ resHeaders?: Record<string, string>;
92
+ /** Response body, pretty-printed as JSON in the detail panel. */
93
+ resBody?: unknown;
94
+ /** Start time, epoch ms (UTC display). */
95
+ start: number;
96
+ /** End time, epoch ms. `null`/`undefined` while in flight (bar grows live). */
97
+ end?: number | null;
98
+ [extra: string]: unknown;
99
+ }
100
+ /** Fields the panel renders itself — everything else lands in *Other fields*. */
101
+ export declare const KNOWN_KEYS: Set<string>;
102
+ /** Whether the event should render the Request/Response sections. */
103
+ export declare const isRequestEvent: (e: TraceTimelineEvent) => boolean;
104
+ /** Chip/log headline: operation id, falling back to request ids, then `id`. */
105
+ export declare const ridOf: (e: TraceTimelineEvent) => string;
106
+ /**
107
+ * Origin badge. Requests keep the implicit `client` caller; plain events show
108
+ * no origin at all unless one was given.
109
+ */
110
+ export declare const srcOf: (e: TraceTimelineEvent) => string;
111
+ /** `origin → target`, or the target alone when there is no origin. */
112
+ export declare const routeOf: (e: TraceTimelineEvent) => string;
113
+ /** Values rendered inline rather than as a JSON block. */
114
+ export declare const isInline: (v: unknown) => v is string | number | boolean;
115
+ /** Pretty-print for payload blocks; strings are shown verbatim. */
116
+ export declare const toText: (v: unknown) => string;
117
+ export type TraceBadgeTone = 'ok' | 'pending' | 'warn' | 'error';
118
+ /** Badge shown beside the method: status for requests, level for events. */
119
+ export declare function badgeOf(e: TraceTimelineEvent, pending: boolean): {
120
+ text: string;
121
+ tone: TraceBadgeTone;
122
+ } | null;
123
+ /**
124
+ * Extra (unknown) event keys as labeled fields, in insertion order. Keys in
125
+ * `hidden` are skipped — for plumbing values that ride along on the event but
126
+ * shouldn't be displayed.
127
+ */
128
+ export declare function extraFieldsOf(e: TraceTimelineEvent, hidden?: readonly string[]): TraceTimelineField[];
@@ -0,0 +1,64 @@
1
+ const s = /* @__PURE__ */ new Set([
2
+ "id",
3
+ "service",
4
+ "source",
5
+ "op",
6
+ "kind",
7
+ "level",
8
+ "message",
9
+ "payload",
10
+ "details",
11
+ "requestId",
12
+ "method",
13
+ "url",
14
+ "label",
15
+ "query",
16
+ "reqHeaders",
17
+ "reqBody",
18
+ "status",
19
+ "resHeaders",
20
+ "resBody",
21
+ "start",
22
+ "end"
23
+ ]), o = [
24
+ "method",
25
+ "url",
26
+ "status",
27
+ "query",
28
+ "reqHeaders",
29
+ "reqBody",
30
+ "resHeaders",
31
+ "resBody"
32
+ ], n = (e) => e.kind ? e.kind === "request" : o.some((r) => e[r] != null), u = (e) => e.op || e.requestId || e.reqHeaders && e.reqHeaders["x-request-id"] || e.id, i = (e) => e.source || (n(e) ? "client" : ""), l = (e) => {
33
+ const r = i(e);
34
+ return r ? r + " → " + e.service : e.service;
35
+ }, d = (e) => typeof e == "string" || typeof e == "number" || typeof e == "boolean", a = (e) => {
36
+ if (typeof e == "string") return e;
37
+ try {
38
+ return JSON.stringify(e, null, 2) ?? String(e);
39
+ } catch {
40
+ return String(e);
41
+ }
42
+ };
43
+ function c(e, r) {
44
+ return r ? { text: n(e) ? "pending" : "ongoing", tone: "pending" } : typeof e.status == "number" ? { text: String(e.status), tone: e.status >= 400 ? "error" : "ok" } : e.level ? {
45
+ text: e.level,
46
+ tone: e.level === "error" ? "error" : e.level === "warning" ? "warn" : e.level === "success" ? "ok" : "pending"
47
+ } : null;
48
+ }
49
+ function f(e, r) {
50
+ return Object.keys(e).filter(
51
+ (t) => !s.has(t) && !r?.includes(t) && e[t] !== void 0 && typeof e[t] != "function"
52
+ ).map((t) => ({ label: t, value: e[t] }));
53
+ }
54
+ export {
55
+ s as KNOWN_KEYS,
56
+ c as badgeOf,
57
+ f as extraFieldsOf,
58
+ d as isInline,
59
+ n as isRequestEvent,
60
+ u as ridOf,
61
+ l as routeOf,
62
+ i as srcOf,
63
+ a as toText
64
+ };