@trainheroic-unofficial/js 2.1.1 → 3.0.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/dist/index.d.mts CHANGED
@@ -163,16 +163,17 @@ declare function mapPool<T, R>(items: readonly T[], limit: number, fn: (item: T,
163
163
  * The exercise-library surface the tools depend on, so the tools work over either a
164
164
  * D1-backed mirror (hosted, multi-tenant) or an in-memory cache (local, single-user).
165
165
  */
166
+ type ExerciseDefaults = {
167
+ param1: number | null;
168
+ param2: number | null;
169
+ };
166
170
  interface ExerciseIndex {
167
171
  ensureFresh(): Promise<void>;
168
172
  refresh(): Promise<Record<string, unknown>>;
169
173
  resolve(name: string): Promise<ResolveResult>;
170
174
  search(query: string, limit?: number): Promise<ExerciseView[]>;
171
175
  get(id: number): Promise<Record<string, unknown> | null>;
172
- defaults(id: number): Promise<{
173
- param1: number | null;
174
- param2: number | null;
175
- } | null>;
176
+ defaultsMany(ids: readonly number[]): Promise<Map<number, ExerciseDefaults>>;
176
177
  create(body: Record<string, unknown>): Promise<Record<string, unknown>>;
177
178
  recordDelete(id: number): Promise<void>;
178
179
  stats(): Promise<Record<string, unknown>>;
@@ -878,6 +879,7 @@ declare function teamVolume(client: TrainHeroicClient, args: {
878
879
  declare function definedProps<T extends object>(obj: T): { [K in keyof T]: Exclude<T[K], undefined>; };
879
880
  //#endregion
880
881
  //#region src/workout-encode.d.ts
882
+ type AdvisoryIndex = Pick<ExerciseIndex, "defaultsMany" | "ensureFresh">;
881
883
  declare const LEADERBOARD_TYPE: Readonly<Record<string, number>>;
882
884
  declare const LEADERBOARD_LABEL: Readonly<Record<number, string>>;
883
885
  type Leaderboard = {
@@ -907,10 +909,10 @@ declare function unitAdvisory(blockTitle: string, ex: ExerciseSpec, defaults: {
907
909
  /**
908
910
  * Run unit advisories across a whole block list against an exercise index. Shared by the
909
911
  * MCP workout_build tool and the CLI so both surface the same notes/warnings. Ensures the
910
- * index is loaded first, otherwise `defaults` returns null on a cold index and every
912
+ * index is loaded first, otherwise the defaults map is empty on a cold index and every
911
913
  * advisory is silently dropped.
912
914
  */
913
- declare function collectAdvisories(blocks: readonly BlockSpec[], index: ExerciseIndex): Promise<Advisory>;
915
+ declare function collectAdvisories(blocks: readonly BlockSpec[], index: AdvisoryIndex): Promise<Advisory>;
914
916
  //#endregion
915
917
  //#region src/workout-session.d.ts
916
918
  type BuildOptions = {
@@ -970,10 +972,7 @@ declare class ExerciseLibrary implements ExerciseIndex {
970
972
  ensureFresh(): Promise<void>;
971
973
  refresh(): Promise<Record<string, unknown>>;
972
974
  get(id: number): Promise<Record<string, unknown> | null>;
973
- defaults(id: number): Promise<{
974
- param1: number | null;
975
- param2: number | null;
976
- } | null>;
975
+ defaultsMany(ids: readonly number[]): Promise<Map<number, ExerciseDefaults>>;
977
976
  search(query: string, limit?: number): Promise<ExerciseView[]>;
978
977
  resolve(name: string): Promise<ResolveResult>;
979
978
  create(body: Record<string, unknown>): Promise<Record<string, unknown>>;
@@ -981,4 +980,4 @@ declare class ExerciseLibrary implements ExerciseIndex {
981
980
  stats(): Promise<Record<string, unknown>>;
982
981
  }
983
982
  //#endregion
984
- export { ANALYTICS_METRIC_KEYS, AddedExercise, AnalyticsMetric, AnalyticsQueryArgs, ApiBase, AthleteMainLiftPRs, BLOCK_TYPE_CONDITIONING, BLOCK_TYPE_HYPERTROPHY, BuildOptions, ClientOptions, ClientResult, CoachAthleteCalendar, CoachRosterAthlete, DEFAULT_INVITE_MESSAGE, 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, PersonalWorkoutCreated, RequestOptions, ResolvedLift, ScheduledAlternative, SerializedExport, SessionExercise, SetResult, type SetWriteMode, SwapExerciseResult, 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, dateWindows, defaultBlockType, definedProps, deleteComment, exerciseTitle, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendar, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkoutExport, presentAthleteWorkouts, presentAthleteWorkoutsExport, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, rankSearch, readLive, readSession, removePersonalWorkout, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveBuildProgramId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, serializeWorkoutHistory, setSessionInstruction, sortRosterByRecency, str, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, updateTeam, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
983
+ export { ANALYTICS_METRIC_KEYS, AddedExercise, AnalyticsMetric, AnalyticsQueryArgs, ApiBase, AthleteMainLiftPRs, BLOCK_TYPE_CONDITIONING, BLOCK_TYPE_HYPERTROPHY, BuildOptions, ClientOptions, ClientResult, CoachAthleteCalendar, CoachRosterAthlete, DEFAULT_INVITE_MESSAGE, 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, PersonalWorkoutCreated, RequestOptions, ResolvedLift, ScheduledAlternative, SerializedExport, SessionExercise, SetResult, type SetWriteMode, SwapExerciseResult, 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, dateWindows, defaultBlockType, definedProps, deleteComment, exerciseTitle, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendar, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkoutExport, presentAthleteWorkouts, presentAthleteWorkoutsExport, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, rankSearch, readLive, readSession, removePersonalWorkout, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveBuildProgramId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, serializeWorkoutHistory, setSessionInstruction, sortRosterByRecency, str, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, updateTeam, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
package/dist/index.mjs CHANGED
@@ -2054,7 +2054,7 @@ function unitAdvisory(blockTitle, ex, defaults) {
2054
2054
  /**
2055
2055
  * Run unit advisories across a whole block list against an exercise index. Shared by the
2056
2056
  * MCP workout_build tool and the CLI so both surface the same notes/warnings. Ensures the
2057
- * index is loaded first, otherwise `defaults` returns null on a cold index and every
2057
+ * index is loaded first, otherwise the defaults map is empty on a cold index and every
2058
2058
  * advisory is silently dropped.
2059
2059
  */
2060
2060
  async function collectAdvisories(blocks, index) {
@@ -2063,14 +2063,12 @@ async function collectAdvisories(blocks, index) {
2063
2063
  block: b,
2064
2064
  ex
2065
2065
  })));
2066
- const defaults = await Promise.all(pairs.map((p) => {
2067
- const id = Number(p.ex.id);
2068
- return Number.isFinite(id) ? index.defaults(id) : Promise.resolve(null);
2069
- }));
2066
+ const ids = [...new Set(pairs.map((p) => Number(p.ex.id)).filter((id) => Number.isFinite(id)))];
2067
+ const defaultsById = await index.defaultsMany(ids);
2070
2068
  const notes = [];
2071
2069
  const warnings = [];
2072
- pairs.forEach((p, i) => {
2073
- const def = defaults[i];
2070
+ pairs.forEach((p) => {
2071
+ const def = defaultsById.get(Number(p.ex.id));
2074
2072
  if (!def) return;
2075
2073
  const advisory = unitAdvisory(p.block.title, p.ex, def);
2076
2074
  notes.push(...advisory.notes);
@@ -2330,7 +2328,8 @@ async function copySession(client, args) {
2330
2328
  year,
2331
2329
  dayOfWeek,
2332
2330
  isToday: false
2333
- }
2331
+ },
2332
+ toTimelineDate: null
2334
2333
  } });
2335
2334
  if (!res.ok) {
2336
2335
  const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
@@ -2938,12 +2937,16 @@ var ExerciseLibrary = class {
2938
2937
  if (!s) return null;
2939
2938
  return presentExercise(s.raw);
2940
2939
  }
2941
- async defaults(id) {
2942
- const s = this.#byId.get(id);
2943
- return s ? {
2944
- param1: s.param_1_type,
2945
- param2: s.param_2_type
2946
- } : null;
2940
+ async defaultsMany(ids) {
2941
+ const result = /* @__PURE__ */ new Map();
2942
+ for (const id of ids) {
2943
+ const s = this.#byId.get(id);
2944
+ if (s) result.set(id, {
2945
+ param1: s.param_1_type,
2946
+ param2: s.param_2_type
2947
+ });
2948
+ }
2949
+ return result;
2947
2950
  }
2948
2951
  async search(query, limit = 20) {
2949
2952
  await this.ensureFresh();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainheroic-unofficial/js",
3
- "version": "2.1.1",
3
+ "version": "3.0.0",
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": "2.1.1"
30
+ "@trainheroic-unofficial/dto": "3.0.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^26.2.0",