snapreq 0.0.8 → 0.0.10
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 +8 -5
- package/build/capabilities.d.ts +17 -17
- package/build/capabilities.d.ts.map +1 -1
- package/build/control.d.ts +12 -0
- package/build/control.d.ts.map +1 -0
- package/build/control.js +27 -0
- package/build/errors.d.ts +16 -16
- package/build/errors.d.ts.map +1 -1
- package/build/headers.d.ts +6 -6
- package/build/headers.d.ts.map +1 -1
- package/build/request.d.ts +15 -15
- package/build/request.d.ts.map +1 -1
- package/build/response.d.ts +27 -17
- package/build/response.d.ts.map +1 -1
- package/build/response.js +26 -2
- package/build/retry.d.ts +38 -37
- package/build/retry.d.ts.map +1 -1
- package/build/retry.js +40 -34
- package/build/snap-req.d.ts +116 -153
- package/build/snap-req.d.ts.map +1 -1
- package/build/snap-req.js +57 -102
- package/build/transports/fetch-transport.d.ts +10 -4
- package/build/transports/fetch-transport.d.ts.map +1 -1
- package/build/transports/fetch-transport.js +58 -12
- package/build/transports/fetch.d.ts.map +1 -1
- package/build/transports/node-transport.d.ts +23 -22
- package/build/transports/node-transport.d.ts.map +1 -1
- package/build/transports/node-transport.js +45 -10
- package/build/transports/proxy-bounce-transport.d.ts +4 -4
- package/build/transports/proxy-bounce-transport.d.ts.map +1 -1
- package/build/transports/select.d.ts +21 -21
- package/build/transports/select.d.ts.map +1 -1
- package/build/transports/xhr-transport.d.ts +2 -2
- package/build/transports/xhr-transport.d.ts.map +1 -1
- package/build/transports/xhr.d.ts.map +1 -1
- package/build/websocket/websocket-channel.d.ts +33 -22
- package/build/websocket/websocket-channel.d.ts.map +1 -1
- package/build/websocket/websocket-channel.js +27 -11
- package/build/websocket/websocket-client.d.ts +136 -65
- package/build/websocket/websocket-client.d.ts.map +1 -1
- package/build/websocket/websocket-client.js +221 -66
- package/build/websocket/websocket-connection.d.ts +19 -16
- package/build/websocket/websocket-connection.d.ts.map +1 -1
- package/build/websocket/websocket-connection.js +11 -3
- package/build/websocket.d.ts.map +1 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ new SnapReq({
|
|
|
76
76
|
|
|
77
77
|
### Timeouts
|
|
78
78
|
|
|
79
|
-
Set `timeoutMs` on the client or a single request to abort stalled requests. The timeout covers
|
|
79
|
+
Set `timeoutMs` on the client or a single request to abort stalled requests. The timeout covers one request attempt, including response headers and body reads through `json()`, `text()`, `bytes()`, `buffer()`, or `stream()`. A timed-out request rejects with `SnapReqTimeoutError`; caller `signal` cancellation rejects with `SnapReqAbortError`. Both controls cooperatively abort the active transport and interrupt retry waits without starting another attempt.
|
|
80
80
|
|
|
81
81
|
```js
|
|
82
82
|
const client = new SnapReq({baseUrl: "https://api.example.com", timeoutMs: 120000})
|
|
@@ -147,21 +147,24 @@ import SnapReqWebSocketClient from "snapreq/websocket"
|
|
|
147
147
|
|
|
148
148
|
const client = new SnapReqWebSocketClient({url: "wss://example.com/websocket"})
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
const controller = new AbortController()
|
|
151
|
+
await client.connect({timeoutMs: 5000, signal: controller.signal})
|
|
151
152
|
|
|
152
153
|
// Request/response over the socket
|
|
153
|
-
const response = await client.post("/things", {name: "thing"})
|
|
154
|
+
const response = await client.post("/things", {name: "thing"}, {timeoutMs: 5000, signal: controller.signal})
|
|
154
155
|
response.json()
|
|
155
156
|
|
|
156
157
|
// Channel subscription
|
|
157
|
-
const unsubscribe = await client.subscribeAndWait("updates", {}, (payload) => console.log(payload))
|
|
158
|
+
const unsubscribe = await client.subscribeAndWait("updates", {timeoutMs: 5000, signal: controller.signal}, (payload) => console.log(payload))
|
|
158
159
|
|
|
159
160
|
// 1:1 connection
|
|
160
|
-
const connection = client.openConnection("ChatConnection", {onMessage: (body) => console.log(body)})
|
|
161
|
+
const connection = client.openConnection("ChatConnection", {timeoutMs: 5000, signal: controller.signal, onMessage: (body) => console.log(body)})
|
|
161
162
|
await connection.ready
|
|
162
163
|
connection.sendMessage({text: "hi"})
|
|
163
164
|
```
|
|
164
165
|
|
|
166
|
+
`timeoutMs` and `signal` are also accepted by `get`, `request`, `subscribe`, `subscribeChannel`, and `waitForReady`. WebSocket timeouts intentionally reject with Awaitery's `TimeoutError`, while WebSocket cancellation rejects with the exact `signal.reason`; unlike HTTP operations, these errors are not mapped to SnapReq error classes. A failed connect deadline closes only a socket created solely for that operation; a shared in-flight socket remains alive for other connect-dependent operations. Request and readiness failures remove only their own pending entry or handle.
|
|
167
|
+
|
|
165
168
|
Optional adapters: `networkMonitor` (gate reconnects on online state), `sessionStore` (persist the session id across reloads) and `deserialize` (a `(value) => value` transform applied inside `response.json()` so an app can re-hydrate its own wire format).
|
|
166
169
|
|
|
167
170
|
## License
|
package/build/capabilities.d.ts
CHANGED
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {object} TransportCapabilities
|
|
3
|
-
* @property {boolean} unixSocket - Connect over a Unix domain socket.
|
|
4
|
-
* @property {boolean} tlsClientCert - Present a client certificate / custom CA for TLS.
|
|
5
|
-
* @property {boolean} requestCompression - Compress the request body (gzip/deflate/br/zstd).
|
|
6
|
-
* @property {boolean} responseStreaming - Expose the response body as a stream before it is fully read.
|
|
7
|
-
* @property {boolean} requestStreaming - Send a streamed (async-iterable) request body.
|
|
8
|
-
* @property {boolean} keepAlive - Reuse connections across requests (HTTP keep-alive).
|
|
9
|
-
* @property {boolean} abort - Cancel an in-flight request via an `AbortSignal`.
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Builds a fully-populated capability object so callers can read every flag
|
|
13
|
-
* without undefined checks.
|
|
14
|
-
* @param {Partial<TransportCapabilities>} overrides - Capabilities the transport supports.
|
|
15
|
-
* @returns {TransportCapabilities} - Complete capability flags.
|
|
16
|
-
*/
|
|
17
|
-
export function buildCapabilities(overrides: Partial<TransportCapabilities>): TransportCapabilities;
|
|
18
1
|
export type TransportCapabilities = {
|
|
19
2
|
/**
|
|
20
3
|
* - Connect over a Unix domain socket.
|
|
@@ -45,4 +28,21 @@ export type TransportCapabilities = {
|
|
|
45
28
|
*/
|
|
46
29
|
abort: boolean;
|
|
47
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* @typedef {object} TransportCapabilities
|
|
33
|
+
* @property {boolean} unixSocket - Connect over a Unix domain socket.
|
|
34
|
+
* @property {boolean} tlsClientCert - Present a client certificate / custom CA for TLS.
|
|
35
|
+
* @property {boolean} requestCompression - Compress the request body (gzip/deflate/br/zstd).
|
|
36
|
+
* @property {boolean} responseStreaming - Expose the response body as a stream before it is fully read.
|
|
37
|
+
* @property {boolean} requestStreaming - Send a streamed (async-iterable) request body.
|
|
38
|
+
* @property {boolean} keepAlive - Reuse connections across requests (HTTP keep-alive).
|
|
39
|
+
* @property {boolean} abort - Cancel an in-flight request via an `AbortSignal`.
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* Builds a fully-populated capability object so callers can read every flag
|
|
43
|
+
* without undefined checks.
|
|
44
|
+
* @param {Partial<TransportCapabilities>} overrides - Capabilities the transport supports.
|
|
45
|
+
* @returns {TransportCapabilities} - Complete capability flags.
|
|
46
|
+
*/
|
|
47
|
+
export declare function buildCapabilities(overrides: Partial<TransportCapabilities>): TransportCapabilities;
|
|
48
48
|
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../src/capabilities.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../src/capabilities.js"],"names":[],"mappings":"AAGG,YAAkB,qBAAqB,GACvC;;;;IAAoB,UAAU,EAAnB,OAAO,CAClB;;;;IAAoB,aAAa,EAAtB,OAAO,CAClB;;;;IAAoB,kBAAkB,EAA3B,OAAO,CAClB;;;;IAAoB,iBAAiB,EAA1B,OAAO,CAClB;;;;IAAoB,gBAAgB,EAAzB,OAAO,CAClB;;;;IAAoB,SAAS,EAAlB,OAAO,CAClB;;;;IAAoB,KAAK,EAAd,OAAO,CACpB;CAAA,CAAA;AATD;;;;;;;;;GASG;AAEH;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAHhC,OAAO,CAAC,qBAAqB,CAGG,GAF9B,qBAAqB,CAajC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs asynchronous work with optional cooperative deadline/cancellation.
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {{timeoutMs?: number, signal?: AbortSignal}} options - Operation controls.
|
|
5
|
+
* @param {(signal: AbortSignal | undefined) => T | Promise<T>} callback - Controlled work.
|
|
6
|
+
* @returns {Promise<T>} - Callback result.
|
|
7
|
+
*/
|
|
8
|
+
export declare function runControlled<T>({ timeoutMs, signal }: {
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}, callback: (signal: AbortSignal | undefined) => T | Promise<T>): Promise<T>;
|
|
12
|
+
//# sourceMappingURL=control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../src/control.js"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,wBAAsB,aAAa,CALtB,CAAC,EAKsB,EAAC,SAAS,EAAE,MAAM,EAAC,EAJ5C;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAIG,EAAE,QAAQ,EAHtD,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAGI,GAFpD,OAAO,CAAC,CAAC,CAAC,CAsBtB"}
|
package/build/control.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import timeout from "awaitery/build/timeout.js";
|
|
3
|
+
/**
|
|
4
|
+
* Runs asynchronous work with optional cooperative deadline/cancellation.
|
|
5
|
+
* @template T
|
|
6
|
+
* @param {{timeoutMs?: number, signal?: AbortSignal}} options - Operation controls.
|
|
7
|
+
* @param {(signal: AbortSignal | undefined) => T | Promise<T>} callback - Controlled work.
|
|
8
|
+
* @returns {Promise<T>} - Callback result.
|
|
9
|
+
*/
|
|
10
|
+
export async function runControlled({ timeoutMs, signal }, callback) {
|
|
11
|
+
if (timeoutMs !== undefined && timeoutMs > 0) {
|
|
12
|
+
return await timeout({ timeout: timeoutMs, signal }, ({ control }) => callback(control.signal));
|
|
13
|
+
}
|
|
14
|
+
if (signal) {
|
|
15
|
+
signal.throwIfAborted();
|
|
16
|
+
return await new Promise((resolve, reject) => {
|
|
17
|
+
const onAbort = () => reject(signal.reason);
|
|
18
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
19
|
+
Promise.resolve()
|
|
20
|
+
.then(() => callback(signal))
|
|
21
|
+
.then(resolve, reject)
|
|
22
|
+
.finally(() => signal.removeEventListener("abort", onAbort));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return await callback(undefined);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJvbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9jb250cm9sLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLFlBQVk7QUFFWixPQUFPLE9BQU8sTUFBTSwyQkFBMkIsQ0FBQTtBQUUvQzs7Ozs7O0dBTUc7QUFDSCxNQUFNLENBQUMsS0FBSyxVQUFVLGFBQWEsQ0FBQyxFQUFDLFNBQVMsRUFBRSxNQUFNLEVBQUMsRUFBRSxRQUFRO0lBQy9ELElBQUksU0FBUyxLQUFLLFNBQVMsSUFBSSxTQUFTLEdBQUcsQ0FBQyxFQUFFLENBQUM7UUFDN0MsT0FBTyxNQUFNLE9BQU8sQ0FBQyxFQUFDLE9BQU8sRUFBRSxTQUFTLEVBQUUsTUFBTSxFQUFDLEVBQUUsQ0FBQyxFQUFDLE9BQU8sRUFBQyxFQUFFLEVBQUUsQ0FBQyxRQUFRLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUE7SUFDN0YsQ0FBQztJQUVELElBQUksTUFBTSxFQUFFLENBQUM7UUFDWCxNQUFNLENBQUMsY0FBYyxFQUFFLENBQUE7UUFFdkIsT0FBTyxNQUFNLElBQUksT0FBTyxDQUFDLENBQUMsT0FBTyxFQUFFLE1BQU0sRUFBRSxFQUFFO1lBQzNDLE1BQU0sT0FBTyxHQUFHLEdBQUcsRUFBRSxDQUFDLE1BQU0sQ0FBQyxNQUFNLENBQUMsTUFBTSxDQUFDLENBQUE7WUFDM0MsTUFBTSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sRUFBRSxPQUFPLEVBQUUsRUFBQyxJQUFJLEVBQUUsSUFBSSxFQUFDLENBQUMsQ0FBQTtZQUV2RCxPQUFPLENBQUMsT0FBTyxFQUFFO2lCQUNkLElBQUksQ0FBQyxHQUFHLEVBQUUsQ0FBQyxRQUFRLENBQUMsTUFBTSxDQUFDLENBQUM7aUJBQzVCLElBQUksQ0FBQyxPQUFPLEVBQUUsTUFBTSxDQUFDO2lCQUNyQixPQUFPLENBQUMsR0FBRyxFQUFFLENBQUMsTUFBTSxDQUFDLG1CQUFtQixDQUFDLE9BQU8sRUFBRSxPQUFPLENBQUMsQ0FBQyxDQUFBO1FBQ2hFLENBQUMsQ0FBQyxDQUFBO0lBQ0osQ0FBQztJQUVELE9BQU8sTUFBTSxRQUFRLENBQUMsU0FBUyxDQUFDLENBQUE7QUFDbEMsQ0FBQyJ9
|
package/build/errors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Base class for every error thrown by snapreq. */
|
|
2
|
-
export class SnapReqError extends Error {
|
|
2
|
+
export declare class SnapReqError extends Error {
|
|
3
3
|
/** @param {string} message - Human readable description. */
|
|
4
4
|
constructor(message: string);
|
|
5
5
|
}
|
|
@@ -9,7 +9,13 @@ export class SnapReqError extends Error {
|
|
|
9
9
|
* the high-level helpers). Carries enough metadata to build a friendly message
|
|
10
10
|
* without re-reading the response.
|
|
11
11
|
*/
|
|
12
|
-
export class SnapReqHttpError extends SnapReqError {
|
|
12
|
+
export declare class SnapReqHttpError extends SnapReqError {
|
|
13
|
+
method: string;
|
|
14
|
+
url: string;
|
|
15
|
+
status: number;
|
|
16
|
+
statusText: string;
|
|
17
|
+
responseText: string;
|
|
18
|
+
response: import("./response.js").default;
|
|
13
19
|
/**
|
|
14
20
|
* @param {object} options - Error metadata.
|
|
15
21
|
* @param {string} options.message - Human readable description.
|
|
@@ -29,12 +35,6 @@ export class SnapReqHttpError extends SnapReqError {
|
|
|
29
35
|
responseText?: string;
|
|
30
36
|
response?: import("./response.js").default;
|
|
31
37
|
});
|
|
32
|
-
method: string;
|
|
33
|
-
url: string;
|
|
34
|
-
status: number;
|
|
35
|
-
statusText: string;
|
|
36
|
-
responseText: string;
|
|
37
|
-
response: import("./response.js").default;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* Thrown when a request asks for a capability the active transport cannot
|
|
@@ -42,7 +42,9 @@ export class SnapReqHttpError extends SnapReqError {
|
|
|
42
42
|
* compression in a browser). The API stays identical across platforms; this
|
|
43
43
|
* error is how snapreq tells you a specific feature had to be left out.
|
|
44
44
|
*/
|
|
45
|
-
export class SnapReqUnsupportedFeatureError extends SnapReqError {
|
|
45
|
+
export declare class SnapReqUnsupportedFeatureError extends SnapReqError {
|
|
46
|
+
feature: string;
|
|
47
|
+
transport: string;
|
|
46
48
|
/**
|
|
47
49
|
* @param {object} options - Error metadata.
|
|
48
50
|
* @param {string} options.feature - The capability that is not supported.
|
|
@@ -54,16 +56,17 @@ export class SnapReqUnsupportedFeatureError extends SnapReqError {
|
|
|
54
56
|
transport: string;
|
|
55
57
|
detail?: string;
|
|
56
58
|
});
|
|
57
|
-
feature: string;
|
|
58
|
-
transport: string;
|
|
59
59
|
}
|
|
60
60
|
/** Thrown when a request is aborted via an `AbortSignal`. */
|
|
61
|
-
export class SnapReqAbortError extends SnapReqError {
|
|
61
|
+
export declare class SnapReqAbortError extends SnapReqError {
|
|
62
62
|
/** @param {string} [message] - Human readable description. */
|
|
63
63
|
constructor(message?: string);
|
|
64
64
|
}
|
|
65
65
|
/** Thrown when a request exceeds its configured timeout. */
|
|
66
|
-
export class SnapReqTimeoutError extends SnapReqError {
|
|
66
|
+
export declare class SnapReqTimeoutError extends SnapReqError {
|
|
67
|
+
method: string;
|
|
68
|
+
url: string;
|
|
69
|
+
timeoutMs: number;
|
|
67
70
|
/**
|
|
68
71
|
* @param {object} options - Error metadata.
|
|
69
72
|
* @param {string} options.method - HTTP method used for the request.
|
|
@@ -75,8 +78,5 @@ export class SnapReqTimeoutError extends SnapReqError {
|
|
|
75
78
|
url: string;
|
|
76
79
|
timeoutMs: number;
|
|
77
80
|
});
|
|
78
|
-
method: string;
|
|
79
|
-
url: string;
|
|
80
|
-
timeoutMs: number;
|
|
81
81
|
}
|
|
82
82
|
//# sourceMappingURL=errors.d.ts.map
|
package/build/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.js"],"names":[],"mappings":"AAEA,oDAAoD;AACpD;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.js"],"names":[],"mappings":"AAEA,oDAAoD;AACpD,qBAAa,YAAa,SAAQ,KAAK;IACrC,4DAA4D;IAC5D,YAAY,OAAO,EADP,MACO,EAGlB;CACF;AAED;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,YAAY;IAczC,MAAM;IACN,GAAG;IACH,MAAM;IACN,UAAU;IACV,YAAY;IACZ,QAAQ;IAlBf;;;;;;;;;OASG;IACH,YAAY,EAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAC,EAR3E;QAAwB,OAAO,EAAvB,MAAM,CACd;QAAwB,MAAM,EAAtB,MAAM,CACd;QAAwB,GAAG,EAAnB,MAAM,CACd;QAAwB,MAAM,EAAtB,MAAM,CACd;QAAyB,UAAU,AAAnC,CACA,EADQ,MAAM,CACd;QAAyB,YAAY,AAArC,CACA,EADQ,MAAM,CACd;QAAkD,QAAQ,AAA1D,CACF,EADU,OAAO,eAAe,EAAE,OAAO,CACzC;KAC6E,EAS7E;CACF;AAED;;;;;GAKG;AACH,qBAAa,8BAA+B,SAAQ,YAAY;IAUvD,OAAO;IACP,SAAS;IAVhB;;;;;OAKG;IACH,YAAY,EAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAC,EAJrC;QAAwB,OAAO,EAAvB,MAAM,CACd;QAAwB,SAAS,EAAzB,MAAM,CACd;QAAyB,MAAM,AAA/B,CACF,EADU,MAAM,CAChB;KACuC,EAKvC;CACF;AAED,6DAA6D;AAC7D,qBAAa,iBAAkB,SAAQ,YAAY;IACjD,8DAA8D;IAC9D,YAAY,OAAO,AADf,CAAwD,EAAhD,MAC4B,EAGvC;CACF;AAED,4DAA4D;AAC5D,qBAAa,mBAAoB,SAAQ,YAAY;IAU5C,MAAM;IACN,GAAG;IACH,SAAS;IAXhB;;;;;OAKG;IACH,YAAY,EAAC,MAAM,EAAE,GAAG,EAAE,SAAS,EAAC,EAJjC;QAAwB,MAAM,EAAtB,MAAM,CACd;QAAwB,GAAG,EAAnB,MAAM,CACd;QAAwB,SAAS,EAAzB,MAAM,CAChB;KACmC,EAMnC;CACF"}
|
package/build/headers.d.ts
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
* Node's header handling. Header values are always stored as strings.
|
|
5
5
|
*/
|
|
6
6
|
export default class SnapReqHeaders {
|
|
7
|
-
/**
|
|
8
|
-
* @param {Record<string, string | number | string[]> | SnapReqHeaders | Iterable<[string, string]>} [init] - Initial headers.
|
|
9
|
-
*/
|
|
10
|
-
constructor(init?: Record<string, string | number | string[]> | SnapReqHeaders | Iterable<[string, string]>);
|
|
11
7
|
/** @type {Map<string, {name: string, value: string}>} - Keyed by lower-cased name. */
|
|
12
8
|
_map: Map<string, {
|
|
13
9
|
name: string;
|
|
14
10
|
value: string;
|
|
15
11
|
}>;
|
|
12
|
+
/**
|
|
13
|
+
* @param {Record<string, string | number | string[]> | SnapReqHeaders | Iterable<[string, string]>} [init] - Initial headers.
|
|
14
|
+
*/
|
|
15
|
+
constructor(init?: Record<string, string | number | string[]> | SnapReqHeaders | Iterable<[string, string]>);
|
|
16
16
|
/**
|
|
17
17
|
* @param {string} name - Header name (case-insensitive).
|
|
18
18
|
* @param {string | number} value - Header value.
|
|
@@ -39,6 +39,8 @@ export default class SnapReqHeaders {
|
|
|
39
39
|
* @returns {IterableIterator<[string, string]>} - Name/value pairs preserving original casing.
|
|
40
40
|
*/
|
|
41
41
|
entries(): IterableIterator<[string, string]>;
|
|
42
|
+
/** @returns {IterableIterator<[string, string]>} - Header entries for structural copying. */
|
|
43
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
42
44
|
/** @returns {[string, string][]} - Name/value pairs preserving original casing. */
|
|
43
45
|
toArray(): [string, string][];
|
|
44
46
|
/**
|
|
@@ -47,7 +49,5 @@ export default class SnapReqHeaders {
|
|
|
47
49
|
* @returns {Record<string, string>} - Header object.
|
|
48
50
|
*/
|
|
49
51
|
toObject(): Record<string, string>;
|
|
50
|
-
/** @returns {IterableIterator<[string, string]>} - Header entries for structural copying. */
|
|
51
|
-
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
52
52
|
}
|
|
53
53
|
//# sourceMappingURL=headers.d.ts.map
|
package/build/headers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../src/headers.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH;
|
|
1
|
+
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../src/headers.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,cAAc;IAK/B,sFAAsF;IACjF,IAAI,EADE,GAAG,CAAC,MAAM,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAC;IAJvD;;OAEG;IACH,YAAY,IAAI,AAFb,CACF,EADU,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,cAAc,GAAG,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAElF,EAmBf;IAED;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAJG,MAIH,EAAE,KAAK,EAHJ,MAAM,GAAG,MAGL,GAFF,IAAI,CAIhB;IAED;;;OAGG;IACH,GAAG,CAAC,IAAI,EAHG,MAGH,GAFK,MAAM,GAAG,IAAI,CAIzB;IAED;;;OAGG;IACH,GAAG,CAAC,IAAI,EAHG,MAGH,GAFK,OAAO,CAInB;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,EAHA,MAGA,GAFE,IAAI,CAIhB;IAED;;;OAGG;IACF,OAAO,IAFK,gBAAgB,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAI9C;IAED,6FAA6F;IAC7F,CAAC,MAAM,CAAC,QAAQ,CAAC,IADH,gBAAgB,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAG/C;IAED,mFAAmF;IACnF,OAAO,IADO,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAG/B;IAED;;;;OAIG;IACH,QAAQ,IAFK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASlC;CACF"}
|
package/build/request.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
import SnapReqHeaders from "./headers.js";
|
|
2
|
+
export type CompressionEncoding = "identity" | "gzip" | "deflate" | "br" | "zstd";
|
|
3
|
+
export type NormalizedBody = {
|
|
4
|
+
/**
|
|
5
|
+
* - Shape of the body payload.
|
|
6
|
+
*/
|
|
7
|
+
kind: "none" | "text" | "bytes" | "stream";
|
|
8
|
+
/**
|
|
9
|
+
* - The payload itself.
|
|
10
|
+
*/
|
|
11
|
+
value: string | Uint8Array | AsyncIterable<Uint8Array> | null;
|
|
12
|
+
};
|
|
1
13
|
/**
|
|
2
14
|
* Joins a base URL and a path and appends query parameters. `path` may be a
|
|
3
15
|
* fully-qualified URL, in which case the base is ignored.
|
|
@@ -6,13 +18,13 @@
|
|
|
6
18
|
* @param {Record<string, string | number | boolean | null | undefined> | undefined} query - Query parameters.
|
|
7
19
|
* @returns {string} - Resolved absolute URL.
|
|
8
20
|
*/
|
|
9
|
-
export function buildUrl(baseUrl: string | undefined, path: string, query: Record<string, string | number | boolean | null | undefined> | undefined): string;
|
|
21
|
+
export declare function buildUrl(baseUrl: string | undefined, path: string, query: Record<string, string | number | boolean | null | undefined> | undefined): string;
|
|
10
22
|
/**
|
|
11
23
|
* Determines whether a value should be sent as a streamed request body.
|
|
12
24
|
* @param {unknown} body - Candidate body value.
|
|
13
25
|
* @returns {boolean} - Whether the body is a stream.
|
|
14
26
|
*/
|
|
15
|
-
export function isStreamBody(body: unknown): boolean;
|
|
27
|
+
export declare function isStreamBody(body: unknown): boolean;
|
|
16
28
|
/**
|
|
17
29
|
* Normalizes a user-supplied body into one of a small set of shapes and applies
|
|
18
30
|
* a default `Content-Type` header when the caller did not set one.
|
|
@@ -20,17 +32,5 @@ export function isStreamBody(body: unknown): boolean;
|
|
|
20
32
|
* @param {SnapReqHeaders} headers - Headers to receive a default `Content-Type`.
|
|
21
33
|
* @returns {NormalizedBody} - Normalized body descriptor.
|
|
22
34
|
*/
|
|
23
|
-
export function normalizeBody(body: unknown, headers: SnapReqHeaders): NormalizedBody;
|
|
24
|
-
export type CompressionEncoding = "identity" | "gzip" | "deflate" | "br" | "zstd";
|
|
25
|
-
export type NormalizedBody = {
|
|
26
|
-
/**
|
|
27
|
-
* - Shape of the body payload.
|
|
28
|
-
*/
|
|
29
|
-
kind: "none" | "text" | "bytes" | "stream";
|
|
30
|
-
/**
|
|
31
|
-
* - The payload itself.
|
|
32
|
-
*/
|
|
33
|
-
value: string | Uint8Array | AsyncIterable<Uint8Array> | null;
|
|
34
|
-
};
|
|
35
|
-
import SnapReqHeaders from "./headers.js";
|
|
35
|
+
export declare function normalizeBody(body: unknown, headers: SnapReqHeaders): NormalizedBody;
|
|
36
36
|
//# sourceMappingURL=request.d.ts.map
|
package/build/request.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.js"],"names":[],"mappings":"AAEA,OAAO,cAAc,MAAM,cAAc,CAAA;AAGtC,YAA2D,mBAAmB,GAApE,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,CAAqB;AAI9E,YAAkB,cAAc,GAChC;;;;IAAiD,IAAI,EAA1C,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAC/C;;;;IAAmE,KAAK,EAA7D,MAAM,GAAG,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC,GAAG,IAAI,CACnE;CAAA,CAAA;AAID;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EALrB,MAAM,GAAG,SAKY,EAAE,IAAI,EAJ3B,MAI2B,EAAE,KAAK,EAHlC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,SAG7B,GAFhC,MAAM,CA2BlB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAHtB,OAGsB,GAFpB,OAAO,CAUnB;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAJvB,OAIuB,EAAE,OAAO,EAHhC,cAGgC,GAF9B,cAAc,CAgC1B"}
|
package/build/response.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import SnapReqHeaders from "./headers.js";
|
|
1
2
|
/**
|
|
2
3
|
* A platform-agnostic response. Transports build it with either a fully-read
|
|
3
4
|
* body (`bytes`) or a `stream` (an async iterable of `Uint8Array`) that the
|
|
@@ -5,6 +6,24 @@
|
|
|
5
6
|
* stream; the buffering helpers may be called repeatedly because they cache.
|
|
6
7
|
*/
|
|
7
8
|
export default class SnapReqResponse {
|
|
9
|
+
url: string;
|
|
10
|
+
method: string;
|
|
11
|
+
status: number;
|
|
12
|
+
statusText: string;
|
|
13
|
+
headers: SnapReqHeaders;
|
|
14
|
+
/** @type {Uint8Array | null} */
|
|
15
|
+
_bytes: Uint8Array | null;
|
|
16
|
+
/** @type {AsyncIterable<Uint8Array> | null} */
|
|
17
|
+
_stream: AsyncIterable<Uint8Array> | null;
|
|
18
|
+
/** @type {import("node:stream").Readable | undefined} */
|
|
19
|
+
nodeStream: import("node:stream").Readable | undefined;
|
|
20
|
+
_streamConsumed: boolean;
|
|
21
|
+
_bodyDone: boolean;
|
|
22
|
+
_onBodyDone: () => void;
|
|
23
|
+
_mapBodyError: (error: unknown) => unknown;
|
|
24
|
+
_cancelBody: (error: unknown) => void;
|
|
25
|
+
/** @type {unknown | null} */
|
|
26
|
+
_bodyAbortError: unknown | null;
|
|
8
27
|
/**
|
|
9
28
|
* @param {object} options - Response data.
|
|
10
29
|
* @param {string} options.url - Fully resolved request URL.
|
|
@@ -17,8 +36,9 @@ export default class SnapReqResponse {
|
|
|
17
36
|
* @param {import("node:stream").Readable} [options.nodeStream] - Raw Node stream, when available, for advanced consumers.
|
|
18
37
|
* @param {() => void} [options.onBodyDone] - Callback fired when body reading finishes or fails.
|
|
19
38
|
* @param {(error: unknown) => unknown} [options.mapBodyError] - Maps body read errors before rethrowing.
|
|
39
|
+
* @param {(error: unknown) => void} [options.cancelBody] - Cancels transport-owned body resources.
|
|
20
40
|
*/
|
|
21
|
-
constructor({ url, method, status, statusText, headers, bytes, stream, nodeStream, onBodyDone, mapBodyError }: {
|
|
41
|
+
constructor({ url, method, status, statusText, headers, bytes, stream, nodeStream, onBodyDone, mapBodyError, cancelBody }: {
|
|
22
42
|
url: string;
|
|
23
43
|
method: string;
|
|
24
44
|
status: number;
|
|
@@ -29,22 +49,8 @@ export default class SnapReqResponse {
|
|
|
29
49
|
nodeStream?: import("node:stream").Readable;
|
|
30
50
|
onBodyDone?: () => void;
|
|
31
51
|
mapBodyError?: (error: unknown) => unknown;
|
|
52
|
+
cancelBody?: (error: unknown) => void;
|
|
32
53
|
});
|
|
33
|
-
url: string;
|
|
34
|
-
method: string;
|
|
35
|
-
status: number;
|
|
36
|
-
statusText: string;
|
|
37
|
-
headers: SnapReqHeaders;
|
|
38
|
-
/** @type {Uint8Array | null} */
|
|
39
|
-
_bytes: Uint8Array | null;
|
|
40
|
-
/** @type {AsyncIterable<Uint8Array> | null} */
|
|
41
|
-
_stream: AsyncIterable<Uint8Array> | null;
|
|
42
|
-
/** @type {import("node:stream").Readable | undefined} */
|
|
43
|
-
nodeStream: import("node:stream").Readable | undefined;
|
|
44
|
-
_streamConsumed: boolean;
|
|
45
|
-
_bodyDone: boolean;
|
|
46
|
-
_onBodyDone: () => void;
|
|
47
|
-
_mapBodyError: (error: unknown) => unknown;
|
|
48
54
|
/** @returns {boolean} - Whether the status is in the 2xx range. */
|
|
49
55
|
get ok(): boolean;
|
|
50
56
|
/**
|
|
@@ -89,6 +95,10 @@ export default class SnapReqResponse {
|
|
|
89
95
|
_mappedBodyError(error: unknown): unknown;
|
|
90
96
|
/** @returns {void} */
|
|
91
97
|
_finishBody(): void;
|
|
98
|
+
/**
|
|
99
|
+
* @param {unknown} error - Cancellation reason.
|
|
100
|
+
* @returns {void}
|
|
101
|
+
*/
|
|
102
|
+
_abortBody(error: unknown): void;
|
|
92
103
|
}
|
|
93
|
-
import SnapReqHeaders from "./headers.js";
|
|
94
104
|
//# sourceMappingURL=response.d.ts.map
|
package/build/response.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../src/response.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../src/response.js"],"names":[],"mappings":"AAEA,OAAO,cAAc,MAAM,cAAc,CAAA;AAuBzC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IAgB3B,GAAG;IACH,MAAM;IACN,MAAM;IACN,UAAU;IACV,OAAO;IACZ,gCAAgC;IAC3B,MAAM,EADA,UAAU,GAAG,IAAI;IAE5B,+CAA+C;IAC1C,OAAO,EADD,aAAa,CAAC,UAAU,CAAC,GAAG,IAAI;IAE3C,yDAAyD;IACpD,UAAU,EADJ,OAAO,aAAa,EAAE,QAAQ,GAAG,SAAS;IAEhD,eAAe;IACf,SAAS;IACT,WAAW,QAlBD,IAAI;IAmBd,aAAa,UAlBD,OAAO,KAAK,OAAO;IAmB/B,WAAW,UAlBC,OAAO,KAAK,IAAI;IAmBjC,6BAA6B;IACxB,eAAe,EADT,OAAO,GAAG,IAAI;IA/B3B;;;;;;;;;;;;;OAaG;IACH,YAAY,EAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,UAAe,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAC,EAZzH;QAAwB,GAAG,EAAnB,MAAM,CACd;QAAwB,MAAM,EAAtB,MAAM,CACd;QAAwB,MAAM,EAAtB,MAAM,CACd;QAAyB,UAAU,AAAnC,CACA,EADQ,MAAM,CACd;QAAiC,OAAO,AAAxC,CACA,EADQ,cAAc,CACtB;QAA6B,KAAK,AAAlC,CACA,EADQ,UAAU,CAClB;QAA4C,MAAM,AAAlD,CACA,EADQ,aAAa,CAAC,UAAU,CAAC,CACjC;QAAiD,UAAU,AAA3D,CACA,EADQ,OAAO,aAAa,EAAE,QAAQ,CACtC;QAA6B,UAAU,AAAvC,CACA,EADQ,MAAM,IAAI,CAClB;QAA8C,YAAY,AAA1D,CACA,EADQ,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CACnC;QAA2C,UAAU,AAArD,CACF,EADU,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAClC;KAC2H,EAqB3H;IAED,mEAAmE;IACnE,IAAI,EAAE,IADQ,OAAO,CAGpB;IAED;;;;OAIG;IACH,MAAM,IAFO,aAAa,CAAC,UAAU,CAAC,CAcrC;IAED,iGAAiG;IACjG,IAAI,UAAU,IADA,OAAO,CAGpB;IAED;;;OAGG;IACG,KAAK,IAFE,OAAO,CAAC,UAAU,CAAC,CAsB/B;IAED;;;;OAIG;IACG,MAAM,IAFC,OAAO,CAAC,MAAM,CAAC,CAU3B;IAED;;;OAGG;IACG,IAAI,IAFG,OAAO,CAAC,MAAM,CAAC,CAM3B;IAED;;;;OAIG;IACG,IAAI,IAFG,OAAO,CAAC,GAAG,CAAC,CAQxB;IAED;;;OAGG;IACH,cAAc,CAAC,MAAM,EAHV,aAAa,CAAC,UAAU,CAGd,GAFR,aAAa,CAAC,UAAU,CAAC,CAiBrC;IAED;;;OAGG;IACH,gBAAgB,CAAC,KAAK,EAHX,OAGW,GAFT,OAAO,CAMnB;IAED,sBAAsB;IACtB,WAAW,IADG,IAAI,CAOjB;IAED;;;OAGG;IACH,UAAU,CAAC,KAAK,EAHL,OAGK,GAFH,IAAI,CAahB;CACF"}
|
package/build/response.js
CHANGED
|
@@ -36,8 +36,9 @@ export default class SnapReqResponse {
|
|
|
36
36
|
* @param {import("node:stream").Readable} [options.nodeStream] - Raw Node stream, when available, for advanced consumers.
|
|
37
37
|
* @param {() => void} [options.onBodyDone] - Callback fired when body reading finishes or fails.
|
|
38
38
|
* @param {(error: unknown) => unknown} [options.mapBodyError] - Maps body read errors before rethrowing.
|
|
39
|
+
* @param {(error: unknown) => void} [options.cancelBody] - Cancels transport-owned body resources.
|
|
39
40
|
*/
|
|
40
|
-
constructor({ url, method, status, statusText = "", headers, bytes, stream, nodeStream, onBodyDone, mapBodyError }) {
|
|
41
|
+
constructor({ url, method, status, statusText = "", headers, bytes, stream, nodeStream, onBodyDone, mapBodyError, cancelBody }) {
|
|
41
42
|
this.url = url;
|
|
42
43
|
this.method = method;
|
|
43
44
|
this.status = status;
|
|
@@ -53,6 +54,9 @@ export default class SnapReqResponse {
|
|
|
53
54
|
this._bodyDone = false;
|
|
54
55
|
this._onBodyDone = onBodyDone;
|
|
55
56
|
this._mapBodyError = mapBodyError;
|
|
57
|
+
this._cancelBody = cancelBody;
|
|
58
|
+
/** @type {unknown | null} */
|
|
59
|
+
this._bodyAbortError = null;
|
|
56
60
|
if (bytes !== undefined)
|
|
57
61
|
this._finishBody();
|
|
58
62
|
}
|
|
@@ -141,6 +145,8 @@ export default class SnapReqResponse {
|
|
|
141
145
|
for await (const chunk of source) {
|
|
142
146
|
yield chunk;
|
|
143
147
|
}
|
|
148
|
+
if (response._bodyAbortError)
|
|
149
|
+
throw response._bodyAbortError;
|
|
144
150
|
}
|
|
145
151
|
catch (error) {
|
|
146
152
|
throw response._mappedBodyError(error);
|
|
@@ -167,5 +173,23 @@ export default class SnapReqResponse {
|
|
|
167
173
|
if (this._onBodyDone)
|
|
168
174
|
this._onBodyDone();
|
|
169
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* @param {unknown} error - Cancellation reason.
|
|
178
|
+
* @returns {void}
|
|
179
|
+
*/
|
|
180
|
+
_abortBody(error) {
|
|
181
|
+
if (this._bodyDone)
|
|
182
|
+
return;
|
|
183
|
+
this._bodyAbortError = error;
|
|
184
|
+
try {
|
|
185
|
+
this._cancelBody?.(error);
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
// Cancellation owns the transport body from this point onward. Mark it
|
|
189
|
+
// terminal even when cancellation throws so deadline watchdogs settle
|
|
190
|
+
// exactly once and cannot abort the same body again later.
|
|
191
|
+
this._finishBody();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
170
194
|
}
|
|
171
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
195
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVzcG9uc2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvcmVzcG9uc2UuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsWUFBWTtBQUVaLE9BQU8sY0FBYyxNQUFNLGNBQWMsQ0FBQTtBQUV6Qzs7OztHQUlHO0FBQ0gsU0FBUyxZQUFZLENBQUMsTUFBTTtJQUMxQixJQUFJLEtBQUssR0FBRyxDQUFDLENBQUE7SUFFYixLQUFLLE1BQU0sS0FBSyxJQUFJLE1BQU07UUFBRSxLQUFLLElBQUksS0FBSyxDQUFDLFVBQVUsQ0FBQTtJQUVyRCxNQUFNLE1BQU0sR0FBRyxJQUFJLFVBQVUsQ0FBQyxLQUFLLENBQUMsQ0FBQTtJQUNwQyxJQUFJLE1BQU0sR0FBRyxDQUFDLENBQUE7SUFFZCxLQUFLLE1BQU0sS0FBSyxJQUFJLE1BQU0sRUFBRSxDQUFDO1FBQzNCLE1BQU0sQ0FBQyxHQUFHLENBQUMsS0FBSyxFQUFFLE1BQU0sQ0FBQyxDQUFBO1FBQ3pCLE1BQU0sSUFBSSxLQUFLLENBQUMsVUFBVSxDQUFBO0lBQzVCLENBQUM7SUFFRCxPQUFPLE1BQU0sQ0FBQTtBQUNmLENBQUM7QUFFRDs7Ozs7R0FLRztBQUNILE1BQU0sQ0FBQyxPQUFPLE9BQU8sZUFBZTtJQUNsQzs7Ozs7Ozs7Ozs7OztPQWFHO0lBQ0gsWUFBWSxFQUFDLEdBQUcsRUFBRSxNQUFNLEVBQUUsTUFBTSxFQUFFLFVBQVUsR0FBRyxFQUFFLEVBQUUsT0FBTyxF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ztZQUFFLElBQUksQ0FBQyxXQUFXLEVBQUUsQ0FBQTtJQUMxQyxDQUFDO0lBRUQ7OztPQUdHO0lBQ0gsVUFBVSxDQUFDLEtBQUs7UUFDZCxJQUFJLElBQUksQ0FBQyxTQUFTO1lBQUUsT0FBTTtRQUMxQixJQUFJLENBQUMsZUFBZSxHQUFHLEtBQUssQ0FBQTtRQUM1QixJQUFJLENBQUM7WUFDSCxJQUFJLENBQUMsV0FBVyxFQUFFLENBQUMsS0FBSyxDQUFDLENBQUE7UUFDM0IsQ0FBQztnQkFBUyxDQUFDO1lBQ1QsdUVBQXVFO1lBQ3ZFLHNFQUFzRTtZQUN0RSwyREFBMkQ7WUFDM0QsSUFBSSxDQUFDLFdBQVcsRUFBRSxDQUFBO1FBQ3BCLENBQUM7SUFDSCxDQUFDO0NBQ0YifQ==
|
package/build/retry.d.ts
CHANGED
|
@@ -1,40 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {object} RetryOptions
|
|
3
|
-
* @property {number} [tries] - Maximum number of attempts. Defaults to 3.
|
|
4
|
-
* @property {number} [waitMs] - Delay between attempts in milliseconds. Defaults to 500.
|
|
5
|
-
* @property {number[]} [retryableStatuses] - HTTP status codes that should be retried. Defaults to 502/503/504.
|
|
6
|
-
* @property {(error: unknown, attempt: number) => boolean} [shouldRetry] - Override the retryable-error classifier.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {object} NormalizedRetryOptions
|
|
10
|
-
* @property {number} tries - Maximum number of attempts.
|
|
11
|
-
* @property {number} waitMs - Delay between attempts in milliseconds.
|
|
12
|
-
* @property {number[]} retryableStatuses - HTTP status codes that should be retried.
|
|
13
|
-
* @property {(error: unknown, attempt: number) => boolean} shouldRetry - Retryable-error classifier.
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* The default network-error classifier. Exposed so callers can compose extra
|
|
17
|
-
* rules on top of it (for example matching server-specific 500 messages).
|
|
18
|
-
* @param {unknown} error - Error thrown by a transport.
|
|
19
|
-
* @returns {boolean} - Whether the error is a transient network failure.
|
|
20
|
-
*/
|
|
21
|
-
export function defaultRetryableError(error: unknown): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Normalizes the `retry` option into a complete set of retry settings, or
|
|
24
|
-
* `null` when retries are disabled.
|
|
25
|
-
* @param {boolean | RetryOptions | undefined} retry - Retry configuration.
|
|
26
|
-
* @returns {NormalizedRetryOptions | null} - Normalized retry settings.
|
|
27
|
-
*/
|
|
28
|
-
export function normalizeRetryOptions(retry: boolean | RetryOptions | undefined): NormalizedRetryOptions | null;
|
|
29
|
-
/**
|
|
30
|
-
* Runs a request attempt, retrying transient network errors and retryable HTTP
|
|
31
|
-
* statuses. Retries are only used for buffered requests — the caller must not
|
|
32
|
-
* apply this to streamed responses.
|
|
33
|
-
* @param {() => Promise<import("./response.js").default>} attempt - Performs one request attempt.
|
|
34
|
-
* @param {NormalizedRetryOptions} retry - Normalized retry settings.
|
|
35
|
-
* @returns {Promise<import("./response.js").default>} - The successful (or final) response.
|
|
36
|
-
*/
|
|
37
|
-
export function runWithRetry(attempt: () => Promise<import("./response.js").default>, retry: NormalizedRetryOptions): Promise<import("./response.js").default>;
|
|
38
1
|
export type RetryOptions = {
|
|
39
2
|
/**
|
|
40
3
|
* - Maximum number of attempts. Defaults to 3.
|
|
@@ -71,4 +34,42 @@ export type NormalizedRetryOptions = {
|
|
|
71
34
|
*/
|
|
72
35
|
shouldRetry: (error: unknown, attempt: number) => boolean;
|
|
73
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {object} RetryOptions
|
|
39
|
+
* @property {number} [tries] - Maximum number of attempts. Defaults to 3.
|
|
40
|
+
* @property {number} [waitMs] - Delay between attempts in milliseconds. Defaults to 500.
|
|
41
|
+
* @property {number[]} [retryableStatuses] - HTTP status codes that should be retried. Defaults to 502/503/504.
|
|
42
|
+
* @property {(error: unknown, attempt: number) => boolean} [shouldRetry] - Override the retryable-error classifier.
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* @typedef {object} NormalizedRetryOptions
|
|
46
|
+
* @property {number} tries - Maximum number of attempts.
|
|
47
|
+
* @property {number} waitMs - Delay between attempts in milliseconds.
|
|
48
|
+
* @property {number[]} retryableStatuses - HTTP status codes that should be retried.
|
|
49
|
+
* @property {(error: unknown, attempt: number) => boolean} shouldRetry - Retryable-error classifier.
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* The default network-error classifier. Exposed so callers can compose extra
|
|
53
|
+
* rules on top of it (for example matching server-specific 500 messages).
|
|
54
|
+
* @param {unknown} error - Error thrown by a transport.
|
|
55
|
+
* @returns {boolean} - Whether the error is a transient network failure.
|
|
56
|
+
*/
|
|
57
|
+
export declare function defaultRetryableError(error: unknown): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Normalizes the `retry` option into a complete set of retry settings, or
|
|
60
|
+
* `null` when retries are disabled.
|
|
61
|
+
* @param {boolean | RetryOptions | undefined} retry - Retry configuration.
|
|
62
|
+
* @returns {NormalizedRetryOptions | null} - Normalized retry settings.
|
|
63
|
+
*/
|
|
64
|
+
export declare function normalizeRetryOptions(retry: boolean | RetryOptions | undefined): NormalizedRetryOptions | null;
|
|
65
|
+
/**
|
|
66
|
+
* Runs a request attempt, retrying transient network errors and retryable HTTP
|
|
67
|
+
* statuses. Retries are only used for buffered requests — the caller must not
|
|
68
|
+
* apply this to streamed responses.
|
|
69
|
+
* @param {(signal: AbortSignal | undefined) => Promise<import("./response.js").default>} attempt - Performs one request attempt.
|
|
70
|
+
* @param {NormalizedRetryOptions} retryOptions - Normalized retry settings.
|
|
71
|
+
* @param {AbortSignal} [signal] - Caller cancellation signal.
|
|
72
|
+
* @returns {Promise<import("./response.js").default>} - The successful (or final) response.
|
|
73
|
+
*/
|
|
74
|
+
export declare function runWithRetry(attempt: (signal: AbortSignal | undefined) => Promise<import("./response.js").default>, retryOptions: NormalizedRetryOptions, signal?: AbortSignal): Promise<import("./response.js").default>;
|
|
74
75
|
//# sourceMappingURL=retry.d.ts.map
|
package/build/retry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.js"],"names":[],"mappings":"AASG,YAAkB,YAAY,GAC9B;;;;IAAoB,KAAK,AAAzB,CACA,EADW,MAAM,CACjB;;;;IAAoB,MAAM,AAA1B,CACA,EADW,MAAM,CACjB;;;;IAAsB,iBAAiB,AAAvC,CACA,EADW,MAAM,EAAE,CACnB;;;;IAA0D,WAAW,AAArE,CACF,EADa,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CACzD;CAAA,CAAA;AAGE,YAAkB,sBAAsB,GACxC;;;;IAAmB,KAAK,EAAb,MAAM,CACjB;;;;IAAmB,MAAM,EAAd,MAAM,CACjB;;;;IAAqB,iBAAiB,EAA3B,MAAM,EAAE,CACnB;;;;IAAyD,WAAW,EAAzD,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CACzD;CAAA,CAAA;AAdD;;;;;;GAMG;AAEH;;;;;;GAMG;AAEH;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAHhC,OAGgC,GAF9B,OAAO,CAYnB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAHhC,OAAO,GAAG,YAAY,GAAG,SAGO,GAF9B,sBAAsB,GAAG,IAAI,CAezC;AAUD;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAL/B,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,KAAK,OAAO,CAAC,OAAO,eAAe,EAAE,OAAO,CAK7C,EAAE,YAAY,EAJ7C,sBAI6C,EAAE,MAAM,AAH7D,CACA,EADQ,WAGqD,GAFnD,OAAO,CAAC,OAAO,eAAe,EAAE,OAAO,CAAC,CAiCpD"}
|