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_store;
122mod event_versioning;
123mod outbox_lifecycle;
124mod process_manager;
125mod projection_reliability;
126mod replay;
127mod repository;
128mod secret;
129mod secret_metadata;
130mod snapshot;
131mod specification;
132mod transactional_outbox;
133mod unit_of_work;
134mod value_object;
135
136pub use aggregate_root::AggregateRoot;
137
138pub use async_dispatch::dispatch_events_async;
139
140pub use async_domain_event_publisher::AsyncDomainEventPublisher;
141
142pub use async_event_consumption::{AsyncEventConsumer, AsyncProjection};
143
144pub use async_event_store::AsyncEventStore;
145
146pub use async_outbox_lifecycle::{
147 AsyncOutboxLifecycleCompletionError, AsyncOutboxLifecycleContext,
148 AsyncOutboxLifecycleOperationError, AsyncTransactionalOutboxCompletionError,
149 AsyncTransactionalOutboxLifecycleContext, AsyncTransactionalOutboxOperationError,
150};
151
152pub use async_repository::AsyncRepository;
153
154pub use async_snapshot::AsyncSnapshotStore;
155
156pub use async_transactional_outbox::AsyncTransactionalOutbox;
157
158pub use cqrs::{
159 AggregateCreator, AsyncAggregateCreator, AsyncCommandHandler, AsyncLifecycleCallback,
160 AsyncLifecycleContext, AsyncQueryHandler, CommandHandler, LifecycleCallback,
161 LifecycleCompletionError, LifecycleContext, LifecycleOperationError, QueryHandler,
162};
163
164pub use dispatch::dispatch_events;
165
166pub use domain_event::DomainEvent;
167
168pub use domain_event_conversion::DomainEventConversion;
169
170pub use domain_event_metadata::DomainEventMetadata;
171
172pub use domain_event_publisher::DomainEventPublisher;
173
174pub use domain_factory::DomainFactory;
175
176pub use domain_service::{DomainService, Policy};
177
178pub use entity::Entity;
179
180pub use event_consumption::{EventConsumer, Projection};
181
182pub use event_delivery_metadata::{DeliveryMetadata, DomainEventDeliveryMetadata};
183
184pub use event_store::{
185 AppendError, AppendResult, CurrentRevision, EventStore, ExpectedRevision, LoadResult, NoStream,
186 RevisionConflict, StreamHistory, StreamHistoryError, StreamRevision,
187};
188
189pub use event_versioning::{EventIdentity, EventUpcaster, UpcasterChain, VersionedEvent};
190
191pub use outbox_lifecycle::{
192 OutboxLifecycleCompletionError, OutboxLifecycleContext, OutboxLifecycleOperationError,
193 TransactionalOutboxCompletionError, TransactionalOutboxLifecycleContext,
194 TransactionalOutboxOperationError,
195};
196
197pub use process_manager::{ProcessManager, Transition};
198
199pub use projection_reliability::{
200 AsyncIdempotentProjection, AsyncProjectionCheckpointStore, IdempotentProjection,
201 ProjectionApplication, ProjectionCheckpoint, ProjectionCheckpointStore,
202};
203
204pub use replay::{
205 AggregateReplay, RehydratedAggregate, ReplayError, SnapshotReplayError, replay_aggregate,
206 replay_with_optional_snapshot,
207};
208
209pub use repository::Repository;
210
211pub use secret::Secret;
212
213pub use secret_metadata::SecretMetadata;
214
215pub use snapshot::{
216 AggregateSnapshot, SnapshotLoadError, SnapshotSaveError, SnapshotStore, SnapshotUse,
217};
218
219pub use specification::{And, Not, Or, Specification};
220
221pub use transactional_outbox::{OutboxClaim, OutboxMessageId, TransactionalOutbox};
222
223pub use unit_of_work::UnitOfWork;
224
225pub use value_object::ValueObject;
226
227#[cfg(feature = "serde")]
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 pub use serde;
241}