cocoda-sdk 3.6.1 → 3.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -88,7 +88,7 @@ class BaseProvider {
88
88
  }
89
89
  return data;
90
90
  }, (error) => {
91
- const count = error.config._retryCount ?? 0;
91
+ const count = error.config?._retryCount ?? 0;
92
92
  const method = error.config.method;
93
93
  const statusCode = error.response?.status;
94
94
  if (this._retryConfig.methods.includes(method) && this._retryConfig.statusCodes.includes(statusCode) && count < this._retryConfig.count) {
@@ -190,13 +190,10 @@ class ConceptApiProvider extends BaseProvider {
190
190
  if (!url) {
191
191
  throw new errors.MissingApiUrlError();
192
192
  }
193
- if (!concepts) {
194
- throw new errors.InvalidOrMissingParameterError({ parameter: "concepts" });
195
- }
196
193
  if (!Array.isArray(concepts)) {
197
- concepts = [concepts];
194
+ concepts = concepts ? [concepts] : [];
198
195
  }
199
- let uris = concepts.map((concept) => concept.uri).filter((uri) => uri != null);
196
+ const uris = concepts.map((concept) => concept.uri).filter((uri) => uri != null);
200
197
  return this.axios({
201
198
  ...config,
202
199
  method: "get",
@@ -204,7 +201,7 @@ class ConceptApiProvider extends BaseProvider {
204
201
  params: {
205
202
  ...this._defaultParams,
206
203
  // ? What should the default limit be?
207
- limit: 500,
204
+ limit: 100,
208
205
  ...config.params || {},
209
206
  uri: uris.join("|")
210
207
  }
@@ -16,7 +16,7 @@ class OlsApiProvider extends BaseProvider {
16
16
  };
17
17
  constructor(config) {
18
18
  super(config);
19
- this.endpoint = config.endpoint;
19
+ this.endpoint = config.endpoint || config.uri;
20
20
  }
21
21
  /**
22
22
  * Used by `registryForScheme` (see src/lib/CocodaSDK.js) to determine a provider config for a concept schceme.
@@ -95,7 +95,7 @@ class OlsApiProvider extends BaseProvider {
95
95
  }
96
96
  if (term["http://www.w3.org/2000/01/rdf-schema#label"]) {
97
97
  concept.prefLabel = {};
98
- concept.prefLabel[lan] = term["http://www.w3.org/2000/01/rdf-schema#label"];
98
+ concept.prefLabel[lan] = term["http://www.w3.org/2000/01/rdf-schema#label"].value || term["http://www.w3.org/2000/01/rdf-schema#label"];
99
99
  }
100
100
  concept.type = [
101
101
  "http://www.w3.org/2004/02/skos/core#Concept",
@@ -261,11 +261,8 @@ class OlsApiProvider extends BaseProvider {
261
261
  async getTop({ scheme }) {
262
262
  const VOCID = await this._getSchemeVOCID(scheme);
263
263
  if (VOCID) {
264
- let url = this._getApiUrl(["ontologies", VOCID, "classes"], { hasDirectParents: "false" });
265
- let response = await this._request(url);
266
- if (response?.elements) {
267
- return Promise.all(response.elements.map((item) => this._termToJSKOS(item)));
268
- }
264
+ let response = await this._paginate(["ontologies", VOCID, "classes"], { hasDirectParents: "false" }, null);
265
+ return Promise.all(response.map((item) => this._termToJSKOS(item)));
269
266
  }
270
267
  return [];
271
268
  }
@@ -281,22 +278,16 @@ class OlsApiProvider extends BaseProvider {
281
278
  async getNarrower({ concept }) {
282
279
  const { VOCID, iri } = await this._splitConcept(concept);
283
280
  if (VOCID && iri) {
284
- let url = this._getApiUrl(["ontologies", VOCID, "classes", iri, "children"]);
285
- let response = await this._request(url);
286
- if (response?.elements) {
287
- return Promise.all(response.elements.map((item) => this._termToJSKOS(item)));
288
- }
281
+ const items = await this._paginate(["ontologies", VOCID, "classes", iri, "children"], {}, 0);
282
+ return Promise.all(items.map((item) => this._termToJSKOS(item)));
289
283
  }
290
284
  return [];
291
285
  }
292
286
  async getAncestors({ concept }) {
293
287
  const { VOCID, iri } = await this._splitConcept(concept);
294
288
  if (VOCID && iri) {
295
- let url = this._getApiUrl(["ontologies", VOCID, "classes", iri, "ancestors"]);
296
- let response = await this._request(url);
297
- if (response?.elements) {
298
- return Promise.all(response.elements.map((item) => this._termToJSKOS(item)));
299
- }
289
+ let response = await this._paginate(["ontologies", VOCID, "classes", iri, "ancestors"], {}, null);
290
+ return Promise.all(response.map((item) => this._termToJSKOS(item)));
300
291
  }
301
292
  return [];
302
293
  }
@@ -45,7 +45,7 @@ class SkosmosApiProvider extends BaseProvider {
45
45
  * @private
46
46
  */
47
47
  _getApiUrl(scheme, endpoint, params) {
48
- const VOCID = scheme && scheme.VOCID || this.schemes.find((s) => jskos.compare(s, scheme))?.VOCID;
48
+ const VOCID = scheme?.VOCID || this.schemes.find((s) => jskos.compare(s, scheme))?.VOCID;
49
49
  if (!VOCID) {
50
50
  throw new errors.InvalidOrMissingParameterError({ parameter: "scheme", message: "Missing scheme or VOCID property on scheme" });
51
51
  }
@@ -179,6 +179,32 @@ class SkosmosApiProvider extends BaseProvider {
179
179
  if (!concept.type.length) {
180
180
  concept.type = ["http://www.w3.org/2004/02/skos/core#Concept"];
181
181
  }
182
+ const map = {
183
+ "skos:definition": "definition",
184
+ "skos:note": "note",
185
+ "skos:scopeNote": "scopeNote",
186
+ "skos:example": "example",
187
+ "skos:historyNote": "historyNote",
188
+ "skos:editorialNote": "editorialNote",
189
+ "skos:changeNote": "changeNote"
190
+ };
191
+ for (let key in map) {
192
+ if (skosmosConcept[key]) {
193
+ const value = skosmosConcept[key];
194
+ if (value.lang && value.value) {
195
+ concept[map[key]] = {
196
+ [value.lang]: value.value
197
+ };
198
+ } else if (Array.isArray(value)) {
199
+ concept[map[key]] = {};
200
+ for (let val of value) {
201
+ if (val.lang && val.value) {
202
+ concept[map[key]][val.lang] = val.value;
203
+ }
204
+ }
205
+ }
206
+ }
207
+ }
182
208
  return concept;
183
209
  }
184
210
  /**
@@ -258,20 +284,20 @@ class SkosmosApiProvider extends BaseProvider {
258
284
  concepts = concepts.map((c) => ({ uri: c.uri, inScheme: c.inScheme }));
259
285
  const newConcepts = [];
260
286
  for (let concept of concepts) {
261
- const url = this._getDataUrl(concept, { addFormatParameter: false });
287
+ if (!concept || !concept.uri) {
288
+ throw new errors.InvalidOrMissingParameterError({ parameter: "concept", message: "Missing concept URI" });
289
+ }
290
+ const params = { uri: concept.uri, format: "application/json" };
291
+ const url = this._getApiUrl(concept?.inScheme?.[0], "/data", params);
262
292
  if (!url) {
263
293
  continue;
264
294
  }
265
295
  const result = await this.axios({
266
296
  ...config,
267
297
  method: "get",
268
- url,
269
- params: {
270
- uri: concept.uri,
271
- format: "application/json"
272
- }
298
+ url
273
299
  });
274
- const resultConcept = result && result.graph && result.graph.find((c) => jskos.compare(c, concept));
300
+ const resultConcept = result?.graph?.find((c) => jskos.compare(c, concept));
275
301
  if (resultConcept) {
276
302
  const newConcept = this._toJskosConcept(resultConcept, { concept, result });
277
303
  for (let type of ["broader", "narrower"]) {
@@ -385,7 +411,7 @@ class SkosmosApiProvider extends BaseProvider {
385
411
  method: "get",
386
412
  url
387
413
  });
388
- for (let type of response && response.types || []) {
414
+ for (let type of response?.types || []) {
389
415
  if (type.uri == "http://www.w3.org/2004/02/skos/core#Concept") {
390
416
  continue;
391
417
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cocoda-sdk",
3
- "version": "3.6.1",
3
+ "version": "3.6.2",
4
4
  "description": "SDK for Cocoda",
5
5
  "main": "dist/cjs/index.cjs",
6
6
  "module": "dist/esm/index.js",