forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.d.ts
More file actions
145 lines (130 loc) · 3.29 KB
/
backup.d.ts
File metadata and controls
145 lines (130 loc) · 3.29 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* @since 1.2.0
*/
declare namespace timer.backup {
type Client = {
id: string
name: string
minDate?: string
maxDate?: string
}
type LoginInfo = {
acc?: string
psw?: string
}
type Auth = {
token?: string
login?: LoginInfo
}
interface CoordinatorContext<Cache> {
cid: string
auth?: Auth
login?: LoginInfo
ext?: TypeExt
cache: Cache
handleCacheChanged: () => Promise<void>
}
/**
* timer.backup.Coordinator of data synchronizer
*/
interface Coordinator<Cache> {
/**
* Register for client
*/
updateClients(context: timer.backup.CoordinatorContext<Cache>, clients: Client[]): Promise<void>
/**
* List all clients
*/
listAllClients(context: timer.backup.CoordinatorContext<Cache>): Promise<Client[]>
/**
* Download fragmented data from cloud
*
* @param targetCid The client id, default value is the local one in context
*/
download(context: timer.backup.CoordinatorContext<Cache>, dateStart: Date, dateEnd: Date, targetCid?: string): Promise<timer.core.Row[]>
/**
* Upload fragmented data to cloud
* @param rows
*/
upload(context: timer.backup.CoordinatorContext<Cache>, rows: timer.core.Row[]): Promise<void>
/**
* Test auth
*
* @returns errorMsg or null/undefined
*/
testAuth(auth: Auth, ext: timer.backup.TypeExt): Promise<string | undefined>
/**
* Clear data
*/
clear(context: timer.backup.CoordinatorContext<Cache>, client: timer.backup.Client): Promise<void>
}
type Type =
| 'none'
| 'gist'
// Sync into Obsidian via its plugin Local REST API
// @since 1.9.4
| 'obsidian_local_rest_api'
// @since 2.4.5
| 'web_dav'
type AuthType =
| 'token'
| 'password'
type TypeExt = {
/**
* The vault of obsidian
*
* @since 2.4.4
*/
bucket?: string
endpoint?: string
dirPath?: string
}
/**
* Snapshot of last backup
*/
type Snapshot = {
/**
* Timestamp
*/
ts: number
/**
* The date of the ts
*/
date: string
}
/**
* Snapshot cache
*/
type SnapshotCache = Partial<{
[type in Type]: Snapshot
}>
type MetaCache = Partial<Record<Type, unknown>>
type RowExtend = {
/**
* The id of client where the remote data is stored
*/
cid?: string
/**
* The name of client where the remote data is stored
*/
cname?: string
}
type Row = core.Row & RowExtend
/**
* The data format for export and import
*/
type ExportMeta = {
version: string
ts: number
}
type ExportData = {
__meta__: ExportMeta
__stat__?: timer.core.Row[]
__limit__?: timer.limit.Rule[]
__merge__?: timer.merge.Rule[]
__whitelist__?: string[]
__cate__?: timer.site.Cate[]
// Legacy data before v4.0.0
[key: string]: unknown
}
}