@runic-artifex/vite-plugin-runic 0.19.0 → 0.20.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/README.md +532 -12
- package/dist/access.d.ts +46 -0
- package/dist/access.js +123 -0
- package/dist/calls.d.ts +83 -0
- package/dist/calls.js +140 -0
- package/dist/channel.d.ts +58 -1
- package/dist/channel.js +20 -1
- package/dist/client.js +210 -1
- package/dist/dev-session.d.ts +19 -2
- package/dist/dev-session.js +67 -46
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.js +2 -1
- package/dist/handlers.d.ts +140 -0
- package/dist/handlers.js +773 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +226 -11
- package/dist/inspect-data.d.ts +268 -0
- package/dist/inspect-data.js +442 -0
- package/dist/inspect-edit.d.ts +164 -0
- package/dist/inspect-edit.js +273 -0
- package/dist/inspect-editor.d.ts +34 -0
- package/dist/inspect-editor.js +282 -0
- package/dist/inspect-frameworks.d.ts +72 -0
- package/dist/inspect-frameworks.js +333 -0
- package/dist/inspect-handlers.d.ts +84 -0
- package/dist/inspect-handlers.js +331 -0
- package/dist/inspect.d.ts +42 -0
- package/dist/inspect.js +783 -0
- package/dist/otlp.d.ts +80 -0
- package/dist/otlp.js +254 -0
- package/dist/requests.d.ts +17 -0
- package/dist/requests.js +67 -0
- package/dist/sources.d.ts +135 -0
- package/dist/sources.js +343 -0
- package/dist/timeline.d.ts +12 -0
- package/dist/timeline.js +14 -0
- package/dist/translations-source.d.ts +36 -0
- package/dist/translations-source.js +109 -0
- package/package.json +12 -6
package/dist/access.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Who may read Runic Inspect's development data from another machine (D066.27 #14): the development server answers
|
|
2
|
+
// pages of this machine (loopback) and, when configured, other hosts and networks, such as a Tailscale network or the
|
|
3
|
+
// laptop whose browser shows a page of an agent's dev server. `runic({ allow })` and `RUNIC_DEV_ALLOW` name them; Runic
|
|
4
|
+
// Translations' in-page editing API reads the same variable (vite-plugin-runic-translations, "Who may edit"), so one
|
|
5
|
+
// setting admits a client to both. Entries are parsed exactly as that plugin parses them.
|
|
6
|
+
//
|
|
7
|
+
// The client address is the TCP connection's, never a forwarded header. The open action (`/__runic/open`) does not use
|
|
8
|
+
// the list: it launches an editor on this machine, so it stays loopback-only.
|
|
9
|
+
import { lookup as dnsLookup } from "node:dns/promises";
|
|
10
|
+
import { BlockList, isIP } from "node:net";
|
|
11
|
+
/** Hosts and networks, besides loopback, that may read the development data: comma- or space-separated. */
|
|
12
|
+
export const allowVariable = "RUNIC_DEV_ALLOW";
|
|
13
|
+
/** How long a resolved host name of the allow list is trusted. */
|
|
14
|
+
const hostTtl = 30_000;
|
|
15
|
+
const hostName = /^(?=.{1,253}$)(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*\.?$/u;
|
|
16
|
+
/** Validates allow-list entries; throws a TypeError naming the entry and `source` for an invalid one. */
|
|
17
|
+
export function parseAllowList(entries, source) {
|
|
18
|
+
if (!Array.isArray(entries))
|
|
19
|
+
throw new TypeError(`${source} must be an array of addresses, networks and host names.`);
|
|
20
|
+
return entries.map((entry) => {
|
|
21
|
+
if (typeof entry !== "string" || entry.trim().length === 0)
|
|
22
|
+
throw new TypeError(`${source}: every entry must be a non-empty string.`);
|
|
23
|
+
const text = entry.trim();
|
|
24
|
+
const slash = text.indexOf("/");
|
|
25
|
+
if (slash >= 0) {
|
|
26
|
+
const address = unbracket(text.slice(0, slash)), prefixText = text.slice(slash + 1);
|
|
27
|
+
const version = isIP(address);
|
|
28
|
+
const prefix = /^\d{1,3}$/u.test(prefixText) ? Number(prefixText) : NaN;
|
|
29
|
+
if (version === 0 || !Number.isInteger(prefix) || prefix > (version === 4 ? 32 : 128))
|
|
30
|
+
throw new TypeError(`${source}: '${text}' is not a network; use an IPv4 or IPv6 CIDR such as 100.64.0.0/10 or fd7a:115c:a1e0::/48.`);
|
|
31
|
+
return { kind: "network", text, address, prefix, family: version === 4 ? "ipv4" : "ipv6" };
|
|
32
|
+
}
|
|
33
|
+
const address = unbracket(text);
|
|
34
|
+
const version = isIP(address);
|
|
35
|
+
if (version !== 0)
|
|
36
|
+
return { kind: "address", text, address, family: version === 4 ? "ipv4" : "ipv6" };
|
|
37
|
+
if (!hostName.test(text) || /^[\d.]+$/u.test(text))
|
|
38
|
+
throw new TypeError(`${source}: '${text}' is not an IP address, a CIDR network or a host name.`);
|
|
39
|
+
return { kind: "host", text, name: text.toLowerCase().replace(/\.$/u, "") };
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** The entries of the environment variable: separated by commas or whitespace. */
|
|
43
|
+
export function allowListFromEnvironment(value) {
|
|
44
|
+
return (value ?? "").split(/[\s,]+/u).filter((entry) => entry.length > 0);
|
|
45
|
+
}
|
|
46
|
+
function unbracket(value) {
|
|
47
|
+
return value.startsWith("[") && value.endsWith("]") ? value.slice(1, -1) : value;
|
|
48
|
+
}
|
|
49
|
+
/** An IPv4-mapped IPv6 address (`::ffff:192.0.2.1`) as its IPv4 address; any other address unchanged, without a zone. */
|
|
50
|
+
export function normalizeAddress(address) {
|
|
51
|
+
const unzoned = address.replace(/%.*$/u, "");
|
|
52
|
+
const mapped = /^::ffff:(\d{1,3}(?:\.\d{1,3}){3})$/iu.exec(unzoned);
|
|
53
|
+
return mapped ? mapped[1] : unzoned;
|
|
54
|
+
}
|
|
55
|
+
/** Whether a client address is loopback: 127.0.0.0/8 or ::1 (also IPv4-mapped). */
|
|
56
|
+
export function isLoopbackAddress(address) {
|
|
57
|
+
if (typeof address !== "string")
|
|
58
|
+
return false;
|
|
59
|
+
const normalized = normalizeAddress(address);
|
|
60
|
+
if (isIP(normalized) === 4)
|
|
61
|
+
return normalized.startsWith("127.");
|
|
62
|
+
return isIP(normalized) === 6 && loopback6.check(normalized, "ipv6");
|
|
63
|
+
}
|
|
64
|
+
const loopback6 = new BlockList();
|
|
65
|
+
loopback6.addAddress("::1", "ipv6");
|
|
66
|
+
/** Decides whether a client address may read the development data: loopback, or one of the rules. */
|
|
67
|
+
export class AccessList {
|
|
68
|
+
rules;
|
|
69
|
+
#addresses = new BlockList();
|
|
70
|
+
#hosts;
|
|
71
|
+
#resolved = new Map();
|
|
72
|
+
#lookup;
|
|
73
|
+
constructor(rules = [], lookup) {
|
|
74
|
+
this.rules = rules;
|
|
75
|
+
for (const rule of rules) {
|
|
76
|
+
if (rule.kind === "address")
|
|
77
|
+
this.#addresses.addAddress(rule.address, rule.family);
|
|
78
|
+
else if (rule.kind === "network")
|
|
79
|
+
this.#addresses.addSubnet(rule.address, rule.prefix, rule.family);
|
|
80
|
+
}
|
|
81
|
+
this.#hosts = rules.flatMap((rule) => rule.kind === "host" ? [rule.name] : []);
|
|
82
|
+
this.#lookup = lookup ?? (async (name) => (await dnsLookup(name, { all: true, verbatim: true })).map((item) => item.address));
|
|
83
|
+
}
|
|
84
|
+
/** Whether the list admits more than loopback. */
|
|
85
|
+
get remote() {
|
|
86
|
+
return this.rules.length > 0;
|
|
87
|
+
}
|
|
88
|
+
async allows(address) {
|
|
89
|
+
if (!address)
|
|
90
|
+
return false;
|
|
91
|
+
const normalized = normalizeAddress(address);
|
|
92
|
+
const version = isIP(normalized);
|
|
93
|
+
if (version === 0)
|
|
94
|
+
return false;
|
|
95
|
+
if (isLoopbackAddress(normalized))
|
|
96
|
+
return true;
|
|
97
|
+
if (this.#addresses.check(normalized, version === 4 ? "ipv4" : "ipv6"))
|
|
98
|
+
return true;
|
|
99
|
+
for (const name of this.#hosts) {
|
|
100
|
+
let entry = this.#resolved.get(name);
|
|
101
|
+
if (!entry || Date.now() - entry.at > hostTtl) {
|
|
102
|
+
entry = { at: Date.now(), addresses: this.#lookup(name).catch(() => []) };
|
|
103
|
+
this.#resolved.set(name, entry);
|
|
104
|
+
}
|
|
105
|
+
if ((await entry.addresses).some((candidate) => normalizeAddress(candidate) === normalized))
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
/** Whether the request's client (its connection's address) is admitted. */
|
|
111
|
+
allowsRequest(request) {
|
|
112
|
+
return this.allows(request.socket?.remoteAddress);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** Loopback only: what the endpoints accept without configuration. */
|
|
116
|
+
export const loopbackOnly = new AccessList();
|
|
117
|
+
/**
|
|
118
|
+
* The access list of a development server: the option's entries (validated when the plugin is created), then
|
|
119
|
+
* `RUNIC_DEV_ALLOW`'s, each validated under its own name.
|
|
120
|
+
*/
|
|
121
|
+
export function resolveAccessList(option, environment = process.env) {
|
|
122
|
+
return new AccessList([...option, ...parseAllowList(allowListFromEnvironment(environment[allowVariable]), allowVariable)]);
|
|
123
|
+
}
|
package/dist/calls.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { RunicDiagnosticFailure } from "./diagnostics.js";
|
|
2
|
+
import type { RunicSourceMap, RunicSourceMember } from "./sources.js";
|
|
3
|
+
/** How a call ended, as `@runic-artifex/views` reports it (`BridgeCallOutcome`). */
|
|
4
|
+
export type RunicBridgeCallOutcome = "ok" | "error" | "cancelled";
|
|
5
|
+
/** A call's C# handler, from the development source map. */
|
|
6
|
+
export interface RunicBridgeCallHandler {
|
|
7
|
+
/** The C# member that ran, such as `Demo.EditorViewModel.SaveAsync()`. */
|
|
8
|
+
readonly symbol: string;
|
|
9
|
+
/** The symbol below its ViewModel: `SaveAsync()`, `Title.set`. */
|
|
10
|
+
readonly method: string;
|
|
11
|
+
/** The map member's id, `{viewModel}/{kind}/{member}`, which `/__runic/open` opens. */
|
|
12
|
+
readonly source: string;
|
|
13
|
+
/** The source file's name and line, when the build had a PDB: `EditorViewModel.cs`, 42. */
|
|
14
|
+
readonly fileName?: string;
|
|
15
|
+
readonly line?: number;
|
|
16
|
+
}
|
|
17
|
+
/** One settled Bridge call in the dock's timeline. */
|
|
18
|
+
export interface RunicBridgeCall {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly timestamp: string;
|
|
21
|
+
/** What the call did: `command`, `set`, `write`, `can`, `region`, `operation`, `query`, or a later kind. */
|
|
22
|
+
readonly kind: string;
|
|
23
|
+
readonly route: string;
|
|
24
|
+
/** The C# ViewModel's type name, from the View contract: `EditorViewModel`. */
|
|
25
|
+
readonly viewModel: string;
|
|
26
|
+
/** The member's wire name: `save`. */
|
|
27
|
+
readonly member: string;
|
|
28
|
+
/** From the call to its settled reply, in milliseconds, as the page measured it. */
|
|
29
|
+
readonly duration: number;
|
|
30
|
+
readonly outcome: RunicBridgeCallOutcome;
|
|
31
|
+
/** What refines the outcome, such as `superseded` or `domain-failed`. */
|
|
32
|
+
readonly reason?: string;
|
|
33
|
+
/** The reply's revision: the frames with this revision carry the call's effects. */
|
|
34
|
+
readonly revision?: number;
|
|
35
|
+
readonly handler?: RunicBridgeCallHandler;
|
|
36
|
+
/**
|
|
37
|
+
* The C# handler's own duration in milliseconds, as .NET measured it, when the reply carried it (a .NET host in
|
|
38
|
+
* Development with handler timing). Absent otherwise.
|
|
39
|
+
*/
|
|
40
|
+
readonly handlerDuration?: number;
|
|
41
|
+
/** .NET's name for the handler from that reply, such as `EditorViewModel.Save`, when the map has none. */
|
|
42
|
+
readonly handlerName?: string;
|
|
43
|
+
/** The .NET exception of a failed call, for local display only; never in `/__runic/state`. */
|
|
44
|
+
readonly failure?: RunicDiagnosticFailure;
|
|
45
|
+
/** `command EditorViewModel.save → SaveAsync() 23 ms`. */
|
|
46
|
+
readonly label: string;
|
|
47
|
+
}
|
|
48
|
+
/** What the development client sends for a call, before the server names its handler. */
|
|
49
|
+
export interface RunicBridgeCallReport {
|
|
50
|
+
readonly page?: string;
|
|
51
|
+
readonly kind: string;
|
|
52
|
+
readonly route: string;
|
|
53
|
+
readonly contract: string;
|
|
54
|
+
readonly member: string;
|
|
55
|
+
readonly duration: number;
|
|
56
|
+
readonly outcome: RunicBridgeCallOutcome;
|
|
57
|
+
readonly reason?: string;
|
|
58
|
+
readonly revision?: number;
|
|
59
|
+
readonly handlerDuration?: number;
|
|
60
|
+
readonly handlerName?: string;
|
|
61
|
+
readonly failure?: RunicDiagnosticFailure;
|
|
62
|
+
}
|
|
63
|
+
/** The report in a client message, or undefined when it is not one. */
|
|
64
|
+
export declare function sanitizeCallReport(candidate: unknown): RunicBridgeCallReport | undefined;
|
|
65
|
+
/** The map member a call ran, when the map has the call's ViewModel. */
|
|
66
|
+
export declare function findCallMember(map: RunicSourceMap | undefined, report: Pick<RunicBridgeCallReport, "contract" | "route" | "member" | "kind">): RunicSourceMember | undefined;
|
|
67
|
+
/** The handler of a map member, as the timeline shows it. */
|
|
68
|
+
export declare function callHandler(member: RunicSourceMember): RunicBridgeCallHandler;
|
|
69
|
+
/** `command EditorViewModel.save → SaveAsync() 23 ms`, with the outcome when it is not `ok`. */
|
|
70
|
+
export declare function callLabel(call: Omit<RunicBridgeCall, "id" | "timestamp" | "label">): string;
|
|
71
|
+
export declare function formatMilliseconds(value: number): string;
|
|
72
|
+
/** A call's entry: its report with the handler the map names. */
|
|
73
|
+
export declare function callEntry(report: RunicBridgeCallReport, map: RunicSourceMap | undefined, id: string, timestamp: string): RunicBridgeCall;
|
|
74
|
+
/** A frame of a .NET stack trace with a source location: ` at Demo.EditorViewModel.SaveAsync() in /src/EditorViewModel.cs:line 42`. */
|
|
75
|
+
export interface RunicStackFrame {
|
|
76
|
+
/** The frame's text, trimmed. */
|
|
77
|
+
readonly text: string;
|
|
78
|
+
readonly method: string;
|
|
79
|
+
readonly file: string;
|
|
80
|
+
readonly line: number;
|
|
81
|
+
}
|
|
82
|
+
/** The frames of a .NET stack that name a source file and line, in order, at most `limit`. */
|
|
83
|
+
export declare function stackFrames(stack: string | undefined, limit?: number): RunicStackFrame[];
|
package/dist/calls.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// The dock's Bridge call timeline (#954). The development client sends each settled call of the Bridge-call channel
|
|
2
|
+
// of `@runic-artifex/views` (route, member, kind, timing, outcome, revision) to the development server, which keeps a
|
|
3
|
+
// bounded history of them next to the timeline. The server names each call's C# handler from the development source
|
|
4
|
+
// map (`sources.json`), such as `command EditorViewModel.save → SaveAsync() 23 ms`, and the dock opens it in the editor
|
|
5
|
+
// with the same decision as `/__runic/open` (sources.ts, `resolveOpenLocation`). A failed call keeps its .NET exception, whose frames in files of the map open the same way.
|
|
6
|
+
//
|
|
7
|
+
// What the page sends is sanitized like a timeline entry: closed shapes, short names, finite numbers, and the failure
|
|
8
|
+
// under the failure rules (bounded, credentials redacted). The handler comes from the server's own map; an entry names
|
|
9
|
+
// it by the map's member id, never by a path. The failure stays out of `/__runic/state` and the copied state.
|
|
10
|
+
import { sanitizeFailure } from "./diagnostics.js";
|
|
11
|
+
const namePattern = /^[A-Za-z][A-Za-z0-9_-]{0,31}$/u;
|
|
12
|
+
const routePattern = /^[A-Za-z0-9_.-]{1,128}$/u;
|
|
13
|
+
const memberPattern = /^[A-Za-z_$][A-Za-z0-9_$.-]{0,127}$/u;
|
|
14
|
+
// `{CLR type}:{fingerprint}`; a nested type has `+`, a generic one a backtick.
|
|
15
|
+
const contractPattern = /^[A-Za-z_][A-Za-z0-9_.+`]{0,255}(?::[A-Za-z0-9_-]{0,128})?$/u;
|
|
16
|
+
const reasonPattern = /^[A-Za-z][A-Za-z0-9_-]{0,47}$/u;
|
|
17
|
+
const handlerNamePattern = /^[A-Za-z_][A-Za-z0-9_.+`<>,]{0,159}(?:\([A-Za-z0-9_.+`<>, []*\))?$/u;
|
|
18
|
+
const pagePattern = /^[a-z0-9]{1,32}$/u;
|
|
19
|
+
const outcomes = new Set(["ok", "error", "cancelled"]);
|
|
20
|
+
// An hour: anything longer is not a measurement of one call.
|
|
21
|
+
const maximumDuration = 3_600_000;
|
|
22
|
+
/** The report in a client message, or undefined when it is not one. */
|
|
23
|
+
export function sanitizeCallReport(candidate) {
|
|
24
|
+
if (typeof candidate !== "object" || candidate === null || Array.isArray(candidate))
|
|
25
|
+
return undefined;
|
|
26
|
+
const value = candidate;
|
|
27
|
+
const text = (name, pattern) => typeof value[name] === "string" && pattern.test(value[name]) ? value[name] : undefined;
|
|
28
|
+
const kind = text("kind", namePattern);
|
|
29
|
+
const route = text("route", routePattern);
|
|
30
|
+
const contract = text("contract", contractPattern);
|
|
31
|
+
const member = text("member", memberPattern);
|
|
32
|
+
const duration = milliseconds(value.duration);
|
|
33
|
+
const outcome = typeof value.outcome === "string" && outcomes.has(value.outcome) ? value.outcome : undefined;
|
|
34
|
+
if (!kind || !route || !contract || !member || duration === undefined || !outcome)
|
|
35
|
+
return undefined;
|
|
36
|
+
const page = text("page", pagePattern);
|
|
37
|
+
const reason = text("reason", reasonPattern);
|
|
38
|
+
const revision = typeof value.revision === "number" && Number.isSafeInteger(value.revision) && value.revision >= 0
|
|
39
|
+
? value.revision : undefined;
|
|
40
|
+
const handlerDuration = milliseconds(value.handlerDuration);
|
|
41
|
+
const handlerName = text("handlerName", handlerNamePattern);
|
|
42
|
+
const failure = outcome === "error" ? sanitizeFailure(value.failure) : undefined;
|
|
43
|
+
return {
|
|
44
|
+
kind, route, contract, member, duration, outcome,
|
|
45
|
+
...(page === undefined ? {} : { page }),
|
|
46
|
+
...(reason === undefined ? {} : { reason }),
|
|
47
|
+
...(revision === undefined ? {} : { revision }),
|
|
48
|
+
...(handlerDuration === undefined ? {} : { handlerDuration }),
|
|
49
|
+
...(handlerName === undefined ? {} : { handlerName }),
|
|
50
|
+
...(failure === undefined ? {} : { failure }),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function milliseconds(value) {
|
|
54
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= maximumDuration
|
|
55
|
+
? Math.round(value * 10) / 10
|
|
56
|
+
: undefined;
|
|
57
|
+
}
|
|
58
|
+
// The source map member kinds a call kind runs: a command its handler, a set or write the property's setter.
|
|
59
|
+
const memberKindsByCall = {
|
|
60
|
+
command: ["command"],
|
|
61
|
+
can: ["command", "commandState"],
|
|
62
|
+
operation: ["command"],
|
|
63
|
+
set: ["setter", "state"],
|
|
64
|
+
write: ["setter", "state"],
|
|
65
|
+
};
|
|
66
|
+
/** The map member a call ran, when the map has the call's ViewModel. */
|
|
67
|
+
export function findCallMember(map, report) {
|
|
68
|
+
if (map === undefined)
|
|
69
|
+
return undefined;
|
|
70
|
+
const type = report.contract.split(":", 1)[0];
|
|
71
|
+
// The same contract, else the same C# type of an older build (another fingerprint).
|
|
72
|
+
const viewModel = map.viewModels.find((entry) => entry.contract === report.contract)
|
|
73
|
+
?? map.viewModels.find((entry) => entry.id === type);
|
|
74
|
+
if (viewModel === undefined)
|
|
75
|
+
return undefined;
|
|
76
|
+
const members = map.members.filter((entry) => entry.viewModel === viewModel.id && entry.member === report.member);
|
|
77
|
+
for (const kind of memberKindsByCall[report.kind] ?? []) {
|
|
78
|
+
const member = members.find((entry) => entry.kind === kind);
|
|
79
|
+
if (member !== undefined)
|
|
80
|
+
return member;
|
|
81
|
+
}
|
|
82
|
+
return members[0];
|
|
83
|
+
}
|
|
84
|
+
/** The handler of a map member, as the timeline shows it. */
|
|
85
|
+
export function callHandler(member) {
|
|
86
|
+
const prefix = `${member.viewModel}.`;
|
|
87
|
+
const method = member.symbol.startsWith(prefix) ? member.symbol.slice(prefix.length) : member.symbol;
|
|
88
|
+
const fileName = member.location?.file.split(/[\\/]/u).pop();
|
|
89
|
+
return {
|
|
90
|
+
symbol: member.symbol,
|
|
91
|
+
method,
|
|
92
|
+
source: member.id,
|
|
93
|
+
...(fileName ? { fileName } : {}),
|
|
94
|
+
...(member.location ? { line: member.location.line } : {}),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** `command EditorViewModel.save → SaveAsync() 23 ms`, with the outcome when it is not `ok`. */
|
|
98
|
+
export function callLabel(call) {
|
|
99
|
+
const handler = call.handler?.method ?? call.handlerName;
|
|
100
|
+
const outcome = call.outcome === "ok" ? "" : ` · ${call.outcome}${call.reason === undefined ? "" : ` (${call.reason})`}`;
|
|
101
|
+
return `${call.kind} ${call.viewModel}.${call.member}${handler === undefined ? "" : ` → ${handler}`} ${formatMilliseconds(call.duration)}${outcome}`;
|
|
102
|
+
}
|
|
103
|
+
export function formatMilliseconds(value) {
|
|
104
|
+
return `${value < 10 ? value.toFixed(1) : Math.round(value)} ms`;
|
|
105
|
+
}
|
|
106
|
+
/** A call's entry: its report with the handler the map names. */
|
|
107
|
+
export function callEntry(report, map, id, timestamp) {
|
|
108
|
+
const member = findCallMember(map, report);
|
|
109
|
+
// `Demo.EditorViewModel:3F2A…` names the C# ViewModel `EditorViewModel`.
|
|
110
|
+
const viewModel = report.contract.split(":", 1)[0].split(/[.+]/u).pop() || report.route;
|
|
111
|
+
const call = {
|
|
112
|
+
kind: report.kind,
|
|
113
|
+
route: report.route,
|
|
114
|
+
viewModel,
|
|
115
|
+
member: report.member,
|
|
116
|
+
duration: report.duration,
|
|
117
|
+
outcome: report.outcome,
|
|
118
|
+
...(report.reason === undefined ? {} : { reason: report.reason }),
|
|
119
|
+
...(report.revision === undefined ? {} : { revision: report.revision }),
|
|
120
|
+
...(member === undefined ? {} : { handler: callHandler(member) }),
|
|
121
|
+
...(report.handlerDuration === undefined ? {} : { handlerDuration: report.handlerDuration }),
|
|
122
|
+
...(report.handlerName === undefined || member !== undefined ? {} : { handlerName: report.handlerName }),
|
|
123
|
+
...(report.failure === undefined ? {} : { failure: report.failure }),
|
|
124
|
+
};
|
|
125
|
+
return { id, timestamp, ...call, label: callLabel(call) };
|
|
126
|
+
}
|
|
127
|
+
const framePattern = /^\s*at (.+?) in (.+):line (\d{1,9})\s*$/u;
|
|
128
|
+
/** The frames of a .NET stack that name a source file and line, in order, at most `limit`. */
|
|
129
|
+
export function stackFrames(stack, limit = 12) {
|
|
130
|
+
const frames = [];
|
|
131
|
+
for (const line of stack?.split("\n") ?? []) {
|
|
132
|
+
const match = framePattern.exec(line);
|
|
133
|
+
if (match === null)
|
|
134
|
+
continue;
|
|
135
|
+
frames.push({ text: line.trim(), method: match[1], file: match[2], line: Number(match[3]) });
|
|
136
|
+
if (frames.length >= limit)
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
return frames;
|
|
140
|
+
}
|
package/dist/channel.d.ts
CHANGED
|
@@ -2,6 +2,45 @@ export declare const diagnosticEvent = "runic:diagnostic";
|
|
|
2
2
|
export declare const connectionEvent = "runic:connection";
|
|
3
3
|
/** The state inspector: a View's state, a closed View, or a page that went away (`DevelopmentTimeline.applyView`). */
|
|
4
4
|
export declare const viewEvent = "runic:view";
|
|
5
|
+
/** A settled Bridge call for the dock's timeline (calls.ts, `RunicBridgeCallReport`). */
|
|
6
|
+
export declare const callEvent = "runic:call";
|
|
7
|
+
/** One settled Bridge call with a trace context, for the server's OTLP export (otlp.ts). */
|
|
8
|
+
export declare const spanEvent = "runic:span";
|
|
9
|
+
/**
|
|
10
|
+
* A request of the development client over Vite's HMR connection, which reaches the development server from any page
|
|
11
|
+
* that loaded Vite's modules, also the .NET host's page under `dotnet runic dev`, whose relative URLs name the host:
|
|
12
|
+
* `{ id, kind: "sources" }` for the source map, `{ id, kind: "handlers", file }` for the handler analysis,
|
|
13
|
+
* `{ id, kind: "message", target: { catalog, key } }` for a Translations message's sources, and
|
|
14
|
+
* `{ id, kind: "open", target }` for `/__runic/open`'s `{ id }`, `{ file, line, column }` or `{ message }`. The server answers each on `responseEvent` with the same `id` (sources.ts,
|
|
15
|
+
* `answerClientRequest`).
|
|
16
|
+
*/
|
|
17
|
+
export declare const requestEvent = "runic:request";
|
|
18
|
+
export declare const responseEvent = "runic:response";
|
|
19
|
+
export type RunicClientRequest = {
|
|
20
|
+
readonly id: number;
|
|
21
|
+
readonly kind: "sources";
|
|
22
|
+
} | {
|
|
23
|
+
readonly id: number;
|
|
24
|
+
readonly kind: "handlers";
|
|
25
|
+
readonly file: string;
|
|
26
|
+
} | {
|
|
27
|
+
readonly id: number;
|
|
28
|
+
readonly kind: "message";
|
|
29
|
+
readonly target: {
|
|
30
|
+
readonly catalog: string;
|
|
31
|
+
readonly key: string;
|
|
32
|
+
};
|
|
33
|
+
} | {
|
|
34
|
+
readonly id: number;
|
|
35
|
+
readonly kind: "open";
|
|
36
|
+
readonly target: unknown;
|
|
37
|
+
};
|
|
38
|
+
/** The answer to a `RunicClientRequest`: an HTTP-like status, and for `sources` with 200 the map. */
|
|
39
|
+
export interface RunicClientResponse {
|
|
40
|
+
readonly id: number;
|
|
41
|
+
readonly status: number;
|
|
42
|
+
readonly body?: unknown;
|
|
43
|
+
}
|
|
5
44
|
/** The endpoint a client posts `{ "event", "data" }` to, one message per request, answered with 204. */
|
|
6
45
|
export declare const diagnosticsPath = "/__runic/diagnostics";
|
|
7
46
|
/**
|
|
@@ -9,8 +48,26 @@ export declare const diagnosticsPath = "/__runic/diagnostics";
|
|
|
9
48
|
* characters, so this leaves room for JSON escaping and multibyte text.
|
|
10
49
|
*/
|
|
11
50
|
export declare const maximumClientMessageBytes = 65536;
|
|
12
|
-
/**
|
|
51
|
+
/** The development source map and the Runic open-in-editor action (sources.ts), which Runic Inspect reads and calls. */
|
|
52
|
+
export declare const sourcesPath = "/__runic/sources";
|
|
53
|
+
export declare const openPath = "/__runic/open";
|
|
54
|
+
/** Runic Inspect's handler analysis of a frontend file (handlers.ts): which event handlers reach which client calls. */
|
|
55
|
+
export declare const handlersPath = "/__runic/handlers";
|
|
56
|
+
/** `{ channel?: "hot", … }` on `globalThis`, set by `virtual:runic/client` before the client evaluates. */
|
|
13
57
|
export declare const clientOptionsKey: unique symbol;
|
|
14
58
|
export interface RunicClientOptions {
|
|
15
59
|
readonly channel?: "hot";
|
|
60
|
+
/** The Vite DevTools dock is registered: the client loads it when the document does not (client.ts, `loadDock`). */
|
|
61
|
+
readonly dock?: boolean;
|
|
62
|
+
/** `false` leaves Runic Inspect out (`runic({ inspect: false })`). */
|
|
63
|
+
readonly inspect?: boolean;
|
|
64
|
+
/** The server's base path. */
|
|
65
|
+
readonly base?: string;
|
|
66
|
+
/** The Vite root, which relative component paths (Svelte, Angular) are relative to. */
|
|
67
|
+
readonly root?: string;
|
|
68
|
+
/**
|
|
69
|
+
* The development server exports the page's spans of Bridge calls over OTLP: the client gives each call a W3C trace
|
|
70
|
+
* context (which its request carries to .NET) and sends the call's span as a `runic:span` message.
|
|
71
|
+
*/
|
|
72
|
+
readonly trace?: boolean;
|
|
16
73
|
}
|
package/dist/channel.js
CHANGED
|
@@ -10,6 +10,20 @@ export const diagnosticEvent = "runic:diagnostic";
|
|
|
10
10
|
export const connectionEvent = "runic:connection";
|
|
11
11
|
/** The state inspector: a View's state, a closed View, or a page that went away (`DevelopmentTimeline.applyView`). */
|
|
12
12
|
export const viewEvent = "runic:view";
|
|
13
|
+
/** A settled Bridge call for the dock's timeline (calls.ts, `RunicBridgeCallReport`). */
|
|
14
|
+
export const callEvent = "runic:call";
|
|
15
|
+
/** One settled Bridge call with a trace context, for the server's OTLP export (otlp.ts). */
|
|
16
|
+
export const spanEvent = "runic:span";
|
|
17
|
+
/**
|
|
18
|
+
* A request of the development client over Vite's HMR connection, which reaches the development server from any page
|
|
19
|
+
* that loaded Vite's modules, also the .NET host's page under `dotnet runic dev`, whose relative URLs name the host:
|
|
20
|
+
* `{ id, kind: "sources" }` for the source map, `{ id, kind: "handlers", file }` for the handler analysis,
|
|
21
|
+
* `{ id, kind: "message", target: { catalog, key } }` for a Translations message's sources, and
|
|
22
|
+
* `{ id, kind: "open", target }` for `/__runic/open`'s `{ id }`, `{ file, line, column }` or `{ message }`. The server answers each on `responseEvent` with the same `id` (sources.ts,
|
|
23
|
+
* `answerClientRequest`).
|
|
24
|
+
*/
|
|
25
|
+
export const requestEvent = "runic:request";
|
|
26
|
+
export const responseEvent = "runic:response";
|
|
13
27
|
/** The endpoint a client posts `{ "event", "data" }` to, one message per request, answered with 204. */
|
|
14
28
|
export const diagnosticsPath = "/__runic/diagnostics";
|
|
15
29
|
/**
|
|
@@ -17,5 +31,10 @@ export const diagnosticsPath = "/__runic/diagnostics";
|
|
|
17
31
|
* characters, so this leaves room for JSON escaping and multibyte text.
|
|
18
32
|
*/
|
|
19
33
|
export const maximumClientMessageBytes = 65_536;
|
|
20
|
-
/**
|
|
34
|
+
/** The development source map and the Runic open-in-editor action (sources.ts), which Runic Inspect reads and calls. */
|
|
35
|
+
export const sourcesPath = "/__runic/sources";
|
|
36
|
+
export const openPath = "/__runic/open";
|
|
37
|
+
/** Runic Inspect's handler analysis of a frontend file (handlers.ts): which event handlers reach which client calls. */
|
|
38
|
+
export const handlersPath = "/__runic/handlers";
|
|
39
|
+
/** `{ channel?: "hot", … }` on `globalThis`, set by `virtual:runic/client` before the client evaluates. */
|
|
21
40
|
export const clientOptionsKey = Symbol.for("runic.vite.client");
|