@kingstinct/react-native-healthkit 10.0.0 → 11.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/ios/CoreModule.swift +5 -15
- package/ios/CorrelationTypeModule.swift +8 -2
- package/ios/Helpers.swift +50 -6
- package/ios/QuantityTypeModule.swift +72 -112
- package/ios/Serializers.swift +39 -66
- package/ios/WorkoutProxy.swift +38 -20
- package/ios/WorkoutsModule.swift +7 -18
- package/lib/commonjs/healthkit.js +1 -1
- package/lib/commonjs/hooks/useMostRecentWorkout.js +2 -9
- package/lib/commonjs/hooks/useWorkoutById.js +1 -4
- package/lib/commonjs/utils/getMostRecentWorkout.js +1 -3
- package/lib/commonjs/utils/getWorkoutById.js +1 -3
- package/lib/module/healthkit.js +1 -1
- package/lib/module/hooks/useMostRecentWorkout.js +3 -10
- package/lib/module/hooks/useWorkoutById.js +1 -4
- package/lib/module/utils/getMostRecentWorkout.js +1 -3
- package/lib/module/utils/getWorkoutById.js +1 -3
- package/lib/typescript/healthkit.d.ts +5 -5
- package/lib/typescript/healthkit.ios.d.ts +1 -1
- package/lib/typescript/hooks/useMostRecentWorkout.d.ts +1 -4
- package/lib/typescript/specs/WorkoutProxy.nitro.d.ts +11 -0
- package/lib/typescript/types/CorrelationType.d.ts +1 -0
- package/lib/typescript/types/QuantityType.d.ts +2 -0
- package/lib/typescript/types/QueryOptions.d.ts +4 -0
- package/lib/typescript/types/Workouts.d.ts +0 -8
- package/lib/typescript/utils/getMostRecentWorkout.d.ts +1 -2
- package/lib/typescript/utils/getWorkoutById.d.ts +1 -2
- package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Bridge.cpp +103 -87
- package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Bridge.hpp +798 -481
- package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/ReactNativeHealthkitAutolinking.mm +8 -8
- package/nitrogen/generated/ios/ReactNativeHealthkitAutolinking.swift +16 -16
- package/nitrogen/generated/ios/c++/HybridCategoryTypeModuleSpecSwift.hpp +9 -4
- package/nitrogen/generated/ios/c++/HybridCharacteristicTypeModuleSpecSwift.hpp +4 -2
- package/nitrogen/generated/ios/c++/HybridCoreModuleSpecSwift.hpp +10 -5
- package/nitrogen/generated/ios/c++/HybridCorrelationTypeModuleSpecSwift.hpp +6 -4
- package/nitrogen/generated/ios/c++/HybridHeartbeatSeriesModuleSpecSwift.hpp +10 -5
- package/nitrogen/generated/ios/c++/HybridQuantityTypeModuleSpecSwift.hpp +7 -2
- package/nitrogen/generated/ios/c++/HybridSourceProxySpecSwift.hpp +3 -1
- package/nitrogen/generated/ios/c++/HybridStateOfMindModuleSpecSwift.hpp +10 -5
- package/nitrogen/generated/ios/c++/HybridWorkoutProxySpecSwift.hpp +50 -22
- package/nitrogen/generated/ios/c++/HybridWorkoutsModuleSpecSwift.hpp +12 -7
- package/nitrogen/generated/ios/swift/CategorySample.swift +4 -2
- package/nitrogen/generated/ios/swift/CategorySampleForSaving.swift +2 -1
- package/nitrogen/generated/ios/swift/CorrelationObject.swift +2 -0
- package/nitrogen/generated/ios/swift/CorrelationSample.swift +13 -2
- package/nitrogen/generated/ios/swift/DeletedSample.swift +2 -1
- package/nitrogen/generated/ios/swift/Device.swift +16 -8
- package/nitrogen/generated/ios/swift/FilterForSamples.swift +2 -0
- package/nitrogen/generated/ios/swift/Func_void_AuthorizationRequestStatus.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_BiologicalSex.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_BloodType.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_CategorySamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_FitzpatrickSkinType.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_HeartbeatSeriesSamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_OnChangeCallbackArgs.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_QuantitySamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_QueryStatisticsResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_QueryWorkoutSamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_WheelchairUse.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_QueryStatisticsResponse_.swift +54 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_WorkoutPlan_.swift +3 -1
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__chrono__system_clock__time_point_.swift +3 -1
- package/nitrogen/generated/ios/swift/{Func_void_std__shared_ptr_margelo__nitro__healthkit__HybridWorkoutProxySpec_.swift → Func_void_std__shared_ptr_HybridWorkoutProxySpec_.swift} +9 -8
- package/nitrogen/generated/ios/swift/Func_void_std__unordered_map_std__string__QueryStatisticsResponse_.swift +55 -0
- package/nitrogen/generated/ios/swift/Func_void_std__unordered_map_std__string__bool_.swift +2 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_CategorySample_.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_CorrelationSample_.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_HeartbeatSeriesSample_.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_IdentifierWithUnit_.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_QuantitySample_.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_QueryStatisticsResponse_.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_StateOfMindSample_.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_WorkoutRoute_.swift +1 -0
- package/nitrogen/generated/ios/swift/{Func_void_std__vector_std__shared_ptr_margelo__nitro__healthkit__HybridSourceProxySpec__.swift → Func_void_std__vector_std__shared_ptr_HybridSourceProxySpec__.swift} +9 -8
- package/nitrogen/generated/ios/swift/{Func_void_std__vector_std__shared_ptr_margelo__nitro__healthkit__HybridWorkoutProxySpec__.swift → Func_void_std__vector_std__shared_ptr_HybridWorkoutProxySpec__.swift} +9 -8
- package/nitrogen/generated/ios/swift/HeartbeatSeriesSample.swift +6 -3
- package/nitrogen/generated/ios/swift/HybridCategoryTypeModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridCategoryTypeModuleSpec_cxx.swift +17 -7
- package/nitrogen/generated/ios/swift/HybridCharacteristicTypeModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridCharacteristicTypeModuleSpec_cxx.swift +15 -6
- package/nitrogen/generated/ios/swift/HybridCoreModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridCoreModuleSpec_cxx.swift +24 -15
- package/nitrogen/generated/ios/swift/HybridCorrelationTypeModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridCorrelationTypeModuleSpec_cxx.swift +15 -6
- package/nitrogen/generated/ios/swift/HybridHeartbeatSeriesModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridHeartbeatSeriesModuleSpec_cxx.swift +17 -7
- package/nitrogen/generated/ios/swift/HybridQuantityTypeModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridQuantityTypeModuleSpec_cxx.swift +21 -9
- package/nitrogen/generated/ios/swift/HybridSourceProxySpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridSourceProxySpec_cxx.swift +17 -7
- package/nitrogen/generated/ios/swift/HybridStateOfMindModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridStateOfMindModuleSpec_cxx.swift +19 -8
- package/nitrogen/generated/ios/swift/HybridWorkoutProxySpec.swift +8 -5
- package/nitrogen/generated/ios/swift/HybridWorkoutProxySpec_cxx.swift +108 -41
- package/nitrogen/generated/ios/swift/HybridWorkoutsModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridWorkoutsModuleSpec_cxx.swift +31 -22
- package/nitrogen/generated/ios/swift/OnChangeCallbackArgs.swift +2 -1
- package/nitrogen/generated/ios/swift/PredicateForSamples.swift +2 -0
- package/nitrogen/generated/ios/swift/PredicateForWorkouts.swift +2 -0
- package/nitrogen/generated/ios/swift/PredicateFromWorkout.swift +3 -3
- package/nitrogen/generated/ios/swift/PredicateWithMetadataKey.swift +95 -2
- package/nitrogen/generated/ios/swift/PredicateWithMetadataOperator.swift +48 -0
- package/nitrogen/generated/ios/swift/PredicateWithStartAndEnd.swift +4 -2
- package/nitrogen/generated/ios/swift/QuantitySample.swift +4 -2
- package/nitrogen/generated/ios/swift/QuantitySampleForSaving.swift +2 -1
- package/nitrogen/generated/ios/swift/QueryOptionsWithAnchor.swift +4 -2
- package/nitrogen/generated/ios/swift/QueryOptionsWithAnchorAndUnit.swift +6 -3
- package/nitrogen/generated/ios/swift/QueryOptionsWithSortOrder.swift +2 -1
- package/nitrogen/generated/ios/swift/QueryOptionsWithSortOrderAndUnit.swift +4 -2
- package/nitrogen/generated/ios/swift/QueryStatisticsResponse.swift +75 -8
- package/nitrogen/generated/ios/swift/QueryWorkoutSamplesWithAnchorResponse.swift +7 -7
- package/nitrogen/generated/ios/swift/SampleForSaving.swift +2 -0
- package/nitrogen/generated/ios/swift/SourceRevision.swift +13 -9
- package/nitrogen/generated/ios/swift/StateOfMindSample.swift +6 -3
- package/nitrogen/generated/ios/swift/StatisticsQueryOptions.swift +4 -2
- package/nitrogen/generated/ios/swift/Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_FilterForSamplesAnd_FilterForSamplesOr.swift +2 -0
- package/nitrogen/generated/ios/swift/Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_WorkoutActivityTypePredicate_WorkoutDurationPredicate_PredicateForWorkoutsOr_PredicateForWorkoutsAnd.swift +2 -0
- package/nitrogen/generated/ios/swift/Variant_String_Double_Bool_Date.swift +20 -0
- package/nitrogen/generated/ios/swift/WorkoutQueryOptions.swift +4 -61
- package/nitrogen/generated/ios/swift/WorkoutQueryOptionsWithAnchor.swift +6 -62
- package/nitrogen/generated/ios/swift/WorkoutRoute.swift +2 -1
- package/nitrogen/generated/ios/swift/WorkoutSample.swift +12 -123
- package/nitrogen/generated/shared/c++/AuthorizationRequestStatus.hpp +9 -11
- package/nitrogen/generated/shared/c++/AuthorizationStatus.hpp +9 -11
- package/nitrogen/generated/shared/c++/BiologicalSex.hpp +9 -11
- package/nitrogen/generated/shared/c++/BloodType.hpp +9 -11
- package/nitrogen/generated/shared/c++/CategorySample.hpp +14 -16
- package/nitrogen/generated/shared/c++/CategorySampleForSaving.hpp +11 -13
- package/nitrogen/generated/shared/c++/CategorySamplesWithAnchorResponse.hpp +11 -13
- package/nitrogen/generated/shared/c++/CategoryTypeIdentifier.hpp +131 -133
- package/nitrogen/generated/shared/c++/ComparisonPredicateOperator.hpp +26 -13
- package/nitrogen/generated/shared/c++/CorrelationSample.hpp +18 -15
- package/nitrogen/generated/shared/c++/CorrelationTypeIdentifier.hpp +7 -9
- package/nitrogen/generated/shared/c++/DeletedSample.hpp +5 -7
- package/nitrogen/generated/shared/c++/Device.hpp +5 -7
- package/nitrogen/generated/shared/c++/FilterForSamplesAnd.hpp +9 -11
- package/nitrogen/generated/shared/c++/FilterForSamplesOr.hpp +9 -11
- package/nitrogen/generated/shared/c++/FitzpatrickSkinType.hpp +9 -11
- package/nitrogen/generated/shared/c++/Heartbeat.hpp +4 -6
- package/nitrogen/generated/shared/c++/HeartbeatSeriesSample.hpp +15 -17
- package/nitrogen/generated/shared/c++/HeartbeatSeriesSamplesWithAnchorResponse.hpp +11 -13
- package/nitrogen/generated/shared/c++/HybridCategoryTypeModuleSpec.hpp +2 -2
- package/nitrogen/generated/shared/c++/HybridCharacteristicTypeModuleSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCoreModuleSpec.hpp +4 -4
- package/nitrogen/generated/shared/c++/HybridCorrelationTypeModuleSpec.hpp +2 -2
- package/nitrogen/generated/shared/c++/HybridHeartbeatSeriesModuleSpec.hpp +3 -3
- package/nitrogen/generated/shared/c++/HybridQuantityTypeModuleSpec.hpp +3 -3
- package/nitrogen/generated/shared/c++/HybridStateOfMindModuleSpec.hpp +3 -3
- package/nitrogen/generated/shared/c++/HybridWorkoutProxySpec.cpp +6 -4
- package/nitrogen/generated/shared/c++/HybridWorkoutProxySpec.hpp +18 -9
- package/nitrogen/generated/shared/c++/HybridWorkoutsModuleSpec.hpp +4 -4
- package/nitrogen/generated/shared/c++/IdentifierWithUnit.hpp +4 -6
- package/nitrogen/generated/shared/c++/IntervalComponents.hpp +4 -6
- package/nitrogen/generated/shared/c++/LocationForSaving.hpp +4 -6
- package/nitrogen/generated/shared/c++/ObjectTypeIdentifier.hpp +397 -399
- package/nitrogen/generated/shared/c++/OnChangeCallbackArgs.hpp +8 -10
- package/nitrogen/generated/shared/c++/PredicateForWorkoutsAnd.hpp +9 -11
- package/nitrogen/generated/shared/c++/PredicateForWorkoutsOr.hpp +9 -11
- package/nitrogen/generated/shared/c++/PredicateFromWorkout.hpp +6 -8
- package/nitrogen/generated/shared/c++/PredicateWithMetadataKey.hpp +20 -9
- package/nitrogen/generated/shared/c++/PredicateWithMetadataOperator.hpp +84 -0
- package/nitrogen/generated/shared/c++/PredicateWithStartAndEnd.hpp +5 -7
- package/nitrogen/generated/shared/c++/PredicateWithUUID.hpp +4 -6
- package/nitrogen/generated/shared/c++/PredicateWithUUIDs.hpp +5 -7
- package/nitrogen/generated/shared/c++/Quantity.hpp +4 -6
- package/nitrogen/generated/shared/c++/QuantityDateInterval.hpp +4 -6
- package/nitrogen/generated/shared/c++/QuantitySample.hpp +14 -16
- package/nitrogen/generated/shared/c++/QuantitySampleForSaving.hpp +11 -13
- package/nitrogen/generated/shared/c++/QuantitySamplesWithAnchorResponse.hpp +11 -13
- package/nitrogen/generated/shared/c++/QuantityTypeIdentifier.hpp +241 -243
- package/nitrogen/generated/shared/c++/QueryOptionsWithAnchor.hpp +9 -11
- package/nitrogen/generated/shared/c++/QueryOptionsWithAnchorAndUnit.hpp +9 -11
- package/nitrogen/generated/shared/c++/QueryOptionsWithSortOrder.hpp +8 -10
- package/nitrogen/generated/shared/c++/QueryOptionsWithSortOrderAndUnit.hpp +9 -11
- package/nitrogen/generated/shared/c++/QueryStatisticsResponse.hpp +36 -29
- package/nitrogen/generated/shared/c++/QueryWorkoutSamplesWithAnchorResponse.hpp +10 -12
- package/nitrogen/generated/shared/c++/SampleTypeIdentifier.hpp +383 -385
- package/nitrogen/generated/shared/c++/SampleTypeIdentifierWriteable.hpp +373 -375
- package/nitrogen/generated/shared/c++/Source.hpp +4 -6
- package/nitrogen/generated/shared/c++/SourceRevision.hpp +7 -9
- package/nitrogen/generated/shared/c++/StateOfMindAssociation.hpp +10 -12
- package/nitrogen/generated/shared/c++/StateOfMindKind.hpp +14 -13
- package/nitrogen/generated/shared/c++/StateOfMindLabel.hpp +10 -12
- package/nitrogen/generated/shared/c++/StateOfMindSample.hpp +24 -26
- package/nitrogen/generated/shared/c++/StateOfMindValenceClassification.hpp +10 -12
- package/nitrogen/generated/shared/c++/StatisticsOptions.hpp +17 -19
- package/nitrogen/generated/shared/c++/StatisticsQueryOptions.hpp +9 -11
- package/nitrogen/generated/shared/c++/UpdateFrequency.hpp +10 -12
- package/nitrogen/generated/shared/c++/WheelchairUse.hpp +9 -11
- package/nitrogen/generated/shared/c++/WorkoutActivity.hpp +4 -6
- package/nitrogen/generated/shared/c++/WorkoutActivityType.hpp +96 -13
- package/nitrogen/generated/shared/c++/WorkoutActivityTypePredicate.hpp +7 -9
- package/nitrogen/generated/shared/c++/WorkoutConfiguration.hpp +11 -13
- package/nitrogen/generated/shared/c++/WorkoutDurationPredicate.hpp +7 -9
- package/nitrogen/generated/shared/c++/WorkoutEvent.hpp +7 -9
- package/nitrogen/generated/shared/c++/WorkoutEventType.hpp +10 -12
- package/nitrogen/generated/shared/c++/WorkoutPlan.hpp +7 -9
- package/nitrogen/generated/shared/c++/WorkoutQueryOptions.hpp +10 -21
- package/nitrogen/generated/shared/c++/WorkoutQueryOptionsWithAnchor.hpp +11 -21
- package/nitrogen/generated/shared/c++/WorkoutRoute.hpp +9 -11
- package/nitrogen/generated/shared/c++/WorkoutRouteLocation.hpp +4 -6
- package/nitrogen/generated/shared/c++/WorkoutSample.hpp +25 -43
- package/nitrogen/generated/shared/c++/WorkoutSessionLocationType.hpp +10 -12
- package/nitrogen/generated/shared/c++/WorkoutTotals.hpp +4 -6
- package/package.json +11 -11
- package/src/healthkit.ts +5 -1
- package/src/hooks/queryStatisticsForQuantity.test.ts +32 -0
- package/src/hooks/useMostRecentWorkout.ts +3 -17
- package/src/hooks/useWorkoutById.ts +1 -4
- package/src/specs/WorkoutProxy.nitro.ts +18 -1
- package/src/types/CorrelationType.ts +1 -0
- package/src/types/QuantityType.ts +2 -0
- package/src/types/QueryOptions.ts +10 -0
- package/src/types/Workouts.ts +0 -8
- package/src/utils/getMostRecentWorkout.ts +1 -6
- package/src/utils/getWorkoutById.ts +1 -6
|
@@ -50,14 +50,12 @@ namespace margelo::nitro::healthkit {
|
|
|
50
50
|
|
|
51
51
|
namespace margelo::nitro {
|
|
52
52
|
|
|
53
|
-
using namespace margelo::nitro::healthkit;
|
|
54
|
-
|
|
55
53
|
// C++ WorkoutRouteLocation <> JS WorkoutRouteLocation (object)
|
|
56
54
|
template <>
|
|
57
|
-
struct JSIConverter<WorkoutRouteLocation> final {
|
|
58
|
-
static inline WorkoutRouteLocation fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
55
|
+
struct JSIConverter<margelo::nitro::healthkit::WorkoutRouteLocation> final {
|
|
56
|
+
static inline margelo::nitro::healthkit::WorkoutRouteLocation fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
59
57
|
jsi::Object obj = arg.asObject(runtime);
|
|
60
|
-
return WorkoutRouteLocation(
|
|
58
|
+
return margelo::nitro::healthkit::WorkoutRouteLocation(
|
|
61
59
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "altitude")),
|
|
62
60
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "course")),
|
|
63
61
|
JSIConverter<std::chrono::system_clock::time_point>::fromJSI(runtime, obj.getProperty(runtime, "date")),
|
|
@@ -70,7 +68,7 @@ namespace margelo::nitro {
|
|
|
70
68
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "verticalAccuracy"))
|
|
71
69
|
);
|
|
72
70
|
}
|
|
73
|
-
static inline jsi::Value toJSI(jsi::Runtime& runtime, const WorkoutRouteLocation& arg) {
|
|
71
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::healthkit::WorkoutRouteLocation& arg) {
|
|
74
72
|
jsi::Object obj(runtime);
|
|
75
73
|
obj.setProperty(runtime, "altitude", JSIConverter<double>::toJSI(runtime, arg.altitude));
|
|
76
74
|
obj.setProperty(runtime, "course", JSIConverter<double>::toJSI(runtime, arg.course));
|
|
@@ -34,15 +34,15 @@ namespace margelo::nitro::healthkit { struct WorkoutEvent; }
|
|
|
34
34
|
namespace margelo::nitro::healthkit { struct WorkoutActivity; }
|
|
35
35
|
|
|
36
36
|
#include <string>
|
|
37
|
-
#include <optional>
|
|
38
37
|
#include "Device.hpp"
|
|
38
|
+
#include <optional>
|
|
39
39
|
#include "WorkoutActivityType.hpp"
|
|
40
40
|
#include "Quantity.hpp"
|
|
41
41
|
#include <chrono>
|
|
42
42
|
#include <NitroModules/AnyMap.hpp>
|
|
43
43
|
#include "SourceRevision.hpp"
|
|
44
|
-
#include <vector>
|
|
45
44
|
#include "WorkoutEvent.hpp"
|
|
45
|
+
#include <vector>
|
|
46
46
|
#include "WorkoutActivity.hpp"
|
|
47
47
|
|
|
48
48
|
namespace margelo::nitro::healthkit {
|
|
@@ -56,10 +56,6 @@ namespace margelo::nitro::healthkit {
|
|
|
56
56
|
std::optional<Device> device SWIFT_PRIVATE;
|
|
57
57
|
WorkoutActivityType workoutActivityType SWIFT_PRIVATE;
|
|
58
58
|
Quantity duration SWIFT_PRIVATE;
|
|
59
|
-
std::optional<Quantity> totalDistance SWIFT_PRIVATE;
|
|
60
|
-
std::optional<Quantity> totalEnergyBurned SWIFT_PRIVATE;
|
|
61
|
-
std::optional<Quantity> totalSwimmingStrokeCount SWIFT_PRIVATE;
|
|
62
|
-
std::optional<Quantity> totalFlightsClimbed SWIFT_PRIVATE;
|
|
63
59
|
std::chrono::system_clock::time_point startDate SWIFT_PRIVATE;
|
|
64
60
|
std::chrono::system_clock::time_point endDate SWIFT_PRIVATE;
|
|
65
61
|
std::optional<std::shared_ptr<AnyMap>> metadata SWIFT_PRIVATE;
|
|
@@ -69,53 +65,43 @@ namespace margelo::nitro::healthkit {
|
|
|
69
65
|
|
|
70
66
|
public:
|
|
71
67
|
WorkoutSample() = default;
|
|
72
|
-
explicit WorkoutSample(std::string uuid, std::optional<Device> device, WorkoutActivityType workoutActivityType, Quantity duration, std::
|
|
68
|
+
explicit WorkoutSample(std::string uuid, std::optional<Device> device, WorkoutActivityType workoutActivityType, Quantity duration, std::chrono::system_clock::time_point startDate, std::chrono::system_clock::time_point endDate, std::optional<std::shared_ptr<AnyMap>> metadata, std::optional<SourceRevision> sourceRevision, std::optional<std::vector<WorkoutEvent>> events, std::optional<std::vector<WorkoutActivity>> activities): uuid(uuid), device(device), workoutActivityType(workoutActivityType), duration(duration), startDate(startDate), endDate(endDate), metadata(metadata), sourceRevision(sourceRevision), events(events), activities(activities) {}
|
|
73
69
|
};
|
|
74
70
|
|
|
75
71
|
} // namespace margelo::nitro::healthkit
|
|
76
72
|
|
|
77
73
|
namespace margelo::nitro {
|
|
78
74
|
|
|
79
|
-
using namespace margelo::nitro::healthkit;
|
|
80
|
-
|
|
81
75
|
// C++ WorkoutSample <> JS WorkoutSample (object)
|
|
82
76
|
template <>
|
|
83
|
-
struct JSIConverter<WorkoutSample> final {
|
|
84
|
-
static inline WorkoutSample fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
77
|
+
struct JSIConverter<margelo::nitro::healthkit::WorkoutSample> final {
|
|
78
|
+
static inline margelo::nitro::healthkit::WorkoutSample fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
85
79
|
jsi::Object obj = arg.asObject(runtime);
|
|
86
|
-
return WorkoutSample(
|
|
80
|
+
return margelo::nitro::healthkit::WorkoutSample(
|
|
87
81
|
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "uuid")),
|
|
88
|
-
JSIConverter<std::optional<Device>>::fromJSI(runtime, obj.getProperty(runtime, "device")),
|
|
89
|
-
JSIConverter<WorkoutActivityType>::fromJSI(runtime, obj.getProperty(runtime, "workoutActivityType")),
|
|
90
|
-
JSIConverter<Quantity>::fromJSI(runtime, obj.getProperty(runtime, "duration")),
|
|
91
|
-
JSIConverter<std::optional<Quantity>>::fromJSI(runtime, obj.getProperty(runtime, "totalDistance")),
|
|
92
|
-
JSIConverter<std::optional<Quantity>>::fromJSI(runtime, obj.getProperty(runtime, "totalEnergyBurned")),
|
|
93
|
-
JSIConverter<std::optional<Quantity>>::fromJSI(runtime, obj.getProperty(runtime, "totalSwimmingStrokeCount")),
|
|
94
|
-
JSIConverter<std::optional<Quantity>>::fromJSI(runtime, obj.getProperty(runtime, "totalFlightsClimbed")),
|
|
82
|
+
JSIConverter<std::optional<margelo::nitro::healthkit::Device>>::fromJSI(runtime, obj.getProperty(runtime, "device")),
|
|
83
|
+
JSIConverter<margelo::nitro::healthkit::WorkoutActivityType>::fromJSI(runtime, obj.getProperty(runtime, "workoutActivityType")),
|
|
84
|
+
JSIConverter<margelo::nitro::healthkit::Quantity>::fromJSI(runtime, obj.getProperty(runtime, "duration")),
|
|
95
85
|
JSIConverter<std::chrono::system_clock::time_point>::fromJSI(runtime, obj.getProperty(runtime, "startDate")),
|
|
96
86
|
JSIConverter<std::chrono::system_clock::time_point>::fromJSI(runtime, obj.getProperty(runtime, "endDate")),
|
|
97
87
|
JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::fromJSI(runtime, obj.getProperty(runtime, "metadata")),
|
|
98
|
-
JSIConverter<std::optional<SourceRevision>>::fromJSI(runtime, obj.getProperty(runtime, "sourceRevision")),
|
|
99
|
-
JSIConverter<std::optional<std::vector<WorkoutEvent>>>::fromJSI(runtime, obj.getProperty(runtime, "events")),
|
|
100
|
-
JSIConverter<std::optional<std::vector<WorkoutActivity>>>::fromJSI(runtime, obj.getProperty(runtime, "activities"))
|
|
88
|
+
JSIConverter<std::optional<margelo::nitro::healthkit::SourceRevision>>::fromJSI(runtime, obj.getProperty(runtime, "sourceRevision")),
|
|
89
|
+
JSIConverter<std::optional<std::vector<margelo::nitro::healthkit::WorkoutEvent>>>::fromJSI(runtime, obj.getProperty(runtime, "events")),
|
|
90
|
+
JSIConverter<std::optional<std::vector<margelo::nitro::healthkit::WorkoutActivity>>>::fromJSI(runtime, obj.getProperty(runtime, "activities"))
|
|
101
91
|
);
|
|
102
92
|
}
|
|
103
|
-
static inline jsi::Value toJSI(jsi::Runtime& runtime, const WorkoutSample& arg) {
|
|
93
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::healthkit::WorkoutSample& arg) {
|
|
104
94
|
jsi::Object obj(runtime);
|
|
105
95
|
obj.setProperty(runtime, "uuid", JSIConverter<std::string>::toJSI(runtime, arg.uuid));
|
|
106
|
-
obj.setProperty(runtime, "device", JSIConverter<std::optional<Device>>::toJSI(runtime, arg.device));
|
|
107
|
-
obj.setProperty(runtime, "workoutActivityType", JSIConverter<WorkoutActivityType>::toJSI(runtime, arg.workoutActivityType));
|
|
108
|
-
obj.setProperty(runtime, "duration", JSIConverter<Quantity>::toJSI(runtime, arg.duration));
|
|
109
|
-
obj.setProperty(runtime, "totalDistance", JSIConverter<std::optional<Quantity>>::toJSI(runtime, arg.totalDistance));
|
|
110
|
-
obj.setProperty(runtime, "totalEnergyBurned", JSIConverter<std::optional<Quantity>>::toJSI(runtime, arg.totalEnergyBurned));
|
|
111
|
-
obj.setProperty(runtime, "totalSwimmingStrokeCount", JSIConverter<std::optional<Quantity>>::toJSI(runtime, arg.totalSwimmingStrokeCount));
|
|
112
|
-
obj.setProperty(runtime, "totalFlightsClimbed", JSIConverter<std::optional<Quantity>>::toJSI(runtime, arg.totalFlightsClimbed));
|
|
96
|
+
obj.setProperty(runtime, "device", JSIConverter<std::optional<margelo::nitro::healthkit::Device>>::toJSI(runtime, arg.device));
|
|
97
|
+
obj.setProperty(runtime, "workoutActivityType", JSIConverter<margelo::nitro::healthkit::WorkoutActivityType>::toJSI(runtime, arg.workoutActivityType));
|
|
98
|
+
obj.setProperty(runtime, "duration", JSIConverter<margelo::nitro::healthkit::Quantity>::toJSI(runtime, arg.duration));
|
|
113
99
|
obj.setProperty(runtime, "startDate", JSIConverter<std::chrono::system_clock::time_point>::toJSI(runtime, arg.startDate));
|
|
114
100
|
obj.setProperty(runtime, "endDate", JSIConverter<std::chrono::system_clock::time_point>::toJSI(runtime, arg.endDate));
|
|
115
101
|
obj.setProperty(runtime, "metadata", JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::toJSI(runtime, arg.metadata));
|
|
116
|
-
obj.setProperty(runtime, "sourceRevision", JSIConverter<std::optional<SourceRevision>>::toJSI(runtime, arg.sourceRevision));
|
|
117
|
-
obj.setProperty(runtime, "events", JSIConverter<std::optional<std::vector<WorkoutEvent>>>::toJSI(runtime, arg.events));
|
|
118
|
-
obj.setProperty(runtime, "activities", JSIConverter<std::optional<std::vector<WorkoutActivity>>>::toJSI(runtime, arg.activities));
|
|
102
|
+
obj.setProperty(runtime, "sourceRevision", JSIConverter<std::optional<margelo::nitro::healthkit::SourceRevision>>::toJSI(runtime, arg.sourceRevision));
|
|
103
|
+
obj.setProperty(runtime, "events", JSIConverter<std::optional<std::vector<margelo::nitro::healthkit::WorkoutEvent>>>::toJSI(runtime, arg.events));
|
|
104
|
+
obj.setProperty(runtime, "activities", JSIConverter<std::optional<std::vector<margelo::nitro::healthkit::WorkoutActivity>>>::toJSI(runtime, arg.activities));
|
|
119
105
|
return obj;
|
|
120
106
|
}
|
|
121
107
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -124,19 +110,15 @@ namespace margelo::nitro {
|
|
|
124
110
|
}
|
|
125
111
|
jsi::Object obj = value.getObject(runtime);
|
|
126
112
|
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "uuid"))) return false;
|
|
127
|
-
if (!JSIConverter<std::optional<Device>>::canConvert(runtime, obj.getProperty(runtime, "device"))) return false;
|
|
128
|
-
if (!JSIConverter<WorkoutActivityType>::canConvert(runtime, obj.getProperty(runtime, "workoutActivityType"))) return false;
|
|
129
|
-
if (!JSIConverter<Quantity>::canConvert(runtime, obj.getProperty(runtime, "duration"))) return false;
|
|
130
|
-
if (!JSIConverter<std::optional<Quantity>>::canConvert(runtime, obj.getProperty(runtime, "totalDistance"))) return false;
|
|
131
|
-
if (!JSIConverter<std::optional<Quantity>>::canConvert(runtime, obj.getProperty(runtime, "totalEnergyBurned"))) return false;
|
|
132
|
-
if (!JSIConverter<std::optional<Quantity>>::canConvert(runtime, obj.getProperty(runtime, "totalSwimmingStrokeCount"))) return false;
|
|
133
|
-
if (!JSIConverter<std::optional<Quantity>>::canConvert(runtime, obj.getProperty(runtime, "totalFlightsClimbed"))) return false;
|
|
113
|
+
if (!JSIConverter<std::optional<margelo::nitro::healthkit::Device>>::canConvert(runtime, obj.getProperty(runtime, "device"))) return false;
|
|
114
|
+
if (!JSIConverter<margelo::nitro::healthkit::WorkoutActivityType>::canConvert(runtime, obj.getProperty(runtime, "workoutActivityType"))) return false;
|
|
115
|
+
if (!JSIConverter<margelo::nitro::healthkit::Quantity>::canConvert(runtime, obj.getProperty(runtime, "duration"))) return false;
|
|
134
116
|
if (!JSIConverter<std::chrono::system_clock::time_point>::canConvert(runtime, obj.getProperty(runtime, "startDate"))) return false;
|
|
135
117
|
if (!JSIConverter<std::chrono::system_clock::time_point>::canConvert(runtime, obj.getProperty(runtime, "endDate"))) return false;
|
|
136
118
|
if (!JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::canConvert(runtime, obj.getProperty(runtime, "metadata"))) return false;
|
|
137
|
-
if (!JSIConverter<std::optional<SourceRevision>>::canConvert(runtime, obj.getProperty(runtime, "sourceRevision"))) return false;
|
|
138
|
-
if (!JSIConverter<std::optional<std::vector<WorkoutEvent>>>::canConvert(runtime, obj.getProperty(runtime, "events"))) return false;
|
|
139
|
-
if (!JSIConverter<std::optional<std::vector<WorkoutActivity>>>::canConvert(runtime, obj.getProperty(runtime, "activities"))) return false;
|
|
119
|
+
if (!JSIConverter<std::optional<margelo::nitro::healthkit::SourceRevision>>::canConvert(runtime, obj.getProperty(runtime, "sourceRevision"))) return false;
|
|
120
|
+
if (!JSIConverter<std::optional<std::vector<margelo::nitro::healthkit::WorkoutEvent>>>::canConvert(runtime, obj.getProperty(runtime, "events"))) return false;
|
|
121
|
+
if (!JSIConverter<std::optional<std::vector<margelo::nitro::healthkit::WorkoutActivity>>>::canConvert(runtime, obj.getProperty(runtime, "activities"))) return false;
|
|
140
122
|
return true;
|
|
141
123
|
}
|
|
142
124
|
};
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
|
-
#include <cmath>
|
|
11
10
|
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
12
11
|
#include <NitroModules/JSIConverter.hpp>
|
|
13
12
|
#else
|
|
@@ -34,16 +33,14 @@ namespace margelo::nitro::healthkit {
|
|
|
34
33
|
|
|
35
34
|
namespace margelo::nitro {
|
|
36
35
|
|
|
37
|
-
using namespace margelo::nitro::healthkit;
|
|
38
|
-
|
|
39
36
|
// C++ WorkoutSessionLocationType <> JS WorkoutSessionLocationType (enum)
|
|
40
37
|
template <>
|
|
41
|
-
struct JSIConverter<WorkoutSessionLocationType> final {
|
|
42
|
-
static inline WorkoutSessionLocationType fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
38
|
+
struct JSIConverter<margelo::nitro::healthkit::WorkoutSessionLocationType> final {
|
|
39
|
+
static inline margelo::nitro::healthkit::WorkoutSessionLocationType fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
43
40
|
int enumValue = JSIConverter<int>::fromJSI(runtime, arg);
|
|
44
|
-
return static_cast<WorkoutSessionLocationType>(enumValue);
|
|
41
|
+
return static_cast<margelo::nitro::healthkit::WorkoutSessionLocationType>(enumValue);
|
|
45
42
|
}
|
|
46
|
-
static inline jsi::Value toJSI(jsi::Runtime& runtime, WorkoutSessionLocationType arg) {
|
|
43
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::healthkit::WorkoutSessionLocationType arg) {
|
|
47
44
|
int enumValue = static_cast<int>(arg);
|
|
48
45
|
return JSIConverter<int>::toJSI(runtime, enumValue);
|
|
49
46
|
}
|
|
@@ -51,14 +48,15 @@ namespace margelo::nitro {
|
|
|
51
48
|
if (!value.isNumber()) {
|
|
52
49
|
return false;
|
|
53
50
|
}
|
|
54
|
-
double
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
//
|
|
51
|
+
double number = value.getNumber();
|
|
52
|
+
int integer = static_cast<int>(number);
|
|
53
|
+
if (number != integer) {
|
|
54
|
+
// The integer is not the same value as the double - we truncated floating points.
|
|
55
|
+
// Enums are all integers, so the input floating point number is obviously invalid.
|
|
58
56
|
return false;
|
|
59
57
|
}
|
|
60
58
|
// Check if we are within the bounds of the enum.
|
|
61
|
-
return integer >=
|
|
59
|
+
return integer >= 1 && integer <= 3;
|
|
62
60
|
}
|
|
63
61
|
};
|
|
64
62
|
|
|
@@ -41,19 +41,17 @@ namespace margelo::nitro::healthkit {
|
|
|
41
41
|
|
|
42
42
|
namespace margelo::nitro {
|
|
43
43
|
|
|
44
|
-
using namespace margelo::nitro::healthkit;
|
|
45
|
-
|
|
46
44
|
// C++ WorkoutTotals <> JS WorkoutTotals (object)
|
|
47
45
|
template <>
|
|
48
|
-
struct JSIConverter<WorkoutTotals> final {
|
|
49
|
-
static inline WorkoutTotals fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
46
|
+
struct JSIConverter<margelo::nitro::healthkit::WorkoutTotals> final {
|
|
47
|
+
static inline margelo::nitro::healthkit::WorkoutTotals fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
50
48
|
jsi::Object obj = arg.asObject(runtime);
|
|
51
|
-
return WorkoutTotals(
|
|
49
|
+
return margelo::nitro::healthkit::WorkoutTotals(
|
|
52
50
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "distance")),
|
|
53
51
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "energyBurned"))
|
|
54
52
|
);
|
|
55
53
|
}
|
|
56
|
-
static inline jsi::Value toJSI(jsi::Runtime& runtime, const WorkoutTotals& arg) {
|
|
54
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::healthkit::WorkoutTotals& arg) {
|
|
57
55
|
jsi::Object obj(runtime);
|
|
58
56
|
obj.setProperty(runtime, "distance", JSIConverter<std::optional<double>>::toJSI(runtime, arg.distance));
|
|
59
57
|
obj.setProperty(runtime, "energyBurned", JSIConverter<std::optional<double>>::toJSI(runtime, arg.energyBurned));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kingstinct/react-native-healthkit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "React Native bindings for HealthKit",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types",
|
|
59
59
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
60
60
|
"lint": "bunx @biomejs/biome format --write",
|
|
61
|
-
"codegen": "bun run build &&
|
|
61
|
+
"codegen": "bun run build && nitrogen --logLevel=\"debug\"",
|
|
62
62
|
"test": "bun test",
|
|
63
63
|
"prepublishOnly": "bun run build && bun run codegen"
|
|
64
64
|
},
|
|
@@ -88,17 +88,17 @@
|
|
|
88
88
|
"access": "public"
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
|
-
"@testing-library/react-native": "^13.
|
|
91
|
+
"@testing-library/react-native": "^13.3.3",
|
|
92
92
|
"@types/react": "~19.0.14",
|
|
93
|
-
"
|
|
94
|
-
"react": "19.
|
|
95
|
-
"react-native": "
|
|
96
|
-
"react-native-nitro-modules": "^0.
|
|
97
|
-
"typescript": "~5.
|
|
93
|
+
"nitrogen": "^0.29.4",
|
|
94
|
+
"react": "19.1.0",
|
|
95
|
+
"react-native": "0.81.4",
|
|
96
|
+
"react-native-nitro-modules": "^0.29.6",
|
|
97
|
+
"typescript": "~5.9.2"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
100
|
-
"react": "
|
|
101
|
-
"react-native": "
|
|
102
|
-
"react-native-nitro-modules": "
|
|
100
|
+
"react": "19.1.0",
|
|
101
|
+
"react-native": "0.81.4",
|
|
102
|
+
"react-native-nitro-modules": "0.29.6"
|
|
103
103
|
}
|
|
104
104
|
}
|
package/src/healthkit.ts
CHANGED
|
@@ -21,7 +21,10 @@ import {
|
|
|
21
21
|
WheelchairUse,
|
|
22
22
|
} from './types/Characteristics'
|
|
23
23
|
import type { QuantitySample } from './types/QuantitySample'
|
|
24
|
-
import type {
|
|
24
|
+
import type {
|
|
25
|
+
QueryOptionsWithAnchor,
|
|
26
|
+
QueryOptionsWithSortOrder,
|
|
27
|
+
} from './types/QueryOptions'
|
|
25
28
|
|
|
26
29
|
export * from './types'
|
|
27
30
|
|
|
@@ -174,6 +177,7 @@ export const isQuantityCompatibleWithUnit = UnavailableFnFromModule(
|
|
|
174
177
|
// CategoryTypeModule functions
|
|
175
178
|
export function queryCategorySamples<T extends CategoryTypeIdentifier>(
|
|
176
179
|
_categoryTypeIdentifier: T,
|
|
180
|
+
_options?: QueryOptionsWithSortOrder,
|
|
177
181
|
): Promise<CategorySampleTyped<T>[]> {
|
|
178
182
|
if (Platform.OS !== 'ios' && !hasWarned) {
|
|
179
183
|
console.warn(notAvailableError)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test case to verify that queryStatisticsForQuantity resolves when no data is present
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, expect, test } from 'bun:test'
|
|
6
|
+
import type { QueryStatisticsResponse } from '../types/QuantityType'
|
|
7
|
+
|
|
8
|
+
describe('queryStatisticsForQuantity', () => {
|
|
9
|
+
test('should resolve with empty response when no data is present', async () => {
|
|
10
|
+
// This test would normally require running on iOS simulator or device
|
|
11
|
+
// For now, we're just testing the TypeScript interface
|
|
12
|
+
|
|
13
|
+
const mockEmptyResponse: QueryStatisticsResponse = {}
|
|
14
|
+
|
|
15
|
+
// Verify that empty response is properly typed
|
|
16
|
+
expect(mockEmptyResponse.averageQuantity).toBeUndefined()
|
|
17
|
+
expect(mockEmptyResponse.sumQuantity).toBeUndefined()
|
|
18
|
+
expect(mockEmptyResponse.startDate).toBeUndefined()
|
|
19
|
+
expect(mockEmptyResponse.endDate).toBeUndefined()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('should handle date range with no data', async () => {
|
|
23
|
+
// This is more of a documentation of the expected behavior
|
|
24
|
+
// The query should resolve with an empty response object
|
|
25
|
+
// when there's no data in the specified timeframe
|
|
26
|
+
const expectedResult: QueryStatisticsResponse = {
|
|
27
|
+
// All properties should be undefined for empty result
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
expect(expectedResult).toBeDefined()
|
|
31
|
+
})
|
|
32
|
+
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useEffect,
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react'
|
|
2
2
|
import type { WorkoutProxy } from '../specs/WorkoutProxy.nitro'
|
|
3
3
|
import getMostRecentWorkout from '../utils/getMostRecentWorkout'
|
|
4
4
|
import useSubscribeToChanges from './useSubscribeToChanges'
|
|
@@ -6,25 +6,11 @@ import useSubscribeToChanges from './useSubscribeToChanges'
|
|
|
6
6
|
/**
|
|
7
7
|
* @returns the most recent workout sample.
|
|
8
8
|
*/
|
|
9
|
-
export function useMostRecentWorkout(
|
|
10
|
-
readonly energyUnit?: string
|
|
11
|
-
readonly distanceUnit?: string
|
|
12
|
-
}) {
|
|
9
|
+
export function useMostRecentWorkout() {
|
|
13
10
|
const [workout, setWorkout] = useState<WorkoutProxy>()
|
|
14
11
|
|
|
15
|
-
const optionsRef = useRef(options)
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
optionsRef.current = options
|
|
19
|
-
}, [options])
|
|
20
|
-
|
|
21
12
|
const update = useCallback(async () => {
|
|
22
|
-
setWorkout(
|
|
23
|
-
await getMostRecentWorkout({
|
|
24
|
-
energyUnit: optionsRef.current?.energyUnit,
|
|
25
|
-
distanceUnit: optionsRef.current?.distanceUnit,
|
|
26
|
-
}),
|
|
27
|
-
)
|
|
13
|
+
setWorkout(await getMostRecentWorkout())
|
|
28
14
|
}, [])
|
|
29
15
|
|
|
30
16
|
useEffect(() => {
|
|
@@ -27,10 +27,7 @@ export function useWorkoutById(
|
|
|
27
27
|
setIsLoading(true)
|
|
28
28
|
setError(null)
|
|
29
29
|
try {
|
|
30
|
-
const fetchedWorkout = await getWorkoutById(uuid
|
|
31
|
-
energyUnit: optionsRef.current?.energyUnit,
|
|
32
|
-
distanceUnit: optionsRef.current?.distanceUnit,
|
|
33
|
-
})
|
|
30
|
+
const fetchedWorkout = await getWorkoutById(uuid)
|
|
34
31
|
setWorkout(fetchedWorkout)
|
|
35
32
|
} catch (err) {
|
|
36
33
|
setError(
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { HybridObject } from 'react-native-nitro-modules'
|
|
2
|
+
import type {
|
|
3
|
+
Quantity,
|
|
4
|
+
QuantityTypeIdentifier,
|
|
5
|
+
QueryStatisticsResponse,
|
|
6
|
+
} from '../types'
|
|
2
7
|
import type {
|
|
3
8
|
LocationForSaving,
|
|
4
9
|
WorkoutPlan,
|
|
@@ -13,6 +18,18 @@ export interface WorkoutProxy
|
|
|
13
18
|
saveWorkoutRoute(locations: readonly LocationForSaving[]): Promise<boolean>
|
|
14
19
|
getWorkoutPlan(): Promise<WorkoutPlan | null>
|
|
15
20
|
getWorkoutRoutes(): Promise<readonly WorkoutRoute[]>
|
|
21
|
+
getStatistic(
|
|
22
|
+
quantityType: QuantityTypeIdentifier,
|
|
23
|
+
unitOverride?: string,
|
|
24
|
+
): Promise<QueryStatisticsResponse | null>
|
|
25
|
+
getAllStatistics(): Promise<Record<string, QueryStatisticsResponse>>
|
|
16
26
|
|
|
17
|
-
|
|
27
|
+
/** @deprecated Use allStatistics or statistic() method instead */
|
|
28
|
+
readonly totalDistance?: Quantity
|
|
29
|
+
/** @deprecated Use allStatistics or statistic() method instead */
|
|
30
|
+
readonly totalEnergyBurned?: Quantity
|
|
31
|
+
/** @deprecated Use allStatistics or statistic() method instead */
|
|
32
|
+
readonly totalSwimmingStrokeCount?: Quantity
|
|
33
|
+
/** @deprecated Use allStatistics or statistic() method instead */
|
|
34
|
+
readonly totalFlightsClimbed?: Quantity
|
|
18
35
|
}
|
|
@@ -13,6 +13,7 @@ export type CorrelationTypeIdentifier =
|
|
|
13
13
|
type CorrelationObject = CategorySample | QuantitySample
|
|
14
14
|
|
|
15
15
|
export interface CorrelationSample {
|
|
16
|
+
readonly uuid: string
|
|
16
17
|
readonly correlationType: CorrelationTypeIdentifier
|
|
17
18
|
readonly objects: readonly CorrelationObject[]
|
|
18
19
|
readonly metadata: AnyMap
|
|
@@ -28,6 +28,8 @@ export interface QueryStatisticsResponse {
|
|
|
28
28
|
readonly mostRecentQuantity?: Quantity
|
|
29
29
|
readonly mostRecentQuantityDateInterval?: QuantityDateInterval
|
|
30
30
|
readonly duration?: Quantity
|
|
31
|
+
readonly startDate?: Date
|
|
32
|
+
readonly endDate?: Date
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
export interface QuantitySamplesWithAnchorResponse {
|
|
@@ -15,8 +15,18 @@ type PredicateWithStartAndEnd = {
|
|
|
15
15
|
readonly strictStartDate?: boolean
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
type PredicateWithMetadataOperator =
|
|
19
|
+
| 'equalTo'
|
|
20
|
+
| 'notEqualTo'
|
|
21
|
+
| 'greaterThan'
|
|
22
|
+
| 'lessThan'
|
|
23
|
+
|
|
24
|
+
type PredicateWithMetadataValue = string | number | Date | boolean
|
|
25
|
+
|
|
18
26
|
type PredicateWithMetadataKey = {
|
|
19
27
|
readonly withMetadataKey: string
|
|
28
|
+
readonly operatorType?: PredicateWithMetadataOperator
|
|
29
|
+
readonly value?: PredicateWithMetadataValue
|
|
20
30
|
}
|
|
21
31
|
|
|
22
32
|
export type FilterForSamplesAnd = {
|
package/src/types/Workouts.ts
CHANGED
|
@@ -215,16 +215,12 @@ export type FilterForWorkouts =
|
|
|
215
215
|
| PredicateForWorkoutsAnd
|
|
216
216
|
|
|
217
217
|
export interface WorkoutQueryOptionsWithAnchor {
|
|
218
|
-
energyUnit?: string
|
|
219
|
-
distanceUnit?: string
|
|
220
218
|
filter?: FilterForWorkouts
|
|
221
219
|
limit?: number
|
|
222
220
|
anchor?: string
|
|
223
221
|
}
|
|
224
222
|
|
|
225
223
|
export interface WorkoutQueryOptions {
|
|
226
|
-
energyUnit?: string
|
|
227
|
-
distanceUnit?: string
|
|
228
224
|
filter?: FilterForWorkouts
|
|
229
225
|
limit?: number
|
|
230
226
|
ascending?: boolean
|
|
@@ -269,10 +265,6 @@ export interface WorkoutSample {
|
|
|
269
265
|
readonly device?: Device
|
|
270
266
|
readonly workoutActivityType: WorkoutActivityType
|
|
271
267
|
readonly duration: Quantity
|
|
272
|
-
readonly totalDistance?: Quantity
|
|
273
|
-
readonly totalEnergyBurned?: Quantity
|
|
274
|
-
readonly totalSwimmingStrokeCount?: Quantity
|
|
275
|
-
readonly totalFlightsClimbed?: Quantity
|
|
276
268
|
readonly startDate: Date
|
|
277
269
|
readonly endDate: Date
|
|
278
270
|
readonly metadata?: AnyMap
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { Workouts } from '../modules'
|
|
2
|
-
import type { WorkoutQueryOptions } from '../types/Workouts'
|
|
3
2
|
|
|
4
|
-
const getMostRecentWorkout = async (
|
|
5
|
-
options: Pick<WorkoutQueryOptions, 'distanceUnit' | 'energyUnit'>,
|
|
6
|
-
) => {
|
|
3
|
+
const getMostRecentWorkout = async () => {
|
|
7
4
|
const workouts = await Workouts.queryWorkoutSamples({
|
|
8
5
|
limit: 1,
|
|
9
6
|
ascending: false,
|
|
10
|
-
energyUnit: options?.energyUnit,
|
|
11
|
-
distanceUnit: options?.distanceUnit,
|
|
12
7
|
})
|
|
13
8
|
|
|
14
9
|
return workouts[0]
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { Workouts } from '../modules'
|
|
2
2
|
import type { WorkoutQueryOptions } from '../types/Workouts'
|
|
3
3
|
|
|
4
|
-
const getWorkoutById = async (
|
|
5
|
-
uuid: string,
|
|
6
|
-
options: Pick<WorkoutQueryOptions, 'distanceUnit' | 'energyUnit'>,
|
|
7
|
-
) => {
|
|
4
|
+
const getWorkoutById = async (uuid: string) => {
|
|
8
5
|
const workouts = await Workouts.queryWorkoutSamples({
|
|
9
6
|
limit: 1,
|
|
10
7
|
filter: {
|
|
11
8
|
uuid: uuid,
|
|
12
9
|
},
|
|
13
|
-
energyUnit: options?.energyUnit,
|
|
14
|
-
distanceUnit: options?.distanceUnit,
|
|
15
10
|
})
|
|
16
11
|
|
|
17
12
|
return workouts[0]
|