Skip to content

Commit

Permalink
Adjust how schemes are handled if given as array on registry (#43)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
stefandesu committed Feb 25, 2022
1 parent 49182cd commit 2839e12
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/lib/CocodaSDK.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/providers/base-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 5 additions & 7 deletions src/providers/concept-api-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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",
Expand All @@ -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
}
Expand Down

0 comments on commit 2839e12

Please sign in to comment.