Skip to main content

ddd_toolkit_core/
lib.rs

1//! **English:**<br>
2//! Core traits for modeling Domain-Driven Design entities and value objects.
3//!
4//! [`Entity`] exposes a stable identifier by reference, while [`ValueObject`] exposes
5//! a wrapped value by reference or by value. Implement these traits on domain types to keep their
6//! domain-facing APIs independent from persistence details.
7//!
8//! For event-sourced aggregates, [`EventStore`] loads complete [`StreamHistory`] values
9//! and appends events using [`ExpectedRevision`]. [`AggregateReplay`] supplies reconstruction hooks
10//! for [`replay_aggregate`] and [`replay_with_optional_snapshot`]. [`SnapshotStore`] persists
11//! [`AggregateSnapshot`] values separately; adapters define storage and concurrency behavior.
12//!
13//! [`Secret`] wraps a value implementing `zeroize::Zeroize`, redacts its formatted
14//! output, and zeroizes it on drop. Access to the unredacted value is explicit; extracting it
15//! transfers responsibility for zeroization to the caller. [`SecretMetadata`] is a zero-sized
16//! marker and does not itself protect data.
17//!
18//! [`AsyncEventStore`] and [`AsyncSnapshotStore`] expose boxed `Send` futures for
19//! event and snapshot persistence. [`EventConsumer`] and [`Projection`] separate event handling
20//! from read-model updates, with asynchronous counterparts [`AsyncEventConsumer`] and
21//! [`AsyncProjection`]. [`DomainEventDeliveryMetadata`] optionally exposes [`DeliveryMetadata`].
22//! [`TransactionalOutbox`] separates save-and-enqueue, claim, and acknowledgement operations;
23//! adapters supply transactions and delivery policies, not this crate.
24//!
25//! [`TransactionalOutboxLifecycleContext`] tracks a single save-and-enqueue attempt.
26//! It pulls pending events without restoring them on failure, rejects repeated attempts, and
27//! reports missing or unsuccessful enqueueing at completion. It does not implement a transaction.
28//!
29//! [`AsyncTransactionalOutbox`] provides future-based outbox operations.
30//! [`AsyncTransactionalOutboxLifecycleContext`] consumes an attempt and pulls events before polling;
31//! dropping its future does not restore events. [`ProjectionCheckpoint`] carries application-defined
32//! progress for [`ProjectionCheckpointStore`], while [`IdempotentProjection`] reports applied or
33//! duplicate input via [`ProjectionApplication`]. Implementations supply duplicate detection and
34//! coordination between checkpoint persistence and read-model changes.
35//!
36//! [`AsyncProjectionCheckpointStore`] persists progress through boxed `Send` futures,
37//! and [`AsyncIdempotentProjection`] asynchronously distinguishes new application from duplicates.
38//! These independent ports do not coordinate transactions; dropping a future does not guarantee
39//! rollback or absence of side effects. Implementations define cancellation and retry semantics.
40//!
41//! [`Specification`] composes fallible predicates with short-circuiting [`And`],
42//! [`Or`], and [`Not`]. [`DomainService`], [`Policy`], and [`DomainFactory`] define typed operation,
43//! rule-checking, and construction boundaries without prescribing persistence or thread safety.
44//! [`ProcessManager`] returns a [`Transition`] of state and effect descriptions for callers to
45//! store and execute. [`UnitOfWork`] exposes explicit registration, commit, and rollback ports;
46//! implementations define their transaction guarantees. [`EventIdentity`] and [`VersionedEvent`]
47//! describe event schemas, while [`UpcasterChain`] applies [`EventUpcaster`] stages in insertion
48//! order without automatically selecting versions.
49//!
50//! **日本語:**<br>
51//! ドメイン駆動設計のエンティティと値オブジェクトを表現するためのコアトレイトを提供します。
52//!
53//! [`Entity`] は安定した識別子を参照で公開し、[`ValueObject`] は内包値を参照または
54//! 値で公開します。永続化の詳細から独立したドメイン型の API を保つために、これらのトレイトを実装します。
55//!
56//! イベントソーシングを使う集約では、[`EventStore`] が完全な [`StreamHistory`] を
57//! 読み込み、[`ExpectedRevision`] を条件にイベントを追加します。[`AggregateReplay`] は
58//! [`replay_aggregate`] と [`replay_with_optional_snapshot`] の復元フックを定めます。
59//! [`SnapshotStore`] は [`AggregateSnapshot`] を別途永続化し、保存や並行処理の挙動は
60//! アダプターが定めます。
61//!
62//! [`Secret`] は `zeroize::Zeroize` を実装する値を包み、書式出力を秘匿化し、
63//! 破棄時にゼロ化します。秘匿化していない値には明示的にアクセスし、値を取り出した後の
64//! ゼロ化は呼び出し側が管理します。[`SecretMetadata`] はサイズがゼロのマーカーであり、
65//! それ自体はデータを保護しません。
66//!
67//! [`AsyncEventStore`] と [`AsyncSnapshotStore`] はイベントとスナップショットの
68//! 永続化を、ボックス化された `Send` Future で公開します。[`EventConsumer`] と [`Projection`]
69//! はイベント処理と読み取りモデル更新を分け、非同期版の [`AsyncEventConsumer`] と
70//! [`AsyncProjection`] も提供します。[`DomainEventDeliveryMetadata`] は任意で
71//! [`DeliveryMetadata`] を公開します。[`TransactionalOutbox`] は保存・登録、取得、確認応答を
72//! 分離します。トランザクションと配信方針はこのクレートではなくアダプターが提供します。
73//!
74//! [`TransactionalOutboxLifecycleContext`] は保存・登録の一回の試行を追跡します。
75//! 保留イベントを取り出して失敗時も復元せず、繰り返しの試行を拒否し、完了確認時に
76//! 未試行や未成功を報告します。トランザクション自体は実装しません。
77//!
78//! [`AsyncTransactionalOutbox`] は Future によるアウトボックス操作を提供します。
79//! [`AsyncTransactionalOutboxLifecycleContext`] はポーリング前に試行を消費してイベントを取り出し、
80//! Future の破棄でも復元しません。[`ProjectionCheckpoint`] はアプリケーション定義の進捗を
81//! [`ProjectionCheckpointStore`] に渡し、[`IdempotentProjection`] は適用または重複を
82//! [`ProjectionApplication`] で報告します。重複検出と、チェックポイント永続化・読み取りモデル変更の
83//! 連携は実装が提供します。
84//!
85//! [`AsyncProjectionCheckpointStore`] はボックス化された `Send` Future で進捗を永続化し、
86//! [`AsyncIdempotentProjection`] は新規適用と重複を非同期に区別します。これらの独立したポートは
87//! トランザクションを調整せず、Future の破棄はロールバックや副作用の不在を保証しません。
88//! キャンセルと再試行の意味は実装が定めます。
89//!
90//! [`Specification`] は失敗し得る述語を、短絡評価する [`And`]、[`Or`]、[`Not`] で
91//! 結合します。[`DomainService`]、[`Policy`]、[`DomainFactory`] は永続化やスレッド安全性を
92//! 規定せず、型付きの操作、規則確認、構築の境界を定めます。[`ProcessManager`] は状態と
93//! 副作用の記述を [`Transition`] で返し、保存と実行は呼び出し側が担います。[`UnitOfWork`] は
94//! 明示的な登録、コミット、ロールバックのポートであり、トランザクションの保証は実装が定めます。
95//! [`EventIdentity`] と [`VersionedEvent`] はイベントのスキーマを表し、[`UpcasterChain`] は
96//! バージョンを自動選択せず、[`EventUpcaster`] の段階を追加順に適用します。
97
98// Generated derives use the library name in both library and consumer targets.
99extern crate self as ddd_toolkit_core;
100
101mod aggregate_root;
102mod async_dispatch;
103mod async_domain_event_publisher;
104mod async_event_consumption;
105mod async_event_store;
106mod async_outbox_lifecycle;
107mod async_repository;
108mod async_snapshot;
109mod async_transactional_outbox;
110mod cqrs;
111mod dispatch;
112mod domain_event;
113mod domain_event_conversion;
114mod domain_event_metadata;
115mod domain_event_publisher;
116mod domain_factory;
117mod domain_service;
118mod entity;
119mod event_consumption;
120mod event_delivery_metadata;
121mod event_restoration_guard;
122mod event_store;
123mod event_versioning;
124mod outbox_lifecycle;
125mod process_manager;
126mod projection_reliability;
127mod replay;
128mod repository;
129mod secret;
130mod secret_metadata;
131mod snapshot;
132mod specification;
133mod transactional_outbox;
134mod unit_of_work;
135mod value_object;
136
137pub use aggregate_root::AggregateRoot;
138
139pub use async_dispatch::dispatch_events_async;
140
141pub use async_domain_event_publisher::AsyncDomainEventPublisher;
142
143pub use async_event_consumption::{AsyncEventConsumer, AsyncProjection};
144
145pub use async_event_store::AsyncEventStore;
146
147pub use async_outbox_lifecycle::{
148    AsyncOutboxLifecycleCompletionError, AsyncOutboxLifecycleContext,
149    AsyncOutboxLifecycleOperationError, AsyncTransactionalOutboxCompletionError,
150    AsyncTransactionalOutboxLifecycleContext, AsyncTransactionalOutboxOperationError,
151};
152
153pub use async_repository::AsyncRepository;
154
155pub use async_snapshot::AsyncSnapshotStore;
156
157pub use async_transactional_outbox::AsyncTransactionalOutbox;
158
159pub use cqrs::{
160    AggregateCreator, AsyncAggregateCreator, AsyncCommandHandler, AsyncLifecycleCallback,
161    AsyncLifecycleContext, AsyncQueryHandler, CommandHandler, LifecycleCallback,
162    LifecycleCompletionError, LifecycleContext, LifecycleOperationError, QueryHandler,
163};
164
165pub use dispatch::dispatch_events;
166
167pub use domain_event::DomainEvent;
168
169pub use domain_event_conversion::DomainEventConversion;
170
171pub use domain_event_metadata::DomainEventMetadata;
172
173pub use domain_event_publisher::DomainEventPublisher;
174
175pub use domain_factory::DomainFactory;
176
177pub use domain_service::{DomainService, Policy};
178
179pub use entity::Entity;
180
181pub use event_consumption::{EventConsumer, Projection};
182
183pub use event_delivery_metadata::{DeliveryMetadata, DomainEventDeliveryMetadata};
184
185pub use event_store::{
186    AppendError, AppendResult, CurrentRevision, EventStore, ExpectedRevision, LoadResult, NoStream,
187    RevisionConflict, StreamHistory, StreamHistoryError, StreamRevision,
188};
189
190pub use event_versioning::{EventIdentity, EventUpcaster, UpcasterChain, VersionedEvent};
191
192pub use outbox_lifecycle::{
193    OutboxLifecycleCompletionError, OutboxLifecycleContext, OutboxLifecycleOperationError,
194    TransactionalOutboxCompletionError, TransactionalOutboxLifecycleContext,
195    TransactionalOutboxOperationError,
196};
197
198pub use process_manager::{ProcessManager, Transition};
199
200pub use projection_reliability::{
201    AsyncIdempotentProjection, AsyncProjectionCheckpointStore, IdempotentProjection,
202    ProjectionApplication, ProjectionCheckpoint, ProjectionCheckpointStore,
203};
204
205pub use replay::{
206    AggregateReplay, RehydratedAggregate, ReplayError, SnapshotReplayError, replay_aggregate,
207    replay_with_optional_snapshot,
208};
209
210pub use repository::Repository;
211
212pub use secret::Secret;
213
214pub use secret_metadata::SecretMetadata;
215
216pub use snapshot::{
217    AggregateSnapshot, SnapshotLoadError, SnapshotSaveError, SnapshotStore, SnapshotUse,
218};
219
220pub use specification::{And, Not, Or, Specification};
221
222pub use transactional_outbox::{OutboxClaim, OutboxMessageId, TransactionalOutbox};
223
224pub use unit_of_work::UnitOfWork;
225
226pub use value_object::ValueObject;
227
228#[doc(hidden)]
229/// **English:**<br>
230/// Internal access to the optional `serde` dependency for generated implementations.
231///
232/// **日本語:**<br>
233/// 生成された実装から任意依存の `serde` にアクセスするための内部モジュールです。
234pub mod __private {
235    /// **English:**<br>
236    /// Re-exports the optional `serde` crate for macro-generated code.
237    ///
238    /// **日本語:**<br>
239    /// マクロが生成したコードで使うために、任意依存の `serde` クレートを再エクスポートします。
240    #[cfg(feature = "serde")]
241    pub use serde;
242}