@ureq/core 0.0.1-alpha.3 → 0.0.1
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/package.json +9 -9
- package/dist/index.d.mts +0 -94
- package/dist/index.d.ts +0 -94
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ureq/core",
|
|
3
|
-
"version": "0.0.1
|
|
3
|
+
"version": "0.0.1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -8,17 +8,17 @@
|
|
|
8
8
|
"dist",
|
|
9
9
|
"README.md"
|
|
10
10
|
],
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"@ureq/lib-cache-store": "0.0.1-alpha.1",
|
|
13
|
-
"@ureq/lib-hash": "0.0.1-alpha.1"
|
|
14
|
-
},
|
|
15
|
-
"devDependencies": {
|
|
16
|
-
"tsup": "8.3.6",
|
|
17
|
-
"typescript": "5.7.3"
|
|
18
|
-
},
|
|
19
11
|
"scripts": {
|
|
20
12
|
"build": "tsup --config tsup.config.ts",
|
|
21
13
|
"dev": "tsup --config tsup.config.ts --watch",
|
|
22
14
|
"test": "vitest"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@ureq/lib-cache-store": "workspace:*",
|
|
18
|
+
"@ureq/lib-hash": "workspace:*"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"tsup": "^8.3.6",
|
|
22
|
+
"typescript": "^5.7.3"
|
|
23
23
|
}
|
|
24
24
|
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { MemoryStore } from '@ureq/lib-cache-store';
|
|
2
|
-
|
|
3
|
-
interface RequestOptions {
|
|
4
|
-
headers?: Record<string, string>;
|
|
5
|
-
timeout?: number;
|
|
6
|
-
signal?: AbortSignal;
|
|
7
|
-
responseType?: 'arraybuffer' | 'json' | 'text' | 'blob';
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
}
|
|
10
|
-
interface Response<T = any> {
|
|
11
|
-
data: T;
|
|
12
|
-
status: number;
|
|
13
|
-
statusText: string;
|
|
14
|
-
headers: Record<string, string>;
|
|
15
|
-
}
|
|
16
|
-
interface RequestError extends Error {
|
|
17
|
-
status?: number;
|
|
18
|
-
code?: string;
|
|
19
|
-
data?: any;
|
|
20
|
-
}
|
|
21
|
-
interface Requestor {
|
|
22
|
-
get<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;
|
|
23
|
-
post<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;
|
|
24
|
-
put<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;
|
|
25
|
-
delete<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;
|
|
26
|
-
patch<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface RequestInterceptor {
|
|
30
|
-
onRequest?(config: RequestOptions): Promise<RequestOptions> | RequestOptions;
|
|
31
|
-
onRequestError?(error: any): Promise<any>;
|
|
32
|
-
}
|
|
33
|
-
interface ResponseInterceptor {
|
|
34
|
-
onResponse?<T>(response: Response<T>): Promise<Response<T>> | Response<T>;
|
|
35
|
-
onResponseError?(error: RequestError): Promise<any>;
|
|
36
|
-
}
|
|
37
|
-
declare class InterceptorManager {
|
|
38
|
-
private requestInterceptors;
|
|
39
|
-
private responseInterceptors;
|
|
40
|
-
addRequestInterceptor(interceptor: RequestInterceptor): () => void;
|
|
41
|
-
addResponseInterceptor(interceptor: ResponseInterceptor): () => void;
|
|
42
|
-
runRequestInterceptors(config: RequestOptions): Promise<RequestOptions>;
|
|
43
|
-
runResponseInterceptors<T>(response: Response<T>): Promise<Response<T>>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface RetryOptions {
|
|
47
|
-
maxRetries?: number;
|
|
48
|
-
retryDelay?: number;
|
|
49
|
-
shouldRetry?: (error: RequestError) => boolean | Promise<boolean>;
|
|
50
|
-
}
|
|
51
|
-
declare function createRetryRequestor(requestor: Requestor, options?: RetryOptions): Requestor;
|
|
52
|
-
|
|
53
|
-
interface CacheOptions {
|
|
54
|
-
ttl?: number;
|
|
55
|
-
store?: MemoryStore;
|
|
56
|
-
getCacheKey?: (url: string, options?: RequestOptions) => string;
|
|
57
|
-
}
|
|
58
|
-
declare function createCacheRequestor(requestor: Requestor, options?: CacheOptions): Requestor;
|
|
59
|
-
|
|
60
|
-
interface ParallelOptions {
|
|
61
|
-
maxConcurrent?: number;
|
|
62
|
-
timeout?: number;
|
|
63
|
-
}
|
|
64
|
-
declare function createParallelRequestor(requestor: Requestor, options?: ParallelOptions): Requestor;
|
|
65
|
-
|
|
66
|
-
interface IdempotentOptions {
|
|
67
|
-
dedupeTime?: number;
|
|
68
|
-
getRequestId?: (method: string, url: string, data?: any, options?: RequestOptions) => string;
|
|
69
|
-
}
|
|
70
|
-
declare function createIdempotentRequestor(requestor: Requestor, options?: IdempotentOptions): Requestor;
|
|
71
|
-
|
|
72
|
-
interface TimeoutOptions {
|
|
73
|
-
timeout?: number;
|
|
74
|
-
timeoutErrorMessage?: string;
|
|
75
|
-
}
|
|
76
|
-
declare function createTimeoutRequestor(requestor: Requestor, options?: TimeoutOptions): Requestor;
|
|
77
|
-
|
|
78
|
-
interface RequestConfig {
|
|
79
|
-
retry?: RetryOptions;
|
|
80
|
-
cache?: CacheOptions;
|
|
81
|
-
parallel?: ParallelOptions;
|
|
82
|
-
idempotent?: IdempotentOptions;
|
|
83
|
-
timeout?: TimeoutOptions;
|
|
84
|
-
}
|
|
85
|
-
declare class Request {
|
|
86
|
-
private requestor;
|
|
87
|
-
interceptors: InterceptorManager;
|
|
88
|
-
constructor(baseRequestor: Requestor, config?: RequestConfig);
|
|
89
|
-
request<T>(method: string, url: string, data?: any, options?: RequestOptions): Promise<T>;
|
|
90
|
-
get<T>(url: string, options?: RequestOptions): Promise<T>;
|
|
91
|
-
post<T>(url: string, data?: any, options?: RequestOptions): Promise<T>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export { type CacheOptions, type IdempotentOptions, InterceptorManager, type ParallelOptions, Request, type RequestConfig, type RequestError, type RequestInterceptor, type RequestOptions, type Requestor, type Response, type ResponseInterceptor, type RetryOptions, type TimeoutOptions, createCacheRequestor, createIdempotentRequestor, createParallelRequestor, createRetryRequestor, createTimeoutRequestor };
|
package/dist/index.d.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { MemoryStore } from '@ureq/lib-cache-store';
|
|
2
|
-
|
|
3
|
-
interface RequestOptions {
|
|
4
|
-
headers?: Record<string, string>;
|
|
5
|
-
timeout?: number;
|
|
6
|
-
signal?: AbortSignal;
|
|
7
|
-
responseType?: 'arraybuffer' | 'json' | 'text' | 'blob';
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
}
|
|
10
|
-
interface Response<T = any> {
|
|
11
|
-
data: T;
|
|
12
|
-
status: number;
|
|
13
|
-
statusText: string;
|
|
14
|
-
headers: Record<string, string>;
|
|
15
|
-
}
|
|
16
|
-
interface RequestError extends Error {
|
|
17
|
-
status?: number;
|
|
18
|
-
code?: string;
|
|
19
|
-
data?: any;
|
|
20
|
-
}
|
|
21
|
-
interface Requestor {
|
|
22
|
-
get<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;
|
|
23
|
-
post<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;
|
|
24
|
-
put<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;
|
|
25
|
-
delete<T = any>(url: string, options?: RequestOptions): Promise<Response<T>>;
|
|
26
|
-
patch<T = any>(url: string, data?: any, options?: RequestOptions): Promise<Response<T>>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface RequestInterceptor {
|
|
30
|
-
onRequest?(config: RequestOptions): Promise<RequestOptions> | RequestOptions;
|
|
31
|
-
onRequestError?(error: any): Promise<any>;
|
|
32
|
-
}
|
|
33
|
-
interface ResponseInterceptor {
|
|
34
|
-
onResponse?<T>(response: Response<T>): Promise<Response<T>> | Response<T>;
|
|
35
|
-
onResponseError?(error: RequestError): Promise<any>;
|
|
36
|
-
}
|
|
37
|
-
declare class InterceptorManager {
|
|
38
|
-
private requestInterceptors;
|
|
39
|
-
private responseInterceptors;
|
|
40
|
-
addRequestInterceptor(interceptor: RequestInterceptor): () => void;
|
|
41
|
-
addResponseInterceptor(interceptor: ResponseInterceptor): () => void;
|
|
42
|
-
runRequestInterceptors(config: RequestOptions): Promise<RequestOptions>;
|
|
43
|
-
runResponseInterceptors<T>(response: Response<T>): Promise<Response<T>>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface RetryOptions {
|
|
47
|
-
maxRetries?: number;
|
|
48
|
-
retryDelay?: number;
|
|
49
|
-
shouldRetry?: (error: RequestError) => boolean | Promise<boolean>;
|
|
50
|
-
}
|
|
51
|
-
declare function createRetryRequestor(requestor: Requestor, options?: RetryOptions): Requestor;
|
|
52
|
-
|
|
53
|
-
interface CacheOptions {
|
|
54
|
-
ttl?: number;
|
|
55
|
-
store?: MemoryStore;
|
|
56
|
-
getCacheKey?: (url: string, options?: RequestOptions) => string;
|
|
57
|
-
}
|
|
58
|
-
declare function createCacheRequestor(requestor: Requestor, options?: CacheOptions): Requestor;
|
|
59
|
-
|
|
60
|
-
interface ParallelOptions {
|
|
61
|
-
maxConcurrent?: number;
|
|
62
|
-
timeout?: number;
|
|
63
|
-
}
|
|
64
|
-
declare function createParallelRequestor(requestor: Requestor, options?: ParallelOptions): Requestor;
|
|
65
|
-
|
|
66
|
-
interface IdempotentOptions {
|
|
67
|
-
dedupeTime?: number;
|
|
68
|
-
getRequestId?: (method: string, url: string, data?: any, options?: RequestOptions) => string;
|
|
69
|
-
}
|
|
70
|
-
declare function createIdempotentRequestor(requestor: Requestor, options?: IdempotentOptions): Requestor;
|
|
71
|
-
|
|
72
|
-
interface TimeoutOptions {
|
|
73
|
-
timeout?: number;
|
|
74
|
-
timeoutErrorMessage?: string;
|
|
75
|
-
}
|
|
76
|
-
declare function createTimeoutRequestor(requestor: Requestor, options?: TimeoutOptions): Requestor;
|
|
77
|
-
|
|
78
|
-
interface RequestConfig {
|
|
79
|
-
retry?: RetryOptions;
|
|
80
|
-
cache?: CacheOptions;
|
|
81
|
-
parallel?: ParallelOptions;
|
|
82
|
-
idempotent?: IdempotentOptions;
|
|
83
|
-
timeout?: TimeoutOptions;
|
|
84
|
-
}
|
|
85
|
-
declare class Request {
|
|
86
|
-
private requestor;
|
|
87
|
-
interceptors: InterceptorManager;
|
|
88
|
-
constructor(baseRequestor: Requestor, config?: RequestConfig);
|
|
89
|
-
request<T>(method: string, url: string, data?: any, options?: RequestOptions): Promise<T>;
|
|
90
|
-
get<T>(url: string, options?: RequestOptions): Promise<T>;
|
|
91
|
-
post<T>(url: string, data?: any, options?: RequestOptions): Promise<T>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export { type CacheOptions, type IdempotentOptions, InterceptorManager, type ParallelOptions, Request, type RequestConfig, type RequestError, type RequestInterceptor, type RequestOptions, type Requestor, type Response, type ResponseInterceptor, type RetryOptions, type TimeoutOptions, createCacheRequestor, createIdempotentRequestor, createParallelRequestor, createRetryRequestor, createTimeoutRequestor };
|
package/dist/index.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var libCacheStore=require('@ureq/lib-cache-store'),libHash=require('@ureq/lib-hash');var c=class{constructor(){this.requestInterceptors=[];this.responseInterceptors=[];}addRequestInterceptor(p){return this.requestInterceptors.push(p),()=>{let t=this.requestInterceptors.indexOf(p);t!==-1&&this.requestInterceptors.splice(t,1);}}addResponseInterceptor(p){return this.responseInterceptors.push(p),()=>{let t=this.responseInterceptors.indexOf(p);t!==-1&&this.responseInterceptors.splice(t,1);}}async runRequestInterceptors(p){let t={...p};for(let s of this.requestInterceptors)s.onRequest&&(t=await s.onRequest(t));return t}async runResponseInterceptors(p){let t={...p};for(let s of this.responseInterceptors)s.onResponse&&(t=await s.onResponse(t));return t}};var x={maxRetries:3,retryDelay:1e3,shouldRetry:o=>o.status?o.status>=500:true};function T(o,p){let t={...x,...p};async function s(n,r=0){try{return await n()}catch(e){if(!await t.shouldRetry(e)||r>=t.maxRetries)throw e;return await new Promise(u=>setTimeout(u,t.retryDelay)),s(n,r+1)}}return {async get(n,r){return s(()=>o.get(n,r))},async post(n,r,e){return s(()=>o.post(n,r,e))},async put(n,r,e){return s(()=>o.put(n,r,e))},async delete(n,r){return s(()=>o.delete(n,r))},async patch(n,r,e){return s(()=>o.patch(n,r,e))}}}var I={ttl:5*60*1e3,store:new libCacheStore.MemoryStore,getCacheKey:(o,p)=>`${o}${p?JSON.stringify(p):""}`};function g(o,p){let t={...I,...p};async function s(n,r){let e=t.store.get(n);if(e)return e;let i=await r();return t.store.set(n,i,t.ttl),i}return {async get(n,r){let e=t.getCacheKey(n,r);return s(e,()=>o.get(n,r))},post:o.post.bind(o),put:o.put.bind(o),delete:o.delete.bind(o),patch:o.patch.bind(o)}}var w={maxConcurrent:5,timeout:3e4},m=class{constructor(p){this.maxConcurrent=p;this.queue=[];this.running=0;}async add(p){this.running>=this.maxConcurrent&&await new Promise(t=>{this.queue.push(t);}),this.running++;try{return await p()}finally{this.running--,this.queue.length>0&&this.queue.shift()?.();}}};function O(o,p){let t={...w,...p},s=new m(t.maxConcurrent);return {async get(n,r){return s.add(()=>o.get(n,r))},async post(n,r,e){return s.add(()=>o.post(n,r,e))},async put(n,r,e){return s.add(()=>o.put(n,r,e))},async delete(n,r){return s.add(()=>o.delete(n,r))},async patch(n,r,e){return s.add(()=>o.patch(n,r,e))}}}var b={dedupeTime:1e3,getRequestId:(o,p,t,s)=>libHash.generateHash(`${o}:${p}:${JSON.stringify(t)}:${JSON.stringify(s)}`)};function d(o,p){let t={...b,...p},s=new Map;function n(){let e=Date.now();for(let[i,u]of s.entries())e-u.timestamp>t.dedupeTime&&s.delete(i);}async function r(e,i,u,a,h){let R=t.getRequestId(e,i,a,h);n();let l=s.get(R);if(l)return l.promise;let q=u();s.set(R,{promise:q,timestamp:Date.now()});try{return await q}finally{s.delete(R);}}return {get:(e,i)=>r("GET",e,()=>o.get(e,i),null,i),post:(e,i,u)=>r("POST",e,()=>o.post(e,i,u),i,u),put:(e,i,u)=>r("PUT",e,()=>o.put(e,i,u),i,u),delete:(e,i)=>r("DELETE",e,()=>o.delete(e,i),null,i),patch:(e,i,u)=>r("PATCH",e,()=>o.patch(e,i,u),i,u)}}var E={timeout:3e4,timeoutErrorMessage:"Request timeout"};function y(o,p){let t={...E,...p};async function s(n,r=t.timeout){let e=new AbortController,i=setTimeout(()=>e.abort(),r);try{let u=await n();return clearTimeout(i),u}catch(u){if(clearTimeout(i),u instanceof DOMException&&u.name==="AbortError"){let a=new Error(t.timeoutErrorMessage);throw a.code="TIMEOUT",a}throw u}}return {get:(n,r)=>{let e=r?.signal,i={...r,signal:e||new AbortController().signal};return s(()=>o.get(n,i))},post:(n,r,e)=>{let i=e?.signal,u={...e,signal:i||new AbortController().signal};return s(()=>o.post(n,r,u))},put:(n,r,e)=>{let i=e?.signal,u={...e,signal:i||new AbortController().signal};return s(()=>o.put(n,r,u))},delete:(n,r)=>{let e=r?.signal,i={...r,signal:e||new AbortController().signal};return s(()=>o.delete(n,i))},patch:(n,r,e)=>{let i=e?.signal,u={...e,signal:i||new AbortController().signal};return s(()=>o.patch(n,r,u))}}}var f=class{constructor(p,t){this.interceptors=new c;let s=p;t?.timeout&&(s=y(s,t.timeout)),t?.retry&&(s=T(s,t.retry)),t?.cache&&(s=g(s,t.cache)),t?.parallel&&(s=O(s,t.parallel)),t?.idempotent&&(s=d(s,t.idempotent)),this.requestor=s;}async request(p,t,s,n){let r=await this.interceptors.runRequestInterceptors({...n,method:p,url:t,data:s});try{let e=p.toLowerCase(),i=await this.requestor[e](t,s,r);return (await this.interceptors.runResponseInterceptors(i)).data}catch(e){throw e}}get(p,t){return this.request("GET",p,void 0,t)}post(p,t,s){return this.request("POST",p,t,s)}};exports.InterceptorManager=c;exports.Request=f;exports.createCacheRequestor=g;exports.createIdempotentRequestor=d;exports.createParallelRequestor=O;exports.createRetryRequestor=T;exports.createTimeoutRequestor=y;//# sourceMappingURL=index.js.map
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interceptor.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":["InterceptorManager","interceptor","index","config","currentConfig","response","currentResponse","defaultRetryOptions","error","createRetryRequestor","requestor","options","finalOptions","retryRequest","request","retries","resolve","url","data","defaultCacheOptions","MemoryStore","createCacheRequestor","cacheRequest","key","cached","defaultParallelOptions","RequestQueue","maxConcurrent","task","createParallelRequestor","queue","defaultOptions","method","generateHash","createIdempotentRequestor","pendingRequests","cleanupOldRequests","now","dedupeRequest","requestFn","requestId","existing","promise","createTimeoutRequestor","withTimeout","timeout","controller","timeoutId","timeoutError","signal","mergedOptions","Request","baseRequestor","requestMethod"],"mappings":"kGAYO,IAAMA,CAAN,CAAA,KAAyB,CAAzB,WAAA,EAAA,CACL,KAAQ,mBAA4C,CAAA,EACpD,CAAA,IAAA,CAAQ,oBAA8C,CAAA,GAEtD,CAAA,qBAAA,CAAsBC,EAAiC,CACrD,OAAA,IAAA,CAAK,mBAAoB,CAAA,IAAA,CAAKA,CAAW,CAAA,CAClC,IAAM,CACX,IAAMC,CAAQ,CAAA,IAAA,CAAK,mBAAoB,CAAA,OAAA,CAAQD,CAAW,CACtDC,CAAAA,CAAAA,GAAU,EACZ,EAAA,IAAA,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CAAW,CAAA,MAAM,KAAK,SAAUgD,CAAAA,CAAa,CAAEpC,CAAAA,CAAAA,CAAKC,EAAMf,CAAM,CAAA,CACtE,OAAQ,CAAA,MAAM,KAAK,YAAa,CAAA,uBAAA,CAAwBE,CAAQ,CAAA,EAAG,IACrE,CAAA,MAASG,CAAO,CAAA,CACd,MAAMA,CACR,CACF,CAEA,GAAA,CAAOS,EAAaN,CAAsC,CAAA,CACxD,OAAO,IAAA,CAAK,QAAQ,KAAOM,CAAAA,CAAAA,CAAK,MAAWN,CAAAA,CAAO,CACpD,CAEA,IAAQM,CAAAA,CAAAA,CAAaC,EAAYP,CAAsC,CAAA,CACrE,OAAO,IAAA,CAAK,QAAQ,MAAQM,CAAAA,CAAAA,CAAKC,CAAMP,CAAAA,CAAO,CAChD,CAGF","file":"index.js","sourcesContent":["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 { Requestor, RequestOptions, Response, RequestError } from '../../interfaces/request';\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) => error.status ? error.status >= 500 : true,\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 shouldRetry = await finalOptions.shouldRetry(error as RequestError);\n \n if (!shouldRetry || retries >= finalOptions.maxRetries) {\n throw error;\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 { MemoryStore } from '@ureq/lib-cache-store';\n\nexport interface CacheOptions {\n ttl?: number;\n store?: MemoryStore;\n getCacheKey?: (url: string, options?: RequestOptions) => string;\n}\n\nconst defaultCacheOptions: Required<CacheOptions> = {\n ttl: 5 * 60 * 1000, // 5 minutes\n store: new MemoryStore(),\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 = finalOptions.store.get<Response<T>>(key);\n if (cached) {\n return cached;\n }\n\n const response = await request();\n 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 { generateHash } from '@ureq/lib-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}\n\nconst defaultOptions: Required<IdempotentOptions> = {\n dedupeTime: 1000,\n getRequestId: (method: string, url: string, data?: any, options?: RequestOptions) => {\n return generateHash(`${method}:${url}:${JSON.stringify(data)}:${JSON.stringify(options)}`);\n },\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 // 实现其他方法...\n} "]}
|
package/dist/index.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {MemoryStore}from'@ureq/lib-cache-store';import {generateHash}from'@ureq/lib-hash';var c=class{constructor(){this.requestInterceptors=[];this.responseInterceptors=[];}addRequestInterceptor(p){return this.requestInterceptors.push(p),()=>{let t=this.requestInterceptors.indexOf(p);t!==-1&&this.requestInterceptors.splice(t,1);}}addResponseInterceptor(p){return this.responseInterceptors.push(p),()=>{let t=this.responseInterceptors.indexOf(p);t!==-1&&this.responseInterceptors.splice(t,1);}}async runRequestInterceptors(p){let t={...p};for(let s of this.requestInterceptors)s.onRequest&&(t=await s.onRequest(t));return t}async runResponseInterceptors(p){let t={...p};for(let s of this.responseInterceptors)s.onResponse&&(t=await s.onResponse(t));return t}};var x={maxRetries:3,retryDelay:1e3,shouldRetry:o=>o.status?o.status>=500:true};function T(o,p){let t={...x,...p};async function s(n,r=0){try{return await n()}catch(e){if(!await t.shouldRetry(e)||r>=t.maxRetries)throw e;return await new Promise(u=>setTimeout(u,t.retryDelay)),s(n,r+1)}}return {async get(n,r){return s(()=>o.get(n,r))},async post(n,r,e){return s(()=>o.post(n,r,e))},async put(n,r,e){return s(()=>o.put(n,r,e))},async delete(n,r){return s(()=>o.delete(n,r))},async patch(n,r,e){return s(()=>o.patch(n,r,e))}}}var I={ttl:5*60*1e3,store:new MemoryStore,getCacheKey:(o,p)=>`${o}${p?JSON.stringify(p):""}`};function g(o,p){let t={...I,...p};async function s(n,r){let e=t.store.get(n);if(e)return e;let i=await r();return t.store.set(n,i,t.ttl),i}return {async get(n,r){let e=t.getCacheKey(n,r);return s(e,()=>o.get(n,r))},post:o.post.bind(o),put:o.put.bind(o),delete:o.delete.bind(o),patch:o.patch.bind(o)}}var w={maxConcurrent:5,timeout:3e4},m=class{constructor(p){this.maxConcurrent=p;this.queue=[];this.running=0;}async add(p){this.running>=this.maxConcurrent&&await new Promise(t=>{this.queue.push(t);}),this.running++;try{return await p()}finally{this.running--,this.queue.length>0&&this.queue.shift()?.();}}};function O(o,p){let t={...w,...p},s=new m(t.maxConcurrent);return {async get(n,r){return s.add(()=>o.get(n,r))},async post(n,r,e){return s.add(()=>o.post(n,r,e))},async put(n,r,e){return s.add(()=>o.put(n,r,e))},async delete(n,r){return s.add(()=>o.delete(n,r))},async patch(n,r,e){return s.add(()=>o.patch(n,r,e))}}}var b={dedupeTime:1e3,getRequestId:(o,p,t,s)=>generateHash(`${o}:${p}:${JSON.stringify(t)}:${JSON.stringify(s)}`)};function d(o,p){let t={...b,...p},s=new Map;function n(){let e=Date.now();for(let[i,u]of s.entries())e-u.timestamp>t.dedupeTime&&s.delete(i);}async function r(e,i,u,a,h){let R=t.getRequestId(e,i,a,h);n();let l=s.get(R);if(l)return l.promise;let q=u();s.set(R,{promise:q,timestamp:Date.now()});try{return await q}finally{s.delete(R);}}return {get:(e,i)=>r("GET",e,()=>o.get(e,i),null,i),post:(e,i,u)=>r("POST",e,()=>o.post(e,i,u),i,u),put:(e,i,u)=>r("PUT",e,()=>o.put(e,i,u),i,u),delete:(e,i)=>r("DELETE",e,()=>o.delete(e,i),null,i),patch:(e,i,u)=>r("PATCH",e,()=>o.patch(e,i,u),i,u)}}var E={timeout:3e4,timeoutErrorMessage:"Request timeout"};function y(o,p){let t={...E,...p};async function s(n,r=t.timeout){let e=new AbortController,i=setTimeout(()=>e.abort(),r);try{let u=await n();return clearTimeout(i),u}catch(u){if(clearTimeout(i),u instanceof DOMException&&u.name==="AbortError"){let a=new Error(t.timeoutErrorMessage);throw a.code="TIMEOUT",a}throw u}}return {get:(n,r)=>{let e=r?.signal,i={...r,signal:e||new AbortController().signal};return s(()=>o.get(n,i))},post:(n,r,e)=>{let i=e?.signal,u={...e,signal:i||new AbortController().signal};return s(()=>o.post(n,r,u))},put:(n,r,e)=>{let i=e?.signal,u={...e,signal:i||new AbortController().signal};return s(()=>o.put(n,r,u))},delete:(n,r)=>{let e=r?.signal,i={...r,signal:e||new AbortController().signal};return s(()=>o.delete(n,i))},patch:(n,r,e)=>{let i=e?.signal,u={...e,signal:i||new AbortController().signal};return s(()=>o.patch(n,r,u))}}}var f=class{constructor(p,t){this.interceptors=new c;let s=p;t?.timeout&&(s=y(s,t.timeout)),t?.retry&&(s=T(s,t.retry)),t?.cache&&(s=g(s,t.cache)),t?.parallel&&(s=O(s,t.parallel)),t?.idempotent&&(s=d(s,t.idempotent)),this.requestor=s;}async request(p,t,s,n){let r=await this.interceptors.runRequestInterceptors({...n,method:p,url:t,data:s});try{let e=p.toLowerCase(),i=await this.requestor[e](t,s,r);return (await this.interceptors.runResponseInterceptors(i)).data}catch(e){throw e}}get(p,t){return this.request("GET",p,void 0,t)}post(p,t,s){return this.request("POST",p,t,s)}};export{c as InterceptorManager,f as Request,g as createCacheRequestor,d as createIdempotentRequestor,O as createParallelRequestor,T as createRetryRequestor,y as createTimeoutRequestor};//# sourceMappingURL=index.mjs.map
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interceptor.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":["InterceptorManager","interceptor","index","config","currentConfig","response","currentResponse","defaultRetryOptions","error","createRetryRequestor","requestor","options","finalOptions","retryRequest","request","retries","resolve","url","data","defaultCacheOptions","MemoryStore","createCacheRequestor","cacheRequest","key","cached","defaultParallelOptions","RequestQueue","maxConcurrent","task","createParallelRequestor","queue","defaultOptions","method","generateHash","createIdempotentRequestor","pendingRequests","cleanupOldRequests","now","dedupeRequest","requestFn","requestId","existing","promise","createTimeoutRequestor","withTimeout","timeout","controller","timeoutId","timeoutError","signal","mergedOptions","Request","baseRequestor","requestMethod"],"mappings":"0FAYO,IAAMA,CAAN,CAAA,KAAyB,CAAzB,WAAA,EAAA,CACL,KAAQ,mBAA4C,CAAA,EACpD,CAAA,IAAA,CAAQ,oBAA8C,CAAA,GAEtD,CAAA,qBAAA,CAAsBC,EAAiC,CACrD,OAAA,IAAA,CAAK,mBAAoB,CAAA,IAAA,CAAKA,CAAW,CAAA,CAClC,IAAM,CACX,IAAMC,CAAQ,CAAA,IAAA,CAAK,mBAAoB,CAAA,OAAA,CAAQD,CAAW,CACtDC,CAAAA,CAAAA,GAAU,EACZ,EAAA,IAAA,CAAK,oBAAoB,MAAOA,CAAAA,CAAAA,CAAO,CAAC,EAE5C,CACF,CAEA,sBAAuBD,CAAAA,CAAAA,CAAkC,CACvD,OAAK,IAAA,CAAA,oBAAA,CAAqB,IAAKA,CAAAA,CAAW,CACnC,CAAA,IAAM,CACX,IAAMC,EAAQ,IAAK,CAAA,oBAAA,CAAqB,OAAQD,CAAAA,CAAW,CACvDC,CAAAA,CAAAA,GAAU,EACZ,EAAA,IAAA,CAAK,qBAAqB,MAAOA,CAAAA,CAAAA,CAAO,CAAC,EAE7C,CACF,CAEA,MAAM,sBAAuBC,CAAAA,CAAAA,CAAiD,CAC5E,IAAIC,CAAAA,CAAgB,CAAE,GAAGD,CAAO,CAAA,CAChC,IAAWF,IAAAA,CAAAA,IAAe,KAAK,mBACzBA,CAAAA,CAAAA,CAAY,SACdG,GAAAA,CAAAA,CAAgB,MAA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aces/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 { Requestor, RequestOptions, Response, RequestError } from '../../interfaces/request';\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) => error.status ? error.status >= 500 : true,\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 shouldRetry = await finalOptions.shouldRetry(error as RequestError);\n \n if (!shouldRetry || retries >= finalOptions.maxRetries) {\n throw error;\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 { MemoryStore } from '@ureq/lib-cache-store';\n\nexport interface CacheOptions {\n ttl?: number;\n store?: MemoryStore;\n getCacheKey?: (url: string, options?: RequestOptions) => string;\n}\n\nconst defaultCacheOptions: Required<CacheOptions> = {\n ttl: 5 * 60 * 1000, // 5 minutes\n store: new MemoryStore(),\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 = finalOptions.store.get<Response<T>>(key);\n if (cached) {\n return cached;\n }\n\n const response = await request();\n 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 { generateHash } from '@ureq/lib-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}\n\nconst defaultOptions: Required<IdempotentOptions> = {\n dedupeTime: 1000,\n getRequestId: (method: string, url: string, data?: any, options?: RequestOptions) => {\n return generateHash(`${method}:${url}:${JSON.stringify(data)}:${JSON.stringify(options)}`);\n },\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 // 实现其他方法...\n} "]}
|