cocoda-sdk 3.2.3 → 3.3.1

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.
@@ -32,13 +32,15 @@ __export(src_exports, {
32
32
  LocApiProvider: () => LocApiProvider,
33
33
  LocalMappingsProvider: () => LocalMappingsProvider,
34
34
  MappingsApiProvider: () => MappingsApiProvider,
35
+ MyCoReProvider: () => MyCoReProvider,
35
36
  OccurrencesApiProvider: () => OccurrencesApiProvider,
36
37
  ReconciliationApiProvider: () => ReconciliationApiProvider,
37
38
  SkohubProvider: () => SkohubProvider,
38
39
  SkosmosApiProvider: () => SkosmosApiProvider,
39
40
  addAllProviders: () => addAllProviders,
40
41
  cdk: () => cdk,
41
- errors: () => errors_exports
42
+ errors: () => errors_exports,
43
+ utils: () => utils_exports
42
44
  });
43
45
  module.exports = __toCommonJS(src_exports);
44
46
 
@@ -112,7 +114,7 @@ var import_omit = __toESM(require("lodash/omit.js"), 1);
112
114
  var import_concat = __toESM(require("lodash/concat.js"), 1);
113
115
 
114
116
  // src/lib/CocodaSDK.js
115
- var import_jskos_tools11 = __toESM(require("jskos-tools"), 1);
117
+ var import_jskos_tools12 = __toESM(require("jskos-tools"), 1);
116
118
 
117
119
  // src/providers/index.js
118
120
  var providers_exports = {};
@@ -123,6 +125,7 @@ __export(providers_exports, {
123
125
  LocApiProvider: () => LocApiProvider,
124
126
  LocalMappingsProvider: () => LocalMappingsProvider,
125
127
  MappingsApiProvider: () => MappingsApiProvider,
128
+ MyCoReProvider: () => MyCoReProvider,
126
129
  OccurrencesApiProvider: () => OccurrencesApiProvider,
127
130
  ReconciliationApiProvider: () => ReconciliationApiProvider,
128
131
  SkohubProvider: () => SkohubProvider,
@@ -134,6 +137,13 @@ var import_jskos_tools = __toESM(require("jskos-tools"), 1);
134
137
  var import_axios = __toESM(require("axios"), 1);
135
138
 
136
139
  // src/utils/index.js
140
+ var utils_exports = {};
141
+ __export(utils_exports, {
142
+ concatUrl: () => concatUrl,
143
+ listOfCapabilities: () => listOfCapabilities,
144
+ requestMethods: () => requestMethods,
145
+ withCustomProps: () => withCustomProps
146
+ });
137
147
  var requestMethods = [
138
148
  {
139
149
  method: "getRegistries",
@@ -347,8 +357,8 @@ var BaseProvider = class {
347
357
  }
348
358
  return config;
349
359
  });
350
- this.axios.interceptors.response.use(({ data, headers = {}, config = {} }) => {
351
- data = import_jskos_tools.default.normalize(data);
360
+ this.axios.interceptors.response.use(({ data: data3, headers = {}, config = {} }) => {
361
+ data3 = import_jskos_tools.default.normalize(data3);
352
362
  let url = config.url;
353
363
  if (!url.endsWith("?")) {
354
364
  url += "?";
@@ -356,14 +366,14 @@ var BaseProvider = class {
356
366
  import_forOwn.default(config.params || {}, (value, key) => {
357
367
  url += `${key}=${encodeURIComponent(value)}&`;
358
368
  });
359
- if (import_isArray.default(data) || import_isObject.default(data)) {
369
+ if (import_isArray.default(data3) || import_isObject.default(data3)) {
360
370
  let totalCount = parseInt(headers["x-total-count"]);
361
371
  if (!isNaN(totalCount)) {
362
- data._totalCount = totalCount;
372
+ data3._totalCount = totalCount;
363
373
  }
364
- data._url = url;
374
+ data3._url = url;
365
375
  }
366
- return data;
376
+ return data3;
367
377
  }, (error) => {
368
378
  const count = import_get.default(error, "config._retryCount", 0);
369
379
  const method = import_get.default(error, "config.method");
@@ -592,7 +602,7 @@ var BaseProvider = class {
592
602
  return (await this.getConcepts({ ...config, concepts: [concept] }))[0];
593
603
  };
594
604
  for (let type of ["broader", "narrower", "ancestors"]) {
595
- if (Array.isArray(concept[type]) && !concept[type].includes(null)) {
605
+ if (Array.isArray(concept[type]) && concept[type].length && !concept[type].includes(null)) {
596
606
  concept[type] = this.adjustConcepts(concept[type]);
597
607
  }
598
608
  }
@@ -1391,9 +1401,13 @@ MappingsApiProvider.stored = true;
1391
1401
 
1392
1402
  // src/providers/occurrences-api-provider.js
1393
1403
  var import_jskos_tools4 = __toESM(require("jskos-tools"), 1);
1404
+ var cache = {};
1394
1405
  var OccurrencesApiProvider = class extends BaseProvider {
1406
+ get _cache() {
1407
+ return cache[this.uri];
1408
+ }
1395
1409
  _prepare() {
1396
- this._cache = [];
1410
+ cache[this.uri] = [];
1397
1411
  this._occurrencesSupportedSchemes = [];
1398
1412
  this.has.occurrences = true;
1399
1413
  this.has.mappings = true;
@@ -1406,11 +1420,11 @@ var OccurrencesApiProvider = class extends BaseProvider {
1406
1420
  } else {
1407
1421
  try {
1408
1422
  const url = concatUrl(this._api.api, "voc");
1409
- const data = await this.axios({
1423
+ const data3 = await this.axios({
1410
1424
  method: "get",
1411
1425
  url
1412
1426
  });
1413
- this._occurrencesSupportedSchemes = data || [];
1427
+ this._occurrencesSupportedSchemes = data3 || [];
1414
1428
  } catch (error) {
1415
1429
  }
1416
1430
  }
@@ -1524,19 +1538,19 @@ var OccurrencesApiProvider = class extends BaseProvider {
1524
1538
  if (resultsFromCache) {
1525
1539
  return resultsFromCache.data;
1526
1540
  }
1527
- const data = await this.axios({
1541
+ const data3 = await this.axios({
1528
1542
  ...config,
1529
1543
  method: "get",
1530
1544
  url: this._api.api
1531
1545
  });
1532
1546
  this._cache.push({
1533
1547
  config,
1534
- data
1548
+ data: data3
1535
1549
  });
1536
1550
  if (this._cache.length > 20) {
1537
- this._cache = this._cache.slice(this._cache.length - 20);
1551
+ cache[this.uri] = this._cache.slice(this._cache.length - 20);
1538
1552
  }
1539
- return data;
1553
+ return data3;
1540
1554
  }
1541
1555
  };
1542
1556
  OccurrencesApiProvider.providerName = "OccurrencesApi";
@@ -1746,34 +1760,34 @@ var ConceptApiProvider = class extends BaseProvider {
1746
1760
  }
1747
1761
  });
1748
1762
  }
1749
- async suggest({ use = "notation,label", types = [], sort = "score", ...config }) {
1763
+ async suggest({ use = "notation,label", types = [], sort = "score", params = {}, ...config }) {
1750
1764
  return this._search({
1751
1765
  ...config,
1752
1766
  endpoint: "suggest",
1753
1767
  params: {
1754
- ...config.params,
1768
+ ...params,
1755
1769
  type: types.join("|"),
1756
1770
  use,
1757
1771
  sort
1758
1772
  }
1759
1773
  });
1760
1774
  }
1761
- async search({ types = [], ...config }) {
1775
+ async search({ types = [], params = {}, ...config }) {
1762
1776
  return this._search({
1763
1777
  ...config,
1764
1778
  endpoint: "search",
1765
1779
  params: {
1766
- ...config.params,
1780
+ ...params,
1767
1781
  type: types.join("|")
1768
1782
  }
1769
1783
  });
1770
1784
  }
1771
- async vocSuggest({ use = "notation,label", sort = "score", ...config }) {
1785
+ async vocSuggest({ use = "notation,label", sort = "score", params = {}, ...config }) {
1772
1786
  return this._search({
1773
1787
  ...config,
1774
1788
  endpoint: "voc-suggest",
1775
1789
  params: {
1776
- ...config.params,
1790
+ ...params,
1777
1791
  use,
1778
1792
  sort
1779
1793
  }
@@ -1785,8 +1799,8 @@ var ConceptApiProvider = class extends BaseProvider {
1785
1799
  endpoint: "voc-search"
1786
1800
  });
1787
1801
  }
1788
- async _search({ endpoint, scheme, search, limit, offset, params, ...config }) {
1789
- let url = this._api[endpoint];
1802
+ async _search({ endpoint, scheme, search, limit, offset, params, url, ...config }) {
1803
+ url = url ?? this._api[endpoint];
1790
1804
  if (!url) {
1791
1805
  throw new MissingApiUrlError();
1792
1806
  }
@@ -1836,9 +1850,13 @@ ConceptApiProvider.providerType = "http://bartoc.org/api-type/jskos";
1836
1850
 
1837
1851
  // src/providers/reconciliation-api-provider.js
1838
1852
  var import_jskos_tools6 = __toESM(require("jskos-tools"), 1);
1853
+ var cache2 = {};
1839
1854
  var ReconciliationApiProvider = class extends BaseProvider {
1855
+ get _cache() {
1856
+ return cache2[this.uri];
1857
+ }
1840
1858
  _prepare() {
1841
- this._cache = [];
1859
+ cache2[this.uri] = [];
1842
1860
  this.has.mappings = true;
1843
1861
  listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
1844
1862
  this.has[c] = false;
@@ -1950,22 +1968,22 @@ var ReconciliationApiProvider = class extends BaseProvider {
1950
1968
  }
1951
1969
  const encodedData = `queries=${encodeURIComponent(JSON.stringify(queries))}`;
1952
1970
  import_set.default(config, ["headers", "Content-Type"], "application/x-www-form-urlencoded");
1953
- let data = await this.axios({
1971
+ let data3 = await this.axios({
1954
1972
  ...config,
1955
1973
  method: "post",
1956
1974
  url,
1957
1975
  data: encodedData
1958
1976
  });
1959
- data = data || {};
1977
+ data3 = data3 || {};
1960
1978
  let newCacheEntry = {
1961
1979
  labels,
1962
1980
  language,
1963
- data,
1981
+ data: data3,
1964
1982
  url: `${url}${url.includes("?") ? "&" : "?"}${encodedData}`
1965
1983
  };
1966
1984
  this._cache.push(newCacheEntry);
1967
1985
  if (this._cache.length > 20) {
1968
- this._cache = this._cache.slice(this._cache.length - 20);
1986
+ cache2[this.uri] = this._cache.slice(this._cache.length - 20);
1969
1987
  }
1970
1988
  return newCacheEntry;
1971
1989
  }
@@ -1984,7 +2002,7 @@ var LabelSearchSuggestionProvider = class extends BaseProvider {
1984
2002
  });
1985
2003
  }
1986
2004
  supportsScheme(scheme) {
1987
- return import_get.default(scheme, "_registry.has.search", false);
2005
+ return super.supportsScheme(scheme) && import_get.default(scheme, "_registry.has.search", false);
1988
2006
  }
1989
2007
  async getMappings({ from, to, mode, selected, limit = 10, ...config }) {
1990
2008
  if (mode != "or") {
@@ -2059,8 +2077,10 @@ var LabelSearchSuggestionProvider = class extends BaseProvider {
2059
2077
  if (!registry || registry.has.search === false) {
2060
2078
  return [];
2061
2079
  }
2062
- const data = await registry.search({
2080
+ let url = this._jskos.overrides.find((o) => import_jskos_tools7.default.compare(o, targetScheme))?.search;
2081
+ const data3 = await registry.search({
2063
2082
  ...config,
2083
+ url,
2064
2084
  search: label,
2065
2085
  scheme: targetScheme,
2066
2086
  limit
@@ -2068,9 +2088,9 @@ var LabelSearchSuggestionProvider = class extends BaseProvider {
2068
2088
  if (!this._cache[targetScheme.uri]) {
2069
2089
  this._cache[targetScheme.uri] = {};
2070
2090
  }
2071
- this._cache[targetScheme.uri][label] = data;
2091
+ this._cache[targetScheme.uri][label] = data3;
2072
2092
  this._cache[targetScheme.uri][label]._limit = limit;
2073
- return data;
2093
+ return data3;
2074
2094
  }
2075
2095
  };
2076
2096
  LabelSearchSuggestionProvider.providerName = "LabelSearchSuggestion";
@@ -2141,11 +2161,11 @@ var SkosmosApiProvider = class extends BaseProvider {
2141
2161
  return null;
2142
2162
  }
2143
2163
  const url = this._getApiUrl(scheme, "/");
2144
- const data = await this.axios({
2164
+ const data3 = await this.axios({
2145
2165
  method: "get",
2146
2166
  url
2147
2167
  });
2148
- const resultScheme = data.conceptschemes.find((s) => import_jskos_tools8.default.compare(s, scheme));
2168
+ const resultScheme = data3.conceptschemes.find((s) => import_jskos_tools8.default.compare(s, scheme));
2149
2169
  if (resultScheme) {
2150
2170
  this._approvedSchemes.push({
2151
2171
  uri: resultScheme.uri,
@@ -2236,12 +2256,12 @@ var SkosmosApiProvider = class extends BaseProvider {
2236
2256
  const schemes = [];
2237
2257
  for (let scheme of this.schemes || []) {
2238
2258
  const url = this._getApiUrl(scheme, "/");
2239
- const data = await this.axios({
2259
+ const data3 = await this.axios({
2240
2260
  ...config,
2241
2261
  method: "get",
2242
2262
  url
2243
2263
  });
2244
- const resultScheme = data.conceptschemes.find((s) => import_jskos_tools8.default.compare(s, scheme));
2264
+ const resultScheme = data3.conceptschemes.find((s) => import_jskos_tools8.default.compare(s, scheme));
2245
2265
  const label = resultScheme && (resultScheme.prefLabel || resultScheme.label || resultScheme.title);
2246
2266
  if (label) {
2247
2267
  import_set.default(scheme, `prefLabel.${this._language}`, label);
@@ -2442,28 +2462,28 @@ var supportedSchemes = [
2442
2462
  }
2443
2463
  ];
2444
2464
  var lccUri = `${locUriPrefix}classification`;
2445
- function madsToJskosItem(data) {
2465
+ function madsToJskosItem(data3) {
2446
2466
  const item = {};
2447
- item.uri = data["@id"];
2448
- item.notation = (data["http://www.loc.gov/mads/rdf/v1#code"] || []).map((n) => n["@value"]);
2449
- const prefLabelArray = data["http://www.loc.gov/mads/rdf/v1#authoritativeLabel"] || data["http://www.w3.org/2000/01/rdf-schema#label"] || [];
2467
+ item.uri = data3["@id"];
2468
+ item.notation = (data3["http://www.loc.gov/mads/rdf/v1#code"] || []).map((n) => n["@value"]);
2469
+ const prefLabelArray = data3["http://www.loc.gov/mads/rdf/v1#authoritativeLabel"] || data3["http://www.w3.org/2000/01/rdf-schema#label"] || [];
2450
2470
  if (prefLabelArray.length) {
2451
2471
  item.prefLabel = {};
2452
2472
  item.prefLabel[prefLabelArray[0]["@language"] || "en"] = prefLabelArray[0]["@value"];
2453
2473
  }
2454
- const altLabelArray = data["http://www.w3.org/2004/02/skos/core#altLabel"] || [];
2474
+ const altLabelArray = data3["http://www.w3.org/2004/02/skos/core#altLabel"] || [];
2455
2475
  if (altLabelArray.length) {
2456
2476
  item.altLabel = { en: altLabelArray.map((l) => l["@value"]) };
2457
2477
  }
2458
- for (let definition of data["http://www.w3.org/2000/01/rdf-schema#comment"] || []) {
2478
+ for (let definition of data3["http://www.w3.org/2000/01/rdf-schema#comment"] || []) {
2459
2479
  item.definition = item.definition || {};
2460
2480
  item.definition.en = item.definition.en || [];
2461
2481
  item.definition.en.push(definition["@value"]);
2462
2482
  }
2463
2483
  return item;
2464
2484
  }
2465
- function madsToJskosScheme(data) {
2466
- const scheme = madsToJskosItem(data);
2485
+ function madsToJskosScheme(data3) {
2486
+ const scheme = madsToJskosItem(data3);
2467
2487
  scheme.namespace = scheme.uri + "/";
2468
2488
  scheme.type = ["http://www.w3.org/2004/02/skos/core#ConceptScheme"];
2469
2489
  return scheme;
@@ -2474,16 +2494,16 @@ var schemeNamespaceFilter = (scheme) => (c) => {
2474
2494
  }
2475
2495
  return c.uri.startsWith(scheme.namespace);
2476
2496
  };
2477
- function madsToJskosConcept(data, { scheme }) {
2478
- const concept = madsToJskosItem(data);
2497
+ function madsToJskosConcept(data3, { scheme }) {
2498
+ const concept = madsToJskosItem(data3);
2479
2499
  concept.type = ["http://www.w3.org/2004/02/skos/core#Concept"];
2480
- concept.inScheme = scheme ? [scheme] : (data["http://www.loc.gov/mads/rdf/v1#isMemberOfMADSScheme"] || []).map((s) => supportedSchemes.find((s2) => s2.uri === s["@id"]));
2500
+ concept.inScheme = scheme ? [scheme] : (data3["http://www.loc.gov/mads/rdf/v1#isMemberOfMADSScheme"] || []).map((s) => supportedSchemes.find((s2) => s2.uri === s["@id"]));
2481
2501
  if (!concept.inScheme.length || !concept.inScheme[0]) {
2482
2502
  delete concept.inScheme;
2483
2503
  }
2484
- const narrower = data["http://www.loc.gov/mads/rdf/v1#hasNarrowerAuthority"] || import_jskos_tools9.default.compare(concept.inScheme[0], { uri: lccUri }) && data["http://www.loc.gov/mads/rdf/v1#hasMADSCollectionMember"] || [];
2504
+ const narrower = data3["http://www.loc.gov/mads/rdf/v1#hasNarrowerAuthority"] || import_jskos_tools9.default.compare(concept.inScheme[0], { uri: lccUri }) && data3["http://www.loc.gov/mads/rdf/v1#hasMADSCollectionMember"] || [];
2485
2505
  concept.narrower = narrower.map((n) => ({ uri: n["@id"] })).filter(schemeNamespaceFilter(concept.inScheme && concept.inScheme[0]));
2486
- const broader = data["http://www.loc.gov/mads/rdf/v1#hasBroaderAuthority"] || import_jskos_tools9.default.compare(concept.inScheme[0], { uri: lccUri }) && data["http://www.loc.gov/mads/rdf/v1#isMemberOfMADSCollection"] || [];
2506
+ const broader = data3["http://www.loc.gov/mads/rdf/v1#hasBroaderAuthority"] || import_jskos_tools9.default.compare(concept.inScheme[0], { uri: lccUri }) && data3["http://www.loc.gov/mads/rdf/v1#isMemberOfMADSCollection"] || [];
2487
2507
  concept.broader = broader.map((n) => ({ uri: n["@id"] })).filter(schemeNamespaceFilter(concept.inScheme && concept.inScheme[0]));
2488
2508
  return concept;
2489
2509
  }
@@ -2515,9 +2535,9 @@ var LocApiProvider = class extends BaseProvider {
2515
2535
  supportedSchemes.filter((s) => !this.schemes || !this.schemes.length || this.schemes.find((s2) => import_jskos_tools9.default.compare(s, s2))).map((s) => (0, import_axios2.default)({
2516
2536
  method: "get",
2517
2537
  url: `${s.uri.replace("http:", "https:")}.json`
2518
- }).then(({ status, data }) => {
2538
+ }).then(({ status, data: data3 }) => {
2519
2539
  if (status === 200) {
2520
- let scheme2 = data.find((d) => s.uri === d["@id"]);
2540
+ let scheme2 = data3.find((d) => s.uri === d["@id"]);
2521
2541
  if (scheme2) {
2522
2542
  scheme2 = import_jskos_tools9.default.merge(madsToJskosScheme(scheme2), s);
2523
2543
  scheme2.topConcepts = (scheme2.topConcepts || []).filter((c) => c);
@@ -2541,9 +2561,9 @@ var LocApiProvider = class extends BaseProvider {
2541
2561
  for (let concept of await Promise.all(concepts.map((c) => (0, import_axios2.default)({
2542
2562
  method: "get",
2543
2563
  url: `${c.uri.replace("http:", "https:")}.json`
2544
- }).then(({ status, data }) => {
2564
+ }).then(({ status, data: data3 }) => {
2545
2565
  if (status === 200) {
2546
- let concept2 = data.find((d) => c.uri === d["@id"]);
2566
+ let concept2 = data3.find((d) => c.uri === d["@id"]);
2547
2567
  if (concept2) {
2548
2568
  return madsToJskosConcept(concept2, { scheme: c.inScheme && c.inScheme[0] });
2549
2569
  }
@@ -2577,7 +2597,7 @@ var LocApiProvider = class extends BaseProvider {
2577
2597
  }
2578
2598
  limit = limit || this._jskos.suggestResultLimit || 100;
2579
2599
  offset = offset || 0;
2580
- const { data } = await (0, import_axios2.default)({
2600
+ const { data: data3 } = await (0, import_axios2.default)({
2581
2601
  method: "get",
2582
2602
  url: `${schemeUri}/suggest2`.replace("http:", "https:"),
2583
2603
  params: {
@@ -2587,7 +2607,7 @@ var LocApiProvider = class extends BaseProvider {
2587
2607
  searchtype: "keyword"
2588
2608
  }
2589
2609
  });
2590
- return (data.hits || []).map((d) => ({
2610
+ return (data3.hits || []).map((d) => ({
2591
2611
  uri: d.uri,
2592
2612
  notation: [d.token],
2593
2613
  prefLabel: { en: d.aLabel },
@@ -2609,6 +2629,7 @@ function decodeUnicode(text) {
2609
2629
  }
2610
2630
  );
2611
2631
  }
2632
+ var data = {};
2612
2633
  var SkohubProvider = class extends BaseProvider {
2613
2634
  _prepare() {
2614
2635
  this.has.schemes = true;
@@ -2622,11 +2643,20 @@ var SkohubProvider = class extends BaseProvider {
2622
2643
  listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
2623
2644
  this.has[c] = false;
2624
2645
  });
2646
+ data[this.uri] = {
2647
+ index: {},
2648
+ conceptCache: {},
2649
+ schemeCache: {}
2650
+ };
2625
2651
  }
2626
- _setup() {
2627
- this._index = {};
2628
- this._conceptCache = {};
2629
- this._schemeCache = {};
2652
+ get _index() {
2653
+ return data[this.uri] && data[this.uri].index;
2654
+ }
2655
+ get _conceptCache() {
2656
+ return data[this.uri] && data[this.uri].conceptCache;
2657
+ }
2658
+ get _schemeCache() {
2659
+ return data[this.uri] && data[this.uri].schemeCache;
2630
2660
  }
2631
2661
  static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
2632
2662
  if (!url || !scheme) {
@@ -2652,11 +2682,11 @@ var SkohubProvider = class extends BaseProvider {
2652
2682
  if (uri.endsWith("/")) {
2653
2683
  postfix = "index.json";
2654
2684
  }
2655
- const data = await this.axios({ ...config, url: `${uri}${postfix}`, _skipAdditionalParameters: true });
2656
- if (data.id !== uri) {
2685
+ const data3 = await this.axios({ ...config, url: `${uri}${postfix}`, _skipAdditionalParameters: true });
2686
+ if (data3.id !== uri) {
2657
2687
  throw new InvalidRequestError({ message: "Skohub URL did not return expected concept scheme" });
2658
2688
  }
2659
- const { title, preferredNamespaceUri, hasTopConcept, description } = data;
2689
+ const { title, preferredNamespaceUri, hasTopConcept, description } = data3;
2660
2690
  scheme = { uri, identifier: uris.filter((u) => u !== uri) };
2661
2691
  scheme.prefLabel = title;
2662
2692
  Object.keys(scheme.prefLabel || {}).forEach((key) => {
@@ -2684,33 +2714,33 @@ var SkohubProvider = class extends BaseProvider {
2684
2714
  return this._conceptCache[uri];
2685
2715
  }
2686
2716
  try {
2687
- const data = await this.axios({ ...config, url: `${uri}.json`, _skipAdditionalParameters: true });
2688
- if (data.id !== uri) {
2717
+ const data3 = await this.axios({ ...config, url: `${uri}.json`, _skipAdditionalParameters: true });
2718
+ if (data3.id !== uri) {
2689
2719
  throw new InvalidRequestError({ message: "Skohub URL did not return expected concept URI" });
2690
2720
  }
2691
- const concept = this._toJskosConcept(data);
2721
+ const concept = this._toJskosConcept(data3);
2692
2722
  this._conceptCache[uri] = concept;
2693
2723
  return concept;
2694
2724
  } catch (error) {
2695
2725
  return null;
2696
2726
  }
2697
2727
  }
2698
- _toJskosConcept(data) {
2699
- const concept = { uri: data.id };
2700
- concept.prefLabel = data.prefLabel;
2728
+ _toJskosConcept(data3) {
2729
+ const concept = { uri: data3.id };
2730
+ concept.prefLabel = data3.prefLabel;
2701
2731
  Object.keys(concept.prefLabel || {}).forEach((key) => {
2702
2732
  concept.prefLabel[key] = decodeUnicode(concept.prefLabel[key]);
2703
2733
  });
2704
- concept.narrower = (data.narrower || []).map((c) => this._toJskosConcept(c));
2705
- concept.notation = data.notation || [];
2706
- if (data.broader && data.broader.id) {
2707
- concept.broader = [{ uri: data.broader.id }];
2734
+ concept.narrower = (data3.narrower || []).map((c) => this._toJskosConcept(c));
2735
+ concept.notation = data3.notation || [];
2736
+ if (data3.broader && data3.broader.id) {
2737
+ concept.broader = [{ uri: data3.broader.id }];
2708
2738
  }
2709
- if (data.inScheme && data.inScheme.id) {
2710
- concept.inScheme = [{ uri: data.inScheme.id }];
2739
+ if (data3.inScheme && data3.inScheme.id) {
2740
+ concept.inScheme = [{ uri: data3.inScheme.id }];
2711
2741
  }
2712
- if (data.scopeNote) {
2713
- concept.scopeNote = data.scopeNote;
2742
+ if (data3.scopeNote) {
2743
+ concept.scopeNote = data3.scopeNote;
2714
2744
  Object.keys(concept.scopeNote).forEach((key) => {
2715
2745
  concept.scopeNote[key] = [decodeUnicode(concept.scopeNote[key])];
2716
2746
  });
@@ -2782,13 +2812,13 @@ var SkohubProvider = class extends BaseProvider {
2782
2812
  if (scheme.uri.endsWith("/")) {
2783
2813
  postfix = `index${postfix}`;
2784
2814
  }
2785
- const data = await this.axios({ url: `${scheme.uri}${postfix}`, _skipAdditionalParameters: true });
2786
- if (data.length < 100) {
2815
+ const data3 = await this.axios({ url: `${scheme.uri}${postfix}`, _skipAdditionalParameters: true });
2816
+ if (data3.length < 100) {
2787
2817
  this._index[scheme.uri][lang] = null;
2788
2818
  continue;
2789
2819
  }
2790
2820
  index = import_flexsearch.default.create();
2791
- index.import(data);
2821
+ index.import(data3);
2792
2822
  this._index[scheme.uri][lang] = index;
2793
2823
  break;
2794
2824
  } catch (error) {
@@ -2824,6 +2854,217 @@ var SkohubProvider = class extends BaseProvider {
2824
2854
  SkohubProvider.providerName = "Skohub";
2825
2855
  SkohubProvider.providerType = "http://bartoc.org/api-type/skohub";
2826
2856
 
2857
+ // src/providers/mycore-provider.js
2858
+ var import_jskos_tools11 = __toESM(require("jskos-tools"), 1);
2859
+ var import_flexsearch2 = __toESM(require("flexsearch"), 1);
2860
+ var data2 = {};
2861
+ var MyCoReProvider = class extends BaseProvider {
2862
+ _prepare() {
2863
+ this.has.schemes = true;
2864
+ this.has.top = true;
2865
+ this.has.data = true;
2866
+ this.has.concepts = true;
2867
+ this.has.narrower = true;
2868
+ this.has.ancestors = true;
2869
+ this.has.suggest = true;
2870
+ this.has.search = true;
2871
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
2872
+ this.has[c] = false;
2873
+ });
2874
+ }
2875
+ _setup() {
2876
+ this._scheme = null;
2877
+ }
2878
+ static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
2879
+ if (!url || !scheme) {
2880
+ return null;
2881
+ }
2882
+ return {
2883
+ api: url
2884
+ };
2885
+ }
2886
+ _schemeInfoToJSKOS(schemeInfo) {
2887
+ const uri = schemeInfo.labels.find((l) => l.lang === "x-uri").text;
2888
+ const prefLabel = {};
2889
+ schemeInfo.labels.filter((l) => !l.lang.startsWith("x-")).forEach((l) => {
2890
+ prefLabel[l.lang] = l.text;
2891
+ });
2892
+ const scheme = {
2893
+ uri,
2894
+ prefLabel
2895
+ };
2896
+ if (schemeInfo.categories && schemeInfo.categories.length) {
2897
+ scheme.topConcepts = [null];
2898
+ }
2899
+ if (schemeInfo.category && schemeInfo.category.length) {
2900
+ scheme.concepts = [null];
2901
+ }
2902
+ return scheme;
2903
+ }
2904
+ _categoryToJSKOS(category, { scheme, broader = [] }) {
2905
+ if (!category || !scheme) {
2906
+ return null;
2907
+ }
2908
+ const id = category.ID;
2909
+ const uri = `${scheme.uri}/${id}`;
2910
+ if (data2[scheme.uri].concepts[uri]) {
2911
+ return data2[scheme.uri].concepts[uri];
2912
+ }
2913
+ const prefLabel = {};
2914
+ category.labels.filter((l) => !l.lang.startsWith("x-") && l.text).forEach((l) => {
2915
+ prefLabel[l.lang] = l.text.replace(`${id} `, "");
2916
+ data2[scheme.uri].searchIndex.add(uri, prefLabel[l.lang]);
2917
+ });
2918
+ const scopeNote = {};
2919
+ category.labels.filter((l) => !l.lang.startsWith("x-") && l.description).forEach((l) => {
2920
+ if (!scopeNote[l.lang]) {
2921
+ scopeNote[l.lang] = [];
2922
+ }
2923
+ scopeNote[l.lang].push(l.description);
2924
+ });
2925
+ data2[scheme.uri].concepts[uri] = {
2926
+ uri,
2927
+ notation: [id],
2928
+ prefLabel,
2929
+ scopeNote,
2930
+ inScheme: [{ uri: scheme.uri }],
2931
+ narrower: (category.categories || []).map((c) => ({ uri: `${scheme.uri}/${c.ID}` })),
2932
+ broader
2933
+ };
2934
+ return data2[scheme.uri].concepts[uri];
2935
+ }
2936
+ _removeNarrower(concept) {
2937
+ if (!concept)
2938
+ return concept;
2939
+ return Object.assign({}, concept, { narrower: concept.narrower && concept.narrower.length ? [null] : [] });
2940
+ }
2941
+ async _loadSchemeData(config) {
2942
+ const schemeInfo = await this.axios({
2943
+ ...config,
2944
+ method: "get",
2945
+ url: this._api.api,
2946
+ _skipAdditionalParameters: true
2947
+ });
2948
+ this._scheme = this._schemeInfoToJSKOS(schemeInfo);
2949
+ const uri = this._scheme.uri;
2950
+ data2[uri] = {
2951
+ schemeInfo,
2952
+ searchIndex: import_flexsearch2.default.create({
2953
+ tokenize: "full"
2954
+ }),
2955
+ concepts: {}
2956
+ };
2957
+ const dealWithCategory = (category, { broader = [] } = {}) => {
2958
+ const concept = this._categoryToJSKOS(category, { scheme: this._scheme, broader });
2959
+ (category.categories || []).forEach((c) => dealWithCategory(c, { broader: [{ uri: concept.uri }] }));
2960
+ };
2961
+ schemeInfo.categories.forEach((category) => dealWithCategory(category));
2962
+ data2[uri].topConcepts = schemeInfo.categories.map((category) => this._categoryToJSKOS(category, { scheme: this._scheme }));
2963
+ }
2964
+ async getSchemes(config = {}) {
2965
+ if (!this._api.api) {
2966
+ throw new MissingApiUrlError();
2967
+ }
2968
+ if (!this._scheme) {
2969
+ if (!this._loadSchemeDataPromise) {
2970
+ this._loadSchemeDataPromise = this._loadSchemeData(config);
2971
+ }
2972
+ await this._loadSchemeDataPromise;
2973
+ }
2974
+ return [this._scheme];
2975
+ }
2976
+ async getTop({ scheme, ...config }) {
2977
+ if (!scheme || !scheme.uri) {
2978
+ throw new InvalidOrMissingParameterError({ parameter: "scheme", message: "Missing scheme URI" });
2979
+ }
2980
+ if (!this._scheme) {
2981
+ await this.getSchemes(config);
2982
+ }
2983
+ if (!import_jskos_tools11.default.compare(scheme, this._scheme)) {
2984
+ throw new InvalidOrMissingParameterError({ parameter: "scheme", message: "Requested vocabulary seems to be unsupported by this API." });
2985
+ }
2986
+ return data2[this._scheme.uri].topConcepts.map(this._removeNarrower);
2987
+ }
2988
+ async getConcepts({ concepts, ...config }) {
2989
+ if (!import_isArray.default(concepts)) {
2990
+ concepts = [concepts];
2991
+ }
2992
+ if (!this._scheme) {
2993
+ await this.getSchemes(config);
2994
+ }
2995
+ return concepts.map((c) => data2[this._scheme.uri].concepts[c.uri]).map(this._removeNarrower);
2996
+ }
2997
+ async getAncestors({ concept, ...config }) {
2998
+ if (!concept || !concept.uri) {
2999
+ throw new InvalidOrMissingParameterError({ parameter: "concept" });
3000
+ }
3001
+ if (concept.ancestors && concept.ancestors[0] !== null) {
3002
+ return concept.ancestors;
3003
+ }
3004
+ if (!this._scheme) {
3005
+ await this.getSchemes(config);
3006
+ }
3007
+ concept = data2[this._scheme.uri].concepts[concept.uri];
3008
+ const broader = concept && concept.broader && concept.broader[0];
3009
+ if (!broader) {
3010
+ return [];
3011
+ }
3012
+ return [broader].concat(await this.getAncestors({ concept: broader, ...config }));
3013
+ }
3014
+ async getNarrower({ concept, ...config }) {
3015
+ if (!concept || !concept.uri) {
3016
+ throw new InvalidOrMissingParameterError({ parameter: "concept" });
3017
+ }
3018
+ if (concept.narrower && concept.narrower[0] !== null) {
3019
+ return concept.narrower;
3020
+ }
3021
+ if (!this._scheme) {
3022
+ await this.getSchemes(config);
3023
+ }
3024
+ concept = data2[this._scheme.uri].concepts[concept.uri];
3025
+ return (concept && concept.narrower || []).map((c) => data2[this._scheme.uri].concepts[c.uri]).map(this._removeNarrower);
3026
+ }
3027
+ async search({ search, scheme, limit = 100 }) {
3028
+ if (!scheme || !scheme.uri) {
3029
+ throw new InvalidOrMissingParameterError({ parameter: "scheme" });
3030
+ }
3031
+ if (!search) {
3032
+ throw new InvalidOrMissingParameterError({ parameter: "search" });
3033
+ }
3034
+ if (!scheme || !scheme.uri) {
3035
+ throw new InvalidOrMissingParameterError({ parameter: "scheme", message: "Missing scheme URI" });
3036
+ }
3037
+ if (!this._scheme) {
3038
+ await this.getSchemes();
3039
+ }
3040
+ if (!import_jskos_tools11.default.compare(scheme, this._scheme)) {
3041
+ throw new InvalidOrMissingParameterError({ parameter: "scheme", message: "Requested vocabulary seems to be unsupported by this API." });
3042
+ }
3043
+ const result = await data2[this._scheme.uri].searchIndex.search(search);
3044
+ return result.map((uri) => data2[this._scheme.uri].concepts[uri]).map(this._removeNarrower).slice(0, limit);
3045
+ }
3046
+ async suggest(config) {
3047
+ config._raw = true;
3048
+ const concepts = await this.search(config);
3049
+ const result = [config.search, [], [], []];
3050
+ for (let concept of concepts) {
3051
+ const notation = import_jskos_tools11.default.notation(concept);
3052
+ const label = import_jskos_tools11.default.prefLabel(concept);
3053
+ result[1].push((notation ? notation + " " : "") + label);
3054
+ result[2].push("");
3055
+ result[3].push(concept.uri);
3056
+ }
3057
+ if (concepts._totalCount != void 0) {
3058
+ result._totalCount = concepts._totalCount;
3059
+ } else {
3060
+ result._totalCount = concepts.length;
3061
+ }
3062
+ return result;
3063
+ }
3064
+ };
3065
+ MyCoReProvider.providerName = "MyCoRe";
3066
+ MyCoReProvider.providerType = "http://bartoc.org/api-type/mycore";
3067
+
2827
3068
  // src/lib/CocodaSDK.js
2828
3069
  var providers = {
2829
3070
  [BaseProvider.providerName]: BaseProvider,
@@ -3009,7 +3250,7 @@ var CocodaSDK = class {
3009
3250
  scheme._registry = registry;
3010
3251
  scheme.__DETAILSLOADED__ = 1;
3011
3252
  scheme.type = scheme.type || ["http://www.w3.org/2004/02/skos/core#ConceptScheme"];
3012
- let otherScheme = schemes.find((s) => import_jskos_tools11.default.compare(s, scheme)), prio, otherPrio, override = false;
3253
+ let otherScheme = schemes.find((s) => import_jskos_tools12.default.compare(s, scheme)), prio, otherPrio, override = false;
3013
3254
  if (otherScheme) {
3014
3255
  prio = this.config.registries.indexOf(registry);
3015
3256
  if (prio != -1) {
@@ -3031,19 +3272,19 @@ var CocodaSDK = class {
3031
3272
  }
3032
3273
  if (!otherScheme || override) {
3033
3274
  if (override) {
3034
- let otherSchemeIndex = schemes.findIndex((s) => import_jskos_tools11.default.compare(s, otherScheme));
3275
+ let otherSchemeIndex = schemes.findIndex((s) => import_jskos_tools12.default.compare(s, otherScheme));
3035
3276
  if (otherSchemeIndex != -1) {
3036
3277
  schemes.splice(otherSchemeIndex, 1);
3037
3278
  }
3038
- scheme = import_jskos_tools11.default.merge(scheme, import_omit.default(otherScheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
3279
+ scheme = import_jskos_tools12.default.merge(scheme, import_omit.default(otherScheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
3039
3280
  }
3040
3281
  scheme._registry = registry;
3041
3282
  schemes.push(scheme);
3042
3283
  } else {
3043
- const index = schemes.findIndex((s) => import_jskos_tools11.default.compare(s, scheme));
3284
+ const index = schemes.findIndex((s) => import_jskos_tools12.default.compare(s, scheme));
3044
3285
  if (index != -1) {
3045
3286
  const otherSchemeRegistry = schemes[index]._registry;
3046
- schemes[index] = import_jskos_tools11.default.merge(schemes[index], import_omit.default(scheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
3287
+ schemes[index] = import_jskos_tools12.default.merge(schemes[index], import_omit.default(scheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
3047
3288
  schemes[index]._registry = otherSchemeRegistry;
3048
3289
  }
3049
3290
  }
@@ -3065,7 +3306,7 @@ var CocodaSDK = class {
3065
3306
  scheme._registry = newRegistry;
3066
3307
  }
3067
3308
  });
3068
- return import_jskos_tools11.default.sortSchemes(schemes.filter(Boolean));
3309
+ return import_jskos_tools12.default.sortSchemes(schemes.filter(Boolean));
3069
3310
  }
3070
3311
  registryForScheme(scheme) {
3071
3312
  let registry = scheme._registry;
@@ -3076,7 +3317,7 @@ var CocodaSDK = class {
3076
3317
  const url = config.url;
3077
3318
  if (registryCache[url]) {
3078
3319
  const registry2 = registryCache[url];
3079
- if (Array.isArray(registry2._jskos.schemes) && !import_jskos_tools11.default.isContainedIn(scheme, registry2._jskos.schemes)) {
3320
+ if (Array.isArray(registry2._jskos.schemes) && !import_jskos_tools12.default.isContainedIn(scheme, registry2._jskos.schemes)) {
3080
3321
  registry2._jskos.schemes.push(scheme);
3081
3322
  }
3082
3323
  return registry2;
@@ -3121,11 +3362,13 @@ function addAllProviders(_cdk) {
3121
3362
  LocApiProvider,
3122
3363
  LocalMappingsProvider,
3123
3364
  MappingsApiProvider,
3365
+ MyCoReProvider,
3124
3366
  OccurrencesApiProvider,
3125
3367
  ReconciliationApiProvider,
3126
3368
  SkohubProvider,
3127
3369
  SkosmosApiProvider,
3128
3370
  addAllProviders,
3129
3371
  cdk,
3130
- errors
3372
+ errors,
3373
+ utils
3131
3374
  });