@mablhq/mabl-cli 1.47.20 → 1.48.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/api/mablApiClient.js +20 -0
- package/cli.js +1 -0
- package/commands/commandUtil/list.js +41 -1
- package/commands/datatables/datatables.js +5 -0
- package/commands/datatables/datatables_cmds/describe.js +17 -0
- package/commands/datatables/datatables_cmds/export.js +78 -0
- package/commands/datatables/datatables_cmds/list.js +18 -0
- package/execution/index.js +1 -1
- package/package.json +2 -1
- package/util/csvUtil.js +8 -0
package/api/mablApiClient.js
CHANGED
|
@@ -461,6 +461,26 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
|
|
|
461
461
|
throw toApiError(`Failed to get File Upload URL`, error);
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
|
+
async getDatatables(workspaceId, limit) {
|
|
465
|
+
try {
|
|
466
|
+
const datatablesQueryString = queryString.stringify({
|
|
467
|
+
organization_id: workspaceId,
|
|
468
|
+
limit,
|
|
469
|
+
});
|
|
470
|
+
return await this.makeGetRequest(`${this.baseApiUrl}/variables/tables?${datatablesQueryString}`).then((result) => { var _a; return (_a = result.variableTables) !== null && _a !== void 0 ? _a : []; });
|
|
471
|
+
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
throw toApiError(`Failed to retrieve datatables`, error);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
async getDatatable(datatableId) {
|
|
477
|
+
try {
|
|
478
|
+
return await this.makeGetRequest(`${this.baseApiUrl}/variables/tables/${datatableId}`);
|
|
479
|
+
}
|
|
480
|
+
catch (error) {
|
|
481
|
+
throw toApiError(`Failed to get datatable`, error);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
464
484
|
async getDatatableRows(datatableId) {
|
|
465
485
|
try {
|
|
466
486
|
return await this.makeGetRequest(`${this.baseApiUrl}/variables/tables/${datatableId}/rows`).then((result) => { var _a; return (_a = result.variableRows) !== null && _a !== void 0 ? _a : []; });
|
package/cli.js
CHANGED
|
@@ -38,6 +38,7 @@ yargs
|
|
|
38
38
|
.commandDir('./commands/branches')
|
|
39
39
|
.commandDir('./commands/config')
|
|
40
40
|
.commandDir('./commands/credentials')
|
|
41
|
+
.commandDir('./commands/datatables')
|
|
41
42
|
.commandDir('./commands/deploy')
|
|
42
43
|
.commandDir('./commands/environments')
|
|
43
44
|
.commandDir('./commands/flows')
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getListBuilderOptions = void 0;
|
|
6
|
+
exports.outputEntities = exports.getListBuilderOptions = void 0;
|
|
4
7
|
const interfaces_1 = require("./interfaces");
|
|
5
8
|
const constants_1 = require("../constants");
|
|
9
|
+
const loggingProvider_1 = require("../../providers/logging/loggingProvider");
|
|
10
|
+
const js_yaml_1 = require("js-yaml");
|
|
11
|
+
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
12
|
+
const moment = require("moment");
|
|
6
13
|
function getListBuilderOptions(pluralEntityName) {
|
|
7
14
|
return (yargs) => {
|
|
8
15
|
yargs
|
|
@@ -28,3 +35,36 @@ function getListBuilderOptions(pluralEntityName) {
|
|
|
28
35
|
};
|
|
29
36
|
}
|
|
30
37
|
exports.getListBuilderOptions = getListBuilderOptions;
|
|
38
|
+
function outputEntities(entities, outputMode) {
|
|
39
|
+
loggingProvider_1.logger.logNewLine();
|
|
40
|
+
let content;
|
|
41
|
+
switch (outputMode) {
|
|
42
|
+
case constants_1.OutputFormats.Json:
|
|
43
|
+
content = JSON.stringify(entities, null, 2);
|
|
44
|
+
break;
|
|
45
|
+
case constants_1.OutputFormats.Yaml:
|
|
46
|
+
content = (0, js_yaml_1.dump)(entities);
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
const table = new cli_table3_1.default({
|
|
50
|
+
head: ['ID', 'Name', 'Created time'],
|
|
51
|
+
wordWrap: true,
|
|
52
|
+
});
|
|
53
|
+
entities.forEach((entity) => {
|
|
54
|
+
table.push([
|
|
55
|
+
{ rowSpan: 1, content: entity.id, vAlign: 'center' },
|
|
56
|
+
{ rowSpan: 1, content: entity.name, vAlign: 'center' },
|
|
57
|
+
{
|
|
58
|
+
rowSpan: 1,
|
|
59
|
+
content: moment.utc(entity.created_time).format(constants_1.ListTimeFormat),
|
|
60
|
+
vAlign: 'center',
|
|
61
|
+
},
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
64
|
+
content = table.toString();
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
loggingProvider_1.logger.info(content);
|
|
68
|
+
return content;
|
|
69
|
+
}
|
|
70
|
+
exports.outputEntities = outputEntities;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mablApiClientFactory_1 = require("../../../api/mablApiClientFactory");
|
|
4
|
+
const constants_1 = require("../../constants");
|
|
5
|
+
const util_1 = require("../../commandUtil/util");
|
|
6
|
+
const describe_1 = require("../../commandUtil/describe");
|
|
7
|
+
exports.command = `describe <${constants_1.CommandArgId}>`;
|
|
8
|
+
exports.describe = 'Describe a specific mabl datatable';
|
|
9
|
+
exports.builder = (0, describe_1.getDescribeBuilderOptions)();
|
|
10
|
+
exports.handler = (0, util_1.failWrapper)(getDatatable);
|
|
11
|
+
async function getDatatable(parsed) {
|
|
12
|
+
const output = parsed.output;
|
|
13
|
+
const datatableId = parsed.id;
|
|
14
|
+
const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createApiClient();
|
|
15
|
+
const datatable = await apiClient.getDatatable(datatableId);
|
|
16
|
+
(0, describe_1.outputEntity)(datatable, output);
|
|
17
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dumpToCsv = void 0;
|
|
4
|
+
const mablApiClientFactory_1 = require("../../../api/mablApiClientFactory");
|
|
5
|
+
const util_1 = require("../../commandUtil/util");
|
|
6
|
+
const constants_1 = require("../../constants");
|
|
7
|
+
const fileUtil_1 = require("../../commandUtil/fileUtil");
|
|
8
|
+
const js_yaml_1 = require("js-yaml");
|
|
9
|
+
const csvUtil_1 = require("../../../util/csvUtil");
|
|
10
|
+
const sync_1 = require("csv-stringify/sync");
|
|
11
|
+
const SCENARIO_NAME_HEADER = 'Scenario name';
|
|
12
|
+
exports.command = `export <${constants_1.CommandArgId}>`;
|
|
13
|
+
exports.describe = 'Export a mabl test in a specified file format';
|
|
14
|
+
exports.builder = (yargs) => {
|
|
15
|
+
yargs
|
|
16
|
+
.positional(constants_1.CommandArgId, {
|
|
17
|
+
describe: 'Datatable id to export',
|
|
18
|
+
type: 'string',
|
|
19
|
+
})
|
|
20
|
+
.option(constants_1.CommandArgFormat, {
|
|
21
|
+
alias: 'fmt',
|
|
22
|
+
default: constants_1.OutputFormats.Yaml,
|
|
23
|
+
describe: `Specify a format for the datatable export`,
|
|
24
|
+
choices: [constants_1.OutputFormats.Json, constants_1.OutputFormats.Yaml, constants_1.OutputFormats.Csv],
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
exports.handler = (0, util_1.failWrapper)(exportDatatable);
|
|
28
|
+
async function exportDatatable(parsed) {
|
|
29
|
+
const datatableId = parsed.id;
|
|
30
|
+
const format = parsed.format;
|
|
31
|
+
const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createApiClient();
|
|
32
|
+
const datatableRows = await apiClient.getDatatableRows(datatableId);
|
|
33
|
+
let output = '';
|
|
34
|
+
switch (format) {
|
|
35
|
+
case constants_1.OutputFormats.Json:
|
|
36
|
+
output = dumpToJson(datatableRows);
|
|
37
|
+
break;
|
|
38
|
+
case constants_1.OutputFormats.Yaml:
|
|
39
|
+
output = dumpToYaml(datatableRows);
|
|
40
|
+
break;
|
|
41
|
+
case constants_1.OutputFormats.Csv:
|
|
42
|
+
output = dumpToCsv(datatableRows);
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
(0, fileUtil_1.writeExportedEntityToFile)(output, format, datatableId);
|
|
46
|
+
}
|
|
47
|
+
function stripDatatableRows(datatableRows) {
|
|
48
|
+
return datatableRows.map((variableRow) => ({
|
|
49
|
+
scenario: variableRow.scenario_id,
|
|
50
|
+
columns: variableRow.row,
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
function dumpToJson(datatableRows) {
|
|
54
|
+
return JSON.stringify(stripDatatableRows(datatableRows), null, 2);
|
|
55
|
+
}
|
|
56
|
+
function dumpToYaml(datatableRows) {
|
|
57
|
+
return (0, js_yaml_1.dump)(stripDatatableRows(datatableRows));
|
|
58
|
+
}
|
|
59
|
+
function dumpToCsv(datatableRows) {
|
|
60
|
+
const output = [];
|
|
61
|
+
if (datatableRows.length === 0) {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
const headers = [
|
|
65
|
+
SCENARIO_NAME_HEADER,
|
|
66
|
+
...(datatableRows[0].row || []).map((variable) => (0, csvUtil_1.sanitizeCellInput)(variable.name || '')),
|
|
67
|
+
];
|
|
68
|
+
output.push(headers);
|
|
69
|
+
datatableRows.forEach(({ scenario_id = '', row = [] }) => {
|
|
70
|
+
const sanitizedRowValues = [
|
|
71
|
+
scenario_id,
|
|
72
|
+
...row.map((variable) => variable.value || ''),
|
|
73
|
+
].map(csvUtil_1.sanitizeCellInput);
|
|
74
|
+
output.push(sanitizedRowValues);
|
|
75
|
+
});
|
|
76
|
+
return (0, sync_1.stringify)(output);
|
|
77
|
+
}
|
|
78
|
+
exports.dumpToCsv = dumpToCsv;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mablApiClientFactory_1 = require("../../../api/mablApiClientFactory");
|
|
4
|
+
const util_1 = require("../../commandUtil/util");
|
|
5
|
+
const list_1 = require("../../commandUtil/list");
|
|
6
|
+
exports.command = 'list';
|
|
7
|
+
exports.describe = 'List your datatables';
|
|
8
|
+
exports.builder = (0, list_1.getListBuilderOptions)('datatables');
|
|
9
|
+
exports.handler = (0, util_1.failWrapper)(listDatatables);
|
|
10
|
+
async function listDatatables(parsed) {
|
|
11
|
+
const output = parsed.output;
|
|
12
|
+
const limit = parsed.limit;
|
|
13
|
+
const workspaceId = await (0, util_1.getWorkspaceId)(parsed);
|
|
14
|
+
const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createApiClient();
|
|
15
|
+
const datatables = await apiClient.getDatatables(workspaceId, limit);
|
|
16
|
+
(0, list_1.outputEntities)(datatables, output);
|
|
17
|
+
return datatables.length;
|
|
18
|
+
}
|