hevy-shared 1.0.962 → 1.0.963

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 (88) hide show
  1. package/README.md +17 -2
  2. package/built/API/APIClient.d.ts +157 -0
  3. package/built/API/APIClient.js +381 -0
  4. package/built/API/index.d.ts +2 -0
  5. package/built/API/index.js +18 -0
  6. package/built/API/types.d.ts +38 -0
  7. package/built/API/types.js +18 -0
  8. package/built/adjustEventTokens.d.ts +16 -0
  9. package/built/adjustEventTokens.js +18 -0
  10. package/built/adminPermissions.d.ts +4 -0
  11. package/built/adminPermissions.js +22 -0
  12. package/built/async.d.ts +50 -0
  13. package/built/async.js +170 -0
  14. package/built/chat.d.ts +25 -23
  15. package/built/coachPlans.d.ts +2 -1
  16. package/built/coachPlans.js +2 -2
  17. package/built/cue.d.ts +12 -0
  18. package/built/cue.js +22 -0
  19. package/built/exerciseLocaleUtils.d.ts +17 -0
  20. package/built/exerciseLocaleUtils.js +62 -0
  21. package/built/filterExercises.d.ts +19 -3
  22. package/built/filterExercises.js +72 -60
  23. package/built/hevyTrainer.d.ts +250 -0
  24. package/built/hevyTrainer.js +676 -0
  25. package/built/index.d.ts +1140 -304
  26. package/built/index.js +269 -75
  27. package/built/muscleHeatmaps.d.ts +31 -0
  28. package/built/muscleHeatmaps.js +68 -0
  29. package/built/muscleSplits.d.ts +36 -0
  30. package/built/muscleSplits.js +100 -0
  31. package/built/normalizedWorkoutUtils.d.ts +88 -0
  32. package/built/normalizedWorkoutUtils.js +112 -0
  33. package/built/notifications.d.ts +215 -0
  34. package/built/notifications.js +9 -0
  35. package/built/routineUtils.d.ts +14 -0
  36. package/built/routineUtils.js +186 -0
  37. package/built/schemas.d.ts +14 -0
  38. package/built/schemas.js +9 -0
  39. package/built/setIndicatorUtils.d.ts +4 -3
  40. package/built/setIndicatorUtils.js +15 -1
  41. package/built/tests/async.test.d.ts +1 -0
  42. package/built/tests/async.test.js +49 -0
  43. package/built/tests/hevyTrainer.test.d.ts +1 -0
  44. package/built/tests/hevyTrainer.test.js +1199 -0
  45. package/built/tests/muscleSplit.test.d.ts +1 -0
  46. package/built/tests/muscleSplit.test.js +153 -0
  47. package/built/tests/routineUtils.test.d.ts +1 -0
  48. package/built/tests/routineUtils.test.js +745 -0
  49. package/built/tests/testUtils.d.ts +85 -0
  50. package/built/tests/testUtils.js +319 -0
  51. package/built/tests/utils.test.js +748 -0
  52. package/built/tests/workoutVolume.test.js +165 -49
  53. package/built/translations/index.d.ts +2 -0
  54. package/built/translations/index.js +18 -0
  55. package/built/translations/translationUtils.d.ts +2 -0
  56. package/built/translations/translationUtils.js +61 -0
  57. package/built/translations/types.d.ts +8 -0
  58. package/built/translations/types.js +20 -0
  59. package/built/typeUtils.d.ts +70 -0
  60. package/built/typeUtils.js +55 -0
  61. package/built/units.d.ts +14 -7
  62. package/built/units.js +24 -14
  63. package/built/utils.d.ts +192 -5
  64. package/built/utils.js +598 -85
  65. package/built/websocket.d.ts +14 -2
  66. package/built/workoutVolume.d.ts +24 -5
  67. package/built/workoutVolume.js +25 -34
  68. package/package.json +32 -10
  69. package/.eslintignore +0 -2
  70. package/.eslintrc +0 -21
  71. package/.github/workflows/ci.yml +0 -15
  72. package/.github/workflows/npm-publish.yml +0 -59
  73. package/.github/workflows/pr-auto-assign.yml +0 -15
  74. package/.prettierrc.js +0 -5
  75. package/jest.config.js +0 -4
  76. package/src/chat.ts +0 -130
  77. package/src/coachPlans.ts +0 -57
  78. package/src/constants.ts +0 -14
  79. package/src/filterExercises.ts +0 -222
  80. package/src/index.ts +0 -1576
  81. package/src/setIndicatorUtils.ts +0 -137
  82. package/src/tests/utils.test.ts +0 -156
  83. package/src/tests/workoutVolume.test.ts +0 -93
  84. package/src/units.ts +0 -41
  85. package/src/utils.ts +0 -516
  86. package/src/websocket.ts +0 -36
  87. package/src/workoutVolume.ts +0 -175
  88. package/tsconfig.json +0 -70
@@ -1,175 +0,0 @@
1
- import { flatten } from 'lodash';
2
- import {
3
- BodyMeasurement,
4
- ExerciseType,
5
- getClosestDataPointBeforeTargetDate,
6
- Workout,
7
- } from '.';
8
-
9
- export const is100PercentBodyWeightExercise = (
10
- exerciseTemplateId: string,
11
- ): boolean => {
12
- const exerciseTemplateIds = new Set([
13
- '1B2B1E7C', // Pull Up
14
- '729237D1', // Pull Up (Weighted)
15
- '2C37EC5E', // Pull Up (Assisted)
16
- '56808FD2', // Pull Up (Band)
17
- 'A91838C0', // Kipping Pull Up
18
- 'EE2938D1', // Sternum Pull up (Gironda)
19
- '7C50F118', // Wide Pull Up
20
- 'C7AE420A', // Scapular Pull Ups
21
- '29083183', // Chin Up
22
- '023943F1', // Chin Up (Weighted)
23
- 'D23C609B', // Chin Up (Assisted)
24
- '28BB4A95', // Triceps Dip
25
- '10347BAC', // Triceps Dip (Weighted)
26
- '4B4BF8C2', // Triceps Dip (Assisted)
27
- '6FCD7755', // Chest Dip
28
- '29472BE1', // Chest Dip (Weighted)
29
- 'E9E4089F', // Chest Dip (Assisted)
30
- '51A0EDAA', // Ring Dips
31
- '9F9C164B', // Muscle Up
32
- '30F03BF0', // Front Lever Raise
33
- '90B04F96', // Handstand Push Up
34
- ]);
35
-
36
- return exerciseTemplateIds.has(exerciseTemplateId);
37
- };
38
-
39
- interface WorkoutVolumeKgProps {
40
- workout: Workout;
41
- measurements: BodyMeasurement[];
42
- }
43
-
44
- export type BodyWeightMeasurement = BodyMeasurement &
45
- Required<Pick<BodyMeasurement, 'weight_kg'>>;
46
-
47
- export const workoutVolumeKg = ({
48
- workout,
49
- measurements,
50
- }: WorkoutVolumeKgProps) => {
51
- const workoutDate = new Date(workout.start_time * 1000);
52
- /** We consider only measurements that include a body weight */
53
- const bodyWeightMeasurements = measurements.filter(
54
- (m): m is BodyWeightMeasurement => !!m.weight_kg,
55
- );
56
-
57
- /** latest logged bodyweight that is older than the workout itself */
58
- const mostRecentMeasurementBeforeWorkout =
59
- getClosestRelevantBodyWeightKgForDate(bodyWeightMeasurements, workoutDate);
60
-
61
- /**
62
- * there are no bodyweights logged *before* the workout, so take the oldest
63
- * logged bodyweight, even though it's newer than the workout, as that's the
64
- * closest approximation that we've got. if there is nothing logged at all,
65
- * then we have to take 0
66
- */
67
- const oldestLoggedMeasurement = bodyWeightMeasurements[0]?.weight_kg ?? 0;
68
-
69
- const bodyweightKg =
70
- mostRecentMeasurementBeforeWorkout ?? oldestLoggedMeasurement;
71
-
72
- return workoutVolumeSetsVolumeKg({
73
- bodyweightKg,
74
- sets: workoutToWorkoutVolumeSets(workout),
75
- });
76
- };
77
-
78
- /**
79
- * Given a date, this will return the nearest bodyweight value
80
- * that was logged before it.
81
- */
82
- export const getClosestRelevantBodyWeightKgForDate = (
83
- bodyWeightMeasurements: BodyWeightMeasurement[],
84
- date: Date,
85
- ): number | undefined => {
86
- return getClosestDataPointBeforeTargetDate(
87
- bodyWeightMeasurements,
88
- (m: BodyWeightMeasurement) => new Date(m.date),
89
- date,
90
- )?.weight_kg;
91
- };
92
-
93
- export interface WorkoutVolumeSetsVolumeKgProps {
94
- bodyweightKg: number; // Pass 0 if it's not known
95
- sets: WorkoutVolumeSet[];
96
- }
97
-
98
- export const workoutVolumeSetsVolumeKg = ({
99
- bodyweightKg,
100
- sets,
101
- }: WorkoutVolumeSetsVolumeKgProps): number => {
102
- return sets.reduce((accu, s) => {
103
- return accu + setVolumeKg(s, bodyweightKg);
104
- }, 0);
105
- };
106
-
107
- export interface WorkoutVolumeSet {
108
- type: ExerciseType;
109
- exerciseTemplateId: string;
110
- weightKg: number;
111
- reps: number;
112
- distanceMeters: number;
113
- }
114
-
115
- export const setVolumeKg = (
116
- set: WorkoutVolumeSet,
117
- bodyweightKg: number,
118
- ): number => {
119
- const { type, exerciseTemplateId, weightKg, reps, distanceMeters } = set;
120
-
121
- switch (type) {
122
- case 'weight_reps':
123
- // eg. Bench Press (Barbell)
124
- return weightKg * reps;
125
- case 'reps_only':
126
- if (is100PercentBodyWeightExercise(exerciseTemplateId)) {
127
- // eg. Pull Up
128
- return bodyweightKg * reps;
129
- } else {
130
- // eg. Push Up
131
- return 0;
132
- }
133
- case 'bodyweight_reps':
134
- if (is100PercentBodyWeightExercise(exerciseTemplateId)) {
135
- // eg. Pull Up (Weighted)
136
- return (weightKg + bodyweightKg) * reps;
137
- } else {
138
- // eg. Push Up (Weighted)
139
- return weightKg * reps;
140
- }
141
- case 'bodyweight_assisted_reps':
142
- if (is100PercentBodyWeightExercise(exerciseTemplateId)) {
143
- // eg. Pull Up (Assisted)
144
- const bodyweightAssistedRepsVolume = (bodyweightKg - weightKg) * reps;
145
- return Math.max(bodyweightAssistedRepsVolume, 0);
146
- } else {
147
- // e.g. a custom `bodyweight_assisted_reps` exercise
148
- return 0;
149
- }
150
- case 'short_distance_weight':
151
- // eg. Farmers Walk
152
- return distanceMeters * weightKg;
153
- default:
154
- // `duration` and `distance_duration` exercises
155
- return 0;
156
- }
157
- };
158
-
159
- const workoutToWorkoutVolumeSets = (workout: Workout) => {
160
- const unflatSets = workout.exercises.map((e) => {
161
- return e.sets.map((s) => {
162
- return {
163
- type: e.exercise_type || 'weight_reps',
164
- exerciseTemplateId: e.exercise_template_id,
165
- weightKg: s.weight_kg ?? 0,
166
- reps: s.reps ?? 0,
167
- distanceMeters: s.distance_meters ?? 0,
168
- } as WorkoutVolumeSet;
169
- });
170
- });
171
-
172
- const sets: WorkoutVolumeSet[] = flatten(unflatSets);
173
-
174
- return sets;
175
- };
package/tsconfig.json DELETED
@@ -1,70 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- /* Basic Options */
4
- // "incremental": true, /* Enable incremental compilation */
5
- "target": "ES2016", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
6
- "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
7
- // "lib": [], /* Specify library files to be included in the compilation. */
8
- // "allowJs": true, /* Allow javascript files to be compiled. */
9
- // "checkJs": true, /* Report errors in .js files. */
10
- // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
11
- "declaration": true, /* Generates corresponding '.d.ts' file. */
12
- // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
13
- // "sourceMap": true, /* Generates corresponding '.map' file. */
14
- // "outFile": "./", /* Concatenate and emit output to single file. */
15
- "outDir": "./built", /* Redirect output structure to the directory. */
16
- // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
17
- // "composite": true, /* Enable project compilation */
18
- // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
19
- // "removeComments": true, /* Do not emit comments to output. */
20
- // "noEmit": true, /* Do not emit outputs. */
21
- // "importHelpers": true, /* Import emit helpers from 'tslib'. */
22
- // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
23
- // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
24
-
25
- /* Strict Type-Checking Options */
26
- "strict": true, /* Enable all strict type-checking options. */
27
- // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
28
- // "strictNullChecks": true, /* Enable strict null checks. */
29
- // "strictFunctionTypes": true, /* Enable strict checking of function types. */
30
- // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
31
- // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
32
- // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
33
- // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
34
-
35
- /* Additional Checks */
36
- // "noUnusedLocals": true, /* Report errors on unused locals. */
37
- // "noUnusedParameters": true, /* Report errors on unused parameters. */
38
- // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
39
- // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
40
-
41
- /* Module Resolution Options */
42
- // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
43
- // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
44
- // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
45
- // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
46
- // "typeRoots": [], /* List of folders to include type definitions from. */
47
- // "types": [], /* Type declaration files to be included in compilation. */
48
- // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
49
- "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
50
- // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
51
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
52
-
53
- /* Source Map Options */
54
- // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
55
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
56
- // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
57
- // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
58
-
59
- /* Experimental Options */
60
- // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
61
- // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
62
-
63
- /* Advanced Options */
64
- "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
65
- },
66
- "exclude": [
67
- "node_modules",
68
- "built"
69
- ]
70
- }