@trainheroic-unofficial/js 3.4.0 → 3.5.1
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/dist/index.d.mts +33 -2
- package/dist/index.mjs +115 -9
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as LibrarySnapshot, r as MemoryLibraryCache, t as LibraryCache } from "./library-cache-CDABOdIN.mjs";
|
|
2
|
-
import { Advisory, AthletePrefs, AthleteProfileSummary, AthleteUser, AthleteWorkingMax, AthleteWorkoutNoteOutput, AthleteWorkoutSummary, AthleteWorkoutView, BlockSpec, CoachAthleteTraining, ExerciseHistoryDetail, ExerciseHistoryListItem, ExerciseRow, ExerciseSpec, ExerciseStats, ExerciseView, PersonalRecord, PresentedExerciseHistory, ProgramWorkout, ReadResult, ResolveResult, RosterActivityRow, SessionTemplateCreate, TeamPublishPatch, TeamVolumeReport, WorkoutDate, WorkoutHistoryExport } from "@trainheroic-unofficial/dto";
|
|
2
|
+
import { Advisory, AthleteExerciseNoteOutput, AthletePrefs, AthleteProfileSummary, AthleteUser, AthleteWorkingMax, AthleteWorkoutNoteOutput, AthleteWorkoutSummary, AthleteWorkoutView, BlockSpec, CoachAthleteTraining, ExerciseHistoryDetail, ExerciseHistoryListItem, ExerciseRow, ExerciseSpec, ExerciseStats, ExerciseView, PersonalRecord, PresentedExerciseHistory, ProgramWorkout, ReadResult, ResolveResult, RosterActivityRow, SessionTemplateCreate, TeamPublishPatch, TeamVolumeReport, WorkoutDate, WorkoutHistoryExport } from "@trainheroic-unofficial/dto";
|
|
3
3
|
import { ZodType } from "zod";
|
|
4
4
|
export * from "@trainheroic-unofficial/dto";
|
|
5
5
|
//#region src/http-error.d.ts
|
|
@@ -290,6 +290,7 @@ type LogSetTarget = {
|
|
|
290
290
|
savedWorkoutSetExerciseId: number;
|
|
291
291
|
title: string;
|
|
292
292
|
units: ReturnType<typeof exerciseUnits>;
|
|
293
|
+
notes: string | null;
|
|
293
294
|
prescribed: string[];
|
|
294
295
|
performed: string[];
|
|
295
296
|
}>;
|
|
@@ -705,6 +706,18 @@ declare function setAthleteWorkoutNote(client: TrainHeroicClient, args: {
|
|
|
705
706
|
rpe?: number | undefined;
|
|
706
707
|
}): Promise<AthleteWorkoutNoteOutput>;
|
|
707
708
|
//#endregion
|
|
709
|
+
//#region src/athlete-exercise-note.d.ts
|
|
710
|
+
/**
|
|
711
|
+
* PUT /1.0/athlete/savedworkoutsetexercise/{id} — set the athlete's per-exercise note (the
|
|
712
|
+
* "Add exercise note" box on the exercise screen). A notes-only body leaves logged reps/weight
|
|
713
|
+
* untouched. Empty `notes` clears the note. GET on that path 405s; the range read and exercise
|
|
714
|
+
* history both echo the stored string. Coach-visible.
|
|
715
|
+
*/
|
|
716
|
+
declare function setAthleteExerciseNote(client: TrainHeroicClient, args: {
|
|
717
|
+
savedWorkoutSetExerciseId: number | string;
|
|
718
|
+
notes: string;
|
|
719
|
+
}): Promise<AthleteExerciseNoteOutput>;
|
|
720
|
+
//#endregion
|
|
708
721
|
//#region src/workout-export.d.ts
|
|
709
722
|
type WorkoutExportFormat = "json" | "csv" | "text";
|
|
710
723
|
/** A serialized export ready to write to a file or hand to a browser download. */
|
|
@@ -992,6 +1005,12 @@ declare function definedProps<T extends object>(obj: T): { [K in keyof T]: Exclu
|
|
|
992
1005
|
//#endregion
|
|
993
1006
|
//#region src/workout-encode.d.ts
|
|
994
1007
|
type AdvisoryIndex = Pick<ExerciseIndex, "defaultsMany" | "ensureFresh">;
|
|
1008
|
+
type SetSplit = {
|
|
1009
|
+
blockTitle: string;
|
|
1010
|
+
exerciseTitle: string;
|
|
1011
|
+
setCount: number;
|
|
1012
|
+
blockCount: number;
|
|
1013
|
+
};
|
|
995
1014
|
declare const LEADERBOARD_TYPE: Readonly<Record<string, number>>;
|
|
996
1015
|
declare const LEADERBOARD_LABEL: Readonly<Record<number, string>>;
|
|
997
1016
|
type Leaderboard = {
|
|
@@ -1002,6 +1021,16 @@ type Leaderboard = {
|
|
|
1002
1021
|
};
|
|
1003
1022
|
declare function resolveLeaderboard(block: BlockSpec): Leaderboard;
|
|
1004
1023
|
declare function repsList(ex: ExerciseSpec): string[];
|
|
1024
|
+
/** Number of sets that the encoder will write for an exercise. */
|
|
1025
|
+
declare function exerciseSetCount(ex: ExerciseSpec): number;
|
|
1026
|
+
declare function findSetSplits(blocks: readonly BlockSpec[]): SetSplit[];
|
|
1027
|
+
declare function setSplitSummary(blocks: readonly BlockSpec[]): string | null;
|
|
1028
|
+
/**
|
|
1029
|
+
* Split blocks so no encoded exercise exceeds TrainHeroic's ten parameter slots.
|
|
1030
|
+
* Exercises in a superset stay aligned by set range; shorter exercises appear only in
|
|
1031
|
+
* chunks where they still have sets.
|
|
1032
|
+
*/
|
|
1033
|
+
declare function splitOversizedBlocks(blocks: readonly BlockSpec[]): BlockSpec[];
|
|
1005
1034
|
/** Build one saveWorkoutSetExercises payload entry with all ten param slots filled. */
|
|
1006
1035
|
declare function makeExercise(ex: ExerciseSpec, workoutSetId: number, order: number, key: string): Record<string, unknown>;
|
|
1007
1036
|
/** Block `type` values the coach calendar accepts (verified in workout-creation.md). */
|
|
@@ -1033,6 +1062,8 @@ type BuildOptions = {
|
|
|
1033
1062
|
date?: WorkoutDate;
|
|
1034
1063
|
timelineDay?: number;
|
|
1035
1064
|
publish?: boolean;
|
|
1065
|
+
/** Explicitly allow prescriptions above ten sets to become consecutive blocks. */
|
|
1066
|
+
confirmSetSplit?: boolean;
|
|
1036
1067
|
/** Optional session-level note ("Coach Instructions"), set after the blocks save. */
|
|
1037
1068
|
instruction?: string;
|
|
1038
1069
|
};
|
|
@@ -1094,4 +1125,4 @@ declare class ExerciseLibrary implements ExerciseIndex {
|
|
|
1094
1125
|
stats(): Promise<Record<string, unknown>>;
|
|
1095
1126
|
}
|
|
1096
1127
|
//#endregion
|
|
1097
|
-
export { ANALYTICS_METRIC_KEYS, AddedExercise, AnalyticsMetric, AnalyticsQueryArgs, ApiBase, AthleteMainLiftPRs, BLOCK_TYPE_CONDITIONING, BLOCK_TYPE_HYPERTROPHY, BuildOptions, ClientOptions, ClientResult, CoachAthleteCalendar, CoachRosterAthlete, CreatedProgram, DEFAULT_INVITE_MESSAGE, DeletedProgram, ExerciseDefaults, ExerciseIndex, ExerciseLibrary, type ExerciseSetInput, type ExerciseSetPayload, LEADERBOARD_LABEL, LEADERBOARD_TYPE, Leaderboard, LibraryCache, LibrarySnapshot, LogSessionResult, LogSetTarget, LoginOptions, MAIN_LIFT_FAMILIES, MAX_PARAM_SLOTS, MainLiftFamily, MainLiftFamilyKey, MainLiftPR, MainLiftResolution, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PROGRAM_KINDS, PersonalWorkoutCreated, ProgramKind, RequestOptions, ResolvedLift, SESSION_TEMPLATES_LIST_PATH, ScheduledAlternative, SerializedExport, SessionExercise, SetResult, type SetWriteMode, SwapExerciseResult, TeamPublishTarget, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicHttpError, type TrainHeroicHttpErrorHandler, TrainHeroicSession, WorkoutExportFormat, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, calendarWriteError, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, createProgram, createSessionTemplate, dateWindows, defaultBlockType, definedProps, deleteComment, deleteProgram, exerciseTitle, exerciseUnits, fetchAthleteCircuits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteProgrammingPrograms, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendar, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRecentExercises, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, prescribeAthleteSet, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkoutExport, presentAthleteWorkouts, presentAthleteWorkoutsExport, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, programWorkoutOnDate, publishSession, queryAnalytics, rankSearch, readLive, readSession, removePersonalWorkout, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveBuildProgramId, resolveLeaderboard, savedWorkoutOf, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, serializeWorkoutHistory, setAthleteWorkoutNote, setSessionInstruction, sortRosterByRecency, str, summarizeAthleteWorkouts, swapAthleteExercise, teamPublishTarget, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, updateTeam, updateTeamPublishSettings, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
|
|
1128
|
+
export { ANALYTICS_METRIC_KEYS, AddedExercise, AnalyticsMetric, AnalyticsQueryArgs, ApiBase, AthleteMainLiftPRs, BLOCK_TYPE_CONDITIONING, BLOCK_TYPE_HYPERTROPHY, BuildOptions, ClientOptions, ClientResult, CoachAthleteCalendar, CoachRosterAthlete, CreatedProgram, DEFAULT_INVITE_MESSAGE, DeletedProgram, ExerciseDefaults, ExerciseIndex, ExerciseLibrary, type ExerciseSetInput, type ExerciseSetPayload, LEADERBOARD_LABEL, LEADERBOARD_TYPE, Leaderboard, LibraryCache, LibrarySnapshot, LogSessionResult, LogSetTarget, LoginOptions, MAIN_LIFT_FAMILIES, MAX_PARAM_SLOTS, MainLiftFamily, MainLiftFamilyKey, MainLiftPR, MainLiftResolution, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PROGRAM_KINDS, PersonalWorkoutCreated, ProgramKind, RequestOptions, ResolvedLift, SESSION_TEMPLATES_LIST_PATH, ScheduledAlternative, SerializedExport, SessionExercise, SetResult, SetSplit, type SetWriteMode, SwapExerciseResult, TeamPublishTarget, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicHttpError, type TrainHeroicHttpErrorHandler, TrainHeroicSession, WorkoutExportFormat, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, calendarWriteError, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, createProgram, createSessionTemplate, dateWindows, defaultBlockType, definedProps, deleteComment, deleteProgram, exerciseSetCount, exerciseTitle, exerciseUnits, fetchAthleteCircuits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteProgrammingPrograms, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendar, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRecentExercises, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, findSetSplits, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, prescribeAthleteSet, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkoutExport, presentAthleteWorkouts, presentAthleteWorkoutsExport, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, programWorkoutOnDate, publishSession, queryAnalytics, rankSearch, readLive, readSession, removePersonalWorkout, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveBuildProgramId, resolveLeaderboard, savedWorkoutOf, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, serializeWorkoutHistory, setAthleteExerciseNote, setAthleteWorkoutNote, setSessionInstruction, setSplitSummary, sortRosterByRecency, splitOversizedBlocks, str, summarizeAthleteWorkouts, swapAthleteExercise, teamPublishTarget, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, updateTeam, updateTeamPublishSettings, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
|
package/dist/index.mjs
CHANGED
|
@@ -663,6 +663,16 @@ function performedSlotsByExerciseId(sets) {
|
|
|
663
663
|
}
|
|
664
664
|
return map;
|
|
665
665
|
}
|
|
666
|
+
/** Per-exercise athlete notes keyed by the prescription template id (`workout_set_exercise_id`). */
|
|
667
|
+
function notesByTemplateId(sets) {
|
|
668
|
+
const map = /* @__PURE__ */ new Map();
|
|
669
|
+
for (const { exercises } of sets) for (const ex of exercises) {
|
|
670
|
+
const id = coerceInt(ex.workout_set_exercise_id);
|
|
671
|
+
const notes = str(ex.notes);
|
|
672
|
+
if (id !== null && notes !== null) map.set(id, notes);
|
|
673
|
+
}
|
|
674
|
+
return map;
|
|
675
|
+
}
|
|
666
676
|
/** Align an exercise's prescribed slots with the slots the athlete logged, per set index. */
|
|
667
677
|
function mergeExercise(prescribed, performed, meta) {
|
|
668
678
|
const indices = [.../* @__PURE__ */ new Set([...prescribed.keys(), ...performed.keys()])].sort((a, b) => a - b);
|
|
@@ -676,7 +686,7 @@ function mergeExercise(prescribed, performed, meta) {
|
|
|
676
686
|
};
|
|
677
687
|
}
|
|
678
688
|
/** A prescription block, each exercise aligned with the slots the athlete logged against it. */
|
|
679
|
-
function mergePrescriptionBlock(set, performedById) {
|
|
689
|
+
function mergePrescriptionBlock(set, performedById, notesById) {
|
|
680
690
|
const exercises = Array.isArray(set.workoutSetExercises) ? set.workoutSetExercises : [];
|
|
681
691
|
return {
|
|
682
692
|
order: coerceInt(set.order) ?? 0,
|
|
@@ -690,6 +700,7 @@ function mergePrescriptionBlock(set, performedById) {
|
|
|
690
700
|
exerciseId: coerceInt(ex.exercise_id),
|
|
691
701
|
title: typeof ex.title === "string" ? ex.title : "",
|
|
692
702
|
instruction: str(ex.instruction),
|
|
703
|
+
notes: id !== null ? notesById.get(id) ?? null : null,
|
|
693
704
|
units: exerciseUnits(ex.param_1_type, ex.param_2_type)
|
|
694
705
|
});
|
|
695
706
|
})
|
|
@@ -706,6 +717,7 @@ function mergeSavedBlock(set, exercises) {
|
|
|
706
717
|
exerciseId: coerceInt(ex.exercise_id),
|
|
707
718
|
title: typeof ex.exercise_title === "string" ? ex.exercise_title : "",
|
|
708
719
|
instruction: str(ex.instruction),
|
|
720
|
+
notes: str(ex.notes),
|
|
709
721
|
units: exerciseUnits(ex.param_1_type, ex.param_2_type)
|
|
710
722
|
}))
|
|
711
723
|
};
|
|
@@ -724,7 +736,8 @@ function mergeAthleteWorkout(raw) {
|
|
|
724
736
|
const prescriptionSets = (Array.isArray(workout.workoutSets) ? workout.workoutSets : []).filter(isRecord);
|
|
725
737
|
const logged = savedSets(saved);
|
|
726
738
|
const performedById = performedSlotsByExerciseId(logged);
|
|
727
|
-
const
|
|
739
|
+
const notesById = notesByTemplateId(logged);
|
|
740
|
+
const blocks = prescriptionSets.map((s) => mergePrescriptionBlock(s, performedById, notesById)).sort((a, b) => a.order - b.order);
|
|
728
741
|
const prescribedIds = /* @__PURE__ */ new Set();
|
|
729
742
|
for (const s of prescriptionSets) {
|
|
730
743
|
const exs = Array.isArray(s.workoutSetExercises) ? s.workoutSetExercises : [];
|
|
@@ -770,6 +783,7 @@ function toStringExercise(ex) {
|
|
|
770
783
|
exerciseId: ex.exerciseId,
|
|
771
784
|
title: ex.title,
|
|
772
785
|
instruction: ex.instruction,
|
|
786
|
+
notes: ex.notes,
|
|
773
787
|
units: ex.units,
|
|
774
788
|
prescribed: sideStrings(ex.sets, (s) => s.prescribed),
|
|
775
789
|
performed: sideStrings(ex.sets, (s) => s.performed)
|
|
@@ -929,6 +943,7 @@ function presentLogTargets(list) {
|
|
|
929
943
|
savedWorkoutSetExerciseId: id,
|
|
930
944
|
title: exerciseTitle(ex),
|
|
931
945
|
units: exerciseUnits(ex.param_1_type, ex.param_2_type),
|
|
946
|
+
notes: str(ex.notes),
|
|
932
947
|
prescribed: prescribedStrings(ex),
|
|
933
948
|
performed: performedStrings(ex)
|
|
934
949
|
};
|
|
@@ -1044,6 +1059,7 @@ function presentExerciseHistory(detail) {
|
|
|
1044
1059
|
sessions: (detail.history ?? []).map((h) => ({
|
|
1045
1060
|
date: h.dateCompleted,
|
|
1046
1061
|
abr: h.abr ?? null,
|
|
1062
|
+
notes: str(h.notes),
|
|
1047
1063
|
estimated1RM: h.bestEstimated1RM ?? null,
|
|
1048
1064
|
sets: (h.sets ?? []).map((s) => ({
|
|
1049
1065
|
setNumber: s.setNumber,
|
|
@@ -1807,6 +1823,28 @@ async function setAthleteWorkoutNote(client, args) {
|
|
|
1807
1823
|
};
|
|
1808
1824
|
}
|
|
1809
1825
|
//#endregion
|
|
1826
|
+
//#region src/athlete-exercise-note.ts
|
|
1827
|
+
/**
|
|
1828
|
+
* PUT /1.0/athlete/savedworkoutsetexercise/{id} — set the athlete's per-exercise note (the
|
|
1829
|
+
* "Add exercise note" box on the exercise screen). A notes-only body leaves logged reps/weight
|
|
1830
|
+
* untouched. Empty `notes` clears the note. GET on that path 405s; the range read and exercise
|
|
1831
|
+
* history both echo the stored string. Coach-visible.
|
|
1832
|
+
*/
|
|
1833
|
+
async function setAthleteExerciseNote(client, args) {
|
|
1834
|
+
const savedWorkoutSetExerciseId = coerceInt(args.savedWorkoutSetExerciseId);
|
|
1835
|
+
if (savedWorkoutSetExerciseId === null) throw new Error(`Invalid savedWorkoutSetExerciseId ${String(args.savedWorkoutSetExerciseId)}.`);
|
|
1836
|
+
const res = await client.request("PUT", `/1.0/athlete/savedworkoutsetexercise/${savedWorkoutSetExerciseId}`, { body: {
|
|
1837
|
+
id: savedWorkoutSetExerciseId,
|
|
1838
|
+
notes: args.notes
|
|
1839
|
+
} });
|
|
1840
|
+
if (!res.ok) throw new Error(`Set exercise note failed (HTTP ${res.status}).`);
|
|
1841
|
+
const data = isRecord(res.data) ? res.data : {};
|
|
1842
|
+
return {
|
|
1843
|
+
savedWorkoutSetExerciseId,
|
|
1844
|
+
notes: typeof data.notes === "string" ? data.notes : args.notes
|
|
1845
|
+
};
|
|
1846
|
+
}
|
|
1847
|
+
//#endregion
|
|
1810
1848
|
//#region src/workout-export.ts
|
|
1811
1849
|
const DEFAULT_FILENAME_BASE = "trainheroic-workout-history";
|
|
1812
1850
|
/** Pretty-printed JSON of the structured workouts, exactly as `presentAthleteWorkoutsExport` yields. */
|
|
@@ -2024,9 +2062,75 @@ function repsList(ex) {
|
|
|
2024
2062
|
const reps = ex.reps;
|
|
2025
2063
|
if (Array.isArray(reps)) return reps.map((r) => String(r));
|
|
2026
2064
|
if (reps === void 0 || reps === null) return [];
|
|
2027
|
-
const sets = Math.max(1, Math.trunc(Number(ex.sets ?? 1)) || 1);
|
|
2065
|
+
const sets = Array.isArray(ex.weight) ? ex.weight.length : Math.max(1, Math.trunc(Number(ex.sets ?? 1)) || 1);
|
|
2028
2066
|
return Array.from({ length: sets }, () => String(reps));
|
|
2029
2067
|
}
|
|
2068
|
+
/** Number of sets that the encoder will write for an exercise. */
|
|
2069
|
+
function exerciseSetCount(ex) {
|
|
2070
|
+
if (Array.isArray(ex.reps) && ex.reps.length > 0) return ex.reps.length;
|
|
2071
|
+
if (Array.isArray(ex.weight)) return ex.weight.length;
|
|
2072
|
+
if (!Array.isArray(ex.reps) && ex.reps !== void 0 && ex.reps !== null || ex.weight !== void 0 && ex.weight !== null) return Math.max(1, Math.trunc(Number(ex.sets ?? 1)) || 1);
|
|
2073
|
+
return 0;
|
|
2074
|
+
}
|
|
2075
|
+
function findSetSplits(blocks) {
|
|
2076
|
+
return blocks.flatMap((block) => block.exercises.flatMap((exercise) => {
|
|
2077
|
+
const setCount = exerciseSetCount(exercise);
|
|
2078
|
+
if (setCount <= 10) return [];
|
|
2079
|
+
return [{
|
|
2080
|
+
blockTitle: block.title,
|
|
2081
|
+
exerciseTitle: exercise.title ?? String(exercise.id),
|
|
2082
|
+
setCount,
|
|
2083
|
+
blockCount: Math.ceil(setCount / 10)
|
|
2084
|
+
}];
|
|
2085
|
+
}));
|
|
2086
|
+
}
|
|
2087
|
+
function setSplitSummary(blocks) {
|
|
2088
|
+
const splits = findSetSplits(blocks);
|
|
2089
|
+
if (splits.length === 0) return null;
|
|
2090
|
+
return `TrainHeroic supports at most 10 sets per exercise block. The following will be split into consecutive same-titled blocks: ${splits.map(({ blockTitle, exerciseTitle, setCount, blockCount }) => `${blockTitle} / ${exerciseTitle}: ${setCount} sets into ${blockCount} blocks`).join("; ")}.`;
|
|
2091
|
+
}
|
|
2092
|
+
function sliceExercise(exercise, setCount, start) {
|
|
2093
|
+
if (start > 0 && setCount <= start) return null;
|
|
2094
|
+
const chunkCount = setCount === 0 ? 0 : Math.min(10, Math.max(0, setCount - start));
|
|
2095
|
+
const chunk = { ...exercise };
|
|
2096
|
+
const hasPerSetReps = Array.isArray(exercise.reps) && exercise.reps.length > 0;
|
|
2097
|
+
const hasScalarReps = !Array.isArray(exercise.reps) && exercise.reps !== void 0 && exercise.reps !== null;
|
|
2098
|
+
if (Array.isArray(exercise.reps) && exercise.reps.length > 0) {
|
|
2099
|
+
chunk.reps = exercise.reps.slice(start, start + 10);
|
|
2100
|
+
delete chunk.sets;
|
|
2101
|
+
} else if (hasScalarReps) chunk.sets = chunkCount;
|
|
2102
|
+
if (Array.isArray(exercise.weight)) {
|
|
2103
|
+
chunk.weight = exercise.weight.slice(start, start + 10);
|
|
2104
|
+
if (!hasPerSetReps && !hasScalarReps) delete chunk.sets;
|
|
2105
|
+
} else if (!hasPerSetReps && exercise.weight !== void 0 && exercise.weight !== null) chunk.sets = chunkCount;
|
|
2106
|
+
return chunk;
|
|
2107
|
+
}
|
|
2108
|
+
/**
|
|
2109
|
+
* Split blocks so no encoded exercise exceeds TrainHeroic's ten parameter slots.
|
|
2110
|
+
* Exercises in a superset stay aligned by set range; shorter exercises appear only in
|
|
2111
|
+
* chunks where they still have sets.
|
|
2112
|
+
*/
|
|
2113
|
+
function splitOversizedBlocks(blocks) {
|
|
2114
|
+
return blocks.flatMap((block) => {
|
|
2115
|
+
const setCounts = block.exercises.map(exerciseSetCount);
|
|
2116
|
+
const largestSetCount = Math.max(0, ...setCounts);
|
|
2117
|
+
const chunkCount = Math.max(1, Math.ceil(largestSetCount / 10));
|
|
2118
|
+
if (chunkCount === 1) return [block];
|
|
2119
|
+
return Array.from({ length: chunkCount }, (_, index) => {
|
|
2120
|
+
const start = index * 10;
|
|
2121
|
+
const exercises = block.exercises.map((exercise, exerciseIndex) => sliceExercise(exercise, setCounts[exerciseIndex] ?? 0, start)).filter((exercise) => exercise !== null);
|
|
2122
|
+
if (index === 0) return {
|
|
2123
|
+
...block,
|
|
2124
|
+
exercises
|
|
2125
|
+
};
|
|
2126
|
+
return {
|
|
2127
|
+
title: block.title,
|
|
2128
|
+
...block.type === void 0 ? {} : { type: block.type },
|
|
2129
|
+
exercises
|
|
2130
|
+
};
|
|
2131
|
+
});
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2030
2134
|
/** Build one saveWorkoutSetExercises payload entry with all ten param slots filled. */
|
|
2031
2135
|
function makeExercise(ex, workoutSetId, order, key) {
|
|
2032
2136
|
const reps = repsList(ex);
|
|
@@ -2034,8 +2138,7 @@ function makeExercise(ex, workoutSetId, order, key) {
|
|
|
2034
2138
|
if (instruction === "" && ex.rpe !== void 0 && ex.rpe !== null) instruction = `RPE ${ex.rpe}`;
|
|
2035
2139
|
const hasWeight = ex.weight !== void 0 && ex.weight !== null;
|
|
2036
2140
|
const weightArr = Array.isArray(ex.weight) ? ex.weight : null;
|
|
2037
|
-
|
|
2038
|
-
if (count === 0 && hasWeight) count = weightArr ? weightArr.length : Math.max(1, Math.trunc(Number(ex.sets ?? 1)) || 1);
|
|
2141
|
+
const count = exerciseSetCount(ex);
|
|
2039
2142
|
let param2Type;
|
|
2040
2143
|
let param2Values;
|
|
2041
2144
|
if (hasWeight) {
|
|
@@ -2066,8 +2169,8 @@ function makeExercise(ex, workoutSetId, order, key) {
|
|
|
2066
2169
|
eType: "e",
|
|
2067
2170
|
use_count: 0
|
|
2068
2171
|
};
|
|
2069
|
-
const p1 = slots(reps);
|
|
2070
|
-
const p2 = slots(param2Values);
|
|
2172
|
+
const p1 = slots(reps, 10);
|
|
2173
|
+
const p2 = slots(param2Values, 10);
|
|
2071
2174
|
for (let i = 0; i < 10; i += 1) {
|
|
2072
2175
|
entry[`param_1_data_${i + 1}`] = p1[i] ?? "";
|
|
2073
2176
|
entry[`param_2_data_${i + 1}`] = p2[i] ?? "";
|
|
@@ -2188,7 +2291,10 @@ function createPath(opts) {
|
|
|
2188
2291
|
return `/2.0/coach/calendar/workout/createWorkoutForDay/${opts.programId}/${y}/${m}/${d}/0`;
|
|
2189
2292
|
}
|
|
2190
2293
|
async function buildSession(client, opts) {
|
|
2191
|
-
const
|
|
2294
|
+
const validatedBlocks = z.array(blockSpecSchema).parse(opts.blocks);
|
|
2295
|
+
const splitSummary = setSplitSummary(validatedBlocks);
|
|
2296
|
+
if (splitSummary !== null && opts.confirmSetSplit !== true) throw new Error(`${splitSummary} Set confirmSetSplit:true to allow this change.`);
|
|
2297
|
+
const blocks = splitSummary === null ? validatedBlocks : splitOversizedBlocks(validatedBlocks);
|
|
2192
2298
|
const sess = await req(client, "POST", createPath(opts), {});
|
|
2193
2299
|
checkResponse(sessionCreateResponseSchema, sess, "session create");
|
|
2194
2300
|
const workoutId = Number(sess.workout_id);
|
|
@@ -3235,4 +3341,4 @@ var ExerciseLibrary = class {
|
|
|
3235
3341
|
}
|
|
3236
3342
|
};
|
|
3237
3343
|
//#endregion
|
|
3238
|
-
export { ANALYTICS_METRIC_KEYS, BLOCK_TYPE_CONDITIONING, BLOCK_TYPE_HYPERTROPHY, DEFAULT_INVITE_MESSAGE, ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, MAIN_LIFT_FAMILIES, MAX_PARAM_SLOTS, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PROGRAM_KINDS, SESSION_TEMPLATES_LIST_PATH, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicHttpError, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, calendarWriteError, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, createProgram, createSessionTemplate, dateWindows, defaultBlockType, definedProps, deleteComment, deleteProgram, exerciseTitle, exerciseUnits, fetchAthleteCircuits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteProgrammingPrograms, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendar, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRecentExercises, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, prescribeAthleteSet, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkoutExport, presentAthleteWorkouts, presentAthleteWorkoutsExport, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, programWorkoutOnDate, publishSession, queryAnalytics, rankSearch, readLive, readSession, removePersonalWorkout, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveBuildProgramId, resolveLeaderboard, savedWorkoutOf, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, serializeWorkoutHistory, setAthleteWorkoutNote, setSessionInstruction, sortRosterByRecency, str, summarizeAthleteWorkouts, swapAthleteExercise, teamPublishTarget, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, updateTeam, updateTeamPublishSettings, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
|
|
3344
|
+
export { ANALYTICS_METRIC_KEYS, BLOCK_TYPE_CONDITIONING, BLOCK_TYPE_HYPERTROPHY, DEFAULT_INVITE_MESSAGE, ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, MAIN_LIFT_FAMILIES, MAX_PARAM_SLOTS, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PROGRAM_KINDS, SESSION_TEMPLATES_LIST_PATH, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicHttpError, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, calendarWriteError, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, createProgram, createSessionTemplate, dateWindows, defaultBlockType, definedProps, deleteComment, deleteProgram, exerciseSetCount, exerciseTitle, exerciseUnits, fetchAthleteCircuits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteProgrammingPrograms, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendar, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRecentExercises, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, findSetSplits, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, prescribeAthleteSet, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkoutExport, presentAthleteWorkouts, presentAthleteWorkoutsExport, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, programWorkoutOnDate, publishSession, queryAnalytics, rankSearch, readLive, readSession, removePersonalWorkout, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveBuildProgramId, resolveLeaderboard, savedWorkoutOf, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, serializeWorkoutHistory, setAthleteExerciseNote, setAthleteWorkoutNote, setSessionInstruction, setSplitSummary, sortRosterByRecency, splitOversizedBlocks, str, summarizeAthleteWorkouts, swapAthleteExercise, teamPublishTarget, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, updateTeam, updateTeamPublishSettings, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/js",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"zod": "^4.4.3",
|
|
30
|
-
"@trainheroic-unofficial/dto": "3.
|
|
30
|
+
"@trainheroic-unofficial/dto": "3.5.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^26.3.0",
|