axios-cache-interceptor
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -8,3 +8,3 @@ "use strict"; | ||
const axios_1 = __importDefault(require("axios")); | ||
const header_1 = require("../header"); | ||
const interpreter_1 = require("../header/interpreter"); | ||
const request_1 = require("../interceptors/request"); | ||
@@ -26,3 +26,3 @@ const response_1 = require("../interceptors/response"); | ||
axiosCache.waiting = waiting || {}; | ||
axiosCache.headerInterpreter = headerInterpreter || header_1.defaultHeaderInterpreter; | ||
axiosCache.headerInterpreter = headerInterpreter || interpreter_1.defaultHeaderInterpreter; | ||
axiosCache.requestInterceptor = requestInterceptor || new request_1.CacheRequestInterceptor(axiosCache); | ||
@@ -29,0 +29,0 @@ axiosCache.responseInterceptor = responseInterceptor || new response_1.CacheResponseInterceptor(axiosCache); |
import type { AxiosInstance, AxiosInterceptorManager, AxiosPromise, AxiosRequestConfig, AxiosResponse, Method } from 'axios'; | ||
import { HeaderInterpreter } from '../header'; | ||
import { HeaderInterpreter } from '../header/types'; | ||
import { AxiosInterceptor } from '../interceptors/types'; | ||
import { CachedResponse, CachedStorageValue, CacheStorage, EmptyStorageValue } from '../storage/types'; | ||
import { CachePredicate } from '../util/cache-predicate'; | ||
import { Deferred } from '../util/deferred'; | ||
import { KeyGenerator } from '../util/key-generator'; | ||
import { CachePredicate, KeyGenerator } from '../util/types'; | ||
export declare type CacheUpdater = 'delete' | ((cached: EmptyStorageValue | CachedStorageValue, newData: any) => CachedStorageValue | void); | ||
@@ -9,0 +8,0 @@ export declare type DefaultCacheRequestConfig = AxiosRequestConfig & { |
@@ -1,4 +0,8 @@ | ||
export * from './axios'; | ||
export * from './storage'; | ||
export * from './axios/cache'; | ||
export * from './axios/types'; | ||
export * from './header/types'; | ||
export * from './interceptors/types'; | ||
export * from './storage/types'; | ||
export * as StatusCodes from './util/status-codes'; | ||
export * from './util/types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -26,5 +26,9 @@ "use strict"; | ||
exports.StatusCodes = void 0; | ||
__exportStar(require("./axios"), exports); | ||
__exportStar(require("./storage"), exports); | ||
__exportStar(require("./axios/cache"), exports); | ||
__exportStar(require("./axios/types"), exports); | ||
__exportStar(require("./header/types"), exports); | ||
__exportStar(require("./interceptors/types"), exports); | ||
__exportStar(require("./storage/types"), exports); | ||
exports.StatusCodes = __importStar(require("./util/status-codes")); | ||
__exportStar(require("./util/types"), exports); | ||
//# sourceMappingURL=index.js.map |
import { AxiosResponse } from 'axios'; | ||
export declare type CachePredicate = CachePredicateObject | ((response: AxiosResponse) => boolean); | ||
export declare type CachePredicateObject = { | ||
/** | ||
* The status predicate, if a tuple is returned, the first and | ||
* seconds value means the interval (inclusive) accepted. Can also | ||
* be a function. | ||
*/ | ||
statusCheck?: [start: number, end: number] | ((status: number) => boolean); | ||
/** | ||
* Matches if the response header container all keys. A tuple also | ||
* checks for values. Can also be a predicate. | ||
*/ | ||
containsHeaders?: Record<string, true | string | ((header: string) => boolean)>; | ||
/** | ||
* Check if the desired response matches this predicate. | ||
*/ | ||
responseMatch?: <T = any>(res: T | undefined) => boolean; | ||
}; | ||
import { CachePredicateObject } from './types'; | ||
export declare function checkPredicateObject(response: AxiosResponse, { statusCheck, containsHeaders: containsHeader, responseMatch }: CachePredicateObject): boolean; | ||
//# sourceMappingURL=cache-predicate.d.ts.map |
@@ -1,4 +0,3 @@ | ||
import { CacheRequestConfig } from '../axios/types'; | ||
export declare type KeyGenerator = (options: CacheRequestConfig) => string; | ||
import { KeyGenerator } from './types'; | ||
export declare const defaultKeyGenerator: KeyGenerator; | ||
//# sourceMappingURL=key-generator.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { AxiosCacheInstance, CacheUpdater } from '../axios'; | ||
import { AxiosCacheInstance, CacheUpdater } from '../axios/types'; | ||
export declare function updateCache(axios: AxiosCacheInstance, data: any, entries: Record<string, CacheUpdater>): Promise<void>; | ||
//# sourceMappingURL=update-cache.d.ts.map |
{ | ||
"name": "axios-cache-interceptor", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Cache interceptor for axios", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -188,6 +188,10 @@ <br /> | ||
Existing implementations: | ||
There are few built in storage implementations, you can use them by importing: | ||
- [MemoryStorage](src/storage/memory.ts) | ||
- [Session and Local Storage](src/storage/web.ts) | ||
```js | ||
import { /* ... */ } from 'axios-cache-interceptor/dist/storage/{name}'; | ||
``` | ||
- [MemoryStorage](src/storage/memory.ts) `import 'axios-cache-interceptor/dist/storage/memory';` | ||
- [Session and Local Storage](src/storage/web.ts) `import 'axios-cache-interceptor/dist/storage/web';` | ||
- _Maybe your own?_ (PR's are welcome) | ||
@@ -194,0 +198,0 @@ |
import Axios, { AxiosInstance, AxiosRequestConfig } from 'axios'; | ||
import { defaultHeaderInterpreter } from '../header'; | ||
import { defaultHeaderInterpreter } from '../header/interpreter'; | ||
import { CacheRequestInterceptor } from '../interceptors/request'; | ||
@@ -4,0 +4,0 @@ import { CacheResponseInterceptor } from '../interceptors/response'; |
@@ -9,3 +9,3 @@ import type { | ||
} from 'axios'; | ||
import { HeaderInterpreter } from '../header'; | ||
import { HeaderInterpreter } from '../header/types'; | ||
import { AxiosInterceptor } from '../interceptors/types'; | ||
@@ -18,5 +18,4 @@ import { | ||
} from '../storage/types'; | ||
import { CachePredicate } from '../util/cache-predicate'; | ||
import { Deferred } from '../util/deferred'; | ||
import { KeyGenerator } from '../util/key-generator'; | ||
import { CachePredicate, KeyGenerator } from '../util/types'; | ||
@@ -23,0 +22,0 @@ export type CacheUpdater = |
@@ -1,3 +0,7 @@ | ||
export * from './axios'; | ||
export * from './storage'; | ||
export * from './axios/cache'; | ||
export * from './axios/types'; | ||
export * from './header/types'; | ||
export * from './interceptors/types'; | ||
export * from './storage/types'; | ||
export * as StatusCodes from './util/status-codes'; | ||
export * from './util/types'; |
import { AxiosResponse } from 'axios'; | ||
import { CachePredicateObject } from './types'; | ||
export type CachePredicate = CachePredicateObject | ((response: AxiosResponse) => boolean); | ||
export type CachePredicateObject = { | ||
/** | ||
* The status predicate, if a tuple is returned, the first and | ||
* seconds value means the interval (inclusive) accepted. Can also | ||
* be a function. | ||
*/ | ||
statusCheck?: [start: number, end: number] | ((status: number) => boolean); | ||
/** | ||
* Matches if the response header container all keys. A tuple also | ||
* checks for values. Can also be a predicate. | ||
*/ | ||
containsHeaders?: Record<string, true | string | ((header: string) => boolean)>; | ||
/** | ||
* Check if the desired response matches this predicate. | ||
*/ | ||
responseMatch?: <T = any>(res: T | undefined) => boolean; | ||
}; | ||
export function checkPredicateObject( | ||
@@ -26,0 +5,0 @@ response: AxiosResponse, |
@@ -1,2 +0,2 @@ | ||
import { CacheRequestConfig } from '../axios/types'; | ||
import { KeyGenerator } from './types'; | ||
@@ -7,4 +7,2 @@ // Remove first and last '/' char, if present | ||
export type KeyGenerator = (options: CacheRequestConfig) => string; | ||
export const defaultKeyGenerator: KeyGenerator = ({ | ||
@@ -11,0 +9,0 @@ baseURL = '', |
@@ -1,2 +0,2 @@ | ||
import { AxiosCacheInstance, CacheUpdater } from '../axios'; | ||
import { AxiosCacheInstance, CacheUpdater } from '../axios/types'; | ||
@@ -3,0 +3,0 @@ export async function updateCache( |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
338
119023
94
1549