@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.
Files changed (93) hide show
  1. package/README.md +59 -18
  2. package/ios/ReactNativeHealthkit.m +7 -0
  3. package/ios/ReactNativeHealthkit.swift +155 -31
  4. package/lib/commonjs/hooks/useSources.js +28 -0
  5. package/lib/commonjs/hooks/useSources.js.map +1 -0
  6. package/lib/commonjs/index.ios.js +3 -0
  7. package/lib/commonjs/index.ios.js.map +1 -1
  8. package/lib/commonjs/index.js +11 -2
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/jest.setup.js +1 -0
  11. package/lib/commonjs/jest.setup.js.map +1 -1
  12. package/lib/commonjs/native-types.js.map +1 -1
  13. package/lib/commonjs/types.js.map +1 -1
  14. package/lib/commonjs/utils/deserializeCorrelation.js.map +1 -1
  15. package/lib/commonjs/utils/deserializeSample.js +2 -2
  16. package/lib/commonjs/utils/deserializeSample.js.map +1 -1
  17. package/lib/commonjs/utils/getMostRecentCategorySample.js +1 -1
  18. package/lib/commonjs/utils/getMostRecentCategorySample.js.map +1 -1
  19. package/lib/commonjs/utils/getMostRecentQuantitySample.js +1 -1
  20. package/lib/commonjs/utils/getMostRecentQuantitySample.js.map +1 -1
  21. package/lib/commonjs/utils/prepareOptions.js +4 -2
  22. package/lib/commonjs/utils/prepareOptions.js.map +1 -1
  23. package/lib/commonjs/utils/queryCategorySamples.js +6 -2
  24. package/lib/commonjs/utils/queryCategorySamples.js.map +1 -1
  25. package/lib/commonjs/utils/queryQuantitySamples.js +6 -2
  26. package/lib/commonjs/utils/queryQuantitySamples.js.map +1 -1
  27. package/lib/commonjs/utils/querySources.js +19 -0
  28. package/lib/commonjs/utils/querySources.js.map +1 -0
  29. package/lib/commonjs/utils/serializeDate.js +1 -1
  30. package/lib/commonjs/utils/serializeDate.js.map +1 -1
  31. package/lib/commonjs/utils/serializeDate.test.js +1 -1
  32. package/lib/commonjs/utils/serializeDate.test.js.map +1 -1
  33. package/lib/module/hooks/useSources.js +17 -0
  34. package/lib/module/hooks/useSources.js.map +1 -0
  35. package/lib/module/index.ios.js +2 -0
  36. package/lib/module/index.ios.js.map +1 -1
  37. package/lib/module/index.js +11 -2
  38. package/lib/module/index.js.map +1 -1
  39. package/lib/module/jest.setup.js +1 -0
  40. package/lib/module/jest.setup.js.map +1 -1
  41. package/lib/module/native-types.js.map +1 -1
  42. package/lib/module/types.js +0 -14
  43. package/lib/module/types.js.map +1 -1
  44. package/lib/module/utils/deserializeCorrelation.js +2 -2
  45. package/lib/module/utils/deserializeCorrelation.js.map +1 -1
  46. package/lib/module/utils/deserializeSample.js +2 -2
  47. package/lib/module/utils/deserializeSample.js.map +1 -1
  48. package/lib/module/utils/getMostRecentCategorySample.js +1 -1
  49. package/lib/module/utils/getMostRecentCategorySample.js.map +1 -1
  50. package/lib/module/utils/getMostRecentQuantitySample.js +1 -1
  51. package/lib/module/utils/getMostRecentQuantitySample.js.map +1 -1
  52. package/lib/module/utils/prepareOptions.js +4 -2
  53. package/lib/module/utils/prepareOptions.js.map +1 -1
  54. package/lib/module/utils/queryCategorySamples.js +6 -2
  55. package/lib/module/utils/queryCategorySamples.js.map +1 -1
  56. package/lib/module/utils/queryQuantitySamples.js +7 -3
  57. package/lib/module/utils/queryQuantitySamples.js.map +1 -1
  58. package/lib/module/utils/querySources.js +9 -0
  59. package/lib/module/utils/querySources.js.map +1 -0
  60. package/lib/module/utils/serializeDate.js +1 -1
  61. package/lib/module/utils/serializeDate.js.map +1 -1
  62. package/lib/module/utils/serializeDate.test.js +1 -1
  63. package/lib/module/utils/serializeDate.test.js.map +1 -1
  64. package/lib/typescript/src/hooks/useSources.d.ts +3 -0
  65. package/lib/typescript/src/index.ios.d.ts +1 -0
  66. package/lib/typescript/src/native-types.d.ts +22 -2
  67. package/lib/typescript/src/types.d.ts +1 -0
  68. package/lib/typescript/src/utils/deserializeSample.d.ts +2 -2
  69. package/lib/typescript/src/utils/prepareOptions.d.ts +1 -0
  70. package/lib/typescript/src/utils/queryCategorySamples.d.ts +7 -2
  71. package/lib/typescript/src/utils/queryQuantitySamples.d.ts +7 -2
  72. package/lib/typescript/src/utils/querySources.d.ts +4 -0
  73. package/package.json +2 -1
  74. package/src/hooks/useSources.ts +28 -0
  75. package/src/index.ios.tsx +2 -0
  76. package/src/index.tsx +12 -3
  77. package/src/jest.setup.ts +1 -0
  78. package/src/native-types.ts +34 -5
  79. package/src/types.ts +1 -134
  80. package/src/utils/deserializeCorrelation.ts +2 -2
  81. package/src/utils/deserializeSample.ts +2 -2
  82. package/src/utils/getMostRecentCategorySample.ts +1 -1
  83. package/src/utils/getMostRecentQuantitySample.ts +1 -1
  84. package/src/utils/prepareOptions.ts +6 -3
  85. package/src/utils/queryCategorySamples.ts +15 -4
  86. package/src/utils/queryQuantitySamples.ts +16 -5
  87. package/src/utils/querySources.ts +21 -0
  88. package/src/utils/serializeDate.test.ts +1 -1
  89. package/src/utils/serializeDate.ts +3 -1
  90. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  91. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  92. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcuserdata/robertherber.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  93. package/ios/ReactNativeHealthkit.xcodeproj/xcuserdata/robertherber.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
@@ -1,5 +1,5 @@
1
1
  import deserializCategorySample from './deserializeCategorySample'
2
- import deserializeSample from './deserializeSample'
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 deserializeSample(o as HKQuantitySampleRaw<HKQuantityTypeIdentifier>)
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 deserializeSample<
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 deserializeSample
17
+ export default deserializeQuantitySample
@@ -12,7 +12,7 @@ async function getMostRecentCategorySample<
12
12
  ascending: false,
13
13
  })
14
14
 
15
- return samples[0] || null
15
+ return samples.samples[0] || null
16
16
  }
17
17
 
18
18
  export default getMostRecentCategorySample
@@ -13,7 +13,7 @@ async function getMostRecentQuantitySample<
13
13
  limit: 1,
14
14
  unit,
15
15
  })
16
- return samples[0] || null
16
+ return samples.samples[0] || null
17
17
  }
18
18
 
19
19
  export default getMostRecentQuantitySample
@@ -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 ? 0 : options.limit
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<readonly HKCategorySample<T>[]>;
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 results = await Native.queryCategorySamples(
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 results.map(deserializCategorySample)
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 deserializeSample from './deserializeSample'
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<readonly HKQuantitySample<TIdentifier>[]>;
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 quantitySamples = await Native.queryQuantitySamples(
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 quantitySamples.map(deserializeSample)
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
@@ -11,6 +11,6 @@ describe('serializeDate', () => {
11
11
  })
12
12
 
13
13
  it('should serialize null date', () => {
14
- expect(serializeDate(null)).toBe('1970-01-01T00:00:00.000Z')
14
+ expect(serializeDate(null)).toBe('1969-12-31T23:59:59.999Z')
15
15
  })
16
16
  })
@@ -1,3 +1,5 @@
1
- const serializeDate = (date?: Date | null): string => (date ? date.toISOString() : new Date(0).toISOString())
1
+ const serializeDate = (date?: Date | null): string => (
2
+ (date || new Date(-1)).toISOString()
3
+ )
2
4
 
3
5
  export default serializeDate
@@ -1,7 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <Workspace
3
- version = "1.0">
4
- <FileRef
5
- location = "self:">
6
- </FileRef>
7
- </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>