From a76263863b9fa7bdcde065c9b5a3d96c9547a7bd Mon Sep 17 00:00:00 2001 From: carl-chen Date: Fri, 5 Jun 2026 15:35:51 +0800 Subject: [PATCH] chore: translate Chinese comments to English in request module --- __test__/lib/request.test.ts | 8 ++++---- lib/request.ts | 34 +++++++++++++++++----------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/__test__/lib/request.test.ts b/__test__/lib/request.test.ts index eeebe99b..c5686db4 100644 --- a/__test__/lib/request.test.ts +++ b/__test__/lib/request.test.ts @@ -12,7 +12,7 @@ describe('Request', () => { }) // ────────────────────────────────────────────── - // 基础功能 + // Basic features // ────────────────────────────────────────────── test('should append GET params to query string', async () => { @@ -188,7 +188,7 @@ describe('Request', () => { }) // ────────────────────────────────────────────── - // 生命周期回调 + // Lifecycle callbacks // ────────────────────────────────────────────── test('should call onSuccess with response data', async () => { @@ -629,7 +629,7 @@ describe('Request', () => { }, 10000) // ────────────────────────────────────────────── - // thenable: await / Promise.all 支持 + // thenable: await / Promise.all support // ────────────────────────────────────────────── test('should be directly awaitable without .promise', async () => { @@ -666,7 +666,7 @@ describe('Request', () => { }) }) -// ─── 测试辅助函数 ────────────────────────────── +// ─── Test helpers ────────────────────────────── function jsonResponse(data: unknown): Response { return { diff --git a/lib/request.ts b/lib/request.ts index 5535f54b..deb198af 100644 --- a/lib/request.ts +++ b/lib/request.ts @@ -1,7 +1,7 @@ import { objectToQueryString } from './url' import { MIME_TYPES } from './const/http' -// ─── Thenable handle (可 await 的返回结果) ─── +// ─── Thenable handle ─── export interface RequestHandle { then: ( @@ -15,7 +15,7 @@ export interface RequestHandle { abort: () => void } -// ─── 拦截器类型 ─── +// ─── Interceptor types ─── export type RequestInterceptor = ( config: RequestInit @@ -27,14 +27,14 @@ export type ResponseInterceptor = ( export type ErrorInterceptor = (error: unknown) => unknown | Promise -// ─── 缓存配置 ─── +// ─── Cache config ─── export interface CacheConfig { /** Time-to-live in milliseconds. */ ttl: number } -// ─── 请求配置 ─── +// ─── Request config ─── export interface RequestConfig extends RequestInit { params?: Record @@ -53,7 +53,7 @@ export interface RequestConfig extends RequestInit { /** Download progress callback. Receives (loadedBytes, totalBytes). */ onDownloadProgress?: (loaded: number, total: number) => void - // ─── 生命周期回调 ─── + // ─── Lifecycle callbacks ─── onSuccess?: (data: unknown) => void onError?: (error: unknown) => void onAbort?: () => void @@ -147,7 +147,7 @@ export class Request { return () => this.removeInterceptor(this.errorInterceptors, interceptor) } - // ─── 快捷方法 ─── + // ─── Convenience methods ─── get( url: string, @@ -182,7 +182,7 @@ export class Request { this.cacheMap.clear() } - // ─── 核心:request ─── + // ─── Core: request ─── request( url: string, @@ -191,7 +191,7 @@ export class Request { const controller = new AbortController() const promise = this.execute(url, config, controller) - // onAbort 在 abort() 时直接触发 + // onAbort fires directly when abort() is called const handle = { then: (onfulfilled?: any, onrejected?: any) => (promise as Promise).then(onfulfilled, onrejected), @@ -207,7 +207,7 @@ export class Request { return handle } - // ─── 内部:execute ─── + // ─── Internal: execute ─── private buildCacheKey(method: string, url: string): string { return `${method}:${url}` @@ -229,7 +229,7 @@ export class Request { retryDelay = 0, cache, onDownloadProgress, - // 剥离回调,不下传到 RequestInit + // Strip lifecycle callbacks — don't pass them down to RequestInit onSuccess, onError, onAbort: _onAbort, @@ -259,7 +259,7 @@ export class Request { onFinally?.() return dedupData as T } catch { - // 上游失败了,fall through 重新发起 + // Upstream failed, fall through to retry } } @@ -308,7 +308,7 @@ export class Request { } } - // ─── 内部:executeWithRetry ─── + // ─── Internal: executeWithRetry ─── private async executeWithRetry( requestUrl: string, @@ -404,7 +404,7 @@ export class Request { continue } - // 最后一次尝试:执行 errorInterceptors 后 throw + // Last attempt: run errorInterceptors then throw const processedError = await this.runErrorInterceptors(error, [ ...this.errorInterceptors, ...errorInterceptors @@ -420,7 +420,7 @@ export class Request { throw new Error('Unreachable') } - // ─── 进度读取 ─── + // ─── Progress reader ─── private async readResponseWithProgress( response: Response, @@ -458,7 +458,7 @@ export class Request { return new Blob([allChunks.buffer], { type: contentType || undefined }) } - // ─── 构建请求 ─── + // ─── Build request ─── private buildRequestInit( method: string, @@ -542,7 +542,7 @@ export class Request { return Object.fromEntries(entries) } - // ─── 拦截器管道 ─── + // ─── Interceptor pipeline ─── private async runRequestInterceptors( config: RequestInit, @@ -577,7 +577,7 @@ export class Request { return currentError } - // ─── 响应解析 ─── + // ─── Response parsing ─── private async parseResponse(response: Response) { const contentType = response.headers.get('content-type') ?? ''