@cratis/pi 7.14.2 → 7.14.4
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/skills/cratis-application-slice-conformance/SKILL.md +11 -2
- package/package/corpus/skills/cratis-application-slice-conformance/references/build-prompts.md +8 -0
- package/package/corpus/skills/cratis-application-slice-conformance/references/checklists.md +10 -6
- package/package/corpus/skills/cratis-application-slice-specifications/SKILL.md +1 -1
- package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/SKILL.md +11 -7
- package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/references/authentication.md +12 -2
- package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/references/authorization.md +16 -1
- package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/references/frontend.md +7 -0
- package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/references/observable-emission-guards.md +9 -0
- package/package/corpus/skills/cratis-arc-command/SKILL.md +20 -15
- package/package/corpus/skills/cratis-arc-command/references/command-result.md +7 -0
- package/package/corpus/skills/cratis-arc-command/references/handler-shapes.md +10 -3
- package/package/corpus/skills/cratis-arc-command-execution/SKILL.md +1 -1
- package/package/corpus/skills/cratis-arc-command-operation/SKILL.md +5 -1
- package/package/corpus/skills/cratis-arc-command-operation/references/execution-and-recovery.md +12 -0
- package/package/corpus/skills/cratis-arc-command-operation/references/testing.md +10 -3
- package/package/corpus/skills/cratis-arc-command-typescript/SKILL.md +20 -116
- package/package/corpus/skills/cratis-arc-command-typescript/references/chronicle-events.md +11 -8
- package/package/corpus/skills/cratis-arc-command-typescript/references/command-specifications.md +63 -0
- package/package/corpus/skills/cratis-arc-command-typescript/references/hosting-and-storage.md +10 -0
- package/package/corpus/skills/cratis-arc-command-typescript/references/proxy-generation.md +38 -0
- package/package/corpus/skills/cratis-arc-command-typescript/references/slice-layout.md +19 -0
- package/package/corpus/skills/cratis-arc-command-typescript/verification.json +1 -1
- package/package/corpus/skills/cratis-arc-command-validation/SKILL.md +1 -1
- package/package/corpus/skills/cratis-arc-query-paging/SKILL.md +11 -10
- package/package/corpus/skills/cratis-arc-react-page/SKILL.md +30 -19
- package/package/corpus/skills/cratis-arc-react-page/references/data-page.md +11 -0
- package/package/corpus/skills/cratis-arc-react-page/references/data-tables.md +10 -0
- package/package/corpus/skills/cratis-arc-react-page/references/dialogs.md +12 -10
- package/package/corpus/skills/cratis-arc-react-page/references/from-screenplay.md +10 -0
- package/package/corpus/skills/cratis-arc-react-page/references/mvvm.md +11 -0
- package/package/corpus/skills/cratis-arc-react-page/references/queries-and-commands.md +7 -0
- package/package/corpus/skills/cratis-chronicle-client-dotnet/SKILL.md +58 -122
- package/package/corpus/skills/cratis-chronicle-client-dotnet/references/compatibility-check.md +26 -0
- package/package/corpus/skills/cratis-chronicle-client-dotnet/references/discovery.md +22 -0
- package/package/corpus/skills/cratis-chronicle-client-dotnet/references/hosting.md +31 -0
- package/package/corpus/skills/cratis-chronicle-client-elixir/SKILL.md +52 -131
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/append-api.md +19 -0
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/variants.md +73 -0
- package/package/corpus/skills/cratis-chronicle-client-kotlin/SKILL.md +29 -232
- package/package/corpus/skills/cratis-chronicle-client-kotlin/references/connection-lifecycle.md +20 -0
- package/package/corpus/skills/cratis-chronicle-client-kotlin/references/discovery-and-registration.md +44 -0
- package/package/corpus/skills/cratis-chronicle-client-kotlin/references/java-api.md +33 -0
- package/package/corpus/skills/cratis-chronicle-client-kotlin/references/spring-boot.md +54 -0
- package/package/corpus/skills/cratis-chronicle-client-kotlin/references/variants.md +77 -0
- package/package/corpus/skills/cratis-chronicle-client-typescript/SKILL.md +26 -102
- package/package/corpus/skills/cratis-chronicle-client-typescript/references/read-models-and-projections.md +23 -0
- package/package/corpus/skills/cratis-chronicle-client-typescript/references/variants.md +63 -0
- package/package/corpus/skills/cratis-chronicle-event-type-migration/SKILL.md +13 -13
- package/package/corpus/skills/cratis-chronicle-mcp-inspection/SKILL.md +1 -1
- package/package/corpus/skills/cratis-chronicle-projection/SKILL.md +13 -4
- package/package/corpus/skills/cratis-chronicle-projection/references/fluent-builder.md +10 -0
- package/package/corpus/skills/cratis-chronicle-projection/references/model-bound-attributes.md +14 -6
- package/package/corpus/skills/cratis-chronicle-projection/references/variants.md +9 -0
- package/package/corpus/skills/cratis-chronicle-reactor/SKILL.md +7 -49
- package/package/corpus/skills/cratis-chronicle-reactor/references/domain-failures.md +19 -0
- package/package/corpus/skills/cratis-chronicle-reactor/references/specifications.md +33 -0
- package/package/corpus/skills/cratis-chronicle-read-model/SKILL.md +2 -2
- package/package/corpus/skills/cratis-chronicle-read-model/references/queries.md +11 -0
- package/package/corpus/skills/cratis-chronicle-read-model-specifications/SKILL.md +1 -0
- package/package/corpus/skills/cratis-chronicle-reducer/SKILL.md +1 -1
- package/package/corpus/skills/cratis-chronicle-web-workbench/SKILL.md +24 -24
- package/package/corpus/skills/cratis-content-length/SKILL.md +1 -1
- package/package/corpus/skills/cratis-content-length/references/length-evidence.md +12 -0
- package/package/corpus/skills/cratis-developer-marketing/SKILL.md +19 -19
- package/package/corpus/skills/cratis-developer-marketing/references/measurement.md +10 -0
- package/package/corpus/skills/cratis-developer-marketing/references/playbook-evidence.md +10 -0
- package/package/corpus/skills/cratis-engineering-csharp-conventions/SKILL.md +5 -0
- package/package/corpus/skills/cratis-engineering-csharp-conventions/references/code-style.md +15 -0
- package/package/corpus/skills/cratis-engineering-csharp-conventions/references/exceptions-logging-and-di.md +9 -4
- package/package/corpus/skills/cratis-engineering-decision-record/SKILL.md +1 -2
- package/package/corpus/skills/cratis-engineering-decision-record/references/record-format.md +8 -0
- package/package/corpus/skills/cratis-engineering-docs-authoring/SKILL.md +1 -2
- package/package/corpus/skills/cratis-engineering-effect-boundaries/references/failure-archetypes.md +10 -0
- package/package/corpus/skills/cratis-fundamentals-concept/SKILL.md +1 -1
- package/package/corpus/skills/cratis-fundamentals-type-discovery/SKILL.md +1 -1
- package/package/corpus/skills/cratis-lens-browser-extension/SKILL.md +18 -18
- package/package/corpus/skills/cratis-performance-review/SKILL.md +1 -1
- package/package/corpus/skills/cratis-release-notes/SKILL.md +1 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/SKILL.md +29 -4
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/automation-patterns.md +16 -4
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/effects-and-idempotency.md +4 -15
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/todo-list-example.md +6 -2
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/translation-patterns.md +1 -6
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/SKILL.md +45 -245
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/references/capture-map-and-example.md +42 -0
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/references/complete-examples.md +155 -0
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/references/specifying-triggers-and-clock.md +27 -0
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/references/trigger-reads-example.md +21 -0
- package/package/corpus/skills/cratis-screenplay-command-surface/SKILL.md +69 -227
- package/package/corpus/skills/cratis-screenplay-command-surface/references/context.md +10 -0
- package/package/corpus/skills/cratis-screenplay-command-surface/references/generated-values-and-responses.md +51 -0
- package/package/corpus/skills/cratis-screenplay-command-surface/references/inline-events.md +62 -0
- package/package/corpus/skills/cratis-screenplay-command-surface/references/policy-persona-seed.md +46 -0
- package/package/corpus/skills/cratis-screenplay-command-surface/references/validate-rules.md +36 -0
- package/package/corpus/skills/cratis-screenplay-command-surface/verification.json +11 -11
- package/package/corpus/skills/cratis-screenplay-discovery/SKILL.md +10 -3
- package/package/corpus/skills/cratis-screenplay-discovery/references/facilitation.md +1 -6
- package/package/corpus/skills/cratis-screenplay-discovery/references/human-workshop.md +13 -0
- package/package/corpus/skills/cratis-screenplay-discovery/references/personas-and-causes.md +8 -0
- package/package/corpus/skills/cratis-screenplay-discovery/references/plotting-and-handoff.md +11 -0
- package/package/corpus/skills/cratis-screenplay-discovery/references/storming-loop.md +7 -0
- package/package/corpus/skills/cratis-screenplay-event-modeling/SKILL.md +75 -198
- package/package/corpus/skills/cratis-screenplay-event-modeling/references/file-layout.md +89 -0
- package/package/corpus/skills/cratis-screenplay-event-modeling/references/naming-primitives.md +26 -0
- package/package/corpus/skills/cratis-screenplay-event-modeling/references/nine-steps.md +14 -1
- package/package/corpus/skills/cratis-screenplay-event-modeling/references/parsed-not-runnable.md +8 -0
- package/package/corpus/skills/cratis-screenplay-event-modeling/references/provenance.md +10 -0
- package/package/corpus/skills/cratis-screenplay-event-modeling/references/slice-type-rules.md +12 -0
- package/package/corpus/skills/cratis-screenplay-event-modeling/verification.json +12 -6
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/SKILL.md +5 -6
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/candidate-inventory.md +11 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/prologue-safety.md +8 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/side-car-migration.md +11 -0
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/ui-observation.md +1 -1
- package/package/corpus/skills/cratis-screenplay-model-authoring/SKILL.md +33 -10
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/language-reference.md +8 -0
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/mcp-loop.md +13 -17
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/mcp-tools.md +11 -0
- package/package/corpus/skills/cratis-screenplay-model-review/SKILL.md +9 -9
- package/package/corpus/skills/cratis-screenplay-model-review/references/business-questions.md +9 -0
- package/package/corpus/skills/cratis-screenplay-model-review/references/checklist.md +15 -0
- package/package/corpus/skills/cratis-screenplay-model-review/references/report-template.md +9 -0
- package/package/corpus/skills/cratis-screenplay-model-review/references/worked-example.md +9 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/SKILL.md +17 -8
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/handoff-template.md +8 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/identity-and-edits.md +1 -6
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/phases.md +19 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/safety.md +1 -1
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/verdicts-and-modes.md +11 -1
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/vocabulary-map.md +2 -2
- package/package/corpus/skills/cratis-screenplay-projections/SKILL.md +3 -4
- package/package/corpus/skills/cratis-screenplay-projections/references/pdl-grammar.md +8 -0
- package/package/corpus/skills/cratis-screenplay-read-surface/SKILL.md +2 -2
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/SKILL.md +3 -3
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/references/gap-fill-handoff.md +1 -1
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/references/worked-example.md +8 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/SKILL.md +10 -10
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/coverage-matrix.md +8 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/invoicing-dues-example.md +4 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/scenario-catalogue.md +17 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/scenario-examples.md +10 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/scenario-workshop.md +11 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/view-and-story-specs.md +12 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/SKILL.md +2 -2
- package/package/corpus/skills/cratis-screenplay-slice-design/references/command-inventory.md +7 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/references/field-lineage.md +8 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/references/read-model-design.md +16 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/references/slicing.md +10 -0
- package/package/corpus/skills/cratis-screenplay-specifications/SKILL.md +52 -360
- package/package/corpus/skills/cratis-screenplay-specifications/references/actions-beyond-commands.md +34 -0
- package/package/corpus/skills/cratis-screenplay-specifications/references/concept-rules.md +77 -0
- package/package/corpus/skills/cratis-screenplay-specifications/references/generated-fixtures.md +39 -0
- package/package/corpus/skills/cratis-screenplay-specifications/references/reactions-and-cascades.md +72 -0
- package/package/corpus/skills/cratis-screenplay-specifications/references/worked-example.md +110 -0
- package/package/corpus/skills/cratis-screenplay-specifications/verification.json +6 -6
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/SKILL.md +21 -1
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/boundaries.md +13 -0
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/chronicle-boundaries.md +1 -1
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/consistency-and-concurrency.md +16 -20
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/stream-patterns.md +16 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/SKILL.md +13 -7
- package/package/corpus/skills/cratis-screenplay-toolchain/references/diagnostics.md +10 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/executable-subset.md +10 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/generated-responses-example.md +1 -1
- package/package/corpus/skills/cratis-screenplay-toolchain/references/traps.md +1 -1
- package/package/corpus/skills/cratis-screenplay-toolchain/references/verdicts.md +10 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/versions.md +12 -0
- package/package/corpus/skills/cratis-screenplay-ui-composition/SKILL.md +11 -13
- package/package/corpus/skills/cratis-screenplay-ui-composition/references/flow-review.md +1 -1
- package/package/corpus/skills/cratis-social-feed-post/SKILL.md +10 -10
- package/package/corpus/skills/cratis-social-feed-post/references/engagement-evidence.md +12 -0
- package/package/corpus/skills/cratis-specifications-csharp/SKILL.md +13 -2
- package/package/corpus/skills/cratis-specifications-csharp/references/application-scenarios.md +10 -10
- package/package/corpus/skills/cratis-specifications-csharp/references/csharp-patterns.md +10 -0
- package/package/corpus/skills/cratis-specifications-csharp/references/integration-specs.md +9 -0
- package/package/corpus/skills/cratis-specifications-typescript/SKILL.md +1 -2
- package/package/corpus/skills/cratis-specifications-typescript/references/typescript-patterns.md +11 -1
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/SKILL.md +30 -21
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/admission.md +9 -0
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/render-example.md +5 -0
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/sandbox-and-specrunner.md +2 -4
- package/package/corpus/skills/cratis-studio-mcp-safety-guidance/SKILL.md +2 -2
- package/package/corpus/skills/cratis-writing-voice-and-cadence/SKILL.md +39 -39
- package/package/corpus/skills/cratis-writing-voice-and-cadence/references/ai-tells.md +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
## Discovery
|
|
2
|
+
|
|
3
|
+
Artifacts are found by **assembly scanning**, with no registration call and no DI
|
|
4
|
+
container required. `DefaultClientArtifactsProvider.Default` composes the
|
|
5
|
+
project-referenced and package-referenced assemblies
|
|
6
|
+
(`Source/Clients/DotNET/DefaultClientArtifactsProvider.cs:37`), and the
|
|
7
|
+
predicates are exactly (`:242-251`):
|
|
8
|
+
|
|
9
|
+
| Kind | Predicate |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| event types | `HasAttribute<EventTypeAttribute>()` or `HasAttribute<EventTypeGenerationForAttribute>()` |
|
|
12
|
+
| projections | `HasInterface(typeof(IProjectionFor<>))` |
|
|
13
|
+
| model-bound projections | `HasModelBoundProjectionAttributes()` |
|
|
14
|
+
| reactors | `HasInterface<IReactor>()` and not generic |
|
|
15
|
+
| read model reactors | `HasInterface<IReadModelReactor>()` and not generic |
|
|
16
|
+
| reducers | `HasInterface(typeof(IReducerFor<>))` and not generic |
|
|
17
|
+
|
|
18
|
+
Explicit registration is available per family as an alternative —
|
|
19
|
+
`IEventTypes.Register`, `IConstraints.Register`, `IProjections.Register`,
|
|
20
|
+
`IReducers.Register`, `IReactors.Register<TReactor>()`,
|
|
21
|
+
`IReadModels.Register<TReadModel>()` — and is what you use with
|
|
22
|
+
`AutoDiscoverAndRegister = false`.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
## In a host
|
|
2
|
+
|
|
3
|
+
```csharp
|
|
4
|
+
var builder = Host.CreateApplicationBuilder(args);
|
|
5
|
+
builder.AddCratisChronicle(options => options.EventStore = "<EventStoreName>");
|
|
6
|
+
builder.Services.AddHostedService<<WorkerName>>();
|
|
7
|
+
await builder.Build().RunAsync();
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
`AddCratisChronicle` is an extension on **`IHostApplicationBuilder`**
|
|
11
|
+
(`Source/Clients/DotNET/ChronicleHostApplicationBuilderExtensions.cs:28`) and binds
|
|
12
|
+
the `Cratis:Chronicle` configuration section by default (`:25`, `:37`), with
|
|
13
|
+
`ValidateDataAnnotations().ValidateOnStart()`. The bound type is
|
|
14
|
+
`ChronicleClientOptions : ChronicleOptions`, which adds a `[Required] EventStore`
|
|
15
|
+
and an optional `EventStoreNamespaceResolverType`.
|
|
16
|
+
|
|
17
|
+
> **`AddCratisChronicle` on `IServiceCollection` does not exist**, despite what
|
|
18
|
+
> `Documentation/clients/dotnet/getting-started.md:61` shows. The real extensions
|
|
19
|
+
> are on `IHostApplicationBuilder`, `WebApplicationBuilder` (in the AspNetCore
|
|
20
|
+
> package), and Aspire's `IDistributedApplicationBuilder`. `IHostBuilder.AddCratisChronicle()`
|
|
21
|
+
> also exists but only registers concept type converters
|
|
22
|
+
> (`Source/Clients/DotNET/Hosting/HostBuilderExtensions.cs:18-23`) — it is not
|
|
23
|
+
> the wiring entry point.
|
|
24
|
+
|
|
25
|
+
`IChronicleBuilder` extensions are exactly five:
|
|
26
|
+
`WithArtifactsProvider`, `WithIdentityProvider`, `WithCorrelationIdAccessor`,
|
|
27
|
+
`WithNamespaceResolver`, `WithCamelCaseNamingPolicy`
|
|
28
|
+
(`Source/Clients/DotNET/ChronicleBuilderExtensions.cs`). **There is no
|
|
29
|
+
`WithClaimsBasedNamespaceResolver`**, despite a doc comment at
|
|
30
|
+
`ChronicleOptions.cs:141` referring to one. Pass the resolver instead:
|
|
31
|
+
`new ChronicleClient(options, namespaceResolver: new ClaimsBasedNamespaceResolver("tenant_id"))`.
|
|
@@ -125,6 +125,54 @@ depends on it, and nothing is left holding a dead channel.
|
|
|
125
125
|
Pass `name:` to `Chronicle.Client` and `client:` to every API call. Every public
|
|
126
126
|
function takes a `:client` option.
|
|
127
127
|
|
|
128
|
+
## Connecting is asynchronous — wait for the lifecycle
|
|
129
|
+
|
|
130
|
+
The client connects in the background. `Chronicle.Connections.Lifecycle`
|
|
131
|
+
broadcasts `{:chronicle_lifecycle, phase, connection_id}` with three phases
|
|
132
|
+
(`lib/chronicle/connections/lifecycle.ex:54`):
|
|
133
|
+
|
|
134
|
+
| Phase | Meaning |
|
|
135
|
+
| --- | --- |
|
|
136
|
+
| `:disconnected` | no live session with the kernel |
|
|
137
|
+
| `:connected` | the session handshake completed |
|
|
138
|
+
| `:registered` | the registration coordinator registered the base artifacts |
|
|
139
|
+
|
|
140
|
+
**Wait for `:registered`, never merely `:connected`** — the module's own docs say
|
|
141
|
+
so at `:27-29`, because reducers and reactors are not attached until registration
|
|
142
|
+
finishes.
|
|
143
|
+
|
|
144
|
+
```elixir
|
|
145
|
+
config = Chronicle.Client.config()
|
|
146
|
+
|
|
147
|
+
case Chronicle.Connections.Lifecycle.wait_until(config.lifecycle, :registered, 30_000) do
|
|
148
|
+
:ok -> :ok
|
|
149
|
+
{:error, :timeout} -> # decide what a not-yet-registered client means for you
|
|
150
|
+
end
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
`wait_until(lifecycle, target_phase, timeout \\ 30_000)` is at `:141`.
|
|
154
|
+
`subscribe/1` (`:90`) returns the current phase **and** sends it as a message,
|
|
155
|
+
which closes the subscribe-after-transition race; `phase/1` (`:98`) is the plain
|
|
156
|
+
read.
|
|
157
|
+
|
|
158
|
+
## Keepalive — the failure mode is silence
|
|
159
|
+
|
|
160
|
+
The contract is spelled out in `lib/chronicle/connections/keep_alive.ex:7-17`:
|
|
161
|
+
the kernel pushes a `ConnectionKeepAlive` down the `Connect` server stream once
|
|
162
|
+
per second, and for each one **the client must call back the separate unary
|
|
163
|
+
`ConnectionKeepAlive` RPC** (`answer/2` at `:56`). A client that only consumes the
|
|
164
|
+
stream is evicted once the kernel's `LastSeen` falls more than five seconds
|
|
165
|
+
behind, and the kernel then unsubscribes its observers.
|
|
166
|
+
|
|
167
|
+
The consequence is stated in that same comment and is worth carrying into any
|
|
168
|
+
diagnosis: **reactors and reducers go quiet while the `Connect` stream stays open
|
|
169
|
+
and every append keeps working.** Nothing raises. If observers stop firing but
|
|
170
|
+
appends succeed, look at the connection before you look at the observer.
|
|
171
|
+
|
|
172
|
+
Reconnect is exponential backoff — `:retry_attempts` 5, `:reconnect_base_delay`
|
|
173
|
+
1000 ms, `:reconnect_max_delay` 10000 ms — re-resolving addresses on every
|
|
174
|
+
attempt.
|
|
175
|
+
|
|
128
176
|
## Connection strings
|
|
129
177
|
|
|
130
178
|
`Chronicle.Connections.ConnectionString` accepts `chronicle://` and
|
|
@@ -205,21 +253,8 @@ raises at compile time.
|
|
|
205
253
|
sequence number, and `append_and_wait_for_completion/3` exists for when you need
|
|
206
254
|
the outcome.
|
|
207
255
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
| `append/3` | `(event_source_id, event, opts)` | `:99` |
|
|
211
|
-
| `append_many/3` | `(event_source_id, events, opts)` | `:120` |
|
|
212
|
-
| `append_many_for_event_sources/2` | `(events, opts)` | `:155` |
|
|
213
|
-
| `append_and_wait_for_completion/3` | returns `{:ok, %{success: _, failed_partitions: _}}` | `:215` |
|
|
214
|
-
| `get_for_event_source/2` | | `:326` |
|
|
215
|
-
| `get_from_sequence_number/2` | | `:369` |
|
|
216
|
-
| `get_tail_sequence_number/2` | | `:408` |
|
|
217
|
-
|
|
218
|
-
Append options (`event_log.ex:79-94`, plus `:occurred` read at `:720`): `:client`, `:namespace`,
|
|
219
|
-
`:event_sequence_id` (default `"event-log"`), `:event_source_type` (default
|
|
220
|
-
`"Default"`), `:event_stream_type` (default **`"All"`**), `:event_stream_id`
|
|
221
|
-
(default `"Default"`), `:tags`, `:subject`, `:correlation_id`, `:identity`,
|
|
222
|
-
`:causation`, `:concurrency_scope`, `:occurred`.
|
|
256
|
+
The other append functions (`append_many/3`, `append_many_for_event_sources/2`, `append_and_wait_for_completion/3`, the `get_*` readers) and the full option list are in the reference.
|
|
257
|
+
Read [references/append-api.md](references/append-api.md) when you need an append variant, a read-back function, or an append option such as `:event_stream_type`, `:concurrency_scope` or `:tags`.
|
|
223
258
|
|
|
224
259
|
Errors are normalized to one of two shapes:
|
|
225
260
|
|
|
@@ -313,75 +348,9 @@ process**, so the reduction is Elixir code you own.
|
|
|
313
348
|
|
|
314
349
|
#### Variants — mutually exclusive read models for one entity's lifecycle
|
|
315
350
|
|
|
316
|
-
|
|
317
|
-
> `3.1.0` baseline (`lib/chronicle/projections/variant_reclassifier.ex` and
|
|
318
|
-
> siblings). Reverify before claiming support; take the version from hex.pm.
|
|
319
|
-
|
|
320
|
-
Some entities do not have one shape for their whole lifetime — a work item is a
|
|
321
|
-
backlog entry until a pull request exists for it, then it is a pull request
|
|
322
|
-
until it merges. `variant_of/2` and `enters_on/1,2` are macros imported by
|
|
323
|
-
**both** `use Chronicle.ReadModels.ReadModel` and
|
|
324
|
-
`use Chronicle.Projections.Projection`, so the model-bound and declarative
|
|
325
|
-
paths declare a variant identically:
|
|
326
|
-
|
|
327
|
-
```elixir
|
|
328
|
-
defmodule MyApp.ReadModels.WorkItem do
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
defmodule MyApp.ReadModels.BacklogItem do
|
|
332
|
-
use Chronicle.ReadModels.ReadModel
|
|
333
|
-
defstruct id: nil, title: nil
|
|
334
|
-
|
|
335
|
-
variant_of MyApp.ReadModels.WorkItem, key: :id
|
|
336
|
-
enters_on MyApp.Events.IssueCreated
|
|
337
|
-
|
|
338
|
-
from MyApp.Events.IssueCreated, set: [id: :event_source_id, title: :title]
|
|
339
|
-
end
|
|
340
|
-
|
|
341
|
-
defmodule MyApp.ReadModels.PullRequestItem do
|
|
342
|
-
use Chronicle.ReadModels.ReadModel
|
|
343
|
-
defstruct id: nil, pull_request_url: nil, build_status: nil
|
|
344
|
-
|
|
345
|
-
variant_of MyApp.ReadModels.WorkItem, key: :id
|
|
346
|
-
enters_on MyApp.Events.PullRequestCreated
|
|
351
|
+
Requires `cratis_chronicle` `3.4.0` or later (newer than this skill's `3.1.0` baseline). `variant_of/2` requires `:key`; a variant with no `enters_on` raises `Chronicle.Projections.VariantMustDeclareEntersOnEvent` at registration.
|
|
347
352
|
|
|
348
|
-
|
|
349
|
-
set: [id: :event_source_id, pull_request_url: :pull_request_url]
|
|
350
|
-
|
|
351
|
-
# not the entering event -> automatically reclassified into an update-only join
|
|
352
|
-
from MyApp.Events.BuildCompleted, set: [build_status: :build_status]
|
|
353
|
-
end
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
`variant_of/2` takes `:key` — **required** — the field on this variant that
|
|
357
|
-
carries the shared identity. `enters_on/1,2` is repeatable and its own `:key`
|
|
358
|
-
option names an *event* property (defaults to `:event_source_id`); every
|
|
359
|
-
`from`/`join` this variant declares for a non-entering event, whether declared
|
|
360
|
-
locally or merged from a shared handler, is automatically reclassified into an
|
|
361
|
-
update-only join keyed on `variant_of`'s `:key`.
|
|
362
|
-
|
|
363
|
-
A mapping shared across every variant of an identity is a
|
|
364
|
-
`Chronicle.Projections.GlobalHandler`, never registered as a projection on its
|
|
365
|
-
own:
|
|
366
|
-
|
|
367
|
-
```elixir
|
|
368
|
-
defmodule MyApp.Projections.WorkItemTitleHandler do
|
|
369
|
-
use Chronicle.Projections.GlobalHandler, identity: MyApp.ReadModels.WorkItem
|
|
370
|
-
|
|
371
|
-
from MyApp.Events.TitleChanged, set: [title: :title]
|
|
372
|
-
end
|
|
373
|
-
```
|
|
374
|
-
|
|
375
|
-
Register it explicitly with `global_handlers: [...]` on `Chronicle.Client`, or
|
|
376
|
-
let `:otp_app` auto-discovery find it (modules exporting
|
|
377
|
-
`__chronicle_global_handler__/1`). A mapping that targets a field some variant
|
|
378
|
-
lacks raises `Chronicle.Projections.GlobalHandlerPropertyNotOnVariant` at
|
|
379
|
-
registration, not a silently skipped mapping.
|
|
380
|
-
|
|
381
|
-
**A variant with no `enters_on` raises
|
|
382
|
-
`Chronicle.Projections.VariantMustDeclareEntersOnEvent`** at registration — a
|
|
383
|
-
variant that could never be entered could never be written to at all, since
|
|
384
|
-
every other handler on it is update-only.
|
|
353
|
+
Read [references/variants.md](references/variants.md) when an entity has mutually exclusive lifecycle shapes (for example a backlog entry that becomes a pull request) and you need variant read models or a `GlobalHandler`.
|
|
385
354
|
|
|
386
355
|
Querying (`lib/chronicle/read_models.ex`):
|
|
387
356
|
|
|
@@ -402,54 +371,6 @@ Querying (`lib/chronicle/read_models.ex`):
|
|
|
402
371
|
is the Elixir analogue of the other clients' observable APIs, and it means the
|
|
403
372
|
receiving process must have a `handle_info` for both.
|
|
404
373
|
|
|
405
|
-
## Connecting is asynchronous — wait for the lifecycle
|
|
406
|
-
|
|
407
|
-
The client connects in the background. `Chronicle.Connections.Lifecycle`
|
|
408
|
-
broadcasts `{:chronicle_lifecycle, phase, connection_id}` with three phases
|
|
409
|
-
(`lib/chronicle/connections/lifecycle.ex:54`):
|
|
410
|
-
|
|
411
|
-
| Phase | Meaning |
|
|
412
|
-
| --- | --- |
|
|
413
|
-
| `:disconnected` | no live session with the kernel |
|
|
414
|
-
| `:connected` | the session handshake completed |
|
|
415
|
-
| `:registered` | the registration coordinator registered the base artifacts |
|
|
416
|
-
|
|
417
|
-
**Wait for `:registered`, never merely `:connected`** — the module's own docs say
|
|
418
|
-
so at `:27-29`, because reducers and reactors are not attached until registration
|
|
419
|
-
finishes.
|
|
420
|
-
|
|
421
|
-
```elixir
|
|
422
|
-
config = Chronicle.Client.config()
|
|
423
|
-
|
|
424
|
-
case Chronicle.Connections.Lifecycle.wait_until(config.lifecycle, :registered, 30_000) do
|
|
425
|
-
:ok -> :ok
|
|
426
|
-
{:error, :timeout} -> # decide what a not-yet-registered client means for you
|
|
427
|
-
end
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
`wait_until(lifecycle, target_phase, timeout \\ 30_000)` is at `:141`.
|
|
431
|
-
`subscribe/1` (`:90`) returns the current phase **and** sends it as a message,
|
|
432
|
-
which closes the subscribe-after-transition race; `phase/1` (`:98`) is the plain
|
|
433
|
-
read.
|
|
434
|
-
|
|
435
|
-
## Keepalive — the failure mode is silence
|
|
436
|
-
|
|
437
|
-
The contract is spelled out in `lib/chronicle/connections/keep_alive.ex:7-17`:
|
|
438
|
-
the kernel pushes a `ConnectionKeepAlive` down the `Connect` server stream once
|
|
439
|
-
per second, and for each one **the client must call back the separate unary
|
|
440
|
-
`ConnectionKeepAlive` RPC** (`answer/2` at `:56`). A client that only consumes the
|
|
441
|
-
stream is evicted once the kernel's `LastSeen` falls more than five seconds
|
|
442
|
-
behind, and the kernel then unsubscribes its observers.
|
|
443
|
-
|
|
444
|
-
The consequence is stated in that same comment and is worth carrying into any
|
|
445
|
-
diagnosis: **reactors and reducers go quiet while the `Connect` stream stays open
|
|
446
|
-
and every append keeps working.** Nothing raises. If observers stop firing but
|
|
447
|
-
appends succeed, look at the connection before you look at the observer.
|
|
448
|
-
|
|
449
|
-
Reconnect is exponential backoff — `:retry_attempts` 5, `:reconnect_base_delay`
|
|
450
|
-
1000 ms, `:reconnect_max_delay` 10000 ms — re-resolving addresses on every
|
|
451
|
-
attempt.
|
|
452
|
-
|
|
453
374
|
## Idioms worth knowing
|
|
454
375
|
|
|
455
376
|
- **Process-scoped context.** Correlation id, identity, and causation are held per
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Append API
|
|
2
|
+
|
|
3
|
+
## Append functions and options
|
|
4
|
+
|
|
5
|
+
| Function | Arity | Line in `event_log.ex` |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| `append/3` | `(event_source_id, event, opts)` | `:99` |
|
|
8
|
+
| `append_many/3` | `(event_source_id, events, opts)` | `:120` |
|
|
9
|
+
| `append_many_for_event_sources/2` | `(events, opts)` | `:155` |
|
|
10
|
+
| `append_and_wait_for_completion/3` | returns `{:ok, %{success: _, failed_partitions: _}}` | `:215` |
|
|
11
|
+
| `get_for_event_source/2` | | `:326` |
|
|
12
|
+
| `get_from_sequence_number/2` | | `:369` |
|
|
13
|
+
| `get_tail_sequence_number/2` | | `:408` |
|
|
14
|
+
|
|
15
|
+
Append options (`event_log.ex:79-94`, plus `:occurred` read at `:720`): `:client`, `:namespace`,
|
|
16
|
+
`:event_sequence_id` (default `"event-log"`), `:event_source_type` (default
|
|
17
|
+
`"Default"`), `:event_stream_type` (default **`"All"`**), `:event_stream_id`
|
|
18
|
+
(default `"Default"`), `:tags`, `:subject`, `:correlation_id`, `:identity`,
|
|
19
|
+
`:causation`, `:concurrency_scope`, `:occurred`.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Variants
|
|
2
|
+
|
|
3
|
+
## Variants — mutually exclusive read models for one entity's lifecycle
|
|
4
|
+
|
|
5
|
+
> Requires `cratis_chronicle` `3.4.0` or later — newer than this skill's
|
|
6
|
+
> `3.1.0` baseline (`lib/chronicle/projections/variant_reclassifier.ex` and
|
|
7
|
+
> siblings). Reverify before claiming support; take the version from hex.pm.
|
|
8
|
+
|
|
9
|
+
Some entities do not have one shape for their whole lifetime — a work item is a
|
|
10
|
+
backlog entry until a pull request exists for it, then it is a pull request
|
|
11
|
+
until it merges. `variant_of/2` and `enters_on/1,2` are macros imported by
|
|
12
|
+
**both** `use Chronicle.ReadModels.ReadModel` and
|
|
13
|
+
`use Chronicle.Projections.Projection`, so the model-bound and declarative
|
|
14
|
+
paths declare a variant identically:
|
|
15
|
+
|
|
16
|
+
```elixir
|
|
17
|
+
defmodule MyApp.ReadModels.WorkItem do
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
defmodule MyApp.ReadModels.BacklogItem do
|
|
21
|
+
use Chronicle.ReadModels.ReadModel
|
|
22
|
+
defstruct id: nil, title: nil
|
|
23
|
+
|
|
24
|
+
variant_of MyApp.ReadModels.WorkItem, key: :id
|
|
25
|
+
enters_on MyApp.Events.IssueCreated
|
|
26
|
+
|
|
27
|
+
from MyApp.Events.IssueCreated, set: [id: :event_source_id, title: :title]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
defmodule MyApp.ReadModels.PullRequestItem do
|
|
31
|
+
use Chronicle.ReadModels.ReadModel
|
|
32
|
+
defstruct id: nil, pull_request_url: nil, build_status: nil
|
|
33
|
+
|
|
34
|
+
variant_of MyApp.ReadModels.WorkItem, key: :id
|
|
35
|
+
enters_on MyApp.Events.PullRequestCreated
|
|
36
|
+
|
|
37
|
+
from MyApp.Events.PullRequestCreated,
|
|
38
|
+
set: [id: :event_source_id, pull_request_url: :pull_request_url]
|
|
39
|
+
|
|
40
|
+
# not the entering event -> automatically reclassified into an update-only join
|
|
41
|
+
from MyApp.Events.BuildCompleted, set: [build_status: :build_status]
|
|
42
|
+
end
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`variant_of/2` takes `:key` — **required** — the field on this variant that
|
|
46
|
+
carries the shared identity. `enters_on/1,2` is repeatable and its own `:key`
|
|
47
|
+
option names an *event* property (defaults to `:event_source_id`); every
|
|
48
|
+
`from`/`join` this variant declares for a non-entering event, whether declared
|
|
49
|
+
locally or merged from a shared handler, is automatically reclassified into an
|
|
50
|
+
update-only join keyed on `variant_of`'s `:key`.
|
|
51
|
+
|
|
52
|
+
A mapping shared across every variant of an identity is a
|
|
53
|
+
`Chronicle.Projections.GlobalHandler`, never registered as a projection on its
|
|
54
|
+
own:
|
|
55
|
+
|
|
56
|
+
```elixir
|
|
57
|
+
defmodule MyApp.Projections.WorkItemTitleHandler do
|
|
58
|
+
use Chronicle.Projections.GlobalHandler, identity: MyApp.ReadModels.WorkItem
|
|
59
|
+
|
|
60
|
+
from MyApp.Events.TitleChanged, set: [title: :title]
|
|
61
|
+
end
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Register it explicitly with `global_handlers: [...]` on `Chronicle.Client`, or
|
|
65
|
+
let `:otp_app` auto-discovery find it (modules exporting
|
|
66
|
+
`__chronicle_global_handler__/1`). A mapping that targets a field some variant
|
|
67
|
+
lacks raises `Chronicle.Projections.GlobalHandlerPropertyNotOnVariant` at
|
|
68
|
+
registration, not a silently skipped mapping.
|
|
69
|
+
|
|
70
|
+
**A variant with no `enters_on` raises
|
|
71
|
+
`Chronicle.Projections.VariantMustDeclareEntersOnEvent`** at registration — a
|
|
72
|
+
variant that could never be entered could never be written to at all, since
|
|
73
|
+
every other handler on it is update-only.
|
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
530
|
-
|
|
531
|
-
|
|
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
|