-
Notifications
You must be signed in to change notification settings - Fork 0
/
statsState.ts
68 lines (58 loc) · 1.37 KB
/
statsState.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
import { EntityStorage } from '@aleph-indexer/core'
import { TimeFrame } from '../../time.js'
export enum StatsStateState {
Processing = 0,
Processed = 1,
}
export type StatsState = {
account: string
type: string
timeFrame: TimeFrame
startDate: number
endDate: number
state: StatsStateState
}
/**
* Stats Entity Storage.
*/
export type StatsStateStorage = EntityStorage<StatsState>
export enum StatsStateDALIndex {
AccountTypeState = 'account_type_state',
}
const accountKey = {
get: (e: StatsState) => e.account,
length: EntityStorage.AddressLength,
}
const typeKey = {
get: (e: StatsState) => e.type,
length: EntityStorage.VariableLength,
}
const timeFrameKey = {
get: (e: StatsState) => e.timeFrame,
length: 2,
}
// @note: start date in millis of the interval
const startDateKey = {
get: (e: StatsState) => e.startDate,
length: EntityStorage.TimestampLength,
}
const stateKey = {
get: (e: StatsState) => e.state || StatsStateState.Processing,
length: 1,
}
/**
* Creates a stats Entity Storage.
*/
export function createStatsStateDAL(path: string): StatsStateStorage {
return new EntityStorage<StatsState>({
name: 'stats_state',
path,
key: [accountKey, typeKey, timeFrameKey, startDateKey],
indexes: [
{
name: StatsStateDALIndex.AccountTypeState,
key: [accountKey, typeKey, stateKey],
},
],
})
}