@ahoo-wang/fetcher 0.9.1 → 0.9.5

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/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(n,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(n=typeof globalThis<"u"?globalThis:n||self,a(n.Fetcher={}))})(this,(function(n){"use strict";function a(r){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(r)}function g(r,e){return a(e)?e:e?r.replace(/\/?\/$/,"")+"/"+e.replace(/^\/+/,""):r}class I{constructor(e){this.baseURL=e}build(e,t){const s=t?.path,o=t?.query,u=g(this.baseURL,e);let i=this.interpolateUrl(u,s);if(o){const h=new URLSearchParams(o).toString();h&&(i+="?"+h)}return i}resolveRequestUrl(e){return this.build(e.url,e.urlParams)}interpolateUrl(e,t){return t?e.replace(/{([^}]+)}/g,(s,o)=>{const u=t[o];if(u===void 0)throw new Error(`Missing required path parameter: ${o}`);return String(u)}):e}}function b(r,e){return typeof r<"u"?r:e}class d extends Error{constructor(e){const t=e.method||"GET",s=`Request timeout of ${e.timeout}ms exceeded for ${t} ${e.url}`;super(s),this.name="FetchTimeoutError",this.request=e,Object.setPrototypeOf(this,d.prototype)}}async function F(r){const e=r.url,t=r.timeout,s=r;if(!t)return fetch(e,s);const o=new AbortController,u={...s,signal:o.signal};let i=null;const h=new Promise((B,D)=>{i=setTimeout(()=>{i&&clearTimeout(i);const _=new d(r);o.abort(_),D(_)},t)});try{return await Promise.race([fetch(e,u),h])}finally{i&&clearTimeout(i)}}function l(r,e){return e?r.filter(e).sort((t,s)=>t.order-s.order):[...r].sort((t,s)=>t.order-s.order)}var c=(r=>(r.GET="GET",r.POST="POST",r.PUT="PUT",r.DELETE="DELETE",r.PATCH="PATCH",r.HEAD="HEAD",r.OPTIONS="OPTIONS",r))(c||{});const L="Content-Type";var m=(r=>(r.APPLICATION_JSON="application/json",r.TEXT_EVENT_STREAM="text/event-stream",r))(m||{});class R{constructor(){this.name="RequestBodyInterceptor",this.order=Number.MIN_SAFE_INTEGER+200}intercept(e){const t=e.request;if(t.body===void 0||t.body===null||typeof t.body!="object"||t.body instanceof ArrayBuffer||ArrayBuffer.isView(t.body)||t.body instanceof Blob||t.body instanceof File||t.body instanceof URLSearchParams||t.body instanceof FormData||t.body instanceof ReadableStream)return;const s={...t};s.body=JSON.stringify(t.body),s.headers||(s.headers={});const o=s.headers;o["Content-Type"]||(o["Content-Type"]=m.APPLICATION_JSON),e.request=s}}class w{constructor(){this.name="FetchInterceptor",this.order=Number.MAX_SAFE_INTEGER-100}async intercept(e){e.response=await F(e.request)}}class P{constructor(){this.name="UrlResolveInterceptor",this.order=Number.MIN_SAFE_INTEGER+100}intercept(e){const t=e.request;t.url=e.fetcher.urlBuilder.resolveRequestUrl(t)}}class f{constructor(e=[]){this.sortedInterceptors=[],this.sortedInterceptors=l(e)}get name(){return this.constructor.name}get order(){return Number.MIN_SAFE_INTEGER}use(e){return this.sortedInterceptors.some(t=>t.name===e.name)?!1:(this.sortedInterceptors=l([...this.sortedInterceptors,e]),!0)}eject(e){const t=this.sortedInterceptors;return this.sortedInterceptors=l(t,s=>s.name!==e),t.length!==this.sortedInterceptors.length}clear(){this.sortedInterceptors=[]}async intercept(e){for(const t of this.sortedInterceptors)await t.intercept(e)}}class A{constructor(){this.request=new f([new P,new R,new w]),this.response=new f,this.error=new f}}class N{constructor(e,t,s,o){this.attributes={},this.fetcher=e,this.request=t,this.response=s,this.error=o}hasError(){return!!this.error}hasResponse(){return!!this.response}}function y(r,e){if(!(r===void 0&&e===void 0))return e===void 0?r:r===void 0?e:{...r,...e}}const p={"Content-Type":m.APPLICATION_JSON},E={baseURL:"",headers:p};class S{constructor(e=E){this.headers=p,this.urlBuilder=new I(e.baseURL),this.headers=e.headers??p,this.timeout=e.timeout,this.interceptors=e.interceptors??new A}async fetch(e,t={}){const s=t;s.url=e;const o=await this.request(s);if(!o.response)throw new Error(`Request to ${s.url} failed with no response`);return o.response}async request(e){const t=y(e.headers,this.headers),s={...e,headers:t,timeout:b(e.timeout,this.timeout)},o=new N(this,s);return this.exchange(o)}async exchange(e){try{return await this.interceptors.request.intercept(e),await this.interceptors.response.intercept(e),e}catch(t){if(e.error=t,await this.interceptors.error.intercept(e),e.hasResponse())return e;throw e.error}}async methodFetch(e,t,s={}){return this.fetch(t,{...s,method:e})}async get(e,t={}){return this.methodFetch(c.GET,e,t)}async post(e,t={}){return this.methodFetch(c.POST,e,t)}async put(e,t={}){return this.methodFetch(c.PUT,e,t)}async delete(e,t={}){return this.methodFetch(c.DELETE,e,t)}async patch(e,t={}){return this.methodFetch(c.PATCH,e,t)}async head(e,t={}){return this.methodFetch(c.HEAD,e,t)}async options(e,t={}){return this.methodFetch(c.OPTIONS,e,t)}}const T="default";class q{constructor(){this.registrar=new Map}register(e,t){this.registrar.set(e,t)}unregister(e){return this.registrar.delete(e)}get(e){return this.registrar.get(e)}requiredGet(e){const t=this.get(e);if(!t)throw new Error(`Fetcher ${e} not found`);return t}get default(){return this.requiredGet(T)}set default(e){this.register(T,e)}get fetchers(){return new Map(this.registrar)}}const O=new q;function v(r,e){if(Object.keys(r).length===0)return e;if(Object.keys(e).length===0)return r;const t={path:y(r.urlParams?.path,e.urlParams?.path),query:y(r.urlParams?.query,e.urlParams?.query)},s={...r.headers,...e.headers},o=e.method??r.method,u=e.body??r.body,i=e.timeout??r.timeout,h=e.signal??r.signal;return{...r,...e,method:o,urlParams:t,headers:s,body:u,timeout:i,signal:h}}class U extends S{constructor(e,t=E){super(t),this.name=e,O.register(e,this)}}const C=new U(T);n.ContentTypeHeader=L,n.ContentTypeValues=m,n.DEFAULT_FETCHER_NAME=T,n.DEFAULT_OPTIONS=E,n.FetchExchange=N,n.FetchInterceptor=w,n.FetchTimeoutError=d,n.Fetcher=S,n.FetcherInterceptors=A,n.FetcherRegistrar=q,n.HttpMethod=c,n.InterceptorManager=f,n.NamedFetcher=U,n.RequestBodyInterceptor=R,n.UrlBuilder=I,n.UrlResolveInterceptor=P,n.combineURLs=g,n.fetcher=C,n.fetcherRegistrar=O,n.isAbsoluteURL=a,n.mergeRecords=y,n.mergeRequest=v,n.resolveTimeout=b,n.timeoutFetch=F,n.toSorted=l,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(s,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(s=typeof globalThis<"u"?globalThis:s||self,h(s.Fetcher={}))})(this,(function(s){"use strict";function h(r){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(r)}function P(r,e){return h(e)?e:e?r.replace(/\/?\/$/,"")+"/"+e.replace(/^\/+/,""):r}class S{constructor(e){this.baseURL=e}build(e,t){const n=t?.path,o=t?.query,u=P(this.baseURL,e);let i=this.interpolateUrl(u,n);if(o){const E=new URLSearchParams(o).toString();E&&(i+="?"+E)}return i}resolveRequestUrl(e){return this.build(e.url,e.urlParams)}interpolateUrl(e,t){return t?e.replace(/{([^}]+)}/g,(n,o)=>{const u=t[o];if(u===void 0)throw new Error(`Missing required path parameter: ${o}`);return String(u)}):e}}class a extends Error{constructor(e,t){const n=e||t?.message||"An error occurred in the fetcher";super(n),this.cause=t,this.name="FetcherError",t?.stack&&(this.stack=t.stack),Object.setPrototypeOf(this,a.prototype)}}class d extends a{constructor(e,t){const n=t||e.error?.message||`Request to ${e.request.url} failed with no response`;super(n,e.error),this.exchange=e,this.name="FetchError",Object.setPrototypeOf(this,d.prototype)}}class l extends a{constructor(e){const t=e.method||"GET",n=`Request timeout of ${e.timeout}ms exceeded for ${t} ${e.url}`;super(n),this.name="FetchTimeoutError",this.request=e,Object.setPrototypeOf(this,l.prototype)}}function N(r,e){return typeof r<"u"?r:e}async function g(r){const e=r.url,t=r.timeout,n=r;if(!t)return fetch(e,n);const o=new AbortController,u={...n,signal:o.signal};let i=null;const E=new Promise((W,K)=>{i=setTimeout(()=>{i&&clearTimeout(i);const J=new l(r);o.abort(J),K(J)},t)});try{return await Promise.race([fetch(e,u),E])}finally{i&&clearTimeout(i)}}class F{constructor(e,t,n,o){this.attributes={},this.fetcher=e,this.request=t,this.response=n,this.error=o}hasError(){return!!this.error}hasResponse(){return!!this.response}}var c=(r=>(r.GET="GET",r.POST="POST",r.PUT="PUT",r.DELETE="DELETE",r.PATCH="PATCH",r.HEAD="HEAD",r.OPTIONS="OPTIONS",r))(c||{});const Q="Content-Type";var T=(r=>(r.APPLICATION_JSON="application/json",r.TEXT_EVENT_STREAM="text/event-stream",r))(T||{});function R(r,e){if(!(r===void 0&&e===void 0))return e===void 0?r:r===void 0?e:{...r,...e}}const b="UrlResolveInterceptor",O=Number.MIN_SAFE_INTEGER+1e3;class w{constructor(){this.name=b,this.order=O}intercept(e){const t=e.request;t.url=e.fetcher.urlBuilder.resolveRequestUrl(t)}}const U="RequestBodyInterceptor",C=O+1e3;class L{constructor(){this.name=U,this.order=C}intercept(e){const t=e.request;if(t.body===void 0||t.body===null||typeof t.body!="object"||t.body instanceof ArrayBuffer||ArrayBuffer.isView(t.body)||t.body instanceof Blob||t.body instanceof File||t.body instanceof URLSearchParams||t.body instanceof FormData||t.body instanceof ReadableStream)return;const n={...t};n.body=JSON.stringify(t.body),n.headers||(n.headers={});const o=n.headers;o["Content-Type"]||(o["Content-Type"]=T.APPLICATION_JSON),e.request=n}}const q="FetchInterceptor",D=Number.MAX_SAFE_INTEGER-1e3;class M{constructor(){this.name=q,this.order=D}async intercept(e){e.response=await g(e.request)}}function m(r,e){return e?r.filter(e).sort((t,n)=>t.order-n.order):[...r].sort((t,n)=>t.order-n.order)}class f{constructor(e=[]){this.sortedInterceptors=[],this.sortedInterceptors=m(e)}get name(){return this.constructor.name}get order(){return Number.MIN_SAFE_INTEGER}get interceptors(){return[...this.sortedInterceptors]}use(e){return this.sortedInterceptors.some(t=>t.name===e.name)?!1:(this.sortedInterceptors=m([...this.sortedInterceptors,e]),!0)}eject(e){const t=this.sortedInterceptors;return this.sortedInterceptors=m(t,n=>n.name!==e),t.length!==this.sortedInterceptors.length}clear(){this.sortedInterceptors=[]}async intercept(e){for(const t of this.sortedInterceptors)await t.intercept(e)}}class y extends a{constructor(e){super(`Request failed with status code ${e.response?.status} for ${e.request.url}`),this.exchange=e,this.name="HttpStatusValidationError",Object.setPrototypeOf(this,y.prototype)}}const Y=r=>r>=200&&r<300,v="ValidateStatusInterceptor",V=Number.MAX_SAFE_INTEGER-1e3;class B{constructor(e=Y){this.validateStatus=e}get name(){return v}get order(){return V}intercept(e){if(!e.response)return;const t=e.response.status;if(!this.validateStatus(t))throw new y(e)}}class I extends a{constructor(e){const t=e.error?.message||e.response?.statusText||`Request to ${e.request.url} failed during exchange`;super(t,e.error),this.exchange=e,this.name="ExchangeError",Object.setPrototypeOf(this,I.prototype)}}class H{constructor(){this.request=new f([new w,new L,new M]),this.response=new f([new B]),this.error=new f}async exchange(e){try{return await this.request.intercept(e),await this.response.intercept(e),e}catch(t){if(e.error=t,await this.error.intercept(e),!e.hasError())return e;throw new I(e)}}}const _={"Content-Type":T.APPLICATION_JSON},A={baseURL:"",headers:_};class j{constructor(e=A){this.headers=_,this.urlBuilder=new S(e.baseURL),this.headers=e.headers??_,this.timeout=e.timeout,this.interceptors=e.interceptors??new H}async fetch(e,t={}){const n=t;n.url=e;const o=await this.request(n);if(!o.response)throw new d(o,`Request to ${n.url} failed with no response`);return o.response}async request(e){const t=R(e.headers,this.headers),n={...e,headers:t,timeout:N(e.timeout,this.timeout)},o=new F(this,n);return this.interceptors.exchange(o)}async methodFetch(e,t,n={}){return this.fetch(t,{...n,method:e})}async get(e,t={}){return this.methodFetch(c.GET,e,t)}async post(e,t={}){return this.methodFetch(c.POST,e,t)}async put(e,t={}){return this.methodFetch(c.PUT,e,t)}async delete(e,t={}){return this.methodFetch(c.DELETE,e,t)}async patch(e,t={}){return this.methodFetch(c.PATCH,e,t)}async head(e,t={}){return this.methodFetch(c.HEAD,e,t)}async options(e,t={}){return this.methodFetch(c.OPTIONS,e,t)}}const p="default";class ${constructor(){this.registrar=new Map}register(e,t){this.registrar.set(e,t)}unregister(e){return this.registrar.delete(e)}get(e){return this.registrar.get(e)}requiredGet(e){const t=this.get(e);if(!t)throw new Error(`Fetcher ${e} not found`);return t}get default(){return this.requiredGet(p)}set default(e){this.register(p,e)}get fetchers(){return new Map(this.registrar)}}const G=new $;function X(r,e){if(Object.keys(r).length===0)return e;if(Object.keys(e).length===0)return r;const t={path:R(r.urlParams?.path,e.urlParams?.path),query:R(r.urlParams?.query,e.urlParams?.query)},n={...r.headers,...e.headers},o=e.method??r.method,u=e.body??r.body,i=e.timeout??r.timeout,E=e.signal??r.signal;return{...r,...e,method:o,urlParams:t,headers:n,body:u,timeout:i,signal:E}}class k extends j{constructor(e,t=A){super(t),this.name=e,G.register(e,this)}}const z=new k(p);s.ContentTypeHeader=Q,s.ContentTypeValues=T,s.DEFAULT_FETCHER_NAME=p,s.DEFAULT_OPTIONS=A,s.ExchangeError=I,s.FETCH_INTERCEPTOR_NAME=q,s.FETCH_INTERCEPTOR_ORDER=D,s.FetchError=d,s.FetchExchange=F,s.FetchInterceptor=M,s.FetchTimeoutError=l,s.Fetcher=j,s.FetcherError=a,s.FetcherRegistrar=$,s.HttpMethod=c,s.HttpStatusValidationError=y,s.InterceptorManager=H,s.InterceptorRegistry=f,s.NamedFetcher=k,s.REQUEST_BODY_INTERCEPTOR_NAME=U,s.REQUEST_BODY_INTERCEPTOR_ORDER=C,s.RequestBodyInterceptor=L,s.URL_RESOLVE_INTERCEPTOR_NAME=b,s.URL_RESOLVE_INTERCEPTOR_ORDER=O,s.UrlBuilder=S,s.UrlResolveInterceptor=w,s.VALIDATE_STATUS_INTERCEPTOR_NAME=v,s.VALIDATE_STATUS_INTERCEPTOR_ORDER=V,s.ValidateStatusInterceptor=B,s.combineURLs=P,s.fetcher=z,s.fetcherRegistrar=G,s.isAbsoluteURL=h,s.mergeRecords=R,s.mergeRequest=X,s.resolveTimeout=N,s.timeoutFetch=g,s.toSorted=m,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
@@ -26,14 +26,21 @@ export interface Interceptor extends NamedCapable, OrderedCapable {
26
26
  /**
27
27
  * Unique identifier for the interceptor.
28
28
  *
29
- * Used by InterceptorManager to manage interceptors, including adding, removing,
29
+ * Used by InterceptorRegistry to manage interceptors, including adding, removing,
30
30
  * and preventing duplicates. Each interceptor must have a unique name.
31
31
  */
32
- name: string;
32
+ readonly name: string;
33
+ /**
34
+ * Interceptor method that modifies the request or response.
35
+ *
36
+ * @param exchange - The current exchange object, which contains the request and response.
37
+ * @returns A promise that resolves to the modified exchange object.
38
+ */
39
+ readonly order: number;
33
40
  /**
34
41
  * Process the exchange object in the interceptor pipeline.
35
42
  *
36
- * This method is called by InterceptorManager to process the exchange object.
43
+ * This method is called by InterceptorRegistry to process the exchange object.
37
44
  * Interceptors can modify request, response, or error properties directly.
38
45
  *
39
46
  * @param exchange - The exchange object containing request, response, and error information
@@ -45,47 +52,123 @@ export interface Interceptor extends NamedCapable, OrderedCapable {
45
52
  intercept(exchange: FetchExchange): void | Promise<void>;
46
53
  }
47
54
  /**
48
- * Manager for a collection of interceptors of the same type.
55
+ * Interface for request interceptors.
56
+ *
57
+ * Request interceptors are executed before the HTTP request is sent.
58
+ * They can modify the request configuration, add headers, or perform
59
+ * other preprocessing tasks.
60
+ *
61
+ * @example
62
+ * // Example of a request interceptor that adds an authorization header
63
+ * const authInterceptor: RequestInterceptor = {
64
+ * name: 'AuthorizationInterceptor',
65
+ * order: 100,
66
+ * async intercept(exchange: FetchExchange): Promise<void> {
67
+ * const token = getAuthToken();
68
+ * if (token) {
69
+ * exchange.request.headers = {
70
+ * ...exchange.request.headers,
71
+ * 'Authorization': `Bearer ${token}`
72
+ * };
73
+ * }
74
+ * }
75
+ * };
76
+ */
77
+ export interface RequestInterceptor extends Interceptor {
78
+ }
79
+ /**
80
+ * Interface for response interceptors.
81
+ *
82
+ * Response interceptors are executed after the HTTP response is received
83
+ * but before it's processed by the application. They can modify the response,
84
+ * transform data, or handle response-specific logic.
85
+ *
86
+ * @example
87
+ * // Example of a response interceptor that parses JSON data
88
+ * const jsonInterceptor: ResponseInterceptor = {
89
+ * name: 'JsonResponseInterceptor',
90
+ * order: 100,
91
+ * async intercept(exchange: FetchExchange): Promise<void> {
92
+ * if (exchange.response && exchange.response.headers.get('content-type')?.includes('application/json')) {
93
+ * const data = await exchange.response.json();
94
+ * // Attach parsed data to a custom property
95
+ * (exchange.response as any).jsonData = data;
96
+ * }
97
+ * }
98
+ * };
99
+ */
100
+ export interface ResponseInterceptor extends Interceptor {
101
+ }
102
+ /**
103
+ * Interface for error interceptors.
104
+ *
105
+ * Error interceptors are executed when an HTTP request fails.
106
+ * They can handle errors, transform them, or implement retry logic.
107
+ *
108
+ * @example
109
+ * // Example of an error interceptor that retries failed requests
110
+ * const retryInterceptor: ErrorInterceptor = {
111
+ * name: 'RetryInterceptor',
112
+ * order: 100,
113
+ * async intercept(exchange: FetchExchange): Promise<void> {
114
+ * if (exchange.error && isRetryableError(exchange.error)) {
115
+ * // Implement retry logic
116
+ * const retryCount = (exchange.request as any).retryCount || 0;
117
+ * if (retryCount < 3) {
118
+ * (exchange.request as any).retryCount = retryCount + 1;
119
+ * // Retry the request
120
+ * exchange.response = await fetch(exchange.request);
121
+ * // Clear the error since we've recovered
122
+ * exchange.error = undefined;
123
+ * }
124
+ * }
125
+ * }
126
+ * };
127
+ */
128
+ export interface ErrorInterceptor extends Interceptor {
129
+ }
130
+ /**
131
+ * Registry for a collection of interceptors of the same type.
49
132
  *
50
133
  * Handles adding, removing, and executing interceptors in the correct order.
51
- * Each InterceptorManager instance manages one type of interceptor (request, response, or error).
134
+ * Each InterceptorRegistry instance manages one type of interceptor (request, response, or error).
52
135
  *
53
136
  * @remarks
54
137
  * Interceptors are executed in ascending order of their `order` property.
55
138
  * Interceptors with the same order value are executed in the order they were added.
56
139
  *
57
140
  * @example
58
- * // Create an interceptor manager with initial interceptors
59
- * const requestManager = new InterceptorManager([interceptor1, interceptor2]);
141
+ * // Create an interceptor registry with initial interceptors
142
+ * const requestRegistry = new InterceptorRegistry([interceptor1, interceptor2]);
60
143
  *
61
144
  * // Add a new interceptor
62
- * requestManager.use(newInterceptor);
145
+ * requestRegistry.use(newInterceptor);
63
146
  *
64
147
  * // Remove an interceptor by name
65
- * requestManager.eject('InterceptorName');
148
+ * requestRegistry.eject('InterceptorName');
66
149
  *
67
150
  * // Process an exchange through all interceptors
68
- * const result = await requestManager.intercept(exchange);
151
+ * const result = await requestRegistry.intercept(exchange);
69
152
  */
70
- export declare class InterceptorManager implements Interceptor {
153
+ export declare class InterceptorRegistry implements Interceptor {
71
154
  /**
72
- * Gets the name of this interceptor manager.
155
+ * Gets the name of this interceptor registry.
73
156
  *
74
157
  * @returns The constructor name of this class
75
158
  */
76
159
  get name(): string;
77
160
  /**
78
- * Gets the order of this interceptor manager.
161
+ * Gets the order of this interceptor registry.
79
162
  *
80
- * @returns Number.MIN_SAFE_INTEGER, indicating this manager should execute early
163
+ * @returns Number.MIN_SAFE_INTEGER, indicating this registry should execute early
81
164
  */
82
165
  get order(): number;
83
166
  /**
84
- * Array of interceptors managed by this manager, sorted by their order property.
167
+ * Array of interceptors managed by this registry, sorted by their order property.
85
168
  */
86
169
  private sortedInterceptors;
87
170
  /**
88
- * Initializes a new InterceptorManager instance.
171
+ * Initializes a new InterceptorRegistry instance.
89
172
  *
90
173
  * @param interceptors - Initial array of interceptors to manage
91
174
  *
@@ -95,7 +178,11 @@ export declare class InterceptorManager implements Interceptor {
95
178
  */
96
179
  constructor(interceptors?: Interceptor[]);
97
180
  /**
98
- * Adds an interceptor to this manager.
181
+ * Returns an array of all interceptors in the registry.
182
+ */
183
+ get interceptors(): Interceptor[];
184
+ /**
185
+ * Adds an interceptor to this registry.
99
186
  *
100
187
  * @param interceptor - The interceptor to add
101
188
  * @returns True if the interceptor was added, false if an interceptor with the
@@ -103,7 +190,7 @@ export declare class InterceptorManager implements Interceptor {
103
190
  *
104
191
  * @remarks
105
192
  * Interceptors are uniquely identified by their name property. Attempting to add
106
- * an interceptor with a name that already exists in the manager will fail.
193
+ * an interceptor with a name that already exists in the registry will fail.
107
194
  *
108
195
  * After adding, interceptors are automatically sorted by their order property.
109
196
  */
@@ -117,7 +204,7 @@ export declare class InterceptorManager implements Interceptor {
117
204
  */
118
205
  eject(name: string): boolean;
119
206
  /**
120
- * Removes all interceptors from this manager.
207
+ * Removes all interceptors from this registry.
121
208
  */
122
209
  clear(): void;
123
210
  /**
@@ -136,79 +223,4 @@ export declare class InterceptorManager implements Interceptor {
136
223
  */
137
224
  intercept(exchange: FetchExchange): Promise<void>;
138
225
  }
139
- /**
140
- * Collection of interceptor managers for the Fetcher client.
141
- *
142
- * Manages three types of interceptors:
143
- * 1. Request interceptors - Process requests before sending HTTP requests
144
- * 2. Response interceptors - Process responses after receiving HTTP responses
145
- * 3. Error interceptors - Handle errors when they occur during the request process
146
- *
147
- * Each type of interceptor is managed by an InterceptorManager instance, supporting
148
- * adding, removing, and executing interceptors.
149
- *
150
- * @example
151
- * // Create a custom interceptor
152
- * const customRequestInterceptor: Interceptor = {
153
- * name: 'CustomRequestInterceptor',
154
- * order: 100,
155
- * async intercept(exchange: FetchExchange): Promise<FetchExchange> {
156
- * // Modify request headers
157
- * exchange.request.headers = {
158
- * ...exchange.request.headers,
159
- * 'X-Custom-Header': 'custom-value'
160
- * };
161
- * return exchange;
162
- * }
163
- * };
164
- *
165
- * // Add interceptor to Fetcher
166
- * const fetcher = new Fetcher();
167
- * fetcher.interceptors.request.use(customRequestInterceptor);
168
- *
169
- * @remarks
170
- * By default, the request interceptor manager has three built-in interceptors registered:
171
- * 1. UrlResolveInterceptor - Resolves the final URL with parameters
172
- * 2. RequestBodyInterceptor - Automatically converts object-type request bodies to JSON strings
173
- * 3. FetchInterceptor - Executes actual HTTP requests and handles timeouts
174
- */
175
- export declare class FetcherInterceptors {
176
- /**
177
- * Manager for request-phase interceptors.
178
- *
179
- * Executed before HTTP requests are sent. Contains three built-in interceptors by default:
180
- * UrlResolveInterceptor, RequestBodyInterceptor, and FetchInterceptor.
181
- *
182
- * @remarks
183
- * Request interceptors are executed in ascending order of their order values, with smaller
184
- * values having higher priority. The default interceptors are:
185
- * 1. UrlResolveInterceptor (order: Number.MIN_SAFE_INTEGER) - Resolves the final URL
186
- * 2. RequestBodyInterceptor (order: 0) - Converts object bodies to JSON
187
- * 3. FetchInterceptor (order: Number.MAX_SAFE_INTEGER) - Executes the actual HTTP request
188
- */
189
- request: InterceptorManager;
190
- /**
191
- * Manager for response-phase interceptors.
192
- *
193
- * Executed after HTTP responses are received. Empty by default, custom response processing
194
- * logic can be added as needed.
195
- *
196
- * @remarks
197
- * Response interceptors are executed in ascending order of their order values, with smaller
198
- * values having higher priority.
199
- */
200
- response: InterceptorManager;
201
- /**
202
- * Manager for error-handling phase interceptors.
203
- *
204
- * Executed when errors occur during HTTP requests. Empty by default, custom error handling
205
- * logic can be added as needed.
206
- *
207
- * @remarks
208
- * Error interceptors are executed in ascending order of their order values, with smaller
209
- * values having higher priority. Error interceptors can transform errors into normal responses,
210
- * avoiding thrown exceptions.
211
- */
212
- error: InterceptorManager;
213
- }
214
226
  //# sourceMappingURL=interceptor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../src/interceptor.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,cAAc,EAAY,MAAM,kBAAkB,CAAC;AAG5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,WAAY,SAAQ,YAAY,EAAE,cAAc;IAC/D;;;;;OAKG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1D;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,kBAAmB,YAAW,WAAW;IACpD;;;;OAIG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;OAIG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;OAEG;IACH,OAAO,CAAC,kBAAkB,CAAqB;IAE/C;;;;;;;;OAQG;gBACS,YAAY,GAAE,WAAW,EAAO;IAI5C;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO;IAWtC;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAS5B;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;;;;;;;;;;;;OAaG;IACG,SAAS,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAMxD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,mBAAmB;IAC9B;;;;;;;;;;;;OAYG;IACH,OAAO,EAAE,kBAAkB,CAIxB;IAEH;;;;;;;;;OASG;IACH,QAAQ,EAAE,kBAAkB,CAA4B;IAExD;;;;;;;;;;OAUG;IACH,KAAK,EAAE,kBAAkB,CAA4B;CACtD"}
1
+ {"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../src/interceptor.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,cAAc,EAAY,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,WAAY,SAAQ,YAAY,EAAE,cAAc;IAC/D;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1D;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,MAAM,WAAW,kBAAmB,SAAQ,WAAW;CACtD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,WAAW,mBAAoB,SAAQ,WAAW;CACvD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,MAAM,WAAW,gBAAiB,SAAQ,WAAW;CACpD;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,mBAAoB,YAAW,WAAW;IACrD;;;;OAIG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;OAIG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;OAEG;IACH,OAAO,CAAC,kBAAkB,CAAqB;IAE/C;;;;;;;;OAQG;gBACS,YAAY,GAAE,WAAW,EAAO;IAI5C;;OAEG;IACH,IAAI,YAAY,IAAI,WAAW,EAAE,CAEhC;IAED;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO;IAWtC;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAS5B;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;;;;;;;;;;;;OAaG;IACG,SAAS,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAMxD"}
@@ -0,0 +1,200 @@
1
+ import { FetchExchange } from './fetchExchange';
2
+ import { FetcherError } from './fetcherError';
3
+ import { InterceptorRegistry } from './interceptor';
4
+ /**
5
+ * Custom error class for FetchExchange related errors.
6
+ *
7
+ * This error is thrown when there are issues with the HTTP exchange process,
8
+ * such as when a request fails and no response is generated. It provides
9
+ * comprehensive information about the failed request through the exchange object.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * try {
14
+ * await fetcher.get('/api/users');
15
+ * } catch (error) {
16
+ * if (error instanceof ExchangeError) {
17
+ * console.log('Request URL:', error.exchange.request.url);
18
+ * console.log('Request method:', error.exchange.request.method);
19
+ * if (error.exchange.error) {
20
+ * console.log('Underlying error:', error.exchange.error);
21
+ * }
22
+ * }
23
+ * }
24
+ * ```
25
+ */
26
+ export declare class ExchangeError extends FetcherError {
27
+ readonly exchange: FetchExchange;
28
+ /**
29
+ * Creates a new ExchangeError instance.
30
+ *
31
+ * @param exchange - The FetchExchange object containing request/response/error information.
32
+ */
33
+ constructor(exchange: FetchExchange);
34
+ }
35
+ /**
36
+ * Collection of interceptor managers for the Fetcher client.
37
+ *
38
+ * Manages three types of interceptors:
39
+ * 1. Request interceptors - Process requests before sending HTTP requests
40
+ * 2. Response interceptors - Process responses after receiving HTTP responses
41
+ * 3. Error interceptors - Handle errors when they occur during the request process
42
+ *
43
+ * Each type of interceptor is managed by an InterceptorRegistry instance, supporting
44
+ * adding, removing, and executing interceptors.
45
+ *
46
+ * @example
47
+ * // Create a custom interceptor
48
+ * const customRequestInterceptor: Interceptor = {
49
+ * name: 'CustomRequestInterceptor',
50
+ * order: 100,
51
+ * async intercept(exchange: FetchExchange): Promise<FetchExchange> {
52
+ * // Modify request headers
53
+ * exchange.request.headers = {
54
+ * ...exchange.request.headers,
55
+ * 'X-Custom-Header': 'custom-value'
56
+ * };
57
+ * return exchange;
58
+ * }
59
+ * };
60
+ *
61
+ * // Add interceptor to Fetcher
62
+ * const fetcher = new Fetcher();
63
+ * fetcher.interceptors.request.use(customRequestInterceptor);
64
+ *
65
+ * @remarks
66
+ * By default, the request interceptor registry has three built-in interceptors registered:
67
+ * 1. UrlResolveInterceptor - Resolves the final URL with parameters
68
+ * 2. RequestBodyInterceptor - Automatically converts object-type request bodies to JSON strings
69
+ * 3. FetchInterceptor - Executes actual HTTP requests and handles timeouts
70
+ */
71
+ export declare class InterceptorManager {
72
+ /**
73
+ * Registry for request-phase interceptors.
74
+ *
75
+ * Executed before HTTP requests are sent. Contains three built-in interceptors by default:
76
+ * UrlResolveInterceptor, RequestBodyInterceptor, and FetchInterceptor.
77
+ *
78
+ * @remarks
79
+ * Request interceptors are executed in ascending order of their order values, with smaller
80
+ * values having higher priority. The default interceptors are:
81
+ * 1. UrlResolveInterceptor (order: Number.MIN_SAFE_INTEGER) - Resolves the final URL
82
+ * 2. RequestBodyInterceptor (order: 0) - Converts object bodies to JSON
83
+ * 3. FetchInterceptor (order: Number.MAX_SAFE_INTEGER) - Executes the actual HTTP request
84
+ */
85
+ readonly request: InterceptorRegistry;
86
+ /**
87
+ * Manager for response-phase interceptors.
88
+ *
89
+ * Executed after HTTP responses are received. Contains ValidateStatusInterceptor by default
90
+ * which validates HTTP status codes and throws errors for invalid statuses.
91
+ *
92
+ * @remarks
93
+ * Response interceptors are executed in ascending order of their order values, with smaller
94
+ * values having higher priority.
95
+ *
96
+ * By default, the response interceptor registry has one built-in interceptor registered:
97
+ * 1. ValidateStatusInterceptor - Validates HTTP status codes and throws HttpStatusValidationError for invalid statuses
98
+ */
99
+ readonly response: InterceptorRegistry;
100
+ /**
101
+ * Manager for error-handling phase interceptors.
102
+ *
103
+ * Executed when errors occur during HTTP requests. Empty by default, custom error handling
104
+ * logic can be added as needed.
105
+ *
106
+ * @remarks
107
+ * Error interceptors are executed in ascending order of their order values, with smaller
108
+ * values having higher priority. Error interceptors can transform errors into normal responses,
109
+ * avoiding thrown exceptions.
110
+ */
111
+ readonly error: InterceptorRegistry;
112
+ /**
113
+ * Processes a FetchExchange through the interceptor pipeline.
114
+ *
115
+ * This method is the core of the Fetcher's interceptor system. It executes the three
116
+ * phases of interceptors in sequence:
117
+ * 1. Request interceptors - Process the request before sending
118
+ * 2. Response interceptors - Process the response after receiving
119
+ * 3. Error interceptors - Handle any errors that occurred during the process
120
+ *
121
+ * The interceptor pipeline follows the Chain of Responsibility pattern, where each
122
+ * interceptor can modify the exchange object and decide whether to continue or
123
+ * terminate the chain.
124
+ *
125
+ * @param fetchExchange - The exchange object containing request, response, and error information
126
+ * @returns Promise that resolves to the processed FetchExchange
127
+ * @throws ExchangeError if an unhandled error occurs during processing
128
+ *
129
+ * @remarks
130
+ * The method handles three distinct phases:
131
+ *
132
+ * 1. Request Phase: Executes request interceptors which can modify headers, URL, body, etc.
133
+ * Built-in interceptors handle URL resolution, body serialization, and actual HTTP execution.
134
+ *
135
+ * 2. Response Phase: Executes response interceptors which can transform or validate responses.
136
+ * These interceptors only run if the request phase completed without throwing.
137
+ *
138
+ * 3. Error Phase: Executes error interceptors when any phase throws an error. Error interceptors
139
+ * can handle errors by clearing the error property. If error interceptors clear the error,
140
+ * the exchange is returned successfully.
141
+ *
142
+ * Error Handling:
143
+ * - If any interceptor throws an error, the error phase is triggered
144
+ * - Error interceptors can "fix" errors by clearing the error property on the exchange
145
+ * - If errors remain after error interceptors run, they are wrapped in ExchangeError
146
+ *
147
+ * Order of Execution:
148
+ * 1. Request interceptors (sorted by order property, ascending)
149
+ * 2. Response interceptors (sorted by order property, ascending) - only if no error in request phase
150
+ * 3. Error interceptors (sorted by order property, ascending) - only if an error occurred
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * // Create a fetcher with custom interceptors
155
+ * const fetcher = new Fetcher();
156
+ *
157
+ * // Add a request interceptor
158
+ * fetcher.interceptors.request.use({
159
+ * name: 'AuthInterceptor',
160
+ * order: 100,
161
+ * async intercept(exchange: FetchExchange) {
162
+ * exchange.request.headers = {
163
+ * ...exchange.request.headers,
164
+ * 'Authorization': 'Bearer ' + getToken()
165
+ * };
166
+ * }
167
+ * });
168
+ *
169
+ * // Add a response interceptor
170
+ * fetcher.interceptors.response.use({
171
+ * name: 'ResponseLogger',
172
+ * order: 100,
173
+ * async intercept(exchange: FetchExchange) {
174
+ * console.log(`Response status: ${exchange.response?.status}`);
175
+ * }
176
+ * });
177
+ *
178
+ * // Add an error interceptor
179
+ * fetcher.interceptors.error.use({
180
+ * name: 'ErrorLogger',
181
+ * order: 100,
182
+ * async intercept(exchange: FetchExchange) {
183
+ * console.error(`Request to ${exchange.request.url} failed:`, exchange.error);
184
+ * // Clear the error to indicate it's been handled
185
+ * exchange.error = undefined;
186
+ * }
187
+ * });
188
+ *
189
+ * // Create and process an exchange
190
+ * const request: FetchRequest = {
191
+ * url: '/api/users',
192
+ * method: HttpMethod.GET
193
+ * };
194
+ * const exchange = new FetchExchange(fetcher, request);
195
+ * const result = await fetcher.exchange(exchange);
196
+ * ```
197
+ */
198
+ exchange(fetchExchange: FetchExchange): Promise<FetchExchange>;
199
+ }
200
+ //# sourceMappingURL=interceptorManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interceptorManager.d.ts","sourceRoot":"","sources":["../src/interceptorManager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGpD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,aAAc,SAAQ,YAAY;aAMjB,QAAQ,EAAE,aAAa;IALnD;;;;OAIG;gBACyB,QAAQ,EAAE,aAAa;CASpD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,kBAAkB;IAC7B;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAIlC;IAEH;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAEnC;IAEH;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAA6B;IAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqFG;IACG,QAAQ,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;CAqBrE"}
@@ -1,27 +1,45 @@
1
- import { Interceptor } from './interceptor';
1
+ import { RequestInterceptor } from './interceptor';
2
2
  import { FetchExchange } from './fetchExchange';
3
+ /**
4
+ * The name of the RequestBodyInterceptor.
5
+ */
6
+ export declare const REQUEST_BODY_INTERCEPTOR_NAME = "RequestBodyInterceptor";
7
+ /**
8
+ * The order of the RequestBodyInterceptor.
9
+ * Set to URL_RESOLVE_INTERCEPTOR_ORDER + 1000 to ensure it runs early among request interceptors.
10
+ */
11
+ export declare const REQUEST_BODY_INTERCEPTOR_ORDER: number;
3
12
  /**
4
13
  * Interceptor responsible for converting plain objects to JSON strings for HTTP request bodies.
5
14
  *
6
15
  * This interceptor ensures that object request bodies are properly serialized and that
7
16
  * the appropriate Content-Type header is set. It runs early in the request processing chain
8
17
  * to ensure request bodies are properly formatted before other interceptors process them.
18
+ *
19
+ * @remarks
20
+ * This interceptor runs after URL resolution (UrlResolveInterceptor) but before
21
+ * the actual HTTP request is made (FetchInterceptor). The order is set to
22
+ * REQUEST_BODY_INTERCEPTOR_ORDER to ensure it executes in the correct position
23
+ * in the interceptor chain, allowing for other interceptors to run between URL resolution
24
+ * and request body processing. This positioning ensures that URL parameters are resolved
25
+ * first, then request bodies are properly formatted, and finally the HTTP request is executed.
9
26
  */
10
- export declare class RequestBodyInterceptor implements Interceptor {
27
+ export declare class RequestBodyInterceptor implements RequestInterceptor {
11
28
  /**
12
29
  * Interceptor name, used for identification and management.
13
30
  */
14
- name: string;
31
+ readonly name = "RequestBodyInterceptor";
15
32
  /**
16
33
  * Interceptor execution order, set to run after UrlResolveInterceptor but before FetchInterceptor.
17
34
  *
18
35
  * This interceptor should run after URL resolution (UrlResolveInterceptor) but before
19
36
  * the actual HTTP request is made (FetchInterceptor). The order is set to
20
- * Number.MIN_SAFE_INTEGER + 200 to ensure it executes in the correct position
37
+ * REQUEST_BODY_INTERCEPTOR_ORDER to ensure it executes in the correct position
21
38
  * in the interceptor chain, allowing for other interceptors to run between URL resolution
22
- * and request body processing.
39
+ * and request body processing. This positioning ensures that URL parameters are resolved
40
+ * first, then request bodies are properly formatted, and finally the HTTP request is executed.
23
41
  */
24
- order: number;
42
+ readonly order: number;
25
43
  /**
26
44
  * Attempts to convert request body to a valid fetch API body type.
27
45
  *
@@ -1 +1 @@
1
- {"version":3,"file":"requestBodyInterceptor.d.ts","sourceRoot":"","sources":["../src/requestBodyInterceptor.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD;;;;;;GAMG;AACH,qBAAa,sBAAuB,YAAW,WAAW;IACxD;;OAEG;IACH,IAAI,SAA4B;IAEhC;;;;;;;;OAQG;IACH,KAAK,SAAiC;IAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,SAAS,CAAC,QAAQ,EAAE,aAAa;CA0ClC"}
1
+ {"version":3,"file":"requestBodyInterceptor.d.ts","sourceRoot":"","sources":["../src/requestBodyInterceptor.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIhD;;GAEG;AACH,eAAO,MAAM,6BAA6B,2BAA2B,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,8BAA8B,QACL,CAAC;AAEvC;;;;;;;;;;;;;;GAcG;AACH,qBAAa,sBAAuB,YAAW,kBAAkB;IAC/D;;OAEG;IACH,QAAQ,CAAC,IAAI,4BAAiC;IAE9C;;;;;;;;;OASG;IACH,QAAQ,CAAC,KAAK,SAAkC;IAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,SAAS,CAAC,QAAQ,EAAE,aAAa;CA0ClC"}
package/dist/timeout.d.ts CHANGED
@@ -1,30 +1,5 @@
1
1
  import { FetchRequest } from './fetchRequest';
2
- /**
3
- * Interface that defines timeout capability for HTTP requests.
4
- *
5
- * Objects implementing this interface can specify timeout values for HTTP requests.
6
- */
7
- export interface TimeoutCapable {
8
- /**
9
- * Request timeout in milliseconds.
10
- *
11
- * When the value is 0, it indicates no timeout should be set.
12
- * The default value is undefined.
13
- */
14
- timeout?: number;
15
- }
16
- /**
17
- * Resolves request timeout settings, prioritizing request-level timeout settings.
18
- *
19
- * @param requestTimeout - Request-level timeout setting
20
- * @param optionsTimeout - Configuration-level timeout setting
21
- * @returns Resolved timeout setting
22
- *
23
- * @remarks
24
- * If requestTimeout is defined, it takes precedence over optionsTimeout.
25
- * Otherwise, optionsTimeout is returned. If both are undefined, undefined is returned.
26
- */
27
- export declare function resolveTimeout(requestTimeout?: number, optionsTimeout?: number): number | undefined;
2
+ import { FetcherError } from './fetcherError';
28
3
  /**
29
4
  * Exception class thrown when an HTTP request times out.
30
5
  *
@@ -41,7 +16,7 @@ export declare function resolveTimeout(requestTimeout?: number, optionsTimeout?:
41
16
  * }
42
17
  * ```
43
18
  */
44
- export declare class FetchTimeoutError extends Error {
19
+ export declare class FetchTimeoutError extends FetcherError {
45
20
  /**
46
21
  * The request options that timed out.
47
22
  */
@@ -53,6 +28,32 @@ export declare class FetchTimeoutError extends Error {
53
28
  */
54
29
  constructor(request: FetchRequest);
55
30
  }
31
+ /**
32
+ * Interface that defines timeout capability for HTTP requests.
33
+ *
34
+ * Objects implementing this interface can specify timeout values for HTTP requests.
35
+ */
36
+ export interface TimeoutCapable {
37
+ /**
38
+ * Request timeout in milliseconds.
39
+ *
40
+ * When the value is 0, it indicates no timeout should be set.
41
+ * The default value is undefined.
42
+ */
43
+ timeout?: number;
44
+ }
45
+ /**
46
+ * Resolves request timeout settings, prioritizing request-level timeout settings.
47
+ *
48
+ * @param requestTimeout - Request-level timeout setting
49
+ * @param optionsTimeout - Configuration-level timeout setting
50
+ * @returns Resolved timeout setting
51
+ *
52
+ * @remarks
53
+ * If requestTimeout is defined, it takes precedence over optionsTimeout.
54
+ * Otherwise, optionsTimeout is returned. If both are undefined, undefined is returned.
55
+ */
56
+ export declare function resolveTimeout(requestTimeout?: number, optionsTimeout?: number): number | undefined;
56
57
  /**
57
58
  * HTTP request method with timeout control.
58
59
  *
@@ -1 +1 @@
1
- {"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../src/timeout.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,cAAc,CAAC,EAAE,MAAM,EACvB,cAAc,CAAC,EAAE,MAAM,GACtB,MAAM,GAAG,SAAS,CAKpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC;IAEtB;;;;OAIG;gBACS,OAAO,EAAE,YAAY;CASlC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,CAyC3E"}
1
+ {"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../src/timeout.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,iBAAkB,SAAQ,YAAY;IACjD;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC;IAEtB;;;;OAIG;gBACS,OAAO,EAAE,YAAY;CASlC;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,cAAc,CAAC,EAAE,MAAM,EACvB,cAAc,CAAC,EAAE,MAAM,GACtB,MAAM,GAAG,SAAS,CAKpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,CAyC3E"}