@sunsteel/contracts 0.64.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
@@ -371,8 +371,34 @@ function resolveActiveTrainingBlock(blocks, date) {
371
371
  }
372
372
  function resolveRoutinePlan(routine, date) {
373
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
+ }
374
399
  if (block) {
375
400
  return {
401
+ override: null,
376
402
  block: {
377
403
  id: block.id,
378
404
  seriesId: block.seriesId,
@@ -390,6 +416,7 @@ function resolveRoutinePlan(routine, date) {
390
416
  }
391
417
  return {
392
418
  block: null,
419
+ override: null,
393
420
  scheduleMode: routine.scheduleMode,
394
421
  restDays: routine.restDays,
395
422
  rotationWeekdays: routine.rotationWeekdays ?? [],
@@ -398,6 +425,57 @@ function resolveRoutinePlan(routine, date) {
398
425
  };
399
426
  }
400
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
+ }
478
+
401
479
  // src/routine-sharing.ts
402
480
  var ROUTINE_VISIBILITY_VALUES = [
403
481
  "PRIVATE",
@@ -636,6 +714,13 @@ export {
636
714
  COMEBACK_REQUIRED_ACTIVE_DAYS,
637
715
  COMEBACK_SESSION_LOOKBACK,
638
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,
639
724
  EXERCISE_EQUIPMENT,
640
725
  EXERCISE_MECHANICS,
641
726
  FEATURED_PROFILE_ITEMS_MAX,
@@ -724,6 +809,8 @@ export {
724
809
  SHARED_ROUTINE_SOURCES,
725
810
  STARRED_EXERCISES_MAX,
726
811
  STREAK_MAX_GAP_DAYS,
812
+ TEMPORARY_OVERRIDE_KINDS,
813
+ TEMPORARY_OVERRIDE_SOURCE_KINDS,
727
814
  TRAINING_DISCIPLINE_VALUES,
728
815
  TRAINING_EVENT_TYPES,
729
816
  TRAINING_EXPERIENCE_LEVEL_VALUES,
@@ -740,6 +827,8 @@ export {
740
827
  WEIGHT_UNITS,
741
828
  WORKOUT_SESSION_STATUSES,
742
829
  accountExportFileName,
830
+ applyDeload,
831
+ deloadLengthDays,
743
832
  isWithinQuietHours,
744
833
  matchesDeletionConfirmation,
745
834
  resolveActiveTrainingBlock,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunsteel/contracts",
3
- "version": "0.64.0",
3
+ "version": "0.65.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ezee969/sunsteel-contracts.git"