• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wozjac / vscode-ui5-api-reference / 9624493125

22 Jun 2024 09:26AM UTC coverage: 73.579%. Remained the same
9624493125

Pull #23

github

wozjac
chore: update eslint to include TypeScript files in linting
Pull Request #23: build: add `typescript-eslint`

122 of 172 branches covered (70.93%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 2 files covered. (100.0%)

1 existing line in 1 file now uncovered.

357 of 479 relevant lines covered (74.53%)

7.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

19.33
/src/core/ui5ApiService.ts
1
import * as ui5Api from "./types.js";
2
import * as constants from "./constants.js";
1✔
3
import * as dataSource from "./dataSource.js";
1✔
4
import * as apiBuffer from "./ui5ApiBuffer.js";
1✔
5

6
interface Ui5LibrariesApi {
7
  [index: string]: ui5Api.LibraryApi;
8
}
9

10
interface SapLibraryDefs {
11
  [index: string]: string | object;
12
}
13

14
const apiIndexNodes: { [key: string]: ui5Api.ApiIndexNodeEnhanced } = {};
1✔
15
const ui5Libraries: Ui5LibrariesApi = {};
1✔
16

17
export const sapLibraryDefs: SapLibraryDefs = {
1✔
18
  "!name": "sap",
19
};
20

21
let apiBaseUrl: string;
22

23
export function setApiBaseURL(apiUrl: string) {
1✔
24
  apiBaseUrl = apiUrl;
1✔
25
}
26

27
export function fetchApiIndex(): Promise<ui5Api.ApiIndex> {
1✔
28
  return dataSource.fetchJSON(`${apiBaseUrl}/docs/api/api-index.json`) as Promise<ui5Api.ApiIndex>;
×
29
}
30

31
function fetchLibraryApi(libraryApiUrl: string): Promise<ui5Api.LibraryApi> {
32
  return dataSource.fetchJSON(libraryApiUrl) as Promise<ui5Api.LibraryApi>;
×
33
}
34

35
function getLibraryApi(libraryName: string): Promise<ui5Api.LibraryApi> {
36
  //eslint-disable-next-line @typescript-eslint/no-explicit-any
UNCOV
37
  const libraryApi = ui5Libraries[libraryName] as any;
×
38

39
  return new Promise((resolve, reject) => {
×
40
    if (Object.keys(libraryApi).length) {
×
41
      resolve(libraryApi);
×
42
    } else {
43
      const libraryUrlName = libraryName.replace(/\./g, "/");
×
44
      const libraryApiUrl = `${apiBaseUrl}/test-resources/${libraryUrlName}/designtime/api.json`;
×
45

46
      fetchLibraryApi(libraryApiUrl).then(
×
47
        (libraryApi) => {
48
          resolve(libraryApi);
×
49
        },
50
        (error) => {
51
          reject(error);
×
52
        }
53
      );
54
    }
55
  });
56
}
57

58
export function getUi5Objects() {
1✔
59
  if (Object.keys(apiIndexNodes).length) {
×
60
    return apiIndexNodes;
×
61
  } else {
62
    throw new Error("UI5 objects could not be loaded");
×
63
  }
64
}
65

66
export function getUi5ObjectDesignApi(
1✔
67
  ui5ObjectName: string,
68
  resultApi?: ui5Api.LibraryApiSymbol
69
): ui5Api.LibraryApiSymbol | undefined {
70
  const ui5Object = apiIndexNodes[ui5ObjectName];
×
71

72
  //no library === just namespace
73
  // if (!ui5Object.library) {
74
  //   return {
75
  //     kind: "namespace",
76
  //     name: ui5ObjectName,
77
  //   };
78
  // }
79

80
  let objectApi: ui5Api.LibraryApiSymbol | undefined;
81
  const bufferedDesignApi = apiBuffer.searchObjectDesignApiBuffer(ui5Object.name);
×
82

83
  if (bufferedDesignApi) {
×
84
    objectApi = bufferedDesignApi;
×
85
  } else {
86
    const libraryApi = ui5Libraries[ui5Object.library];
×
87

88
    objectApi = libraryApi.symbols.find((element) => {
×
89
      if (element.kind === "class" || element.kind === "enum") {
×
90
        return element.name === ui5Object.name;
×
91
      } else {
92
        return element.basename === ui5Object.basename;
×
93
      }
94
    });
95

96
    if (!objectApi) {
×
97
      return;
×
98
    }
99

100
    objectApi.apiDocUrl = ui5Object.apiDocUrl;
×
101
  }
102

103
  //method called recursively, we have previous result -> add new stuff
104
  if (resultApi) {
×
105
    if (!resultApi.inheritedApi) {
×
106
      resultApi.inheritedApi = {};
×
107
    }
108

109
    resultApi.inheritedApi[ui5ObjectName] = objectApi;
×
110
  } else {
111
    resultApi = objectApi;
×
112
  }
113

114
  if (objectApi.extends) {
×
115
    return getUi5ObjectDesignApi(objectApi.extends, resultApi);
×
116
  } else {
117
    apiBuffer.addToObjectDesignApiBuffer(resultApi);
×
118
    return resultApi;
×
119
  }
120
}
121

122
//eslint-disable-next-line @typescript-eslint/no-explicit-any
123
export function loadUi5Objects(): Promise<any> {
1✔
124
  if (Object.keys(apiIndexNodes).length > 0) {
×
125
    return Promise.resolve(true);
×
126
  } else {
127
    return fetchApiIndex().then(
×
128
      (apiIndex) => {
129
        prepareUi5Objects(apiIndex);
×
130
        console.log(`${constants.pluginLogPrefix}: UI5 API loaded from ${apiBaseUrl}`);
×
131
        Promise.resolve(true);
×
132
      },
133
      (error) => {
134
        Promise.reject(error);
×
135
      }
136
    );
137
  }
138
}
139

140
export function loadUi5LibrariesDesignApi(): Promise<void[]> {
1✔
141
  const promises = [];
×
142

143
  for (const libraryKey in ui5Libraries) {
×
144
    promises.push(
×
145
      new Promise<void>((resolve) => {
146
        getLibraryApi(libraryKey)
×
147
          .then((libraryApi) => {
148
            if (libraryApi.symbols && Array.isArray(libraryApi.symbols)) {
×
149
              libraryApi.symbols.forEach((element) => {
×
150
                element.name = getNormalizedName(element.name);
×
151
                element.originalName = element.name;
×
152
                element.apiDocUrl = getUi5ObjectApiDocUrl(element.name, apiBaseUrl);
×
153
              });
154
            }
155

156
            ui5Libraries[libraryKey] = libraryApi;
×
157
            console.log(`${constants.pluginLogPrefix}: loaded UI5 library: ${libraryKey}`);
×
158
            resolve();
×
159
          })
160
          .catch((error) => {
161
            //continue, no rejections
162
            console.error(`${error}`);
×
163
            return;
×
164
          });
165
      })
166
    );
167
  }
168

169
  return Promise.all(promises);
×
170
}
171

172
function prepareUi5Objects(apiIndexEntry: ui5Api.ApiIndex | ui5Api.ApiIndexNode) {
173
  let normalizedName;
174

175
  if ("symbols" in apiIndexEntry) {
×
176
    for (const object of apiIndexEntry.symbols) {
×
177
      normalizedName = getNormalizedName(object.name);
×
178
      apiIndexNodes[normalizedName] = enhanceApiIndexNode(object);
×
179

180
      //extract library
181
      ui5Libraries[object.lib] = <ui5Api.LibraryApi>{};
×
182

183
      if (object.nodes) {
×
184
        for (const node of object.nodes) {
×
185
          prepareUi5Objects(node);
×
186
        }
187
      }
188
    }
189
  } else {
190
    normalizedName = getNormalizedName(apiIndexEntry.name);
×
191
    apiIndexNodes[normalizedName] = enhanceApiIndexNode(apiIndexEntry);
×
192
    ui5Libraries[apiIndexEntry.lib] = <ui5Api.LibraryApi>{};
×
193

194
    if (apiIndexEntry.nodes) {
×
195
      for (const node of apiIndexEntry.nodes) {
×
196
        prepareUi5Objects(node);
×
197
      }
198
    }
199
  }
200
}
201

202
export function enhanceApiIndexNode(
1✔
203
  apiIndexNode: ui5Api.ApiIndexNode
204
): ui5Api.ApiIndexNodeEnhanced {
205
  return {
1✔
206
    name: getNormalizedName(apiIndexNode.name),
207
    originalName: apiIndexNode.name,
208
    basename: apiIndexNode.name.substring(apiIndexNode.name.lastIndexOf(".") + 1),
209
    kind: apiIndexNode.kind,
210
    library: apiIndexNode.lib,
211
    apiDocUrl: getUi5ObjectApiDocUrl(apiIndexNode.name, apiBaseUrl),
212
  };
213
}
214

215
export function getNormalizedName(name: string) {
1✔
216
  return name.replace("module:", "").replace(/\//g, ".");
3✔
217
}
218

219
export function getUi5ObjectApiDocUrl(ui5ObjectName: string, apiBaseUrl: string) {
1✔
220
  let path = ui5ObjectName;
3✔
221

222
  if (path.indexOf("module:") !== -1) {
3✔
223
    path = encodeURIComponent(path);
1✔
224
  }
225

226
  return `${apiBaseUrl}/#/api/${path}`;
3✔
227
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc