@cratis/pi 7.189.2 → 7.189.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package/corpus/harnesses/copilot/instructions/elixir.instructions.md +26 -4
- package/package/corpus/rules/elixir.md +26 -4
- package/package/corpus/skills/cratis-arc-elixir/SKILL.md +22 -12
- package/package/corpus/skills/cratis-arc-elixir/references/availability.md +14 -14
- package/package/corpus/skills/cratis-arc-elixir/references/commands-and-queries.md +8 -8
- package/package/corpus/skills/cratis-arc-elixir/references/event-model.md +79 -0
- package/package/corpus/skills/cratis-arc-elixir/references/hosting-and-testing.md +10 -10
- package/package/corpus/skills/cratis-arc-elixir/references/mongodb.md +9 -9
- package/package/corpus/skills/cratis-arc-elixir/references/observable-queries-and-hubs.md +5 -5
- package/package/corpus/skills/cratis-arc-elixir/references/pitfalls.md +13 -2
- package/package/corpus/skills/cratis-arc-elixir/references/product-sources.md +3 -2
- package/package/corpus/skills/cratis-arc-elixir/references/tenancy-and-identity.md +7 -7
- package/package/corpus/skills/cratis-arc-elixir/verification.json +14 -1
- package/package/corpus/skills/cratis-chronicle-client-elixir/SKILL.md +43 -43
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/append-api.md +4 -4
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/captures.md +5 -5
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/client-options.md +5 -5
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/compliance.md +6 -6
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/connections.md +3 -3
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/constraints.md +6 -6
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/decision-reads.md +12 -12
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/discovery-and-generations.md +10 -10
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/event-sources.md +7 -7
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/graphs.md +6 -6
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/idioms-and-inspection.md +5 -5
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/observability.md +2 -2
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/patterns.md +6 -6
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/pitfalls.md +4 -4
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/projections.md +4 -4
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/reactor-example.md +2 -2
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/read-models.md +7 -7
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/testing.md +15 -15
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/upgrading.md +19 -3
- package/package/corpus/skills/cratis-chronicle-client-elixir/references/variants.md +9 -9
- package/package/corpus/skills/cratis-chronicle-client-elixir/verification.json +3 -3
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ license: MIT
|
|
|
10
10
|
# The Chronicle client for Elixir
|
|
11
11
|
|
|
12
12
|
`cratis_chronicle` is a **standalone client SDK**. It is a library, not a
|
|
13
|
-
framework: it starts no supervision tree of its own, you add `Chronicle.Client`
|
|
13
|
+
framework: it starts no supervision tree of its own, you add `Cratis.Chronicle.Client`
|
|
14
14
|
to yours, and everything after that is ordinary OTP.
|
|
15
15
|
|
|
16
16
|
## Verified product sources
|
|
@@ -19,9 +19,9 @@ Source: `Cratis/Chronicle.Elixir` (Hex package `cratis_chronicle`). Source paths
|
|
|
19
19
|
|
|
20
20
|
Read [references/upgrading.md](references/upgrading.md) when moving an application from an older client. Requires Elixir `~> 1.18`; read [references/product-sources.md](references/product-sources.md) for the package and contracts dependency facts.
|
|
21
21
|
|
|
22
|
-
> **A git tag is not a Hex release.** `mix deps.get` fetches only published versions, and the repository's `VERSION` file is a build-time placeholder: never quote it. Use namespaced modules (`Chronicle.Events.EventType`, not `Chronicle.EventType`); older READMEs got this wrong. Maintained snippets live in `Documentation/client-snippets/`.
|
|
22
|
+
> **A git tag is not a Hex release.** `mix deps.get` fetches only published versions, and the repository's `VERSION` file is a build-time placeholder: never quote it. Use namespaced modules (`Cratis.Chronicle.Events.EventType`, not `Cratis.Chronicle.EventType`); older READMEs got this wrong. Maintained snippets live in `Documentation/client-snippets/`.
|
|
23
23
|
|
|
24
|
-
`Chronicle.Concept` (`use Chronicle.Concept, type: :string`) is the preferred way to classify a personal value once, mirroring `ConceptAs<T>`; it requires `cratis_chronicle` 3.0.0, and an older client annotates fields with `pii/1,2`.
|
|
24
|
+
`Cratis.Chronicle.Concept` (`use Cratis.Chronicle.Concept, type: :string`) is the preferred way to classify a personal value once, mirroring `ConceptAs<T>`; it requires `cratis_chronicle` 3.0.0, and an older client annotates fields with `pii/1,2`.
|
|
25
25
|
|
|
26
26
|
## Adding it
|
|
27
27
|
|
|
@@ -29,7 +29,7 @@ Read [references/upgrading.md](references/upgrading.md) when moving an applicati
|
|
|
29
29
|
# mix.exs
|
|
30
30
|
defp deps do
|
|
31
31
|
[
|
|
32
|
-
{:cratis_chronicle, "~>
|
|
32
|
+
{:cratis_chronicle, "~> 4.0"}
|
|
33
33
|
]
|
|
34
34
|
end
|
|
35
35
|
```
|
|
@@ -40,7 +40,7 @@ The library declares `extra_applications: [:logger, :inets, :ssl]` and **no
|
|
|
40
40
|
|
|
41
41
|
## Starting the client
|
|
42
42
|
|
|
43
|
-
`Chronicle.Client` is a `Supervisor` (`lib/chronicle/client.ex`) with
|
|
43
|
+
`Cratis.Chronicle.Client` is a `Supervisor` (`lib/cratis/chronicle/client.ex`) with
|
|
44
44
|
`start_link(opts \\ [])`. Put it in your application's tree — this is
|
|
45
45
|
the CI-validated snippet from
|
|
46
46
|
`Documentation/client-snippets/get-started/console/connect.md`:
|
|
@@ -52,8 +52,8 @@ defmodule MyApp.Application do
|
|
|
52
52
|
@impl true
|
|
53
53
|
def start(_type, _args) do
|
|
54
54
|
children = [
|
|
55
|
-
{Chronicle.Client,
|
|
56
|
-
connection_string: Chronicle.Connections.ConnectionString.development(),
|
|
55
|
+
{Cratis.Chronicle.Client,
|
|
56
|
+
connection_string: Cratis.Chronicle.Connections.ConnectionString.development(),
|
|
57
57
|
event_store: "quickstart",
|
|
58
58
|
otp_app: :my_app}
|
|
59
59
|
]
|
|
@@ -65,13 +65,13 @@ end
|
|
|
65
65
|
|
|
66
66
|
### Options, supervision and multiple clients
|
|
67
67
|
|
|
68
|
-
Read [references/client-options.md](references/client-options.md) when setting `Chronicle.Client` options (set `:otp_app`), its supervision tree, or multiple clients.
|
|
68
|
+
Read [references/client-options.md](references/client-options.md) when setting `Cratis.Chronicle.Client` options (set `:otp_app`), its supervision tree, or multiple clients.
|
|
69
69
|
|
|
70
70
|
## Connecting is asynchronous — wait for the lifecycle
|
|
71
71
|
|
|
72
|
-
The client connects in the background. `Chronicle.Connections.Lifecycle`
|
|
72
|
+
The client connects in the background. `Cratis.Chronicle.Connections.Lifecycle`
|
|
73
73
|
broadcasts `{:chronicle_lifecycle, phase, connection_id}` with three phases
|
|
74
|
-
(`lib/chronicle/connections/lifecycle.ex`):
|
|
74
|
+
(`lib/cratis/chronicle/connections/lifecycle.ex`):
|
|
75
75
|
|
|
76
76
|
| Phase | Meaning |
|
|
77
77
|
| --- | --- |
|
|
@@ -84,9 +84,9 @@ so, because reducers and reactors are not attached until registration
|
|
|
84
84
|
finishes.
|
|
85
85
|
|
|
86
86
|
```elixir
|
|
87
|
-
alias Chronicle.Connections.Lifecycle
|
|
87
|
+
alias Cratis.Chronicle.Connections.Lifecycle
|
|
88
88
|
|
|
89
|
-
case Lifecycle.wait_until(Lifecycle.name_for(Chronicle.Client), :registered, 30_000) do
|
|
89
|
+
case Lifecycle.wait_until(Lifecycle.name_for(Cratis.Chronicle.Client), :registered, 30_000) do
|
|
90
90
|
:ok -> :ready
|
|
91
91
|
{:error, :timeout} -> :not_ready
|
|
92
92
|
end
|
|
@@ -129,14 +129,14 @@ Read [references/connections.md](references/connections.md) when configuring con
|
|
|
129
129
|
defmodule MyApp.Events.FundsDeposited do
|
|
130
130
|
@moduledoc "Funds were deposited into an account."
|
|
131
131
|
|
|
132
|
-
use Chronicle.Events.EventType, id: "funds-deposited"
|
|
132
|
+
use Cratis.Chronicle.Events.EventType, id: "funds-deposited"
|
|
133
133
|
|
|
134
134
|
defstruct amount: 0, active: false, title: ""
|
|
135
135
|
end
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
`use Chronicle.Events.EventType` takes `:id` through `Keyword.fetch!`
|
|
139
|
-
(`lib/chronicle/events/event_type.ex`) — **the id is required**, unlike the
|
|
138
|
+
`use Cratis.Chronicle.Events.EventType` takes `:id` through `Keyword.fetch!`
|
|
139
|
+
(`lib/cratis/chronicle/events/event_type.ex`) — **the id is required**, unlike the
|
|
140
140
|
.NET, Kotlin, and TypeScript clients where it defaults to the type name. Give it
|
|
141
141
|
a stable, kebab-case string and never change it. `:generation` defaults to `1`.
|
|
142
142
|
|
|
@@ -146,34 +146,34 @@ list element schemas use the first default element. Nested structs and concepts
|
|
|
146
146
|
are descended into (`schemas/json_schema_generator.ex`).
|
|
147
147
|
|
|
148
148
|
The macro imports `unique/1,2`, `unique_event_type/0,1`, `remove_constraint/1,2`,
|
|
149
|
-
`closes_stream/1`, `Chronicle.Compliance.pii/1,2` and
|
|
150
|
-
`Chronicle.Confidentiality.encrypted/1,2,3`; the accumulating attributes
|
|
149
|
+
`closes_stream/1`, `Cratis.Chronicle.Compliance.pii/1,2` and
|
|
150
|
+
`Cratis.Chronicle.Confidentiality.encrypted/1,2,3`; the accumulating attributes
|
|
151
151
|
`@unique`, `@unique_event_type`, `@remove_constraint` also work. Read
|
|
152
152
|
[references/constraints.md](references/constraints.md) for their options.
|
|
153
153
|
|
|
154
154
|
**Only top-level event keys are camelCased.** `encode_event/1` transforms them
|
|
155
155
|
before `Jason.encode!` (`event_sequences/event_log.ex`); nested keys are
|
|
156
156
|
not transformed. Event structs get no `Jason.Encoder` implementation;
|
|
157
|
-
`Chronicle.Concept` does, encoding its wrapped value.
|
|
157
|
+
`Cratis.Chronicle.Concept` does, encoding its wrapped value.
|
|
158
158
|
|
|
159
159
|
Read [references/compliance.md](references/compliance.md) when defining personal data, data subjects, concepts or encrypted operational secrets. `pii` and `encrypted` are not interchangeable and cannot mark the same leaf.
|
|
160
160
|
|
|
161
161
|
Schema evolution is
|
|
162
|
-
`use Chronicle.Events.Migration, from: {Mod, generation: n}, to: {Mod, generation: n + 1}`
|
|
162
|
+
`use Cratis.Chronicle.Events.Migration, from: {Mod, generation: n}, to: {Mod, generation: n + 1}`
|
|
163
163
|
with `upcast/1` and `downcast/1`; the generations must be exactly one apart. Mark
|
|
164
164
|
the older module with `generation_for:`, not a second `:id`.
|
|
165
165
|
|
|
166
166
|
## Appending
|
|
167
167
|
|
|
168
168
|
```elixir
|
|
169
|
-
case Chronicle.append("account-1", %MyApp.Events.FundsDeposited{amount: 50}) do
|
|
169
|
+
case Cratis.Chronicle.append("account-1", %MyApp.Events.FundsDeposited{amount: 50}) do
|
|
170
170
|
:ok -> :ok
|
|
171
171
|
{:error, {:constraint_violations, violations}} -> {:rejected, violations}
|
|
172
172
|
{:error, reason} -> {:error, reason}
|
|
173
173
|
end
|
|
174
174
|
```
|
|
175
175
|
|
|
176
|
-
`Chronicle.append/3` delegates to `Chronicle.EventSequences.EventLog`.
|
|
176
|
+
`Cratis.Chronicle.append/3` delegates to `Cratis.Chronicle.EventSequences.EventLog`.
|
|
177
177
|
**The event source id comes first, the event second.** The return is a bare
|
|
178
178
|
`:ok`, carrying no sequence number; use `append_with_result/3` or
|
|
179
179
|
`append_and_wait_for_completion/3` when you need the outcome.
|
|
@@ -187,15 +187,15 @@ Failed appends return `{:error, reason}`: `{:constraint_violations, violations}`
|
|
|
187
187
|
`{:unknown_event_type, module}`, `:not_connected`, and `{:incompatible_server, response}`
|
|
188
188
|
from the first append's compatibility preflight per channel. Pair the kernel and
|
|
189
189
|
installed contracts; do not blindly retry a timed-out write. **Match on them**: a
|
|
190
|
-
bare `:ok = Chronicle.append(...)` raises a `MatchError` on a violation, fine in a
|
|
190
|
+
bare `:ok = Cratis.Chronicle.append(...)` raises a `MatchError` on a violation, fine in a
|
|
191
191
|
script and wrong in a GenServer.
|
|
192
192
|
|
|
193
193
|
Read [references/event-sources.md](references/event-sources.md) when declaring named event sources/streams, deriving concurrency scopes or routing mixed-source batches; definitions have client and kernel requirements stated there.
|
|
194
194
|
|
|
195
|
-
A unit of work is a process: `Chronicle.begin_unit_of_work/1` starts an `Agent`;
|
|
195
|
+
A unit of work is a process: `Cratis.Chronicle.begin_unit_of_work/1` starts an `Agent`;
|
|
196
196
|
while one is current for the calling process, `append`/`append_many` buffer until
|
|
197
197
|
`UnitOfWork.commit/1` (`:ok | {:error, reason}`) or `rollback/1`.
|
|
198
|
-
`Chronicle.with_unit_of_work(fun, opts)` commits on return and raises on commit
|
|
198
|
+
`Cratis.Chronicle.with_unit_of_work(fun, opts)` commits on return and raises on commit
|
|
199
199
|
failure.
|
|
200
200
|
|
|
201
201
|
## Observing
|
|
@@ -204,7 +204,7 @@ failure.
|
|
|
204
204
|
|
|
205
205
|
Requires Chronicle.Elixir 3.14.0, contracts 19.70 and kernel 19.70.0 for start_at_tail; check `mix deps` and the server version, or retain initial catch-up until upgraded.
|
|
206
206
|
|
|
207
|
-
`use Chronicle.Reactors.Reactor, start_at_tail: true` skips history only on first
|
|
207
|
+
`use Cratis.Chronicle.Reactors.Reactor, start_at_tail: true` skips history only on first
|
|
208
208
|
registration; an existing reactor keeps its position. `once_only` does not skip
|
|
209
209
|
initial catch-up. An older server ignores the flag and catches up from the beginning.
|
|
210
210
|
|
|
@@ -222,14 +222,14 @@ Read [references/reactor-example.md](references/reactor-example.md) when you nee
|
|
|
222
222
|
- Optional replay callbacks: `on_replay_begin/0`, `on_replay_end/0`,
|
|
223
223
|
`on_partition_replay_begin/1`, `on_partition_replay_end/1`.
|
|
224
224
|
|
|
225
|
-
**The context is a `Chronicle.Events.EventContext` struct** (requires 3.11.0; a
|
|
225
|
+
**The context is a `Cratis.Chronicle.Events.EventContext` struct** (requires 3.11.0; a
|
|
226
226
|
bare map before). Pattern match on keys or use `context.caused_by`. It carries
|
|
227
227
|
`event_source_id`, `sequence_number`, `occurred`, `event_source` (the registered
|
|
228
228
|
source name or `nil`), `event_store`, `namespace`, `correlation_id`, `caused_by`,
|
|
229
229
|
`causation`, `tags`, `subject`, `appended_generation`, `replaying?` and, for
|
|
230
230
|
reactors only, `delivery_id` (stable across replay and failed-partition
|
|
231
231
|
recovery; key a receipt on it). Reducers get the same struct with
|
|
232
|
-
`observation_state` set (`lib/chronicle/events/event_context.ex`).
|
|
232
|
+
`observation_state` set (`lib/cratis/chronicle/events/event_context.ex`).
|
|
233
233
|
|
|
234
234
|
### Read models and projections
|
|
235
235
|
|
|
@@ -246,29 +246,29 @@ Read [references/projections.md](references/projections.md) when choosing `passi
|
|
|
246
246
|
> `MyApp.ReadModels.Account` registers as `"Account"`, so two read models with the
|
|
247
247
|
> same final segment collide. Pass `id:` to disambiguate.
|
|
248
248
|
|
|
249
|
-
A standalone projection is `use Chronicle.Projections.Projection, model: Mod`
|
|
249
|
+
A standalone projection is `use Cratis.Chronicle.Projections.Projection, model: Mod`
|
|
250
250
|
(`:model` is required); a reducer is
|
|
251
|
-
`use Chronicle.Reducers.Reducer, model: Mod` with
|
|
251
|
+
`use Cratis.Chronicle.Reducers.Reducer, model: Mod` with
|
|
252
252
|
`reduce(event, model_or_nil, context) :: struct()`. **Reducers run in your
|
|
253
253
|
process**, so the reduction is Elixir code you own.
|
|
254
254
|
|
|
255
255
|
#### Variants — mutually exclusive read models for one entity's lifecycle
|
|
256
256
|
|
|
257
|
-
Requires `cratis_chronicle` `3.4.0` or later. `variant_of/2` requires `:key`; a variant with no `enters_on` raises `Chronicle.Projections.VariantMustDeclareEntersOnEvent` at registration.
|
|
257
|
+
Requires `cratis_chronicle` `3.4.0` or later. `variant_of/2` requires `:key`; a variant with no `enters_on` raises `Cratis.Chronicle.Projections.VariantMustDeclareEntersOnEvent` at registration.
|
|
258
258
|
|
|
259
259
|
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`.
|
|
260
260
|
|
|
261
|
-
Querying (`lib/chronicle/read_models.ex`):
|
|
261
|
+
Querying (`lib/cratis/chronicle/read_models.ex`):
|
|
262
262
|
|
|
263
263
|
```elixir
|
|
264
|
-
{:ok, accounts} = Chronicle.all(MyApp.ReadModels.AccountBalance)
|
|
265
|
-
{:ok, account} = Chronicle.read_model(MyApp.ReadModels.AccountBalance, "account-1")
|
|
264
|
+
{:ok, accounts} = Cratis.Chronicle.all(MyApp.ReadModels.AccountBalance)
|
|
265
|
+
{:ok, account} = Cratis.Chronicle.read_model(MyApp.ReadModels.AccountBalance, "account-1")
|
|
266
266
|
```
|
|
267
267
|
|
|
268
|
-
`Chronicle.read_model/3` returns `{:ok, struct() | nil} | {:error, term()}`; `nil`
|
|
268
|
+
`Cratis.Chronicle.read_model/3` returns `{:ok, struct() | nil} | {:error, term()}`; `nil`
|
|
269
269
|
means absent **or not projected yet**.
|
|
270
270
|
|
|
271
|
-
Use `Chronicle.ReadModels.query(MyApp.ReadModels.AccountBalance, page: 0)` for paging:
|
|
271
|
+
Use `Cratis.Chronicle.ReadModels.query(MyApp.ReadModels.AccountBalance, page: 0)` for paging:
|
|
272
272
|
`:page` is zero-based (default `0`), `:page_size` defaults to `50`, and
|
|
273
273
|
`:occurrence` selects a replay container. **Page 1 is the second page**. `ReadModels.snapshots/3`,
|
|
274
274
|
`occurrences/2`, and `definitions/1` expose history, replay containers, and
|
|
@@ -278,11 +278,11 @@ registered definitions.
|
|
|
278
278
|
|
|
279
279
|
#### Graph projections — `node` and `edge`
|
|
280
280
|
|
|
281
|
-
A graph is a module with `use Chronicle.Graphs.Graph, id: "Organization"`; its nodes
|
|
282
|
-
and edges are structs with `use Chronicle.Graphs.Node` and `use Chronicle.Graphs.Edge,
|
|
281
|
+
A graph is a module with `use Cratis.Chronicle.Graphs.Graph, id: "Organization"`; its nodes
|
|
282
|
+
and edges are structs with `use Cratis.Chronicle.Graphs.Node` and `use Cratis.Chronicle.Graphs.Edge,
|
|
283
283
|
type: "MEMBER_OF"`. Inside the graph, `node Mod, key: :field do ... end` and
|
|
284
284
|
`edge Mod, source: A, target: B do ... end` hold `from/2` and `removed_with/2`
|
|
285
|
-
(`detach: true` on a node). Register it with `graphs: [Mod]` on `Chronicle.Client`.
|
|
285
|
+
(`detach: true` on a node). Register it with `graphs: [Mod]` on `Cratis.Chronicle.Client`.
|
|
286
286
|
Requires cratis_chronicle 3.20.0 (check `mix deps`). Read
|
|
287
287
|
[references/graphs.md](references/graphs.md) for the options, counters, edge identity,
|
|
288
288
|
compiler checks and sink choice. Pin `id:`; renaming it registers a different projection.
|
|
@@ -291,12 +291,12 @@ compiler checks and sink choice. Pin `id:`; renaming it registers a different pr
|
|
|
291
291
|
|
|
292
292
|
Read the reference that matches the task:
|
|
293
293
|
|
|
294
|
-
- [references/decision-reads.md](references/decision-reads.md) when an append depends on state a concurrent append could change: `Chronicle.decide/2`, `DecisionReads`, `ConcurrencyScope` builders, the optimistic default.
|
|
295
|
-
- [references/testing.md](references/testing.md) when writing specs: `Chronicle.Testing.Case`, assertions, the in-memory kernel's limits.
|
|
294
|
+
- [references/decision-reads.md](references/decision-reads.md) when an append depends on state a concurrent append could change: `Cratis.Chronicle.decide/2`, `DecisionReads`, `ConcurrencyScope` builders, the optimistic default.
|
|
295
|
+
- [references/testing.md](references/testing.md) when writing specs: `Cratis.Chronicle.Testing.Case`, assertions, the in-memory kernel's limits.
|
|
296
296
|
- [references/constraints.md](references/constraints.md) when declaring uniqueness, standalone constraint modules, `remove_constraint/2`, violation details or closing events.
|
|
297
297
|
- [references/discovery-and-generations.md](references/discovery-and-generations.md) when pinning ids, setting `:drift_policy`, running `mix chronicle.discover`, or handling older event generations.
|
|
298
298
|
- [references/captures.md](references/captures.md) when turning external API, webhook or other-store data into events.
|
|
299
|
-
- [references/observability.md](references/observability.md) and [references/patterns.md](references/patterns.md) for OpenTelemetry/`:telemetry` and `Chronicle.Patterns`.
|
|
299
|
+
- [references/observability.md](references/observability.md) and [references/patterns.md](references/patterns.md) for OpenTelemetry/`:telemetry` and `Cratis.Chronicle.Patterns`.
|
|
300
300
|
|
|
301
301
|
## Idioms and operational inspection
|
|
302
302
|
|
|
@@ -311,12 +311,12 @@ Read [references/pitfalls.md](references/pitfalls.md) when troubleshooting disco
|
|
|
311
311
|
- Elixir 1.18+ and `mix deps.get` resolve the intended published client; contracts
|
|
312
312
|
and kernel are compatible (event source definitions have their own client and kernel requirements; see the event sources reference).
|
|
313
313
|
- Local development uses `ConnectionString.development()` or explicit credentials.
|
|
314
|
-
- `Chronicle.Client` is in the supervision tree with an explicit `:otp_app`, and
|
|
314
|
+
- `Cratis.Chronicle.Client` is in the supervision tree with an explicit `:otp_app`, and
|
|
315
315
|
the tree starts clean.
|
|
316
316
|
- The lifecycle reaches `:registered` before the application claims readiness.
|
|
317
317
|
- A production connection string sets `skipTlsValidation=false`.
|
|
318
318
|
- Every event type module passes an explicit, stable `id:`.
|
|
319
|
-
- Every `Chronicle.append/3` call site handles `{:error, _}` as well as `:ok`.
|
|
319
|
+
- Every `Cratis.Chronicle.append/3` call site handles `{:error, _}` as well as `:ok`.
|
|
320
320
|
- Every reactor's `@handles` list matches the clauses of its `handle/2`.
|
|
321
321
|
- Reactors, reducers and projections that must survive a rename pin their `:id`.
|
|
322
322
|
- Read model module names have distinct final segments, or explicit ids.
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
# Append API
|
|
5
5
|
|
|
6
|
-
Source: `Cratis/Chronicle.Elixir`; paths below are under `Source/chronicle/lib/chronicle/`.
|
|
6
|
+
Source: `Cratis/Chronicle.Elixir`; paths below are under `Source/chronicle/lib/cratis/chronicle/`.
|
|
7
7
|
|
|
8
8
|
## Append functions and readers
|
|
9
9
|
|
|
10
|
-
| Function on `Chronicle.EventSequences.EventLog` | Arguments / result | Line in `event_log.ex` |
|
|
10
|
+
| Function on `Cratis.Chronicle.EventSequences.EventLog` | Arguments / result | Line in `event_log.ex` |
|
|
11
11
|
| --- | --- | --- |
|
|
12
12
|
| `append/3` | `(event_source_id, event, opts)` → `:ok \| {:error, reason}` | |
|
|
13
13
|
| `append_many/3` | `(event_source_id, events, opts)` → `:ok \| {:error, reason}` | |
|
|
@@ -45,6 +45,6 @@ Requires `cratis_chronicle` 3.13.0 for everything in this section.
|
|
|
45
45
|
|
|
46
46
|
- `append_with_result/3` and `append_many_with_result/3` return `{:ok, %AppendResult{sequence_number: _}}` (batch: every assigned number, in order) or `{:error, %AppendResult{}}` carrying `:constraint_violations` (each with `:constraint_name`, `:message`, `:event_type_id`, `:sequence_number`, `:details`), `:concurrency_violations` (`:event_source_id`, `:expected_sequence_number`, `:actual_sequence_number`) and `:errors`. Use them when you need the assigned sequence number or the structured reason; transport failures stay plain `{:error, reason}`. `AppendResult.wait_for_completion/2` waits for observers.
|
|
47
47
|
- `EventLog.prepare/2` serializes an event once into a `PreparedEvent` bound to the client, namespace and event sequence that prepared it; reuse it with `EventLog.append_prepared/3` and `Streams.verify_content/3`. Appending it through another client, namespace or sequence returns `{:error, :prepared_event_belongs_to_another_sequence}`. Single use is not enforced.
|
|
48
|
-
- **A struct that does not `use Chronicle.Events.EventType` returns `{:error, {:unknown_event_type, module}}`** from every append path, `prepare/2` and `Streams.verify_content/3`; it does not raise. Match it like any other error.
|
|
48
|
+
- **A struct that does not `use Cratis.Chronicle.Events.EventType` returns `{:error, {:unknown_event_type, module}}`** from every append path, `prepare/2` and `Streams.verify_content/3`; it does not raise. Match it like any other error.
|
|
49
49
|
- A payload over 4 MiB returns `{:error, {:payload_too_large, size, limit}}` before sending. Raise or disable the guard with `config :cratis_chronicle, max_payload_bytes: ...` (or `:infinity`) only when the kernel is configured for larger messages.
|
|
50
|
-
- Reads: `get_for_event_source/3` and `get_from_sequence_number/2` return raw wire events; pass `decode: true` for `Chronicle.Events.AppendedEvent` structs (`event: nil` and `:raw` for an unknown type, `redacted?: true` for a redacted event).
|
|
50
|
+
- Reads: `get_for_event_source/3` and `get_from_sequence_number/2` return raw wire events; pass `decode: true` for `Cratis.Chronicle.Events.AppendedEvent` structs (`event: nil` and `:raw` for an unknown type, `redacted?: true` for a redacted event).
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# Captures
|
|
5
5
|
|
|
6
|
-
Source: `Cratis/Chronicle.Elixir`: `Source/chronicle/lib/chronicle/captures.ex`, `captures/capture.ex`, `captures/registrar.ex`, and `Documentation/captures.md`.
|
|
6
|
+
Source: `Cratis/Chronicle.Elixir`: `Source/chronicle/lib/cratis/chronicle/captures.ex`, `captures/capture.ex`, `captures/registrar.ex`, and `Documentation/captures.md`.
|
|
7
7
|
|
|
8
8
|
Requires `cratis_chronicle` 3.13.0.
|
|
9
9
|
|
|
@@ -14,7 +14,7 @@ A capture turns data that arrives from outside the event log (an external API, a
|
|
|
14
14
|
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
15
15
|
|
|
16
16
|
defmodule MyApp.Captures.InvoiceCapture do
|
|
17
|
-
use Chronicle.Captures.Capture, name: "InvoiceCapture"
|
|
17
|
+
use Cratis.Chronicle.Captures.Capture, name: "InvoiceCapture"
|
|
18
18
|
|
|
19
19
|
api_source("InvoicingApi", route: "/invoices", poll: "10m")
|
|
20
20
|
|
|
@@ -32,12 +32,12 @@ end
|
|
|
32
32
|
- `when:` takes a property name, `{:any, [...]}`, `{:all, [...]}`, `{:transition, property, from, to}`, `:added`, `:removed`, or `{:expression, "template"}`. `set/2` maps a target field from `"$.path"` (payload) or `"$context.<property>"`.
|
|
33
33
|
- The DSL also has `nested` and `children` scopes, and a `map do` block with `rename`, `template`, `translate` and `split`.
|
|
34
34
|
|
|
35
|
-
**An appended event type's id must start with an uppercase letter and contain only letters, digits and underscores.** The kernel's CDL parser rejects hyphens, so `use Chronicle.Events.EventType, id: "InvoiceStatusChanged"` works as an `append` target and `id: "invoice-status-changed"` raises `ArgumentError` at compile time. This restriction does not apply to `events_source/1`.
|
|
35
|
+
**An appended event type's id must start with an uppercase letter and contain only letters, digits and underscores.** The kernel's CDL parser rejects hyphens, so `use Cratis.Chronicle.Events.EventType, id: "InvoiceStatusChanged"` works as an `append` target and `id: "invoice-status-changed"` raises `ArgumentError` at compile time. This restriction does not apply to `events_source/1`.
|
|
36
36
|
|
|
37
37
|
**The kernel's capture engine runs a subset of the language**: only `api` and `events` sources, and only root-level `append` rules. `map`, `nested` and `children` compile and validate but are not applied at runtime, and webhook sources cannot carry authentication.
|
|
38
38
|
|
|
39
39
|
## Registering and managing
|
|
40
40
|
|
|
41
|
-
Captures are discovered with `otp_app:` or listed in the client's `:captures` option. `Chronicle.Captures.Registrar` saves them at `:registered` and again on every reconnect. It skips a capture whose declaration already matches, and warns before saving over a **started** capture whose declaration changed, because saving stops it on the kernel.
|
|
41
|
+
Captures are discovered with `otp_app:` or listed in the client's `:captures` option. `Cratis.Chronicle.Captures.Registrar` saves them at `:registered` and again on every reconnect. It skips a capture whose declaration already matches, and warns before saving over a **started** capture whose declaration changed, because saving stops it on the kernel.
|
|
42
42
|
|
|
43
|
-
Manage directly with `Chronicle.Captures.register/1`, `start/1`, `stop/1`, `delete/1`, `list/0`, `validate/1` (a module or raw CDL text) and `captured_events/1`. `start`, `stop` and `delete` also accept a raw capture id; `delete` is destructive, so obtain authority for the specific capture first.
|
|
43
|
+
Manage directly with `Cratis.Chronicle.Captures.register/1`, `start/1`, `stop/1`, `delete/1`, `list/0`, `validate/1` (a module or raw CDL text) and `captured_events/1`. `start`, `stop` and `delete` also accept a raw capture id; `delete` is destructive, so obtain authority for the specific capture first.
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# Client options and supervision
|
|
2
2
|
|
|
3
|
-
This reference holds the `Chronicle.Client` child-spec options, its supervision tree and the multiple-client rule.
|
|
3
|
+
This reference holds the `Cratis.Chronicle.Client` child-spec options, its supervision tree and the multiple-client rule.
|
|
4
4
|
|
|
5
5
|
### Options
|
|
6
6
|
|
|
7
7
|
Pass **child-spec keyword options**. The client reads no application env;
|
|
8
|
-
your app must read its own configuration and pass it in (`lib/chronicle/client.ex`).
|
|
8
|
+
your app must read its own configuration and pass it in (`lib/cratis/chronicle/client.ex`).
|
|
9
9
|
|
|
10
10
|
| Option | Default |
|
|
11
11
|
| --- | --- |
|
|
12
|
-
| `:name` | `Chronicle.Client` |
|
|
12
|
+
| `:name` | `Cratis.Chronicle.Client` |
|
|
13
13
|
| `:connection_string` | `ConnectionString.default/0` |
|
|
14
14
|
| `:event_store` | `"default"` |
|
|
15
15
|
| `:namespace` | `"Default"` — capital D |
|
|
@@ -34,7 +34,7 @@ your app must read its own configuration and pass it in (`lib/chronicle/client.e
|
|
|
34
34
|
without it the client falls back to scanning every loaded module.
|
|
35
35
|
|
|
36
36
|
Configuration is stashed in `:persistent_term` and read back with
|
|
37
|
-
`Chronicle.Client.config/1` (`client.ex`). Its subset includes `event_sources`,
|
|
37
|
+
`Cratis.Chronicle.Client.config/1` (`client.ex`). Its subset includes `event_sources`,
|
|
38
38
|
but not `read_models`, `projections`, or `migrations`.
|
|
39
39
|
|
|
40
40
|
### The supervision tree
|
|
@@ -45,5 +45,5 @@ The connection, session and registration precede observers.
|
|
|
45
45
|
|
|
46
46
|
### Multiple clients
|
|
47
47
|
|
|
48
|
-
Pass `name:` to `Chronicle.Client` and `client:` to every API call. Every public
|
|
48
|
+
Pass `name:` to `Cratis.Chronicle.Client` and `client:` to every API call. Every public
|
|
49
49
|
function takes a `:client` option.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# Personal data, concepts and operational secrets
|
|
5
5
|
|
|
6
|
-
Source: `Cratis/Chronicle.Elixir`: `Source/chronicle/lib/chronicle/{concept,compliance,confidentiality}.ex`, `events/event_type.ex`, and `read_models/read_model.ex`.
|
|
6
|
+
Source: `Cratis/Chronicle.Elixir`: `Source/chronicle/lib/cratis/chronicle/{concept,compliance,confidentiality}.ex`, `events/event_type.ex`, and `read_models/read_model.ex`.
|
|
7
7
|
|
|
8
8
|
`pii/1,2` marks personal data for compliance encryption and right-to-erasure. `encrypted/1,2,3` marks non-personal operational secrets for separate confidentiality encryption with no compliance erasure operation. Its scopes are `:subject` (default), `:namespace`, `:global`. They are not interchangeable.
|
|
9
9
|
|
|
@@ -14,12 +14,12 @@ Requires `cratis_chronicle` 3.5.0 for `encrypted/1,2,3`.
|
|
|
14
14
|
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
15
15
|
|
|
16
16
|
defmodule MyApp.PersonName do
|
|
17
|
-
use Chronicle.Concept, type: :string
|
|
17
|
+
use Cratis.Chronicle.Concept, type: :string
|
|
18
18
|
pii("Legal name of the data subject")
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
defmodule MyApp.Events.PartnerIntegrationConfigured do
|
|
22
|
-
use Chronicle.Events.EventType, id: "partner-integration-configured"
|
|
22
|
+
use Cratis.Chronicle.Events.EventType, id: "partner-integration-configured"
|
|
23
23
|
defstruct contact_name: %MyApp.PersonName{}, email: "", api_key: ""
|
|
24
24
|
|
|
25
25
|
pii(:email, "Partner contact's email address")
|
|
@@ -27,8 +27,8 @@ defmodule MyApp.Events.PartnerIntegrationConfigured do
|
|
|
27
27
|
end
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
`Chronicle.Concept` is published on Hex; on a client without it, annotate fields with `pii/1,2`. `type:` is required: `:string`, `:integer`, `:float`, `:boolean`, `:uuid`. Typed concept defaults let the schema generator carry the wrapped type and classification onto every leaf that uses it. The concept's `Jason.Encoder` serializes only its wrapped value.
|
|
30
|
+
`Cratis.Chronicle.Concept` is published on Hex; on a client without it, annotate fields with `pii/1,2`. `type:` is required: `:string`, `:integer`, `:float`, `:boolean`, `:uuid`. Typed concept defaults let the schema generator carry the wrapped type and classification onto every leaf that uses it. The concept's `Jason.Encoder` serializes only its wrapped value.
|
|
31
31
|
|
|
32
|
-
On a concept use `pii/0,1` to classify its sole value, not the field-oriented `Chronicle.Compliance.pii/1,2`. Concept `encrypted/0,1,2` similarly marks that value. Neither classification is allowed on a concept with `event_source_id: true`; use a non-sensitive surrogate stream identity instead. Both classifications on one schema leaf raise `Chronicle.Confidentiality.PiiAndEncryptedCombinedNotSupported`.
|
|
32
|
+
On a concept use `pii/0,1` to classify its sole value, not the field-oriented `Cratis.Chronicle.Compliance.pii/1,2`. Concept `encrypted/0,1,2` similarly marks that value. Neither classification is allowed on a concept with `event_source_id: true`; use a non-sensitive surrogate stream identity instead. Both classifications on one schema leaf raise `Cratis.Chronicle.Confidentiality.PiiAndEncryptedCombinedNotSupported`.
|
|
33
33
|
|
|
34
|
-
For a read model whose subject is not its `:id`, declare `subject(:customer_id)` in the module using `Chronicle.ReadModels.ReadModel`. It identifies the natural person for PII release; there is only one subject declaration per module. `subject/1` is not imported by `EventType`; append-time `:subject` is an append option, not this read-model macro.
|
|
34
|
+
For a read model whose subject is not its `:id`, declare `subject(:customer_id)` in the module using `Cratis.Chronicle.ReadModels.ReadModel`. It identifies the natural person for PII release; there is only one subject declaration per module. `subject/1` is not imported by `EventType`; append-time `:subject` is an append option, not this read-model macro.
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
# Connections, trust and resilience
|
|
5
5
|
|
|
6
|
-
Source: `Cratis/Chronicle.Elixir`: `Source/chronicle/lib/chronicle/connections/{connection_string,connection,keep_alive,client_certificate,transport}.ex`, `registration/coordinator.ex`, and `Documentation/connections/{connection-strings,resilience,crash-reports}.md`.
|
|
6
|
+
Source: `Cratis/Chronicle.Elixir`: `Source/chronicle/lib/cratis/chronicle/connections/{connection_string,connection,keep_alive,client_certificate,transport}.ex`, `registration/coordinator.ex`, and `Documentation/connections/{connection-strings,resilience,crash-reports}.md`.
|
|
7
7
|
|
|
8
8
|
## Connection strings and authentication
|
|
9
9
|
|
|
10
|
-
`Chronicle.Connections.ConnectionString` accepts `chronicle://` and `chronicle+srv://`; the default port is `35000`. Multiple comma-separated hosts are resolved again on reconnect; SRV accepts only one host (`connection_string.ex`).
|
|
10
|
+
`Cratis.Chronicle.Connections.ConnectionString` accepts `chronicle://` and `chronicle+srv://`; the default port is `35000`. Multiple comma-separated hosts are resolved again on reconnect; SRV accepts only one host (`connection_string.ex`).
|
|
11
11
|
|
|
12
12
|
| Function | Line in `connection_string.ex` |
|
|
13
13
|
| --- | --- |
|
|
@@ -45,7 +45,7 @@ The client uses grpc 1.x and Mint 1.11+, owns its transport, and needs no `GRPC.
|
|
|
45
45
|
|
|
46
46
|
## Credential-safe logging is still necessary
|
|
47
47
|
|
|
48
|
-
Chronicle's own process status redacts credentials, but dependency crash reports can expose gRPC headers, bearer tokens, API keys and Mint HPACK tables. The client itself installs a primary Logger filter (`Chronicle.Connections.ResponseCrashRedaction`) when a connection starts, replacing the Mint response-process termination report, the one shape it can intercept generically, with a one-line notice (requires `cratis_chronicle` 3.13.0). The `ConnectionProcess` and `GRPC.Client.Connection` state can still print credentials, so before starting the client, install the primary Logger filter from the [client crash-report guide](https://github.com/Cratis/Chronicle.Elixir/blob/main/Documentation/connections/crash-reports.md). It matches `Elixir.GRPC.Client`, `Elixir.GRPC.Channel`, and `Elixir.Mint.` report content and replaces reports with a notice.
|
|
48
|
+
Chronicle's own process status redacts credentials, but dependency crash reports can expose gRPC headers, bearer tokens, API keys and Mint HPACK tables. The client itself installs a primary Logger filter (`Cratis.Chronicle.Connections.ResponseCrashRedaction`) when a connection starts, replacing the Mint response-process termination report, the one shape it can intercept generically, with a one-line notice (requires `cratis_chronicle` 3.13.0). The `ConnectionProcess` and `GRPC.Client.Connection` state can still print credentials, so before starting the client, install the primary Logger filter from the [client crash-report guide](https://github.com/Cratis/Chronicle.Elixir/blob/main/Documentation/connections/crash-reports.md). It matches `Elixir.GRPC.Client`, `Elixir.GRPC.Channel`, and `Elixir.Mint.` report content and replaces reports with a notice.
|
|
49
49
|
|
|
50
50
|
Keep `handle_sasl_reports: false`. This is a safety net, not a guarantee: plain warning strings carrying exit reasons are not covered, and filters do not survive a Logger restart. Restrict production log access and rotate any credential already exposed. Never log connection strings ([`secrets.md`](../../../rules/secrets.md)).
|
|
51
51
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# Constraints
|
|
5
5
|
|
|
6
|
-
Source: `Cratis/Chronicle.Elixir`: `Source/chronicle/lib/chronicle/events/event_type.ex`, `events/constraint.ex`, `events/constraint_violation.ex`, and `Documentation/constraints.md`.
|
|
6
|
+
Source: `Cratis/Chronicle.Elixir`: `Source/chronicle/lib/cratis/chronicle/events/event_type.ex`, `events/constraint.ex`, `events/constraint_violation.ex`, and `Documentation/constraints.md`.
|
|
7
7
|
|
|
8
8
|
Requires `cratis_chronicle` 3.13.0 for standalone constraint modules, `remove_constraint/2`, `:scope` and `ConstraintViolation.details/1`.
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ A constraint is checked by the kernel at append time; a violation returns `{:err
|
|
|
11
11
|
|
|
12
12
|
## On the event type
|
|
13
13
|
|
|
14
|
-
`unique/2`, `unique_event_type/1`, `remove_constraint/1,2` and `closes_stream/1` are imported by `use Chronicle.Events.EventType`.
|
|
14
|
+
`unique/2`, `unique_event_type/1`, `remove_constraint/1,2` and `closes_stream/1` are imported by `use Cratis.Chronicle.Events.EventType`.
|
|
15
15
|
|
|
16
16
|
| Option | Meaning |
|
|
17
17
|
| --- | --- |
|
|
@@ -30,14 +30,14 @@ In `:per_value` mode, `remove_constraint("Name")` releases every value the remov
|
|
|
30
30
|
|
|
31
31
|
## Standalone constraint modules
|
|
32
32
|
|
|
33
|
-
Use `use Chronicle.Events.Constraint` when one name spans several event types or lives apart from any one event type's module.
|
|
33
|
+
Use `use Cratis.Chronicle.Events.Constraint` when one name spans several event types or lives apart from any one event type's module.
|
|
34
34
|
|
|
35
35
|
```elixir
|
|
36
36
|
# Copyright (c) Cratis. All rights reserved.
|
|
37
37
|
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
38
38
|
|
|
39
39
|
defmodule MyApp.Constraints.UniqueEmail do
|
|
40
|
-
use Chronicle.Events.Constraint
|
|
40
|
+
use Cratis.Chronicle.Events.Constraint
|
|
41
41
|
|
|
42
42
|
unique name: "UniqueEmail" do
|
|
43
43
|
on MyApp.Events.UserRegistered, [:email]
|
|
@@ -54,10 +54,10 @@ end
|
|
|
54
54
|
|
|
55
55
|
## Violation details
|
|
56
56
|
|
|
57
|
-
`Chronicle.Events.ConstraintViolation.details(violation)` maps the kernel's detail keys to atoms: `:property_name`, `:property_value`, `:closed_by`, `:closed_at_sequence_number`; any other key stays a string. A PII property's `:property_value` is its **encrypted** form. Use it in a `:message` callback: `"A project named '#{ConstraintViolation.details(violation)[:property_value]}' already exists."`.
|
|
57
|
+
`Cratis.Chronicle.Events.ConstraintViolation.details(violation)` maps the kernel's detail keys to atoms: `:property_name`, `:property_value`, `:closed_by`, `:closed_at_sequence_number`; any other key stays a string. A PII property's `:property_value` is its **encrypted** form. Use it in a `:message` callback: `"A project named '#{ConstraintViolation.details(violation)[:property_value]}' already exists."`.
|
|
58
58
|
|
|
59
59
|
## Closing events
|
|
60
60
|
|
|
61
|
-
`closes_stream event_stream_id_from: :period, reopened_by: [MyApp.Events.PeriodReopened]` on an event type closes that stream scope when the event is appended; later events in the scope are refused. Options: `:dimensions`, `:event_stream_id_from`, `:reopened_by`, `:name`, `:event_sequences`; same-named declarations merge and must agree on dimensions. Registration closes nothing in history. Inspect closed scopes with `Chronicle.EventSequences.Streams`. The in-memory test kernel does not model `closes_stream`.
|
|
61
|
+
`closes_stream event_stream_id_from: :period, reopened_by: [MyApp.Events.PeriodReopened]` on an event type closes that stream scope when the event is appended; later events in the scope are refused. Options: `:dimensions`, `:event_stream_id_from`, `:reopened_by`, `:name`, `:event_sequences`; same-named declarations merge and must agree on dimensions. Registration closes nothing in history. Inspect closed scopes with `Cratis.Chronicle.EventSequences.Streams`. The in-memory test kernel does not model `closes_stream`.
|
|
62
62
|
|
|
63
63
|
Constraint drift is not detected: the kernel cannot list registered constraints.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
Requires Chronicle.Elixir 3.14.2 for the rejection/cleanup behavior below; check `mix deps`, or upgrade before relying on a rejected callback to discard buffered events.
|
|
7
7
|
|
|
8
|
-
A `Chronicle.decide/2` callback returning `{:error, reason}` rejects all buffered
|
|
8
|
+
A `Cratis.Chronicle.decide/2` callback returning `{:error, reason}` rejects all buffered
|
|
9
9
|
appends and returns that tuple unchanged.
|
|
10
10
|
Migrate matches on `{:ok, {:error, _}}` to `{:error, _}`. A failed commit rolls
|
|
11
11
|
back the unit of work, and both `decide/2` and `with_unit_of_work/2` stop their
|
|
@@ -13,32 +13,32 @@ unit-of-work process on return, so later appends from long-lived GenServers or
|
|
|
13
13
|
Phoenix connections are not trapped in a failed buffer. Spec the rejection and
|
|
14
14
|
failed-commit paths, not only successful decisions.
|
|
15
15
|
|
|
16
|
-
Source: `Cratis/Chronicle.Elixir`: `Source/chronicle/lib/chronicle/read_models/decision_reads.ex`, `decision_read_refused.ex`, `decision_conflict.ex`, `transactions/unit_of_work.ex`, and `Documentation/dynamic-consistency-boundary.md`.
|
|
16
|
+
Source: `Cratis/Chronicle.Elixir`: `Source/chronicle/lib/cratis/chronicle/read_models/decision_reads.ex`, `decision_read_refused.ex`, `decision_conflict.ex`, `transactions/unit_of_work.ex`, and `Documentation/dynamic-consistency-boundary.md`.
|
|
17
17
|
|
|
18
18
|
Requires `cratis_chronicle` 3.13.0.
|
|
19
19
|
|
|
20
|
-
Use a decision read when an append depends on state that a concurrent append could change (a seat can be booked once, a course has capacity). It folds a read model at a key in a fresh session and remembers the exact log position it stopped at; the commit is then rejected by the kernel if a matching event arrived since. An ordinary `Chronicle.read_model/3` followed by `append/3` is **not** a guard: it can silently act on stale state.
|
|
20
|
+
Use a decision read when an append depends on state that a concurrent append could change (a seat can be booked once, a course has capacity). It folds a read model at a key in a fresh session and remembers the exact log position it stopped at; the commit is then rejected by the kernel if a matching event arrived since. An ordinary `Cratis.Chronicle.read_model/3` followed by `append/3` is **not** a guard: it can silently act on stale state.
|
|
21
21
|
|
|
22
22
|
## Decide
|
|
23
23
|
|
|
24
24
|
```elixir
|
|
25
25
|
result =
|
|
26
|
-
Chronicle.decide(fn _unit_of_work ->
|
|
27
|
-
{:ok, read} = Chronicle.ReadModels.DecisionReads.get(MyApp.ReadModels.Seat, "seat-5")
|
|
26
|
+
Cratis.Chronicle.decide(fn _unit_of_work ->
|
|
27
|
+
{:ok, read} = Cratis.Chronicle.ReadModels.DecisionReads.get(MyApp.ReadModels.Seat, "seat-5")
|
|
28
28
|
|
|
29
29
|
if read.instance == nil do
|
|
30
|
-
Chronicle.EventSequences.EventLog.append("seat-5", %MyApp.Events.SeatBooked{by: "alice"})
|
|
30
|
+
Cratis.Chronicle.EventSequences.EventLog.append("seat-5", %MyApp.Events.SeatBooked{by: "alice"})
|
|
31
31
|
end
|
|
32
32
|
end)
|
|
33
33
|
|
|
34
34
|
case result do
|
|
35
35
|
{:ok, _} -> :booked
|
|
36
|
-
{:error, %Chronicle.ReadModels.DecisionConflict{}} -> :retry
|
|
36
|
+
{:error, %Cratis.Chronicle.ReadModels.DecisionConflict{}} -> :retry
|
|
37
37
|
{:error, reason} -> {:error, reason}
|
|
38
38
|
end
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
- `Chronicle.decide/2` runs the function in a unit of work and commits on return. It returns `{:ok, result}`, or `{:error, %DecisionConflict{}}` when an enrolled decision read conflicted with a concurrent append; nothing from that attempt was written, so re-read and decide again. Other commit failures are plain `{:error, reason}`.
|
|
41
|
+
- `Cratis.Chronicle.decide/2` runs the function in a unit of work and commits on return. It returns `{:ok, result}`, or `{:error, %DecisionConflict{}}` when an enrolled decision read conflicted with a concurrent append; nothing from that attempt was written, so re-read and decide again. Other commit failures are plain `{:error, reason}`.
|
|
42
42
|
- Unlike `with_unit_of_work/2`, `decide/2` never raises on a conflict. A concurrency violation without an enrolled decision read stays `{:error, {:concurrency_violations, _}}`.
|
|
43
43
|
- **`DecisionReads.get/2` enrolls the read only inside a unit of work** (`decide/2` or `UnitOfWork.with_unit_of_work/2`). Outside one it returns `{:error, :requires_unit_of_work}`.
|
|
44
44
|
- `DecisionReads.get_detached/2` folds the same way and enrolls nothing; use it for a read you do not intend to guard.
|
|
@@ -47,13 +47,13 @@ end
|
|
|
47
47
|
|
|
48
48
|
## Admission
|
|
49
49
|
|
|
50
|
-
`DecisionReads.admit/2` and `admit_for_stream/2` check a model's shape without any I/O and return `{:ok, event_types}` or `{:error, reason}`. `get` and `get_detached` **raise** `Chronicle.ReadModels.DecisionReadRefused` for a refused shape, because that is a programming error. Refusal reasons: `:reducer` (an active reducer), `:join`, `:hierarchy` (`children/2`), `:not_event_log`, `:open_ended_event_types` (`from_every/1`), `:no_event_types`, `:not_event_source_keyed`, `:unsupported_event_type_id`, `:all_streams_not_supported`, `:stream_scope_not_supported`, `:fold_incomplete`.
|
|
50
|
+
`DecisionReads.admit/2` and `admit_for_stream/2` check a model's shape without any I/O and return `{:ok, event_types}` or `{:error, reason}`. `get` and `get_detached` **raise** `Cratis.Chronicle.ReadModels.DecisionReadRefused` for a refused shape, because that is a programming error. Refusal reasons: `:reducer` (an active reducer), `:join`, `:hierarchy` (`children/2`), `:not_event_log`, `:open_ended_event_types` (`from_every/1`), `:no_event_types`, `:not_event_source_keyed`, `:unsupported_event_type_id`, `:all_streams_not_supported`, `:stream_scope_not_supported`, `:fold_incomplete`.
|
|
51
51
|
|
|
52
|
-
A model with `join/2`, `removed_with_join/2`, `children/2` or `from_every/1` cannot be guarded. A **passive** reducer (`use Chronicle.Reducers.Reducer, model: M, active: false`) can back a decision read because it is folded fresh on the client; an active reducer cannot.
|
|
52
|
+
A model with `join/2`, `removed_with_join/2`, `children/2` or `from_every/1` cannot be guarded. A **passive** reducer (`use Cratis.Chronicle.Reducers.Reducer, model: M, active: false`) can back a decision read because it is folded fresh on the client; an active reducer cannot.
|
|
53
53
|
|
|
54
54
|
## Explicit concurrency scopes
|
|
55
55
|
|
|
56
|
-
When a plain guard on the tail is enough, use `Chronicle.Events.ConcurrencyScope` (`:concurrency_scope` append option) instead of a read model.
|
|
56
|
+
When a plain guard on the tail is enough, use `Cratis.Chronicle.Events.ConcurrencyScope` (`:concurrency_scope` append option) instead of a read model.
|
|
57
57
|
|
|
58
58
|
| Need | Builder |
|
|
59
59
|
| --- | --- |
|
|
@@ -67,7 +67,7 @@ When a plain guard on the tail is enough, use `Chronicle.Events.ConcurrencyScope
|
|
|
67
67
|
## Default optimistic strategy
|
|
68
68
|
|
|
69
69
|
```elixir
|
|
70
|
-
{Chronicle.Client, ..., concurrency: [default: :optimistic, check_first_append: false]}
|
|
70
|
+
{Cratis.Chronicle.Client, ..., concurrency: [default: :optimistic, check_first_append: false]}
|
|
71
71
|
```
|
|
72
72
|
|
|
73
73
|
By default an append with no explicit or definition-derived scope sends no guard. With `default: :optimistic` the client reads the tail, narrowed the way the append is routed, and expects nothing newer. `check_first_append: true` also guards the first append into an empty narrowing with `expecting_no_matching_event/1`. An explicit or definition-derived scope always wins.
|
package/package/corpus/skills/cratis-chronicle-client-elixir/references/discovery-and-generations.md
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
# Discovery, artifact identity and event generations
|
|
5
5
|
|
|
6
|
-
Source: `Cratis/Chronicle.Elixir`: `Source/chronicle/lib/chronicle/discovery/`, `artifacts.ex`, `client.ex`, `events/event_type.ex`, `events/event_types.ex`, `reactors/reactor.ex`, `reducers/reducer.ex`, `lib/mix/tasks/chronicle.discover.ex`, and `Documentation/discovery.md`, `events.md`, `reactors.md`, `reducers.md`.
|
|
6
|
+
Source: `Cratis/Chronicle.Elixir`: `Source/chronicle/lib/cratis/chronicle/discovery/`, `artifacts.ex`, `client.ex`, `events/event_type.ex`, `events/event_types.ex`, `reactors/reactor.ex`, `reducers/reducer.ex`, `lib/mix/tasks/chronicle.discover.ex`, and `Documentation/discovery.md`, `events.md`, `reactors.md`, `reducers.md`.
|
|
7
7
|
|
|
8
8
|
Requires `cratis_chronicle` 3.13.0.
|
|
9
9
|
|
|
10
10
|
## The discovery report
|
|
11
11
|
|
|
12
|
-
`Chronicle.Client` builds a `%Chronicle.Discovery.Report{}` at start, logs a one-line summary at `:info` and the whole report at `:debug`. Read it with `Chronicle.Client.discovery_report()` and print it with `Chronicle.Discovery.Report.format/1`. `Chronicle.Artifacts.report(:my_app)` builds the same report without starting a client; `Chronicle.Artifacts.discover/1` still returns its plain map.
|
|
12
|
+
`Cratis.Chronicle.Client` builds a `%Cratis.Chronicle.Discovery.Report{}` at start, logs a one-line summary at `:info` and the whole report at `:debug`. Read it with `Cratis.Chronicle.Client.discovery_report()` and print it with `Cratis.Chronicle.Discovery.Report.format/1`. `Cratis.Chronicle.Artifacts.report(:my_app)` builds the same report without starting a client; `Cratis.Chronicle.Artifacts.discover/1` still returns its plain map.
|
|
13
13
|
|
|
14
14
|
Run it from the shell with `mix chronicle.discover --otp-app my_app`; add `--connection-string "chronicle://..."` to compare against a kernel (event store `"default"`, namespace `"Default"`) and `--fail-on-drift` to exit `1` on a warning-severity finding. Exit codes: `0` clean, `1` drift found, `2` could not run (no `--otp-app`, or kernel unreachable). `--fail-on-drift` has no effect without `--connection-string`.
|
|
15
15
|
|
|
@@ -18,11 +18,11 @@ Run it from the shell with `mix chronicle.discover --otp-app my_app`; add `--con
|
|
|
18
18
|
A reactor, reducer or declarative projection with no `:id` defaults it from its module name (reactors and reducers: the full module name; projections: the last segment). **Renaming or moving the module then creates a different artifact and silently resets its observation position.** Pin it:
|
|
19
19
|
|
|
20
20
|
```elixir
|
|
21
|
-
use Chronicle.Reactors.Reactor, id: "notification-reactor"
|
|
22
|
-
use Chronicle.Projections.Projection, id: "account-summary", model: MyApp.ReadModels.AccountSummary
|
|
21
|
+
use Cratis.Chronicle.Reactors.Reactor, id: "notification-reactor"
|
|
22
|
+
use Cratis.Chronicle.Projections.Projection, id: "account-summary", model: MyApp.ReadModels.AccountSummary
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
Discovery logs a warning once per module per BEAM node for a defaulted id. `warn_defaulted_ids: false` on `Chronicle.Client` suppresses it; prefer pinning. In-memory test clients skip it.
|
|
25
|
+
Discovery logs a warning once per module per BEAM node for a defaulted id. `warn_defaulted_ids: false` on `Cratis.Chronicle.Client` suppresses it; prefer pinning. In-memory test clients skip it.
|
|
26
26
|
|
|
27
27
|
## Drift policy
|
|
28
28
|
|
|
@@ -34,7 +34,7 @@ Before registering, the client compares what it would register with the kernel.
|
|
|
34
34
|
| `:fail` | Log findings and refuse to register on a `:warning`-severity finding |
|
|
35
35
|
| `:ignore` | Skip the check and its kernel calls |
|
|
36
36
|
|
|
37
|
-
Findings: `:schema_changed_without_generation` (an event type generation's coarse shape changed: added, removed or retyped field), `:observer_missing_from_code` (always `:info`, never blocks: other clients may own the observer), `:observer_event_types_changed` (a reactor's handled types differ; `:warning`). An indeterminate check (kernel unreachable, exception, 5 s deadline) continues under `:warn` and stops under `:fail`. Read the current findings with `Chronicle.Client.identity_drift()`. The kernel rejects a schema change without a bumped generation itself, regardless of policy.
|
|
37
|
+
Findings: `:schema_changed_without_generation` (an event type generation's coarse shape changed: added, removed or retyped field), `:observer_missing_from_code` (always `:info`, never blocks: other clients may own the observer), `:observer_event_types_changed` (a reactor's handled types differ; `:warning`). An indeterminate check (kernel unreachable, exception, 5 s deadline) continues under `:warn` and stops under `:fail`. Read the current findings with `Cratis.Chronicle.Client.identity_drift()`. The kernel rejects a schema change without a bumped generation itself, regardless of policy.
|
|
38
38
|
|
|
39
39
|
## Event type generations
|
|
40
40
|
|
|
@@ -42,15 +42,15 @@ A module for an **older** generation uses `generation_for:` instead of its own `
|
|
|
42
42
|
|
|
43
43
|
```elixir
|
|
44
44
|
defmodule MyApp.Events.CustomerRegisteredV1 do
|
|
45
|
-
use Chronicle.Events.EventType, generation_for: MyApp.Events.CustomerRegistered, generation: 1
|
|
45
|
+
use Cratis.Chronicle.Events.EventType, generation_for: MyApp.Events.CustomerRegistered, generation: 1
|
|
46
46
|
defstruct customer_id: "", owner_name: ""
|
|
47
47
|
end
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
`generation_for:` requires an explicit `generation:` and cannot be combined with `:id`. Bridge the generations with `Chronicle.Events.Migration` (exactly one migrator per pair).
|
|
50
|
+
`generation_for:` requires an explicit `generation:` and cannot be combined with `:id`. Bridge the generations with `Cratis.Chronicle.Events.Migration` (exactly one migrator per pair).
|
|
51
51
|
|
|
52
|
-
Mistakes such as two modules for one id and generation, two migrators for a pair, or `generation_for:` naming a module that is not an event type are logged and the client continues. Set `strict_validation: true` on `Chronicle.Client` to raise instead; `Chronicle.Events.EventTypes.validate/2` returns `:ok | {:error, exception}` and `validate!/2` raises.
|
|
52
|
+
Mistakes such as two modules for one id and generation, two migrators for a pair, or `generation_for:` naming a module that is not an event type are logged and the client continues. Set `strict_validation: true` on `Cratis.Chronicle.Client` to raise instead; `Cratis.Chronicle.Events.EventTypes.validate/2` returns `:ok | {:error, exception}` and `validate!/2` raises.
|
|
53
53
|
|
|
54
54
|
## Pinned generation delivery
|
|
55
55
|
|
|
56
|
-
By default (`:compatibility`) every event is upgraded to the generation of the module a reactor or reducer handles. For a handler written against an **older** generation, `use Chronicle.Reactors.Reactor, generation_delivery: :pinned` (or the same on a reducer) delivers the event as appended. `context.appended_generation` reports the appended generation (`0` means unknown). The client-wide default is `event_generation_delivery: :pinned`; an artifact's own option wins. A pinned observer that handles two generations of one event type raises `Chronicle.Observers.MultipleGenerationsOfEventTypeInObserver` on start.
|
|
56
|
+
By default (`:compatibility`) every event is upgraded to the generation of the module a reactor or reducer handles. For a handler written against an **older** generation, `use Cratis.Chronicle.Reactors.Reactor, generation_delivery: :pinned` (or the same on a reducer) delivers the event as appended. `context.appended_generation` reports the appended generation (`0` means unknown). The client-wide default is `event_generation_delivery: :pinned`; an artifact's own option wins. A pinned observer that handles two generations of one event type raises `Cratis.Chronicle.Observers.MultipleGenerationsOfEventTypeInObserver` on start.
|