1 | import { combine, hOP, isUrlAbsolute } from "@pnp/core";
|
2 | import { extractWebUrl } from "./extract-web-url.js";
|
3 | export function odataUrlFrom(candidate) {
|
4 | const parts = [];
|
5 | const s = ["odata.type", "odata.editLink", "__metadata", "odata.metadata", "odata.id"];
|
6 | if (hOP(candidate, s[0]) && candidate[s[0]] === "SP.Web") {
|
7 |
|
8 | if (hOP(candidate, s[4])) {
|
9 | parts.push(candidate[s[4]]);
|
10 | }
|
11 | else if (hOP(candidate, s[2])) {
|
12 |
|
13 | parts.push(candidate.__metadata.uri);
|
14 | }
|
15 | }
|
16 | else {
|
17 | if (hOP(candidate, s[3]) && hOP(candidate, s[1])) {
|
18 |
|
19 |
|
20 |
|
21 | const editLink = isUrlAbsolute(candidate[s[1]]) ? candidate[s[1]].split("_api")[1] : candidate[s[1]];
|
22 | parts.push(extractWebUrl(candidate[s[3]]), "_api", editLink);
|
23 | }
|
24 | else if (hOP(candidate, s[1])) {
|
25 | parts.push("_api", candidate[s[1]]);
|
26 | }
|
27 | else if (hOP(candidate, s[2])) {
|
28 |
|
29 | parts.push(candidate.__metadata.uri);
|
30 | }
|
31 | }
|
32 | if (parts.length < 1) {
|
33 | return "";
|
34 | }
|
35 | return combine(...parts);
|
36 | }
|
37 |
|
\ | No newline at end of file |