From 2839e12112d50b4e7721f8c4944003b33de85e73 Mon Sep 17 00:00:00 2001 From: Stefan Peters Date: Fri, 25 Feb 2022 09:14:59 +0100 Subject: [PATCH] Adjust how schemes are handled if given as array on registry (#43) - this._api.schemes will not contain an array of schemes anymore. - ConceptApi: getSchemes will always perform request, then filter by the list of schemes in this._jskos.schemes if necessary. --- src/lib/CocodaSDK.js | 4 ++-- src/providers/base-provider.js | 3 ++- src/providers/concept-api-provider.js | 12 +++++------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/lib/CocodaSDK.js b/src/lib/CocodaSDK.js index 6896c11..f420b54 100644 --- a/src/lib/CocodaSDK.js +++ b/src/lib/CocodaSDK.js @@ -400,8 +400,8 @@ export default class CocodaSDK { // Registry in cache is used const registry = registryCache[url] // Check if scheme is part of registry already; if not, add it - if (Array.isArray(registry._api.schemes) && !jskos.isContainedIn(scheme, registry._api.schemes)) { - registry._api.schemes.push(scheme) + if (Array.isArray(registry._jskos.schemes) && !jskos.isContainedIn(scheme, registry._jskos.schemes)) { + registry._jskos.schemes.push(scheme) } return registry } else { diff --git a/src/providers/base-provider.js b/src/providers/base-provider.js index b0f521f..a462333 100644 --- a/src/providers/base-provider.js +++ b/src/providers/base-provider.js @@ -109,7 +109,8 @@ export default class BaseProvider { // Set API URLs from registry object this._api = { status: registry.status, - schemes: registry.schemes, + // If `schemes` on registry is an array, remove it because we're only keeping it in this._jskos.schemes + schemes: Array.isArray(registry.schemes) ? undefined : registry.schemes, top: registry.top, data: registry.data, concepts: registry.concepts, diff --git a/src/providers/concept-api-provider.js b/src/providers/concept-api-provider.js index c8cc0e5..e045901 100644 --- a/src/providers/concept-api-provider.js +++ b/src/providers/concept-api-provider.js @@ -125,8 +125,9 @@ export default class ConceptApiProvider extends BaseProvider { return null } // Otherwise load scheme data and save in approved/rejected schemes - // TODO: What does the `uri` parameter here actually do? - const schemes = await this.getSchemes({ uri: jskos.getAllUris(scheme) }) + const schemes = await this.getSchemes({ params: { + uri: jskos.getAllUris(scheme).join("|"), + } }) const resultScheme = schemes.find(s => jskos.compare(s, scheme)) if (resultScheme) { this._approvedSchemes.push({ @@ -153,9 +154,6 @@ export default class ConceptApiProvider extends BaseProvider { if (!this._api.schemes) { throw new errors.MissingApiUrlError() } - if (Array.isArray(this._api.schemes)) { - return this._api.schemes - } const schemes = await this.axios({ ...config, method: "get", @@ -168,8 +166,8 @@ export default class ConceptApiProvider extends BaseProvider { }, }) // If schemes were given in registry object, only request those schemes from API - if (Array.isArray(this._jskos.schemes)) { - return utils.withCustomProps(schemes.filter(s => jskos.isContainedIn(s, this._jskos.schemes)), schemes) + if (Array.isArray(this.schemes)) { + return utils.withCustomProps(schemes.filter(s => jskos.isContainedIn(s, this.schemes)), schemes) } else { return schemes }