@trainheroic-unofficial/dto 1.7.2 → 1.7.4

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.
Files changed (2) hide show
  1. package/dist/index.mjs +22 -8
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -173,6 +173,26 @@ const loggedSetSchema = z.object({
173
173
  * always sequential).
174
174
  */
175
175
  const loggedSetWithSlotSchema = loggedSetSchema.extend({ slot: z.number().int().min(1).max(10).optional() });
176
+ function requireUniqueExerciseIds(results, ctx) {
177
+ const seen = /* @__PURE__ */ new Set();
178
+ results.forEach((result, index) => {
179
+ const id = String(result.savedWorkoutSetExerciseId).replace(/^0+(?=\d)/u, "");
180
+ if (seen.has(id)) ctx.addIssue({
181
+ code: "custom",
182
+ message: `savedWorkoutSetExerciseId ${id} appears more than once; combine its sets into one result.`,
183
+ path: [index, "savedWorkoutSetExerciseId"]
184
+ });
185
+ seen.add(id);
186
+ });
187
+ }
188
+ const loggedExerciseResultsSchema = z.array(z.object({
189
+ savedWorkoutSetExerciseId: idArgSchema,
190
+ sets: z.array(loggedSetWithSlotSchema).min(1)
191
+ })).min(1).superRefine(requireUniqueExerciseIds);
192
+ const prescribedExerciseResultsSchema = z.array(z.object({
193
+ savedWorkoutSetExerciseId: idArgSchema,
194
+ sets: z.array(loggedSetSchema).min(1)
195
+ })).min(1).superRefine(requireUniqueExerciseIds);
176
196
  /**
177
197
  * Args for the set-logging write. `date` (the workout's day) locates the saved
178
198
  * workout via the range endpoint; `savedWorkoutSetId` picks the set to complete; `results`
@@ -184,10 +204,7 @@ const loggedSetWithSlotSchema = loggedSetSchema.extend({ slot: z.number().int().
184
204
  const logSetArgsSchema = z.object({
185
205
  date: dateString,
186
206
  savedWorkoutSetId: idArgSchema,
187
- results: z.array(z.object({
188
- savedWorkoutSetExerciseId: idArgSchema,
189
- sets: z.array(loggedSetWithSlotSchema).min(1)
190
- })).min(1)
207
+ results: loggedExerciseResultsSchema
191
208
  });
192
209
  /**
193
210
  * Args for the coach "log for athlete" write — the same shape as logSetArgsSchema plus the
@@ -207,10 +224,7 @@ const coachPrescribeSetArgsSchema = z.object({
207
224
  date: dateString,
208
225
  savedWorkoutSetId: idArgSchema,
209
226
  athleteId: idArgSchema,
210
- results: z.array(z.object({
211
- savedWorkoutSetExerciseId: idArgSchema,
212
- sets: z.array(loggedSetSchema).min(1)
213
- })).min(1)
227
+ results: prescribedExerciseResultsSchema
214
228
  });
215
229
  /**
216
230
  * Args for the coach per-athlete exercise swap: replace the exercise prescribed in one of a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainheroic-unofficial/dto",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "devDependencies": {
28
28
  "tsdown": "^0.22.3",
29
- "vitest": "^4.1.9"
29
+ "vitest": "^4.1.10"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "tsdown",