cocoda-sdk 2.0.13 → 3.0.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.
@@ -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,
@@ -562,6 +578,9 @@ var BaseProvider = class {
562
578
  return import_jskos_tools.default.isContainedIn(scheme, schemes);
563
579
  }
564
580
  adjustConcept(concept) {
581
+ if (!concept || concept.__SAVED__) {
582
+ return concept;
583
+ }
565
584
  concept._getNarrower = (config) => {
566
585
  return this.getNarrower({ ...config, concept });
567
586
  };
@@ -586,7 +605,20 @@ var BaseProvider = class {
586
605
  return registries;
587
606
  }
588
607
  adjustScheme(scheme) {
589
- scheme._registry = this.cdk && this.cdk.registryForScheme(scheme) || this;
608
+ if (!scheme || scheme.__SAVED__) {
609
+ return scheme;
610
+ }
611
+ const previousRegistry = scheme._registry;
612
+ scheme._registry = this.cdk && this.cdk.registryForScheme(scheme);
613
+ if (!scheme._registry || previousRegistry === scheme._registry) {
614
+ scheme._registry = previousRegistry || this;
615
+ } else {
616
+ ["concepts", "topConcepts"].forEach((key) => {
617
+ if (Array.isArray(scheme[key]) && (scheme[key].length === 0 || scheme[key][0] === null)) {
618
+ delete scheme[key];
619
+ }
620
+ });
621
+ }
590
622
  if (scheme._registry) {
591
623
  scheme._getTop = (config) => {
592
624
  return scheme._registry.getTop({ ...config, scheme });
@@ -673,13 +705,18 @@ var import_localforage = __toESM(require("localforage"), 1);
673
705
  var import_uuid = require("uuid");
674
706
  var uriPrefix = "urn:uuid:";
675
707
  var LocalMappingsProvider = class extends BaseProvider {
676
- _setup() {
708
+ _prepare() {
677
709
  this.has.mappings = {
678
710
  read: true,
679
711
  create: true,
680
712
  update: true,
681
713
  delete: true
682
714
  };
715
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
716
+ this.has[c] = false;
717
+ });
718
+ }
719
+ _setup() {
683
720
  this.queue = [];
684
721
  this.localStorageKey = "cocoda-mappings--" + this._path;
685
722
  let oldLocalStorageKey = "mappings";
@@ -1007,6 +1044,12 @@ var MappingsApiProvider = class extends BaseProvider {
1007
1044
  if (this._api.api && this._api.status === void 0) {
1008
1045
  this._api.status = concatUrl(this._api.api, "/status");
1009
1046
  }
1047
+ this.has.mappings = true;
1048
+ this.has.concordances = true;
1049
+ this.has.annotations = true;
1050
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
1051
+ this.has[c] = false;
1052
+ });
1010
1053
  }
1011
1054
  _setup() {
1012
1055
  if (this._api.api) {
@@ -1262,11 +1305,14 @@ MappingsApiProvider.stored = true;
1262
1305
  // src/providers/occurrences-api-provider.js
1263
1306
  var import_jskos_tools4 = __toESM(require("jskos-tools"), 1);
1264
1307
  var OccurrencesApiProvider = class extends BaseProvider {
1265
- _setup() {
1308
+ _prepare() {
1266
1309
  this._cache = [];
1267
1310
  this._occurrencesSupportedSchemes = [];
1268
1311
  this.has.occurrences = true;
1269
1312
  this.has.mappings = true;
1313
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
1314
+ this.has[c] = false;
1315
+ });
1270
1316
  }
1271
1317
  async _occurrencesIsSupported(scheme) {
1272
1318
  if (this._occurrencesSupportedSchemes && this._occurrencesSupportedSchemes.length) {
@@ -1434,6 +1480,9 @@ var ConceptApiProvider = class extends BaseProvider {
1434
1480
  this.has.suggest = true;
1435
1481
  this.has.search = true;
1436
1482
  this.has.auth = true;
1483
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
1484
+ this.has[c] = false;
1485
+ });
1437
1486
  }
1438
1487
  _setup() {
1439
1488
  if (this._api.api) {
@@ -1455,6 +1504,9 @@ var ConceptApiProvider = class extends BaseProvider {
1455
1504
  }
1456
1505
  }
1457
1506
  this.has.schemes = !!this._api.schemes;
1507
+ if (!this.has.schemes && Array.isArray(this.schemes)) {
1508
+ this.has.schemes = true;
1509
+ }
1458
1510
  this.has.top = !!this._api.top;
1459
1511
  this.has.data = !!this._api.data;
1460
1512
  this.has.concepts = !!this._api.concepts || this.has.data;
@@ -1465,15 +1517,16 @@ var ConceptApiProvider = class extends BaseProvider {
1465
1517
  this.has.search = !!this._api.search;
1466
1518
  this.has.auth = import_get.default(this._config, "auth.key") != null;
1467
1519
  this._defaultParams = {
1468
- properties: "uri,prefLabel,notation,inScheme"
1520
+ properties: "+created,issued,modified,editorialNote,scopeNote"
1469
1521
  };
1470
1522
  }
1471
- static _registryConfigForBartocApiConfig({ url } = {}) {
1472
- if (!url) {
1523
+ static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
1524
+ if (!url || !scheme) {
1473
1525
  return null;
1474
1526
  }
1475
1527
  return {
1476
- api: url
1528
+ api: url,
1529
+ schemes: [scheme]
1477
1530
  };
1478
1531
  }
1479
1532
  async _getSchemeUri(scheme) {
@@ -1486,7 +1539,9 @@ var ConceptApiProvider = class extends BaseProvider {
1486
1539
  if (this._rejectedSchemes.find((s) => import_jskos_tools5.default.compare(scheme, s))) {
1487
1540
  return null;
1488
1541
  }
1489
- const schemes = await this.getSchemes({ uri: import_jskos_tools5.default.getAllUris(scheme) });
1542
+ const schemes = await this.getSchemes({ params: {
1543
+ uri: import_jskos_tools5.default.getAllUris(scheme).join("|")
1544
+ } });
1490
1545
  const resultScheme = schemes.find((s) => import_jskos_tools5.default.compare(s, scheme));
1491
1546
  if (resultScheme) {
1492
1547
  this._approvedSchemes.push({
@@ -1504,11 +1559,11 @@ var ConceptApiProvider = class extends BaseProvider {
1504
1559
  }
1505
1560
  async getSchemes(config) {
1506
1561
  if (!this._api.schemes) {
1562
+ if (Array.isArray(this.schemes)) {
1563
+ return this.schemes;
1564
+ }
1507
1565
  throw new MissingApiUrlError();
1508
1566
  }
1509
- if (Array.isArray(this._api.schemes)) {
1510
- return this._api.schemes;
1511
- }
1512
1567
  const schemes = await this.axios({
1513
1568
  ...config,
1514
1569
  method: "get",
@@ -1519,8 +1574,8 @@ var ConceptApiProvider = class extends BaseProvider {
1519
1574
  ...config.params || {}
1520
1575
  }
1521
1576
  });
1522
- if (Array.isArray(this._jskos.schemes)) {
1523
- return withCustomProps(schemes.filter((s) => import_jskos_tools5.default.isContainedIn(s, this._jskos.schemes)), schemes);
1577
+ if (Array.isArray(this.schemes)) {
1578
+ return withCustomProps(schemes.filter((s) => import_jskos_tools5.default.isContainedIn(s, this.schemes)), schemes);
1524
1579
  } else {
1525
1580
  return schemes;
1526
1581
  }
@@ -1552,7 +1607,7 @@ var ConceptApiProvider = class extends BaseProvider {
1552
1607
  });
1553
1608
  }
1554
1609
  async getConcepts({ concepts, ...config }) {
1555
- if (!this.has.data) {
1610
+ if (this.has.data === false) {
1556
1611
  throw new MissingApiUrlError();
1557
1612
  }
1558
1613
  if (!concepts) {
@@ -1612,26 +1667,24 @@ var ConceptApiProvider = class extends BaseProvider {
1612
1667
  }
1613
1668
  });
1614
1669
  }
1615
- async suggest({ scheme, use = "notation,label", types = [], sort = "score", ...config }) {
1670
+ async suggest({ use = "notation,label", types = [], sort = "score", ...config }) {
1616
1671
  return this._search({
1617
1672
  ...config,
1618
1673
  endpoint: "suggest",
1619
1674
  params: {
1620
1675
  ...config.params,
1621
- voc: import_get.default(scheme, "uri", ""),
1622
1676
  type: types.join("|"),
1623
1677
  use,
1624
1678
  sort
1625
1679
  }
1626
1680
  });
1627
1681
  }
1628
- async search({ scheme, types = [], ...config }) {
1682
+ async search({ types = [], ...config }) {
1629
1683
  return this._search({
1630
1684
  ...config,
1631
1685
  endpoint: "search",
1632
1686
  params: {
1633
1687
  ...config.params,
1634
- voc: import_get.default(scheme, "uri", ""),
1635
1688
  type: types.join("|")
1636
1689
  }
1637
1690
  });
@@ -1653,7 +1706,7 @@ var ConceptApiProvider = class extends BaseProvider {
1653
1706
  endpoint: "voc-search"
1654
1707
  });
1655
1708
  }
1656
- async _search({ endpoint, search, limit, offset, params, ...config }) {
1709
+ async _search({ endpoint, scheme, search, limit, offset, params, ...config }) {
1657
1710
  let url = this._api[endpoint];
1658
1711
  if (!url) {
1659
1712
  throw new MissingApiUrlError();
@@ -1663,6 +1716,7 @@ var ConceptApiProvider = class extends BaseProvider {
1663
1716
  }
1664
1717
  limit = limit || this._jskos.suggestResultLimit || 100;
1665
1718
  offset = offset || 0;
1719
+ const voc = scheme && await this._getSchemeUri(scheme);
1666
1720
  url = url.replace("{searchTerms}", search);
1667
1721
  return this.axios({
1668
1722
  ...config,
@@ -1673,7 +1727,8 @@ var ConceptApiProvider = class extends BaseProvider {
1673
1727
  count: limit,
1674
1728
  offset,
1675
1729
  search,
1676
- query: search
1730
+ query: search,
1731
+ voc
1677
1732
  },
1678
1733
  method: "get",
1679
1734
  url
@@ -1703,9 +1758,12 @@ ConceptApiProvider.providerType = "http://bartoc.org/api-type/jskos";
1703
1758
  // src/providers/reconciliation-api-provider.js
1704
1759
  var import_jskos_tools6 = __toESM(require("jskos-tools"), 1);
1705
1760
  var ReconciliationApiProvider = class extends BaseProvider {
1706
- _setup() {
1707
- this.has.mappings = true;
1761
+ _prepare() {
1708
1762
  this._cache = [];
1763
+ this.has.mappings = true;
1764
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
1765
+ this.has[c] = false;
1766
+ });
1709
1767
  }
1710
1768
  async getMappings({ from, to, mode, ...config }) {
1711
1769
  let schemes = [];
@@ -1839,9 +1897,12 @@ ReconciliationApiProvider.stored = false;
1839
1897
  // src/providers/label-search-suggestion-provider.js
1840
1898
  var import_jskos_tools7 = __toESM(require("jskos-tools"), 1);
1841
1899
  var LabelSearchSuggestionProvider = class extends BaseProvider {
1842
- _setup() {
1900
+ _prepare() {
1843
1901
  this._cache = [];
1844
1902
  this.has.mappings = true;
1903
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
1904
+ this.has[c] = false;
1905
+ });
1845
1906
  }
1846
1907
  supportsScheme(scheme) {
1847
1908
  return import_get.default(scheme, "_registry.has.search", false);
@@ -1890,6 +1951,8 @@ var LabelSearchSuggestionProvider = class extends BaseProvider {
1890
1951
  if (!label) {
1891
1952
  return [];
1892
1953
  }
1954
+ const regexResult = /^[\s\wäüöÄÜÖß]*\w/.exec(label);
1955
+ label = regexResult ? regexResult[0] : label;
1893
1956
  const results = await this._getResults({ ...config, label, targetScheme, limit });
1894
1957
  let mappings = results.map((result) => ({
1895
1958
  fromScheme: sourceScheme,
@@ -1914,7 +1977,7 @@ var LabelSearchSuggestionProvider = class extends BaseProvider {
1914
1977
  return resultsFromCache;
1915
1978
  }
1916
1979
  const registry = import_get.default(targetScheme, "_registry");
1917
- if (!registry || !registry.has.search) {
1980
+ if (!registry || registry.has.search === false) {
1918
1981
  return [];
1919
1982
  }
1920
1983
  const data = await registry.search({
@@ -1937,7 +2000,7 @@ LabelSearchSuggestionProvider.stored = false;
1937
2000
  // src/providers/skosmos-api-provider.js
1938
2001
  var import_jskos_tools8 = __toESM(require("jskos-tools"), 1);
1939
2002
  var SkosmosApiProvider = class extends BaseProvider {
1940
- _setup() {
2003
+ _prepare() {
1941
2004
  this.has.schemes = true;
1942
2005
  this.has.top = true;
1943
2006
  this.has.data = true;
@@ -1947,6 +2010,9 @@ var SkosmosApiProvider = class extends BaseProvider {
1947
2010
  this.has.types = true;
1948
2011
  this.has.suggest = true;
1949
2012
  this.has.search = true;
2013
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
2014
+ this.has[c] = false;
2015
+ });
1950
2016
  }
1951
2017
  static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
1952
2018
  if (!url || !scheme) {
@@ -2343,7 +2409,7 @@ function madsToJskosConcept(data, { scheme }) {
2343
2409
  return concept;
2344
2410
  }
2345
2411
  var LocApiProvider = class extends BaseProvider {
2346
- _setup() {
2412
+ _prepare() {
2347
2413
  this.has.schemes = true;
2348
2414
  this.has.top = false;
2349
2415
  this.has.data = true;
@@ -2352,6 +2418,9 @@ var LocApiProvider = class extends BaseProvider {
2352
2418
  this.has.ancestors = false;
2353
2419
  this.has.suggest = true;
2354
2420
  this.has.search = true;
2421
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
2422
+ this.has[c] = false;
2423
+ });
2355
2424
  }
2356
2425
  static _registryConfigForBartocApiConfig({ scheme } = {}) {
2357
2426
  if (!scheme || !supportedSchemes.find((s) => import_jskos_tools9.default.compare(s, scheme))) {
@@ -2467,6 +2536,7 @@ var providers = {
2467
2536
  };
2468
2537
  providers.addProvider(ConceptApiProvider);
2469
2538
  providers.addProvider(MappingsApiProvider);
2539
+ var registryCache = {};
2470
2540
  var CocodaSDK = class {
2471
2541
  constructor(config) {
2472
2542
  this.config = config;
@@ -2619,9 +2689,10 @@ var CocodaSDK = class {
2619
2689
  async getSchemes(config = {}) {
2620
2690
  let schemes = [], promises = [];
2621
2691
  for (let registry of this.config.registries) {
2622
- if (registry.has.schemes) {
2692
+ if (registry.has.schemes !== false) {
2623
2693
  let promise = registry.getSchemes(config).then((results) => {
2624
2694
  for (let scheme of results) {
2695
+ const currentSchemeRegistry = scheme._registry;
2625
2696
  scheme.__DETAILSLOADED__ = 1;
2626
2697
  scheme.type = scheme.type || ["http://www.w3.org/2004/02/skos/core#ConceptScheme"];
2627
2698
  let otherScheme = schemes.find((s) => import_jskos_tools10.default.compare(s, scheme)), prio, otherPrio, override = false;
@@ -2652,14 +2723,14 @@ var CocodaSDK = class {
2652
2723
  }
2653
2724
  scheme = import_jskos_tools10.default.merge(scheme, import_omit.default(otherScheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
2654
2725
  }
2655
- scheme._registry = registry;
2726
+ scheme._registry = currentSchemeRegistry;
2656
2727
  schemes.push(scheme);
2657
2728
  } else {
2658
- let index = schemes.findIndex((s) => import_jskos_tools10.default.compare(s, scheme));
2729
+ const index = schemes.findIndex((s) => import_jskos_tools10.default.compare(s, scheme));
2659
2730
  if (index != -1) {
2660
- let registry2 = schemes[index]._registry;
2731
+ const otherSchemeRegistry = schemes[index]._registry;
2661
2732
  schemes[index] = import_jskos_tools10.default.merge(schemes[index], import_omit.default(scheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
2662
- schemes[index]._registry = registry2;
2733
+ schemes[index]._registry = otherSchemeRegistry;
2663
2734
  }
2664
2735
  }
2665
2736
  }
@@ -2678,22 +2749,34 @@ var CocodaSDK = class {
2678
2749
  return registry;
2679
2750
  }
2680
2751
  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;
2752
+ const url = config.url;
2753
+ if (registryCache[url]) {
2754
+ const registry2 = registryCache[url];
2755
+ if (Array.isArray(registry2._jskos.schemes) && !import_jskos_tools10.default.isContainedIn(scheme, registry2._jskos.schemes)) {
2756
+ registry2._jskos.schemes.push(scheme);
2757
+ }
2758
+ return registry2;
2759
+ } else {
2760
+ const provider = Object.values(providers).find((p) => p.providerType === type);
2761
+ if (!provider || !provider._registryConfigForBartocApiConfig) {
2762
+ continue;
2763
+ }
2764
+ const providerName = provider.providerName;
2765
+ config.scheme = scheme;
2766
+ config = providers[providerName]._registryConfigForBartocApiConfig(config);
2767
+ if (!config) {
2768
+ continue;
2769
+ }
2770
+ config.provider = providerName;
2771
+ try {
2772
+ registry = this.initializeRegistry(config);
2773
+ if (registry) {
2774
+ registryCache[url] = registry;
2775
+ return registry;
2776
+ }
2777
+ } catch (error) {
2778
+ continue;
2779
+ }
2697
2780
  }
2698
2781
  }
2699
2782
  return null;