@sunsteel/contracts 0.63.0 → 0.65.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.js CHANGED
@@ -363,6 +363,118 @@ var ROUTINE_TRAINING_BLOCK_SOURCE_KINDS = [
363
363
  "CURRENT_ROUTINE",
364
364
  "SAVED_VERSION"
365
365
  ];
366
+ function trainingBlockCovers(block, date) {
367
+ return block.startDate <= date && date <= block.endDate;
368
+ }
369
+ function resolveActiveTrainingBlock(blocks, date) {
370
+ return blocks?.find((block) => trainingBlockCovers(block, date)) ?? null;
371
+ }
372
+ function resolveRoutinePlan(routine, date) {
373
+ const block = resolveActiveTrainingBlock(routine.trainingBlocks, date);
374
+ const deload = resolveActiveTrainingBlock(routine.temporaryOverrides, date);
375
+ const blockInForce = block ? {
376
+ id: block.id,
377
+ seriesId: block.seriesId,
378
+ revision: block.revision,
379
+ name: block.name,
380
+ startDate: block.startDate,
381
+ endDate: block.endDate
382
+ } : null;
383
+ if (deload) {
384
+ return {
385
+ block: blockInForce,
386
+ override: {
387
+ id: deload.id,
388
+ kind: deload.kind,
389
+ startDate: deload.startDate,
390
+ endDate: deload.endDate
391
+ },
392
+ scheduleMode: deload.scheduleMode,
393
+ restDays: deload.restDays,
394
+ rotationWeekdays: deload.rotationWeekdays,
395
+ nextRotationDayId: deload.nextRotationDayId,
396
+ days: deload.days
397
+ };
398
+ }
399
+ if (block) {
400
+ return {
401
+ override: null,
402
+ block: {
403
+ id: block.id,
404
+ seriesId: block.seriesId,
405
+ revision: block.revision,
406
+ name: block.name,
407
+ startDate: block.startDate,
408
+ endDate: block.endDate
409
+ },
410
+ scheduleMode: block.scheduleMode,
411
+ restDays: block.restDays,
412
+ rotationWeekdays: block.rotationWeekdays,
413
+ nextRotationDayId: block.nextRotationDayId,
414
+ days: block.days
415
+ };
416
+ }
417
+ return {
418
+ block: null,
419
+ override: null,
420
+ scheduleMode: routine.scheduleMode,
421
+ restDays: routine.restDays,
422
+ rotationWeekdays: routine.rotationWeekdays ?? [],
423
+ nextRotationDayId: routine.nextRotationDayId ?? null,
424
+ days: routine.days
425
+ };
426
+ }
427
+
428
+ // src/deloads.ts
429
+ var DELOAD_MAX_DAYS = 14;
430
+ var DELOAD_DEFAULT_DAYS = 7;
431
+ var DELOAD_LOAD_REDUCTIONS = [0, 10, 20, 30, 40];
432
+ var DELOAD_DEFAULT_LOAD_REDUCTION = 10;
433
+ var DELOAD_SET_MODES = ["ALL", "HALF"];
434
+ var DELOAD_DEFAULT_SET_MODE = "HALF";
435
+ var TEMPORARY_OVERRIDE_KINDS = ["DELOAD"];
436
+ var TEMPORARY_OVERRIDE_SOURCE_KINDS = [
437
+ "BASELINE",
438
+ "TRAINING_BLOCK"
439
+ ];
440
+ var DELOAD_NOT_LIGHTER = "Those options leave every set as it is: choose a lighter load or fewer sets";
441
+ var lighterOnGrid = (original, target, increment) => {
442
+ const step = increment > 0 ? increment : 2.5;
443
+ const stepped = Math.round(Math.round(target / step) * step * 1e3) / 1e3;
444
+ return stepped > 0 && stepped < original ? stepped : original;
445
+ };
446
+ function applyDeload(setup, options) {
447
+ const factor = 1 - options.loadReductionPercent / 100;
448
+ let lighter = false;
449
+ const days = setup.days.map((day) => ({
450
+ ...day,
451
+ exercises: day.exercises.map((exercise) => {
452
+ const kept = options.setMode === "HALF" ? exercise.sets.slice(0, Math.ceil(exercise.sets.length / 2)) : exercise.sets;
453
+ if (kept.length < exercise.sets.length) lighter = true;
454
+ return {
455
+ ...exercise,
456
+ sets: kept.map((set) => {
457
+ if (typeof set.weight !== "number" || set.weight <= 0) {
458
+ return { ...set };
459
+ }
460
+ if (factor === 1) return { ...set };
461
+ const weight = lighterOnGrid(
462
+ set.weight,
463
+ set.weight * factor,
464
+ exercise.minWeightIncrement
465
+ );
466
+ if (weight < set.weight) lighter = true;
467
+ return { ...set, weight };
468
+ })
469
+ };
470
+ })
471
+ }));
472
+ return lighter ? { ...setup, days } : null;
473
+ }
474
+ function deloadLengthDays(startDate, endDate) {
475
+ const ms = (date) => Date.parse(`${date}T00:00:00Z`);
476
+ return Math.round((ms(endDate) - ms(startDate)) / 864e5) + 1;
477
+ }
366
478
 
367
479
  // src/routine-sharing.ts
368
480
  var ROUTINE_VISIBILITY_VALUES = [
@@ -602,6 +714,13 @@ export {
602
714
  COMEBACK_REQUIRED_ACTIVE_DAYS,
603
715
  COMEBACK_SESSION_LOOKBACK,
604
716
  COMEBACK_WINDOW_DAYS,
717
+ DELOAD_DEFAULT_DAYS,
718
+ DELOAD_DEFAULT_LOAD_REDUCTION,
719
+ DELOAD_DEFAULT_SET_MODE,
720
+ DELOAD_LOAD_REDUCTIONS,
721
+ DELOAD_MAX_DAYS,
722
+ DELOAD_NOT_LIGHTER,
723
+ DELOAD_SET_MODES,
605
724
  EXERCISE_EQUIPMENT,
606
725
  EXERCISE_MECHANICS,
607
726
  FEATURED_PROFILE_ITEMS_MAX,
@@ -690,6 +809,8 @@ export {
690
809
  SHARED_ROUTINE_SOURCES,
691
810
  STARRED_EXERCISES_MAX,
692
811
  STREAK_MAX_GAP_DAYS,
812
+ TEMPORARY_OVERRIDE_KINDS,
813
+ TEMPORARY_OVERRIDE_SOURCE_KINDS,
693
814
  TRAINING_DISCIPLINE_VALUES,
694
815
  TRAINING_EVENT_TYPES,
695
816
  TRAINING_EXPERIENCE_LEVEL_VALUES,
@@ -706,9 +827,14 @@ export {
706
827
  WEIGHT_UNITS,
707
828
  WORKOUT_SESSION_STATUSES,
708
829
  accountExportFileName,
830
+ applyDeload,
831
+ deloadLengthDays,
709
832
  isWithinQuietHours,
710
833
  matchesDeletionConfirmation,
834
+ resolveActiveTrainingBlock,
835
+ resolveRoutinePlan,
711
836
  routineDayLabel,
712
837
  sessionCorrectionWindow,
713
- setLogValuesDiffer
838
+ setLogValuesDiffer,
839
+ trainingBlockCovers
714
840
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunsteel/contracts",
3
- "version": "0.63.0",
3
+ "version": "0.65.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ezee969/sunsteel-contracts.git"