cocoda-sdk 3.6.0 → 3.6.2

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/dist/esm/index.js CHANGED
@@ -2,8 +2,8 @@ import CocodaSDK from "./lib/CocodaSDK.js";
2
2
  import * as errors from "./errors/index.js";
3
3
  import * as utils from "./utils/index.js";
4
4
  export * from "./providers/index.js";
5
- const cdk = new CocodaSDK();
6
5
  import * as providers from "./providers/index.js";
6
+ const cdk = new CocodaSDK();
7
7
  function addAllProviders(_cdk) {
8
8
  Object.values(providers).forEach((provider) => (_cdk || cdk).addProvider(provider));
9
9
  }
@@ -12,5 +12,6 @@ export {
12
12
  addAllProviders,
13
13
  cdk,
14
14
  errors,
15
+ providers,
15
16
  utils
16
17
  };
@@ -1,13 +1,24 @@
1
1
  import * as errors from "../errors/index.js";
2
2
  import axios from "axios";
3
- import * as _ from "../utils/lodash.js";
4
3
  import jskos from "jskos-tools";
4
+ import { deepEqual } from "../utils/index.js";
5
5
  import { BaseProvider, ConceptApiProvider, MappingsApiProvider } from "../providers/index.js";
6
6
  const providers = {
7
7
  [BaseProvider.providerName]: BaseProvider,
8
8
  init(registry) {
9
- if (this[registry.provider]) {
10
- return new this[registry.provider](registry);
9
+ let name = registry.provider;
10
+ if (registry.api) {
11
+ Object.keys(this).find((p) => {
12
+ if (providers[p].prototype instanceof BaseProvider && registry.api === providers[p].providerType) {
13
+ registry = { ...registry };
14
+ delete registry.api;
15
+ name = p;
16
+ return true;
17
+ }
18
+ });
19
+ }
20
+ if (this[name]) {
21
+ return new this[name](registry);
11
22
  }
12
23
  throw new errors.InvalidProviderError();
13
24
  },
@@ -121,7 +132,7 @@ class CocodaSDK {
121
132
  callback: (error, result, previousResult) => {
122
133
  if (error) {
123
134
  callback(error);
124
- } else if (previousResult || !previousResult && buildInfo && !_.isEqual(result, buildInfo)) {
135
+ } else if (previousResult || !previousResult && buildInfo && !deepEqual(result, buildInfo)) {
125
136
  callback(null, result, previousResult || buildInfo);
126
137
  }
127
138
  }
@@ -212,7 +223,7 @@ class CocodaSDK {
212
223
  };
213
224
  const handleResult = (result) => {
214
225
  const previousResult = repeat.result;
215
- if (!_.isEqual(previousResult, result)) {
226
+ if (!deepEqual(previousResult, result)) {
216
227
  repeat.result = result;
217
228
  repeat.error = null;
218
229
  callback(null, result, previousResult);
@@ -292,7 +303,7 @@ class CocodaSDK {
292
303
  if (prio != -1) {
293
304
  prio = this.config.registries.length - prio;
294
305
  }
295
- otherPrio = this.config.registries.indexOf(_.get(otherScheme, "_registry"));
306
+ otherPrio = this.config.registries.indexOf(otherScheme?._registry);
296
307
  if (otherPrio != -1) {
297
308
  otherPrio = this.config.registries.length - otherPrio;
298
309
  }
@@ -312,7 +323,8 @@ class CocodaSDK {
312
323
  if (otherSchemeIndex != -1) {
313
324
  schemes.splice(otherSchemeIndex, 1);
314
325
  }
315
- scheme = jskos.merge(scheme, _.omit(otherScheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
326
+ const { concepts, topConcepts, ...fromOtherScheme } = otherScheme;
327
+ scheme = jskos.merge(scheme, fromOtherScheme, { mergeUris: true, skipPaths: ["_registry"] });
316
328
  }
317
329
  scheme._registry = registry;
318
330
  schemes.push(scheme);
@@ -320,7 +332,8 @@ class CocodaSDK {
320
332
  const index = schemes.findIndex((s) => jskos.compare(s, scheme));
321
333
  if (index != -1) {
322
334
  const otherSchemeRegistry = schemes[index]._registry;
323
- schemes[index] = jskos.merge(schemes[index], _.omit(scheme, ["concepts", "topConcepts"]), { mergeUris: true, skipPaths: ["_registry"] });
335
+ const { concepts, topConcepts, ...fromScheme } = scheme;
336
+ schemes[index] = jskos.merge(schemes[index], fromScheme, { mergeUris: true, skipPaths: ["_registry"] });
324
337
  schemes[index]._registry = otherSchemeRegistry;
325
338
  }
326
339
  }
@@ -1,9 +1,10 @@
1
1
  import jskos from "jskos-tools";
2
- import * as _ from "../utils/lodash.js";
3
2
  import axios from "axios";
4
- import * as utils from "../utils/index.js";
3
+ import { withCustomProps, listOfCapabilities, requestMethods, deepEqual } from "../utils/index.js";
5
4
  import * as errors from "../errors/index.js";
5
+ const intersection = (arrays) => arrays.reduce((a, b) => a.filter((c) => b.includes(c)));
6
6
  class BaseProvider {
7
+ static providerName = "Base";
7
8
  /**
8
9
  * Provider constructor.
9
10
  *
@@ -20,7 +21,7 @@ class BaseProvider {
20
21
  if (this.constructor?.supports) {
21
22
  this.has = Object.assign({}, this.constructor?.supports);
22
23
  }
23
- utils.listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
24
+ listOfCapabilities.filter((c) => !this.has[c]).forEach((c) => {
24
25
  this.has[c] = false;
25
26
  });
26
27
  this._defaultLanguages = "en,de,fr,es,nl,it,fi,pl,ru,cs,jp".split(",");
@@ -49,16 +50,21 @@ class BaseProvider {
49
50
  annotations: registry.annotations,
50
51
  occurrences: registry.occurrences,
51
52
  reconcile: registry.reconcile,
52
- api: registry.api
53
+ api: registry.endpoint || registry.api
53
54
  };
54
55
  this._config = {};
55
56
  this.setRetryConfig();
56
57
  this.axios.interceptors.request.use((config = {}) => {
57
58
  if (!config._skipAdditionalParameters) {
58
- const language = _.uniq([].concat(_.get(config, "params.language", "").split(","), this.languages, this._defaultLanguages).filter((lang) => lang != "")).join(",");
59
- _.set(config, "params.language", language);
60
- if (this.has.auth && this._auth.bearerToken && !_.get(config, "headers.Authorization")) {
61
- _.set(config, "headers.Authorization", `Bearer ${this._auth.bearerToken}`);
59
+ config.params ||= {};
60
+ config.params.language = [
61
+ ...new Set(
62
+ [].concat((config.params.language ?? "").split(","), this.languages, this._defaultLanguages).filter(Boolean)
63
+ )
64
+ ].join(",");
65
+ if (this.has.auth && this._auth.bearerToken && !config?.headers?.Authorization) {
66
+ config.headers ||= {};
67
+ config.headers.Authorization = `Bearer ${this._auth.bearerToken}`;
62
68
  }
63
69
  }
64
70
  if (config.url?.startsWith("http:") && typeof window !== "undefined" && window.location.protocol == "https:") {
@@ -72,10 +78,8 @@ class BaseProvider {
72
78
  if (!url.endsWith("?")) {
73
79
  url += "?";
74
80
  }
75
- _.forOwn(config.params || {}, (value, key) => {
76
- url += `${key}=${encodeURIComponent(value)}&`;
77
- });
78
- if (_.isArray(data) || _.isObject(data)) {
81
+ url += new URLSearchParams(config.params || {}).toString();
82
+ if (typeof data === "object") {
79
83
  let totalCount = parseInt(headers["x-total-count"]);
80
84
  if (!isNaN(totalCount)) {
81
85
  data._totalCount = totalCount;
@@ -84,9 +88,9 @@ class BaseProvider {
84
88
  }
85
89
  return data;
86
90
  }, (error) => {
87
- const count = _.get(error, "config._retryCount", 0);
88
- const method = _.get(error, "config.method");
89
- const statusCode = _.get(error, "response.status");
91
+ const count = error.config?._retryCount ?? 0;
92
+ const method = error.config.method;
93
+ const statusCode = error.response?.status;
90
94
  if (this._retryConfig.methods.includes(method) && this._retryConfig.statusCodes.includes(statusCode) && count < this._retryConfig.count) {
91
95
  error.config._retryCount = count + 1;
92
96
  if (error.config.data) {
@@ -108,7 +112,7 @@ class BaseProvider {
108
112
  }
109
113
  });
110
114
  const currentRequests = [];
111
- for (let { method, type } of utils.requestMethods) {
115
+ for (let { method, type } of requestMethods) {
112
116
  const existingMethod = this[method] && this[method].bind(this);
113
117
  if (!existingMethod) {
114
118
  this[method] = () => {
@@ -121,7 +125,7 @@ class BaseProvider {
121
125
  delete options._raw;
122
126
  return existingMethod(options);
123
127
  }
124
- const existingRequest = currentRequests.find((r) => r.method == method && _.isEqual(r.options, options));
128
+ const existingRequest = currentRequests.find((r) => r.method == method && deepEqual(r.options, options));
125
129
  if (existingRequest) {
126
130
  return existingRequest.promise;
127
131
  }
@@ -131,10 +135,8 @@ class BaseProvider {
131
135
  options.cancelToken = source.token;
132
136
  }
133
137
  const promise = this.init().then(() => existingMethod(options)).then((result) => {
134
- if (_.isArray(result) && result._totalCount === void 0) {
135
- result._totalCount = result.length;
136
- } else if (_.isObject(result) && result._totalCount === void 0) {
137
- result._totalCount = 1;
138
+ if (typeof result === "object" && result._totalCount === void 0) {
139
+ result._totalCount = Array.isArray(result) ? result.length : 1;
138
140
  }
139
141
  if (result && type && this[`adjust${type}`]) {
140
142
  result = this[`adjust${type}`](result);
@@ -168,9 +170,10 @@ class BaseProvider {
168
170
  return source.cancel(...args);
169
171
  };
170
172
  }
173
+ const { cancelToken, ...opts } = options;
171
174
  const request = {
172
175
  method,
173
- options: _.omit(options, ["cancelToken"]),
176
+ options: opts,
174
177
  promise
175
178
  };
176
179
  currentRequests.push(request);
@@ -214,21 +217,21 @@ class BaseProvider {
214
217
  this._init = (async () => {
215
218
  this._prepare();
216
219
  let status;
217
- if (_.isString(this._api.status)) {
220
+ if (typeof this._api.status === "string") {
218
221
  try {
219
222
  status = await this.axios({
220
223
  method: "get",
221
224
  url: this._api.status
222
225
  });
223
226
  } catch (error) {
224
- if (_.get(error, "response.status") === 404) {
227
+ if (error?.response?.status === 404) {
225
228
  this._api.status = null;
226
229
  }
227
230
  }
228
231
  } else {
229
232
  status = this._api.status;
230
233
  }
231
- if (_.isObject(status) && !_.isEmpty(status)) {
234
+ if (typeof status === "object" && Object.keys(status).length) {
232
235
  this._config = status.config || {};
233
236
  for (let key of Object.keys(this._api)) {
234
237
  if (this._api[key] === void 0) {
@@ -337,30 +340,30 @@ class BaseProvider {
337
340
  if (!this.has[type]) {
338
341
  return false;
339
342
  }
340
- const options = _.get(this._config, `${type}.${action}`);
343
+ const options = this._config?.[type]?.[action];
341
344
  if (!options) {
342
345
  return !!this.has[type][action];
343
346
  }
344
347
  if (options.auth && (!user || !this._auth.key)) {
345
348
  return false;
346
349
  }
347
- if (options.auth && this._auth.key != _.get(this._config, "auth.key")) {
350
+ if (options.auth && this._auth.key != this._config?.auth?.key) {
348
351
  return false;
349
352
  }
350
353
  const userUris = [user?.uri].concat(Object.values(user?.identities || {}).map((id) => id.uri)).filter(Boolean);
351
354
  if (options.auth && options.identities) {
352
- if (_.intersection(userUris, options.identities).length == 0) {
355
+ if (intersection(userUris, options.identities).length == 0) {
353
356
  return false;
354
357
  }
355
358
  }
356
359
  if (options.auth && options.identityProviders) {
357
360
  const providers = Object.keys(user?.identities || {});
358
- if (_.intersection(providers, options.identityProviders).length == 0) {
361
+ if (intersection(providers, options.identityProviders).length == 0) {
359
362
  return false;
360
363
  }
361
364
  }
362
365
  if (crossUser) {
363
- return options.crossUser === true || _.intersection(options.crossUser || [], userUris).length > 0;
366
+ return options.crossUser === true || intersection(options.crossUser || [], userUris).length > 0;
364
367
  }
365
368
  return !!this.has[type][action];
366
369
  }
@@ -374,7 +377,7 @@ class BaseProvider {
374
377
  if (!scheme) {
375
378
  return false;
376
379
  }
377
- let schemes = _.isArray(this.schemes) ? this.schemes : null;
380
+ let schemes = Array.isArray(this.schemes) ? this.schemes : null;
378
381
  if (schemes == null && !jskos.isContainedIn(scheme, this.excludedSchemes || [])) {
379
382
  return true;
380
383
  }
@@ -402,7 +405,7 @@ class BaseProvider {
402
405
  return concept;
403
406
  }
404
407
  adjustConcepts(concepts) {
405
- return utils.withCustomProps(concepts.map((concept) => this.adjustConcept(concept)), concepts);
408
+ return withCustomProps(concepts.map((concept) => this.adjustConcept(concept)), concepts);
406
409
  }
407
410
  adjustRegistries(registries) {
408
411
  return registries;
@@ -436,7 +439,7 @@ class BaseProvider {
436
439
  return scheme;
437
440
  }
438
441
  adjustSchemes(schemes) {
439
- return utils.withCustomProps(schemes.map((scheme) => this.adjustScheme(scheme)), schemes);
442
+ return withCustomProps(schemes.map((scheme) => this.adjustScheme(scheme)), schemes);
440
443
  }
441
444
  adjustConcordances(concordances) {
442
445
  for (let concordance of concordances) {
@@ -448,12 +451,12 @@ class BaseProvider {
448
451
  for (let side of ["from", "to"]) {
449
452
  let sideScheme = `${side}Scheme`;
450
453
  if (!mapping[sideScheme]) {
451
- mapping[sideScheme] = _.get(jskos.conceptsOfMapping(mapping, side), "[0].inScheme[0]", null);
454
+ mapping[sideScheme] = jskos.conceptsOfMapping(mapping, side)?.[0]?.inScheme?.[0] ?? null;
452
455
  }
453
456
  }
454
457
  mapping._registry = this;
455
458
  if (!mapping.identifier) {
456
- let identifier = _.get(jskos.addMappingIdentifiers(mapping), "identifier");
459
+ let identifier = jskos.addMappingIdentifiers(mapping)?.identifier;
457
460
  if (identifier) {
458
461
  mapping.identifier = identifier;
459
462
  }
@@ -461,7 +464,7 @@ class BaseProvider {
461
464
  return mapping;
462
465
  }
463
466
  adjustMappings(mappings) {
464
- return utils.withCustomProps(mappings.map((mapping) => this.adjustMapping(mapping)), mappings);
467
+ return withCustomProps(mappings.map((mapping) => this.adjustMapping(mapping)), mappings);
465
468
  }
466
469
  /**
467
470
  * POSTs multiple mappings. Do not override in subclass!
@@ -528,7 +531,6 @@ class BaseProvider {
528
531
  return resultItems;
529
532
  }
530
533
  }
531
- BaseProvider.providerName = "Base";
532
534
  export {
533
535
  BaseProvider as default
534
536
  };
@@ -1,7 +1,6 @@
1
1
  import BaseProvider from "./base-provider.js";
2
- import * as _ from "../utils/lodash.js";
3
2
  import * as errors from "../errors/index.js";
4
- import * as utils from "../utils/index.js";
3
+ import { withCustomProps, concatUrl } from "../utils/index.js";
5
4
  import jskos from "jskos-tools";
6
5
  class ConceptApiProvider extends BaseProvider {
7
6
  static providerName = "ConceptApi";
@@ -23,7 +22,7 @@ class ConceptApiProvider extends BaseProvider {
23
22
  */
24
23
  _prepare() {
25
24
  if (this._api.api && this._api.status === void 0) {
26
- this._api.status = utils.concatUrl(this._api.api, "/status");
25
+ this._api.status = concatUrl(this._api.api, "/status");
27
26
  }
28
27
  }
29
28
  /**
@@ -44,7 +43,7 @@ class ConceptApiProvider extends BaseProvider {
44
43
  };
45
44
  for (let key of Object.keys(endpoints)) {
46
45
  if (this._api[key] === void 0) {
47
- this._api[key] = utils.concatUrl(this._api.api, endpoints[key]);
46
+ this._api[key] = concatUrl(this._api.api, endpoints[key]);
48
47
  }
49
48
  }
50
49
  }
@@ -60,7 +59,7 @@ class ConceptApiProvider extends BaseProvider {
60
59
  this.has.types = !!this._api.types;
61
60
  this.has.suggest = !!this._api.suggest;
62
61
  this.has.search = !!this._api.search;
63
- this.has.auth = _.get(this._config, "auth.key") != null;
62
+ this.has.auth = this._config?.auth?.key;
64
63
  this._defaultParams = {
65
64
  // Default parameters mostly for DANTE
66
65
  properties: "+created,issued,modified,editorialNote,scopeNote,note,definition,mappings,location"
@@ -140,7 +139,7 @@ class ConceptApiProvider extends BaseProvider {
140
139
  }
141
140
  });
142
141
  if (Array.isArray(this.schemes)) {
143
- return utils.withCustomProps(schemes.filter((s) => jskos.isContainedIn(s, this.schemes)), schemes);
142
+ return withCustomProps(schemes.filter((s) => jskos.isContainedIn(s, this.schemes)), schemes);
144
143
  } else {
145
144
  return schemes;
146
145
  }
@@ -191,13 +190,10 @@ class ConceptApiProvider extends BaseProvider {
191
190
  if (!url) {
192
191
  throw new errors.MissingApiUrlError();
193
192
  }
194
- if (!concepts) {
195
- throw new errors.InvalidOrMissingParameterError({ parameter: "concepts" });
196
- }
197
193
  if (!Array.isArray(concepts)) {
198
- concepts = [concepts];
194
+ concepts = concepts ? [concepts] : [];
199
195
  }
200
- let uris = concepts.map((concept) => concept.uri).filter((uri) => uri != null);
196
+ const uris = concepts.map((concept) => concept.uri).filter((uri) => uri != null);
201
197
  return this.axios({
202
198
  ...config,
203
199
  method: "get",
@@ -205,7 +201,7 @@ class ConceptApiProvider extends BaseProvider {
205
201
  params: {
206
202
  ...this._defaultParams,
207
203
  // ? What should the default limit be?
208
- limit: 500,
204
+ limit: 100,
209
205
  ...config.params || {},
210
206
  uri: uris.join("|")
211
207
  }
@@ -401,7 +397,8 @@ class ConceptApiProvider extends BaseProvider {
401
397
  }
402
398
  const schemeUri = scheme && await this._getSchemeUri(scheme);
403
399
  if (schemeUri) {
404
- _.set(config, "params.uri", schemeUri);
400
+ config.params ||= {};
401
+ config.params.uri = schemeUri;
405
402
  }
406
403
  let types = await this.axios({
407
404
  ...config,
@@ -1,6 +1,5 @@
1
1
  import BaseProvider from "./base-provider.js";
2
2
  import jskos from "jskos-tools";
3
- import * as _ from "../utils/lodash.js";
4
3
  import * as errors from "../errors/index.js";
5
4
  class LabelSearchSuggestionProvider extends BaseProvider {
6
5
  static supports = {
@@ -19,7 +18,7 @@ class LabelSearchSuggestionProvider extends BaseProvider {
19
18
  * @returns {boolean}
20
19
  */
21
20
  supportsScheme(scheme) {
22
- return super.supportsScheme(scheme) && _.get(scheme, "_registry.has.search", false);
21
+ return super.supportsScheme(scheme) && scheme?._registry?.has?.search;
23
22
  }
24
23
  /**
25
24
  * Returns a list of mappings.
@@ -53,12 +52,12 @@ class LabelSearchSuggestionProvider extends BaseProvider {
53
52
  toResult = toResult.filter((m) => !fromResult.find((n) => jskos.compareMappingMembers(m, n)));
54
53
  while (fromResult.length + toResult.length > limit) {
55
54
  if (toResult.length >= fromResult.length) {
56
- toResult = toResult.slice(0, -1);
55
+ toResult.pop();
57
56
  } else {
58
- fromResult = fromResult.slice(0, -1);
57
+ fromResult.pop();
59
58
  }
60
59
  }
61
- return _.union(fromResult, toResult);
60
+ return [...fromResult, ...toResult];
62
61
  }
63
62
  /**
64
63
  * Internal function to get mapping recommendations for a certain concept with sourceScheme and targetScheme.
@@ -135,7 +134,7 @@ class LabelSearchSuggestionProvider extends BaseProvider {
135
134
  if (resultsFromCache && resultsFromCache._limit >= limit) {
136
135
  return resultsFromCache;
137
136
  }
138
- const registry = _.get(targetScheme, "_registry");
137
+ const registry = targetScheme?._registry;
139
138
  if (!registry || registry.has.search === false) {
140
139
  return [];
141
140
  }
@@ -1,6 +1,5 @@
1
1
  import BaseProvider from "./base-provider.js";
2
2
  import jskos from "jskos-tools";
3
- import * as _ from "../utils/lodash.js";
4
3
  import localforage from "localforage";
5
4
  import { v4 as uuid } from "uuid";
6
5
  import * as errors from "../errors/index.js";
@@ -69,7 +68,7 @@ class LocalMappingsProvider extends BaseProvider {
69
68
  * @private
70
69
  */
71
70
  _getMappingsQueue() {
72
- let last = _.last(this.queue) || Promise.resolve();
71
+ let last = this.queue.slice(-1)[0] || Promise.resolve();
73
72
  return new Promise((resolve) => {
74
73
  function defer() {
75
74
  let res, rej;
@@ -118,25 +117,25 @@ class LocalMappingsProvider extends BaseProvider {
118
117
  async getMappings({ from, fromScheme, to, toScheme, creator, type, partOf, offset, limit, direction, mode, identifier, uri } = {}) {
119
118
  let params = {};
120
119
  if (from) {
121
- params.from = _.isString(from) ? from : from.uri;
120
+ params.from = typeof from === "string" ? from : from.uri;
122
121
  }
123
122
  if (fromScheme) {
124
- params.fromScheme = _.isString(fromScheme) ? { uri: fromScheme } : fromScheme;
123
+ params.fromScheme = typeof fromScheme === "string" ? { uri: fromScheme } : fromScheme;
125
124
  }
126
125
  if (to) {
127
- params.to = _.isString(to) ? to : to.uri;
126
+ params.to = typeof to === "string" ? to : to.uri;
128
127
  }
129
128
  if (toScheme) {
130
- params.toScheme = _.isString(toScheme) ? { uri: toScheme } : toScheme;
129
+ params.toScheme = typeof toScheme === "string" ? { uri: toScheme } : toScheme;
131
130
  }
132
131
  if (creator) {
133
- params.creator = _.isString(creator) ? creator : jskos.prefLabel(creator);
132
+ params.creator = typeof creator === "string" ? creator : jskos.prefLabel(creator);
134
133
  }
135
134
  if (type) {
136
- params.type = _.isString(type) ? type : type.uri;
135
+ params.type = typeof type === "string" ? type : type.uri;
137
136
  }
138
137
  if (partOf) {
139
- params.partOf = _.isString(partOf) ? partOf : partOf.uri;
138
+ params.partOf = typeof partOf === "string" ? partOf : partOf.uri;
140
139
  }
141
140
  if (offset) {
142
141
  params.offset = offset;
@@ -1,8 +1,7 @@
1
1
  import BaseProvider from "./base-provider.js";
2
2
  import jskos from "jskos-tools";
3
- import * as _ from "../utils/lodash.js";
4
3
  import * as errors from "../errors/index.js";
5
- import * as utils from "../utils/index.js";
4
+ import { concatUrl } from "../utils/index.js";
6
5
  class MappingsApiProvider extends BaseProvider {
7
6
  static supports = {
8
7
  mappings: true,
@@ -14,7 +13,7 @@ class MappingsApiProvider extends BaseProvider {
14
13
  */
15
14
  _prepare() {
16
15
  if (this._api.api && this._api.status === void 0) {
17
- this._api.status = utils.concatUrl(this._api.api, "/status");
16
+ this._api.status = concatUrl(this._api.api, "/status");
18
17
  }
19
18
  }
20
19
  /**
@@ -29,33 +28,33 @@ class MappingsApiProvider extends BaseProvider {
29
28
  };
30
29
  for (let key of Object.keys(endpoints)) {
31
30
  if (this._api[key] === void 0) {
32
- this._api[key] = utils.concatUrl(this._api.api, endpoints[key]);
31
+ this._api[key] = concatUrl(this._api.api, endpoints[key]);
33
32
  }
34
33
  }
35
34
  }
36
35
  this.has.mappings = this._api.mappings ? {} : false;
37
36
  if (this.has.mappings) {
38
- this.has.mappings.read = !!_.get(this._config, "mappings.read", true);
39
- this.has.mappings.create = !!_.get(this._config, "mappings.create");
40
- this.has.mappings.update = !!_.get(this._config, "mappings.update");
41
- this.has.mappings.delete = !!_.get(this._config, "mappings.delete");
42
- this.has.mappings.anonymous = !!_.get(this._config, "mappings.anonymous");
37
+ this.has.mappings.read = !!(this._config?.mappings?.read ?? true);
38
+ this.has.mappings.create = !!this._config?.mappings?.create;
39
+ this.has.mappings.update = !!this._config?.mappings?.update;
40
+ this.has.mappings.delete = !!this._config?.mappings?.delete;
41
+ this.has.mappings.anonymous = !!this._config?.mappings?.anonymous;
43
42
  }
44
43
  this.has.concordances = this._api.concordances ? {} : false;
45
44
  if (this.has.concordances) {
46
- this.has.concordances.read = !!_.get(this._config, "concordances.read");
47
- this.has.concordances.create = !!_.get(this._config, "concordances.create");
48
- this.has.concordances.update = !!_.get(this._config, "concordances.update");
49
- this.has.concordances.delete = !!_.get(this._config, "concordances.delete");
45
+ this.has.concordances.read = !!this._config?.concordances?.read;
46
+ this.has.concordances.create = !!this._config?.concordances?.create;
47
+ this.has.concordances.update = !!this._config?.concordances?.update;
48
+ this.has.concordances.delete = !!this._config?.concordances?.delete;
50
49
  }
51
50
  this.has.annotations = this._api.annotations ? {} : false;
52
51
  if (this.has.annotations) {
53
- this.has.annotations.read = !!_.get(this._config, "annotations.read");
54
- this.has.annotations.create = !!_.get(this._config, "annotations.create");
55
- this.has.annotations.update = !!_.get(this._config, "annotations.update");
56
- this.has.annotations.delete = !!_.get(this._config, "annotations.delete");
52
+ this.has.annotations.read = !!this._config?.annotations?.read;
53
+ this.has.annotations.create = !!this._config?.annotations?.create;
54
+ this.has.annotations.update = !!this._config?.annotations?.update;
55
+ this.has.annotations.delete = !!this._config?.annotations?.delete;
57
56
  }
58
- this.has.auth = _.get(this._config, "auth.key") != null;
57
+ this.has.auth = this._config?.auth?.key != null;
59
58
  this._defaultParams = {
60
59
  properties: "annotations"
61
60
  };
@@ -84,7 +83,7 @@ class MappingsApiProvider extends BaseProvider {
84
83
  }
85
84
  });
86
85
  } catch (error) {
87
- if (_.get(error, "response.status") == 404) {
86
+ if (error?.response?.status == 404) {
88
87
  return null;
89
88
  }
90
89
  throw error;
@@ -99,25 +98,25 @@ class MappingsApiProvider extends BaseProvider {
99
98
  async getMappings({ from, fromScheme, to, toScheme, creator, type, partOf, offset, limit, direction, mode, identifier, cardinality, annotatedBy, annotatedFor, annotatedWith, sort, order, ...config }) {
100
99
  let params = {}, url = this._api.mappings;
101
100
  if (from) {
102
- params.from = _.isString(from) ? from : from.uri;
101
+ params.from = typeof from === "string" ? from : from.uri;
103
102
  }
104
103
  if (fromScheme) {
105
- params.fromScheme = _.isString(fromScheme) ? fromScheme : fromScheme.uri;
104
+ params.fromScheme = typeof fromScheme === "string" ? fromScheme : fromScheme.uri;
106
105
  }
107
106
  if (to) {
108
- params.to = _.isString(to) ? to : to.uri;
107
+ params.to = typeof to === "string" ? to : to.uri;
109
108
  }
110
109
  if (toScheme) {
111
- params.toScheme = _.isString(toScheme) ? toScheme : toScheme.uri;
110
+ params.toScheme = typeof toScheme === "string" ? toScheme : toScheme.uri;
112
111
  }
113
112
  if (creator) {
114
- params.creator = _.isString(creator) ? creator : jskos.prefLabel(creator);
113
+ params.creator = typeof creator === "string" ? creator : jskos.prefLabel(creator);
115
114
  }
116
115
  if (type) {
117
- params.type = _.isString(type) ? type : type.uri;
116
+ params.type = typeof type === "string" ? type : type.uri;
118
117
  }
119
118
  if (partOf) {
120
- params.partOf = _.isString(partOf) ? partOf : partOf.uri;
119
+ params.partOf = typeof partOf === "string" ? partOf : partOf.uri;
121
120
  }
122
121
  if (offset) {
123
122
  params.offset = offset;
@@ -226,15 +225,15 @@ class MappingsApiProvider extends BaseProvider {
226
225
  if (!mapping) {
227
226
  throw new errors.InvalidOrMissingParameterError({ parameter: "mapping" });
228
227
  }
229
- const uri = mapping.uri;
230
- if (!uri || !uri.startsWith(this._api.mappings)) {
228
+ if (!mapping.uri?.startsWith(this._api.mappings)) {
231
229
  throw new errors.InvalidOrMissingParameterError({ parameter: "mapping", message: "URI doesn't seem to be part of this registry." });
232
230
  }
231
+ const { uri, ...data } = mapping;
233
232
  return this.axios({
234
233
  ...config,
235
234
  method: "patch",
236
235
  url: uri,
237
- data: _.omit(mapping, "uri"),
236
+ data,
238
237
  params: {
239
238
  ...this._defaultParams,
240
239
  ...config.params || {}
@@ -272,7 +271,8 @@ class MappingsApiProvider extends BaseProvider {
272
271
  */
273
272
  async getAnnotations({ target, ...config }) {
274
273
  if (target) {
275
- _.set(config, "params.target", target);
274
+ config.params ||= {};
275
+ config.params.target = target;
276
276
  }
277
277
  return this.axios({
278
278
  ...config,
@@ -424,15 +424,15 @@ class MappingsApiProvider extends BaseProvider {
424
424
  if (!concordance) {
425
425
  throw new errors.InvalidOrMissingParameterError({ parameter: "concordance" });
426
426
  }
427
- const uri = concordance.uri;
428
- if (!uri || !uri.startsWith(this._api.concordances)) {
427
+ if (!concordance.uri?.startsWith(this._api.concordances)) {
429
428
  throw new errors.InvalidOrMissingParameterError({ parameter: "concordance", message: "URI doesn't seem to be part of this registry." });
430
429
  }
430
+ const { uri, ...data } = concordance;
431
431
  return this.axios({
432
432
  ...config,
433
433
  method: "patch",
434
434
  url: uri,
435
- data: _.omit(concordance, "uri"),
435
+ data,
436
436
  params: {
437
437
  ...this._defaultParams,
438
438
  ...config.params || {}
@@ -1,5 +1,4 @@
1
1
  import BaseProvider from "./base-provider.js";
2
- import * as _ from "../utils/lodash.js";
3
2
  import * as errors from "../errors/index.js";
4
3
  import jskos from "jskos-tools";
5
4
  import FlexSearch from "flexsearch";
@@ -154,7 +153,7 @@ class MyCoReProvider extends BaseProvider {
154
153
  return data[this._scheme.uri].topConcepts.map(this._removeNarrower);
155
154
  }
156
155
  async getConcepts({ concepts, ...config }) {
157
- if (!_.isArray(concepts)) {
156
+ if (!Array.isArray(concepts)) {
158
157
  concepts = [concepts];
159
158
  }
160
159
  if (!this._scheme) {