@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
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import HealthKit
|
|
2
|
+
import NitroModules
|
|
3
|
+
|
|
4
|
+
func queryQuantitySamplesInternal(
|
|
5
|
+
typeIdentifier: QuantityTypeIdentifier,
|
|
6
|
+
options: QueryOptionsWithSortOrderAndUnit?
|
|
7
|
+
) throws -> Promise<[QuantitySample]> {
|
|
8
|
+
let quantityType = try initializeQuantityType(typeIdentifier.stringValue)
|
|
9
|
+
let predicate = try createPredicate(filter: options?.filter)
|
|
10
|
+
let limit = getQueryLimit(options?.limit)
|
|
11
|
+
|
|
12
|
+
return Promise.async {
|
|
13
|
+
let unit = try await getUnitToUse(unitOverride: options?.unit, quantityType: quantityType)
|
|
14
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
15
|
+
let q = HKSampleQuery(
|
|
16
|
+
sampleType: quantityType,
|
|
17
|
+
predicate: predicate,
|
|
18
|
+
limit: limit,
|
|
19
|
+
sortDescriptors: getSortDescriptors(ascending: options?.ascending)
|
|
20
|
+
) { (_: HKSampleQuery, samples: [HKSample]?, error: Error?) in
|
|
21
|
+
guard let err = error else {
|
|
22
|
+
if let returnValue = samples?.compactMap({ sample in
|
|
23
|
+
if let sample = sample as? HKQuantitySample {
|
|
24
|
+
do {
|
|
25
|
+
let serialized = try serializeQuantitySample(
|
|
26
|
+
sample: sample,
|
|
27
|
+
unit: unit
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
return serialized
|
|
31
|
+
} catch {
|
|
32
|
+
print(error.localizedDescription)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return nil
|
|
37
|
+
}) {
|
|
38
|
+
return continuation.resume(returning: returnValue)
|
|
39
|
+
}
|
|
40
|
+
return continuation.resume(throwing: RuntimeError.error(withMessage: "Empty response returned")
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
return continuation.resume(throwing: err)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
store.execute(q)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
func saveQuantitySampleInternal(
|
|
53
|
+
typeIdentifier: HKQuantityType,
|
|
54
|
+
unitString: String,
|
|
55
|
+
value: Double,
|
|
56
|
+
start: Date,
|
|
57
|
+
end: Date,
|
|
58
|
+
metadata: [String: Any]?
|
|
59
|
+
) -> Promise<Bool> {
|
|
60
|
+
let unit = HKUnit.init(from: unitString)
|
|
61
|
+
let quantity = HKQuantity.init(unit: unit, doubleValue: value)
|
|
62
|
+
let sample = HKQuantitySample.init(
|
|
63
|
+
type: typeIdentifier,
|
|
64
|
+
quantity: quantity,
|
|
65
|
+
start: start,
|
|
66
|
+
end: end,
|
|
67
|
+
metadata: metadata
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
return Promise.async {
|
|
71
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
72
|
+
store.save(sample) { (success: Bool, error: Error?) in
|
|
73
|
+
if let error = error {
|
|
74
|
+
return continuation.resume(throwing: error)
|
|
75
|
+
}
|
|
76
|
+
return continuation.resume(returning: success)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
func getAnyMapValue(_ anyMap: AnyMapHolder, key: String) -> Any? {
|
|
83
|
+
if(anyMap.isBool(key: key)){
|
|
84
|
+
return anyMap.getBoolean(key: key)
|
|
85
|
+
}
|
|
86
|
+
if(anyMap.isArray(key: key)){
|
|
87
|
+
return anyMap.getArray(key: key)
|
|
88
|
+
}
|
|
89
|
+
if(anyMap.isDouble(key: key)){
|
|
90
|
+
return anyMap.getDouble(key: key)
|
|
91
|
+
}
|
|
92
|
+
if(anyMap.isObject(key: key)){
|
|
93
|
+
return anyMap.getObject(key: key)
|
|
94
|
+
}
|
|
95
|
+
if(anyMap.isString(key: key)){
|
|
96
|
+
return anyMap.getString(key: key)
|
|
97
|
+
}
|
|
98
|
+
if(anyMap.isBigInt(key: key)){
|
|
99
|
+
return anyMap.getBigInt(key: key)
|
|
100
|
+
}
|
|
101
|
+
if(anyMap.isNull(key: key)){
|
|
102
|
+
return nil
|
|
103
|
+
}
|
|
104
|
+
return nil
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
func anyMapToDictionary(_ anyMap: AnyMapHolder) -> [String: Any] {
|
|
108
|
+
var dict = Dictionary<String, Any>()
|
|
109
|
+
anyMap.getAllKeys().forEach { key in
|
|
110
|
+
dict[key] = getAnyMapValue(anyMap, key: key)
|
|
111
|
+
}
|
|
112
|
+
return dict
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
func buildStatisticsOptions(statistics: [StatisticsOptions]) -> HKStatisticsOptions{
|
|
116
|
+
// Build statistics options
|
|
117
|
+
var opts = HKStatisticsOptions()
|
|
118
|
+
for statistic in statistics {
|
|
119
|
+
if statistic == .cumulativesum {
|
|
120
|
+
opts.insert(HKStatisticsOptions.cumulativeSum)
|
|
121
|
+
} else if statistic == .discreteaverage {
|
|
122
|
+
opts.insert(HKStatisticsOptions.discreteAverage)
|
|
123
|
+
} else if statistic == .discretemax {
|
|
124
|
+
opts.insert(HKStatisticsOptions.discreteMax)
|
|
125
|
+
} else if statistic == .discretemin {
|
|
126
|
+
opts.insert(HKStatisticsOptions.discreteMin)
|
|
127
|
+
}
|
|
128
|
+
if #available(iOS 13, *) {
|
|
129
|
+
if statistic == .duration {
|
|
130
|
+
opts.insert(HKStatisticsOptions.duration)
|
|
131
|
+
}
|
|
132
|
+
if statistic == .mostrecent {
|
|
133
|
+
opts.insert(HKStatisticsOptions.mostRecent)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if statistic == .separatebysource {
|
|
137
|
+
opts.insert(HKStatisticsOptions.separateBySource)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return opts
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
144
|
+
func deleteQuantitySamples(identifier: QuantityTypeIdentifier, filter: FilterForSamples) throws -> Promise<Bool> {
|
|
145
|
+
let sampleType = try initializeQuantityType(identifier.stringValue)
|
|
146
|
+
let samplePredicate = try createPredicateForSamples(filter: filter)
|
|
147
|
+
|
|
148
|
+
return Promise.async {
|
|
149
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
150
|
+
store.deleteObjects(of: sampleType, predicate: samplePredicate) { (success: Bool, _: Int, error: Error?) in
|
|
151
|
+
if let error = error {
|
|
152
|
+
continuation.resume(throwing: error)
|
|
153
|
+
} else {
|
|
154
|
+
continuation.resume(returning: success)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
func isQuantityCompatibleWithUnit(identifier: QuantityTypeIdentifier, unit: String) throws -> Bool {
|
|
163
|
+
let sampleType = try initializeQuantityType(identifier.stringValue)
|
|
164
|
+
|
|
165
|
+
return sampleType.is(compatibleWith: HKUnit.init(from: unit))
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
func queryStatisticsForQuantity(identifier: QuantityTypeIdentifier, statistics: [StatisticsOptions], options: StatisticsQueryOptions?) throws -> Promise<QueryStatisticsResponse> {
|
|
169
|
+
|
|
170
|
+
let quantityType = try initializeQuantityType(identifier.stringValue)
|
|
171
|
+
let predicate = try createPredicate(filter: options?.filter)
|
|
172
|
+
let unit = HKUnit.init(from: options?.unit ?? "count")
|
|
173
|
+
|
|
174
|
+
return Promise.async {
|
|
175
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
176
|
+
let query = HKStatisticsQuery.init(
|
|
177
|
+
quantityType: quantityType,
|
|
178
|
+
quantitySamplePredicate: predicate,
|
|
179
|
+
options: buildStatisticsOptions(statistics: statistics)
|
|
180
|
+
) { (_, stats: HKStatistics?, error: Error?) in
|
|
181
|
+
if let error = error {
|
|
182
|
+
continuation.resume(throwing: error)
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
guard let gottenStats = stats else {
|
|
187
|
+
let emptyResponse = QueryStatisticsResponse()
|
|
188
|
+
continuation.resume(returning: emptyResponse)
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
var response = QueryStatisticsResponse()
|
|
193
|
+
|
|
194
|
+
if let averageQuantity = gottenStats.averageQuantity() {
|
|
195
|
+
response.averageQuantity = Quantity(
|
|
196
|
+
unit: unit.unitString,
|
|
197
|
+
quantity: averageQuantity.doubleValue(for: unit)
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
if let maximumQuantity = gottenStats.maximumQuantity() {
|
|
201
|
+
response.maximumQuantity = Quantity(
|
|
202
|
+
unit: unit.unitString,
|
|
203
|
+
quantity: maximumQuantity.doubleValue(for: unit)
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
if let minimumQuantity = gottenStats.minimumQuantity() {
|
|
207
|
+
response.minimumQuantity = Quantity(
|
|
208
|
+
unit: unit.unitString,
|
|
209
|
+
quantity: minimumQuantity.doubleValue(for: unit)
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
if let sumQuantity = gottenStats.sumQuantity() {
|
|
213
|
+
response.sumQuantity = Quantity(
|
|
214
|
+
unit: unit.unitString,
|
|
215
|
+
quantity: sumQuantity.doubleValue(for: unit)
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if #available(iOS 12, *) {
|
|
220
|
+
if let mostRecent = gottenStats.mostRecentQuantity() {
|
|
221
|
+
response.mostRecentQuantity = Quantity(
|
|
222
|
+
unit: unit.unitString,
|
|
223
|
+
quantity: mostRecent.doubleValue(for: unit)
|
|
224
|
+
)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if let mostRecentDateInterval = gottenStats.mostRecentQuantityDateInterval() {
|
|
228
|
+
response.mostRecentQuantityDateInterval = QuantityDateInterval(
|
|
229
|
+
from: mostRecentDateInterval.start,
|
|
230
|
+
to: mostRecentDateInterval.end
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if #available(iOS 13, *) {
|
|
236
|
+
if let duration = gottenStats.duration() {
|
|
237
|
+
let durationUnit = HKUnit.second()
|
|
238
|
+
response.duration = Quantity(
|
|
239
|
+
unit: durationUnit.unitString,
|
|
240
|
+
quantity: duration.doubleValue(for: durationUnit)
|
|
241
|
+
)
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
continuation.resume(returning: response)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
store.execute(query)
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
func queryStatisticsCollectionForQuantity(identifier: QuantityTypeIdentifier, statistics: [StatisticsOptions], anchorDate: String, intervalComponents: IntervalComponents, options: StatisticsQueryOptions?) throws -> Promise<[QueryStatisticsResponse]> {
|
|
254
|
+
let quantityType = try initializeQuantityType(identifier.stringValue)
|
|
255
|
+
|
|
256
|
+
let predicate = try createPredicate(filter: options?.filter)
|
|
257
|
+
let unit = HKUnit.init(from: options?.unit ?? "count")
|
|
258
|
+
|
|
259
|
+
// Convert the anchor date string to Date
|
|
260
|
+
let dateFormatter = ISO8601DateFormatter()
|
|
261
|
+
guard let anchor = dateFormatter.date(from: anchorDate) else {
|
|
262
|
+
throw RuntimeError.error(withMessage: "Invalid anchor date format: " + anchorDate)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Create date components from interval
|
|
266
|
+
var dateComponents = DateComponents()
|
|
267
|
+
if let minute = intervalComponents.minute {
|
|
268
|
+
dateComponents.minute = Int(minute)
|
|
269
|
+
}
|
|
270
|
+
if let hour = intervalComponents.hour {
|
|
271
|
+
dateComponents.hour = Int(hour)
|
|
272
|
+
}
|
|
273
|
+
if let day = intervalComponents.day {
|
|
274
|
+
dateComponents.day = Int(day)
|
|
275
|
+
}
|
|
276
|
+
if let month = intervalComponents.month {
|
|
277
|
+
dateComponents.month = Int(month)
|
|
278
|
+
}
|
|
279
|
+
if let year = intervalComponents.year {
|
|
280
|
+
dateComponents.year = Int(year)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Build statistics options
|
|
284
|
+
let opts = buildStatisticsOptions(statistics: statistics)
|
|
285
|
+
|
|
286
|
+
return Promise.async {
|
|
287
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
288
|
+
let query = HKStatisticsCollectionQuery.init(
|
|
289
|
+
quantityType: quantityType,
|
|
290
|
+
quantitySamplePredicate: predicate,
|
|
291
|
+
options: opts,
|
|
292
|
+
anchorDate: anchor,
|
|
293
|
+
intervalComponents: dateComponents
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
query.initialResultsHandler = { (_, results: HKStatisticsCollection?, error: Error?) in
|
|
297
|
+
if let error = error {
|
|
298
|
+
continuation.resume(throwing: error)
|
|
299
|
+
return
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
guard let statistics = results else {
|
|
303
|
+
continuation.resume(returning: [])
|
|
304
|
+
return
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
var responseArray: [QueryStatisticsResponse] = []
|
|
308
|
+
|
|
309
|
+
// todo: handle from/to here?
|
|
310
|
+
statistics.enumerateStatistics(from: Date.distantPast, to: Date()) { stats, _ in
|
|
311
|
+
var response = QueryStatisticsResponse()
|
|
312
|
+
|
|
313
|
+
if let averageQuantity = stats.averageQuantity() {
|
|
314
|
+
response.averageQuantity = Quantity(
|
|
315
|
+
unit: unit.unitString,
|
|
316
|
+
quantity: averageQuantity.doubleValue(for: unit)
|
|
317
|
+
)
|
|
318
|
+
}
|
|
319
|
+
if let maximumQuantity = stats.maximumQuantity() {
|
|
320
|
+
response.maximumQuantity = Quantity(
|
|
321
|
+
unit: unit.unitString,
|
|
322
|
+
quantity: maximumQuantity.doubleValue(for: unit)
|
|
323
|
+
)
|
|
324
|
+
}
|
|
325
|
+
if let minimumQuantity = stats.minimumQuantity() {
|
|
326
|
+
response.minimumQuantity = Quantity(
|
|
327
|
+
unit: unit.unitString,
|
|
328
|
+
quantity: minimumQuantity.doubleValue(for: unit)
|
|
329
|
+
)
|
|
330
|
+
}
|
|
331
|
+
if let sumQuantity = stats.sumQuantity() {
|
|
332
|
+
response.sumQuantity = Quantity(
|
|
333
|
+
unit: unit.unitString,
|
|
334
|
+
quantity: sumQuantity.doubleValue(for: unit)
|
|
335
|
+
)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if #available(iOS 12, *) {
|
|
339
|
+
if let mostRecent = stats.mostRecentQuantity() {
|
|
340
|
+
response.mostRecentQuantity = Quantity(
|
|
341
|
+
unit: unit.unitString,
|
|
342
|
+
quantity: mostRecent.doubleValue(for: unit)
|
|
343
|
+
)
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if let mostRecentDateInterval = stats.mostRecentQuantityDateInterval() {
|
|
347
|
+
response.mostRecentQuantityDateInterval = QuantityDateInterval(
|
|
348
|
+
from: mostRecentDateInterval.start,
|
|
349
|
+
to: mostRecentDateInterval.end
|
|
350
|
+
)
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if #available(iOS 13, *) {
|
|
355
|
+
if let duration = stats.duration() {
|
|
356
|
+
let durationUnit = HKUnit.second()
|
|
357
|
+
response.duration = Quantity(
|
|
358
|
+
unit: durationUnit.unitString,
|
|
359
|
+
quantity: duration.doubleValue(for: durationUnit)
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
responseArray.append(response)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
continuation.resume(returning: responseArray)
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
store.execute(query)
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
func queryQuantitySamplesWithAnchor(identifier: QuantityTypeIdentifier, options: QueryOptionsWithAnchorAndUnit) throws -> Promise<QuantitySamplesWithAnchorResponse> {
|
|
376
|
+
let quantityType = try initializeQuantityType(identifier.stringValue)
|
|
377
|
+
let predicate = try createPredicate(filter: options.filter)
|
|
378
|
+
let limit = getQueryLimit(options.limit)
|
|
379
|
+
let actualAnchor = try deserializeHKQueryAnchor(base64String: options.anchor)
|
|
380
|
+
|
|
381
|
+
return Promise.async {
|
|
382
|
+
let unit = try await getUnitToUse(
|
|
383
|
+
unitOverride: options.unit,
|
|
384
|
+
quantityType: quantityType
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
388
|
+
let query = HKAnchoredObjectQuery(
|
|
389
|
+
type: quantityType,
|
|
390
|
+
predicate: predicate,
|
|
391
|
+
anchor: actualAnchor,
|
|
392
|
+
limit: limit
|
|
393
|
+
) { (
|
|
394
|
+
_: HKAnchoredObjectQuery,
|
|
395
|
+
samples: [HKSample]?,
|
|
396
|
+
deletedSamples: [HKDeletedObject]?,
|
|
397
|
+
newAnchor: HKQueryAnchor?,
|
|
398
|
+
error: Error?
|
|
399
|
+
) in
|
|
400
|
+
if let error = error {
|
|
401
|
+
continuation.resume(throwing: error)
|
|
402
|
+
return
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
guard let samples = samples else {
|
|
406
|
+
let response = QuantitySamplesWithAnchorResponse(
|
|
407
|
+
samples: [],
|
|
408
|
+
deletedSamples: deletedSamples?.map { serializeDeletedSample(sample: $0) } ?? [],
|
|
409
|
+
newAnchor: serializeAnchor(anchor: newAnchor) ?? ""
|
|
410
|
+
)
|
|
411
|
+
continuation.resume(returning: response)
|
|
412
|
+
return
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
let quantitySamples = samples.compactMap { sample in
|
|
416
|
+
if let quantitySample = sample as? HKQuantitySample {
|
|
417
|
+
do {
|
|
418
|
+
return try serializeQuantitySample(
|
|
419
|
+
sample: quantitySample,
|
|
420
|
+
unit: unit
|
|
421
|
+
)
|
|
422
|
+
} catch {
|
|
423
|
+
print(error.localizedDescription)
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return nil
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
let response = QuantitySamplesWithAnchorResponse(
|
|
430
|
+
samples: quantitySamples,
|
|
431
|
+
deletedSamples: deletedSamples?.map { serializeDeletedSample(sample: $0) } ?? [],
|
|
432
|
+
newAnchor: serializeAnchor(anchor: newAnchor) ?? ""
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
continuation.resume(returning: response)
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
store.execute(query)
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
func saveQuantitySample(identifier: QuantityTypeIdentifier, unit: String, value: Double, start: Date, end: Date, metadata: AnyMapHolder) throws -> Promise<Bool> {
|
|
444
|
+
return saveQuantitySampleInternal(
|
|
445
|
+
typeIdentifier: HKQuantityType(
|
|
446
|
+
HKQuantityTypeIdentifier(rawValue: identifier.stringValue)
|
|
447
|
+
),
|
|
448
|
+
unitString: unit,
|
|
449
|
+
value: value,
|
|
450
|
+
start: start,
|
|
451
|
+
end: end,
|
|
452
|
+
metadata: anyMapToDictionary(metadata)
|
|
453
|
+
)
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
func queryQuantitySamples(identifier: QuantityTypeIdentifier, options: QueryOptionsWithSortOrderAndUnit?) throws -> Promise<[QuantitySample]> {
|
|
457
|
+
return try queryQuantitySamplesInternal(typeIdentifier: identifier, options: options)
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
}
|