@cratis/pi 7.6.1 → 7.6.3
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/rules/reactors.md +11 -0
- package/package/corpus/rules/vertical-slices.md +27 -0
- package/package/corpus/skills/cratis-arc-command-execution/SKILL.md +38 -1
- package/package/corpus/skills/cratis-arc-query-paging/SKILL.md +7 -2
- package/package/corpus/skills/cratis-chronicle-projection/SKILL.md +14 -0
- package/package/corpus/skills/cratis-chronicle-reactor/SKILL.md +20 -0
- package/package/corpus/skills/cratis-chronicle-read-model/SKILL.md +36 -2
- package/package/corpus/skills/cratis-chronicle-read-model/references/queries.md +37 -0
- package/package/corpus/skills/cratis-chronicle-reducer/SKILL.md +16 -0
- package/package/corpus/skills/cratis-performance-review/SKILL.md +14 -1
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/SKILL.md +8 -0
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/verification.json +3 -0
- package/package/corpus/skills/cratis-screenplay-command-surface/SKILL.md +85 -8
- package/package/corpus/skills/cratis-screenplay-command-surface/references/context.md +10 -0
- package/package/corpus/skills/cratis-screenplay-command-surface/verification.json +10 -0
- package/package/corpus/skills/cratis-screenplay-event-modeling/SKILL.md +20 -7
- package/package/corpus/skills/cratis-screenplay-event-modeling/references/nine-steps.md +25 -15
- package/package/corpus/skills/cratis-screenplay-event-modeling/verification.json +4 -1
- package/package/corpus/skills/cratis-screenplay-model-authoring/SKILL.md +44 -8
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/language-reference.md +40 -21
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/mcp-tools.md +53 -1
- package/package/corpus/skills/cratis-screenplay-model-authoring/verification.json +7 -0
- package/package/corpus/skills/cratis-screenplay-projections/SKILL.md +11 -0
- package/package/corpus/skills/cratis-screenplay-projections/verification.json +3 -0
- package/package/corpus/skills/cratis-screenplay-read-surface/SKILL.md +26 -14
- package/package/corpus/skills/cratis-screenplay-read-surface/verification.json +4 -0
- package/package/corpus/skills/cratis-screenplay-specifications/SKILL.md +18 -12
- package/package/corpus/skills/cratis-screenplay-specifications/verification.json +4 -0
- package/package/corpus/skills/cratis-screenplay-ui-composition/SKILL.md +16 -9
- package/package/corpus/skills/cratis-screenplay-ui-composition/verification.json +5 -0
- package/package.json +1 -1
|
@@ -201,6 +201,17 @@ The default is fire-and-forget. When a caller's correctness depends on all obser
|
|
|
201
201
|
7. **No state** — Reactors should be stateless. Inject dependencies via primary constructor, but do not store mutable state on the class.
|
|
202
202
|
8. **An unattended, irreversible pass reads the log, not the sink — and carries a fuse.** A reactor that deletes, revokes, bills or notifies *because a read model says something is absent* is trusting a materialized sink that is only as current as its observer: a paused partition, a replay in progress or a lagging projection makes "absent" true of the sink and false of the world. Decide from a **`[Passive]`** read model (computed on demand from the events at the moment the reactor runs) or from the events themselves. And the code shape cannot tell an **empty subject set** ("nothing to consider" — fail-safe) from an **empty qualifying set** ("nothing survived the filter" — fail-destructive: every subject is about to be acted on), so an unattended pass states its expected population, refuses when the count is implausible, and caps how many subjects one run may touch — the same discipline as [guards-and-fuses.md](./guards-and-fuses.md), applied to a reactor.
|
|
203
203
|
|
|
204
|
+
## Failure transitions **[convention]**
|
|
205
|
+
|
|
206
|
+
A domain failure must produce a timely, observable workflow outcome rather than
|
|
207
|
+
leave work looking active until a watchdog notices. Assign the transition to a
|
|
208
|
+
reliable consumer: an existing state machine can be sufficient; do not add a
|
|
209
|
+
redundant failure reactor when it already owns the event. Watchdogs cover missing
|
|
210
|
+
signals, not ordinary handling of an already recorded failure. Specify the visible
|
|
211
|
+
transition, repeated delivery, and stale failures from earlier attempts. Keep
|
|
212
|
+
public reasons free of secrets. See **cratis-chronicle-reactor** for the distinction
|
|
213
|
+
between domain failure and an observer's operational failure.
|
|
214
|
+
|
|
204
215
|
## Slice Types That Use Reactors
|
|
205
216
|
|
|
206
217
|
| Slice type | Pattern |
|
|
@@ -90,6 +90,15 @@ The command carries input from the caller. `Handle()` is defined directly on the
|
|
|
90
90
|
|
|
91
91
|
**Do not throw for normal business rejection.** A thrown exception (from `Provide()` or `Handle()`) surfaces as an exception/HTTP 500, *not* a validation result. Recoverable, user-facing rejections are validation: `ValidationResult.Error(...)` via a validator or `Result<,>`. (For step-by-step business-rule placement, invoke the **cratis-arc-command-validation** skill.)
|
|
92
92
|
|
|
93
|
+
### Nested commands **[contract]**
|
|
94
|
+
|
|
95
|
+
With Arc + Chronicle, ordinary nested pipeline commands join the outer ambient
|
|
96
|
+
transaction even when the call creates a new DI scope. Child success is enrollment,
|
|
97
|
+
not final persistence. Do not promise partial success for an atomic returned batch.
|
|
98
|
+
Independent outcomes require separate top-level executions outside that transaction;
|
|
99
|
+
operation-capable commands reject nesting entirely. See **cratis-arc-command-execution**
|
|
100
|
+
for the versioned boundary and supported alternatives.
|
|
101
|
+
|
|
93
102
|
### Causation — what a command records **[contract]**
|
|
94
103
|
|
|
95
104
|
A command's **property values** are recorded on the causation of every event it appends, alongside the command's name, so an event says not only which command produced it but what that command was asked to do. The causation is written into the event log and stays there for as long as the events do — a value recorded there cannot be taken back out by changing code.
|
|
@@ -240,10 +249,28 @@ public record Author(AuthorId Id, AuthorName Name)
|
|
|
240
249
|
|
|
241
250
|
**[convention] Read-model boundaries & naming.** Read models are shaped for consumers and command policies, not CRUD-style aggregate DTOs. Split one when it starts mixing unrelated lifecycles — the test is coupling (state that changes for different reasons), not size. The event log is already the canonical history/audit trail, so name a model `AuditLog`/`ActivityLog` only when it genuinely is an audit surface; for curated UI projections prefer names like `Timeline`, `WorkSurface`, `Summary`, `Detail`, or `Policy`. (This is "specialization over reuse" applied to read models.)
|
|
242
251
|
|
|
252
|
+
**[convention] Keep query cost bounded.** Prefer slim, purpose-built projections
|
|
253
|
+
for frequently read summaries rather than repeatedly joining broad collections.
|
|
254
|
+
This is not a one-collection framework restriction. Embed bounded children; keep
|
|
255
|
+
growing histories in separately paged timeline models. Evaluate variants when
|
|
256
|
+
lifecycle shapes diverge, and preserve reducer admission/ordering guards when
|
|
257
|
+
considering a projection conversion. Narrow observable inputs at the source.
|
|
258
|
+
Ordinary MongoDB `Observe` retains its initial set and applies changes; do not
|
|
259
|
+
claim it always re-queries the whole collection per event. Explicit recompute
|
|
260
|
+
callbacks have a different cost. See the **cratis-chronicle-read-model** skill's
|
|
261
|
+
query reference for versioned behavior and composition trade-offs.
|
|
262
|
+
|
|
243
263
|
### Choosing read-model access in command-side code **[convention]**
|
|
244
264
|
|
|
245
265
|
Ladder, first that fits: (1) direct read-model (DCB) injection — only when keyed by the command's own event-source id; (2) a `[Passive]` projection; (3) `IReadModels.GetInstanceById<T>((EventSourceId)key)` for a different/derived key; (4) a materialized projection. A lookup *interface* is justified **only** for a genuine non-key search (e.g. find-by-email) — never to wrap a keyed `GetInstanceById`.
|
|
246
266
|
|
|
267
|
+
**[contract] Passive state is not sink state.** `IMongoCollection<T>` cannot
|
|
268
|
+
compute a passive read model; any leftover documents are not maintained state.
|
|
269
|
+
Read through Chronicle by key or supported injection. **[convention]** Never
|
|
270
|
+
materialize secret-bearing state just to make a collection query work: project
|
|
271
|
+
safe metadata separately. Count passive types only as inventory, not as a defect;
|
|
272
|
+
evaluate reconstruction frequency, history length, consistency, and security.
|
|
273
|
+
|
|
247
274
|
### Existence checks — what an absent read model actually resolves to **[contract]**
|
|
248
275
|
|
|
249
276
|
`IReadModels.GetInstanceById<T>` is declared `Task<TReadModel>` (non-nullable) yet hands back `default!` when nothing exists, so the compiler gives callers no signal. What "nothing exists" resolves to depends on the **backing** — *not* on whether the model carries `[RemovedWith<T>]`:
|
|
@@ -60,7 +60,8 @@ public class <Name>Reactor(ICommandPipeline pipeline) : IReactor
|
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
`Execute(command)` is the scopeless overload: the pipeline creates its own DI
|
|
63
|
-
scope for the call. This is the normal case.
|
|
63
|
+
scope for the call. This is the normal case. **A DI scope is not an independent
|
|
64
|
+
transaction boundary**; see the nested-command contract below.
|
|
64
65
|
|
|
65
66
|
## The overloads
|
|
66
67
|
|
|
@@ -89,6 +90,42 @@ command failed for any reason, `Response` is `default` — a failed result never
|
|
|
89
90
|
carries a response, because the pipeline clears it once the execution scopes
|
|
90
91
|
have completed.
|
|
91
92
|
|
|
93
|
+
## Nested commands and atomic batches
|
|
94
|
+
|
|
95
|
+
With **Arc's Chronicle integration**, an ordinary nested pipeline command joins
|
|
96
|
+
the outer command's ambient transaction. Only the outer owner commits pending
|
|
97
|
+
returned events. The child's successful result means enrollment, not persistence;
|
|
98
|
+
a commit-time constraint rejection can reject the entire batch. Inspect and
|
|
99
|
+
propagate child failures, and never report per-item persisted success before the
|
|
100
|
+
outer result is known.
|
|
101
|
+
|
|
102
|
+
This remains true with the scopeless overload or a newly created DI scope:
|
|
103
|
+
transaction context follows the async flow, not DI scope identity. Do not invent
|
|
104
|
+
a detached `Execute` overload or use fire-and-forget work to escape the owner.
|
|
105
|
+
Standalone Arc does not supply this Chronicle transaction guarantee. The flat
|
|
106
|
+
operation-capable boundary described above is stricter and rejects nesting.
|
|
107
|
+
|
|
108
|
+
Choose the intended outcome before implementing a bulk action:
|
|
109
|
+
|
|
110
|
+
- **All-or-nothing:** one command owns the returned event batch. Report its final
|
|
111
|
+
result as one atomic outcome, not a list of independently committed children.
|
|
112
|
+
- **Independent outcomes:** orchestrate separate top-level pipeline executions
|
|
113
|
+
outside an enclosing command transaction, awaiting each final result. A durable
|
|
114
|
+
workflow/reactor can own follow-up work and retries. A collection of returned
|
|
115
|
+
reactor commands executes as separate transactions; earlier successes remain
|
|
116
|
+
when a later command fails, so retries must be idempotent.
|
|
117
|
+
|
|
118
|
+
Neither choice makes external service writes atomic. Immediate event appends
|
|
119
|
+
and explicit early commits also do not become rollbackable merely because a
|
|
120
|
+
command later fails; do not use them as an undocumented batch-isolation trick.
|
|
121
|
+
|
|
122
|
+
Checked against **Arc v22.49.0**
|
|
123
|
+
([transactional commands](https://github.com/Cratis/Arc/blob/v22.49.0/Documentation/backend/csharp/chronicle/commands/transactional-commands.md),
|
|
124
|
+
[transaction scope](https://github.com/Cratis/Arc/blob/v22.49.0/Source/DotNET/Chronicle/Commands/TransactionalCommandScope.cs),
|
|
125
|
+
[ambient context](https://github.com/Cratis/Arc/blob/v22.49.0/Source/DotNET/Chronicle/Commands/CommandTransaction.cs)).
|
|
126
|
+
Specify a later child's rejection and the actual persisted events: none for an
|
|
127
|
+
atomic returned batch, only completed independent items for separate commands.
|
|
128
|
+
|
|
92
129
|
## Pre-flight `Validate`
|
|
93
130
|
|
|
94
131
|
`await pipeline.Validate(command)` runs the authorization and validation filters
|
|
@@ -55,7 +55,7 @@ return type.
|
|
|
55
55
|
| `T`, `T?`, `IEnumerable<T>`, `List<T>`, `T[]` | No | Nothing narrows the result |
|
|
56
56
|
| `IQueryable<T>` | **Yes** | The query renderer counts, orders, then applies `Skip`/`Take` |
|
|
57
57
|
| `Task<IQueryable<T>>` | **Yes** | Awaited first, then rendered as the queryable it unwraps to |
|
|
58
|
-
| `ISubject<IEnumerable<T>>` | **Yes** | Not by the renderer — the
|
|
58
|
+
| `ISubject<IEnumerable<T>>` | **Yes, with a paging-aware storage helper** | Not by the renderer — the helper reads the ambient query context; a custom subject does not page automatically |
|
|
59
59
|
| `ISubject<IQueryable<T>>` | **No** | No `Observe` overload returns it, and the renderer matches on the outer type |
|
|
60
60
|
|
|
61
61
|
There is exactly one query renderer, and it is for `IQueryable`. Everything else
|
|
@@ -82,7 +82,7 @@ For a live paged list, return what `Observe` returns:
|
|
|
82
82
|
|
|
83
83
|
```csharp
|
|
84
84
|
public static ISubject<IEnumerable<<ReadModel>>> AllLive(<Collection> collection) =>
|
|
85
|
-
collection.Observe(
|
|
85
|
+
collection.Observe(item => !item.<IsArchived>);
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
`ARC0001` is an **error** when a query method's return type is none of the
|
|
@@ -91,6 +91,11 @@ query-shaped method on a read model is generic — a generic method is registere
|
|
|
91
91
|
and routed but can never be invoked, because there is nothing to close its type
|
|
92
92
|
parameters with.
|
|
93
93
|
|
|
94
|
+
For MongoDB `Observe` cost, distinguish the initial retained result, incremental
|
|
95
|
+
membership updates, and page-refill queries from an application callback that
|
|
96
|
+
explicitly re-runs a query. It does not always fetch the whole collection per
|
|
97
|
+
change. See the read-model skill's [versioned query-cost guidance](../cratis-chronicle-read-model/references/queries.md#cost-and-composition).
|
|
98
|
+
|
|
94
99
|
## Page the source, not the answer
|
|
95
100
|
|
|
96
101
|
- Do not `.ToList()` before returning an `IQueryable<T>` — that defeats
|
|
@@ -83,6 +83,20 @@ member list. The trap that costs the most time: **`UsingKey`, `UsingParentKey`,
|
|
|
83
83
|
`UsingCompositeKey`, and `UsingConstantKey` are not on the projection builder.**
|
|
84
84
|
They live on the per-event builder that `From<TEvent>` hands to your callback.
|
|
85
85
|
|
|
86
|
+
## Choose a bounded projection shape
|
|
87
|
+
|
|
88
|
+
Project the fields a consumer needs, rather than building a universal entity
|
|
89
|
+
with every detail and historical entry. Children are useful for bounded related
|
|
90
|
+
state, not an invitation to embed an unbounded timeline. Give growing histories
|
|
91
|
+
their own paged read model. A slim summary may combine event facts without
|
|
92
|
+
query-time joins, but there is no framework requirement that a query read only
|
|
93
|
+
one collection. Preserve security/compliance boundaries when choosing the shape.
|
|
94
|
+
|
|
95
|
+
When replacing a reducer, preserve creation/admission and late-event guards;
|
|
96
|
+
an unconditional `[SetValue<T>]` is not equivalent to guarded state transition
|
|
97
|
+
code. See the reducer skill's conversion guidance. Evaluate variants below when
|
|
98
|
+
shapes diverge; do not mandate them for every status field.
|
|
99
|
+
|
|
86
100
|
## Joins are on events, never on read models
|
|
87
101
|
|
|
88
102
|
Both `[Join<T>]` and the fluent `Join<TEvent>` take an **event** type. Joining on
|
|
@@ -328,6 +328,26 @@ surface it through the operational failure path, and skip the partial side
|
|
|
328
328
|
effect. Throwing just to reject it pauses the partition and can quarantine the
|
|
329
329
|
whole observer.
|
|
330
330
|
|
|
331
|
+
### Domain failures must leave a visible state
|
|
332
|
+
|
|
333
|
+
A recorded failure fact is not complete handling if the user-facing workflow
|
|
334
|
+
still looks running indefinitely. Give each terminal failure a reliable owner
|
|
335
|
+
that transitions the affected attempt/workflow promptly to failed, retryable, or
|
|
336
|
+
another explicit outcome, and project a safe reason for the reader. Keep secrets
|
|
337
|
+
and raw provider payloads out of public failure details.
|
|
338
|
+
|
|
339
|
+
This is an application reliability convention, **not** a requirement for a
|
|
340
|
+
separate failure reactor. An existing reliable state machine that consumes the
|
|
341
|
+
failure event and owns the transition is sufficient; adding another consumer can
|
|
342
|
+
race or duplicate it. Add a reactor only when the transition/effect has no owner.
|
|
343
|
+
Use a watchdog for missing signals or lost work, not as the normal consumer of a
|
|
344
|
+
failure already known. Distinguish domain failure from an observer partition
|
|
345
|
+
failure: the latter also needs operational monitoring and recovery.
|
|
346
|
+
|
|
347
|
+
Specify failure-to-visible-state, repeated delivery, stale failure from an older
|
|
348
|
+
attempt, and recovery/retry behavior. Prove the normal failure transition without
|
|
349
|
+
waiting for the watchdog timeout.
|
|
350
|
+
|
|
331
351
|
## Keep the reactor stateless
|
|
332
352
|
|
|
333
353
|
Inject collaborators through the primary constructor; hold no mutable state on
|
|
@@ -77,6 +77,21 @@ public record <ReadModelName>(
|
|
|
77
77
|
- `Cratis.Chronicle.ReadModels.IndexAttribute` (`[Index]`) marks a property for
|
|
78
78
|
indexing in the sink.
|
|
79
79
|
|
|
80
|
+
### Shape the model for its consumer
|
|
81
|
+
|
|
82
|
+
Prefer a slim, purpose-built projection over assembling a screen by repeatedly
|
|
83
|
+
joining broad collections at query time. A summary needs summary fields, not
|
|
84
|
+
every detail and historical entry. This is a design convention, **not a
|
|
85
|
+
one-collection framework requirement**: bounded query composition remains valid,
|
|
86
|
+
including when separate security or compliance boundaries must be preserved.
|
|
87
|
+
|
|
88
|
+
Embed children only when their cardinality and payload are bounded by the use
|
|
89
|
+
case. Keep growing activity, message, or attempt histories in separately paged
|
|
90
|
+
timeline models; embedding all history makes every parent read and emission
|
|
91
|
+
larger. Evaluate variants when lifecycle shapes genuinely diverge, not merely
|
|
92
|
+
because a status changes. See the projection skill for children and variants,
|
|
93
|
+
and [query cost and composition](references/queries.md#cost-and-composition).
|
|
94
|
+
|
|
80
95
|
## Step 3 — Choose a projection or a reducer
|
|
81
96
|
|
|
82
97
|
| | Projection | Reducer |
|
|
@@ -165,6 +180,23 @@ passive: no sink, nothing materialized, and the instance is computed on demand
|
|
|
165
180
|
from the events at the moment it is read. Reach for it when a decision needs the
|
|
166
181
|
model **strongly consistent** rather than eventually consistent.
|
|
167
182
|
|
|
183
|
+
**`IMongoCollection<T>` reads only the sink.** It cannot compute passive state:
|
|
184
|
+
a fresh passive model has no maintained collection, and a formerly active one
|
|
185
|
+
may leave stale documents. Use Chronicle's keyed read API above (or supported
|
|
186
|
+
read-model parameter injection) when you need its computed state. Do not remove
|
|
187
|
+
`[Passive]` merely to make a sink query work when the model contains secrets.
|
|
188
|
+
Keep secret-bearing state on the protected access path; project only safe
|
|
189
|
+
metadata into a separate list/search model.
|
|
190
|
+
|
|
191
|
+
The number of passive types is not itself a performance smell. Review event
|
|
192
|
+
history length, invocation frequency, and the consistency/security requirement;
|
|
193
|
+
repeated reconstruction of large histories on a hot path is the concern.
|
|
194
|
+
Passivity does not itself authorize access or encrypt secrets.
|
|
195
|
+
|
|
196
|
+
This access distinction was checked against Chronicle **v19.31.2**
|
|
197
|
+
([passive projections](https://github.com/Cratis/Chronicle/blob/v19.31.2/Documentation/projections/declarative/passive.mdx),
|
|
198
|
+
[passive reducers](https://github.com/Cratis/Chronicle/blob/v19.31.2/Documentation/reducers/passive-reducers.mdx)).
|
|
199
|
+
|
|
168
200
|
`[Passive]` on its own does **not** make a read model a projection. It is
|
|
169
201
|
deliberately excluded from the annotations that do; it changes how an existing
|
|
170
202
|
projection is registered.
|
|
@@ -187,7 +219,9 @@ spans streams.
|
|
|
187
219
|
- Query methods are `static` and declare `ISubject<...>` rather than a concrete
|
|
188
220
|
subject type.
|
|
189
221
|
- A direct `GetInstanceById` result is checked for absence before use.
|
|
190
|
-
-
|
|
191
|
-
|
|
222
|
+
- Passive access goes through Chronicle, not a sink collection; consistency,
|
|
223
|
+
access frequency, and non-materialization requirements justify the choice.
|
|
224
|
+
- Summary payloads and embedded children are bounded; growing histories have
|
|
225
|
+
a separate paged surface, and no secret was materialized to fix a query.
|
|
192
226
|
- The project builds clean and the read-model specifications pass against the
|
|
193
227
|
verified package versions.
|
|
@@ -118,6 +118,43 @@ Two details that catch people out:
|
|
|
118
118
|
Also available in the same place: `FindById<T, TId>` and
|
|
119
119
|
`FindByIdAsync<T, TId>`.
|
|
120
120
|
|
|
121
|
+
## Cost and composition
|
|
122
|
+
|
|
123
|
+
The behavior below was checked against **Arc v22.49.0**
|
|
124
|
+
([collection observation](https://github.com/Cratis/Arc/blob/v22.49.0/Documentation/backend/csharp/mongodb/observing-collections.md),
|
|
125
|
+
[implementation](https://github.com/Cratis/Arc/blob/v22.49.0/Source/DotNET/MongoDB/MongoCollectionExtensions.cs)).
|
|
126
|
+
Do not generalize it to every provider or custom observable.
|
|
127
|
+
|
|
128
|
+
- Per-collection `Observe` reads an initial filtered set, retains it in memory,
|
|
129
|
+
and applies change-stream updates. It does **not** re-query the entire
|
|
130
|
+
collection for every event. Updates/replacements perform a keyed membership
|
|
131
|
+
lookup; paged removals can query to refill the page.
|
|
132
|
+
- Collection emissions still construct a snapshot of the retained set. In-memory
|
|
133
|
+
joins, sorting, mapping, and serialization downstream can be expensive even
|
|
134
|
+
without a full database re-query. Measure retained rows, payload size, change
|
|
135
|
+
frequency, and concurrent subscriptions separately from database calls.
|
|
136
|
+
- A custom change callback that explicitly runs another query pays that query's
|
|
137
|
+
cost on each invocation. Distinguish this recompute path from ordinary retained
|
|
138
|
+
observation; inspect the actual callback before reporting a full scan.
|
|
139
|
+
- Filter by the requested entity, parent, tenant, or relevant state at the
|
|
140
|
+
observation source; filtering after an unbounded `Observe()` retains too much.
|
|
141
|
+
This narrows initial state and emissions, not necessarily every watched change:
|
|
142
|
+
updates/deletes must still detect documents leaving the set. Test removal and
|
|
143
|
+
filter-exit behavior as well as additions.
|
|
144
|
+
- For counts, do not retain rich documents and entire histories just to count
|
|
145
|
+
them. Consider a slim projected counter or an explicit aggregate query with an
|
|
146
|
+
appropriate refresh policy; preserve the count's actual semantics.
|
|
147
|
+
- Prefer a purpose-built projected summary for frequently recomputed joins.
|
|
148
|
+
Query-time composition is supported, not forbidden. Bound each input and define
|
|
149
|
+
count, paging, missing-related-data, and subscription-disposal behavior.
|
|
150
|
+
In v22.49.0 auxiliary observations can use `ignoreQueryContext: true` so client
|
|
151
|
+
paging/counts belong to the primary source. That option reads **all matching
|
|
152
|
+
auxiliary rows**; it is not a performance limit. Confirm version support before
|
|
153
|
+
using it, and keep an explicit narrow filter.
|
|
154
|
+
|
|
155
|
+
Use the **cratis-arc-query-paging** skill for source-side paging. Paging an
|
|
156
|
+
already materialized list does not bound database reads or retained memory.
|
|
157
|
+
|
|
121
158
|
## Custom routes
|
|
122
159
|
|
|
123
160
|
```csharp
|
|
@@ -59,6 +59,22 @@ public class <ReadModelName>Reducer : IReducerFor<<ReadModelName>>
|
|
|
59
59
|
`IReducerFor<TReadModel>` is a marker with no members, constrained to
|
|
60
60
|
`where TReadModel : class`.
|
|
61
61
|
|
|
62
|
+
## Preserve admission and ordering when converting
|
|
63
|
+
|
|
64
|
+
A handler that ends with `current with { Status = ... }` is not necessarily a
|
|
65
|
+
plain setter. First inspect guards: does it require a creation event, ignore an
|
|
66
|
+
older attempt, preserve a terminal state, or compare prior values? Replacing it
|
|
67
|
+
with unconditional `[SetValue<T>]` can create state too early or resurrect a
|
|
68
|
+
finished entity. Keep the reducer when the projection APIs cannot express those
|
|
69
|
+
semantics; the admission test is about behavior, not handler length.
|
|
70
|
+
|
|
71
|
+
Evaluate variants for mutually exclusive lifecycle shapes (see the projection
|
|
72
|
+
skill). Their non-entering events are update-only, but that does not replace
|
|
73
|
+
arbitrary guards on attempt identity, ordering, or prior state. Before conversion,
|
|
74
|
+
keep specifications for update-before-create, late events after completion,
|
|
75
|
+
repeated events, and each guarded branch, as applicable. Assert the same outcomes
|
|
76
|
+
with the replacement, not only the happy-path final status.
|
|
77
|
+
|
|
62
78
|
## Method signatures — exactly what is accepted
|
|
63
79
|
|
|
64
80
|
Dispatch is by the **first parameter's type**, never by the method name. Name the
|
|
@@ -68,7 +68,20 @@ behavior this file does not already state.
|
|
|
68
68
|
- No N+1: one query returns what the caller needs.
|
|
69
69
|
- A count is a count. Hydrating the collection to measure its length is the
|
|
70
70
|
same finding as an unpaged list, wearing different clothes.
|
|
71
|
-
-
|
|
71
|
+
- Prefer slim projection-backed summaries over repeatedly assembling broad
|
|
72
|
+
collections. Query composition is supported; one collection per query is not
|
|
73
|
+
a framework requirement. Bound each input and measure recomputation.
|
|
74
|
+
- Embed bounded related state, not growing histories; page timelines separately.
|
|
75
|
+
Evaluate variants for divergent lifecycle shapes, not every status field.
|
|
76
|
+
- Preserve reducer admission and ordering guards when proposing a projection
|
|
77
|
+
conversion; an unconditional setter may resurrect or prematurely create state.
|
|
78
|
+
- Count passive models as inventory, not a smell. Assess history length and read
|
|
79
|
+
frequency against consistency/security needs. `IMongoCollection<T>` cannot
|
|
80
|
+
read passive computed state; never materialize secrets to make that query work.
|
|
81
|
+
- Distinguish retained `Observe` state and in-memory emissions from explicit
|
|
82
|
+
recompute queries. Narrow source filters and inspect page-refill/membership
|
|
83
|
+
lookups; do not claim every change re-queries the entire collection. See the
|
|
84
|
+
**cratis-chronicle-read-model** query reference for versioned behavior.
|
|
72
85
|
|
|
73
86
|
## Step 3 — Commands and queries
|
|
74
87
|
|
|
@@ -26,6 +26,10 @@ source is the single flow model.
|
|
|
26
26
|
| Package | Version | Purpose |
|
|
27
27
|
| --- | --- | --- |
|
|
28
28
|
| `Cratis.Screenplay` | `4.31.0` | CDL parser, reaction and trigger parsers, diagnostics, semantic binder |
|
|
29
|
+
| `Cratis.Screenplay` | main `fd18129` | Command-only inline event boundary |
|
|
30
|
+
|
|
31
|
+
The update follows `commands.md`, `events.md` and `diagnostics.md` at that main
|
|
32
|
+
commit (after v4.52.0); no reaction or capture example changes in this update.
|
|
29
33
|
|
|
30
34
|
Checked against the Screenplay repository at tag `v4.31.0` (commit `355dffb`):
|
|
31
35
|
`Documentation/screenplay/{captures,captures/grammar,reactions,triggers,interactions,file-references,grammar,diagnostics}.md`
|
|
@@ -188,6 +192,10 @@ reaction is an error; combine with `and`/`or` instead.
|
|
|
188
192
|
|
|
189
193
|
### Effects — `produces` vs `invokes`
|
|
190
194
|
|
|
195
|
+
Inline `produces event <Name>` is command-only (`PLAY0474` in a reaction).
|
|
196
|
+
Declare reaction-produced events separately and use plain `produces <Name>`.
|
|
197
|
+
Do not extend the inline command destination default or its repairs to reactions.
|
|
198
|
+
|
|
191
199
|
Excerpt, inside an `Automation` slice:
|
|
192
200
|
|
|
193
201
|
```screenplay
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
"input": "Translate external data into events and declare a reaction.",
|
|
4
4
|
"fixtures": [],
|
|
5
5
|
"assertions": [
|
|
6
|
+
{ "kind": "skill-contains", "value": "main `fd18129`" },
|
|
7
|
+
{ "kind": "skill-contains", "value": "command-only (`PLAY0474` in a reaction)" },
|
|
8
|
+
{ "kind": "skill-contains", "value": "Do not extend the inline command destination default" },
|
|
6
9
|
{ "kind": "skill-contains", "value": ".cratis/screenplay/" },
|
|
7
10
|
{ "kind": "skill-contains", "value": "`cratis ai install` manages `.cratis/ai/`, not `.cratis/screenplay/`" },
|
|
8
11
|
{ "kind": "skill-contains", "value": "cannot be mixed in one clause" },
|
|
@@ -25,12 +25,17 @@ source is the single flow model.
|
|
|
25
25
|
|
|
26
26
|
| Package | Version | Purpose |
|
|
27
27
|
| --- | --- | --- |
|
|
28
|
-
| `Cratis.Screenplay` | `4.31.0` |
|
|
28
|
+
| `Cratis.Screenplay` | `4.31.0` | Original examples and executable boundaries |
|
|
29
|
+
| `Cratis.Screenplay` | main `fd18129` | Inline events, repairs and canonical `optional`; changed examples compiled |
|
|
30
|
+
|
|
31
|
+
The update follows `commands.md`, `events.md`, `types.md`, `diagnostics.md`,
|
|
32
|
+
`mcp/authoring-tools.md` and decision 0023 at that main commit (after v4.52.0).
|
|
33
|
+
Compilation checks syntax and model consistency, not reference execution.
|
|
29
34
|
|
|
30
35
|
Checked against the Screenplay repository at tag `v4.31.0` (commit `355dffb`):
|
|
31
36
|
`Documentation/screenplay/{commands,constraints,policies,context,concepts,diagnostics}.md`
|
|
32
|
-
and decisions 0001 and 0003
|
|
33
|
-
|
|
37
|
+
and decisions 0001 and 0003 established the original baseline. Changed examples
|
|
38
|
+
use the newer main commit above; do not attribute their verification to the old tag.
|
|
34
39
|
|
|
35
40
|
"Parses" and "runs" are different claims. The executable profile, and what
|
|
36
41
|
each construct binds to, is in the `cratis-screenplay-model-authoring` language
|
|
@@ -47,17 +52,21 @@ command RegisterInvoice
|
|
|
47
52
|
invoiceId InvoiceId identifier
|
|
48
53
|
invoiceNumber InvoiceNumber
|
|
49
54
|
lines InvoiceLine[]
|
|
50
|
-
note String
|
|
55
|
+
note String optional
|
|
51
56
|
authorize CanManageInvoice
|
|
52
57
|
validate
|
|
53
58
|
invoiceNumber not empty message "Invoice number is required"
|
|
54
59
|
invoiceNumber matches "^INV-[0-9]{6}$" severity warning message "Must look like INV-000000"
|
|
55
60
|
produces InvoiceRegistered
|
|
56
|
-
|
|
61
|
+
for invoiceId
|
|
57
62
|
registeredAt = $context.occurred
|
|
58
63
|
```
|
|
59
64
|
|
|
60
|
-
Type modifiers: `<Type>[]` for a collection, `<Type
|
|
65
|
+
Type modifiers: `<Type>[]` for a collection, `<Type> optional` for absence.
|
|
66
|
+
`Type[] optional` makes the whole collection optional, not its items. Legacy
|
|
67
|
+
`Type?` still parses with information `PLAY0479`; use its repair or editor quick
|
|
68
|
+
fix to migrate. `--warnaserror` does not reject information diagnostics.
|
|
69
|
+
`reads X optional` is not supported yet.
|
|
61
70
|
|
|
62
71
|
⚠️ **The parser enforces no clause order.** The house order is description,
|
|
63
72
|
properties, `reads`, `authorize`, `validate`, `produces`/`handler`, `concurrency`.
|
|
@@ -189,6 +198,68 @@ A continuation line extends the clause.
|
|
|
189
198
|
reaches a policy implemented in code, the reference runner reports the outcome
|
|
190
199
|
unsupported; it never guesses allow or deny.
|
|
191
200
|
|
|
201
|
+
## Inline events and destinations
|
|
202
|
+
|
|
203
|
+
Use `produces event` when the command introduces a new, generation-1 event.
|
|
204
|
+
This complete example declares its payload and mappings together:
|
|
205
|
+
|
|
206
|
+
````screenplay
|
|
207
|
+
concept ProjectId : Uuid
|
|
208
|
+
concept ProjectName : String
|
|
209
|
+
module Projects
|
|
210
|
+
feature Naming
|
|
211
|
+
slice StateChange RenameProject
|
|
212
|
+
command RenameProject
|
|
213
|
+
projectId ProjectId identifier
|
|
214
|
+
name ProjectName
|
|
215
|
+
produces event ProjectRenamed
|
|
216
|
+
description "A project received a new name"
|
|
217
|
+
documentation
|
|
218
|
+
```markdown
|
|
219
|
+
Existing links retain the project's identity.
|
|
220
|
+
```
|
|
221
|
+
tag audit
|
|
222
|
+
name ProjectName = name
|
|
223
|
+
````
|
|
224
|
+
|
|
225
|
+
The omitted `for` means the command's required scalar identifier **only for
|
|
226
|
+
inline productions**, when every production targets that same source. Once a
|
|
227
|
+
production targets another source, every production must state `for`. Mixing
|
|
228
|
+
omitted inline and plain destinations also fails (`PLAY0470`); there is no
|
|
229
|
+
verified MCP repair for that diagnostic. Explicit syntax does not make cross-source
|
|
230
|
+
execution supported.
|
|
231
|
+
|
|
232
|
+
Plain `produces X` references a declared event; omitting `for` does not infer
|
|
233
|
+
the command's identifier. In ESM v2+, it inherits a sibling production's resolved
|
|
234
|
+
destination through the command destination default. An allocated identity is
|
|
235
|
+
used only when no production resolves a destination. State `for` explicitly on
|
|
236
|
+
every production targeting the identifier. `PLAY0478` offers advice and a
|
|
237
|
+
reviewed repair, not permission to silently retarget an append. Supply an
|
|
238
|
+
allocated identity to the executable model when allocation is intentional.
|
|
239
|
+
|
|
240
|
+
Inline declarations are slice-owned contracts, usable by other consumers.
|
|
241
|
+
Their `tag` lines are event-type tags; plain production tags apply at that one
|
|
242
|
+
append site. Both inline and standalone events accept a quoted description or
|
|
243
|
+
text/Markdown description fence, and one nonempty fenced Markdown `documentation`.
|
|
244
|
+
New events omit `id`. Only a rename preserving an old stored name needs
|
|
245
|
+
`id "<old name>"`; it does not replace the catalog's `EventContractId`.
|
|
246
|
+
|
|
247
|
+
| Diagnostic | What to change |
|
|
248
|
+
| --- | --- |
|
|
249
|
+
| `PLAY0469` | Do not copy the same-source command identifier into payload. Inline copies warn; plain copies with explicit `for` are information. Review persistence before changing a contract. |
|
|
250
|
+
| `PLAY0471` / `PLAY0472` | Remove a redundant name-equal `id`; an id must be one nonempty quoted value. |
|
|
251
|
+
| `PLAY0473` / `PLAY0474` | Avoid declaration/import collisions; inline events belong only in commands, never reactions. |
|
|
252
|
+
| `PLAY0475` | Extract the inline event before adding generations. |
|
|
253
|
+
| `PLAY0476` | Inline `origin` and unescaped system-assigned production metadata are forbidden. |
|
|
254
|
+
| `PLAY0477` | Use one nonempty Markdown documentation fence. |
|
|
255
|
+
|
|
256
|
+
MCP can declare a missing produced event (`PLAY0166`), add explicit routing
|
|
257
|
+
(`PLAY0478`), remove a redundant pin (`PLAY0471`), or remove an inline identifier
|
|
258
|
+
copy (`PLAY0469`). The last **changes the event contract**, retires a property,
|
|
259
|
+
refuses affected consumers/opaque implementations and is not fix-all. It does
|
|
260
|
+
not establish that stored data is safe to migrate. Use
|
|
261
|
+
`cratis-screenplay-model-authoring` for discovery, preview, extraction and rename.
|
|
262
|
+
|
|
192
263
|
## `produces`
|
|
193
264
|
|
|
194
265
|
- **Mapping sources** that bind to the executable model: a command property
|
|
@@ -216,7 +287,7 @@ A continuation line extends the clause.
|
|
|
216
287
|
```screenplay
|
|
217
288
|
produces when isProForma == true
|
|
218
289
|
ProFormaInvoiceIssued
|
|
219
|
-
|
|
290
|
+
for invoiceId
|
|
220
291
|
```
|
|
221
292
|
|
|
222
293
|
## `concurrency`
|
|
@@ -234,7 +305,12 @@ the executable model does not bind it (`PLAY0271`), and it does not protect a
|
|
|
234
305
|
| `streamId <Name>` | an event stream id |
|
|
235
306
|
| `events <A>, <B>` | the listed event types |
|
|
236
307
|
|
|
237
|
-
An empty block or an unknown dimension is an error.
|
|
308
|
+
An empty block or an unknown dimension is an error. Omitting `concurrency` does
|
|
309
|
+
not mean unchecked appends: Chronicle's default optimistic concurrency applies
|
|
310
|
+
to the routed scope. This does not make command `reads` protected.
|
|
311
|
+
|
|
312
|
+
Decision 0023's generated values, `returns`, operations, named event sources and
|
|
313
|
+
streams, `derive` and `provide` are planned, not available yet.
|
|
238
314
|
|
|
239
315
|
## `constraint` — uniqueness at append time
|
|
240
316
|
|
|
@@ -364,6 +440,7 @@ Four contexts, and **what each omits is load-bearing** — read
|
|
|
364
440
|
## Verify
|
|
365
441
|
|
|
366
442
|
- [ ] `screenplay <model> --warnaserror` reports zero errors and zero warnings.
|
|
443
|
+
- [ ] No unintended `PLAY0478` or `PLAY0479` information remains.
|
|
367
444
|
- [ ] At most one command property carries `identifier`, and no event property does.
|
|
368
445
|
- [ ] Format rules live on the `concept`; state-dependent rules are specifications.
|
|
369
446
|
- [ ] Every `authorize` combining policies writes `and`/`or` explicitly.
|
|
@@ -78,6 +78,16 @@ roles, claims and causation report `PLAY0268`.
|
|
|
78
78
|
|
|
79
79
|
An unknown `$context.` path is reported, so a typo does not silently become null.
|
|
80
80
|
|
|
81
|
+
## Production metadata is not a context expression
|
|
82
|
+
|
|
83
|
+
`namespace`, `sequence`, `correlation`, `causation`, `causedBy` and `occurred`
|
|
84
|
+
are reserved, system-assigned directives in production bodies (`PLAY0476`).
|
|
85
|
+
They are not routing knobs. Escape a genuine payload property with `@`, as in
|
|
86
|
+
`@sequence String = name` in an inline event. `occurred at` is not available yet.
|
|
87
|
+
Reading `$context.occurred` into a payload mapping does not assign the event's
|
|
88
|
+
occurrence metadata; use `given clock`, never `given time`, to state scenario time
|
|
89
|
+
(the specification skill distinguishes parsing from execution).
|
|
90
|
+
|
|
81
91
|
## The other expression roots
|
|
82
92
|
|
|
83
93
|
| Root | Where | Yields |
|
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
"input": "Declare a Screenplay command with validation, authorization, a uniqueness constraint and a state-dependent rule.",
|
|
4
4
|
"fixtures": [],
|
|
5
5
|
"assertions": [
|
|
6
|
+
{ "kind": "skill-contains", "value": "main `fd18129`" },
|
|
7
|
+
{ "kind": "skill-contains", "value": "produces event ProjectRenamed" },
|
|
8
|
+
{ "kind": "skill-contains", "value": "name ProjectName = name" },
|
|
9
|
+
{ "kind": "skill-contains", "value": "In ESM v2+, it inherits a sibling production's resolved\ndestination through the command destination default" },
|
|
10
|
+
{ "kind": "skill-contains", "value": "An allocated identity is\nused only when no production resolves a destination" },
|
|
11
|
+
{ "kind": "skill-contains", "value": "State `for` explicitly on\nevery production targeting the identifier" },
|
|
12
|
+
{ "kind": "skill-contains", "value": "PLAY0478" },
|
|
13
|
+
{ "kind": "skill-contains", "value": "PLAY0479" },
|
|
14
|
+
{ "kind": "skill-contains", "value": "changes the event contract" },
|
|
15
|
+
{ "kind": "skill-contains", "value": "`reads X optional` is not supported yet" },
|
|
6
16
|
{
|
|
7
17
|
"kind": "skill-contains",
|
|
8
18
|
"value": ".cratis/screenplay/"
|
|
@@ -34,12 +34,16 @@ source is the single flow model.
|
|
|
34
34
|
| --- | --- | --- |
|
|
35
35
|
| `Cratis.Screenplay` | `4.31.0` | Compiler: parser, validator, diagnostics, folder merge, semantic binder |
|
|
36
36
|
| `Cratis.Screenplay.Tool` | `4.31.0` | The `screenplay` dotnet tool |
|
|
37
|
+
| `Cratis.Screenplay` | main `fd18129` | Inline contracts and event context; changed nine-step examples compiled |
|
|
38
|
+
|
|
39
|
+
The update follows `commands.md`, `events.md` and decision 0023 at that main
|
|
40
|
+
commit (after v4.52.0); compilation does not establish reference execution.
|
|
37
41
|
|
|
38
42
|
Checked against the Screenplay repository at tag `v4.31.0` (commit `355dffb`):
|
|
39
43
|
`Documentation/screenplay/{slices,commands,folders,printing,interactions,specifications}.md`,
|
|
40
|
-
`projections/keys.md`, and decisions 0001 to 0014
|
|
41
|
-
[nine-
|
|
42
|
-
|
|
44
|
+
`projections/keys.md`, and decisions 0001 to 0014 established the original
|
|
45
|
+
baseline. Changed [nine-step examples](references/nine-steps.md) use the newer
|
|
46
|
+
main commit above; do not attribute their verification to the old tag.
|
|
43
47
|
|
|
44
48
|
> **Method lineage.** The two-phase process, the nine steps, the four patterns and
|
|
45
49
|
> the GWT discipline follow **Event Modeling** (Adam Dymitruk; Martin Dilger,
|
|
@@ -132,6 +136,13 @@ compile or will not be safe. Both are deliberate.
|
|
|
132
136
|
- **The event-source identity is never an event property.** The command binds it
|
|
133
137
|
with `identifier` on at most one property; marking an *event* property
|
|
134
138
|
`identifier` is an error: *an event never carries its event source id*.
|
|
139
|
+
- **Inline events remain slice-owned contracts.** A command may introduce one
|
|
140
|
+
with `produces event <Name>` and typed mappings; other slices still consume it
|
|
141
|
+
by name. Extracting it changes placement, not its contract or projection meaning.
|
|
142
|
+
- **Storage identity is not payload identity.** `for` selects the event source;
|
|
143
|
+
`id "<old name>"` preserves an event type's old persisted name on rename. New
|
|
144
|
+
events omit the pin, and the pin does not replace catalog identity. Do not copy
|
|
145
|
+
the same-source identifier into payload merely to project it; use `$eventSourceId`.
|
|
135
146
|
- **Domain facts, not runtime context.** Test: would this field have the same value
|
|
136
147
|
if the event were replayed on a different machine? If not, it does not belong.
|
|
137
148
|
|
|
@@ -288,10 +299,12 @@ read a clean `screenplay` run as evidence a construct works downstream.
|
|
|
288
299
|
|
|
289
300
|
Decision 0006 shipped in Screenplay 4.31.0: a reaction trigger can declare the
|
|
290
301
|
views it decides from with `reads` (see `cratis-screenplay-captures-and-reactions`),
|
|
291
|
-
but nothing enforces them yet.
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
302
|
+
but nothing enforces them yet. Event generations and typed repairs now ship;
|
|
303
|
+
generations do not supply deployed migrations. Do not treat every accepted
|
|
304
|
+
decision as implemented: affected-instance declarations, per-event subjects,
|
|
305
|
+
external origin and richer query delivery remain unavailable. Decision 0023's
|
|
306
|
+
responses, operations, streams and derived/provided values are planned, not
|
|
307
|
+
available yet; do not turn their examples into usable syntax.
|
|
295
308
|
|
|
296
309
|
## Route near misses
|
|
297
310
|
|