@stll/fetch 0.2.0 → 0.3.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/dist/body-reader.d.ts +0 -2
- package/dist/body-reader.js +2 -3
- package/dist/{index-C-MNDO3-.d.ts → index-pEynxKdA.d.ts} +2 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -5
- package/dist/publisher.d.ts +1 -3
- package/dist/publisher.js +2 -3
- package/dist/{race-abort-wtommv8G.js → race-abort-DhS8oTc3.js} +1 -2
- package/package.json +2 -2
package/dist/body-reader.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/body-reader.d.ts
|
|
2
1
|
declare const BodyByteLimitError_base: import("better-result").TaggedErrorClass<"BodyByteLimitError">;
|
|
3
2
|
export declare class BodyByteLimitError extends BodyByteLimitError_base<{
|
|
4
3
|
message: string;
|
|
@@ -18,5 +17,4 @@ export declare function iterateBodyWithIdleDeadline(response: Response, { idleMs
|
|
|
18
17
|
export declare const readBodyWithIdleDeadline: (response: Response, options: BodyIdleDeadlineOptions) => Promise<Uint8Array>;
|
|
19
18
|
export declare const readBodyTextWithIdleDeadline: (response: Response, options: BodyIdleDeadlineOptions) => Promise<string>;
|
|
20
19
|
export declare const readBodyJsonWithIdleDeadline: (response: Response, options: BodyIdleDeadlineOptions) => Promise<unknown>;
|
|
21
|
-
//#endregion
|
|
22
20
|
export {};
|
package/dist/body-reader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as raceAbort } from "./race-abort-
|
|
1
|
+
import { t as raceAbort } from "./race-abort-DhS8oTc3.js";
|
|
2
2
|
import { TaggedError } from "better-result";
|
|
3
|
-
|
|
3
|
+
// src/body-reader.ts
|
|
4
4
|
var BodyByteLimitError = class extends TaggedError("BodyByteLimitError") {};
|
|
5
5
|
const invalidIdleMs = (idleMs) => {
|
|
6
6
|
if (!Number.isFinite(idleMs) || idleMs < 0 || idleMs > 2147483647) return new DOMException("Invalid body idle deadline duration", "NotSupportedError");
|
|
@@ -74,5 +74,4 @@ const readBodyWithIdleDeadline = async (response, options) => {
|
|
|
74
74
|
};
|
|
75
75
|
const readBodyTextWithIdleDeadline = async (response, options) => new TextDecoder().decode(await readBodyWithIdleDeadline(response, options));
|
|
76
76
|
const readBodyJsonWithIdleDeadline = async (response, options) => JSON.parse(await readBodyTextWithIdleDeadline(response, options));
|
|
77
|
-
//#endregion
|
|
78
77
|
export { BodyByteLimitError, iterateBodyWithIdleDeadline, readBodyJsonWithIdleDeadline, readBodyTextWithIdleDeadline, readBodyWithIdleDeadline };
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
//#region src/connection-failure.d.ts
|
|
2
1
|
declare const isConnectionFailure: (cause: unknown) => boolean;
|
|
3
|
-
//#endregion
|
|
4
|
-
//#region src/index.d.ts
|
|
5
2
|
type FetchTimeout = {
|
|
6
3
|
type: "total";
|
|
7
4
|
ms: number;
|
|
@@ -10,7 +7,8 @@ type FetchTimeout = {
|
|
|
10
7
|
ms: number;
|
|
11
8
|
};
|
|
12
9
|
type TransportRequestInit = RequestInit & {
|
|
13
|
-
|
|
10
|
+
/** `false` turns off the runtime's own idle limit; the signal owns the deadline. */
|
|
11
|
+
timeout?: FetchTimeout | false;
|
|
14
12
|
timeoutMs?: number;
|
|
15
13
|
};
|
|
16
14
|
type Fetcher = (input: string | URL | Request, init?: TransportRequestInit) => Promise<Response>;
|
|
@@ -28,5 +26,4 @@ type FetchWithTimeoutInit = Omit<RequestInit, "signal"> & {
|
|
|
28
26
|
declare const createFetchWithTimeout: (fetcher: Fetcher) => (input: string | URL | Request, init: FetchWithTimeoutInit) => Promise<Response>;
|
|
29
27
|
/** Uses the current global fetch implementation at request time. */
|
|
30
28
|
declare const fetchWithTimeout: (input: string | URL | Request, init: FetchWithTimeoutInit) => Promise<Response>;
|
|
31
|
-
//#endregion
|
|
32
29
|
export { createFetchWithTimeout as a, TransportRequestInit as i, FetchWithTimeoutInit as n, fetchWithTimeout as o, Fetcher as r, isConnectionFailure as s, FetchTimeout as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as createFetchWithTimeout, i as TransportRequestInit, n as FetchWithTimeoutInit, o as fetchWithTimeout, r as Fetcher, s as isConnectionFailure, t as FetchTimeout } from "./index-
|
|
1
|
+
import { a as createFetchWithTimeout, i as TransportRequestInit, n as FetchWithTimeoutInit, o as fetchWithTimeout, r as Fetcher, s as isConnectionFailure, t as FetchTimeout } from "./index-pEynxKdA.js";
|
|
2
2
|
export { FetchTimeout, FetchWithTimeoutInit, Fetcher, TransportRequestInit, createFetchWithTimeout, fetchWithTimeout, isConnectionFailure };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/connection-failure.ts
|
|
2
2
|
const CONNECTION_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
3
3
|
"ConnectionRefused",
|
|
4
4
|
"FailedToOpenSocket",
|
|
@@ -48,8 +48,7 @@ const isConnectionFailure = (cause) => {
|
|
|
48
48
|
if (codes.length > 0) return codes.some((code) => CONNECTION_ERROR_CODES.has(code) || code.startsWith("ERR_SSL_") || code.startsWith("ERR_TLS_"));
|
|
49
49
|
return messages.some((message) => /^(?:Unable to connect|Failed to fetch|fetch failed|NetworkError|Load failed|TLS handshake failed|DNS lookup failed)/iu.test(message));
|
|
50
50
|
};
|
|
51
|
-
|
|
52
|
-
//#region src/index.ts
|
|
51
|
+
// src/index.ts
|
|
53
52
|
const executeFetchWithTimeout = async (fetcher, input, { timeout, timeoutMs, signal, ...init }) => {
|
|
54
53
|
const callerSignals = [signal, input instanceof Request ? input.signal : void 0].filter((candidate) => candidate !== void 0);
|
|
55
54
|
const activeFetcher = fetcher ?? globalThis.fetch;
|
|
@@ -58,7 +57,7 @@ const executeFetchWithTimeout = async (fetcher, input, { timeout, timeoutMs, sig
|
|
|
58
57
|
if (timeout === void 0 || timeout.type === "total") return await activeFetcher(input, {
|
|
59
58
|
...init,
|
|
60
59
|
signal: AbortSignal.any([...callerSignals, AbortSignal.timeout(duration)]),
|
|
61
|
-
|
|
60
|
+
timeout: false,
|
|
62
61
|
timeoutMs: duration
|
|
63
62
|
});
|
|
64
63
|
const controller = new AbortController();
|
|
@@ -86,5 +85,4 @@ const executeFetchWithTimeout = async (fetcher, input, { timeout, timeoutMs, sig
|
|
|
86
85
|
const createFetchWithTimeout = (fetcher) => async (input, init) => await executeFetchWithTimeout(fetcher, input, init);
|
|
87
86
|
/** Uses the current global fetch implementation at request time. */
|
|
88
87
|
const fetchWithTimeout = async (input, init) => await executeFetchWithTimeout(void 0, input, init);
|
|
89
|
-
//#endregion
|
|
90
88
|
export { createFetchWithTimeout, fetchWithTimeout, isConnectionFailure };
|
package/dist/publisher.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Result } from "better-result";
|
|
2
|
-
import { i as TransportRequestInit } from "./index-
|
|
3
|
-
//#region src/publisher.d.ts
|
|
2
|
+
import { i as TransportRequestInit } from "./index-pEynxKdA.js";
|
|
4
3
|
export type PublisherPolicy = {
|
|
5
4
|
type: "obey";
|
|
6
5
|
} | {
|
|
@@ -121,5 +120,4 @@ type ReadBoundedBodyOptions = {
|
|
|
121
120
|
};
|
|
122
121
|
export declare const readBoundedBody: (response: Response, { maxBytes, signal }: ReadBoundedBodyOptions) => Promise<Result<Uint8Array, PublisherBodyLimitError>>;
|
|
123
122
|
export declare const createPolitePublisherFetch: <Target extends PublisherTarget>({ validateTarget, fetcher, clock, robotsTtlMs, robotsRetryMs, robotsLoadTimeoutMs, defaultMinimumIntervalMs, onTelemetry }: PublisherFetcherOptions<Target>) => (input: string | URL, options?: PublisherFetchOptions) => Promise<Result<PublisherFetchResult, PublisherPolicyError>>;
|
|
124
|
-
//#endregion
|
|
125
123
|
export {};
|
package/dist/publisher.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as raceAbort } from "./race-abort-
|
|
1
|
+
import { t as raceAbort } from "./race-abort-DhS8oTc3.js";
|
|
2
2
|
import { Result, TaggedError } from "better-result";
|
|
3
|
-
|
|
3
|
+
// src/publisher.ts
|
|
4
4
|
const ROBOTS_MAX_BYTES = 524288;
|
|
5
5
|
const ROBOTS_TTL_MS = 36e5;
|
|
6
6
|
const ROBOTS_RETRY_MS = 6e4;
|
|
@@ -654,5 +654,4 @@ const createPolitePublisherFetch = ({ validateTarget, fetcher, clock = {
|
|
|
654
654
|
};
|
|
655
655
|
return async (input, options = {}) => await walkPublisherRedirects(input, options, bindPublisherRuntimeToAbort(runtime, options.init?.signal ?? void 0));
|
|
656
656
|
};
|
|
657
|
-
//#endregion
|
|
658
657
|
export { AgentExcludedError, CrawlDelayUnsupportedError, PublisherBodyLimitError, PublisherBodyNotReplayableError, PublisherBypassUnauditedError, PublisherRedirectLimitError, PublisherRequestAbortedError, PublisherTargetRefusedError, RobotsDisallowedError, RobotsUnavailableError, createPolitePublisherFetch, evaluatePublisherRobots, readBoundedBody };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/race-abort.ts
|
|
2
2
|
const abortReason = (signal) => signal.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
3
3
|
const raceAbort = async (work, signal) => {
|
|
4
4
|
if (signal === void 0) return await work;
|
|
@@ -12,5 +12,4 @@ const raceAbort = async (work, signal) => {
|
|
|
12
12
|
signal.removeEventListener("abort", onAbort);
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
-
//#endregion
|
|
16
15
|
export { raceAbort as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stll/fetch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Fetch with mandatory total or header timeouts, idle-bounded body reads, connection-failure classification, and a robots-aware polite publisher fetch",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"abort",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@stll/typescript-config": "0.0.0",
|
|
62
62
|
"bun-types": "1.4.4",
|
|
63
63
|
"fast-check": "^4.10.2",
|
|
64
|
-
"tsdown": "0.23.
|
|
64
|
+
"tsdown": "0.23.4"
|
|
65
65
|
},
|
|
66
66
|
"main": "./dist/index.js",
|
|
67
67
|
"types": "./dist/index.d.ts"
|