@kingstinct/react-native-healthkit 7.1.0 → 7.2.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 (47) hide show
  1. package/ios/Helpers.swift +6 -0
  2. package/ios/ReactNativeHealthkit.m +6 -0
  3. package/ios/ReactNativeHealthkit.swift +143 -62
  4. package/lib/commonjs/index.ios.js +2 -0
  5. package/lib/commonjs/index.ios.js.map +1 -1
  6. package/lib/commonjs/index.js +2 -1
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/commonjs/jest.setup.js +2 -1
  9. package/lib/commonjs/jest.setup.js.map +1 -1
  10. package/lib/commonjs/native-types.js.map +1 -1
  11. package/lib/commonjs/types.js.map +1 -1
  12. package/lib/commonjs/utils/saveCorrelationSample.js +20 -4
  13. package/lib/commonjs/utils/saveCorrelationSample.js.map +1 -1
  14. package/lib/commonjs/utils/saveWorkoutRoute.js +27 -0
  15. package/lib/commonjs/utils/saveWorkoutRoute.js.map +1 -0
  16. package/lib/commonjs/utils/saveWorkoutSample.js +20 -4
  17. package/lib/commonjs/utils/saveWorkoutSample.js.map +1 -1
  18. package/lib/module/index.ios.js +2 -0
  19. package/lib/module/index.ios.js.map +1 -1
  20. package/lib/module/index.js +2 -1
  21. package/lib/module/index.js.map +1 -1
  22. package/lib/module/jest.setup.js +2 -1
  23. package/lib/module/jest.setup.js.map +1 -1
  24. package/lib/module/native-types.js.map +1 -1
  25. package/lib/module/types.js +5 -0
  26. package/lib/module/types.js.map +1 -1
  27. package/lib/module/utils/saveCorrelationSample.js +20 -4
  28. package/lib/module/utils/saveCorrelationSample.js.map +1 -1
  29. package/lib/module/utils/saveWorkoutRoute.js +19 -0
  30. package/lib/module/utils/saveWorkoutRoute.js.map +1 -0
  31. package/lib/module/utils/saveWorkoutSample.js +20 -4
  32. package/lib/module/utils/saveWorkoutSample.js.map +1 -1
  33. package/lib/typescript/src/index.d.ts +1 -0
  34. package/lib/typescript/src/index.ios.d.ts +2 -0
  35. package/lib/typescript/src/native-types.d.ts +21 -4
  36. package/lib/typescript/src/types.d.ts +16 -3
  37. package/lib/typescript/src/utils/saveWorkoutRoute.d.ts +3 -0
  38. package/lib/typescript/src/utils/saveWorkoutSample.d.ts +1 -1
  39. package/package.json +1 -1
  40. package/src/index.ios.tsx +2 -0
  41. package/src/index.tsx +2 -1
  42. package/src/jest.setup.ts +1 -0
  43. package/src/native-types.ts +25 -8
  44. package/src/types.ts +17 -2
  45. package/src/utils/saveCorrelationSample.ts +10 -1
  46. package/src/utils/saveWorkoutRoute.ts +21 -0
  47. package/src/utils/saveWorkoutSample.ts +9 -1
@@ -0,0 +1,19 @@
1
+ import Native from '../native-types';
2
+ async function saveWorkoutRoute(workoutUUID, locations) {
3
+ return Native.saveWorkoutRoute(workoutUUID, locations.map(location => {
4
+ const {
5
+ timestamp,
6
+ ...rest
7
+ } = location;
8
+ return {
9
+ ...rest,
10
+ ...(timestamp ? {
11
+ timestamp: new Date(timestamp).toISOString()
12
+ } : {
13
+ timestamp: ''
14
+ })
15
+ };
16
+ }));
17
+ }
18
+ export default saveWorkoutRoute;
19
+ //# sourceMappingURL=saveWorkoutRoute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Native","saveWorkoutRoute","workoutUUID","locations","map","location","timestamp","rest","Date","toISOString"],"sources":["saveWorkoutRoute.ts"],"sourcesContent":["import Native from '../native-types'\n\nimport type { CLLocationForSaving } from '../types'\n\nasync function saveWorkoutRoute(\n workoutUUID: string,\n locations: readonly CLLocationForSaving[],\n) {\n return Native.saveWorkoutRoute(\n workoutUUID,\n locations.map((location) => {\n const { timestamp, ...rest } = location\n return {\n ...rest,\n ...(timestamp ? { timestamp: new Date(timestamp).toISOString() } : { timestamp: '' }),\n }\n }),\n )\n}\n\nexport default saveWorkoutRoute\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,iBAAiB;AAIpC,eAAeC,gBAAgBA,CAC7BC,WAAmB,EACnBC,SAAyC,EACzC;EACA,OAAOH,MAAM,CAACC,gBAAgB,CAC5BC,WAAW,EACXC,SAAS,CAACC,GAAG,CAAEC,QAAQ,IAAK;IAC1B,MAAM;MAAEC,SAAS;MAAE,GAAGC;IAAK,CAAC,GAAGF,QAAQ;IACvC,OAAO;MACL,GAAGE,IAAI;MACP,IAAID,SAAS,GAAG;QAAEA,SAAS,EAAE,IAAIE,IAAI,CAACF,SAAS,CAAC,CAACG,WAAW,CAAC;MAAE,CAAC,GAAG;QAAEH,SAAS,EAAE;MAAG,CAAC;IACtF,CAAC;EACH,CAAC,CACH,CAAC;AACH;AAEA,eAAeL,gBAAgB"}
@@ -3,10 +3,26 @@ import Native from '../native-types';
3
3
  async function saveWorkoutSample(typeIdentifier, quantities, _start, options) {
4
4
  const start = _start.toISOString();
5
5
  const end = ((options === null || options === void 0 ? void 0 : options.end) || new Date()).toISOString();
6
- return Native.saveWorkoutSample(typeIdentifier, quantities.map(s => ({
7
- ...s,
8
- metadata: ensureMetadata(s.metadata)
9
- })), start, end, ensureMetadata(options === null || options === void 0 ? void 0 : options.metadata));
6
+ return Native.saveWorkoutSample(typeIdentifier, quantities.map(quantity => {
7
+ const {
8
+ startDate,
9
+ endDate,
10
+ ...rest
11
+ } = quantity;
12
+ const updatedQuantity = {
13
+ ...rest,
14
+ ...(startDate && {
15
+ startDate: startDate.toISOString()
16
+ }),
17
+ ...(endDate && {
18
+ endDate: endDate.toISOString()
19
+ })
20
+ };
21
+ return {
22
+ ...updatedQuantity,
23
+ metadata: ensureMetadata(quantity.metadata)
24
+ };
25
+ }), start, end, ensureMetadata(options === null || options === void 0 ? void 0 : options.metadata));
10
26
  }
11
27
  export default saveWorkoutSample;
12
28
  //# sourceMappingURL=saveWorkoutSample.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ensureMetadata","Native","saveWorkoutSample","typeIdentifier","quantities","_start","options","start","toISOString","end","Date","map","s","metadata"],"sources":["saveWorkoutSample.ts"],"sourcesContent":["import ensureMetadata from './ensureMetadata'\nimport Native from '../native-types'\n\nimport type { HKWorkoutActivityType, HKWorkoutMetadata } from '../native-types'\nimport type { HKQuantitySampleForSaving } from '../types'\n\nasync function saveWorkoutSample<TIdentifier extends HKWorkoutActivityType>(\n typeIdentifier: TIdentifier,\n quantities: readonly HKQuantitySampleForSaving[],\n _start: Date,\n options?: {\n readonly end?: Date;\n readonly metadata?: HKWorkoutMetadata;\n },\n) {\n const start = _start.toISOString()\n const end = (options?.end || new Date()).toISOString()\n\n return Native.saveWorkoutSample(\n typeIdentifier,\n quantities.map(((s) => ({ ...s, metadata: ensureMetadata(s.metadata) }))),\n start,\n end,\n ensureMetadata(options?.metadata),\n )\n}\n\nexport default saveWorkoutSample\n"],"mappings":"AAAA,OAAOA,cAAc,MAAM,kBAAkB;AAC7C,OAAOC,MAAM,MAAM,iBAAiB;AAKpC,eAAeC,iBAAiBA,CAC9BC,cAA2B,EAC3BC,UAAgD,EAChDC,MAAY,EACZC,OAGC,EACD;EACA,MAAMC,KAAK,GAAGF,MAAM,CAACG,WAAW,CAAC,CAAC;EAClC,MAAMC,GAAG,GAAG,CAAC,CAAAH,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEG,GAAG,KAAI,IAAIC,IAAI,CAAC,CAAC,EAAEF,WAAW,CAAC,CAAC;EAEtD,OAAOP,MAAM,CAACC,iBAAiB,CAC7BC,cAAc,EACdC,UAAU,CAACO,GAAG,CAAGC,CAAC,KAAM;IAAE,GAAGA,CAAC;IAAEC,QAAQ,EAAEb,cAAc,CAACY,CAAC,CAACC,QAAQ;EAAE,CAAC,CAAE,CAAC,EACzEN,KAAK,EACLE,GAAG,EACHT,cAAc,CAACM,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEO,QAAQ,CAClC,CAAC;AACH;AAEA,eAAeX,iBAAiB"}
1
+ {"version":3,"names":["ensureMetadata","Native","saveWorkoutSample","typeIdentifier","quantities","_start","options","start","toISOString","end","Date","map","quantity","startDate","endDate","rest","updatedQuantity","metadata"],"sources":["saveWorkoutSample.ts"],"sourcesContent":["import ensureMetadata from './ensureMetadata'\nimport Native from '../native-types'\n\nimport type { HKWorkoutActivityType, HKWorkoutMetadata } from '../native-types'\nimport type { HKQuantitySampleForSaving } from '../types'\n\nasync function saveWorkoutSample<TIdentifier extends HKWorkoutActivityType>(\n typeIdentifier: TIdentifier,\n quantities: readonly HKQuantitySampleForSaving[],\n _start: Date,\n options?: {\n readonly end?: Date;\n readonly metadata?: HKWorkoutMetadata;\n },\n) {\n const start = _start.toISOString()\n const end = (options?.end || new Date()).toISOString()\n\n return Native.saveWorkoutSample(\n typeIdentifier,\n quantities.map((quantity) => {\n const { startDate, endDate, ...rest } = quantity\n const updatedQuantity = {\n ...rest,\n ...(startDate && { startDate: startDate.toISOString() }),\n ...(endDate && { endDate: endDate.toISOString() }),\n }\n return { ...updatedQuantity, metadata: ensureMetadata(quantity.metadata) }\n }),\n start,\n end,\n ensureMetadata(options?.metadata),\n )\n}\n\nexport default saveWorkoutSample\n"],"mappings":"AAAA,OAAOA,cAAc,MAAM,kBAAkB;AAC7C,OAAOC,MAAM,MAAM,iBAAiB;AAKpC,eAAeC,iBAAiBA,CAC9BC,cAA2B,EAC3BC,UAAgD,EAChDC,MAAY,EACZC,OAGC,EACD;EACA,MAAMC,KAAK,GAAGF,MAAM,CAACG,WAAW,CAAC,CAAC;EAClC,MAAMC,GAAG,GAAG,CAAC,CAAAH,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEG,GAAG,KAAI,IAAIC,IAAI,CAAC,CAAC,EAAEF,WAAW,CAAC,CAAC;EAEtD,OAAOP,MAAM,CAACC,iBAAiB,CAC7BC,cAAc,EACdC,UAAU,CAACO,GAAG,CAAEC,QAAQ,IAAK;IAC3B,MAAM;MAAEC,SAAS;MAAEC,OAAO;MAAE,GAAGC;IAAK,CAAC,GAAGH,QAAQ;IAChD,MAAMI,eAAe,GAAG;MACtB,GAAGD,IAAI;MACP,IAAIF,SAAS,IAAI;QAAEA,SAAS,EAAEA,SAAS,CAACL,WAAW,CAAC;MAAE,CAAC,CAAC;MACxD,IAAIM,OAAO,IAAI;QAAEA,OAAO,EAAEA,OAAO,CAACN,WAAW,CAAC;MAAE,CAAC;IACnD,CAAC;IACD,OAAO;MAAE,GAAGQ,eAAe;MAAEC,QAAQ,EAAEjB,cAAc,CAACY,QAAQ,CAACK,QAAQ;IAAE,CAAC;EAC5E,CAAC,CAAC,EACFV,KAAK,EACLE,GAAG,EACHT,cAAc,CAACM,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEW,QAAQ,CAClC,CAAC;AACH;AAEA,eAAef,iBAAiB"}
@@ -40,6 +40,7 @@ declare const _default: {
40
40
  saveCorrelationSample: typeof import("./utils/saveCorrelationSample").default;
41
41
  saveQuantitySample: typeof import("./utils/saveQuantitySample").default;
42
42
  saveWorkoutSample: typeof import("./utils/saveWorkoutSample").default;
43
+ saveWorkoutRoute: typeof import("./utils/saveWorkoutRoute").default;
43
44
  subscribeToChanges: (identifier: import("./native-types").HKSampleTypeIdentifier, callback: () => void) => Promise<() => Promise<boolean>>;
44
45
  useMostRecentCategorySample: typeof import("./hooks/useMostRecentCategorySample").default;
45
46
  useMostRecentQuantitySample: typeof import("./hooks/useMostRecentQuantitySample").default;
@@ -10,6 +10,7 @@ import queryWorkouts from './utils/queryWorkouts';
10
10
  import saveCategorySample from './utils/saveCategorySample';
11
11
  import saveCorrelationSample from './utils/saveCorrelationSample';
12
12
  import saveQuantitySample from './utils/saveQuantitySample';
13
+ import saveWorkoutRoute from './utils/saveWorkoutRoute';
13
14
  import saveWorkoutSample from './utils/saveWorkoutSample';
14
15
  /**
15
16
  * @see {@link https://developer.apple.com/documentation/healthkit/about_the_healthkit_framework About the HealthKit Framework (Apple Docs)}
@@ -108,6 +109,7 @@ declare const _default: {
108
109
  saveCorrelationSample: typeof saveCorrelationSample;
109
110
  saveQuantitySample: typeof saveQuantitySample;
110
111
  saveWorkoutSample: typeof saveWorkoutSample;
112
+ saveWorkoutRoute: typeof saveWorkoutRoute;
111
113
  subscribeToChanges: (identifier: import("./native-types").HKSampleTypeIdentifier, callback: () => void) => Promise<() => Promise<boolean>>;
112
114
  /**
113
115
  * @returns the most recent sample for the given category type.
@@ -1030,7 +1030,7 @@ export type MetadataMapperForQuantityIdentifier<TQuantityTypeIdentifier = HKQuan
1030
1030
  export type MetadataMapperForCorrelationIdentifier<TCorrelationTypeIdentifier = HKCorrelationTypeIdentifier> = TCorrelationTypeIdentifier extends HKCorrelationTypeIdentifier.food ? HKGenericMetadata & {
1031
1031
  readonly HKFoodType?: string;
1032
1032
  } : HKGenericMetadata;
1033
- export type UnitForIdentifier<T extends HKQuantityTypeIdentifier> = T extends HKQuantityTypeIdentifier.bloodGlucose ? BloodGlucoseUnit : T extends HKQuantityTypeIdentifier.appleExerciseTime | HKQuantityTypeIdentifier.appleMoveTime | HKQuantityTypeIdentifier.appleStandTime ? TimeUnit : T extends HKQuantityTypeIdentifier.activeEnergyBurned | HKQuantityTypeIdentifier.basalEnergyBurned | HKQuantityTypeIdentifier.dietaryEnergyConsumed ? EnergyUnit : T extends HKQuantityTypeIdentifier.distanceCycling | HKQuantityTypeIdentifier.distanceDownhillSnowSports | HKQuantityTypeIdentifier.distanceSwimming | HKQuantityTypeIdentifier.distanceWalkingRunning | HKQuantityTypeIdentifier.distanceWheelchair | HKQuantityTypeIdentifier.sixMinuteWalkTestDistance | HKQuantityTypeIdentifier.waistCircumference ? LengthUnit : T extends HKQuantityTypeIdentifier.bodyFatPercentage | HKQuantityTypeIdentifier.oxygenSaturation | HKQuantityTypeIdentifier.walkingAsymmetryPercentage | HKQuantityTypeIdentifier.walkingDoubleSupportPercentage ? HKUnits.Percent : T extends HKQuantityTypeIdentifier.basalBodyTemperature | HKQuantityTypeIdentifier.basalBodyTemperature ? TemperatureUnit : T extends HKQuantityTypeIdentifier.stairAscentSpeed | HKQuantityTypeIdentifier.stairDescentSpeed | HKQuantityTypeIdentifier.walkingSpeed | HKQuantityTypeIdentifier.walkingSpeed ? SpeedUnit<LengthUnit, TimeUnit> : T extends HKQuantityTypeIdentifier.flightsClimbed | HKQuantityTypeIdentifier.numberOfAlcoholicBeverages | HKQuantityTypeIdentifier.numberOfTimesFallen | HKQuantityTypeIdentifier.pushCount | HKQuantityTypeIdentifier.stepCount | HKQuantityTypeIdentifier.swimmingStrokeCount ? HKUnits.Count : T extends HKQuantityTypeIdentifier.dietaryBiotin | HKQuantityTypeIdentifier.dietaryCaffeine | HKQuantityTypeIdentifier.dietaryCalcium | HKQuantityTypeIdentifier.dietaryCarbohydrates | HKQuantityTypeIdentifier.dietaryChloride | HKQuantityTypeIdentifier.dietaryCholesterol | HKQuantityTypeIdentifier.dietaryChromium | HKQuantityTypeIdentifier.dietaryCopper | HKQuantityTypeIdentifier.dietaryFatMonounsaturated | HKQuantityTypeIdentifier.dietaryFatPolyunsaturated | HKQuantityTypeIdentifier.dietaryFatSaturated | HKQuantityTypeIdentifier.dietaryFatTotal | HKQuantityTypeIdentifier.dietaryFiber | HKQuantityTypeIdentifier.dietaryFolate | HKQuantityTypeIdentifier.dietaryIodine | HKQuantityTypeIdentifier.dietaryIodine | HKQuantityTypeIdentifier.dietaryIron | HKQuantityTypeIdentifier.dietaryMagnesium | HKQuantityTypeIdentifier.dietaryManganese | HKQuantityTypeIdentifier.dietaryMolybdenum | HKQuantityTypeIdentifier.dietaryNiacin | HKQuantityTypeIdentifier.dietaryPantothenicAcid | HKQuantityTypeIdentifier.dietaryPhosphorus | HKQuantityTypeIdentifier.dietaryPotassium | HKQuantityTypeIdentifier.dietaryProtein | HKQuantityTypeIdentifier.dietaryRiboflavin | HKQuantityTypeIdentifier.dietarySelenium | HKQuantityTypeIdentifier.dietarySodium | HKQuantityTypeIdentifier.dietarySugar | HKQuantityTypeIdentifier.dietaryThiamin | HKQuantityTypeIdentifier.dietaryVitaminA | HKQuantityTypeIdentifier.dietaryVitaminB6 | HKQuantityTypeIdentifier.dietaryVitaminB12 | HKQuantityTypeIdentifier.dietaryVitaminC | HKQuantityTypeIdentifier.dietaryVitaminD | HKQuantityTypeIdentifier.dietaryVitaminE | HKQuantityTypeIdentifier.dietaryVitaminK | HKQuantityTypeIdentifier.dietaryZinc ? MassUnit : T extends HKQuantityTypeIdentifier.dietaryWater ? VolumeUnit : T extends HKQuantityTypeIdentifier.insulinDelivery ? HKUnits.InternationalUnit | `${HKUnits.InternationalUnit}` : T extends HKQuantityTypeIdentifier.heartRate | HKQuantityTypeIdentifier.restingHeartRate | HKQuantityTypeIdentifier.walkingHeartRateAverage ? CountPerTime<TimeUnit> : HKUnit;
1033
+ export type UnitForIdentifier<T extends HKQuantityTypeIdentifier> = T extends HKQuantityTypeIdentifier.bloodGlucose ? BloodGlucoseUnit : T extends HKQuantityTypeIdentifier.appleExerciseTime | HKQuantityTypeIdentifier.appleMoveTime | HKQuantityTypeIdentifier.appleStandTime ? TimeUnit : T extends HKQuantityTypeIdentifier.activeEnergyBurned | HKQuantityTypeIdentifier.basalEnergyBurned | HKQuantityTypeIdentifier.dietaryEnergyConsumed ? EnergyUnit : T extends HKQuantityTypeIdentifier.distanceCycling | HKQuantityTypeIdentifier.distanceDownhillSnowSports | HKQuantityTypeIdentifier.distanceSwimming | HKQuantityTypeIdentifier.distanceWalkingRunning | HKQuantityTypeIdentifier.distanceWheelchair | HKQuantityTypeIdentifier.sixMinuteWalkTestDistance | HKQuantityTypeIdentifier.waistCircumference ? LengthUnit : T extends HKQuantityTypeIdentifier.bodyFatPercentage | HKQuantityTypeIdentifier.oxygenSaturation | HKQuantityTypeIdentifier.walkingAsymmetryPercentage | HKQuantityTypeIdentifier.walkingDoubleSupportPercentage ? HKUnits.Percent : T extends HKQuantityTypeIdentifier.basalBodyTemperature | HKQuantityTypeIdentifier.basalBodyTemperature ? TemperatureUnit : T extends HKQuantityTypeIdentifier.runningSpeed | HKQuantityTypeIdentifier.stairAscentSpeed | HKQuantityTypeIdentifier.stairDescentSpeed | HKQuantityTypeIdentifier.walkingSpeed | HKQuantityTypeIdentifier.walkingSpeed ? SpeedUnit<LengthUnit, TimeUnit> : T extends HKQuantityTypeIdentifier.flightsClimbed | HKQuantityTypeIdentifier.numberOfAlcoholicBeverages | HKQuantityTypeIdentifier.numberOfTimesFallen | HKQuantityTypeIdentifier.pushCount | HKQuantityTypeIdentifier.stepCount | HKQuantityTypeIdentifier.swimmingStrokeCount ? HKUnits.Count : T extends HKQuantityTypeIdentifier.dietaryBiotin | HKQuantityTypeIdentifier.dietaryCaffeine | HKQuantityTypeIdentifier.dietaryCalcium | HKQuantityTypeIdentifier.dietaryCarbohydrates | HKQuantityTypeIdentifier.dietaryChloride | HKQuantityTypeIdentifier.dietaryCholesterol | HKQuantityTypeIdentifier.dietaryChromium | HKQuantityTypeIdentifier.dietaryCopper | HKQuantityTypeIdentifier.dietaryFatMonounsaturated | HKQuantityTypeIdentifier.dietaryFatPolyunsaturated | HKQuantityTypeIdentifier.dietaryFatSaturated | HKQuantityTypeIdentifier.dietaryFatTotal | HKQuantityTypeIdentifier.dietaryFiber | HKQuantityTypeIdentifier.dietaryFolate | HKQuantityTypeIdentifier.dietaryIodine | HKQuantityTypeIdentifier.dietaryIodine | HKQuantityTypeIdentifier.dietaryIron | HKQuantityTypeIdentifier.dietaryMagnesium | HKQuantityTypeIdentifier.dietaryManganese | HKQuantityTypeIdentifier.dietaryMolybdenum | HKQuantityTypeIdentifier.dietaryNiacin | HKQuantityTypeIdentifier.dietaryPantothenicAcid | HKQuantityTypeIdentifier.dietaryPhosphorus | HKQuantityTypeIdentifier.dietaryPotassium | HKQuantityTypeIdentifier.dietaryProtein | HKQuantityTypeIdentifier.dietaryRiboflavin | HKQuantityTypeIdentifier.dietarySelenium | HKQuantityTypeIdentifier.dietarySodium | HKQuantityTypeIdentifier.dietarySugar | HKQuantityTypeIdentifier.dietaryThiamin | HKQuantityTypeIdentifier.dietaryVitaminA | HKQuantityTypeIdentifier.dietaryVitaminB6 | HKQuantityTypeIdentifier.dietaryVitaminB12 | HKQuantityTypeIdentifier.dietaryVitaminC | HKQuantityTypeIdentifier.dietaryVitaminD | HKQuantityTypeIdentifier.dietaryVitaminE | HKQuantityTypeIdentifier.dietaryVitaminK | HKQuantityTypeIdentifier.dietaryZinc ? MassUnit : T extends HKQuantityTypeIdentifier.dietaryWater ? VolumeUnit : T extends HKQuantityTypeIdentifier.insulinDelivery ? HKUnits.InternationalUnit | `${HKUnits.InternationalUnit}` : T extends HKQuantityTypeIdentifier.heartRate | HKQuantityTypeIdentifier.restingHeartRate | HKQuantityTypeIdentifier.walkingHeartRateAverage ? CountPerTime<TimeUnit> : HKUnit;
1034
1034
  export type HKCategoryValueForIdentifier<T extends HKCategoryTypeIdentifier> = T extends HKCategoryTypeIdentifier.cervicalMucusQuality ? HKCategoryValueCervicalMucusQuality : T extends HKCategoryTypeIdentifier.menstrualFlow ? HKCategoryValueMenstrualFlow : T extends HKCategoryTypeIdentifier.ovulationTestResult ? HKCategoryValueOvulationTestResult : T extends HKCategoryTypeIdentifier.sleepAnalysis ? HKCategoryValueSleepAnalysis : T extends HKCategoryTypeIdentifier.highHeartRateEvent | HKCategoryTypeIdentifier.intermenstrualBleeding | HKCategoryTypeIdentifier.mindfulSession | HKCategoryTypeIdentifier.sexualActivity ? HKCategoryValueNotApplicable : T extends HKCategoryTypeIdentifier.abdominalCramps | HKCategoryTypeIdentifier.abdominalCramps | HKCategoryTypeIdentifier.acne | HKCategoryTypeIdentifier.bladderIncontinence | HKCategoryTypeIdentifier.bloating | HKCategoryTypeIdentifier.breastPain | HKCategoryTypeIdentifier.chestTightnessOrPain | HKCategoryTypeIdentifier.chills | HKCategoryTypeIdentifier.constipation | HKCategoryTypeIdentifier.coughing | HKCategoryTypeIdentifier.diarrhea | HKCategoryTypeIdentifier.dizziness | HKCategoryTypeIdentifier.drySkin | HKCategoryTypeIdentifier.fainting | HKCategoryTypeIdentifier.fatigue | HKCategoryTypeIdentifier.fever | HKCategoryTypeIdentifier.generalizedBodyAche | HKCategoryTypeIdentifier.hairLoss | HKCategoryTypeIdentifier.headache | HKCategoryTypeIdentifier.heartburn | HKCategoryTypeIdentifier.hotFlashes | HKCategoryTypeIdentifier.lossOfSmell | HKCategoryTypeIdentifier.lossOfTaste | HKCategoryTypeIdentifier.lowerBackPain | HKCategoryTypeIdentifier.memoryLapse | HKCategoryTypeIdentifier.moodChanges | HKCategoryTypeIdentifier.nausea | HKCategoryTypeIdentifier.nightSweats | HKCategoryTypeIdentifier.pelvicPain | HKCategoryTypeIdentifier.rapidPoundingOrFlutteringHeartbeat | HKCategoryTypeIdentifier.runnyNose | HKCategoryTypeIdentifier.shortnessOfBreath | HKCategoryTypeIdentifier.sinusCongestion | HKCategoryTypeIdentifier.skippedHeartbeat | HKCategoryTypeIdentifier.soreThroat | HKCategoryTypeIdentifier.vaginalDryness | HKCategoryTypeIdentifier.vomiting | HKCategoryTypeIdentifier.wheezing ? HKCategoryValueSeverity : T extends HKCategoryTypeIdentifier.appetiteChanges | HKCategoryTypeIdentifier.sleepChanges ? HKCategoryValuePresence : T extends HKCategoryTypeIdentifier.lowCardioFitnessEvent ? HKCategoryValueLowCardioFitnessEvent : T extends HKCategoryTypeIdentifier.pregnancyTestResult ? HKCategoryValuePregnancyTestResult : T extends HKCategoryTypeIdentifier.pregnancyTestResult ? HKCategoryValuePregnancyTestResult : T extends HKCategoryTypeIdentifier.appleStandHour ? HKCategoryValueAppleStandHour : number;
1035
1035
  /**
1036
1036
  * @see {@link https://developer.apple.com/documentation/healthkit/hkcategoryvaluepregnancytestresult Apple Docs }
@@ -1276,8 +1276,24 @@ export type HKHeartbeatSeriesSampleRaw = {
1276
1276
  readonly metadata?: HKHeartbeatSeriesSampleMetadata;
1277
1277
  readonly sourceRevision?: HKSourceRevision;
1278
1278
  };
1279
- export type HKQuantitySampleRawForSaving<TQuantityIdentifier extends HKQuantityTypeIdentifier = HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TQuantityIdentifier> = UnitForIdentifier<TQuantityIdentifier>> = Omit<HKQuantitySampleRaw<TQuantityIdentifier, TUnit>, 'device' | 'endDate' | 'startDate' | 'uuid'>;
1280
- export type HKCategorySampleRawForSaving<TCategory extends HKCategoryTypeIdentifier = HKCategoryTypeIdentifier> = Omit<HKCategorySampleRaw<TCategory>, 'device' | 'endDate' | 'startDate' | 'uuid'>;
1279
+ export type CLLocationRawForSaving = {
1280
+ readonly latitude: number;
1281
+ readonly longitude: number;
1282
+ readonly altitude: number;
1283
+ readonly horizontalAccuracy: number;
1284
+ readonly verticalAccuracy: number;
1285
+ readonly course: number;
1286
+ readonly speed: number;
1287
+ readonly timestamp: string;
1288
+ };
1289
+ export type HKQuantitySampleRawForSaving<TQuantityIdentifier extends HKQuantityTypeIdentifier = HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TQuantityIdentifier> = UnitForIdentifier<TQuantityIdentifier>> = Omit<HKQuantitySampleRaw<TQuantityIdentifier, TUnit>, 'device' | 'endDate' | 'startDate' | 'uuid'> & {
1290
+ readonly startDate?: string;
1291
+ readonly endDate?: string;
1292
+ };
1293
+ export type HKCategorySampleRawForSaving<TCategory extends HKCategoryTypeIdentifier = HKCategoryTypeIdentifier> = Omit<HKCategorySampleRaw<TCategory>, 'device' | 'endDate' | 'startDate' | 'uuid'> & {
1294
+ readonly startDate?: string;
1295
+ readonly endDate?: string;
1296
+ };
1281
1297
  export interface HKWorkoutEvent {
1282
1298
  readonly type: HKWorkoutEventType;
1283
1299
  readonly startDate: string;
@@ -1424,7 +1440,8 @@ type ReactNativeHealthkitTypeNative = {
1424
1440
  */
1425
1441
  readonly disableAllBackgroundDelivery: () => Promise<boolean>;
1426
1442
  readonly saveCorrelationSample: <TIdentifier extends HKCorrelationTypeIdentifier, TSamples extends readonly (HKCategorySampleRawForSaving | HKQuantitySampleRawForSaving)[]>(typeIdentifier: TIdentifier, samples: TSamples, start: string, end: string, metadata: MetadataMapperForCorrelationIdentifier<TIdentifier>) => Promise<boolean>;
1427
- readonly saveWorkoutSample: (typeIdentifier: HKWorkoutActivityType, quantities: readonly HKQuantitySampleRawForSaving[], start: string, end: string, metadata: HKWorkoutMetadata) => Promise<boolean>;
1443
+ readonly saveWorkoutSample: (typeIdentifier: HKWorkoutActivityType, quantities: readonly HKQuantitySampleRawForSaving[], start: string, end: string, metadata: HKWorkoutMetadata) => Promise<string | null>;
1444
+ readonly saveWorkoutRoute: (workoutUUID: string, locations: readonly CLLocationRawForSaving[]) => Promise<boolean>;
1428
1445
  readonly queryCorrelationSamples: <TIdentifier extends HKCorrelationTypeIdentifier>(typeIdentifier: TIdentifier, from: string, to: string) => Promise<readonly HKCorrelationRaw<TIdentifier>[]>;
1429
1446
  subscribeToObserverQuery(identifier: HKSampleTypeIdentifier): Promise<QueryId>;
1430
1447
  unsubscribeQuery(queryId: QueryId): Promise<boolean>;
@@ -1,4 +1,4 @@
1
- import type { EnergyUnit, HKCategorySampleRaw, HKCategoryTypeIdentifier, HKCorrelationRaw, HKCorrelationTypeIdentifier, HKDevice, HKHeartbeatSeriesSampleRaw, HKQuantityTypeIdentifier, HKSourceRevision, HKUnit, HKWorkoutRaw, LengthUnit, MetadataMapperForQuantityIdentifier, QueryStatisticsResponseRaw, UnitForIdentifier } from './native-types';
1
+ import type { CLLocationRawForSaving, EnergyUnit, HKCategorySampleRaw, HKCategoryTypeIdentifier, HKCorrelationRaw, HKCorrelationTypeIdentifier, HKDevice, HKHeartbeatSeriesSampleRaw, HKQuantityTypeIdentifier, HKSourceRevision, HKUnit, HKWorkoutRaw, LengthUnit, MetadataMapperForQuantityIdentifier, QueryStatisticsResponseRaw, UnitForIdentifier } from './native-types';
2
2
  export * from './native-types';
3
3
  /**
4
4
  * Options for querying workouts.
@@ -80,12 +80,18 @@ export interface QueryStatisticsResponse<TIdentifier extends HKQuantityTypeIdent
80
80
  * Represents a category sample for saving.
81
81
  * @see {@link https://developer.apple.com/documentation/healthkit/hkcategorysample Apple Docs HKCategorySample}
82
82
  */
83
- export type HKCategorySampleForSaving = Omit<HKCategorySample, 'device' | 'endDate' | 'startDate' | 'uuid'>;
83
+ export type HKCategorySampleForSaving = Omit<HKCategorySample, 'device' | 'endDate' | 'startDate' | 'uuid'> & {
84
+ readonly startDate?: Date;
85
+ readonly endDate?: Date;
86
+ };
84
87
  /**
85
88
  * Represents a quantity sample for saving.
86
89
  * @see {@link https://developer.apple.com/documentation/healthkit/hkquantitysample Apple Docs HKQuantitySample}
87
90
  */
88
- export type HKQuantitySampleForSaving = Omit<HKQuantitySample, 'device' | 'endDate' | 'startDate' | 'uuid'>;
91
+ export type HKQuantitySampleForSaving = Omit<HKQuantitySample, 'device' | 'endDate' | 'startDate' | 'uuid'> & {
92
+ readonly startDate?: Date;
93
+ readonly endDate?: Date;
94
+ };
89
95
  /**
90
96
  * Represents a correlation.
91
97
  * @template TIdentifier The correlation type identifier.
@@ -96,3 +102,10 @@ export interface HKCorrelation<TIdentifier extends HKCorrelationTypeIdentifier>
96
102
  readonly startDate: Date;
97
103
  readonly endDate: Date;
98
104
  }
105
+ /**
106
+ * Represents a location sample for saving.
107
+ * @see {@link https://developer.apple.com/documentation/corelocation/cllocation Apple Docs CLLocation}
108
+ */
109
+ export type CLLocationForSaving = Omit<CLLocationRawForSaving, 'timestamp'> & {
110
+ readonly timestamp: number;
111
+ };
@@ -0,0 +1,3 @@
1
+ import type { CLLocationForSaving } from '../types';
2
+ declare function saveWorkoutRoute(workoutUUID: string, locations: readonly CLLocationForSaving[]): Promise<boolean>;
3
+ export default saveWorkoutRoute;
@@ -3,5 +3,5 @@ import type { HKQuantitySampleForSaving } from '../types';
3
3
  declare function saveWorkoutSample<TIdentifier extends HKWorkoutActivityType>(typeIdentifier: TIdentifier, quantities: readonly HKQuantitySampleForSaving[], _start: Date, options?: {
4
4
  readonly end?: Date;
5
5
  readonly metadata?: HKWorkoutMetadata;
6
- }): Promise<boolean>;
6
+ }): Promise<string | null>;
7
7
  export default saveWorkoutSample;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kingstinct/react-native-healthkit",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "description": "React Native bindings for HealthKit",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
package/src/index.ios.tsx CHANGED
@@ -30,6 +30,7 @@ import requestAuthorization from './utils/requestAuthorization'
30
30
  import saveCategorySample from './utils/saveCategorySample'
31
31
  import saveCorrelationSample from './utils/saveCorrelationSample'
32
32
  import saveQuantitySample from './utils/saveQuantitySample'
33
+ import saveWorkoutRoute from './utils/saveWorkoutRoute'
33
34
  import saveWorkoutSample from './utils/saveWorkoutSample'
34
35
  import subscribeToChanges from './utils/subscribeToChanges'
35
36
 
@@ -181,6 +182,7 @@ export default {
181
182
  saveCorrelationSample,
182
183
  saveQuantitySample,
183
184
  saveWorkoutSample,
185
+ saveWorkoutRoute,
184
186
 
185
187
  // subscriptions
186
188
  subscribeToChanges,
package/src/index.tsx CHANGED
@@ -80,7 +80,8 @@ const Healthkit = {
80
80
  saveCategorySample: UnavailableFn(Promise.resolve(false)),
81
81
  saveCorrelationSample: UnavailableFn(Promise.resolve(false)),
82
82
  saveQuantitySample: UnavailableFn(Promise.resolve(false)),
83
- saveWorkoutSample: UnavailableFn(Promise.resolve(false)),
83
+ saveWorkoutSample: UnavailableFn(Promise.resolve(null)),
84
+ saveWorkoutRoute: UnavailableFn(Promise.resolve(false)),
84
85
  subscribeToChanges: UnavailableFn(Promise.resolve(async () => Promise.resolve(false))),
85
86
  useMostRecentCategorySample: UnavailableFn(null),
86
87
  useMostRecentQuantitySample: UnavailableFn(null),
package/src/jest.setup.ts CHANGED
@@ -39,6 +39,7 @@ const mockModule: (NativeModule & typeof Native) = {
39
39
  unsubscribeQuery: jest.fn(),
40
40
  // Todo [>8]: Remove to align with Apple function name (isProtectedDataAvailable)
41
41
  canAccessProtectedData: jest.fn(),
42
+ saveWorkoutRoute: jest.fn(),
42
43
  }
43
44
 
44
45
  NativeModules.ReactNativeHealthkit = mockModule
@@ -1233,6 +1233,7 @@ export type UnitForIdentifier<T extends HKQuantityTypeIdentifier> =
1233
1233
  | HKQuantityTypeIdentifier.basalBodyTemperature
1234
1234
  ? TemperatureUnit
1235
1235
  : T extends
1236
+ | HKQuantityTypeIdentifier.runningSpeed
1236
1237
  | HKQuantityTypeIdentifier.stairAscentSpeed
1237
1238
  | HKQuantityTypeIdentifier.stairDescentSpeed
1238
1239
  | HKQuantityTypeIdentifier.walkingSpeed
@@ -1696,20 +1697,31 @@ export type HKHeartbeatSeriesSampleRaw = {
1696
1697
  readonly sourceRevision?: HKSourceRevision;
1697
1698
  }
1698
1699
 
1700
+ export type CLLocationRawForSaving = {
1701
+ readonly latitude: number;
1702
+ readonly longitude: number;
1703
+ readonly altitude: number;
1704
+ readonly horizontalAccuracy: number;
1705
+ readonly verticalAccuracy: number;
1706
+ readonly course: number;
1707
+ readonly speed: number;
1708
+ readonly timestamp: string; // unix timestamp in milliseconds
1709
+ }
1710
+
1699
1711
  export type HKQuantitySampleRawForSaving<
1700
1712
  TQuantityIdentifier extends HKQuantityTypeIdentifier = HKQuantityTypeIdentifier,
1701
1713
  TUnit extends UnitForIdentifier<TQuantityIdentifier> = UnitForIdentifier<TQuantityIdentifier>
1702
- > = Omit<
1703
- HKQuantitySampleRaw<TQuantityIdentifier, TUnit>,
1704
- 'device' | 'endDate' | 'startDate' | 'uuid'
1705
- >;
1714
+ > = Omit<HKQuantitySampleRaw<TQuantityIdentifier, TUnit>, 'device' | 'endDate' | 'startDate' | 'uuid'> & {
1715
+ readonly startDate?: string;
1716
+ readonly endDate?: string;
1717
+ };
1706
1718
 
1707
1719
  export type HKCategorySampleRawForSaving<
1708
1720
  TCategory extends HKCategoryTypeIdentifier = HKCategoryTypeIdentifier
1709
- > = Omit<
1710
- HKCategorySampleRaw<TCategory>,
1711
- 'device' | 'endDate' | 'startDate' | 'uuid'
1712
- >;
1721
+ > = Omit<HKCategorySampleRaw<TCategory>, 'device' | 'endDate' | 'startDate' | 'uuid'> & {
1722
+ readonly startDate?: string;
1723
+ readonly endDate?: string;
1724
+ };
1713
1725
 
1714
1726
  export interface HKWorkoutEvent {
1715
1727
  readonly type: HKWorkoutEventType,
@@ -1921,6 +1933,11 @@ type ReactNativeHealthkitTypeNative = {
1921
1933
  start: string,
1922
1934
  end: string,
1923
1935
  metadata: HKWorkoutMetadata
1936
+ ) => Promise<string | null>;
1937
+
1938
+ readonly saveWorkoutRoute: (
1939
+ workoutUUID: string,
1940
+ locations: readonly CLLocationRawForSaving[],
1924
1941
  ) => Promise<boolean>;
1925
1942
 
1926
1943
  readonly queryCorrelationSamples: <
package/src/types.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ CLLocationRawForSaving,
2
3
  EnergyUnit,
3
4
  HKCategorySampleRaw,
4
5
  HKCategoryTypeIdentifier,
@@ -117,13 +118,19 @@ export interface QueryStatisticsResponse<TIdentifier extends HKQuantityTypeIdent
117
118
  * Represents a category sample for saving.
118
119
  * @see {@link https://developer.apple.com/documentation/healthkit/hkcategorysample Apple Docs HKCategorySample}
119
120
  */
120
- export type HKCategorySampleForSaving = Omit<HKCategorySample, 'device' | 'endDate' | 'startDate' | 'uuid'>
121
+ export type HKCategorySampleForSaving = Omit<HKCategorySample, 'device' | 'endDate' | 'startDate' | 'uuid'> & {
122
+ readonly startDate?: Date;
123
+ readonly endDate?: Date;
124
+ }
121
125
 
122
126
  /**
123
127
  * Represents a quantity sample for saving.
124
128
  * @see {@link https://developer.apple.com/documentation/healthkit/hkquantitysample Apple Docs HKQuantitySample}
125
129
  */
126
- export type HKQuantitySampleForSaving = Omit<HKQuantitySample, 'device' | 'endDate' | 'startDate' | 'uuid'>
130
+ export type HKQuantitySampleForSaving = Omit<HKQuantitySample, 'device' | 'endDate' | 'startDate' | 'uuid'> & {
131
+ readonly startDate?: Date;
132
+ readonly endDate?: Date;
133
+ };
127
134
 
128
135
  /**
129
136
  * Represents a correlation.
@@ -139,3 +146,11 @@ export interface HKCorrelation<TIdentifier extends HKCorrelationTypeIdentifier>
139
146
  readonly startDate: Date;
140
147
  readonly endDate: Date;
141
148
  }
149
+
150
+ /**
151
+ * Represents a location sample for saving.
152
+ * @see {@link https://developer.apple.com/documentation/corelocation/cllocation Apple Docs CLLocation}
153
+ */
154
+ export type CLLocationForSaving = Omit<CLLocationRawForSaving, 'timestamp'> & {
155
+ readonly timestamp: number;
156
+ };
@@ -24,7 +24,16 @@ async function saveCorrelationSample<
24
24
 
25
25
  return Native.saveCorrelationSample(
26
26
  typeIdentifier,
27
- samples.map((s) => ({ ...s, metadata: ensureMetadata(s.metadata) })),
27
+ samples.map((sample) => {
28
+ const { startDate, endDate, ...rest } = sample
29
+ const updatedSample = {
30
+ ...rest,
31
+ ...(startDate && { startDate: new Date(startDate).toISOString() }),
32
+ ...(endDate && { endDate: new Date(endDate).toISOString() }),
33
+ }
34
+
35
+ return { ...updatedSample, metadata: ensureMetadata(sample.metadata) }
36
+ }),
28
37
  start,
29
38
  end,
30
39
  ensureMetadata(options?.metadata),
@@ -0,0 +1,21 @@
1
+ import Native from '../native-types'
2
+
3
+ import type { CLLocationForSaving } from '../types'
4
+
5
+ async function saveWorkoutRoute(
6
+ workoutUUID: string,
7
+ locations: readonly CLLocationForSaving[],
8
+ ) {
9
+ return Native.saveWorkoutRoute(
10
+ workoutUUID,
11
+ locations.map((location) => {
12
+ const { timestamp, ...rest } = location
13
+ return {
14
+ ...rest,
15
+ ...(timestamp ? { timestamp: new Date(timestamp).toISOString() } : { timestamp: '' }),
16
+ }
17
+ }),
18
+ )
19
+ }
20
+
21
+ export default saveWorkoutRoute
@@ -18,7 +18,15 @@ async function saveWorkoutSample<TIdentifier extends HKWorkoutActivityType>(
18
18
 
19
19
  return Native.saveWorkoutSample(
20
20
  typeIdentifier,
21
- quantities.map(((s) => ({ ...s, metadata: ensureMetadata(s.metadata) }))),
21
+ quantities.map((quantity) => {
22
+ const { startDate, endDate, ...rest } = quantity
23
+ const updatedQuantity = {
24
+ ...rest,
25
+ ...(startDate && { startDate: startDate.toISOString() }),
26
+ ...(endDate && { endDate: endDate.toISOString() }),
27
+ }
28
+ return { ...updatedQuantity, metadata: ensureMetadata(quantity.metadata) }
29
+ }),
22
30
  start,
23
31
  end,
24
32
  ensureMetadata(options?.metadata),