@mark1russell7/netdiag-cli 0.4.0 → 0.4.2
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 +10 -0
- package/build/bin.js +1 -1
- package/build/cli-CcguQFNo.js +239 -0
- package/build/cli-CcguQFNo.js.map +1 -0
- package/build/index.d.ts +4 -180
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -1
- package/build/report-CFfbXV7w.d.ts +195 -0
- package/build/report-CFfbXV7w.d.ts.map +1 -0
- package/build/{cli-BzbcmVhn.js → report-CbppPHXp.js} +108 -231
- package/build/report-CbppPHXp.js.map +1 -0
- package/build/report.d.ts +2 -0
- package/build/report.js +1 -0
- package/package.json +6 -2
- package/src/cli.ts +2 -1
- package/src/index.ts +14 -2
- package/src/next.ts +1 -1
- package/src/plan.ts +4 -12
- package/src/report.ts +141 -2
- package/src/scheme.ts +12 -0
- package/build/cli-BzbcmVhn.js.map +0 -1
package/README.md
CHANGED
|
@@ -100,6 +100,15 @@ The option `--json` writes the object `CheckReport` in the format `netdiag-check
|
|
|
100
100
|
| `ignored`, `skipped` | The evidence and the facts that the diagnosis did not use, with the reason. |
|
|
101
101
|
| `facts` | Each fact of the visit, with its role and its host. |
|
|
102
102
|
|
|
103
|
+
`readCheckReport(value)` reads a report of JSON and checks it. The checks are these:
|
|
104
|
+
|
|
105
|
+
- Each field has its type, and each fact passes `readFact` of netdiag.
|
|
106
|
+
- The causes go from the most probable, and their probabilities sum to 1.
|
|
107
|
+
- `next` is the first of `choices`, and each fact id is unique.
|
|
108
|
+
- Each fact id of `evidence`, `ignored` and `skipped` is the id of a fact of the report.
|
|
109
|
+
|
|
110
|
+
The entry `@mark1russell7/netdiag-cli/report` has the report functions only. It starts no probe, so a page can read a report with it.
|
|
111
|
+
|
|
103
112
|
## The API
|
|
104
113
|
|
|
105
114
|
The pure parts of the command are also exports. A program can use them with its own probes.
|
|
@@ -109,6 +118,7 @@ The pure parts of the command are also exports. A program can use them with its
|
|
|
109
118
|
| `planCheck(options, system)` | It gives the plan of a check with the grants of its scope, or each problem of the options. |
|
|
110
119
|
| `reportOf(plan, steps)` | It gives the report of the steps of a visit. |
|
|
111
120
|
| `formatReport(report)` | It gives the lines of the text output. |
|
|
121
|
+
| `readCheckReport(value)` | It reads a JSON report and gives the report, or at most 20 problems. |
|
|
112
122
|
| `nextSteps(diagnosis, plan, addressed)` | It gives the next steps, from the largest gain. |
|
|
113
123
|
| `check(options, deps)` | It plans a check, starts the visit with the given clock and tool host, and gives the report. |
|
|
114
124
|
| `createNetdiagCli(options)` | It makes the command line with a given check, output and terminal. |
|
package/build/bin.js
CHANGED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { h as isScheme, m as SCHEMES, o as reportOf, r as formatReport } from "./report-CbppPHXp.js";
|
|
2
|
+
import { DEFAULT_PING_COUNT, MAX_PING_COUNT, canonicalHost, grantProblems, hostKind, namedGrant, parseTarget } from "@mark1russell7/netdiag/core";
|
|
3
|
+
import { err, ok } from "@mark1russell7/optional";
|
|
4
|
+
import { getServers } from "node:dns";
|
|
5
|
+
import { realClock } from "@mark1russell7/algebra/clock";
|
|
6
|
+
import { visitTarget } from "@mark1russell7/netdiag";
|
|
7
|
+
import { DEFAULT_PING_COUNT as DEFAULT_PING_COUNT$1, MAX_PING_COUNT as MAX_PING_COUNT$1, commandHost } from "@mark1russell7/netdiag/tools";
|
|
8
|
+
import { runCommand } from "@procedures/shell/command";
|
|
9
|
+
import { readFileSync } from "node:fs";
|
|
10
|
+
import { createProcedureCli } from "@procedures/cli-kit";
|
|
11
|
+
import { defineProcedure } from "@procedures/client";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
// src/plan.ts
|
|
14
|
+
/** This function reads a host of the user. A URL also gives a scheme and a path. Only a port in the text stays in the target. */
|
|
15
|
+
function locate(text, what) {
|
|
16
|
+
const parsed = parseTarget(text);
|
|
17
|
+
if (parsed.tag === "err") return err(`The ${what} is not valid. ${parsed.error}`);
|
|
18
|
+
if (!text.includes("://")) return ok({ target: parsed.value });
|
|
19
|
+
const url = new URL(text.trim());
|
|
20
|
+
const scheme = url.protocol.slice(0, -1);
|
|
21
|
+
if (!isScheme(scheme)) return err(`The ${what} "${text}" has the scheme ${scheme}. A check sends HTTP and HTTPS requests only.`);
|
|
22
|
+
const host = {
|
|
23
|
+
host: parsed.value.host,
|
|
24
|
+
kind: parsed.value.kind
|
|
25
|
+
};
|
|
26
|
+
const target = url.port === "" ? host : {
|
|
27
|
+
...host,
|
|
28
|
+
port: Number(url.port)
|
|
29
|
+
};
|
|
30
|
+
return ok({
|
|
31
|
+
target,
|
|
32
|
+
scheme,
|
|
33
|
+
path: `${url.pathname}${url.search}`
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** This function gives a grant of one IP address. */
|
|
37
|
+
function addressGrant(address, basis, note) {
|
|
38
|
+
return {
|
|
39
|
+
...namedGrant(address, note),
|
|
40
|
+
basis
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function visitHost(target) {
|
|
44
|
+
return target.port === void 0 ? { host: target.host } : {
|
|
45
|
+
host: target.host,
|
|
46
|
+
port: target.port
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function whole(value, low, high) {
|
|
50
|
+
return Number.isInteger(value) && value >= low && value <= high;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* This function gives the plan of a check from the options of the command line, or each problem of the options.
|
|
54
|
+
*
|
|
55
|
+
* The grants of the plan are the scope rule of the command. The plan grants only these hosts:
|
|
56
|
+
*
|
|
57
|
+
* - the target, and each reference host, with the basis `named`
|
|
58
|
+
* - the DNS resolver, with the basis `named` from `--resolver`, or `configured` from the computer
|
|
59
|
+
* - the gateway, when the user gives it, with the basis `named`
|
|
60
|
+
* - each range of `--grant`, with the basis `owned`
|
|
61
|
+
*
|
|
62
|
+
* The visit also puts in the scope the addresses that the resolver gives for a named host.
|
|
63
|
+
*/
|
|
64
|
+
function planCheck(options, system) {
|
|
65
|
+
const problems = [];
|
|
66
|
+
const grants = [];
|
|
67
|
+
const located = locate(options.target, "target");
|
|
68
|
+
if (located.tag === "err") return err([located.error]);
|
|
69
|
+
const scheme = options.scheme ?? located.value.scheme ?? "https";
|
|
70
|
+
const path = options.path ?? located.value.path ?? "/";
|
|
71
|
+
if (!isScheme(scheme)) problems.push(`The scheme ${String(scheme)} is not http or https.`);
|
|
72
|
+
if (!path.startsWith("/")) problems.push(`The path "${path}" does not start with "/".`);
|
|
73
|
+
const port = options.port ?? located.value.target.port;
|
|
74
|
+
if (port !== void 0 && !whole(port, 1, 65535)) problems.push(`The port ${port} is not an integer from 1 to 65535.`);
|
|
75
|
+
const pingCount = options.pingCount ?? DEFAULT_PING_COUNT;
|
|
76
|
+
if (!whole(pingCount, 0, MAX_PING_COUNT)) problems.push(`The ping count ${pingCount} is not an integer from 0 to ${MAX_PING_COUNT}.`);
|
|
77
|
+
const target = port === void 0 ? {
|
|
78
|
+
host: located.value.target.host,
|
|
79
|
+
kind: located.value.target.kind
|
|
80
|
+
} : {
|
|
81
|
+
...located.value.target,
|
|
82
|
+
port
|
|
83
|
+
};
|
|
84
|
+
grants.push(namedGrant(target, "the target"));
|
|
85
|
+
const references = [];
|
|
86
|
+
for (const text of options.reference ?? []) {
|
|
87
|
+
const reference = locate(text, "reference");
|
|
88
|
+
if (reference.tag === "err") problems.push(reference.error);
|
|
89
|
+
else {
|
|
90
|
+
references.push(visitHost(reference.value.target));
|
|
91
|
+
grants.push(namedGrant(reference.value.target, "a reference host"));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
let resolver;
|
|
95
|
+
const resolverText = options.resolver ?? system.resolvers[0];
|
|
96
|
+
if (resolverText !== void 0) {
|
|
97
|
+
const from = options.resolver === void 0 ? "The DNS resolver of the computer" : "The DNS resolver";
|
|
98
|
+
const parsed = parseTarget(resolverText);
|
|
99
|
+
if (parsed.tag === "err") problems.push(`${from} is not valid. ${parsed.error}`);
|
|
100
|
+
else if (parsed.value.kind === "name") problems.push(`${from} "${resolverText}" is not an IP address.`);
|
|
101
|
+
else {
|
|
102
|
+
resolver = parsed.value.port === void 0 ? { address: parsed.value.host } : {
|
|
103
|
+
address: parsed.value.host,
|
|
104
|
+
port: parsed.value.port
|
|
105
|
+
};
|
|
106
|
+
grants.push(addressGrant(parsed.value, options.resolver === void 0 ? "configured" : "named", "the DNS resolver"));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
let gateway;
|
|
110
|
+
if (options.gateway !== void 0) {
|
|
111
|
+
const host = canonicalHost(options.gateway);
|
|
112
|
+
const kind = hostKind(host);
|
|
113
|
+
if (kind === "name") problems.push(`The gateway "${options.gateway}" is not an IP address.`);
|
|
114
|
+
else {
|
|
115
|
+
gateway = host;
|
|
116
|
+
grants.push(addressGrant({
|
|
117
|
+
host,
|
|
118
|
+
kind
|
|
119
|
+
}, "named", "the default gateway"));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (const cidr of options.grant ?? []) grants.push({
|
|
123
|
+
kind: "range",
|
|
124
|
+
cidr: cidr.trim(),
|
|
125
|
+
basis: "owned",
|
|
126
|
+
note: "a range of --grant"
|
|
127
|
+
});
|
|
128
|
+
for (const grant of grants) for (const problem of grantProblems(grant)) problems.push(grant.basis === "configured" ? `${problem} Give a resolver with --resolver <address>.` : problem);
|
|
129
|
+
if (problems.length > 0) return err(problems);
|
|
130
|
+
const visit = {
|
|
131
|
+
target: visitHost(target),
|
|
132
|
+
references,
|
|
133
|
+
...gateway === void 0 ? {} : { gateway },
|
|
134
|
+
...resolver === void 0 ? {} : { resolver },
|
|
135
|
+
grants
|
|
136
|
+
};
|
|
137
|
+
const mtu = options.mtu === void 0 ? "auto" : options.mtu ? "always" : "never";
|
|
138
|
+
return ok({
|
|
139
|
+
target,
|
|
140
|
+
scheme,
|
|
141
|
+
path,
|
|
142
|
+
pingCount,
|
|
143
|
+
mtu,
|
|
144
|
+
visit
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
// src/check.ts
|
|
148
|
+
/** This function gives the parts of this computer: the monotonic clock, `runCommand` of `@procedures/shell` and the DNS resolvers. */
|
|
149
|
+
function systemDeps() {
|
|
150
|
+
return {
|
|
151
|
+
clock: realClock,
|
|
152
|
+
tools: commandHost(runCommand, process.platform),
|
|
153
|
+
resolvers: getServers()
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* This function plans a check, starts its visit, and gives the report.
|
|
158
|
+
*
|
|
159
|
+
* It throws a `RangeError` with each problem of the options before the first probe.
|
|
160
|
+
*/
|
|
161
|
+
async function check(options, deps) {
|
|
162
|
+
const planned = planCheck(options, { resolvers: deps.resolvers });
|
|
163
|
+
if (planned.tag === "err") throw new RangeError(planned.error.join("\n"));
|
|
164
|
+
const plan = planned.value;
|
|
165
|
+
const steps = [];
|
|
166
|
+
const visit = visitTarget(plan.visit, {
|
|
167
|
+
clock: deps.clock,
|
|
168
|
+
tools: deps.tools,
|
|
169
|
+
pingCount: plan.pingCount,
|
|
170
|
+
mtu: plan.mtu,
|
|
171
|
+
scheme: plan.scheme,
|
|
172
|
+
path: plan.path,
|
|
173
|
+
tls: deps.tls,
|
|
174
|
+
signal: deps.signal
|
|
175
|
+
});
|
|
176
|
+
for await (const step of visit) steps.push(step);
|
|
177
|
+
return reportOf(plan, steps);
|
|
178
|
+
}
|
|
179
|
+
// src/cli.ts
|
|
180
|
+
/** The name of the program. */
|
|
181
|
+
const PROGRAM = "netdiag";
|
|
182
|
+
const CHECK_INPUT = z.object({
|
|
183
|
+
target: z.string().min(1).describe("The host to check: a DNS name, an IP address, host:port or a URL"),
|
|
184
|
+
port: z.number().int().min(1).max(65535).optional().describe("The port of the HTTP request. The default is the port of the scheme"),
|
|
185
|
+
scheme: z.enum(SCHEMES).optional().describe("The scheme of the HTTP request: http or https. The default is https"),
|
|
186
|
+
path: z.string().optional().describe("The path of the HTTP request. The default is /"),
|
|
187
|
+
reference: z.array(z.string()).optional().describe("A host that works, for a comparison. Give the flag again for more hosts"),
|
|
188
|
+
resolver: z.string().optional().describe("The address of the DNS resolver. The default is the first resolver of this computer"),
|
|
189
|
+
gateway: z.string().optional().describe("The IP address of the default gateway. The check pings it"),
|
|
190
|
+
grant: z.array(z.string()).optional().describe("A CIDR range that you own. The check can probe each address in it"),
|
|
191
|
+
pingCount: z.number().int().min(0).max(MAX_PING_COUNT$1).optional().describe(`The number of echo requests to each address. The default is ${DEFAULT_PING_COUNT$1}`),
|
|
192
|
+
mtu: z.boolean().optional().describe("Search the MTU of the path to each address. The default searches only after a time-out of TLS or HTTP. --no-mtu starts no search")
|
|
193
|
+
});
|
|
194
|
+
/** This function makes the command line of netdiag with the command `check`. */
|
|
195
|
+
function createNetdiagCli(options) {
|
|
196
|
+
const procedure = defineProcedure({
|
|
197
|
+
path: ["check"],
|
|
198
|
+
input: CHECK_INPUT,
|
|
199
|
+
output: z.custom(),
|
|
200
|
+
metadata: {
|
|
201
|
+
description: "Check a target, and show the probable causes of a fault and the next step",
|
|
202
|
+
args: ["target"],
|
|
203
|
+
effects: {
|
|
204
|
+
reads: ["network"],
|
|
205
|
+
writes: ["process"],
|
|
206
|
+
destructive: false
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
handler: (input, context) => options.check(input, context.signal)
|
|
210
|
+
});
|
|
211
|
+
return createProcedureCli({
|
|
212
|
+
name: PROGRAM,
|
|
213
|
+
version: options.version,
|
|
214
|
+
description: "the probable causes of a network fault, and the next step",
|
|
215
|
+
procedures: [procedure],
|
|
216
|
+
format: { check: (result) => formatReport(result) },
|
|
217
|
+
print: options.print,
|
|
218
|
+
terminal: options.terminal
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
/** This function gives the version in `package.json` of this package. */
|
|
222
|
+
function packageVersion() {
|
|
223
|
+
const manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
224
|
+
const version = typeof manifest === "object" && manifest !== null && "version" in manifest ? manifest.version : void 0;
|
|
225
|
+
return typeof version === "string" ? version : "0.0.0";
|
|
226
|
+
}
|
|
227
|
+
/** This function operates the command line on this computer, and gives the exit code. */
|
|
228
|
+
async function main(argv) {
|
|
229
|
+
return createNetdiagCli({
|
|
230
|
+
version: packageVersion(),
|
|
231
|
+
check: (options, signal) => check(options, {
|
|
232
|
+
...systemDeps(),
|
|
233
|
+
signal
|
|
234
|
+
})
|
|
235
|
+
}).run(argv);
|
|
236
|
+
}
|
|
237
|
+
export { check as a, packageVersion as i, createNetdiagCli as n, systemDeps as o, main as r, planCheck as s, PROGRAM as t };
|
|
238
|
+
|
|
239
|
+
//# sourceMappingURL=cli-CcguQFNo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-CcguQFNo.js","names":["MAX_PING_COUNT","DEFAULT_PING_COUNT"],"sources":["../src/plan.ts","../src/check.ts","../src/cli.ts"],"sourcesContent":["import {\n DEFAULT_PING_COUNT,\n MAX_PING_COUNT,\n canonicalHost,\n grantProblems,\n hostKind,\n namedGrant,\n parseTarget,\n type Grant,\n type MtuSearch,\n type Target,\n type VisitHost,\n type VisitInput,\n type VisitResolver,\n} from \"@mark1russell7/netdiag/core\";\nimport { err, ok, type Result } from \"@mark1russell7/optional\";\nimport { isScheme, type Scheme } from \"./scheme.ts\";\n\n// The plan of a check: the options of the command line, changed into the input of a visit. The plan is the scope rule\n// of the command: it grants only the hosts that the user names, the DNS resolver and the ranges of `--grant`.\n\n/** The options of the command `check`. Each field is a flag of the command line. */\nexport interface CheckOptions {\n /** The host to check: a DNS name, an IP address, `host:port` or a URL. */\n readonly target: string;\n /** The port of the HTTP request. The default is the port in the target, then the port of the scheme. */\n readonly port?: number | undefined;\n /** The scheme of the HTTP request. The default is the scheme of a URL target, then `https`. */\n readonly scheme?: Scheme | undefined;\n /** The path of the HTTP request. The default is the path of a URL target, then `/`. */\n readonly path?: string | undefined;\n /** The hosts that work, for a comparison with the target. */\n readonly reference?: readonly string[] | undefined;\n /** The address of the DNS resolver, with an optional port. The default is the first resolver of the computer. */\n readonly resolver?: string | undefined;\n /** The IP address of the default gateway. Without it, the check does not ping a gateway. */\n readonly gateway?: string | undefined;\n /** The CIDR ranges that the user owns. The check can probe each address in them. */\n readonly grant?: readonly string[] | undefined;\n /** The number of echo requests to each address. The default is `DEFAULT_PING_COUNT`. */\n readonly pingCount?: number | undefined;\n /**\n * `true` searches the MTU of the path to each address. Without it, the check searches only after a TLS handshake or\n * an HTTP response that timed out. `false` does not search.\n */\n readonly mtu?: boolean | undefined;\n}\n\n/** The parts of the computer that a plan reads. */\nexport interface PlanSystem {\n /** The DNS resolvers of the computer, in the form of `getServers()` of `node:dns`. */\n readonly resolvers: readonly string[];\n}\n\n/** The plan of a check: the target, the HTTP request, the number of echo requests, and the input of the visit. */\nexport interface CheckPlan {\n /** The target, with the port of the HTTP request when the user gives one. */\n readonly target: Target;\n readonly scheme: Scheme;\n readonly path: string;\n readonly pingCount: number;\n /** When the visit searches the MTU of the path to an address. The default is `auto`. */\n readonly mtu?: MtuSearch | undefined;\n /** The input of `visitTarget`, with the grants of the scope. */\n readonly visit: VisitInput;\n}\n\ninterface Located {\n readonly target: Target;\n readonly scheme?: Scheme | undefined;\n readonly path?: string | undefined;\n}\n\n/** This function reads a host of the user. A URL also gives a scheme and a path. Only a port in the text stays in the target. */\nfunction locate(text: string, what: string): Result<Located, string> {\n const parsed = parseTarget(text);\n if (parsed.tag === \"err\") return err(`The ${what} is not valid. ${parsed.error}`);\n if (!text.includes(\"://\")) return ok({ target: parsed.value });\n const url = new URL(text.trim());\n const scheme = url.protocol.slice(0, -1);\n if (!isScheme(scheme)) return err(`The ${what} \"${text}\" has the scheme ${scheme}. A check sends HTTP and HTTPS requests only.`);\n // `parseTarget` gives the port of the scheme to a URL with no port. The check keeps only a port that the URL names.\n const host = { host: parsed.value.host, kind: parsed.value.kind };\n const target = url.port === \"\" ? host : { ...host, port: Number(url.port) };\n return ok({ target, scheme, path: `${url.pathname}${url.search}` });\n}\n\n/** This function gives a grant of one IP address. */\nfunction addressGrant(address: Target, basis: Grant[\"basis\"], note: string): Grant {\n return { ...namedGrant(address, note), basis };\n}\n\nfunction visitHost(target: Target): VisitHost {\n return target.port === undefined ? { host: target.host } : { host: target.host, port: target.port };\n}\n\nfunction whole(value: number, low: number, high: number): boolean {\n return Number.isInteger(value) && value >= low && value <= high;\n}\n\n/**\n * This function gives the plan of a check from the options of the command line, or each problem of the options.\n *\n * The grants of the plan are the scope rule of the command. The plan grants only these hosts:\n *\n * - the target, and each reference host, with the basis `named`\n * - the DNS resolver, with the basis `named` from `--resolver`, or `configured` from the computer\n * - the gateway, when the user gives it, with the basis `named`\n * - each range of `--grant`, with the basis `owned`\n *\n * The visit also puts in the scope the addresses that the resolver gives for a named host.\n */\nexport function planCheck(options: CheckOptions, system: PlanSystem): Result<CheckPlan, readonly string[]> {\n const problems: string[] = [];\n const grants: Grant[] = [];\n\n const located = locate(options.target, \"target\");\n if (located.tag === \"err\") return err([located.error]);\n const scheme = options.scheme ?? located.value.scheme ?? \"https\";\n const path = options.path ?? located.value.path ?? \"/\";\n if (!isScheme(scheme)) problems.push(`The scheme ${String(scheme)} is not http or https.`);\n if (!path.startsWith(\"/\")) problems.push(`The path \"${path}\" does not start with \"/\".`);\n const port = options.port ?? located.value.target.port;\n if (port !== undefined && !whole(port, 1, 65535)) problems.push(`The port ${port} is not an integer from 1 to 65535.`);\n const pingCount = options.pingCount ?? DEFAULT_PING_COUNT;\n if (!whole(pingCount, 0, MAX_PING_COUNT)) problems.push(`The ping count ${pingCount} is not an integer from 0 to ${MAX_PING_COUNT}.`);\n const target: Target = port === undefined ? { host: located.value.target.host, kind: located.value.target.kind } : { ...located.value.target, port };\n grants.push(namedGrant(target, \"the target\"));\n\n const references: VisitHost[] = [];\n for (const text of options.reference ?? []) {\n const reference = locate(text, \"reference\");\n if (reference.tag === \"err\") problems.push(reference.error);\n else {\n references.push(visitHost(reference.value.target));\n grants.push(namedGrant(reference.value.target, \"a reference host\"));\n }\n }\n\n let resolver: VisitResolver | undefined;\n const resolverText = options.resolver ?? system.resolvers[0];\n if (resolverText !== undefined) {\n const from = options.resolver === undefined ? \"The DNS resolver of the computer\" : \"The DNS resolver\";\n const parsed = parseTarget(resolverText);\n if (parsed.tag === \"err\") problems.push(`${from} is not valid. ${parsed.error}`);\n else if (parsed.value.kind === \"name\") problems.push(`${from} \"${resolverText}\" is not an IP address.`);\n else {\n resolver = parsed.value.port === undefined ? { address: parsed.value.host } : { address: parsed.value.host, port: parsed.value.port };\n grants.push(addressGrant(parsed.value, options.resolver === undefined ? \"configured\" : \"named\", \"the DNS resolver\"));\n }\n }\n\n let gateway: string | undefined;\n if (options.gateway !== undefined) {\n const host = canonicalHost(options.gateway);\n const kind = hostKind(host);\n if (kind === \"name\") problems.push(`The gateway \"${options.gateway}\" is not an IP address.`);\n else {\n gateway = host;\n grants.push(addressGrant({ host, kind }, \"named\", \"the default gateway\"));\n }\n }\n\n for (const cidr of options.grant ?? []) grants.push({ kind: \"range\", cidr: cidr.trim(), basis: \"owned\", note: \"a range of --grant\" });\n\n // A grant with a problem stops the plan, so a typing error cannot widen the scope.\n for (const grant of grants) {\n for (const problem of grantProblems(grant)) problems.push(grant.basis === \"configured\" ? `${problem} Give a resolver with --resolver <address>.` : problem);\n }\n if (problems.length > 0) return err(problems);\n\n const visit: VisitInput = {\n target: visitHost(target),\n references,\n ...(gateway === undefined ? {} : { gateway }),\n ...(resolver === undefined ? {} : { resolver }),\n grants,\n };\n const mtu: MtuSearch = options.mtu === undefined ? \"auto\" : options.mtu ? \"always\" : \"never\";\n return ok({ target, scheme, path, pingCount, mtu, visit });\n}\n","import { getServers } from \"node:dns\";\nimport { realClock, type Clock } from \"@mark1russell7/algebra/clock\";\nimport { visitTarget, type TlsProbeOptions, type VisitStep } from \"@mark1russell7/netdiag\";\nimport { commandHost, type ToolHost } from \"@mark1russell7/netdiag/tools\";\nimport { runCommand } from \"@procedures/shell/command\";\nimport { planCheck, type CheckOptions } from \"./plan.ts\";\nimport { reportOf, type CheckReport } from \"./report.ts\";\n\n// The edge of a check: the visit sends the packets, and starts the outside tools. A test gives a fake tool host and\n// servers on the loopback addresses.\n\n/** The parts of the computer that a check uses. A test gives its own parts. */\nexport interface CheckDeps {\n readonly clock: Clock;\n /** The host of the outside tools. Without it, the check starts no `ping`. */\n readonly tools?: ToolHost | undefined;\n /** The DNS resolvers of the computer, in the form of `getServers()` of `node:dns`. */\n readonly resolvers: readonly string[];\n /** The trust stores of the TLS handshake. The default is the roots of Node.js. */\n readonly tls?: TlsProbeOptions | undefined;\n readonly signal?: AbortSignal | undefined;\n}\n\n/** This function gives the parts of this computer: the monotonic clock, `runCommand` of `@procedures/shell` and the DNS resolvers. */\nexport function systemDeps(): CheckDeps {\n return { clock: realClock, tools: commandHost(runCommand, process.platform), resolvers: getServers() };\n}\n\n/**\n * This function plans a check, starts its visit, and gives the report.\n *\n * It throws a `RangeError` with each problem of the options before the first probe.\n */\nexport async function check(options: CheckOptions, deps: CheckDeps): Promise<CheckReport> {\n const planned = planCheck(options, { resolvers: deps.resolvers });\n if (planned.tag === \"err\") throw new RangeError(planned.error.join(\"\\n\"));\n const plan = planned.value;\n const steps: VisitStep[] = [];\n const visit = visitTarget(plan.visit, {\n clock: deps.clock,\n tools: deps.tools,\n pingCount: plan.pingCount,\n mtu: plan.mtu,\n scheme: plan.scheme,\n path: plan.path,\n tls: deps.tls,\n signal: deps.signal,\n });\n for await (const step of visit) steps.push(step);\n return reportOf(plan, steps);\n}\n","import { readFileSync } from \"node:fs\";\nimport { DEFAULT_PING_COUNT, MAX_PING_COUNT } from \"@mark1russell7/netdiag/tools\";\nimport { createProcedureCli, type Print, type ProcedureCli, type Terminal } from \"@procedures/cli-kit\";\nimport { defineProcedure } from \"@procedures/client\";\nimport { z } from \"zod\";\nimport { check, systemDeps } from \"./check.ts\";\nimport type { CheckOptions } from \"./plan.ts\";\nimport { formatReport, type CheckReport } from \"./report.ts\";\nimport { SCHEMES } from \"./scheme.ts\";\n\n// The command line of netdiag. `@procedures/cli-kit` makes the flags from the input schema of the command `check`, and\n// gives the help, `--json` and the exit code.\n\n/** The name of the program. */\nexport const PROGRAM = \"netdiag\";\n\n/** The options of `createNetdiagCli`. */\nexport interface NetdiagCliOptions {\n /** The function that operates one check. A test gives a fake. */\n readonly check: (options: CheckOptions, signal: AbortSignal | undefined) => Promise<CheckReport>;\n /** The version that `--version` shows. */\n readonly version?: string | undefined;\n /** The output of the program. The default writes plain text to the console. */\n readonly print?: Print | undefined;\n /** The terminal state. The program asks for a missing target only in a terminal. */\n readonly terminal?: Terminal | undefined;\n}\n\nconst CHECK_INPUT = z.object({\n target: z.string().min(1).describe(\"The host to check: a DNS name, an IP address, host:port or a URL\"),\n port: z.number().int().min(1).max(65535).optional().describe(\"The port of the HTTP request. The default is the port of the scheme\"),\n scheme: z.enum(SCHEMES).optional().describe(\"The scheme of the HTTP request: http or https. The default is https\"),\n path: z.string().optional().describe(\"The path of the HTTP request. The default is /\"),\n reference: z.array(z.string()).optional().describe(\"A host that works, for a comparison. Give the flag again for more hosts\"),\n resolver: z.string().optional().describe(\"The address of the DNS resolver. The default is the first resolver of this computer\"),\n gateway: z.string().optional().describe(\"The IP address of the default gateway. The check pings it\"),\n grant: z.array(z.string()).optional().describe(\"A CIDR range that you own. The check can probe each address in it\"),\n pingCount: z\n .number()\n .int()\n .min(0)\n .max(MAX_PING_COUNT)\n .optional()\n .describe(`The number of echo requests to each address. The default is ${DEFAULT_PING_COUNT}`),\n mtu: z\n .boolean()\n .optional()\n .describe(\"Search the MTU of the path to each address. The default searches only after a time-out of TLS or HTTP. --no-mtu starts no search\"),\n});\n\n/** This function makes the command line of netdiag with the command `check`. */\nexport function createNetdiagCli(options: NetdiagCliOptions): ProcedureCli {\n const procedure = defineProcedure({\n path: [\"check\"],\n input: CHECK_INPUT,\n output: z.custom<CheckReport>(),\n metadata: {\n description: \"Check a target, and show the probable causes of a fault and the next step\",\n args: [\"target\"],\n effects: { reads: [\"network\"], writes: [\"process\"], destructive: false },\n },\n handler: (input, context) => options.check(input, context.signal),\n });\n return createProcedureCli({\n name: PROGRAM,\n version: options.version,\n description: \"the probable causes of a network fault, and the next step\",\n procedures: [procedure],\n format: { check: (result) => formatReport(result as CheckReport) },\n print: options.print,\n terminal: options.terminal,\n });\n}\n\n/** This function gives the version in `package.json` of this package. */\nexport function packageVersion(): string {\n const manifest: unknown = JSON.parse(readFileSync(new URL(\"../package.json\", import.meta.url), \"utf8\"));\n const version = typeof manifest === \"object\" && manifest !== null && \"version\" in manifest ? manifest.version : undefined;\n return typeof version === \"string\" ? version : \"0.0.0\";\n}\n\n/** This function operates the command line on this computer, and gives the exit code. */\nexport async function main(argv: readonly string[]): Promise<number> {\n const cli = createNetdiagCli({ version: packageVersion(), check: (options, signal) => check(options, { ...systemDeps(), signal }) });\n return cli.run(argv);\n}\n"],"mappings":";;;;;;;;;;;;;;AA0EA,SAAS,OAAO,MAAc,MAAuC;CACnE,MAAM,SAAS,YAAY,IAAI;CAC/B,IAAI,OAAO,QAAQ,OAAO,OAAO,IAAI,OAAO,KAAK,iBAAiB,OAAO,OAAO;CAChF,IAAI,CAAC,KAAK,SAAS,KAAK,GAAG,OAAO,GAAG,EAAE,QAAQ,OAAO,MAAM,CAAC;CAC7D,MAAM,MAAM,IAAI,IAAI,KAAK,KAAK,CAAC;CAC/B,MAAM,SAAS,IAAI,SAAS,MAAM,GAAG,EAAE;CACvC,IAAI,CAAC,SAAS,MAAM,GAAG,OAAO,IAAI,OAAO,KAAK,IAAI,KAAK,mBAAmB,OAAO,8CAA8C;CAE/H,MAAM,OAAO;EAAE,MAAM,OAAO,MAAM;EAAM,MAAM,OAAO,MAAM;CAAK;CAChE,MAAM,SAAS,IAAI,SAAS,KAAK,OAAO;EAAE,GAAG;EAAM,MAAM,OAAO,IAAI,IAAI;CAAE;CAC1E,OAAO,GAAG;EAAE;EAAQ;EAAQ,MAAM,GAAG,IAAI,WA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AAY,QAAQ,MAAM,OAAO,QAAQ,MAAM;CAClE,CAAC;CACD,OAAO,mBAAmB;EACxB,MAAM;EACN,SAAS,QAAQ;EACjB,aAAa;EACb,YAAY,CAAC,SAAS;EACtB,QAAQ,EAAE,QAAQ,WAAW,aAAa,MAAqB,EAAE;EACjE,OAAO,QAAQ;EACf,UAAU,QAAQ;CACpB,CAAC;AACH;;AAGA,SAAgB,iBAAyB;CACvC,MAAM,WAAoB,KAAK,MAAM,aAAa,IAAI,IAAI,mBAAmB,YAAY,GAAG,GAAG,MAAM,CAAC;CACtG,MAAM,UAAU,OAAO,aAAa,YAAY,aAAa,QAAQ,aAAa,WAAW,SAAS,UAAU,KAAA;CAChH,OAAO,OAAO,YAAY,WAAW,UAAU;AACjD;;AAGA,eAAsB,KAAK,MAA0C;CAEnE,OADY,iBAAiB;EAAE,SAAS,eAAe;EAAG,QAAQ,SAAS,WAAW,MAAM,SAAS;GAAE,GAAG,WAAW;GAAG;EAAO,CAAC;CAAE,CACzH,CAAC,CAAC,IAAI,IAAI;AACrB"}
|
package/build/index.d.ts
CHANGED
|
@@ -4,187 +4,11 @@
|
|
|
4
4
|
* The program `netdiag` has the command `check`. The pure parts are also exports. They are the plan of a check with
|
|
5
5
|
* its scope rule, the report, the text of the report and the choice of the next step.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import { ToolHost } from "@mark1russell7/netdiag/tools";
|
|
9
|
-
import { Result } from "@mark1russell7/optional";
|
|
7
|
+
import { C as planCheck, E as isScheme, S as PlanSystem, T as Scheme, _ as TOP_CAUSES, a as MAX_REPORT_PROBLEMS, b as CheckOptions, c as readCheckReport, d as ADD_GATEWAY, f as ADD_REFERENCE, g as NextStep, h as NextProbeKind, i as CheckReport, l as reportOf, m as NextProbe, n as CheckFact, o as formatReport, p as NEXT_PROBES, r as CheckProblem, s as percentOf, t as CHECK_FORMAT, u as subjectText, v as nextSteps, w as SCHEMES, x as CheckPlan, y as stepText } from "./report-CFfbXV7w.js";
|
|
10
8
|
import { Clock } from "@mark1russell7/algebra/clock";
|
|
9
|
+
import { TlsProbeOptions } from "@mark1russell7/netdiag";
|
|
10
|
+
import { ToolHost } from "@mark1russell7/netdiag/tools";
|
|
11
11
|
import { Print, ProcedureCli, Terminal } from "@procedures/cli-kit";
|
|
12
|
-
/** The schemes of the HTTP request of a check. */
|
|
13
|
-
export declare const SCHEMES: readonly ["http", "https"];
|
|
14
|
-
/** A scheme of the HTTP request of a check. */
|
|
15
|
-
type Scheme = (typeof SCHEMES)[number];
|
|
16
|
-
/** The options of the command `check`. Each field is a flag of the command line. */
|
|
17
|
-
interface CheckOptions {
|
|
18
|
-
/** The host to check: a DNS name, an IP address, `host:port` or a URL. */
|
|
19
|
-
readonly target: string;
|
|
20
|
-
/** The port of the HTTP request. The default is the port in the target, then the port of the scheme. */
|
|
21
|
-
readonly port?: number | undefined;
|
|
22
|
-
/** The scheme of the HTTP request. The default is the scheme of a URL target, then `https`. */
|
|
23
|
-
readonly scheme?: Scheme | undefined;
|
|
24
|
-
/** The path of the HTTP request. The default is the path of a URL target, then `/`. */
|
|
25
|
-
readonly path?: string | undefined;
|
|
26
|
-
/** The hosts that work, for a comparison with the target. */
|
|
27
|
-
readonly reference?: readonly string[] | undefined;
|
|
28
|
-
/** The address of the DNS resolver, with an optional port. The default is the first resolver of the computer. */
|
|
29
|
-
readonly resolver?: string | undefined;
|
|
30
|
-
/** The IP address of the default gateway. Without it, the check does not ping a gateway. */
|
|
31
|
-
readonly gateway?: string | undefined;
|
|
32
|
-
/** The CIDR ranges that the user owns. The check can probe each address in them. */
|
|
33
|
-
readonly grant?: readonly string[] | undefined;
|
|
34
|
-
/** The number of echo requests to each address. The default is `DEFAULT_PING_COUNT`. */
|
|
35
|
-
readonly pingCount?: number | undefined;
|
|
36
|
-
/**
|
|
37
|
-
* `true` searches the MTU of the path to each address. Without it, the check searches only after a TLS handshake or
|
|
38
|
-
* an HTTP response that timed out. `false` does not search.
|
|
39
|
-
*/
|
|
40
|
-
readonly mtu?: boolean | undefined;
|
|
41
|
-
}
|
|
42
|
-
/** The parts of the computer that a plan reads. */
|
|
43
|
-
interface PlanSystem {
|
|
44
|
-
/** The DNS resolvers of the computer, in the form of `getServers()` of `node:dns`. */
|
|
45
|
-
readonly resolvers: readonly string[];
|
|
46
|
-
}
|
|
47
|
-
/** The plan of a check: the target, the HTTP request, the number of echo requests, and the input of the visit. */
|
|
48
|
-
interface CheckPlan {
|
|
49
|
-
/** The target, with the port of the HTTP request when the user gives one. */
|
|
50
|
-
readonly target: Target;
|
|
51
|
-
readonly scheme: Scheme;
|
|
52
|
-
readonly path: string;
|
|
53
|
-
readonly pingCount: number;
|
|
54
|
-
/** When the visit searches the MTU of the path to an address. The default is `auto`. */
|
|
55
|
-
readonly mtu?: MtuSearch | undefined;
|
|
56
|
-
/** The input of `visitTarget`, with the grants of the scope. */
|
|
57
|
-
readonly visit: VisitInput;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* This function gives the plan of a check from the options of the command line, or each problem of the options.
|
|
61
|
-
*
|
|
62
|
-
* The grants of the plan are the scope rule of the command. The plan grants only these hosts:
|
|
63
|
-
*
|
|
64
|
-
* - the target, and each reference host, with the basis `named`
|
|
65
|
-
* - the DNS resolver, with the basis `named` from `--resolver`, or `configured` from the computer
|
|
66
|
-
* - the gateway, when the user gives it, with the basis `named`
|
|
67
|
-
* - each range of `--grant`, with the basis `owned`
|
|
68
|
-
*
|
|
69
|
-
* The visit also puts in the scope the addresses that the resolver gives for a named host.
|
|
70
|
-
*/
|
|
71
|
-
export declare function planCheck(options: CheckOptions, system: PlanSystem): Result<CheckPlan, readonly string[]>;
|
|
72
|
-
/**
|
|
73
|
-
* A probe of a visit: the DNS query, the ICMP echo requests, the TLS handshake, the HTTP request, the HTTPS request or
|
|
74
|
-
* the MTU search.
|
|
75
|
-
*/
|
|
76
|
-
type NextProbeKind = "dns" | "ping" | "tls" | "http" | "https" | "mtu";
|
|
77
|
-
/** A probe that the next step can start, for one role of the visit. */
|
|
78
|
-
interface NextProbe {
|
|
79
|
-
/** The id of the candidate: the role and the probe, for example `gateway.ping`. */
|
|
80
|
-
readonly id: string;
|
|
81
|
-
readonly role: VisitRole;
|
|
82
|
-
readonly probe: NextProbeKind;
|
|
83
|
-
/** The fact kinds that the probe gives. A TLS handshake and an HTTP request also give the TCP connect before them. */
|
|
84
|
-
readonly kinds: readonly string[];
|
|
85
|
-
/** An approximate time of the probe, in seconds. When two gains are equal, the lower cost comes first. */
|
|
86
|
-
readonly cost: number;
|
|
87
|
-
}
|
|
88
|
-
/** The next step of a check: the instruction in plain words, its information gain, and the features that it observes. */
|
|
89
|
-
interface NextStep {
|
|
90
|
-
/** The id of the probe of the step, for example `gateway.ping`. */
|
|
91
|
-
readonly id: string;
|
|
92
|
-
/** The instruction to the user. */
|
|
93
|
-
readonly step: string;
|
|
94
|
-
/** The expected information gain over the most probable causes, in bits. */
|
|
95
|
-
readonly gain: number;
|
|
96
|
-
/** The features that the step observes and that the evidence does not have. */
|
|
97
|
-
readonly observes: readonly Observable[];
|
|
98
|
-
}
|
|
99
|
-
/** The number of the most probable causes that the report shows, and that the gain of a next step tells apart. */
|
|
100
|
-
export declare const TOP_CAUSES = 3;
|
|
101
|
-
/**
|
|
102
|
-
* The candidates of the next step: each probe of the target and of the reference hosts, and the ping of the gateway.
|
|
103
|
-
* The MTU search of the path to an address is a candidate of the target and of the reference hosts.
|
|
104
|
-
*
|
|
105
|
-
* - The HTTPS request is one candidate. It observes the features of the TCP connect, the TLS handshake and the HTTP
|
|
106
|
-
* answer together, 7 in all. Thus its gain counts what the three stages tell together.
|
|
107
|
-
* - The TLS handshake is a second candidate. It costs less, so it comes first when the HTTP answer adds no gain.
|
|
108
|
-
* - The HTTP request is the candidate of the scheme `http`, and the HTTPS request is the candidate of the scheme `https`.
|
|
109
|
-
*/
|
|
110
|
-
export declare const NEXT_PROBES: readonly NextProbe[];
|
|
111
|
-
/** The instruction to add a reference host. */
|
|
112
|
-
export declare const ADD_REFERENCE = "Add a host that works for you with --reference <host>, for example a large web site.";
|
|
113
|
-
/** The instruction to add the gateway. */
|
|
114
|
-
export declare const ADD_GATEWAY = "Give the address of your router with --gateway <address>.";
|
|
115
|
-
/** This function gives the instruction of a next step in plain words. */
|
|
116
|
-
export declare function stepText(probe: NextProbe, observes: readonly Observable[], plan: CheckPlan): string;
|
|
117
|
-
/**
|
|
118
|
-
* This function gives the next steps of a check, from the largest information gain. The first step is the next step.
|
|
119
|
-
*
|
|
120
|
-
* - A candidate observes the features of its fact kinds that the evidence does not have, with the role of the probe.
|
|
121
|
-
* A feature after a stage that gave another value is not observable: no address follows an answer `nxdomain`.
|
|
122
|
-
* - A probe that cannot give its facts is not a candidate. `addressed` has the roles with an address to probe: an IP
|
|
123
|
-
* address, or an address of a DNS answer.
|
|
124
|
-
* - A step with a gain of `GAIN_RESOLUTION` or less tells nothing, so the list does not have it.
|
|
125
|
-
* - Two probes with the same instruction give one step, with the larger gain. For example, each probe of a reference
|
|
126
|
-
* host that the user did not give has the instruction `ADD_REFERENCE`.
|
|
127
|
-
*/
|
|
128
|
-
export declare function nextSteps(diagnosis: Diagnosis, plan: CheckPlan, addressed: ReadonlySet<VisitRole>): NextStep[];
|
|
129
|
-
/** The format of the JSON report of a check. A change to the shape of `CheckReport` changes the format. */
|
|
130
|
-
export declare const CHECK_FORMAT = "netdiag-check/1";
|
|
131
|
-
/** A fact of a visit, with the role and the host of the step that gave it. */
|
|
132
|
-
interface CheckFact {
|
|
133
|
-
readonly role: VisitRole;
|
|
134
|
-
readonly host: string;
|
|
135
|
-
readonly fact: Fact;
|
|
136
|
-
}
|
|
137
|
-
/** A problem of a visit: a probe that did not end, with the role and the host of the step. */
|
|
138
|
-
interface CheckProblem {
|
|
139
|
-
readonly role: VisitRole;
|
|
140
|
-
readonly host: string;
|
|
141
|
-
readonly problem: string;
|
|
142
|
-
}
|
|
143
|
-
/** The report of a check. `--json` writes this object. */
|
|
144
|
-
interface CheckReport {
|
|
145
|
-
readonly format: typeof CHECK_FORMAT;
|
|
146
|
-
/** The target, as `host` or `host:port`. */
|
|
147
|
-
readonly target: string;
|
|
148
|
-
readonly scheme: Scheme;
|
|
149
|
-
readonly path: string;
|
|
150
|
-
/** The grants of the scope of the check. */
|
|
151
|
-
readonly grants: readonly Grant[];
|
|
152
|
-
/** Each cause, from the most probable. */
|
|
153
|
-
readonly causes: readonly Cause[];
|
|
154
|
-
/** The next step, or `null` when no probe can tell more about the most probable causes. */
|
|
155
|
-
readonly next: NextStep | null;
|
|
156
|
-
/** Each next step with a gain, from the largest gain. The first one is `next`. */
|
|
157
|
-
readonly choices: readonly NextStep[];
|
|
158
|
-
readonly problems: readonly CheckProblem[];
|
|
159
|
-
/** The evidence that the diagnosis used. A fact of the role `target` gives primary evidence. */
|
|
160
|
-
readonly evidence: readonly Evidence[];
|
|
161
|
-
/** The evidence that the diagnosis did not use, with the reason. */
|
|
162
|
-
readonly ignored: Diagnosis["ignored"];
|
|
163
|
-
/** The facts that gave no evidence, with the reason. */
|
|
164
|
-
readonly skipped: readonly Skipped[];
|
|
165
|
-
readonly facts: readonly CheckFact[];
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* This function gives the report of the steps of a visit.
|
|
169
|
-
*
|
|
170
|
-
* - A fact of the role `target` gives primary evidence. A fact of each other role gives reference evidence.
|
|
171
|
-
* - The report finds the facts of the target by their role, not by their position. Thus a first step of the role
|
|
172
|
-
* `local` is not a problem.
|
|
173
|
-
* - The causes come from `diagnose` with `STANDARD_CATALOG`. The next steps come from `nextSteps`.
|
|
174
|
-
*/
|
|
175
|
-
export declare function reportOf(plan: CheckPlan, steps: readonly VisitStep[]): CheckReport;
|
|
176
|
-
/** This function gives a probability as a percent for a person: `<1%` for a probability above 0 that rounds to 0. */
|
|
177
|
-
export declare function percentOf(probability: number): string;
|
|
178
|
-
/**
|
|
179
|
-
* This function gives the role and the host of a step for a person. A step of the role `local` is a passive read of
|
|
180
|
-
* this computer, so its text is `this computer`.
|
|
181
|
-
*/
|
|
182
|
-
export declare function subjectText(role: string, host: string): string;
|
|
183
|
-
/**
|
|
184
|
-
* This function gives the lines of the text report of a check. The lines show the most probable causes with their
|
|
185
|
-
* probabilities and the next step with its gain. They also show the problems of the visit and the count of the evidence.
|
|
186
|
-
*/
|
|
187
|
-
export declare function formatReport(report: CheckReport): string[];
|
|
188
12
|
/** The parts of the computer that a check uses. A test gives its own parts. */
|
|
189
13
|
interface CheckDeps {
|
|
190
14
|
readonly clock: Clock;
|
|
@@ -223,5 +47,5 @@ export declare function createNetdiagCli(options: NetdiagCliOptions): ProcedureC
|
|
|
223
47
|
export declare function packageVersion(): string;
|
|
224
48
|
/** This function operates the command line on this computer, and gives the exit code. */
|
|
225
49
|
export declare function main(argv: readonly string[]): Promise<number>;
|
|
226
|
-
export type
|
|
50
|
+
export { ADD_GATEWAY, ADD_REFERENCE, CHECK_FORMAT, type CheckDeps, type CheckFact, type CheckOptions, type CheckPlan, type CheckProblem, type CheckReport, MAX_REPORT_PROBLEMS, NEXT_PROBES, type NetdiagCliOptions, type NextProbe, type NextProbeKind, type NextStep, type PlanSystem, SCHEMES, type Scheme, TOP_CAUSES, formatReport, isScheme, nextSteps, percentOf, planCheck, readCheckReport, reportOf, stepText, subjectText };
|
|
227
51
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/check.ts","../src/cli.ts"],"mappings":";;;;;;;;;;;;UAYiB;WACN,OAAO;;WAEP,QAAQ;;WAER;;WAEA,MAAM;WACN,SAAS;;;wBAIJ,cAAc;;;;;;wBASR,MAAM,SAAS,cAAc,MAAM,YAAY,QAAQ;;qBCnBhE;;UAGI;;WAEN,QAAQ,SAAS,cAAc,QAAQ,4BAA4B,QAAQ;;WAE3E;;WAEA,QAAQ;;WAER,WAAW;;;wBA0BN,iBAAiB,SAAS,oBAAoB;;wBAwB9C;;wBAOM,KAAK,0BAA0B"}
|
package/build/index.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { a as readCheckReport, c as ADD_GATEWAY, d as TOP_CAUSES, f as nextSteps, h as isScheme, i as percentOf, l as ADD_REFERENCE, m as SCHEMES, n as MAX_REPORT_PROBLEMS, o as reportOf, p as stepText, r as formatReport, s as subjectText, t as CHECK_FORMAT, u as NEXT_PROBES } from "./report-CbppPHXp.js";
|
|
2
|
+
import { a as check, i as packageVersion, n as createNetdiagCli, o as systemDeps, r as main, s as planCheck, t as PROGRAM } from "./cli-CcguQFNo.js";
|
|
3
|
+
export { ADD_GATEWAY, ADD_REFERENCE, CHECK_FORMAT, MAX_REPORT_PROBLEMS, NEXT_PROBES, PROGRAM, SCHEMES, TOP_CAUSES, check, createNetdiagCli, formatReport, isScheme, main, nextSteps, packageVersion, percentOf, planCheck, readCheckReport, reportOf, stepText, subjectText, systemDeps };
|