This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

semble / src / shared / infrastructure / http / factories / UseCaseFactory.ts
23 kB 474 lines
1import { InitiateOAuthSignInUseCase } from '../../../../modules/user/application/use-cases/InitiateOAuthSignInUseCase'; 2import { CompleteOAuthSignInUseCase } from '../../../../modules/user/application/use-cases/CompleteOAuthSignInUseCase'; 3import { RefreshAccessTokenUseCase } from '../../../../modules/user/application/use-cases/RefreshAccessTokenUseCase'; 4import { AddUrlToLibraryUseCase } from '../../../../modules/cards/application/useCases/commands/AddUrlToLibraryUseCase'; 5import { AddCardToLibraryUseCase } from '../../../../modules/cards/application/useCases/commands/AddCardToLibraryUseCase'; 6import { AddCardToCollectionUseCase } from '../../../../modules/cards/application/useCases/commands/AddCardToCollectionUseCase'; 7import { UpdateNoteCardUseCase } from '../../../../modules/cards/application/useCases/commands/UpdateNoteCardUseCase'; 8import { UpdateUrlCardAssociationsUseCase } from '../../../../modules/cards/application/useCases/commands/UpdateUrlCardAssociationsUseCase'; 9import { RemoveCardFromLibraryUseCase } from '../../../../modules/cards/application/useCases/commands/RemoveCardFromLibraryUseCase'; 10import { RemoveCardFromCollectionUseCase } from '../../../../modules/cards/application/useCases/commands/RemoveCardFromCollectionUseCase'; 11import { GetUrlMetadataUseCase } from '../../../../modules/cards/application/useCases/queries/GetUrlMetadataUseCase'; 12import { GetUrlCardViewUseCase } from '../../../../modules/cards/application/useCases/queries/GetUrlCardViewUseCase'; 13import { GetLibrariesForCardUseCase } from '../../../../modules/cards/application/useCases/queries/GetLibrariesForCardUseCase'; 14import { GetUrlCardsUseCase } from '../../../../modules/cards/application/useCases/queries/GetUrlCardsUseCase'; 15import { CreateCollectionUseCase } from '../../../../modules/cards/application/useCases/commands/CreateCollectionUseCase'; 16import { UpdateCollectionUseCase } from '../../../../modules/cards/application/useCases/commands/UpdateCollectionUseCase'; 17import { DeleteCollectionUseCase } from '../../../../modules/cards/application/useCases/commands/DeleteCollectionUseCase'; 18import { GetCollectionPageUseCase } from '../../../../modules/cards/application/useCases/queries/GetCollectionPageUseCase'; 19import { Repositories } from './RepositoryFactory'; 20import { Services, SharedServices } from './ServiceFactory'; 21import { GetProfileUseCase } from 'src/modules/cards/application/useCases/queries/GetProfileUseCase'; 22import { LoginWithAppPasswordUseCase } from 'src/modules/user/application/use-cases/LoginWithAppPasswordUseCase'; 23import { LogoutUseCase } from 'src/modules/user/application/use-cases/LogoutUseCase'; 24import { GenerateExtensionTokensUseCase } from 'src/modules/user/application/use-cases/GenerateExtensionTokensUseCase'; 25import { GetGlobalFeedUseCase } from '../../../../modules/feeds/application/useCases/queries/GetGlobalFeedUseCase'; 26import { GetGemActivityFeedUseCase } from '../../../../modules/feeds/application/useCases/queries/GetGemActivityFeedUseCase'; 27import { AddActivityToFeedUseCase } from '../../../../modules/feeds/application/useCases/commands/AddActivityToFeedUseCase'; 28import { GetCollectionsUseCase } from 'src/modules/cards/application/useCases/queries/GetCollectionsUseCase'; 29import { SearchCollectionsUseCase } from 'src/modules/cards/application/useCases/queries/SearchCollectionsUseCase'; 30import { GetCollectionPageByAtUriUseCase } from 'src/modules/cards/application/useCases/queries/GetCollectionPageByAtUriUseCase'; 31import { GetUrlStatusForMyLibraryUseCase } from '../../../../modules/cards/application/useCases/queries/GetUrlStatusForMyLibraryUseCase'; 32import { GetLibrariesForUrlUseCase } from '../../../../modules/cards/application/useCases/queries/GetLibrariesForUrlUseCase'; 33import { GetCollectionsForUrlUseCase } from '../../../../modules/cards/application/useCases/queries/GetCollectionsForUrlUseCase'; 34import { GetNoteCardsForUrlUseCase } from '../../../../modules/cards/application/useCases/queries/GetNoteCardsForUrlUseCase'; 35import { IndexUrlForSearchUseCase } from '../../../../modules/search/application/useCases/commands/IndexUrlForSearchUseCase'; 36import { GetSimilarUrlsForUrlUseCase } from '../../../../modules/search/application/useCases/queries/GetSimilarUrlsForUrlUseCase'; 37import { SemanticSearchUrlsUseCase } from '../../../../modules/search/application/useCases/queries/SemanticSearchUrlsUseCase'; 38import { SearchBskyPostsForUrlUseCase } from '../../../../modules/search/application/use-cases/SearchBskyPostsForUrlUseCase'; 39import { SearchAtProtoAccountsUseCase } from '../../../../modules/search/application/use-cases/SearchAtProtoAccountsUseCase'; 40import { SearchLeafletDocsForUrlUseCase } from '../../../../modules/search/application/use-cases/SearchLeafletDocsForUrlUseCase'; 41import { ProcessCardFirehoseEventUseCase } from '../../../../modules/atproto/application/useCases/ProcessCardFirehoseEventUseCase'; 42import { ProcessCollectionFirehoseEventUseCase } from '../../../../modules/atproto/application/useCases/ProcessCollectionFirehoseEventUseCase'; 43import { ProcessCollectionLinkFirehoseEventUseCase } from '../../../../modules/atproto/application/useCases/ProcessCollectionLinkFirehoseEventUseCase'; 44import { ProcessMarginBookmarkFirehoseEventUseCase } from '../../../../modules/atproto/application/useCases/ProcessMarginBookmarkFirehoseEventUseCase'; 45import { ProcessMarginCollectionFirehoseEventUseCase } from '../../../../modules/atproto/application/useCases/ProcessMarginCollectionFirehoseEventUseCase'; 46import { ProcessMarginCollectionItemFirehoseEventUseCase } from '../../../../modules/atproto/application/useCases/ProcessMarginCollectionItemFirehoseEventUseCase'; 47import { GetMyNotificationsUseCase } from '../../../../modules/notifications/application/useCases/queries/GetMyNotificationsUseCase'; 48import { GetUnreadNotificationCountUseCase } from '../../../../modules/notifications/application/useCases/queries/GetUnreadNotificationCountUseCase'; 49import { MarkNotificationsAsReadUseCase } from '../../../../modules/notifications/application/useCases/commands/MarkNotificationsAsReadUseCase'; 50import { MarkAllNotificationsAsReadUseCase } from '../../../../modules/notifications/application/useCases/commands/MarkAllNotificationsAsReadUseCase'; 51import { CreateNotificationUseCase } from '../../../../modules/notifications/application/useCases/commands/CreateNotificationUseCase'; 52import { SyncAccountDataUseCase } from '../../../../modules/sync/application/useCases/SyncAccountDataUseCase'; 53 54export interface WorkerUseCases { 55 addActivityToFeedUseCase: AddActivityToFeedUseCase; 56 indexUrlForSearchUseCase: IndexUrlForSearchUseCase; 57 createNotificationUseCase: CreateNotificationUseCase; 58 syncAccountDataUseCase: SyncAccountDataUseCase; 59 // Firehose-specific use cases 60 addUrlToLibraryUseCase: AddUrlToLibraryUseCase; 61 updateUrlCardAssociationsUseCase: UpdateUrlCardAssociationsUseCase; 62 removeCardFromLibraryUseCase: RemoveCardFromLibraryUseCase; 63 createCollectionUseCase: CreateCollectionUseCase; 64 updateCollectionUseCase: UpdateCollectionUseCase; 65 deleteCollectionUseCase: DeleteCollectionUseCase; 66 processCardFirehoseEventUseCase: ProcessCardFirehoseEventUseCase; 67 processCollectionFirehoseEventUseCase: ProcessCollectionFirehoseEventUseCase; 68 processCollectionLinkFirehoseEventUseCase: ProcessCollectionLinkFirehoseEventUseCase; 69 processMarginBookmarkFirehoseEventUseCase: ProcessMarginBookmarkFirehoseEventUseCase; 70 processMarginCollectionFirehoseEventUseCase: ProcessMarginCollectionFirehoseEventUseCase; 71 processMarginCollectionItemFirehoseEventUseCase: ProcessMarginCollectionItemFirehoseEventUseCase; 72} 73 74export interface UseCases { 75 // User use cases 76 loginWithAppPasswordUseCase: LoginWithAppPasswordUseCase; 77 logoutUseCase: LogoutUseCase; 78 initiateOAuthSignInUseCase: InitiateOAuthSignInUseCase; 79 completeOAuthSignInUseCase: CompleteOAuthSignInUseCase; 80 getProfileUseCase: GetProfileUseCase; 81 refreshAccessTokenUseCase: RefreshAccessTokenUseCase; 82 generateExtensionTokensUseCase: GenerateExtensionTokensUseCase; 83 // Card use cases 84 addUrlToLibraryUseCase: AddUrlToLibraryUseCase; 85 addCardToLibraryUseCase: AddCardToLibraryUseCase; 86 addCardToCollectionUseCase: AddCardToCollectionUseCase; 87 updateNoteCardUseCase: UpdateNoteCardUseCase; 88 updateUrlCardAssociationsUseCase: UpdateUrlCardAssociationsUseCase; 89 removeCardFromLibraryUseCase: RemoveCardFromLibraryUseCase; 90 removeCardFromCollectionUseCase: RemoveCardFromCollectionUseCase; 91 getUrlMetadataUseCase: GetUrlMetadataUseCase; 92 getUrlCardViewUseCase: GetUrlCardViewUseCase; 93 getLibrariesForCardUseCase: GetLibrariesForCardUseCase; 94 getMyUrlCardsUseCase: GetUrlCardsUseCase; 95 createCollectionUseCase: CreateCollectionUseCase; 96 updateCollectionUseCase: UpdateCollectionUseCase; 97 deleteCollectionUseCase: DeleteCollectionUseCase; 98 getCollectionPageUseCase: GetCollectionPageUseCase; 99 getCollectionPageByAtUriUseCase: GetCollectionPageByAtUriUseCase; 100 getCollectionsUseCase: GetCollectionsUseCase; 101 searchCollectionsUseCase: SearchCollectionsUseCase; 102 getUrlStatusForMyLibraryUseCase: GetUrlStatusForMyLibraryUseCase; 103 getLibrariesForUrlUseCase: GetLibrariesForUrlUseCase; 104 getCollectionsForUrlUseCase: GetCollectionsForUrlUseCase; 105 getNoteCardsForUrlUseCase: GetNoteCardsForUrlUseCase; 106 // Feed use cases 107 getGlobalFeedUseCase: GetGlobalFeedUseCase; 108 getGemActivityFeedUseCase: GetGemActivityFeedUseCase; 109 addActivityToFeedUseCase: AddActivityToFeedUseCase; 110 // Search use cases 111 getSimilarUrlsForUrlUseCase: GetSimilarUrlsForUrlUseCase; 112 semanticSearchUrlsUseCase: SemanticSearchUrlsUseCase; 113 searchBskyPostsForUrlUseCase: SearchBskyPostsForUrlUseCase; 114 searchAtProtoAccountsUseCase: SearchAtProtoAccountsUseCase; 115 searchLeafletDocsForUrlUseCase: SearchLeafletDocsForUrlUseCase; 116 // Notification use cases 117 getMyNotificationsUseCase: GetMyNotificationsUseCase; 118 getUnreadNotificationCountUseCase: GetUnreadNotificationCountUseCase; 119 markNotificationsAsReadUseCase: MarkNotificationsAsReadUseCase; 120 markAllNotificationsAsReadUseCase: MarkAllNotificationsAsReadUseCase; 121} 122 123export class UseCaseFactory { 124 static create(repositories: Repositories, services: Services): UseCases { 125 return this.createForWebApp(repositories, services); 126 } 127 128 static createForWebApp( 129 repositories: Repositories, 130 services: Services, 131 ): UseCases { 132 const getCollectionPageUseCase = new GetCollectionPageUseCase( 133 repositories.collectionRepository, 134 repositories.cardQueryRepository, 135 services.profileService, 136 ); 137 138 return { 139 // User use cases 140 loginWithAppPasswordUseCase: new LoginWithAppPasswordUseCase( 141 services.appPasswordProcessor, 142 services.tokenService, 143 repositories.userRepository, 144 services.userAuthService, 145 ), 146 logoutUseCase: new LogoutUseCase(services.tokenService), 147 initiateOAuthSignInUseCase: new InitiateOAuthSignInUseCase( 148 services.oauthProcessor, 149 ), 150 completeOAuthSignInUseCase: new CompleteOAuthSignInUseCase( 151 services.oauthProcessor, 152 services.tokenService, 153 repositories.userRepository, 154 services.userAuthService, 155 ), 156 getProfileUseCase: new GetProfileUseCase( 157 services.profileService, 158 services.identityResolutionService, 159 ), 160 refreshAccessTokenUseCase: new RefreshAccessTokenUseCase( 161 services.tokenService, 162 ), 163 generateExtensionTokensUseCase: new GenerateExtensionTokensUseCase( 164 services.tokenService, 165 ), 166 167 // Card use cases 168 addUrlToLibraryUseCase: new AddUrlToLibraryUseCase( 169 repositories.cardRepository, 170 services.metadataService, 171 services.cardLibraryService, 172 services.cardCollectionService, 173 services.eventPublisher, 174 ), 175 addCardToLibraryUseCase: new AddCardToLibraryUseCase( 176 repositories.cardRepository, 177 services.cardLibraryService, 178 services.cardCollectionService, 179 ), 180 addCardToCollectionUseCase: new AddCardToCollectionUseCase( 181 repositories.cardRepository, 182 services.cardCollectionService, 183 services.eventPublisher, 184 ), 185 updateNoteCardUseCase: new UpdateNoteCardUseCase( 186 repositories.cardRepository, 187 services.cardPublisher, 188 ), 189 updateUrlCardAssociationsUseCase: new UpdateUrlCardAssociationsUseCase( 190 repositories.cardRepository, 191 services.cardLibraryService, 192 services.cardCollectionService, 193 services.eventPublisher, 194 ), 195 removeCardFromLibraryUseCase: new RemoveCardFromLibraryUseCase( 196 repositories.cardRepository, 197 services.cardLibraryService, 198 services.eventPublisher, 199 ), 200 removeCardFromCollectionUseCase: new RemoveCardFromCollectionUseCase( 201 repositories.cardRepository, 202 services.cardCollectionService, 203 ), 204 getUrlMetadataUseCase: new GetUrlMetadataUseCase( 205 services.metadataService, 206 repositories.cardRepository, 207 ), 208 getUrlCardViewUseCase: new GetUrlCardViewUseCase( 209 repositories.cardQueryRepository, 210 services.profileService, 211 repositories.collectionRepository, 212 ), 213 getLibrariesForCardUseCase: new GetLibrariesForCardUseCase( 214 repositories.cardQueryRepository, 215 services.profileService, 216 ), 217 getMyUrlCardsUseCase: new GetUrlCardsUseCase( 218 repositories.cardQueryRepository, 219 services.identityResolutionService, 220 services.profileService, 221 ), 222 createCollectionUseCase: new CreateCollectionUseCase( 223 repositories.collectionRepository, 224 services.collectionPublisher, 225 ), 226 updateCollectionUseCase: new UpdateCollectionUseCase( 227 repositories.collectionRepository, 228 services.collectionPublisher, 229 ), 230 deleteCollectionUseCase: new DeleteCollectionUseCase( 231 repositories.collectionRepository, 232 services.collectionPublisher, 233 ), 234 getCollectionPageUseCase, 235 getCollectionPageByAtUriUseCase: new GetCollectionPageByAtUriUseCase( 236 services.identityResolutionService, 237 repositories.atUriResolutionService, 238 getCollectionPageUseCase, 239 services.configService.getAtProtoCollections().collection, 240 services.configService.getAtProtoCollections().marginCollection, 241 ), 242 getCollectionsUseCase: new GetCollectionsUseCase( 243 repositories.collectionQueryRepository, 244 services.profileService, 245 services.identityResolutionService, 246 ), 247 searchCollectionsUseCase: new SearchCollectionsUseCase( 248 repositories.collectionQueryRepository, 249 services.profileService, 250 services.identityResolutionService, 251 ), 252 getUrlStatusForMyLibraryUseCase: new GetUrlStatusForMyLibraryUseCase( 253 repositories.cardRepository, 254 repositories.cardQueryRepository, 255 repositories.collectionQueryRepository, 256 repositories.collectionRepository, 257 services.profileService, 258 services.eventPublisher, 259 ), 260 getLibrariesForUrlUseCase: new GetLibrariesForUrlUseCase( 261 repositories.cardQueryRepository, 262 services.profileService, 263 ), 264 getCollectionsForUrlUseCase: new GetCollectionsForUrlUseCase( 265 repositories.collectionQueryRepository, 266 services.profileService, 267 repositories.collectionRepository, 268 ), 269 getNoteCardsForUrlUseCase: new GetNoteCardsForUrlUseCase( 270 repositories.cardQueryRepository, 271 services.profileService, 272 ), 273 274 // Feed use cases 275 getGlobalFeedUseCase: new GetGlobalFeedUseCase( 276 repositories.feedRepository, 277 services.profileService, 278 repositories.cardQueryRepository, 279 repositories.collectionRepository, 280 ), 281 getGemActivityFeedUseCase: new GetGemActivityFeedUseCase( 282 repositories.feedRepository, 283 services.profileService, 284 repositories.cardQueryRepository, 285 repositories.collectionRepository, 286 repositories.collectionQueryRepository, 287 ), 288 addActivityToFeedUseCase: new AddActivityToFeedUseCase( 289 services.feedService, 290 repositories.cardRepository, 291 ), 292 // Search use cases 293 getSimilarUrlsForUrlUseCase: new GetSimilarUrlsForUrlUseCase( 294 services.searchService, 295 ), 296 semanticSearchUrlsUseCase: new SemanticSearchUrlsUseCase( 297 services.searchService, 298 services.identityResolutionService, 299 ), 300 searchBskyPostsForUrlUseCase: new SearchBskyPostsForUrlUseCase( 301 services.atProtoAgentService, 302 ), 303 searchAtProtoAccountsUseCase: new SearchAtProtoAccountsUseCase( 304 services.atProtoAgentService, 305 ), 306 searchLeafletDocsForUrlUseCase: new SearchLeafletDocsForUrlUseCase( 307 services.leafletSearchService, 308 repositories.cardQueryRepository, 309 ), 310 // Notification use cases 311 getMyNotificationsUseCase: new GetMyNotificationsUseCase( 312 repositories.notificationRepository, 313 services.profileService, 314 repositories.cardQueryRepository, 315 repositories.collectionRepository, 316 ), 317 getUnreadNotificationCountUseCase: new GetUnreadNotificationCountUseCase( 318 repositories.notificationRepository, 319 ), 320 markNotificationsAsReadUseCase: new MarkNotificationsAsReadUseCase( 321 repositories.notificationRepository, 322 ), 323 markAllNotificationsAsReadUseCase: new MarkAllNotificationsAsReadUseCase( 324 repositories.notificationRepository, 325 ), 326 }; 327 } 328 329 static createForWorker( 330 repositories: Repositories, 331 services: SharedServices, 332 ): WorkerUseCases { 333 return { 334 // Feed use cases (only ones needed by workers) 335 addActivityToFeedUseCase: new AddActivityToFeedUseCase( 336 services.feedService, 337 repositories.cardRepository, 338 ), 339 // Search use cases (only ones needed by workers) 340 indexUrlForSearchUseCase: new IndexUrlForSearchUseCase( 341 services.searchService, 342 ), 343 // Notification use cases (only ones needed by workers) 344 createNotificationUseCase: new CreateNotificationUseCase( 345 services.notificationService, 346 ), 347 // Sync use cases (only ones needed by workers) 348 syncAccountDataUseCase: new SyncAccountDataUseCase( 349 repositories.syncStatusRepository, 350 ), 351 // Firehose-specific use cases 352 addUrlToLibraryUseCase: new AddUrlToLibraryUseCase( 353 repositories.cardRepository, 354 services.metadataService, 355 services.cardLibraryService, 356 services.cardCollectionService, 357 services.eventPublisher, 358 ), 359 updateUrlCardAssociationsUseCase: new UpdateUrlCardAssociationsUseCase( 360 repositories.cardRepository, 361 services.cardLibraryService, 362 services.cardCollectionService, 363 services.eventPublisher, 364 ), 365 removeCardFromLibraryUseCase: new RemoveCardFromLibraryUseCase( 366 repositories.cardRepository, 367 services.cardLibraryService, 368 services.eventPublisher, 369 ), 370 createCollectionUseCase: new CreateCollectionUseCase( 371 repositories.collectionRepository, 372 services.collectionPublisher, 373 ), 374 updateCollectionUseCase: new UpdateCollectionUseCase( 375 repositories.collectionRepository, 376 services.collectionPublisher, 377 ), 378 deleteCollectionUseCase: new DeleteCollectionUseCase( 379 repositories.collectionRepository, 380 services.collectionPublisher, 381 ), 382 processCardFirehoseEventUseCase: new ProcessCardFirehoseEventUseCase( 383 repositories.atUriResolutionService, 384 new AddUrlToLibraryUseCase( 385 repositories.cardRepository, 386 services.metadataService, 387 services.cardLibraryService, 388 services.cardCollectionService, 389 services.eventPublisher, 390 ), 391 new UpdateUrlCardAssociationsUseCase( 392 repositories.cardRepository, 393 services.cardLibraryService, 394 services.cardCollectionService, 395 services.eventPublisher, 396 ), 397 new RemoveCardFromLibraryUseCase( 398 repositories.cardRepository, 399 services.cardLibraryService, 400 services.eventPublisher, 401 ), 402 repositories.cardRepository, 403 ), 404 processCollectionFirehoseEventUseCase: 405 new ProcessCollectionFirehoseEventUseCase( 406 repositories.atUriResolutionService, 407 new CreateCollectionUseCase( 408 repositories.collectionRepository, 409 services.collectionPublisher, 410 ), 411 new UpdateCollectionUseCase( 412 repositories.collectionRepository, 413 services.collectionPublisher, 414 ), 415 new DeleteCollectionUseCase( 416 repositories.collectionRepository, 417 services.collectionPublisher, 418 ), 419 ), 420 processCollectionLinkFirehoseEventUseCase: 421 new ProcessCollectionLinkFirehoseEventUseCase( 422 repositories.atUriResolutionService, 423 new UpdateUrlCardAssociationsUseCase( 424 repositories.cardRepository, 425 services.cardLibraryService, 426 services.cardCollectionService, 427 services.eventPublisher, 428 ), 429 ), 430 processMarginBookmarkFirehoseEventUseCase: 431 new ProcessMarginBookmarkFirehoseEventUseCase( 432 repositories.atUriResolutionService, 433 new AddUrlToLibraryUseCase( 434 repositories.cardRepository, 435 services.metadataService, 436 services.cardLibraryService, 437 services.cardCollectionService, 438 services.eventPublisher, 439 ), 440 new RemoveCardFromLibraryUseCase( 441 repositories.cardRepository, 442 services.cardLibraryService, 443 services.eventPublisher, 444 ), 445 ), 446 processMarginCollectionFirehoseEventUseCase: 447 new ProcessMarginCollectionFirehoseEventUseCase( 448 repositories.atUriResolutionService, 449 new CreateCollectionUseCase( 450 repositories.collectionRepository, 451 services.collectionPublisher, 452 ), 453 new UpdateCollectionUseCase( 454 repositories.collectionRepository, 455 services.collectionPublisher, 456 ), 457 new DeleteCollectionUseCase( 458 repositories.collectionRepository, 459 services.collectionPublisher, 460 ), 461 ), 462 processMarginCollectionItemFirehoseEventUseCase: 463 new ProcessMarginCollectionItemFirehoseEventUseCase( 464 repositories.atUriResolutionService, 465 new UpdateUrlCardAssociationsUseCase( 466 repositories.cardRepository, 467 services.cardLibraryService, 468 services.cardCollectionService, 469 services.eventPublisher, 470 ), 471 ), 472 }; 473 } 474}