diff --git a/src/axios/cache.ts b/src/axios/cache.ts index 7c6e790..cdb1f74 100644 --- a/src/axios/cache.ts +++ b/src/axios/cache.ts @@ -4,7 +4,7 @@ import { CacheRequestInterceptor } from '../interceptors/request'; import { CacheResponseInterceptor } from '../interceptors/response'; import { MemoryStorage } from '../storage/memory'; import { defaultKeyGenerator } from '../util/key-generator'; -import CacheInstance, { AxiosCacheInstance, CacheProperties } from './types'; +import type { AxiosCacheInstance, CacheInstance, CacheProperties } from './types'; /** * Apply the caching interceptors for a already created axios instance. diff --git a/src/axios/types.ts b/src/axios/types.ts index 0a89efb..89914b0 100644 --- a/src/axios/types.ts +++ b/src/axios/types.ts @@ -6,16 +6,16 @@ import type { AxiosResponse, Method } from 'axios'; -import { HeaderInterpreter } from '../header/types'; -import { AxiosInterceptor } from '../interceptors/types'; -import { +import type { HeaderInterpreter } from '../header/types'; +import type { AxiosInterceptor } from '../interceptors/types'; +import type { CachedResponse, CachedStorageValue, CacheStorage, EmptyStorageValue } from '../storage/types'; -import { Deferred } from '../util/deferred'; -import { CachePredicate, KeyGenerator } from '../util/types'; +import type { Deferred } from '../util/deferred'; +import type { CachePredicate, KeyGenerator } from '../util/types'; export type CacheUpdater = | 'delete' @@ -111,7 +111,7 @@ export type CacheRequestConfig = AxiosRequestConfig & { cache?: false | Partial; }; -export default interface CacheInstance { +export interface CacheInstance { /** * The storage to save the cache data. * diff --git a/src/header/interpreter.ts b/src/header/interpreter.ts index babf5c7..7747f02 100644 --- a/src/header/interpreter.ts +++ b/src/header/interpreter.ts @@ -1,5 +1,5 @@ import { parse } from '@tusbar/cache-control'; -import { HeaderInterpreter } from './types'; +import type { HeaderInterpreter } from './types'; export const defaultHeaderInterpreter: HeaderInterpreter = (headers) => { const cacheControl = headers?.['cache-control']; diff --git a/src/interceptors/request.ts b/src/interceptors/request.ts index aa1ebc6..0ee9572 100644 --- a/src/interceptors/request.ts +++ b/src/interceptors/request.ts @@ -1,12 +1,12 @@ -import { AxiosCacheInstance, CacheRequestConfig } from '../axios/types'; -import { +import type { AxiosCacheInstance, CacheRequestConfig } from '../axios/types'; +import type { CachedResponse, CachedStorageValue, LoadingStorageValue } from '../storage/types'; import { deferred } from '../util/deferred'; import { CACHED_STATUS_CODE, CACHED_STATUS_TEXT } from '../util/status-codes'; -import { AxiosInterceptor } from './types'; +import type { AxiosInterceptor } from './types'; export class CacheRequestInterceptor implements AxiosInterceptor { constructor(readonly axios: AxiosCacheInstance) {} diff --git a/src/interceptors/response.ts b/src/interceptors/response.ts index 73911fd..2186922 100644 --- a/src/interceptors/response.ts +++ b/src/interceptors/response.ts @@ -1,14 +1,14 @@ -import { AxiosResponse } from 'axios'; -import { +import type { AxiosResponse } from 'axios'; +import type { AxiosCacheInstance, CacheAxiosResponse, CacheProperties, CacheRequestConfig } from '../axios/types'; -import { CachedStorageValue } from '../storage/types'; +import type { CachedStorageValue } from '../storage/types'; import { checkPredicateObject } from '../util/cache-predicate'; import { updateCache } from '../util/update-cache'; -import { AxiosInterceptor } from './types'; +import type { AxiosInterceptor } from './types'; type CacheConfig = CacheRequestConfig & { cache?: Partial }; diff --git a/src/storage/memory.ts b/src/storage/memory.ts index 659deb9..354fbb7 100644 --- a/src/storage/memory.ts +++ b/src/storage/memory.ts @@ -1,4 +1,4 @@ -import { CacheStorage, StorageValue } from './types'; +import type { CacheStorage, StorageValue } from './types'; export class MemoryStorage implements CacheStorage { private readonly storage: Map = new Map(); diff --git a/src/storage/web.ts b/src/storage/web.ts index 97a55a8..6207d39 100644 --- a/src/storage/web.ts +++ b/src/storage/web.ts @@ -1,4 +1,4 @@ -import { CacheStorage, StorageValue } from './types'; +import type { CacheStorage, StorageValue } from './types'; /** * A storage that uses any {@link Storage} as his storage. */ diff --git a/src/util/cache-predicate.ts b/src/util/cache-predicate.ts index af6f4a9..4af24bb 100644 --- a/src/util/cache-predicate.ts +++ b/src/util/cache-predicate.ts @@ -1,5 +1,5 @@ -import { AxiosResponse } from 'axios'; -import { CachePredicateObject } from './types'; +import type { AxiosResponse } from 'axios'; +import type { CachePredicateObject } from './types'; export function checkPredicateObject( response: AxiosResponse, diff --git a/src/util/key-generator.ts b/src/util/key-generator.ts index 9a54f83..057bd33 100644 --- a/src/util/key-generator.ts +++ b/src/util/key-generator.ts @@ -1,4 +1,4 @@ -import { KeyGenerator } from './types'; +import type { KeyGenerator } from './types'; // Remove first and last '/' char, if present // https://regex101.com/r/ENqrFy/1 diff --git a/src/util/types.ts b/src/util/types.ts index 06b9289..faffc4b 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -1,5 +1,5 @@ -import { AxiosResponse } from 'axios'; -import { CacheRequestConfig } from '../axios/types'; +import type { AxiosResponse } from 'axios'; +import type { CacheRequestConfig } from '../axios/types'; export type CachePredicate = | CachePredicateObject diff --git a/src/util/update-cache.ts b/src/util/update-cache.ts index 9875138..0c2f7fb 100644 --- a/src/util/update-cache.ts +++ b/src/util/update-cache.ts @@ -1,4 +1,4 @@ -import { AxiosCacheInstance, CacheUpdater } from '../axios/types'; +import type { AxiosCacheInstance, CacheUpdater } from '../axios/types'; export async function updateCache( axios: AxiosCacheInstance, diff --git a/test/mocks/axios.ts b/test/mocks/axios.ts index 621ab8e..7e8c556 100644 --- a/test/mocks/axios.ts +++ b/test/mocks/axios.ts @@ -1,5 +1,5 @@ import { AxiosCacheInstance, CacheProperties, createCache } from '../../src'; -import CacheInstance from '../../src/axios/types'; +import type { CacheInstance } from '../../src/axios/types'; export const axiosMock = { statusCode: 200, diff --git a/test/storage/storages.ts b/test/storage/storages.ts index 23046ac..788cb98 100644 --- a/test/storage/storages.ts +++ b/test/storage/storages.ts @@ -1,4 +1,4 @@ -import { CacheStorage } from '../../src/storage/types'; +import type { CacheStorage } from '../../src/storage/types'; export function testStorage(name: string, Storage: () => CacheStorage) { it(`tests ${name} storage methods`, async () => { diff --git a/test/util/cache-predicate.test.ts b/test/util/cache-predicate.test.ts index 9845500..e78fdaf 100644 --- a/test/util/cache-predicate.test.ts +++ b/test/util/cache-predicate.test.ts @@ -1,21 +1,4 @@ -// /** -// * 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. -// */ -// containsHeaders?: (string | [string, string])[]; - -// /** -// * Check if the desired response matches this predicate. -// */ -// responseMatch?: (res: T | undefined) => boolean; - -import { AxiosResponse } from 'axios'; +import type { AxiosResponse } from 'axios'; import { checkPredicateObject } from '../../src/util/cache-predicate'; const Response = (config: Partial): AxiosResponse => { diff --git a/test/util/update-cache.test.ts b/test/util/update-cache.test.ts index e384f54..c550b87 100644 --- a/test/util/update-cache.test.ts +++ b/test/util/update-cache.test.ts @@ -1,4 +1,4 @@ -import { AxiosCacheInstance, CachedStorageValue } from '../../src'; +import type { AxiosCacheInstance, CachedStorageValue } from '../../src'; import { updateCache } from '../../src/util/update-cache'; import { mockAxios } from '../mocks/axios'; diff --git a/tsconfig.json b/tsconfig.json index d71cf6f..99b92b5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -51,7 +51,7 @@ // "removeComments": true, /* Disable emitting comments. */ // "noEmit": true, /* Disable emitting files from a compilation. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ - // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ + "importsNotUsedAsValues": "error", /* Specify emit/checking behavior for imports that are only used for types */ "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */