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