distributed 4.8.0

CQRS/ES framework for Rust using Plain Old Rust Structs — append-only events, replay, snapshots, outbox, service bus, and pluggable infrastructure
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
//! Per-shard stream store: in-process stand-in for one cell's private SQLite.
//!
//! Production celld wraps rusqlite (or workers-rs storage) the same way: sync
//! calls inside async fns. This is **not** `feature = "sqlite"` (sqlx pool) and
//! **not** a `celld` dialect.

use std::future::Future;
use std::sync::{Arc, Mutex};

use serde_json::Value;

use crate::command_ledger::{
    AttemptFence, CausalCommitBatch, CausalGetStream, CausalRepositoryIdentity,
    CausalStorageIdentity, CausalTransactionalCommit, CommandLedgerError, CommandLedgerKey,
    CommandLedgerStore, CommandLookup, CommandLookupScope, CommandReservation, ReservationOutcome,
};
use crate::entity::{Entity, EventRecord};
use crate::microsvc::HasOutboxStore;
use crate::outbox::OutboxMessage;
use crate::projection_protocol::{
    ProjectionChangeCursor, ProjectionChangeRead, ProjectionCheckpoint, ProjectionCommitBatch,
    ProjectionCommitResult, ProjectionFailure, ProjectionFailureBatch, ProjectionFailureLocation,
    ProjectionGeneration, ProjectionInputCursor, ProjectionInputDisposition,
    ProjectionLiveRecordBatch, ProjectionLiveRecordBatchRequest, ProjectionModelOwnership,
    ProjectionObligationEvidenceBatch, ProjectionObligationEvidenceBatchRequest,
    ProjectionObservation, ProjectionObservationKind, ProjectionPartition,
    ProjectionPartitionRuntimeState, ProjectionProtocolError, ProjectionProtocolStore,
    ProjectionQuerySnapshot, ProjectionQuerySnapshotBatch, ProjectionQuerySnapshotBatchRequest,
    ProjectionQuerySnapshotRequest, ProjectionRecordMetadata, ProjectionRecordScope,
    ProjectorTopologyId, TrustedProjectionInput,
};
use crate::repository::{
    CommitBatch, GetStream, RepositoryError, SnapshotStore, SnapshotWrite, StreamIdentity,
    TransactionalCommit,
};
use crate::snapshot::SnapshotRecord;
use crate::{InMemoryOutboxStore, InMemoryRepository};
use serde::{Deserialize, Serialize};

#[derive(Clone)]
enum CellOwnership {
    /// One stream identity (Todo, BlobGame). Foreign streams are rejected.
    Exclusive(StreamIdentity),
    /// Parent game cell: map/player/bomb/explosion/saga streams share this
    /// cell's private SQLite. There is no API to commit across two cells.
    Parent {
        name: StreamIdentity,
        owns: Arc<dyn Fn(&StreamIdentity) -> bool + Send + Sync>,
    },
}

/// Private SQLite stand-in for one cell instance (`{aggregate_type}:{shard}`).
///
/// Exclusive cells reject any stream that is not this cell's shard. Parent
/// cells (`for_parent_shard`) hold sibling streams of one game and commit
/// them in one [`CommitBatch`].
///
/// ```compile_fail
/// fn two_cell_transaction_does_not_exist(
///     left: &distributed::cell_host::CellStreamStore,
///     right: &distributed::cell_host::CellStreamStore,
///     batch: distributed::CommitBatch<'_>,
/// ) {
///     let _ = left.commit_across(right, batch);
/// }
/// ```

/// One stream's event records for Durable Object SQLite persistence.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct DurableCellEvents {
    pub stream: String,
    pub events: Vec<EventRecord>,
}

/// Snapshot cache record for Durable Object SQLite persistence.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct DurableCellSnapshot {
    pub stream: String,
    pub aggregate_type: String,
    pub aggregate_id: String,
    pub version: u64,
    pub snapshot_version: u64,
    pub payload_codec: String,
    pub payload_codec_version: u16,
    pub payload: Vec<u8>,
}

/// One versioned command-ledger row for Durable Object SQLite persistence.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct DurableCellCommand {
    pub id: String,
    pub body: String,
}

/// Current persisted aggregate-cell state envelope version.
pub const DURABLE_AGGREGATE_CELL_STATE_VERSION: u16 = 1;

/// Complete durable working copy for one aggregate cell.
///
/// Hosts should serialize this value and persist it with one storage write.
/// That makes the event log, snapshot cache, command ledger, outbox, and sealed
/// row one commit even when a Worker SDK does not expose celld's
/// `transactionSync` API.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct DurableAggregateCellState {
    pub version: u16,
    pub events: Vec<DurableCellEvents>,
    pub snapshots: Vec<DurableCellSnapshot>,
    pub commands: Vec<DurableCellCommand>,
    pub outbox: Vec<OutboxMessage>,
    pub sealed_row: Option<Value>,
}

#[derive(Clone)]
pub struct CellStreamStore {
    ownership: CellOwnership,
    inner: InMemoryRepository,
    sealed_row: Arc<Mutex<Option<Value>>>,
}

impl CellStreamStore {
    /// Bind a store to one exact stream identity.
    pub fn for_identity(identity: StreamIdentity) -> Self {
        Self {
            ownership: CellOwnership::Exclusive(identity),
            inner: InMemoryRepository::new(),
            sealed_row: Arc::new(Mutex::new(None)),
        }
    }

    /// Parent-shard cell: `"{parent_type}:{parent_id}"` (bomberman `game:{id}`).
    ///
    /// Child streams of any aggregate type live in this cell's SQLite. A
    /// transaction across two parent cells does not exist.
    pub fn for_parent_shard(
        parent_type: impl Into<String>,
        parent_id: impl Into<String>,
        owns: impl Fn(&StreamIdentity) -> bool + Send + Sync + 'static,
    ) -> Result<Self, RepositoryError> {
        Ok(Self {
            ownership: CellOwnership::Parent {
                name: StreamIdentity::new(parent_type, parent_id)?,
                owns: Arc::new(owns),
            },
            inner: InMemoryRepository::new(),
            sealed_row: Arc::new(Mutex::new(None)),
        })
    }

    /// Named exclusive-cell constructor used by [`super::AggregateCell`].
    pub fn new(
        aggregate_type: impl Into<String>,
        shard_id: impl Into<String>,
    ) -> Result<Self, RepositoryError> {
        Ok(Self::for_identity(StreamIdentity::new(
            aggregate_type,
            shard_id,
        )?))
    }

    /// Cell instance name (`type:id`).
    pub fn instance_name(&self) -> String {
        match &self.ownership {
            CellOwnership::Exclusive(identity) | CellOwnership::Parent { name: identity, .. } => {
                identity.to_string()
            }
        }
    }

    /// Stream this exclusive cell owns. Parent cells have no single stream.
    pub fn identity(&self) -> Option<&StreamIdentity> {
        match &self.ownership {
            CellOwnership::Exclusive(identity) => Some(identity),
            CellOwnership::Parent { .. } => None,
        }
    }

    fn ensure_identity(&self, identity: &StreamIdentity) -> Result<(), RepositoryError> {
        match &self.ownership {
            CellOwnership::Parent { owns, .. } if owns(identity) => Ok(()),
            CellOwnership::Parent { name, .. } => Err(RepositoryError::Model(format!(
                "parent cell {name} does not own stream {identity}"
            ))),
            CellOwnership::Exclusive(owned) if identity == owned => Ok(()),
            CellOwnership::Exclusive(owned) => Err(RepositoryError::Model(format!(
                "cell `{owned}` cannot access stream `{identity}`"
            ))),
        }
    }

    /// Sealed read-model row for GET on this cell instance.
    pub fn sealed_row(&self) -> Result<Option<Value>, RepositoryError> {
        self.sealed_row
            .lock()
            .map(|guard| guard.clone())
            .map_err(|_| RepositoryError::Model("cell sealed row lock poisoned".into()))
    }

    /// Replace the sealed read-model row (Atomic board / Todo view).
    pub fn replace_sealed_row(&self, row: Value) -> Result<(), RepositoryError> {
        let mut guard = self
            .sealed_row
            .lock()
            .map_err(|_| RepositoryError::Model("cell sealed row lock poisoned".into()))?;
        *guard = Some(row);
        Ok(())
    }

    /// Event log for Durable Object SQLite. Memory remains the working copy.
    pub fn durable_events(&self) -> Result<Vec<DurableCellEvents>, RepositoryError> {
        Ok(self
            .inner
            .clone_events()?
            .into_iter()
            .map(|(stream, events)| DurableCellEvents { stream, events })
            .collect())
    }

    /// Outbox rows committed with this cell's events (same private SQLite).
    pub fn durable_outbox(&self) -> Result<Vec<OutboxMessage>, RepositoryError> {
        self.inner.clone_outbox()
    }

    /// Restore outbox rows from Durable Object SQLite.
    pub fn restore_durable_outbox(
        &self,
        messages: Vec<OutboxMessage>,
    ) -> Result<(), RepositoryError> {
        self.inner.replace_outbox(messages)
    }

    /// Replace the working event log from Durable Object SQLite.
    pub fn restore_durable_events(
        &self,
        events: Vec<DurableCellEvents>,
    ) -> Result<(), RepositoryError> {
        self.inner.replace_events(
            events
                .into_iter()
                .map(|row| (row.stream, row.events))
                .collect(),
        )
    }

    /// Snapshot cache for Durable Object SQLite.
    pub fn durable_snapshots(&self) -> Result<Vec<DurableCellSnapshot>, RepositoryError> {
        Ok(self
            .inner
            .clone_snapshots()?
            .into_iter()
            .map(|(stream, record)| DurableCellSnapshot {
                stream,
                aggregate_type: record.aggregate_type,
                aggregate_id: record.aggregate_id,
                version: record.version,
                snapshot_version: record.snapshot_version,
                payload_codec: record.payload_codec,
                payload_codec_version: record.payload_codec_version,
                payload: record.payload,
            })
            .collect())
    }

    /// Replace the working snapshot cache from Durable Object SQLite.
    pub fn restore_durable_snapshots(
        &self,
        snapshots: Vec<DurableCellSnapshot>,
    ) -> Result<(), RepositoryError> {
        self.inner.replace_snapshots(
            snapshots
                .into_iter()
                .map(|row| {
                    (
                        row.stream,
                        SnapshotRecord {
                            aggregate_type: row.aggregate_type,
                            aggregate_id: row.aggregate_id,
                            version: row.version,
                            snapshot_version: row.snapshot_version,
                            payload_codec: row.payload_codec,
                            payload_codec_version: row.payload_codec_version,
                            payload: row.payload,
                            metadata: Default::default(),
                            recorded_at: crate::time::now(),
                        },
                    )
                })
                .collect(),
        )
    }

    /// Fenced command rows committed with this cell's domain effects.
    pub fn durable_commands(&self) -> Result<Vec<DurableCellCommand>, RepositoryError> {
        self.inner
            .clone_command_ledger()?
            .into_iter()
            .map(|record| {
                let id = record.durable_cell_key();
                let body = record
                    .durable_cell_json()
                    .map_err(|error| RepositoryError::Model(error.to_string()))?;
                Ok(DurableCellCommand { id, body })
            })
            .collect()
    }

    /// Restore the complete command ledger before accepting another request.
    pub fn restore_durable_commands(
        &self,
        commands: Vec<DurableCellCommand>,
    ) -> Result<(), RepositoryError> {
        let mut records = Vec::with_capacity(commands.len());
        for command in commands {
            let record =
                crate::command_ledger::CommandLedgerRecord::from_durable_cell_json(&command.body)
                    .map_err(|error| RepositoryError::Model(error.to_string()))?;
            if record.durable_cell_key() != command.id {
                return Err(RepositoryError::Model(
                    "cell command ledger row key does not match its body".into(),
                ));
            }
            records.push(record);
        }
        self.inner.replace_command_ledger(records)
    }

    /// Export every durable concern as one versioned persistence envelope.
    pub fn durable_state(&self) -> Result<DurableAggregateCellState, RepositoryError> {
        Ok(DurableAggregateCellState {
            version: DURABLE_AGGREGATE_CELL_STATE_VERSION,
            events: self.durable_events()?,
            snapshots: self.durable_snapshots()?,
            commands: self.durable_commands()?,
            outbox: self.durable_outbox()?,
            sealed_row: self.sealed_row()?,
        })
    }

    /// Replace the complete working copy from one persisted envelope.
    pub fn restore_durable_state(
        &self,
        state: DurableAggregateCellState,
    ) -> Result<(), RepositoryError> {
        if state.version != DURABLE_AGGREGATE_CELL_STATE_VERSION {
            return Err(RepositoryError::Model(format!(
                "unsupported durable aggregate cell state version {}",
                state.version
            )));
        }

        // Parse and validate the command ledger before replacing the other
        // working-copy components; malformed persisted JSON must fail closed.
        self.restore_durable_commands(state.commands)?;
        self.restore_durable_events(state.events)?;
        self.restore_durable_snapshots(state.snapshots)?;
        self.restore_durable_outbox(state.outbox)?;
        let mut sealed = self
            .sealed_row
            .lock()
            .map_err(|_| RepositoryError::Model("cell sealed row lock poisoned".into()))?;
        *sealed = state.sealed_row;
        Ok(())
    }

    fn ensure_batch(&self, batch: &CommitBatch<'_>) -> Result<(), RepositoryError> {
        for stream in &batch.streams {
            self.ensure_identity(&stream.identity)?;
        }
        for snapshot in &batch.snapshots {
            match snapshot {
                SnapshotWrite::Save { identity, .. } => self.ensure_identity(identity)?,
            }
        }
        Ok(())
    }
}

impl CausalGetStream for CellStreamStore {
    fn get_causal_stream<'a>(
        &'a self,
        identity: &'a StreamIdentity,
    ) -> impl Future<Output = Result<Option<Entity>, RepositoryError>> + Send + 'a {
        async move {
            self.ensure_identity(identity)?;
            CausalGetStream::get_causal_stream(&self.inner, identity).await
        }
    }
}

impl GetStream for CellStreamStore {
    fn get_stream<'a>(
        &'a self,
        identity: &'a StreamIdentity,
    ) -> impl Future<Output = Result<Option<Entity>, RepositoryError>> + Send + 'a {
        async move {
            self.ensure_identity(identity)?;
            GetStream::get_stream(&self.inner, identity).await
        }
    }

    fn get_stream_tail<'a>(
        &'a self,
        identity: &'a StreamIdentity,
        after_version: u64,
    ) -> impl Future<Output = Result<Option<Entity>, RepositoryError>> + Send + 'a {
        async move {
            self.ensure_identity(identity)?;
            GetStream::get_stream_tail(&self.inner, identity, after_version).await
        }
    }
}

impl SnapshotStore for CellStreamStore {
    fn get_snapshot<'a>(
        &'a self,
        identity: &'a StreamIdentity,
    ) -> impl Future<Output = Result<Option<SnapshotRecord>, RepositoryError>> + Send + 'a {
        async move {
            self.ensure_identity(identity)?;
            SnapshotStore::get_snapshot(&self.inner, identity).await
        }
    }

    fn get_snapshots<'a>(
        &'a self,
        identities: &'a [StreamIdentity],
    ) -> impl Future<Output = Result<Vec<SnapshotRecord>, RepositoryError>> + Send + 'a {
        async move {
            for identity in identities {
                self.ensure_identity(identity)?;
            }
            SnapshotStore::get_snapshots(&self.inner, identities).await
        }
    }

    fn save_snapshot<'a>(
        &'a self,
        identity: &'a StreamIdentity,
        record: SnapshotRecord,
    ) -> impl Future<Output = Result<(), RepositoryError>> + Send + 'a {
        async move {
            self.ensure_identity(identity)?;
            SnapshotStore::save_snapshot(&self.inner, identity, record).await
        }
    }

    fn delete_snapshot<'a>(
        &'a self,
        identity: &'a StreamIdentity,
    ) -> impl Future<Output = Result<bool, RepositoryError>> + Send + 'a {
        async move {
            self.ensure_identity(identity)?;
            SnapshotStore::delete_snapshot(&self.inner, identity).await
        }
    }
}

impl CausalRepositoryIdentity for CellStreamStore {
    fn causal_storage_identity(&self) -> CausalStorageIdentity {
        CausalRepositoryIdentity::causal_storage_identity(&self.inner)
    }
}

impl CommandLedgerStore for CellStreamStore {
    fn reserve_command(
        &self,
        reservation: CommandReservation,
    ) -> impl Future<Output = Result<ReservationOutcome, CommandLedgerError>> + Send + '_ {
        CommandLedgerStore::reserve_command(&self.inner, reservation)
    }

    fn lookup_command<'a>(
        &'a self,
        key: &'a CommandLedgerKey,
        scope: CommandLookupScope<'a>,
    ) -> impl Future<Output = Result<CommandLookup, CommandLedgerError>> + Send + 'a {
        CommandLedgerStore::lookup_command(&self.inner, key, scope)
    }

    fn mark_retryable_unknown(
        &self,
        attempt: AttemptFence,
    ) -> impl Future<Output = Result<(), CommandLedgerError>> + Send + '_ {
        CommandLedgerStore::mark_retryable_unknown(&self.inner, attempt)
    }

    fn compact_expired_commands(
        &self,
        limit: usize,
    ) -> impl Future<Output = Result<u64, CommandLedgerError>> + Send + '_ {
        CommandLedgerStore::compact_expired_commands(&self.inner, limit)
    }
}

impl TransactionalCommit for CellStreamStore {
    fn commit_batch<'a>(
        &'a self,
        batch: CommitBatch<'a>,
    ) -> impl Future<Output = Result<(), RepositoryError>> + Send + 'a {
        async move {
            self.ensure_batch(&batch)?;
            TransactionalCommit::commit_batch(&self.inner, batch).await
        }
    }
}

impl CausalTransactionalCommit for CellStreamStore {
    fn commit_causal_batch<'a>(
        &'a self,
        batch: CausalCommitBatch<'a>,
    ) -> impl Future<Output = Result<(), CommandLedgerError>> + Send + 'a {
        async move {
            self.ensure_batch(&batch.domain)
                .map_err(CommandLedgerError::Storage)?;
            CausalTransactionalCommit::commit_causal_batch(&self.inner, batch).await
        }
    }
}

impl HasOutboxStore for CellStreamStore {
    type OutboxStore = InMemoryOutboxStore;

    fn outbox_store(&self) -> Self::OutboxStore {
        self.inner.outbox_store()
    }
}

impl ProjectionProtocolStore for CellStreamStore {
    fn register_projection_models<'a>(
        &'a self,
        topology: &'a ProjectorTopologyId,
        ownership: &'a [ProjectionModelOwnership],
    ) -> impl Future<Output = Result<(), ProjectionProtocolError>> + Send + 'a {
        self.inner.register_projection_models(topology, ownership)
    }

    fn commit_projection(
        &self,
        batch: ProjectionCommitBatch,
    ) -> impl Future<Output = Result<ProjectionCommitResult, ProjectionProtocolError>> + Send + '_
    {
        self.inner.commit_projection(batch)
    }

    fn record_projection_failure(
        &self,
        batch: ProjectionFailureBatch,
    ) -> impl Future<Output = Result<ProjectionFailure, ProjectionProtocolError>> + Send + '_ {
        self.inner.record_projection_failure(batch)
    }

    fn projection_checkpoint<'a>(
        &'a self,
        cursor_scope: &'a ProjectionInputCursor,
        generation: ProjectionGeneration,
    ) -> impl Future<Output = Result<Option<ProjectionCheckpoint>, ProjectionProtocolError>> + Send + 'a
    {
        self.inner.projection_checkpoint(cursor_scope, generation)
    }

    fn projection_record<'a>(
        &'a self,
        scope: &'a ProjectionRecordScope,
    ) -> impl Future<Output = Result<Option<ProjectionRecordMetadata>, ProjectionProtocolError>>
           + Send
           + 'a {
        self.inner.projection_record(scope)
    }

    fn projection_input_disposition<'a>(
        &'a self,
        input: &'a TrustedProjectionInput,
    ) -> impl Future<Output = Result<ProjectionInputDisposition, ProjectionProtocolError>> + Send + 'a
    {
        self.inner.projection_input_disposition(input)
    }

    fn projection_query_snapshot<'a>(
        &'a self,
        request: &'a ProjectionQuerySnapshotRequest,
    ) -> impl Future<Output = Result<ProjectionQuerySnapshot, ProjectionProtocolError>> + Send + 'a
    {
        self.inner.projection_query_snapshot(request)
    }

    fn projection_query_snapshot_batch<'a>(
        &'a self,
        request: &'a ProjectionQuerySnapshotBatchRequest,
    ) -> impl Future<Output = Result<ProjectionQuerySnapshotBatch, ProjectionProtocolError>> + Send + 'a
    {
        self.inner.projection_query_snapshot_batch(request)
    }

    fn projection_obligation_evidence_batch<'a>(
        &'a self,
        request: &'a ProjectionObligationEvidenceBatchRequest,
    ) -> impl Future<Output = Result<ProjectionObligationEvidenceBatch, ProjectionProtocolError>>
           + Send
           + 'a {
        self.inner.projection_obligation_evidence_batch(request)
    }

    fn projection_live_record_batch<'a>(
        &'a self,
        request: &'a ProjectionLiveRecordBatchRequest,
    ) -> impl Future<Output = Result<ProjectionLiveRecordBatch, ProjectionProtocolError>> + Send + 'a
    {
        self.inner.projection_live_record_batch(request)
    }

    fn projection_partition_runtime_state<'a>(
        &'a self,
        topology: &'a ProjectorTopologyId,
        partition: &'a ProjectionPartition,
    ) -> impl Future<Output = Result<Option<ProjectionPartitionRuntimeState>, ProjectionProtocolError>>
           + Send
           + 'a {
        self.inner
            .projection_partition_runtime_state(topology, partition)
    }

    fn projection_observation<'a>(
        &'a self,
        causation_id: &'a str,
        scope: &'a ProjectionRecordScope,
        kind: ProjectionObservationKind,
    ) -> impl Future<Output = Result<Option<ProjectionObservation>, ProjectionProtocolError>> + Send + 'a
    {
        self.inner.projection_observation(causation_id, scope, kind)
    }

    fn projection_changes<'a>(
        &'a self,
        topology: &'a ProjectorTopologyId,
        partition: &'a ProjectionPartition,
        after: Option<&'a ProjectionChangeCursor>,
        limit: usize,
    ) -> impl Future<Output = Result<ProjectionChangeRead, ProjectionProtocolError>> + Send + 'a
    {
        self.inner
            .projection_changes(topology, partition, after, limit)
    }

    fn repair_projection<'a>(
        &'a self,
        topology: &'a ProjectorTopologyId,
        partition: &'a ProjectionPartition,
        failure_id: &'a str,
    ) -> impl Future<Output = Result<ProjectionGeneration, ProjectionProtocolError>> + Send + 'a
    {
        self.inner
            .repair_projection(topology, partition, failure_id)
    }

    fn compact_projection_changes<'a>(
        &'a self,
        through: &'a ProjectionChangeCursor,
    ) -> impl Future<Output = Result<u64, ProjectionProtocolError>> + Send + 'a {
        self.inner.compact_projection_changes(through)
    }

    fn projection_failure<'a>(
        &'a self,
        topology: &'a ProjectorTopologyId,
        partition: &'a ProjectionPartition,
        failure_id: &'a str,
    ) -> impl Future<Output = Result<Option<ProjectionFailure>, ProjectionProtocolError>> + Send + 'a
    {
        self.inner
            .projection_failure(topology, partition, failure_id)
    }

    fn projection_failure_location<'a>(
        &'a self,
        failure_id: &'a str,
    ) -> impl Future<Output = Result<Option<ProjectionFailureLocation>, ProjectionProtocolError>>
           + Send
           + 'a {
        self.inner.projection_failure_location(failure_id)
    }
}