@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
|
@@ -12,13 +12,14 @@ paths:
|
|
|
12
12
|
# Elixir Conventions
|
|
13
13
|
|
|
14
14
|
Use Elixir and OTP idioms, not translated C# or JVM shapes. These conventions
|
|
15
|
-
are grounded in `Cratis/Chronicle.Elixir
|
|
16
|
-
`.formatter.exs`, and `lib/chronicle/`)
|
|
17
|
-
|
|
15
|
+
are grounded in `Cratis/Chronicle.Elixir` 4.x (`Source/chronicle/mix.exs`,
|
|
16
|
+
`.formatter.exs`, and `lib/cratis/chronicle/`) and `Cratis/Arc.Elixir` 1.4.x
|
|
17
|
+
(`lib/cratis/arc/`). Client-specific APIs belong in the
|
|
18
|
+
**cratis-chronicle-client-elixir** skill, Arc APIs in **cratis-arc-elixir**.
|
|
18
19
|
|
|
19
20
|
## Build and format
|
|
20
21
|
|
|
21
|
-
-
|
|
22
|
+
- Use Elixir 1.18 or later (`~> 1.18`); the packages build on 1.19.
|
|
22
23
|
- Run `mix compile --warnings-as-errors`, `mix test`, and
|
|
23
24
|
`mix format --check-formatted` with the project's formatter inputs.
|
|
24
25
|
- Use two-space indentation and let `mix format` own layout.
|
|
@@ -42,6 +43,27 @@ are grounded in `Cratis/Chronicle.Elixir v3.13.0` (`Source/chronicle/mix.exs`,
|
|
|
42
43
|
operational logging and keep credentials out of messages and crash reports.
|
|
43
44
|
- Use American English in identifiers, comments and documentation.
|
|
44
45
|
|
|
46
|
+
## Event-sourced applications on Arc and Chronicle
|
|
47
|
+
|
|
48
|
+
Read the **cratis-arc-elixir** and **cratis-chronicle-client-elixir** skills before touching a slice.
|
|
49
|
+
|
|
50
|
+
- **Folders are Module, Feature, Slice, and sub-features nest.** One folder per behavior, named for what
|
|
51
|
+
it does as a gerund (`RotatingSecrets`); the command inside is the verb. Group slices that act on one
|
|
52
|
+
thing into a sub-feature (`Secrets`, `Credentials`, `Viewing`), and put a reactor with the facts it
|
|
53
|
+
reacts to, not in a folder named for the third party it calls. No folders named for a kind of file.
|
|
54
|
+
- **Names are ids.** `use Cratis.Arc.Command, id: "rotate-secret"`, an event type's `id:`, a reactor's
|
|
55
|
+
`id:`; the model shows the id in PascalCase, so a module can be renamed without renaming the model.
|
|
56
|
+
- **A command and its events live in one file**, events first. An event is past tense, one fact, and
|
|
57
|
+
never carries a secret.
|
|
58
|
+
- **Every slice tells a whole story**: a state change has a command and the events it appends; a view
|
|
59
|
+
has a read model and consumes events (`consumes:` when it reads the event log); an automation reacts to
|
|
60
|
+
an event and records a fact of its own, so the event model shows what it did. A reactor that calls a
|
|
61
|
+
third party returns the event recording that it did.
|
|
62
|
+
- **Order is the story**: a slice that uses events of several sub-features goes in a sub-feature after
|
|
63
|
+
them. Build with `arc: [event_model_strict: true]` so an incomplete model fails the build.
|
|
64
|
+
- **Third parties are integrations behind a behaviour**, with an in-memory stand-in for specs; only
|
|
65
|
+
reactors write to them.
|
|
66
|
+
|
|
45
67
|
Every `.ex` and `.exs` source file starts with:
|
|
46
68
|
|
|
47
69
|
```elixir
|
|
@@ -11,13 +11,14 @@ paths:
|
|
|
11
11
|
# Elixir Conventions
|
|
12
12
|
|
|
13
13
|
Use Elixir and OTP idioms, not translated C# or JVM shapes. These conventions
|
|
14
|
-
are grounded in `Cratis/Chronicle.Elixir
|
|
15
|
-
`.formatter.exs`, and `lib/chronicle/`)
|
|
16
|
-
|
|
14
|
+
are grounded in `Cratis/Chronicle.Elixir` 4.x (`Source/chronicle/mix.exs`,
|
|
15
|
+
`.formatter.exs`, and `lib/cratis/chronicle/`) and `Cratis/Arc.Elixir` 1.4.x
|
|
16
|
+
(`lib/cratis/arc/`). Client-specific APIs belong in the
|
|
17
|
+
**cratis-chronicle-client-elixir** skill, Arc APIs in **cratis-arc-elixir**.
|
|
17
18
|
|
|
18
19
|
## Build and format
|
|
19
20
|
|
|
20
|
-
-
|
|
21
|
+
- Use Elixir 1.18 or later (`~> 1.18`); the packages build on 1.19.
|
|
21
22
|
- Run `mix compile --warnings-as-errors`, `mix test`, and
|
|
22
23
|
`mix format --check-formatted` with the project's formatter inputs.
|
|
23
24
|
- Use two-space indentation and let `mix format` own layout.
|
|
@@ -41,6 +42,27 @@ are grounded in `Cratis/Chronicle.Elixir v3.13.0` (`Source/chronicle/mix.exs`,
|
|
|
41
42
|
operational logging and keep credentials out of messages and crash reports.
|
|
42
43
|
- Use American English in identifiers, comments and documentation.
|
|
43
44
|
|
|
45
|
+
## Event-sourced applications on Arc and Chronicle
|
|
46
|
+
|
|
47
|
+
Read the **cratis-arc-elixir** and **cratis-chronicle-client-elixir** skills before touching a slice.
|
|
48
|
+
|
|
49
|
+
- **Folders are Module, Feature, Slice, and sub-features nest.** One folder per behavior, named for what
|
|
50
|
+
it does as a gerund (`RotatingSecrets`); the command inside is the verb. Group slices that act on one
|
|
51
|
+
thing into a sub-feature (`Secrets`, `Credentials`, `Viewing`), and put a reactor with the facts it
|
|
52
|
+
reacts to, not in a folder named for the third party it calls. No folders named for a kind of file.
|
|
53
|
+
- **Names are ids.** `use Cratis.Arc.Command, id: "rotate-secret"`, an event type's `id:`, a reactor's
|
|
54
|
+
`id:`; the model shows the id in PascalCase, so a module can be renamed without renaming the model.
|
|
55
|
+
- **A command and its events live in one file**, events first. An event is past tense, one fact, and
|
|
56
|
+
never carries a secret.
|
|
57
|
+
- **Every slice tells a whole story**: a state change has a command and the events it appends; a view
|
|
58
|
+
has a read model and consumes events (`consumes:` when it reads the event log); an automation reacts to
|
|
59
|
+
an event and records a fact of its own, so the event model shows what it did. A reactor that calls a
|
|
60
|
+
third party returns the event recording that it did.
|
|
61
|
+
- **Order is the story**: a slice that uses events of several sub-features goes in a sub-feature after
|
|
62
|
+
them. Build with `arc: [event_model_strict: true]` so an incomplete model fails the build.
|
|
63
|
+
- **Third parties are integrations behind a behaviour**, with an in-memory stand-in for specs; only
|
|
64
|
+
reactors write to them.
|
|
65
|
+
|
|
44
66
|
Every `.ex` and `.exs` source file starts with:
|
|
45
67
|
|
|
46
68
|
```elixir
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: cratis-arc-elixir
|
|
3
|
-
description: Use when building an Elixir CQRS application with Arc for Elixir (`cratis_arc`, `cratis_arc_mongodb`) with commands, read-model queries, observable queries over WebSocket or SSE hubs, tenancy, MongoDB, identity, generated TypeScript proxies and vertical slices. Not for the Chronicle client alone, or for .NET, JVM, Go or TypeScript Arc.
|
|
3
|
+
description: Use when building an Elixir CQRS application with Arc for Elixir (`cratis_arc`, `cratis_arc_mongodb`) with commands, read-model queries, observable queries over WebSocket or SSE hubs, tenancy, MongoDB, identity, availability, the generated event model, generated TypeScript proxies and vertical slices grouped into sub-features. Not for the Chronicle client alone, or for .NET, JVM, Go or TypeScript Arc.
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Elixir 1.18 or later; Plug and Bandit, or Phoenix.
|
|
6
6
|
---
|
|
@@ -25,8 +25,8 @@ and with **MongoDB** (`cratis_arc_mongodb`) for documents.
|
|
|
25
25
|
|
|
26
26
|
| Product | Source checked |
|
|
27
27
|
| --- | --- |
|
|
28
|
-
| Arc for Elixir (`cratis_arc`) | `Source/arc/lib/arc/{command,read_model,application,pipeline,tenancy,filter,watch,proxy_generator}.ex`, `lib/arc/plug/{hub_session,hub,sse_hub}.ex`, `Documentation/*.md` |
|
|
29
|
-
| Arc for Elixir MongoDB (`cratis_arc_mongodb`) | `Source/arc_mongodb/lib/arc/mongodb.ex`, `lib/arc/mongodb/*.ex` |
|
|
28
|
+
| Arc for Elixir (`cratis_arc`) | `Source/arc/lib/cratis/arc/{command,read_model,application,pipeline,tenancy,filter,watch,proxy_generator}.ex`, `lib/cratis/arc/plug/{hub_session,hub,sse_hub}.ex`, `Documentation/*.md` |
|
|
29
|
+
| Arc for Elixir MongoDB (`cratis_arc_mongodb`) | `Source/arc_mongodb/lib/cratis/arc/mongodb.ex`, `lib/cratis/arc/mongodb/*.ex` |
|
|
30
30
|
| Samples | `Samples/showcase` (every feature, plain Plug), `Samples/phoenix` (LiveView, Chronicle) |
|
|
31
31
|
|
|
32
32
|
Source is authoritative. `Documentation/` excerpts marked `# From: <path>` are verified
|
|
@@ -37,7 +37,7 @@ against the samples in CI, so prefer them to memory.
|
|
|
37
37
|
```elixir
|
|
38
38
|
defmodule Library.Authors.Registration.RenameAuthor do
|
|
39
39
|
@moduledoc "Renames an author. Only editors may."
|
|
40
|
-
use Arc.Command
|
|
40
|
+
use Cratis.Arc.Command, id: "rename-author"
|
|
41
41
|
authorize roles: ["editor"]
|
|
42
42
|
|
|
43
43
|
schema do
|
|
@@ -50,7 +50,8 @@ defmodule Library.Authors.Registration.RenameAuthor do
|
|
|
50
50
|
end
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
`id:` is the command's kebab-case name: its route is `/api/<namespace>/rename-author`, and the structure
|
|
54
|
+
and the event model show `RenameAuthor`, whatever the module is called. Only `handle/2` is required. The order is validate, `provide/2`, then `handle/2`.
|
|
54
55
|
`handle/2` returns `{:append, event | [events]}`, `{:append, events, response}`,
|
|
55
56
|
`{:ok, response}` (records nothing) or `{:error, results}`. `key: true` marks the event
|
|
56
57
|
source. A handler that returns an event with no key and no source id is rejected as
|
|
@@ -60,13 +61,13 @@ source. A handler that returns an event with no key and no source id is rejected
|
|
|
60
61
|
|
|
61
62
|
```elixir
|
|
62
63
|
defmodule Library.Authors.Listing.Authors do
|
|
63
|
-
use Arc.ReadModel, model: Library.Authors.Author, types: [id: :uuid]
|
|
64
|
+
use Cratis.Arc.ReadModel, model: Library.Authors.Author, types: [id: :uuid]
|
|
64
65
|
|
|
65
66
|
@query many: true
|
|
66
|
-
def all_authors(_args, ctx), do: Chronicle.all(Library.Authors.Author, ctx.chronicle)
|
|
67
|
+
def all_authors(_args, ctx), do: Cratis.Chronicle.all(Library.Authors.Author, ctx.chronicle)
|
|
67
68
|
|
|
68
69
|
@observe many: true, watch: [Library.Authors.Author]
|
|
69
|
-
def live_authors(_args, ctx), do: Chronicle.all(Library.Authors.Author, ctx.chronicle)
|
|
70
|
+
def live_authors(_args, ctx), do: Cratis.Chronicle.all(Library.Authors.Author, ctx.chronicle)
|
|
70
71
|
end
|
|
71
72
|
```
|
|
72
73
|
|
|
@@ -80,14 +81,14 @@ before choosing a transport or a transfer mode.
|
|
|
80
81
|
|
|
81
82
|
```elixir
|
|
82
83
|
defmodule MyApp.Arc do
|
|
83
|
-
use Arc.Application, otp_app: :my_app
|
|
84
|
+
use Cratis.Arc.Application, otp_app: :my_app
|
|
84
85
|
end
|
|
85
86
|
|
|
86
87
|
# in the supervision tree, before the endpoint
|
|
87
88
|
children = [MyApp.Arc, {Bandit, plug: MyApp.Router, port: 4000}]
|
|
88
89
|
|
|
89
90
|
# the router
|
|
90
|
-
plug Arc.Plug, application: MyApp.Arc
|
|
91
|
+
plug Cratis.Arc.Plug, application: MyApp.Arc
|
|
91
92
|
```
|
|
92
93
|
|
|
93
94
|
`MyApp.Arc` **must be in the supervision tree**: it owns the processes behind observable
|
|
@@ -113,8 +114,17 @@ Phoenix and LiveView use the same application in process. Read
|
|
|
113
114
|
- **Organize by feature.** Backend, generated proxies and React page of a feature share a
|
|
114
115
|
folder. `layout: :colocated` generates that layout.
|
|
115
116
|
|
|
116
|
-
- **
|
|
117
|
-
|
|
117
|
+
- **Names are ids.** A command (`id:`), event type (`id:`), reactor (`id:`) and read model (optional `id:`)
|
|
118
|
+
is named by its kebab-case id; `/.cratis/structure` and the event model show it in PascalCase (the
|
|
119
|
+
application's `display_names:` picks `:pascal_case`, `:kebab_case`, `:as_declared` or a function).
|
|
120
|
+
The module name is free, so never read meaning from its last segment.
|
|
121
|
+
- **Group slices into sub-features, and validate the event model.** A folder is a feature, a folder in a
|
|
122
|
+
folder a sub-feature; the board and the Screenplay nest them. A view is drawn after the slices that
|
|
123
|
+
produce what it consumes, and the `:arc_event_model` compiler warns (errors with
|
|
124
|
+
`event_model_strict: true`) about a slice without its command, events or read model. Read
|
|
125
|
+
[references/event-model.md](references/event-model.md) before adding a slice.
|
|
126
|
+
- **Availability ships (v1.3.0).** Read [references/availability.md](references/availability.md) for `available`,
|
|
127
|
+
the definition, suspension and the dev model route.
|
|
118
128
|
|
|
119
129
|
See [references/pitfalls.md](references/pitfalls.md) for the full list, and
|
|
120
130
|
[references/product-sources.md](references/product-sources.md) for package facts.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
Arc for Elixir ships availability (v1.3.0): the same model as Arc for .NET and Screenplay, in the same words.
|
|
7
7
|
Verify names against the package's `Documentation/availability.md`.
|
|
8
8
|
|
|
9
|
-
It is one gate and runs **first**, before binding, `Arc.Filter`, authorization and validation.
|
|
9
|
+
It is one gate and runs **first**, before binding, `Cratis.Arc.Filter`, authorization and validation.
|
|
10
10
|
|
|
11
11
|
| Decision | Result |
|
|
12
12
|
| --- | --- |
|
|
@@ -29,7 +29,7 @@ config :my_app, MyApp.Arc,
|
|
|
29
29
|
|
|
30
30
|
```elixir
|
|
31
31
|
defmodule MyApp.Availability do
|
|
32
|
-
use Arc.Availability.Definition
|
|
32
|
+
use Cratis.Arc.Availability.Definition
|
|
33
33
|
|
|
34
34
|
audience "Plus", "Customers on the Plus package"
|
|
35
35
|
block "Paid", "Sold with Plus", for: ["Plus", "Admin"]
|
|
@@ -38,37 +38,37 @@ defmodule MyApp.Availability do
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
defmodule MyApp.Fleet.Vessels.DockVessel do
|
|
41
|
-
use Arc.Command
|
|
41
|
+
use Cratis.Arc.Command
|
|
42
42
|
available for: ["Plus", "Admin"], not: "Preview", with: "Reported"
|
|
43
|
-
available when: Arc.Availability.Condition.equal("vessel.package", "Plus")
|
|
43
|
+
available when: Cratis.Arc.Availability.Condition.equal("vessel.package", "Plus")
|
|
44
44
|
end
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
- `for:` audience(s), one is enough; `not:` none may be held; `with:` a named block; `when:` a condition
|
|
48
|
-
(`Arc.Availability.Condition` data shared with other languages, or a module implementing the behaviour).
|
|
48
|
+
(`Cratis.Arc.Availability.Condition` data shared with other languages, or a module implementing the behaviour).
|
|
49
49
|
- On a read model `available` gates every query; `@query available: [...]` gates one query.
|
|
50
|
-
- Module, feature and slice come from `Arc.Descriptor.slice_location/2`.
|
|
50
|
+
- Module, feature and slice come from `Cratis.Arc.Descriptor.slice_location/2`.
|
|
51
51
|
- Conditions read `tenant`, `identity.user`, `arguments.<name>` (camelCase wire name) and `<name>.<path>` of a
|
|
52
52
|
provided value; tenant and identity always come from the server.
|
|
53
53
|
- Three values: available, unavailable, unknown. Only available opens a gate; an absent value is unknown for every
|
|
54
|
-
operator. `Arc.Availability.Engine` passes the shared conformance cases.
|
|
54
|
+
operator. `Cratis.Arc.Availability.Engine` passes the shared conformance cases.
|
|
55
55
|
|
|
56
56
|
## Sources: audiences granted and withdrawn, parts suspended and resumed
|
|
57
57
|
|
|
58
|
-
- `Arc.Availability.AudienceSource`: `grants(subject)` returns the audience names held. Undeclared audiences never match.
|
|
59
|
-
- `Arc.Availability.SuspensionSource`: `suspended/0` returns paths (`"Fleet"`, `"Fleet/Vessels"`,
|
|
58
|
+
- `Cratis.Arc.Availability.AudienceSource`: `grants(subject)` returns the audience names held. Undeclared audiences never match.
|
|
59
|
+
- `Cratis.Arc.Availability.SuspensionSource`: `suspended/0` returns paths (`"Fleet"`, `"Fleet/Vessels"`,
|
|
60
60
|
`"Fleet/Vessels/Dock"`, or a part's full name); suspension is decided before any gate.
|
|
61
|
-
- `Arc.Availability.Memory` serves specifications and samples (`grant/2`, `withdraw/2`, `suspend/1`, `resume/1`).
|
|
62
|
-
- Call `Arc.Availability.changed/1` when a source changes; open sessions decide again, on every node with `:pubsub`.
|
|
61
|
+
- `Cratis.Arc.Availability.Memory` serves specifications and samples (`grant/2`, `withdraw/2`, `suspend/1`, `resume/1`).
|
|
62
|
+
- Call `Cratis.Arc.Availability.changed/1` when a source changes; open sessions decide again, on every node with `:pubsub`.
|
|
63
63
|
|
|
64
64
|
## Client
|
|
65
65
|
|
|
66
66
|
- `/.cratis/availability` is an observable query listing what is unavailable to the caller (name, module, feature,
|
|
67
67
|
slice, reason); `?part=<name>&arguments=<json>` asks about one part. A decision that cannot be made is a retryable error.
|
|
68
68
|
- Generated proxies carry `static readonly part` (part identity).
|
|
69
|
-
- LiveView: `<Arc.LiveView.Availability.available socket={@socket} version={@arc_availability} command={...}>`
|
|
70
|
-
hides a part (`Arc.LiveView.available?/3`). Hiding is presentation; the server still refuses.
|
|
71
|
-
- `Arc.Availability.Manifest.build/1`, `to_json/1`, `decode/1`, `decide/3` use the shared
|
|
69
|
+
- LiveView: `<Cratis.Arc.LiveView.Availability.available socket={@socket} version={@arc_availability} command={...}>`
|
|
70
|
+
hides a part (`Cratis.Arc.LiveView.available?/3`). Hiding is presentation; the server still refuses.
|
|
71
|
+
- `Cratis.Arc.Availability.Manifest.build/1`, `to_json/1`, `decode/1`, `decide/3` use the shared
|
|
72
72
|
`cratis-availability-manifest` (version 1).
|
|
73
73
|
|
|
74
74
|
## Rules
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
## Fields
|
|
7
7
|
|
|
8
8
|
Types: `:string`, `:integer`, `:float`, `:boolean`, `:uuid` (a `Guid` in TypeScript),
|
|
9
|
-
`:date` (`DateOnly`), `:datetime`, `:map`, `{:list, type}`, a `Chronicle.Concept` module (the
|
|
10
|
-
primitive it wraps) and a module that `use Arc.Schema`. **Nested lists are not supported.**
|
|
9
|
+
`:date` (`DateOnly`), `:datetime`, `:map`, `{:list, type}`, a `Cratis.Chronicle.Concept` module (the
|
|
10
|
+
primitive it wraps) and a module that `use Cratis.Arc.Schema`. **Nested lists are not supported.**
|
|
11
11
|
Options: `required: true`, `nullable:`, `key: true`, `default:`, `doc:`, `min_length`,
|
|
12
12
|
`max_length`, `email`, `matches`, `min`, `max`, `greater_than`, `less_than`.
|
|
13
13
|
|
|
14
|
-
Use a `Chronicle.Concept` for domain values such as an author id, so the type is declared
|
|
14
|
+
Use a `Cratis.Chronicle.Concept` for domain values such as an author id, so the type is declared
|
|
15
15
|
once and is what Chronicle records.
|
|
16
16
|
|
|
17
17
|
## Callbacks
|
|
@@ -32,8 +32,8 @@ A constraint or concurrency rejection never raises. It is a validation result wi
|
|
|
32
32
|
## Run from code
|
|
33
33
|
|
|
34
34
|
```elixir
|
|
35
|
-
result = Arc.execute(MyApp.Arc, %RegisterAuthor{id: Arc.new_id(), name: "Ada"}, principal: principal)
|
|
36
|
-
Arc.CommandResult.success?(result)
|
|
35
|
+
result = Cratis.Arc.execute(MyApp.Arc, %RegisterAuthor{id: Cratis.Arc.new_id(), name: "Ada"}, principal: principal)
|
|
36
|
+
Cratis.Arc.CommandResult.success?(result)
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
Pass `{RegisterAuthor, %{"id" => "...", "name" => "..."}}` to bind a wire map first.
|
|
@@ -46,7 +46,7 @@ Options: `principal:`, `tenant:`, `correlation_id:`, `metadata:`, `validate_only
|
|
|
46
46
|
`watch: [...]` and `topics: [...]`. Arguments arrive cast; a missing or wrongly typed
|
|
47
47
|
argument is `malformedRequest` before your function runs.
|
|
48
48
|
|
|
49
|
-
`use Arc.ReadModel, types: [id: :uuid]` overrides inferred field types for the proxies:
|
|
49
|
+
`use Cratis.Arc.ReadModel, types: [id: :uuid]` overrides inferred field types for the proxies:
|
|
50
50
|
a struct default of `""` or `nil` reads as a string.
|
|
51
51
|
|
|
52
52
|
## Paging and sorting
|
|
@@ -54,11 +54,11 @@ a struct default of `""` or `nil` reads as a string.
|
|
|
54
54
|
`page` (zero-based), `pageSize`, `sortBy` and `sortDirection` are reserved query-string
|
|
55
55
|
names, matched case-insensitively; `QUERY` requests carry them in the body. A returned
|
|
56
56
|
list is sorted and paged **in memory**. For a large collection page in the database and
|
|
57
|
-
return `%Arc.Page{items:, total:, page:, size:}`; Arc then does not touch the items.
|
|
57
|
+
return `%Cratis.Arc.Page{items:, total:, page:, size:}`; Arc then does not touch the items.
|
|
58
58
|
`ctx.query` holds the requested page, page size and sorting.
|
|
59
59
|
|
|
60
60
|
## Results
|
|
61
61
|
|
|
62
|
-
`Arc.CommandResult.to_wire/1` and `Arc.QueryResult.to_wire/1` are the contract envelopes.
|
|
62
|
+
`Cratis.Arc.CommandResult.to_wire/1` and `Cratis.Arc.QueryResult.to_wire/1` are the contract envelopes.
|
|
63
63
|
An exception becomes `exceptionMessages`; outside development the message is generic and
|
|
64
64
|
the detail is logged with the correlation id.
|
|
@@ -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
|
}
|