-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathschemas.ts
More file actions
56 lines (46 loc) · 1.36 KB
/
schemas.ts
File metadata and controls
56 lines (46 loc) · 1.36 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
import { z } from 'zod'
import { MAX_DAYS_AGO } from '@/features/dashboard/sandboxes/monitoring/time-picker/constants'
// PRIVATE
const _startDateSchema = z
.number()
.int()
.positive()
.describe('Unix timestamp in milliseconds')
.refine(
(start) => {
const now = Date.now()
return start >= now - MAX_DAYS_AGO
},
{
message: `Start date cannot be more than ${MAX_DAYS_AGO / (1000 * 60 * 60 * 24)} days ago`,
}
)
const _endDateSchema = z
.number()
.int()
.positive()
.describe('Unix timestamp in milliseconds')
.refine((end) => end <= Date.now(), {
message: 'End date cannot be in the future',
})
const _dateRangeRefine = (data: { startDate: number; endDate: number }) => {
return data.endDate - data.startDate <= MAX_DAYS_AGO
}
const _dateRangeRefineMessage = {
message: `Date range cannot exceed ${MAX_DAYS_AGO / (1000 * 60 * 60 * 24)} days`,
}
// PUBLIC
export const MAX_SANDBOX_IDS_PER_REQUEST = 100
export const GetTeamMetricsSchema = z
.object({
startDate: _startDateSchema,
endDate: _endDateSchema,
})
.refine(_dateRangeRefine, _dateRangeRefineMessage)
export const GetTeamMetricsMaxSchema = z
.object({
startDate: _startDateSchema,
endDate: _endDateSchema,
metric: z.enum(['concurrent_sandboxes', 'sandbox_start_rate']),
})
.refine(_dateRangeRefine, _dateRangeRefineMessage)