diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-04 15:42:00 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-04 15:42:00 +0000 |
| commit | 819866330c7e2f535a155d1d7efaf2e12dc15dc2 (patch) | |
| tree | d84c8361811544aad9cad089c0358b9028c8fb80 /src/nostr/policy/mod.rs | |
| parent | fd0c87c787d0626b3546fa571541c9c809711821 (diff) | |
refactor: split Nip34WritePolicy into focused sub-policies
Split the ~900 line Nip34WritePolicy into focused sub-policies for improved
testability and maintainability:
- AnnouncementPolicy - Repository announcement validation
- StatePolicy - State event validation + ref alignment
- PrEventPolicy - PR/PR Update validation
- RelatedEventPolicy - Forward/backward reference checking
The main Nip34WritePolicy now delegates to these sub-policies via a shared
PolicyContext that provides domain, database, and git_data_path.
Also updates:
- README.md: Accurate project structure reflecting actual implementation
- docs/learnings: Marks this technical debt item as complete
Diffstat (limited to 'src/nostr/policy/mod.rs')
| -rw-r--r-- | src/nostr/policy/mod.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/nostr/policy/mod.rs b/src/nostr/policy/mod.rs new file mode 100644 index 0000000..6d67394 --- /dev/null +++ b/src/nostr/policy/mod.rs | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | /// Policy module for NIP-34 write policies | ||
| 2 | /// | ||
| 3 | /// This module splits the large Nip34WritePolicy into focused sub-policies: | ||
| 4 | /// - `AnnouncementPolicy` - Repository announcement validation | ||
| 5 | /// - `StatePolicy` - State event validation + ref alignment | ||
| 6 | /// - `PrEventPolicy` - PR/PR Update validation | ||
| 7 | /// - `RelatedEventPolicy` - Forward/backward reference checking | ||
| 8 | |||
| 9 | mod announcement; | ||
| 10 | mod pr_event; | ||
| 11 | mod related; | ||
| 12 | mod state; | ||
| 13 | |||
| 14 | pub use announcement::{AnnouncementPolicy, AnnouncementResult}; | ||
| 15 | pub use pr_event::PrEventPolicy; | ||
| 16 | pub use related::{ReferenceResult, RelatedEventPolicy}; | ||
| 17 | pub use state::{AlignmentResult, StatePolicy, StateResult}; | ||
| 18 | |||
| 19 | use super::SharedDatabase; | ||
| 20 | |||
| 21 | /// Shared context for all sub-policies | ||
| 22 | #[derive(Clone)] | ||
| 23 | pub struct PolicyContext { | ||
| 24 | pub domain: String, | ||
| 25 | pub database: SharedDatabase, | ||
| 26 | pub git_data_path: std::path::PathBuf, | ||
| 27 | } | ||
| 28 | |||
| 29 | impl PolicyContext { | ||
| 30 | pub fn new( | ||
| 31 | domain: impl Into<String>, | ||
| 32 | database: SharedDatabase, | ||
| 33 | git_data_path: impl Into<std::path::PathBuf>, | ||
| 34 | ) -> Self { | ||
| 35 | Self { | ||
| 36 | domain: domain.into(), | ||
| 37 | database, | ||
| 38 | git_data_path: git_data_path.into(), | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } \ No newline at end of file | ||