@trainheroic-unofficial/dto 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/index.d.mts +197 -0
- package/dist/index.mjs +113 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alan Cohen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @trainheroic-unofficial/dto
|
|
2
|
+
|
|
3
|
+
Domain DTOs and zod schemas for the TrainHeroic API. This package is the single source of
|
|
4
|
+
truth for request and response shapes; the SDK, the MCP tool layer, and the CLI all import
|
|
5
|
+
their types from here instead of redefining them.
|
|
6
|
+
|
|
7
|
+
Part of the [trainheroic-unofficial](../../README.md) workspace.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
Internal to the workspace (consumed as `workspace:*`). Published builds expose a single ESM
|
|
12
|
+
entry with type declarations.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { workoutSpecSchema, type WorkoutSpec, idSchema } from "@trainheroic-unofficial/dto";
|
|
16
|
+
|
|
17
|
+
const spec: WorkoutSpec = workoutSpecSchema.parse(input);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## What's inside
|
|
21
|
+
|
|
22
|
+
Schemas come in two flavors. Input schemas are strict enough to validate user-supplied
|
|
23
|
+
data such as workout specs, exercise-create bodies, and message drafts. Response schemas
|
|
24
|
+
are deliberately tolerant: they use loose objects and accept a number or a numeric string
|
|
25
|
+
for ids, so upstream API drift adds fields without breaking parsing.
|
|
26
|
+
|
|
27
|
+
`src/` is organized by domain (`common`, `exercise`, `workout`, `messaging`, `responses`),
|
|
28
|
+
re-exported through `index.ts`. The central pieces:
|
|
29
|
+
|
|
30
|
+
- `idSchema` normalizes the API's number-or-string ids.
|
|
31
|
+
- `workoutSpecSchema` / `WorkoutSpec` is the protocol used to build a session: an optional
|
|
32
|
+
top-level instruction plus an array of blocks, where each block carries an exercises
|
|
33
|
+
array and each exercise references a library id. `blockSpecSchema` and
|
|
34
|
+
`exerciseSpecSchema` are its parts; `leaderboardSpecSchema` covers red-zone leaderboards.
|
|
35
|
+
- The read-back types (`ReadResult` and friends) describe a decoded session, and `Advisory`
|
|
36
|
+
carries the unit notes and warnings the encoder produces.
|
|
37
|
+
- The `responses` module holds the tolerant schemas used to validate API payloads at
|
|
38
|
+
checkpoints without rejecting unknown fields.
|
|
39
|
+
|
|
40
|
+
## Develop
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pnpm build # tsdown -> dist (ESM + .d.mts)
|
|
44
|
+
pnpm typecheck
|
|
45
|
+
pnpm test # vitest
|
|
46
|
+
pnpm exec vitest run test/workout.test.ts # one file
|
|
47
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/common.d.ts
|
|
4
|
+
/** An entity id as it arrives over the wire — a number or a numeric string. */
|
|
5
|
+
declare const idSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
6
|
+
type Id = z.infer<typeof idSchema>;
|
|
7
|
+
/**
|
|
8
|
+
* An id as a tool argument: a number, or a string of digits. Unlike idSchema (which
|
|
9
|
+
* tolerates whatever the API sends back), this rejects non-numeric strings up front so
|
|
10
|
+
* a bad argument fails validation instead of becoming NaN in a URL or a query.
|
|
11
|
+
*/
|
|
12
|
+
declare const idArgSchema: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/exercise.d.ts
|
|
15
|
+
/** A library exercise row as the index stores it. */
|
|
16
|
+
type ExerciseRow = {
|
|
17
|
+
id: number;
|
|
18
|
+
title: string;
|
|
19
|
+
param_1_type: number | null;
|
|
20
|
+
param_2_type: number | null;
|
|
21
|
+
can_edit: number;
|
|
22
|
+
user_id: number | null;
|
|
23
|
+
use_count: number;
|
|
24
|
+
};
|
|
25
|
+
/** A row annotated with human-readable unit labels for display. */
|
|
26
|
+
type ExerciseView = ExerciseRow & {
|
|
27
|
+
param_1_unit: string | null;
|
|
28
|
+
param_2_unit: string | null;
|
|
29
|
+
};
|
|
30
|
+
/** The outcome of resolving a name: a single match (or null) plus ranked candidates. */
|
|
31
|
+
type ResolveResult = {
|
|
32
|
+
match: ExerciseView | null;
|
|
33
|
+
candidates: ExerciseView[];
|
|
34
|
+
};
|
|
35
|
+
/** Body for creating a custom exercise; extra fields the API accepts are preserved. */
|
|
36
|
+
declare const exerciseCreateSchema: z.ZodObject<{
|
|
37
|
+
title: z.ZodString;
|
|
38
|
+
param_1_type: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
param_2_type: z.ZodOptional<z.ZodNumber>;
|
|
40
|
+
}, z.core.$loose>;
|
|
41
|
+
type ExerciseCreate = z.infer<typeof exerciseCreateSchema>;
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/messaging.d.ts
|
|
44
|
+
/** A chat comment to draft or send: target stream, body text, optional threaded reply. */
|
|
45
|
+
declare const commentDraftSchema: z.ZodObject<{
|
|
46
|
+
streamId: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
47
|
+
text: z.ZodString;
|
|
48
|
+
replyTo: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
type CommentDraft = z.infer<typeof commentDraftSchema>;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/responses.d.ts
|
|
53
|
+
/** An exercise as the library + create endpoints return it (only the fields we read). */
|
|
54
|
+
declare const exerciseResponseSchema: z.ZodObject<{
|
|
55
|
+
id: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
|
|
56
|
+
title: z.ZodString;
|
|
57
|
+
param_1_type: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodNull]>>;
|
|
58
|
+
param_2_type: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodNull]>>;
|
|
59
|
+
}, z.core.$loose>;
|
|
60
|
+
/** The exercise library list (envelope already unwrapped). */
|
|
61
|
+
declare const exerciseLibraryResponseSchema: z.ZodArray<z.ZodObject<{
|
|
62
|
+
id: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
|
|
63
|
+
title: z.ZodString;
|
|
64
|
+
param_1_type: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodNull]>>;
|
|
65
|
+
param_2_type: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodNull]>>;
|
|
66
|
+
}, z.core.$loose>>;
|
|
67
|
+
/** The create-session response (a programWorkout): we read workout_id + id. */
|
|
68
|
+
declare const sessionCreateResponseSchema: z.ZodObject<{
|
|
69
|
+
workout_id: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
|
|
70
|
+
id: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
|
|
71
|
+
}, z.core.$loose>;
|
|
72
|
+
/** A programWorkout from the calendar edit view (we match by id and walk sets). */
|
|
73
|
+
declare const programWorkoutResponseSchema: z.ZodObject<{
|
|
74
|
+
id: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
|
|
75
|
+
sets: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
76
|
+
}, z.core.$loose>;
|
|
77
|
+
/** The calendar edit-view response we read sessions back from. */
|
|
78
|
+
declare const programsEditResponseSchema: z.ZodObject<{
|
|
79
|
+
programWorkouts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
80
|
+
id: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
|
|
81
|
+
sets: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
82
|
+
}, z.core.$loose>>>;
|
|
83
|
+
}, z.core.$loose>;
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/workout.d.ts
|
|
86
|
+
/** A single exercise prescription inside a block. */
|
|
87
|
+
declare const exerciseSpecSchema: z.ZodObject<{
|
|
88
|
+
id: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
|
|
89
|
+
title: z.ZodOptional<z.ZodString>;
|
|
90
|
+
reps: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>]>>;
|
|
91
|
+
sets: z.ZodOptional<z.ZodNumber>;
|
|
92
|
+
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodArray<z.ZodNumber>]>>;
|
|
93
|
+
rpe: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
94
|
+
instr: z.ZodOptional<z.ZodString>;
|
|
95
|
+
param_1_type: z.ZodOptional<z.ZodNumber>;
|
|
96
|
+
param_2_type: z.ZodOptional<z.ZodNumber>;
|
|
97
|
+
}, z.core.$strip>;
|
|
98
|
+
type ExerciseSpec = z.infer<typeof exerciseSpecSchema>;
|
|
99
|
+
/** A block's Red-Zone leaderboard: a unit string/number, or an object with options. */
|
|
100
|
+
declare const leaderboardSpecSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodObject<{
|
|
101
|
+
unit: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
102
|
+
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
103
|
+
lowest_wins: z.ZodOptional<z.ZodBoolean>;
|
|
104
|
+
instruction: z.ZodOptional<z.ZodString>;
|
|
105
|
+
}, z.core.$strip>]>;
|
|
106
|
+
type LeaderboardSpec = z.infer<typeof leaderboardSpecSchema>;
|
|
107
|
+
/** A block (group of exercises); two exercises render as a superset. */
|
|
108
|
+
declare const blockSpecSchema: z.ZodObject<{
|
|
109
|
+
title: z.ZodString;
|
|
110
|
+
type: z.ZodOptional<z.ZodNumber>;
|
|
111
|
+
instruction: z.ZodOptional<z.ZodString>;
|
|
112
|
+
leaderboard: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodObject<{
|
|
113
|
+
unit: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
114
|
+
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
115
|
+
lowest_wins: z.ZodOptional<z.ZodBoolean>;
|
|
116
|
+
instruction: z.ZodOptional<z.ZodString>;
|
|
117
|
+
}, z.core.$strip>]>>;
|
|
118
|
+
exercises: z.ZodArray<z.ZodObject<{
|
|
119
|
+
id: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
|
|
120
|
+
title: z.ZodOptional<z.ZodString>;
|
|
121
|
+
reps: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>]>>;
|
|
122
|
+
sets: z.ZodOptional<z.ZodNumber>;
|
|
123
|
+
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodArray<z.ZodNumber>]>>;
|
|
124
|
+
rpe: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
125
|
+
instr: z.ZodOptional<z.ZodString>;
|
|
126
|
+
param_1_type: z.ZodOptional<z.ZodNumber>;
|
|
127
|
+
param_2_type: z.ZodOptional<z.ZodNumber>;
|
|
128
|
+
}, z.core.$strip>>;
|
|
129
|
+
}, z.core.$strip>;
|
|
130
|
+
type BlockSpec = z.infer<typeof blockSpecSchema>;
|
|
131
|
+
/** A full session spec: the blocks plus an optional session note (Coach Instructions). */
|
|
132
|
+
declare const workoutSpecSchema: z.ZodObject<{
|
|
133
|
+
blocks: z.ZodArray<z.ZodObject<{
|
|
134
|
+
title: z.ZodString;
|
|
135
|
+
type: z.ZodOptional<z.ZodNumber>;
|
|
136
|
+
instruction: z.ZodOptional<z.ZodString>;
|
|
137
|
+
leaderboard: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodObject<{
|
|
138
|
+
unit: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
139
|
+
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
140
|
+
lowest_wins: z.ZodOptional<z.ZodBoolean>;
|
|
141
|
+
instruction: z.ZodOptional<z.ZodString>;
|
|
142
|
+
}, z.core.$strip>]>>;
|
|
143
|
+
exercises: z.ZodArray<z.ZodObject<{
|
|
144
|
+
id: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
|
|
145
|
+
title: z.ZodOptional<z.ZodString>;
|
|
146
|
+
reps: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>]>>;
|
|
147
|
+
sets: z.ZodOptional<z.ZodNumber>;
|
|
148
|
+
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodArray<z.ZodNumber>]>>;
|
|
149
|
+
rpe: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
150
|
+
instr: z.ZodOptional<z.ZodString>;
|
|
151
|
+
param_1_type: z.ZodOptional<z.ZodNumber>;
|
|
152
|
+
param_2_type: z.ZodOptional<z.ZodNumber>;
|
|
153
|
+
}, z.core.$strip>>;
|
|
154
|
+
}, z.core.$strip>>;
|
|
155
|
+
instruction: z.ZodOptional<z.ZodString>;
|
|
156
|
+
}, z.core.$strip>;
|
|
157
|
+
type WorkoutSpec = z.infer<typeof workoutSpecSchema>;
|
|
158
|
+
/** A calendar date as the workout API expects it: [year, month, day]. */
|
|
159
|
+
type WorkoutDate = readonly [number, number, number];
|
|
160
|
+
/**
|
|
161
|
+
* Parse a `YYYY-M-D` string into the `WorkoutDate` tuple. The single home for this
|
|
162
|
+
* conversion, shared by the MCP tools and the CLI so they cannot drift on what counts
|
|
163
|
+
* as a valid date. Each part must be an integer.
|
|
164
|
+
*/
|
|
165
|
+
declare function parseWorkoutDate(s: string): WorkoutDate;
|
|
166
|
+
/** Unit advisories surfaced when building: informational notes and override warnings. */
|
|
167
|
+
type Advisory = {
|
|
168
|
+
notes: string[];
|
|
169
|
+
warnings: string[];
|
|
170
|
+
};
|
|
171
|
+
/** A single exercise as read back from a built session. */
|
|
172
|
+
type ReadExercise = {
|
|
173
|
+
order: number;
|
|
174
|
+
title: string;
|
|
175
|
+
reps: string[];
|
|
176
|
+
primaryUnit: string | null;
|
|
177
|
+
load: string[];
|
|
178
|
+
loadUnit: string | null;
|
|
179
|
+
instruction: string;
|
|
180
|
+
};
|
|
181
|
+
/** A block as read back from a built session. */
|
|
182
|
+
type ReadBlock = {
|
|
183
|
+
order: number;
|
|
184
|
+
title: string;
|
|
185
|
+
leaderboard: string | null;
|
|
186
|
+
exercises: ReadExercise[];
|
|
187
|
+
};
|
|
188
|
+
/** A whole session read back from the calendar. */
|
|
189
|
+
type ReadResult = {
|
|
190
|
+
pwId: number;
|
|
191
|
+
date: string;
|
|
192
|
+
published: unknown;
|
|
193
|
+
instruction: string;
|
|
194
|
+
blocks: ReadBlock[];
|
|
195
|
+
};
|
|
196
|
+
//#endregion
|
|
197
|
+
export { Advisory, BlockSpec, CommentDraft, ExerciseCreate, ExerciseRow, ExerciseSpec, ExerciseView, Id, LeaderboardSpec, ReadBlock, ReadExercise, ReadResult, ResolveResult, WorkoutDate, WorkoutSpec, blockSpecSchema, commentDraftSchema, exerciseCreateSchema, exerciseLibraryResponseSchema, exerciseResponseSchema, exerciseSpecSchema, idArgSchema, idSchema, leaderboardSpecSchema, parseWorkoutDate, programWorkoutResponseSchema, programsEditResponseSchema, sessionCreateResponseSchema, workoutSpecSchema };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/common.ts
|
|
3
|
+
/** An entity id as it arrives over the wire — a number or a numeric string. */
|
|
4
|
+
const idSchema = z.union([z.string(), z.number()]);
|
|
5
|
+
/**
|
|
6
|
+
* An id as a tool argument: a number, or a string of digits. Unlike idSchema (which
|
|
7
|
+
* tolerates whatever the API sends back), this rejects non-numeric strings up front so
|
|
8
|
+
* a bad argument fails validation instead of becoming NaN in a URL or a query.
|
|
9
|
+
*/
|
|
10
|
+
const idArgSchema = z.union([z.number().int(), z.string().regex(/^\d+$/u)]);
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/exercise.ts
|
|
13
|
+
/** Body for creating a custom exercise; extra fields the API accepts are preserved. */
|
|
14
|
+
const exerciseCreateSchema = z.looseObject({
|
|
15
|
+
title: z.string().min(1),
|
|
16
|
+
param_1_type: z.number().optional(),
|
|
17
|
+
param_2_type: z.number().optional()
|
|
18
|
+
});
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/messaging.ts
|
|
21
|
+
/** A chat comment to draft or send: target stream, body text, optional threaded reply. */
|
|
22
|
+
const commentDraftSchema = z.object({
|
|
23
|
+
streamId: idSchema,
|
|
24
|
+
text: z.string().min(1),
|
|
25
|
+
replyTo: idSchema.optional()
|
|
26
|
+
});
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/responses.ts
|
|
29
|
+
const intLike = z.union([z.number(), z.string()]);
|
|
30
|
+
const intLikeOrNull = z.union([
|
|
31
|
+
z.number(),
|
|
32
|
+
z.string(),
|
|
33
|
+
z.null()
|
|
34
|
+
]);
|
|
35
|
+
/** An exercise as the library + create endpoints return it (only the fields we read). */
|
|
36
|
+
const exerciseResponseSchema = z.looseObject({
|
|
37
|
+
id: intLike,
|
|
38
|
+
title: z.string(),
|
|
39
|
+
param_1_type: intLikeOrNull.optional(),
|
|
40
|
+
param_2_type: intLikeOrNull.optional()
|
|
41
|
+
});
|
|
42
|
+
/** The exercise library list (envelope already unwrapped). */
|
|
43
|
+
const exerciseLibraryResponseSchema = z.array(exerciseResponseSchema);
|
|
44
|
+
/** The create-session response (a programWorkout): we read workout_id + id. */
|
|
45
|
+
const sessionCreateResponseSchema = z.looseObject({
|
|
46
|
+
workout_id: intLike,
|
|
47
|
+
id: intLike
|
|
48
|
+
});
|
|
49
|
+
/** A programWorkout from the calendar edit view (we match by id and walk sets). */
|
|
50
|
+
const programWorkoutResponseSchema = z.looseObject({
|
|
51
|
+
id: intLike,
|
|
52
|
+
sets: z.record(z.string(), z.unknown()).optional()
|
|
53
|
+
});
|
|
54
|
+
/** The calendar edit-view response we read sessions back from. */
|
|
55
|
+
const programsEditResponseSchema = z.looseObject({ programWorkouts: z.array(programWorkoutResponseSchema).optional() });
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/workout.ts
|
|
58
|
+
/** A single exercise prescription inside a block. */
|
|
59
|
+
const exerciseSpecSchema = z.object({
|
|
60
|
+
id: z.union([z.number(), z.string()]),
|
|
61
|
+
title: z.string().optional(),
|
|
62
|
+
reps: z.union([
|
|
63
|
+
z.number(),
|
|
64
|
+
z.string(),
|
|
65
|
+
z.array(z.union([z.number(), z.string()]))
|
|
66
|
+
]).optional(),
|
|
67
|
+
sets: z.number().optional(),
|
|
68
|
+
weight: z.union([z.number(), z.array(z.number())]).optional(),
|
|
69
|
+
rpe: z.union([z.number(), z.string()]).optional(),
|
|
70
|
+
instr: z.string().optional(),
|
|
71
|
+
param_1_type: z.number().optional(),
|
|
72
|
+
param_2_type: z.number().optional()
|
|
73
|
+
});
|
|
74
|
+
/** A block's Red-Zone leaderboard: a unit string/number, or an object with options. */
|
|
75
|
+
const leaderboardSpecSchema = z.union([
|
|
76
|
+
z.string(),
|
|
77
|
+
z.number(),
|
|
78
|
+
z.object({
|
|
79
|
+
unit: z.union([z.string(), z.number()]).optional(),
|
|
80
|
+
type: z.union([z.string(), z.number()]).optional(),
|
|
81
|
+
lowest_wins: z.boolean().optional(),
|
|
82
|
+
instruction: z.string().optional()
|
|
83
|
+
})
|
|
84
|
+
]);
|
|
85
|
+
/** A block (group of exercises); two exercises render as a superset. */
|
|
86
|
+
const blockSpecSchema = z.object({
|
|
87
|
+
title: z.string(),
|
|
88
|
+
type: z.number().optional(),
|
|
89
|
+
instruction: z.string().optional(),
|
|
90
|
+
leaderboard: leaderboardSpecSchema.optional(),
|
|
91
|
+
exercises: z.array(exerciseSpecSchema)
|
|
92
|
+
});
|
|
93
|
+
/** A full session spec: the blocks plus an optional session note (Coach Instructions). */
|
|
94
|
+
const workoutSpecSchema = z.object({
|
|
95
|
+
blocks: z.array(blockSpecSchema),
|
|
96
|
+
instruction: z.string().optional()
|
|
97
|
+
});
|
|
98
|
+
/**
|
|
99
|
+
* Parse a `YYYY-M-D` string into the `WorkoutDate` tuple. The single home for this
|
|
100
|
+
* conversion, shared by the MCP tools and the CLI so they cannot drift on what counts
|
|
101
|
+
* as a valid date. Each part must be an integer.
|
|
102
|
+
*/
|
|
103
|
+
function parseWorkoutDate(s) {
|
|
104
|
+
const parts = s.split("-").map((p) => Number(p));
|
|
105
|
+
if (parts.length !== 3 || parts.some((n) => !Number.isInteger(n))) throw new Error(`date must be YYYY-M-D, got "${s}".`);
|
|
106
|
+
return [
|
|
107
|
+
parts[0],
|
|
108
|
+
parts[1],
|
|
109
|
+
parts[2]
|
|
110
|
+
];
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
export { blockSpecSchema, commentDraftSchema, exerciseCreateSchema, exerciseLibraryResponseSchema, exerciseResponseSchema, exerciseSpecSchema, idArgSchema, idSchema, leaderboardSpecSchema, parseWorkoutDate, programWorkoutResponseSchema, programsEditResponseSchema, sessionCreateResponseSchema, workoutSpecSchema };
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trainheroic-unofficial/dto",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/alandotcom/trainheroic-skill.git",
|
|
8
|
+
"directory": "packages/dto"
|
|
9
|
+
},
|
|
10
|
+
"description": "Domain DTOs and zod schemas for TrainHeroic — the single source of truth for shapes.",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.mts",
|
|
15
|
+
"import": "./dist/index.mjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"zod": "^4.4.3"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"tsdown": "^0.22.3",
|
|
29
|
+
"vitest": "^4.1.9"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsdown",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"test": "vitest run"
|
|
35
|
+
}
|
|
36
|
+
}
|