@cratis/pi 7.14.1 → 7.14.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.
Files changed (197) hide show
  1. package/package/corpus/agents/security-reviewer.md +2 -1
  2. package/package/corpus/rules/concepts.md +13 -7
  3. package/package/corpus/rules/glossary.md +2 -1
  4. package/package/corpus/rules/vertical-slices.md +5 -4
  5. package/package/corpus/skills/cratis-application-slice-conformance/SKILL.md +11 -2
  6. package/package/corpus/skills/cratis-application-slice-conformance/references/build-prompts.md +8 -0
  7. package/package/corpus/skills/cratis-application-slice-conformance/references/checklists.md +10 -6
  8. package/package/corpus/skills/cratis-application-slice-specifications/SKILL.md +1 -1
  9. package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/SKILL.md +11 -7
  10. package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/references/authentication.md +12 -2
  11. package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/references/authorization.md +16 -1
  12. package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/references/frontend.md +7 -0
  13. package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/references/observable-emission-guards.md +9 -0
  14. package/package/corpus/skills/cratis-arc-command/SKILL.md +24 -16
  15. package/package/corpus/skills/cratis-arc-command/references/command-result.md +7 -0
  16. package/package/corpus/skills/cratis-arc-command/references/handler-shapes.md +10 -3
  17. package/package/corpus/skills/cratis-arc-command-execution/SKILL.md +1 -1
  18. package/package/corpus/skills/cratis-arc-command-operation/SKILL.md +5 -1
  19. package/package/corpus/skills/cratis-arc-command-operation/references/execution-and-recovery.md +12 -0
  20. package/package/corpus/skills/cratis-arc-command-operation/references/testing.md +10 -3
  21. package/package/corpus/skills/cratis-arc-command-typescript/SKILL.md +20 -116
  22. package/package/corpus/skills/cratis-arc-command-typescript/references/chronicle-events.md +11 -8
  23. package/package/corpus/skills/cratis-arc-command-typescript/references/command-specifications.md +63 -0
  24. package/package/corpus/skills/cratis-arc-command-typescript/references/hosting-and-storage.md +10 -0
  25. package/package/corpus/skills/cratis-arc-command-typescript/references/proxy-generation.md +38 -0
  26. package/package/corpus/skills/cratis-arc-command-typescript/references/slice-layout.md +19 -0
  27. package/package/corpus/skills/cratis-arc-command-typescript/verification.json +1 -1
  28. package/package/corpus/skills/cratis-arc-command-validation/SKILL.md +1 -1
  29. package/package/corpus/skills/cratis-arc-query-paging/SKILL.md +11 -10
  30. package/package/corpus/skills/cratis-arc-react-page/SKILL.md +30 -19
  31. package/package/corpus/skills/cratis-arc-react-page/references/data-page.md +11 -0
  32. package/package/corpus/skills/cratis-arc-react-page/references/data-tables.md +10 -0
  33. package/package/corpus/skills/cratis-arc-react-page/references/dialogs.md +12 -10
  34. package/package/corpus/skills/cratis-arc-react-page/references/from-screenplay.md +10 -0
  35. package/package/corpus/skills/cratis-arc-react-page/references/mvvm.md +11 -0
  36. package/package/corpus/skills/cratis-arc-react-page/references/queries-and-commands.md +7 -0
  37. package/package/corpus/skills/cratis-chronicle-client-dotnet/SKILL.md +58 -122
  38. package/package/corpus/skills/cratis-chronicle-client-dotnet/references/compatibility-check.md +26 -0
  39. package/package/corpus/skills/cratis-chronicle-client-dotnet/references/discovery.md +22 -0
  40. package/package/corpus/skills/cratis-chronicle-client-dotnet/references/hosting.md +31 -0
  41. package/package/corpus/skills/cratis-chronicle-client-elixir/SKILL.md +52 -131
  42. package/package/corpus/skills/cratis-chronicle-client-elixir/references/append-api.md +19 -0
  43. package/package/corpus/skills/cratis-chronicle-client-elixir/references/variants.md +73 -0
  44. package/package/corpus/skills/cratis-chronicle-client-kotlin/SKILL.md +29 -232
  45. package/package/corpus/skills/cratis-chronicle-client-kotlin/references/connection-lifecycle.md +20 -0
  46. package/package/corpus/skills/cratis-chronicle-client-kotlin/references/discovery-and-registration.md +44 -0
  47. package/package/corpus/skills/cratis-chronicle-client-kotlin/references/java-api.md +33 -0
  48. package/package/corpus/skills/cratis-chronicle-client-kotlin/references/spring-boot.md +54 -0
  49. package/package/corpus/skills/cratis-chronicle-client-kotlin/references/variants.md +77 -0
  50. package/package/corpus/skills/cratis-chronicle-client-typescript/SKILL.md +26 -102
  51. package/package/corpus/skills/cratis-chronicle-client-typescript/references/read-models-and-projections.md +23 -0
  52. package/package/corpus/skills/cratis-chronicle-client-typescript/references/variants.md +63 -0
  53. package/package/corpus/skills/cratis-chronicle-compliance/SKILL.md +11 -2
  54. package/package/corpus/skills/cratis-chronicle-event-modeling/SKILL.md +2 -2
  55. package/package/corpus/skills/cratis-chronicle-event-type-migration/SKILL.md +13 -13
  56. package/package/corpus/skills/cratis-chronicle-mcp-inspection/SKILL.md +1 -1
  57. package/package/corpus/skills/cratis-chronicle-projection/SKILL.md +13 -4
  58. package/package/corpus/skills/cratis-chronicle-projection/references/fluent-builder.md +10 -0
  59. package/package/corpus/skills/cratis-chronicle-projection/references/model-bound-attributes.md +14 -6
  60. package/package/corpus/skills/cratis-chronicle-projection/references/variants.md +9 -0
  61. package/package/corpus/skills/cratis-chronicle-reactor/SKILL.md +7 -49
  62. package/package/corpus/skills/cratis-chronicle-reactor/references/domain-failures.md +19 -0
  63. package/package/corpus/skills/cratis-chronicle-reactor/references/specifications.md +33 -0
  64. package/package/corpus/skills/cratis-chronicle-read-model/SKILL.md +2 -2
  65. package/package/corpus/skills/cratis-chronicle-read-model/references/queries.md +11 -0
  66. package/package/corpus/skills/cratis-chronicle-read-model-specifications/SKILL.md +1 -0
  67. package/package/corpus/skills/cratis-chronicle-reducer/SKILL.md +1 -1
  68. package/package/corpus/skills/cratis-chronicle-web-workbench/SKILL.md +24 -24
  69. package/package/corpus/skills/cratis-content-length/SKILL.md +1 -1
  70. package/package/corpus/skills/cratis-content-length/references/length-evidence.md +12 -0
  71. package/package/corpus/skills/cratis-developer-marketing/SKILL.md +19 -19
  72. package/package/corpus/skills/cratis-developer-marketing/references/measurement.md +10 -0
  73. package/package/corpus/skills/cratis-developer-marketing/references/playbook-evidence.md +10 -0
  74. package/package/corpus/skills/cratis-engineering-csharp-conventions/SKILL.md +5 -0
  75. package/package/corpus/skills/cratis-engineering-csharp-conventions/references/code-style.md +15 -0
  76. package/package/corpus/skills/cratis-engineering-csharp-conventions/references/exceptions-logging-and-di.md +9 -4
  77. package/package/corpus/skills/cratis-engineering-decision-record/SKILL.md +1 -2
  78. package/package/corpus/skills/cratis-engineering-decision-record/references/record-format.md +8 -0
  79. package/package/corpus/skills/cratis-engineering-docs-authoring/SKILL.md +1 -2
  80. package/package/corpus/skills/cratis-engineering-effect-boundaries/references/failure-archetypes.md +10 -0
  81. package/package/corpus/skills/cratis-fundamentals-concept/SKILL.md +4 -4
  82. package/package/corpus/skills/cratis-fundamentals-type-discovery/SKILL.md +1 -1
  83. package/package/corpus/skills/cratis-lens-browser-extension/SKILL.md +18 -18
  84. package/package/corpus/skills/cratis-performance-review/SKILL.md +1 -1
  85. package/package/corpus/skills/cratis-release-notes/SKILL.md +1 -0
  86. package/package/corpus/skills/cratis-screenplay-automations-and-translations/SKILL.md +29 -4
  87. package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/automation-patterns.md +16 -4
  88. package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/effects-and-idempotency.md +4 -15
  89. package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/todo-list-example.md +6 -2
  90. package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/translation-patterns.md +1 -6
  91. package/package/corpus/skills/cratis-screenplay-captures-and-reactions/SKILL.md +45 -245
  92. package/package/corpus/skills/cratis-screenplay-captures-and-reactions/references/capture-map-and-example.md +42 -0
  93. package/package/corpus/skills/cratis-screenplay-captures-and-reactions/references/complete-examples.md +155 -0
  94. package/package/corpus/skills/cratis-screenplay-captures-and-reactions/references/specifying-triggers-and-clock.md +27 -0
  95. package/package/corpus/skills/cratis-screenplay-captures-and-reactions/references/trigger-reads-example.md +21 -0
  96. package/package/corpus/skills/cratis-screenplay-command-surface/SKILL.md +70 -221
  97. package/package/corpus/skills/cratis-screenplay-command-surface/references/context.md +10 -0
  98. package/package/corpus/skills/cratis-screenplay-command-surface/references/generated-values-and-responses.md +51 -0
  99. package/package/corpus/skills/cratis-screenplay-command-surface/references/inline-events.md +62 -0
  100. package/package/corpus/skills/cratis-screenplay-command-surface/references/policy-persona-seed.md +46 -0
  101. package/package/corpus/skills/cratis-screenplay-command-surface/references/validate-rules.md +36 -0
  102. package/package/corpus/skills/cratis-screenplay-command-surface/verification.json +11 -11
  103. package/package/corpus/skills/cratis-screenplay-discovery/SKILL.md +10 -3
  104. package/package/corpus/skills/cratis-screenplay-discovery/references/facilitation.md +1 -6
  105. package/package/corpus/skills/cratis-screenplay-discovery/references/human-workshop.md +13 -0
  106. package/package/corpus/skills/cratis-screenplay-discovery/references/personas-and-causes.md +8 -0
  107. package/package/corpus/skills/cratis-screenplay-discovery/references/plotting-and-handoff.md +11 -0
  108. package/package/corpus/skills/cratis-screenplay-discovery/references/storming-loop.md +7 -0
  109. package/package/corpus/skills/cratis-screenplay-event-modeling/SKILL.md +75 -198
  110. package/package/corpus/skills/cratis-screenplay-event-modeling/references/file-layout.md +89 -0
  111. package/package/corpus/skills/cratis-screenplay-event-modeling/references/naming-primitives.md +26 -0
  112. package/package/corpus/skills/cratis-screenplay-event-modeling/references/nine-steps.md +14 -1
  113. package/package/corpus/skills/cratis-screenplay-event-modeling/references/parsed-not-runnable.md +8 -0
  114. package/package/corpus/skills/cratis-screenplay-event-modeling/references/provenance.md +10 -0
  115. package/package/corpus/skills/cratis-screenplay-event-modeling/references/slice-type-rules.md +12 -0
  116. package/package/corpus/skills/cratis-screenplay-event-modeling/verification.json +12 -6
  117. package/package/corpus/skills/cratis-screenplay-legacy-extraction/SKILL.md +5 -6
  118. package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/candidate-inventory.md +11 -0
  119. package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/prologue-safety.md +8 -0
  120. package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/side-car-migration.md +11 -0
  121. package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/ui-observation.md +1 -1
  122. package/package/corpus/skills/cratis-screenplay-model-authoring/SKILL.md +33 -10
  123. package/package/corpus/skills/cratis-screenplay-model-authoring/references/language-reference.md +8 -0
  124. package/package/corpus/skills/cratis-screenplay-model-authoring/references/mcp-loop.md +13 -17
  125. package/package/corpus/skills/cratis-screenplay-model-authoring/references/mcp-tools.md +11 -0
  126. package/package/corpus/skills/cratis-screenplay-model-review/SKILL.md +9 -9
  127. package/package/corpus/skills/cratis-screenplay-model-review/references/business-questions.md +9 -0
  128. package/package/corpus/skills/cratis-screenplay-model-review/references/checklist.md +16 -1
  129. package/package/corpus/skills/cratis-screenplay-model-review/references/report-template.md +9 -0
  130. package/package/corpus/skills/cratis-screenplay-model-review/references/worked-example.md +9 -0
  131. package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/SKILL.md +17 -8
  132. package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/handoff-template.md +8 -0
  133. package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/identity-and-edits.md +1 -6
  134. package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/phases.md +19 -0
  135. package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/safety.md +1 -1
  136. package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/verdicts-and-modes.md +11 -1
  137. package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/vocabulary-map.md +2 -2
  138. package/package/corpus/skills/cratis-screenplay-projections/SKILL.md +3 -4
  139. package/package/corpus/skills/cratis-screenplay-projections/references/pdl-grammar.md +8 -0
  140. package/package/corpus/skills/cratis-screenplay-read-surface/SKILL.md +2 -2
  141. package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/SKILL.md +3 -3
  142. package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/references/gap-fill-handoff.md +1 -1
  143. package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/references/renderability-gate.md +1 -1
  144. package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/references/worked-example.md +8 -0
  145. package/package/corpus/skills/cratis-screenplay-scenario-coverage/SKILL.md +10 -10
  146. package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/coverage-matrix.md +8 -0
  147. package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/invoicing-dues-example.md +4 -0
  148. package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/scenario-catalogue.md +17 -0
  149. package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/scenario-examples.md +10 -0
  150. package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/scenario-workshop.md +11 -0
  151. package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/view-and-story-specs.md +12 -0
  152. package/package/corpus/skills/cratis-screenplay-slice-design/SKILL.md +2 -2
  153. package/package/corpus/skills/cratis-screenplay-slice-design/references/command-inventory.md +7 -0
  154. package/package/corpus/skills/cratis-screenplay-slice-design/references/field-lineage.md +8 -0
  155. package/package/corpus/skills/cratis-screenplay-slice-design/references/read-model-design.md +16 -0
  156. package/package/corpus/skills/cratis-screenplay-slice-design/references/slicing.md +10 -0
  157. package/package/corpus/skills/cratis-screenplay-specifications/SKILL.md +52 -360
  158. package/package/corpus/skills/cratis-screenplay-specifications/references/actions-beyond-commands.md +34 -0
  159. package/package/corpus/skills/cratis-screenplay-specifications/references/concept-rules.md +77 -0
  160. package/package/corpus/skills/cratis-screenplay-specifications/references/generated-fixtures.md +39 -0
  161. package/package/corpus/skills/cratis-screenplay-specifications/references/reactions-and-cascades.md +72 -0
  162. package/package/corpus/skills/cratis-screenplay-specifications/references/worked-example.md +110 -0
  163. package/package/corpus/skills/cratis-screenplay-specifications/verification.json +6 -6
  164. package/package/corpus/skills/cratis-screenplay-streams-and-consistency/SKILL.md +23 -3
  165. package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/boundaries.md +13 -0
  166. package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/chronicle-boundaries.md +3 -3
  167. package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/consistency-and-concurrency.md +16 -20
  168. package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/stream-patterns.md +16 -0
  169. package/package/corpus/skills/cratis-screenplay-toolchain/SKILL.md +13 -7
  170. package/package/corpus/skills/cratis-screenplay-toolchain/references/diagnostics.md +10 -0
  171. package/package/corpus/skills/cratis-screenplay-toolchain/references/doc-contradictions.md +1 -1
  172. package/package/corpus/skills/cratis-screenplay-toolchain/references/executable-subset.md +12 -2
  173. package/package/corpus/skills/cratis-screenplay-toolchain/references/generated-responses-example.md +1 -1
  174. package/package/corpus/skills/cratis-screenplay-toolchain/references/provenance.md +2 -2
  175. package/package/corpus/skills/cratis-screenplay-toolchain/references/renderable-subset.md +1 -1
  176. package/package/corpus/skills/cratis-screenplay-toolchain/references/traps.md +1 -1
  177. package/package/corpus/skills/cratis-screenplay-toolchain/references/verdicts.md +10 -0
  178. package/package/corpus/skills/cratis-screenplay-toolchain/references/versions.md +15 -5
  179. package/package/corpus/skills/cratis-screenplay-ui-composition/SKILL.md +11 -13
  180. package/package/corpus/skills/cratis-screenplay-ui-composition/references/flow-review.md +1 -1
  181. package/package/corpus/skills/cratis-security-review/SKILL.md +13 -8
  182. package/package/corpus/skills/cratis-social-feed-post/SKILL.md +10 -10
  183. package/package/corpus/skills/cratis-social-feed-post/references/engagement-evidence.md +12 -0
  184. package/package/corpus/skills/cratis-specifications-csharp/SKILL.md +13 -2
  185. package/package/corpus/skills/cratis-specifications-csharp/references/application-scenarios.md +10 -10
  186. package/package/corpus/skills/cratis-specifications-csharp/references/csharp-patterns.md +10 -0
  187. package/package/corpus/skills/cratis-specifications-csharp/references/integration-specs.md +9 -0
  188. package/package/corpus/skills/cratis-specifications-typescript/SKILL.md +1 -2
  189. package/package/corpus/skills/cratis-specifications-typescript/references/typescript-patterns.md +11 -1
  190. package/package/corpus/skills/cratis-stage-rendering-and-sandbox/SKILL.md +30 -21
  191. package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/admission.md +9 -0
  192. package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/render-example.md +5 -0
  193. package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/sandbox-and-specrunner.md +2 -4
  194. package/package/corpus/skills/cratis-studio-mcp-safety-guidance/SKILL.md +2 -2
  195. package/package/corpus/skills/cratis-writing-voice-and-cadence/SKILL.md +39 -39
  196. package/package/corpus/skills/cratis-writing-voice-and-cadence/references/ai-tells.md +10 -0
  197. package/package.json +1 -1
@@ -48,6 +48,24 @@ All three artifacts are published to Maven Central under `io.cratis`
48
48
  > supported before relying on it — do not infer compatibility from the fact that
49
49
  > both are "latest".
50
50
 
51
+ ## Common pitfalls
52
+
53
+ | Pitfall | Why it bites |
54
+ | --- | --- |
55
+ | Naming a reactor method after the event | The name is ignored; **the first parameter's type** is the subscription (`EventHandlerMethod.kt:61-74`) |
56
+ | Two `@EventType` classes sharing a simple name | The id defaults to the simple name, so they collide on the wire (`EventTypesService.kt:67`) |
57
+ | Shipping the default connection string to production | `skipTlsValidation` defaults to **true**; certificate validation is off (`ChronicleConnectionString.kt:28`) |
58
+ | Copying a version from the README or docs | Both are stale at `v4.0.0`; the real version comes from the release, not the source |
59
+ | Expecting `getEventStore` to suspend | It does not — the client already connected in its constructor (`ChronicleClient.kt:12`) |
60
+ | Expecting `awaitRegistration()` to mean "registered" | It completes in a `finally`, so it also returns after a failed pass (`ArtifactRegistrations.kt:47-57`) |
61
+ | Expecting a registration failure to throw | Failures are printed to `System.err`, not raised (`EventStore.kt:244`) |
62
+ | Expecting read model reactors to be discovered | `IReadModelReactor` is absent from the scan and from `IEventStore`; construct `ReadModelReactors(...)` yourself |
63
+ | Leaving the default classpath scan on in a large app | Use `withArtifactsFrom(...)` or `artifact-packages` to narrow it (`ChronicleOptions.kt:58`) |
64
+ | Expecting WebFlux support from the starter | The web auto-configuration is `SERVLET`-only (`ChronicleWebAutoConfiguration.kt:29`) |
65
+ | Exiting `main` after an append | Reactors and reducers stop with the process; the stream is live |
66
+ | Passing a `KProperty1` as `@VariantOf`'s `key` | The annotation form always takes a plain string; only the declarative `variantOf(...)` builder accepts a property reference |
67
+ | A `@GlobalFor` mapping targeting a property one variant lacks | `GlobalHandlerPropertyNotOnVariant` at registration, not a silently skipped mapping |
68
+
51
69
  ## Two ways in — pick one
52
70
 
53
71
  | You are building | Use | Artifact |
@@ -147,58 +165,9 @@ credentials (`:42-43`).
147
165
 
148
166
  ### Spring Boot
149
167
 
150
- The starter registers exactly two auto-configurations —
151
- `Integrations/SpringBoot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports`:
152
-
153
- - `io.cratis.chronicle.spring.ChronicleAutoConfiguration`
154
- - `io.cratis.chronicle.spring.ChronicleWebAutoConfiguration`
155
-
156
- Configuration binds under the prefix `cratis.chronicle` —
157
- `ChronicleProperties.kt:42-43`. The minimum real configuration is one key, as in
158
- the shipped sample (`Samples/Kotlin/SpringBoot/src/main/resources/application.yml`):
159
-
160
- ```yaml
161
- cratis:
162
- chronicle:
163
- event-store: <EventStoreName>
164
- ```
168
+ The starter binds `cratis.chronicle.*` (minimum: `event-store`) and exposes the `IChronicleClient`, `IEventStore` and `Chronicle` beans; its web auto-configuration is servlet-only.
165
169
 
166
- Everything else has a default (`ChronicleProperties.kt:44-55`):
167
-
168
- | Key under `cratis.chronicle` | Default | Line |
169
- | --- | --- | --- |
170
- | `connection-string` | the development connection string | `:44` |
171
- | `event-store` | `"Default"` | `:45` |
172
- | `namespace` | `"Default"` | `:46` |
173
- | `auto-discover-and-register` | `true` | `:47` |
174
- | `artifact-packages` | empty — falls back to Spring's auto-configuration packages | `:48` |
175
- | `default-sink-type-id` | `null` | `:49` |
176
- | `program-identifier` | `null` — falls back to `spring.application.name` | `:50` |
177
- | `registration-timeout` | `PT30S` | `:51` |
178
- | `namespace-resolution.strategy` | `FIXED` | `:65` |
179
- | `namespace-resolution.http-header` | `"x-cratis-tenant-id"` | `:66` |
180
- | `namespace-resolution.claim` | `"tenant_id"` | `:67` |
181
-
182
- `NamespaceResolution.Strategy` is `FIXED`, `HTTP_HEADER`, `SUBDOMAIN`,
183
- `AUTHENTICATION` (`ChronicleProperties.kt:70-82`).
184
-
185
- The beans you inject are `IChronicleClient`, `IEventStore`, and the convenience
186
- facade `Chronicle` (`ChronicleAutoConfiguration.kt:93-114`). `Chronicle` wraps
187
- the suspending API in blocking calls and takes `Class<T>` rather than
188
- `KClass<T>`, so Java can use it unchanged —
189
- `Integrations/SpringBoot/src/main/kotlin/io/cratis/chronicle/spring/Chronicle.kt:47`,
190
- `append` at `:57`, `appendMany` at `:69`.
191
-
192
- `ChronicleWebAutoConfiguration` is **servlet-only**
193
- (`@ConditionalOnWebApplication(SERVLET)`, `ChronicleWebAutoConfiguration.kt:29`).
194
- A WebFlux application gets no per-request namespace, identity, causation, or
195
- unit-of-work filter.
196
-
197
- **Artifacts are Spring beans.** `SpringArtifactActivator` resolves a discovered
198
- artifact from the container when it is uniquely defined and otherwise builds it
199
- through `autowireCapableBeanFactory.createBean`
200
- (`SpringArtifactActivator.kt:28-43`), so a reactor takes constructor
201
- dependencies exactly like a `@Service` would.
170
+ Read [references/spring-boot.md](references/spring-boot.md) when wiring or configuring the Spring Boot starter (properties, namespace resolution, injected beans, WebFlux).
202
171
 
203
172
  ## Defining event types
204
173
 
@@ -369,181 +338,27 @@ alternative is a class implementing `IProjectionFor<TReadModel>`.
369
338
 
370
339
  ### Variants — mutually exclusive read models for one entity's lifecycle
371
340
 
372
- > Requires `io.cratis:chronicle` `6.3.0` or later — newer than this skill's
373
- > `5.1.0` baseline (`Source/src/main/kotlin/io/cratis/chronicle/projections/VariantOf.kt`
374
- > and siblings). Reverify before claiming support; take the version from Maven
375
- > Central, not the checked-in source.
376
-
377
- Some entities do not have one shape for their whole lifetime — a work item is a
378
- backlog entry until a pull request exists for it, then it is a pull request
379
- until it merges. **Variants** let several read models share one logical
380
- identity and be mutually exclusive: entering one variant removes the entity
381
- from every other variant in the group, and only the event named by
382
- `@EntersOn`/`entersOn(...)` can create or resurrect a variant — every other
383
- event it handles is automatically reclassified into an update-only join.
384
-
385
- **Model-bound** (the annotations are ordinary Java annotations, so Kotlin and
386
- Java use the identical shape):
387
-
388
- ```kotlin
389
- class WorkItem // anchors the group; not itself a read model
390
-
391
- @ReadModel
392
- @VariantOf(WorkItem::class, key = "id")
393
- @EntersOn(IssueCreated::class)
394
- @FromEvent(IssueCreated::class)
395
- data class BacklogItem(
396
- @FromEventSourceId val id: String = "",
397
- @SetFrom("title", IssueCreated::class) val title: String = ""
398
- )
399
-
400
- @ReadModel
401
- @VariantOf(WorkItem::class, key = "id")
402
- @EntersOn(PullRequestCreated::class)
403
- @FromEvent(PullRequestCreated::class)
404
- @FromEvent(BuildCompleted::class) // not the entering event -> update-only join
405
- data class PullRequestItem(
406
- @FromEventSourceId val id: String = "",
407
- @SetFrom("pullRequestUrl", PullRequestCreated::class) val pullRequestUrl: String = "",
408
- @SetFrom("buildStatus", BuildCompleted::class) val buildStatus: String = ""
409
- )
410
- ```
411
-
412
- `@VariantOf(identity, key)` — **`key` is always an explicit property-name
413
- string**, on both Kotlin and Java, because reflection resolves it rather than a
414
- compile-time property reference. `@EntersOn(eventType, key = "EventSourceId")`
415
- is repeatable — a variant may enter on more than one event — and its `key`
416
- names an *event* property (not the read model's), defaulting to the event
417
- source id. A mapping shared by every variant of an identity goes on a type
418
- annotated `@GlobalFor(identity)` instead of being repeated per variant; every
419
- variant it targets must actually have the member it maps, or
420
- `GlobalHandlerPropertyNotOnVariant` is thrown at registration.
421
-
422
- **Declarative** — `variantOf` and `entersOn` are members of
423
- `IProjectionBuilderFor<TReadModel>` itself:
341
+ Variants let several read models share one identity and be mutually exclusive; each variant must declare an `@EntersOn`/`entersOn(...)` event or registration throws `VariantMustDeclareEntersOnEvent`. Requires `io.cratis:chronicle` `6.3.0` or later.
424
342
 
425
- ```kotlin
426
- class PullRequestItemProjection : IProjectionFor<PullRequestItem> {
427
- override fun define(builder: IProjectionBuilderFor<PullRequestItem>) {
428
- builder
429
- .variantOf(WorkItem::class, PullRequestItem::id) // or variantOf(WorkItem::class, "id")
430
- .entersOn(PullRequestCreated::class)
431
- .from(BuildCompleted::class) // update-only, same reason
432
- }
433
- }
434
- ```
435
-
436
- Java calls the same builder with a `Class` and a string key — there is no
437
- property-reference overload in Java:
438
-
439
- ```java
440
- builder.variantOf(WorkItem.class, "id").entersOn(PullRequestCreated.class);
441
- ```
442
-
443
- **A variant that declares no `@EntersOn`/`entersOn(...)` throws
444
- `VariantMustDeclareEntersOnEvent`** at registration — a variant that could
445
- never be entered could never be written to at all, since every other handler
446
- on it is update-only.
343
+ Read [references/variants.md](references/variants.md) when an entity changes shape over its lifecycle and you need `@VariantOf`, `@EntersOn`, `@GlobalFor` or the declarative `variantOf`/`entersOn` builder.
447
344
 
448
345
  ## Discovery and registration
449
346
 
450
- `ClientArtifacts` scans the classpath with ClassGraph
451
- (`artifacts/ClientArtifacts.kt:66-98`), and `ClientArtifacts.default` is a
452
- process-wide lazy singleton (`:156`). What it looks for (`:66-98`):
347
+ Artifacts are found by a classpath scan and registered in a fixed order, re-run on every reconnect.
453
348
 
454
- | Kind | Rule |
455
- | --- | --- |
456
- | event types | `@EventType` |
457
- | event type migrations | implements `IEventTypeMigration` |
458
- | read models | `@ReadModel` |
459
- | declarative projections | implements `IProjectionFor` |
460
- | model-bound projections | `@FromEvent` **and** the synthetic `FromEvent$Container` |
461
- | reactors | `@Reactor` |
462
- | reducers | `@Reducer` |
463
- | constraints | implements `IConstraint` |
464
- | seeders | implements `ICanSeedEvents` |
465
- | webhooks | implements `IWebhookDefiner` |
466
- | captures | implements `ICapture` |
467
- | reactor middlewares | implements `IReactorMiddleware` or `BlockingReactorMiddleware` |
468
- | reactor argument resolvers | implements `IReactorMethodArgumentResolver` or `BlockingReactorMethodArgumentResolver` |
469
-
470
- > The `FromEvent$Container` entry is not incidental: Kotlin's `@Repeatable`
471
- > replaces repeated annotations with a synthetic container, so a class carrying
472
- > more than one `@FromEvent` is **not** annotated with `@FromEvent` at runtime.
473
- > A scan that looks only for the annotation silently misses every multi-event
474
- > projection.
475
-
476
- Registration order is fixed and matters
477
- (`artifacts/ArtifactRegistrations.kt:59-91`): event types and migrations →
478
- unowned read models → constraints → model-bound constraints → projections →
479
- webhooks → reactors → reducers → captures → seeders. Reactors and reducers are
480
- started only on the first pass (`:78-82`).
481
-
482
- **Registration re-runs on every reconnect.** `EventStore.kt:226-241` launches a
483
- coroutine on `Dispatchers.IO` collecting the connection lifecycle and
484
- re-registers each time. The connection id rotates on every disconnect because
485
- the kernel keys observer subscriptions by it
486
- (`connection/ConnectionLifecycle.kt:24-32`), so observers must re-register — and
487
- they do.
488
-
489
- `store.awaitRegistration()` (`IEventStore.kt:92`) waits for the first pass.
490
- `store.registerAll()` (`:83`) runs it by hand when
491
- `autoDiscoverAndRegister = false`.
349
+ Read [references/discovery-and-registration.md](references/discovery-and-registration.md) when you need the scan rules, registration order, reconnect behavior, or `registerAll()` with `autoDiscoverAndRegister = false`.
492
350
 
493
351
  ## Java
494
352
 
495
- Java is a first-class target here, not an afterthought: there is a compile-only
496
- Java conformance suite under `Source/src/test/java` whose whole point is stated
497
- in `conformance/JavaConformance.java:71-74` — *"It is never run — compiling it is
498
- the assertion"*.
353
+ Java code starts at `BlockingChronicleClient.connect(...)`, not the raw `ChronicleClient` plus `*JavaBridge` statics; in Spring Boot, inject the `Chronicle` bean.
499
354
 
500
- **Start Java code at `BlockingChronicleClient`**, not at the raw `ChronicleClient`
501
- plus static bridges. Verbatim from the compile-checked fixture
502
- (`Source/src/test/java/io/cratis/chronicle/java/JavaClientFlowUsage.java:29-34`):
503
-
504
- ```java
505
- var client = BlockingChronicleClient.connect(ChronicleOptions.development());
506
- var eventStore = client.getEventStore("<EventStoreName>");
507
-
508
- eventStore.getEventLog().append("<event-source-id>", new <EventName>("<value>"));
509
- ```
510
-
511
- `BlockingChronicleClient` is `AutoCloseable`, so `try (var client = ...)` works
512
- (`java/BlockingChronicleClient.kt:35`, `connect` at `:74-76`). The blocking
513
- surface continues through `BlockingEventStore`, `BlockingEventSequence`,
514
- `BlockingReadModels`, `BlockingReactors`, `BlockingReducers`,
515
- `BlockingUnitOfWork`, and `AppendOptionsBuilder`.
516
-
517
- > The repository's own README shows the **older** low-level route —
518
- > `new ChronicleClient(...)` plus `EventStoreJavaBridge` / `EventLogJavaBridge`
519
- > (`README.md:225-244`). Both APIs are real, but the reference documentation and
520
- > the compile-checked fixture both start at `BlockingChronicleClient`. Write new
521
- > Java against that; reach for the `*JavaBridge` statics only for a corner the
522
- > blocking client does not wrap.
523
-
524
- In Spring Boot, Java injects the `Chronicle` bean instead — it already takes
525
- `Class<T>` and returns plain values.
355
+ Read [references/java-api.md](references/java-api.md) when writing Java against the client (blocking surface, conformance suite, README's older bridge route).
526
356
 
527
357
  ## Connection lifecycle
528
358
 
529
- - **Keepalive is two-way.** The kernel pushes a keep-alive down the `Connect`
530
- stream and the client answers with a separate unary `connectionKeepAlive` RPC
531
- (`connection/ConnectionManager.kt:30`). A watchdog checks every
532
- `WATCHDOG_INTERVAL_MS = 1_000L` and treats a gap longer than
533
- `KEEP_ALIVE_TIMEOUT_MS = 5_000L` as a lost connection (`:126-128`, `:164`,
534
- `:171`). **Silence, not an error, is how the connection dies** — nothing throws.
535
- - Reconnect is an infinite loop with jittered exponential backoff, base 1s,
536
- capped at 30s, re-resolving DNS/SRV on every attempt
537
- (`ConnectionManager.kt:75-101`, `:155-158`).
538
- - The client identifies itself to the kernel as `"Kotlin"`
539
- (`ConnectionManager.kt:161`).
540
- - `dispose()` cancels the connection manager, shuts the channel down with a
541
- 5-second `awaitTermination`, then `shutdownNow`
542
- (`connection/ChronicleConnection.kt:116-125`).
543
- - **Your process must stay alive** for reactors and reducers to keep receiving —
544
- observation is a live gRPC stream, and each observer runs on its own
545
- `CoroutineScope(Dispatchers.IO)` (`observation/ReactorsService.kt:57`,
546
- `observation/ReducersService.kt:59`).
359
+ Keepalive is two-way and silence, not an error, is how the connection dies; your process must stay alive for reactors and reducers to keep receiving.
360
+
361
+ Read [references/connection-lifecycle.md](references/connection-lifecycle.md) when diagnosing disconnects, reconnect/backoff behavior, keepalive timeouts or shutdown.
547
362
 
548
363
  ## Testing
549
364
 
@@ -555,24 +370,6 @@ folds a reducer through the same handler-shape rules as production
555
370
  only; there is no in-process reactor, projection, or constraint scenario
556
371
  (`Testing/api/Testing.api` is 57 lines).
557
372
 
558
- ## Common pitfalls
559
-
560
- | Pitfall | Why it bites |
561
- | --- | --- |
562
- | Naming a reactor method after the event | The name is ignored; **the first parameter's type** is the subscription (`EventHandlerMethod.kt:61-74`) |
563
- | Two `@EventType` classes sharing a simple name | The id defaults to the simple name, so they collide on the wire (`EventTypesService.kt:67`) |
564
- | Shipping the default connection string to production | `skipTlsValidation` defaults to **true**; certificate validation is off (`ChronicleConnectionString.kt:28`) |
565
- | Copying a version from the README or docs | Both are stale at `v4.0.0`; the real version comes from the release, not the source |
566
- | Expecting `getEventStore` to suspend | It does not — the client already connected in its constructor (`ChronicleClient.kt:12`) |
567
- | Expecting `awaitRegistration()` to mean "registered" | It completes in a `finally`, so it also returns after a failed pass (`ArtifactRegistrations.kt:47-57`) |
568
- | Expecting a registration failure to throw | Failures are printed to `System.err`, not raised (`EventStore.kt:244`) |
569
- | Expecting read model reactors to be discovered | `IReadModelReactor` is absent from the scan and from `IEventStore`; construct `ReadModelReactors(...)` yourself |
570
- | Leaving the default classpath scan on in a large app | Use `withArtifactsFrom(...)` or `artifact-packages` to narrow it (`ChronicleOptions.kt:58`) |
571
- | Expecting WebFlux support from the starter | The web auto-configuration is `SERVLET`-only (`ChronicleWebAutoConfiguration.kt:29`) |
572
- | Exiting `main` after an append | Reactors and reducers stop with the process; the stream is live |
573
- | Passing a `KProperty1` as `@VariantOf`'s `key` | The annotation form always takes a plain string; only the declarative `variantOf(...)` builder accepts a property reference |
574
- | A `@GlobalFor` mapping targeting a property one variant lacks | `GlobalHandlerPropertyNotOnVariant` at registration, not a silently skipped mapping |
575
-
576
373
  ## Verify
577
374
 
578
375
  - The dependency resolves from Maven Central and the version is the one you
@@ -0,0 +1,20 @@
1
+ ## Connection lifecycle
2
+
3
+ - **Keepalive is two-way.** The kernel pushes a keep-alive down the `Connect`
4
+ stream and the client answers with a separate unary `connectionKeepAlive` RPC
5
+ (`connection/ConnectionManager.kt:30`). A watchdog checks every
6
+ `WATCHDOG_INTERVAL_MS = 1_000L` and treats a gap longer than
7
+ `KEEP_ALIVE_TIMEOUT_MS = 5_000L` as a lost connection (`:126-128`, `:164`,
8
+ `:171`). **Silence, not an error, is how the connection dies** — nothing throws.
9
+ - Reconnect is an infinite loop with jittered exponential backoff, base 1s,
10
+ capped at 30s, re-resolving DNS/SRV on every attempt
11
+ (`ConnectionManager.kt:75-101`, `:155-158`).
12
+ - The client identifies itself to the kernel as `"Kotlin"`
13
+ (`ConnectionManager.kt:161`).
14
+ - `dispose()` cancels the connection manager, shuts the channel down with a
15
+ 5-second `awaitTermination`, then `shutdownNow`
16
+ (`connection/ChronicleConnection.kt:116-125`).
17
+ - **Your process must stay alive** for reactors and reducers to keep receiving —
18
+ observation is a live gRPC stream, and each observer runs on its own
19
+ `CoroutineScope(Dispatchers.IO)` (`observation/ReactorsService.kt:57`,
20
+ `observation/ReducersService.kt:59`).
@@ -0,0 +1,44 @@
1
+ ## Discovery and registration
2
+
3
+ `ClientArtifacts` scans the classpath with ClassGraph
4
+ (`artifacts/ClientArtifacts.kt:66-98`), and `ClientArtifacts.default` is a
5
+ process-wide lazy singleton (`:156`). What it looks for (`:66-98`):
6
+
7
+ | Kind | Rule |
8
+ | --- | --- |
9
+ | event types | `@EventType` |
10
+ | event type migrations | implements `IEventTypeMigration` |
11
+ | read models | `@ReadModel` |
12
+ | declarative projections | implements `IProjectionFor` |
13
+ | model-bound projections | `@FromEvent` **and** the synthetic `FromEvent$Container` |
14
+ | reactors | `@Reactor` |
15
+ | reducers | `@Reducer` |
16
+ | constraints | implements `IConstraint` |
17
+ | seeders | implements `ICanSeedEvents` |
18
+ | webhooks | implements `IWebhookDefiner` |
19
+ | captures | implements `ICapture` |
20
+ | reactor middlewares | implements `IReactorMiddleware` or `BlockingReactorMiddleware` |
21
+ | reactor argument resolvers | implements `IReactorMethodArgumentResolver` or `BlockingReactorMethodArgumentResolver` |
22
+
23
+ > The `FromEvent$Container` entry is not incidental: Kotlin's `@Repeatable`
24
+ > replaces repeated annotations with a synthetic container, so a class carrying
25
+ > more than one `@FromEvent` is **not** annotated with `@FromEvent` at runtime.
26
+ > A scan that looks only for the annotation silently misses every multi-event
27
+ > projection.
28
+
29
+ Registration order is fixed and matters
30
+ (`artifacts/ArtifactRegistrations.kt:59-91`): event types and migrations →
31
+ unowned read models → constraints → model-bound constraints → projections →
32
+ webhooks → reactors → reducers → captures → seeders. Reactors and reducers are
33
+ started only on the first pass (`:78-82`).
34
+
35
+ **Registration re-runs on every reconnect.** `EventStore.kt:226-241` launches a
36
+ coroutine on `Dispatchers.IO` collecting the connection lifecycle and
37
+ re-registers each time. The connection id rotates on every disconnect because
38
+ the kernel keys observer subscriptions by it
39
+ (`connection/ConnectionLifecycle.kt:24-32`), so observers must re-register — and
40
+ they do.
41
+
42
+ `store.awaitRegistration()` (`IEventStore.kt:92`) waits for the first pass.
43
+ `store.registerAll()` (`:83`) runs it by hand when
44
+ `autoDiscoverAndRegister = false`.
@@ -0,0 +1,33 @@
1
+ ## Java
2
+
3
+ Java is a first-class target here, not an afterthought: there is a compile-only
4
+ Java conformance suite under `Source/src/test/java` whose whole point is stated
5
+ in `conformance/JavaConformance.java:71-74` — *"It is never run — compiling it is
6
+ the assertion"*.
7
+
8
+ **Start Java code at `BlockingChronicleClient`**, not at the raw `ChronicleClient`
9
+ plus static bridges. Verbatim from the compile-checked fixture
10
+ (`Source/src/test/java/io/cratis/chronicle/java/JavaClientFlowUsage.java:29-34`):
11
+
12
+ ```java
13
+ var client = BlockingChronicleClient.connect(ChronicleOptions.development());
14
+ var eventStore = client.getEventStore("<EventStoreName>");
15
+
16
+ eventStore.getEventLog().append("<event-source-id>", new <EventName>("<value>"));
17
+ ```
18
+
19
+ `BlockingChronicleClient` is `AutoCloseable`, so `try (var client = ...)` works
20
+ (`java/BlockingChronicleClient.kt:35`, `connect` at `:74-76`). The blocking
21
+ surface continues through `BlockingEventStore`, `BlockingEventSequence`,
22
+ `BlockingReadModels`, `BlockingReactors`, `BlockingReducers`,
23
+ `BlockingUnitOfWork`, and `AppendOptionsBuilder`.
24
+
25
+ > The repository's own README shows the **older** low-level route —
26
+ > `new ChronicleClient(...)` plus `EventStoreJavaBridge` / `EventLogJavaBridge`
27
+ > (`README.md:225-244`). Both APIs are real, but the reference documentation and
28
+ > the compile-checked fixture both start at `BlockingChronicleClient`. Write new
29
+ > Java against that; reach for the `*JavaBridge` statics only for a corner the
30
+ > blocking client does not wrap.
31
+
32
+ In Spring Boot, Java injects the `Chronicle` bean instead — it already takes
33
+ `Class<T>` and returns plain values.
@@ -0,0 +1,54 @@
1
+ ## Spring Boot
2
+
3
+ The starter registers exactly two auto-configurations —
4
+ `Integrations/SpringBoot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports`:
5
+
6
+ - `io.cratis.chronicle.spring.ChronicleAutoConfiguration`
7
+ - `io.cratis.chronicle.spring.ChronicleWebAutoConfiguration`
8
+
9
+ Configuration binds under the prefix `cratis.chronicle` —
10
+ `ChronicleProperties.kt:42-43`. The minimum real configuration is one key, as in
11
+ the shipped sample (`Samples/Kotlin/SpringBoot/src/main/resources/application.yml`):
12
+
13
+ ```yaml
14
+ cratis:
15
+ chronicle:
16
+ event-store: <EventStoreName>
17
+ ```
18
+
19
+ Everything else has a default (`ChronicleProperties.kt:44-55`):
20
+
21
+ | Key under `cratis.chronicle` | Default | Line |
22
+ | --- | --- | --- |
23
+ | `connection-string` | the development connection string | `:44` |
24
+ | `event-store` | `"Default"` | `:45` |
25
+ | `namespace` | `"Default"` | `:46` |
26
+ | `auto-discover-and-register` | `true` | `:47` |
27
+ | `artifact-packages` | empty — falls back to Spring's auto-configuration packages | `:48` |
28
+ | `default-sink-type-id` | `null` | `:49` |
29
+ | `program-identifier` | `null` — falls back to `spring.application.name` | `:50` |
30
+ | `registration-timeout` | `PT30S` | `:51` |
31
+ | `namespace-resolution.strategy` | `FIXED` | `:65` |
32
+ | `namespace-resolution.http-header` | `"x-cratis-tenant-id"` | `:66` |
33
+ | `namespace-resolution.claim` | `"tenant_id"` | `:67` |
34
+
35
+ `NamespaceResolution.Strategy` is `FIXED`, `HTTP_HEADER`, `SUBDOMAIN`,
36
+ `AUTHENTICATION` (`ChronicleProperties.kt:70-82`).
37
+
38
+ The beans you inject are `IChronicleClient`, `IEventStore`, and the convenience
39
+ facade `Chronicle` (`ChronicleAutoConfiguration.kt:93-114`). `Chronicle` wraps
40
+ the suspending API in blocking calls and takes `Class<T>` rather than
41
+ `KClass<T>`, so Java can use it unchanged —
42
+ `Integrations/SpringBoot/src/main/kotlin/io/cratis/chronicle/spring/Chronicle.kt:47`,
43
+ `append` at `:57`, `appendMany` at `:69`.
44
+
45
+ `ChronicleWebAutoConfiguration` is **servlet-only**
46
+ (`@ConditionalOnWebApplication(SERVLET)`, `ChronicleWebAutoConfiguration.kt:29`).
47
+ A WebFlux application gets no per-request namespace, identity, causation, or
48
+ unit-of-work filter.
49
+
50
+ **Artifacts are Spring beans.** `SpringArtifactActivator` resolves a discovered
51
+ artifact from the container when it is uniquely defined and otherwise builds it
52
+ through `autowireCapableBeanFactory.createBean`
53
+ (`SpringArtifactActivator.kt:28-43`), so a reactor takes constructor
54
+ dependencies exactly like a `@Service` would.
@@ -0,0 +1,77 @@
1
+ ## Variants — mutually exclusive read models for one entity's lifecycle
2
+
3
+ > Requires `io.cratis:chronicle` `6.3.0` or later — newer than this skill's
4
+ > `5.1.0` baseline (`Source/src/main/kotlin/io/cratis/chronicle/projections/VariantOf.kt`
5
+ > and siblings). Reverify before claiming support; take the version from Maven
6
+ > Central, not the checked-in source.
7
+
8
+ Some entities do not have one shape for their whole lifetime — a work item is a
9
+ backlog entry until a pull request exists for it, then it is a pull request
10
+ until it merges. **Variants** let several read models share one logical
11
+ identity and be mutually exclusive: entering one variant removes the entity
12
+ from every other variant in the group, and only the event named by
13
+ `@EntersOn`/`entersOn(...)` can create or resurrect a variant — every other
14
+ event it handles is automatically reclassified into an update-only join.
15
+
16
+ **Model-bound** (the annotations are ordinary Java annotations, so Kotlin and
17
+ Java use the identical shape):
18
+
19
+ ```kotlin
20
+ class WorkItem // anchors the group; not itself a read model
21
+
22
+ @ReadModel
23
+ @VariantOf(WorkItem::class, key = "id")
24
+ @EntersOn(IssueCreated::class)
25
+ @FromEvent(IssueCreated::class)
26
+ data class BacklogItem(
27
+ @FromEventSourceId val id: String = "",
28
+ @SetFrom("title", IssueCreated::class) val title: String = ""
29
+ )
30
+
31
+ @ReadModel
32
+ @VariantOf(WorkItem::class, key = "id")
33
+ @EntersOn(PullRequestCreated::class)
34
+ @FromEvent(PullRequestCreated::class)
35
+ @FromEvent(BuildCompleted::class) // not the entering event -> update-only join
36
+ data class PullRequestItem(
37
+ @FromEventSourceId val id: String = "",
38
+ @SetFrom("pullRequestUrl", PullRequestCreated::class) val pullRequestUrl: String = "",
39
+ @SetFrom("buildStatus", BuildCompleted::class) val buildStatus: String = ""
40
+ )
41
+ ```
42
+
43
+ `@VariantOf(identity, key)` — **`key` is always an explicit property-name
44
+ string**, on both Kotlin and Java, because reflection resolves it rather than a
45
+ compile-time property reference. `@EntersOn(eventType, key = "EventSourceId")`
46
+ is repeatable — a variant may enter on more than one event — and its `key`
47
+ names an *event* property (not the read model's), defaulting to the event
48
+ source id. A mapping shared by every variant of an identity goes on a type
49
+ annotated `@GlobalFor(identity)` instead of being repeated per variant; every
50
+ variant it targets must actually have the member it maps, or
51
+ `GlobalHandlerPropertyNotOnVariant` is thrown at registration.
52
+
53
+ **Declarative** — `variantOf` and `entersOn` are members of
54
+ `IProjectionBuilderFor<TReadModel>` itself:
55
+
56
+ ```kotlin
57
+ class PullRequestItemProjection : IProjectionFor<PullRequestItem> {
58
+ override fun define(builder: IProjectionBuilderFor<PullRequestItem>) {
59
+ builder
60
+ .variantOf(WorkItem::class, PullRequestItem::id) // or variantOf(WorkItem::class, "id")
61
+ .entersOn(PullRequestCreated::class)
62
+ .from(BuildCompleted::class) // update-only, same reason
63
+ }
64
+ }
65
+ ```
66
+
67
+ Java calls the same builder with a `Class` and a string key — there is no
68
+ property-reference overload in Java:
69
+
70
+ ```java
71
+ builder.variantOf(WorkItem.class, "id").entersOn(PullRequestCreated.class);
72
+ ```
73
+
74
+ **A variant that declares no `@EntersOn`/`entersOn(...)` throws
75
+ `VariantMustDeclareEntersOnEvent`** at registration — a variant that could
76
+ never be entered could never be written to at all, since every other handler
77
+ on it is update-only.