@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
package/ios/Helpers.swift CHANGED
@@ -7,142 +7,392 @@
7
7
 
8
8
  import Foundation
9
9
  import HealthKit
10
+ import NitroModules
10
11
 
11
- func dateOrNilIfZero(date: Date) -> Date? {
12
- return date.timeIntervalSince1970 > 0 ? date : nil
12
+ func dateOrNilIfZero(_ timestamp: Double?) -> Date? {
13
+ if let timestamp = timestamp {
14
+ if(timestamp == 0){
15
+ return nil
16
+ }
17
+ return Date.init(timeIntervalSince1970: timestamp)
18
+ }
19
+ return nil
20
+
21
+
13
22
  }
14
23
 
15
- func limitOrNilIfZero(limit: Int) -> Int {
16
- return limit == 0 ? HKObjectQueryNoLimit : limit
24
+ func getQueryLimit(_ limit: Double?) -> Int {
25
+ if let limit = limit {
26
+ if(limit == .infinity || limit <= 0){
27
+ return HKObjectQueryNoLimit
28
+ }
29
+
30
+ return Int(limit)
31
+ }
32
+
33
+ return DEFAULT_QUERY_LIMIT
17
34
  }
18
35
 
19
- func createPredicate(from: Date?, to: Date?) -> NSPredicate? {
20
- if from != nil || to != nil {
21
- return HKQuery.predicateForSamples(
22
- withStart: from, end: to, options: [.strictEndDate, .strictStartDate])
23
- } else {
24
- return nil
36
+ func createPredicateForWorkout(filter: PredicateForWorkouts) throws -> NSPredicate {
37
+ switch filter {
38
+ case .first(let uuidWrapper):
39
+ return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
40
+ case .second(let uuidsWrapper):
41
+ return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
42
+ case .third(let metadataKey):
43
+ return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
44
+ case .fourth(let dateFilter):
45
+ return createDatePredicate(dateFilter: dateFilter)
46
+ case .fifth(let w):
47
+ if let w = w.workout as? WorkoutProxy {
48
+ return HKQuery.predicateForObjects(from: w.workout)
49
+ }
50
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
51
+ case .sixth(let activityType):
52
+ if let activityType = HKWorkoutActivityType.init(rawValue: UInt(activityType.workoutActivityType.rawValue)) {
53
+ return HKQuery.predicateForWorkouts(with: activityType)
54
+ } else {
55
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized workoutActivityType with identifier \(activityType.workoutActivityType.rawValue)")
56
+ }
57
+ case .seventh(let durationPredicate):
58
+ if let op = NSComparisonPredicate.Operator(rawValue: UInt(durationPredicate.predicateOperator.rawValue)){
59
+ return HKQuery.predicateForWorkouts(with: op, duration: durationPredicate.durationInSeconds)
60
+ }
61
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized workout duration predicate operator \(durationPredicate.predicateOperator.rawValue)")
62
+ }
63
+ }
64
+
65
+ func createPredicateForWorkout(filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_WorkoutActivityTypePredicate_WorkoutDurationPredicate_PredicateForWorkoutsOr_PredicateForWorkoutsAnd?) throws -> NSPredicate? {
66
+ if let filter = filter {
67
+ switch filter {
68
+ case .first(let uuidWrapper):
69
+ return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
70
+ case .second(let uuidsWrapper):
71
+ return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
72
+ case .third(let metadataKey):
73
+ return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
74
+ case .fourth(let dateFilter):
75
+ return createDatePredicate(dateFilter: dateFilter)
76
+ case .fifth(let w):
77
+ if let w = w.workout as? WorkoutProxy {
78
+ return HKQuery.predicateForObjects(from: w.workout)
79
+ }
80
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
81
+ case .sixth(let activityType):
82
+ if let activityType = HKWorkoutActivityType.init(rawValue: UInt(activityType.workoutActivityType.rawValue)) {
83
+ return HKQuery.predicateForWorkouts(with: activityType)
84
+ } else {
85
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized workoutActivityType with identifier \(activityType.workoutActivityType.rawValue)")
86
+ }
87
+ case .seventh(let durationPredicate):
88
+ if let op = NSComparisonPredicate.Operator(rawValue: UInt(durationPredicate.predicateOperator.rawValue)){
89
+ return HKQuery.predicateForWorkouts(with: op, duration: durationPredicate.durationInSeconds)
90
+ }
91
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized workout duration predicate operator \(durationPredicate.predicateOperator.rawValue)")
92
+
93
+ case .eigth(let or):
94
+ return NSCompoundPredicate.init(andPredicateWithSubpredicates: try or.OR.map { predicate in
95
+ return try createPredicateForWorkout(filter: predicate)
96
+ })
97
+ case .ninth(let and):
98
+ return NSCompoundPredicate.init(orPredicateWithSubpredicates: try and.AND
99
+ .map { predicate in
100
+ return try createPredicateForWorkout(filter: predicate)
101
+ })
102
+ }
25
103
  }
104
+
105
+ return nil
26
106
  }
27
107
 
28
- func getSortDescriptors(ascending: Bool) -> [NSSortDescriptor] {
29
- return [NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: ascending)]
108
+ func createDatePredicate(dateFilter: PredicateWithStartAndEnd) -> NSPredicate {
109
+ let strictStartDate = dateFilter.strictStartDate ?? false
110
+ let strictEndDate = dateFilter.strictEndDate ?? false
111
+
112
+ let options: HKQueryOptions = strictStartDate && strictEndDate
113
+ ? [.strictStartDate, .strictEndDate]
114
+ : strictEndDate
115
+ ? .strictEndDate
116
+ : strictStartDate
117
+ ? .strictStartDate
118
+ : []
119
+
120
+ return HKQuery.predicateForSamples(
121
+ withStart: dateFilter.startDate,
122
+ end: dateFilter.endDate,
123
+ options: options
124
+ )
30
125
  }
31
126
 
32
- func base64StringToHKQueryAnchor(base64String: String) -> HKQueryAnchor? {
33
- // Step 1: Decode the base64 string to a Data object
34
- guard let data = Data(base64Encoded: base64String) else {
35
- print("Error: Invalid base64 string")
36
- return nil
127
+ func createUUIDsPredicate(uuidsWrapper: PredicateWithUUIDs) -> NSPredicate {
128
+ let uuids = uuidsWrapper.uuids.compactMap { uuidStr -> UUID? in
129
+ do {
130
+ let uuid = try initializeUUID(uuidStr)
131
+ return uuid
132
+ }
133
+ catch {
134
+ print(error.localizedDescription)
135
+ return nil
136
+ }
37
137
  }
138
+ return HKQuery.predicateForObjects(with: Set(uuids))
139
+ }
38
140
 
39
- // Step 2: Use NSKeyedUnarchiver to unarchive the data and create an HKQueryAnchor object
40
- do {
41
- let unarchiver = try NSKeyedUnarchiver(forReadingFrom: data)
42
- unarchiver.requiresSecureCoding = true
43
- let anchor = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data)
141
+ func createPredicate(filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout?) throws -> NSPredicate? {
142
+ if let filter = filter {
143
+ switch filter {
144
+ case .first(let uuidWrapper):
145
+ return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
146
+ case .second(let uuidsWrapper):
147
+ return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
148
+ case .third(let metadataKey):
149
+ return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
150
+ case .fourth(let dateFilter):
151
+ return createDatePredicate(dateFilter: dateFilter)
152
+ case .fifth(let w):
153
+ if let w = w.workout as? WorkoutProxy {
154
+ return HKQuery.predicateForObjects(from: w.workout)
155
+ }
156
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
157
+ }
158
+ }
159
+ return nil
160
+ }
44
161
 
45
- return anchor as? HKQueryAnchor
46
- } catch {
47
- print("Error: Unable to unarchive HKQueryAnchor object: \(error)")
48
- return nil
162
+ func createPredicate(filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_FilterForSamplesAnd_FilterForSamplesOr?) throws -> NSPredicate? {
163
+ if let filter = filter {
164
+ switch filter {
165
+ case .first(let uuidWrapper):
166
+ return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
167
+ case .second(let uuidsWrapper):
168
+ return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
169
+ case .third(let metadataKey):
170
+ return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
171
+ case .fourth(let dateFilter):
172
+ return createDatePredicate(dateFilter: dateFilter)
173
+ case .fifth(let w):
174
+ if let w = w.workout as? WorkoutProxy {
175
+ return HKQuery.predicateForObjects(from: w.workout)
176
+ }
177
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
178
+ case .sixth(let and):
179
+ return NSCompoundPredicate.init(andPredicateWithSubpredicates: try and.AND.map { predicate in
180
+ return try createPredicateForSamples(filter: predicate)
181
+ })
182
+ case .seventh(let or):
183
+ return NSCompoundPredicate.init(orPredicateWithSubpredicates: try or.OR
184
+ .map { predicate in
185
+ return try createPredicateForSamples(filter: predicate)
186
+ })
187
+ }
49
188
  }
189
+ return nil
50
190
  }
51
191
 
52
- func sampleTypeFromString(typeIdentifier: String) -> HKSampleType? {
53
- if typeIdentifier.starts(with: HKQuantityTypeIdentifier_PREFIX) {
54
- let identifier = HKQuantityTypeIdentifier.init(rawValue: typeIdentifier)
55
- return HKSampleType.quantityType(forIdentifier: identifier) as HKSampleType?
192
+ func createPredicateForSamples(filter: PredicateForSamples) throws -> NSPredicate {
193
+ switch filter {
194
+ case .first(let uuidWrapper):
195
+ return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
196
+ case .second(let uuidsWrapper):
197
+ return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
198
+ case .third(let metadataKey):
199
+ return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
200
+ case .fourth(let dateFilter):
201
+ return createDatePredicate(dateFilter: dateFilter)
202
+ case .fifth(let w):
203
+ if let w = w.workout as? WorkoutProxy {
204
+ return HKQuery.predicateForObjects(from: w.workout)
205
+ }
206
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
56
207
  }
208
+ }
57
209
 
58
- if typeIdentifier.starts(with: HKCategoryTypeIdentifier_PREFIX) {
59
- let identifier = HKCategoryTypeIdentifier.init(rawValue: typeIdentifier)
60
- return HKSampleType.categoryType(forIdentifier: identifier) as HKSampleType?
210
+ func createPredicateForSamples(filter: FilterForSamples) throws -> NSPredicate {
211
+ switch filter {
212
+ case .first(let uuidWrapper):
213
+ return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
214
+ case .second(let uuidsWrapper):
215
+ return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
216
+ case .third(let metadataKey):
217
+ return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
218
+ case .fourth(let dateFilter):
219
+ return createDatePredicate(dateFilter: dateFilter)
220
+ case .fifth(let w):
221
+ if let w = w.workout as? WorkoutProxy {
222
+ return HKQuery.predicateForObjects(from: w.workout)
223
+ }
224
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
225
+ case .sixth(let and):
226
+ return NSCompoundPredicate.init(andPredicateWithSubpredicates: try and.AND.map { predicate in
227
+ return try createPredicateForSamples(filter: predicate)
228
+ })
229
+ case .seventh(let or):
230
+ return NSCompoundPredicate.init(orPredicateWithSubpredicates: try or.OR
231
+ .map { predicate in
232
+ return try createPredicateForSamples(filter: predicate)
233
+ })
61
234
  }
235
+ }
62
236
 
63
- if typeIdentifier.starts(with: HKCorrelationTypeIdentifier_PREFIX) {
64
- let identifier = HKCorrelationTypeIdentifier.init(rawValue: typeIdentifier)
65
- return HKSampleType.correlationType(forIdentifier: identifier) as HKSampleType?
237
+ func createPredicateForSamples(filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_FilterForSamplesAnd_FilterForSamplesOr) throws -> NSPredicate {
238
+ switch filter {
239
+ case .first(let uuidWrapper):
240
+ return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
241
+ case .second(let uuidsWrapper):
242
+ return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
243
+ case .third(let metadataKey):
244
+ return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
245
+ case .fourth(let dateFilter):
246
+ return createDatePredicate(dateFilter: dateFilter)
247
+ case .fifth(let w):
248
+ if let w = w.workout as? WorkoutProxy {
249
+ return HKQuery.predicateForObjects(from: w.workout)
250
+ }
251
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
252
+ case .sixth(let and):
253
+ return NSCompoundPredicate.init(andPredicateWithSubpredicates: try and.AND.map { predicate in
254
+ return try createPredicateForSamples(filter: predicate)
255
+ })
256
+ case .seventh(let or):
257
+ return NSCompoundPredicate.init(orPredicateWithSubpredicates: try or.OR
258
+ .map { predicate in
259
+ return try createPredicateForSamples(filter: predicate)
260
+ })
66
261
  }
262
+ }
67
263
 
68
- if #available(iOS 13, *) {
69
- if typeIdentifier == HKAudiogramTypeIdentifier {
70
- return HKSampleType.audiogramSampleType()
264
+ func getSortDescriptors(ascending: Bool?) -> [NSSortDescriptor] {
265
+ return [NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: ascending ?? false)]
266
+ }
267
+
268
+ func getSortDescsdsdriptors(ascending: Bool?) -> [NSSortDescriptor] {
269
+ return [NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: ascending ?? false)]
270
+ }
271
+
272
+ func deserializeHKQueryAnchor(base64String: String?) throws -> HKQueryAnchor? {
273
+ if let base64String = base64String {
274
+ if base64String.isEmpty {
275
+ return nil
276
+ }
277
+
278
+ // Step 1: Decode the base64 string to a Data object
279
+ guard let data = Data(base64Encoded: base64String) else {
280
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Invalid base64 string: \(base64String)")
71
281
  }
72
- }
73
282
 
74
- #if compiler(>=6)
75
- if #available(iOS 18, *) {
76
- if typeIdentifier == HKStateOfMindTypeIdentifier {
77
- return HKObjectType.stateOfMindType()
78
- }
283
+ // Step 2: Use NSKeyedUnarchiver to unarchive the data and create an HKQueryAnchor object
284
+ do {
285
+ let unarchiver = try NSKeyedUnarchiver(forReadingFrom: data)
286
+ unarchiver.requiresSecureCoding = true
287
+ let anchor = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data)
288
+
289
+ return anchor as? HKQueryAnchor
290
+ } catch {
291
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Error recreating HKQueryAnchor object: \(error.localizedDescription)")
79
292
  }
80
- #endif
293
+ }
294
+ return nil
295
+ }
81
296
 
82
- if typeIdentifier == HKWorkoutTypeIdentifier {
83
- return HKSampleType.workoutType()
297
+
298
+ func initializeCategoryType(_ identifier: String) throws -> HKCategoryType {
299
+ let identifier = HKCategoryTypeIdentifier(rawValue: identifier)
300
+ if let sampleType = HKSampleType.categoryType(forIdentifier: identifier) {
301
+ return sampleType
84
302
  }
303
+
304
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized categoryType with identifier \(identifier)")
305
+ }
85
306
 
86
- if #available(iOS 11.0, *) {
87
- if typeIdentifier == HKWorkoutRouteTypeIdentifier {
88
- return HKObjectType.seriesType(forIdentifier: typeIdentifier)
89
- }
307
+ func initializeWorkoutActivityType(_ typeIdentifier: UInt) throws -> HKWorkoutActivityType {
308
+ if let type = HKWorkoutActivityType.init(rawValue: typeIdentifier) {
309
+ return type
90
310
  }
311
+
312
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized quantityType with identifier \(typeIdentifier)")
313
+ }
91
314
 
92
- return nil
315
+ func initializeQuantityType(_ identifier: String) throws -> HKQuantityType {
316
+ let identifier = HKQuantityTypeIdentifier(rawValue: identifier)
317
+
318
+ if let sampleType = HKSampleType.quantityType(forIdentifier: identifier) {
319
+ return sampleType
320
+ }
321
+
322
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized quantityType with identifier \(identifier)")
93
323
  }
94
324
 
95
- func objectTypesFromDictionary(typeIdentifiers: NSDictionary) -> Set<HKObjectType> {
96
- var share = Set<HKObjectType>()
97
- for item in typeIdentifiers {
98
- if item.value as! Bool {
99
- let objectType = objectTypeFromString(typeIdentifier: item.key as! String)
100
- if objectType != nil {
101
- share.insert(objectType!)
102
- }
103
- }
325
+ func initializeCorrelationType(_ identifier: String) throws -> HKCorrelationType {
326
+ let identifier = HKCorrelationTypeIdentifier(rawValue: identifier)
327
+
328
+ if let sampleType = HKSampleType.correlationType(forIdentifier: identifier) {
329
+ return sampleType
104
330
  }
105
- return share
331
+
332
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized correlationType with identifier \(identifier)")
106
333
  }
107
334
 
108
- func sampleTypesFromDictionary(typeIdentifiers: NSDictionary) -> Set<HKSampleType> {
109
- var share = Set<HKSampleType>()
110
- for item in typeIdentifiers {
111
- if item.value as! Bool {
112
- let sampleType = sampleTypeFromString(typeIdentifier: item.key as! String)
113
- if sampleType != nil {
114
- share.insert(sampleType!)
115
- }
116
- }
335
+ func initializeSeriesType(_ identifier: String) throws -> HKSeriesType {
336
+ if let seriesType = HKObjectType.seriesType(forIdentifier: identifier) {
337
+ return seriesType
117
338
  }
118
- return share
339
+
340
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized seriesType with identifier \(identifier)")
119
341
  }
120
342
 
121
- func objectTypeFromString(typeIdentifier: String) -> HKObjectType? {
122
- if typeIdentifier.starts(with: HKCharacteristicTypeIdentifier_PREFIX) {
123
- let identifier = HKCharacteristicTypeIdentifier.init(rawValue: typeIdentifier)
124
- return HKObjectType.characteristicType(forIdentifier: identifier) as HKObjectType?
343
+ func sampleTypeFrom(sampleTypeIdentifier: SampleTypeIdentifier) throws -> HKSampleType {
344
+ if let sampleType = try sampleTypeFromStringNullable(typeIdentifier: sampleTypeIdentifier.stringValue) {
345
+ return sampleType
125
346
  }
347
+
348
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized sampleType with identifier \(sampleTypeIdentifier.stringValue)")
349
+ }
350
+
351
+ func sampleTypeFrom(sampleTypeIdentifierWriteable: SampleTypeIdentifierWriteable) throws -> HKSampleType {
352
+ if let sampleType = try sampleTypeFromStringNullable(typeIdentifier: sampleTypeIdentifierWriteable.stringValue) {
353
+ return sampleType
354
+ }
355
+
356
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized sampleType with identifier \(sampleTypeIdentifierWriteable.stringValue)")
357
+ }
126
358
 
359
+ private func sampleTypeFromStringNullable(typeIdentifier: String) throws -> HKSampleType? {
127
360
  if typeIdentifier.starts(with: HKQuantityTypeIdentifier_PREFIX) {
128
- let identifier = HKQuantityTypeIdentifier.init(rawValue: typeIdentifier)
129
- return HKObjectType.quantityType(forIdentifier: identifier) as HKObjectType?
361
+ return try initializeQuantityType(typeIdentifier)
130
362
  }
131
363
 
132
364
  if typeIdentifier.starts(with: HKCategoryTypeIdentifier_PREFIX) {
133
- let identifier = HKCategoryTypeIdentifier.init(rawValue: typeIdentifier)
134
- return HKObjectType.categoryType(forIdentifier: identifier) as HKObjectType?
365
+ return try initializeCategoryType(typeIdentifier)
135
366
  }
136
367
 
137
368
  if typeIdentifier.starts(with: HKCorrelationTypeIdentifier_PREFIX) {
138
- let identifier = HKCorrelationTypeIdentifier.init(rawValue: typeIdentifier)
139
- return HKObjectType.correlationType(forIdentifier: identifier) as HKObjectType?
369
+ return try initializeCorrelationType(typeIdentifier)
370
+ }
371
+
372
+ if typeIdentifier == HKWorkoutTypeIdentifier {
373
+ return HKSampleType.workoutType()
140
374
  }
141
375
 
142
- if typeIdentifier == HKActivitySummaryTypeIdentifier {
143
- return HKObjectType.activitySummaryType()
376
+ if #available(iOS 11.0, *) {
377
+ if typeIdentifier == HKWorkoutRouteTypeIdentifier {
378
+ return try initializeSeriesType(typeIdentifier)
379
+ }
144
380
  }
145
381
 
382
+ if #available(iOS 13, *) {
383
+ if typeIdentifier == HKAudiogramTypeIdentifier {
384
+ return HKObjectType.audiogramSampleType()
385
+ }
386
+
387
+ if typeIdentifier == HKDataTypeIdentifierHeartbeatSeries {
388
+ return try initializeSeriesType(typeIdentifier)
389
+ }
390
+
391
+ if typeIdentifier == HKAudiogramTypeIdentifier {
392
+ return HKSampleType.audiogramSampleType()
393
+ }
394
+ }
395
+
146
396
  #if compiler(>=6)
147
397
  if #available(iOS 18, *) {
148
398
  if typeIdentifier == HKStateOfMindTypeIdentifier {
@@ -151,27 +401,74 @@ func objectTypeFromString(typeIdentifier: String) -> HKObjectType? {
151
401
  }
152
402
  #endif
153
403
 
154
- if #available(iOS 13, *) {
155
- if typeIdentifier == HKAudiogramTypeIdentifier {
156
- return HKObjectType.audiogramSampleType()
157
- }
404
+ return nil
405
+ }
158
406
 
159
- if typeIdentifier == HKDataTypeIdentifierHeartbeatSeries {
160
- return HKObjectType.seriesType(forIdentifier: typeIdentifier)
407
+ func objectTypesFromArray(typeIdentifiers: [ObjectTypeIdentifier]) -> Set<HKObjectType> {
408
+ var share = Set<HKObjectType>()
409
+ for typeIdentifier in typeIdentifiers {
410
+ do {
411
+ let objectType = try objectTypeFrom(objectTypeIdentifier: typeIdentifier)
412
+ share.insert(objectType)
413
+ } catch {
414
+ print(error.localizedDescription)
161
415
  }
162
416
  }
417
+ return share
418
+ }
163
419
 
164
- if typeIdentifier == HKWorkoutTypeIdentifier {
165
- return HKObjectType.workoutType()
420
+ func initializeUUID(_ uuidString: String) throws -> UUID {
421
+ if let uuid = UUID(uuidString: uuidString) {
422
+ return uuid
166
423
  }
424
+
425
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Got invalid UUID: \(uuidString)")
426
+ }
167
427
 
168
- if #available(iOS 11.0, *) {
169
- if typeIdentifier == HKWorkoutRouteTypeIdentifier {
170
- return HKObjectType.seriesType(forIdentifier: typeIdentifier)
428
+ func sampleTypesFromArray(typeIdentifiers: [SampleTypeIdentifier]) -> Set<HKSampleType> {
429
+ return Set(typeIdentifiers.compactMap { typeIdentifier in
430
+ do {
431
+ let sampleType = try sampleTypeFrom(sampleTypeIdentifier: typeIdentifier)
432
+ return sampleType
433
+ } catch {
434
+ print(error.localizedDescription)
435
+ }
436
+ return nil
437
+ })
438
+ }
439
+
440
+ func sampleTypesFromArray(typeIdentifiersWriteable: [SampleTypeIdentifierWriteable]) -> Set<HKSampleType> {
441
+ return Set(typeIdentifiersWriteable.compactMap { typeIdentifier in
442
+ do {
443
+ let sampleType = try sampleTypeFrom(sampleTypeIdentifierWriteable: typeIdentifier)
444
+ return sampleType
445
+ } catch {
446
+ print(error.localizedDescription)
447
+ }
448
+ return nil
449
+ })
450
+ }
451
+
452
+
453
+ // objectType is wider than sampleType, so it uses it under the hood
454
+ func objectTypeFrom(objectTypeIdentifier: ObjectTypeIdentifier) throws -> HKObjectType {
455
+ let typeIdentifier = objectTypeIdentifier.stringValue
456
+ if let sampleType = try sampleTypeFromStringNullable(typeIdentifier: typeIdentifier) {
457
+ return sampleType
458
+ }
459
+
460
+ if typeIdentifier.starts(with: HKCharacteristicTypeIdentifier_PREFIX) {
461
+ let identifier = HKCharacteristicTypeIdentifier.init(rawValue: typeIdentifier)
462
+ if let type = HKObjectType.characteristicType(forIdentifier: identifier) as HKObjectType? {
463
+ return type
171
464
  }
172
465
  }
173
466
 
174
- return nil
467
+ if typeIdentifier == HKActivitySummaryTypeIdentifier {
468
+ return HKObjectType.activitySummaryType()
469
+ }
470
+
471
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed initializing unrecognized objectType identifier " + typeIdentifier)
175
472
  }
176
473
 
177
474
  func hkStatisticsOptionsFromOptions(_ options: NSArray) -> HKStatisticsOptions {
@@ -189,10 +486,6 @@ func hkStatisticsOptionsFromOptions(_ options: NSArray) -> HKStatisticsOptions {
189
486
  opts.insert(.discreteMax)
190
487
  case "discreteMin":
191
488
  opts.insert(.discreteMin)
192
- case "discreteMostRecent":
193
- if #available(iOS 12, *) {
194
- opts.insert(.discreteMostRecent)
195
- }
196
489
  case "duration":
197
490
  if #available(iOS 13, *) {
198
491
  opts.insert(.duration)
@@ -229,166 +522,151 @@ func componentsFromInterval(_ interval: NSDictionary) -> DateComponents {
229
522
  return intervalComponents
230
523
  }
231
524
 
232
- func serializeQuantityIfExists(unit: HKUnit, quantity: HKQuantity?) -> [String: Any]? {
233
- guard let quantity = quantity else { return nil }
234
- return serializeQuantity(unit: unit, quantity: quantity)
235
- }
236
-
237
- func serializeStatisticIfExists(unit: HKUnit, quantity: HKQuantity?, stats: HKStatistics)
238
- -> [String: Any]? {
239
- guard let quantity = quantity else { return nil }
240
- return serializeStatistic(unit: unit, quantity: quantity, stats: stats)
241
- }
242
-
243
- func parseWorkoutConfiguration(_ dict: NSDictionary) -> HKWorkoutConfiguration {
525
+ func parseWorkoutConfiguration(_ config: WorkoutConfiguration) -> HKWorkoutConfiguration {
244
526
  let configuration = HKWorkoutConfiguration()
245
527
 
246
- if let activityTypeRaw = dict[HKWorkoutActivityTypePropertyName] as? UInt,
247
- let activityType = HKWorkoutActivityType(rawValue: activityTypeRaw) {
248
- configuration.activityType = activityType
528
+ if let activityType = HKWorkoutActivityType(rawValue: UInt(config.activityType.rawValue)) {
529
+ configuration.activityType = activityType
249
530
  }
250
531
 
251
- if let locationTypeRaw = dict[HKWorkoutSessionLocationTypePropertyName] as? Int,
252
- let locationType = HKWorkoutSessionLocationType(rawValue: locationTypeRaw) {
532
+ if let locationTypeRaw = config.locationType,
533
+ let locationType = HKWorkoutSessionLocationType(rawValue: Int(locationTypeRaw.rawValue)) {
253
534
  configuration.locationType = locationType
254
535
  }
255
536
 
256
537
  return configuration
257
538
  }
258
539
 
259
- #if compiler(>=6)
260
- @available(iOS 18.0, *)
261
- extension HKStateOfMind.Kind: @retroactive CaseIterable, @retroactive CustomStringConvertible {
262
- public var description: String {
263
- switch self {
264
- case .dailyMood: "Daily mood"
265
- case .momentaryEmotion: "Momentary Emotion"
266
- @unknown default: "Unknown"
267
- }
268
- }
269
-
270
- public static var allCases: [HKStateOfMind.Kind] {
271
- [.dailyMood, .momentaryEmotion]
272
- }
273
-
274
- static func convertToStateOfMindKind(int: Int) -> HKStateOfMind.Kind {
275
- // default to .dailyMood if we receive an int out of bounds
276
- return HKStateOfMind.Kind(rawValue: int) ?? .dailyMood
277
- }
278
- }
279
- #endif
280
-
281
- #if compiler(>=6)
282
- @available(iOS 18.0, *)
283
- extension HKStateOfMind.Label: @retroactive CaseIterable, @retroactive CustomStringConvertible {
284
- public var description: String {
285
- switch self {
286
- case .amazed: "Amazed"
287
- case .amused: "Amused"
288
- case .angry: "Angry"
289
- case .anxious: "Anxious"
290
- case .ashamed: "Ashamed"
291
- case .brave: "Brave"
292
- case .calm: "Calm"
293
- case .content: "Content"
294
- case .disappointed: "Disappointed"
295
- case .discouraged: "Discouraged"
296
- case .disgusted: "Disgusted"
297
- case .embarrassed: "Embarrassed"
298
- case .excited: "Excited"
299
- case .frustrated: "Frustrated"
300
- case .grateful: "Grateful"
301
- case .guilty: "Guilty"
302
- case .happy: "Happy"
303
- case .hopeless: "Hopeless"
304
- case .irritated: "Irritated"
305
- case .jealous: "Jealous"
306
- case .joyful: "Joyful"
307
- case .lonely: "Lonely"
308
- case .passionate: "Passionate"
309
- case .peaceful: "Peaceful"
310
- case .proud: "Proud"
311
- case .relieved: "Relieved"
312
- case .sad: "Sad"
313
- case .scared: "Scared"
314
- case .stressed: "Stressed"
315
- case .surprised: "Surprised"
316
- case .worried: "Worried"
317
- case .annoyed: "Annoyed"
318
- case .confident: "Confident"
319
- case .drained: "Drained"
320
- case .hopeful: "Hopeful"
321
- case .indifferent: "Indifferent"
322
- case .overwhelmed: "Overwhelmed"
323
- case .satisfied: "Satisfied"
324
- @unknown default: "Unknown"
325
- }
326
- }
327
-
328
- public static var allCases: [HKStateOfMind.Label] {
329
- [
330
- .amazed, .amused, .angry, .anxious, .ashamed,
331
- .brave, .calm, .content, .disappointed, .discouraged,
332
- .disgusted, .embarrassed, .excited, .frustrated, .grateful,
333
- .guilty, .happy, .hopeless, .irritated, .jealous,
334
- .joyful, .lonely, .passionate, .peaceful, .proud,
335
- .relieved, .sad, .scared, .stressed, .surprised,
336
- .worried, .annoyed, .confident, .drained, .hopeful,
337
- .indifferent, .overwhelmed, .satisfied
540
+ // Returns all available HKQuantityTypeIdentifier raw values as an array of String
541
+ func allQuantityTypeIdentifiers() -> [String] {
542
+ let allIdentifiers: [HKQuantityTypeIdentifier] = [
543
+ .bodyMassIndex,
544
+ .bodyFatPercentage,
545
+ .height,
546
+ .bodyMass,
547
+ .leanBodyMass,
548
+ .waistCircumference,
549
+ .stepCount,
550
+ .distanceWalkingRunning,
551
+ .distanceCycling,
552
+ .distanceWheelchair,
553
+ .basalEnergyBurned,
554
+ .activeEnergyBurned,
555
+ .flightsClimbed,
556
+ .nikeFuel,
557
+ .appleExerciseTime,
558
+ .pushCount,
559
+ .distanceSwimming,
560
+ .swimmingStrokeCount,
561
+ .vo2Max,
562
+ .distanceDownhillSnowSports,
563
+ .appleStandTime,
564
+ .walkingSpeed,
565
+ .walkingDoubleSupportPercentage,
566
+ .walkingAsymmetryPercentage,
567
+ .walkingStepLength,
568
+ .sixMinuteWalkTestDistance,
569
+ .stairAscentSpeed,
570
+ .stairDescentSpeed,
571
+ .heartRate,
572
+ .bodyTemperature,
573
+ .basalBodyTemperature,
574
+ .bloodPressureSystolic,
575
+ .bloodPressureDiastolic,
576
+ .respiratoryRate,
577
+ .restingHeartRate,
578
+ .walkingHeartRateAverage,
579
+ .heartRateVariabilitySDNN,
580
+ .oxygenSaturation,
581
+ .peripheralPerfusionIndex,
582
+ .bloodGlucose,
583
+ .numberOfTimesFallen,
584
+ .electrodermalActivity,
585
+ .inhalerUsage,
586
+ .insulinDelivery,
587
+ .bloodAlcoholContent,
588
+ .forcedVitalCapacity,
589
+ .forcedExpiratoryVolume1,
590
+ .peakExpiratoryFlowRate,
591
+ .environmentalAudioExposure,
592
+ .headphoneAudioExposure,
593
+ .dietaryFatTotal,
594
+ .dietaryFatPolyunsaturated,
595
+ .dietaryFatMonounsaturated,
596
+ .dietaryFatSaturated,
597
+ .dietaryCholesterol,
598
+ .dietarySodium,
599
+ .dietaryCarbohydrates,
600
+ .dietaryFiber,
601
+ .dietarySugar,
602
+ .dietaryEnergyConsumed,
603
+ .dietaryProtein,
604
+ .dietaryVitaminA,
605
+ .dietaryVitaminB6,
606
+ .dietaryVitaminB12,
607
+ .dietaryVitaminC,
608
+ .dietaryVitaminD,
609
+ .dietaryVitaminE,
610
+ .dietaryVitaminK,
611
+ .dietaryCalcium,
612
+ .dietaryIron,
613
+ .dietaryThiamin,
614
+ .dietaryRiboflavin,
615
+ .dietaryNiacin,
616
+ .dietaryFolate,
617
+ .dietaryBiotin,
618
+ .dietaryPantothenicAcid,
619
+ .dietaryPhosphorus,
620
+ .dietaryIodine,
621
+ .dietaryMagnesium,
622
+ .dietaryZinc,
623
+ .dietarySelenium,
624
+ .dietaryCopper,
625
+ .dietaryManganese,
626
+ .dietaryChromium,
627
+ .dietaryMolybdenum,
628
+ .dietaryChloride,
629
+ .dietaryPotassium,
630
+ .dietaryCaffeine,
631
+ .dietaryWater,
632
+ .uvExposure
633
+ // Add more identifiers as needed for your iOS version
338
634
  ]
339
- }
340
-
341
- static func convertToStateOfMindLabels(intArray: [Int]) -> [HKStateOfMind.Label] {
342
- return intArray.compactMap { index in
343
- // if any int are out of bounds return nil instead of crashing
344
- guard index >= 0 && index < HKStateOfMind.Label.allCases.count else { return nil }
345
- return HKStateOfMind.Label(rawValue: index)
346
- }
347
- }
348
- }
349
- #endif
350
-
351
- #if compiler(>=6)
352
- @available(iOS 18.0, *)
353
- extension HKStateOfMind.Association: @retroactive CaseIterable, @retroactive CustomStringConvertible {
354
- public var description: String {
355
- switch self {
356
- case .community: "Community"
357
- case .currentEvents: "Current Events"
358
- case .dating: "Dating"
359
- case .education: "Education"
360
- case .family: "Family"
361
- case .fitness: "Fitness"
362
- case .friends: "Friends"
363
- case .health: "Health"
364
- case .hobbies: "Hobbies"
365
- case .identity: "Identity"
366
- case .money: "Money"
367
- case .partner: "Partner"
368
- case .selfCare: "Self Care"
369
- case .spirituality: "Spirituality"
370
- case .tasks: "Tasks"
371
- case .travel: "Travel"
372
- case .work: "Work"
373
- case .weather: "Weather"
374
- @unknown default: "Unknown"
375
- }
376
- }
377
-
378
- public static var allCases: [HKStateOfMind.Association] {
379
- [
380
- .community, .currentEvents, .dating, .education, .family,
381
- .fitness, .friends, .health, .hobbies, .identity,
382
- .money, .partner, .selfCare, .spirituality, .tasks,
383
- .travel, .work, .weather
635
+ let supported = allIdentifiers.compactMap { identifier in
636
+ HKObjectType.quantityType(forIdentifier: identifier) != nil ? identifier.rawValue : nil
637
+ }
638
+ let missing = allIdentifiers.filter { HKObjectType.quantityType(forIdentifier: $0) == nil }
639
+ if !missing.isEmpty {
640
+ print("[react-native-healthkit] Warning: The following HKQuantityTypeIdentifiers are not available on this iOS version: \(missing.map { $0.rawValue })")
641
+ }
642
+ // --- New logic: Warn if any available identifier is not in the hardcoded list ---
643
+ // Try common HealthKit identifier strings (brute-force, as Apple does not provide a list)
644
+ let knownPrefixes = [
645
+ "HKQuantityTypeIdentifier",
646
+ "HKQuantityTypeIdentifierDietary",
647
+ "HKQuantityTypeIdentifierEnvironmental",
648
+ "HKQuantityTypeIdentifierBlood",
649
+ "HKQuantityTypeIdentifierBody",
650
+ "HKQuantityTypeIdentifierDistance",
651
+ "HKQuantityTypeIdentifierHeart",
652
+ "HKQuantityTypeIdentifierRespiratory",
653
+ "HKQuantityTypeIdentifierWalking",
654
+ "HKQuantityTypeIdentifierSwimming",
655
+ "HKQuantityTypeIdentifierApple"
384
656
  ]
385
- }
386
-
387
- static func convertToStateOfMindAssociations(intArray: [Int]) -> [HKStateOfMind.Association] {
388
- return intArray.compactMap { index in
389
- guard index >= 0 && index < HKStateOfMind.Association.allCases.count else { return nil }
390
- return HKStateOfMind.Association(rawValue: index)
391
- }
392
- }
657
+ var foundButNotListed: [String] = []
658
+ // Try all possible identifier strings (brute-force for demonstration, not exhaustive)
659
+ for codePoint in 0..<300 {
660
+ for prefix in knownPrefixes {
661
+ let candidate = prefix + String(codePoint)
662
+ if let type = HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier(rawValue: candidate)),
663
+ !allIdentifiers.contains(where: { $0.rawValue == candidate }) {
664
+ foundButNotListed.append(candidate)
665
+ }
666
+ }
667
+ }
668
+ if !foundButNotListed.isEmpty {
669
+ print("[react-native-healthkit] Warning: The following HKQuantityTypeIdentifiers are available on this iOS version but NOT included in the hardcoded list: \(foundButNotListed)")
670
+ }
671
+ return supported
393
672
  }
394
- #endif