-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: 缓存默认关闭
- Loading branch information
geekact
committed
Jul 21, 2024
1 parent
95e29be
commit 42a6eb8
Showing
26 changed files
with
358 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
export * from './enhancer'; | ||
export * from './slots/CacheSlot'; | ||
export * from './slots/ThrottleSlot'; | ||
export * from './slots/RetrySlot'; | ||
export * from './libs/overrideRequest'; | ||
export * from './libs/preventTransform'; | ||
export * from './libs/mergeSlotOptions'; | ||
export * from './libs/cloneResponse'; | ||
export * from './enhance'; | ||
export * from 'axios'; | ||
export { default as axios } from 'axios'; | ||
export { axios as default } from './enhance'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
interface BaseConfig { | ||
enable?: boolean; | ||
} | ||
|
||
export const mergeSlotOptions = <T extends BaseConfig>( | ||
globalOptions?: boolean | T, | ||
localOptions?: boolean | T, | ||
): T => { | ||
const globalOpts: BaseConfig | undefined = | ||
typeof globalOptions === 'undefined' | ||
? {} | ||
: typeof globalOptions === 'boolean' | ||
? { enable: globalOptions } | ||
: { enable: true, ...globalOptions }; | ||
const localOpts: BaseConfig | undefined = | ||
typeof localOptions === 'undefined' | ||
? {} | ||
: typeof localOptions === 'boolean' | ||
? { enable: localOptions } | ||
: { enable: true, ...localOptions }; | ||
|
||
return Object.assign({ enable: true }, globalOpts, localOpts) as T; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Axios, AxiosRequestConfig, type AxiosInstance, type AxiosResponse } from 'axios'; | ||
|
||
export interface FocaAxiosPromise<T = any, D = any> extends Promise<T> { | ||
/** | ||
* 返回axios原始的response格式 | ||
* @see AxiosResponse | ||
*/ | ||
toRaw: () => Promise<AxiosResponse<T, D>>; | ||
} | ||
|
||
export const overrideRequest = (instance: AxiosInstance) => { | ||
// 真实的上下文 context = new Axios(),但是未暴露出来,导致 instance.request 与 context.request 不是同一个。 | ||
Object.keys(Axios.prototype).forEach((key) => { | ||
// @ts-expect-error | ||
if (typeof Axios.prototype[key] === 'function') { | ||
Object.defineProperty(instance, key, { | ||
get() { | ||
// @ts-expect-error | ||
return Axios.prototype[key].bind(instance); | ||
}, | ||
enumerable: true, | ||
}); | ||
} | ||
}); | ||
|
||
instance.request = function overrideRequest(config?: AxiosRequestConfig<any>) { | ||
let shouldUnwrap: boolean = true; | ||
const promise = Axios.prototype.request | ||
.call(instance, config || {}) | ||
.then((response) => { | ||
return shouldUnwrap ? (response as AxiosResponse).data : response; | ||
}) as FocaAxiosPromise; | ||
|
||
promise.toRaw = function toRawResponse() { | ||
shouldUnwrap = false; | ||
return promise; | ||
}; | ||
|
||
return promise; | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.