cocoda-sdk 3.4.13 → 3.5.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.
@@ -27,8 +27,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
 
29
29
  // src/index.js
30
- var src_exports = {};
31
- __export(src_exports, {
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
32
  BaseProvider: () => BaseProvider,
33
33
  CocodaSDK: () => CocodaSDK,
34
34
  ConceptApiProvider: () => ConceptApiProvider,
@@ -48,7 +48,7 @@ __export(src_exports, {
48
48
  errors: () => errors_exports,
49
49
  utils: () => utils_exports
50
50
  });
51
- module.exports = __toCommonJS(src_exports);
51
+ module.exports = __toCommonJS(index_exports);
52
52
 
53
53
  // src/errors/index.js
54
54
  var errors_exports = {};
@@ -2075,7 +2075,8 @@ var ConceptApiProvider = class extends BaseProvider {
2075
2075
  * @returns {Object[]} array of JSKOS concept objects
2076
2076
  */
2077
2077
  async getConcepts({ concepts, ...config }) {
2078
- if (this.has.data === false) {
2078
+ const url = this._api.concepts || this._api.data;
2079
+ if (!url) {
2079
2080
  throw new MissingApiUrlError();
2080
2081
  }
2081
2082
  if (!concepts) {
@@ -2088,7 +2089,7 @@ var ConceptApiProvider = class extends BaseProvider {
2088
2089
  return this.axios({
2089
2090
  ...config,
2090
2091
  method: "get",
2091
- url: this._api.data,
2092
+ url,
2092
2093
  params: {
2093
2094
  ...this._defaultParams,
2094
2095
  // ? What should the default limit be?
@@ -2106,24 +2107,29 @@ var ConceptApiProvider = class extends BaseProvider {
2106
2107
  * @returns {Object[]} array of JSKOS concept objects
2107
2108
  */
2108
2109
  async getNarrower({ concept, ...config }) {
2109
- if (!this._api.narrower) {
2110
- throw new MissingApiUrlError();
2111
- }
2112
2110
  if (!concept || !concept.uri) {
2113
2111
  throw new InvalidOrMissingParameterError({ parameter: "concept" });
2114
2112
  }
2115
- return this.axios({
2116
- ...config,
2117
- method: "get",
2118
- url: this._api.narrower,
2119
- params: {
2120
- ...this._defaultParams,
2121
- // ? What should the default limit be?
2122
- limit: 1e4,
2123
- ...config.params || {},
2124
- uri: concept.uri
2125
- }
2126
- });
2113
+ if (this._api.narrower) {
2114
+ return this.axios({
2115
+ ...config,
2116
+ method: "get",
2117
+ url: this._api.narrower,
2118
+ params: {
2119
+ ...this._defaultParams,
2120
+ // ? What should the default limit be?
2121
+ limit: 1e4,
2122
+ ...config.params || {},
2123
+ uri: concept.uri
2124
+ }
2125
+ });
2126
+ } else {
2127
+ const conf2 = { params: {}, ...config };
2128
+ conf2.params.properties = "narrower";
2129
+ const response = await this.getConcepts({ concepts: [concept], ...conf2 });
2130
+ const narrower = response[0]?.narrower || [];
2131
+ return narrower.length ? this.getConcepts({ concepts: narrower, ...config }) : [];
2132
+ }
2127
2133
  }
2128
2134
  /**
2129
2135
  * Returns ancestor concepts for a concept.
@@ -2133,24 +2139,29 @@ var ConceptApiProvider = class extends BaseProvider {
2133
2139
  * @returns {Object[]} array of JSKOS concept objects
2134
2140
  */
2135
2141
  async getAncestors({ concept, ...config }) {
2136
- if (!this._api.ancestors) {
2137
- throw new MissingApiUrlError();
2138
- }
2139
2142
  if (!concept || !concept.uri) {
2140
2143
  throw new InvalidOrMissingParameterError({ parameter: "concept" });
2141
2144
  }
2142
- return this.axios({
2143
- ...config,
2144
- method: "get",
2145
- url: this._api.ancestors,
2146
- params: {
2147
- ...this._defaultParams,
2148
- // ? What should the default limit be?
2149
- limit: 1e4,
2150
- ...config.params || {},
2151
- uri: concept.uri
2152
- }
2153
- });
2145
+ if (this._api.ancestors) {
2146
+ return this.axios({
2147
+ ...config,
2148
+ method: "get",
2149
+ url: this._api.ancestors,
2150
+ params: {
2151
+ ...this._defaultParams,
2152
+ // ? What should the default limit be?
2153
+ limit: 1e4,
2154
+ ...config.params || {},
2155
+ uri: concept.uri
2156
+ }
2157
+ });
2158
+ } else {
2159
+ const conf2 = { params: {}, ...config };
2160
+ conf2.params.properties = "ancestors";
2161
+ const response = await this.getConcepts({ concepts: [concept], ...conf2 });
2162
+ const ancestors = response[0]?.ancestors || [];
2163
+ return ancestors.length ? this.getConcepts({ concepts: ancestors, ...config }) : [];
2164
+ }
2154
2165
  }
2155
2166
  /**
2156
2167
  * Returns suggestion result in OpenSearch Suggest Format.