@ureq/core 0.0.3-alpha.0 → 0.0.4

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 ADDED
@@ -0,0 +1,114 @@
1
+ # @ureq/core
2
+
3
+ 核心请求库,提供统一的请求接口和功能组合。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @ureq/core @ureq/impl-fetch
9
+ # 或
10
+ pnpm add @ureq/core @ureq/impl-fetch
11
+ ```
12
+
13
+ ## 快速开始
14
+
15
+ ```typescript
16
+ import { Request } from '@ureq/core';
17
+ import { FetchRequestor } from '@ureq/impl-fetch';
18
+
19
+ // 创建请求实例
20
+ const request = new Request(new FetchRequestor({
21
+ baseURL: 'https://jsonplaceholder.typicode.com/todos/1'
22
+ }));
23
+
24
+ // 发起请求
25
+ const data = await request.get('/users');
26
+ ```
27
+
28
+ ## 功能特性
29
+
30
+ - 🎯 **多种实现支持** - 支持 Fetch 和 Axios
31
+ - 🔄 **智能重试** - 自动重试失败的请求
32
+ - 💾 **请求缓存** - 内置缓存机制
33
+ - 🚦 **拦截器** - 请求和响应拦截
34
+ - ⚡ **并发控制** - 限制并发请求数量
35
+ - 🔒 **幂等性保证** - 自动去重相同请求
36
+ - ⏱️ **超时控制** - 灵活的超时配置
37
+
38
+ ## 配置选项
39
+
40
+ ```typescript
41
+ const request = new Request(
42
+ new FetchRequestor({
43
+ baseURL: 'https://jsonplaceholder.typicode.com/todos/1'
44
+ }),
45
+ {
46
+ retry: {
47
+ maxRetries: 3,
48
+ retryDelay: 1000
49
+ },
50
+ cache: {
51
+ ttl: 60000
52
+ },
53
+ timeout: {
54
+ timeout: 5000
55
+ },
56
+ parallel: {
57
+ maxConcurrent: 5
58
+ },
59
+ idempotent: {
60
+ dedupeTime: 1000
61
+ }
62
+ }
63
+ );
64
+ ```
65
+
66
+ ## 拦截器
67
+
68
+ ```typescript
69
+ // 请求拦截器
70
+ request.interceptors.addRequestInterceptor({
71
+ onRequest: (config) => {
72
+ config.headers = {
73
+ ...config.headers,
74
+ 'Authorization': `Bearer ${token}`
75
+ };
76
+ return config;
77
+ }
78
+ });
79
+
80
+ // 响应拦截器
81
+ request.interceptors.addResponseInterceptor({
82
+ onResponse: (response) => {
83
+ console.log('Response:', response.status);
84
+ return response;
85
+ },
86
+ onResponseError: (error) => {
87
+ console.error('Error:', error);
88
+ throw error;
89
+ }
90
+ });
91
+ ```
92
+
93
+ ## API
94
+
95
+ ### Request 类
96
+
97
+ - `get<T>(url, options?)` - GET 请求
98
+ - `post<T>(url, data?, options?)` - POST 请求
99
+ - `put<T>(url, data?, options?)` - PUT 请求
100
+ - `delete<T>(url, options?)` - DELETE 请求
101
+ - `patch<T>(url, data?, options?)` - PATCH 请求
102
+
103
+ ### 拦截器
104
+
105
+ - `interceptors.addRequestInterceptor(interceptor)` - 添加请求拦截器
106
+ - `interceptors.addResponseInterceptor(interceptor)` - 添加响应拦截器
107
+
108
+ ## 文档
109
+
110
+ 查看完整文档:[https://sunny-117.github.io/ureq](https://sunny-117.github.io/ureq)
111
+
112
+ ## License
113
+
114
+ MIT
package/dist/index.d.mts CHANGED
@@ -1,8 +1,27 @@
1
+ /**
2
+ * 响应类型
3
+ */
4
+ type ResponseType = 'json' | 'text' | 'blob' | 'arraybuffer' | 'formData';
5
+ /**
6
+ * 响应转换器函数类型
7
+ * @param response 原始响应对象(Fetch Response 或其他)
8
+ * @returns 转换后的数据
9
+ */
10
+ type ResponseTransformer<T = any> = (response: any) => Promise<T>;
1
11
  interface RequestOptions {
2
12
  headers?: Record<string, string>;
3
13
  timeout?: number;
4
14
  signal?: AbortSignal;
5
- responseType?: 'arraybuffer' | 'json' | 'text' | 'blob';
15
+ /**
16
+ * 响应类型,用于指定如何解析响应体
17
+ * @default 'json'
18
+ */
19
+ responseType?: ResponseType;
20
+ /**
21
+ * 自定义响应转换器,优先级高于 responseType
22
+ * 当需要自定义响应解析逻辑时使用
23
+ */
24
+ responseTransformer?: ResponseTransformer;
6
25
  [key: string]: any;
7
26
  }
8
27
  interface Response<T = any> {
@@ -206,4 +225,4 @@ declare function formatError(error: RequestError): string;
206
225
  */
207
226
  declare function getErrorDetails(error: RequestError): Record<string, any>;
208
227
 
209
- export { AbortError, type CacheOptions, type CacheStore, DefaultHashService, type ErrorContext, type HashService, HttpError, type IdempotentOptions, InterceptorManager, MemoryCacheStore, NetworkError, type ParallelOptions, Request, type RequestConfig, type RequestError, type RequestInterceptor, type RequestOptions, type Requestor, type Response, type ResponseInterceptor, type RetryOptions, TimeoutError, type TimeoutOptions, UreqError, createCacheRequestor, createIdempotentRequestor, createParallelRequestor, createRequestError, createRetryRequestor, createTimeoutRequestor, formatError, getErrorDetails, isRetryableError };
228
+ export { AbortError, type CacheOptions, type CacheStore, DefaultHashService, type ErrorContext, type HashService, HttpError, type IdempotentOptions, InterceptorManager, MemoryCacheStore, NetworkError, type ParallelOptions, Request, type RequestConfig, type RequestError, type RequestInterceptor, type RequestOptions, type Requestor, type Response, type ResponseInterceptor, type ResponseTransformer, type ResponseType, type RetryOptions, TimeoutError, type TimeoutOptions, UreqError, createCacheRequestor, createIdempotentRequestor, createParallelRequestor, createRequestError, createRetryRequestor, createTimeoutRequestor, formatError, getErrorDetails, isRetryableError };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,27 @@
1
+ /**
2
+ * 响应类型
3
+ */
4
+ type ResponseType = 'json' | 'text' | 'blob' | 'arraybuffer' | 'formData';
5
+ /**
6
+ * 响应转换器函数类型
7
+ * @param response 原始响应对象(Fetch Response 或其他)
8
+ * @returns 转换后的数据
9
+ */
10
+ type ResponseTransformer<T = any> = (response: any) => Promise<T>;
1
11
  interface RequestOptions {
2
12
  headers?: Record<string, string>;
3
13
  timeout?: number;
4
14
  signal?: AbortSignal;
5
- responseType?: 'arraybuffer' | 'json' | 'text' | 'blob';
15
+ /**
16
+ * 响应类型,用于指定如何解析响应体
17
+ * @default 'json'
18
+ */
19
+ responseType?: ResponseType;
20
+ /**
21
+ * 自定义响应转换器,优先级高于 responseType
22
+ * 当需要自定义响应解析逻辑时使用
23
+ */
24
+ responseTransformer?: ResponseTransformer;
6
25
  [key: string]: any;
7
26
  }
8
27
  interface Response<T = any> {
@@ -206,4 +225,4 @@ declare function formatError(error: RequestError): string;
206
225
  */
207
226
  declare function getErrorDetails(error: RequestError): Record<string, any>;
208
227
 
209
- export { AbortError, type CacheOptions, type CacheStore, DefaultHashService, type ErrorContext, type HashService, HttpError, type IdempotentOptions, InterceptorManager, MemoryCacheStore, NetworkError, type ParallelOptions, Request, type RequestConfig, type RequestError, type RequestInterceptor, type RequestOptions, type Requestor, type Response, type ResponseInterceptor, type RetryOptions, TimeoutError, type TimeoutOptions, UreqError, createCacheRequestor, createIdempotentRequestor, createParallelRequestor, createRequestError, createRetryRequestor, createTimeoutRequestor, formatError, getErrorDetails, isRetryableError };
228
+ export { AbortError, type CacheOptions, type CacheStore, DefaultHashService, type ErrorContext, type HashService, HttpError, type IdempotentOptions, InterceptorManager, MemoryCacheStore, NetworkError, type ParallelOptions, Request, type RequestConfig, type RequestError, type RequestInterceptor, type RequestOptions, type Requestor, type Response, type ResponseInterceptor, type ResponseTransformer, type ResponseType, type RetryOptions, TimeoutError, type TimeoutOptions, UreqError, createCacheRequestor, createIdempotentRequestor, createParallelRequestor, createRequestError, createRetryRequestor, createTimeoutRequestor, formatError, getErrorDetails, isRetryableError };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var p=class extends Error{constructor(r,t={}){super(r),this.name="UreqError",this.timestamp=Date.now(),Object.assign(this,t);}},m=class extends p{constructor(r,t={}){super(r,{...t,isNetworkError:true}),this.name="NetworkError";}},l=class extends p{constructor(r,t={}){super(r,{...t,isTimeout:true}),this.name="TimeoutError";}},d=class extends p{constructor(r,t={}){super(r,{...t,isAborted:true}),this.name="AbortError";}},R=class extends p{constructor(r,t,s={}){super(r,{...s,status:t}),this.name="HttpError";}};var g=class{constructor(){this.cache=new Map;}get(r){let t=this.cache.get(r);if(t){if(t.expires&&Date.now()>t.expires){this.cache.delete(r);return}return t.value}}set(r,t,s){let n=s?Date.now()+s:void 0;this.cache.set(r,{value:t,expires:n});}delete(r){this.cache.delete(r);}clear(){this.cache.clear();}has(r){let t=this.cache.get(r);return t?t.expires&&Date.now()>t.expires?(this.cache.delete(r),false):true:false}};var T=class{generateHash(r){let t=0;for(let s=0;s<r.length;s++){let n=r.charCodeAt(s);t=(t<<5)-t+n,t=t&t;}return t.toString(36)}generateRequestHash(r,t,s,n){let i=[r.toUpperCase(),t,s?JSON.stringify(s):"",n?JSON.stringify(n):""];return this.generateHash(i.join("|"))}};var h=class{constructor(){this.requestInterceptors=[];this.responseInterceptors=[];}addRequestInterceptor(r){return this.requestInterceptors.push(r),()=>{let t=this.requestInterceptors.indexOf(r);t!==-1&&this.requestInterceptors.splice(t,1);}}addResponseInterceptor(r){return this.responseInterceptors.push(r),()=>{let t=this.responseInterceptors.indexOf(r);t!==-1&&this.responseInterceptors.splice(t,1);}}async runRequestInterceptors(r){let t={...r};for(let s of this.requestInterceptors)s.onRequest&&(t=await s.onRequest(t));return t}async runResponseInterceptors(r){let t={...r};for(let s of this.responseInterceptors)s.onResponse&&(t=await s.onResponse(t));return t}};function J(e,r={}){let{url:t,method:s,retryCount:n}=r;return e.name==="AbortError"||e.code==="ABORT_ERR"?new d("Request was aborted",{url:t,method:s,retryCount:n,code:"ABORT_ERR"}):e.name==="TimeoutError"||e.message?.includes("timeout")?new l("Request timed out",{url:t,method:s,retryCount:n,code:"TIMEOUT"}):e.name==="TypeError"&&e.message?.includes("fetch")?new m("Network request failed",{url:t,method:s,retryCount:n,code:"NETWORK_ERROR"}):e instanceof globalThis.Response?new R(`HTTP ${e.status}: ${e.statusText}`,e.status,{url:t,method:s,retryCount:n,code:`HTTP_${e.status}`,data:e}):e.response?new R(`HTTP ${e.response.status}: ${e.response.statusText||"Unknown Error"}`,e.response.status,{url:t||e.config?.url,method:s||e.config?.method?.toUpperCase(),retryCount:n,code:`HTTP_${e.response.status}`,data:e.response.data}):e.request&&!e.response?new m("Network request failed",{url:t||e.config?.url,method:s||e.config?.method?.toUpperCase(),retryCount:n,code:"NETWORK_ERROR"}):e instanceof p?(t&&!e.url&&(e.url=t),s&&!e.method&&(e.method=s),n!==void 0&&(e.retryCount=n),e):new p(e.message||"Unknown error occurred",{url:t,method:s,retryCount:n,code:"UNKNOWN_ERROR"})}function x(e){return e.status&&e.status>=400&&e.status<500?e.status===408||e.status===429:e.status&&e.status>=500||e.isNetworkError||e.isTimeout?true:!e.isAborted}function L(e){let r=[`[${e.name}]`,e.message];return e.method&&e.url&&r.push(`(${e.method} ${e.url})`),e.status&&r.push(`Status: ${e.status}`),e.retryCount!==void 0&&r.push(`Retry: ${e.retryCount}`),r.join(" ")}function W(e){return {name:e.name,message:e.message,status:e.status,code:e.code,url:e.url,method:e.method,timestamp:e.timestamp,retryCount:e.retryCount,isTimeout:e.isTimeout,isNetworkError:e.isNetworkError,isAborted:e.isAborted,stack:e.stack}}var S={maxRetries:3,retryDelay:1e3,shouldRetry:e=>x(e)};function E(e,r){let t={...S,...r};async function s(n,i=0){try{return await n()}catch(o){let a=o;if(a.retryCount=i,!await t.shouldRetry(a)||i>=t.maxRetries)throw a;return await new Promise(c=>setTimeout(c,t.retryDelay)),s(n,i+1)}}return {async get(n,i){return s(()=>e.get(n,i))},async post(n,i,o){return s(()=>e.post(n,i,o))},async put(n,i,o){return s(()=>e.put(n,i,o))},async delete(n,i){return s(()=>e.delete(n,i))},async patch(n,i,o){return s(()=>e.patch(n,i,o))}}}var k={ttl:5*60*1e3,store:new g,getCacheKey:(e,r)=>`${e}${r?JSON.stringify(r):""}`};function b(e,r){let t={...k,...r};async function s(n,i){let o=await t.store.get(n);if(o)return o;let a=await i();return await t.store.set(n,a,t.ttl),a}return {async get(n,i){let o=t.getCacheKey(n,i);return s(o,()=>e.get(n,i))},post:e.post.bind(e),put:e.put.bind(e),delete:e.delete.bind(e),patch:e.patch.bind(e)}}var H={maxConcurrent:5,timeout:3e4},q=class{constructor(r){this.maxConcurrent=r;this.queue=[];this.running=0;}async add(r){this.running>=this.maxConcurrent&&await new Promise(t=>{this.queue.push(t);}),this.running++;try{return await r()}finally{this.running--,this.queue.length>0&&this.queue.shift()?.();}}};function w(e,r){let t={...H,...r},s=new q(t.maxConcurrent);return {async get(n,i){return s.add(()=>e.get(n,i))},async post(n,i,o){return s.add(()=>e.post(n,i,o))},async put(n,i,o){return s.add(()=>e.put(n,i,o))},async delete(n,i){return s.add(()=>e.delete(n,i))},async patch(n,i,o){return s.add(()=>e.patch(n,i,o))}}}var P=new T,N={dedupeTime:1e3,getRequestId:(e,r,t,s)=>P.generateRequestHash(e,r,t,s),hashService:P};function C(e,r){let t={...N,...r},s=new Map;function n(){let o=Date.now();for(let[a,u]of s.entries())o-u.timestamp>t.dedupeTime&&s.delete(a);}async function i(o,a,u,c,A){let f=t.getRequestId(o,a,c,A);n();let y=s.get(f);if(y)return y.promise;let O=u();s.set(f,{promise:O,timestamp:Date.now()});try{return await O}finally{s.delete(f);}}return {get:(o,a)=>i("GET",o,()=>e.get(o,a),null,a),post:(o,a,u)=>i("POST",o,()=>e.post(o,a,u),a,u),put:(o,a,u)=>i("PUT",o,()=>e.put(o,a,u),a,u),delete:(o,a)=>i("DELETE",o,()=>e.delete(o,a),null,a),patch:(o,a,u)=>i("PATCH",o,()=>e.patch(o,a,u),a,u)}}var D={timeout:3e4,timeoutErrorMessage:"Request timeout"};function I(e,r){let t={...D,...r};async function s(n,i=t.timeout){let o=new AbortController,a=setTimeout(()=>o.abort(),i);try{let u=await n();return clearTimeout(a),u}catch(u){if(clearTimeout(a),u instanceof DOMException&&u.name==="AbortError"){let c=new Error(t.timeoutErrorMessage);throw c.code="TIMEOUT",c}throw u}}return {get:(n,i)=>{let o=i?.signal,a={...i,signal:o||new AbortController().signal};return s(()=>e.get(n,a))},post:(n,i,o)=>{let a=o?.signal,u={...o,signal:a||new AbortController().signal};return s(()=>e.post(n,i,u))},put:(n,i,o)=>{let a=o?.signal,u={...o,signal:a||new AbortController().signal};return s(()=>e.put(n,i,u))},delete:(n,i)=>{let o=i?.signal,a={...i,signal:o||new AbortController().signal};return s(()=>e.delete(n,a))},patch:(n,i,o)=>{let a=o?.signal,u={...o,signal:a||new AbortController().signal};return s(()=>e.patch(n,i,u))}}}var v=class{constructor(r,t){this.interceptors=new h;let s=r;t?.timeout&&(s=I(s,t.timeout)),t?.retry&&(s=E(s,t.retry)),t?.cache&&(s=b(s,t.cache)),t?.parallel&&(s=w(s,t.parallel)),t?.idempotent&&(s=C(s,t.idempotent)),this.requestor=s;}async request(r,t,s,n){let i=await this.interceptors.runRequestInterceptors({...n,method:r,url:t,data:s});try{let o=r.toLowerCase(),a=await this.requestor[o](t,s,i);return (await this.interceptors.runResponseInterceptors(a)).data}catch(o){throw o}}get(r,t){return this.request("GET",r,void 0,t)}post(r,t,s){return this.request("POST",r,t,s)}put(r,t,s){return this.request("PUT",r,t,s)}delete(r,t){return this.request("DELETE",r,void 0,t)}patch(r,t,s){return this.request("PATCH",r,t,s)}};exports.AbortError=d;exports.DefaultHashService=T;exports.HttpError=R;exports.InterceptorManager=h;exports.MemoryCacheStore=g;exports.NetworkError=m;exports.Request=v;exports.TimeoutError=l;exports.UreqError=p;exports.createCacheRequestor=b;exports.createIdempotentRequestor=C;exports.createParallelRequestor=w;exports.createRequestError=J;exports.createRetryRequestor=E;exports.createTimeoutRequestor=I;exports.formatError=L;exports.getErrorDetails=W;exports.isRetryableError=x;//# sourceMappingURL=index.js.map
1
+ 'use strict';var c=class extends Error{constructor(n,t={}){super(n),this.name="UreqError",this.timestamp=Date.now(),Object.assign(this,t);}},m=class extends c{constructor(n,t={}){super(n,{...t,isNetworkError:true}),this.name="NetworkError";}},l=class extends c{constructor(n,t={}){super(n,{...t,isTimeout:true}),this.name="TimeoutError";}},d=class extends c{constructor(n,t={}){super(n,{...t,isAborted:true}),this.name="AbortError";}},R=class extends c{constructor(n,t,s={}){super(n,{...s,status:t}),this.name="HttpError";}};var g=class{constructor(){this.cache=new Map;}get(n){let t=this.cache.get(n);if(t){if(t.expires&&Date.now()>t.expires){this.cache.delete(n);return}return t.value}}set(n,t,s){let r=s?Date.now()+s:void 0;this.cache.set(n,{value:t,expires:r});}delete(n){this.cache.delete(n);}clear(){this.cache.clear();}has(n){let t=this.cache.get(n);return t?t.expires&&Date.now()>t.expires?(this.cache.delete(n),false):true:false}};var T=class{generateHash(n){let t=0;for(let s=0;s<n.length;s++){let r=n.charCodeAt(s);t=(t<<5)-t+r,t=t&t;}return t.toString(36)}generateRequestHash(n,t,s,r){let o=[n.toUpperCase(),t,s?JSON.stringify(s):"",r?JSON.stringify(r):""];return this.generateHash(o.join("|"))}};var f=class{constructor(){this.requestInterceptors=[];this.responseInterceptors=[];}addRequestInterceptor(n){return this.requestInterceptors.push(n),()=>{let t=this.requestInterceptors.indexOf(n);t!==-1&&this.requestInterceptors.splice(t,1);}}addResponseInterceptor(n){return this.responseInterceptors.push(n),()=>{let t=this.responseInterceptors.indexOf(n);t!==-1&&this.responseInterceptors.splice(t,1);}}async runRequestInterceptors(n){let t={...n};for(let s of this.requestInterceptors)s.onRequest&&(t=await s.onRequest(t));return t}async runResponseInterceptors(n){let t={...n};for(let s of this.responseInterceptors)s.onResponse&&(t=await s.onResponse(t));return t}};function G(e,n={}){let{url:t,method:s,retryCount:r}=n;return e.name==="AbortError"||e.code==="ABORT_ERR"?new d("Request was aborted",{url:t,method:s,retryCount:r,code:"ABORT_ERR"}):e.name==="TimeoutError"||e.message?.includes("timeout")?new l("Request timed out",{url:t,method:s,retryCount:r,code:"TIMEOUT"}):e.name==="TypeError"&&e.message?.includes("fetch")?new m("Network request failed",{url:t,method:s,retryCount:r,code:"NETWORK_ERROR"}):e instanceof globalThis.Response?new R(`HTTP ${e.status}: ${e.statusText}`,e.status,{url:t,method:s,retryCount:r,code:`HTTP_${e.status}`,data:e}):e.response?new R(`HTTP ${e.response.status}: ${e.response.statusText||"Unknown Error"}`,e.response.status,{url:t||e.config?.url,method:s||e.config?.method?.toUpperCase(),retryCount:r,code:`HTTP_${e.response.status}`,data:e.response.data}):e.request&&!e.response?new m("Network request failed",{url:t||e.config?.url,method:s||e.config?.method?.toUpperCase(),retryCount:r,code:"NETWORK_ERROR"}):e instanceof c?(t&&!e.url&&(e.url=t),s&&!e.method&&(e.method=s),r!==void 0&&(e.retryCount=r),e):new c(e.message||"Unknown error occurred",{url:t,method:s,retryCount:r,code:"UNKNOWN_ERROR"})}function x(e){return e.status&&e.status>=400&&e.status<500?e.status===408||e.status===429:e.status&&e.status>=500||e.isNetworkError||e.isTimeout?true:!e.isAborted}function J(e){let n=[`[${e.name}]`,e.message];return e.method&&e.url&&n.push(`(${e.method} ${e.url})`),e.status&&n.push(`Status: ${e.status}`),e.retryCount!==void 0&&n.push(`Retry: ${e.retryCount}`),n.join(" ")}function W(e){return {name:e.name,message:e.message,status:e.status,code:e.code,url:e.url,method:e.method,timestamp:e.timestamp,retryCount:e.retryCount,isTimeout:e.isTimeout,isNetworkError:e.isNetworkError,isAborted:e.isAborted,stack:e.stack}}var S={maxRetries:3,retryDelay:1e3,shouldRetry:e=>x(e)};function E(e,n){let t={...S,...n};async function s(r,o=0){try{return await r()}catch(i){let a=i;if(a.retryCount=o,!await t.shouldRetry(a)||o>=t.maxRetries)throw a;return await new Promise(p=>setTimeout(p,t.retryDelay)),s(r,o+1)}}return {async get(r,o){return s(()=>e.get(r,o))},async post(r,o,i){return s(()=>e.post(r,o,i))},async put(r,o,i){return s(()=>e.put(r,o,i))},async delete(r,o){return s(()=>e.delete(r,o))},async patch(r,o,i){return s(()=>e.patch(r,o,i))}}}var H={ttl:5*60*1e3,store:new g,getCacheKey:(e,n)=>`${e}${n?JSON.stringify(n):""}`};function w(e,n){let t={...H,...n};async function s(r,o){let i=await t.store.get(r);if(i)return i;let a=await o();return await t.store.set(r,a,t.ttl),a}return {async get(r,o){let i=t.getCacheKey(r,o);return s(i,()=>e.get(r,o))},post:e.post.bind(e),put:e.put.bind(e),delete:e.delete.bind(e),patch:e.patch.bind(e)}}var k={maxConcurrent:5,timeout:3e4},h=class{constructor(n){this.maxConcurrent=n;this.queue=[];this.running=0;}async add(n){this.running>=this.maxConcurrent&&await new Promise(t=>{this.queue.push(t);}),this.running++;try{return await n()}finally{this.running--,this.queue.length>0&&this.queue.shift()?.();}}};function P(e,n){let t={...k,...n},s=new h(t.maxConcurrent);return {async get(r,o){return s.add(()=>e.get(r,o))},async post(r,o,i){return s.add(()=>e.post(r,o,i))},async put(r,o,i){return s.add(()=>e.put(r,o,i))},async delete(r,o){return s.add(()=>e.delete(r,o))},async patch(r,o,i){return s.add(()=>e.patch(r,o,i))}}}var b=new T,N={dedupeTime:1e3,getRequestId:(e,n,t,s)=>b.generateRequestHash(e,n,t,s),hashService:b};function C(e,n){let t={...N,...n},s=new Map;function r(){let i=Date.now();for(let[a,u]of s.entries())i-u.timestamp>t.dedupeTime&&s.delete(a);}async function o(i,a,u,p,A){let q=t.getRequestId(i,a,p,A);r();let y=s.get(q);if(y)return y.promise;let O=u();s.set(q,{promise:O,timestamp:Date.now()});try{return await O}finally{s.delete(q);}}return {get:(i,a)=>o("GET",i,()=>e.get(i,a),null,a),post:(i,a,u)=>o("POST",i,()=>e.post(i,a,u),a,u),put:(i,a,u)=>o("PUT",i,()=>e.put(i,a,u),a,u),delete:(i,a)=>o("DELETE",i,()=>e.delete(i,a),null,a),patch:(i,a,u)=>o("PATCH",i,()=>e.patch(i,a,u),a,u)}}var D={timeout:3e4,timeoutErrorMessage:"Request timeout"};function I(e,n){let t={...D,...n};async function s(r,o=t.timeout){let i=new AbortController,a=setTimeout(()=>i.abort(),o);try{let u=await r();return clearTimeout(a),u}catch(u){if(clearTimeout(a),u instanceof DOMException&&u.name==="AbortError"){let p=new Error(t.timeoutErrorMessage);throw p.code="TIMEOUT",p}throw u}}return {get:(r,o)=>{let i=o?.signal,a={...o,signal:i||new AbortController().signal};return s(()=>e.get(r,a))},post:(r,o,i)=>{let a=i?.signal,u={...i,signal:a||new AbortController().signal};return s(()=>e.post(r,o,u))},put:(r,o,i)=>{let a=i?.signal,u={...i,signal:a||new AbortController().signal};return s(()=>e.put(r,o,u))},delete:(r,o)=>{let i=o?.signal,a={...o,signal:i||new AbortController().signal};return s(()=>e.delete(r,a))},patch:(r,o,i)=>{let a=i?.signal,u={...i,signal:a||new AbortController().signal};return s(()=>e.patch(r,o,u))}}}function $(e,n){let t=async(s,r,o,i)=>{let a=await n.runRequestInterceptors({...i,method:s,url:r,data:o}),u=s.toLowerCase(),p;return u==="get"||u==="delete"?p=await e[u](a.url,a):p=await e[u](a.url,a.data,a),n.runResponseInterceptors(p)};return {async get(s,r){return t("GET",s,void 0,r)},async post(s,r,o){return t("POST",s,r,o)},async put(s,r,o){return t("PUT",s,r,o)},async delete(s,r){return t("DELETE",s,void 0,r)},async patch(s,r,o){return t("PATCH",s,r,o)}}}var v=class{constructor(n,t){this.interceptors=new f;let s=$(n,this.interceptors);t?.timeout&&(s=I(s,t.timeout)),t?.retry&&(s=E(s,t.retry)),t?.cache&&(s=w(s,t.cache)),t?.parallel&&(s=P(s,t.parallel)),t?.idempotent&&(s=C(s,t.idempotent)),this.requestor=s;}async request(n,t,s,r){let o=n.toLowerCase(),i;return o==="get"||o==="delete"?i=await this.requestor[o](t,r):i=await this.requestor[o](t,s,r),i.data}get(n,t){return this.request("GET",n,void 0,t)}post(n,t,s){return this.request("POST",n,t,s)}put(n,t,s){return this.request("PUT",n,t,s)}delete(n,t){return this.request("DELETE",n,void 0,t)}patch(n,t,s){return this.request("PATCH",n,t,s)}};exports.AbortError=d;exports.DefaultHashService=T;exports.HttpError=R;exports.InterceptorManager=f;exports.MemoryCacheStore=g;exports.NetworkError=m;exports.Request=v;exports.TimeoutError=l;exports.UreqError=c;exports.createCacheRequestor=w;exports.createIdempotentRequestor=C;exports.createParallelRequestor=P;exports.createRequestError=G;exports.createRetryRequestor=E;exports.createTimeoutRequestor=I;exports.formatError=J;exports.getErrorDetails=W;exports.isRetryableError=x;//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interfaces/request.ts","../src/interfaces/cache.ts","../src/interfaces/hash.ts","../src/interceptor.ts","../src/utils/error.ts","../src/features/retry/index.ts","../src/features/cache/index.ts","../src/features/parallel/index.ts","../src/features/idempotent/index.ts","../src/features/timeout/index.ts","../src/request.ts"],"names":["UreqError","message","options","NetworkError","TimeoutError","AbortError","HttpError","status","MemoryCacheStore","key","item","value","ttl","expires","DefaultHashService","input","hash","i","char","method","url","data","parts","InterceptorManager","interceptor","index","config","currentConfig","response","currentResponse","createRequestError","error","context","retryCount","isRetryableError","formatError","getErrorDetails","defaultRetryOptions","createRetryRequestor","requestor","finalOptions","retryRequest","request","retries","requestError","resolve","defaultCacheOptions","createCacheRequestor","cacheRequest","cached","defaultParallelOptions","RequestQueue","maxConcurrent","task","createParallelRequestor","queue","defaultHashService","defaultOptions","createIdempotentRequestor","pendingRequests","cleanupOldRequests","now","dedupeRequest","requestFn","requestId","existing","promise","createTimeoutRequestor","withTimeout","timeout","controller","timeoutId","timeoutError","signal","mergedOptions","Request","baseRequestor","requestMethod"],"mappings":"aA4BaA,IAAAA,CAAAA,CAAN,cAAwB,KAA8B,CAY3D,WAAA,CAAYC,EAAiBC,CAAiC,CAAA,EAAI,CAAA,CAChE,KAAMD,CAAAA,CAAO,EACb,IAAK,CAAA,IAAA,CAAO,WACZ,CAAA,IAAA,CAAK,SAAY,CAAA,IAAA,CAAK,GAAI,EAAA,CAC1B,MAAO,CAAA,MAAA,CAAO,IAAMC,CAAAA,CAAO,EAC7B,CACF,EAEaC,CAAN,CAAA,cAA2BH,CAAU,CAC1C,WAAYC,CAAAA,CAAAA,CAAiBC,EAAiC,EAAC,CAAG,CAChE,KAAA,CAAMD,CAAS,CAAA,CAAE,GAAGC,CAAS,CAAA,cAAA,CAAgB,IAAK,CAAC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,CAAK,SAAUiD,CAAAA,CAAa,EAAEzD,CAAKC,CAAAA,CAAAA,CAAMK,CAAM,CAAA,CACtE,OAAQ,CAAA,MAAM,IAAK,CAAA,YAAA,CAAa,uBAAwBE,CAAAA,CAAQ,CAAG,EAAA,IACrE,CAASG,MAAAA,CAAAA,CAAO,CACd,MAAMA,CACR,CACF,CAEA,GAAOX,CAAAA,CAAAA,CAAalB,CAAsC,CAAA,CACxD,OAAO,IAAA,CAAK,OAAQ,CAAA,KAAA,CAAOkB,CAAK,CAAA,MAAA,CAAWlB,CAAO,CACpD,CAEA,IAAQkB,CAAAA,CAAAA,CAAaC,CAAYnB,CAAAA,CAAAA,CAAsC,CACrE,OAAO,IAAA,CAAK,OAAQ,CAAA,MAAA,CAAQkB,CAAKC,CAAAA,CAAAA,CAAMnB,CAAO,CAChD,CAEA,GAAOkB,CAAAA,CAAAA,CAAaC,CAAYnB,CAAAA,CAAAA,CAAsC,CACpE,OAAO,IAAK,CAAA,OAAA,CAAQ,KAAOkB,CAAAA,CAAAA,CAAKC,CAAMnB,CAAAA,CAAO,CAC/C,CAEA,MAAA,CAAUkB,CAAalB,CAAAA,CAAAA,CAAsC,CAC3D,OAAO,IAAK,CAAA,OAAA,CAAQ,QAAUkB,CAAAA,CAAAA,CAAK,MAAWlB,CAAAA,CAAO,CACvD,CAEA,MAASkB,CAAaC,CAAAA,CAAAA,CAAYnB,CAAsC,CAAA,CACtE,OAAO,IAAA,CAAK,OAAQ,CAAA,OAAA,CAASkB,CAAKC,CAAAA,CAAAA,CAAMnB,CAAO,CACjD,CAGF","file":"index.js","sourcesContent":["export interface RequestOptions {\n headers?: Record<string, string>;\n timeout?: number;\n signal?: AbortSignal;\n responseType?: 'arraybuffer' | 'json' | 'text' | 'blob';\n [key: string]: any;\n}\n\nexport interface Response<T = any> {\n data: T;\n status: number;\n statusText: string;\n headers: Record<string, string>;\n}\n\nexport interface RequestError extends Error {\n status?: number;\n code?: string;\n data?: any;\n url?: string;\n method?: string;\n timestamp?: number;\n retryCount?: number;\n isTimeout?: boolean;\n isNetworkError?: boolean;\n isAborted?: boolean;\n}\n\nexport class UreqError extends Error implements RequestError {\n status?: number;\n code?: string;\n data?: any;\n url?: string;\n method?: string;\n timestamp: number;\n retryCount?: number;\n isTimeout?: boolean;\n isNetworkError?: boolean;\n isAborted?: boolean;\n\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message);\n this.name = 'UreqError';\n this.timestamp = Date.now();\n Object.assign(this, options);\n }\n}\n\nexport class NetworkError extends UreqError {\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message, { ...options, isNetworkError: true });\n this.name = 'NetworkError';\n }\n}\n\nexport class TimeoutError extends UreqError {\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message, { ...options, isTimeout: true });\n this.name = 'TimeoutError';\n }\n}\n\nexport class AbortError extends UreqError {\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message, { ...options, isAborted: true });\n this.name = 'AbortError';\n }\n}\n\nexport class HttpError extends UreqError {\n constructor(message: string, status: number, options: Partial<RequestError> = {}) {\n super(message, { ...options, status });\n this.name = 'HttpError';\n }\n}\n\nexport interface Requestor {\n get<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;\n post<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;\n put<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;\n delete<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;\n patch<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;\n} ","/**\n * Cache store interface for storing and retrieving cached data\n */\nexport interface CacheStore {\n /**\n * Get a value from the cache\n */\n get<T>(key: string): Promise<T | undefined> | T | undefined;\n \n /**\n * Set a value in the cache with optional TTL\n */\n set<T>(key: string, value: T, ttl?: number): Promise<void> | void;\n \n /**\n * Delete a value from the cache\n */\n delete(key: string): Promise<void> | void;\n \n /**\n * Clear all values from the cache\n */\n clear(): Promise<void> | void;\n \n /**\n * Check if a key exists in the cache\n */\n has(key: string): Promise<boolean> | boolean;\n}\n\n/**\n * Simple in-memory cache store implementation\n */\nexport class MemoryCacheStore implements CacheStore {\n private cache = new Map<string, { value: any; expires?: number }>();\n\n get<T>(key: string): T | undefined {\n const item = this.cache.get(key);\n if (!item) return undefined;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return undefined;\n }\n \n return item.value;\n }\n\n set<T>(key: string, value: T, ttl?: number): void {\n const expires = ttl ? Date.now() + ttl : undefined;\n this.cache.set(key, { value, expires });\n }\n\n delete(key: string): void {\n this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n\n has(key: string): boolean {\n const item = this.cache.get(key);\n if (!item) return false;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return false;\n }\n \n return true;\n }\n}\n","/**\n * Hash service interface for generating request identifiers\n */\nexport interface HashService {\n /**\n * Generate a hash from a string input\n */\n generateHash(input: string): string;\n \n /**\n * Generate a hash for a request based on method, URL, data, and options\n */\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string;\n}\n\n/**\n * Default hash service implementation using simple hash algorithm\n */\nexport class DefaultHashService implements HashService {\n generateHash(input: string): string {\n let hash = 0;\n for (let i = 0; i < input.length; i++) {\n const char = input.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash = hash & hash; // Convert to 32-bit integer\n }\n return hash.toString(36);\n }\n\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string {\n const parts = [\n method.toUpperCase(),\n url,\n data ? JSON.stringify(data) : '',\n options ? JSON.stringify(options) : ''\n ];\n return this.generateHash(parts.join('|'));\n }\n}\n","import { RequestError, RequestOptions, Response } from \"./interfaces/request\";\n\nexport interface RequestInterceptor {\n onRequest?(config: RequestOptions): Promise<RequestOptions> | RequestOptions;\n onRequestError?(error: any): Promise<any>;\n}\n\nexport interface ResponseInterceptor {\n onResponse?<T>(response: Response<T>): Promise<Response<T>> | Response<T>;\n onResponseError?(error: RequestError): Promise<any>;\n}\n\nexport class InterceptorManager {\n private requestInterceptors: RequestInterceptor[] = [];\n private responseInterceptors: ResponseInterceptor[] = [];\n\n addRequestInterceptor(interceptor: RequestInterceptor) {\n this.requestInterceptors.push(interceptor);\n return () => {\n const index = this.requestInterceptors.indexOf(interceptor);\n if (index !== -1) {\n this.requestInterceptors.splice(index, 1);\n }\n };\n }\n\n addResponseInterceptor(interceptor: ResponseInterceptor) {\n this.responseInterceptors.push(interceptor);\n return () => {\n const index = this.responseInterceptors.indexOf(interceptor);\n if (index !== -1) {\n this.responseInterceptors.splice(index, 1);\n }\n };\n }\n\n async runRequestInterceptors(config: RequestOptions): Promise<RequestOptions> {\n let currentConfig = { ...config };\n for (const interceptor of this.requestInterceptors) {\n if (interceptor.onRequest) {\n currentConfig = await interceptor.onRequest(currentConfig);\n }\n }\n return currentConfig;\n }\n\n async runResponseInterceptors<T>(response: Response<T>): Promise<Response<T>> {\n let currentResponse = { ...response };\n for (const interceptor of this.responseInterceptors) {\n if (interceptor.onResponse) {\n currentResponse = await interceptor.onResponse(currentResponse);\n }\n }\n return currentResponse;\n }\n} ","import { \n RequestError, \n UreqError, \n NetworkError, \n TimeoutError, \n AbortError, \n HttpError \n} from '../interfaces/request.js';\n\nexport interface ErrorContext {\n url?: string;\n method?: string;\n retryCount?: number;\n requestId?: string;\n}\n\n/**\n * Creates appropriate error types based on the error context\n */\nexport function createRequestError(\n error: any, \n context: ErrorContext = {}\n): RequestError {\n const { url, method, retryCount } = context;\n \n // Handle AbortController signals\n if (error.name === 'AbortError' || error.code === 'ABORT_ERR') {\n return new AbortError('Request was aborted', {\n url,\n method,\n retryCount,\n code: 'ABORT_ERR'\n });\n }\n \n // Handle timeout errors\n if (error.name === 'TimeoutError' || error.message?.includes('timeout')) {\n return new TimeoutError('Request timed out', {\n url,\n method,\n retryCount,\n code: 'TIMEOUT'\n });\n }\n \n // Handle network errors\n if (error.name === 'TypeError' && error.message?.includes('fetch')) {\n return new NetworkError('Network request failed', {\n url,\n method,\n retryCount,\n code: 'NETWORK_ERROR'\n });\n }\n \n // Handle HTTP errors (Response objects)\n if (error instanceof globalThis.Response) {\n return new HttpError(\n `HTTP ${error.status}: ${error.statusText}`,\n error.status,\n {\n url,\n method,\n retryCount,\n code: `HTTP_${error.status}`,\n data: error\n }\n );\n }\n \n // Handle Axios errors\n if (error.response) {\n return new HttpError(\n `HTTP ${error.response.status}: ${error.response.statusText || 'Unknown Error'}`,\n error.response.status,\n {\n url: url || error.config?.url,\n method: method || error.config?.method?.toUpperCase(),\n retryCount,\n code: `HTTP_${error.response.status}`,\n data: error.response.data\n }\n );\n }\n \n // Handle Axios network errors\n if (error.request && !error.response) {\n return new NetworkError('Network request failed', {\n url: url || error.config?.url,\n method: method || error.config?.method?.toUpperCase(),\n retryCount,\n code: 'NETWORK_ERROR'\n });\n }\n \n // Handle already processed UreqError\n if (error instanceof UreqError) {\n // Update context if provided\n if (url && !error.url) error.url = url;\n if (method && !error.method) error.method = method;\n if (retryCount !== undefined) error.retryCount = retryCount;\n return error;\n }\n \n // Generic error fallback\n return new UreqError(error.message || 'Unknown error occurred', {\n url,\n method,\n retryCount,\n code: 'UNKNOWN_ERROR'\n });\n}\n\n/**\n * Determines if an error is retryable\n */\nexport function isRetryableError(error: RequestError): boolean {\n // Don't retry client errors (4xx) except for specific cases\n if (error.status && error.status >= 400 && error.status < 500) {\n // Retry on 408 (Request Timeout), 429 (Too Many Requests)\n return error.status === 408 || error.status === 429;\n }\n \n // Retry on server errors (5xx)\n if (error.status && error.status >= 500) {\n return true;\n }\n \n // Retry on network errors and timeouts\n if (error.isNetworkError || error.isTimeout) {\n return true;\n }\n \n // Don't retry aborted requests\n if (error.isAborted) {\n return false;\n }\n \n // Default to retryable for unknown errors\n return true;\n}\n\n/**\n * Formats error for logging\n */\nexport function formatError(error: RequestError): string {\n const parts = [\n `[${error.name}]`,\n error.message\n ];\n \n if (error.method && error.url) {\n parts.push(`(${error.method} ${error.url})`);\n }\n \n if (error.status) {\n parts.push(`Status: ${error.status}`);\n }\n \n if (error.retryCount !== undefined) {\n parts.push(`Retry: ${error.retryCount}`);\n }\n \n return parts.join(' ');\n}\n\n/**\n * Extracts error details for debugging\n */\nexport function getErrorDetails(error: RequestError): Record<string, any> {\n return {\n name: error.name,\n message: error.message,\n status: error.status,\n code: error.code,\n url: error.url,\n method: error.method,\n timestamp: error.timestamp,\n retryCount: error.retryCount,\n isTimeout: error.isTimeout,\n isNetworkError: error.isNetworkError,\n isAborted: error.isAborted,\n stack: error.stack\n };\n}\n","import { Requestor, RequestOptions, Response, RequestError } from '../../interfaces/request';\nimport { isRetryableError } from '../../utils/error';\n\nexport interface RetryOptions {\n maxRetries?: number;\n retryDelay?: number;\n shouldRetry?: (error: RequestError) => boolean | Promise<boolean>;\n}\n\nconst defaultRetryOptions: Required<RetryOptions> = {\n maxRetries: 3,\n retryDelay: 1000,\n shouldRetry: (error: RequestError) => isRetryableError(error),\n};\n\nexport function createRetryRequestor(\n requestor: Requestor,\n options?: RetryOptions\n): Requestor {\n const finalOptions = { ...defaultRetryOptions, ...options };\n\n async function retryRequest<T>(\n request: () => Promise<Response<T>>,\n retries = 0\n ): Promise<Response<T>> {\n try {\n return await request();\n } catch (error) {\n const requestError = error as RequestError;\n // Update retry count in error\n requestError.retryCount = retries;\n\n const shouldRetry = await finalOptions.shouldRetry(requestError);\n\n if (!shouldRetry || retries >= finalOptions.maxRetries) {\n throw requestError;\n }\n\n await new Promise(resolve => setTimeout(resolve, finalOptions.retryDelay));\n return retryRequest(request, retries + 1);\n }\n }\n\n return {\n async get<T>(url: string, options?: RequestOptions) {\n return retryRequest(() => requestor.get<T>(url, options));\n },\n\n async post<T>(url: string, data?: any, options?: RequestOptions) {\n return retryRequest(() => requestor.post<T>(url, data, options));\n },\n\n async put<T>(url: string, data?: any, options?: RequestOptions) {\n return retryRequest(() => requestor.put<T>(url, data, options));\n },\n\n async delete<T>(url: string, options?: RequestOptions) {\n return retryRequest(() => requestor.delete<T>(url, options));\n },\n\n async patch<T>(url: string, data?: any, options?: RequestOptions) {\n return retryRequest(() => requestor.patch<T>(url, data, options));\n },\n };\n} ","import { Requestor, RequestOptions, Response } from '../../interfaces/request';\nimport { CacheStore, MemoryCacheStore } from '../../interfaces/cache';\n\nexport interface CacheOptions {\n ttl?: number;\n store?: CacheStore;\n getCacheKey?: (url: string, options?: RequestOptions) => string;\n}\n\nconst defaultCacheOptions: Required<CacheOptions> = {\n ttl: 5 * 60 * 1000, // 5 minutes\n store: new MemoryCacheStore(),\n getCacheKey: (url: string, options?: RequestOptions) => {\n return `${url}${options ? JSON.stringify(options) : ''}`;\n },\n};\n\nexport function createCacheRequestor(\n requestor: Requestor,\n options?: CacheOptions\n): Requestor {\n const finalOptions = { ...defaultCacheOptions, ...options };\n\n async function cacheRequest<T>(\n key: string,\n request: () => Promise<Response<T>>\n ): Promise<Response<T>> {\n const cached = await finalOptions.store.get<Response<T>>(key);\n if (cached) {\n return cached;\n }\n\n const response = await request();\n await finalOptions.store.set(key, response, finalOptions.ttl);\n return response;\n }\n\n return {\n async get<T>(url: string, options?: RequestOptions) {\n const key = finalOptions.getCacheKey(url, options);\n return cacheRequest(key, () => requestor.get<T>(url, options));\n },\n\n // POST, PUT, DELETE, PATCH methods don't use cache\n post: requestor.post.bind(requestor),\n put: requestor.put.bind(requestor),\n delete: requestor.delete.bind(requestor),\n patch: requestor.patch.bind(requestor),\n };\n} ","import { Requestor, RequestOptions, Response } from '../../interfaces/request';\n\nexport interface ParallelOptions {\n maxConcurrent?: number;\n timeout?: number;\n}\n\nconst defaultParallelOptions: Required<ParallelOptions> = {\n maxConcurrent: 5,\n timeout: 30000,\n};\n\nclass RequestQueue {\n private queue: Array<() => void> = [];\n private running = 0;\n\n constructor(private maxConcurrent: number) {}\n\n async add<T>(task: () => Promise<T>): Promise<T> {\n if (this.running >= this.maxConcurrent) {\n await new Promise<void>((resolve) => {\n this.queue.push(resolve);\n });\n }\n\n this.running++;\n try {\n return await task();\n } finally {\n this.running--;\n if (this.queue.length > 0) {\n const next = this.queue.shift();\n next?.();\n }\n }\n }\n}\n\nexport function createParallelRequestor(\n requestor: Requestor,\n options?: ParallelOptions\n): Requestor {\n const finalOptions = { ...defaultParallelOptions, ...options };\n const queue = new RequestQueue(finalOptions.maxConcurrent);\n\n return {\n async get<T>(url: string, options?: RequestOptions) {\n return queue.add(() => requestor.get<T>(url, options));\n },\n\n async post<T>(url: string, data?: any, options?: RequestOptions) {\n return queue.add(() => requestor.post<T>(url, data, options));\n },\n\n async put<T>(url: string, data?: any, options?: RequestOptions) {\n return queue.add(() => requestor.put<T>(url, data, options));\n },\n\n async delete<T>(url: string, options?: RequestOptions) {\n return queue.add(() => requestor.delete<T>(url, options));\n },\n\n async patch<T>(url: string, data?: any, options?: RequestOptions) {\n return queue.add(() => requestor.patch<T>(url, data, options));\n },\n };\n} ","import { Requestor, RequestOptions, Response } from '../../interfaces/request';\nimport { HashService, DefaultHashService } from '../../interfaces/hash';\n\ninterface PendingRequest<T> {\n promise: Promise<Response<T>>;\n timestamp: number;\n}\n\nexport interface IdempotentOptions {\n // 请求合并的时间窗口,单位毫秒\n dedupeTime?: number;\n // 自定义请求标识生成函数\n getRequestId?: (method: string, url: string, data?: any, options?: RequestOptions) => string;\n // Hash service for generating request IDs\n hashService?: HashService;\n}\n\nconst defaultHashService = new DefaultHashService();\n\nconst defaultOptions: Required<IdempotentOptions> = {\n dedupeTime: 1000,\n getRequestId: (method: string, url: string, data?: any, options?: RequestOptions) => {\n return defaultHashService.generateRequestHash(method, url, data, options);\n },\n hashService: defaultHashService,\n};\n\nexport function createIdempotentRequestor(\n requestor: Requestor,\n options?: IdempotentOptions\n): Requestor {\n const finalOptions = { ...defaultOptions, ...options };\n const pendingRequests = new Map<string, PendingRequest<any>>();\n\n function cleanupOldRequests() {\n const now = Date.now();\n for (const [key, request] of pendingRequests.entries()) {\n if (now - request.timestamp > finalOptions.dedupeTime) {\n pendingRequests.delete(key);\n }\n }\n }\n\n async function dedupeRequest<T>(\n method: string,\n url: string,\n requestFn: () => Promise<Response<T>>,\n data?: any,\n options?: RequestOptions\n ): Promise<Response<T>> {\n const requestId = finalOptions.getRequestId(method, url, data, options);\n \n cleanupOldRequests();\n\n const existing = pendingRequests.get(requestId);\n if (existing) {\n return existing.promise;\n }\n\n const promise = requestFn();\n pendingRequests.set(requestId, {\n promise,\n timestamp: Date.now(),\n });\n\n try {\n return await promise;\n } finally {\n pendingRequests.delete(requestId);\n }\n }\n\n return {\n get: <T>(url: string, options?: RequestOptions) => {\n return dedupeRequest('GET', url, () => requestor.get<T>(url, options), null, options);\n },\n\n post: <T>(url: string, data?: any, options?: RequestOptions) => {\n return dedupeRequest('POST', url, () => requestor.post<T>(url, data, options), data, options);\n },\n\n put: <T>(url: string, data?: any, options?: RequestOptions) => {\n return dedupeRequest('PUT', url, () => requestor.put<T>(url, data, options), data, options);\n },\n\n delete: <T>(url: string, options?: RequestOptions) => {\n return dedupeRequest('DELETE', url, () => requestor.delete<T>(url, options), null, options);\n },\n\n patch: <T>(url: string, data?: any, options?: RequestOptions) => {\n return dedupeRequest('PATCH', url, () => requestor.patch<T>(url, data, options), data, options);\n },\n };\n} ","import { Requestor, RequestOptions, Response, RequestError } from '../../interfaces/request';\n\nexport interface TimeoutOptions {\n timeout?: number;\n timeoutErrorMessage?: string;\n}\n\nconst defaultOptions: Required<TimeoutOptions> = {\n timeout: 30000,\n timeoutErrorMessage: 'Request timeout',\n};\n\nexport function createTimeoutRequestor(\n requestor: Requestor,\n options?: TimeoutOptions\n): Requestor {\n const finalOptions = { ...defaultOptions, ...options };\n\n async function withTimeout<T>(\n request: () => Promise<Response<T>>,\n timeout: number = finalOptions.timeout\n ): Promise<Response<T>> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout);\n\n try {\n const response = await request();\n clearTimeout(timeoutId);\n return response;\n } catch (error) {\n clearTimeout(timeoutId);\n if (error instanceof DOMException && error.name === 'AbortError') {\n const timeoutError = new Error(finalOptions.timeoutErrorMessage) as RequestError;\n timeoutError.code = 'TIMEOUT';\n throw timeoutError;\n }\n throw error;\n }\n }\n\n return {\n get: <T>(url: string, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.get<T>(url, mergedOptions));\n },\n\n post: <T>(url: string, data?: any, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.post<T>(url, data, mergedOptions));\n },\n\n put: <T>(url: string, data?: any, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.put<T>(url, data, mergedOptions));\n },\n\n delete: <T>(url: string, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.delete<T>(url, mergedOptions));\n },\n\n patch: <T>(url: string, data?: any, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.patch<T>(url, data, mergedOptions));\n },\n };\n} ","import { Requestor, RequestOptions } from './interfaces/request';\nimport { InterceptorManager } from './interceptor';\nimport { createRetryRequestor, RetryOptions } from './features/retry';\nimport { CacheOptions, createCacheRequestor } from './features/cache';\nimport { createParallelRequestor, ParallelOptions } from './features/parallel';\nimport { createIdempotentRequestor, IdempotentOptions } from './features/idempotent';\nimport { createTimeoutRequestor, TimeoutOptions } from './features/timeout';\n\nexport interface RequestConfig {\n retry?: RetryOptions;\n cache?: CacheOptions;\n parallel?: ParallelOptions;\n idempotent?: IdempotentOptions;\n timeout?: TimeoutOptions;\n}\n\nexport class Request {\n private requestor: Requestor;\n public interceptors: InterceptorManager;\n\n constructor(baseRequestor: Requestor, config?: RequestConfig) {\n this.interceptors = new InterceptorManager();\n \n // 组合各种功能\n let requestor = baseRequestor;\n \n if (config?.timeout) {\n requestor = createTimeoutRequestor(requestor, config.timeout);\n }\n \n if (config?.retry) {\n requestor = createRetryRequestor(requestor, config.retry);\n }\n \n if (config?.cache) {\n requestor = createCacheRequestor(requestor, config.cache);\n }\n \n if (config?.parallel) {\n requestor = createParallelRequestor(requestor, config.parallel);\n }\n \n if (config?.idempotent) {\n requestor = createIdempotentRequestor(requestor, config.idempotent);\n }\n \n this.requestor = requestor;\n }\n\n async request<T>(method: string, url: string, data?: any, options?: RequestOptions): Promise<T> {\n const config = await this.interceptors.runRequestInterceptors({\n ...options,\n method,\n url,\n data,\n });\n\n try {\n // 使用类型断言和映射类型来解决索引签名问题\n type RequestMethod = keyof Requestor;\n const requestMethod = method.toLowerCase() as RequestMethod;\n const response = await this.requestor[requestMethod](url, data, config);\n return (await this.interceptors.runResponseInterceptors(response)).data as T;\n } catch (error) {\n throw error;\n }\n }\n\n get<T>(url: string, options?: RequestOptions): Promise<T> {\n return this.request('GET', url, undefined, options);\n }\n\n post<T>(url: string, data?: any, options?: RequestOptions): Promise<T> {\n return this.request('POST', url, data, options);\n }\n\n put<T>(url: string, data?: any, options?: RequestOptions): Promise<T> {\n return this.request('PUT', url, data, options);\n }\n\n delete<T>(url: string, options?: RequestOptions): Promise<T> {\n return this.request('DELETE', url, undefined, options);\n }\n\n patch<T>(url: string, data?: any, options?: RequestOptions): Promise<T> {\n return this.request('PATCH', url, data, options);\n }\n\n // 实现其他方法...\n} "]}
1
+ {"version":3,"sources":["../src/interfaces/request.ts","../src/interfaces/cache.ts","../src/interfaces/hash.ts","../src/interceptor.ts","../src/utils/error.ts","../src/features/retry/index.ts","../src/features/cache/index.ts","../src/features/parallel/index.ts","../src/features/idempotent/index.ts","../src/features/timeout/index.ts","../src/request.ts"],"names":["UreqError","message","options","NetworkError","TimeoutError","AbortError","HttpError","status","MemoryCacheStore","key","item","value","ttl","expires","DefaultHashService","input","hash","i","char","method","url","data","parts","InterceptorManager","interceptor","index","config","currentConfig","response","currentResponse","createRequestError","error","context","retryCount","isRetryableError","formatError","getErrorDetails","defaultRetryOptions","createRetryRequestor","requestor","finalOptions","retryRequest","request","retries","requestError","resolve","defaultCacheOptions","createCacheRequestor","cacheRequest","cached","defaultParallelOptions","RequestQueue","maxConcurrent","task","createParallelRequestor","queue","defaultHashService","defaultOptions","createIdempotentRequestor","pendingRequests","cleanupOldRequests","now","dedupeRequest","requestFn","requestId","existing","promise","createTimeoutRequestor","withTimeout","timeout","controller","timeoutId","timeoutError","signal","mergedOptions","createInterceptorRequestor","interceptors","wrapRequest","methodLower","Request","baseRequestor"],"mappings":"aAiDaA,IAAAA,CAAAA,CAAN,cAAwB,KAA8B,CAY3D,WAAA,CAAYC,CAAiBC,CAAAA,CAAAA,CAAiC,EAAC,CAAG,CAChE,KAAA,CAAMD,CAAO,CAAA,CACb,IAAK,CAAA,IAAA,CAAO,WACZ,CAAA,IAAA,CAAK,SAAY,CAAA,IAAA,CAAK,GAAI,EAAA,CAC1B,MAAO,CAAA,MAAA,CAAO,IAAMC,CAAAA,CAAO,EAC7B,CACF,CAEaC,CAAAA,CAAAA,CAAN,cAA2BH,CAAU,CAC1C,WAAYC,CAAAA,CAAAA,CAAiBC,CAAiC,CAAA,EAAI,CAAA,CAChE,KAAMD,CAAAA,CAAAA,CAAS,CAAE,GAAGC,CAAS,CAAA,cAAA,CAAgB,IAAK,CAAC,CACnD,CAAA,IAAA,CAAK,IAAO,CAAA,eACd,CACF,CAAA,CAEaE,CAAN,CAAA,cAA2BJ,CAAU,CAC1C,WAAYC,CAAAA,CAAAA,CAAiBC,CAAiC,CAAA,GAAI,CAChE,KAAA,CAAMD,CAAS,CAAA,CAAE,GAAGC,CAAAA,CAAS,SAAW,CAAA,IAAK,CAAC,CAAA,CAC9C,IAAK,CAAA,IAAA,CAAO,eACd,CACF,CAEaG,CAAAA,CAAAA,CAAN,cAAyBL,CAAU,CACxC,WAAA,CAAYC,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,CAAaC,CAAAA,CAAAA,CAAYnB,CAAsC,CAAA,CACtE,OAAO,IAAA,CAAK,OAAQ,CAAA,OAAA,CAASkB,CAAKC,CAAAA,CAAAA,CAAMnB,CAAO,CACjD,CAGF","file":"index.js","sourcesContent":["/**\n * 响应类型\n */\nexport type ResponseType = 'json' | 'text' | 'blob' | 'arraybuffer' | 'formData';\n\n/**\n * 响应转换器函数类型\n * @param response 原始响应对象(Fetch Response 或其他)\n * @returns 转换后的数据\n */\nexport type ResponseTransformer<T = any> = (response: any) => Promise<T>;\n\nexport interface RequestOptions {\n headers?: Record<string, string>;\n timeout?: number;\n signal?: AbortSignal;\n /**\n * 响应类型,用于指定如何解析响应体\n * @default 'json'\n */\n responseType?: ResponseType;\n /**\n * 自定义响应转换器,优先级高于 responseType\n * 当需要自定义响应解析逻辑时使用\n */\n responseTransformer?: ResponseTransformer;\n [key: string]: any;\n}\n\nexport interface Response<T = any> {\n data: T;\n status: number;\n statusText: string;\n headers: Record<string, string>;\n}\n\nexport interface RequestError extends Error {\n status?: number;\n code?: string;\n data?: any;\n url?: string;\n method?: string;\n timestamp?: number;\n retryCount?: number;\n isTimeout?: boolean;\n isNetworkError?: boolean;\n isAborted?: boolean;\n}\n\nexport class UreqError extends Error implements RequestError {\n status?: number;\n code?: string;\n data?: any;\n url?: string;\n method?: string;\n timestamp: number;\n retryCount?: number;\n isTimeout?: boolean;\n isNetworkError?: boolean;\n isAborted?: boolean;\n\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message);\n this.name = 'UreqError';\n this.timestamp = Date.now();\n Object.assign(this, options);\n }\n}\n\nexport class NetworkError extends UreqError {\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message, { ...options, isNetworkError: true });\n this.name = 'NetworkError';\n }\n}\n\nexport class TimeoutError extends UreqError {\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message, { ...options, isTimeout: true });\n this.name = 'TimeoutError';\n }\n}\n\nexport class AbortError extends UreqError {\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message, { ...options, isAborted: true });\n this.name = 'AbortError';\n }\n}\n\nexport class HttpError extends UreqError {\n constructor(message: string, status: number, options: Partial<RequestError> = {}) {\n super(message, { ...options, status });\n this.name = 'HttpError';\n }\n}\n\nexport interface Requestor {\n get<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;\n post<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;\n put<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;\n delete<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;\n patch<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;\n} ","/**\n * Cache store interface for storing and retrieving cached data\n */\nexport interface CacheStore {\n /**\n * Get a value from the cache\n */\n get<T>(key: string): Promise<T | undefined> | T | undefined;\n \n /**\n * Set a value in the cache with optional TTL\n */\n set<T>(key: string, value: T, ttl?: number): Promise<void> | void;\n \n /**\n * Delete a value from the cache\n */\n delete(key: string): Promise<void> | void;\n \n /**\n * Clear all values from the cache\n */\n clear(): Promise<void> | void;\n \n /**\n * Check if a key exists in the cache\n */\n has(key: string): Promise<boolean> | boolean;\n}\n\n/**\n * Simple in-memory cache store implementation\n */\nexport class MemoryCacheStore implements CacheStore {\n private cache = new Map<string, { value: any; expires?: number }>();\n\n get<T>(key: string): T | undefined {\n const item = this.cache.get(key);\n if (!item) return undefined;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return undefined;\n }\n \n return item.value;\n }\n\n set<T>(key: string, value: T, ttl?: number): void {\n const expires = ttl ? Date.now() + ttl : undefined;\n this.cache.set(key, { value, expires });\n }\n\n delete(key: string): void {\n this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n\n has(key: string): boolean {\n const item = this.cache.get(key);\n if (!item) return false;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return false;\n }\n \n return true;\n }\n}\n","/**\n * Hash service interface for generating request identifiers\n */\nexport interface HashService {\n /**\n * Generate a hash from a string input\n */\n generateHash(input: string): string;\n \n /**\n * Generate a hash for a request based on method, URL, data, and options\n */\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string;\n}\n\n/**\n * Default hash service implementation using simple hash algorithm\n */\nexport class DefaultHashService implements HashService {\n generateHash(input: string): string {\n let hash = 0;\n for (let i = 0; i < input.length; i++) {\n const char = input.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash = hash & hash; // Convert to 32-bit integer\n }\n return hash.toString(36);\n }\n\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string {\n const parts = [\n method.toUpperCase(),\n url,\n data ? JSON.stringify(data) : '',\n options ? JSON.stringify(options) : ''\n ];\n return this.generateHash(parts.join('|'));\n }\n}\n","import { RequestError, RequestOptions, Response } from \"./interfaces/request\";\n\nexport interface RequestInterceptor {\n onRequest?(config: RequestOptions): Promise<RequestOptions> | RequestOptions;\n onRequestError?(error: any): Promise<any>;\n}\n\nexport interface ResponseInterceptor {\n onResponse?<T>(response: Response<T>): Promise<Response<T>> | Response<T>;\n onResponseError?(error: RequestError): Promise<any>;\n}\n\nexport class InterceptorManager {\n private requestInterceptors: RequestInterceptor[] = [];\n private responseInterceptors: ResponseInterceptor[] = [];\n\n addRequestInterceptor(interceptor: RequestInterceptor) {\n this.requestInterceptors.push(interceptor);\n return () => {\n const index = this.requestInterceptors.indexOf(interceptor);\n if (index !== -1) {\n this.requestInterceptors.splice(index, 1);\n }\n };\n }\n\n addResponseInterceptor(interceptor: ResponseInterceptor) {\n this.responseInterceptors.push(interceptor);\n return () => {\n const index = this.responseInterceptors.indexOf(interceptor);\n if (index !== -1) {\n this.responseInterceptors.splice(index, 1);\n }\n };\n }\n\n async runRequestInterceptors(config: RequestOptions): Promise<RequestOptions> {\n let currentConfig = { ...config };\n for (const interceptor of this.requestInterceptors) {\n if (interceptor.onRequest) {\n currentConfig = await interceptor.onRequest(currentConfig);\n }\n }\n return currentConfig;\n }\n\n async runResponseInterceptors<T>(response: Response<T>): Promise<Response<T>> {\n let currentResponse = { ...response };\n for (const interceptor of this.responseInterceptors) {\n if (interceptor.onResponse) {\n currentResponse = await interceptor.onResponse(currentResponse);\n }\n }\n return currentResponse;\n }\n} ","import { \n RequestError, \n UreqError, \n NetworkError, \n TimeoutError, \n AbortError, \n HttpError \n} from '../interfaces/request.js';\n\nexport interface ErrorContext {\n url?: string;\n method?: string;\n retryCount?: number;\n requestId?: string;\n}\n\n/**\n * Creates appropriate error types based on the error context\n */\nexport function createRequestError(\n error: any, \n context: ErrorContext = {}\n): RequestError {\n const { url, method, retryCount } = context;\n \n // Handle AbortController signals\n if (error.name === 'AbortError' || error.code === 'ABORT_ERR') {\n return new AbortError('Request was aborted', {\n url,\n method,\n retryCount,\n code: 'ABORT_ERR'\n });\n }\n \n // Handle timeout errors\n if (error.name === 'TimeoutError' || error.message?.includes('timeout')) {\n return new TimeoutError('Request timed out', {\n url,\n method,\n retryCount,\n code: 'TIMEOUT'\n });\n }\n \n // Handle network errors\n if (error.name === 'TypeError' && error.message?.includes('fetch')) {\n return new NetworkError('Network request failed', {\n url,\n method,\n retryCount,\n code: 'NETWORK_ERROR'\n });\n }\n \n // Handle HTTP errors (Response objects)\n if (error instanceof globalThis.Response) {\n return new HttpError(\n `HTTP ${error.status}: ${error.statusText}`,\n error.status,\n {\n url,\n method,\n retryCount,\n code: `HTTP_${error.status}`,\n data: error\n }\n );\n }\n \n // Handle Axios errors\n if (error.response) {\n return new HttpError(\n `HTTP ${error.response.status}: ${error.response.statusText || 'Unknown Error'}`,\n error.response.status,\n {\n url: url || error.config?.url,\n method: method || error.config?.method?.toUpperCase(),\n retryCount,\n code: `HTTP_${error.response.status}`,\n data: error.response.data\n }\n );\n }\n \n // Handle Axios network errors\n if (error.request && !error.response) {\n return new NetworkError('Network request failed', {\n url: url || error.config?.url,\n method: method || error.config?.method?.toUpperCase(),\n retryCount,\n code: 'NETWORK_ERROR'\n });\n }\n \n // Handle already processed UreqError\n if (error instanceof UreqError) {\n // Update context if provided\n if (url && !error.url) error.url = url;\n if (method && !error.method) error.method = method;\n if (retryCount !== undefined) error.retryCount = retryCount;\n return error;\n }\n \n // Generic error fallback\n return new UreqError(error.message || 'Unknown error occurred', {\n url,\n method,\n retryCount,\n code: 'UNKNOWN_ERROR'\n });\n}\n\n/**\n * Determines if an error is retryable\n */\nexport function isRetryableError(error: RequestError): boolean {\n // Don't retry client errors (4xx) except for specific cases\n if (error.status && error.status >= 400 && error.status < 500) {\n // Retry on 408 (Request Timeout), 429 (Too Many Requests)\n return error.status === 408 || error.status === 429;\n }\n \n // Retry on server errors (5xx)\n if (error.status && error.status >= 500) {\n return true;\n }\n \n // Retry on network errors and timeouts\n if (error.isNetworkError || error.isTimeout) {\n return true;\n }\n \n // Don't retry aborted requests\n if (error.isAborted) {\n return false;\n }\n \n // Default to retryable for unknown errors\n return true;\n}\n\n/**\n * Formats error for logging\n */\nexport function formatError(error: RequestError): string {\n const parts = [\n `[${error.name}]`,\n error.message\n ];\n \n if (error.method && error.url) {\n parts.push(`(${error.method} ${error.url})`);\n }\n \n if (error.status) {\n parts.push(`Status: ${error.status}`);\n }\n \n if (error.retryCount !== undefined) {\n parts.push(`Retry: ${error.retryCount}`);\n }\n \n return parts.join(' ');\n}\n\n/**\n * Extracts error details for debugging\n */\nexport function getErrorDetails(error: RequestError): Record<string, any> {\n return {\n name: error.name,\n message: error.message,\n status: error.status,\n code: error.code,\n url: error.url,\n method: error.method,\n timestamp: error.timestamp,\n retryCount: error.retryCount,\n isTimeout: error.isTimeout,\n isNetworkError: error.isNetworkError,\n isAborted: error.isAborted,\n stack: error.stack\n };\n}\n","import { Requestor, RequestOptions, Response, RequestError } from '../../interfaces/request';\nimport { isRetryableError } from '../../utils/error';\n\nexport interface RetryOptions {\n maxRetries?: number;\n retryDelay?: number;\n shouldRetry?: (error: RequestError) => boolean | Promise<boolean>;\n}\n\nconst defaultRetryOptions: Required<RetryOptions> = {\n maxRetries: 3,\n retryDelay: 1000,\n shouldRetry: (error: RequestError) => isRetryableError(error),\n};\n\nexport function createRetryRequestor(\n requestor: Requestor,\n options?: RetryOptions\n): Requestor {\n const finalOptions = { ...defaultRetryOptions, ...options };\n\n async function retryRequest<T>(\n request: () => Promise<Response<T>>,\n retries = 0\n ): Promise<Response<T>> {\n try {\n return await request();\n } catch (error) {\n const requestError = error as RequestError;\n // Update retry count in error\n requestError.retryCount = retries;\n\n const shouldRetry = await finalOptions.shouldRetry(requestError);\n\n if (!shouldRetry || retries >= finalOptions.maxRetries) {\n throw requestError;\n }\n\n await new Promise(resolve => setTimeout(resolve, finalOptions.retryDelay));\n return retryRequest(request, retries + 1);\n }\n }\n\n return {\n async get<T>(url: string, options?: RequestOptions) {\n return retryRequest(() => requestor.get<T>(url, options));\n },\n\n async post<T>(url: string, data?: any, options?: RequestOptions) {\n return retryRequest(() => requestor.post<T>(url, data, options));\n },\n\n async put<T>(url: string, data?: any, options?: RequestOptions) {\n return retryRequest(() => requestor.put<T>(url, data, options));\n },\n\n async delete<T>(url: string, options?: RequestOptions) {\n return retryRequest(() => requestor.delete<T>(url, options));\n },\n\n async patch<T>(url: string, data?: any, options?: RequestOptions) {\n return retryRequest(() => requestor.patch<T>(url, data, options));\n },\n };\n} ","import { Requestor, RequestOptions, Response } from '../../interfaces/request';\nimport { CacheStore, MemoryCacheStore } from '../../interfaces/cache';\n\nexport interface CacheOptions {\n ttl?: number;\n store?: CacheStore;\n getCacheKey?: (url: string, options?: RequestOptions) => string;\n}\n\nconst defaultCacheOptions: Required<CacheOptions> = {\n ttl: 5 * 60 * 1000, // 5 minutes\n store: new MemoryCacheStore(),\n getCacheKey: (url: string, options?: RequestOptions) => {\n return `${url}${options ? JSON.stringify(options) : ''}`;\n },\n};\n\nexport function createCacheRequestor(\n requestor: Requestor,\n options?: CacheOptions\n): Requestor {\n const finalOptions = { ...defaultCacheOptions, ...options };\n\n async function cacheRequest<T>(\n key: string,\n request: () => Promise<Response<T>>\n ): Promise<Response<T>> {\n const cached = await finalOptions.store.get<Response<T>>(key);\n if (cached) {\n return cached;\n }\n\n const response = await request();\n await finalOptions.store.set(key, response, finalOptions.ttl);\n return response;\n }\n\n return {\n async get<T>(url: string, options?: RequestOptions) {\n const key = finalOptions.getCacheKey(url, options);\n return cacheRequest(key, () => requestor.get<T>(url, options));\n },\n\n // POST, PUT, DELETE, PATCH methods don't use cache\n post: requestor.post.bind(requestor),\n put: requestor.put.bind(requestor),\n delete: requestor.delete.bind(requestor),\n patch: requestor.patch.bind(requestor),\n };\n} ","import { Requestor, RequestOptions, Response } from '../../interfaces/request';\n\nexport interface ParallelOptions {\n maxConcurrent?: number;\n timeout?: number;\n}\n\nconst defaultParallelOptions: Required<ParallelOptions> = {\n maxConcurrent: 5,\n timeout: 30000,\n};\n\nclass RequestQueue {\n private queue: Array<() => void> = [];\n private running = 0;\n\n constructor(private maxConcurrent: number) {}\n\n async add<T>(task: () => Promise<T>): Promise<T> {\n if (this.running >= this.maxConcurrent) {\n await new Promise<void>((resolve) => {\n this.queue.push(resolve);\n });\n }\n\n this.running++;\n try {\n return await task();\n } finally {\n this.running--;\n if (this.queue.length > 0) {\n const next = this.queue.shift();\n next?.();\n }\n }\n }\n}\n\nexport function createParallelRequestor(\n requestor: Requestor,\n options?: ParallelOptions\n): Requestor {\n const finalOptions = { ...defaultParallelOptions, ...options };\n const queue = new RequestQueue(finalOptions.maxConcurrent);\n\n return {\n async get<T>(url: string, options?: RequestOptions) {\n return queue.add(() => requestor.get<T>(url, options));\n },\n\n async post<T>(url: string, data?: any, options?: RequestOptions) {\n return queue.add(() => requestor.post<T>(url, data, options));\n },\n\n async put<T>(url: string, data?: any, options?: RequestOptions) {\n return queue.add(() => requestor.put<T>(url, data, options));\n },\n\n async delete<T>(url: string, options?: RequestOptions) {\n return queue.add(() => requestor.delete<T>(url, options));\n },\n\n async patch<T>(url: string, data?: any, options?: RequestOptions) {\n return queue.add(() => requestor.patch<T>(url, data, options));\n },\n };\n} ","import { Requestor, RequestOptions, Response } from '../../interfaces/request';\nimport { HashService, DefaultHashService } from '../../interfaces/hash';\n\ninterface PendingRequest<T> {\n promise: Promise<Response<T>>;\n timestamp: number;\n}\n\nexport interface IdempotentOptions {\n // 请求合并的时间窗口,单位毫秒\n dedupeTime?: number;\n // 自定义请求标识生成函数\n getRequestId?: (method: string, url: string, data?: any, options?: RequestOptions) => string;\n // Hash service for generating request IDs\n hashService?: HashService;\n}\n\nconst defaultHashService = new DefaultHashService();\n\nconst defaultOptions: Required<IdempotentOptions> = {\n dedupeTime: 1000,\n getRequestId: (method: string, url: string, data?: any, options?: RequestOptions) => {\n return defaultHashService.generateRequestHash(method, url, data, options);\n },\n hashService: defaultHashService,\n};\n\nexport function createIdempotentRequestor(\n requestor: Requestor,\n options?: IdempotentOptions\n): Requestor {\n const finalOptions = { ...defaultOptions, ...options };\n const pendingRequests = new Map<string, PendingRequest<any>>();\n\n function cleanupOldRequests() {\n const now = Date.now();\n for (const [key, request] of pendingRequests.entries()) {\n if (now - request.timestamp > finalOptions.dedupeTime) {\n pendingRequests.delete(key);\n }\n }\n }\n\n async function dedupeRequest<T>(\n method: string,\n url: string,\n requestFn: () => Promise<Response<T>>,\n data?: any,\n options?: RequestOptions\n ): Promise<Response<T>> {\n const requestId = finalOptions.getRequestId(method, url, data, options);\n \n cleanupOldRequests();\n\n const existing = pendingRequests.get(requestId);\n if (existing) {\n return existing.promise;\n }\n\n const promise = requestFn();\n pendingRequests.set(requestId, {\n promise,\n timestamp: Date.now(),\n });\n\n try {\n return await promise;\n } finally {\n pendingRequests.delete(requestId);\n }\n }\n\n return {\n get: <T>(url: string, options?: RequestOptions) => {\n return dedupeRequest('GET', url, () => requestor.get<T>(url, options), null, options);\n },\n\n post: <T>(url: string, data?: any, options?: RequestOptions) => {\n return dedupeRequest('POST', url, () => requestor.post<T>(url, data, options), data, options);\n },\n\n put: <T>(url: string, data?: any, options?: RequestOptions) => {\n return dedupeRequest('PUT', url, () => requestor.put<T>(url, data, options), data, options);\n },\n\n delete: <T>(url: string, options?: RequestOptions) => {\n return dedupeRequest('DELETE', url, () => requestor.delete<T>(url, options), null, options);\n },\n\n patch: <T>(url: string, data?: any, options?: RequestOptions) => {\n return dedupeRequest('PATCH', url, () => requestor.patch<T>(url, data, options), data, options);\n },\n };\n} ","import { Requestor, RequestOptions, Response, RequestError } from '../../interfaces/request';\n\nexport interface TimeoutOptions {\n timeout?: number;\n timeoutErrorMessage?: string;\n}\n\nconst defaultOptions: Required<TimeoutOptions> = {\n timeout: 30000,\n timeoutErrorMessage: 'Request timeout',\n};\n\nexport function createTimeoutRequestor(\n requestor: Requestor,\n options?: TimeoutOptions\n): Requestor {\n const finalOptions = { ...defaultOptions, ...options };\n\n async function withTimeout<T>(\n request: () => Promise<Response<T>>,\n timeout: number = finalOptions.timeout\n ): Promise<Response<T>> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout);\n\n try {\n const response = await request();\n clearTimeout(timeoutId);\n return response;\n } catch (error) {\n clearTimeout(timeoutId);\n if (error instanceof DOMException && error.name === 'AbortError') {\n const timeoutError = new Error(finalOptions.timeoutErrorMessage) as RequestError;\n timeoutError.code = 'TIMEOUT';\n throw timeoutError;\n }\n throw error;\n }\n }\n\n return {\n get: <T>(url: string, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.get<T>(url, mergedOptions));\n },\n\n post: <T>(url: string, data?: any, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.post<T>(url, data, mergedOptions));\n },\n\n put: <T>(url: string, data?: any, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.put<T>(url, data, mergedOptions));\n },\n\n delete: <T>(url: string, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.delete<T>(url, mergedOptions));\n },\n\n patch: <T>(url: string, data?: any, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.patch<T>(url, data, mergedOptions));\n },\n };\n} ","import { Requestor, RequestOptions, Response } from './interfaces/request';\nimport { InterceptorManager } from './interceptor';\nimport { createRetryRequestor, RetryOptions } from './features/retry';\nimport { CacheOptions, createCacheRequestor } from './features/cache';\nimport { createParallelRequestor, ParallelOptions } from './features/parallel';\nimport { createIdempotentRequestor, IdempotentOptions } from './features/idempotent';\nimport { createTimeoutRequestor, TimeoutOptions } from './features/timeout';\n\nexport interface RequestConfig {\n retry?: RetryOptions;\n cache?: CacheOptions;\n parallel?: ParallelOptions;\n idempotent?: IdempotentOptions;\n timeout?: TimeoutOptions;\n}\n\n/**\n * 创建拦截器包装的 Requestor\n * 这样每次实际发起请求时都会经过拦截器\n */\nfunction createInterceptorRequestor(\n requestor: Requestor,\n interceptors: InterceptorManager\n): Requestor {\n const wrapRequest = async <T>(\n method: string,\n url: string,\n data: any,\n options?: RequestOptions\n ): Promise<Response<T>> => {\n // 运行请求拦截器\n const config = await interceptors.runRequestInterceptors({\n ...options,\n method,\n url,\n data,\n });\n\n // 发起实际请求\n const methodLower = method.toLowerCase();\n let response: Response<T>;\n\n if (methodLower === 'get' || methodLower === 'delete') {\n response = await (requestor as any)[methodLower](config.url, config);\n } else {\n response = await (requestor as any)[methodLower](config.url, config.data, config);\n }\n\n // 运行响应拦截器\n return interceptors.runResponseInterceptors(response);\n };\n\n return {\n async get<T>(url: string, options?: RequestOptions) {\n return wrapRequest<T>('GET', url, undefined, options);\n },\n async post<T>(url: string, data?: any, options?: RequestOptions) {\n return wrapRequest<T>('POST', url, data, options);\n },\n async put<T>(url: string, data?: any, options?: RequestOptions) {\n return wrapRequest<T>('PUT', url, data, options);\n },\n async delete<T>(url: string, options?: RequestOptions) {\n return wrapRequest<T>('DELETE', url, undefined, options);\n },\n async patch<T>(url: string, data?: any, options?: RequestOptions) {\n return wrapRequest<T>('PATCH', url, data, options);\n },\n };\n}\n\nexport class Request {\n private requestor: Requestor;\n public interceptors: InterceptorManager;\n\n constructor(baseRequestor: Requestor, config?: RequestConfig) {\n this.interceptors = new InterceptorManager();\n\n // 组合各种功能\n // 拦截器放在最内层,这样每次请求(包括重试)都会触发拦截器\n let requestor: Requestor = createInterceptorRequestor(baseRequestor, this.interceptors);\n\n if (config?.timeout) {\n requestor = createTimeoutRequestor(requestor, config.timeout);\n }\n\n if (config?.retry) {\n requestor = createRetryRequestor(requestor, config.retry);\n }\n\n if (config?.cache) {\n requestor = createCacheRequestor(requestor, config.cache);\n }\n\n if (config?.parallel) {\n requestor = createParallelRequestor(requestor, config.parallel);\n }\n\n if (config?.idempotent) {\n // 幂等\n requestor = createIdempotentRequestor(requestor, config.idempotent);\n }\n\n this.requestor = requestor;\n }\n\n async request<T>(method: string, url: string, data?: any, options?: RequestOptions): Promise<T> {\n // 拦截器已经在 createInterceptorRequestor 中处理\n // 直接调用 requestor,拦截器会在每次请求(包括重试)时自动触发\n const methodLower = method.toLowerCase();\n let response;\n\n if (methodLower === 'get' || methodLower === 'delete') {\n response = await (this.requestor as any)[methodLower](url, options);\n } else {\n response = await (this.requestor as any)[methodLower](url, data, options);\n }\n\n return response.data as T;\n }\n\n get<T>(url: string, options?: RequestOptions): Promise<T> {\n return this.request('GET', url, undefined, options);\n }\n\n post<T>(url: string, data?: any, options?: RequestOptions): Promise<T> {\n return this.request('POST', url, data, options);\n }\n\n put<T>(url: string, data?: any, options?: RequestOptions): Promise<T> {\n return this.request('PUT', url, data, options);\n }\n\n delete<T>(url: string, options?: RequestOptions): Promise<T> {\n return this.request('DELETE', url, undefined, options);\n }\n\n patch<T>(url: string, data?: any, options?: RequestOptions): Promise<T> {\n return this.request('PATCH', url, data, options);\n }\n\n // 实现其他方法...\n} "]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- var p=class extends Error{constructor(r,t={}){super(r),this.name="UreqError",this.timestamp=Date.now(),Object.assign(this,t);}},m=class extends p{constructor(r,t={}){super(r,{...t,isNetworkError:true}),this.name="NetworkError";}},l=class extends p{constructor(r,t={}){super(r,{...t,isTimeout:true}),this.name="TimeoutError";}},d=class extends p{constructor(r,t={}){super(r,{...t,isAborted:true}),this.name="AbortError";}},R=class extends p{constructor(r,t,s={}){super(r,{...s,status:t}),this.name="HttpError";}};var g=class{constructor(){this.cache=new Map;}get(r){let t=this.cache.get(r);if(t){if(t.expires&&Date.now()>t.expires){this.cache.delete(r);return}return t.value}}set(r,t,s){let n=s?Date.now()+s:void 0;this.cache.set(r,{value:t,expires:n});}delete(r){this.cache.delete(r);}clear(){this.cache.clear();}has(r){let t=this.cache.get(r);return t?t.expires&&Date.now()>t.expires?(this.cache.delete(r),false):true:false}};var T=class{generateHash(r){let t=0;for(let s=0;s<r.length;s++){let n=r.charCodeAt(s);t=(t<<5)-t+n,t=t&t;}return t.toString(36)}generateRequestHash(r,t,s,n){let i=[r.toUpperCase(),t,s?JSON.stringify(s):"",n?JSON.stringify(n):""];return this.generateHash(i.join("|"))}};var h=class{constructor(){this.requestInterceptors=[];this.responseInterceptors=[];}addRequestInterceptor(r){return this.requestInterceptors.push(r),()=>{let t=this.requestInterceptors.indexOf(r);t!==-1&&this.requestInterceptors.splice(t,1);}}addResponseInterceptor(r){return this.responseInterceptors.push(r),()=>{let t=this.responseInterceptors.indexOf(r);t!==-1&&this.responseInterceptors.splice(t,1);}}async runRequestInterceptors(r){let t={...r};for(let s of this.requestInterceptors)s.onRequest&&(t=await s.onRequest(t));return t}async runResponseInterceptors(r){let t={...r};for(let s of this.responseInterceptors)s.onResponse&&(t=await s.onResponse(t));return t}};function J(e,r={}){let{url:t,method:s,retryCount:n}=r;return e.name==="AbortError"||e.code==="ABORT_ERR"?new d("Request was aborted",{url:t,method:s,retryCount:n,code:"ABORT_ERR"}):e.name==="TimeoutError"||e.message?.includes("timeout")?new l("Request timed out",{url:t,method:s,retryCount:n,code:"TIMEOUT"}):e.name==="TypeError"&&e.message?.includes("fetch")?new m("Network request failed",{url:t,method:s,retryCount:n,code:"NETWORK_ERROR"}):e instanceof globalThis.Response?new R(`HTTP ${e.status}: ${e.statusText}`,e.status,{url:t,method:s,retryCount:n,code:`HTTP_${e.status}`,data:e}):e.response?new R(`HTTP ${e.response.status}: ${e.response.statusText||"Unknown Error"}`,e.response.status,{url:t||e.config?.url,method:s||e.config?.method?.toUpperCase(),retryCount:n,code:`HTTP_${e.response.status}`,data:e.response.data}):e.request&&!e.response?new m("Network request failed",{url:t||e.config?.url,method:s||e.config?.method?.toUpperCase(),retryCount:n,code:"NETWORK_ERROR"}):e instanceof p?(t&&!e.url&&(e.url=t),s&&!e.method&&(e.method=s),n!==void 0&&(e.retryCount=n),e):new p(e.message||"Unknown error occurred",{url:t,method:s,retryCount:n,code:"UNKNOWN_ERROR"})}function x(e){return e.status&&e.status>=400&&e.status<500?e.status===408||e.status===429:e.status&&e.status>=500||e.isNetworkError||e.isTimeout?true:!e.isAborted}function L(e){let r=[`[${e.name}]`,e.message];return e.method&&e.url&&r.push(`(${e.method} ${e.url})`),e.status&&r.push(`Status: ${e.status}`),e.retryCount!==void 0&&r.push(`Retry: ${e.retryCount}`),r.join(" ")}function W(e){return {name:e.name,message:e.message,status:e.status,code:e.code,url:e.url,method:e.method,timestamp:e.timestamp,retryCount:e.retryCount,isTimeout:e.isTimeout,isNetworkError:e.isNetworkError,isAborted:e.isAborted,stack:e.stack}}var S={maxRetries:3,retryDelay:1e3,shouldRetry:e=>x(e)};function E(e,r){let t={...S,...r};async function s(n,i=0){try{return await n()}catch(o){let a=o;if(a.retryCount=i,!await t.shouldRetry(a)||i>=t.maxRetries)throw a;return await new Promise(c=>setTimeout(c,t.retryDelay)),s(n,i+1)}}return {async get(n,i){return s(()=>e.get(n,i))},async post(n,i,o){return s(()=>e.post(n,i,o))},async put(n,i,o){return s(()=>e.put(n,i,o))},async delete(n,i){return s(()=>e.delete(n,i))},async patch(n,i,o){return s(()=>e.patch(n,i,o))}}}var k={ttl:5*60*1e3,store:new g,getCacheKey:(e,r)=>`${e}${r?JSON.stringify(r):""}`};function b(e,r){let t={...k,...r};async function s(n,i){let o=await t.store.get(n);if(o)return o;let a=await i();return await t.store.set(n,a,t.ttl),a}return {async get(n,i){let o=t.getCacheKey(n,i);return s(o,()=>e.get(n,i))},post:e.post.bind(e),put:e.put.bind(e),delete:e.delete.bind(e),patch:e.patch.bind(e)}}var H={maxConcurrent:5,timeout:3e4},q=class{constructor(r){this.maxConcurrent=r;this.queue=[];this.running=0;}async add(r){this.running>=this.maxConcurrent&&await new Promise(t=>{this.queue.push(t);}),this.running++;try{return await r()}finally{this.running--,this.queue.length>0&&this.queue.shift()?.();}}};function w(e,r){let t={...H,...r},s=new q(t.maxConcurrent);return {async get(n,i){return s.add(()=>e.get(n,i))},async post(n,i,o){return s.add(()=>e.post(n,i,o))},async put(n,i,o){return s.add(()=>e.put(n,i,o))},async delete(n,i){return s.add(()=>e.delete(n,i))},async patch(n,i,o){return s.add(()=>e.patch(n,i,o))}}}var P=new T,N={dedupeTime:1e3,getRequestId:(e,r,t,s)=>P.generateRequestHash(e,r,t,s),hashService:P};function C(e,r){let t={...N,...r},s=new Map;function n(){let o=Date.now();for(let[a,u]of s.entries())o-u.timestamp>t.dedupeTime&&s.delete(a);}async function i(o,a,u,c,A){let f=t.getRequestId(o,a,c,A);n();let y=s.get(f);if(y)return y.promise;let O=u();s.set(f,{promise:O,timestamp:Date.now()});try{return await O}finally{s.delete(f);}}return {get:(o,a)=>i("GET",o,()=>e.get(o,a),null,a),post:(o,a,u)=>i("POST",o,()=>e.post(o,a,u),a,u),put:(o,a,u)=>i("PUT",o,()=>e.put(o,a,u),a,u),delete:(o,a)=>i("DELETE",o,()=>e.delete(o,a),null,a),patch:(o,a,u)=>i("PATCH",o,()=>e.patch(o,a,u),a,u)}}var D={timeout:3e4,timeoutErrorMessage:"Request timeout"};function I(e,r){let t={...D,...r};async function s(n,i=t.timeout){let o=new AbortController,a=setTimeout(()=>o.abort(),i);try{let u=await n();return clearTimeout(a),u}catch(u){if(clearTimeout(a),u instanceof DOMException&&u.name==="AbortError"){let c=new Error(t.timeoutErrorMessage);throw c.code="TIMEOUT",c}throw u}}return {get:(n,i)=>{let o=i?.signal,a={...i,signal:o||new AbortController().signal};return s(()=>e.get(n,a))},post:(n,i,o)=>{let a=o?.signal,u={...o,signal:a||new AbortController().signal};return s(()=>e.post(n,i,u))},put:(n,i,o)=>{let a=o?.signal,u={...o,signal:a||new AbortController().signal};return s(()=>e.put(n,i,u))},delete:(n,i)=>{let o=i?.signal,a={...i,signal:o||new AbortController().signal};return s(()=>e.delete(n,a))},patch:(n,i,o)=>{let a=o?.signal,u={...o,signal:a||new AbortController().signal};return s(()=>e.patch(n,i,u))}}}var v=class{constructor(r,t){this.interceptors=new h;let s=r;t?.timeout&&(s=I(s,t.timeout)),t?.retry&&(s=E(s,t.retry)),t?.cache&&(s=b(s,t.cache)),t?.parallel&&(s=w(s,t.parallel)),t?.idempotent&&(s=C(s,t.idempotent)),this.requestor=s;}async request(r,t,s,n){let i=await this.interceptors.runRequestInterceptors({...n,method:r,url:t,data:s});try{let o=r.toLowerCase(),a=await this.requestor[o](t,s,i);return (await this.interceptors.runResponseInterceptors(a)).data}catch(o){throw o}}get(r,t){return this.request("GET",r,void 0,t)}post(r,t,s){return this.request("POST",r,t,s)}put(r,t,s){return this.request("PUT",r,t,s)}delete(r,t){return this.request("DELETE",r,void 0,t)}patch(r,t,s){return this.request("PATCH",r,t,s)}};export{d as AbortError,T as DefaultHashService,R as HttpError,h as InterceptorManager,g as MemoryCacheStore,m as NetworkError,v as Request,l as TimeoutError,p as UreqError,b as createCacheRequestor,C as createIdempotentRequestor,w as createParallelRequestor,J as createRequestError,E as createRetryRequestor,I as createTimeoutRequestor,L as formatError,W as getErrorDetails,x as isRetryableError};//# sourceMappingURL=index.mjs.map
1
+ var c=class extends Error{constructor(n,t={}){super(n),this.name="UreqError",this.timestamp=Date.now(),Object.assign(this,t);}},m=class extends c{constructor(n,t={}){super(n,{...t,isNetworkError:true}),this.name="NetworkError";}},l=class extends c{constructor(n,t={}){super(n,{...t,isTimeout:true}),this.name="TimeoutError";}},d=class extends c{constructor(n,t={}){super(n,{...t,isAborted:true}),this.name="AbortError";}},R=class extends c{constructor(n,t,s={}){super(n,{...s,status:t}),this.name="HttpError";}};var g=class{constructor(){this.cache=new Map;}get(n){let t=this.cache.get(n);if(t){if(t.expires&&Date.now()>t.expires){this.cache.delete(n);return}return t.value}}set(n,t,s){let r=s?Date.now()+s:void 0;this.cache.set(n,{value:t,expires:r});}delete(n){this.cache.delete(n);}clear(){this.cache.clear();}has(n){let t=this.cache.get(n);return t?t.expires&&Date.now()>t.expires?(this.cache.delete(n),false):true:false}};var T=class{generateHash(n){let t=0;for(let s=0;s<n.length;s++){let r=n.charCodeAt(s);t=(t<<5)-t+r,t=t&t;}return t.toString(36)}generateRequestHash(n,t,s,r){let o=[n.toUpperCase(),t,s?JSON.stringify(s):"",r?JSON.stringify(r):""];return this.generateHash(o.join("|"))}};var f=class{constructor(){this.requestInterceptors=[];this.responseInterceptors=[];}addRequestInterceptor(n){return this.requestInterceptors.push(n),()=>{let t=this.requestInterceptors.indexOf(n);t!==-1&&this.requestInterceptors.splice(t,1);}}addResponseInterceptor(n){return this.responseInterceptors.push(n),()=>{let t=this.responseInterceptors.indexOf(n);t!==-1&&this.responseInterceptors.splice(t,1);}}async runRequestInterceptors(n){let t={...n};for(let s of this.requestInterceptors)s.onRequest&&(t=await s.onRequest(t));return t}async runResponseInterceptors(n){let t={...n};for(let s of this.responseInterceptors)s.onResponse&&(t=await s.onResponse(t));return t}};function G(e,n={}){let{url:t,method:s,retryCount:r}=n;return e.name==="AbortError"||e.code==="ABORT_ERR"?new d("Request was aborted",{url:t,method:s,retryCount:r,code:"ABORT_ERR"}):e.name==="TimeoutError"||e.message?.includes("timeout")?new l("Request timed out",{url:t,method:s,retryCount:r,code:"TIMEOUT"}):e.name==="TypeError"&&e.message?.includes("fetch")?new m("Network request failed",{url:t,method:s,retryCount:r,code:"NETWORK_ERROR"}):e instanceof globalThis.Response?new R(`HTTP ${e.status}: ${e.statusText}`,e.status,{url:t,method:s,retryCount:r,code:`HTTP_${e.status}`,data:e}):e.response?new R(`HTTP ${e.response.status}: ${e.response.statusText||"Unknown Error"}`,e.response.status,{url:t||e.config?.url,method:s||e.config?.method?.toUpperCase(),retryCount:r,code:`HTTP_${e.response.status}`,data:e.response.data}):e.request&&!e.response?new m("Network request failed",{url:t||e.config?.url,method:s||e.config?.method?.toUpperCase(),retryCount:r,code:"NETWORK_ERROR"}):e instanceof c?(t&&!e.url&&(e.url=t),s&&!e.method&&(e.method=s),r!==void 0&&(e.retryCount=r),e):new c(e.message||"Unknown error occurred",{url:t,method:s,retryCount:r,code:"UNKNOWN_ERROR"})}function x(e){return e.status&&e.status>=400&&e.status<500?e.status===408||e.status===429:e.status&&e.status>=500||e.isNetworkError||e.isTimeout?true:!e.isAborted}function J(e){let n=[`[${e.name}]`,e.message];return e.method&&e.url&&n.push(`(${e.method} ${e.url})`),e.status&&n.push(`Status: ${e.status}`),e.retryCount!==void 0&&n.push(`Retry: ${e.retryCount}`),n.join(" ")}function W(e){return {name:e.name,message:e.message,status:e.status,code:e.code,url:e.url,method:e.method,timestamp:e.timestamp,retryCount:e.retryCount,isTimeout:e.isTimeout,isNetworkError:e.isNetworkError,isAborted:e.isAborted,stack:e.stack}}var S={maxRetries:3,retryDelay:1e3,shouldRetry:e=>x(e)};function E(e,n){let t={...S,...n};async function s(r,o=0){try{return await r()}catch(i){let a=i;if(a.retryCount=o,!await t.shouldRetry(a)||o>=t.maxRetries)throw a;return await new Promise(p=>setTimeout(p,t.retryDelay)),s(r,o+1)}}return {async get(r,o){return s(()=>e.get(r,o))},async post(r,o,i){return s(()=>e.post(r,o,i))},async put(r,o,i){return s(()=>e.put(r,o,i))},async delete(r,o){return s(()=>e.delete(r,o))},async patch(r,o,i){return s(()=>e.patch(r,o,i))}}}var H={ttl:5*60*1e3,store:new g,getCacheKey:(e,n)=>`${e}${n?JSON.stringify(n):""}`};function w(e,n){let t={...H,...n};async function s(r,o){let i=await t.store.get(r);if(i)return i;let a=await o();return await t.store.set(r,a,t.ttl),a}return {async get(r,o){let i=t.getCacheKey(r,o);return s(i,()=>e.get(r,o))},post:e.post.bind(e),put:e.put.bind(e),delete:e.delete.bind(e),patch:e.patch.bind(e)}}var k={maxConcurrent:5,timeout:3e4},h=class{constructor(n){this.maxConcurrent=n;this.queue=[];this.running=0;}async add(n){this.running>=this.maxConcurrent&&await new Promise(t=>{this.queue.push(t);}),this.running++;try{return await n()}finally{this.running--,this.queue.length>0&&this.queue.shift()?.();}}};function P(e,n){let t={...k,...n},s=new h(t.maxConcurrent);return {async get(r,o){return s.add(()=>e.get(r,o))},async post(r,o,i){return s.add(()=>e.post(r,o,i))},async put(r,o,i){return s.add(()=>e.put(r,o,i))},async delete(r,o){return s.add(()=>e.delete(r,o))},async patch(r,o,i){return s.add(()=>e.patch(r,o,i))}}}var b=new T,N={dedupeTime:1e3,getRequestId:(e,n,t,s)=>b.generateRequestHash(e,n,t,s),hashService:b};function C(e,n){let t={...N,...n},s=new Map;function r(){let i=Date.now();for(let[a,u]of s.entries())i-u.timestamp>t.dedupeTime&&s.delete(a);}async function o(i,a,u,p,A){let q=t.getRequestId(i,a,p,A);r();let y=s.get(q);if(y)return y.promise;let O=u();s.set(q,{promise:O,timestamp:Date.now()});try{return await O}finally{s.delete(q);}}return {get:(i,a)=>o("GET",i,()=>e.get(i,a),null,a),post:(i,a,u)=>o("POST",i,()=>e.post(i,a,u),a,u),put:(i,a,u)=>o("PUT",i,()=>e.put(i,a,u),a,u),delete:(i,a)=>o("DELETE",i,()=>e.delete(i,a),null,a),patch:(i,a,u)=>o("PATCH",i,()=>e.patch(i,a,u),a,u)}}var D={timeout:3e4,timeoutErrorMessage:"Request timeout"};function I(e,n){let t={...D,...n};async function s(r,o=t.timeout){let i=new AbortController,a=setTimeout(()=>i.abort(),o);try{let u=await r();return clearTimeout(a),u}catch(u){if(clearTimeout(a),u instanceof DOMException&&u.name==="AbortError"){let p=new Error(t.timeoutErrorMessage);throw p.code="TIMEOUT",p}throw u}}return {get:(r,o)=>{let i=o?.signal,a={...o,signal:i||new AbortController().signal};return s(()=>e.get(r,a))},post:(r,o,i)=>{let a=i?.signal,u={...i,signal:a||new AbortController().signal};return s(()=>e.post(r,o,u))},put:(r,o,i)=>{let a=i?.signal,u={...i,signal:a||new AbortController().signal};return s(()=>e.put(r,o,u))},delete:(r,o)=>{let i=o?.signal,a={...o,signal:i||new AbortController().signal};return s(()=>e.delete(r,a))},patch:(r,o,i)=>{let a=i?.signal,u={...i,signal:a||new AbortController().signal};return s(()=>e.patch(r,o,u))}}}function $(e,n){let t=async(s,r,o,i)=>{let a=await n.runRequestInterceptors({...i,method:s,url:r,data:o}),u=s.toLowerCase(),p;return u==="get"||u==="delete"?p=await e[u](a.url,a):p=await e[u](a.url,a.data,a),n.runResponseInterceptors(p)};return {async get(s,r){return t("GET",s,void 0,r)},async post(s,r,o){return t("POST",s,r,o)},async put(s,r,o){return t("PUT",s,r,o)},async delete(s,r){return t("DELETE",s,void 0,r)},async patch(s,r,o){return t("PATCH",s,r,o)}}}var v=class{constructor(n,t){this.interceptors=new f;let s=$(n,this.interceptors);t?.timeout&&(s=I(s,t.timeout)),t?.retry&&(s=E(s,t.retry)),t?.cache&&(s=w(s,t.cache)),t?.parallel&&(s=P(s,t.parallel)),t?.idempotent&&(s=C(s,t.idempotent)),this.requestor=s;}async request(n,t,s,r){let o=n.toLowerCase(),i;return o==="get"||o==="delete"?i=await this.requestor[o](t,r):i=await this.requestor[o](t,s,r),i.data}get(n,t){return this.request("GET",n,void 0,t)}post(n,t,s){return this.request("POST",n,t,s)}put(n,t,s){return this.request("PUT",n,t,s)}delete(n,t){return this.request("DELETE",n,void 0,t)}patch(n,t,s){return this.request("PATCH",n,t,s)}};export{d as AbortError,T as DefaultHashService,R as HttpError,f as InterceptorManager,g as MemoryCacheStore,m as NetworkError,v as Request,l as TimeoutError,c as UreqError,w as createCacheRequestor,C as createIdempotentRequestor,P as createParallelRequestor,G as createRequestError,E as createRetryRequestor,I as createTimeoutRequestor,J as formatError,W as getErrorDetails,x as isRetryableError};//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interfaces/request.ts","../src/interfaces/cache.ts","../src/interfaces/hash.ts","../src/interceptor.ts","../src/utils/error.ts","../src/features/retry/index.ts","../src/features/cache/index.ts","../src/features/parallel/index.ts","../src/features/idempotent/index.ts","../src/features/timeout/index.ts","../src/request.ts"],"names":["UreqError","message","options","NetworkError","TimeoutError","AbortError","HttpError","status","MemoryCacheStore","key","item","value","ttl","expires","DefaultHashService","input","hash","i","char","method","url","data","parts","InterceptorManager","interceptor","index","config","currentConfig","response","currentResponse","createRequestError","error","context","retryCount","isRetryableError","formatError","getErrorDetails","defaultRetryOptions","createRetryRequestor","requestor","finalOptions","retryRequest","request","retries","requestError","resolve","defaultCacheOptions","createCacheRequestor","cacheRequest","cached","defaultParallelOptions","RequestQueue","maxConcurrent","task","createParallelRequestor","queue","defaultHashService","defaultOptions","createIdempotentRequestor","pendingRequests","cleanupOldRequests","now","dedupeRequest","requestFn","requestId","existing","promise","createTimeoutRequestor","withTimeout","timeout","controller","timeoutId","timeoutError","signal","mergedOptions","Request","baseRequestor","requestMethod"],"mappings":"AA4BaA,IAAAA,CAAAA,CAAN,cAAwB,KAA8B,CAY3D,WAAA,CAAYC,EAAiBC,CAAiC,CAAA,EAAI,CAAA,CAChE,KAAMD,CAAAA,CAAO,EACb,IAAK,CAAA,IAAA,CAAO,WACZ,CAAA,IAAA,CAAK,SAAY,CAAA,IAAA,CAAK,G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s","sourcesContent":["export interface RequestOptions {\n headers?: Record<string, string>;\n timeout?: number;\n signal?: AbortSignal;\n responseType?: 'arraybuffer' | 'json' | 'text' | 'blob';\n [key: string]: any;\n}\n\nexport interface Response<T = any> {\n data: T;\n status: number;\n statusText: string;\n headers: Record<string, string>;\n}\n\nexport interface RequestError extends Error {\n status?: number;\n code?: string;\n data?: any;\n url?: string;\n method?: string;\n timestamp?: number;\n retryCount?: number;\n isTimeout?: boolean;\n isNetworkError?: boolean;\n isAborted?: boolean;\n}\n\nexport class UreqError extends Error implements RequestError {\n status?: number;\n code?: string;\n data?: any;\n url?: string;\n method?: string;\n timestamp: number;\n retryCount?: number;\n isTimeout?: boolean;\n isNetworkError?: boolean;\n isAborted?: boolean;\n\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message);\n this.name = 'UreqError';\n this.timestamp = Date.now();\n Object.assign(this, options);\n }\n}\n\nexport class NetworkError extends UreqError {\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message, { ...options, isNetworkError: true });\n this.name = 'NetworkError';\n }\n}\n\nexport class TimeoutError extends UreqError {\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message, { ...options, isTimeout: true });\n this.name = 'TimeoutError';\n }\n}\n\nexport class AbortError extends UreqError {\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message, { ...options, isAborted: true });\n this.name = 'AbortError';\n }\n}\n\nexport class HttpError extends UreqError {\n constructor(message: string, status: number, options: Partial<RequestError> = {}) {\n super(message, { ...options, status });\n this.name = 'HttpError';\n }\n}\n\nexport interface Requestor {\n get<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;\n post<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;\n put<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;\n delete<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;\n patch<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;\n} ","/**\n * Cache store interface for storing and retrieving cached data\n */\nexport interface CacheStore {\n /**\n * Get a value from the cache\n */\n get<T>(key: string): Promise<T | undefined> | T | undefined;\n \n /**\n * Set a value in the cache with optional TTL\n */\n set<T>(key: string, value: T, ttl?: number): Promise<void> | void;\n \n /**\n * Delete a value from the cache\n */\n delete(key: string): Promise<void> | void;\n \n /**\n * Clear all values from the cache\n */\n clear(): Promise<void> | void;\n \n /**\n * Check if a key exists in the cache\n */\n has(key: string): Promise<boolean> | boolean;\n}\n\n/**\n * Simple in-memory cache store implementation\n */\nexport class MemoryCacheStore implements CacheStore {\n private cache = new Map<string, { value: any; expires?: number }>();\n\n get<T>(key: string): T | undefined {\n const item = this.cache.get(key);\n if (!item) return undefined;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return undefined;\n }\n \n return item.value;\n }\n\n set<T>(key: string, value: T, ttl?: number): void {\n const expires = ttl ? Date.now() + ttl : undefined;\n this.cache.set(key, { value, expires });\n }\n\n delete(key: string): void {\n this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n\n has(key: string): boolean {\n const item = this.cache.get(key);\n if (!item) return false;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return false;\n }\n \n return true;\n }\n}\n","/**\n * Hash service interface for generating request identifiers\n */\nexport interface HashService {\n /**\n * Generate a hash from a string input\n */\n generateHash(input: string): string;\n \n /**\n * Generate a hash for a request based on method, URL, data, and options\n */\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string;\n}\n\n/**\n * Default hash service implementation using simple hash algorithm\n */\nexport class DefaultHashService implements HashService {\n generateHash(input: string): string {\n let hash = 0;\n for (let i = 0; i < input.length; i++) {\n const char = input.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash = hash & hash; // Convert to 32-bit integer\n }\n return hash.toString(36);\n }\n\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string {\n const parts = [\n method.toUpperCase(),\n url,\n data ? JSON.stringify(data) : '',\n options ? JSON.stringify(options) : ''\n ];\n return this.generateHash(parts.join('|'));\n }\n}\n","import { RequestError, RequestOptions, Response } from \"./interfaces/request\";\n\nexport interface RequestInterceptor {\n onRequest?(config: RequestOptions): Promise<RequestOptions> | RequestOptions;\n onRequestError?(error: any): Promise<any>;\n}\n\nexport interface ResponseInterceptor {\n onResponse?<T>(response: Response<T>): Promise<Response<T>> | Response<T>;\n onResponseError?(error: RequestError): Promise<any>;\n}\n\nexport class InterceptorManager {\n private requestInterceptors: RequestInterceptor[] = [];\n private responseInterceptors: ResponseInterceptor[] = [];\n\n addRequestInterceptor(interceptor: RequestInterceptor) {\n this.requestInterceptors.push(interceptor);\n return () => {\n const index = this.requestInterceptors.indexOf(interceptor);\n if (index !== -1) {\n this.requestInterceptors.splice(index, 1);\n }\n };\n }\n\n addResponseInterceptor(interceptor: ResponseInterceptor) {\n this.responseInterceptors.push(interceptor);\n return () => {\n const index = this.responseInterceptors.indexOf(interceptor);\n if (index !== -1) {\n this.responseInterceptors.splice(index, 1);\n }\n };\n }\n\n async runRequestInterceptors(config: RequestOptions): Promise<RequestOptions> {\n let currentConfig = { ...config };\n for (const interceptor of this.requestInterceptors) {\n if (interceptor.onRequest) {\n currentConfig = await interceptor.onRequest(currentConfig);\n }\n }\n return currentConfig;\n }\n\n async runResponseInterceptors<T>(response: Response<T>): Promise<Response<T>> {\n let currentResponse = { ...response };\n for (const interceptor of this.responseInterceptors) {\n if (interceptor.onResponse) {\n currentResponse = await interceptor.onResponse(currentResponse);\n }\n }\n return currentResponse;\n }\n} ","import { \n RequestError, \n UreqError, \n NetworkError, \n TimeoutError, \n AbortError, \n HttpError \n} from '../interfaces/request.js';\n\nexport interface ErrorContext {\n url?: string;\n method?: string;\n retryCount?: number;\n requestId?: string;\n}\n\n/**\n * Creates appropriate error types based on the error context\n */\nexport function createRequestError(\n error: any, \n context: ErrorContext = {}\n): RequestError {\n const { url, method, retryCount } = context;\n \n // Handle AbortController signals\n if (error.name === 'AbortError' || error.code === 'ABORT_ERR') {\n return new AbortError('Request was aborted', {\n url,\n method,\n retryCount,\n code: 'ABORT_ERR'\n });\n }\n \n // Handle timeout errors\n if (error.name === 'TimeoutError' || error.message?.includes('timeout')) {\n return new TimeoutError('Request timed out', {\n url,\n method,\n retryCount,\n code: 'TIMEOUT'\n });\n }\n \n // Handle network errors\n if (error.name === 'TypeError' && error.message?.includes('fetch')) {\n return new NetworkError('Network request failed', {\n url,\n method,\n retryCount,\n code: 'NETWORK_ERROR'\n });\n }\n \n // Handle HTTP errors (Response objects)\n if (error instanceof globalThis.Response) {\n return new HttpError(\n `HTTP ${error.status}: ${error.statusText}`,\n error.status,\n {\n url,\n method,\n retryCount,\n code: `HTTP_${error.status}`,\n data: error\n }\n );\n }\n \n // Handle Axios errors\n if (error.response) {\n return new HttpError(\n `HTTP ${error.response.status}: ${error.response.statusText || 'Unknown Error'}`,\n error.response.status,\n {\n url: url || error.config?.url,\n method: method || error.config?.method?.toUpperCase(),\n retryCount,\n code: `HTTP_${error.response.status}`,\n data: error.response.data\n }\n );\n }\n \n // Handle Axios network errors\n if (error.request && !error.response) {\n return new NetworkError('Network request failed', {\n url: url || error.config?.url,\n method: method || error.config?.method?.toUpperCase(),\n retryCount,\n code: 'NETWORK_ERROR'\n });\n }\n \n // Handle already processed UreqError\n if (error instanceof UreqError) {\n // Update context if provided\n if (url && !error.url) error.url = url;\n if (method && !error.method) error.method = method;\n if (retryCount !== undefined) error.retryCount = retryCount;\n return error;\n }\n \n // Generic error fallback\n return new UreqError(error.message || 'Unknown error occurred', {\n url,\n method,\n retryCount,\n code: 'UNKNOWN_ERROR'\n });\n}\n\n/**\n * Determines if an error is retryable\n */\nexport function isRetryableError(error: RequestError): boolean {\n // Don't retry client errors (4xx) except for specific cases\n if (error.status && error.status >= 400 && error.status < 500) {\n // Retry on 408 (Request Timeout), 429 (Too Many Requests)\n return error.status === 408 || error.status === 429;\n }\n \n // Retry on server errors (5xx)\n if (error.status && error.status >= 500) {\n return true;\n }\n \n // Retry on network errors and timeouts\n if (error.isNetworkError || error.isTimeout) {\n return true;\n }\n \n // Don't retry aborted requests\n if (error.isAborted) {\n return false;\n }\n \n // Default to retryable for unknown errors\n return true;\n}\n\n/**\n * Formats error for logging\n */\nexport function formatError(error: RequestError): string {\n const parts = [\n `[${error.name}]`,\n error.message\n ];\n \n if (error.method && error.url) {\n parts.push(`(${error.method} ${error.url})`);\n }\n \n if (error.status) {\n parts.push(`Status: ${error.status}`);\n }\n \n if (error.retryCount !== undefined) {\n parts.push(`Retry: ${error.retryCount}`);\n }\n \n return parts.join(' ');\n}\n\n/**\n * Extracts error details for debugging\n */\nexport function getErrorDetails(error: RequestError): Record<string, any> {\n return {\n name: error.name,\n message: error.message,\n status: error.status,\n code: error.code,\n url: error.url,\n method: error.method,\n timestamp: error.timestamp,\n retryCount: error.retryCount,\n isTimeout: error.isTimeout,\n isNetworkError: error.isNetworkError,\n isAborted: error.isAborted,\n stack: error.stack\n };\n}\n","import { Requestor, RequestOptions, Response, RequestError } from '../../interfaces/request';\nimport { isRetryableError } from '../../utils/error';\n\nexport interface RetryOptions {\n maxRetries?: number;\n retryDelay?: number;\n shouldRetry?: (error: RequestError) => boolean | Promise<boolean>;\n}\n\nconst defaultRetryOptions: Required<RetryOptions> = {\n maxRetries: 3,\n retryDelay: 1000,\n shouldRetry: (error: RequestError) => isRetryableError(error),\n};\n\nexport function createRetryRequestor(\n requestor: Requestor,\n options?: RetryOptions\n): Requestor {\n const finalOptions = { ...defaultRetryOptions, ...options };\n\n async function retryRequest<T>(\n request: () => Promise<Response<T>>,\n retries = 0\n ): Promise<Response<T>> {\n try {\n return await request();\n } catch (error) {\n const requestError = error as RequestError;\n // Update retry count in error\n requestError.retryCount = retries;\n\n const shouldRetry = await finalOptions.shouldRetry(requestError);\n\n if (!shouldRetry || retries >= finalOptions.maxRetries) {\n throw requestError;\n }\n\n await new Promise(resolve => setTimeout(resolve, finalOptions.retryDelay));\n return retryRequest(request, retries + 1);\n }\n }\n\n return {\n async get<T>(url: string, options?: RequestOptions) {\n return retryRequest(() => requestor.get<T>(url, options));\n },\n\n async post<T>(url: string, data?: any, options?: RequestOptions) {\n return retryRequest(() => requestor.post<T>(url, data, options));\n },\n\n async put<T>(url: string, data?: any, options?: RequestOptions) {\n return retryRequest(() => requestor.put<T>(url, data, options));\n },\n\n async delete<T>(url: string, options?: RequestOptions) {\n return retryRequest(() => requestor.delete<T>(url, options));\n },\n\n async patch<T>(url: string, data?: any, options?: RequestOptions) {\n return retryRequest(() => requestor.patch<T>(url, data, options));\n },\n };\n} ","import { Requestor, RequestOptions, Response } from '../../interfaces/request';\nimport { CacheStore, MemoryCacheStore } from '../../interfaces/cache';\n\nexport interface CacheOptions {\n ttl?: number;\n store?: CacheStore;\n getCacheKey?: (url: string, options?: RequestOptions) => string;\n}\n\nconst defaultCacheOptions: Required<CacheOptions> = {\n ttl: 5 * 60 * 1000, // 5 minutes\n store: new MemoryCacheStore(),\n getCacheKey: (url: string, options?: RequestOptions) => {\n return `${url}${options ? JSON.stringify(options) : ''}`;\n },\n};\n\nexport function createCacheRequestor(\n requestor: Requestor,\n options?: CacheOptions\n): Requestor {\n const finalOptions = { ...defaultCacheOptions, ...options };\n\n async function cacheRequest<T>(\n key: string,\n request: () => Promise<Response<T>>\n ): Promise<Response<T>> {\n const cached = await finalOptions.store.get<Response<T>>(key);\n if (cached) {\n return cached;\n }\n\n const response = await request();\n await finalOptions.store.set(key, response, finalOptions.ttl);\n return response;\n }\n\n return {\n async get<T>(url: string, options?: RequestOptions) {\n const key = finalOptions.getCacheKey(url, options);\n return cacheRequest(key, () => requestor.get<T>(url, options));\n },\n\n // POST, PUT, DELETE, PATCH methods don't use cache\n post: requestor.post.bind(requestor),\n put: requestor.put.bind(requestor),\n delete: requestor.delete.bind(requestor),\n patch: requestor.patch.bind(requestor),\n };\n} ","import { Requestor, RequestOptions, Response } from '../../interfaces/request';\n\nexport interface ParallelOptions {\n maxConcurrent?: number;\n timeout?: number;\n}\n\nconst defaultParallelOptions: Required<ParallelOptions> = {\n maxConcurrent: 5,\n timeout: 30000,\n};\n\nclass RequestQueue {\n private queue: Array<() => void> = [];\n private running = 0;\n\n constructor(private maxConcurrent: number) {}\n\n async add<T>(task: () => Promise<T>): Promise<T> {\n if (this.running >= this.maxConcurrent) {\n await new Promise<void>((resolve) => {\n this.queue.push(resolve);\n });\n }\n\n this.running++;\n try {\n return await task();\n } finally {\n this.running--;\n if (this.queue.length > 0) {\n const next = this.queue.shift();\n next?.();\n }\n }\n }\n}\n\nexport function createParallelRequestor(\n requestor: Requestor,\n options?: ParallelOptions\n): Requestor {\n const finalOptions = { ...defaultParallelOptions, ...options };\n const queue = new RequestQueue(finalOptions.maxConcurrent);\n\n return {\n async get<T>(url: string, options?: RequestOptions) {\n return queue.add(() => requestor.get<T>(url, options));\n },\n\n async post<T>(url: string, data?: any, options?: RequestOptions) {\n return queue.add(() => requestor.post<T>(url, data, options));\n },\n\n async put<T>(url: string, data?: any, options?: RequestOptions) {\n return queue.add(() => requestor.put<T>(url, data, options));\n },\n\n async delete<T>(url: string, options?: RequestOptions) {\n return queue.add(() => requestor.delete<T>(url, options));\n },\n\n async patch<T>(url: string, data?: any, options?: RequestOptions) {\n return queue.add(() => requestor.patch<T>(url, data, options));\n },\n };\n} ","import { Requestor, RequestOptions, Response } from '../../interfaces/request';\nimport { HashService, DefaultHashService } from '../../interfaces/hash';\n\ninterface PendingRequest<T> {\n promise: Promise<Response<T>>;\n timestamp: number;\n}\n\nexport interface IdempotentOptions {\n // 请求合并的时间窗口,单位毫秒\n dedupeTime?: number;\n // 自定义请求标识生成函数\n getRequestId?: (method: string, url: string, data?: any, options?: RequestOptions) => string;\n // Hash service for generating request IDs\n hashService?: HashService;\n}\n\nconst defaultHashService = new DefaultHashService();\n\nconst defaultOptions: Required<IdempotentOptions> = {\n dedupeTime: 1000,\n getRequestId: (method: string, url: string, data?: any, options?: RequestOptions) => {\n return defaultHashService.generateRequestHash(method, url, data, options);\n },\n hashService: defaultHashService,\n};\n\nexport function createIdempotentRequestor(\n requestor: Requestor,\n options?: IdempotentOptions\n): Requestor {\n const finalOptions = { ...defaultOptions, ...options };\n const pendingRequests = new Map<string, PendingRequest<any>>();\n\n function cleanupOldRequests() {\n const now = Date.now();\n for (const [key, request] of pendingRequests.entries()) {\n if (now - request.timestamp > finalOptions.dedupeTime) {\n pendingRequests.delete(key);\n }\n }\n }\n\n async function dedupeRequest<T>(\n method: string,\n url: string,\n requestFn: () => Promise<Response<T>>,\n data?: any,\n options?: RequestOptions\n ): Promise<Response<T>> {\n const requestId = finalOptions.getRequestId(method, url, data, options);\n \n cleanupOldRequests();\n\n const existing = pendingRequests.get(requestId);\n if (existing) {\n return existing.promise;\n }\n\n const promise = requestFn();\n pendingRequests.set(requestId, {\n promise,\n timestamp: Date.now(),\n });\n\n try {\n return await promise;\n } finally {\n pendingRequests.delete(requestId);\n }\n }\n\n return {\n get: <T>(url: string, options?: RequestOptions) => {\n return dedupeRequest('GET', url, () => requestor.get<T>(url, options), null, options);\n },\n\n post: <T>(url: string, data?: any, options?: RequestOptions) => {\n return dedupeRequest('POST', url, () => requestor.post<T>(url, data, options), data, options);\n },\n\n put: <T>(url: string, data?: any, options?: RequestOptions) => {\n return dedupeRequest('PUT', url, () => requestor.put<T>(url, data, options), data, options);\n },\n\n delete: <T>(url: string, options?: RequestOptions) => {\n return dedupeRequest('DELETE', url, () => requestor.delete<T>(url, options), null, options);\n },\n\n patch: <T>(url: string, data?: any, options?: RequestOptions) => {\n return dedupeRequest('PATCH', url, () => requestor.patch<T>(url, data, options), data, options);\n },\n };\n} ","import { Requestor, RequestOptions, Response, RequestError } from '../../interfaces/request';\n\nexport interface TimeoutOptions {\n timeout?: number;\n timeoutErrorMessage?: string;\n}\n\nconst defaultOptions: Required<TimeoutOptions> = {\n timeout: 30000,\n timeoutErrorMessage: 'Request timeout',\n};\n\nexport function createTimeoutRequestor(\n requestor: Requestor,\n options?: TimeoutOptions\n): Requestor {\n const finalOptions = { ...defaultOptions, ...options };\n\n async function withTimeout<T>(\n request: () => Promise<Response<T>>,\n timeout: number = finalOptions.timeout\n ): Promise<Response<T>> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout);\n\n try {\n const response = await request();\n clearTimeout(timeoutId);\n return response;\n } catch (error) {\n clearTimeout(timeoutId);\n if (error instanceof DOMException && error.name === 'AbortError') {\n const timeoutError = new Error(finalOptions.timeoutErrorMessage) as RequestError;\n timeoutError.code = 'TIMEOUT';\n throw timeoutError;\n }\n throw error;\n }\n }\n\n return {\n get: <T>(url: string, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.get<T>(url, mergedOptions));\n },\n\n post: <T>(url: string, data?: any, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.post<T>(url, data, mergedOptions));\n },\n\n put: <T>(url: string, data?: any, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.put<T>(url, data, mergedOptions));\n },\n\n delete: <T>(url: string, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.delete<T>(url, mergedOptions));\n },\n\n patch: <T>(url: string, data?: any, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.patch<T>(url, data, mergedOptions));\n },\n };\n} ","import { Requestor, RequestOptions } from './interfaces/request';\nimport { InterceptorManager } from './interceptor';\nimport { createRetryRequestor, RetryOptions } from './features/retry';\nimport { CacheOptions, createCacheRequestor } from './features/cache';\nimport { createParallelRequestor, ParallelOptions } from './features/parallel';\nimport { createIdempotentRequestor, IdempotentOptions } from './features/idempotent';\nimport { createTimeoutRequestor, TimeoutOptions } from './features/timeout';\n\nexport interface RequestConfig {\n retry?: RetryOptions;\n cache?: CacheOptions;\n parallel?: ParallelOptions;\n idempotent?: IdempotentOptions;\n timeout?: TimeoutOptions;\n}\n\nexport class Request {\n private requestor: Requestor;\n public interceptors: InterceptorManager;\n\n constructor(baseRequestor: Requestor, config?: RequestConfig) {\n this.interceptors = new InterceptorManager();\n \n // 组合各种功能\n let requestor = baseRequestor;\n \n if (config?.timeout) {\n requestor = createTimeoutRequestor(requestor, config.timeout);\n }\n \n if (config?.retry) {\n requestor = createRetryRequestor(requestor, config.retry);\n }\n \n if (config?.cache) {\n requestor = createCacheRequestor(requestor, config.cache);\n }\n \n if (config?.parallel) {\n requestor = createParallelRequestor(requestor, config.parallel);\n }\n \n if (config?.idempotent) {\n requestor = createIdempotentRequestor(requestor, config.idempotent);\n }\n \n this.requestor = requestor;\n }\n\n async request<T>(method: string, url: string, data?: any, options?: RequestOptions): Promise<T> {\n const config = await this.interceptors.runRequestInterceptors({\n ...options,\n method,\n url,\n data,\n });\n\n try {\n // 使用类型断言和映射类型来解决索引签名问题\n type RequestMethod = keyof Requestor;\n const requestMethod = method.toLowerCase() as RequestMethod;\n const response = await this.requestor[requestMethod](url, data, config);\n return (await this.interceptors.runResponseInterceptors(response)).data as T;\n } catch (error) {\n throw error;\n }\n }\n\n get<T>(url: string, options?: RequestOptions): Promise<T> {\n return this.request('GET', url, undefined, options);\n }\n\n post<T>(url: string, data?: any, options?: RequestOptions): Promise<T> {\n return this.request('POST', url, data, options);\n }\n\n put<T>(url: string, data?: any, options?: RequestOptions): Promise<T> {\n return this.request('PUT', url, data, options);\n }\n\n delete<T>(url: string, options?: RequestOptions): Promise<T> {\n return this.request('DELETE', url, undefined, options);\n }\n\n patch<T>(url: string, data?: any, options?: RequestOptions): Promise<T> {\n return this.request('PATCH', url, data, options);\n }\n\n // 实现其他方法...\n} "]}
1
+ {"version":3,"sources":["../src/interfaces/request.ts","../src/interfaces/cache.ts","../src/interfaces/hash.ts","../src/interceptor.ts","../src/utils/error.ts","../src/features/retry/index.ts","../src/features/cache/index.ts","../src/features/parallel/index.ts","../src/features/idempotent/index.ts","../src/features/timeout/index.ts","../src/request.ts"],"names":["UreqError","message","options","NetworkError","TimeoutError","AbortError","HttpError","status","MemoryCacheStore","key","item","value","ttl","expires","DefaultHashService","input","hash","i","char","method","url","data","parts","InterceptorManager","interceptor","index","config","currentConfig","response","currentResponse","createRequestError","error","context","retryCount","isRetryableError","formatError","getErrorDetails","defaultRetryOptions","createRetryRequestor","requestor","finalOptions","retryRequest","request","retries","requestError","resolve","defaultCacheOptions","createCacheRequestor","cacheRequest","cached","defaultParallelOptions","RequestQueue","maxConcurrent","task","createParallelRequestor","queue","defaultHashService","defaultOptions","createIdempotentRequestor","pendingRequests","cleanupOldRequests","now","dedupeRequest","requestFn","requestId","existing","promise","createTimeoutRequestor","withTimeout","timeout","controller","timeoutId","timeoutError","signal","mergedOptions","createInterceptorRequestor","interceptors","wrapRequest","methodLower","Request","baseRequestor"],"mappings":"AAiDaA,IAAAA,CAAAA,CAAN,cAAwB,KAA8B,CAY3D,WAAA,CAAYC,CAAiBC,CAAAA,CAAAA,CAAiC,EAAC,CAAG,CAChE,KAAA,CAAMD,CAAO,CAAA,CACb,IAAK,CAAA,IAAA,CAAO,WACZ,CAAA,IAAA,CAAK,SAAY,CAAA,IAAA,CAAK,GAAI,EAAA,CAC1B,MAAO,CAAA,MAAA,CAAO,IAAMC,CAAAA,CAAO,EAC7B,CACF,CAEaC,CAAAA,CAAAA,CAAN,cAA2BH,CAAU,CAC1C,WAAYC,CAAAA,CAAAA,CAAiBC,CAAiC,CAAA,EAAI,CAAA,CAChE,KAAMD,CAAAA,CAAAA,CAAS,CAAE,GAAGC,CAAS,CAAA,cAAA,CAAgB,IAAK,CAAC,CACnD,CAAA,IAAA,CAAK,IAAO,CAAA,eACd,CACF,CAAA,CAEaE,CAAN,CAAA,cAA2BJ,CAAU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AAO,IAAK,CAAA,OAAA,CAAQ,KAAOkB,CAAAA,CAAAA,CAAKC,CAAMnB,CAAAA,CAAO,CAC/C,CAEA,MAAUkB,CAAAA,CAAAA,CAAalB,CAAsC,CAAA,CAC3D,OAAO,IAAA,CAAK,OAAQ,CAAA,QAAA,CAAUkB,CAAK,CAAA,MAAA,CAAWlB,CAAO,CACvD,CAEA,KAAA,CAASkB,CAAaC,CAAAA,CAAAA,CAAYnB,CAAsC,CAAA,CACtE,OAAO,IAAA,CAAK,OAAQ,CAAA,OAAA,CAASkB,CAAKC,CAAAA,CAAAA,CAAMnB,CAAO,CACjD,CAGF","file":"index.mjs","sourcesContent":["/**\n * 响应类型\n */\nexport type ResponseType = 'json' | 'text' | 'blob' | 'arraybuffer' | 'formData';\n\n/**\n * 响应转换器函数类型\n * @param response 原始响应对象(Fetch Response 或其他)\n * @returns 转换后的数据\n */\nexport type ResponseTransformer<T = any> = (response: any) => Promise<T>;\n\nexport interface RequestOptions {\n headers?: Record<string, string>;\n timeout?: number;\n signal?: AbortSignal;\n /**\n * 响应类型,用于指定如何解析响应体\n * @default 'json'\n */\n responseType?: ResponseType;\n /**\n * 自定义响应转换器,优先级高于 responseType\n * 当需要自定义响应解析逻辑时使用\n */\n responseTransformer?: ResponseTransformer;\n [key: string]: any;\n}\n\nexport interface Response<T = any> {\n data: T;\n status: number;\n statusText: string;\n headers: Record<string, string>;\n}\n\nexport interface RequestError extends Error {\n status?: number;\n code?: string;\n data?: any;\n url?: string;\n method?: string;\n timestamp?: number;\n retryCount?: number;\n isTimeout?: boolean;\n isNetworkError?: boolean;\n isAborted?: boolean;\n}\n\nexport class UreqError extends Error implements RequestError {\n status?: number;\n code?: string;\n data?: any;\n url?: string;\n method?: string;\n timestamp: number;\n retryCount?: number;\n isTimeout?: boolean;\n isNetworkError?: boolean;\n isAborted?: boolean;\n\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message);\n this.name = 'UreqError';\n this.timestamp = Date.now();\n Object.assign(this, options);\n }\n}\n\nexport class NetworkError extends UreqError {\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message, { ...options, isNetworkError: true });\n this.name = 'NetworkError';\n }\n}\n\nexport class TimeoutError extends UreqError {\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message, { ...options, isTimeout: true });\n this.name = 'TimeoutError';\n }\n}\n\nexport class AbortError extends UreqError {\n constructor(message: string, options: Partial<RequestError> = {}) {\n super(message, { ...options, isAborted: true });\n this.name = 'AbortError';\n }\n}\n\nexport class HttpError extends UreqError {\n constructor(message: string, status: number, options: Partial<RequestError> = {}) {\n super(message, { ...options, status });\n this.name = 'HttpError';\n }\n}\n\nexport interface Requestor {\n get<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;\n post<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;\n put<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;\n delete<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;\n patch<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;\n} ","/**\n * Cache store interface for storing and retrieving cached data\n */\nexport interface CacheStore {\n /**\n * Get a value from the cache\n */\n get<T>(key: string): Promise<T | undefined> | T | undefined;\n \n /**\n * Set a value in the cache with optional TTL\n */\n set<T>(key: string, value: T, ttl?: number): Promise<void> | void;\n \n /**\n * Delete a value from the cache\n */\n delete(key: string): Promise<void> | void;\n \n /**\n * Clear all values from the cache\n */\n clear(): Promise<void> | void;\n \n /**\n * Check if a key exists in the cache\n */\n has(key: string): Promise<boolean> | boolean;\n}\n\n/**\n * Simple in-memory cache store implementation\n */\nexport class MemoryCacheStore implements CacheStore {\n private cache = new Map<string, { value: any; expires?: number }>();\n\n get<T>(key: string): T | undefined {\n const item = this.cache.get(key);\n if (!item) return undefined;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return undefined;\n }\n \n return item.value;\n }\n\n set<T>(key: string, value: T, ttl?: number): void {\n const expires = ttl ? Date.now() + ttl : undefined;\n this.cache.set(key, { value, expires });\n }\n\n delete(key: string): void {\n this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n\n has(key: string): boolean {\n const item = this.cache.get(key);\n if (!item) return false;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return false;\n }\n \n return true;\n }\n}\n","/**\n * Hash service interface for generating request identifiers\n */\nexport interface HashService {\n /**\n * Generate a hash from a string input\n */\n generateHash(input: string): string;\n \n /**\n * Generate a hash for a request based on method, URL, data, and options\n */\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string;\n}\n\n/**\n * Default hash service implementation using simple hash algorithm\n */\nexport class DefaultHashService implements HashService {\n generateHash(input: string): string {\n let hash = 0;\n for (let i = 0; i < input.length; i++) {\n const char = input.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash = hash & hash; // Convert to 32-bit integer\n }\n return hash.toString(36);\n }\n\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string {\n const parts = [\n method.toUpperCase(),\n url,\n data ? JSON.stringify(data) : '',\n options ? JSON.stringify(options) : ''\n ];\n return this.generateHash(parts.join('|'));\n }\n}\n","import { RequestError, RequestOptions, Response } from \"./interfaces/request\";\n\nexport interface RequestInterceptor {\n onRequest?(config: RequestOptions): Promise<RequestOptions> | RequestOptions;\n onRequestError?(error: any): Promise<any>;\n}\n\nexport interface ResponseInterceptor {\n onResponse?<T>(response: Response<T>): Promise<Response<T>> | Response<T>;\n onResponseError?(error: RequestError): Promise<any>;\n}\n\nexport class InterceptorManager {\n private requestInterceptors: RequestInterceptor[] = [];\n private responseInterceptors: ResponseInterceptor[] = [];\n\n addRequestInterceptor(interceptor: RequestInterceptor) {\n this.requestInterceptors.push(interceptor);\n return () => {\n const index = this.requestInterceptors.indexOf(interceptor);\n if (index !== -1) {\n this.requestInterceptors.splice(index, 1);\n }\n };\n }\n\n addResponseInterceptor(interceptor: ResponseInterceptor) {\n this.responseInterceptors.push(interceptor);\n return () => {\n const index = this.responseInterceptors.indexOf(interceptor);\n if (index !== -1) {\n this.responseInterceptors.splice(index, 1);\n }\n };\n }\n\n async runRequestInterceptors(config: RequestOptions): Promise<RequestOptions> {\n let currentConfig = { ...config };\n for (const interceptor of this.requestInterceptors) {\n if (interceptor.onRequest) {\n currentConfig = await interceptor.onRequest(currentConfig);\n }\n }\n return currentConfig;\n }\n\n async runResponseInterceptors<T>(response: Response<T>): Promise<Response<T>> {\n let currentResponse = { ...response };\n for (const interceptor of this.responseInterceptors) {\n if (interceptor.onResponse) {\n currentResponse = await interceptor.onResponse(currentResponse);\n }\n }\n return currentResponse;\n }\n} ","import { \n RequestError, \n UreqError, \n NetworkError, \n TimeoutError, \n AbortError, \n HttpError \n} from '../interfaces/request.js';\n\nexport interface ErrorContext {\n url?: string;\n method?: string;\n retryCount?: number;\n requestId?: string;\n}\n\n/**\n * Creates appropriate error types based on the error context\n */\nexport function createRequestError(\n error: any, \n context: ErrorContext = {}\n): RequestError {\n const { url, method, retryCount } = context;\n \n // Handle AbortController signals\n if (error.name === 'AbortError' || error.code === 'ABORT_ERR') {\n return new AbortError('Request was aborted', {\n url,\n method,\n retryCount,\n code: 'ABORT_ERR'\n });\n }\n \n // Handle timeout errors\n if (error.name === 'TimeoutError' || error.message?.includes('timeout')) {\n return new TimeoutError('Request timed out', {\n url,\n method,\n retryCount,\n code: 'TIMEOUT'\n });\n }\n \n // Handle network errors\n if (error.name === 'TypeError' && error.message?.includes('fetch')) {\n return new NetworkError('Network request failed', {\n url,\n method,\n retryCount,\n code: 'NETWORK_ERROR'\n });\n }\n \n // Handle HTTP errors (Response objects)\n if (error instanceof globalThis.Response) {\n return new HttpError(\n `HTTP ${error.status}: ${error.statusText}`,\n error.status,\n {\n url,\n method,\n retryCount,\n code: `HTTP_${error.status}`,\n data: error\n }\n );\n }\n \n // Handle Axios errors\n if (error.response) {\n return new HttpError(\n `HTTP ${error.response.status}: ${error.response.statusText || 'Unknown Error'}`,\n error.response.status,\n {\n url: url || error.config?.url,\n method: method || error.config?.method?.toUpperCase(),\n retryCount,\n code: `HTTP_${error.response.status}`,\n data: error.response.data\n }\n );\n }\n \n // Handle Axios network errors\n if (error.request && !error.response) {\n return new NetworkError('Network request failed', {\n url: url || error.config?.url,\n method: method || error.config?.method?.toUpperCase(),\n retryCount,\n code: 'NETWORK_ERROR'\n });\n }\n \n // Handle already processed UreqError\n if (error instanceof UreqError) {\n // Update context if provided\n if (url && !error.url) error.url = url;\n if (method && !error.method) error.method = method;\n if (retryCount !== undefined) error.retryCount = retryCount;\n return error;\n }\n \n // Generic error fallback\n return new UreqError(error.message || 'Unknown error occurred', {\n url,\n method,\n retryCount,\n code: 'UNKNOWN_ERROR'\n });\n}\n\n/**\n * Determines if an error is retryable\n */\nexport function isRetryableError(error: RequestError): boolean {\n // Don't retry client errors (4xx) except for specific cases\n if (error.status && error.status >= 400 && error.status < 500) {\n // Retry on 408 (Request Timeout), 429 (Too Many Requests)\n return error.status === 408 || error.status === 429;\n }\n \n // Retry on server errors (5xx)\n if (error.status && error.status >= 500) {\n return true;\n }\n \n // Retry on network errors and timeouts\n if (error.isNetworkError || error.isTimeout) {\n return true;\n }\n \n // Don't retry aborted requests\n if (error.isAborted) {\n return false;\n }\n \n // Default to retryable for unknown errors\n return true;\n}\n\n/**\n * Formats error for logging\n */\nexport function formatError(error: RequestError): string {\n const parts = [\n `[${error.name}]`,\n error.message\n ];\n \n if (error.method && error.url) {\n parts.push(`(${error.method} ${error.url})`);\n }\n \n if (error.status) {\n parts.push(`Status: ${error.status}`);\n }\n \n if (error.retryCount !== undefined) {\n parts.push(`Retry: ${error.retryCount}`);\n }\n \n return parts.join(' ');\n}\n\n/**\n * Extracts error details for debugging\n */\nexport function getErrorDetails(error: RequestError): Record<string, any> {\n return {\n name: error.name,\n message: error.message,\n status: error.status,\n code: error.code,\n url: error.url,\n method: error.method,\n timestamp: error.timestamp,\n retryCount: error.retryCount,\n isTimeout: error.isTimeout,\n isNetworkError: error.isNetworkError,\n isAborted: error.isAborted,\n stack: error.stack\n };\n}\n","import { Requestor, RequestOptions, Response, RequestError } from '../../interfaces/request';\nimport { isRetryableError } from '../../utils/error';\n\nexport interface RetryOptions {\n maxRetries?: number;\n retryDelay?: number;\n shouldRetry?: (error: RequestError) => boolean | Promise<boolean>;\n}\n\nconst defaultRetryOptions: Required<RetryOptions> = {\n maxRetries: 3,\n retryDelay: 1000,\n shouldRetry: (error: RequestError) => isRetryableError(error),\n};\n\nexport function createRetryRequestor(\n requestor: Requestor,\n options?: RetryOptions\n): Requestor {\n const finalOptions = { ...defaultRetryOptions, ...options };\n\n async function retryRequest<T>(\n request: () => Promise<Response<T>>,\n retries = 0\n ): Promise<Response<T>> {\n try {\n return await request();\n } catch (error) {\n const requestError = error as RequestError;\n // Update retry count in error\n requestError.retryCount = retries;\n\n const shouldRetry = await finalOptions.shouldRetry(requestError);\n\n if (!shouldRetry || retries >= finalOptions.maxRetries) {\n throw requestError;\n }\n\n await new Promise(resolve => setTimeout(resolve, finalOptions.retryDelay));\n return retryRequest(request, retries + 1);\n }\n }\n\n return {\n async get<T>(url: string, options?: RequestOptions) {\n return retryRequest(() => requestor.get<T>(url, options));\n },\n\n async post<T>(url: string, data?: any, options?: RequestOptions) {\n return retryRequest(() => requestor.post<T>(url, data, options));\n },\n\n async put<T>(url: string, data?: any, options?: RequestOptions) {\n return retryRequest(() => requestor.put<T>(url, data, options));\n },\n\n async delete<T>(url: string, options?: RequestOptions) {\n return retryRequest(() => requestor.delete<T>(url, options));\n },\n\n async patch<T>(url: string, data?: any, options?: RequestOptions) {\n return retryRequest(() => requestor.patch<T>(url, data, options));\n },\n };\n} ","import { Requestor, RequestOptions, Response } from '../../interfaces/request';\nimport { CacheStore, MemoryCacheStore } from '../../interfaces/cache';\n\nexport interface CacheOptions {\n ttl?: number;\n store?: CacheStore;\n getCacheKey?: (url: string, options?: RequestOptions) => string;\n}\n\nconst defaultCacheOptions: Required<CacheOptions> = {\n ttl: 5 * 60 * 1000, // 5 minutes\n store: new MemoryCacheStore(),\n getCacheKey: (url: string, options?: RequestOptions) => {\n return `${url}${options ? JSON.stringify(options) : ''}`;\n },\n};\n\nexport function createCacheRequestor(\n requestor: Requestor,\n options?: CacheOptions\n): Requestor {\n const finalOptions = { ...defaultCacheOptions, ...options };\n\n async function cacheRequest<T>(\n key: string,\n request: () => Promise<Response<T>>\n ): Promise<Response<T>> {\n const cached = await finalOptions.store.get<Response<T>>(key);\n if (cached) {\n return cached;\n }\n\n const response = await request();\n await finalOptions.store.set(key, response, finalOptions.ttl);\n return response;\n }\n\n return {\n async get<T>(url: string, options?: RequestOptions) {\n const key = finalOptions.getCacheKey(url, options);\n return cacheRequest(key, () => requestor.get<T>(url, options));\n },\n\n // POST, PUT, DELETE, PATCH methods don't use cache\n post: requestor.post.bind(requestor),\n put: requestor.put.bind(requestor),\n delete: requestor.delete.bind(requestor),\n patch: requestor.patch.bind(requestor),\n };\n} ","import { Requestor, RequestOptions, Response } from '../../interfaces/request';\n\nexport interface ParallelOptions {\n maxConcurrent?: number;\n timeout?: number;\n}\n\nconst defaultParallelOptions: Required<ParallelOptions> = {\n maxConcurrent: 5,\n timeout: 30000,\n};\n\nclass RequestQueue {\n private queue: Array<() => void> = [];\n private running = 0;\n\n constructor(private maxConcurrent: number) {}\n\n async add<T>(task: () => Promise<T>): Promise<T> {\n if (this.running >= this.maxConcurrent) {\n await new Promise<void>((resolve) => {\n this.queue.push(resolve);\n });\n }\n\n this.running++;\n try {\n return await task();\n } finally {\n this.running--;\n if (this.queue.length > 0) {\n const next = this.queue.shift();\n next?.();\n }\n }\n }\n}\n\nexport function createParallelRequestor(\n requestor: Requestor,\n options?: ParallelOptions\n): Requestor {\n const finalOptions = { ...defaultParallelOptions, ...options };\n const queue = new RequestQueue(finalOptions.maxConcurrent);\n\n return {\n async get<T>(url: string, options?: RequestOptions) {\n return queue.add(() => requestor.get<T>(url, options));\n },\n\n async post<T>(url: string, data?: any, options?: RequestOptions) {\n return queue.add(() => requestor.post<T>(url, data, options));\n },\n\n async put<T>(url: string, data?: any, options?: RequestOptions) {\n return queue.add(() => requestor.put<T>(url, data, options));\n },\n\n async delete<T>(url: string, options?: RequestOptions) {\n return queue.add(() => requestor.delete<T>(url, options));\n },\n\n async patch<T>(url: string, data?: any, options?: RequestOptions) {\n return queue.add(() => requestor.patch<T>(url, data, options));\n },\n };\n} ","import { Requestor, RequestOptions, Response } from '../../interfaces/request';\nimport { HashService, DefaultHashService } from '../../interfaces/hash';\n\ninterface PendingRequest<T> {\n promise: Promise<Response<T>>;\n timestamp: number;\n}\n\nexport interface IdempotentOptions {\n // 请求合并的时间窗口,单位毫秒\n dedupeTime?: number;\n // 自定义请求标识生成函数\n getRequestId?: (method: string, url: string, data?: any, options?: RequestOptions) => string;\n // Hash service for generating request IDs\n hashService?: HashService;\n}\n\nconst defaultHashService = new DefaultHashService();\n\nconst defaultOptions: Required<IdempotentOptions> = {\n dedupeTime: 1000,\n getRequestId: (method: string, url: string, data?: any, options?: RequestOptions) => {\n return defaultHashService.generateRequestHash(method, url, data, options);\n },\n hashService: defaultHashService,\n};\n\nexport function createIdempotentRequestor(\n requestor: Requestor,\n options?: IdempotentOptions\n): Requestor {\n const finalOptions = { ...defaultOptions, ...options };\n const pendingRequests = new Map<string, PendingRequest<any>>();\n\n function cleanupOldRequests() {\n const now = Date.now();\n for (const [key, request] of pendingRequests.entries()) {\n if (now - request.timestamp > finalOptions.dedupeTime) {\n pendingRequests.delete(key);\n }\n }\n }\n\n async function dedupeRequest<T>(\n method: string,\n url: string,\n requestFn: () => Promise<Response<T>>,\n data?: any,\n options?: RequestOptions\n ): Promise<Response<T>> {\n const requestId = finalOptions.getRequestId(method, url, data, options);\n \n cleanupOldRequests();\n\n const existing = pendingRequests.get(requestId);\n if (existing) {\n return existing.promise;\n }\n\n const promise = requestFn();\n pendingRequests.set(requestId, {\n promise,\n timestamp: Date.now(),\n });\n\n try {\n return await promise;\n } finally {\n pendingRequests.delete(requestId);\n }\n }\n\n return {\n get: <T>(url: string, options?: RequestOptions) => {\n return dedupeRequest('GET', url, () => requestor.get<T>(url, options), null, options);\n },\n\n post: <T>(url: string, data?: any, options?: RequestOptions) => {\n return dedupeRequest('POST', url, () => requestor.post<T>(url, data, options), data, options);\n },\n\n put: <T>(url: string, data?: any, options?: RequestOptions) => {\n return dedupeRequest('PUT', url, () => requestor.put<T>(url, data, options), data, options);\n },\n\n delete: <T>(url: string, options?: RequestOptions) => {\n return dedupeRequest('DELETE', url, () => requestor.delete<T>(url, options), null, options);\n },\n\n patch: <T>(url: string, data?: any, options?: RequestOptions) => {\n return dedupeRequest('PATCH', url, () => requestor.patch<T>(url, data, options), data, options);\n },\n };\n} ","import { Requestor, RequestOptions, Response, RequestError } from '../../interfaces/request';\n\nexport interface TimeoutOptions {\n timeout?: number;\n timeoutErrorMessage?: string;\n}\n\nconst defaultOptions: Required<TimeoutOptions> = {\n timeout: 30000,\n timeoutErrorMessage: 'Request timeout',\n};\n\nexport function createTimeoutRequestor(\n requestor: Requestor,\n options?: TimeoutOptions\n): Requestor {\n const finalOptions = { ...defaultOptions, ...options };\n\n async function withTimeout<T>(\n request: () => Promise<Response<T>>,\n timeout: number = finalOptions.timeout\n ): Promise<Response<T>> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout);\n\n try {\n const response = await request();\n clearTimeout(timeoutId);\n return response;\n } catch (error) {\n clearTimeout(timeoutId);\n if (error instanceof DOMException && error.name === 'AbortError') {\n const timeoutError = new Error(finalOptions.timeoutErrorMessage) as RequestError;\n timeoutError.code = 'TIMEOUT';\n throw timeoutError;\n }\n throw error;\n }\n }\n\n return {\n get: <T>(url: string, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.get<T>(url, mergedOptions));\n },\n\n post: <T>(url: string, data?: any, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.post<T>(url, data, mergedOptions));\n },\n\n put: <T>(url: string, data?: any, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.put<T>(url, data, mergedOptions));\n },\n\n delete: <T>(url: string, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.delete<T>(url, mergedOptions));\n },\n\n patch: <T>(url: string, data?: any, options?: RequestOptions) => {\n const signal = options?.signal;\n const mergedOptions = {\n ...options,\n signal: signal || new AbortController().signal,\n };\n return withTimeout(() => requestor.patch<T>(url, data, mergedOptions));\n },\n };\n} ","import { Requestor, RequestOptions, Response } from './interfaces/request';\nimport { InterceptorManager } from './interceptor';\nimport { createRetryRequestor, RetryOptions } from './features/retry';\nimport { CacheOptions, createCacheRequestor } from './features/cache';\nimport { createParallelRequestor, ParallelOptions } from './features/parallel';\nimport { createIdempotentRequestor, IdempotentOptions } from './features/idempotent';\nimport { createTimeoutRequestor, TimeoutOptions } from './features/timeout';\n\nexport interface RequestConfig {\n retry?: RetryOptions;\n cache?: CacheOptions;\n parallel?: ParallelOptions;\n idempotent?: IdempotentOptions;\n timeout?: TimeoutOptions;\n}\n\n/**\n * 创建拦截器包装的 Requestor\n * 这样每次实际发起请求时都会经过拦截器\n */\nfunction createInterceptorRequestor(\n requestor: Requestor,\n interceptors: InterceptorManager\n): Requestor {\n const wrapRequest = async <T>(\n method: string,\n url: string,\n data: any,\n options?: RequestOptions\n ): Promise<Response<T>> => {\n // 运行请求拦截器\n const config = await interceptors.runRequestInterceptors({\n ...options,\n method,\n url,\n data,\n });\n\n // 发起实际请求\n const methodLower = method.toLowerCase();\n let response: Response<T>;\n\n if (methodLower === 'get' || methodLower === 'delete') {\n response = await (requestor as any)[methodLower](config.url, config);\n } else {\n response = await (requestor as any)[methodLower](config.url, config.data, config);\n }\n\n // 运行响应拦截器\n return interceptors.runResponseInterceptors(response);\n };\n\n return {\n async get<T>(url: string, options?: RequestOptions) {\n return wrapRequest<T>('GET', url, undefined, options);\n },\n async post<T>(url: string, data?: any, options?: RequestOptions) {\n return wrapRequest<T>('POST', url, data, options);\n },\n async put<T>(url: string, data?: any, options?: RequestOptions) {\n return wrapRequest<T>('PUT', url, data, options);\n },\n async delete<T>(url: string, options?: RequestOptions) {\n return wrapRequest<T>('DELETE', url, undefined, options);\n },\n async patch<T>(url: string, data?: any, options?: RequestOptions) {\n return wrapRequest<T>('PATCH', url, data, options);\n },\n };\n}\n\nexport class Request {\n private requestor: Requestor;\n public interceptors: InterceptorManager;\n\n constructor(baseRequestor: Requestor, config?: RequestConfig) {\n this.interceptors = new InterceptorManager();\n\n // 组合各种功能\n // 拦截器放在最内层,这样每次请求(包括重试)都会触发拦截器\n let requestor: Requestor = createInterceptorRequestor(baseRequestor, this.interceptors);\n\n if (config?.timeout) {\n requestor = createTimeoutRequestor(requestor, config.timeout);\n }\n\n if (config?.retry) {\n requestor = createRetryRequestor(requestor, config.retry);\n }\n\n if (config?.cache) {\n requestor = createCacheRequestor(requestor, config.cache);\n }\n\n if (config?.parallel) {\n requestor = createParallelRequestor(requestor, config.parallel);\n }\n\n if (config?.idempotent) {\n // 幂等\n requestor = createIdempotentRequestor(requestor, config.idempotent);\n }\n\n this.requestor = requestor;\n }\n\n async request<T>(method: string, url: string, data?: any, options?: RequestOptions): Promise<T> {\n // 拦截器已经在 createInterceptorRequestor 中处理\n // 直接调用 requestor,拦截器会在每次请求(包括重试)时自动触发\n const methodLower = method.toLowerCase();\n let response;\n\n if (methodLower === 'get' || methodLower === 'delete') {\n response = await (this.requestor as any)[methodLower](url, options);\n } else {\n response = await (this.requestor as any)[methodLower](url, data, options);\n }\n\n return response.data as T;\n }\n\n get<T>(url: string, options?: RequestOptions): Promise<T> {\n return this.request('GET', url, undefined, options);\n }\n\n post<T>(url: string, data?: any, options?: RequestOptions): Promise<T> {\n return this.request('POST', url, data, options);\n }\n\n put<T>(url: string, data?: any, options?: RequestOptions): Promise<T> {\n return this.request('PUT', url, data, options);\n }\n\n delete<T>(url: string, options?: RequestOptions): Promise<T> {\n return this.request('DELETE', url, undefined, options);\n }\n\n patch<T>(url: string, data?: any, options?: RequestOptions): Promise<T> {\n return this.request('PATCH', url, data, options);\n }\n\n // 实现其他方法...\n} "]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ureq/core",
3
- "version": "0.0.3-alpha.0",
3
+ "version": "0.0.4",
4
4
  "description": "Universal request library core",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -20,7 +20,7 @@
20
20
  "access": "public"
21
21
  },
22
22
  "dependencies": {
23
- "@ureq/business": "0.0.3-alpha.0"
23
+ "@ureq/business": "0.0.4"
24
24
  },
25
25
  "devDependencies": {
26
26
  "tsup": "^8.3.6",
@@ -29,6 +29,6 @@
29
29
  "scripts": {
30
30
  "build": "tsup --config tsup.config.ts",
31
31
  "dev": "tsup --config tsup.config.ts --watch",
32
- "test": "vitest"
32
+ "test": "vitest --run"
33
33
  }
34
34
  }