15840: Adds comment to refactored tree construction
[arvados.git] / src / services / services.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import Axios from "axios";
6 import { ApiClientAuthorizationService } from '~/services/api-client-authorization-service/api-client-authorization-service';
7 import { AuthService } from "./auth-service/auth-service";
8 import { GroupsService } from "./groups-service/groups-service";
9 import { ProjectService } from "./project-service/project-service";
10 import { LinkService } from "./link-service/link-service";
11 import { FavoriteService } from "./favorite-service/favorite-service";
12 import { CollectionService } from "./collection-service/collection-service";
13 import { TagService } from "./tag-service/tag-service";
14 import { CollectionFilesService } from "./collection-files-service/collection-files-service";
15 import { KeepService } from "./keep-service/keep-service";
16 import { WebDAV } from "~/common/webdav";
17 import { Config } from "~/common/config";
18 import { UserService } from './user-service/user-service';
19 import { AncestorService } from "~/services/ancestors-service/ancestors-service";
20 import { ResourceKind } from "~/models/resource";
21 import { ContainerRequestService } from './container-request-service/container-request-service';
22 import { ContainerService } from './container-service/container-service';
23 import { LogService } from './log-service/log-service';
24 import { ApiActions } from "~/services/api/api-actions";
25 import { WorkflowService } from "~/services/workflow-service/workflow-service";
26 import { SearchService } from '~/services/search-service/search-service';
27 import { PermissionService } from "~/services/permission-service/permission-service";
28 import { VirtualMachinesService } from "~/services/virtual-machines-service/virtual-machines-service";
29 import { RepositoriesService } from '~/services/repositories-service/repositories-service';
30 import { AuthorizedKeysService } from '~/services/authorized-keys-service/authorized-keys-service';
31 import { VocabularyService } from '~/services/vocabulary-service/vocabulary-service';
32 import { NodeService } from '~/services/node-service/node-service';
33 import { FileViewersConfigService } from '~/services/file-viewers-config-service/file-viewers-config-service';
34 import { LinkAccountService } from "./link-account-service/link-account-service";
35
36 export type ServiceRepository = ReturnType<typeof createServices>;
37
38 export const createServices = (config: Config, actions: ApiActions) => {
39     const apiClient = Axios.create();
40     apiClient.defaults.baseURL = config.baseUrl;
41
42     const webdavClient = new WebDAV();
43     webdavClient.defaults.baseURL = config.keepWebServiceUrl;
44
45     const apiClientAuthorizationService = new ApiClientAuthorizationService(apiClient, actions);
46     const authorizedKeysService = new AuthorizedKeysService(apiClient, actions);
47     const containerRequestService = new ContainerRequestService(apiClient, actions);
48     const containerService = new ContainerService(apiClient, actions);
49     const groupsService = new GroupsService(apiClient, actions);
50     const keepService = new KeepService(apiClient, actions);
51     const linkService = new LinkService(apiClient, actions);
52     const logService = new LogService(apiClient, actions);
53     const nodeService = new NodeService(apiClient, actions);
54     const permissionService = new PermissionService(apiClient, actions);
55     const projectService = new ProjectService(apiClient, actions);
56     const repositoriesService = new RepositoriesService(apiClient, actions);
57     const userService = new UserService(apiClient, actions);
58     const virtualMachineService = new VirtualMachinesService(apiClient, actions);
59     const workflowService = new WorkflowService(apiClient, actions);
60     const linkAccountService = new LinkAccountService(apiClient, actions);
61
62     const ancestorsService = new AncestorService(groupsService, userService);
63     const authService = new AuthService(apiClient, config.rootUrl, actions);
64     const collectionService = new CollectionService(apiClient, webdavClient, authService, actions);
65     const collectionFilesService = new CollectionFilesService(collectionService);
66     const favoriteService = new FavoriteService(linkService, groupsService);
67     const tagService = new TagService(linkService);
68     const searchService = new SearchService();
69     const vocabularyService = new VocabularyService(config.vocabularyUrl);
70     const fileViewersConfig = new FileViewersConfigService(config.fileViewersConfigUrl);
71
72     return {
73         ancestorsService,
74         apiClient,
75         apiClientAuthorizationService,
76         authService,
77         authorizedKeysService,
78         collectionFilesService,
79         collectionService,
80         containerRequestService,
81         containerService,
82         favoriteService,
83         fileViewersConfig,
84         groupsService,
85         keepService,
86         linkService,
87         logService,
88         nodeService,
89         permissionService,
90         projectService,
91         repositoriesService,
92         searchService,
93         tagService,
94         userService,
95         virtualMachineService,
96         webdavClient,
97         workflowService,
98         vocabularyService,
99         linkAccountService
100     };
101 };
102
103 export const getResourceService = (kind?: ResourceKind) => (serviceRepository: ServiceRepository) => {
104     switch (kind) {
105         case ResourceKind.USER:
106             return serviceRepository.userService;
107         case ResourceKind.GROUP:
108             return serviceRepository.groupsService;
109         case ResourceKind.COLLECTION:
110             return serviceRepository.collectionService;
111         default:
112             return undefined;
113     }
114 };