@trainheroic-unofficial/js 0.2.0 → 0.3.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
@@ -69,8 +69,19 @@ declare const PARAM_RPE = 14;
69
69
  declare function coerceInt(value: unknown): number | null;
70
70
  declare function coerceNum(value: unknown): number | null;
71
71
  declare function unitLabel(paramType: unknown): string | null;
72
- /** Annotate a row with human-readable units for display. */
72
+ /**
73
+ * Fixed measurement units for an exercise, ordered by entry slot (param 1, then param 2).
74
+ * Positional, not semantic: some exercises reverse the slots, so the array is not labelled
75
+ * by role. A null entry is an unset slot.
76
+ */
77
+ declare function exerciseUnits(param1: unknown, param2: unknown): Array<string | null>;
78
+ /** Present a row for display: drop the raw param-type codes, surface units positionally. */
73
79
  declare function withUnits(row: ExerciseRow): ExerciseView;
80
+ /**
81
+ * Present a full raw exercise object for display: drop the raw param-type codes and add the
82
+ * positional `units` array. Keeps every other field of the raw object intact.
83
+ */
84
+ declare function presentExercise(raw: Record<string, unknown>): Record<string, unknown>;
74
85
  declare function buildSearchText(title: string): string;
75
86
  /** Strip the {"success":1,"data":X} envelope some 2.0/coach endpoints use. */
76
87
  declare function unwrapEnvelope(body: unknown): unknown;
@@ -195,4 +206,4 @@ declare class ExerciseLibrary implements ExerciseIndex {
195
206
  stats(): Promise<Record<string, unknown>>;
196
207
  }
197
208
  //#endregion
198
- export { ApiBase, BuildOptions, ClientResult, ExerciseIndex, ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, Leaderboard, LibraryCache, LibrarySnapshot, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, RequestOptions, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicSession, asExerciseList, buildBlockPayload, buildCommentPayload, buildSearchText, buildSession, checkResponse, chunk, coerceInt, coerceNum, collectAdvisories, deleteComment, fetchStreams, isRecord, loginTrainHeroic, makeExercise, publishSession, rankSearch, readLive, readSession, removeSession, repsList, resolveLeaderboard, sendComment, setSessionInstruction, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
209
+ export { ApiBase, BuildOptions, ClientResult, ExerciseIndex, ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, Leaderboard, LibraryCache, LibrarySnapshot, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, RequestOptions, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicSession, asExerciseList, buildBlockPayload, buildCommentPayload, buildSearchText, buildSession, checkResponse, chunk, coerceInt, coerceNum, collectAdvisories, deleteComment, exerciseUnits, fetchStreams, isRecord, loginTrainHeroic, makeExercise, presentExercise, publishSession, rankSearch, readLive, readSession, removeSession, repsList, resolveLeaderboard, sendComment, setSessionInstruction, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
package/dist/index.mjs CHANGED
@@ -175,12 +175,31 @@ function unitLabel(paramType) {
175
175
  if (t === null) return null;
176
176
  return PARAM_UNIT[t] ?? null;
177
177
  }
178
- /** Annotate a row with human-readable units for display. */
178
+ /**
179
+ * Fixed measurement units for an exercise, ordered by entry slot (param 1, then param 2).
180
+ * Positional, not semantic: some exercises reverse the slots, so the array is not labelled
181
+ * by role. A null entry is an unset slot.
182
+ */
183
+ function exerciseUnits(param1, param2) {
184
+ return [unitLabel(param1), unitLabel(param2)];
185
+ }
186
+ /** Present a row for display: drop the raw param-type codes, surface units positionally. */
179
187
  function withUnits(row) {
188
+ const { param_1_type, param_2_type, ...rest } = row;
189
+ return {
190
+ ...rest,
191
+ units: exerciseUnits(param_1_type, param_2_type)
192
+ };
193
+ }
194
+ /**
195
+ * Present a full raw exercise object for display: drop the raw param-type codes and add the
196
+ * positional `units` array. Keeps every other field of the raw object intact.
197
+ */
198
+ function presentExercise(raw) {
199
+ const { param_1_type, param_2_type, ...rest } = raw;
180
200
  return {
181
- ...row,
182
- param_1_unit: unitLabel(row.param_1_type),
183
- param_2_unit: unitLabel(row.param_2_type)
201
+ ...rest,
202
+ units: exerciseUnits(param_1_type, param_2_type)
184
203
  };
185
204
  }
186
205
  function buildSearchText(title) {
@@ -741,10 +760,7 @@ var ExerciseLibrary = class {
741
760
  await this.ensureFresh();
742
761
  const s = this.#byId.get(id);
743
762
  if (!s) return null;
744
- const full = { ...s.raw };
745
- full.param_1_unit = unitLabel(full.param_1_type);
746
- full.param_2_unit = unitLabel(full.param_2_type);
747
- return full;
763
+ return presentExercise(s.raw);
748
764
  }
749
765
  async defaults(id) {
750
766
  const s = this.#byId.get(id);
@@ -824,4 +840,4 @@ var ExerciseLibrary = class {
824
840
  }
825
841
  };
826
842
  //#endregion
827
- export { ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, TrainHeroicAuthError, TrainHeroicClient, asExerciseList, buildBlockPayload, buildCommentPayload, buildSearchText, buildSession, checkResponse, chunk, coerceInt, coerceNum, collectAdvisories, deleteComment, fetchStreams, isRecord, loginTrainHeroic, makeExercise, publishSession, rankSearch, readLive, readSession, removeSession, repsList, resolveLeaderboard, sendComment, setSessionInstruction, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
843
+ export { ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, TrainHeroicAuthError, TrainHeroicClient, asExerciseList, buildBlockPayload, buildCommentPayload, buildSearchText, buildSession, checkResponse, chunk, coerceInt, coerceNum, collectAdvisories, deleteComment, exerciseUnits, fetchStreams, isRecord, loginTrainHeroic, makeExercise, presentExercise, publishSession, rankSearch, readLive, readSession, removeSession, repsList, resolveLeaderboard, sendComment, setSessionInstruction, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainheroic-unofficial/js",
3
- "version": "0.2.0",
3
+ "version": "0.3.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": "0.2.0"
30
+ "@trainheroic-unofficial/dto": "0.3.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^26.0.0",