ddd_toolkit_core/lib.rs
1//! **English:** Core traits for modeling Domain-Driven Design entities and value objects.
2//!
3//! **日本語:** ドメイン駆動設計のエンティティと値オブジェクトを表現するためのコアトレイトを提供します。
4//!
5//! **English:** [`Entity`] exposes a stable identifier by reference, while [`ValueObject`] exposes
6//! a wrapped value by reference or by value. Implement these traits on domain types to keep their
7//! domain-facing APIs independent from persistence details.
8//!
9//! **日本語:** [`Entity`] は安定した識別子を参照で公開し、[`ValueObject`] は内包値を参照または
10//! 値で公開します。永続化の詳細から独立したドメイン型の API を保つために、これらのトレイトを実装します。
11//!
12//! **English:** For event-sourced aggregates, [`EventStore`] loads complete [`StreamHistory`] values
13//! and appends events using [`ExpectedRevision`]. [`AggregateReplay`] supplies reconstruction hooks
14//! for [`replay_aggregate`] and [`replay_with_optional_snapshot`]. [`SnapshotStore`] persists
15//! [`AggregateSnapshot`] values separately; adapters define storage and concurrency behavior.
16//!
17//! **日本語:** イベントソーシングを使う集約では、[`EventStore`] が完全な [`StreamHistory`] を
18//! 読み込み、[`ExpectedRevision`] を条件にイベントを追加します。[`AggregateReplay`] は
19//! [`replay_aggregate`] と [`replay_with_optional_snapshot`] の復元フックを定めます。
20//! [`SnapshotStore`] は [`AggregateSnapshot`] を別途永続化し、保存や並行処理の挙動は
21//! アダプターが定めます。
22//!
23//! **English:** [`Secret`] wraps a value implementing `zeroize::Zeroize`, redacts its formatted
24//! output, and zeroizes it on drop. Access to the unredacted value is explicit; extracting it
25//! transfers responsibility for zeroization to the caller. [`SecretMetadata`] is a zero-sized
26//! marker and does not itself protect data.
27//!
28//! **日本語:** [`Secret`] は `zeroize::Zeroize` を実装する値を包み、書式出力を秘匿化し、
29//! 破棄時にゼロ化します。秘匿化していない値には明示的にアクセスし、値を取り出した後の
30//! ゼロ化は呼び出し側が管理します。[`SecretMetadata`] はサイズがゼロのマーカーであり、
31//! それ自体はデータを保護しません。
32//!
33//! **English:** [`AsyncEventStore`] and [`AsyncSnapshotStore`] expose boxed `Send` futures for
34//! event and snapshot persistence. [`EventConsumer`] and [`Projection`] separate event handling
35//! from read-model updates, with asynchronous counterparts [`AsyncEventConsumer`] and
36//! [`AsyncProjection`]. [`DomainEventDeliveryMetadata`] optionally exposes [`DeliveryMetadata`].
37//! [`TransactionalOutbox`] separates save-and-enqueue, claim, and acknowledgement operations;
38//! adapters supply transactions and delivery policies, not this crate.
39//!
40//! **日本語:** [`AsyncEventStore`] と [`AsyncSnapshotStore`] はイベントとスナップショットの
41//! 永続化を、ボックス化された `Send` Future で公開します。[`EventConsumer`] と [`Projection`]
42//! はイベント処理と読み取りモデル更新を分け、非同期版の [`AsyncEventConsumer`] と
43//! [`AsyncProjection`] も提供します。[`DomainEventDeliveryMetadata`] は任意で
44//! [`DeliveryMetadata`] を公開します。[`TransactionalOutbox`] は保存・登録、取得、確認応答を
45//! 分離します。トランザクションと配信方針はこのクレートではなくアダプターが提供します。
46//!
47//! **English:** [`TransactionalOutboxLifecycleContext`] tracks a single save-and-enqueue attempt.
48//! It pulls pending events without restoring them on failure, rejects repeated attempts, and
49//! reports missing or unsuccessful enqueueing at completion. It does not implement a transaction.
50//!
51//! **日本語:** [`TransactionalOutboxLifecycleContext`] は保存・登録の一回の試行を追跡します。
52//! 保留イベントを取り出して失敗時も復元せず、繰り返しの試行を拒否し、完了確認時に
53//! 未試行や未成功を報告します。トランザクション自体は実装しません。
54//!
55//! **English:** [`AsyncTransactionalOutbox`] provides future-based outbox operations.
56//! [`AsyncTransactionalOutboxLifecycleContext`] consumes an attempt and pulls events before polling;
57//! dropping its future does not restore events. [`ProjectionCheckpoint`] carries application-defined
58//! progress for [`ProjectionCheckpointStore`], while [`IdempotentProjection`] reports applied or
59//! duplicate input via [`ProjectionApplication`]. Implementations supply duplicate detection and
60//! coordination between checkpoint persistence and read-model changes.
61//!
62//! **日本語:** [`AsyncTransactionalOutbox`] は Future によるアウトボックス操作を提供します。
63//! [`AsyncTransactionalOutboxLifecycleContext`] はポーリング前に試行を消費してイベントを取り出し、
64//! Future の破棄でも復元しません。[`ProjectionCheckpoint`] はアプリケーション定義の進捗を
65//! [`ProjectionCheckpointStore`] に渡し、[`IdempotentProjection`] は適用または重複を
66//! [`ProjectionApplication`] で報告します。重複検出と、チェックポイント永続化・読み取りモデル変更の
67//! 連携は実装が提供します。
68
69//!
70//! **English:** [`AsyncProjectionCheckpointStore`] persists progress through boxed `Send` futures,
71//! and [`AsyncIdempotentProjection`] asynchronously distinguishes new application from duplicates.
72//! These independent ports do not coordinate transactions; dropping a future does not guarantee
73//! rollback or absence of side effects. Implementations define cancellation and retry semantics.
74//!
75//! **日本語:** [`AsyncProjectionCheckpointStore`] はボックス化された `Send` Future で進捗を永続化し、
76//! [`AsyncIdempotentProjection`] は新規適用と重複を非同期に区別します。これらの独立したポートは
77//! トランザクションを調整せず、Future の破棄はロールバックや副作用の不在を保証しません。
78//! キャンセルと再試行の意味は実装が定めます。
79//!
80//! **English:** [`Specification`] composes fallible predicates with short-circuiting [`And`],
81//! [`Or`], and [`Not`]. [`DomainService`], [`Policy`], and [`DomainFactory`] define typed operation,
82//! rule-checking, and construction boundaries without prescribing persistence or thread safety.
83//! [`ProcessManager`] returns a [`Transition`] of state and effect descriptions for callers to
84//! store and execute. [`UnitOfWork`] exposes explicit registration, commit, and rollback ports;
85//! implementations define their transaction guarantees. [`EventIdentity`] and [`VersionedEvent`]
86//! describe event schemas, while [`UpcasterChain`] applies [`EventUpcaster`] stages in insertion
87//! order without automatically selecting versions.
88//!
89//! **日本語:** [`Specification`] は失敗し得る述語を、短絡評価する [`And`]、[`Or`]、[`Not`] で
90//! 結合します。[`DomainService`]、[`Policy`]、[`DomainFactory`] は永続化やスレッド安全性を
91//! 規定せず、型付きの操作、規則確認、構築の境界を定めます。[`ProcessManager`] は状態と
92//! 副作用の記述を [`Transition`] で返し、保存と実行は呼び出し側が担います。[`UnitOfWork`] は
93//! 明示的な登録、コミット、ロールバックのポートであり、トランザクションの保証は実装が定めます。
94//! [`EventIdentity`] と [`VersionedEvent`] はイベントのスキーマを表し、[`UpcasterChain`] は
95//! バージョンを自動選択せず、[`EventUpcaster`] の段階を追加順に適用します。
96
97mod aggregate_root;
98mod async_dispatch;
99mod async_domain_event_publisher;
100mod async_event_consumption;
101mod async_event_store;
102mod async_outbox_lifecycle;
103mod async_repository;
104mod async_snapshot;
105mod async_transactional_outbox;
106mod cqrs;
107mod dispatch;
108mod domain_event;
109mod domain_event_conversion;
110mod domain_event_metadata;
111mod domain_event_publisher;
112mod domain_factory;
113mod domain_service;
114mod entity;
115mod event_consumption;
116mod event_delivery_metadata;
117mod event_store;
118mod event_versioning;
119mod outbox_lifecycle;
120mod process_manager;
121mod projection_reliability;
122mod replay;
123mod repository;
124mod secret;
125mod secret_metadata;
126mod snapshot;
127mod specification;
128mod transactional_outbox;
129mod unit_of_work;
130mod value_object;
131
132/// **English:** Re-exports the [`aggregate_root::AggregateRoot`] trait for the crate's public API.
133///
134/// **日本語:** [`aggregate_root::AggregateRoot`] トレイトをクレートの公開 API として再エクスポートします。
135pub use aggregate_root::AggregateRoot;
136
137/// **English:** Re-exports [`async_dispatch::dispatch_events_async`] to publish aggregate events
138/// asynchronously with restoration of pulled events if publishing fails.
139///
140/// **日本語:** 発行に失敗した場合に取り出したイベントを復元しながら、集約イベントを非同期発行する
141/// [`async_dispatch::dispatch_events_async`] を再エクスポートします。
142pub use async_dispatch::dispatch_events_async;
143
144/// **English:** Re-exports [`async_domain_event_publisher::AsyncDomainEventPublisher`], the trait
145/// implemented by asynchronous domain-event publishers.
146///
147/// **日本語:** 非同期ドメインイベントパブリッシャーが実装するトレイト
148/// [`async_domain_event_publisher::AsyncDomainEventPublisher`] を再エクスポートします。
149pub use async_domain_event_publisher::AsyncDomainEventPublisher;
150
151/// **English:** Exposes asynchronous event handling and read-model update ports.
152///
153/// **日本語:** 非同期イベント処理と読み取りモデル更新のポートを公開します。
154pub use async_event_consumption::{AsyncEventConsumer, AsyncProjection};
155
156/// **English:** Exposes [`async_event_store::AsyncEventStore`] for future-based event persistence.
157///
158/// **日本語:** Future によるイベント永続化の [`async_event_store::AsyncEventStore`] を公開します。
159pub use async_event_store::AsyncEventStore;
160
161/// **English:** Exposes asynchronous single-attempt enqueue tracking, errors, and their short aliases.
162///
163/// **日本語:** 非同期登録の一回の試行追跡、エラー、短い別名を公開します。
164pub use async_outbox_lifecycle::{
165 AsyncOutboxLifecycleCompletionError, AsyncOutboxLifecycleContext,
166 AsyncOutboxLifecycleOperationError, AsyncTransactionalOutboxCompletionError,
167 AsyncTransactionalOutboxLifecycleContext, AsyncTransactionalOutboxOperationError,
168};
169
170/// **English:** Re-exports [`async_repository::AsyncRepository`], the trait for asynchronous
171/// persistence operations on aggregates.
172///
173/// **日本語:** 集約に対する非同期永続化操作のトレイト [`async_repository::AsyncRepository`] を
174/// 再エクスポートします。
175pub use async_repository::AsyncRepository;
176
177/// **English:** Exposes [`async_snapshot::AsyncSnapshotStore`] for asynchronous snapshot storage.
178///
179/// **日本語:** 非同期スナップショット保存の [`async_snapshot::AsyncSnapshotStore`] を公開します。
180pub use async_snapshot::AsyncSnapshotStore;
181
182/// **English:** Exposes [`async_transactional_outbox::AsyncTransactionalOutbox`] for asynchronous save, claim, and acknowledgement.
183///
184/// **日本語:** 非同期の保存、取得、確認応答の [`async_transactional_outbox::AsyncTransactionalOutbox`] を公開します。
185pub use async_transactional_outbox::AsyncTransactionalOutbox;
186
187/// **English:** Re-exports synchronous and asynchronous CQRS handlers, aggregate creators, and lifecycle APIs.
188///
189/// **日本語:** 同期・非同期の CQRS ハンドラー、集約作成器、ライフサイクル API を再エクスポートします。
190pub use cqrs::{
191 AggregateCreator, AsyncAggregateCreator, AsyncCommandHandler, AsyncLifecycleCallback,
192 AsyncLifecycleContext, AsyncQueryHandler, CommandHandler, LifecycleCallback,
193 LifecycleCompletionError, LifecycleContext, LifecycleOperationError, QueryHandler,
194};
195
196/// **English:** Publishes all currently pending events from an aggregate.
197///
198/// Events are published in the order returned by [`AggregateRoot::pull_events`]. If publishing any
199/// event fails, the events returned from the aggregate are recorded back into it before the error
200/// is returned. Events already accepted by the publisher are not rolled back, so retrying may
201/// publish them again. On success, the pulled events are discarded from the aggregate.
202///
203/// **日本語:** 集約に現在保留されているすべてのイベントを発行します。
204///
205/// イベントは [`AggregateRoot::pull_events`] が返した順序で発行されます。いずれかのイベントの
206/// 発行に失敗すると、集約から取り出したイベントを集約へ記録し直してからエラーを返します。
207/// パブリッシャーがすでに受理したイベントはロールバックされないため、再試行時に重複して
208/// 発行される可能性があります。成功した場合、取り出したイベントは集約から破棄されます。
209///
210/// [`dispatch_events`] は [`DomainEventPublisher::publish`] のエラーをそのまま返します。
211/// [`AggregateRoot::pull_events`] または [`AggregateRoot::record_event`] のパニック条件は、
212/// それぞれの実装に従います。
213pub use dispatch::dispatch_events;
214
215/// **English:** Re-exports the [`domain_event::DomainEvent`] marker trait for the crate's public API.
216///
217/// **日本語:** [`domain_event::DomainEvent`] マーカートレイトをクレートの公開 API として再エクスポートします。
218pub use domain_event::DomainEvent;
219
220/// **English:** Re-exports [`domain_event_conversion::DomainEventConversion`] for converting a domain event into another representation.
221///
222/// **日本語:** ドメインイベントを別の表現へ変換する [`domain_event_conversion::DomainEventConversion`] トレイトを再エクスポートします。
223pub use domain_event_conversion::DomainEventConversion;
224
225/// **English:** Re-exports [`domain_event_metadata::DomainEventMetadata`] for describing an event name, version, and optional metadata.
226///
227/// **日本語:** イベント名、バージョン、任意のメタデータを記述する [`domain_event_metadata::DomainEventMetadata`] トレイトを再エクスポートします。
228pub use domain_event_metadata::DomainEventMetadata;
229
230/// **English:** Re-exports the [`domain_event_publisher::DomainEventPublisher`] trait for publishing domain events.
231///
232/// **日本語:** ドメインイベントを発行する [`domain_event_publisher::DomainEventPublisher`] トレイトを再エクスポートします。
233pub use domain_event_publisher::DomainEventPublisher;
234
235/// **English:** Exposes [`domain_factory::DomainFactory`] for fallible construction from owned input.
236///
237/// **日本語:** 所有する入力からの失敗し得る構築に使う [`domain_factory::DomainFactory`] を公開します。
238pub use domain_factory::DomainFactory;
239
240/// **English:** Exposes typed domain operations and borrowed-context policy checks.
241///
242/// **日本語:** 型付きのドメイン操作と、コンテキストを借用するポリシー確認を公開します。
243pub use domain_service::{DomainService, Policy};
244
245/// **English:** Re-exports the [`entity::Entity`] trait for the crate's public API.
246///
247/// **日本語:** [`entity::Entity`] トレイトをクレートの公開 API として再エクスポートします。
248pub use entity::Entity;
249
250/// **English:** Exposes synchronous event consumption and projection update contracts.
251///
252/// **日本語:** 同期イベント処理とプロジェクション更新の契約を公開します。
253pub use event_consumption::{EventConsumer, Projection};
254
255/// **English:** Exposes delivery identifier containers and opt-in metadata access for events.
256///
257/// **日本語:** 配信識別子のコンテナーとイベントの任意メタデータアクセスを公開します。
258pub use event_delivery_metadata::{DeliveryMetadata, DomainEventDeliveryMetadata};
259
260/// **English:** Re-exports event-stream storage contracts, revision checks, and validated histories.
261///
262/// **日本語:** イベントストリームの保存契約、リビジョン照合、検証済み履歴を再エクスポートします。
263pub use event_store::{
264 AppendError, AppendResult, CurrentRevision, EventStore, ExpectedRevision, LoadResult, NoStream,
265 RevisionConflict, StreamHistory, StreamHistoryError, StreamRevision,
266};
267
268/// **English:** Exposes event schema identities and insertion-ordered, fallible upcasting stages.
269///
270/// **日本語:** イベントのスキーマ識別情報と、追加順の失敗し得る変換段階を公開します。
271pub use event_versioning::{EventIdentity, EventUpcaster, UpcasterChain, VersionedEvent};
272
273/// **English:** Exposes the single-attempt outbox lifecycle context, its errors, and their short aliases.
274///
275/// **日本語:** 一回のみ試行するアウトボックスのライフサイクルコンテキスト、エラー、短い別名を公開します。
276pub use outbox_lifecycle::{
277 OutboxLifecycleCompletionError, OutboxLifecycleContext, OutboxLifecycleOperationError,
278 TransactionalOutboxCompletionError, TransactionalOutboxLifecycleContext,
279 TransactionalOutboxOperationError,
280};
281
282/// **English:** Exposes process transition computation and owned state/effect results.
283///
284/// **日本語:** プロセスの遷移計算と、所有された状態・副作用の結果を公開します。
285pub use process_manager::{ProcessManager, Transition};
286
287/// **English:** Exposes typed projection progress and synchronous/asynchronous checkpoint and duplicate-aware application ports.
288///
289/// **日本語:** 型付きのプロジェクション進捗と、同期・非同期のチェックポイント保存および重複を区別する適用ポートを公開します。
290pub use projection_reliability::{
291 AsyncIdempotentProjection, AsyncProjectionCheckpointStore, IdempotentProjection,
292 ProjectionApplication, ProjectionCheckpoint, ProjectionCheckpointStore,
293};
294
295/// **English:** Re-exports aggregate reconstruction hooks, replay helpers, results, and failure types.
296///
297/// **日本語:** 集約復元フック、再生ヘルパー、結果、失敗の型を再エクスポートします。
298pub use replay::{
299 AggregateReplay, RehydratedAggregate, ReplayError, SnapshotReplayError, replay_aggregate,
300 replay_with_optional_snapshot,
301};
302
303/// **English:** Re-exports the [`repository::Repository`] trait for the crate's public API.
304///
305/// **日本語:** [`repository::Repository`] トレイトをクレートの公開 API として再エクスポートします。
306pub use repository::Repository;
307
308/// **English:** Exposes [`secret::Secret`] for redacted formatting and zeroization on drop.
309///
310/// **日本語:** 書式出力の秘匿化と破棄時のゼロ化を行う [`secret::Secret`] を公開します。
311pub use secret::Secret;
312
313/// **English:** Exposes [`secret_metadata::SecretMetadata`], a marker with no stored secret value.
314///
315/// **日本語:** 秘密の値を保持しないマーカー [`secret_metadata::SecretMetadata`] を公開します。
316pub use secret_metadata::SecretMetadata;
317
318/// **English:** Re-exports snapshot state containers, classification, storage contracts, and errors.
319///
320/// **日本語:** スナップショット状態コンテナー、分類、保存契約、エラーを再エクスポートします。
321pub use snapshot::{
322 AggregateSnapshot, SnapshotLoadError, SnapshotSaveError, SnapshotStore, SnapshotUse,
323};
324
325/// **English:** Exposes fallible specifications and their short-circuiting boolean wrappers.
326///
327/// **日本語:** 失敗し得る仕様と、短絡評価する論理演算のラッパーを公開します。
328pub use specification::{And, Not, Or, Specification};
329
330/// **English:** Exposes the outbox persistence port, owned claims, and acknowledgement identifiers.
331///
332/// **日本語:** アウトボックス永続化ポート、所有された取得結果、確認応答用の識別子を公開します。
333pub use transactional_outbox::{OutboxClaim, OutboxMessageId, TransactionalOutbox};
334
335/// **English:** Exposes [`unit_of_work::UnitOfWork`] for explicit change registration and transaction requests.
336///
337/// **日本語:** 明示的な変更登録とトランザクション要求に使う [`unit_of_work::UnitOfWork`] を公開します。
338pub use unit_of_work::UnitOfWork;
339
340/// **English:** Re-exports the [`value_object::ValueObject`] trait for the crate's public API.
341///
342/// **日本語:** [`value_object::ValueObject`] トレイトをクレートの公開 API として再エクスポートします。
343pub use value_object::ValueObject;
344
345#[cfg(feature = "serde")]
346#[doc(hidden)]
347/// **English:** Internal access to the optional `serde` dependency for generated implementations.
348///
349/// **日本語:** 生成された実装から任意依存の `serde` にアクセスするための内部モジュールです。
350pub mod __private {
351 /// **English:** Re-exports the optional `serde` crate for macro-generated code.
352 ///
353 /// **日本語:** マクロが生成したコードで使うために、任意依存の `serde` クレートを再エクスポートします。
354 pub use serde;
355}