@scm-manager/ui-api 2.36.1 → 2.36.2-20220522-120507

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/build/index.d.ts +735 -0
  2. package/build/index.js +3200 -0
  3. package/build/index.mjs +3031 -0
  4. package/package.json +15 -10
  5. package/LICENSE.txt +0 -21
  6. package/src/ApiProvider.test.tsx +0 -60
  7. package/src/ApiProvider.tsx +0 -80
  8. package/src/LegacyContext.test.tsx +0 -52
  9. package/src/LegacyContext.tsx +0 -75
  10. package/src/admin.test.ts +0 -55
  11. package/src/admin.ts +0 -42
  12. package/src/alerts.ts +0 -107
  13. package/src/annotations.ts +0 -45
  14. package/src/apiKeys.ts +0 -82
  15. package/src/apiclient.test.ts +0 -126
  16. package/src/apiclient.ts +0 -336
  17. package/src/base.test.ts +0 -238
  18. package/src/base.ts +0 -120
  19. package/src/branches.test.ts +0 -234
  20. package/src/branches.ts +0 -201
  21. package/src/changesets.test.ts +0 -178
  22. package/src/changesets.ts +0 -82
  23. package/src/compare.ts +0 -90
  24. package/src/config.test.ts +0 -118
  25. package/src/config.ts +0 -60
  26. package/src/configLink.test.ts +0 -169
  27. package/src/configLink.ts +0 -89
  28. package/src/contentType.ts +0 -58
  29. package/src/diff.test.ts +0 -234
  30. package/src/diff.ts +0 -93
  31. package/src/errors.test.ts +0 -59
  32. package/src/errors.ts +0 -133
  33. package/src/fileContent.ts +0 -33
  34. package/src/groupSuggestions.ts +0 -32
  35. package/src/groups.test.ts +0 -241
  36. package/src/groups.ts +0 -141
  37. package/src/help/search/modal.de.ts +0 -33
  38. package/src/help/search/modal.en.ts +0 -33
  39. package/src/help/search/syntax.de.ts +0 -148
  40. package/src/help/search/syntax.en.ts +0 -145
  41. package/src/history.ts +0 -62
  42. package/src/import.ts +0 -114
  43. package/src/index.ts +0 -72
  44. package/src/keys.ts +0 -48
  45. package/src/links.test.ts +0 -99
  46. package/src/links.ts +0 -54
  47. package/src/login.test.ts +0 -240
  48. package/src/login.ts +0 -128
  49. package/src/loginInfo.ts +0 -43
  50. package/src/namespaceSuggestions.ts +0 -32
  51. package/src/namespaces.test.ts +0 -95
  52. package/src/namespaces.ts +0 -43
  53. package/src/notifications.ts +0 -183
  54. package/src/permissions.test.ts +0 -345
  55. package/src/permissions.ts +0 -202
  56. package/src/plugins.test.ts +0 -336
  57. package/src/plugins.ts +0 -259
  58. package/src/publicKeys.ts +0 -83
  59. package/src/repositories.test.ts +0 -508
  60. package/src/repositories.ts +0 -375
  61. package/src/repository-roles.test.ts +0 -229
  62. package/src/repository-roles.ts +0 -142
  63. package/src/reset.ts +0 -36
  64. package/src/search.ts +0 -153
  65. package/src/sources.test.ts +0 -233
  66. package/src/sources.ts +0 -136
  67. package/src/suggestions.ts +0 -47
  68. package/src/tags.test.ts +0 -272
  69. package/src/tags.ts +0 -118
  70. package/src/tests/createInfiniteCachingClient.ts +0 -37
  71. package/src/tests/createWrapper.tsx +0 -37
  72. package/src/tests/indexLinks.ts +0 -43
  73. package/src/urls.test.ts +0 -104
  74. package/src/urls.ts +0 -118
  75. package/src/usePluginCenterAuthInfo.ts +0 -91
  76. package/src/userSuggestions.ts +0 -32
  77. package/src/users.test.ts +0 -310
  78. package/src/users.ts +0 -240
  79. package/src/utils.ts +0 -29
@@ -1,145 +0,0 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
- export default `### Modifiers
25
-
26
- Note: You can not use wildcards as the first character of a search.
27
-
28
- <table>
29
- <tr>
30
- <th>Definition</th>
31
- <th>Example</th>
32
- </tr>
33
- <tr>
34
- <td>? - single character Wildcard</td>
35
- <td>Ultimate?Repo – finds e.g. Ultimate-Repo, Ultimate Repo, Ultimate+Repo</td>
36
- </tr>
37
- <tr>
38
- <td>* - multiple character Wildcard</td>
39
- <td>Ultimat*y - finds e.g. Ultimate Repository, Ultimate-Special-Repository, Ultimately</td>
40
- </tr>
41
- </table>
42
-
43
-
44
- ### Ranges
45
-
46
- Range Queries allow one to match documents whose field(s) values are between the lower and upper bound specified by the Range Query. Range Queries can be inclusive or exclusive of the upper and lower bounds. Sorting is done lexicographically.
47
-
48
- Ranges are not reserved to numerical fields.
49
-
50
- <table>
51
- <tr>
52
- <th>Definition</th>
53
- <th>Example</th>
54
- </tr>
55
- <tr>
56
- <td>[ … TO … ] - inclusive range</td>
57
- <td>creationDate:[1609459200000 TO 1612137600000] – finds e.G. repositories created between 2021-01-01 and 2021-02-01 </td>
58
- </tr>
59
- <tr>
60
- <td>{… TO …} - exclusive range</td>
61
- <td>name:{Aida TO Carmen} – finds e.G. repositories with names between Aida and Carmen, excluding these to values.</td>
62
- </tr>
63
- </table>
64
-
65
-
66
- ### Boosting
67
-
68
- Boosting allows you to control the relevance of a document by boosting its term.
69
-
70
- <table>
71
- <tr>
72
- <th>Definition</th>
73
- <th>Example</th>
74
- </tr>
75
- <tr>
76
- <td>term^number</td>
77
- <td>ultimate^2 repository – makes the term "ultimate" more relevant. </td>
78
- </tr>
79
- </table>
80
-
81
-
82
- By default, the boost factor is 1. Although the boost factor must be positive, it can be less than 1 (e.g. 0.2)
83
-
84
- By default Repository names are boosted by 1.5, namespace by 1.25.
85
-
86
- ## Boolean Operators
87
-
88
- Note: Logical Operators must be entered in upper case (e.g. "AND").
89
-
90
- <table>
91
- <tr>
92
- <th>Definition</th>
93
- <th>Example</th>
94
- </tr>
95
- <tr>
96
- <td>AND – both terms must be included</td>
97
- <td>Ultimate AND Repository – finds e.g. Ultimate Repository, Ultimate Special Repository</td>
98
- </tr>
99
- <tr>
100
- <td>OR – at least one of the terms must be included</td>
101
- <td>Ultimate OR Repository – finds e.g. Ultimate Repository, Ultimate User, Special Repository</td>
102
- </tr>
103
- <tr>
104
- <td>NOT – following term may not be included, "!" may be used alternatively</td>
105
- <td>Ultimate NOT Repository – finds e.g. Ultimate user, excludes e.g. Ultimate Repository</td>
106
- </tr>
107
- <tr>
108
- <td>– excludes following term from search</td>
109
- <td>Ultimate Repository -Special – finds e.g. Ultimate Repository, excludes e.g. Ultimate Special Repository</td>
110
- </tr>
111
- <tr>
112
- <td>– following term must be included</td>
113
- <td>Ultimate +Repository – finds e.g. my Repository, Ultimate Repository</td>
114
- </tr>
115
- </table>
116
-
117
-
118
- ## Grouping
119
-
120
- Search supports using parentheses to group clauses to form sub queries. This can be very useful if you want to control the boolean logic for a query.
121
-
122
- <table>
123
- <tr>
124
- <th>Definition</th>
125
- <th>Example</th>
126
- </tr>
127
- <tr>
128
- <td>() – terms inside parentheses are grouped together</td>
129
- <td>(Ultimate OR my) AND Repository – finds e.g. Ultimate Repository, my Repository, excludes e.g. Super Repository. Either "Ultimate" or “My” must exist, “Repository” must always exist.
130
- </td>
131
- </tr>
132
- </table>
133
-
134
-
135
- ## Escaping Special Characters
136
-
137
- The search supports escaping special characters that are part of the query syntax. The current list special characters are
138
-
139
- &plus; &minus; && || ! ( ) { } [ ] ^ " ~ * ? : &bsol; /
140
-
141
- To escape these characters use the "&bsol;" before the character. For example to search for (1+1):2 use the query:
142
-
143
- &bsol;(1&bsol;+1&bsol;)&bsol;:2
144
-
145
- Source: [https://javadoc.io/static/org.apache.lucene/lucene-queryparser/8.9.0/org/apache/lucene/queryparser/classic/package-summary.html#package.description](https://javadoc.io/static/org.apache.lucene/lucene-queryparser/8.9.0/org/apache/lucene/queryparser/classic/package-summary.html#package.description)`;
package/src/history.ts DELETED
@@ -1,62 +0,0 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
- import { ApiResult } from "./base";
25
- import { Changeset, ChangesetCollection, File, Link, Repository } from "@scm-manager/ui-types";
26
- import { useQuery, useQueryClient } from "react-query";
27
- import { apiClient } from "./apiclient";
28
- import { createQueryString } from "./utils";
29
- import { changesetQueryKey } from "./changesets";
30
- import { repoQueryKey } from "./keys";
31
-
32
- export type UseHistoryRequest = {
33
- page?: number | string;
34
- };
35
-
36
- export const useHistory = (
37
- repository: Repository,
38
- revision: string,
39
- file: File,
40
- request?: UseHistoryRequest
41
- ): ApiResult<ChangesetCollection> => {
42
- const queryClient = useQueryClient();
43
- const link = (file._links.history as Link).href;
44
-
45
- const queryParams: Record<string, string> = {};
46
- if (request?.page) {
47
- queryParams.page = request.page.toString();
48
- }
49
-
50
- return useQuery<ChangesetCollection, Error>(
51
- repoQueryKey(repository, "history", revision, file.path, request?.page || 0),
52
- () => apiClient.get(`${link}?${createQueryString(queryParams)}`).then((response) => response.json()),
53
- {
54
- keepPreviousData: true,
55
- onSuccess: (changesets: ChangesetCollection) => {
56
- changesets._embedded?.changesets.forEach((changeset: Changeset) =>
57
- queryClient.setQueryData(changesetQueryKey(repository, changeset.id), changeset)
58
- );
59
- },
60
- }
61
- );
62
- };
package/src/import.ts DELETED
@@ -1,114 +0,0 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import { ApiResult, fetchResourceFromLocationHeader, getResponseJson, useRequiredIndexLink } from "./base";
26
- import { useMutation, useQuery } from "react-query";
27
- import { apiClient } from "./apiclient";
28
- import { Repository, RepositoryCreation, RepositoryType, RepositoryUrlImport } from "@scm-manager/ui-types";
29
- import { requiredLink } from "./links";
30
-
31
- export const useImportLog = (logId: string): ApiResult<string> => {
32
- const link = useRequiredIndexLink("importLog").replace("{logId}", logId);
33
- return useQuery<string, Error>(["importLog", logId], () => apiClient.get(link).then(response => response.text()));
34
- };
35
-
36
- export const useImportRepositoryFromUrl = (repositoryType: RepositoryType) => {
37
- const url = requiredLink(repositoryType, "import", "url");
38
- const { isLoading, error, data, mutate } = useMutation<Repository, Error, RepositoryUrlImport>(repo =>
39
- apiClient
40
- .post(url, repo, "application/vnd.scmm-repository+json;v=2")
41
- .then(fetchResourceFromLocationHeader)
42
- .then(getResponseJson)
43
- );
44
-
45
- return {
46
- isLoading,
47
- error,
48
- importRepositoryFromUrl: (repository: RepositoryUrlImport) => mutate(repository),
49
- importedRepository: data
50
- };
51
- };
52
-
53
- const importRepository = (url: string, repository: RepositoryCreation, file: File, password?: string) => {
54
- return apiClient
55
- .postBinary(url, formData => {
56
- formData.append("bundle", file, file.name);
57
- formData.append("repository", JSON.stringify({ ...repository, password }));
58
- })
59
- .then(fetchResourceFromLocationHeader)
60
- .then(getResponseJson);
61
- };
62
-
63
- type ImportRepositoryFromBundleRequest = {
64
- repository: RepositoryCreation;
65
- file: File;
66
- compressed?: boolean;
67
- password?: string;
68
- };
69
-
70
- export const useImportRepositoryFromBundle = (repositoryType: RepositoryType) => {
71
- const url = requiredLink(repositoryType, "import", "bundle");
72
- const { isLoading, error, data, mutate } = useMutation<Repository, Error, ImportRepositoryFromBundleRequest>(
73
- ({ repository, file, compressed, password }) =>
74
- importRepository(compressed ? url + "?compressed=true" : url, repository, file, password)
75
- );
76
-
77
- return {
78
- isLoading,
79
- error,
80
- importRepositoryFromBundle: (repository: RepositoryCreation, file: File, compressed?: boolean, password?: string) =>
81
- mutate({
82
- repository,
83
- file,
84
- compressed,
85
- password
86
- }),
87
- importedRepository: data
88
- };
89
- };
90
-
91
- type ImportFullRepositoryRequest = {
92
- repository: RepositoryCreation;
93
- file: File;
94
- password?: string;
95
- };
96
-
97
- export const useImportFullRepository = (repositoryType: RepositoryType) => {
98
- const { isLoading, error, data, mutate } = useMutation<Repository, Error, ImportFullRepositoryRequest>(
99
- ({ repository, file, password }) =>
100
- importRepository(requiredLink(repositoryType, "import", "fullImport"), repository, file, password)
101
- );
102
-
103
- return {
104
- isLoading,
105
- error,
106
- importFullRepository: (repository: RepositoryCreation, file: File, password?: string) =>
107
- mutate({
108
- repository,
109
- file,
110
- password
111
- }),
112
- importedRepository: data
113
- };
114
- };
package/src/index.ts DELETED
@@ -1,72 +0,0 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import * as urls from "./urls";
26
-
27
- export { urls };
28
-
29
- export * from "./errors";
30
- export * from "./apiclient";
31
-
32
- export * from "./base";
33
- export * from "./login";
34
- export * from "./groups";
35
- export * from "./users";
36
- export * from "./suggestions";
37
- export * from "./userSuggestions";
38
- export * from "./groupSuggestions";
39
- export * from "./namespaceSuggestions";
40
- export * from "./repositories";
41
- export * from "./namespaces";
42
- export * from "./branches";
43
- export * from "./changesets";
44
- export * from "./tags";
45
- export * from "./config";
46
- export * from "./admin";
47
- export * from "./plugins";
48
- export * from "./repository-roles";
49
- export * from "./permissions";
50
- export * from "./sources";
51
- export * from "./import";
52
- export * from "./diff";
53
- export * from "./notifications";
54
- export * from "./alerts";
55
- export * from "./configLink";
56
- export * from "./apiKeys";
57
- export * from "./publicKeys";
58
- export * from "./fileContent";
59
- export * from "./history";
60
- export * from "./contentType";
61
- export * from "./annotations";
62
- export * from "./search";
63
- export * from "./loginInfo";
64
- export * from "./usePluginCenterAuthInfo";
65
- export * from "./compare";
66
- export * from "./utils";
67
- export * from "./links";
68
-
69
- export { default as ApiProvider } from "./ApiProvider";
70
- export * from "./ApiProvider";
71
-
72
- export * from "./LegacyContext";
package/src/keys.ts DELETED
@@ -1,48 +0,0 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
- import { Branch, NamespaceAndName } from "@scm-manager/ui-types";
25
-
26
- export const repoQueryKey = (repository: NamespaceAndName, ...values: unknown[]) => {
27
- return ["repository", repository.namespace, repository.name, ...values];
28
- };
29
-
30
- const isBranch = (branch: string | Branch): branch is Branch => {
31
- return (branch as Branch).name !== undefined;
32
- };
33
-
34
- export const branchQueryKey = (
35
- repository: NamespaceAndName,
36
- branch: string | Branch | undefined,
37
- ...values: unknown[]
38
- ) => {
39
- let branchName;
40
- if (!branch) {
41
- branchName = "_";
42
- } else if (isBranch(branch)) {
43
- branchName = branch.name;
44
- } else {
45
- branchName = branch;
46
- }
47
- return [...repoQueryKey(repository), "branch", branchName, ...values];
48
- };
package/src/links.test.ts DELETED
@@ -1,99 +0,0 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
- import { requiredLink } from "./links";
25
-
26
- describe("requireLink tests", () => {
27
- it("should return required link", () => {
28
- const link = requiredLink(
29
- {
30
- _links: {
31
- spaceship: {
32
- href: "/v2/ship",
33
- },
34
- },
35
- },
36
- "spaceship"
37
- );
38
- expect(link).toBe("/v2/ship");
39
- });
40
-
41
- it("should throw error, if link is missing", () => {
42
- const object = { _links: {} };
43
- expect(() => requiredLink(object, "spaceship")).toThrowError();
44
- });
45
-
46
- it("should throw error, if link is array", () => {
47
- const object = {
48
- _links: {
49
- spaceship: [
50
- {
51
- name: "one",
52
- href: "/v2/one",
53
- },
54
- {
55
- name: "two",
56
- href: "/v2/two",
57
- },
58
- ],
59
- },
60
- };
61
- expect(() => requiredLink(object, "spaceship")).toThrowError();
62
- });
63
-
64
- it("should return sub-link if it exists", () => {
65
- const object = {
66
- _links: {
67
- spaceship: [
68
- {
69
- name: "one",
70
- href: "/v2/one",
71
- },
72
- {
73
- name: "two",
74
- href: "/v2/two",
75
- },
76
- ],
77
- },
78
- };
79
- expect(requiredLink(object, "spaceship", "one")).toBe("/v2/one");
80
- });
81
-
82
- it("should throw error, if sub-link does not exist in link array", () => {
83
- const object = {
84
- _links: {
85
- spaceship: [
86
- {
87
- name: "one",
88
- href: "/v2/one",
89
- },
90
- {
91
- name: "two",
92
- href: "/v2/two",
93
- },
94
- ],
95
- },
96
- };
97
- expect(() => requiredLink(object, "spaceship", "three")).toThrowError();
98
- });
99
- });
package/src/links.ts DELETED
@@ -1,54 +0,0 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
- import { HalRepresentation, Link } from "@scm-manager/ui-types";
25
- import { MissingLinkError } from "./errors";
26
-
27
- export const requiredLink = (object: HalRepresentation, name: string, subName?: string): string => {
28
- const link = object._links[name];
29
- if (!link) {
30
- throw new MissingLinkError(`could not find link with name ${name}`);
31
- }
32
- if (Array.isArray(link)) {
33
- if (subName) {
34
- const subLink = link.find((l: Link) => l.name === subName);
35
- if (subLink) {
36
- return subLink.href;
37
- }
38
- throw new Error(`could not return href, sub-link ${subName} in ${name} does not exist`);
39
- }
40
- throw new Error(`could not return href, link ${name} is a multi link`);
41
- }
42
- return link.href;
43
- };
44
-
45
- export const objectLink = (object: HalRepresentation, name: string) => {
46
- const link = object._links[name];
47
- if (!link) {
48
- return null;
49
- }
50
- if (Array.isArray(link)) {
51
- throw new Error(`could not return href, link ${name} is a multi link`);
52
- }
53
- return link.href;
54
- };