@cratis/pi 7.6.4 → 7.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package/corpus/agents/backend-developer.md +14 -0
- package/package/corpus/agents/code-reviewer.md +16 -0
- package/package/corpus/agents/coordinator.md +17 -0
- package/package/corpus/agents/frontend-developer.md +17 -0
- package/package/corpus/agents/orchestrator.md +18 -0
- package/package/corpus/agents/planner.md +24 -0
- package/package/corpus/agents/screenplay-modeler.md +57 -0
- package/package/corpus/agents/screenplay-renderer.md +42 -0
- package/package/corpus/agents/screenplay-reviewer.md +45 -0
- package/package/corpus/agents/slice-implementer.md +32 -5
- package/package/corpus/agents/spec-writer.md +16 -3
- package/package/corpus/prompts/add-reactor.prompt.md +5 -3
- package/package/corpus/prompts/new-vertical-slice.prompt.md +16 -5
- package/package/corpus/prompts/write-specs.prompt.md +12 -6
- package/package/corpus/rules/application-profile.md +7 -3
- package/package/corpus/rules/general.md +8 -3
- package/package/corpus/rules/glossary.md +1 -1
- package/package/corpus/rules/profiles.md +42 -4
- package/package/corpus/rules/reactors.md +30 -22
- package/package/corpus/rules/vertical-slices.md +3 -1
- package/package/corpus/skills/cratis-application-react-specifications/SKILL.md +13 -0
- package/package/corpus/skills/cratis-application-slice-conformance/LICENSE +2 -0
- package/package/corpus/skills/cratis-application-slice-conformance/SKILL.md +173 -0
- package/package/corpus/skills/cratis-application-slice-conformance/references/checklists.md +66 -0
- package/package/corpus/skills/cratis-application-slice-conformance/references/contract-and-precedence.md +49 -0
- package/package/corpus/skills/cratis-application-slice-conformance/references/provenance.md +23 -0
- package/package/corpus/skills/cratis-application-slice-conformance/references/worked-example.md +91 -0
- package/package/corpus/skills/cratis-application-slice-conformance/verification.json +14 -0
- package/package/corpus/skills/cratis-application-slice-specifications/SKILL.md +57 -1
- package/package/corpus/skills/cratis-application-slice-specifications/references/provenance.md +16 -0
- package/package/corpus/skills/cratis-arc-command/SKILL.md +10 -0
- package/package/corpus/skills/cratis-arc-command-execution/SKILL.md +10 -0
- package/package/corpus/skills/cratis-arc-command-validation/SKILL.md +10 -0
- package/package/corpus/skills/cratis-arc-observable-query-http/SKILL.md +10 -0
- package/package/corpus/skills/cratis-arc-query-paging/SKILL.md +10 -0
- package/package/corpus/skills/cratis-arc-react-page/SKILL.md +68 -8
- package/package/corpus/skills/cratis-arc-react-page/references/from-screenplay.md +199 -0
- package/package/corpus/skills/cratis-arc-react-page/references/provenance.md +13 -0
- package/package/corpus/skills/cratis-chronicle-event-constraints/SKILL.md +10 -0
- package/package/corpus/skills/cratis-chronicle-event-modeling/SKILL.md +38 -10
- package/package/corpus/skills/cratis-chronicle-event-type-migration/SKILL.md +13 -0
- package/package/corpus/skills/cratis-chronicle-projection/SKILL.md +13 -0
- package/package/corpus/skills/cratis-chronicle-reactor/SKILL.md +58 -6
- package/package/corpus/skills/cratis-chronicle-reactor/references/provenance.md +9 -0
- package/package/corpus/skills/cratis-chronicle-read-model/SKILL.md +13 -0
- package/package/corpus/skills/cratis-chronicle-read-model-specifications/SKILL.md +47 -0
- package/package/corpus/skills/cratis-chronicle-read-model-specifications/references/provenance.md +11 -0
- package/package/corpus/skills/cratis-chronicle-reducer/SKILL.md +13 -0
- package/package/corpus/skills/cratis-components-stepper-command-dialog/SKILL.md +13 -0
- package/package/corpus/skills/cratis-event-model-diagram/SKILL.md +35 -16
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/LICENSE +28 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/SKILL.md +166 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/audit-format.md +31 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/automation-patterns.md +139 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/cases-to-specify.md +69 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/effects-and-idempotency.md +88 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/integration-contracts.md +64 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/provenance.md +37 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/realization-and-gap-fill.md +34 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/todo-list-example.md +208 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/translate-example.md +126 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/translation-patterns.md +93 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/worked-integration.md +98 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/verification.json +15 -0
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/SKILL.md +267 -50
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/references/complete-examples.md +185 -0
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/verification.json +60 -12
- package/package/corpus/skills/cratis-screenplay-command-surface/SKILL.md +42 -12
- package/package/corpus/skills/cratis-screenplay-discovery/LICENSE +30 -0
- package/package/corpus/skills/cratis-screenplay-discovery/SKILL.md +229 -0
- package/package/corpus/skills/cratis-screenplay-discovery/references/divergent-sweep.md +37 -0
- package/package/corpus/skills/cratis-screenplay-discovery/references/event-naming.md +64 -0
- package/package/corpus/skills/cratis-screenplay-discovery/references/facilitation.md +62 -0
- package/package/corpus/skills/cratis-screenplay-discovery/references/human-workshop.md +222 -0
- package/package/corpus/skills/cratis-screenplay-discovery/references/interview-questions.md +66 -0
- package/package/corpus/skills/cratis-screenplay-discovery/references/personas-and-causes.md +152 -0
- package/package/corpus/skills/cratis-screenplay-discovery/references/plotting-and-handoff.md +111 -0
- package/package/corpus/skills/cratis-screenplay-discovery/references/provenance.md +37 -0
- package/package/corpus/skills/cratis-screenplay-discovery/references/storming-loop.md +119 -0
- package/package/corpus/skills/cratis-screenplay-discovery/references/worked-session.md +87 -0
- package/package/corpus/skills/cratis-screenplay-discovery/verification.json +15 -0
- package/package/corpus/skills/cratis-screenplay-event-modeling/SKILL.md +140 -77
- package/package/corpus/skills/cratis-screenplay-event-modeling/references/invoicing-example.md +51 -0
- package/package/corpus/skills/cratis-screenplay-event-modeling/references/nine-steps.md +114 -28
- package/package/corpus/skills/cratis-screenplay-event-modeling/references/parsed-not-runnable.md +50 -0
- package/package/corpus/skills/cratis-screenplay-event-modeling/verification.json +28 -3
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/LICENSE +31 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/SKILL.md +239 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/chronicle-observations.md +25 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/evidence-table-template.md +79 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/expert-verification.md +48 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/generate-notes.md +75 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/intent-example.md +164 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/interview-findings.md +88 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/loss-report-template.md +47 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/prologue-safety.md +147 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/provenance.md +10 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/rule-modeling.md +36 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/side-car-migration.md +126 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/signal-to-intent.md +57 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/ui-observation.md +52 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/verification.json +17 -0
- package/package/corpus/skills/cratis-screenplay-model-authoring/SKILL.md +95 -54
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/language-reference.md +50 -20
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/mcp-loop.md +211 -0
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/mcp-tools.md +45 -5
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/provenance.md +13 -0
- package/package/corpus/skills/cratis-screenplay-model-authoring/verification.json +64 -7
- package/package/corpus/skills/cratis-screenplay-model-review/LICENSE +34 -0
- package/package/corpus/skills/cratis-screenplay-model-review/SKILL.md +209 -0
- package/package/corpus/skills/cratis-screenplay-model-review/references/anti-patterns.md +89 -0
- package/package/corpus/skills/cratis-screenplay-model-review/references/business-questions.md +128 -0
- package/package/corpus/skills/cratis-screenplay-model-review/references/checklist.md +176 -0
- package/package/corpus/skills/cratis-screenplay-model-review/references/provenance.md +36 -0
- package/package/corpus/skills/cratis-screenplay-model-review/references/report-template.md +149 -0
- package/package/corpus/skills/cratis-screenplay-model-review/references/review-questions.md +59 -0
- package/package/corpus/skills/cratis-screenplay-model-review/references/worked-example.md +255 -0
- package/package/corpus/skills/cratis-screenplay-model-review/verification.json +13 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/LICENSE +32 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/SKILL.md +239 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/code-reading-and-tokens.md +55 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/handoff-template.md +124 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/identity-and-edits.md +84 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/opt-in.md +48 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/phase-report-inventories.md +25 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/phases.md +162 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/principles.md +53 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/provenance.md +63 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/reasoning-notes.md +31 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/safety.md +31 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/stop-or-assume.md +46 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/verdicts-and-modes.md +204 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/vocabulary-map.md +55 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/worked-example.md +86 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/verification.json +16 -0
- package/package/corpus/skills/cratis-screenplay-projections/SKILL.md +14 -3
- package/package/corpus/skills/cratis-screenplay-read-surface/SKILL.md +15 -1
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/LICENSE +2 -0
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/SKILL.md +179 -0
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/references/delivery-protocol.md +99 -0
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/references/drift-and-ledger.md +67 -0
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/references/gap-fill-handoff.md +72 -0
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/references/provenance.md +27 -0
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/references/renderability-gate.md +56 -0
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/references/worked-example.md +124 -0
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/verification.json +14 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/LICENSE +31 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/SKILL.md +200 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/berth-reservations.md +579 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/chronicle-verification.md +24 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/coverage-matrix.md +102 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/provenance.md +41 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/scenario-catalogue.md +196 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/scenario-workshop.md +102 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/spec-forms-by-mode.md +71 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/view-and-story-specs.md +91 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/verification.json +13 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/LICENSE +30 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/SKILL.md +236 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/references/command-inventory.md +107 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/references/field-lineage.md +130 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/references/provenance.md +20 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/references/read-model-design.md +201 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/references/review-questions.md +23 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/references/rule-layers.md +41 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/references/slicing.md +122 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/references/worked-example.md +305 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/verification.json +43 -0
- package/package/corpus/skills/cratis-screenplay-specifications/SKILL.md +217 -36
- package/package/corpus/skills/cratis-screenplay-specifications/verification.json +28 -4
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/LICENSE +33 -0
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/SKILL.md +191 -0
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/boundaries.md +154 -0
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/chronicle-boundaries.md +54 -0
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/consistency-and-concurrency.md +191 -0
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/evolution-example.md +70 -0
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/evolution.md +65 -0
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/provenance.md +13 -0
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/stream-patterns.md +128 -0
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/streams-example.md +378 -0
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/verification.json +14 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/LICENSE +2 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/SKILL.md +177 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/automation-translate-example.md +121 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/cheat-sheet-example.md +319 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/cheat-sheet.md +96 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/diagnostics.md +107 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/doc-contradictions.md +48 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/executable-example.md +113 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/executable-subset.md +148 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/pdl-example.md +267 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/provenance.md +51 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/renderable-subset.md +88 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/traps.md +51 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/verdicts.md +134 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/versions.md +134 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/verification.json +15 -0
- package/package/corpus/skills/cratis-screenplay-ui-composition/SKILL.md +53 -5
- package/package/corpus/skills/cratis-screenplay-ui-composition/references/flow-review.md +56 -0
- package/package/corpus/skills/cratis-screenplay-ui-composition/references/provenance.md +13 -0
- package/package/corpus/skills/cratis-screenplay-ui-composition/references/worked-flow.md +65 -0
- package/package/corpus/skills/cratis-screenplay-ui-composition/verification.json +4 -1
- package/package/corpus/skills/cratis-specification-by-example/SKILL.md +44 -1
- package/package/corpus/skills/cratis-specifications-csharp/SKILL.md +10 -0
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/SKILL.md +186 -219
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/admission.md +177 -0
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/render-example.md +150 -0
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/rendered-application.md +87 -0
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/sandbox-and-specrunner.md +98 -0
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/verification.json +19 -0
- package/package/profile-catalog.json +11 -0
- package/package.json +1 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Stream patterns
|
|
2
|
+
|
|
3
|
+
A stream in Screenplay is the event source a production lands on: `identifier` on the
|
|
4
|
+
command, `for <identifier>` on each `produces`, `$eventSourceId` in projections, `for "<id>"`
|
|
5
|
+
in specifications. Choosing the identifier *is* choosing the stream.
|
|
6
|
+
|
|
7
|
+
## Identity and event-membership review
|
|
8
|
+
Start from the business instance, then choose its representation. A generated id can name a
|
|
9
|
+
real instance; a readable constant can hide a collection. Write one sentence per identity
|
|
10
|
+
concept:
|
|
11
|
+
|
|
12
|
+
> `EnrolmentId`: one stream per enrolment of one member in one course; it answers "what is
|
|
13
|
+
> the state of this enrolment?"
|
|
14
|
+
|
|
15
|
+
For every affected identifier:
|
|
16
|
+
1. Name the instance and its lifecycle.
|
|
17
|
+
2. Inspect every producer and destination that can write its history, including reactions and
|
|
18
|
+
captures (`cratis-screenplay-automations-and-translations`), not only event declarations.
|
|
19
|
+
3. Explain how each event changes or records that instance's history.
|
|
20
|
+
4. List cross-stream references (payload properties) and the consumers that need them.
|
|
21
|
+
5. Decide: retain, split, model a view instead, or leave unresolved pending a named answer.
|
|
22
|
+
Record a short reason and the invariant a split would affect; do not build a second catalog.
|
|
23
|
+
|
|
24
|
+
Facts about another thing go on that thing's stream with a reference as payload
|
|
25
|
+
(`MemberEnrolled` carries `courseId` and `memberId`). A view over many streams is a projection
|
|
26
|
+
keyed by the reference (`from MemberEnrolled key courseId`), never a shared stream. A command
|
|
27
|
+
with no identifier allocates a new stream (executable mode needs explicit allocation, see
|
|
28
|
+
`cratis-screenplay-toolchain`). Prefer an identifier the caller chooses before the first attempt: it
|
|
29
|
+
is also the retry identity; one allocated afresh per retry can create a second history.
|
|
30
|
+
Never use personal data as the identifier (see `chronicle-boundaries.md`).
|
|
31
|
+
|
|
32
|
+
### Event-by-event identity check (record the result)
|
|
33
|
+
Do not stop at the identity concept's name. Walk every event, command production, reaction and
|
|
34
|
+
capture that writes to the identifier and fill one row each:
|
|
35
|
+
|
|
36
|
+
| Event | Written by (command, reaction, capture) | How it changes or records this instance's history | Belongs? |
|
|
37
|
+
|---|---|---|---|
|
|
38
|
+
| `MemberEnrolled` | `EnrolMember` | records the enrolment decision | yes |
|
|
39
|
+
| `CourseSeatsAdjusted` | `AdjustSeats` (same identifier) | changes the course, not the enrolment | no: move to the course stream |
|
|
40
|
+
|
|
41
|
+
Then decide per identity, with a reason and the invariant a split would affect:
|
|
42
|
+
- **retain**: every event is a fact about this instance, however long the history;
|
|
43
|
+
- **split**: some events have another lifecycle or decision owner; name the new identity and
|
|
44
|
+
re-check every rule and reference that crossed the split;
|
|
45
|
+
- **view instead**: the "stream" is really a collection or report; keep facts on the real
|
|
46
|
+
instances and build the combined view by projection;
|
|
47
|
+
- **unresolved**: record the question, the person who can answer and the default taken meanwhile.
|
|
48
|
+
|
|
49
|
+
## Interpret the evidence
|
|
50
|
+
| Observation | Investigation and possible decision |
|
|
51
|
+
|---|---|
|
|
52
|
+
| Events describe one business instance | Retain, however long the history. |
|
|
53
|
+
| Parent and children decide together and share a lifetime | A small composite may be one stream; test shared invariants and whether children live independently. |
|
|
54
|
+
| Independent instances appended together only for reporting | Give each its own identity; build the combined view from facts. |
|
|
55
|
+
| A named collection makes its own decisions | It may be a real entity: separate its membership facts from its members' histories. |
|
|
56
|
+
| Unrelated technical happenings share a source | An audit or observability log is not a domain decision boundary; split by business concern or leave to observability. |
|
|
57
|
+
| Groups of events with independent lifecycles (profile vs sessions) | Consider one identity each, then re-evaluate rules and references that cross the split. |
|
|
58
|
+
| A closed instance still needs its history | Retain the identity by default; different access frequency alone is no reason to split. |
|
|
59
|
+
| Archive custody has its own business lifecycle | Consider a linked identity for custody facts; preserve the original history. |
|
|
60
|
+
|
|
61
|
+
Length, age, event count, a conjunction in a description or a collection-like name each fail to
|
|
62
|
+
prove a boundary wrong: a thirty-year account is correctly one long stream. Report a defect only
|
|
63
|
+
with the lost business meaning, lifecycle independence or consistency that follows.
|
|
64
|
+
|
|
65
|
+
## Event meaning is a separate check
|
|
66
|
+
A correctly routed event can still be unclear. Do not name an event or command for a form:
|
|
67
|
+
`Update/Edit/Save/Set/Change/Manage<Noun>` and `<Noun>Updated/Changed/Edited/Saved/Modified` are
|
|
68
|
+
not accepted names. Name the business act, or for a correction say what it corrects
|
|
69
|
+
(`ResultCorrected`); ask which decision happened and whether a consumer can tell it from other
|
|
70
|
+
changes without comparing snapshots (naming method: `cratis-screenplay-discovery`, `cratis-screenplay-slice-design`). Do not split every property into an event, and do not merge recognised facts
|
|
71
|
+
because one command produced them. Separately, an event whose payload restates the creation event is a review signal (major only when
|
|
72
|
+
meaning is lost, a rule is bypassed or consumers become ambiguous); historical generations are
|
|
73
|
+
exempt from that signal, not from the naming rule.
|
|
74
|
+
|
|
75
|
+
## Contrasting examples
|
|
76
|
+
- A research study may accumulate observations for years; duration does not invalidate the study
|
|
77
|
+
identity, yet participants or lab analyses may have their own lifecycles.
|
|
78
|
+
- A diagnostic panel request may own several measurements finalized together; a measurement that
|
|
79
|
+
can be commissioned and repeated alone suggests its own identity and a rule joining results.
|
|
80
|
+
- "All analyses received today" is a query; a scheduled analysis batch with its own authorization,
|
|
81
|
+
capacity and completion decisions can be a real instance.
|
|
82
|
+
- Closing a study needs no rewrite into an ArchivedStudy stream; a separately managed legal-custody
|
|
83
|
+
case may warrant a linked identity.
|
|
84
|
+
|
|
85
|
+
## Growth and snapshots
|
|
86
|
+
Design first, snapshot second. If a stream seems too long, first ask whether the identity is wrong
|
|
87
|
+
(split by the narrower business instance), whether events are too fine-grained, and whether
|
|
88
|
+
decisions read from a projection rather than replaying history. Snapshotting, caching and replay
|
|
89
|
+
speed are target concerns: Screenplay does not model them, and the model must never grow a stream
|
|
90
|
+
or an event only to make replay cheaper. Estimate before worrying: events per instance per year
|
|
91
|
+
times the instance lifetime. Measure real replay latency in the target before adding any snapshot
|
|
92
|
+
mechanism, and name the commands that actually replay the stream rather than read a view. A
|
|
93
|
+
thirty-year account is correctly one long stream; an eternal "all orders" stream is not.
|
|
94
|
+
|
|
95
|
+
## Short lifecycles
|
|
96
|
+
When the business has natural ends (a period, an attempt, a case, a booking), a stream per
|
|
97
|
+
end-bounded thing keeps streams short, keeps evolution cheap (old shapes stop being written
|
|
98
|
+
soon), and narrows races. Do not invent artificial periods where the business has none.
|
|
99
|
+
|
|
100
|
+
## Consistency questions per stream
|
|
101
|
+
Ask for each stream:
|
|
102
|
+
1. Which rules must hold *at the moment of appending* to this stream? (enforce here)
|
|
103
|
+
2. Which rules span several streams? (constraint, or recorded state-dependent rule)
|
|
104
|
+
3. Who else writes to this stream, and can they race? (concurrency scenario)
|
|
105
|
+
4. What does a retry of each command do? (retry identity, `unique event`)
|
|
106
|
+
5. Which views read it, and what may they show late? (projection lag)
|
|
107
|
+
|
|
108
|
+
## Constraint scope and what it implies for stream choice
|
|
109
|
+
- A Screenplay constraint covers the whole event sequence across all sources; narrower scope
|
|
110
|
+
(per source type or stream) cannot be declared yet.
|
|
111
|
+
- `unique <prop> on <Event>`: the value belongs to one source; that source may re-claim it,
|
|
112
|
+
and a new value from the same source frees the old one. Nulls are skipped.
|
|
113
|
+
- `unique event <Event>`: at most once per source. Several `unique event` lines under one
|
|
114
|
+
name are mutually exclusive until `released by`. This is how simple lifecycle rules
|
|
115
|
+
("one result per attempt", "withdraw once") can be enforced atomically today.
|
|
116
|
+
- So: if a rule is "one per X", make X's stream the source and use `unique event`; if it is
|
|
117
|
+
"no two Xs share Y", put Y on the event and use `unique Y on`.
|
|
118
|
+
|
|
119
|
+
## Decision-scoped consistency (note)
|
|
120
|
+
Some event stores decide consistency by a query over tagged events instead of one stream
|
|
121
|
+
(often called dynamic consistency boundaries). Chronicle's concurrency scopes can narrow a
|
|
122
|
+
check to event types, source type or stream (`concurrency` block, Screenplay
|
|
123
|
+
`commands.md`), and Screenplay has syntax-only event-source/stream declarations (ESM v10,
|
|
124
|
+
`event-sources.md`). None of this binds on either compiler (`versions.md` in `cratis-screenplay-toolchain`). Model the stream by business
|
|
125
|
+
identity; when a rule truly needs a cross-stream decision, record it (see
|
|
126
|
+
`consistency-and-concurrency.md`) rather than inventing a construct.
|
|
127
|
+
|
|
128
|
+
Complete compiled example: `streams-example.md`.
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
# Example: streams, constraints and a recorded rule
|
|
2
|
+
|
|
3
|
+
A complete design-mode model for course enrolment. It shows one business identity per stream,
|
|
4
|
+
cross-stream references as payload, three kinds of uniqueness constraint, a state-dependent
|
|
5
|
+
rule recorded as **NOT enforced in the model today**, a declared `concurrency` scope, and an
|
|
6
|
+
active-state view with removal. Read it with `consistency-and-concurrency.md` (sections 1-4).
|
|
7
|
+
|
|
8
|
+
The model compiles (V1, warnings as errors) but is not binding-ready by design: the `@pii`
|
|
9
|
+
concept fails binding (PLAY0268), `reads` and the `concurrency` block are PLAY0271, and
|
|
10
|
+
`require` over a view is PLAY0268. Keep those lines: they state real intent.
|
|
11
|
+
|
|
12
|
+
```screenplay
|
|
13
|
+
// cratis-screenplay-streams-and-consistency: complete design-mode example (V1 with --warnings-as-errors).
|
|
14
|
+
// Shows: one business identity per stream, cross-stream references as payload, uniqueness
|
|
15
|
+
// constraints (single, composite with release, unique event), a recorded state-dependent rule
|
|
16
|
+
// that Screenplay cannot enforce, a declared concurrency scope, and an active-state view with removal.
|
|
17
|
+
// Not executable on either tool (probed): the @pii concept fails binding (PLAY0268), the
|
|
18
|
+
// concurrency block and `reads` are PLAY0271, `require` over a view is PLAY0268. Keep them: they state
|
|
19
|
+
// real intent. The capacity rule is NOT enforced in the model today (see the slice description).
|
|
20
|
+
|
|
21
|
+
domain Acme.Academy
|
|
22
|
+
|
|
23
|
+
concept MemberId : Uuid // event source id of one member stream
|
|
24
|
+
concept CourseId : Uuid // event source id of one course stream
|
|
25
|
+
concept EnrolmentId : Uuid // event source id of one enrolment stream
|
|
26
|
+
concept Email : String @pii
|
|
27
|
+
pii reason "Identifies a person"
|
|
28
|
+
validate
|
|
29
|
+
not empty message "An email is required"
|
|
30
|
+
|
|
31
|
+
policy IsAuthenticated
|
|
32
|
+
require authenticated
|
|
33
|
+
policy IsCoordinator
|
|
34
|
+
require role "Coordinator"
|
|
35
|
+
persona Coordinator
|
|
36
|
+
description "Schedules courses and manages enrolments. Cannot: change member contact details"
|
|
37
|
+
policy IsAuthenticated
|
|
38
|
+
policy IsCoordinator
|
|
39
|
+
|
|
40
|
+
module Membership
|
|
41
|
+
description "Who our members are"
|
|
42
|
+
authorize IsAuthenticated
|
|
43
|
+
feature Members
|
|
44
|
+
slice StateChange RegisterMember
|
|
45
|
+
description "A person becomes a member; the email address is unique across members"
|
|
46
|
+
command RegisterMember
|
|
47
|
+
memberId MemberId identifier
|
|
48
|
+
email Email
|
|
49
|
+
name String
|
|
50
|
+
authorize IsCoordinator
|
|
51
|
+
produces MemberRegistered
|
|
52
|
+
for memberId
|
|
53
|
+
email = email
|
|
54
|
+
name = name
|
|
55
|
+
event MemberRegistered
|
|
56
|
+
email Email
|
|
57
|
+
name String
|
|
58
|
+
constraint UniqueMemberEmail
|
|
59
|
+
unique email on MemberRegistered
|
|
60
|
+
ignore casing
|
|
61
|
+
specification RegisteringAMember
|
|
62
|
+
given caller
|
|
63
|
+
authenticated
|
|
64
|
+
role "Coordinator"
|
|
65
|
+
when RegisterMember
|
|
66
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
67
|
+
email = "kari@example.com"
|
|
68
|
+
name = "Kari"
|
|
69
|
+
then MemberRegistered
|
|
70
|
+
for "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
71
|
+
email = "kari@example.com"
|
|
72
|
+
name = "Kari"
|
|
73
|
+
specification RefusingARegistrationWithoutTheCoordinatorRole
|
|
74
|
+
given caller
|
|
75
|
+
authenticated
|
|
76
|
+
when RegisterMember
|
|
77
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
78
|
+
email = "kari@example.com"
|
|
79
|
+
name = "Kari"
|
|
80
|
+
then denied
|
|
81
|
+
specification RefusingAnEmailAnotherMemberHolds
|
|
82
|
+
given caller
|
|
83
|
+
authenticated
|
|
84
|
+
role "Coordinator"
|
|
85
|
+
given MemberRegistered
|
|
86
|
+
for "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
87
|
+
email = "kari@example.com"
|
|
88
|
+
name = "Kari"
|
|
89
|
+
when RegisterMember
|
|
90
|
+
memberId = "7b2d3c9f-1c2e-4e66-8b4f-3a7b8d2e1f22"
|
|
91
|
+
email = "kari@example.com"
|
|
92
|
+
name = "Kari Two"
|
|
93
|
+
then error "Constraint 'UniqueMemberEmail' is violated: another event source already holds the constrained value."
|
|
94
|
+
|
|
95
|
+
module Courses
|
|
96
|
+
description "Courses and who attends them"
|
|
97
|
+
authorize IsAuthenticated
|
|
98
|
+
feature Enrolment
|
|
99
|
+
authorize IsCoordinator
|
|
100
|
+
slice StateChange OpenCourse
|
|
101
|
+
command OpenCourse
|
|
102
|
+
courseId CourseId identifier
|
|
103
|
+
seats Int
|
|
104
|
+
produces CourseOpened
|
|
105
|
+
for courseId
|
|
106
|
+
seats = seats
|
|
107
|
+
event CourseOpened
|
|
108
|
+
seats Int
|
|
109
|
+
specification OpeningACourse
|
|
110
|
+
given caller
|
|
111
|
+
authenticated
|
|
112
|
+
role "Coordinator"
|
|
113
|
+
when OpenCourse
|
|
114
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
115
|
+
seats = 12
|
|
116
|
+
then CourseOpened
|
|
117
|
+
for "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
118
|
+
seats = 12
|
|
119
|
+
specification RefusingOpeningACourseWithoutTheCoordinatorRole
|
|
120
|
+
given caller
|
|
121
|
+
authenticated
|
|
122
|
+
when OpenCourse
|
|
123
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
124
|
+
seats = 12
|
|
125
|
+
then denied
|
|
126
|
+
|
|
127
|
+
slice StateView CourseAvailability
|
|
128
|
+
description "Open seats per course, built from enrolment and withdrawal facts. A lagging view: usable for display and as stated intent, not as a protected decision. It routes enrolment-stream facts to the course by a payload property (fan-in). A Chronicle protected decision read admits only a projection keyed directly by the event source id and refuses event-property routing, so this view cannot be guarded, and a concurrency scope on the course source would not see enrolment-stream appends. Consequence: two concurrent enrolments can both pass the capacity check and overbook the course. Redesign awaiting agreement (see consistency-and-concurrency.md section 3): record seat reservations as decisions on the course source (a seat-taken fact there, with enrolment reacting to it), or give each seat its own identity and claim it with a uniqueness constraint."
|
|
129
|
+
readmodel CourseAvailability
|
|
130
|
+
courseId CourseId
|
|
131
|
+
openSeats Int
|
|
132
|
+
query CourseAvailabilityById => CourseAvailability optional
|
|
133
|
+
by courseId CourseId
|
|
134
|
+
projection CourseAvailabilityProjection => CourseAvailability
|
|
135
|
+
from CourseOpened
|
|
136
|
+
courseId = $eventSourceId
|
|
137
|
+
openSeats = seats
|
|
138
|
+
from MemberEnrolled key courseId
|
|
139
|
+
decrement openSeats
|
|
140
|
+
from EnrolmentWithdrawn key courseId
|
|
141
|
+
increment openSeats
|
|
142
|
+
specification CountingOpenSeats
|
|
143
|
+
given caller
|
|
144
|
+
authenticated
|
|
145
|
+
role "Coordinator"
|
|
146
|
+
given CourseOpened
|
|
147
|
+
for "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
148
|
+
seats = 12
|
|
149
|
+
given MemberEnrolled
|
|
150
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
151
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
152
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
153
|
+
then query CourseAvailabilityById
|
|
154
|
+
arguments
|
|
155
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
156
|
+
result
|
|
157
|
+
openSeats = 11
|
|
158
|
+
specification RefusingAvailabilityToAnOrdinaryMember
|
|
159
|
+
given caller
|
|
160
|
+
authenticated
|
|
161
|
+
then query CourseAvailabilityById
|
|
162
|
+
arguments
|
|
163
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
164
|
+
then denied
|
|
165
|
+
|
|
166
|
+
slice StateChange EnrolMember
|
|
167
|
+
description "Atomic here: one active enrolment per member and course (composite unique constraint, released by withdrawal), and one MemberEnrolled per enrolment stream, so a retry with the same enrolment id after a lost reply cannot enrol twice (the composite constraint alone lets a source re-claim its own value). NOT enforced in the model today: 'enrolments never exceed the course capacity'. The rule depends on other streams' state: `reads` is PLAY0271 and `require` over a view is PLAY0268 at binding (Screenplay#129/#209). The enrolment-to-course fan-in cannot be protected as modeled (see the CourseAvailability slice): concurrent enrolments can overbook. Target enforcement is an open decision (consistency-and-concurrency.md section 3); the model stays as stated intent, recorded in STATE.md."
|
|
168
|
+
command EnrolMember
|
|
169
|
+
enrolmentId EnrolmentId identifier
|
|
170
|
+
courseId CourseId
|
|
171
|
+
memberId MemberId
|
|
172
|
+
concurrency
|
|
173
|
+
eventSource
|
|
174
|
+
reads CourseAvailability as course by courseId // stated intent, unprotected (PLAY0271 at binding)
|
|
175
|
+
validate
|
|
176
|
+
require course.openSeats > 0
|
|
177
|
+
message "The course is full" // NOT enforced: the view lags (PLAY0268 at binding)
|
|
178
|
+
produces MemberEnrolled
|
|
179
|
+
for enrolmentId
|
|
180
|
+
courseId = courseId // cross-stream references are payload
|
|
181
|
+
memberId = memberId
|
|
182
|
+
event MemberEnrolled
|
|
183
|
+
courseId CourseId
|
|
184
|
+
memberId MemberId
|
|
185
|
+
constraint OneActiveEnrolmentPerMemberAndCourse
|
|
186
|
+
unique courseId, memberId on MemberEnrolled
|
|
187
|
+
released by EnrolmentWithdrawn
|
|
188
|
+
constraint EnrolOnce
|
|
189
|
+
unique event MemberEnrolled
|
|
190
|
+
specification EnrollingAMember
|
|
191
|
+
given caller
|
|
192
|
+
authenticated
|
|
193
|
+
role "Coordinator"
|
|
194
|
+
given CourseOpened
|
|
195
|
+
for "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
196
|
+
seats = 12
|
|
197
|
+
when EnrolMember
|
|
198
|
+
enrolmentId = "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
199
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
200
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
201
|
+
then MemberEnrolled
|
|
202
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
203
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
204
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
205
|
+
specification RefusingARetriedEnrolment
|
|
206
|
+
given caller
|
|
207
|
+
authenticated
|
|
208
|
+
role "Coordinator"
|
|
209
|
+
given CourseOpened
|
|
210
|
+
for "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
211
|
+
seats = 12
|
|
212
|
+
given MemberEnrolled
|
|
213
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
214
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
215
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
216
|
+
when EnrolMember
|
|
217
|
+
enrolmentId = "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
218
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
219
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
220
|
+
then error "Constraint 'EnrolOnce' is violated: the event source already has the constrained event."
|
|
221
|
+
|
|
222
|
+
specification RefusingAnEnrolmentWithoutTheCoordinatorRole
|
|
223
|
+
given caller
|
|
224
|
+
authenticated
|
|
225
|
+
when EnrolMember
|
|
226
|
+
enrolmentId = "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
227
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
228
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
229
|
+
then denied
|
|
230
|
+
specification RefusingASecondActiveEnrolmentUnderANewId
|
|
231
|
+
given caller
|
|
232
|
+
authenticated
|
|
233
|
+
role "Coordinator"
|
|
234
|
+
given CourseOpened
|
|
235
|
+
for "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
236
|
+
seats = 12
|
|
237
|
+
given MemberEnrolled
|
|
238
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
239
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
240
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
241
|
+
when EnrolMember
|
|
242
|
+
enrolmentId = "1e4c0f3b-7d5a-4a2f-9c8b-6f3e2d4c5b12"
|
|
243
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
244
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
245
|
+
then error "Constraint 'OneActiveEnrolmentPerMemberAndCourse' is violated: another event source already holds the constrained value."
|
|
246
|
+
specification ReEnrollingAfterWithdrawal
|
|
247
|
+
given caller
|
|
248
|
+
authenticated
|
|
249
|
+
role "Coordinator"
|
|
250
|
+
given CourseOpened
|
|
251
|
+
for "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
252
|
+
seats = 12
|
|
253
|
+
given MemberEnrolled
|
|
254
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
255
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
256
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
257
|
+
given EnrolmentWithdrawn
|
|
258
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
259
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
260
|
+
when EnrolMember
|
|
261
|
+
enrolmentId = "1e4c0f3b-7d5a-4a2f-9c8b-6f3e2d4c5b12"
|
|
262
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
263
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
264
|
+
then MemberEnrolled
|
|
265
|
+
for "1e4c0f3b-7d5a-4a2f-9c8b-6f3e2d4c5b12"
|
|
266
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
267
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
268
|
+
|
|
269
|
+
slice StateChange WithdrawEnrolment
|
|
270
|
+
description "NOT enforced in the model today: a withdrawal must name an existing active enrolment of the same course. `courseId` is only a routing reference supplied by the caller, so without this check a wrong course would restore a seat elsewhere, and a withdrawal of an enrolment that does not exist would invent a free seat. Stated as `reads` + `require` over ActiveEnrolmentEntry (PLAY0271/PLAY0268 at binding). Target enforcement: a protected decision read of the enrolment (it is keyed directly by the enrolment source id, so it qualifies). Requirements to test in the target: withdrawing an unknown enrolment is rejected; withdrawing with another course is rejected; a correct withdrawal restores one seat."
|
|
271
|
+
command WithdrawEnrolment
|
|
272
|
+
enrolmentId EnrolmentId identifier
|
|
273
|
+
courseId CourseId
|
|
274
|
+
reads ActiveEnrolmentEntry as enrolment by enrolmentId // stated intent, unprotected
|
|
275
|
+
validate
|
|
276
|
+
require enrolment.courseId == courseId
|
|
277
|
+
message "The enrolment does not belong to that course" // NOT enforced today
|
|
278
|
+
produces EnrolmentWithdrawn
|
|
279
|
+
for enrolmentId
|
|
280
|
+
courseId = courseId
|
|
281
|
+
event EnrolmentWithdrawn
|
|
282
|
+
courseId CourseId
|
|
283
|
+
constraint WithdrawOnce
|
|
284
|
+
unique event EnrolmentWithdrawn
|
|
285
|
+
specification WithdrawingAnEnrolment
|
|
286
|
+
given caller
|
|
287
|
+
authenticated
|
|
288
|
+
role "Coordinator"
|
|
289
|
+
given MemberEnrolled
|
|
290
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
291
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
292
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
293
|
+
when WithdrawEnrolment
|
|
294
|
+
enrolmentId = "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
295
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
296
|
+
then EnrolmentWithdrawn
|
|
297
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
298
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
299
|
+
specification RefusingAWithdrawalWithoutTheCoordinatorRole
|
|
300
|
+
given caller
|
|
301
|
+
authenticated
|
|
302
|
+
when WithdrawEnrolment
|
|
303
|
+
enrolmentId = "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
304
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
305
|
+
then denied
|
|
306
|
+
specification RefusingASecondWithdrawal
|
|
307
|
+
given caller
|
|
308
|
+
authenticated
|
|
309
|
+
role "Coordinator"
|
|
310
|
+
given MemberEnrolled
|
|
311
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
312
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
313
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
314
|
+
given EnrolmentWithdrawn
|
|
315
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
316
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
317
|
+
when WithdrawEnrolment
|
|
318
|
+
enrolmentId = "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
319
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
320
|
+
then error "The enrolment does not belong to that course"
|
|
321
|
+
specification AppendingASecondWithdrawal
|
|
322
|
+
given MemberEnrolled
|
|
323
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
324
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
325
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
326
|
+
given EnrolmentWithdrawn
|
|
327
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
328
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
329
|
+
when append EnrolmentWithdrawn
|
|
330
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
331
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
332
|
+
then error "Constraint 'WithdrawOnce' is violated: the event source already has the constrained event."
|
|
333
|
+
|
|
334
|
+
slice StateView ActiveEnrolment
|
|
335
|
+
description "An active enrolment is present until withdrawal; the facts stay in history."
|
|
336
|
+
readmodel ActiveEnrolmentEntry
|
|
337
|
+
enrolmentId EnrolmentId
|
|
338
|
+
courseId CourseId
|
|
339
|
+
memberId MemberId
|
|
340
|
+
query ActiveEnrolmentById => ActiveEnrolmentEntry optional
|
|
341
|
+
by enrolmentId EnrolmentId
|
|
342
|
+
projection ActiveEnrolments => ActiveEnrolmentEntry
|
|
343
|
+
from MemberEnrolled
|
|
344
|
+
enrolmentId = $eventSourceId
|
|
345
|
+
courseId = courseId
|
|
346
|
+
memberId = memberId
|
|
347
|
+
remove with EnrolmentWithdrawn
|
|
348
|
+
specification ShowingAnActiveEnrolment
|
|
349
|
+
given caller
|
|
350
|
+
authenticated
|
|
351
|
+
role "Coordinator"
|
|
352
|
+
given MemberEnrolled
|
|
353
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
354
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
355
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
356
|
+
then query ActiveEnrolmentById
|
|
357
|
+
arguments
|
|
358
|
+
enrolmentId = "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
359
|
+
result
|
|
360
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
361
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
362
|
+
specification RefusingEnrolmentDetailToAnOrdinaryMember
|
|
363
|
+
given caller
|
|
364
|
+
authenticated
|
|
365
|
+
then query ActiveEnrolmentById
|
|
366
|
+
arguments
|
|
367
|
+
enrolmentId = "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
368
|
+
then denied
|
|
369
|
+
specification RemovingAWithdrawnEnrolment
|
|
370
|
+
given MemberEnrolled
|
|
371
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
372
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
373
|
+
memberId = "6f1c2a8e-0b1d-4d55-9a3e-2f6a7c1d0e11"
|
|
374
|
+
when append EnrolmentWithdrawn
|
|
375
|
+
for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
376
|
+
courseId = "a4e7c1d2-3b5f-4a6e-9c8d-7f1e2d3c4b02"
|
|
377
|
+
then no readmodel ActiveEnrolmentEntry for "0d3b9e2a-6c4f-4f1e-8b7a-5e2d1c3b4a01"
|
|
378
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"skill": "cratis-screenplay-streams-and-consistency",
|
|
3
|
+
"input": "Review the stream identities in our Screenplay model, tell me whether two people can enrol in the last seat at once, and what happens when a client retries after a lost reply.",
|
|
4
|
+
"fixtures": [],
|
|
5
|
+
"assertions": [
|
|
6
|
+
{ "kind": "skill-contains", "value": "one business identity per stream" },
|
|
7
|
+
{ "kind": "skill-contains", "value": "NOT enforced in the model today" },
|
|
8
|
+
{ "kind": "skill-contains", "value": "#3744" },
|
|
9
|
+
{ "kind": "skill-contains", "value": "`[ProtectedDecision]`" },
|
|
10
|
+
{ "kind": "skill-contains", "value": "ownership interview" },
|
|
11
|
+
{ "kind": "skill-contains", "value": "retry identity" },
|
|
12
|
+
{ "kind": "skill-contains", "value": "CHR0034" }
|
|
13
|
+
]
|
|
14
|
+
}
|