@kingstinct/react-native-healthkit 13.3.1 → 14.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.
Files changed (191) hide show
  1. package/ReactNativeHealthkit.podspec +1 -0
  2. package/app.plugin.ts +40 -2
  3. package/ios/BackgroundDeliveryManager.swift +196 -0
  4. package/ios/CategoryTypeModule.swift +1 -1
  5. package/ios/CoreModule.swift +24 -0
  6. package/ios/CorrelationTypeModule.swift +2 -35
  7. package/ios/ElectrocardiogramModule.swift +2 -34
  8. package/ios/HeartbeatSeriesModule.swift +2 -34
  9. package/ios/MedicationModule.swift +3 -35
  10. package/ios/PredicateHelpers.swift +2 -2
  11. package/ios/QuantityTypeModule.swift +11 -11
  12. package/ios/Serializers.swift +58 -90
  13. package/ios/StateOfMindModule.swift +2 -34
  14. package/ios/WorkoutProxy.swift +4 -149
  15. package/ios/generated/HealthkitGenerated.swift +52 -0
  16. package/lib/commonjs/generated/healthkit.generated.js +745 -0
  17. package/lib/commonjs/healthkit.ios.js +51 -17
  18. package/lib/commonjs/healthkit.js +120 -34
  19. package/lib/commonjs/specs/QuantityTypeModule.nitro.js +1 -0
  20. package/lib/commonjs/type-tests/generated-typing.js +2 -0
  21. package/lib/commonjs/types/CategoryType.js +19 -99
  22. package/lib/commonjs/types/Medication.js +2 -0
  23. package/lib/commonjs/types/MetadataEnums.js +17 -0
  24. package/lib/commonjs/types/QuantityType.js +4 -15
  25. package/lib/commonjs/types/WeatherCondition.js +2 -32
  26. package/lib/commonjs/types/Workouts.js +3 -98
  27. package/lib/commonjs/types/index.js +2 -0
  28. package/lib/module/generated/healthkit.generated.js +742 -0
  29. package/lib/module/healthkit.ios.js +49 -15
  30. package/lib/module/healthkit.js +94 -20
  31. package/lib/module/specs/QuantityTypeModule.nitro.js +1 -0
  32. package/lib/module/type-tests/generated-typing.js +1 -0
  33. package/lib/module/types/CategoryType.js +2 -98
  34. package/lib/module/types/Medication.js +1 -0
  35. package/lib/module/types/MetadataEnums.js +1 -0
  36. package/lib/module/types/QuantityType.js +2 -14
  37. package/lib/module/types/WeatherCondition.js +1 -32
  38. package/lib/module/types/Workouts.js +2 -98
  39. package/lib/module/types/index.js +2 -0
  40. package/lib/typescript/generated/healthkit.generated.d.ts +1006 -0
  41. package/lib/typescript/healthkit.d.ts +39 -36
  42. package/lib/typescript/healthkit.ios.d.ts +64 -53
  43. package/lib/typescript/hooks/useMostRecentQuantitySample.d.ts +3 -2
  44. package/lib/typescript/hooks/useMostRecentWorkout.d.ts +2 -2
  45. package/lib/typescript/hooks/useQuantitySampleById.d.ts +5 -4
  46. package/lib/typescript/hooks/useStatisticsForQuantity.d.ts +2 -2
  47. package/lib/typescript/hooks/useSubscribeToQuantitySamples.d.ts +1 -1
  48. package/lib/typescript/modules.d.ts +2 -2
  49. package/lib/typescript/specs/CategoryTypeModule.nitro.d.ts +3 -3
  50. package/lib/typescript/specs/CoreModule.nitro.d.ts +15 -0
  51. package/lib/typescript/specs/QuantityTypeModule.nitro.d.ts +20 -9
  52. package/lib/typescript/type-tests/generated-typing.d.ts +1 -0
  53. package/lib/typescript/types/CategoryType.d.ts +10 -104
  54. package/lib/typescript/types/CategoryTypeIdentifier.d.ts +1 -61
  55. package/lib/typescript/types/CorrelationType.d.ts +8 -2
  56. package/lib/typescript/types/ElectrocardiogramSample.d.ts +8 -1
  57. package/lib/typescript/types/HeartbeatSeries.d.ts +8 -1
  58. package/lib/typescript/types/InterfaceVerification.d.ts +14 -1
  59. package/lib/typescript/types/Medication.d.ts +10 -0
  60. package/lib/typescript/types/MetadataEnums.d.ts +1 -0
  61. package/lib/typescript/types/QuantitySample.d.ts +9 -1
  62. package/lib/typescript/types/QuantityType.d.ts +14 -18
  63. package/lib/typescript/types/QuantityTypeIdentifier.d.ts +1 -671
  64. package/lib/typescript/types/QueryOptions.d.ts +8 -4
  65. package/lib/typescript/types/Shared.d.ts +12 -41
  66. package/lib/typescript/types/StateOfMind.d.ts +8 -1
  67. package/lib/typescript/types/Subscriptions.d.ts +11 -11
  68. package/lib/typescript/types/WeatherCondition.d.ts +1 -30
  69. package/lib/typescript/types/Workouts.d.ts +20 -104
  70. package/lib/typescript/types/index.d.ts +2 -0
  71. package/lib/typescript/utils/getMostRecentQuantitySample.d.ts +2 -1
  72. package/lib/typescript/utils/getMostRecentWorkout.d.ts +2 -1
  73. package/lib/typescript/utils/getPreferredUnit.d.ts +2 -1
  74. package/lib/typescript/utils/getQuantitySampleById.d.ts +2 -1
  75. package/lib/typescript/utils/subscribeToQuantitySamples.d.ts +1 -1
  76. package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Bridge.hpp +55 -109
  77. package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Umbrella.hpp +12 -18
  78. package/nitrogen/generated/ios/c++/HybridCategoryTypeModuleSpecSwift.hpp +5 -14
  79. package/nitrogen/generated/ios/c++/HybridCoreModuleSpecSwift.hpp +18 -2
  80. package/nitrogen/generated/ios/c++/HybridCorrelationTypeModuleSpecSwift.hpp +1 -13
  81. package/nitrogen/generated/ios/c++/HybridElectrocardiogramModuleSpecSwift.hpp +1 -13
  82. package/nitrogen/generated/ios/c++/HybridHeartbeatSeriesModuleSpecSwift.hpp +2 -14
  83. package/nitrogen/generated/ios/c++/HybridMedicationModuleSpecSwift.hpp +1 -13
  84. package/nitrogen/generated/ios/c++/HybridQuantityTypeModuleSpecSwift.hpp +19 -28
  85. package/nitrogen/generated/ios/c++/HybridStateOfMindModuleSpecSwift.hpp +2 -14
  86. package/nitrogen/generated/ios/c++/HybridWorkoutProxySpecSwift.hpp +3 -116
  87. package/nitrogen/generated/ios/swift/CategorySample.swift +4 -329
  88. package/nitrogen/generated/ios/swift/CategoryTypeIdentifier.swift +112 -108
  89. package/nitrogen/generated/ios/swift/CategoryTypeIdentifierWriteable.swift +292 -0
  90. package/nitrogen/generated/ios/swift/CorrelationSample.swift +4 -347
  91. package/nitrogen/generated/ios/swift/ElectrocardiogramSample.swift +4 -329
  92. package/nitrogen/generated/ios/swift/FilterForWorkouts.swift +30 -30
  93. package/nitrogen/generated/ios/swift/FilterForWorkoutsBase.swift +30 -30
  94. package/nitrogen/generated/ios/swift/GeneralForm.swift +4 -4
  95. package/nitrogen/generated/ios/swift/HeartbeatSeriesSample.swift +4 -329
  96. package/nitrogen/generated/ios/swift/HybridCategoryTypeModuleSpec.swift +1 -1
  97. package/nitrogen/generated/ios/swift/HybridCategoryTypeModuleSpec_cxx.swift +1 -1
  98. package/nitrogen/generated/ios/swift/HybridCoreModuleSpec.swift +2 -0
  99. package/nitrogen/generated/ios/swift/HybridCoreModuleSpec_cxx.swift +38 -0
  100. package/nitrogen/generated/ios/swift/HybridQuantityTypeModuleSpec.swift +6 -6
  101. package/nitrogen/generated/ios/swift/HybridQuantityTypeModuleSpec_cxx.swift +6 -6
  102. package/nitrogen/generated/ios/swift/HybridWorkoutProxySpec.swift +1 -27
  103. package/nitrogen/generated/ios/swift/HybridWorkoutProxySpec_cxx.swift +2 -340
  104. package/nitrogen/generated/ios/swift/MedicationDoseEvent.swift +4 -329
  105. package/nitrogen/generated/ios/swift/ObjectTypeIdentifier.swift +492 -492
  106. package/nitrogen/generated/ios/swift/QuantitySample.swift +4 -329
  107. package/nitrogen/generated/ios/swift/QuantityTypeIdentifier.swift +380 -384
  108. package/nitrogen/generated/ios/swift/QuantityTypeIdentifierWriteable.swift +372 -376
  109. package/nitrogen/generated/ios/swift/{QueryOptionsWithAnchorAndUnit.swift → QueryOptionsWithAnchorAndStringUnit.swift} +5 -5
  110. package/nitrogen/generated/ios/swift/{QueryOptionsWithSortOrderAndUnit.swift → QueryOptionsWithSortOrderAndStringUnit.swift} +5 -5
  111. package/nitrogen/generated/ios/swift/QueryStatisticsResponseFromSingleSource.swift +37 -37
  112. package/nitrogen/generated/ios/swift/SampleTypeIdentifier.swift +492 -492
  113. package/nitrogen/generated/ios/swift/SampleTypeIdentifierWriteable.swift +482 -486
  114. package/nitrogen/generated/ios/swift/StateOfMindSample.swift +4 -329
  115. package/nitrogen/generated/ios/swift/{StatisticsQueryOptions.swift → StatisticsQueryOptionsWithStringUnit.swift} +5 -5
  116. package/nitrogen/generated/ios/swift/WorkoutEvent.swift +20 -2
  117. package/nitrogen/generated/ios/swift/WorkoutSample.swift +4 -402
  118. package/nitrogen/generated/shared/c++/CategorySample.hpp +8 -100
  119. package/nitrogen/generated/shared/c++/CategoryTypeIdentifier.hpp +153 -149
  120. package/nitrogen/generated/shared/c++/CategoryTypeIdentifierWriteable.hpp +328 -0
  121. package/nitrogen/generated/shared/c++/CorrelationSample.hpp +9 -105
  122. package/nitrogen/generated/shared/c++/ElectrocardiogramSample.hpp +7 -99
  123. package/nitrogen/generated/shared/c++/FilterForWorkouts.hpp +13 -13
  124. package/nitrogen/generated/shared/c++/FilterForWorkoutsBase.hpp +13 -13
  125. package/nitrogen/generated/shared/c++/GeneralForm.hpp +7 -7
  126. package/nitrogen/generated/shared/c++/HeartbeatSeriesSample.hpp +8 -100
  127. package/nitrogen/generated/shared/c++/HybridCategoryTypeModuleSpec.hpp +5 -2
  128. package/nitrogen/generated/shared/c++/HybridCoreModuleSpec.cpp +2 -0
  129. package/nitrogen/generated/shared/c++/HybridCoreModuleSpec.hpp +4 -2
  130. package/nitrogen/generated/shared/c++/HybridQuantityTypeModuleSpec.hpp +15 -15
  131. package/nitrogen/generated/shared/c++/HybridWorkoutProxySpec.cpp +1 -27
  132. package/nitrogen/generated/shared/c++/HybridWorkoutProxySpec.hpp +2 -37
  133. package/nitrogen/generated/shared/c++/MedicationDoseEvent.hpp +7 -99
  134. package/nitrogen/generated/shared/c++/ObjectTypeIdentifier.hpp +565 -565
  135. package/nitrogen/generated/shared/c++/QuantitySample.hpp +8 -100
  136. package/nitrogen/generated/shared/c++/QuantityTypeIdentifier.hpp +407 -411
  137. package/nitrogen/generated/shared/c++/QuantityTypeIdentifierWriteable.hpp +398 -402
  138. package/nitrogen/generated/shared/c++/{QueryOptionsWithAnchorAndUnit.hpp → QueryOptionsWithAnchorAndStringUnit.hpp} +11 -11
  139. package/nitrogen/generated/shared/c++/{QueryOptionsWithSortOrderAndUnit.hpp → QueryOptionsWithSortOrderAndStringUnit.hpp} +11 -11
  140. package/nitrogen/generated/shared/c++/QueryStatisticsResponseFromSingleSource.hpp +12 -12
  141. package/nitrogen/generated/shared/c++/SampleTypeIdentifier.hpp +559 -559
  142. package/nitrogen/generated/shared/c++/SampleTypeIdentifierWriteable.hpp +541 -545
  143. package/nitrogen/generated/shared/c++/StateOfMindSample.hpp +8 -100
  144. package/nitrogen/generated/shared/c++/{StatisticsQueryOptions.hpp → StatisticsQueryOptionsWithStringUnit.hpp} +11 -11
  145. package/nitrogen/generated/shared/c++/WorkoutEvent.hpp +8 -2
  146. package/nitrogen/generated/shared/c++/WorkoutSample.hpp +7 -120
  147. package/package.json +5 -2
  148. package/src/generated/healthkit-schema.json +3680 -0
  149. package/src/generated/healthkit.generated.ts +1307 -0
  150. package/src/healthkit.ios.ts +225 -19
  151. package/src/healthkit.ts +181 -55
  152. package/src/hooks/useMostRecentQuantitySample.ts +6 -5
  153. package/src/hooks/useMostRecentWorkout.ts +2 -2
  154. package/src/hooks/useQuantitySampleById.ts +6 -5
  155. package/src/hooks/useStatisticsForQuantity.ts +2 -1
  156. package/src/hooks/useSubscribeToQuantitySamples.ts +1 -1
  157. package/src/modules.ts +7 -2
  158. package/src/specs/CategoryTypeModule.nitro.ts +8 -5
  159. package/src/specs/CoreModule.nitro.ts +20 -0
  160. package/src/specs/QuantityTypeModule.nitro.ts +81 -7
  161. package/src/test-setup.ts +2 -0
  162. package/src/type-tests/generated-typing.ts +133 -0
  163. package/src/types/CategoryType.ts +52 -148
  164. package/src/types/CategoryTypeIdentifier.ts +5 -134
  165. package/src/types/CorrelationType.ts +13 -3
  166. package/src/types/ElectrocardiogramSample.ts +13 -1
  167. package/src/types/HeartbeatSeries.ts +13 -1
  168. package/src/types/InterfaceVerification.ts +38 -1
  169. package/src/types/Medication.ts +19 -0
  170. package/src/types/MetadataEnums.ts +15 -0
  171. package/src/types/QuantitySample.ts +14 -2
  172. package/src/types/QuantityType.ts +22 -122
  173. package/src/types/QuantityTypeIdentifier.ts +5 -772
  174. package/src/types/QueryOptions.ts +11 -4
  175. package/src/types/Shared.ts +22 -49
  176. package/src/types/StateOfMind.ts +13 -1
  177. package/src/types/Subscriptions.ts +19 -13
  178. package/src/types/WeatherCondition.ts +1 -31
  179. package/src/types/Workouts.ts +46 -108
  180. package/src/types/index.ts +2 -0
  181. package/src/utils/getMostRecentQuantitySample.ts +4 -3
  182. package/src/utils/getMostRecentWorkout.ts +5 -2
  183. package/src/utils/getPreferredUnit.ts +5 -4
  184. package/src/utils/getQuantitySampleById.ts +4 -3
  185. package/src/utils/subscribeToQuantitySamples.ts +5 -3
  186. package/nitrogen/generated/ios/swift/HeartRateMotionContext.swift +0 -44
  187. package/nitrogen/generated/ios/swift/InsulinDeliveryReason.swift +0 -40
  188. package/nitrogen/generated/ios/swift/WeatherCondition.swift +0 -144
  189. package/nitrogen/generated/shared/c++/HeartRateMotionContext.hpp +0 -67
  190. package/nitrogen/generated/shared/c++/InsulinDeliveryReason.hpp +0 -62
  191. package/nitrogen/generated/shared/c++/WeatherCondition.hpp +0 -88
@@ -102,11 +102,18 @@ export interface QueryOptionsWithSortOrder extends GenericQueryOptions {
102
102
  readonly ascending?: boolean
103
103
  }
104
104
 
105
- export interface QueryOptionsWithSortOrderAndUnit
105
+ export interface QueryOptionsWithSortOrderAndUnit<TUnit extends string = string>
106
106
  extends QueryOptionsWithSortOrder {
107
- readonly unit?: string
107
+ readonly unit?: TUnit
108
108
  }
109
109
 
110
- export interface QueryOptionsWithAnchorAndUnit extends QueryOptionsWithAnchor {
111
- readonly unit?: string
110
+ export interface QueryOptionsWithAnchorAndUnit<TUnit extends string = string>
111
+ extends QueryOptionsWithAnchor {
112
+ readonly unit?: TUnit
112
113
  }
114
+
115
+ export interface QueryOptionsWithSortOrderAndStringUnit
116
+ extends QueryOptionsWithSortOrderAndUnit<string> {}
117
+
118
+ export interface QueryOptionsWithAnchorAndStringUnit
119
+ extends QueryOptionsWithAnchorAndUnit<string> {}
@@ -1,4 +1,8 @@
1
1
  import type { AnyMap } from 'react-native-nitro-modules'
2
+ import type {
3
+ KnownObjectMetadata,
4
+ KnownSampleMetadata,
5
+ } from '../generated/healthkit.generated'
2
6
  import type {
3
7
  CategoryTypeIdentifier,
4
8
  CategoryTypeIdentifierWriteable,
@@ -17,17 +21,11 @@ import type {
17
21
  } from './Constants'
18
22
  import type { CorrelationTypeIdentifier } from './CorrelationType'
19
23
  import type { Device } from './Device'
20
- import type {
21
- HeartRateMotionContext,
22
- InsulinDeliveryReason,
23
- Quantity,
24
- } from './QuantityType'
25
24
  import type {
26
25
  QuantityTypeIdentifier,
27
26
  QuantityTypeIdentifierWriteable,
28
27
  } from './QuantityTypeIdentifier'
29
28
  import type { SourceRevision } from './Source'
30
- import type { WeatherCondition } from './WeatherCondition'
31
29
 
32
30
  export interface DeletedSample {
33
31
  readonly uuid: string
@@ -64,45 +62,30 @@ export type SampleTypeIdentifierWriteable =
64
62
  | typeof WorkoutRouteTypeIdentifier
65
63
  | typeof WorkoutTypeIdentifier
66
64
 
67
- export interface GenericMetadata {
68
- readonly HKExternalUUID?: string
69
- readonly HKTimeZone?: string
70
- readonly HKWasUserEntered?: boolean
71
- readonly HKDeviceSerialNumber?: string
72
- readonly HKUDIDeviceIdentifier?: string
73
- readonly HKUDIProductionIdentifier?: string
74
- readonly HKDigitalSignature?: string
75
- readonly HKDeviceName?: string
76
- readonly HKDeviceManufacturerName?: string
77
- readonly HKSyncIdentifier?: string
78
- readonly HKSyncVersion?: number
79
- readonly HKWasTakenInLab?: boolean
80
- readonly HKReferenceRangeLowerLimit?: number
81
- readonly HKReferenceRangeUpperLimit?: number
65
+ export type MetadataWithUnknown<T extends object> = AnyMap & T
66
+ export type GenericMetadata = AnyMap & KnownObjectMetadata
67
+ export type WithTypedMetadata<T, TMetadata extends object> = Omit<
68
+ T,
69
+ 'metadata'
70
+ > & {
71
+ readonly metadata: AnyMap & TMetadata
72
+ }
73
+ export type WithOptionalTypedMetadata<T, TMetadata extends object> = Omit<
74
+ T,
75
+ 'metadata'
76
+ > & {
77
+ readonly metadata?: AnyMap & TMetadata
82
78
  }
79
+ export type BaseObjectTyped<TMetadata extends object = KnownObjectMetadata> =
80
+ WithTypedMetadata<BaseObject, TMetadata>
81
+ export type BaseSampleTyped<TMetadata extends object = KnownSampleMetadata> =
82
+ WithTypedMetadata<BaseSample, TMetadata>
83
83
 
84
84
  export interface BaseObject {
85
85
  readonly uuid: string
86
86
  readonly sourceRevision: SourceRevision
87
87
  readonly device?: Device
88
88
  readonly metadata: AnyMap
89
-
90
- // metadata
91
- readonly metadataExternalUUID?: string
92
- readonly metadataTimeZone?: string
93
- readonly metadataWasUserEntered?: boolean
94
- readonly metadataDeviceSerialNumber?: string
95
- readonly metadataUdiDeviceIdentifier?: string
96
- readonly metadataUdiProductionIdentifier?: string
97
- readonly metadataDigitalSignature?: string
98
- readonly metadataDeviceName?: string
99
- readonly metadataDeviceManufacturerName?: string
100
- readonly metadataSyncIdentifier?: string
101
- readonly metadataSyncVersion?: number
102
- readonly metadataWasTakenInLab?: boolean
103
- readonly metadataReferenceRangeLowerLimit?: number
104
- readonly metadataReferenceRangeUpperLimit?: number
105
- readonly metadataAlgorithmVersion?: number
106
89
  }
107
90
 
108
91
  export interface SampleType {
@@ -117,15 +100,5 @@ export interface BaseSample extends BaseObject {
117
100
  readonly startDate: Date
118
101
  readonly endDate: Date
119
102
  readonly hasUndeterminedDuration: boolean
120
-
121
- // metadata
122
- readonly metadataWeatherCondition?: WeatherCondition
123
- readonly metadataWeatherHumidity?: Quantity
124
- readonly metadataWeatherTemperature?: Quantity
125
- readonly metadataInsulinDeliveryReason?: InsulinDeliveryReason
126
- /**
127
- * postprandial or preprandial (https://developer.apple.com/documentation/healthkit/hkbloodglucosemealtime)
128
- */
129
- // readonly metadataBloodGlucoseMealTime?: number
130
- readonly metadataHeartRateMotionContext?: HeartRateMotionContext
103
+ readonly metadata: AnyMap
131
104
  }
@@ -1,4 +1,5 @@
1
- import type { BaseSample, DeletedSample } from './Shared'
1
+ import type { KnownSampleMetadata } from '../generated/healthkit.generated'
2
+ import type { BaseSample, DeletedSample, WithTypedMetadata } from './Shared'
2
3
 
3
4
  export enum StateOfMindValenceClassification {
4
5
  veryUnpleasant = 1,
@@ -23,12 +24,23 @@ export interface StateOfMindSample extends BaseSample {
23
24
  readonly labels: readonly StateOfMindLabel[]
24
25
  }
25
26
 
27
+ export type StateOfMindSampleTyped = WithTypedMetadata<
28
+ StateOfMindSample,
29
+ KnownSampleMetadata
30
+ >
31
+
26
32
  export interface StateOfMindSamplesWithAnchorResponse {
27
33
  readonly samples: readonly StateOfMindSample[]
28
34
  readonly deletedSamples: readonly DeletedSample[]
29
35
  readonly newAnchor: string
30
36
  }
31
37
 
38
+ export interface StateOfMindSamplesWithAnchorResponseTyped {
39
+ readonly samples: readonly StateOfMindSampleTyped[]
40
+ readonly deletedSamples: readonly DeletedSample[]
41
+ readonly newAnchor: string
42
+ }
43
+
32
44
  /**
33
45
  * @see {@link https://developer.apple.com/documentation/healthkit/hkstateofmind/label Apple Docs}
34
46
  */
@@ -1,6 +1,6 @@
1
1
  import type { CategorySampleTyped } from './CategoryType'
2
2
  import type { CategoryTypeIdentifier } from './CategoryTypeIdentifier'
3
- import type { QuantitySample } from './QuantitySample'
3
+ import type { QuantitySampleTyped } from './QuantitySample'
4
4
  import type { QuantityTypeIdentifier } from './QuantityTypeIdentifier'
5
5
  import type { SampleTypeIdentifier } from './Shared'
6
6
 
@@ -13,32 +13,38 @@ export interface OnChangeCallbackArgs {
13
13
  readonly errorMessage?: string
14
14
  }
15
15
 
16
- export interface OnQuantitySamplesCallbackError {
17
- readonly typeIdentifier: QuantityTypeIdentifier
16
+ export interface OnQuantitySamplesCallbackError<
17
+ T extends QuantityTypeIdentifier = QuantityTypeIdentifier,
18
+ > {
19
+ readonly typeIdentifier: T
18
20
  readonly errorMessage: string
19
21
  }
20
22
 
21
- export interface OnQuantitySamplesCallbackSuccess {
22
- readonly typeIdentifier: QuantityTypeIdentifier
23
- readonly samples: readonly QuantitySample[]
23
+ export interface OnQuantitySamplesCallbackSuccess<
24
+ T extends QuantityTypeIdentifier = QuantityTypeIdentifier,
25
+ > {
26
+ readonly typeIdentifier: T
27
+ readonly samples: readonly QuantitySampleTyped<T>[]
24
28
  }
25
29
 
26
- export type OnQuantitySamplesCallback =
27
- | OnQuantitySamplesCallbackError
28
- | OnQuantitySamplesCallbackSuccess
30
+ export type OnQuantitySamplesCallback<
31
+ T extends QuantityTypeIdentifier = QuantityTypeIdentifier,
32
+ > = OnQuantitySamplesCallbackError<T> | OnQuantitySamplesCallbackSuccess<T>
29
33
 
30
- export interface OnCategorySamplesCallbackError {
31
- readonly typeIdentifier: CategoryTypeIdentifier
34
+ export interface OnCategorySamplesCallbackError<
35
+ T extends CategoryTypeIdentifier = CategoryTypeIdentifier,
36
+ > {
37
+ readonly typeIdentifier: T
32
38
  readonly errorMessage: string
33
39
  }
34
40
 
35
41
  export interface OnCategorySamplesCallbackSuccess<
36
42
  T extends CategoryTypeIdentifier,
37
43
  > {
38
- readonly typeIdentifier: CategoryTypeIdentifier
44
+ readonly typeIdentifier: T
39
45
  readonly samples: readonly CategorySampleTyped<T>[]
40
46
  }
41
47
 
42
48
  export type OnCategorySamplesCallback<T extends CategoryTypeIdentifier> =
43
- | OnCategorySamplesCallbackError
49
+ | OnCategorySamplesCallbackError<T>
44
50
  | OnCategorySamplesCallbackSuccess<T>
@@ -1,31 +1 @@
1
- // documented at https://developer.apple.com/documentation/healthkit/hkweathercondition
2
- export enum WeatherCondition {
3
- none = 0,
4
- clear = 1,
5
- fair = 2,
6
- partlyCloudy = 3,
7
- mostlyCloudy = 4,
8
- cloudy = 5,
9
- foggy = 6,
10
- haze = 7,
11
- windy = 8,
12
- blustery = 9,
13
- smoky = 10,
14
- dust = 11,
15
- snow = 12,
16
- hail = 13,
17
- sleet = 14,
18
- freezingDrizzle = 15,
19
- freezingRain = 16,
20
- mixedRainAndHail = 17,
21
- mixedRainAndSnow = 18,
22
- mixedRainAndSleet = 19,
23
- mixedSnowAndSleet = 20,
24
- drizzle = 21,
25
- scatteredShowers = 22,
26
- showers = 23,
27
- thunderstorms = 24,
28
- tropicalStorm = 25,
29
- hurricane = 26,
30
- tornado = 27,
31
- }
1
+ export { WeatherCondition } from '../generated/healthkit.generated'
@@ -1,112 +1,35 @@
1
+ import type { AnyMap } from 'react-native-nitro-modules'
2
+ import type {
3
+ WorkoutEventTypedMetadata,
4
+ WorkoutTypedMetadata,
5
+ } from '../generated/healthkit.generated'
6
+ import {
7
+ WorkoutActivityType,
8
+ WorkoutEventType,
9
+ } from '../generated/healthkit.generated'
1
10
  import type { WorkoutProxy } from '../specs/WorkoutProxy.nitro'
2
11
  import type { BaseSample, ComparisonPredicateOperator } from '../types'
3
12
  import type { Quantity } from './QuantityType'
4
13
  import type { FilterForSamplesBase } from './QueryOptions'
5
- import type { DeletedSample } from './Shared'
6
-
7
- export enum WorkoutActivityType {
8
- americanFootball = 1,
9
- archery = 2,
10
- australianFootball = 3,
11
- badminton = 4,
12
- baseball = 5,
13
- basketball = 6,
14
- bowling = 7,
15
- boxing = 8, // See also HKWorkoutActivityTypeKickboxing.,
16
- climbing = 9,
17
- cricket = 10,
18
- crossTraining = 11, // Any mix of cardio and/or strength training. See also HKWorkoutActivityTypeCoreTraining and HKWorkoutActivityTypeFlexibility.,
19
- curling = 12,
20
- cycling = 13,
21
- dance = 14,
22
- danceInspiredTraining = 15, // This enum remains available to access older data.,
23
- elliptical = 16,
24
- equestrianSports = 17, // Polo, Horse Racing, Horse Riding, etc.,
25
- fencing = 18,
26
- fishing = 19,
27
- functionalStrengthTraining = 20, // Primarily free weights and/or body weight and/or accessories,
28
- golf = 21,
29
- gymnastics = 22,
30
- handball = 23,
31
- hiking = 24,
32
- hockey = 25, // Ice Hockey, Field Hockey, etc.,
33
- hunting = 26,
34
- lacrosse = 27,
35
- martialArts = 28,
36
- mindAndBody = 29, // Qigong, meditation, etc.,
37
- mixedMetabolicCardioTraining = 30, // This enum remains available to access older data.,
38
- paddleSports = 31, // Canoeing, Kayaking, Outrigger, Stand Up Paddle Board, etc.,
39
- play = 32, // Dodge Ball, Hopscotch, Tetherball, Jungle Gym, etc.,
40
- preparationAndRecovery = 33, // Foam rolling, stretching, etc.,
41
- racquetball = 34,
42
- rowing = 35,
43
- rugby = 36,
44
- running = 37,
45
- sailing = 38,
46
- skatingSports = 39, // Ice Skating, Speed Skating, Inline Skating, Skateboarding, etc.,
47
- snowSports = 40, // Sledding, Snowmobiling, Building a Snowman, etc. See also HKWorkoutActivityTypeCrossCountrySkiing, HKWorkoutActivityTypeSnowboarding, and HKWorkoutActivityTypeDownhillSkiing.,
48
- soccer = 41,
49
- softball = 42,
50
- squash = 43,
51
- stairClimbing = 44, // See also HKWorkoutActivityTypeStairs and HKWorkoutActivityTypeStepTraining.,
52
- surfingSports = 45, // Traditional Surfing, Kite Surfing, Wind Surfing, etc.,
53
- swimming = 46,
54
- tableTennis = 47,
55
- tennis = 48,
56
- trackAndField = 49, // Shot Put, Javelin, Pole Vaulting, etc.,
57
- traditionalStrengthTraining = 50, // Primarily machines and/or free weights,
58
- volleyball = 51,
59
- walking = 52,
60
- waterFitness = 53,
61
- waterPolo = 54,
62
- waterSports = 55, // Water Skiing, Wake Boarding, etc.,
63
- wrestling = 56,
64
- yoga = 57,
65
- barre = 58, // HKWorkoutActivityTypeDanceInspiredTraining,
66
- coreTraining = 59,
67
- crossCountrySkiing = 60,
68
- downhillSkiing = 61,
69
- flexibility = 62,
70
- highIntensityIntervalTraining = 63,
71
- jumpRope = 64,
72
- kickboxing = 65,
73
- pilates = 66, // HKWorkoutActivityTypeDanceInspiredTraining,
74
- snowboarding = 67,
75
- stairs = 68,
76
- stepTraining = 69,
77
- wheelchairWalkPace = 70,
78
- wheelchairRunPace = 71,
79
- taiChi = 72,
80
- mixedCardio = 73, // HKWorkoutActivityTypeMixedMetabolicCardioTraining,
81
- handCycling = 74,
82
- discSports = 75,
83
- fitnessGaming = 76,
84
- cardioDance = 77,
85
- socialDance = 78,
86
- pickleball = 79,
87
- cooldown = 80,
88
- swimBikeRun = 82,
89
- transition = 83,
90
- underwaterDiving = 84,
91
- other = 3000,
92
- }
14
+ import type {
15
+ DeletedSample,
16
+ WithOptionalTypedMetadata,
17
+ WithTypedMetadata,
18
+ } from './Shared'
19
+
20
+ export { WorkoutActivityType, WorkoutEventType }
93
21
 
94
22
  export interface WorkoutEvent {
95
23
  readonly type: WorkoutEventType
96
24
  readonly startDate: Date
97
25
  readonly endDate: Date
26
+ readonly metadata?: AnyMap
98
27
  }
99
28
 
100
- export enum WorkoutEventType {
101
- pause = 1,
102
- resume = 2,
103
- lap = 3,
104
- marker = 4,
105
- motionPaused = 5,
106
- motionResumed = 6,
107
- segment = 7,
108
- pauseOrResumeRequest = 8,
109
- }
29
+ export type WorkoutEventTyped = WithOptionalTypedMetadata<
30
+ WorkoutEvent,
31
+ WorkoutEventTypedMetadata
32
+ >
110
33
 
111
34
  export interface WorkoutActivity {
112
35
  readonly startDate: Date
@@ -127,6 +50,12 @@ export interface QueryWorkoutSamplesWithAnchorResponse {
127
50
  readonly newAnchor: string
128
51
  }
129
52
 
53
+ export interface QueryWorkoutSamplesWithAnchorResponseTyped {
54
+ readonly workouts: readonly WorkoutProxyTyped[]
55
+ readonly deletedSamples: readonly DeletedSample[]
56
+ readonly newAnchor: string
57
+ }
58
+
130
59
  export type WorkoutDurationPredicate = {
131
60
  readonly predicateOperator: ComparisonPredicateOperator
132
61
  readonly durationInSeconds: number
@@ -178,7 +107,7 @@ export interface WorkoutRouteLocation {
178
107
  export interface LocationForSaving {
179
108
  readonly altitude: number
180
109
  readonly course: number
181
- readonly date: Date // unix timestamp in milliseconds
110
+ readonly date: Date
182
111
  readonly horizontalAccuracy: number
183
112
  readonly latitude: number
184
113
  readonly longitude: number
@@ -196,7 +125,7 @@ export interface WorkoutTotals {
196
125
  readonly energyBurned?: number
197
126
  }
198
127
 
199
- export interface WorkoutSample extends BaseSample {
128
+ export interface WorkoutSample extends Omit<BaseSample, 'metadata'> {
200
129
  readonly workoutActivityType: WorkoutActivityType
201
130
  readonly duration: Quantity
202
131
  readonly totalEnergyBurned?: Quantity
@@ -205,11 +134,20 @@ export interface WorkoutSample extends BaseSample {
205
134
  readonly totalFlightsClimbed?: Quantity
206
135
  readonly events?: readonly WorkoutEvent[]
207
136
  readonly activities?: readonly WorkoutActivity[]
208
-
209
- readonly metadataAverageMETs?: Quantity
210
- readonly metadataElevationAscended?: Quantity
211
- readonly metadataElevationDescended?: Quantity
212
- readonly metadataIndoorWorkout?: boolean
213
- readonly metadataAverageSpeed?: Quantity
214
- readonly metadataMaximumSpeed?: Quantity
215
- }
137
+ readonly metadata: AnyMap
138
+ }
139
+
140
+ export type WorkoutSampleTyped = WithTypedMetadata<
141
+ Omit<WorkoutSample, 'events'> & {
142
+ readonly events?: readonly WorkoutEventTyped[]
143
+ },
144
+ WorkoutTypedMetadata
145
+ >
146
+
147
+ export type WorkoutProxyTyped = Omit<
148
+ WorkoutProxy,
149
+ keyof WorkoutSample | 'toJSON'
150
+ > &
151
+ WorkoutSampleTyped & {
152
+ toJSON(key?: string): WorkoutSampleTyped
153
+ }
@@ -7,6 +7,8 @@ export * from './Constants'
7
7
  export * from './CorrelationType'
8
8
  export * from './Device'
9
9
  export * from './HeartbeatSeries'
10
+ export * from './Medication'
11
+ export * from './MetadataEnums'
10
12
  export * from './QuantitySample'
11
13
  export * from './QuantityType'
12
14
  export * from './QuantityTypeIdentifier'
@@ -1,9 +1,10 @@
1
1
  import { QuantityTypes } from '../modules'
2
+ import type { UnitForIdentifier } from '../types/QuantityType'
2
3
  import type { QuantityTypeIdentifier } from '../types/QuantityTypeIdentifier'
3
4
 
4
- async function getMostRecentQuantitySample(
5
- identifier: QuantityTypeIdentifier,
6
- unit?: string,
5
+ async function getMostRecentQuantitySample<T extends QuantityTypeIdentifier>(
6
+ identifier: T,
7
+ unit?: UnitForIdentifier<T>,
7
8
  ) {
8
9
  const samples = await QuantityTypes.queryQuantitySamples(identifier, {
9
10
  limit: 1,
@@ -1,12 +1,15 @@
1
1
  import { Workouts } from '../modules'
2
+ import type { WorkoutProxyTyped } from '../types/Workouts'
2
3
 
3
- const getMostRecentWorkout = async () => {
4
+ const getMostRecentWorkout = async (): Promise<
5
+ WorkoutProxyTyped | undefined
6
+ > => {
4
7
  const workouts = await Workouts.queryWorkoutSamples({
5
8
  limit: 1,
6
9
  ascending: false,
7
10
  })
8
11
 
9
- return workouts[0]
12
+ return workouts[0] as WorkoutProxyTyped | undefined
10
13
  }
11
14
 
12
15
  export default getMostRecentWorkout
@@ -1,9 +1,10 @@
1
1
  import { Core } from '../modules'
2
+ import type { UnitForIdentifier } from '../types/QuantityType'
2
3
  import type { QuantityTypeIdentifier } from '../types/QuantityTypeIdentifier'
3
4
 
4
- const getPreferredUnit = async (
5
- quantityType: QuantityTypeIdentifier,
6
- ): Promise<string> => {
5
+ const getPreferredUnit = async <T extends QuantityTypeIdentifier>(
6
+ quantityType: T,
7
+ ): Promise<UnitForIdentifier<T>> => {
7
8
  const units = await Core.getPreferredUnits([quantityType])
8
9
  const unit = units[0]?.unit
9
10
 
@@ -13,6 +14,6 @@ const getPreferredUnit = async (
13
14
  )
14
15
  }
15
16
 
16
- return unit
17
+ return unit as UnitForIdentifier<T>
17
18
  }
18
19
  export default getPreferredUnit
@@ -1,10 +1,11 @@
1
1
  import { QuantityTypes } from '../modules'
2
+ import type { UnitForIdentifier } from '../types/QuantityType'
2
3
  import type { QuantityTypeIdentifier } from '../types/QuantityTypeIdentifier'
3
4
 
4
- async function getQuantitySampleById(
5
- identifier: QuantityTypeIdentifier,
5
+ async function getQuantitySampleById<T extends QuantityTypeIdentifier>(
6
+ identifier: T,
6
7
  uuid: string,
7
- unit?: string,
8
+ unit?: UnitForIdentifier<T>,
8
9
  ) {
9
10
  const samples = await QuantityTypes.queryQuantitySamples(identifier, {
10
11
  limit: 1,
@@ -3,9 +3,11 @@ import type { QuantityTypeIdentifier } from '../types'
3
3
  import type { OnQuantitySamplesCallback } from '../types/Subscriptions'
4
4
  import { subscribeToChanges } from './subscribeToChanges'
5
5
 
6
- export const subscribeToQuantitySamples = (
7
- identifier: QuantityTypeIdentifier,
8
- callback: (args: OnQuantitySamplesCallback) => void,
6
+ export const subscribeToQuantitySamples = <
7
+ TIdentifier extends QuantityTypeIdentifier,
8
+ >(
9
+ identifier: TIdentifier,
10
+ callback: (args: OnQuantitySamplesCallback<TIdentifier>) => void,
9
11
  after = new Date(),
10
12
  ) => {
11
13
  return subscribeToChanges(identifier, async ({ errorMessage }) => {
@@ -1,44 +0,0 @@
1
- ///
2
- /// HeartRateMotionContext.swift
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © Marc Rousavy @ Margelo
6
- ///
7
-
8
- /**
9
- * Represents the JS enum `HeartRateMotionContext`, backed by a C++ enum.
10
- */
11
- public typealias HeartRateMotionContext = margelo.nitro.healthkit.HeartRateMotionContext
12
-
13
- public extension HeartRateMotionContext {
14
- /**
15
- * Get a HeartRateMotionContext for the given String value, or
16
- * return `nil` if the given value was invalid/unknown.
17
- */
18
- init?(fromString string: String) {
19
- switch string {
20
- case "active":
21
- self = .active
22
- case "notSet":
23
- self = .notset
24
- case "sedentary":
25
- self = .sedentary
26
- default:
27
- return nil
28
- }
29
- }
30
-
31
- /**
32
- * Get the String value this HeartRateMotionContext represents.
33
- */
34
- var stringValue: String {
35
- switch self {
36
- case .active:
37
- return "active"
38
- case .notset:
39
- return "notSet"
40
- case .sedentary:
41
- return "sedentary"
42
- }
43
- }
44
- }
@@ -1,40 +0,0 @@
1
- ///
2
- /// InsulinDeliveryReason.swift
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © Marc Rousavy @ Margelo
6
- ///
7
-
8
- /**
9
- * Represents the JS enum `InsulinDeliveryReason`, backed by a C++ enum.
10
- */
11
- public typealias InsulinDeliveryReason = margelo.nitro.healthkit.InsulinDeliveryReason
12
-
13
- public extension InsulinDeliveryReason {
14
- /**
15
- * Get a InsulinDeliveryReason for the given String value, or
16
- * return `nil` if the given value was invalid/unknown.
17
- */
18
- init?(fromString string: String) {
19
- switch string {
20
- case "basal":
21
- self = .basal
22
- case "bolus":
23
- self = .bolus
24
- default:
25
- return nil
26
- }
27
- }
28
-
29
- /**
30
- * Get the String value this InsulinDeliveryReason represents.
31
- */
32
- var stringValue: String {
33
- switch self {
34
- case .basal:
35
- return "basal"
36
- case .bolus:
37
- return "bolus"
38
- }
39
- }
40
- }