@kingstinct/react-native-healthkit 5.0.0 → 5.1.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/README.md +39 -12
- package/ios/ReactNativeHealthkit.m +6 -0
- package/ios/ReactNativeHealthkit.swift +23 -0
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js.map +1 -1
- package/lib/commonjs/hooks/useIsHealthDataAvailable.test.js +45 -0
- package/lib/commonjs/hooks/useIsHealthDataAvailable.test.js.map +1 -0
- package/lib/commonjs/hooks/useMostRecentWorkout.js +0 -4
- package/lib/commonjs/hooks/useMostRecentWorkout.js.map +1 -1
- package/lib/commonjs/index.ios.js +4 -0
- package/lib/commonjs/index.ios.js.map +1 -1
- package/lib/commonjs/index.js +1 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/jest.setup.js +10 -0
- package/lib/commonjs/jest.setup.js.map +1 -0
- package/lib/commonjs/native-types.js.map +1 -1
- package/lib/commonjs/utils/deleteQuantitySample.js +16 -0
- package/lib/commonjs/utils/deleteQuantitySample.js.map +1 -0
- package/lib/commonjs/utils/deserializeCategorySample.js +2 -2
- package/lib/commonjs/utils/deserializeCategorySample.js.map +1 -1
- package/lib/commonjs/utils/deserializeCategorySample.test.js +25 -0
- package/lib/commonjs/utils/deserializeCategorySample.test.js.map +1 -0
- package/lib/commonjs/utils/serializeDate.test.js +19 -0
- package/lib/commonjs/utils/serializeDate.test.js.map +1 -0
- package/lib/module/hooks/useIsHealthDataAvailable.js.map +1 -1
- package/lib/module/hooks/useIsHealthDataAvailable.test.js +38 -0
- package/lib/module/hooks/useIsHealthDataAvailable.test.js.map +1 -0
- package/lib/module/hooks/useMostRecentWorkout.js +0 -4
- package/lib/module/hooks/useMostRecentWorkout.js.map +1 -1
- package/lib/module/index.ios.js +3 -0
- package/lib/module/index.ios.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest.setup.js +7 -0
- package/lib/module/jest.setup.js.map +1 -0
- package/lib/module/native-types.js.map +1 -1
- package/lib/module/utils/deleteQuantitySample.js +6 -0
- package/lib/module/utils/deleteQuantitySample.js.map +1 -0
- package/lib/module/utils/deserializeCategorySample.js +2 -2
- package/lib/module/utils/deserializeCategorySample.js.map +1 -1
- package/lib/module/utils/deserializeCategorySample.test.js +19 -0
- package/lib/module/utils/deserializeCategorySample.test.js.map +1 -0
- package/lib/module/utils/serializeDate.test.js +14 -0
- package/lib/module/utils/serializeDate.test.js.map +1 -0
- package/lib/typescript/src/hooks/useIsHealthDataAvailable.test.d.ts +1 -0
- package/lib/typescript/src/index.ios.d.ts +1 -0
- package/lib/typescript/src/jest.setup.d.ts +1 -0
- package/lib/typescript/src/native-types.d.ts +1 -0
- package/lib/typescript/src/utils/deleteQuantitySample.d.ts +4 -0
- package/lib/typescript/src/utils/deserializeCategorySample.d.ts +2 -2
- package/lib/typescript/src/utils/deserializeCategorySample.test.d.ts +1 -0
- package/lib/typescript/src/utils/serializeDate.test.d.ts +1 -0
- package/package.json +3 -8
- package/src/hooks/useIsHealthDataAvailable.test.ts +40 -0
- package/src/hooks/useIsHealthDataAvailable.ts +2 -0
- package/src/hooks/useMostRecentWorkout.ts +0 -2
- package/src/index.ios.tsx +4 -0
- package/src/index.tsx +1 -0
- package/src/jest.setup.ts +7 -0
- package/src/native-types.ts +21 -5
- package/src/utils/deleteQuantitySample.ts +14 -0
- package/src/utils/deserializeCategorySample.test.ts +21 -0
- package/src/utils/deserializeCategorySample.ts +2 -2
- package/src/utils/serializeDate.test.ts +16 -0
package/src/native-types.ts
CHANGED
|
@@ -804,8 +804,11 @@ export enum BloodGlucoseUnit {
|
|
|
804
804
|
export type SpeedUnit<TLength extends LengthUnit, TTime extends TimeUnit> =`${TLength}/${TTime}`;
|
|
805
805
|
export type CountPerTime<TTime extends TimeUnit> =`count/${TTime}`;
|
|
806
806
|
|
|
807
|
-
export type HKUnit = BloodGlucoseUnit | CountPerTime<TimeUnit> | EnergyUnit
|
|
808
|
-
|
|
|
807
|
+
export type HKUnit = BloodGlucoseUnit | CountPerTime<TimeUnit> | EnergyUnit
|
|
808
|
+
| FrequencyUnit | HKUnits | LengthUnit | MassUnit | PressureUnit | SpeedUnit<LengthUnit, TimeUnit>
|
|
809
|
+
| TemperatureUnit | TimeUnit | VolumeUnit
|
|
810
|
+
| `${BloodGlucoseUnit}` | `${EnergyUnit}` | `${FrequencyUnit}` | `${HKUnits}` | `${LengthUnit}`
|
|
811
|
+
| `${MassUnit}` | `${PressureUnit}` | `${TemperatureUnit}` | `${TimeUnit}` | `${VolumeUnit}`;
|
|
809
812
|
|
|
810
813
|
export type HKDevice = {
|
|
811
814
|
readonly name: string; // ex: "Apple Watch"
|
|
@@ -957,7 +960,10 @@ type ReactNativeHealthkitTypeNative = {
|
|
|
957
960
|
) => Promise<boolean>;
|
|
958
961
|
readonly disableAllBackgroundDelivery: () => Promise<boolean>;
|
|
959
962
|
|
|
960
|
-
readonly saveCorrelationSample: <
|
|
963
|
+
readonly saveCorrelationSample: <
|
|
964
|
+
TIdentifier extends HKCorrelationTypeIdentifier,
|
|
965
|
+
TSamples extends readonly (HKCategorySampleRawForSaving | HKQuantitySampleRawForSaving)[]
|
|
966
|
+
>(
|
|
961
967
|
typeIdentifier: TIdentifier,
|
|
962
968
|
samples: TSamples,
|
|
963
969
|
start: string,
|
|
@@ -994,7 +1000,10 @@ type ReactNativeHealthkitTypeNative = {
|
|
|
994
1000
|
write: WritePermissions,
|
|
995
1001
|
read: ReadPermissions
|
|
996
1002
|
): Promise<boolean>;
|
|
997
|
-
readonly saveQuantitySample: <
|
|
1003
|
+
readonly saveQuantitySample: <
|
|
1004
|
+
TType extends HKQuantityTypeIdentifier,
|
|
1005
|
+
TUnit extends UnitForIdentifier<TType> = UnitForIdentifier<TType>
|
|
1006
|
+
> (
|
|
998
1007
|
identifier: TType,
|
|
999
1008
|
unit: TUnit,
|
|
1000
1009
|
value: number,
|
|
@@ -1002,6 +1011,10 @@ type ReactNativeHealthkitTypeNative = {
|
|
|
1002
1011
|
end: string,
|
|
1003
1012
|
metadata: unknown
|
|
1004
1013
|
) => Promise<boolean>;
|
|
1014
|
+
readonly deleteQuantitySample: <TIdentifier extends HKQuantityTypeIdentifier>(
|
|
1015
|
+
typeIdentifier: TIdentifier,
|
|
1016
|
+
uuid: string
|
|
1017
|
+
) => Promise<boolean>;
|
|
1005
1018
|
readonly queryWorkoutSamples: <TEnergy extends EnergyUnit, TDistance extends LengthUnit>(
|
|
1006
1019
|
energyUnit: TEnergy,
|
|
1007
1020
|
distanceUnit: TDistance,
|
|
@@ -1035,7 +1048,10 @@ type ReactNativeHealthkitTypeNative = {
|
|
|
1035
1048
|
end: string,
|
|
1036
1049
|
metadata: unknown
|
|
1037
1050
|
) => Promise<boolean>;
|
|
1038
|
-
readonly queryStatisticsForQuantity: <
|
|
1051
|
+
readonly queryStatisticsForQuantity: <
|
|
1052
|
+
TIdentifier extends HKQuantityTypeIdentifier,
|
|
1053
|
+
TUnit extends UnitForIdentifier<TIdentifier>
|
|
1054
|
+
>(
|
|
1039
1055
|
identifier: HKQuantityTypeIdentifier,
|
|
1040
1056
|
unit: TUnit,
|
|
1041
1057
|
from: string,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Native from '../native-types'
|
|
2
|
+
|
|
3
|
+
import type { HKQuantityTypeIdentifier } from '../native-types'
|
|
4
|
+
|
|
5
|
+
export type DeleteQuantitySampleFn = <
|
|
6
|
+
TIdentifier extends HKQuantityTypeIdentifier
|
|
7
|
+
>(
|
|
8
|
+
identifier: TIdentifier,
|
|
9
|
+
uuid: string
|
|
10
|
+
) => Promise<boolean>
|
|
11
|
+
|
|
12
|
+
const deleteQuantitySample: DeleteQuantitySampleFn = async (identifier, uuid) => Native.deleteQuantitySample(identifier, uuid)
|
|
13
|
+
|
|
14
|
+
export default deleteQuantitySample
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HKCategorySampleRaw, HKCategoryTypeIdentifier } from '../types'
|
|
2
|
+
import deserializeCategorySample from './deserializeCategorySample'
|
|
3
|
+
|
|
4
|
+
describe('deserializeCategorySample', () => {
|
|
5
|
+
it('should deserialize category sample', () => {
|
|
6
|
+
const sample: HKCategorySampleRaw = {
|
|
7
|
+
startDate: '2020-01-01T00:00:00.000Z',
|
|
8
|
+
endDate: '2020-01-01T00:00:00.000Z',
|
|
9
|
+
value: 1,
|
|
10
|
+
categoryType: HKCategoryTypeIdentifier.sexualActivity,
|
|
11
|
+
metadata: {},
|
|
12
|
+
uuid: 'uuid',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
expect(deserializeCategorySample(sample)).toEqual({
|
|
16
|
+
...sample,
|
|
17
|
+
startDate: new Date('2020-01-01T00:00:00.000Z'),
|
|
18
|
+
endDate: new Date('2020-01-01T00:00:00.000Z'),
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HKCategorySampleRaw, HKCategoryTypeIdentifier } from '../native-types'
|
|
2
2
|
import type { HKCategorySample } from '../types'
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const deserializeCategorySample = <T extends HKCategoryTypeIdentifier>(
|
|
5
5
|
sample: HKCategorySampleRaw<T>,
|
|
6
6
|
): HKCategorySample<T> => ({
|
|
7
7
|
...sample,
|
|
@@ -9,4 +9,4 @@ const deserializCategorySample = <T extends HKCategoryTypeIdentifier>(
|
|
|
9
9
|
endDate: new Date(sample.endDate),
|
|
10
10
|
})
|
|
11
11
|
|
|
12
|
-
export default
|
|
12
|
+
export default deserializeCategorySample
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import serializeDate from './serializeDate'
|
|
2
|
+
|
|
3
|
+
describe('serializeDate', () => {
|
|
4
|
+
it('should serialize zero date', () => {
|
|
5
|
+
expect(serializeDate(new Date(0))).toBe('1970-01-01T00:00:00.000Z')
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
it('should serialize date', () => {
|
|
9
|
+
const date = new Date()
|
|
10
|
+
expect(serializeDate(date)).toBe(date.toISOString())
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('should serialize null date', () => {
|
|
14
|
+
expect(serializeDate(null)).toBe('1970-01-01T00:00:00.000Z')
|
|
15
|
+
})
|
|
16
|
+
})
|