@cratis/pi 7.189.4 → 7.190.0

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.
@@ -43,6 +43,45 @@ are grounded in `Cratis/Chronicle.Elixir` 4.x (`Source/chronicle/mix.exs`,
43
43
  operational logging and keep credentials out of messages and crash reports.
44
44
  - Use American English in identifiers, comments and documentation.
45
45
 
46
+ ## Anti-patterns to avoid
47
+
48
+ Check new Elixir against the official anti-pattern pages (code, design, process and meta-programming
49
+ anti-patterns in the Elixir documentation). The ones that matter most here:
50
+
51
+ - **Never create atoms from input.** `String.to_atom/1` on a name that a user, a file or a wire message
52
+ supplies leaks atoms. Compare as strings, or map through an explicit table or
53
+ `String.to_existing_atom/1`. A bounded, developer-written set of names is acceptable.
54
+ - **Match the shape you need.** Use `%{key: value} = map` or `Map.fetch!/2` for required data; `Map.get/3`
55
+ and `opts[:key]` are for optional data, and a default must not hide a missing required value
56
+ (`Map.get(actor, :id) || "unknown"`). Prefer `%{parts: parts} <- state` to `x when x != nil <- state`.
57
+ - **Do not rescue to find out whether something exists.** Check with `function_exported?/3` (after
58
+ `Code.ensure_loaded?/1`) or a pattern match. `rescue _ ->` that returns a default swallows real errors;
59
+ rescue narrowly, around foreign code only.
60
+ - **Do not let `with ... else` carry business logic.** Make each step return a tagged result
61
+ (`:ok` or `{:error, reason}`) so `else` is unnecessary or has one clause per distinct failure. Do not
62
+ mix a boolean into a `with` (`true <- cond`); wrap it in a function that returns a tagged result.
63
+ - **Return one shape.** Do not let an option or an argument change the return type or select between
64
+ different outcomes (`outcome: "applied" | "failed"` choosing the event); use two functions or commands.
65
+ Use `{:error, :not_found}` rather than `{:ok, nil}` when absence is a failure for the caller.
66
+ - **Keep parameter lists short.** Three or four. When a function needs more, or discards most of them,
67
+ pass one map or struct. Do not keep an unused parameter.
68
+ - **Supervise processes.** No bare `Task.start/1` or `spawn` for work that must not fail silently; start it
69
+ under a `Task.Supervisor` in the supervision tree. A process dictionary value does not reach a `Task`.
70
+ - **Libraries do not read global application configuration.** Take options from the caller. An
71
+ application may call `Application.get_env/2` for its own settings, ideally in one settings module.
72
+ Compile-time config belongs in `Application.compile_env/3`.
73
+ - **Macros earn their place.** Use a macro for syntax a function cannot take (a declaration DSL, a block)
74
+ and `use` only to define or register something, not to import functions.
75
+ - **Stringly typed values stay at the boundary.** Wire strings (ids, ISO 8601 times, enum names) are fine in
76
+ events and commands; decide on atoms or structs inside the code.
77
+
78
+ ### Cohesion over file count
79
+
80
+ Do not split code only because a file is long or holds several modules. **High cohesion wins**: keep a
81
+ slice's command, its events and its specs next to each other, and a view's markup with the LiveView that
82
+ owns it. A module is too big when it has several reasons to change, not when it has many lines. These
83
+ anti-pattern fixes must not scatter a vertical slice across folders.
84
+
46
85
  ## Event-sourced applications on Arc and Chronicle
47
86
 
48
87
  Read the **cratis-arc-elixir** and **cratis-chronicle-client-elixir** skills before touching a slice.
@@ -57,8 +96,9 @@ Read the **cratis-arc-elixir** and **cratis-chronicle-client-elixir** skills bef
57
96
  never carries a secret.
58
97
  - **Every slice tells a whole story**: a state change has a command and the events it appends; a view
59
98
  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.
99
+ an event, runs a command and records the fact that command appends, so the event model shows what it
100
+ did. A reactor that calls a third party does not append events itself: it runs a `:system` command
101
+ (`Cratis.Arc.execute/3`) that records the outcome, and the command lives in the reactor's slice folder.
62
102
  - **Order is the story**: a slice that uses events of several sub-features goes in a sub-feature after
63
103
  them. Build with `arc: [event_model_strict: true]` so an incomplete model fails the build.
64
104
  - **Third parties are integrations behind a behaviour**, with an in-memory stand-in for specs; only
@@ -42,6 +42,45 @@ are grounded in `Cratis/Chronicle.Elixir` 4.x (`Source/chronicle/mix.exs`,
42
42
  operational logging and keep credentials out of messages and crash reports.
43
43
  - Use American English in identifiers, comments and documentation.
44
44
 
45
+ ## Anti-patterns to avoid
46
+
47
+ Check new Elixir against the official anti-pattern pages (code, design, process and meta-programming
48
+ anti-patterns in the Elixir documentation). The ones that matter most here:
49
+
50
+ - **Never create atoms from input.** `String.to_atom/1` on a name that a user, a file or a wire message
51
+ supplies leaks atoms. Compare as strings, or map through an explicit table or
52
+ `String.to_existing_atom/1`. A bounded, developer-written set of names is acceptable.
53
+ - **Match the shape you need.** Use `%{key: value} = map` or `Map.fetch!/2` for required data; `Map.get/3`
54
+ and `opts[:key]` are for optional data, and a default must not hide a missing required value
55
+ (`Map.get(actor, :id) || "unknown"`). Prefer `%{parts: parts} <- state` to `x when x != nil <- state`.
56
+ - **Do not rescue to find out whether something exists.** Check with `function_exported?/3` (after
57
+ `Code.ensure_loaded?/1`) or a pattern match. `rescue _ ->` that returns a default swallows real errors;
58
+ rescue narrowly, around foreign code only.
59
+ - **Do not let `with ... else` carry business logic.** Make each step return a tagged result
60
+ (`:ok` or `{:error, reason}`) so `else` is unnecessary or has one clause per distinct failure. Do not
61
+ mix a boolean into a `with` (`true <- cond`); wrap it in a function that returns a tagged result.
62
+ - **Return one shape.** Do not let an option or an argument change the return type or select between
63
+ different outcomes (`outcome: "applied" | "failed"` choosing the event); use two functions or commands.
64
+ Use `{:error, :not_found}` rather than `{:ok, nil}` when absence is a failure for the caller.
65
+ - **Keep parameter lists short.** Three or four. When a function needs more, or discards most of them,
66
+ pass one map or struct. Do not keep an unused parameter.
67
+ - **Supervise processes.** No bare `Task.start/1` or `spawn` for work that must not fail silently; start it
68
+ under a `Task.Supervisor` in the supervision tree. A process dictionary value does not reach a `Task`.
69
+ - **Libraries do not read global application configuration.** Take options from the caller. An
70
+ application may call `Application.get_env/2` for its own settings, ideally in one settings module.
71
+ Compile-time config belongs in `Application.compile_env/3`.
72
+ - **Macros earn their place.** Use a macro for syntax a function cannot take (a declaration DSL, a block)
73
+ and `use` only to define or register something, not to import functions.
74
+ - **Stringly typed values stay at the boundary.** Wire strings (ids, ISO 8601 times, enum names) are fine in
75
+ events and commands; decide on atoms or structs inside the code.
76
+
77
+ ### Cohesion over file count
78
+
79
+ Do not split code only because a file is long or holds several modules. **High cohesion wins**: keep a
80
+ slice's command, its events and its specs next to each other, and a view's markup with the LiveView that
81
+ owns it. A module is too big when it has several reasons to change, not when it has many lines. These
82
+ anti-pattern fixes must not scatter a vertical slice across folders.
83
+
45
84
  ## Event-sourced applications on Arc and Chronicle
46
85
 
47
86
  Read the **cratis-arc-elixir** and **cratis-chronicle-client-elixir** skills before touching a slice.
@@ -56,8 +95,9 @@ Read the **cratis-arc-elixir** and **cratis-chronicle-client-elixir** skills bef
56
95
  never carries a secret.
57
96
  - **Every slice tells a whole story**: a state change has a command and the events it appends; a view
58
97
  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.
98
+ an event, runs a command and records the fact that command appends, so the event model shows what it
99
+ did. A reactor that calls a third party does not append events itself: it runs a `:system` command
100
+ (`Cratis.Arc.execute/3`) that records the outcome, and the command lives in the reactor's slice folder.
61
101
  - **Order is the story**: a slice that uses events of several sub-features goes in a sub-feature after
62
102
  them. Build with `arc: [event_model_strict: true]` so an incomplete model fails the build.
63
103
  - **Third parties are integrations behind a behaviour**, with an in-memory stand-in for specs; only
@@ -57,7 +57,7 @@ The compiler reports what is incomplete (warnings; errors with `event_model_stri
57
57
  | --- | --- |
58
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
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 |
60
+ | an automation that reacts to no event, or records none | the reactor runs a command in its slice folder that appends the fact (`RecordSecretRetirement` appends `SecretRetiredInOry`); a slice with a reactor and its command is an automation showing reaction, command and event |
61
61
  | a consumed event no slice produces | the event needs a command appending it |
62
62
  | a fact used before it is produced | move the slice into a sub-feature after the ones it uses |
63
63
 
@@ -29,7 +29,7 @@
29
29
  | Mistake | What happens | Do this |
30
30
  | --- | --- | --- |
31
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 |
32
+ | A reactor that appends events itself or returns nothing | The automation slice shows no command or no events | Have the reactor run a command in its slice folder that appends the fact; Arc shows reaction, command and event |
33
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
34
  | Reading the last module segment as the name | The model shows the `id:` | Name by `id:` and keep `display_names:` in mind |
35
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 |
@@ -9,7 +9,7 @@
9
9
  | Elixir requirement | `~> 1.18` | `mix.exs` |
10
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. 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` |
12
+ | Release | Source preview. Every release is published to Hex automatically: depend on `{:cratis_arc, "~> 1.4"}` from Hex, never a path or git reference, and check hex.pm for the current version | repository, `gh release list` |
13
13
  | Module namespace | Everything is `Cratis.Arc.*` (`use Cratis.Arc.Command, id: "..."`); sources are under `Source/arc/lib/cratis/arc/` | repository |
14
14
  | Documented gaps | `Documentation/limits-and-gaps.md` | repository |
15
15
  | Contract | The Arc HTTP contract | Cratis/Arc `Documentation/http-contract.md` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.189.4",
3
+ "version": "7.190.0",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [