cocoda-sdk 3.3.3 → 3.4.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 +3 -1
- package/dist/cjs/index.cjs +1086 -35
- package/dist/cocoda-sdk.js +16 -11
- package/dist/cocoda-sdk.js.LICENSES.txt +178 -4
- package/dist/cocoda-sdk.js.map +4 -4
- package/dist/esm/errors/index.js +22 -0
- package/dist/esm/lib/CocodaSDK.js +120 -17
- package/dist/esm/providers/base-provider.js +88 -0
- package/dist/esm/providers/concept-api-provider.js +108 -0
- package/dist/esm/providers/index.js +2 -0
- package/dist/esm/providers/label-search-suggestion-provider.js +39 -0
- package/dist/esm/providers/lobid-api-provider.js +239 -0
- package/dist/esm/providers/loc-api-provider.js +58 -0
- package/dist/esm/providers/local-mappings-provider.js +60 -3
- package/dist/esm/providers/mappings-api-provider.js +116 -0
- package/dist/esm/providers/mycore-provider.js +42 -0
- package/dist/esm/providers/occurrences-api-provider.js +32 -0
- package/dist/esm/providers/reconciliation-api-provider.js +21 -0
- package/dist/esm/providers/skohub-provider.js +26 -0
- package/dist/esm/providers/skosmos-api-provider.js +89 -0
- package/dist/esm/utils/index.js +8 -0
- package/package.json +8 -8
package/dist/esm/errors/index.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
class CDKError extends Error {
|
|
2
|
+
/**
|
|
3
|
+
* CDKError constructor.
|
|
4
|
+
*
|
|
5
|
+
* @param {Object} options
|
|
6
|
+
* @param {string} [options.message=""] message for the error
|
|
7
|
+
* @param {Error} [options.relatedError=null] related error
|
|
8
|
+
* @param {number} [options.code] HTTP status code for the error
|
|
9
|
+
*/
|
|
2
10
|
constructor({ message = "", relatedError = null, code = null } = {}) {
|
|
3
11
|
if (!message && relatedError && relatedError.message) {
|
|
4
12
|
message = relatedError.message;
|
|
@@ -10,12 +18,26 @@ class CDKError extends Error {
|
|
|
10
18
|
}
|
|
11
19
|
}
|
|
12
20
|
class MethodNotImplementedError extends CDKError {
|
|
21
|
+
/**
|
|
22
|
+
* MethodNotImplementedError constructor.
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} config
|
|
25
|
+
* @param {string} config.method method that this error refers to
|
|
26
|
+
* @param {string} [config.message=""] message for the error
|
|
27
|
+
*/
|
|
13
28
|
constructor({ method, message = "", ...options }) {
|
|
14
29
|
options.message = `Method not implemented: ${method} (${message})`;
|
|
15
30
|
super(options);
|
|
16
31
|
}
|
|
17
32
|
}
|
|
18
33
|
class InvalidOrMissingParameterError extends CDKError {
|
|
34
|
+
/**
|
|
35
|
+
* InvalidOrMissingParameterError constructor.
|
|
36
|
+
*
|
|
37
|
+
* @param {Object} config
|
|
38
|
+
* @param {string} config.parameter parameter that this error refers to
|
|
39
|
+
* @param {string} [config.message=""] message for the error
|
|
40
|
+
*/
|
|
19
41
|
constructor({ parameter, message = "", ...options }) {
|
|
20
42
|
options.message = `Invalid or missing parameter: ${parameter} (${message})`;
|
|
21
43
|
super(options);
|
|
@@ -23,16 +23,37 @@ providers.addProvider(ConceptApiProvider);
|
|
|
23
23
|
providers.addProvider(MappingsApiProvider);
|
|
24
24
|
const registryCache = {};
|
|
25
25
|
class CocodaSDK {
|
|
26
|
+
/**
|
|
27
|
+
* CDK constructor.
|
|
28
|
+
*
|
|
29
|
+
* @param {Object} [config={}] Cocoda-stye config object
|
|
30
|
+
*/
|
|
26
31
|
constructor(config) {
|
|
27
32
|
this.config = config;
|
|
28
33
|
this.axios = axios.create();
|
|
29
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Method to set the configuration.
|
|
37
|
+
*
|
|
38
|
+
* @param {Object} config Cocoda-stye config object
|
|
39
|
+
*/
|
|
30
40
|
setConfig(config) {
|
|
31
41
|
this.config = config;
|
|
32
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Current configuration.
|
|
45
|
+
*
|
|
46
|
+
* @returns {Object} current configuration
|
|
47
|
+
*/
|
|
33
48
|
get config() {
|
|
34
49
|
return this._config;
|
|
35
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Prepares config when set.
|
|
53
|
+
*
|
|
54
|
+
* @param {Object} config Cocoda config object
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
36
57
|
set config(config) {
|
|
37
58
|
config = config || {};
|
|
38
59
|
config.registries = config.registries || [];
|
|
@@ -42,16 +63,44 @@ class CocodaSDK {
|
|
|
42
63
|
});
|
|
43
64
|
this._config = config;
|
|
44
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Map of registered providers.
|
|
68
|
+
*
|
|
69
|
+
* @returns {Object} map of registered providers (name -> provider)
|
|
70
|
+
*/
|
|
45
71
|
get providers() {
|
|
46
72
|
return providers;
|
|
47
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new CDK instance (same as `new CocodaSDK(config)`).
|
|
76
|
+
*
|
|
77
|
+
* @param {Object} config Cocoda config object
|
|
78
|
+
* @returns {CocodaSDK} new CDK instance
|
|
79
|
+
*/
|
|
48
80
|
createInstance(config) {
|
|
49
81
|
return new CocodaSDK(config);
|
|
50
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Offer method to load a config file from URL.
|
|
85
|
+
*
|
|
86
|
+
* @param {string} url URL of config as JSON
|
|
87
|
+
*/
|
|
51
88
|
async loadConfig(url) {
|
|
52
89
|
const response = await this.axios.get(url);
|
|
53
90
|
this.config = response.data;
|
|
54
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Method to load buildInfo.
|
|
94
|
+
*
|
|
95
|
+
* Callback will only be called if buildInfo changes; it will not be called when there is no previous value.
|
|
96
|
+
*
|
|
97
|
+
* @param {Object} config
|
|
98
|
+
* @param {string} [config.url] full URL for build-info.json (default is taken from config.cocodaBaseUrl)
|
|
99
|
+
* @param {Object} [config.buildInfo] current buildInfo
|
|
100
|
+
* @param {number} [config.interval=60000] interval to load buildInfo in ms
|
|
101
|
+
* @param {Function} config.callback callback function called with two parameters (error, buildInfo, previousBuildInfo)
|
|
102
|
+
* @returns {Object} object with two function properties, `stop` to cancel the repeating request, `start` to restart the repeating request, as well as three convenience properties, `isPaused` (whether it is currently paused), `lastResult`, `hasErrored` (whether the last call of the function has errored)
|
|
103
|
+
*/
|
|
55
104
|
loadBuildInfo({ url, buildInfo = null, interval = 6e4, callback, ...config }) {
|
|
56
105
|
if (!url && !this.config.cocodaBaseUrl) {
|
|
57
106
|
throw new errors.CDKError({ message: "Could not determine URL to load build config." });
|
|
@@ -78,20 +127,64 @@ class CocodaSDK {
|
|
|
78
127
|
}
|
|
79
128
|
});
|
|
80
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Method to get a registry by URI.
|
|
132
|
+
*
|
|
133
|
+
* @param {string} uri URI of registry in config
|
|
134
|
+
* @returns {?Object} initialized registry from config if found
|
|
135
|
+
*/
|
|
81
136
|
getRegistryForUri(uri) {
|
|
82
137
|
return this.config.registries.find((r) => r.uri == uri);
|
|
83
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Method to initialize registry.
|
|
141
|
+
*
|
|
142
|
+
* @param {Object} registry JSKOS registry object
|
|
143
|
+
* @returns {Object} initialized registry
|
|
144
|
+
*/
|
|
84
145
|
initializeRegistry(registry) {
|
|
85
146
|
registry = providers.init(registry);
|
|
86
147
|
registry.cdk = this;
|
|
87
148
|
return registry;
|
|
88
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Method to add custom provider.
|
|
152
|
+
*
|
|
153
|
+
* @param {Object} provider provider class that extends BaseProvider
|
|
154
|
+
*/
|
|
89
155
|
addProvider(provider) {
|
|
90
156
|
providers.addProvider(provider);
|
|
91
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Static method to add custom provider.
|
|
160
|
+
*
|
|
161
|
+
* @param {Object} provider provider class that extends BaseProvider
|
|
162
|
+
*/
|
|
92
163
|
static addProvider(provider) {
|
|
93
164
|
providers.addProvider(provider);
|
|
94
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Repeatedly call a certain function.
|
|
168
|
+
*
|
|
169
|
+
* Notes:
|
|
170
|
+
* - Callback will only be called if the results were changed.
|
|
171
|
+
* - The function will only be repeated after the previous call is resolved. This means that the total interval duration is (interval + duration of function call).
|
|
172
|
+
*
|
|
173
|
+
* Example:
|
|
174
|
+
* ```js
|
|
175
|
+
* cdk.repeat({
|
|
176
|
+
* function: () => registry.getMappings(),
|
|
177
|
+
* callback: (error, result) => console.log(result),
|
|
178
|
+
* })
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* @param {Object} config
|
|
182
|
+
* @param {string} config.function a function to be called (can be async)
|
|
183
|
+
* @param {number} [config.interval=15000] interval in ms
|
|
184
|
+
* @param {Function} config.callback callback function called with two parameters (error, result, previousResult)
|
|
185
|
+
* @param {boolean} [config.callImmediately=true] whether to call the function immediately
|
|
186
|
+
* @returns {Object} object with two function properties, `stop` to cancel the repeating request, `start` to restart the repeating request, as well as three convenience properties, `isPaused` (whether it is currently paused), `lastResult`, `hasErrored` (whether the last call of the function has errored)
|
|
187
|
+
*/
|
|
95
188
|
repeat({ function: func, interval = 15e3, callback, callImmediately = true } = {}) {
|
|
96
189
|
if (!func) {
|
|
97
190
|
throw new errors.InvalidOrMissingParameterError({ parameter: "function" });
|
|
@@ -178,6 +271,12 @@ class CocodaSDK {
|
|
|
178
271
|
}
|
|
179
272
|
};
|
|
180
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* Gets schemes from all registries that support schemes and merges the results.
|
|
276
|
+
*
|
|
277
|
+
* @param {Object} [config={}] configuration object that will be used as a parameter for internal `getSchemes` calls
|
|
278
|
+
* @returns {Object[]} array of JSKOS schemes
|
|
279
|
+
*/
|
|
181
280
|
async getSchemes(config = {}) {
|
|
182
281
|
let schemes = [], promises = [];
|
|
183
282
|
for (let registry of this.config.registries) {
|
|
@@ -259,25 +358,29 @@ class CocodaSDK {
|
|
|
259
358
|
}
|
|
260
359
|
return registry2;
|
|
261
360
|
} else {
|
|
262
|
-
const provider = Object.values(providers).find((p) => p.providerType === type);
|
|
263
|
-
if (!provider || !provider._registryConfigForBartocApiConfig) {
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
const providerName = provider.providerName;
|
|
267
361
|
config.scheme = scheme;
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
362
|
+
for (const provider of Object.values(providers)) {
|
|
363
|
+
if (provider.providerType && provider.providerType !== type) {
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (!provider._registryConfigForBartocApiConfig) {
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
const providerName = provider.providerName;
|
|
370
|
+
const registryConfig = providers[providerName]._registryConfigForBartocApiConfig(config);
|
|
371
|
+
if (!registryConfig) {
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
registryConfig.provider = providerName;
|
|
375
|
+
try {
|
|
376
|
+
registry = this.initializeRegistry(registryConfig);
|
|
377
|
+
if (registry) {
|
|
378
|
+
registryCache[url] = registry;
|
|
379
|
+
return registry;
|
|
380
|
+
}
|
|
381
|
+
} catch (error) {
|
|
382
|
+
continue;
|
|
278
383
|
}
|
|
279
|
-
} catch (error) {
|
|
280
|
-
continue;
|
|
281
384
|
}
|
|
282
385
|
}
|
|
283
386
|
}
|
|
@@ -4,9 +4,15 @@ import axios from "axios";
|
|
|
4
4
|
import * as utils from "../utils/index.js";
|
|
5
5
|
import * as errors from "../errors/index.js";
|
|
6
6
|
class BaseProvider {
|
|
7
|
+
/**
|
|
8
|
+
* Provider constructor.
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} registry the registry for this provider
|
|
11
|
+
*/
|
|
7
12
|
constructor(registry = {}) {
|
|
8
13
|
this._jskos = registry;
|
|
9
14
|
this.axios = axios.create({
|
|
15
|
+
// TODO: Decide on timeout value
|
|
10
16
|
timeout: 2e4
|
|
11
17
|
});
|
|
12
18
|
this._path = typeof window !== "undefined" && window.location.pathname;
|
|
@@ -20,6 +26,7 @@ class BaseProvider {
|
|
|
20
26
|
this._repeating = [];
|
|
21
27
|
this._api = {
|
|
22
28
|
status: registry.status,
|
|
29
|
+
// If `schemes` on registry is an array, remove it because we're only keeping it in this._jskos.schemes
|
|
23
30
|
schemes: Array.isArray(registry.schemes) ? void 0 : registry.schemes,
|
|
24
31
|
top: registry.top,
|
|
25
32
|
data: registry.data,
|
|
@@ -165,6 +172,7 @@ class BaseProvider {
|
|
|
165
172
|
};
|
|
166
173
|
}
|
|
167
174
|
}
|
|
175
|
+
// Expose some properties from original registry object as getters
|
|
168
176
|
get uri() {
|
|
169
177
|
return this._jskos.uri;
|
|
170
178
|
}
|
|
@@ -186,6 +194,11 @@ class BaseProvider {
|
|
|
186
194
|
get stored() {
|
|
187
195
|
return this._jskos.stored !== void 0 ? this._jskos.stored : this.constructor.stored;
|
|
188
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Load data about registry via the status endpoint.
|
|
199
|
+
*
|
|
200
|
+
* @returns {Promise} Promise that resolves when initialization is complete.
|
|
201
|
+
*/
|
|
189
202
|
async init() {
|
|
190
203
|
if (this._init) {
|
|
191
204
|
return this._init;
|
|
@@ -219,17 +232,48 @@ class BaseProvider {
|
|
|
219
232
|
})();
|
|
220
233
|
return this._init;
|
|
221
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Preparation to be executed before init. Should be overwritten by subclasses.
|
|
237
|
+
*
|
|
238
|
+
* @private
|
|
239
|
+
*/
|
|
222
240
|
_prepare() {
|
|
223
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Setup to be executed after init. Should be overwritten by subclasses.
|
|
244
|
+
*
|
|
245
|
+
* @private
|
|
246
|
+
*/
|
|
224
247
|
_setup() {
|
|
225
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Returns a source for a axios cancel token.
|
|
251
|
+
*
|
|
252
|
+
* @returns {Object} axios cancel token source
|
|
253
|
+
*/
|
|
226
254
|
getCancelTokenSource() {
|
|
227
255
|
return axios.CancelToken.source();
|
|
228
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Sets authentication credentials.
|
|
259
|
+
*
|
|
260
|
+
* @param {Object} options
|
|
261
|
+
* @param {string} options.key public key of login-server instance the user is authorized for
|
|
262
|
+
* @param {string} options.bearerToken token that is sent with each request
|
|
263
|
+
*/
|
|
229
264
|
setAuth({ key = this._auth.key, bearerToken = this._auth.bearerToken }) {
|
|
230
265
|
this._auth.key = key;
|
|
231
266
|
this._auth.bearerToken = bearerToken;
|
|
232
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Sets retry configuration.
|
|
270
|
+
*
|
|
271
|
+
* @param {Object} config
|
|
272
|
+
* @param {string[]} [config.methods=["get", "head", "options"]] HTTP methods to retry (lowercase)
|
|
273
|
+
* @param {number[]} [config.statusCodes=[401, 403]] status codes to retry
|
|
274
|
+
* @param {number} [config.count=3] maximum number of retries
|
|
275
|
+
* @param {number|Function} [config.delay=300*count] a delay in ms or a function that takes the number of current retries and returns a delay in ms
|
|
276
|
+
*/
|
|
233
277
|
setRetryConfig(config = {}) {
|
|
234
278
|
this._retryConfig = Object.assign({
|
|
235
279
|
methods: ["get", "head", "options"],
|
|
@@ -240,6 +284,16 @@ class BaseProvider {
|
|
|
240
284
|
}
|
|
241
285
|
}, config);
|
|
242
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Returns whether a user is authorized for a certain request.
|
|
289
|
+
*
|
|
290
|
+
* @param {Object} options
|
|
291
|
+
* @param {string} options.type type of item (e.g. mappings)
|
|
292
|
+
* @param {string} options.action action to be performed (read/create/update/delete)
|
|
293
|
+
* @param {Object} options.user user object
|
|
294
|
+
* @param {boolean} [options.crossUser] whether the request is a crossUser request (i.e. updading/deleting another user's item)
|
|
295
|
+
* @returns {boolean}
|
|
296
|
+
*/
|
|
243
297
|
isAuthorizedFor({ type, action, user, crossUser }) {
|
|
244
298
|
if (action == "read" && this.has[type] === true) {
|
|
245
299
|
return true;
|
|
@@ -274,6 +328,12 @@ class BaseProvider {
|
|
|
274
328
|
}
|
|
275
329
|
return !!this.has[type][action];
|
|
276
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* Returns a boolean whether a certain target scheme is supported or not.
|
|
333
|
+
*
|
|
334
|
+
* @param {Object} scheme
|
|
335
|
+
* @returns {boolean}
|
|
336
|
+
*/
|
|
277
337
|
supportsScheme(scheme) {
|
|
278
338
|
if (!scheme) {
|
|
279
339
|
return false;
|
|
@@ -367,6 +427,13 @@ class BaseProvider {
|
|
|
367
427
|
adjustMappings(mappings) {
|
|
368
428
|
return utils.withCustomProps(mappings.map((mapping) => this.adjustMapping(mapping)), mappings);
|
|
369
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
* POSTs multiple mappings. Do not override in subclass!
|
|
432
|
+
*
|
|
433
|
+
* @param {Object} config
|
|
434
|
+
* @param {Array} config.mappings array of mapping objects
|
|
435
|
+
* @returns {Object[]} array of created mapping objects; in case of failure, consult the `_errors` property on the array at the index of the failed request
|
|
436
|
+
*/
|
|
370
437
|
async postMappings({ mappings, ...config } = {}) {
|
|
371
438
|
if (!mappings || !mappings.length) {
|
|
372
439
|
throw new errors.InvalidOrMissingParameterError({ parameter: "mappings" });
|
|
@@ -378,6 +445,13 @@ class BaseProvider {
|
|
|
378
445
|
config
|
|
379
446
|
});
|
|
380
447
|
}
|
|
448
|
+
/**
|
|
449
|
+
* DELETEs multiple mappings. Do not override in subclass!
|
|
450
|
+
*
|
|
451
|
+
* @param {Object} config
|
|
452
|
+
* @param {Array} config.mappings array of mapping objects
|
|
453
|
+
* @returns {Object[]} array of results (`true` if successful); in case of failure, consult the `_errors` property on the array at the index of the failed request
|
|
454
|
+
*/
|
|
381
455
|
async deleteMappings({ mappings, ...config } = {}) {
|
|
382
456
|
if (!mappings || !mappings.length) {
|
|
383
457
|
throw new errors.InvalidOrMissingParameterError({ parameter: "mappings" });
|
|
@@ -389,6 +463,20 @@ class BaseProvider {
|
|
|
389
463
|
config
|
|
390
464
|
});
|
|
391
465
|
}
|
|
466
|
+
/**
|
|
467
|
+
* Calls a method that is for only one item for an array of items. Returns an array of results.
|
|
468
|
+
*
|
|
469
|
+
* If there is an error, that index in the result array will be `null`. There is a property `_errors` on the result array that will contain the respective error at the correct index.
|
|
470
|
+
*
|
|
471
|
+
* @param {Object} options
|
|
472
|
+
* @param {string} options.method instance method to call (e.g. `postMapping`)
|
|
473
|
+
* @param {Object[]} options.items items to call the method for
|
|
474
|
+
* @param {string} options.itemProperty the property name for the item when calling the method (e.g. `mapping`)
|
|
475
|
+
* @param {Object} options.config other properties to pass to the method call
|
|
476
|
+
* @returns {any[]} result array with values returned from individual method calls
|
|
477
|
+
*
|
|
478
|
+
* @private
|
|
479
|
+
*/
|
|
392
480
|
async _callHelperForArrayWrappers({ method, items, itemProperty, config }) {
|
|
393
481
|
const errors2 = [];
|
|
394
482
|
const resultItems = await Promise.all(items.map(async (item) => {
|
|
@@ -4,6 +4,9 @@ import * as errors from "../errors/index.js";
|
|
|
4
4
|
import * as utils from "../utils/index.js";
|
|
5
5
|
import jskos from "jskos-tools";
|
|
6
6
|
class ConceptApiProvider extends BaseProvider {
|
|
7
|
+
/**
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
7
10
|
_prepare() {
|
|
8
11
|
if (this._api.api && this._api.status === void 0) {
|
|
9
12
|
this._api.status = utils.concatUrl(this._api.api, "/status");
|
|
@@ -22,6 +25,9 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
22
25
|
this.has[c] = false;
|
|
23
26
|
});
|
|
24
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
25
31
|
_setup() {
|
|
26
32
|
if (this._api.api) {
|
|
27
33
|
const endpoints = {
|
|
@@ -55,9 +61,17 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
55
61
|
this.has.search = !!this._api.search;
|
|
56
62
|
this.has.auth = _.get(this._config, "auth.key") != null;
|
|
57
63
|
this._defaultParams = {
|
|
64
|
+
// Default parameters mostly for DANTE
|
|
58
65
|
properties: "+created,issued,modified,editorialNote,scopeNote"
|
|
59
66
|
};
|
|
60
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Used by `registryForScheme` (see src/lib/CocodaSDK.js) to determine a provider config for a concept schceme.
|
|
70
|
+
*
|
|
71
|
+
* @param {Object} options
|
|
72
|
+
* @param {Object} options.url API URL for server
|
|
73
|
+
* @returns {Object} provider configuration
|
|
74
|
+
*/
|
|
61
75
|
static _registryConfigForBartocApiConfig({ url, scheme } = {}) {
|
|
62
76
|
if (!url || !scheme) {
|
|
63
77
|
return null;
|
|
@@ -67,6 +81,11 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
67
81
|
schemes: [scheme]
|
|
68
82
|
};
|
|
69
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns the main vocabulary URI by requesting the scheme info and saving it in a cache.
|
|
86
|
+
*
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
70
89
|
async _getSchemeUri(scheme) {
|
|
71
90
|
this._approvedSchemes = this._approvedSchemes || [];
|
|
72
91
|
this._rejectedSchemes = this._rejectedSchemes || [];
|
|
@@ -95,6 +114,12 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
95
114
|
return null;
|
|
96
115
|
}
|
|
97
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Returns all concept schemes.
|
|
119
|
+
*
|
|
120
|
+
* @param {Object} config
|
|
121
|
+
* @returns {Object[]} array of JSKOS concept scheme objects
|
|
122
|
+
*/
|
|
98
123
|
async getSchemes(config) {
|
|
99
124
|
if (!this._api.schemes) {
|
|
100
125
|
if (Array.isArray(this.schemes)) {
|
|
@@ -108,6 +133,7 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
108
133
|
url: this._api.schemes,
|
|
109
134
|
params: {
|
|
110
135
|
...this._defaultParams,
|
|
136
|
+
// ? What should the default limit be?
|
|
111
137
|
limit: 500,
|
|
112
138
|
...config.params || {}
|
|
113
139
|
}
|
|
@@ -118,6 +144,13 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
118
144
|
return schemes;
|
|
119
145
|
}
|
|
120
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Returns top concepts for a concept scheme.
|
|
149
|
+
*
|
|
150
|
+
* @param {Object} config
|
|
151
|
+
* @param {Object} config.scheme concept scheme object
|
|
152
|
+
* @returns {Object[]} array of JSKOS concept objects
|
|
153
|
+
*/
|
|
121
154
|
async getTop({ scheme, ...config }) {
|
|
122
155
|
if (!this._api.top) {
|
|
123
156
|
throw new errors.MissingApiUrlError();
|
|
@@ -138,12 +171,20 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
138
171
|
url: this._api.top,
|
|
139
172
|
params: {
|
|
140
173
|
...this._defaultParams,
|
|
174
|
+
// ? What should the default limit be?
|
|
141
175
|
limit: 1e4,
|
|
142
176
|
...config.params || {},
|
|
143
177
|
uri: schemeUri
|
|
144
178
|
}
|
|
145
179
|
});
|
|
146
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Returns details for a list of concepts.
|
|
183
|
+
*
|
|
184
|
+
* @param {Object} config
|
|
185
|
+
* @param {Object[]} config.concepts list of concept objects to load
|
|
186
|
+
* @returns {Object[]} array of JSKOS concept objects
|
|
187
|
+
*/
|
|
147
188
|
async getConcepts({ concepts, ...config }) {
|
|
148
189
|
if (this.has.data === false) {
|
|
149
190
|
throw new errors.MissingApiUrlError();
|
|
@@ -161,12 +202,20 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
161
202
|
url: this._api.data,
|
|
162
203
|
params: {
|
|
163
204
|
...this._defaultParams,
|
|
205
|
+
// ? What should the default limit be?
|
|
164
206
|
limit: 500,
|
|
165
207
|
...config.params || {},
|
|
166
208
|
uri: uris.join("|")
|
|
167
209
|
}
|
|
168
210
|
});
|
|
169
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Returns narrower concepts for a concept.
|
|
214
|
+
*
|
|
215
|
+
* @param {Object} config
|
|
216
|
+
* @param {Object} config.concept concept object
|
|
217
|
+
* @returns {Object[]} array of JSKOS concept objects
|
|
218
|
+
*/
|
|
170
219
|
async getNarrower({ concept, ...config }) {
|
|
171
220
|
if (!this._api.narrower) {
|
|
172
221
|
throw new errors.MissingApiUrlError();
|
|
@@ -180,12 +229,20 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
180
229
|
url: this._api.narrower,
|
|
181
230
|
params: {
|
|
182
231
|
...this._defaultParams,
|
|
232
|
+
// ? What should the default limit be?
|
|
183
233
|
limit: 1e4,
|
|
184
234
|
...config.params || {},
|
|
185
235
|
uri: concept.uri
|
|
186
236
|
}
|
|
187
237
|
});
|
|
188
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Returns ancestor concepts for a concept.
|
|
241
|
+
*
|
|
242
|
+
* @param {Object} config
|
|
243
|
+
* @param {Object} config.concept concept object
|
|
244
|
+
* @returns {Object[]} array of JSKOS concept objects
|
|
245
|
+
*/
|
|
189
246
|
async getAncestors({ concept, ...config }) {
|
|
190
247
|
if (!this._api.ancestors) {
|
|
191
248
|
throw new errors.MissingApiUrlError();
|
|
@@ -199,12 +256,25 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
199
256
|
url: this._api.ancestors,
|
|
200
257
|
params: {
|
|
201
258
|
...this._defaultParams,
|
|
259
|
+
// ? What should the default limit be?
|
|
202
260
|
limit: 1e4,
|
|
203
261
|
...config.params || {},
|
|
204
262
|
uri: concept.uri
|
|
205
263
|
}
|
|
206
264
|
});
|
|
207
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Returns suggestion result in OpenSearch Suggest Format.
|
|
268
|
+
*
|
|
269
|
+
* @param {Object} config
|
|
270
|
+
* @param {string} config.search search string
|
|
271
|
+
* @param {Object} [config.scheme] concept scheme to search in
|
|
272
|
+
* @param {number} [config.limit=100] maximum number of search results (default might be overridden by registry)
|
|
273
|
+
* @param {string} [config.use=notation,label] which fields to search ("notation", "label" or "notation,label")
|
|
274
|
+
* @param {string[]} [config.types=[]] list of type URIs
|
|
275
|
+
* @param {string} [config.sort=score] sorting parameter
|
|
276
|
+
* @returns {Array} result in OpenSearch Suggest Format
|
|
277
|
+
*/
|
|
208
278
|
async suggest({ use = "notation,label", types = [], sort = "score", params = {}, ...config }) {
|
|
209
279
|
return this._search({
|
|
210
280
|
...config,
|
|
@@ -217,6 +287,17 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
217
287
|
}
|
|
218
288
|
});
|
|
219
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Returns search results in JSKOS Format.
|
|
292
|
+
*
|
|
293
|
+
* @param {Object} config
|
|
294
|
+
* @param {string} config.search search string
|
|
295
|
+
* @param {Object} [config.scheme] concept scheme to search in
|
|
296
|
+
* @param {number} [config.limit=100] maximum number of search results (default might be overridden by registry)
|
|
297
|
+
* @param {number} [config.offset=0] offset
|
|
298
|
+
* @param {string[]} [config.types=[]] list of type URIs
|
|
299
|
+
* @returns {Array} result in JSKOS Format
|
|
300
|
+
*/
|
|
220
301
|
async search({ types = [], params = {}, ...config }) {
|
|
221
302
|
return this._search({
|
|
222
303
|
...config,
|
|
@@ -227,6 +308,16 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
227
308
|
}
|
|
228
309
|
});
|
|
229
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Returns concept scheme suggestion result in OpenSearch Suggest Format.
|
|
313
|
+
*
|
|
314
|
+
* @param {Object} config
|
|
315
|
+
* @param {string} config.search search string
|
|
316
|
+
* @param {number} [config.limit=100] maximum number of search results (default might be overridden by registry)
|
|
317
|
+
* @param {string} [config.use=notation,label] which fields to search ("notation", "label" or "notation,label")
|
|
318
|
+
* @param {string} [config.sort=score] sorting parameter
|
|
319
|
+
* @returns {Array} result in OpenSearch Suggest Format
|
|
320
|
+
*/
|
|
230
321
|
async vocSuggest({ use = "notation,label", sort = "score", params = {}, ...config }) {
|
|
231
322
|
return this._search({
|
|
232
323
|
...config,
|
|
@@ -238,6 +329,15 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
238
329
|
}
|
|
239
330
|
});
|
|
240
331
|
}
|
|
332
|
+
/**
|
|
333
|
+
* Returns concept scheme search results in JSKOS Format.
|
|
334
|
+
*
|
|
335
|
+
* @param {Object} config
|
|
336
|
+
* @param {string} config.search search string
|
|
337
|
+
* @param {number} [config.limit=100] maximum number of search results (default might be overridden by registry)
|
|
338
|
+
* @param {number} [config.offset=0] offset
|
|
339
|
+
* @returns {Array} result in JSKOS Format
|
|
340
|
+
*/
|
|
241
341
|
async vocSearch(config) {
|
|
242
342
|
return this._search({
|
|
243
343
|
...config,
|
|
@@ -263,6 +363,7 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
263
363
|
...params,
|
|
264
364
|
limit,
|
|
265
365
|
count: limit,
|
|
366
|
+
// Some endpoints use count instead of limit
|
|
266
367
|
offset,
|
|
267
368
|
search,
|
|
268
369
|
query: search,
|
|
@@ -272,6 +373,13 @@ class ConceptApiProvider extends BaseProvider {
|
|
|
272
373
|
url
|
|
273
374
|
});
|
|
274
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* Returns a list of types.
|
|
378
|
+
*
|
|
379
|
+
* @param {Object} config
|
|
380
|
+
* @param {Object} [config.scheme] concept scheme to load types for
|
|
381
|
+
* @returns {Object[]} array of JSKOS type objects
|
|
382
|
+
*/
|
|
275
383
|
async getTypes({ scheme, ...config }) {
|
|
276
384
|
if (!this._api.types) {
|
|
277
385
|
throw new errors.MissingApiUrlError();
|
|
@@ -8,11 +8,13 @@ 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 LobidApiProvider from "./lobid-api-provider.js";
|
|
11
12
|
import MyCoReProvider from "./mycore-provider.js";
|
|
12
13
|
export {
|
|
13
14
|
BaseProvider,
|
|
14
15
|
ConceptApiProvider,
|
|
15
16
|
LabelSearchSuggestionProvider,
|
|
17
|
+
LobidApiProvider,
|
|
16
18
|
LocApiProvider,
|
|
17
19
|
LocalMappingsProvider,
|
|
18
20
|
MappingsApiProvider,
|