Merge branch 'master'
[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 { AuthService } from "./auth-service/auth-service";
7 import { GroupsService } from "./groups-service/groups-service";
8 import { ProjectService } from "./project-service/project-service";
9 import { LinkService } from "./link-service/link-service";
10 import { FavoriteService } from "./favorite-service/favorite-service";
11 import { CollectionService } from "./collection-service/collection-service";
12 import { TagService } from "./tag-service/tag-service";
13 import { CollectionFilesService } from "./collection-files-service/collection-files-service";
14 import { KeepService } from "./keep-service/keep-service";
15 import { WebDAV } from "~/common/webdav";
16 import { Config } from "~/common/config";
17 import { UserService } from './user-service/user-service';
18 import { AncestorService } from "~/services/ancestors-service/ancestors-service";
19 import { ResourceKind } from "~/models/resource";
20 import { ContainerRequestService } from './container-request-service/container-request-service';
21 import { ContainerService } from './container-service/container-service';
22 import { LogService } from './log-service/log-service';
23 import { ApiActions } from "~/services/api/api-actions";
24 import { WorkflowService } from "~/services/workflow-service/workflow-service";
25 import { SearchService } from '~/services/search-service/search-service';
26 import { PermissionService } from "~/services/permission-service/permission-service";
27
28 export type ServiceRepository = ReturnType<typeof createServices>;
29
30 export const createServices = (config: Config, actions: ApiActions) => {
31     const apiClient = Axios.create();
32     apiClient.defaults.baseURL = config.baseUrl;
33
34     const webdavClient = new WebDAV();
35     webdavClient.defaults.baseURL = config.keepWebServiceUrl;
36
37     const containerRequestService = new ContainerRequestService(apiClient, actions);
38     const containerService = new ContainerService(apiClient, actions);
39     const groupsService = new GroupsService(apiClient, actions);
40     const keepService = new KeepService(apiClient, actions);
41     const linkService = new LinkService(apiClient, actions);
42     const logService = new LogService(apiClient, actions);
43     const permissionService = new PermissionService(apiClient, actions);
44     const projectService = new ProjectService(apiClient, actions);
45     const userService = new UserService(apiClient, actions);
46     const workflowService = new WorkflowService(apiClient, actions);
47
48     const ancestorsService = new AncestorService(groupsService, userService);
49     const authService = new AuthService(apiClient, config.rootUrl, actions);
50     const collectionService = new CollectionService(apiClient, webdavClient, authService, actions);
51     const collectionFilesService = new CollectionFilesService(collectionService);
52     const favoriteService = new FavoriteService(linkService, groupsService);
53     const tagService = new TagService(linkService);
54     const searchService = new SearchService();
55
56     return {
57         ancestorsService,
58         apiClient,
59         authService,
60         collectionFilesService,
61         collectionService,
62         containerRequestService,
63         containerService,
64         favoriteService,
65         groupsService,
66         keepService,
67         linkService,
68         logService,
69         permissionService,
70         projectService,
71         searchService,
72         tagService,
73         userService,
74         webdavClient,
75         workflowService,
76     };
77 };
78
79 export const getResourceService = (kind?: ResourceKind) => (serviceRepository: ServiceRepository) => {
80     switch (kind) {
81         case ResourceKind.USER:
82             return serviceRepository.userService;
83         case ResourceKind.GROUP:
84             return serviceRepository.groupsService;
85         case ResourceKind.COLLECTION:
86             return serviceRepository.collectionService;
87         default:
88             return undefined;
89     }
90 };