fix: force import type to help compilation tools

This commit is contained in:
Hazork 2021-09-26 16:24:33 -03:00
parent 9ea72dca5b
commit f8adcc4352
16 changed files with 28 additions and 45 deletions

View File

@ -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.

View File

@ -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<CacheProperties>;
};
export default interface CacheInstance {
export interface CacheInstance {
/**
* The storage to save the cache data.
*

View File

@ -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'];

View File

@ -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<CacheRequestConfig> {
constructor(readonly axios: AxiosCacheInstance) {}

View File

@ -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<CacheProperties> };

View File

@ -1,4 +1,4 @@
import { CacheStorage, StorageValue } from './types';
import type { CacheStorage, StorageValue } from './types';
export class MemoryStorage implements CacheStorage {
private readonly storage: Map<string, StorageValue> = new Map();

View File

@ -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.
*/

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -1,4 +1,4 @@
import { AxiosCacheInstance, CacheUpdater } from '../axios/types';
import type { AxiosCacheInstance, CacheUpdater } from '../axios/types';
export async function updateCache(
axios: AxiosCacheInstance,

View File

@ -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,

View File

@ -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 () => {

View File

@ -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?: <T = any>(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>): AxiosResponse => {

View File

@ -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';

View File

@ -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. */