Skip to content

Commit f677b52

Browse files
committed
chore(projects): migrate to oxlint & oxfmt
1 parent f27e75f commit f677b52

File tree

11 files changed

+564
-146
lines changed

11 files changed

+564
-146
lines changed

.oxfmtrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"printWidth": 120,
4+
"singleQuote": true,
5+
"trailingComma": "none",
6+
"arrowParens": "avoid"
7+
}

.oxlintrc.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "./node_modules/oxlint/configuration_schema.json",
3+
"categories": {
4+
"correctness": "error",
5+
"suspicious": "error"
6+
},
7+
"plugins": ["eslint", "typescript", "unicorn", "oxc", "import", "vue"],
8+
"rules": {
9+
"unicorn/consistent-function-scoping": "off",
10+
"unicorn/no-array-reverse": "off",
11+
"unicorn/no-array-sort": "off",
12+
"unicorn/no-empty-file": "off",
13+
"import/no-unassigned-import": "off",
14+
"unicorn/require-module-specifiers": "off",
15+
"vue/prefer-import-from-vue": "off"
16+
}
17+
}

.vscode/extensions.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
"afzalsayed96.icones",
44
"antfu.iconify",
55
"antfu.unocss",
6-
"dbaeumer.vscode-eslint",
76
"editorconfig.editorconfig",
8-
"esbenp.prettier-vscode",
9-
"lokalise.i18n-ally",
107
"mhutchie.git-graph",
118
"mikestead.dotenv",
129
"naumovs.color-highlight",
10+
"oxc.oxc-vscode",
1311
"pkief.material-icon-theme",
14-
"sdras.vue-vscode-snippets",
15-
"vue.volar",
1612
"whtouche.vscode-js-console-utils",
1713
"zhuangtongfa.material-theme"
1814
]

.vscode/settings.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"editor.codeActionsOnSave": {
3-
"source.fixAll.eslint": "explicit",
4-
"source.organizeImports": "never"
3+
"source.fixAll.oxc": "explicit"
54
},
6-
"editor.formatOnSave": false,
7-
"eslint.validate": ["javascript", "typescript", "json", "jsonc"],
8-
"prettier.enable": false
5+
"editor.defaultFormatter": "oxc.oxc-vscode",
6+
"editor.formatOnSave": true
97
}

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Changelog
22

3-
43
## [v0.0.2](https://github.com/soybeanjs/request/compare/v0.0.1...v0.0.2) (2026-02-03)
54

65
###    🐞 Bug Fixes
@@ -28,4 +27,3 @@
2827
###    ❤️ Contributors
2928

3029
[![soybeanjs](https://github.com/soybeanjs.png?size=48)](https://github.com/soybeanjs)  
31-

README.en_US.md

Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ const request = createRequest(
5454
return response.data.result;
5555
},
5656
// Request interceptor
57-
onRequest: async (config) => {
57+
onRequest: async config => {
5858
// Add token
5959
config.headers.Authorization = `Bearer ${getToken()}`;
6060
return config;
6161
},
6262
// Check if backend request is successful
63-
isBackendSuccess: (response) => {
63+
isBackendSuccess: response => {
6464
return response.data.code === 200;
6565
},
6666
// Handle backend failure
@@ -73,7 +73,7 @@ const request = createRequest(
7373
}
7474
},
7575
// Error handling
76-
onError: async (error) => {
76+
onError: async error => {
7777
console.error('Request failed:', error.message);
7878
}
7979
}
@@ -111,16 +111,16 @@ if (error) {
111111

112112
### RequestOption Configuration
113113

114-
| Option | Type | Required | Description |
115-
|--------|------|----------|-------------|
116-
| `transform` | `Function` | Yes | Transform response data to business data |
117-
| `onRequest` | `Function` | No | Request interceptor, can add token, etc. |
118-
| `isBackendSuccess` | `Function` | Yes | Check if backend business logic is successful |
119-
| `onBackendFail` | `Function` | No | Backend failure callback, handle token expiration, etc. |
120-
| `onError` | `Function` | No | Request error handling, show error message, etc. |
121-
| `defaultState` | `Object` | No | Default state object |
122-
| `backendErrorFlag` | `string` | No | Backend error flag, default `'BACKEND_ERROR'` |
123-
| `backendErrorMsg` | `string` | No | Backend error message |
114+
| Option | Type | Required | Description |
115+
| ------------------ | ---------- | -------- | ------------------------------------------------------- |
116+
| `transform` | `Function` | Yes | Transform response data to business data |
117+
| `onRequest` | `Function` | No | Request interceptor, can add token, etc. |
118+
| `isBackendSuccess` | `Function` | Yes | Check if backend business logic is successful |
119+
| `onBackendFail` | `Function` | No | Backend failure callback, handle token expiration, etc. |
120+
| `onError` | `Function` | No | Request error handling, show error message, etc. |
121+
| `defaultState` | `Object` | No | Default state object |
122+
| `backendErrorFlag` | `string` | No | Backend error flag, default `'BACKEND_ERROR'` |
123+
| `backendErrorMsg` | `string` | No | Backend error message |
124124

125125
### Request Processing Flow
126126

@@ -168,7 +168,7 @@ const fileData = await request({
168168
const fileData = await request({
169169
url: '/download/file',
170170
responseType: 'blob',
171-
getFileName: (response) => {
171+
getFileName: response => {
172172
// Custom parsing logic
173173
return 'custom-filename.pdf';
174174
}
@@ -192,6 +192,7 @@ import { downloadFile } from '@soybeanjs/request';
192192
```
193193

194194
Supported file types:
195+
195196
- `blob``FileResponseData<Blob>`
196197
- `arraybuffer``FileResponseData<ArrayBuffer>`
197198
- `stream``FileResponseData<ReadableStream<Uint8Array>>`
@@ -244,26 +245,23 @@ interface CustomState {
244245
userId: number;
245246
}
246247

247-
const request = createRequest(
248-
axiosConfig,
249-
{
250-
defaultState: {
251-
token: '',
252-
userId: 0
253-
} as CustomState,
254-
// ...other config
255-
}
256-
);
248+
const request = createRequest(axiosConfig, {
249+
defaultState: {
250+
token: '',
251+
userId: 0
252+
} as CustomState
253+
// ...other config
254+
});
257255

258256
// Access and modify state
259257
request.state.token = 'new-token';
260258
request.state.userId = 123;
261259

262260
// Use state in hooks
263-
onRequest: (config) => {
261+
onRequest: config => {
264262
config.headers.Authorization = `Bearer ${request.state.token}`;
265263
return config;
266-
}
264+
};
267265
```
268266

269267
### 4. Auto Retry
@@ -274,8 +272,8 @@ const request = createRequest(
274272
baseURL: 'https://api.example.com',
275273
// axios-retry config
276274
retries: 3,
277-
retryDelay: (retryCount) => retryCount * 1000,
278-
retryCondition: (error) => {
275+
retryDelay: retryCount => retryCount * 1000,
276+
retryCondition: error => {
279277
// Only retry on network error or 5xx error
280278
return !error.response || error.response.status >= 500;
281279
}
@@ -302,12 +300,9 @@ interface ApiResponse<T = any> {
302300

303301
// ResponseData: backend raw response type
304302
// ApiData: business data type
305-
const request = createRequest(
306-
axiosConfig,
307-
{
308-
transform: (response: AxiosResponse<ApiResponse>) => response.data.data,
309-
}
310-
);
303+
const request = createRequest(axiosConfig, {
304+
transform: (response: AxiosResponse<ApiResponse>) => response.data.data
305+
});
311306

312307
// Type inference: data type is ApiResponse<User>
313308
const user = await request<User>({
@@ -324,13 +319,12 @@ Parse filename from `Content-Disposition` response header:
324319
```typescript
325320
import { parseContentDisposition } from '@soybeanjs/request';
326321

327-
const filename = parseContentDisposition(
328-
'attachment; filename*=UTF-8\'\'%E6%96%87%E4%BB%B6.pdf'
329-
);
322+
const filename = parseContentDisposition("attachment; filename*=UTF-8''%E6%96%87%E4%BB%B6.pdf");
330323
// '文件.pdf'
331324
```
332325

333326
Supported formats:
327+
334328
- RFC 5987 encoded: `filename*=UTF-8''example%20file.pdf`
335329
- Regular format: `filename="example.pdf"` or `filename=example.pdf`
336330

@@ -365,15 +359,15 @@ const request = createRequest(
365359
return response.data.data;
366360
},
367361
// Request interceptor
368-
onRequest: async (config) => {
362+
onRequest: async config => {
369363
const token = localStorage.getItem('token');
370364
if (token) {
371365
config.headers.Authorization = `Bearer ${token}`;
372366
}
373367
return config;
374368
},
375369
// Check business success
376-
isBackendSuccess: (response) => {
370+
isBackendSuccess: response => {
377371
return response.data.code === 200;
378372
},
379373
// Business failure handling
@@ -389,10 +383,9 @@ const request = createRequest(
389383
response.config.headers.Authorization = `Bearer ${newToken}`;
390384
return instance.request(response.config);
391385
}
392-
393386
},
394387
// Error handling
395-
onError: async (error) => {
388+
onError: async error => {
396389
showMessage(error.response?.data.message || error.message);
397390
}
398391
}
@@ -458,10 +451,7 @@ async function uploadFile(file: File) {
458451
```typescript
459452
import { createFlatRequest } from '@soybeanjs/request';
460453

461-
const flatRequest = createFlatRequest(
462-
axiosConfig,
463-
options
464-
);
454+
const flatRequest = createFlatRequest(axiosConfig, options);
465455

466456
// All requests return { data, error, response }
467457
async function safeGetUser(id: number) {
@@ -488,7 +478,7 @@ Create standard request instance.
488478
function createRequest<ResponseData, ApiData, State>(
489479
axiosConfig?: CreateAxiosDefaults,
490480
options?: Partial<RequestOption<ResponseData, ApiData, State>>
491-
): RequestInstance<ApiData, State>
481+
): RequestInstance<ApiData, State>;
492482
```
493483

494484
### createFlatRequest
@@ -499,17 +489,15 @@ Create flat request instance, no exception thrown.
499489
function createFlatRequest<ResponseData, ApiData, State>(
500490
axiosConfig?: CreateAxiosDefaults,
501491
options?: Partial<RequestOption<ResponseData, ApiData, State>>
502-
): FlatRequestInstance<ResponseData, ApiData, State>
492+
): FlatRequestInstance<ResponseData, ApiData, State>;
503493
```
504494

505495
### Type Definitions
506496

507497
```typescript
508498
// Request instance
509499
interface RequestInstance<ApiData, State> {
510-
<T = ApiData, R extends ResponseType = 'json'>(
511-
config: CustomAxiosRequestConfig<R>
512-
): Promise<MappedType<R, T>>;
500+
<T = ApiData, R extends ResponseType = 'json'>(config: CustomAxiosRequestConfig<R>): Promise<MappedType<R, T>>;
513501
state: State;
514502
}
515503

@@ -573,7 +561,7 @@ The library automatically parses filename from `Content-Disposition` response he
573561
const fileData = await request({
574562
url: '/download',
575563
responseType: 'blob',
576-
getFileName: (response) => {
564+
getFileName: response => {
577565
// Custom parsing logic
578566
return 'my-file.pdf';
579567
}

0 commit comments

Comments
 (0)