mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 14:16:12 +00:00
The element schemas move out of validations/backup.ts into one <domain>-backup-schema.ts per domain, beside its export and restore, with the shared primitives in backup-schema-kit.ts. validations/backup.ts now composes the slices into backupPayloadSchema in the same key order, with the same defaults and the checks that span sections, so the parsed payload, every validation message and the OpenAPI contract are unchanged. The lazy-schema guard now covers the slices too: a slice is reached only through the payload schema or another slice, never from a domain's export or restore. The external-id guard carries the payload's exemption to its slices, and mutation testing scores the slices with the payload schema.
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
/**
|
|
* The symptoms slice of the backup payload schema.
|
|
*
|
|
* Part of the symptoms backup domain, beside its export and restore.
|
|
* Loaded only through `src/lib/validations/backup.ts`, which composes every
|
|
* slice into `backupPayloadSchema` on first use (the schema is ~12 MB of
|
|
* heap; see `backup-schema-lazy-guard.test.ts`).
|
|
*/
|
|
import { z } from "zod/v4";
|
|
import { base64BytesSchema, isoDateTime } from "@/lib/export/backup-schema-kit";
|
|
|
|
/**
|
|
* A person-defined symptom (v1.40) with every occurrence of it nested inside,
|
|
* the way a medication carries its side effects. `label` / `labelEncrypted`
|
|
* and `note` / `noteEncrypted` are the two ends of the free-text contract: a
|
|
* portable file carries the plaintext, a disaster-recovery file the ciphertext.
|
|
* An occurrence's `episodeId` is the exported episode's own id; the restore
|
|
* nulls one that names an episode the file does not carry.
|
|
*/
|
|
export const symptomEventBackupSchema = z
|
|
.object({
|
|
id: z.string().min(1).optional(),
|
|
occurredAt: isoDateTime,
|
|
intensity: z.number().int().min(0).max(10),
|
|
note: z.string().nullable().optional(),
|
|
noteEncrypted: base64BytesSchema.nullable().optional(),
|
|
episodeId: z.string().min(1).nullable().optional(),
|
|
createdAt: isoDateTime,
|
|
updatedAt: isoDateTime,
|
|
})
|
|
.passthrough();
|
|
export const symptomDefinitionBackupSchema = z
|
|
.object({
|
|
id: z.string().min(1).optional(),
|
|
label: z.string().min(1).optional(),
|
|
labelEncrypted: base64BytesSchema.optional(),
|
|
icon: z.string().nullable().optional(),
|
|
sortOrder: z.number().int(),
|
|
isActive: z.boolean(),
|
|
createdAt: isoDateTime,
|
|
updatedAt: isoDateTime,
|
|
events: z.array(symptomEventBackupSchema).default([]),
|
|
})
|
|
.passthrough()
|
|
.refine((d) => d.label !== undefined || d.labelEncrypted !== undefined, {
|
|
message: "A symptom definition needs a label or its ciphertext",
|
|
});
|