cocoda-sdk 3.2.2 → 3.3.0

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.
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/index.js
@@ -29,13 +32,15 @@ __export(src_exports, {
29
32
  LocApiProvider: () => LocApiProvider,
30
33
  LocalMappingsProvider: () => LocalMappingsProvider,
31
34
  MappingsApiProvider: () => MappingsApiProvider,
35
+ MyCoReProvider: () => MyCoReProvider,
32
36
  OccurrencesApiProvider: () => OccurrencesApiProvider,
33
37
  ReconciliationApiProvider: () => ReconciliationApiProvider,
34
38
  SkohubProvider: () => SkohubProvider,
35
39
  SkosmosApiProvider: () => SkosmosApiProvider,
36
40
  addAllProviders: () => addAllProviders,
37
41
  cdk: () => cdk,
38
- errors: () => errors_exports
42
+ errors: () => errors_exports,
43
+ utils: () => utils_exports
39
44
  });
40
45
  module.exports = __toCommonJS(src_exports);
41
46
 
@@ -109,7 +114,7 @@ var import_omit = __toESM(require("lodash/omit.js"), 1);
109
114
  var import_concat = __toESM(require("lodash/concat.js"), 1);
110
115
 
111
116
  // src/lib/CocodaSDK.js
112
- var import_jskos_tools11 = __toESM(require("jskos-tools"), 1);
117
+ var import_jskos_tools12 = __toESM(require("jskos-tools"), 1);
113
118
 
114
119
  // src/providers/index.js
115
120
  var providers_exports = {};
@@ -120,6 +125,7 @@ __export(providers_exports, {
120
125
  LocApiProvider: () => LocApiProvider,
121
126
  LocalMappingsProvider: () => LocalMappingsProvider,
122
127
  MappingsApiProvider: () => MappingsApiProvider,
128
+ MyCoReProvider: () => MyCoReProvider,
123
129
  OccurrencesApiProvider: () => OccurrencesApiProvider,
124
130
  ReconciliationApiProvider: () => ReconciliationApiProvider,
125
131
  SkohubProvider: () => SkohubProvider,
@@ -131,6 +137,13 @@ var import_jskos_tools = __toESM(require("jskos-tools"), 1);
131
137
  var import_axios = __toESM(require("axios"), 1);
132
138
 
133
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
+ });
134
147
  var requestMethods = [
135
148
  {
136
149
  method: "getRegistries",
@@ -344,8 +357,8 @@ var BaseProvider = class {
344
357
  }
345
358
  return config;
346
359
  });
347
- this.axios.interceptors.response.use(({ data, headers = {}, config = {} }) => {
348
- 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);
349
362
  let url = config.url;
350
363
  if (!url.endsWith("?")) {
351
364
  url += "?";
@@ -353,14 +366,14 @@ var BaseProvider = class {
353
366
  import_forOwn.default(config.params || {}, (value, key) => {
354
367
  url += `${key}=${encodeURIComponent(value)}&`;
355
368
  });
356
- if (import_isArray.default(data) || import_isObject.default(data)) {
369
+ if (import_isArray.default(data3) || import_isObject.default(data3)) {
357
370
  let totalCount = parseInt(headers["x-total-count"]);
358
371
  if (!isNaN(totalCount)) {
359
- data._totalCount = totalCount;
372
+ data3._totalCount = totalCount;
360
373
  }
361
- data._url = url;
374
+ data3._url = url;
362
375
  }
363
- return data;
376
+ return data3;
364
377
  }, (error) => {
365
378
  const count = import_get.default(error, "config._retryCount", 0);
366
379
  const method = import_get.default(error, "config.method");
@@ -548,9 +561,9 @@ var BaseProvider = class {
548
561
  if (options.auth && this._auth.key != import_get.default(this._config, "auth.key")) {
549
562
  return false;
550
563
  }
564
+ const userUris = [user.uri].concat(Object.values(user.identities || {}).map((id) => id.uri)).filter((uri) => uri != null);
551
565
  if (options.auth && options.identities) {
552
- const uris = [user.uri].concat(Object.values(user.identities || {}).map((id) => id.uri)).filter((uri) => uri != null);
553
- if (import_intersection.default(uris, options.identities).length == 0) {
566
+ if (import_intersection.default(userUris, options.identities).length == 0) {
554
567
  return false;
555
568
  }
556
569
  }
@@ -561,7 +574,7 @@ var BaseProvider = class {
561
574
  }
562
575
  }
563
576
  if (crossUser) {
564
- return !!options.crossUser;
577
+ return options.crossUser === true || import_intersection.default(options.crossUser || [], userUris).length > 0;
565
578
  }
566
579
  return !!this.has[type][action];
567
580
  }
@@ -589,7 +602,7 @@ var BaseProvider = class {
589
602
  return (await this.getConcepts({ ...config, concepts: [concept] }))[0];
590
603
  };
591
604
  for (let type of ["broader", "narrower", "ancestors"]) {
592
- if (Array.isArray(concept[type]) && !concept[type].includes(null)) {
605
+ if (Array.isArray(concept[type]) && concept[type].length && !concept[type].includes(null)) {
593
606
  concept[type] = this.adjustConcepts(concept[type]);
594
607
  }
595
608
  }
@@ -743,9 +756,11 @@ var LocalMappingsProvider = class extends BaseProvider {
743
756
  console.warn(`Warning: There is old data in local storage (or IndexedDB, depending on the ) with the key "${oldLocalStorageKey}". This data will not be used anymore. A manual export is necessary to get this data back.`);
744
757
  }
745
758
  });
746
- this.queue.push(addUris().catch((error) => {
747
- console.warn("Error when adding URIs to local mappings:", error);
748
- }));
759
+ this.queue.push(
760
+ addUris().catch((error) => {
761
+ console.warn("Error when adding URIs to local mappings:", error);
762
+ })
763
+ );
749
764
  }
750
765
  isAuthorizedFor({ type, action }) {
751
766
  if (type == "mappings" && action != "anonymous") {
@@ -833,10 +848,10 @@ var LocalMappingsProvider = class extends BaseProvider {
833
848
  let checkConcept = (concept, param) => concept.uri == param || param && concept.notation && concept.notation[0].toLowerCase() == param.toLowerCase();
834
849
  if (params.from || params.to) {
835
850
  mappings = mappings.filter((mapping) => {
836
- let fromInFrom = import_jskos_tools2.default.conceptsOfMapping(mapping, "from").find((concept) => checkConcept(concept, params.from)) != null;
837
- let fromInTo = import_jskos_tools2.default.conceptsOfMapping(mapping, "to").find((concept) => checkConcept(concept, params.from)) != null;
838
- let toInFrom = import_jskos_tools2.default.conceptsOfMapping(mapping, "from").find((concept) => checkConcept(concept, params.to)) != null;
839
- let toInTo = import_jskos_tools2.default.conceptsOfMapping(mapping, "to").find((concept) => checkConcept(concept, params.to)) != null;
851
+ let fromInFrom = null != import_jskos_tools2.default.conceptsOfMapping(mapping, "from").find((concept) => checkConcept(concept, params.from));
852
+ let fromInTo = null != import_jskos_tools2.default.conceptsOfMapping(mapping, "to").find((concept) => checkConcept(concept, params.from));
853
+ let toInFrom = null != import_jskos_tools2.default.conceptsOfMapping(mapping, "from").find((concept) => checkConcept(concept, params.to));
854
+ let toInTo = null != import_jskos_tools2.default.conceptsOfMapping(mapping, "to").find((concept) => checkConcept(concept, params.to));
840
855
  if (params.direction == "backward") {
841
856
  if (params.mode == "or") {
842
857
  return params.from && fromInTo || params.to && toInFrom;
@@ -1386,9 +1401,13 @@ MappingsApiProvider.stored = true;
1386
1401
 
1387
1402
  // src/providers/occurrences-api-provider.js
1388
1403
  var import_jskos_tools4 = __toESM(require("jskos-tools"), 1);
1404
+ var cache = {};
1389
1405
  var OccurrencesApiProvider = class extends BaseProvider {
1406
+ get _cache() {
1407
+ return cache[this.uri];
1408
+ }
1390
1409
  _prepare() {
1391
- this._cache = [];
1410
+ cache[this.uri] = [];
1392
1411
  this._occurrencesSupportedSchemes = [];
1393
1412
  this.has.occurrences = true;
1394
1413
  this.has.mappings = true;
@@ -1401,11 +1420,11 @@ var OccurrencesApiProvider = class extends BaseProvider {
1401
1420
  } else {
1402
1421
  try {
1403
1422
  const url = concatUrl(this._api.api, "voc");
1404
- const data = await this.axios({
1423
+ const data3 = await this.axios({
1405
1424
  method: "get",
1406
1425
  url
1407
1426
  });
1408
- this._occurrencesSupportedSchemes = data || [];
1427
+ this._occurrencesSupportedSchemes = data3 || [];
1409
1428
  } catch (error) {
1410
1429
  }
1411
1430
  }
@@ -1519,19 +1538,19 @@ var OccurrencesApiProvider = class extends BaseProvider {
1519
1538
  if (resultsFromCache) {
1520
1539
  return resultsFromCache.data;
1521
1540
  }
1522
- const data = await this.axios({
1541
+ const data3 = await this.axios({
1523
1542
  ...config,
1524
1543
  method: "get",
1525
1544
  url: this._api.api
1526
1545
  });
1527
1546
  this._cache.push({
1528
1547
  config,
1529
- data
1548
+ data: data3
1530
1549
  });
1531
1550
  if (this._cache.length > 20) {
1532
- this._cache = this._cache.slice(this._cache.length - 20);
1551
+ cache[this.uri] = this._cache.slice(this._cache.length - 20);
1533
1552
  }
1534
- return data;
1553
+ return data3;
1535
1554
  }
1536
1555
  };
1537
1556
  OccurrencesApiProvider.providerName = "OccurrencesApi";
@@ -1831,9 +1850,13 @@ ConceptApiProvider.providerType = "http://bartoc.org/api-type/jskos";
1831
1850
 
1832
1851
  // src/providers/reconciliation-api-provider.js
1833
1852
  var import_jskos_tools6 = __toESM(require("jskos-tools"), 1);
1853
+ var cache2 = {};
1834
1854
  var ReconciliationApiProvider = class extends BaseProvider {
1855
+ get _cache() {
1856
+ return cache2[this.uri];
1857
+ }
1835
1858
  _prepare() {
1836
- this._cache = [];
1859
+ cache2[this.uri] = [];
1837
1860
  this.has.mappings = true;
1838
1861
  listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
1839
1862
  this.has[c] = false;
@@ -1945,22 +1968,22 @@ var ReconciliationApiProvider = class extends BaseProvider {
1945
1968
  }
1946
1969
  const encodedData = `queries=${encodeURIComponent(JSON.stringify(queries))}`;
1947
1970
  import_set.default(config, ["headers", "Content-Type"], "application/x-www-form-urlencoded");
1948
- let data = await this.axios({
1971
+ let data3 = await this.axios({
1949
1972
  ...config,
1950
1973
  method: "post",
1951
1974
  url,
1952
1975
  data: encodedData
1953
1976
  });
1954
- data = data || {};
1977
+ data3 = data3 || {};
1955
1978
  let newCacheEntry = {
1956
1979
  labels,
1957
1980
  language,
1958
- data,
1981
+ data: data3,
1959
1982
  url: `${url}${url.includes("?") ? "&" : "?"}${encodedData}`
1960
1983
  };
1961
1984
  this._cache.push(newCacheEntry);
1962
1985
  if (this._cache.length > 20) {
1963
- this._cache = this._cache.slice(this._cache.length - 20);
1986
+ cache2[this.uri] = this._cache.slice(this._cache.length - 20);
1964
1987
  }
1965
1988
  return newCacheEntry;
1966
1989
  }
@@ -2054,7 +2077,7 @@ var LabelSearchSuggestionProvider = class extends BaseProvider {
2054
2077
  if (!registry || registry.has.search === false) {
2055
2078
  return [];
2056
2079
  }
2057
- const data = await registry.search({
2080
+ const data3 = await registry.search({
2058
2081
  ...config,
2059
2082
  search: label,
2060
2083
  scheme: targetScheme,
@@ -2063,9 +2086,9 @@ var LabelSearchSuggestionProvider = class extends BaseProvider {
2063
2086
  if (!this._cache[targetScheme.uri]) {
2064
2087
  this._cache[targetScheme.uri] = {};
2065
2088
  }
2066
- this._cache[targetScheme.uri][label] = data;
2089
+ this._cache[targetScheme.uri][label] = data3;
2067
2090
  this._cache[targetScheme.uri][label]._limit = limit;
2068
- return data;
2091
+ return data3;
2069
2092
  }
2070
2093
  };
2071
2094
  LabelSearchSuggestionProvider.providerName = "LabelSearchSuggestion";
@@ -2136,11 +2159,11 @@ var SkosmosApiProvider = class extends BaseProvider {
2136
2159
  return null;
2137
2160
  }
2138
2161
  const url = this._getApiUrl(scheme, "/");
2139
- const data = await this.axios({
2162
+ const data3 = await this.axios({
2140
2163
  method: "get",
2141
2164
  url
2142
2165
  });
2143
- const resultScheme = data.conceptschemes.find((s) => import_jskos_tools8.default.compare(s, scheme));
2166
+ const resultScheme = data3.conceptschemes.find((s) => import_jskos_tools8.default.compare(s, scheme));
2144
2167
  if (resultScheme) {
2145
2168
  this._approvedSchemes.push({
2146
2169
  uri: resultScheme.uri,
@@ -2231,12 +2254,12 @@ var SkosmosApiProvider = class extends BaseProvider {
2231
2254
  const schemes = [];
2232
2255
  for (let scheme of this.schemes || []) {
2233
2256
  const url = this._getApiUrl(scheme, "/");
2234
- const data = await this.axios({
2257
+ const data3 = await this.axios({
2235
2258
  ...config,
2236
2259
  method: "get",
2237
2260
  url
2238
2261
  });
2239
- const resultScheme = data.conceptschemes.find((s) => import_jskos_tools8.default.compare(s, scheme));
2262
+ const resultScheme = data3.conceptschemes.find((s) => import_jskos_tools8.default.compare(s, scheme));
2240
2263
  const label = resultScheme && (resultScheme.prefLabel || resultScheme.label || resultScheme.title);
2241
2264
  if (label) {
2242
2265
  import_set.default(scheme, `prefLabel.${this._language}`, label);
@@ -2437,28 +2460,28 @@ var supportedSchemes = [
2437
2460
  }
2438
2461
  ];
2439
2462
  var lccUri = `${locUriPrefix}classification`;
2440
- function madsToJskosItem(data) {
2463
+ function madsToJskosItem(data3) {
2441
2464
  const item = {};
2442
- item.uri = data["@id"];
2443
- item.notation = (data["http://www.loc.gov/mads/rdf/v1#code"] || []).map((n) => n["@value"]);
2444
- const prefLabelArray = data["http://www.loc.gov/mads/rdf/v1#authoritativeLabel"] || data["http://www.w3.org/2000/01/rdf-schema#label"] || [];
2465
+ item.uri = data3["@id"];
2466
+ item.notation = (data3["http://www.loc.gov/mads/rdf/v1#code"] || []).map((n) => n["@value"]);
2467
+ const prefLabelArray = data3["http://www.loc.gov/mads/rdf/v1#authoritativeLabel"] || data3["http://www.w3.org/2000/01/rdf-schema#label"] || [];
2445
2468
  if (prefLabelArray.length) {
2446
2469
  item.prefLabel = {};
2447
2470
  item.prefLabel[prefLabelArray[0]["@language"] || "en"] = prefLabelArray[0]["@value"];
2448
2471
  }
2449
- const altLabelArray = data["http://www.w3.org/2004/02/skos/core#altLabel"] || [];
2472
+ const altLabelArray = data3["http://www.w3.org/2004/02/skos/core#altLabel"] || [];
2450
2473
  if (altLabelArray.length) {
2451
2474
  item.altLabel = { en: altLabelArray.map((l) => l["@value"]) };
2452
2475
  }
2453
- for (let definition of data["http://www.w3.org/2000/01/rdf-schema#comment"] || []) {
2476
+ for (let definition of data3["http://www.w3.org/2000/01/rdf-schema#comment"] || []) {
2454
2477
  item.definition = item.definition || {};
2455
2478
  item.definition.en = item.definition.en || [];
2456
2479
  item.definition.en.push(definition["@value"]);
2457
2480
  }
2458
2481
  return item;
2459
2482
  }
2460
- function madsToJskosScheme(data) {
2461
- const scheme = madsToJskosItem(data);
2483
+ function madsToJskosScheme(data3) {
2484
+ const scheme = madsToJskosItem(data3);
2462
2485
  scheme.namespace = scheme.uri + "/";
2463
2486
  scheme.type = ["http://www.w3.org/2004/02/skos/core#ConceptScheme"];
2464
2487
  return scheme;
@@ -2469,16 +2492,16 @@ var schemeNamespaceFilter = (scheme) => (c) => {
2469
2492
  }
2470
2493
  return c.uri.startsWith(scheme.namespace);
2471
2494
  };
2472
- function madsToJskosConcept(data, { scheme }) {
2473
- const concept = madsToJskosItem(data);
2495
+ function madsToJskosConcept(data3, { scheme }) {
2496
+ const concept = madsToJskosItem(data3);
2474
2497
  concept.type = ["http://www.w3.org/2004/02/skos/core#Concept"];
2475
- concept.inScheme = scheme ? [scheme] : (data["http://www.loc.gov/mads/rdf/v1#isMemberOfMADSScheme"] || []).map((s) => supportedSchemes.find((s2) => s2.uri === s["@id"]));
2498
+ concept.inScheme = scheme ? [scheme] : (data3["http://www.loc.gov/mads/rdf/v1#isMemberOfMADSScheme"] || []).map((s) => supportedSchemes.find((s2) => s2.uri === s["@id"]));
2476
2499
  if (!concept.inScheme.length || !concept.inScheme[0]) {
2477
2500
  delete concept.inScheme;
2478
2501
  }
2479
- 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"] || [];
2502
+ 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"] || [];
2480
2503
  concept.narrower = narrower.map((n) => ({ uri: n["@id"] })).filter(schemeNamespaceFilter(concept.inScheme && concept.inScheme[0]));
2481
- 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"] || [];
2504
+ 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"] || [];
2482
2505
  concept.broader = broader.map((n) => ({ uri: n["@id"] })).filter(schemeNamespaceFilter(concept.inScheme && concept.inScheme[0]));
2483
2506
  return concept;
2484
2507
  }
@@ -2506,20 +2529,22 @@ var LocApiProvider = class extends BaseProvider {
2506
2529
  }
2507
2530
  async getSchemes() {
2508
2531
  const schemes = [];
2509
- for (let scheme of await Promise.all(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)({
2510
- method: "get",
2511
- url: `${s.uri.replace("http:", "https:")}.json`
2512
- }).then(({ status, data }) => {
2513
- if (status === 200) {
2514
- let scheme2 = data.find((d) => s.uri === d["@id"]);
2515
- if (scheme2) {
2516
- scheme2 = import_jskos_tools9.default.merge(madsToJskosScheme(scheme2), s);
2517
- scheme2.topConcepts = (scheme2.topConcepts || []).filter((c) => c);
2518
- return scheme2;
2532
+ for (let scheme of await Promise.all(
2533
+ 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)({
2534
+ method: "get",
2535
+ url: `${s.uri.replace("http:", "https:")}.json`
2536
+ }).then(({ status, data: data3 }) => {
2537
+ if (status === 200) {
2538
+ let scheme2 = data3.find((d) => s.uri === d["@id"]);
2539
+ if (scheme2) {
2540
+ scheme2 = import_jskos_tools9.default.merge(madsToJskosScheme(scheme2), s);
2541
+ scheme2.topConcepts = (scheme2.topConcepts || []).filter((c) => c);
2542
+ return scheme2;
2543
+ }
2519
2544
  }
2520
- }
2521
- return null;
2522
- })))) {
2545
+ return null;
2546
+ }))
2547
+ )) {
2523
2548
  if (scheme) {
2524
2549
  schemes.push(scheme);
2525
2550
  }
@@ -2534,9 +2559,9 @@ var LocApiProvider = class extends BaseProvider {
2534
2559
  for (let concept of await Promise.all(concepts.map((c) => (0, import_axios2.default)({
2535
2560
  method: "get",
2536
2561
  url: `${c.uri.replace("http:", "https:")}.json`
2537
- }).then(({ status, data }) => {
2562
+ }).then(({ status, data: data3 }) => {
2538
2563
  if (status === 200) {
2539
- let concept2 = data.find((d) => c.uri === d["@id"]);
2564
+ let concept2 = data3.find((d) => c.uri === d["@id"]);
2540
2565
  if (concept2) {
2541
2566
  return madsToJskosConcept(concept2, { scheme: c.inScheme && c.inScheme[0] });
2542
2567
  }
@@ -2570,7 +2595,7 @@ var LocApiProvider = class extends BaseProvider {
2570
2595
  }
2571
2596
  limit = limit || this._jskos.suggestResultLimit || 100;
2572
2597
  offset = offset || 0;
2573
- const { data } = await (0, import_axios2.default)({
2598
+ const { data: data3 } = await (0, import_axios2.default)({
2574
2599
  method: "get",
2575
2600
  url: `${schemeUri}/suggest2`.replace("http:", "https:"),
2576
2601
  params: {
@@ -2580,7 +2605,7 @@ var LocApiProvider = class extends BaseProvider {
2580
2605
  searchtype: "keyword"
2581
2606
  }
2582
2607
  });
2583
- return (data.hits || []).map((d) => ({
2608
+ return (data3.hits || []).map((d) => ({
2584
2609
  uri: d.uri,
2585
2610
  notation: [d.token],
2586
2611
  prefLabel: { en: d.aLabel },
@@ -2595,10 +2620,14 @@ LocApiProvider.providerType = "http://bartoc.org/api-type/loc";
2595
2620
  var import_jskos_tools10 = __toESM(require("jskos-tools"), 1);
2596
2621
  var import_flexsearch = __toESM(require("flexsearch"), 1);
2597
2622
  function decodeUnicode(text) {
2598
- return text.replace(/\\u[\dA-F]{4}/gi, function(match) {
2599
- return String.fromCharCode(parseInt(match.replace(/\\u/g, ""), 16));
2600
- });
2623
+ return text.replace(
2624
+ /\\u[\dA-F]{4}/gi,
2625
+ function(match) {
2626
+ return String.fromCharCode(parseInt(match.replace(/\\u/g, ""), 16));
2627
+ }
2628
+ );
2601
2629
  }
2630
+ var data = {};
2602
2631
  var SkohubProvider = class extends BaseProvider {
2603
2632
  _prepare() {
2604
2633
  this.has.schemes = true;
@@ -2612,11 +2641,20 @@ var SkohubProvider = class extends BaseProvider {
2612
2641
  listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
2613
2642
  this.has[c] = false;
2614
2643
  });
2644
+ data[this.uri] = {
2645
+ index: {},
2646
+ conceptCache: {},
2647
+ schemeCache: {}
2648
+ };
2615
2649
  }
2616
- _setup() {
2617
- this._index = {};
2618
- this._conceptCache = {};
2619
- this._schemeCache = {};
2650
+ get _index() {
2651
+ return data[this.uri] && data[this.uri].index;
2652
+ }
2653
+ get _conceptCache() {
2654
+ return data[this.uri] && data[this.uri].conceptCache;
2655
+ }
2656
+ get _schemeCache() {
2657
+ return data[this.uri] && data[this.uri].schemeCache;
2620
2658
  }
2621
2659
  static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
2622
2660
  if (!url || !scheme) {
@@ -2642,11 +2680,11 @@ var SkohubProvider = class extends BaseProvider {
2642
2680
  if (uri.endsWith("/")) {
2643
2681
  postfix = "index.json";
2644
2682
  }
2645
- const data = await this.axios({ ...config, url: `${uri}${postfix}`, _skipAdditionalParameters: true });
2646
- if (data.id !== uri) {
2683
+ const data3 = await this.axios({ ...config, url: `${uri}${postfix}`, _skipAdditionalParameters: true });
2684
+ if (data3.id !== uri) {
2647
2685
  throw new InvalidRequestError({ message: "Skohub URL did not return expected concept scheme" });
2648
2686
  }
2649
- const { title, preferredNamespaceUri, hasTopConcept, description } = data;
2687
+ const { title, preferredNamespaceUri, hasTopConcept, description } = data3;
2650
2688
  scheme = { uri, identifier: uris.filter((u) => u !== uri) };
2651
2689
  scheme.prefLabel = title;
2652
2690
  Object.keys(scheme.prefLabel || {}).forEach((key) => {
@@ -2674,33 +2712,33 @@ var SkohubProvider = class extends BaseProvider {
2674
2712
  return this._conceptCache[uri];
2675
2713
  }
2676
2714
  try {
2677
- const data = await this.axios({ ...config, url: `${uri}.json`, _skipAdditionalParameters: true });
2678
- if (data.id !== uri) {
2715
+ const data3 = await this.axios({ ...config, url: `${uri}.json`, _skipAdditionalParameters: true });
2716
+ if (data3.id !== uri) {
2679
2717
  throw new InvalidRequestError({ message: "Skohub URL did not return expected concept URI" });
2680
2718
  }
2681
- const concept = this._toJskosConcept(data);
2719
+ const concept = this._toJskosConcept(data3);
2682
2720
  this._conceptCache[uri] = concept;
2683
2721
  return concept;
2684
2722
  } catch (error) {
2685
2723
  return null;
2686
2724
  }
2687
2725
  }
2688
- _toJskosConcept(data) {
2689
- const concept = { uri: data.id };
2690
- concept.prefLabel = data.prefLabel;
2726
+ _toJskosConcept(data3) {
2727
+ const concept = { uri: data3.id };
2728
+ concept.prefLabel = data3.prefLabel;
2691
2729
  Object.keys(concept.prefLabel || {}).forEach((key) => {
2692
2730
  concept.prefLabel[key] = decodeUnicode(concept.prefLabel[key]);
2693
2731
  });
2694
- concept.narrower = (data.narrower || []).map((c) => this._toJskosConcept(c));
2695
- concept.notation = data.notation || [];
2696
- if (data.broader && data.broader.id) {
2697
- concept.broader = [{ uri: data.broader.id }];
2732
+ concept.narrower = (data3.narrower || []).map((c) => this._toJskosConcept(c));
2733
+ concept.notation = data3.notation || [];
2734
+ if (data3.broader && data3.broader.id) {
2735
+ concept.broader = [{ uri: data3.broader.id }];
2698
2736
  }
2699
- if (data.inScheme && data.inScheme.id) {
2700
- concept.inScheme = [{ uri: data.inScheme.id }];
2737
+ if (data3.inScheme && data3.inScheme.id) {
2738
+ concept.inScheme = [{ uri: data3.inScheme.id }];
2701
2739
  }
2702
- if (data.scopeNote) {
2703
- concept.scopeNote = data.scopeNote;
2740
+ if (data3.scopeNote) {
2741
+ concept.scopeNote = data3.scopeNote;
2704
2742
  Object.keys(concept.scopeNote).forEach((key) => {
2705
2743
  concept.scopeNote[key] = [decodeUnicode(concept.scopeNote[key])];
2706
2744
  });
@@ -2772,13 +2810,13 @@ var SkohubProvider = class extends BaseProvider {
2772
2810
  if (scheme.uri.endsWith("/")) {
2773
2811
  postfix = `index${postfix}`;
2774
2812
  }
2775
- const data = await this.axios({ url: `${scheme.uri}${postfix}`, _skipAdditionalParameters: true });
2776
- if (data.length < 100) {
2813
+ const data3 = await this.axios({ url: `${scheme.uri}${postfix}`, _skipAdditionalParameters: true });
2814
+ if (data3.length < 100) {
2777
2815
  this._index[scheme.uri][lang] = null;
2778
2816
  continue;
2779
2817
  }
2780
2818
  index = import_flexsearch.default.create();
2781
- index.import(data);
2819
+ index.import(data3);
2782
2820
  this._index[scheme.uri][lang] = index;
2783
2821
  break;
2784
2822
  } catch (error) {
@@ -2814,6 +2852,217 @@ var SkohubProvider = class extends BaseProvider {
2814
2852
  SkohubProvider.providerName = "Skohub";
2815
2853
  SkohubProvider.providerType = "http://bartoc.org/api-type/skohub";
2816
2854
 
2855
+ // src/providers/mycore-provider.js
2856
+ var import_jskos_tools11 = __toESM(require("jskos-tools"), 1);
2857
+ var import_flexsearch2 = __toESM(require("flexsearch"), 1);
2858
+ var data2 = {};
2859
+ var MyCoReProvider = class extends BaseProvider {
2860
+ _prepare() {
2861
+ this.has.schemes = true;
2862
+ this.has.top = true;
2863
+ this.has.data = true;
2864
+ this.has.concepts = true;
2865
+ this.has.narrower = true;
2866
+ this.has.ancestors = true;
2867
+ this.has.suggest = true;
2868
+ this.has.search = true;
2869
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
2870
+ this.has[c] = false;
2871
+ });
2872
+ }
2873
+ _setup() {
2874
+ this._scheme = null;
2875
+ }
2876
+ static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
2877
+ if (!url || !scheme) {
2878
+ return null;
2879
+ }
2880
+ return {
2881
+ api: url
2882
+ };
2883
+ }
2884
+ _schemeInfoToJSKOS(schemeInfo) {
2885
+ const uri = schemeInfo.labels.find((l) => l.lang === "x-uri").text;
2886
+ const prefLabel = {};
2887
+ schemeInfo.labels.filter((l) => !l.lang.startsWith("x-")).forEach((l) => {
2888
+ prefLabel[l.lang] = l.text;
2889
+ });
2890
+ const scheme = {
2891
+ uri,
2892
+ prefLabel
2893
+ };
2894
+ if (schemeInfo.categories && schemeInfo.categories.length) {
2895
+ scheme.topConcepts = [null];
2896
+ }
2897
+ if (schemeInfo.category && schemeInfo.category.length) {
2898
+ scheme.concepts = [null];
2899
+ }
2900
+ return scheme;
2901
+ }
2902
+ _categoryToJSKOS(category, { scheme, broader = [] }) {
2903
+ if (!category || !scheme) {
2904
+ return null;
2905
+ }
2906
+ const id = category.ID;
2907
+ const uri = `${scheme.uri}/${id}`;
2908
+ if (data2[scheme.uri].concepts[uri]) {
2909
+ return data2[scheme.uri].concepts[uri];
2910
+ }
2911
+ const prefLabel = {};
2912
+ category.labels.filter((l) => !l.lang.startsWith("x-") && l.text).forEach((l) => {
2913
+ prefLabel[l.lang] = l.text.replace(`${id} `, "");
2914
+ data2[scheme.uri].searchIndex.add(uri, prefLabel[l.lang]);
2915
+ });
2916
+ const scopeNote = {};
2917
+ category.labels.filter((l) => !l.lang.startsWith("x-") && l.description).forEach((l) => {
2918
+ if (!scopeNote[l.lang]) {
2919
+ scopeNote[l.lang] = [];
2920
+ }
2921
+ scopeNote[l.lang].push(l.description);
2922
+ });
2923
+ data2[scheme.uri].concepts[uri] = {
2924
+ uri,
2925
+ notation: [id],
2926
+ prefLabel,
2927
+ scopeNote,
2928
+ inScheme: [{ uri: scheme.uri }],
2929
+ narrower: (category.categories || []).map((c) => ({ uri: `${scheme.uri}/${c.ID}` })),
2930
+ broader
2931
+ };
2932
+ return data2[scheme.uri].concepts[uri];
2933
+ }
2934
+ _removeNarrower(concept) {
2935
+ if (!concept)
2936
+ return concept;
2937
+ return Object.assign({}, concept, { narrower: concept.narrower && concept.narrower.length ? [null] : [] });
2938
+ }
2939
+ async _loadSchemeData(config) {
2940
+ const schemeInfo = await this.axios({
2941
+ ...config,
2942
+ method: "get",
2943
+ url: this._api.api,
2944
+ _skipAdditionalParameters: true
2945
+ });
2946
+ this._scheme = this._schemeInfoToJSKOS(schemeInfo);
2947
+ const uri = this._scheme.uri;
2948
+ data2[uri] = {
2949
+ schemeInfo,
2950
+ searchIndex: import_flexsearch2.default.create({
2951
+ tokenize: "full"
2952
+ }),
2953
+ concepts: {}
2954
+ };
2955
+ const dealWithCategory = (category, { broader = [] } = {}) => {
2956
+ const concept = this._categoryToJSKOS(category, { scheme: this._scheme, broader });
2957
+ (category.categories || []).forEach((c) => dealWithCategory(c, { broader: [{ uri: concept.uri }] }));
2958
+ };
2959
+ schemeInfo.categories.forEach((category) => dealWithCategory(category));
2960
+ data2[uri].topConcepts = schemeInfo.categories.map((category) => this._categoryToJSKOS(category, { scheme: this._scheme }));
2961
+ }
2962
+ async getSchemes(config = {}) {
2963
+ if (!this._api.api) {
2964
+ throw new MissingApiUrlError();
2965
+ }
2966
+ if (!this._scheme) {
2967
+ if (!this._loadSchemeDataPromise) {
2968
+ this._loadSchemeDataPromise = this._loadSchemeData(config);
2969
+ }
2970
+ await this._loadSchemeDataPromise;
2971
+ }
2972
+ return [this._scheme];
2973
+ }
2974
+ async getTop({ scheme, ...config }) {
2975
+ if (!scheme || !scheme.uri) {
2976
+ throw new InvalidOrMissingParameterError({ parameter: "scheme", message: "Missing scheme URI" });
2977
+ }
2978
+ if (!this._scheme) {
2979
+ await this.getSchemes(config);
2980
+ }
2981
+ if (!import_jskos_tools11.default.compare(scheme, this._scheme)) {
2982
+ throw new InvalidOrMissingParameterError({ parameter: "scheme", message: "Requested vocabulary seems to be unsupported by this API." });
2983
+ }
2984
+ return data2[this._scheme.uri].topConcepts.map(this._removeNarrower);
2985
+ }
2986
+ async getConcepts({ concepts, ...config }) {
2987
+ if (!import_isArray.default(concepts)) {
2988
+ concepts = [concepts];
2989
+ }
2990
+ if (!this._scheme) {
2991
+ await this.getSchemes(config);
2992
+ }
2993
+ return concepts.map((c) => data2[this._scheme.uri].concepts[c.uri]).map(this._removeNarrower);
2994
+ }
2995
+ async getAncestors({ concept, ...config }) {
2996
+ if (!concept || !concept.uri) {
2997
+ throw new InvalidOrMissingParameterError({ parameter: "concept" });
2998
+ }
2999
+ if (concept.ancestors && concept.ancestors[0] !== null) {
3000
+ return concept.ancestors;
3001
+ }
3002
+ if (!this._scheme) {
3003
+ await this.getSchemes(config);
3004
+ }
3005
+ concept = data2[this._scheme.uri].concepts[concept.uri];
3006
+ const broader = concept && concept.broader && concept.broader[0];
3007
+ if (!broader) {
3008
+ return [];
3009
+ }
3010
+ return [broader].concat(await this.getAncestors({ concept: broader, ...config }));
3011
+ }
3012
+ async getNarrower({ concept, ...config }) {
3013
+ if (!concept || !concept.uri) {
3014
+ throw new InvalidOrMissingParameterError({ parameter: "concept" });
3015
+ }
3016
+ if (concept.narrower && concept.narrower[0] !== null) {
3017
+ return concept.narrower;
3018
+ }
3019
+ if (!this._scheme) {
3020
+ await this.getSchemes(config);
3021
+ }
3022
+ concept = data2[this._scheme.uri].concepts[concept.uri];
3023
+ return (concept && concept.narrower || []).map((c) => data2[this._scheme.uri].concepts[c.uri]).map(this._removeNarrower);
3024
+ }
3025
+ async search({ search, scheme, limit = 100 }) {
3026
+ if (!scheme || !scheme.uri) {
3027
+ throw new InvalidOrMissingParameterError({ parameter: "scheme" });
3028
+ }
3029
+ if (!search) {
3030
+ throw new InvalidOrMissingParameterError({ parameter: "search" });
3031
+ }
3032
+ if (!scheme || !scheme.uri) {
3033
+ throw new InvalidOrMissingParameterError({ parameter: "scheme", message: "Missing scheme URI" });
3034
+ }
3035
+ if (!this._scheme) {
3036
+ await this.getSchemes();
3037
+ }
3038
+ if (!import_jskos_tools11.default.compare(scheme, this._scheme)) {
3039
+ throw new InvalidOrMissingParameterError({ parameter: "scheme", message: "Requested vocabulary seems to be unsupported by this API." });
3040
+ }
3041
+ const result = await data2[this._scheme.uri].searchIndex.search(search);
3042
+ return result.map((uri) => data2[this._scheme.uri].concepts[uri]).map(this._removeNarrower).slice(0, limit);
3043
+ }
3044
+ async suggest(config) {
3045
+ config._raw = true;
3046
+ const concepts = await this.search(config);
3047
+ const result = [config.search, [], [], []];
3048
+ for (let concept of concepts) {
3049
+ const notation = import_jskos_tools11.default.notation(concept);
3050
+ const label = import_jskos_tools11.default.prefLabel(concept);
3051
+ result[1].push((notation ? notation + " " : "") + label);
3052
+ result[2].push("");
3053
+ result[3].push(concept.uri);
3054
+ }
3055
+ if (concepts._totalCount != void 0) {
3056
+ result._totalCount = concepts._totalCount;
3057
+ } else {
3058
+ result._totalCount = concepts.length;
3059
+ }
3060
+ return result;
3061
+ }
3062
+ };
3063
+ MyCoReProvider.providerName = "MyCoRe";
3064
+ MyCoReProvider.providerType = "http://bartoc.org/api-type/mycore";
3065
+
2817
3066
  // src/lib/CocodaSDK.js
2818
3067
  var providers = {
2819
3068
  [BaseProvider.providerName]: BaseProvider,
@@ -2999,7 +3248,7 @@ var CocodaSDK = class {
2999
3248
  scheme._registry = registry;
3000
3249
  scheme.__DETAILSLOADED__ = 1;
3001
3250
  scheme.type = scheme.type || ["http://www.w3.org/2004/02/skos/core#ConceptScheme"];
3002
- let otherScheme = schemes.find((s) => import_jskos_tools11.default.compare(s, scheme)), prio, otherPrio, override = false;
3251
+ let otherScheme = schemes.find((s) => import_jskos_tools12.default.compare(s, scheme)), prio, otherPrio, override = false;
3003
3252
  if (otherScheme) {
3004
3253
  prio = this.config.registries.indexOf(registry);
3005
3254
  if (prio != -1) {
@@ -3021,19 +3270,19 @@ var CocodaSDK = class {
3021
3270
  }
3022
3271
  if (!otherScheme || override) {
3023
3272
  if (override) {
3024
- let otherSchemeIndex = schemes.findIndex((s) => import_jskos_tools11.default.compare(s, otherScheme));
3273
+ let otherSchemeIndex = schemes.findIndex((s) => import_jskos_tools12.default.compare(s, otherScheme));
3025
3274
  if (otherSchemeIndex != -1) {
3026
3275
  schemes.splice(otherSchemeIndex, 1);
3027
3276
  }
3028
- scheme = import_jskos_tools11.default.merge(scheme, import_omit.default(otherScheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
3277
+ scheme = import_jskos_tools12.default.merge(scheme, import_omit.default(otherScheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
3029
3278
  }
3030
3279
  scheme._registry = registry;
3031
3280
  schemes.push(scheme);
3032
3281
  } else {
3033
- const index = schemes.findIndex((s) => import_jskos_tools11.default.compare(s, scheme));
3282
+ const index = schemes.findIndex((s) => import_jskos_tools12.default.compare(s, scheme));
3034
3283
  if (index != -1) {
3035
3284
  const otherSchemeRegistry = schemes[index]._registry;
3036
- schemes[index] = import_jskos_tools11.default.merge(schemes[index], import_omit.default(scheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
3285
+ schemes[index] = import_jskos_tools12.default.merge(schemes[index], import_omit.default(scheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
3037
3286
  schemes[index]._registry = otherSchemeRegistry;
3038
3287
  }
3039
3288
  }
@@ -3055,7 +3304,7 @@ var CocodaSDK = class {
3055
3304
  scheme._registry = newRegistry;
3056
3305
  }
3057
3306
  });
3058
- return import_jskos_tools11.default.sortSchemes(schemes.filter(Boolean));
3307
+ return import_jskos_tools12.default.sortSchemes(schemes.filter(Boolean));
3059
3308
  }
3060
3309
  registryForScheme(scheme) {
3061
3310
  let registry = scheme._registry;
@@ -3066,7 +3315,7 @@ var CocodaSDK = class {
3066
3315
  const url = config.url;
3067
3316
  if (registryCache[url]) {
3068
3317
  const registry2 = registryCache[url];
3069
- if (Array.isArray(registry2._jskos.schemes) && !import_jskos_tools11.default.isContainedIn(scheme, registry2._jskos.schemes)) {
3318
+ if (Array.isArray(registry2._jskos.schemes) && !import_jskos_tools12.default.isContainedIn(scheme, registry2._jskos.schemes)) {
3070
3319
  registry2._jskos.schemes.push(scheme);
3071
3320
  }
3072
3321
  return registry2;
@@ -3111,11 +3360,13 @@ function addAllProviders(_cdk) {
3111
3360
  LocApiProvider,
3112
3361
  LocalMappingsProvider,
3113
3362
  MappingsApiProvider,
3363
+ MyCoReProvider,
3114
3364
  OccurrencesApiProvider,
3115
3365
  ReconciliationApiProvider,
3116
3366
  SkohubProvider,
3117
3367
  SkosmosApiProvider,
3118
3368
  addAllProviders,
3119
3369
  cdk,
3120
- errors
3370
+ errors,
3371
+ utils
3121
3372
  });