@kingstinct/react-native-healthkit 9.0.5 → 9.0.6

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.
@@ -9,102 +9,99 @@ import NitroModules
9
9
 
10
10
  var store = HKHealthStore.init()
11
11
 
12
- var quantityTypeUnitCache = Dictionary<HKQuantityType, HKUnit>()
12
+ var quantityTypeUnitCache = [HKQuantityType: HKUnit]()
13
13
 
14
14
  func getUnitToUse(unitOverride: String?, quantityType: HKQuantityType) async throws -> HKUnit {
15
15
  if let unitOverride = unitOverride {
16
16
  let unit = HKUnit(from: unitOverride)
17
-
18
- if(!quantityType.is(compatibleWith: unit)){
17
+
18
+ if !quantityType.is(compatibleWith: unit) {
19
19
  throw RuntimeError.error(withMessage: "[react-native-healthkit] Unit \(unitOverride) is incompatible with \(quantityType.identifier)")
20
20
  }
21
-
21
+
22
22
  return unit
23
23
  }
24
-
24
+
25
25
  if let preferredUnit = try await getPreferredUnitsInternal(quantityTypes: [quantityType]).first?.value {
26
26
  return preferredUnit
27
27
  }
28
-
28
+
29
29
  throw RuntimeError.error(withMessage: "[react-native-healthkit] Must specify a unit for \(quantityType.identifier)")
30
30
  }
31
31
 
32
32
  func getPreferredUnitsInternal(quantityTypes: [HKQuantityType], forceUpdate: Bool? = false) async throws -> [HKQuantityType: HKUnit] {
33
-
34
- if(forceUpdate != true){
35
- let itemsInCache = quantityTypeUnitCache.filter { (quantityType: HKQuantityType, unit: HKUnit) in
33
+
34
+ if forceUpdate != true {
35
+ let itemsInCache = quantityTypeUnitCache.filter { (quantityType: HKQuantityType, _: HKUnit) in
36
36
  return quantityTypes.contains(where: { $0 == quantityType })
37
37
  }
38
- if(itemsInCache.count == quantityTypes.count){
38
+ if itemsInCache.count == quantityTypes.count {
39
39
  return itemsInCache
40
40
  }
41
41
  }
42
-
43
-
42
+
44
43
  return try await withCheckedThrowingContinuation { continuation in
45
44
  store.preferredUnits(for: Set(quantityTypes)) {
46
45
  (typePerUnits: [HKQuantityType: HKUnit], error: Error?) in
47
46
  if let error = error {
48
47
  return continuation.resume(throwing: error)
49
48
  }
50
-
49
+
51
50
  typePerUnits.forEach { (type: HKQuantityType, unit: HKUnit) in
52
51
  quantityTypeUnitCache.updateValue(unit, forKey: type)
53
52
  }
54
-
53
+
55
54
  return continuation.resume(returning: typePerUnits)
56
55
  }
57
56
  }
58
57
  }
59
58
 
60
- class CoreModule : HybridCoreModuleSpec {
61
- func areObjectTypesAvailable(objectTypeIdentifiers: [ObjectTypeIdentifier]) -> Dictionary<String, Bool> {
62
- var dict = Dictionary<String, Bool>()
63
-
59
+ class CoreModule: HybridCoreModuleSpec {
60
+ func areObjectTypesAvailable(objectTypeIdentifiers: [ObjectTypeIdentifier]) -> [String: Bool] {
61
+ var dict = [String: Bool]()
62
+
64
63
  for objectTypeIdentifier in objectTypeIdentifiers {
65
64
  dict[objectTypeIdentifier.stringValue] = isObjectTypeAvailable(objectTypeIdentifier: objectTypeIdentifier)
66
65
  }
67
-
66
+
68
67
  return dict
69
68
  }
70
-
71
- func areObjectTypesAvailableAsync(objectTypeIdentifiers: [ObjectTypeIdentifier]) -> Promise<Dictionary<String, Bool>> {
72
- return Promise.resolved(withResult: areObjectTypesAvailable(objectTypeIdentifiers: objectTypeIdentifiers))
69
+
70
+ func areObjectTypesAvailableAsync(objectTypeIdentifiers: [ObjectTypeIdentifier]) -> Promise<[String: Bool]> {
71
+ return Promise.resolved(withResult: areObjectTypesAvailable(objectTypeIdentifiers: objectTypeIdentifiers))
73
72
  }
74
-
75
-
76
-
73
+
77
74
  func isObjectTypeAvailable(objectTypeIdentifier: ObjectTypeIdentifier) -> Bool {
78
75
  do {
79
- let _ = try objectTypeFrom(objectTypeIdentifier: objectTypeIdentifier)
76
+ _ = try objectTypeFrom(objectTypeIdentifier: objectTypeIdentifier)
80
77
  return true
81
78
  } catch {
82
79
  return false
83
80
  }
84
81
  }
85
-
82
+
86
83
  func isObjectTypeAvailableAsync(objectTypeIdentifier: ObjectTypeIdentifier) -> Promise<Bool> {
87
84
  return Promise.resolved(withResult: isObjectTypeAvailable(objectTypeIdentifier: objectTypeIdentifier))
88
85
  }
89
-
86
+
90
87
  func authorizationStatusFor(
91
88
  type: ObjectTypeIdentifier
92
89
  ) throws -> AuthorizationStatus {
93
90
  let objectType = try objectTypeFrom(objectTypeIdentifier: type)
94
-
91
+
95
92
  let authStatus = store.authorizationStatus(for: objectType)
96
-
97
- if let authStatus = AuthorizationStatus(rawValue: Int32(authStatus.rawValue)){
93
+
94
+ if let authStatus = AuthorizationStatus(rawValue: Int32(authStatus.rawValue)) {
98
95
  return authStatus
99
96
  }
100
-
97
+
101
98
  throw RuntimeError.error(withMessage: "[react-native-healthkit] got unrecognized AuthorizationStatus with value \(authStatus.rawValue)")
102
99
  }
103
-
100
+
104
101
  func getRequestStatusForAuthorization(toShare: [SampleTypeIdentifierWriteable], toRead: [ObjectTypeIdentifier]) throws -> Promise<AuthorizationRequestStatus> {
105
102
  let toShare = sampleTypesFromArray(typeIdentifiersWriteable: toShare)
106
103
  let toRead = objectTypesFromArray(typeIdentifiers: toRead)
107
-
104
+
108
105
  return Promise.async {
109
106
  try await withCheckedThrowingContinuation { continuation in
110
107
  store.getRequestStatusForAuthorization(toShare: toShare, read: toRead) { status, error in
@@ -116,17 +113,17 @@ class CoreModule : HybridCoreModuleSpec {
116
113
  } else {
117
114
  continuation.resume(throwing: RuntimeError.error(withMessage: "Unrecognized authStatus returned: \(status.rawValue)"))
118
115
  }
119
-
116
+
120
117
  }
121
118
  }
122
119
  }
123
120
  }
124
121
  }
125
-
122
+
126
123
  func requestAuthorization(toShare: [SampleTypeIdentifierWriteable], toRead: [ObjectTypeIdentifier]) throws -> Promise<Bool> {
127
124
  let share = sampleTypesFromArray(typeIdentifiersWriteable: toShare)
128
125
  let toRead = objectTypesFromArray(typeIdentifiers: toRead)
129
-
126
+
130
127
  return Promise.async {
131
128
  try await withCheckedThrowingContinuation { continuation in
132
129
  store.requestAuthorization(toShare: share, read: toRead) { status, error in
@@ -139,10 +136,10 @@ class CoreModule : HybridCoreModuleSpec {
139
136
  }
140
137
  }
141
138
  }
142
-
139
+
143
140
  func querySources(identifier: SampleTypeIdentifier) throws -> Promise<[HybridSourceProxySpec]> {
144
141
  let sampleType = try sampleTypeFrom(sampleTypeIdentifier: identifier)
145
-
142
+
146
143
  return Promise.async {
147
144
  try await withCheckedThrowingContinuation { continuation in
148
145
  let query = HKSourceQuery(
@@ -153,26 +150,26 @@ class CoreModule : HybridCoreModuleSpec {
153
150
  continuation.resume(throwing: error)
154
151
  return
155
152
  }
156
-
153
+
157
154
  guard let sources = sources else {
158
155
  return continuation.resume(throwing: RuntimeError.error(withMessage: "Empty response for sample type \(identifier.stringValue)"))
159
156
  }
160
-
157
+
161
158
  let serializedSources = sources.map { source -> SourceProxy in
162
-
159
+
163
160
  return SourceProxy(
164
161
  source: source
165
162
  )
166
163
  }
167
-
164
+
168
165
  continuation.resume(returning: serializedSources)
169
166
  }
170
-
167
+
171
168
  store.execute(query)
172
169
  }
173
170
  }
174
171
  }
175
-
172
+
176
173
  func enableBackgroundDelivery(typeIdentifier: ObjectTypeIdentifier, updateFrequency: UpdateFrequency) throws -> Promise<Bool> {
177
174
  if let frequency = HKUpdateFrequency(rawValue: Int(updateFrequency.rawValue)) {
178
175
  let type = try objectTypeFrom(objectTypeIdentifier: typeIdentifier)
@@ -193,7 +190,7 @@ class CoreModule : HybridCoreModuleSpec {
193
190
  throw RuntimeError.error(withMessage: "Invalid update frequency value: \(updateFrequency)")
194
191
  }
195
192
  }
196
-
193
+
197
194
  func disableBackgroundDelivery(
198
195
  typeIdentifier: ObjectTypeIdentifier
199
196
  ) throws -> Promise<Bool> {
@@ -211,7 +208,7 @@ class CoreModule : HybridCoreModuleSpec {
211
208
  }
212
209
  }
213
210
  }
214
-
211
+
215
212
  func disableAllBackgroundDelivery() throws -> Promise<Bool> {
216
213
  return Promise.async {
217
214
  try await withCheckedThrowingContinuation { continuation in
@@ -224,64 +221,65 @@ class CoreModule : HybridCoreModuleSpec {
224
221
  }
225
222
  }
226
223
  }
227
-
224
+
228
225
  func unsubscribeQueryAsync(queryId: String) throws -> Promise<Bool> {
229
226
  let result = try self.unsubscribeQuery(queryId: queryId)
230
-
227
+
231
228
  return Promise.resolved(withResult: result)
232
229
  }
233
-
230
+
234
231
  func isHealthDataAvailableAsync() -> Promise<Bool> {
235
232
  return Promise.resolved(withResult: HKHealthStore.isHealthDataAvailable())
236
233
  }
237
-
234
+
238
235
  func isProtectedDataAvailableAsync() -> Promise<Bool> {
239
236
  return Promise.resolved(withResult: UIApplication.shared.isProtectedDataAvailable)
240
237
  }
241
-
238
+
242
239
  func isHealthDataAvailable() throws -> Bool {
243
240
  return HKHealthStore.isHealthDataAvailable()
244
241
  }
245
-
242
+
246
243
  func isProtectedDataAvailable() throws -> Bool {
247
244
  return UIApplication.shared.isProtectedDataAvailable
248
245
  }
249
-
246
+
250
247
  func getPreferredUnits(identifiers: [QuantityTypeIdentifier], forceUpdate: Bool?) throws -> Promise<[IdentifierWithUnit]> {
251
248
  return Promise.async {
252
-
249
+
253
250
  let quantityTypes = identifiers.compactMap { identifier in
254
251
  do {
255
252
  let quantityType = try initializeQuantityType(identifier.stringValue)
253
+
256
254
  return quantityType
257
255
  } catch {
258
256
  print(error.localizedDescription)
259
257
  return nil
260
258
  }
261
259
  }
262
-
260
+
263
261
  let typePerUnits = try await getPreferredUnitsInternal(quantityTypes: quantityTypes, forceUpdate: forceUpdate)
264
-
262
+
265
263
  let dic = typePerUnits.map { typePerUnit in
266
264
  return IdentifierWithUnit(
267
265
  typeIdentifier: typePerUnit.key.identifier,
268
266
  unit: typePerUnit.value.unitString
269
267
  )
270
268
  }
271
-
269
+
272
270
  return dic
273
271
  }
274
272
  }
275
-
273
+
276
274
  var _runningQueries: [String: HKQuery] = [:]
277
-
275
+
278
276
  func deleteObjects(objectTypeIdentifier: ObjectTypeIdentifier, filter: FilterForSamples) throws -> Promise<Double> {
279
277
  let predicate = try createPredicateForSamples(filter: filter)
280
278
  let of = try objectTypeFrom(objectTypeIdentifier: objectTypeIdentifier)
281
-
279
+
282
280
  return Promise.async {
283
281
  return try await withCheckedThrowingContinuation { continuation in
284
- store.deleteObjects(of: of, predicate: predicate) { (success, count, error) in
282
+ store.deleteObjects(of: of, predicate: predicate) { (_, count, error) in
285
283
  if let error = error {
286
284
  continuation.resume(throwing: error)
287
285
  } else {
@@ -291,21 +289,21 @@ class CoreModule : HybridCoreModuleSpec {
291
289
  }
292
290
  }
293
291
  }
294
-
292
+
295
293
  func subscribeToObserverQuery(
296
294
  typeIdentifier: SampleTypeIdentifier,
297
295
  callback: @escaping (OnChangeCallbackArgs) -> Void
298
296
  ) throws -> String {
299
297
  let sampleType = try sampleTypeFrom(sampleTypeIdentifier: typeIdentifier)
300
-
298
+
301
299
  let predicate = HKQuery.predicateForSamples(
302
300
  withStart: Date.init(),
303
301
  end: nil,
304
302
  options: HKQueryOptions.strictStartDate
305
303
  )
306
-
304
+
307
305
  let queryId = UUID().uuidString
308
-
306
+
309
307
  func responder(
310
308
  query: HKObserverQuery,
311
309
  handler: @escaping HKObserverQueryCompletionHandler,
@@ -316,42 +314,42 @@ class CoreModule : HybridCoreModuleSpec {
316
314
  handler()
317
315
  }
318
316
  }
319
-
317
+
320
318
  let query = HKObserverQuery(
321
319
  sampleType: sampleType,
322
320
  predicate: predicate
323
321
  ) {
324
322
  (query: HKObserverQuery, handler: @escaping HKObserverQueryCompletionHandler, error: Error?)
325
323
  in
326
-
324
+
327
325
  return responder(query: query, handler: handler, error: error)
328
-
326
+
329
327
  }
330
-
328
+
331
329
  store.execute(query)
332
-
330
+
333
331
  self._runningQueries.updateValue(query, forKey: queryId)
334
-
335
- //resolve(queryId)
336
-
332
+
333
+ // resolve(queryId)
334
+
337
335
  return queryId
338
336
  }
339
-
337
+
340
338
  func unsubscribeQuery(queryId: String) throws -> Bool {
341
339
  guard let query = self._runningQueries[queryId] else {
342
340
  throw RuntimeError.error(withMessage: "Query with id \(queryId) not found")
343
341
  }
344
-
342
+
345
343
  store.stop(query)
346
-
344
+
347
345
  self._runningQueries.removeValue(forKey: queryId)
348
-
346
+
349
347
  return true
350
348
  }
351
-
349
+
352
350
  func unsubscribeQueriesAsync(queryIds: [String]) throws -> Promise<Double> {
353
351
  let successCount = self.unsubscribeQueries(queryIds: queryIds)
354
-
352
+
355
353
  return Promise.resolved(withResult: successCount)
356
354
  }
357
355
 
@@ -359,17 +357,17 @@ class CoreModule : HybridCoreModuleSpec {
359
357
  let successCounts = queryIds.map { queryId in
360
358
  if let query = self._runningQueries[queryId] {
361
359
  store.stop(query)
362
-
360
+
363
361
  self._runningQueries.removeValue(forKey: queryId)
364
-
362
+
365
363
  return true
366
364
  }
367
-
365
+
368
366
  print("Query with id \(queryId) not found, skipping unsubscribe")
369
-
367
+
370
368
  return false
371
369
  }
372
-
370
+
373
371
  return Double(successCounts.filter { $0 }.count)
374
372
  }
375
373
 
package/ios/Helpers.swift CHANGED
@@ -136,27 +136,6 @@ func createUUIDsPredicate(uuidsWrapper: PredicateWithUUIDs) -> NSPredicate {
136
136
  return HKQuery.predicateForObjects(with: Set(uuids))
137
137
  }
138
138
 
139
- func createPredicate(filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout?) throws -> NSPredicate? {
140
- if let filter = filter {
141
- switch filter {
142
- case .first(let uuidWrapper):
143
- return HKQuery.predicateForObject(with: try initializeUUID(uuidWrapper.uuid))
144
- case .second(let uuidsWrapper):
145
- return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
146
- case .third(let metadataKey):
147
- return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
148
- case .fourth(let dateFilter):
149
- return createDatePredicate(dateFilter: dateFilter)
150
- case .fifth(let w):
151
- if let w = w.workout as? WorkoutProxy {
152
- return w.workoutPredicate
153
- }
154
- throw RuntimeError.error(withMessage: "[react-native-healthkit] Failed to initialize workout for filter")
155
- }
156
- }
157
- return nil
158
- }
159
-
160
139
  func createPredicate(filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_FilterForSamplesAnd_FilterForSamplesOr?) throws -> NSPredicate? {
161
140
  if let filter = filter {
162
141
  switch filter {
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./Auth"), exports);
18
18
  __exportStar(require("./Background"), exports);
19
19
  __exportStar(require("./CategoryType"), exports);
20
+ __exportStar(require("./CategoryTypeIdentifier"), exports);
20
21
  __exportStar(require("./Characteristics"), exports);
21
22
  __exportStar(require("./Constants"), exports);
22
23
  __exportStar(require("./CorrelationType"), exports);
@@ -1,6 +1,7 @@
1
1
  export * from './Auth';
2
2
  export * from './Background';
3
3
  export * from './CategoryType';
4
+ export * from './CategoryTypeIdentifier';
4
5
  export * from './Characteristics';
5
6
  export * from './Constants';
6
7
  export * from './CorrelationType';
@@ -45,8 +45,8 @@ export declare const getRequestStatusForAuthorization: (toShare: import("./types
45
45
  export declare const getWheelchairUse: () => import("./types").WheelchairUse;
46
46
  export declare const isHealthDataAvailable: () => boolean;
47
47
  export declare const isHealthDataAvailableAsync: () => Promise<boolean>;
48
- export declare const queryCategorySamples: <T extends import("./types/CategoryTypeIdentifier").CategoryTypeIdentifier>(identifier: T, options?: import("./types").QueryOptionsWithSortOrder) => Promise<readonly import("./types").CategorySampleTyped<T>[]>;
49
- export declare const queryCategorySamplesWithAnchor: <T extends import("./types/CategoryTypeIdentifier").CategoryTypeIdentifier>(identifier: T, options: import("./types").QueryOptionsWithAnchor) => Promise<import("./types").CategorySamplesWithAnchorResponseTyped<T>>;
48
+ export declare const queryCategorySamples: <T extends import("./types").CategoryTypeIdentifier>(identifier: T, options?: import("./types").QueryOptionsWithSortOrder) => Promise<readonly import("./types").CategorySampleTyped<T>[]>;
49
+ export declare const queryCategorySamplesWithAnchor: <T extends import("./types").CategoryTypeIdentifier>(identifier: T, options: import("./types").QueryOptionsWithAnchor) => Promise<import("./types").CategorySamplesWithAnchorResponseTyped<T>>;
50
50
  export declare const queryCorrelationSamples: (typeIdentifier: import("./types").CorrelationTypeIdentifier, from: Date, to: Date) => Promise<readonly import("./types").CorrelationSample[]>;
51
51
  export declare const queryHeartbeatSeriesSamples: (options?: import("./types").QueryOptionsWithSortOrder) => Promise<readonly import("./types").HeartbeatSeriesSample[]>;
52
52
  export declare const queryHeartbeatSeriesSamplesWithAnchor: (options: import("./types").QueryOptionsWithAnchor) => Promise<import("./types").HeartbeatSeriesSamplesWithAnchorResponse>;
@@ -59,7 +59,7 @@ export declare const queryWorkoutSamplesWithAnchor: (options: import("./types").
59
59
  export declare const querySources: (identifier: import("./types").SampleTypeIdentifier) => Promise<readonly import("./specs/SourceProxy.nitro").SourceProxy[]>;
60
60
  export declare const requestAuthorization: (toShare: import("./types").SampleTypeIdentifierWriteable[], toRead: import("./types").ObjectTypeIdentifier[]) => Promise<boolean>;
61
61
  export declare const deleteObjects: (objectTypeIdentifier: import("./types").ObjectTypeIdentifier, filter: import("./types").FilterForSamples) => Promise<number>;
62
- export declare const saveCategorySample: <T extends import("./types/CategoryTypeIdentifier").CategoryTypeIdentifier>(identifier: T, value: import("./types").CategoryValueForIdentifier, startDate: Date, endDate: Date, metadata: import("./types").MetadataForCategoryIdentifier<T>) => Promise<boolean>;
62
+ export declare const saveCategorySample: <T extends import("./types").CategoryTypeIdentifier>(identifier: T, value: import("./types").CategoryValueForIdentifier, startDate: Date, endDate: Date, metadata: import("./types").MetadataForCategoryIdentifier<T>) => Promise<boolean>;
63
63
  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>;
64
64
  export declare const saveQuantitySample: (identifier: QuantityTypeIdentifier, unit: string, value: number, start: Date, end: Date, metadata: import("react-native-nitro-modules").AnyMap) => Promise<boolean>;
65
65
  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>;
@@ -107,8 +107,8 @@ declare const _default: {
107
107
  getWheelchairUse: () => import("./types").WheelchairUse;
108
108
  isHealthDataAvailable: () => boolean;
109
109
  isHealthDataAvailableAsync: () => Promise<boolean>;
110
- queryCategorySamples: <T extends import("./types/CategoryTypeIdentifier").CategoryTypeIdentifier>(identifier: T, options?: import("./types").QueryOptionsWithSortOrder) => Promise<readonly import("./types").CategorySampleTyped<T>[]>;
111
- queryCategorySamplesWithAnchor: <T extends import("./types/CategoryTypeIdentifier").CategoryTypeIdentifier>(identifier: T, options: import("./types").QueryOptionsWithAnchor) => Promise<import("./types").CategorySamplesWithAnchorResponseTyped<T>>;
110
+ queryCategorySamples: <T extends import("./types").CategoryTypeIdentifier>(identifier: T, options?: import("./types").QueryOptionsWithSortOrder) => Promise<readonly import("./types").CategorySampleTyped<T>[]>;
111
+ queryCategorySamplesWithAnchor: <T extends import("./types").CategoryTypeIdentifier>(identifier: T, options: import("./types").QueryOptionsWithAnchor) => Promise<import("./types").CategorySamplesWithAnchorResponseTyped<T>>;
112
112
  queryCorrelationSamples: (typeIdentifier: import("./types").CorrelationTypeIdentifier, from: Date, to: Date) => Promise<readonly import("./types").CorrelationSample[]>;
113
113
  queryHeartbeatSeriesSamples: (options?: import("./types").QueryOptionsWithSortOrder) => Promise<readonly import("./types").HeartbeatSeriesSample[]>;
114
114
  queryHeartbeatSeriesSamplesWithAnchor: (options: import("./types").QueryOptionsWithAnchor) => Promise<import("./types").HeartbeatSeriesSamplesWithAnchorResponse>;
@@ -121,7 +121,7 @@ declare const _default: {
121
121
  querySources: (identifier: import("./types").SampleTypeIdentifier) => Promise<readonly import("./specs/SourceProxy.nitro").SourceProxy[]>;
122
122
  requestAuthorization: (toShare: import("./types").SampleTypeIdentifierWriteable[], toRead: import("./types").ObjectTypeIdentifier[]) => Promise<boolean>;
123
123
  deleteObjects: (objectTypeIdentifier: import("./types").ObjectTypeIdentifier, filter: import("./types").FilterForSamples) => Promise<number>;
124
- saveCategorySample: <T extends import("./types/CategoryTypeIdentifier").CategoryTypeIdentifier>(identifier: T, value: import("./types").CategoryValueForIdentifier, startDate: Date, endDate: Date, metadata: import("./types").MetadataForCategoryIdentifier<T>) => Promise<boolean>;
124
+ saveCategorySample: <T extends import("./types").CategoryTypeIdentifier>(identifier: T, value: import("./types").CategoryValueForIdentifier, startDate: Date, endDate: Date, metadata: import("./types").MetadataForCategoryIdentifier<T>) => Promise<boolean>;
125
125
  saveCorrelationSample: (typeIdentifier: import("./types").CorrelationTypeIdentifier, samples: import("./types").SampleForSaving[], start: Date, end: Date, metadata: import("react-native-nitro-modules").AnyMap) => Promise<boolean>;
126
126
  saveQuantitySample: (identifier: QuantityTypeIdentifier, unit: string, value: number, start: Date, end: Date, metadata: import("react-native-nitro-modules").AnyMap) => Promise<boolean>;
127
127
  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>;
@@ -1,6 +1,6 @@
1
1
  import type { QuantitySample } from './QuantitySample';
2
2
  import type { QuantityTypeIdentifier } from './QuantityTypeIdentifier';
3
- import type { PredicateForSamples } from './QueryOptions';
3
+ import type { FilterForSamples } from './QueryOptions';
4
4
  import type { DeletedSample, GenericMetadata } from './Shared';
5
5
  import type { BloodGlucoseUnit, CountPerTime, EnergyUnit, LengthUnit, MassUnit, SpeedUnit, TemperatureUnit, TimeUnit, Unit, VolumeUnit } from './Units';
6
6
  interface QuantityDateInterval {
@@ -45,7 +45,7 @@ export interface IntervalComponents {
45
45
  readonly year?: number;
46
46
  }
47
47
  export interface StatisticsQueryOptions {
48
- filter?: PredicateForSamples;
48
+ filter?: FilterForSamples;
49
49
  unit?: string;
50
50
  }
51
51
  /**
@@ -15,14 +15,22 @@ type PredicateWithMetadataKey = {
15
15
  readonly withMetadataKey: string;
16
16
  };
17
17
  export type FilterForSamplesAnd = {
18
- AND: PredicateForSamples[];
18
+ readonly AND: PredicateForSamples[];
19
19
  };
20
20
  export type FilterForSamplesOr = {
21
- OR: PredicateForSamples[];
21
+ readonly OR: PredicateForSamples[];
22
22
  };
23
23
  export type PredicateFromWorkout = {
24
- workout: WorkoutProxy;
24
+ readonly workout: WorkoutProxy;
25
25
  };
26
+ type ComputeRaw<A> = A extends Function ? A : {
27
+ [K in keyof A]: A[K];
28
+ } & {};
29
+ type AllKeys<U> = U extends any ? keyof U : never;
30
+ type _Strict<U, UAll extends U = U> = U extends any ? ComputeRaw<U & {
31
+ [K in Exclude<AllKeys<UAll>, keyof U>]?: never;
32
+ }> : never;
33
+ export type StrictUnion<U extends object> = _Strict<U>;
26
34
  export type FilterForSamples = PredicateForSamples | FilterForSamplesAnd | FilterForSamplesOr;
27
35
  export type PredicateForSamples = PredicateWithUUID | PredicateWithUUIDs | PredicateWithMetadataKey | PredicateWithStartAndEnd | PredicateFromWorkout;
28
36
  /**
@@ -1,6 +1,7 @@
1
1
  export * from './Auth';
2
2
  export * from './Background';
3
3
  export * from './CategoryType';
4
+ export * from './CategoryTypeIdentifier';
4
5
  export * from './Characteristics';
5
6
  export * from './Constants';
6
7
  export * from './CorrelationType';
@@ -1737,15 +1737,6 @@ namespace margelo::nitro::healthkit::bridge::swift {
1737
1737
  return vector;
1738
1738
  }
1739
1739
 
1740
- // pragma MARK: std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout>>
1741
- /**
1742
- * Specialized version of `std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout>>`.
1743
- */
1744
- using std__optional_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__ = std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout>>;
1745
- inline std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout>> create_std__optional_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__(const std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout>& value) {
1746
- return std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout>>(value);
1747
- }
1748
-
1749
1740
  // pragma MARK: std::optional<StatisticsQueryOptions>
1750
1741
  /**
1751
1742
  * Specialized version of `std::optional<StatisticsQueryOptions>`.
@@ -18,21 +18,25 @@ public extension StatisticsQueryOptions {
18
18
  /**
19
19
  * Create a new instance of `StatisticsQueryOptions`.
20
20
  */
21
- init(filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout?, unit: String?) {
22
- self.init({ () -> bridge.std__optional_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__ in
21
+ init(filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_FilterForSamplesAnd_FilterForSamplesOr?, unit: String?) {
22
+ self.init({ () -> bridge.std__optional_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr__ in
23
23
  if let __unwrappedValue = filter {
24
- return bridge.create_std__optional_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__({ () -> bridge.std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout_ in
24
+ return bridge.create_std__optional_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr__({ () -> bridge.std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_ in
25
25
  switch __unwrappedValue {
26
26
  case .first(let __value):
27
- return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout_(__value)
27
+ return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__value)
28
28
  case .second(let __value):
29
- return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout_(__value)
29
+ return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__value)
30
30
  case .third(let __value):
31
- return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout_(__value)
31
+ return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__value)
32
32
  case .fourth(let __value):
33
- return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout_(__value)
33
+ return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__value)
34
34
  case .fifth(let __value):
35
- return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout_(__value)
35
+ return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__value)
36
+ case .sixth(let __value):
37
+ return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__value)
38
+ case .seventh(let __value):
39
+ return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__value)
36
40
  }
37
41
  }().variant)
38
42
  } else {
@@ -47,13 +51,13 @@ public extension StatisticsQueryOptions {
47
51
  }())
48
52
  }
49
53
 
50
- var filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout? {
54
+ var filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_FilterForSamplesAnd_FilterForSamplesOr? {
51
55
  @inline(__always)
52
56
  get {
53
- return { () -> Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout? in
57
+ return { () -> Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_FilterForSamplesAnd_FilterForSamplesOr? in
54
58
  if let __unwrapped = self.__filter.value {
55
- return { () -> Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout in
56
- let __variant = bridge.std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout_(__unwrapped)
59
+ return { () -> Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_FilterForSamplesAnd_FilterForSamplesOr in
60
+ let __variant = bridge.std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__unwrapped)
57
61
  switch __variant.index() {
58
62
  case 0:
59
63
  let __actual = __variant.get_0()
@@ -70,6 +74,12 @@ public extension StatisticsQueryOptions {
70
74
  case 4:
71
75
  let __actual = __variant.get_4()
72
76
  return .fifth(__actual)
77
+ case 5:
78
+ let __actual = __variant.get_5()
79
+ return .sixth(__actual)
80
+ case 6:
81
+ let __actual = __variant.get_6()
82
+ return .seventh(__actual)
73
83
  default:
74
84
  fatalError("Variant can never have index \(__variant.index())!")
75
85
  }
@@ -81,20 +91,24 @@ public extension StatisticsQueryOptions {
81
91
  }
82
92
  @inline(__always)
83
93
  set {
84
- self.__filter = { () -> bridge.std__optional_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__ in
94
+ self.__filter = { () -> bridge.std__optional_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr__ in
85
95
  if let __unwrappedValue = newValue {
86
- return bridge.create_std__optional_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__({ () -> bridge.std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout_ in
96
+ return bridge.create_std__optional_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr__({ () -> bridge.std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_ in
87
97
  switch __unwrappedValue {
88
98
  case .first(let __value):
89
- return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout_(__value)
99
+ return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__value)
90
100
  case .second(let __value):
91
- return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout_(__value)
101
+ return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__value)
92
102
  case .third(let __value):
93
- return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout_(__value)
103
+ return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__value)
94
104
  case .fourth(let __value):
95
- return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout_(__value)
105
+ return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__value)
96
106
  case .fifth(let __value):
97
- return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout_(__value)
107
+ return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__value)
108
+ case .sixth(let __value):
109
+ return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__value)
110
+ case .seventh(let __value):
111
+ return bridge.create_std__variant_PredicateWithUUID__PredicateWithUUIDs__PredicateWithMetadataKey__PredicateWithStartAndEnd__PredicateFromWorkout__FilterForSamplesAnd__FilterForSamplesOr_(__value)
98
112
  }
99
113
  }().variant)
100
114
  } else {
@@ -28,6 +28,10 @@ namespace margelo::nitro::healthkit { struct PredicateWithMetadataKey; }
28
28
  namespace margelo::nitro::healthkit { struct PredicateWithStartAndEnd; }
29
29
  // Forward declaration of `PredicateFromWorkout` to properly resolve imports.
30
30
  namespace margelo::nitro::healthkit { struct PredicateFromWorkout; }
31
+ // Forward declaration of `FilterForSamplesAnd` to properly resolve imports.
32
+ namespace margelo::nitro::healthkit { struct FilterForSamplesAnd; }
33
+ // Forward declaration of `FilterForSamplesOr` to properly resolve imports.
34
+ namespace margelo::nitro::healthkit { struct FilterForSamplesOr; }
31
35
 
32
36
  #include <optional>
33
37
  #include <variant>
@@ -36,6 +40,8 @@ namespace margelo::nitro::healthkit { struct PredicateFromWorkout; }
36
40
  #include "PredicateWithMetadataKey.hpp"
37
41
  #include "PredicateWithStartAndEnd.hpp"
38
42
  #include "PredicateFromWorkout.hpp"
43
+ #include "FilterForSamplesAnd.hpp"
44
+ #include "FilterForSamplesOr.hpp"
39
45
  #include <string>
40
46
 
41
47
  namespace margelo::nitro::healthkit {
@@ -45,12 +51,12 @@ namespace margelo::nitro::healthkit {
45
51
  */
46
52
  struct StatisticsQueryOptions {
47
53
  public:
48
- std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout>> filter SWIFT_PRIVATE;
54
+ std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout, FilterForSamplesAnd, FilterForSamplesOr>> filter SWIFT_PRIVATE;
49
55
  std::optional<std::string> unit SWIFT_PRIVATE;
50
56
 
51
57
  public:
52
58
  StatisticsQueryOptions() = default;
53
- explicit StatisticsQueryOptions(std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout>> filter, std::optional<std::string> unit): filter(filter), unit(unit) {}
59
+ explicit StatisticsQueryOptions(std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout, FilterForSamplesAnd, FilterForSamplesOr>> filter, std::optional<std::string> unit): filter(filter), unit(unit) {}
54
60
  };
55
61
 
56
62
  } // namespace margelo::nitro::healthkit
@@ -65,13 +71,13 @@ namespace margelo::nitro {
65
71
  static inline StatisticsQueryOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
66
72
  jsi::Object obj = arg.asObject(runtime);
67
73
  return StatisticsQueryOptions(
68
- JSIConverter<std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout>>>::fromJSI(runtime, obj.getProperty(runtime, "filter")),
74
+ JSIConverter<std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout, FilterForSamplesAnd, FilterForSamplesOr>>>::fromJSI(runtime, obj.getProperty(runtime, "filter")),
69
75
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "unit"))
70
76
  );
71
77
  }
72
78
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const StatisticsQueryOptions& arg) {
73
79
  jsi::Object obj(runtime);
74
- obj.setProperty(runtime, "filter", JSIConverter<std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout>>>::toJSI(runtime, arg.filter));
80
+ obj.setProperty(runtime, "filter", JSIConverter<std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout, FilterForSamplesAnd, FilterForSamplesOr>>>::toJSI(runtime, arg.filter));
75
81
  obj.setProperty(runtime, "unit", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.unit));
76
82
  return obj;
77
83
  }
@@ -80,7 +86,7 @@ namespace margelo::nitro {
80
86
  return false;
81
87
  }
82
88
  jsi::Object obj = value.getObject(runtime);
83
- if (!JSIConverter<std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout>>>::canConvert(runtime, obj.getProperty(runtime, "filter"))) return false;
89
+ if (!JSIConverter<std::optional<std::variant<PredicateWithUUID, PredicateWithUUIDs, PredicateWithMetadataKey, PredicateWithStartAndEnd, PredicateFromWorkout, FilterForSamplesAnd, FilterForSamplesOr>>>::canConvert(runtime, obj.getProperty(runtime, "filter"))) return false;
84
90
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "unit"))) return false;
85
91
  return true;
86
92
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kingstinct/react-native-healthkit",
3
- "version": "9.0.5",
3
+ "version": "9.0.6",
4
4
  "description": "React Native bindings for HealthKit",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
@@ -1,6 +1,6 @@
1
1
  import type { QuantitySample } from './QuantitySample'
2
2
  import type { QuantityTypeIdentifier } from './QuantityTypeIdentifier'
3
- import type { PredicateForSamples } from './QueryOptions'
3
+ import type { FilterForSamples } from './QueryOptions'
4
4
  import type { DeletedSample, GenericMetadata } from './Shared'
5
5
  import type {
6
6
  BloodGlucoseUnit,
@@ -64,7 +64,7 @@ export interface IntervalComponents {
64
64
  }
65
65
 
66
66
  export interface StatisticsQueryOptions {
67
- filter?: PredicateForSamples
67
+ filter?: FilterForSamples
68
68
  unit?: string
69
69
  }
70
70
 
@@ -20,17 +20,39 @@ type PredicateWithMetadataKey = {
20
20
  }
21
21
 
22
22
  export type FilterForSamplesAnd = {
23
- AND: PredicateForSamples[]
23
+ readonly AND: PredicateForSamples[]
24
24
  }
25
25
 
26
26
  export type FilterForSamplesOr = {
27
- OR: PredicateForSamples[]
27
+ readonly OR: PredicateForSamples[]
28
28
  }
29
29
 
30
30
  export type PredicateFromWorkout = {
31
- workout: WorkoutProxy
31
+ readonly workout: WorkoutProxy
32
32
  }
33
33
 
34
+ // Computes and flattens object types
35
+ // biome-ignore lint/complexity/noBannedTypes: <explanation>
36
+ type ComputeRaw<A> = A extends Function ? A : { [K in keyof A]: A[K] } & {}
37
+
38
+ // Gets all keys from a union of objects
39
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
40
+ type AllKeys<U> = U extends any ? keyof U : never
41
+
42
+ // The core: for each member U in the union,
43
+ // add `?: never` for any key that exists in other union members.
44
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
45
+ type _Strict<U, UAll extends U = U> = U extends any
46
+ ? ComputeRaw<
47
+ U & {
48
+ [K in Exclude<AllKeys<UAll>, keyof U>]?: never
49
+ }
50
+ >
51
+ : never
52
+
53
+ // The exported type you can copy into your codebase
54
+ export type StrictUnion<U extends object> = _Strict<U>
55
+
34
56
  export type FilterForSamples =
35
57
  | PredicateForSamples
36
58
  | FilterForSamplesAnd
@@ -42,7 +64,6 @@ export type PredicateForSamples =
42
64
  | PredicateWithMetadataKey
43
65
  | PredicateWithStartAndEnd
44
66
  | PredicateFromWorkout
45
-
46
67
  /**
47
68
  * Generic options for querying.
48
69
  */
@@ -1,6 +1,7 @@
1
1
  export * from './Auth'
2
2
  export * from './Background'
3
3
  export * from './CategoryType'
4
+ export * from './CategoryTypeIdentifier'
4
5
  export * from './Characteristics'
5
6
  export * from './Constants'
6
7
  export * from './CorrelationType'
@@ -1,19 +0,0 @@
1
- ///
2
- /// Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout.swift
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
6
- ///
7
-
8
- /**
9
- * An Swift enum with associated values representing a Variant/Union type.
10
- * JS type: `struct | struct | struct | struct | struct`
11
- */
12
- @frozen
13
- public indirect enum Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout {
14
- case first(PredicateWithUUID)
15
- case second(PredicateWithUUIDs)
16
- case third(PredicateWithMetadataKey)
17
- case fourth(PredicateWithStartAndEnd)
18
- case fifth(PredicateFromWorkout)
19
- }