cocoda-sdk 3.2.1 → 3.2.3

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
@@ -548,9 +551,9 @@ var BaseProvider = class {
548
551
  if (options.auth && this._auth.key != import_get.default(this._config, "auth.key")) {
549
552
  return false;
550
553
  }
554
+ const userUris = [user.uri].concat(Object.values(user.identities || {}).map((id) => id.uri)).filter((uri) => uri != null);
551
555
  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) {
556
+ if (import_intersection.default(userUris, options.identities).length == 0) {
554
557
  return false;
555
558
  }
556
559
  }
@@ -561,7 +564,7 @@ var BaseProvider = class {
561
564
  }
562
565
  }
563
566
  if (crossUser) {
564
- return !!options.crossUser;
567
+ return options.crossUser === true || import_intersection.default(options.crossUser || [], userUris).length > 0;
565
568
  }
566
569
  return !!this.has[type][action];
567
570
  }
@@ -743,9 +746,11 @@ var LocalMappingsProvider = class extends BaseProvider {
743
746
  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
747
  }
745
748
  });
746
- this.queue.push(addUris().catch((error) => {
747
- console.warn("Error when adding URIs to local mappings:", error);
748
- }));
749
+ this.queue.push(
750
+ addUris().catch((error) => {
751
+ console.warn("Error when adding URIs to local mappings:", error);
752
+ })
753
+ );
749
754
  }
750
755
  isAuthorizedFor({ type, action }) {
751
756
  if (type == "mappings" && action != "anonymous") {
@@ -833,10 +838,10 @@ var LocalMappingsProvider = class extends BaseProvider {
833
838
  let checkConcept = (concept, param) => concept.uri == param || param && concept.notation && concept.notation[0].toLowerCase() == param.toLowerCase();
834
839
  if (params.from || params.to) {
835
840
  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;
841
+ let fromInFrom = null != import_jskos_tools2.default.conceptsOfMapping(mapping, "from").find((concept) => checkConcept(concept, params.from));
842
+ let fromInTo = null != import_jskos_tools2.default.conceptsOfMapping(mapping, "to").find((concept) => checkConcept(concept, params.from));
843
+ let toInFrom = null != import_jskos_tools2.default.conceptsOfMapping(mapping, "from").find((concept) => checkConcept(concept, params.to));
844
+ let toInTo = null != import_jskos_tools2.default.conceptsOfMapping(mapping, "to").find((concept) => checkConcept(concept, params.to));
840
845
  if (params.direction == "backward") {
841
846
  if (params.mode == "or") {
842
847
  return params.from && fromInTo || params.to && toInFrom;
@@ -1419,8 +1424,10 @@ var OccurrencesApiProvider = class extends BaseProvider {
1419
1424
  }
1420
1425
  async getMappings(config) {
1421
1426
  const occurrences = await this.getOccurrences(config);
1422
- const fromScheme = import_get.default(config, "from.inScheme[0]") || config.fromScheme;
1423
- const toScheme = import_get.default(config, "to.inScheme[0]") || config.toScheme;
1427
+ const from = config.from;
1428
+ const fromScheme = import_get.default(from, "inScheme[0]") || config.fromScheme;
1429
+ const to = config.to;
1430
+ const toScheme = import_get.default(to, "inScheme[0]") || config.toScheme;
1424
1431
  const mappings = [];
1425
1432
  for (let occurrence of occurrences) {
1426
1433
  if (!occurrence) {
@@ -1441,7 +1448,7 @@ var OccurrencesApiProvider = class extends BaseProvider {
1441
1448
  mapping.to = { memberSet: [] };
1442
1449
  }
1443
1450
  mapping.toScheme = import_get.default(occurrence, "memberSet[1].inScheme[0]");
1444
- if (fromScheme && mapping.fromScheme && !import_jskos_tools4.default.compare(mapping.fromScheme, fromScheme) || toScheme && mapping.toScheme && !import_jskos_tools4.default.compare(mapping.toScheme, toScheme)) {
1451
+ if (from && import_jskos_tools4.default.compare(from, import_get.default(mapping, "to.memberSet[0]")) || to && import_jskos_tools4.default.compare(to, import_get.default(mapping, "from.memberSet[0]"))) {
1445
1452
  [mapping.from, mapping.fromScheme, mapping.to, mapping.toScheme] = [mapping.to, mapping.toScheme, mapping.from, mapping.fromScheme];
1446
1453
  }
1447
1454
  if (!mapping.fromScheme && fromScheme) {
@@ -1453,14 +1460,12 @@ var OccurrencesApiProvider = class extends BaseProvider {
1453
1460
  mapping.type = [import_jskos_tools4.default.defaultMappingType.uri];
1454
1461
  mapping._occurrence = occurrence;
1455
1462
  mapping = import_jskos_tools4.default.addMappingIdentifiers(mapping);
1456
- if (occurrence.database) {
1457
- mapping.creator = [occurrence.database];
1458
- }
1459
1463
  mappings.push(mapping);
1460
1464
  }
1465
+ mappings._url = occurrences._url;
1461
1466
  return mappings;
1462
1467
  }
1463
- async getOccurrences({ from, to, concepts, ...config }) {
1468
+ async getOccurrences({ from, to, concepts, threshold = 0, ...config }) {
1464
1469
  let promises = [];
1465
1470
  concepts = (concepts || []).concat([from, to]).filter((c) => !!c);
1466
1471
  for (let concept of concepts) {
@@ -1484,17 +1489,7 @@ var OccurrencesApiProvider = class extends BaseProvider {
1484
1489
  params: {
1485
1490
  member: uri,
1486
1491
  scheme: "*",
1487
- threshold: 5
1488
- }
1489
- }));
1490
- }
1491
- if (uris.length > 1) {
1492
- let urisString = uris.join(" ");
1493
- promises.push(this._getOccurrences({
1494
- ...config,
1495
- params: {
1496
- member: urisString,
1497
- threshold: 5
1492
+ threshold
1498
1493
  }
1499
1494
  }));
1500
1495
  }
@@ -1518,7 +1513,9 @@ var OccurrencesApiProvider = class extends BaseProvider {
1518
1513
  delete occurrences[value];
1519
1514
  });
1520
1515
  occurrences = occurrences.filter((o) => o != null);
1521
- return occurrences.sort((a, b) => parseInt(b.count || 0) - parseInt(a.count || 0));
1516
+ occurrences = occurrences.sort((a, b) => parseInt(b.count || 0) - parseInt(a.count || 0));
1517
+ occurrences._url = results.map((result) => result._url);
1518
+ return occurrences;
1522
1519
  }
1523
1520
  async _getOccurrences(config) {
1524
1521
  let resultsFromCache = this._cache.find((item) => {
@@ -2514,20 +2511,22 @@ var LocApiProvider = class extends BaseProvider {
2514
2511
  }
2515
2512
  async getSchemes() {
2516
2513
  const schemes = [];
2517
- 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)({
2518
- method: "get",
2519
- url: `${s.uri.replace("http:", "https:")}.json`
2520
- }).then(({ status, data }) => {
2521
- if (status === 200) {
2522
- let scheme2 = data.find((d) => s.uri === d["@id"]);
2523
- if (scheme2) {
2524
- scheme2 = import_jskos_tools9.default.merge(madsToJskosScheme(scheme2), s);
2525
- scheme2.topConcepts = (scheme2.topConcepts || []).filter((c) => c);
2526
- return scheme2;
2514
+ for (let scheme of await Promise.all(
2515
+ 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
+ method: "get",
2517
+ url: `${s.uri.replace("http:", "https:")}.json`
2518
+ }).then(({ status, data }) => {
2519
+ if (status === 200) {
2520
+ let scheme2 = data.find((d) => s.uri === d["@id"]);
2521
+ if (scheme2) {
2522
+ scheme2 = import_jskos_tools9.default.merge(madsToJskosScheme(scheme2), s);
2523
+ scheme2.topConcepts = (scheme2.topConcepts || []).filter((c) => c);
2524
+ return scheme2;
2525
+ }
2527
2526
  }
2528
- }
2529
- return null;
2530
- })))) {
2527
+ return null;
2528
+ }))
2529
+ )) {
2531
2530
  if (scheme) {
2532
2531
  schemes.push(scheme);
2533
2532
  }
@@ -2603,9 +2602,12 @@ LocApiProvider.providerType = "http://bartoc.org/api-type/loc";
2603
2602
  var import_jskos_tools10 = __toESM(require("jskos-tools"), 1);
2604
2603
  var import_flexsearch = __toESM(require("flexsearch"), 1);
2605
2604
  function decodeUnicode(text) {
2606
- return text.replace(/\\u[\dA-F]{4}/gi, function(match) {
2607
- return String.fromCharCode(parseInt(match.replace(/\\u/g, ""), 16));
2608
- });
2605
+ return text.replace(
2606
+ /\\u[\dA-F]{4}/gi,
2607
+ function(match) {
2608
+ return String.fromCharCode(parseInt(match.replace(/\\u/g, ""), 16));
2609
+ }
2610
+ );
2609
2611
  }
2610
2612
  var SkohubProvider = class extends BaseProvider {
2611
2613
  _prepare() {