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.
@@ -257,9 +257,9 @@ class BaseProvider {
257
257
  if (options.auth && this._auth.key != _.get(this._config, "auth.key")) {
258
258
  return false;
259
259
  }
260
+ const userUris = [user.uri].concat(Object.values(user.identities || {}).map((id) => id.uri)).filter((uri) => uri != null);
260
261
  if (options.auth && options.identities) {
261
- const uris = [user.uri].concat(Object.values(user.identities || {}).map((id) => id.uri)).filter((uri) => uri != null);
262
- if (_.intersection(uris, options.identities).length == 0) {
262
+ if (_.intersection(userUris, options.identities).length == 0) {
263
263
  return false;
264
264
  }
265
265
  }
@@ -270,7 +270,7 @@ class BaseProvider {
270
270
  }
271
271
  }
272
272
  if (crossUser) {
273
- return !!options.crossUser;
273
+ return options.crossUser === true || _.intersection(options.crossUser || [], userUris).length > 0;
274
274
  }
275
275
  return !!this.has[type][action];
276
276
  }
@@ -94,20 +94,22 @@ class LocApiProvider extends BaseProvider {
94
94
  }
95
95
  async getSchemes() {
96
96
  const schemes = [];
97
- for (let scheme of await Promise.all(supportedSchemes.filter((s) => !this.schemes || !this.schemes.length || this.schemes.find((s2) => jskos.compare(s, s2))).map((s) => axios({
98
- method: "get",
99
- url: `${s.uri.replace("http:", "https:")}.json`
100
- }).then(({ status, data }) => {
101
- if (status === 200) {
102
- let scheme2 = data.find((d) => s.uri === d["@id"]);
103
- if (scheme2) {
104
- scheme2 = jskos.merge(madsToJskosScheme(scheme2), s);
105
- scheme2.topConcepts = (scheme2.topConcepts || []).filter((c) => c);
106
- return scheme2;
97
+ for (let scheme of await Promise.all(
98
+ supportedSchemes.filter((s) => !this.schemes || !this.schemes.length || this.schemes.find((s2) => jskos.compare(s, s2))).map((s) => axios({
99
+ method: "get",
100
+ url: `${s.uri.replace("http:", "https:")}.json`
101
+ }).then(({ status, data }) => {
102
+ if (status === 200) {
103
+ let scheme2 = data.find((d) => s.uri === d["@id"]);
104
+ if (scheme2) {
105
+ scheme2 = jskos.merge(madsToJskosScheme(scheme2), s);
106
+ scheme2.topConcepts = (scheme2.topConcepts || []).filter((c) => c);
107
+ return scheme2;
108
+ }
107
109
  }
108
- }
109
- return null;
110
- })))) {
110
+ return null;
111
+ }))
112
+ )) {
111
113
  if (scheme) {
112
114
  schemes.push(scheme);
113
115
  }
@@ -47,9 +47,11 @@ class LocalMappingsProvider extends BaseProvider {
47
47
  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.`);
48
48
  }
49
49
  });
50
- this.queue.push(addUris().catch((error) => {
51
- console.warn("Error when adding URIs to local mappings:", error);
52
- }));
50
+ this.queue.push(
51
+ addUris().catch((error) => {
52
+ console.warn("Error when adding URIs to local mappings:", error);
53
+ })
54
+ );
53
55
  }
54
56
  isAuthorizedFor({ type, action }) {
55
57
  if (type == "mappings" && action != "anonymous") {
@@ -137,10 +139,10 @@ class LocalMappingsProvider extends BaseProvider {
137
139
  let checkConcept = (concept, param) => concept.uri == param || param && concept.notation && concept.notation[0].toLowerCase() == param.toLowerCase();
138
140
  if (params.from || params.to) {
139
141
  mappings = mappings.filter((mapping) => {
140
- let fromInFrom = jskos.conceptsOfMapping(mapping, "from").find((concept) => checkConcept(concept, params.from)) != null;
141
- let fromInTo = jskos.conceptsOfMapping(mapping, "to").find((concept) => checkConcept(concept, params.from)) != null;
142
- let toInFrom = jskos.conceptsOfMapping(mapping, "from").find((concept) => checkConcept(concept, params.to)) != null;
143
- let toInTo = jskos.conceptsOfMapping(mapping, "to").find((concept) => checkConcept(concept, params.to)) != null;
142
+ let fromInFrom = null != jskos.conceptsOfMapping(mapping, "from").find((concept) => checkConcept(concept, params.from));
143
+ let fromInTo = null != jskos.conceptsOfMapping(mapping, "to").find((concept) => checkConcept(concept, params.from));
144
+ let toInFrom = null != jskos.conceptsOfMapping(mapping, "from").find((concept) => checkConcept(concept, params.to));
145
+ let toInTo = null != jskos.conceptsOfMapping(mapping, "to").find((concept) => checkConcept(concept, params.to));
144
146
  if (params.direction == "backward") {
145
147
  if (params.mode == "or") {
146
148
  return params.from && fromInTo || params.to && toInFrom;
@@ -36,8 +36,10 @@ class OccurrencesApiProvider extends BaseProvider {
36
36
  }
37
37
  async getMappings(config) {
38
38
  const occurrences = await this.getOccurrences(config);
39
- const fromScheme = _.get(config, "from.inScheme[0]") || config.fromScheme;
40
- const toScheme = _.get(config, "to.inScheme[0]") || config.toScheme;
39
+ const from = config.from;
40
+ const fromScheme = _.get(from, "inScheme[0]") || config.fromScheme;
41
+ const to = config.to;
42
+ const toScheme = _.get(to, "inScheme[0]") || config.toScheme;
41
43
  const mappings = [];
42
44
  for (let occurrence of occurrences) {
43
45
  if (!occurrence) {
@@ -58,7 +60,7 @@ class OccurrencesApiProvider extends BaseProvider {
58
60
  mapping.to = { memberSet: [] };
59
61
  }
60
62
  mapping.toScheme = _.get(occurrence, "memberSet[1].inScheme[0]");
61
- if (fromScheme && mapping.fromScheme && !jskos.compare(mapping.fromScheme, fromScheme) || toScheme && mapping.toScheme && !jskos.compare(mapping.toScheme, toScheme)) {
63
+ if (from && jskos.compare(from, _.get(mapping, "to.memberSet[0]")) || to && jskos.compare(to, _.get(mapping, "from.memberSet[0]"))) {
62
64
  [mapping.from, mapping.fromScheme, mapping.to, mapping.toScheme] = [mapping.to, mapping.toScheme, mapping.from, mapping.fromScheme];
63
65
  }
64
66
  if (!mapping.fromScheme && fromScheme) {
@@ -70,14 +72,12 @@ class OccurrencesApiProvider extends BaseProvider {
70
72
  mapping.type = [jskos.defaultMappingType.uri];
71
73
  mapping._occurrence = occurrence;
72
74
  mapping = jskos.addMappingIdentifiers(mapping);
73
- if (occurrence.database) {
74
- mapping.creator = [occurrence.database];
75
- }
76
75
  mappings.push(mapping);
77
76
  }
77
+ mappings._url = occurrences._url;
78
78
  return mappings;
79
79
  }
80
- async getOccurrences({ from, to, concepts, ...config }) {
80
+ async getOccurrences({ from, to, concepts, threshold = 0, ...config }) {
81
81
  let promises = [];
82
82
  concepts = (concepts || []).concat([from, to]).filter((c) => !!c);
83
83
  for (let concept of concepts) {
@@ -101,17 +101,7 @@ class OccurrencesApiProvider extends BaseProvider {
101
101
  params: {
102
102
  member: uri,
103
103
  scheme: "*",
104
- threshold: 5
105
- }
106
- }));
107
- }
108
- if (uris.length > 1) {
109
- let urisString = uris.join(" ");
110
- promises.push(this._getOccurrences({
111
- ...config,
112
- params: {
113
- member: urisString,
114
- threshold: 5
104
+ threshold
115
105
  }
116
106
  }));
117
107
  }
@@ -135,7 +125,9 @@ class OccurrencesApiProvider extends BaseProvider {
135
125
  delete occurrences[value];
136
126
  });
137
127
  occurrences = occurrences.filter((o) => o != null);
138
- return occurrences.sort((a, b) => parseInt(b.count || 0) - parseInt(a.count || 0));
128
+ occurrences = occurrences.sort((a, b) => parseInt(b.count || 0) - parseInt(a.count || 0));
129
+ occurrences._url = results.map((result) => result._url);
130
+ return occurrences;
139
131
  }
140
132
  async _getOccurrences(config) {
141
133
  let resultsFromCache = this._cache.find((item) => {
@@ -5,9 +5,12 @@ import { listOfCapabilities } from "../utils/index.js";
5
5
  import jskos from "jskos-tools";
6
6
  import FlexSearch from "flexsearch";
7
7
  function decodeUnicode(text) {
8
- return text.replace(/\\u[\dA-F]{4}/gi, function(match) {
9
- return String.fromCharCode(parseInt(match.replace(/\\u/g, ""), 16));
10
- });
8
+ return text.replace(
9
+ /\\u[\dA-F]{4}/gi,
10
+ function(match) {
11
+ return String.fromCharCode(parseInt(match.replace(/\\u/g, ""), 16));
12
+ }
13
+ );
11
14
  }
12
15
  class SkohubProvider extends BaseProvider {
13
16
  _prepare() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cocoda-sdk",
3
- "version": "3.2.1",
3
+ "version": "3.2.3",
4
4
  "description": "SDK for Cocoda",
5
5
  "main": "dist/cjs/index.cjs",
6
6
  "module": "dist/esm/index.js",
@@ -52,14 +52,14 @@
52
52
  },
53
53
  "homepage": "https://github.com/gbv/cocoda-sdk#readme",
54
54
  "devDependencies": {
55
- "axios-mock-adapter": "^1.21.1",
55
+ "axios-mock-adapter": "^1.21.2",
56
56
  "better-docs": "^2.7.2",
57
- "esbuild": "~0.14.43",
57
+ "esbuild": "~0.14.54",
58
58
  "esbuild-plugin-ifdef": "^1.0.1",
59
- "eslint": "^8.17.0",
59
+ "eslint": "^8.23.1",
60
60
  "eslint-config-gbv": "^1.0.3",
61
61
  "glob": "^8.0.3",
62
- "jsdoc": "^3.6.10",
62
+ "jsdoc": "^3.6.11",
63
63
  "license-checker": "^25.0.1",
64
64
  "lint-staged": "^12.5.0",
65
65
  "mocha": "^9.2.2",
@@ -72,6 +72,6 @@
72
72
  "jskos-tools": "^1.0.26",
73
73
  "localforage": "^1.10.0",
74
74
  "lodash": "^4.17.21",
75
- "uuid": "^8.3.2"
75
+ "uuid": "^9.0.0"
76
76
  }
77
77
  }