@ureq/core 0.0.1 → 0.0.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,209 @@
1
+ interface RequestOptions {
2
+ headers?: Record<string, string>;
3
+ timeout?: number;
4
+ signal?: AbortSignal;
5
+ responseType?: 'arraybuffer' | 'json' | 'text' | 'blob';
6
+ [key: string]: any;
7
+ }
8
+ interface Response<T = any> {
9
+ data: T;
10
+ status: number;
11
+ statusText: string;
12
+ headers: Record<string, string>;
13
+ }
14
+ interface RequestError extends Error {
15
+ status?: number;
16
+ code?: string;
17
+ data?: any;
18
+ url?: string;
19
+ method?: string;
20
+ timestamp?: number;
21
+ retryCount?: number;
22
+ isTimeout?: boolean;
23
+ isNetworkError?: boolean;
24
+ isAborted?: boolean;
25
+ }
26
+ declare class UreqError extends Error implements RequestError {
27
+ status?: number;
28
+ code?: string;
29
+ data?: any;
30
+ url?: string;
31
+ method?: string;
32
+ timestamp: number;
33
+ retryCount?: number;
34
+ isTimeout?: boolean;
35
+ isNetworkError?: boolean;
36
+ isAborted?: boolean;
37
+ constructor(message: string, options?: Partial<RequestError>);
38
+ }
39
+ declare class NetworkError extends UreqError {
40
+ constructor(message: string, options?: Partial<RequestError>);
41
+ }
42
+ declare class TimeoutError extends UreqError {
43
+ constructor(message: string, options?: Partial<RequestError>);
44
+ }
45
+ declare class AbortError extends UreqError {
46
+ constructor(message: string, options?: Partial<RequestError>);
47
+ }
48
+ declare class HttpError extends UreqError {
49
+ constructor(message: string, status: number, options?: Partial<RequestError>);
50
+ }
51
+ interface Requestor {
52
+ get<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;
53
+ post<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;
54
+ put<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;
55
+ delete<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;
56
+ patch<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;
57
+ }
58
+
59
+ /**
60
+ * Cache store interface for storing and retrieving cached data
61
+ */
62
+ interface CacheStore {
63
+ /**
64
+ * Get a value from the cache
65
+ */
66
+ get<T>(key: string): Promise<T | undefined> | T | undefined;
67
+ /**
68
+ * Set a value in the cache with optional TTL
69
+ */
70
+ set<T>(key: string, value: T, ttl?: number): Promise<void> | void;
71
+ /**
72
+ * Delete a value from the cache
73
+ */
74
+ delete(key: string): Promise<void> | void;
75
+ /**
76
+ * Clear all values from the cache
77
+ */
78
+ clear(): Promise<void> | void;
79
+ /**
80
+ * Check if a key exists in the cache
81
+ */
82
+ has(key: string): Promise<boolean> | boolean;
83
+ }
84
+ /**
85
+ * Simple in-memory cache store implementation
86
+ */
87
+ declare class MemoryCacheStore implements CacheStore {
88
+ private cache;
89
+ get<T>(key: string): T | undefined;
90
+ set<T>(key: string, value: T, ttl?: number): void;
91
+ delete(key: string): void;
92
+ clear(): void;
93
+ has(key: string): boolean;
94
+ }
95
+
96
+ /**
97
+ * Hash service interface for generating request identifiers
98
+ */
99
+ interface HashService {
100
+ /**
101
+ * Generate a hash from a string input
102
+ */
103
+ generateHash(input: string): string;
104
+ /**
105
+ * Generate a hash for a request based on method, URL, data, and options
106
+ */
107
+ generateRequestHash(method: string, url: string, data?: any, options?: Record<string, any>): string;
108
+ }
109
+ /**
110
+ * Default hash service implementation using simple hash algorithm
111
+ */
112
+ declare class DefaultHashService implements HashService {
113
+ generateHash(input: string): string;
114
+ generateRequestHash(method: string, url: string, data?: any, options?: Record<string, any>): string;
115
+ }
116
+
117
+ interface RequestInterceptor {
118
+ onRequest?(config: RequestOptions): Promise<RequestOptions> | RequestOptions;
119
+ onRequestError?(error: any): Promise<any>;
120
+ }
121
+ interface ResponseInterceptor {
122
+ onResponse?<T>(response: Response<T>): Promise<Response<T>> | Response<T>;
123
+ onResponseError?(error: RequestError): Promise<any>;
124
+ }
125
+ declare class InterceptorManager {
126
+ private requestInterceptors;
127
+ private responseInterceptors;
128
+ addRequestInterceptor(interceptor: RequestInterceptor): () => void;
129
+ addResponseInterceptor(interceptor: ResponseInterceptor): () => void;
130
+ runRequestInterceptors(config: RequestOptions): Promise<RequestOptions>;
131
+ runResponseInterceptors<T>(response: Response<T>): Promise<Response<T>>;
132
+ }
133
+
134
+ interface RetryOptions {
135
+ maxRetries?: number;
136
+ retryDelay?: number;
137
+ shouldRetry?: (error: RequestError) => boolean | Promise<boolean>;
138
+ }
139
+ declare function createRetryRequestor(requestor: Requestor, options?: RetryOptions): Requestor;
140
+
141
+ interface CacheOptions {
142
+ ttl?: number;
143
+ store?: CacheStore;
144
+ getCacheKey?: (url: string, options?: RequestOptions) => string;
145
+ }
146
+ declare function createCacheRequestor(requestor: Requestor, options?: CacheOptions): Requestor;
147
+
148
+ interface ParallelOptions {
149
+ maxConcurrent?: number;
150
+ timeout?: number;
151
+ }
152
+ declare function createParallelRequestor(requestor: Requestor, options?: ParallelOptions): Requestor;
153
+
154
+ interface IdempotentOptions {
155
+ dedupeTime?: number;
156
+ getRequestId?: (method: string, url: string, data?: any, options?: RequestOptions) => string;
157
+ hashService?: HashService;
158
+ }
159
+ declare function createIdempotentRequestor(requestor: Requestor, options?: IdempotentOptions): Requestor;
160
+
161
+ interface TimeoutOptions {
162
+ timeout?: number;
163
+ timeoutErrorMessage?: string;
164
+ }
165
+ declare function createTimeoutRequestor(requestor: Requestor, options?: TimeoutOptions): Requestor;
166
+
167
+ interface RequestConfig {
168
+ retry?: RetryOptions;
169
+ cache?: CacheOptions;
170
+ parallel?: ParallelOptions;
171
+ idempotent?: IdempotentOptions;
172
+ timeout?: TimeoutOptions;
173
+ }
174
+ declare class Request {
175
+ private requestor;
176
+ interceptors: InterceptorManager;
177
+ constructor(baseRequestor: Requestor, config?: RequestConfig);
178
+ request<T>(method: string, url: string, data?: any, options?: RequestOptions): Promise<T>;
179
+ get<T>(url: string, options?: RequestOptions): Promise<T>;
180
+ post<T>(url: string, data?: any, options?: RequestOptions): Promise<T>;
181
+ put<T>(url: string, data?: any, options?: RequestOptions): Promise<T>;
182
+ delete<T>(url: string, options?: RequestOptions): Promise<T>;
183
+ patch<T>(url: string, data?: any, options?: RequestOptions): Promise<T>;
184
+ }
185
+
186
+ interface ErrorContext {
187
+ url?: string;
188
+ method?: string;
189
+ retryCount?: number;
190
+ requestId?: string;
191
+ }
192
+ /**
193
+ * Creates appropriate error types based on the error context
194
+ */
195
+ declare function createRequestError(error: any, context?: ErrorContext): RequestError;
196
+ /**
197
+ * Determines if an error is retryable
198
+ */
199
+ declare function isRetryableError(error: RequestError): boolean;
200
+ /**
201
+ * Formats error for logging
202
+ */
203
+ declare function formatError(error: RequestError): string;
204
+ /**
205
+ * Extracts error details for debugging
206
+ */
207
+ declare function getErrorDetails(error: RequestError): Record<string, any>;
208
+
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 };
@@ -0,0 +1,209 @@
1
+ interface RequestOptions {
2
+ headers?: Record<string, string>;
3
+ timeout?: number;
4
+ signal?: AbortSignal;
5
+ responseType?: 'arraybuffer' | 'json' | 'text' | 'blob';
6
+ [key: string]: any;
7
+ }
8
+ interface Response<T = any> {
9
+ data: T;
10
+ status: number;
11
+ statusText: string;
12
+ headers: Record<string, string>;
13
+ }
14
+ interface RequestError extends Error {
15
+ status?: number;
16
+ code?: string;
17
+ data?: any;
18
+ url?: string;
19
+ method?: string;
20
+ timestamp?: number;
21
+ retryCount?: number;
22
+ isTimeout?: boolean;
23
+ isNetworkError?: boolean;
24
+ isAborted?: boolean;
25
+ }
26
+ declare class UreqError extends Error implements RequestError {
27
+ status?: number;
28
+ code?: string;
29
+ data?: any;
30
+ url?: string;
31
+ method?: string;
32
+ timestamp: number;
33
+ retryCount?: number;
34
+ isTimeout?: boolean;
35
+ isNetworkError?: boolean;
36
+ isAborted?: boolean;
37
+ constructor(message: string, options?: Partial<RequestError>);
38
+ }
39
+ declare class NetworkError extends UreqError {
40
+ constructor(message: string, options?: Partial<RequestError>);
41
+ }
42
+ declare class TimeoutError extends UreqError {
43
+ constructor(message: string, options?: Partial<RequestError>);
44
+ }
45
+ declare class AbortError extends UreqError {
46
+ constructor(message: string, options?: Partial<RequestError>);
47
+ }
48
+ declare class HttpError extends UreqError {
49
+ constructor(message: string, status: number, options?: Partial<RequestError>);
50
+ }
51
+ interface Requestor {
52
+ get<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;
53
+ post<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;
54
+ put<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;
55
+ delete<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;
56
+ patch<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;
57
+ }
58
+
59
+ /**
60
+ * Cache store interface for storing and retrieving cached data
61
+ */
62
+ interface CacheStore {
63
+ /**
64
+ * Get a value from the cache
65
+ */
66
+ get<T>(key: string): Promise<T | undefined> | T | undefined;
67
+ /**
68
+ * Set a value in the cache with optional TTL
69
+ */
70
+ set<T>(key: string, value: T, ttl?: number): Promise<void> | void;
71
+ /**
72
+ * Delete a value from the cache
73
+ */
74
+ delete(key: string): Promise<void> | void;
75
+ /**
76
+ * Clear all values from the cache
77
+ */
78
+ clear(): Promise<void> | void;
79
+ /**
80
+ * Check if a key exists in the cache
81
+ */
82
+ has(key: string): Promise<boolean> | boolean;
83
+ }
84
+ /**
85
+ * Simple in-memory cache store implementation
86
+ */
87
+ declare class MemoryCacheStore implements CacheStore {
88
+ private cache;
89
+ get<T>(key: string): T | undefined;
90
+ set<T>(key: string, value: T, ttl?: number): void;
91
+ delete(key: string): void;
92
+ clear(): void;
93
+ has(key: string): boolean;
94
+ }
95
+
96
+ /**
97
+ * Hash service interface for generating request identifiers
98
+ */
99
+ interface HashService {
100
+ /**
101
+ * Generate a hash from a string input
102
+ */
103
+ generateHash(input: string): string;
104
+ /**
105
+ * Generate a hash for a request based on method, URL, data, and options
106
+ */
107
+ generateRequestHash(method: string, url: string, data?: any, options?: Record<string, any>): string;
108
+ }
109
+ /**
110
+ * Default hash service implementation using simple hash algorithm
111
+ */
112
+ declare class DefaultHashService implements HashService {
113
+ generateHash(input: string): string;
114
+ generateRequestHash(method: string, url: string, data?: any, options?: Record<string, any>): string;
115
+ }
116
+
117
+ interface RequestInterceptor {
118
+ onRequest?(config: RequestOptions): Promise<RequestOptions> | RequestOptions;
119
+ onRequestError?(error: any): Promise<any>;
120
+ }
121
+ interface ResponseInterceptor {
122
+ onResponse?<T>(response: Response<T>): Promise<Response<T>> | Response<T>;
123
+ onResponseError?(error: RequestError): Promise<any>;
124
+ }
125
+ declare class InterceptorManager {
126
+ private requestInterceptors;
127
+ private responseInterceptors;
128
+ addRequestInterceptor(interceptor: RequestInterceptor): () => void;
129
+ addResponseInterceptor(interceptor: ResponseInterceptor): () => void;
130
+ runRequestInterceptors(config: RequestOptions): Promise<RequestOptions>;
131
+ runResponseInterceptors<T>(response: Response<T>): Promise<Response<T>>;
132
+ }
133
+
134
+ interface RetryOptions {
135
+ maxRetries?: number;
136
+ retryDelay?: number;
137
+ shouldRetry?: (error: RequestError) => boolean | Promise<boolean>;
138
+ }
139
+ declare function createRetryRequestor(requestor: Requestor, options?: RetryOptions): Requestor;
140
+
141
+ interface CacheOptions {
142
+ ttl?: number;
143
+ store?: CacheStore;
144
+ getCacheKey?: (url: string, options?: RequestOptions) => string;
145
+ }
146
+ declare function createCacheRequestor(requestor: Requestor, options?: CacheOptions): Requestor;
147
+
148
+ interface ParallelOptions {
149
+ maxConcurrent?: number;
150
+ timeout?: number;
151
+ }
152
+ declare function createParallelRequestor(requestor: Requestor, options?: ParallelOptions): Requestor;
153
+
154
+ interface IdempotentOptions {
155
+ dedupeTime?: number;
156
+ getRequestId?: (method: string, url: string, data?: any, options?: RequestOptions) => string;
157
+ hashService?: HashService;
158
+ }
159
+ declare function createIdempotentRequestor(requestor: Requestor, options?: IdempotentOptions): Requestor;
160
+
161
+ interface TimeoutOptions {
162
+ timeout?: number;
163
+ timeoutErrorMessage?: string;
164
+ }
165
+ declare function createTimeoutRequestor(requestor: Requestor, options?: TimeoutOptions): Requestor;
166
+
167
+ interface RequestConfig {
168
+ retry?: RetryOptions;
169
+ cache?: CacheOptions;
170
+ parallel?: ParallelOptions;
171
+ idempotent?: IdempotentOptions;
172
+ timeout?: TimeoutOptions;
173
+ }
174
+ declare class Request {
175
+ private requestor;
176
+ interceptors: InterceptorManager;
177
+ constructor(baseRequestor: Requestor, config?: RequestConfig);
178
+ request<T>(method: string, url: string, data?: any, options?: RequestOptions): Promise<T>;
179
+ get<T>(url: string, options?: RequestOptions): Promise<T>;
180
+ post<T>(url: string, data?: any, options?: RequestOptions): Promise<T>;
181
+ put<T>(url: string, data?: any, options?: RequestOptions): Promise<T>;
182
+ delete<T>(url: string, options?: RequestOptions): Promise<T>;
183
+ patch<T>(url: string, data?: any, options?: RequestOptions): Promise<T>;
184
+ }
185
+
186
+ interface ErrorContext {
187
+ url?: string;
188
+ method?: string;
189
+ retryCount?: number;
190
+ requestId?: string;
191
+ }
192
+ /**
193
+ * Creates appropriate error types based on the error context
194
+ */
195
+ declare function createRequestError(error: any, context?: ErrorContext): RequestError;
196
+ /**
197
+ * Determines if an error is retryable
198
+ */
199
+ declare function isRetryableError(error: RequestError): boolean;
200
+ /**
201
+ * Formats error for logging
202
+ */
203
+ declare function formatError(error: RequestError): string;
204
+ /**
205
+ * Extracts error details for debugging
206
+ */
207
+ declare function getErrorDetails(error: RequestError): Record<string, any>;
208
+
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 };
package/dist/index.js ADDED
@@ -0,0 +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
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,W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AAAA,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} "]}
package/dist/index.mjs ADDED
@@ -0,0 +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
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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,CACnD,CAAA,IAAA,CAA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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.mjs","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} "]}
package/package.json CHANGED
@@ -1,24 +1,34 @@
1
1
  {
2
2
  "name": "@ureq/core",
3
- "version": "0.0.1",
3
+ "version": "0.0.2-alpha.0",
4
+ "description": "Universal request library core",
4
5
  "main": "./dist/index.js",
5
6
  "module": "./dist/index.mjs",
6
7
  "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
7
15
  "files": [
8
16
  "dist",
9
17
  "README.md"
10
18
  ],
11
- "scripts": {
12
- "build": "tsup --config tsup.config.ts",
13
- "dev": "tsup --config tsup.config.ts --watch",
14
- "test": "vitest"
19
+ "publishConfig": {
20
+ "access": "public"
15
21
  },
16
22
  "dependencies": {
17
- "@ureq/lib-cache-store": "workspace:*",
18
- "@ureq/lib-hash": "workspace:*"
23
+ "@ureq/business": "0.0.2-alpha.0"
19
24
  },
20
25
  "devDependencies": {
21
26
  "tsup": "^8.3.6",
22
27
  "typescript": "^5.7.3"
28
+ },
29
+ "scripts": {
30
+ "build": "tsup --config tsup.config.ts",
31
+ "dev": "tsup --config tsup.config.ts --watch",
32
+ "test": "vitest"
23
33
  }
24
34
  }