@kingstinct/react-native-healthkit 8.7.2 → 9.0.1

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/README.md +34 -21
  2. package/ReactNativeHealthkit.podspec +36 -0
  3. package/app.plugin.js +43 -33
  4. package/ios/Bridge.h +8 -0
  5. package/ios/CategoryTypeModule.swift +128 -0
  6. package/ios/CharacteristicTypeModule.swift +78 -0
  7. package/ios/Constants.swift +2 -0
  8. package/ios/CoreModule.swift +376 -0
  9. package/ios/CorrelationTypeModule.swift +153 -0
  10. package/ios/HeartbeatSeriesModule.swift +189 -0
  11. package/ios/Helpers.swift +525 -251
  12. package/ios/QuantityTypeModule.swift +461 -0
  13. package/ios/Serializers.swift +211 -124
  14. package/ios/SourceProxy.swift +35 -0
  15. package/ios/StateOfMindModule.swift +160 -0
  16. package/ios/WorkoutProxy.swift +412 -0
  17. package/ios/WorkoutSessionModule.swift +182 -0
  18. package/ios/WorkoutsModule.swift +357 -0
  19. package/package.json +43 -127
  20. package/react-native.config.js +16 -0
  21. package/src/hooks/useHealthkitAuthorization.test.ts +47 -29
  22. package/src/hooks/useHealthkitAuthorization.ts +21 -15
  23. package/src/hooks/useIsHealthDataAvailable.test.ts +17 -7
  24. package/src/hooks/useIsHealthDataAvailable.ts +7 -7
  25. package/src/hooks/useMostRecentCategorySample.ts +10 -12
  26. package/src/hooks/useMostRecentQuantitySample.ts +17 -36
  27. package/src/hooks/useMostRecentWorkout.ts +16 -38
  28. package/src/hooks/useSources.ts +8 -12
  29. package/src/hooks/useStatisticsForQuantity.ts +19 -14
  30. package/src/hooks/useSubscribeToChanges.ts +9 -13
  31. package/src/index.ios.ts +232 -0
  32. package/src/index.ts +444 -0
  33. package/src/modules.ts +43 -0
  34. package/src/specs/CategoryTypeModule.nitro.ts +64 -0
  35. package/src/specs/CharacteristicTypeModule.nitro.ts +22 -0
  36. package/src/specs/CoreModule.nitro.ts +107 -0
  37. package/src/specs/CorrelationTypeModule.nitro.ts +23 -0
  38. package/src/specs/HeartbeatSeriesModule.nitro.ts +19 -0
  39. package/src/specs/QuantityTypeModule.nitro.ts +60 -0
  40. package/src/specs/SourceProxy.nitro.ts +13 -0
  41. package/src/specs/StateOfMindModule.nitro.ts +23 -0
  42. package/src/specs/WorkoutProxy.nitro.ts +18 -0
  43. package/src/specs/WorkoutSessionModule.nitro.ts +71 -0
  44. package/src/specs/WorkoutsModule.nitro.ts +32 -0
  45. package/src/test-setup.ts +68 -54
  46. package/src/test-utils.ts +3 -2
  47. package/src/types/Auth.ts +17 -0
  48. package/src/types/Background.ts +9 -0
  49. package/src/types/CategoryType.ts +249 -0
  50. package/src/types/CategoryTypeIdentifier.ts +99 -0
  51. package/src/types/Characteristics.ts +53 -0
  52. package/src/types/Constants.ts +25 -0
  53. package/src/types/CorrelationType.ts +31 -0
  54. package/src/types/Device.ts +13 -0
  55. package/src/types/HeartbeatSeries.ts +29 -0
  56. package/src/types/InterfaceVerification.ts +164 -0
  57. package/src/types/InterfaceVerificationExample.ts +89 -0
  58. package/src/types/QuantitySample.ts +30 -0
  59. package/src/types/QuantityType.ts +192 -0
  60. package/src/types/QuantityTypeIdentifier.ts +758 -0
  61. package/src/types/QueryOptions.ts +69 -0
  62. package/src/types/README-InterfaceVerification.md +103 -0
  63. package/src/types/Shared.ts +79 -0
  64. package/src/types/Source.ts +11 -0
  65. package/src/types/StateOfMind.ts +110 -0
  66. package/src/types/Subscriptons.ts +10 -0
  67. package/src/types/Units.ts +190 -0
  68. package/src/types/WeatherCondition.ts +31 -0
  69. package/src/types/WorkoutKit.ts +18 -0
  70. package/src/types/Workouts.ts +282 -0
  71. package/src/utils/getMostRecentCategorySample.ts +7 -11
  72. package/src/utils/getMostRecentQuantitySample.ts +8 -18
  73. package/src/utils/getMostRecentWorkout.ts +7 -17
  74. package/src/utils/getPreferredUnit.ts +12 -8
  75. package/src/utils/subscribeToChanges.ts +9 -26
  76. package/LICENSE +0 -21
  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,140 +7,387 @@
7
7
 
8
8
  import Foundation
9
9
  import HealthKit
10
+ import NitroModules
11
+
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
10
20
 
11
- func dateOrNilIfZero(date: Date) -> Date? {
12
- return date.timeIntervalSince1970 > 0 ? date : nil
13
21
  }
14
22
 
15
- func limitOrNilIfZero(limit: Int) -> Int {
16
- return limit == 0 ? HKObjectQueryNoLimit : limit
23
+ func getQueryLimit(_ limit: Double?) -> Int {
24
+ if let limit = limit {
25
+ if limit == .infinity || limit <= 0 {
26
+ return HKObjectQueryNoLimit
27
+ }
28
+
29
+ return Int(limit)
30
+ }
31
+
32
+ return DEFAULT_QUERY_LIMIT
17
33
  }
18
34
 
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
35
+ func createPredicateForWorkout(filter: PredicateForWorkouts) throws -> NSPredicate {
36
+ switch filter {
37
+ case .first(let uuidWrapper):
38
+ return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
39
+ case .second(let uuidsWrapper):
40
+ return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
41
+ case .third(let metadataKey):
42
+ return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
43
+ case .fourth(let dateFilter):
44
+ return createDatePredicate(dateFilter: dateFilter)
45
+ case .fifth(let w):
46
+ if let w = w.workout as? WorkoutProxy {
47
+ return w.workoutPredicate
48
+ }
49
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
50
+ case .sixth(let activityType):
51
+ if let activityType = HKWorkoutActivityType.init(rawValue: UInt(activityType.workoutActivityType.rawValue)) {
52
+ return HKQuery.predicateForWorkouts(with: activityType)
53
+ } else {
54
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized workoutActivityType with identifier \(activityType.workoutActivityType.rawValue)")
55
+ }
56
+ case .seventh(let durationPredicate):
57
+ if let op = NSComparisonPredicate.Operator(rawValue: UInt(durationPredicate.predicateOperator.rawValue)) {
58
+ return HKQuery.predicateForWorkouts(with: op, duration: durationPredicate.durationInSeconds)
59
+ }
60
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized workout duration predicate operator \(durationPredicate.predicateOperator.rawValue)")
61
+ }
62
+ }
63
+
64
+ func createPredicateForWorkout(filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_WorkoutActivityTypePredicate_WorkoutDurationPredicate_PredicateForWorkoutsOr_PredicateForWorkoutsAnd?) throws -> NSPredicate? {
65
+ if let filter = filter {
66
+ switch filter {
67
+ case .first(let uuidWrapper):
68
+ return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
69
+ case .second(let uuidsWrapper):
70
+ return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
71
+ case .third(let metadataKey):
72
+ return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
73
+ case .fourth(let dateFilter):
74
+ return createDatePredicate(dateFilter: dateFilter)
75
+ case .fifth(let w):
76
+ if let w = w.workout as? WorkoutProxy {
77
+ return w.workoutPredicate
78
+ }
79
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
80
+ case .sixth(let activityType):
81
+ if let activityType = HKWorkoutActivityType.init(rawValue: UInt(activityType.workoutActivityType.rawValue)) {
82
+ return HKQuery.predicateForWorkouts(with: activityType)
83
+ } else {
84
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized workoutActivityType with identifier \(activityType.workoutActivityType.rawValue)")
85
+ }
86
+ case .seventh(let durationPredicate):
87
+ if let op = NSComparisonPredicate.Operator(rawValue: UInt(durationPredicate.predicateOperator.rawValue)) {
88
+ return HKQuery.predicateForWorkouts(with: op, duration: durationPredicate.durationInSeconds)
89
+ }
90
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized workout duration predicate operator \(durationPredicate.predicateOperator.rawValue)")
91
+
92
+ case .eigth(let or):
93
+ return NSCompoundPredicate.init(andPredicateWithSubpredicates: try or.OR.map { predicate in
94
+ return try createPredicateForWorkout(filter: predicate)
95
+ })
96
+ case .ninth(let and):
97
+ return NSCompoundPredicate.init(orPredicateWithSubpredicates: try and.AND
98
+ .map { predicate in
99
+ return try createPredicateForWorkout(filter: predicate)
100
+ })
101
+ }
25
102
  }
103
+
104
+ return nil
26
105
  }
27
106
 
28
- func getSortDescriptors(ascending: Bool) -> [NSSortDescriptor] {
29
- return [NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: ascending)]
107
+ func createDatePredicate(dateFilter: PredicateWithStartAndEnd) -> NSPredicate {
108
+ let strictStartDate = dateFilter.strictStartDate ?? false
109
+ let strictEndDate = dateFilter.strictEndDate ?? false
110
+
111
+ let options: HKQueryOptions = strictStartDate && strictEndDate
112
+ ? [.strictStartDate, .strictEndDate]
113
+ : strictEndDate
114
+ ? .strictEndDate
115
+ : strictStartDate
116
+ ? .strictStartDate
117
+ : []
118
+
119
+ return HKQuery.predicateForSamples(
120
+ withStart: dateFilter.startDate,
121
+ end: dateFilter.endDate,
122
+ options: options
123
+ )
30
124
  }
31
125
 
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
126
+ func createUUIDsPredicate(uuidsWrapper: PredicateWithUUIDs) -> NSPredicate {
127
+ let uuids = uuidsWrapper.uuids.compactMap { uuidStr -> UUID? in
128
+ do {
129
+ let uuid = try initializeUUID(uuidStr)
130
+ return uuid
131
+ } catch {
132
+ print(error.localizedDescription)
133
+ return nil
134
+ }
37
135
  }
136
+ return HKQuery.predicateForObjects(with: Set(uuids))
137
+ }
38
138
 
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)
139
+ func createPredicate(filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout?) throws -> NSPredicate? {
140
+ if let filter = filter {
141
+ switch filter {
142
+ case .first(let uuidWrapper):
143
+ return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
144
+ case .second(let uuidsWrapper):
145
+ return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
146
+ case .third(let metadataKey):
147
+ return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
148
+ case .fourth(let dateFilter):
149
+ return createDatePredicate(dateFilter: dateFilter)
150
+ case .fifth(let w):
151
+ if let w = w.workout as? WorkoutProxy {
152
+ return w.workoutPredicate
153
+ }
154
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
155
+ }
156
+ }
157
+ return nil
158
+ }
44
159
 
45
- return anchor as? HKQueryAnchor
46
- } catch {
47
- print("Error: Unable to unarchive HKQueryAnchor object: \(error)")
48
- return nil
160
+ func createPredicate(filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_FilterForSamplesAnd_FilterForSamplesOr?) throws -> NSPredicate? {
161
+ if let filter = filter {
162
+ switch filter {
163
+ case .first(let uuidWrapper):
164
+ return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
165
+ case .second(let uuidsWrapper):
166
+ return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
167
+ case .third(let metadataKey):
168
+ return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
169
+ case .fourth(let dateFilter):
170
+ return createDatePredicate(dateFilter: dateFilter)
171
+ case .fifth(let w):
172
+ if let w = w.workout as? WorkoutProxy {
173
+ return w.workoutPredicate
174
+ }
175
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
176
+ case .sixth(let and):
177
+ return NSCompoundPredicate.init(andPredicateWithSubpredicates: try and.AND.map { predicate in
178
+ return try createPredicateForSamples(filter: predicate)
179
+ })
180
+ case .seventh(let or):
181
+ return NSCompoundPredicate.init(orPredicateWithSubpredicates: try or.OR
182
+ .map { predicate in
183
+ return try createPredicateForSamples(filter: predicate)
184
+ })
185
+ }
49
186
  }
187
+ return nil
50
188
  }
51
189
 
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?
190
+ func createPredicateForSamples(filter: PredicateForSamples) throws -> NSPredicate {
191
+ switch filter {
192
+ case .first(let uuidWrapper):
193
+ return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
194
+ case .second(let uuidsWrapper):
195
+ return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
196
+ case .third(let metadataKey):
197
+ return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
198
+ case .fourth(let dateFilter):
199
+ return createDatePredicate(dateFilter: dateFilter)
200
+ case .fifth(let w):
201
+ if let w = w.workout as? WorkoutProxy {
202
+ return w.workoutPredicate
203
+ }
204
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
56
205
  }
206
+ }
57
207
 
58
- if typeIdentifier.starts(with: HKCategoryTypeIdentifier_PREFIX) {
59
- let identifier = HKCategoryTypeIdentifier.init(rawValue: typeIdentifier)
60
- return HKSampleType.categoryType(forIdentifier: identifier) as HKSampleType?
208
+ func createPredicateForSamples(filter: FilterForSamples) throws -> NSPredicate {
209
+ switch filter {
210
+ case .first(let uuidWrapper):
211
+ return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
212
+ case .second(let uuidsWrapper):
213
+ return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
214
+ case .third(let metadataKey):
215
+ return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
216
+ case .fourth(let dateFilter):
217
+ return createDatePredicate(dateFilter: dateFilter)
218
+ case .fifth(let w):
219
+ if let w = w.workout as? WorkoutProxy {
220
+ return w.workoutPredicate
221
+ }
222
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
223
+ case .sixth(let and):
224
+ return NSCompoundPredicate.init(andPredicateWithSubpredicates: try and.AND.map { predicate in
225
+ return try createPredicateForSamples(filter: predicate)
226
+ })
227
+ case .seventh(let or):
228
+ return NSCompoundPredicate.init(orPredicateWithSubpredicates: try or.OR
229
+ .map { predicate in
230
+ return try createPredicateForSamples(filter: predicate)
231
+ })
61
232
  }
233
+ }
62
234
 
63
- if typeIdentifier.starts(with: HKCorrelationTypeIdentifier_PREFIX) {
64
- let identifier = HKCorrelationTypeIdentifier.init(rawValue: typeIdentifier)
65
- return HKSampleType.correlationType(forIdentifier: identifier) as HKSampleType?
235
+ func createPredicateForSamples(filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_FilterForSamplesAnd_FilterForSamplesOr) throws -> NSPredicate {
236
+ switch filter {
237
+ case .first(let uuidWrapper):
238
+ return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
239
+ case .second(let uuidsWrapper):
240
+ return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
241
+ case .third(let metadataKey):
242
+ return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
243
+ case .fourth(let dateFilter):
244
+ return createDatePredicate(dateFilter: dateFilter)
245
+ case .fifth(let w):
246
+ if let w = w.workout as? WorkoutProxy {
247
+ return w.workoutPredicate
248
+ }
249
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
250
+ case .sixth(let and):
251
+ return NSCompoundPredicate.init(andPredicateWithSubpredicates: try and.AND.map { predicate in
252
+ return try createPredicateForSamples(filter: predicate)
253
+ })
254
+ case .seventh(let or):
255
+ return NSCompoundPredicate.init(orPredicateWithSubpredicates: try or.OR
256
+ .map { predicate in
257
+ return try createPredicateForSamples(filter: predicate)
258
+ })
66
259
  }
260
+ }
67
261
 
68
- if #available(iOS 13, *) {
69
- if typeIdentifier == HKAudiogramTypeIdentifier {
70
- return HKSampleType.audiogramSampleType()
262
+ func getSortDescriptors(ascending: Bool?) -> [NSSortDescriptor] {
263
+ return [NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: ascending ?? false)]
264
+ }
265
+
266
+ func getSortDescsdsdriptors(ascending: Bool?) -> [NSSortDescriptor] {
267
+ return [NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: ascending ?? false)]
268
+ }
269
+
270
+ func deserializeHKQueryAnchor(base64String: String?) throws -> HKQueryAnchor? {
271
+ if let base64String = base64String {
272
+ if base64String.isEmpty {
273
+ return nil
71
274
  }
72
- }
73
275
 
74
- #if compiler(>=6)
75
- if #available(iOS 18, *) {
76
- if typeIdentifier == HKStateOfMindTypeIdentifier {
77
- return HKObjectType.stateOfMindType()
78
- }
276
+ // Step 1: Decode the base64 string to a Data object
277
+ guard let data = Data(base64Encoded: base64String) else {
278
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Invalid base64 string: \(base64String)")
79
279
  }
80
- #endif
81
280
 
82
- if typeIdentifier == HKWorkoutTypeIdentifier {
83
- return HKSampleType.workoutType()
84
- }
281
+ // Step 2: Use NSKeyedUnarchiver to unarchive the data and create an HKQueryAnchor object
282
+ do {
283
+ let unarchiver = try NSKeyedUnarchiver(forReadingFrom: data)
284
+ unarchiver.requiresSecureCoding = true
285
+ let anchor = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data)
85
286
 
86
- if #available(iOS 11.0, *) {
87
- if typeIdentifier == HKWorkoutRouteTypeIdentifier {
88
- return HKObjectType.seriesType(forIdentifier: typeIdentifier)
287
+ return anchor as? HKQueryAnchor
288
+ } catch {
289
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Error recreating HKQueryAnchor object: \(error.localizedDescription)")
89
290
  }
90
291
  }
91
-
92
292
  return nil
93
293
  }
94
294
 
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
- }
295
+ func initializeCategoryType(_ identifier: String) throws -> HKCategoryType {
296
+ let identifier = HKCategoryTypeIdentifier(rawValue: identifier)
297
+ if let sampleType = HKSampleType.categoryType(forIdentifier: identifier) {
298
+ return sampleType
104
299
  }
105
- return share
300
+
301
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized categoryType with identifier \(identifier)")
106
302
  }
107
303
 
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
- }
304
+ func initializeWorkoutActivityType(_ typeIdentifier: UInt) throws -> HKWorkoutActivityType {
305
+ if let type = HKWorkoutActivityType.init(rawValue: typeIdentifier) {
306
+ return type
117
307
  }
118
- return share
308
+
309
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized quantityType with identifier \(typeIdentifier)")
119
310
  }
120
311
 
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?
312
+ func initializeQuantityType(_ identifier: String) throws -> HKQuantityType {
313
+ let identifier = HKQuantityTypeIdentifier(rawValue: identifier)
314
+
315
+ if let sampleType = HKSampleType.quantityType(forIdentifier: identifier) {
316
+ return sampleType
317
+ }
318
+
319
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized quantityType with identifier \(identifier)")
320
+ }
321
+
322
+ func initializeCorrelationType(_ identifier: String) throws -> HKCorrelationType {
323
+ let identifier = HKCorrelationTypeIdentifier(rawValue: identifier)
324
+
325
+ if let sampleType = HKSampleType.correlationType(forIdentifier: identifier) {
326
+ return sampleType
327
+ }
328
+
329
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized correlationType with identifier \(identifier)")
330
+ }
331
+
332
+ func initializeSeriesType(_ identifier: String) throws -> HKSeriesType {
333
+ if let seriesType = HKObjectType.seriesType(forIdentifier: identifier) {
334
+ return seriesType
125
335
  }
126
336
 
337
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized seriesType with identifier \(identifier)")
338
+ }
339
+
340
+ func sampleTypeFrom(sampleTypeIdentifier: SampleTypeIdentifier) throws -> HKSampleType {
341
+ if let sampleType = try sampleTypeFromStringNullable(typeIdentifier: sampleTypeIdentifier.stringValue) {
342
+ return sampleType
343
+ }
344
+
345
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized sampleType with identifier \(sampleTypeIdentifier.stringValue)")
346
+ }
347
+
348
+ func sampleTypeFrom(sampleTypeIdentifierWriteable: SampleTypeIdentifierWriteable) throws -> HKSampleType {
349
+ if let sampleType = try sampleTypeFromStringNullable(typeIdentifier: sampleTypeIdentifierWriteable.stringValue) {
350
+ return sampleType
351
+ }
352
+
353
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize unrecognized sampleType with identifier \(sampleTypeIdentifierWriteable.stringValue)")
354
+ }
355
+
356
+ private func sampleTypeFromStringNullable(typeIdentifier: String) throws -> HKSampleType? {
127
357
  if typeIdentifier.starts(with: HKQuantityTypeIdentifier_PREFIX) {
128
- let identifier = HKQuantityTypeIdentifier.init(rawValue: typeIdentifier)
129
- return HKObjectType.quantityType(forIdentifier: identifier) as HKObjectType?
358
+ return try initializeQuantityType(typeIdentifier)
130
359
  }
131
360
 
132
361
  if typeIdentifier.starts(with: HKCategoryTypeIdentifier_PREFIX) {
133
- let identifier = HKCategoryTypeIdentifier.init(rawValue: typeIdentifier)
134
- return HKObjectType.categoryType(forIdentifier: identifier) as HKObjectType?
362
+ return try initializeCategoryType(typeIdentifier)
135
363
  }
136
364
 
137
365
  if typeIdentifier.starts(with: HKCorrelationTypeIdentifier_PREFIX) {
138
- let identifier = HKCorrelationTypeIdentifier.init(rawValue: typeIdentifier)
139
- return HKObjectType.correlationType(forIdentifier: identifier) as HKObjectType?
366
+ return try initializeCorrelationType(typeIdentifier)
140
367
  }
141
368
 
142
- if typeIdentifier == HKActivitySummaryTypeIdentifier {
143
- return HKObjectType.activitySummaryType()
369
+ if typeIdentifier == HKWorkoutTypeIdentifier {
370
+ return HKSampleType.workoutType()
371
+ }
372
+
373
+ if #available(iOS 11.0, *) {
374
+ if typeIdentifier == HKWorkoutRouteTypeIdentifier {
375
+ return try initializeSeriesType(typeIdentifier)
376
+ }
377
+ }
378
+
379
+ if #available(iOS 13, *) {
380
+ if typeIdentifier == HKAudiogramTypeIdentifier {
381
+ return HKObjectType.audiogramSampleType()
382
+ }
383
+
384
+ if typeIdentifier == HKDataTypeIdentifierHeartbeatSeries {
385
+ return try initializeSeriesType(typeIdentifier)
386
+ }
387
+
388
+ if typeIdentifier == HKAudiogramTypeIdentifier {
389
+ return HKSampleType.audiogramSampleType()
390
+ }
144
391
  }
145
392
 
146
393
  #if compiler(>=6)
@@ -151,27 +398,73 @@ func objectTypeFromString(typeIdentifier: String) -> HKObjectType? {
151
398
  }
152
399
  #endif
153
400
 
154
- if #available(iOS 13, *) {
155
- if typeIdentifier == HKAudiogramTypeIdentifier {
156
- return HKObjectType.audiogramSampleType()
157
- }
401
+ return nil
402
+ }
158
403
 
159
- if typeIdentifier == HKDataTypeIdentifierHeartbeatSeries {
160
- return HKObjectType.seriesType(forIdentifier: typeIdentifier)
404
+ func objectTypesFromArray(typeIdentifiers: [ObjectTypeIdentifier]) -> Set<HKObjectType> {
405
+ var share = Set<HKObjectType>()
406
+ for typeIdentifier in typeIdentifiers {
407
+ do {
408
+ let objectType = try objectTypeFrom(objectTypeIdentifier: typeIdentifier)
409
+ share.insert(objectType)
410
+ } catch {
411
+ print(error.localizedDescription)
161
412
  }
162
413
  }
414
+ return share
415
+ }
163
416
 
164
- if typeIdentifier == HKWorkoutTypeIdentifier {
165
- return HKObjectType.workoutType()
417
+ func initializeUUID(_ uuidString: String) throws -> UUID {
418
+ if let uuid = UUID(uuidString: uuidString) {
419
+ return uuid
166
420
  }
167
421
 
168
- if #available(iOS 11.0, *) {
169
- if typeIdentifier == HKWorkoutRouteTypeIdentifier {
170
- return HKObjectType.seriesType(forIdentifier: typeIdentifier)
422
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Got invalid UUID: \(uuidString)")
423
+ }
424
+
425
+ func sampleTypesFromArray(typeIdentifiers: [SampleTypeIdentifier]) -> Set<HKSampleType> {
426
+ return Set(typeIdentifiers.compactMap { typeIdentifier in
427
+ do {
428
+ let sampleType = try sampleTypeFrom(sampleTypeIdentifier: typeIdentifier)
429
+ return sampleType
430
+ } catch {
431
+ print(error.localizedDescription)
432
+ }
433
+ return nil
434
+ })
435
+ }
436
+
437
+ func sampleTypesFromArray(typeIdentifiersWriteable: [SampleTypeIdentifierWriteable]) -> Set<HKSampleType> {
438
+ return Set(typeIdentifiersWriteable.compactMap { typeIdentifier in
439
+ do {
440
+ let sampleType = try sampleTypeFrom(sampleTypeIdentifierWriteable: typeIdentifier)
441
+ return sampleType
442
+ } catch {
443
+ print(error.localizedDescription)
444
+ }
445
+ return nil
446
+ })
447
+ }
448
+
449
+ // objectType is wider than sampleType, so it uses it under the hood
450
+ func objectTypeFrom(objectTypeIdentifier: ObjectTypeIdentifier) throws -> HKObjectType {
451
+ let typeIdentifier = objectTypeIdentifier.stringValue
452
+ if let sampleType = try sampleTypeFromStringNullable(typeIdentifier: typeIdentifier) {
453
+ return sampleType
454
+ }
455
+
456
+ if typeIdentifier.starts(with: HKCharacteristicTypeIdentifier_PREFIX) {
457
+ let identifier = HKCharacteristicTypeIdentifier.init(rawValue: typeIdentifier)
458
+ if let type = HKObjectType.characteristicType(forIdentifier: identifier) as HKObjectType? {
459
+ return type
171
460
  }
172
461
  }
173
462
 
174
- return nil
463
+ if typeIdentifier == HKActivitySummaryTypeIdentifier {
464
+ return HKObjectType.activitySummaryType()
465
+ }
466
+
467
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed initializing unrecognized objectType identifier " + typeIdentifier)
175
468
  }
176
469
 
177
470
  func hkStatisticsOptionsFromOptions(_ options: NSArray) -> HKStatisticsOptions {
@@ -189,10 +482,6 @@ func hkStatisticsOptionsFromOptions(_ options: NSArray) -> HKStatisticsOptions {
189
482
  opts.insert(.discreteMax)
190
483
  case "discreteMin":
191
484
  opts.insert(.discreteMin)
192
- case "discreteMostRecent":
193
- if #available(iOS 12, *) {
194
- opts.insert(.discreteMostRecent)
195
- }
196
485
  case "duration":
197
486
  if #available(iOS 13, *) {
198
487
  opts.insert(.duration)
@@ -229,166 +518,151 @@ func componentsFromInterval(_ interval: NSDictionary) -> DateComponents {
229
518
  return intervalComponents
230
519
  }
231
520
 
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 {
521
+ func parseWorkoutConfiguration(_ config: WorkoutConfiguration) -> HKWorkoutConfiguration {
244
522
  let configuration = HKWorkoutConfiguration()
245
523
 
246
- if let activityTypeRaw = dict[HKWorkoutActivityTypePropertyName] as? UInt,
247
- let activityType = HKWorkoutActivityType(rawValue: activityTypeRaw) {
248
- configuration.activityType = activityType
524
+ if let activityType = HKWorkoutActivityType(rawValue: UInt(config.activityType.rawValue)) {
525
+ configuration.activityType = activityType
249
526
  }
250
527
 
251
- if let locationTypeRaw = dict[HKWorkoutSessionLocationTypePropertyName] as? Int,
252
- let locationType = HKWorkoutSessionLocationType(rawValue: locationTypeRaw) {
528
+ if let locationTypeRaw = config.locationType,
529
+ let locationType = HKWorkoutSessionLocationType(rawValue: Int(locationTypeRaw.rawValue)) {
253
530
  configuration.locationType = locationType
254
531
  }
255
532
 
256
533
  return configuration
257
534
  }
258
535
 
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
536
+ // Returns all available HKQuantityTypeIdentifier raw values as an array of String
537
+ func allQuantityTypeIdentifiers() -> [String] {
538
+ let allIdentifiers: [HKQuantityTypeIdentifier] = [
539
+ .bodyMassIndex,
540
+ .bodyFatPercentage,
541
+ .height,
542
+ .bodyMass,
543
+ .leanBodyMass,
544
+ .waistCircumference,
545
+ .stepCount,
546
+ .distanceWalkingRunning,
547
+ .distanceCycling,
548
+ .distanceWheelchair,
549
+ .basalEnergyBurned,
550
+ .activeEnergyBurned,
551
+ .flightsClimbed,
552
+ .nikeFuel,
553
+ .appleExerciseTime,
554
+ .pushCount,
555
+ .distanceSwimming,
556
+ .swimmingStrokeCount,
557
+ .vo2Max,
558
+ .distanceDownhillSnowSports,
559
+ .appleStandTime,
560
+ .walkingSpeed,
561
+ .walkingDoubleSupportPercentage,
562
+ .walkingAsymmetryPercentage,
563
+ .walkingStepLength,
564
+ .sixMinuteWalkTestDistance,
565
+ .stairAscentSpeed,
566
+ .stairDescentSpeed,
567
+ .heartRate,
568
+ .bodyTemperature,
569
+ .basalBodyTemperature,
570
+ .bloodPressureSystolic,
571
+ .bloodPressureDiastolic,
572
+ .respiratoryRate,
573
+ .restingHeartRate,
574
+ .walkingHeartRateAverage,
575
+ .heartRateVariabilitySDNN,
576
+ .oxygenSaturation,
577
+ .peripheralPerfusionIndex,
578
+ .bloodGlucose,
579
+ .numberOfTimesFallen,
580
+ .electrodermalActivity,
581
+ .inhalerUsage,
582
+ .insulinDelivery,
583
+ .bloodAlcoholContent,
584
+ .forcedVitalCapacity,
585
+ .forcedExpiratoryVolume1,
586
+ .peakExpiratoryFlowRate,
587
+ .environmentalAudioExposure,
588
+ .headphoneAudioExposure,
589
+ .dietaryFatTotal,
590
+ .dietaryFatPolyunsaturated,
591
+ .dietaryFatMonounsaturated,
592
+ .dietaryFatSaturated,
593
+ .dietaryCholesterol,
594
+ .dietarySodium,
595
+ .dietaryCarbohydrates,
596
+ .dietaryFiber,
597
+ .dietarySugar,
598
+ .dietaryEnergyConsumed,
599
+ .dietaryProtein,
600
+ .dietaryVitaminA,
601
+ .dietaryVitaminB6,
602
+ .dietaryVitaminB12,
603
+ .dietaryVitaminC,
604
+ .dietaryVitaminD,
605
+ .dietaryVitaminE,
606
+ .dietaryVitaminK,
607
+ .dietaryCalcium,
608
+ .dietaryIron,
609
+ .dietaryThiamin,
610
+ .dietaryRiboflavin,
611
+ .dietaryNiacin,
612
+ .dietaryFolate,
613
+ .dietaryBiotin,
614
+ .dietaryPantothenicAcid,
615
+ .dietaryPhosphorus,
616
+ .dietaryIodine,
617
+ .dietaryMagnesium,
618
+ .dietaryZinc,
619
+ .dietarySelenium,
620
+ .dietaryCopper,
621
+ .dietaryManganese,
622
+ .dietaryChromium,
623
+ .dietaryMolybdenum,
624
+ .dietaryChloride,
625
+ .dietaryPotassium,
626
+ .dietaryCaffeine,
627
+ .dietaryWater,
628
+ .uvExposure
629
+ // Add more identifiers as needed for your iOS version
338
630
  ]
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
631
+ let supported = allIdentifiers.compactMap { identifier in
632
+ HKObjectType.quantityType(forIdentifier: identifier) != nil ? identifier.rawValue : nil
633
+ }
634
+ let missing = allIdentifiers.filter { HKObjectType.quantityType(forIdentifier: $0) == nil }
635
+ if !missing.isEmpty {
636
+ print("[react-native-healthkit] Warning: The following HKQuantityTypeIdentifiers are not available on this iOS version: \(missing.map { $0.rawValue })")
637
+ }
638
+ // --- New logic: Warn if any available identifier is not in the hardcoded list ---
639
+ // Try common HealthKit identifier strings (brute-force, as Apple does not provide a list)
640
+ let knownPrefixes = [
641
+ "HKQuantityTypeIdentifier",
642
+ "HKQuantityTypeIdentifierDietary",
643
+ "HKQuantityTypeIdentifierEnvironmental",
644
+ "HKQuantityTypeIdentifierBlood",
645
+ "HKQuantityTypeIdentifierBody",
646
+ "HKQuantityTypeIdentifierDistance",
647
+ "HKQuantityTypeIdentifierHeart",
648
+ "HKQuantityTypeIdentifierRespiratory",
649
+ "HKQuantityTypeIdentifierWalking",
650
+ "HKQuantityTypeIdentifierSwimming",
651
+ "HKQuantityTypeIdentifierApple"
384
652
  ]
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
- }
653
+ var foundButNotListed: [String] = []
654
+ // Try all possible identifier strings (brute-force for demonstration, not exhaustive)
655
+ for codePoint in 0..<300 {
656
+ for prefix in knownPrefixes {
657
+ let candidate = prefix + String(codePoint)
658
+ if let type = HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier(rawValue: candidate)),
659
+ !allIdentifiers.contains(where: { $0.rawValue == candidate }) {
660
+ foundButNotListed.append(candidate)
661
+ }
662
+ }
663
+ }
664
+ if !foundButNotListed.isEmpty {
665
+ print("[react-native-healthkit] Warning: The following HKQuantityTypeIdentifiers are available on this iOS version but NOT included in the hardcoded list: \(foundButNotListed)")
666
+ }
667
+ return supported
393
668
  }
394
- #endif