@kingstinct/react-native-healthkit 8.7.2 → 9.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 (449) hide show
  1. package/ReactNativeHealthkit.podspec +36 -0
  2. package/app.plugin.js +43 -33
  3. package/ios/Bridge.h +8 -0
  4. package/ios/CategoryTypeModule.swift +128 -0
  5. package/ios/CharacteristicTypeModule.swift +78 -0
  6. package/ios/Constants.swift +2 -0
  7. package/ios/CoreModule.swift +376 -0
  8. package/ios/CorrelationTypeModule.swift +153 -0
  9. package/ios/HeartbeatSeriesModule.swift +189 -0
  10. package/ios/Helpers.swift +529 -251
  11. package/ios/QuantityTypeModule.swift +461 -0
  12. package/ios/Serializers.swift +211 -124
  13. package/ios/SourceProxy.swift +35 -0
  14. package/ios/StateOfMindModule.swift +160 -0
  15. package/ios/WorkoutProxy.swift +405 -0
  16. package/ios/WorkoutSessionModule.swift +182 -0
  17. package/ios/WorkoutsModule.swift +357 -0
  18. package/package.json +43 -127
  19. package/react-native.config.js +16 -0
  20. package/src/hooks/useHealthkitAuthorization.test.ts +47 -29
  21. package/src/hooks/useHealthkitAuthorization.ts +21 -15
  22. package/src/hooks/useIsHealthDataAvailable.test.ts +17 -7
  23. package/src/hooks/useIsHealthDataAvailable.ts +7 -7
  24. package/src/hooks/useMostRecentCategorySample.ts +10 -12
  25. package/src/hooks/useMostRecentQuantitySample.ts +17 -36
  26. package/src/hooks/useMostRecentWorkout.ts +16 -38
  27. package/src/hooks/useSources.ts +8 -12
  28. package/src/hooks/useStatisticsForQuantity.ts +19 -14
  29. package/src/hooks/useSubscribeToChanges.ts +9 -13
  30. package/src/index.ios.ts +232 -0
  31. package/src/index.ts +444 -0
  32. package/src/modules.ts +43 -0
  33. package/src/specs/CategoryTypeModule.nitro.ts +64 -0
  34. package/src/specs/CharacteristicTypeModule.nitro.ts +22 -0
  35. package/src/specs/CoreModule.nitro.ts +107 -0
  36. package/src/specs/CorrelationTypeModule.nitro.ts +23 -0
  37. package/src/specs/HeartbeatSeriesModule.nitro.ts +19 -0
  38. package/src/specs/QuantityTypeModule.nitro.ts +60 -0
  39. package/src/specs/SourceProxy.nitro.ts +13 -0
  40. package/src/specs/StateOfMindModule.nitro.ts +23 -0
  41. package/src/specs/WorkoutProxy.nitro.ts +18 -0
  42. package/src/specs/WorkoutSessionModule.nitro.ts +71 -0
  43. package/src/specs/WorkoutsModule.nitro.ts +32 -0
  44. package/src/test-setup.ts +68 -54
  45. package/src/test-utils.ts +3 -2
  46. package/src/types/Auth.ts +17 -0
  47. package/src/types/Background.ts +9 -0
  48. package/src/types/CategoryType.ts +249 -0
  49. package/src/types/CategoryTypeIdentifier.ts +99 -0
  50. package/src/types/Characteristics.ts +53 -0
  51. package/src/types/Constants.ts +25 -0
  52. package/src/types/CorrelationType.ts +31 -0
  53. package/src/types/Device.ts +13 -0
  54. package/src/types/HeartbeatSeries.ts +29 -0
  55. package/src/types/InterfaceVerification.ts +164 -0
  56. package/src/types/InterfaceVerificationExample.ts +89 -0
  57. package/src/types/QuantitySample.ts +30 -0
  58. package/src/types/QuantityType.ts +192 -0
  59. package/src/types/QuantityTypeIdentifier.ts +758 -0
  60. package/src/types/QueryOptions.ts +69 -0
  61. package/src/types/README-InterfaceVerification.md +103 -0
  62. package/src/types/Shared.ts +79 -0
  63. package/src/types/Source.ts +11 -0
  64. package/src/types/StateOfMind.ts +110 -0
  65. package/src/types/Subscriptons.ts +10 -0
  66. package/src/types/Units.ts +190 -0
  67. package/src/types/WeatherCondition.ts +31 -0
  68. package/src/types/WorkoutKit.ts +18 -0
  69. package/src/types/Workouts.ts +282 -0
  70. package/src/utils/getMostRecentCategorySample.ts +7 -11
  71. package/src/utils/getMostRecentQuantitySample.ts +8 -18
  72. package/src/utils/getMostRecentWorkout.ts +7 -17
  73. package/src/utils/getPreferredUnit.ts +12 -8
  74. package/src/utils/subscribeToChanges.ts +9 -26
  75. package/LICENSE +0 -21
  76. package/README.md +0 -179
  77. package/ios/ReactNativeHealthkit-Bridging-Header.h +0 -2
  78. package/ios/ReactNativeHealthkit.m +0 -271
  79. package/ios/ReactNativeHealthkit.swift +0 -2333
  80. package/ios/ReactNativeHealthkit.xcodeproj/project.pbxproj +0 -279
  81. package/kingstinct-react-native-healthkit.podspec +0 -21
  82. package/lib/commonjs/hooks/useHealthkitAuthorization.js +0 -39
  83. package/lib/commonjs/hooks/useHealthkitAuthorization.js.map +0 -1
  84. package/lib/commonjs/hooks/useHealthkitAuthorization.test.js +0 -72
  85. package/lib/commonjs/hooks/useHealthkitAuthorization.test.js.map +0 -1
  86. package/lib/commonjs/hooks/useIsHealthDataAvailable.js +0 -27
  87. package/lib/commonjs/hooks/useIsHealthDataAvailable.js.map +0 -1
  88. package/lib/commonjs/hooks/useIsHealthDataAvailable.test.js +0 -41
  89. package/lib/commonjs/hooks/useIsHealthDataAvailable.test.js.map +0 -1
  90. package/lib/commonjs/hooks/useMostRecentCategorySample.js +0 -23
  91. package/lib/commonjs/hooks/useMostRecentCategorySample.js.map +0 -1
  92. package/lib/commonjs/hooks/useMostRecentQuantitySample.js +0 -37
  93. package/lib/commonjs/hooks/useMostRecentQuantitySample.js.map +0 -1
  94. package/lib/commonjs/hooks/useMostRecentWorkout.js +0 -48
  95. package/lib/commonjs/hooks/useMostRecentWorkout.js.map +0 -1
  96. package/lib/commonjs/hooks/useSources.js +0 -22
  97. package/lib/commonjs/hooks/useSources.js.map +0 -1
  98. package/lib/commonjs/hooks/useStatisticsForQuantity.js +0 -28
  99. package/lib/commonjs/hooks/useStatisticsForQuantity.js.map +0 -1
  100. package/lib/commonjs/hooks/useSubscribeToChanges.js +0 -28
  101. package/lib/commonjs/hooks/useSubscribeToChanges.js.map +0 -1
  102. package/lib/commonjs/index.ios.js +0 -531
  103. package/lib/commonjs/index.ios.js.map +0 -1
  104. package/lib/commonjs/index.js +0 -22
  105. package/lib/commonjs/index.js.map +0 -1
  106. package/lib/commonjs/index.native.js +0 -235
  107. package/lib/commonjs/index.native.js.map +0 -1
  108. package/lib/commonjs/index.web.js +0 -22
  109. package/lib/commonjs/index.web.js.map +0 -1
  110. package/lib/commonjs/native-types.js +0 -1575
  111. package/lib/commonjs/native-types.js.map +0 -1
  112. package/lib/commonjs/test-setup.js +0 -57
  113. package/lib/commonjs/test-setup.js.map +0 -1
  114. package/lib/commonjs/test-utils.js +0 -18
  115. package/lib/commonjs/test-utils.js.map +0 -1
  116. package/lib/commonjs/types.js +0 -17
  117. package/lib/commonjs/types.js.map +0 -1
  118. package/lib/commonjs/utils/deleteQuantitySample.js +0 -11
  119. package/lib/commonjs/utils/deleteQuantitySample.js.map +0 -1
  120. package/lib/commonjs/utils/deleteSamples.js +0 -18
  121. package/lib/commonjs/utils/deleteSamples.js.map +0 -1
  122. package/lib/commonjs/utils/deleteWorkoutSample.js +0 -11
  123. package/lib/commonjs/utils/deleteWorkoutSample.js.map +0 -1
  124. package/lib/commonjs/utils/deserializeCategorySample.js +0 -13
  125. package/lib/commonjs/utils/deserializeCategorySample.js.map +0 -1
  126. package/lib/commonjs/utils/deserializeCategorySample.test.js +0 -26
  127. package/lib/commonjs/utils/deserializeCategorySample.test.js.map +0 -1
  128. package/lib/commonjs/utils/deserializeCorrelation.js +0 -26
  129. package/lib/commonjs/utils/deserializeCorrelation.js.map +0 -1
  130. package/lib/commonjs/utils/deserializeHeartbeatSeriesSample.js +0 -15
  131. package/lib/commonjs/utils/deserializeHeartbeatSeriesSample.js.map +0 -1
  132. package/lib/commonjs/utils/deserializeSample.js +0 -15
  133. package/lib/commonjs/utils/deserializeSample.js.map +0 -1
  134. package/lib/commonjs/utils/deserializeWorkout.js +0 -15
  135. package/lib/commonjs/utils/deserializeWorkout.js.map +0 -1
  136. package/lib/commonjs/utils/ensureMetadata.js +0 -11
  137. package/lib/commonjs/utils/ensureMetadata.js.map +0 -1
  138. package/lib/commonjs/utils/ensureTotals.js +0 -11
  139. package/lib/commonjs/utils/ensureTotals.js.map +0 -1
  140. package/lib/commonjs/utils/ensureUnit.js +0 -17
  141. package/lib/commonjs/utils/ensureUnit.js.map +0 -1
  142. package/lib/commonjs/utils/getDateOfBirth.js +0 -14
  143. package/lib/commonjs/utils/getDateOfBirth.js.map +0 -1
  144. package/lib/commonjs/utils/getMostRecentCategorySample.js +0 -17
  145. package/lib/commonjs/utils/getMostRecentCategorySample.js.map +0 -1
  146. package/lib/commonjs/utils/getMostRecentQuantitySample.js +0 -21
  147. package/lib/commonjs/utils/getMostRecentQuantitySample.js.map +0 -1
  148. package/lib/commonjs/utils/getMostRecentWorkout.js +0 -19
  149. package/lib/commonjs/utils/getMostRecentWorkout.js.map +0 -1
  150. package/lib/commonjs/utils/getPreferredUnit.js +0 -14
  151. package/lib/commonjs/utils/getPreferredUnit.js.map +0 -1
  152. package/lib/commonjs/utils/getPreferredUnits.js +0 -14
  153. package/lib/commonjs/utils/getPreferredUnits.js.map +0 -1
  154. package/lib/commonjs/utils/getPreferredUnitsTyped.js +0 -33
  155. package/lib/commonjs/utils/getPreferredUnitsTyped.js.map +0 -1
  156. package/lib/commonjs/utils/getRequestStatusForAuthorization.js +0 -21
  157. package/lib/commonjs/utils/getRequestStatusForAuthorization.js.map +0 -1
  158. package/lib/commonjs/utils/getWorkoutPlanById.js +0 -13
  159. package/lib/commonjs/utils/getWorkoutPlanById.js.map +0 -1
  160. package/lib/commonjs/utils/prepareOptions.js +0 -25
  161. package/lib/commonjs/utils/prepareOptions.js.map +0 -1
  162. package/lib/commonjs/utils/queryCategorySamples.js +0 -17
  163. package/lib/commonjs/utils/queryCategorySamples.js.map +0 -1
  164. package/lib/commonjs/utils/queryCategorySamplesWithAnchor.js +0 -21
  165. package/lib/commonjs/utils/queryCategorySamplesWithAnchor.js.map +0 -1
  166. package/lib/commonjs/utils/queryCorrelationSamples.js +0 -17
  167. package/lib/commonjs/utils/queryCorrelationSamples.js.map +0 -1
  168. package/lib/commonjs/utils/queryHeartbeatSeriesSamples.js +0 -17
  169. package/lib/commonjs/utils/queryHeartbeatSeriesSamples.js.map +0 -1
  170. package/lib/commonjs/utils/queryHeartbeatSeriesSamplesWithAnchor.js +0 -21
  171. package/lib/commonjs/utils/queryHeartbeatSeriesSamplesWithAnchor.js.map +0 -1
  172. package/lib/commonjs/utils/queryQuantitySamples.js +0 -19
  173. package/lib/commonjs/utils/queryQuantitySamples.js.map +0 -1
  174. package/lib/commonjs/utils/queryQuantitySamplesWithAnchor.js +0 -23
  175. package/lib/commonjs/utils/queryQuantitySamplesWithAnchor.js.map +0 -1
  176. package/lib/commonjs/utils/querySources.js +0 -14
  177. package/lib/commonjs/utils/querySources.js.map +0 -1
  178. package/lib/commonjs/utils/queryStateOfMindSamples.js +0 -22
  179. package/lib/commonjs/utils/queryStateOfMindSamples.js.map +0 -1
  180. package/lib/commonjs/utils/queryStatisticsCollectionForQuantity.js +0 -16
  181. package/lib/commonjs/utils/queryStatisticsCollectionForQuantity.js.map +0 -1
  182. package/lib/commonjs/utils/queryStatisticsForQuantity.js +0 -29
  183. package/lib/commonjs/utils/queryStatisticsForQuantity.js.map +0 -1
  184. package/lib/commonjs/utils/queryWorkoutSamplesWithAnchor.js +0 -26
  185. package/lib/commonjs/utils/queryWorkoutSamplesWithAnchor.js.map +0 -1
  186. package/lib/commonjs/utils/queryWorkouts.js +0 -22
  187. package/lib/commonjs/utils/queryWorkouts.js.map +0 -1
  188. package/lib/commonjs/utils/requestAuthorization.js +0 -22
  189. package/lib/commonjs/utils/requestAuthorization.js.map +0 -1
  190. package/lib/commonjs/utils/saveCategorySample.js +0 -20
  191. package/lib/commonjs/utils/saveCategorySample.js.map +0 -1
  192. package/lib/commonjs/utils/saveCorrelationSample.js +0 -35
  193. package/lib/commonjs/utils/saveCorrelationSample.js.map +0 -1
  194. package/lib/commonjs/utils/saveQuantitySample.js +0 -16
  195. package/lib/commonjs/utils/saveQuantitySample.js.map +0 -1
  196. package/lib/commonjs/utils/saveStateOfMindSample.js +0 -17
  197. package/lib/commonjs/utils/saveStateOfMindSample.js.map +0 -1
  198. package/lib/commonjs/utils/saveWorkoutRoute.js +0 -26
  199. package/lib/commonjs/utils/saveWorkoutRoute.js.map +0 -1
  200. package/lib/commonjs/utils/saveWorkoutSample.js +0 -36
  201. package/lib/commonjs/utils/saveWorkoutSample.js.map +0 -1
  202. package/lib/commonjs/utils/serializeDate.js +0 -9
  203. package/lib/commonjs/utils/serializeDate.js.map +0 -1
  204. package/lib/commonjs/utils/serializeDate.test.js +0 -17
  205. package/lib/commonjs/utils/serializeDate.test.js.map +0 -1
  206. package/lib/commonjs/utils/startWatchApp.js +0 -11
  207. package/lib/commonjs/utils/startWatchApp.js.map +0 -1
  208. package/lib/commonjs/utils/subscribeToChanges.js +0 -27
  209. package/lib/commonjs/utils/subscribeToChanges.js.map +0 -1
  210. package/lib/module/hooks/useHealthkitAuthorization.js +0 -32
  211. package/lib/module/hooks/useHealthkitAuthorization.js.map +0 -1
  212. package/lib/module/hooks/useHealthkitAuthorization.test.js +0 -68
  213. package/lib/module/hooks/useHealthkitAuthorization.test.js.map +0 -1
  214. package/lib/module/hooks/useIsHealthDataAvailable.js +0 -21
  215. package/lib/module/hooks/useIsHealthDataAvailable.js.map +0 -1
  216. package/lib/module/hooks/useIsHealthDataAvailable.test.js +0 -37
  217. package/lib/module/hooks/useIsHealthDataAvailable.test.js.map +0 -1
  218. package/lib/module/hooks/useMostRecentCategorySample.js +0 -16
  219. package/lib/module/hooks/useMostRecentCategorySample.js.map +0 -1
  220. package/lib/module/hooks/useMostRecentQuantitySample.js +0 -30
  221. package/lib/module/hooks/useMostRecentQuantitySample.js.map +0 -1
  222. package/lib/module/hooks/useMostRecentWorkout.js +0 -41
  223. package/lib/module/hooks/useMostRecentWorkout.js.map +0 -1
  224. package/lib/module/hooks/useSources.js +0 -15
  225. package/lib/module/hooks/useSources.js.map +0 -1
  226. package/lib/module/hooks/useStatisticsForQuantity.js +0 -21
  227. package/lib/module/hooks/useStatisticsForQuantity.js.map +0 -1
  228. package/lib/module/hooks/useSubscribeToChanges.js +0 -21
  229. package/lib/module/hooks/useSubscribeToChanges.js.map +0 -1
  230. package/lib/module/index.ios.js +0 -209
  231. package/lib/module/index.ios.js.map +0 -1
  232. package/lib/module/index.js +0 -4
  233. package/lib/module/index.js.map +0 -1
  234. package/lib/module/index.native.js +0 -160
  235. package/lib/module/index.native.js.map +0 -1
  236. package/lib/module/index.web.js +0 -4
  237. package/lib/module/index.web.js.map +0 -1
  238. package/lib/module/native-types.js +0 -1606
  239. package/lib/module/native-types.js.map +0 -1
  240. package/lib/module/test-setup.js +0 -54
  241. package/lib/module/test-setup.js.map +0 -1
  242. package/lib/module/test-utils.js +0 -11
  243. package/lib/module/test-utils.js.map +0 -1
  244. package/lib/module/types.js +0 -67
  245. package/lib/module/types.js.map +0 -1
  246. package/lib/module/utils/deleteQuantitySample.js +0 -4
  247. package/lib/module/utils/deleteQuantitySample.js.map +0 -1
  248. package/lib/module/utils/deleteSamples.js +0 -11
  249. package/lib/module/utils/deleteSamples.js.map +0 -1
  250. package/lib/module/utils/deleteWorkoutSample.js +0 -4
  251. package/lib/module/utils/deleteWorkoutSample.js.map +0 -1
  252. package/lib/module/utils/deserializeCategorySample.js +0 -7
  253. package/lib/module/utils/deserializeCategorySample.js.map +0 -1
  254. package/lib/module/utils/deserializeCategorySample.test.js +0 -22
  255. package/lib/module/utils/deserializeCategorySample.test.js.map +0 -1
  256. package/lib/module/utils/deserializeCorrelation.js +0 -19
  257. package/lib/module/utils/deserializeCorrelation.js.map +0 -1
  258. package/lib/module/utils/deserializeHeartbeatSeriesSample.js +0 -9
  259. package/lib/module/utils/deserializeHeartbeatSeriesSample.js.map +0 -1
  260. package/lib/module/utils/deserializeSample.js +0 -9
  261. package/lib/module/utils/deserializeSample.js.map +0 -1
  262. package/lib/module/utils/deserializeWorkout.js +0 -9
  263. package/lib/module/utils/deserializeWorkout.js.map +0 -1
  264. package/lib/module/utils/ensureMetadata.js +0 -5
  265. package/lib/module/utils/ensureMetadata.js.map +0 -1
  266. package/lib/module/utils/ensureTotals.js +0 -5
  267. package/lib/module/utils/ensureTotals.js.map +0 -1
  268. package/lib/module/utils/ensureUnit.js +0 -10
  269. package/lib/module/utils/ensureUnit.js.map +0 -1
  270. package/lib/module/utils/getDateOfBirth.js +0 -7
  271. package/lib/module/utils/getDateOfBirth.js.map +0 -1
  272. package/lib/module/utils/getMostRecentCategorySample.js +0 -10
  273. package/lib/module/utils/getMostRecentCategorySample.js.map +0 -1
  274. package/lib/module/utils/getMostRecentQuantitySample.js +0 -14
  275. package/lib/module/utils/getMostRecentQuantitySample.js.map +0 -1
  276. package/lib/module/utils/getMostRecentWorkout.js +0 -12
  277. package/lib/module/utils/getMostRecentWorkout.js.map +0 -1
  278. package/lib/module/utils/getPreferredUnit.js +0 -7
  279. package/lib/module/utils/getPreferredUnit.js.map +0 -1
  280. package/lib/module/utils/getPreferredUnits.js +0 -7
  281. package/lib/module/utils/getPreferredUnits.js.map +0 -1
  282. package/lib/module/utils/getPreferredUnitsTyped.js +0 -26
  283. package/lib/module/utils/getPreferredUnitsTyped.js.map +0 -1
  284. package/lib/module/utils/getRequestStatusForAuthorization.js +0 -14
  285. package/lib/module/utils/getRequestStatusForAuthorization.js.map +0 -1
  286. package/lib/module/utils/getWorkoutPlanById.js +0 -6
  287. package/lib/module/utils/getWorkoutPlanById.js.map +0 -1
  288. package/lib/module/utils/prepareOptions.js +0 -18
  289. package/lib/module/utils/prepareOptions.js.map +0 -1
  290. package/lib/module/utils/queryCategorySamples.js +0 -10
  291. package/lib/module/utils/queryCategorySamples.js.map +0 -1
  292. package/lib/module/utils/queryCategorySamplesWithAnchor.js +0 -14
  293. package/lib/module/utils/queryCategorySamplesWithAnchor.js.map +0 -1
  294. package/lib/module/utils/queryCorrelationSamples.js +0 -10
  295. package/lib/module/utils/queryCorrelationSamples.js.map +0 -1
  296. package/lib/module/utils/queryHeartbeatSeriesSamples.js +0 -10
  297. package/lib/module/utils/queryHeartbeatSeriesSamples.js.map +0 -1
  298. package/lib/module/utils/queryHeartbeatSeriesSamplesWithAnchor.js +0 -14
  299. package/lib/module/utils/queryHeartbeatSeriesSamplesWithAnchor.js.map +0 -1
  300. package/lib/module/utils/queryQuantitySamples.js +0 -12
  301. package/lib/module/utils/queryQuantitySamples.js.map +0 -1
  302. package/lib/module/utils/queryQuantitySamplesWithAnchor.js +0 -16
  303. package/lib/module/utils/queryQuantitySamplesWithAnchor.js.map +0 -1
  304. package/lib/module/utils/querySources.js +0 -7
  305. package/lib/module/utils/querySources.js.map +0 -1
  306. package/lib/module/utils/queryStateOfMindSamples.js +0 -14
  307. package/lib/module/utils/queryStateOfMindSamples.js.map +0 -1
  308. package/lib/module/utils/queryStatisticsCollectionForQuantity.js +0 -9
  309. package/lib/module/utils/queryStatisticsCollectionForQuantity.js.map +0 -1
  310. package/lib/module/utils/queryStatisticsForQuantity.js +0 -22
  311. package/lib/module/utils/queryStatisticsForQuantity.js.map +0 -1
  312. package/lib/module/utils/queryWorkoutSamplesWithAnchor.js +0 -19
  313. package/lib/module/utils/queryWorkoutSamplesWithAnchor.js.map +0 -1
  314. package/lib/module/utils/queryWorkouts.js +0 -15
  315. package/lib/module/utils/queryWorkouts.js.map +0 -1
  316. package/lib/module/utils/requestAuthorization.js +0 -15
  317. package/lib/module/utils/requestAuthorization.js.map +0 -1
  318. package/lib/module/utils/saveCategorySample.js +0 -13
  319. package/lib/module/utils/saveCategorySample.js.map +0 -1
  320. package/lib/module/utils/saveCorrelationSample.js +0 -28
  321. package/lib/module/utils/saveCorrelationSample.js.map +0 -1
  322. package/lib/module/utils/saveQuantitySample.js +0 -9
  323. package/lib/module/utils/saveQuantitySample.js.map +0 -1
  324. package/lib/module/utils/saveStateOfMindSample.js +0 -10
  325. package/lib/module/utils/saveStateOfMindSample.js.map +0 -1
  326. package/lib/module/utils/saveWorkoutRoute.js +0 -19
  327. package/lib/module/utils/saveWorkoutRoute.js.map +0 -1
  328. package/lib/module/utils/saveWorkoutSample.js +0 -29
  329. package/lib/module/utils/saveWorkoutSample.js.map +0 -1
  330. package/lib/module/utils/serializeDate.js +0 -3
  331. package/lib/module/utils/serializeDate.js.map +0 -1
  332. package/lib/module/utils/serializeDate.test.js +0 -14
  333. package/lib/module/utils/serializeDate.test.js.map +0 -1
  334. package/lib/module/utils/startWatchApp.js +0 -4
  335. package/lib/module/utils/startWatchApp.js.map +0 -1
  336. package/lib/module/utils/subscribeToChanges.js +0 -20
  337. package/lib/module/utils/subscribeToChanges.js.map +0 -1
  338. package/lib/typescript/example-expo/App.d.ts +0 -2
  339. package/lib/typescript/src/hooks/useHealthkitAuthorization.d.ts +0 -8
  340. package/lib/typescript/src/hooks/useHealthkitAuthorization.test.d.ts +0 -1
  341. package/lib/typescript/src/hooks/useIsHealthDataAvailable.d.ts +0 -7
  342. package/lib/typescript/src/hooks/useIsHealthDataAvailable.test.d.ts +0 -1
  343. package/lib/typescript/src/hooks/useMostRecentCategorySample.d.ts +0 -7
  344. package/lib/typescript/src/hooks/useMostRecentQuantitySample.d.ts +0 -7
  345. package/lib/typescript/src/hooks/useMostRecentWorkout.d.ts +0 -10
  346. package/lib/typescript/src/hooks/useSources.d.ts +0 -3
  347. package/lib/typescript/src/hooks/useStatisticsForQuantity.d.ts +0 -4
  348. package/lib/typescript/src/hooks/useSubscribeToChanges.d.ts +0 -3
  349. package/lib/typescript/src/index.d.ts +0 -3
  350. package/lib/typescript/src/index.ios.d.ts +0 -198
  351. package/lib/typescript/src/index.native.d.ts +0 -41
  352. package/lib/typescript/src/index.web.d.ts +0 -3
  353. package/lib/typescript/src/native-types.d.ts +0 -1764
  354. package/lib/typescript/src/test-setup.d.ts +0 -1
  355. package/lib/typescript/src/test-utils.d.ts +0 -2
  356. package/lib/typescript/src/types.d.ts +0 -111
  357. package/lib/typescript/src/utils/deleteQuantitySample.d.ts +0 -4
  358. package/lib/typescript/src/utils/deleteSamples.d.ts +0 -8
  359. package/lib/typescript/src/utils/deleteWorkoutSample.d.ts +0 -3
  360. package/lib/typescript/src/utils/deserializeCategorySample.d.ts +0 -4
  361. package/lib/typescript/src/utils/deserializeCategorySample.test.d.ts +0 -1
  362. package/lib/typescript/src/utils/deserializeCorrelation.d.ts +0 -4
  363. package/lib/typescript/src/utils/deserializeHeartbeatSeriesSample.d.ts +0 -4
  364. package/lib/typescript/src/utils/deserializeSample.d.ts +0 -4
  365. package/lib/typescript/src/utils/deserializeWorkout.d.ts +0 -4
  366. package/lib/typescript/src/utils/ensureMetadata.d.ts +0 -2
  367. package/lib/typescript/src/utils/ensureTotals.d.ts +0 -2
  368. package/lib/typescript/src/utils/ensureUnit.d.ts +0 -3
  369. package/lib/typescript/src/utils/getDateOfBirth.d.ts +0 -2
  370. package/lib/typescript/src/utils/getMostRecentCategorySample.d.ts +0 -4
  371. package/lib/typescript/src/utils/getMostRecentQuantitySample.d.ts +0 -4
  372. package/lib/typescript/src/utils/getMostRecentWorkout.d.ts +0 -5
  373. package/lib/typescript/src/utils/getPreferredUnit.d.ts +0 -4
  374. package/lib/typescript/src/utils/getPreferredUnits.d.ts +0 -4
  375. package/lib/typescript/src/utils/getPreferredUnitsTyped.d.ts +0 -9
  376. package/lib/typescript/src/utils/getRequestStatusForAuthorization.d.ts +0 -3
  377. package/lib/typescript/src/utils/getWorkoutPlanById.d.ts +0 -5
  378. package/lib/typescript/src/utils/prepareOptions.d.ts +0 -9
  379. package/lib/typescript/src/utils/queryCategorySamples.d.ts +0 -5
  380. package/lib/typescript/src/utils/queryCategorySamplesWithAnchor.d.ts +0 -10
  381. package/lib/typescript/src/utils/queryCorrelationSamples.d.ts +0 -5
  382. package/lib/typescript/src/utils/queryHeartbeatSeriesSamples.d.ts +0 -10
  383. package/lib/typescript/src/utils/queryHeartbeatSeriesSamplesWithAnchor.d.ts +0 -10
  384. package/lib/typescript/src/utils/queryQuantitySamples.d.ts +0 -7
  385. package/lib/typescript/src/utils/queryQuantitySamplesWithAnchor.d.ts +0 -12
  386. package/lib/typescript/src/utils/querySources.d.ts +0 -4
  387. package/lib/typescript/src/utils/queryStateOfMindSamples.d.ts +0 -7
  388. package/lib/typescript/src/utils/queryStatisticsCollectionForQuantity.d.ts +0 -3
  389. package/lib/typescript/src/utils/queryStatisticsForQuantity.d.ts +0 -14
  390. package/lib/typescript/src/utils/queryWorkoutSamplesWithAnchor.d.ts +0 -9
  391. package/lib/typescript/src/utils/queryWorkouts.d.ts +0 -4
  392. package/lib/typescript/src/utils/requestAuthorization.d.ts +0 -4
  393. package/lib/typescript/src/utils/saveCategorySample.d.ts +0 -11
  394. package/lib/typescript/src/utils/saveCorrelationSample.d.ts +0 -8
  395. package/lib/typescript/src/utils/saveQuantitySample.d.ts +0 -7
  396. package/lib/typescript/src/utils/saveStateOfMindSample.d.ts +0 -11
  397. package/lib/typescript/src/utils/saveWorkoutRoute.d.ts +0 -3
  398. package/lib/typescript/src/utils/saveWorkoutSample.d.ts +0 -11
  399. package/lib/typescript/src/utils/serializeDate.d.ts +0 -2
  400. package/lib/typescript/src/utils/serializeDate.test.d.ts +0 -1
  401. package/lib/typescript/src/utils/startWatchApp.d.ts +0 -3
  402. package/lib/typescript/src/utils/subscribeToChanges.d.ts +0 -3
  403. package/src/index.ios.tsx +0 -292
  404. package/src/index.native.tsx +0 -233
  405. package/src/index.tsx +0 -5
  406. package/src/index.web.tsx +0 -5
  407. package/src/native-types.ts +0 -2471
  408. package/src/types.ts +0 -156
  409. package/src/utils/deleteQuantitySample.ts +0 -14
  410. package/src/utils/deleteSamples.ts +0 -23
  411. package/src/utils/deleteWorkoutSample.ts +0 -7
  412. package/src/utils/deserializeCategorySample.test.ts +0 -24
  413. package/src/utils/deserializeCategorySample.ts +0 -12
  414. package/src/utils/deserializeCorrelation.ts +0 -28
  415. package/src/utils/deserializeHeartbeatSeriesSample.ts +0 -12
  416. package/src/utils/deserializeSample.ts +0 -17
  417. package/src/utils/deserializeWorkout.ts +0 -14
  418. package/src/utils/ensureMetadata.ts +0 -5
  419. package/src/utils/ensureTotals.ts +0 -5
  420. package/src/utils/ensureUnit.ts +0 -19
  421. package/src/utils/getDateOfBirth.ts +0 -8
  422. package/src/utils/getPreferredUnits.ts +0 -14
  423. package/src/utils/getPreferredUnitsTyped.ts +0 -38
  424. package/src/utils/getRequestStatusForAuthorization.ts +0 -21
  425. package/src/utils/getWorkoutPlanById.ts +0 -7
  426. package/src/utils/prepareOptions.ts +0 -19
  427. package/src/utils/queryCategorySamples.ts +0 -29
  428. package/src/utils/queryCategorySamplesWithAnchor.ts +0 -39
  429. package/src/utils/queryCorrelationSamples.ts +0 -29
  430. package/src/utils/queryHeartbeatSeriesSamples.ts +0 -29
  431. package/src/utils/queryHeartbeatSeriesSamplesWithAnchor.ts +0 -33
  432. package/src/utils/queryQuantitySamples.ts +0 -38
  433. package/src/utils/queryQuantitySamplesWithAnchor.ts +0 -46
  434. package/src/utils/querySources.ts +0 -21
  435. package/src/utils/queryStateOfMindSamples.ts +0 -14
  436. package/src/utils/queryStatisticsCollectionForQuantity.ts +0 -38
  437. package/src/utils/queryStatisticsForQuantity.ts +0 -38
  438. package/src/utils/queryWorkoutSamplesWithAnchor.ts +0 -46
  439. package/src/utils/queryWorkouts.ts +0 -28
  440. package/src/utils/requestAuthorization.ts +0 -19
  441. package/src/utils/saveCategorySample.ts +0 -31
  442. package/src/utils/saveCorrelationSample.ts +0 -43
  443. package/src/utils/saveQuantitySample.ts +0 -29
  444. package/src/utils/saveStateOfMindSample.ts +0 -38
  445. package/src/utils/saveWorkoutRoute.ts +0 -21
  446. package/src/utils/saveWorkoutSample.ts +0 -42
  447. package/src/utils/serializeDate.test.ts +0 -16
  448. package/src/utils/serializeDate.ts +0 -5
  449. package/src/utils/startWatchApp.ts +0 -7
@@ -0,0 +1,282 @@
1
+ import type { AnyMap } from 'react-native-nitro-modules'
2
+ import type { WorkoutProxy } from '../specs/WorkoutProxy.nitro'
3
+ import type { Device } from './Device'
4
+ import type { Quantity } from './QuantityType'
5
+ import type { PredicateForSamples } from './QueryOptions'
6
+ import type { DeletedSample, GenericMetadata } from './Shared'
7
+ import type { SourceRevision } from './Source'
8
+
9
+ export enum WorkoutActivityType {
10
+ americanFootball = 1,
11
+ archery = 2,
12
+ australianFootball = 3,
13
+ badminton = 4,
14
+ baseball = 5,
15
+ basketball = 6,
16
+ bowling = 7,
17
+ boxing = 8, // See also HKWorkoutActivityTypeKickboxing.,
18
+ climbing = 9,
19
+ cricket = 10,
20
+ crossTraining = 11, // Any mix of cardio and/or strength training. See also HKWorkoutActivityTypeCoreTraining and HKWorkoutActivityTypeFlexibility.,
21
+ curling = 12,
22
+ cycling = 13,
23
+ dance = 14,
24
+ danceInspiredTraining = 15, // This enum remains available to access older data.,
25
+ elliptical = 16,
26
+ equestrianSports = 17, // Polo, Horse Racing, Horse Riding, etc.,
27
+ fencing = 18,
28
+ fishing = 19,
29
+ functionalStrengthTraining = 20, // Primarily free weights and/or body weight and/or accessories,
30
+ golf = 21,
31
+ gymnastics = 22,
32
+ handball = 23,
33
+ hiking = 24,
34
+ hockey = 25, // Ice Hockey, Field Hockey, etc.,
35
+ hunting = 26,
36
+ lacrosse = 27,
37
+ martialArts = 28,
38
+ mindAndBody = 29, // Qigong, meditation, etc.,
39
+ mixedMetabolicCardioTraining = 30, // This enum remains available to access older data.,
40
+ paddleSports = 31, // Canoeing, Kayaking, Outrigger, Stand Up Paddle Board, etc.,
41
+ play = 32, // Dodge Ball, Hopscotch, Tetherball, Jungle Gym, etc.,
42
+ preparationAndRecovery = 33, // Foam rolling, stretching, etc.,
43
+ racquetball = 34,
44
+ rowing = 35,
45
+ rugby = 36,
46
+ running = 37,
47
+ sailing = 38,
48
+ skatingSports = 39, // Ice Skating, Speed Skating, Inline Skating, Skateboarding, etc.,
49
+ snowSports = 40, // Sledding, Snowmobiling, Building a Snowman, etc. See also HKWorkoutActivityTypeCrossCountrySkiing, HKWorkoutActivityTypeSnowboarding, and HKWorkoutActivityTypeDownhillSkiing.,
50
+ soccer = 41,
51
+ softball = 42,
52
+ squash = 43,
53
+ stairClimbing = 44, // See also HKWorkoutActivityTypeStairs and HKWorkoutActivityTypeStepTraining.,
54
+ surfingSports = 45, // Traditional Surfing, Kite Surfing, Wind Surfing, etc.,
55
+ swimming = 46,
56
+ tableTennis = 47,
57
+ tennis = 48,
58
+ trackAndField = 49, // Shot Put, Javelin, Pole Vaulting, etc.,
59
+ traditionalStrengthTraining = 50, // Primarily machines and/or free weights,
60
+ volleyball = 51,
61
+ walking = 52,
62
+ waterFitness = 53,
63
+ waterPolo = 54,
64
+ waterSports = 55, // Water Skiing, Wake Boarding, etc.,
65
+ wrestling = 56,
66
+ yoga = 57,
67
+ barre = 58, // HKWorkoutActivityTypeDanceInspiredTraining,
68
+ coreTraining = 59,
69
+ crossCountrySkiing = 60,
70
+ downhillSkiing = 61,
71
+ flexibility = 62,
72
+ highIntensityIntervalTraining = 63,
73
+ jumpRope = 64,
74
+ kickboxing = 65,
75
+ pilates = 66, // HKWorkoutActivityTypeDanceInspiredTraining,
76
+ snowboarding = 67,
77
+ stairs = 68,
78
+ stepTraining = 69,
79
+ wheelchairWalkPace = 70,
80
+ wheelchairRunPace = 71,
81
+ taiChi = 72,
82
+ mixedCardio = 73, // HKWorkoutActivityTypeMixedMetabolicCardioTraining,
83
+ handCycling = 74,
84
+ discSports = 75,
85
+ fitnessGaming = 76,
86
+ cardioDance = 77,
87
+ socialDance = 78,
88
+ pickleball = 79,
89
+ cooldown = 80,
90
+ swimBikeRun = 82,
91
+ transition = 83,
92
+ underwaterDiving = 84,
93
+ other = 3000,
94
+ }
95
+
96
+ // documented at https://developer.apple.com/documentation/healthkit/hkweathercondition
97
+ export enum WeatherCondition {
98
+ none = 0,
99
+ clear = 1,
100
+ fair = 2,
101
+ partlyCloudy = 3,
102
+ mostlyCloudy = 4,
103
+ cloudy = 5,
104
+ foggy = 6,
105
+ haze = 7,
106
+ windy = 8,
107
+ blustery = 9,
108
+ smoky = 10,
109
+ dust = 11,
110
+ snow = 12,
111
+ hail = 13,
112
+ sleet = 14,
113
+ freezingDrizzle = 15,
114
+ freezingRain = 16,
115
+ mixedRainAndHail = 17,
116
+ mixedRainAndSnow = 18,
117
+ mixedRainAndSleet = 19,
118
+ mixedSnowAndSleet = 20,
119
+ drizzle = 21,
120
+ scatteredShowers = 22,
121
+ showers = 23,
122
+ thunderstorms = 24,
123
+ tropicalStorm = 25,
124
+ hurricane = 26,
125
+ tornado = 27,
126
+ }
127
+
128
+ export interface WorkoutMetadata extends GenericMetadata {
129
+ readonly HKWeatherCondition?: WeatherCondition
130
+ readonly HKWeatherHumidity?: Quantity
131
+ readonly HKWeatherTemperature?: Quantity
132
+ readonly HKAverageMETs?: Quantity
133
+ readonly HKElevationAscended?: Quantity
134
+ readonly HKIndoorWorkout?: boolean
135
+ }
136
+
137
+ export interface WorkoutEvent {
138
+ readonly type: WorkoutEventType
139
+ readonly startDate: Date
140
+ readonly endDate: Date
141
+ }
142
+
143
+ export enum WorkoutEventType {
144
+ pause = 1,
145
+ resume = 2,
146
+ lap = 3,
147
+ marker = 4,
148
+ motionPaused = 5,
149
+ motionResumed = 6,
150
+ segment = 7,
151
+ pauseOrResumeRequest = 8,
152
+ }
153
+
154
+ export interface WorkoutActivity {
155
+ readonly startDate: Date
156
+ readonly endDate: Date
157
+ readonly uuid: string
158
+ readonly duration: number
159
+ }
160
+
161
+ export interface WorkoutRoute {
162
+ readonly locations: readonly WorkoutRouteLocation[]
163
+ readonly HKMetadataKeySyncIdentifier?: string
164
+ readonly HKMetadataKeySyncVersion?: number
165
+ }
166
+
167
+ export interface QueryWorkoutSamplesWithAnchorResponse {
168
+ readonly workouts: readonly WorkoutProxy[]
169
+ readonly deletedSamples: readonly DeletedSample[]
170
+ readonly newAnchor: string
171
+ }
172
+
173
+ type WorkoutActivityTypePredicate = {
174
+ readonly workoutActivityType: WorkoutActivityType
175
+ }
176
+
177
+ enum ComparisonPredicateOperator {
178
+ lessThan = 0,
179
+ lessThanOrEqualTo = 1,
180
+ greaterThan = 2,
181
+ greaterThanOrEqualTo = 3,
182
+ equalTo = 4,
183
+ notEqualTo = 5,
184
+ matches = 6,
185
+ like = 7,
186
+ beginsWith = 8,
187
+ endsWith = 9,
188
+ in = 10,
189
+ customSelector = 11,
190
+ contains = 99,
191
+ between = 100,
192
+ }
193
+
194
+ type WorkoutDurationPredicate = {
195
+ readonly predicateOperator: ComparisonPredicateOperator
196
+ readonly durationInSeconds: number
197
+ }
198
+
199
+ export type PredicateForWorkouts =
200
+ | PredicateForSamples
201
+ | WorkoutActivityTypePredicate
202
+ | WorkoutDurationPredicate
203
+
204
+ export type PredicateForWorkoutsOr = {
205
+ readonly OR: readonly PredicateForWorkouts[]
206
+ }
207
+
208
+ export type PredicateForWorkoutsAnd = {
209
+ readonly AND: readonly PredicateForWorkouts[]
210
+ }
211
+
212
+ export type FilterForWorkouts =
213
+ | PredicateForWorkouts
214
+ | PredicateForWorkoutsOr
215
+ | PredicateForWorkoutsAnd
216
+
217
+ export interface WorkoutQueryOptionsWithAnchor {
218
+ energyUnit?: string
219
+ distanceUnit?: string
220
+ filter?: FilterForWorkouts
221
+ limit?: number
222
+ anchor?: string
223
+ }
224
+
225
+ export interface WorkoutQueryOptions {
226
+ energyUnit?: string
227
+ distanceUnit?: string
228
+ filter?: FilterForWorkouts
229
+ limit?: number
230
+ ascending?: boolean
231
+ }
232
+
233
+ export interface WorkoutRouteLocation {
234
+ readonly altitude: number
235
+ readonly course: number
236
+ readonly date: Date
237
+ readonly distance: number | null
238
+ readonly horizontalAccuracy: number
239
+ readonly latitude: number
240
+ readonly longitude: number
241
+ readonly speed: number
242
+ readonly speedAccuracy: number
243
+ readonly verticalAccuracy: number
244
+ }
245
+
246
+ export interface LocationForSaving {
247
+ readonly altitude: number
248
+ readonly course: number
249
+ readonly date: Date // unix timestamp in milliseconds
250
+ readonly horizontalAccuracy: number
251
+ readonly latitude: number
252
+ readonly longitude: number
253
+ readonly speed: number
254
+ readonly verticalAccuracy: number
255
+ }
256
+
257
+ export interface WorkoutPlan {
258
+ readonly id: string
259
+ readonly activityType: WorkoutActivityType
260
+ }
261
+
262
+ export interface WorkoutTotals {
263
+ readonly distance?: number
264
+ readonly energyBurned?: number
265
+ }
266
+
267
+ export interface WorkoutSample {
268
+ readonly uuid: string
269
+ readonly device?: Device
270
+ readonly workoutActivityType: WorkoutActivityType
271
+ readonly duration: Quantity
272
+ readonly totalDistance?: Quantity
273
+ readonly totalEnergyBurned?: Quantity
274
+ readonly totalSwimmingStrokeCount?: Quantity
275
+ readonly totalFlightsClimbed?: Quantity
276
+ readonly startDate: Date
277
+ readonly endDate: Date
278
+ readonly metadata?: AnyMap
279
+ readonly sourceRevision?: SourceRevision
280
+ readonly events?: readonly WorkoutEvent[]
281
+ readonly activities?: readonly WorkoutActivity[]
282
+ }
@@ -1,19 +1,15 @@
1
- import queryCategorySamples from './queryCategorySamples'
1
+ import { CategoryTypes } from '../modules'
2
+ import type { CategoryTypeIdentifier } from '../types/CategoryTypeIdentifier'
2
3
 
3
- import type { HKCategoryTypeIdentifier } from '../native-types'
4
- import type { HKCategorySample } from '../types'
5
-
6
- async function getMostRecentCategorySample<
7
- T extends HKCategoryTypeIdentifier
8
- >(
9
- identifier: T,
10
- ): Promise<HKCategorySample<T> | null> {
11
- const samples = await queryCategorySamples(identifier, {
4
+ export async function getMostRecentCategorySample<
5
+ T extends CategoryTypeIdentifier,
6
+ >(identifier: T) {
7
+ const samples = await CategoryTypes.queryCategorySamples(identifier, {
12
8
  limit: 1,
13
9
  ascending: false,
14
10
  })
15
11
 
16
- return samples[0] ?? null
12
+ return samples[0]
17
13
  }
18
14
 
19
15
  export default getMostRecentCategorySample
@@ -1,26 +1,16 @@
1
- import queryQuantitySamples from './queryQuantitySamples'
1
+ import { QuantityTypes } from '../modules'
2
+ import type { QuantityTypeIdentifier } from '../types/QuantityTypeIdentifier'
2
3
 
3
- import type { HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types'
4
- import type { HKQuantitySample } from '../types'
5
-
6
- async function getMostRecentQuantitySample<
7
- TIdentifier extends HKQuantityTypeIdentifier,
8
- TUnit extends UnitForIdentifier<TIdentifier>
9
- >(
10
- identifier: TIdentifier,
11
- unit: TUnit,
12
- ): Promise<HKQuantitySample<TIdentifier, TUnit> | null> {
13
- const samples = await queryQuantitySamples(identifier, {
4
+ async function getMostRecentQuantitySample(
5
+ identifier: QuantityTypeIdentifier,
6
+ unit?: string,
7
+ ) {
8
+ const samples = await QuantityTypes.queryQuantitySamples(identifier, {
14
9
  limit: 1,
15
10
  unit,
16
11
  })
17
12
 
18
- const lastSample = samples[0]
19
-
20
- if (lastSample) {
21
- return lastSample as HKQuantitySample<TIdentifier, TUnit>
22
- }
23
- return null
13
+ return samples[0]
24
14
  }
25
15
 
26
16
  export default getMostRecentQuantitySample
@@ -1,27 +1,17 @@
1
- import queryWorkouts from './queryWorkouts'
1
+ import { Workouts } from '../modules'
2
+ import type { WorkoutQueryOptions } from '../types/Workouts'
2
3
 
3
- import type { EnergyUnit, LengthUnit } from '../native-types'
4
- import type { HKWorkout, QueryWorkoutsOptions } from '../types'
5
-
6
- export type GetMostRecentWorkoutFn = <
7
- TEnergy extends EnergyUnit,
8
- TDistance extends LengthUnit
9
- >(
10
- options?: Pick<
11
- QueryWorkoutsOptions<TEnergy, TDistance>,
12
- 'distanceUnit' | 'energyUnit'
13
- >
14
- ) => Promise<HKWorkout<TEnergy, TDistance> | null>;
15
-
16
- const getMostRecentWorkout: GetMostRecentWorkoutFn = async (options) => {
17
- const workouts = await queryWorkouts({
4
+ const getMostRecentWorkout = async (
5
+ options: Pick<WorkoutQueryOptions, 'distanceUnit' | 'energyUnit'>,
6
+ ) => {
7
+ const workouts = await Workouts.queryWorkoutSamples({
18
8
  limit: 1,
19
9
  ascending: false,
20
10
  energyUnit: options?.energyUnit,
21
11
  distanceUnit: options?.distanceUnit,
22
12
  })
23
13
 
24
- return workouts[0] || null
14
+ return workouts[0]
25
15
  }
26
16
 
27
17
  export default getMostRecentWorkout
@@ -1,14 +1,18 @@
1
- import getPreferredUnits from './getPreferredUnits'
1
+ import { Core } from '../modules'
2
+ import type { QuantityTypeIdentifier } from '../types/QuantityTypeIdentifier'
2
3
 
3
- import type { HKQuantityTypeIdentifier, HKUnit } from '../native-types'
4
+ const getPreferredUnit = async (
5
+ quantityType: QuantityTypeIdentifier,
6
+ ): Promise<string> => {
7
+ const units = await Core.getPreferredUnits([quantityType])
8
+ const unit = units[0]?.unit
4
9
 
5
- export type GetPreferredUnitFn = (
6
- identifier: HKQuantityTypeIdentifier
7
- ) => Promise<HKUnit | undefined>;
10
+ if (!unit) {
11
+ throw new Error(
12
+ `No preferred unit found for quantity type: ${quantityType}`,
13
+ )
14
+ }
8
15
 
9
- const getPreferredUnit: GetPreferredUnitFn = async (type) => {
10
- const [unit] = await getPreferredUnits([type])
11
16
  return unit
12
17
  }
13
-
14
18
  export default getPreferredUnit
@@ -1,31 +1,14 @@
1
- import Native, { EventEmitter } from '../native-types'
1
+ import { Core } from '../modules'
2
+ import type { SampleTypeIdentifier } from '../types/Shared'
3
+ import type { OnChangeCallbackArgs } from '../types/Subscriptons'
2
4
 
3
- import type { HKSampleTypeIdentifier } from '..'
4
-
5
- const subscribeToChanges = async (
6
- identifier: HKSampleTypeIdentifier,
7
- callback: () => void,
5
+ export const subscribeToChanges = (
6
+ identifier: SampleTypeIdentifier,
7
+ callback: (args: OnChangeCallbackArgs) => void,
8
8
  ) => {
9
- const subscription = EventEmitter.addListener(
10
- 'onChange',
11
- ({ typeIdentifier }: { readonly typeIdentifier: HKSampleTypeIdentifier }) => {
12
- if (typeIdentifier === identifier) {
13
- callback()
14
- }
15
- },
16
- )
17
-
18
- const queryId = await Native.subscribeToObserverQuery(identifier).catch(
19
- async (error) => {
20
- subscription.remove()
21
- return Promise.reject(error)
22
- },
23
- )
9
+ const queryId = Core.subscribeToObserverQuery(identifier, callback)
24
10
 
25
- return async () => {
26
- subscription.remove()
27
- return Native.unsubscribeQuery(queryId)
11
+ return {
12
+ remove: () => Core.unsubscribeQuery(queryId),
28
13
  }
29
14
  }
30
-
31
- export default subscribeToChanges
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 Robert Herber
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/README.md DELETED
@@ -1,179 +0,0 @@
1
- # @kingstinct/react-native-healthkit
2
-
3
- [![Test Status](https://github.com/Kingstinct/react-native-healthkit/actions/workflows/test.yml/badge.svg)](https://github.com/Kingstinct/react-native-healthkit/actions/workflows/test.yml)
4
- [![Latest version on NPM](https://img.shields.io/npm/v/@kingstinct/react-native-healthkit)](https://www.npmjs.com/package/@kingstinct/react-native-healthkit)
5
- [![Downloads on NPM](https://img.shields.io/npm/dt/@kingstinct/react-native-healthkit)](https://www.npmjs.com/package/@kingstinct/react-native-healthkit)
6
- [![Discord](https://dcbadge.vercel.app/api/server/hrgnETpsJA?style=flat)](https://discord.gg/hrgnETpsJA)
7
-
8
-
9
- React Native bindings for HealthKit with full TypeScript and Promise support covering about any kind of data. Keeping TypeScript mappings as close as possible to HealthKit - both in regards to naming and serialization. This will make it easier to keep this library up-to-date with HealthKit as well as browsing [the official documentation](https://developer.apple.com/documentation/healthkit) (and if something - metadata properties for example - is not typed it will still be accessible).
10
-
11
- | Data Types | Query | Save | Subscribe | Examples |
12
- | ----------------------------|:------|:------|:----------|:---------------------------------------|
13
- | 100+ Quantity Types | ✅ | ✅ | ✅ | Steps, energy burnt, blood glucose etc.. |
14
- | 63 Category Types | ✅ | ✅ | ✅ | Sleep analysis, mindful sessions etc.. |
15
- | 75+ Workout Activity Types | ✅ | ✅ | ✅ | Swimming, running, table tennis etc.. |
16
- | Correlation Types | ✅ | ✅ | ✅ | Food and blood pressure |
17
- | Document Types | ✅ | ❌ | ✅ | [CDA documents](https://developer.apple.com/documentation/healthkit/hkcdadocument) exposed as Base64 data |
18
- | Clinical Records | ⚠️ | ❌ | ⚠️ | Lab results etc in [FHIR JSON format](https://www.hl7.org/fhir/json.html) (see [Clinical Records](https://github.com/kingstinct/react-native-healthkit#clinical-records)) |
19
-
20
- ### Disclaimer
21
-
22
- This library is provided as-is without any warranty and is not affiliated with Apple in any way. The data might be incomplete or inaccurate.
23
-
24
- ## Installation
25
-
26
- ### Expo
27
- Usage with Expo is possible - just keep in mind it will not work in Expo Go and [you'll need to roll your own Dev Client](https://docs.expo.dev/development/getting-started/).
28
-
29
- 1. `yarn add @kingstinct/react-native-healthkit`
30
- 2. Update your app.json with the config plugin:
31
- ```json
32
- {
33
- "expo": {
34
- "plugins": ["@kingstinct/react-native-healthkit"]
35
- }
36
- }
37
- ```
38
- this will give you defaults that make the app build without any further configuration. If you want, you can override the defaults:
39
- ```json
40
- {
41
- "expo": {
42
- "plugins": [
43
- ["@kingstinct/react-native-healthkit", {
44
- "NSHealthShareUsageDescription": "Your own custom usage description",
45
- "NSHealthUpdateUsageDescription": false, // if you have no plans to update data, you could skip adding it to your info.plist
46
- "background": false // if you have no plans to use it in background mode, you could skip adding it to the entitlements
47
- }]
48
- ]
49
- }
50
- }
51
- ```
52
- 3. Build a new Dev Client
53
-
54
- ### Native or Expo Bare Workflow
55
- 1. `yarn add @kingstinct/react-native-healthkit`
56
- 2. `npx pod-install`
57
- 3. Set `NSHealthUpdateUsageDescription` and `NSHealthShareUsageDescription` in your `Info.plist`
58
- 4. Enable the HealthKit capability for the project in Xcode.
59
- 5. Since this package is using Swift you might also need to add a bridging header in your project if you haven't already, you can [find more about that in the official React Native docs](https://reactnative.dev/docs/native-modules-ios#exporting-swift)
60
-
61
- ## Usage
62
-
63
- During runtime check and request permissions with `requestAuthorization`. Failing to request authorization, or requesting a permission you haven't requested yet, will result in the app crashing. This is easy to miss - for example by requesting authorization in the same component where you have a hook trying to fetch data right away.. :)
64
-
65
- Some hook examples:
66
- ```TypeScript
67
- import { HKQuantityTypeIdentifier, useHealthkitAuthorization } from '@kingstinct/react-native-healthkit';
68
-
69
- const [authorizationStatus, requestAuthorization] = useHealthkitAuthorization([HKQuantityTypeIdentifier.bloodGlucose])
70
-
71
- // make sure that you've requested authorization before requesting data, otherwise your app will crash
72
- import { useMostRecentQuantitySample, HKQuantityTypeIdentifier, useMostRecentCategorySample } from '@kingstinct/react-native-healthkit';
73
-
74
- const mostRecentBloodGlucoseSample = useMostRecentQuantitySample(HKQuantityTypeIdentifier.bloodGlucose)
75
- const lastBodyFatSample = useMostRecentQuantitySample(HKQuantityTypeIdentifier.bodyFatPercentage)
76
- const lastMindfulSession = useMostRecentCategorySample(HKCategoryTypeIdentifier.mindfulSession)
77
- const lastWorkout = useMostRecentWorkout()
78
- ```
79
-
80
- Some imperative examples:
81
- ```TypeScript
82
- import HealthKit, { HKUnit, HKQuantityTypeIdentifier, HKInsulinDeliveryReason, HKCategoryTypeIdentifier } from '@kingstinct/react-native-healthkit';
83
-
84
- const isAvailable = await HealthKit.isHealthDataAvailable();
85
-
86
- /* Read latest sample of any data */
87
- await HealthKit.requestAuthorization([HKQuantityTypeIdentifier.bodyFatPercentage]); // request read permission for bodyFatPercentage
88
-
89
- const { quantity, unit, startDate, endDate } = await HealthKit.getMostRecentQuantitySample(HKQuantityTypeIdentifier.bodyFatPercentage); // read latest sample
90
-
91
- console.log(quantity) // 17.5
92
- console.log(unit) // %
93
-
94
- await HealthKit.requestAuthorization([HKQuantityTypeIdentifier.heartRate]); // request read permission for heart rate
95
-
96
- /* Subscribe to data (Make sure to request permissions before subscribing to changes) */
97
- const [hasRequestedAuthorization, setHasRequestedAuthorization] = useState(false);
98
-
99
- useEffect(() => {
100
- HealthKit.requestAuthorization([HKQuantityTypeIdentifier.heartRate]).then(() => {
101
- setHasRequestedAuthorization(true);
102
- });
103
- }, []);
104
-
105
- useEffect(() => {
106
- if (hasRequestedAuthorization) {
107
- const unsubscribe = HealthKit.subscribeToChanges(HKQuantityTypeIdentifier.heartRate, () => {
108
- // refetch data as needed
109
- });
110
- }
111
-
112
- return () => unsubscribe();
113
- }, [hasRequestedAuthorization]);
114
-
115
- /* write data */
116
- await HealthKit.requestAuthorization([], [HKQuantityTypeIdentifier.insulinDelivery]); // request write permission for insulin delivery
117
-
118
- ReactNativeHealthkit.saveQuantitySample(
119
- HKQuantityTypeIdentifier.insulinDelivery,
120
- HKUnit.InternationalUnit,
121
- 5.5,
122
- {
123
- metadata: {
124
- // Metadata keys could be arbirtary string to store app-specific data.
125
- // To use built-in types from https://developer.apple.com/documentation/healthkit/samples/metadata_keys
126
- // you need to specify string values instead of variable names (by dropping MetadataKey from the name).
127
- HKInsulinDeliveryReason: HKInsulinDeliveryReason.basal,
128
- },
129
- }
130
- );
131
- ```
132
-
133
- ### HealthKit Anchors (breaking change in 6.0)
134
- In 6.0 you can use HealthKit anchors to get changes and deleted items which is very useful for syncing. This is a breaking change - but a very easy one to handle that TypeScript should help you with. Most queries now return an object containing samples which is what was returned as only an array before.
135
-
136
- ```newAnchor``` is a base64-encoded string returned from HealthKit that contain sync information. After each successful sync, store the anchor for the next time your anchor query is called to only return the values that have changed.
137
-
138
- ```limit``` will indicate how many records to consider when sycning data, you can set this value to 0 indicate no limit.
139
-
140
- Example:
141
-
142
- ```TypeScript
143
- const { newAnchor, samples, deletedSamples } = await queryQuantitySamplesWithAnchor(HKQuantityTypeIdentifier.stepCount, {
144
- limit: 2,
145
- })
146
-
147
- const nextResult = await queryQuantitySamplesWithAnchor(HKQuantityTypeIdentifier.stepCount, {
148
- limit: 2,
149
- anchor: newAnchor,
150
- })
151
-
152
- // etc..
153
- ```
154
-
155
- ## A note on Apple Documentation
156
-
157
- We're striving to do as straight a mapping as possible to the Native Libraries. This means that in most cases the Apple Documentation makes sense. However, when it comes to the Healthkit [Metadata Keys](https://developer.apple.com/documentation/healthkit/samples/metadata_keys) the documentation doesn't actually reflect the serialized values. For example HKMetadataKeyExternalUUID in the documentation serializes to HKExternalUUID - which is what we use.
158
-
159
- ## Clinical Records
160
-
161
- For accessing Clinical Records use old version (3.x) or use specific branch "including-clinical-records". The reason is we cannot refer to this code natively in apps without getting approval from Apple, this could probably be solved by the config plugin but we haven't had time to look into it yet.
162
-
163
- ## Android alternatives
164
-
165
- For a similar library for Android, check out [react-native-health-connect](https://github.com/matinzd/react-native-health-connect/) that works with the new Health Connect. For Google Fit [react-native-google-fit](https://www.npmjs.com/package/react-native-google-fit) seems to be the most popular option, and and another possible option is to work directly with the Google Fit REST API which I've some experience with.
166
-
167
- ## Contributing
168
-
169
- See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
170
-
171
- ## Sponsorship and enterprise-grade support
172
-
173
- If you're using @kingstinct/react-native-healthkit to build your production app [please consider funding its continued development](https://github.com/sponsors/Kingstinct). It helps us spend more time on keeping this library as good as it can be.
174
-
175
- At Kingstinct we're also able to provide enterprise-grade support for this package, [find us here](https://kingstinct.com) or [drop an email](mailto:healthkit@kingstinct.com) for more information. Also feel free to join our [Discord community](https://discord.gg/EHScS93v).
176
-
177
- ## License
178
-
179
- MIT
@@ -1,2 +0,0 @@
1
- #import <React/RCTBridgeModule.h>
2
- #import <React/RCTEventEmitter.h>