feat: add change data capture pattern#496
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Pull request overview
Adds the Change Data Capture (CDC) pattern across PatternKit’s runtime, source-generator route, examples, benchmarks, docs, and production-readiness catalogs, aligning with the repo’s “pattern must be covered by tests + docs + examples + benchmarks” approach.
Changes:
- Introduces
ChangeDataCapturePipeline<TMutation,TEvent>with anIChangeDataCaptureStoreabstraction and an in-memory store implementation. - Adds
[GenerateChangeDataCapture]+ChangeDataCaptureGeneratorwith diagnostics and generator tests. - Adds a DI-importable Product Catalog CDC demo, catalog/coverage wiring, docs, and benchmark coverage entries.
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/PatternKit.Tests/Messaging/ChangeDataCapture/ChangeDataCapturePipelineTests.cs | Adds runtime TinyBDD coverage for ordered capture/publish and failure retry tracking. |
| test/PatternKit.Generators.Tests/ChangeDataCaptureGeneratorTests.cs | Adds generator output + diagnostics + attribute contract tests. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs | Updates catalog assertions to include CDC and adjusts expected family counts. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitBenchmarkCoverageTests.cs | Updates expected benchmark-route totals for the new pattern. |
| test/PatternKit.Examples.Tests/ChangeDataCaptureDemo/ProductCatalogChangeDataCaptureDemoTests.cs | Validates fluent vs generated demo behavior and DI importability. |
| src/PatternKit.Generators/ChangeDataCapture/ChangeDataCaptureGenerator.cs | Implements incremental generator emitting a CDC pipeline factory + diagnostics. |
| src/PatternKit.Generators/AnalyzerReleases.Unshipped.md | Registers new PKCDC diagnostics in analyzer release notes. |
| src/PatternKit.Generators.Abstractions/ChangeDataCapture/ChangeDataCaptureAttributes.cs | Adds the [GenerateChangeDataCapture] attribute definition. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs | Registers CDC pattern metadata for production-readiness catalog. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs | Registers the Product Catalog CDC example in the example catalog. |
| src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs | Adds DI wiring for the new example in the examples extension surface. |
| src/PatternKit.Examples/ChangeDataCaptureDemo/ProductCatalogChangeDataCaptureDemo.cs | Adds demo domain types, fluent + generated policies, and IServiceCollection extension. |
| src/PatternKit.Core/Messaging/ChangeDataCapture/ChangeDataCapturePipeline.cs | Adds CDC runtime primitives, store abstraction, in-memory store, and pipeline behavior. |
| README.md | Updates pattern counts and benchmark matrix placeholders for CDC. |
| docs/patterns/toc.yml | Adds CDC to the patterns TOC. |
| docs/patterns/messaging/change-data-capture.md | Adds the CDC pattern documentation page. |
| docs/index.md | Updates pattern counts and pattern table to include CDC. |
| docs/guides/benchmark-results.md | Updates benchmark matrix placeholders + coverage matrix counts and generator matrix entries. |
| docs/generators/toc.yml | Adds CDC generator docs to generator TOC. |
| docs/generators/index.md | Adds CDC generator to the generators index table and sample attribute list. |
| docs/generators/change-data-capture.md | Adds detailed CDC generator documentation + diagnostics list. |
| docs/examples/toc.yml | Adds Product Catalog CDC demo to examples TOC. |
| docs/examples/product-catalog-change-data-capture.md | Adds documentation page for the new CDC demo. |
| docs/examples/index.md | Adds CDC demo to examples landing page. |
| benchmarks/PatternKit.Benchmarks/Messaging/ChangeDataCaptureBenchmarks.cs | Adds BenchmarkDotNet coverage for fluent vs generated CDC routes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Test Results 12 files 12 suites 12m 42s ⏱️ Results for commit b07a2c4. ♻️ This comment has been updated with latest results. |
🔍 PR Validation ResultsVersion: `` ✅ Validation Steps
📊 ArtifactsDry-run artifacts have been uploaded and will be available for 7 days. This comment was automatically generated by the PR validation workflow. |
994e47e to
9601592
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #496 +/- ##
==========================================
- Coverage 97.40% 97.40% -0.01%
==========================================
Files 595 599 +4
Lines 48648 49014 +366
Branches 3138 34 -3104
==========================================
+ Hits 47385 47741 +356
- Misses 1263 1273 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
9601592 to
b07a2c4
Compare
| public static Builder Create(string name = "change-data-capture") => new(name); | ||
|
|
||
| public async ValueTask<ChangeDataCaptureEntry<TMutation, TEvent>> CaptureAsync( | ||
| TMutation mutation, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
| if (mutation is null) | ||
| throw new ArgumentNullException(nameof(mutation)); | ||
|
|
||
| var nextSequence = await _store.GetNextSequenceAsync(Name, cancellationToken).ConfigureAwait(false); | ||
| var @event = _eventFactory(mutation, nextSequence); | ||
| return await _store.AppendAsync(Name, nextSequence, mutation, @event, _utcNow(), cancellationToken).ConfigureAwait(false); | ||
| } |
| | ID | Severity | Message | | ||
| | --- | --- | --- | | ||
| | `PKCDC001` | Error | The host type must be partial. | | ||
| | `PKCDC002` | Error | Factory and mapper method names must be valid C# identifiers. | | ||
| | `PKCDC003` | Error | Mutation and event types are required. | | ||
|
|
| var pipeline = ChangeDataCapturePipeline<ProductMutation, ProductChanged> | ||
| .Create("product-catalog-cdc") | ||
| .UseStore(store) | ||
| .MapWith((mutation, sequence) => new ProductChanged(sequence, mutation.Sku, mutation.Name)) | ||
| .PublishWith((changed, ct) => publisher.PublishAsync(changed, ct)) | ||
| .Build(); | ||
|
|
||
| await pipeline.CaptureAsync(new ProductMutation("sku-1", "Desk")); | ||
| await pipeline.PublishPendingAsync(); |
Code Coverage |
Closes #485.
Summary
Validation