-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathworking-exercise.ts
More file actions
156 lines (137 loc) · 4.83 KB
/
working-exercise.ts
File metadata and controls
156 lines (137 loc) · 4.83 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
146
147
148
149
150
151
152
153
154
155
156
import { z } from 'zod'
import { MuscleGroup } from './muscle-group'
import { LoadingType } from './weight-snapping'
export enum WorkoutExerciseState {
loading = 'loading',
testing = 'testing',
tested = 'tested',
pending = 'pending',
finished = 'finished',
loaded = 'loaded',
}
export enum WorkingSetState {
failed = 'failed',
done = 'done',
pending = 'pending',
}
export enum ExerciseAssesmentScore {
Ideal = 'ideal',
Hard = 'hard',
}
export enum HardAssesmentTag {
TooHeavy = 'too_heavy',
TooHighVolume = 'too_high_volume',
BadForm = 'bad_form',
Other = 'other',
}
export enum ProgressionMode {
LiftCoach = 'liftcoach',
Custom = 'custom',
}
export enum ProgressionType {
KeepProgressSuboptimalLifestyle = 'keep_progress_suboptimal_lifestyle',
ProgressedReps = 'progressed_reps',
NoProgressFailure = 'no_progress_failure',
LoweredWeightTooHeavy = 'lowered_weight_too_heavy',
LoweredWeightBadForm = 'lowered_weight_bad_form',
LoweredWeightTooManyFailures = 'lowered_weight_too_many_failures',
RegressTooMuchVolume = 'regress_too_much_volume',
CustomUserProvided = 'custom_user_provided',
}
const progressionTypeSchema = z.nativeEnum(ProgressionType)
const failedSetSchema = z.object({
id: z.string().uuid(),
state: z.literal(WorkingSetState.failed),
orderIndex: z.number(),
weight: z.number(),
reps: z.number(),
})
const doneSetSchema = z.object({
id: z.string().uuid(),
state: z.literal(WorkingSetState.done),
orderIndex: z.number(),
weight: z.number(),
reps: z.number(),
})
const pendingSetSchema = z.object({
id: z.string().uuid(),
state: z.literal(WorkingSetState.pending),
orderIndex: z.number(),
weight: z.number().nullable(),
reps: z.number().nullable(),
})
export const exerciseSchema = z.object({
id: z.string().uuid(),
name: z.string(),
muscleGroup: z.nativeEnum(MuscleGroup),
loadingType: z.nativeEnum(LoadingType),
})
export type Exercise = z.infer<typeof exerciseSchema>
export const workingSetSchema = z.discriminatedUnion('state', [failedSetSchema, doneSetSchema, pendingSetSchema])
export type WorkingSet = z.infer<typeof workingSetSchema>
export const loadingSetSchema = z.object({
weight: z.number(),
reps: z.number(),
})
export type LoadingSet = z.infer<typeof loadingSetSchema>
const workingExerciseBaseSchema = z.object({
id: z.string().uuid(),
createdAt: z.string().datetime(),
exercise: exerciseSchema,
orderIndex: z.number(),
targetSets: z.number(),
targetReps: z.number(),
})
export const loadingWorkingExerciseSchema = workingExerciseBaseSchema.extend({
state: z.literal(WorkoutExerciseState.loading),
sets: z.array(z.never()),
})
export type LoadingWorkingExercise = z.infer<typeof loadingWorkingExerciseSchema>
export const testingWorkingExerciseSchema = workingExerciseBaseSchema.extend({
state: z.literal(WorkoutExerciseState.testing),
testingWeight: z.number(),
sets: z.array(z.never()),
})
export type TestingWorkingExercise = z.infer<typeof testingWorkingExerciseSchema>
export const testedWorkingExerciseScehma = workingExerciseBaseSchema.extend({
state: z.literal(WorkoutExerciseState.tested),
loadingSet: loadingSetSchema,
sets: z.array(workingSetSchema),
})
export type TestedWorkingExercise = z.infer<typeof testedWorkingExerciseScehma>
export const loadedWorkingExerciseSchema = workingExerciseBaseSchema.extend({
state: z.literal(WorkoutExerciseState.loaded),
loadingSet: loadingSetSchema,
sets: z.array(workingSetSchema),
})
export type LoadedWorkingExercise = z.infer<typeof loadedWorkingExerciseSchema>
const exerciseAssesmentIdeal = z.object({
assesment: z.literal(ExerciseAssesmentScore.Ideal),
})
const exerciseAssesmentHard = z.object({
assesment: z.literal(ExerciseAssesmentScore.Hard),
assesmentTag: z.nativeEnum(HardAssesmentTag),
})
export const exerciseAssesment = z.discriminatedUnion('assesment', [exerciseAssesmentIdeal, exerciseAssesmentHard])
export type ExerciseAssesment = z.infer<typeof exerciseAssesment>
export const finishedWorkingExerciseSchema = workingExerciseBaseSchema.extend({
state: z.literal(WorkoutExerciseState.finished),
sets: z.array(workingSetSchema),
exerciseAssesment: exerciseAssesment.nullable(),
})
export type FinishedWorkingExercise = z.infer<typeof finishedWorkingExerciseSchema>
export const pendingWorkingExerciseSchema = workingExerciseBaseSchema.extend({
state: z.literal(WorkoutExerciseState.pending),
progressionType: progressionTypeSchema,
sets: z.array(workingSetSchema),
})
export type PendingWorkingExercise = z.infer<typeof pendingWorkingExerciseSchema>
export const workingExerciseSchema = z.discriminatedUnion('state', [
finishedWorkingExerciseSchema,
pendingWorkingExerciseSchema,
loadedWorkingExerciseSchema,
loadingWorkingExerciseSchema,
testingWorkingExerciseSchema,
testedWorkingExerciseScehma,
])
export type WorkingExercise = z.infer<typeof workingExerciseSchema>