-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathswrCache.ts
More file actions
107 lines (79 loc) · 3.01 KB
/
swrCache.ts
File metadata and controls
107 lines (79 loc) · 3.01 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import type { AccountAddress, FindThreadQuery } from '@dialectlabs/sdk';
// v2 cache keys
export const CACHE_KEY_HISTORY = (appId: string) => ['HISTORY', appId];
export const CACHE_KEY_HISTORY_SUMMARY = (
walletAddress: string,
appId: string,
) => ['HISTORY_SUMMARY', walletAddress, appId];
export const CACHE_KEY_SUBSCRIBE_MUTATION = (
appId: string,
channel: string | string[],
) => ['SUBSCRIBE', appId, channel];
export const CACHE_KEY_UNSUBSCRIBE_MUTATION = (
appId: string,
channel: string | string[],
) => ['UNSUBSCRIBE', appId, channel];
export const CACHE_KEY_EMAIL_PREPARE_MUTATION = () => ['EMAIL_PREPARE'];
export const CACHE_KEY_EMAIL_VERIFY_MUTATION = () => ['EMAIL_VERIFY'];
export const CACHE_KEY_EMAIL_UNLINK_MUTATION = () => ['EMAIL_UNLINK'];
export const CACHE_KEY_EMAIL_RESEND_MUTATION = () => ['EMAIL_RESEND'];
export const CACHE_KEY_TELEGRAM_PREPARE_MUTATION = () => ['TELEGRAM_PREPARE'];
export const CACHE_KEY_TELEGRAM_UNLINK_MUTATION = () => ['TELEGRAM_UNLINK'];
export const CACHE_KEY_CHANNELS = (appId?: string | null, type?: string) => [
'CHANNELS',
appId,
type,
];
export const CACHE_KEY_TOPICS = () => ['TOPICS'];
export const CACHE_KEY_READ_MUTATION = (appId: string) => [
'READ_HISTORY',
appId,
];
export const CACHE_KEY_CLEAR_MUTATION = (appId: string) => [
'CLEAR_HISTORY',
appId,
];
// v1 cache keys
export const CACHE_KEY_THREADS = 'THREADS';
export const CACHE_KEY_THREAD_FN = (findParams: FindThreadQuery): string => {
const prefix = 'THREAD_';
if ('id' in findParams) {
return prefix + findParams.id.toString();
}
if ('otherMembers' in findParams) {
return (
prefix +
findParams.otherMembers
.filter((it) => it)
.map((it) => it.toString())
.join(':')
);
}
throw new Error('should never happen');
};
export const CACHE_KEY_MESSAGES_FN = (id: string) => `MESSAGES_${id}`;
export const CACHE_KEY_THREAD_SUMMARY_FN = (otherMembers: AccountAddress[]) =>
'THREAD_SUMMARY_' +
otherMembers
.filter((it) => it)
.map((it) => it.toString())
.join(':');
export const CACHE_KEY_THREADS_SUMMARY = 'THREADS_GENERAL_SUMMARY';
export const DAPPS_CACHE_KEY = 'DAPPS';
export const DAPP_CACHE_KEY_FN = (walletAddress: AccountAddress) =>
'DAPPS_' + walletAddress;
export const DAPP_ADDRESSES_CACHE_KEY_FN = (dappAddress?: AccountAddress) =>
'DAPP_ADDRESSES_' + dappAddress;
export const WALLET_ADDRESSES_CACHE_KEY_FN = (walletAddress: AccountAddress) =>
'WALLET_ADDRESSES_' + walletAddress;
export const WALLET_DAPP_ADDRESSES_CACHE_KEY_FN = (
walletAddress: AccountAddress,
dappAddress: AccountAddress,
) => 'WALLET_DAPP_ADDRESSES_' + walletAddress + '_' + dappAddress;
export const WALLET_NOTIFICATION_SUBSCRIPTIONS_CACHE_KEY_FN = (
walletAddress: AccountAddress,
dappAddress: AccountAddress = '',
) => `WALLET_NOTIFICATION_SUBSCRIPTIONS_${walletAddress}${dappAddress}`;
export const DAPP_NOTIFICATION_SUBSCRIPTIONS_CACHE_KEY_FN = (
dappAddress?: AccountAddress,
) => 'DAPP_NOTIFICATION_SUBSCRIPTIONS_' + dappAddress;