cocoda-sdk 3.6.2 → 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.
@@ -139,24 +139,31 @@ class CocodaSDK {
139
139
  });
140
140
  }
141
141
  /**
142
- * Method to get a registry by URI.
142
+ * Method to get a service by URI.
143
143
  *
144
- * @param {string} uri URI of registry in config
145
- * @returns {?Object} initialized registry from config if found
144
+ * @param {string} uri URI of service in config
145
+ * @returns {?Object} initialized service from config if found
146
146
  */
147
- getRegistryForUri(uri) {
147
+ getServiceForUri(uri) {
148
148
  return this.config.registries.find((r) => r.uri == uri);
149
149
  }
150
+ // alias for backwards compatibility
151
+ getRegistryForUri(uri) {
152
+ return this.getRegistryForUri(uri);
153
+ }
150
154
  /**
151
- * Method to initialize registry.
155
+ * Method to initialize service.
152
156
  *
153
- * @param {Object} registry JSKOS registry object
154
- * @returns {Object} initialized registry
157
+ * @param {Object} service JSKOS service object
158
+ * @returns {Object} initialized service
155
159
  */
156
- initializeRegistry(registry) {
157
- registry = providers.init(registry);
158
- registry.cdk = this;
159
- return registry;
160
+ initializeService(service) {
161
+ service = providers.init(service);
162
+ service.cdk = this;
163
+ return service;
164
+ }
165
+ initializeRegistry(service) {
166
+ return this.initializeService(service);
160
167
  }
161
168
  /**
162
169
  * Method to add custom provider.
@@ -50,7 +50,8 @@ class BaseProvider {
50
50
  annotations: registry.annotations,
51
51
  occurrences: registry.occurrences,
52
52
  reconcile: registry.reconcile,
53
- api: registry.endpoint || registry.api
53
+ api: registry.endpoint || registry.api,
54
+ registries: registry.registries
54
55
  };
55
56
  this._config = {};
56
57
  this.setRetryConfig();
@@ -15,7 +15,8 @@ class ConceptApiProvider extends BaseProvider {
15
15
  types: true,
16
16
  suggest: true,
17
17
  search: true,
18
- auth: true
18
+ auth: true,
19
+ registries: true
19
20
  };
20
21
  /**
21
22
  * @private
@@ -39,7 +40,8 @@ class ConceptApiProvider extends BaseProvider {
39
40
  ancestors: "/ancestors",
40
41
  types: "/types",
41
42
  suggest: "/suggest",
42
- search: "/search"
43
+ search: "/search",
44
+ registries: "/registries"
43
45
  };
44
46
  for (let key of Object.keys(endpoints)) {
45
47
  if (this._api[key] === void 0) {
@@ -47,6 +49,7 @@ class ConceptApiProvider extends BaseProvider {
47
49
  }
48
50
  }
49
51
  }
52
+ this.has.registries = !!this._api.registries;
50
53
  this.has.schemes = !!this._api.schemes;
51
54
  if (!this.has.schemes && Array.isArray(this.schemes)) {
52
55
  this.has.schemes = true;
@@ -114,6 +117,32 @@ class ConceptApiProvider extends BaseProvider {
114
117
  return null;
115
118
  }
116
119
  }
120
+ /**
121
+ * Returns all concept registries.
122
+ *
123
+ * @param {Object} config
124
+ * @returns {Object[]} array of JSKOS concept registry objects
125
+ */
126
+ async getRegistries(config = {}) {
127
+ if (!this._api.registries) {
128
+ if (Array.isArray(this.registries)) {
129
+ return this.registries;
130
+ }
131
+ throw new errors.MissingApiUrlError();
132
+ }
133
+ const registries = await this.axios({
134
+ ...config,
135
+ method: "get",
136
+ url: this._api.registries,
137
+ params: {
138
+ ...this._defaultParams,
139
+ // ? What should the default limit be?
140
+ limit: 500,
141
+ ...config.params || {}
142
+ }
143
+ });
144
+ return registries;
145
+ }
117
146
  /**
118
147
  * Returns all concept schemes.
119
148
  *
@@ -189,18 +189,16 @@ class SkosmosApiProvider extends BaseProvider {
189
189
  "skos:changeNote": "changeNote"
190
190
  };
191
191
  for (let key in map) {
192
- if (skosmosConcept[key]) {
193
- const value = skosmosConcept[key];
194
- if (value.lang && value.value) {
195
- concept[map[key]] = {
196
- [value.lang]: value.value
197
- };
198
- } else if (Array.isArray(value)) {
199
- concept[map[key]] = {};
200
- for (let val of value) {
201
- if (val.lang && val.value) {
202
- concept[map[key]][val.lang] = val.value;
203
- }
192
+ let notes = skosmosConcept[key] || [];
193
+ if (!Array.isArray(notes)) {
194
+ notes = [notes];
195
+ }
196
+ if (notes.length) {
197
+ concept[map[key]] = {};
198
+ for (const { lang, value } of notes) {
199
+ if (lang && value) {
200
+ concept[map[key]][lang] ||= [];
201
+ concept[map[key]][lang].push(value);
204
202
  }
205
203
  }
206
204
  }
@@ -152,6 +152,7 @@ function withCustomProps(arr, from) {
152
152
  return arr;
153
153
  }
154
154
  const listOfCapabilities = [
155
+ "registries",
155
156
  "schemes",
156
157
  "top",
157
158
  "data",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cocoda-sdk",
3
- "version": "3.6.2",
3
+ "version": "3.6.3",
4
4
  "description": "SDK for Cocoda",
5
5
  "main": "dist/cjs/index.cjs",
6
6
  "module": "dist/esm/index.js",