@kingstinct/react-native-healthkit 7.0.4 → 7.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -31
- package/ios/ReactNativeHealthkit.swift +3 -2
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js +5 -0
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js.map +1 -1
- package/lib/commonjs/index.ios.js +121 -15
- package/lib/commonjs/index.ios.js.map +1 -1
- package/lib/commonjs/index.js +3 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/jest.setup.js +1 -0
- package/lib/commonjs/jest.setup.js.map +1 -1
- package/lib/commonjs/native-types.js +36 -27
- package/lib/commonjs/native-types.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/getMostRecentCategorySample.js +1 -1
- package/lib/commonjs/utils/getMostRecentCategorySample.js.map +1 -1
- package/lib/commonjs/utils/getMostRecentQuantitySample.js +5 -1
- package/lib/commonjs/utils/getMostRecentQuantitySample.js.map +1 -1
- package/lib/module/hooks/useIsHealthDataAvailable.js +6 -0
- package/lib/module/hooks/useIsHealthDataAvailable.js.map +1 -1
- package/lib/module/index.ios.js +119 -15
- package/lib/module/index.ios.js.map +1 -1
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest.setup.js +1 -0
- package/lib/module/jest.setup.js.map +1 -1
- package/lib/module/native-types.js +36 -27
- package/lib/module/native-types.js.map +1 -1
- package/lib/module/types.js +59 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/getMostRecentCategorySample.js +1 -1
- package/lib/module/utils/getMostRecentCategorySample.js.map +1 -1
- package/lib/module/utils/getMostRecentQuantitySample.js +5 -1
- package/lib/module/utils/getMostRecentQuantitySample.js.map +1 -1
- package/lib/typescript/src/hooks/useIsHealthDataAvailable.d.ts +5 -0
- package/lib/typescript/src/index.d.ts +50 -3
- package/lib/typescript/src/index.ios.d.ts +84 -3
- package/lib/typescript/src/native-types.d.ts +515 -34
- package/lib/typescript/src/types.d.ts +49 -0
- package/lib/typescript/src/utils/getMostRecentCategorySample.d.ts +2 -1
- package/lib/typescript/src/utils/getMostRecentQuantitySample.d.ts +2 -1
- package/package.json +1 -1
- package/src/hooks/useIsHealthDataAvailable.ts +5 -0
- package/src/index.ios.tsx +132 -21
- package/src/index.tsx +6 -4
- package/src/jest.setup.ts +1 -0
- package/src/native-types.ts +615 -81
- package/src/types.ts +51 -2
- package/src/utils/getMostRecentCategorySample.ts +3 -2
- package/src/utils/getMostRecentQuantitySample.ts +9 -2
package/src/types.ts
CHANGED
|
@@ -18,6 +18,12 @@ import type {
|
|
|
18
18
|
|
|
19
19
|
export * from './native-types'
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Options for querying workouts.
|
|
23
|
+
* @template TEnergy The energy unit type.
|
|
24
|
+
* @template TDistance The distance unit type.
|
|
25
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkworkout Apple Docs HKWorkout}
|
|
26
|
+
*/
|
|
21
27
|
export interface QueryWorkoutsOptions<
|
|
22
28
|
TEnergy extends HKUnit,
|
|
23
29
|
TDistance extends HKUnit
|
|
@@ -26,6 +32,11 @@ export interface QueryWorkoutsOptions<
|
|
|
26
32
|
readonly distanceUnit?: TDistance;
|
|
27
33
|
}
|
|
28
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Represents a category sample.
|
|
37
|
+
* @template T The category type identifier.
|
|
38
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkcategorysample Apple Docs HKCategorySample}
|
|
39
|
+
*/
|
|
29
40
|
export interface HKCategorySample<
|
|
30
41
|
T extends HKCategoryTypeIdentifier = HKCategoryTypeIdentifier
|
|
31
42
|
> extends Omit<HKCategorySampleRaw<T>, 'endDate' | 'startDate'> {
|
|
@@ -33,6 +44,9 @@ export interface HKCategorySample<
|
|
|
33
44
|
readonly endDate: Date;
|
|
34
45
|
}
|
|
35
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Generic options for querying.
|
|
49
|
+
*/
|
|
36
50
|
export type GenericQueryOptions = {
|
|
37
51
|
readonly from?: Date;
|
|
38
52
|
readonly to?: Date;
|
|
@@ -41,6 +55,12 @@ export type GenericQueryOptions = {
|
|
|
41
55
|
readonly anchor?: string
|
|
42
56
|
};
|
|
43
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Represents a workout.
|
|
60
|
+
* @template TEnergy The energy unit type.
|
|
61
|
+
* @template TDistance The distance unit type.
|
|
62
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkworkout Apple Docs HKWorkout}
|
|
63
|
+
*/
|
|
44
64
|
export interface HKWorkout<
|
|
45
65
|
TEnergy extends EnergyUnit = EnergyUnit,
|
|
46
66
|
TDistance extends LengthUnit = LengthUnit
|
|
@@ -49,11 +69,21 @@ export interface HKWorkout<
|
|
|
49
69
|
readonly endDate: Date;
|
|
50
70
|
}
|
|
51
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Represents a heartbeat series sample.
|
|
74
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkheartbeatseriessample Apple Docs HKHeartbeatSeriesSample}
|
|
75
|
+
*/
|
|
52
76
|
export interface HKHeartbeatSeriesSample extends Omit<HKHeartbeatSeriesSampleRaw, 'endDate' | 'startDate'> {
|
|
53
77
|
readonly startDate: Date;
|
|
54
78
|
readonly endDate: Date;
|
|
55
79
|
}
|
|
56
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Represents a quantity sample.
|
|
83
|
+
* @template TIdentifier The quantity type identifier.
|
|
84
|
+
* @template TUnit The unit for the identifier.
|
|
85
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkquantitysample Apple Docs HKQuantitySample}
|
|
86
|
+
*/
|
|
57
87
|
export interface HKQuantitySample<
|
|
58
88
|
TIdentifier extends HKQuantityTypeIdentifier = HKQuantityTypeIdentifier,
|
|
59
89
|
TUnit extends UnitForIdentifier<TIdentifier> = UnitForIdentifier<TIdentifier>
|
|
@@ -69,6 +99,12 @@ export interface HKQuantitySample<
|
|
|
69
99
|
readonly endDate: Date;
|
|
70
100
|
}
|
|
71
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Represents a response from a statistics query.
|
|
104
|
+
* @template TIdentifier The quantity type identifier.
|
|
105
|
+
* @template TUnit The unit for the identifier.
|
|
106
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkstatisticsquery Apple Docs HKStatisticsQuery}
|
|
107
|
+
*/
|
|
72
108
|
export interface QueryStatisticsResponse<TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier> = UnitForIdentifier<TIdentifier>>
|
|
73
109
|
extends Omit<
|
|
74
110
|
QueryStatisticsResponseRaw<TIdentifier, TUnit>,
|
|
@@ -77,10 +113,23 @@ export interface QueryStatisticsResponse<TIdentifier extends HKQuantityTypeIdent
|
|
|
77
113
|
readonly mostRecentQuantityDateInterval?: { readonly from: Date; readonly to: Date };
|
|
78
114
|
}
|
|
79
115
|
|
|
80
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Represents a category sample for saving.
|
|
118
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkcategorysample Apple Docs HKCategorySample}
|
|
119
|
+
*/
|
|
120
|
+
export type HKCategorySampleForSaving = Omit<HKCategorySample, 'device' | 'endDate' | 'startDate' | 'uuid'>
|
|
81
121
|
|
|
82
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Represents a quantity sample for saving.
|
|
124
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkquantitysample Apple Docs HKQuantitySample}
|
|
125
|
+
*/
|
|
126
|
+
export type HKQuantitySampleForSaving = Omit<HKQuantitySample, 'device' | 'endDate' | 'startDate' | 'uuid'>
|
|
83
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Represents a correlation.
|
|
130
|
+
* @template TIdentifier The correlation type identifier.
|
|
131
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkcorrelation Apple Docs HKCorrelation}
|
|
132
|
+
*/
|
|
84
133
|
export interface HKCorrelation<TIdentifier extends HKCorrelationTypeIdentifier>
|
|
85
134
|
extends Omit<
|
|
86
135
|
HKCorrelationRaw<TIdentifier>,
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import queryCategorySamples from './queryCategorySamples'
|
|
2
2
|
|
|
3
3
|
import type { HKCategoryTypeIdentifier } from '../native-types'
|
|
4
|
+
import type { HKCategorySample } from '../types'
|
|
4
5
|
|
|
5
6
|
async function getMostRecentCategorySample<
|
|
6
7
|
T extends HKCategoryTypeIdentifier
|
|
7
8
|
>(
|
|
8
9
|
identifier: T,
|
|
9
|
-
) {
|
|
10
|
+
): Promise<HKCategorySample<T> | null> {
|
|
10
11
|
const samples = await queryCategorySamples(identifier, {
|
|
11
12
|
limit: 1,
|
|
12
13
|
ascending: false,
|
|
13
14
|
})
|
|
14
15
|
|
|
15
|
-
return samples[0]
|
|
16
|
+
return samples[0] ?? null
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export default getMostRecentCategorySample
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import queryQuantitySamples from './queryQuantitySamples'
|
|
2
2
|
|
|
3
3
|
import type { HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types'
|
|
4
|
+
import type { HKQuantitySample } from '../types'
|
|
4
5
|
|
|
5
6
|
async function getMostRecentQuantitySample<
|
|
6
7
|
TIdentifier extends HKQuantityTypeIdentifier,
|
|
@@ -8,12 +9,18 @@ async function getMostRecentQuantitySample<
|
|
|
8
9
|
>(
|
|
9
10
|
identifier: TIdentifier,
|
|
10
11
|
unit: TUnit,
|
|
11
|
-
) {
|
|
12
|
+
): Promise<HKQuantitySample<TIdentifier, TUnit> | null> {
|
|
12
13
|
const samples = await queryQuantitySamples(identifier, {
|
|
13
14
|
limit: 1,
|
|
14
15
|
unit,
|
|
15
16
|
})
|
|
16
|
-
|
|
17
|
+
|
|
18
|
+
const lastSample = samples[0]
|
|
19
|
+
|
|
20
|
+
if (lastSample) {
|
|
21
|
+
return lastSample as HKQuantitySample<TIdentifier, TUnit>
|
|
22
|
+
}
|
|
23
|
+
return null
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
export default getMostRecentQuantitySample
|