refactor(relay): implement factory pattern with Mastodon and LitePub relay support #484
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the
@fedify/relaypackage to introduce a factory pattern that supports multiple relay implementations, specifically Mastodon and LitePub relay protocols. The changes improve code organization, maintainability, and extensibility for future relay implementations.Key Changes
createRelay()factory function that instantiates relay implementations based on type ("mastodon"or"litepub")MastodonRelay: Implements Mastodon's relay protocol with immediate follower acceptanceLitePubRelay: Implements LitePub's relay protocol with reciprocal follow pattern (pending → accepted states)relay.tswith shared:mastodon.test.ts: 896 lines of tests covering Mastodon relay behaviorlitepub.test.ts: 896 lines of tests covering LitePub relay behavior with reciprocal followsrelay.test.tsProtocol Differences
Mastodon Relay:
LitePub Relay:
pending→acceptedArchitecture Improvements
relay.tsandrelayBuilderRelayOptions,LitePubFollower)Migration Guide
Before:
After:
Files Changed
packages/relay/src/relay.ts: Refactored to shared infrastructure (771 → 161 lines)packages/relay/src/mastodon.ts: New Mastodon relay implementation (191 lines)packages/relay/src/litepub.ts: New LitePub relay implementation (297 lines)packages/relay/src/mastodon.test.ts: New comprehensive test suite (784 lines)packages/relay/src/litepub.test.ts: New comprehensive test suite (896 lines)packages/relay/src/relay.test.ts: Removed old monolithic tests (1128 lines deleted)packages/relay/src/mod.ts: Updated exports to include new relay classesTest Plan
Breaking Changes
This is a breaking change that requires updates to existing relay usage code:
Relayclass constructor is replaced withcreateRelay()factory function"mastodon"or"litepub"Related Commits
🤖 Generated with Claude Code