refactor: simplify batch (S-02 to S-04)

Three small reuse wins from the W6 simplify review:

- openapi/registry.ts swaps the lazy require() for a static import.
  The ESLint disable + as-cast carried no real benefit; the only
  callers always loaded the route table anyway.
- Extract useCoachPrefs() into a shared hook so the settings sheet
  and message thread share one queryKey + one fallback shape. Removes
  the drift between the two existing inline blocks.
- Replace the 9-deep wantsX boolean ladder in coach snapshot with a
  single CoachScopeSource -> MeasurementType[] map. Drives both the
  WHERE type IN (...) build and the appleHealthBlocks gate, so adding
  a new metric is one entry instead of three parallel edits.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Marc-André BombeckandClaude Opus 4.7 committed 2026-05-11 02:23:43 +02:00
1 parent 3ee6dab6fa
commit dfffe6bb3b
5 files changed
+99 -60

No files matched your search

+7 -9
View File
@@ -24,6 +24,8 @@
*/
import { createDocument, type ZodOpenApiObject } from "zod-openapi";
import { openApiPaths, openApiComponents } from "./routes";
export const openApiBase: Pick<
ZodOpenApiObject,
"openapi" | "info" | "servers" | "tags"
@@ -57,17 +59,13 @@ export const openApiBase: Pick<
};
/**
* Assemble the full OpenAPI 3.1 document. Imports the route table
* lazily so the base scaffolding stays usable from contexts that
* shouldn't pull every Zod schema in the project (e.g. a hypothetical
* future devtools-only consumer).
* Assemble the full OpenAPI 3.1 document. Routes live in their own
* file so additions don't touch the base scaffolding. The static
* import keeps typecheck-narrowing and tree-shaking intact (W6 S-02
* removed the lazy-`require` form which had no real consumer and was
* costing an `eslint-disable` + an `as` cast for no benefit).
*/
export function buildOpenApiDocument(): ReturnType<typeof createDocument> {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { openApiPaths, openApiComponents } = require("./routes") as {
openApiPaths: ZodOpenApiObject["paths"];
openApiComponents: ZodOpenApiObject["components"];
};
return createDocument({
...openApiBase,
paths: openApiPaths,