@iiasa/ixmp4-ts 0.8.0 → 0.9.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.
Files changed (41) hide show
  1. package/dist/cjs/backend.js +12 -3
  2. package/dist/cjs/core/exceptions.js +5 -2
  3. package/dist/cjs/core/iamc/data.js +9 -9
  4. package/dist/cjs/core/meta.js +5 -5
  5. package/dist/cjs/core/run.js +6 -6
  6. package/dist/cjs/core/utils.js +10 -9
  7. package/dist/cjs/data/base.js +24 -15
  8. package/dist/cjs/data/fetch-client.js +182 -0
  9. package/dist/cjs/data/iamc/datapoint.js +14 -14
  10. package/dist/cjs/data/iamc/timeseries.js +12 -12
  11. package/dist/cjs/data/iamc/variable.js +6 -6
  12. package/dist/cjs/data/meta.js +6 -6
  13. package/dist/cjs/data/model.js +6 -6
  14. package/dist/cjs/data/region.js +6 -6
  15. package/dist/cjs/data/run.js +6 -6
  16. package/dist/cjs/data/scenario.js +6 -6
  17. package/dist/cjs/data/unit.js +6 -6
  18. package/dist/cjs/data/utils.js +5 -4
  19. package/dist/cjs/dataframe/utils.js +5 -4
  20. package/dist/cjs/index.js +2 -1
  21. package/dist/esm/backend.js +12 -3
  22. package/dist/esm/core/exceptions.js +3 -1
  23. package/dist/esm/data/base.js +17 -7
  24. package/dist/esm/data/fetch-client.js +161 -0
  25. package/dist/esm/index.js +1 -1
  26. package/dist/types/backend.d.ts +2 -0
  27. package/dist/types/core/exceptions.d.ts +3 -1
  28. package/dist/types/data/base.d.ts +2 -2
  29. package/dist/types/data/fetch-client.d.ts +54 -0
  30. package/dist/types/data/filters.d.ts +9 -9
  31. package/dist/types/data/iamc/variable.d.ts +2 -2
  32. package/dist/types/data/info.d.ts +2 -2
  33. package/dist/types/data/model.d.ts +2 -2
  34. package/dist/types/data/region.d.ts +2 -2
  35. package/dist/types/data/scenario.d.ts +2 -2
  36. package/dist/types/data/unit.d.ts +2 -2
  37. package/dist/types/index.d.ts +2 -1
  38. package/package.json +1 -2
  39. package/dist/cjs/tsconfig.cjs.tsbuildinfo +0 -1
  40. package/dist/esm/tsconfig.tsbuildinfo +0 -1
  41. package/dist/types/tsconfig.types.tsbuildinfo +0 -1
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Backend = void 0;
16
- const axios_1 = __importDefault(require("axios"));
16
+ const fetch_client_1 = require("./data/fetch-client");
17
17
  const query_string_1 = __importDefault(require("query-string"));
18
18
  const run_1 = require("./data/run");
19
19
  const datapoint_1 = require("./data/iamc/datapoint");
@@ -45,7 +45,7 @@ class Backend {
45
45
  static create(name, baseUrl, auth) {
46
46
  return __awaiter(this, void 0, void 0, function* () {
47
47
  const anonymous = !auth;
48
- const client = axios_1.default.create({
48
+ const client = fetch_client_1.FetchClient.create({
49
49
  baseURL: new URL(`/v1/${name}`, baseUrl).href,
50
50
  timeout: 0,
51
51
  // we don't want to send (auth) cookies to ixmp4 but use JWT in Authorization header
@@ -66,10 +66,13 @@ class Backend {
66
66
  : 'Bearer ' + auth.accessToken;
67
67
  }
68
68
  return config;
69
- }, undefined);
69
+ });
70
70
  client.interceptors.response.use((value) => {
71
71
  return value;
72
72
  }, (err) => __awaiter(this, void 0, void 0, function* () {
73
+ if (!err.response) {
74
+ return Promise.reject(err);
75
+ }
73
76
  const originalRequest = err.config;
74
77
  if (!originalRequest._retry &&
75
78
  err.response &&
@@ -96,5 +99,11 @@ class Backend {
96
99
  return new Backend(client, auth);
97
100
  });
98
101
  }
102
+ addErrorHandler(handler) {
103
+ this.client.interceptors.response.use(undefined, handler);
104
+ }
105
+ removeErrorHandler(handler) {
106
+ this.client.interceptors.response.eject(undefined, handler);
107
+ }
99
108
  }
100
109
  exports.Backend = Backend;
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidCredentials = exports.BadFilterArguments = exports.InvalidRunMeta = exports.NoDefaultRunVersion = exports.SchemaError = exports.OperationNotSupported = exports.DeletionPrevented = exports.NotUnique = exports.NotFound = exports.Forbidden = exports.InvalidToken = exports.MissingToken = exports.PlatformNotUnique = exports.PlatformNotFound = exports.UnknownApiError = exports.ManagerApiError = exports.ImproperlyConfigured = exports.BadRequest = exports.InconsistentIamcType = exports.ProgrammingError = exports.IxmpError = void 0;
4
- exports.createError = createError;
3
+ exports.InvalidCredentials = exports.BadFilterArguments = exports.InvalidRunMeta = exports.NoDefaultRunVersion = exports.SchemaError = exports.OperationNotSupported = exports.DeletionPrevented = exports.NotUnique = exports.NotFound = exports.Forbidden = exports.InvalidToken = exports.MissingToken = exports.PlatformNotUnique = exports.PlatformNotFound = exports.UnknownApiError = exports.ManagerApiError = exports.ImproperlyConfigured = exports.BadRequest = exports.InconsistentIamcType = exports.NetworkError = exports.ProgrammingError = exports.IxmpError = exports.createError = void 0;
5
4
  class ProgrammingError extends Error {
6
5
  }
7
6
  exports.ProgrammingError = ProgrammingError;
7
+ class NetworkError extends Error {
8
+ }
9
+ exports.NetworkError = NetworkError;
8
10
  class IxmpError extends Error {
9
11
  constructor(options) {
10
12
  const _message = options === null || options === void 0 ? void 0 : options.message;
@@ -211,6 +213,7 @@ function createError(options) {
211
213
  return new ImproperlyConfigured(Object.assign({ message: 'Could not find remote exception in registry. Are you sure client and server ixmp versions are compatible?' }, options));
212
214
  }
213
215
  }
216
+ exports.createError = createError;
214
217
  // Register all error classes
215
218
  registerError(InconsistentIamcType);
216
219
  registerError(BadRequest);
@@ -71,12 +71,12 @@ class RunIamcData extends base_1.BaseFacade {
71
71
  yield this.backend.iamc.datapoints.bulkDelete(df);
72
72
  });
73
73
  }
74
- tabulate() {
75
- return __awaiter(this, arguments, void 0, function* (_a = {
76
- wide: false,
77
- splitByType: false,
78
- }) {
79
- var { wide = false, splitByType = false } = _a, filter = __rest(_a, ["wide", "splitByType"]);
74
+ tabulate(_a = {
75
+ wide: false,
76
+ splitByType: false,
77
+ }) {
78
+ var { wide = false, splitByType = false } = _a, filter = __rest(_a, ["wide", "splitByType"]);
79
+ return __awaiter(this, void 0, void 0, function* () {
80
80
  if (filter !== undefined && filter !== null) {
81
81
  // these filters do not make sense when applied from a Run
82
82
  const illegalFilter = Object.keys(filter).filter((key) => {
@@ -132,9 +132,9 @@ class PlatformIamcData extends base_1.BaseFacade {
132
132
  super(backend);
133
133
  this.variables = new variable_1.VariableRepository(this.backend);
134
134
  }
135
- tabulate() {
136
- return __awaiter(this, arguments, void 0, function* (_a = { joinRuns: true, wide: false, splitByType: false }) {
137
- var { joinRuns = true, joinRunId = false, wide = false, splitByType = false } = _a, filter = __rest(_a, ["joinRuns", "joinRunId", "wide", "splitByType"]);
135
+ tabulate(_a = { joinRuns: true, wide: false, splitByType: false }) {
136
+ var { joinRuns = true, joinRunId = false, wide = false, splitByType = false } = _a, filter = __rest(_a, ["joinRuns", "joinRunId", "wide", "splitByType"]);
137
+ return __awaiter(this, void 0, void 0, function* () {
138
138
  if (filter === undefined) {
139
139
  filter = {};
140
140
  }
@@ -33,11 +33,11 @@ class MetaIndicatorRepository extends base_1.BaseFacade {
33
33
  * @param joinRunIndex Optional. Whether to join the run index to the tabulated data, defaults to true.
34
34
  * @returns A promise that resolves to a DataFrame containing the tabulated meta indicators.
35
35
  */
36
- tabulate() {
37
- return __awaiter(this, arguments, void 0, function* (_a = {
38
- joinRunIndex: true,
39
- }) {
40
- var { joinRunIndex = true } = _a, filter = __rest(_a, ["joinRunIndex"]);
36
+ tabulate(_a = {
37
+ joinRunIndex: true,
38
+ }) {
39
+ var { joinRunIndex = true } = _a, filter = __rest(_a, ["joinRunIndex"]);
40
+ return __awaiter(this, void 0, void 0, function* () {
41
41
  if (filter === undefined) {
42
42
  filter = {};
43
43
  }
@@ -151,8 +151,8 @@ class RunRepository extends base_1.BaseFacade {
151
151
  * @param filter Optional. Filter for retriving runs.
152
152
  * @returns A promise that resolves to an array of Run instances.
153
153
  */
154
- list() {
155
- return __awaiter(this, arguments, void 0, function* (filter = {}) {
154
+ list(filter = {}) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
156
  if (filter.defaultOnly === undefined) {
157
157
  filter.defaultOnly = true;
158
158
  }
@@ -168,8 +168,8 @@ class RunRepository extends base_1.BaseFacade {
168
168
  * @param filter Optional. Filter for tabulating runs.
169
169
  * @returns A promise that resolves to a DataFrame containing the tabulated runs.
170
170
  */
171
- tabulate() {
172
- return __awaiter(this, arguments, void 0, function* (filter = {}) {
171
+ tabulate(filter = {}) {
172
+ return __awaiter(this, void 0, void 0, function* () {
173
173
  if (filter.defaultOnly === undefined) {
174
174
  filter.defaultOnly = true;
175
175
  }
@@ -195,8 +195,8 @@ class RunRepository extends base_1.BaseFacade {
195
195
  * @param filter Optional. Filter for counting runs.
196
196
  * @returns A promise that resolves to the count of runs.
197
197
  */
198
- count() {
199
- return __awaiter(this, arguments, void 0, function* (filter = {}) {
198
+ count(filter = {}) {
199
+ return __awaiter(this, void 0, void 0, function* () {
200
200
  return this.backend.runs.count((0, utils_1.withIamcDefault)(filter));
201
201
  });
202
202
  }
@@ -1,14 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.substitudeType = substitudeType;
4
- exports.unitToDimensionless = unitToDimensionless;
5
- exports.dfToDimensionless = dfToDimensionless;
6
- exports.standardizeIamcDf = standardizeIamcDf;
7
- exports.toIamcWide = toIamcWide;
8
- exports.withIamcDefault = withIamcDefault;
9
- exports.getIamcRowIndex = getIamcRowIndex;
10
- exports.sortTimesWithYearFirst = sortTimesWithYearFirst;
11
- exports.splitDataFrameByType = splitDataFrameByType;
3
+ exports.splitDataFrameByType = exports.sortTimesWithYearFirst = exports.getIamcRowIndex = exports.withIamcDefault = exports.toIamcWide = exports.standardizeIamcDf = exports.dfToDimensionless = exports.unitToDimensionless = exports.substitudeType = void 0;
12
4
  const dataframe_1 = require("../dataframe");
13
5
  const datapoint_1 = require("../data/iamc/datapoint");
14
6
  function substitudeType(df, type) {
@@ -31,12 +23,14 @@ function substitudeType(df, type) {
31
23
  }
32
24
  return df;
33
25
  }
26
+ exports.substitudeType = substitudeType;
34
27
  function unitToDimensionless(name) {
35
28
  if (name === 'dimensionless') {
36
29
  throw new Error("Unit name 'dimensionless' is reserved, use an empty string '' instead.");
37
30
  }
38
31
  return name === '' ? 'dimensionless' : name;
39
32
  }
33
+ exports.unitToDimensionless = unitToDimensionless;
40
34
  function dfToDimensionless(df) {
41
35
  if (df
42
36
  .loc({ columns: ['unit'] })
@@ -47,6 +41,7 @@ function dfToDimensionless(df) {
47
41
  df.replaceValue('', 'dimensionless', 'unit');
48
42
  return df;
49
43
  }
44
+ exports.dfToDimensionless = dfToDimensionless;
50
45
  /**
51
46
  * Standardizes the columns of a DataFrame in IAMC format.
52
47
  * @param df DataFrame in IAMC format
@@ -65,6 +60,7 @@ function standardizeIamcDf(df) {
65
60
  }
66
61
  return df;
67
62
  }
63
+ exports.standardizeIamcDf = standardizeIamcDf;
68
64
  /**
69
65
  * Converts a DataFrame in IAMC long format to wide format.
70
66
  * @param df The DataFrame to convert
@@ -163,6 +159,7 @@ function toIamcWide(df) {
163
159
  const wideIamcData = Array.from(dataMap.values());
164
160
  return new dataframe_1.DataFrame(wideIamcData, { columns, dtypes });
165
161
  }
162
+ exports.toIamcWide = toIamcWide;
166
163
  /**
167
164
  * Generates a unique row index for IAMC data based on the row's identifiers.
168
165
  * @param row The row data as an array
@@ -172,6 +169,7 @@ function toIamcWide(df) {
172
169
  function getIamcRowIndex(row, rowIdentifiers) {
173
170
  return rowIdentifiers.map((i) => row[i]).join('_');
174
171
  }
172
+ exports.getIamcRowIndex = getIamcRowIndex;
175
173
  /**
176
174
  * Processes the filter to ensure that IAMC filter is enabled by default unless explicitly disabled.
177
175
  * When enabled, only entities with associated datapoints are returned.
@@ -192,6 +190,7 @@ function withIamcDefault(filter) {
192
190
  }
193
191
  return filter;
194
192
  }
193
+ exports.withIamcDefault = withIamcDefault;
195
194
  function sortTimesWithYearFirst(years, dateTimes) {
196
195
  // Create a combined array with type information
197
196
  const combined = [];
@@ -230,6 +229,7 @@ function sortTimesWithYearFirst(years, dateTimes) {
230
229
  // Return just the values
231
230
  return combined.map((item) => item.value);
232
231
  }
232
+ exports.sortTimesWithYearFirst = sortTimesWithYearFirst;
233
233
  /**
234
234
  * Splits a DataFrame into separate DataFrames based on DataPointType.
235
235
  * @param df The DataFrame to split
@@ -264,3 +264,4 @@ function splitDataFrameByType(df) {
264
264
  }
265
265
  return result;
266
266
  }
267
+ exports.splitDataFrameByType = splitDataFrameByType;
@@ -26,8 +26,8 @@ class BaseRepository {
26
26
  this.enumerationMethod = (_a = this.constructor.enumerationMethod) !== null && _a !== void 0 ? _a : 'PATCH';
27
27
  }
28
28
  _request(url, method, params, body) {
29
+ var _a;
29
30
  return __awaiter(this, void 0, void 0, function* () {
30
- var _a;
31
31
  const config = {};
32
32
  config.url = url;
33
33
  config.method = method;
@@ -40,7 +40,7 @@ class BaseRepository {
40
40
  return res.data;
41
41
  }
42
42
  catch (err) {
43
- BaseRepository.throwRemoteException(err.response, (_a = err.response) === null || _a === void 0 ? void 0 : _a.status);
43
+ BaseRepository.throwRemoteException(err.response, ((_a = err.response) === null || _a === void 0 ? void 0 : _a.status) || err.status);
44
44
  }
45
45
  });
46
46
  }
@@ -80,8 +80,8 @@ class BaseRepository {
80
80
  /**
81
81
  * Convenience method for requests to the enumeration endpoint.
82
82
  */
83
- _requestEnumeration() {
84
- return __awaiter(this, arguments, void 0, function* (params = {}, body = {}, table = false) {
83
+ _requestEnumeration(params = {}, body = {}, table = false) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
85
  params = (0, utils_1.convertToSnakeCase)(params);
86
86
  if (body !== undefined && Object.keys(body).length === 0) {
87
87
  body = undefined;
@@ -116,8 +116,8 @@ class BaseRepository {
116
116
  }
117
117
  });
118
118
  }
119
- _list(_a) {
120
- return __awaiter(this, arguments, void 0, function* ({ filter, params, }) {
119
+ _list({ filter, params, }) {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
121
  if (this.enumerationMethod === 'GET') {
122
122
  params = Object.assign(Object.assign({}, params), filter);
123
123
  filter = undefined;
@@ -133,8 +133,8 @@ class BaseRepository {
133
133
  }
134
134
  });
135
135
  }
136
- _tabulate(_a) {
137
- return __awaiter(this, arguments, void 0, function* ({ filter, params, }) {
136
+ _tabulate({ filter, params, }) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
138
  // TODO: test what happens if we get a number that cannot be represented as float32 (or int32)
139
139
  const data = yield this._requestEnumeration(params, filter, true);
140
140
  const pagination = data.pagination;
@@ -156,8 +156,8 @@ class BaseRepository {
156
156
  }
157
157
  });
158
158
  }
159
- _count(_a) {
160
- return __awaiter(this, arguments, void 0, function* ({ filter, params, }) {
159
+ _count({ filter, params, }) {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
161
  if (this.enumerationMethod === 'GET') {
162
162
  params = Object.assign(Object.assign(Object.assign({}, params), filter), { limit: 0 });
163
163
  filter = undefined;
@@ -185,15 +185,24 @@ class BaseRepository {
185
185
  });
186
186
  }
187
187
  static throwRemoteException(res, statusCode) {
188
- const json = res === null || res === void 0 ? void 0 : res.data;
188
+ if (!res) {
189
+ throw new exceptions_1.UnknownApiError({
190
+ message: 'No response received from server',
191
+ status_code: statusCode || 500,
192
+ });
193
+ }
194
+ const actualStatusCode = statusCode || res.status;
195
+ const json = res.data;
196
+ const contentType = res.headers.get('content-type');
189
197
  if (typeof json !== 'object' ||
190
- res.headers['content-type'] !== 'application/json') {
191
- throw new exceptions_1.UnknownApiError(Object.assign({ status_code: statusCode }, res === null || res === void 0 ? void 0 : res.data));
198
+ !contentType ||
199
+ !contentType.includes('application/json')) {
200
+ throw new exceptions_1.UnknownApiError(Object.assign({ status_code: actualStatusCode, message: `HTTP ${actualStatusCode}: ${res.statusText}` }, res.data));
192
201
  }
193
202
  if (!Object.hasOwn(json, 'error_name')) {
194
- throw new exceptions_1.UnknownApiError(Object.assign({ status_code: statusCode }, json));
203
+ throw new exceptions_1.UnknownApiError(Object.assign({ status_code: actualStatusCode }, json));
195
204
  }
196
- throw (0, exceptions_1.createError)(Object.assign({ status_code: statusCode }, json));
205
+ throw (0, exceptions_1.createError)(Object.assign({ status_code: actualStatusCode }, json));
197
206
  }
198
207
  }
199
208
  exports.BaseRepository = BaseRepository;
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FetchClient = void 0;
13
+ const exceptions_1 = require("../core/exceptions");
14
+ class FetchClient {
15
+ constructor(config = {}) {
16
+ this.requestInterceptors = [];
17
+ this.responseInterceptors = [];
18
+ this.errorInterceptors = [];
19
+ this.config = Object.assign({}, config);
20
+ }
21
+ static create(config = {}) {
22
+ return new FetchClient(config);
23
+ }
24
+ buildUrl(url, params, paramsSerializer) {
25
+ let fullUrl = url;
26
+ if (this.config.baseURL && !url.startsWith('http')) {
27
+ fullUrl =
28
+ this.config.baseURL.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
29
+ }
30
+ if (params && Object.keys(params).length > 0) {
31
+ const queryString = paramsSerializer
32
+ ? paramsSerializer(params)
33
+ : new URLSearchParams(params).toString();
34
+ fullUrl += (fullUrl.includes('?') ? '&' : '?') + queryString;
35
+ }
36
+ return fullUrl;
37
+ }
38
+ executeRequest(config) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ let finalConfig = Object.assign(Object.assign({}, this.config), config);
41
+ // Ensure headers is always initialized
42
+ if (!finalConfig.headers) {
43
+ finalConfig.headers = {};
44
+ }
45
+ for (const interceptor of this.requestInterceptors) {
46
+ finalConfig = yield interceptor(finalConfig);
47
+ }
48
+ const url = this.buildUrl(finalConfig.url || '', finalConfig.params, finalConfig.paramsSerializer || this.config.paramsSerializer);
49
+ const headers = Object.assign(Object.assign({ 'Content-Type': 'application/json' }, this.config.headers), finalConfig.headers);
50
+ const fetchOptions = {
51
+ method: finalConfig.method || 'GET',
52
+ headers,
53
+ credentials: finalConfig.withCredentials ? 'include' : 'omit',
54
+ };
55
+ if (finalConfig.data !== undefined &&
56
+ finalConfig.method !== 'GET' &&
57
+ finalConfig.method !== 'HEAD') {
58
+ fetchOptions.body =
59
+ typeof finalConfig.data === 'string'
60
+ ? finalConfig.data
61
+ : JSON.stringify(finalConfig.data);
62
+ }
63
+ let controller;
64
+ if (finalConfig.timeout && finalConfig.timeout > 0) {
65
+ controller = new AbortController();
66
+ fetchOptions.signal = controller.signal;
67
+ setTimeout(() => controller.abort(), finalConfig.timeout);
68
+ }
69
+ try {
70
+ const response = yield fetch(url, fetchOptions);
71
+ let data;
72
+ const contentType = response.headers.get('content-type');
73
+ if (contentType && contentType.includes('application/json')) {
74
+ data = yield response.json();
75
+ }
76
+ else {
77
+ data = yield response.text();
78
+ }
79
+ const fetchResponse = {
80
+ data,
81
+ status: response.status,
82
+ statusText: response.statusText,
83
+ headers: response.headers,
84
+ config: finalConfig,
85
+ };
86
+ if (!response.ok) {
87
+ const error = new Error(`HTTP ${response.status}: ${response.statusText}`);
88
+ error.config = finalConfig;
89
+ error.response = fetchResponse;
90
+ error.status = response.status;
91
+ throw error;
92
+ }
93
+ let finalResponse = fetchResponse;
94
+ for (const interceptor of this.responseInterceptors) {
95
+ finalResponse = yield interceptor(finalResponse);
96
+ }
97
+ return finalResponse;
98
+ }
99
+ catch (error) {
100
+ let fetchError = error;
101
+ // process through error interceptors
102
+ for (const interceptor of this.errorInterceptors) {
103
+ try {
104
+ return yield interceptor(fetchError);
105
+ }
106
+ catch (interceptorError) {
107
+ fetchError = interceptorError;
108
+ }
109
+ }
110
+ if (fetchError.name === 'AbortError') {
111
+ const timeoutError = new Error('Request timeout');
112
+ timeoutError.config = finalConfig;
113
+ throw timeoutError;
114
+ }
115
+ if (fetchError.name === 'TypeError') {
116
+ // This is likely a network error, CORS error, or DNS resolution failure
117
+ const networkError = new exceptions_1.NetworkError(`Network error: ${fetchError.message}`);
118
+ throw networkError;
119
+ }
120
+ throw fetchError;
121
+ }
122
+ });
123
+ }
124
+ request(config) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ return this.executeRequest(config);
127
+ });
128
+ }
129
+ get(url, config = {}) {
130
+ return __awaiter(this, void 0, void 0, function* () {
131
+ return this.request(Object.assign(Object.assign({}, config), { method: 'GET', url }));
132
+ });
133
+ }
134
+ post(url, data, config = {}) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ return this.request(Object.assign(Object.assign({}, config), { method: 'POST', url, data }));
137
+ });
138
+ }
139
+ put(url, data, config = {}) {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ return this.request(Object.assign(Object.assign({}, config), { method: 'PUT', url, data }));
142
+ });
143
+ }
144
+ patch(url, data, config = {}) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ return this.request(Object.assign(Object.assign({}, config), { method: 'PATCH', url, data }));
147
+ });
148
+ }
149
+ delete(url, config = {}) {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ return this.request(Object.assign(Object.assign({}, config), { method: 'DELETE', url }));
152
+ });
153
+ }
154
+ get interceptors() {
155
+ return {
156
+ request: {
157
+ use: (fulfilled) => {
158
+ this.requestInterceptors.push(fulfilled);
159
+ },
160
+ },
161
+ response: {
162
+ use: (fulfilled, rejected) => {
163
+ if (fulfilled) {
164
+ this.responseInterceptors.push(fulfilled);
165
+ }
166
+ if (rejected) {
167
+ this.errorInterceptors.push(rejected);
168
+ }
169
+ },
170
+ eject: (fulfilled, rejected) => {
171
+ if (fulfilled) {
172
+ this.responseInterceptors = this.responseInterceptors.filter((interceptor) => interceptor !== fulfilled);
173
+ }
174
+ if (rejected) {
175
+ this.errorInterceptors = this.errorInterceptors.filter((interceptor) => interceptor !== rejected);
176
+ }
177
+ },
178
+ },
179
+ };
180
+ }
181
+ }
182
+ exports.FetchClient = FetchClient;
@@ -18,24 +18,24 @@ var DataPointType;
18
18
  DataPointType["DATETIME"] = "DATETIME";
19
19
  })(DataPointType || (exports.DataPointType = DataPointType = {}));
20
20
  class DataPointRepository extends base_1.BaseRepository {
21
- list() {
22
- return __awaiter(this, arguments, void 0, function* ({ joinParameters = false, filter = {}, } = {
23
- joinParameters: false,
24
- filter: {},
25
- }) {
21
+ list({ joinParameters = false, filter = {}, } = {
22
+ joinParameters: false,
23
+ filter: {},
24
+ }) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
26
  return (yield this._list({
27
27
  filter,
28
28
  params: { joinParameters },
29
29
  }));
30
30
  });
31
31
  }
32
- tabulate() {
33
- return __awaiter(this, arguments, void 0, function* ({ joinParameters = false, joinRuns = false, joinRunId = false, filter = {}, } = {
34
- joinParameters: false,
35
- joinRuns: false,
36
- joinRunId: false,
37
- filter: {},
38
- }) {
32
+ tabulate({ joinParameters = false, joinRuns = false, joinRunId = false, filter = {}, } = {
33
+ joinParameters: false,
34
+ joinRuns: false,
35
+ joinRunId: false,
36
+ filter: {},
37
+ }) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
39
  return yield this._tabulate({
40
40
  filter,
41
41
  params: {
@@ -46,8 +46,8 @@ class DataPointRepository extends base_1.BaseRepository {
46
46
  });
47
47
  });
48
48
  }
49
- count() {
50
- return __awaiter(this, arguments, void 0, function* (filter = {}) {
49
+ count(filter = {}) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
51
  return yield this._count({
52
52
  filter,
53
53
  });
@@ -49,30 +49,30 @@ class TimeSeriesRepository extends base_1.BaseRepository {
49
49
  }
50
50
  });
51
51
  }
52
- list() {
53
- return __awaiter(this, arguments, void 0, function* ({ joinParameters = false, filter = {}, } = {
54
- joinParameters: false,
55
- filter: {},
56
- }) {
52
+ list({ joinParameters = false, filter = {}, } = {
53
+ joinParameters: false,
54
+ filter: {},
55
+ }) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
57
  return (yield this._list({
58
58
  filter,
59
59
  params: { joinParameters },
60
60
  }));
61
61
  });
62
62
  }
63
- tabulate() {
64
- return __awaiter(this, arguments, void 0, function* ({ joinParameters = false, filter = {}, } = {
65
- joinParameters: false,
66
- filter: {},
67
- }) {
63
+ tabulate({ joinParameters = false, filter = {}, } = {
64
+ joinParameters: false,
65
+ filter: {},
66
+ }) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
68
  return yield this._tabulate({
69
69
  filter,
70
70
  params: { joinParameters },
71
71
  });
72
72
  });
73
73
  }
74
- bulkUpsert(df_1) {
75
- return __awaiter(this, arguments, void 0, function* (df, createRelated = false) {
74
+ bulkUpsert(df, createRelated = false) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
76
  yield this._bulkUpsert(df, { create_related: createRelated });
77
77
  });
78
78
  }
@@ -17,18 +17,18 @@ class VariableRepository extends base_1.BaseRepository {
17
17
  super(client);
18
18
  this.docs = new docs_1.DocsRepository(client, 'docs/iamc/variables/');
19
19
  }
20
- list() {
21
- return __awaiter(this, arguments, void 0, function* (filter = {}) {
20
+ list(filter = {}) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
22
  return yield this._list({ filter });
23
23
  });
24
24
  }
25
- tabulate() {
26
- return __awaiter(this, arguments, void 0, function* (filter = {}) {
25
+ tabulate(filter = {}) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
27
  return yield this._tabulate({ filter });
28
28
  });
29
29
  }
30
- count() {
31
- return __awaiter(this, arguments, void 0, function* (filter = {}) {
30
+ count(filter = {}) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
32
  return yield this._count({ filter });
33
33
  });
34
34
  }
@@ -19,18 +19,18 @@ var MetaIndicatorType;
19
19
  MetaIndicatorType["BOOL"] = "BOOL";
20
20
  })(MetaIndicatorType || (MetaIndicatorType = {}));
21
21
  class MetaIndicatorRepository extends base_1.BaseRepository {
22
- list() {
23
- return __awaiter(this, arguments, void 0, function* (filter = {}) {
22
+ list(filter = {}) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
24
  return yield this._list(filter);
25
25
  });
26
26
  }
27
- tabulate() {
28
- return __awaiter(this, arguments, void 0, function* (filter = {}, joinRunIndex) {
27
+ tabulate(filter = {}, joinRunIndex) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
29
  return yield this._tabulate({ filter, params: { joinRunIndex } });
30
30
  });
31
31
  }
32
- count() {
33
- return __awaiter(this, arguments, void 0, function* (filter = {}) {
32
+ count(filter = {}) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
34
  return yield this._count({ filter });
35
35
  });
36
36
  }