The map from code
How Sypnorm use cases become the map, and what stays written by people.
On this page
With Sypnorm, the use-case ORM that comes with Cases, the code is a set of use cases. The traffic goes both ways: the skeleton of each case is generated from its file, and the technical side of the map is read back from the code.
npx @sypnia/cases generate # a typed skeleton for every case that has none, and the types of every casegenerate writes src/cases/<area>/<id>.ts for each new case (never overwriting one that exists) .sypnia/cases/types.d.ts with every input, outcome and failure, so ctx.outcome only accepts what the case declares, and src/areas/<area>.ts, the service of each area.
import { useCase } from '@sypnia/cases/sypnorm';
import { db } from '../db';
export const placeOrder = useCase('place-order', {
actor: 'customer',
touches: { reads: [db.products], writes: [db.orders, db.order_items] },
async run(ctx) {
// … every path ends in ctx.outcome('OrderPlaced', …), ctx.outcome('OutOfStock', …) or ctx.outcome('BakeryClosed')
},
});npx @sypnia/cases map lists it, and npx @sypnia/cases map --upload --project <x> sends it to the map as a draft proposal: --project la-espiga names the Cases map and goes straight to the Cases server; a Data project’s ref (20 lowercase letters) sends it to that project’s «Use cases», and Sypnia Data forwards it to the Cases map linked with it (The map from your code). Cases matches each use case to its case file by the case id it names: useCase('place-order', …) ↔ cases/orders/place-order.case.yaml.
Who owns which field
| Field | Comes from | When they disagree |
|---|---|---|
title, goal, steps, the words of outcomes and failures (says, tell) | the case file (people) | — |
starts, where, loop, ai | the case file | — |
| outcome and failure names and payloads | the case file declares them, generate types them, the code must end only in them | drift |
data.reads, data.writes | the code | drift |
allowed | the code (and the policies in Data) | drift |
npx @sypnia/cases sync --from-code # fills the code-owned fields into the files; review them as a change to the mapWhat an upload proposes
An upload never changes an approved version: it becomes a draft proposal of what the code owns, and the check runs with it.
- A use case whose case is on the map: a change to its
dataandallowedwhen they differ from the code. Table names compare by singular and plural, as the check does. - A use case with no case: a skeleton case, with
starts: in_app,status: building, its outcomes and failures by name, its area (from the upload, from its source pathsrc/cases/<area>/…, or the map’s only area), ready for someone to write its title, goal and steps. - A case with no code is never retired by an upload.
- The files of the format (
{ files }) can be uploaded too: each case that differs from the approved version becomes a change.
The upload’s code sources are kept, so «where is it?» answers with the files behind each place. A draft becomes open when someone asks for reviews (Versions and reviews).
Without Sypnorm, the code side is thinner: Case: <id> trailers in commits and // case: <id> notes in the sources say which cases have code, not what they do (The check).