cocoda-sdk 3.2.2 → 3.3.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.
- package/README.md +2 -0
- package/dist/cjs/index.cjs +355 -104
- package/dist/cocoda-sdk.js +6 -6
- package/dist/cocoda-sdk.js.LICENSES.txt +1 -1
- package/dist/cocoda-sdk.js.map +4 -4
- package/dist/esm/index.js +3 -1
- package/dist/esm/providers/base-provider.js +4 -4
- package/dist/esm/providers/index.js +2 -0
- package/dist/esm/providers/loc-api-provider.js +15 -13
- package/dist/esm/providers/local-mappings-provider.js +9 -7
- package/dist/esm/providers/mycore-provider.js +216 -0
- package/dist/esm/providers/occurrences-api-provider.js +6 -2
- package/dist/esm/providers/reconciliation-api-provider.js +6 -2
- package/dist/esm/providers/skohub-provider.js +40 -27
- package/package.json +7 -7
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import CocodaSDK from "./lib/CocodaSDK.js";
|
|
2
2
|
import * as errors from "./errors/index.js";
|
|
3
|
+
import * as utils from "./utils/index.js";
|
|
3
4
|
export * from "./providers/index.js";
|
|
4
5
|
const cdk = new CocodaSDK();
|
|
5
6
|
import * as providers from "./providers/index.js";
|
|
@@ -10,5 +11,6 @@ export {
|
|
|
10
11
|
CocodaSDK,
|
|
11
12
|
addAllProviders,
|
|
12
13
|
cdk,
|
|
13
|
-
errors
|
|
14
|
+
errors,
|
|
15
|
+
utils
|
|
14
16
|
};
|
|
@@ -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
|
-
|
|
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
|
|
273
|
+
return options.crossUser === true || _.intersection(options.crossUser || [], userUris).length > 0;
|
|
274
274
|
}
|
|
275
275
|
return !!this.has[type][action];
|
|
276
276
|
}
|
|
@@ -298,7 +298,7 @@ class BaseProvider {
|
|
|
298
298
|
return (await this.getConcepts({ ...config, concepts: [concept] }))[0];
|
|
299
299
|
};
|
|
300
300
|
for (let type of ["broader", "narrower", "ancestors"]) {
|
|
301
|
-
if (Array.isArray(concept[type]) && !concept[type].includes(null)) {
|
|
301
|
+
if (Array.isArray(concept[type]) && concept[type].length && !concept[type].includes(null)) {
|
|
302
302
|
concept[type] = this.adjustConcepts(concept[type]);
|
|
303
303
|
}
|
|
304
304
|
}
|
|
@@ -8,6 +8,7 @@ import LabelSearchSuggestionProvider from "./label-search-suggestion-provider.js
|
|
|
8
8
|
import SkosmosApiProvider from "./skosmos-api-provider.js";
|
|
9
9
|
import LocApiProvider from "./loc-api-provider.js";
|
|
10
10
|
import SkohubProvider from "./skohub-provider.js";
|
|
11
|
+
import MyCoReProvider from "./mycore-provider.js";
|
|
11
12
|
export {
|
|
12
13
|
BaseProvider,
|
|
13
14
|
ConceptApiProvider,
|
|
@@ -15,6 +16,7 @@ export {
|
|
|
15
16
|
LocApiProvider,
|
|
16
17
|
LocalMappingsProvider,
|
|
17
18
|
MappingsApiProvider,
|
|
19
|
+
MyCoReProvider,
|
|
18
20
|
OccurrencesApiProvider,
|
|
19
21
|
ReconciliationApiProvider,
|
|
20
22
|
SkohubProvider,
|
|
@@ -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(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
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(
|
|
51
|
-
|
|
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))
|
|
141
|
-
let fromInTo = jskos.conceptsOfMapping(mapping, "to").find((concept) => checkConcept(concept, params.from))
|
|
142
|
-
let toInFrom = jskos.conceptsOfMapping(mapping, "from").find((concept) => checkConcept(concept, params.to))
|
|
143
|
-
let toInTo = jskos.conceptsOfMapping(mapping, "to").find((concept) => checkConcept(concept, params.to))
|
|
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;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import BaseProvider from "./base-provider.js";
|
|
2
|
+
import * as _ from "../utils/lodash.js";
|
|
3
|
+
import * as errors from "../errors/index.js";
|
|
4
|
+
import { listOfCapabilities } from "../utils/index.js";
|
|
5
|
+
import jskos from "jskos-tools";
|
|
6
|
+
import FlexSearch from "flexsearch";
|
|
7
|
+
const data = {};
|
|
8
|
+
class MyCoReProvider extends BaseProvider {
|
|
9
|
+
_prepare() {
|
|
10
|
+
this.has.schemes = true;
|
|
11
|
+
this.has.top = true;
|
|
12
|
+
this.has.data = true;
|
|
13
|
+
this.has.concepts = true;
|
|
14
|
+
this.has.narrower = true;
|
|
15
|
+
this.has.ancestors = true;
|
|
16
|
+
this.has.suggest = true;
|
|
17
|
+
this.has.search = true;
|
|
18
|
+
listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
|
|
19
|
+
this.has[c] = false;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
_setup() {
|
|
23
|
+
this._scheme = null;
|
|
24
|
+
}
|
|
25
|
+
static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
|
|
26
|
+
if (!url || !scheme) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
api: url
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
_schemeInfoToJSKOS(schemeInfo) {
|
|
34
|
+
const uri = schemeInfo.labels.find((l) => l.lang === "x-uri").text;
|
|
35
|
+
const prefLabel = {};
|
|
36
|
+
schemeInfo.labels.filter((l) => !l.lang.startsWith("x-")).forEach((l) => {
|
|
37
|
+
prefLabel[l.lang] = l.text;
|
|
38
|
+
});
|
|
39
|
+
const scheme = {
|
|
40
|
+
uri,
|
|
41
|
+
prefLabel
|
|
42
|
+
};
|
|
43
|
+
if (schemeInfo.categories && schemeInfo.categories.length) {
|
|
44
|
+
scheme.topConcepts = [null];
|
|
45
|
+
}
|
|
46
|
+
if (schemeInfo.category && schemeInfo.category.length) {
|
|
47
|
+
scheme.concepts = [null];
|
|
48
|
+
}
|
|
49
|
+
return scheme;
|
|
50
|
+
}
|
|
51
|
+
_categoryToJSKOS(category, { scheme, broader = [] }) {
|
|
52
|
+
if (!category || !scheme) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const id = category.ID;
|
|
56
|
+
const uri = `${scheme.uri}/${id}`;
|
|
57
|
+
if (data[scheme.uri].concepts[uri]) {
|
|
58
|
+
return data[scheme.uri].concepts[uri];
|
|
59
|
+
}
|
|
60
|
+
const prefLabel = {};
|
|
61
|
+
category.labels.filter((l) => !l.lang.startsWith("x-") && l.text).forEach((l) => {
|
|
62
|
+
prefLabel[l.lang] = l.text.replace(`${id} `, "");
|
|
63
|
+
data[scheme.uri].searchIndex.add(uri, prefLabel[l.lang]);
|
|
64
|
+
});
|
|
65
|
+
const scopeNote = {};
|
|
66
|
+
category.labels.filter((l) => !l.lang.startsWith("x-") && l.description).forEach((l) => {
|
|
67
|
+
if (!scopeNote[l.lang]) {
|
|
68
|
+
scopeNote[l.lang] = [];
|
|
69
|
+
}
|
|
70
|
+
scopeNote[l.lang].push(l.description);
|
|
71
|
+
});
|
|
72
|
+
data[scheme.uri].concepts[uri] = {
|
|
73
|
+
uri,
|
|
74
|
+
notation: [id],
|
|
75
|
+
prefLabel,
|
|
76
|
+
scopeNote,
|
|
77
|
+
inScheme: [{ uri: scheme.uri }],
|
|
78
|
+
narrower: (category.categories || []).map((c) => ({ uri: `${scheme.uri}/${c.ID}` })),
|
|
79
|
+
broader
|
|
80
|
+
};
|
|
81
|
+
return data[scheme.uri].concepts[uri];
|
|
82
|
+
}
|
|
83
|
+
_removeNarrower(concept) {
|
|
84
|
+
if (!concept)
|
|
85
|
+
return concept;
|
|
86
|
+
return Object.assign({}, concept, { narrower: concept.narrower && concept.narrower.length ? [null] : [] });
|
|
87
|
+
}
|
|
88
|
+
async _loadSchemeData(config) {
|
|
89
|
+
const schemeInfo = await this.axios({
|
|
90
|
+
...config,
|
|
91
|
+
method: "get",
|
|
92
|
+
url: this._api.api,
|
|
93
|
+
_skipAdditionalParameters: true
|
|
94
|
+
});
|
|
95
|
+
this._scheme = this._schemeInfoToJSKOS(schemeInfo);
|
|
96
|
+
const uri = this._scheme.uri;
|
|
97
|
+
data[uri] = {
|
|
98
|
+
schemeInfo,
|
|
99
|
+
searchIndex: FlexSearch.create({
|
|
100
|
+
tokenize: "full"
|
|
101
|
+
}),
|
|
102
|
+
concepts: {}
|
|
103
|
+
};
|
|
104
|
+
const dealWithCategory = (category, { broader = [] } = {}) => {
|
|
105
|
+
const concept = this._categoryToJSKOS(category, { scheme: this._scheme, broader });
|
|
106
|
+
(category.categories || []).forEach((c) => dealWithCategory(c, { broader: [{ uri: concept.uri }] }));
|
|
107
|
+
};
|
|
108
|
+
schemeInfo.categories.forEach((category) => dealWithCategory(category));
|
|
109
|
+
data[uri].topConcepts = schemeInfo.categories.map((category) => this._categoryToJSKOS(category, { scheme: this._scheme }));
|
|
110
|
+
}
|
|
111
|
+
async getSchemes(config = {}) {
|
|
112
|
+
if (!this._api.api) {
|
|
113
|
+
throw new errors.MissingApiUrlError();
|
|
114
|
+
}
|
|
115
|
+
if (!this._scheme) {
|
|
116
|
+
if (!this._loadSchemeDataPromise) {
|
|
117
|
+
this._loadSchemeDataPromise = this._loadSchemeData(config);
|
|
118
|
+
}
|
|
119
|
+
await this._loadSchemeDataPromise;
|
|
120
|
+
}
|
|
121
|
+
return [this._scheme];
|
|
122
|
+
}
|
|
123
|
+
async getTop({ scheme, ...config }) {
|
|
124
|
+
if (!scheme || !scheme.uri) {
|
|
125
|
+
throw new errors.InvalidOrMissingParameterError({ parameter: "scheme", message: "Missing scheme URI" });
|
|
126
|
+
}
|
|
127
|
+
if (!this._scheme) {
|
|
128
|
+
await this.getSchemes(config);
|
|
129
|
+
}
|
|
130
|
+
if (!jskos.compare(scheme, this._scheme)) {
|
|
131
|
+
throw new errors.InvalidOrMissingParameterError({ parameter: "scheme", message: "Requested vocabulary seems to be unsupported by this API." });
|
|
132
|
+
}
|
|
133
|
+
return data[this._scheme.uri].topConcepts.map(this._removeNarrower);
|
|
134
|
+
}
|
|
135
|
+
async getConcepts({ concepts, ...config }) {
|
|
136
|
+
if (!_.isArray(concepts)) {
|
|
137
|
+
concepts = [concepts];
|
|
138
|
+
}
|
|
139
|
+
if (!this._scheme) {
|
|
140
|
+
await this.getSchemes(config);
|
|
141
|
+
}
|
|
142
|
+
return concepts.map((c) => data[this._scheme.uri].concepts[c.uri]).map(this._removeNarrower);
|
|
143
|
+
}
|
|
144
|
+
async getAncestors({ concept, ...config }) {
|
|
145
|
+
if (!concept || !concept.uri) {
|
|
146
|
+
throw new errors.InvalidOrMissingParameterError({ parameter: "concept" });
|
|
147
|
+
}
|
|
148
|
+
if (concept.ancestors && concept.ancestors[0] !== null) {
|
|
149
|
+
return concept.ancestors;
|
|
150
|
+
}
|
|
151
|
+
if (!this._scheme) {
|
|
152
|
+
await this.getSchemes(config);
|
|
153
|
+
}
|
|
154
|
+
concept = data[this._scheme.uri].concepts[concept.uri];
|
|
155
|
+
const broader = concept && concept.broader && concept.broader[0];
|
|
156
|
+
if (!broader) {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
return [broader].concat(await this.getAncestors({ concept: broader, ...config }));
|
|
160
|
+
}
|
|
161
|
+
async getNarrower({ concept, ...config }) {
|
|
162
|
+
if (!concept || !concept.uri) {
|
|
163
|
+
throw new errors.InvalidOrMissingParameterError({ parameter: "concept" });
|
|
164
|
+
}
|
|
165
|
+
if (concept.narrower && concept.narrower[0] !== null) {
|
|
166
|
+
return concept.narrower;
|
|
167
|
+
}
|
|
168
|
+
if (!this._scheme) {
|
|
169
|
+
await this.getSchemes(config);
|
|
170
|
+
}
|
|
171
|
+
concept = data[this._scheme.uri].concepts[concept.uri];
|
|
172
|
+
return (concept && concept.narrower || []).map((c) => data[this._scheme.uri].concepts[c.uri]).map(this._removeNarrower);
|
|
173
|
+
}
|
|
174
|
+
async search({ search, scheme, limit = 100 }) {
|
|
175
|
+
if (!scheme || !scheme.uri) {
|
|
176
|
+
throw new errors.InvalidOrMissingParameterError({ parameter: "scheme" });
|
|
177
|
+
}
|
|
178
|
+
if (!search) {
|
|
179
|
+
throw new errors.InvalidOrMissingParameterError({ parameter: "search" });
|
|
180
|
+
}
|
|
181
|
+
if (!scheme || !scheme.uri) {
|
|
182
|
+
throw new errors.InvalidOrMissingParameterError({ parameter: "scheme", message: "Missing scheme URI" });
|
|
183
|
+
}
|
|
184
|
+
if (!this._scheme) {
|
|
185
|
+
await this.getSchemes();
|
|
186
|
+
}
|
|
187
|
+
if (!jskos.compare(scheme, this._scheme)) {
|
|
188
|
+
throw new errors.InvalidOrMissingParameterError({ parameter: "scheme", message: "Requested vocabulary seems to be unsupported by this API." });
|
|
189
|
+
}
|
|
190
|
+
const result = await data[this._scheme.uri].searchIndex.search(search);
|
|
191
|
+
return result.map((uri) => data[this._scheme.uri].concepts[uri]).map(this._removeNarrower).slice(0, limit);
|
|
192
|
+
}
|
|
193
|
+
async suggest(config) {
|
|
194
|
+
config._raw = true;
|
|
195
|
+
const concepts = await this.search(config);
|
|
196
|
+
const result = [config.search, [], [], []];
|
|
197
|
+
for (let concept of concepts) {
|
|
198
|
+
const notation = jskos.notation(concept);
|
|
199
|
+
const label = jskos.prefLabel(concept);
|
|
200
|
+
result[1].push((notation ? notation + " " : "") + label);
|
|
201
|
+
result[2].push("");
|
|
202
|
+
result[3].push(concept.uri);
|
|
203
|
+
}
|
|
204
|
+
if (concepts._totalCount != void 0) {
|
|
205
|
+
result._totalCount = concepts._totalCount;
|
|
206
|
+
} else {
|
|
207
|
+
result._totalCount = concepts.length;
|
|
208
|
+
}
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
MyCoReProvider.providerName = "MyCoRe";
|
|
213
|
+
MyCoReProvider.providerType = "http://bartoc.org/api-type/mycore";
|
|
214
|
+
export {
|
|
215
|
+
MyCoReProvider as default
|
|
216
|
+
};
|
|
@@ -3,9 +3,13 @@ import jskos from "jskos-tools";
|
|
|
3
3
|
import * as _ from "../utils/lodash.js";
|
|
4
4
|
import * as errors from "../errors/index.js";
|
|
5
5
|
import * as utils from "../utils/index.js";
|
|
6
|
+
const cache = {};
|
|
6
7
|
class OccurrencesApiProvider extends BaseProvider {
|
|
8
|
+
get _cache() {
|
|
9
|
+
return cache[this.uri];
|
|
10
|
+
}
|
|
7
11
|
_prepare() {
|
|
8
|
-
this.
|
|
12
|
+
cache[this.uri] = [];
|
|
9
13
|
this._occurrencesSupportedSchemes = [];
|
|
10
14
|
this.has.occurrences = true;
|
|
11
15
|
this.has.mappings = true;
|
|
@@ -146,7 +150,7 @@ class OccurrencesApiProvider extends BaseProvider {
|
|
|
146
150
|
data
|
|
147
151
|
});
|
|
148
152
|
if (this._cache.length > 20) {
|
|
149
|
-
this.
|
|
153
|
+
cache[this.uri] = this._cache.slice(this._cache.length - 20);
|
|
150
154
|
}
|
|
151
155
|
return data;
|
|
152
156
|
}
|
|
@@ -3,9 +3,13 @@ import jskos from "jskos-tools";
|
|
|
3
3
|
import * as _ from "../utils/lodash.js";
|
|
4
4
|
import * as errors from "../errors/index.js";
|
|
5
5
|
import { listOfCapabilities } from "../utils/index.js";
|
|
6
|
+
const cache = {};
|
|
6
7
|
class ReconciliationApiProvider extends BaseProvider {
|
|
8
|
+
get _cache() {
|
|
9
|
+
return cache[this.uri];
|
|
10
|
+
}
|
|
7
11
|
_prepare() {
|
|
8
|
-
this.
|
|
12
|
+
cache[this.uri] = [];
|
|
9
13
|
this.has.mappings = true;
|
|
10
14
|
listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
|
|
11
15
|
this.has[c] = false;
|
|
@@ -132,7 +136,7 @@ class ReconciliationApiProvider extends BaseProvider {
|
|
|
132
136
|
};
|
|
133
137
|
this._cache.push(newCacheEntry);
|
|
134
138
|
if (this._cache.length > 20) {
|
|
135
|
-
this.
|
|
139
|
+
cache[this.uri] = this._cache.slice(this._cache.length - 20);
|
|
136
140
|
}
|
|
137
141
|
return newCacheEntry;
|
|
138
142
|
}
|
|
@@ -5,10 +5,14 @@ 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(
|
|
9
|
-
|
|
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
|
}
|
|
15
|
+
const data = {};
|
|
12
16
|
class SkohubProvider extends BaseProvider {
|
|
13
17
|
_prepare() {
|
|
14
18
|
this.has.schemes = true;
|
|
@@ -22,11 +26,20 @@ class SkohubProvider extends BaseProvider {
|
|
|
22
26
|
listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
|
|
23
27
|
this.has[c] = false;
|
|
24
28
|
});
|
|
29
|
+
data[this.uri] = {
|
|
30
|
+
index: {},
|
|
31
|
+
conceptCache: {},
|
|
32
|
+
schemeCache: {}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
get _index() {
|
|
36
|
+
return data[this.uri] && data[this.uri].index;
|
|
37
|
+
}
|
|
38
|
+
get _conceptCache() {
|
|
39
|
+
return data[this.uri] && data[this.uri].conceptCache;
|
|
25
40
|
}
|
|
26
|
-
|
|
27
|
-
this.
|
|
28
|
-
this._conceptCache = {};
|
|
29
|
-
this._schemeCache = {};
|
|
41
|
+
get _schemeCache() {
|
|
42
|
+
return data[this.uri] && data[this.uri].schemeCache;
|
|
30
43
|
}
|
|
31
44
|
static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
|
|
32
45
|
if (!url || !scheme) {
|
|
@@ -52,11 +65,11 @@ class SkohubProvider extends BaseProvider {
|
|
|
52
65
|
if (uri.endsWith("/")) {
|
|
53
66
|
postfix = "index.json";
|
|
54
67
|
}
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
68
|
+
const data2 = await this.axios({ ...config, url: `${uri}${postfix}`, _skipAdditionalParameters: true });
|
|
69
|
+
if (data2.id !== uri) {
|
|
57
70
|
throw new errors.InvalidRequestError({ message: "Skohub URL did not return expected concept scheme" });
|
|
58
71
|
}
|
|
59
|
-
const { title, preferredNamespaceUri, hasTopConcept, description } =
|
|
72
|
+
const { title, preferredNamespaceUri, hasTopConcept, description } = data2;
|
|
60
73
|
scheme = { uri, identifier: uris.filter((u) => u !== uri) };
|
|
61
74
|
scheme.prefLabel = title;
|
|
62
75
|
Object.keys(scheme.prefLabel || {}).forEach((key) => {
|
|
@@ -84,33 +97,33 @@ class SkohubProvider extends BaseProvider {
|
|
|
84
97
|
return this._conceptCache[uri];
|
|
85
98
|
}
|
|
86
99
|
try {
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
100
|
+
const data2 = await this.axios({ ...config, url: `${uri}.json`, _skipAdditionalParameters: true });
|
|
101
|
+
if (data2.id !== uri) {
|
|
89
102
|
throw new errors.InvalidRequestError({ message: "Skohub URL did not return expected concept URI" });
|
|
90
103
|
}
|
|
91
|
-
const concept = this._toJskosConcept(
|
|
104
|
+
const concept = this._toJskosConcept(data2);
|
|
92
105
|
this._conceptCache[uri] = concept;
|
|
93
106
|
return concept;
|
|
94
107
|
} catch (error) {
|
|
95
108
|
return null;
|
|
96
109
|
}
|
|
97
110
|
}
|
|
98
|
-
_toJskosConcept(
|
|
99
|
-
const concept = { uri:
|
|
100
|
-
concept.prefLabel =
|
|
111
|
+
_toJskosConcept(data2) {
|
|
112
|
+
const concept = { uri: data2.id };
|
|
113
|
+
concept.prefLabel = data2.prefLabel;
|
|
101
114
|
Object.keys(concept.prefLabel || {}).forEach((key) => {
|
|
102
115
|
concept.prefLabel[key] = decodeUnicode(concept.prefLabel[key]);
|
|
103
116
|
});
|
|
104
|
-
concept.narrower = (
|
|
105
|
-
concept.notation =
|
|
106
|
-
if (
|
|
107
|
-
concept.broader = [{ uri:
|
|
117
|
+
concept.narrower = (data2.narrower || []).map((c) => this._toJskosConcept(c));
|
|
118
|
+
concept.notation = data2.notation || [];
|
|
119
|
+
if (data2.broader && data2.broader.id) {
|
|
120
|
+
concept.broader = [{ uri: data2.broader.id }];
|
|
108
121
|
}
|
|
109
|
-
if (
|
|
110
|
-
concept.inScheme = [{ uri:
|
|
122
|
+
if (data2.inScheme && data2.inScheme.id) {
|
|
123
|
+
concept.inScheme = [{ uri: data2.inScheme.id }];
|
|
111
124
|
}
|
|
112
|
-
if (
|
|
113
|
-
concept.scopeNote =
|
|
125
|
+
if (data2.scopeNote) {
|
|
126
|
+
concept.scopeNote = data2.scopeNote;
|
|
114
127
|
Object.keys(concept.scopeNote).forEach((key) => {
|
|
115
128
|
concept.scopeNote[key] = [decodeUnicode(concept.scopeNote[key])];
|
|
116
129
|
});
|
|
@@ -182,13 +195,13 @@ class SkohubProvider extends BaseProvider {
|
|
|
182
195
|
if (scheme.uri.endsWith("/")) {
|
|
183
196
|
postfix = `index${postfix}`;
|
|
184
197
|
}
|
|
185
|
-
const
|
|
186
|
-
if (
|
|
198
|
+
const data2 = await this.axios({ url: `${scheme.uri}${postfix}`, _skipAdditionalParameters: true });
|
|
199
|
+
if (data2.length < 100) {
|
|
187
200
|
this._index[scheme.uri][lang] = null;
|
|
188
201
|
continue;
|
|
189
202
|
}
|
|
190
203
|
index = FlexSearch.create();
|
|
191
|
-
index.import(
|
|
204
|
+
index.import(data2);
|
|
192
205
|
this._index[scheme.uri][lang] = index;
|
|
193
206
|
break;
|
|
194
207
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cocoda-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "SDK for Cocoda",
|
|
5
5
|
"main": "dist/cjs/index.cjs",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"release:patch": "SEMVER=patch npm run release",
|
|
28
28
|
"release:minor": "SEMVER=minor npm run release",
|
|
29
29
|
"release:major": "SEMVER=major npm run release",
|
|
30
|
-
"
|
|
30
|
+
"prepare": "[ -d './dist' ] || npm run build"
|
|
31
31
|
},
|
|
32
32
|
"lint-staged": {
|
|
33
33
|
"**/*.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.
|
|
55
|
+
"axios-mock-adapter": "^1.21.2",
|
|
56
56
|
"better-docs": "^2.7.2",
|
|
57
|
-
"esbuild": "~0.14.
|
|
57
|
+
"esbuild": "~0.14.54",
|
|
58
58
|
"esbuild-plugin-ifdef": "^1.0.1",
|
|
59
|
-
"eslint": "^8.
|
|
59
|
+
"eslint": "^8.23.1",
|
|
60
60
|
"eslint-config-gbv": "^1.0.3",
|
|
61
61
|
"glob": "^8.0.3",
|
|
62
|
-
"jsdoc": "^3.6.
|
|
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": "^
|
|
75
|
+
"uuid": "^9.0.0"
|
|
76
76
|
}
|
|
77
77
|
}
|