Skip to content

Commit

Permalink
refactor(types): update request config interface and remove unused im…
Browse files Browse the repository at this point in the history
…port

- Remove unused AxiosInstance import
- Add AxcacheRequestConfig interface extending AxiosRequestConfig
- Update HTTP methods to use AxcacheRequestConfig for better type safety
  • Loading branch information
Sasamous committed Nov 17, 2024
1 parent a705ba5 commit a89587e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
17 changes: 11 additions & 6 deletions lib/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import { AxiosRequestConfig, AxiosResponse } from 'axios';

export interface AxcacheOptions extends AxiosRequestConfig {
stdTTL?: number;
Expand All @@ -8,12 +8,17 @@ export interface AxcacheOptions extends AxiosRequestConfig {
onCacheWrite?: (key: string) => void;
}

export interface AxcacheRequestConfig extends AxiosRequestConfig {
forceRefresh?: boolean;
ttl?: number;
}

export interface Axcache {
get<T = any>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
get<T = any>(url: string, config?: AxcacheRequestConfig): Promise<AxiosResponse<T>>;
post<T = any>(url: string, data?: any, config?: AxcacheRequestConfig): Promise<AxiosResponse<T>>;
put<T = any>(url: string, data?: any, config?: AxcacheRequestConfig): Promise<AxiosResponse<T>>;
delete<T = any>(url: string, config?: AxcacheRequestConfig): Promise<AxiosResponse<T>>;
patch<T = any>(url: string, data?: any, config?: AxcacheRequestConfig): Promise<AxiosResponse<T>>;
getCacheStats(): { entries: number; size: number };
clearCache(): void;
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "axcache",
"version": "2.0.3",
"version": "2.0.4",
"description": "A caching wrapper for axios with TTL and advanced caching strategies",
"main": "./dist/axcache.cjs.js",
"module": "./dist/axcache.esm.js",
Expand Down

0 comments on commit a89587e

Please sign in to comment.