shelving 1.196.3 → 1.197.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.
|
@@ -21,7 +21,11 @@ export interface ClientAPIProviderOptions {
|
|
|
21
21
|
* - Omits `signal` because it's not relevant at the provider level.
|
|
22
22
|
*/
|
|
23
23
|
readonly options?: Omit<RequestOptions, "signal">;
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Timeout in milliseconds before the request is aborted with `TimeoutError`.
|
|
26
|
+
* - Defaults to `20_000` (20 seconds) — chosen to fire before common platform wall-clock caps (Cloudflare Workers ~30s, Vercel/AWS API Gateway ~29s) so the abort propagates as a clean rejection instead of an opaque runtime termination.
|
|
27
|
+
* - Pass `0` to disable the timeout (e.g. for streaming or long-poll endpoints). Raise it for specifically slow endpoints.
|
|
28
|
+
*/
|
|
25
29
|
readonly timeout?: number | undefined;
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
@@ -37,8 +41,8 @@ export declare class ClientAPIProvider<P = unknown, R = unknown> extends APIProv
|
|
|
37
41
|
readonly url: URL;
|
|
38
42
|
/** Default options used for HTTP requests created with `this.getRequest()` and `this.fetch()` */
|
|
39
43
|
readonly options: RequestOptions;
|
|
40
|
-
/** Timeout in milliseconds, or `
|
|
41
|
-
readonly timeout: number
|
|
44
|
+
/** Timeout in milliseconds before the request is aborted, or `0` for no timeout. */
|
|
45
|
+
readonly timeout: number;
|
|
42
46
|
constructor({ url, options, timeout }: ClientAPIProviderOptions);
|
|
43
47
|
renderURL<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>, payload: PP, caller?: AnyCaller): URL;
|
|
44
48
|
getRequest<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>, payload: PP, options?: RequestOptions, caller?: AnyCaller): Request;
|
|
@@ -19,9 +19,9 @@ export class ClientAPIProvider extends APIProvider {
|
|
|
19
19
|
url;
|
|
20
20
|
/** Default options used for HTTP requests created with `this.getRequest()` and `this.fetch()` */
|
|
21
21
|
options;
|
|
22
|
-
/** Timeout in milliseconds, or `
|
|
22
|
+
/** Timeout in milliseconds before the request is aborted, or `0` for no timeout. */
|
|
23
23
|
timeout;
|
|
24
|
-
constructor({ url, options = {}, timeout }) {
|
|
24
|
+
constructor({ url, options = {}, timeout = 20_000 }) {
|
|
25
25
|
super();
|
|
26
26
|
this.url = requireBaseURL(url, ClientAPIProvider);
|
|
27
27
|
this.options = options;
|
|
@@ -18,9 +18,9 @@ export class DebugAPIProvider extends ThroughAPIProvider {
|
|
|
18
18
|
async fetch(request) {
|
|
19
19
|
const url = this.url.toString();
|
|
20
20
|
try {
|
|
21
|
-
console.
|
|
21
|
+
console.debug("→ FETCH", url, await debugFullRequest(request));
|
|
22
22
|
const response = await super.fetch(request);
|
|
23
|
-
console.
|
|
23
|
+
console.debug("← FETCH", url, await debugFullResponse(response));
|
|
24
24
|
return response;
|
|
25
25
|
}
|
|
26
26
|
catch (reason) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NONE } from "../util/constants.js";
|
|
2
2
|
import { FetchStore } from "./FetchStore.js";
|
|
3
|
-
import { Store } from "./Store.js";
|
|
4
|
-
export type PayloadFetchCallback<P, R> = (payload: P, signal: AbortSignal) =>
|
|
3
|
+
import { type AsyncStoreInput, Store } from "./Store.js";
|
|
4
|
+
export type PayloadFetchCallback<P, R> = (payload: P, signal: AbortSignal) => AsyncStoreInput<R>;
|
|
5
5
|
/**
|
|
6
6
|
* Store that fetches its values from a remote source by sending a payload to them.
|
|
7
7
|
*
|
package/util/debug.js
CHANGED
|
@@ -77,8 +77,36 @@ async function _debugFullMessage(head, message) {
|
|
|
77
77
|
const body = await _debugMessageBody(message);
|
|
78
78
|
return `${head}${headers && `\n${headers}`}${body && `\n\n${body}`}`;
|
|
79
79
|
}
|
|
80
|
+
/** Maximum bytes read from a Request/Response body when debugging. Caps memory and prevents hangs on streaming bodies. */
|
|
81
|
+
const _DEBUG_BODY_LIMIT = 64 * 1024;
|
|
80
82
|
async function _debugMessageBody(message) {
|
|
81
|
-
|
|
83
|
+
if (message.bodyUsed)
|
|
84
|
+
return "[body used]";
|
|
85
|
+
const body = message.clone().body;
|
|
86
|
+
if (!body)
|
|
87
|
+
return "";
|
|
88
|
+
const reader = body.getReader();
|
|
89
|
+
const decoder = new TextDecoder();
|
|
90
|
+
let bytes = 0;
|
|
91
|
+
let text = "";
|
|
92
|
+
try {
|
|
93
|
+
while (true) {
|
|
94
|
+
const { done, value } = await reader.read();
|
|
95
|
+
if (done)
|
|
96
|
+
return text + decoder.decode();
|
|
97
|
+
bytes += value.byteLength;
|
|
98
|
+
if (bytes > _DEBUG_BODY_LIMIT) {
|
|
99
|
+
const keep = value.byteLength - (bytes - _DEBUG_BODY_LIMIT);
|
|
100
|
+
text += decoder.decode(value.subarray(0, keep), { stream: true });
|
|
101
|
+
await reader.cancel();
|
|
102
|
+
return `${text}${decoder.decode()}\n[truncated at ${_DEBUG_BODY_LIMIT} bytes]`;
|
|
103
|
+
}
|
|
104
|
+
text += decoder.decode(value, { stream: true });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (reason) {
|
|
108
|
+
return `${text}\n[read failed: ${reason?.message ?? reason}]`;
|
|
109
|
+
}
|
|
82
110
|
}
|
|
83
111
|
/** Debug a `Request` as a string. */
|
|
84
112
|
export function debugRequest(request) {
|