@ahoo-wang/fetcher 0.6.8 → 0.8.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.
@@ -0,0 +1,59 @@
1
+ import { FetchExchange, Interceptor } from './interceptor';
2
+ /**
3
+ * FetchInterceptor Class
4
+ *
5
+ * This is an interceptor implementation responsible for executing actual HTTP requests
6
+ * and handling timeout control. It is the last interceptor in the Fetcher request
7
+ * processing chain, ensuring that the actual network request is executed after all
8
+ * previous interceptors have completed processing.
9
+ *
10
+ * @example
11
+ * // Usually not created manually as Fetcher uses it automatically
12
+ * const fetcher = new Fetcher();
13
+ * // FetchInterceptor is automatically registered in fetcher.interceptors.request
14
+ */
15
+ export declare class FetchInterceptor implements Interceptor {
16
+ /**
17
+ * Interceptor name, used to identify and manage interceptor instances
18
+ *
19
+ * @remarks
20
+ * Each interceptor must have a unique name for identification and manipulation
21
+ * within the interceptor manager
22
+ */
23
+ name: string;
24
+ /**
25
+ * Interceptor execution order, set to maximum safe integer to ensure last execution
26
+ *
27
+ * @remarks
28
+ * Since this is the interceptor that actually executes HTTP requests, it should
29
+ * execute after all other request interceptors, so its order is set to
30
+ * Number.MAX_SAFE_INTEGER
31
+ */
32
+ order: number;
33
+ /**
34
+ * Intercept and process HTTP requests
35
+ *
36
+ * Executes the actual HTTP request and applies timeout control. This is the final
37
+ * step in the request processing chain, responsible for calling the timeoutFetch
38
+ * function to send the network request.
39
+ *
40
+ * @param exchange - Exchange object containing request information
41
+ * @returns Promise<FetchExchange> Processed exchange object containing response information
42
+ *
43
+ * @throws {FetchTimeoutError} Throws timeout exception when request times out
44
+ *
45
+ * @example
46
+ * // Usually called internally by Fetcher
47
+ * const exchange = {
48
+ * url: 'https://api.example.com/users',
49
+ * request: {
50
+ * method: 'GET',
51
+ * timeout: 5000
52
+ * }
53
+ * };
54
+ * const result = await fetchInterceptor.intercept(exchange);
55
+ * console.log(result.response); // HTTP response object
56
+ */
57
+ intercept(exchange: FetchExchange): Promise<FetchExchange>;
58
+ }
59
+ //# sourceMappingURL=fetchInterceptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchInterceptor.d.ts","sourceRoot":"","sources":["../src/fetchInterceptor.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG3D;;;;;;;;;;;;GAYG;AACH,qBAAa,gBAAiB,YAAW,WAAW;IAClD;;;;;;OAMG;IACH,IAAI,SAAsB;IAE1B;;;;;;;OAOG;IACH,KAAK,SAA2B;IAEhC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,SAAS,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;CAQjE"}
package/dist/fetcher.d.ts CHANGED
@@ -131,18 +131,6 @@ export declare class Fetcher implements HeadersCapable, TimeoutCapable {
131
131
  * @throws Throws an exception when an error occurs during the request and is not handled by error interceptors
132
132
  */
133
133
  request(url: string, request?: FetcherRequest): Promise<FetchExchange>;
134
- /**
135
- * HTTP request method with timeout control
136
- *
137
- * This method uses Promise.race to implement timeout control, initiating both
138
- * fetch request and timeout Promise simultaneously. When either Promise completes,
139
- * it returns the result or throws an exception.
140
- *
141
- * @param exchange - The exchange containing request information
142
- * @returns Promise<Response> HTTP response Promise
143
- * @throws FetchTimeoutError Thrown when the request times out
144
- */
145
- private timeoutFetch;
146
134
  /**
147
135
  * Make an HTTP request with the specified method
148
136
  *
@@ -1 +1 @@
1
- {"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../src/fetcher.ts"],"names":[],"mappings":"AAcA,OAAO,EAAqC,cAAc,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EACL,cAAc,EAGd,cAAc,EAEd,YAAY,EACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,cACf,SAAQ,c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;OAMG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,MAAM,GAAG,YAAY,CAAC,IAAI,CAAM,GAC1E,OAAO,CAAC,QAAQ,CAAC;IAIpB;;;;;;OAMG;IACG,IAAI,CACR,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,MAAM,CAAM,GACtD,OAAO,CAAC,QAAQ,CAAC;IAIpB;;;;;;OAMG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,MAAM,CAAM,GACtD,OAAO,CAAC,QAAQ,CAAC;IAIpB;;;;;;OAMG;IACG,MAAM,CACV,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,MAAM,CAAM,GACtD,OAAO,CAAC,QAAQ,CAAC;IAIpB;;;;;;OAMG;IACG,KAAK,CACT,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,MAAM,CAAM,GACtD,OAAO,CAAC,QAAQ,CAAC;IAIpB;;;;;;OAMG;IACG,IAAI,CACR,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,MAAM,GAAG,YAAY,CAAC,IAAI,CAAM,GAC1E,OAAO,CAAC,QAAQ,CAAC;IAIpB;;;;;;OAMG;IACG,OAAO,CACX,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,MAAM,GAAG,YAAY,CAAC,IAAI,CAAM,GAC1E,OAAO,CAAC,QAAQ,CAAC;CAGrB"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './fetcher';
2
2
  export * from './fetcherRegistrar';
3
+ export * from './fetchInterceptor';
3
4
  export * from './interceptor';
4
5
  export * from './mergeRequest';
5
6
  export * from './namedFetcher';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}