refactor(apple-health): drop redundant HK_QUANTITY_TYPE_TO_MEASUREMENT view

The derived map mirrored APPLE_HEALTH_TYPE_MAP one key for one key
with the value narrowed to the measurementType field. Every caller can
read that via APPLE_HEALTH_TYPE_MAP[id]?.measurementType — no external
consumer is depending on the compact view today. Drops the redundant
constant plus the mirror-check test block that only existed to keep
the two tables in sync.
This commit is contained in:
Marc-André Bombeck committed 2026-05-14 17:09:17 +02:00
1 parent 4ec67056e5
commit 7851341d98
2 files changed
-31

No files matched your search

@@ -3,7 +3,6 @@ import {
APPLE_HEALTH_SLEEP_STAGE_MAP,
APPLE_HEALTH_TYPE_MAP,
HK_QUANTITY_TYPE_DEFERRED,
HK_QUANTITY_TYPE_TO_MEASUREMENT,
mapAppleHealthEntry,
} from "../apple-health-mapping";
import { measurementTypeEnum } from "@/lib/validations/measurement";
@@ -111,20 +110,6 @@ describe("APPLE_HEALTH_TYPE_MAP", () => {
});
});
describe("HK_QUANTITY_TYPE_TO_MEASUREMENT", () => {
it("mirrors APPLE_HEALTH_TYPE_MAP key-for-key", () => {
expect(Object.keys(HK_QUANTITY_TYPE_TO_MEASUREMENT).sort()).toEqual(
Object.keys(APPLE_HEALTH_TYPE_MAP).sort(),
);
});
it("agrees with APPLE_HEALTH_TYPE_MAP on the measurement type per key", () => {
for (const [k, t] of Object.entries(HK_QUANTITY_TYPE_TO_MEASUREMENT)) {
expect(APPLE_HEALTH_TYPE_MAP[k]?.measurementType).toBe(t);
}
});
});
describe("HK_QUANTITY_TYPE_DEFERRED", () => {
it("contains only valid HealthKit identifier strings", () => {
for (const id of HK_QUANTITY_TYPE_DEFERRED) {
@@ -287,22 +287,6 @@ export const APPLE_HEALTH_TYPE_MAP: Record<string, AppleHealthMapping> = {
},
};
/**
* Compact `HKQuantityTypeIdentifier* → MeasurementType` view of the
* same data carried by `APPLE_HEALTH_TYPE_MAP`. Exists so the iOS
* Swift session and the v1.4.26 XML-import worker can do a cheap
* lookup without instantiating the full `AppleHealthMapping` record
* — useful when all the caller wants is the canonical enum value
* for routing / filtering. Always stays a strict subset of the keys
* in the table above.
*/
export const HK_QUANTITY_TYPE_TO_MEASUREMENT: Record<
string,
import("@/generated/prisma/client").MeasurementType
> = Object.fromEntries(
Object.entries(APPLE_HEALTH_TYPE_MAP).map(([k, v]) => [k, v.measurementType]),
);
/**
* HK identifiers the iOS app may emit that HealthLog deliberately does
* NOT map yet. Listing them here means the batch route can log a