Skip to content

Commit 5b1cf53

Browse files
Fix listFederation, add id property (#67 option 1)
If coming from a spec-compliant backend, `this.data.federation` is an object, so the function used to always return the empty array. The code now transforms the object into an array, and also adds the former object keys to each item as an `id` property.
1 parent 6d0e09b commit 5b1cf53

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `id` field to the objects in the array returned by `listFederation` in `Capabilities`
13+
1014
## [2.7.0] - 2025-01-04
1115

1216
### Added

src/capabilities.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,15 @@ class Capabilities {
198198
* @returns {Array.<FederationBackend>} Array of backends
199199
*/
200200
listFederation() {
201-
return Array.isArray(this.data.federation) ? this.data.federation : [];
201+
let federation = [];
202+
if (Utils.isObject(this.data.federation)) {
203+
// convert to array and add keys as `id` property
204+
for(const [key, backend] of Object.entries(this.data.federation)) {
205+
backend.id = key;
206+
federation.push(backend);
207+
}
208+
}
209+
return federation;
202210
}
203211

204212
/**

src/typedefs.js

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@
200200
*
201201
* @typedef FederationBackend
202202
* @type {object}
203+
* @property {string} id ID of the back-end within the federation.
203204
* @property {string} url URL to the versioned API endpoint of the back-end.
204205
* @property {string} title Name of the back-end.
205206
* @property {string} description A description of the back-end and its specifics.

0 commit comments

Comments
 (0)