Skip to content

The map from your code

Derive the map from your use cases, upload it to your Cases project, and keep code and map in agreement.

Applies to EngineCloud
View as Markdown
On this page
  1. Derive it
  2. Link it
  3. From your own scripts
  4. What comes from code, what from people

Derive it

Terminal
npx @sypnia/cases map

Sypnorm reads your code, without running it, and finds every useCase(...). It writes sypnorm.map.json, the code side of your map:

sypnorm.map.json
{
  "app": "la-espiga",
  "useCases": [
    {
      "case": "place-order",
      "summary": "A customer orders today's bread for pick-up",
      "actor": "customer",
      "reads": ["products", "opening_hours"],
      "writes": ["orders", "order_items", "products"],
      "outcomes": ["OrderPlaced"],
      "failures": ["BakeryClosed", "OutOfStock"],
      "source": "src/cases/orders/place-order.ts:5"
    }
  ]
}
FlagDoes
--uploadsends the map to your Cases map as a draft proposal that a person approves (Versions, proposals and reviews); sent to a Sypnia Data project, it lands in its «Use cases», where the console shows each case with the tables it touches, and Data forwards it to the linked Cases map, also as a draft proposal (Data)
--project <x>where to upload: 20 lowercase letters is a Data project’s ref (as in the console’s address); anything else is a Cases map’s slug on the Cases server (cases.api.sypnia.com, or SYPNIA_CASES_API). By default project, then data, of the [cases] table of sypnia.toml
--forceuploads even when the check finds errors in the map (by default a map with errors is not uploaded)
--checkfails in CI when the code and the committed file differ, so the file stays true
--jsonprints it, for cases check or an agent
--out <file>writes another file than sypnorm.map.json

The upload is more than sypnorm.map.json: it is the whole map as one document, the code side merged with the case files. Each case carries its area, title, actor, the tables it touches, its outcomes with their event names, its failures, its start, its place and path in the navigation, and the events it listens to; the document also carries the navigation tree, the event graph and the check’s findings. It signs in with SYPNIA_TOKEN, or with the session npx @sypnia/cases login saved.

npx @sypnia/cases check uses the same reading: it compares the code side with the written map and reports what is missing, unmapped or drifting.

Terminal
npx @sypnia/cases login
npx @sypnia/cases link la-espiga --data <ref>      # this repository's Cases map and its Sypnia Data project

login signs you in with your Sypnia account, the same session as npx @sypnia/data login. link writes the Cases map into the [cases] table of sypnia.toml (project = "la-espiga") and, with --data, the Data project (data = "<ref>"), and links the map with the Sypnia Data project, both ways; from then on each case shows its tables and their policies. After that, map --upload knows where to go (or name it: npx @sypnia/cases map --upload --project la-espiga).

From your own scripts

TypeScript
import { deriveMap, uploadMap } from '@sypnia/cases/map';

const map = await deriveMap({ root: '.', include: ['src/cases/**/*.ts'] });
await uploadMap(map, { project: '<ref>', token: process.env.SYPNIA_TOKEN! });   // a Data project's ref; Data forwards it to the linked map

What comes from code, what from people

The code owns the data and the allowed actors, and must end only in the outcomes the case declares; people own the title, the goal, how it starts, where it lives, the steps and the messages. The map from code has the full table and how cases sync --from-code fills the files.

  1. Derive it
  2. Link it
  3. From your own scripts
  4. What comes from code, what from people

    Search pages, sections and terms