@fedify/cli 2.4.0-dev.2169 → 2.4.0-dev.2193
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/dist/deno.js +1 -1
- package/dist/docloader.js +4 -3
- package/dist/lookup.js +49 -35
- package/package.json +9 -9
package/dist/deno.js
CHANGED
package/dist/docloader.js
CHANGED
|
@@ -17,8 +17,8 @@ function getDocumentLoaderCachePrefix(userAgent, allowPrivateAddress) {
|
|
|
17
17
|
allowPrivateAddress ? "allow-private" : "deny-private"
|
|
18
18
|
];
|
|
19
19
|
}
|
|
20
|
-
async function getDocumentLoader$1({ userAgent, allowPrivateAddress = false } = {}) {
|
|
21
|
-
const cacheKey = `${userAgent ?? ""}:${allowPrivateAddress}`;
|
|
20
|
+
async function getDocumentLoader$1({ userAgent, allowPrivateAddress = false, timeout } = {}) {
|
|
21
|
+
const cacheKey = `${userAgent ?? ""}:${allowPrivateAddress}:${timeout ?? ""}`;
|
|
22
22
|
if (documentLoaders[cacheKey]) return documentLoaders[cacheKey];
|
|
23
23
|
const kv = await getKvStore();
|
|
24
24
|
return documentLoaders[cacheKey] = kvCache({
|
|
@@ -52,7 +52,8 @@ async function getDocumentLoader$1({ userAgent, allowPrivateAddress = false } =
|
|
|
52
52
|
],
|
|
53
53
|
loader: getDocumentLoader({
|
|
54
54
|
allowPrivateAddress,
|
|
55
|
-
userAgent
|
|
55
|
+
userAgent,
|
|
56
|
+
timeout
|
|
56
57
|
})
|
|
57
58
|
});
|
|
58
59
|
}
|
package/dist/lookup.js
CHANGED
|
@@ -10,7 +10,7 @@ import process from "node:process";
|
|
|
10
10
|
import { message, optionNames, text } from "@optique/core";
|
|
11
11
|
import { printError } from "@optique/run";
|
|
12
12
|
import { createWriteStream } from "node:fs";
|
|
13
|
-
import { UrlError, expandIPv6Address, isValidPublicIPv4Address, isValidPublicIPv6Address } from "@fedify/vocab-runtime";
|
|
13
|
+
import { FetchError, UrlError, expandIPv6Address, isValidPublicIPv4Address, isValidPublicIPv6Address } from "@fedify/vocab-runtime";
|
|
14
14
|
import { generateCryptoKeyPair, getAuthenticatedDocumentLoader, respondWithObject } from "@fedify/fedify";
|
|
15
15
|
import { getLogger } from "@logtape/logtape";
|
|
16
16
|
import ora from "ora";
|
|
@@ -25,12 +25,21 @@ const logger = getLogger([
|
|
|
25
25
|
]);
|
|
26
26
|
var TimeoutError = class extends Error {
|
|
27
27
|
name = "TimeoutError";
|
|
28
|
-
constructor(message) {
|
|
29
|
-
super(message);
|
|
28
|
+
constructor(message, options) {
|
|
29
|
+
super(message, options);
|
|
30
30
|
this.name = "TimeoutError";
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
34
|
+
* The timeout that the built-in document loaders use when `-T`/`--timeout`
|
|
35
|
+
* is not given, in seconds.
|
|
36
|
+
*/
|
|
37
|
+
const DEFAULT_TIMEOUT_SECONDS = 10;
|
|
38
|
+
/**
|
|
39
|
+
* The maximum delay in milliseconds that timers accept.
|
|
40
|
+
*/
|
|
41
|
+
const MAX_TIMEOUT_MS = 2147483647;
|
|
42
|
+
/**
|
|
34
43
|
* Error thrown when a recursive lookup target cannot be fetched.
|
|
35
44
|
*/
|
|
36
45
|
var RecursiveLookupError = class extends Error {
|
|
@@ -140,40 +149,39 @@ async function collectAsyncItems(iterable) {
|
|
|
140
149
|
};
|
|
141
150
|
}
|
|
142
151
|
}
|
|
143
|
-
|
|
144
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Converts the `-T`/`--timeout` option in seconds into the `timeout` option
|
|
154
|
+
* of the built-in document loaders in milliseconds. Zero means timing out
|
|
155
|
+
* immediately, and too long timeouts are clamped to what timers accept.
|
|
156
|
+
* @param timeoutSeconds The timeout in seconds, if given.
|
|
157
|
+
* @returns The timeout in milliseconds, or `undefined` for the default.
|
|
158
|
+
*/
|
|
159
|
+
function toDocumentLoaderTimeout(timeoutSeconds) {
|
|
145
160
|
if (timeoutSeconds == null) return void 0;
|
|
146
|
-
|
|
147
|
-
const timerId = setTimeout(() => {
|
|
148
|
-
controller.abort(new TimeoutError(`Request timed out after ${timeoutSeconds} seconds`));
|
|
149
|
-
}, timeoutSeconds * 1e3);
|
|
150
|
-
signalTimers.set(controller.signal, timerId);
|
|
151
|
-
return controller.signal;
|
|
161
|
+
return Math.min(MAX_TIMEOUT_MS, Math.max(1, Math.ceil(timeoutSeconds * 1e3)));
|
|
152
162
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Checks whether the given error was thrown by a built-in document loader
|
|
165
|
+
* that timed out.
|
|
166
|
+
* @param error The error to check.
|
|
167
|
+
* @returns `true` if the document loader timed out.
|
|
168
|
+
*/
|
|
169
|
+
function isDocumentLoaderTimeoutError(error) {
|
|
170
|
+
return error instanceof FetchError && error.response == null && error.cause instanceof Error && error.cause.name === "TimeoutError";
|
|
160
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Wraps a built-in document loader so that its timeouts are thrown as
|
|
174
|
+
* {@link TimeoutError}s, which the lookup command reports specially.
|
|
175
|
+
*/
|
|
161
176
|
function wrapDocumentLoaderWithTimeout(loader, timeoutSeconds) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
...options,
|
|
167
|
-
signal
|
|
168
|
-
}).catch((error) => {
|
|
169
|
-
if (signal?.aborted) throw signal.reason;
|
|
170
|
-
throw error;
|
|
171
|
-
}).finally(() => clearTimeoutSignal(signal));
|
|
172
|
-
};
|
|
177
|
+
return (url, options) => loader(url, options).catch((error) => {
|
|
178
|
+
if (isDocumentLoaderTimeoutError(error)) throw new TimeoutError(`Request timed out after ${timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS} seconds`, { cause: error });
|
|
179
|
+
throw error;
|
|
180
|
+
});
|
|
173
181
|
}
|
|
174
182
|
function handleTimeoutError(spinner, timeoutSeconds, url) {
|
|
175
183
|
const urlText = url ? ` for: ${colors.red(url)}` : "";
|
|
176
|
-
spinner.fail(`Request timed out after ${timeoutSeconds} seconds${urlText}.`);
|
|
184
|
+
spinner.fail(`Request timed out after ${timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS} seconds${urlText}.`);
|
|
177
185
|
printError(message`Try increasing the timeout with ${optionNames(["-T", "--timeout"])} option or check network connectivity.`);
|
|
178
186
|
}
|
|
179
187
|
function isPrivateAddressError(error) {
|
|
@@ -348,15 +356,18 @@ async function runLookup(command, deps = {}) {
|
|
|
348
356
|
let server = void 0;
|
|
349
357
|
const initialDocumentLoader = wrapDocumentLoaderWithTimeout(await getDocumentLoader$1({
|
|
350
358
|
userAgent: command.userAgent,
|
|
351
|
-
allowPrivateAddress: true
|
|
359
|
+
allowPrivateAddress: true,
|
|
360
|
+
timeout: toDocumentLoaderTimeout(command.timeout)
|
|
352
361
|
}), command.timeout);
|
|
353
362
|
const documentLoader = wrapDocumentLoaderWithTimeout(await getDocumentLoader$1({
|
|
354
363
|
userAgent: command.userAgent,
|
|
355
|
-
allowPrivateAddress: command.allowPrivateAddress
|
|
364
|
+
allowPrivateAddress: command.allowPrivateAddress,
|
|
365
|
+
timeout: toDocumentLoaderTimeout(command.timeout)
|
|
356
366
|
}), command.timeout);
|
|
357
367
|
const contextLoader = wrapDocumentLoaderWithTimeout(await getContextLoader({
|
|
358
368
|
userAgent: command.userAgent,
|
|
359
|
-
allowPrivateAddress: command.allowPrivateAddress
|
|
369
|
+
allowPrivateAddress: command.allowPrivateAddress,
|
|
370
|
+
timeout: toDocumentLoaderTimeout(command.timeout)
|
|
360
371
|
}), command.timeout);
|
|
361
372
|
let authLoader = void 0;
|
|
362
373
|
let initialAuthLoader = void 0;
|
|
@@ -429,6 +440,7 @@ async function runLookup(command, deps = {}) {
|
|
|
429
440
|
authLoader = wrapDocumentLoaderWithTimeout(getAuthenticatedDocumentLoader(authIdentity, {
|
|
430
441
|
allowPrivateAddress: command.allowPrivateAddress,
|
|
431
442
|
userAgent: command.userAgent,
|
|
443
|
+
timeout: toDocumentLoaderTimeout(command.timeout),
|
|
432
444
|
specDeterminer: {
|
|
433
445
|
determineSpec() {
|
|
434
446
|
return firstKnock;
|
|
@@ -439,6 +451,7 @@ async function runLookup(command, deps = {}) {
|
|
|
439
451
|
initialAuthLoader = wrapDocumentLoaderWithTimeout(getAuthenticatedDocumentLoader(authIdentity, {
|
|
440
452
|
allowPrivateAddress: true,
|
|
441
453
|
userAgent: command.userAgent,
|
|
454
|
+
timeout: toDocumentLoaderTimeout(command.timeout),
|
|
442
455
|
specDeterminer: {
|
|
443
456
|
determineSpec() {
|
|
444
457
|
return firstKnock;
|
|
@@ -453,7 +466,8 @@ async function runLookup(command, deps = {}) {
|
|
|
453
466
|
const recursiveLookupDocumentLoader = authLoader ?? documentLoader;
|
|
454
467
|
const recursiveContextLoader = wrapDocumentLoaderWithTimeout(await getContextLoader({
|
|
455
468
|
userAgent: command.userAgent,
|
|
456
|
-
allowPrivateAddress: false
|
|
469
|
+
allowPrivateAddress: false,
|
|
470
|
+
timeout: toDocumentLoaderTimeout(command.timeout)
|
|
457
471
|
}), command.timeout);
|
|
458
472
|
let totalObjects = 0;
|
|
459
473
|
const recurseDepth = command.recurseDepth;
|
|
@@ -747,4 +761,4 @@ async function runLookup(command, deps = {}) {
|
|
|
747
761
|
if (success && command.output) spinner.succeed(`Successfully wrote output to ${colors.green(command.output)}.`);
|
|
748
762
|
}
|
|
749
763
|
//#endregion
|
|
750
|
-
export { RecursiveLookupError, TimeoutError,
|
|
764
|
+
export { RecursiveLookupError, TimeoutError, collectAsyncItems, collectRecursiveObjects, getLookupFailureHint, getPrivateUrlCandidate, getRecursiveTargetId, isDocumentLoaderTimeoutError, runLookup, shouldPrintLookupFailureHint, shouldSuggestSuppressErrorsForLookupFailure, toDocumentLoaderTimeout, toPresentationOrder, wrapDocumentLoaderWithTimeout, writeObjectToStream, writeSeparator };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/cli",
|
|
3
|
-
"version": "2.4.0-dev.
|
|
3
|
+
"version": "2.4.0-dev.2193+402149b5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"README.md",
|
|
@@ -88,14 +88,14 @@
|
|
|
88
88
|
"temporal-polyfill": "^1.0.1",
|
|
89
89
|
"valibot": "^1.4.0",
|
|
90
90
|
"yaml": "^2.9.0",
|
|
91
|
-
"@fedify/fedify": "2.4.0-dev.
|
|
92
|
-
"@fedify/init": "2.4.0-dev.
|
|
93
|
-
"@fedify/relay": "2.4.0-dev.
|
|
94
|
-
"@fedify/sqlite": "2.4.0-dev.
|
|
95
|
-
"@fedify/vocab": "2.4.0-dev.
|
|
96
|
-
"@fedify/vocab
|
|
97
|
-
"@fedify/vocab-runtime": "2.4.0-dev.
|
|
98
|
-
"@fedify/webfinger": "2.4.0-dev.
|
|
91
|
+
"@fedify/fedify": "2.4.0-dev.2193+402149b5",
|
|
92
|
+
"@fedify/init": "2.4.0-dev.2193+402149b5",
|
|
93
|
+
"@fedify/relay": "2.4.0-dev.2193+402149b5",
|
|
94
|
+
"@fedify/sqlite": "2.4.0-dev.2193+402149b5",
|
|
95
|
+
"@fedify/vocab-tools": "2.4.0-dev.2193+402149b5",
|
|
96
|
+
"@fedify/vocab": "2.4.0-dev.2193+402149b5",
|
|
97
|
+
"@fedify/vocab-runtime": "2.4.0-dev.2193+402149b5",
|
|
98
|
+
"@fedify/webfinger": "2.4.0-dev.2193+402149b5"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@types/bun": "^1.2.23",
|