curated2: review fixes — touch drag (!45), deload seeds (!28), rep-range typing (!69), rebuilt rows on config change (!54), swap keeps history (!43), Hevy retry/dedup/aliases (!30), HTTPS doc (!67), locale gaps
This commit is contained in:
1 parent
148ef9fbbb
commit
cc878dd353
26 files changed
+230
-64
No files matched your search
@@ -1,7 +1,9 @@
|
||||
// AUTO-GENERATED by scripts/build-hevy-id-map.mjs — do not edit by hand.
|
||||
// Hevy exercise_template id → openGym catalogue id, plus English title → id for CSV exports
|
||||
// (Hevy CSV has titles, not template ids). Regenerated from the Hevy templates API +
|
||||
// verified title aliases.
|
||||
// verified title aliases. Five title aliases whose catalogue match was wrong (crunch → weighted
|
||||
// crunch, side plank → hip adduction, machine squat → barbell squat, cable triceps extension and
|
||||
// cable reverse fly → lever machines) are left out; those titles import as custom exercises.
|
||||
// 283 mapped · 168 left unmatched (import as custom).
|
||||
// Source templates: 451 (built-in only).
|
||||
|
||||
@@ -348,7 +350,6 @@ export const HEVY_TITLE_MAP = {
|
||||
"clean and press": "0028",
|
||||
"concentration curl": "0297",
|
||||
"cross body hammer curl": "0298",
|
||||
"crunch": "0832",
|
||||
"crunch (machine)": "1452",
|
||||
"crunch (weighted)": "0832",
|
||||
"cycling": "2331",
|
||||
@@ -473,7 +474,6 @@ export const HEVY_TITLE_MAP = {
|
||||
"push up (weighted)": "0662",
|
||||
"push up - close grip": "0259",
|
||||
"rack pull": "0074",
|
||||
"rear delt reverse fly (cable)": "0602",
|
||||
"rear delt reverse fly (dumbbell)": "0383",
|
||||
"rear delt reverse fly (machine)": "0602",
|
||||
"renegade row (dumbbell)": "0521",
|
||||
@@ -516,7 +516,6 @@ export const HEVY_TITLE_MAP = {
|
||||
"shrug (machine)": "0604",
|
||||
"shrug (smith machine)": "0767",
|
||||
"side bend (dumbbell)": "0407",
|
||||
"side plank": "1775",
|
||||
"single arm lateral raise (cable)": "0192",
|
||||
"single leg standing calf raise (machine)": "0605",
|
||||
"sissy squat (weighted)": "1489",
|
||||
@@ -530,7 +529,6 @@ export const HEVY_TITLE_MAP = {
|
||||
"squat (barbell)": "0043",
|
||||
"squat (bodyweight)": "3543",
|
||||
"squat (dumbbell)": "0413",
|
||||
"squat (machine)": "0043",
|
||||
"squat (smith machine)": "0770",
|
||||
"squat (suspension)": "0043",
|
||||
"squat row": "1003",
|
||||
@@ -558,7 +556,6 @@ export const HEVY_TITLE_MAP = {
|
||||
"triceps dip (assisted)": "0019",
|
||||
"triceps dip (weighted)": "0591",
|
||||
"triceps extension (barbell)": "0607",
|
||||
"triceps extension (cable)": "0607",
|
||||
"triceps extension (dumbbell)": "0607",
|
||||
"triceps extension (machine)": "0607",
|
||||
"triceps extension (suspension)": "0607",
|
||||
|
||||
@@ -308,11 +308,17 @@ export function buildSets(S, cfg, options = {}) {
|
||||
export const MAX_PLANNED_WARMUPS = 5
|
||||
|
||||
function buildWorkSets(S, cfg, options = {}) {
|
||||
const last = lastEntryFor(S, cfg.id)
|
||||
const n = Math.max(1, cfg.sets || 1)
|
||||
const mode = modeOf(cfg)
|
||||
const preferLast = !!options.preferLast
|
||||
const useTarget = !!options.useTarget
|
||||
// A workout flagged excludeFromProgression (a planned deload) is not "last time" for the
|
||||
// next regular session either: its reps and durations must not seed the rows any more than
|
||||
// its weight seeds the prescription. The deload session itself reads the routine's own target.
|
||||
const regular = (S.workouts || []).some(w => w.excludeFromProgression === true)
|
||||
? { ...S, workouts: S.workouts.filter(w => w.excludeFromProgression !== true) }
|
||||
: S
|
||||
const last = lastEntryFor(regular, cfg.id)
|
||||
const n = Math.max(1, cfg.sets || 1)
|
||||
const mode = modeOf(cfg)
|
||||
const sets = []
|
||||
// A deload routine must use its own prescription instead of carrying regular-session values
|
||||
// into the workout. Other planned sessions keep the existing history-first behaviour.
|
||||
@@ -341,8 +347,11 @@ function buildWorkSets(S, cfg, options = {}) {
|
||||
const usable = prev && prev.r > 0 ? prev : null
|
||||
// Planned sessions may use the confirmed working weight, while freestyle should reproduce
|
||||
// the load of each matching set when that option is requested.
|
||||
// A deload uses the routine's target weight; a routine that never set one (weight 0) falls
|
||||
// back to the last regular load rather than prescribing an empty bar.
|
||||
const lastRegular = last ? (last.sets[i] || last.sets[last.sets.length - 1]) : null
|
||||
const w = useTarget
|
||||
? cfg.weight
|
||||
? (cfg.weight > 0 ? cfg.weight : (lastRegular && lastRegular.r > 0 ? lastRegular.w : cfg.weight))
|
||||
: preferLast && usable ? usable.w : (conf && conf.w > 0 ? conf.w : (usable ? usable.w : cfg.weight))
|
||||
sets.push({ w, r: usable ? usable.r : cfg.reps, done: false })
|
||||
}
|
||||
|
||||
@@ -31,12 +31,22 @@ async function hevyGet(path, apiKey, params = {}) {
|
||||
for (const [k, v] of Object.entries(params)) {
|
||||
if (v != null && v !== '') url.searchParams.set(k, String(v))
|
||||
}
|
||||
const res = await fetch(url, { headers: { 'api-key': apiKey } })
|
||||
if (res.status === 401 || res.status === 403) {
|
||||
throw new HevyApiError(res.status, 'auth')
|
||||
// Hevy publishes no rate limit, but a large account is 100+ sequential page requests; a 429
|
||||
// gets a short back-off and one more try before it surfaces as its own error kind.
|
||||
for (let attempt = 0; ; attempt++) {
|
||||
const res = await fetch(url, { headers: { 'api-key': apiKey } })
|
||||
if (res.status === 401 || res.status === 403) {
|
||||
throw new HevyApiError(res.status, 'auth')
|
||||
}
|
||||
if (res.status === 429 && attempt < 2) {
|
||||
const after = Number(res.headers?.get?.('retry-after'))
|
||||
await new Promise(r => setTimeout(r, (after > 0 && after <= 30 ? after : 2 * (attempt + 1)) * 1000))
|
||||
continue
|
||||
}
|
||||
if (res.status === 429) throw new HevyApiError(res.status, 'rate-limit')
|
||||
if (!res.ok) throw new HevyApiError(res.status, `http ${res.status}`)
|
||||
return res.json()
|
||||
}
|
||||
if (!res.ok) throw new HevyApiError(res.status, `http ${res.status}`)
|
||||
return res.json()
|
||||
}
|
||||
|
||||
/** Page through a Hevy list endpoint. `pageSize` caps differ per resource. */
|
||||
@@ -371,17 +381,28 @@ export function mergeHevyRoutines(S, parsed) {
|
||||
// Keep the pre-assigned id from parse so routine configs already point at it.
|
||||
if (!S.customEx.some(x => x.id === c.id)) S.customEx.push(c)
|
||||
})
|
||||
let added = 0
|
||||
// A second import must not double every plan: a routine that already carries the same Hevy
|
||||
// id is replaced in place (its exercises re-read from Hevy), everything else is appended.
|
||||
let added = 0, updated = 0
|
||||
for (const r of parsed.routines || []) {
|
||||
const ex = (r.ex || []).map(e => ({ ...e, id: exIdMap[e.id] || e.id }))
|
||||
const existing = r.hevyId ? S.routines.find(x => x.hevyId === r.hevyId) : null
|
||||
if (existing) {
|
||||
existing.name = r.name
|
||||
existing.ex = ex
|
||||
updated++
|
||||
continue
|
||||
}
|
||||
S.routines.push({
|
||||
id: uid(),
|
||||
name: r.name,
|
||||
emoji: r.emoji || 'figureStrength',
|
||||
ex: (r.ex || []).map(e => ({ ...e, id: exIdMap[e.id] || e.id })),
|
||||
...(r.hevyId ? { hevyId: r.hevyId } : {}),
|
||||
ex,
|
||||
})
|
||||
added++
|
||||
}
|
||||
return { added }
|
||||
return { added, updated }
|
||||
}
|
||||
|
||||
/** Body measurements from the Hevy API → `mergeImport` bodyweight shape. */
|
||||
|
||||
@@ -269,14 +269,25 @@ describe('parseHevyRoutines', () => {
|
||||
expect(pull.sg).toBe(row.sg)
|
||||
})
|
||||
|
||||
it('mergeHevyRoutines always adds new routines', () => {
|
||||
it('mergeHevyRoutines replaces a routine it imported before instead of duplicating it', () => {
|
||||
const parsed = parseHevyRoutines([ROUTINE], TEMPLATES, { unit: 'kg' })
|
||||
const S = { routines: [], customEx: [] }
|
||||
expect(mergeHevyRoutines(S, parsed).added).toBe(1)
|
||||
expect(mergeHevyRoutines(S, parsed)).toEqual({ added: 1, updated: 0 })
|
||||
expect(S.routines).toHaveLength(1)
|
||||
expect(mergeHevyRoutines(S, parsed).added).toBe(1)
|
||||
expect(S.routines[0].hevyId).toBe(ROUTINE.id)
|
||||
const firstId = S.routines[0].id
|
||||
S.routines[0].name = 'renamed locally'
|
||||
expect(mergeHevyRoutines(S, parsed)).toEqual({ added: 0, updated: 1 })
|
||||
expect(S.routines).toHaveLength(1)
|
||||
expect(S.routines[0].id).toBe(firstId)
|
||||
expect(S.routines[0].name).toBe(ROUTINE.title)
|
||||
})
|
||||
|
||||
it('mergeHevyRoutines still adds a routine that carries no Hevy id', () => {
|
||||
const parsed = parseHevyRoutines([{ ...ROUTINE, id: undefined }], TEMPLATES, { unit: 'kg' })
|
||||
const S = { routines: [], customEx: [] }
|
||||
mergeHevyRoutines(S, parsed); mergeHevyRoutines(S, parsed)
|
||||
expect(S.routines).toHaveLength(2)
|
||||
expect(S.routines[0].id).not.toBe(S.routines[1].id)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ describe('Brazilian Portuguese locale', () => {
|
||||
.sort(byCodeUnit)
|
||||
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
|
||||
|
||||
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(331)
|
||||
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(333)
|
||||
expect(inherited).toHaveLength(448)
|
||||
// If this fails, review the changed keys and wording before accepting a new hash. From
|
||||
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
|
||||
|
||||
Reference in new issue
Block a user