@kingstinct/react-native-healthkit 5.4.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 (66) hide show
  1. package/README.md +59 -18
  2. package/ios/ReactNativeHealthkit.m +2 -0
  3. package/ios/ReactNativeHealthkit.swift +121 -40
  4. package/lib/commonjs/index.js +10 -2
  5. package/lib/commonjs/index.js.map +1 -1
  6. package/lib/commonjs/native-types.js.map +1 -1
  7. package/lib/commonjs/types.js.map +1 -1
  8. package/lib/commonjs/utils/deserializeCorrelation.js.map +1 -1
  9. package/lib/commonjs/utils/deserializeSample.js +2 -2
  10. package/lib/commonjs/utils/deserializeSample.js.map +1 -1
  11. package/lib/commonjs/utils/getMostRecentCategorySample.js +1 -1
  12. package/lib/commonjs/utils/getMostRecentCategorySample.js.map +1 -1
  13. package/lib/commonjs/utils/getMostRecentQuantitySample.js +1 -1
  14. package/lib/commonjs/utils/getMostRecentQuantitySample.js.map +1 -1
  15. package/lib/commonjs/utils/prepareOptions.js +4 -2
  16. package/lib/commonjs/utils/prepareOptions.js.map +1 -1
  17. package/lib/commonjs/utils/queryCategorySamples.js +6 -2
  18. package/lib/commonjs/utils/queryCategorySamples.js.map +1 -1
  19. package/lib/commonjs/utils/queryQuantitySamples.js +6 -2
  20. package/lib/commonjs/utils/queryQuantitySamples.js.map +1 -1
  21. package/lib/commonjs/utils/serializeDate.js +1 -1
  22. package/lib/commonjs/utils/serializeDate.js.map +1 -1
  23. package/lib/commonjs/utils/serializeDate.test.js +1 -1
  24. package/lib/commonjs/utils/serializeDate.test.js.map +1 -1
  25. package/lib/module/index.js +10 -2
  26. package/lib/module/index.js.map +1 -1
  27. package/lib/module/native-types.js.map +1 -1
  28. package/lib/module/types.js +0 -14
  29. package/lib/module/types.js.map +1 -1
  30. package/lib/module/utils/deserializeCorrelation.js +2 -2
  31. package/lib/module/utils/deserializeCorrelation.js.map +1 -1
  32. package/lib/module/utils/deserializeSample.js +2 -2
  33. package/lib/module/utils/deserializeSample.js.map +1 -1
  34. package/lib/module/utils/getMostRecentCategorySample.js +1 -1
  35. package/lib/module/utils/getMostRecentCategorySample.js.map +1 -1
  36. package/lib/module/utils/getMostRecentQuantitySample.js +1 -1
  37. package/lib/module/utils/getMostRecentQuantitySample.js.map +1 -1
  38. package/lib/module/utils/prepareOptions.js +4 -2
  39. package/lib/module/utils/prepareOptions.js.map +1 -1
  40. package/lib/module/utils/queryCategorySamples.js +6 -2
  41. package/lib/module/utils/queryCategorySamples.js.map +1 -1
  42. package/lib/module/utils/queryQuantitySamples.js +7 -3
  43. package/lib/module/utils/queryQuantitySamples.js.map +1 -1
  44. package/lib/module/utils/serializeDate.js +1 -1
  45. package/lib/module/utils/serializeDate.js.map +1 -1
  46. package/lib/module/utils/serializeDate.test.js +1 -1
  47. package/lib/module/utils/serializeDate.test.js.map +1 -1
  48. package/lib/typescript/src/native-types.d.ts +21 -2
  49. package/lib/typescript/src/types.d.ts +1 -0
  50. package/lib/typescript/src/utils/deserializeSample.d.ts +2 -2
  51. package/lib/typescript/src/utils/prepareOptions.d.ts +1 -0
  52. package/lib/typescript/src/utils/queryCategorySamples.d.ts +7 -2
  53. package/lib/typescript/src/utils/queryQuantitySamples.d.ts +7 -2
  54. package/package.json +2 -1
  55. package/src/index.tsx +11 -3
  56. package/src/native-types.ts +29 -4
  57. package/src/types.ts +1 -134
  58. package/src/utils/deserializeCorrelation.ts +2 -2
  59. package/src/utils/deserializeSample.ts +2 -2
  60. package/src/utils/getMostRecentCategorySample.ts +1 -1
  61. package/src/utils/getMostRecentQuantitySample.ts +1 -1
  62. package/src/utils/prepareOptions.ts +6 -3
  63. package/src/utils/queryCategorySamples.ts +15 -4
  64. package/src/utils/queryQuantitySamples.ts +16 -5
  65. package/src/utils/serializeDate.test.ts +1 -1
  66. package/src/utils/serializeDate.ts +3 -1
@@ -1,4 +1,4 @@
1
- const serializeDate = date => date ? date.toISOString() : new Date(0).toISOString();
1
+ const serializeDate = date => (date || new Date(-1)).toISOString();
2
2
 
3
3
  export default serializeDate;
4
4
  //# sourceMappingURL=serializeDate.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["serializeDate","date","toISOString","Date"],"sources":["serializeDate.ts"],"sourcesContent":["const serializeDate = (date?: Date | null): string => (date ? date.toISOString() : new Date(0).toISOString())\n\nexport default serializeDate\n"],"mappings":"AAAA,MAAMA,aAAa,GAAIC,IAAD,IAAiCA,IAAI,GAAGA,IAAI,CAACC,WAAL,EAAH,GAAwB,IAAIC,IAAJ,CAAS,CAAT,EAAYD,WAAZ,EAAnF;;AAEA,eAAeF,aAAf"}
1
+ {"version":3,"names":["serializeDate","date","Date","toISOString"],"sources":["serializeDate.ts"],"sourcesContent":["const serializeDate = (date?: Date | null): string => (\n (date || new Date(-1)).toISOString()\n)\n\nexport default serializeDate\n"],"mappings":"AAAA,MAAMA,aAAa,GAAIC,IAAD,IACpB,CAACA,IAAI,IAAI,IAAIC,IAAJ,CAAS,CAAC,CAAV,CAAT,EAAuBC,WAAvB,EADF;;AAIA,eAAeH,aAAf"}
@@ -8,7 +8,7 @@ describe('serializeDate', () => {
8
8
  expect(serializeDate(date)).toBe(date.toISOString());
9
9
  });
10
10
  it('should serialize null date', () => {
11
- expect(serializeDate(null)).toBe('1970-01-01T00:00:00.000Z');
11
+ expect(serializeDate(null)).toBe('1969-12-31T23:59:59.999Z');
12
12
  });
13
13
  });
14
14
  //# sourceMappingURL=serializeDate.test.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["serializeDate","describe","it","expect","Date","toBe","date","toISOString"],"sources":["serializeDate.test.ts"],"sourcesContent":["import serializeDate from './serializeDate'\n\ndescribe('serializeDate', () => {\n it('should serialize zero date', () => {\n expect(serializeDate(new Date(0))).toBe('1970-01-01T00:00:00.000Z')\n })\n\n it('should serialize date', () => {\n const date = new Date()\n expect(serializeDate(date)).toBe(date.toISOString())\n })\n\n it('should serialize null date', () => {\n expect(serializeDate(null)).toBe('1970-01-01T00:00:00.000Z')\n })\n})\n"],"mappings":"AAAA,OAAOA,aAAP,MAA0B,iBAA1B;AAEAC,QAAQ,CAAC,eAAD,EAAkB,MAAM;EAC9BC,EAAE,CAAC,4BAAD,EAA+B,MAAM;IACrCC,MAAM,CAACH,aAAa,CAAC,IAAII,IAAJ,CAAS,CAAT,CAAD,CAAd,CAAN,CAAmCC,IAAnC,CAAwC,0BAAxC;EACD,CAFC,CAAF;EAIAH,EAAE,CAAC,uBAAD,EAA0B,MAAM;IAChC,MAAMI,IAAI,GAAG,IAAIF,IAAJ,EAAb;IACAD,MAAM,CAACH,aAAa,CAACM,IAAD,CAAd,CAAN,CAA4BD,IAA5B,CAAiCC,IAAI,CAACC,WAAL,EAAjC;EACD,CAHC,CAAF;EAKAL,EAAE,CAAC,4BAAD,EAA+B,MAAM;IACrCC,MAAM,CAACH,aAAa,CAAC,IAAD,CAAd,CAAN,CAA4BK,IAA5B,CAAiC,0BAAjC;EACD,CAFC,CAAF;AAGD,CAbO,CAAR"}
1
+ {"version":3,"names":["serializeDate","describe","it","expect","Date","toBe","date","toISOString"],"sources":["serializeDate.test.ts"],"sourcesContent":["import serializeDate from './serializeDate'\n\ndescribe('serializeDate', () => {\n it('should serialize zero date', () => {\n expect(serializeDate(new Date(0))).toBe('1970-01-01T00:00:00.000Z')\n })\n\n it('should serialize date', () => {\n const date = new Date()\n expect(serializeDate(date)).toBe(date.toISOString())\n })\n\n it('should serialize null date', () => {\n expect(serializeDate(null)).toBe('1969-12-31T23:59:59.999Z')\n })\n})\n"],"mappings":"AAAA,OAAOA,aAAP,MAA0B,iBAA1B;AAEAC,QAAQ,CAAC,eAAD,EAAkB,MAAM;EAC9BC,EAAE,CAAC,4BAAD,EAA+B,MAAM;IACrCC,MAAM,CAACH,aAAa,CAAC,IAAII,IAAJ,CAAS,CAAT,CAAD,CAAd,CAAN,CAAmCC,IAAnC,CAAwC,0BAAxC;EACD,CAFC,CAAF;EAIAH,EAAE,CAAC,uBAAD,EAA0B,MAAM;IAChC,MAAMI,IAAI,GAAG,IAAIF,IAAJ,EAAb;IACAD,MAAM,CAACH,aAAa,CAACM,IAAD,CAAd,CAAN,CAA4BD,IAA5B,CAAiCC,IAAI,CAACC,WAAL,EAAjC;EACD,CAHC,CAAF;EAKAL,EAAE,CAAC,4BAAD,EAA+B,MAAM;IACrCC,MAAM,CAACH,aAAa,CAAC,IAAD,CAAd,CAAN,CAA4BK,IAA5B,CAAiC,0BAAjC;EACD,CAFC,CAAF;AAGD,CAbO,CAAR"}
@@ -643,6 +643,7 @@ export declare type HKDevice = {
643
643
  readonly manufacturer: string;
644
644
  readonly model: string;
645
645
  readonly softwareVersion: string;
646
+ readonly udiDeviceIdentifier: string | null;
646
647
  };
647
648
  export declare type HKSource = {
648
649
  readonly name: string;
@@ -705,6 +706,24 @@ export declare type HKCategorySampleRaw<T extends HKCategoryTypeIdentifier = HKC
705
706
  readonly metadata: MetadataMapperForCategoryIdentifier<T>;
706
707
  readonly sourceRevision?: HKSourceRevision;
707
708
  };
709
+ export declare type DeletedCategorySampleRaw<T extends HKCategoryTypeIdentifier> = {
710
+ readonly uuid: string;
711
+ readonly metadata: MetadataMapperForCategoryIdentifier<T>;
712
+ };
713
+ export declare type DeletedQuantitySampleRaw<T extends HKQuantityTypeIdentifier> = {
714
+ readonly uuid: string;
715
+ readonly metadata: MetadataMapperForQuantityIdentifier<T>;
716
+ };
717
+ export declare type QueryCategorySamplesResponseRaw<T extends HKCategoryTypeIdentifier> = {
718
+ readonly samples: readonly HKCategorySampleRaw<T>[];
719
+ readonly deletedSamples: readonly DeletedCategorySampleRaw<T>[];
720
+ readonly newAnchor: string;
721
+ };
722
+ export declare type QueryQuantitySamplesResponseRaw<T extends HKQuantityTypeIdentifier> = {
723
+ readonly samples: readonly HKQuantitySampleRaw<T>[];
724
+ readonly deletedSamples: readonly DeletedQuantitySampleRaw<T>[];
725
+ readonly newAnchor: string;
726
+ };
708
727
  export declare type HKCorrelationRaw<TIdentifier extends HKCorrelationTypeIdentifier> = {
709
728
  readonly correlationType: HKCorrelationTypeIdentifier;
710
729
  readonly objects: readonly (HKCategorySampleRaw | HKQuantitySampleRaw)[];
@@ -758,8 +777,8 @@ declare type ReactNativeHealthkitTypeNative = {
758
777
  readonly deleteQuantitySample: <TIdentifier extends HKQuantityTypeIdentifier>(typeIdentifier: TIdentifier, uuid: string) => Promise<boolean>;
759
778
  readonly deleteSamples: <TIdentifier extends HKQuantityTypeIdentifier>(identifier: TIdentifier, start: string, end: string) => Promise<boolean>;
760
779
  readonly queryWorkoutSamples: <TEnergy extends EnergyUnit, TDistance extends LengthUnit>(energyUnit: TEnergy, distanceUnit: TDistance, from: string, to: string, limit: number, ascending: boolean) => Promise<readonly HKWorkoutRaw<TEnergy, TDistance>[]>;
761
- readonly queryCategorySamples: <T extends HKCategoryTypeIdentifier>(identifier: T, from: string, to: string, limit: number, ascending: boolean) => Promise<readonly HKCategorySampleRaw<T>[]>;
762
- readonly queryQuantitySamples: <TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier>>(identifier: TIdentifier, unit: TUnit, from: string, to: string, limit: number, ascending: boolean) => Promise<readonly HKQuantitySampleRaw<TIdentifier, TUnit>[]>;
780
+ readonly queryCategorySamples: <T extends HKCategoryTypeIdentifier>(identifier: T, from: string, to: string, limit: number, ascending: boolean, anchor: string) => Promise<QueryCategorySamplesResponseRaw<T>>;
781
+ readonly queryQuantitySamples: <TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier>>(identifier: TIdentifier, unit: TUnit, from: string, to: string, limit: number, ascending: boolean, anchor: string) => Promise<QueryQuantitySamplesResponseRaw<TIdentifier>>;
763
782
  readonly querySources: <TIdentifier extends HKCategoryTypeIdentifier | HKQuantityTypeIdentifier>(identifier: TIdentifier) => Promise<readonly HKSource[]>;
764
783
  readonly saveCategorySample: <T extends HKCategoryTypeIdentifier>(identifier: T, value: HKCategoryValueForIdentifier<T>, start: string, end: string, metadata: unknown) => Promise<boolean>;
765
784
  readonly queryStatisticsForQuantity: <TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier>>(identifier: HKQuantityTypeIdentifier, unit: TUnit, from: string, to: string, options: readonly HKStatisticsOptions[]) => Promise<QueryStatisticsResponseRaw<TIdentifier, TUnit>>;
@@ -13,6 +13,7 @@ export declare type GenericQueryOptions = {
13
13
  readonly to?: Date;
14
14
  readonly limit?: number;
15
15
  readonly ascending?: boolean;
16
+ readonly anchor?: string;
16
17
  };
17
18
  export interface HKWorkout<TEnergy extends EnergyUnit = EnergyUnit, TDistance extends LengthUnit = LengthUnit> extends Omit<HKWorkoutRaw<TEnergy, TDistance>, 'endDate' | 'startDate'> {
18
19
  readonly startDate: Date;
@@ -1,4 +1,4 @@
1
1
  import type { HKQuantitySampleRaw, HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types';
2
2
  import type { HKQuantitySample } from '../types';
3
- declare function deserializeSample<TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier>>(sample: HKQuantitySampleRaw<TIdentifier, TUnit>): HKQuantitySample<TIdentifier, TUnit>;
4
- export default deserializeSample;
3
+ declare function deserializeQuantitySample<TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier>>(sample: HKQuantitySampleRaw<TIdentifier, TUnit>): HKQuantitySample<TIdentifier, TUnit>;
4
+ export default deserializeQuantitySample;
@@ -4,5 +4,6 @@ declare const prepareOptions: (options: GenericQueryOptions) => {
4
4
  ascending: boolean;
5
5
  from: string;
6
6
  to: string;
7
+ anchor: string;
7
8
  };
8
9
  export default prepareOptions;
@@ -1,5 +1,10 @@
1
- import type { HKCategoryTypeIdentifier } from '../native-types';
1
+ import type { HKCategoryTypeIdentifier, DeletedCategorySampleRaw } from '../native-types';
2
2
  import type { GenericQueryOptions, HKCategorySample } from '../types';
3
- export declare type QueryCategorySamplesFn = <T extends HKCategoryTypeIdentifier>(identifier: T, options: GenericQueryOptions) => Promise<readonly HKCategorySample<T>[]>;
3
+ export declare type QueryCategorySamplesResponse<T extends HKCategoryTypeIdentifier> = {
4
+ readonly samples: readonly HKCategorySample<T>[];
5
+ readonly deletedSamples: readonly DeletedCategorySampleRaw<T>[];
6
+ readonly newAnchor: string;
7
+ };
8
+ export declare type QueryCategorySamplesFn = <T extends HKCategoryTypeIdentifier>(identifier: T, options: GenericQueryOptions) => Promise<QueryCategorySamplesResponse<T>>;
4
9
  declare const queryCategorySamples: QueryCategorySamplesFn;
5
10
  export default queryCategorySamples;
@@ -1,7 +1,12 @@
1
- import type { HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types';
1
+ import type { HKQuantityTypeIdentifier, UnitForIdentifier, DeletedQuantitySampleRaw } from '../native-types';
2
2
  import type { GenericQueryOptions, HKQuantitySample } from '../types';
3
+ export declare type QueryQuantitySamplesResponse<T extends HKQuantityTypeIdentifier> = {
4
+ readonly samples: readonly HKQuantitySample<T>[];
5
+ readonly deletedSamples: readonly DeletedQuantitySampleRaw<T>[];
6
+ readonly newAnchor: string;
7
+ };
3
8
  export declare type QueryQuantitySamplesFn = <TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier>>(identifier: TIdentifier, options: GenericQueryOptions & {
4
9
  readonly unit?: TUnit;
5
- }) => Promise<readonly HKQuantitySample<TIdentifier>[]>;
10
+ }) => Promise<QueryQuantitySamplesResponse<TIdentifier>>;
6
11
  declare const queryQuantitySamples: QueryQuantitySamplesFn;
7
12
  export default queryQuantitySamples;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kingstinct/react-native-healthkit",
3
- "version": "5.4.0",
3
+ "version": "6.0.0",
4
4
  "description": "React Native bindings for HealthKit",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -48,6 +48,7 @@
48
48
  "@babel/core": ">=7",
49
49
  "@babel/preset-env": "^7.18.10",
50
50
  "@commitlint/config-conventional": "12",
51
+ "@expo/config-plugins": "^6.0.1",
51
52
  "@graphql-eslint/eslint-plugin": ">=3",
52
53
  "@release-it/conventional-changelog": "2",
53
54
  "@testing-library/react-native": "^11.0.0",
package/src/index.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Platform } from 'react-native'
2
2
 
3
3
  import {
4
- HKAuthorizationRequestStatus, HKBiologicalSex, HKBloodType, HKFitzpatrickSkinType, HKUnits, HKWheelchairUse,
4
+ HKAuthorizationRequestStatus, HKBiologicalSex, HKBloodType, HKFitzpatrickSkinType, HKQuantityTypeIdentifier, HKUnits, HKWheelchairUse, QueryQuantitySamplesResponseRaw,
5
5
  } from './native-types'
6
6
 
7
7
  import type ReactNativeHealthkit from './index.ios'
@@ -41,9 +41,17 @@ const Healthkit: typeof ReactNativeHealthkit = {
41
41
  getWheelchairUse: UnavailableFn(Promise.resolve(HKWheelchairUse.notSet)),
42
42
  getWorkoutRoutes: UnavailableFn(Promise.resolve([])),
43
43
  isHealthDataAvailable: async () => Promise.resolve(false),
44
- queryCategorySamples: UnavailableFn(Promise.resolve([])),
44
+ queryCategorySamples: UnavailableFn(Promise.resolve({
45
+ samples: [],
46
+ deletedSamples: [],
47
+ newAnchor: '',
48
+ })),
45
49
  queryCorrelationSamples: UnavailableFn(Promise.resolve([])),
46
- queryQuantitySamples: UnavailableFn(Promise.resolve([])),
50
+ queryQuantitySamples: UnavailableFn(Promise.resolve({
51
+ samples: [],
52
+ deletedSamples: [],
53
+ newAnchor: '',
54
+ })),
47
55
  queryStatisticsForQuantity: UnavailableFn(Promise.resolve({
48
56
  averageQuantity: undefined,
49
57
  maximumQuantity: undefined,
@@ -994,6 +994,7 @@ export type HKDevice = {
994
994
  readonly manufacturer: string; // ex: "Apple Inc."
995
995
  readonly model: string; // ex: "Watch"
996
996
  readonly softwareVersion: string; // ex: "9.0"
997
+ readonly udiDeviceIdentifier: string | null
997
998
  };
998
999
 
999
1000
  export type HKSource = {
@@ -1099,6 +1100,28 @@ export type HKCategorySampleRaw<
1099
1100
  readonly sourceRevision?: HKSourceRevision;
1100
1101
  };
1101
1102
 
1103
+ export type DeletedCategorySampleRaw<T extends HKCategoryTypeIdentifier> = {
1104
+ readonly uuid: string;
1105
+ readonly metadata: MetadataMapperForCategoryIdentifier<T>
1106
+ }
1107
+
1108
+ export type DeletedQuantitySampleRaw<T extends HKQuantityTypeIdentifier> = {
1109
+ readonly uuid: string;
1110
+ readonly metadata: MetadataMapperForQuantityIdentifier<T>
1111
+ }
1112
+
1113
+ export type QueryCategorySamplesResponseRaw<T extends HKCategoryTypeIdentifier> = {
1114
+ readonly samples: readonly HKCategorySampleRaw<T>[],
1115
+ readonly deletedSamples: readonly DeletedCategorySampleRaw<T>[],
1116
+ readonly newAnchor: string
1117
+ }
1118
+
1119
+ export type QueryQuantitySamplesResponseRaw<T extends HKQuantityTypeIdentifier> = {
1120
+ readonly samples: readonly HKQuantitySampleRaw<T>[],
1121
+ readonly deletedSamples: readonly DeletedQuantitySampleRaw<T>[],
1122
+ readonly newAnchor: string
1123
+ }
1124
+
1102
1125
  export type HKCorrelationRaw<TIdentifier extends HKCorrelationTypeIdentifier> =
1103
1126
  {
1104
1127
  readonly correlationType: HKCorrelationTypeIdentifier;
@@ -1232,8 +1255,9 @@ type ReactNativeHealthkitTypeNative = {
1232
1255
  from: string,
1233
1256
  to: string,
1234
1257
  limit: number,
1235
- ascending: boolean
1236
- ) => Promise<readonly HKCategorySampleRaw<T>[]>;
1258
+ ascending: boolean,
1259
+ anchor: string
1260
+ ) => Promise<QueryCategorySamplesResponseRaw<T>>;
1237
1261
  readonly queryQuantitySamples: <
1238
1262
  TIdentifier extends HKQuantityTypeIdentifier,
1239
1263
  TUnit extends UnitForIdentifier<TIdentifier>
@@ -1243,8 +1267,9 @@ type ReactNativeHealthkitTypeNative = {
1243
1267
  from: string,
1244
1268
  to: string,
1245
1269
  limit: number,
1246
- ascending: boolean
1247
- ) => Promise<readonly HKQuantitySampleRaw<TIdentifier, TUnit>[]>;
1270
+ ascending: boolean,
1271
+ anchor: string
1272
+ ) => Promise<QueryQuantitySamplesResponseRaw<TIdentifier>>;
1248
1273
  readonly querySources: <
1249
1274
  TIdentifier extends HKCategoryTypeIdentifier | HKQuantityTypeIdentifier
1250
1275
  >(
package/src/types.ts CHANGED
@@ -37,6 +37,7 @@ export type GenericQueryOptions = {
37
37
  readonly to?: Date;
38
38
  readonly limit?: number;
39
39
  readonly ascending?: boolean;
40
+ readonly anchor?: string
40
41
  };
41
42
 
42
43
  export interface HKWorkout<
@@ -69,132 +70,11 @@ export interface QueryStatisticsResponse<TIdentifier extends HKQuantityTypeIdent
69
70
  > {
70
71
  readonly mostRecentQuantityDateInterval?: { readonly from: Date; readonly to: Date };
71
72
  }
72
- /*
73
- export type IsHealthDataAvailableFn = () => Promise<boolean>;
74
-
75
- export type GetBloodTypeFn = () => Promise<HKBloodType>;
76
-
77
- export type GetDateOfBirthFn = () => Promise<Date>;
78
- export type GetBiologicalSexFn = () => Promise<HKBiologicalSex>;
79
- export type GetWheelchairUseFn = () => Promise<HKWheelchairUse>;
80
- export type GetFitzpatrickSkinTypeFn = () => Promise<HKFitzpatrickSkinType>;
81
-
82
- export type AuthorizationStatusForFn = (
83
- type: HealthkitReadAuthorization
84
- ) => Promise<boolean>;
85
-
86
- export type QueryCategorySamplesFn = <T extends HKCategoryTypeIdentifier>(
87
- identifier: T,
88
- options: GenericQueryOptions
89
- ) => Promise<readonly HKCategorySample<T>[]>;
90
-
91
- export type GetRequestStatusForAuthorizationFn = (
92
- read: readonly HealthkitReadAuthorization[],
93
- write?: readonly HealthkitWriteAuthorization[]
94
- ) => Promise<HKAuthorizationRequestStatus>;
95
-
96
- export type RequestAuthorizationFn = (
97
- read: readonly HealthkitReadAuthorization[],
98
- write?: readonly HealthkitWriteAuthorization[]
99
- ) => Promise<boolean>;
100
-
101
- export type SaveQuantitySampleFn = <TType extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TType>>(
102
- identifier: TType,
103
- unit: TUnit,
104
- value: number,
105
- options?: {
106
- readonly start?: Date;
107
- readonly end?: Date;
108
- readonly metadata?: MetadataMapperForQuantityIdentifier<TType>;
109
- }
110
- ) => Promise<boolean>;
111
-
112
- export type QueryQuantitySamplesFn = <
113
- TIdentifier extends HKQuantityTypeIdentifier,
114
- TUnit extends UnitForIdentifier<TIdentifier>
115
- >(
116
- identifier: TIdentifier,
117
- options: GenericQueryOptions & { readonly unit?: TUnit }
118
- ) => Promise<readonly HKQuantitySample<TIdentifier>[]>; */
119
73
 
120
74
  export type HKCategorySampleForSaving =Omit<HKCategorySample, 'device' | 'endDate' | 'startDate' | 'uuid'>
121
75
 
122
76
  export type HKQuantitySampleForSaving =Omit<HKQuantitySample, 'device' | 'endDate' | 'startDate' | 'uuid'>
123
- /*
124
- export type SaveCategorySampleFn = <T extends HKCategoryTypeIdentifier>(
125
- identifier: T,
126
- value: HKCategoryValueForIdentifier<T>,
127
- options?: {
128
- readonly start?: Date;
129
- readonly end?: Date;
130
- readonly metadata?: MetadataMapperForCategoryIdentifier<T>;
131
- }
132
- ) => Promise<boolean>;
133
77
 
134
- export type MostRecentCategorySampleHook = <T extends HKCategoryTypeIdentifier>(
135
- identifier: T
136
- ) => HKCategorySample<T> | null;
137
-
138
- export type MostRecentCorrelationSampleHook = <
139
- T extends HKCorrelationTypeIdentifier
140
- >(
141
- identifer: T
142
- ) => HKCorrelation<T> | null;
143
-
144
- export type MostRecentQuantitySampleHook = <
145
- TIdentifier extends HKQuantityTypeIdentifier,
146
- TUnit extends UnitForIdentifier<TIdentifier>
147
- >(
148
- identifier: TIdentifier,
149
- unit?: TUnit
150
- ) => HKQuantitySample<TIdentifier> | null;
151
-
152
- export type MostRecentWorkoutHook = <
153
- TEnergy extends EnergyUnit,
154
- TDistance extends LengthUnit
155
- >(
156
- options?: Pick<
157
- QueryWorkoutsOptions<TEnergy, TDistance>,
158
- 'distanceUnit' | 'energyUnit'
159
- >
160
- ) => HKWorkout<TEnergy, TDistance> | null;
161
-
162
- export type GetPreferredUnitsFn = (
163
- identifiers: readonly HKQuantityTypeIdentifier[]
164
- ) => Promise<readonly HKUnit[]>;
165
-
166
- export type GetPreferredUnitFn = (
167
- identifier: HKQuantityTypeIdentifier
168
- ) => Promise<HKUnit>;
169
-
170
- export type SaveCorrelationSampleFn = <
171
- TIdentifier extends HKCorrelationTypeIdentifier
172
- >(
173
- typeIdentifier: TIdentifier,
174
- samples: readonly (
175
- | Omit<HKCategorySample, 'device' | 'endDate' | 'startDate' | 'uuid'>
176
- | Omit<HKQuantitySample<HKQuantityTypeIdentifier>, 'device' | 'endDate' | 'startDate' | 'uuid'>
177
- )[],
178
- options?: {
179
- readonly start?: Date;
180
- readonly end?: Date;
181
- readonly metadata?: MetadataMapperForCorrelationIdentifier<TIdentifier>;
182
- }
183
- ) => Promise<boolean>;
184
-
185
- export type SaveWorkoutSampleFn<TIdentifier extends HKWorkoutActivityType, TQIdentifier extends HKQuantityTypeIdentifier> = (
186
- typeIdentifier: TIdentifier,
187
- quantities: readonly Omit<
188
- HKQuantitySample<TQIdentifier>,
189
- 'device' | 'endDate' | 'startDate' | 'uuid'
190
- >[],
191
- start: Date,
192
- options?: {
193
- readonly end?: Date;
194
- readonly metadata?: HKWorkoutMetadata;
195
- }
196
- ) => Promise<boolean>;
197
- */
198
78
  export interface HKCorrelation<TIdentifier extends HKCorrelationTypeIdentifier>
199
79
  extends Omit<
200
80
  HKCorrelationRaw<TIdentifier>,
@@ -204,16 +84,3 @@ export interface HKCorrelation<TIdentifier extends HKCorrelationTypeIdentifier>
204
84
  readonly startDate: Date;
205
85
  readonly endDate: Date;
206
86
  }
207
- /*
208
- export type SubscribeToChangesHook = <
209
- TIdentifier extends HKSampleTypeIdentifier
210
- >(
211
- identifier: TIdentifier,
212
- onChange: () => void,
213
- runInitialUpdate?: boolean
214
- ) => void;
215
-
216
- export type GetWorkoutRoutesFn = (
217
- workoutUUID: string
218
- ) => Promise<readonly WorkoutRoute[]>;
219
- */
@@ -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
@@ -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