@yh-ui/request 0.1.21

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.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +274 -0
  3. package/dist/adapters/fetch.cjs +157 -0
  4. package/dist/adapters/fetch.d.ts +25 -0
  5. package/dist/adapters/fetch.mjs +148 -0
  6. package/dist/adapters/index.cjs +27 -0
  7. package/dist/adapters/index.d.ts +5 -0
  8. package/dist/adapters/index.mjs +2 -0
  9. package/dist/adapters/platform.cjs +394 -0
  10. package/dist/adapters/platform.d.ts +72 -0
  11. package/dist/adapters/platform.mjs +369 -0
  12. package/dist/cache/index.cjs +56 -0
  13. package/dist/cache/index.d.ts +21 -0
  14. package/dist/cache/index.mjs +14 -0
  15. package/dist/cache/indexedDB.cjs +188 -0
  16. package/dist/cache/indexedDB.d.ts +58 -0
  17. package/dist/cache/indexedDB.mjs +176 -0
  18. package/dist/cache/localStorage.cjs +158 -0
  19. package/dist/cache/localStorage.d.ts +58 -0
  20. package/dist/cache/localStorage.mjs +153 -0
  21. package/dist/cache/memory.cjs +112 -0
  22. package/dist/cache/memory.d.ts +71 -0
  23. package/dist/cache/memory.mjs +103 -0
  24. package/dist/graphql.cjs +255 -0
  25. package/dist/graphql.d.ts +192 -0
  26. package/dist/graphql.mjs +235 -0
  27. package/dist/http-cache.cjs +248 -0
  28. package/dist/http-cache.d.ts +156 -0
  29. package/dist/http-cache.mjs +233 -0
  30. package/dist/index.cjs +181 -0
  31. package/dist/index.d.ts +23 -0
  32. package/dist/index.mjs +16 -0
  33. package/dist/interceptors/debug.cjs +139 -0
  34. package/dist/interceptors/debug.d.ts +92 -0
  35. package/dist/interceptors/debug.mjs +130 -0
  36. package/dist/interceptors/index.cjs +38 -0
  37. package/dist/interceptors/index.d.ts +6 -0
  38. package/dist/interceptors/index.mjs +3 -0
  39. package/dist/interceptors/progress.cjs +185 -0
  40. package/dist/interceptors/progress.d.ts +97 -0
  41. package/dist/interceptors/progress.mjs +177 -0
  42. package/dist/interceptors/security.cjs +154 -0
  43. package/dist/interceptors/security.d.ts +83 -0
  44. package/dist/interceptors/security.mjs +134 -0
  45. package/dist/plugin.cjs +166 -0
  46. package/dist/plugin.d.ts +106 -0
  47. package/dist/plugin.mjs +163 -0
  48. package/dist/request.cjs +396 -0
  49. package/dist/request.d.ts +111 -0
  50. package/dist/request.mjs +339 -0
  51. package/dist/types.cjs +13 -0
  52. package/dist/types.d.ts +157 -0
  53. package/dist/types.mjs +7 -0
  54. package/dist/useAIStream.cjs +125 -0
  55. package/dist/useAIStream.d.ts +89 -0
  56. package/dist/useAIStream.mjs +108 -0
  57. package/dist/useLoadMore.cjs +136 -0
  58. package/dist/useLoadMore.d.ts +84 -0
  59. package/dist/useLoadMore.mjs +134 -0
  60. package/dist/usePagination.cjs +141 -0
  61. package/dist/usePagination.d.ts +89 -0
  62. package/dist/usePagination.mjs +132 -0
  63. package/dist/useQueue.cjs +243 -0
  64. package/dist/useQueue.d.ts +118 -0
  65. package/dist/useQueue.mjs +239 -0
  66. package/dist/useRequest.cjs +325 -0
  67. package/dist/useRequest.d.ts +126 -0
  68. package/dist/useRequest.mjs +329 -0
  69. package/dist/useRequestQueue.cjs +36 -0
  70. package/dist/useRequestQueue.d.ts +52 -0
  71. package/dist/useRequestQueue.mjs +27 -0
  72. package/dist/useSSE.cjs +241 -0
  73. package/dist/useSSE.d.ts +74 -0
  74. package/dist/useSSE.mjs +226 -0
  75. package/dist/websocket.cjs +325 -0
  76. package/dist/websocket.d.ts +163 -0
  77. package/dist/websocket.mjs +316 -0
  78. package/package.json +61 -0
@@ -0,0 +1,163 @@
1
+ export class PluginManager {
2
+ plugins = /* @__PURE__ */ new Map();
3
+ request = null;
4
+ lifecycleHooks = {};
5
+ /**
6
+ * 初始化插件管理器
7
+ */
8
+ init(request) {
9
+ this.request = request;
10
+ }
11
+ /**
12
+ * 注册插件
13
+ */
14
+ use(plugin, options) {
15
+ if (this.plugins.has(plugin.name)) {
16
+ console.warn(`Plugin ${plugin.name} is already installed`);
17
+ return this;
18
+ }
19
+ if (!this.request) {
20
+ throw new Error("PluginManager must be initialized with a Request instance");
21
+ }
22
+ plugin.install(this.request, options);
23
+ this.plugins.set(plugin.name, {
24
+ plugin,
25
+ options,
26
+ installedAt: Date.now()
27
+ });
28
+ return this;
29
+ }
30
+ /**
31
+ * 卸载插件
32
+ */
33
+ uninstall(name) {
34
+ const instance = this.plugins.get(name);
35
+ if (!instance) return false;
36
+ if (instance.plugin.uninstall && this.request) {
37
+ instance.plugin.uninstall(this.request);
38
+ }
39
+ this.plugins.delete(name);
40
+ return true;
41
+ }
42
+ /**
43
+ * 获取插件
44
+ */
45
+ get(name) {
46
+ return this.plugins.get(name);
47
+ }
48
+ /**
49
+ * 获取所有插件
50
+ */
51
+ getAll() {
52
+ return Array.from(this.plugins.values());
53
+ }
54
+ /**
55
+ * 检查插件是否已安装
56
+ */
57
+ has(name) {
58
+ return this.plugins.has(name);
59
+ }
60
+ /**
61
+ * 清除所有插件
62
+ */
63
+ clear() {
64
+ this.plugins.forEach((instance, name) => {
65
+ this.uninstall(name);
66
+ });
67
+ }
68
+ /**
69
+ * 注册生命周期钩子
70
+ */
71
+ registerHooks(hooks) {
72
+ this.lifecycleHooks = {
73
+ ...this.lifecycleHooks,
74
+ ...hooks
75
+ };
76
+ }
77
+ /**
78
+ * 获取生命周期钩子
79
+ */
80
+ getHooks() {
81
+ return { ...this.lifecycleHooks };
82
+ }
83
+ }
84
+ export const loggingPlugin = {
85
+ name: "logging",
86
+ version: "1.0.0",
87
+ install(request) {
88
+ request.interceptors.request.use((config) => {
89
+ console.log(`[YH-Request] \u2192 ${config.method} ${config.url}`);
90
+ return config;
91
+ });
92
+ request.interceptors.response.use((response) => {
93
+ console.log(`[YH-Request] \u2190 ${response.response.status} ${response.config.url}`);
94
+ return response;
95
+ });
96
+ }
97
+ };
98
+ export const cachePlugin = {
99
+ name: "cache",
100
+ version: "1.0.0",
101
+ install(request, options) {
102
+ request.interceptors.request.use((config) => {
103
+ if (config.method === "GET" && options?.getCache) {
104
+ const key = config.url || "";
105
+ const cached = options.getCache(key);
106
+ if (cached) {
107
+ console.log("[YH-Request Cache] Cache hit:", key);
108
+ }
109
+ }
110
+ return config;
111
+ });
112
+ request.interceptors.response.use((response) => {
113
+ if (response.config.method === "GET" && options?.setCache) {
114
+ const key = response.config.url || "";
115
+ options.setCache(key, response.data);
116
+ }
117
+ return response;
118
+ });
119
+ }
120
+ };
121
+ export const errorHandlerPlugin = {
122
+ name: "errorHandler",
123
+ version: "1.0.0",
124
+ install(request, options) {
125
+ request.interceptors.response.use(
126
+ (response) => response,
127
+ (error) => {
128
+ if (options?.onError) {
129
+ options.onError(error);
130
+ }
131
+ return Promise.reject(error);
132
+ }
133
+ );
134
+ }
135
+ };
136
+ export const retryPlugin = {
137
+ name: "retry",
138
+ version: "1.0.0",
139
+ install(request, options) {
140
+ const retries = options?.retries || 3;
141
+ const retryDelay = options?.retryDelay || 1e3;
142
+ request.interceptors.response.use(
143
+ (response) => response,
144
+ async (error) => {
145
+ const config = error.config;
146
+ if (!config) return Promise.reject(error);
147
+ const currentRetries = config._retryCount || 0;
148
+ if (currentRetries < retries) {
149
+ config._retryCount = currentRetries + 1;
150
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
151
+ return request.request(config);
152
+ }
153
+ return Promise.reject(error);
154
+ }
155
+ );
156
+ }
157
+ };
158
+ export const builtInPlugins = {
159
+ logging: loggingPlugin,
160
+ cache: cachePlugin,
161
+ errorHandler: errorHandlerPlugin,
162
+ retry: retryPlugin
163
+ };
@@ -0,0 +1,396 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Request = exports.InterceptorManagerImpl = void 0;
7
+ exports.buildURL = buildURL;
8
+ exports.createRequest = void 0;
9
+ exports.createRequestError = createRequestError;
10
+
11
+ exports.defaultExponentialBackoff = defaultExponentialBackoff;
12
+ exports.exponentialBackoffWithMaxRetries = exponentialBackoffWithMaxRetries;
13
+ exports.fixedBackoff = fixedBackoff;
14
+ exports.generateRequestId = generateRequestId;
15
+ exports.linearBackoff = linearBackoff;
16
+ exports.request = void 0;
17
+ exports.serializeParams = serializeParams;
18
+ let requestIdCounter = 0;
19
+ function generateRequestId() {
20
+ return `req_${Date.now()}_${++requestIdCounter}`;
21
+ }
22
+ function serializeParams(params) {
23
+ const searchParams = new URLSearchParams();
24
+ const encode = value => {
25
+ if (value === null || value === void 0) return "";
26
+ if (typeof value === "object") return JSON.stringify(value);
27
+ return String(value);
28
+ };
29
+ const addParam = (key, value) => {
30
+ if (value !== null && value !== void 0) {
31
+ searchParams.append(key, encode(value));
32
+ }
33
+ };
34
+ for (const [key, value] of Object.entries(params)) {
35
+ if (Array.isArray(value)) {
36
+ value.forEach(v => addParam(key, v));
37
+ } else {
38
+ addParam(key, value);
39
+ }
40
+ }
41
+ return searchParams.toString();
42
+ }
43
+ function buildURL(options) {
44
+ const {
45
+ baseURL = "",
46
+ url = "",
47
+ params,
48
+ serializeParams: sp = true
49
+ } = options;
50
+ let fullPath = url;
51
+ if (baseURL) {
52
+ fullPath = url.startsWith("http") ? url : baseURL + url;
53
+ }
54
+ if (params && Object.keys(params).length > 0 && sp) {
55
+ const queryString = serializeParams(params);
56
+ const separator = fullPath.includes("?") ? "&" : "?";
57
+ fullPath += separator + queryString;
58
+ }
59
+ return fullPath;
60
+ }
61
+ function createRequestError(error, config, response) {
62
+ const err = typeof error === "string" ? new Error(error) : error;
63
+ const requestError = {
64
+ name: err.name,
65
+ message: err.message,
66
+ config,
67
+ response,
68
+ requestId: config?.requestId
69
+ };
70
+ if (error instanceof TypeError && error.message.includes("fetch")) {
71
+ requestError.isNetworkError = true;
72
+ requestError.code = "NETWORK_ERROR";
73
+ } else if (config?.signal?.aborted) {
74
+ requestError.isCanceled = true;
75
+ requestError.code = "CANCELED";
76
+ } else if (response) {
77
+ requestError.code = `HTTP_${response.status}`;
78
+ }
79
+ return requestError;
80
+ }
81
+ class InterceptorManagerImpl {
82
+ handlers = [];
83
+ use(onFulfilled, onRejected) {
84
+ this.handlers.push({
85
+ fulfilled: onFulfilled,
86
+ rejected: onRejected
87
+ });
88
+ return this.handlers.length - 1;
89
+ }
90
+ eject(id) {
91
+ if (this.handlers[id]) {
92
+ this.handlers[id] = null;
93
+ }
94
+ }
95
+ clear() {
96
+ this.handlers = [];
97
+ }
98
+ async execute(value) {
99
+ let result = value;
100
+ for (const handler of this.handlers) {
101
+ if (handler) {
102
+ try {
103
+ result = await handler.fulfilled(result);
104
+ } catch (error) {
105
+ if (handler.rejected) {
106
+ result = await handler.rejected(error);
107
+ } else {
108
+ throw error;
109
+ }
110
+ }
111
+ }
112
+ }
113
+ return result;
114
+ }
115
+ }
116
+ exports.InterceptorManagerImpl = InterceptorManagerImpl;
117
+ class Request {
118
+ defaults;
119
+ interceptors;
120
+ abortControllers = /* @__PURE__ */new Map();
121
+ constructor(options = {}) {
122
+ this.defaults = {
123
+ timeout: 3e4,
124
+ credentials: "same-origin",
125
+ responseType: "json",
126
+ serializeParams: true,
127
+ retry: false,
128
+ retryTimes: 3,
129
+ retryDelay: 1e3,
130
+ retryCondition: error => {
131
+ return error.isNetworkError || (error.response?.status ?? 0) >= 500;
132
+ },
133
+ ...options.defaultOptions
134
+ };
135
+ this.interceptors = {
136
+ request: new InterceptorManagerImpl(),
137
+ response: new InterceptorManagerImpl()
138
+ };
139
+ }
140
+ /**
141
+ * 创建请求实例的静态方法
142
+ */
143
+ static create(options) {
144
+ return new Request(options);
145
+ }
146
+ /**
147
+ * 生成 AbortSignal
148
+ */
149
+ createAbortSignal(options) {
150
+ const controller = new AbortController();
151
+ if (options.requestKey) {
152
+ const prevController = this.abortControllers.get(options.requestKey);
153
+ if (prevController) {
154
+ prevController.abort();
155
+ }
156
+ this.abortControllers.set(options.requestKey, controller);
157
+ }
158
+ if (options.timeout) {
159
+ const timeoutId = setTimeout(() => {
160
+ controller.abort(new Error("Request timeout"));
161
+ }, options.timeout);
162
+ controller.signal.addEventListener("abort", () => {
163
+ clearTimeout(timeoutId);
164
+ });
165
+ }
166
+ return controller.signal;
167
+ }
168
+ /**
169
+ * 执行请求
170
+ */
171
+ async request(options) {
172
+ const requestId = generateRequestId();
173
+ const mergedOptions = {
174
+ ...this.defaults,
175
+ ...options,
176
+ requestId
177
+ };
178
+ mergedOptions.fullPath = buildURL(mergedOptions);
179
+ mergedOptions.signal = this.createAbortSignal(mergedOptions);
180
+ let config = await this.interceptors.request.execute(mergedOptions);
181
+ if (config.requestInterceptor) {
182
+ config = await config.requestInterceptor(config);
183
+ }
184
+ const executeRequest = async () => {
185
+ try {
186
+ const fetchOptions = {
187
+ method: config.method || "GET",
188
+ headers: config.headers,
189
+ credentials: config.credentials,
190
+ signal: config.signal
191
+ };
192
+ if (config.data !== void 0 && config.method !== "GET") {
193
+ if (config.responseType === "formdata" || config.data instanceof FormData) {
194
+ fetchOptions.body = config.data;
195
+ } else {
196
+ fetchOptions.body = JSON.stringify(config.data);
197
+ if (!fetchOptions.headers) {
198
+ fetchOptions.headers = {};
199
+ }
200
+ const headers = fetchOptions.headers;
201
+ if (!headers["Content-Type"]) {
202
+ headers["Content-Type"] = "application/json";
203
+ }
204
+ }
205
+ }
206
+ let response;
207
+ try {
208
+ response = await fetch(config.fullPath, fetchOptions);
209
+ } catch (error) {
210
+ throw createRequestError(error, config);
211
+ }
212
+ if (!response.ok) {
213
+ const error = createRequestError(`Request failed with status ${response.status}`, config, response);
214
+ try {
215
+ await this.interceptors.response.execute({
216
+ data: void 0,
217
+ response,
218
+ config,
219
+ requestId
220
+ });
221
+ } catch {}
222
+ throw error;
223
+ }
224
+ let data;
225
+ if (config.rawResponse) {
226
+ data = response;
227
+ } else {
228
+ switch (config.responseType) {
229
+ case "text":
230
+ data = await response.text();
231
+ break;
232
+ case "blob":
233
+ data = await response.blob();
234
+ break;
235
+ case "arraybuffer":
236
+ data = await response.arrayBuffer();
237
+ break;
238
+ case "formdata":
239
+ data = await response.formData();
240
+ break;
241
+ case "json":
242
+ default:
243
+ const text = await response.text();
244
+ data = text ? JSON.parse(text) : null;
245
+ break;
246
+ }
247
+ }
248
+ const requestResponse = {
249
+ data,
250
+ response,
251
+ config,
252
+ requestId
253
+ };
254
+ const finalResponse = await this.interceptors.response.execute(requestResponse);
255
+ return finalResponse;
256
+ } catch (error) {
257
+ const requestError = error;
258
+ const currentRetryCount = config._retryCount ?? 0;
259
+ const maxRetries = config.retryTimes ?? 3;
260
+ const shouldRetry = config.retry && currentRetryCount < maxRetries && (!config.retryCondition || config.retryCondition(requestError));
261
+ if (shouldRetry) {
262
+ const baseDelay = config.retryDelay || 1e3;
263
+ const delayCalculator = config.retryDelayCalculator || defaultExponentialBackoff;
264
+ const delay = delayCalculator(currentRetryCount, baseDelay);
265
+ if (delay < 0) {
266
+ if (config.errorHandler) {
267
+ config.errorHandler(requestError);
268
+ }
269
+ throw requestError;
270
+ }
271
+ await new Promise(resolve => setTimeout(resolve, delay));
272
+ config._retryCount = currentRetryCount + 1;
273
+ return executeRequest();
274
+ }
275
+ if (config.errorHandler) {
276
+ config.errorHandler(requestError);
277
+ }
278
+ throw requestError;
279
+ }
280
+ };
281
+ return executeRequest();
282
+ }
283
+ /**
284
+ * 便捷方法
285
+ */
286
+ get(url, options) {
287
+ return this.request({
288
+ ...options,
289
+ url,
290
+ method: "GET"
291
+ });
292
+ }
293
+ post(url, data, options) {
294
+ return this.request({
295
+ ...options,
296
+ url,
297
+ method: "POST",
298
+ data
299
+ });
300
+ }
301
+ put(url, data, options) {
302
+ return this.request({
303
+ ...options,
304
+ url,
305
+ method: "PUT",
306
+ data
307
+ });
308
+ }
309
+ delete(url, options) {
310
+ return this.request({
311
+ ...options,
312
+ url,
313
+ method: "DELETE"
314
+ });
315
+ }
316
+ patch(url, data, options) {
317
+ return this.request({
318
+ ...options,
319
+ url,
320
+ method: "PATCH",
321
+ data
322
+ });
323
+ }
324
+ head(url, options) {
325
+ return this.request({
326
+ ...options,
327
+ url,
328
+ method: "HEAD"
329
+ });
330
+ }
331
+ options(url, options) {
332
+ return this.request({
333
+ ...options,
334
+ url,
335
+ method: "OPTIONS"
336
+ });
337
+ }
338
+ /**
339
+ * 设置默认配置
340
+ */
341
+ setConfig(config) {
342
+ this.defaults = {
343
+ ...this.defaults,
344
+ ...config
345
+ };
346
+ }
347
+ /**
348
+ * 获取默认配置
349
+ */
350
+ getConfig() {
351
+ return {
352
+ ...this.defaults
353
+ };
354
+ }
355
+ /**
356
+ * 取消所有请求
357
+ */
358
+ cancelAll() {
359
+ this.abortControllers.forEach(controller => {
360
+ controller.abort();
361
+ });
362
+ this.abortControllers.clear();
363
+ }
364
+ /**
365
+ * 取消指定 key 的请求
366
+ */
367
+ cancel(key) {
368
+ const controller = this.abortControllers.get(key);
369
+ if (controller) {
370
+ controller.abort();
371
+ this.abortControllers.delete(key);
372
+ }
373
+ }
374
+ }
375
+ exports.Request = Request;
376
+ function defaultExponentialBackoff(retryCount, defaultDelay = 1e3) {
377
+ const baseDelay = defaultDelay * Math.pow(2, retryCount);
378
+ const jitter = Math.random() * 1e3;
379
+ return Math.min(baseDelay + jitter, 3e4);
380
+ }
381
+ function linearBackoff(retryCount, defaultDelay) {
382
+ return defaultDelay * (retryCount + 1);
383
+ }
384
+ function fixedBackoff(_retryCount, defaultDelay) {
385
+ return defaultDelay;
386
+ }
387
+ function exponentialBackoffWithMaxRetries(retryCount, defaultDelay, maxRetries = 10) {
388
+ if (retryCount >= maxRetries) {
389
+ return -1;
390
+ }
391
+ return defaultExponentialBackoff(retryCount, defaultDelay);
392
+ }
393
+ const request = exports.request = new Request();
394
+ const createRequest = options => new Request(options);
395
+ exports.createRequest = createRequest;
396
+ module.exports = request;
@@ -0,0 +1,111 @@
1
+ import { type RequestOptions, type InternalRequestOptions, type RequestResponse, type RequestError, type RequestInstance, type InterceptorManager, type CreateRequestOptions, type ParamsRecord } from './types';
2
+ export declare function generateRequestId(): string;
3
+ /**
4
+ * 序列化 URL 参数
5
+ */
6
+ export declare function serializeParams(params: ParamsRecord): string;
7
+ /**
8
+ * 构建完整 URL
9
+ */
10
+ export declare function buildURL(options: InternalRequestOptions): string;
11
+ /**
12
+ * 创建请求错误
13
+ */
14
+ export declare function createRequestError(error: Error | string, config?: InternalRequestOptions, response?: Response): RequestError;
15
+ /**
16
+ * 拦截器管理器
17
+ */
18
+ export declare class InterceptorManagerImpl<T> implements InterceptorManager<T> {
19
+ private handlers;
20
+ use(onFulfilled: (value: T) => T | Promise<T>, onRejected?: (error: RequestError) => T | Promise<T>): number;
21
+ eject(id: number): void;
22
+ clear(): void;
23
+ execute(value: T): Promise<T>;
24
+ }
25
+ /**
26
+ * 请求客户端类
27
+ */
28
+ export declare class Request implements RequestInstance {
29
+ defaults: RequestOptions;
30
+ interceptors: {
31
+ request: InterceptorManager<InternalRequestOptions>;
32
+ response: InterceptorManager<RequestResponse<unknown>>;
33
+ };
34
+ private abortControllers;
35
+ constructor(options?: CreateRequestOptions);
36
+ /**
37
+ * 创建请求实例的静态方法
38
+ */
39
+ static create(options?: CreateRequestOptions): Request;
40
+ /**
41
+ * 生成 AbortSignal
42
+ */
43
+ private createAbortSignal;
44
+ /**
45
+ * 执行请求
46
+ */
47
+ request<T = unknown>(options: RequestOptions & {
48
+ url: string;
49
+ }): Promise<RequestResponse<T>>;
50
+ /**
51
+ * 便捷方法
52
+ */
53
+ get<T = unknown>(url: string, options?: RequestOptions): Promise<RequestResponse<T>>;
54
+ post<T = unknown>(url: string, data?: unknown, options?: RequestOptions): Promise<RequestResponse<T>>;
55
+ put<T = unknown>(url: string, data?: unknown, options?: RequestOptions): Promise<RequestResponse<T>>;
56
+ delete<T = unknown>(url: string, options?: RequestOptions): Promise<RequestResponse<T>>;
57
+ patch<T = unknown>(url: string, data?: unknown, options?: RequestOptions): Promise<RequestResponse<T>>;
58
+ head<T = unknown>(url: string, options?: RequestOptions): Promise<RequestResponse<T>>;
59
+ options<T = unknown>(url: string, options?: RequestOptions): Promise<RequestResponse<T>>;
60
+ /**
61
+ * 设置默认配置
62
+ */
63
+ setConfig(config: Partial<RequestOptions>): void;
64
+ /**
65
+ * 获取默认配置
66
+ */
67
+ getConfig(): RequestOptions;
68
+ /**
69
+ * 取消所有请求
70
+ */
71
+ cancelAll(): void;
72
+ /**
73
+ * 取消指定 key 的请求
74
+ */
75
+ cancel(key: string): void;
76
+ }
77
+ /**
78
+ * 默认指数退避延迟计算器 (带随机抖动)
79
+ * @param retryCount 当前重试次数 (从 0 开始)
80
+ * @param defaultDelay 基础延迟时间 (ms)
81
+ * @returns 实际延迟时间 (ms)
82
+ *
83
+ * @example
84
+ * // 第 1 次重试: 1000ms * 2^0 + 随机(0-1000ms) = 1000-2000ms
85
+ * // 第 2 次重试: 1000ms * 2^1 + 随机(0-1000ms) = 2000-3000ms
86
+ * // 第 3 次重试: 1000ms * 2^2 + 随机(0-1000ms) = 4000-5000ms
87
+ */
88
+ export declare function defaultExponentialBackoff(retryCount: number, defaultDelay?: number): number;
89
+ /**
90
+ * 线性退避延迟计算器
91
+ * 每次重试延迟线性增长
92
+ *
93
+ * @example
94
+ * // defaultDelay = 1000
95
+ * // 第 1 次重试: 1000ms
96
+ * // 第 2 次重试: 2000ms
97
+ * // 第 3 次重试: 3000ms
98
+ */
99
+ export declare function linearBackoff(retryCount: number, defaultDelay: number): number;
100
+ /**
101
+ * 固定延迟计算器
102
+ * 每次重试使用相同的延迟
103
+ */
104
+ export declare function fixedBackoff(_retryCount: number, defaultDelay: number): number;
105
+ /**
106
+ * 指数退避带最大重试次数限制
107
+ */
108
+ export declare function exponentialBackoffWithMaxRetries(retryCount: number, defaultDelay: number, maxRetries?: number): number;
109
+ export declare const request: Request;
110
+ export declare const createRequest: (options?: CreateRequestOptions) => Request;
111
+ export default request;