This repository was archived by the owner on Feb 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdao.ts
76 lines (66 loc) · 2.22 KB
/
dao.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { UUID } from 'uuid-class';
import { DeviceDetectorResult } from 'device-detector-js';
export interface DAO {
init(): Promise<void>;
getDashboards(): Promise<Dashboard[]>;
cancelAll(toCancel: Dashboard[], toActivate?: Dashboard[]): Promise<void>;
monthlyViews(hostname: string, date?: Date): Promise<number>;
upsertDashboard(data: Dashboard): Promise<Required<Dashboard>>;
getDashboard(id: UUID): Promise<Required<Dashboard> | null>;
appendDomain(id: UUID, hostname: string): Promise<Required<Dashboard>>;
removeDomain(id: UUID, hostname: string): Promise<Required<Dashboard>>;
relocateDashboard(oldId: UUID, newId: UUID): Promise<Required<Dashboard>>;
updateClaps(data: ClapData, options: UpdateOptions): Promise<ClapCount>;
getClaps({ href }: { href: string }): Promise<{ [href: string]: ClapCount }>;
getClapsAndUpdateViews(data: ViewData, options: UpdateOptions): Promise<{ [href: string]: ClapCount }>;
getStats(did: UUID, timeFrame?: [number, TimeUnit]): Promise<StatsData>;
getLog(did: UUID, timeFrame?: [number, TimeUnit]): Promise<LogEntry[]>;
}
export interface Dashboard {
id: UUID,
hostname?: string[],
active?: boolean,
[k: string]: any,
}
interface ViewDataLike {
hostname: string,
href: string,
country?: string | null,
visitor?: UUID | null,
device?: DeviceDetectorResult | null,
}
export interface ClapData extends ViewDataLike {
hash: string,
id: UUID,
claps: number,
nonce: number,
}
export interface ViewData extends ViewDataLike {
referrer?: string | null,
}
export interface UpdateOptions {
dnt?: boolean,
originHostname: string,
}
export interface ClapCount {
claps: number
}
export interface StatsData {
totalClaps: number,
totalClappers: number,
totalViews: number,
visitors: number,
views: { href: string, views: number }[],
claps: { href: string, claps: number, clappers: number }[],
countries: { country: string, views: number }[],
referrals: { referrer: string, referrals: number }[],
}
export interface LogEntry {
href: string,
visitor: UUID,
country: string,
referrer: string,
claps: number,
ts: Date
}
export type TimeUnit = 'day' | 'days' | 'half day' | 'half days' | 'hour' | 'hours' | 'minute' | 'minutes' | 'second' | 'seconds';