|
1 | 1 | const Utils = require('@openeo/js-commons/src/utils');
|
| 2 | +if (typeof RegExp.escape !== 'function') { |
| 3 | + require('regexp.escape').shim(); |
| 4 | +} |
2 | 5 |
|
3 | 6 | const FEATURE_MAP = {
|
4 | 7 | // Discovery
|
5 | 8 | capabilities: true,
|
6 | 9 | listFileTypes: 'get /file_formats',
|
7 | 10 | listServiceTypes: 'get /service_types',
|
8 | 11 | listUdfRuntimes: 'get /udf_runtimes',
|
| 12 | + listProcessingParameters: 'get /processing_parameters', |
9 | 13 | // Collections
|
10 | 14 | listCollections: 'get /collections',
|
11 | 15 | describeCollection: 'get /collections/{}',
|
@@ -58,6 +62,22 @@ const FEATURE_MAP = {
|
58 | 62 | debugService: 'get /services/{}/logs',
|
59 | 63 | };
|
60 | 64 |
|
| 65 | +const CONFORMANCE_CLASSES = { |
| 66 | + openeo: "https://api.openeo.org/extensions/openeo/v1.*", |
| 67 | + // STAC API |
| 68 | + stacCollections: [ |
| 69 | + 'https://api.stacspec.org/v1.*/collections', |
| 70 | + 'https://api.stacspec.org/v1.*/ogcapi-features' |
| 71 | + ], |
| 72 | + stacItems: 'https://api.stacspec.org/v1.*/ogcapi-features', |
| 73 | + // openEO API Extensions |
| 74 | + commercialData: 'https://api.openeo.org/extensions/commercial-data/0.1.*', |
| 75 | + federation: 'https://api.openeo.org/extensions/federation/0.1.*', |
| 76 | + processingParameters: "https://api.openeo.org/extensions/processing-parameters/0.1.*", |
| 77 | + remoteProcessDefinition: 'https://api.openeo.org/extensions/remote-process-definition/0.1.*', |
| 78 | + workspaces: 'https://api.openeo.org/extensions/workspaces/0.1.*' |
| 79 | +}; |
| 80 | + |
61 | 81 | /**
|
62 | 82 | * Capabilities of a back-end.
|
63 | 83 | */
|
@@ -261,6 +281,29 @@ class Capabilities {
|
261 | 281 | return feature === true || this.features.some(e => e === feature);
|
262 | 282 | }
|
263 | 283 |
|
| 284 | + /** |
| 285 | + * Check whether a conformance class is supported by the back-end. |
| 286 | + * |
| 287 | + * Use `*` as a wildcard character for e.g. version numbers. |
| 288 | + * |
| 289 | + * @param {string|Array.<string>} uris - Conformance class URI(s) - any of them must match. |
| 290 | + * @returns {boolean} `true` if any of the conformance classes is supported, otherwise `false`. |
| 291 | + */ |
| 292 | + hasConformance(uris) { |
| 293 | + if (typeof uris === 'string') { |
| 294 | + uris = [uris]; |
| 295 | + } |
| 296 | + if(!Array.isArray(this.data.conformsTo) || !Array.isArray(uris)) { |
| 297 | + return false; |
| 298 | + } |
| 299 | + |
| 300 | + const classRegexp = uris |
| 301 | + .map(uri => RegExp.escape(uri).replaceAll('\\*', '[^/]+')) |
| 302 | + .join('|'); |
| 303 | + const regexp = new RegExp('^(' + classRegexp + ')$'); |
| 304 | + return Boolean(this.data.conformsTo.find(uri => uri.match(regexp))); |
| 305 | + } |
| 306 | + |
264 | 307 | /**
|
265 | 308 | * Get the billing currency.
|
266 | 309 | *
|
@@ -302,4 +345,6 @@ class Capabilities {
|
302 | 345 | }
|
303 | 346 | }
|
304 | 347 |
|
| 348 | +Capabilities.Conformance = CONFORMANCE_CLASSES; |
| 349 | + |
305 | 350 | module.exports = Capabilities;
|
0 commit comments