@kingstinct/react-native-healthkit 4.4.6 → 5.0.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.
Files changed (231) hide show
  1. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcuserdata/robertherber.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  2. package/lib/commonjs/hooks/useHealthkitAuthorization.js +41 -0
  3. package/lib/commonjs/hooks/useHealthkitAuthorization.js.map +1 -0
  4. package/lib/commonjs/hooks/useIsHealthDataAvailable.js +29 -0
  5. package/lib/commonjs/hooks/useIsHealthDataAvailable.js.map +1 -0
  6. package/lib/commonjs/hooks/useMostRecentCategorySample.js +27 -0
  7. package/lib/commonjs/hooks/useMostRecentCategorySample.js.map +1 -0
  8. package/lib/commonjs/hooks/useMostRecentQuantitySample.js +43 -0
  9. package/lib/commonjs/hooks/useMostRecentQuantitySample.js.map +1 -0
  10. package/lib/commonjs/hooks/useMostRecentWorkout.js +60 -0
  11. package/lib/commonjs/hooks/useMostRecentWorkout.js.map +1 -0
  12. package/lib/commonjs/hooks/useStatisticsForQuantity.js +35 -0
  13. package/lib/commonjs/hooks/useStatisticsForQuantity.js.map +1 -0
  14. package/lib/commonjs/hooks/useSubscribeToChanges.js +37 -0
  15. package/lib/commonjs/hooks/useSubscribeToChanges.js.map +1 -0
  16. package/lib/commonjs/index.ios.js +66 -394
  17. package/lib/commonjs/index.ios.js.map +1 -1
  18. package/lib/commonjs/index.js +2 -15
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/commonjs/native-types.js +170 -78
  21. package/lib/commonjs/native-types.js.map +1 -1
  22. package/lib/commonjs/types.js +13 -0
  23. package/lib/commonjs/types.js.map +1 -1
  24. package/lib/commonjs/utils/deserializeCategorySample.js +15 -0
  25. package/lib/commonjs/utils/deserializeCategorySample.js.map +1 -0
  26. package/lib/commonjs/utils/deserializeCorrelation.js +32 -0
  27. package/lib/commonjs/utils/deserializeCorrelation.js.map +1 -0
  28. package/lib/commonjs/utils/deserializeSample.js +17 -0
  29. package/lib/commonjs/utils/deserializeSample.js.map +1 -0
  30. package/lib/commonjs/utils/deserializeWorkout.js +17 -0
  31. package/lib/commonjs/utils/deserializeWorkout.js.map +1 -0
  32. package/lib/commonjs/utils/ensureMetadata.js +14 -0
  33. package/lib/commonjs/utils/ensureMetadata.js.map +1 -0
  34. package/lib/commonjs/utils/ensureUnit.js +23 -0
  35. package/lib/commonjs/utils/ensureUnit.js.map +1 -0
  36. package/lib/commonjs/utils/getDateOfBirth.js +19 -0
  37. package/lib/commonjs/utils/getDateOfBirth.js.map +1 -0
  38. package/lib/commonjs/utils/getMostRecentCategorySample.js +22 -0
  39. package/lib/commonjs/utils/getMostRecentCategorySample.js.map +1 -0
  40. package/lib/commonjs/utils/getMostRecentQuantitySample.js +22 -0
  41. package/lib/commonjs/utils/getMostRecentQuantitySample.js.map +1 -0
  42. package/lib/commonjs/utils/getMostRecentWorkout.js +24 -0
  43. package/lib/commonjs/utils/getMostRecentWorkout.js.map +1 -0
  44. package/lib/commonjs/utils/getPreferredUnit.js +19 -0
  45. package/lib/commonjs/utils/getPreferredUnit.js.map +1 -0
  46. package/lib/commonjs/utils/getPreferredUnits.js +19 -0
  47. package/lib/commonjs/utils/getPreferredUnits.js.map +1 -0
  48. package/lib/commonjs/utils/getPreferredUnitsTyped.js +46 -0
  49. package/lib/commonjs/utils/getPreferredUnitsTyped.js.map +1 -0
  50. package/lib/commonjs/utils/getRequestStatusForAuthorization.js +25 -0
  51. package/lib/commonjs/utils/getRequestStatusForAuthorization.js.map +1 -0
  52. package/lib/commonjs/utils/prepareOptions.js +27 -0
  53. package/lib/commonjs/utils/prepareOptions.js.map +1 -0
  54. package/lib/commonjs/utils/queryCategorySamples.js +24 -0
  55. package/lib/commonjs/utils/queryCategorySamples.js.map +1 -0
  56. package/lib/commonjs/utils/queryCorrelationSamples.js +24 -0
  57. package/lib/commonjs/utils/queryCorrelationSamples.js.map +1 -0
  58. package/lib/commonjs/utils/queryQuantitySamples.js +27 -0
  59. package/lib/commonjs/utils/queryQuantitySamples.js.map +1 -0
  60. package/lib/commonjs/utils/queryStatisticsForQuantity.js +34 -0
  61. package/lib/commonjs/utils/queryStatisticsForQuantity.js.map +1 -0
  62. package/lib/commonjs/utils/queryWorkouts.js +30 -0
  63. package/lib/commonjs/utils/queryWorkouts.js.map +1 -0
  64. package/lib/commonjs/utils/requestAuthorization.js +25 -0
  65. package/lib/commonjs/utils/requestAuthorization.js.map +1 -0
  66. package/lib/commonjs/utils/saveCategorySample.js +21 -0
  67. package/lib/commonjs/utils/saveCategorySample.js.map +1 -0
  68. package/lib/commonjs/utils/saveCorrelationSample.js +24 -0
  69. package/lib/commonjs/utils/saveCorrelationSample.js.map +1 -0
  70. package/lib/commonjs/utils/saveQuantitySample.js +21 -0
  71. package/lib/commonjs/utils/saveQuantitySample.js.map +1 -0
  72. package/lib/commonjs/utils/saveWorkoutSample.js +25 -0
  73. package/lib/commonjs/utils/saveWorkoutSample.js.map +1 -0
  74. package/lib/commonjs/utils/serializeDate.js +12 -0
  75. package/lib/commonjs/utils/serializeDate.js.map +1 -0
  76. package/lib/commonjs/utils/subscribeToChanges.js +37 -0
  77. package/lib/commonjs/utils/subscribeToChanges.js.map +1 -0
  78. package/lib/module/hooks/useHealthkitAuthorization.js +29 -0
  79. package/lib/module/hooks/useHealthkitAuthorization.js.map +1 -0
  80. package/lib/module/hooks/useIsHealthDataAvailable.js +18 -0
  81. package/lib/module/hooks/useIsHealthDataAvailable.js.map +1 -0
  82. package/lib/module/hooks/useMostRecentCategorySample.js +15 -0
  83. package/lib/module/hooks/useMostRecentCategorySample.js.map +1 -0
  84. package/lib/module/hooks/useMostRecentQuantitySample.js +30 -0
  85. package/lib/module/hooks/useMostRecentQuantitySample.js.map +1 -0
  86. package/lib/module/hooks/useMostRecentWorkout.js +47 -0
  87. package/lib/module/hooks/useMostRecentWorkout.js.map +1 -0
  88. package/lib/module/hooks/useStatisticsForQuantity.js +23 -0
  89. package/lib/module/hooks/useStatisticsForQuantity.js.map +1 -0
  90. package/lib/module/hooks/useSubscribeToChanges.js +26 -0
  91. package/lib/module/hooks/useSubscribeToChanges.js.map +1 -0
  92. package/lib/module/index.ios.js +32 -370
  93. package/lib/module/index.ios.js.map +1 -1
  94. package/lib/module/index.js +3 -5
  95. package/lib/module/index.js.map +1 -1
  96. package/lib/module/native-types.js +154 -74
  97. package/lib/module/native-types.js.map +1 -1
  98. package/lib/module/types.js +15 -0
  99. package/lib/module/types.js.map +1 -1
  100. package/lib/module/utils/deserializeCategorySample.js +7 -0
  101. package/lib/module/utils/deserializeCategorySample.js.map +1 -0
  102. package/lib/module/utils/deserializeCorrelation.js +21 -0
  103. package/lib/module/utils/deserializeCorrelation.js.map +1 -0
  104. package/lib/module/utils/deserializeSample.js +9 -0
  105. package/lib/module/utils/deserializeSample.js.map +1 -0
  106. package/lib/module/utils/deserializeWorkout.js +9 -0
  107. package/lib/module/utils/deserializeWorkout.js.map +1 -0
  108. package/lib/module/utils/ensureMetadata.js +6 -0
  109. package/lib/module/utils/ensureMetadata.js.map +1 -0
  110. package/lib/module/utils/ensureUnit.js +13 -0
  111. package/lib/module/utils/ensureUnit.js.map +1 -0
  112. package/lib/module/utils/getDateOfBirth.js +9 -0
  113. package/lib/module/utils/getDateOfBirth.js.map +1 -0
  114. package/lib/module/utils/getMostRecentCategorySample.js +12 -0
  115. package/lib/module/utils/getMostRecentCategorySample.js.map +1 -0
  116. package/lib/module/utils/getMostRecentQuantitySample.js +12 -0
  117. package/lib/module/utils/getMostRecentQuantitySample.js.map +1 -0
  118. package/lib/module/utils/getMostRecentWorkout.js +14 -0
  119. package/lib/module/utils/getMostRecentWorkout.js.map +1 -0
  120. package/lib/module/utils/getPreferredUnit.js +9 -0
  121. package/lib/module/utils/getPreferredUnit.js.map +1 -0
  122. package/lib/module/utils/getPreferredUnits.js +9 -0
  123. package/lib/module/utils/getPreferredUnits.js.map +1 -0
  124. package/lib/module/utils/getPreferredUnitsTyped.js +34 -0
  125. package/lib/module/utils/getPreferredUnitsTyped.js.map +1 -0
  126. package/lib/module/utils/getRequestStatusForAuthorization.js +15 -0
  127. package/lib/module/utils/getRequestStatusForAuthorization.js.map +1 -0
  128. package/lib/module/utils/prepareOptions.js +17 -0
  129. package/lib/module/utils/prepareOptions.js.map +1 -0
  130. package/lib/module/utils/queryCategorySamples.js +12 -0
  131. package/lib/module/utils/queryCategorySamples.js.map +1 -0
  132. package/lib/module/utils/queryCorrelationSamples.js +12 -0
  133. package/lib/module/utils/queryCorrelationSamples.js.map +1 -0
  134. package/lib/module/utils/queryQuantitySamples.js +14 -0
  135. package/lib/module/utils/queryQuantitySamples.js.map +1 -0
  136. package/lib/module/utils/queryStatisticsForQuantity.js +23 -0
  137. package/lib/module/utils/queryStatisticsForQuantity.js.map +1 -0
  138. package/lib/module/utils/queryWorkouts.js +17 -0
  139. package/lib/module/utils/queryWorkouts.js.map +1 -0
  140. package/lib/module/utils/requestAuthorization.js +15 -0
  141. package/lib/module/utils/requestAuthorization.js.map +1 -0
  142. package/lib/module/utils/saveCategorySample.js +11 -0
  143. package/lib/module/utils/saveCategorySample.js.map +1 -0
  144. package/lib/module/utils/saveCorrelationSample.js +13 -0
  145. package/lib/module/utils/saveCorrelationSample.js.map +1 -0
  146. package/lib/module/utils/saveQuantitySample.js +11 -0
  147. package/lib/module/utils/saveQuantitySample.js.map +1 -0
  148. package/lib/module/utils/saveWorkoutSample.js +14 -0
  149. package/lib/module/utils/saveWorkoutSample.js.map +1 -0
  150. package/lib/module/utils/serializeDate.js +4 -0
  151. package/lib/module/utils/serializeDate.js.map +1 -0
  152. package/lib/module/utils/subscribeToChanges.js +25 -0
  153. package/lib/module/utils/subscribeToChanges.js.map +1 -0
  154. package/lib/typescript/example-expo/App.d.ts +2 -0
  155. package/lib/typescript/src/hooks/useHealthkitAuthorization.d.ts +3 -0
  156. package/lib/typescript/src/hooks/useIsHealthDataAvailable.d.ts +2 -0
  157. package/lib/typescript/src/hooks/useMostRecentCategorySample.d.ts +4 -0
  158. package/lib/typescript/src/hooks/useMostRecentQuantitySample.d.ts +4 -0
  159. package/lib/typescript/src/hooks/useMostRecentWorkout.d.ts +7 -0
  160. package/lib/typescript/src/hooks/useStatisticsForQuantity.d.ts +4 -0
  161. package/lib/typescript/src/hooks/useSubscribeToChanges.d.ts +3 -0
  162. package/lib/typescript/src/index.d.ts +2 -3
  163. package/lib/typescript/src/index.ios.d.ts +48 -3
  164. package/lib/typescript/src/native-types.d.ts +169 -65
  165. package/lib/typescript/src/types.d.ts +14 -90
  166. package/lib/typescript/src/utils/deserializeCategorySample.d.ts +4 -0
  167. package/lib/typescript/src/utils/deserializeCorrelation.d.ts +4 -0
  168. package/lib/typescript/src/utils/deserializeSample.d.ts +4 -0
  169. package/lib/typescript/src/utils/deserializeWorkout.d.ts +4 -0
  170. package/lib/typescript/src/utils/ensureMetadata.d.ts +2 -0
  171. package/lib/typescript/src/utils/ensureUnit.d.ts +3 -0
  172. package/lib/typescript/src/utils/getDateOfBirth.d.ts +2 -0
  173. package/lib/typescript/src/utils/getMostRecentCategorySample.d.ts +3 -0
  174. package/lib/typescript/src/utils/getMostRecentQuantitySample.d.ts +3 -0
  175. package/lib/typescript/src/utils/getMostRecentWorkout.d.ts +5 -0
  176. package/lib/typescript/src/utils/getPreferredUnit.d.ts +4 -0
  177. package/lib/typescript/src/utils/getPreferredUnits.d.ts +4 -0
  178. package/lib/typescript/src/utils/getPreferredUnitsTyped.d.ts +9 -0
  179. package/lib/typescript/src/utils/getRequestStatusForAuthorization.d.ts +3 -0
  180. package/lib/typescript/src/utils/prepareOptions.d.ts +8 -0
  181. package/lib/typescript/src/utils/queryCategorySamples.d.ts +5 -0
  182. package/lib/typescript/src/utils/queryCorrelationSamples.d.ts +5 -0
  183. package/lib/typescript/src/utils/queryQuantitySamples.d.ts +7 -0
  184. package/lib/typescript/src/utils/queryStatisticsForQuantity.d.ts +14 -0
  185. package/lib/typescript/src/utils/queryWorkouts.d.ts +4 -0
  186. package/lib/typescript/src/utils/requestAuthorization.d.ts +3 -0
  187. package/lib/typescript/src/utils/saveCategorySample.d.ts +7 -0
  188. package/lib/typescript/src/utils/saveCorrelationSample.d.ts +8 -0
  189. package/lib/typescript/src/utils/saveQuantitySample.d.ts +7 -0
  190. package/lib/typescript/src/utils/saveWorkoutSample.d.ts +7 -0
  191. package/lib/typescript/src/utils/serializeDate.d.ts +2 -0
  192. package/lib/typescript/src/utils/subscribeToChanges.d.ts +3 -0
  193. package/package.json +17 -6
  194. package/src/hooks/useHealthkitAuthorization.ts +39 -0
  195. package/src/hooks/useIsHealthDataAvailable.ts +17 -0
  196. package/src/hooks/useMostRecentCategorySample.ts +24 -0
  197. package/src/hooks/useMostRecentQuantitySample.ts +39 -0
  198. package/src/hooks/useMostRecentWorkout.ts +60 -0
  199. package/src/hooks/useStatisticsForQuantity.ts +42 -0
  200. package/src/hooks/useSubscribeToChanges.ts +31 -0
  201. package/src/index.ios.tsx +36 -569
  202. package/src/index.tsx +5 -7
  203. package/src/native-types.ts +213 -74
  204. package/src/types.ts +41 -152
  205. package/src/utils/deserializeCategorySample.ts +12 -0
  206. package/src/utils/deserializeCorrelation.ts +28 -0
  207. package/src/utils/deserializeSample.ts +17 -0
  208. package/src/utils/deserializeWorkout.ts +14 -0
  209. package/src/utils/ensureMetadata.ts +5 -0
  210. package/src/utils/ensureUnit.ts +19 -0
  211. package/src/utils/getDateOfBirth.ts +8 -0
  212. package/src/utils/getMostRecentCategorySample.ts +18 -0
  213. package/src/utils/getMostRecentQuantitySample.ts +19 -0
  214. package/src/utils/getMostRecentWorkout.ts +27 -0
  215. package/src/utils/getPreferredUnit.ts +14 -0
  216. package/src/utils/getPreferredUnits.ts +14 -0
  217. package/src/utils/getPreferredUnitsTyped.ts +38 -0
  218. package/src/utils/getRequestStatusForAuthorization.ts +21 -0
  219. package/src/utils/prepareOptions.ts +15 -0
  220. package/src/utils/queryCategorySamples.ts +29 -0
  221. package/src/utils/queryCorrelationSamples.ts +29 -0
  222. package/src/utils/queryQuantitySamples.ts +36 -0
  223. package/src/utils/queryStatisticsForQuantity.ts +38 -0
  224. package/src/utils/queryWorkouts.ts +28 -0
  225. package/src/utils/requestAuthorization.ts +18 -0
  226. package/src/utils/saveCategorySample.ts +27 -0
  227. package/src/utils/saveCorrelationSample.ts +34 -0
  228. package/src/utils/saveQuantitySample.ts +29 -0
  229. package/src/utils/saveWorkoutSample.ts +28 -0
  230. package/src/utils/serializeDate.ts +3 -0
  231. package/src/utils/subscribeToChanges.ts +32 -0
@@ -369,10 +369,10 @@ enum HKIndoorWorkout {
369
369
  export interface HKWorkoutMetadata
370
370
  extends HKGenericMetadata /* <TTemperatureUnit extends HKUnit> */ {
371
371
  readonly HKWeatherCondition?: HKWeatherCondition;
372
- readonly HKWeatherHumidity?: HKQuantity<HKUnit.Percent>;
372
+ readonly HKWeatherHumidity?: HKQuantity<HKQuantityTypeIdentifier, HKUnits.Percent>;
373
373
  // HKWeatherTemperature: HKQuantity<TTemperatureUnit>
374
- readonly HKAverageMETs?: HKQuantity<HKUnit>,
375
- readonly HKElevationAscended?: HKQuantity<HKUnit.Meters>,
374
+ readonly HKAverageMETs?: HKQuantity<HKQuantityTypeIdentifier, HKUnit>,
375
+ readonly HKElevationAscended?: HKQuantity<HKQuantityTypeIdentifier, LengthUnit>,
376
376
  readonly HKIndoorWorkout?: HKIndoorWorkout,
377
377
  }
378
378
 
@@ -388,8 +388,8 @@ export enum HKAuthorizationStatus {
388
388
  sharingAuthorized = 2,
389
389
  }
390
390
 
391
- export type HKQuantity<T extends HKUnit = HKUnit> = {
392
- readonly unit: T;
391
+ export type HKQuantity<TIdentifier extends HKQuantityTypeIdentifier = HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier> = UnitForIdentifier<TIdentifier>> = {
392
+ readonly unit: TUnit;
393
393
  readonly quantity: number;
394
394
  };
395
395
 
@@ -433,14 +433,14 @@ export enum HKStatisticsOptions {
433
433
  separateBySource = 'separateBySource',
434
434
  }
435
435
 
436
- export type QueryStatisticsResponseRaw<TUnit extends HKUnit = HKUnit> = {
437
- readonly averageQuantity?: HKQuantity<TUnit>;
438
- readonly maximumQuantity?: HKQuantity<TUnit>;
439
- readonly minimumQuantity?: HKQuantity<TUnit>;
440
- readonly sumQuantity?: HKQuantity<TUnit>;
441
- readonly mostRecentQuantity?: HKQuantity<TUnit>;
436
+ export type QueryStatisticsResponseRaw<TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier>> = {
437
+ readonly averageQuantity?: HKQuantity<TIdentifier, TUnit>;
438
+ readonly maximumQuantity?: HKQuantity<TIdentifier, TUnit>;
439
+ readonly minimumQuantity?: HKQuantity<TIdentifier, TUnit>;
440
+ readonly sumQuantity?: HKQuantity<TIdentifier, TUnit>;
441
+ readonly mostRecentQuantity?: HKQuantity<TIdentifier, TUnit>;
442
442
  readonly mostRecentQuantityDateInterval?: { readonly from: string; readonly to: string };
443
- readonly duration?: HKQuantity<HKUnit.Seconds>;
443
+ readonly duration?: HKQuantity<HKQuantityTypeIdentifier, TimeUnit>;
444
444
  };
445
445
 
446
446
  export enum HKCategoryValueCervicalMucusQuality {
@@ -531,6 +531,20 @@ export type MetadataMapperForCorrelationIdentifier<
531
531
  }
532
532
  : HKGenericMetadata;
533
533
 
534
+ export type UnitForIdentifier<T extends HKQuantityTypeIdentifier> = T extends HKQuantityTypeIdentifier.bloodGlucose ? BloodGlucoseUnit
535
+ : T extends HKQuantityTypeIdentifier.appleExerciseTime | HKQuantityTypeIdentifier.appleMoveTime | HKQuantityTypeIdentifier.appleStandTime ? TimeUnit
536
+ : T extends HKQuantityTypeIdentifier.activeEnergyBurned | HKQuantityTypeIdentifier.basalEnergyBurned | HKQuantityTypeIdentifier.dietaryEnergyConsumed ? EnergyUnit
537
+ : T extends HKQuantityTypeIdentifier.distanceCycling | HKQuantityTypeIdentifier.distanceDownhillSnowSports | HKQuantityTypeIdentifier.distanceSwimming | HKQuantityTypeIdentifier.distanceWalkingRunning | HKQuantityTypeIdentifier.distanceWheelchair | HKQuantityTypeIdentifier.sixMinuteWalkTestDistance | HKQuantityTypeIdentifier.waistCircumference ? LengthUnit
538
+ : T extends HKQuantityTypeIdentifier.bodyFatPercentage | HKQuantityTypeIdentifier.oxygenSaturation | HKQuantityTypeIdentifier.walkingAsymmetryPercentage | HKQuantityTypeIdentifier.walkingDoubleSupportPercentage ? HKUnits.Percent
539
+ : T extends HKQuantityTypeIdentifier.basalBodyTemperature | HKQuantityTypeIdentifier.basalBodyTemperature ? TemperatureUnit
540
+ : T extends HKQuantityTypeIdentifier.stairAscentSpeed | HKQuantityTypeIdentifier.stairDescentSpeed | HKQuantityTypeIdentifier.walkingSpeed | HKQuantityTypeIdentifier.walkingSpeed ? SpeedUnit<LengthUnit, TimeUnit>
541
+ : T extends HKQuantityTypeIdentifier.flightsClimbed | HKQuantityTypeIdentifier.numberOfAlcoholicBeverages | HKQuantityTypeIdentifier.numberOfTimesFallen | HKQuantityTypeIdentifier.pushCount | HKQuantityTypeIdentifier.stepCount | HKQuantityTypeIdentifier.swimmingStrokeCount ? HKUnits.Count
542
+ : T extends HKQuantityTypeIdentifier.dietaryBiotin | HKQuantityTypeIdentifier.dietaryCaffeine | HKQuantityTypeIdentifier.dietaryCalcium | HKQuantityTypeIdentifier.dietaryCarbohydrates | HKQuantityTypeIdentifier.dietaryChloride | HKQuantityTypeIdentifier.dietaryCholesterol | HKQuantityTypeIdentifier.dietaryChromium | HKQuantityTypeIdentifier.dietaryCopper | HKQuantityTypeIdentifier.dietaryFatMonounsaturated | HKQuantityTypeIdentifier.dietaryFatPolyunsaturated | HKQuantityTypeIdentifier.dietaryFatSaturated | HKQuantityTypeIdentifier.dietaryFatTotal | HKQuantityTypeIdentifier.dietaryFiber | HKQuantityTypeIdentifier.dietaryFolate | HKQuantityTypeIdentifier.dietaryIodine | HKQuantityTypeIdentifier.dietaryIodine | HKQuantityTypeIdentifier.dietaryIron | HKQuantityTypeIdentifier.dietaryMagnesium | HKQuantityTypeIdentifier.dietaryManganese | HKQuantityTypeIdentifier.dietaryMolybdenum | HKQuantityTypeIdentifier.dietaryNiacin | HKQuantityTypeIdentifier.dietaryPantothenicAcid | HKQuantityTypeIdentifier.dietaryPhosphorus | HKQuantityTypeIdentifier.dietaryPotassium | HKQuantityTypeIdentifier.dietaryProtein | HKQuantityTypeIdentifier.dietaryRiboflavin | HKQuantityTypeIdentifier.dietarySelenium | HKQuantityTypeIdentifier.dietarySodium | HKQuantityTypeIdentifier.dietarySugar | HKQuantityTypeIdentifier.dietaryThiamin | HKQuantityTypeIdentifier.dietaryVitaminA | HKQuantityTypeIdentifier.dietaryVitaminB6 | HKQuantityTypeIdentifier.dietaryVitaminB12 | HKQuantityTypeIdentifier.dietaryVitaminC | HKQuantityTypeIdentifier.dietaryVitaminD | HKQuantityTypeIdentifier.dietaryVitaminE | HKQuantityTypeIdentifier.dietaryVitaminK | HKQuantityTypeIdentifier.dietaryZinc ? MassUnit
543
+ : T extends HKQuantityTypeIdentifier.dietaryWater ? VolumeUnit
544
+ : T extends HKQuantityTypeIdentifier.insulinDelivery ? HKUnits.InternationalUnit | `${HKUnits.InternationalUnit}`
545
+ : T extends HKQuantityTypeIdentifier.heartRate | HKQuantityTypeIdentifier.restingHeartRate | HKQuantityTypeIdentifier.walkingHeartRateAverage ? CountPerTime<TimeUnit>
546
+ : HKUnit
547
+
534
548
  export type HKCategoryValueForIdentifier<T extends HKCategoryTypeIdentifier> =
535
549
  T extends HKCategoryTypeIdentifier.cervicalMucusQuality
536
550
  ? HKCategoryValueCervicalMucusQuality
@@ -606,7 +620,8 @@ export enum HKWheelchairUse {
606
620
  }
607
621
 
608
622
  // Unit types are a straight mapping from here https://developer.apple.com/documentation/healthkit/hkunit/1615733-init
609
- export enum HKUnitSIPrefix {
623
+ export enum HKMetricPrefix {
624
+ None = '',
610
625
  Pico = 'p',
611
626
  Nano = 'n',
612
627
  Micro = 'mc',
@@ -619,64 +634,179 @@ export enum HKUnitSIPrefix {
619
634
  Mega = 'M',
620
635
  Giga = 'G',
621
636
  Tera = 'T',
637
+ Femto = 'f',
622
638
  }
623
639
 
624
- export enum HKUnitSI {
625
- Grams = 'g',
626
- Joules = 'J',
640
+ export enum HKUnitMetric {
641
+ Gram = 'g',
642
+ Joule = 'J',
627
643
  Kelvin = 'K',
628
- Liters = 'l',
629
- Meters = 'm',
630
- Pascals = 'Pa',
631
- Seconds = 's',
632
- Siemens = 'S',
644
+ Liter = 'l',
645
+ Meter = 'm',
646
+ Pascal = 'Pa',
647
+ Second = 's',
648
+ Siemen = 'S',
649
+ Hertz = 'Hz',
650
+ Volt = 'V',
633
651
  }
634
652
 
635
- export enum HKUnit {
636
- Grams = 'g',
637
- Joules = 'J',
638
- Kelvin = 'K',
639
- Liters = 'l',
640
- Meters = 'm',
641
- Pascals = 'Pa',
642
- Seconds = 's',
643
- Siemens = 'S',
653
+ export enum HKUnits {
644
654
 
645
- Atmospheres = 'atm',
646
- CentimetersOfWater = 'cmAq',
647
- Count = 'count',
648
- Days = 'd',
649
655
  DecibelHearingLevel = 'dBHL',
650
656
  DecibelSoundPressureLevel = 'dBASPL',
651
- DegreesCelsius = 'degC',
652
- DegreesFahrenheit = 'degF',
657
+
658
+ Percent = '%',
659
+ Count = 'count',
660
+ InternationalUnit = 'IU',
661
+
662
+ }
663
+
664
+ export type MeterUnit<Prefix extends HKMetricPrefix = HKMetricPrefix.None> =`${Prefix}${HKUnitMetric.Meter}`;
665
+ export type LiterUnit<Prefix extends HKMetricPrefix = HKMetricPrefix.None> =`${Prefix}${HKUnitMetric.Liter}`;
666
+ export type GramUnit<Prefix extends HKMetricPrefix = HKMetricPrefix.None> =`${Prefix}${HKUnitMetric.Gram}`;
667
+ export type PascalUnit<Prefix extends HKMetricPrefix = HKMetricPrefix.None> =`${Prefix}${HKUnitMetric.Pascal}`;
668
+ export type SecondUnit<Prefix extends HKMetricPrefix = HKMetricPrefix.None> =`${Prefix}${HKUnitMetric.Second}`;
669
+ export type JouleUnit<Prefix extends HKMetricPrefix = HKMetricPrefix.None> =`${Prefix}${HKUnitMetric.Joule}`;
670
+ export type HertzUnit<Prefix extends HKMetricPrefix = HKMetricPrefix.None> =`${Prefix}${HKUnitMetric.Hertz}`;
671
+ export type VoltUnit<Prefix extends HKMetricPrefix = HKMetricPrefix.None> =`${Prefix}${HKUnitMetric.Volt}`;
672
+ export type SiemenUnit<Prefix extends HKMetricPrefix = HKMetricPrefix.None> =`${Prefix}${HKUnitMetric.Siemen}`;
673
+
674
+ // not 100% sure about these
675
+ export type MoleUnit<MolarMass extends number> =`mol<${MolarMass}>`;
676
+ export type MoleUnitWith<MolarMass extends number, Prefix extends HKMetricPrefix = HKMetricPrefix.None> =`${Prefix}mol<${MolarMass}>`;
677
+
678
+ export type FrequencyUnit = HertzUnit<HKMetricPrefix>
679
+
680
+ /**
681
+ * More SI prefixes also available as literals, just type the string
682
+ * @example 'cm', 'km'
683
+ */
684
+ export enum UnitOfLength {
653
685
  Feet = 'ft',
654
- Hertz = 'Hz',
655
- Hours = 'hr',
686
+ /**
687
+ * More SI prefixes also available as literals, just type the string
688
+ * @example 'cm', 'km'
689
+ */
690
+ Meter = 'm',
691
+ Inches = 'in',
692
+ Yards = 'yd',
693
+ Miles = 'mi',
694
+ }
695
+ export type LengthUnit = MeterUnit<HKMetricPrefix> | UnitOfLength
696
+
697
+ /**
698
+ * More SI prefixes also available as literals, just type the string
699
+ * @example 'ml', 'cl'
700
+ */
701
+ export enum UnitOfVolume {
656
702
  ImperialCup = 'cup_imp',
657
703
  ImperialFluidOunces = 'fl_oz_imp',
658
704
  ImperialPint = 'pt_imp',
659
- Inches = 'in',
660
- InternationalUnit = 'IU',
661
- Kilocalories = 'kcal',
662
- LargeCalories = 'Cal',
663
- Miles = 'mi',
664
- MillimetersOfMercury = 'mmHg',
665
- Minutes = 'min',
666
- Ounces = 'oz',
667
- Percent = '%',
668
- Pounds = 'lb',
669
- SmallCalories = 'cal',
670
- Stones = 'st',
671
705
  USCup = 'cup_us',
672
706
  USFluidOunces = 'fl_oz_us',
673
707
  USPint = 'pt_us',
674
- Yard = 'yd',
708
+ /**
709
+ * More SI prefixes also available as literals, just type the string
710
+ * @example 'ml', 'cl'
711
+ */
712
+ Liter = 'l',
713
+ }
714
+ export type VolumeUnit = LiterUnit<HKMetricPrefix> | UnitOfVolume;
715
+
716
+ /**
717
+ * More SI prefixes also available as literals, just type the string
718
+ * @example 'mg', 'kg'
719
+ */
720
+ export enum UnitOfMass {
721
+ Ounces = 'oz',
722
+ Stones = 'st',
723
+ Pounds = 'lb',
724
+ /**
725
+ * More SI prefixes also available as literals, just type the string
726
+ * @example 'mg', 'kg'
727
+ */
728
+ Gram = 'g'
729
+ }
730
+ /**
731
+ * More SI prefixes also available as literals, just type the string
732
+ * @example 'mg', 'kg'
733
+ */
734
+ export type MassUnit = GramUnit<HKMetricPrefix> | UnitOfMass
735
+
736
+ /**
737
+ * More SI prefixes also available as literals, just type the string
738
+ * @example 'kPa', 'hPa'
739
+ */
740
+ export enum UnitOfPressure {
741
+ Atmospheres = 'atm',
742
+ CentimetersOfWater = 'cmAq',
743
+ MillimetersOfMercury = 'mmHg',
744
+ InchesOfMercury = 'inHg',
745
+ DecibelAWeightedSoundPressureLevel = 'dBASPL',
746
+ /**
747
+ * More SI prefixes also available as literals, just type the string
748
+ * @example 'kPa', 'hPa'
749
+ */
750
+ Pascals = 'Pa',
751
+ }
752
+
753
+ /**
754
+ * More SI prefixes also available as literals, just type the string
755
+ * @example 'kPa', 'hPa'
756
+ */
757
+ export type PressureUnit = PascalUnit<HKMetricPrefix> | UnitOfPressure;
758
+
759
+ /**
760
+ * More SI prefixes also available as literals, just type the string
761
+ * @example 'ms'
762
+ */
763
+ export enum UnitOfTime {
764
+ Days = 'd',
765
+ Minutes = 'min',
766
+ Hours = 'hr',
767
+ /**
768
+ * More SI prefixes also available as literals, just type the string
769
+ * @example 'ms'
770
+ */
771
+ Seconds = 's',
772
+ }
773
+ /**
774
+ * More SI prefixes also available as literals, just type the string
775
+ * @example 'ms'
776
+ */
777
+ export type TimeUnit = SecondUnit<HKMetricPrefix> | UnitOfTime
778
+ export enum TemperatureUnit {
779
+ DegreesCelsius = 'degC',
780
+ DegreesFahrenheit = 'degF',
781
+ Kelvin = 'K',
782
+ }
675
783
 
784
+ /**
785
+ * More SI prefixes also available as literals, just type the string
786
+ * @example 'kJ'
787
+ */
788
+ export enum UnitOfEnergy {
789
+ Kilocalories = 'kcal',
790
+ LargeCalories = 'Cal',
791
+ SmallCalories = 'cal',
792
+ /**
793
+ * More SI prefixes also available as literals, just type the string
794
+ * @example 'kJ'
795
+ */
796
+ Joules = 'J',
797
+ }
798
+ export type EnergyUnit = JouleUnit<HKMetricPrefix> | UnitOfEnergy
799
+ export enum BloodGlucoseUnit {
676
800
  GlucoseMmolPerL = 'mmol<180.15588000005408>/l',
677
801
  GlucoseMgPerDl = 'mg/dL',
678
802
  }
679
803
 
804
+ export type SpeedUnit<TLength extends LengthUnit, TTime extends TimeUnit> =`${TLength}/${TTime}`;
805
+ export type CountPerTime<TTime extends TimeUnit> =`count/${TTime}`;
806
+
807
+ export type HKUnit = BloodGlucoseUnit | CountPerTime<TimeUnit> | EnergyUnit | FrequencyUnit | HKUnits | LengthUnit | MassUnit | PressureUnit | SpeedUnit<LengthUnit, TimeUnit> | TemperatureUnit | TimeUnit | VolumeUnit
808
+ | `${BloodGlucoseUnit}` | `${EnergyUnit}` | `${FrequencyUnit}` | `${HKUnits}` | `${LengthUnit}` | `${MassUnit}` | `${PressureUnit}` | `${TemperatureUnit}` | `${TimeUnit}` | `${VolumeUnit}`;
809
+
680
810
  export type HKDevice = {
681
811
  readonly name: string; // ex: "Apple Watch"
682
812
  readonly firmwareVersion: string | null;
@@ -701,7 +831,7 @@ export type HKSourceRevision = {
701
831
 
702
832
  export type HKQuantitySampleRaw<
703
833
  TQuantityIdentifier extends HKQuantityTypeIdentifier = HKQuantityTypeIdentifier,
704
- TUnit extends HKUnit = HKUnit
834
+ TUnit extends UnitForIdentifier<TQuantityIdentifier> = UnitForIdentifier<TQuantityIdentifier>,
705
835
  > = {
706
836
  readonly uuid: string;
707
837
  readonly device?: HKDevice;
@@ -714,15 +844,30 @@ export type HKQuantitySampleRaw<
714
844
  readonly sourceRevision?: HKSourceRevision;
715
845
  };
716
846
 
717
- export type HKWorkoutRaw<TEnergy extends HKUnit, TDistance extends HKUnit> = {
847
+ export type HKQuantitySampleRawForSaving<
848
+ TQuantityIdentifier extends HKQuantityTypeIdentifier = HKQuantityTypeIdentifier,
849
+ TUnit extends UnitForIdentifier<TQuantityIdentifier> = UnitForIdentifier<TQuantityIdentifier>,
850
+ > = Omit<
851
+ HKQuantitySampleRaw<TQuantityIdentifier, TUnit>,
852
+ 'device' | 'endDate' | 'startDate' | 'uuid'
853
+ >
854
+
855
+ export type HKCategorySampleRawForSaving<
856
+ TCategory extends HKCategoryTypeIdentifier = HKCategoryTypeIdentifier,
857
+ > = Omit<
858
+ HKCategorySampleRaw<TCategory>,
859
+ 'device' | 'endDate' | 'startDate' | 'uuid'
860
+ >
861
+
862
+ export type HKWorkoutRaw<TEnergy extends EnergyUnit, TDistance extends LengthUnit> = {
718
863
  readonly uuid: string;
719
864
  readonly device?: HKDevice;
720
865
  readonly workoutActivityType: HKWorkoutActivityType;
721
866
  readonly duration: number;
722
- readonly totalDistance?: HKQuantity<TDistance>;
723
- readonly totalEnergyBurned?: HKQuantity<TEnergy>;
724
- readonly totalSwimmingStrokeCount?: HKQuantity<HKUnit.Count>;
725
- readonly totalFlightsClimbed?: HKQuantity<HKUnit.Count>;
867
+ readonly totalDistance?: HKQuantity<HKQuantityTypeIdentifier, TDistance>;
868
+ readonly totalEnergyBurned?: HKQuantity<HKQuantityTypeIdentifier, TEnergy>;
869
+ readonly totalSwimmingStrokeCount?: HKQuantity<HKQuantityTypeIdentifier, HKUnits.Count>;
870
+ readonly totalFlightsClimbed?: HKQuantity<HKQuantityTypeIdentifier, HKUnits.Count>;
726
871
  readonly startDate: string;
727
872
  readonly endDate: string;
728
873
  readonly metadata?: HKWorkoutMetadata;
@@ -812,12 +957,9 @@ type ReactNativeHealthkitTypeNative = {
812
957
  ) => Promise<boolean>;
813
958
  readonly disableAllBackgroundDelivery: () => Promise<boolean>;
814
959
 
815
- readonly saveCorrelationSample: <TIdentifier extends HKCorrelationTypeIdentifier>(
960
+ readonly saveCorrelationSample: <TIdentifier extends HKCorrelationTypeIdentifier, TSamples extends readonly (HKCategorySampleRawForSaving | HKQuantitySampleRawForSaving)[]>(
816
961
  typeIdentifier: TIdentifier,
817
- samples: readonly Omit<
818
- HKCategorySampleRaw | HKQuantitySampleRaw,
819
- 'device' | 'endDate' | 'startDate' | 'uuid'
820
- >[],
962
+ samples: TSamples,
821
963
  start: string,
822
964
  end: string,
823
965
  metadata: MetadataMapperForCorrelationIdentifier<TIdentifier>
@@ -825,10 +967,7 @@ type ReactNativeHealthkitTypeNative = {
825
967
 
826
968
  readonly saveWorkoutSample: (
827
969
  typeIdentifier: HKWorkoutActivityType,
828
- quantities: readonly Omit<
829
- HKQuantitySampleRaw,
830
- 'device' | 'endDate' | 'startDate' | 'uuid'
831
- >[],
970
+ quantities: readonly HKQuantitySampleRawForSaving[],
832
971
  start: string,
833
972
  end: string,
834
973
  metadata: HKWorkoutMetadata
@@ -855,15 +994,15 @@ type ReactNativeHealthkitTypeNative = {
855
994
  write: WritePermissions,
856
995
  read: ReadPermissions
857
996
  ): Promise<boolean>;
858
- readonly saveQuantitySample: (
859
- identifier: HKQuantityTypeIdentifier,
860
- unit: HKUnit,
997
+ readonly saveQuantitySample: <TType extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TType> = UnitForIdentifier<TType>> (
998
+ identifier: TType,
999
+ unit: TUnit,
861
1000
  value: number,
862
1001
  start: string,
863
1002
  end: string,
864
1003
  metadata: unknown
865
1004
  ) => Promise<boolean>;
866
- readonly queryWorkoutSamples: <TEnergy extends HKUnit, TDistance extends HKUnit>(
1005
+ readonly queryWorkoutSamples: <TEnergy extends EnergyUnit, TDistance extends LengthUnit>(
867
1006
  energyUnit: TEnergy,
868
1007
  distanceUnit: TDistance,
869
1008
  from: string,
@@ -879,8 +1018,8 @@ type ReactNativeHealthkitTypeNative = {
879
1018
  ascending: boolean
880
1019
  ) => Promise<readonly HKCategorySampleRaw<T>[]>;
881
1020
  readonly queryQuantitySamples: <
882
- TUnit extends HKUnit,
883
- TIdentifier extends HKQuantityTypeIdentifier
1021
+ TIdentifier extends HKQuantityTypeIdentifier,
1022
+ TUnit extends UnitForIdentifier<TIdentifier>,
884
1023
  >(
885
1024
  identifier: TIdentifier,
886
1025
  unit: TUnit,
@@ -896,13 +1035,13 @@ type ReactNativeHealthkitTypeNative = {
896
1035
  end: string,
897
1036
  metadata: unknown
898
1037
  ) => Promise<boolean>;
899
- readonly queryStatisticsForQuantity: <TUnit extends HKUnit>(
1038
+ readonly queryStatisticsForQuantity: <TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier>>(
900
1039
  identifier: HKQuantityTypeIdentifier,
901
1040
  unit: TUnit,
902
1041
  from: string,
903
1042
  to: string,
904
1043
  options: readonly HKStatisticsOptions[]
905
- ) => Promise<QueryStatisticsResponseRaw<TUnit>>;
1044
+ ) => Promise<QueryStatisticsResponseRaw<TIdentifier, TUnit>>;
906
1045
  readonly getPreferredUnits: (
907
1046
  identifiers: readonly HKQuantityTypeIdentifier[]
908
1047
  ) => Promise<TypeToUnitMapping>;