feat: lay down the day view and timeline contract

Land every file the day view, the timeline and life events share before
any of them is built, so the server, the day view and the timeline can be
built side by side without editing the same file (#613).

Schema and migration 0387: LifeEvent with a short category list, calendar
start and end dates, a day/month/year precision, encrypted title and note,
a soft-delete tombstone and an index for the per-user live list. Every new
column is annotated for the column-reader sweep. Life events travel in both
backup purposes with their two ends in one file, are wiped with the
account, and are registered for key rotation.

src/lib/day/contract.ts carries the constants and wire types for
GET /api/day/{date}, /api/day/index, /api/timeline, /api/timeline/readiness
and the life-event routes, free of Zod so the navigation chrome can import
it; the schemas beside it feed the routes and the published contract. The
Coach and MCP tool name get_day is reserved there, and life events are
listed as the one section no model ever sees.

The opt-in timeline module, its navigation entry, the day-section and
timeline-lane surfaces, the day and timeline query keys (evicted by every
record data bundle), and stub routes that answer 501 behind their
admissions. The four cross-section reads declare the whole record for now;
the life-event list is a profile read, and life events join the profile
sharing domain and its consent copy in all seven locales. The day,
timeline and lifeEvents message namespaces carry their base copy as
release-pending keys.

The aggregate bundle cap moves to 4400: the branch already measured 4365
against 4335, and the new copy adds 10 KB.
This commit is contained in:
Marc-André Bombeck committed 2026-10-08 13:03:37 +02:00
1 parent 861ba21086
commit c79fc6cc7b
57 files changed
+4290 -21

No files matched your search

@@ -0,0 +1,31 @@
-- Life events for the timeline (#613).
--
-- A dated anchor in the person's life: a move, a birth, a new job, a loss.
-- Dates are calendar strings (`YYYY-MM-DD`) without a time zone, and
-- `precision` says how much of the date is known; at MONTH or YEAR the stored
-- date is the first day of that month or year. Title and note are encrypted
-- at rest. Soft-deleted like the other record tables; the index serves the
-- per-user live list in date order.
CREATE TYPE "life_event_category" AS ENUM ('FAMILY', 'HOME', 'WORK', 'LOSS', 'OTHER');
CREATE TYPE "life_event_precision" AS ENUM ('DAY', 'MONTH', 'YEAR');
CREATE TABLE "life_events" (
"id" TEXT NOT NULL,
"user_id" TEXT NOT NULL,
"category" "life_event_category" NOT NULL,
"start_date" TEXT NOT NULL,
"end_date" TEXT,
"precision" "life_event_precision" NOT NULL,
"title_encrypted" BYTEA NOT NULL,
"note_encrypted" BYTEA,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"deleted_at" TIMESTAMP(3),
CONSTRAINT "life_events_pkey" PRIMARY KEY ("id")
);
CREATE INDEX "life_events_user_id_deleted_at_start_date_idx" ON "life_events"("user_id", "deleted_at", "start_date");
ALTER TABLE "life_events" ADD CONSTRAINT "life_events_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+69
View File
@@ -992,6 +992,10 @@ model User {
// over, and the guardian who minted the link.
handoversOfProfile ManagedProfileHandover[] @relation("HandoverProfile")
handoversCreated ManagedProfileHandover[] @relation("HandoverCreator")
// v1.42 — dated anchors in the person's life for the timeline (#613): a
// move, a birth, a new job. Shared under the `profile` domain; never sent to
// a model.
lifeEvents LifeEvent[]
// v1.7.0 profile — optional patient-identity fields surfaced on the
// health-record export cover (PDF) and the FHIR `Patient` resource.
@@ -9563,3 +9567,68 @@ model DocumentAiRun {
@@index([status, expiresAt])
@@map("document_ai_runs")
}
/// A dated anchor in the person's life for the timeline (v1.42, #613): a move,
/// a birth, a new job, a loss. Not a health reading and not a symptom; it gives
/// the years around the readings something to hang on.
///
/// Shared under the `profile` domain, beside allergies, visits and the
/// immunization history. Never sent to a model in any form: the Coach, the
/// MCP endpoint and every AI job leave it out, and the day loader's model-facing
/// projection drops it.
///
/// Dates are calendar dates without a time zone (`YYYY-MM-DD`), the
/// `src/lib/tz/date-only.ts` convention, because "we moved in September 2023"
/// names a day on a calendar, not an instant. `precision` says how much of the
/// date the person actually knows; at MONTH or YEAR the stored date is the
/// first day of that month or year, and only a DAY event appears in a day view.
model LifeEvent {
id String @id @default(cuid())
userId String @map("user_id")
/// @pending-consumer(#613) The kind of event, from a deliberately short list.
category LifeEventCategory
/// @pending-consumer(#613) First day of the event, `YYYY-MM-DD`. At MONTH or
/// YEAR precision the first day of that month or year.
startDate String @map("start_date")
/// @pending-consumer(#613) Last day, `YYYY-MM-DD`, for an event that spans a
/// period (parental leave, a year abroad). NULL = a single date.
endDate String? @map("end_date")
/// @pending-consumer(#613) How much of the date is known. Applies to both
/// ends.
precision LifeEventPrecision
/// @pending-consumer(#613) What happened, in the person's own words,
/// AES-256-GCM encrypted at rest.
titleEncrypted Bytes @map("title_encrypted")
/// @pending-consumer(#613) An optional note, AES-256-GCM encrypted at rest.
noteEncrypted Bytes? @map("note_encrypted")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
/// Soft-delete tombstone. NULL = live.
deletedAt DateTime? @map("deleted_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId, deletedAt, startDate])
@@map("life_events")
}
/// What kind of life event. Few on purpose: travel already comes from the
/// environment module, and a long list turns an anchor into a diary.
enum LifeEventCategory {
FAMILY
HOME
WORK
LOSS
OTHER
@@map("life_event_category")
}
/// How much of a life event's date the person knows.
enum LifeEventPrecision {
DAY
MONTH
YEAR
@@map("life_event_precision")
}