@kingstinct/react-native-healthkit 5.3.0 → 6.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.
- package/README.md +59 -18
- package/ios/ReactNativeHealthkit.m +7 -0
- package/ios/ReactNativeHealthkit.swift +155 -31
- package/lib/commonjs/hooks/useSources.js +28 -0
- package/lib/commonjs/hooks/useSources.js.map +1 -0
- package/lib/commonjs/index.ios.js +3 -0
- package/lib/commonjs/index.ios.js.map +1 -1
- package/lib/commonjs/index.js +11 -2
- 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.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/deserializeCorrelation.js.map +1 -1
- package/lib/commonjs/utils/deserializeSample.js +2 -2
- package/lib/commonjs/utils/deserializeSample.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 +1 -1
- package/lib/commonjs/utils/getMostRecentQuantitySample.js.map +1 -1
- package/lib/commonjs/utils/prepareOptions.js +4 -2
- package/lib/commonjs/utils/prepareOptions.js.map +1 -1
- package/lib/commonjs/utils/queryCategorySamples.js +6 -2
- package/lib/commonjs/utils/queryCategorySamples.js.map +1 -1
- package/lib/commonjs/utils/queryQuantitySamples.js +6 -2
- package/lib/commonjs/utils/queryQuantitySamples.js.map +1 -1
- package/lib/commonjs/utils/querySources.js +19 -0
- package/lib/commonjs/utils/querySources.js.map +1 -0
- package/lib/commonjs/utils/serializeDate.js +1 -1
- package/lib/commonjs/utils/serializeDate.js.map +1 -1
- package/lib/commonjs/utils/serializeDate.test.js +1 -1
- package/lib/commonjs/utils/serializeDate.test.js.map +1 -1
- package/lib/module/hooks/useSources.js +17 -0
- package/lib/module/hooks/useSources.js.map +1 -0
- package/lib/module/index.ios.js +2 -0
- package/lib/module/index.ios.js.map +1 -1
- package/lib/module/index.js +11 -2
- 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.map +1 -1
- package/lib/module/types.js +0 -14
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/deserializeCorrelation.js +2 -2
- package/lib/module/utils/deserializeCorrelation.js.map +1 -1
- package/lib/module/utils/deserializeSample.js +2 -2
- package/lib/module/utils/deserializeSample.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 +1 -1
- package/lib/module/utils/getMostRecentQuantitySample.js.map +1 -1
- package/lib/module/utils/prepareOptions.js +4 -2
- package/lib/module/utils/prepareOptions.js.map +1 -1
- package/lib/module/utils/queryCategorySamples.js +6 -2
- package/lib/module/utils/queryCategorySamples.js.map +1 -1
- package/lib/module/utils/queryQuantitySamples.js +7 -3
- package/lib/module/utils/queryQuantitySamples.js.map +1 -1
- package/lib/module/utils/querySources.js +9 -0
- package/lib/module/utils/querySources.js.map +1 -0
- package/lib/module/utils/serializeDate.js +1 -1
- package/lib/module/utils/serializeDate.js.map +1 -1
- package/lib/module/utils/serializeDate.test.js +1 -1
- package/lib/module/utils/serializeDate.test.js.map +1 -1
- package/lib/typescript/src/hooks/useSources.d.ts +3 -0
- package/lib/typescript/src/index.ios.d.ts +1 -0
- package/lib/typescript/src/native-types.d.ts +22 -2
- package/lib/typescript/src/types.d.ts +1 -0
- package/lib/typescript/src/utils/deserializeSample.d.ts +2 -2
- package/lib/typescript/src/utils/prepareOptions.d.ts +1 -0
- package/lib/typescript/src/utils/queryCategorySamples.d.ts +7 -2
- package/lib/typescript/src/utils/queryQuantitySamples.d.ts +7 -2
- package/lib/typescript/src/utils/querySources.d.ts +4 -0
- package/package.json +2 -1
- package/src/hooks/useSources.ts +28 -0
- package/src/index.ios.tsx +2 -0
- package/src/index.tsx +12 -3
- package/src/jest.setup.ts +1 -0
- package/src/native-types.ts +34 -5
- package/src/types.ts +1 -134
- package/src/utils/deserializeCorrelation.ts +2 -2
- package/src/utils/deserializeSample.ts +2 -2
- package/src/utils/getMostRecentCategorySample.ts +1 -1
- package/src/utils/getMostRecentQuantitySample.ts +1 -1
- package/src/utils/prepareOptions.ts +6 -3
- package/src/utils/queryCategorySamples.ts +15 -4
- package/src/utils/queryQuantitySamples.ts +16 -5
- package/src/utils/querySources.ts +21 -0
- package/src/utils/serializeDate.test.ts +1 -1
- package/src/utils/serializeDate.ts +3 -1
- package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcuserdata/robertherber.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/ReactNativeHealthkit.xcodeproj/xcuserdata/robertherber.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import deserializCategorySample from './deserializeCategorySample'
|
|
2
|
-
import
|
|
2
|
+
import deserializeQuantitySample from './deserializeSample'
|
|
3
3
|
|
|
4
4
|
import type {
|
|
5
5
|
HKCategorySampleRaw, HKCorrelationRaw, HKCorrelationTypeIdentifier, HKQuantitySampleRaw, HKQuantityTypeIdentifier,
|
|
@@ -15,7 +15,7 @@ function deserializeCorrelation<
|
|
|
15
15
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
16
16
|
// @ts-ignore
|
|
17
17
|
if (o.quantity !== undefined) {
|
|
18
|
-
return
|
|
18
|
+
return deserializeQuantitySample(o as HKQuantitySampleRaw<HKQuantityTypeIdentifier>)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
return deserializCategorySample(o as HKCategorySampleRaw)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HKQuantitySampleRaw, HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types'
|
|
2
2
|
import type { HKQuantitySample } from '../types'
|
|
3
3
|
|
|
4
|
-
function
|
|
4
|
+
function deserializeQuantitySample<
|
|
5
5
|
TIdentifier extends HKQuantityTypeIdentifier,
|
|
6
6
|
TUnit extends UnitForIdentifier<TIdentifier>
|
|
7
7
|
>(
|
|
@@ -14,4 +14,4 @@ function deserializeSample<
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export default
|
|
17
|
+
export default deserializeQuantitySample
|
|
@@ -3,12 +3,15 @@ import serializeDate from './serializeDate'
|
|
|
3
3
|
import type { GenericQueryOptions } from '../types'
|
|
4
4
|
|
|
5
5
|
const prepareOptions = (options: GenericQueryOptions) => {
|
|
6
|
-
const limit = !options.limit || options.limit === Infinity
|
|
6
|
+
const limit = !options.limit || options.limit === Infinity
|
|
7
|
+
? 0
|
|
8
|
+
: options.limit
|
|
7
9
|
const ascending = options.ascending ?? limit === 0
|
|
8
|
-
const from = serializeDate(options.from)
|
|
10
|
+
const from = serializeDate(options.from ? options.from : (limit > 0 ? new Date(0) : undefined))
|
|
9
11
|
const to = serializeDate(options.to)
|
|
12
|
+
const anchor = options.anchor ?? ''
|
|
10
13
|
return {
|
|
11
|
-
limit, ascending, from, to,
|
|
14
|
+
limit, ascending, from, to, anchor,
|
|
12
15
|
}
|
|
13
16
|
}
|
|
14
17
|
|
|
@@ -2,28 +2,39 @@ import Native from '../native-types'
|
|
|
2
2
|
import deserializCategorySample from './deserializeCategorySample'
|
|
3
3
|
import prepareOptions from './prepareOptions'
|
|
4
4
|
|
|
5
|
-
import type { HKCategoryTypeIdentifier } from '../native-types'
|
|
5
|
+
import type { HKCategoryTypeIdentifier, DeletedCategorySampleRaw } from '../native-types'
|
|
6
6
|
import type { GenericQueryOptions, HKCategorySample } from '../types'
|
|
7
7
|
|
|
8
|
+
export type QueryCategorySamplesResponse<T extends HKCategoryTypeIdentifier> = {
|
|
9
|
+
readonly samples: readonly HKCategorySample<T>[],
|
|
10
|
+
readonly deletedSamples: readonly DeletedCategorySampleRaw<T>[],
|
|
11
|
+
readonly newAnchor: string
|
|
12
|
+
}
|
|
13
|
+
|
|
8
14
|
export type QueryCategorySamplesFn = <T extends HKCategoryTypeIdentifier>(
|
|
9
15
|
identifier: T,
|
|
10
16
|
options: GenericQueryOptions
|
|
11
|
-
) => Promise<
|
|
17
|
+
) => Promise<QueryCategorySamplesResponse<T>>;
|
|
12
18
|
|
|
13
19
|
const queryCategorySamples: QueryCategorySamplesFn = async (
|
|
14
20
|
identifier,
|
|
15
21
|
options,
|
|
16
22
|
) => {
|
|
17
23
|
const opts = prepareOptions(options)
|
|
18
|
-
const
|
|
24
|
+
const raw = await Native.queryCategorySamples(
|
|
19
25
|
identifier,
|
|
20
26
|
opts.from,
|
|
21
27
|
opts.to,
|
|
22
28
|
opts.limit,
|
|
23
29
|
opts.ascending,
|
|
30
|
+
opts.anchor,
|
|
24
31
|
)
|
|
25
32
|
|
|
26
|
-
return
|
|
33
|
+
return {
|
|
34
|
+
samples: raw.samples.map(deserializCategorySample),
|
|
35
|
+
deletedSamples: raw.deletedSamples,
|
|
36
|
+
newAnchor: raw.newAnchor,
|
|
37
|
+
}
|
|
27
38
|
}
|
|
28
39
|
|
|
29
40
|
export default queryCategorySamples
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import Native from '../native-types'
|
|
2
|
-
import
|
|
2
|
+
import deserializeQuantitySample from './deserializeSample'
|
|
3
3
|
import ensureUnit from './ensureUnit'
|
|
4
4
|
import prepareOptions from './prepareOptions'
|
|
5
5
|
|
|
6
|
-
import type { HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types'
|
|
6
|
+
import type { HKQuantityTypeIdentifier, UnitForIdentifier, DeletedQuantitySampleRaw } from '../native-types'
|
|
7
7
|
import type { GenericQueryOptions, HKQuantitySample } from '../types'
|
|
8
8
|
|
|
9
|
+
export type QueryQuantitySamplesResponse<T extends HKQuantityTypeIdentifier> = {
|
|
10
|
+
readonly samples: readonly HKQuantitySample<T>[],
|
|
11
|
+
readonly deletedSamples: readonly DeletedQuantitySampleRaw<T>[],
|
|
12
|
+
readonly newAnchor: string
|
|
13
|
+
}
|
|
14
|
+
|
|
9
15
|
export type QueryQuantitySamplesFn = <
|
|
10
16
|
TIdentifier extends HKQuantityTypeIdentifier,
|
|
11
17
|
TUnit extends UnitForIdentifier<TIdentifier>
|
|
12
18
|
>(
|
|
13
19
|
identifier: TIdentifier,
|
|
14
20
|
options: GenericQueryOptions & { readonly unit?: TUnit }
|
|
15
|
-
) => Promise<
|
|
21
|
+
) => Promise<QueryQuantitySamplesResponse<TIdentifier>>;
|
|
16
22
|
|
|
17
23
|
const queryQuantitySamples: QueryQuantitySamplesFn = async (
|
|
18
24
|
identifier,
|
|
@@ -21,16 +27,21 @@ const queryQuantitySamples: QueryQuantitySamplesFn = async (
|
|
|
21
27
|
const unit = await ensureUnit(identifier, options.unit)
|
|
22
28
|
const opts = prepareOptions(options)
|
|
23
29
|
|
|
24
|
-
const
|
|
30
|
+
const result = await Native.queryQuantitySamples(
|
|
25
31
|
identifier,
|
|
26
32
|
unit,
|
|
27
33
|
opts.from,
|
|
28
34
|
opts.to,
|
|
29
35
|
opts.limit,
|
|
30
36
|
opts.ascending,
|
|
37
|
+
opts.anchor,
|
|
31
38
|
)
|
|
32
39
|
|
|
33
|
-
return
|
|
40
|
+
return {
|
|
41
|
+
deletedSamples: result.deletedSamples,
|
|
42
|
+
newAnchor: result.newAnchor,
|
|
43
|
+
samples: result.samples.map(deserializeQuantitySample),
|
|
44
|
+
}
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
export default queryQuantitySamples
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Native from '../native-types'
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
HKQuantityTypeIdentifier,
|
|
5
|
+
HKSource,
|
|
6
|
+
HKCategoryTypeIdentifier,
|
|
7
|
+
} from '../native-types'
|
|
8
|
+
|
|
9
|
+
export type QuerySourcesFn = <
|
|
10
|
+
TIdentifier extends HKCategoryTypeIdentifier | HKQuantityTypeIdentifier
|
|
11
|
+
>(
|
|
12
|
+
identifier: TIdentifier
|
|
13
|
+
) => Promise<readonly HKSource[]>;
|
|
14
|
+
|
|
15
|
+
const querySources: QuerySourcesFn = async (identifier) => {
|
|
16
|
+
const quantitySamples = await Native.querySources(identifier)
|
|
17
|
+
|
|
18
|
+
return quantitySamples
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default querySources
|
|
Binary file
|
|
@@ -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>
|