@kingstinct/react-native-healthkit 9.0.8 → 9.0.10

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.
@@ -169,9 +169,9 @@ class QuantityTypeModule: HybridQuantityTypeModuleSpec {
169
169
 
170
170
  let quantityType = try initializeQuantityType(identifier.stringValue)
171
171
  let predicate = try createPredicate(filter: options?.filter)
172
- let unit = HKUnit.init(from: options?.unit ?? "count")
173
172
 
174
173
  return Promise.async {
174
+ let unit = try await getUnitToUse(unitOverride: options?.unit, quantityType: quantityType)
175
175
  return try await withCheckedThrowingContinuation { continuation in
176
176
  let query = HKStatisticsQuery.init(
177
177
  quantityType: quantityType,
@@ -254,7 +254,6 @@ class QuantityTypeModule: HybridQuantityTypeModuleSpec {
254
254
  let quantityType = try initializeQuantityType(identifier.stringValue)
255
255
 
256
256
  let predicate = try createPredicate(filter: options?.filter)
257
- let unit = HKUnit.init(from: options?.unit ?? "count")
258
257
 
259
258
  // Convert the anchor date string to Date
260
259
  let dateFormatter = ISO8601DateFormatter()
@@ -284,6 +283,7 @@ class QuantityTypeModule: HybridQuantityTypeModuleSpec {
284
283
  let opts = buildStatisticsOptions(statistics: statistics)
285
284
 
286
285
  return Promise.async {
286
+ let unit = try await getUnitToUse(unitOverride: options?.unit, quantityType: quantityType)
287
287
  return try await withCheckedThrowingContinuation { continuation in
288
288
  let query = HKStatisticsCollectionQuery.init(
289
289
  quantityType: quantityType,
@@ -306,8 +306,21 @@ class QuantityTypeModule: HybridQuantityTypeModuleSpec {
306
306
 
307
307
  var responseArray: [QueryStatisticsResponse] = []
308
308
 
309
- // todo: handle from/to here?
310
- statistics.enumerateStatistics(from: Date.distantPast, to: Date()) { stats, _ in
309
+ // Limit enumeration to the range in the provided filter if possible
310
+ var enumerateFrom = Date.distantPast
311
+ var enumerateTo = Date()
312
+
313
+ if let filter = options?.filter {
314
+ switch filter {
315
+ case .fourth(let dateFilter):
316
+ enumerateFrom = dateFilter.startDate ?? enumerateFrom
317
+ enumerateTo = dateFilter.endDate ?? enumerateTo
318
+ default:
319
+ break
320
+ }
321
+ }
322
+
323
+ statistics.enumerateStatistics(from: enumerateFrom, to: enumerateTo) { stats, _ in
311
324
  var response = QueryStatisticsResponse()
312
325
 
313
326
  if let averageQuantity = stats.averageQuantity() {
@@ -81,7 +81,7 @@ function queryCategorySamples(_categoryTypeIdentifier) {
81
81
  }
82
82
  return Promise.resolve([]);
83
83
  }
84
- function queryCategorySamplesWithAnchor(_categoryTypeIdentifier) {
84
+ function queryCategorySamplesWithAnchor(_categoryTypeIdentifier, _options) {
85
85
  if (react_native_1.Platform.OS !== 'ios' && !hasWarned) {
86
86
  console.warn(notAvailableError);
87
87
  hasWarned = true;
@@ -59,7 +59,7 @@ export function queryCategorySamples(_categoryTypeIdentifier) {
59
59
  }
60
60
  return Promise.resolve([]);
61
61
  }
62
- export function queryCategorySamplesWithAnchor(_categoryTypeIdentifier) {
62
+ export function queryCategorySamplesWithAnchor(_categoryTypeIdentifier, _options) {
63
63
  if (Platform.OS !== 'ios' && !hasWarned) {
64
64
  console.warn(notAvailableError);
65
65
  hasWarned = true;
@@ -5,6 +5,7 @@ import type { CategorySamplesWithAnchorResponseTyped, CategorySampleTyped } from
5
5
  import type { CategoryTypeIdentifier } from './types/CategoryTypeIdentifier';
6
6
  import { BiologicalSex, BloodType, FitzpatrickSkinType, WheelchairUse } from './types/Characteristics';
7
7
  import type { QuantitySample } from './types/QuantitySample';
8
+ import type { QueryOptionsWithAnchor } from './types/QueryOptions';
8
9
  export * from './types';
9
10
  export declare const authorizationStatusFor: (type: import("./types").ObjectTypeIdentifier) => AuthorizationStatus;
10
11
  export declare const disableAllBackgroundDelivery: () => Promise<boolean>;
@@ -35,12 +36,12 @@ export declare const queryStatisticsCollectionForQuantity: (identifier: import("
35
36
  export declare const saveQuantitySample: (identifier: import("./types").QuantityTypeIdentifier, unit: string, value: number, start: Date, end: Date, metadata: import("react-native-nitro-modules").AnyMap) => Promise<boolean>;
36
37
  export declare const isQuantityCompatibleWithUnit: (identifier: import("./types").QuantityTypeIdentifier, unit: string) => boolean;
37
38
  export declare function queryCategorySamples<T extends CategoryTypeIdentifier>(_categoryTypeIdentifier: T): Promise<CategorySampleTyped<T>[]>;
38
- export declare function queryCategorySamplesWithAnchor<T extends CategoryTypeIdentifier>(_categoryTypeIdentifier: T): Promise<CategorySamplesWithAnchorResponseTyped<T>>;
39
+ export declare function queryCategorySamplesWithAnchor<T extends CategoryTypeIdentifier>(_categoryTypeIdentifier: T, _options: QueryOptionsWithAnchor): Promise<CategorySamplesWithAnchorResponseTyped<T>>;
39
40
  export declare const saveCategorySample: <T extends CategoryTypeIdentifier>(identifier: T, value: import("./types").CategoryValueForIdentifier, startDate: Date, endDate: Date, metadata: import("./types").MetadataForCategoryIdentifier<T>) => Promise<boolean>;
40
41
  export declare const queryCorrelationSamples: (typeIdentifier: import("./types").CorrelationTypeIdentifier, from: Date, to: Date) => Promise<readonly import("./types").CorrelationSample[]>;
41
42
  export declare const saveCorrelationSample: (typeIdentifier: import("./types").CorrelationTypeIdentifier, samples: import("./types").SampleForSaving[], start: Date, end: Date, metadata: import("react-native-nitro-modules").AnyMap) => Promise<boolean>;
42
43
  export declare const queryHeartbeatSeriesSamples: (options?: import("./types").QueryOptionsWithSortOrder) => Promise<readonly import("./types").HeartbeatSeriesSample[]>;
43
- export declare const queryHeartbeatSeriesSamplesWithAnchor: (options: import("./types").QueryOptionsWithAnchor) => Promise<import("./types").HeartbeatSeriesSamplesWithAnchorResponse>;
44
+ export declare const queryHeartbeatSeriesSamplesWithAnchor: (options: QueryOptionsWithAnchor) => Promise<import("./types").HeartbeatSeriesSamplesWithAnchorResponse>;
44
45
  export declare const queryWorkoutSamples: (options: import("./types").WorkoutQueryOptions) => Promise<WorkoutProxy[]>;
45
46
  export declare const queryWorkoutSamplesWithAnchor: (options: import("./types").WorkoutQueryOptionsWithAnchor) => Promise<import("./types").QueryWorkoutSamplesWithAnchorResponse>;
46
47
  export declare const saveWorkoutSample: (workoutActivityType: import("./types").WorkoutActivityType, quantities: readonly import("./types").QuantitySampleForSaving[], startDate: Date, endDate: Date, totals: import("./types").WorkoutTotals, metadata: import("react-native-nitro-modules").AnyMap) => Promise<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kingstinct/react-native-healthkit",
3
- "version": "9.0.8",
3
+ "version": "9.0.10",
4
4
  "description": "React Native bindings for HealthKit",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
package/src/healthkit.ts CHANGED
@@ -21,6 +21,7 @@ import {
21
21
  WheelchairUse,
22
22
  } from './types/Characteristics'
23
23
  import type { QuantitySample } from './types/QuantitySample'
24
+ import type { QueryOptionsWithAnchor } from './types/QueryOptions'
24
25
 
25
26
  export * from './types'
26
27
 
@@ -185,6 +186,7 @@ export function queryCategorySamplesWithAnchor<
185
186
  T extends CategoryTypeIdentifier,
186
187
  >(
187
188
  _categoryTypeIdentifier: T,
189
+ _options: QueryOptionsWithAnchor,
188
190
  ): Promise<CategorySamplesWithAnchorResponseTyped<T>> {
189
191
  if (Platform.OS !== 'ios' && !hasWarned) {
190
192
  console.warn(notAvailableError)