Skip to content

Commit aba3b48

Browse files
committed
add new features
1 parent 0860059 commit aba3b48

File tree

27 files changed

+386
-31
lines changed

27 files changed

+386
-31
lines changed

src/core/cache/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ Changelog
99
> - :house: [Internal]
1010
> - :nail_care: [Polish]
1111
12+
## v3.??.? (2022-0?-??)
13+
14+
#### :rocket: New Feature
15+
16+
* Add a new method `clone`
17+
18+
#### :boom: Breaking Change
19+
20+
* Change type parameters from `<V, K>` to `<K, V>`
21+
1222
## v3.50.0 (2021-06-07)
1323

1424
#### :rocket: New Feature

src/core/cache/decorators/helpers/add-emitter/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Changelog
99
> - :house: [Internal]
1010
> - :nail_care: [Polish]
1111
12+
## v3.??.? (2022-0?-??)
13+
14+
#### :boom: Breaking Change
15+
16+
* Change type parameters from `<V, K>` to `<K, V>`
17+
1218
## v3.59.1 (2021-09-21)
1319

1420
#### :bug: Bug Fix

src/core/cache/decorators/helpers/add-emitter/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ export const
4040
*
4141
* @param cache
4242
*/
43-
const addEmitter: AddEmitter = <T extends Cache<V, K>, V = unknown, K extends string = string>(cache) => {
43+
const addEmitter: AddEmitter = <T extends Cache<K, V>, K = unknown, V = unknown>(cache: T) => {
4444
const
45-
expandedCache = <Overwrite<CacheWithEmitter<V, K, T>, {[eventEmitter]?: EventEmitter}>><unknown>cache;
45+
expandedCache = <Overwrite<CacheWithEmitter<K, V, T>, {[eventEmitter]?: EventEmitter}>><unknown>cache;
4646

4747
const
48-
cacheWithEmitter = <CacheWithEmitter<V, K, T>>expandedCache;
48+
cacheWithEmitter = <CacheWithEmitter<K, V, T>>expandedCache;
4949

5050
let
5151
emitter;

src/core/cache/decorators/helpers/add-emitter/interface.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ export interface MutationHandler<M extends AnyFunction = AnyFunction> {
2525
(e: MutationEvent<M>): void;
2626
}
2727

28-
export interface CacheWithEmitter<V = unknown, K = string, T extends Cache<V, K> = Cache<V, K>> extends Cache<V, K> {
28+
export interface CacheWithEmitter<
29+
K = unknown,
30+
V = unknown,
31+
T extends Cache<K, V> = Cache<K, V>
32+
> extends Cache<K, V> {
2933
/** @override */
3034
set(key: K, value: V, opts?: Parameters<T['set']>[2]): V;
3135

@@ -36,9 +40,9 @@ export interface CacheWithEmitter<V = unknown, K = string, T extends Cache<V, K>
3640
}
3741

3842
export type AddEmitter =
39-
<T extends Cache<V, K>, V = unknown, K extends string = string>(cache: T) => AddEmitterReturn<T>;
43+
<T extends Cache<K, V>, K = unknown, V = unknown>(cache: T) => AddEmitterReturn<T>;
4044

41-
export interface AddEmitterReturn<T extends Cache<V, K>, V = unknown, K extends string = string> {
45+
export interface AddEmitterReturn<T extends Cache<K, V>, K = unknown, V = unknown> {
4246
/** @see [[Cache.set]] */
4347
set: T['set'];
4448

src/core/cache/decorators/persistent/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Changelog
99
> - :house: [Internal]
1010
> - :nail_care: [Polish]
1111
12+
## v3.??.? (2022-0?-??)
13+
14+
#### :boom: Breaking Change
15+
16+
* Change type parameters from `<V, K>` to `<K, V>`
17+
1218
## v3.60.2 (2021-10-04)
1319

1420
#### :bug: Bug Fix

src/core/cache/decorators/persistent/engines/active.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class ActivePersistentEngine<V> extends UncheckablePersistentEngi
1818
*/
1919
protected ttlIndex: Dictionary<number> = Object.createDict();
2020

21-
override async initCache(cache: Cache<V>): Promise<void> {
21+
override async initCache(cache: Cache<string, V>): Promise<void> {
2222
if (await this.storage.has(INDEX_STORAGE_NAME)) {
2323
this.ttlIndex = (await this.storage.get<Dictionary<number>>(INDEX_STORAGE_NAME))!;
2424

src/core/cache/decorators/persistent/engines/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface AbstractPersistentEngine<V = unknown> {
1616
* Initializes a new cache instance from the past one
1717
* @param cache
1818
*/
19-
initCache?(cache: Cache<V>): CanPromise<void>;
19+
initCache?(cache: Cache<unknown, V>): CanPromise<void>;
2020
}
2121

2222
export abstract class AbstractPersistentEngine<V = unknown> {

src/core/cache/decorators/persistent/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ export * from 'core/cache/decorators/persistent/interface';
5050
* ```
5151
*/
5252
const addPersistent = <V>(
53-
cache: Cache<V, string>,
53+
cache: Cache<string, V>,
5454
storage: SyncStorageNamespace | AsyncStorageNamespace,
5555
opts?: PersistentOptions
56-
): Promise<PersistentCache<V>> => new PersistentWrapper<Cache<V, string>, V>(cache, storage, opts).getInstance();
56+
): Promise<PersistentCache<string, V>> =>
57+
new PersistentWrapper<Cache<string, V>, V>(cache, storage, opts).getInstance();
5758

5859
export default addPersistent;

src/core/cache/decorators/persistent/interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import type { CacheWithEmitter } from 'core/cache/decorators/helpers/add-emitter/interface';
1010
import type { eventEmitter } from 'core/cache/decorators/helpers/add-emitter';
1111

12-
export type PersistentCache<V = unknown, K = string, T extends CacheWithEmitter<V, K> = CacheWithEmitter<V, K>> = {
13-
[key in Exclude<(keyof CacheWithEmitter<V, K>), 'set' | 'size' | typeof eventEmitter>]: ReturnPromise<CacheWithEmitter<V, K>[key]>
12+
export type PersistentCache<K = string, V = unknown, T extends CacheWithEmitter<K, V> = CacheWithEmitter<K, V>> = {
13+
[key in Exclude<(keyof CacheWithEmitter<K, V>), 'set' | 'size' | typeof eventEmitter>]: ReturnPromise<CacheWithEmitter<K, V>[key]>
1414
} & {
1515
/** @see [[Cache.size]] */
1616
size: [T['size']];

src/core/cache/decorators/persistent/wrapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import addEmitter from 'core/cache/decorators/helpers/add-emitter';
1818
import type { PersistentEngine, CheckablePersistentEngine } from 'core/cache/decorators/persistent/engines/interface';
1919
import type { PersistentOptions, PersistentCache, PersistentTTLDecoratorOptions } from 'core/cache/decorators/persistent/interface';
2020

21-
export default class PersistentWrapper<T extends Cache<V, string>, V = unknown> {
21+
export default class PersistentWrapper<T extends Cache<string, V>, V = unknown> {
2222
/**
2323
* Default TTL to store items
2424
*/
@@ -32,7 +32,7 @@ export default class PersistentWrapper<T extends Cache<V, string>, V = unknown>
3232
/**
3333
* Wrapped cache object
3434
*/
35-
protected readonly wrappedCache: PersistentCache<V>;
35+
protected readonly wrappedCache: PersistentCache<string, V>;
3636

3737
/**
3838
* Engine to save cache items within a storage
@@ -61,7 +61,7 @@ export default class PersistentWrapper<T extends Cache<V, string>, V = unknown>
6161
/**
6262
* Returns an instance of the wrapped cache
6363
*/
64-
async getInstance(): Promise<PersistentCache<V>> {
64+
async getInstance(): Promise<PersistentCache<string, V>> {
6565
if (this.engine.initCache) {
6666
await this.engine.initCache(this.cache);
6767
}
@@ -80,7 +80,7 @@ export default class PersistentWrapper<T extends Cache<V, string>, V = unknown>
8080
set: originalSet,
8181
clear: originalClear,
8282
subscribe
83-
} = addEmitter<T, V, string>(this.cache);
83+
} = addEmitter<T, string, V>(this.cache);
8484

8585
this.wrappedCache.has = this.getDefaultImplementation('has');
8686
this.wrappedCache.get = this.getDefaultImplementation('get');

0 commit comments

Comments
 (0)