cocoda-sdk 3.6.1 → 3.6.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.
- package/README.md +96 -87
- package/dist/cjs/index.cjs +97 -47
- package/dist/cocoda-sdk.js +7 -7
- package/dist/cocoda-sdk.js.map +3 -3
- package/dist/esm/lib/CocodaSDK.js +18 -11
- package/dist/esm/providers/base-provider.js +3 -2
- package/dist/esm/providers/concept-api-provider.js +34 -8
- package/dist/esm/providers/ols-api-provider.js +8 -17
- package/dist/esm/providers/skosmos-api-provider.js +33 -9
- package/dist/esm/utils/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
- [Install](#install)
|
|
12
12
|
- [Usage](#usage)
|
|
13
13
|
- [Import](#import)
|
|
14
|
+
- [Multiple Instances](#multiple-instances)
|
|
14
15
|
- [Configuration](#configuration)
|
|
15
|
-
- [Registries](#registries)
|
|
16
16
|
- [Providers](#providers)
|
|
17
|
-
- [
|
|
17
|
+
- [Services](#services)
|
|
18
18
|
- [Authenticated Requests](#authenticated-requests)
|
|
19
19
|
- [API](#api)
|
|
20
20
|
- [General](#general)
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
- [Concepts](#concepts)
|
|
23
23
|
- [Concordances](#concordances)
|
|
24
24
|
- [Mappings](#mappings)
|
|
25
|
+
- [Registries](#registries)
|
|
25
26
|
- [Annotations](#annotations)
|
|
26
27
|
- [Occurrences](#occurrences)
|
|
27
28
|
- [Types](#types)
|
|
@@ -60,6 +61,14 @@ cocoda-sdk also exports some other members:
|
|
|
60
61
|
- `addAllProviders` - a method that adds all avaiable providers to an instance
|
|
61
62
|
- Can be called without parameters to add to the default instance. Useful if you need all providers.
|
|
62
63
|
|
|
64
|
+
### Multiple Instances
|
|
65
|
+
|
|
66
|
+
The `createInstance` method can be used to create a new and independent instance with a separate configuration if needed:
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
const newCdk = cdk.createInstance(config)
|
|
70
|
+
```
|
|
71
|
+
|
|
63
72
|
### Configuration
|
|
64
73
|
cocoda-sdk can be configured after import:
|
|
65
74
|
|
|
@@ -75,76 +84,9 @@ import { cdk } from "cocoda-sdk"
|
|
|
75
84
|
await cdk.loadConfig("https://raw.githubusercontent.com/gbv/cocoda/dev/config/cocoda.default.json")
|
|
76
85
|
```
|
|
77
86
|
|
|
78
|
-
The configuration is a JSON object corresponding the the [configuration format of Cocoda](https://github.com/gbv/cocoda#configuration). In particular, the configuration contains an array property
|
|
79
|
-
|
|
80
|
-
If you only use cocoda-sdk with a single registry, configuration might not be necessary (see below).
|
|
81
|
-
|
|
82
|
-
### Registries
|
|
83
|
-
|
|
84
|
-
A registry is an individual source of data, for instance a set of concept schemes available from a specific terminology service. The simplest registry consists only of a unique identifier (`uri`) and the name of the access provider (`provider`):
|
|
85
|
-
|
|
86
|
-
```json
|
|
87
|
-
{
|
|
88
|
-
"uri": "http://coli-conc.gbv.de/registry/local-mappings",
|
|
89
|
-
"provider": "LocalMappings"
|
|
90
|
-
}
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
For most providers the configuration should use the BARTOC vocabulary API type URI instead:
|
|
94
|
-
|
|
95
|
-
```json
|
|
96
|
-
{
|
|
97
|
-
"api": "http://bartoc.org/api-type/skosmos",
|
|
98
|
-
"endpoint": "https://www.loterre.fr/skosmos/905/"
|
|
99
|
-
}
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
A list of available providers can be found [below](#providers). Most providers need additional properties to work correctly.
|
|
103
|
-
|
|
104
|
-
#### Endpoint Determination
|
|
105
|
-
For many providers, you need to specify one or more endpoints on the registry object for it to work. There are, however, three steps in which these endpoints are determined:
|
|
106
|
-
|
|
107
|
-
1. By explicitly specifying an endpoint on the registry object.
|
|
108
|
-
2. By performaning a request to the provider's `/status` endpoint and parsing its result (which is done in `registry.init()`).
|
|
109
|
-
3. By implication using the `api` base URL.
|
|
110
|
-
|
|
111
|
-
Values set earlier in these steps will never be overwritten by later steps. That means to disable an endpoint explicitly, you can set it to `null` when configuring the registry. Also, if step 2 is successful, it will be assumed that no further endpoints exist and all missing endpoints will be set to `null`, i.e. essentially skipping step 3.
|
|
112
|
-
|
|
113
|
-
#### Using a Single Registry
|
|
114
|
-
|
|
115
|
-
If you only have a single registry you want to access, you can initialize it as follows:
|
|
116
|
-
|
|
117
|
-
```js
|
|
118
|
-
import { cdk, LocalMappingsProvider } from "cocoda-sdk"
|
|
119
|
-
// Local mappings are not included by default
|
|
120
|
-
cdk.addProvider(LocalMappingsProvider)
|
|
121
|
-
const registry = cdk.initializeRegistry({
|
|
122
|
-
uri: "http://coli-conc.gbv.de/registry/local-mappings",
|
|
123
|
-
provider: "LocalMappings"
|
|
124
|
-
})
|
|
125
|
-
// Now, access methods are available on the registry:
|
|
126
|
-
registry.getMappings()
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
Most Providers can also be initialized with API Type URI from [BARTOC vocabulary API types list](https://bartoc.org/en/node/20002):
|
|
130
|
-
|
|
131
|
-
```js
|
|
132
|
-
const registry = cdk.initializeRegistry({
|
|
133
|
-
api: "http://bartoc.org/api-type/skosmos",
|
|
134
|
-
endpoint: "https://www.loterre.fr/skosmos/905/"
|
|
135
|
-
})
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
It's also possible to directly use Registry classes.
|
|
139
|
-
|
|
140
|
-
#### Using Registries From a Configuration
|
|
87
|
+
The configuration is a JSON object corresponding the the [configuration format of Cocoda](https://github.com/gbv/cocoda#configuration). In particular, the configuration contains an array property `registries` holding a list of [services](#services).
|
|
141
88
|
|
|
142
|
-
If you
|
|
143
|
-
|
|
144
|
-
```js
|
|
145
|
-
// After setting up cdk
|
|
146
|
-
const registry = cdk.getRegistryForUri("...")
|
|
147
|
-
```
|
|
89
|
+
If you use cocoda-sdk [with one single service](#using-a-single-service) only, configuration might not be necessary.
|
|
148
90
|
|
|
149
91
|
### Providers
|
|
150
92
|
|
|
@@ -166,10 +108,10 @@ The following providers are also exported, but have to be added via `cdk.addProv
|
|
|
166
108
|
- `LobidApi` - access to GND via [lobid](https://lobid.org)
|
|
167
109
|
- **This integration is currently experimental.**
|
|
168
110
|
- `MyCoRe` - access to vocabularies via [MyCoRe](https://www.mycore.de/)
|
|
169
|
-
- **This integration is currently experimental. Only one vocabulary per
|
|
111
|
+
- **This integration is currently experimental. Only one vocabulary per service is supported. Not recommended for large vocabularies as all of the vocabulary data is loaded and kept in memory.**
|
|
170
112
|
- `ReconciliationApi` - access to mapping suggestions via a [Reconciliation Service API](https://reconciliation-api.github.io/specs/draft/)
|
|
171
113
|
- `OccurrencesApi` - access to concept occurrences via [occurrences-api](https://github.com/gbv/occurrences-api) (will be changed to [occurrences-server](https://github.com/gbv/occurrences-server) in the future)
|
|
172
|
-
- `LabelSearchSuggestion` - access to mapping suggestions using other
|
|
114
|
+
- `LabelSearchSuggestion` - access to mapping suggestions using other services' search endpoints (using [jskos-server])
|
|
173
115
|
- `ModApi` - (experimental) access to concept schemes and concepts via a [MOD](https://github.com/FAIR-IMPACT/MOD) API
|
|
174
116
|
|
|
175
117
|
To add a provider, append `Provider` to its name and import it together with `cdk`:
|
|
@@ -206,12 +148,75 @@ cdk.addProvider(CustomProvider)
|
|
|
206
148
|
|
|
207
149
|
See [`examples/custom-provider.js`](https://github.com/gbv/cocoda-sdk/blob/main/examples/custom-provider.js) for an extended example.
|
|
208
150
|
|
|
209
|
-
###
|
|
151
|
+
### Services
|
|
210
152
|
|
|
211
|
-
|
|
153
|
+
*Services have also been called registries until cocoda-sdk 3.7.0 but the name was changed to not confuse with JSKOS Registries!*
|
|
154
|
+
|
|
155
|
+
A service is an individual source of data, for instance a set of concept schemes available from a specific terminology web service.
|
|
156
|
+
|
|
157
|
+
For most providers the service configuration must include an `api` URI from [BARTOC vocabulary API types](http://bartoc.org/en/node/20002):
|
|
158
|
+
|
|
159
|
+
```json
|
|
160
|
+
{
|
|
161
|
+
"api": "http://bartoc.org/api-type/skosmos",
|
|
162
|
+
"endpoint": "https://www.loterre.fr/skosmos/905/"
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Some services can also be configured with the name of the access provider (`provider`) instead:
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"provider": "LocalMappings"
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
A list of available providers can be found [below](#providers). Most providers need additional properties to work correctly.
|
|
175
|
+
|
|
176
|
+
#### Endpoint Determination
|
|
177
|
+
|
|
178
|
+
For many providers, you need to specify one or more endpoints on the service object for it to work. There are, however, three steps in which these endpoints are determined:
|
|
179
|
+
|
|
180
|
+
1. By explicitly specifying an endpoint on the service object.
|
|
181
|
+
2. By performaning a request to the provider's `/status` endpoint and parsing its result (which is done in `service.init()`).
|
|
182
|
+
3. By implication using the `api` base URL.
|
|
183
|
+
|
|
184
|
+
Values set earlier in these steps will never be overwritten by later steps. That means to disable an endpoint explicitly, you can set it to `null` when configuring the service. Also, if step 2 is successful, it will be assumed that no further endpoints exist and all missing endpoints will be set to `null`, i.e. essentially skipping step 3.
|
|
185
|
+
|
|
186
|
+
#### Using a Single Service
|
|
187
|
+
|
|
188
|
+
If you only have a single service you want to access, you can initialize it as follows:
|
|
212
189
|
|
|
213
190
|
```js
|
|
214
|
-
|
|
191
|
+
import { cdk, LocalMappingsProvider } from "cocoda-sdk"
|
|
192
|
+
// Local mappings are not included by default
|
|
193
|
+
cdk.addProvider(LocalMappingsProvider)
|
|
194
|
+
const service = cdk.initializeRegistry({
|
|
195
|
+
uri: "http://coli-conc.gbv.de/registry/local-mappings",
|
|
196
|
+
provider: "LocalMappings"
|
|
197
|
+
})
|
|
198
|
+
// Now, access methods are available on the service:
|
|
199
|
+
service.getMappings()
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Most Providers can also be initialized with API Type URI from [BARTOC vocabulary API types list](https://bartoc.org/en/node/20002):
|
|
203
|
+
|
|
204
|
+
```js
|
|
205
|
+
const service = cdk.initializeRegistry({
|
|
206
|
+
api: "http://bartoc.org/api-type/skosmos",
|
|
207
|
+
endpoint: "https://www.loterre.fr/skosmos/905/"
|
|
208
|
+
})
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
It's also possible to directly use Provider classes.
|
|
212
|
+
|
|
213
|
+
#### Using services from a configuration
|
|
214
|
+
|
|
215
|
+
If you initialize cocoda-sdk with a [configuration](#configuration), it will initialize all included services automatically. Those services are then accessible via `cdk.config.registries`. Alternatively, you can retrieve services by URI:
|
|
216
|
+
|
|
217
|
+
```js
|
|
218
|
+
// After setting up cdk
|
|
219
|
+
const service = cdk.getServiceForUri("...")
|
|
215
220
|
```
|
|
216
221
|
|
|
217
222
|
### Authenticated Requests
|
|
@@ -242,14 +247,14 @@ See also the code comments inside the example.
|
|
|
242
247
|
<script src="https://cdn.jsdelivr.net/npm/gbv-login-client@0"></script>
|
|
243
248
|
<script src="https://cdn.jsdelivr.net/npm/cocoda-sdk@2"></script>
|
|
244
249
|
<script>
|
|
245
|
-
// Initialize mapping
|
|
246
|
-
const
|
|
250
|
+
// Initialize mapping service at localhost:3000
|
|
251
|
+
const service = CDK.cdk.initializeRegistry({
|
|
247
252
|
provider: "MappingsApi",
|
|
248
253
|
uri: "local:mappings",
|
|
249
254
|
status: "http://localhost:3000/status",
|
|
250
255
|
})
|
|
251
256
|
// Note: This is an async function, so we might be dealing with race conditions here.
|
|
252
|
-
|
|
257
|
+
service.init()
|
|
253
258
|
// Create client to connect to Login Server at localhost:3004
|
|
254
259
|
let client = new LoginClient("localhost:3004", { ssl: false })
|
|
255
260
|
let user
|
|
@@ -258,26 +263,26 @@ client.addEventListener(null, event => {
|
|
|
258
263
|
switch (event.type) {
|
|
259
264
|
case LoginClient.events.connect:
|
|
260
265
|
// At this point, we don't know whether the user has logged in yet, but we can try
|
|
261
|
-
console.log(
|
|
266
|
+
console.log(service.isAuthorizedFor({ type: "mappings", action: "create", user }))
|
|
262
267
|
break
|
|
263
268
|
case LoginClient.events.login:
|
|
264
269
|
// Update user
|
|
265
270
|
user = event.user
|
|
266
271
|
// Now we know the user is logged in, so this should return true
|
|
267
272
|
// Note that if the user is already logged in, this event will fire before connected
|
|
268
|
-
console.log(
|
|
273
|
+
console.log(service.isAuthorizedFor({ type: "mappings", action: "create", user }))
|
|
269
274
|
break
|
|
270
275
|
case LoginClient.events.update:
|
|
271
276
|
// Update user
|
|
272
277
|
user = event.user
|
|
273
278
|
break
|
|
274
279
|
case LoginClient.events.about:
|
|
275
|
-
// Register the server's public key in the
|
|
276
|
-
|
|
280
|
+
// Register the server's public key in the service
|
|
281
|
+
service.setAuth({ key: event.publicKey })
|
|
277
282
|
break
|
|
278
283
|
case LoginClient.events.token:
|
|
279
|
-
// On every token update, update the token in the
|
|
280
|
-
|
|
284
|
+
// On every token update, update the token in the service
|
|
285
|
+
service.setAuth({ bearerToken: event.token })
|
|
281
286
|
break
|
|
282
287
|
}
|
|
283
288
|
})
|
|
@@ -291,7 +296,7 @@ client.connect()
|
|
|
291
296
|
Note that for a real application, there are more things necessary:
|
|
292
297
|
- Track whether the client is connected and whether the user is logged in
|
|
293
298
|
- Tell the user to log in if necessary
|
|
294
|
-
- Check if the `
|
|
299
|
+
- Check if the `init()` call finished before making requests (might not be necessary because requests will wait for initialization)
|
|
295
300
|
- Error handling
|
|
296
301
|
- etc.
|
|
297
302
|
|
|
@@ -303,7 +308,7 @@ You can find more in-depth examples here:
|
|
|
303
308
|
|
|
304
309
|
## API
|
|
305
310
|
|
|
306
|
-
A cocoda-sdk instance itself offers only a handful of methods. The actual access to APIs happens through [
|
|
311
|
+
A cocoda-sdk instance itself offers only a handful of methods. The actual access to APIs happens through [services](#services). The following list of methods assume either an instance of cocoda-sdk (`cdk.someMethod`) or an initialized service (`service.someMethod`). Documentation for service methods is on a per-provider basis. While the API should be the same for a particular methods across providers, the details on how to use it might differ.
|
|
307
312
|
|
|
308
313
|
Please refer to the [documentation](https://gbv.github.io/cocoda-sdk/CocodaSDK.html) for a list of methods of for cocoda-sdk instances.
|
|
309
314
|
|
|
@@ -429,6 +434,10 @@ Please refer to the [documentation](https://gbv.github.io/cocoda-sdk/CocodaSDK.h
|
|
|
429
434
|
#### deleteMappings
|
|
430
435
|
- [BaseProvider - deleteMappings](https://gbv.github.io/cocoda-sdk/BaseProvider.html#deleteMappings)
|
|
431
436
|
|
|
437
|
+
### Registries
|
|
438
|
+
|
|
439
|
+
- [getRegistries](https://gbv.github.io/cocoda-sdk/ConceptApiProvider.html#getRegistries)
|
|
440
|
+
|
|
432
441
|
### Annotations
|
|
433
442
|
|
|
434
443
|
- [getAnnotations](https://gbv.github.io/cocoda-sdk/MappingsApiProvider.html#getAnnotations)
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -291,6 +291,7 @@ function withCustomProps(arr, from) {
|
|
|
291
291
|
return arr;
|
|
292
292
|
}
|
|
293
293
|
var listOfCapabilities = [
|
|
294
|
+
"registries",
|
|
294
295
|
"schemes",
|
|
295
296
|
"top",
|
|
296
297
|
"data",
|
|
@@ -398,7 +399,8 @@ var BaseProvider = class {
|
|
|
398
399
|
annotations: registry.annotations,
|
|
399
400
|
occurrences: registry.occurrences,
|
|
400
401
|
reconcile: registry.reconcile,
|
|
401
|
-
api: registry.endpoint || registry.api
|
|
402
|
+
api: registry.endpoint || registry.api,
|
|
403
|
+
registries: registry.registries
|
|
402
404
|
};
|
|
403
405
|
this._config = {};
|
|
404
406
|
this.setRetryConfig();
|
|
@@ -436,7 +438,7 @@ var BaseProvider = class {
|
|
|
436
438
|
}
|
|
437
439
|
return data3;
|
|
438
440
|
}, (error) => {
|
|
439
|
-
const count = error.config
|
|
441
|
+
const count = error.config?._retryCount ?? 0;
|
|
440
442
|
const method = error.config.method;
|
|
441
443
|
const statusCode = error.response?.status;
|
|
442
444
|
if (this._retryConfig.methods.includes(method) && this._retryConfig.statusCodes.includes(statusCode) && count < this._retryConfig.count) {
|
|
@@ -1942,7 +1944,8 @@ var ConceptApiProvider = class extends BaseProvider {
|
|
|
1942
1944
|
types: true,
|
|
1943
1945
|
suggest: true,
|
|
1944
1946
|
search: true,
|
|
1945
|
-
auth: true
|
|
1947
|
+
auth: true,
|
|
1948
|
+
registries: true
|
|
1946
1949
|
};
|
|
1947
1950
|
/**
|
|
1948
1951
|
* @private
|
|
@@ -1966,7 +1969,8 @@ var ConceptApiProvider = class extends BaseProvider {
|
|
|
1966
1969
|
ancestors: "/ancestors",
|
|
1967
1970
|
types: "/types",
|
|
1968
1971
|
suggest: "/suggest",
|
|
1969
|
-
search: "/search"
|
|
1972
|
+
search: "/search",
|
|
1973
|
+
registries: "/registries"
|
|
1970
1974
|
};
|
|
1971
1975
|
for (let key of Object.keys(endpoints)) {
|
|
1972
1976
|
if (this._api[key] === void 0) {
|
|
@@ -1974,6 +1978,7 @@ var ConceptApiProvider = class extends BaseProvider {
|
|
|
1974
1978
|
}
|
|
1975
1979
|
}
|
|
1976
1980
|
}
|
|
1981
|
+
this.has.registries = !!this._api.registries;
|
|
1977
1982
|
this.has.schemes = !!this._api.schemes;
|
|
1978
1983
|
if (!this.has.schemes && Array.isArray(this.schemes)) {
|
|
1979
1984
|
this.has.schemes = true;
|
|
@@ -2041,6 +2046,32 @@ var ConceptApiProvider = class extends BaseProvider {
|
|
|
2041
2046
|
return null;
|
|
2042
2047
|
}
|
|
2043
2048
|
}
|
|
2049
|
+
/**
|
|
2050
|
+
* Returns all concept registries.
|
|
2051
|
+
*
|
|
2052
|
+
* @param {Object} config
|
|
2053
|
+
* @returns {Object[]} array of JSKOS concept registry objects
|
|
2054
|
+
*/
|
|
2055
|
+
async getRegistries(config = {}) {
|
|
2056
|
+
if (!this._api.registries) {
|
|
2057
|
+
if (Array.isArray(this.registries)) {
|
|
2058
|
+
return this.registries;
|
|
2059
|
+
}
|
|
2060
|
+
throw new MissingApiUrlError();
|
|
2061
|
+
}
|
|
2062
|
+
const registries = await this.axios({
|
|
2063
|
+
...config,
|
|
2064
|
+
method: "get",
|
|
2065
|
+
url: this._api.registries,
|
|
2066
|
+
params: {
|
|
2067
|
+
...this._defaultParams,
|
|
2068
|
+
// ? What should the default limit be?
|
|
2069
|
+
limit: 500,
|
|
2070
|
+
...config.params || {}
|
|
2071
|
+
}
|
|
2072
|
+
});
|
|
2073
|
+
return registries;
|
|
2074
|
+
}
|
|
2044
2075
|
/**
|
|
2045
2076
|
* Returns all concept schemes.
|
|
2046
2077
|
*
|
|
@@ -2117,13 +2148,10 @@ var ConceptApiProvider = class extends BaseProvider {
|
|
|
2117
2148
|
if (!url) {
|
|
2118
2149
|
throw new MissingApiUrlError();
|
|
2119
2150
|
}
|
|
2120
|
-
if (!concepts) {
|
|
2121
|
-
throw new InvalidOrMissingParameterError({ parameter: "concepts" });
|
|
2122
|
-
}
|
|
2123
2151
|
if (!Array.isArray(concepts)) {
|
|
2124
|
-
concepts = [concepts];
|
|
2152
|
+
concepts = concepts ? [concepts] : [];
|
|
2125
2153
|
}
|
|
2126
|
-
|
|
2154
|
+
const uris = concepts.map((concept) => concept.uri).filter((uri) => uri != null);
|
|
2127
2155
|
return this.axios({
|
|
2128
2156
|
...config,
|
|
2129
2157
|
method: "get",
|
|
@@ -2131,7 +2159,7 @@ var ConceptApiProvider = class extends BaseProvider {
|
|
|
2131
2159
|
params: {
|
|
2132
2160
|
...this._defaultParams,
|
|
2133
2161
|
// ? What should the default limit be?
|
|
2134
|
-
limit:
|
|
2162
|
+
limit: 100,
|
|
2135
2163
|
...config.params || {},
|
|
2136
2164
|
uri: uris.join("|")
|
|
2137
2165
|
}
|
|
@@ -2709,7 +2737,7 @@ var SkosmosApiProvider = class extends BaseProvider {
|
|
|
2709
2737
|
* @private
|
|
2710
2738
|
*/
|
|
2711
2739
|
_getApiUrl(scheme, endpoint, params) {
|
|
2712
|
-
const VOCID = scheme
|
|
2740
|
+
const VOCID = scheme?.VOCID || this.schemes.find((s) => import_jskos_tools8.default.compare(s, scheme))?.VOCID;
|
|
2713
2741
|
if (!VOCID) {
|
|
2714
2742
|
throw new InvalidOrMissingParameterError({ parameter: "scheme", message: "Missing scheme or VOCID property on scheme" });
|
|
2715
2743
|
}
|
|
@@ -2843,6 +2871,30 @@ var SkosmosApiProvider = class extends BaseProvider {
|
|
|
2843
2871
|
if (!concept.type.length) {
|
|
2844
2872
|
concept.type = ["http://www.w3.org/2004/02/skos/core#Concept"];
|
|
2845
2873
|
}
|
|
2874
|
+
const map = {
|
|
2875
|
+
"skos:definition": "definition",
|
|
2876
|
+
"skos:note": "note",
|
|
2877
|
+
"skos:scopeNote": "scopeNote",
|
|
2878
|
+
"skos:example": "example",
|
|
2879
|
+
"skos:historyNote": "historyNote",
|
|
2880
|
+
"skos:editorialNote": "editorialNote",
|
|
2881
|
+
"skos:changeNote": "changeNote"
|
|
2882
|
+
};
|
|
2883
|
+
for (let key in map) {
|
|
2884
|
+
let notes = skosmosConcept[key] || [];
|
|
2885
|
+
if (!Array.isArray(notes)) {
|
|
2886
|
+
notes = [notes];
|
|
2887
|
+
}
|
|
2888
|
+
if (notes.length) {
|
|
2889
|
+
concept[map[key]] = {};
|
|
2890
|
+
for (const { lang, value } of notes) {
|
|
2891
|
+
if (lang && value) {
|
|
2892
|
+
concept[map[key]][lang] ||= [];
|
|
2893
|
+
concept[map[key]][lang].push(value);
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2846
2898
|
return concept;
|
|
2847
2899
|
}
|
|
2848
2900
|
/**
|
|
@@ -2922,20 +2974,20 @@ var SkosmosApiProvider = class extends BaseProvider {
|
|
|
2922
2974
|
concepts = concepts.map((c) => ({ uri: c.uri, inScheme: c.inScheme }));
|
|
2923
2975
|
const newConcepts = [];
|
|
2924
2976
|
for (let concept of concepts) {
|
|
2925
|
-
|
|
2977
|
+
if (!concept || !concept.uri) {
|
|
2978
|
+
throw new InvalidOrMissingParameterError({ parameter: "concept", message: "Missing concept URI" });
|
|
2979
|
+
}
|
|
2980
|
+
const params = { uri: concept.uri, format: "application/json" };
|
|
2981
|
+
const url = this._getApiUrl(concept?.inScheme?.[0], "/data", params);
|
|
2926
2982
|
if (!url) {
|
|
2927
2983
|
continue;
|
|
2928
2984
|
}
|
|
2929
2985
|
const result = await this.axios({
|
|
2930
2986
|
...config,
|
|
2931
2987
|
method: "get",
|
|
2932
|
-
url
|
|
2933
|
-
params: {
|
|
2934
|
-
uri: concept.uri,
|
|
2935
|
-
format: "application/json"
|
|
2936
|
-
}
|
|
2988
|
+
url
|
|
2937
2989
|
});
|
|
2938
|
-
const resultConcept = result
|
|
2990
|
+
const resultConcept = result?.graph?.find((c) => import_jskos_tools8.default.compare(c, concept));
|
|
2939
2991
|
if (resultConcept) {
|
|
2940
2992
|
const newConcept = this._toJskosConcept(resultConcept, { concept, result });
|
|
2941
2993
|
for (let type of ["broader", "narrower"]) {
|
|
@@ -3049,7 +3101,7 @@ var SkosmosApiProvider = class extends BaseProvider {
|
|
|
3049
3101
|
method: "get",
|
|
3050
3102
|
url
|
|
3051
3103
|
});
|
|
3052
|
-
for (let type of response
|
|
3104
|
+
for (let type of response?.types || []) {
|
|
3053
3105
|
if (type.uri == "http://www.w3.org/2004/02/skos/core#Concept") {
|
|
3054
3106
|
continue;
|
|
3055
3107
|
}
|
|
@@ -4382,7 +4434,7 @@ var OlsApiProvider = class extends BaseProvider {
|
|
|
4382
4434
|
};
|
|
4383
4435
|
constructor(config) {
|
|
4384
4436
|
super(config);
|
|
4385
|
-
this.endpoint = config.endpoint;
|
|
4437
|
+
this.endpoint = config.endpoint || config.uri;
|
|
4386
4438
|
}
|
|
4387
4439
|
/**
|
|
4388
4440
|
* Used by `registryForScheme` (see src/lib/CocodaSDK.js) to determine a provider config for a concept schceme.
|
|
@@ -4461,7 +4513,7 @@ var OlsApiProvider = class extends BaseProvider {
|
|
|
4461
4513
|
}
|
|
4462
4514
|
if (term["http://www.w3.org/2000/01/rdf-schema#label"]) {
|
|
4463
4515
|
concept.prefLabel = {};
|
|
4464
|
-
concept.prefLabel[lan] = term["http://www.w3.org/2000/01/rdf-schema#label"];
|
|
4516
|
+
concept.prefLabel[lan] = term["http://www.w3.org/2000/01/rdf-schema#label"].value || term["http://www.w3.org/2000/01/rdf-schema#label"];
|
|
4465
4517
|
}
|
|
4466
4518
|
concept.type = [
|
|
4467
4519
|
"http://www.w3.org/2004/02/skos/core#Concept",
|
|
@@ -4627,11 +4679,8 @@ var OlsApiProvider = class extends BaseProvider {
|
|
|
4627
4679
|
async getTop({ scheme }) {
|
|
4628
4680
|
const VOCID = await this._getSchemeVOCID(scheme);
|
|
4629
4681
|
if (VOCID) {
|
|
4630
|
-
let
|
|
4631
|
-
|
|
4632
|
-
if (response?.elements) {
|
|
4633
|
-
return Promise.all(response.elements.map((item) => this._termToJSKOS(item)));
|
|
4634
|
-
}
|
|
4682
|
+
let response = await this._paginate(["ontologies", VOCID, "classes"], { hasDirectParents: "false" }, null);
|
|
4683
|
+
return Promise.all(response.map((item) => this._termToJSKOS(item)));
|
|
4635
4684
|
}
|
|
4636
4685
|
return [];
|
|
4637
4686
|
}
|
|
@@ -4647,22 +4696,16 @@ var OlsApiProvider = class extends BaseProvider {
|
|
|
4647
4696
|
async getNarrower({ concept }) {
|
|
4648
4697
|
const { VOCID, iri } = await this._splitConcept(concept);
|
|
4649
4698
|
if (VOCID && iri) {
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
if (response?.elements) {
|
|
4653
|
-
return Promise.all(response.elements.map((item) => this._termToJSKOS(item)));
|
|
4654
|
-
}
|
|
4699
|
+
const items = await this._paginate(["ontologies", VOCID, "classes", iri, "children"], {}, 0);
|
|
4700
|
+
return Promise.all(items.map((item) => this._termToJSKOS(item)));
|
|
4655
4701
|
}
|
|
4656
4702
|
return [];
|
|
4657
4703
|
}
|
|
4658
4704
|
async getAncestors({ concept }) {
|
|
4659
4705
|
const { VOCID, iri } = await this._splitConcept(concept);
|
|
4660
4706
|
if (VOCID && iri) {
|
|
4661
|
-
let
|
|
4662
|
-
|
|
4663
|
-
if (response?.elements) {
|
|
4664
|
-
return Promise.all(response.elements.map((item) => this._termToJSKOS(item)));
|
|
4665
|
-
}
|
|
4707
|
+
let response = await this._paginate(["ontologies", VOCID, "classes", iri, "ancestors"], {}, null);
|
|
4708
|
+
return Promise.all(response.map((item) => this._termToJSKOS(item)));
|
|
4666
4709
|
}
|
|
4667
4710
|
return [];
|
|
4668
4711
|
}
|
|
@@ -5215,24 +5258,31 @@ var CocodaSDK = class _CocodaSDK {
|
|
|
5215
5258
|
});
|
|
5216
5259
|
}
|
|
5217
5260
|
/**
|
|
5218
|
-
* Method to get a
|
|
5261
|
+
* Method to get a service by URI.
|
|
5219
5262
|
*
|
|
5220
|
-
* @param {string} uri URI of
|
|
5221
|
-
* @returns {?Object} initialized
|
|
5263
|
+
* @param {string} uri URI of service in config
|
|
5264
|
+
* @returns {?Object} initialized service from config if found
|
|
5222
5265
|
*/
|
|
5223
|
-
|
|
5266
|
+
getServiceForUri(uri) {
|
|
5224
5267
|
return this.config.registries.find((r) => r.uri == uri);
|
|
5225
5268
|
}
|
|
5269
|
+
// alias for backwards compatibility
|
|
5270
|
+
getRegistryForUri(uri) {
|
|
5271
|
+
return this.getRegistryForUri(uri);
|
|
5272
|
+
}
|
|
5226
5273
|
/**
|
|
5227
|
-
* Method to initialize
|
|
5274
|
+
* Method to initialize service.
|
|
5228
5275
|
*
|
|
5229
|
-
* @param {Object}
|
|
5230
|
-
* @returns {Object} initialized
|
|
5276
|
+
* @param {Object} service JSKOS service object
|
|
5277
|
+
* @returns {Object} initialized service
|
|
5231
5278
|
*/
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
return
|
|
5279
|
+
initializeService(service) {
|
|
5280
|
+
service = providers.init(service);
|
|
5281
|
+
service.cdk = this;
|
|
5282
|
+
return service;
|
|
5283
|
+
}
|
|
5284
|
+
initializeRegistry(service) {
|
|
5285
|
+
return this.initializeService(service);
|
|
5236
5286
|
}
|
|
5237
5287
|
/**
|
|
5238
5288
|
* Method to add custom provider.
|