@tryterra/react-native 0.0.0-stage → 2.2.1
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.
- package/LICENSE +21 -0
- package/README.md +142 -2
- package/TerraReactNative.podspec +48 -0
- package/android/build.gradle +87 -0
- package/android/src/bridgeCore/kotlin/README.md +1 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/BridgeBootstrap.kt +133 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/BridgeHost.kt +32 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/Conversions.kt +557 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/LauncherSlots.kt +41 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/ReadConversions.kt +250 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/Rejections.kt +150 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/StreamRegistry.kt +77 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/TerraBridge.kt +86 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/TerraBridgeOpsImpl.kt +300 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/TerraBridgeStreamsImpl.kt +50 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/TokenBroker.kt +198 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/generated/BridgeErrors.kt +217 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/generated/BridgeOps.kt +582 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/generated/BridgeTypes.kt +1569 -0
- package/android/src/healthConnectOnly/kotlin/co/tryterra/sdk/reactnative/TerraStores.kt +11 -0
- package/android/src/main/AndroidManifest.xml +24 -0
- package/android/src/main/java/co/tryterra/sdk/reactnative/TerraBridgeModule.kt +96 -0
- package/android/src/main/java/co/tryterra/sdk/reactnative/TerraReactNativePackage.kt +26 -0
- package/android/src/main/java/co/tryterra/sdk/reactnative/TerraStartup.kt +46 -0
- package/android/src/samsung/kotlin/co/tryterra/sdk/reactnative/TerraStores.kt +13 -0
- package/docs/availability.md +396 -0
- package/frameworks/TerraSDK.xcframework/Info.plist +48 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/Info.plist +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios.abi.json +82672 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios.package.swiftinterface +2186 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +2186 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios.swiftinterface +2163 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/PrivacyInfo.xcprivacy +96 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/TerraSDK +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/dSYMs/TerraSDK.framework.dSYM/Contents/Info.plist +20 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/dSYMs/TerraSDK.framework.dSYM/Contents/Resources/DWARF/TerraSDK +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/dSYMs/TerraSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/TerraSDK.yml +6594 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Info.plist +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +82672 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios-simulator.package.swiftinterface +2186 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +2186 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +2163 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +82672 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/x86_64-apple-ios-simulator.package.swiftinterface +2186 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +2186 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +2163 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/PrivacyInfo.xcprivacy +96 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/TerraSDK +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/_CodeSignature/CodeResources +223 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/TerraSDK.framework.dSYM/Contents/Info.plist +20 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/TerraSDK.framework.dSYM/Contents/Resources/DWARF/TerraSDK +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/TerraSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/TerraSDK.yml +6595 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/TerraSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/TerraSDK.yml +6513 -0
- package/ios/TerraBridgeCore/BridgeBootstrap.swift +89 -0
- package/ios/TerraBridgeCore/BridgeHost.swift +13 -0
- package/ios/TerraBridgeCore/Conversions+Reads.swift +259 -0
- package/ios/TerraBridgeCore/Conversions.swift +594 -0
- package/ios/TerraBridgeCore/Generated/BridgeErrors.swift +179 -0
- package/ios/TerraBridgeCore/Generated/BridgeOps.swift +967 -0
- package/ios/TerraBridgeCore/Generated/BridgeTypes.swift +2050 -0
- package/ios/TerraBridgeCore/Locked.swift +15 -0
- package/ios/TerraBridgeCore/README.md +1 -0
- package/ios/TerraBridgeCore/Rejections.swift +130 -0
- package/ios/TerraBridgeCore/RuntimeAttachment.swift +60 -0
- package/ios/TerraBridgeCore/StreamRegistry.swift +59 -0
- package/ios/TerraBridgeCore/TerraBridge.swift +122 -0
- package/ios/TerraBridgeCore/TerraBridgeOpsImpl.swift +318 -0
- package/ios/TerraBridgeCore/TerraBridgeStreamsImpl.swift +60 -0
- package/ios/TerraBridgeCore/TokenBroker.swift +147 -0
- package/ios/TerraBridgeModule.mm +79 -0
- package/ios/TerraBridgeModuleImpl.swift +49 -0
- package/ios/TerraReactNative.swift +19 -0
- package/lib/EndUser.d.ts +12 -0
- package/lib/EndUser.js +13 -0
- package/lib/NativeTerraBridge.d.ts +23 -0
- package/lib/NativeTerraBridge.js +13 -0
- package/lib/Terra.d.ts +223 -0
- package/lib/Terra.js +336 -0
- package/lib/TerraError.d.ts +42 -0
- package/lib/TerraError.js +95 -0
- package/lib/createTerra.d.ts +8 -0
- package/lib/createTerra.js +19 -0
- package/lib/generated/client.d.ts +128 -0
- package/lib/generated/client.js +256 -0
- package/lib/generated/codecs.d.ts +219 -0
- package/lib/generated/codecs.js +2066 -0
- package/lib/generated/errors.d.ts +13 -0
- package/lib/generated/errors.js +68 -0
- package/lib/generated/ops.d.ts +13 -0
- package/lib/generated/ops.js +161 -0
- package/lib/generated/streams.d.ts +23 -0
- package/lib/generated/streams.js +58 -0
- package/lib/generated/types.d.ts +794 -0
- package/lib/generated/types.js +224 -0
- package/lib/index.d.ts +29 -0
- package/lib/index.js +55 -0
- package/package.json +71 -4
- package/src/EndUser.ts +15 -0
- package/src/NativeTerraBridge.ts +27 -0
- package/src/Terra.ts +592 -0
- package/src/TerraError.ts +116 -0
- package/src/createTerra.ts +18 -0
- package/src/generated/client.ts +315 -0
- package/src/generated/codecs.ts +1989 -0
- package/src/generated/errors.ts +113 -0
- package/src/generated/ops.ts +233 -0
- package/src/generated/streams.ts +74 -0
- package/src/generated/types.ts +1222 -0
- package/src/index.ts +54 -0
|
@@ -0,0 +1,1989 @@
|
|
|
1
|
+
// Generated from surface/terra-surface.json by surface/gen. Do not edit by hand.
|
|
2
|
+
// Regenerate with: node surface/gen/src/cli.ts generate
|
|
3
|
+
|
|
4
|
+
import type { Source, DataCategory, PermissionStatus, MotionContext, Nutrient, MealType, MenstruationFlow, BiologicalSex, ActivityMoveMode, BackgroundRestrictionReason, DiagnosticsReason, DeviceKeyRevokeOutcome, FailureCode, WorkoutSchedulingStatus, DayTotalMetric, IntradayMetric, WorkoutIntensityMetric, BodyMetric, BloodGlucoseUnit, GlucoseMealTime, GlucoseSpecimen, BodyTemperatureMetric, HeartRateVariabilityMetric, VO2MaxTestType, MenstrualEventKind, EndUser, TimeRange, SleepStage, WorkoutActivity, DiagnosticsState, StreamMessage, BodyReadingKind, StoreAvailability, SampleSource, Connection, HeartRateSample, StepCount, SleepSegment, Workout, DietaryQuantity, MenstruationFlowDay, AthleteProfile, HealthChange, WorkoutScope, HealthAccess, HeartRateEntry, StepEntry, SleepEntry, WorkoutEntry, BodyEntry, Nutrients, NutritionEntry, TerraErrorPayload, PlannedWorkout, TerraEvent, SupportReport, BootstrapState, TokenRequest, Empty, SourceRequest, RangeRequest, CategoryRequest, RecordIdRequest, ConnectRequest, PermissionRequest, PermissionGrant, TokenResolveRequest, TokenRejectRequest, TokenProviderRequest, MarkCompleteRequest, BoolResult, StatusResult, StatusesResult, RecordIdList, ConnectionList, HeartRateList, StepCountList, SleepSegmentList, WorkoutList, DietaryQuantityList, MenstruationFlowDayList, MenstrualEvent, MenstrualEventList, AthleteProfileResult, PlannedWorkoutList, WorkoutScheduling, LastDeliveryResult, HeartRateEntryList, BodyEntryList, StepEntryList, SleepEntryList, WorkoutEntryList, NutritionEntryList, DayTotal, IntradaySample, RestingHeartRateSample, BodyReading, RoutePoint, WorkoutRoute, WorkoutIntensitySample, HydrationSample, DayTotalList, IntradaySampleList, RestingHeartRateList, BodyReadingList, WorkoutRouteList, WorkoutIntensityList, HydrationList, AvailabilityResult } from "./types";
|
|
5
|
+
|
|
6
|
+
function encodeInstant(value: Date): string {
|
|
7
|
+
return value.toISOString();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function decodeInstant(value: unknown, at: string): Date {
|
|
11
|
+
if (typeof value !== 'string') throw new TypeError(`${at}: expected an ISO 8601 string`);
|
|
12
|
+
// `new Date` reads a string with no offset as device-local time and shifts the instant.
|
|
13
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(value)) {
|
|
14
|
+
throw new TypeError(`${at}: not a millisecond UTC instant`);
|
|
15
|
+
}
|
|
16
|
+
const parsed = new Date(value);
|
|
17
|
+
if (Number.isNaN(parsed.getTime()) || parsed.toISOString() !== value) {
|
|
18
|
+
throw new TypeError(`${at}: not a valid instant`);
|
|
19
|
+
}
|
|
20
|
+
return parsed;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function asObject(value: unknown, at: string): Record<string, unknown> {
|
|
24
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
25
|
+
throw new TypeError(`${at}: expected an object`);
|
|
26
|
+
}
|
|
27
|
+
return value as Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function asArray(value: unknown, at: string): readonly unknown[] {
|
|
31
|
+
if (!Array.isArray(value)) throw new TypeError(`${at}: expected an array`);
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Checked rather than cast.
|
|
37
|
+
*
|
|
38
|
+
* `value as number` on a string produces a `number`-typed value that is a string, and the
|
|
39
|
+
* failure then happens in the caller's arithmetic with no mention of the bridge. Rejecting at
|
|
40
|
+
* the boundary names the field that was wrong.
|
|
41
|
+
*/
|
|
42
|
+
function asNumber(value: unknown, at: string): number {
|
|
43
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
44
|
+
throw new TypeError(`${at}: expected a number`);
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function asInteger(value: unknown, at: string): number {
|
|
50
|
+
if (typeof value !== 'number' || !Number.isInteger(value)) {
|
|
51
|
+
throw new TypeError(`${at}: expected an integer`);
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function caseSet<T extends string>(items: readonly T[]): T[] {
|
|
57
|
+
return [...new Set(items)].sort();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function asBoolean(value: unknown, at: string): boolean {
|
|
61
|
+
if (typeof value !== 'boolean') throw new TypeError(`${at}: expected a boolean`);
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function asString(value: unknown, at: string): string {
|
|
66
|
+
if (typeof value !== 'string') throw new TypeError(`${at}: expected a string`);
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function optional<T>(value: unknown, read: (value: unknown) => T): T | undefined {
|
|
71
|
+
return value === undefined || value === null ? undefined : read(value);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const SourceCases: ReadonlySet<string> = new Set(["health", "samsungHealth"]);
|
|
75
|
+
|
|
76
|
+
/** Narrows an untyped value to Source, or throws naming the field. */
|
|
77
|
+
export function asSource(value: unknown, at = "Source"): Source {
|
|
78
|
+
if (typeof value !== "string" || !SourceCases.has(value)) {
|
|
79
|
+
throw new TypeError(`${at}: ${String(value)} is not a Source`);
|
|
80
|
+
}
|
|
81
|
+
return value as Source;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const DataCategoryCases: ReadonlySet<string> = new Set(["activity", "body", "daily", "sleep", "nutrition", "menstruation", "athlete"]);
|
|
85
|
+
|
|
86
|
+
/** Narrows an untyped value to DataCategory, or throws naming the field. */
|
|
87
|
+
export function asDataCategory(value: unknown, at = "DataCategory"): DataCategory {
|
|
88
|
+
if (typeof value !== "string" || !DataCategoryCases.has(value)) {
|
|
89
|
+
throw new TypeError(`${at}: ${String(value)} is not a DataCategory`);
|
|
90
|
+
}
|
|
91
|
+
return value as DataCategory;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const PermissionStatusCases: ReadonlySet<string> = new Set(["granted", "denied", "notDetermined", "notDisclosed", "unsupported", "unavailable"]);
|
|
95
|
+
|
|
96
|
+
/** Narrows an untyped value to PermissionStatus, or throws naming the field. */
|
|
97
|
+
export function asPermissionStatus(value: unknown, at = "PermissionStatus"): PermissionStatus {
|
|
98
|
+
if (typeof value !== "string" || !PermissionStatusCases.has(value)) {
|
|
99
|
+
throw new TypeError(`${at}: ${String(value)} is not a PermissionStatus`);
|
|
100
|
+
}
|
|
101
|
+
return value as PermissionStatus;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const MotionContextCases: ReadonlySet<string> = new Set(["unknown", "sedentary", "active"]);
|
|
105
|
+
|
|
106
|
+
/** Narrows an untyped value to MotionContext. A string it does not name is `unknown`; anything else throws. */
|
|
107
|
+
export function asMotionContext(value: unknown, at = "MotionContext"): MotionContext {
|
|
108
|
+
if (typeof value !== "string") {
|
|
109
|
+
throw new TypeError(`${at}: ${String(value)} is not a MotionContext`);
|
|
110
|
+
}
|
|
111
|
+
if (!MotionContextCases.has(value)) return "unknown";
|
|
112
|
+
return value as MotionContext;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const NutrientCases: ReadonlySet<string> = new Set(["energyConsumed", "protein", "carbohydrates", "fatTotal", "fatSaturated", "fatMonounsaturated", "fatPolyunsaturated", "sugar", "fiber", "cholesterol", "sodium", "potassium", "calcium", "iron", "magnesium", "zinc", "phosphorus", "iodine", "manganese", "molybdenum", "selenium", "copper", "chromium", "chloride", "caffeine", "vitaminA", "vitaminC", "vitaminD", "vitaminE", "vitaminK", "vitaminB6", "vitaminB12", "thiamin", "riboflavin", "niacin", "folate", "biotin", "pantothenicAcid"]);
|
|
116
|
+
|
|
117
|
+
/** Narrows an untyped value to Nutrient, or throws naming the field. */
|
|
118
|
+
export function asNutrient(value: unknown, at = "Nutrient"): Nutrient {
|
|
119
|
+
if (typeof value !== "string" || !NutrientCases.has(value)) {
|
|
120
|
+
throw new TypeError(`${at}: ${String(value)} is not a Nutrient`);
|
|
121
|
+
}
|
|
122
|
+
return value as Nutrient;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const MealTypeCases: ReadonlySet<string> = new Set(["breakfast", "lunch", "dinner", "snack", "unknown"]);
|
|
126
|
+
|
|
127
|
+
/** Narrows an untyped value to MealType. A string it does not name is `unknown`; anything else throws. */
|
|
128
|
+
export function asMealType(value: unknown, at = "MealType"): MealType {
|
|
129
|
+
if (typeof value !== "string") {
|
|
130
|
+
throw new TypeError(`${at}: ${String(value)} is not a MealType`);
|
|
131
|
+
}
|
|
132
|
+
if (!MealTypeCases.has(value)) return "unknown";
|
|
133
|
+
return value as MealType;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const MenstruationFlowCases: ReadonlySet<string> = new Set(["unspecified", "light", "medium", "heavy", "none"]);
|
|
137
|
+
|
|
138
|
+
/** Narrows an untyped value to MenstruationFlow, or throws naming the field. */
|
|
139
|
+
export function asMenstruationFlow(value: unknown, at = "MenstruationFlow"): MenstruationFlow {
|
|
140
|
+
if (typeof value !== "string" || !MenstruationFlowCases.has(value)) {
|
|
141
|
+
throw new TypeError(`${at}: ${String(value)} is not a MenstruationFlow`);
|
|
142
|
+
}
|
|
143
|
+
return value as MenstruationFlow;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const BiologicalSexCases: ReadonlySet<string> = new Set(["female", "male", "other", "notSet"]);
|
|
147
|
+
|
|
148
|
+
/** Narrows an untyped value to BiologicalSex, or throws naming the field. */
|
|
149
|
+
export function asBiologicalSex(value: unknown, at = "BiologicalSex"): BiologicalSex {
|
|
150
|
+
if (typeof value !== "string" || !BiologicalSexCases.has(value)) {
|
|
151
|
+
throw new TypeError(`${at}: ${String(value)} is not a BiologicalSex`);
|
|
152
|
+
}
|
|
153
|
+
return value as BiologicalSex;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const ActivityMoveModeCases: ReadonlySet<string> = new Set(["activeEnergy", "appleMoveTime"]);
|
|
157
|
+
|
|
158
|
+
/** Narrows an untyped value to ActivityMoveMode, or throws naming the field. */
|
|
159
|
+
export function asActivityMoveMode(value: unknown, at = "ActivityMoveMode"): ActivityMoveMode {
|
|
160
|
+
if (typeof value !== "string" || !ActivityMoveModeCases.has(value)) {
|
|
161
|
+
throw new TypeError(`${at}: ${String(value)} is not a ActivityMoveMode`);
|
|
162
|
+
}
|
|
163
|
+
return value as ActivityMoveMode;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const BackgroundRestrictionReasonCases: ReadonlySet<string> = new Set(["oemRestricted", "backgroundReadDenied", "healthConnectFeatureUnavailable", "storeFeatureUnavailable", "ticksNotRunning"]);
|
|
167
|
+
|
|
168
|
+
/** Narrows an untyped value to BackgroundRestrictionReason, or throws naming the field. */
|
|
169
|
+
export function asBackgroundRestrictionReason(value: unknown, at = "BackgroundRestrictionReason"): BackgroundRestrictionReason {
|
|
170
|
+
if (typeof value !== "string" || !BackgroundRestrictionReasonCases.has(value)) {
|
|
171
|
+
throw new TypeError(`${at}: ${String(value)} is not a BackgroundRestrictionReason`);
|
|
172
|
+
}
|
|
173
|
+
return value as BackgroundRestrictionReason;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const DiagnosticsReasonCases: ReadonlySet<string> = new Set(["uploadFailed", "backfillAbandoned", "backgroundObservationUnavailable", "backgroundRestricted", "backgroundRefreshUnscheduled", "quiet", "requested"]);
|
|
177
|
+
|
|
178
|
+
/** Narrows an untyped value to DiagnosticsReason, or throws naming the field. */
|
|
179
|
+
export function asDiagnosticsReason(value: unknown, at = "DiagnosticsReason"): DiagnosticsReason {
|
|
180
|
+
if (typeof value !== "string" || !DiagnosticsReasonCases.has(value)) {
|
|
181
|
+
throw new TypeError(`${at}: ${String(value)} is not a DiagnosticsReason`);
|
|
182
|
+
}
|
|
183
|
+
return value as DiagnosticsReason;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const DeviceKeyRevokeOutcomeCases: ReadonlySet<string> = new Set(["revoked", "alreadyRevoked", "routeAbsent"]);
|
|
187
|
+
|
|
188
|
+
/** Narrows an untyped value to DeviceKeyRevokeOutcome, or throws naming the field. */
|
|
189
|
+
export function asDeviceKeyRevokeOutcome(value: unknown, at = "DeviceKeyRevokeOutcome"): DeviceKeyRevokeOutcome {
|
|
190
|
+
if (typeof value !== "string" || !DeviceKeyRevokeOutcomeCases.has(value)) {
|
|
191
|
+
throw new TypeError(`${at}: ${String(value)} is not a DeviceKeyRevokeOutcome`);
|
|
192
|
+
}
|
|
193
|
+
return value as DeviceKeyRevokeOutcome;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const FailureCodeCases: ReadonlySet<string> = new Set(["healthDataUnavailable", "notConnected", "tokenUnavailable", "tokenRejected", "tokenProviderFailed", "offline", "timedOut", "serverError", "transport", "malformedResponse", "userLimitReached", "upgradeRequired", "platform", "deviceKeyUnavailable", "signatureRejected", "linkRevoked", "linkConflict", "clockSkewed", "devIDMismatch", "syncAlreadyRunning", "linkAlreadyRunning", "storeLocked", "storeUnreadable", "deadlineExceeded", "permissionDenied", "authorizationNotDetermined", "sampleNotFound", "rollbackIncomplete", "distanceNotAttributable", "bloodPressureIncomplete", "authorizationUnavailableInExtension", "routeAwaitingConverter", "readQuotaExceeded", "plannedWorkoutUnnamed"]);
|
|
197
|
+
|
|
198
|
+
/** Narrows an untyped value to FailureCode, or throws naming the field. */
|
|
199
|
+
export function asFailureCode(value: unknown, at = "FailureCode"): FailureCode {
|
|
200
|
+
if (typeof value !== "string" || !FailureCodeCases.has(value)) {
|
|
201
|
+
throw new TypeError(`${at}: ${String(value)} is not a FailureCode`);
|
|
202
|
+
}
|
|
203
|
+
return value as FailureCode;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const WorkoutSchedulingStatusCases: ReadonlySet<string> = new Set(["unsupported", "notDetermined", "denied", "authorized"]);
|
|
207
|
+
|
|
208
|
+
/** Narrows an untyped value to WorkoutSchedulingStatus, or throws naming the field. */
|
|
209
|
+
export function asWorkoutSchedulingStatus(value: unknown, at = "WorkoutSchedulingStatus"): WorkoutSchedulingStatus {
|
|
210
|
+
if (typeof value !== "string" || !WorkoutSchedulingStatusCases.has(value)) {
|
|
211
|
+
throw new TypeError(`${at}: ${String(value)} is not a WorkoutSchedulingStatus`);
|
|
212
|
+
}
|
|
213
|
+
return value as WorkoutSchedulingStatus;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const DayTotalMetricCases: ReadonlySet<string> = new Set(["distanceWalkingRunning", "distanceCycling", "distanceSwimming", "distanceWheelchair", "activeEnergyBurned", "basalEnergyBurned", "flightsClimbed", "appleExerciseTime"]);
|
|
217
|
+
|
|
218
|
+
/** Narrows an untyped value to DayTotalMetric, or throws naming the field. */
|
|
219
|
+
export function asDayTotalMetric(value: unknown, at = "DayTotalMetric"): DayTotalMetric {
|
|
220
|
+
if (typeof value !== "string" || !DayTotalMetricCases.has(value)) {
|
|
221
|
+
throw new TypeError(`${at}: ${String(value)} is not a DayTotalMetric`);
|
|
222
|
+
}
|
|
223
|
+
return value as DayTotalMetric;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const IntradayMetricCases: ReadonlySet<string> = new Set(["activeEnergy", "basalEnergy", "distance", "floorsClimbed"]);
|
|
227
|
+
|
|
228
|
+
/** Narrows an untyped value to IntradayMetric, or throws naming the field. */
|
|
229
|
+
export function asIntradayMetric(value: unknown, at = "IntradayMetric"): IntradayMetric {
|
|
230
|
+
if (typeof value !== "string" || !IntradayMetricCases.has(value)) {
|
|
231
|
+
throw new TypeError(`${at}: ${String(value)} is not a IntradayMetric`);
|
|
232
|
+
}
|
|
233
|
+
return value as IntradayMetric;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const WorkoutIntensityMetricCases: ReadonlySet<string> = new Set(["speed", "power", "cadence"]);
|
|
237
|
+
|
|
238
|
+
/** Narrows an untyped value to WorkoutIntensityMetric, or throws naming the field. */
|
|
239
|
+
export function asWorkoutIntensityMetric(value: unknown, at = "WorkoutIntensityMetric"): WorkoutIntensityMetric {
|
|
240
|
+
if (typeof value !== "string" || !WorkoutIntensityMetricCases.has(value)) {
|
|
241
|
+
throw new TypeError(`${at}: ${String(value)} is not a WorkoutIntensityMetric`);
|
|
242
|
+
}
|
|
243
|
+
return value as WorkoutIntensityMetric;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const BodyMetricCases: ReadonlySet<string> = new Set(["weight", "height", "bodyFatPercentage", "leanBodyMass", "bmi"]);
|
|
247
|
+
|
|
248
|
+
/** Narrows an untyped value to BodyMetric, or throws naming the field. */
|
|
249
|
+
export function asBodyMetric(value: unknown, at = "BodyMetric"): BodyMetric {
|
|
250
|
+
if (typeof value !== "string" || !BodyMetricCases.has(value)) {
|
|
251
|
+
throw new TypeError(`${at}: ${String(value)} is not a BodyMetric`);
|
|
252
|
+
}
|
|
253
|
+
return value as BodyMetric;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const BloodGlucoseUnitCases: ReadonlySet<string> = new Set(["mg/dL", "mmol/L"]);
|
|
257
|
+
|
|
258
|
+
/** Narrows an untyped value to BloodGlucoseUnit, or throws naming the field. */
|
|
259
|
+
export function asBloodGlucoseUnit(value: unknown, at = "BloodGlucoseUnit"): BloodGlucoseUnit {
|
|
260
|
+
if (typeof value !== "string" || !BloodGlucoseUnitCases.has(value)) {
|
|
261
|
+
throw new TypeError(`${at}: ${String(value)} is not a BloodGlucoseUnit`);
|
|
262
|
+
}
|
|
263
|
+
return value as BloodGlucoseUnit;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const GlucoseMealTimeCases: ReadonlySet<string> = new Set(["preprandial", "postprandial", "unknown"]);
|
|
267
|
+
|
|
268
|
+
/** Narrows an untyped value to GlucoseMealTime. A string it does not name is `unknown`; anything else throws. */
|
|
269
|
+
export function asGlucoseMealTime(value: unknown, at = "GlucoseMealTime"): GlucoseMealTime {
|
|
270
|
+
if (typeof value !== "string") {
|
|
271
|
+
throw new TypeError(`${at}: ${String(value)} is not a GlucoseMealTime`);
|
|
272
|
+
}
|
|
273
|
+
if (!GlucoseMealTimeCases.has(value)) return "unknown";
|
|
274
|
+
return value as GlucoseMealTime;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const GlucoseSpecimenCases: ReadonlySet<string> = new Set(["capillary", "interstitial", "plasma", "serum", "tears", "wholeBlood", "unknown"]);
|
|
278
|
+
|
|
279
|
+
/** Narrows an untyped value to GlucoseSpecimen. A string it does not name is `unknown`; anything else throws. */
|
|
280
|
+
export function asGlucoseSpecimen(value: unknown, at = "GlucoseSpecimen"): GlucoseSpecimen {
|
|
281
|
+
if (typeof value !== "string") {
|
|
282
|
+
throw new TypeError(`${at}: ${String(value)} is not a GlucoseSpecimen`);
|
|
283
|
+
}
|
|
284
|
+
if (!GlucoseSpecimenCases.has(value)) return "unknown";
|
|
285
|
+
return value as GlucoseSpecimen;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const BodyTemperatureMetricCases: ReadonlySet<string> = new Set(["body", "basal", "wrist", "skin"]);
|
|
289
|
+
|
|
290
|
+
/** Narrows an untyped value to BodyTemperatureMetric, or throws naming the field. */
|
|
291
|
+
export function asBodyTemperatureMetric(value: unknown, at = "BodyTemperatureMetric"): BodyTemperatureMetric {
|
|
292
|
+
if (typeof value !== "string" || !BodyTemperatureMetricCases.has(value)) {
|
|
293
|
+
throw new TypeError(`${at}: ${String(value)} is not a BodyTemperatureMetric`);
|
|
294
|
+
}
|
|
295
|
+
return value as BodyTemperatureMetric;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const HeartRateVariabilityMetricCases: ReadonlySet<string> = new Set(["sdnn", "rmssd"]);
|
|
299
|
+
|
|
300
|
+
/** Narrows an untyped value to HeartRateVariabilityMetric, or throws naming the field. */
|
|
301
|
+
export function asHeartRateVariabilityMetric(value: unknown, at = "HeartRateVariabilityMetric"): HeartRateVariabilityMetric {
|
|
302
|
+
if (typeof value !== "string" || !HeartRateVariabilityMetricCases.has(value)) {
|
|
303
|
+
throw new TypeError(`${at}: ${String(value)} is not a HeartRateVariabilityMetric`);
|
|
304
|
+
}
|
|
305
|
+
return value as HeartRateVariabilityMetric;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const VO2MaxTestTypeCases: ReadonlySet<string> = new Set(["maxExercise", "predictedSubMaxExercise", "predictedNonExercise"]);
|
|
309
|
+
|
|
310
|
+
/** Narrows an untyped value to VO2MaxTestType, or throws naming the field. */
|
|
311
|
+
export function asVO2MaxTestType(value: unknown, at = "VO2MaxTestType"): VO2MaxTestType {
|
|
312
|
+
if (typeof value !== "string" || !VO2MaxTestTypeCases.has(value)) {
|
|
313
|
+
throw new TypeError(`${at}: ${String(value)} is not a VO2MaxTestType`);
|
|
314
|
+
}
|
|
315
|
+
return value as VO2MaxTestType;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const MenstrualEventKindCases: ReadonlySet<string> = new Set(["intermenstrualBleeding", "ovulationTest", "cervicalMucus"]);
|
|
319
|
+
|
|
320
|
+
/** Narrows an untyped value to MenstrualEventKind, or throws naming the field. */
|
|
321
|
+
export function asMenstrualEventKind(value: unknown, at = "MenstrualEventKind"): MenstrualEventKind {
|
|
322
|
+
if (typeof value !== "string" || !MenstrualEventKindCases.has(value)) {
|
|
323
|
+
throw new TypeError(`${at}: ${String(value)} is not a MenstrualEventKind`);
|
|
324
|
+
}
|
|
325
|
+
return value as MenstrualEventKind;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export function encodeSampleSource(value: SampleSource): Record<string, unknown> {
|
|
329
|
+
const out: Record<string, unknown> = {};
|
|
330
|
+
out.name = value.name;
|
|
331
|
+
out.bundleId = value.bundleId;
|
|
332
|
+
if (value.productType !== undefined) out.productType = value.productType;
|
|
333
|
+
if (value.deviceType !== undefined) out.deviceType = value.deviceType;
|
|
334
|
+
return out;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export function decodeSampleSource(raw: unknown, at$ = "SampleSource"): SampleSource {
|
|
338
|
+
const object = asObject(raw, at$);
|
|
339
|
+
const name = asString(object.name, `${at$}.name`);
|
|
340
|
+
const bundleId = asString(object.bundleId, `${at$}.bundleId`);
|
|
341
|
+
const productType = optional(object.productType, (value) => asString(value, `${at$}.productType`));
|
|
342
|
+
const deviceType = optional(object.deviceType, (value) => asString(value, `${at$}.deviceType`));
|
|
343
|
+
return { name, bundleId, productType, deviceType };
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export function encodeConnection(value: Connection): Record<string, unknown> {
|
|
347
|
+
const out: Record<string, unknown> = {};
|
|
348
|
+
out.source = value.source;
|
|
349
|
+
out.userId = value.userId;
|
|
350
|
+
if (value.providerUserId !== undefined) out.providerUserId = value.providerUserId;
|
|
351
|
+
return out;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export function decodeConnection(raw: unknown, at$ = "Connection"): Connection {
|
|
355
|
+
const object = asObject(raw, at$);
|
|
356
|
+
const source = asSource(object.source, `${at$}.source`);
|
|
357
|
+
const userId = asString(object.userId, `${at$}.userId`);
|
|
358
|
+
const providerUserId = optional(object.providerUserId, (value) => asString(value, `${at$}.providerUserId`));
|
|
359
|
+
return { source, userId, providerUserId };
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export function encodeHeartRateSample(value: HeartRateSample): Record<string, unknown> {
|
|
363
|
+
const out: Record<string, unknown> = {};
|
|
364
|
+
out.id = value.id;
|
|
365
|
+
out.time = encodeInstant(value.time);
|
|
366
|
+
out.beatsPerMinute = value.beatsPerMinute;
|
|
367
|
+
out.source = encodeSampleSource(value.source);
|
|
368
|
+
if (value.motionContext !== undefined) out.motionContext = value.motionContext;
|
|
369
|
+
out.userEntered = value.userEntered;
|
|
370
|
+
if (value.timeZone !== undefined) out.timeZone = value.timeZone;
|
|
371
|
+
return out;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export function decodeHeartRateSample(raw: unknown, at$ = "HeartRateSample"): HeartRateSample {
|
|
375
|
+
const object = asObject(raw, at$);
|
|
376
|
+
const id = asString(object.id, `${at$}.id`);
|
|
377
|
+
const time = decodeInstant(object.time, `${at$}.time`);
|
|
378
|
+
const beatsPerMinute = asNumber(object.beatsPerMinute, `${at$}.beatsPerMinute`);
|
|
379
|
+
const source = decodeSampleSource(object.source, `${at$}.source`);
|
|
380
|
+
const motionContext = optional(object.motionContext, (value) => asMotionContext(value, `${at$}.motionContext`));
|
|
381
|
+
const userEntered = asBoolean(object.userEntered, `${at$}.userEntered`);
|
|
382
|
+
const timeZone = optional(object.timeZone, (value) => asString(value, `${at$}.timeZone`));
|
|
383
|
+
return { id, time, beatsPerMinute, source, motionContext, userEntered, timeZone };
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export function encodeStepCount(value: StepCount): Record<string, unknown> {
|
|
387
|
+
const out: Record<string, unknown> = {};
|
|
388
|
+
if (value.id !== undefined) out.id = value.id;
|
|
389
|
+
out.start = encodeInstant(value.start);
|
|
390
|
+
out.end = encodeInstant(value.end);
|
|
391
|
+
out.steps = value.steps;
|
|
392
|
+
out.source = encodeSampleSource(value.source);
|
|
393
|
+
out.userEntered = value.userEntered;
|
|
394
|
+
if (value.timeZone !== undefined) out.timeZone = value.timeZone;
|
|
395
|
+
return out;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export function decodeStepCount(raw: unknown, at$ = "StepCount"): StepCount {
|
|
399
|
+
const object = asObject(raw, at$);
|
|
400
|
+
const id = optional(object.id, (value) => asString(value, `${at$}.id`));
|
|
401
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
402
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
403
|
+
const steps = asInteger(object.steps, `${at$}.steps`);
|
|
404
|
+
const source = decodeSampleSource(object.source, `${at$}.source`);
|
|
405
|
+
const userEntered = asBoolean(object.userEntered, `${at$}.userEntered`);
|
|
406
|
+
const timeZone = optional(object.timeZone, (value) => asString(value, `${at$}.timeZone`));
|
|
407
|
+
return { id, start, end, steps, source, userEntered, timeZone };
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export function encodeSleepSegment(value: SleepSegment): Record<string, unknown> {
|
|
411
|
+
const out: Record<string, unknown> = {};
|
|
412
|
+
out.id = value.id;
|
|
413
|
+
out.start = encodeInstant(value.start);
|
|
414
|
+
out.end = encodeInstant(value.end);
|
|
415
|
+
out.stage = encodeSleepStage(value.stage);
|
|
416
|
+
out.source = encodeSampleSource(value.source);
|
|
417
|
+
out.userEntered = value.userEntered;
|
|
418
|
+
if (value.timeZone !== undefined) out.timeZone = value.timeZone;
|
|
419
|
+
return out;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export function decodeSleepSegment(raw: unknown, at$ = "SleepSegment"): SleepSegment {
|
|
423
|
+
const object = asObject(raw, at$);
|
|
424
|
+
const id = asString(object.id, `${at$}.id`);
|
|
425
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
426
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
427
|
+
const stage = decodeSleepStage(object.stage, `${at$}.stage`);
|
|
428
|
+
const source = decodeSampleSource(object.source, `${at$}.source`);
|
|
429
|
+
const userEntered = asBoolean(object.userEntered, `${at$}.userEntered`);
|
|
430
|
+
const timeZone = optional(object.timeZone, (value) => asString(value, `${at$}.timeZone`));
|
|
431
|
+
return { id, start, end, stage, source, userEntered, timeZone };
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export function encodeWorkout(value: Workout): Record<string, unknown> {
|
|
435
|
+
const out: Record<string, unknown> = {};
|
|
436
|
+
out.id = value.id;
|
|
437
|
+
out.start = encodeInstant(value.start);
|
|
438
|
+
out.end = encodeInstant(value.end);
|
|
439
|
+
out.activity = encodeWorkoutActivity(value.activity);
|
|
440
|
+
out.activityTypeCode = value.activityTypeCode;
|
|
441
|
+
if (value.indoor !== undefined) out.indoor = value.indoor;
|
|
442
|
+
if (value.activeEnergyKilocalories !== undefined) out.activeEnergyKilocalories = value.activeEnergyKilocalories;
|
|
443
|
+
if (value.distanceMeters !== undefined) out.distanceMeters = value.distanceMeters;
|
|
444
|
+
out.source = encodeSampleSource(value.source);
|
|
445
|
+
out.userEntered = value.userEntered;
|
|
446
|
+
if (value.timeZone !== undefined) out.timeZone = value.timeZone;
|
|
447
|
+
if (value.title !== undefined) out.title = value.title;
|
|
448
|
+
return out;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export function decodeWorkout(raw: unknown, at$ = "Workout"): Workout {
|
|
452
|
+
const object = asObject(raw, at$);
|
|
453
|
+
const id = asString(object.id, `${at$}.id`);
|
|
454
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
455
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
456
|
+
const activity = decodeWorkoutActivity(object.activity, `${at$}.activity`);
|
|
457
|
+
const activityTypeCode = asInteger(object.activityTypeCode, `${at$}.activityTypeCode`);
|
|
458
|
+
const indoor = optional(object.indoor, (value) => asBoolean(value, `${at$}.indoor`));
|
|
459
|
+
const activeEnergyKilocalories = optional(object.activeEnergyKilocalories, (value) => asNumber(value, `${at$}.activeEnergyKilocalories`));
|
|
460
|
+
const distanceMeters = optional(object.distanceMeters, (value) => asNumber(value, `${at$}.distanceMeters`));
|
|
461
|
+
const source = decodeSampleSource(object.source, `${at$}.source`);
|
|
462
|
+
const userEntered = asBoolean(object.userEntered, `${at$}.userEntered`);
|
|
463
|
+
const timeZone = optional(object.timeZone, (value) => asString(value, `${at$}.timeZone`));
|
|
464
|
+
const title = optional(object.title, (value) => asString(value, `${at$}.title`));
|
|
465
|
+
return { id, start, end, activity, activityTypeCode, indoor, activeEnergyKilocalories, distanceMeters, source, userEntered, timeZone, title };
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export function encodeDietaryQuantity(value: DietaryQuantity): Record<string, unknown> {
|
|
469
|
+
const out: Record<string, unknown> = {};
|
|
470
|
+
out.id = value.id;
|
|
471
|
+
out.nutrient = value.nutrient;
|
|
472
|
+
out.value = value.value;
|
|
473
|
+
out.start = encodeInstant(value.start);
|
|
474
|
+
out.end = encodeInstant(value.end);
|
|
475
|
+
out.mealType = value.mealType;
|
|
476
|
+
if (value.name !== undefined) out.name = value.name;
|
|
477
|
+
if (value.foodCorrelationId !== undefined) out.foodCorrelationId = value.foodCorrelationId;
|
|
478
|
+
out.source = encodeSampleSource(value.source);
|
|
479
|
+
out.userEntered = value.userEntered;
|
|
480
|
+
if (value.timeZone !== undefined) out.timeZone = value.timeZone;
|
|
481
|
+
return out;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export function decodeDietaryQuantity(raw: unknown, at$ = "DietaryQuantity"): DietaryQuantity {
|
|
485
|
+
const object = asObject(raw, at$);
|
|
486
|
+
const id = asString(object.id, `${at$}.id`);
|
|
487
|
+
const nutrient = asNutrient(object.nutrient, `${at$}.nutrient`);
|
|
488
|
+
const value = asNumber(object.value, `${at$}.value`);
|
|
489
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
490
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
491
|
+
const mealType = asMealType(object.mealType, `${at$}.mealType`);
|
|
492
|
+
const name = optional(object.name, (value) => asString(value, `${at$}.name`));
|
|
493
|
+
const foodCorrelationId = optional(object.foodCorrelationId, (value) => asString(value, `${at$}.foodCorrelationId`));
|
|
494
|
+
const source = decodeSampleSource(object.source, `${at$}.source`);
|
|
495
|
+
const userEntered = asBoolean(object.userEntered, `${at$}.userEntered`);
|
|
496
|
+
const timeZone = optional(object.timeZone, (value) => asString(value, `${at$}.timeZone`));
|
|
497
|
+
return { id, nutrient, value, start, end, mealType, name, foodCorrelationId, source, userEntered, timeZone };
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
export function encodeMenstruationFlowDay(value: MenstruationFlowDay): Record<string, unknown> {
|
|
501
|
+
const out: Record<string, unknown> = {};
|
|
502
|
+
out.id = value.id;
|
|
503
|
+
out.start = encodeInstant(value.start);
|
|
504
|
+
out.end = encodeInstant(value.end);
|
|
505
|
+
out.flow = value.flow;
|
|
506
|
+
out.cycleStart = value.cycleStart;
|
|
507
|
+
out.source = encodeSampleSource(value.source);
|
|
508
|
+
out.userEntered = value.userEntered;
|
|
509
|
+
if (value.timeZone !== undefined) out.timeZone = value.timeZone;
|
|
510
|
+
return out;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export function decodeMenstruationFlowDay(raw: unknown, at$ = "MenstruationFlowDay"): MenstruationFlowDay {
|
|
514
|
+
const object = asObject(raw, at$);
|
|
515
|
+
const id = asString(object.id, `${at$}.id`);
|
|
516
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
517
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
518
|
+
const flow = asMenstruationFlow(object.flow, `${at$}.flow`);
|
|
519
|
+
const cycleStart = asBoolean(object.cycleStart, `${at$}.cycleStart`);
|
|
520
|
+
const source = decodeSampleSource(object.source, `${at$}.source`);
|
|
521
|
+
const userEntered = asBoolean(object.userEntered, `${at$}.userEntered`);
|
|
522
|
+
const timeZone = optional(object.timeZone, (value) => asString(value, `${at$}.timeZone`));
|
|
523
|
+
return { id, start, end, flow, cycleStart, source, userEntered, timeZone };
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
export function encodeAthleteProfile(value: AthleteProfile): Record<string, unknown> {
|
|
527
|
+
const out: Record<string, unknown> = {};
|
|
528
|
+
out.biologicalSex = value.biologicalSex;
|
|
529
|
+
if (value.dateOfBirth !== undefined) out.dateOfBirth = value.dateOfBirth;
|
|
530
|
+
if (value.wheelchairUse !== undefined) out.wheelchairUse = value.wheelchairUse;
|
|
531
|
+
if (value.activityMoveMode !== undefined) out.activityMoveMode = value.activityMoveMode;
|
|
532
|
+
return out;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
export function decodeAthleteProfile(raw: unknown, at$ = "AthleteProfile"): AthleteProfile {
|
|
536
|
+
const object = asObject(raw, at$);
|
|
537
|
+
const biologicalSex = asBiologicalSex(object.biologicalSex, `${at$}.biologicalSex`);
|
|
538
|
+
const dateOfBirth = optional(object.dateOfBirth, (value) => asString(value, `${at$}.dateOfBirth`));
|
|
539
|
+
const wheelchairUse = optional(object.wheelchairUse, (value) => asBoolean(value, `${at$}.wheelchairUse`));
|
|
540
|
+
const activityMoveMode = optional(object.activityMoveMode, (value) => asActivityMoveMode(value, `${at$}.activityMoveMode`));
|
|
541
|
+
return { biologicalSex, dateOfBirth, wheelchairUse, activityMoveMode };
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export function encodeHealthChange(value: HealthChange): Record<string, unknown> {
|
|
545
|
+
const out: Record<string, unknown> = {};
|
|
546
|
+
out.category = value.category;
|
|
547
|
+
out.day = value.day;
|
|
548
|
+
return out;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
export function decodeHealthChange(raw: unknown, at$ = "HealthChange"): HealthChange {
|
|
552
|
+
const object = asObject(raw, at$);
|
|
553
|
+
const category = asDataCategory(object.category, `${at$}.category`);
|
|
554
|
+
const day = asString(object.day, `${at$}.day`);
|
|
555
|
+
return { category, day };
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
export function encodeWorkoutScope(value: WorkoutScope): Record<string, unknown> {
|
|
559
|
+
const out: Record<string, unknown> = {};
|
|
560
|
+
out.activity = encodeWorkoutActivity(value.activity);
|
|
561
|
+
out.energy = value.energy;
|
|
562
|
+
out.distance = value.distance;
|
|
563
|
+
return out;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
export function decodeWorkoutScope(raw: unknown, at$ = "WorkoutScope"): WorkoutScope {
|
|
567
|
+
const object = asObject(raw, at$);
|
|
568
|
+
const activity = decodeWorkoutActivity(object.activity, `${at$}.activity`);
|
|
569
|
+
const energy = asBoolean(object.energy, `${at$}.energy`);
|
|
570
|
+
const distance = asBoolean(object.distance, `${at$}.distance`);
|
|
571
|
+
return { activity, energy, distance };
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
export function encodeHealthAccess(value: HealthAccess): Record<string, unknown> {
|
|
575
|
+
const out: Record<string, unknown> = {};
|
|
576
|
+
out.read = caseSet(value.read);
|
|
577
|
+
out.write = caseSet(value.write);
|
|
578
|
+
out.workouts = value.workouts.map((item) => encodeWorkoutScope(item));
|
|
579
|
+
return out;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
export function decodeHealthAccess(raw: unknown, at$ = "HealthAccess"): HealthAccess {
|
|
583
|
+
const object = asObject(raw, at$);
|
|
584
|
+
const read = caseSet(asArray(object.read, `${at$}.read`).map((item, index) => asDataCategory(item, `${`${at$}.read`}[${index}]`)));
|
|
585
|
+
const write = caseSet(asArray(object.write, `${at$}.write`).map((item, index) => asDataCategory(item, `${`${at$}.write`}[${index}]`)));
|
|
586
|
+
const workouts = asArray(object.workouts, `${at$}.workouts`).map((item, index) => decodeWorkoutScope(item, `${`${at$}.workouts`}[${index}]`));
|
|
587
|
+
return { read, write, workouts };
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
export function encodeHeartRateEntry(value: HeartRateEntry): Record<string, unknown> {
|
|
591
|
+
const out: Record<string, unknown> = {};
|
|
592
|
+
out.time = encodeInstant(value.time);
|
|
593
|
+
out.beatsPerMinute = value.beatsPerMinute;
|
|
594
|
+
if (value.recordId !== undefined) out.recordId = value.recordId;
|
|
595
|
+
return out;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
export function decodeHeartRateEntry(raw: unknown, at$ = "HeartRateEntry"): HeartRateEntry {
|
|
599
|
+
const object = asObject(raw, at$);
|
|
600
|
+
const time = decodeInstant(object.time, `${at$}.time`);
|
|
601
|
+
const beatsPerMinute = asNumber(object.beatsPerMinute, `${at$}.beatsPerMinute`);
|
|
602
|
+
const recordId = optional(object.recordId, (value) => asString(value, `${at$}.recordId`));
|
|
603
|
+
return { time, beatsPerMinute, recordId };
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
export function encodeStepEntry(value: StepEntry): Record<string, unknown> {
|
|
607
|
+
const out: Record<string, unknown> = {};
|
|
608
|
+
out.start = encodeInstant(value.start);
|
|
609
|
+
out.end = encodeInstant(value.end);
|
|
610
|
+
out.steps = value.steps;
|
|
611
|
+
if (value.recordId !== undefined) out.recordId = value.recordId;
|
|
612
|
+
return out;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export function decodeStepEntry(raw: unknown, at$ = "StepEntry"): StepEntry {
|
|
616
|
+
const object = asObject(raw, at$);
|
|
617
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
618
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
619
|
+
const steps = asInteger(object.steps, `${at$}.steps`);
|
|
620
|
+
const recordId = optional(object.recordId, (value) => asString(value, `${at$}.recordId`));
|
|
621
|
+
return { start, end, steps, recordId };
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export function encodeSleepEntry(value: SleepEntry): Record<string, unknown> {
|
|
625
|
+
const out: Record<string, unknown> = {};
|
|
626
|
+
out.start = encodeInstant(value.start);
|
|
627
|
+
out.end = encodeInstant(value.end);
|
|
628
|
+
out.stage = encodeSleepStage(value.stage);
|
|
629
|
+
if (value.recordId !== undefined) out.recordId = value.recordId;
|
|
630
|
+
return out;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
export function decodeSleepEntry(raw: unknown, at$ = "SleepEntry"): SleepEntry {
|
|
634
|
+
const object = asObject(raw, at$);
|
|
635
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
636
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
637
|
+
const stage = decodeSleepStage(object.stage, `${at$}.stage`);
|
|
638
|
+
const recordId = optional(object.recordId, (value) => asString(value, `${at$}.recordId`));
|
|
639
|
+
return { start, end, stage, recordId };
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
export function encodeWorkoutEntry(value: WorkoutEntry): Record<string, unknown> {
|
|
643
|
+
const out: Record<string, unknown> = {};
|
|
644
|
+
out.start = encodeInstant(value.start);
|
|
645
|
+
out.end = encodeInstant(value.end);
|
|
646
|
+
out.activity = encodeWorkoutActivity(value.activity);
|
|
647
|
+
if (value.totalEnergyKilocalories !== undefined) out.totalEnergyKilocalories = value.totalEnergyKilocalories;
|
|
648
|
+
if (value.totalDistanceMeters !== undefined) out.totalDistanceMeters = value.totalDistanceMeters;
|
|
649
|
+
if (value.recordId !== undefined) out.recordId = value.recordId;
|
|
650
|
+
return out;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
export function decodeWorkoutEntry(raw: unknown, at$ = "WorkoutEntry"): WorkoutEntry {
|
|
654
|
+
const object = asObject(raw, at$);
|
|
655
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
656
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
657
|
+
const activity = decodeWorkoutActivity(object.activity, `${at$}.activity`);
|
|
658
|
+
const totalEnergyKilocalories = optional(object.totalEnergyKilocalories, (value) => asNumber(value, `${at$}.totalEnergyKilocalories`));
|
|
659
|
+
const totalDistanceMeters = optional(object.totalDistanceMeters, (value) => asNumber(value, `${at$}.totalDistanceMeters`));
|
|
660
|
+
const recordId = optional(object.recordId, (value) => asString(value, `${at$}.recordId`));
|
|
661
|
+
return { start, end, activity, totalEnergyKilocalories, totalDistanceMeters, recordId };
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export function encodeBodyEntry(value: BodyEntry): Record<string, unknown> {
|
|
665
|
+
const out: Record<string, unknown> = {};
|
|
666
|
+
out.time = encodeInstant(value.time);
|
|
667
|
+
if (value.bodyMassKilograms !== undefined) out.bodyMassKilograms = value.bodyMassKilograms;
|
|
668
|
+
if (value.bodyFatPercent !== undefined) out.bodyFatPercent = value.bodyFatPercent;
|
|
669
|
+
if (value.bodyMassIndex !== undefined) out.bodyMassIndex = value.bodyMassIndex;
|
|
670
|
+
if (value.heightMeters !== undefined) out.heightMeters = value.heightMeters;
|
|
671
|
+
if (value.leanBodyMassKilograms !== undefined) out.leanBodyMassKilograms = value.leanBodyMassKilograms;
|
|
672
|
+
if (value.bodyTemperatureCelsius !== undefined) out.bodyTemperatureCelsius = value.bodyTemperatureCelsius;
|
|
673
|
+
if (value.oxygenSaturationPercent !== undefined) out.oxygenSaturationPercent = value.oxygenSaturationPercent;
|
|
674
|
+
if (value.bloodGlucoseMilligramsPerDeciliter !== undefined) out.bloodGlucoseMilligramsPerDeciliter = value.bloodGlucoseMilligramsPerDeciliter;
|
|
675
|
+
if (value.bloodPressureSystolicMillimetersOfMercury !== undefined) out.bloodPressureSystolicMillimetersOfMercury = value.bloodPressureSystolicMillimetersOfMercury;
|
|
676
|
+
if (value.bloodPressureDiastolicMillimetersOfMercury !== undefined) out.bloodPressureDiastolicMillimetersOfMercury = value.bloodPressureDiastolicMillimetersOfMercury;
|
|
677
|
+
if (value.recordId !== undefined) out.recordId = value.recordId;
|
|
678
|
+
return out;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
export function decodeBodyEntry(raw: unknown, at$ = "BodyEntry"): BodyEntry {
|
|
682
|
+
const object = asObject(raw, at$);
|
|
683
|
+
const time = decodeInstant(object.time, `${at$}.time`);
|
|
684
|
+
const bodyMassKilograms = optional(object.bodyMassKilograms, (value) => asNumber(value, `${at$}.bodyMassKilograms`));
|
|
685
|
+
const bodyFatPercent = optional(object.bodyFatPercent, (value) => asNumber(value, `${at$}.bodyFatPercent`));
|
|
686
|
+
const bodyMassIndex = optional(object.bodyMassIndex, (value) => asNumber(value, `${at$}.bodyMassIndex`));
|
|
687
|
+
const heightMeters = optional(object.heightMeters, (value) => asNumber(value, `${at$}.heightMeters`));
|
|
688
|
+
const leanBodyMassKilograms = optional(object.leanBodyMassKilograms, (value) => asNumber(value, `${at$}.leanBodyMassKilograms`));
|
|
689
|
+
const bodyTemperatureCelsius = optional(object.bodyTemperatureCelsius, (value) => asNumber(value, `${at$}.bodyTemperatureCelsius`));
|
|
690
|
+
const oxygenSaturationPercent = optional(object.oxygenSaturationPercent, (value) => asNumber(value, `${at$}.oxygenSaturationPercent`));
|
|
691
|
+
const bloodGlucoseMilligramsPerDeciliter = optional(object.bloodGlucoseMilligramsPerDeciliter, (value) => asNumber(value, `${at$}.bloodGlucoseMilligramsPerDeciliter`));
|
|
692
|
+
const bloodPressureSystolicMillimetersOfMercury = optional(object.bloodPressureSystolicMillimetersOfMercury, (value) => asNumber(value, `${at$}.bloodPressureSystolicMillimetersOfMercury`));
|
|
693
|
+
const bloodPressureDiastolicMillimetersOfMercury = optional(object.bloodPressureDiastolicMillimetersOfMercury, (value) => asNumber(value, `${at$}.bloodPressureDiastolicMillimetersOfMercury`));
|
|
694
|
+
const recordId = optional(object.recordId, (value) => asString(value, `${at$}.recordId`));
|
|
695
|
+
return { time, bodyMassKilograms, bodyFatPercent, bodyMassIndex, heightMeters, leanBodyMassKilograms, bodyTemperatureCelsius, oxygenSaturationPercent, bloodGlucoseMilligramsPerDeciliter, bloodPressureSystolicMillimetersOfMercury, bloodPressureDiastolicMillimetersOfMercury, recordId };
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
export function encodeNutrients(value: Nutrients): Record<string, unknown> {
|
|
699
|
+
const out: Record<string, unknown> = {};
|
|
700
|
+
if (value.energyKilocalories !== undefined) out.energyKilocalories = value.energyKilocalories;
|
|
701
|
+
if (value.proteinGrams !== undefined) out.proteinGrams = value.proteinGrams;
|
|
702
|
+
if (value.carbohydratesGrams !== undefined) out.carbohydratesGrams = value.carbohydratesGrams;
|
|
703
|
+
if (value.fiberGrams !== undefined) out.fiberGrams = value.fiberGrams;
|
|
704
|
+
if (value.sugarGrams !== undefined) out.sugarGrams = value.sugarGrams;
|
|
705
|
+
if (value.fatTotalGrams !== undefined) out.fatTotalGrams = value.fatTotalGrams;
|
|
706
|
+
if (value.fatSaturatedGrams !== undefined) out.fatSaturatedGrams = value.fatSaturatedGrams;
|
|
707
|
+
if (value.fatMonounsaturatedGrams !== undefined) out.fatMonounsaturatedGrams = value.fatMonounsaturatedGrams;
|
|
708
|
+
if (value.fatPolyunsaturatedGrams !== undefined) out.fatPolyunsaturatedGrams = value.fatPolyunsaturatedGrams;
|
|
709
|
+
if (value.cholesterolMilligrams !== undefined) out.cholesterolMilligrams = value.cholesterolMilligrams;
|
|
710
|
+
if (value.sodiumMilligrams !== undefined) out.sodiumMilligrams = value.sodiumMilligrams;
|
|
711
|
+
if (value.potassiumMilligrams !== undefined) out.potassiumMilligrams = value.potassiumMilligrams;
|
|
712
|
+
if (value.calciumMilligrams !== undefined) out.calciumMilligrams = value.calciumMilligrams;
|
|
713
|
+
if (value.ironMilligrams !== undefined) out.ironMilligrams = value.ironMilligrams;
|
|
714
|
+
if (value.magnesiumMilligrams !== undefined) out.magnesiumMilligrams = value.magnesiumMilligrams;
|
|
715
|
+
if (value.zincMilligrams !== undefined) out.zincMilligrams = value.zincMilligrams;
|
|
716
|
+
if (value.waterLiters !== undefined) out.waterLiters = value.waterLiters;
|
|
717
|
+
if (value.caffeineMilligrams !== undefined) out.caffeineMilligrams = value.caffeineMilligrams;
|
|
718
|
+
if (value.vitaminAMicrograms !== undefined) out.vitaminAMicrograms = value.vitaminAMicrograms;
|
|
719
|
+
if (value.vitaminCMilligrams !== undefined) out.vitaminCMilligrams = value.vitaminCMilligrams;
|
|
720
|
+
if (value.vitaminDMicrograms !== undefined) out.vitaminDMicrograms = value.vitaminDMicrograms;
|
|
721
|
+
if (value.vitaminEMilligrams !== undefined) out.vitaminEMilligrams = value.vitaminEMilligrams;
|
|
722
|
+
if (value.vitaminKMicrograms !== undefined) out.vitaminKMicrograms = value.vitaminKMicrograms;
|
|
723
|
+
if (value.vitaminB6Milligrams !== undefined) out.vitaminB6Milligrams = value.vitaminB6Milligrams;
|
|
724
|
+
if (value.vitaminB12Micrograms !== undefined) out.vitaminB12Micrograms = value.vitaminB12Micrograms;
|
|
725
|
+
if (value.folateMicrograms !== undefined) out.folateMicrograms = value.folateMicrograms;
|
|
726
|
+
if (value.thiaminMilligrams !== undefined) out.thiaminMilligrams = value.thiaminMilligrams;
|
|
727
|
+
if (value.riboflavinMilligrams !== undefined) out.riboflavinMilligrams = value.riboflavinMilligrams;
|
|
728
|
+
if (value.niacinMilligrams !== undefined) out.niacinMilligrams = value.niacinMilligrams;
|
|
729
|
+
if (value.biotinMicrograms !== undefined) out.biotinMicrograms = value.biotinMicrograms;
|
|
730
|
+
if (value.pantothenicAcidMilligrams !== undefined) out.pantothenicAcidMilligrams = value.pantothenicAcidMilligrams;
|
|
731
|
+
if (value.phosphorusMilligrams !== undefined) out.phosphorusMilligrams = value.phosphorusMilligrams;
|
|
732
|
+
if (value.iodineMicrograms !== undefined) out.iodineMicrograms = value.iodineMicrograms;
|
|
733
|
+
if (value.chromiumMicrograms !== undefined) out.chromiumMicrograms = value.chromiumMicrograms;
|
|
734
|
+
if (value.copperMilligrams !== undefined) out.copperMilligrams = value.copperMilligrams;
|
|
735
|
+
if (value.manganeseMilligrams !== undefined) out.manganeseMilligrams = value.manganeseMilligrams;
|
|
736
|
+
if (value.molybdenumMicrograms !== undefined) out.molybdenumMicrograms = value.molybdenumMicrograms;
|
|
737
|
+
if (value.seleniumMicrograms !== undefined) out.seleniumMicrograms = value.seleniumMicrograms;
|
|
738
|
+
if (value.chlorideMilligrams !== undefined) out.chlorideMilligrams = value.chlorideMilligrams;
|
|
739
|
+
return out;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
export function decodeNutrients(raw: unknown, at$ = "Nutrients"): Nutrients {
|
|
743
|
+
const object = asObject(raw, at$);
|
|
744
|
+
const energyKilocalories = optional(object.energyKilocalories, (value) => asNumber(value, `${at$}.energyKilocalories`));
|
|
745
|
+
const proteinGrams = optional(object.proteinGrams, (value) => asNumber(value, `${at$}.proteinGrams`));
|
|
746
|
+
const carbohydratesGrams = optional(object.carbohydratesGrams, (value) => asNumber(value, `${at$}.carbohydratesGrams`));
|
|
747
|
+
const fiberGrams = optional(object.fiberGrams, (value) => asNumber(value, `${at$}.fiberGrams`));
|
|
748
|
+
const sugarGrams = optional(object.sugarGrams, (value) => asNumber(value, `${at$}.sugarGrams`));
|
|
749
|
+
const fatTotalGrams = optional(object.fatTotalGrams, (value) => asNumber(value, `${at$}.fatTotalGrams`));
|
|
750
|
+
const fatSaturatedGrams = optional(object.fatSaturatedGrams, (value) => asNumber(value, `${at$}.fatSaturatedGrams`));
|
|
751
|
+
const fatMonounsaturatedGrams = optional(object.fatMonounsaturatedGrams, (value) => asNumber(value, `${at$}.fatMonounsaturatedGrams`));
|
|
752
|
+
const fatPolyunsaturatedGrams = optional(object.fatPolyunsaturatedGrams, (value) => asNumber(value, `${at$}.fatPolyunsaturatedGrams`));
|
|
753
|
+
const cholesterolMilligrams = optional(object.cholesterolMilligrams, (value) => asNumber(value, `${at$}.cholesterolMilligrams`));
|
|
754
|
+
const sodiumMilligrams = optional(object.sodiumMilligrams, (value) => asNumber(value, `${at$}.sodiumMilligrams`));
|
|
755
|
+
const potassiumMilligrams = optional(object.potassiumMilligrams, (value) => asNumber(value, `${at$}.potassiumMilligrams`));
|
|
756
|
+
const calciumMilligrams = optional(object.calciumMilligrams, (value) => asNumber(value, `${at$}.calciumMilligrams`));
|
|
757
|
+
const ironMilligrams = optional(object.ironMilligrams, (value) => asNumber(value, `${at$}.ironMilligrams`));
|
|
758
|
+
const magnesiumMilligrams = optional(object.magnesiumMilligrams, (value) => asNumber(value, `${at$}.magnesiumMilligrams`));
|
|
759
|
+
const zincMilligrams = optional(object.zincMilligrams, (value) => asNumber(value, `${at$}.zincMilligrams`));
|
|
760
|
+
const waterLiters = optional(object.waterLiters, (value) => asNumber(value, `${at$}.waterLiters`));
|
|
761
|
+
const caffeineMilligrams = optional(object.caffeineMilligrams, (value) => asNumber(value, `${at$}.caffeineMilligrams`));
|
|
762
|
+
const vitaminAMicrograms = optional(object.vitaminAMicrograms, (value) => asNumber(value, `${at$}.vitaminAMicrograms`));
|
|
763
|
+
const vitaminCMilligrams = optional(object.vitaminCMilligrams, (value) => asNumber(value, `${at$}.vitaminCMilligrams`));
|
|
764
|
+
const vitaminDMicrograms = optional(object.vitaminDMicrograms, (value) => asNumber(value, `${at$}.vitaminDMicrograms`));
|
|
765
|
+
const vitaminEMilligrams = optional(object.vitaminEMilligrams, (value) => asNumber(value, `${at$}.vitaminEMilligrams`));
|
|
766
|
+
const vitaminKMicrograms = optional(object.vitaminKMicrograms, (value) => asNumber(value, `${at$}.vitaminKMicrograms`));
|
|
767
|
+
const vitaminB6Milligrams = optional(object.vitaminB6Milligrams, (value) => asNumber(value, `${at$}.vitaminB6Milligrams`));
|
|
768
|
+
const vitaminB12Micrograms = optional(object.vitaminB12Micrograms, (value) => asNumber(value, `${at$}.vitaminB12Micrograms`));
|
|
769
|
+
const folateMicrograms = optional(object.folateMicrograms, (value) => asNumber(value, `${at$}.folateMicrograms`));
|
|
770
|
+
const thiaminMilligrams = optional(object.thiaminMilligrams, (value) => asNumber(value, `${at$}.thiaminMilligrams`));
|
|
771
|
+
const riboflavinMilligrams = optional(object.riboflavinMilligrams, (value) => asNumber(value, `${at$}.riboflavinMilligrams`));
|
|
772
|
+
const niacinMilligrams = optional(object.niacinMilligrams, (value) => asNumber(value, `${at$}.niacinMilligrams`));
|
|
773
|
+
const biotinMicrograms = optional(object.biotinMicrograms, (value) => asNumber(value, `${at$}.biotinMicrograms`));
|
|
774
|
+
const pantothenicAcidMilligrams = optional(object.pantothenicAcidMilligrams, (value) => asNumber(value, `${at$}.pantothenicAcidMilligrams`));
|
|
775
|
+
const phosphorusMilligrams = optional(object.phosphorusMilligrams, (value) => asNumber(value, `${at$}.phosphorusMilligrams`));
|
|
776
|
+
const iodineMicrograms = optional(object.iodineMicrograms, (value) => asNumber(value, `${at$}.iodineMicrograms`));
|
|
777
|
+
const chromiumMicrograms = optional(object.chromiumMicrograms, (value) => asNumber(value, `${at$}.chromiumMicrograms`));
|
|
778
|
+
const copperMilligrams = optional(object.copperMilligrams, (value) => asNumber(value, `${at$}.copperMilligrams`));
|
|
779
|
+
const manganeseMilligrams = optional(object.manganeseMilligrams, (value) => asNumber(value, `${at$}.manganeseMilligrams`));
|
|
780
|
+
const molybdenumMicrograms = optional(object.molybdenumMicrograms, (value) => asNumber(value, `${at$}.molybdenumMicrograms`));
|
|
781
|
+
const seleniumMicrograms = optional(object.seleniumMicrograms, (value) => asNumber(value, `${at$}.seleniumMicrograms`));
|
|
782
|
+
const chlorideMilligrams = optional(object.chlorideMilligrams, (value) => asNumber(value, `${at$}.chlorideMilligrams`));
|
|
783
|
+
return { energyKilocalories, proteinGrams, carbohydratesGrams, fiberGrams, sugarGrams, fatTotalGrams, fatSaturatedGrams, fatMonounsaturatedGrams, fatPolyunsaturatedGrams, cholesterolMilligrams, sodiumMilligrams, potassiumMilligrams, calciumMilligrams, ironMilligrams, magnesiumMilligrams, zincMilligrams, waterLiters, caffeineMilligrams, vitaminAMicrograms, vitaminCMilligrams, vitaminDMicrograms, vitaminEMilligrams, vitaminKMicrograms, vitaminB6Milligrams, vitaminB12Micrograms, folateMicrograms, thiaminMilligrams, riboflavinMilligrams, niacinMilligrams, biotinMicrograms, pantothenicAcidMilligrams, phosphorusMilligrams, iodineMicrograms, chromiumMicrograms, copperMilligrams, manganeseMilligrams, molybdenumMicrograms, seleniumMicrograms, chlorideMilligrams };
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
export function encodeNutritionEntry(value: NutritionEntry): Record<string, unknown> {
|
|
787
|
+
const out: Record<string, unknown> = {};
|
|
788
|
+
out.start = encodeInstant(value.start);
|
|
789
|
+
out.end = encodeInstant(value.end);
|
|
790
|
+
if (value.name !== undefined) out.name = value.name;
|
|
791
|
+
out.nutrients = encodeNutrients(value.nutrients);
|
|
792
|
+
if (value.recordId !== undefined) out.recordId = value.recordId;
|
|
793
|
+
return out;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
export function decodeNutritionEntry(raw: unknown, at$ = "NutritionEntry"): NutritionEntry {
|
|
797
|
+
const object = asObject(raw, at$);
|
|
798
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
799
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
800
|
+
const name = optional(object.name, (value) => asString(value, `${at$}.name`));
|
|
801
|
+
const nutrients = decodeNutrients(object.nutrients, `${at$}.nutrients`);
|
|
802
|
+
const recordId = optional(object.recordId, (value) => asString(value, `${at$}.recordId`));
|
|
803
|
+
return { start, end, name, nutrients, recordId };
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
export function encodeTerraErrorPayload(value: TerraErrorPayload): Record<string, unknown> {
|
|
807
|
+
const out: Record<string, unknown> = {};
|
|
808
|
+
out.code = value.code;
|
|
809
|
+
out.retryable = value.retryable;
|
|
810
|
+
out.message = value.message;
|
|
811
|
+
if (value.source !== undefined) out.source = value.source;
|
|
812
|
+
if (value.details !== undefined) out.details = value.details;
|
|
813
|
+
return out;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
export function decodeTerraErrorPayload(raw: unknown, at$ = "TerraErrorPayload"): TerraErrorPayload {
|
|
817
|
+
const object = asObject(raw, at$);
|
|
818
|
+
const code = asString(object.code, `${at$}.code`);
|
|
819
|
+
const retryable = asBoolean(object.retryable, `${at$}.retryable`);
|
|
820
|
+
const message = asString(object.message, `${at$}.message`);
|
|
821
|
+
const source = optional(object.source, (value) => asSource(value, `${at$}.source`));
|
|
822
|
+
const details = optional(object.details, (value) => asObject(value, `${at$}.details`));
|
|
823
|
+
return { code, retryable, message, source, details };
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
export function encodePlannedWorkout(value: PlannedWorkout): Record<string, unknown> {
|
|
827
|
+
const out: Record<string, unknown> = {};
|
|
828
|
+
out.id = value.id;
|
|
829
|
+
out.plannedOn = value.plannedOn;
|
|
830
|
+
out.activity = encodeWorkoutActivity(value.activity);
|
|
831
|
+
if (value.title !== undefined) out.title = value.title;
|
|
832
|
+
if (value.completedAt !== undefined) out.completedAt = encodeInstant(value.completedAt);
|
|
833
|
+
return out;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
export function decodePlannedWorkout(raw: unknown, at$ = "PlannedWorkout"): PlannedWorkout {
|
|
837
|
+
const object = asObject(raw, at$);
|
|
838
|
+
const id = asString(object.id, `${at$}.id`);
|
|
839
|
+
const plannedOn = asString(object.plannedOn, `${at$}.plannedOn`);
|
|
840
|
+
const activity = decodeWorkoutActivity(object.activity, `${at$}.activity`);
|
|
841
|
+
const title = optional(object.title, (value) => asString(value, `${at$}.title`));
|
|
842
|
+
const completedAt = optional(object.completedAt, (value) => decodeInstant(value, `${at$}.completedAt`));
|
|
843
|
+
return { id, plannedOn, activity, title, completedAt };
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
export function encodeTerraEvent(value: TerraEvent): Record<string, unknown> {
|
|
847
|
+
return value;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
export function decodeTerraEvent(raw: unknown, at$ = "TerraEvent"): TerraEvent {
|
|
851
|
+
const object = asObject(raw, at$);
|
|
852
|
+
if (!(typeof object["at"] === "string")) {
|
|
853
|
+
throw new TypeError(`${at$}: at is not a string`);
|
|
854
|
+
}
|
|
855
|
+
if (!(typeof object["event"] === "string")) {
|
|
856
|
+
throw new TypeError(`${at$}: event is not a string`);
|
|
857
|
+
}
|
|
858
|
+
return object;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
export function encodeSupportReport(value: SupportReport): Record<string, unknown> {
|
|
862
|
+
const out: Record<string, unknown> = {};
|
|
863
|
+
out.sdkVersion = value.sdkVersion;
|
|
864
|
+
out.generatedAt = encodeInstant(value.generatedAt);
|
|
865
|
+
out.state = encodeDiagnosticsState(value.state);
|
|
866
|
+
if (value.lastDelivery !== undefined) out.lastDelivery = encodeInstant(value.lastDelivery);
|
|
867
|
+
out.isConnected = value.isConnected;
|
|
868
|
+
out.requestedCategories = value.requestedCategories;
|
|
869
|
+
out.requestedWrites = value.requestedWrites;
|
|
870
|
+
out.requestedWorkouts = value.requestedWorkouts;
|
|
871
|
+
out.recentEvents = value.recentEvents.map((item) => encodeTerraEvent(item));
|
|
872
|
+
return out;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
export function decodeSupportReport(raw: unknown, at$ = "SupportReport"): SupportReport {
|
|
876
|
+
const object = asObject(raw, at$);
|
|
877
|
+
const sdkVersion = asString(object.sdkVersion, `${at$}.sdkVersion`);
|
|
878
|
+
const generatedAt = decodeInstant(object.generatedAt, `${at$}.generatedAt`);
|
|
879
|
+
const state = decodeDiagnosticsState(object.state, `${at$}.state`);
|
|
880
|
+
const lastDelivery = optional(object.lastDelivery, (value) => decodeInstant(value, `${at$}.lastDelivery`));
|
|
881
|
+
const isConnected = asBoolean(object.isConnected, `${at$}.isConnected`);
|
|
882
|
+
const requestedCategories = asArray(object.requestedCategories, `${at$}.requestedCategories`).map((item, index) => asString(item, `${`${at$}.requestedCategories`}[${index}]`));
|
|
883
|
+
const requestedWrites = asArray(object.requestedWrites, `${at$}.requestedWrites`).map((item, index) => asString(item, `${`${at$}.requestedWrites`}[${index}]`));
|
|
884
|
+
const requestedWorkouts = asArray(object.requestedWorkouts, `${at$}.requestedWorkouts`).map((item, index) => asString(item, `${`${at$}.requestedWorkouts`}[${index}]`));
|
|
885
|
+
const recentEvents = asArray(object.recentEvents, `${at$}.recentEvents`).map((item, index) => decodeTerraEvent(item, `${`${at$}.recentEvents`}[${index}]`));
|
|
886
|
+
return { sdkVersion, generatedAt, state, lastDelivery, isConnected, requestedCategories, requestedWrites, requestedWorkouts, recentEvents };
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
export function encodeBootstrapState(value: BootstrapState): Record<string, unknown> {
|
|
890
|
+
const out: Record<string, unknown> = {};
|
|
891
|
+
out.bootstrapped = value.bootstrapped;
|
|
892
|
+
if (value.devId !== undefined) out.devId = value.devId;
|
|
893
|
+
out.platform = value.platform;
|
|
894
|
+
out.sdkVersion = value.sdkVersion;
|
|
895
|
+
out.backgroundRegistered = value.backgroundRegistered;
|
|
896
|
+
return out;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
export function decodeBootstrapState(raw: unknown, at$ = "BootstrapState"): BootstrapState {
|
|
900
|
+
const object = asObject(raw, at$);
|
|
901
|
+
const bootstrapped = asBoolean(object.bootstrapped, `${at$}.bootstrapped`);
|
|
902
|
+
const devId = optional(object.devId, (value) => asString(value, `${at$}.devId`));
|
|
903
|
+
const platform = asString(object.platform, `${at$}.platform`);
|
|
904
|
+
const sdkVersion = asString(object.sdkVersion, `${at$}.sdkVersion`);
|
|
905
|
+
const backgroundRegistered = asBoolean(object.backgroundRegistered, `${at$}.backgroundRegistered`);
|
|
906
|
+
return { bootstrapped, devId, platform, sdkVersion, backgroundRegistered };
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
export function encodeTokenRequest(value: TokenRequest): Record<string, unknown> {
|
|
910
|
+
const out: Record<string, unknown> = {};
|
|
911
|
+
out.requestId = value.requestId;
|
|
912
|
+
return out;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
export function decodeTokenRequest(raw: unknown, at$ = "TokenRequest"): TokenRequest {
|
|
916
|
+
const object = asObject(raw, at$);
|
|
917
|
+
const requestId = asString(object.requestId, `${at$}.requestId`);
|
|
918
|
+
return { requestId };
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
export function encodeEmpty(_value: Empty): Record<string, unknown> {
|
|
922
|
+
return {};
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
export function decodeEmpty(raw: unknown, at$ = "Empty"): Empty {
|
|
926
|
+
asObject(raw, at$);
|
|
927
|
+
return {} as never;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
export function encodeSourceRequest(value: SourceRequest): Record<string, unknown> {
|
|
931
|
+
const out: Record<string, unknown> = {};
|
|
932
|
+
if (value.source !== undefined) out.source = value.source;
|
|
933
|
+
return out;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
export function decodeSourceRequest(raw: unknown, at$ = "SourceRequest"): SourceRequest {
|
|
937
|
+
const object = asObject(raw, at$);
|
|
938
|
+
const source = optional(object.source, (value) => asSource(value, `${at$}.source`));
|
|
939
|
+
return { source };
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
export function encodeRangeRequest(value: RangeRequest): Record<string, unknown> {
|
|
943
|
+
const out: Record<string, unknown> = {};
|
|
944
|
+
out.range = encodeTimeRange(value.range);
|
|
945
|
+
return out;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
export function decodeRangeRequest(raw: unknown, at$ = "RangeRequest"): RangeRequest {
|
|
949
|
+
const object = asObject(raw, at$);
|
|
950
|
+
const range = decodeTimeRange(object.range, `${at$}.range`);
|
|
951
|
+
return { range };
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
export function encodeCategoryRequest(value: CategoryRequest): Record<string, unknown> {
|
|
955
|
+
const out: Record<string, unknown> = {};
|
|
956
|
+
out.category = value.category;
|
|
957
|
+
if (value.source !== undefined) out.source = value.source;
|
|
958
|
+
return out;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
export function decodeCategoryRequest(raw: unknown, at$ = "CategoryRequest"): CategoryRequest {
|
|
962
|
+
const object = asObject(raw, at$);
|
|
963
|
+
const category = asDataCategory(object.category, `${at$}.category`);
|
|
964
|
+
const source = optional(object.source, (value) => asSource(value, `${at$}.source`));
|
|
965
|
+
return { category, source };
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
export function encodeRecordIdRequest(value: RecordIdRequest): Record<string, unknown> {
|
|
969
|
+
const out: Record<string, unknown> = {};
|
|
970
|
+
out.id = value.id;
|
|
971
|
+
return out;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
export function decodeRecordIdRequest(raw: unknown, at$ = "RecordIdRequest"): RecordIdRequest {
|
|
975
|
+
const object = asObject(raw, at$);
|
|
976
|
+
const id = asString(object.id, `${at$}.id`);
|
|
977
|
+
return { id };
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
export function encodeConnectRequest(value: ConnectRequest): Record<string, unknown> {
|
|
981
|
+
const out: Record<string, unknown> = {};
|
|
982
|
+
if (value.source !== undefined) out.source = value.source;
|
|
983
|
+
out.endUser = encodeEndUser(value.endUser);
|
|
984
|
+
if (value.token !== undefined) out.token = value.token;
|
|
985
|
+
return out;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
export function decodeConnectRequest(raw: unknown, at$ = "ConnectRequest"): ConnectRequest {
|
|
989
|
+
const object = asObject(raw, at$);
|
|
990
|
+
const source = optional(object.source, (value) => asSource(value, `${at$}.source`));
|
|
991
|
+
const endUser = decodeEndUser(object.endUser, `${at$}.endUser`);
|
|
992
|
+
const token = optional(object.token, (value) => asString(value, `${at$}.token`));
|
|
993
|
+
return { source, endUser, token };
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
export function encodePermissionRequest(value: PermissionRequest): Record<string, unknown> {
|
|
997
|
+
const out: Record<string, unknown> = {};
|
|
998
|
+
out.read = caseSet(value.read);
|
|
999
|
+
out.write = caseSet(value.write);
|
|
1000
|
+
out.workouts = value.workouts.map((item) => encodeWorkoutScope(item));
|
|
1001
|
+
if (value.source !== undefined) out.source = value.source;
|
|
1002
|
+
return out;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
export function decodePermissionRequest(raw: unknown, at$ = "PermissionRequest"): PermissionRequest {
|
|
1006
|
+
const object = asObject(raw, at$);
|
|
1007
|
+
const read = caseSet(asArray(object.read, `${at$}.read`).map((item, index) => asDataCategory(item, `${`${at$}.read`}[${index}]`)));
|
|
1008
|
+
const write = caseSet(asArray(object.write, `${at$}.write`).map((item, index) => asDataCategory(item, `${`${at$}.write`}[${index}]`)));
|
|
1009
|
+
const workouts = asArray(object.workouts, `${at$}.workouts`).map((item, index) => decodeWorkoutScope(item, `${`${at$}.workouts`}[${index}]`));
|
|
1010
|
+
const source = optional(object.source, (value) => asSource(value, `${at$}.source`));
|
|
1011
|
+
return { read, write, workouts, source };
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
export function encodePermissionGrant(value: PermissionGrant): Record<string, unknown> {
|
|
1015
|
+
const out: Record<string, unknown> = {};
|
|
1016
|
+
if (value.granted !== undefined) out.granted = encodeHealthAccess(value.granted);
|
|
1017
|
+
return out;
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
export function decodePermissionGrant(raw: unknown, at$ = "PermissionGrant"): PermissionGrant {
|
|
1021
|
+
const object = asObject(raw, at$);
|
|
1022
|
+
const granted = optional(object.granted, (value) => decodeHealthAccess(value, `${at$}.granted`));
|
|
1023
|
+
return { granted };
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
export function encodeTokenResolveRequest(value: TokenResolveRequest): Record<string, unknown> {
|
|
1027
|
+
const out: Record<string, unknown> = {};
|
|
1028
|
+
out.requestId = value.requestId;
|
|
1029
|
+
out.token = value.token;
|
|
1030
|
+
return out;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
export function decodeTokenResolveRequest(raw: unknown, at$ = "TokenResolveRequest"): TokenResolveRequest {
|
|
1034
|
+
const object = asObject(raw, at$);
|
|
1035
|
+
const requestId = asString(object.requestId, `${at$}.requestId`);
|
|
1036
|
+
const token = asString(object.token, `${at$}.token`);
|
|
1037
|
+
return { requestId, token };
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
export function encodeTokenRejectRequest(value: TokenRejectRequest): Record<string, unknown> {
|
|
1041
|
+
const out: Record<string, unknown> = {};
|
|
1042
|
+
out.requestId = value.requestId;
|
|
1043
|
+
out.message = value.message;
|
|
1044
|
+
return out;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
export function decodeTokenRejectRequest(raw: unknown, at$ = "TokenRejectRequest"): TokenRejectRequest {
|
|
1048
|
+
const object = asObject(raw, at$);
|
|
1049
|
+
const requestId = asString(object.requestId, `${at$}.requestId`);
|
|
1050
|
+
const message = asString(object.message, `${at$}.message`);
|
|
1051
|
+
return { requestId, message };
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
export function encodeTokenProviderRequest(value: TokenProviderRequest): Record<string, unknown> {
|
|
1055
|
+
const out: Record<string, unknown> = {};
|
|
1056
|
+
out.present = value.present;
|
|
1057
|
+
out.timeoutMs = value.timeoutMs;
|
|
1058
|
+
return out;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
export function decodeTokenProviderRequest(raw: unknown, at$ = "TokenProviderRequest"): TokenProviderRequest {
|
|
1062
|
+
const object = asObject(raw, at$);
|
|
1063
|
+
const present = asBoolean(object.present, `${at$}.present`);
|
|
1064
|
+
const timeoutMs = asInteger(object.timeoutMs, `${at$}.timeoutMs`);
|
|
1065
|
+
return { present, timeoutMs };
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
export function encodeMarkCompleteRequest(value: MarkCompleteRequest): Record<string, unknown> {
|
|
1069
|
+
const out: Record<string, unknown> = {};
|
|
1070
|
+
out.id = value.id;
|
|
1071
|
+
if (value.at !== undefined) out.at = encodeInstant(value.at);
|
|
1072
|
+
return out;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
export function decodeMarkCompleteRequest(raw: unknown, at$ = "MarkCompleteRequest"): MarkCompleteRequest {
|
|
1076
|
+
const object = asObject(raw, at$);
|
|
1077
|
+
const id = asString(object.id, `${at$}.id`);
|
|
1078
|
+
const at = optional(object.at, (value) => decodeInstant(value, `${at$}.at`));
|
|
1079
|
+
return { id, at };
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
export function encodeBoolResult(value: BoolResult): Record<string, unknown> {
|
|
1083
|
+
const out: Record<string, unknown> = {};
|
|
1084
|
+
out.value = value.value;
|
|
1085
|
+
return out;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
export function decodeBoolResult(raw: unknown, at$ = "BoolResult"): BoolResult {
|
|
1089
|
+
const object = asObject(raw, at$);
|
|
1090
|
+
const value = asBoolean(object.value, `${at$}.value`);
|
|
1091
|
+
return { value };
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
export function encodeStatusResult(value: StatusResult): Record<string, unknown> {
|
|
1095
|
+
const out: Record<string, unknown> = {};
|
|
1096
|
+
out.status = value.status;
|
|
1097
|
+
return out;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
export function decodeStatusResult(raw: unknown, at$ = "StatusResult"): StatusResult {
|
|
1101
|
+
const object = asObject(raw, at$);
|
|
1102
|
+
const status = asPermissionStatus(object.status, `${at$}.status`);
|
|
1103
|
+
return { status };
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
export function encodeStatusesResult(value: StatusesResult): Record<string, unknown> {
|
|
1107
|
+
const out: Record<string, unknown> = {};
|
|
1108
|
+
out.statuses = value.statuses;
|
|
1109
|
+
return out;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
export function decodeStatusesResult(raw: unknown, at$ = "StatusesResult"): StatusesResult {
|
|
1113
|
+
const object = asObject(raw, at$);
|
|
1114
|
+
const statuses = Object.fromEntries(Object.entries(asObject(object.statuses, `${at$}.statuses`)).map(([key, item]) => [asDataCategory(key, `${at$}.statuses`), asPermissionStatus(item, `${at$}.statuses`)])) as never;
|
|
1115
|
+
return { statuses };
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
export function encodeRecordIdList(value: RecordIdList): Record<string, unknown> {
|
|
1119
|
+
const out: Record<string, unknown> = {};
|
|
1120
|
+
out.ids = value.ids;
|
|
1121
|
+
return out;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
export function decodeRecordIdList(raw: unknown, at$ = "RecordIdList"): RecordIdList {
|
|
1125
|
+
const object = asObject(raw, at$);
|
|
1126
|
+
const ids = asArray(object.ids, `${at$}.ids`).map((item, index) => asString(item, `${`${at$}.ids`}[${index}]`));
|
|
1127
|
+
return { ids };
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
export function encodeConnectionList(value: ConnectionList): Record<string, unknown> {
|
|
1131
|
+
const out: Record<string, unknown> = {};
|
|
1132
|
+
out.connections = value.connections.map((item) => encodeConnection(item));
|
|
1133
|
+
return out;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
export function decodeConnectionList(raw: unknown, at$ = "ConnectionList"): ConnectionList {
|
|
1137
|
+
const object = asObject(raw, at$);
|
|
1138
|
+
const connections = asArray(object.connections, `${at$}.connections`).map((item, index) => decodeConnection(item, `${`${at$}.connections`}[${index}]`));
|
|
1139
|
+
return { connections };
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
export function encodeHeartRateList(value: HeartRateList): Record<string, unknown> {
|
|
1143
|
+
const out: Record<string, unknown> = {};
|
|
1144
|
+
out.samples = value.samples.map((item) => encodeHeartRateSample(item));
|
|
1145
|
+
return out;
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
export function decodeHeartRateList(raw: unknown, at$ = "HeartRateList"): HeartRateList {
|
|
1149
|
+
const object = asObject(raw, at$);
|
|
1150
|
+
const samples = asArray(object.samples, `${at$}.samples`).map((item, index) => decodeHeartRateSample(item, `${`${at$}.samples`}[${index}]`));
|
|
1151
|
+
return { samples };
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
export function encodeStepCountList(value: StepCountList): Record<string, unknown> {
|
|
1155
|
+
const out: Record<string, unknown> = {};
|
|
1156
|
+
out.samples = value.samples.map((item) => encodeStepCount(item));
|
|
1157
|
+
return out;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
export function decodeStepCountList(raw: unknown, at$ = "StepCountList"): StepCountList {
|
|
1161
|
+
const object = asObject(raw, at$);
|
|
1162
|
+
const samples = asArray(object.samples, `${at$}.samples`).map((item, index) => decodeStepCount(item, `${`${at$}.samples`}[${index}]`));
|
|
1163
|
+
return { samples };
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
export function encodeSleepSegmentList(value: SleepSegmentList): Record<string, unknown> {
|
|
1167
|
+
const out: Record<string, unknown> = {};
|
|
1168
|
+
out.samples = value.samples.map((item) => encodeSleepSegment(item));
|
|
1169
|
+
return out;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
export function decodeSleepSegmentList(raw: unknown, at$ = "SleepSegmentList"): SleepSegmentList {
|
|
1173
|
+
const object = asObject(raw, at$);
|
|
1174
|
+
const samples = asArray(object.samples, `${at$}.samples`).map((item, index) => decodeSleepSegment(item, `${`${at$}.samples`}[${index}]`));
|
|
1175
|
+
return { samples };
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
export function encodeWorkoutList(value: WorkoutList): Record<string, unknown> {
|
|
1179
|
+
const out: Record<string, unknown> = {};
|
|
1180
|
+
out.samples = value.samples.map((item) => encodeWorkout(item));
|
|
1181
|
+
return out;
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
export function decodeWorkoutList(raw: unknown, at$ = "WorkoutList"): WorkoutList {
|
|
1185
|
+
const object = asObject(raw, at$);
|
|
1186
|
+
const samples = asArray(object.samples, `${at$}.samples`).map((item, index) => decodeWorkout(item, `${`${at$}.samples`}[${index}]`));
|
|
1187
|
+
return { samples };
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
export function encodeDietaryQuantityList(value: DietaryQuantityList): Record<string, unknown> {
|
|
1191
|
+
const out: Record<string, unknown> = {};
|
|
1192
|
+
out.samples = value.samples.map((item) => encodeDietaryQuantity(item));
|
|
1193
|
+
return out;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
export function decodeDietaryQuantityList(raw: unknown, at$ = "DietaryQuantityList"): DietaryQuantityList {
|
|
1197
|
+
const object = asObject(raw, at$);
|
|
1198
|
+
const samples = asArray(object.samples, `${at$}.samples`).map((item, index) => decodeDietaryQuantity(item, `${`${at$}.samples`}[${index}]`));
|
|
1199
|
+
return { samples };
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
export function encodeMenstruationFlowDayList(value: MenstruationFlowDayList): Record<string, unknown> {
|
|
1203
|
+
const out: Record<string, unknown> = {};
|
|
1204
|
+
out.samples = value.samples.map((item) => encodeMenstruationFlowDay(item));
|
|
1205
|
+
return out;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
export function decodeMenstruationFlowDayList(raw: unknown, at$ = "MenstruationFlowDayList"): MenstruationFlowDayList {
|
|
1209
|
+
const object = asObject(raw, at$);
|
|
1210
|
+
const samples = asArray(object.samples, `${at$}.samples`).map((item, index) => decodeMenstruationFlowDay(item, `${`${at$}.samples`}[${index}]`));
|
|
1211
|
+
return { samples };
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
export function encodeMenstrualEvent(value: MenstrualEvent): Record<string, unknown> {
|
|
1215
|
+
const out: Record<string, unknown> = {};
|
|
1216
|
+
out.id = value.id;
|
|
1217
|
+
out.kind = value.kind;
|
|
1218
|
+
out.time = encodeInstant(value.time);
|
|
1219
|
+
if (value.value !== undefined) out.value = value.value;
|
|
1220
|
+
out.storeIdentifier = value.storeIdentifier;
|
|
1221
|
+
out.source = encodeSampleSource(value.source);
|
|
1222
|
+
out.userEntered = value.userEntered;
|
|
1223
|
+
if (value.timeZone !== undefined) out.timeZone = value.timeZone;
|
|
1224
|
+
return out;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
export function decodeMenstrualEvent(raw: unknown, at$ = "MenstrualEvent"): MenstrualEvent {
|
|
1228
|
+
const object = asObject(raw, at$);
|
|
1229
|
+
const id = asString(object.id, `${at$}.id`);
|
|
1230
|
+
const kind = asMenstrualEventKind(object.kind, `${at$}.kind`);
|
|
1231
|
+
const time = decodeInstant(object.time, `${at$}.time`);
|
|
1232
|
+
const value = optional(object.value, (value) => asString(value, `${at$}.value`));
|
|
1233
|
+
const storeIdentifier = asString(object.storeIdentifier, `${at$}.storeIdentifier`);
|
|
1234
|
+
const source = decodeSampleSource(object.source, `${at$}.source`);
|
|
1235
|
+
const userEntered = asBoolean(object.userEntered, `${at$}.userEntered`);
|
|
1236
|
+
const timeZone = optional(object.timeZone, (value) => asString(value, `${at$}.timeZone`));
|
|
1237
|
+
return { id, kind, time, value, storeIdentifier, source, userEntered, timeZone };
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
export function encodeMenstrualEventList(value: MenstrualEventList): Record<string, unknown> {
|
|
1241
|
+
const out: Record<string, unknown> = {};
|
|
1242
|
+
out.samples = value.samples.map((item) => encodeMenstrualEvent(item));
|
|
1243
|
+
return out;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
export function decodeMenstrualEventList(raw: unknown, at$ = "MenstrualEventList"): MenstrualEventList {
|
|
1247
|
+
const object = asObject(raw, at$);
|
|
1248
|
+
const samples = asArray(object.samples, `${at$}.samples`).map((item, index) => decodeMenstrualEvent(item, `${`${at$}.samples`}[${index}]`));
|
|
1249
|
+
return { samples };
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
export function encodeAthleteProfileResult(value: AthleteProfileResult): Record<string, unknown> {
|
|
1253
|
+
const out: Record<string, unknown> = {};
|
|
1254
|
+
if (value.profile !== undefined) out.profile = encodeAthleteProfile(value.profile);
|
|
1255
|
+
return out;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
export function decodeAthleteProfileResult(raw: unknown, at$ = "AthleteProfileResult"): AthleteProfileResult {
|
|
1259
|
+
const object = asObject(raw, at$);
|
|
1260
|
+
const profile = optional(object.profile, (value) => decodeAthleteProfile(value, `${at$}.profile`));
|
|
1261
|
+
return { profile };
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
export function encodePlannedWorkoutList(value: PlannedWorkoutList): Record<string, unknown> {
|
|
1265
|
+
const out: Record<string, unknown> = {};
|
|
1266
|
+
out.workouts = value.workouts.map((item) => encodePlannedWorkout(item));
|
|
1267
|
+
return out;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
export function decodePlannedWorkoutList(raw: unknown, at$ = "PlannedWorkoutList"): PlannedWorkoutList {
|
|
1271
|
+
const object = asObject(raw, at$);
|
|
1272
|
+
const workouts = asArray(object.workouts, `${at$}.workouts`).map((item, index) => decodePlannedWorkout(item, `${`${at$}.workouts`}[${index}]`));
|
|
1273
|
+
return { workouts };
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
export function encodeWorkoutScheduling(value: WorkoutScheduling): Record<string, unknown> {
|
|
1277
|
+
const out: Record<string, unknown> = {};
|
|
1278
|
+
out.status = value.status;
|
|
1279
|
+
return out;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
export function decodeWorkoutScheduling(raw: unknown, at$ = "WorkoutScheduling"): WorkoutScheduling {
|
|
1283
|
+
const object = asObject(raw, at$);
|
|
1284
|
+
const status = asWorkoutSchedulingStatus(object.status, `${at$}.status`);
|
|
1285
|
+
return { status };
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
export function encodeLastDeliveryResult(value: LastDeliveryResult): Record<string, unknown> {
|
|
1289
|
+
const out: Record<string, unknown> = {};
|
|
1290
|
+
if (value.at !== undefined) out.at = encodeInstant(value.at);
|
|
1291
|
+
return out;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
export function decodeLastDeliveryResult(raw: unknown, at$ = "LastDeliveryResult"): LastDeliveryResult {
|
|
1295
|
+
const object = asObject(raw, at$);
|
|
1296
|
+
const at = optional(object.at, (value) => decodeInstant(value, `${at$}.at`));
|
|
1297
|
+
return { at };
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
export function encodeHeartRateEntryList(value: HeartRateEntryList): Record<string, unknown> {
|
|
1301
|
+
const out: Record<string, unknown> = {};
|
|
1302
|
+
out.entries = value.entries.map((item) => encodeHeartRateEntry(item));
|
|
1303
|
+
return out;
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
export function decodeHeartRateEntryList(raw: unknown, at$ = "HeartRateEntryList"): HeartRateEntryList {
|
|
1307
|
+
const object = asObject(raw, at$);
|
|
1308
|
+
const entries = asArray(object.entries, `${at$}.entries`).map((item, index) => decodeHeartRateEntry(item, `${`${at$}.entries`}[${index}]`));
|
|
1309
|
+
return { entries };
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
export function encodeBodyEntryList(value: BodyEntryList): Record<string, unknown> {
|
|
1313
|
+
const out: Record<string, unknown> = {};
|
|
1314
|
+
out.entries = value.entries.map((item) => encodeBodyEntry(item));
|
|
1315
|
+
return out;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
export function decodeBodyEntryList(raw: unknown, at$ = "BodyEntryList"): BodyEntryList {
|
|
1319
|
+
const object = asObject(raw, at$);
|
|
1320
|
+
const entries = asArray(object.entries, `${at$}.entries`).map((item, index) => decodeBodyEntry(item, `${`${at$}.entries`}[${index}]`));
|
|
1321
|
+
return { entries };
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
export function encodeStepEntryList(value: StepEntryList): Record<string, unknown> {
|
|
1325
|
+
const out: Record<string, unknown> = {};
|
|
1326
|
+
out.entries = value.entries.map((item) => encodeStepEntry(item));
|
|
1327
|
+
return out;
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
export function decodeStepEntryList(raw: unknown, at$ = "StepEntryList"): StepEntryList {
|
|
1331
|
+
const object = asObject(raw, at$);
|
|
1332
|
+
const entries = asArray(object.entries, `${at$}.entries`).map((item, index) => decodeStepEntry(item, `${`${at$}.entries`}[${index}]`));
|
|
1333
|
+
return { entries };
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
export function encodeSleepEntryList(value: SleepEntryList): Record<string, unknown> {
|
|
1337
|
+
const out: Record<string, unknown> = {};
|
|
1338
|
+
out.entries = value.entries.map((item) => encodeSleepEntry(item));
|
|
1339
|
+
return out;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
export function decodeSleepEntryList(raw: unknown, at$ = "SleepEntryList"): SleepEntryList {
|
|
1343
|
+
const object = asObject(raw, at$);
|
|
1344
|
+
const entries = asArray(object.entries, `${at$}.entries`).map((item, index) => decodeSleepEntry(item, `${`${at$}.entries`}[${index}]`));
|
|
1345
|
+
return { entries };
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
export function encodeWorkoutEntryList(value: WorkoutEntryList): Record<string, unknown> {
|
|
1349
|
+
const out: Record<string, unknown> = {};
|
|
1350
|
+
out.entries = value.entries.map((item) => encodeWorkoutEntry(item));
|
|
1351
|
+
return out;
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
export function decodeWorkoutEntryList(raw: unknown, at$ = "WorkoutEntryList"): WorkoutEntryList {
|
|
1355
|
+
const object = asObject(raw, at$);
|
|
1356
|
+
const entries = asArray(object.entries, `${at$}.entries`).map((item, index) => decodeWorkoutEntry(item, `${`${at$}.entries`}[${index}]`));
|
|
1357
|
+
return { entries };
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
export function encodeNutritionEntryList(value: NutritionEntryList): Record<string, unknown> {
|
|
1361
|
+
const out: Record<string, unknown> = {};
|
|
1362
|
+
out.entries = value.entries.map((item) => encodeNutritionEntry(item));
|
|
1363
|
+
return out;
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
export function decodeNutritionEntryList(raw: unknown, at$ = "NutritionEntryList"): NutritionEntryList {
|
|
1367
|
+
const object = asObject(raw, at$);
|
|
1368
|
+
const entries = asArray(object.entries, `${at$}.entries`).map((item, index) => decodeNutritionEntry(item, `${`${at$}.entries`}[${index}]`));
|
|
1369
|
+
return { entries };
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
export function encodeDayTotal(value: DayTotal): Record<string, unknown> {
|
|
1373
|
+
const out: Record<string, unknown> = {};
|
|
1374
|
+
out.metric = value.metric;
|
|
1375
|
+
out.start = encodeInstant(value.start);
|
|
1376
|
+
out.end = encodeInstant(value.end);
|
|
1377
|
+
out.value = value.value;
|
|
1378
|
+
out.unit = value.unit;
|
|
1379
|
+
if (value.timeZone !== undefined) out.timeZone = value.timeZone;
|
|
1380
|
+
return out;
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
export function decodeDayTotal(raw: unknown, at$ = "DayTotal"): DayTotal {
|
|
1384
|
+
const object = asObject(raw, at$);
|
|
1385
|
+
const metric = asDayTotalMetric(object.metric, `${at$}.metric`);
|
|
1386
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
1387
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
1388
|
+
const value = asNumber(object.value, `${at$}.value`);
|
|
1389
|
+
const unit = asString(object.unit, `${at$}.unit`);
|
|
1390
|
+
const timeZone = optional(object.timeZone, (value) => asString(value, `${at$}.timeZone`));
|
|
1391
|
+
return { metric, start, end, value, unit, timeZone };
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
export function encodeIntradaySample(value: IntradaySample): Record<string, unknown> {
|
|
1395
|
+
const out: Record<string, unknown> = {};
|
|
1396
|
+
out.id = value.id;
|
|
1397
|
+
out.metric = value.metric;
|
|
1398
|
+
out.start = encodeInstant(value.start);
|
|
1399
|
+
out.end = encodeInstant(value.end);
|
|
1400
|
+
out.value = value.value;
|
|
1401
|
+
out.source = encodeSampleSource(value.source);
|
|
1402
|
+
out.userEntered = value.userEntered;
|
|
1403
|
+
if (value.timeZone !== undefined) out.timeZone = value.timeZone;
|
|
1404
|
+
return out;
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
export function decodeIntradaySample(raw: unknown, at$ = "IntradaySample"): IntradaySample {
|
|
1408
|
+
const object = asObject(raw, at$);
|
|
1409
|
+
const id = asString(object.id, `${at$}.id`);
|
|
1410
|
+
const metric = asIntradayMetric(object.metric, `${at$}.metric`);
|
|
1411
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
1412
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
1413
|
+
const value = asNumber(object.value, `${at$}.value`);
|
|
1414
|
+
const source = decodeSampleSource(object.source, `${at$}.source`);
|
|
1415
|
+
const userEntered = asBoolean(object.userEntered, `${at$}.userEntered`);
|
|
1416
|
+
const timeZone = optional(object.timeZone, (value) => asString(value, `${at$}.timeZone`));
|
|
1417
|
+
return { id, metric, start, end, value, source, userEntered, timeZone };
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
export function encodeRestingHeartRateSample(value: RestingHeartRateSample): Record<string, unknown> {
|
|
1421
|
+
const out: Record<string, unknown> = {};
|
|
1422
|
+
out.id = value.id;
|
|
1423
|
+
out.start = encodeInstant(value.start);
|
|
1424
|
+
out.end = encodeInstant(value.end);
|
|
1425
|
+
out.beatsPerMinute = value.beatsPerMinute;
|
|
1426
|
+
out.source = encodeSampleSource(value.source);
|
|
1427
|
+
out.userEntered = value.userEntered;
|
|
1428
|
+
if (value.timeZone !== undefined) out.timeZone = value.timeZone;
|
|
1429
|
+
return out;
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
export function decodeRestingHeartRateSample(raw: unknown, at$ = "RestingHeartRateSample"): RestingHeartRateSample {
|
|
1433
|
+
const object = asObject(raw, at$);
|
|
1434
|
+
const id = asString(object.id, `${at$}.id`);
|
|
1435
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
1436
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
1437
|
+
const beatsPerMinute = asNumber(object.beatsPerMinute, `${at$}.beatsPerMinute`);
|
|
1438
|
+
const source = decodeSampleSource(object.source, `${at$}.source`);
|
|
1439
|
+
const userEntered = asBoolean(object.userEntered, `${at$}.userEntered`);
|
|
1440
|
+
const timeZone = optional(object.timeZone, (value) => asString(value, `${at$}.timeZone`));
|
|
1441
|
+
return { id, start, end, beatsPerMinute, source, userEntered, timeZone };
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
export function encodeBodyReading(value: BodyReading): Record<string, unknown> {
|
|
1445
|
+
const out: Record<string, unknown> = {};
|
|
1446
|
+
out.id = value.id;
|
|
1447
|
+
out.kind = encodeBodyReadingKind(value.kind);
|
|
1448
|
+
out.start = encodeInstant(value.start);
|
|
1449
|
+
out.end = encodeInstant(value.end);
|
|
1450
|
+
out.source = encodeSampleSource(value.source);
|
|
1451
|
+
out.userEntered = value.userEntered;
|
|
1452
|
+
if (value.timeZone !== undefined) out.timeZone = value.timeZone;
|
|
1453
|
+
return out;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
export function decodeBodyReading(raw: unknown, at$ = "BodyReading"): BodyReading {
|
|
1457
|
+
const object = asObject(raw, at$);
|
|
1458
|
+
const id = asString(object.id, `${at$}.id`);
|
|
1459
|
+
const kind = decodeBodyReadingKind(object.kind, `${at$}.kind`);
|
|
1460
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
1461
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
1462
|
+
const source = decodeSampleSource(object.source, `${at$}.source`);
|
|
1463
|
+
const userEntered = asBoolean(object.userEntered, `${at$}.userEntered`);
|
|
1464
|
+
const timeZone = optional(object.timeZone, (value) => asString(value, `${at$}.timeZone`));
|
|
1465
|
+
return { id, kind, start, end, source, userEntered, timeZone };
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
export function encodeRoutePoint(value: RoutePoint): Record<string, unknown> {
|
|
1469
|
+
const out: Record<string, unknown> = {};
|
|
1470
|
+
out.time = encodeInstant(value.time);
|
|
1471
|
+
out.latitude = value.latitude;
|
|
1472
|
+
out.longitude = value.longitude;
|
|
1473
|
+
return out;
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
export function decodeRoutePoint(raw: unknown, at$ = "RoutePoint"): RoutePoint {
|
|
1477
|
+
const object = asObject(raw, at$);
|
|
1478
|
+
const time = decodeInstant(object.time, `${at$}.time`);
|
|
1479
|
+
const latitude = asNumber(object.latitude, `${at$}.latitude`);
|
|
1480
|
+
const longitude = asNumber(object.longitude, `${at$}.longitude`);
|
|
1481
|
+
return { time, latitude, longitude };
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
export function encodeWorkoutRoute(value: WorkoutRoute): Record<string, unknown> {
|
|
1485
|
+
const out: Record<string, unknown> = {};
|
|
1486
|
+
out.id = value.id;
|
|
1487
|
+
out.workoutId = value.workoutId;
|
|
1488
|
+
out.start = encodeInstant(value.start);
|
|
1489
|
+
out.end = encodeInstant(value.end);
|
|
1490
|
+
out.points = value.points.map((item) => encodeRoutePoint(item));
|
|
1491
|
+
out.source = encodeSampleSource(value.source);
|
|
1492
|
+
if (value.timeZone !== undefined) out.timeZone = value.timeZone;
|
|
1493
|
+
return out;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
export function decodeWorkoutRoute(raw: unknown, at$ = "WorkoutRoute"): WorkoutRoute {
|
|
1497
|
+
const object = asObject(raw, at$);
|
|
1498
|
+
const id = asString(object.id, `${at$}.id`);
|
|
1499
|
+
const workoutId = asString(object.workoutId, `${at$}.workoutId`);
|
|
1500
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
1501
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
1502
|
+
const points = asArray(object.points, `${at$}.points`).map((item, index) => decodeRoutePoint(item, `${`${at$}.points`}[${index}]`));
|
|
1503
|
+
const source = decodeSampleSource(object.source, `${at$}.source`);
|
|
1504
|
+
const timeZone = optional(object.timeZone, (value) => asString(value, `${at$}.timeZone`));
|
|
1505
|
+
return { id, workoutId, start, end, points, source, timeZone };
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
export function encodeWorkoutIntensitySample(value: WorkoutIntensitySample): Record<string, unknown> {
|
|
1509
|
+
const out: Record<string, unknown> = {};
|
|
1510
|
+
out.id = value.id;
|
|
1511
|
+
out.metric = value.metric;
|
|
1512
|
+
if (value.workoutId !== undefined) out.workoutId = value.workoutId;
|
|
1513
|
+
out.start = encodeInstant(value.start);
|
|
1514
|
+
out.end = encodeInstant(value.end);
|
|
1515
|
+
out.value = value.value;
|
|
1516
|
+
out.source = encodeSampleSource(value.source);
|
|
1517
|
+
out.userEntered = value.userEntered;
|
|
1518
|
+
if (value.timeZone !== undefined) out.timeZone = value.timeZone;
|
|
1519
|
+
return out;
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
export function decodeWorkoutIntensitySample(raw: unknown, at$ = "WorkoutIntensitySample"): WorkoutIntensitySample {
|
|
1523
|
+
const object = asObject(raw, at$);
|
|
1524
|
+
const id = asString(object.id, `${at$}.id`);
|
|
1525
|
+
const metric = asWorkoutIntensityMetric(object.metric, `${at$}.metric`);
|
|
1526
|
+
const workoutId = optional(object.workoutId, (value) => asString(value, `${at$}.workoutId`));
|
|
1527
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
1528
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
1529
|
+
const value = asNumber(object.value, `${at$}.value`);
|
|
1530
|
+
const source = decodeSampleSource(object.source, `${at$}.source`);
|
|
1531
|
+
const userEntered = asBoolean(object.userEntered, `${at$}.userEntered`);
|
|
1532
|
+
const timeZone = optional(object.timeZone, (value) => asString(value, `${at$}.timeZone`));
|
|
1533
|
+
return { id, metric, workoutId, start, end, value, source, userEntered, timeZone };
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
export function encodeHydrationSample(value: HydrationSample): Record<string, unknown> {
|
|
1537
|
+
const out: Record<string, unknown> = {};
|
|
1538
|
+
out.id = value.id;
|
|
1539
|
+
out.start = encodeInstant(value.start);
|
|
1540
|
+
out.end = encodeInstant(value.end);
|
|
1541
|
+
out.millilitres = value.millilitres;
|
|
1542
|
+
out.source = encodeSampleSource(value.source);
|
|
1543
|
+
out.userEntered = value.userEntered;
|
|
1544
|
+
if (value.timeZone !== undefined) out.timeZone = value.timeZone;
|
|
1545
|
+
return out;
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
export function decodeHydrationSample(raw: unknown, at$ = "HydrationSample"): HydrationSample {
|
|
1549
|
+
const object = asObject(raw, at$);
|
|
1550
|
+
const id = asString(object.id, `${at$}.id`);
|
|
1551
|
+
const start = decodeInstant(object.start, `${at$}.start`);
|
|
1552
|
+
const end = decodeInstant(object.end, `${at$}.end`);
|
|
1553
|
+
const millilitres = asNumber(object.millilitres, `${at$}.millilitres`);
|
|
1554
|
+
const source = decodeSampleSource(object.source, `${at$}.source`);
|
|
1555
|
+
const userEntered = asBoolean(object.userEntered, `${at$}.userEntered`);
|
|
1556
|
+
const timeZone = optional(object.timeZone, (value) => asString(value, `${at$}.timeZone`));
|
|
1557
|
+
return { id, start, end, millilitres, source, userEntered, timeZone };
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
export function encodeDayTotalList(value: DayTotalList): Record<string, unknown> {
|
|
1561
|
+
const out: Record<string, unknown> = {};
|
|
1562
|
+
out.totals = value.totals.map((item) => encodeDayTotal(item));
|
|
1563
|
+
return out;
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
export function decodeDayTotalList(raw: unknown, at$ = "DayTotalList"): DayTotalList {
|
|
1567
|
+
const object = asObject(raw, at$);
|
|
1568
|
+
const totals = asArray(object.totals, `${at$}.totals`).map((item, index) => decodeDayTotal(item, `${`${at$}.totals`}[${index}]`));
|
|
1569
|
+
return { totals };
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
export function encodeIntradaySampleList(value: IntradaySampleList): Record<string, unknown> {
|
|
1573
|
+
const out: Record<string, unknown> = {};
|
|
1574
|
+
out.samples = value.samples.map((item) => encodeIntradaySample(item));
|
|
1575
|
+
return out;
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
export function decodeIntradaySampleList(raw: unknown, at$ = "IntradaySampleList"): IntradaySampleList {
|
|
1579
|
+
const object = asObject(raw, at$);
|
|
1580
|
+
const samples = asArray(object.samples, `${at$}.samples`).map((item, index) => decodeIntradaySample(item, `${`${at$}.samples`}[${index}]`));
|
|
1581
|
+
return { samples };
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
export function encodeRestingHeartRateList(value: RestingHeartRateList): Record<string, unknown> {
|
|
1585
|
+
const out: Record<string, unknown> = {};
|
|
1586
|
+
out.samples = value.samples.map((item) => encodeRestingHeartRateSample(item));
|
|
1587
|
+
return out;
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
export function decodeRestingHeartRateList(raw: unknown, at$ = "RestingHeartRateList"): RestingHeartRateList {
|
|
1591
|
+
const object = asObject(raw, at$);
|
|
1592
|
+
const samples = asArray(object.samples, `${at$}.samples`).map((item, index) => decodeRestingHeartRateSample(item, `${`${at$}.samples`}[${index}]`));
|
|
1593
|
+
return { samples };
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
export function encodeBodyReadingList(value: BodyReadingList): Record<string, unknown> {
|
|
1597
|
+
const out: Record<string, unknown> = {};
|
|
1598
|
+
out.samples = value.samples.map((item) => encodeBodyReading(item));
|
|
1599
|
+
return out;
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
export function decodeBodyReadingList(raw: unknown, at$ = "BodyReadingList"): BodyReadingList {
|
|
1603
|
+
const object = asObject(raw, at$);
|
|
1604
|
+
const samples = asArray(object.samples, `${at$}.samples`).map((item, index) => decodeBodyReading(item, `${`${at$}.samples`}[${index}]`));
|
|
1605
|
+
return { samples };
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
export function encodeWorkoutRouteList(value: WorkoutRouteList): Record<string, unknown> {
|
|
1609
|
+
const out: Record<string, unknown> = {};
|
|
1610
|
+
out.routes = value.routes.map((item) => encodeWorkoutRoute(item));
|
|
1611
|
+
return out;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
export function decodeWorkoutRouteList(raw: unknown, at$ = "WorkoutRouteList"): WorkoutRouteList {
|
|
1615
|
+
const object = asObject(raw, at$);
|
|
1616
|
+
const routes = asArray(object.routes, `${at$}.routes`).map((item, index) => decodeWorkoutRoute(item, `${`${at$}.routes`}[${index}]`));
|
|
1617
|
+
return { routes };
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
export function encodeWorkoutIntensityList(value: WorkoutIntensityList): Record<string, unknown> {
|
|
1621
|
+
const out: Record<string, unknown> = {};
|
|
1622
|
+
out.samples = value.samples.map((item) => encodeWorkoutIntensitySample(item));
|
|
1623
|
+
return out;
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
export function decodeWorkoutIntensityList(raw: unknown, at$ = "WorkoutIntensityList"): WorkoutIntensityList {
|
|
1627
|
+
const object = asObject(raw, at$);
|
|
1628
|
+
const samples = asArray(object.samples, `${at$}.samples`).map((item, index) => decodeWorkoutIntensitySample(item, `${`${at$}.samples`}[${index}]`));
|
|
1629
|
+
return { samples };
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
export function encodeHydrationList(value: HydrationList): Record<string, unknown> {
|
|
1633
|
+
const out: Record<string, unknown> = {};
|
|
1634
|
+
out.samples = value.samples.map((item) => encodeHydrationSample(item));
|
|
1635
|
+
return out;
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
export function decodeHydrationList(raw: unknown, at$ = "HydrationList"): HydrationList {
|
|
1639
|
+
const object = asObject(raw, at$);
|
|
1640
|
+
const samples = asArray(object.samples, `${at$}.samples`).map((item, index) => decodeHydrationSample(item, `${`${at$}.samples`}[${index}]`));
|
|
1641
|
+
return { samples };
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
export function encodeAvailabilityResult(value: AvailabilityResult): Record<string, unknown> {
|
|
1645
|
+
const out: Record<string, unknown> = {};
|
|
1646
|
+
out.availability = encodeStoreAvailability(value.availability);
|
|
1647
|
+
return out;
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
export function decodeAvailabilityResult(raw: unknown, at$ = "AvailabilityResult"): AvailabilityResult {
|
|
1651
|
+
const object = asObject(raw, at$);
|
|
1652
|
+
const availability = decodeStoreAvailability(object.availability, `${at$}.availability`);
|
|
1653
|
+
return { availability };
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
export function encodeEndUser(value: EndUser): Record<string, unknown> {
|
|
1657
|
+
switch (value.kind) {
|
|
1658
|
+
case "reference":
|
|
1659
|
+
return { kind: "reference", id: value.id };
|
|
1660
|
+
case "anonymous":
|
|
1661
|
+
return { kind: "anonymous" };
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
export function decodeEndUser(raw: unknown, at$ = "EndUser"): EndUser {
|
|
1666
|
+
const object = asObject(raw, at$);
|
|
1667
|
+
const tag = object.kind;
|
|
1668
|
+
switch (tag) {
|
|
1669
|
+
case "reference": {
|
|
1670
|
+
return { kind: "reference", id: asString(object.id, `${at$}.id`) };
|
|
1671
|
+
}
|
|
1672
|
+
case "anonymous": {
|
|
1673
|
+
return { kind: "anonymous" };
|
|
1674
|
+
}
|
|
1675
|
+
default:
|
|
1676
|
+
throw new TypeError(`${at$}: unknown kind ${String(tag)}`);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
export function encodeTimeRange(value: TimeRange): Record<string, unknown> {
|
|
1681
|
+
switch (value.kind) {
|
|
1682
|
+
case "lastHours":
|
|
1683
|
+
return { kind: "lastHours", hours: value.hours };
|
|
1684
|
+
case "lastDays":
|
|
1685
|
+
return { kind: "lastDays", days: value.days };
|
|
1686
|
+
case "today":
|
|
1687
|
+
return { kind: "today" };
|
|
1688
|
+
case "between":
|
|
1689
|
+
return { kind: "between", start: encodeInstant(value.start), end: encodeInstant(value.end) };
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
export function decodeTimeRange(raw: unknown, at$ = "TimeRange"): TimeRange {
|
|
1694
|
+
const object = asObject(raw, at$);
|
|
1695
|
+
const tag = object.kind;
|
|
1696
|
+
switch (tag) {
|
|
1697
|
+
case "lastHours": {
|
|
1698
|
+
return { kind: "lastHours", hours: asInteger(object.hours, `${at$}.hours`) };
|
|
1699
|
+
}
|
|
1700
|
+
case "lastDays": {
|
|
1701
|
+
return { kind: "lastDays", days: asInteger(object.days, `${at$}.days`) };
|
|
1702
|
+
}
|
|
1703
|
+
case "today": {
|
|
1704
|
+
return { kind: "today" };
|
|
1705
|
+
}
|
|
1706
|
+
case "between": {
|
|
1707
|
+
return { kind: "between", start: decodeInstant(object.start, `${at$}.start`), end: decodeInstant(object.end, `${at$}.end`) };
|
|
1708
|
+
}
|
|
1709
|
+
default:
|
|
1710
|
+
throw new TypeError(`${at$}: unknown kind ${String(tag)}`);
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
export function encodeSleepStage(value: SleepStage): Record<string, unknown> {
|
|
1715
|
+
switch (value.kind) {
|
|
1716
|
+
case "inBed":
|
|
1717
|
+
return { kind: "inBed" };
|
|
1718
|
+
case "awake":
|
|
1719
|
+
return { kind: "awake" };
|
|
1720
|
+
case "asleep":
|
|
1721
|
+
return { kind: "asleep" };
|
|
1722
|
+
case "light":
|
|
1723
|
+
return { kind: "light" };
|
|
1724
|
+
case "deep":
|
|
1725
|
+
return { kind: "deep" };
|
|
1726
|
+
case "rem":
|
|
1727
|
+
return { kind: "rem" };
|
|
1728
|
+
case "unknown":
|
|
1729
|
+
return { kind: "unknown", raw: value.raw };
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
export function decodeSleepStage(raw: unknown, at$ = "SleepStage"): SleepStage {
|
|
1734
|
+
const object = asObject(raw, at$);
|
|
1735
|
+
const tag = object.kind;
|
|
1736
|
+
switch (tag) {
|
|
1737
|
+
case "inBed": {
|
|
1738
|
+
return { kind: "inBed" };
|
|
1739
|
+
}
|
|
1740
|
+
case "awake": {
|
|
1741
|
+
return { kind: "awake" };
|
|
1742
|
+
}
|
|
1743
|
+
case "asleep": {
|
|
1744
|
+
return { kind: "asleep" };
|
|
1745
|
+
}
|
|
1746
|
+
case "light": {
|
|
1747
|
+
return { kind: "light" };
|
|
1748
|
+
}
|
|
1749
|
+
case "deep": {
|
|
1750
|
+
return { kind: "deep" };
|
|
1751
|
+
}
|
|
1752
|
+
case "rem": {
|
|
1753
|
+
return { kind: "rem" };
|
|
1754
|
+
}
|
|
1755
|
+
case "unknown": {
|
|
1756
|
+
return { kind: "unknown", raw: asString(object.raw, `${at$}.raw`) };
|
|
1757
|
+
}
|
|
1758
|
+
default:
|
|
1759
|
+
if (typeof tag === "string") return { kind: "unknown", raw: tag };
|
|
1760
|
+
throw new TypeError(`${at$}: unknown kind ${String(tag)}`);
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
export function encodeWorkoutActivity(value: WorkoutActivity): Record<string, unknown> {
|
|
1765
|
+
switch (value.kind) {
|
|
1766
|
+
case "running":
|
|
1767
|
+
return { kind: "running" };
|
|
1768
|
+
case "walking":
|
|
1769
|
+
return { kind: "walking" };
|
|
1770
|
+
case "cycling":
|
|
1771
|
+
return { kind: "cycling" };
|
|
1772
|
+
case "swimming":
|
|
1773
|
+
return { kind: "swimming" };
|
|
1774
|
+
case "strengthTraining":
|
|
1775
|
+
return { kind: "strengthTraining" };
|
|
1776
|
+
case "other":
|
|
1777
|
+
return { kind: "other", label: value.label };
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
export function decodeWorkoutActivity(raw: unknown, at$ = "WorkoutActivity"): WorkoutActivity {
|
|
1782
|
+
const object = asObject(raw, at$);
|
|
1783
|
+
const tag = object.kind;
|
|
1784
|
+
switch (tag) {
|
|
1785
|
+
case "running": {
|
|
1786
|
+
return { kind: "running" };
|
|
1787
|
+
}
|
|
1788
|
+
case "walking": {
|
|
1789
|
+
return { kind: "walking" };
|
|
1790
|
+
}
|
|
1791
|
+
case "cycling": {
|
|
1792
|
+
return { kind: "cycling" };
|
|
1793
|
+
}
|
|
1794
|
+
case "swimming": {
|
|
1795
|
+
return { kind: "swimming" };
|
|
1796
|
+
}
|
|
1797
|
+
case "strengthTraining": {
|
|
1798
|
+
return { kind: "strengthTraining" };
|
|
1799
|
+
}
|
|
1800
|
+
case "other": {
|
|
1801
|
+
return { kind: "other", label: asString(object.label, `${at$}.label`) };
|
|
1802
|
+
}
|
|
1803
|
+
default:
|
|
1804
|
+
if (typeof tag === "string") return { kind: "other", label: tag };
|
|
1805
|
+
throw new TypeError(`${at$}: unknown kind ${String(tag)}`);
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
export function encodeDiagnosticsState(value: DiagnosticsState): Record<string, unknown> {
|
|
1810
|
+
switch (value.state) {
|
|
1811
|
+
case "healthy":
|
|
1812
|
+
return { state: "healthy" };
|
|
1813
|
+
case "quiet":
|
|
1814
|
+
return { state: "quiet", since: encodeInstant(value.since) };
|
|
1815
|
+
case "backgroundRestricted":
|
|
1816
|
+
return { state: "backgroundRestricted", reason: value.reason };
|
|
1817
|
+
case "backgroundRefreshUnscheduled":
|
|
1818
|
+
return { state: "backgroundRefreshUnscheduled" };
|
|
1819
|
+
case "pendingRetry":
|
|
1820
|
+
return { state: "pendingRetry" };
|
|
1821
|
+
case "linkRevoked":
|
|
1822
|
+
return { state: "linkRevoked" };
|
|
1823
|
+
case "devIDMismatch":
|
|
1824
|
+
return { state: "devIDMismatch" };
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
export function decodeDiagnosticsState(raw: unknown, at$ = "DiagnosticsState"): DiagnosticsState {
|
|
1829
|
+
const object = asObject(raw, at$);
|
|
1830
|
+
const tag = object.state;
|
|
1831
|
+
switch (tag) {
|
|
1832
|
+
case "healthy": {
|
|
1833
|
+
return { state: "healthy" };
|
|
1834
|
+
}
|
|
1835
|
+
case "quiet": {
|
|
1836
|
+
return { state: "quiet", since: decodeInstant(object.since, `${at$}.since`) };
|
|
1837
|
+
}
|
|
1838
|
+
case "backgroundRestricted": {
|
|
1839
|
+
return { state: "backgroundRestricted", reason: optional(object.reason, (value) => asBackgroundRestrictionReason(value, `${at$}.reason`)) };
|
|
1840
|
+
}
|
|
1841
|
+
case "backgroundRefreshUnscheduled": {
|
|
1842
|
+
return { state: "backgroundRefreshUnscheduled" };
|
|
1843
|
+
}
|
|
1844
|
+
case "pendingRetry": {
|
|
1845
|
+
return { state: "pendingRetry" };
|
|
1846
|
+
}
|
|
1847
|
+
case "linkRevoked": {
|
|
1848
|
+
return { state: "linkRevoked" };
|
|
1849
|
+
}
|
|
1850
|
+
case "devIDMismatch": {
|
|
1851
|
+
return { state: "devIDMismatch" };
|
|
1852
|
+
}
|
|
1853
|
+
default:
|
|
1854
|
+
throw new TypeError(`${at$}: unknown state ${String(tag)}`);
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
export function encodeStreamMessage(value: StreamMessage): Record<string, unknown> {
|
|
1859
|
+
switch (value.kind) {
|
|
1860
|
+
case "data":
|
|
1861
|
+
return { kind: "data", element: value.element };
|
|
1862
|
+
case "error":
|
|
1863
|
+
return { kind: "error", error: encodeTerraErrorPayload(value.error) };
|
|
1864
|
+
case "complete":
|
|
1865
|
+
return { kind: "complete" };
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
export function decodeStreamMessage(raw: unknown, at$ = "StreamMessage"): StreamMessage {
|
|
1870
|
+
const object = asObject(raw, at$);
|
|
1871
|
+
const tag = object.kind;
|
|
1872
|
+
switch (tag) {
|
|
1873
|
+
case "data": {
|
|
1874
|
+
return { kind: "data", element: asObject(object.element, `${at$}.element`) };
|
|
1875
|
+
}
|
|
1876
|
+
case "error": {
|
|
1877
|
+
return { kind: "error", error: decodeTerraErrorPayload(object.error, `${at$}.error`) };
|
|
1878
|
+
}
|
|
1879
|
+
case "complete": {
|
|
1880
|
+
return { kind: "complete" };
|
|
1881
|
+
}
|
|
1882
|
+
default:
|
|
1883
|
+
throw new TypeError(`${at$}: unknown kind ${String(tag)}`);
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
export function encodeBodyReadingKind(value: BodyReadingKind): Record<string, unknown> {
|
|
1888
|
+
switch (value.type) {
|
|
1889
|
+
case "measurement":
|
|
1890
|
+
return { type: "measurement", metric: value.metric, value: value.value };
|
|
1891
|
+
case "bloodPressure":
|
|
1892
|
+
return { type: "bloodPressure", systolic: value.systolic, diastolic: value.diastolic };
|
|
1893
|
+
case "bloodGlucose":
|
|
1894
|
+
return { type: "bloodGlucose", value: value.value, unit: value.unit, mealTime: value.mealTime, specimen: value.specimen };
|
|
1895
|
+
case "oxygenSaturation":
|
|
1896
|
+
return { type: "oxygenSaturation", fraction: value.fraction };
|
|
1897
|
+
case "temperature":
|
|
1898
|
+
return { type: "temperature", metric: value.metric, celsius: value.celsius };
|
|
1899
|
+
case "heartRateVariability":
|
|
1900
|
+
return { type: "heartRateVariability", metric: value.metric, milliseconds: value.milliseconds };
|
|
1901
|
+
case "respiratoryRate":
|
|
1902
|
+
return { type: "respiratoryRate", breathsPerMinute: value.breathsPerMinute };
|
|
1903
|
+
case "vo2Max":
|
|
1904
|
+
return { type: "vo2Max", millilitresPerKilogramMinute: value.millilitresPerKilogramMinute, testType: value.testType };
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1908
|
+
export function decodeBodyReadingKind(raw: unknown, at$ = "BodyReadingKind"): BodyReadingKind {
|
|
1909
|
+
const object = asObject(raw, at$);
|
|
1910
|
+
const tag = object.type;
|
|
1911
|
+
switch (tag) {
|
|
1912
|
+
case "measurement": {
|
|
1913
|
+
return { type: "measurement", metric: asBodyMetric(object.metric, `${at$}.metric`), value: asNumber(object.value, `${at$}.value`) };
|
|
1914
|
+
}
|
|
1915
|
+
case "bloodPressure": {
|
|
1916
|
+
return { type: "bloodPressure", systolic: asNumber(object.systolic, `${at$}.systolic`), diastolic: asNumber(object.diastolic, `${at$}.diastolic`) };
|
|
1917
|
+
}
|
|
1918
|
+
case "bloodGlucose": {
|
|
1919
|
+
return { type: "bloodGlucose", value: asNumber(object.value, `${at$}.value`), unit: asBloodGlucoseUnit(object.unit, `${at$}.unit`), mealTime: optional(object.mealTime, (value) => asGlucoseMealTime(value, `${at$}.mealTime`)), specimen: optional(object.specimen, (value) => asGlucoseSpecimen(value, `${at$}.specimen`)) };
|
|
1920
|
+
}
|
|
1921
|
+
case "oxygenSaturation": {
|
|
1922
|
+
return { type: "oxygenSaturation", fraction: asNumber(object.fraction, `${at$}.fraction`) };
|
|
1923
|
+
}
|
|
1924
|
+
case "temperature": {
|
|
1925
|
+
return { type: "temperature", metric: asBodyTemperatureMetric(object.metric, `${at$}.metric`), celsius: asNumber(object.celsius, `${at$}.celsius`) };
|
|
1926
|
+
}
|
|
1927
|
+
case "heartRateVariability": {
|
|
1928
|
+
return { type: "heartRateVariability", metric: asHeartRateVariabilityMetric(object.metric, `${at$}.metric`), milliseconds: asNumber(object.milliseconds, `${at$}.milliseconds`) };
|
|
1929
|
+
}
|
|
1930
|
+
case "respiratoryRate": {
|
|
1931
|
+
return { type: "respiratoryRate", breathsPerMinute: asNumber(object.breathsPerMinute, `${at$}.breathsPerMinute`) };
|
|
1932
|
+
}
|
|
1933
|
+
case "vo2Max": {
|
|
1934
|
+
return { type: "vo2Max", millilitresPerKilogramMinute: asNumber(object.millilitresPerKilogramMinute, `${at$}.millilitresPerKilogramMinute`), testType: optional(object.testType, (value) => asVO2MaxTestType(value, `${at$}.testType`)) };
|
|
1935
|
+
}
|
|
1936
|
+
default:
|
|
1937
|
+
throw new TypeError(`${at$}: unknown type ${String(tag)}`);
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
export function encodeStoreAvailability(value: StoreAvailability): Record<string, unknown> {
|
|
1942
|
+
switch (value.kind) {
|
|
1943
|
+
case "available":
|
|
1944
|
+
return { kind: "available" };
|
|
1945
|
+
case "unsupportedDevice":
|
|
1946
|
+
return { kind: "unsupportedDevice" };
|
|
1947
|
+
case "providerAppMissing":
|
|
1948
|
+
return { kind: "providerAppMissing" };
|
|
1949
|
+
case "providerAppTooOld":
|
|
1950
|
+
return { kind: "providerAppTooOld", installed: value.installed };
|
|
1951
|
+
case "moduleMissing":
|
|
1952
|
+
return { kind: "moduleMissing" };
|
|
1953
|
+
case "partnerPolicyMissing":
|
|
1954
|
+
return { kind: "partnerPolicyMissing" };
|
|
1955
|
+
case "featureUnavailable":
|
|
1956
|
+
return { kind: "featureUnavailable" };
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
export function decodeStoreAvailability(raw: unknown, at$ = "StoreAvailability"): StoreAvailability {
|
|
1961
|
+
const object = asObject(raw, at$);
|
|
1962
|
+
const tag = object.kind;
|
|
1963
|
+
switch (tag) {
|
|
1964
|
+
case "available": {
|
|
1965
|
+
return { kind: "available" };
|
|
1966
|
+
}
|
|
1967
|
+
case "unsupportedDevice": {
|
|
1968
|
+
return { kind: "unsupportedDevice" };
|
|
1969
|
+
}
|
|
1970
|
+
case "providerAppMissing": {
|
|
1971
|
+
return { kind: "providerAppMissing" };
|
|
1972
|
+
}
|
|
1973
|
+
case "providerAppTooOld": {
|
|
1974
|
+
return { kind: "providerAppTooOld", installed: asString(object.installed, `${at$}.installed`) };
|
|
1975
|
+
}
|
|
1976
|
+
case "moduleMissing": {
|
|
1977
|
+
return { kind: "moduleMissing" };
|
|
1978
|
+
}
|
|
1979
|
+
case "partnerPolicyMissing": {
|
|
1980
|
+
return { kind: "partnerPolicyMissing" };
|
|
1981
|
+
}
|
|
1982
|
+
case "featureUnavailable": {
|
|
1983
|
+
return { kind: "featureUnavailable" };
|
|
1984
|
+
}
|
|
1985
|
+
default:
|
|
1986
|
+
throw new TypeError(`${at$}: unknown kind ${String(tag)}`);
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
|