This repository has no description
Firehose Event Handlers Implementation Guide - Reusing Existing Use Cases#
Overview#
This implementation reuses existing use cases as much as possible for handling firehose events. The key insight is that firehose events represent already-published records, so we need to skip the publishing step and use the provided AT URI + CID as the published record ID.
Architecture Approach#
- Reuse existing use cases - Leverage existing business logic in use cases
- Skip publishing for firehose events - Add optional
publishedRecordIdparameter to use cases - Use AT URI resolution - Convert AT URIs from firehose events to domain entities
- Minimal changes - Keep modifications as simple as possible
Implementation Strategy#
Core Pattern#
Each firehose processor will:
- Parse the AT URI and extract relevant data from the record
- Use
IAtUriResolutionServiceto resolve AT URIs to domain entities - Call existing use cases with an optional
publishedRecordIdparameter - When
publishedRecordIdis provided, skip publishing and use that ID for marking as published
Use Case Modifications#
Add optional publishedRecordId?: PublishedRecordId parameter to these use cases:
AddUrlToLibraryUseCaseCreateCollectionUseCaseUpdateCollectionUseCaseDeleteCollectionUseCaseRemoveCardFromLibraryUseCase
For UpdateUrlCardAssociationsUseCase, we'll need a more complex approach since it handles multiple operations. We'll add optional parameters for collection link published record IDs.
Event Handling Implementation#
URL Card Events#
Create#
- Extract URL and curator DID from record
- Call
AddUrlToLibraryUseCasewithpublishedRecordIdfrom event
Update#
- Skip for now (URL cards don't typically update)
Delete#
- Resolve AT URI to card ID
- Call
RemoveCardFromLibraryUseCasewithpublishedRecordIdto skip unpublishing
Note Card Events#
Create/Update#
- Extract parent card AT URI, note text, and curator DID
- Resolve parent card AT URI to card ID
- Call
UpdateUrlCardAssociationsUseCasewith note andpublishedRecordId
Delete#
- Resolve AT URI to card ID
- Verify it's a note card
- Call
RemoveCardFromLibraryUseCasewithpublishedRecordId
Collection Events#
Create#
- Extract name, description, curator DID from record
- Call
CreateCollectionUseCasewithpublishedRecordIdfrom event
Update#
- Resolve AT URI to collection ID
- Extract updated fields from record
- Call
UpdateCollectionUseCasewithpublishedRecordId
Delete#
- Resolve AT URI to collection ID
- Call
DeleteCollectionUseCasewithpublishedRecordIdto skip unpublishing
Collection Link Events#
Create#
- Extract collection and card strong refs from record
- Resolve AT URIs to collection ID and card ID
- Call
UpdateUrlCardAssociationsUseCasewithaddToCollectionsand linkpublishedRecordId
Delete#
- Extract collection and card strong refs from record
- Resolve AT URIs to collection ID and card ID
- Call
UpdateUrlCardAssociationsUseCasewithremoveFromCollectionsand linkpublishedRecordId
Key Benefits#
- Reuses existing business logic - No duplication of validation and domain rules
- Minimal code changes - Just add optional parameters to existing use cases
- Consistent behavior - Same validation and error handling as normal operations
- Simple to test - Can test firehose handling by calling existing use cases with mock data
Files to Modify#
Use Cases (add optional publishedRecordId parameter):#
AddUrlToLibraryUseCase.tsCreateCollectionUseCase.tsUpdateCollectionUseCase.tsDeleteCollectionUseCase.tsRemoveCardFromLibraryUseCase.tsUpdateUrlCardAssociationsUseCase.ts(more complex - add collection link published record IDs)
Firehose Processors (simplify to call existing use cases):#
ProcessCardFirehoseEventUseCase.tsProcessCollectionFirehoseEventUseCase.tsProcessCollectionLinkFirehoseEventUseCase.ts
Services (add mapping storage methods):#
IAtUriResolutionService.ts(already has the methods we need)
This approach maintains clean separation of concerns while maximizing code reuse and minimizing the complexity of firehose event handling.