Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
8ba71a0
feat(projects): refactor theme drawer with tabbed layout for better UX.
Azir-11 Jun 14, 2025
f238fcb
feat(projects): Add current time display option for watermark (#772)
wenyuanw Jun 26, 2025
8439a60
optimize(projects): improve theme drawer responsive width for mobile …
wenyuanw Jun 25, 2025
d37ce04
refactor(types): move Auth and Route namespaces to separate files and…
Azir-11 Jun 28, 2025
b6ac310
feat(projects)!: optimize layout mode, split horizontal mix component…
Azir-11 Jul 3, 2025
b4e5c6d
feat(projects): add 'vertical-hybrid-header-first' layout mode
wenyuanw Jul 12, 2025
6207292
typo(projects): update description of vertical-hybrid-header-first la…
wenyuanw Jul 13, 2025
8b8a208
optimize(projects): improve robustness of second-level menu key logic
wenyuanw Jul 13, 2025
8146858
optimize(projects): optimize theme drawer width
honghuangdc Jul 13, 2025
d6c8142
refactor(projects): remove unnecessary logic in onRouteSwitchWhenLogg…
wenyuanw Jul 15, 2025
50a5cba
optimize(request): enhance request options and response handling with…
honghuangdc Jul 18, 2025
b4e1253
refactor(request)!: remove cancelRequest method and related logic fro…
honghuangdc Jul 18, 2025
abaaa4a
optimize(packages): remove ofetch package
honghuangdc Jul 18, 2025
32b8f99
fix(table): add type annotations for records in useTable hook
honghuangdc Jul 18, 2025
c965140
refactor(hooks): optimize useContext and update useMixMenuContext
honghuangdc Jul 18, 2025
936b834
optimize(hooks): optimize useEcharts
honghuangdc Jul 18, 2025
f83eefb
refactor(request): unify response transformation methods and deprecat…
honghuangdc Jul 19, 2025
3a343ee
optimize(projects): optimize api type file
honghuangdc Jul 19, 2025
8cc5177
refactor(hooks)!: refactor useTable and enhance type definitions
honghuangdc Jul 19, 2025
c962f7b
chore(deps): update deps
honghuangdc Jul 19, 2025
8a7cd59
fix(hooks): correct chart rendering logic in useEcharts
honghuangdc Jul 19, 2025
ee43414
refactor(hooks): streamline column visibility handling in useTable an…
honghuangdc Jul 19, 2025
87adc35
refactor(hooks): remove useSignal hook and update exports
honghuangdc Jul 19, 2025
9ea56c9
fix(packages): fix the parsing logic for stored data to ensure correc…
Lruihao Jul 25, 2025
358e129
feat(hooks): add scrollX computation for total table width in useNaiv…
Lruihao Aug 4, 2025
be8f915
chore(other): update the ESLint validation configuration to support m…
Azir-11 Aug 12, 2025
a55b4dc
feat(components): add the IconTooltip component.
Azir-11 Aug 12, 2025
4005763
feat(components): replace NTooltip with IconTooltip and optimize the …
Azir-11 Aug 12, 2025
29a2a5c
feat(projects): add prompt information for scrolling mode and tab bar…
Azir-11 Aug 12, 2025
d731111
refactor(menu): optimize the margin on the menu
NicholasLD Aug 14, 2025
257f118
feat(projects): support theme preset function.
Azir-11 Aug 21, 2025
100e0ea
style(projects): format code.
Azir-11 Aug 21, 2025
3c0a528
feat(projects): modify the default value of the reset cache policy to…
Azir-11 Aug 24, 2025
805c338
chore(packages): add picomatch to fix scripts
honghuangdc Aug 27, 2025
1213531
chore(deps): update deps
honghuangdc Aug 27, 2025
3d72f95
fix(types): fix proxy types
honghuangdc Aug 27, 2025
b041fdd
chore(deps): update deps
honghuangdc Sep 17, 2025
fd087f5
fix(packages): axios: fix json response. fixed #815
honghuangdc Sep 17, 2025
5be864a
fix(packages): axios: fix json response. fixed #815
honghuangdc Sep 17, 2025
e18d397
docs(projects): add github trendshift info.
Azir-11 Sep 27, 2025
2a0c9f1
docs(projects): add github trendshift info.
Azir-11 Sep 27, 2025
ef7acc6
feat(projects): optimize tabs cache cleaning strategy. close #820.
Azir-11 Oct 1, 2025
61fa4b7
feat(packages): materials support slider-tab. closed #823
CyberShen Oct 2, 2025
91fae50
typo(other): Correct the typos in the Chinese translation and change …
HongxuanG Oct 3, 2025
d567c05
chore(deps): update deps
honghuangdc Oct 13, 2025
d5a3a25
fix(types): fix ts type error
honghuangdc Oct 13, 2025
017440c
docs(projects): add contribution leaderboard
wenyuanw Oct 21, 2025
345aa29
feat(styles): add text-autospace property to improve text layout
wenyuanw Oct 18, 2025
a8d1e5d
feat(projects): support closing tabs with middle mouse button click
wenyuanw Oct 21, 2025
dac5075
fix(styles): show light color scrollbar while dark mode is on
whyang9701 Oct 21, 2025
24c6df5
feat(projects): support set global redius
CyberShen Oct 2, 2025
3549c4d
feat(projects): support set global redius
CyberShen Oct 2, 2025
87a66a4
optimize(projects): optimize radius settings
honghuangdc Oct 25, 2025
6cbf570
chore(deps): update deps
honghuangdc Oct 25, 2025
56ad0df
chore(projects): release v2.0.0-beta.1
honghuangdc Oct 25, 2025
6011557
Merge branch 'v2.0'
honghuangdc Oct 25, 2025
8dc17e6
fix(scripts): update command to use 'npm-check-updates' instead of 'ncu'
honghuangdc Oct 27, 2025
b2c919b
feat(global-tab): add support for switching tabs with right mouse but…
honghuangdc Oct 27, 2025
e471e91
fix(layout): fix getSiderWidth
honghuangdc Oct 27, 2025
5cfb606
chore(projects): release v2.0.0-beta.2
honghuangdc Oct 27, 2025
1d14269
optimize(typings): update component typings
honghuangdc Oct 28, 2025
0b9982b
fix(projects): adjust legend position in line chart options.
Azir-11 Oct 29, 2025
9755c31
feat(projects): compatible with the new Echarts API and optimized sty…
Azir-11 Oct 29, 2025
6010f51
chore(deps): update deps
honghuangdc Oct 29, 2025
232f56f
chore(deps): update deps
honghuangdc Nov 2, 2025
ec792fa
chore(projects): release v2.0.0
honghuangdc Nov 2, 2025
4a9cf6c
fix(types): add missing property in theme presets
taisha Nov 8, 2025
46081c3
feat(docs): update QQ group image in README
honghuangdc Nov 12, 2025
f8dc639
chore(deps): update deps
honghuangdc Nov 16, 2025
bb232bf
fix(docs): update project name in ecosystem section of README
honghuangdc Nov 17, 2025
91a261c
style(projects): modify homepage prompt title to tip.
Azir-11 Nov 24, 2025
c472a94
docs(projects): add link to ecosystem document.
Azir-11 Nov 24, 2025
9da847f
feat(projects): support theme presets to only set partial content.
Azir-11 Nov 29, 2025
c6d97db
optimize(projects): simplify some theme preset configurations.
Azir-11 Nov 29, 2025
73e9a0f
chore(other): remove Prettier's recommendation.
Azir-11 Dec 2, 2025
605173a
feat(projects): support theme perset to override component library p…
Azir-11 Dec 2, 2025
b8a767d
feat(projects): support pinning and unpinning of tabs
hellohooke Dec 3, 2025
9401925
feat(projects): hybrid layout mode auto select first deepest child menu
paynezhuang Dec 3, 2025
7cf4083
chore(deps): update deps
honghuangdc Dec 4, 2025
098cd50
chore(styles): format code
honghuangdc Dec 4, 2025
e675474
chore(projects): release v2.0.1
honghuangdc Dec 4, 2025
64226d9
fix(hooks): update pagination pageSize after data fetch.
Azir-11 Dec 4, 2025
62a43c3
fix(projects): fix the incorrect judgment of home by pin tab.
Azir-11 Dec 4, 2025
ec9f9af
chore(deps): update deps
honghuangdc Dec 22, 2025
5e40b85
chore(projects): release v2.0.2
honghuangdc Dec 23, 2025
5aac540
feat(logo): use new logo
honghuangdc Dec 25, 2025
232e1ac
chore(deps): update deps
honghuangdc Dec 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"antfu.unocss",
"dbaeumer.vscode-eslint",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"lokalise.i18n-ally",
"mhutchie.git-graph",
"mikestead.dotenv",
Expand Down
341 changes: 341 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions README.en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
[![gitee stars](https://gitee.com/honghuangdc/soybean-admin/badge/star.svg)](https://gitee.com/honghuangdc/soybean-admin)
[![gitcode star](https://gitcode.com/soybeanjs/soybean-admin/star/badge.svg)](https://gitcode.com/soybeanjs/soybean-admin)

<a href="https://hellogithub.com/repository/1298f27d5fe54959a16cf9686516ddb3" target="_blank"><img src="https://abroad.hellogithub.com/v1/widgets/recommend.svg?rid=1298f27d5fe54959a16cf9686516ddb3&claim_uid=IiDXWmP4TEntjbV" alt="Featured|HelloGitHub" style="width: 250px; height: 54px;" width="250" height="54" /></a>

<div style="display: flex; gap: 12px; align-items: center;">
<a href="https://trendshift.io/repositories/7963" target="_blank"><img src="https://trendshift.io/api/badge/repositories/7963" alt="soybeanjs%2Fsoybean-admin | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
<a href="https://hellogithub.com/repository/1298f27d5fe54959a16cf9686516ddb3" target="_blank"><img src="https://abroad.hellogithub.com/v1/widgets/recommend.svg?rid=1298f27d5fe54959a16cf9686516ddb3&claim_uid=IiDXWmP4TEntjbV" alt="Featured|HelloGitHub" style="width: 250px; height: 54px;" width="250" height="54" /></a>
</div>

> [!NOTE]
> If you think `SoybeanAdmin` is helpful to you, or you like our project, please give us a ⭐️ on GitHub. Your support is the driving force for us to continue to improve and add new features! Thank you for your support!
Expand Down Expand Up @@ -137,7 +139,7 @@ Refer to the [Code Synchronization](https://docs.soybeanjs.cn/guide/sync) docume

## Ecosystem

- [react-soybean-admin](https://github.com/mufeng889/react-soybean-admin): SoybeanAdmin based version of React.
- [skyroc-admin](https://github.com/Ohh-889/skyroc-admin): SoybeanAdmin's React version implementation.
- [electron-mock-admin](https://github.com/lixin59/electron-mock-api): A Mock Api management system that helps front-end developers quickly implement interface mocks.
- [T-Shell](https://github.com/TheBlindM/T-Shell): A terminal emulator and SSH client with configurable command prompts.
- [pea](https://github.com/haitang1894/pea) : Adopting SpringBoot3.2 + JDK21, MyBatis-Plus, SpringSecurity security framework, etc., suitable for the simple permission system developed by [soybean-admin](https://gitee.com/honghuangdc/soybean-admin).
Expand All @@ -149,6 +151,8 @@ Refer to the [Code Synchronization](https://docs.soybeanjs.cn/guide/sync) docume
- [ba](https://github.com/xiatianYa/Ba-Server): Backend service docking with soybean admin based on goFrame framework, adapted to dynamic routing, and interface authentication permissions.
- [soybean-admin-go](https://github.com/WgoW/soybean-admin-go):A Go backend service developed based on the Gin and GORM frameworks, integrated with the example branch of Soybean Admin. It supports dynamic routing and API permission authentication.

More ecosystem please refer to [Ecosystem](https://docs.soybeanjs.cn/awesome) document.


## How to Contribute

Expand Down Expand Up @@ -178,13 +182,21 @@ Thanks the following people for their contributions. If you want to contribute t
<img src="https://contrib.rocks/image?repo=soybeanjs/soybean-admin" />
</a>

---

Here are the most active contributors from the past year. Thank you all for your support, which has enabled the project's continued development.

<a href="https://openomy.com/soybeanjs/soybean-admin" target="_blank" style="display: block; width: 100%;" align="center">
<img src="https://www.openomy.com/svg?repo=soybeanjs/soybean-admin&chart=list&latestMonth=12" target="_blank" alt="Contribution Leaderboard" style="display: block; width: 100%;" />
</a>

## Communication

`SoybeanAdmin` is a completely open source and free project, helping developers to develop medium and large-scale management systems more conveniently. It also provides WeChat and QQ communication groups. If you have any questions, please feel free to ask in the group.

<div>
<p>QQ Group</p>
<img src="https://soybeanjs-1300612522.cos.ap-guangzhou.myqcloud.com/uPic/qq-soybean-admin-4.jpg" style="width:200px" />
<img src="https://soybeanjs-1300612522.cos.ap-guangzhou.myqcloud.com/uPic/qq-soybean-admin-5.jpg" style="width:200px" />
</div>
<!-- <div>
<p>WeChat Group</p>
Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
[![gitee stars](https://gitee.com/honghuangdc/soybean-admin/badge/star.svg)](https://gitee.com/honghuangdc/soybean-admin)
[![gitcode star](https://gitcode.com/soybeanjs/soybean-admin/star/badge.svg)](https://gitcode.com/soybeanjs/soybean-admin)

<a href="https://hellogithub.com/repository/1298f27d5fe54959a16cf9686516ddb3" target="_blank"><img src="https://abroad.hellogithub.com/v1/widgets/recommend.svg?rid=1298f27d5fe54959a16cf9686516ddb3&claim_uid=IiDXWmP4TEntjbV" alt="Featured|HelloGitHub" style="width: 250px; height: 54px;" width="250" height="54" /></a>
<div style="display: flex; gap: 12px; align-items: center;">
<a href="https://trendshift.io/repositories/7963" target="_blank"><img src="https://trendshift.io/api/badge/repositories/7963" alt="soybeanjs%2Fsoybean-admin | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
<a href="https://hellogithub.com/repository/1298f27d5fe54959a16cf9686516ddb3" target="_blank"><img src="https://abroad.hellogithub.com/v1/widgets/recommend.svg?rid=1298f27d5fe54959a16cf9686516ddb3&claim_uid=IiDXWmP4TEntjbV" alt="Featured|HelloGitHub" style="width: 250px; height: 54px;" width="250" height="54" /></a>
</div>

> [!NOTE]
> 如果您觉得 `SoybeanAdmin`对您有所帮助,或者您喜欢我们的项目,请在 GitHub 上给我们一个 ⭐️。您的支持是我们持续改进和增加新功能的动力!感谢您的支持!
Expand Down Expand Up @@ -162,7 +165,7 @@ pnpm build

## 周边生态

- [react-soybean-admin](https://github.com/mufeng889/react-soybean-admin): 基于SoybeanAdmin的React版本.
- [skyroc-admin](https://github.com/Ohh-889/skyroc-admin): SoybeanAdmin的React版本实现.
- [electron-mock-admin](https://github.com/lixin59/electron-mock-api): 一个 Mock Api 管理系统,帮助前端开发伙伴快速实现接口的 mock。
- [T-Shell](https://github.com/TheBlindM/T-Shell): 是一个可配置命令提示的终端模拟器和 SSH 客户端。
- [pea](https://github.com/haitang1894/pea) : 采用SpringBoot3.2 + JDK21、MyBatis-Plus、SpringSecurity安全框架等,适配 [soybean-admin](https://gitee.com/honghuangdc/soybean-admin) 开发的简单权限系统。
Expand All @@ -174,6 +177,8 @@ pnpm build
- [ba](https://github.com/xiatianYa/Ba-Server): 基于goFrame框架开发的后端服务对接soybean-admin,适配动态路由,接口鉴权限。
- [soybean-admin-go](https://github.com/WgoW/soybean-admin-go):基于gin+gorm框架开发的go语言后端服务对接soybean-admin的example分支,适配动态路由,接口鉴权限。

更多周边生态请翻阅 [周边生态](https://docs.soybeanjs.cn/zh/awesome) 文档。


## 如何贡献

Expand Down Expand Up @@ -205,13 +210,21 @@ pnpm build
<img src="https://contrib.rocks/image?repo=soybeanjs/soybean-admin" />
</a>

---

以下是近一年中活跃度较高的贡献者,感谢各位的支持,让项目得以持续发展。

<a href="https://openomy.com/soybeanjs/soybean-admin" target="_blank" style="display: block; width: 100%;" align="center">
<img src="https://www.openomy.com/svg?repo=soybeanjs/soybean-admin&chart=list&latestMonth=12" target="_blank" alt="Contribution Leaderboard" style="display: block; width: 100%;" />
</a>

## 交流

`SoybeanAdmin` 是完全开源免费的项目,在帮助开发者更方便地进行中大型管理系统开发,同时也提供微信和 QQ 交流群,使用问题欢迎在群内提问。

<div>
<p>QQ交流群</p>
<img src="https://soybeanjs-1300612522.cos.ap-guangzhou.myqcloud.com/uPic/qq-soybean-admin-4.jpg" style="width:200px" />
<img src="https://soybeanjs-1300612522.cos.ap-guangzhou.myqcloud.com/uPic/qq-soybean-admin-5.jpg" style="width:200px" />
</div>
<!-- <div>
<p>微信群</p>
Expand Down
60 changes: 30 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "soybean-admin",
"type": "module",
"version": "1.3.15",
"version": "2.0.2",
"description": "A fresh and elegant admin template, based on Vue3、Vite7、TypeScript、NaiveUI and UnoCSS. 一个基于Vue3、Vite7、TypeScript、NaiveUI and UnoCSS的清新优雅的中后台模版。",
"author": {
"name": "Soybean",
Expand Down Expand Up @@ -54,53 +54,53 @@
"@sa/hooks": "workspace:*",
"@sa/materials": "workspace:*",
"@sa/utils": "workspace:*",
"@vueuse/core": "13.9.0",
"@vueuse/core": "14.1.0",
"clipboard": "2.0.11",
"dayjs": "1.11.18",
"dayjs": "1.11.19",
"defu": "6.1.4",
"echarts": "6.0.0",
"json5": "2.2.3",
"naive-ui": "2.43.1",
"naive-ui": "2.43.2",
"nprogress": "0.2.0",
"pinia": "3.0.3",
"tailwind-merge": "3.3.1",
"vue": "3.5.21",
"pinia": "3.0.4",
"tailwind-merge": "3.4.0",
"vue": "3.5.26",
"vue-draggable-plus": "0.6.0",
"vue-i18n": "11.1.12",
"vue-router": "4.5.1"
"vue-i18n": "11.2.7",
"vue-router": "4.6.4"
},
"devDependencies": {
"@elegant-router/vue": "0.3.8",
"@iconify/json": "2.2.385",
"@iconify/json": "2.2.417",
"@sa/scripts": "workspace:*",
"@sa/uno-preset": "workspace:*",
"@soybeanjs/eslint-config": "1.7.1",
"@types/node": "24.5.1",
"@soybeanjs/eslint-config": "1.7.5",
"@types/node": "25.0.3",
"@types/nprogress": "0.2.3",
"@unocss/eslint-config": "66.5.1",
"@unocss/preset-icons": "66.5.1",
"@unocss/preset-uno": "66.5.1",
"@unocss/transformer-directives": "66.5.1",
"@unocss/transformer-variant-group": "66.5.1",
"@unocss/vite": "66.5.1",
"@vitejs/plugin-vue": "6.0.1",
"@vitejs/plugin-vue-jsx": "5.1.1",
"@unocss/eslint-config": "66.5.10",
"@unocss/preset-icons": "66.5.10",
"@unocss/preset-uno": "66.5.10",
"@unocss/transformer-directives": "66.5.10",
"@unocss/transformer-variant-group": "66.5.10",
"@unocss/vite": "66.5.10",
"@vitejs/plugin-vue": "6.0.3",
"@vitejs/plugin-vue-jsx": "5.1.3",
"consola": "3.4.2",
"eslint": "9.35.0",
"eslint-plugin-vue": "10.4.0",
"eslint": "9.39.2",
"eslint-plugin-vue": "10.6.2",
"kolorist": "1.8.0",
"sass": "1.92.1",
"sass": "1.97.1",
"simple-git-hooks": "2.13.1",
"tsx": "4.20.5",
"typescript": "5.9.2",
"unplugin-icons": "22.3.0",
"unplugin-vue-components": "29.0.0",
"vite": "7.1.5",
"tsx": "4.21.0",
"typescript": "5.9.3",
"unplugin-icons": "22.5.0",
"unplugin-vue-components": "30.0.0",
"vite": "7.3.0",
"vite-plugin-progress": "0.0.7",
"vite-plugin-svg-icons": "2.0.1",
"vite-plugin-vue-devtools": "8.0.2",
"vite-plugin-vue-devtools": "8.0.5",
"vue-eslint-parser": "10.2.0",
"vue-tsc": "3.0.7"
"vue-tsc": "3.2.1"
},
"simple-git-hooks": {
"commit-msg": "pnpm sa git-commit-verify",
Expand Down
6 changes: 3 additions & 3 deletions packages/alova/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sa/alova",
"version": "1.3.15",
"version": "2.0.2",
"exports": {
".": "./src/index.ts",
"./fetch": "./src/fetch.ts",
Expand All @@ -13,8 +13,8 @@
}
},
"dependencies": {
"@alova/mock": "2.0.17",
"@alova/mock": "2.0.18",
"@sa/utils": "workspace:*",
"alova": "3.3.4"
"alova": "3.4.1"
}
}
4 changes: 2 additions & 2 deletions packages/axios/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sa/axios",
"version": "1.3.15",
"version": "2.0.2",
"exports": {
".": "./src/index.ts"
},
Expand All @@ -11,7 +11,7 @@
},
"dependencies": {
"@sa/utils": "workspace:*",
"axios": "1.12.2",
"axios": "1.13.2",
"axios-retry": "4.5.0",
"qs": "6.14.0"
},
Expand Down
62 changes: 29 additions & 33 deletions packages/axios/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } f
import axiosRetry from 'axios-retry';
import { nanoid } from '@sa/utils';
import { createAxiosConfig, createDefaultOptions, createRetryOptions } from './options';
import { transformResponse } from './shared';
import { BACKEND_ERROR_CODE, REQUEST_ID_KEY } from './constant';
import type {
CustomAxiosRequestConfig,
Expand All @@ -13,11 +14,12 @@ import type {
ResponseType
} from './type';

function createCommonRequest<ResponseData = any>(
axiosConfig?: CreateAxiosDefaults,
options?: Partial<RequestOption<ResponseData>>
) {
const opts = createDefaultOptions<ResponseData>(options);
function createCommonRequest<
ResponseData,
ApiData = ResponseData,
State extends Record<string, unknown> = Record<string, unknown>
>(axiosConfig?: CreateAxiosDefaults, options?: Partial<RequestOption<ResponseData, ApiData, State>>) {
const opts = createDefaultOptions<ResponseData, ApiData, State>(options);

const axiosConf = createAxiosConfig(axiosConfig);
const instance = axios.create(axiosConf);
Expand Down Expand Up @@ -52,6 +54,8 @@ function createCommonRequest<ResponseData = any>(
async response => {
const responseType: ResponseType = (response.config?.responseType as ResponseType) || 'json';

await transformResponse(response);

if (responseType !== 'json' || opts.isBackendSuccess(response)) {
return Promise.resolve(response);
}
Expand Down Expand Up @@ -80,14 +84,6 @@ function createCommonRequest<ResponseData = any>(
}
);

function cancelRequest(requestId: string) {
const abortController = abortControllerMap.get(requestId);
if (abortController) {
abortController.abort();
abortControllerMap.delete(requestId);
}
}

function cancelAllRequest() {
abortControllerMap.forEach(abortController => {
abortController.abort();
Expand All @@ -98,7 +94,6 @@ function createCommonRequest<ResponseData = any>(
return {
instance,
opts,
cancelRequest,
cancelAllRequest
};
}
Expand All @@ -109,27 +104,27 @@ function createCommonRequest<ResponseData = any>(
* @param axiosConfig axios config
* @param options request options
*/
export function createRequest<ResponseData = any, State = Record<string, unknown>>(
export function createRequest<ResponseData, ApiData, State extends Record<string, unknown>>(
axiosConfig?: CreateAxiosDefaults,
options?: Partial<RequestOption<ResponseData>>
options?: Partial<RequestOption<ResponseData, ApiData, State>>
) {
const { instance, opts, cancelRequest, cancelAllRequest } = createCommonRequest<ResponseData>(axiosConfig, options);
const { instance, opts, cancelAllRequest } = createCommonRequest<ResponseData, ApiData, State>(axiosConfig, options);

const request: RequestInstance<State> = async function request<T = any, R extends ResponseType = 'json'>(
config: CustomAxiosRequestConfig
) {
const request: RequestInstance<ApiData, State> = async function request<
T extends ApiData = ApiData,
R extends ResponseType = 'json'
>(config: CustomAxiosRequestConfig) {
const response: AxiosResponse<ResponseData> = await instance(config);

const responseType = response.config?.responseType || 'json';

if (responseType === 'json') {
return opts.transformBackendResponse(response);
return opts.transform(response);
}

return response.data as MappedType<R, T>;
} as RequestInstance<State>;
} as RequestInstance<ApiData, State>;

request.cancelRequest = cancelRequest;
request.cancelAllRequest = cancelAllRequest;
request.state = {} as State;

Expand All @@ -144,14 +139,14 @@ export function createRequest<ResponseData = any, State = Record<string, unknown
* @param axiosConfig axios config
* @param options request options
*/
export function createFlatRequest<ResponseData = any, State = Record<string, unknown>>(
export function createFlatRequest<ResponseData, ApiData, State extends Record<string, unknown>>(
axiosConfig?: CreateAxiosDefaults,
options?: Partial<RequestOption<ResponseData>>
options?: Partial<RequestOption<ResponseData, ApiData, State>>
) {
const { instance, opts, cancelRequest, cancelAllRequest } = createCommonRequest<ResponseData>(axiosConfig, options);
const { instance, opts, cancelAllRequest } = createCommonRequest<ResponseData, ApiData, State>(axiosConfig, options);

const flatRequest: FlatRequestInstance<State, ResponseData> = async function flatRequest<
T = any,
const flatRequest: FlatRequestInstance<ResponseData, ApiData, State> = async function flatRequest<
T extends ApiData = ApiData,
R extends ResponseType = 'json'
>(config: CustomAxiosRequestConfig) {
try {
Expand All @@ -160,20 +155,21 @@ export function createFlatRequest<ResponseData = any, State = Record<string, unk
const responseType = response.config?.responseType || 'json';

if (responseType === 'json') {
const data = opts.transformBackendResponse(response);
const data = await opts.transform(response);

return { data, error: null, response };
}

return { data: response.data as MappedType<R, T>, error: null };
return { data: response.data as MappedType<R, T>, error: null, response };
} catch (error) {
return { data: null, error, response: (error as AxiosError<ResponseData>).response };
}
} as FlatRequestInstance<State, ResponseData>;
} as FlatRequestInstance<ResponseData, ApiData, State>;

flatRequest.cancelRequest = cancelRequest;
flatRequest.cancelAllRequest = cancelAllRequest;
flatRequest.state = {} as State;
flatRequest.state = {
...opts.defaultState
} as State;

return flatRequest;
}
Expand Down
Loading