Skip to content

Commit 955eae9

Browse files
authored
Integrate rollup (#236)
1 parent d18df11 commit 955eae9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+163
-86
lines changed

.eslintrc.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"extends": [
33
"eslint:recommended",
44
"plugin:@typescript-eslint/recommended",
5-
"plugin:prettier/recommended"
5+
"plugin:prettier/recommended",
6+
"plugin:import/recommended",
7+
"plugin:import/typescript"
68
],
79
"plugins": [
810
"@typescript-eslint",
@@ -31,6 +33,7 @@
3133
],
3234
"no-var": "off",
3335
"@typescript-eslint/ban-ts-comment": "off",
36+
"@typescript-eslint/consistent-type-imports": "warn",
3437
"@typescript-eslint/no-non-null-assertion": "off",
3538
"@typescript-eslint/no-var-requires": "off",
3639
"@typescript-eslint/indent": "off",

lib/AbstractGroupedOperation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AbstractOperation } from './AbstractOperation'
2-
import { GroupedCache } from './types/DataSources'
2+
import type { GroupedCache } from './types/DataSources'
33

44
export abstract class AbstractGroupedOperation<LoadedValue, ResolveParams = undefined> extends AbstractOperation<
55
LoadedValue,

lib/AbstractOperation.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { InMemoryCache, InMemoryCacheConfiguration, NoopCache } from './memory'
2-
import { SynchronousGroupedCache } from './types/SyncDataSources'
3-
import { Cache } from './types/DataSources'
4-
import { defaultLogger, Logger } from './Logger'
1+
import type { InMemoryCacheConfiguration } from './memory'
2+
import { InMemoryCache, NoopCache } from './memory'
3+
import type { SynchronousGroupedCache } from './types/SyncDataSources'
4+
import type { Cache } from './types/DataSources'
5+
import type { Logger } from './Logger'
6+
import { defaultLogger } from './Logger'
57

68
export type LoaderErrorHandler = (
79
err: Error,

lib/GroupedCachingOperation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { GroupedCache } from './types/DataSources'
2-
import { CommonOperationConfig } from './AbstractOperation'
1+
import type { GroupedCache } from './types/DataSources'
2+
import type { CommonOperationConfig } from './AbstractOperation'
33
import { AbstractGroupedOperation } from './AbstractGroupedOperation'
44

55
export type GroupedCachingOperationConfig<LoadedValue> = CommonOperationConfig<LoadedValue, GroupedCache<LoadedValue>>

lib/GroupedLoadingOperation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { GroupedCache, GroupLoader } from './types/DataSources'
2-
import { LoadingOperationConfig } from './LoadingOperation'
1+
import type { GroupedCache, GroupLoader } from './types/DataSources'
2+
import type { LoadingOperationConfig } from './LoadingOperation'
33
import { AbstractGroupedOperation } from './AbstractGroupedOperation'
44

55
export type GroupedLoadingOperationConfig<LoadedValue, LoaderParams = undefined> = LoadingOperationConfig<

lib/LoadingOperation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { CommonOperationConfig } from './AbstractOperation'
2-
import { Cache, Loader } from './types/DataSources'
1+
import type { CommonOperationConfig } from './AbstractOperation'
2+
import type { Cache, Loader } from './types/DataSources'
33
import { AbstractFlatOperation } from './AbstractFlatOperation'
44

55
export type LoadingOperationConfig<

lib/memory/InMemoryCache.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import { fifo, fifoObject, lru, lruObject, ToadCache } from 'toad-cache'
2-
import { SynchronousCache, SynchronousGroupedCache } from '../types/SyncDataSources'
3-
import { CacheConfiguration } from '../types/DataSources'
1+
import type { CacheConstructor, ToadCache } from 'toad-cache'
2+
import { FifoMap, FifoObject, LruMap, LruObject } from 'toad-cache'
3+
import type { SynchronousCache, SynchronousGroupedCache } from '../types/SyncDataSources'
4+
import type { CacheConfiguration } from '../types/DataSources'
5+
6+
type CacheTypeId = 'lru-map' | 'fifo-map' | 'lru-object' | 'fifo-object'
47

58
export interface InMemoryCacheConfiguration extends CacheConfiguration {
6-
cacheType?: 'lru' | 'fifo' | 'lru-object' | 'fifo-object'
7-
groupCacheType?: 'lru' | 'fifo' | 'lru-object' | 'fifo-object'
9+
cacheType?: CacheTypeId
10+
groupCacheType?: CacheTypeId
811
maxItems?: number
912
maxGroups?: number
1013
maxItemsPerGroup?: number
@@ -25,31 +28,31 @@ export class InMemoryCache<T> implements SynchronousCache<T>, SynchronousGrouped
2528
name = 'In-memory cache'
2629
private readonly ttlInMsecs: number | undefined
2730
public readonly ttlLeftBeforeRefreshInMsecs?: number
28-
private readonly cacheConstructor: <T = any>(max?: number, ttl?: number) => ToadCache<T>
29-
private readonly groupCacheConstructor: <T = any>(max?: number, ttl?: number) => ToadCache<T>
31+
private readonly cacheConstructor: CacheConstructor<ToadCache<T>>
32+
private readonly groupCacheConstructor: CacheConstructor<ToadCache<ToadCache<T | null>>>
3033

3134
constructor(config: InMemoryCacheConfiguration) {
32-
this.cacheConstructor = this.resolveCacheConstructor(config.cacheType ?? DEFAULT_CONFIGURATION.cacheType)
33-
this.groupCacheConstructor = this.resolveCacheConstructor(
35+
this.cacheConstructor = this.resolveCacheConstructor<T>(config.cacheType ?? DEFAULT_CONFIGURATION.cacheType)
36+
this.groupCacheConstructor = this.resolveCacheConstructor<ToadCache<T | null>>(
3437
config.groupCacheType ?? DEFAULT_CONFIGURATION.groupCacheType
3538
)
3639

37-
this.cache = this.cacheConstructor(config.maxItems ?? DEFAULT_CONFIGURATION.maxItems, config.ttlInMsecs ?? 0)
38-
this.groups = this.groupCacheConstructor(config.maxGroups ?? DEFAULT_CONFIGURATION.maxGroups)
40+
this.cache = new this.cacheConstructor(config.maxItems ?? DEFAULT_CONFIGURATION.maxItems, config.ttlInMsecs ?? 0)
41+
this.groups = new this.groupCacheConstructor(config.maxGroups ?? DEFAULT_CONFIGURATION.maxGroups)
3942
this.maxItemsPerGroup = config.maxItemsPerGroup ?? DEFAULT_CONFIGURATION.maxItemsPerGroup
4043
this.ttlInMsecs = config.ttlInMsecs
4144
this.ttlLeftBeforeRefreshInMsecs = config.ttlLeftBeforeRefreshInMsecs
4245
}
4346

44-
private resolveCacheConstructor(cacheTypeId: 'lru' | 'fifo' | 'lru-object' | 'fifo-object') {
45-
if (cacheTypeId === 'fifo') {
46-
return fifo
47-
} else if (cacheTypeId === 'lru') {
48-
return lru
47+
private resolveCacheConstructor<T>(cacheTypeId: CacheTypeId): CacheConstructor<ToadCache<T>> {
48+
if (cacheTypeId === 'fifo-map') {
49+
return FifoMap
50+
} else if (cacheTypeId === 'lru-map') {
51+
return LruMap
4952
} else if (cacheTypeId === 'fifo-object') {
50-
return fifoObject
53+
return FifoObject
5154
} else {
52-
return lruObject
55+
return LruObject
5356
}
5457
}
5558

@@ -59,7 +62,7 @@ export class InMemoryCache<T> implements SynchronousCache<T>, SynchronousGrouped
5962
return groupCache
6063
}
6164

62-
const newGroupCache = this.cacheConstructor(this.maxItemsPerGroup, this.ttlInMsecs)
65+
const newGroupCache = new this.cacheConstructor(this.maxItemsPerGroup, this.ttlInMsecs)
6366
this.groups.set(groupId, newGroupCache)
6467
return newGroupCache
6568
}

lib/memory/NoopCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SynchronousCache, SynchronousGroupedCache } from '../types/SyncDataSources'
1+
import type { SynchronousCache, SynchronousGroupedCache } from '../types/SyncDataSources'
22

33
export class NoopCache<T> implements SynchronousCache<T>, SynchronousGroupedCache<T> {
44
name = 'Noop cache'

lib/redis/RedisCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Cache, CacheConfiguration, GroupedCache, Loader } from '../types/DataSources'
1+
import type { Cache, CacheConfiguration, GroupedCache, Loader } from '../types/DataSources'
22
import type { Redis } from 'ioredis'
33
import { RedisTimeoutError } from './RedisTimeoutError'
44
import { GET_OR_SET_ZERO_WITH_TTL, GET_OR_SET_ZERO_WITHOUT_TTL } from './lua'

lib/redis/RedisExpirationTimeGroupedLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GroupedCache, GroupLoader } from '../types/DataSources'
1+
import type { GroupedCache, GroupLoader } from '../types/DataSources'
22

33
export class RedisExpirationTimeGroupedLoader implements GroupLoader<number> {
44
public readonly name = 'RedisExpirationTimeGroupedLoader'

0 commit comments

Comments
 (0)