@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.
- package/ReactNativeHealthkit.podspec +36 -0
- package/app.plugin.js +43 -33
- package/ios/Bridge.h +8 -0
- package/ios/CategoryTypeModule.swift +128 -0
- package/ios/CharacteristicTypeModule.swift +78 -0
- package/ios/Constants.swift +2 -0
- package/ios/CoreModule.swift +376 -0
- package/ios/CorrelationTypeModule.swift +153 -0
- package/ios/HeartbeatSeriesModule.swift +189 -0
- package/ios/Helpers.swift +529 -251
- package/ios/QuantityTypeModule.swift +461 -0
- package/ios/Serializers.swift +211 -124
- package/ios/SourceProxy.swift +35 -0
- package/ios/StateOfMindModule.swift +160 -0
- package/ios/WorkoutProxy.swift +405 -0
- package/ios/WorkoutSessionModule.swift +182 -0
- package/ios/WorkoutsModule.swift +357 -0
- package/package.json +43 -127
- package/react-native.config.js +16 -0
- package/src/hooks/useHealthkitAuthorization.test.ts +47 -29
- package/src/hooks/useHealthkitAuthorization.ts +21 -15
- package/src/hooks/useIsHealthDataAvailable.test.ts +17 -7
- package/src/hooks/useIsHealthDataAvailable.ts +7 -7
- package/src/hooks/useMostRecentCategorySample.ts +10 -12
- package/src/hooks/useMostRecentQuantitySample.ts +17 -36
- package/src/hooks/useMostRecentWorkout.ts +16 -38
- package/src/hooks/useSources.ts +8 -12
- package/src/hooks/useStatisticsForQuantity.ts +19 -14
- package/src/hooks/useSubscribeToChanges.ts +9 -13
- package/src/index.ios.ts +232 -0
- package/src/index.ts +444 -0
- package/src/modules.ts +43 -0
- package/src/specs/CategoryTypeModule.nitro.ts +64 -0
- package/src/specs/CharacteristicTypeModule.nitro.ts +22 -0
- package/src/specs/CoreModule.nitro.ts +107 -0
- package/src/specs/CorrelationTypeModule.nitro.ts +23 -0
- package/src/specs/HeartbeatSeriesModule.nitro.ts +19 -0
- package/src/specs/QuantityTypeModule.nitro.ts +60 -0
- package/src/specs/SourceProxy.nitro.ts +13 -0
- package/src/specs/StateOfMindModule.nitro.ts +23 -0
- package/src/specs/WorkoutProxy.nitro.ts +18 -0
- package/src/specs/WorkoutSessionModule.nitro.ts +71 -0
- package/src/specs/WorkoutsModule.nitro.ts +32 -0
- package/src/test-setup.ts +68 -54
- package/src/test-utils.ts +3 -2
- package/src/types/Auth.ts +17 -0
- package/src/types/Background.ts +9 -0
- package/src/types/CategoryType.ts +249 -0
- package/src/types/CategoryTypeIdentifier.ts +99 -0
- package/src/types/Characteristics.ts +53 -0
- package/src/types/Constants.ts +25 -0
- package/src/types/CorrelationType.ts +31 -0
- package/src/types/Device.ts +13 -0
- package/src/types/HeartbeatSeries.ts +29 -0
- package/src/types/InterfaceVerification.ts +164 -0
- package/src/types/InterfaceVerificationExample.ts +89 -0
- package/src/types/QuantitySample.ts +30 -0
- package/src/types/QuantityType.ts +192 -0
- package/src/types/QuantityTypeIdentifier.ts +758 -0
- package/src/types/QueryOptions.ts +69 -0
- package/src/types/README-InterfaceVerification.md +103 -0
- package/src/types/Shared.ts +79 -0
- package/src/types/Source.ts +11 -0
- package/src/types/StateOfMind.ts +110 -0
- package/src/types/Subscriptons.ts +10 -0
- package/src/types/Units.ts +190 -0
- package/src/types/WeatherCondition.ts +31 -0
- package/src/types/WorkoutKit.ts +18 -0
- package/src/types/Workouts.ts +282 -0
- package/src/utils/getMostRecentCategorySample.ts +7 -11
- package/src/utils/getMostRecentQuantitySample.ts +8 -18
- package/src/utils/getMostRecentWorkout.ts +7 -17
- package/src/utils/getPreferredUnit.ts +12 -8
- package/src/utils/subscribeToChanges.ts +9 -26
- package/LICENSE +0 -21
- package/README.md +0 -179
- package/ios/ReactNativeHealthkit-Bridging-Header.h +0 -2
- package/ios/ReactNativeHealthkit.m +0 -271
- package/ios/ReactNativeHealthkit.swift +0 -2333
- package/ios/ReactNativeHealthkit.xcodeproj/project.pbxproj +0 -279
- package/kingstinct-react-native-healthkit.podspec +0 -21
- package/lib/commonjs/hooks/useHealthkitAuthorization.js +0 -39
- package/lib/commonjs/hooks/useHealthkitAuthorization.js.map +0 -1
- package/lib/commonjs/hooks/useHealthkitAuthorization.test.js +0 -72
- package/lib/commonjs/hooks/useHealthkitAuthorization.test.js.map +0 -1
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js +0 -27
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js.map +0 -1
- package/lib/commonjs/hooks/useIsHealthDataAvailable.test.js +0 -41
- package/lib/commonjs/hooks/useIsHealthDataAvailable.test.js.map +0 -1
- package/lib/commonjs/hooks/useMostRecentCategorySample.js +0 -23
- package/lib/commonjs/hooks/useMostRecentCategorySample.js.map +0 -1
- package/lib/commonjs/hooks/useMostRecentQuantitySample.js +0 -37
- package/lib/commonjs/hooks/useMostRecentQuantitySample.js.map +0 -1
- package/lib/commonjs/hooks/useMostRecentWorkout.js +0 -48
- package/lib/commonjs/hooks/useMostRecentWorkout.js.map +0 -1
- package/lib/commonjs/hooks/useSources.js +0 -22
- package/lib/commonjs/hooks/useSources.js.map +0 -1
- package/lib/commonjs/hooks/useStatisticsForQuantity.js +0 -28
- package/lib/commonjs/hooks/useStatisticsForQuantity.js.map +0 -1
- package/lib/commonjs/hooks/useSubscribeToChanges.js +0 -28
- package/lib/commonjs/hooks/useSubscribeToChanges.js.map +0 -1
- package/lib/commonjs/index.ios.js +0 -531
- package/lib/commonjs/index.ios.js.map +0 -1
- package/lib/commonjs/index.js +0 -22
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/index.native.js +0 -235
- package/lib/commonjs/index.native.js.map +0 -1
- package/lib/commonjs/index.web.js +0 -22
- package/lib/commonjs/index.web.js.map +0 -1
- package/lib/commonjs/native-types.js +0 -1575
- package/lib/commonjs/native-types.js.map +0 -1
- package/lib/commonjs/test-setup.js +0 -57
- package/lib/commonjs/test-setup.js.map +0 -1
- package/lib/commonjs/test-utils.js +0 -18
- package/lib/commonjs/test-utils.js.map +0 -1
- package/lib/commonjs/types.js +0 -17
- package/lib/commonjs/types.js.map +0 -1
- package/lib/commonjs/utils/deleteQuantitySample.js +0 -11
- package/lib/commonjs/utils/deleteQuantitySample.js.map +0 -1
- package/lib/commonjs/utils/deleteSamples.js +0 -18
- package/lib/commonjs/utils/deleteSamples.js.map +0 -1
- package/lib/commonjs/utils/deleteWorkoutSample.js +0 -11
- package/lib/commonjs/utils/deleteWorkoutSample.js.map +0 -1
- package/lib/commonjs/utils/deserializeCategorySample.js +0 -13
- package/lib/commonjs/utils/deserializeCategorySample.js.map +0 -1
- package/lib/commonjs/utils/deserializeCategorySample.test.js +0 -26
- package/lib/commonjs/utils/deserializeCategorySample.test.js.map +0 -1
- package/lib/commonjs/utils/deserializeCorrelation.js +0 -26
- package/lib/commonjs/utils/deserializeCorrelation.js.map +0 -1
- package/lib/commonjs/utils/deserializeHeartbeatSeriesSample.js +0 -15
- package/lib/commonjs/utils/deserializeHeartbeatSeriesSample.js.map +0 -1
- package/lib/commonjs/utils/deserializeSample.js +0 -15
- package/lib/commonjs/utils/deserializeSample.js.map +0 -1
- package/lib/commonjs/utils/deserializeWorkout.js +0 -15
- package/lib/commonjs/utils/deserializeWorkout.js.map +0 -1
- package/lib/commonjs/utils/ensureMetadata.js +0 -11
- package/lib/commonjs/utils/ensureMetadata.js.map +0 -1
- package/lib/commonjs/utils/ensureTotals.js +0 -11
- package/lib/commonjs/utils/ensureTotals.js.map +0 -1
- package/lib/commonjs/utils/ensureUnit.js +0 -17
- package/lib/commonjs/utils/ensureUnit.js.map +0 -1
- package/lib/commonjs/utils/getDateOfBirth.js +0 -14
- package/lib/commonjs/utils/getDateOfBirth.js.map +0 -1
- package/lib/commonjs/utils/getMostRecentCategorySample.js +0 -17
- package/lib/commonjs/utils/getMostRecentCategorySample.js.map +0 -1
- package/lib/commonjs/utils/getMostRecentQuantitySample.js +0 -21
- package/lib/commonjs/utils/getMostRecentQuantitySample.js.map +0 -1
- package/lib/commonjs/utils/getMostRecentWorkout.js +0 -19
- package/lib/commonjs/utils/getMostRecentWorkout.js.map +0 -1
- package/lib/commonjs/utils/getPreferredUnit.js +0 -14
- package/lib/commonjs/utils/getPreferredUnit.js.map +0 -1
- package/lib/commonjs/utils/getPreferredUnits.js +0 -14
- package/lib/commonjs/utils/getPreferredUnits.js.map +0 -1
- package/lib/commonjs/utils/getPreferredUnitsTyped.js +0 -33
- package/lib/commonjs/utils/getPreferredUnitsTyped.js.map +0 -1
- package/lib/commonjs/utils/getRequestStatusForAuthorization.js +0 -21
- package/lib/commonjs/utils/getRequestStatusForAuthorization.js.map +0 -1
- package/lib/commonjs/utils/getWorkoutPlanById.js +0 -13
- package/lib/commonjs/utils/getWorkoutPlanById.js.map +0 -1
- package/lib/commonjs/utils/prepareOptions.js +0 -25
- package/lib/commonjs/utils/prepareOptions.js.map +0 -1
- package/lib/commonjs/utils/queryCategorySamples.js +0 -17
- package/lib/commonjs/utils/queryCategorySamples.js.map +0 -1
- package/lib/commonjs/utils/queryCategorySamplesWithAnchor.js +0 -21
- package/lib/commonjs/utils/queryCategorySamplesWithAnchor.js.map +0 -1
- package/lib/commonjs/utils/queryCorrelationSamples.js +0 -17
- package/lib/commonjs/utils/queryCorrelationSamples.js.map +0 -1
- package/lib/commonjs/utils/queryHeartbeatSeriesSamples.js +0 -17
- package/lib/commonjs/utils/queryHeartbeatSeriesSamples.js.map +0 -1
- package/lib/commonjs/utils/queryHeartbeatSeriesSamplesWithAnchor.js +0 -21
- package/lib/commonjs/utils/queryHeartbeatSeriesSamplesWithAnchor.js.map +0 -1
- package/lib/commonjs/utils/queryQuantitySamples.js +0 -19
- package/lib/commonjs/utils/queryQuantitySamples.js.map +0 -1
- package/lib/commonjs/utils/queryQuantitySamplesWithAnchor.js +0 -23
- package/lib/commonjs/utils/queryQuantitySamplesWithAnchor.js.map +0 -1
- package/lib/commonjs/utils/querySources.js +0 -14
- package/lib/commonjs/utils/querySources.js.map +0 -1
- package/lib/commonjs/utils/queryStateOfMindSamples.js +0 -22
- package/lib/commonjs/utils/queryStateOfMindSamples.js.map +0 -1
- package/lib/commonjs/utils/queryStatisticsCollectionForQuantity.js +0 -16
- package/lib/commonjs/utils/queryStatisticsCollectionForQuantity.js.map +0 -1
- package/lib/commonjs/utils/queryStatisticsForQuantity.js +0 -29
- package/lib/commonjs/utils/queryStatisticsForQuantity.js.map +0 -1
- package/lib/commonjs/utils/queryWorkoutSamplesWithAnchor.js +0 -26
- package/lib/commonjs/utils/queryWorkoutSamplesWithAnchor.js.map +0 -1
- package/lib/commonjs/utils/queryWorkouts.js +0 -22
- package/lib/commonjs/utils/queryWorkouts.js.map +0 -1
- package/lib/commonjs/utils/requestAuthorization.js +0 -22
- package/lib/commonjs/utils/requestAuthorization.js.map +0 -1
- package/lib/commonjs/utils/saveCategorySample.js +0 -20
- package/lib/commonjs/utils/saveCategorySample.js.map +0 -1
- package/lib/commonjs/utils/saveCorrelationSample.js +0 -35
- package/lib/commonjs/utils/saveCorrelationSample.js.map +0 -1
- package/lib/commonjs/utils/saveQuantitySample.js +0 -16
- package/lib/commonjs/utils/saveQuantitySample.js.map +0 -1
- package/lib/commonjs/utils/saveStateOfMindSample.js +0 -17
- package/lib/commonjs/utils/saveStateOfMindSample.js.map +0 -1
- package/lib/commonjs/utils/saveWorkoutRoute.js +0 -26
- package/lib/commonjs/utils/saveWorkoutRoute.js.map +0 -1
- package/lib/commonjs/utils/saveWorkoutSample.js +0 -36
- package/lib/commonjs/utils/saveWorkoutSample.js.map +0 -1
- package/lib/commonjs/utils/serializeDate.js +0 -9
- package/lib/commonjs/utils/serializeDate.js.map +0 -1
- package/lib/commonjs/utils/serializeDate.test.js +0 -17
- package/lib/commonjs/utils/serializeDate.test.js.map +0 -1
- package/lib/commonjs/utils/startWatchApp.js +0 -11
- package/lib/commonjs/utils/startWatchApp.js.map +0 -1
- package/lib/commonjs/utils/subscribeToChanges.js +0 -27
- package/lib/commonjs/utils/subscribeToChanges.js.map +0 -1
- package/lib/module/hooks/useHealthkitAuthorization.js +0 -32
- package/lib/module/hooks/useHealthkitAuthorization.js.map +0 -1
- package/lib/module/hooks/useHealthkitAuthorization.test.js +0 -68
- package/lib/module/hooks/useHealthkitAuthorization.test.js.map +0 -1
- package/lib/module/hooks/useIsHealthDataAvailable.js +0 -21
- package/lib/module/hooks/useIsHealthDataAvailable.js.map +0 -1
- package/lib/module/hooks/useIsHealthDataAvailable.test.js +0 -37
- package/lib/module/hooks/useIsHealthDataAvailable.test.js.map +0 -1
- package/lib/module/hooks/useMostRecentCategorySample.js +0 -16
- package/lib/module/hooks/useMostRecentCategorySample.js.map +0 -1
- package/lib/module/hooks/useMostRecentQuantitySample.js +0 -30
- package/lib/module/hooks/useMostRecentQuantitySample.js.map +0 -1
- package/lib/module/hooks/useMostRecentWorkout.js +0 -41
- package/lib/module/hooks/useMostRecentWorkout.js.map +0 -1
- package/lib/module/hooks/useSources.js +0 -15
- package/lib/module/hooks/useSources.js.map +0 -1
- package/lib/module/hooks/useStatisticsForQuantity.js +0 -21
- package/lib/module/hooks/useStatisticsForQuantity.js.map +0 -1
- package/lib/module/hooks/useSubscribeToChanges.js +0 -21
- package/lib/module/hooks/useSubscribeToChanges.js.map +0 -1
- package/lib/module/index.ios.js +0 -209
- package/lib/module/index.ios.js.map +0 -1
- package/lib/module/index.js +0 -4
- package/lib/module/index.js.map +0 -1
- package/lib/module/index.native.js +0 -160
- package/lib/module/index.native.js.map +0 -1
- package/lib/module/index.web.js +0 -4
- package/lib/module/index.web.js.map +0 -1
- package/lib/module/native-types.js +0 -1606
- package/lib/module/native-types.js.map +0 -1
- package/lib/module/test-setup.js +0 -54
- package/lib/module/test-setup.js.map +0 -1
- package/lib/module/test-utils.js +0 -11
- package/lib/module/test-utils.js.map +0 -1
- package/lib/module/types.js +0 -67
- package/lib/module/types.js.map +0 -1
- package/lib/module/utils/deleteQuantitySample.js +0 -4
- package/lib/module/utils/deleteQuantitySample.js.map +0 -1
- package/lib/module/utils/deleteSamples.js +0 -11
- package/lib/module/utils/deleteSamples.js.map +0 -1
- package/lib/module/utils/deleteWorkoutSample.js +0 -4
- package/lib/module/utils/deleteWorkoutSample.js.map +0 -1
- package/lib/module/utils/deserializeCategorySample.js +0 -7
- package/lib/module/utils/deserializeCategorySample.js.map +0 -1
- package/lib/module/utils/deserializeCategorySample.test.js +0 -22
- package/lib/module/utils/deserializeCategorySample.test.js.map +0 -1
- package/lib/module/utils/deserializeCorrelation.js +0 -19
- package/lib/module/utils/deserializeCorrelation.js.map +0 -1
- package/lib/module/utils/deserializeHeartbeatSeriesSample.js +0 -9
- package/lib/module/utils/deserializeHeartbeatSeriesSample.js.map +0 -1
- package/lib/module/utils/deserializeSample.js +0 -9
- package/lib/module/utils/deserializeSample.js.map +0 -1
- package/lib/module/utils/deserializeWorkout.js +0 -9
- package/lib/module/utils/deserializeWorkout.js.map +0 -1
- package/lib/module/utils/ensureMetadata.js +0 -5
- package/lib/module/utils/ensureMetadata.js.map +0 -1
- package/lib/module/utils/ensureTotals.js +0 -5
- package/lib/module/utils/ensureTotals.js.map +0 -1
- package/lib/module/utils/ensureUnit.js +0 -10
- package/lib/module/utils/ensureUnit.js.map +0 -1
- package/lib/module/utils/getDateOfBirth.js +0 -7
- package/lib/module/utils/getDateOfBirth.js.map +0 -1
- package/lib/module/utils/getMostRecentCategorySample.js +0 -10
- package/lib/module/utils/getMostRecentCategorySample.js.map +0 -1
- package/lib/module/utils/getMostRecentQuantitySample.js +0 -14
- package/lib/module/utils/getMostRecentQuantitySample.js.map +0 -1
- package/lib/module/utils/getMostRecentWorkout.js +0 -12
- package/lib/module/utils/getMostRecentWorkout.js.map +0 -1
- package/lib/module/utils/getPreferredUnit.js +0 -7
- package/lib/module/utils/getPreferredUnit.js.map +0 -1
- package/lib/module/utils/getPreferredUnits.js +0 -7
- package/lib/module/utils/getPreferredUnits.js.map +0 -1
- package/lib/module/utils/getPreferredUnitsTyped.js +0 -26
- package/lib/module/utils/getPreferredUnitsTyped.js.map +0 -1
- package/lib/module/utils/getRequestStatusForAuthorization.js +0 -14
- package/lib/module/utils/getRequestStatusForAuthorization.js.map +0 -1
- package/lib/module/utils/getWorkoutPlanById.js +0 -6
- package/lib/module/utils/getWorkoutPlanById.js.map +0 -1
- package/lib/module/utils/prepareOptions.js +0 -18
- package/lib/module/utils/prepareOptions.js.map +0 -1
- package/lib/module/utils/queryCategorySamples.js +0 -10
- package/lib/module/utils/queryCategorySamples.js.map +0 -1
- package/lib/module/utils/queryCategorySamplesWithAnchor.js +0 -14
- package/lib/module/utils/queryCategorySamplesWithAnchor.js.map +0 -1
- package/lib/module/utils/queryCorrelationSamples.js +0 -10
- package/lib/module/utils/queryCorrelationSamples.js.map +0 -1
- package/lib/module/utils/queryHeartbeatSeriesSamples.js +0 -10
- package/lib/module/utils/queryHeartbeatSeriesSamples.js.map +0 -1
- package/lib/module/utils/queryHeartbeatSeriesSamplesWithAnchor.js +0 -14
- package/lib/module/utils/queryHeartbeatSeriesSamplesWithAnchor.js.map +0 -1
- package/lib/module/utils/queryQuantitySamples.js +0 -12
- package/lib/module/utils/queryQuantitySamples.js.map +0 -1
- package/lib/module/utils/queryQuantitySamplesWithAnchor.js +0 -16
- package/lib/module/utils/queryQuantitySamplesWithAnchor.js.map +0 -1
- package/lib/module/utils/querySources.js +0 -7
- package/lib/module/utils/querySources.js.map +0 -1
- package/lib/module/utils/queryStateOfMindSamples.js +0 -14
- package/lib/module/utils/queryStateOfMindSamples.js.map +0 -1
- package/lib/module/utils/queryStatisticsCollectionForQuantity.js +0 -9
- package/lib/module/utils/queryStatisticsCollectionForQuantity.js.map +0 -1
- package/lib/module/utils/queryStatisticsForQuantity.js +0 -22
- package/lib/module/utils/queryStatisticsForQuantity.js.map +0 -1
- package/lib/module/utils/queryWorkoutSamplesWithAnchor.js +0 -19
- package/lib/module/utils/queryWorkoutSamplesWithAnchor.js.map +0 -1
- package/lib/module/utils/queryWorkouts.js +0 -15
- package/lib/module/utils/queryWorkouts.js.map +0 -1
- package/lib/module/utils/requestAuthorization.js +0 -15
- package/lib/module/utils/requestAuthorization.js.map +0 -1
- package/lib/module/utils/saveCategorySample.js +0 -13
- package/lib/module/utils/saveCategorySample.js.map +0 -1
- package/lib/module/utils/saveCorrelationSample.js +0 -28
- package/lib/module/utils/saveCorrelationSample.js.map +0 -1
- package/lib/module/utils/saveQuantitySample.js +0 -9
- package/lib/module/utils/saveQuantitySample.js.map +0 -1
- package/lib/module/utils/saveStateOfMindSample.js +0 -10
- package/lib/module/utils/saveStateOfMindSample.js.map +0 -1
- package/lib/module/utils/saveWorkoutRoute.js +0 -19
- package/lib/module/utils/saveWorkoutRoute.js.map +0 -1
- package/lib/module/utils/saveWorkoutSample.js +0 -29
- package/lib/module/utils/saveWorkoutSample.js.map +0 -1
- package/lib/module/utils/serializeDate.js +0 -3
- package/lib/module/utils/serializeDate.js.map +0 -1
- package/lib/module/utils/serializeDate.test.js +0 -14
- package/lib/module/utils/serializeDate.test.js.map +0 -1
- package/lib/module/utils/startWatchApp.js +0 -4
- package/lib/module/utils/startWatchApp.js.map +0 -1
- package/lib/module/utils/subscribeToChanges.js +0 -20
- package/lib/module/utils/subscribeToChanges.js.map +0 -1
- package/lib/typescript/example-expo/App.d.ts +0 -2
- package/lib/typescript/src/hooks/useHealthkitAuthorization.d.ts +0 -8
- package/lib/typescript/src/hooks/useHealthkitAuthorization.test.d.ts +0 -1
- package/lib/typescript/src/hooks/useIsHealthDataAvailable.d.ts +0 -7
- package/lib/typescript/src/hooks/useIsHealthDataAvailable.test.d.ts +0 -1
- package/lib/typescript/src/hooks/useMostRecentCategorySample.d.ts +0 -7
- package/lib/typescript/src/hooks/useMostRecentQuantitySample.d.ts +0 -7
- package/lib/typescript/src/hooks/useMostRecentWorkout.d.ts +0 -10
- package/lib/typescript/src/hooks/useSources.d.ts +0 -3
- package/lib/typescript/src/hooks/useStatisticsForQuantity.d.ts +0 -4
- package/lib/typescript/src/hooks/useSubscribeToChanges.d.ts +0 -3
- package/lib/typescript/src/index.d.ts +0 -3
- package/lib/typescript/src/index.ios.d.ts +0 -198
- package/lib/typescript/src/index.native.d.ts +0 -41
- package/lib/typescript/src/index.web.d.ts +0 -3
- package/lib/typescript/src/native-types.d.ts +0 -1764
- package/lib/typescript/src/test-setup.d.ts +0 -1
- package/lib/typescript/src/test-utils.d.ts +0 -2
- package/lib/typescript/src/types.d.ts +0 -111
- package/lib/typescript/src/utils/deleteQuantitySample.d.ts +0 -4
- package/lib/typescript/src/utils/deleteSamples.d.ts +0 -8
- package/lib/typescript/src/utils/deleteWorkoutSample.d.ts +0 -3
- package/lib/typescript/src/utils/deserializeCategorySample.d.ts +0 -4
- package/lib/typescript/src/utils/deserializeCategorySample.test.d.ts +0 -1
- package/lib/typescript/src/utils/deserializeCorrelation.d.ts +0 -4
- package/lib/typescript/src/utils/deserializeHeartbeatSeriesSample.d.ts +0 -4
- package/lib/typescript/src/utils/deserializeSample.d.ts +0 -4
- package/lib/typescript/src/utils/deserializeWorkout.d.ts +0 -4
- package/lib/typescript/src/utils/ensureMetadata.d.ts +0 -2
- package/lib/typescript/src/utils/ensureTotals.d.ts +0 -2
- package/lib/typescript/src/utils/ensureUnit.d.ts +0 -3
- package/lib/typescript/src/utils/getDateOfBirth.d.ts +0 -2
- package/lib/typescript/src/utils/getMostRecentCategorySample.d.ts +0 -4
- package/lib/typescript/src/utils/getMostRecentQuantitySample.d.ts +0 -4
- package/lib/typescript/src/utils/getMostRecentWorkout.d.ts +0 -5
- package/lib/typescript/src/utils/getPreferredUnit.d.ts +0 -4
- package/lib/typescript/src/utils/getPreferredUnits.d.ts +0 -4
- package/lib/typescript/src/utils/getPreferredUnitsTyped.d.ts +0 -9
- package/lib/typescript/src/utils/getRequestStatusForAuthorization.d.ts +0 -3
- package/lib/typescript/src/utils/getWorkoutPlanById.d.ts +0 -5
- package/lib/typescript/src/utils/prepareOptions.d.ts +0 -9
- package/lib/typescript/src/utils/queryCategorySamples.d.ts +0 -5
- package/lib/typescript/src/utils/queryCategorySamplesWithAnchor.d.ts +0 -10
- package/lib/typescript/src/utils/queryCorrelationSamples.d.ts +0 -5
- package/lib/typescript/src/utils/queryHeartbeatSeriesSamples.d.ts +0 -10
- package/lib/typescript/src/utils/queryHeartbeatSeriesSamplesWithAnchor.d.ts +0 -10
- package/lib/typescript/src/utils/queryQuantitySamples.d.ts +0 -7
- package/lib/typescript/src/utils/queryQuantitySamplesWithAnchor.d.ts +0 -12
- package/lib/typescript/src/utils/querySources.d.ts +0 -4
- package/lib/typescript/src/utils/queryStateOfMindSamples.d.ts +0 -7
- package/lib/typescript/src/utils/queryStatisticsCollectionForQuantity.d.ts +0 -3
- package/lib/typescript/src/utils/queryStatisticsForQuantity.d.ts +0 -14
- package/lib/typescript/src/utils/queryWorkoutSamplesWithAnchor.d.ts +0 -9
- package/lib/typescript/src/utils/queryWorkouts.d.ts +0 -4
- package/lib/typescript/src/utils/requestAuthorization.d.ts +0 -4
- package/lib/typescript/src/utils/saveCategorySample.d.ts +0 -11
- package/lib/typescript/src/utils/saveCorrelationSample.d.ts +0 -8
- package/lib/typescript/src/utils/saveQuantitySample.d.ts +0 -7
- package/lib/typescript/src/utils/saveStateOfMindSample.d.ts +0 -11
- package/lib/typescript/src/utils/saveWorkoutRoute.d.ts +0 -3
- package/lib/typescript/src/utils/saveWorkoutSample.d.ts +0 -11
- package/lib/typescript/src/utils/serializeDate.d.ts +0 -2
- package/lib/typescript/src/utils/serializeDate.test.d.ts +0 -1
- package/lib/typescript/src/utils/startWatchApp.d.ts +0 -3
- package/lib/typescript/src/utils/subscribeToChanges.d.ts +0 -3
- package/src/index.ios.tsx +0 -292
- package/src/index.native.tsx +0 -233
- package/src/index.tsx +0 -5
- package/src/index.web.tsx +0 -5
- package/src/native-types.ts +0 -2471
- package/src/types.ts +0 -156
- package/src/utils/deleteQuantitySample.ts +0 -14
- package/src/utils/deleteSamples.ts +0 -23
- package/src/utils/deleteWorkoutSample.ts +0 -7
- package/src/utils/deserializeCategorySample.test.ts +0 -24
- package/src/utils/deserializeCategorySample.ts +0 -12
- package/src/utils/deserializeCorrelation.ts +0 -28
- package/src/utils/deserializeHeartbeatSeriesSample.ts +0 -12
- package/src/utils/deserializeSample.ts +0 -17
- package/src/utils/deserializeWorkout.ts +0 -14
- package/src/utils/ensureMetadata.ts +0 -5
- package/src/utils/ensureTotals.ts +0 -5
- package/src/utils/ensureUnit.ts +0 -19
- package/src/utils/getDateOfBirth.ts +0 -8
- package/src/utils/getPreferredUnits.ts +0 -14
- package/src/utils/getPreferredUnitsTyped.ts +0 -38
- package/src/utils/getRequestStatusForAuthorization.ts +0 -21
- package/src/utils/getWorkoutPlanById.ts +0 -7
- package/src/utils/prepareOptions.ts +0 -19
- package/src/utils/queryCategorySamples.ts +0 -29
- package/src/utils/queryCategorySamplesWithAnchor.ts +0 -39
- package/src/utils/queryCorrelationSamples.ts +0 -29
- package/src/utils/queryHeartbeatSeriesSamples.ts +0 -29
- package/src/utils/queryHeartbeatSeriesSamplesWithAnchor.ts +0 -33
- package/src/utils/queryQuantitySamples.ts +0 -38
- package/src/utils/queryQuantitySamplesWithAnchor.ts +0 -46
- package/src/utils/querySources.ts +0 -21
- package/src/utils/queryStateOfMindSamples.ts +0 -14
- package/src/utils/queryStatisticsCollectionForQuantity.ts +0 -38
- package/src/utils/queryStatisticsForQuantity.ts +0 -38
- package/src/utils/queryWorkoutSamplesWithAnchor.ts +0 -46
- package/src/utils/queryWorkouts.ts +0 -28
- package/src/utils/requestAuthorization.ts +0 -19
- package/src/utils/saveCategorySample.ts +0 -31
- package/src/utils/saveCorrelationSample.ts +0 -43
- package/src/utils/saveQuantitySample.ts +0 -29
- package/src/utils/saveStateOfMindSample.ts +0 -38
- package/src/utils/saveWorkoutRoute.ts +0 -21
- package/src/utils/saveWorkoutSample.ts +0 -42
- package/src/utils/serializeDate.test.ts +0 -16
- package/src/utils/serializeDate.ts +0 -5
- package/src/utils/startWatchApp.ts +0 -7
package/ios/Serializers.swift
CHANGED
|
@@ -7,174 +7,281 @@
|
|
|
7
7
|
|
|
8
8
|
import Foundation
|
|
9
9
|
import HealthKit
|
|
10
|
+
import NitroModules
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
func serializeQuantity(unit: HKUnit, quantity: HKQuantity?) -> [String: Any]? {
|
|
14
|
-
guard let q = quantity else {
|
|
12
|
+
func serializeQuantityTyped(unit: HKUnit, quantityNullable: HKQuantity?) -> Quantity? {
|
|
13
|
+
guard let q = quantityNullable else {
|
|
15
14
|
return nil
|
|
16
15
|
}
|
|
16
|
+
|
|
17
|
+
return Quantity(
|
|
18
|
+
unit: unit.unitString,
|
|
19
|
+
quantity: q.doubleValue(for: unit)
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func serializeQuantityTyped(unit: HKUnit, quantity: HKQuantity) -> Quantity {
|
|
24
|
+
return Quantity(
|
|
25
|
+
unit: unit.unitString,
|
|
26
|
+
quantity: quantity.doubleValue(for: unit)
|
|
27
|
+
)
|
|
28
|
+
}
|
|
17
29
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
func serializeQuantitySample(sample: HKQuantitySample, unit: HKUnit) throws -> QuantitySample {
|
|
31
|
+
if let quantityType = QuantityTypeIdentifier(fromString: sample.quantityType.identifier) {
|
|
32
|
+
return QuantitySample(
|
|
33
|
+
uuid: sample.uuid.uuidString,
|
|
34
|
+
device: serializeDevice(hkDevice: sample.device),
|
|
35
|
+
quantityType: quantityType,
|
|
36
|
+
startDate: sample.startDate,
|
|
37
|
+
endDate: sample.endDate,
|
|
38
|
+
quantity: sample.quantity.doubleValue(for: unit),
|
|
39
|
+
unit: unit.unitString,
|
|
40
|
+
metadata: serializeMetadata(sample.metadata),
|
|
41
|
+
sourceRevision: serializeSourceRevision(sample.sourceRevision),
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
throw RuntimeError.error(withMessage: "[react-native-healthkit] Unable to recognize quantityType: \(sample.quantityType.identifier)")
|
|
22
45
|
}
|
|
23
46
|
|
|
24
|
-
func
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return [
|
|
31
|
-
"uuid": sample.uuid.uuidString,
|
|
32
|
-
"device": serializeDevice(_device: sample.device) as Any,
|
|
33
|
-
"quantityType": sample.quantityType.identifier,
|
|
34
|
-
"endDate": endDate,
|
|
35
|
-
"startDate": startDate,
|
|
36
|
-
"quantity": quantity,
|
|
37
|
-
"unit": unit.unitString,
|
|
38
|
-
"metadata": serializeMetadata(metadata: sample.metadata),
|
|
39
|
-
"sourceRevision": serializeSourceRevision(_sourceRevision: sample.sourceRevision) as Any
|
|
40
|
-
]
|
|
47
|
+
func serializeDeletedSample(sample: HKDeletedObject) -> DeletedSample {
|
|
48
|
+
return DeletedSample(
|
|
49
|
+
uuid: sample.uuid.uuidString,
|
|
50
|
+
metadata: serializeMetadata(sample.metadata)
|
|
51
|
+
)
|
|
41
52
|
}
|
|
42
53
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
54
|
+
|
|
55
|
+
func serializeCategorySample(sample: HKCategorySample) -> CategorySample {
|
|
56
|
+
return CategorySample(
|
|
57
|
+
uuid: sample.uuid.uuidString,
|
|
58
|
+
device: serializeDevice(hkDevice: sample.device),
|
|
59
|
+
categoryType: CategoryTypeIdentifier(fromString: sample.categoryType.identifier)!,
|
|
60
|
+
startDate: sample.startDate,
|
|
61
|
+
endDate: sample.endDate,
|
|
62
|
+
value: Double(sample.value),
|
|
63
|
+
metadata: serializeMetadata(sample.metadata),
|
|
64
|
+
sourceRevision: serializeSourceRevision(sample.sourceRevision)
|
|
65
|
+
)
|
|
48
66
|
}
|
|
49
67
|
|
|
50
|
-
func
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return [
|
|
55
|
-
"uuid": sample.uuid.uuidString,
|
|
56
|
-
"device": serializeDevice(_device: sample.device) as Any,
|
|
57
|
-
"categoryType": sample.categoryType.identifier,
|
|
58
|
-
"endDate": endDate,
|
|
59
|
-
"startDate": startDate,
|
|
60
|
-
"value": sample.value,
|
|
61
|
-
"metadata": serializeMetadata(metadata: sample.metadata),
|
|
62
|
-
"sourceRevision": serializeSourceRevision(_sourceRevision: sample.sourceRevision) as Any
|
|
63
|
-
]
|
|
68
|
+
func serializeSource(_ source: HKSource) -> SourceProxy {
|
|
69
|
+
return SourceProxy(
|
|
70
|
+
source: source
|
|
71
|
+
)
|
|
64
72
|
}
|
|
65
73
|
|
|
66
|
-
func serializeSource(source: HKSource) -> NSDictionary {
|
|
67
74
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
func getUnitForQuantityType(quantityType: HKQuantityType) -> HKUnit? {
|
|
76
|
+
if quantityType.is(compatibleWith: HKUnit.percent()) {
|
|
77
|
+
return HKUnit.percent()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if quantityType.is(compatibleWith: HKUnit.second()) {
|
|
81
|
+
return HKUnit.second()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if quantityType.is(compatibleWith: HKUnit.kilocalorie()) {
|
|
85
|
+
return HKUnit.kilocalorie()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if quantityType.is(compatibleWith: HKUnit.count()) {
|
|
89
|
+
return HKUnit.count()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if quantityType.is(compatibleWith: HKUnit.meter()) {
|
|
93
|
+
return HKUnit.meter()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if quantityType.is(compatibleWith: SpeedUnit) {
|
|
97
|
+
return SpeedUnit
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if quantityType.is(compatibleWith: METUnit) {
|
|
101
|
+
return METUnit
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if #available(iOS 11, *) {
|
|
105
|
+
if quantityType.is(compatibleWith: HKUnit.internationalUnit()) {
|
|
106
|
+
return HKUnit.internationalUnit()
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if #available(iOS 13, *) {
|
|
111
|
+
if quantityType.is(compatibleWith: HKUnit.hertz()) {
|
|
112
|
+
return HKUnit.hertz()
|
|
113
|
+
}
|
|
114
|
+
if quantityType.is(compatibleWith: HKUnit.decibelHearingLevel()) {
|
|
115
|
+
return HKUnit.decibelHearingLevel()
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if #available(iOS 17.0, *) {
|
|
120
|
+
if quantityType.is(compatibleWith: HKUnit.lux()) {
|
|
121
|
+
return HKUnit.lux()
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
#if compiler(>=6)
|
|
126
|
+
if #available(iOS 18.0, *) {
|
|
127
|
+
if quantityType.is(compatibleWith: HKUnit.appleEffortScore()) {
|
|
128
|
+
return HKUnit.appleEffortScore()
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
#endif
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
return nil
|
|
72
135
|
}
|
|
73
136
|
|
|
74
|
-
func
|
|
137
|
+
func serializeUnknownQuantityTyped(quantity: HKQuantity?) -> Quantity? {
|
|
138
|
+
guard let quantity = quantity else {
|
|
139
|
+
return nil
|
|
140
|
+
}
|
|
141
|
+
|
|
75
142
|
if quantity.is(compatibleWith: HKUnit.percent()) {
|
|
76
|
-
return
|
|
143
|
+
return serializeQuantityTyped(unit: HKUnit.percent(), quantity: quantity)
|
|
77
144
|
}
|
|
78
145
|
|
|
79
146
|
if quantity.is(compatibleWith: HKUnit.second()) {
|
|
80
|
-
return
|
|
147
|
+
return serializeQuantityTyped(unit: HKUnit.second(), quantity: quantity)
|
|
81
148
|
}
|
|
82
149
|
|
|
83
150
|
if quantity.is(compatibleWith: HKUnit.kilocalorie()) {
|
|
84
|
-
return
|
|
151
|
+
return serializeQuantityTyped(unit: HKUnit.kilocalorie(), quantity: quantity)
|
|
85
152
|
}
|
|
86
153
|
|
|
87
154
|
if quantity.is(compatibleWith: HKUnit.count()) {
|
|
88
|
-
return
|
|
155
|
+
return serializeQuantityTyped(unit: HKUnit.count(), quantity: quantity)
|
|
89
156
|
}
|
|
90
157
|
|
|
91
158
|
if quantity.is(compatibleWith: HKUnit.meter()) {
|
|
92
|
-
return
|
|
159
|
+
return serializeQuantityTyped(unit: HKUnit.meter(), quantity: quantity)
|
|
93
160
|
}
|
|
94
161
|
|
|
95
162
|
if #available(iOS 11, *) {
|
|
96
163
|
if quantity.is(compatibleWith: HKUnit.internationalUnit()) {
|
|
97
|
-
return
|
|
164
|
+
return serializeQuantityTyped(unit: HKUnit.internationalUnit(), quantity: quantity)
|
|
98
165
|
}
|
|
99
166
|
}
|
|
100
167
|
|
|
101
168
|
if #available(iOS 13, *) {
|
|
102
169
|
if quantity.is(compatibleWith: HKUnit.hertz()) {
|
|
103
|
-
return
|
|
170
|
+
return serializeQuantityTyped(unit: HKUnit.hertz(), quantity: quantity)
|
|
104
171
|
}
|
|
105
172
|
if quantity.is(compatibleWith: HKUnit.decibelHearingLevel()) {
|
|
106
|
-
return
|
|
173
|
+
return serializeQuantityTyped(unit: HKUnit.decibelHearingLevel(), quantity: quantity)
|
|
107
174
|
}
|
|
108
175
|
}
|
|
109
176
|
|
|
110
177
|
if #available(iOS 17.0, *) {
|
|
111
178
|
if quantity.is(compatibleWith: HKUnit.lux()) {
|
|
112
|
-
return
|
|
179
|
+
return serializeQuantityTyped(unit: HKUnit.lux(), quantity: quantity)
|
|
113
180
|
}
|
|
114
181
|
}
|
|
115
182
|
|
|
116
183
|
#if compiler(>=6)
|
|
117
184
|
if #available(iOS 18.0, *) {
|
|
118
185
|
if quantity.is(compatibleWith: HKUnit.appleEffortScore()) {
|
|
119
|
-
return
|
|
186
|
+
return serializeQuantityTyped(unit: HKUnit.appleEffortScore(), quantity: quantity)
|
|
120
187
|
}
|
|
121
188
|
}
|
|
122
189
|
#endif
|
|
123
190
|
|
|
124
191
|
if quantity.is(compatibleWith: SpeedUnit) {
|
|
125
|
-
return
|
|
192
|
+
return serializeQuantityTyped(unit: SpeedUnit, quantity: quantity)
|
|
126
193
|
}
|
|
127
194
|
|
|
128
195
|
if quantity.is(compatibleWith: METUnit) {
|
|
129
|
-
return
|
|
196
|
+
return serializeQuantityTyped(unit: METUnit, quantity: quantity)
|
|
130
197
|
}
|
|
131
198
|
|
|
132
199
|
return nil
|
|
133
200
|
}
|
|
134
201
|
|
|
135
|
-
func
|
|
136
|
-
let
|
|
202
|
+
func serializeUnknownQuantity(quantity: HKQuantity) -> Dictionary<String, AnyValue>? {
|
|
203
|
+
if let quantityTyped = serializeUnknownQuantityTyped(quantity: quantity) {
|
|
204
|
+
return [
|
|
205
|
+
"quantity": AnyValue.number(quantityTyped.quantity),
|
|
206
|
+
"unit": AnyValue.string(quantityTyped.unit)
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return nil
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
func serializeMetadata(_ metadata: [String: Any]?) -> AnyMapHolder {
|
|
214
|
+
let serialized = AnyMapHolder()
|
|
137
215
|
if let m = metadata {
|
|
138
216
|
for item in m {
|
|
139
217
|
if let bool = item.value as? Bool {
|
|
140
|
-
serialized.
|
|
218
|
+
serialized.setBoolean(key: item.key, value: bool)
|
|
141
219
|
}
|
|
220
|
+
|
|
142
221
|
if let str = item.value as? String {
|
|
143
|
-
serialized.
|
|
222
|
+
serialized.setString(key: item.key, value: str)
|
|
144
223
|
}
|
|
145
224
|
|
|
146
225
|
if let double = item.value as? Double {
|
|
147
|
-
serialized.
|
|
226
|
+
serialized.setDouble(key: item.key, value: double)
|
|
148
227
|
}
|
|
228
|
+
|
|
149
229
|
if let quantity = item.value as? HKQuantity {
|
|
150
230
|
if let s = serializeUnknownQuantity(quantity: quantity) {
|
|
151
|
-
serialized.
|
|
231
|
+
serialized.setObject(key: item.key, value: s)
|
|
152
232
|
}
|
|
153
233
|
}
|
|
234
|
+
|
|
235
|
+
if let dict = item.value as? Dictionary<String, AnyValue> {
|
|
236
|
+
serialized.setObject(key: item.key, value: dict)
|
|
237
|
+
}
|
|
154
238
|
}
|
|
155
239
|
}
|
|
156
240
|
return serialized
|
|
157
241
|
}
|
|
158
242
|
|
|
159
|
-
func
|
|
160
|
-
|
|
161
|
-
return
|
|
243
|
+
/*func serializeGenericMetadata(_ metadata: [String: Any]?) -> GenericMetadata? {
|
|
244
|
+
if let metadata = metadata {
|
|
245
|
+
return GenericMetadata(
|
|
246
|
+
HKExternalUUID: metadata["HKExternalUUID"] as? String,
|
|
247
|
+
HKTimeZone: metadata["HKTimeZone"] as? String,
|
|
248
|
+
HKWasUserEntered: metadata["HKWasUserEntered"] as? Bool,
|
|
249
|
+
HKDeviceSerialNumber: metadata["HKDeviceSerialNumber"] as? String,
|
|
250
|
+
HKUDIDeviceIdentifier: metadata["HKUDIDeviceIdentifier"] as? String,
|
|
251
|
+
HKUDIProductionIdentifier: metadata["HKUDIProductionIdentifier"] as? String,
|
|
252
|
+
HKDigitalSignature: metadata["HKDigitalSignature"] as? String,
|
|
253
|
+
HKDeviceName: metadata["HKDeviceName"] as? String,
|
|
254
|
+
HKDeviceManufacturerName: metadata["HKDeviceManufacturerName"] as? String,
|
|
255
|
+
HKSyncIdentifier: metadata["HKSyncIdentifier"] as? String,
|
|
256
|
+
HKSyncVersion: metadata["HKSyncVersion"] as? Double,
|
|
257
|
+
HKWasTakenInLab: metadata["HKWasTakenInLab"] as? Bool,
|
|
258
|
+
HKReferenceRangeLowerLimit: metadata["HKReferenceRangeLowerLimit"] as? Double,
|
|
259
|
+
HKReferenceRangeUpperLimit: metadata["HKReferenceRangeUpperLimit"] as? Double,
|
|
260
|
+
allMetadata: serializeAllMetadata(metadata)
|
|
261
|
+
)
|
|
162
262
|
}
|
|
263
|
+
return nil
|
|
264
|
+
}*/
|
|
163
265
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
266
|
+
func serializeDevice(hkDevice: HKDevice?) -> Device? {
|
|
267
|
+
guard let hkDevice = hkDevice else {
|
|
268
|
+
return nil
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return Device(
|
|
272
|
+
name: hkDevice.name,
|
|
273
|
+
firmwareVersion: hkDevice.firmwareVersion,
|
|
274
|
+
hardwareVersion: hkDevice.hardwareVersion,
|
|
275
|
+
localIdentifier: hkDevice.localIdentifier,
|
|
276
|
+
manufacturer: hkDevice.manufacturer,
|
|
277
|
+
model: hkDevice.model,
|
|
278
|
+
softwareVersion: hkDevice.softwareVersion,
|
|
279
|
+
udiDeviceIdentifier: hkDevice.udiDeviceIdentifier
|
|
280
|
+
)
|
|
174
281
|
}
|
|
175
282
|
|
|
176
|
-
func serializeOperatingSystemVersion(
|
|
177
|
-
guard let version =
|
|
283
|
+
func serializeOperatingSystemVersion(_ version: OperatingSystemVersion?) -> String? {
|
|
284
|
+
guard let version = version else {
|
|
178
285
|
return nil
|
|
179
286
|
}
|
|
180
287
|
|
|
@@ -183,56 +290,36 @@ func serializeOperatingSystemVersion(_version: OperatingSystemVersion?) -> Strin
|
|
|
183
290
|
return versionString
|
|
184
291
|
}
|
|
185
292
|
|
|
186
|
-
func serializeSourceRevision(
|
|
187
|
-
guard let
|
|
293
|
+
func serializeSourceRevision(_ hkSourceRevision: HKSourceRevision?) -> SourceRevision? {
|
|
294
|
+
guard let hkSourceRevision = hkSourceRevision else {
|
|
188
295
|
return nil
|
|
189
296
|
}
|
|
190
297
|
|
|
191
|
-
|
|
192
|
-
"source": [
|
|
193
|
-
"name": sourceRevision.source.name,
|
|
194
|
-
"bundleIdentifier": sourceRevision.source.bundleIdentifier
|
|
195
|
-
],
|
|
196
|
-
"version": sourceRevision.version as Any
|
|
197
|
-
] as [String: Any]
|
|
198
|
-
|
|
298
|
+
|
|
199
299
|
if #available(iOS 11, *) {
|
|
200
|
-
|
|
201
|
-
|
|
300
|
+
return SourceRevision(
|
|
301
|
+
source: serializeSource(hkSourceRevision.source),
|
|
302
|
+
version: hkSourceRevision.version,
|
|
303
|
+
operatingSystemVersion: serializeOperatingSystemVersion( hkSourceRevision.operatingSystemVersion),
|
|
304
|
+
productType: hkSourceRevision.productType
|
|
305
|
+
)
|
|
202
306
|
}
|
|
203
|
-
|
|
204
|
-
return
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
307
|
+
|
|
308
|
+
return SourceRevision(
|
|
309
|
+
source: serializeSource(hkSourceRevision.source),
|
|
310
|
+
version: hkSourceRevision.version,
|
|
311
|
+
operatingSystemVersion: nil,
|
|
312
|
+
productType: nil
|
|
313
|
+
)
|
|
209
314
|
}
|
|
210
315
|
|
|
211
316
|
func serializeAnchor(anchor: HKQueryAnchor?) -> String? {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
317
|
+
if let anchor = anchor {
|
|
318
|
+
let data = NSKeyedArchiver.archivedData(withRootObject: anchor)
|
|
319
|
+
let encoded = data.base64EncodedString()
|
|
215
320
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
return encoded
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
func serializeStatistic(unit: HKUnit, quantity: HKQuantity?, stats: HKStatistics?) -> [String: Any]? {
|
|
223
|
-
guard let q = quantity, let stats = stats else {
|
|
321
|
+
return encoded
|
|
322
|
+
} else {
|
|
224
323
|
return nil
|
|
225
324
|
}
|
|
226
|
-
|
|
227
|
-
let endDate = _dateFormatter.string(from: stats.endDate)
|
|
228
|
-
let startDate = _dateFormatter.string(from: stats.startDate)
|
|
229
|
-
let quantityType = stats.quantityType.identifier
|
|
230
|
-
|
|
231
|
-
return [
|
|
232
|
-
"quantityType": quantityType,
|
|
233
|
-
"startDate": startDate,
|
|
234
|
-
"endDate": endDate,
|
|
235
|
-
"quantity": q.doubleValue(for: unit),
|
|
236
|
-
"unit": unit.unitString
|
|
237
|
-
]
|
|
238
325
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//
|
|
2
|
+
// SourceProxy.swift
|
|
3
|
+
// Pods
|
|
4
|
+
//
|
|
5
|
+
// Created by Robert Herber on 2025-06-16.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import HealthKit
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
class SourceProxy: HybridSourceProxySpec {
|
|
12
|
+
func toJSON(key: String?) throws -> Source {
|
|
13
|
+
if key != nil && key?.isEmpty != true {
|
|
14
|
+
print("SourceProxy does not support toJSON with key: \(key!)")
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return Source(
|
|
18
|
+
name: self.name,
|
|
19
|
+
bundleIdentifier: self.bundleIdentifier
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private let source: HKSource
|
|
25
|
+
|
|
26
|
+
let name: String
|
|
27
|
+
|
|
28
|
+
let bundleIdentifier: String
|
|
29
|
+
|
|
30
|
+
init(source: HKSource) {
|
|
31
|
+
self.source = source
|
|
32
|
+
self.name = source.name
|
|
33
|
+
self.bundleIdentifier = source.bundleIdentifier
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import HealthKit
|
|
2
|
+
import NitroModules
|
|
3
|
+
|
|
4
|
+
@available(iOS 18.0, *)
|
|
5
|
+
func serializeStateOfMindSample(sample: HKStateOfMind) -> StateOfMindSample {
|
|
6
|
+
// todo: warn if we get unknown labels??
|
|
7
|
+
let associations = sample.associations.compactMap { association in
|
|
8
|
+
if let association = StateOfMindAssociation(rawValue: Int32(association.rawValue)) {
|
|
9
|
+
return association
|
|
10
|
+
}
|
|
11
|
+
print("[react-native-healthkit] Unknown StateOfMindAssociation raw value: \(association.rawValue)")
|
|
12
|
+
|
|
13
|
+
return nil
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// todo: warn if we get unknown labels??
|
|
17
|
+
let labels = sample.labels.compactMap { label in
|
|
18
|
+
if let label = StateOfMindLabel(rawValue: Int32(label.rawValue)){
|
|
19
|
+
return label
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
print("[react-native-healthkit] Unknown StateOfMindLabel raw value: \(label.rawValue)")
|
|
23
|
+
return nil
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return StateOfMindSample(
|
|
27
|
+
uuid: sample.uuid.uuidString,
|
|
28
|
+
device: serializeDevice(hkDevice: sample.device),
|
|
29
|
+
startDate: sample.startDate,
|
|
30
|
+
endDate: sample.endDate,
|
|
31
|
+
metadata: serializeMetadata(sample.metadata),
|
|
32
|
+
sourceRevision: serializeSourceRevision(sample.sourceRevision),
|
|
33
|
+
valence: sample.valence,
|
|
34
|
+
// todo: handle better?
|
|
35
|
+
kind: StateOfMindKind(rawValue: Int32(sample.kind.rawValue))!,
|
|
36
|
+
// todo: handle better?
|
|
37
|
+
valenceClassification: StateOfMindValenceClassification(rawValue: Int32(sample.valenceClassification.rawValue))!,
|
|
38
|
+
associations: associations,
|
|
39
|
+
labels: labels
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
#if compiler(>=6)
|
|
44
|
+
class StateOfMindModule : HybridStateOfMindModuleSpec {
|
|
45
|
+
func queryStateOfMindSamples(
|
|
46
|
+
options: QueryOptionsWithSortOrder?
|
|
47
|
+
) throws -> Promise<[StateOfMindSample]> {
|
|
48
|
+
if #available(iOS 18.0, *) {
|
|
49
|
+
let predicate = try createPredicate(filter: options?.filter)
|
|
50
|
+
let queryLimit = getQueryLimit(options?.limit)
|
|
51
|
+
|
|
52
|
+
return Promise.async {
|
|
53
|
+
try await withCheckedThrowingContinuation { continuation in
|
|
54
|
+
let type = HKStateOfMindType.stateOfMindType()
|
|
55
|
+
|
|
56
|
+
let query = HKSampleQuery(
|
|
57
|
+
sampleType: type,
|
|
58
|
+
predicate: predicate,
|
|
59
|
+
limit: queryLimit,
|
|
60
|
+
sortDescriptors: [
|
|
61
|
+
NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: options?.ascending ?? false)
|
|
62
|
+
]
|
|
63
|
+
) { (_: HKSampleQuery, samples: [HKSample]?, error: Error?) in
|
|
64
|
+
if let error = error {
|
|
65
|
+
continuation.resume(throwing: error)
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
guard let samples = samples as? [HKStateOfMind] else {
|
|
70
|
+
return continuation.resume(throwing: RuntimeError.error(withMessage: "[react-native-healthkit] Unexpected empty response"))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let serializedSamples = samples.map { sample -> StateOfMindSample in
|
|
74
|
+
return serializeStateOfMindSample(sample: sample)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
continuation.resume(returning: serializedSamples)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
store.execute(query)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
throw RuntimeError.error(withMessage: "StateOfMind is only available on iOS 18 and later")
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
func saveStateOfMindSample(
|
|
89
|
+
date: Date,
|
|
90
|
+
kind: StateOfMindKind,
|
|
91
|
+
valence: Double,
|
|
92
|
+
labels: [StateOfMindLabel],
|
|
93
|
+
associations: [StateOfMindAssociation],
|
|
94
|
+
metadata: AnyMapHolder?
|
|
95
|
+
) throws -> Promise<Bool> {
|
|
96
|
+
if #available(iOS 18, *) {
|
|
97
|
+
return Promise.async {
|
|
98
|
+
try await withCheckedThrowingContinuation { continuation in
|
|
99
|
+
// Convert enum values to HKStateOfMind types
|
|
100
|
+
if let hkKind = HKStateOfMind.Kind.init(rawValue: Int(kind.rawValue)) {
|
|
101
|
+
let hkLabels = labels.compactMap {
|
|
102
|
+
if let label = HKStateOfMind.Label.init(rawValue: Int($0.rawValue)) {
|
|
103
|
+
return label
|
|
104
|
+
}
|
|
105
|
+
print("[react-native-healthkit] Unknown StateOfMindLabel raw value: \($0.rawValue)")
|
|
106
|
+
return nil
|
|
107
|
+
}
|
|
108
|
+
let hkAssociations = associations.compactMap {
|
|
109
|
+
if let association = HKStateOfMind.Association.init(rawValue: Int($0.rawValue)) {
|
|
110
|
+
return association
|
|
111
|
+
}
|
|
112
|
+
print("[react-native-healthkit] Unknown StateOfMindAssociation raw value: \($0.rawValue)")
|
|
113
|
+
return nil
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let sample = HKStateOfMind(
|
|
117
|
+
date: date,
|
|
118
|
+
kind: hkKind,
|
|
119
|
+
valence: valence,
|
|
120
|
+
labels: hkLabels,
|
|
121
|
+
associations: hkAssociations,
|
|
122
|
+
metadata: anyMapToDictionary(metadata ?? AnyMapHolder())
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
store.save(sample) { (success: Bool, error: Error?) in
|
|
126
|
+
if let error = error {
|
|
127
|
+
continuation.resume(throwing: error)
|
|
128
|
+
} else {
|
|
129
|
+
continuation.resume(returning: success)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
throw RuntimeError.error(withMessage: "StateOfMind is only available on iOS 18 and later")
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
#else
|
|
141
|
+
// Fallback for older Xcode versions
|
|
142
|
+
class StateOfMind : HybridStateOfMindModuleSpec {
|
|
143
|
+
func queryStateOfMindSamples(
|
|
144
|
+
options: QueryOptionsWithSortOrder?
|
|
145
|
+
) throws -> Promise<[StateOfMindSample]> {
|
|
146
|
+
throw RuntimeError.error(withMessage: "State of Mind features require iOS 18.0 or later and Xcode 16 or later to compile")
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
func saveStateOfMindSample(
|
|
150
|
+
date: Date,
|
|
151
|
+
kind: StateOfMindKind,
|
|
152
|
+
valence: Double,
|
|
153
|
+
labels: [StateOfMindLabel],
|
|
154
|
+
associations: [StateOfMindAssociation],
|
|
155
|
+
metadata: [String: Any]?
|
|
156
|
+
) throws -> Promise<Bool> {
|
|
157
|
+
throw RuntimeError.error(withMessage: "State of Mind features require iOS 18.0 or later and Xcode 16 or later to compile")
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
#endif
|