@kingstinct/react-native-healthkit 4.1.1 → 4.4.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.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/ios/ReactNativeHealthkit.m +15 -10
  3. package/ios/ReactNativeHealthkit.swift +365 -177
  4. package/lib/commonjs/index.ios.js +104 -106
  5. package/lib/commonjs/index.ios.js.map +1 -1
  6. package/lib/commonjs/index.js +11 -10
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/commonjs/native-types.js +25 -1
  9. package/lib/commonjs/native-types.js.map +1 -1
  10. package/lib/commonjs/types.js +4 -0
  11. package/lib/commonjs/types.js.map +1 -1
  12. package/lib/example/App.js +197 -0
  13. package/lib/index.ios.js +310 -0
  14. package/lib/index.js +44 -0
  15. package/lib/module/index.ios.js +104 -106
  16. package/lib/module/index.ios.js.map +1 -1
  17. package/lib/module/index.js +4 -3
  18. package/lib/module/index.js.map +1 -1
  19. package/lib/module/native-types.js +20 -1
  20. package/lib/module/native-types.js.map +1 -1
  21. package/lib/module/types.js +1 -1
  22. package/lib/module/types.js.map +1 -1
  23. package/lib/native-types.js +447 -0
  24. package/lib/src/index.ios.js +314 -0
  25. package/lib/src/index.js +45 -0
  26. package/lib/src/native-types.js +453 -0
  27. package/lib/src/types.js +1 -0
  28. package/lib/types.js +1 -0
  29. package/lib/typescript/src/index.d.ts +1 -1
  30. package/lib/typescript/src/index.ios.d.ts +1 -1
  31. package/lib/typescript/src/native-types.d.ts +142 -108
  32. package/lib/typescript/src/types.d.ts +80 -78
  33. package/package.json +25 -39
  34. package/src/index.ios.tsx +260 -264
  35. package/src/index.tsx +14 -13
  36. package/src/native-types.ts +213 -179
  37. package/src/types.ts +106 -100
  38. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
  39. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  40. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcuserdata/robertherber.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  41. package/ios/ReactNativeHealthkit.xcodeproj/xcuserdata/robertherber.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
package/src/index.tsx CHANGED
@@ -1,14 +1,14 @@
1
- import { Platform } from 'react-native';
2
- import type { ReactNativeHealthkit } from './types';
1
+ import { Platform } from 'react-native'
3
2
 
4
- const notAvailableError =
5
- 'Platform "' +
6
- Platform.OS +
7
- '" not supported, use isHealthDataAvailable to check for availability before using it';
3
+ import type { ReactNativeHealthkit } from './types'
4
+
5
+ const notAvailableError = `Platform "${
6
+ Platform.OS
7
+ }" not supported, use isHealthDataAvailable to check for availability before using it`
8
8
 
9
9
  const UnavailableFn = () => {
10
- throw new Error(notAvailableError);
11
- };
10
+ throw new Error(notAvailableError)
11
+ }
12
12
 
13
13
  const Healthkit: ReactNativeHealthkit = {
14
14
  authorizationStatusFor: UnavailableFn,
@@ -27,7 +27,8 @@ const Healthkit: ReactNativeHealthkit = {
27
27
  getPreferredUnits: UnavailableFn,
28
28
  getRequestStatusForAuthorization: UnavailableFn,
29
29
  getWheelchairUse: UnavailableFn,
30
- isHealthDataAvailable: () => Promise.resolve(false),
30
+ getWorkoutRoutes: UnavailableFn,
31
+ isHealthDataAvailable: async () => Promise.resolve(false),
31
32
  queryCategorySamples: UnavailableFn,
32
33
  queryCorrelationSamples: UnavailableFn,
33
34
  queryQuantitySamples: UnavailableFn,
@@ -43,9 +44,9 @@ const Healthkit: ReactNativeHealthkit = {
43
44
  useMostRecentQuantitySample: UnavailableFn,
44
45
  useMostRecentWorkout: UnavailableFn,
45
46
  useSubscribeToChanges: UnavailableFn,
46
- };
47
+ }
47
48
 
48
- export * from './types';
49
- export * from './native-types';
49
+ export * from './native-types'
50
+ export * from './types'
50
51
 
51
- export default Healthkit;
52
+ export default Healthkit
@@ -1,20 +1,25 @@
1
1
  import {
2
- NativeModules,
3
2
  NativeEventEmitter,
4
- EmitterSubscription,
5
- } from 'react-native';
3
+ NativeModules,
4
+ } from 'react-native'
5
+
6
+ import type { EmitterSubscription } from 'react-native'
6
7
 
7
- export type HKWorkoutTypeIdentifier = 'HKWorkoutTypeIdentifier';
8
- export type HKAudiogramTypeIdentifier = 'HKAudiogramTypeIdentifier';
8
+ export const HKWorkoutTypeIdentifier = 'HKWorkoutTypeIdentifier'
9
+ export const HKAudiogramTypeIdentifier = 'HKAudiogramTypeIdentifier'
10
+ export const HKWorkoutRouteTypeIdentifier = 'HKWorkoutRouteTypeIdentifier'
11
+ export const HKDataTypeIdentifierHeartbeatSeries = 'HKDataTypeIdentifierHeartbeatSeries'
9
12
 
10
13
  export type HKSampleTypeIdentifier =
11
- | HKWorkoutTypeIdentifier
12
- | HKQuantityTypeIdentifier
13
14
  | HKCategoryTypeIdentifier
14
- | HKAudiogramTypeIdentifier
15
- | HKCorrelationTypeIdentifier;
15
+ | HKCorrelationTypeIdentifier
16
+ | HKQuantityTypeIdentifier
17
+ | typeof HKAudiogramTypeIdentifier
18
+ | typeof HKDataTypeIdentifierHeartbeatSeries
19
+ | typeof HKWorkoutRouteTypeIdentifier
20
+ | typeof HKWorkoutTypeIdentifier;
16
21
 
17
- export type TypeToUnitMapping = {
22
+ export type TypeToUnitMapping = { readonly
18
23
  [key in HKQuantityTypeIdentifier]: HKUnit;
19
24
  };
20
25
 
@@ -126,21 +131,21 @@ export enum HKWorkoutActivityType {
126
131
  }
127
132
 
128
133
  export type HKGenericMetadata = {
129
- [key: string]: string | number | boolean | HKQuantity | undefined;
130
- HKExternalUUID?: string;
131
- HKTimeZone?: string;
132
- HKWasUserEntered?: boolean;
133
- HKDeviceSerialNumber?: string;
134
- HKUDIDeviceIdentifier?: string;
135
- HKUDIProductionIdentifier?: string;
136
- HKDigitalSignature?: string;
137
- HKDeviceName?: string;
138
- HKDeviceManufacturerName?: string;
139
- HKSyncIdentifier?: string;
140
- HKSyncVersion?: number;
141
- HKWasTakenInLab?: boolean;
142
- HKReferenceRangeLowerLimit?: number;
143
- HKReferenceRangeUpperLimit?: number;
134
+ readonly [key: string]: HKQuantity | boolean | number | string | undefined;
135
+ readonly HKExternalUUID?: string;
136
+ readonly HKTimeZone?: string;
137
+ readonly HKWasUserEntered?: boolean;
138
+ readonly HKDeviceSerialNumber?: string;
139
+ readonly HKUDIDeviceIdentifier?: string;
140
+ readonly HKUDIProductionIdentifier?: string;
141
+ readonly HKDigitalSignature?: string;
142
+ readonly HKDeviceName?: string;
143
+ readonly HKDeviceManufacturerName?: string;
144
+ readonly HKSyncIdentifier?: string;
145
+ readonly HKSyncVersion?: number;
146
+ readonly HKWasTakenInLab?: boolean;
147
+ readonly HKReferenceRangeLowerLimit?: number;
148
+ readonly HKReferenceRangeUpperLimit?: number;
144
149
  };
145
150
 
146
151
  // documented at https://developer.apple.com/documentation/healthkit/hkweathercondition
@@ -176,9 +181,9 @@ export enum HKWeatherCondition {
176
181
  }
177
182
 
178
183
  export interface HKWorkoutMetadata
179
- extends HKGenericMetadata /*<TTemperatureUnit extends HKUnit>*/ {
180
- HKWeatherCondition?: HKWeatherCondition;
181
- HKWeatherHumidity?: HKQuantity<HKUnit.Percent>;
184
+ extends HKGenericMetadata /* <TTemperatureUnit extends HKUnit> */ {
185
+ readonly HKWeatherCondition?: HKWeatherCondition;
186
+ readonly HKWeatherHumidity?: HKQuantity<HKUnit.Percent>;
182
187
  // HKWeatherTemperature: HKQuantity<TTemperatureUnit>
183
188
  }
184
189
 
@@ -279,6 +284,15 @@ export enum HKQuantityTypeIdentifier {
279
284
  dietaryCaffeine = 'HKQuantityTypeIdentifierDietaryCaffeine', // Mass, Cumulative
280
285
  dietaryWater = 'HKQuantityTypeIdentifierDietaryWater', // Volume, Cumulative
281
286
 
287
+ // Mobility
288
+ sixMinuteWalkTestDistance = 'HKQuantityTypeIdentifierSixMinuteWalkTestDistance',
289
+ walkingSpeed = 'HKQuantityTypeIdentifierWalkingSpeed',
290
+ walkingStepLength = 'HKQuantityTypeIdentifierWalkingStepLength',
291
+ walkingAsymmetryPercentage = 'HKQuantityTypeIdentifierWalkingAsymmetryPercentage',
292
+ walkingDoubleSupportPercentage = 'HKQuantityTypeIdentifierWalkingDoubleSupportPercentage',
293
+ stairAscentSpeed = 'HKQuantityTypeIdentifierStairAscentSpeed',
294
+ stairDescentSpeed = 'HKQuantityTypeIdentifierStairDescentSpeed',
295
+
282
296
  uvExposure = 'HKQuantityTypeIdentifierUvExposure', // Scalar (Count), Discrete
283
297
  }
284
298
 
@@ -288,9 +302,15 @@ export enum HKAuthorizationRequestStatus {
288
302
  unnecessary = 2,
289
303
  }
290
304
 
305
+ export enum HKAuthorizationStatus {
306
+ notDetermined = 0,
307
+ sharingDenied = 1,
308
+ sharingAuthorized = 2,
309
+ }
310
+
291
311
  export type HKQuantity<T extends HKUnit = HKUnit> = {
292
- unit: T;
293
- quantity: number;
312
+ readonly unit: T;
313
+ readonly quantity: number;
294
314
  };
295
315
 
296
316
  export enum HKBloodType {
@@ -334,13 +354,13 @@ export enum HKStatisticsOptions {
334
354
  }
335
355
 
336
356
  export type QueryStatisticsResponseRaw<TUnit extends HKUnit = HKUnit> = {
337
- averageQuantity?: HKQuantity<TUnit>;
338
- maximumQuantity?: HKQuantity<TUnit>;
339
- minimumQuantity?: HKQuantity<TUnit>;
340
- sumQuantity?: HKQuantity<TUnit>;
341
- mostRecentQuantity?: HKQuantity<TUnit>;
342
- mostRecentQuantityDateInterval?: { from: string; to: string };
343
- duration?: HKQuantity<HKUnit.Seconds>;
357
+ readonly averageQuantity?: HKQuantity<TUnit>;
358
+ readonly maximumQuantity?: HKQuantity<TUnit>;
359
+ readonly minimumQuantity?: HKQuantity<TUnit>;
360
+ readonly sumQuantity?: HKQuantity<TUnit>;
361
+ readonly mostRecentQuantity?: HKQuantity<TUnit>;
362
+ readonly mostRecentQuantityDateInterval?: { readonly from: string; readonly to: string };
363
+ readonly duration?: HKQuantity<HKUnit.Seconds>;
344
364
  };
345
365
 
346
366
  export enum HKCategoryValueCervicalMucusQuality {
@@ -398,13 +418,13 @@ export enum HKCategoryValueNotApplicable {
398
418
 
399
419
  export type HKCategoryValue =
400
420
  | HKCategoryValueAppetiteChanges
421
+ | HKCategoryValueCervicalMucusQuality
422
+ | HKCategoryValueMenstrualFlow
423
+ | HKCategoryValueOvulationTestResult
401
424
  | HKCategoryValuePresence
402
- | HKCategoryValueSeverity
403
425
  | HKCategoryValuePresence
404
- | HKCategoryValueMenstrualFlow
426
+ | HKCategoryValueSeverity
405
427
  | HKCategoryValueSleepAnalysis
406
- | HKCategoryValueCervicalMucusQuality
407
- | HKCategoryValueOvulationTestResult
408
428
  | number;
409
429
 
410
430
  export enum HKInsulinDeliveryReason {
@@ -416,59 +436,58 @@ export type MetadataMapperForQuantityIdentifier<
416
436
  TQuantityTypeIdentifier = HKQuantityTypeIdentifier
417
437
  > = TQuantityTypeIdentifier extends HKQuantityTypeIdentifier.insulinDelivery
418
438
  ? HKGenericMetadata & {
419
- HKInsulinDeliveryReason: HKInsulinDeliveryReason;
420
- }
439
+ readonly HKInsulinDeliveryReason: HKInsulinDeliveryReason;
440
+ }
421
441
  : TQuantityTypeIdentifier extends HKQuantityTypeIdentifier.bloodGlucose
422
- ? HKGenericMetadata & {
423
- HKBloodGlucoseMealTime?: number;
424
- }
425
- : TQuantityTypeIdentifier extends HKQuantityTypeIdentifier.heartRate
426
- ? HKGenericMetadata & {
427
- HKHeartRateMotionContext?: HKHeartRateMotionContext;
442
+ ? HKGenericMetadata & {
443
+ readonly HKBloodGlucoseMealTime?: number;
428
444
  }
429
- : HKGenericMetadata;
445
+ : TQuantityTypeIdentifier extends HKQuantityTypeIdentifier.heartRate
446
+ ? HKGenericMetadata & {
447
+ readonly HKHeartRateMotionContext?: HKHeartRateMotionContext;
448
+ }
449
+ : HKGenericMetadata;
430
450
 
431
451
  export type MetadataMapperForCorrelationIdentifier<
432
452
  TCorrelationTypeIdentifier = HKCorrelationTypeIdentifier
433
453
  > = TCorrelationTypeIdentifier extends HKCorrelationTypeIdentifier.food
434
454
  ? HKGenericMetadata & {
435
- HKFoodType?: string;
436
- }
455
+ readonly HKFoodType?: string;
456
+ }
437
457
  : HKGenericMetadata;
438
458
 
439
- export type HKCategoryValueForIdentifier<
440
- T extends HKCategoryTypeIdentifier
441
- > = T extends HKCategoryTypeIdentifier.cervicalMucusQuality
442
- ? HKCategoryValueCervicalMucusQuality
443
- : T extends HKCategoryTypeIdentifier.menstrualFlow
444
- ? HKCategoryValueMenstrualFlow
445
- : T extends HKCategoryTypeIdentifier.ovulationTestResult
446
- ? HKCategoryValueOvulationTestResult
447
- : T extends HKCategoryTypeIdentifier.sleepAnalysis
448
- ? HKCategoryValueSleepAnalysis
449
- : T extends HKCategoryTypeIdentifier.mindfulSession
450
- ? HKCategoryValueNotApplicable
451
- : T extends HKCategoryTypeIdentifier.intermenstrualBleeding
452
- ? HKCategoryValueNotApplicable
453
- : T extends HKCategoryTypeIdentifier.highHeartRateEvent
454
- ? HKCategoryValueNotApplicable
455
- : T extends HKCategoryTypeIdentifier.sexualActivity
456
- ? HKCategoryValueNotApplicable
457
- : T extends HKCategoryTypeIdentifier.appleStandHour
458
- ? HKCategoryValueAppleStandHour
459
- : number;
459
+ export type HKCategoryValueForIdentifier<T extends HKCategoryTypeIdentifier> =
460
+ T extends HKCategoryTypeIdentifier.cervicalMucusQuality
461
+ ? HKCategoryValueCervicalMucusQuality
462
+ : T extends HKCategoryTypeIdentifier.menstrualFlow
463
+ ? HKCategoryValueMenstrualFlow
464
+ : T extends HKCategoryTypeIdentifier.ovulationTestResult
465
+ ? HKCategoryValueOvulationTestResult
466
+ : T extends HKCategoryTypeIdentifier.sleepAnalysis
467
+ ? HKCategoryValueSleepAnalysis
468
+ : T extends HKCategoryTypeIdentifier.mindfulSession
469
+ ? HKCategoryValueNotApplicable
470
+ : T extends HKCategoryTypeIdentifier.intermenstrualBleeding
471
+ ? HKCategoryValueNotApplicable
472
+ : T extends HKCategoryTypeIdentifier.highHeartRateEvent
473
+ ? HKCategoryValueNotApplicable
474
+ : T extends HKCategoryTypeIdentifier.sexualActivity
475
+ ? HKCategoryValueNotApplicable
476
+ : T extends HKCategoryTypeIdentifier.appleStandHour
477
+ ? HKCategoryValueAppleStandHour
478
+ : number;
460
479
 
461
480
  export type MetadataMapperForCategoryIdentifier<
462
481
  T extends HKCategoryTypeIdentifier
463
482
  > = T extends HKCategoryTypeIdentifier.sexualActivity
464
483
  ? HKGenericMetadata & {
465
- HKSexualActivityProtectionUsed: boolean;
466
- }
484
+ readonly HKSexualActivityProtectionUsed: boolean;
485
+ }
467
486
  : T extends HKCategoryTypeIdentifier.menstrualFlow
468
- ? HKGenericMetadata & {
469
- HKMenstrualCycleStart: boolean;
487
+ ? HKGenericMetadata & {
488
+ readonly HKMenstrualCycleStart: boolean;
470
489
  }
471
- : HKGenericMetadata;
490
+ : HKGenericMetadata;
472
491
 
473
492
  // Maps directly to https://developer.apple.com/documentation/healthkit/hkwheelchairuse
474
493
  export enum HKWheelchairUse {
@@ -550,53 +569,55 @@ export enum HKUnit {
550
569
  }
551
570
 
552
571
  export type HKDevice = {
553
- name: string;
554
- firmwareVersion: string;
555
- hardwareVersion: string;
556
- localIdentifier: string;
557
- manufacturer: string;
558
- model: string;
559
- softwareVersion: string;
572
+ readonly name: string;
573
+ readonly firmwareVersion: string;
574
+ readonly hardwareVersion: string;
575
+ readonly localIdentifier: string;
576
+ readonly manufacturer: string;
577
+ readonly model: string;
578
+ readonly softwareVersion: string;
560
579
  };
561
580
 
562
581
  export type HKSource = {
563
- name: string;
564
- bundleIdentifier: string;
582
+ readonly name: string;
583
+ readonly bundleIdentifier: string;
565
584
  };
566
585
 
567
586
  export type HKSourceRevision = {
568
- source: HKSource;
569
- version: string;
570
- operatingSystemVersion?: string;
571
- productType?: string;
587
+ readonly source: HKSource;
588
+ readonly version: string;
589
+ readonly operatingSystemVersion?: string;
590
+ readonly productType?: string;
572
591
  };
573
592
 
574
593
  export type HKQuantitySampleRaw<
575
594
  TQuantityIdentifier extends HKQuantityTypeIdentifier = HKQuantityTypeIdentifier,
576
595
  TUnit extends HKUnit = HKUnit
577
596
  > = {
578
- uuid: string;
579
- device?: HKDevice;
580
- quantityType: TQuantityIdentifier;
581
- startDate: string;
582
- endDate: string;
583
- quantity: number;
584
- unit: TUnit;
585
- metadata: MetadataMapperForQuantityIdentifier<TQuantityIdentifier>;
586
- sourceRevision?: HKSourceRevision;
597
+ readonly uuid: string;
598
+ readonly device?: HKDevice;
599
+ readonly quantityType: TQuantityIdentifier;
600
+ readonly startDate: string;
601
+ readonly endDate: string;
602
+ readonly quantity: number;
603
+ readonly unit: TUnit;
604
+ readonly metadata: MetadataMapperForQuantityIdentifier<TQuantityIdentifier>;
605
+ readonly sourceRevision?: HKSourceRevision;
587
606
  };
588
607
 
589
608
  export type HKWorkoutRaw<TEnergy extends HKUnit, TDistance extends HKUnit> = {
590
- workoutActivityType: HKWorkoutActivityType;
591
- duration: number;
592
- totalDistance?: HKQuantity<TDistance>;
593
- totalEnergyBurned?: HKQuantity<TEnergy>;
594
- totalSwimmingStrokeCount?: HKQuantity<HKUnit.Count>;
595
- totalFlightsClimbed?: HKQuantity<HKUnit.Count>;
596
- startDate: string;
597
- endDate: string;
598
- metadata?: HKWorkoutMetadata;
599
- sourceRevision?: HKSourceRevision;
609
+ readonly uuid: string;
610
+ readonly device?: HKDevice;
611
+ readonly workoutActivityType: HKWorkoutActivityType;
612
+ readonly duration: number;
613
+ readonly totalDistance?: HKQuantity<TDistance>;
614
+ readonly totalEnergyBurned?: HKQuantity<TEnergy>;
615
+ readonly totalSwimmingStrokeCount?: HKQuantity<HKUnit.Count>;
616
+ readonly totalFlightsClimbed?: HKQuantity<HKUnit.Count>;
617
+ readonly startDate: string;
618
+ readonly endDate: string;
619
+ readonly metadata?: HKWorkoutMetadata;
620
+ readonly sourceRevision?: HKSourceRevision;
600
621
  };
601
622
 
602
623
  // Straight mapping to https://developer.apple.com/documentation/healthkit/hkcharacteristictypeidentifier
@@ -608,42 +629,35 @@ export enum HKCharacteristicTypeIdentifier {
608
629
  wheelchairUse = 'HKCharacteristicTypeIdentifierWheelchairUse',
609
630
  }
610
631
 
611
- export type WritePermssions = {
612
- [key in
613
- | HKCharacteristicTypeIdentifier
614
- | HKQuantityTypeIdentifier
615
- | HKCategoryTypeIdentifier]: boolean;
632
+ export type WritePermissions = {
633
+ readonly [key in HKCategoryTypeIdentifier | HKCharacteristicTypeIdentifier | HKQuantityTypeIdentifier]: boolean;
616
634
  };
617
635
 
618
- export type ReadPermssions = {
619
- [key in
620
- | HKQuantityTypeIdentifier
621
- | HKCharacteristicTypeIdentifier
622
- | HKCategoryTypeIdentifier]: boolean;
636
+ export type ReadPermissions = {
637
+ readonly [key in HKCategoryTypeIdentifier | HKCharacteristicTypeIdentifier | HKQuantityTypeIdentifier]: boolean;
623
638
  };
624
639
 
625
640
  export type HKCategorySampleRaw<
626
641
  T extends HKCategoryTypeIdentifier = HKCategoryTypeIdentifier
627
642
  > = {
628
- uuid: string;
629
- device?: HKDevice;
630
- categoryType: T;
631
- startDate: string;
632
- endDate: string;
633
- value: HKCategoryValueForIdentifier<T>;
634
- metadata: MetadataMapperForCategoryIdentifier<T>;
635
- sourceRevision?: HKSourceRevision;
643
+ readonly uuid: string;
644
+ readonly device?: HKDevice;
645
+ readonly categoryType: T;
646
+ readonly startDate: string;
647
+ readonly endDate: string;
648
+ readonly value: HKCategoryValueForIdentifier<T>;
649
+ readonly metadata: MetadataMapperForCategoryIdentifier<T>;
650
+ readonly sourceRevision?: HKSourceRevision;
636
651
  };
637
652
 
638
- export type HKCorrelationRaw<
639
- TIdentifier extends HKCorrelationTypeIdentifier
640
- > = {
641
- correlationType: HKCorrelationTypeIdentifier;
642
- objects: (HKQuantitySampleRaw | HKCategorySampleRaw)[];
643
- metadata: MetadataMapperForCorrelationIdentifier<TIdentifier>;
644
- startDate: string;
645
- endDate: string;
646
- };
653
+ export type HKCorrelationRaw<TIdentifier extends HKCorrelationTypeIdentifier> =
654
+ {
655
+ readonly correlationType: HKCorrelationTypeIdentifier;
656
+ readonly objects: readonly (HKCategorySampleRaw | HKQuantitySampleRaw)[];
657
+ readonly metadata: MetadataMapperForCorrelationIdentifier<TIdentifier>;
658
+ readonly startDate: string;
659
+ readonly endDate: string;
660
+ };
647
661
 
648
662
  type QueryId = string;
649
663
 
@@ -659,90 +673,109 @@ export enum HKUpdateFrequency {
659
673
  weekly = 4,
660
674
  }
661
675
 
676
+ export type WorkoutLocation = {
677
+ readonly longitude: number;
678
+ readonly latitude: number;
679
+ readonly altitude: number;
680
+ readonly speed: number;
681
+ readonly timestamp: number;
682
+ readonly horizontalAccuracy: number;
683
+ readonly speedAccuracy: number;
684
+ readonly verticalAccuracy: number;
685
+ };
686
+
687
+ export type WorkoutRoute = {
688
+ readonly locations: readonly WorkoutLocation[];
689
+ readonly HKMetadataKeySyncIdentifier?: string;
690
+ readonly HKMetadataKeySyncVersion?: number;
691
+ };
692
+
693
+ type AuthorizationStatusFor = HKCharacteristicTypeIdentifier | HKSampleTypeIdentifier
694
+
662
695
  type ReactNativeHealthkitTypeNative = {
663
696
  isHealthDataAvailable(): Promise<boolean>;
664
697
  getBloodType(): Promise<HKBloodType>;
665
698
  getDateOfBirth(): Promise<string>;
666
699
  getBiologicalSex(): Promise<HKBiologicalSex>;
667
700
  getFitzpatrickSkinType(): Promise<HKFitzpatrickSkinType>;
668
- getWheelchairUse: () => Promise<HKWheelchairUse>;
701
+ readonly getWheelchairUse: () => Promise<HKWheelchairUse>;
669
702
 
670
- enableBackgroundDelivery: (
703
+ readonly enableBackgroundDelivery: (
671
704
  typeIdentifier: HKSampleTypeIdentifier,
672
705
  updateFrequency: HKUpdateFrequency
673
706
  ) => Promise<boolean>;
674
- disableBackgroundDelivery: (
707
+ readonly disableBackgroundDelivery: (
675
708
  typeIdentifier: HKSampleTypeIdentifier
676
709
  ) => Promise<boolean>;
677
- disableAllBackgroundDelivery: () => Promise<boolean>;
710
+ readonly disableAllBackgroundDelivery: () => Promise<boolean>;
678
711
 
679
- saveCorrelationSample: <TIdentifier extends HKCorrelationTypeIdentifier>(
712
+ readonly saveCorrelationSample: <TIdentifier extends HKCorrelationTypeIdentifier>(
680
713
  typeIdentifier: TIdentifier,
681
- samples: Omit<
682
- HKQuantitySampleRaw | HKCategorySampleRaw,
683
- 'startDate' | 'endDate' | 'uuid' | 'device'
714
+ samples: readonly Omit<
715
+ HKCategorySampleRaw | HKQuantitySampleRaw,
716
+ 'device' | 'endDate' | 'startDate' | 'uuid'
684
717
  >[],
685
718
  start: string,
686
719
  end: string,
687
720
  metadata: MetadataMapperForCorrelationIdentifier<TIdentifier>
688
721
  ) => Promise<boolean>;
689
722
 
690
- saveWorkoutSample: (
723
+ readonly saveWorkoutSample: (
691
724
  typeIdentifier: HKWorkoutActivityType,
692
- quantities: Omit<
693
- HKQuantitySampleRaw,
694
- 'startDate' | 'endDate' | 'uuid' | 'device'
725
+ quantities: readonly Omit<
726
+ HKQuantitySampleRaw,
727
+ 'device' | 'endDate' | 'startDate' | 'uuid'
695
728
  >[],
696
729
  start: string,
697
730
  end: string,
698
731
  metadata: HKWorkoutMetadata
699
732
  ) => Promise<boolean>;
700
733
 
701
- queryCorrelationSamples: <TIdentifier extends HKCorrelationTypeIdentifier>(
734
+ readonly queryCorrelationSamples: <TIdentifier extends HKCorrelationTypeIdentifier>(
702
735
  typeIdentifier: TIdentifier,
703
736
  from: string,
704
737
  to: string
705
- ) => Promise<HKCorrelationRaw<TIdentifier>[]>;
738
+ ) => Promise<readonly HKCorrelationRaw<TIdentifier>[]>;
706
739
 
707
740
  subscribeToObserverQuery(
708
741
  identifier: HKSampleTypeIdentifier
709
742
  ): Promise<QueryId>;
710
743
  unsubscribeQuery(queryId: QueryId): Promise<boolean>;
711
744
  authorizationStatusFor(
712
- type: HKSampleTypeIdentifier | HKCharacteristicTypeIdentifier
745
+ type: AuthorizationStatusFor
713
746
  ): Promise<boolean>;
714
747
  getRequestStatusForAuthorization(
715
- write: WritePermssions | {},
716
- read: ReadPermssions | {}
748
+ write: WritePermissions,
749
+ read: ReadPermissions
717
750
  ): Promise<HKAuthorizationRequestStatus>;
718
751
  requestAuthorization(
719
- write: WritePermssions | {},
720
- read: ReadPermssions | {}
752
+ write: WritePermissions,
753
+ read: ReadPermissions
721
754
  ): Promise<boolean>;
722
- saveQuantitySample: (
755
+ readonly saveQuantitySample: (
723
756
  identifier: HKQuantityTypeIdentifier,
724
757
  unit: HKUnit,
725
758
  value: number,
726
759
  start: string,
727
760
  end: string,
728
- metadata: Object
761
+ metadata: unknown
729
762
  ) => Promise<boolean>;
730
- queryWorkoutSamples: <TEnergy extends HKUnit, TDistance extends HKUnit>(
763
+ readonly queryWorkoutSamples: <TEnergy extends HKUnit, TDistance extends HKUnit>(
731
764
  energyUnit: TEnergy,
732
765
  distanceUnit: TDistance,
733
766
  from: string,
734
767
  to: string,
735
- limit: Number,
768
+ limit: number,
736
769
  ascending: boolean
737
- ) => Promise<HKWorkoutRaw<TEnergy, TDistance>[]>;
738
- queryCategorySamples: <T extends HKCategoryTypeIdentifier>(
770
+ ) => Promise<readonly HKWorkoutRaw<TEnergy, TDistance>[]>;
771
+ readonly queryCategorySamples: <T extends HKCategoryTypeIdentifier>(
739
772
  identifier: T,
740
773
  from: string,
741
774
  to: string,
742
- limit: Number,
775
+ limit: number,
743
776
  ascending: boolean
744
- ) => Promise<HKCategorySampleRaw<T>[]>;
745
- queryQuantitySamples: <
777
+ ) => Promise<readonly HKCategorySampleRaw<T>[]>;
778
+ readonly queryQuantitySamples: <
746
779
  TUnit extends HKUnit,
747
780
  TIdentifier extends HKQuantityTypeIdentifier
748
781
  >(
@@ -750,45 +783,46 @@ type ReactNativeHealthkitTypeNative = {
750
783
  unit: TUnit,
751
784
  from: string,
752
785
  to: string,
753
- limit: Number,
786
+ limit: number,
754
787
  ascending: boolean
755
- ) => Promise<HKQuantitySampleRaw<TIdentifier, TUnit>[]>;
756
- saveCategorySample: <T extends HKCategoryTypeIdentifier>(
788
+ ) => Promise<readonly HKQuantitySampleRaw<TIdentifier, TUnit>[]>;
789
+ readonly saveCategorySample: <T extends HKCategoryTypeIdentifier>(
757
790
  identifier: T,
758
791
  value: HKCategoryValueForIdentifier<T>,
759
792
  start: string,
760
793
  end: string,
761
- metadata: Object
794
+ metadata: unknown
762
795
  ) => Promise<boolean>;
763
- queryStatisticsForQuantity: <TUnit extends HKUnit>(
796
+ readonly queryStatisticsForQuantity: <TUnit extends HKUnit>(
764
797
  identifier: HKQuantityTypeIdentifier,
765
798
  unit: TUnit,
766
799
  from: string,
767
800
  to: string,
768
- options: HKStatisticsOptions[]
801
+ options: readonly HKStatisticsOptions[]
769
802
  ) => Promise<QueryStatisticsResponseRaw<TUnit>>;
770
- getPreferredUnits: (
771
- identifiers: HKQuantityTypeIdentifier[]
803
+ readonly getPreferredUnits: (
804
+ identifiers: readonly HKQuantityTypeIdentifier[]
772
805
  ) => Promise<TypeToUnitMapping>;
806
+ readonly getWorkoutRoutes: (workoutUUID: string) => Promise<readonly WorkoutRoute[]>;
773
807
  };
774
808
 
775
- const Native = NativeModules.ReactNativeHealthkit as ReactNativeHealthkitTypeNative;
809
+ const Native = NativeModules.ReactNativeHealthkit as ReactNativeHealthkitTypeNative
776
810
 
777
811
  type OnChangeCallback = ({
778
812
  typeIdentifier,
779
813
  }: {
780
- typeIdentifier: HKSampleTypeIdentifier;
814
+ readonly typeIdentifier: HKSampleTypeIdentifier;
781
815
  }) => void;
782
816
 
783
817
  interface HealthkitEventEmitter extends NativeEventEmitter {
784
- addListener: (
818
+ readonly addListener: (
785
819
  eventType: 'onChange',
786
820
  callback: OnChangeCallback
787
821
  ) => EmitterSubscription;
788
822
  }
789
823
 
790
824
  export const EventEmitter = new NativeEventEmitter(
791
- NativeModules.ReactNativeHealthkit
792
- ) as HealthkitEventEmitter;
825
+ NativeModules.ReactNativeHealthkit,
826
+ ) as HealthkitEventEmitter
793
827
 
794
- export default Native;
828
+ export default Native