@kingstinct/react-native-healthkit 4.4.6 → 5.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/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcuserdata/robertherber.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/commonjs/hooks/useHealthkitAuthorization.js +41 -0
- package/lib/commonjs/hooks/useHealthkitAuthorization.js.map +1 -0
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js +29 -0
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js.map +1 -0
- package/lib/commonjs/hooks/useMostRecentCategorySample.js +27 -0
- package/lib/commonjs/hooks/useMostRecentCategorySample.js.map +1 -0
- package/lib/commonjs/hooks/useMostRecentQuantitySample.js +43 -0
- package/lib/commonjs/hooks/useMostRecentQuantitySample.js.map +1 -0
- package/lib/commonjs/hooks/useMostRecentWorkout.js +60 -0
- package/lib/commonjs/hooks/useMostRecentWorkout.js.map +1 -0
- package/lib/commonjs/hooks/useStatisticsForQuantity.js +35 -0
- package/lib/commonjs/hooks/useStatisticsForQuantity.js.map +1 -0
- package/lib/commonjs/hooks/useSubscribeToChanges.js +37 -0
- package/lib/commonjs/hooks/useSubscribeToChanges.js.map +1 -0
- package/lib/commonjs/index.ios.js +66 -394
- package/lib/commonjs/index.ios.js.map +1 -1
- package/lib/commonjs/index.js +2 -15
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/native-types.js +170 -78
- package/lib/commonjs/native-types.js.map +1 -1
- package/lib/commonjs/types.js +13 -0
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/deserializeCategorySample.js +15 -0
- package/lib/commonjs/utils/deserializeCategorySample.js.map +1 -0
- package/lib/commonjs/utils/deserializeCorrelation.js +32 -0
- package/lib/commonjs/utils/deserializeCorrelation.js.map +1 -0
- package/lib/commonjs/utils/deserializeSample.js +17 -0
- package/lib/commonjs/utils/deserializeSample.js.map +1 -0
- package/lib/commonjs/utils/deserializeWorkout.js +17 -0
- package/lib/commonjs/utils/deserializeWorkout.js.map +1 -0
- package/lib/commonjs/utils/ensureMetadata.js +14 -0
- package/lib/commonjs/utils/ensureMetadata.js.map +1 -0
- package/lib/commonjs/utils/ensureUnit.js +23 -0
- package/lib/commonjs/utils/ensureUnit.js.map +1 -0
- package/lib/commonjs/utils/getDateOfBirth.js +19 -0
- package/lib/commonjs/utils/getDateOfBirth.js.map +1 -0
- package/lib/commonjs/utils/getMostRecentCategorySample.js +22 -0
- package/lib/commonjs/utils/getMostRecentCategorySample.js.map +1 -0
- package/lib/commonjs/utils/getMostRecentQuantitySample.js +22 -0
- package/lib/commonjs/utils/getMostRecentQuantitySample.js.map +1 -0
- package/lib/commonjs/utils/getMostRecentWorkout.js +24 -0
- package/lib/commonjs/utils/getMostRecentWorkout.js.map +1 -0
- package/lib/commonjs/utils/getPreferredUnit.js +19 -0
- package/lib/commonjs/utils/getPreferredUnit.js.map +1 -0
- package/lib/commonjs/utils/getPreferredUnits.js +19 -0
- package/lib/commonjs/utils/getPreferredUnits.js.map +1 -0
- package/lib/commonjs/utils/getPreferredUnitsTyped.js +46 -0
- package/lib/commonjs/utils/getPreferredUnitsTyped.js.map +1 -0
- package/lib/commonjs/utils/getRequestStatusForAuthorization.js +25 -0
- package/lib/commonjs/utils/getRequestStatusForAuthorization.js.map +1 -0
- package/lib/commonjs/utils/prepareOptions.js +27 -0
- package/lib/commonjs/utils/prepareOptions.js.map +1 -0
- package/lib/commonjs/utils/queryCategorySamples.js +24 -0
- package/lib/commonjs/utils/queryCategorySamples.js.map +1 -0
- package/lib/commonjs/utils/queryCorrelationSamples.js +24 -0
- package/lib/commonjs/utils/queryCorrelationSamples.js.map +1 -0
- package/lib/commonjs/utils/queryQuantitySamples.js +27 -0
- package/lib/commonjs/utils/queryQuantitySamples.js.map +1 -0
- package/lib/commonjs/utils/queryStatisticsForQuantity.js +34 -0
- package/lib/commonjs/utils/queryStatisticsForQuantity.js.map +1 -0
- package/lib/commonjs/utils/queryWorkouts.js +30 -0
- package/lib/commonjs/utils/queryWorkouts.js.map +1 -0
- package/lib/commonjs/utils/requestAuthorization.js +25 -0
- package/lib/commonjs/utils/requestAuthorization.js.map +1 -0
- package/lib/commonjs/utils/saveCategorySample.js +21 -0
- package/lib/commonjs/utils/saveCategorySample.js.map +1 -0
- package/lib/commonjs/utils/saveCorrelationSample.js +24 -0
- package/lib/commonjs/utils/saveCorrelationSample.js.map +1 -0
- package/lib/commonjs/utils/saveQuantitySample.js +21 -0
- package/lib/commonjs/utils/saveQuantitySample.js.map +1 -0
- package/lib/commonjs/utils/saveWorkoutSample.js +25 -0
- package/lib/commonjs/utils/saveWorkoutSample.js.map +1 -0
- package/lib/commonjs/utils/serializeDate.js +12 -0
- package/lib/commonjs/utils/serializeDate.js.map +1 -0
- package/lib/commonjs/utils/subscribeToChanges.js +37 -0
- package/lib/commonjs/utils/subscribeToChanges.js.map +1 -0
- package/lib/module/hooks/useHealthkitAuthorization.js +29 -0
- package/lib/module/hooks/useHealthkitAuthorization.js.map +1 -0
- package/lib/module/hooks/useIsHealthDataAvailable.js +18 -0
- package/lib/module/hooks/useIsHealthDataAvailable.js.map +1 -0
- package/lib/module/hooks/useMostRecentCategorySample.js +15 -0
- package/lib/module/hooks/useMostRecentCategorySample.js.map +1 -0
- package/lib/module/hooks/useMostRecentQuantitySample.js +30 -0
- package/lib/module/hooks/useMostRecentQuantitySample.js.map +1 -0
- package/lib/module/hooks/useMostRecentWorkout.js +47 -0
- package/lib/module/hooks/useMostRecentWorkout.js.map +1 -0
- package/lib/module/hooks/useStatisticsForQuantity.js +23 -0
- package/lib/module/hooks/useStatisticsForQuantity.js.map +1 -0
- package/lib/module/hooks/useSubscribeToChanges.js +26 -0
- package/lib/module/hooks/useSubscribeToChanges.js.map +1 -0
- package/lib/module/index.ios.js +32 -370
- package/lib/module/index.ios.js.map +1 -1
- package/lib/module/index.js +3 -5
- package/lib/module/index.js.map +1 -1
- package/lib/module/native-types.js +154 -74
- package/lib/module/native-types.js.map +1 -1
- package/lib/module/types.js +15 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/deserializeCategorySample.js +7 -0
- package/lib/module/utils/deserializeCategorySample.js.map +1 -0
- package/lib/module/utils/deserializeCorrelation.js +21 -0
- package/lib/module/utils/deserializeCorrelation.js.map +1 -0
- package/lib/module/utils/deserializeSample.js +9 -0
- package/lib/module/utils/deserializeSample.js.map +1 -0
- package/lib/module/utils/deserializeWorkout.js +9 -0
- package/lib/module/utils/deserializeWorkout.js.map +1 -0
- package/lib/module/utils/ensureMetadata.js +6 -0
- package/lib/module/utils/ensureMetadata.js.map +1 -0
- package/lib/module/utils/ensureUnit.js +13 -0
- package/lib/module/utils/ensureUnit.js.map +1 -0
- package/lib/module/utils/getDateOfBirth.js +9 -0
- package/lib/module/utils/getDateOfBirth.js.map +1 -0
- package/lib/module/utils/getMostRecentCategorySample.js +12 -0
- package/lib/module/utils/getMostRecentCategorySample.js.map +1 -0
- package/lib/module/utils/getMostRecentQuantitySample.js +12 -0
- package/lib/module/utils/getMostRecentQuantitySample.js.map +1 -0
- package/lib/module/utils/getMostRecentWorkout.js +14 -0
- package/lib/module/utils/getMostRecentWorkout.js.map +1 -0
- package/lib/module/utils/getPreferredUnit.js +9 -0
- package/lib/module/utils/getPreferredUnit.js.map +1 -0
- package/lib/module/utils/getPreferredUnits.js +9 -0
- package/lib/module/utils/getPreferredUnits.js.map +1 -0
- package/lib/module/utils/getPreferredUnitsTyped.js +34 -0
- package/lib/module/utils/getPreferredUnitsTyped.js.map +1 -0
- package/lib/module/utils/getRequestStatusForAuthorization.js +15 -0
- package/lib/module/utils/getRequestStatusForAuthorization.js.map +1 -0
- package/lib/module/utils/prepareOptions.js +17 -0
- package/lib/module/utils/prepareOptions.js.map +1 -0
- package/lib/module/utils/queryCategorySamples.js +12 -0
- package/lib/module/utils/queryCategorySamples.js.map +1 -0
- package/lib/module/utils/queryCorrelationSamples.js +12 -0
- package/lib/module/utils/queryCorrelationSamples.js.map +1 -0
- package/lib/module/utils/queryQuantitySamples.js +14 -0
- package/lib/module/utils/queryQuantitySamples.js.map +1 -0
- package/lib/module/utils/queryStatisticsForQuantity.js +23 -0
- package/lib/module/utils/queryStatisticsForQuantity.js.map +1 -0
- package/lib/module/utils/queryWorkouts.js +17 -0
- package/lib/module/utils/queryWorkouts.js.map +1 -0
- package/lib/module/utils/requestAuthorization.js +15 -0
- package/lib/module/utils/requestAuthorization.js.map +1 -0
- package/lib/module/utils/saveCategorySample.js +11 -0
- package/lib/module/utils/saveCategorySample.js.map +1 -0
- package/lib/module/utils/saveCorrelationSample.js +13 -0
- package/lib/module/utils/saveCorrelationSample.js.map +1 -0
- package/lib/module/utils/saveQuantitySample.js +11 -0
- package/lib/module/utils/saveQuantitySample.js.map +1 -0
- package/lib/module/utils/saveWorkoutSample.js +14 -0
- package/lib/module/utils/saveWorkoutSample.js.map +1 -0
- package/lib/module/utils/serializeDate.js +4 -0
- package/lib/module/utils/serializeDate.js.map +1 -0
- package/lib/module/utils/subscribeToChanges.js +25 -0
- package/lib/module/utils/subscribeToChanges.js.map +1 -0
- package/lib/typescript/example-expo/App.d.ts +2 -0
- package/lib/typescript/src/hooks/useHealthkitAuthorization.d.ts +3 -0
- package/lib/typescript/src/hooks/useIsHealthDataAvailable.d.ts +2 -0
- package/lib/typescript/src/hooks/useMostRecentCategorySample.d.ts +4 -0
- package/lib/typescript/src/hooks/useMostRecentQuantitySample.d.ts +4 -0
- package/lib/typescript/src/hooks/useMostRecentWorkout.d.ts +7 -0
- package/lib/typescript/src/hooks/useStatisticsForQuantity.d.ts +4 -0
- package/lib/typescript/src/hooks/useSubscribeToChanges.d.ts +3 -0
- package/lib/typescript/src/index.d.ts +2 -3
- package/lib/typescript/src/index.ios.d.ts +48 -3
- package/lib/typescript/src/native-types.d.ts +169 -65
- package/lib/typescript/src/types.d.ts +14 -90
- package/lib/typescript/src/utils/deserializeCategorySample.d.ts +4 -0
- package/lib/typescript/src/utils/deserializeCorrelation.d.ts +4 -0
- package/lib/typescript/src/utils/deserializeSample.d.ts +4 -0
- package/lib/typescript/src/utils/deserializeWorkout.d.ts +4 -0
- package/lib/typescript/src/utils/ensureMetadata.d.ts +2 -0
- package/lib/typescript/src/utils/ensureUnit.d.ts +3 -0
- package/lib/typescript/src/utils/getDateOfBirth.d.ts +2 -0
- package/lib/typescript/src/utils/getMostRecentCategorySample.d.ts +3 -0
- package/lib/typescript/src/utils/getMostRecentQuantitySample.d.ts +3 -0
- package/lib/typescript/src/utils/getMostRecentWorkout.d.ts +5 -0
- package/lib/typescript/src/utils/getPreferredUnit.d.ts +4 -0
- package/lib/typescript/src/utils/getPreferredUnits.d.ts +4 -0
- package/lib/typescript/src/utils/getPreferredUnitsTyped.d.ts +9 -0
- package/lib/typescript/src/utils/getRequestStatusForAuthorization.d.ts +3 -0
- package/lib/typescript/src/utils/prepareOptions.d.ts +8 -0
- package/lib/typescript/src/utils/queryCategorySamples.d.ts +5 -0
- package/lib/typescript/src/utils/queryCorrelationSamples.d.ts +5 -0
- package/lib/typescript/src/utils/queryQuantitySamples.d.ts +7 -0
- package/lib/typescript/src/utils/queryStatisticsForQuantity.d.ts +14 -0
- package/lib/typescript/src/utils/queryWorkouts.d.ts +4 -0
- package/lib/typescript/src/utils/requestAuthorization.d.ts +3 -0
- package/lib/typescript/src/utils/saveCategorySample.d.ts +7 -0
- package/lib/typescript/src/utils/saveCorrelationSample.d.ts +8 -0
- package/lib/typescript/src/utils/saveQuantitySample.d.ts +7 -0
- package/lib/typescript/src/utils/saveWorkoutSample.d.ts +7 -0
- package/lib/typescript/src/utils/serializeDate.d.ts +2 -0
- package/lib/typescript/src/utils/subscribeToChanges.d.ts +3 -0
- package/package.json +17 -6
- package/src/hooks/useHealthkitAuthorization.ts +39 -0
- package/src/hooks/useIsHealthDataAvailable.ts +17 -0
- package/src/hooks/useMostRecentCategorySample.ts +24 -0
- package/src/hooks/useMostRecentQuantitySample.ts +39 -0
- package/src/hooks/useMostRecentWorkout.ts +60 -0
- package/src/hooks/useStatisticsForQuantity.ts +42 -0
- package/src/hooks/useSubscribeToChanges.ts +31 -0
- package/src/index.ios.tsx +36 -569
- package/src/index.tsx +5 -7
- package/src/native-types.ts +213 -74
- package/src/types.ts +41 -152
- package/src/utils/deserializeCategorySample.ts +12 -0
- package/src/utils/deserializeCorrelation.ts +28 -0
- package/src/utils/deserializeSample.ts +17 -0
- package/src/utils/deserializeWorkout.ts +14 -0
- package/src/utils/ensureMetadata.ts +5 -0
- package/src/utils/ensureUnit.ts +19 -0
- package/src/utils/getDateOfBirth.ts +8 -0
- package/src/utils/getMostRecentCategorySample.ts +18 -0
- package/src/utils/getMostRecentQuantitySample.ts +19 -0
- package/src/utils/getMostRecentWorkout.ts +27 -0
- package/src/utils/getPreferredUnit.ts +14 -0
- package/src/utils/getPreferredUnits.ts +14 -0
- package/src/utils/getPreferredUnitsTyped.ts +38 -0
- package/src/utils/getRequestStatusForAuthorization.ts +21 -0
- package/src/utils/prepareOptions.ts +15 -0
- package/src/utils/queryCategorySamples.ts +29 -0
- package/src/utils/queryCorrelationSamples.ts +29 -0
- package/src/utils/queryQuantitySamples.ts +36 -0
- package/src/utils/queryStatisticsForQuantity.ts +38 -0
- package/src/utils/queryWorkouts.ts +28 -0
- package/src/utils/requestAuthorization.ts +18 -0
- package/src/utils/saveCategorySample.ts +27 -0
- package/src/utils/saveCorrelationSample.ts +34 -0
- package/src/utils/saveQuantitySample.ts +29 -0
- package/src/utils/saveWorkoutSample.ts +28 -0
- package/src/utils/serializeDate.ts +3 -0
- package/src/utils/subscribeToChanges.ts +32 -0
package/src/types.ts
CHANGED
|
@@ -1,34 +1,22 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
HealthkitWriteAuthorization,
|
|
4
|
-
HKAuthorizationRequestStatus,
|
|
5
|
-
HKBiologicalSex,
|
|
6
|
-
HKBloodType,
|
|
2
|
+
EnergyUnit,
|
|
7
3
|
HKCategorySampleRaw,
|
|
8
4
|
HKCategoryTypeIdentifier,
|
|
9
|
-
HKCategoryValueForIdentifier,
|
|
10
5
|
HKCorrelationRaw,
|
|
11
6
|
HKCorrelationTypeIdentifier,
|
|
12
|
-
|
|
13
|
-
HKQuantitySampleRaw,
|
|
7
|
+
HKDevice,
|
|
14
8
|
HKQuantityTypeIdentifier,
|
|
15
|
-
|
|
16
|
-
HKStatisticsOptions,
|
|
9
|
+
HKSourceRevision,
|
|
17
10
|
HKUnit,
|
|
18
|
-
HKUnitSI,
|
|
19
|
-
HKUnitSIPrefix,
|
|
20
|
-
HKUpdateFrequency,
|
|
21
|
-
HKWheelchairUse,
|
|
22
|
-
HKWorkoutActivityType,
|
|
23
|
-
HKWorkoutMetadata,
|
|
24
11
|
HKWorkoutRaw,
|
|
25
|
-
|
|
26
|
-
MetadataMapperForCorrelationIdentifier,
|
|
12
|
+
LengthUnit,
|
|
27
13
|
MetadataMapperForQuantityIdentifier,
|
|
28
14
|
QueryStatisticsResponseRaw,
|
|
29
|
-
|
|
15
|
+
UnitForIdentifier,
|
|
30
16
|
} from './native-types'
|
|
31
17
|
|
|
18
|
+
export * from './native-types'
|
|
19
|
+
|
|
32
20
|
export interface QueryWorkoutsOptions<
|
|
33
21
|
TEnergy extends HKUnit,
|
|
34
22
|
TDistance extends HKUnit
|
|
@@ -52,8 +40,8 @@ export type GenericQueryOptions = {
|
|
|
52
40
|
};
|
|
53
41
|
|
|
54
42
|
export interface HKWorkout<
|
|
55
|
-
TEnergy extends
|
|
56
|
-
TDistance extends
|
|
43
|
+
TEnergy extends EnergyUnit = EnergyUnit,
|
|
44
|
+
TDistance extends LengthUnit = LengthUnit
|
|
57
45
|
> extends Omit<HKWorkoutRaw<TEnergy, TDistance>, 'endDate' | 'startDate'> {
|
|
58
46
|
readonly startDate: Date;
|
|
59
47
|
readonly endDate: Date;
|
|
@@ -61,25 +49,27 @@ export interface HKWorkout<
|
|
|
61
49
|
|
|
62
50
|
export interface HKQuantitySample<
|
|
63
51
|
TIdentifier extends HKQuantityTypeIdentifier = HKQuantityTypeIdentifier,
|
|
64
|
-
TUnit extends
|
|
65
|
-
>
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
52
|
+
TUnit extends UnitForIdentifier<TIdentifier> = UnitForIdentifier<TIdentifier>
|
|
53
|
+
> {
|
|
54
|
+
readonly uuid: string;
|
|
55
|
+
readonly device?: HKDevice;
|
|
56
|
+
readonly quantityType: TIdentifier;
|
|
57
|
+
readonly quantity: number;
|
|
58
|
+
readonly unit: TUnit;
|
|
59
|
+
readonly metadata?: MetadataMapperForQuantityIdentifier<TIdentifier>;
|
|
60
|
+
readonly sourceRevision?: HKSourceRevision;
|
|
69
61
|
readonly startDate: Date;
|
|
70
62
|
readonly endDate: Date;
|
|
71
63
|
}
|
|
72
64
|
|
|
73
|
-
export interface QueryStatisticsResponse<
|
|
65
|
+
export interface QueryStatisticsResponse<TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier> = UnitForIdentifier<TIdentifier>>
|
|
74
66
|
extends Omit<
|
|
75
|
-
QueryStatisticsResponseRaw<
|
|
67
|
+
QueryStatisticsResponseRaw<TIdentifier, TUnit>,
|
|
76
68
|
'mostRecentQuantityDateInterval'
|
|
77
69
|
> {
|
|
78
70
|
readonly mostRecentQuantityDateInterval?: { readonly from: Date; readonly to: Date };
|
|
79
71
|
}
|
|
80
|
-
|
|
81
|
-
type UnsubscribeFunction = () => Promise<boolean>;
|
|
82
|
-
|
|
72
|
+
/*
|
|
83
73
|
export type IsHealthDataAvailableFn = () => Promise<boolean>;
|
|
84
74
|
|
|
85
75
|
export type GetBloodTypeFn = () => Promise<HKBloodType>;
|
|
@@ -89,21 +79,6 @@ export type GetBiologicalSexFn = () => Promise<HKBiologicalSex>;
|
|
|
89
79
|
export type GetWheelchairUseFn = () => Promise<HKWheelchairUse>;
|
|
90
80
|
export type GetFitzpatrickSkinTypeFn = () => Promise<HKFitzpatrickSkinType>;
|
|
91
81
|
|
|
92
|
-
export type QueryStatisticsForQuantityFn = <TUnit extends HKUnit>(
|
|
93
|
-
identifier: HKQuantityTypeIdentifier,
|
|
94
|
-
options: readonly HKStatisticsOptions[],
|
|
95
|
-
from: Date,
|
|
96
|
-
to?: Date,
|
|
97
|
-
unit?: TUnit
|
|
98
|
-
) => Promise<QueryStatisticsResponse<TUnit>>;
|
|
99
|
-
|
|
100
|
-
export type QueryWorkoutsFn = <
|
|
101
|
-
TEnergy extends HKUnit,
|
|
102
|
-
TDistance extends HKUnit
|
|
103
|
-
>(
|
|
104
|
-
options: QueryWorkoutsOptions<TEnergy, TDistance>
|
|
105
|
-
) => Promise<readonly HKWorkout<TEnergy, TDistance>[]>;
|
|
106
|
-
|
|
107
82
|
export type AuthorizationStatusForFn = (
|
|
108
83
|
type: HealthkitReadAuthorization
|
|
109
84
|
) => Promise<boolean>;
|
|
@@ -123,30 +98,29 @@ export type RequestAuthorizationFn = (
|
|
|
123
98
|
write?: readonly HealthkitWriteAuthorization[]
|
|
124
99
|
) => Promise<boolean>;
|
|
125
100
|
|
|
126
|
-
export type SaveQuantitySampleFn = <TUnit extends
|
|
127
|
-
identifier:
|
|
128
|
-
unit:
|
|
101
|
+
export type SaveQuantitySampleFn = <TType extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TType>>(
|
|
102
|
+
identifier: TType,
|
|
103
|
+
unit: TUnit,
|
|
129
104
|
value: number,
|
|
130
105
|
options?: {
|
|
131
106
|
readonly start?: Date;
|
|
132
107
|
readonly end?: Date;
|
|
133
|
-
readonly metadata?: MetadataMapperForQuantityIdentifier<
|
|
108
|
+
readonly metadata?: MetadataMapperForQuantityIdentifier<TType>;
|
|
134
109
|
}
|
|
135
110
|
) => Promise<boolean>;
|
|
136
111
|
|
|
137
112
|
export type QueryQuantitySamplesFn = <
|
|
138
113
|
TIdentifier extends HKQuantityTypeIdentifier,
|
|
139
|
-
TUnit extends
|
|
114
|
+
TUnit extends UnitForIdentifier<TIdentifier>
|
|
140
115
|
>(
|
|
141
116
|
identifier: TIdentifier,
|
|
142
117
|
options: GenericQueryOptions & { readonly unit?: TUnit }
|
|
143
|
-
) => Promise<readonly HKQuantitySample<TIdentifier
|
|
118
|
+
) => Promise<readonly HKQuantitySample<TIdentifier>[]>; */
|
|
144
119
|
|
|
145
|
-
export type
|
|
146
|
-
identifier: HKSampleTypeIdentifier,
|
|
147
|
-
callback: () => void
|
|
148
|
-
) => Promise<UnsubscribeFunction>;
|
|
120
|
+
export type HKCategorySampleForSaving =Omit<HKCategorySample, 'device' | 'endDate' | 'startDate' | 'uuid'>
|
|
149
121
|
|
|
122
|
+
export type HKQuantitySampleForSaving =Omit<HKQuantitySample, 'device' | 'endDate' | 'startDate' | 'uuid'>
|
|
123
|
+
/*
|
|
150
124
|
export type SaveCategorySampleFn = <T extends HKCategoryTypeIdentifier>(
|
|
151
125
|
identifier: T,
|
|
152
126
|
value: HKCategoryValueForIdentifier<T>,
|
|
@@ -157,12 +131,6 @@ export type SaveCategorySampleFn = <T extends HKCategoryTypeIdentifier>(
|
|
|
157
131
|
}
|
|
158
132
|
) => Promise<boolean>;
|
|
159
133
|
|
|
160
|
-
export type GetMostRecentCategorySampleFn = <
|
|
161
|
-
T extends HKCategoryTypeIdentifier
|
|
162
|
-
>(
|
|
163
|
-
identifier: T
|
|
164
|
-
) => Promise<HKCategorySample<T> | null>;
|
|
165
|
-
|
|
166
134
|
export type MostRecentCategorySampleHook = <T extends HKCategoryTypeIdentifier>(
|
|
167
135
|
identifier: T
|
|
168
136
|
) => HKCategorySample<T> | null;
|
|
@@ -173,35 +141,17 @@ export type MostRecentCorrelationSampleHook = <
|
|
|
173
141
|
identifer: T
|
|
174
142
|
) => HKCorrelation<T> | null;
|
|
175
143
|
|
|
176
|
-
export type GetMostRecentQuantitySampleFn = <
|
|
177
|
-
TIdentifier extends HKQuantityTypeIdentifier,
|
|
178
|
-
TUnit extends HKUnit
|
|
179
|
-
>(
|
|
180
|
-
identifier: TIdentifier,
|
|
181
|
-
unit?: TUnit
|
|
182
|
-
) => Promise<HKQuantitySample<TIdentifier, TUnit> | null>;
|
|
183
|
-
|
|
184
144
|
export type MostRecentQuantitySampleHook = <
|
|
185
145
|
TIdentifier extends HKQuantityTypeIdentifier,
|
|
186
|
-
TUnit extends
|
|
146
|
+
TUnit extends UnitForIdentifier<TIdentifier>
|
|
187
147
|
>(
|
|
188
148
|
identifier: TIdentifier,
|
|
189
149
|
unit?: TUnit
|
|
190
|
-
) => HKQuantitySample<TIdentifier
|
|
191
|
-
|
|
192
|
-
export type GetMostRecentWorkoutFn = <
|
|
193
|
-
TEnergy extends HKUnit,
|
|
194
|
-
TDistance extends HKUnit
|
|
195
|
-
>(
|
|
196
|
-
options?: Pick<
|
|
197
|
-
QueryWorkoutsOptions<TEnergy, TDistance>,
|
|
198
|
-
'distanceUnit' | 'energyUnit'
|
|
199
|
-
>
|
|
200
|
-
) => Promise<HKWorkout<TEnergy, TDistance> | null>;
|
|
150
|
+
) => HKQuantitySample<TIdentifier> | null;
|
|
201
151
|
|
|
202
152
|
export type MostRecentWorkoutHook = <
|
|
203
|
-
TEnergy extends
|
|
204
|
-
TDistance extends
|
|
153
|
+
TEnergy extends EnergyUnit,
|
|
154
|
+
TDistance extends LengthUnit
|
|
205
155
|
>(
|
|
206
156
|
options?: Pick<
|
|
207
157
|
QueryWorkoutsOptions<TEnergy, TDistance>,
|
|
@@ -223,7 +173,7 @@ export type SaveCorrelationSampleFn = <
|
|
|
223
173
|
typeIdentifier: TIdentifier,
|
|
224
174
|
samples: readonly (
|
|
225
175
|
| Omit<HKCategorySample, 'device' | 'endDate' | 'startDate' | 'uuid'>
|
|
226
|
-
| Omit<HKQuantitySample
|
|
176
|
+
| Omit<HKQuantitySample<HKQuantityTypeIdentifier>, 'device' | 'endDate' | 'startDate' | 'uuid'>
|
|
227
177
|
)[],
|
|
228
178
|
options?: {
|
|
229
179
|
readonly start?: Date;
|
|
@@ -232,10 +182,10 @@ export type SaveCorrelationSampleFn = <
|
|
|
232
182
|
}
|
|
233
183
|
) => Promise<boolean>;
|
|
234
184
|
|
|
235
|
-
export type SaveWorkoutSampleFn = (
|
|
236
|
-
typeIdentifier:
|
|
185
|
+
export type SaveWorkoutSampleFn<TIdentifier extends HKWorkoutActivityType, TQIdentifier extends HKQuantityTypeIdentifier> = (
|
|
186
|
+
typeIdentifier: TIdentifier,
|
|
237
187
|
quantities: readonly Omit<
|
|
238
|
-
HKQuantitySample
|
|
188
|
+
HKQuantitySample<TQIdentifier>,
|
|
239
189
|
'device' | 'endDate' | 'startDate' | 'uuid'
|
|
240
190
|
>[],
|
|
241
191
|
start: Date,
|
|
@@ -244,7 +194,7 @@ export type SaveWorkoutSampleFn = (
|
|
|
244
194
|
readonly metadata?: HKWorkoutMetadata;
|
|
245
195
|
}
|
|
246
196
|
) => Promise<boolean>;
|
|
247
|
-
|
|
197
|
+
*/
|
|
248
198
|
export interface HKCorrelation<TIdentifier extends HKCorrelationTypeIdentifier>
|
|
249
199
|
extends Omit<
|
|
250
200
|
HKCorrelationRaw<TIdentifier>,
|
|
@@ -254,14 +204,7 @@ export interface HKCorrelation<TIdentifier extends HKCorrelationTypeIdentifier>
|
|
|
254
204
|
readonly startDate: Date;
|
|
255
205
|
readonly endDate: Date;
|
|
256
206
|
}
|
|
257
|
-
|
|
258
|
-
export type QueryCorrelationSamplesFn = <
|
|
259
|
-
TIdentifier extends HKCorrelationTypeIdentifier
|
|
260
|
-
>(
|
|
261
|
-
typeIdentifier: TIdentifier,
|
|
262
|
-
options: Omit<GenericQueryOptions, 'ascending' | 'limit'>
|
|
263
|
-
) => Promise<readonly HKCorrelation<TIdentifier>[]>;
|
|
264
|
-
|
|
207
|
+
/*
|
|
265
208
|
export type SubscribeToChangesHook = <
|
|
266
209
|
TIdentifier extends HKSampleTypeIdentifier
|
|
267
210
|
>(
|
|
@@ -273,58 +216,4 @@ export type SubscribeToChangesHook = <
|
|
|
273
216
|
export type GetWorkoutRoutesFn = (
|
|
274
217
|
workoutUUID: string
|
|
275
218
|
) => Promise<readonly WorkoutRoute[]>;
|
|
276
|
-
|
|
277
|
-
export type ReactNativeHealthkit = {
|
|
278
|
-
readonly authorizationStatusFor: AuthorizationStatusForFn;
|
|
279
|
-
|
|
280
|
-
readonly getBiologicalSex: GetBiologicalSexFn;
|
|
281
|
-
readonly getBloodType: GetBloodTypeFn;
|
|
282
|
-
readonly getDateOfBirth: GetDateOfBirthFn;
|
|
283
|
-
readonly getFitzpatrickSkinType: GetFitzpatrickSkinTypeFn;
|
|
284
|
-
readonly getMostRecentQuantitySample: GetMostRecentQuantitySampleFn;
|
|
285
|
-
readonly getMostRecentCategorySample: GetMostRecentCategorySampleFn;
|
|
286
|
-
readonly getMostRecentWorkout: GetMostRecentWorkoutFn;
|
|
287
|
-
readonly getPreferredUnit: GetPreferredUnitFn;
|
|
288
|
-
readonly getPreferredUnits: GetPreferredUnitsFn;
|
|
289
|
-
readonly getRequestStatusForAuthorization: GetRequestStatusForAuthorizationFn;
|
|
290
|
-
readonly getWheelchairUse: GetWheelchairUseFn;
|
|
291
|
-
readonly getWorkoutRoutes: GetWorkoutRoutesFn;
|
|
292
|
-
|
|
293
|
-
readonly buildUnitWithPrefix: (prefix: HKUnitSIPrefix, unit: HKUnitSI) => HKUnit;
|
|
294
|
-
|
|
295
|
-
readonly isHealthDataAvailable: IsHealthDataAvailableFn;
|
|
296
|
-
|
|
297
|
-
readonly queryCategorySamples: QueryCategorySamplesFn;
|
|
298
|
-
readonly queryQuantitySamples: QueryQuantitySamplesFn;
|
|
299
|
-
readonly queryStatisticsForQuantity: QueryStatisticsForQuantityFn;
|
|
300
|
-
readonly queryWorkouts: QueryWorkoutsFn;
|
|
301
|
-
readonly queryCorrelationSamples: QueryCorrelationSamplesFn;
|
|
302
|
-
|
|
303
|
-
readonly requestAuthorization: RequestAuthorizationFn;
|
|
304
|
-
|
|
305
|
-
readonly saveCategorySample: SaveCategorySampleFn;
|
|
306
|
-
readonly saveQuantitySample: SaveQuantitySampleFn;
|
|
307
|
-
readonly saveCorrelationSample: SaveCorrelationSampleFn;
|
|
308
|
-
readonly saveWorkoutSample: SaveWorkoutSampleFn;
|
|
309
|
-
readonly enableBackgroundDelivery: (
|
|
310
|
-
typeIdentifier: HKSampleTypeIdentifier,
|
|
311
|
-
updateFrequency: HKUpdateFrequency
|
|
312
|
-
) => Promise<boolean>;
|
|
313
|
-
readonly disableBackgroundDelivery: (
|
|
314
|
-
typeIdentifier: HKSampleTypeIdentifier
|
|
315
|
-
) => Promise<boolean>;
|
|
316
|
-
readonly disableAllBackgroundDelivery: () => Promise<boolean>;
|
|
317
|
-
|
|
318
|
-
readonly subscribeToChanges: SubscribeToChangesFn;
|
|
319
|
-
|
|
320
|
-
readonly useMostRecentWorkout: MostRecentWorkoutHook;
|
|
321
|
-
readonly useMostRecentCategorySample: MostRecentCategorySampleHook;
|
|
322
|
-
readonly useMostRecentQuantitySample: MostRecentQuantitySampleHook;
|
|
323
|
-
|
|
324
|
-
readonly useSubscribeToChanges: SubscribeToChangesHook;
|
|
325
|
-
readonly useIsHealthDataAvailable: () => boolean | null;
|
|
326
|
-
readonly useHealthkitAuthorization: (
|
|
327
|
-
read: readonly HealthkitReadAuthorization[],
|
|
328
|
-
write?: readonly HealthkitWriteAuthorization[],
|
|
329
|
-
) => readonly [authorizationStatus: HKAuthorizationRequestStatus | null, request: () => Promise<HKAuthorizationRequestStatus | null>];
|
|
330
|
-
};
|
|
219
|
+
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { HKCategorySampleRaw, HKCategoryTypeIdentifier } from '../native-types'
|
|
2
|
+
import type { HKCategorySample } from '../types'
|
|
3
|
+
|
|
4
|
+
const deserializCategorySample = <T extends HKCategoryTypeIdentifier>(
|
|
5
|
+
sample: HKCategorySampleRaw<T>,
|
|
6
|
+
): HKCategorySample<T> => ({
|
|
7
|
+
...sample,
|
|
8
|
+
startDate: new Date(sample.startDate),
|
|
9
|
+
endDate: new Date(sample.endDate),
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
export default deserializCategorySample
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import deserializCategorySample from './deserializeCategorySample'
|
|
2
|
+
import deserializeSample from './deserializeSample'
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
HKCategorySampleRaw, HKCorrelationRaw, HKCorrelationTypeIdentifier, HKQuantitySampleRaw, HKQuantityTypeIdentifier,
|
|
6
|
+
} from '../native-types'
|
|
7
|
+
import type { HKCorrelation } from '../types'
|
|
8
|
+
|
|
9
|
+
function deserializeCorrelation<
|
|
10
|
+
TIdentifier extends HKCorrelationTypeIdentifier
|
|
11
|
+
>(s: HKCorrelationRaw<TIdentifier>): HKCorrelation<TIdentifier> {
|
|
12
|
+
return {
|
|
13
|
+
...s,
|
|
14
|
+
objects: s.objects.map((o) => {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
if (o.quantity !== undefined) {
|
|
18
|
+
return deserializeSample(o as HKQuantitySampleRaw<HKQuantityTypeIdentifier>)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return deserializCategorySample(o as HKCategorySampleRaw)
|
|
22
|
+
}),
|
|
23
|
+
endDate: new Date(s.endDate),
|
|
24
|
+
startDate: new Date(s.startDate),
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default deserializeCorrelation
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { HKQuantitySampleRaw, HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types'
|
|
2
|
+
import type { HKQuantitySample } from '../types'
|
|
3
|
+
|
|
4
|
+
function deserializeSample<
|
|
5
|
+
TIdentifier extends HKQuantityTypeIdentifier,
|
|
6
|
+
TUnit extends UnitForIdentifier<TIdentifier>
|
|
7
|
+
>(
|
|
8
|
+
sample: HKQuantitySampleRaw<TIdentifier, TUnit>,
|
|
9
|
+
): HKQuantitySample<TIdentifier, TUnit> {
|
|
10
|
+
return {
|
|
11
|
+
...sample,
|
|
12
|
+
startDate: new Date(sample.startDate),
|
|
13
|
+
endDate: new Date(sample.endDate),
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default deserializeSample
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EnergyUnit, HKWorkoutRaw, LengthUnit } from '../native-types'
|
|
2
|
+
import type { HKWorkout } from '../types'
|
|
3
|
+
|
|
4
|
+
function deserializeWorkout<TEnergy extends EnergyUnit, TDistance extends LengthUnit>(
|
|
5
|
+
sample: HKWorkoutRaw<TEnergy, TDistance>,
|
|
6
|
+
): HKWorkout<TEnergy, TDistance> {
|
|
7
|
+
return {
|
|
8
|
+
...sample,
|
|
9
|
+
startDate: new Date(sample.startDate),
|
|
10
|
+
endDate: new Date(sample.endDate),
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default deserializeWorkout
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Native from '../native-types'
|
|
2
|
+
|
|
3
|
+
import type { HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types'
|
|
4
|
+
|
|
5
|
+
const ensureUnit = async <
|
|
6
|
+
TIdentifier extends HKQuantityTypeIdentifier,
|
|
7
|
+
TUnit extends UnitForIdentifier<TIdentifier>
|
|
8
|
+
>(
|
|
9
|
+
type: TIdentifier,
|
|
10
|
+
providedUnit?: TUnit,
|
|
11
|
+
) => {
|
|
12
|
+
if (providedUnit) {
|
|
13
|
+
return providedUnit
|
|
14
|
+
}
|
|
15
|
+
const unit = await Native.getPreferredUnits([type])
|
|
16
|
+
return unit[type] as TUnit
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default ensureUnit
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import queryCategorySamples from './queryCategorySamples'
|
|
2
|
+
|
|
3
|
+
import type { HKCategoryTypeIdentifier } from '../native-types'
|
|
4
|
+
|
|
5
|
+
async function getMostRecentCategorySample<
|
|
6
|
+
T extends HKCategoryTypeIdentifier
|
|
7
|
+
>(
|
|
8
|
+
identifier: T,
|
|
9
|
+
) {
|
|
10
|
+
const samples = await queryCategorySamples(identifier, {
|
|
11
|
+
limit: 1,
|
|
12
|
+
ascending: false,
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
return samples[0] || null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default getMostRecentCategorySample
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import queryQuantitySamples from './queryQuantitySamples'
|
|
2
|
+
|
|
3
|
+
import type { HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types'
|
|
4
|
+
|
|
5
|
+
async function getMostRecentQuantitySample<
|
|
6
|
+
TIdentifier extends HKQuantityTypeIdentifier,
|
|
7
|
+
TUnit extends UnitForIdentifier<TIdentifier>
|
|
8
|
+
>(
|
|
9
|
+
identifier: TIdentifier,
|
|
10
|
+
unit: TUnit,
|
|
11
|
+
) {
|
|
12
|
+
const samples = await queryQuantitySamples(identifier, {
|
|
13
|
+
limit: 1,
|
|
14
|
+
unit,
|
|
15
|
+
})
|
|
16
|
+
return samples[0] || null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default getMostRecentQuantitySample
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import queryWorkouts from './queryWorkouts'
|
|
2
|
+
|
|
3
|
+
import type { EnergyUnit, LengthUnit } from '../native-types'
|
|
4
|
+
import type { HKWorkout, QueryWorkoutsOptions } from '../types'
|
|
5
|
+
|
|
6
|
+
export type GetMostRecentWorkoutFn = <
|
|
7
|
+
TEnergy extends EnergyUnit,
|
|
8
|
+
TDistance extends LengthUnit
|
|
9
|
+
>(
|
|
10
|
+
options?: Pick<
|
|
11
|
+
QueryWorkoutsOptions<TEnergy, TDistance>,
|
|
12
|
+
'distanceUnit' | 'energyUnit'
|
|
13
|
+
>
|
|
14
|
+
) => Promise<HKWorkout<TEnergy, TDistance> | null>;
|
|
15
|
+
|
|
16
|
+
const getMostRecentWorkout: GetMostRecentWorkoutFn = async (options) => {
|
|
17
|
+
const workouts = await queryWorkouts({
|
|
18
|
+
limit: 1,
|
|
19
|
+
ascending: false,
|
|
20
|
+
energyUnit: options?.energyUnit,
|
|
21
|
+
distanceUnit: options?.distanceUnit,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
return workouts[0] || null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default getMostRecentWorkout
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import getPreferredUnits from './getPreferredUnits'
|
|
2
|
+
|
|
3
|
+
import type { HKQuantityTypeIdentifier, HKUnit } from '../native-types'
|
|
4
|
+
|
|
5
|
+
export type GetPreferredUnitFn = (
|
|
6
|
+
identifier: HKQuantityTypeIdentifier
|
|
7
|
+
) => Promise<HKUnit>;
|
|
8
|
+
|
|
9
|
+
const getPreferredUnit: GetPreferredUnitFn = async (type) => {
|
|
10
|
+
const [unit] = await getPreferredUnits([type])
|
|
11
|
+
return unit!
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default getPreferredUnit
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Native from '../native-types'
|
|
2
|
+
|
|
3
|
+
import type { HKQuantityTypeIdentifier, HKUnit } from '../native-types'
|
|
4
|
+
|
|
5
|
+
export type GetPreferredUnitsFn = (
|
|
6
|
+
identifiers: readonly HKQuantityTypeIdentifier[]
|
|
7
|
+
) => Promise<readonly HKUnit[]>;
|
|
8
|
+
|
|
9
|
+
const getPreferredUnits: GetPreferredUnitsFn = async (identifiers) => {
|
|
10
|
+
const units = await Native.getPreferredUnits(identifiers)
|
|
11
|
+
return identifiers.map((i) => units[i])
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default getPreferredUnits
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import Native, { HKQuantityTypeIdentifier, UnitOfEnergy, UnitOfLength } from '../native-types'
|
|
2
|
+
|
|
3
|
+
import type { HKUnit } from '../native-types'
|
|
4
|
+
|
|
5
|
+
async function getPreferredUnitsTyped<
|
|
6
|
+
TEnergy extends HKUnit,
|
|
7
|
+
TDistance extends HKUnit
|
|
8
|
+
>(options?: { readonly energyUnit?: TEnergy; readonly distanceUnit?: TDistance }) {
|
|
9
|
+
let energyUnit = options?.energyUnit
|
|
10
|
+
let distanceUnit = options?.distanceUnit
|
|
11
|
+
|
|
12
|
+
if (!energyUnit || !distanceUnit) {
|
|
13
|
+
const units = await Native.getPreferredUnits([
|
|
14
|
+
HKQuantityTypeIdentifier.distanceWalkingRunning,
|
|
15
|
+
HKQuantityTypeIdentifier.activeEnergyBurned,
|
|
16
|
+
])
|
|
17
|
+
if (!energyUnit) {
|
|
18
|
+
energyUnit = units[HKQuantityTypeIdentifier.activeEnergyBurned] as
|
|
19
|
+
| TEnergy
|
|
20
|
+
| undefined
|
|
21
|
+
}
|
|
22
|
+
if (!distanceUnit) {
|
|
23
|
+
distanceUnit = units[HKQuantityTypeIdentifier.distanceWalkingRunning] as
|
|
24
|
+
| TDistance
|
|
25
|
+
| undefined
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!energyUnit) {
|
|
30
|
+
energyUnit = UnitOfEnergy.Kilocalories as TEnergy
|
|
31
|
+
}
|
|
32
|
+
if (!distanceUnit) {
|
|
33
|
+
distanceUnit = UnitOfLength.Meter as TDistance
|
|
34
|
+
}
|
|
35
|
+
return { energyUnit, distanceUnit }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default getPreferredUnitsTyped
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Native from '../native-types'
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
HealthkitReadAuthorization, HealthkitWriteAuthorization, ReadPermissions, WritePermissions,
|
|
5
|
+
} from '../native-types'
|
|
6
|
+
|
|
7
|
+
const getRequestStatusForAuthorization = async (
|
|
8
|
+
read: readonly HealthkitReadAuthorization[],
|
|
9
|
+
write: readonly HealthkitWriteAuthorization[] = [],
|
|
10
|
+
) => {
|
|
11
|
+
const readPermissions = read.reduce((obj, cur) => ({ ...obj, [cur]: true }), {} as ReadPermissions)
|
|
12
|
+
|
|
13
|
+
const writePermissions = write.reduce((obj, cur) => ({ ...obj, [cur]: true }), {} as WritePermissions)
|
|
14
|
+
|
|
15
|
+
return Native.getRequestStatusForAuthorization(
|
|
16
|
+
writePermissions,
|
|
17
|
+
readPermissions,
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default getRequestStatusForAuthorization
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import serializeDate from './serializeDate'
|
|
2
|
+
|
|
3
|
+
import type { GenericQueryOptions } from '../types'
|
|
4
|
+
|
|
5
|
+
const prepareOptions = (options: GenericQueryOptions) => {
|
|
6
|
+
const limit = !options.limit || options.limit === Infinity ? 0 : options.limit
|
|
7
|
+
const ascending = options.ascending ?? limit === 0
|
|
8
|
+
const from = serializeDate(options.from)
|
|
9
|
+
const to = serializeDate(options.to)
|
|
10
|
+
return {
|
|
11
|
+
limit, ascending, from, to,
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default prepareOptions
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Native from '../native-types'
|
|
2
|
+
import deserializCategorySample from './deserializeCategorySample'
|
|
3
|
+
import prepareOptions from './prepareOptions'
|
|
4
|
+
|
|
5
|
+
import type { HKCategoryTypeIdentifier } from '../native-types'
|
|
6
|
+
import type { GenericQueryOptions, HKCategorySample } from '../types'
|
|
7
|
+
|
|
8
|
+
export type QueryCategorySamplesFn = <T extends HKCategoryTypeIdentifier>(
|
|
9
|
+
identifier: T,
|
|
10
|
+
options: GenericQueryOptions
|
|
11
|
+
) => Promise<readonly HKCategorySample<T>[]>;
|
|
12
|
+
|
|
13
|
+
const queryCategorySamples: QueryCategorySamplesFn = async (
|
|
14
|
+
identifier,
|
|
15
|
+
options,
|
|
16
|
+
) => {
|
|
17
|
+
const opts = prepareOptions(options)
|
|
18
|
+
const results = await Native.queryCategorySamples(
|
|
19
|
+
identifier,
|
|
20
|
+
opts.from,
|
|
21
|
+
opts.to,
|
|
22
|
+
opts.limit,
|
|
23
|
+
opts.ascending,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
return results.map(deserializCategorySample)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default queryCategorySamples
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Native from '../native-types'
|
|
2
|
+
import deserializeCorrelation from './deserializeCorrelation'
|
|
3
|
+
import prepareOptions from './prepareOptions'
|
|
4
|
+
|
|
5
|
+
import type { HKCorrelationTypeIdentifier } from '../native-types'
|
|
6
|
+
import type { GenericQueryOptions, HKCorrelation } from '../types'
|
|
7
|
+
|
|
8
|
+
export type QueryCorrelationSamplesFn = <
|
|
9
|
+
TIdentifier extends HKCorrelationTypeIdentifier
|
|
10
|
+
>(
|
|
11
|
+
typeIdentifier: TIdentifier,
|
|
12
|
+
options: Omit<GenericQueryOptions, 'ascending' | 'limit'>
|
|
13
|
+
) => Promise<readonly HKCorrelation<TIdentifier>[]>;
|
|
14
|
+
|
|
15
|
+
const queryCorrelationSamples: QueryCorrelationSamplesFn = async (
|
|
16
|
+
typeIdentifier,
|
|
17
|
+
options,
|
|
18
|
+
) => {
|
|
19
|
+
const opts = prepareOptions(options)
|
|
20
|
+
const correlations = await Native.queryCorrelationSamples(
|
|
21
|
+
typeIdentifier,
|
|
22
|
+
opts.from,
|
|
23
|
+
opts.to,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
return correlations.map(deserializeCorrelation)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default queryCorrelationSamples
|