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
11 kB 237 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 { AddActivityToFeedUseCase } from '../../../../modules/feeds/application/useCases/commands/AddActivityToFeedUseCase'; 27import { GetCollectionsUseCase } from 'src/modules/cards/application/useCases/queries/GetCollectionsUseCase'; 28import { GetCollectionPageByAtUriUseCase } from 'src/modules/cards/application/useCases/queries/GetCollectionPageByAtUriUseCase'; 29import { GetUrlStatusForMyLibraryUseCase } from '../../../../modules/cards/application/useCases/queries/GetUrlStatusForMyLibraryUseCase'; 30import { GetLibrariesForUrlUseCase } from '../../../../modules/cards/application/useCases/queries/GetLibrariesForUrlUseCase'; 31import { GetCollectionsForUrlUseCase } from '../../../../modules/cards/application/useCases/queries/GetCollectionsForUrlUseCase'; 32import { GetNoteCardsForUrlUseCase } from '../../../../modules/cards/application/useCases/queries/GetNoteCardsForUrlUseCase'; 33 34export interface UseCases { 35 // User use cases 36 loginWithAppPasswordUseCase: LoginWithAppPasswordUseCase; 37 logoutUseCase: LogoutUseCase; 38 initiateOAuthSignInUseCase: InitiateOAuthSignInUseCase; 39 completeOAuthSignInUseCase: CompleteOAuthSignInUseCase; 40 getMyProfileUseCase: GetProfileUseCase; 41 refreshAccessTokenUseCase: RefreshAccessTokenUseCase; 42 generateExtensionTokensUseCase: GenerateExtensionTokensUseCase; 43 // Card use cases 44 addUrlToLibraryUseCase: AddUrlToLibraryUseCase; 45 addCardToLibraryUseCase: AddCardToLibraryUseCase; 46 addCardToCollectionUseCase: AddCardToCollectionUseCase; 47 updateNoteCardUseCase: UpdateNoteCardUseCase; 48 updateUrlCardAssociationsUseCase: UpdateUrlCardAssociationsUseCase; 49 removeCardFromLibraryUseCase: RemoveCardFromLibraryUseCase; 50 removeCardFromCollectionUseCase: RemoveCardFromCollectionUseCase; 51 getUrlMetadataUseCase: GetUrlMetadataUseCase; 52 getUrlCardViewUseCase: GetUrlCardViewUseCase; 53 getLibrariesForCardUseCase: GetLibrariesForCardUseCase; 54 getMyUrlCardsUseCase: GetUrlCardsUseCase; 55 createCollectionUseCase: CreateCollectionUseCase; 56 updateCollectionUseCase: UpdateCollectionUseCase; 57 deleteCollectionUseCase: DeleteCollectionUseCase; 58 getCollectionPageUseCase: GetCollectionPageUseCase; 59 getCollectionPageByAtUriUseCase: GetCollectionPageByAtUriUseCase; 60 getCollectionsUseCase: GetCollectionsUseCase; 61 getUrlStatusForMyLibraryUseCase: GetUrlStatusForMyLibraryUseCase; 62 getLibrariesForUrlUseCase: GetLibrariesForUrlUseCase; 63 getCollectionsForUrlUseCase: GetCollectionsForUrlUseCase; 64 getNoteCardsForUrlUseCase: GetNoteCardsForUrlUseCase; 65 // Feed use cases 66 getGlobalFeedUseCase: GetGlobalFeedUseCase; 67 addActivityToFeedUseCase: AddActivityToFeedUseCase; 68} 69 70export class UseCaseFactory { 71 static create(repositories: Repositories, services: Services): UseCases { 72 return this.createForWebApp(repositories, services); 73 } 74 75 static createForWebApp( 76 repositories: Repositories, 77 services: Services, 78 ): UseCases { 79 const getCollectionPageUseCase = new GetCollectionPageUseCase( 80 repositories.collectionRepository, 81 repositories.cardQueryRepository, 82 services.profileService, 83 ); 84 85 return { 86 // User use cases 87 loginWithAppPasswordUseCase: new LoginWithAppPasswordUseCase( 88 services.appPasswordProcessor, 89 services.tokenService, 90 repositories.userRepository, 91 services.userAuthService, 92 ), 93 logoutUseCase: new LogoutUseCase(services.tokenService), 94 initiateOAuthSignInUseCase: new InitiateOAuthSignInUseCase( 95 services.oauthProcessor, 96 ), 97 completeOAuthSignInUseCase: new CompleteOAuthSignInUseCase( 98 services.oauthProcessor, 99 services.tokenService, 100 repositories.userRepository, 101 services.userAuthService, 102 ), 103 getMyProfileUseCase: new GetProfileUseCase( 104 services.profileService, 105 services.identityResolutionService, 106 ), 107 refreshAccessTokenUseCase: new RefreshAccessTokenUseCase( 108 services.tokenService, 109 ), 110 generateExtensionTokensUseCase: new GenerateExtensionTokensUseCase( 111 services.tokenService, 112 ), 113 114 // Card use cases 115 addUrlToLibraryUseCase: new AddUrlToLibraryUseCase( 116 repositories.cardRepository, 117 services.metadataService, 118 services.cardLibraryService, 119 services.cardCollectionService, 120 services.eventPublisher, 121 ), 122 addCardToLibraryUseCase: new AddCardToLibraryUseCase( 123 repositories.cardRepository, 124 services.cardLibraryService, 125 services.cardCollectionService, 126 ), 127 addCardToCollectionUseCase: new AddCardToCollectionUseCase( 128 repositories.cardRepository, 129 services.cardCollectionService, 130 services.eventPublisher, 131 ), 132 updateNoteCardUseCase: new UpdateNoteCardUseCase( 133 repositories.cardRepository, 134 services.cardPublisher, 135 ), 136 updateUrlCardAssociationsUseCase: new UpdateUrlCardAssociationsUseCase( 137 repositories.cardRepository, 138 services.cardLibraryService, 139 services.cardCollectionService, 140 services.eventPublisher, 141 ), 142 removeCardFromLibraryUseCase: new RemoveCardFromLibraryUseCase( 143 repositories.cardRepository, 144 services.cardLibraryService, 145 ), 146 removeCardFromCollectionUseCase: new RemoveCardFromCollectionUseCase( 147 repositories.cardRepository, 148 services.cardCollectionService, 149 ), 150 getUrlMetadataUseCase: new GetUrlMetadataUseCase( 151 services.metadataService, 152 repositories.cardRepository, 153 ), 154 getUrlCardViewUseCase: new GetUrlCardViewUseCase( 155 repositories.cardQueryRepository, 156 services.profileService, 157 repositories.collectionRepository, 158 ), 159 getLibrariesForCardUseCase: new GetLibrariesForCardUseCase( 160 repositories.cardQueryRepository, 161 services.profileService, 162 ), 163 getMyUrlCardsUseCase: new GetUrlCardsUseCase( 164 repositories.cardQueryRepository, 165 services.identityResolutionService, 166 ), 167 createCollectionUseCase: new CreateCollectionUseCase( 168 repositories.collectionRepository, 169 services.collectionPublisher, 170 ), 171 updateCollectionUseCase: new UpdateCollectionUseCase( 172 repositories.collectionRepository, 173 services.collectionPublisher, 174 ), 175 deleteCollectionUseCase: new DeleteCollectionUseCase( 176 repositories.collectionRepository, 177 services.collectionPublisher, 178 ), 179 getCollectionPageUseCase, 180 getCollectionPageByAtUriUseCase: new GetCollectionPageByAtUriUseCase( 181 services.identityResolutionService, 182 repositories.atUriResolutionService, 183 getCollectionPageUseCase, 184 services.configService.getAtProtoCollections().collection, 185 ), 186 getCollectionsUseCase: new GetCollectionsUseCase( 187 repositories.collectionQueryRepository, 188 services.profileService, 189 services.identityResolutionService, 190 ), 191 getUrlStatusForMyLibraryUseCase: new GetUrlStatusForMyLibraryUseCase( 192 repositories.cardRepository, 193 repositories.collectionQueryRepository, 194 repositories.collectionRepository, 195 services.profileService, 196 services.eventPublisher, 197 ), 198 getLibrariesForUrlUseCase: new GetLibrariesForUrlUseCase( 199 repositories.cardQueryRepository, 200 services.profileService, 201 ), 202 getCollectionsForUrlUseCase: new GetCollectionsForUrlUseCase( 203 repositories.collectionQueryRepository, 204 services.profileService, 205 repositories.collectionRepository, 206 ), 207 getNoteCardsForUrlUseCase: new GetNoteCardsForUrlUseCase( 208 repositories.cardQueryRepository, 209 services.profileService, 210 ), 211 212 // Feed use cases 213 getGlobalFeedUseCase: new GetGlobalFeedUseCase( 214 repositories.feedRepository, 215 services.profileService, 216 repositories.cardQueryRepository, 217 repositories.collectionRepository, 218 services.identityResolutionService, 219 ), 220 addActivityToFeedUseCase: new AddActivityToFeedUseCase( 221 services.feedService, 222 ), 223 }; 224 } 225 226 static createForWorker( 227 repositories: Repositories, 228 services: SharedServices, 229 ): Pick<UseCases, 'addActivityToFeedUseCase'> { 230 return { 231 // Feed use cases (only ones needed by workers) 232 addActivityToFeedUseCase: new AddActivityToFeedUseCase( 233 services.feedService, 234 ), 235 }; 236 } 237}