cocoda-sdk 2.0.13 → 3.0.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.
@@ -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) {
@@ -1465,15 +1507,16 @@ var ConceptApiProvider = class extends BaseProvider {
1465
1507
  this.has.search = !!this._api.search;
1466
1508
  this.has.auth = import_get.default(this._config, "auth.key") != null;
1467
1509
  this._defaultParams = {
1468
- properties: "uri,prefLabel,notation,inScheme"
1510
+ properties: "+created,issued,modified,editorialNote,scopeNote"
1469
1511
  };
1470
1512
  }
1471
- static _registryConfigForBartocApiConfig({ url } = {}) {
1472
- if (!url) {
1513
+ static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
1514
+ if (!url || !scheme) {
1473
1515
  return null;
1474
1516
  }
1475
1517
  return {
1476
- api: url
1518
+ api: url,
1519
+ schemes: [scheme]
1477
1520
  };
1478
1521
  }
1479
1522
  async _getSchemeUri(scheme) {
@@ -1486,7 +1529,9 @@ var ConceptApiProvider = class extends BaseProvider {
1486
1529
  if (this._rejectedSchemes.find((s) => import_jskos_tools5.default.compare(scheme, s))) {
1487
1530
  return null;
1488
1531
  }
1489
- const schemes = await this.getSchemes({ uri: import_jskos_tools5.default.getAllUris(scheme) });
1532
+ const schemes = await this.getSchemes({ params: {
1533
+ uri: import_jskos_tools5.default.getAllUris(scheme).join("|")
1534
+ } });
1490
1535
  const resultScheme = schemes.find((s) => import_jskos_tools5.default.compare(s, scheme));
1491
1536
  if (resultScheme) {
1492
1537
  this._approvedSchemes.push({
@@ -1506,9 +1551,6 @@ var ConceptApiProvider = class extends BaseProvider {
1506
1551
  if (!this._api.schemes) {
1507
1552
  throw new MissingApiUrlError();
1508
1553
  }
1509
- if (Array.isArray(this._api.schemes)) {
1510
- return this._api.schemes;
1511
- }
1512
1554
  const schemes = await this.axios({
1513
1555
  ...config,
1514
1556
  method: "get",
@@ -1519,8 +1561,8 @@ var ConceptApiProvider = class extends BaseProvider {
1519
1561
  ...config.params || {}
1520
1562
  }
1521
1563
  });
1522
- if (Array.isArray(this._jskos.schemes)) {
1523
- return withCustomProps(schemes.filter((s) => import_jskos_tools5.default.isContainedIn(s, this._jskos.schemes)), schemes);
1564
+ if (Array.isArray(this.schemes)) {
1565
+ return withCustomProps(schemes.filter((s) => import_jskos_tools5.default.isContainedIn(s, this.schemes)), schemes);
1524
1566
  } else {
1525
1567
  return schemes;
1526
1568
  }
@@ -1552,7 +1594,7 @@ var ConceptApiProvider = class extends BaseProvider {
1552
1594
  });
1553
1595
  }
1554
1596
  async getConcepts({ concepts, ...config }) {
1555
- if (!this.has.data) {
1597
+ if (this.has.data === false) {
1556
1598
  throw new MissingApiUrlError();
1557
1599
  }
1558
1600
  if (!concepts) {
@@ -1612,26 +1654,24 @@ var ConceptApiProvider = class extends BaseProvider {
1612
1654
  }
1613
1655
  });
1614
1656
  }
1615
- async suggest({ scheme, use = "notation,label", types = [], sort = "score", ...config }) {
1657
+ async suggest({ use = "notation,label", types = [], sort = "score", ...config }) {
1616
1658
  return this._search({
1617
1659
  ...config,
1618
1660
  endpoint: "suggest",
1619
1661
  params: {
1620
1662
  ...config.params,
1621
- voc: import_get.default(scheme, "uri", ""),
1622
1663
  type: types.join("|"),
1623
1664
  use,
1624
1665
  sort
1625
1666
  }
1626
1667
  });
1627
1668
  }
1628
- async search({ scheme, types = [], ...config }) {
1669
+ async search({ types = [], ...config }) {
1629
1670
  return this._search({
1630
1671
  ...config,
1631
1672
  endpoint: "search",
1632
1673
  params: {
1633
1674
  ...config.params,
1634
- voc: import_get.default(scheme, "uri", ""),
1635
1675
  type: types.join("|")
1636
1676
  }
1637
1677
  });
@@ -1653,7 +1693,7 @@ var ConceptApiProvider = class extends BaseProvider {
1653
1693
  endpoint: "voc-search"
1654
1694
  });
1655
1695
  }
1656
- async _search({ endpoint, search, limit, offset, params, ...config }) {
1696
+ async _search({ endpoint, scheme, search, limit, offset, params, ...config }) {
1657
1697
  let url = this._api[endpoint];
1658
1698
  if (!url) {
1659
1699
  throw new MissingApiUrlError();
@@ -1663,6 +1703,7 @@ var ConceptApiProvider = class extends BaseProvider {
1663
1703
  }
1664
1704
  limit = limit || this._jskos.suggestResultLimit || 100;
1665
1705
  offset = offset || 0;
1706
+ const voc = scheme && await this._getSchemeUri(scheme);
1666
1707
  url = url.replace("{searchTerms}", search);
1667
1708
  return this.axios({
1668
1709
  ...config,
@@ -1673,7 +1714,8 @@ var ConceptApiProvider = class extends BaseProvider {
1673
1714
  count: limit,
1674
1715
  offset,
1675
1716
  search,
1676
- query: search
1717
+ query: search,
1718
+ voc
1677
1719
  },
1678
1720
  method: "get",
1679
1721
  url
@@ -1703,9 +1745,12 @@ ConceptApiProvider.providerType = "http://bartoc.org/api-type/jskos";
1703
1745
  // src/providers/reconciliation-api-provider.js
1704
1746
  var import_jskos_tools6 = __toESM(require("jskos-tools"), 1);
1705
1747
  var ReconciliationApiProvider = class extends BaseProvider {
1706
- _setup() {
1707
- this.has.mappings = true;
1748
+ _prepare() {
1708
1749
  this._cache = [];
1750
+ this.has.mappings = true;
1751
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
1752
+ this.has[c] = false;
1753
+ });
1709
1754
  }
1710
1755
  async getMappings({ from, to, mode, ...config }) {
1711
1756
  let schemes = [];
@@ -1839,9 +1884,12 @@ ReconciliationApiProvider.stored = false;
1839
1884
  // src/providers/label-search-suggestion-provider.js
1840
1885
  var import_jskos_tools7 = __toESM(require("jskos-tools"), 1);
1841
1886
  var LabelSearchSuggestionProvider = class extends BaseProvider {
1842
- _setup() {
1887
+ _prepare() {
1843
1888
  this._cache = [];
1844
1889
  this.has.mappings = true;
1890
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
1891
+ this.has[c] = false;
1892
+ });
1845
1893
  }
1846
1894
  supportsScheme(scheme) {
1847
1895
  return import_get.default(scheme, "_registry.has.search", false);
@@ -1890,6 +1938,8 @@ var LabelSearchSuggestionProvider = class extends BaseProvider {
1890
1938
  if (!label) {
1891
1939
  return [];
1892
1940
  }
1941
+ const regexResult = /^[\s\wäüöÄÜÖß]*\w/.exec(label);
1942
+ label = regexResult ? regexResult[0] : label;
1893
1943
  const results = await this._getResults({ ...config, label, targetScheme, limit });
1894
1944
  let mappings = results.map((result) => ({
1895
1945
  fromScheme: sourceScheme,
@@ -1914,7 +1964,7 @@ var LabelSearchSuggestionProvider = class extends BaseProvider {
1914
1964
  return resultsFromCache;
1915
1965
  }
1916
1966
  const registry = import_get.default(targetScheme, "_registry");
1917
- if (!registry || !registry.has.search) {
1967
+ if (!registry || registry.has.search === false) {
1918
1968
  return [];
1919
1969
  }
1920
1970
  const data = await registry.search({
@@ -1937,7 +1987,7 @@ LabelSearchSuggestionProvider.stored = false;
1937
1987
  // src/providers/skosmos-api-provider.js
1938
1988
  var import_jskos_tools8 = __toESM(require("jskos-tools"), 1);
1939
1989
  var SkosmosApiProvider = class extends BaseProvider {
1940
- _setup() {
1990
+ _prepare() {
1941
1991
  this.has.schemes = true;
1942
1992
  this.has.top = true;
1943
1993
  this.has.data = true;
@@ -1947,6 +1997,9 @@ var SkosmosApiProvider = class extends BaseProvider {
1947
1997
  this.has.types = true;
1948
1998
  this.has.suggest = true;
1949
1999
  this.has.search = true;
2000
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
2001
+ this.has[c] = false;
2002
+ });
1950
2003
  }
1951
2004
  static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
1952
2005
  if (!url || !scheme) {
@@ -2343,7 +2396,7 @@ function madsToJskosConcept(data, { scheme }) {
2343
2396
  return concept;
2344
2397
  }
2345
2398
  var LocApiProvider = class extends BaseProvider {
2346
- _setup() {
2399
+ _prepare() {
2347
2400
  this.has.schemes = true;
2348
2401
  this.has.top = false;
2349
2402
  this.has.data = true;
@@ -2352,6 +2405,9 @@ var LocApiProvider = class extends BaseProvider {
2352
2405
  this.has.ancestors = false;
2353
2406
  this.has.suggest = true;
2354
2407
  this.has.search = true;
2408
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
2409
+ this.has[c] = false;
2410
+ });
2355
2411
  }
2356
2412
  static _registryConfigForBartocApiConfig({ scheme } = {}) {
2357
2413
  if (!scheme || !supportedSchemes.find((s) => import_jskos_tools9.default.compare(s, scheme))) {
@@ -2467,6 +2523,7 @@ var providers = {
2467
2523
  };
2468
2524
  providers.addProvider(ConceptApiProvider);
2469
2525
  providers.addProvider(MappingsApiProvider);
2526
+ var registryCache = {};
2470
2527
  var CocodaSDK = class {
2471
2528
  constructor(config) {
2472
2529
  this.config = config;
@@ -2619,9 +2676,10 @@ var CocodaSDK = class {
2619
2676
  async getSchemes(config = {}) {
2620
2677
  let schemes = [], promises = [];
2621
2678
  for (let registry of this.config.registries) {
2622
- if (registry.has.schemes) {
2679
+ if (registry.has.schemes !== false) {
2623
2680
  let promise = registry.getSchemes(config).then((results) => {
2624
2681
  for (let scheme of results) {
2682
+ const currentSchemeRegistry = scheme._registry;
2625
2683
  scheme.__DETAILSLOADED__ = 1;
2626
2684
  scheme.type = scheme.type || ["http://www.w3.org/2004/02/skos/core#ConceptScheme"];
2627
2685
  let otherScheme = schemes.find((s) => import_jskos_tools10.default.compare(s, scheme)), prio, otherPrio, override = false;
@@ -2652,14 +2710,14 @@ var CocodaSDK = class {
2652
2710
  }
2653
2711
  scheme = import_jskos_tools10.default.merge(scheme, import_omit.default(otherScheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
2654
2712
  }
2655
- scheme._registry = registry;
2713
+ scheme._registry = currentSchemeRegistry;
2656
2714
  schemes.push(scheme);
2657
2715
  } else {
2658
- let index = schemes.findIndex((s) => import_jskos_tools10.default.compare(s, scheme));
2716
+ const index = schemes.findIndex((s) => import_jskos_tools10.default.compare(s, scheme));
2659
2717
  if (index != -1) {
2660
- let registry2 = schemes[index]._registry;
2718
+ const otherSchemeRegistry = schemes[index]._registry;
2661
2719
  schemes[index] = import_jskos_tools10.default.merge(schemes[index], import_omit.default(scheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
2662
- schemes[index]._registry = registry2;
2720
+ schemes[index]._registry = otherSchemeRegistry;
2663
2721
  }
2664
2722
  }
2665
2723
  }
@@ -2678,22 +2736,34 @@ var CocodaSDK = class {
2678
2736
  return registry;
2679
2737
  }
2680
2738
  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;
2739
+ const url = config.url;
2740
+ if (registryCache[url]) {
2741
+ const registry2 = registryCache[url];
2742
+ if (Array.isArray(registry2._jskos.schemes) && !import_jskos_tools10.default.isContainedIn(scheme, registry2._jskos.schemes)) {
2743
+ registry2._jskos.schemes.push(scheme);
2744
+ }
2745
+ return registry2;
2746
+ } else {
2747
+ const provider = Object.values(providers).find((p) => p.providerType === type);
2748
+ if (!provider || !provider._registryConfigForBartocApiConfig) {
2749
+ continue;
2750
+ }
2751
+ const providerName = provider.providerName;
2752
+ config.scheme = scheme;
2753
+ config = providers[providerName]._registryConfigForBartocApiConfig(config);
2754
+ if (!config) {
2755
+ continue;
2756
+ }
2757
+ config.provider = providerName;
2758
+ try {
2759
+ registry = this.initializeRegistry(config);
2760
+ if (registry) {
2761
+ registryCache[url] = registry;
2762
+ return registry;
2763
+ }
2764
+ } catch (error) {
2765
+ continue;
2766
+ }
2697
2767
  }
2698
2768
  }
2699
2769
  return null;