-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtypes.ts
62 lines (55 loc) · 1.38 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type { Cache as SWRCache } from 'swr'
import type { IDBPDatabase } from 'idb'
/**
* Configuration options
*/
export type Config = {
/** Database Name */
dbName: string,
/** Store name */
storeName: string,
/** Storage handler */
storageHandler?: StorageHandler,
/** Schema version; use when switching storage handlers on same database and store */
version?: number,
/** Error handler */
onError?: (reason: any) => void,
}
/**
* Cache provider interface, missing in swr
*/
export type CacheProvider<Data = any> = (globalCache: Readonly<SWRCache<Data>>) => SWRCache<Data>
/**
* Use cache provider interface
*/
export type UseCacheProvider<Data = any> = (props: Config) => CacheProvider<Data> | undefined
/**
* Storage handler for Transferrable object
*/
export interface StorageHandler<Data = any, StoreObject = any> {
/**
* Initialize
*/
initialize(
upgradeDb: IDBPDatabase<unknown>,
storeName: string,
): void
/**
* Upgrade
*/
upgrade(
upgradeDb: IDBPDatabase<unknown>,
storeName: string,
oldVesion: number,
): void
/**
* Value replacer on db put
* Return undefined ignore item persistence
*/
replace: (key: string, value: Data) => StoreObject | undefined,
/**
* Value reviver on db get
* Return undefined to remove item from cache
*/
revive: (key: string, storeObject: StoreObject) => Data | undefined,
}