@trainheroic-unofficial/cli 3.0.0 → 3.0.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.
Files changed (2) hide show
  1. package/dist/cli.mjs +23 -35
  2. package/package.json +3 -3
package/dist/cli.mjs CHANGED
@@ -800,8 +800,9 @@ function sortRosterByRecency(rows) {
800
800
  async function fetchRosterActivity(client, athleteIds, useMetric = false) {
801
801
  const rows = [];
802
802
  const concurrency = 6;
803
- for (let i = 0; i < athleteIds.length; i += concurrency) {
804
- const chunk = athleteIds.slice(i, i + concurrency);
803
+ const uniqueAthleteIds = [...new Set(athleteIds)];
804
+ for (let i = 0; i < uniqueAthleteIds.length; i += concurrency) {
805
+ const chunk = uniqueAthleteIds.slice(i, i + concurrency);
805
806
  const settled = await Promise.all(chunk.map(async (id) => {
806
807
  try {
807
808
  return {
@@ -1979,7 +1980,7 @@ function prescribedExerciseLabels(workouts) {
1979
1980
  return labels;
1980
1981
  }
1981
1982
  /** Group resolved exercises by saved set and write each set via the given log target. */
1982
- async function logResolvedExercises(client, target, date, resolved) {
1983
+ async function logResolvedExercises(client, target, workouts, resolved) {
1983
1984
  const bySet = /* @__PURE__ */ new Map();
1984
1985
  for (const r of resolved) {
1985
1986
  const list = bySet.get(r.savedWorkoutSetId) ?? [];
@@ -1991,19 +1992,10 @@ async function logResolvedExercises(client, target, date, resolved) {
1991
1992
  }
1992
1993
  const out = [];
1993
1994
  for (const [savedWorkoutSetId, results] of bySet) {
1994
- const written = target.role === "coach" ? await logForAthlete(client, {
1995
- athleteId: target.athleteId,
1996
- date,
1997
- savedWorkoutSetId,
1998
- results
1999
- }) : await logAthleteSet(client, {
2000
- date,
2001
- savedWorkoutSetId,
2002
- results
2003
- });
1995
+ const written = await writeSetResults(client, target, workouts, savedWorkoutSetId, results, "log");
2004
1996
  out.push({
2005
1997
  savedWorkoutSetId: written.savedWorkoutSetId,
2006
- exercisesLogged: written.exercisesLogged
1998
+ exercisesLogged: written.exercisesWritten
2007
1999
  });
2008
2000
  }
2009
2001
  return out;
@@ -2041,7 +2033,7 @@ async function logAdHocSession(client, args) {
2041
2033
  sets: e.sets
2042
2034
  };
2043
2035
  });
2044
- const sets = await logResolvedExercises(client, { role: "athlete" }, args.date, resolved);
2036
+ const sets = await logResolvedExercises(client, { role: "athlete" }, await fetchAthleteWorkouts(client, args.date, args.date), resolved);
2045
2037
  const result = {
2046
2038
  date: args.date,
2047
2039
  created,
@@ -2079,7 +2071,7 @@ async function logSessionForAthlete(client, args) {
2079
2071
  const sets = await logResolvedExercises(client, {
2080
2072
  role: "coach",
2081
2073
  athleteId: args.athleteId
2082
- }, args.date, resolved);
2074
+ }, day, resolved);
2083
2075
  return {
2084
2076
  date: args.date,
2085
2077
  created: false,
@@ -2439,6 +2431,7 @@ async function collectAdvisories(blocks, index) {
2439
2431
  }
2440
2432
  //#endregion
2441
2433
  //#region ../js/src/workout-session.ts
2434
+ const EXERCISE_SAVE_CONCURRENCY = 4;
2442
2435
  /**
2443
2436
  * Coach calendar writes (`createWorkoutForDay`, timeline create, `copyProgramWorkout`) 500/401
2444
2437
  * on personal calendars (Coach Plan / `personal_cal`). Shared by `buildSession` and
@@ -2472,15 +2465,14 @@ async function buildSession(client, opts) {
2472
2465
  const created = await req(client, "POST", "/2.0/coach/calendar/saveProgramWorkoutSets", buildBlockPayload(blocks, workoutId));
2473
2466
  const byOrder = new Map(created.map((b) => [b.order, b.id]));
2474
2467
  let counter = 0;
2475
- const payloads = blocks.map((block, i) => {
2468
+ await mapPool(blocks.map((block, i) => {
2476
2469
  const wsid = byOrder.get(i + 1);
2477
2470
  if (wsid === void 0) throw new Error(`No saved block for order ${i + 1}.`);
2478
2471
  return block.exercises.map((ex, j) => {
2479
2472
  counter += 1;
2480
2473
  return makeExercise(ex, wsid, j + 1, `k::${workoutId}${String(counter).padStart(3, "0")}`);
2481
2474
  });
2482
- });
2483
- await Promise.all(payloads.filter((p) => p.length > 0).map((p) => req(client, "POST", "/2.0/coach/calendar/saveWorkoutSetExercises", p)));
2475
+ }).filter((p) => p.length > 0), EXERCISE_SAVE_CONCURRENCY, (payload) => req(client, "POST", "/2.0/coach/calendar/saveWorkoutSetExercises", payload));
2484
2476
  if (opts.instruction !== void 0 && opts.instruction !== "") {
2485
2477
  const blockIds = [...byOrder.entries()].sort((a, b) => a[0] - b[0]).map(([, id]) => id);
2486
2478
  await setSessionInstruction(client, workoutId, sess, opts.instruction, blockIds);
@@ -3186,9 +3178,11 @@ async function deleteComment(client, streamId, commentId) {
3186
3178
  if (!res.ok) throw new Error(`Message delete failed (HTTP ${res.status}).`);
3187
3179
  return res.data;
3188
3180
  }
3189
- async function readLive(client, streamId, limit) {
3190
- const res = await client.request("GET", `/v5/messaging/streams/${streamId}/comments?lastCommentId=`);
3181
+ async function readLive(client, streamId, limit, afterCommentId) {
3182
+ const cursor = afterCommentId === void 0 ? "" : String(afterCommentId);
3183
+ const res = await client.request("GET", `/v5/messaging/streams/${streamId}/comments?lastCommentId=${cursor}`);
3191
3184
  if (!res.ok || !Array.isArray(res.data)) throw new Error(`Message read failed (HTTP ${res.status}).`);
3185
+ if (afterCommentId !== void 0) return limit !== void 0 && limit > 0 ? res.data.slice(0, limit) : res.data;
3192
3186
  return limit !== void 0 && limit > 0 ? res.data.slice(-limit) : res.data;
3193
3187
  }
3194
3188
  //#endregion
@@ -3319,21 +3313,12 @@ var ExerciseLibrary = class {
3319
3313
  }
3320
3314
  async resolve(name) {
3321
3315
  await this.ensureFresh();
3322
- let hit = this.#exact(name);
3316
+ const hit = this.#exact(name);
3323
3317
  if (hit) return {
3324
3318
  match: hit,
3325
3319
  candidates: [hit]
3326
3320
  };
3327
- let candidates = this.#searchOnly(name, 20);
3328
- if (candidates.length === 0) {
3329
- await this.refresh();
3330
- hit = this.#exact(name);
3331
- if (hit) return {
3332
- match: hit,
3333
- candidates: [hit]
3334
- };
3335
- candidates = this.#searchOnly(name, 20);
3336
- }
3321
+ const candidates = this.#searchOnly(name, 20);
3337
3322
  if (candidates.length === 1) return {
3338
3323
  match: candidates[0] ?? null,
3339
3324
  candidates
@@ -3521,7 +3506,7 @@ Coach — manage a roster (needs a coach account):
3521
3506
 
3522
3507
  messaging:
3523
3508
  coach message list
3524
- coach message read <streamId> [--limit N]
3509
+ coach message read <streamId> [--limit N] [--after <commentId>]
3525
3510
  coach message draft <streamId> <text> [--reply-to <id>]
3526
3511
  coach message send <streamId> <text> [--reply-to <id>] --yes
3527
3512
  coach message delete <streamId> <commentId> --yes
@@ -3756,8 +3741,11 @@ async function cmdMessage(client, rest) {
3756
3741
  userId: stream.userId
3757
3742
  })));
3758
3743
  case "read": {
3759
- const { values, positionals } = parse(a, { limit: { type: "string" } });
3760
- return out(await readLive(client, toInt(need(positionals[0], "coach message read <streamId> [--limit N]"), "streamId"), values.limit !== void 0 ? toInt(values.limit, "--limit") : 20));
3744
+ const { values, positionals } = parse(a, {
3745
+ limit: { type: "string" },
3746
+ after: { type: "string" }
3747
+ });
3748
+ return out(await readLive(client, toInt(need(positionals[0], "coach message read <streamId> [--limit N] [--after <commentId>]"), "streamId"), values.limit !== void 0 ? toInt(values.limit, "--limit") : 20, values.after !== void 0 ? toInt(values.after, "--after") : void 0));
3761
3749
  }
3762
3750
  case "draft": {
3763
3751
  const { values, positionals } = parse(a, { "reply-to": { type: "string" } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainheroic-unofficial/cli",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,8 +21,8 @@
21
21
  ],
22
22
  "dependencies": {
23
23
  "zod": "^4.4.3",
24
- "@trainheroic-unofficial/dto": "3.0.0",
25
- "@trainheroic-unofficial/js": "3.0.0"
24
+ "@trainheroic-unofficial/dto": "3.0.1",
25
+ "@trainheroic-unofficial/js": "3.0.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^26.2.0",