@kingstinct/react-native-healthkit 8.2.0 → 8.3.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/README.md +18 -4
- package/ios/Constants.swift +4 -0
- package/ios/Helpers.swift +81 -0
- package/ios/ReactNativeHealthkit.m +15 -0
- package/ios/ReactNativeHealthkit.swift +104 -2
- package/ios/Serializers.swift +18 -0
- package/lib/commonjs/index.ios.js +18 -0
- package/lib/commonjs/index.ios.js.map +1 -1
- package/lib/commonjs/index.native.js +15 -1
- package/lib/commonjs/index.native.js.map +1 -1
- package/lib/commonjs/native-types.js +14 -1
- package/lib/commonjs/native-types.js.map +1 -1
- package/lib/commonjs/test-setup.js +3 -1
- package/lib/commonjs/test-setup.js.map +1 -1
- package/lib/commonjs/utils/queryStatisticsCollectionForQuantity.js +16 -0
- package/lib/commonjs/utils/queryStatisticsCollectionForQuantity.js.map +1 -0
- package/lib/commonjs/utils/startWatchApp.js +11 -0
- package/lib/commonjs/utils/startWatchApp.js.map +1 -0
- package/lib/module/index.ios.js +6 -2
- package/lib/module/index.ios.js.map +1 -1
- package/lib/module/index.native.js +13 -1
- package/lib/module/index.native.js.map +1 -1
- package/lib/module/native-types.js +15 -0
- package/lib/module/native-types.js.map +1 -1
- package/lib/module/test-setup.js +3 -1
- package/lib/module/test-setup.js.map +1 -1
- package/lib/module/utils/queryStatisticsCollectionForQuantity.js +9 -0
- package/lib/module/utils/queryStatisticsCollectionForQuantity.js.map +1 -0
- package/lib/module/utils/startWatchApp.js +4 -0
- package/lib/module/utils/startWatchApp.js.map +1 -0
- package/lib/typescript/src/index.ios.d.ts +6 -2
- package/lib/typescript/src/index.native.d.ts +11 -3
- package/lib/typescript/src/native-types.d.ts +29 -1
- package/lib/typescript/src/utils/queryStatisticsCollectionForQuantity.d.ts +3 -0
- package/lib/typescript/src/utils/startWatchApp.d.ts +3 -0
- package/package.json +1 -1
- package/src/index.ios.tsx +7 -0
- package/src/index.native.tsx +16 -0
- package/src/native-types.ts +45 -1
- package/src/test-setup.ts +2 -0
- package/src/utils/queryStatisticsCollectionForQuantity.ts +38 -0
- package/src/utils/startWatchApp.ts +7 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Native","startWatchApp","configuration","startWatchAppWithWorkoutConfiguration"],"sources":["startWatchApp.ts"],"sourcesContent":["import Native from '../native-types'\n\nimport type { HKWorkoutConfiguration } from '..'\n\nconst startWatchApp = (configuration: HKWorkoutConfiguration) => async () => Native.startWatchAppWithWorkoutConfiguration(configuration)\n\nexport default startWatchApp\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,iBAAiB;AAIpC,MAAMC,aAAa,GAAIC,aAAqC,IAAK,YAAYF,MAAM,CAACG,qCAAqC,CAACD,aAAa,CAAC;AAExI,eAAeD,aAAa","ignoreList":[]}
|
|
@@ -25,6 +25,7 @@ import queryHeartbeatSeriesSamplesWithAnchor from './utils/queryHeartbeatSeriesS
|
|
|
25
25
|
import queryQuantitySamples from './utils/queryQuantitySamples';
|
|
26
26
|
import queryQuantitySamplesWithAnchor from './utils/queryQuantitySamplesWithAnchor';
|
|
27
27
|
import querySources from './utils/querySources';
|
|
28
|
+
import queryStatisticsCollectionForQuantity from './utils/queryStatisticsCollectionForQuantity';
|
|
28
29
|
import queryStatisticsForQuantity from './utils/queryStatisticsForQuantity';
|
|
29
30
|
import queryWorkoutSamples from './utils/queryWorkouts';
|
|
30
31
|
import queryWorkoutSamplesWithAnchor from './utils/queryWorkoutSamplesWithAnchor';
|
|
@@ -34,6 +35,7 @@ import saveCorrelationSample from './utils/saveCorrelationSample';
|
|
|
34
35
|
import saveQuantitySample from './utils/saveQuantitySample';
|
|
35
36
|
import saveWorkoutRoute from './utils/saveWorkoutRoute';
|
|
36
37
|
import saveWorkoutSample from './utils/saveWorkoutSample';
|
|
38
|
+
import startWatchApp from './utils/startWatchApp';
|
|
37
39
|
import subscribeToChanges from './utils/subscribeToChanges';
|
|
38
40
|
declare const availableQuantityTypes: (majorVersionIOS?: number) => HKQuantityTypeIdentifier[];
|
|
39
41
|
declare const authorizationStatusFor: (type: import("./native-types").HealthkitReadAuthorization) => Promise<import("./native-types").HKAuthorizationStatus>;
|
|
@@ -125,6 +127,7 @@ declare const _default: {
|
|
|
125
127
|
queryQuantitySamples: import("./utils/queryQuantitySamples").QueryQuantitySamplesFn;
|
|
126
128
|
queryQuantitySamplesWithAnchor: import("./utils/queryQuantitySamplesWithAnchor").QueryQuantitySamplesWithAnchorFn;
|
|
127
129
|
queryStatisticsForQuantity: typeof queryStatisticsForQuantity;
|
|
130
|
+
queryStatisticsCollectionForQuantity: typeof queryStatisticsCollectionForQuantity;
|
|
128
131
|
/**
|
|
129
132
|
* @deprecated Use queryWorkoutSamples instead
|
|
130
133
|
*/
|
|
@@ -145,6 +148,7 @@ declare const _default: {
|
|
|
145
148
|
saveWorkoutSample: typeof saveWorkoutSample;
|
|
146
149
|
saveWorkoutRoute: typeof saveWorkoutRoute;
|
|
147
150
|
subscribeToChanges: (identifier: import("./native-types").HKSampleTypeIdentifier, callback: () => void) => Promise<() => Promise<boolean>>;
|
|
151
|
+
startWatchApp: (configuration: import("./native-types").HKWorkoutConfiguration) => () => Promise<boolean>;
|
|
148
152
|
/**
|
|
149
153
|
* @returns the most recent sample for the given category type.
|
|
150
154
|
*/
|
|
@@ -175,9 +179,9 @@ declare const _default: {
|
|
|
175
179
|
};
|
|
176
180
|
export default _default;
|
|
177
181
|
declare const queryWorkouts: typeof queryWorkoutSamples;
|
|
178
|
-
export { authorizationStatusFor, availableQuantityTypes, disableAllBackgroundDelivery, disableBackgroundDelivery, enableBackgroundDelivery, getBiologicalSex, getBloodType, getDateOfBirth, getFitzpatrickSkinType, getMostRecentCategorySample, getMostRecentQuantitySample, getMostRecentWorkout, getPreferredUnit, getPreferredUnits, getRequestStatusForAuthorization, getWheelchairUse, getWorkoutRoutes, isHealthDataAvailable, queryCategorySamples, queryCategorySamplesWithAnchor, queryCorrelationSamples, queryHeartbeatSeriesSamples, queryHeartbeatSeriesSamplesWithAnchor, queryQuantitySamples, queryQuantitySamplesWithAnchor, queryStatisticsForQuantity,
|
|
182
|
+
export { authorizationStatusFor, availableQuantityTypes, disableAllBackgroundDelivery, disableBackgroundDelivery, enableBackgroundDelivery, getBiologicalSex, getBloodType, getDateOfBirth, getFitzpatrickSkinType, getMostRecentCategorySample, getMostRecentQuantitySample, getMostRecentWorkout, getPreferredUnit, getPreferredUnits, getRequestStatusForAuthorization, getWheelchairUse, getWorkoutRoutes, isHealthDataAvailable, queryCategorySamples, queryCategorySamplesWithAnchor, queryCorrelationSamples, queryHeartbeatSeriesSamples, queryHeartbeatSeriesSamplesWithAnchor, queryQuantitySamples, queryQuantitySamplesWithAnchor, queryStatisticsForQuantity, queryStatisticsCollectionForQuantity,
|
|
179
183
|
/**
|
|
180
184
|
* @deprecated Use queryWorkoutSamples instead
|
|
181
185
|
*/
|
|
182
|
-
queryWorkouts, queryWorkoutSamples, queryWorkoutSamplesWithAnchor, querySources, requestAuthorization, deleteQuantitySample, deleteSamples, getWorkoutPlanById, saveCategorySample, saveCorrelationSample, saveQuantitySample, saveWorkoutSample, saveWorkoutRoute, subscribeToChanges, useMostRecentCategorySample, useMostRecentQuantitySample, useMostRecentWorkout, useSubscribeToChanges, useHealthkitAuthorization, useIsHealthDataAvailable, useSources, useStatisticsForQuantity, isProtectedDataAvailable, };
|
|
186
|
+
queryWorkouts, queryWorkoutSamples, queryWorkoutSamplesWithAnchor, querySources, requestAuthorization, deleteQuantitySample, deleteSamples, getWorkoutPlanById, saveCategorySample, saveCorrelationSample, saveQuantitySample, saveWorkoutSample, saveWorkoutRoute, subscribeToChanges, startWatchApp, useMostRecentCategorySample, useMostRecentQuantitySample, useMostRecentWorkout, useSubscribeToChanges, useHealthkitAuthorization, useIsHealthDataAvailable, useSources, useStatisticsForQuantity, isProtectedDataAvailable, };
|
|
183
187
|
export * from './types';
|
|
@@ -22,12 +22,20 @@ declare const authorizationStatusFor: () => Promise<HKAuthorizationStatus>, avai
|
|
|
22
22
|
mostRecentQuantity: undefined;
|
|
23
23
|
mostRecentQuantityDateInterval: undefined;
|
|
24
24
|
duration: undefined;
|
|
25
|
-
}>,
|
|
25
|
+
}>, queryStatisticsCollectionForQuantity: () => Promise<{
|
|
26
|
+
averageQuantity: undefined;
|
|
27
|
+
maximumQuantity: undefined;
|
|
28
|
+
minimumQuantity: undefined;
|
|
29
|
+
sumQuantity: undefined;
|
|
30
|
+
mostRecentQuantity: undefined;
|
|
31
|
+
mostRecentQuantityDateInterval: undefined;
|
|
32
|
+
duration: undefined;
|
|
33
|
+
}[]>, queryWorkouts: () => Promise<never[]>, queryWorkoutSamples: () => Promise<never[]>, queryWorkoutSamplesWithAnchor: () => Promise<{
|
|
26
34
|
samples: never[];
|
|
27
35
|
deletedSamples: never[];
|
|
28
36
|
newAnchor: string;
|
|
29
|
-
}>, querySources: () => Promise<never[]>, requestAuthorization: () => Promise<boolean>, deleteQuantitySample: () => Promise<boolean>, deleteSamples: () => Promise<boolean>, getWorkoutPlanById: () => Promise<null>, saveCategorySample: () => Promise<boolean>, saveCorrelationSample: () => Promise<boolean>, saveQuantitySample: () => Promise<boolean>, saveWorkoutSample: () => Promise<null>, saveWorkoutRoute: () => Promise<boolean>, subscribeToChanges: () => Promise<() => Promise<boolean>>, useMostRecentCategorySample: () => null, useMostRecentQuantitySample: () => null, useMostRecentWorkout: () => null, useSubscribeToChanges: () => ((() => null) | null)[], useHealthkitAuthorization: () => readonly [null, () => Promise<HKAuthorizationRequestStatus>], useIsHealthDataAvailable: () => boolean, isProtectedDataAvailable: () => Promise<boolean>;
|
|
37
|
+
}>, querySources: () => Promise<never[]>, requestAuthorization: () => Promise<boolean>, deleteQuantitySample: () => Promise<boolean>, deleteSamples: () => Promise<boolean>, getWorkoutPlanById: () => Promise<null>, saveCategorySample: () => Promise<boolean>, saveCorrelationSample: () => Promise<boolean>, saveQuantitySample: () => Promise<boolean>, saveWorkoutSample: () => Promise<null>, saveWorkoutRoute: () => Promise<boolean>, subscribeToChanges: () => Promise<() => Promise<boolean>>, startWatchApp: () => () => Promise<boolean>, useMostRecentCategorySample: () => null, useMostRecentQuantitySample: () => null, useMostRecentWorkout: () => null, useSubscribeToChanges: () => ((() => null) | null)[], useHealthkitAuthorization: () => readonly [null, () => Promise<HKAuthorizationRequestStatus>], useIsHealthDataAvailable: () => boolean, isProtectedDataAvailable: () => Promise<boolean>;
|
|
30
38
|
declare const Healthkit: typeof ReactNativeHealthkit;
|
|
31
|
-
export { authorizationStatusFor, availableQuantityTypes, deleteQuantitySample, deleteSamples, disableAllBackgroundDelivery, disableBackgroundDelivery, enableBackgroundDelivery, getBiologicalSex, getBloodType, getDateOfBirth, getFitzpatrickSkinType, getMostRecentCategorySample, getMostRecentQuantitySample, getMostRecentWorkout, getPreferredUnit, getPreferredUnits, getRequestStatusForAuthorization, getWheelchairUse, getWorkoutPlanById, getWorkoutRoutes, isHealthDataAvailable, isProtectedDataAvailable, queryCategorySamples, queryCategorySamplesWithAnchor, queryCorrelationSamples, queryHeartbeatSeriesSamples, queryHeartbeatSeriesSamplesWithAnchor, queryQuantitySamples, queryQuantitySamplesWithAnchor, querySources, queryStatisticsForQuantity, queryWorkouts, queryWorkoutSamples, queryWorkoutSamplesWithAnchor, requestAuthorization, saveCategorySample, saveCorrelationSample, saveQuantitySample, saveWorkoutRoute, saveWorkoutSample, subscribeToChanges, useHealthkitAuthorization, useIsHealthDataAvailable, useMostRecentCategorySample, useMostRecentQuantitySample, useMostRecentWorkout, useSources, useStatisticsForQuantity, useSubscribeToChanges, };
|
|
39
|
+
export { authorizationStatusFor, availableQuantityTypes, deleteQuantitySample, deleteSamples, disableAllBackgroundDelivery, disableBackgroundDelivery, enableBackgroundDelivery, getBiologicalSex, getBloodType, getDateOfBirth, getFitzpatrickSkinType, getMostRecentCategorySample, getMostRecentQuantitySample, getMostRecentWorkout, getPreferredUnit, getPreferredUnits, getRequestStatusForAuthorization, getWheelchairUse, getWorkoutPlanById, getWorkoutRoutes, isHealthDataAvailable, isProtectedDataAvailable, queryCategorySamples, queryCategorySamplesWithAnchor, queryCorrelationSamples, queryHeartbeatSeriesSamples, queryHeartbeatSeriesSamplesWithAnchor, queryQuantitySamples, queryQuantitySamplesWithAnchor, querySources, queryStatisticsForQuantity, queryStatisticsCollectionForQuantity, queryWorkouts, queryWorkoutSamples, queryWorkoutSamplesWithAnchor, requestAuthorization, saveCategorySample, saveCorrelationSample, saveQuantitySample, saveWorkoutRoute, saveWorkoutSample, subscribeToChanges, startWatchApp, useHealthkitAuthorization, useIsHealthDataAvailable, useMostRecentCategorySample, useMostRecentQuantitySample, useMostRecentWorkout, useSources, useStatisticsForQuantity, useSubscribeToChanges, };
|
|
32
40
|
export * from './types';
|
|
33
41
|
export default Healthkit;
|
|
@@ -1014,6 +1014,13 @@ export type QueryStatisticsResponseRaw<TIdentifier extends HKQuantityTypeIdentif
|
|
|
1014
1014
|
};
|
|
1015
1015
|
readonly duration?: HKQuantity<HKQuantityTypeIdentifier, TimeUnit>;
|
|
1016
1016
|
};
|
|
1017
|
+
export interface IntervalComponents {
|
|
1018
|
+
readonly minute?: number;
|
|
1019
|
+
readonly hour?: number;
|
|
1020
|
+
readonly day?: number;
|
|
1021
|
+
readonly month?: number;
|
|
1022
|
+
readonly year?: number;
|
|
1023
|
+
}
|
|
1017
1024
|
/**
|
|
1018
1025
|
* @see {@link https://developer.apple.com/documentation/healthkit/hkcategoryvaluecervicalmucusquality Apple Docs }
|
|
1019
1026
|
*/
|
|
@@ -1167,7 +1174,8 @@ export declare enum HKUnits {
|
|
|
1167
1174
|
DecibelSoundPressureLevel = "dBASPL",
|
|
1168
1175
|
Percent = "%",
|
|
1169
1176
|
Count = "count",
|
|
1170
|
-
InternationalUnit = "IU"
|
|
1177
|
+
InternationalUnit = "IU",
|
|
1178
|
+
AppleEffortScore = "appleEffortScore"
|
|
1171
1179
|
}
|
|
1172
1180
|
export type MeterUnit<Prefix extends HKMetricPrefix = HKMetricPrefix.None> = `${Prefix}${HKUnitMetric.Meter}`;
|
|
1173
1181
|
export type LiterUnit<Prefix extends HKMetricPrefix = HKMetricPrefix.None> = `${Prefix}${HKUnitMetric.Liter}`;
|
|
@@ -1506,6 +1514,21 @@ type QueryWorkoutSamplesWithAnchorResponseRaw<TEnergy extends EnergyUnit, TDista
|
|
|
1506
1514
|
readonly deletedSamples: readonly DeletedWorkoutSampleRaw[];
|
|
1507
1515
|
readonly newAnchor: string;
|
|
1508
1516
|
};
|
|
1517
|
+
/**
|
|
1518
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkworkoutconfiguration Apple Docs }
|
|
1519
|
+
*/
|
|
1520
|
+
export type HKWorkoutConfiguration = {
|
|
1521
|
+
readonly activityType: HKWorkoutActivityType;
|
|
1522
|
+
readonly locationType?: HKWorkoutSessionLocationType;
|
|
1523
|
+
};
|
|
1524
|
+
/**
|
|
1525
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkworkoutsessionlocationtype Apple Docs }
|
|
1526
|
+
*/
|
|
1527
|
+
export declare enum HKWorkoutSessionLocationType {
|
|
1528
|
+
unknown = 1,
|
|
1529
|
+
indoor = 2,
|
|
1530
|
+
outdoor = 3
|
|
1531
|
+
}
|
|
1509
1532
|
type ReactNativeHealthkitTypeNative = {
|
|
1510
1533
|
/**
|
|
1511
1534
|
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614180-ishealthdataavailable Apple Docs }
|
|
@@ -1564,12 +1587,17 @@ type ReactNativeHealthkitTypeNative = {
|
|
|
1564
1587
|
readonly querySources: <TIdentifier extends HKCategoryTypeIdentifier | HKQuantityTypeIdentifier>(identifier: TIdentifier) => Promise<readonly HKSource[]>;
|
|
1565
1588
|
readonly saveCategorySample: <T extends HKCategoryTypeIdentifier>(identifier: T, value: HKCategoryValueForIdentifier<T>, start: string, end: string, metadata: unknown) => Promise<boolean>;
|
|
1566
1589
|
readonly queryStatisticsForQuantity: <TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier>>(identifier: HKQuantityTypeIdentifier, unit: TUnit, from: string, to: string, options: readonly HKStatisticsOptions[]) => Promise<QueryStatisticsResponseRaw<TIdentifier, TUnit>>;
|
|
1590
|
+
readonly queryStatisticsCollectionForQuantity: <TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier>>(identifier: TIdentifier, unit: TUnit, options: readonly HKStatisticsOptions[], anchorDate: string, intervalComponents: IntervalComponents, startDate: string, endDate: string) => Promise<readonly QueryStatisticsResponseRaw<TIdentifier, TUnit>[]>;
|
|
1567
1591
|
readonly getPreferredUnits: (identifiers: readonly HKQuantityTypeIdentifier[]) => Promise<TypeToUnitMapping>;
|
|
1568
1592
|
readonly getWorkoutRoutes: (workoutUUID: string) => Promise<readonly WorkoutRoute[]>;
|
|
1569
1593
|
readonly getWorkoutPlanById: (workoutUUID: string) => Promise<{
|
|
1570
1594
|
readonly id: string;
|
|
1571
1595
|
readonly activityType: HKWorkoutActivityType;
|
|
1572
1596
|
} | null>;
|
|
1597
|
+
/**
|
|
1598
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1648358-startwatchapp Apple Docs }
|
|
1599
|
+
*/
|
|
1600
|
+
readonly startWatchAppWithWorkoutConfiguration: (workoutConfiguration: HKWorkoutConfiguration) => Promise<boolean>;
|
|
1573
1601
|
};
|
|
1574
1602
|
declare const Native: ReactNativeHealthkitTypeNative;
|
|
1575
1603
|
type OnChangeCallback = ({ typeIdentifier, }: {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { HKQuantityTypeIdentifier, HKStatisticsOptions, UnitForIdentifier, IntervalComponents } from '../native-types';
|
|
2
|
+
declare function queryStatisticsCollectionForQuantity<TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier> = UnitForIdentifier<TIdentifier>>(identifier: TIdentifier, options: readonly HKStatisticsOptions[], anchorDate: Date, intervalComponents: IntervalComponents, startDate: Date, endDate: Date, unit?: TUnit): Promise<readonly import("../native-types").QueryStatisticsResponseRaw<TIdentifier, TUnit>[]>;
|
|
3
|
+
export default queryStatisticsCollectionForQuantity;
|
package/package.json
CHANGED
package/src/index.ios.tsx
CHANGED
|
@@ -27,6 +27,7 @@ import queryHeartbeatSeriesSamplesWithAnchor from './utils/queryHeartbeatSeriesS
|
|
|
27
27
|
import queryQuantitySamples from './utils/queryQuantitySamples'
|
|
28
28
|
import queryQuantitySamplesWithAnchor from './utils/queryQuantitySamplesWithAnchor'
|
|
29
29
|
import querySources from './utils/querySources'
|
|
30
|
+
import queryStatisticsCollectionForQuantity from './utils/queryStatisticsCollectionForQuantity'
|
|
30
31
|
import queryStatisticsForQuantity from './utils/queryStatisticsForQuantity'
|
|
31
32
|
import queryWorkoutSamples from './utils/queryWorkouts'
|
|
32
33
|
import queryWorkoutSamplesWithAnchor from './utils/queryWorkoutSamplesWithAnchor'
|
|
@@ -36,6 +37,7 @@ import saveCorrelationSample from './utils/saveCorrelationSample'
|
|
|
36
37
|
import saveQuantitySample from './utils/saveQuantitySample'
|
|
37
38
|
import saveWorkoutRoute from './utils/saveWorkoutRoute'
|
|
38
39
|
import saveWorkoutSample from './utils/saveWorkoutSample'
|
|
40
|
+
import startWatchApp from './utils/startWatchApp'
|
|
39
41
|
import subscribeToChanges from './utils/subscribeToChanges'
|
|
40
42
|
|
|
41
43
|
const currentMajorVersionIOS = Platform.OS === 'ios' ? parseInt(Platform.Version, 10) : 0
|
|
@@ -159,6 +161,7 @@ export default {
|
|
|
159
161
|
queryQuantitySamples,
|
|
160
162
|
queryQuantitySamplesWithAnchor,
|
|
161
163
|
queryStatisticsForQuantity,
|
|
164
|
+
queryStatisticsCollectionForQuantity,
|
|
162
165
|
/**
|
|
163
166
|
* @deprecated Use queryWorkoutSamples instead
|
|
164
167
|
*/
|
|
@@ -187,6 +190,8 @@ export default {
|
|
|
187
190
|
// subscriptions
|
|
188
191
|
subscribeToChanges,
|
|
189
192
|
|
|
193
|
+
startWatchApp,
|
|
194
|
+
|
|
190
195
|
/**
|
|
191
196
|
* @returns the most recent sample for the given category type.
|
|
192
197
|
*/
|
|
@@ -245,6 +250,7 @@ export {
|
|
|
245
250
|
queryQuantitySamples,
|
|
246
251
|
queryQuantitySamplesWithAnchor,
|
|
247
252
|
queryStatisticsForQuantity,
|
|
253
|
+
queryStatisticsCollectionForQuantity,
|
|
248
254
|
/**
|
|
249
255
|
* @deprecated Use queryWorkoutSamples instead
|
|
250
256
|
*/
|
|
@@ -262,6 +268,7 @@ export {
|
|
|
262
268
|
saveWorkoutSample,
|
|
263
269
|
saveWorkoutRoute,
|
|
264
270
|
subscribeToChanges,
|
|
271
|
+
startWatchApp,
|
|
265
272
|
useMostRecentCategorySample,
|
|
266
273
|
useMostRecentQuantitySample,
|
|
267
274
|
useMostRecentWorkout,
|
package/src/index.native.tsx
CHANGED
|
@@ -73,6 +73,17 @@ const authorizationStatusFor = UnavailableFn(Promise.resolve(HKAuthorizationStat
|
|
|
73
73
|
mostRecentQuantityDateInterval: undefined,
|
|
74
74
|
duration: undefined,
|
|
75
75
|
})),
|
|
76
|
+
queryStatisticsCollectionForQuantity = UnavailableFn(Promise.resolve([
|
|
77
|
+
{
|
|
78
|
+
averageQuantity: undefined,
|
|
79
|
+
maximumQuantity: undefined,
|
|
80
|
+
minimumQuantity: undefined,
|
|
81
|
+
sumQuantity: undefined,
|
|
82
|
+
mostRecentQuantity: undefined,
|
|
83
|
+
mostRecentQuantityDateInterval: undefined,
|
|
84
|
+
duration: undefined,
|
|
85
|
+
},
|
|
86
|
+
])),
|
|
76
87
|
queryWorkouts = UnavailableFn(Promise.resolve([])),
|
|
77
88
|
queryWorkoutSamples = UnavailableFn(Promise.resolve([])),
|
|
78
89
|
queryWorkoutSamplesWithAnchor = UnavailableFn(Promise.resolve({
|
|
@@ -91,6 +102,7 @@ const authorizationStatusFor = UnavailableFn(Promise.resolve(HKAuthorizationStat
|
|
|
91
102
|
saveWorkoutSample = UnavailableFn(Promise.resolve(null)),
|
|
92
103
|
saveWorkoutRoute = UnavailableFn(Promise.resolve(false)),
|
|
93
104
|
subscribeToChanges = UnavailableFn(Promise.resolve(async () => Promise.resolve(false))),
|
|
105
|
+
startWatchApp = UnavailableFn(async () => Promise.resolve(false)),
|
|
94
106
|
useMostRecentCategorySample = UnavailableFn(null),
|
|
95
107
|
useMostRecentQuantitySample = UnavailableFn(null),
|
|
96
108
|
useMostRecentWorkout = UnavailableFn(null),
|
|
@@ -131,6 +143,7 @@ const Healthkit: typeof ReactNativeHealthkit = {
|
|
|
131
143
|
queryQuantitySamplesWithAnchor,
|
|
132
144
|
querySources,
|
|
133
145
|
queryStatisticsForQuantity,
|
|
146
|
+
queryStatisticsCollectionForQuantity,
|
|
134
147
|
queryWorkouts,
|
|
135
148
|
queryWorkoutSamples,
|
|
136
149
|
queryWorkoutSamplesWithAnchor,
|
|
@@ -141,6 +154,7 @@ const Healthkit: typeof ReactNativeHealthkit = {
|
|
|
141
154
|
saveWorkoutRoute,
|
|
142
155
|
saveWorkoutSample,
|
|
143
156
|
subscribeToChanges,
|
|
157
|
+
startWatchApp,
|
|
144
158
|
useHealthkitAuthorization,
|
|
145
159
|
useIsHealthDataAvailable,
|
|
146
160
|
useMostRecentCategorySample,
|
|
@@ -183,6 +197,7 @@ export {
|
|
|
183
197
|
queryQuantitySamplesWithAnchor,
|
|
184
198
|
querySources,
|
|
185
199
|
queryStatisticsForQuantity,
|
|
200
|
+
queryStatisticsCollectionForQuantity,
|
|
186
201
|
queryWorkouts,
|
|
187
202
|
queryWorkoutSamples,
|
|
188
203
|
queryWorkoutSamplesWithAnchor,
|
|
@@ -193,6 +208,7 @@ export {
|
|
|
193
208
|
saveWorkoutRoute,
|
|
194
209
|
saveWorkoutSample,
|
|
195
210
|
subscribeToChanges,
|
|
211
|
+
startWatchApp,
|
|
196
212
|
useHealthkitAuthorization,
|
|
197
213
|
useIsHealthDataAvailable,
|
|
198
214
|
useMostRecentCategorySample,
|
package/src/native-types.ts
CHANGED
|
@@ -1172,6 +1172,14 @@ export type QueryStatisticsResponseRaw<
|
|
|
1172
1172
|
readonly duration?: HKQuantity<HKQuantityTypeIdentifier, TimeUnit>;
|
|
1173
1173
|
};
|
|
1174
1174
|
|
|
1175
|
+
export interface IntervalComponents {
|
|
1176
|
+
readonly minute?: number;
|
|
1177
|
+
readonly hour?: number;
|
|
1178
|
+
readonly day?: number;
|
|
1179
|
+
readonly month?: number;
|
|
1180
|
+
readonly year?: number;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1175
1183
|
/**
|
|
1176
1184
|
* @see {@link https://developer.apple.com/documentation/healthkit/hkcategoryvaluecervicalmucusquality Apple Docs }
|
|
1177
1185
|
*/
|
|
@@ -1545,10 +1553,10 @@ export enum HKUnitMetric {
|
|
|
1545
1553
|
export enum HKUnits {
|
|
1546
1554
|
DecibelHearingLevel = 'dBHL',
|
|
1547
1555
|
DecibelSoundPressureLevel = 'dBASPL',
|
|
1548
|
-
|
|
1549
1556
|
Percent = '%',
|
|
1550
1557
|
Count = 'count',
|
|
1551
1558
|
InternationalUnit = 'IU',
|
|
1559
|
+
AppleEffortScore = 'appleEffortScore'
|
|
1552
1560
|
}
|
|
1553
1561
|
|
|
1554
1562
|
export type MeterUnit<Prefix extends HKMetricPrefix = HKMetricPrefix.None> =
|
|
@@ -2008,6 +2016,23 @@ type QueryWorkoutSamplesWithAnchorResponseRaw<
|
|
|
2008
2016
|
readonly newAnchor: string
|
|
2009
2017
|
}
|
|
2010
2018
|
|
|
2019
|
+
/**
|
|
2020
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkworkoutconfiguration Apple Docs }
|
|
2021
|
+
*/
|
|
2022
|
+
export type HKWorkoutConfiguration = {
|
|
2023
|
+
readonly activityType: HKWorkoutActivityType;
|
|
2024
|
+
readonly locationType?: HKWorkoutSessionLocationType;
|
|
2025
|
+
};
|
|
2026
|
+
|
|
2027
|
+
/**
|
|
2028
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkworkoutsessionlocationtype Apple Docs }
|
|
2029
|
+
*/
|
|
2030
|
+
export enum HKWorkoutSessionLocationType {
|
|
2031
|
+
unknown = 1,
|
|
2032
|
+
indoor = 2,
|
|
2033
|
+
outdoor = 3
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2011
2036
|
type ReactNativeHealthkitTypeNative = {
|
|
2012
2037
|
/**
|
|
2013
2038
|
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614180-ishealthdataavailable Apple Docs }
|
|
@@ -2212,6 +2237,18 @@ type ReactNativeHealthkitTypeNative = {
|
|
|
2212
2237
|
to: string,
|
|
2213
2238
|
options: readonly HKStatisticsOptions[]
|
|
2214
2239
|
) => Promise<QueryStatisticsResponseRaw<TIdentifier, TUnit>>;
|
|
2240
|
+
readonly queryStatisticsCollectionForQuantity: <
|
|
2241
|
+
TIdentifier extends HKQuantityTypeIdentifier,
|
|
2242
|
+
TUnit extends UnitForIdentifier<TIdentifier>
|
|
2243
|
+
>(
|
|
2244
|
+
identifier: TIdentifier,
|
|
2245
|
+
unit: TUnit,
|
|
2246
|
+
options: readonly HKStatisticsOptions[],
|
|
2247
|
+
anchorDate: string,
|
|
2248
|
+
intervalComponents: IntervalComponents,
|
|
2249
|
+
startDate: string,
|
|
2250
|
+
endDate: string
|
|
2251
|
+
) => Promise<readonly QueryStatisticsResponseRaw<TIdentifier, TUnit>[]>;
|
|
2215
2252
|
readonly getPreferredUnits: (
|
|
2216
2253
|
identifiers: readonly HKQuantityTypeIdentifier[]
|
|
2217
2254
|
) => Promise<TypeToUnitMapping>;
|
|
@@ -2219,6 +2256,13 @@ type ReactNativeHealthkitTypeNative = {
|
|
|
2219
2256
|
workoutUUID: string
|
|
2220
2257
|
) => Promise<readonly WorkoutRoute[]>;
|
|
2221
2258
|
readonly getWorkoutPlanById: (workoutUUID: string) => Promise<{readonly id: string, readonly activityType: HKWorkoutActivityType} | null>;
|
|
2259
|
+
|
|
2260
|
+
/**
|
|
2261
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1648358-startwatchapp Apple Docs }
|
|
2262
|
+
*/
|
|
2263
|
+
readonly startWatchAppWithWorkoutConfiguration: (
|
|
2264
|
+
workoutConfiguration: HKWorkoutConfiguration
|
|
2265
|
+
) => Promise<boolean>;
|
|
2222
2266
|
};
|
|
2223
2267
|
|
|
2224
2268
|
const Native = NativeModules.ReactNativeHealthkit as ReactNativeHealthkitTypeNative
|
package/src/test-setup.ts
CHANGED
|
@@ -33,6 +33,7 @@ beforeAll(async () => {
|
|
|
33
33
|
queryQuantitySamples: jest.fn(),
|
|
34
34
|
querySources: jest.fn(),
|
|
35
35
|
queryStatisticsForQuantity: jest.fn(),
|
|
36
|
+
queryStatisticsCollectionForQuantity: jest.fn(),
|
|
36
37
|
queryWorkoutSamples: jest.fn(),
|
|
37
38
|
saveCategorySample: jest.fn(),
|
|
38
39
|
saveCorrelationSample: jest.fn(),
|
|
@@ -41,6 +42,7 @@ beforeAll(async () => {
|
|
|
41
42
|
unsubscribeQuery: jest.fn(),
|
|
42
43
|
saveWorkoutRoute: jest.fn(),
|
|
43
44
|
getWorkoutPlanById: jest.fn(),
|
|
45
|
+
startWatchAppWithWorkoutConfiguration: jest.fn(),
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
await mock.module('react-native', () => ({
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import ensureUnit from './ensureUnit'
|
|
2
|
+
import Native from '../native-types'
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
HKQuantityTypeIdentifier,
|
|
6
|
+
HKStatisticsOptions,
|
|
7
|
+
UnitForIdentifier,
|
|
8
|
+
IntervalComponents,
|
|
9
|
+
} from '../native-types'
|
|
10
|
+
|
|
11
|
+
async function queryStatisticsCollectionForQuantity<
|
|
12
|
+
TIdentifier extends HKQuantityTypeIdentifier,
|
|
13
|
+
TUnit extends UnitForIdentifier<TIdentifier> = UnitForIdentifier<TIdentifier>
|
|
14
|
+
>(
|
|
15
|
+
identifier: TIdentifier,
|
|
16
|
+
options: readonly HKStatisticsOptions[],
|
|
17
|
+
anchorDate: Date,
|
|
18
|
+
intervalComponents: IntervalComponents,
|
|
19
|
+
startDate: Date,
|
|
20
|
+
endDate: Date,
|
|
21
|
+
unit?: TUnit,
|
|
22
|
+
) {
|
|
23
|
+
const actualUnit = await ensureUnit(identifier, unit)
|
|
24
|
+
|
|
25
|
+
const rawResponse = await Native.queryStatisticsCollectionForQuantity(
|
|
26
|
+
identifier,
|
|
27
|
+
actualUnit,
|
|
28
|
+
options,
|
|
29
|
+
anchorDate.toISOString(),
|
|
30
|
+
intervalComponents,
|
|
31
|
+
startDate.toISOString(),
|
|
32
|
+
endDate.toISOString(),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
return rawResponse
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default queryStatisticsCollectionForQuantity
|