@kingstinct/react-native-healthkit 4.3.0 → 4.4.2

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