Skip to content

Commit

Permalink
fix: force import type to help compilation tools
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Sep 26, 2021
1 parent 9ea72dc commit f8adcc4
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/axios/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions src/axios/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/header/interpreter.ts
Original file line number Diff line number Diff line change
@@ -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'];
Expand Down
6 changes: 3 additions & 3 deletions src/interceptors/request.ts
Original file line number Diff line number Diff line change
@@ -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) {}
Expand Down
8 changes: 4 additions & 4 deletions src/interceptors/response.ts
Original file line number Diff line number Diff line change
@@ -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> };

Expand Down
2 changes: 1 addition & 1 deletion src/storage/memory.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/storage/web.ts
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/util/cache-predicate.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/util/key-generator.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/util/types.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/util/update-cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AxiosCacheInstance, CacheUpdater } from '../axios/types';
import type { AxiosCacheInstance, CacheUpdater } from '../axios/types';

export async function updateCache(
axios: AxiosCacheInstance,
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/axios.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/storage/storages.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
19 changes: 1 addition & 18 deletions test/util/cache-predicate.test.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion test/util/update-cache.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit f8adcc4

Please sign in to comment.