Skip to content

Commit fd78bb8

Browse files
committed
Improve support for the Federation Extension #63
1 parent 4b2e45d commit fd78bb8

File tree

6 files changed

+111
-21
lines changed

6 files changed

+111
-21
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- New function `getMissingBackends` for `Logs`
13+
- New property `federation:backends` added to the array returned by `validateProcess`
14+
1015
## [2.6.0] - 2024-07-11
1116

1217
### Added

openeo.d.ts

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ declare module OpenEO {
241241
* @param {string|Buffer} str - String to encode.
242242
* @returns {string} String encoded in Base64.
243243
*/
244-
static base64encode(str: string|Buffer): string;
244+
static base64encode(str: string | Buffer): string;
245245
/**
246246
* Detect the file name for the given data source.
247247
*
@@ -302,14 +302,14 @@ declare module OpenEO {
302302
username: string;
303303
/**
304304
* Authenticate with HTTP Basic.
305-
*
305+
*
306306
* @async
307-
* @param {string} username
308-
* @param {string} password
307+
* @param {string} username
308+
* @param {string} password
309309
* @returns {Promise<void>}
310310
* @throws {Error}
311311
*/
312-
login(username: string, password: string) : Promise<void>;
312+
login(username: string, password: string): Promise<void>;
313313
}
314314
/**
315315
* Capabilities of a back-end.
@@ -652,7 +652,7 @@ declare module OpenEO {
652652
* @public
653653
* @type {Array.<string>}
654654
*/
655-
public "federation:missing": Array<string>;
655+
public 'federation:missing': Array<string>;
656656
/**
657657
* Returns the file types response as a JSON serializable representation of the data that is API compliant.
658658
*
@@ -812,9 +812,26 @@ declare module OpenEO {
812812
* @type {Connection}
813813
*/
814814
protected connection: Connection;
815-
endpoint: string;
816-
lastId: string;
817-
level: string;
815+
/**
816+
* @protected
817+
* @type {string}
818+
*/
819+
protected endpoint: string;
820+
/**
821+
* @protected
822+
* @type {string}
823+
*/
824+
protected lastId: string;
825+
/**
826+
* @protected
827+
* @type {?string}
828+
*/
829+
protected level: string | null;
830+
/**
831+
* @protected
832+
* @type {Set<String>}
833+
*/
834+
protected missing: Set<string>;
818835
/**
819836
* Retrieves the next log entries since the last request.
820837
*
@@ -825,6 +842,16 @@ declare module OpenEO {
825842
* @returns {Promise<Array.<Log>>}
826843
*/
827844
nextLogs(limit?: number): Promise<Array<Log>>;
845+
/**
846+
* Retrieves the backend identifiers that are (partially) missing in the logs.
847+
*
848+
* This is only filled after the first request using `nextLogs` or `next`.
849+
*
850+
* @returns {Array.<string>}
851+
* @see {Logs#nextLogs}
852+
* @see {Logs#next}
853+
*/
854+
getMissingBackends(): Array<string>;
828855
/**
829856
* Retrieves the next log entries since the last request.
830857
*
@@ -2259,10 +2286,10 @@ declare module OpenEO {
22592286
*
22602287
* @async
22612288
* @param {Process} process - User-defined process to validate.
2262-
* @returns {Promise<Array.<ApiError>>} errors - A list of API compatible error objects. A valid process returns an empty list.
2289+
* @returns {Promise<ValidationResult>} errors - A list of API compatible error objects. A valid process returns an empty list.
22632290
* @throws {Error}
22642291
*/
2265-
validateProcess(process: Process): Promise<Array<ApiError>>;
2292+
validateProcess(process: Process): Promise<ValidationResult>;
22662293
/**
22672294
* Lists all user-defined processes of the authenticated user.
22682295
*
@@ -2413,7 +2440,7 @@ declare module OpenEO {
24132440
protected _getLinkHref(links: Array<Link>, rel: string | Array<string>): string | null;
24142441
/**
24152442
* Makes all links in the list absolute.
2416-
*
2443+
*
24172444
* @param {Array.<Link>} links - An array of links.
24182445
* @param {?string|AxiosResponse} [base=null] - The base url to use for relative links, or an response to derive the url from.
24192446
* @returns {Array.<Link>}
@@ -2492,11 +2519,11 @@ declare module OpenEO {
24922519
download(url: string, authorize: boolean): Promise<Readable | Blob>;
24932520
/**
24942521
* Get the authorization header for requests.
2495-
*
2522+
*
24962523
* @protected
24972524
* @returns {object.<string, string>}
24982525
*/
2499-
protected _getAuthHeaders() : object<string, string>;
2526+
protected _getAuthHeaders(): object<string, string>;
25002527
/**
25012528
* Sends a HTTP request.
25022529
*
@@ -2876,7 +2903,7 @@ declare module OpenEO {
28762903
*
28772904
* Adds two properties: `links` and `federation:missing`.
28782905
*/
2879-
export type ResponseArray = Array;
2906+
export type ResponseArray = any;
28802907
export type ServiceType = object<string, any>;
28812908
export type SyncResult = {
28822909
/**
@@ -2915,7 +2942,12 @@ declare module OpenEO {
29152942
budget: number | null;
29162943
links: Array<Link> | null;
29172944
};
2918-
2945+
/**
2946+
* An array, but enriched with additional details from an openEO API response.
2947+
*
2948+
* Adds the property `federation:backends`.
2949+
*/
2950+
export type ValidationResult = any;
29192951
}
29202952

29212953
export = OpenEO;

src/connection.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,13 +728,15 @@ class Connection {
728728
*
729729
* @async
730730
* @param {Process} process - User-defined process to validate.
731-
* @returns {Promise<Array.<ApiError>>} errors - A list of API compatible error objects. A valid process returns an empty list.
731+
* @returns {Promise<ValidationResult>} errors - A list of API compatible error objects. A valid process returns an empty list.
732732
* @throws {Error}
733733
*/
734734
async validateProcess(process) {
735735
let response = await this._post('/validation', this._normalizeUserProcess(process).process);
736736
if (Array.isArray(response.data.errors)) {
737-
return response.data.errors;
737+
const errors = response.data.errors;
738+
errors['federation:backends'] = Array.isArray(response.data['federation:missing']) ? response.data['federation:missing'] : [];
739+
return errors;
738740
}
739741
else {
740742
throw new Error("Invalid validation response received.");

src/logs.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,26 @@ class Logs {
1818
* @type {Connection}
1919
*/
2020
this.connection = connection;
21+
/**
22+
* @protected
23+
* @type {string}
24+
*/
2125
this.endpoint = endpoint;
26+
/**
27+
* @protected
28+
* @type {string}
29+
*/
2230
this.lastId = "";
31+
/**
32+
* @protected
33+
* @type {?string}
34+
*/
2335
this.level = level;
36+
/**
37+
* @protected
38+
* @type {Set<String>}
39+
*/
40+
this.missing = new Set();
2441
}
2542

2643
/**
@@ -37,6 +54,19 @@ class Logs {
3754
return Array.isArray(response.logs) ? response.logs : [];
3855
}
3956

57+
/**
58+
* Retrieves the backend identifiers that are (partially) missing in the logs.
59+
*
60+
* This is only filled after the first request using `nextLogs` or `next`.
61+
*
62+
* @returns {Array.<string>}
63+
* @see {Logs#nextLogs}
64+
* @see {Logs#next}
65+
*/
66+
getMissingBackends() {
67+
return Array.from(this.missing);
68+
}
69+
4070
/**
4171
* Retrieves the next log entries since the last request.
4272
*
@@ -64,7 +94,13 @@ class Logs {
6494
else {
6595
response.data.logs = [];
6696
}
97+
6798
response.data.links = Array.isArray(response.data.links) ? response.data.links : [];
99+
100+
if (Array.isArray(response.data["federation:missing"])) {
101+
response.data["federation:missing"].forEach(backend => this.missing.add(backend));
102+
}
103+
68104
return response.data;
69105
}
70106

src/typedefs.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
* An array of backends in the federation.
200200
*
201201
* @typedef FederationBackend
202-
* @type {Object}
202+
* @type {object}
203203
* @property {string} url URL to the versioned API endpoint of the back-end.
204204
* @property {string} title Name of the back-end.
205205
* @property {string} description A description of the back-end and its specifics.
@@ -257,4 +257,15 @@
257257
* @property {?UserAccountStorage} storage
258258
* @property {?number} budget
259259
* @property {?Array.<Link>} links
260-
*/
260+
*/
261+
262+
/**
263+
* An array, but enriched with additional details from an openEO API response.
264+
*
265+
* Adds the property `federation:backends`.
266+
*
267+
* @typedef ValidationResult
268+
* @augments Array
269+
* @type {Array.<ApiError>}
270+
* @property {Array.<string>} ["federation:backends"] The back-ends that support / do not support the process.
271+
*/

tests/earthengine.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ describe('GEE back-end', () => {
259259
test('Valid process graph', async () => {
260260
let result = await con.validateProcess(VALID_PROCESS);
261261
expect(Array.isArray(result)).toBeTruthy();
262-
expect(result).toEqual([]);
262+
expect(result.length).toBe(0);
263+
expect(result["federation:backends"]).toEqual([]);
263264
});
264265

265266
test('Invalid process graph', async () => {
@@ -485,11 +486,14 @@ describe('GEE back-end', () => {
485486
test('Debug Job', async () => {
486487
let logsIterator = job.debugJob();
487488
expect(logsIterator instanceof Logs).toBeTruthy();
489+
expect(logsIterator.getMissingBackends()).toEqual([]);
488490
let logs1 = await logsIterator.next();
489491
expect(Array.isArray(logs1.logs)).toBeTruthy();
490492
expect(Array.isArray(logs1.links)).toBeTruthy();
493+
expect(logsIterator.getMissingBackends()).toEqual([]);
491494
let logs2 = await logsIterator.nextLogs();
492495
expect(Array.isArray(logs2)).toBeTruthy();
496+
expect(logsIterator.getMissingBackends()).toEqual([]);
493497
// ToDo: Add more tests
494498
});
495499

0 commit comments

Comments
 (0)