Skip to content

fix: infer optimistic constants from flat domain events - #230

Open
patrickleet wants to merge 1 commit into
v5from
fix/flat-event-preview
Open

fix: infer optimistic constants from flat domain events#230
patrickleet wants to merge 1 commit into
v5from
fix/flat-event-preview

Conversation

@patrickleet

@patrickleet patrickleet commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Why

Flat domain events should drive optimistic UI just as snapshot events do. A transition that records "approved" already defines the result; application authors should not repeat it in a preview declaration or client-side status mapping.

What changes

#[sourced] now derives known event-body values from literal arguments to direct domain = event recorder calls. The existing typed command and projection pipeline carries those constants into generated client slots. No new public configuration, event shape, or storage format is required.

pub fn approve(&mut self, id: String) -> distributed::SourcedResult {
    self.record_status(id, "approved".into())?;
    Ok(())
}

#[event("review.status_recorded", version = 1, domain = event)]
fn record_status(&mut self, id: String, status: String) {
    self.entity.set_id(id);
    self.status = status;
}

Before: a command selecting domain_commands::Approve exported an unknown status.
After: a projection consuming that field receives the known "approved" constant without an additional preview declaration.

Inference stays deliberately conservative: computed IDs, clocks, arbitrary calls, variables, and conflicting recorder arguments remain unknown. Numeric literals retain their recorder parameter type. Optional literals require fully qualified standard constructors so locally shadowed Some/None are not mistaken for values. Server authorization and confirmed projection events remain authoritative.

Two existing macro Clippy findings were corrected without suppressions while validating the change.

Verification

  • cargo test --test sourced --test sourced_snapshot --features graphql,sqlite --offline --quiet: 27 + 15 pass, including flat event payload parity, conflicting/dynamic arguments, shadowed constructors, and generated client projection slots.
  • cargo test --lib --features graphql,sqlite --offline --quiet: 994 pass.
  • cargo test --test typed_commands --features graphql,sqlite --offline --quiet: 27 pass.
  • cargo test -p distributed_macros --offline --quiet: unit and compile-fail suites pass.
  • Strict macro Clippy, format, and diff checks pass.
  • cargo test --offline --quiet: default-feature library and integration suites pass (761 library tests; pre-existing ignored documentation examples remain ignored).
  • PR CI is running; not yet claiming all checks have passed.

UI copy

No application UI or user-facing copy changes. "approved" above is a domain-value example in documentation and tests, not new rendered interface copy.

Implements the flat-event-preview specification and tasks/distributed-flat-event-preview-1.

Implements [[tasks/distributed-flat-event-preview-1]]
@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: ed44e5af-2786-4083-926a-8476b50b772e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant