Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#2643] refactor: Replace TypeScript with JavaScript in the web (#3728)

Lance Line34c8253cd57
diff --git a/build.gradle.kts b/build.gradle.kts
index ebad670388..dbceeb5083 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -466,7 +466,7 @@ tasks.rat {
"web/dist/**/*",
"web/node_modules/**/*",
"web/src/lib/utils/axios/**/*",
- "web/src/lib/enums/httpEnum.ts",
+ "web/src/lib/enums/httpEnum.js",
"web/src/types/axios.d.ts",
"web/yarn.lock",
"web/package-lock.json",
diff --git a/web/LICENSE b/web/LICENSE
index 2f135a0dd4..96d6ecd174 100644
--- a/web/LICENSE
+++ b/web/LICENSE
@@ -212,6 +212,5 @@
Vben
./src/lib/utils/axios
- ./src/types/axios.d.ts
- ./src/lib/enums/httpEnum.ts
+ ./src/lib/enums/httpEnum.js
./src/lib/utils/index.js (parts of)
diff --git a/web/LICENSE.bin b/web/LICENSE.bin
index 936d321d83..5b0c0e2d0b 100644
--- a/web/LICENSE.bin
+++ b/web/LICENSE.bin
@@ -225,8 +225,7 @@
Vben
./web/lib/utils/axios
- ./web/types/axios.d.ts
- ./web/lib/enums/httpEnum.ts
+ ./web/lib/enums/httpEnum.js
./web/lib/utils/index.js (parts of)
@aashutoshrathi/word-wrap
diff --git a/web/tsconfig.json b/web/jsconfig.json
similarity index 58%
rename from web/tsconfig.json
rename to web/jsconfig.json
index 50b0ae57af..7b7b3f2b88 100644
--- a/web/tsconfig.json
+++ b/web/jsconfig.json
@@ -1,15 +1,9 @@
{
"compilerOptions": {
"paths": {
- "@/*": [
- "./src/*"
- ]
+ "@/*": ["./src/*"]
},
- "lib": [
- "dom",
- "dom.iterable",
- "esnext"
- ],
+ "lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
@@ -27,14 +21,6 @@
}
]
},
- "include": [
- "next-env.d.ts",
- "dist/ui/types/**/*.ts",
- "**/*.ts",
- "**/*.tsx",
- ".next/types/**/*.ts"
- ],
- "exclude": [
- "node_modules"
- ]
+ "include": ["next-env.d.ts", "dist/ui/types/**/*.js", "**/*.js", "**/*.jsx", ".next/types/**/*.js"],
+ "exclude": ["node_modules"]
}
diff --git a/web/src/components/ColumnTypeChip.js b/web/src/components/ColumnTypeChip.js
index bb4a72f04f..d53b49a407 100644
--- a/web/src/components/ColumnTypeChip.js
+++ b/web/src/components/ColumnTypeChip.js
@@ -4,7 +4,7 @@
*/
import { Chip } from '@mui/material'
-import { ColumnTypeColorEnum } from '@/lib/enums/columnTypeEnum'
+import { ColumnTypeColorEnum } from '@/lib/enums/columnTypeEnum.js'
import colors from '@/lib/theme/colors'
import { alpha } from '@/lib/utils/color'
import { isString } from 'lodash-es'
diff --git a/web/src/lib/enums/columnTypeEnum.js b/web/src/lib/enums/columnTypeEnum.js
new file mode 100644
index 0000000000..c1e08a12b1
--- /dev/null
+++ b/web/src/lib/enums/columnTypeEnum.js
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+
+/**
+ * @enum {string}
+ */
+const ColumnTypeColorEnum = Object.freeze({
+ boolean: 'primary',
+ short: 'primary',
+ integer: 'primary',
+ long: 'primary',
+ float: 'primary',
+ double: 'primary',
+ decimal: 'primary',
+ fixed: 'primary',
+
+ date: 'info',
+ time: 'info',
+ timestamp: 'info',
+ timestamp_tz: 'info',
+ interval_day: 'info',
+ interval_year: 'info',
+
+ string: 'warning',
+ char: 'warning',
+ varchar: 'warning',
+
+ byte: 'success',
+ uuid: 'success',
+ binary: 'success'
+})
+
+export { ColumnTypeColorEnum }
diff --git a/web/src/lib/enums/columnTypeEnum.ts b/web/src/lib/enums/columnTypeEnum.ts
deleted file mode 100644
index 115b4dab39..0000000000
--- a/web/src/lib/enums/columnTypeEnum.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2024 Datastrato Pvt Ltd.
- * This software is licensed under the Apache License version 2.
- */
-
-export enum ColumnTypeColorEnum {
- boolean = 'primary',
- short = 'primary',
- integer = 'primary',
- long = 'primary',
- float = 'primary',
- double = 'primary',
- decimal = 'primary',
- fixed = 'primary',
-
- date = 'info',
- time = 'info',
- timestamp = 'info',
- timestamp_tz = 'info',
- interval_day = 'info',
- interval_year = 'info',
-
- string = 'warning',
- char = 'warning',
- varchar = 'warning',
-
- byte = 'success',
- uuid = 'success',
- binary = 'success'
-}
diff --git a/web/src/lib/enums/httpEnum.ts b/web/src/lib/enums/httpEnum.js
similarity index 66%
rename from web/src/lib/enums/httpEnum.ts
rename to web/src/lib/enums/httpEnum.js
index 4bd15de1ed..ba379b841c 100644
--- a/web/src/lib/enums/httpEnum.ts
+++ b/web/src/lib/enums/httpEnum.js
@@ -20,28 +20,35 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-*/
+ */
+
+/**
+ * @enum {string}
+ */
+const ContentTypeEnum = Object.freeze({
+ JSON: 'application/json;charset=UTF-8',
+ FORM_URLENCODED: 'application/x-www-form-urlencoded;charset=UTF-8',
+ FORM_DATA: 'multipart/form-data;charset=UTF-8'
+})
/**
- * Referred from src/enums/httpEnum.ts
+ * @enum {string}
*/
+const RequestEnum = Object.freeze({
+ GET: 'GET',
+ POST: 'POST',
+ PUT: 'PUT',
+ DELETE: 'DELETE'
+})
-export enum ContentTypeEnum {
- JSON = 'application/json;charset=UTF-8',
- FORM_URLENCODED = 'application/x-www-form-urlencoded;charset=UTF-8',
- FORM_DATA = 'multipart/form-data;charset=UTF-8'
-}
-
-export enum RequestEnum {
- GET = 'GET',
- POST = 'POST',
- PUT = 'PUT',
- DELETE = 'DELETE'
-}
-
-export enum ResultEnum {
- SUCCESS = 0,
- ERROR = -1,
- TIMEOUT = 401,
- TYPE = 'success'
-}
+/**
+ * @enum {number|string}
+ */
+const ResultEnum = Object.freeze({
+ SUCCESS: 0,
+ ERROR: -1,
+ TIMEOUT: 401,
+ TYPE: 'success'
+})
+
+export { ContentTypeEnum, RequestEnum, ResultEnum }
diff --git a/web/src/lib/utils/axios/Axios.ts b/web/src/lib/utils/axios/Axios.js
similarity index 70%
rename from web/src/lib/utils/axios/Axios.ts
rename to web/src/lib/utils/axios/Axios.js
index e96b41d605..92411b012f 100644
--- a/web/src/lib/utils/axios/Axios.ts
+++ b/web/src/lib/utils/axios/Axios.js
@@ -26,9 +26,6 @@ SOFTWARE.
* Referred from src/utils/http/axios/Axios.ts
*/
-import type { AxiosRequestConfig, AxiosInstance, AxiosResponse, AxiosError, InternalAxiosRequestConfig } from 'axios'
-import type { RequestOptions, Result, UploadFileParams } from '@/types/axios'
-import type { CreateAxiosOptions } from './axiosTransform'
import axios from 'axios'
import qs from 'qs'
import { AxiosCanceler } from './axiosCancel'
@@ -38,14 +35,38 @@ import { ContentTypeEnum, RequestEnum } from '../../enums/httpEnum'
export * from './axiosTransform'
+/**
+ * @typedef {import('axios').AxiosRequestConfig} AxiosRequestConfig
+ * @typedef {import('axios').AxiosInstance} AxiosInstance
+ * @typedef {import('axios').AxiosResponse} AxiosResponse
+ * @typedef {import('axios').AxiosError} AxiosError
+ * @typedef {import('axios').InternalAxiosRequestConfig} InternalAxiosRequestConfig
+ * @typedef {import('@/types/axios').RequestOptions} RequestOptions
+ * @typedef {import('@/types/axios').Result} Result
+ * @typedef {import('@/types/axios').UploadFileParams} UploadFileParams
+ * @typedef {import('./axiosTransform').CreateAxiosOptions} CreateAxiosOptions
+ */
+
/**
* @description: axios module
*/
-export class NextAxios {
- private axiosInstance: AxiosInstance
- private readonly options: CreateAxiosOptions
+class NextAxios {
+ /**
+ * @type {AxiosInstance}
+ * @private
+ */
+ axiosInstance
+
+ /**
+ * @type {CreateAxiosOptions}
+ * @readonly
+ */
+ options
- constructor(options: CreateAxiosOptions) {
+ /**
+ * @param {CreateAxiosOptions} options
+ */
+ constructor(options) {
this.options = options
this.axiosInstance = axios.create(options)
this.setupInterceptors()
@@ -53,25 +74,31 @@ export class NextAxios {
/**
* @description: Create axios instance
+ * @private
+ * @param {CreateAxiosOptions} config
*/
- private createAxios(config: CreateAxiosOptions): void {
+ createAxios(config) {
this.axiosInstance = axios.create(config)
}
- private getTransform() {
+ getTransform() {
const { transform } = this.options
return transform
}
- getAxios(): AxiosInstance {
+ /**
+ * @returns {AxiosInstance}
+ */
+ getAxios() {
return this.axiosInstance
}
/**
* @description: Reconfigure axios
+ * @param {CreateAxiosOptions} config
*/
- configAxios(config: CreateAxiosOptions) {
+ configAxios(config) {
if (!this.axiosInstance) {
return
}
@@ -80,8 +107,9 @@ export class NextAxios {
/**
* @description: Set general header
+ * @param {Object} headers
*/
- setHeader(headers: any): void {
+ setHeader(headers) {
if (!this.axiosInstance) {
return
}
@@ -90,8 +118,9 @@ export class NextAxios {
/**
* @description: Interceptor configuration
+ * @private
*/
- private setupInterceptors() {
+ setupInterceptors() {
const {
axiosInstance,
options: { transform }
@@ -105,9 +134,9 @@ export class NextAxios {
const axiosCanceler = new AxiosCanceler()
// ** Request interceptor configuration processing
- this.axiosInstance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
+ this.axiosInstance.interceptors.request.use(config => {
// ** If cancel repeat request is turned on, then cancel repeat request is prohibited
- const requestOptions = (config as unknown as any).requestOptions ?? this.options.requestOptions
+ const requestOptions = config.requestOptions ?? this.options.requestOptions
const ignoreCancelToken = requestOptions?.ignoreCancelToken ?? true
!ignoreCancelToken && axiosCanceler.addPending(config)
@@ -125,7 +154,7 @@ export class NextAxios {
this.axiosInstance.interceptors.request.use(undefined, requestInterceptorsCatch)
// ** Response result interceptor processing
- this.axiosInstance.interceptors.response.use((res: AxiosResponse<any>) => {
+ this.axiosInstance.interceptors.response.use(res => {
res && axiosCanceler.removePending(res.config)
if (responseInterceptors && isFunction(responseInterceptors)) {
res = responseInterceptors(res)
@@ -144,8 +173,12 @@ export class NextAxios {
/**
* @description: File Upload
+ * @template T
+ * @param {AxiosRequestConfig} config
+ * @param {UploadFileParams} params
+ * @returns {Promise<T>}
*/
- uploadFile<T = any>(config: AxiosRequestConfig, params: UploadFileParams) {
+ uploadFile(config, params) {
const formData = new window.FormData()
const customFilename = params.name || 'file'
@@ -157,7 +190,7 @@ export class NextAxios {
if (params.data) {
Object.keys(params.data).forEach(key => {
- const value = params.data![key]
+ const value = params.data[key]
if (Array.isArray(value)) {
value.forEach(item => {
formData.append(`${key}[]`, item)
@@ -166,11 +199,11 @@ export class NextAxios {
return
}
- formData.append(key, params.data![key])
+ formData.append(key, params.data[key])
})
}
- return this.axiosInstance.request<T>({
+ return this.axiosInstance.request({
...config,
method: 'POST',
data: formData,
@@ -182,7 +215,7 @@ export class NextAxios {
}
// ** support form-data
- supportFormData(config: AxiosRequestConfig) {
+ supportFormData(config) {
const headers = config.headers || this.options.headers
const contentType = headers?.['Content-Type'] || headers?.['content-type']
@@ -200,24 +233,54 @@ export class NextAxios {
}
}
- get<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T> {
+ /**
+ * @template T
+ * @param {AxiosRequestConfig} config
+ * @param {RequestOptions} [options]
+ * @returns {Promise<T>}
+ */
+ get(config, options) {
return this.request({ ...config, method: 'GET' }, options)
}
- post<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T> {
+ /**
+ * @template T
+ * @param {AxiosRequestConfig} config
+ * @param {RequestOptions} [options]
+ * @returns {Promise<T>}
+ */
+ post(config, options) {
return this.request({ ...config, method: 'POST' }, options)
}
- put<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T> {
+ /**
+ * @template T
+ * @param {AxiosRequestConfig} config
+ * @param {RequestOptions} [options]
+ * @returns {Promise<T>}
+ */
+ put(config, options) {
return this.request({ ...config, method: 'PUT' }, options)
}
- delete<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T> {
+ /**
+ * @template T
+ * @param {AxiosRequestConfig} config
+ * @param {RequestOptions} [options]
+ * @returns {Promise<T>}
+ */
+ delete(config, options) {
return this.request({ ...config, method: 'DELETE' }, options)
}
- request<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T> {
- let conf: CreateAxiosOptions = cloneDeep(config)
+ /**
+ * @template T
+ * @param {AxiosRequestConfig} config
+ * @param {RequestOptions} [options]
+ * @returns {Promise<T>}
+ */
+ request(config, options) {
+ let conf = cloneDeep(config)
if (config.cancelToken) {
conf.cancelToken = config.cancelToken
}
@@ -230,7 +293,7 @@ export class NextAxios {
const { requestOptions } = this.options
- const opt: RequestOptions = Object.assign({}, requestOptions, options)
+ const opt = Object.assign({}, requestOptions, options)
const { beforeRequestHook, requestCatchHook, transformResponseHook } = transform || {}
if (beforeRequestHook && isFunction(beforeRequestHook)) {
@@ -242,8 +305,8 @@ export class NextAxios {
return new Promise((resolve, reject) => {
this.axiosInstance
- .request<any, AxiosResponse<Result>>(conf)
- .then((res: AxiosResponse<Result>) => {
+ .request(conf)
+ .then(res => {
if (transformResponseHook && isFunction(transformResponseHook)) {
try {
const ret = transformResponseHook(res, opt)
@@ -254,9 +317,9 @@ export class NextAxios {
return
}
- resolve(res as unknown as Promise<T>)
+ resolve(res)
})
- .catch((e: Error | AxiosError) => {
+ .catch(e => {
if (requestCatchHook && isFunction(requestCatchHook)) {
reject(requestCatchHook(e, opt))
@@ -270,3 +333,5 @@ export class NextAxios {
})
}
}
+
+export { NextAxios }
diff --git a/web/src/lib/utils/axios/axiosCancel.ts b/web/src/lib/utils/axios/axiosCancel.js
similarity index 80%
rename from web/src/lib/utils/axios/axiosCancel.ts
rename to web/src/lib/utils/axios/axiosCancel.js
index ac4413a442..3a009d7001 100644
--- a/web/src/lib/utils/axios/axiosCancel.ts
+++ b/web/src/lib/utils/axios/axiosCancel.js
@@ -20,22 +20,26 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-*/
+ */
+
+import axios from 'axios'
/**
- * Referred from src/utils/http/axios/axiosCancel.ts
+ * @typedef {import('axios').AxiosRequestConfig} AxiosRequestConfig
*/
-import type { AxiosRequestConfig } from 'axios'
-
-const pendingMap = new Map<string, AbortController>()
+const pendingMap = new Map()
-const getPendingUrl = (config: AxiosRequestConfig): string => {
+/**
+ * @param {AxiosRequestConfig} config
+ * @returns {string}
+ */
+const getPendingUrl = config => {
return [config.method, config.url].join('&')
}
-export class AxiosCanceler {
- public addPending(config: AxiosRequestConfig): void {
+class AxiosCanceler {
+ addPending(config) {
this.removePending(config)
const url = getPendingUrl(config)
const controller = new AbortController()
@@ -45,7 +49,7 @@ export class AxiosCanceler {
}
}
- public removeAllPending(): void {
+ removeAllPending() {
pendingMap.forEach(abortController => {
if (abortController) {
abortController.abort()
@@ -54,7 +58,7 @@ export class AxiosCanceler {
this.reset()
}
- public removePending(config: AxiosRequestConfig): void {
+ removePending(config) {
const url = getPendingUrl(config)
if (pendingMap.has(url)) {
const abortController = pendingMap.get(url)
@@ -65,7 +69,9 @@ export class AxiosCanceler {
}
}
- public reset(): void {
+ reset() {
pendingMap.clear()
}
}
+
+export { AxiosCanceler }
diff --git a/web/src/lib/utils/axios/axiosRetry.ts b/web/src/lib/utils/axios/axiosRetry.js
similarity index 77%
rename from web/src/lib/utils/axios/axiosRetry.ts
rename to web/src/lib/utils/axios/axiosRetry.js
index 5082cc3879..a86f05d42f 100644
--- a/web/src/lib/utils/axios/axiosRetry.ts
+++ b/web/src/lib/utils/axios/axiosRetry.js
@@ -20,17 +20,27 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-*/
+ */
/**
* Referred from src/utils/http/axios/axiosRetry.ts
*/
-import { AxiosError, AxiosInstance } from 'axios'
+import axios from 'axios'
-export class AxiosRetry {
- retry(axiosInstance: AxiosInstance, error: AxiosError) {
- const { config }: any = error.response
+/**
+ * @typedef {import('axios').AxiosError} AxiosError
+ * @typedef {import('axios').AxiosInstance} AxiosInstance
+ */
+
+class AxiosRetry {
+ /**
+ * @param {AxiosInstance} axiosInstance
+ * @param {AxiosError} error
+ * @returns {Promise}
+ */
+ retry(axiosInstance, error) {
+ const { config } = error.response
const { waitTime, count } = config?.requestOptions?.retryRequest ?? {}
config.__retryCount = config.__retryCount || 0
if (config.__retryCount >= count) {
@@ -43,7 +53,13 @@ export class AxiosRetry {
return this.delay(waitTime).then(() => axiosInstance(config))
}
- private delay(waitTime: number) {
+ /**
+ * @param {number} waitTime
+ * @returns {Promise}
+ */
+ delay(waitTime) {
return new Promise(resolve => setTimeout(resolve, waitTime))
}
}
+
+export { AxiosRetry }
diff --git a/web/src/lib/utils/axios/axiosTransform.js b/web/src/lib/utils/axios/axiosTransform.js
new file mode 100644
index 0000000000..76e5e3acce
--- /dev/null
+++ b/web/src/lib/utils/axios/axiosTransform.js
@@ -0,0 +1,102 @@
+/*
+MIT License
+
+Copyright (c) 2020-present, Vben
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+ */
+
+/**
+ * Referred from src/utils/http/axios/axiosTransform.ts
+ */
+
+/**
+ * @typedef {import('axios').AxiosInstance} AxiosInstance
+ * @typedef {import('axios').AxiosRequestConfig} AxiosRequestConfig
+ * @typedef {import('axios').AxiosResponse} AxiosResponse
+ * @typedef {import('axios').InternalAxiosRequestConfig} InternalAxiosRequestConfig
+ * @typedef {import('@/types/axios').RequestOptions} RequestOptions
+ * @typedef {import('@/types/axios').Result} Result
+ */
+
+/**
+ * @typedef {AxiosRequestConfig} CreateAxiosOptions
+ * @property {string} [authenticationScheme]
+ * @property {AxiosTransform} [transform]
+ * @property {RequestOptions} [requestOptions]
+ */
+
+/**
+ * Data processing class, can be configured according to the project
+ */
+class AxiosTransform {
+ /**
+ * A function that is called before a request is sent. It can modify the request configuration as needed.
+ * @param {AxiosRequestConfig} config
+ * @param {RequestOptions} options
+ * @returns {AxiosRequestConfig}
+ */
+ beforeRequestHook(config, options) {}
+
+ /**
+ * Processing response data
+ * @param {AxiosResponse<Result>} res
+ * @param {RequestOptions} options
+ * @returns {any}
+ */
+ transformResponseHook(res, options) {}
+
+ /**
+ * Handling of failed requests
+ * @param {Error} e
+ * @param {RequestOptions} options
+ * @returns {Promise<any>}
+ */
+ requestCatchHook(e, options) {}
+
+ /**
+ * Interceptor before request
+ * @param {InternalAxiosRequestConfig} config
+ * @param {CreateAxiosOptions} options
+ * @returns {InternalAxiosRequestConfig}
+ */
+ requestInterceptors(config, options) {}
+
+ /**
+ * Interceptor after request
+ * @param {AxiosResponse<any>} res
+ * @returns {AxiosResponse<any>}
+ */
+ responseInterceptors(res) {}
+
+ /**
+ * Interceptors error handing before request
+ * @param {Error} error
+ */
+ requestInterceptorsCatch(error) {}
+
+ /**
+ * Interceptors error handing after request
+ * @param {AxiosInstance} axiosInstance
+ * @param {Error} error
+ */
+ responseInterceptorsCatch(axiosInstance, error) {}
+}
+
+export { AxiosTransform }
diff --git a/web/src/lib/utils/axios/axiosTransform.ts b/web/src/lib/utils/axios/axiosTransform.ts
deleted file mode 100644
index 5c467d8624..0000000000
--- a/web/src/lib/utils/axios/axiosTransform.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
-MIT License
-
-Copyright (c) 2020-present, Vben
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
-
-/**
- * Referred from src/utils/http/axios/axiosTransform.ts
- */
-
-// ** Data processing class, can be configured according to the project
-import type { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
-import type { RequestOptions, Result } from '@/types/axios'
-
-export interface CreateAxiosOptions extends AxiosRequestConfig {
- authenticationScheme?: string
- transform?: AxiosTransform
- requestOptions?: RequestOptions
-}
-
-export abstract class AxiosTransform {
- // ** A function that is called before a request is sent. It can modify the request configuration as needed.
- beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig
-
- /**
- * @description: Processing response data
- */
- transformResponseHook?: (res: AxiosResponse<Result>, options: RequestOptions) => any
-
- /**
- * @description: Handling of failed requests
- */
- requestCatchHook?: (e: Error, options: RequestOptions) => Promise<any>
-
- /**
- * @description: Interceptor before request
- */
- requestInterceptors?: (config: InternalAxiosRequestConfig, options: CreateAxiosOptions) => InternalAxiosRequestConfig
-
- /**
- * @description: Interceptor after request
- */
- responseInterceptors?: (res: AxiosResponse<any>) => AxiosResponse<any>
-
- /**
- * @description: Interceptors error handing before request
- */
- requestInterceptorsCatch?: (error: Error) => void
-
- /**
- * @description: Interceptors error handing after request
- */
- responseInterceptorsCatch?: (axiosInstance: AxiosInstance, error: Error) => void
-}
diff --git a/web/src/lib/utils/axios/checkStatus.ts b/web/src/lib/utils/axios/checkStatus.js
similarity index 89%
rename from web/src/lib/utils/axios/checkStatus.ts
rename to web/src/lib/utils/axios/checkStatus.js
index b4ceb92e39..ea215adf5d 100644
--- a/web/src/lib/utils/axios/checkStatus.ts
+++ b/web/src/lib/utils/axios/checkStatus.js
@@ -20,16 +20,24 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-*/
+ */
/**
* Referred from src/utils/http/axios/checkStatus.ts
*/
-import type { ErrorMessageMode } from '@/types/axios'
+/**
+ * @typedef {'none' | 'modal' | 'message' | undefined} ErrorMessageMode
+ */
+
import toast from 'react-hot-toast'
-export function checkStatus(status: number, msg: string, errorMessageMode: ErrorMessageMode = 'message'): void {
+/**
+ * @param {number} status
+ * @param {string} msg
+ * @param {ErrorMessageMode} [errorMessageMode='message']
+ */
+export function checkStatus(status, msg, errorMessageMode = 'message') {
let errMessage = ''
switch (status) {
@@ -39,9 +47,9 @@ export function checkStatus(status: number, msg: string, errorMessageMode: Error
case 401:
// ** reserve error message
- // errMessage = msg || 'The user does not have permission (token, user name, password error or expired)!'
-
+ // errMessage = msg || 'The user does not have permission (token, user name, password error or expired)!';
break
+
case 403:
errMessage = 'The user is authorized, but access is forbidden!'
break
diff --git a/web/src/lib/utils/axios/helper.ts b/web/src/lib/utils/axios/helper.js
similarity index 85%
rename from web/src/lib/utils/axios/helper.ts
rename to web/src/lib/utils/axios/helper.js
index 18a1d0c6a7..ba3291b4b4 100644
--- a/web/src/lib/utils/axios/helper.ts
+++ b/web/src/lib/utils/axios/helper.js
@@ -20,7 +20,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-*/
+ */
/**
* Referred from src/utils/http/axios/helper.ts
@@ -30,9 +30,13 @@ import { isObject, isString } from '@/lib/utils/is'
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'
-export function joinTimestamp<T extends boolean>(join: boolean, restful: T): T extends true ? string : object
-
-export function joinTimestamp(join: boolean, restful = false): string | object {
+/**
+ * @template T
+ * @param {boolean} join
+ * @param {T} restful
+ * @returns {T extends true ? string : object}
+ */
+export function joinTimestamp(join, restful = false) {
if (!join) {
return restful ? '' : {}
}
@@ -44,10 +48,15 @@ export function joinTimestamp(join: boolean, restful = false): string | object {
return { _t: now }
}
+/**
+ * @typedef {Object.<string, any>} Recordable
+ */
+
/**
* @description: Format request parameter time
+ * @param {Recordable} params
*/
-export function formatRequestDate(params: Recordable) {
+export function formatRequestDate(params) {
if (Object.prototype.toString.call(params) !== '[object Object]') {
return
}
@@ -62,7 +71,7 @@ export function formatRequestDate(params: Recordable) {
if (value) {
try {
params[key] = isString(value) ? value.trim() : value
- } catch (error: any) {
+ } catch (error) {
throw new Error(error)
}
}
diff --git a/web/src/lib/utils/axios/index.ts b/web/src/lib/utils/axios/index.js
similarity index 87%
rename from web/src/lib/utils/axios/index.ts
rename to web/src/lib/utils/axios/index.js
index d4cfbddd33..5c49b32f01 100644
--- a/web/src/lib/utils/axios/index.ts
+++ b/web/src/lib/utils/axios/index.js
@@ -20,29 +20,24 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-*/
-
+ */
/**
* Referred from src/utils/http/axios/index.ts
*/
-// ** The axios configuration can be changed according to the project, just change the file, other files can be left unchanged
-
-import type { AxiosInstance, AxiosResponse } from 'axios'
+import axios from 'axios'
import { clone } from 'lodash-es'
-import type { RequestOptions, Result } from '@/types/axios'
-import type { AxiosTransform, CreateAxiosOptions } from './axiosTransform'
-import { NextAxios } from './Axios'
-import { checkStatus } from './checkStatus'
import toast from 'react-hot-toast'
+import qs from 'qs'
import { RequestEnum, ResultEnum, ContentTypeEnum } from '@/lib/enums/httpEnum'
import { isString, isUndefined, isNull, isEmpty } from '@/lib/utils/is'
import { setObjToUrlParams, deepMerge } from '@/lib/utils'
import { joinTimestamp, formatRequestDate } from './helper'
import { AxiosRetry } from './axiosRetry'
-import axios from 'axios'
+import { AxiosCanceler } from './axiosCancel'
+import { NextAxios } from './Axios'
+import { checkStatus } from './checkStatus'
import { useAuth as Auth } from '../../provider/session'
-import qs from 'qs'
let isRefreshing = false
@@ -64,11 +59,14 @@ const resetToLoginState = () => {
/**
* @description: Data processing to facilitate the distinction of multiple processing methods
*/
-const transform: AxiosTransform = {
+const transform = {
/**
* @description: Handling response data. If the data does not conform to the expected format, an error can be thrown directly
+ * @param {AxiosResponse<Result>} res
+ * @param {RequestOptions} options
+ * @returns {any}
*/
- transformResponseHook: (res: AxiosResponse<Result>, options: RequestOptions) => {
+ transformResponseHook: (res, options) => {
const { isTransformResponse, isReturnNativeResponse } = options
// ** Whether to return the native response headers, for example: use this property when you need to access the response headers
@@ -112,7 +110,6 @@ const transform: AxiosTransform = {
case ResultEnum.TIMEOUT:
timeoutMsg = 'Login timed out, please log in again!'
Auth().logout()
-
break
default:
if (message) {
@@ -130,6 +127,11 @@ const transform: AxiosTransform = {
},
// ** Handling Configuration Prior to Request
+ /**
+ * @param {InternalAxiosRequestConfig} config
+ * @param {RequestOptions} options
+ * @returns {InternalAxiosRequestConfig}
+ */
beforeRequestHook: (config, options) => {
const { apiUrl, joinPrefix, joinParamsToUrl, formatDate, joinTime = true, urlPrefix } = options
@@ -168,7 +170,7 @@ const transform: AxiosTransform = {
// config.params = undefined
}
if (joinParamsToUrl) {
- config.url = setObjToUrlParams(config.url as string, Object.assign({}, config.params, config.data))
+ config.url = setObjToUrlParams(config.url, Object.assign({}, config.params, config.data))
}
} else {
// ** Supporting RESTful Style
@@ -181,37 +183,40 @@ const transform: AxiosTransform = {
},
/**
- * @description: Interceptor Handling of Requests
+ * @param {InternalAxiosRequestConfig} config
+ * @param {CreateAxiosOptions} options
+ * @returns {InternalAxiosRequestConfig}
*/
requestInterceptors: (config, options) => {
// ** Pre-Request Configuration Handling
const token = localStorage.getItem('accessToken')
- if (token && (config as Recordable)?.requestOptions?.withToken !== false) {
+ if (token && config?.requestOptions?.withToken !== false) {
// ** jwt token
- ;(config as Recordable).headers.Authorization = options.authenticationScheme
- ? `${options.authenticationScheme} ${token}`
- : token
+ config.headers.Authorization = options.authenticationScheme ? `${options.authenticationScheme} ${token}` : token
}
return config
},
/**
- * @description: Interceptor Handling of Responses
+ * @param {AxiosResponse<any>} res
+ * @returns {AxiosResponse<any>}
*/
- responseInterceptors: (res: AxiosResponse<any>) => {
+ responseInterceptors: res => {
return res
},
/**
- * @description: Error Response Handling
+ * @param {AxiosInstance} axiosInstance
+ * @param {any} error
+ * @returns {Promise<any>}
*/
- responseInterceptorsCatch: (axiosInstance: AxiosInstance, error: any) => {
+ responseInterceptorsCatch: (axiosInstance, error) => {
const { response, code, message, config: originConfig } = error || {}
const errorMessageMode = originConfig?.requestOptions?.errorMessageMode || 'none'
- const msg: string = response?.data?.error?.message ?? response?.data?.message ?? ''
- const err: string = error?.toString?.() ?? ''
+ const msg = response?.data?.error?.message ?? response?.data?.message ?? ''
+ const err = error?.toString?.() ?? ''
let errMessage = ''
if (axios.isCancel(error)) {
@@ -236,7 +241,7 @@ const transform: AxiosTransform = {
return Promise.reject(error)
}
} catch (error) {
- throw new Error(error as unknown as string)
+ throw new Error(error)
}
checkStatus(error?.response?.status, msg, errorMessageMode)
@@ -283,7 +288,11 @@ const transform: AxiosTransform = {
}
}
-function createAxios(opt?: Partial<CreateAxiosOptions>) {
+/**
+ * @param {Partial<CreateAxiosOptions>} [opt]
+ * @returns {NextAxios}
+ */
+function createAxios(opt) {
return new NextAxios(
deepMerge(
{
diff --git a/web/src/types/axios.d.ts b/web/src/types/axios.d.ts
deleted file mode 100644
index fdecf9d0aa..0000000000
--- a/web/src/types/axios.d.ts
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
-MIT License
-
-Copyright (c) 2020-present, Vben
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
-
-/**
- * Referred from types/axios.d.ts
- */
-
-export type ErrorMessageMode = 'none' | 'modal' | 'message' | undefined
-
-export type SuccessMessageMode = ErrorMessageMode
-
-export interface RequestOptions {
- joinParamsToUrl?: boolean
-
- // ** Format request parameter time
- formatDate?: boolean
-
- // ** Whether to process the request result
- isTransformResponse?: boolean
-
- // ** Whether to return native response headers
- // ** For example: use this attribute when you need to get the response headers
- isReturnNativeResponse?: boolean
-
- // ** Whether to join url
- joinPrefix?: boolean
-
- // ** Interface address, use the default apiUrl if you leave it blank
- apiUrl?: string
-
- // ** Concatenating Path for the Request
- urlPrefix?: string
-
- // ** Error message prompt type
- errorMessageMode?: ErrorMessageMode
-
- // ** Success message prompt type
- successMessageMode?: SuccessMessageMode
-
- // ** Whether to add a timestamp
- joinTime?: boolean
- ignoreCancelToken?: boolean
-
- // ** Whether to send token in header
- withToken?: boolean
-
- // ** Retry Mechanism for Requests
- retryRequest?: RetryRequest
-}
-
-export interface RetryRequest {
- isOpenRetry: boolean
- count: number
- waitTime: number
-}
-
-export interface Result<T = any> {
- code: number
- type: 'success' | 'error' | 'warning'
- message: string
- result: T
-}
-
-// ** multipart/form-data: upload file
-export interface UploadFileParams {
- data?: Recordable
-
- // ** File parameter interface field name
- name?: string
-
- file: File | Blob
-
- filename?: string
- [key: string]: any
-}
diff --git a/web/src/types/global.d.ts b/web/src/types/global.d.ts
deleted file mode 100644
index 36cb991038..0000000000
--- a/web/src/types/global.d.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-/*
- * Copyright 2023 Datastrato Pvt Ltd.
- * This software is licensed under the Apache License version 2.
- */
-
-declare type Recordable<T = any> = Record<string, T>