cocoda-sdk 1.0.13 → 2.0.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/LICENSE +1 -1
- package/README.md +74 -28
- package/dist/cjs/index.cjs +2673 -0
- package/dist/cocoda-sdk.js +33 -17423
- package/dist/cocoda-sdk.js.LICENSES.txt +105 -86
- package/dist/cocoda-sdk.js.map +7 -0
- package/dist/esm/errors/index.js +46 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/lib/CocodaSDK.js +269 -0
- package/dist/esm/providers/base-provider.js +368 -0
- package/dist/esm/providers/concept-api-provider.js +278 -0
- package/dist/esm/providers/index.js +20 -0
- package/dist/esm/providers/label-search-suggestion-provider.js +101 -0
- package/dist/esm/providers/loc-api-provider.js +185 -0
- package/dist/esm/providers/local-mappings-provider.js +337 -0
- package/dist/esm/providers/mappings-api-provider.js +264 -0
- package/dist/esm/providers/occurrences-api-provider.js +163 -0
- package/dist/esm/providers/reconciliation-api-provider.js +140 -0
- package/dist/esm/providers/skosmos-api-provider.js +345 -0
- package/{utils → dist/esm/utils}/index.js +40 -53
- package/dist/esm/utils/lodash.js +34 -0
- package/package.json +16 -17
- package/errors/index.js +0 -119
- package/index.js +0 -5
- package/lib/CocodaSDK.js +0 -360
- package/providers/base-provider.js +0 -581
- package/providers/concept-api-provider.js +0 -377
- package/providers/index.js +0 -34
- package/providers/label-search-suggestion-provider.js +0 -219
- package/providers/loc-api-provider.js +0 -275
- package/providers/local-mappings-provider.js +0 -459
- package/providers/mappings-api-provider.js +0 -396
- package/providers/occurrences-api-provider.js +0 -234
- package/providers/reconciliation-api-provider.js +0 -211
- package/providers/skosmos-api-provider.js +0 -441
- package/utils/lodash.js +0 -21
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2021 Verbundzentrale des GBV (VZG)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -10,13 +10,14 @@
|
|
|
10
10
|
- [Install](#install)
|
|
11
11
|
- [Usage](#usage)
|
|
12
12
|
- [Import](#import)
|
|
13
|
+
- [v1 Compatibility](#v1-compatibility)
|
|
13
14
|
- [Configuration](#configuration)
|
|
14
15
|
- [Registries](#registries)
|
|
15
16
|
- [Providers](#providers)
|
|
16
17
|
- [Multiple Instances](#multiple-instances)
|
|
17
18
|
- [Authenticated Requests](#authenticated-requests)
|
|
18
19
|
- [Methods](#methods)
|
|
19
|
-
- [Methods for
|
|
20
|
+
- [Methods for cocoda-sdk instance](#methods-for-cocoda-sdk-instance)
|
|
20
21
|
- [Registry Methods - General](#registry-methods---general)
|
|
21
22
|
- [Registry Methods - Concept Schemes](#registry-methods---concept-schemes)
|
|
22
23
|
- [Registry Methods - Concepts](#registry-methods---concepts)
|
|
@@ -34,39 +35,71 @@
|
|
|
34
35
|
npm i cocoda-sdk
|
|
35
36
|
```
|
|
36
37
|
|
|
37
|
-
We are also providing browser
|
|
38
|
-
- Development (not minified, ~97K): https://cdn.jsdelivr.net/npm/cocoda-sdk/dist/cocoda-sdk.js
|
|
39
|
-
- Production (minified, ~40K): https://cdn.jsdelivr.net/npm/cocoda-sdk@1
|
|
38
|
+
We are also providing a browser bundle: https://cdn.jsdelivr.net/npm/cocoda-sdk@2/dist/cocoda-sdk.js (~49K gzipped, ~151K not gzipped) It will be available under the global name `CDK` and contain the listed members below (in particular the default instance `CDK.cdk`).
|
|
40
39
|
|
|
41
40
|
[](https://www.jsdelivr.com/package/npm/cocoda-sdk)
|
|
42
41
|
|
|
43
42
|
## Usage
|
|
44
43
|
|
|
45
44
|
### Import
|
|
46
|
-
|
|
45
|
+
cocoda-sdk exports a default instance, so the same object is used on each import of cocoda-sdk. We recommend using this instance over creating one's own.
|
|
47
46
|
|
|
48
47
|
```js
|
|
49
|
-
const cdk = require("cocoda-sdk")
|
|
48
|
+
const { cdk } = require("cocoda-sdk") // CommonJS
|
|
49
|
+
import { cdk } from "cocoda-sdk" // ESM
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Since cocoda-sdk is an ES module, we'll use the `import`/`export` syntax in the rest of the documentation.
|
|
53
|
+
|
|
54
|
+
cocoda-sdk also exports some other members:
|
|
55
|
+
- `CocodaSDK` - the class that is behind the default instance
|
|
56
|
+
- `errors` - see [Errors](#errors)
|
|
57
|
+
- All individual provider classes - see [Providers](#providers)
|
|
58
|
+
- Note: You need to append `Provider` to the names, e.g. `LocalMappings` is exported as `LocalMappingsProvider`.
|
|
59
|
+
|
|
60
|
+
### v1 Compatibility
|
|
61
|
+
cocoda-sdk v2 changed how it is exported and therefore it needs to be included differently.
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
// CommonJS
|
|
65
|
+
// Previously: const cdk = require("cocoda-sdk")
|
|
66
|
+
// Now:
|
|
67
|
+
const { cdk } = require("cocoda-sdk")
|
|
68
|
+
// or: const cdk = require("cocoda-sdk").cdk
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
// ES6
|
|
73
|
+
// Previously: import * as cdk from "cocoda-sdk"
|
|
74
|
+
// Now:
|
|
75
|
+
import { cdk } from "cocoda-sdk"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
// Browser
|
|
80
|
+
// Previously the default instance was globally available under `cdk`.
|
|
81
|
+
// Now the module is available under `CDK` with `cdk` as one of its members. To easily make previous code compatible:
|
|
82
|
+
const { cdk } = CDK
|
|
50
83
|
```
|
|
51
84
|
|
|
52
85
|
### Configuration
|
|
53
|
-
|
|
86
|
+
cocoda-sdk can be configured after import:
|
|
54
87
|
|
|
55
88
|
```js
|
|
56
|
-
|
|
89
|
+
import { cdk } from "cocoda-sdk"
|
|
57
90
|
cdk.setConfig(config)
|
|
58
91
|
```
|
|
59
92
|
|
|
60
93
|
The configuration can also be loaded from a URL:
|
|
61
94
|
|
|
62
95
|
```js
|
|
63
|
-
|
|
96
|
+
import { cdk } from "cocoda-sdk"
|
|
64
97
|
await cdk.loadConfig("https://raw.githubusercontent.com/gbv/cocoda/dev/config/cocoda.default.json")
|
|
65
98
|
```
|
|
66
99
|
|
|
67
100
|
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`](#registries).
|
|
68
101
|
|
|
69
|
-
If you only use
|
|
102
|
+
If you only use cocoda-sdk with a single registry, configuration might not be necessary (see below).
|
|
70
103
|
|
|
71
104
|
### Registries
|
|
72
105
|
|
|
@@ -95,7 +128,9 @@ Values set earlier in these steps will never be overwritten by later steps. That
|
|
|
95
128
|
If you only have a single registry you want to access, you can initialize it as follows:
|
|
96
129
|
|
|
97
130
|
```js
|
|
98
|
-
|
|
131
|
+
import { cdk, LocalMappingsProvider } from "cocoda-sdk"
|
|
132
|
+
// Local mappings are not included by default
|
|
133
|
+
cdk.addProvider(LocalMappingsProvider)
|
|
99
134
|
const registry = cdk.initializeRegistry({
|
|
100
135
|
uri: "http://coli-conc.gbv.de/registry/local-mappings",
|
|
101
136
|
provider: "LocalMappings"
|
|
@@ -106,7 +141,7 @@ registry.getMappings()
|
|
|
106
141
|
|
|
107
142
|
#### Using Registries From a Configuration
|
|
108
143
|
|
|
109
|
-
If you initialize
|
|
144
|
+
If you initialize cocoda-sdk with a [configuration](#configuration), it will initialize all included registries automatically. Those registries are then accessible via `cdk.config.registries`. Alternatively, you can retrieve registries by URI:
|
|
110
145
|
|
|
111
146
|
```js
|
|
112
147
|
// After setting up cdk
|
|
@@ -117,10 +152,12 @@ const registry = cdk.getRegistryForUri("...")
|
|
|
117
152
|
|
|
118
153
|
Providers allow access to different types of APIs.
|
|
119
154
|
|
|
120
|
-
The following providers are offered in
|
|
155
|
+
The following providers are offered in cocoda-sdk by default:
|
|
121
156
|
- `Base` - the base provider that all other providers have to inherit from
|
|
122
157
|
- `ConceptApi` - access to concept schemes and concepts via [jskos-server]
|
|
123
158
|
- `MappingsApi` - access to concordances, mappings, and annotations via [jskos-server]
|
|
159
|
+
|
|
160
|
+
The following providers are also exported, but have to be added via `cdk.addProvider`:
|
|
124
161
|
- `LocalMappings` - access to local mappings via [localForage](https://github.com/localForage/localForage) (only available in browser)
|
|
125
162
|
- `SkosmosApi` - access to concept schemes and concepts via a [Skosmos](https://github.com/NatLibFi/Skosmos) API
|
|
126
163
|
- `LocApi` - access to concept schemes and concepts via the [Library of Congress Linked Data Service](https://id.loc.gov/)
|
|
@@ -129,16 +166,25 @@ The following providers are offered in `cocoda-sdk` by default:
|
|
|
129
166
|
- `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)
|
|
130
167
|
- `LabelSearchSuggestion` - access to mapping suggestions using other registries' search endpoints (using [jskos-server])
|
|
131
168
|
|
|
169
|
+
To add a provider, append `Provider` to its name and import it together with `cdk`:
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
import { cdk, LocApiProvider } from "cocoda-sdk"
|
|
173
|
+
cdk.addProvider(LocApiProvider)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Note that in the browser bundle, all providers listed above are included and do not have to be added separately.
|
|
177
|
+
|
|
132
178
|
Please refer to each provider's documentation for how exactly to configure that provider: [Documentation](https://gbv.github.io/cocoda-sdk/)
|
|
133
179
|
|
|
134
180
|
It is also possible to add custom providers that inherit from BaseProvider:
|
|
135
181
|
|
|
136
182
|
```js
|
|
137
|
-
|
|
183
|
+
import CustomProvider from "./custom-provider.js"
|
|
138
184
|
cdk.addProvider(CustomProvider)
|
|
139
185
|
```
|
|
140
186
|
|
|
141
|
-
It is then possible to use that provider via
|
|
187
|
+
It is then possible to use that provider via cocoda-sdk as well. (See also: Example under [`examples/custom-provider.js`](https://github.com/gbv/cocoda-sdk/blob/master/examples/custom-provider.js).)
|
|
142
188
|
|
|
143
189
|
### Multiple Instances
|
|
144
190
|
|
|
@@ -149,7 +195,7 @@ const newCdk = cdk.createInstance(config)
|
|
|
149
195
|
```
|
|
150
196
|
|
|
151
197
|
### Authenticated Requests
|
|
152
|
-
The following is a barebones example on how to use
|
|
198
|
+
The following is a barebones example on how to use cocoda-sdk together with [`login-client`](https://github.com/gbv/login-client).
|
|
153
199
|
|
|
154
200
|
Prerequisites:
|
|
155
201
|
- A local instance of [Login Server](https://github.com/gbv/login-server) running on `localhost:3004`
|
|
@@ -162,6 +208,8 @@ Prerequisites:
|
|
|
162
208
|
|
|
163
209
|
See also the code comments inside the example.
|
|
164
210
|
|
|
211
|
+
<!-- TODO: Offer modern ESM example. -->
|
|
212
|
+
|
|
165
213
|
```html
|
|
166
214
|
<!DOCTYPE html>
|
|
167
215
|
<html>
|
|
@@ -171,11 +219,11 @@ See also the code comments inside the example.
|
|
|
171
219
|
</head>
|
|
172
220
|
<body>
|
|
173
221
|
<!-- login-client, cocoda-sdk -->
|
|
174
|
-
<script src="https://cdn.jsdelivr.net/npm/gbv-login-client"></script>
|
|
175
|
-
<script src="https://cdn.jsdelivr.net/npm/cocoda-sdk"></script>
|
|
222
|
+
<script src="https://cdn.jsdelivr.net/npm/gbv-login-client@0"></script>
|
|
223
|
+
<script src="https://cdn.jsdelivr.net/npm/cocoda-sdk@2"></script>
|
|
176
224
|
<script>
|
|
177
225
|
// Initialize mapping registry at localhost:3000
|
|
178
|
-
const registry = cdk.initializeRegistry({
|
|
226
|
+
const registry = CDK.cdk.initializeRegistry({
|
|
179
227
|
provider: "MappingsApi",
|
|
180
228
|
uri: "local:mappings",
|
|
181
229
|
status: "http://localhost:3000/status",
|
|
@@ -230,14 +278,14 @@ Note that for a real application, there are more things necessary:
|
|
|
230
278
|
You can find more in-depth examples here:
|
|
231
279
|
- The [Vuex store module for authentication in Cocoda](https://github.com/gbv/cocoda/blob/dev/src/store/modules/auth.js).
|
|
232
280
|
- Even if you're not using Vue.js, this can be helpful.
|
|
233
|
-
- Cocoda is using
|
|
281
|
+
- Cocoda is using cocoda-sdk extensively, so other parts of the code might also be helpful. It has gotten pretty big and complex though.
|
|
234
282
|
- The [API page of Login Server](https://github.com/gbv/login-server/blob/master/views/api.ejs). This is merely an example on how to use `login-client`.
|
|
235
283
|
|
|
236
284
|
## Methods
|
|
237
285
|
|
|
238
|
-
A
|
|
286
|
+
A cocoda-sdk instance itself offers only a handful of methods. The actual access to APIs happens through [registries](#registries). The following list of methods assume either an instance of cocoda-sdk (`cdk.someMethod`) or an initialized registry (`registry.someMethod`). Documentation for registry 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.
|
|
239
287
|
|
|
240
|
-
### Methods for
|
|
288
|
+
### Methods for cocoda-sdk instance
|
|
241
289
|
Please refer to the [documentation](https://gbv.github.io/cocoda-sdk/CocodaSDK.html).
|
|
242
290
|
|
|
243
291
|
### Registry Methods - General
|
|
@@ -258,9 +306,6 @@ Please refer to the [documentation](https://gbv.github.io/cocoda-sdk/CocodaSDK.h
|
|
|
258
306
|
#### `registry.setRetryConfig`
|
|
259
307
|
- [BaseProvider - setRetryConfig](https://gbv.github.io/cocoda-sdk/BaseProvider.html#setRetryConfig)
|
|
260
308
|
|
|
261
|
-
#### `registry.setRegistries`
|
|
262
|
-
- [LabelSearchSuggestionProvider - setRegistries](https://gbv.github.io/cocoda-sdk/LabelSearchSuggestionProvider.html#setRegistries)
|
|
263
|
-
|
|
264
309
|
#### `registry.getCancelTokenSource`
|
|
265
310
|
- [BaseProvider - getCancelTokenSource](https://gbv.github.io/cocoda-sdk/BaseProvider.html#getCancelTokenSource)
|
|
266
311
|
|
|
@@ -363,10 +408,11 @@ Please refer to the [documentation](https://gbv.github.io/cocoda-sdk/CocodaSDK.h
|
|
|
363
408
|
- [SkosmosApiProvider - getTypes](https://gbv.github.io/cocoda-sdk/SkosmosApiProvider.html#getTypes)
|
|
364
409
|
|
|
365
410
|
## Errors
|
|
366
|
-
|
|
411
|
+
cocoda-sdk defines some custom errors.
|
|
367
412
|
|
|
368
413
|
```js
|
|
369
|
-
const errors = require("cocoda-sdk
|
|
414
|
+
const { errors } = require("cocoda-sdk") // CommonJS
|
|
415
|
+
import { errors } from "cocoda-sdk"
|
|
370
416
|
```
|
|
371
417
|
|
|
372
418
|
The following errors are defined:
|
|
@@ -413,6 +459,6 @@ PRs accepted.
|
|
|
413
459
|
Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
|
|
414
460
|
|
|
415
461
|
## License
|
|
416
|
-
MIT Copyright (c)
|
|
462
|
+
MIT Copyright (c) 2021 Verbundzentrale des GBV (VZG)
|
|
417
463
|
|
|
418
464
|
[jskos-server]: https://github.com/gbv/jskos-server
|