@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/types.ts CHANGED
@@ -9,7 +9,6 @@ import type {
9
9
  HKCorrelationRaw,
10
10
  HKCorrelationTypeIdentifier,
11
11
  HKFitzpatrickSkinType,
12
- MetadataMapperForCategoryIdentifier,
13
12
  HKQuantitySampleRaw,
14
13
  HKQuantityTypeIdentifier,
15
14
  HKSampleTypeIdentifier,
@@ -17,63 +16,65 @@ import type {
17
16
  HKUnit,
18
17
  HKUnitSI,
19
18
  HKUnitSIPrefix,
19
+ HKUpdateFrequency,
20
20
  HKWheelchairUse,
21
21
  HKWorkoutActivityType,
22
22
  HKWorkoutMetadata,
23
23
  HKWorkoutRaw,
24
+ MetadataMapperForCategoryIdentifier,
24
25
  MetadataMapperForCorrelationIdentifier,
25
26
  MetadataMapperForQuantityIdentifier,
26
27
  QueryStatisticsResponseRaw,
27
- HKUpdateFrequency,
28
- } from './native-types';
28
+ WorkoutRoute,
29
+ } from './native-types'
29
30
 
30
31
  export interface QueryWorkoutsOptions<
31
32
  TEnergy extends HKUnit,
32
33
  TDistance extends HKUnit
33
34
  > extends GenericQueryOptions {
34
- energyUnit?: TEnergy;
35
- distanceUnit?: TDistance;
35
+ readonly energyUnit?: TEnergy;
36
+ readonly distanceUnit?: TDistance;
36
37
  }
37
38
 
38
39
  export interface HKCategorySample<
39
40
  T extends HKCategoryTypeIdentifier = HKCategoryTypeIdentifier
40
- > extends Omit<HKCategorySampleRaw<T>, 'startDate' | 'endDate'> {
41
- startDate: Date;
42
- endDate: Date;
41
+ > extends Omit<HKCategorySampleRaw<T>, 'endDate' | 'startDate'> {
42
+ readonly startDate: Date;
43
+ readonly endDate: Date;
43
44
  }
44
45
 
45
46
  export type GenericQueryOptions = {
46
- from?: Date;
47
- to?: Date;
48
- limit?: Number;
49
- ascending?: boolean;
47
+ readonly from?: Date;
48
+ readonly to?: Date;
49
+ readonly limit?: number;
50
+ readonly ascending?: boolean;
50
51
  };
51
52
 
52
53
  export interface HKWorkout<
53
54
  TEnergy extends HKUnit = HKUnit,
54
55
  TDistance extends HKUnit = HKUnit
55
- > extends Omit<HKWorkoutRaw<TEnergy, TDistance>, 'startDate' | 'endDate'> {
56
- startDate: Date;
57
- endDate: Date;
56
+ > extends Omit<HKWorkoutRaw<TEnergy, TDistance>, 'endDate' | 'startDate'> {
57
+ readonly startDate: Date;
58
+ readonly endDate: Date;
58
59
  }
59
60
 
60
61
  export interface HKQuantitySample<
61
62
  TIdentifier extends HKQuantityTypeIdentifier = HKQuantityTypeIdentifier,
62
63
  TUnit extends HKUnit = HKUnit
63
64
  > extends Omit<
64
- HKQuantitySampleRaw<TIdentifier, TUnit>,
65
- 'startDate' | 'endDate'
65
+ HKQuantitySampleRaw<TIdentifier, TUnit>,
66
+ 'endDate' | 'startDate'
66
67
  > {
67
- startDate: Date;
68
- endDate: Date;
68
+ readonly startDate: Date;
69
+ readonly endDate: Date;
69
70
  }
70
71
 
71
72
  export interface QueryStatisticsResponse<T extends HKUnit = HKUnit>
72
73
  extends Omit<
73
- QueryStatisticsResponseRaw<T>,
74
- 'mostRecentQuantityDateInterval'
74
+ QueryStatisticsResponseRaw<T>,
75
+ 'mostRecentQuantityDateInterval'
75
76
  > {
76
- mostRecentQuantityDateInterval?: { from: Date; to: Date };
77
+ readonly mostRecentQuantityDateInterval?: { readonly from: Date; readonly to: Date };
77
78
  }
78
79
 
79
80
  type UnsubscribeFunction = () => Promise<boolean>;
@@ -89,7 +90,7 @@ export type GetFitzpatrickSkinTypeFn = () => Promise<HKFitzpatrickSkinType>;
89
90
 
90
91
  export type QueryStatisticsForQuantityFn = <TUnit extends HKUnit>(
91
92
  identifier: HKQuantityTypeIdentifier,
92
- options: HKStatisticsOptions[],
93
+ options: readonly HKStatisticsOptions[],
93
94
  from: Date,
94
95
  to?: Date,
95
96
  unit?: TUnit
@@ -100,25 +101,25 @@ export type QueryWorkoutsFn = <
100
101
  TDistance extends HKUnit
101
102
  >(
102
103
  options: QueryWorkoutsOptions<TEnergy, TDistance>
103
- ) => Promise<HKWorkout<TEnergy, TDistance>[]>;
104
+ ) => Promise<readonly HKWorkout<TEnergy, TDistance>[]>;
104
105
 
105
106
  export type AuthorizationStatusForFn = (
106
- type: HKSampleTypeIdentifier | HKCharacteristicTypeIdentifier
107
+ type: HKCharacteristicTypeIdentifier | HKSampleTypeIdentifier
107
108
  ) => Promise<boolean>;
108
109
 
109
110
  export type QueryCategorySamplesFn = <T extends HKCategoryTypeIdentifier>(
110
111
  identifier: T,
111
112
  options: GenericQueryOptions
112
- ) => Promise<HKCategorySample<T>[]>;
113
+ ) => Promise<readonly HKCategorySample<T>[]>;
113
114
 
114
115
  export type GetRequestStatusForAuthorizationFn = (
115
- read: (HKCharacteristicTypeIdentifier | HKSampleTypeIdentifier)[],
116
- write?: HKSampleTypeIdentifier[]
116
+ read: readonly (HKCharacteristicTypeIdentifier | HKSampleTypeIdentifier)[],
117
+ write?: readonly HKSampleTypeIdentifier[]
117
118
  ) => Promise<HKAuthorizationRequestStatus>;
118
119
 
119
120
  export type RequestAuthorizationFn = (
120
- read: (HKCharacteristicTypeIdentifier | HKSampleTypeIdentifier)[],
121
- write?: HKSampleTypeIdentifier[]
121
+ read: readonly (HKCharacteristicTypeIdentifier | HKSampleTypeIdentifier)[],
122
+ write?: readonly HKSampleTypeIdentifier[]
122
123
  ) => Promise<boolean>;
123
124
 
124
125
  export type SaveQuantitySampleFn = <TUnit extends HKQuantityTypeIdentifier>(
@@ -126,9 +127,9 @@ export type SaveQuantitySampleFn = <TUnit extends HKQuantityTypeIdentifier>(
126
127
  unit: HKUnit,
127
128
  value: number,
128
129
  options?: {
129
- start?: Date;
130
- end?: Date;
131
- metadata?: MetadataMapperForQuantityIdentifier<TUnit>;
130
+ readonly start?: Date;
131
+ readonly end?: Date;
132
+ readonly metadata?: MetadataMapperForQuantityIdentifier<TUnit>;
132
133
  }
133
134
  ) => Promise<boolean>;
134
135
 
@@ -137,8 +138,8 @@ export type QueryQuantitySamplesFn = <
137
138
  TUnit extends HKUnit = HKUnit
138
139
  >(
139
140
  identifier: TIdentifier,
140
- options: GenericQueryOptions & { unit?: TUnit }
141
- ) => Promise<HKQuantitySample<TIdentifier, TUnit>[]>;
141
+ options: GenericQueryOptions & { readonly unit?: TUnit }
142
+ ) => Promise<readonly HKQuantitySample<TIdentifier, TUnit>[]>;
142
143
 
143
144
  export type SubscribeToChangesFn = (
144
145
  identifier: HKSampleTypeIdentifier,
@@ -149,9 +150,9 @@ export type SaveCategorySampleFn = <T extends HKCategoryTypeIdentifier>(
149
150
  identifier: T,
150
151
  value: HKCategoryValueForIdentifier<T>,
151
152
  options?: {
152
- start?: Date;
153
- end?: Date;
154
- metadata?: MetadataMapperForCategoryIdentifier<T>;
153
+ readonly start?: Date;
154
+ readonly end?: Date;
155
+ readonly metadata?: MetadataMapperForCategoryIdentifier<T>;
155
156
  }
156
157
  ) => Promise<boolean>;
157
158
 
@@ -192,8 +193,8 @@ export type GetMostRecentWorkoutFn = <
192
193
  TDistance extends HKUnit
193
194
  >(
194
195
  options?: Pick<
195
- QueryWorkoutsOptions<TEnergy, TDistance>,
196
- 'distanceUnit' | 'energyUnit'
196
+ QueryWorkoutsOptions<TEnergy, TDistance>,
197
+ 'distanceUnit' | 'energyUnit'
197
198
  >
198
199
  ) => Promise<HKWorkout<TEnergy, TDistance> | null>;
199
200
 
@@ -202,14 +203,14 @@ export type MostRecentWorkoutHook = <
202
203
  TDistance extends HKUnit
203
204
  >(
204
205
  options?: Pick<
205
- QueryWorkoutsOptions<TEnergy, TDistance>,
206
- 'distanceUnit' | 'energyUnit'
206
+ QueryWorkoutsOptions<TEnergy, TDistance>,
207
+ 'distanceUnit' | 'energyUnit'
207
208
  >
208
209
  ) => HKWorkout<TEnergy, TDistance> | null;
209
210
 
210
211
  export type GetPreferredUnitsFn = (
211
- identifiers: HKQuantityTypeIdentifier[]
212
- ) => Promise<HKUnit[]>;
212
+ identifiers: readonly HKQuantityTypeIdentifier[]
213
+ ) => Promise<readonly HKUnit[]>;
213
214
 
214
215
  export type GetPreferredUnitFn = (
215
216
  identifier: HKQuantityTypeIdentifier
@@ -219,46 +220,46 @@ export type SaveCorrelationSampleFn = <
219
220
  TIdentifier extends HKCorrelationTypeIdentifier
220
221
  >(
221
222
  typeIdentifier: TIdentifier,
222
- samples: (
223
- | Omit<HKCategorySample, 'startDate' | 'endDate' | 'uuid' | 'device'>
224
- | Omit<HKQuantitySample, 'startDate' | 'endDate' | 'uuid' | 'device'>
223
+ samples: readonly (
224
+ | Omit<HKCategorySample, 'device' | 'endDate' | 'startDate' | 'uuid'>
225
+ | Omit<HKQuantitySample, 'device' | 'endDate' | 'startDate' | 'uuid'>
225
226
  )[],
226
227
  options?: {
227
- start?: Date;
228
- end?: Date;
229
- metadata?: MetadataMapperForCorrelationIdentifier<TIdentifier>;
228
+ readonly start?: Date;
229
+ readonly end?: Date;
230
+ readonly metadata?: MetadataMapperForCorrelationIdentifier<TIdentifier>;
230
231
  }
231
232
  ) => Promise<boolean>;
232
233
 
233
234
  export type SaveWorkoutSampleFn = (
234
235
  typeIdentifier: HKWorkoutActivityType,
235
- quantities: Omit<
236
- HKQuantitySample,
237
- 'startDate' | 'endDate' | 'uuid' | 'device'
236
+ quantities: readonly Omit<
237
+ HKQuantitySample,
238
+ 'device' | 'endDate' | 'startDate' | 'uuid'
238
239
  >[],
239
240
  start: Date,
240
241
  options?: {
241
- end?: Date;
242
- metadata?: HKWorkoutMetadata;
242
+ readonly end?: Date;
243
+ readonly metadata?: HKWorkoutMetadata;
243
244
  }
244
245
  ) => Promise<boolean>;
245
246
 
246
247
  export interface HKCorrelation<TIdentifier extends HKCorrelationTypeIdentifier>
247
248
  extends Omit<
248
- HKCorrelationRaw<TIdentifier>,
249
- 'startDate' | 'endDate' | 'objects'
249
+ HKCorrelationRaw<TIdentifier>,
250
+ 'endDate' | 'objects' | 'startDate'
250
251
  > {
251
- objects: (HKQuantitySample | HKCategorySample)[];
252
- startDate: Date;
253
- endDate: Date;
252
+ readonly objects: readonly (HKCategorySample | HKQuantitySample)[];
253
+ readonly startDate: Date;
254
+ readonly endDate: Date;
254
255
  }
255
256
 
256
257
  export type QueryCorrelationSamplesFn = <
257
258
  TIdentifier extends HKCorrelationTypeIdentifier
258
259
  >(
259
260
  typeIdentifier: TIdentifier,
260
- options: Omit<GenericQueryOptions, 'limit' | 'ascending'>
261
- ) => Promise<HKCorrelation<TIdentifier>[]>;
261
+ options: Omit<GenericQueryOptions, 'ascending' | 'limit'>
262
+ ) => Promise<readonly HKCorrelation<TIdentifier>[]>;
262
263
 
263
264
  export type SubscribeToChangesHook = <
264
265
  TIdentifier extends HKSampleTypeIdentifier
@@ -268,51 +269,56 @@ export type SubscribeToChangesHook = <
268
269
  runInitialUpdate?: boolean
269
270
  ) => void;
270
271
 
272
+ export type GetWorkoutRoutesFn = (
273
+ workoutUUID: string
274
+ ) => Promise<readonly WorkoutRoute[]>;
275
+
271
276
  export type ReactNativeHealthkit = {
272
- authorizationStatusFor: AuthorizationStatusForFn;
273
-
274
- getBiologicalSex: GetBiologicalSexFn;
275
- getBloodType: GetBloodTypeFn;
276
- getDateOfBirth: GetDateOfBirthFn;
277
- getFitzpatrickSkinType: GetFitzpatrickSkinTypeFn;
278
- getMostRecentQuantitySample: GetMostRecentQuantitySampleFn;
279
- getMostRecentCategorySample: GetMostRecentCategorySampleFn;
280
- getMostRecentWorkout: GetMostRecentWorkoutFn;
281
- getPreferredUnit: GetPreferredUnitFn;
282
- getPreferredUnits: GetPreferredUnitsFn;
283
- getRequestStatusForAuthorization: GetRequestStatusForAuthorizationFn;
284
- getWheelchairUse: GetWheelchairUseFn;
285
-
286
- buildUnitWithPrefix: (prefix: HKUnitSIPrefix, unit: HKUnitSI) => HKUnit;
287
-
288
- isHealthDataAvailable: IsHealthDataAvailableFn;
289
-
290
- queryCategorySamples: QueryCategorySamplesFn;
291
- queryQuantitySamples: QueryQuantitySamplesFn;
292
- queryStatisticsForQuantity: QueryStatisticsForQuantityFn;
293
- queryWorkouts: QueryWorkoutsFn;
294
- queryCorrelationSamples: QueryCorrelationSamplesFn;
295
-
296
- requestAuthorization: RequestAuthorizationFn;
297
-
298
- saveCategorySample: SaveCategorySampleFn;
299
- saveQuantitySample: SaveQuantitySampleFn;
300
- saveCorrelationSample: SaveCorrelationSampleFn;
301
- saveWorkoutSample: SaveWorkoutSampleFn;
302
- enableBackgroundDelivery: (
277
+ readonly authorizationStatusFor: AuthorizationStatusForFn;
278
+
279
+ readonly getBiologicalSex: GetBiologicalSexFn;
280
+ readonly getBloodType: GetBloodTypeFn;
281
+ readonly getDateOfBirth: GetDateOfBirthFn;
282
+ readonly getFitzpatrickSkinType: GetFitzpatrickSkinTypeFn;
283
+ readonly getMostRecentQuantitySample: GetMostRecentQuantitySampleFn;
284
+ readonly getMostRecentCategorySample: GetMostRecentCategorySampleFn;
285
+ readonly getMostRecentWorkout: GetMostRecentWorkoutFn;
286
+ readonly getPreferredUnit: GetPreferredUnitFn;
287
+ readonly getPreferredUnits: GetPreferredUnitsFn;
288
+ readonly getRequestStatusForAuthorization: GetRequestStatusForAuthorizationFn;
289
+ readonly getWheelchairUse: GetWheelchairUseFn;
290
+ readonly getWorkoutRoutes: GetWorkoutRoutesFn;
291
+
292
+ readonly buildUnitWithPrefix: (prefix: HKUnitSIPrefix, unit: HKUnitSI) => HKUnit;
293
+
294
+ readonly isHealthDataAvailable: IsHealthDataAvailableFn;
295
+
296
+ readonly queryCategorySamples: QueryCategorySamplesFn;
297
+ readonly queryQuantitySamples: QueryQuantitySamplesFn;
298
+ readonly queryStatisticsForQuantity: QueryStatisticsForQuantityFn;
299
+ readonly queryWorkouts: QueryWorkoutsFn;
300
+ readonly queryCorrelationSamples: QueryCorrelationSamplesFn;
301
+
302
+ readonly requestAuthorization: RequestAuthorizationFn;
303
+
304
+ readonly saveCategorySample: SaveCategorySampleFn;
305
+ readonly saveQuantitySample: SaveQuantitySampleFn;
306
+ readonly saveCorrelationSample: SaveCorrelationSampleFn;
307
+ readonly saveWorkoutSample: SaveWorkoutSampleFn;
308
+ readonly enableBackgroundDelivery: (
303
309
  typeIdentifier: HKSampleTypeIdentifier,
304
310
  updateFrequency: HKUpdateFrequency
305
311
  ) => Promise<boolean>;
306
- disableBackgroundDelivery: (
312
+ readonly disableBackgroundDelivery: (
307
313
  typeIdentifier: HKSampleTypeIdentifier
308
314
  ) => Promise<boolean>;
309
- disableAllBackgroundDelivery: () => Promise<boolean>;
315
+ readonly disableAllBackgroundDelivery: () => Promise<boolean>;
310
316
 
311
- subscribeToChanges: SubscribeToChangesFn;
317
+ readonly subscribeToChanges: SubscribeToChangesFn;
312
318
 
313
- useMostRecentWorkout: MostRecentWorkoutHook;
314
- useMostRecentCategorySample: MostRecentCategorySampleHook;
315
- useMostRecentQuantitySample: MostRecentQuantitySampleHook;
319
+ readonly useMostRecentWorkout: MostRecentWorkoutHook;
320
+ readonly useMostRecentCategorySample: MostRecentCategorySampleHook;
321
+ readonly useMostRecentQuantitySample: MostRecentQuantitySampleHook;
316
322
 
317
- useSubscribeToChanges: SubscribeToChangesHook;
323
+ readonly useSubscribeToChanges: SubscribeToChangesHook;
318
324
  };
@@ -1,4 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <Workspace
3
- version = "1.0">
4
- </Workspace>
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>IDEDidComputeMac32BitWarning</key>
6
- <true/>
7
- </dict>
8
- </plist>
@@ -1,14 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>SchemeUserState</key>
6
- <dict>
7
- <key>ReactNativeHealthkit.xcscheme_^#shared#^_</key>
8
- <dict>
9
- <key>orderHint</key>
10
- <integer>0</integer>
11
- </dict>
12
- </dict>
13
- </dict>
14
- </plist>