feat: serve the day, its index, the timeline and life events

Replace the day, timeline and life-event stubs with their implementations
(#613) and drop the not-implemented helper, its error code and its OpenAPI
response with the last stub.

loadDay reads one local day for every reader: the readings live inside the
record's own day window (never the UTC rollups), through the canonical-source
engine the mood sheet already uses (resolveDayReadings in linked-context.ts),
with the person's usual range over the 30 days before; the record sections
from their own tables, each in the storage form it speaks (an instant in the
local window, a date string with its own zone, a calendar date). A switched-off
module's section is not read; a section the grant does not cover is named
not_shared and not read.

The day, the day index and the new visit preparation (GET /api/day/notable)
are admitted on the readings and narrowed per section through
actingDomainVisibility, so a scoped grant sees exactly its sections. The
timeline and its readiness stay whole-record reads and narrow their lanes the
same way.

Notable days are deterministic keys: a three-month high or low with history
behind it, a first reading, and in the visit preparation a regular reading
that stopped. The timeline lays out spans and points from the owning tables,
standing items without a date, and series by zoom: months from the rollup
tier inside its five-year window and from one cached live query before it.
The readiness inventory rates each lane with one link per gap.

Life events are created, edited and soft-deleted as MANAGE verbs with audit
rows, encrypted at rest, and join the sharing guard and the handler matrix.
get_day reads a day for the Coach and the MCP endpoint without life events,
notes or document names; its step carries the date it read.
This commit is contained in:
Marc-André Bombeck committed 2026-10-08 14:31:13 +02:00
1 parent b8f6372963
commit 0924285cd6
65 files changed
+7642 -209

No files matched your search

+3 -1
View File
@@ -118,6 +118,7 @@ export const ERROR_CODE_CATALOGUE: Readonly<Record<string, readonly string[]>> =
],
"cycle-prefs": ["cycle-prefs.body.invalid_json", "cycle-prefs.invalid"],
"disable-coach": ["disable-coach.body.invalid_json"],
day: ["day.invalid"],
demo: ["demo.readOnly"],
documents: [
"documents.chat.conversationNotFound",
@@ -230,6 +231,7 @@ export const ERROR_CODE_CATALOGUE: Readonly<Record<string, readonly string[]>> =
"labs.update.referenceRangeInvalid",
"labs.update.sourceReferenceRangeInvalid",
],
life_event: ["life_event.invalid", "life_event.not_found"],
managed_profile: [
"managed_profile.guardian.duplicate",
"managed_profile.guardian.managed_invitee",
@@ -380,6 +382,7 @@ export const ERROR_CODE_CATALOGUE: Readonly<Record<string, readonly string[]>> =
"symptoms.event.notFound",
"symptoms.invalid",
],
timeline: ["timeline.invalid"],
tokens: [
"tokens.documents.ceiling_reached",
"tokens.measurements.ceiling_reached",
@@ -423,7 +426,6 @@ export const ERROR_CODE_CATALOGUE: Readonly<Record<string, readonly string[]>> =
"modules_conflict",
"mood_tag_layout_conflict",
"not_configured",
"not_implemented",
"notification_prefs_conflict",
"oidc_only",
"private_origin_not_approved",
+34 -11
View File
@@ -4,14 +4,15 @@
*
* Part of the OpenAPI route table; aggregated in `./index.ts`. The request
* and response schemas are the runtime ones from `@/lib/day/wire-schemas`, so
* the published contract is the parser's own. Published ahead of the
* implementation: every operation answers 501 until its route lands.
* the published contract is the parser's own.
*/
import type { ZodOpenApiObject } from "zod-openapi";
import {
dayIndexQuerySchema,
dayIndexResponseSchema,
dayNotableQuerySchema,
dayNotableResponseSchema,
dayPathSchema,
dayResponseSchema,
lifeEventCreateSchema,
@@ -27,7 +28,8 @@ import {
import {
dataEnvelope,
errorEnvelope,
notImplementedResponse,
idempotencyKeyParameter,
idempotentWrite,
recordRefusal,
recordWriteRateLimitResponse,
stdResponses,
@@ -62,7 +64,30 @@ export const dayPaths: NonNullable<ZodOpenApiObject["paths"]> = {
},
...stdResponses,
...recordRefusal(),
...notImplementedResponse,
},
},
},
"/api/day/notable": {
get: {
tags: ["Records"],
summary: "Since the last visit",
description:
"What stood out and what changed in a window, for the preparation of the next visit: deterministic observations (a value highest or lowest for at least three months, a first reading, a regular reading that stopped for two weeks or more) and context changes (dose changes, medication and course starts and ends, pauses, illness onsets and recoveries, vaccinations, procedures, lab days). Without `from` the window starts at the last completed visit the caller may see (else 90 days back); without `to` it ends today; at most 1096 days. Keys and the record's own names only, no judgement. Days are cut in the record's own time zone. Sections the caller's grant does not cover are left out.",
requestParams: { query: dayNotableQuerySchema },
responses: {
"200": {
description: "The window, its observations and its changes.",
content: {
"application/json": {
schema: dataEnvelope(
dayNotableResponseSchema,
"DayNotableWindowEnvelope",
),
},
},
},
...stdResponses,
...recordRefusal(),
},
},
},
@@ -84,7 +109,6 @@ export const dayPaths: NonNullable<ZodOpenApiObject["paths"]> = {
},
...stdResponses,
...recordRefusal(),
...notImplementedResponse,
},
},
},
@@ -106,7 +130,6 @@ export const dayPaths: NonNullable<ZodOpenApiObject["paths"]> = {
},
...stdResponses,
...recordRefusal(TIMELINE_OFF),
...notImplementedResponse,
},
},
},
@@ -130,7 +153,6 @@ export const dayPaths: NonNullable<ZodOpenApiObject["paths"]> = {
},
...stdResponses,
...recordRefusal(TIMELINE_OFF),
...notImplementedResponse,
},
},
},
@@ -154,10 +176,10 @@ export const dayPaths: NonNullable<ZodOpenApiObject["paths"]> = {
},
...stdResponses,
...recordRefusal(),
...notImplementedResponse,
},
},
post: {
parameters: [idempotencyKeyParameter],
tags: ["Records"],
summary: "Add a life event",
description:
@@ -176,8 +198,9 @@ export const dayPaths: NonNullable<ZodOpenApiObject["paths"]> = {
},
},
...stdResponses,
...recordRefusal(),
...recordWriteRateLimitResponse,
...notImplementedResponse,
...idempotentWrite(),
},
},
},
@@ -203,7 +226,7 @@ export const dayPaths: NonNullable<ZodOpenApiObject["paths"]> = {
},
...lifeEventNotFound,
...stdResponses,
...notImplementedResponse,
...recordRefusal(),
},
},
delete: {
@@ -222,7 +245,7 @@ export const dayPaths: NonNullable<ZodOpenApiObject["paths"]> = {
},
...lifeEventNotFound,
...stdResponses,
...notImplementedResponse,
...recordRefusal(),
},
},
},
-15
View File
@@ -269,21 +269,6 @@ export const malformedJsonResponse = {
},
};
/**
* The 501 a route answers while its contract is published ahead of its
* implementation on a release branch. Every stub carries it; the owner of the
* route drops it with the stub. No tagged release answers it: the error-code
* catalogue check fails once `not_implemented` is listed and nothing emits
* it, and fails while something still does and it is not listed.
*/
export const notImplementedResponse = {
"501": {
description:
"Not implemented yet: the contract is published ahead of the implementation on a release branch. `meta.errorCode: not_implemented`.",
content: { "application/json": { schema: errorEnvelope } },
},
} as const;
// ── Standard 401 / 422 / 429 responses ───────────────────────────────
export const stdResponses = {