Skip to content

Commit b72f302

Browse files
Add helpers for retrieving backend details (#67 option 3)
1 parent a264163 commit b72f302

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

openeo.d.ts

+14
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,20 @@ declare module OpenEO {
409409
* @returns {Array.<FederationBackend>} Array of backends
410410
*/
411411
listFederation(): Array<FederationBackend>;
412+
/**
413+
* Given just the string ID of a backend within the federation, returns that backend's full details as a FederationBackend object
414+
*
415+
* @param {string} backendId The ID of a backend within the federation
416+
* @returns {FederationBackend} The full details of the backend, or `undefined` if no backend with the given ID exists
417+
*/
418+
getFederationBackendById(backendId: string): FederationBackend | undefined;
419+
/**
420+
* Given a list of string IDs of backends within the federation, returns those backends' full details as FederationBackend objects
421+
*
422+
* @param {Array<string>} backendIds The IDs of backends within the federation
423+
* @returns {Array<FederationBackend>} An array in the same order as the input, containing for each position either the full details of the backend, or `undefined` if no backend with the given ID exists
424+
*/
425+
getFederationBackendsByIds(backendIds: Array<string>): Array<FederationBackend | undefined>;
412426
/**
413427
* Lists all supported features.
414428
*

src/capabilities.js

+22
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,28 @@ class Capabilities {
209209
return federation;
210210
}
211211

212+
/**
213+
* Given just the string ID of a backend within the federation, returns that backend's full details as a FederationBackend object
214+
*
215+
* @param {string} backendId The ID of a backend within the federation
216+
* @returns {FederationBackend | undefined} The full details of the backend, or `undefined` if no backend with the given ID exists
217+
*/
218+
getFederationBackendById(backendId) {
219+
// Add `id` property to make it a proper FederationBackend object, but check for undefined case beforehand
220+
return this.data.federation[backendId] ? { id: backendId, ...this.data.federation[backendId] } : undefined;
221+
}
222+
223+
/**
224+
* Given a list of string IDs of backends within the federation, returns those backends' full details as FederationBackend objects
225+
*
226+
* @param {Array<string>} backendIds The IDs of backends within the federation
227+
* @returns {Array<FederationBackend | undefined>} An array in the same order as the input, containing for each position either the full details of the backend, or `undefined` if no backend with the given ID exists
228+
*/
229+
getFederationBackendsByIds(backendIds) {
230+
// Let 'single case' function do the work, but pass `this` so that `this.data.federation` can be accessed in the callback context
231+
return backendIds.map(this.getFederationBackendById, this);
232+
}
233+
212234
/**
213235
* Lists all supported features.
214236
*

0 commit comments

Comments
 (0)