@cratis/pi 7.189.2 → 7.189.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/harnesses/copilot/instructions/elixir.instructions.md +26 -4
- package/package/corpus/hooks/README.md +36 -1
- package/package/corpus/hooks/scripts/cratis-guard-shell-writes.sh +62 -17
- 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
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<!-- Copyright (c) Cratis. All rights reserved. -->
|
|
2
|
+
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
|
|
3
|
+
|
|
4
|
+
# Event model explorer
|
|
5
|
+
|
|
6
|
+
Arc serves the same explorer as the C# Arc at `/.cratis/event-model/`: the slices of each feature
|
|
7
|
+
(and sub-feature) with their commands, events, read models, queries and reactions, and the Screenplay
|
|
8
|
+
source. It is drawn from the code, so slice and event names are what readers see.
|
|
9
|
+
|
|
10
|
+
## Switch it on
|
|
11
|
+
|
|
12
|
+
```elixir
|
|
13
|
+
# mix.exs
|
|
14
|
+
compilers: Mix.compilers() ++ [:arc_event_model],
|
|
15
|
+
arc: [application: MyApp.Arc, event_model_strict: true]
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
- The compiler writes `priv/cratis/event_model/` while the app compiles (`catalog.json`, a
|
|
19
|
+
`*.model.json` and a `*.screenplay` per document: the application, each module, each feature at every
|
|
20
|
+
depth). It is part of every release; nothing is analysed at run time. Commit it.
|
|
21
|
+
- The routes are served by `Cratis.Arc.Plug`: `/.cratis/event-model/`, `hierarchy`,
|
|
22
|
+
`documents/{project}/{document}/model|source` and `assets/*`. **Mount `Cratis.Arc.Plug` before anything
|
|
23
|
+
that only accepts HTML** (a Phoenix endpoint's `plug :accepts, ["html"]` answers 406 to the
|
|
24
|
+
explorer's JSON requests).
|
|
25
|
+
- `event_model:` on the Arc application is `:auto` (default: development only), `true` or `false`;
|
|
26
|
+
`introspection` decides who may read it (`:authenticated` default, `:anonymous`, `false`);
|
|
27
|
+
`event_model_apps: [:other_app]` adds other OTP apps' embedded models.
|
|
28
|
+
- `/.cratis/structure` lists the same modules, features and slices (nested) with their commands and
|
|
29
|
+
read models, for tools such as Lens. `display_names:` on the application chooses how an id is shown.
|
|
30
|
+
|
|
31
|
+
## How slices are found
|
|
32
|
+
|
|
33
|
+
- A slice is the module namespace after `segments_to_skip` as `[module, feature..., slice]`: the first
|
|
34
|
+
segment is the module, the last the slice, **everything between is a feature path**, so
|
|
35
|
+
`Prism.Access.ApiCredentials.Secrets.RotatingSecrets.RotateSecret` with `segments_to_skip: 1` is the
|
|
36
|
+
slice `RotatingSecrets` of the sub-feature `Secrets` of the feature `ApiCredentials` of the module
|
|
37
|
+
`Access`. The board nests sub-features as `subFeatures`, the Screenplay source nests `feature` inside
|
|
38
|
+
`feature`, and each depth has its own document. Fewer than three segments fill the deepest parts first.
|
|
39
|
+
- A slice with a command is a state change; with a read model, reducer or projection a state view; with
|
|
40
|
+
only a reactor an automation. **Keep a view's query module inside its slice folder**
|
|
41
|
+
(`Viewing.Listing.Queries`): a read model module sitting in the parent namespace is grouped with
|
|
42
|
+
the parent, not with its slice.
|
|
43
|
+
- **The events of a command are the event types its compiled code builds** (read from the debug info of
|
|
44
|
+
the module, helpers included). A command that gets its events from another module shows only what it
|
|
45
|
+
builds itself. A reactor's `@handles` is what it reacts to and its code is what it emits.
|
|
46
|
+
- A view consumes the events its reducer or projection handles. Another read model over the same
|
|
47
|
+
model consumes the same events. A model read some other way (the event log) declares them:
|
|
48
|
+
`use Cratis.Arc.ReadModel, model: ..., consumes: MyApp.Events.all()`.
|
|
49
|
+
- **Names are ids.** Commands, event types and reactors are shown by their `id:` in PascalCase;
|
|
50
|
+
`display_names:` chooses `:pascal_case` (default), `:kebab_case`, `:as_declared` or a function.
|
|
51
|
+
|
|
52
|
+
## It is validated
|
|
53
|
+
|
|
54
|
+
The compiler reports what is incomplete (warnings; errors with `event_model_strict: true`):
|
|
55
|
+
|
|
56
|
+
| Problem | Fix |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| a state change without a command, or whose command appends no events | the command must build its event types in its own module |
|
|
59
|
+
| a view without a read model, or that consumes no events | add a reducer or projection, or `consumes:` |
|
|
60
|
+
| an automation that reacts to no event, or records none | have the reactor return the event that says what it did (`SecretRetiredInOry`), not nothing |
|
|
61
|
+
| a consumed event no slice produces | the event needs a command appending it |
|
|
62
|
+
| a fact used before it is produced | move the slice into a sub-feature after the ones it uses |
|
|
63
|
+
|
|
64
|
+
Reading order is dependency order. A view or automation follows the slices that produce what it
|
|
65
|
+
consumes; sibling features and modules follow the same order; a feature's own slices come before its
|
|
66
|
+
sub-features. So a slice that uses events of several sub-features belongs in a sub-feature of its own
|
|
67
|
+
(for example `Viewing` for the views of a feature), not in the parent.
|
|
68
|
+
|
|
69
|
+
The generated `.screenplay` compiles with the Screenplay compiler (`screenplay x.play`): a read model
|
|
70
|
+
shared by several views is declared once, `produces` names the stream (`for id`), and property names
|
|
71
|
+
are plain identifiers.
|
|
72
|
+
|
|
73
|
+
## Build and troubleshoot
|
|
74
|
+
|
|
75
|
+
- The explorer is built from `Source/event_model_viewer` into the package; a git dependency lacks
|
|
76
|
+
`priv/event_model` (it is built at publish), so use a released package or a built checkout.
|
|
77
|
+
- Run `MIX_ENV=dev mix compile` to regenerate; the files only change when the content does.
|
|
78
|
+
- A slice missing from the board is usually in a namespace the application does not discover, or has
|
|
79
|
+
no command, read model, reducer, projection or reactor.
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
## Plug
|
|
7
7
|
|
|
8
|
-
`plug Arc.Plug, application: MyApp.Arc` answers `/api/...` commands and queries, `/.cratis/*`
|
|
8
|
+
`plug Cratis.Arc.Plug, application: MyApp.Arc` answers `/api/...` commands and queries, `/.cratis/*`
|
|
9
9
|
(identity, discovery, both hubs) and passes everything else on. `max_body_bytes` is the only
|
|
10
|
-
request limit; there are no connection or subscription caps. `Arc.Plug.SinglePage` serves a
|
|
10
|
+
request limit; there are no connection or subscription caps. `Cratis.Arc.Plug.SinglePage` serves a
|
|
11
11
|
built SPA (`root:`, `api_prefixes:`). Plug and Bandit are enough; no Phoenix is needed.
|
|
12
12
|
|
|
13
13
|
## Phoenix and LiveView
|
|
14
14
|
|
|
15
|
-
The same application runs in process: `Arc.execute/3`, `Arc.query/5`, and `Arc.LiveView` keeps
|
|
15
|
+
The same application runs in process: `Cratis.Arc.execute/3`, `Cratis.Arc.query/5`, and `Cratis.Arc.LiveView` keeps
|
|
16
16
|
an assign current from an observable query, with forms that show pipeline errors on the
|
|
17
17
|
field. Hand the endpoint the Arc plug as for Plug.
|
|
18
18
|
|
|
@@ -25,18 +25,18 @@ On the application: `chronicle:`, `authentication:`, `trust_forwarded_identity_h
|
|
|
25
25
|
|
|
26
26
|
## Testing
|
|
27
27
|
|
|
28
|
-
`use Arc.Test.Case, application: MyApp.Arc, event_types: [...]` starts a Chronicle in-memory
|
|
29
|
-
test client per test and gives an `Arc.Test.Scenario` as `:arc`; `async: true` is safe.
|
|
28
|
+
`use Cratis.Arc.Test.Case, application: MyApp.Arc, event_types: [...]` starts a Chronicle in-memory
|
|
29
|
+
test client per test and gives an `Cratis.Arc.Test.Scenario` as `:arc`; `async: true` is safe.
|
|
30
30
|
|
|
31
31
|
```elixir
|
|
32
|
-
result = Arc.Test.execute(arc, {RegisterAuthor, %{"id" => Arc.new_id(), "name" => "A"}})
|
|
33
|
-
Arc.Test.assert_invalid(result, :name)
|
|
34
|
-
Arc.Test.refute_appended(arc, AuthorRegistered)
|
|
32
|
+
result = Cratis.Arc.Test.execute(arc, {RegisterAuthor, %{"id" => Cratis.Arc.new_id(), "name" => "A"}})
|
|
33
|
+
Cratis.Arc.Test.assert_invalid(result, :name)
|
|
34
|
+
Cratis.Arc.Test.refute_appended(arc, AuthorRegistered)
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
Also `Arc.Test.query/5`, `principal/2`, `assert_success/1`, `assert_forbidden/1`,
|
|
37
|
+
Also `Cratis.Arc.Test.query/5`, `principal/2`, `assert_success/1`, `assert_forbidden/1`,
|
|
38
38
|
`assert_appended/3` and `wait_for_observers/1`. For a plain Plug application without
|
|
39
|
-
Chronicle, call `Arc.execute/3` and `Arc.query/5` with `principal:` and `tenant:` and assert
|
|
39
|
+
Chronicle, call `Cratis.Arc.execute/3` and `Cratis.Arc.query/5` with `principal:` and `tenant:` and assert
|
|
40
40
|
on the result. In-memory Chronicle has the limits listed in the Chronicle client skill.
|
|
41
41
|
|
|
42
42
|
## Running samples
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
config :my_app, MyApp.Arc,
|
|
10
10
|
mongodb: [server: System.get_env("MONGODB_URL"), database: "library", naming_policy: :camel_case]
|
|
11
11
|
|
|
12
|
-
children = [MyApp.Arc, {Arc.MongoDB, application: MyApp.Arc}, MyApp.Endpoint]
|
|
12
|
+
children = [MyApp.Arc, {Cratis.Arc.MongoDB, application: MyApp.Arc}, MyApp.Endpoint]
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Start `Arc.MongoDB` **after** the Arc application. `server` and `database` are required; a
|
|
15
|
+
Start `Cratis.Arc.MongoDB` **after** the Arc application. `server` and `database` are required; a
|
|
16
16
|
missing one raises on first use. **Change streams need a replica set or sharded cluster**;
|
|
17
17
|
a single node started with `--replSet` is enough. Keep credentials out of source control.
|
|
18
18
|
|
|
@@ -22,13 +22,13 @@ Other options: `direct_connection`, `database_resolver`, `server_resolver`,
|
|
|
22
22
|
## Documents
|
|
23
23
|
|
|
24
24
|
```elixir
|
|
25
|
-
use Arc.MongoDB.Document, types: [id: :uuid, created_at: :datetime]
|
|
25
|
+
use Cratis.Arc.MongoDB.Document, types: [id: :uuid, created_at: :datetime]
|
|
26
26
|
defstruct id: "", name: "", created_at: ~U[1970-01-01 00:00:00Z]
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
Types: `:string`, `:integer`, `:float`, `:boolean`, `:uuid` (binary subtype 4), `:object_id`,
|
|
30
30
|
`:datetime` (UTC), `:date` (UTC at noon), `{:list, t}` (never `nil` when read), `:map`, a
|
|
31
|
-
`Chronicle.Concept`, a struct module. `id` is stored as `_id`. Use a datetime default of
|
|
31
|
+
`Cratis.Chronicle.Concept`, a struct module. `id` is stored as `_id`. Use a datetime default of
|
|
32
32
|
`~U[1970-01-01 00:00:00Z]` if the generated TypeScript should be non-optional.
|
|
33
33
|
|
|
34
34
|
Naming policies: `:none`, `:camel_case`, `:snake_case` or a module (`property_name/1`,
|
|
@@ -36,7 +36,7 @@ Naming policies: `:none`, `:camel_case`, `:snake_case` or a module (`property_na
|
|
|
36
36
|
|
|
37
37
|
## Using a collection
|
|
38
38
|
|
|
39
|
-
Every function takes `{ctx, DocumentModule}` (or an `Arc.MongoDB.Collection`): `all`, `find`,
|
|
39
|
+
Every function takes `{ctx, DocumentModule}` (or an `Cratis.Arc.MongoDB.Collection`): `all`, `find`,
|
|
40
40
|
`find_one`, `find_by_id`, `count`, `page`, `insert`, `insert_many`, `save`, `update`,
|
|
41
41
|
`update_many`, `delete`, `delete_many`, `create_index`, `provide`. The context selects the
|
|
42
42
|
tenant's database.
|
|
@@ -56,7 +56,7 @@ caller; **changing the naming of a database in use is a data migration.**
|
|
|
56
56
|
|
|
57
57
|
`connection_resolution` places tenants on servers and credentials of their own by
|
|
58
58
|
`:default`, a rule (`{:template, ...}`), an endpoint (`{:http, ...}`) or a module
|
|
59
|
-
implementing `Arc.MongoDB.ConnectionResolver`, following the shared connection-resolution
|
|
59
|
+
implementing `Cratis.Arc.MongoDB.ConnectionResolver`, following the shared connection-resolution
|
|
60
60
|
contract. Answers are cached by purpose and tenant (never by credential) until a minute before
|
|
61
61
|
expiry; an authentication failure drops the cached answer. **An OIDC `accessToken` is refused**:
|
|
62
62
|
the Elixir driver has no such mechanism.
|
|
@@ -64,8 +64,8 @@ the Elixir driver has no such mechanism.
|
|
|
64
64
|
## Observation
|
|
65
65
|
|
|
66
66
|
```elixir
|
|
67
|
-
@observe many: true, watch: [Arc.MongoDB.watch(Book)]
|
|
68
|
-
def live_books(_args, ctx), do: {:ok, Arc.MongoDB.all({ctx, Book}, sort: [title: :asc])}
|
|
67
|
+
@observe many: true, watch: [Cratis.Arc.MongoDB.watch(Book)]
|
|
68
|
+
def live_books(_args, ctx), do: {:ok, Cratis.Arc.MongoDB.all({ctx, Book}, sort: [title: :asc])}
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
One database-level change stream is shared by every observer of a database; it resumes
|
|
@@ -75,5 +75,5 @@ the collection another query writes to is how one change updates several lists.
|
|
|
75
75
|
|
|
76
76
|
## Test
|
|
77
77
|
|
|
78
|
-
`Arc.MongoDB.Test.unique_database/1`, `connect`, `available?` and `drop_databases/3`. Tests
|
|
78
|
+
`Cratis.Arc.MongoDB.Test.unique_database/1`, `connect`, `available?` and `drop_databases/3`. Tests
|
|
79
79
|
that need MongoDB should skip when none answers (`MONGODB_URL`).
|
|
@@ -10,7 +10,7 @@ hub that carries many subscriptions on one connection.
|
|
|
10
10
|
## The two hubs
|
|
11
11
|
|
|
12
12
|
Both speak one protocol (`Connected`, `Subscribe`, `Unsubscribe`, `QueryResult`,
|
|
13
|
-
`Unauthorized`, `Error`, `Ping`/`Pong`) through `Arc.Plug.HubSession`.
|
|
13
|
+
`Unauthorized`, `Error`, `Ping`/`Pong`) through `Cratis.Arc.Plug.HubSession`.
|
|
14
14
|
|
|
15
15
|
| | WebSocket | Server-Sent Events |
|
|
16
16
|
| --- | --- | --- |
|
|
@@ -39,9 +39,9 @@ or paged query always sends the snapshot too, because position matters.
|
|
|
39
39
|
## What triggers a re-run
|
|
40
40
|
|
|
41
41
|
- `watch: [ReadModel]` re-runs when Chronicle changes that read model.
|
|
42
|
-
- `watch: [Arc.MongoDB.watch(Doc)]`, or any `{module, target}` for a module implementing
|
|
43
|
-
`Arc.Watch`, re-runs when that source reports a change.
|
|
44
|
-
- `topics: ["name"]` re-runs on `Arc.Notifier.notify(MyApp.Arc, "name")`. It reaches
|
|
42
|
+
- `watch: [Cratis.Arc.MongoDB.watch(Doc)]`, or any `{module, target}` for a module implementing
|
|
43
|
+
`Cratis.Arc.Watch`, re-runs when that source reports a change.
|
|
44
|
+
- `topics: ["name"]` re-runs on `Cratis.Arc.Notifier.notify(MyApp.Arc, "name")`. It reaches
|
|
45
45
|
**subscriptions on the same node only**; across nodes broadcast with `Phoenix.PubSub`
|
|
46
46
|
and notify in each receiver.
|
|
47
47
|
|
|
@@ -50,5 +50,5 @@ it and the client resubscribes.
|
|
|
50
50
|
|
|
51
51
|
## Authentication of browser connections
|
|
52
52
|
|
|
53
|
-
Use cookies. A plug in front of `Arc.Plug` can turn a sign-in cookie and a tenant cookie
|
|
53
|
+
Use cookies. A plug in front of `Cratis.Arc.Plug` can turn a sign-in cookie and a tenant cookie
|
|
54
54
|
into the headers Arc reads (the showcase's `Samples.Web.CookieIdentity` does, for a demo).
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
- **`/.cratis/tenants` and `/.cratis/users` list; they do not select.**
|
|
10
10
|
- **A subscription runs with the context of the request that created it.** For SSE that is the
|
|
11
11
|
control `POST`.
|
|
12
|
-
- **`Arc.Notifier` is one node.** Broadcast across nodes yourself.
|
|
13
|
-
- **In-memory sorting and paging.** A large list needs `%Arc.Page{}` from the database.
|
|
12
|
+
- **`Cratis.Arc.Notifier` is one node.** Broadcast across nodes yourself.
|
|
13
|
+
- **In-memory sorting and paging.** A large list needs `%Cratis.Arc.Page{}` from the database.
|
|
14
14
|
- **A query with no `authorize` or `allow_anonymous()` is a decision you have not made.**
|
|
15
15
|
- **Replay memory is per node.** Signed forwarded-identity and on-behalf-of replay caches
|
|
16
16
|
live in a process per application and node, and verification fails closed when the
|
|
@@ -23,3 +23,14 @@
|
|
|
23
23
|
what protects hand-written files from being overwritten.
|
|
24
24
|
- **Do not copy .NET idioms**: no `[Command]` attributes, no DI-injected `IEventLog`. Events are
|
|
25
25
|
returned from `handle/2` as `{:append, ...}`.
|
|
26
|
+
|
|
27
|
+
## Event model and structure
|
|
28
|
+
|
|
29
|
+
| Mistake | What happens | Do this |
|
|
30
|
+
| --- | --- | --- |
|
|
31
|
+
| A read model module in the parent namespace (`ApiCredentials.Listing` beside `ApiCredentials.Listing.Reducer`) | The view is grouped with the parent feature, not its slice | Put the query module inside the slice folder (`Listing.Queries`) |
|
|
32
|
+
| A reactor that returns nothing | The automation slice shows no events | Return the event that records what it did |
|
|
33
|
+
| A view over a model another slice builds | Old Arc showed no events | Arc 1.4 reads them from the reducer; use `consumes:` for a model read from the event log |
|
|
34
|
+
| Reading the last module segment as the name | The model shows the `id:` | Name by `id:` and keep `display_names:` in mind |
|
|
35
|
+
| Slices that use events of several sub-features in the parent feature | A fact is drawn after what uses it; validation fails | Give them a sub-feature that follows the others |
|
|
36
|
+
| Leaving `event_model_strict` off | An incomplete model only warns | Set `arc: [event_model_strict: true]` once the model is clean |
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
| --- | --- | --- |
|
|
8
8
|
| Packages | `cratis_arc` (core, Plug, Phoenix, LiveView), `cratis_arc_mongodb` | `Source/arc/mix.exs`, `Source/arc_mongodb/mix.exs` |
|
|
9
9
|
| Elixir requirement | `~> 1.18` | `mix.exs` |
|
|
10
|
-
| Chronicle dependency | `cratis_chronicle ~>
|
|
10
|
+
| Chronicle dependency | `cratis_chronicle ~> 4.0` (modules are `Cratis.Chronicle.*`) | `Source/arc/mix.exs` |
|
|
11
11
|
| MongoDB driver | `mongodb_driver ~> 1.6` | `Source/arc_mongodb/mix.exs` |
|
|
12
|
-
| Release | Source preview
|
|
12
|
+
| Release | Source preview. Releases are GitHub tags and Hex may lag them: pin a git tag or a path, and check hex.pm before quoting a version | repository, `gh release list` |
|
|
13
|
+
| Module namespace | Everything is `Cratis.Arc.*` (`use Cratis.Arc.Command, id: "..."`); sources are under `Source/arc/lib/cratis/arc/` | repository |
|
|
13
14
|
| Documented gaps | `Documentation/limits-and-gaps.md` | repository |
|
|
14
15
|
| Contract | The Arc HTTP contract | Cratis/Arc `Documentation/http-contract.md` |
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
| Decision | Who |
|
|
9
9
|
| --- | --- |
|
|
10
|
-
| Selection: which tenant is this request for | `Arc.Tenancy` |
|
|
11
|
-
| Membership: may this caller use it | You, in a command, query, policy or `Arc.Filter` |
|
|
10
|
+
| Selection: which tenant is this request for | `Cratis.Arc.Tenancy` |
|
|
11
|
+
| Membership: may this caller use it | You, in a command, query, policy or `Cratis.Arc.Filter` |
|
|
12
12
|
| Storage isolation: where the data lives | Chronicle namespace and the MongoDB database |
|
|
13
13
|
|
|
14
14
|
**A resolver only selects.** Do not treat a header, query value or host as evidence of
|
|
@@ -23,7 +23,7 @@ config :my_app, MyApp.Arc, tenancy: [resolver: :header]
|
|
|
23
23
|
`:header` (default; `header:`, default `x-cratis-tenant-id`), `:query` (`query_parameter:`,
|
|
24
24
|
default `tenantId`), `:claim` (`claim_type:`, default `tenant_id`; ties selection to the
|
|
25
25
|
authenticated principal), `:subdomain` (`base_domain:` required), `:fixed` or `:development`
|
|
26
|
-
(`tenant_id:`), or a module implementing `Arc.Tenancy` (`resolve(conn, principal, options)`).
|
|
26
|
+
(`tenant_id:`), or a module implementing `Cratis.Arc.Tenancy` (`resolve(conn, principal, options)`).
|
|
27
27
|
There is **no chain of resolvers**. The `:subdomain` resolver accepts only exactly one label
|
|
28
28
|
before a registrable base domain and otherwise falls back to the client-controlled header, so
|
|
29
29
|
strip the header at the ingress; the application refuses to start with an unusable base
|
|
@@ -35,21 +35,21 @@ explicit `namespace:` is given. `:arc_tenant` is Logger metadata.
|
|
|
35
35
|
## Authentication and identity
|
|
36
36
|
|
|
37
37
|
Authentication handlers return `{:authenticated, principal}`, `:failed` (terminal, generic
|
|
38
|
-
401) or `:anonymous` (the next handler tries). `Arc.Authentication.MicrosoftIdentityPlatform`
|
|
38
|
+
401) or `:anonymous` (the next handler tries). `Cratis.Arc.Authentication.MicrosoftIdentityPlatform`
|
|
39
39
|
reads `x-ms-client-principal`, `-id` and `-name`; **forwarded headers are trusted only with
|
|
40
40
|
`trust_forwarded_identity_headers: true`**, or when signed (HMAC with audience, key id,
|
|
41
41
|
timestamp, nonce and method/path coverage). An RS256 on-behalf-of assertion is checked for
|
|
42
42
|
signature (RSA 2048+), issuer, audience, expiry and replay.
|
|
43
43
|
|
|
44
|
-
Identity for the frontend: `use Arc.Identity.Provider, details: MyApp.IdentityDetails`;
|
|
44
|
+
Identity for the frontend: `use Cratis.Arc.Identity.Provider, details: MyApp.IdentityDetails`;
|
|
45
45
|
`/.cratis/me` answers 401 not signed in, 403 when the provider says `:unauthorized`, else the
|
|
46
|
-
identity with `details`. The provider receives the tenant (`Arc.Identity.Context.tenant`).
|
|
46
|
+
identity with `details`. The provider receives the tenant (`Cratis.Arc.Identity.Context.tenant`).
|
|
47
47
|
`/.cratis/users` and `/.cratis/tenants` list development users and tenants for tools such
|
|
48
48
|
as Lens; they do not decide the request's tenant.
|
|
49
49
|
|
|
50
50
|
## Authorize a namespace
|
|
51
51
|
|
|
52
|
-
An `Arc.Filter` implements `on_command(ctx, descriptor)` and `on_query(ctx, descriptor, query)`
|
|
52
|
+
An `Cratis.Arc.Filter` implements `on_command(ctx, descriptor)` and `on_query(ctx, descriptor, query)`
|
|
53
53
|
returning `:ok` or `{:unauthorized, reason}`. Register with `filters: [MyFilter]`. Filters run
|
|
54
54
|
**after authorization and before validation**, for every artifact; match the descriptor's
|
|
55
55
|
`namespace` to scope one. A refusal is `403` and the artifact never runs.
|
|
@@ -50,8 +50,21 @@
|
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
"kind": "skill-contains",
|
|
53
|
-
"value": "**`Arc.Notifier` is one node.**",
|
|
53
|
+
"value": "**`Cratis.Arc.Notifier` is one node.**",
|
|
54
54
|
"file": "references/pitfalls.md"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"kind": "skill-contains",
|
|
58
|
+
"value": "**Names are ids.**"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"kind": "skill-contains",
|
|
62
|
+
"value": "**Group slices into sub-features, and validate the event model.**"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"kind": "skill-contains",
|
|
66
|
+
"value": "## It is validated",
|
|
67
|
+
"file": "references/event-model.md"
|
|
55
68
|
}
|
|
56
69
|
]
|
|
57
70
|
}
|
|
@@ -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).
|