@happy-ts/fetch-t 1.3.3 → 1.4.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/types.d.ts CHANGED
@@ -1,207 +1,432 @@
1
- import { AsyncResult, IOResult } from 'happy-rusty';
2
-
3
- /**
4
- * Name of abort error;
5
- */
6
- declare const ABORT_ERROR: "AbortError";
7
- /**
8
- * Name of timeout error;
9
- */
10
- declare const TIMEOUT_ERROR: "TimeoutError";
11
-
12
- /**
13
- * Represents the response of a fetch operation, encapsulating the result data or any error that occurred.
14
- *
15
- * @typeParam T - The type of the data expected in the response.
16
- */
17
- type FetchResponse<T, E = any> = AsyncResult<T, E>;
18
- /**
19
- * Defines the structure and behavior of a fetch task, including the ability to abort the task and check its status.
20
- *
21
- * @typeParam T - The type of the data expected in the response.
22
- */
23
- interface FetchTask<T> {
24
- /**
25
- * Aborts the fetch task, optionally with a reason for the abortion.
26
- *
27
- * @param reason - An optional parameter to indicate why the task was aborted.
28
- */
29
- abort(reason?: any): void;
30
- /**
31
- * Indicates whether the fetch task has been aborted.
32
- */
33
- readonly aborted: boolean;
34
- /**
35
- * The response of the fetch task, represented as an `AsyncResult`.
36
- */
37
- readonly response: FetchResponse<T>;
38
- }
39
- /**
40
- * Specifies the expected response type of the fetch request.
41
- */
42
- type FetchResponseType = 'text' | 'arraybuffer' | 'blob' | 'json';
43
- /**
44
- * Represents the progress of a fetch operation.
45
- */
46
- interface FetchProgress {
47
- /**
48
- * The total number of bytes to be received.
49
- */
50
- totalByteLength: number;
51
- /**
52
- * The number of bytes received so far.
53
- */
54
- completedByteLength: number;
55
- }
56
- /**
57
- * Extends the standard `RequestInit` interface from the Fetch API to include additional custom options.
58
- */
59
- interface FetchInit extends RequestInit {
60
- /**
61
- * Indicates whether the fetch request should be abortable.
62
- */
63
- abortable?: boolean;
64
- /**
65
- * Specifies the expected response type of the fetch request.
66
- */
67
- responseType?: FetchResponseType;
68
- /**
69
- * Specifies the maximum time in milliseconds to wait for the fetch request to complete.
70
- */
71
- timeout?: number;
72
- /**
73
- * Specifies a function to be called when the fetch request makes progress.
74
- * @param progressResult - The progress of the fetch request.
75
- */
76
- onProgress?: (progressResult: IOResult<FetchProgress>) => void;
77
- /**
78
- * Specifies a function to be called when the fetch request receives a chunk of data.
79
- * @param chunk - The chunk of data received.
80
- */
81
- onChunk?: (chunk: Uint8Array) => void;
82
- }
83
- /**
84
- * Represents an error that occurred during a fetch operation when the response is not ok.
85
- */
86
- declare class FetchError extends Error {
87
- /**
88
- * The name of the error.
89
- */
90
- name: string;
91
- /**
92
- * The status code of the response.
93
- */
94
- status: number;
95
- constructor(message: string, status: number);
96
- }
97
-
98
- /**
99
- * Fetches a resource from the network as a text string and returns a `FetchTask` representing the operation.
100
- *
101
- * @typeParam T - The expected type of the response data.
102
- * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
103
- * @param init - Additional options for the fetch operation, including custom `FetchInit` properties.
104
- * @returns A `FetchTask` representing the operation with a `string` response.
105
- */
106
- declare function fetchT(url: string | URL, init: FetchInit & {
107
- abortable: true;
108
- responseType: 'text';
109
- }): FetchTask<string>;
110
- /**
111
- * Fetches a resource from the network as an ArrayBuffer and returns a `FetchTask` representing the operation.
112
- *
113
- * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
114
- * @param init - Additional options for the fetch operation, including custom `FetchInit` properties.
115
- * @returns A `FetchTask` representing the operation with an `ArrayBuffer` response.
116
- */
117
- declare function fetchT(url: string | URL, init: FetchInit & {
118
- abortable: true;
119
- responseType: 'arraybuffer';
120
- }): FetchTask<ArrayBuffer>;
121
- /**
122
- * Fetches a resource from the network as a Blob and returns a `FetchTask` representing the operation.
123
- *
124
- * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
125
- * @param init - Additional options for the fetch operation, including custom `FetchInit` properties.
126
- * @returns A `FetchTask` representing the operation with a `Blob` response.
127
- */
128
- declare function fetchT(url: string | URL, init: FetchInit & {
129
- abortable: true;
130
- responseType: 'blob';
131
- }): FetchTask<Blob>;
132
- /**
133
- * Fetches a resource from the network and parses it as JSON, returning a `FetchTask` representing the operation.
134
- *
135
- * @typeParam T - The expected type of the parsed JSON data.
136
- * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
137
- * @param init - Additional options for the fetch operation, including custom `FetchInit` properties.
138
- * @returns A `FetchTask` representing the operation with a response parsed as JSON.
139
- */
140
- declare function fetchT<T>(url: string | URL, init: FetchInit & {
141
- abortable: true;
142
- responseType: 'json';
143
- }): FetchTask<T>;
144
- /**
145
- * Fetches a resource from the network as a text string and returns a `FetchResponse` representing the operation.
146
- *
147
- * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
148
- * @param init - Additional options for the fetch operation, specifying the response type as 'text'.
149
- * @returns A `FetchResponse` representing the operation with a `string` response.
150
- */
151
- declare function fetchT(url: string | URL, init: FetchInit & {
152
- responseType: 'text';
153
- }): FetchResponse<string, Error>;
154
- /**
155
- * Fetches a resource from the network as an ArrayBuffer and returns a `FetchResponse` representing the operation.
156
- *
157
- * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
158
- * @param init - Additional options for the fetch operation, specifying the response type as 'arraybuffer'.
159
- * @returns A `FetchResponse` representing the operation with an `ArrayBuffer` response.
160
- */
161
- declare function fetchT(url: string | URL, init: FetchInit & {
162
- responseType: 'arraybuffer';
163
- }): FetchResponse<ArrayBuffer, Error>;
164
- /**
165
- * Fetches a resource from the network as a Blob and returns a `FetchResponse` representing the operation.
166
- *
167
- * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
168
- * @param init - Additional options for the fetch operation, specifying the response type as 'blob'.
169
- * @returns A `FetchResponse` representing the operation with a `Blob` response.
170
- */
171
- declare function fetchT(url: string | URL, init: FetchInit & {
172
- responseType: 'blob';
173
- }): FetchResponse<Blob, Error>;
174
- /**
175
- * Fetches a resource from the network and parses it as JSON, returning a `FetchResponse` representing the operation.
176
- *
177
- * @typeParam T - The expected type of the parsed JSON data.
178
- * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
179
- * @param init - Additional options for the fetch operation, specifying the response type as 'json'.
180
- * @returns A `FetchResponse` representing the operation with a response parsed as JSON.
181
- */
182
- declare function fetchT<T>(url: string | URL, init: FetchInit & {
183
- responseType: 'json';
184
- }): FetchResponse<T, Error>;
185
- /**
186
- * Fetches a resource from the network and returns a `FetchTask` representing the operation with a generic `Response`.
187
- *
188
- * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
189
- * @param init - Additional options for the fetch operation, indicating that the operation should be abortable.
190
- * @returns A `FetchTask` representing the operation with a generic `Response`.
191
- */
192
- declare function fetchT(url: string | URL, init: FetchInit & {
193
- abortable: true;
194
- }): FetchTask<Response>;
195
- /**
196
- * Fetches a resource from the network and returns a `FetchResponse` or `FetchTask` based on the provided options.
197
- *
198
- * @typeParam T - The expected type of the response data when not using a specific `responseType`.
199
- * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
200
- * @param init - Additional options for the fetch operation, including custom `FetchInit` properties.
201
- * @returns A `FetchResponse` representing the operation with a `Response` object.
202
- */
203
- declare function fetchT(url: string | URL, init?: FetchInit): FetchResponse<Response>;
204
-
205
- export { ABORT_ERROR, FetchError, TIMEOUT_ERROR, fetchT };
206
- export type { FetchInit, FetchProgress, FetchResponse, FetchResponseType, FetchTask };
207
- //# sourceMappingURL=types.d.ts.map
1
+ import { AsyncResult } from 'happy-rusty';
2
+ import { IOResult } from 'happy-rusty';
3
+
4
+ /**
5
+ * Error name for aborted fetch requests.
6
+ *
7
+ * This matches the standard `AbortError` name used by the Fetch API when a request
8
+ * is cancelled via `AbortController.abort()`.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { fetchT, ABORT_ERROR } from '@happy-ts/fetch-t';
13
+ *
14
+ * const task = fetchT('https://api.example.com/data', { abortable: true });
15
+ * task.abort();
16
+ *
17
+ * const result = await task.response;
18
+ * result.inspectErr((err) => {
19
+ * if (err.name === ABORT_ERROR) {
20
+ * console.log('Request was aborted');
21
+ * }
22
+ * });
23
+ * ```
24
+ */
25
+ export declare const ABORT_ERROR: "AbortError";
26
+
27
+ /**
28
+ * Custom error class for HTTP error responses (non-2xx status codes).
29
+ *
30
+ * Thrown when `Response.ok` is `false`. Contains the HTTP status code
31
+ * for programmatic error handling.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { fetchT, FetchError } from '@happy-ts/fetch-t';
36
+ *
37
+ * const result = await fetchT('https://api.example.com/not-found', {
38
+ * responseType: 'json',
39
+ * });
40
+ *
41
+ * result.inspectErr((err) => {
42
+ * if (err instanceof FetchError) {
43
+ * console.log('HTTP Status:', err.status); // e.g., 404
44
+ * console.log('Status Text:', err.message); // e.g., "Not Found"
45
+ *
46
+ * // Handle specific status codes
47
+ * switch (err.status) {
48
+ * case 401:
49
+ * console.log('Unauthorized - please login');
50
+ * break;
51
+ * case 404:
52
+ * console.log('Resource not found');
53
+ * break;
54
+ * case 500:
55
+ * console.log('Server error');
56
+ * break;
57
+ * }
58
+ * }
59
+ * });
60
+ * ```
61
+ */
62
+ export declare class FetchError extends Error {
63
+ /**
64
+ * The error name, always `'FetchError'`.
65
+ */
66
+ name: string;
67
+ /**
68
+ * The HTTP status code of the response (e.g., 404, 500).
69
+ */
70
+ status: number;
71
+ /**
72
+ * Creates a new FetchError instance.
73
+ *
74
+ * @param message - The status text from the HTTP response (e.g., "Not Found").
75
+ * @param status - The HTTP status code (e.g., 404).
76
+ */
77
+ constructor(message: string, status: number);
78
+ }
79
+
80
+ /**
81
+ * Extended fetch options that add additional capabilities to the standard `RequestInit`.
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * import { fetchT, type FetchInit } from '@happy-ts/fetch-t';
86
+ *
87
+ * const options: FetchInit = {
88
+ * // Standard RequestInit options
89
+ * method: 'POST',
90
+ * headers: { 'Content-Type': 'application/json' },
91
+ * body: JSON.stringify({ key: 'value' }),
92
+ *
93
+ * // Extended options
94
+ * abortable: true, // Return FetchTask for manual abort control
95
+ * responseType: 'json', // Auto-parse response as JSON
96
+ * timeout: 10000, // Abort after 10 seconds
97
+ * onProgress: (result) => { // Track download progress
98
+ * result.inspect(({ completedByteLength, totalByteLength }) => {
99
+ * console.log(`${completedByteLength}/${totalByteLength}`);
100
+ * });
101
+ * },
102
+ * onChunk: (chunk) => { // Receive raw data chunks
103
+ * console.log('Received chunk:', chunk.byteLength, 'bytes');
104
+ * },
105
+ * };
106
+ *
107
+ * const task = fetchT('https://api.example.com/upload', options);
108
+ * ```
109
+ */
110
+ export declare interface FetchInit extends RequestInit {
111
+ /**
112
+ * When `true`, returns a `FetchTask` instead of `FetchResponse`.
113
+ *
114
+ * The `FetchTask` provides `abort()` method and `aborted` status.
115
+ *
116
+ * @default false
117
+ */
118
+ abortable?: boolean;
119
+ /**
120
+ * Specifies how the response body should be parsed.
121
+ *
122
+ * - `'text'` - Returns `string`
123
+ * - `'json'` - Returns parsed JSON (type `T`)
124
+ * - `'arraybuffer'` - Returns `ArrayBuffer`
125
+ * - `'blob'` - Returns `Blob`
126
+ * - `undefined` - Returns raw `Response` object
127
+ */
128
+ responseType?: FetchResponseType;
129
+ /**
130
+ * Maximum time in milliseconds to wait for the request to complete.
131
+ *
132
+ * If exceeded, the request is automatically aborted with a `TimeoutError`.
133
+ * Must be a positive number.
134
+ */
135
+ timeout?: number;
136
+ /**
137
+ * Callback invoked during download to report progress.
138
+ *
139
+ * Receives an `IOResult<FetchProgress>`:
140
+ * - `Ok(FetchProgress)` - Progress update with byte counts
141
+ * - `Err(Error)` - If `Content-Length` header is missing (called once)
142
+ *
143
+ * @param progressResult - The progress result, either success with progress data or error.
144
+ */
145
+ onProgress?: (progressResult: IOResult<FetchProgress>) => void;
146
+ /**
147
+ * Callback invoked when a chunk of data is received.
148
+ *
149
+ * Useful for streaming or processing data as it arrives.
150
+ * Each chunk is a `Uint8Array` containing the raw bytes.
151
+ *
152
+ * @param chunk - The raw data chunk received from the response stream.
153
+ */
154
+ onChunk?: (chunk: Uint8Array) => void;
155
+ }
156
+
157
+ /**
158
+ * Represents the download progress of a fetch operation.
159
+ *
160
+ * Passed to the `onProgress` callback when tracking download progress.
161
+ * Note: Progress tracking requires the server to send a `Content-Length` header.
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * import { fetchT, type FetchProgress } from '@happy-ts/fetch-t';
166
+ *
167
+ * await fetchT('https://example.com/file.zip', {
168
+ * responseType: 'blob',
169
+ * onProgress: (result) => {
170
+ * result.inspect((progress: FetchProgress) => {
171
+ * const percent = (progress.completedByteLength / progress.totalByteLength) * 100;
172
+ * console.log(`Downloaded: ${percent.toFixed(1)}%`);
173
+ * });
174
+ * },
175
+ * });
176
+ * ```
177
+ */
178
+ export declare interface FetchProgress {
179
+ /**
180
+ * The total number of bytes to be received (from Content-Length header).
181
+ */
182
+ totalByteLength: number;
183
+ /**
184
+ * The number of bytes received so far.
185
+ */
186
+ completedByteLength: number;
187
+ }
188
+
189
+ /**
190
+ * Represents the response of a fetch operation as an async Result type.
191
+ *
192
+ * This is an alias for `AsyncResult<T, E>` from the `happy-rusty` library,
193
+ * providing Rust-like error handling without throwing exceptions.
194
+ *
195
+ * @typeParam T - The type of the data expected in a successful response.
196
+ * @typeParam E - The type of the error (defaults to `any`). Typically `Error` or `FetchError`.
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * import { fetchT, type FetchResponse } from '@happy-ts/fetch-t';
201
+ *
202
+ * // FetchResponse is a Promise that resolves to Result<T, E>
203
+ * const response: FetchResponse<string> = fetchT('https://api.example.com', {
204
+ * responseType: 'text',
205
+ * });
206
+ *
207
+ * const result = await response;
208
+ * result
209
+ * .inspect((text) => console.log('Success:', text))
210
+ * .inspectErr((err) => console.error('Error:', err));
211
+ * ```
212
+ */
213
+ export declare type FetchResponse<T, E = any> = AsyncResult<T, E>;
214
+
215
+ /**
216
+ * Specifies the expected response type for automatic parsing.
217
+ *
218
+ * - `'text'` - Parse response as string via `Response.text()`
219
+ * - `'json'` - Parse response as JSON via `Response.json()`
220
+ * - `'arraybuffer'` - Parse response as ArrayBuffer via `Response.arrayBuffer()`
221
+ * - `'blob'` - Parse response as Blob via `Response.blob()`
222
+ *
223
+ * If not specified, the raw `Response` object is returned.
224
+ *
225
+ * @example
226
+ * ```typescript
227
+ * import { fetchT, type FetchResponseType } from '@happy-ts/fetch-t';
228
+ *
229
+ * const responseType: FetchResponseType = 'json';
230
+ *
231
+ * const result = await fetchT('https://api.example.com/data', { responseType });
232
+ * ```
233
+ */
234
+ export declare type FetchResponseType = 'text' | 'arraybuffer' | 'blob' | 'json';
235
+
236
+ /**
237
+ * Fetches a resource from the network as a text string and returns an abortable `FetchTask`.
238
+ *
239
+ * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
240
+ * @param init - Additional options for the fetch operation, must include `abortable: true` and `responseType: 'text'`.
241
+ * @returns A `FetchTask` representing the abortable operation with a `string` response.
242
+ */
243
+ export declare function fetchT(url: string | URL, init: FetchInit & {
244
+ abortable: true;
245
+ responseType: 'text';
246
+ }): FetchTask<string>;
247
+
248
+ /**
249
+ * Fetches a resource from the network as an ArrayBuffer and returns an abortable `FetchTask`.
250
+ *
251
+ * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
252
+ * @param init - Additional options for the fetch operation, must include `abortable: true` and `responseType: 'arraybuffer'`.
253
+ * @returns A `FetchTask` representing the abortable operation with an `ArrayBuffer` response.
254
+ */
255
+ export declare function fetchT(url: string | URL, init: FetchInit & {
256
+ abortable: true;
257
+ responseType: 'arraybuffer';
258
+ }): FetchTask<ArrayBuffer>;
259
+
260
+ /**
261
+ * Fetches a resource from the network as a Blob and returns an abortable `FetchTask`.
262
+ *
263
+ * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
264
+ * @param init - Additional options for the fetch operation, must include `abortable: true` and `responseType: 'blob'`.
265
+ * @returns A `FetchTask` representing the abortable operation with a `Blob` response.
266
+ */
267
+ export declare function fetchT(url: string | URL, init: FetchInit & {
268
+ abortable: true;
269
+ responseType: 'blob';
270
+ }): FetchTask<Blob>;
271
+
272
+ /**
273
+ * Fetches a resource from the network and parses it as JSON, returning an abortable `FetchTask`.
274
+ *
275
+ * @typeParam T - The expected type of the parsed JSON data.
276
+ * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
277
+ * @param init - Additional options for the fetch operation, must include `abortable: true` and `responseType: 'json'`.
278
+ * @returns A `FetchTask` representing the abortable operation with a response parsed as type `T`.
279
+ */
280
+ export declare function fetchT<T>(url: string | URL, init: FetchInit & {
281
+ abortable: true;
282
+ responseType: 'json';
283
+ }): FetchTask<T>;
284
+
285
+ /**
286
+ * Fetches a resource from the network as a text string.
287
+ *
288
+ * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
289
+ * @param init - Additional options for the fetch operation, must include `responseType: 'text'`.
290
+ * @returns A `FetchResponse` representing the operation with a `string` response.
291
+ */
292
+ export declare function fetchT(url: string | URL, init: FetchInit & {
293
+ responseType: 'text';
294
+ }): FetchResponse<string, Error>;
295
+
296
+ /**
297
+ * Fetches a resource from the network as an ArrayBuffer.
298
+ *
299
+ * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
300
+ * @param init - Additional options for the fetch operation, must include `responseType: 'arraybuffer'`.
301
+ * @returns A `FetchResponse` representing the operation with an `ArrayBuffer` response.
302
+ */
303
+ export declare function fetchT(url: string | URL, init: FetchInit & {
304
+ responseType: 'arraybuffer';
305
+ }): FetchResponse<ArrayBuffer, Error>;
306
+
307
+ /**
308
+ * Fetches a resource from the network as a Blob.
309
+ *
310
+ * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
311
+ * @param init - Additional options for the fetch operation, must include `responseType: 'blob'`.
312
+ * @returns A `FetchResponse` representing the operation with a `Blob` response.
313
+ */
314
+ export declare function fetchT(url: string | URL, init: FetchInit & {
315
+ responseType: 'blob';
316
+ }): FetchResponse<Blob, Error>;
317
+
318
+ /**
319
+ * Fetches a resource from the network and parses it as JSON.
320
+ *
321
+ * @typeParam T - The expected type of the parsed JSON data.
322
+ * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
323
+ * @param init - Additional options for the fetch operation, must include `responseType: 'json'`.
324
+ * @returns A `FetchResponse` representing the operation with a response parsed as type `T`.
325
+ */
326
+ export declare function fetchT<T>(url: string | URL, init: FetchInit & {
327
+ responseType: 'json';
328
+ }): FetchResponse<T, Error>;
329
+
330
+ /**
331
+ * Fetches a resource from the network and returns an abortable `FetchTask` with a generic `Response`.
332
+ *
333
+ * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
334
+ * @param init - Additional options for the fetch operation, must include `abortable: true`.
335
+ * @returns A `FetchTask` representing the abortable operation with a `Response` object.
336
+ */
337
+ export declare function fetchT(url: string | URL, init: FetchInit & {
338
+ abortable: true;
339
+ }): FetchTask<Response>;
340
+
341
+ /**
342
+ * Fetches a resource from the network and returns a `FetchResponse` with a generic `Response` object.
343
+ *
344
+ * @param url - The resource to fetch. Can be a URL object or a string representing a URL.
345
+ * @param init - Optional additional options for the fetch operation.
346
+ * @returns A `FetchResponse` representing the operation with a `Response` object.
347
+ */
348
+ export declare function fetchT(url: string | URL, init?: FetchInit): FetchResponse<Response>;
349
+
350
+ /**
351
+ * Represents an abortable fetch operation with control methods.
352
+ *
353
+ * Returned when `abortable: true` is set in the fetch options. Provides
354
+ * the ability to cancel the request and check its abort status.
355
+ *
356
+ * @typeParam T - The type of the data expected in the response.
357
+ *
358
+ * @example
359
+ * ```typescript
360
+ * import { fetchT, type FetchTask } from '@happy-ts/fetch-t';
361
+ *
362
+ * interface User {
363
+ * id: number;
364
+ * name: string;
365
+ * }
366
+ *
367
+ * const task: FetchTask<User> = fetchT<User>('https://api.example.com/user/1', {
368
+ * abortable: true,
369
+ * responseType: 'json',
370
+ * });
371
+ *
372
+ * // Check if aborted
373
+ * console.log('Is aborted:', task.aborted); // false
374
+ *
375
+ * // Abort with optional reason
376
+ * task.abort('User navigated away');
377
+ *
378
+ * // Access the response (will be an error after abort)
379
+ * const result = await task.response;
380
+ * result.inspectErr((err) => console.log('Aborted:', err.message));
381
+ * ```
382
+ */
383
+ export declare interface FetchTask<T> {
384
+ /**
385
+ * Aborts the fetch task, optionally with a reason.
386
+ *
387
+ * Once aborted, the `response` promise will resolve to an `Err` containing
388
+ * an `AbortError`. The abort reason can be any value and will be passed
389
+ * to the underlying `AbortController.abort()`.
390
+ *
391
+ * @param reason - An optional value indicating why the task was aborted.
392
+ * This can be an Error, string, or any other value.
393
+ */
394
+ abort(reason?: any): void;
395
+ /**
396
+ * Indicates whether the fetch task has been aborted.
397
+ *
398
+ * Returns `true` if `abort()` was called or if the request timed out.
399
+ */
400
+ readonly aborted: boolean;
401
+ /**
402
+ * The response promise of the fetch task.
403
+ *
404
+ * Resolves to `Ok<T>` on success, or `Err<Error>` on failure (including abort).
405
+ */
406
+ readonly response: FetchResponse<T>;
407
+ }
408
+
409
+ /**
410
+ * Error name for timed out fetch requests.
411
+ *
412
+ * This is set on the `Error.name` property when a request exceeds the specified
413
+ * `timeout` duration and is automatically aborted.
414
+ *
415
+ * @example
416
+ * ```typescript
417
+ * import { fetchT, TIMEOUT_ERROR } from '@happy-ts/fetch-t';
418
+ *
419
+ * const result = await fetchT('https://api.example.com/slow-endpoint', {
420
+ * timeout: 5000, // 5 seconds
421
+ * });
422
+ *
423
+ * result.inspectErr((err) => {
424
+ * if (err.name === TIMEOUT_ERROR) {
425
+ * console.log('Request timed out after 5 seconds');
426
+ * }
427
+ * });
428
+ * ```
429
+ */
430
+ export declare const TIMEOUT_ERROR: "TimeoutError";
431
+
432
+ export { }