cocoda-sdk 2.0.12 → 3.0.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.
@@ -280,6 +280,22 @@ function withCustomProps(arr, from) {
280
280
  arr._url = from._url;
281
281
  return arr;
282
282
  }
283
+ var listOfCapabilities = [
284
+ "schemes",
285
+ "top",
286
+ "data",
287
+ "concepts",
288
+ "narrower",
289
+ "ancestors",
290
+ "types",
291
+ "suggest",
292
+ "search",
293
+ "auth",
294
+ "mappings",
295
+ "concordances",
296
+ "annotations",
297
+ "occurrences"
298
+ ];
283
299
 
284
300
  // src/providers/base-provider.js
285
301
  var BaseProvider = class {
@@ -299,7 +315,7 @@ var BaseProvider = class {
299
315
  this._repeating = [];
300
316
  this._api = {
301
317
  status: registry.status,
302
- schemes: registry.schemes,
318
+ schemes: Array.isArray(registry.schemes) ? void 0 : registry.schemes,
303
319
  top: registry.top,
304
320
  data: registry.data,
305
321
  concepts: registry.concepts,
@@ -586,7 +602,16 @@ var BaseProvider = class {
586
602
  return registries;
587
603
  }
588
604
  adjustScheme(scheme) {
589
- scheme._registry = this.cdk && this.cdk.registryForScheme(scheme) || this;
605
+ scheme._registry = this.cdk && this.cdk.registryForScheme(scheme);
606
+ if (!scheme._registry) {
607
+ scheme._registry = this;
608
+ } else {
609
+ ["concepts", "topConcepts"].forEach((key) => {
610
+ if (Array.isArray(scheme[key]) && (scheme[key].length === 0 || scheme[key][0] === null)) {
611
+ delete scheme[key];
612
+ }
613
+ });
614
+ }
590
615
  if (scheme._registry) {
591
616
  scheme._getTop = (config) => {
592
617
  return scheme._registry.getTop({ ...config, scheme });
@@ -673,13 +698,18 @@ var import_localforage = __toESM(require("localforage"), 1);
673
698
  var import_uuid = require("uuid");
674
699
  var uriPrefix = "urn:uuid:";
675
700
  var LocalMappingsProvider = class extends BaseProvider {
676
- _setup() {
701
+ _prepare() {
677
702
  this.has.mappings = {
678
703
  read: true,
679
704
  create: true,
680
705
  update: true,
681
706
  delete: true
682
707
  };
708
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
709
+ this.has[c] = false;
710
+ });
711
+ }
712
+ _setup() {
683
713
  this.queue = [];
684
714
  this.localStorageKey = "cocoda-mappings--" + this._path;
685
715
  let oldLocalStorageKey = "mappings";
@@ -1007,6 +1037,12 @@ var MappingsApiProvider = class extends BaseProvider {
1007
1037
  if (this._api.api && this._api.status === void 0) {
1008
1038
  this._api.status = concatUrl(this._api.api, "/status");
1009
1039
  }
1040
+ this.has.mappings = true;
1041
+ this.has.concordances = true;
1042
+ this.has.annotations = true;
1043
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
1044
+ this.has[c] = false;
1045
+ });
1010
1046
  }
1011
1047
  _setup() {
1012
1048
  if (this._api.api) {
@@ -1262,11 +1298,14 @@ MappingsApiProvider.stored = true;
1262
1298
  // src/providers/occurrences-api-provider.js
1263
1299
  var import_jskos_tools4 = __toESM(require("jskos-tools"), 1);
1264
1300
  var OccurrencesApiProvider = class extends BaseProvider {
1265
- _setup() {
1301
+ _prepare() {
1266
1302
  this._cache = [];
1267
1303
  this._occurrencesSupportedSchemes = [];
1268
1304
  this.has.occurrences = true;
1269
1305
  this.has.mappings = true;
1306
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
1307
+ this.has[c] = false;
1308
+ });
1270
1309
  }
1271
1310
  async _occurrencesIsSupported(scheme) {
1272
1311
  if (this._occurrencesSupportedSchemes && this._occurrencesSupportedSchemes.length) {
@@ -1434,6 +1473,9 @@ var ConceptApiProvider = class extends BaseProvider {
1434
1473
  this.has.suggest = true;
1435
1474
  this.has.search = true;
1436
1475
  this.has.auth = true;
1476
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
1477
+ this.has[c] = false;
1478
+ });
1437
1479
  }
1438
1480
  _setup() {
1439
1481
  if (this._api.api) {
@@ -1455,6 +1497,9 @@ var ConceptApiProvider = class extends BaseProvider {
1455
1497
  }
1456
1498
  }
1457
1499
  this.has.schemes = !!this._api.schemes;
1500
+ if (!this.has.schemes && Array.isArray(this.schemes)) {
1501
+ this.has.schemes = true;
1502
+ }
1458
1503
  this.has.top = !!this._api.top;
1459
1504
  this.has.data = !!this._api.data;
1460
1505
  this.has.concepts = !!this._api.concepts || this.has.data;
@@ -1465,15 +1510,16 @@ var ConceptApiProvider = class extends BaseProvider {
1465
1510
  this.has.search = !!this._api.search;
1466
1511
  this.has.auth = import_get.default(this._config, "auth.key") != null;
1467
1512
  this._defaultParams = {
1468
- properties: "uri,prefLabel,notation,inScheme"
1513
+ properties: "+created,issued,modified,editorialNote,scopeNote"
1469
1514
  };
1470
1515
  }
1471
- static _registryConfigForBartocApiConfig({ url } = {}) {
1472
- if (!url) {
1516
+ static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
1517
+ if (!url || !scheme) {
1473
1518
  return null;
1474
1519
  }
1475
1520
  return {
1476
- api: url
1521
+ api: url,
1522
+ schemes: [scheme]
1477
1523
  };
1478
1524
  }
1479
1525
  async _getSchemeUri(scheme) {
@@ -1486,7 +1532,9 @@ var ConceptApiProvider = class extends BaseProvider {
1486
1532
  if (this._rejectedSchemes.find((s) => import_jskos_tools5.default.compare(scheme, s))) {
1487
1533
  return null;
1488
1534
  }
1489
- const schemes = await this.getSchemes({ uri: import_jskos_tools5.default.getAllUris(scheme) });
1535
+ const schemes = await this.getSchemes({ params: {
1536
+ uri: import_jskos_tools5.default.getAllUris(scheme).join("|")
1537
+ } });
1490
1538
  const resultScheme = schemes.find((s) => import_jskos_tools5.default.compare(s, scheme));
1491
1539
  if (resultScheme) {
1492
1540
  this._approvedSchemes.push({
@@ -1504,11 +1552,11 @@ var ConceptApiProvider = class extends BaseProvider {
1504
1552
  }
1505
1553
  async getSchemes(config) {
1506
1554
  if (!this._api.schemes) {
1555
+ if (Array.isArray(this.schemes)) {
1556
+ return this.schemes;
1557
+ }
1507
1558
  throw new MissingApiUrlError();
1508
1559
  }
1509
- if (Array.isArray(this._api.schemes)) {
1510
- return this._api.schemes;
1511
- }
1512
1560
  const schemes = await this.axios({
1513
1561
  ...config,
1514
1562
  method: "get",
@@ -1519,8 +1567,8 @@ var ConceptApiProvider = class extends BaseProvider {
1519
1567
  ...config.params || {}
1520
1568
  }
1521
1569
  });
1522
- if (Array.isArray(this._jskos.schemes)) {
1523
- return withCustomProps(schemes.filter((s) => import_jskos_tools5.default.isContainedIn(s, this._jskos.schemes)), schemes);
1570
+ if (Array.isArray(this.schemes)) {
1571
+ return withCustomProps(schemes.filter((s) => import_jskos_tools5.default.isContainedIn(s, this.schemes)), schemes);
1524
1572
  } else {
1525
1573
  return schemes;
1526
1574
  }
@@ -1552,7 +1600,7 @@ var ConceptApiProvider = class extends BaseProvider {
1552
1600
  });
1553
1601
  }
1554
1602
  async getConcepts({ concepts, ...config }) {
1555
- if (!this.has.data) {
1603
+ if (this.has.data === false) {
1556
1604
  throw new MissingApiUrlError();
1557
1605
  }
1558
1606
  if (!concepts) {
@@ -1612,26 +1660,24 @@ var ConceptApiProvider = class extends BaseProvider {
1612
1660
  }
1613
1661
  });
1614
1662
  }
1615
- async suggest({ scheme, use = "notation,label", types = [], sort = "score", ...config }) {
1663
+ async suggest({ use = "notation,label", types = [], sort = "score", ...config }) {
1616
1664
  return this._search({
1617
1665
  ...config,
1618
1666
  endpoint: "suggest",
1619
1667
  params: {
1620
1668
  ...config.params,
1621
- voc: import_get.default(scheme, "uri", ""),
1622
1669
  type: types.join("|"),
1623
1670
  use,
1624
1671
  sort
1625
1672
  }
1626
1673
  });
1627
1674
  }
1628
- async search({ scheme, types = [], ...config }) {
1675
+ async search({ types = [], ...config }) {
1629
1676
  return this._search({
1630
1677
  ...config,
1631
1678
  endpoint: "search",
1632
1679
  params: {
1633
1680
  ...config.params,
1634
- voc: import_get.default(scheme, "uri", ""),
1635
1681
  type: types.join("|")
1636
1682
  }
1637
1683
  });
@@ -1653,7 +1699,7 @@ var ConceptApiProvider = class extends BaseProvider {
1653
1699
  endpoint: "voc-search"
1654
1700
  });
1655
1701
  }
1656
- async _search({ endpoint, search, limit, offset, params, ...config }) {
1702
+ async _search({ endpoint, scheme, search, limit, offset, params, ...config }) {
1657
1703
  let url = this._api[endpoint];
1658
1704
  if (!url) {
1659
1705
  throw new MissingApiUrlError();
@@ -1663,6 +1709,7 @@ var ConceptApiProvider = class extends BaseProvider {
1663
1709
  }
1664
1710
  limit = limit || this._jskos.suggestResultLimit || 100;
1665
1711
  offset = offset || 0;
1712
+ const voc = scheme && await this._getSchemeUri(scheme);
1666
1713
  url = url.replace("{searchTerms}", search);
1667
1714
  return this.axios({
1668
1715
  ...config,
@@ -1673,7 +1720,8 @@ var ConceptApiProvider = class extends BaseProvider {
1673
1720
  count: limit,
1674
1721
  offset,
1675
1722
  search,
1676
- query: search
1723
+ query: search,
1724
+ voc
1677
1725
  },
1678
1726
  method: "get",
1679
1727
  url
@@ -1703,9 +1751,12 @@ ConceptApiProvider.providerType = "http://bartoc.org/api-type/jskos";
1703
1751
  // src/providers/reconciliation-api-provider.js
1704
1752
  var import_jskos_tools6 = __toESM(require("jskos-tools"), 1);
1705
1753
  var ReconciliationApiProvider = class extends BaseProvider {
1706
- _setup() {
1707
- this.has.mappings = true;
1754
+ _prepare() {
1708
1755
  this._cache = [];
1756
+ this.has.mappings = true;
1757
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
1758
+ this.has[c] = false;
1759
+ });
1709
1760
  }
1710
1761
  async getMappings({ from, to, mode, ...config }) {
1711
1762
  let schemes = [];
@@ -1839,9 +1890,12 @@ ReconciliationApiProvider.stored = false;
1839
1890
  // src/providers/label-search-suggestion-provider.js
1840
1891
  var import_jskos_tools7 = __toESM(require("jskos-tools"), 1);
1841
1892
  var LabelSearchSuggestionProvider = class extends BaseProvider {
1842
- _setup() {
1893
+ _prepare() {
1843
1894
  this._cache = [];
1844
1895
  this.has.mappings = true;
1896
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
1897
+ this.has[c] = false;
1898
+ });
1845
1899
  }
1846
1900
  supportsScheme(scheme) {
1847
1901
  return import_get.default(scheme, "_registry.has.search", false);
@@ -1890,6 +1944,8 @@ var LabelSearchSuggestionProvider = class extends BaseProvider {
1890
1944
  if (!label) {
1891
1945
  return [];
1892
1946
  }
1947
+ const regexResult = /^[\s\wäüöÄÜÖß]*\w/.exec(label);
1948
+ label = regexResult ? regexResult[0] : label;
1893
1949
  const results = await this._getResults({ ...config, label, targetScheme, limit });
1894
1950
  let mappings = results.map((result) => ({
1895
1951
  fromScheme: sourceScheme,
@@ -1914,7 +1970,7 @@ var LabelSearchSuggestionProvider = class extends BaseProvider {
1914
1970
  return resultsFromCache;
1915
1971
  }
1916
1972
  const registry = import_get.default(targetScheme, "_registry");
1917
- if (!registry || !registry.has.search) {
1973
+ if (!registry || registry.has.search === false) {
1918
1974
  return [];
1919
1975
  }
1920
1976
  const data = await registry.search({
@@ -1937,7 +1993,7 @@ LabelSearchSuggestionProvider.stored = false;
1937
1993
  // src/providers/skosmos-api-provider.js
1938
1994
  var import_jskos_tools8 = __toESM(require("jskos-tools"), 1);
1939
1995
  var SkosmosApiProvider = class extends BaseProvider {
1940
- _setup() {
1996
+ _prepare() {
1941
1997
  this.has.schemes = true;
1942
1998
  this.has.top = true;
1943
1999
  this.has.data = true;
@@ -1947,6 +2003,9 @@ var SkosmosApiProvider = class extends BaseProvider {
1947
2003
  this.has.types = true;
1948
2004
  this.has.suggest = true;
1949
2005
  this.has.search = true;
2006
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
2007
+ this.has[c] = false;
2008
+ });
1950
2009
  }
1951
2010
  static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
1952
2011
  if (!url || !scheme) {
@@ -2343,7 +2402,7 @@ function madsToJskosConcept(data, { scheme }) {
2343
2402
  return concept;
2344
2403
  }
2345
2404
  var LocApiProvider = class extends BaseProvider {
2346
- _setup() {
2405
+ _prepare() {
2347
2406
  this.has.schemes = true;
2348
2407
  this.has.top = false;
2349
2408
  this.has.data = true;
@@ -2352,6 +2411,9 @@ var LocApiProvider = class extends BaseProvider {
2352
2411
  this.has.ancestors = false;
2353
2412
  this.has.suggest = true;
2354
2413
  this.has.search = true;
2414
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
2415
+ this.has[c] = false;
2416
+ });
2355
2417
  }
2356
2418
  static _registryConfigForBartocApiConfig({ scheme } = {}) {
2357
2419
  if (!scheme || !supportedSchemes.find((s) => import_jskos_tools9.default.compare(s, scheme))) {
@@ -2467,6 +2529,7 @@ var providers = {
2467
2529
  };
2468
2530
  providers.addProvider(ConceptApiProvider);
2469
2531
  providers.addProvider(MappingsApiProvider);
2532
+ var registryCache = {};
2470
2533
  var CocodaSDK = class {
2471
2534
  constructor(config) {
2472
2535
  this.config = config;
@@ -2619,9 +2682,10 @@ var CocodaSDK = class {
2619
2682
  async getSchemes(config = {}) {
2620
2683
  let schemes = [], promises = [];
2621
2684
  for (let registry of this.config.registries) {
2622
- if (registry.has.schemes) {
2685
+ if (registry.has.schemes !== false) {
2623
2686
  let promise = registry.getSchemes(config).then((results) => {
2624
2687
  for (let scheme of results) {
2688
+ const currentSchemeRegistry = scheme._registry;
2625
2689
  scheme.__DETAILSLOADED__ = 1;
2626
2690
  scheme.type = scheme.type || ["http://www.w3.org/2004/02/skos/core#ConceptScheme"];
2627
2691
  let otherScheme = schemes.find((s) => import_jskos_tools10.default.compare(s, scheme)), prio, otherPrio, override = false;
@@ -2652,14 +2716,14 @@ var CocodaSDK = class {
2652
2716
  }
2653
2717
  scheme = import_jskos_tools10.default.merge(scheme, import_omit.default(otherScheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
2654
2718
  }
2655
- scheme._registry = registry;
2719
+ scheme._registry = currentSchemeRegistry;
2656
2720
  schemes.push(scheme);
2657
2721
  } else {
2658
- let index = schemes.findIndex((s) => import_jskos_tools10.default.compare(s, scheme));
2722
+ const index = schemes.findIndex((s) => import_jskos_tools10.default.compare(s, scheme));
2659
2723
  if (index != -1) {
2660
- let registry2 = schemes[index]._registry;
2724
+ const otherSchemeRegistry = schemes[index]._registry;
2661
2725
  schemes[index] = import_jskos_tools10.default.merge(schemes[index], import_omit.default(scheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
2662
- schemes[index]._registry = registry2;
2726
+ schemes[index]._registry = otherSchemeRegistry;
2663
2727
  }
2664
2728
  }
2665
2729
  }
@@ -2678,22 +2742,34 @@ var CocodaSDK = class {
2678
2742
  return registry;
2679
2743
  }
2680
2744
  for (let { type, ...config } of scheme.API || []) {
2681
- const provider = Object.values(providers).find((p) => p.providerType === type);
2682
- if (!provider || !provider._registryConfigForBartocApiConfig) {
2683
- continue;
2684
- }
2685
- const providerName = provider.providerName;
2686
- config.scheme = scheme;
2687
- config = providers[providerName]._registryConfigForBartocApiConfig(config);
2688
- if (!config) {
2689
- continue;
2690
- }
2691
- config.provider = providerName;
2692
- try {
2693
- registry = this.initializeRegistry(config);
2694
- return registry;
2695
- } catch (error) {
2696
- continue;
2745
+ const url = config.url;
2746
+ if (registryCache[url]) {
2747
+ const registry2 = registryCache[url];
2748
+ if (Array.isArray(registry2._jskos.schemes) && !import_jskos_tools10.default.isContainedIn(scheme, registry2._jskos.schemes)) {
2749
+ registry2._jskos.schemes.push(scheme);
2750
+ }
2751
+ return registry2;
2752
+ } else {
2753
+ const provider = Object.values(providers).find((p) => p.providerType === type);
2754
+ if (!provider || !provider._registryConfigForBartocApiConfig) {
2755
+ continue;
2756
+ }
2757
+ const providerName = provider.providerName;
2758
+ config.scheme = scheme;
2759
+ config = providers[providerName]._registryConfigForBartocApiConfig(config);
2760
+ if (!config) {
2761
+ continue;
2762
+ }
2763
+ config.provider = providerName;
2764
+ try {
2765
+ registry = this.initializeRegistry(config);
2766
+ if (registry) {
2767
+ registryCache[url] = registry;
2768
+ return registry;
2769
+ }
2770
+ } catch (error) {
2771
+ continue;
2772
+ }
2697
2773
  }
2698
2774
  }
2699
2775
  return null;