@iiasa/ixmp4-ts 0.4.0 → 0.6.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/dist/cjs/backend.js +7 -4
- package/dist/cjs/core/model.js +3 -2
- package/dist/cjs/core/region.js +3 -2
- package/dist/cjs/core/run.js +3 -2
- package/dist/cjs/core/scenario.js +5 -2
- package/dist/cjs/core/unit.js +2 -2
- package/dist/cjs/core/utils.js +22 -1
- package/dist/cjs/data/base.js +4 -0
- package/dist/cjs/data/docs.js +2 -2
- package/dist/cjs/dataframe/dataframe.js +43 -1
- package/dist/cjs/dataframe/exceptions.js +24 -0
- package/dist/cjs/dataframe/index.js +5 -1
- package/dist/cjs/index.js +4 -1
- package/dist/esm/backend.js +7 -4
- package/dist/esm/core/model.js +3 -2
- package/dist/esm/core/region.js +3 -2
- package/dist/esm/core/run.js +3 -2
- package/dist/esm/core/scenario.js +5 -2
- package/dist/esm/core/unit.js +3 -3
- package/dist/esm/core/utils.js +21 -1
- package/dist/esm/data/base.js +4 -0
- package/dist/esm/data/docs.js +2 -2
- package/dist/esm/dataframe/dataframe.js +42 -1
- package/dist/esm/dataframe/exceptions.js +18 -0
- package/dist/esm/dataframe/index.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/types/core/model.d.ts +3 -2
- package/dist/types/core/region.d.ts +1 -1
- package/dist/types/core/run.d.ts +1 -1
- package/dist/types/core/scenario.d.ts +1 -1
- package/dist/types/core/unit.d.ts +1 -1
- package/dist/types/core/utils.d.ts +14 -1
- package/dist/types/dataframe/dataframe.d.ts +17 -1
- package/dist/types/dataframe/exceptions.d.ts +9 -0
- package/dist/types/dataframe/index.d.ts +2 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +2 -2
package/dist/cjs/backend.js
CHANGED
@@ -70,23 +70,26 @@ class Backend {
|
|
70
70
|
client.interceptors.response.use((value) => {
|
71
71
|
return value;
|
72
72
|
}, (err) => __awaiter(this, void 0, void 0, function* () {
|
73
|
-
|
73
|
+
const originalRequest = err.config;
|
74
|
+
if (!originalRequest._retry &&
|
75
|
+
err.response &&
|
74
76
|
((err.response.status === 401 &&
|
75
77
|
err.response.data.error_name === 'invalid_token') ||
|
76
78
|
(err.response.status === 403 &&
|
77
79
|
err.response.data.error_name === 'forbidden' &&
|
78
80
|
auth.accessToken === null))) {
|
81
|
+
originalRequest._retry = true;
|
79
82
|
return yield auth
|
80
83
|
.refreshOrObtainAccessToken()
|
81
84
|
.then(() => {
|
82
85
|
return client.request(err.config);
|
83
86
|
})
|
84
|
-
.catch(() => {
|
85
|
-
|
87
|
+
.catch((error) => {
|
88
|
+
return Promise.reject(error);
|
86
89
|
});
|
87
90
|
}
|
88
91
|
else {
|
89
|
-
|
92
|
+
return Promise.reject(err);
|
90
93
|
}
|
91
94
|
}));
|
92
95
|
}
|
package/dist/cjs/core/model.js
CHANGED
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
12
|
exports.ModelRepository = exports.Model = void 0;
|
13
13
|
const base_1 = require("./base");
|
14
|
+
const utils_1 = require("./utils");
|
14
15
|
/**
|
15
16
|
* Represents a model in the assessment modeling system.
|
16
17
|
*/
|
@@ -120,7 +121,7 @@ class ModelRepository extends base_1.BaseFacade {
|
|
120
121
|
*/
|
121
122
|
list(filter) {
|
122
123
|
return __awaiter(this, void 0, void 0, function* () {
|
123
|
-
const models = yield this.backend.models.list(filter);
|
124
|
+
const models = yield this.backend.models.list((0, utils_1.withIamcDefault)(filter));
|
124
125
|
return models.map((model) => {
|
125
126
|
return new Model(this.backend, model);
|
126
127
|
});
|
@@ -133,7 +134,7 @@ class ModelRepository extends base_1.BaseFacade {
|
|
133
134
|
*/
|
134
135
|
tabulate(filter) {
|
135
136
|
return __awaiter(this, void 0, void 0, function* () {
|
136
|
-
return this.backend.models.tabulate(filter);
|
137
|
+
return this.backend.models.tabulate((0, utils_1.withIamcDefault)(filter));
|
137
138
|
});
|
138
139
|
}
|
139
140
|
}
|
package/dist/cjs/core/region.js
CHANGED
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
12
|
exports.RegionRepository = exports.Region = void 0;
|
13
13
|
const base_1 = require("./base");
|
14
|
+
const utils_1 = require("./utils");
|
14
15
|
/**
|
15
16
|
* Represents a unit in the system.
|
16
17
|
*/
|
@@ -152,7 +153,7 @@ class RegionRepository extends base_1.BaseFacade {
|
|
152
153
|
*/
|
153
154
|
list(filter) {
|
154
155
|
return __awaiter(this, void 0, void 0, function* () {
|
155
|
-
return this.backend.regions.list(filter).then((models) => {
|
156
|
+
return this.backend.regions.list((0, utils_1.withIamcDefault)(filter)).then((models) => {
|
156
157
|
return models.map((model) => new Region(this.backend, model));
|
157
158
|
});
|
158
159
|
});
|
@@ -164,7 +165,7 @@ class RegionRepository extends base_1.BaseFacade {
|
|
164
165
|
*/
|
165
166
|
tabulate(filter) {
|
166
167
|
return __awaiter(this, void 0, void 0, function* () {
|
167
|
-
return this.backend.regions.tabulate(filter);
|
168
|
+
return this.backend.regions.tabulate((0, utils_1.withIamcDefault)(filter));
|
168
169
|
});
|
169
170
|
}
|
170
171
|
}
|
package/dist/cjs/core/run.js
CHANGED
@@ -13,6 +13,7 @@ exports.RunRepository = exports.Run = void 0;
|
|
13
13
|
const base_1 = require("./base");
|
14
14
|
const data_1 = require("./iamc/data");
|
15
15
|
const meta_1 = require("./meta");
|
16
|
+
const utils_1 = require("./utils");
|
16
17
|
/**
|
17
18
|
* Represents a Modeling Run.
|
18
19
|
*/
|
@@ -155,7 +156,7 @@ class RunRepository extends base_1.BaseFacade {
|
|
155
156
|
if (filter.defaultOnly === undefined) {
|
156
157
|
filter.defaultOnly = true;
|
157
158
|
}
|
158
|
-
const runs = yield this.backend.runs.list(filter);
|
159
|
+
const runs = yield this.backend.runs.list((0, utils_1.withIamcDefault)(filter));
|
159
160
|
const runPromises = runs.map((run) => __awaiter(this, void 0, void 0, function* () {
|
160
161
|
return new Run(this.backend, run);
|
161
162
|
}));
|
@@ -172,7 +173,7 @@ class RunRepository extends base_1.BaseFacade {
|
|
172
173
|
if (filter.defaultOnly === undefined) {
|
173
174
|
filter.defaultOnly = true;
|
174
175
|
}
|
175
|
-
const df = yield this.backend.runs.tabulate(filter);
|
176
|
+
const df = yield this.backend.runs.tabulate((0, utils_1.withIamcDefault)(filter));
|
176
177
|
const models = yield this.backend.models.list();
|
177
178
|
const scenarios = yield this.backend.scenarios.list();
|
178
179
|
const modelNames = df.columnValues('model__id').map((id) => {
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
12
|
exports.ScenarioRepository = exports.Scenario = void 0;
|
13
13
|
const base_1 = require("./base");
|
14
|
+
const utils_1 = require("./utils");
|
14
15
|
/**
|
15
16
|
* Represents a Modeling Scenario.
|
16
17
|
*/
|
@@ -127,7 +128,9 @@ class ScenarioRepository extends base_1.BaseFacade {
|
|
127
128
|
*/
|
128
129
|
list(filter) {
|
129
130
|
return __awaiter(this, void 0, void 0, function* () {
|
130
|
-
return this.backend.scenarios
|
131
|
+
return this.backend.scenarios
|
132
|
+
.list((0, utils_1.withIamcDefault)(filter))
|
133
|
+
.then((models) => {
|
131
134
|
return models.map((model) => new Scenario(this.backend, model));
|
132
135
|
});
|
133
136
|
});
|
@@ -139,7 +142,7 @@ class ScenarioRepository extends base_1.BaseFacade {
|
|
139
142
|
*/
|
140
143
|
tabulate(filter) {
|
141
144
|
return __awaiter(this, void 0, void 0, function* () {
|
142
|
-
return this.backend.scenarios.tabulate(filter);
|
145
|
+
return this.backend.scenarios.tabulate((0, utils_1.withIamcDefault)(filter));
|
143
146
|
});
|
144
147
|
}
|
145
148
|
}
|
package/dist/cjs/core/unit.js
CHANGED
@@ -167,7 +167,7 @@ class UnitRepository extends base_1.BaseFacade {
|
|
167
167
|
*/
|
168
168
|
list(filter) {
|
169
169
|
return __awaiter(this, void 0, void 0, function* () {
|
170
|
-
return this.backend.units.list(filter).then((models) => {
|
170
|
+
return this.backend.units.list((0, utils_1.withIamcDefault)(filter)).then((models) => {
|
171
171
|
return models.map((model) => new Unit(this.backend, model));
|
172
172
|
});
|
173
173
|
});
|
@@ -179,7 +179,7 @@ class UnitRepository extends base_1.BaseFacade {
|
|
179
179
|
*/
|
180
180
|
tabulate(filter) {
|
181
181
|
return __awaiter(this, void 0, void 0, function* () {
|
182
|
-
return this.backend.units.tabulate(filter);
|
182
|
+
return this.backend.units.tabulate((0, utils_1.withIamcDefault)(filter));
|
183
183
|
});
|
184
184
|
}
|
185
185
|
}
|
package/dist/cjs/core/utils.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.toIamcWide = exports.dfToDimensionless = exports.unitToDimensionless = exports.substitudeType = void 0;
|
3
|
+
exports.withIamcDefault = exports.toIamcWide = exports.dfToDimensionless = exports.unitToDimensionless = exports.substitudeType = void 0;
|
4
4
|
const dataframe_1 = require("../dataframe");
|
5
5
|
const datapoint_1 = require("../data/iamc/datapoint");
|
6
6
|
function substitudeType(df, type) {
|
@@ -111,3 +111,24 @@ exports.toIamcWide = toIamcWide;
|
|
111
111
|
function getIamcRowIndex(row, rowIdentifiers) {
|
112
112
|
return rowIdentifiers.map((i) => row[i]).join('_');
|
113
113
|
}
|
114
|
+
/**
|
115
|
+
* Processes the filter to ensure that IAMC filter is enabled by default unless explicitly disabled.
|
116
|
+
* When enabled, only entities with associated datapoints are returned.
|
117
|
+
* @param filter The filter to process
|
118
|
+
* @returns The processed filter with IAMC default settings
|
119
|
+
*/
|
120
|
+
function withIamcDefault(filter) {
|
121
|
+
if (!filter) {
|
122
|
+
return { iamc: true };
|
123
|
+
}
|
124
|
+
else if (filter.iamc === undefined) {
|
125
|
+
// If the IAMC filter is not explicitly set, default to true
|
126
|
+
filter.iamc = true;
|
127
|
+
}
|
128
|
+
else if (filter.iamc === null) {
|
129
|
+
// If the IAMC filter is explicitly set to null, leave it as is
|
130
|
+
return filter;
|
131
|
+
}
|
132
|
+
return filter;
|
133
|
+
}
|
134
|
+
exports.withIamcDefault = withIamcDefault;
|
package/dist/cjs/data/base.js
CHANGED
@@ -118,6 +118,10 @@ class BaseRepository {
|
|
118
118
|
}
|
119
119
|
_list({ filter, params, }) {
|
120
120
|
return __awaiter(this, void 0, void 0, function* () {
|
121
|
+
if (this.enumerationMethod === 'GET') {
|
122
|
+
params = Object.assign(Object.assign({}, params), filter);
|
123
|
+
filter = undefined;
|
124
|
+
}
|
121
125
|
const data = yield this._requestEnumeration(params, filter, false);
|
122
126
|
const pagination = data.pagination;
|
123
127
|
if (pagination !== undefined) {
|
package/dist/cjs/data/docs.js
CHANGED
@@ -14,7 +14,7 @@ const base_1 = require("./base");
|
|
14
14
|
class DocsRepository extends base_1.BaseRepository {
|
15
15
|
get(dimensionId) {
|
16
16
|
return __awaiter(this, void 0, void 0, function* () {
|
17
|
-
return yield this._get({
|
17
|
+
return yield this._get({ dimensionId });
|
18
18
|
});
|
19
19
|
}
|
20
20
|
set(dimensionId, description) {
|
@@ -27,7 +27,7 @@ class DocsRepository extends base_1.BaseRepository {
|
|
27
27
|
}
|
28
28
|
list(dimensionId) {
|
29
29
|
return __awaiter(this, void 0, void 0, function* () {
|
30
|
-
return yield this._list({ filter: {
|
30
|
+
return yield this._list({ filter: { dimensionId } });
|
31
31
|
});
|
32
32
|
}
|
33
33
|
delete(dimensionId) {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.DType = exports.DataFrame = void 0;
|
4
|
+
const exceptions_1 = require("./exceptions");
|
4
5
|
/**
|
5
6
|
* Represents the available data types for the DataFrame.
|
6
7
|
*/
|
@@ -24,7 +25,7 @@ const nonValueIamcColumns = [
|
|
24
25
|
'type',
|
25
26
|
];
|
26
27
|
/**
|
27
|
-
* Represents a DataFrame, an immutable two-dimensional tabular data structure with labeled axes.
|
28
|
+
* Represents a DataFrame, an immutable two-dimensional row-based tabular data structure with labeled axes.
|
28
29
|
*/
|
29
30
|
class DataFrame {
|
30
31
|
/**
|
@@ -218,6 +219,47 @@ class DataFrame {
|
|
218
219
|
iat(row, column) {
|
219
220
|
return this._values[column][row];
|
220
221
|
}
|
222
|
+
/**
|
223
|
+
* Executes a query on the DataFrame and returns a new DataFrame containing
|
224
|
+
* the rows that match the specified conditions.
|
225
|
+
* @param query.conditions - A single QueryCondition or an array of QueryCondition objects.
|
226
|
+
* @param query.conjunction - Optional. Specifies how to combine multiple conditions.
|
227
|
+
* Can be 'AND' or 'OR'. Defaults to 'AND'.
|
228
|
+
* @returns A new DataFrame containing the rows that match the query.
|
229
|
+
*/
|
230
|
+
query(query) {
|
231
|
+
var _a;
|
232
|
+
const conditions = Array.isArray(query.conditions)
|
233
|
+
? query.conditions
|
234
|
+
: [query.conditions];
|
235
|
+
const conjunction = (_a = query.conjunction) !== null && _a !== void 0 ? _a : 'AND';
|
236
|
+
conditions.forEach((condition) => {
|
237
|
+
if (typeof condition.column === 'string') {
|
238
|
+
condition.column = this._columns.indexOf(condition.column);
|
239
|
+
}
|
240
|
+
});
|
241
|
+
const illegalColumnns = conditions
|
242
|
+
.filter((condition) => condition.column === -1)
|
243
|
+
.map((condition) => condition.column);
|
244
|
+
if (illegalColumnns.length > 0) {
|
245
|
+
throw new exceptions_1.InvalidColumn(illegalColumnns);
|
246
|
+
}
|
247
|
+
const indices = this._values
|
248
|
+
.map((row, i) => {
|
249
|
+
if (conjunction === 'AND') {
|
250
|
+
return conditions.every((condition) => condition.predicate(row[condition.column]))
|
251
|
+
? i
|
252
|
+
: -1;
|
253
|
+
}
|
254
|
+
else {
|
255
|
+
return conditions.some((condition) => condition.predicate(row[condition.column]))
|
256
|
+
? i
|
257
|
+
: -1;
|
258
|
+
}
|
259
|
+
})
|
260
|
+
.filter((i) => i !== -1);
|
261
|
+
return this.iloc({ rows: indices });
|
262
|
+
}
|
221
263
|
/**
|
222
264
|
* Gets the data type for a specific column.
|
223
265
|
* @param column - The column name.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.InvalidIndex = exports.InvalidColumn = exports.DataFrameError = void 0;
|
4
|
+
class DataFrameError extends Error {
|
5
|
+
constructor(message) {
|
6
|
+
super(message);
|
7
|
+
this.name = 'DataFrameError';
|
8
|
+
}
|
9
|
+
}
|
10
|
+
exports.DataFrameError = DataFrameError;
|
11
|
+
class InvalidColumn extends DataFrameError {
|
12
|
+
constructor(column) {
|
13
|
+
super(`Invalid column: ${Array.isArray(column) ? column.join(', ') : column}`);
|
14
|
+
this.name = 'InvalidColumn';
|
15
|
+
}
|
16
|
+
}
|
17
|
+
exports.InvalidColumn = InvalidColumn;
|
18
|
+
class InvalidIndex extends DataFrameError {
|
19
|
+
constructor(index) {
|
20
|
+
super(`Invalid index: ${Array.isArray(index) ? index.join(', ') : index}`);
|
21
|
+
this.name = 'InvalidIndex';
|
22
|
+
}
|
23
|
+
}
|
24
|
+
exports.InvalidIndex = InvalidIndex;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.merge = exports.toCsv = exports.toJson = exports.concat = exports.DType = exports.DataFrame = void 0;
|
3
|
+
exports.InvalidIndex = exports.InvalidColumn = exports.DataFrameError = exports.merge = exports.toCsv = exports.toJson = exports.concat = exports.DType = exports.DataFrame = void 0;
|
4
4
|
var dataframe_1 = require("./dataframe");
|
5
5
|
Object.defineProperty(exports, "DataFrame", { enumerable: true, get: function () { return dataframe_1.DataFrame; } });
|
6
6
|
Object.defineProperty(exports, "DType", { enumerable: true, get: function () { return dataframe_1.DType; } });
|
@@ -9,3 +9,7 @@ Object.defineProperty(exports, "concat", { enumerable: true, get: function () {
|
|
9
9
|
Object.defineProperty(exports, "toJson", { enumerable: true, get: function () { return utils_1.toJson; } });
|
10
10
|
Object.defineProperty(exports, "toCsv", { enumerable: true, get: function () { return utils_1.toCsv; } });
|
11
11
|
Object.defineProperty(exports, "merge", { enumerable: true, get: function () { return utils_1.merge; } });
|
12
|
+
var exceptions_1 = require("./exceptions");
|
13
|
+
Object.defineProperty(exports, "DataFrameError", { enumerable: true, get: function () { return exceptions_1.DataFrameError; } });
|
14
|
+
Object.defineProperty(exports, "InvalidColumn", { enumerable: true, get: function () { return exceptions_1.InvalidColumn; } });
|
15
|
+
Object.defineProperty(exports, "InvalidIndex", { enumerable: true, get: function () { return exceptions_1.InvalidIndex; } });
|
package/dist/cjs/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.merge = exports.toCsv = exports.toJson = exports.concat = exports.DType = exports.DataFrame = 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 = exports.Platform = void 0;
|
3
|
+
exports.InvalidIndex = exports.InvalidColumn = exports.DataFrameError = exports.merge = exports.toCsv = exports.toJson = exports.concat = exports.DType = exports.DataFrame = 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 = exports.Platform = void 0;
|
4
4
|
var platform_1 = require("./core/platform");
|
5
5
|
Object.defineProperty(exports, "Platform", { enumerable: true, get: function () { return platform_1.Platform; } });
|
6
6
|
var exceptions_1 = require("./core/exceptions");
|
@@ -32,3 +32,6 @@ Object.defineProperty(exports, "concat", { enumerable: true, get: function () {
|
|
32
32
|
Object.defineProperty(exports, "toJson", { enumerable: true, get: function () { return dataframe_1.toJson; } });
|
33
33
|
Object.defineProperty(exports, "toCsv", { enumerable: true, get: function () { return dataframe_1.toCsv; } });
|
34
34
|
Object.defineProperty(exports, "merge", { enumerable: true, get: function () { return dataframe_1.merge; } });
|
35
|
+
Object.defineProperty(exports, "DataFrameError", { enumerable: true, get: function () { return dataframe_1.DataFrameError; } });
|
36
|
+
Object.defineProperty(exports, "InvalidColumn", { enumerable: true, get: function () { return dataframe_1.InvalidColumn; } });
|
37
|
+
Object.defineProperty(exports, "InvalidIndex", { enumerable: true, get: function () { return dataframe_1.InvalidIndex; } });
|
package/dist/esm/backend.js
CHANGED
@@ -64,23 +64,26 @@ class Backend {
|
|
64
64
|
client.interceptors.response.use((value) => {
|
65
65
|
return value;
|
66
66
|
}, async (err) => {
|
67
|
-
|
67
|
+
const originalRequest = err.config;
|
68
|
+
if (!originalRequest._retry &&
|
69
|
+
err.response &&
|
68
70
|
((err.response.status === 401 &&
|
69
71
|
err.response.data.error_name === 'invalid_token') ||
|
70
72
|
(err.response.status === 403 &&
|
71
73
|
err.response.data.error_name === 'forbidden' &&
|
72
74
|
auth.accessToken === null))) {
|
75
|
+
originalRequest._retry = true;
|
73
76
|
return await auth
|
74
77
|
.refreshOrObtainAccessToken()
|
75
78
|
.then(() => {
|
76
79
|
return client.request(err.config);
|
77
80
|
})
|
78
|
-
.catch(() => {
|
79
|
-
|
81
|
+
.catch((error) => {
|
82
|
+
return Promise.reject(error);
|
80
83
|
});
|
81
84
|
}
|
82
85
|
else {
|
83
|
-
|
86
|
+
return Promise.reject(err);
|
84
87
|
}
|
85
88
|
});
|
86
89
|
}
|
package/dist/esm/core/model.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { BaseFacade, BaseModelFacade } from './base';
|
2
|
+
import { withIamcDefault } from './utils';
|
2
3
|
/**
|
3
4
|
* Represents a model in the assessment modeling system.
|
4
5
|
*/
|
@@ -96,7 +97,7 @@ class ModelRepository extends BaseFacade {
|
|
96
97
|
* @returns A promise that resolves to an array of models.
|
97
98
|
*/
|
98
99
|
async list(filter) {
|
99
|
-
const models = await this.backend.models.list(filter);
|
100
|
+
const models = await this.backend.models.list(withIamcDefault(filter));
|
100
101
|
return models.map((model) => {
|
101
102
|
return new Model(this.backend, model);
|
102
103
|
});
|
@@ -107,7 +108,7 @@ class ModelRepository extends BaseFacade {
|
|
107
108
|
* @returns A promise that resolves to the tabulated result.
|
108
109
|
*/
|
109
110
|
async tabulate(filter) {
|
110
|
-
return this.backend.models.tabulate(filter);
|
111
|
+
return this.backend.models.tabulate(withIamcDefault(filter));
|
111
112
|
}
|
112
113
|
}
|
113
114
|
export { Model, ModelRepository };
|
package/dist/esm/core/region.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { BaseFacade, BaseModelFacade } from './base';
|
2
|
+
import { withIamcDefault } from './utils';
|
2
3
|
/**
|
3
4
|
* Represents a unit in the system.
|
4
5
|
*/
|
@@ -126,7 +127,7 @@ class RegionRepository extends BaseFacade {
|
|
126
127
|
* @returns A promise that resolves to an array of regions.
|
127
128
|
*/
|
128
129
|
async list(filter) {
|
129
|
-
return this.backend.regions.list(filter).then((models) => {
|
130
|
+
return this.backend.regions.list(withIamcDefault(filter)).then((models) => {
|
130
131
|
return models.map((model) => new Region(this.backend, model));
|
131
132
|
});
|
132
133
|
}
|
@@ -136,7 +137,7 @@ class RegionRepository extends BaseFacade {
|
|
136
137
|
* @returns A promise that resolves to a DataFrame containing the tabulated regions.
|
137
138
|
*/
|
138
139
|
async tabulate(filter) {
|
139
|
-
return this.backend.regions.tabulate(filter);
|
140
|
+
return this.backend.regions.tabulate(withIamcDefault(filter));
|
140
141
|
}
|
141
142
|
}
|
142
143
|
export { Region as Region, RegionRepository };
|
package/dist/esm/core/run.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { BaseFacade, BaseModelFacade } from './base';
|
2
2
|
import { RunIamcData } from './iamc/data';
|
3
3
|
import { RunMetaIndicatorRepository } from './meta';
|
4
|
+
import { withIamcDefault } from './utils';
|
4
5
|
/**
|
5
6
|
* Represents a Modeling Run.
|
6
7
|
*/
|
@@ -135,7 +136,7 @@ class RunRepository extends BaseFacade {
|
|
135
136
|
if (filter.defaultOnly === undefined) {
|
136
137
|
filter.defaultOnly = true;
|
137
138
|
}
|
138
|
-
const runs = await this.backend.runs.list(filter);
|
139
|
+
const runs = await this.backend.runs.list(withIamcDefault(filter));
|
139
140
|
const runPromises = runs.map(async (run) => {
|
140
141
|
return new Run(this.backend, run);
|
141
142
|
});
|
@@ -150,7 +151,7 @@ class RunRepository extends BaseFacade {
|
|
150
151
|
if (filter.defaultOnly === undefined) {
|
151
152
|
filter.defaultOnly = true;
|
152
153
|
}
|
153
|
-
const df = await this.backend.runs.tabulate(filter);
|
154
|
+
const df = await this.backend.runs.tabulate(withIamcDefault(filter));
|
154
155
|
const models = await this.backend.models.list();
|
155
156
|
const scenarios = await this.backend.scenarios.list();
|
156
157
|
const modelNames = df.columnValues('model__id').map((id) => {
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { BaseFacade, BaseModelFacade } from './base';
|
2
|
+
import { withIamcDefault } from './utils';
|
2
3
|
/**
|
3
4
|
* Represents a Modeling Scenario.
|
4
5
|
*/
|
@@ -103,7 +104,9 @@ class ScenarioRepository extends BaseFacade {
|
|
103
104
|
* @returns A Promise that resolves to an array of Scenarios.
|
104
105
|
*/
|
105
106
|
async list(filter) {
|
106
|
-
return this.backend.scenarios
|
107
|
+
return this.backend.scenarios
|
108
|
+
.list(withIamcDefault(filter))
|
109
|
+
.then((models) => {
|
107
110
|
return models.map((model) => new Scenario(this.backend, model));
|
108
111
|
});
|
109
112
|
}
|
@@ -113,7 +116,7 @@ class ScenarioRepository extends BaseFacade {
|
|
113
116
|
* @returns A Promise that resolves to a DataFrame containing the tabulated data.
|
114
117
|
*/
|
115
118
|
async tabulate(filter) {
|
116
|
-
return this.backend.scenarios.tabulate(filter);
|
119
|
+
return this.backend.scenarios.tabulate(withIamcDefault(filter));
|
117
120
|
}
|
118
121
|
}
|
119
122
|
export { Scenario, ScenarioRepository };
|
package/dist/esm/core/unit.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { BaseFacade, BaseModelFacade } from './base';
|
2
|
-
import { unitToDimensionless } from './utils';
|
2
|
+
import { withIamcDefault, unitToDimensionless } from './utils';
|
3
3
|
/**
|
4
4
|
* Represents a unit in the system.
|
5
5
|
*/
|
@@ -139,7 +139,7 @@ class UnitRepository extends BaseFacade {
|
|
139
139
|
* @returns A promise that resolves with an array of Unit objects.
|
140
140
|
*/
|
141
141
|
async list(filter) {
|
142
|
-
return this.backend.units.list(filter).then((models) => {
|
142
|
+
return this.backend.units.list(withIamcDefault(filter)).then((models) => {
|
143
143
|
return models.map((model) => new Unit(this.backend, model));
|
144
144
|
});
|
145
145
|
}
|
@@ -149,7 +149,7 @@ class UnitRepository extends BaseFacade {
|
|
149
149
|
* @returns A promise that resolves with a DataFrame object.
|
150
150
|
*/
|
151
151
|
async tabulate(filter) {
|
152
|
-
return this.backend.units.tabulate(filter);
|
152
|
+
return this.backend.units.tabulate(withIamcDefault(filter));
|
153
153
|
}
|
154
154
|
}
|
155
155
|
export { Unit, UnitRepository };
|
package/dist/esm/core/utils.js
CHANGED
@@ -104,4 +104,24 @@ function toIamcWide(df) {
|
|
104
104
|
function getIamcRowIndex(row, rowIdentifiers) {
|
105
105
|
return rowIdentifiers.map((i) => row[i]).join('_');
|
106
106
|
}
|
107
|
-
|
107
|
+
/**
|
108
|
+
* Processes the filter to ensure that IAMC filter is enabled by default unless explicitly disabled.
|
109
|
+
* When enabled, only entities with associated datapoints are returned.
|
110
|
+
* @param filter The filter to process
|
111
|
+
* @returns The processed filter with IAMC default settings
|
112
|
+
*/
|
113
|
+
function withIamcDefault(filter) {
|
114
|
+
if (!filter) {
|
115
|
+
return { iamc: true };
|
116
|
+
}
|
117
|
+
else if (filter.iamc === undefined) {
|
118
|
+
// If the IAMC filter is not explicitly set, default to true
|
119
|
+
filter.iamc = true;
|
120
|
+
}
|
121
|
+
else if (filter.iamc === null) {
|
122
|
+
// If the IAMC filter is explicitly set to null, leave it as is
|
123
|
+
return filter;
|
124
|
+
}
|
125
|
+
return filter;
|
126
|
+
}
|
127
|
+
export { substitudeType, unitToDimensionless, dfToDimensionless, toIamcWide, withIamcDefault, };
|
package/dist/esm/data/base.js
CHANGED
@@ -91,6 +91,10 @@ class BaseRepository {
|
|
91
91
|
}
|
92
92
|
}
|
93
93
|
async _list({ filter, params, }) {
|
94
|
+
if (this.enumerationMethod === 'GET') {
|
95
|
+
params = { ...params, ...filter };
|
96
|
+
filter = undefined;
|
97
|
+
}
|
94
98
|
const data = await this._requestEnumeration(params, filter, false);
|
95
99
|
const pagination = data.pagination;
|
96
100
|
if (pagination !== undefined) {
|
package/dist/esm/data/docs.js
CHANGED
@@ -2,7 +2,7 @@ import { BaseRepository } from './base';
|
|
2
2
|
class DocsRepository extends BaseRepository {
|
3
3
|
static enumerationMethod = 'GET';
|
4
4
|
async get(dimensionId) {
|
5
|
-
return await this._get({
|
5
|
+
return await this._get({ dimensionId });
|
6
6
|
}
|
7
7
|
async set(dimensionId, description) {
|
8
8
|
return (await this._post({
|
@@ -11,7 +11,7 @@ class DocsRepository extends BaseRepository {
|
|
11
11
|
}));
|
12
12
|
}
|
13
13
|
async list(dimensionId) {
|
14
|
-
return await this._list({ filter: {
|
14
|
+
return await this._list({ filter: { dimensionId } });
|
15
15
|
}
|
16
16
|
async delete(dimensionId) {
|
17
17
|
await this._delete(dimensionId);
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { InvalidColumn } from './exceptions';
|
1
2
|
/**
|
2
3
|
* Represents the available data types for the DataFrame.
|
3
4
|
*/
|
@@ -21,7 +22,7 @@ const nonValueIamcColumns = [
|
|
21
22
|
'type',
|
22
23
|
];
|
23
24
|
/**
|
24
|
-
* Represents a DataFrame, an immutable two-dimensional tabular data structure with labeled axes.
|
25
|
+
* Represents a DataFrame, an immutable two-dimensional row-based tabular data structure with labeled axes.
|
25
26
|
*/
|
26
27
|
class DataFrame {
|
27
28
|
_index;
|
@@ -218,6 +219,46 @@ class DataFrame {
|
|
218
219
|
iat(row, column) {
|
219
220
|
return this._values[column][row];
|
220
221
|
}
|
222
|
+
/**
|
223
|
+
* Executes a query on the DataFrame and returns a new DataFrame containing
|
224
|
+
* the rows that match the specified conditions.
|
225
|
+
* @param query.conditions - A single QueryCondition or an array of QueryCondition objects.
|
226
|
+
* @param query.conjunction - Optional. Specifies how to combine multiple conditions.
|
227
|
+
* Can be 'AND' or 'OR'. Defaults to 'AND'.
|
228
|
+
* @returns A new DataFrame containing the rows that match the query.
|
229
|
+
*/
|
230
|
+
query(query) {
|
231
|
+
const conditions = Array.isArray(query.conditions)
|
232
|
+
? query.conditions
|
233
|
+
: [query.conditions];
|
234
|
+
const conjunction = query.conjunction ?? 'AND';
|
235
|
+
conditions.forEach((condition) => {
|
236
|
+
if (typeof condition.column === 'string') {
|
237
|
+
condition.column = this._columns.indexOf(condition.column);
|
238
|
+
}
|
239
|
+
});
|
240
|
+
const illegalColumnns = conditions
|
241
|
+
.filter((condition) => condition.column === -1)
|
242
|
+
.map((condition) => condition.column);
|
243
|
+
if (illegalColumnns.length > 0) {
|
244
|
+
throw new InvalidColumn(illegalColumnns);
|
245
|
+
}
|
246
|
+
const indices = this._values
|
247
|
+
.map((row, i) => {
|
248
|
+
if (conjunction === 'AND') {
|
249
|
+
return conditions.every((condition) => condition.predicate(row[condition.column]))
|
250
|
+
? i
|
251
|
+
: -1;
|
252
|
+
}
|
253
|
+
else {
|
254
|
+
return conditions.some((condition) => condition.predicate(row[condition.column]))
|
255
|
+
? i
|
256
|
+
: -1;
|
257
|
+
}
|
258
|
+
})
|
259
|
+
.filter((i) => i !== -1);
|
260
|
+
return this.iloc({ rows: indices });
|
261
|
+
}
|
221
262
|
/**
|
222
263
|
* Gets the data type for a specific column.
|
223
264
|
* @param column - The column name.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export class DataFrameError extends Error {
|
2
|
+
constructor(message) {
|
3
|
+
super(message);
|
4
|
+
this.name = 'DataFrameError';
|
5
|
+
}
|
6
|
+
}
|
7
|
+
export class InvalidColumn extends DataFrameError {
|
8
|
+
constructor(column) {
|
9
|
+
super(`Invalid column: ${Array.isArray(column) ? column.join(', ') : column}`);
|
10
|
+
this.name = 'InvalidColumn';
|
11
|
+
}
|
12
|
+
}
|
13
|
+
export class InvalidIndex extends DataFrameError {
|
14
|
+
constructor(index) {
|
15
|
+
super(`Invalid index: ${Array.isArray(index) ? index.join(', ') : index}`);
|
16
|
+
this.name = 'InvalidIndex';
|
17
|
+
}
|
18
|
+
}
|
package/dist/esm/index.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
export { Platform } from './core/platform';
|
2
2
|
export { IxmpError, ProgrammingError, InconsistentIamcType, BadRequest, ImproperlyConfigured, ManagerApiError, UnknownApiError, PlatformNotFound, PlatformNotUnique, MissingToken, InvalidToken, Forbidden, NotFound, NotUnique, DeletionPrevented, OperationNotSupported, SchemaError, NoDefaultRunVersion, InvalidRunMeta, BadFilterArguments, InvalidCredentials, } from './core/exceptions';
|
3
|
-
export { DataFrame, DType, concat, toJson, toCsv, merge } from './dataframe';
|
3
|
+
export { DataFrame, DType, concat, toJson, toCsv, merge, DataFrameError, InvalidColumn, InvalidIndex, } from './dataframe';
|
@@ -7,6 +7,7 @@ import { VariableFilter as BaseVariableFilter } from '../data/iamc/variable';
|
|
7
7
|
import { UnitFilter as BaseUnitFilter } from '../data/unit';
|
8
8
|
import { RunFilter as BaseRunFilter } from '../data/run';
|
9
9
|
import { ScenarioFilter as BaseScenarioFilter } from '../data/scenario';
|
10
|
+
import { DataFrame } from '../dataframe';
|
10
11
|
/**
|
11
12
|
* Represents a filter for listing and tabulating models.
|
12
13
|
*/
|
@@ -18,7 +19,7 @@ type ModelFilter = BaseModelFilter & {
|
|
18
19
|
run?: BaseRunFilter & {
|
19
20
|
scenario?: BaseScenarioFilter;
|
20
21
|
};
|
21
|
-
};
|
22
|
+
} | boolean;
|
22
23
|
};
|
23
24
|
/**
|
24
25
|
* Represents a model in the assessment modeling system.
|
@@ -94,7 +95,7 @@ declare class ModelRepository extends BaseFacade {
|
|
94
95
|
* @param filter Optional. Filter for tabulating models.
|
95
96
|
* @returns A promise that resolves to the tabulated result.
|
96
97
|
*/
|
97
|
-
tabulate(filter?: ModelFilter): Promise<
|
98
|
+
tabulate(filter?: ModelFilter): Promise<DataFrame>;
|
98
99
|
}
|
99
100
|
export { Model, ModelRepository };
|
100
101
|
export type { ModelFilter };
|
package/dist/types/core/run.d.ts
CHANGED
@@ -1,7 +1,20 @@
|
|
1
1
|
import { DataFrame } from '../dataframe';
|
2
2
|
import { DataPointType } from '../data/iamc/datapoint';
|
3
|
+
import { PlainObject } from '../data/base';
|
4
|
+
import { RunFilter } from './run';
|
5
|
+
import { ScenarioFilter } from './scenario';
|
6
|
+
import { RegionFilter } from './region';
|
7
|
+
import { UnitFilter } from './unit';
|
8
|
+
import { ModelFilter } from './model';
|
3
9
|
declare function substitudeType(df: DataFrame, type?: DataPointType): DataFrame;
|
4
10
|
declare function unitToDimensionless(name: string): string;
|
5
11
|
declare function dfToDimensionless(df: DataFrame): DataFrame;
|
6
12
|
declare function toIamcWide(df: DataFrame): DataFrame;
|
7
|
-
|
13
|
+
/**
|
14
|
+
* Processes the filter to ensure that IAMC filter is enabled by default unless explicitly disabled.
|
15
|
+
* When enabled, only entities with associated datapoints are returned.
|
16
|
+
* @param filter The filter to process
|
17
|
+
* @returns The processed filter with IAMC default settings
|
18
|
+
*/
|
19
|
+
declare function withIamcDefault(filter?: RunFilter | ScenarioFilter | ModelFilter | RegionFilter | UnitFilter): PlainObject;
|
20
|
+
export { substitudeType, unitToDimensionless, dfToDimensionless, toIamcWide, withIamcDefault, };
|
@@ -9,8 +9,12 @@ declare enum DType {
|
|
9
9
|
DATETIME = "datetime",
|
10
10
|
MIXED = "mixed"
|
11
11
|
}
|
12
|
+
export type QueryCondition = {
|
13
|
+
column: string | number;
|
14
|
+
predicate: (value: any) => boolean;
|
15
|
+
};
|
12
16
|
/**
|
13
|
-
* Represents a DataFrame, an immutable two-dimensional tabular data structure with labeled axes.
|
17
|
+
* Represents a DataFrame, an immutable two-dimensional row-based tabular data structure with labeled axes.
|
14
18
|
*/
|
15
19
|
declare class DataFrame {
|
16
20
|
private _index;
|
@@ -122,6 +126,18 @@ declare class DataFrame {
|
|
122
126
|
* @returns The value at the specified row and column.
|
123
127
|
*/
|
124
128
|
iat(row: number, column: number): any;
|
129
|
+
/**
|
130
|
+
* Executes a query on the DataFrame and returns a new DataFrame containing
|
131
|
+
* the rows that match the specified conditions.
|
132
|
+
* @param query.conditions - A single QueryCondition or an array of QueryCondition objects.
|
133
|
+
* @param query.conjunction - Optional. Specifies how to combine multiple conditions.
|
134
|
+
* Can be 'AND' or 'OR'. Defaults to 'AND'.
|
135
|
+
* @returns A new DataFrame containing the rows that match the query.
|
136
|
+
*/
|
137
|
+
query(query: {
|
138
|
+
conditions: QueryCondition[] | QueryCondition;
|
139
|
+
conjunction?: 'AND' | 'OR';
|
140
|
+
}): DataFrame;
|
125
141
|
/**
|
126
142
|
* Gets the data type for a specific column.
|
127
143
|
* @param column - The column name.
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export declare class DataFrameError extends Error {
|
2
|
+
constructor(message: string);
|
3
|
+
}
|
4
|
+
export declare class InvalidColumn extends DataFrameError {
|
5
|
+
constructor(column: string | number | (string | number)[]);
|
6
|
+
}
|
7
|
+
export declare class InvalidIndex extends DataFrameError {
|
8
|
+
constructor(index: number | number[]);
|
9
|
+
}
|
package/dist/types/index.d.ts
CHANGED
@@ -21,4 +21,4 @@ export type { TimeSeries as TimeSeriesModel } from './data/iamc/timeseries';
|
|
21
21
|
export type { PlatformInfo as PlatformInfoModel } from './data/info';
|
22
22
|
export type { Lookup } from './data/filters';
|
23
23
|
export { IxmpError, ProgrammingError, InconsistentIamcType, BadRequest, ImproperlyConfigured, ManagerApiError, UnknownApiError, PlatformNotFound, PlatformNotUnique, MissingToken, InvalidToken, Forbidden, NotFound, NotUnique, DeletionPrevented, OperationNotSupported, SchemaError, NoDefaultRunVersion, InvalidRunMeta, BadFilterArguments, InvalidCredentials, } from './core/exceptions';
|
24
|
-
export { DataFrame, DType, concat, toJson, toCsv, merge } from './dataframe';
|
24
|
+
export { DataFrame, DType, type QueryCondition, concat, toJson, toCsv, merge, DataFrameError, InvalidColumn, InvalidIndex, } from './dataframe';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@iiasa/ixmp4-ts",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.6.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "typescript client for ixmp4, a data warehouse for scenario analysis",
|
6
6
|
"repository": {
|
@@ -91,7 +91,7 @@
|
|
91
91
|
"testcontainers": "^10.3.2",
|
92
92
|
"typedoc": "^0.25.7",
|
93
93
|
"typescript": "^5.3.2",
|
94
|
-
"vitest": "^1.
|
94
|
+
"vitest": "^3.1.2"
|
95
95
|
},
|
96
96
|
"dependencies": {
|
97
97
|
"axios": "^1.6.2",
|