diff --git a/.eslintrc.json b/.eslintrc.json index 58720c2..fc79572 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,7 +2,9 @@ "extends": [ "eslint:recommended", "plugin:@typescript-eslint/recommended", - "plugin:prettier/recommended" + "plugin:prettier/recommended", + "plugin:import/recommended", + "plugin:import/typescript" ], "plugins": [ "@typescript-eslint", @@ -31,6 +33,7 @@ ], "no-var": "off", "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/consistent-type-imports": "warn", "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-var-requires": "off", "@typescript-eslint/indent": "off", diff --git a/lib/AbstractGroupedOperation.ts b/lib/AbstractGroupedOperation.ts index 8c5cc52..e8e9efd 100644 --- a/lib/AbstractGroupedOperation.ts +++ b/lib/AbstractGroupedOperation.ts @@ -1,5 +1,5 @@ import { AbstractOperation } from './AbstractOperation' -import { GroupedCache } from './types/DataSources' +import type { GroupedCache } from './types/DataSources' export abstract class AbstractGroupedOperation extends AbstractOperation< LoadedValue, diff --git a/lib/AbstractOperation.ts b/lib/AbstractOperation.ts index 4663c0a..e58832a 100644 --- a/lib/AbstractOperation.ts +++ b/lib/AbstractOperation.ts @@ -1,7 +1,9 @@ -import { InMemoryCache, InMemoryCacheConfiguration, NoopCache } from './memory' -import { SynchronousGroupedCache } from './types/SyncDataSources' -import { Cache } from './types/DataSources' -import { defaultLogger, Logger } from './Logger' +import type { InMemoryCacheConfiguration } from './memory' +import { InMemoryCache, NoopCache } from './memory' +import type { SynchronousGroupedCache } from './types/SyncDataSources' +import type { Cache } from './types/DataSources' +import type { Logger } from './Logger' +import { defaultLogger } from './Logger' export type LoaderErrorHandler = ( err: Error, diff --git a/lib/GroupedCachingOperation.ts b/lib/GroupedCachingOperation.ts index 46a2832..15fb93c 100644 --- a/lib/GroupedCachingOperation.ts +++ b/lib/GroupedCachingOperation.ts @@ -1,5 +1,5 @@ -import { GroupedCache } from './types/DataSources' -import { CommonOperationConfig } from './AbstractOperation' +import type { GroupedCache } from './types/DataSources' +import type { CommonOperationConfig } from './AbstractOperation' import { AbstractGroupedOperation } from './AbstractGroupedOperation' export type GroupedCachingOperationConfig = CommonOperationConfig> diff --git a/lib/GroupedLoadingOperation.ts b/lib/GroupedLoadingOperation.ts index 69841be..62b5f66 100644 --- a/lib/GroupedLoadingOperation.ts +++ b/lib/GroupedLoadingOperation.ts @@ -1,5 +1,5 @@ -import { GroupedCache, GroupLoader } from './types/DataSources' -import { LoadingOperationConfig } from './LoadingOperation' +import type { GroupedCache, GroupLoader } from './types/DataSources' +import type { LoadingOperationConfig } from './LoadingOperation' import { AbstractGroupedOperation } from './AbstractGroupedOperation' export type GroupedLoadingOperationConfig = LoadingOperationConfig< diff --git a/lib/LoadingOperation.ts b/lib/LoadingOperation.ts index b500acb..4118e8c 100644 --- a/lib/LoadingOperation.ts +++ b/lib/LoadingOperation.ts @@ -1,5 +1,5 @@ -import { CommonOperationConfig } from './AbstractOperation' -import { Cache, Loader } from './types/DataSources' +import type { CommonOperationConfig } from './AbstractOperation' +import type { Cache, Loader } from './types/DataSources' import { AbstractFlatOperation } from './AbstractFlatOperation' export type LoadingOperationConfig< diff --git a/lib/memory/InMemoryCache.ts b/lib/memory/InMemoryCache.ts index 4bd8419..faeec77 100644 --- a/lib/memory/InMemoryCache.ts +++ b/lib/memory/InMemoryCache.ts @@ -1,10 +1,13 @@ -import { fifo, fifoObject, lru, lruObject, ToadCache } from 'toad-cache' -import { SynchronousCache, SynchronousGroupedCache } from '../types/SyncDataSources' -import { CacheConfiguration } from '../types/DataSources' +import type { CacheConstructor, ToadCache } from 'toad-cache' +import { FifoMap, FifoObject, LruMap, LruObject } from 'toad-cache' +import type { SynchronousCache, SynchronousGroupedCache } from '../types/SyncDataSources' +import type { CacheConfiguration } from '../types/DataSources' + +type CacheTypeId = 'lru-map' | 'fifo-map' | 'lru-object' | 'fifo-object' export interface InMemoryCacheConfiguration extends CacheConfiguration { - cacheType?: 'lru' | 'fifo' | 'lru-object' | 'fifo-object' - groupCacheType?: 'lru' | 'fifo' | 'lru-object' | 'fifo-object' + cacheType?: CacheTypeId + groupCacheType?: CacheTypeId maxItems?: number maxGroups?: number maxItemsPerGroup?: number @@ -25,31 +28,31 @@ export class InMemoryCache implements SynchronousCache, SynchronousGrouped name = 'In-memory cache' private readonly ttlInMsecs: number | undefined public readonly ttlLeftBeforeRefreshInMsecs?: number - private readonly cacheConstructor: (max?: number, ttl?: number) => ToadCache - private readonly groupCacheConstructor: (max?: number, ttl?: number) => ToadCache + private readonly cacheConstructor: CacheConstructor> + private readonly groupCacheConstructor: CacheConstructor>> constructor(config: InMemoryCacheConfiguration) { - this.cacheConstructor = this.resolveCacheConstructor(config.cacheType ?? DEFAULT_CONFIGURATION.cacheType) - this.groupCacheConstructor = this.resolveCacheConstructor( + this.cacheConstructor = this.resolveCacheConstructor(config.cacheType ?? DEFAULT_CONFIGURATION.cacheType) + this.groupCacheConstructor = this.resolveCacheConstructor>( config.groupCacheType ?? DEFAULT_CONFIGURATION.groupCacheType ) - this.cache = this.cacheConstructor(config.maxItems ?? DEFAULT_CONFIGURATION.maxItems, config.ttlInMsecs ?? 0) - this.groups = this.groupCacheConstructor(config.maxGroups ?? DEFAULT_CONFIGURATION.maxGroups) + this.cache = new this.cacheConstructor(config.maxItems ?? DEFAULT_CONFIGURATION.maxItems, config.ttlInMsecs ?? 0) + this.groups = new this.groupCacheConstructor(config.maxGroups ?? DEFAULT_CONFIGURATION.maxGroups) this.maxItemsPerGroup = config.maxItemsPerGroup ?? DEFAULT_CONFIGURATION.maxItemsPerGroup this.ttlInMsecs = config.ttlInMsecs this.ttlLeftBeforeRefreshInMsecs = config.ttlLeftBeforeRefreshInMsecs } - private resolveCacheConstructor(cacheTypeId: 'lru' | 'fifo' | 'lru-object' | 'fifo-object') { - if (cacheTypeId === 'fifo') { - return fifo - } else if (cacheTypeId === 'lru') { - return lru + private resolveCacheConstructor(cacheTypeId: CacheTypeId): CacheConstructor> { + if (cacheTypeId === 'fifo-map') { + return FifoMap + } else if (cacheTypeId === 'lru-map') { + return LruMap } else if (cacheTypeId === 'fifo-object') { - return fifoObject + return FifoObject } else { - return lruObject + return LruObject } } @@ -59,7 +62,7 @@ export class InMemoryCache implements SynchronousCache, SynchronousGrouped return groupCache } - const newGroupCache = this.cacheConstructor(this.maxItemsPerGroup, this.ttlInMsecs) + const newGroupCache = new this.cacheConstructor(this.maxItemsPerGroup, this.ttlInMsecs) this.groups.set(groupId, newGroupCache) return newGroupCache } diff --git a/lib/memory/NoopCache.ts b/lib/memory/NoopCache.ts index df8fca1..9fa58aa 100644 --- a/lib/memory/NoopCache.ts +++ b/lib/memory/NoopCache.ts @@ -1,4 +1,4 @@ -import { SynchronousCache, SynchronousGroupedCache } from '../types/SyncDataSources' +import type { SynchronousCache, SynchronousGroupedCache } from '../types/SyncDataSources' export class NoopCache implements SynchronousCache, SynchronousGroupedCache { name = 'Noop cache' diff --git a/lib/redis/RedisCache.ts b/lib/redis/RedisCache.ts index c9a4b4c..cd5a4af 100644 --- a/lib/redis/RedisCache.ts +++ b/lib/redis/RedisCache.ts @@ -1,4 +1,4 @@ -import { Cache, CacheConfiguration, GroupedCache, Loader } from '../types/DataSources' +import type { Cache, CacheConfiguration, GroupedCache, Loader } from '../types/DataSources' import type { Redis } from 'ioredis' import { RedisTimeoutError } from './RedisTimeoutError' import { GET_OR_SET_ZERO_WITH_TTL, GET_OR_SET_ZERO_WITHOUT_TTL } from './lua' diff --git a/lib/redis/RedisExpirationTimeGroupedLoader.ts b/lib/redis/RedisExpirationTimeGroupedLoader.ts index 9f9cc96..9226e05 100644 --- a/lib/redis/RedisExpirationTimeGroupedLoader.ts +++ b/lib/redis/RedisExpirationTimeGroupedLoader.ts @@ -1,4 +1,4 @@ -import { GroupedCache, GroupLoader } from '../types/DataSources' +import type { GroupedCache, GroupLoader } from '../types/DataSources' export class RedisExpirationTimeGroupedLoader implements GroupLoader { public readonly name = 'RedisExpirationTimeGroupedLoader' diff --git a/lib/redis/RedisExpirationTimeLoader.ts b/lib/redis/RedisExpirationTimeLoader.ts index fd4d9f3..d115e9c 100644 --- a/lib/redis/RedisExpirationTimeLoader.ts +++ b/lib/redis/RedisExpirationTimeLoader.ts @@ -1,4 +1,4 @@ -import { Cache, Loader } from '../types/DataSources' +import type { Cache, Loader } from '../types/DataSources' export class RedisExpirationTimeLoader implements Loader { public readonly name = 'RedisExpirationTimeLoader' diff --git a/lib/types/DataSources.ts b/lib/types/DataSources.ts index 94d51d9..4e38c8f 100644 --- a/lib/types/DataSources.ts +++ b/lib/types/DataSources.ts @@ -1,5 +1,5 @@ -import { LoadingOperation } from '../LoadingOperation' -import { GroupedLoadingOperation } from '../GroupedLoadingOperation' +import type { LoadingOperation } from '../LoadingOperation' +import type { GroupedLoadingOperation } from '../GroupedLoadingOperation' export interface CacheConfiguration { ttlLeftBeforeRefreshInMsecs?: number diff --git a/package.json b/package.json index 296f86b..8ccdc0f 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,16 @@ "email": "kibertoad@gmail.com" } ], - "main": "dist/index.js", + "main": "dist/layered-loader", + "exports": { + "import": "./dist/layered-loader.js", + "require": "./dist/layered-loader.cjs" + }, "types": "dist/index.d.ts", "scripts": { "build": "tsc", + "build:release": "del-cli dist && del-cli coverage && npm run lint && npm run build:rollup", + "build:rollup": "rollup --config", "docker:start": "docker-compose -f docker-compose.yml up --build -d redis && docker-compose -f docker-compose.yml up --build -d wait_for_redis", "docker:stop": "docker-compose -f docker-compose.yml down", "test": "jest --runInBand", @@ -21,7 +27,7 @@ "lint": "eslint \"lib/**/*.ts\" \"test/**/*.ts\"", "lint:fix": "eslint --fix \"lib/**/*.ts\" \"test/**/*.ts\"", "prettier": "prettier --write \"{lib,test}/**/*.{js,ts}\" index.ts", - "prepublishOnly": "npm run build" + "prepublishOnly": "npm run build:release" }, "engines": { "node": ">=16" @@ -47,13 +53,16 @@ ], "homepage": "https://github.com/kibertoad/layered-loader", "dependencies": { - "toad-cache": "^2.1.0" + "toad-cache": "^3.0.0" }, "devDependencies": { + "@rollup/plugin-terser": "^0.4.0", + "@rollup/plugin-typescript": "^11.1.0", "@types/jest": "^29.5.0", "@types/node": "^18.15.11", "@typescript-eslint/eslint-plugin": "^5.57.0", "@typescript-eslint/parser": "^5.57.0", + "del-cli": "^5.0.0", "eslint": "^8.37.0", "eslint-config-prettier": "^8.8.0", "eslint-plugin-import": "^2.27.5", @@ -62,6 +71,7 @@ "jest": "29.5.0", "prettier": "^2.8.7", "rfdc": "^1.3.0", + "rollup": "^3.20.2", "ts-jest": "29.1.0", "typescript": "5.0.3" }, diff --git a/rollup.config.mjs b/rollup.config.mjs new file mode 100644 index 0000000..b999e87 --- /dev/null +++ b/rollup.config.mjs @@ -0,0 +1,56 @@ +import terser from '@rollup/plugin-terser' +import typescript from '@rollup/plugin-typescript' +import { createRequire } from 'node:module' +const require = createRequire(import.meta.url) +const pkg = require('./package.json') +const year = new Date().getFullYear() +const bannerLong = `/** + * ${pkg.name} + * + * @copyright ${year} ${pkg.author} + * @license ${pkg.license} + * @version ${pkg.version} + */` +const bannerShort = `/*! + ${year} ${pkg.author} + @version ${pkg.version} +*/` +const defaultOutBase = { compact: true, banner: bannerLong, name: pkg.name } +const cjOutBase = { ...defaultOutBase, compact: false, format: 'cjs', exports: 'named' } +const esmOutBase = { ...defaultOutBase, format: 'esm' } +const umdOutBase = { ...defaultOutBase, format: 'umd' } +const minOutBase = { banner: bannerShort, name: pkg.name, plugins: [terser()], sourcemap: true } + +export default [ + { + input: './index.ts', + output: [ + { + ...cjOutBase, + file: `dist/${pkg.name}.cjs`, + }, + { + ...esmOutBase, + file: `dist/${pkg.name}.js`, + }, + { + ...esmOutBase, + ...minOutBase, + file: `dist/${pkg.name}.min.js`, + }, + { + ...umdOutBase, + file: `dist/${pkg.name}.umd.js`, + name: 'layered-loader', + }, + { + ...umdOutBase, + ...minOutBase, + file: `dist/${pkg.name}.umd.min.js`, + name: 'layered-loader', + }, + ], + plugins: [typescript()], + external: ['toad-cache'] + }, +] diff --git a/test/CachingOperation.spec.ts b/test/CachingOperation.spec.ts index 9e3b11e..b16d225 100644 --- a/test/CachingOperation.spec.ts +++ b/test/CachingOperation.spec.ts @@ -1,4 +1,4 @@ -import { InMemoryCacheConfiguration } from '../lib/memory/InMemoryCache' +import type { InMemoryCacheConfiguration } from '../lib/memory/InMemoryCache' import { ThrowingCache } from './fakes/ThrowingCache' import { CachingOperation } from '../lib/CachingOperation' import { DummyCache } from './fakes/DummyCache' diff --git a/test/GroupedCachingOperation.spec.ts b/test/GroupedCachingOperation.spec.ts index 95950b1..e0dd9a0 100644 --- a/test/GroupedCachingOperation.spec.ts +++ b/test/GroupedCachingOperation.spec.ts @@ -1,12 +1,12 @@ import { GroupedCachingOperation } from '../lib/GroupedCachingOperation' import { ThrowingGroupedCache } from './fakes/ThrowingGroupedCache' -import { User } from './types/testTypes' +import type { User } from './types/testTypes' import { RedisCache } from '../lib/redis' import Redis from 'ioredis' import { redisOptions } from './fakes/TestRedisConfig' import { DummyGroupedCache } from './fakes/DummyGroupedCache' import { CountingGroupedCache } from './fakes/CountingGroupedCache' -import { InMemoryCacheConfiguration } from '../lib/memory' +import type { InMemoryCacheConfiguration } from '../lib/memory' import { TemporaryThrowingGroupedCache } from './fakes/TemporaryThrowingGroupedCache' const redisCacheConfig = { json: true, ttlInMsecs: 99999, prefix: 'users' } diff --git a/test/GroupedLoadingOperation-async-refresh.spec.ts b/test/GroupedLoadingOperation-async-refresh.spec.ts index 3917a16..70470fd 100644 --- a/test/GroupedLoadingOperation-async-refresh.spec.ts +++ b/test/GroupedLoadingOperation-async-refresh.spec.ts @@ -1,4 +1,4 @@ -import { User } from './types/testTypes' +import type { User } from './types/testTypes' import { GroupedLoadingOperation } from '../lib/GroupedLoadingOperation' import { CountingGroupedLoader } from './fakes/CountingGroupedLoader' import { setTimeout } from 'timers/promises' diff --git a/test/GroupedLoadingOperation-main.spec.ts b/test/GroupedLoadingOperation-main.spec.ts index ab88927..4381984 100644 --- a/test/GroupedLoadingOperation-main.spec.ts +++ b/test/GroupedLoadingOperation-main.spec.ts @@ -1,5 +1,5 @@ -import { InMemoryCacheConfiguration } from '../lib/memory/InMemoryCache' -import { User } from './types/testTypes' +import type { InMemoryCacheConfiguration } from '../lib/memory/InMemoryCache' +import type { User } from './types/testTypes' import { GroupedLoadingOperation } from '../lib/GroupedLoadingOperation' import { DummyGroupedCache } from './fakes/DummyGroupedCache' import { ThrowingGroupedLoader } from './fakes/ThrowingGroupedLoader' @@ -7,7 +7,7 @@ import { DummyGroupedLoader } from './fakes/DummyGroupedLoader' import { TemporaryThrowingGroupedLoader } from './fakes/TemporaryThrowingGroupedLoader' import { ThrowingGroupedCache } from './fakes/ThrowingGroupedCache' import { CountingGroupedLoader } from './fakes/CountingGroupedLoader' -import { DummyLoaderParams } from './fakes/DummyLoaderWithParams' +import type { DummyLoaderParams } from './fakes/DummyLoaderWithParams' import { DummyGroupedLoaderWithParams } from './fakes/DummyGroupedLoaderWithParams' import { setTimeout } from 'timers/promises' diff --git a/test/InMemoryCache.spec.ts b/test/InMemoryCache.spec.ts index 4cafd83..9063b21 100644 --- a/test/InMemoryCache.spec.ts +++ b/test/InMemoryCache.spec.ts @@ -1,4 +1,5 @@ -import { InMemoryCache, InMemoryCacheConfiguration } from '../lib/memory/InMemoryCache' +import type { InMemoryCacheConfiguration } from '../lib/memory/InMemoryCache' +import { InMemoryCache } from '../lib/memory/InMemoryCache' import { setTimeout } from 'timers/promises' const IN_MEMORY_CACHE_CONFIG = { ttlInMsecs: 999 } satisfies InMemoryCacheConfiguration @@ -7,7 +8,7 @@ describe('InMemoryCache', () => { describe('set', () => { it('expires LRU', () => { const cache = new InMemoryCache({ - cacheType: 'lru', + cacheType: 'lru-map', maxItems: 2, ttlInMsecs: 1, }) @@ -49,7 +50,7 @@ describe('InMemoryCache', () => { it('expires FIFO', () => { const cache = new InMemoryCache({ - cacheType: 'fifo', + cacheType: 'fifo-map', maxItems: 2, ttlInMsecs: 1, }) diff --git a/test/LoadingOperation-main.spec.ts b/test/LoadingOperation-main.spec.ts index 8665c41..e40767f 100644 --- a/test/LoadingOperation-main.spec.ts +++ b/test/LoadingOperation-main.spec.ts @@ -1,13 +1,14 @@ import { setTimeout } from 'timers/promises' import { LoadingOperation } from '../lib/LoadingOperation' -import { InMemoryCacheConfiguration } from '../lib/memory/InMemoryCache' +import type { InMemoryCacheConfiguration } from '../lib/memory/InMemoryCache' import { DummyLoader } from './fakes/DummyLoader' import { CountingLoader } from './fakes/CountingLoader' import { ThrowingLoader } from './fakes/ThrowingLoader' import { ThrowingCache } from './fakes/ThrowingCache' import { TemporaryThrowingLoader } from './fakes/TemporaryThrowingLoader' import { DummyCache } from './fakes/DummyCache' -import { DummyLoaderParams, DummyLoaderWithParams } from './fakes/DummyLoaderWithParams' +import type { DummyLoaderParams } from './fakes/DummyLoaderWithParams' +import { DummyLoaderWithParams } from './fakes/DummyLoaderWithParams' const IN_MEMORY_CACHE_CONFIG = { ttlInMsecs: 999 } satisfies InMemoryCacheConfiguration diff --git a/test/RedisCache.timeout.spec.ts b/test/RedisCache.timeout.spec.ts index f948c2f..d8b1848 100644 --- a/test/RedisCache.timeout.spec.ts +++ b/test/RedisCache.timeout.spec.ts @@ -1,4 +1,4 @@ -import Redis from 'ioredis' +import type Redis from 'ioredis' import { RedisCache } from '../lib/redis/RedisCache' import { FakeRedis } from './fakes/FakeRedis' diff --git a/test/fakes/CountingCache.ts b/test/fakes/CountingCache.ts index cc4cf3c..dcfd2be 100644 --- a/test/fakes/CountingCache.ts +++ b/test/fakes/CountingCache.ts @@ -1,4 +1,4 @@ -import { Cache } from '../../lib/types/DataSources' +import type { Cache } from '../../lib/types/DataSources' export class CountingCache implements Cache { private value: string | undefined diff --git a/test/fakes/CountingGroupedCache.ts b/test/fakes/CountingGroupedCache.ts index ab47400..5a07fc4 100644 --- a/test/fakes/CountingGroupedCache.ts +++ b/test/fakes/CountingGroupedCache.ts @@ -1,5 +1,5 @@ -import { GroupedCache } from '../../lib/types/DataSources' -import { GroupValues, User } from '../types/testTypes' +import type { GroupedCache } from '../../lib/types/DataSources' +import type { GroupValues, User } from '../types/testTypes' import { cloneDeep } from '../utils/cloneUtils' export class CountingGroupedCache implements GroupedCache { diff --git a/test/fakes/CountingGroupedLoader.ts b/test/fakes/CountingGroupedLoader.ts index 116b3db..dee27f5 100644 --- a/test/fakes/CountingGroupedLoader.ts +++ b/test/fakes/CountingGroupedLoader.ts @@ -1,5 +1,5 @@ -import { GroupLoader } from '../../lib/types/DataSources' -import { GroupValues, User } from '../types/testTypes' +import type { GroupLoader } from '../../lib/types/DataSources' +import type { GroupValues, User } from '../types/testTypes' import { cloneDeep } from '../utils/cloneUtils' export class CountingGroupedLoader implements GroupLoader { diff --git a/test/fakes/CountingLoader.ts b/test/fakes/CountingLoader.ts index 03a510e..0970532 100644 --- a/test/fakes/CountingLoader.ts +++ b/test/fakes/CountingLoader.ts @@ -1,4 +1,4 @@ -import { Loader } from '../../lib/types/DataSources' +import type { Loader } from '../../lib/types/DataSources' export class CountingLoader implements Loader { public value: string | undefined diff --git a/test/fakes/DelayedCountingGroupedLoader.ts b/test/fakes/DelayedCountingGroupedLoader.ts index e3f5840..d78233b 100644 --- a/test/fakes/DelayedCountingGroupedLoader.ts +++ b/test/fakes/DelayedCountingGroupedLoader.ts @@ -1,5 +1,5 @@ -import { GroupLoader } from '../../lib/types/DataSources' -import { GroupValues, User } from '../types/testTypes' +import type { GroupLoader } from '../../lib/types/DataSources' +import type { GroupValues, User } from '../types/testTypes' import { cloneDeep } from '../utils/cloneUtils' export class DelayedCountingGroupedLoader implements GroupLoader { diff --git a/test/fakes/DelayedCountingLoader.ts b/test/fakes/DelayedCountingLoader.ts index 0a057d8..780b4d2 100644 --- a/test/fakes/DelayedCountingLoader.ts +++ b/test/fakes/DelayedCountingLoader.ts @@ -1,4 +1,4 @@ -import { Loader } from '../../lib/types/DataSources' +import type { Loader } from '../../lib/types/DataSources' export class DelayedCountingLoader implements Loader { public value: string | undefined diff --git a/test/fakes/DummyCache.ts b/test/fakes/DummyCache.ts index bfd4d4d..2564fda 100644 --- a/test/fakes/DummyCache.ts +++ b/test/fakes/DummyCache.ts @@ -1,4 +1,4 @@ -import { Cache } from '../../lib/types/DataSources' +import type { Cache } from '../../lib/types/DataSources' export class DummyCache implements Cache { value: string | undefined | null diff --git a/test/fakes/DummyGroupedCache.ts b/test/fakes/DummyGroupedCache.ts index fc1f1f2..8d69c8b 100644 --- a/test/fakes/DummyGroupedCache.ts +++ b/test/fakes/DummyGroupedCache.ts @@ -1,5 +1,5 @@ -import { GroupedCache } from '../../lib/types/DataSources' -import { GroupValues, User } from '../types/testTypes' +import type { GroupedCache } from '../../lib/types/DataSources' +import type { GroupValues, User } from '../types/testTypes' import { cloneDeep } from '../utils/cloneUtils' export class DummyGroupedCache implements GroupedCache { diff --git a/test/fakes/DummyGroupedLoader.ts b/test/fakes/DummyGroupedLoader.ts index f764cbe..374ef08 100644 --- a/test/fakes/DummyGroupedLoader.ts +++ b/test/fakes/DummyGroupedLoader.ts @@ -1,5 +1,5 @@ -import { GroupLoader } from '../../lib/types/DataSources' -import { GroupValues, User } from '../types/testTypes' +import type { GroupLoader } from '../../lib/types/DataSources' +import type { GroupValues, User } from '../types/testTypes' import { cloneDeep } from '../utils/cloneUtils' export class DummyGroupedLoader implements GroupLoader { diff --git a/test/fakes/DummyGroupedLoaderWithParams.ts b/test/fakes/DummyGroupedLoaderWithParams.ts index 045fa01..35a6088 100644 --- a/test/fakes/DummyGroupedLoaderWithParams.ts +++ b/test/fakes/DummyGroupedLoaderWithParams.ts @@ -1,7 +1,7 @@ -import { GroupLoader } from '../../lib/types/DataSources' -import { GroupValues, User } from '../types/testTypes' +import type { GroupLoader } from '../../lib/types/DataSources' +import type { GroupValues, User } from '../types/testTypes' import { cloneDeep } from '../utils/cloneUtils' -import { DummyLoaderParams } from './DummyLoaderWithParams' +import type { DummyLoaderParams } from './DummyLoaderWithParams' export class DummyGroupedLoaderWithParams implements GroupLoader { public groupValues: GroupValues | null | undefined diff --git a/test/fakes/DummyLoader.ts b/test/fakes/DummyLoader.ts index 8b96bd1..04eeb46 100644 --- a/test/fakes/DummyLoader.ts +++ b/test/fakes/DummyLoader.ts @@ -1,4 +1,4 @@ -import { Loader } from '../../lib/types/DataSources' +import type { Loader } from '../../lib/types/DataSources' export class DummyLoader implements Loader { value: string | undefined | null diff --git a/test/fakes/DummyLoaderWithParams.ts b/test/fakes/DummyLoaderWithParams.ts index 2a6489e..5b92a58 100644 --- a/test/fakes/DummyLoaderWithParams.ts +++ b/test/fakes/DummyLoaderWithParams.ts @@ -1,4 +1,4 @@ -import { Loader } from '../../lib/types/DataSources' +import type { Loader } from '../../lib/types/DataSources' export type DummyLoaderParams = { prefix: string diff --git a/test/fakes/FakeRedis.ts b/test/fakes/FakeRedis.ts index 0125f4d..5ff7b69 100644 --- a/test/fakes/FakeRedis.ts +++ b/test/fakes/FakeRedis.ts @@ -1,4 +1,5 @@ -import Redis, { Result } from 'ioredis' +import type { Result } from 'ioredis' +import Redis from 'ioredis' function createLongDelayPromise() { return new Promise((resolve) => setTimeout(resolve, 9999999)) diff --git a/test/fakes/TemporaryThrowingCache.ts b/test/fakes/TemporaryThrowingCache.ts index 705a429..1c0fb05 100644 --- a/test/fakes/TemporaryThrowingCache.ts +++ b/test/fakes/TemporaryThrowingCache.ts @@ -1,4 +1,4 @@ -import { Cache } from '../../lib/types/DataSources' +import type { Cache } from '../../lib/types/DataSources' export class TemporaryThrowingCache implements Cache { name = 'Throwing loader' diff --git a/test/fakes/TemporaryThrowingGroupedCache.ts b/test/fakes/TemporaryThrowingGroupedCache.ts index 6734ce1..c957ab3 100644 --- a/test/fakes/TemporaryThrowingGroupedCache.ts +++ b/test/fakes/TemporaryThrowingGroupedCache.ts @@ -1,5 +1,5 @@ -import { GroupedCache } from '../../lib/types/DataSources' -import { GroupValues, User } from '../types/testTypes' +import type { GroupedCache } from '../../lib/types/DataSources' +import type { GroupValues, User } from '../types/testTypes' import { cloneDeep } from '../utils/cloneUtils' export class TemporaryThrowingGroupedCache implements GroupedCache { diff --git a/test/fakes/TemporaryThrowingGroupedLoader.ts b/test/fakes/TemporaryThrowingGroupedLoader.ts index 26c4a89..2ec899d 100644 --- a/test/fakes/TemporaryThrowingGroupedLoader.ts +++ b/test/fakes/TemporaryThrowingGroupedLoader.ts @@ -1,5 +1,5 @@ -import { GroupLoader } from '../../lib/types/DataSources' -import { GroupValues, User } from '../types/testTypes' +import type { GroupLoader } from '../../lib/types/DataSources' +import type { GroupValues, User } from '../types/testTypes' import { cloneDeep } from '../utils/cloneUtils' export class TemporaryThrowingGroupedLoader implements GroupLoader { diff --git a/test/fakes/TemporaryThrowingLoader.ts b/test/fakes/TemporaryThrowingLoader.ts index 084a5cd..a1548ec 100644 --- a/test/fakes/TemporaryThrowingLoader.ts +++ b/test/fakes/TemporaryThrowingLoader.ts @@ -1,4 +1,4 @@ -import { Loader } from '../../lib/types/DataSources' +import type { Loader } from '../../lib/types/DataSources' export class TemporaryThrowingLoader implements Loader { name = 'Throwing loader' diff --git a/test/fakes/TestRedisConfig.ts b/test/fakes/TestRedisConfig.ts index 6768ce0..3949976 100644 --- a/test/fakes/TestRedisConfig.ts +++ b/test/fakes/TestRedisConfig.ts @@ -1,4 +1,4 @@ -import { RedisOptions } from 'ioredis' +import type { RedisOptions } from 'ioredis' export const redisOptions: RedisOptions = { host: 'localhost', diff --git a/test/fakes/ThrowingCache.ts b/test/fakes/ThrowingCache.ts index a6c9be7..6476d1a 100644 --- a/test/fakes/ThrowingCache.ts +++ b/test/fakes/ThrowingCache.ts @@ -1,4 +1,4 @@ -import { Cache } from '../../lib/types/DataSources' +import type { Cache } from '../../lib/types/DataSources' export class ThrowingCache implements Cache { name = 'Throwing cache' diff --git a/test/fakes/ThrowingGroupedCache.ts b/test/fakes/ThrowingGroupedCache.ts index 854832f..1cfc2e8 100644 --- a/test/fakes/ThrowingGroupedCache.ts +++ b/test/fakes/ThrowingGroupedCache.ts @@ -1,5 +1,5 @@ -import { GroupedCache } from '../../lib/types/DataSources' -import { User } from '../types/testTypes' +import type { GroupedCache } from '../../lib/types/DataSources' +import type { User } from '../types/testTypes' export class ThrowingGroupedCache implements GroupedCache { name = 'Throwing grouped cache' diff --git a/test/fakes/ThrowingGroupedLoader.ts b/test/fakes/ThrowingGroupedLoader.ts index 74bd23b..caba5d2 100644 --- a/test/fakes/ThrowingGroupedLoader.ts +++ b/test/fakes/ThrowingGroupedLoader.ts @@ -1,4 +1,4 @@ -import { GroupLoader } from '../../lib/types/DataSources' +import type { GroupLoader } from '../../lib/types/DataSources' export class ThrowingGroupedLoader implements GroupLoader { name = 'Throwing loader' diff --git a/test/fakes/ThrowingLoader.ts b/test/fakes/ThrowingLoader.ts index 7f34375..c97c1bf 100644 --- a/test/fakes/ThrowingLoader.ts +++ b/test/fakes/ThrowingLoader.ts @@ -1,4 +1,4 @@ -import { Loader } from '../../lib/types/DataSources' +import type { Loader } from '../../lib/types/DataSources' export class ThrowingLoader implements Loader { name = 'Throwing loader' diff --git a/tsconfig.json b/tsconfig.json index 2fdff98..4c0d748 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "outDir": "dist", - "module": "commonjs", + "module": "ES2022", "target": "ES2022", "sourceMap": true, "declaration": true,