feat(anatomy): curation pipeline — changeset schema, applier with before/after records, cleaned single asset, draft seed, changelog + review report generators; seed layout legacy-import/curation/draft

This commit is contained in:
bchanot committed 2026-10-09 16:50:08 +02:00
1 parent 3dbbfdf1df
commit 6870d87910
58 files changed
+18167 -267

No files matched your search

+40 -12
View File
@@ -299,17 +299,44 @@ the decision lands; only the naming one is implemented in this document.
| 6 | Server-side validation and integrity for every publication; the frontend is never a security boundary. | SQL already re-checks references, sizes and species. The full shape check (Zod) moves server-side before community publication: plpgsql shape rules or an Edge Function gate, decided at the community step. |
| 7 | Account deletion handles dependencies and transfers explicitly (RGPD); no dependency may block the erasure of personal data forever. | Retention step (§16): published versions get their `created_by` / `published_by` anonymised through a dedicated system path (the immutability guard will allow that single transition), personal sheets are transferred or archived, `creator_user_id` keeps `on delete restrict` only as the backstop that forces the explicit path. |
## 6. Official equine sheet: import (Step 4b)
## 6. Official equine sheet: import (Step 4b) and curation (Step 4c)
`packages/anatomy` holds a one-off, deterministic importer
(`pnpm import:equine`) that reads `Horse.svg`, `Horse_head.svg` and
`pathologies.json` and writes `supabase/seed/anatomical-sheets/equine/v1/`:
the canonical `document.json`, `legacy-id-map.json` (every legacy
`data-anno-id`, category slug and view key → new id), `assets.json` and the
byte-identical SVG copies, `IMPORT-REPORT.md` (French, for the osteopath:
volumes in / out, every mapping, every anomaly to validate) and
`equine_v1.sql`, the idempotent seed that creates the platform-owned sheet
`faunosteo-cheval` (private, official) with its two asset rows and draft v1.
`packages/anatomy` holds a deterministic pipeline (`pnpm import:equine`)
that reads `Horse.svg`, `Horse_head.svg` and `pathologies.json`, then the
authored curation files, and writes under
`supabase/seed/anatomical-sheets/equine/`:
| Folder | Nature | Content |
| ---------------- | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `legacy-import/` | generated baseline | canonical `document.json`, `legacy-id-map.json` (every legacy `data-anno-id`, category slug and view key → new id), `assets.json` + byte-identical SVG copies, `IMPORT-REPORT.md` (French, for the osteopath: volumes, mappings, anomalies). No SQL. |
| `curation/` | authored, committed | `references.json` (the references registry) and `changes.json` (the changeset) |
| `draft/` | generated working revision | curated `document.json`, `assets.json` + `assets/horse.svg`, `CHANGELOG.md`, `REVIEW-REPORT.md`, `equine_draft.sql` |
Changeset (`packages/anatomy/src/curation/schema.ts`): each change has an
id `CHG-nnn`, a level (A demonstrated error, B supported improvement, C
uncertain: a `question` is then required), a kind (correction,
terminology, translation, restructure, enrichment, reference, geometry,
removal, technical), a FR/EN title, a French rationale, the
`reference_ids` it relies on (declared in `references.json`), a priority and
ops: `set` (dot field path, `scope: subtree` on findings), `rename` (every
link follows: annotations, views, citations), `add`, `remove`, `move`,
`cite`. Targets are strings: `document`, `region:<code>`, `reference:<id>`,
`category:<id>`, `view:<id>`, `annotation:<id>`, `zone:<id>`,
`finding:<zone>/<category>[/<node>…]`. `needs_confirmation` is derived (B
and C). Any op that cannot apply as written, and any integrity error left at
the end, stops the run; every elementary edit is a CHANGELOG row.
Asset cleaning: both legacy files carry the same drawing, so the draft keeps
one, `horse.svg`, with every element carrying `data-anno-id` removed (the
markers are document data now); the head view has no asset and a
`view_box` (`60 100 500 380`) cropping it. This step is the reserved change
`CHG-000`, listed like the others.
Seed: `equine_draft.sql` is idempotent and converging. On a fresh database
it inserts the sheet, the cleaned asset row and the draft through
`private.insert_sheet_draft`; when the sheet's only version is a draft
whose content differs, it replaces that content in place. It never touches
a published row and never publishes.
Rules of the import:
@@ -317,14 +344,15 @@ Rules of the import:
EN names match exactly (26 / 26), finding zone id = catalog key, views
`main` and `head`, trigger `head-trigger`; nothing matches by label at
runtime;
- no medical correction: catalog ids and labels are kept verbatim
- no medical correction in the import (only the changeset changes content):
catalog ids and labels are kept verbatim
(`ssb-dysfunctions` under `sphenoid` included) and every doubt is an entry
of the report; only technical slugs (degraded category ids) are
normalised, and the report says so;
- no publication: the seed inserts a draft through
`private.insert_sheet_draft` (audited with a null actor) and never calls
`publish_sheet_version`; only a platform admin can publish it, after the
business review of the report (pgTAP 007 pins both);
business review of `REVIEW-REPORT.md` (pgTAP 007 pins both);
- the source files under `apps/app/public/species/equine/` stay untouched
and keep serving the current application.
+5 -4
View File
@@ -17,9 +17,10 @@ supabase/
│ ├─ 20261008110100_private_execute_hardening.sql EXECUTE revoked from PUBLIC on the Step 3 helpers
│ └─ 20261009100000_sheet_asset_storage.sql bucket anatomical-sheet-assets + read policy through the sheet
├─ seed.sql LOCAL dev accounts + first owner (never run in prod)
├─ seed/anatomical-sheets/equine/v1/ official equine sheet as a DRAFT, generated by `pnpm import:equine`
│ ├─ equine_v1.sql idempotent seed (sheet, 2 asset rows, draft v1), applied by db reset and by PGlite
│ └─ document.json, legacy-id-map.json, assets.json, assets/*.svg, IMPORT-REPORT.md
├─ seed/anatomical-sheets/equine/ official equine sheet as a DRAFT, generated by `pnpm import:equine`
│ ├─ legacy-import/ baseline import (document, id map, SVG copies, IMPORT-REPORT.md), no SQL
│ ├─ curation/ authored changes.json + references.json
│ └─ draft/equine_draft.sql idempotent, converging seed (sheet, 1 asset row, working draft), applied by db reset and by PGlite
└─ tests/ pgTAP, one file per concern, allowed AND denied paths
packages/supabase/
├─ src/client.ts createBrowserClient() (anon key, PKCE)
@@ -97,7 +98,7 @@ the service key, from the generated seed folder:
```bash
export SUPABASE_URL=http://127.0.0.1:54321
read -rs SUPABASE_SERVICE_ROLE_KEY && export SUPABASE_SERVICE_ROLE_KEY # typed, not in shell history
pnpm assets:upload supabase/seed/anatomical-sheets/equine/v1
pnpm assets:upload supabase/seed/anatomical-sheets/equine/draft
```
The script verifies each file against `assets.json` (sha256, size) before