1. Start
  2. An entity
  3. A source
  4. A rule
  5. A port
  6. A link
  7. A fact
  8. An app
  9. Split

Publishing is not an update

A post is published only once. We write that rule as a method and make status readOnly, so nothing else can change it, not even update.

fronds/blog/entities/Post.ts
+import { entity, oneOf, primary, readOnly, text } from '@fougere/schema';
2
3export default class Post extends entity({
4 id: primary(),
5 title: text({ min: 1, max: 160 }),
+ status: readOnly(oneOf('draft', 'published', { default: 'draft' })),d
7}) {}

point at a lettered line, or tap it, to see what grows from it

A state changes through an operation, never through a field write.

Try it
$ curl -X POST localhost:4100/api/blog/posts/$ID/publish   # twice
409  CONFLICT  Already published
In the docsHandler
Built with Fougere and Nuxt, hosted on GitHub Pages.